Mercurial > hg > octave-kai > gnulib-hg
annotate lib/freadptr.c @ 9981:e3d6988a9347
Add tentative support for DragonFly BSD.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sat, 26 Apr 2008 18:58:00 +0200 |
parents | 2c1ba629f5d5 |
children | 4611578c5669 |
rev | line source |
---|---|
9727 | 1 /* Retrieve information about a FILE stream. |
2 Copyright (C) 2007-2008 Free Software Foundation, Inc. | |
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! */ |
9928
9a02133ad731
Add tentative support for Linux libc5.
Bruno Haible <bruno@clisp.org>
parents:
9899
diff
changeset
|
32 #if defined _IO_ferror_unlocked || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, 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; |
9981
e3d6988a9347
Add tentative support for DragonFly BSD.
Bruno Haible <bruno@clisp.org>
parents:
9980
diff
changeset
|
40 #elif 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
|
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; |
9876
057a5220dfd5
Add tentative support for OpenServer.
Bruno Haible <bruno@clisp.org>
parents:
9779
diff
changeset
|
59 #elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, OpenServer, mingw */ |
9779
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
60 if ((fp_->_flag & _IOWRT) != 0) |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
61 return NULL; |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
62 size = fp_->_cnt; |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
63 if (size == 0) |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
64 return NULL; |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
65 *sizep = size; |
9727 | 66 return (const char *) fp_->_ptr; |
67 #elif defined __UCLIBC__ /* uClibc */ | |
68 # ifdef __STDIO_BUFFERS | |
9779
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
69 if (fp->__modeflags & __FLAG_WRITING) |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
70 return NULL; |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
71 size = fp->__bufread - fp->__bufpos; |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
72 if (size == 0) |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
73 return NULL; |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
74 *sizep = size; |
9727 | 75 return (const char *) fp->__bufpos; |
76 # else | |
77 return NULL; | |
78 # endif | |
79 #elif defined __QNX__ /* QNX */ | |
9779
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
80 if ((fp->_Mode & 0x2000 /* _MWRITE */) != 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 /* fp->_Buf <= fp->_Next <= fp->_Rend */ |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
83 size = fp->_Rend - fp->_Next; |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
84 if (size == 0) |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
85 return NULL; |
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
86 *sizep = size; |
9727 | 87 return (const char *) fp->_Next; |
88 #else | |
9779
569a44f4dd4d
Extend freadptr to return also the buffer size.
Bruno Haible <bruno@clisp.org>
parents:
9727
diff
changeset
|
89 #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 | 90 #endif |
91 } |