3
0

cat.c 823 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. *
  7. * Licensed under GPLv2, see file License in this tarball for details.
  8. */
  9. /* BB_AUDIT SUSv3 compliant */
  10. /* http://www.opengroup.org/onlinepubs/007904975/utilities/cat.html */
  11. #include "busybox.h"
  12. int bb_cat(char **argv)
  13. {
  14. static char *const argv_dash[] = { "-", NULL };
  15. FILE *f;
  16. int retval = EXIT_SUCCESS;
  17. if (!*argv) argv = (char**) &argv_dash;
  18. do {
  19. f = fopen_or_warn_stdin(*argv);
  20. if (f) {
  21. off_t r = bb_copyfd_eof(fileno(f), STDOUT_FILENO);
  22. fclose_if_not_stdin(f);
  23. if (r >= 0)
  24. continue;
  25. }
  26. retval = EXIT_FAILURE;
  27. } while (*++argv);
  28. return retval;
  29. }
  30. int cat_main(int argc, char **argv)
  31. {
  32. getopt32(argc, argv, "u");
  33. argv += optind;
  34. return bb_cat(argv);
  35. }