[Previous]
[Contents]
[Next]

symlink()

create a symbolic link to a path

Synopsis:

#include <unistd.h>
int symlink( const char *pname,
             const char *slink );

Description:

The symlink() function creates a symbolic link named slink that contains the pathname specified by pname (slink is the name of the symbolic link created, pname is the pathname contained in the symbolic link).

File access checking isn't performed on the file named by pname, and the file need not exist.

If the symlink() function is unsuccessful, any file named by slink is unaffected.

Returns:

0
Success
-1
An error occurred. errno is set to indicate the error.

Errors:

EACCES
A component of the slink path prefix denies search permission, or write permission is denied in the parent directory of the symbolic link to be created.
EEXIST
A file named by slink already exists.
ELOOP
A loop exists in symbolic links encountered during resolution of the slink argument, and it resolves to more than SYMLOOP_MAX levels.
ENAMETOOLONG
A component of the path specified by slink exceeds NAME_MAX bytes, or the length of the entire pathname exceeded PATH_MAX characters.
ENOSPC
The new symbolic link cannot be created because there is no space left on the filesystem that will contain the symbolic link.
ENOTDIR
A component of the path prefix of slink isn't a directory.
EROFS
The file slink would reside on a read-only file system.

Examples:

/*
 * create a symbolic link to "/usr/include"
 */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

void main()
  {
    if( symlink( "/usr/include", "slink" ) == -1) {
      perror( "slink -> /usr/include" );
      exit( EXIT_FAILURE );
    }
    exit( EXIT_SUCCESS );
  }

Classification:

POSIX 1003.1

Safety:
Interrupt handler No
Signal handler Yes
Thread Yes

Caveats:

This function requires a 2K stack.

See also:

errno, link(), lstat(), readlink(), unlink()


[Previous]
[Contents]
[Next]