Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

realpath(3) [mojave man page]

REALPATH(3)						   BSD Library Functions Manual 					       REALPATH(3)

NAME
realpath -- returns the canonicalized absolute pathname SYNOPSIS
#include <stdlib.h> char * realpath(const char *restrict file_name, char *restrict resolved_name); DESCRIPTION
The realpath() function resolves all symbolic links, extra ``/'' characters, and references to /./ and /../ in file_name. If the resolved_name argument is non-NULL, the resulting absolute pathname is copied there (it must refer to a buffer capable of storing at least PATH_MAX characters). As a permitted extension to the standard, if resolved_name is NULL, memory is allocated for the resulting absolute pathname, and is returned by realpath(). This memory should be freed by a call to free(3) when no longer needed. The realpath() function will resolve both absolute and relative paths and return the absolute pathname corresponding to file_name. All com- ponents of file_name must exist when realpath() is called. RETURN VALUES
On success, the realpath() function returns the address of the resulting absolute pathname, which is resolved_name if it was non-NULL, or the address of newly allocated memory. If an error occurs, realpath() returns NULL. If resolved_name was non-NULL, it will contain the pathname which caused the problem. VARIANTS
Defining _DARWIN_C_SOURCE or _DARWIN_BETTER_REALPATH before including stdio.h will cause the provided implementation of realpath() to use F_GETPATH from fcntl(2) to discover the path. ERRORS
The function realpath() may fail and set the external variable errno for any of the errors specified for the library functions alloca(3), getattrlist(2), getcwd(3), lstat(2), readlink(2), stat(2), and strdup(3). LEGACY SYNOPSIS
#include <sys/param.h> #include <stdlib.h> The include file <sys/param.h> is necessary. LEGACY DESCRIPTION
In legacy mode, the last component of file_name does not need to exist when realpath() is called. SEE ALSO
free(3), getcwd(3), compat(5) HISTORY
The realpath() function first appeared in 4.4BSD. BSD
April 5, 2008 BSD

Check Out this Related Man Page

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

PROLOG
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the correspond- ing Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux. NAME
realpath - resolve a pathname SYNOPSIS
#include <stdlib.h> char *realpath(const char *restrict file_name, char *restrict resolved_name); DESCRIPTION
The realpath() function shall derive, from the pathname pointed to by file_name, an absolute pathname that names the same file, whose reso- lution does not involve '.', '..', or symbolic links. The generated pathname shall be stored as a null-terminated string, up to a maximum of {PATH_MAX} bytes, in the buffer pointed to by resolved_name. If resolved_name is a null pointer, the behavior of realpath() is implementation-defined. RETURN VALUE
Upon successful completion, realpath() shall return a pointer to the resolved name. Otherwise, realpath() shall return a null pointer and set errno to indicate the error, and the contents of the buffer pointed to by resolved_name are undefined. ERRORS
The realpath() function shall fail if: EACCES Read or search permission was denied for a component of file_name. EINVAL The file_name argument is a null pointer. EIO An error occurred while reading from the file system. ELOOP A loop exists in symbolic links encountered during resolution of the path argument. ENAMETOOLONG The length of the file_name argument exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}. ENOENT A component of file_name does not name an existing file or file_name points to an empty string. ENOTDIR A component of the path prefix is not a directory. The realpath() function may fail if: ELOOP More than {SYMLOOP_MAX} symbolic links were encountered during resolution of the path argument. ENAMETOOLONG Pathname resolution of a symbolic link produced an intermediate result whose length exceeds {PATH_MAX}. ENOMEM Insufficient storage space is available. The following sections are informative. EXAMPLES
Generating an Absolute Pathname The following example generates an absolute pathname for the file identified by the symlinkpath argument. The generated pathname is stored in the actualpath array. #include <stdlib.h> ... char *symlinkpath = "/tmp/symlink/file"; char actualpath [PATH_MAX+1]; char *ptr; ptr = realpath(symlinkpath, actualpath); APPLICATION USAGE
None. RATIONALE
Since the maximum pathname length is arbitrary unless {PATH_MAX} is defined, an application generally cannot supply a resolved_name buffer with size {{PATH_MAX}+1}. FUTURE DIRECTIONS
In the future, passing a null pointer to realpath() for the resolved_name argument may be defined to have realpath() allocate space for the generated pathname. SEE ALSO
getcwd(), sysconf(), the Base Definitions volume of IEEE Std 1003.1-2001, <stdlib.h> COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2003 Edition, Standard for Information Technol- ogy -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 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 at http://www.opengroup.org/unix/online.html . IEEE
/The Open Group 2003 REALPATH(3P)
Man Page