Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <fcntl.h>
  4. #include <unistd.h>
  5.  
  6. #define BUFFER_SIZE 1024
  7.  
  8. int main(){
  9.  
  10. char *sourcePath, *destPath;
  11. ssize_t ret_in, ret_out;
  12. char temp[BUFFER_SIZE];
  13.  
  14. printf("Enter source file path: ");
  15. scanf("%s", sourcePath);
  16.  
  17. printf("Enter destination file path: ");
  18. scanf("%s", destPath);
  19.  
  20. int sourceFile = open(sourcePath, O_RDONLY);
  21. if(sourceFile == -1){
  22. printf("Error: invalid source file");
  23. return 0;
  24. }
  25.  
  26. int destFile = open(destPath, O_WRONLY | O_CREAT);
  27. if(destFile == -1){
  28. printf("Error: invalid destination file");
  29. return 0;
  30. }
  31.  
  32. while((ret_in = read(sourceFile, &temp, BUFFER_SIZE)) > 0){
  33. ret_out = write(destFile, &temp, (ssize_t) ret_in);
  34. if(ret_out != ret_in){
  35. printf("Copy failed");
  36. }
  37. }
  38.  
  39. close(sourceFile);
  40. close(destFile);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement