Differences between open and fopen:
1. buffer File System
the buffer file system features a buffer zone in the memory ", it is used for each file in the Program . When you perform file read operations, read data from the disk file into the memory "buffer" first ", read the received variable from the memory buffer after filling. When writing a file, the data is first written to the memory "buffer", and then written to the file after the memory "buffer" is filled up. It can be seen that the size of the memory "buffer" affects the number of external memory operations. The larger the memory "buffer", the less times the external memory operations are performed, fast execution speed and high efficiency. Generally, the size of the file "buffer" varies with the random device.
fopen, fclose, fread, fwrite, fgetc, fgets, fputc, fputs, freopen, fseek, ftell, rewind and so on
2. the unbuffered File System
the file system uses the file structure pointer to manage the file and access the file through the file pointer, it can read and write characters, strings, formatted data, and binary data. The non-buffered file system depends on the operating system. It reads and writes files through the operating system function. It is a system-level input and output. It does not have a file structure pointer and can only read and write binary files, however, it is highly efficient and fast. Since ANSI standards do not include non-buffered file systems, we recommend that you do not select them. This book is only a brief introduction. Open, close, read, write, GETC, getchar, putc, putchar, etc.
open is the file handle returned by a system call, the file handle is the index of the file in the file description table. fopen is the library function of C and returns a pointer to the file structure.
Fopen is a C language library function in the ansic standard. Different kernel APIs should be called in different systems.
In Linux, the system function is open, and fopen is its encapsulation function. For reference only.
File descriptor is a concept in Linux. All devices in Linux operate as files, such as network sockets and hardware devices. Including operationsComposition.
Fopen is a standard C function. Return the file stream instead of the file handle in Linux.
A device file cannot be used as a stream file.
Fopen is used to manipulate regular files and has buffer. It is different from open.
Use fopen to open a common file and open a device file.
Fopen is in Standard C, while open is a Linux system call.
Their levels are different.
Fopen can be transplanted, open cannot
I think the main difference between fopen and open is that fopen has a cache in the user mode, which reduces switching between the user mode and the kernel mode during read and write operations, while open requires switching between kernel and user States every time. The result is that if files are accessed sequentially, fopen functions are faster than calling open functions directly; if the random access to file open is faster than fopen.
Classic answers from the Forum:
The former is a low-level Io, and the latter is a high-level Io.
The former returns a file descriptor (in the user program area), 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.