| Skip Navigation Links | |
| Exit Print View | |
![]() | man pages section 2: System Calls Oracle Solaris 11 Information Library |
- read the contents of a symbolic link
#include <unistd.h>ssize_treadlink(const char *restrictpath,char *restrictbuf,size_tbufsiz);
ssize_t readlinkat(intfd, const char *restrictpath,char *restrictbuf, size_tbufsize);
Thereadlink() function places the contents of the symbolic link referred tobypath in the bufferbuf which has sizebufsiz. Ifthe number of bytes in the symbolic link is less thanbufsiz, thecontents of the remainder ofbuf are left unchanged. If thebufargument is not large enough to contain the link content, the firstbufsize bytes are placed inbuf.
Upon successful completion,readlink() marks for update the last data access timestampof the symbolic link.
Thereadlinkat() function is equivalent to thereadlink() function except in thecase wherepath specifies a relative path. In this case the symboliclink whose content is read is relative to the directory associated withthe file descriptorfd instead of the current working directory. If the filedescriptor was opened withoutO_SEARCH, the function checks whether directory searches arepermitted using the current permissions of the directory underlying the file descriptor.If the file descriptor was opened withO_SEARCH, the function does not performthe check.
Ifreadlinkat() is passed the special valueAT_FDCWD in thefd parameter,the current working directory is used and the behavior is identical toa call toreadlink().
Upon successful completion,readlink() andreadlinkat() return the count of bytes placedin the buffer. Otherwise, it returns-1, leaves the bufferunchanged, and setserrno to indicate the error.
Thereadlink() andreadlinkat() functions will fail if:
Search permission is denied for a component of the path prefix ofpath.
path orbuf points to an illegal address.
Thepath argument names a file that is not a symbolic link.
An I/O error occurred while reading from the file system.
A component ofpath does not name an existing file orpath is an empty string.
A loop exists in symbolic links encountered during resolution of thepath argument.
The length ofpath exceeds {PATH_MAX}, or a pathname component is longer than {NAME_MAX} while_POSIX_NO_TRUNC is in effect.
A component of the path prefix is not a directory.
The file system does not support symbolic links.
Thereadlinkat() function will fail if:
fd was not opened withO_SEARCH and the permissions of the directory underlyingfd do not permit directory searches.
Thepath argument does not specify an absolute path and thefd argument is neitherAT_FDCWD nor a valid file descriptor open for reading or searching.
Thereadlink() andreadlinkat() functions may fail if:
Read permission is denied for the directory.
More than {SYMLOOP_MAX} symbolic links were encountered in resolvingpath.
As a result of encountering a symbolic link in resolution of the path argument, the length of the substituted pathname string exceeded {PATH_MAX}.
Thereadlinkat() function may fail if:
Thepath argument is not an absolute path andfd is neitherAT_FDCWD nor a file descriptor associated with a directory.
Portable applications should not assume that the returned contents of the symboliclink are null-terminated.
Seeattributes(5) for descriptions of the following attributes:
|
Copyright © 2011, Oracle and/or its affiliates. All rights reserved.Legal Notices | ![]() ![]() |