Support any value from /proc instead of relying on buf.-size

This commit is contained in:
Patrick Siegl
2019-03-27 21:35:29 +01:00
parent b5dce0e23b
commit eb777add58

View File

@@ -26,15 +26,13 @@ static uint32_t readNumberFromFile(char *fileName) {
fprintf(stderr, "Unable to open %s\n", fileName);
exit(1);
}
char buf[42u];
uint32_t i = 0u;
int c = getc(file);
while(c != EOF) {
buf[i++] = c;
c = getc(file);
uint32_t value = 0u;
char c;
while( (c = getc(file)) != EOF
&& '0' <= c && c <= '9' ) {
value *= 10;
value += c - '0';
}
buf[i] = '\0';
uint32_t value = atoi(buf);
fclose(file);
return value;
}