Mercurial > gnulib
annotate lib/close-stream.c @ 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 |
---|---|
7035 | 1 /* Close a stream, with nicer error checking than fclose's. |
2 | |
40057
b06060465f09
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19484
diff
changeset
|
3 Copyright (C) 1998-2002, 2004, 2006-2019 Free Software Foundation, Inc. |
7035 | 4 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9183
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify |
7035 | 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:
9183
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:
9183
diff
changeset
|
8 (at your option) any later version. |
7035 | 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/>. */ |
7035 | 17 |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
7035
diff
changeset
|
18 #include <config.h> |
7035 | 19 |
20 #include "close-stream.h" | |
21 | |
22 #include <errno.h> | |
23 #include <stdbool.h> | |
24 | |
9183
cc316ffcb4fc
Rename __fpending.c -> fpending.c and __fpending.h -> fpending.h
Jim Meyering <jim@meyering.net>
parents:
7302
diff
changeset
|
25 #include "fpending.h" |
7035 | 26 |
27 #if USE_UNLOCKED_IO | |
28 # include "unlocked-io.h" | |
29 #endif | |
30 | |
31 /* Close STREAM. Return 0 if successful, EOF (setting errno) | |
32 otherwise. A failure might set errno to 0 if the error number | |
33 cannot be determined. | |
34 | |
10595
37b949ffd096
Add an option for ignoring EPIPE during close_stdout.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
35 A failure with errno set to EPIPE may or may not indicate an error |
37b949ffd096
Add an option for ignoring EPIPE during close_stdout.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
36 situation worth signaling to the user. See the documentation of the |
37b949ffd096
Add an option for ignoring EPIPE during close_stdout.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
37 close_stdout_set_ignore_EPIPE function for details. |
37b949ffd096
Add an option for ignoring EPIPE during close_stdout.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
38 |
7035 | 39 If a program writes *anything* to STREAM, that program should close |
40 STREAM and make sure that it succeeds before exiting. Otherwise, | |
41 suppose that you go to the extreme of checking the return status | |
42 of every function that does an explicit write to STREAM. The last | |
43 printf can succeed in writing to the internal stream buffer, and yet | |
44 the fclose(STREAM) could still fail (due e.g., to a disk full error) | |
45 when it tries to write out that buffered data. Thus, you would be | |
46 left with an incomplete output file and the offending program would | |
47 exit successfully. Even calling fflush is not always sufficient, | |
48 since some file systems (NFS and CODA) buffer written/flushed data | |
49 until an actual close call. | |
50 | |
51 Besides, it's wasteful to check the return value from every call | |
52 that writes to STREAM -- just let the internal stream state record | |
53 the failure. That's what the ferror test is checking below. */ | |
54 | |
55 int | |
56 close_stream (FILE *stream) | |
57 { | |
13212
d724e1ff61cd
close-stream: declare local scalars to be "const"
James Youngman <jay@gnu.org>
parents:
12559
diff
changeset
|
58 const bool some_pending = (__fpending (stream) != 0); |
d724e1ff61cd
close-stream: declare local scalars to be "const"
James Youngman <jay@gnu.org>
parents:
12559
diff
changeset
|
59 const bool prev_fail = (ferror (stream) != 0); |
d724e1ff61cd
close-stream: declare local scalars to be "const"
James Youngman <jay@gnu.org>
parents:
12559
diff
changeset
|
60 const bool fclose_fail = (fclose (stream) != 0); |
7035 | 61 |
62 /* Return an error indication if there was a previous failure or if | |
63 fclose failed, with one exception: ignore an fclose failure if | |
64 there was no previous error, no data remains to be flushed, and | |
65 fclose failed with EBADF. That can happen when a program like cp | |
16235
18a38c9615f0
In commentary, do not use ` to quote.
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
66 is invoked like this 'cp a b >&-' (i.e., with standard output |
7035 | 67 closed) and doesn't generate any output (hence no previous error |
68 and nothing to be flushed). */ | |
69 | |
70 if (prev_fail || (fclose_fail && (some_pending || errno != EBADF))) | |
71 { | |
72 if (! fclose_fail) | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
10595
diff
changeset
|
73 errno = 0; |
7035 | 74 return EOF; |
75 } | |
76 | |
77 return 0; | |
78 } |