Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- FILE *safeOpenFile(const char *const path, const char *const mode) {
- FILE *file = NULL;
- file = fopen(path, mode);
- if (file == NULL) {
- perror("opening error!");
- exit(EXIT_FAILURE);
- }
- return file;
- }
- void safeCloseFile(FILE *file) {
- if (fclose(file) == EOF) {
- perror(NULL);
- }
- }
- void argCheck(int argc) {
- if (argc < 3) {
- fprintf(stderr, "MORE ARG(s) NEEDED!\n");
- exit(-1);
- }
- }
- int main(int argc, char **argv) {
- argCheck(argc);
- FILE *fin = safeOpenFile(argv[1], "rb");
- FILE *fout = safeOpenFile(argv[2], "wb");
- for (uint8_t byte; fread(&byte, sizeof(byte), 1, fin) == 1;) {
- fwrite(&byte, sizeof(byte), 1, fout);
- }
- safeCloseFile(fin);
- safeCloseFile(fout);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement