Symbolic links, Symlink and readlink, Linux C

Source: Internet
Author: User
Tags symlink

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.