#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
/*
./copy a.txt b.txt
argc = 3
argv[0] = "./copy"
argv[1] = "a.txt"
argv[2] = "b.txt"
*/
int main(int argc, char **argv)
{
int fd_old, fd_new;
char buf[1024];
int len;
if(argc != 3)
{
printf("Usage: %s <old-file> <new-file>",argv[0]);
return -1;
}
fd_old = open(argv[1],O_RDONLY);
if(fd_old == -1)
{
printf("cannot open file %s\n",argv[1]);
return -1;
}
fd_new = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP
| S_IWGRP | S_IROTH | S_IWOTH);
if(fd_new == -1)
{