3 * Duplicate multiple files
5 * (c) 2008 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 /*----- Data structures ---------------------------------------------------*/
34 typedef struct mdup_fd {
35 int cur; /* Current file descriptor */
36 int want; /* File descriptor wanted */
39 /*----- Functions provided ------------------------------------------------*/
43 * Arguments: @mdup_fd *v@ = pointer to @mdup_fd@ vector
44 * @size_t n@ = size of vector
46 * Returns: Zero if successful, @-1@ on failure.
48 * Use: Rearranges file descriptors.
50 * Use: Rearranges file descriptors.
52 * The vector @v@ consists of a number of @mdup_fd@ structures.
53 * Each `slot' in the table represents a file. The slot's @cur@
54 * member names the current file descriptor for this file; the
55 * @want@ member is the file descriptor we want to use for it.
56 * if you want to keep a file alive but don't care which
57 * descriptor it ends up with, set @want = -1@. Several slots
58 * may specify the same @cur@ descriptor; but they all have to
59 * declare different @want@s (except that several slots may have
62 * On successful exit, the function will have rearranged the
63 * file descriptors as requested. To reflect this, the @cur@
64 * members will all be set to match the (non-@-1@) @want@
67 * If there is a failure, then some rearrangement may have been
68 * performed and some not; the @cur@ members are set to reflect
69 * which file descriptors are to be used. The old file
70 * descriptors are closed. (This is different from usual @dup@
71 * behaviour, of course, but essential for reliable error
72 * handling.) If you want to keep a particular source file
73 * descriptor open as well as make a new copy then specify two
74 * slots with the same @cur@, one with @want = cur@ and one with
75 * the desired output descriptor.
77 * This function works correctly even if the desired remappings
81 extern int mdup(mdup_fd */*v*/, size_t /*n*/);
83 /*----- That's all, folks -------------------------------------------------*/