/* Copyright (c) 1993 Xerox Corporation. All rights reserved. */ /* $Id$ $Date$ */ /* Chauser, October 28, 1993 3:30 pm PDT */ /* * stdio.h -- * * This header file declares the stdio library facilities. They * provide a general stream facility and routines for formatted * input and output. * * Copyright 1986, 1988 Regents of the University of California * Permission to use, copy, modify, and distribute this * software and its documentation for any purpose and without * fee is hereby granted, provided that the above copyright * notice appear in all copies. The University of California * makes no representations about the suitability of this * software for any purpose. It is provided "as is" without * express or implied warranty. * * $Header: /sprite/src/lib/include/RCS/stdio.h,v 1.19 90/06/27 13:29:57 shirriff Exp $ SPRITE (Berkeley) */ /* * PCR stdio.h */ #ifndef ←←PCR←stdio←h #define ←←PCR←stdio←h #include <config/PCR←StdTypes.h> #include <stdarg.h> #include <stddef.h> #define FILE struct PCR←Stdio←StreamRep typedef unsigned long fpos←t; #ifndef EOF #define EOF (-1) #endif #ifndef NULL # error NULL not in stddef #endif /* * Mode for setvbuf: */ #define ←IOFBF 0 /* default must be 0 */ #define ←IOLBF 1 #define ←IONBF 2 /* * Relative position indicator for fseek: */ #ifndef SEEK←SET # define SEEK←SET 0 # define SEEK←CUR 1 # define SEEK←END 2 #endif /* * Directory for tmpnam */ #define P←tmpdir "/usr/tmp" /* * Limits */ #define BUFSIZ 4096 #define FOPEN←MAX 10 /* ??? */ #define FILENAME←MAX 1024 /* ??? */ #define TMP←MAX 1000 /* ??? */ #define L←tmpnam 48 /* * File operations (4.9.4) */ extern int PCR←remove(const char *filename); extern int PCR←rename(const char *old, const char *new); extern FILE *PCR←tmpfile(void); extern char *PCR←tmpnam(char *s); #ifndef PCR←NO←RENAME # undef remove # define remove PCR←remove # undef rename # define rename PCR←rename # undef tmpfile # define tmpfile PCR←tmpfile # undef tmpnam # define tmpnam PCR←tmpnam #endif /* !PCR←NO←RENAME */ /* * File access functions (4.9.5) */ extern int PCR←fclose(FILE *stream); extern int PCR←fflush(FILE *stream); extern FILE *PCR←fopen(const char *filename, const char *mode); extern FILE *PCR←freopen( const char *filename, const char *mode, FILE *stream); extern FILE *PCR←fdopen(int fd, const char *mode); /* not ANSI */ extern FILE *PCR←fdreopen(int fd, const char *mode, FILE *stream); /* not ANSI */ extern int PCR←fileno(FILE *stream); /* not ANSI */ extern void PCR←setbuf(FILE *stream, char *buf); extern int PCR←setvbuf(FILE *stream, char *buf, int mode, size←t size); #ifndef PCR←NO←RENAME # undef fclose # define fclose PCR←fclose # undef fflush # define fflush PCR←fflush # undef fopen # define fopen PCR←fopen # undef freopen # define freopen PCR←freopen # undef fdopen # define fdopen PCR←fdopen # undef fdreopen # define fdreopen PCR←fdreopen # undef fileno # define fileno PCR←fileno # undef setbuf # define setbuf PCR←setbuf # undef setvbuf # define setvbuf PCR←setvbuf #endif /* !PCR←NO←RENAME */ /* * Formatted input/output functions (4.9.6) */ extern int PCR←fprintf(FILE *stream, const char *format, ...); extern int PCR←fscanf(FILE *stream, const char *format, ...); extern int PCR←printf(const char *format, ...); extern int PCR←scanf(const char *format, ...); extern int PCR←sprintf(char *s, const char *format, ...); extern int PCR←sscanf(const char *s, const char *format, ...); extern int PCR←vfprintf(FILE *stream, const char *format, va←list arg); extern int PCR←vprintf(const char *format, va←list arg); extern int PCR←vsprintf(char *s, const char *format, va←list arg); extern int PCR←vfscanf(FILE *stream, const char *format, va←list arg); /* not ANSI */ #ifndef PCR←NO←RENAME # undef fprintf # define fprintf PCR←fprintf # undef fscanf # define fscanf PCR←fscanf # undef printf # define printf PCR←printf # undef scanf # define scanf PCR←scanf # undef sprintf # define sprintf PCR←sprintf # undef sscanf # define sscanf PCR←sscanf # undef vfprintf # define vfprintf PCR←vfprintf # undef vprintf # define vprintf PCR←vprintf # undef vsprintf # define vsprintf PCR←vsprintf # undef vfscanf # define vfscanf PCR←vfscanf #endif /* !PCR←NO←RENAME */ /* * Character input/output functions (4.9.7) */ extern int PCR←fgetc(FILE *stream); extern char * PCR←fgets(char *s, int n, FILE *stream); extern int PCR←fputc(int c, FILE *stream); extern int PCR←fputs(const char *s, FILE *stream); extern int PCR←getc(FILE *stream); #define PCR←getc(stream) PCR←Stdio←GetCMacro(stream) extern int PCR←getchar(void); #define PCR←getchar() PCR←getc(PCR←stdin) extern char * PCR←gets(char *s); extern int PCR←putc(int c, FILE *stream); #define PCR←putc(c,stream) PCR←Stdio←PutCMacro(c,stream) extern int PCR←putchar(int c); #define PCR←putchar(c) PCR←putc((c),PCR←stdout) extern int PCR←puts(const char *s); extern int PCR←ungetc(int c, FILE *stream); #ifndef PCR←NO←RENAME # undef fgetc # define fgetc PCR←fgetc # undef fgets # define fgets PCR←fgets # undef fputc # define fputc PCR←fputc # undef fputs # define fputs PCR←fputs # undef getc # define getc PCR←getc # undef getchar # define getchar PCR←getchar # undef gets # define gets PCR←gets # undef putc # define putc PCR←putc # undef putchar # define putchar PCR←putchar # undef puts # define puts PCR←puts # undef ungetc # define ungetc PCR←ungetc #endif /* !PCR←NO←RENAME */ /* * Direct input/output functions (4.9.8) */ extern size←t PCR←fread( void *ptr, size←t size, size←t nmemb, FILE *stream); extern size←t PCR←fwrite( const void *ptr, size←t size, size←t nmemb, FILE *stream); #ifndef PCR←NO←RENAME # undef fread # define fread PCR←fread # undef fwrite # define fwrite PCR←fwrite #endif /* !PCR←NO←RENAME */ /* * File positioning functions (4.9.9) */ extern int PCR←fgetpos(FILE *stream, fpos←t *pos); extern int PCR←fseek(FILE *stream, long offset, int whence); extern int PCR←fsetpos(FILE *stream, const fpos←t *fpos); extern long PCR←ftell(FILE *stream); extern void PCR←rewind(FILE *stream); #ifndef PCR←NO←RENAME # undef fgetpos # define fgetpos PCR←fgetpos # undef fseek # define fseek PCR←fseek # undef fsetpos # define fsetpos PCR←fsetpos # undef ftell # define ftell PCR←ftell # undef rewind # define rewind PCR←rewind #endif /* !PCR←NO←RENAME */ /* * Error handling functions (4.9.10) */ extern void PCR←clearerr(FILE *stream); extern void PCR←seterr(FILE *stream, int err); /* not ANSI */ extern int PCR←feof(FILE *stream); extern int PCR←ferror(FILE *stream); extern void PCR←perror(const char *s); #ifndef PCR←NO←RENAME # undef clearerr # define clearerr PCR←clearerr # undef seterr # define seterr PCR←seterr # undef feof # define feof PCR←feof # undef ferror # define ferror PCR←ferror # undef perror # define perror PCR←perror #endif /* !PCR←NO←RENAME */ /* ************************************************************************ * * Implementation details * ************************************************************************ */ struct PCR←Stdio←StreamRep { void * str←procs; FILE *str←next; FILE *str←prev; int str←flags; int str←status; PCR←Bool str←eof; int str←readCount; unsigned char *str←readPtr; int str←writeCount; unsigned char *str←writePtr; unsigned char * str←vbuf; int str←vbufSize; int str←vbufMode; PCR←Any str←clientData; }; typedef FILE PCR←Stdio←Stream; #define PCR←Stdio←GetCMacro(stream) \ ( ((stream)->str←readCount <= 0) \ ? PCR←fgetc(stream) \ : ( ((stream)->str←readCount--), \ *(((stream)->str←readPtr)++) ) ) #define PCR←Stdio←PutCMacro(c,stream) \ ( ((stream)->str←writeCount <= 1) \ ? PCR←fputc((c),(stream)) \ : ( ((stream)->str←writeCount--), \ (*(((stream)->str←writePtr)++) = (c)) ) ) /* * Handles for standard input and output streams. * * All threads share the same streams, but they actually * behave as if they were per-thread. */ #define PCR←Stdio←numStdStreams 3 PCR←Stdio←Stream PCR←Stdio←stdStreams[PCR←Stdio←numStdStreams]; #define PCR←stdin &(PCR←Stdio←stdStreams[0]) #define PCR←stdout &(PCR←Stdio←stdStreams[1]) #define PCR←stderr &(PCR←Stdio←stdStreams[2]) #ifndef PCR←NO←RENAME # define stdin PCR←stdin # define stdout PCR←stdout # define stderr PCR←stderr #endif #endif /* ←←PCR←stdio←h */ /* $Log$ */