From ea652045bb38651d99bcc53972a524f602c3b306 Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Sat, 14 Jul 2018 11:46:12 +0800 Subject: Added a simple tool to create a fake sysfs backlight interface that invokes external commands. Some changes in the utility module to accomodate the new tool. Added an option to watch ALS readings. --- utils.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'utils.cpp') diff --git a/utils.cpp b/utils.cpp index 1d26fc3..698c7eb 100644 --- a/utils.cpp +++ b/utils.cpp @@ -4,15 +4,18 @@ #include #include #include +#include +#include #include "utils.hpp" int readint(const char* path) { - FILE* f=fopen(path,"r"); - if(!f)return LOG('W',"failed to open %s for reading: %d",path,errno),0; + int fd=open(path,O_RDONLY); + if(!~fd)return LOG('W',"failed to open %s for reading: %d",path,errno),0; char buf[16]; - ignore_result(fgets(buf,16,f)); - buf[15]=0; - fclose(f); + int l=read(fd,buf,15); + if(!~l){close(fd);return 0;} + buf[l]=0; + close(fd); return atoi(buf); } float readfloat(const char* path) -- cgit v1.2.3