1 /* Copyright (C) 2018-2020 Free Software Foundation, Inc.
3 This program is free software: you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 3 of the License, or
6 (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <https://www.gnu.org/licenses/>. */
25 # define __sysconf(open_max) getdtablesize ()
28 #if REPLACE_POSIX_SPAWN
29 # include "spawn_int.h"
32 /* Add an action to FILE-ACTIONS which tells the implementation to call
33 'fchdir' to the given directory during the 'spawn' call. */
35 posix_spawn_file_actions_addfchdir (posix_spawn_file_actions_t
*file_actions
,
37 #undef posix_spawn_file_actions_addfchdir
39 int maxfd
= __sysconf (_SC_OPEN_MAX
);
41 /* Test for the validity of the file descriptor. */
42 if (fd
< 0 || fd
>= maxfd
)
45 #if !REPLACE_POSIX_SPAWN
46 return posix_spawn_file_actions_addfchdir_np (file_actions
, fd
);
48 /* Allocate more memory if needed. */
49 if (file_actions
->_used
== file_actions
->_allocated
50 && __posix_spawn_file_actions_realloc (file_actions
) != 0)
51 /* This can only mean we ran out of memory. */
55 struct __spawn_action
*rec
;
57 /* Add the new value. */
58 rec
= &file_actions
->_actions
[file_actions
->_used
];
59 rec
->tag
= spawn_do_fchdir
;
60 rec
->action
.fchdir_action
.fd
= fd
;
62 /* Account for the new entry. */
63 ++file_actions
->_used
;