Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

realpath(3) [osx 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 contains the path- name 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(3)						     Linux Programmer's Manual						       REALPATH(3)

NAME
realpath - return the canonicalized absolute pathname SYNOPSIS
#include <limits.h> #include <stdlib.h> char *realpath(const char *path, char *resolved_path); DESCRIPTION
realpath expands all symbolic links and resolves references to '/./', '/../' and extra '/' characters in the null terminated string named by path and stores the canonicalized absolute pathname in the buffer of size PATH_MAX named by resolved_path. The resulting path will have no symbolic link, '/./' or '/../' components. RETURN VALUE
If there is no error, it returns a pointer to the resolved_path. Otherwise it returns a NULL pointer, and the contents of the array resolved_path are undefined. The global variable errno is set to indi- cate the error. ERRORS
EACCES Read or search permission was denied for a component of the path prefix. EINVAL Either path or resolved_path is NULL. (In libc5 this would just cause a segfault.) EIO An I/O error occurred while reading from the file system. ELOOP Too many symbolic links were encountered in translating the pathname. ENAMETOOLONG A component of a path name exceeded NAME_MAX characters, or an entire path name exceeded PATH_MAX characters. ENOENT The named file does not exist. ENOTDIR A component of the path prefix is not a directory. BUGS
The libc4 and libc5 implementation contains a buffer overflow (fixed in libc-5.4.13). Thus, suid programs like mount need a private ver- sion. The length of the output buffer should have been an additional parameter, especially since pathconf(3) warns that the result of pathconf() may be huge and unsuitable for mallocing memory. HISTORY
The realpath function first appeared in BSD 4.4, contributed by Jan-Simon Pendry. In Linux this function appears in libc 4.5.21. CONFORMING TO
In BSD 4.4 and Solaris the limit on the pathname length is MAXPATHLEN (found in <sys/param.h>). The SUSv2 prescribes PATH_MAX and NAME_MAX, as found in <limits.h> or provided by the pathconf() 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 The BSD 4.4, Linux and SUSv2 versions always return an absolute path name. Solaris may return a relative path name when the path argument is relative. The prototype of realpath is given in <unistd.h> in libc4 and libc5, but in <stdlib.h> everywhere else. SEE ALSO
readlink(2), getcwd(3), pathconf(3), sysconf(3) 1999-08-24 REALPATH(3)
Man Page