Logo Search packages:      
Sourcecode: ud version File versions  Download package

uptime.c

/*
   Uptime Daemon
   Copyright (C) 1998 Matthew Trent <root@piguy.dyn.ml.org>
   Changes by Johnny Teve_en <j.tevessen@line.org>
   Changes by Andreas Muck <andi@koala.rhein-neckar.de>
   Changes by John Campbell <jcampbel@lynn.ci-n.com>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
 */

#include <stdio.h>
#include <stdlib.h>

float
get_uptime (void)
{
  static const char proc_uptime_path[] = "/proc/uptime";
  FILE *proc_uptime;
  float uptime;
  int err = 0;
  
  if ((proc_uptime = fopen (proc_uptime_path, "r")) == NULL)
    {
      fprintf (stderr, "Can't open `%s'.\n", proc_uptime_path);
      err = 1;
    }
  else
    {
      if (1 != fscanf (proc_uptime, "%f", &uptime))
      {
        fprintf (stderr, "Error parsing `%s'.\n", proc_uptime_path);
        err = 1;
      }
      (void) fclose (proc_uptime);
    }
  if (0 != err)
    exit (EXIT_FAILURE);
  return (uptime);
}

Generated by  Doxygen 1.6.0   Back to index