annotate lib/dup.c @ 16201:8250f2777afc

maint: update all copyright year number ranges Run "make update-copyright".
author Jim Meyering <meyering@redhat.com>
date Sun, 01 Jan 2012 10:04:58 +0100
parents 45b9be95a543
children dd46d4e6beea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15760
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Duplicate an open file descriptor.
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2
16201
8250f2777afc maint: update all copyright year number ranges
Jim Meyering <meyering@redhat.com>
parents: 15760
diff changeset
3 Copyright (C) 2011-2012 Free Software Foundation, Inc.
15760
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8 (at your option) any later version.
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 #include <config.h>
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 /* Specification. */
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <unistd.h>
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <errno.h>
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include "msvc-inval.h"
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #undef dup
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 #if HAVE_MSVC_INVALID_PARAMETER_HANDLER
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 static inline int
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 dup_nothrow (int fd)
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 {
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 int result;
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 TRY_MSVC_INVAL
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 {
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 result = dup (fd);
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 }
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 CATCH_MSVC_INVAL
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 {
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 result = -1;
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 errno = EBADF;
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 }
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 DONE_MSVC_INVAL;
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 return result;
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 }
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 #else
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 # define dup_nothrow dup
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 #endif
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 int
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 rpl_dup (int fd)
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 {
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 int result = dup_nothrow (fd);
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 #if REPLACE_FCHDIR
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 if (result >= 0)
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 result = _gl_register_dup (fd, result);
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 #endif
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 return result;
45b9be95a543 New module 'dup'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 }