diff options
author | Chris Xiong <chirs241097@gmail.com> | 2018-07-14 11:46:12 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2018-07-14 11:46:12 +0800 |
commit | ea652045bb38651d99bcc53972a524f602c3b306 (patch) | |
tree | ea7bf5f5b3f0a76faf07bfeb944b3a56f6afd527 /utils.cpp | |
parent | e5aac499a8a2026af5d5176f45be3ac2576d75cc (diff) | |
download | lightsd-ea652045bb38651d99bcc53972a524f602c3b306.tar.xz |
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.
Diffstat (limited to 'utils.cpp')
-rw-r--r-- | utils.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -4,15 +4,18 @@ #include <cstring> #include <cerrno> #include <cctype> +#include <unistd.h> +#include <fcntl.h> #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) |