[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions, Volume 2

readlink Subroutine

Purpose

Reads the contents of a symbolic link.

Library

Standard C Library (libc.a)

Syntax


#include <unistd.h>
int readlink ( Path, Buffer, BufferSize)
const char *Path;
char *Buffer;
size_t BufferSize;

Description

The readlink subroutine copies the contents of the symbolic link named by the Path parameter in the buffer specified in the Buffer parameter. The BufferSize parameter indicates the size of the buffer in bytes. If the actual length of the symbolic link is less than the number of bytes specified in the BufferSize parameter, the string copied into the buffer will be null-terminated. If the actual length of the symbolic link is greater than the number of bytes specified in the Buffersize parameter, an error is returned. The length of a symbolic link cannot exceed 1023 characters or the value of the PATH_MAX constant. PATH_MAX is defined in the limits.h file.

Parameters

Path Specifies the path name of the destination file or directory.
Buffer Points to the user's buffer. The buffer should be at least as large as the BufferSize parameter.
BufferSize Indicates the size of the buffer. The contents of the link are null-terminated, provided there is room in the buffer.

Return Values

Upon successful completion, the readlink subroutine returns a count of the number of characters placed in the buffer (not including any terminating null character). If the readlink subroutine is unsuccessful, the buffer is not modified, a value of -1 is returned, and the errno global variable is set to indicate the error.

Error Codes

The readlink subroutine fails if one or both of the following are true:

ENOENT The file named by the Path parameter does not exist, or the path points to an empty string.
EINVAL The file named by the Path parameter is not a symbolic link.
ERANGE The path name in the symbolic link is longer than the BufferSize value.

The readlink subroutine can also fail due to additional errors. See "Base Operating System Error Codes for Services that Require Path-Name Resolution" for a list of additional error codes.

The readlink subroutine can also fail due to additional errors. See Appendix A,"Base Operating System Error Codes for Services That Require Path-Name Resolution" on page A-1 for a list of additional error codes.

If Network File System (NFS) is installed on the system, the readlink subroutine can also fail if the following is true:

ETIMEDOUT The connection timed out.

Related Information

The ln command.

The link subroutine, statx, stat, fstatx, fstat, fullstat, or ffullstat (statx, stat, lstat, fstatx, fstat, fullstat, ffullstat, stat64, lstat64, or fstat64 Subroutine) subroutine, symlink (symlink Subroutine) subroutine, unlink (unlink Subroutine) subroutine.

Files, Directories, and File Systems for Programmers in AIX 5L Version 5.2 General Programming Concepts: Writing and Debugging Programs.

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]