diff options
author | Chris Xiong <chirs241097@gmail.com> | 2018-07-06 21:25:39 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2018-07-06 21:25:39 +0800 |
commit | b5932d1d22d35cef95eb1cffbf489619b264442d (patch) | |
tree | 6040dc505e9b22875449bcc045fed9b0ac3f0692 /utils.cpp | |
parent | 61e0a974c07f38b8e42f226d68f22e2d1b26fa6d (diff) | |
download | lightsd-b5932d1d22d35cef95eb1cffbf489619b264442d.tar.xz |
Random code clean-ups to get ready for the next update.
Also tweaked the config a little bit.
Diffstat (limited to 'utils.cpp')
-rw-r--r-- | utils.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -23,15 +23,17 @@ float readfloat(const char* path) fclose(f); return atof(buf); } -std::string readstr(const char* path) +std::string readstr(const char* path,int max_length) { FILE* f=fopen(path,"r"); if(!f)return LOG('W',"failed to open %s for reading: %d",path,errno),""; - char buf[256]; - ignore_result(fgets(buf,256,f)); - buf[255]=0; + char* buf=new char[max_length+1]; + ignore_result(fgets(buf,max_length+1,f)); + buf[max_length]=0; fclose(f); - return std::string(buf); + std::string ret(buf); + delete buf; + return ret; } void writeint(const char* path,int v) { |