uptime: Use fgets()

This commit is contained in:
apio 2022-10-22 14:23:34 +02:00
parent a4eed362b6
commit 31e0f0efed

View File

@ -10,17 +10,15 @@ int main()
return 1;
}
char buf[4096];
size_t nread = fread(buf, sizeof(buf) - 1, 1, fp);
char buf[32];
fgets(buf, sizeof(buf), fp);
if (ferror(fp))
{
perror("fread");
perror("fgets");
return 1;
}
buf[nread] = 0; // null terminate it :)
long ms_uptime = atol(buf);
printf("up for %ld seconds\n", ms_uptime / 1000);