I have a program that take two files Source and Destination.
I am trying to Copies the SOURCE file to the DESTINATION file. If DESTINATION does not exist, it is created. If DESTINATION exists and is a file, it is overwritten. If DESTINATION exists and is a directory, the source files will be copied there.
How can i copy the source file into the destination directory using calls system ?
What i tried :
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include "checksum.h"
int main (int argc, char *argv[])
{
if (argc < 3) {
fprintf(stderr, "Usage: lcp [-b taille] source... destination\n");
exit(1);
}
int fd1 = open(argv[1], O_RDONLY, 0644); //0644 — owner can read or write, group and others can only read; or something more restrictive).
if (fd1 < 0)
{
fprintf(stderr, "%s: failed to open file %s for reading\n", argv[0], argv[1]);
return 1;
}
int fd2 = open(argv[2], O_RDWR|O_CREAT);
if (fd2 < 0)
{
fprintf(stderr, "%s: failed to open file %s for reading and writing\n", argv[0], argv[2]);
return 1;
}
close(fd1);
close(fd2);
return 0;
}