home *** CD-ROM | disk | FTP | other *** search
- /*
- * ledtime()
- *
- * written by: Stephen J. Friedl
- * V-Systems, Inc.
- * +1 714 545 6442
- * friedl@mtndew.Tustin.CA.US
- *
- * Modified to use ioctl() by D'Arcy J.M. Cain (darcy@druid.UUCP)
- *
- * This program sits in the background and writes the current time to the
- * led device via ioctl function 1 so the Everex front-panel display always
- * shows the time. This is run from inittab. If you prefer not to run this
- * change the relevant line in the Makefile.
- *
- * This is in the public domain (not that you couldn't figure
- * this out in about two minutes anyway).
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <errno.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <time.h>
-
- int main(int argc, char **argv)
- {
- const char *led_device = "/dev/ledclock";
- struct tm *tm;
- time_t now; /* current UNIX time */
- int led; /* LED device */
- char buf[40]; /* buffer for the time string */
-
- if (argc > 1) /* we can name led device if we want */
- led_device = argv[1];
-
- if ((led = open(led_device, O_WRONLY)) == -1)
- {
- fprintf(stderr, "Can't open %s - %s", led_device, strerror(errno));
- return(1);
- }
-
- for (;;)
- {
- time(&now);
- tm = localtime(&now);
-
- #ifdef CLOCK12
- if (tm->tm_hour > 12)
- tm->tm_hour -= 12;
- else if (!tm->tm_hour)
- tm->tm_hour = 12;
-
- sprintf(buf, "%2d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec);
- #else
- sprintf(buf, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min, tm->tm_sec);
- #endif
- ioctl(led, 1, buf);
- sleep(1);
- }
- }
-