home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3297 / boottime.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-07  |  1.5 KB  |  68 lines

  1. /* History:
  2. 5/1/91 DJB baseline public domain
  3. */
  4.  
  5. /* getboottime() returns the time that the system wwas booted. It */
  6. /* returns 0 on error. */
  7.  
  8. /* boottimeinit() does optional initialization to cooperate with other */
  9. /* libraries that use nlistlist. boottimeinit returns -1 on error. */
  10.  
  11. /* boottimestrerr is a strerrfun for use with the strerr library. */
  12.  
  13. #include "boottime.h"
  14. #include "kmem.h"
  15. #include "nlistlist.h"
  16. #include "strerr.h"
  17.  
  18. #define BOOTTIMENLIST "_boottime"
  19.  
  20. static int btinit = 0;
  21.  
  22. static long boottime;
  23. static short bttype;
  24. static unsigned long btvalue;
  25. static int boottimeerrno = 0;
  26.  
  27. static struct strerrtab e[] = {
  28.   { 0, "boottime error 0", 0 }
  29. #define BT_INIT 1
  30. , { BT_INIT, "cannot init boottime: ", nliststrerr }
  31. #define BT_NLIST 2
  32. , { BT_NLIST, "cannot nlist: ", nliststrerr }
  33. #define BT_NLISTFOUND 3
  34. , { BT_NLISTFOUND, BOOTTIMENLIST, nlistnotin }
  35. #define BT_KMEM 4
  36. , { BT_KMEM, "cannot read boottime: ", kmemstrerr }
  37. } ;
  38.  
  39. char *boottimestrerr(ke)
  40. strerrfun *ke;
  41. {
  42.  *ke = 0;
  43.  return strerrtaberr(ke,boottimeerrno,e,sizeof(e)/sizeof(*e),"unknown boottime error");
  44. }
  45.  
  46. int boottimeinit()
  47. {
  48.  if (nlistadd(BOOTTIMENLIST,&bttype,&btvalue) == -1)
  49.    RETERN(-1,boottimeerrno,BT_INIT)
  50.  btinit = 1;
  51.  return 0;
  52. }
  53.  
  54. long getboottime()
  55. {
  56.  if (!btinit)
  57.    if (boottimeinit() == -1)
  58.      return 0;
  59.  if (bttype == -1)
  60.    if (nlistdo() == -1)
  61.      RETERN(0,boottimeerrno,BT_NLIST)
  62.  if (!bttype)
  63.    RETERN(0,boottimeerrno,BT_NLISTFOUND)
  64.  if (kmemcpy((char *) &boottime,(char *) btvalue,sizeof(boottime)) == -1)
  65.    RETERN(0,boottimeerrno,BT_KMEM)
  66.  return boottime;
  67. }
  68.