This source file includes following definitions.
- posix_spawn_file_actions_adddup2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include <config.h>
18
19
20 #include <spawn.h>
21
22 #include <errno.h>
23 #include <unistd.h>
24
25 #if !_LIBC
26 # define __sysconf(open_max) getdtablesize ()
27 #endif
28
29 #if REPLACE_POSIX_SPAWN
30 # include "spawn_int.h"
31 #endif
32
33
34
35 int
36 posix_spawn_file_actions_adddup2 (posix_spawn_file_actions_t *file_actions,
37 int fd, int newfd)
38 #undef posix_spawn_file_actions_adddup2
39 {
40 int maxfd = __sysconf (_SC_OPEN_MAX);
41
42
43 if (fd < 0 || newfd < 0 || fd >= maxfd || newfd >= maxfd)
44 return EBADF;
45
46 #if !REPLACE_POSIX_SPAWN
47 return posix_spawn_file_actions_adddup2 (file_actions, fd, newfd);
48 #else
49
50 if (file_actions->_used == file_actions->_allocated
51 && __posix_spawn_file_actions_realloc (file_actions) != 0)
52
53 return ENOMEM;
54
55 {
56 struct __spawn_action *rec;
57
58
59 rec = &file_actions->_actions[file_actions->_used];
60 rec->tag = spawn_do_dup2;
61 rec->action.dup2_action.fd = fd;
62 rec->action.dup2_action.newfd = newfd;
63
64
65 ++file_actions->_used;
66
67 return 0;
68 }
69 #endif
70 }