home *** CD-ROM | disk | FTP | other *** search
- /* History:
- 5/1/91 DJB baseline public domain
- */
-
- /* getboottime() returns the time that the system wwas booted. It */
- /* returns 0 on error. */
-
- /* boottimeinit() does optional initialization to cooperate with other */
- /* libraries that use nlistlist. boottimeinit returns -1 on error. */
-
- /* boottimestrerr is a strerrfun for use with the strerr library. */
-
- #include "boottime.h"
- #include "kmem.h"
- #include "nlistlist.h"
- #include "strerr.h"
-
- #define BOOTTIMENLIST "_boottime"
-
- static int btinit = 0;
-
- static long boottime;
- static short bttype;
- static unsigned long btvalue;
- static int boottimeerrno = 0;
-
- static struct strerrtab e[] = {
- { 0, "boottime error 0", 0 }
- #define BT_INIT 1
- , { BT_INIT, "cannot init boottime: ", nliststrerr }
- #define BT_NLIST 2
- , { BT_NLIST, "cannot nlist: ", nliststrerr }
- #define BT_NLISTFOUND 3
- , { BT_NLISTFOUND, BOOTTIMENLIST, nlistnotin }
- #define BT_KMEM 4
- , { BT_KMEM, "cannot read boottime: ", kmemstrerr }
- } ;
-
- char *boottimestrerr(ke)
- strerrfun *ke;
- {
- *ke = 0;
- return strerrtaberr(ke,boottimeerrno,e,sizeof(e)/sizeof(*e),"unknown boottime error");
- }
-
- int boottimeinit()
- {
- if (nlistadd(BOOTTIMENLIST,&bttype,&btvalue) == -1)
- RETERN(-1,boottimeerrno,BT_INIT)
- btinit = 1;
- return 0;
- }
-
- long getboottime()
- {
- if (!btinit)
- if (boottimeinit() == -1)
- return 0;
- if (bttype == -1)
- if (nlistdo() == -1)
- RETERN(0,boottimeerrno,BT_NLIST)
- if (!bttype)
- RETERN(0,boottimeerrno,BT_NLISTFOUND)
- if (kmemcpy((char *) &boottime,(char *) btvalue,sizeof(boottime)) == -1)
- RETERN(0,boottimeerrno,BT_KMEM)
- return boottime;
- }
-