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:
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.