Fix libkeymap.pc installation
[platform/upstream/kbd.git] / contrib / vcstime.c
1 /*
2  * vcstime.c
3  *
4  * Show time in upper right hand corner of the console screen
5  * aeb, 951202, following a suggestion by Miguel de Icaza.
6  */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <fcntl.h>
11 #include <time.h>
12
13 void
14 fatal(char *s) {
15     perror(s);
16     exit(1);
17 }
18
19 int
20 number_of_columns() {
21     int fda;
22     unsigned char rc[2];        /* unsigned: Ranty@soon.com */
23
24     if((fda = open("/dev/vcsa", O_RDONLY)) < 0
25             && (fda = open("/dev/vcsa0", O_RDONLY)) < 0)
26         fatal("/dev/vcsa");
27     if(read(fda, rc, 2) != 2)
28         fatal("/dev/vcsa");
29     close(fda);
30     return rc[1];
31 }
32
33 int
34 main(){
35     int fd;
36     int cols = number_of_columns();
37     time_t tid;
38     struct tm *t;
39     char tijd[10];
40
41     if((fd = open("/dev/vcs", O_WRONLY)) < 0
42             && (fd = open("/dev/vcs0", O_WRONLY)) < 0)
43         fatal("/dev/vcs");
44
45     while(1) {
46         lseek(fd, cols-10, 0);
47         tid = time(0);
48         t = localtime(&tid);
49         sprintf(tijd, " %02d:%02d:%02d", t->tm_hour, t->tm_min, t->tm_sec);
50         write(fd, tijd, 9);
51         usleep(500000L);        /* or sleep(1); */
52     }
53 }