annotate lib/fclose.c @ 10690:01f3623813da

Split winsock.c into many smaller files. * lib/close.c: Add _gl_close_fd_maybe_socket from winsock.c. * lib/accept.c: New file, based on winsock.c. * lib/bind.c: New file, based on winsock.c. * lib/connect.c: New file, based on winsock.c. * lib/getpeername.c: New file, based on winsock.c. * lib/getsockname.c: New file, based on winsock.c. * lib/getsockopt.c: New file, based on winsock.c. * lib/ioctl.c: New file, based on winsock.c. * lib/listen.c: New file, based on winsock.c. * lib/recv.c: New file, based on winsock.c. * lib/recvfrom.c: New file, based on winsock.c. * lib/send.c: New file, based on winsock.c. * lib/sendto.c: New file, based on winsock.c. * lib/setsockopt.c: New file, based on winsock.c. * lib/shutdown.c: New file, based on winsock.c. * lib/socket.c: New file, based on winsock.c. * lib/w32sock.h: New file, based on winsock.c. * lib/winsock.c: Remove file. * modules/accept: Likewise. * modules/bind: Likewise. * modules/connect: Likewise. * modules/getpeername: Likewise. * modules/getsockname: Likewise. * modules/getsockopt: Likewise. * modules/ioctl: Likewise. * modules/listen: Likewise. * modules/recv: Likewise. * modules/recvfrom: Likewise. * modules/send: Likewise. * modules/sendto: Likewise. * modules/setsockopt: Likewise. * modules/shutdown: Likewise. * modules/socket: Use socket.c instead of winsock.c. * modules/sys_socket: Remove (unneeded?) dependency on winsock.c. * doc/posix-functions/accept.texi: Doc fix. * doc/posix-functions/bind.texi: Doc fix. * doc/posix-functions/close.texi: Doc fix. * doc/posix-functions/connect.texi: Doc fix. * doc/posix-functions/getpeername.texi: Doc fix. * doc/posix-functions/getsockname.texi: Doc fix. * doc/posix-functions/getsockopt.texi: Doc fix. * doc/posix-functions/ioctl.texi: Doc fix. * doc/posix-functions/listen.texi: Doc fix. * doc/posix-functions/recv.texi: Doc fix. * doc/posix-functions/recvfrom.texi: Doc fix. * doc/posix-functions/send.texi: Doc fix. * doc/posix-functions/sendto.texi: Doc fix. * doc/posix-functions/setsockopt.texi: Doc fix. * doc/posix-functions/shutdown.texi: Doc fix. * doc/posix-functions/socket.texi: Doc fix.
author Simon Josefsson <simon@josefsson.org>
date Tue, 21 Oct 2008 12:17:19 +0200
parents cce8e54214d5
children b5e42ef33b49
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10623
cce8e54214d5 * lib/fclose.c: Fix typo in comment: s/close/fclose/.
Jim Meyering <meyering@redhat.com>
parents: 10622
diff changeset
1 /* fclose replacement.
10622
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2 Copyright (C) 2008 Free Software Foundation, Inc.
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 #include <config.h>
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 /* Specification. */
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 #include <stdio.h>
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 #include <errno.h>
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <unistd.h>
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 /* Override fclose() to call the overridden close(). */
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 int
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 rpl_fclose (FILE *fp)
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 #undef fclose
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 {
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 int saved_errno = 0;
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 if (fflush (fp))
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 saved_errno = errno;
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 if (close (fileno (fp)) < 0 && saved_errno == 0)
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 saved_errno = errno;
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 fclose (fp); /* will fail with errno = EBADF */
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 if (saved_errno != 0)
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 {
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 errno = saved_errno;
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 return EOF;
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 }
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 return 0;
ac6f431cc95d New module 'fclose'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 }