1*8d67ca89SAndroid Build Coastguard Worker /* $OpenBSD: local.h,v 1.12 2005/10/10 17:37:44 espie Exp $ */ 2*8d67ca89SAndroid Build Coastguard Worker 3*8d67ca89SAndroid Build Coastguard Worker /*- 4*8d67ca89SAndroid Build Coastguard Worker * Copyright (c) 1990, 1993 5*8d67ca89SAndroid Build Coastguard Worker * The Regents of the University of California. All rights reserved. 6*8d67ca89SAndroid Build Coastguard Worker * 7*8d67ca89SAndroid Build Coastguard Worker * This code is derived from software contributed to Berkeley by 8*8d67ca89SAndroid Build Coastguard Worker * Chris Torek. 9*8d67ca89SAndroid Build Coastguard Worker * 10*8d67ca89SAndroid Build Coastguard Worker * Redistribution and use in source and binary forms, with or without 11*8d67ca89SAndroid Build Coastguard Worker * modification, are permitted provided that the following conditions 12*8d67ca89SAndroid Build Coastguard Worker * are met: 13*8d67ca89SAndroid Build Coastguard Worker * 1. Redistributions of source code must retain the above copyright 14*8d67ca89SAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer. 15*8d67ca89SAndroid Build Coastguard Worker * 2. Redistributions in binary form must reproduce the above copyright 16*8d67ca89SAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer in the 17*8d67ca89SAndroid Build Coastguard Worker * documentation and/or other materials provided with the distribution. 18*8d67ca89SAndroid Build Coastguard Worker * 3. Neither the name of the University nor the names of its contributors 19*8d67ca89SAndroid Build Coastguard Worker * may be used to endorse or promote products derived from this software 20*8d67ca89SAndroid Build Coastguard Worker * without specific prior written permission. 21*8d67ca89SAndroid Build Coastguard Worker * 22*8d67ca89SAndroid Build Coastguard Worker * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23*8d67ca89SAndroid Build Coastguard Worker * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24*8d67ca89SAndroid Build Coastguard Worker * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25*8d67ca89SAndroid Build Coastguard Worker * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26*8d67ca89SAndroid Build Coastguard Worker * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27*8d67ca89SAndroid Build Coastguard Worker * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28*8d67ca89SAndroid Build Coastguard Worker * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29*8d67ca89SAndroid Build Coastguard Worker * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30*8d67ca89SAndroid Build Coastguard Worker * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31*8d67ca89SAndroid Build Coastguard Worker * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32*8d67ca89SAndroid Build Coastguard Worker * SUCH DAMAGE. 33*8d67ca89SAndroid Build Coastguard Worker */ 34*8d67ca89SAndroid Build Coastguard Worker 35*8d67ca89SAndroid Build Coastguard Worker #pragma once 36*8d67ca89SAndroid Build Coastguard Worker 37*8d67ca89SAndroid Build Coastguard Worker #include <pthread.h> 38*8d67ca89SAndroid Build Coastguard Worker #include <stdbool.h> 39*8d67ca89SAndroid Build Coastguard Worker #include <wchar.h> 40*8d67ca89SAndroid Build Coastguard Worker 41*8d67ca89SAndroid Build Coastguard Worker #if defined(__cplusplus) // Until we fork all of stdio... 42*8d67ca89SAndroid Build Coastguard Worker #include "private/bionic_fortify.h" 43*8d67ca89SAndroid Build Coastguard Worker #endif 44*8d67ca89SAndroid Build Coastguard Worker 45*8d67ca89SAndroid Build Coastguard Worker /* 46*8d67ca89SAndroid Build Coastguard Worker * Information local to this implementation of stdio, 47*8d67ca89SAndroid Build Coastguard Worker * in particular, macros and private variables. 48*8d67ca89SAndroid Build Coastguard Worker */ 49*8d67ca89SAndroid Build Coastguard Worker 50*8d67ca89SAndroid Build Coastguard Worker __BEGIN_DECLS 51*8d67ca89SAndroid Build Coastguard Worker 52*8d67ca89SAndroid Build Coastguard Worker struct __sbuf { 53*8d67ca89SAndroid Build Coastguard Worker unsigned char* _base; 54*8d67ca89SAndroid Build Coastguard Worker size_t _size; 55*8d67ca89SAndroid Build Coastguard Worker }; 56*8d67ca89SAndroid Build Coastguard Worker 57*8d67ca89SAndroid Build Coastguard Worker struct __sFILE { 58*8d67ca89SAndroid Build Coastguard Worker unsigned char* _p; /* current position in (some) buffer */ 59*8d67ca89SAndroid Build Coastguard Worker int _r; /* read space left for getc() */ 60*8d67ca89SAndroid Build Coastguard Worker int _w; /* write space left for putc() */ 61*8d67ca89SAndroid Build Coastguard Worker #if defined(__LP64__) 62*8d67ca89SAndroid Build Coastguard Worker int _flags; /* flags, below; this FILE is free if 0 */ 63*8d67ca89SAndroid Build Coastguard Worker int _file; /* fileno, if Unix descriptor, else -1 */ 64*8d67ca89SAndroid Build Coastguard Worker #else 65*8d67ca89SAndroid Build Coastguard Worker short _flags; /* flags, below; this FILE is free if 0 */ 66*8d67ca89SAndroid Build Coastguard Worker short _file; /* fileno, if Unix descriptor, else -1 */ 67*8d67ca89SAndroid Build Coastguard Worker #endif 68*8d67ca89SAndroid Build Coastguard Worker struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */ 69*8d67ca89SAndroid Build Coastguard Worker int _lbfsize; /* 0 or -_bf._size, for inline putc */ 70*8d67ca89SAndroid Build Coastguard Worker 71*8d67ca89SAndroid Build Coastguard Worker // Function pointers used by `funopen`. 72*8d67ca89SAndroid Build Coastguard Worker // Note that `_seek` is ignored if `_seek64` (in __sfileext) is set. 73*8d67ca89SAndroid Build Coastguard Worker // TODO: NetBSD has `funopen2` which corrects the `int`s to `size_t`s. 74*8d67ca89SAndroid Build Coastguard Worker // TODO: glibc has `fopencookie` which passes the function pointers in a struct. 75*8d67ca89SAndroid Build Coastguard Worker void* _cookie; /* cookie passed to io functions */ 76*8d67ca89SAndroid Build Coastguard Worker int (*_close)(void*); 77*8d67ca89SAndroid Build Coastguard Worker int (*_read)(void*, char*, int); 78*8d67ca89SAndroid Build Coastguard Worker fpos_t (*_seek)(void*, fpos_t, int); 79*8d67ca89SAndroid Build Coastguard Worker int (*_write)(void*, const char*, int); 80*8d67ca89SAndroid Build Coastguard Worker 81*8d67ca89SAndroid Build Coastguard Worker /* extension data, to avoid further ABI breakage */ 82*8d67ca89SAndroid Build Coastguard Worker struct __sbuf _ext; 83*8d67ca89SAndroid Build Coastguard Worker /* data for long sequences of ungetc() */ 84*8d67ca89SAndroid Build Coastguard Worker unsigned char* _up; /* saved _p when _p is doing ungetc data */ 85*8d67ca89SAndroid Build Coastguard Worker int _ur; /* saved _r when _r is counting ungetc data */ 86*8d67ca89SAndroid Build Coastguard Worker 87*8d67ca89SAndroid Build Coastguard Worker /* tricks to meet minimum requirements even when malloc() fails */ 88*8d67ca89SAndroid Build Coastguard Worker unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */ 89*8d67ca89SAndroid Build Coastguard Worker unsigned char _nbuf[1]; /* guarantee a getc() buffer */ 90*8d67ca89SAndroid Build Coastguard Worker 91*8d67ca89SAndroid Build Coastguard Worker /* separate buffer for fgetln() when line crosses buffer boundary */ 92*8d67ca89SAndroid Build Coastguard Worker struct __sbuf _lb; /* buffer for fgetln() */ 93*8d67ca89SAndroid Build Coastguard Worker 94*8d67ca89SAndroid Build Coastguard Worker /* Unix stdio files get aligned to block boundaries on fseek() */ 95*8d67ca89SAndroid Build Coastguard Worker int _blksize; /* stat.st_blksize (may be != _bf._size) */ 96*8d67ca89SAndroid Build Coastguard Worker 97*8d67ca89SAndroid Build Coastguard Worker fpos_t _unused_0; // This was the `_offset` field (see below). 98*8d67ca89SAndroid Build Coastguard Worker 99*8d67ca89SAndroid Build Coastguard Worker // Do not add new fields here. (Or remove or change the size of any above.) 100*8d67ca89SAndroid Build Coastguard Worker // Although bionic currently exports `stdin`, `stdout`, and `stderr` symbols, 101*8d67ca89SAndroid Build Coastguard Worker // that still hasn't made it to the NDK. All NDK-built apps index directly 102*8d67ca89SAndroid Build Coastguard Worker // into an array of this struct (which was in <stdio.h> historically), so if 103*8d67ca89SAndroid Build Coastguard Worker // you need to make any changes, they need to be in the `__sfileext` struct 104*8d67ca89SAndroid Build Coastguard Worker // below, and accessed via `_EXT`. 105*8d67ca89SAndroid Build Coastguard Worker }; 106*8d67ca89SAndroid Build Coastguard Worker 107*8d67ca89SAndroid Build Coastguard Worker /* minimal requirement of SUSv2 */ 108*8d67ca89SAndroid Build Coastguard Worker #define WCIO_UNGETWC_BUFSIZE 1 109*8d67ca89SAndroid Build Coastguard Worker 110*8d67ca89SAndroid Build Coastguard Worker struct wchar_io_data { 111*8d67ca89SAndroid Build Coastguard Worker mbstate_t wcio_mbstate_in; 112*8d67ca89SAndroid Build Coastguard Worker mbstate_t wcio_mbstate_out; 113*8d67ca89SAndroid Build Coastguard Worker 114*8d67ca89SAndroid Build Coastguard Worker wchar_t wcio_ungetwc_buf[WCIO_UNGETWC_BUFSIZE]; 115*8d67ca89SAndroid Build Coastguard Worker size_t wcio_ungetwc_inbuf; 116*8d67ca89SAndroid Build Coastguard Worker 117*8d67ca89SAndroid Build Coastguard Worker int wcio_mode; /* orientation */ 118*8d67ca89SAndroid Build Coastguard Worker }; 119*8d67ca89SAndroid Build Coastguard Worker 120*8d67ca89SAndroid Build Coastguard Worker struct __sfileext { 121*8d67ca89SAndroid Build Coastguard Worker // ungetc buffer. 122*8d67ca89SAndroid Build Coastguard Worker struct __sbuf _ub; 123*8d67ca89SAndroid Build Coastguard Worker 124*8d67ca89SAndroid Build Coastguard Worker // Wide char io status. 125*8d67ca89SAndroid Build Coastguard Worker struct wchar_io_data _wcio; 126*8d67ca89SAndroid Build Coastguard Worker 127*8d67ca89SAndroid Build Coastguard Worker // File lock. 128*8d67ca89SAndroid Build Coastguard Worker pthread_mutex_t _lock; 129*8d67ca89SAndroid Build Coastguard Worker 130*8d67ca89SAndroid Build Coastguard Worker // __fsetlocking support. 131*8d67ca89SAndroid Build Coastguard Worker bool _caller_handles_locking; 132*8d67ca89SAndroid Build Coastguard Worker 133*8d67ca89SAndroid Build Coastguard Worker // Equivalent to `_seek` but for _FILE_OFFSET_BITS=64. 134*8d67ca89SAndroid Build Coastguard Worker // Callers should use this but fall back to `__sFILE::_seek`. 135*8d67ca89SAndroid Build Coastguard Worker off64_t (*_seek64)(void*, off64_t, int); 136*8d67ca89SAndroid Build Coastguard Worker 137*8d67ca89SAndroid Build Coastguard Worker // The pid of the child if this FILE* is from popen(3). 138*8d67ca89SAndroid Build Coastguard Worker pid_t _popen_pid; 139*8d67ca89SAndroid Build Coastguard Worker }; 140*8d67ca89SAndroid Build Coastguard Worker 141*8d67ca89SAndroid Build Coastguard Worker // Values for `__sFILE::_flags`. 142*8d67ca89SAndroid Build Coastguard Worker #define __SLBF 0x0001 // Line buffered. 143*8d67ca89SAndroid Build Coastguard Worker #define __SNBF 0x0002 // Unbuffered. 144*8d67ca89SAndroid Build Coastguard Worker // __SRD and __SWR are mutually exclusive because they indicate what we did last. 145*8d67ca89SAndroid Build Coastguard Worker // If you want to know whether we were opened read-write, check __SRW instead. 146*8d67ca89SAndroid Build Coastguard Worker #define __SRD 0x0004 // Last operation was read. 147*8d67ca89SAndroid Build Coastguard Worker #define __SWR 0x0008 // Last operation was write. 148*8d67ca89SAndroid Build Coastguard Worker #define __SRW 0x0010 // Was opened for reading & writing. 149*8d67ca89SAndroid Build Coastguard Worker #define __SEOF 0x0020 // Found EOF. 150*8d67ca89SAndroid Build Coastguard Worker #define __SERR 0x0040 // Found error. 151*8d67ca89SAndroid Build Coastguard Worker #define __SMBF 0x0080 // `_buf` is from malloc. 152*8d67ca89SAndroid Build Coastguard Worker // #define __SAPP 0x0100 --- historical (fdopen()ed in append mode). 153*8d67ca89SAndroid Build Coastguard Worker #define __SSTR 0x0200 // This is an sprintf/snprintf string. 154*8d67ca89SAndroid Build Coastguard Worker // #define __SOPT 0x0400 --- historical (do fseek() optimization). 155*8d67ca89SAndroid Build Coastguard Worker // #define __SNPT 0x0800 --- historical (do not do fseek() optimization). 156*8d67ca89SAndroid Build Coastguard Worker // #define __SOFF 0x1000 --- historical (set iff _offset is in fact correct). 157*8d67ca89SAndroid Build Coastguard Worker // #define __SMOD 0x2000 --- historical (set iff fgetln modified _p text). 158*8d67ca89SAndroid Build Coastguard Worker #define __SALC 0x4000 // Allocate string space dynamically. 159*8d67ca89SAndroid Build Coastguard Worker #define __SIGN 0x8000 // Ignore this file in _fwalk. 160*8d67ca89SAndroid Build Coastguard Worker 161*8d67ca89SAndroid Build Coastguard Worker // TODO: remove remaining references to these obsolete flags (see above). 162*8d67ca89SAndroid Build Coastguard Worker #define __SMOD 0 163*8d67ca89SAndroid Build Coastguard Worker #define __SNPT 0 164*8d67ca89SAndroid Build Coastguard Worker #define __SOPT 0 165*8d67ca89SAndroid Build Coastguard Worker 166*8d67ca89SAndroid Build Coastguard Worker #define _EXT(fp) __BIONIC_CAST(reinterpret_cast, struct __sfileext*, (fp)->_ext._base) 167*8d67ca89SAndroid Build Coastguard Worker 168*8d67ca89SAndroid Build Coastguard Worker #define _UB(fp) _EXT(fp)->_ub 169*8d67ca89SAndroid Build Coastguard Worker 170*8d67ca89SAndroid Build Coastguard Worker #define _FILEEXT_SETUP(fp, fext) \ 171*8d67ca89SAndroid Build Coastguard Worker do { \ 172*8d67ca89SAndroid Build Coastguard Worker (fp)->_ext._base = __BIONIC_CAST(reinterpret_cast, unsigned char*, fext); \ 173*8d67ca89SAndroid Build Coastguard Worker memset(_EXT(fp), 0, sizeof(struct __sfileext)); \ 174*8d67ca89SAndroid Build Coastguard Worker _EXT(fp)->_caller_handles_locking = true; \ 175*8d67ca89SAndroid Build Coastguard Worker } while (0) 176*8d67ca89SAndroid Build Coastguard Worker 177*8d67ca89SAndroid Build Coastguard Worker // Android <= 19 had getc/putc macros in <stdio.h> that referred 178*8d67ca89SAndroid Build Coastguard Worker // to __srget/__swbuf, so those symbols need to be public for LP32 179*8d67ca89SAndroid Build Coastguard Worker // but can be hidden for LP64. Moreover, the NDK continued to ship 180*8d67ca89SAndroid Build Coastguard Worker // those macros until r15 made unified headers the default. 181*8d67ca89SAndroid Build Coastguard Worker __LIBC32_LEGACY_PUBLIC__ int __srget(FILE*); 182*8d67ca89SAndroid Build Coastguard Worker __LIBC32_LEGACY_PUBLIC__ int __swbuf(int, FILE*); 183*8d67ca89SAndroid Build Coastguard Worker __LIBC32_LEGACY_PUBLIC__ int __srefill(FILE*); 184*8d67ca89SAndroid Build Coastguard Worker 185*8d67ca89SAndroid Build Coastguard Worker /* This was referenced by the apportable middleware for LP32. */ 186*8d67ca89SAndroid Build Coastguard Worker __LIBC32_LEGACY_PUBLIC__ int __swsetup(FILE*); 187*8d67ca89SAndroid Build Coastguard Worker 188*8d67ca89SAndroid Build Coastguard Worker /* These were referenced by a couple of different pieces of middleware and the Crystax NDK. */ 189*8d67ca89SAndroid Build Coastguard Worker __LIBC32_LEGACY_PUBLIC__ int __sflags(const char*, int*); 190*8d67ca89SAndroid Build Coastguard Worker __LIBC32_LEGACY_PUBLIC__ FILE* __sfp(void); 191*8d67ca89SAndroid Build Coastguard Worker __LIBC32_LEGACY_PUBLIC__ void __smakebuf(FILE*); 192*8d67ca89SAndroid Build Coastguard Worker 193*8d67ca89SAndroid Build Coastguard Worker /* These are referenced by the Greed for Glory franchise. */ 194*8d67ca89SAndroid Build Coastguard Worker __LIBC32_LEGACY_PUBLIC__ int __sflush(FILE*); 195*8d67ca89SAndroid Build Coastguard Worker __LIBC32_LEGACY_PUBLIC__ int __sread(void*, char*, int); 196*8d67ca89SAndroid Build Coastguard Worker __LIBC32_LEGACY_PUBLIC__ int __swrite(void*, const char*, int); 197*8d67ca89SAndroid Build Coastguard Worker __LIBC32_LEGACY_PUBLIC__ fpos_t __sseek(void*, fpos_t, int); 198*8d67ca89SAndroid Build Coastguard Worker __LIBC32_LEGACY_PUBLIC__ int __sclose(void*); 199*8d67ca89SAndroid Build Coastguard Worker __LIBC32_LEGACY_PUBLIC__ int _fwalk(int (*)(FILE*)); 200*8d67ca89SAndroid Build Coastguard Worker 201*8d67ca89SAndroid Build Coastguard Worker off64_t __sseek64(void*, off64_t, int); 202*8d67ca89SAndroid Build Coastguard Worker int __sflush_locked(FILE*); 203*8d67ca89SAndroid Build Coastguard Worker int __swhatbuf(FILE*, size_t*, int*); 204*8d67ca89SAndroid Build Coastguard Worker wint_t __fgetwc_unlock(FILE*); 205*8d67ca89SAndroid Build Coastguard Worker wint_t __ungetwc(wint_t, FILE*); 206*8d67ca89SAndroid Build Coastguard Worker int __vfprintf(FILE*, const char*, va_list); 207*8d67ca89SAndroid Build Coastguard Worker int __svfscanf(FILE*, const char*, va_list); 208*8d67ca89SAndroid Build Coastguard Worker int __vfwprintf(FILE*, const wchar_t*, va_list); 209*8d67ca89SAndroid Build Coastguard Worker int __vfwscanf(FILE*, const wchar_t*, va_list); 210*8d67ca89SAndroid Build Coastguard Worker 211*8d67ca89SAndroid Build Coastguard Worker /* 212*8d67ca89SAndroid Build Coastguard Worker * Return true if the given FILE cannot be written now. 213*8d67ca89SAndroid Build Coastguard Worker */ 214*8d67ca89SAndroid Build Coastguard Worker #define cantwrite(fp) ((((fp)->_flags & __SWR) == 0 || (fp)->_bf._base == NULL) && __swsetup(fp)) 215*8d67ca89SAndroid Build Coastguard Worker 216*8d67ca89SAndroid Build Coastguard Worker /* 217*8d67ca89SAndroid Build Coastguard Worker * Test whether the given stdio file has an active ungetc buffer; 218*8d67ca89SAndroid Build Coastguard Worker * release such a buffer, without restoring ordinary unread data. 219*8d67ca89SAndroid Build Coastguard Worker */ 220*8d67ca89SAndroid Build Coastguard Worker #define HASUB(fp) (_UB(fp)._base != NULL) 221*8d67ca89SAndroid Build Coastguard Worker #define FREEUB(fp) \ 222*8d67ca89SAndroid Build Coastguard Worker { \ 223*8d67ca89SAndroid Build Coastguard Worker if (_UB(fp)._base != (fp)->_ubuf) free(_UB(fp)._base); \ 224*8d67ca89SAndroid Build Coastguard Worker _UB(fp)._base = NULL; \ 225*8d67ca89SAndroid Build Coastguard Worker } 226*8d67ca89SAndroid Build Coastguard Worker 227*8d67ca89SAndroid Build Coastguard Worker #define FLOCKFILE(fp) \ 228*8d67ca89SAndroid Build Coastguard Worker if (!_EXT(fp)->_caller_handles_locking) flockfile(fp) 229*8d67ca89SAndroid Build Coastguard Worker #define FUNLOCKFILE(fp) \ 230*8d67ca89SAndroid Build Coastguard Worker if (!_EXT(fp)->_caller_handles_locking) funlockfile(fp) 231*8d67ca89SAndroid Build Coastguard Worker 232*8d67ca89SAndroid Build Coastguard Worker /* OpenBSD exposes these in <stdio.h>, but we only want them exposed to the implementation. */ 233*8d67ca89SAndroid Build Coastguard Worker #define __sferror(p) (((p)->_flags & __SERR) != 0) 234*8d67ca89SAndroid Build Coastguard Worker #define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR | __SEOF))) 235*8d67ca89SAndroid Build Coastguard Worker #define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : __BIONIC_CAST(static_cast, int, *(p)->_p++)) 236*8d67ca89SAndroid Build Coastguard Worker 237*8d67ca89SAndroid Build Coastguard Worker /* OpenBSD declares these in fvwrite.h, but we share them with C++ parts of the implementation. */ 238*8d67ca89SAndroid Build Coastguard Worker struct __siov { 239*8d67ca89SAndroid Build Coastguard Worker void* iov_base; 240*8d67ca89SAndroid Build Coastguard Worker size_t iov_len; 241*8d67ca89SAndroid Build Coastguard Worker }; 242*8d67ca89SAndroid Build Coastguard Worker struct __suio { 243*8d67ca89SAndroid Build Coastguard Worker struct __siov* uio_iov; 244*8d67ca89SAndroid Build Coastguard Worker int uio_iovcnt; 245*8d67ca89SAndroid Build Coastguard Worker size_t uio_resid; 246*8d67ca89SAndroid Build Coastguard Worker }; 247*8d67ca89SAndroid Build Coastguard Worker int __sfvwrite(FILE*, struct __suio*); 248*8d67ca89SAndroid Build Coastguard Worker wint_t __fputwc_unlock(wchar_t wc, FILE* fp); 249*8d67ca89SAndroid Build Coastguard Worker 250*8d67ca89SAndroid Build Coastguard Worker /* Remove the if (!__sdidinit) __sinit() idiom from untouched upstream stdio code. */ 251*8d67ca89SAndroid Build Coastguard Worker extern void __sinit(void); // Not actually implemented. 252*8d67ca89SAndroid Build Coastguard Worker #define __sdidinit 1 253*8d67ca89SAndroid Build Coastguard Worker 254*8d67ca89SAndroid Build Coastguard Worker size_t parsefloat(FILE*, char*, char*); 255*8d67ca89SAndroid Build Coastguard Worker size_t wparsefloat(FILE*, wchar_t*, wchar_t*); 256*8d67ca89SAndroid Build Coastguard Worker 257*8d67ca89SAndroid Build Coastguard Worker // Check a FILE* isn't nullptr, so we can emit a clear diagnostic message 258*8d67ca89SAndroid Build Coastguard Worker // instead of just crashing with SIGSEGV. 259*8d67ca89SAndroid Build Coastguard Worker #define CHECK_FP(fp) \ 260*8d67ca89SAndroid Build Coastguard Worker if (fp == nullptr) __fortify_fatal("%s: null FILE*", __FUNCTION__) 261*8d67ca89SAndroid Build Coastguard Worker 262*8d67ca89SAndroid Build Coastguard Worker /* 263*8d67ca89SAndroid Build Coastguard Worker * Floating point scanf/printf (input/output) definitions. 264*8d67ca89SAndroid Build Coastguard Worker */ 265*8d67ca89SAndroid Build Coastguard Worker 266*8d67ca89SAndroid Build Coastguard Worker /* 11-bit exponent (VAX G floating point) is 308 decimal digits */ 267*8d67ca89SAndroid Build Coastguard Worker #define MAXEXP 308 268*8d67ca89SAndroid Build Coastguard Worker /* 128 bit fraction takes up 39 decimal digits; max reasonable precision */ 269*8d67ca89SAndroid Build Coastguard Worker #define MAXFRACT 39 270*8d67ca89SAndroid Build Coastguard Worker 271*8d67ca89SAndroid Build Coastguard Worker /* 272*8d67ca89SAndroid Build Coastguard Worker * MAXEXPDIG is the maximum number of decimal digits needed to store a 273*8d67ca89SAndroid Build Coastguard Worker * floating point exponent in the largest supported format. It should 274*8d67ca89SAndroid Build Coastguard Worker * be ceil(log10(LDBL_MAX_10_EXP)) or, if hexadecimal floating point 275*8d67ca89SAndroid Build Coastguard Worker * conversions are supported, ceil(log10(LDBL_MAX_EXP)). But since it 276*8d67ca89SAndroid Build Coastguard Worker * is presently never greater than 5 in practice, we fudge it. 277*8d67ca89SAndroid Build Coastguard Worker */ 278*8d67ca89SAndroid Build Coastguard Worker #define MAXEXPDIG 6 279*8d67ca89SAndroid Build Coastguard Worker #if LDBL_MAX_EXP > 999999 280*8d67ca89SAndroid Build Coastguard Worker #error "floating point buffers too small" 281*8d67ca89SAndroid Build Coastguard Worker #endif 282*8d67ca89SAndroid Build Coastguard Worker 283*8d67ca89SAndroid Build Coastguard Worker char* __hdtoa(double, const char*, int, int*, int*, char**); 284*8d67ca89SAndroid Build Coastguard Worker char* __hldtoa(long double, const char*, int, int*, int*, char**); 285*8d67ca89SAndroid Build Coastguard Worker char* __ldtoa(long double*, int, int, int*, int*, char**); 286*8d67ca89SAndroid Build Coastguard Worker 287*8d67ca89SAndroid Build Coastguard Worker #define WCIO_GET(fp) (_EXT(fp) ? &(_EXT(fp)->_wcio) : NULL) 288*8d67ca89SAndroid Build Coastguard Worker 289*8d67ca89SAndroid Build Coastguard Worker #define ORIENT_BYTES (-1) 290*8d67ca89SAndroid Build Coastguard Worker #define ORIENT_UNKNOWN 0 291*8d67ca89SAndroid Build Coastguard Worker #define ORIENT_CHARS 1 292*8d67ca89SAndroid Build Coastguard Worker 293*8d67ca89SAndroid Build Coastguard Worker #define _SET_ORIENTATION(fp, mode) \ 294*8d67ca89SAndroid Build Coastguard Worker do { \ 295*8d67ca89SAndroid Build Coastguard Worker struct wchar_io_data* _wcio = WCIO_GET(fp); \ 296*8d67ca89SAndroid Build Coastguard Worker if (_wcio && _wcio->wcio_mode == ORIENT_UNKNOWN) _wcio->wcio_mode = (mode); \ 297*8d67ca89SAndroid Build Coastguard Worker } while (0) 298*8d67ca89SAndroid Build Coastguard Worker 299*8d67ca89SAndroid Build Coastguard Worker #define WCIO_FREE(fp) \ 300*8d67ca89SAndroid Build Coastguard Worker do { \ 301*8d67ca89SAndroid Build Coastguard Worker struct wchar_io_data* _wcio = WCIO_GET(fp); \ 302*8d67ca89SAndroid Build Coastguard Worker if (_wcio) { \ 303*8d67ca89SAndroid Build Coastguard Worker _wcio->wcio_mode = ORIENT_UNKNOWN; \ 304*8d67ca89SAndroid Build Coastguard Worker _wcio->wcio_ungetwc_inbuf = 0; \ 305*8d67ca89SAndroid Build Coastguard Worker } \ 306*8d67ca89SAndroid Build Coastguard Worker } while (0) 307*8d67ca89SAndroid Build Coastguard Worker 308*8d67ca89SAndroid Build Coastguard Worker __END_DECLS 309