Linking Files

This is accomplished by the link(2) system call:

#include <unistd.h>

int link(const char *oldpath, const char *newpath);

The function returns -1 if it fails and leaves the error code in errno. Upon a successful return, the value 0 is returned.

The following example shows how the function can be used to link the filename a.out to my_app:

if ( link("a.out","my_app") == -1 ) {
    fprintf(stderr,"%s: link(2)\n",strerror(errno));
    abort();
}

Warning

Some UNIX platforms allow link(2) to return the error EINTR (SGI IRIX 6.5 for example).

Note

The st_ctime (create time) value of the file is updated upon successful completion of a link(2) call. The values st_ctime and st_mtime (time of last modification) of the directory containing the ...

Get Advanced UNIX Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.