cat.c 745 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. #include <unistd.h>
  13. int cat_main(int argc, char **argv)
  14. {
  15. FILE *f;
  16. int retval = EXIT_SUCCESS;
  17. getopt32(argc, argv, "u");
  18. argv += optind;
  19. if (!*argv) {
  20. *--argv = "-";
  21. }
  22. do {
  23. f = fopen_or_warn_stdin(*argv);
  24. if (f) {
  25. off_t r = bb_copyfd_eof(fileno(f), STDOUT_FILENO);
  26. fclose_if_not_stdin(f);
  27. if (r >= 0) {
  28. continue;
  29. }
  30. }
  31. retval = EXIT_FAILURE;
  32. } while (*++argv);
  33. return retval;
  34. }