Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <unistd.h>
- #define BUFFER_SIZE 1024
- int main(){
- char *sourcePath, *destPath;
- ssize_t ret_in, ret_out;
- char temp[BUFFER_SIZE];
- printf("Enter source file path: ");
- scanf("%s", sourcePath);
- printf("Enter destination file path: ");
- scanf("%s", destPath);
- int sourceFile = open(sourcePath, O_RDONLY);
- if(sourceFile == -1){
- printf("Error: invalid source file");
- return 0;
- }
- int destFile = open(destPath, O_WRONLY | O_CREAT);
- if(destFile == -1){
- printf("Error: invalid destination file");
- return 0;
- }
- while((ret_in = read(sourceFile, &temp, BUFFER_SIZE)) > 0){
- ret_out = write(destFile, &temp, (ssize_t) ret_in);
- if(ret_out != ret_in){
- printf("Copy failed");
- }
- }
- close(sourceFile);
- close(destFile);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement