Mercurial > gnulib
annotate lib/savewd.h @ 40231:9b3c79fdfe0b
strtod: fix clash with strtold
Problem reported for RHEL 5 by Jesse Caldwell (Bug#34817).
* lib/strtod.c (compute_minus_zero, minus_zero):
Simplify by remving the macro / external variable,
and having just a function. User changed. This avoids
the need for an external variable that might clash.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Mon, 11 Mar 2019 16:40:29 -0700 |
parents | b06060465f09 |
children |
rev | line source |
---|---|
7315 | 1 /* Save and restore the working directory, possibly using a subprocess. |
2 | |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
3 Copyright (C) 2006, 2009-2019 Free Software Foundation, Inc. |
7315 | 4 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7316
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify |
7315 | 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:
7316
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:
7316
diff
changeset
|
8 (at your option) any later version. |
7315 | 9 |
10 This program is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 GNU General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU General Public License | |
19190 | 16 along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
7315 | 17 |
18 /* Written by Paul Eggert. */ | |
19 | |
20 #ifndef SAVEWD_H | |
21 # define SAVEWD_H 1 | |
22 | |
23 #include <stdbool.h> | |
24 #include <sys/types.h> | |
25 | |
17473
1f9070ef79b0
headers: check that _GL_INLINE_HEADER_BEGIN is defined
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
26 #ifndef _GL_INLINE_HEADER_BEGIN |
1f9070ef79b0
headers: check that _GL_INLINE_HEADER_BEGIN is defined
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
27 #error "Please include config.h first." |
1f9070ef79b0
headers: check that _GL_INLINE_HEADER_BEGIN is defined
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
28 #endif |
17181
a80e4b259d9b
chdir-long, cycle-check, savewd: better 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
29 _GL_INLINE_HEADER_BEGIN |
a80e4b259d9b
chdir-long, cycle-check, savewd: better 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
30 #ifndef SAVEWD_INLINE |
a80e4b259d9b
chdir-long, cycle-check, savewd: better 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
31 # define SAVEWD_INLINE _GL_INLINE |
a80e4b259d9b
chdir-long, cycle-check, savewd: better 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
32 #endif |
a80e4b259d9b
chdir-long, cycle-check, savewd: better 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
33 |
7315 | 34 /* A saved working directory. The member names and constants defined |
35 by this structure are private to the savewd module. */ | |
36 struct savewd | |
37 { | |
38 /* The state of this object. */ | |
39 enum | |
40 { | |
41 /* This object has been created but does not yet represent | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
42 the working directory. */ |
7315 | 43 INITIAL_STATE, |
44 | |
45 /* val.fd is the original working directory's file descriptor. | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
46 It is still the working directory. */ |
7315 | 47 FD_STATE, |
48 | |
49 /* Like FD_STATE, but the working directory has changed, so | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
50 restoring it will require a fchdir. */ |
7315 | 51 FD_POST_CHDIR_STATE, |
52 | |
53 /* Fork and let the subprocess do the work. val.child is 0 in a | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
54 child, negative in a childless parent, and the child process |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
55 ID in a parent with a child. */ |
7315 | 56 FORKING_STATE, |
57 | |
58 /* A serious problem argues against further efforts. val.errnum | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
59 contains the error number (e.g., EIO). */ |
7315 | 60 ERROR_STATE, |
61 | |
62 /* savewd_finish has been called, so the application no longer | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
63 cares whether the working directory is saved, and there is no |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
64 more work to do. */ |
7315 | 65 FINAL_STATE |
66 } state; | |
67 | |
68 /* The object's value. */ | |
69 union | |
70 { | |
71 int fd; | |
72 int errnum; | |
73 pid_t child; | |
74 } val; | |
75 }; | |
76 | |
77 /* Initialize a saved working directory object. */ | |
17181
a80e4b259d9b
chdir-long, cycle-check, savewd: better 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
78 SAVEWD_INLINE void |
7315 | 79 savewd_init (struct savewd *wd) |
80 { | |
81 wd->state = INITIAL_STATE; | |
82 } | |
83 | |
84 | |
18104
76e10610d806
savewd: remove SAVEWD_CHDIR_READABLE
Paul Eggert <eggert@cs.ucla.edu>
parents:
17848
diff
changeset
|
85 /* Options for savewd_chdir. Can be ORed together. */ |
7315 | 86 enum |
87 { | |
88 /* Do not follow symbolic links, if supported. */ | |
89 SAVEWD_CHDIR_NOFOLLOW = 1, | |
90 | |
91 /* Do not chdir if the directory is readable; simply succeed | |
92 without invoking chdir if the directory was opened. */ | |
18104
76e10610d806
savewd: remove SAVEWD_CHDIR_READABLE
Paul Eggert <eggert@cs.ucla.edu>
parents:
17848
diff
changeset
|
93 SAVEWD_CHDIR_SKIP_READABLE = 2 |
7315 | 94 }; |
95 | |
96 /* Change the directory, and if successful, record into *WD the fact | |
97 that the process chdired into DIR. A process using this module | |
98 should use savewd_chdir rather than chdir or fchdir. Obey the | |
99 options specified in OPTIONS. | |
100 | |
101 If OPEN_RESULT is not null, store into OPEN_RESULT[0] a file | |
102 descriptor that accesses DIR if a file descriptor is successfully | |
103 obtained. Store -1 otherwise, setting OPEN_RESULT[1] to the error | |
104 number. Store through OPEN_RESULT regardless of whether the chdir | |
105 is successful. However, when -2 is returned, the contents of | |
106 OPEN_RESULT are indeterminate since the file descriptor is closed | |
107 in the parent. | |
108 | |
109 Return -2 if a subprocess was spun off to do the real work, -1 | |
110 (setting errno) if unsuccessful, 0 if successful. */ | |
111 int savewd_chdir (struct savewd *wd, char const *dir, int options, | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
112 int open_result[2]); |
7315 | 113 |
114 /* Restore the working directory from *WD. STATUS indicates the exit | |
115 status corresponding to the work done since the last save; this is | |
116 used when the caller is in a subprocess. Return 0 if successful, | |
117 -1 (setting errno) on our failure, a positive subprocess exit | |
118 status if the working directory was restored in the parent but the | |
119 subprocess failed. */ | |
120 int savewd_restore (struct savewd *wd, int status); | |
121 | |
122 /* Return WD's error number, or 0 if WD is not in an error state. */ | |
17820
5ca75b20ebc2
apply _GL_ATTRIBUTE_PURE to some inline functions
Pádraig Brady <P@draigBrady.com>
parents:
17576
diff
changeset
|
123 SAVEWD_INLINE int _GL_ATTRIBUTE_PURE |
7315 | 124 savewd_errno (struct savewd const *wd) |
125 { | |
126 return (wd->state == ERROR_STATE ? wd->val.errnum : 0); | |
127 } | |
128 | |
129 /* Deallocate any resources associated with WD. A program that chdirs | |
130 should restore before finishing. */ | |
131 void savewd_finish (struct savewd *wd); | |
132 | |
133 /* Process N_FILES file names, FILE[0] through FILE[N_FILES - 1]. | |
134 For each file name F, call ACT (F, WD, OPTIONS); ACT should invoke | |
135 savewd_chdir as needed, and should return an exit status. WD | |
7316 | 136 represents the working directory; it may be in an error state when |
7315 | 137 ACT is called. |
138 | |
139 Save and restore the working directory as needed by the file name | |
140 vector; assume that ACT does not require access to any relative | |
141 file names other than its first argument, and that it is OK if the | |
142 working directory is changed when this function returns. Some | |
143 actions may be applied in a subprocess. | |
144 | |
145 Return the maximum exit status that any call to ACT returned, or | |
146 EXIT_SUCCESS (i.e., 0) if no calls were made. */ | |
147 int savewd_process_files (int n_files, char **file, | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
148 int (*act) (char *, struct savewd *, void *), |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
149 void *options); |
7315 | 150 |
17181
a80e4b259d9b
chdir-long, cycle-check, savewd: better 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
151 _GL_INLINE_HEADER_END |
a80e4b259d9b
chdir-long, cycle-check, savewd: better 'inline'
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
152 |
7315 | 153 #endif |