3
0

bb_cat.c 614 B

123456789101112131415161718192021222324252627282930313233
  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. #include "libbb.h"
  9. int FAST_FUNC bb_cat(char **argv)
  10. {
  11. int fd;
  12. int retval = EXIT_SUCCESS;
  13. if (!*argv)
  14. argv = (char**) &bb_argv_dash;
  15. do {
  16. fd = open_or_warn_stdin(*argv);
  17. if (fd >= 0) {
  18. /* This is not a xfunc - never exits */
  19. off_t r = bb_copyfd_eof(fd, STDOUT_FILENO);
  20. if (fd != STDIN_FILENO)
  21. close(fd);
  22. if (r >= 0)
  23. continue;
  24. }
  25. retval = EXIT_FAILURE;
  26. } while (*++argv);
  27. return retval;
  28. }