[Cpp]
# Include <unistd. h>
# Include <fcntl. h>
# Include <stdlib. h>
# Define BUFFERSIZE 4096
# Define COPYMODE 0644
Void oops (char *, char *);
Int main (int argc, char * argv [])
{
Int in_fd, out_fd, n_chars;
Char buf [BUFFERSIZE];
If (argc! = 3)
{
Fprintf (stderr, "Usage: % s source destination \ n", * argv );
Exit (1 );
}
If (in_fd = open (argv [1], O_RDONLY) =-1)
Oops ("Cannot open", argv [1]);
If (out_fd = creat (argv [2], COPYMODE) =-1)
Oops ("Cannot creat", argv [2]);
While (n_chars = read (in_fd, buf, BUFFERSIZE)> 0)
{
If (write (out_fd, buf, n_chars )! = N_chars)
{
Oops ("Write error to", argv [2]);
}
}
If (n_chars =-1)
Oops ("Read error from", argv [1]);
If (close (in_fd) =-1 | close (out_fd) =-1)
Oops ("Error closing files ","");
Return 0;
}
Void oops (char * s1, char * s2)
{
Fprintf (stderr, "Error: % s", s1 );
Perror (s2 );
Exit (1 );
}