home *** CD-ROM | disk | FTP | other *** search
- /* UpTime.c
-
- Written by Christopher A. Wichura (caw@miroc.chi.il.us)
-
- Status: Public Domain. Do with it as you wish.
-
- In using this program, you accept the responsibility for any and
- all damages, loss of money/productivity/etc that may occur while
- UpTime is in use. C. Wichura can not and will not be held accountable.
-
- Description:
- UpTime should be run as part of your startup sequence with
- the SET option. This will create a global environment
- variable with the time the system was booted. Running
- UpTime with no arguements will then read this variable and
- print out the time the system booted. Useful for people
- who leave their system on for great lengths of time and
- would like to have an easy way to tell how long it has
- been up.
-
- Note that the last boot message is displayed even when
- the SET option is being used. Therefor, you may wish to
- redirect the output to NULL: (or, pray tell, NIL:) when
- running UpTime in your Startup-Sequence. Also, ENV: must
- exist before UpTime is run.
- */
-
- #include <exec/types.h>
- #include <proto/exec.h>
- #include <proto/dos.h>
- #include <exec/libraries.h>
- #include <dos/rdargs.h>
- #include <dos/datetime.h>
- #include <dos/var.h>
- #include <string.h>
-
- #define ARG_TEMPLATE "SET/S"
- #define ARG_SET 0
- #define ARG_sizeof 1
-
- LONG __saveds __asm UpTime(register __d0 LONG CmdLen, register __a0 char *CmdPtr)
- {
- register struct Library *DOSBase;
- struct RDArgs *ArgsPtr;
- struct RDArgs MyArgs;
- char *ArgArray[ARG_sizeof];
- LONG error = 0;
- struct DateTime dt;
- char Day [LEN_DATSTRING+1];
- char Date[LEN_DATSTRING+1];
- char Time[LEN_DATSTRING+1];
-
- if (!(DOSBase = OpenLibrary("dos.library", 36)))
- return 20;
-
- memset((char *)&MyArgs, 0, sizeof(struct RDArgs));
- memset(ArgArray, 0, sizeof(ArgArray));
-
- if (!(ArgsPtr = ReadArgs(ARG_TEMPLATE, (LONG *)&ArgArray, &MyArgs))) {
- PrintFault(IoErr(), NULL);
- error = 15;
- goto MyExit;
- }
-
- /* if we are to set the UpTime then we do so here */
-
- if (ArgArray[ARG_SET]) {
- DateStamp((LONG *)&dt.dat_Stamp);
-
- if (!SetVar("UpTime", (UBYTE *)&dt.dat_Stamp, sizeof(struct DateStamp), LV_VAR|GVF_GLOBAL_ONLY|GVF_BINARY_VAR)) {
- PutStr("Error writing UpTime data.\n");
- error = 5;
- goto MyExit;
- }
- }
-
- /* now read an print the UpTime */
-
- if (GetVar("UpTime", (UBYTE *)&dt.dat_Stamp, sizeof(struct DateStamp), LV_VAR|GVF_GLOBAL_ONLY|GVF_BINARY_VAR) != sizeof(struct DateStamp)) {
- PutStr("Error reading UpTime data.\n");
- error = 5;
- goto MyExit;
- }
-
- memset(Day, 0, LEN_DATSTRING + 1);
- memset(Date, 0, LEN_DATSTRING + 1);
- memset(Time, 0, LEN_DATSTRING + 1);
-
- dt.dat_Format = FORMAT_DOS;
- dt.dat_Flags = 0;
- dt.dat_StrDay = Day;
- dt.dat_StrDate = Date;
- dt.dat_StrTime = Time;
- DateToStr(&dt);
-
- PutStr("System last booted on ");
- PutStr(Day);
- PutStr(", ");
- PutStr(Date);
- PutStr(" at ");
- PutStr(Time);
- PutStr(".\n");
-
- MyExit:
- CloseLibrary(DOSBase);
-
- return error;
- }
-