realpath.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 <limits.h>
  11. #include <stdlib.h>
  12. #include "busybox.h"
  13. int realpath_main(int argc, char **argv)
  14. {
  15. int retval = EXIT_SUCCESS;
  16. #if PATH_MAX > (BUFSIZ+1)
  17. RESERVE_CONFIG_BUFFER(resolved_path, PATH_MAX);
  18. # define resolved_path_MUST_FREE 1
  19. #else
  20. #define resolved_path bb_common_bufsiz1
  21. # define resolved_path_MUST_FREE 0
  22. #endif
  23. if (--argc == 0) {
  24. bb_show_usage();
  25. }
  26. do {
  27. argv++;
  28. if (realpath(*argv, resolved_path) != NULL) {
  29. puts(resolved_path);
  30. } else {
  31. retval = EXIT_FAILURE;
  32. bb_perror_msg("%s", *argv);
  33. }
  34. } while (--argc);
  35. #if ENABLE_FEATURE_CLEAN_UP && resolved_path_MUST_FREE
  36. RELEASE_CONFIG_BUFFER(resolved_path);
  37. #endif
  38. fflush_stdout_and_exit(retval);
  39. }