1.1Linux system call and user programming interface
1.1.1 System Call
The interface that the user program requests to the operating system. The system invocation interfaces provided by different systems are not the same. Inherit the most basic and useful parts of UNIX system calls.
Calls are divided by function: Process Control, interprocess communication, file system control, storage management, network management, socket control, user management.
1.1.2 User Programming Interface
The actual development uses the user programming interface:
(1), the system call interface function is very simple, can not meet the needs of the program. (2), the system call interface of different operating system is incompatible, the program porting is very heavy.
1.2Linux Standard Programming Interface
1.2.1 The origin of standard IO: refers to a series of functions defined in ANSI C for IO operations.
(1), have better transplant, (2), can reduce the number of system calls, improve system efficiency (create buffer in user space).
Meaning of the 1.2.2 stream
Buffer type: (1), full buffer, (2), row buffer, (3), no buffer;
1.3 Standard IO Programming
1.3.1 The opening of the stream:
FILE *fopen (const char *path, const char *mode);
1.3.2 the closing of the stream:
int fclose (FILE *fp);
1.3.3 Error Handling:
void perror (const char *s);
char *strerror (int errnum);
1.3.4 Stream reads and writes:
1. Input/output by character (bytes)
Character input:
int fgetc (FILE *stream);
int getc (FILE *stream);
int GetChar (void);
Character output:
int FPUTC (int c, FILE *stream);
int PUTC (int c, FILE *stream);
int Putchar (int c);
2. Input/output by line
Line Input:
Char *fgets (char *s, int size, FILE *stream);
Char *gets (char *s);
Line output:
int fputs (const char *s, FILE *stream);
int puts (const char *s);
3. Read and write files in the specified size
size_t fread (void *ptr, size_t size, size_t nmemb, FILE *stream);
size_t fwrite (const void *ptr, size_t size, size_t nmemb, FILE *stream);
Positioning of 1.3.5 Flow
int fseek (FILE *stream, long offset, int whence);
Whence:seek_set, Seek_cur, or seek_end: File start, current, end read and write position;
Long Ftell (FILE *stream);
1.3.6 format input and output
Input:
int scanf (const char *format, ...);
int fscanf (FILE *stream, const char *format, ...);
int sscanf (const char *STR, const char *format, ...);
Output:
int printf (const char *format, ...);
int fprintf (FILE *stream, const char *format, ...);
int sprintf (char *str, const char *format, ...);
int snprintf (char *str, size_t size, const char *format, ...);
1.4 Experimental Content
Copy of the 1.4.1 file
1. Experiment Objective: To master the basic operation of the flow by realizing the file copying.
2. Experiment content: Open source files and target files separately in the program. The loop reads the contents from the source file and writes to the destination file.
3. Experiment steps: (1), check parameter → open source file → open target file → Loop read/write file → close file.
(2), write code.
1.4.2 Cycle Recording System time
1. Experimental purpose: To obtain the system time → in the program delay → stream format output.
2. Experimental content: The program reads the system time every second and writes the file.
3. Experiment steps: (1), design process: Open file → get system time → write file → delay 1s→ return second step (get system time).
(2), write code.
1.Linux Standard IO Programming