realpath(3) Library Functions Manual realpath(3) realpath - LIBRARY Standard C library (libc, -lc) #include #include char *realpath(const char *restrict path, char *restrict resolved_path); glibc (. feature_test_macros(7)): realpath(): _XOPEN_SOURCE >= 500 || /* glibc >= 2.19: */ _DEFAULT_SOURCE || /* glibc <= 2.19: */ _BSD_SOURCE realpath() expands all symbolic links and resolves references to /./, /../ and extra '/' characters in the null-terminated string named by path to produce a canonicalized absolute pathname. The resulting pathname is stored as a null-terminated string, up to a maximum of PATH_MAX bytes, in the buffer pointed to by resolved_path. The resulting path will have no symbolic link, /./ or /../ components. resolved_path NULL, realpath() PATH_MAX malloc(3) . free(3). realpath() resolved_path. NULL, resolved_path errno . EACCES , . EINVAL path is NULL. (Before glibc 2.3, this error is also returned if resolved_path is NULL.) EIO -. ELOOP pathname . ENAMETOOLONG NAME_MAX , PATH_MAX . ENOENT . ENOMEM . ENOTDIR . attributes(7). +----------------------------+----------------------------------------------------------+--------------------------+ | | | | +----------------------------+----------------------------------------------------------+--------------------------+ |realpath() | | MT-Safe | +----------------------------+----------------------------------------------------------+--------------------------+ GNU EACCES ENOENT resolved_path NULL, resolved_path path. POSIX.1-2008. 4.4BSD, POSIX.1-2001, Solaris. POSIX.1-2001 , resolved_path NULL, . POSIX.1-2008 , . 4.4BSD Solaris MAXPATHLEN ( ). SUSv2 PATH_MAX NAME_MAX pathconf(3). : #ifdef PATH_MAX path_max = PATH_MAX; #else path_max = pathconf(path, _PC_PATH_MAX); if (path_max <= 0) path_max = 4096; #endif ( ) POSIX.1-2001 , . POSIX.1-2001 PATH_MAX , PATH_MAX , pathconf(3). pathconf(3) , POSIX , pathconf(3) . , pathconf(3) -1 , PATH_MAX . resolved_path == NULL, POSIX.1-2001, POSIX.1-2008, . . realpath(1), readlink(2), canonicalize_file_name(3), getcwd(3), pathconf(3), sysconf(3) aereiae , Azamat Hackimov , Dmitriy S. Seregin , Katrin Kutepova , Lockal , Yuri Kozlov , ; GNU 3 , . . , , . Linux man-pages 6.06 31 2023 . realpath(3)