home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Other / power / power.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-15  |  2.2 KB  |  110 lines

  1. #include <sys/types.h>
  2. #include <sys/file.h>
  3.  
  4. #include <mon/nvram.h>
  5. #include <sgtty.h>
  6. #include <nextdev/video.h>
  7.  
  8. #include <stdlib.h>
  9.  
  10. /*
  11.  * Code for manipulating the RTC for auto-power-on.
  12.  * Based on some /usr/include-searching and disassembling Preferences
  13.  * Hope you can use it.
  14.  * These routines wants to be root; otherwise opening of /dev/vid0 will fail.
  15.  * Caveat: these routines depends on 32bit int's (as god intended int's
  16.  *         to be :-) )
  17.  */
  18.  
  19.  
  20.  
  21. /*
  22.  * Purpose: low-level routine to open device, make an ioctl and close
  23.  *          device.
  24.  * Return Code: 0 if opening or ioctl fails; 1 for success
  25.  * Side effects: data pointed to by ptr may be modified.
  26.  */
  27. static int
  28. do_nvram_io( int code, void *ptr)
  29. {
  30.   int    fd,ret;
  31.  
  32.   ret = 0;
  33.   if( (fd = open( "/dev/vid0", O_RDONLY)) >= 0 ) {
  34.     if( ioctl( fd, code, ptr) >= 0) {
  35.       ret = 1;
  36.     }
  37.     (void) close( fd );
  38.   }
  39.   return ret;
  40. }
  41.  
  42.  
  43. /*
  44.  * Purpose: sets an epoche-time for powering on
  45.  * Return-code: 0 for failure, 1 for success
  46.  * Side-effects: sets a power-on date
  47.  */
  48. int
  49. set_nvram_power_on_alarm( int argtime )
  50. {
  51.   struct alarm  tmpalarm;
  52.  
  53.   /* get old copy and modify it */
  54.   if( do_nvram_io( DKIOCGALARM, &tmpalarm) > 0) {
  55.     tmpalarm.alarm_time = argtime;
  56.     if( do_nvram_io( DKIOCSALARM, &tmpalarm) > 0) {
  57.       return 1;
  58.     }
  59.   }
  60.   return 0;
  61. }
  62.  
  63. /*
  64.  * Purpose: get current power-on time
  65.  * return-code: date as epoche-time (seconds since 1970)
  66.  */
  67. int
  68. get_nvram_power_on_alarm()
  69. {
  70.   struct alarm  tmpalarm;
  71.  
  72.   if( do_nvram_io( DKIOCGALARM, &tmpalarm) > 0) {
  73.     return tmpalarm.alarm_time;
  74.   }
  75.   return 0;
  76. }
  77.  
  78. /*
  79.  * Purpose: is the power-on-date feature enabled ?
  80.  * return-code: 1 for yes, 0 for no or failure
  81.  */
  82. int
  83. get_nvram_power_on_alarm_enabled()
  84. {
  85.   struct alarm  tmpalarm;
  86.  
  87.   if( do_nvram_io( DKIOCGALARM, &tmpalarm) > 0) {
  88.     return tmpalarm.alarm_enabled;
  89.   }
  90.   return 0;
  91. }
  92.  
  93. /*
  94.  * Purpose: enable/disable power-on-date feature
  95.  * return-code: 0 for failure, 1 for success
  96.  */
  97. int
  98. set_nvram_power_on_alarm_enabled( int argflag )
  99. {
  100.   struct alarm  tmpalarm;
  101.  
  102.   if( do_nvram_io( DKIOCGALARM, &tmpalarm) > 0) {
  103.     tmpalarm.alarm_enabled = argflag;
  104.     if( do_nvram_io( DKIOCSALARM, &tmpalarm) > 0) {
  105.       return 1;
  106.     }
  107.   }
  108.   return 0;
  109. }
  110.