annotate lib/ftello.c @ 8868:90e71310a07f

Fix fseeko/ftello on cygwin 1.5.24. * doc/functions/fseeko.texi (fseeko): Document the fix. * doc/functions/ftello.texi (ftello): Document the fix. * doc/functions/stdin.texi (stdin): Document the cygwin bug. * doc/functions/stdout.text (stdout): New file. * doc/functions/stderr.text (stderr): New file. * doc/gnulib.texi (Function Substitutes): Use new files. * tests/test-fseeko.c (main): Check for broken fseeko on cygwin prior to 1.7.0. * tests/test-ftello.c (main): Likewise for ftello. * tests/test-fseeko.sh: New file. * tests/test-ftello.sh: New file. * modules/fseeko-tests (Makefile.am): Ensure test-fseeko is run with seekable stdin. * modules/ftello-tests (Makefile.am): Likewise for test-ftello. * m4/fseeko.m4 (gl_FUNC_FSEEKO): Detect the cygwin bug. (gl_REPLACE_FSEEKO): New macro. * m4/ftello.m4 (gl_FUNC_FTELLO, gl_REPLACE_FTELLO): Likewise. * modules/fseeko (Files): Distribute fseeko.c. * modules/ftello (Files): Distribute ftello.c. * lib/fseeko.c (rpl_fseeko) [__CYGWIN__]: Convert stdin to 64-bit mode. * lib/ftello.c (rpl_ftello): New file. * m4/stdio_h.m4 (gl_STDIO_H_DEFAULTS): Allow replacement of fseeko, ftello. (gl_STDIN_LARGE_OFFSET): New macro. * modules/stdio (Makefile.am): Perform the replacement. * lib/stdio_.h (rpl_fseeko, rpl_ftello): Define when needed.
author Eric Blake <ebb9@byu.net>
date Thu, 24 May 2007 03:53:37 +0000
parents
children dfee3b4fd46c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8868
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
1 /* An ftello() function that works around platform bugs.
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
2 Copyright (C) 2007 Free Software Foundation, Inc.
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
3
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
4 This program is free software; you can redistribute it and/or modify
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
6 the Free Software Foundation; either version 2, or (at your option)
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
7 any later version.
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
8
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
12 GNU General Public License for more details.
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
13
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License along
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
15 with this program; if not, write to the Free Software Foundation,
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
17
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
18 #include <config.h>
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
19
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
20 /* Specification. */
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
21 #include <stdio.h>
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
22
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
23 #undef ftello
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
24 #if !HAVE_FTELLO
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
25 # define ftello ftell
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
26 #endif
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
27
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
28 off_t
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
29 rpl_ftello (FILE *fp)
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
30 {
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
31 #if defined __SL64 && defined __SCLE /* Cygwin */
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
32 if ((fp->_flags & __SL64) == 0)
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
33 {
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
34 /* Cygwin 1.5.0 through 1.5.24 failed to open stdin in 64-bit
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
35 mode; but has an ftello that requires 64-bit mode. */
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
36 FILE *tmp = fopen ("/dev/null", "r");
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
37 if (!tmp)
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
38 return -1;
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
39 fp->_flags |= __SL64;
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
40 fp->_seek64 = tmp->_seek64;
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
41 fclose (tmp);
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
42 }
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
43 #endif
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
44 return ftello (fp);
90e71310a07f Fix fseeko/ftello on cygwin 1.5.24.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
45 }