Differences between open and fopen in Linux

Source: Internet
Author: User
Differences between open and fopen in Linux: the path and name of the file to be opened in intopen (constchar * path, intaccess, intmode) path www.2cto. comaccess access mode. the macro definition and meaning are as follows :... differences between open and fopen in Linux int open (const char * path, int access, int mode) path specifies the file path to open and the name www.2cto.com access mode. the macro definition and meaning are as follows: o_RDONLY 1 read-only open O_WRONLY 2 write only open O_RDWR 4 read and write Open also can select the following mode and the above three basic mode phase: o_CREAT 0x0100 create a file and open O_TRUNC 0x0200 open an existing file and set the file length to 0, other attributes keep O_EXCL 0x0400 not using O_APPEND 0x0800 Open file O_TEXT 0x4000 open text file translation CR-LF control character O_BINARY 0x8000 open binary character, do not translate CR-LF www.2cto.com mode this parameter is only used in access = O_CREAT mode, the value is as follows: s_IFMT 0xF000 file type mask S_IFDIR 0x4000 directory S_IFIFO 0x1000 FIFO dedicated S_IFCHR 0x2000 character dedicated S_IFBLK 0x3000 block dedicated S_IFREG 0x8000 only 0x0000 S_IREAD 0x0100 readable S_IWRITE 0x0080 writable S_IEXEC 0x0040 executable FILE * fopen (char * filename, char * mode) filename File Name mode open mode: r read-only mode to open a text file rb read-only mode to open a binary file W. open a text file in write-only mode wb open a binary file a append open a text file AB append open a binary file r + read/write open a text file rb + read/write: open a binary file w + read/write create a text file wb + read/write generate a binary file a + read/write append open a text file AB + read/write method to append a binary file www.2cto.com open and fopen: the former is a low-level IO, and the latter is a high-level IO. The former returns a file descriptor, and the latter returns a file pointer. The former has no buffer, and the latter has a buffer. The former works with read and write, and the latter works with fread and fwrite. The latter is expanded based on the former. In most cases, the latter is used.
Related Article

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.