realpath(3)

realpath3

Returns the canonicalized absolute pathname

Usage

#include <stdlib.h>

char *

realpath(const char * restrict pathname, char * restrict resolved_path);

Library

Standard C Library (libc, -lc)

Overview

The realpath() function resolves all symbolic links, extra “/” characters and references to /./ and /../ in pathname, and copies the resulting absolute pathname into the memory pointed to by resolved_path. The resolved_path argument must point to a buffer capable of storing at least PATH_MAX characters, or be NULL.

The realpath() function will resolve both absolute and relative paths and return the absolute pathname corresponding to pathname. All components of pathname must exist when realpath() is called, and all but the last component must name either directories or symlinks pointing to the directories.

Return values

On success, the realpath() function returns resolved_path if it was not NULL, or a pointer to a null-terminated string which must be freed by the caller if it was. If an error occurs, realpath() returns NULL, and if resolved_path was not NULL, the array that it points to contains the pathname which caused the problem.

Errors

The function realpath() may fail and set the external variable errno for any of the errors specified for the library functions lstat(2), readlink(2) and getcwd(3).

Releases

87 releases since FreeBSD 2.0.5-RELEASE; the text changed 44 times.

  1. 2.0.5–2.2.5
  2. 2.2.6–3.4
  3. 3.5–3.5.1
  4. 4.0
  5. 4.1–4.3
  6. 4.4
  7. 4.5–4.11
  8. 5.0
  9. 5.1–6.3
  10. 6.4
  11. 7.0
  12. 7.1
  13. 7.2
  14. 7.3
  15. 7.4
  16. 8.0
  17. 8.1
  18. 8.2
  19. 8.3
  20. 8.4
  21. 9.0
  22. 9.1
  23. 9.2
  24. 9.3
  25. 10.0
  26. 10.1
  27. 10.2
  28. 10.3
  29. 10.4
  30. 11.0
  31. 11.1
  32. 11.2
  33. 11.3
  34. 11.4
  35. 12.0
  36. 12.1
  37. 12.2
  38. 12.3
  39. 12.4
  40. 13.0–13.2
  41. 13.3–14.3
  42. 14.4
  43. 14.5
  44. 15.0
  45. 15.1–16.0

Standards

The realpath() function conforms to IEEE Std 1003.1-2001 (“POSIX.1”).

History

The realpath() function first appeared in 4.4BSD.

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.