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 * The vector @v@ consists of a number of @mdup_fd@ structures.
51 * Each `slot' in the table represents a file. The slot's @cur@
52 * member names the current file descriptor for this file; the
53 * @want@ member is the file descriptor we want to use for it.
54 * if you want to keep a file alive but don't care which
55 * descriptor it ends up with, set @want = -1@. Several slots
56 * may specify the same @cur@ descriptor; but they all have to
57 * declare different @want@s (except that several slots may have
60 * On successful exit, the function will have rearranged the
61 * file descriptors as requested. To reflect this, the @cur@
62 * members will all be set to match the (non-@-1@) @want@
65 * If there is a failure, then some rearrangement may have been
66 * performed and some not; the @cur@ members are set to reflect
67 * which file descriptors are to be used. The old file
68 * descriptors are closed. (This is different from usual @dup@
69 * behaviour, of course, but essential for reliable error
70 * handling.) If you want to keep a particular source file
71 * descriptor open as well as make a new copy then specify two
72 * slots with the same @cur@, one with @want = cur@ and one with
73 * the desired output descriptor.
75 * This function works correctly even if the desired remappings
79 extern int mdup(mdup_fd */*v*/, size_t /*n*/);
81 /*----- That's all, folks -------------------------------------------------*/