LINUX Study Notes 9-file access

Source: Internet
Author: User
A) create a file: Intcreat (constchar * filename, mode_tmode) 1. filename: name of the file to be created 2. # include & lt; sys/types. h & gt; # include & lt; sys/stat. h & gt; # include & lt; fcntl. h & gt; 3. mode: creation mode: only create a can be controlled.) create File: Int creat (const char * filename, mode_t mode)
 
1. filename: name of the file to be created
 
2. # include
 
# Include
 
# Include
 
3. mode: creation mode: only the write attribute of the created user can be controlled, and other users cannot write, so generally 755
 
A) S_IRUSR: readable-> 1
 
B) S_IWUSR: writable-> 2
 
C) S_IXUSR: executable-> 4
 
D) S_IRWXU: read/write execution-> 7
 
4. return value: 0 is returned for success.-1 is returned for failure.
 
B) file description:
 
1. essence: a non-negative integer
 
C) open the file:
 
1. Int open (const char * pathname, int flags, [mode])
 
2. # include
 
# Include
 
# Include
 
3. common opening signs:
 
A) O_RDONLY: Read-only
 
B) O_WRONLY: write only
 
C) O_RDWR: Read/Write
 
D) O_APPEND: append method
 
E) O_CREAT: create a file that does not exist. open with three parameters must be used,
 
F) O_NOBLOCK: open in non-blocking mode
 
D) close the file: int close (int fd)
 
E) system call: read int read (int fd, const void * buf, size_t length)
 
1. return value: actual read length
 
F) write: int write (int fd, const void * buf, size_t length)
 
1. return value: actual write length
 
G) positioning: int lseek (int fd, offset_t offset, int whence)
 
1. description: offset bytes are moved relative to whence.
 
2. Whence value
 
A) SEEK_SET: relative file header
 
B) SEEK_CUR: relative to the current location
 
C) SEEK_END: relative to the end of the file
 
3. return value: Number of bytes that deviate from the file header after the pointer is moved
 
4. calculate the file length: move the end of the file and return the value of 0 offset.
 
H) judgment: int access (const char * pathname, int mode)
 
1. Role: determine whether a file can be operated.
 
2. mode:
 
A) R_ OK: The file is readable.
 
B) W_ OK: The file is writable.
 
C) X_ OK: The file is executable.
 
D) F_ OK: The file exists.
 
3. return value: 0 is returned when the request is successful, and-1 is returned if the request is incorrect.

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.