#include <unistd.h>
|
int
link (const char *name1, const char *name2); |
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.
/* * 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:\arent.txt","C:\ink") < 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.
[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. | |
© 2005-2007 Nokia |