The difference between open and fopen in Linux __linux

Source: Internet
Author: User
Tags fread

Change from: Http://z515256164.blog.163.com/blog/static/324430292011113112712825/linux the difference between open and fopen:

The difference between open and fopen:
The main difference is that it involves the system, not the buffer. With F is standard IO, the code can be ported.

No f can only be invoked on the Unix/linux system.  Open is an integer, fopen one is a pointer (FILE *). The differences can be summed up in the following points:
The 1,fread is buffered with read without buffering.
2,fopen is defined in standard C, and open is defined in POSIX.
3,fread can read a structure. Read the binary in Linux/unix is no different from normal files.
4,fopen cannot specify permissions to create a file. Open can specify permissions.
5,fopen returns the pointer, open returns the file descriptor (integer).
Any device in the 6,linux/unix is a file and can be used open,read.

1. Non-buffered file system
The buffer file system is used to manage files by using file structure pointers, and access to files through file pointers
.

You can read-write characters, strings, format data, or read and write binary data. Non-buffered file systems depend on the operating system,

through the function of the operating system to read and write files, is the system-level input and output, it does not set the file structure body pointer,

Only binary files can be read and write, but they are efficient and fast, and since the ANSI standard no longer includes a non-buffered file system, it is recommended that you do not choose it.
Open, close, read, write, getc, GetChar, PUTC, Putchar, etc.
2. Buffer File System
The feature of the buffered file system is that it opens up a "buffer" in memory, which is used for every file in the program.

when performing a read-file operation, the data is read from the disk file into the memory "buffer" .

The received variable is then read from the memory "buffer" after it is filled. When performing a write file,

The data is written to the memory "buffer" before the memory "buffer" is filled and then written to the file.

from this we can see that the size of the memory "buffer" affects the actual operation of the external storage number,

The larger the memory "buffer", the less the number of external storage operations, the faster the execution speed and high efficiency.

In general, the size of the file "buffer" varies depending on the machine.
fopen, Fclose, Fread, fwrite, fgetc
, Fgets, FPUTC, fputs, freopen, etc.

The former belongs to low-level IO, the latter is advanced IO.
The former returns a file descriptor (the user's program area), which returns a file pointer.
The former has no buffer, the latter has buffer.
The former is used in conjunction with read, write, etc., the latter with Fread, fwrite and so on.
The latter is expanded on the basis of the former, in most cases with the latter.
http://blog.chinaunix.net/u/21067/showart_213410.html
Open is the file handle returned by the Linux/unix system call, and the file's handle is the index of the file in the file description list.

fopen is a library function of C that returns a pointer to the file structure.

Fopen is the C language library function in the Ansic standard and should invoke different kernel APIs in different systems
The system function in Linux is Open,fopen is its encapsulation function.
Fopen eventually call open on the underlying system call.

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.