[BACK]Return to stdio.h CVS log [TXT][DIR] Up to [local] / prex-old / usr / include

Annotation of prex-old/usr/include/stdio.h, Revision 1.1.1.1

1.1       nbrk        1: /*-
                      2:  * Copyright (c) 1990, 1993
                      3:  *     The Regents of the University of California.  All rights reserved.
                      4:  *
                      5:  * This code is derived from software contributed to Berkeley by
                      6:  * Chris Torek.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
                     16:  * 3. Neither the name of the University nor the names of its contributors
                     17:  *    may be used to endorse or promote products derived from this software
                     18:  *    without specific prior written permission.
                     19:  *
                     20:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     21:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     22:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     23:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     24:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     25:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     26:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     27:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     28:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     29:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     30:  * SUCH DAMAGE.
                     31:  *
                     32:  *     @(#)stdio.h     8.5 (Berkeley) 4/29/95
                     33:  */
                     34:
                     35: #ifndef        _STDIO_H_
                     36: #define        _STDIO_H_
                     37:
                     38: #include <sys/types.h>
                     39: #include <sys/cdefs.h>
                     40:
                     41: #include <machine/ansi.h>
                     42: #ifdef _BSD_SIZE_T_
                     43: typedef        _BSD_SIZE_T_    size_t;
                     44: #undef _BSD_SIZE_T_
                     45: #endif
                     46:
                     47: #include <sys/null.h>
                     48:
                     49: typedef off_t fpos_t;
                     50:
                     51: #define        _FSTDIO                 /* Define for new stdio with functions. */
                     52:
                     53: /*
                     54:  * NB: to fit things in six character monocase externals, the stdio
                     55:  * code uses the prefix `__s' for stdio objects, typically followed
                     56:  * by a three-character attempt at a mnemonic.
                     57:  */
                     58:
                     59: /* stdio buffers */
                     60: struct __sbuf {
                     61:        unsigned char *_base;
                     62:        int     _size;
                     63: };
                     64:
                     65: /*
                     66:  * stdio state variables.
                     67:  *
                     68:  * The following always hold:
                     69:  *
                     70:  *     if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
                     71:  *             _lbfsize is -_bf._size, else _lbfsize is 0
                     72:  *     if _flags&__SRD, _w is 0
                     73:  *     if _flags&__SWR, _r is 0
                     74:  *
                     75:  * This ensures that the getc and putc macros (or inline functions) never
                     76:  * try to write or read from a file that is in `read' or `write' mode.
                     77:  * (Moreover, they can, and do, automatically switch from read mode to
                     78:  * write mode, and back, on "r+" and "w+" files.)
                     79:  *
                     80:  * _lbfsize is used only to make the inline line-buffered output stream
                     81:  * code as compact as possible.
                     82:  *
                     83:  * _ub, _up, and _ur are used when ungetc() pushes back more characters
                     84:  * than fit in the current _bf, or when ungetc() pushes back a character
                     85:  * that does not match the previous one in _bf.  When this happens,
                     86:  * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff
                     87:  * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.
                     88:  *
                     89:  * NB: see WARNING above before changing the layout of this structure!
                     90:  */
                     91: typedef        struct __sFILE {
                     92:        struct __sFILE *next;   /* file chain */
                     93:        unsigned char *_p;      /* current position in (some) buffer */
                     94:        int     _r;             /* read space left for getc() */
                     95:        int     _w;             /* write space left for putc() */
                     96:        short   _flags;         /* flags, below; this FILE is free if 0 */
                     97:        short   _file;          /* fileno, if Unix descriptor, else -1 */
                     98:        struct  __sbuf _bf;     /* the buffer (at least 1 byte, if !NULL) */
                     99:
                    100:        /* separate buffer for long sequences of ungetc() */
                    101:        struct  __sbuf _ub;     /* ungetc buffer */
                    102:        unsigned char *_up;     /* saved _p when _p is doing ungetc data */
                    103:        int     _ur;            /* saved _r when _r is counting ungetc data */
                    104:
                    105:        /* tricks to meet minimum requirements even when malloc() fails */
                    106:        unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */
                    107:        unsigned char _nbuf[1]; /* guarantee a getc() buffer */
                    108: } FILE;
                    109:
                    110: __BEGIN_DECLS
                    111: extern FILE __sF[];
                    112: __END_DECLS
                    113:
                    114: #define        __SLBF  0x0001          /* line buffered */
                    115: #define        __SNBF  0x0002          /* unbuffered */
                    116: #define        __SRD   0x0004          /* OK to read */
                    117: #define        __SWR   0x0008          /* OK to write */
                    118:        /* RD and WR are never simultaneously asserted */
                    119: #define        __SRW   0x0010          /* open for reading & writing */
                    120: #define        __SEOF  0x0020          /* found EOF */
                    121: #define        __SERR  0x0040          /* found error */
                    122: #define        __SMBF  0x0080          /* _buf is from malloc */
                    123: #define        __SAPP  0x0100          /* fdopen()ed in append mode */
                    124: #define        __SSTR  0x0200          /* this is an sprintf/snprintf string */
                    125:
                    126: /*
                    127:  * The following three definitions are for ANSI C, which took them
                    128:  * from System V, which brilliantly took internal interface macros and
                    129:  * made them official arguments to setvbuf(), without renaming them.
                    130:  * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
                    131:  *
                    132:  * Although numbered as their counterparts above, the implementation
                    133:  * does not rely on this.
                    134:  */
                    135: #define        _IOFBF  0               /* setvbuf should set fully buffered */
                    136: #define        _IOLBF  1               /* setvbuf should set line buffered */
                    137: #define        _IONBF  2               /* setvbuf should set unbuffered */
                    138:
                    139: #define        BUFSIZ  512             /* size of buffer used by setbuf */
                    140: #define        EOF     (-1)
                    141:
                    142: /*
                    143:  * FOPEN_MAX is a minimum maximum, and is the number of streams that
                    144:  * stdio can provide without attempting to allocate further resources
                    145:  * (which could fail).  Do not use this for anything.
                    146:  */
                    147:                                /* must be == _POSIX_STREAM_MAX <limits.h> */
                    148: #define        FOPEN_MAX       16      /* must be <= OPEN_MAX <sys/syslimits.h> */
                    149: #define        FILENAME_MAX    256     /* must be <= PATH_MAX <sys/syslimits.h> */
                    150:
                    151: /* System V/ANSI C; this is the wrong way to do this, do *not* use these. */
                    152: #ifndef _ANSI_SOURCE
                    153: #define        P_tmpdir        "/var/tmp/"
                    154: #endif
                    155: #define        L_tmpnam        255     /* XXX must be == PATH_MAX */
                    156: #define        TMP_MAX         308915776
                    157:
                    158: /* access function */
                    159: #define        F_OK            0       /* test for existence of file */
                    160: #define        X_OK            0x01    /* test for execute or search permission */
                    161: #define        W_OK            0x02    /* test for write permission */
                    162: #define        R_OK            0x04    /* test for read permission */
                    163:
                    164: /* whence values for lseek(2) */
                    165: #define        SEEK_SET        0       /* set file offset to offset */
                    166: #define        SEEK_CUR        1       /* set file offset to current plus offset */
                    167: #define        SEEK_END        2       /* set file offset to EOF plus offset */
                    168:
                    169: #define        stdin   (&__sF[0])
                    170: #define        stdout  (&__sF[1])
                    171: #define        stderr  (&__sF[2])
                    172:
                    173: /*
                    174:  * Functions defined in ANSI C standard.
                    175:  */
                    176: __BEGIN_DECLS
                    177: void    clearerr(FILE *);
                    178: int     fclose(FILE *);
                    179: int     feof(FILE *);
                    180: int     ferror(FILE *);
                    181: int     fflush(FILE *);
                    182: int     fgetc(FILE *);
                    183: int     fgetpos(FILE *, fpos_t *);
                    184: char   *fgets(char *, size_t, FILE *);
                    185: FILE   *fopen(const char *, const char *);
                    186: int     fprintf(FILE *, const char *, ...);
                    187: int     fputc(int, FILE *);
                    188: int     fputs(const char *, FILE *);
                    189: size_t  fread(void *, size_t, size_t, FILE *);
                    190: FILE   *freopen(const char *, const char *, FILE *);
                    191: int     fscanf(FILE *, const char *, ...);
                    192: int     fseek(FILE *, long, int);
                    193: int     fsetpos(FILE *, const fpos_t *);
                    194: long    ftell(FILE *);
                    195: size_t  fwrite(const void *, size_t, size_t, FILE *);
                    196: int     getc(FILE *);
                    197: int     getchar(void);
                    198: char   *gets(char *);
                    199: #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
                    200: extern const int _sys_nerr;                    /* perror(3) external variables */
                    201: extern const char *const _sys_errlist[];
                    202: #endif
                    203: void    perror(const char *);
                    204: int     printf(const char *, ...);
                    205: int     putc(int, FILE *);
                    206: int     putchar(int);
                    207: int     puts(const char *);
                    208: int     remove(const char *);
                    209: int     rename (const char *, const char *);
                    210: void    rewind(FILE *);
                    211: int     scanf(const char *, ...);
                    212: void    setbuf(FILE *, char *);
                    213: int     setvbuf(FILE *, char *, int, size_t);
                    214: int     sprintf(char *, const char *, ...);
                    215: int     sscanf(const char *, const char *, ...);
                    216: FILE   *tmpfile(void);
                    217: char   *tmpnam(char *);
                    218: int     ungetc(int, FILE *);
                    219: int     vfprintf(FILE *, const char *, _BSD_VA_LIST_);
                    220: int     vprintf(const char *, _BSD_VA_LIST_);
                    221: int     vsprintf(char *, const char *, _BSD_VA_LIST_);
                    222: __END_DECLS
                    223:
                    224: /*
                    225:  * Functions defined in POSIX 1003.1.
                    226:  */
                    227: #ifndef _ANSI_SOURCE
                    228: #define        L_cuserid       9       /* size for cuserid(); UT_NAMESIZE + 1 */
                    229: #define        L_ctermid       1024    /* size for ctermid(); PATH_MAX */
                    230:
                    231: __BEGIN_DECLS
                    232: char   *ctermid(char *);
                    233: FILE   *fdopen(int, const char *);
                    234: int     fileno(FILE *);
                    235: __END_DECLS
                    236: #endif /* not ANSI */
                    237:
                    238: /*
                    239:  * Routines that are purely local.
                    240:  */
                    241: #if !defined (_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
                    242: __BEGIN_DECLS
                    243: int     fpurge(FILE *);
                    244: int     getw(FILE *);
                    245: int     pclose(FILE *);
                    246: FILE   *popen(const char *, const char *);
                    247: int     putw(int, FILE *);
                    248: void    setbuffer(FILE *, char *, int);
                    249: int     setlinebuf(FILE *);
                    250: char   *tempnam(const char *, const char *);
                    251: int     snprintf(char *, size_t, const char *, ...);
                    252: int     vsnprintf(char *, size_t, const char *, _BSD_VA_LIST_);
                    253: int     vscanf(const char *, _BSD_VA_LIST_);
                    254: int     vsscanf(const char *, const char *, _BSD_VA_LIST_);
                    255: FILE   *zopen(const char *, const char *, int);
                    256: __END_DECLS
                    257:
                    258: /*
                    259:  * This is a #define because the function is used internally and
                    260:  * (unlike vfscanf) the name __svfscanf is guaranteed not to collide
                    261:  * with a user function when _ANSI_SOURCE or _POSIX_SOURCE is defined.
                    262:  */
                    263: #define         vfscanf        __svfscanf
                    264:
                    265: #endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */
                    266:
                    267: /*
                    268:  * Functions internal to the implementation.
                    269:  */
                    270: __BEGIN_DECLS
                    271: int    __srget(FILE *);
                    272: int    __svfscanf(FILE *, const char *, _BSD_VA_LIST_);
                    273: int    __swbuf(int, FILE *);
                    274: __END_DECLS
                    275:
                    276: /*
                    277:  * The __sfoo macros are here so that we can
                    278:  * define function versions in the C library.
                    279:  */
                    280:
                    281: #define        __sfeof(p)      (((p)->_flags & __SEOF) != 0)
                    282: #define        __sferror(p)    (((p)->_flags & __SERR) != 0)
                    283: #define        __sclearerr(p)  ((void)((p)->_flags &= ~(__SERR|__SEOF)))
                    284: #define        __sfileno(p)    ((p)->_file)
                    285:
                    286: #define        feof(p)         __sfeof(p)
                    287: #define        ferror(p)       __sferror(p)
                    288: #define        clearerr(p)     __sclearerr(p)
                    289:
                    290: #ifndef _ANSI_SOURCE
                    291: #define        fileno(p)       __sfileno(p)
                    292: #endif
                    293:
                    294: #endif /* _STDIO_H_ */

CVSweb