-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem_call.cpp
More file actions
52 lines (41 loc) · 999 Bytes
/
system_call.cpp
File metadata and controls
52 lines (41 loc) · 999 Bytes
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
#include<iostream>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <unistd.h>
using namespace std;
// practical 5
//copying file using system call
int main(int argc, char* argv[]) {
int fd1 , fd2;
fd1 = open(argv[1] , O_RDONLY);
fd2 = open(argv[2] , O_WRONLY|O_CREAT , 0777);
int count_fd1 , count_fd2;
char buffer[100];
if(argc!=3)
{
cout<<"Error"<<endl;
exit(100);
}
if(fd1<0)
{
cout<<"!!!!Error in opening file "<<endl;
}
else if(fd2<0)
{
cout<<"!!!Error in creating file "<<endl;
}
else
while(count_fd1 = read(fd1,buffer,sizeof(buffer)))
{
count_fd2 = write(fd2,buffer,count_fd1);
if(count_fd1!=count_fd2)
{
cout<<"!!!Error"<<endl;
}
}
close(fd1);
close(fd2);
}