Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the fopen function of Linux

Shulou Source: shulou.com Published: 2022-06-02 00:37:38 10月15日 Update

What is the fopen function of Linux? I believe many inexperienced people don't know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Fopen (Open File)

Correlation function open,fclose

Header file # include

Define the function FILE * fopen (const char * path,const char * mode)

The function description parameter path string contains the file path and file name to be opened, while the parameter mode string represents the flow pattern.

Mode has the following morphological strings:

R Open a read-only file, which must exist.

R + Open a read / write file, which must exist.

W Open a write-only file. If the file exists, the length of the file is cleared to 0, that is, the content of the file will be deleted.

Lose. Create a file if it does not exist.

W + opens the read-write file. If the file exists, the length of the file is zero, that is, the contents of the file.

Will disappear. Create a file if it does not exist.

An opens the write-only file in an additional way. If the file does not exist, the file will be created

If the file exists, the written data will be added to the end of the file, that is, the original contents of the file will

To be retained.

A + opens a read-write file in an additional way. If the file does not exist, the text will be created

If the file exists, the written data will be added to the end of the file, that is, the original

The content will be retained.

All of the above morphological strings can be added with a b character, such as rb, Whiteb, or ab+

The b character is added to tell the function library that the open file is binary rather than pure

Text files. However, on POSIX systems, including Linux ignores this character. By fopen

() the new document created will have

S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH (0666) permission. The umask value is also used for this file permission.

After the return value file is successfully opened, the file pointer to the stream is returned. If the file fails to open, return NULL and store the error code in errno.

Generally speaking, some file reading or writing actions will be made after opening the file, and if the open file fails, the following read and write action can not be carried out smoothly, so please make an error judgment and handling after fopen ().

After reading the above, have you mastered what the fopen function of Linux is? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Tags: Files characters functions contents strings forms attachments actions parameters data methods more permissions errors length problems helpless to this end next Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Tech Info Linux vpn Shulou Technology