Name

link - makes a new name for a file

Library

libc.lib

Synopsis

  #include <unistd.h>
  int link (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

The link system call atomically creates the specified directory entry (hard link) name2 with the attributes of the underlying object pointed at by name1. If the link is successful: it is expected the link count of the underlying object to be incremented but since link as a functionality is simulated and not supported by the platform, the underlying object is not aware of a existing link; name1 and name2 share equal access and rights to the underlying object. Link is supported only on regular files, fifos and not on directories. Creation of link on a existing link file is not supported.

If name1 is removed, the file name2 is also deleted as the platform recognizes the underlying object only by name1.

The object pointed at by the name1 argument must exist for the hard link to succeed and both name1 and name2 must be in the same file system. The name1 argument may not be a directory. 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 link to a file
* Precondition : "Parent.txt" should exist in c: drive
*
*/
#include <unistd.h>
#include <stdio.h>
int main(void)
 {
    if(link("C:\\Parent.txt","C:\\Link") < 0)
    {
         printf("Link creation to parent file failed\n");
         return -1;
    }
    printf("Link to parent file created");
    return 0;
 }

         

Output

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.
[ENOENT]
  A relative path was encountered in translating name2 and is not supported by the platform.
[ENAMETOOLONG]
  A component or an entire path name exceeded 255 characters.
[ENOENT]
  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.
[EMLINK]
  This is not supported as link is a simulated functionality.

See also

readlink, symlink, unlink

Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top