1 /* vi: set sw=4 ts=4: */
2 /*
3  * Copyright (C) 2003  Manuel Novoa III  <mjn3@codepoet.org>
4  *
5  * Licensed under GPLv2, see file LICENSE in this source tree.
6  */
7 //kbuild:lib-y += bb_cat.o
8 
9 #include "libbb.h"
10 
bb_cat(char ** argv)11 int FAST_FUNC bb_cat(char **argv)
12 {
13 	int fd;
14 	int retval = EXIT_SUCCESS;
15 
16 	if (!*argv)
17 		argv = (char**) &bb_argv_dash;
18 
19 	do {
20 		fd = open_or_warn_stdin(*argv);
21 		if (fd >= 0) {
22 			/* This is not a xfunc - never exits */
23 			off_t r = bb_copyfd_eof(fd, STDOUT_FILENO);
24 			if (fd != STDIN_FILENO)
25 				close(fd);
26 			if (r >= 0)
27 				continue;
28 		}
29 		retval = EXIT_FAILURE;
30 	} while (*++argv);
31 
32 	return retval;
33 }
34