[821] | 1 | /* vi: set sw=4 ts=4: */
|
---|
| 2 | /*
|
---|
| 3 | * cat implementation for busybox
|
---|
| 4 | *
|
---|
| 5 | * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org>
|
---|
| 6 | *
|
---|
[2725] | 7 | * Licensed under GPLv2, see file LICENSE in this source tree.
|
---|
[821] | 8 | */
|
---|
| 9 |
|
---|
| 10 | /* BB_AUDIT SUSv3 compliant */
|
---|
| 11 | /* http://www.opengroup.org/onlinepubs/007904975/utilities/cat.html */
|
---|
| 12 |
|
---|
[2725] | 13 | //kbuild:lib-$(CONFIG_CAT) += cat.o
|
---|
| 14 | //kbuild:lib-$(CONFIG_MORE) += cat.o # more uses it if stdout isn't a tty
|
---|
| 15 | //kbuild:lib-$(CONFIG_LESS) += cat.o # less too
|
---|
| 16 | //kbuild:lib-$(CONFIG_CRONTAB) += cat.o # crontab -l
|
---|
| 17 |
|
---|
| 18 | //config:config CAT
|
---|
| 19 | //config: bool "cat"
|
---|
| 20 | //config: default y
|
---|
| 21 | //config: help
|
---|
| 22 | //config: cat is used to concatenate files and print them to the standard
|
---|
| 23 | //config: output. Enable this option if you wish to enable the 'cat' utility.
|
---|
| 24 |
|
---|
[3232] | 25 | //usage:#define cat_trivial_usage
|
---|
| 26 | //usage: "[FILE]..."
|
---|
| 27 | //usage:#define cat_full_usage "\n\n"
|
---|
| 28 | //usage: "Concatenate FILEs and print them to stdout"
|
---|
| 29 | //usage:
|
---|
| 30 | //usage:#define cat_example_usage
|
---|
| 31 | //usage: "$ cat /proc/uptime\n"
|
---|
| 32 | //usage: "110716.72 17.67"
|
---|
| 33 |
|
---|
[1765] | 34 | #include "libbb.h"
|
---|
[821] | 35 |
|
---|
[1765] | 36 | /* This is a NOFORK applet. Be very careful! */
|
---|
| 37 |
|
---|
| 38 |
|
---|
| 39 | int bb_cat(char **argv)
|
---|
[821] | 40 | {
|
---|
[1765] | 41 | int fd;
|
---|
[821] | 42 | int retval = EXIT_SUCCESS;
|
---|
| 43 |
|
---|
[1765] | 44 | if (!*argv)
|
---|
[2725] | 45 | argv = (char**) &bb_argv_dash;
|
---|
[821] | 46 |
|
---|
| 47 | do {
|
---|
[2725] | 48 | fd = open_or_warn_stdin(*argv);
|
---|
[1765] | 49 | if (fd >= 0) {
|
---|
[2725] | 50 | /* This is not a xfunc - never exits */
|
---|
[1765] | 51 | off_t r = bb_copyfd_eof(fd, STDOUT_FILENO);
|
---|
| 52 | if (fd != STDIN_FILENO)
|
---|
| 53 | close(fd);
|
---|
| 54 | if (r >= 0)
|
---|
[821] | 55 | continue;
|
---|
| 56 | }
|
---|
| 57 | retval = EXIT_FAILURE;
|
---|
| 58 | } while (*++argv);
|
---|
| 59 |
|
---|
| 60 | return retval;
|
---|
| 61 | }
|
---|
[1765] | 62 |
|
---|
[2725] | 63 | int cat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
---|
| 64 | int cat_main(int argc UNUSED_PARAM, char **argv)
|
---|
[1765] | 65 | {
|
---|
| 66 | getopt32(argv, "u");
|
---|
| 67 | argv += optind;
|
---|
| 68 | return bb_cat(argv);
|
---|
| 69 | }
|
---|