Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

18. Directories and Links > Working with Symbolic Links: symlink() and readlink...

We now look at the system calls used to create symbolic links and examine their contents.

The symlink() system call creates a new symbolic link, linkpath, to the pathname specified in filepath. (To remove a symbolic link, we use unlink().)

#include <unistd.h>

int symlink(const char *filepath, const char *linkpath);

Note

Returns 0 on success, or -1 on error

If the pathname given in linkpath already exists, then the call fails (with errno set to EEXIST). The pathname specified in filepath may be absolute or relative.

The file or directory named in filepath doesn’t need to exist at the time of the call. Even if it exists at that time, there is nothing to prevent it from being removed later. In this case, linkpath becomes a dangling link, and attempts to dereference it in other system calls yield an error (usually ENOENT).


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint