3 * Copyright (c) 2005-2007 by Michal Nazareicz <mina86@mina86.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 * This is part of Tiny Applications Collection
19 * -> http://tinyapps.sourceforge.net/
22 #define _POSIX_C_SOURCE 199309
28 volatile sig_atomic_t signum
= 0;
30 static void sighandler(int sig
) {
36 struct timespec wait
= { 0, 10000000 };
37 unsigned int m
= 0, ss
= 0;
38 char buffer
[11] = "\r 0:00.00";
41 signal(SIGHUP
, sighandler
);
44 signal(SIGINT
, sighandler
);
47 signal(SIGQUIT
, sighandler
);
50 signal(SIGPIPE
, sighandler
);
53 signal(SIGTERM
, sighandler
);
56 signal(SIGSTOP
, sighandler
);
59 signal(SIGTSTP
, sighandler
);
63 if (write(1, buffer
, 11)!=11) return 1;
65 while (!signum
&& nanosleep(&wait
, &wait
));
67 wait
.tv_nsec
= 10000000;
69 if ((ss
= (ss
+1)%6000)==0) {
71 buffer
[ 1] = m
<1000 ? ' ' : (m
/1000%10 + '0');
72 buffer
[ 1] = m
<100 ? ' ' : (m
/100 %10 + '0');
73 buffer
[ 3] = m
<10 ? ' ' : (m
/10 %10 + '0');
74 buffer
[ 4] = m
%10 + '0';
77 buffer
[ 6] = ss
/1000 + '0';
78 buffer
[ 7] = ss
/100 %10 + '0';
79 buffer
[ 9] = ss
/10 %10 + '0';
80 buffer
[10] = ss
%10 + '0';
83 printf("%07ld\n", 10000000 - wait
.tv_nsec
);