-
Notifications
You must be signed in to change notification settings - Fork 0
/
.goutputstream-KKZ5GX
92 lines (78 loc) · 1.53 KB
/
.goutputstream-KKZ5GX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define BUFFER_SIZE 1024
int main(int argc, char *argv[])
{
int fd_from,fd_to;//
int file_access=0;//
int byte_read,byte_write;
int i=0;
char file_buf[BUFFER_SIZE];
char *ptr;
if(argc!=3)//
{
printf("An incorrect input ! please check the parameter.\n");
exit(EXIT_FAILURE);
}
if(access(argv[1],F_OK))//
{
printf("there is no file %s !\n",argv[1]);
exit(EXIT_FAILURE);
}
if(access(argv[1],R_OK))//
{
printf("you have no read permission to file %s !\n",argv[1]);
exit(EXIT_FAILURE);
}
else
{
file_access+=4;
}
if(access(argv[1],W_OK)==0)//
{
file_access+=2;
}
if(access(argv[1],X_OK)==0)//
{
file_access+=1;
}
if((fd_from=open(argv[1],O_RDONLY))<0)
{
printf("you can't open the file %s !\n",argv[1]);
exit(EXIT_FAILURE);
}
if(file_access==5)
{
if((fd_to=creat(argv[2],0555))<0)
{
printf("creat file %s failure ! \n",argv[2]);
close(fd_from);
exit(EXIT_FAILURE);
}
}
else if(file_access==6)
{
if((fd_to=creat(argv[2],0655))<0)
{
printf("creat file %s failure ! \n",argv[2]);
close(fd_from);
exit(EXIT_FAILURE);
}
}
else if(file_access==7)
{
if((fd_to=creat(argv[2],0755))<0)
{
printf("creat file %s failure ! \n",argv[2]);
close(fd_from);
exit(EXIT_FAILURE);
}
}
while(byte_read=read(fd_from,file_buf,BUFFER_SIZE))
{
if(byte_read==-1)
{
printf("