summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2010-05-01 20:32:26 +0200
committerBruno Haible <bruno@clisp.org>2010-05-01 20:32:26 +0200
commit55ca839ef4bfcf78114ef277c618385b521a5f5c (patch)
tree50a79546f602ea28320600e5a3c1e40ea9e8efb7 /lib
parent2d0c228f339519d2353cd1e4847aeb185f329d2b (diff)
downloadgnulib-55ca839ef4bfcf78114ef277c618385b521a5f5c.tar.gz
ftell, ftello: Work around Solaris bug.
Diffstat (limited to 'lib')
-rw-r--r--lib/ftello.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/ftello.c b/lib/ftello.c
index a15e26bc15..098e36ae58 100644
--- a/lib/ftello.c
+++ b/lib/ftello.c
@@ -22,6 +22,8 @@
/* Get lseek. */
#include <unistd.h>
+#include "stdio-impl.h"
+
off_t
ftello (FILE *fp)
#undef ftello
@@ -36,6 +38,28 @@ ftello (FILE *fp)
return -1;
#endif
+#if FTELLO_BROKEN_AFTER_SWITCHING_FROM_READ_TO_WRITE /* Solaris */
+ /* The Solaris stdio leaves the _IOREAD flag set after reading from a file
+ reaches EOF and the program then starts writing to the file. ftello
+ gets confused by this. */
+ if (fp_->_flag & _IOWRT)
+ {
+ off_t pos;
+
+ /* Call ftello nevertheless, for the side effects that it does on fp. */
+ ftello (fp);
+
+ /* Compute the file position ourselves. */
+ pos = llseek (fileno (fp), (off_t) 0, SEEK_CUR);
+ if (pos >= 0)
+ {
+ if ((fp_->_flag & _IONBF) == 0 && fp_->_base != NULL)
+ pos += fp_->_ptr - fp_->_base;
+ }
+ return pos;
+ }
+#endif
+
#if defined __SL64 && defined __SCLE /* Cygwin */
if ((fp->_flags & __SL64) == 0)
{