-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyswrappers.c
More file actions
159 lines (138 loc) · 3.5 KB
/
syswrappers.c
File metadata and controls
159 lines (138 loc) · 3.5 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include <unistd.h>
#include <sys/wait.h>
#include <signal.h>
#include <fcntl.h>
#include "utils.h"
#include "syswrappers.h"
pid_t Fork(void) {
pid_t pid;
if ((pid = fork()) < 0)
unix_error("fork error");
return pid;
}
int Kill(pid_t pid, int sig) {
int ret;
if (ret = kill(pid, sig) == -1)
unix_error("kill error");
return ret;
}
int Pause(void) {
return pause();
}
ssize_t Write(int fildes, const void *buf, size_t nbyte) {
ssize_t ret;
if (ret = write(fildes, buf, nbyte) == -1)
unix_error("write error");
return ret;
}
pid_t Wait(int *status) {
pid_t ret;
if ((ret = wait(status) == -1))
unix_error("wait error");
return ret;
}
pid_t Waitpid(pid_t pid, int *status, int options) {
pid_t ret;
if ((ret = waitpid(pid, status, options)) == -1)
unix_error("waitpid error");
return ret;
}
int Sigaction(int sig, const struct sigaction *restrict act, struct sigaction *restrict aact) {
int ret;
if ((ret = sigaction(sig, act, aact)) == -1)
unix_error("sigaction error");
return ret;
}
int Pipe(int fildes[2]) {
int ret;
if ((ret = pipe(fildes)) == -1) {
unix_error("pipe error");
}
return ret;
}
int Dup(int fildes) {
int ret;
if ((ret = dup(fildes)) == -1)
unix_error("dup error");
return ret;
}
int Dup2(int fildes, int fildes2) {
int ret;
if ((ret = dup2(fildes, fildes2)) == -1)
unix_error("dup2 error");
return ret;
}
int Open(const char *pathname, int flags) {
int ret;
if ((ret = open(pathname, flags)) == -1)
unix_error("open error");
return ret;
}
/*
int Open(const char *pathname, int flags, mode_t mode) {
int ret;
if ((ret = opnen(pathname, flags, mode)) == -1)
unix_error("open error");
return ret;
}
*/
int Close(int fildes) {
int ret;
if ((ret = close(fildes)) == -1)
unix_error("close error");
return ret;
}
int Execvp(const char *file, char *const argv[]) {
int ret;
if ((ret = execvp(file, argv)) == -1)
unix_error("execvp error");
return ret;
}
int Sigprocmask(int how, const sigset_t *set, sigset_t *oset) {
int ret;
if ((ret = sigprocmask(how, set, oset)) == -1)
unix_error("sigprocmask error");
return ret;
}
int Sigsuspend(const sigset_t *mask) {
int ret;
if ((ret = sigsuspend(mask)) == -1)
//unix_error("sigsuspend error");
return ret;
}
int Sigemptyset(sigset_t *set) {
int ret;
if ((ret = sigemptyset(set)) == -1)
unix_error("sigemptyset error");
return ret;
}
int Sigaddset(sigset_t *set, int signo) {
int ret;
if ((ret = sigaddset(set, signo)) == -1)
unix_error("sigaddset error");
return ret;
}
int Sigfillset(sigset_t *set) {
int ret;
if ((ret = sigfillset(set)) == -1)
unix_error("sigfillset error");
return ret;
}
int Setpgid(pid_t pid, pid_t pgid) {
int ret;
if ((ret = setpgid(pid, pgid)) == -2)
unix_error("setpgid error");
return ret;
}
int Tcsetpgrp(int fildes, pid_t pgid_id) {
int ret;
if ((ret = tcsetpgrp(fildes, pgid_id)) == -1)
unix_error("tcsetpgrp error");
return ret;
}
sighandler_t Signal(int signum, sighandler_t handler) {
sighandler_t ret;
if ((ret = signal(signum, handler)) == SIG_ERR)
unix_error("signal error");
return ret;
}