1 /* Copyright (C) 2000 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
26 # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
28 # define __sysconf(open_max) _getmaxstdio ()
30 # define __sysconf(open_max) getdtablesize ()
34 #include "spawn_int.h"
36 /* Add an action to FILE-ACTIONS which tells the implementation to call
37 `open' for the given file during the `spawn' call. */
39 posix_spawn_file_actions_addopen (posix_spawn_file_actions_t *file_actions,
40 int fd, const char *path, int oflag,
43 int maxfd = __sysconf (_SC_OPEN_MAX);
44 struct __spawn_action *rec;
46 /* Test for the validity of the file descriptor. */
47 if (fd < 0 || fd >= maxfd)
50 /* Allocate more memory if needed. */
51 if (file_actions->_used == file_actions->_allocated
52 && __posix_spawn_file_actions_realloc (file_actions) != 0)
53 /* This can only mean we ran out of memory. */
56 /* Add the new value. */
57 rec = &file_actions->_actions[file_actions->_used];
58 rec->tag = spawn_do_open;
59 rec->action.open_action.fd = fd;
60 rec->action.open_action.path = path;
61 rec->action.open_action.oflag = oflag;
62 rec->action.open_action.mode = mode;
64 /* Account for the new entry. */
65 ++file_actions->_used;