blob: 0211c5498f6ef16fd1e8940f0f0f7ce7f17384a9 (
plain)
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
|
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#ifdef __linux__
#include <linux/limits.h>
#endif
#include "cron.h"
int close_all(int start)
{
#ifdef F_CLOSEM
return fcntl(start, F_CLOSEM);
#else
int fd, max;
max = sysconf(_SC_OPEN_MAX);
if (max <= 0)
return -1;
#ifdef __linux__
if (max < NR_OPEN)
max = NR_OPEN;
#endif
for (fd = start; fd < max; fd++) {
if (close(fd) && errno != EBADF)
return -1;
}
return 0;
#endif
}
|