diff options
author | Manuel Novoa III <mjn3@codepoet.org> | 2003-03-19 09:13:01 +0000 |
---|---|---|
committer | Manuel Novoa III <mjn3@codepoet.org> | 2003-03-19 09:13:01 +0000 |
commit | cad5364599eb5062d59e0c397ed638ddd61a8d5d (patch) | |
tree | a318d0f03aa076c74b576ea45dc543a5669e8e91 /coreutils/tty.c | |
parent | e01f9662a5bd5d91be4f6b3941b57fff73cd5af1 (diff) | |
download | busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.gz busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.tar.bz2 busybox-w32-cad5364599eb5062d59e0c397ed638ddd61a8d5d.zip |
Major coreutils update.
Diffstat (limited to 'coreutils/tty.c')
-rw-r--r-- | coreutils/tty.c | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/coreutils/tty.c b/coreutils/tty.c index 4510c2996..cd2c784fd 100644 --- a/coreutils/tty.c +++ b/coreutils/tty.c | |||
@@ -1,8 +1,8 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | 2 | /* |
3 | * Mini tty implementation for busybox | 3 | * tty implementation for busybox |
4 | * | 4 | * |
5 | * Copyright (C) 2000 Edward Betts <edward@debian.org>. | 5 | * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org> |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by | 8 | * it under the terms of the GNU General Public License as published by |
@@ -20,25 +20,39 @@ | |||
20 | * | 20 | * |
21 | */ | 21 | */ |
22 | 22 | ||
23 | /* BB_AUDIT SUSv3 compliant */ | ||
24 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/tty.html */ | ||
25 | |||
23 | #include <stdio.h> | 26 | #include <stdio.h> |
24 | #include <stdlib.h> | 27 | #include <stdlib.h> |
25 | #include <unistd.h> | 28 | #include <unistd.h> |
26 | #include <sys/types.h> | ||
27 | #include "busybox.h" | 29 | #include "busybox.h" |
28 | 30 | ||
29 | extern int tty_main(int argc, char **argv) | 31 | extern int tty_main(int argc, char **argv) |
30 | { | 32 | { |
31 | char *tty; | 33 | const char *s; |
32 | 34 | int silent; /* Note: No longer relevant in SUSv3. */ | |
33 | if (argc > 1) { | 35 | int retval; |
34 | if (argv[1][0] != '-' || argv[1][1] != 's') | 36 | |
35 | show_usage(); | 37 | bb_default_error_retval = 2; /* SUSv3 requires > 1 for error. */ |
36 | } else { | 38 | |
37 | tty = ttyname(0); | 39 | silent = bb_getopt_ulflags(argc, argv, "s"); |
38 | if (tty) | 40 | |
39 | puts(tty); | 41 | /* gnu tty outputs a warning that it is ignoring all args. */ |
40 | else | 42 | bb_warn_ignoring_args(argc - optind); |
41 | puts("not a tty"); | 43 | |
44 | retval = 0; | ||
45 | |||
46 | if ((s = ttyname(0)) == NULL) { | ||
47 | /* According to SUSv3, ttyname can on fail with EBADF or ENOTTY. | ||
48 | * We know the file descriptor is good, so failure means not a tty. */ | ||
49 | s = "not a tty"; | ||
50 | retval = 1; | ||
51 | } | ||
52 | |||
53 | if (!silent) { | ||
54 | puts(s); | ||
42 | } | 55 | } |
43 | return(isatty(0) ? EXIT_SUCCESS : EXIT_FAILURE); | 56 | |
57 | bb_fflush_stdout_and_exit(retval); | ||
44 | } | 58 | } |