C language Symlink () function: Establishing a File Symbolic connection
header file:
To define a function:
int symlink (const char * oldpath, const char * newpath);
Function Description: Symlink () creates a new connection (symbolic connection) to the existing file specified by the parameter OldPath NewPath the name specified by the argument. Parameter OldPath The specified file does not necessarily exist, and if the parameter newpath the specified name as an existing file, the connection is not established.
Return value: Success returns 0, failure returns-1, the reason for the error is in errno.
Error code:
1, the Eperm parameter OldPath and NewPath refers to the file system does not support symbolic connection.
2, erofs to test write permission files exist in the read-only file system.
3, the Efault parameter oldpath or NewPath pointer exceeds the accessible memory space.
4, Enametoolong parameter OldPath or NewPath too long.
5, Enomem core memory is not enough.
6, the Eexist parameter NewPath refers to the filename already exists.
7, the Emlink parameter OldPath refers to the file has reached the maximum number of connections.
8, eloop parameter pathname has too many symbolic connection problems.
9, the ENOSPC file system's remaining space is insufficient.
10, Eio I/O access errors.
Example
#include <unistd.h>
Main ()
{
symlink ("/etc/passwd", "Pass");
}
C language Readlink () function: Get the file that the symbolic connection refers to
header file:
To define a function:
int Readlink (const char * path, char * buf, size_t bufsiz);
Function Description: Readlink () Saves the symbolic connection of parameter path to the memory space referred to in parameter buf, and the returned content does not end with NULL as a string, but returns the number of characters in the string. If the parameter bufsiz is less than the content length of the symbolic connection, the longer content is truncated.
Return value: Execution succeeds with the file path string referred to by the symbolic connection, and the failure returns-1, with the error code stored in errno.
Error code:
1, eaccess access to the file is denied, insufficient permissions.
2, the einval parameter bufsiz is negative.
3, Eio I/O access errors.
4, Eloop to open the file has too many symbolic connection problems.
5, enametoolong parameter path name is too long.
6, enoent parameter path specifies a file that does not exist.
7, Enomem core memory is not enough.
8, Enotdir parameter the directory in the path path exists but is not a real directory.