comparison lib/ftello.c @ 8872:dfee3b4fd46c

Fix lseek on mingw. * modules/lseek: New module. * m4/lseek.m4: New file. * lib/lseek.c: New file. * modules/lseek-tests: New file. * tests/test-lseek.c: New file. * tests/test-lseek.sh: New file. * MODULES.html.sh: Document lseek module. * modules/fflush (Depends-on): Add lseek, fseeko. * modules/fseeko (Depends-on): Likewise. * modules/ftello (Depends-on): Likewise. * m4/fseeko.m4 (gl_FUNC_FSEEKO): Replace fseek[o] if lseek is broken. * m4/ftello.m4 (gl_FUNC_FTELLO): Replace ftell[o] if lseek is broken. * m4/fflush.m4 (gl_REPLACE_FFLUSH): Trigger fseeko module. * lib/fseeko.c (rpl_fseeko): Quit early on non-seekable files. * lib/ftello.c (rpl_ftello): Likewise. * tests/test-fseeko.c (main): Test this. * tests/test-fseeko.sh: Likewise. * tests/test-ftello.c (main): Likewise. * tests/test-ftello.sh: Likewise. * lib/stdio_.h (fseek, ftell): Simplify, since missing fseeko now implies replacing fseek. * modules/stdio (Makefile.am): No longer need HAVE_FSEEKO, HAVE_FTELLO. * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Add lseek info. * modules/unistd (Makefile.am): Likewise. * lib/unistd_.h (lseek): Declare a replacement. * doc/functions/lseek.texi (lseek): Document this fix. * doc/functions/fseek.texi (fseek): Likewise. * doc/functions/ftell.texi (ftell): Likewise.
author Eric Blake <ebb9@byu.net>
date Thu, 24 May 2007 16:59:20 +0000
parents 90e71310a07f
children bbbbbf4cd1c5
comparison
equal deleted inserted replaced
8871:8015a071250c 8872:dfee3b4fd46c
18 #include <config.h> 18 #include <config.h>
19 19
20 /* Specification. */ 20 /* Specification. */
21 #include <stdio.h> 21 #include <stdio.h>
22 22
23 /* Get lseek. */
24 #include <unistd.h>
25
23 #undef ftello 26 #undef ftello
24 #if !HAVE_FTELLO 27 #if !HAVE_FTELLO
28 # undef ftell
25 # define ftello ftell 29 # define ftello ftell
26 #endif 30 #endif
27 31
28 off_t 32 off_t
29 rpl_ftello (FILE *fp) 33 rpl_ftello (FILE *fp)
30 { 34 {
35 #if LSEEK_PIPE_BROKEN
36 /* mingw gives bogus answers rather than failure on non-seekable files. */
37 if (lseek (fileno (fp), 0, SEEK_CUR) == -1)
38 return -1;
39 #endif
40
31 #if defined __SL64 && defined __SCLE /* Cygwin */ 41 #if defined __SL64 && defined __SCLE /* Cygwin */
32 if ((fp->_flags & __SL64) == 0) 42 if ((fp->_flags & __SL64) == 0)
33 { 43 {
34 /* Cygwin 1.5.0 through 1.5.24 failed to open stdin in 64-bit 44 /* Cygwin 1.5.0 through 1.5.24 failed to open stdin in 64-bit
35 mode; but has an ftello that requires 64-bit mode. */ 45 mode; but has an ftello that requires 64-bit mode. */