Mercurial > hg > octave-kai > gnulib-hg
annotate lib/freadptr.c @ 17160:72f4bab621be
fts: introduce FTS_VERBATIM
This gives clients the option to disable stripping of trailing slashes
from input path names during fts_open initialization.
The recent change v0.0-7611-g3a9002d that made fts_open strip trailing
slashes from input path names had a negative impact on findutils that
relies on the old fts_open behavior to implement POSIX requirement that
each path operand of the find utility shall be evaluated unaltered as it
was provided, including all trailing slash characters.
* lib/fts_.h (FTS_VERBATIM): New bit flag.
(FTS_OPTIONMASK, FTS_NAMEONLY, FTS_STOP): Adjust.
* lib/fts.c (fts_open): Honor it.
author | Dmitry V. Levin <ldv@altlinux.org> |
---|---|
date | Sun, 18 Nov 2012 04:40:18 +0400 |
parents | 498a2211d839 |
children | e542fd46ad6f |
rev | line source |
---|---|
9727 | 1 /* Retrieve information about a FILE stream. |
16201
8250f2777afc
maint: update all copyright year number ranges
Jim Meyering <meyering@redhat.com>
parents:
15485
diff
changeset
|
2 Copyright (C) 2007-2012 Free Software Foundation, Inc. |
9727 | 3 |
4 This program is free software: you can redistribute it and/or modify | |
5 it under the terms of the GNU General Public License as published by | |
6 the Free Software Foundation; either version 3 of the License, or | |
7 (at your option) any later version. | |
8 | |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
16 | |
17 #include <config.h> | |
18 | |
19 /* Specification. */ | |
9779
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
20 #include "freadptr.h" |
9727 | 21 |
9881
e21211210418
Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents:
9876
diff
changeset
|
22 #include <stdlib.h> |
e21211210418
Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents:
9876
diff
changeset
|
23 |
9980
2c1ba629f5d5
New private include file lib/stdio-impl.h.
Bruno Haible <bruno@clisp.org>
parents:
9928
diff
changeset
|
24 #include "stdio-impl.h" |
2c1ba629f5d5
New private include file lib/stdio-impl.h.
Bruno Haible <bruno@clisp.org>
parents:
9928
diff
changeset
|
25 |
9727 | 26 const char * |
9779
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
27 freadptr (FILE *fp, size_t *sizep) |
9727 | 28 { |
9779
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
29 size_t size; |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
30 |
9727 | 31 /* Keep this code in sync with freadahead! */ |
10780 | 32 #if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */ |
9779
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
33 if (fp->_IO_write_ptr > fp->_IO_write_base) |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
34 return NULL; |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
35 size = fp->_IO_read_end - fp->_IO_read_ptr; |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
36 if (size == 0) |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
37 return NULL; |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
38 *sizep = size; |
9727 | 39 return (const char *) fp->_IO_read_ptr; |
16935
498a2211d839
Write "Mac OS X" instead of "MacOS X".
Bruno Haible <bruno@clisp.org>
parents:
16344
diff
changeset
|
40 #elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */ |
9981
e3d6988a9347
Add tentative support for DragonFly BSD.
Bruno Haible <bruno@clisp.org>
parents:
9980
diff
changeset
|
41 if ((fp_->_flags & __SWR) != 0 || fp_->_r < 0) |
9779
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
42 return NULL; |
9981
e3d6988a9347
Add tentative support for DragonFly BSD.
Bruno Haible <bruno@clisp.org>
parents:
9980
diff
changeset
|
43 size = fp_->_r; |
9779
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
44 if (size == 0) |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
45 return NULL; |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
46 *sizep = size; |
9981
e3d6988a9347
Add tentative support for DragonFly BSD.
Bruno Haible <bruno@clisp.org>
parents:
9980
diff
changeset
|
47 return (const char *) fp_->_p; |
9881
e21211210418
Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents:
9876
diff
changeset
|
48 #elif defined __EMX__ /* emx+gcc */ |
e21211210418
Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents:
9876
diff
changeset
|
49 if ((fp->_flags & _IOWRT) != 0) |
e21211210418
Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents:
9876
diff
changeset
|
50 return NULL; |
e21211210418
Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents:
9876
diff
changeset
|
51 /* Note: fp->_ungetc_count > 0 implies fp->_rcount <= 0, |
e21211210418
Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents:
9876
diff
changeset
|
52 fp->_ungetc_count = 0 implies fp->_rcount >= 0. */ |
e21211210418
Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents:
9876
diff
changeset
|
53 if (fp->_rcount <= 0) |
e21211210418
Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents:
9876
diff
changeset
|
54 return NULL; |
9899 | 55 if (!(fp->_ungetc_count == 0)) |
9881
e21211210418
Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents:
9876
diff
changeset
|
56 abort (); |
e21211210418
Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents:
9876
diff
changeset
|
57 *sizep = fp->_rcount; |
e21211210418
Port the extended stdio functions to emx+gcc.
Bruno Haible <bruno@clisp.org>
parents:
9876
diff
changeset
|
58 return fp->_ptr; |
15485
20a2699b8a90
stdioext: Add support for Minix.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
59 #elif defined __minix /* Minix */ |
20a2699b8a90
stdioext: Add support for Minix.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
60 if ((fp_->_flags & _IOWRITING) != 0) |
20a2699b8a90
stdioext: Add support for Minix.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
61 return NULL; |
20a2699b8a90
stdioext: Add support for Minix.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
62 size = fp_->_count; |
20a2699b8a90
stdioext: Add support for Minix.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
63 if (size == 0) |
20a2699b8a90
stdioext: Add support for Minix.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
64 return NULL; |
20a2699b8a90
stdioext: Add support for Minix.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
65 *sizep = size; |
20a2699b8a90
stdioext: Add support for Minix.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
66 return (const char *) fp_->_ptr; |
13997
6fa9f46e6153
Port extended stdio modules to HP NonStop Kernel.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
67 #elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw, NonStop Kernel */ |
9779
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
68 if ((fp_->_flag & _IOWRT) != 0) |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
69 return NULL; |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
70 size = fp_->_cnt; |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
71 if (size == 0) |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
72 return NULL; |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
73 *sizep = size; |
9727 | 74 return (const char *) fp_->_ptr; |
75 #elif defined __UCLIBC__ /* uClibc */ | |
76 # ifdef __STDIO_BUFFERS | |
9779
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
77 if (fp->__modeflags & __FLAG_WRITING) |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
78 return NULL; |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
79 size = fp->__bufread - fp->__bufpos; |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
80 if (size == 0) |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
81 return NULL; |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
82 *sizep = size; |
9727 | 83 return (const char *) fp->__bufpos; |
84 # else | |
85 return NULL; | |
86 # endif | |
87 #elif defined __QNX__ /* QNX */ | |
9779
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
88 if ((fp->_Mode & 0x2000 /* _MWRITE */) != 0) |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
89 return NULL; |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
90 /* fp->_Buf <= fp->_Next <= fp->_Rend */ |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
91 size = fp->_Rend - fp->_Next; |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
92 if (size == 0) |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
93 return NULL; |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
94 *sizep = size; |
9727 | 95 return (const char *) fp->_Next; |
11236
d4475bf2a2bf
Add tentative support for FreeMiNT.
Bruno Haible <bruno@clisp.org>
parents:
10780
diff
changeset
|
96 #elif defined __MINT__ /* Atari FreeMiNT */ |
d4475bf2a2bf
Add tentative support for FreeMiNT.
Bruno Haible <bruno@clisp.org>
parents:
10780
diff
changeset
|
97 if (!fp->__mode.__read) |
d4475bf2a2bf
Add tentative support for FreeMiNT.
Bruno Haible <bruno@clisp.org>
parents:
10780
diff
changeset
|
98 return NULL; |
d4475bf2a2bf
Add tentative support for FreeMiNT.
Bruno Haible <bruno@clisp.org>
parents:
10780
diff
changeset
|
99 size = fp->__get_limit - fp->__bufp; |
d4475bf2a2bf
Add tentative support for FreeMiNT.
Bruno Haible <bruno@clisp.org>
parents:
10780
diff
changeset
|
100 if (size == 0) |
d4475bf2a2bf
Add tentative support for FreeMiNT.
Bruno Haible <bruno@clisp.org>
parents:
10780
diff
changeset
|
101 return NULL; |
d4475bf2a2bf
Add tentative support for FreeMiNT.
Bruno Haible <bruno@clisp.org>
parents:
10780
diff
changeset
|
102 *sizep = size; |
d4475bf2a2bf
Add tentative support for FreeMiNT.
Bruno Haible <bruno@clisp.org>
parents:
10780
diff
changeset
|
103 return fp->__bufp; |
16344
ecfc57537d99
stdioext: Add tentative support for Plan9.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
104 #elif defined EPLAN9 /* Plan9 */ |
ecfc57537d99
stdioext: Add tentative support for Plan9.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
105 if (fp->state == 4 /* WR */) |
ecfc57537d99
stdioext: Add tentative support for Plan9.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
106 return NULL; |
ecfc57537d99
stdioext: Add tentative support for Plan9.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
107 if (fp->rp >= fp->wp) |
ecfc57537d99
stdioext: Add tentative support for Plan9.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
108 return NULL; |
ecfc57537d99
stdioext: Add tentative support for Plan9.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
109 *sizep = fp->wp - fp->rp; |
ecfc57537d99
stdioext: Add tentative support for Plan9.
Bruno Haible <bruno@clisp.org>
parents:
16201
diff
changeset
|
110 return fp->rp; |
10404
4611578c5669
Add conditional code for SLOW_BUT_NO_HACKS.
Bruno Haible <bruno@clisp.org>
parents:
9981
diff
changeset
|
111 #elif defined SLOW_BUT_NO_HACKS /* users can define this */ |
4611578c5669
Add conditional code for SLOW_BUT_NO_HACKS.
Bruno Haible <bruno@clisp.org>
parents:
9981
diff
changeset
|
112 /* This implementation is correct on any ANSI C platform. It is just |
4611578c5669
Add conditional code for SLOW_BUT_NO_HACKS.
Bruno Haible <bruno@clisp.org>
parents:
9981
diff
changeset
|
113 awfully slow. */ |
4611578c5669
Add conditional code for SLOW_BUT_NO_HACKS.
Bruno Haible <bruno@clisp.org>
parents:
9981
diff
changeset
|
114 return NULL; |
9727 | 115 #else |
9779
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
116 #error "Please port gnulib freadptr.c to your platform! Look at the definition of fflush, fread, getc, getc_unlocked on your system, then report this to bug-gnulib." |
9727 | 117 #endif |
118 } |