Name

symlink - make a new name for a file

Library

libc.lib

Synopsis

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

Return values

Upon successful completion, 0 shall be returned. Otherwise, -1 shall be returned and errno set to indicate the error.

Detailed description

A symbolic link name2 is created to name1 ( name2 is the name of the file created, name1 is the string used in creating the symbolic link). Either name may be an arbitrary path name; it is expected the files can be on the different file system, but since the platform does not support multiple file system, symlink behaviour is exactly similar to link API and symlink on directories are not supported. symlink on a existing link file is not supported. Creation time stamp of the file is not supported, accesstime stamp is equal to modification time stamp. Newly created file will not alter the time stamp of parent directory.

Examples

/*
* Detailed description  : Example to create symlink to a file.
* Precondition : "Parent.txt" should exist in c: drive.
* Remarks      : Symlink behaviour is exactly similar to link api.
*/
#include <unistd.h>
#include <stdio.h>
int main(void)
 {
    if(symlink("C:\\Parent.txt","C:\\Link") < 0)
    {
         printf("simulated link creation to parent file failed\n");
         return -1  ;
    }
    printf("simulated link to parent file created");
    return 0 ;
 }

         

Output

simulated link to parent file created.

         

Errors

The link system call will fail and no link will be created if:
[ENOENT]
  A component of either path prefix does not exist.
[ENAMETOOLONG]
  A component or an entire path name exceeded 255 characters.
[ENOENT]
  A relative path was encountered in translating name2 and is not supported by the platform.
[EINVAL]
  A relative path was encountered in translating name1 and is not supported by the platform.
[ENOENT]
  An empty path was encountered in translating one of the pathnames.
[ELOOP]
  Too many symbolic links were encountered in translating one of the pathnames.
[ELOOP]
  name2 itself is a link type file.
[ENOENT]
  The file named by name1 does not exist.
[EEXIST]
  The link named by name2 does exist.

See also

link, lstat, readlink, unlink, symlink

Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top