3
0

realpath.c 993 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 source tree.
  9. */
  10. //usage:#define realpath_trivial_usage
  11. //usage: "FILE..."
  12. //usage:#define realpath_full_usage "\n\n"
  13. //usage: "Return the absolute pathnames of given FILE"
  14. #include "libbb.h"
  15. int realpath_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  16. int realpath_main(int argc UNUSED_PARAM, char **argv)
  17. {
  18. int retval = EXIT_SUCCESS;
  19. if (!*++argv) {
  20. bb_show_usage();
  21. }
  22. do {
  23. char *resolved_path = xmalloc_realpath(*argv);
  24. if (resolved_path != NULL) {
  25. puts(resolved_path);
  26. free(resolved_path);
  27. } else {
  28. retval = EXIT_FAILURE;
  29. bb_simple_perror_msg(*argv);
  30. }
  31. } while (*++argv);
  32. fflush_stdout_and_exit(retval);
  33. }