Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <sys/time.h>
- #include <sys/types.h>
- #include <unistd.h>
- const int BLOCK_SIZE = 64;
- void copyfile (int fd1, int fd2){
- char buffer[BLOCK_SIZE];
- int chars;
- while ((chars = read(fd1, &buffer, BLOCK_SIZE)) > 0){
- write(fd2, &buffer, chars);
- }
- }
- int main(int argc, char* argv[]) {
- int f, f2;
- struct timeval tv;
- gettimeofday(&tv, NULL);
- int start = tv.tv_usec;
- if (argc != 3){
- printf("Invallid number of arguments\n");
- return 0;
- }
- if ((f = open(argv[1], O_RDONLY)) == -1){
- printf("Invallid path to first file1\n");
- return 0;
- }
- if((f2 = open(argv[2], O_WRONLY | O_CREAT, 0644)) == -1){
- printf("Can't create file\n");
- close(f);
- return 0;
- }
- copyfile(f, f2);
- close(f);
- close(f2);
- gettimeofday(&tv, NULL);
- int end = tv.tv_usec;
- double time = (double)(end - start) / 1000000;
- printf("File copied in %f seconds\n", time);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement