annotate lib/cloexec.c @ 10001:facc928673d7

Declare rpmatch.
author Bruno Haible <bruno@clisp.org>
date Tue, 29 Apr 2008 02:55:59 +0200
parents bbbbbf4cd1c5
children 27f6d88f60b1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4979
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
1 /* closexec.c - set or clear the close-on-exec descriptor flag
7302
8a1a9361108c * _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents: 6275
diff changeset
2
8a1a9361108c * _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents: 6275
diff changeset
3 Copyright (C) 1991, 2004, 2005, 2006 Free Software Foundation, Inc.
4979
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
4
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7302
diff changeset
5 This program is free software: you can redistribute it and/or modify
4979
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7302
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7302
diff changeset
8 (at your option) any later version.
4979
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
9
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
13 GNU General Public License for more details.
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
14
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7302
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
4979
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
17
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
18 The code is taken from glibc/manual/llio.texi */
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
19
7302
8a1a9361108c * _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents: 6275
diff changeset
20 #include <config.h>
4979
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
21
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
22 #include "cloexec.h"
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
23
6275
fd0ccce602e4 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6259
diff changeset
24 #include <unistd.h>
5955
ace6ea191424 Assume HAVE_FCNTL_H (i.e., include <fcntl.h> unconditionally,
Jim Meyering <jim@meyering.net>
parents: 5848
diff changeset
25 #include <fcntl.h>
4979
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
26
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
27 #ifndef FD_CLOEXEC
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
28 # define FD_CLOEXEC 1
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
29 #endif
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
30
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
31 /* Set the `FD_CLOEXEC' flag of DESC if VALUE is true,
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
32 or clear the flag if VALUE is false.
4982
87f0b7b6d498 cloexec returns int not bool, to be more consistent with Unix conventions.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4979
diff changeset
33 Return 0 on success, or -1 on error with `errno' set. */
4979
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
34
4982
87f0b7b6d498 cloexec returns int not bool, to be more consistent with Unix conventions.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4979
diff changeset
35 int
4979
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
36 set_cloexec_flag (int desc, bool value)
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
37 {
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
38 #if defined F_GETFD && defined F_SETFD
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
39
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
40 int flags = fcntl (desc, F_GETFD, 0);
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
41
4982
87f0b7b6d498 cloexec returns int not bool, to be more consistent with Unix conventions.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4979
diff changeset
42 if (0 <= flags)
87f0b7b6d498 cloexec returns int not bool, to be more consistent with Unix conventions.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4979
diff changeset
43 {
87f0b7b6d498 cloexec returns int not bool, to be more consistent with Unix conventions.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4979
diff changeset
44 int newflags = (value ? flags | FD_CLOEXEC : flags & ~FD_CLOEXEC);
4979
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
45
4982
87f0b7b6d498 cloexec returns int not bool, to be more consistent with Unix conventions.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4979
diff changeset
46 if (flags == newflags
87f0b7b6d498 cloexec returns int not bool, to be more consistent with Unix conventions.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4979
diff changeset
47 || fcntl (desc, F_SETFD, newflags) != -1)
87f0b7b6d498 cloexec returns int not bool, to be more consistent with Unix conventions.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4979
diff changeset
48 return 0;
87f0b7b6d498 cloexec returns int not bool, to be more consistent with Unix conventions.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4979
diff changeset
49 }
4979
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
50
4982
87f0b7b6d498 cloexec returns int not bool, to be more consistent with Unix conventions.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4979
diff changeset
51 return -1;
4979
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
52
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
53 #else
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
54
4982
87f0b7b6d498 cloexec returns int not bool, to be more consistent with Unix conventions.
Paul Eggert <eggert@cs.ucla.edu>
parents: 4979
diff changeset
55 return 0;
4979
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
56
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
57 #endif
6b9af4133e6f Merge changes to getloadavg.c from coreutils and Emacs; this
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
58 }