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
|
/* See LICENSE file for copyright and license details. */
#include <sys/wait.h>
#include <unistd.h>
#define eexecvp(F, ...) (execvp(F, __VA_ARGS__), eprintf("exec %s:", F))
#define eexeclp(F, ...) (execlp(F, __VA_ARGS__), eprintf("exec %s:", F))
static inline void
epipe(int fds[2])
{
if (pipe(fds))
eprintf("pipe:");
}
static inline pid_t
efork(void)
{
pid_t ret = fork();
if (ret < 0)
eprintf("fork:");
return ret;
}
static inline void
edup2(int old, int new)
{
if (dup2(old, new) < 0)
eprintf("dup2:");
}
static inline int
edup(int fd)
{
int ret = dup(fd);
if (ret < 0)
eprintf("dup:");
return ret;
}
static inline pid_t
ewaitpid(pid_t pid, int *status, int flags)
{
pid_t ret = waitpid(pid, status, flags);
if (ret < 0)
eprintf("waitpid:");
return ret;
}
static inline size_t
eread(int fd, void *buf, size_t n, const char *fname)
{
ssize_t ret = read(fd, buf, n);
if (ret < 0)
eprintf("read %s:", fname);
return (size_t)ret;
}
static inline size_t
epread(int fd, void *buf, size_t n, off_t off, const char *fname)
{
ssize_t ret = pread(fd, buf, n, off);
if (ret < 0)
eprintf("pread %s:", fname);
return (size_t)ret;
}
static inline off_t
elseek(int fd, off_t offset, int whence, const char *fname)
{
off_t ret = lseek(fd, offset, whence);
if (ret < 0)
eprintf("lseek %s:", fname);
return ret;
}
|