Mode in the fopen (20161115)

Source: Internet
Author: User
Tags flock truncated

Mode

The mode parameter specifies the type of access required to the stream. Can be the following:

fopen () list of possible values in mode

Mode

Description

' R '

Read-only opens, pointing the file pointer to the file header.

' R+ '

Read-write mode opens, pointing the file pointer to the file header. (that is, overwrite)

' W '

The Write method opens, pointing the file pointer to the file header and truncating the file size to zero. (That is, when the file pointer is pointed to the file header and the file is emptied), if the file does not exist, try to create it.

' w+ '

Read-write mode opens, pointing the file pointer to the file header and truncating the file size to zero. If the file does not exist, try to create it.

A

Write to open, pointing the file pointer to the end of the file. If the file does not exist, try to create it. (equivalent to append)

' A + '

Read-write mode opens, pointing the file pointer to the end of the file. If the file does not exist, try to create it.

' X '

Creates and opens in writing, pointing the file pointer to the file header. If the file already exists, the fopen () call fails and returns false , and generates an e_warning level error message. If the file does not exist, try to create it. This specifies o_excl| for the underlying open (2) system call The O_creat tag is equivalent.

' x+ '

Created and opened in read-write mode, other behaviors are the same as ' X ' .

' C '

open the file for writing only. If The file does not exist, it is created. If it exists, it is a neither truncated (as opposed to ' W ' ), or the call to this function fails (as was the case WI Th ' x ' ). The file pointer is positioned on the beginning of the file. This could be useful if it's desired to get a advisory lock (see Flock ()) before attempting to modify the file, as using the em> ' W ' could truncate the file before the lock was obtained (if truncation are desired, ftruncate () can be used after The lock is requested).

 

 

' C+ '

Open the file for reading and writing; Otherwise it has the

Same behavior as ' C '.

Mode in the fopen (20161115)

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.