/* 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 #include #include #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$ */