Luna/apps/src/uptime.c

29 lines
466 B
C
Raw Normal View History

#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE* fp = fopen("/dev/uptime", "r");
if (!fp)
{
perror("fopen");
return 1;
}
char buf[4096];
size_t nread = fread(buf, sizeof(buf) - 1, 1, fp);
if (ferror(fp))
{
perror("fread");
return 1;
}
buf[nread] = 0; // null terminate it :)
long ms_uptime = atol(buf);
printf("up for %ld seconds\n", ms_uptime / 1000);
fclose(fp);
}