diff options
Diffstat (limited to 'coreutils/cat.c')
-rw-r--r-- | coreutils/cat.c | 60 |
1 files changed, 37 insertions, 23 deletions
diff --git a/coreutils/cat.c b/coreutils/cat.c index 33f15da71..865275767 100644 --- a/coreutils/cat.c +++ b/coreutils/cat.c | |||
@@ -1,9 +1,8 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | 2 | /* |
3 | * Mini Cat implementation for busybox | 3 | * cat implementation for busybox |
4 | * | 4 | * |
5 | * Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen | 5 | * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org> |
6 | * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org> | ||
7 | * | 6 | * |
8 | * 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 |
9 | * 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 |
@@ -21,33 +20,48 @@ | |||
21 | * | 20 | * |
22 | */ | 21 | */ |
23 | 22 | ||
23 | /* BB_AUDIT SUSv3 compliant */ | ||
24 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/cat.html */ | ||
25 | |||
26 | /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org) | ||
27 | * | ||
28 | * This is a new implementation of 'cat' which aims to be SUSv3 compliant. | ||
29 | * | ||
30 | * Changes from the previous implementation include: | ||
31 | * 1) Multiple '-' args are accepted as required by SUSv3. The previous | ||
32 | * implementation would close stdin and segfault on a subsequent '-'. | ||
33 | * 2) The '-u' options is required by SUSv3. Note that the specified | ||
34 | * behavior for '-u' is done by default, so all we need do is accept | ||
35 | * the option. | ||
36 | */ | ||
37 | |||
24 | #include <stdlib.h> | 38 | #include <stdlib.h> |
25 | #include <string.h> | 39 | #include <stdio.h> |
40 | #include <unistd.h> | ||
26 | #include "busybox.h" | 41 | #include "busybox.h" |
27 | 42 | ||
28 | extern int cat_main(int argc, char **argv) | 43 | extern int cat_main(int argc, char **argv) |
29 | { | 44 | { |
30 | int status = EXIT_SUCCESS; | 45 | FILE *f; |
46 | int retval = EXIT_SUCCESS; | ||
31 | 47 | ||
32 | if (argc == 1) { | 48 | bb_getopt_ulflags(argc, argv, "u"); |
33 | print_file(stdin); | 49 | |
34 | return status; | 50 | argv += optind; |
51 | if (!*argv) { | ||
52 | *--argv = "-"; | ||
35 | } | 53 | } |
36 | 54 | ||
37 | while (--argc > 0) { | 55 | do { |
38 | if(!(strcmp(*++argv, "-"))) { | 56 | if ((f = bb_wfopen_input(*argv)) != NULL) { |
39 | print_file(stdin); | 57 | int r = bb_copyfd(fileno(f), STDOUT_FILENO, 0); |
40 | } else if (! print_file_by_name(*argv)) { | 58 | bb_fclose_nonstdin(f); |
41 | status = EXIT_FAILURE; | 59 | if (r >= 0) { |
60 | continue; | ||
61 | } | ||
42 | } | 62 | } |
43 | } | 63 | retval = EXIT_FAILURE; |
44 | return status; | 64 | } while (*++argv); |
45 | } | ||
46 | 65 | ||
47 | /* | 66 | return retval; |
48 | Local Variables: | 67 | } |
49 | c-file-style: "linux" | ||
50 | c-basic-offset: 4 | ||
51 | tab-width: 4 | ||
52 | End: | ||
53 | */ | ||