The use _c language of symlink () function and Readlink () function in C language

Source: Internet
Author: User
Tags error code symlink

C language Symlink () function: Establishing a File Symbolic connection
header file:

 #include <unistd.h>

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:

 #include <unistd.h>

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.

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.