1. Linux platform C implements local file CP
Code sub-and Running Effect Test
Compile code child;
Run the executable program;
2. c. Copy files through pipelines
3. Next episode-File Read/Write File Location operations;
Linux lseek function usage;
Lseek ()
Header file # include <sys/types. h>
# Include <unistd. h>
Prototype:
Off_t lseek (INT Fildes, off_t offset, int whence); // offset, Root
Function Description: each opened file has a read/write location. When a file is opened, its read/write Location usually points to the beginning of the file;
If you open a file (o_append) as an attachment, the read/write position points to the end of the file;
When read () or write (), the read/write location increases accordingly.
Lseek () is used to control the read/write location of a file.
The Fildes parameter is an opened file descriptor, And the offset parameter is the number of read/write locations to be moved Based on the whence parameter;
The whence parameter is one of the following
The seek_set parameter offset is the new read/write location.
Seek_cur: Increase the offset displacement after the current read/write position
Seek_end points the read/write position to the end of the file and then increases the offset displacement.
When the whence value is seek_cur or seek_end, the offset parameter allows negative values.
Special usage
1) to move the read/write location to the beginning of the file: lseek (INT Fildes, 0, seek_set );
2) Move the read/write location to the end of the file: lssek (INT Fildes, 0, seek_end)
3) obtain the current file location: lseek (INT Fildes, 0, seek_cur)
Return Value: when the call is successful, the current read/write location is returned, that is, the number of characters before the start of the file,
If an error occurs,-1 is returned, and errno stores the error number;
Error code: eintr system interruption;
C local file operations