Mercurial > hg > octave-shane > gnulib-hg
annotate lib/fwriteerror.h @ 15727:144db791c6fa
Ensure EBADF returns for socket functions on mingw.
* lib/accept.c (rpl_accept): Fail with error EBADF if the file
descriptor is invalid.
* lib/bind.c (rpl_bind): Likewise.
* lib/connect.c (rpl_connect): Likewise.
* lib/getpeername.c (rpl_getpeername): Likewise.
* lib/getsockname.c (rpl_getsockname): Likewise.
* lib/getsockopt.c (rpl_getsockopt): Likewise.
* lib/listen.c (rpl_listen): Likewise.
* lib/recv.c (rpl_recv): Likewise.
* lib/recvfrom.c (rpl_recvfrom): Likewise.
* lib/send.c (rpl_send): Likewise.
* lib/sendto.c (rpl_sendto): Likewise.
* lib/setsockopt.c (rpl_setsockopt): Likewise.
* lib/shutdown.c (rpl_shutdown): Likewise.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Wed, 21 Sep 2011 00:20:59 +0200 |
parents | 97fc9a21a8fb |
children | 8250f2777afc |
rev | line source |
---|---|
4709 | 1 /* Detect write error on a stream. |
14079
97fc9a21a8fb
maint: update almost all copyright ranges to include 2011
Jim Meyering <meyering@redhat.com>
parents:
12559
diff
changeset
|
2 Copyright (C) 2003, 2005-2006, 2009-2011 Free Software Foundation, Inc. |
4709 | 3 Written by Bruno Haible <bruno@clisp.org>, 2003. |
4 | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7602
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify |
4709 | 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:
7602
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:
7602
diff
changeset
|
8 (at your option) any later version. |
4709 | 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 | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7602
diff
changeset
|
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
4709 | 17 |
18 /* There are two approaches for detecting a write error on a stream opened | |
19 for writing: | |
20 | |
21 (a) Test the return value of every fwrite() or fprintf() call, and react | |
22 immediately. | |
23 (b) Just before fclose(), test the error indicator in the stream and | |
5581
c8676e66b5da
The fwriteerror() function now needs to fclose() the stream,
Bruno Haible <bruno@clisp.org>
parents:
4709
diff
changeset
|
24 the return value of the final fclose() call. |
4709 | 25 |
26 The benefit of (a) is that non file related errors (such that ENOMEM during | |
27 fprintf) and temporary error conditions can be diagnosed accurately. | |
28 | |
29 A theoretical benefit of (a) is also that, on POSIX systems, in the case of | |
30 an ENOSPC error, errno is set and can be used by error() to provide a more | |
31 accurate error message. But in practice, this benefit is not big because | |
32 users can easily figure out by themselves why a file cannot be written to, | |
33 and furthermore the function fwriteerror() can provide errno as well. | |
34 | |
35 The big drawback of (a) is extensive error checking code: Every function | |
36 which does stream output must return an error indicator. | |
37 | |
38 This file provides support for (b). */ | |
39 | |
40 #include <stdio.h> | |
41 | |
7602
adf3720ff325
Avoid name mangling in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
7388
diff
changeset
|
42 #ifdef __cplusplus |
adf3720ff325
Avoid name mangling in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
7388
diff
changeset
|
43 extern "C" { |
adf3720ff325
Avoid name mangling in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
7388
diff
changeset
|
44 #endif |
adf3720ff325
Avoid name mangling in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
7388
diff
changeset
|
45 |
5581
c8676e66b5da
The fwriteerror() function now needs to fclose() the stream,
Bruno Haible <bruno@clisp.org>
parents:
4709
diff
changeset
|
46 /* Write out the not yet written buffered contents of the stream FP, close |
c8676e66b5da
The fwriteerror() function now needs to fclose() the stream,
Bruno Haible <bruno@clisp.org>
parents:
4709
diff
changeset
|
47 the stream FP, and test whether some error occurred on the stream FP. |
c8676e66b5da
The fwriteerror() function now needs to fclose() the stream,
Bruno Haible <bruno@clisp.org>
parents:
4709
diff
changeset
|
48 FP must be a stream opened for writing. |
c8676e66b5da
The fwriteerror() function now needs to fclose() the stream,
Bruno Haible <bruno@clisp.org>
parents:
4709
diff
changeset
|
49 Return 0 if no error occurred and fclose (fp) succeeded. |
4709 | 50 Return -1 and set errno if there was an error. The errno value will be 0 |
51 if the cause of the error cannot be determined. | |
5581
c8676e66b5da
The fwriteerror() function now needs to fclose() the stream,
Bruno Haible <bruno@clisp.org>
parents:
4709
diff
changeset
|
52 For any given stream FP other than stdout, fwriteerror (FP) may only be |
c8676e66b5da
The fwriteerror() function now needs to fclose() the stream,
Bruno Haible <bruno@clisp.org>
parents:
4709
diff
changeset
|
53 called once. */ |
4709 | 54 extern int fwriteerror (FILE *fp); |
7388
de85bc61c2dc
New function fwriteerror_no_ebadf.
Bruno Haible <bruno@clisp.org>
parents:
5848
diff
changeset
|
55 |
de85bc61c2dc
New function fwriteerror_no_ebadf.
Bruno Haible <bruno@clisp.org>
parents:
5848
diff
changeset
|
56 /* Likewise, but don't consider it an error if FP has an invalid file |
de85bc61c2dc
New function fwriteerror_no_ebadf.
Bruno Haible <bruno@clisp.org>
parents:
5848
diff
changeset
|
57 descriptor and no output was done to FP. */ |
de85bc61c2dc
New function fwriteerror_no_ebadf.
Bruno Haible <bruno@clisp.org>
parents:
5848
diff
changeset
|
58 extern int fwriteerror_no_ebadf (FILE *fp); |
7602
adf3720ff325
Avoid name mangling in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
7388
diff
changeset
|
59 |
adf3720ff325
Avoid name mangling in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
7388
diff
changeset
|
60 #ifdef __cplusplus |
adf3720ff325
Avoid name mangling in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
7388
diff
changeset
|
61 } |
adf3720ff325
Avoid name mangling in C++ mode.
Bruno Haible <bruno@clisp.org>
parents:
7388
diff
changeset
|
62 #endif |