Guys,
Why not...
long get_uptime_in_sec(void)
{
struct sysinfo info;
if (sysinfo(&info) < 0 ) {
perror("getting uptime");
return -1; /* TODO: maybe this should be 0 */
}
return info.uptime;
}
On Mon, 15 Aug 2005, Dave Shield wrote:
> On Mon, 2005-08-15 at 14:13 +0200, Yegor Yefremov wrote:
> > Comment a accepted:
> >
> > long get_uptime_in_sec(void)
> > {
> > long ret;
> > struct sysinfo *info =
> > (struct sysinfo*)malloc(sizeof(struct sysinfo));
> >
> > if(sysinfo(info) < 0)
> > {
> > perror("Getting uptime");
> > return -1;
> > }
> >
> > ret = info->uptime;
> > free(info);
> >
> > return ret;
> > }
>
> Actually, I'd be inclined to do away with the dynamic allocation
> altogether. It would be much simpler (as well as more efficient)
> to use a static data structure:
>
> long get_uptime_in_sec(void)
> {
> static struct sysinfo info;
>
> if (sysinfo(&info) < 0 ) {
> perror("getting uptime");
> return -1;
> }
> return info.uptime;
> }
>
>
> > I just wanted to show the main concept, that the usage of uptime is
> > safer and more precise then the usage of local time.
>
Regards,
/david t. perkins
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders