1*09d4459fSDaniel Fojt /* cloexec.c - set or clear the close-on-exec descriptor flag 2cf28ed85SJohn Marino 3*09d4459fSDaniel Fojt Copyright (C) 2004, 2009-2020 Free Software Foundation, Inc. 4cf28ed85SJohn Marino 5cf28ed85SJohn Marino This program is free software: you can redistribute it and/or modify 6cf28ed85SJohn Marino it under the terms of the GNU General Public License as published by 7cf28ed85SJohn Marino the Free Software Foundation; either version 3 of the License, or 8cf28ed85SJohn Marino (at your option) any later version. 9cf28ed85SJohn Marino 10cf28ed85SJohn Marino This program is distributed in the hope that it will be useful, 11cf28ed85SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of 12cf28ed85SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13cf28ed85SJohn Marino GNU General Public License for more details. 14cf28ed85SJohn Marino 15cf28ed85SJohn Marino You should have received a copy of the GNU General Public License 16*09d4459fSDaniel Fojt along with this program. If not, see <https://www.gnu.org/licenses/>. 17cf28ed85SJohn Marino 18cf28ed85SJohn Marino */ 19cf28ed85SJohn Marino 20cf28ed85SJohn Marino #include <stdbool.h> 21cf28ed85SJohn Marino 22cf28ed85SJohn Marino /* Set the 'FD_CLOEXEC' flag of DESC if VALUE is true, 23cf28ed85SJohn Marino or clear the flag if VALUE is false. 24cf28ed85SJohn Marino Return 0 on success, or -1 on error with 'errno' set. 25cf28ed85SJohn Marino 26cf28ed85SJohn Marino Note that on MingW, this function does NOT protect DESC from being 27cf28ed85SJohn Marino inherited into spawned children. Instead, either use dup_cloexec 28cf28ed85SJohn Marino followed by closing the original DESC, or use interfaces such as 29cf28ed85SJohn Marino open or pipe2 that accept flags like O_CLOEXEC to create DESC 30cf28ed85SJohn Marino non-inheritable in the first place. */ 31cf28ed85SJohn Marino 32cf28ed85SJohn Marino int set_cloexec_flag (int desc, bool value); 33cf28ed85SJohn Marino 34cf28ed85SJohn Marino /* Duplicates a file handle FD, while marking the copy to be closed 35cf28ed85SJohn Marino prior to exec or spawn. Returns -1 and sets errno if FD could not 36cf28ed85SJohn Marino be duplicated. */ 37cf28ed85SJohn Marino 38cf28ed85SJohn Marino int dup_cloexec (int fd); 39