gtpc2m73 | C/C++ Language Support User's Guide |
This function creates a symbolic link to a path name.
Format
#include <unistd.h> int symlink(const char *pathname, const char *slink);
This function creates the symbolic link named by slink with the file specified by pathname. File access checking is not performed on the pathname file and the file does not need to exist.
A symbolic link path name is resolved as follows:
If the path name in the symbolic link does not start with a slash (/), the symbolic link path name is resolved with respect to the directory that contains the symbolic link.
Because the mode of a symbolic link cannot be changed, its mode is ignored during the lookup process. Any files and directories to which a symbolic link refers are checked for access permission.
Normal Return
If successful, the symlink function returns a value of zero.
Error Return
If unsuccessful, the symlink function returns a value of -1, does not affect any file it names, and sets errno to one of the following:
Programming Considerations
The TPF system does not support creating, updating, or deleting files in 1052 or UTIL state. Special files may or may not be writable in 1052 or UTIL state depending on the device driver implementation.
Because the symlink function requires an update to a directory file, new symbolic links cannot be created in 1052 or UTIL state.
Examples
The following example provides symlink information for a file.
#include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> main() { char fn[]="test.file"; char sln[]="test.symlink"; int fd; if ((fd = creat(fn, S_IWUSR)) < 0) perror("creat() error"); else { close(fd); if (symlink(fn, sln) != 0) { perror("symlink() error"); unlink(fn); } else { unlink(fn); unlink(sln); } } }
Related Information
See Appendix E, Programming Support for the TPF File System for more information about TPF File System C Functions.