forked from ochko/safeexec
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathsafe.c
More file actions
42 lines (35 loc) · 712 Bytes
/
safe.c
File metadata and controls
42 lines (35 loc) · 712 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
#define _GNU_SOURCE
#include "safe.h"
#define SAFE_LOOP(u,v) while (((u) = (v)), (((v) < 0) && (errno == EINTR)))
int safe_close (int fd)
{
int v;
SAFE_LOOP (v, close (fd));
return (v);
}
int safe_dup2 (int oldfd, int newfd)
{
int v;
SAFE_LOOP (v, dup2 (oldfd, newfd));
return (v);
}
int safe_sigaction (int n, struct sigaction *u, struct sigaction *v)
{
int w;
SAFE_LOOP (w, sigaction (n, u, v));
return (w);
}
int safe_fcntl (int fd, int u, int v)
{
int w;
SAFE_LOOP (w, fcntl (fd, u, v));
return (w);
}
int safe_signal (int n, void (*p) (int))
{
struct sigaction u, v;
u.sa_handler = p;
sigemptyset (&u.sa_mask);
u.sa_flags = 0;
return (safe_sigaction (n, &u, &v));
}