1*1c3b0983Skre /* $NetBSD: redir.h,v 1.29 2024/11/11 22:57:42 kre Exp $ */ 249f0ad86Scgd 361f28255Scgd /*- 437ed7877Sjtc * Copyright (c) 1991, 1993 537ed7877Sjtc * The Regents of the University of California. All rights reserved. 661f28255Scgd * 761f28255Scgd * This code is derived from software contributed to Berkeley by 861f28255Scgd * Kenneth Almquist. 961f28255Scgd * 1061f28255Scgd * Redistribution and use in source and binary forms, with or without 1161f28255Scgd * modification, are permitted provided that the following conditions 1261f28255Scgd * are met: 1361f28255Scgd * 1. Redistributions of source code must retain the above copyright 1461f28255Scgd * notice, this list of conditions and the following disclaimer. 1561f28255Scgd * 2. Redistributions in binary form must reproduce the above copyright 1661f28255Scgd * notice, this list of conditions and the following disclaimer in the 1761f28255Scgd * documentation and/or other materials provided with the distribution. 18b5b29542Sagc * 3. Neither the name of the University nor the names of its contributors 1961f28255Scgd * may be used to endorse or promote products derived from this software 2061f28255Scgd * without specific prior written permission. 2161f28255Scgd * 2261f28255Scgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2361f28255Scgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2461f28255Scgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2561f28255Scgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2661f28255Scgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2761f28255Scgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2861f28255Scgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2961f28255Scgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3061f28255Scgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3161f28255Scgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3261f28255Scgd * SUCH DAMAGE. 3361f28255Scgd * 3407bae7edSchristos * @(#)redir.h 8.2 (Berkeley) 5/4/95 3561f28255Scgd */ 3661f28255Scgd 3761f28255Scgd /* flags passed to redirect */ 385047abd1Schristos #define REDIR_PUSH 0x01 /* save previous values of file descriptors */ 395047abd1Schristos #define REDIR_BACKQ 0x02 /* save the command output in memory */ 405047abd1Schristos #define REDIR_VFORK 0x04 /* running under vfork(2), be careful */ 415047abd1Schristos #define REDIR_KEEP 0x08 /* don't close-on-exec */ 4261f28255Scgd 43*1c3b0983Skre /* flags passed to popredir and free_rl */ 44*1c3b0983Skre #define POPREDIR_DISCARD 0 /* just abandon everything */ 45*1c3b0983Skre #define POPREDIR_UNDO 1 /* undo saved redirects */ 46*1c3b0983Skre #define POPREDIR_PERMANENT 2 /* keep renamed fd, close saving fd */ 47*1c3b0983Skre 4861f28255Scgd union node; 49c02b3bbdSchristos void redirect(union node *, int); 50*1c3b0983Skre void popredir(int); 51c02b3bbdSchristos int fd0_redirected_p(void); 52c02b3bbdSchristos void clearredir(int); 531fad4bb6Schristos int movefd(int, int); 541fad4bb6Schristos int to_upper_fd(int); 5551c4dfe4Skre void register_sh_fd(int, void (*)(int, int)); 5651c4dfe4Skre void sh_close(int); 573b297678Skre struct output; 583b297678Skre int outredir(struct output *, union node *, int); 59c1cbf199Skre 60761b9f95Sjoerg extern int max_user_fd; /* highest fd used by user */ 6152967993Skre extern long user_fd_limit; /* highest possible user fd */ 62