11dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* $OpenBSD: local.h,v 1.12 2005/10/10 17:37:44 espie Exp $ */ 21dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 31dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/*- 41dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Copyright (c) 1990, 1993 51dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * The Regents of the University of California. All rights reserved. 61dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 71dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * This code is derived from software contributed to Berkeley by 81dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Chris Torek. 91dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 101dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Redistribution and use in source and binary forms, with or without 111dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * modification, are permitted provided that the following conditions 121dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * are met: 131dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 1. Redistributions of source code must retain the above copyright 141dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * notice, this list of conditions and the following disclaimer. 151dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 2. Redistributions in binary form must reproduce the above copyright 161dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * notice, this list of conditions and the following disclaimer in the 171dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * documentation and/or other materials provided with the distribution. 181dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 3. Neither the name of the University nor the names of its contributors 191dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * may be used to endorse or promote products derived from this software 201dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * without specific prior written permission. 211dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 221dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 231dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 241dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 251dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 261dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 271dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 281dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 291dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 301dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 311dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 321dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * SUCH DAMAGE. 331dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */ 341dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 35f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes#ifndef __BIONIC_STDIO_LOCAL_H__ 36f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes#define __BIONIC_STDIO_LOCAL_H__ 37f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes 38f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes#include <pthread.h> 39f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes#include <stdbool.h> 40f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes#include <wchar.h> 41f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes#include "wcio.h" 42f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes 431dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* 441dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Information local to this implementation of stdio, 451dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * in particular, macros and private variables. 461dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */ 471dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 48c48c3e4bb3d1665f3e9fa2785daafa72dfe59399Elliott Hughes__BEGIN_DECLS 49c48c3e4bb3d1665f3e9fa2785daafa72dfe59399Elliott Hughes 50f0141dfab10a4b332769d52fa76631a64741297aElliott Hughesstruct __sbuf { 51f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes unsigned char* _base; 52f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes#if defined(__LP64__) 53f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes size_t _size; 54f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes#else 55f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes int _size; 56f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes#endif 57f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes}; 58f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes 59f0141dfab10a4b332769d52fa76631a64741297aElliott Hughesstruct __sFILE { 60f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes unsigned char *_p; /* current position in (some) buffer */ 61f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes int _r; /* read space left for getc() */ 62f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes int _w; /* write space left for putc() */ 63f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes#if defined(__LP64__) 64f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes int _flags; /* flags, below; this FILE is free if 0 */ 65f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes int _file; /* fileno, if Unix descriptor, else -1 */ 66f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes#else 67f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes short _flags; /* flags, below; this FILE is free if 0 */ 68f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes short _file; /* fileno, if Unix descriptor, else -1 */ 69f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes#endif 70f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */ 71f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes int _lbfsize; /* 0 or -_bf._size, for inline putc */ 72f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes 73023c3071a036d84bbd7973edef152c5a48679cb7Elliott Hughes // Function pointers used by `funopen`. 74023c3071a036d84bbd7973edef152c5a48679cb7Elliott Hughes // Note that `_seek` is ignored if `_seek64` (in __sfileext) is set. 75023c3071a036d84bbd7973edef152c5a48679cb7Elliott Hughes // TODO: NetBSD has `funopen2` which corrects the `int`s to `size_t`s. 76023c3071a036d84bbd7973edef152c5a48679cb7Elliott Hughes // TODO: glibc has `fopencookie` which passes the function pointers in a struct. 77023c3071a036d84bbd7973edef152c5a48679cb7Elliott Hughes void* _cookie; /* cookie passed to io functions */ 78023c3071a036d84bbd7973edef152c5a48679cb7Elliott Hughes int (*_close)(void*); 79023c3071a036d84bbd7973edef152c5a48679cb7Elliott Hughes int (*_read)(void*, char*, int); 80023c3071a036d84bbd7973edef152c5a48679cb7Elliott Hughes fpos_t (*_seek)(void*, fpos_t, int); 81023c3071a036d84bbd7973edef152c5a48679cb7Elliott Hughes int (*_write)(void*, const char*, int); 82f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes 83f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes /* extension data, to avoid further ABI breakage */ 84f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes struct __sbuf _ext; 85f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes /* data for long sequences of ungetc() */ 86f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes unsigned char *_up; /* saved _p when _p is doing ungetc data */ 87f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes int _ur; /* saved _r when _r is counting ungetc data */ 88f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes 89f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes /* tricks to meet minimum requirements even when malloc() fails */ 90f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */ 91f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes unsigned char _nbuf[1]; /* guarantee a getc() buffer */ 92f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes 93f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes /* separate buffer for fgetln() when line crosses buffer boundary */ 94f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes struct __sbuf _lb; /* buffer for fgetln() */ 95f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes 96f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes /* Unix stdio files get aligned to block boundaries on fseek() */ 97f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes int _blksize; /* stat.st_blksize (may be != _bf._size) */ 98b877601bff1fcc60c7ea2180d15e38b1e873f36eElliott Hughes 99b877601bff1fcc60c7ea2180d15e38b1e873f36eElliott Hughes fpos_t _unused_0; // This was the `_offset` field (see below). 100b877601bff1fcc60c7ea2180d15e38b1e873f36eElliott Hughes 101b877601bff1fcc60c7ea2180d15e38b1e873f36eElliott Hughes // Do not add new fields here. (Or remove or change the size of any above.) 102b877601bff1fcc60c7ea2180d15e38b1e873f36eElliott Hughes // Although bionic currently exports `stdin`, `stdout`, and `stderr` symbols, 103b877601bff1fcc60c7ea2180d15e38b1e873f36eElliott Hughes // that still hasn't made it to the NDK. All NDK-built apps index directly 104b877601bff1fcc60c7ea2180d15e38b1e873f36eElliott Hughes // into an array of this struct (which was in <stdio.h> historically), so if 105b877601bff1fcc60c7ea2180d15e38b1e873f36eElliott Hughes // you need to make any changes, they need to be in the `__sfileext` struct 106b877601bff1fcc60c7ea2180d15e38b1e873f36eElliott Hughes // below, and accessed via `_EXT`. 107f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes}; 108f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes 109f0141dfab10a4b332769d52fa76631a64741297aElliott Hughesstruct __sfileext { 110023c3071a036d84bbd7973edef152c5a48679cb7Elliott Hughes // ungetc buffer. 111f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes struct __sbuf _ub; 112f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes 113023c3071a036d84bbd7973edef152c5a48679cb7Elliott Hughes // Wide char io status. 114f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes struct wchar_io_data _wcio; 115f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes 116023c3071a036d84bbd7973edef152c5a48679cb7Elliott Hughes // File lock. 117f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes pthread_mutex_t _lock; 118f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes 119023c3071a036d84bbd7973edef152c5a48679cb7Elliott Hughes // __fsetlocking support. 12076144aaa6397fe9e16893882cf59c5c9c0684a66Yabin Cui bool _caller_handles_locking; 121023c3071a036d84bbd7973edef152c5a48679cb7Elliott Hughes 122023c3071a036d84bbd7973edef152c5a48679cb7Elliott Hughes // Equivalent to `_seek` but for _FILE_OFFSET_BITS=64. 123023c3071a036d84bbd7973edef152c5a48679cb7Elliott Hughes // Callers should use this but fall back to `__sFILE::_seek`. 124023c3071a036d84bbd7973edef152c5a48679cb7Elliott Hughes off64_t (*_seek64)(void*, off64_t, int); 125f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes}; 126f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes 127e70e0e9267d069bf56a5078c99307e08a7280de7Elliott Hughes// Values for `__sFILE::_flags`. 128e70e0e9267d069bf56a5078c99307e08a7280de7Elliott Hughes#define __SLBF 0x0001 // Line buffered. 129e70e0e9267d069bf56a5078c99307e08a7280de7Elliott Hughes#define __SNBF 0x0002 // Unbuffered. 130e70e0e9267d069bf56a5078c99307e08a7280de7Elliott Hughes// RD and WR are never simultaneously asserted: use _SRW instead. 131e70e0e9267d069bf56a5078c99307e08a7280de7Elliott Hughes#define __SRD 0x0004 // OK to read. 132e70e0e9267d069bf56a5078c99307e08a7280de7Elliott Hughes#define __SWR 0x0008 // OK to write. 133e70e0e9267d069bf56a5078c99307e08a7280de7Elliott Hughes#define __SRW 0x0010 // Open for reading & writing. 134e70e0e9267d069bf56a5078c99307e08a7280de7Elliott Hughes#define __SEOF 0x0020 // Found EOF. 135e70e0e9267d069bf56a5078c99307e08a7280de7Elliott Hughes#define __SERR 0x0040 // Found error. 136e70e0e9267d069bf56a5078c99307e08a7280de7Elliott Hughes#define __SMBF 0x0080 // `_buf` is from malloc. 137e70e0e9267d069bf56a5078c99307e08a7280de7Elliott Hughes#define __SAPP 0x0100 // fdopen()ed in append mode. 138e70e0e9267d069bf56a5078c99307e08a7280de7Elliott Hughes#define __SSTR 0x0200 // This is an sprintf/snprintf string. 139e70e0e9267d069bf56a5078c99307e08a7280de7Elliott Hughes// #define __SOPT 0x0400 --- historical (do fseek() optimization). 140e70e0e9267d069bf56a5078c99307e08a7280de7Elliott Hughes// #define __SNPT 0x0800 --- historical (do not do fseek() optimization). 141e70e0e9267d069bf56a5078c99307e08a7280de7Elliott Hughes// #define __SOFF 0x1000 --- historical (set iff _offset is in fact correct). 142e70e0e9267d069bf56a5078c99307e08a7280de7Elliott Hughes#define __SMOD 0x2000 // true => fgetln modified _p text. 143e70e0e9267d069bf56a5078c99307e08a7280de7Elliott Hughes#define __SALC 0x4000 // Allocate string space dynamically. 144e70e0e9267d069bf56a5078c99307e08a7280de7Elliott Hughes#define __SIGN 0x8000 // Ignore this file in _fwalk. 145e70e0e9267d069bf56a5078c99307e08a7280de7Elliott Hughes 1462704bd13409a77237147f861c43796148326b2e3Elliott Hughes// TODO: remove remaining references to these obsolete flags. 1472704bd13409a77237147f861c43796148326b2e3Elliott Hughes#define __SNPT 0 1482704bd13409a77237147f861c43796148326b2e3Elliott Hughes#define __SOPT 0 1492704bd13409a77237147f861c43796148326b2e3Elliott Hughes 150f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes#if defined(__cplusplus) 151f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes#define _EXT(fp) reinterpret_cast<__sfileext*>((fp)->_ext._base) 152f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes#else 153f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes#define _EXT(fp) ((struct __sfileext *)((fp)->_ext._base)) 154f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes#endif 155f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes 156f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes#define _UB(fp) _EXT(fp)->_ub 157f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes#define _FLOCK(fp) _EXT(fp)->_lock 158f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes 159f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes#define _FILEEXT_INIT(fp) \ 160f0141dfab10a4b332769d52fa76631a64741297aElliott Hughesdo { \ 161f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes _UB(fp)._base = NULL; \ 162f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes _UB(fp)._size = 0; \ 163f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes WCIO_INIT(fp); \ 164f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes pthread_mutexattr_t attr; \ 165f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes pthread_mutexattr_init(&attr); \ 166f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); \ 167f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes pthread_mutex_init(&_FLOCK(fp), &attr); \ 168f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes pthread_mutexattr_destroy(&attr); \ 16976144aaa6397fe9e16893882cf59c5c9c0684a66Yabin Cui _EXT(fp)->_caller_handles_locking = false; \ 170f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes} while (0) 171f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes 172f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes#define _FILEEXT_SETUP(f, fext) \ 173f0141dfab10a4b332769d52fa76631a64741297aElliott Hughesdo { \ 174f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes (f)->_ext._base = (unsigned char *)(fext); \ 175f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes _FILEEXT_INIT(f); \ 176f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes} while (0) 177f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes 178aa50585d961fb2b0f6943399d90ca0ec734946a3Elliott Hughes/* 179aa50585d961fb2b0f6943399d90ca0ec734946a3Elliott Hughes * Android <= KitKat had getc/putc macros in <stdio.h> that referred 18035d90bb6ec9799e04dacaa4b3a4984de9dc4c7f2Elliott Hughes * to __srget/__swbuf, so those symbols need to be public for LP32 18135d90bb6ec9799e04dacaa4b3a4984de9dc4c7f2Elliott Hughes * but can be hidden for LP64. 18235d90bb6ec9799e04dacaa4b3a4984de9dc4c7f2Elliott Hughes */ 183a8184456229ace2b0255468e6b15aeb6509e27f7Christopher Ferris__LIBC32_LEGACY_PUBLIC__ int __srget(FILE*); 184a8184456229ace2b0255468e6b15aeb6509e27f7Christopher Ferris__LIBC32_LEGACY_PUBLIC__ int __swbuf(int, FILE*); 185a8184456229ace2b0255468e6b15aeb6509e27f7Christopher Ferris__LIBC32_LEGACY_PUBLIC__ int __srefill(FILE*); 1865f35710fad2092f930124ca98c0ecd456f83eecaElliott Hughes 1875f35710fad2092f930124ca98c0ecd456f83eecaElliott Hughes/* This was referenced by the apportable middleware for LP32. */ 188a8184456229ace2b0255468e6b15aeb6509e27f7Christopher Ferris__LIBC32_LEGACY_PUBLIC__ int __swsetup(FILE*); 18935d90bb6ec9799e04dacaa4b3a4984de9dc4c7f2Elliott Hughes 190abefc93ff33afdb0e92e1fe9bd47a82b5e303e14Elliott Hughes/* These were referenced by a couple of different pieces of middleware and the Crystax NDK. */ 191a8184456229ace2b0255468e6b15aeb6509e27f7Christopher Ferris__LIBC32_LEGACY_PUBLIC__ int __sflags(const char*, int*); 192a8184456229ace2b0255468e6b15aeb6509e27f7Christopher Ferris__LIBC32_LEGACY_PUBLIC__ FILE* __sfp(void); 193a8184456229ace2b0255468e6b15aeb6509e27f7Christopher Ferris__LIBC32_LEGACY_PUBLIC__ void __smakebuf(FILE*); 194abefc93ff33afdb0e92e1fe9bd47a82b5e303e14Elliott Hughes 19578ba823033e5767f54e8f4a1f9986bbc6fe57e82Christopher Ferris/* These are referenced by the Greed for Glory franchise. */ 196a8184456229ace2b0255468e6b15aeb6509e27f7Christopher Ferris__LIBC32_LEGACY_PUBLIC__ int __sflush(FILE *); 197a8184456229ace2b0255468e6b15aeb6509e27f7Christopher Ferris__LIBC32_LEGACY_PUBLIC__ int __sread(void *, char *, int); 198a8184456229ace2b0255468e6b15aeb6509e27f7Christopher Ferris__LIBC32_LEGACY_PUBLIC__ int __swrite(void *, const char *, int); 199a8184456229ace2b0255468e6b15aeb6509e27f7Christopher Ferris__LIBC32_LEGACY_PUBLIC__ fpos_t __sseek(void *, fpos_t, int); 200a8184456229ace2b0255468e6b15aeb6509e27f7Christopher Ferris__LIBC32_LEGACY_PUBLIC__ int __sclose(void *); 201a8184456229ace2b0255468e6b15aeb6509e27f7Christopher Ferris__LIBC32_LEGACY_PUBLIC__ int _fwalk(int (*)(FILE *)); 20278ba823033e5767f54e8f4a1f9986bbc6fe57e82Christopher Ferris 2032899de9b05f15e67966ed3d046709b48703a162aElliott Hughes#pragma GCC visibility push(hidden) 2042899de9b05f15e67966ed3d046709b48703a162aElliott Hughes 205023c3071a036d84bbd7973edef152c5a48679cb7Elliott Hughesoff64_t __sseek64(void*, off64_t, int); 206f582340a6a48588aa50da17e1620e8f91b146941Kenny Rootint __sflush_locked(FILE *); 2071dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectint __swhatbuf(FILE *, size_t *, int *); 20801ae00f3170ad0e36c1657f6ff8c89dfa730fd37Elliott Hugheswint_t __fgetwc_unlock(FILE *); 20901ae00f3170ad0e36c1657f6ff8c89dfa730fd37Elliott Hugheswint_t __ungetwc(wint_t, FILE *); 210f582340a6a48588aa50da17e1620e8f91b146941Kenny Rootint __vfprintf(FILE *, const char *, __va_list); 21101ae00f3170ad0e36c1657f6ff8c89dfa730fd37Elliott Hughesint __svfscanf(FILE * __restrict, const char * __restrict, __va_list); 21201ae00f3170ad0e36c1657f6ff8c89dfa730fd37Elliott Hughesint __vfwprintf(FILE * __restrict, const wchar_t * __restrict, __va_list); 21301ae00f3170ad0e36c1657f6ff8c89dfa730fd37Elliott Hughesint __vfwscanf(FILE * __restrict, const wchar_t * __restrict, __va_list); 2141dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 2151dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* 2161dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Return true if the given FILE cannot be written now. 2171dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */ 2181dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define cantwrite(fp) \ 2191dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project ((((fp)->_flags & __SWR) == 0 || (fp)->_bf._base == NULL) && \ 2201dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project __swsetup(fp)) 2211dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 2221dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* 2231dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Test whether the given stdio file has an active ungetc buffer; 2241dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * release such a buffer, without restoring ordinary unread data. 2251dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */ 2261dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define HASUB(fp) (_UB(fp)._base != NULL) 2271dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define FREEUB(fp) { \ 2281dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project if (_UB(fp)._base != (fp)->_ubuf) \ 2291dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project free(_UB(fp)._base); \ 2301dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project _UB(fp)._base = NULL; \ 2311dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} 2321dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 2331dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* 2341dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * test for an fgetln() buffer. 2351dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */ 2361dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define HASLB(fp) ((fp)->_lb._base != NULL) 2371dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define FREELB(fp) { \ 2381dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project free((char *)(fp)->_lb._base); \ 2391dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project (fp)->_lb._base = NULL; \ 2401dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project} 241f582340a6a48588aa50da17e1620e8f91b146941Kenny Root 24276144aaa6397fe9e16893882cf59c5c9c0684a66Yabin Cui#define FLOCKFILE(fp) if (!_EXT(fp)->_caller_handles_locking) flockfile(fp) 24376144aaa6397fe9e16893882cf59c5c9c0684a66Yabin Cui#define FUNLOCKFILE(fp) if (!_EXT(fp)->_caller_handles_locking) funlockfile(fp) 2441d13c64d781a87dfa3f01e5c179bfa36748786afElliott Hughes 2451d13c64d781a87dfa3f01e5c179bfa36748786afElliott Hughes#define FLOATING_POINT 2460549371bd74ba7c7a5a16c2a7d6cc17dbe0e6f97Elliott Hughes#define PRINTF_WIDE_CHAR 2470549371bd74ba7c7a5a16c2a7d6cc17dbe0e6f97Elliott Hughes#define SCANF_WIDE_CHAR 248e2341d08fa4a4e0c22056c410fd34d3f93e06017Elliott Hughes#define NO_PRINTF_PERCENT_N 249f2cea021ab2c6d7d7feeb40cca098aa132605876Elliott Hughes 250f2cea021ab2c6d7d7feeb40cca098aa132605876Elliott Hughes/* OpenBSD exposes these in <stdio.h>, but we only want them exposed to the implementation. */ 251f2cea021ab2c6d7d7feeb40cca098aa132605876Elliott Hughes#define __sfeof(p) (((p)->_flags & __SEOF) != 0) 252f2cea021ab2c6d7d7feeb40cca098aa132605876Elliott Hughes#define __sferror(p) (((p)->_flags & __SERR) != 0) 253f2cea021ab2c6d7d7feeb40cca098aa132605876Elliott Hughes#define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF))) 2548b5df3920f2843c9cdf04160517c1e8b77c992f5Elliott Hughes#if !defined(__cplusplus) 255f2cea021ab2c6d7d7feeb40cca098aa132605876Elliott Hughes#define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++)) 256f2cea021ab2c6d7d7feeb40cca098aa132605876Elliott Hughesstatic __inline int __sputc(int _c, FILE* _p) { 257f2cea021ab2c6d7d7feeb40cca098aa132605876Elliott Hughes if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n')) { 258f2cea021ab2c6d7d7feeb40cca098aa132605876Elliott Hughes return (*_p->_p++ = _c); 259f2cea021ab2c6d7d7feeb40cca098aa132605876Elliott Hughes } else { 260f2cea021ab2c6d7d7feeb40cca098aa132605876Elliott Hughes return (__swbuf(_c, _p)); 261f2cea021ab2c6d7d7feeb40cca098aa132605876Elliott Hughes } 262f2cea021ab2c6d7d7feeb40cca098aa132605876Elliott Hughes} 2638b5df3920f2843c9cdf04160517c1e8b77c992f5Elliott Hughes#endif 2642899de9b05f15e67966ed3d046709b48703a162aElliott Hughes 2652899de9b05f15e67966ed3d046709b48703a162aElliott Hughes/* OpenBSD declares these in fvwrite.h but we want to ensure they're hidden. */ 2662899de9b05f15e67966ed3d046709b48703a162aElliott Hughesstruct __suio; 2672899de9b05f15e67966ed3d046709b48703a162aElliott Hughesextern int __sfvwrite(FILE *, struct __suio *); 2682899de9b05f15e67966ed3d046709b48703a162aElliott Hugheswint_t __fputwc_unlock(wchar_t wc, FILE *fp); 2692899de9b05f15e67966ed3d046709b48703a162aElliott Hughes 270bb46afd6c44a847efe96e30d72708fd2d0906e8cElliott Hughes/* Remove the if (!__sdidinit) __sinit() idiom from untouched upstream stdio code. */ 271bb46afd6c44a847efe96e30d72708fd2d0906e8cElliott Hughesextern void __sinit(void); // Not actually implemented. 272bb46afd6c44a847efe96e30d72708fd2d0906e8cElliott Hughes#define __sdidinit 1 273bb46afd6c44a847efe96e30d72708fd2d0906e8cElliott Hughes 2742899de9b05f15e67966ed3d046709b48703a162aElliott Hughes#pragma GCC visibility pop 275c48c3e4bb3d1665f3e9fa2785daafa72dfe59399Elliott Hughes 276c48c3e4bb3d1665f3e9fa2785daafa72dfe59399Elliott Hughes__END_DECLS 277f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes 278f0141dfab10a4b332769d52fa76631a64741297aElliott Hughes#endif 279