Briefly introduce the Umask () function and truncate () function _c language in C language

Source: Internet
Author: User

C language Umask () function: Set permissions mask when new files are created
header file:

#include <sys/types.h>  #include <sys/stat.h>

To define a function:

mode_t umask (mode_t mask);

Function Description: Umask () sets the system Umask value to the value after the parameter mask&0777, and then returns the previous Umask value. When you use open () to create a new file, the argument mode is not the right to actually establish the file, but rather (mode&~umask) the permission value.

For example:
When the file is created with a file permission of 0666, and the Umask value defaults to 022, the file's true permissions are 0666&~022=0644, that is, rw-r--r--returns without an error value on this call. The return value is the Umask value of the original system.

C language Truncate () function: Change file size
header file:

#include <unistd.h>

To define a function:

int truncate (const char * path, off_t length);

Function Description: Truncate () changes the file size specified by the parameter path to the size specified by the parameter length. If the original file size is larger than the parameter length, the portion of the excess is deleted.

Return value: Successful execution returns 0, failure returns-1, the reason for the error is in errno.

Error code:
1. The eaccess parameter path specifies a file that cannot be accessed.
2, Erofs to write the file exists in the read-only file system.
3, efault parameter The path pointer exceeds the accessible memory space.
4, einval parameter path contains illegal characters.
5, Enametoolong parameter path is too long.
6, enotdir parameter path path is not a directory.
7, the Eisdir parameter path points to a directory.
8, etxtbusy parameter path refers to the file as a shared program, and is being executed.
9, eloop parameter path has too many symbolic connection problems.
10, Eio I/O access errors.

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.