home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************
- *
- * $Source: /unixb/home/unixlib/source/unixlib37/src/clib/h/RCS/stdio,v $
- * $Date: 1996/11/06 22:01:41 $
- * $Revision: 1.3 $
- * $State: Rel $
- * $Author: unixlib $
- *
- * $Log: stdio,v $
- * Revision 1.3 1996/11/06 22:01:41 unixlib
- * Yet more changes by NB, PB and SC.
- *
- * Revision 1.2 1996/10/30 21:58:58 unixlib
- * Massive changes made by Nick Burret and Peter Burwood.
- *
- * Revision 1.1 1996/04/19 21:02:57 simon
- * Initial revision
- *
- ***************************************************************************/
-
- /* ANSI Standard 4.9: Input/Output <stdio.h>. */
-
- #ifndef __STDIO_H
- #define __STDIO_H
-
- #ifndef __UNIXLIB_TYPES_H
- #include <unixlib/types.h>
- #endif
- #ifndef __STDARG_H
- #include <stdarg.h>
- #endif
- #ifndef __STDDEF_H
- #include <stddef.h>
- #endif
-
- #ifdef __cplusplus
- extern "C" {
- #endif
-
- typedef __off_t fpos_t;
-
-
- /* Maximum number of files that can be open at once.
- Keep in sync with <limits.h>, _POSIX_OPEN_MAX. */
- #define FOPEN_MAX 64
-
- /* Maximum length of a filename.
- Keep in sync with <limits.h>, _POSIX_NAME_MAX. */
- #define FILENAME_MAX 252
-
- /* Default buffer size. */
- #define BUFSIZ 4096
-
- /* End of file character. */
- #define EOF (-1)
-
- /* The possibilities for the third argument to fseek.
- <unistd.h> has the same definitions. */
-
- /* Seek from beginning of file. */
- #ifndef SEEK_SET
- #define SEEK_SET 0
- #endif
- /* Seek from current position. */
- #ifndef SEEK_CUR
- #define SEEK_CUR 1
- #endif
- /* Seek from end of file. */
- #ifndef SEEK_END
- #define SEEK_END 2
- #endif
-
- /* Magic number to fill __magic. */
- #define _IOMAGIC 0xfedabeeb
-
- typedef struct __iobuf
- {
- /* Magic number for stream validation. */
- int __magic;
- unsigned char *i_ptr;
- unsigned char *i_base;
- int i_cnt;
- unsigned char *o_ptr;
- unsigned char *o_base;
- int o_cnt;
- /* File flags. */
- int flag;
- /* File descriptor. */
- int fd;
- fpos_t pos;
- int bufsiz;
- } __FILE;
-
- #define FILE __FILE
-
- /* Nonzero if stream is a valid stream. */
- #define __validfp(stream) (stream != NULL && stream->__magic == _IOMAGIC)
-
- /* Standard streams. */
- extern FILE __iob[FOPEN_MAX];
-
- #define stdin (&__iob[0])
- #define stdout (&__iob[1])
- #define stderr (&__iob[2])
-
- #define _IOOMASK 0000003
-
- #define _IOREAD 0000001
- #define _IOWRITE 0000002
- #define _IOAPPEND 0000004
-
- #define _IOBF 0000070
-
- /* The possibilities for the third argument to setvbuf. */
-
- /* No buffering. */
- #define _IONBF 0000010
- /* Line buffering. */
- #define _IOLBF 0000020
- /* Full buffering. */
- #define _IOFBF 0000040
-
- #define _IOEOF 0000100
- #define _IOERR 0000200
-
- #define _IOTTY 0000400
- #define _IOPIPE 0001000
-
- /* Return the EOF indicator for stream. */
- #define feof(f) ((f)->flag & _IOEOF)
- /* Return the error indicator for stream. */
- #define ferror(f) ((f)->flag & _IOERR)
- #define fisatty(f) ((f)->flag & _IOTTY)
- #define fispipe(f) ((f)->flag & _IOPIPE)
- #define fisopen(f) ((f)->flag & (_IOREAD|_IOWRITE))
-
- /* Clear the error and EOF indicators of stream. */
- #define clearerr(stream) (void)((stream)->flag &= (~(_IOEOF|_IOERR)))
-
- extern int (feof)(FILE *);
- extern int (ferror)(FILE *);
- extern int (fisatty)(FILE *);
- extern int (fisopen)(FILE *);
-
- extern void (clearerr)(FILE *);
-
- /* Print a message describing the meaning of the value of errno. */
- extern void perror (const char *s);
-
- extern void __stdioinit(void); /* initialise stdin,stdout & stderr */
- extern void __stdioexit(void); /* close streams & delete tmpfile() */
-
- /* fill buffer */
- extern int __filbuf(FILE *);
- /* flush buffer */
- extern int __flsbuf(int,FILE *);
-
- /* null pointer output */
- extern char *__null;
-
- /* Open a file and create a new stream for it. */
- extern FILE *fopen (const char *filename, const char *modes);
- /* Open a file, replacing an existing stream with it. */
- extern FILE *freopen (const char *filename, const char *modes, FILE *stream);
-
- /* Close stream, or all streams if stream is null. */
- extern int fclose (FILE *stream);
- /* Flush stream, or all streams if stream is null. */
- extern int fflush (FILE *stream);
-
-
-
- /* Read chunks of generic data from stream. */
- extern size_t fread (void *ptr, size_t size, size_t n, FILE *stream);
- extern int __fread(FILE *,char *,int);
-
- /* Write chunks of generic data to stream. */
- extern size_t fwrite(const void *ptr, size_t size, size_t n, FILE *stream);
- extern int __fwrite(FILE *,char *,int);
-
- /* If buf is null, make stream unbuffered.
- If not null, use buffer buf of size BUFSIZ. */
- extern void setbuf (FILE *stream, char *buf);
- /* Make stream use buffering mode 'mode'.
- If buf is not NULL, use n bytes of it for buffering;
- else allocate an internal buffer n bytes long. */
- extern int setvbuf (FILE *stream, char *buf, int modes, size_t n);
-
- /* Push a character back onto the input buffer of stream. */
- extern int ungetc (int c, FILE *stream);
-
- /* Get stream's position. */
- extern int fgetpos (FILE *stream, fpos_t *pos);
- /* Set stream's position. */
- extern int fsetpos (FILE *stream, const fpos_t *pos);
-
- /* Seek to a certain position on stream. */
- extern int fseek (FILE *stream, long int off, int whence);
- /* Return the current position of stream. */
- extern long ftell (FILE *stream);
- /* Rewind to the beginning of stream. */
- extern void rewind (FILE *stream);
-
- /* Read a character from stream. */
- #define getc(f) \
- ((--((f)->i_cnt) >= 0 ? *((f)->i_ptr)++ : __filbuf(f)))
- /* Read a character from stdin. */
- #define getchar() getc(stdin)
-
- /* Read a character from stream. */
- extern int fgetc (FILE *stream);
- extern int (getc)(FILE *);
- extern int (getchar)(void);
-
- /* Write a character to stream. */
- #define putc(c,f) \
- (((((f)->flag) & _IOLBF) && (c) == '\n') ? __flsbuf(c,f) : \
- ((--((f)->o_cnt) > 0 ? (*((f)->o_ptr)++ = (c)) : __flsbuf(c,f))))
- #define putchar(c) putc(c,stdout)
-
- extern int fputc(int,FILE *);
- extern int (putc)(int,FILE *);
- extern int (putchar)(int);
-
- /* Get a newline-terminated string of finite length from stream. */
- extern char *fgets (char *s, size_t n, FILE *stream);
- /* Get a newline-terminated string from stdin, removing the newline. */
- extern char *gets (char *s);
-
- /* Write a string to stream. */
- extern int fputs (const char *s, FILE *stream);
- /* Write a string, followed by a newline, to stdout. */
- extern int puts (const char *s);
-
- /* formatted I/O */
-
- extern int __printf(char *,const char *,va_list);
- extern int __scanf(FILE *,const char *,va_list,int *);
-
- /* buffer for printf */
- extern char *__pbuf;
- /* buffer for scanf */
- extern char *__sbuf;
-
- /* I know I said I would not do this, but ... */
-
- /* Write formatted output to s from argument list arg. */
- extern int vsprintf (char *s, const char *format, va_list arg);
- /* Write formatted output to stream from arg list arg. */
- extern int vfprintf (FILE *stream, const char *format, va_list arg);
- /* Write formatted output to stdio from arg list arg. */
- extern int vprintf (const char *format, va_list arg);
-
- #pragma -v1
- /* Write formatted output to s. */
- extern int sprintf (char *s, const char *format, ...);
- /* Write formatted output to stream. */
- extern int fprintf (FILE *stream, const char *format, ...);
- /* Write formatted output to stdout. */
- extern int printf (const char *format, ...);
-
- #pragma -v2
- /* Read formatted input from s. */
- extern int sscanf (const char *s, const char *format, ...);
- /* Read formatted input from stream. */
- extern int fscanf (FILE *stream, const char *format, ...);
- /* Read format input from stdin. */
- extern int scanf (const char *format, ...);
- #pragma -v3
-
- /* How long an array of chars must be to be passed to tmpnam. */
- #define L_tmpnam 255
- /* The minimum number of unique filenames generated by tmpnam. */
- #define TMP_MAX 0x100
-
- /* Remove file filename. */
- extern int remove (const char *filename);
-
- /* Rename file oldname to newname. */
- extern int rename(const char *old, const char *newname);
-
- /* Create a temporary file and open it read/write. */
- extern FILE *tmpfile (void);
- /* Generate a temporary filename. */
- extern char *tmpnam (char *s);
-
- /* Generate a unique temporary file name for temp. */
- extern char *mktemp(char *temp);
- /* As for mktemp but returns an open file descriptor on the file. */
- extern int mkstemp(char *temp);
-
- extern FILE *__tmpf;
- extern char __tmpn[L_tmpnam + 1];
- extern unsigned int __tmpcnt;
-
- #define __STDIOLIB__ static void __stdiolib(void) { __stdioinit(); }
-
- /* System V enhancements. */
-
- /* Get a word (int) from stream. */
- extern int getw (FILE *stream);
- /* Write a word (int) to stream. */
- extern int putw (int w, FILE *stream);
-
- /* Default path prefix for tempnam and tmpnam. */
- #define P_tmpdir "/tmp"
-
-
- /* BSD enhancements. */
-
- /* If BUF is NULL, make STREAM unbuffered.
- Else make it use SIZE bytes of BUF for buffering. */
- extern void setbuffer (FILE *stream, char *buf, size_t size);
-
- /* Make STREAM line-buffered. */
- extern void setlinebuf (FILE *stream);
-
- extern int sys_nerr;
- extern char *sys_errlist[];
-
- /* POSIX enhancements. */
-
- /* Create a new stream that refers to an existing system file descriptor. */
- extern FILE *fdopen (int fd, const char *modes);
-
- /* Return the system file descriptor for stream. */
- #define fileno(f) ((f)->fd)
- extern int (fileno)(FILE *stream);
-
- #if 0
- /* Return the name of the controlling terminal. */
- extern char *ctermid (char *__s);
- /* Return the name of the current user. */
- extern char *cuserid (char *__s);
- #endif
-
- /* POSIX 2 enhancements. */
-
- /* Create a new stream connected to a pipe running the given command. */
- extern FILE *popen (const char *command, const char *modes);
-
- /* Close a stream opened by popen and return the status of its child. */
- extern int pclose (FILE *stram);
-
-
- /* GNU extenstions. */
-
- /* Read an entire line from stream (upto newline), storing the text in
- a buffer and storing the buffer address in *lineptr. */
- extern __ssize_t getline (char **lineptr, size_t *n, FILE *stream);
-
- /* Similar to getline except that the line terminator doesn't
- have to be a newline. */
- extern __ssize_t getdelim (char **lineptr, size_t *n, int delimiter, FILE *stream);
-
- #ifdef __cplusplus
- }
- #endif
-
- #endif
-