LOWCOPY.C
上传用户:qq5388545
上传日期:2022-07-04
资源大小:29849k
文件大小:1k
- #include <stdio.h>
- #include <io.h>
- #include <fcntl.h>
- #include <systypes.h>
- #include <sysstat.h>
- void main(int argc, char *argv[])
- {
- int source, target; // file handles
- char buffer[1024]; // I/O buffer
- int bytes_read;
- if (argc < 3)
- fprintf(stderr, "Must specify source and target filesn");
- else if ((source = open(argv[1], O_BINARY | O_RDONLY)) == -1)
- fprintf(stderr, "Error opening %sn", argv[1]);
- else if ((target = open(argv[2], O_WRONLY | O_BINARY | O_TRUNC |
- O_CREAT, S_IWRITE)) == -1)
- fprintf(stderr, "Error opening %sn", argv[2]);
- else
- {
- while (!eof(source))
- {
- if ((bytes_read = read(source, buffer, sizeof(buffer))) <= 0)
- fprintf(stderr, "Error reading from source file");
- else if (write(target, buffer, bytes_read) != bytes_read)
- fprintf(stderr, "Error writing to target file");
- }
- close(source);
- close(target);
- }
- }