blob: 10eb29c4d65437d14d8fc6421936cbf2b92c7f0d [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Eric Andersencc8ed391999-10-05 16:24:54 +00002/*
Manuel Novoa III cad53642003-03-19 09:13:01 +00003 * cat implementation for busybox
Eric Andersencc8ed391999-10-05 16:24:54 +00004 *
Manuel Novoa III cad53642003-03-19 09:13:01 +00005 * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org>
Eric Andersencc8ed391999-10-05 16:24:54 +00006 *
Denis Vlasenko7039a662006-10-08 17:54:47 +00007 * Licensed under GPLv2, see file License in this tarball for details.
Eric Andersencc8ed391999-10-05 16:24:54 +00008 */
9
Manuel Novoa III cad53642003-03-19 09:13:01 +000010/* BB_AUDIT SUSv3 compliant */
11/* http://www.opengroup.org/onlinepubs/007904975/utilities/cat.html */
12
Eric Andersencbe31da2001-02-20 06:14:08 +000013#include "busybox.h"
Rob Landley8abbee42006-05-31 19:36:04 +000014#include <unistd.h>
Eric Andersencc8ed391999-10-05 16:24:54 +000015
Rob Landleydfba7412006-03-06 20:47:33 +000016int cat_main(int argc, char **argv)
Eric Andersencc8ed391999-10-05 16:24:54 +000017{
Manuel Novoa III cad53642003-03-19 09:13:01 +000018 FILE *f;
19 int retval = EXIT_SUCCESS;
Matt Kraaie7c1af12000-09-27 03:01:40 +000020
Denis Vlasenko67b23e62006-10-03 21:00:06 +000021 getopt32(argc, argv, "u");
Manuel Novoa III cad53642003-03-19 09:13:01 +000022
23 argv += optind;
24 if (!*argv) {
25 *--argv = "-";
Eric Andersencc8ed391999-10-05 16:24:54 +000026 }
Erik Andersene49d5ec2000-02-08 19:58:47 +000027
Manuel Novoa III cad53642003-03-19 09:13:01 +000028 do {
Denis Vlasenko7039a662006-10-08 17:54:47 +000029 f = bb_wfopen_input(*argv);
30 if (f) {
31 off_t r = bb_copyfd_eof(fileno(f), STDOUT_FILENO);
Manuel Novoa III cad53642003-03-19 09:13:01 +000032 bb_fclose_nonstdin(f);
33 if (r >= 0) {
34 continue;
35 }
Erik Andersene49d5ec2000-02-08 19:58:47 +000036 }
Manuel Novoa III cad53642003-03-19 09:13:01 +000037 retval = EXIT_FAILURE;
38 } while (*++argv);
Erik Andersen029011b2000-03-04 21:19:32 +000039
Manuel Novoa III cad53642003-03-19 09:13:01 +000040 return retval;
41}