|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <config.h> |
|
|
|
|
|
#include <spawn.h> |
|
|
|
#include <errno.h> |
|
#include <stdlib.h> |
|
#include <string.h> |
|
#include <unistd.h> |
|
|
|
#if !_LIBC |
|
# define __sysconf(open_max) getdtablesize () |
|
#endif |
|
|
|
#if REPLACE_POSIX_SPAWN |
|
# include "spawn_int.h" |
|
#endif |
|
|
|
|
|
|
|
int |
|
posix_spawn_file_actions_addopen (posix_spawn_file_actions_t *file_actions, |
|
int fd, const char *path, int oflag, |
|
mode_t mode) |
|
#undef posix_spawn_file_actions_addopen |
|
{ |
|
int maxfd = __sysconf (_SC_OPEN_MAX); |
|
|
|
|
|
if (fd < 0 || fd >= maxfd) |
|
return EBADF; |
|
|
|
#if !REPLACE_POSIX_SPAWN |
|
return posix_spawn_file_actions_addopen (file_actions, fd, path, oflag, mode); |
|
#else |
|
{ |
|
|
|
|
|
char *path_copy = strdup (path); |
|
if (path_copy == NULL) |
|
return ENOMEM; |
|
|
|
|
|
if (file_actions->_used == file_actions->_allocated |
|
&& __posix_spawn_file_actions_realloc (file_actions) != 0) |
|
{ |
|
|
|
free (path_copy); |
|
return ENOMEM; |
|
} |
|
|
|
{ |
|
struct __spawn_action *rec; |
|
|
|
|
|
rec = &file_actions->_actions[file_actions->_used]; |
|
rec->tag = spawn_do_open; |
|
rec->action.open_action.fd = fd; |
|
rec->action.open_action.path = path_copy; |
|
rec->action.open_action.oflag = oflag; |
|
rec->action.open_action.mode = mode; |
|
|
|
|
|
++file_actions->_used; |
|
|
|
return 0; |
|
} |
|
} |
|
#endif |
|
} |
|
|