Summarize and organize the common library functions of C language in Linux----file operation

Source: Internet
Author: User
Tags mathematical functions

In the absence of an IDE, it is necessary to remember the function names, parameters, basic usage, and considerations of some commonly used library functions.

Referring to the Linux_c_hs.chm directory, I have roughly divided the usual functions into several categories:

    • 1. Memory and string control and operation
    • 2. String conversions
    • 3. Character test
    • 4. File operation
    • 5. Time and date
    • 6. Common mathematical functions
    • 7. File Content operation
    • 8. File Permissions Control
    • 9. Process Operations
    • 10. Threading Operations
    • One. Socket operation
    • 12. Signal Processing
    • 13. Data structures and algorithms

This is the main summary of the above black section, about the function of the file operation.

    • System Call Collation
**function name Usage notes**1.intOpenConst Char*pathname,intflags); Open and possibly create a file or device flags must contain any one of o_rdonly, o_wronly, or O_rdwr**2.intOpenConst Char*pathname,intflags, mode_t mode); Up mode only works if the o_creat is included in the flags**3.intFsyncintFD); Synchronize a file's In-core state with storage device must be synchronized before writing data close to prevent accidental**4. off_t Lseek (intFD, off_t offset,intwhence); Locating file Locations The third parameter can be seek_set seek_cur seek_end**5. ssize_t Read (intFildes,void*buf, size_t nbyte); The up file location is moved with the number of bytes read**6. ssize_t Write (intFildes,Const void*buf, size_t nbyte); up up**7.intCloseintFD); up up**8.void*mmap (void*ADDR, size_t length,intProtintflags, the memory map first uses Fstat to get the file size, and then uses the function to map the contents of the file to memory, and then you canintfd, off_t offset); Directly invokes a string function operation. **9.intMunmap (void*addr, size_t length); Release Memory up**Ten.intFtruncate (intFD, off_t length); Truncate a file to a specified length in the case of new files, if memory mapping is used, then it is necessary to call the function to preset a file size, or error** One.intFstat (intFdstructStat *buf); Get the basic information of the file specific parameters see Man, you can find the size of the file, modification date, etc.*

    • C99 Standard Classification
/*Standard C function * Function name usage Note **1.    FILE *fopen (const char *path, const char *mode); NT mode can be R,R+,W,W+,A,A+,RW and other **2.   int fseek (FILE *stream, long offset, int whence); NT locates file location **3.                           Long Ftell (FILE *stream); The current file location is nt**4.                          void Rewind (FILE *stream); Move the file location to the file header nt**5.   size_t fread (void *ptr, size_t size, size_t nmemb, FILE *stream); NT nt**6. size_t fwrite (const void *ptr, size_t size, size_t nmemb,file *stream); NT nt**7.                             int feof (FILE *stream); Determine if the file has finished reading nt**8.  int fscanf (FILE *stream, const char *format, ...); Read file streams in format there are other functions of the scanf family, such as sscanf can read byte stream **9. int fprintf (FILE *stream, const char *format, ...);            Write content to a file in a format    There are sprintf,vprintf and so on **10.    int vfprintf (FILE *stream, const char *format, va_list AP); Write the indefinite parameter directly to the file corresponding to the read letter **11.                          int fflush (FILE *stream); NT nt**12.       Char *fgets (char *s, int size, FILE *stream); The NT stops **13 when it reads to a newline character or EOF.                          int Fileno (FILE *stream); Returns an integer file descriptor this is the place **14 with glibc.            int fputs (const char *s, FILE *stream); NT does not write the Terminator \0**/

    • File permission control class functions Summary
*function name Usage notes**1.intRemoveConst Char*pathname); NT deletes a file of the specified path**2.intRenameConst Char*old,Const Char*New); NT Rename**3.intUtime (Const Char*path,Const structUTIMBUF *Times ); NT modified file access time**4.intStatConst Char*restrict Path,structStat *restrict buf); NT can get further details about the file**5.intReaddir_r (DIR *dirp,structDirent *entry,structDirent * *result); NT Read Folder Contents**6. DIR *opendir (Const Char*name); NT open folder, this is the first step**7.Char*GETCWD (Char*buf, size_t size); NT obtains the current absolute path**8.intchmodConst Char*path, mode_t mode); NT Change file Permissions**9.intClosedir (DIR *dirp); NT must be closed after opening folder**Ten.intChDirConst Char*path); NT changes the current working directory*

    • Additional functions required to handle an indeterminate parameter

* *1void  va_start (va_list ap, last);                    Must first be called * *2. Type Va_arg (va_list ap, type);                      Immediately thereafter, theactual value is obtained according to%s%d c * *3void  va_end (va_list ap);                            When the desired value is obtained, end is called. **

As above, just a simple summary of commonly used functions, some less commonly used, such as links and so on, there is no classification.

These functions, at least to know that there are these functions, and do not need to implement, the specific parameters are not clear, know the function name, under Linux, with the man fun can have more specific elaboration.

Summarize and organize the common library functions of C language in Linux----file operation

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.