C language umask () function:set the permission mask when creating a new fileHeader file:


Define the 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 using open () to create a new file, The parameter mode is not the permission to actually create the file, It is the (mode&~ umask) permission value.


When creating a file, specify file permissions as 0666, usually the umask value defaults to 022, then the true permissions of the file are 0666&022=0644, which is rw-r--r--return value. This call will have no error return. The return value is the umask value of the previous system.

c language truncate () function:change file sizeHeader file:


Define the function:

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

Function description:truncate () will change the file size specified by the parameter path to the size specified by the length parameter. If the original file size is larger than the length parameter, the excess will be deleted.

Return value:0 for successful execution, -1 for failure, and the cause of the error is stored in errno.

error code:

1. The file specified by the eaccess parameter path cannot be accessed.

2. Erofs The file to be written exists in the read-only file system.

3. The efault parameter path pointer exceeds the accessible memory space.

4. The einval parameter path contains illegal characters.

5. The 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.The file pointed to by etxtbusy parameter path is a shared program. And it is being implemented.

9. The eloop parameter path has too many symbolic link problems.

10. eio i/o access error.

  • Previous Example Python method for processing XML files
  • Next Lua to configure the anti-theft function of the Nginx server