2. Introduction of Open function parameters
◇filename: The name of the file to be created. If there is only a file name, then the program is in the same directory as this file name.
Routines:
Compile and run the program to get:
You can get the compiled executable file creat_file with the test created under the same directory. What if you want to create a file under the specified directory?
Just add the specified directory to the file! Here's what the above routine modifies:
The above three files are placed under the/home/system_program directory:
Compile the modified program to run the resulting:
◇Flags: The way to open a file
1. O_rdonly: Open in read-only mode
2, O_wronly: Open in a write-only way
3. O_RDWR: Open in Read and write mode
4. O_append: Open file in Append mode
5, O_creat: If the file does not exist, then create a file and use the parameter mode to set permissions
6. O_exec : If O_creat is used, but the file already exists, return error message
7, O_noblock: Open the file in a non-blocking way
8. O_trunc: If the file already exists, delete its original data before writing the data
◇mode: Setting access permissions for a file
1, S_IRUSR: The document belongs to the main readable
2, S_IWUSR: The document belongs to the master can write
3, S_IXUSR: The file is the main executable
4, S_irwxu: The document is the master can read, write, execute
5. S_IRGRP: The document belongs to the group readable
6, S_iwgrp: Documents belong to the group can be written
7, S_ixgrp: File group executable
8, S_irwxg: Documents belong to the group can read, write, execute
9, S_iroth: Other users can read
10, S_iwoth: Other users can write
11, S_irwxo: Other users can read, write, execute
12, S_isuid: Set the file owner's execution ID
13. S_isgid: Set the execution ID of the file group
3. Relationship between Umask value and file permissions
or This program, when we compile and run it to get Test1 file, from the above can be seen test1 This file permissions are read, write, executable. However, when viewing file permissions
you can see that test1 's permissions are not the permission settings you want in the open function, what is the cause of this?
In fact, this is related to the value of umask. Umask represents some of the access bits that a file or directory needs to be masked when it is created. When a process creates a file, the actual access permission for the file is determined by the mode& (~umask) formula.
0022 This value indicates that the created file will automatically block write permissions for the group and write permissions for other groups. Because in Linux file permissions 4-readable, 2-writable, 1-executable.
So what do you do to modify this value?
After you re-create the file: