Symbolic links, Symlink and readlink, Linux C
---------------------------------------------------------------------------------------------
The Symlink () function creates a symbolic connection.
Overview POSIX
#include <unistd.h>
int symlink (const char *path1, const char *path2);
Symlink ("/root/b.out", "/root/c.out");
If successful, Symlink returns 0: Otherwise return-1 and set errno.
---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------
View the name of the file that the link points to
---------------------------------------------------------------------------------------------
int main ()
{
Char buf[100];
Readlink ("/root/c.out", Buf,sizeof (BUF));
printf ("%s", buf);
return 0;
}
---------------------------------------------------------------------------------------------
Related functions: Stat, Lstat, symlink
Table header files: #include <unistd.h>
Define functions: ssize_t readlink (const char *path, char *buf, size_t bufsiz);
Function Description: Readlink () stores the symbolic link contents of the parameter path to the memory space referred to by the parameter buf, instead of \000 as the end of the string, but returns the character count of the string, which makes adding \000 simple. If the parameter bufsiz is less than the content length of the symbolic connection, the long content is truncated, and if readlink first argument points to a file instead of a symbolic link, Readlink sets errno to EINVAL and returns-1. The Readlink () function combines all the operations of open (), read (), and Close ().
Return value: Successful execution returns the character count of the string, failure returns-1, error code stored in errno
Successful execution returns ssize_t
Error code:
Eaccess rejected when fetching files, insufficient permissions
EINVAL parameter bufsiz is negative
EIO o Access Error
Eloop the file you want to open has too many symbolic connection issues
Enametoolong parameter path name of path is too long
ENOENT parameter The file specified by path does not exist
Enomem Core memory is low
Enotdir parameter in path path directory exists but is not a real directory
Symbolic links, Symlink and readlink, Linux C