---
name: "realpath"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["linux", "freebsd", "macos"]
url: "https://new.carta.tech/realpath/3"
---

# realpath(3)

returns the canonicalized absolute pathname

## NAME

**realpath** – returns the canonicalized absolute pathname

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

**#include \<stdlib.h\>**

*char \**\

**realpath**(*const char \* restrict pathname*, *char \* restrict resolved\_path*);

## DESCRIPTION

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)](/lstat/2.md), [readlink(2)](/readlink/2.md) and [getcwd(3)](/getcwd/3.md).

## SEE ALSO

[basename(3)](/basename/3.md), [dirname(3)](/dirname/3.md), [free(3)](/free/3.md), [getcwd(3)](/getcwd/3.md)

## STANDARDS

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

## HISTORY

The **realpath**() function first appeared in 4.4BSD.
