stdio-impl.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* Implementation details of FILE streams.
  2. Copyright (C) 2007-2008, 2010-2013 Free Software Foundation, Inc.
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. /* Glibc 2.28 made _IO_IN_BACKUP private. For now, work around this
  14. problem by defining it ourselves. FIXME: Do not rely on glibc
  15. internals. */
  16. #if !defined _IO_IN_BACKUP && defined _IO_EOF_SEEN
  17. # define _IO_IN_BACKUP 0x100
  18. #endif
  19. /* Many stdio implementations have the same logic and therefore can share
  20. the same implementation of stdio extension API, except that some fields
  21. have different naming conventions, or their access requires some casts. */
  22. /* BSD stdio derived implementations. */
  23. #if defined __NetBSD__ /* NetBSD */
  24. /* Get __NetBSD_Version__. */
  25. # include <sys/param.h>
  26. #endif
  27. #include <errno.h> /* For detecting Plan9. */
  28. #if defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
  29. # if defined __DragonFly__ /* DragonFly */
  30. /* See <http://www.dragonflybsd.org/cvsweb/src/lib/libc/stdio/priv_stdio.h?rev=HEAD&content-type=text/x-cvsweb-markup>. */
  31. # define fp_ ((struct { struct __FILE_public pub; \
  32. struct { unsigned char *_base; int _size; } _bf; \
  33. void *cookie; \
  34. void *_close; \
  35. void *_read; \
  36. void *_seek; \
  37. void *_write; \
  38. struct { unsigned char *_base; int _size; } _ub; \
  39. int _ur; \
  40. unsigned char _ubuf[3]; \
  41. unsigned char _nbuf[1]; \
  42. struct { unsigned char *_base; int _size; } _lb; \
  43. int _blksize; \
  44. fpos_t _offset; \
  45. /* More fields, not relevant here. */ \
  46. } *) fp)
  47. /* See <http://www.dragonflybsd.org/cvsweb/src/include/stdio.h?rev=HEAD&content-type=text/x-cvsweb-markup>. */
  48. # define _p pub._p
  49. # define _flags pub._flags
  50. # define _r pub._r
  51. # define _w pub._w
  52. # else
  53. # define fp_ fp
  54. # endif
  55. # if (defined __NetBSD__ && __NetBSD_Version__ >= 105270000) || defined __OpenBSD__ || defined __ANDROID__ /* NetBSD >= 1.5ZA, OpenBSD, Android */
  56. /* See <http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup>
  57. and <http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/fileext.h?rev=HEAD&content-type=text/x-cvsweb-markup> */
  58. struct __sfileext
  59. {
  60. struct __sbuf _ub; /* ungetc buffer */
  61. /* More fields, not relevant here. */
  62. };
  63. # define fp_ub ((struct __sfileext *) fp->_ext._base)->_ub
  64. # else /* FreeBSD, NetBSD <= 1.5Z, DragonFly, Mac OS X, Cygwin */
  65. # define fp_ub fp_->_ub
  66. # endif
  67. # define HASUB(fp) (fp_ub._base != NULL)
  68. #endif
  69. /* SystemV derived implementations. */
  70. #ifdef __TANDEM /* NonStop Kernel */
  71. # ifndef _IOERR
  72. /* These values were determined by the program 'stdioext-flags' at
  73. <http://lists.gnu.org/archive/html/bug-gnulib/2010-12/msg00165.html>. */
  74. # define _IOERR 0x40
  75. # define _IOREAD 0x80
  76. # define _IOWRT 0x4
  77. # define _IORW 0x100
  78. # endif
  79. #endif
  80. #if defined _IOERR
  81. # if defined __sun && defined _LP64 /* Solaris/{SPARC,AMD64} 64-bit */
  82. # define fp_ ((struct { unsigned char *_ptr; \
  83. unsigned char *_base; \
  84. unsigned char *_end; \
  85. long _cnt; \
  86. int _file; \
  87. unsigned int _flag; \
  88. } *) fp)
  89. # else
  90. # define fp_ fp
  91. # endif
  92. # if defined _SCO_DS /* OpenServer */
  93. # define _cnt __cnt
  94. # define _ptr __ptr
  95. # define _base __base
  96. # define _flag __flag
  97. # endif
  98. #endif