Last active
December 10, 2019 14:20
-
-
Save romanoffs/e1379e46246452f9d5b3ec02033b64b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/types.h> | |
#include <fcntl.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#define BUF_SIZE 4096 | |
#define OUTPUT_MODE 0700 | |
#define TRUE 1 | |
int main(int argc, char *argv[]); | |
int main(int argc, char *argv[]) { | |
int in_fd, out_fd, rd_count, wt_count; | |
char buffer[BUF_SIZE]; | |
if (argc != 3) exit(1); | |
in_fd = open(argv[1], O_RDONLY); | |
if (in_fd < 0) exit(2); | |
out_fd = creat(argv[2], OUTPUT_MODE); | |
if (out_fd < 0) exit(3); | |
while (TRUE) { | |
rd_count = read(in_fd, buffer, BUF_SIZE); | |
if (rd_count <= 0) break; | |
wt_count = write(out_fd, buffer, rd_count); | |
if (wt_count <= 0) exit(4); | |
} | |
close(in_fd); | |
close(out_fd); | |
if (rd_count == 0) { | |
exit(0); | |
} else { | |
exit(5); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment