annotate IM_AF Encoder/stdio.h @ 8:c51c0b844461 tip

Ok
author Eugenio Oñate Hospital <eo301@eecs.qmul.ac.uk>
date Tue, 28 Aug 2012 12:20:04 +0100
parents 138a3cea9792
children
rev   line source
eo301@0 1 /*-
eo301@0 2 * Copyright (c) 1990, 1993
eo301@0 3 * The Regents of the University of California. All rights reserved.
eo301@0 4 *
eo301@0 5 * This code is derived from software contributed to Berkeley by
eo301@0 6 * Chris Torek.
eo301@0 7 *
eo301@0 8 * Redistribution and use in source and binary forms, with or without
eo301@0 9 * modification, are permitted provided that the following conditions
eo301@0 10 * are met:
eo301@0 11 * 1. Redistributions of source code must retain the above copyright
eo301@0 12 * notice, this list of conditions and the following disclaimer.
eo301@0 13 * 2. Redistributions in binary form must reproduce the above copyright
eo301@0 14 * notice, this list of conditions and the following disclaimer in the
eo301@0 15 * documentation and/or other materials provided with the distribution.
eo301@0 16 * 3. All advertising materials mentioning features or use of this software
eo301@0 17 * must display the following acknowledgement:
eo301@0 18 * This product includes software developed by the University of
eo301@0 19 * California, Berkeley and its contributors.
eo301@0 20 * 4. Neither the name of the University nor the names of its contributors
eo301@0 21 * may be used to endorse or promote products derived from this software
eo301@0 22 * without specific prior written permission.
eo301@0 23 *
eo301@0 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
eo301@0 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
eo301@0 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
eo301@0 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
eo301@0 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
eo301@0 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
eo301@0 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
eo301@0 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
eo301@0 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
eo301@0 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
eo301@0 34 * SUCH DAMAGE.
eo301@0 35 *
eo301@0 36 * @(#)stdio.h 8.5 (Berkeley) 4/29/95
eo301@0 37 * $FreeBSD$
eo301@0 38 */
eo301@0 39
eo301@0 40 #ifndef _STDIO_H_
eo301@0 41 #define _STDIO_H_
eo301@0 42
eo301@0 43 #include <sys/cdefs.h>
eo301@0 44 #include <sys/_null.h>
eo301@0 45 #include <sys/_types.h>
eo301@0 46
eo301@0 47 typedef __off_t fpos_t;
eo301@0 48
eo301@0 49 #ifndef _SIZE_T_DECLARED
eo301@0 50 typedef __size_t size_t;
eo301@0 51 #define _SIZE_T_DECLARED
eo301@0 52 #endif
eo301@0 53
eo301@0 54 #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809
eo301@0 55 #ifndef _OFF_T_DECLARED
eo301@0 56 #define _OFF_T_DECLARED
eo301@0 57 typedef __off_t off_t;
eo301@0 58 #endif
eo301@0 59 #ifndef _SSIZE_T_DECLARED
eo301@0 60 #define _SSIZE_T_DECLARED
eo301@0 61 typedef __ssize_t ssize_t;
eo301@0 62 #endif
eo301@0 63 #endif
eo301@0 64
eo301@0 65 #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 || __XSI_VISIBLE
eo301@0 66 #ifndef _VA_LIST_DECLARED
eo301@0 67 typedef __va_list va_list;
eo301@0 68 #define _VA_LIST_DECLARED
eo301@0 69 #endif
eo301@0 70 #endif
eo301@0 71
eo301@0 72 #define _FSTDIO /* Define for new stdio with functions. */
eo301@0 73
eo301@0 74 /*
eo301@0 75 * NB: to fit things in six character monocase externals, the stdio
eo301@0 76 * code uses the prefix `__s' for stdio objects, typically followed
eo301@0 77 * by a three-character attempt at a mnemonic.
eo301@0 78 */
eo301@0 79
eo301@0 80 /* stdio buffers */
eo301@0 81 struct __sbuf {
eo301@0 82 unsigned char *_base;
eo301@0 83 int _size;
eo301@0 84 };
eo301@0 85
eo301@0 86 /*
eo301@0 87 * stdio state variables.
eo301@0 88 *
eo301@0 89 * The following always hold:
eo301@0 90 *
eo301@0 91 * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
eo301@0 92 * _lbfsize is -_bf._size, else _lbfsize is 0
eo301@0 93 * if _flags&__SRD, _w is 0
eo301@0 94 * if _flags&__SWR, _r is 0
eo301@0 95 *
eo301@0 96 * This ensures that the getc and putc macros (or inline functions) never
eo301@0 97 * try to write or read from a file that is in `read' or `write' mode.
eo301@0 98 * (Moreover, they can, and do, automatically switch from read mode to
eo301@0 99 * write mode, and back, on "r+" and "w+" files.)
eo301@0 100 *
eo301@0 101 * _lbfsize is used only to make the inline line-buffered output stream
eo301@0 102 * code as compact as possible.
eo301@0 103 *
eo301@0 104 * _ub, _up, and _ur are used when ungetc() pushes back more characters
eo301@0 105 * than fit in the current _bf, or when ungetc() pushes back a character
eo301@0 106 * that does not match the previous one in _bf. When this happens,
eo301@0 107 * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff
eo301@0 108 * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.
eo301@0 109 *
eo301@0 110 * Certain members of __sFILE are accessed directly via macros or
eo301@0 111 * inline functions. To preserve ABI compat, these members must not
eo301@0 112 * be disturbed. These members are marked below with (*).
eo301@0 113 */
eo301@0 114 typedef struct __sFILE {
eo301@0 115 unsigned char *_p; /* (*) current position in (some) buffer */
eo301@0 116 int _r; /* (*) read space left for getc() */
eo301@0 117 int _w; /* (*) write space left for putc() */
eo301@0 118 short _flags; /* (*) flags, below; this FILE is free if 0 */
eo301@0 119 short _file; /* (*) fileno, if Unix descriptor, else -1 */
eo301@0 120 struct __sbuf _bf; /* (*) the buffer (at least 1 byte, if !NULL) */
eo301@0 121 int _lbfsize; /* (*) 0 or -_bf._size, for inline putc */
eo301@0 122
eo301@0 123 /* operations */
eo301@0 124 void *_cookie; /* (*) cookie passed to io functions */
eo301@0 125 int (*_close)(void *);
eo301@0 126 int (*_read)(void *, char *, int);
eo301@0 127 fpos_t (*_seek)(void *, fpos_t, int);
eo301@0 128 int (*_write)(void *, const char *, int);
eo301@0 129
eo301@0 130 /* separate buffer for long sequences of ungetc() */
eo301@0 131 struct __sbuf _ub; /* ungetc buffer */
eo301@0 132 unsigned char *_up; /* saved _p when _p is doing ungetc data */
eo301@0 133 int _ur; /* saved _r when _r is counting ungetc data */
eo301@0 134
eo301@0 135 /* tricks to meet minimum requirements even when malloc() fails */
eo301@0 136 unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */
eo301@0 137 unsigned char _nbuf[1]; /* guarantee a getc() buffer */
eo301@0 138
eo301@0 139 /* separate buffer for fgetln() when line crosses buffer boundary */
eo301@0 140 struct __sbuf _lb; /* buffer for fgetln() */
eo301@0 141
eo301@0 142 /* Unix stdio files get aligned to block boundaries on fseek() */
eo301@0 143 int _blksize; /* stat.st_blksize (may be != _bf._size) */
eo301@0 144 fpos_t _offset; /* current lseek offset */
eo301@0 145
eo301@0 146 struct pthread_mutex *_fl_mutex; /* used for MT-safety */
eo301@0 147 struct pthread *_fl_owner; /* current owner */
eo301@0 148 int _fl_count; /* recursive lock count */
eo301@0 149 int _orientation; /* orientation for fwide() */
eo301@0 150 __mbstate_t _mbstate; /* multibyte conversion state */
eo301@0 151 } FILE;
eo301@0 152
eo301@0 153 #ifndef _STDSTREAM_DECLARED
eo301@0 154 __BEGIN_DECLS
eo301@0 155 extern FILE *__stdinp;
eo301@0 156 extern FILE *__stdoutp;
eo301@0 157 extern FILE *__stderrp;
eo301@0 158 __END_DECLS
eo301@0 159 #define _STDSTREAM_DECLARED
eo301@0 160 #endif
eo301@0 161
eo301@0 162 #define __SLBF 0x0001 /* line buffered */
eo301@0 163 #define __SNBF 0x0002 /* unbuffered */
eo301@0 164 #define __SRD 0x0004 /* OK to read */
eo301@0 165 #define __SWR 0x0008 /* OK to write */
eo301@0 166 /* RD and WR are never simultaneously asserted */
eo301@0 167 #define __SRW 0x0010 /* open for reading & writing */
eo301@0 168 #define __SEOF 0x0020 /* found EOF */
eo301@0 169 #define __SERR 0x0040 /* found error */
eo301@0 170 #define __SMBF 0x0080 /* _buf is from malloc */
eo301@0 171 #define __SAPP 0x0100 /* fdopen()ed in append mode */
eo301@0 172 #define __SSTR 0x0200 /* this is an sprintf/snprintf string */
eo301@0 173 #define __SOPT 0x0400 /* do fseek() optimization */
eo301@0 174 #define __SNPT 0x0800 /* do not do fseek() optimization */
eo301@0 175 #define __SOFF 0x1000 /* set iff _offset is in fact correct */
eo301@0 176 #define __SMOD 0x2000 /* true => fgetln modified _p text */
eo301@0 177 #define __SALC 0x4000 /* allocate string space dynamically */
eo301@0 178 #define __SIGN 0x8000 /* ignore this file in _fwalk */
eo301@0 179
eo301@0 180 /*
eo301@0 181 * The following three definitions are for ANSI C, which took them
eo301@0 182 * from System V, which brilliantly took internal interface macros and
eo301@0 183 * made them official arguments to setvbuf(), without renaming them.
eo301@0 184 * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
eo301@0 185 *
eo301@0 186 * Although numbered as their counterparts above, the implementation
eo301@0 187 * does not rely on this.
eo301@0 188 */
eo301@0 189 #define _IOFBF 0 /* setvbuf should set fully buffered */
eo301@0 190 #define _IOLBF 1 /* setvbuf should set line buffered */
eo301@0 191 #define _IONBF 2 /* setvbuf should set unbuffered */
eo301@0 192
eo301@0 193 #define BUFSIZ 1024 /* size of buffer used by setbuf */
eo301@0 194 #define EOF (-1)
eo301@0 195
eo301@0 196 /*
eo301@0 197 * FOPEN_MAX is a minimum maximum, and is the number of streams that
eo301@0 198 * stdio can provide without attempting to allocate further resources
eo301@0 199 * (which could fail). Do not use this for anything.
eo301@0 200 */
eo301@0 201 /* must be == _POSIX_STREAM_MAX <limits.h> */
eo301@0 202 #ifndef FOPEN_MAX
eo301@0 203 #define FOPEN_MAX 20 /* must be <= OPEN_MAX <sys/syslimits.h> */
eo301@0 204 #endif
eo301@0 205 #define FILENAME_MAX 1024 /* must be <= PATH_MAX <sys/syslimits.h> */
eo301@0 206
eo301@0 207 /* System V/ANSI C; this is the wrong way to do this, do *not* use these. */
eo301@0 208 #if __XSI_VISIBLE
eo301@0 209 #define P_tmpdir "/var/tmp/"
eo301@0 210 #endif
eo301@0 211 #define L_tmpnam 1024 /* XXX must be == PATH_MAX */
eo301@0 212 #define TMP_MAX 308915776
eo301@0 213
eo301@0 214 #ifndef SEEK_SET
eo301@0 215 #define SEEK_SET 0 /* set file offset to offset */
eo301@0 216 #endif
eo301@0 217 #ifndef SEEK_CUR
eo301@0 218 #define SEEK_CUR 1 /* set file offset to current plus offset */
eo301@0 219 #endif
eo301@0 220 #ifndef SEEK_END
eo301@0 221 #define SEEK_END 2 /* set file offset to EOF plus offset */
eo301@0 222 #endif
eo301@0 223
eo301@0 224 #define stdin __stdinp
eo301@0 225 #define stdout __stdoutp
eo301@0 226 #define stderr __stderrp
eo301@0 227
eo301@0 228 __BEGIN_DECLS
eo301@0 229 /*
eo301@0 230 * Functions defined in ANSI C standard.
eo301@0 231 */
eo301@0 232 void clearerr(FILE *);
eo301@0 233 int fclose(FILE *);
eo301@0 234 int feof(FILE *);
eo301@0 235 int ferror(FILE *);
eo301@0 236 int fflush(FILE *);
eo301@0 237 int fgetc(FILE *);
eo301@0 238 int fgetpos(FILE * __restrict, fpos_t * __restrict);
eo301@0 239 char *fgets(char * __restrict, int, FILE * __restrict);
eo301@0 240 FILE *fopen(const char * __restrict, const char * __restrict);
eo301@0 241 int fprintf(FILE * __restrict, const char * __restrict, ...);
eo301@0 242 int fputc(int, FILE *);
eo301@0 243 int fputs(const char * __restrict, FILE * __restrict);
eo301@0 244 size_t fread(void * __restrict, size_t, size_t, FILE * __restrict);
eo301@0 245 FILE *freopen(const char * __restrict, const char * __restrict, FILE * __restrict);
eo301@0 246 int fscanf(FILE * __restrict, const char * __restrict, ...);
eo301@0 247 int fseek(FILE *, long, int);
eo301@0 248 int fsetpos(FILE *, const fpos_t *);
eo301@0 249 long ftell(FILE *);
eo301@0 250 size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict);
eo301@0 251 int getc(FILE *);
eo301@0 252 int getchar(void);
eo301@0 253 char *gets(char *);
eo301@0 254 void perror(const char *);
eo301@0 255 int printf(const char * __restrict, ...);
eo301@0 256 int putc(int, FILE *);
eo301@0 257 int putchar(int);
eo301@0 258 int puts(const char *);
eo301@0 259 int remove(const char *);
eo301@0 260 int rename(const char *, const char *);
eo301@0 261 void rewind(FILE *);
eo301@0 262 int scanf(const char * __restrict, ...);
eo301@0 263 void setbuf(FILE * __restrict, char * __restrict);
eo301@0 264 int setvbuf(FILE * __restrict, char * __restrict, int, size_t);
eo301@0 265 int sprintf(char * __restrict, const char * __restrict, ...);
eo301@0 266 int sscanf(const char * __restrict, const char * __restrict, ...);
eo301@0 267 FILE *tmpfile(void);
eo301@0 268 char *tmpnam(char *);
eo301@0 269 int ungetc(int, FILE *);
eo301@0 270 int vfprintf(FILE * __restrict, const char * __restrict,
eo301@0 271 __va_list);
eo301@0 272 int vprintf(const char * __restrict, __va_list);
eo301@0 273 int vsprintf(char * __restrict, const char * __restrict,
eo301@0 274 __va_list);
eo301@0 275
eo301@0 276 #if __ISO_C_VISIBLE >= 1999
eo301@0 277 int snprintf(char * __restrict, size_t, const char * __restrict,
eo301@0 278 ...) __printflike(3, 4);
eo301@0 279 int vfscanf(FILE * __restrict, const char * __restrict, __va_list)
eo301@0 280 __scanflike(2, 0);
eo301@0 281 int vscanf(const char * __restrict, __va_list) __scanflike(1, 0);
eo301@0 282 int vsnprintf(char * __restrict, size_t, const char * __restrict,
eo301@0 283 __va_list) __printflike(3, 0);
eo301@0 284 int vsscanf(const char * __restrict, const char * __restrict, __va_list)
eo301@0 285 __scanflike(2, 0);
eo301@0 286 #endif
eo301@0 287
eo301@0 288 /*
eo301@0 289 * Functions defined in all versions of POSIX 1003.1.
eo301@0 290 */
eo301@0 291 #if __BSD_VISIBLE || __POSIX_VISIBLE <= 199506
eo301@0 292 /* size for cuserid(3); UT_NAMESIZE + 1, see <utmp.h> */
eo301@0 293 #define L_cuserid 17 /* legacy */
eo301@0 294 #endif
eo301@0 295
eo301@0 296 #if __POSIX_VISIBLE
eo301@0 297 #define L_ctermid 1024 /* size for ctermid(3); PATH_MAX */
eo301@0 298
eo301@0 299 char *ctermid(char *);
eo301@0 300 FILE *fdopen(int, const char *);
eo301@0 301 int fileno(FILE *);
eo301@0 302 #endif /* __POSIX_VISIBLE */
eo301@0 303
eo301@0 304 #if __POSIX_VISIBLE >= 199209
eo301@0 305 int pclose(FILE *);
eo301@0 306 FILE *popen(const char *, const char *);
eo301@0 307 #endif
eo301@0 308
eo301@0 309 #if __POSIX_VISIBLE >= 199506
eo301@0 310 int ftrylockfile(FILE *);
eo301@0 311 void flockfile(FILE *);
eo301@0 312 void funlockfile(FILE *);
eo301@0 313
eo301@0 314 /*
eo301@0 315 * These are normally used through macros as defined below, but POSIX
eo301@0 316 * requires functions as well.
eo301@0 317 */
eo301@0 318 int getc_unlocked(FILE *);
eo301@0 319 int getchar_unlocked(void);
eo301@0 320 int putc_unlocked(int, FILE *);
eo301@0 321 int putchar_unlocked(int);
eo301@0 322 #endif
eo301@0 323 #if __BSD_VISIBLE
eo301@0 324 void clearerr_unlocked(FILE *);
eo301@0 325 int feof_unlocked(FILE *);
eo301@0 326 int ferror_unlocked(FILE *);
eo301@0 327 int fileno_unlocked(FILE *);
eo301@0 328 #endif
eo301@0 329
eo301@0 330 #if __POSIX_VISIBLE >= 200112
eo301@0 331 int fseeko(FILE *, __off_t, int);
eo301@0 332 __off_t ftello(FILE *);
eo301@0 333 #endif
eo301@0 334
eo301@0 335 #if __BSD_VISIBLE || __XSI_VISIBLE > 0 && __XSI_VISIBLE < 600
eo301@0 336 int getw(FILE *);
eo301@0 337 int putw(int, FILE *);
eo301@0 338 #endif /* BSD or X/Open before issue 6 */
eo301@0 339
eo301@0 340 #if __XSI_VISIBLE
eo301@0 341 char *tempnam(const char *, const char *);
eo301@0 342 #endif
eo301@0 343
eo301@0 344 #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809
eo301@0 345 ssize_t getdelim(char ** __restrict, size_t * __restrict, int,
eo301@0 346 FILE * __restrict);
eo301@0 347 int renameat(int, const char *, int, const char *);
eo301@0 348 int vdprintf(int, const char * __restrict, __va_list);
eo301@0 349
eo301@0 350 /*
eo301@0 351 * Every programmer and his dog wrote functions called getline() and dprintf()
eo301@0 352 * before POSIX.1-2008 came along and decided to usurp the names, so we
eo301@0 353 * don't prototype them by default unless one of the following is true:
eo301@0 354 * a) the app has requested them specifically by defining _WITH_GETLINE or
eo301@0 355 * _WITH_DPRINTF, respectively
eo301@0 356 * b) the app has requested a POSIX.1-2008 environment via _POSIX_C_SOURCE
eo301@0 357 * c) the app defines a GNUism such as _BSD_SOURCE or _GNU_SOURCE
eo301@0 358 */
eo301@0 359 #ifndef _WITH_GETLINE
eo301@0 360 #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
eo301@0 361 #define _WITH_GETLINE
eo301@0 362 #elif defined(_POSIX_C_SOURCE)
eo301@0 363 #if _POSIX_C_SOURCE >= 200809
eo301@0 364 #define _WITH_GETLINE
eo301@0 365 #endif
eo301@0 366 #endif
eo301@0 367 #endif
eo301@0 368
eo301@0 369 #ifdef _WITH_GETLINE
eo301@0 370 ssize_t getline(char ** __restrict, size_t * __restrict, FILE * __restrict);
eo301@0 371 #endif
eo301@0 372
eo301@0 373 #ifndef _WITH_DPRINTF
eo301@0 374 #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
eo301@0 375 #define _WITH_DPRINTF
eo301@0 376 #elif defined(_POSIX_C_SOURCE)
eo301@0 377 #if _POSIX_C_SOURCE >= 200809
eo301@0 378 #define _WITH_DPRINTF
eo301@0 379 #endif
eo301@0 380 #endif
eo301@0 381 #endif
eo301@0 382
eo301@0 383 #ifdef _WITH_DPRINTF
eo301@0 384 int (dprintf)(int, const char * __restrict, ...);
eo301@0 385 #endif
eo301@0 386
eo301@0 387 #endif /* __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 */
eo301@0 388
eo301@0 389 /*
eo301@0 390 * Routines that are purely local.
eo301@0 391 */
eo301@0 392 #if __BSD_VISIBLE
eo301@0 393 int asprintf(char **, const char *, ...) __printflike(2, 3);
eo301@0 394 char *ctermid_r(char *);
eo301@0 395 void fcloseall(void);
eo301@0 396 char *fgetln(FILE *, size_t *);
eo301@0 397 const char *fmtcheck(const char *, const char *) __format_arg(2);
eo301@0 398 int fpurge(FILE *);
eo301@0 399 void setbuffer(FILE *, char *, int);
eo301@0 400 int setlinebuf(FILE *);
eo301@0 401 int vasprintf(char **, const char *, __va_list)
eo301@0 402 __printflike(2, 0);
eo301@0 403
eo301@0 404 /*
eo301@0 405 * The system error table contains messages for the first sys_nerr
eo301@0 406 * positive errno values. Use strerror() or strerror_r() from <string.h>
eo301@0 407 * instead.
eo301@0 408 */
eo301@0 409 extern __const int sys_nerr;
eo301@0 410 extern __const char *__const sys_errlist[];
eo301@0 411
eo301@0 412 /*
eo301@0 413 * Stdio function-access interface.
eo301@0 414 */
eo301@0 415 FILE *funopen(const void *,
eo301@0 416 int (*)(void *, char *, int),
eo301@0 417 int (*)(void *, const char *, int),
eo301@0 418 fpos_t (*)(void *, fpos_t, int),
eo301@0 419 int (*)(void *));
eo301@0 420 #define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
eo301@0 421 #define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
eo301@0 422
eo301@0 423 /*
eo301@0 424 * Portability hacks. See <sys/types.h>.
eo301@0 425 */
eo301@0 426 #ifndef _FTRUNCATE_DECLARED
eo301@0 427 #define _FTRUNCATE_DECLARED
eo301@0 428 int ftruncate(int, __off_t);
eo301@0 429 #endif
eo301@0 430 #ifndef _LSEEK_DECLARED
eo301@0 431 #define _LSEEK_DECLARED
eo301@0 432 __off_t lseek(int, __off_t, int);
eo301@0 433 #endif
eo301@0 434 #ifndef _MMAP_DECLARED
eo301@0 435 #define _MMAP_DECLARED
eo301@0 436 void *mmap(void *, size_t, int, int, int, __off_t);
eo301@0 437 #endif
eo301@0 438 #ifndef _TRUNCATE_DECLARED
eo301@0 439 #define _TRUNCATE_DECLARED
eo301@0 440 int truncate(const char *, __off_t);
eo301@0 441 #endif
eo301@0 442 #endif /* __BSD_VISIBLE */
eo301@0 443
eo301@0 444 /*
eo301@0 445 * Functions internal to the implementation.
eo301@0 446 */
eo301@0 447 int __srget(FILE *);
eo301@0 448 int __swbuf(int, FILE *);
eo301@0 449
eo301@0 450 /*
eo301@0 451 * The __sfoo macros are here so that we can
eo301@0 452 * define function versions in the C library.
eo301@0 453 */
eo301@0 454 #define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
eo301@0 455 #if defined(__GNUC__) && defined(__STDC__)
eo301@0 456 static __inline int __sputc(int _c, FILE *_p) {
eo301@0 457 if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
eo301@0 458 return (*_p->_p++ = _c);
eo301@0 459 else
eo301@0 460 return (__swbuf(_c, _p));
eo301@0 461 }
eo301@0 462 #else
eo301@0 463 /*
eo301@0 464 * This has been tuned to generate reasonable code on the vax using pcc.
eo301@0 465 */
eo301@0 466 #define __sputc(c, p) \
eo301@0 467 (--(p)->_w < 0 ? \
eo301@0 468 (p)->_w >= (p)->_lbfsize ? \
eo301@0 469 (*(p)->_p = (c)), *(p)->_p != '\n' ? \
eo301@0 470 (int)*(p)->_p++ : \
eo301@0 471 __swbuf('\n', p) : \
eo301@0 472 __swbuf((int)(c), p) : \
eo301@0 473 (*(p)->_p = (c), (int)*(p)->_p++))
eo301@0 474 #endif
eo301@0 475
eo301@0 476 #define __sfeof(p) (((p)->_flags & __SEOF) != 0)
eo301@0 477 #define __sferror(p) (((p)->_flags & __SERR) != 0)
eo301@0 478 #define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF)))
eo301@0 479 #define __sfileno(p) ((p)->_file)
eo301@0 480
eo301@0 481 extern int __isthreaded;
eo301@0 482
eo301@0 483 #define feof(p) (!__isthreaded ? __sfeof(p) : (feof)(p))
eo301@0 484 #define ferror(p) (!__isthreaded ? __sferror(p) : (ferror)(p))
eo301@0 485 #define clearerr(p) (!__isthreaded ? __sclearerr(p) : (clearerr)(p))
eo301@0 486
eo301@0 487 #if __POSIX_VISIBLE
eo301@0 488 #define fileno(p) (!__isthreaded ? __sfileno(p) : (fileno)(p))
eo301@0 489 #endif
eo301@0 490
eo301@0 491 #define getc(fp) (!__isthreaded ? __sgetc(fp) : (getc)(fp))
eo301@0 492 #define putc(x, fp) (!__isthreaded ? __sputc(x, fp) : (putc)(x, fp))
eo301@0 493
eo301@0 494 #define getchar() getc(stdin)
eo301@0 495 #define putchar(x) putc(x, stdout)
eo301@0 496
eo301@0 497 #if __BSD_VISIBLE
eo301@0 498 /*
eo301@0 499 * See ISO/IEC 9945-1 ANSI/IEEE Std 1003.1 Second Edition 1996-07-12
eo301@0 500 * B.8.2.7 for the rationale behind the *_unlocked() macros.
eo301@0 501 */
eo301@0 502 #define feof_unlocked(p) __sfeof(p)
eo301@0 503 #define ferror_unlocked(p) __sferror(p)
eo301@0 504 #define clearerr_unlocked(p) __sclearerr(p)
eo301@0 505 #define fileno_unlocked(p) __sfileno(p)
eo301@0 506 #endif
eo301@0 507 #if __POSIX_VISIBLE >= 199506
eo301@0 508 #define getc_unlocked(fp) __sgetc(fp)
eo301@0 509 #define putc_unlocked(x, fp) __sputc(x, fp)
eo301@0 510
eo301@0 511 #define getchar_unlocked() getc_unlocked(stdin)
eo301@0 512 #define putchar_unlocked(x) putc_unlocked(x, stdout)
eo301@0 513 #endif
eo301@0 514
eo301@0 515 __END_DECLS
eo301@0 516 #endif /* !_STDIO_H_ */