#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.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", "");
}
void oops (char *s1, char *s2)
{
fprintf (stderr, "Error:%s", S1);
Perror (S2);
Exit (1);
}
20135234 Ma Qiyang-—— Information Security system design basics Tenth Week study summary