Movatterモバイル変換


[0]ホーム

URL:


man7.org > Linux >man-pages

Linux/UNIX system programming training


realpath(3p) — Linux manual page

PROLOG |NAME |SYNOPSIS |DESCRIPTION |RETURN VALUE |ERRORS |EXAMPLES |APPLICATION USAGE |RATIONALE |FUTURE DIRECTIONS |SEE ALSO |COPYRIGHT

REALPATH(3P)            POSIX Programmer's ManualREALPATH(3P)

PROLOG        top

       This manual page is part of the POSIX Programmer's Manual.  The       Linux implementation of this interface may differ (consult the       corresponding Linux manual page for details of Linux behavior), or       the interface may not be implemented on Linux.

NAME        top

       realpath — resolve a pathname

SYNOPSIS        top

       #include <stdlib.h>       char *realpath(const char *restrictfile_name,           char *restrictresolved_name);

DESCRIPTION        top

       Therealpath() function shall derive, from the pathname pointed to       byfile_name, an absolute pathname that resolves to the same       directory entry, whose resolution does not involve'.','..', or       symbolic links. Ifresolved_name is a null pointer, the generated       pathname shall be stored as a null-terminated string in a buffer       allocated as if by a call tomalloc().  Otherwise, if {PATH_MAX}       is defined as a constant in the<limits.h> header, then the       generated pathname shall be stored as a null-terminated string, up       to a maximum of {PATH_MAX} bytes, in the buffer pointed to byresolved_name.       Ifresolved_name is not a null pointer and {PATH_MAX} is not       defined as a constant in the<limits.h> header, the behavior is       undefined.

RETURN VALUE        top

       Upon successful completion,realpath() shall return a pointer to       the buffer containing the resolved name.  Otherwise,realpath()       shall return a null pointer and seterrno to indicate the error.       If theresolved_name argument is a null pointer, the pointer       returned byrealpath() can be passed tofree().       If theresolved_name argument is not a null pointer and therealpath() function fails, the contents of the buffer pointed to       byresolved_name are undefined.

ERRORS        top

       Therealpath() function shall fail if:EACCESSearch permission was denied for a component of the path              prefix offile_name.EINVALThefile_name argument is a null pointer.EIOAn error occurred while reading from the file system.ELOOPA loop exists in symbolic links encountered during              resolution of thefile_name argument.ENAMETOOLONG              The length of a component of a pathname is longer than              {NAME_MAX}.ENOENTA component offile_name does not name an existing file orfile_name points to an empty string.ENOTDIR              A component of the path prefix names an existing file that              is neither a directory nor a symbolic link to a directory,              or thefile_name argument contains at least one non-<slash>              character and ends with one or more trailing <slash>              characters and the last pathname component names an              existing file that is neither a directory nor a symbolic              link to a directory.       Therealpath() function may fail if:EACCESThefile_name argument does not begin with a <slash> and              none of the symbolic links (if any) processed during              pathname resolution offile_name had contents that began              with a <slash>, and either search permission was denied for              the current directory or read or search permission was              denied for a directory above the current directory in the              file hierarchy.ELOOPMore than {SYMLOOP_MAX} symbolic links were encountered              during resolution of thefile_name argument.ENAMETOOLONG              The length of a pathname exceeds {PATH_MAX}, or pathname              resolution of a symbolic link produced an intermediate              result with a length that exceeds {PATH_MAX}.ENOMEMInsufficient storage space is available.The following sections are informative.

EXAMPLES        top

Generating an Absolute Pathname       The following example generates an absolute pathname for the file       identified by thesymlinkpath argument. The generated pathname is       stored in the buffer pointed to byactualpath.           #include <stdlib.h>           ...           char *symlinkpath = "/tmp/symlink/file";           char *actualpath;           actualpath = realpath(symlinkpath, NULL);           if (actualpath != NULL)           {               ... use actualpath ...               free(actualpath);           }           else           {               ... handle error ...           }

APPLICATION USAGE        top

       For functions that allocate memory as if bymalloc(), the       application should release such memory when it is no longer       required by a call tofree().  Forrealpath(), this is the return       value.

RATIONALE        top

       Sincerealpath() has nolength argument, if {PATH_MAX} is not       defined as a constant in<limits.h>, applications have no way of       determining how large a buffer they need to allocate for it to be       safe to pass torealpath().  A {PATH_MAX} value obtained from a       priorpathconf() call is out-of-date by the timerealpath() is       called. Hence the only reliable way to userealpath() when       {PATH_MAX} is not defined in<limits.h> is to pass a null pointer       forresolved_name so thatrealpath() will allocate a buffer of the       necessary size.

FUTURE DIRECTIONS        top

       None.

SEE ALSO        top

fpathconf(3p),free(3p),getcwd(3p),sysconf(3p)       The Base Definitions volume of POSIX.1‐2017,limits.h(0p),stdlib.h(0p)

COPYRIGHT        top

       Portions of this text are reprinted and reproduced in electronic       form from IEEE Std 1003.1-2017, Standard for Information       Technology -- Portable Operating System Interface (POSIX), The       Open Group Base Specifications Issue 7, 2018 Edition, Copyright       (C) 2018 by the Institute of Electrical and Electronics Engineers,       Inc and The Open Group.  In the event of any discrepancy between       this version and the original IEEE and The Open Group Standard,       the original IEEE and The Open Group Standard is the referee       document. The original Standard can be obtained online athttp://www.opengroup.org/unix/online.html .       Any typographical or formatting errors that appear in this page       are most likely to have been introduced during the conversion of       the source files to man page format. To report such errors, seehttps://www.kernel.org/doc/man-pages/reporting_bugs.html .IEEE/The Open Group                2017REALPATH(3P)

Pages that refer to this page:stdlib.h(0p)



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