-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcloseonexec.c
65 lines (60 loc) · 1.11 KB
/
closeonexec.c
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
/* $Revision: 6790 $
**
*/
/*#include "configdata.h"*/
#include <stdio.h>
#include <sys/types.h>
#include <errno.h>
#include <sys/ioctl.h>
#include "clibrary.h"
#ifndef CLX_IOCTL
# define CLX_IOCTL
#endif
#ifndef CLX_FCNTL
# define CLX_FCNTL
#endif
//add for cygwin
#ifndef FIOCLEX
#define FIOCLEX 0x5451
#endif
#ifndef FIONCLEX
#define FIONCLEX 0x5450
#endif
#if defined(CLX_IOCTL) && !defined(IRIX)
#if defined(__linux) || defined(CYGWIN)
#include <termios.h>
#else
#include <sgtty.h>
#endif
/*
** Mark a file close-on-exec so that it doesn't get shared with our
** children. Ignore any error codes.
*/
void
closeOnExec(fd, flag)
int fd;
int flag;
{
int oerrno;
oerrno = errno;
(void) ioctl(fd, flag ? FIOCLEX : FIONCLEX, (char *) NULL);
errno = oerrno;
}
#endif /* defined(CLX_IOCTL) */
#if defined(CLX_FCNTL)
#include <fcntl.h>
/*
** Mark a file close-on-exec so that it doesn't get shared with our
** children. Ignore any error codes.
*/
void
CloseOnExec(fd, flag)
int fd;
int flag;
{
int oerrno;
oerrno = errno;
(void) fcntl(fd, F_SETFD, flag ? 1 : 0);
errno = oerrno;
}
#endif /* defined(CLX_FCNTL) */