#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
int main(void)
{
const char *pathName = "f.c";
int in, out, flag;
char buffer[1024];
in = open("z.c", O_RDONLY, S_IRUSR);
if (-1 == in) // ,
{
printf("open file z.c error !
");
return -1;
}
out = creat(pathName, S_IWUSR);
if (-1 == in) // ,
{
printf("create file %s error !
", pathName);
return -1;
}
while ((flag = read(in, buffer, 1024)) > 0)
{
write(out, buffer, flag);
}
close(in);
close(out);
printf("copy file z.t to %s finish !
", pathName);
return 0;
}