C Standard IO---io with cache
Advantage:
With cache (merge system calls)
Disadvantages:
Low real-time availability
Type of cache:
Row cache: stdin stdout (buffer is size)
Full cache: File
No cache: stderr
1. Flow
The identity of the open file
2.FILE type
struct type:
File descriptor
The address of the buffer
Size of the cache
Error ID
3. Opening of the stream
fopen (3);
errno Global Variables
Defined macros:
/usr/include/asm-generic/errno-base.h
/usr/include/asm-generic/errno.h
Strerror (3);
Perror (3);
4. Stream operation (Read and write)
<1> bytes
Fgetc ();/fputc ();
GetChar ();/putchar ();
Getc ();/putc ();
<2> by row
Fgets ();/fputs ();
Gets ();/puts ();
<3> binary
Fread ();/fwirte ();
<4> formatting
FSCANF ();/fprintf ();
scanf ();/printf ();
5. Positioning of the stream
Fseek ();
Ftell ();
Rewind ();
6. Closing the stream
Fclose (3);
7. Refresh of the stream
Fflush (3);
8. Temporary files
Tmpnam ();//understanding
Tmpfile ();//Master
9.io efficiency
The discussion is not about the impact of cache size
Standard IO has created a buffer when calling fopen ()
Preferred choice:
Fgets ();/fputs ();
Fread ();/fwrite ();
10.
Setbuf ();
Setvbuf ();
Homework:
Add a string "uplooking" to the beginning of line 5th of a file
Standard IO for UNIX advanced programming