Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 2 | /* |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 3 | * cat implementation for busybox |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 4 | * |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 5 | * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org> |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 6 | * |
Denis Vlasenko | 7039a66 | 2006-10-08 17:54:47 +0000 | [diff] [blame] | 7 | * Licensed under GPLv2, see file License in this tarball for details. |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 8 | */ |
9 | |||||
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 10 | /* BB_AUDIT SUSv3 compliant */ |
11 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/cat.html */ | ||||
12 | |||||
Eric Andersen | cbe31da | 2001-02-20 06:14:08 +0000 | [diff] [blame] | 13 | #include "busybox.h" |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 14 | |
Denis Vlasenko | bf66fbc | 2006-12-21 13:23:14 +0000 | [diff] [blame] | 15 | int bb_cat(char **argv) |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 16 | { |
Denis Vlasenko | e865e81 | 2006-12-21 13:24:58 +0000 | [diff] [blame^] | 17 | static char *const argv_dash[] = { "-", NULL }; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 18 | FILE *f; |
19 | int retval = EXIT_SUCCESS; | ||||
Matt Kraai | e7c1af1 | 2000-09-27 03:01:40 +0000 | [diff] [blame] | 20 | |
Denis Vlasenko | e865e81 | 2006-12-21 13:24:58 +0000 | [diff] [blame^] | 21 | if (!*argv) argv = (char**) &argv_dash; |
22 | |||||
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 23 | do { |
Denis Vlasenko | ddec5af | 2006-10-26 23:25:17 +0000 | [diff] [blame] | 24 | f = fopen_or_warn_stdin(*argv); |
Denis Vlasenko | 7039a66 | 2006-10-08 17:54:47 +0000 | [diff] [blame] | 25 | if (f) { |
26 | off_t r = bb_copyfd_eof(fileno(f), STDOUT_FILENO); | ||||
Denis Vlasenko | ddec5af | 2006-10-26 23:25:17 +0000 | [diff] [blame] | 27 | fclose_if_not_stdin(f); |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 28 | if (r >= 0) { |
29 | continue; | ||||
30 | } | ||||
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 31 | } |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 32 | retval = EXIT_FAILURE; |
33 | } while (*++argv); | ||||
Erik Andersen | 029011b | 2000-03-04 21:19:32 +0000 | [diff] [blame] | 34 | |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 35 | return retval; |
36 | } | ||||
Denis Vlasenko | bf66fbc | 2006-12-21 13:23:14 +0000 | [diff] [blame] | 37 | |
38 | int cat_main(int argc, char **argv) | ||||
39 | { | ||||
40 | getopt32(argc, argv, "u"); | ||||
Denis Vlasenko | bf66fbc | 2006-12-21 13:23:14 +0000 | [diff] [blame] | 41 | argv += optind; |
Denis Vlasenko | bf66fbc | 2006-12-21 13:23:14 +0000 | [diff] [blame] | 42 | return bb_cat(argv); |
43 | } |