This source file includes following definitions.
- posix_spawn_file_actions_addopen
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 <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26
27 #if !_LIBC
28 # define __sysconf(open_max) getdtablesize ()
29 #endif
30
31 #if REPLACE_POSIX_SPAWN
32 # include "spawn_int.h"
33 #endif
34
35
36
37 int
38 posix_spawn_file_actions_addopen (posix_spawn_file_actions_t *file_actions,
39 int fd, const char *path, int oflag,
40 mode_t mode)
41 #undef posix_spawn_file_actions_addopen
42 {
43 int maxfd = __sysconf (_SC_OPEN_MAX);
44
45
46 if (fd < 0 || fd >= maxfd)
47 return EBADF;
48
49 #if !REPLACE_POSIX_SPAWN
50 return posix_spawn_file_actions_addopen (file_actions, fd, path, oflag, mode);
51 #else
52 {
53
54
55 char *path_copy = strdup (path);
56 if (path_copy == NULL)
57 return ENOMEM;
58
59
60 if (file_actions->_used == file_actions->_allocated
61 && __posix_spawn_file_actions_realloc (file_actions) != 0)
62 {
63
64 free (path_copy);
65 return ENOMEM;
66 }
67
68 {
69 struct __spawn_action *rec;
70
71
72 rec = &file_actions->_actions[file_actions->_used];
73 rec->tag = spawn_do_open;
74 rec->action.open_action.fd = fd;
75 rec->action.open_action.path = path_copy;
76 rec->action.open_action.oflag = oflag;
77 rec->action.open_action.mode = mode;
78
79
80 ++file_actions->_used;
81
82 return 0;
83 }
84 }
85 #endif
86 }