aboutsummaryrefslogtreecommitdiff
path: root/utils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'utils.cpp')
-rw-r--r--utils.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/utils.cpp b/utils.cpp
index 1d26fc3..698c7eb 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -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)