2012-01-11 09:22:27 +04:00
|
|
|
/*
|
|
|
|
* clock
|
|
|
|
*
|
2012-07-07 08:08:28 +04:00
|
|
|
* Displays the current time in the upper right corner
|
|
|
|
* of your terminal session; forks on startup.
|
2012-01-11 09:22:27 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <syscall.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <time.h>
|
2012-10-10 08:02:43 +04:00
|
|
|
#include <sys/time.h>
|
2012-01-11 09:22:27 +04:00
|
|
|
|
|
|
|
int main(int argc, char ** argv) {
|
|
|
|
if (!fork()) {
|
|
|
|
struct timeval now;
|
|
|
|
int last = 0;
|
|
|
|
struct tm * timeinfo;
|
|
|
|
char buffer[80];
|
|
|
|
while (1) {
|
2014-05-12 04:40:16 +04:00
|
|
|
gettimeofday(&now, NULL);
|
2012-01-11 09:22:27 +04:00
|
|
|
if (now.tv_sec != last) {
|
|
|
|
last = now.tv_sec;
|
|
|
|
timeinfo = localtime((time_t *)&now.tv_sec);
|
|
|
|
strftime(buffer, 80, "%H:%M:%S", timeinfo);
|
|
|
|
printf("\033[s\033[1;200H\033[9D%s\033[u", buffer);
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|