This is how GNU's coreutils
uptime does it
Code:
fp = fopen ("/proc/uptime", "r");
if (fp != NULL)
{
char buf[BUFSIZ];
int res;
char *b = fgets (buf, BUFSIZ, fp);
if (b == buf)
{
/* The following sscanf must use the C locale. */
setlocale (LC_NUMERIC, "C");
res = sscanf (buf, "%lf", &upsecs);
setlocale (LC_NUMERIC, "");
if (res == 1)
uptime = (time_t) upsecs;
}
fclose (fp);
}
:)
Cheers,
Tink