realpath.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 PATH_MAX > (BUFSIZ+1)
  16. RESERVE_CONFIG_BUFFER(resolved_path, PATH_MAX);
  17. # define resolved_path_MUST_FREE 1
  18. #else
  19. #define resolved_path bb_common_bufsiz1
  20. # define resolved_path_MUST_FREE 0
  21. #endif
  22. if (!*++argv) {
  23. bb_show_usage();
  24. }
  25. do {
  26. if (realpath(*argv, resolved_path) != NULL) {
  27. puts(resolved_path);
  28. } else {
  29. retval = EXIT_FAILURE;
  30. bb_simple_perror_msg(*argv);
  31. }
  32. } while (*++argv);
  33. #if ENABLE_FEATURE_CLEAN_UP && resolved_path_MUST_FREE
  34. RELEASE_CONFIG_BUFFER(resolved_path);
  35. #endif
  36. fflush_stdout_and_exit(retval);
  37. }