-
-
Save hackaugusto/093234e7019f3c2248ac9efa8a7bade8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #define _GNU_SOURCE | |
| #include <fcntl.h> | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <unistd.h> | |
| #include <errno.h> | |
| #include <limits.h> | |
| int | |
| main(int argc, char *argv[]) | |
| { | |
| int in_fd, out_fd, len; | |
| if (argc != 3) { | |
| fprintf(stderr, "Usage: %s <from> <to>\n", argv[0]); | |
| exit(EXIT_FAILURE); | |
| } | |
| in_fd = open(argv[1], O_RDONLY); | |
| out_fd = open(argv[2], O_WRONLY); | |
| if (in_fd == -1) { | |
| perror("open"); | |
| exit(EXIT_FAILURE); | |
| } | |
| if (out_fd == -1) { | |
| perror("open"); | |
| exit(EXIT_FAILURE); | |
| } | |
| do { | |
| len = copy_file_range(in_fd, NULL, out_fd, NULL, INT_MAX, 0); | |
| if (len < 0) { | |
| if (errno == EAGAIN) { | |
| continue; | |
| } | |
| perror("copy_file_range"); | |
| exit(EXIT_FAILURE); | |
| } else if (len == 0) { | |
| break; | |
| } | |
| } while (1); | |
| close(in_fd); | |
| close(out_fd); | |
| exit(EXIT_SUCCESS); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment