Mercurial > hg > octave-shane > gnulib-hg
annotate lib/fflush.c @ 9982:a4502ab3c8d6
Oops, fix mistake in third-to-last commit.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sat, 26 Apr 2008 19:42:00 +0200 |
parents | e3d6988a9347 |
children | 95eb3a6eb21d |
rev | line source |
---|---|
8657
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
1 /* fflush.c -- allow flushing input streams |
9772
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
2 Copyright (C) 2007-2008 Free Software Foundation, Inc. |
8657
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
3 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9134
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
8657
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
5 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:
9134
diff
changeset
|
6 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:
9134
diff
changeset
|
7 (at your option) any later version. |
8657
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
8 |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
12 GNU General Public License for more details. |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
13 |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
14 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:
9134
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
8657
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
16 |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
17 /* Written by Eric Blake. */ |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
18 |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
19 #include <config.h> |
8705
caaaf4823aec
* lib/fflush.c: Fix missing include.
Eric Blake <ebb9@byu.net>
parents:
8700
diff
changeset
|
20 |
caaaf4823aec
* lib/fflush.c: Fix missing include.
Eric Blake <ebb9@byu.net>
parents:
8700
diff
changeset
|
21 /* Specification. */ |
caaaf4823aec
* lib/fflush.c: Fix missing include.
Eric Blake <ebb9@byu.net>
parents:
8700
diff
changeset
|
22 #include <stdio.h> |
caaaf4823aec
* lib/fflush.c: Fix missing include.
Eric Blake <ebb9@byu.net>
parents:
8700
diff
changeset
|
23 |
8657
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
24 #include <errno.h> |
8705
caaaf4823aec
* lib/fflush.c: Fix missing include.
Eric Blake <ebb9@byu.net>
parents:
8700
diff
changeset
|
25 #include <unistd.h> |
8657
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
26 |
8721 | 27 #include "freading.h" |
8700 | 28 #include "fpurge.h" |
8657
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
29 |
9980
2c1ba629f5d5
New private include file lib/stdio-impl.h.
Bruno Haible <bruno@clisp.org>
parents:
9976
diff
changeset
|
30 #include "stdio-impl.h" |
2c1ba629f5d5
New private include file lib/stdio-impl.h.
Bruno Haible <bruno@clisp.org>
parents:
9976
diff
changeset
|
31 |
8657
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
32 #undef fflush |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
33 |
9976
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
34 static inline void |
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
35 clear_ungetc_buffer (FILE *fp) |
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
36 { |
9981
e3d6988a9347
Add tentative support for DragonFly BSD.
Bruno Haible <bruno@clisp.org>
parents:
9980
diff
changeset
|
37 #if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */ |
9976
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
38 if (HASUB (fp)) |
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
39 { |
9981
e3d6988a9347
Add tentative support for DragonFly BSD.
Bruno Haible <bruno@clisp.org>
parents:
9980
diff
changeset
|
40 fp_->_p += fp_->_r; |
e3d6988a9347
Add tentative support for DragonFly BSD.
Bruno Haible <bruno@clisp.org>
parents:
9980
diff
changeset
|
41 fp_->_r = 0; |
9976
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
42 } |
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
43 #endif |
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
44 } |
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
45 |
9981
e3d6988a9347
Add tentative support for DragonFly BSD.
Bruno Haible <bruno@clisp.org>
parents:
9980
diff
changeset
|
46 #if (defined __sferror || defined __DragonFly__) && defined __SNPT /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */ |
9976
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
47 |
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
48 static inline int |
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
49 disable_seek_optimization (FILE *fp) |
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
50 { |
9981
e3d6988a9347
Add tentative support for DragonFly BSD.
Bruno Haible <bruno@clisp.org>
parents:
9980
diff
changeset
|
51 int saved_flags = fp_->_flags & (__SOPT | __SNPT); |
e3d6988a9347
Add tentative support for DragonFly BSD.
Bruno Haible <bruno@clisp.org>
parents:
9980
diff
changeset
|
52 fp_->_flags = (fp_->_flags & ~__SOPT) | __SNPT; |
9976
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
53 return saved_flags; |
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
54 } |
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
55 |
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
56 static inline void |
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
57 restore_seek_optimization (FILE *fp, int saved_flags) |
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
58 { |
9981
e3d6988a9347
Add tentative support for DragonFly BSD.
Bruno Haible <bruno@clisp.org>
parents:
9980
diff
changeset
|
59 fp_->_flags = (fp_->_flags & ~(__SOPT | __SNPT)) | saved_flags; |
9976
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
60 } |
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
61 |
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
62 #endif |
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
63 |
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
64 static inline void |
9982
a4502ab3c8d6
Oops, fix mistake in third-to-last commit.
Bruno Haible <bruno@clisp.org>
parents:
9981
diff
changeset
|
65 update_fpos_cache (FILE *fp, off_t pos) |
9976
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
66 { |
9981
e3d6988a9347
Add tentative support for DragonFly BSD.
Bruno Haible <bruno@clisp.org>
parents:
9980
diff
changeset
|
67 #if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */ |
e3d6988a9347
Add tentative support for DragonFly BSD.
Bruno Haible <bruno@clisp.org>
parents:
9980
diff
changeset
|
68 fp_->_offset = pos; |
e3d6988a9347
Add tentative support for DragonFly BSD.
Bruno Haible <bruno@clisp.org>
parents:
9980
diff
changeset
|
69 fp_->_flags |= __SOFF; |
9976
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
70 #endif |
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
71 } |
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
72 |
8657
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
73 /* Flush all pending data on STREAM according to POSIX rules. Both |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
74 output and seekable input streams are supported. */ |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
75 int |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
76 rpl_fflush (FILE *stream) |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
77 { |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
78 int result; |
8700 | 79 off_t pos; |
8657
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
80 |
8725 | 81 /* When stream is NULL, POSIX and C99 only require flushing of "output |
82 streams and update streams in which the most recent operation was not | |
83 input", and all implementations do this. | |
84 | |
85 When stream is "an output stream or an update stream in which the most | |
86 recent operation was not input", POSIX and C99 requires that fflush | |
87 writes out any buffered data, and all implementations do this. | |
88 | |
8731
2e1ecfc17762
* lib/freading.h: Improve comments.
Eric Blake <ebb9@byu.net>
parents:
8725
diff
changeset
|
89 When stream is, however, an input stream or an update stream in |
2e1ecfc17762
* lib/freading.h: Improve comments.
Eric Blake <ebb9@byu.net>
parents:
8725
diff
changeset
|
90 which the most recent operation was input, C99 specifies nothing, |
2e1ecfc17762
* lib/freading.h: Improve comments.
Eric Blake <ebb9@byu.net>
parents:
8725
diff
changeset
|
91 and POSIX only specifies behavior if the stream is seekable. |
2e1ecfc17762
* lib/freading.h: Improve comments.
Eric Blake <ebb9@byu.net>
parents:
8725
diff
changeset
|
92 mingw, in particular, drops the input buffer, leaving the file |
2e1ecfc17762
* lib/freading.h: Improve comments.
Eric Blake <ebb9@byu.net>
parents:
8725
diff
changeset
|
93 descriptor positioned at the end of the input buffer. I.e. ftell |
2e1ecfc17762
* lib/freading.h: Improve comments.
Eric Blake <ebb9@byu.net>
parents:
8725
diff
changeset
|
94 (stream) is lost. We don't want to call the implementation's |
2e1ecfc17762
* lib/freading.h: Improve comments.
Eric Blake <ebb9@byu.net>
parents:
8725
diff
changeset
|
95 fflush in this case. |
8725 | 96 |
97 We test ! freading (stream) here, rather than fwriting (stream), because | |
98 what we need to know is whether the stream holds a "read buffer", and on | |
99 mingw this is indicated by _IOREAD, regardless of _IOWRT. */ | |
100 if (stream == NULL || ! freading (stream)) | |
8721 | 101 return fflush (stream); |
8657
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
102 |
9772
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
103 /* Clear the ungetc buffer. |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
104 |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
105 This is needed before fetching the file-position indicator, because |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
106 1) The file position indicator is incremented by fgetc() and decremented |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
107 by ungetc(): |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
108 <http://www.opengroup.org/susv3/functions/fgetc.html> |
9776
ca038bcad2a5
Fix comments in last commit.
Bruno Haible <bruno@clisp.org>
parents:
9772
diff
changeset
|
109 "... the fgetc() function shall ... advance the associated file |
ca038bcad2a5
Fix comments in last commit.
Bruno Haible <bruno@clisp.org>
parents:
9772
diff
changeset
|
110 position indicator for the stream ..." |
ca038bcad2a5
Fix comments in last commit.
Bruno Haible <bruno@clisp.org>
parents:
9772
diff
changeset
|
111 <http://www.opengroup.org/susv3/functions/ungetc.html> |
9772
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
112 "The file-position indicator is decremented by each successful |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
113 call to ungetc()..." |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
114 2) <http://www.opengroup.org/susv3/functions/ungetc.html> says: |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
115 "The value of the file-position indicator for the stream after |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
116 reading or discarding all pushed-back bytes shall be the same |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
117 as it was before the bytes were pushed back." |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
118 3) Here we are discarding all pushed-back bytes. |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
119 |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
120 Unfortunately it is impossible to implement this on platforms with |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
121 _IOERR, because an ungetc() on this platform prepends the pushed-back |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
122 bytes to the buffer without an indication of the limit between the |
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
123 pushed-back bytes and the read-ahead bytes. */ |
9976
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
124 clear_ungetc_buffer (stream); |
9772
cfd020716bf2
Make fflush after ungetc work on BSD platforms.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
125 |
8700 | 126 /* POSIX does not specify fflush behavior for non-seekable input |
8731
2e1ecfc17762
* lib/freading.h: Improve comments.
Eric Blake <ebb9@byu.net>
parents:
8725
diff
changeset
|
127 streams. Some implementations purge unread data, some return |
2e1ecfc17762
* lib/freading.h: Improve comments.
Eric Blake <ebb9@byu.net>
parents:
8725
diff
changeset
|
128 EBADF, some do nothing. */ |
8700 | 129 pos = ftello (stream); |
130 if (pos == -1) | |
8657
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
131 { |
8700 | 132 errno = EBADF; |
8657
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
133 return EOF; |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
134 } |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
135 |
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
136 /* To get here, we must be flushing a seekable input stream, so the |
8700 | 137 semantics of fpurge are now appropriate to clear the buffer. To |
138 avoid losing data, the lseek is also necessary. */ | |
8657
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
139 result = fpurge (stream); |
8717
3afefd650c3a
On BSD implementations, when we call lseek(), we must also update or disable
Bruno Haible <bruno@clisp.org>
parents:
8705
diff
changeset
|
140 if (result != 0) |
3afefd650c3a
On BSD implementations, when we call lseek(), we must also update or disable
Bruno Haible <bruno@clisp.org>
parents:
8705
diff
changeset
|
141 return result; |
8725 | 142 |
9981
e3d6988a9347
Add tentative support for DragonFly BSD.
Bruno Haible <bruno@clisp.org>
parents:
9980
diff
changeset
|
143 #if (defined __sferror || defined __DragonFly__) && defined __SNPT /* FreeBSD, NetBSD, OpenBSD, DragonFly, MacOS X, Cygwin */ |
9134
38df3bd8e54e
Use a slightly cleaner hack on BSD systems.
Bruno Haible <bruno@clisp.org>
parents:
8731
diff
changeset
|
144 |
38df3bd8e54e
Use a slightly cleaner hack on BSD systems.
Bruno Haible <bruno@clisp.org>
parents:
8731
diff
changeset
|
145 { |
38df3bd8e54e
Use a slightly cleaner hack on BSD systems.
Bruno Haible <bruno@clisp.org>
parents:
8731
diff
changeset
|
146 /* Disable seek optimization for the next fseeko call. This tells the |
38df3bd8e54e
Use a slightly cleaner hack on BSD systems.
Bruno Haible <bruno@clisp.org>
parents:
8731
diff
changeset
|
147 following fseeko call to seek to the desired position directly, rather |
38df3bd8e54e
Use a slightly cleaner hack on BSD systems.
Bruno Haible <bruno@clisp.org>
parents:
8731
diff
changeset
|
148 than to seek to a block-aligned boundary. */ |
9976
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
149 int saved_flags = disable_seek_optimization (stream); |
9134
38df3bd8e54e
Use a slightly cleaner hack on BSD systems.
Bruno Haible <bruno@clisp.org>
parents:
8731
diff
changeset
|
150 |
38df3bd8e54e
Use a slightly cleaner hack on BSD systems.
Bruno Haible <bruno@clisp.org>
parents:
8731
diff
changeset
|
151 result = fseeko (stream, pos, SEEK_SET); |
38df3bd8e54e
Use a slightly cleaner hack on BSD systems.
Bruno Haible <bruno@clisp.org>
parents:
8731
diff
changeset
|
152 |
9976
621cb9082339
Put system dependent routines into inline functions.
Bruno Haible <bruno@clisp.org>
parents:
9776
diff
changeset
|
153 restore_seek_optimization (stream, saved_flags); |
9134
38df3bd8e54e
Use a slightly cleaner hack on BSD systems.
Bruno Haible <bruno@clisp.org>
parents:
8731
diff
changeset
|
154 } |
38df3bd8e54e
Use a slightly cleaner hack on BSD systems.
Bruno Haible <bruno@clisp.org>
parents:
8731
diff
changeset
|
155 return result; |
38df3bd8e54e
Use a slightly cleaner hack on BSD systems.
Bruno Haible <bruno@clisp.org>
parents:
8731
diff
changeset
|
156 |
38df3bd8e54e
Use a slightly cleaner hack on BSD systems.
Bruno Haible <bruno@clisp.org>
parents:
8731
diff
changeset
|
157 #else |
38df3bd8e54e
Use a slightly cleaner hack on BSD systems.
Bruno Haible <bruno@clisp.org>
parents:
8731
diff
changeset
|
158 |
8717
3afefd650c3a
On BSD implementations, when we call lseek(), we must also update or disable
Bruno Haible <bruno@clisp.org>
parents:
8705
diff
changeset
|
159 pos = lseek (fileno (stream), pos, SEEK_SET); |
3afefd650c3a
On BSD implementations, when we call lseek(), we must also update or disable
Bruno Haible <bruno@clisp.org>
parents:
8705
diff
changeset
|
160 if (pos == -1) |
8700 | 161 return EOF; |
8725 | 162 /* After a successful lseek, update the file descriptor's position cache |
163 in the stream. */ | |
9982
a4502ab3c8d6
Oops, fix mistake in third-to-last commit.
Bruno Haible <bruno@clisp.org>
parents:
9981
diff
changeset
|
164 update_fpos_cache (stream, pos); |
8725 | 165 |
8717
3afefd650c3a
On BSD implementations, when we call lseek(), we must also update or disable
Bruno Haible <bruno@clisp.org>
parents:
8705
diff
changeset
|
166 return 0; |
9134
38df3bd8e54e
Use a slightly cleaner hack on BSD systems.
Bruno Haible <bruno@clisp.org>
parents:
8731
diff
changeset
|
167 |
38df3bd8e54e
Use a slightly cleaner hack on BSD systems.
Bruno Haible <bruno@clisp.org>
parents:
8731
diff
changeset
|
168 #endif |
8657
05f21166eb81
* lib/stdio_.h [REPLACE_FFLUSH]: Declare rpl_fflush.
Eric Blake <ebb9@byu.net>
parents:
diff
changeset
|
169 } |