realpath.c 832 B

123456789101112131415161718192021222324252627282930313233343536
  1. /* vi: set sw=4 ts=4: */
  2. /* BB_AUDIT SUSv3 N/A -- Apparently a busybox extension. */
  3. /* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
  4. *
  5. * Now does proper error checking on output and returns a failure exit code
  6. * if one or more paths cannot be resolved.
  7. *
  8. * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  9. */
  10. #include "libbb.h"
  11. int realpath_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  12. int realpath_main(int argc UNUSED_PARAM, char **argv)
  13. {
  14. int retval = EXIT_SUCCESS;
  15. if (!*++argv) {
  16. bb_show_usage();
  17. }
  18. do {
  19. char *resolved_path = xmalloc_realpath(*argv);
  20. if (resolved_path != NULL) {
  21. puts(resolved_path);
  22. free(resolved_path);
  23. } else {
  24. retval = EXIT_FAILURE;
  25. bb_simple_perror_msg(*argv);
  26. }
  27. } while (*++argv);
  28. fflush_stdout_and_exit(retval);
  29. }