Movatterモバイル変換


[0]ホーム

URL:


man7.org > Linux >man-pages

Linux/UNIX system programming training


realpath(3) — Linux manual page

NAME |LIBRARY |SYNOPSIS |DESCRIPTION |RETURN VALUE |ERRORS |ATTRIBUTES |VERSIONS |STANDARDS |HISTORY |BUGS |SEE ALSO |COLOPHON

realpath(3)              Library Functions Manualrealpath(3)

NAME        top

       realpath - return the canonicalized absolute pathname

LIBRARY        top

       Standard C library (libc,-lc)

SYNOPSIS        top

#include <limits.h>#include <stdlib.h>char *realpath(const char *restrictpath,char *restrictresolved_path);   Feature Test Macro Requirements for glibc (seefeature_test_macros(7)):realpath():           _XOPEN_SOURCE >= 500               || /* glibc >= 2.19: */ _DEFAULT_SOURCE               || /* glibc <= 2.19: */ _BSD_SOURCE

DESCRIPTION        top

realpath() expands all symbolic links and resolves references to/./,/../ and extra '/' characters in the null-terminated string       named bypath to produce a canonicalized absolute pathname.  The       resulting pathname is stored as a null-terminated string, up to a       maximum ofPATH_MAXbytes, in the buffer pointed to byresolved_path.  The resulting path will have no symbolic link,/./       or/../ components.       Ifresolved_path is specified as NULL, thenrealpath() usesmalloc(3) to allocate a buffer of up toPATH_MAXbytes to hold the       resolved pathname, and returns a pointer to this buffer.  The       caller should deallocate this buffer usingfree(3).

RETURN VALUE        top

       If there is no error,realpath() returns a pointer to theresolved_path.       Otherwise, it returns NULL, the contents of the arrayresolved_path are undefined, anderrno is set to indicate the       error.

ERRORS        top

EACCESRead or search permission was denied for a component of the              path prefix.EINVALpath is NULL.  (Before glibc 2.3, this error is also              returned ifresolved_path is NULL.)EIOAn I/O error occurred while reading from the filesystem.ELOOPToo many symbolic links were encountered in translating the              pathname.ENAMETOOLONG              A component of a pathname exceededNAME_MAXcharacters, or              an entire pathname exceededPATH_MAXcharacters.ENOENTThe named file does not exist.ENOMEMOut of memory.ENOTDIR              A component of the path prefix is not a directory.

ATTRIBUTES        top

       For an explanation of the terms used in this section, seeattributes(7).       ┌──────────────────────────────────────┬───────────────┬─────────┐       │InterfaceAttributeValue│       ├──────────────────────────────────────┼───────────────┼─────────┤       │realpath()                           │ Thread safety │ MT-Safe │       └──────────────────────────────────────┴───────────────┴─────────┘

VERSIONS        top

GNU extensions       If the call fails with eitherEACCESorENOENTandresolved_path       is not NULL, then the prefix ofpath that is not readable or does       not exist is returned inresolved_path.

STANDARDS        top

       POSIX.1-2008.

HISTORY        top

       4.4BSD, POSIX.1-2001, Solaris.       POSIX.1-2001 says that the behavior ifresolved_path is NULL is       implementation-defined.  POSIX.1-2008 specifies the behavior       described in this page.       In 4.4BSD and Solaris, the limit on the pathname length isMAXPATHLEN(found in<sys/param.h>).  SUSv2 prescribesPATH_MAX       andNAME_MAX, as found in<limits.h> or provided by thepathconf(3) function.  A typical source fragment would be           #ifdef PATH_MAX             path_max = PATH_MAX;           #else             path_max = pathconf(path, _PC_PATH_MAX);             if (path_max <= 0)               path_max = 4096;           #endif       (But see the BUGS section.)

BUGS        top

       The POSIX.1-2001 standard version of this function is broken by       design, since it is impossible to determine a suitable size for       the output buffer,resolved_path.  According to POSIX.1-2001 a       buffer of sizePATH_MAXsuffices, butPATH_MAXneed not be a       defined constant, and may have to be obtained usingpathconf(3).       And askingpathconf(3) does not really help, since, on the one       hand POSIX warns that the result ofpathconf(3) may be huge and       unsuitable for mallocing memory, and on the other handpathconf(3)       may return -1 to signify thatPATH_MAXis not bounded.  Theresolved_path == NULL feature, not standardized in POSIX.1-2001,       but standardized in POSIX.1-2008, allows this design problem to be       avoided.

SEE ALSO        top

realpath(1),readlink(2),canonicalize_file_name(3),getcwd(3),pathconf(3),sysconf(3)

COLOPHON        top

       This page is part of theman-pages (Linux kernel and C library       user-space interface documentation) project.  Information about       the project can be found at        ⟨https://www.kernel.org/doc/man-pages/⟩.  If you have a bug report       for this manual page, see       ⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩.       This page was obtained from the tarball man-pages-6.15.tar.gz       fetched from       ⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on       2025-08-11.  If you discover any rendering problems in this HTML       version of the page, or you believe there is a better or more up-       to-date source for the page, or you have corrections or       improvements to the information in this COLOPHON (which isnot       part of the original manual page), send a mail to       man-pages@man7.orgLinux man-pages 6.15            2025-05-17realpath(3)

Pages that refer to this page:dpkg-shlibdeps(1)readlink(1)realpath(1)mount(2)readlink(2)bindtextdomain(3)canonicalize_file_name(3)matchpathcon(3)selinux_restorecon(3)mount(8)restorecon(8)



HTML rendering created 2025-09-06 byMichael Kerrisk, author ofThe Linux Programming Interface.

For details of in-depthLinux/UNIX system programming training courses that I teach, lookhere.

Hosting byjambit GmbH.

Cover of TLPI


[8]ページ先頭

©2009-2025 Movatter.jp