diff options
Diffstat (limited to 'coreutils/watch.c')
-rw-r--r-- | coreutils/watch.c | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/coreutils/watch.c b/coreutils/watch.c index c8b16b908..7b9c6698a 100644 --- a/coreutils/watch.c +++ b/coreutils/watch.c | |||
@@ -3,6 +3,7 @@ | |||
3 | * Mini watch implementation for busybox | 3 | * Mini watch implementation for busybox |
4 | * | 4 | * |
5 | * Copyright (C) 2001 by Michael Habermann <mhabermann@gmx.de> | 5 | * Copyright (C) 2001 by Michael Habermann <mhabermann@gmx.de> |
6 | * Copyrigjt (C) Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org) | ||
6 | * | 7 | * |
7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | 8 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
8 | */ | 9 | */ |
@@ -10,14 +11,9 @@ | |||
10 | /* BB_AUDIT SUSv3 N/A */ | 11 | /* BB_AUDIT SUSv3 N/A */ |
11 | /* BB_AUDIT GNU defects -- only option -n is supported. */ | 12 | /* BB_AUDIT GNU defects -- only option -n is supported. */ |
12 | 13 | ||
13 | /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org) | ||
14 | * | ||
15 | * Removed dependency on date_main(), added proper error checking, and | ||
16 | * reduced size. | ||
17 | */ | ||
18 | |||
19 | #include "busybox.h" | 14 | #include "busybox.h" |
20 | 15 | ||
16 | |||
21 | int watch_main(int argc, char **argv) | 17 | int watch_main(int argc, char **argv) |
22 | { | 18 | { |
23 | int width, len; | 19 | int width, len; |
@@ -26,19 +22,18 @@ int watch_main(int argc, char **argv) | |||
26 | 22 | ||
27 | if (argc < 2) bb_show_usage(); | 23 | if (argc < 2) bb_show_usage(); |
28 | 24 | ||
29 | get_terminal_width_height(1, &width, 0); | 25 | get_terminal_width_height(STDOUT_FILENO, &width, 0); |
30 | header = xzalloc(width--); | 26 | header = xzalloc(width--); |
31 | 27 | ||
32 | /* don't use getopt, because it permutes the arguments */ | 28 | /* don't use getopt, because it permutes the arguments */ |
33 | ++argv; | 29 | ++argv; |
34 | if ((argc > 3) && !strcmp(*argv, "-n")) { | 30 | if ((argc > 3) && argv[0][0] == '-' && argv[0][1] == 'n') { |
35 | period = bb_xgetularg10_bnd(argv[1], 1, UINT_MAX); | 31 | period = bb_xgetularg10_bnd(argv[1], 1, UINT_MAX); |
36 | argv += 2; | 32 | argv += 2; |
37 | } | 33 | } |
38 | watched_argv = argv; | 34 | watched_argv = argv; |
39 | 35 | ||
40 | /* create header */ | 36 | /* create header */ |
41 | |||
42 | len = snprintf(header, width, "Every %ds:", period); | 37 | len = snprintf(header, width, "Every %ds:", period); |
43 | while (*argv && len<width) | 38 | while (*argv && len<width) |
44 | snprintf(header+len, width-len, " %s", *(argv++)); | 39 | snprintf(header+len, width-len, " %s", *(argv++)); |
@@ -50,11 +45,13 @@ int watch_main(int argc, char **argv) | |||
50 | time(&t); | 45 | time(&t); |
51 | thyme = ctime(&t); | 46 | thyme = ctime(&t); |
52 | len = strlen(thyme); | 47 | len = strlen(thyme); |
53 | if (len < width) header[width-len] = 0; | 48 | if (len < width) |
54 | 49 | header[width-len] = 0; | |
55 | printf("\033[H\033[J%s %s\n", header, thyme); | 50 | bb_printf("\033[H\033[J%s %s\n", header, thyme); |
56 | 51 | ||
57 | waitpid(xspawn(watched_argv),0,0); | 52 | waitpid(xspawn(watched_argv),0,0); |
58 | sleep(period); | 53 | sleep(period); |
59 | } | 54 | } |
55 | if (ENABLE_FEATURE_CLEAN_UP) | ||
56 | free(header); | ||
60 | } | 57 | } |