Skip to content

Instantly share code, notes, and snippets.

@aliharis
Created November 19, 2012 18:14
Show Gist options
  • Save aliharis/4112431 to your computer and use it in GitHub Desktop.
Save aliharis/4112431 to your computer and use it in GitHub Desktop.
Standard Input Output for C (Header)
/* stdio.h
Definitions for stream input/output.
Copyright (c) Borland International 1987,1988,1990,1991
All Rights Reserved.
*/
#ifndef __STDIO_H
#define __STDIO_H
#ifdef __DLL__
#define _FAR far
#else
#define _FAR
#endif
#if __STDC__
#define _Cdecl
#else
#define _Cdecl cdecl
#endif
#ifndef __PAS__
#define _CType _Cdecl
#else
#define _CType pascal
#endif
#ifndef _SIZE_T
#define _SIZE_T
typedef unsigned size_t;
#endif
#ifndef NULL
#if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
#define NULL 0
#else
#define NULL 0L
#endif
#endif
/* Definition of the file position type
*/
typedef long fpos_t;
/* Definition of the control structure for streams
*/
typedef struct {
short level; /* fill/empty level of buffer */
unsigned flags; /* File status flags */
char fd; /* File descriptor */
unsigned char hold; /* Ungetc char if no buffer */
short bsize; /* Buffer size */
unsigned char _FAR *buffer; /* Data transfer buffer */
unsigned char _FAR *curp; /* Current active pointer */
unsigned istemp; /* Temporary file indicator */
short token; /* Used for validity checking */
} FILE; /* This is the FILE object */
/* Bufferisation type to be used as 3rd argument for "setvbuf" function
*/
#define _IOFBF 0
#define _IOLBF 1
#define _IONBF 2
/* "flags" bits definitions
*/
#define _F_RDWR 0x0003 /* Read/write flag */
#define _F_READ 0x0001 /* Read only file */
#define _F_WRIT 0x0002 /* Write only file */
#define _F_BUF 0x0004 /* Malloc'ed Buffer data */
#define _F_LBUF 0x0008 /* line-buffered file */
#define _F_ERR 0x0010 /* Error indicator */
#define _F_EOF 0x0020 /* EOF indicator */
#define _F_BIN 0x0040 /* Binary file indicator */
#define _F_IN 0x0080 /* Data is incoming */
#define _F_OUT 0x0100 /* Data is outgoing */
#define _F_TERM 0x0200 /* File is a terminal */
/* End-of-file constant definition
*/
#define EOF (-1) /* End of file indicator */
/* Number of files that can be open simultaneously
*/
#if __STDC__
#define FOPEN_MAX 18 /* Able to have 18 files (20 - stdaux & stdprn) */
#else
#define FOPEN_MAX 20 /* Able to have 20 files */
#define SYS_OPEN 20
#endif
#define FILENAME_MAX 80
/* Default buffer size use by "setbuf" function
*/
#define BUFSIZ 512 /* Buffer size for stdio */
/* Size of an arry large enough to hold a temporary file name string
*/
#define L_ctermid 5 /* CON: plus null byte */
#define L_tmpnam 13 /* tmpnam buffer size */
/* Constants to be used as 3rd argument for "fseek" function
*/
#define SEEK_CUR 1
#define SEEK_END 2
#define SEEK_SET 0
/* Number of unique file names that shall be generated by "tmpnam" function
*/
#define TMP_MAX 0xFFFF
/* Standard I/O predefined streams
*/
extern FILE _Cdecl _streams[];
#define stdin (&_streams[0])
#define stdout (&_streams[1])
#define stderr (&_streams[2])
#if !__STDC__
#define stdaux (&_streams[3])
#define stdprn (&_streams[4])
#endif
#ifdef __cplusplus
extern "C" {
#endif
void _Cdecl clearerr(FILE _FAR *__stream);
int _Cdecl fclose(FILE _FAR *__stream);
int _Cdecl fflush(FILE _FAR *__stream);
int _Cdecl fgetc(FILE _FAR *__stream);
int _Cdecl fgetpos(FILE _FAR *__stream, fpos_t _FAR *__pos);
char _FAR *_Cdecl fgets(char _FAR *__s, int __n, FILE _FAR *__stream);
FILE _FAR *_Cdecl fopen(const char _FAR *__path, const char _FAR *__mode);
int _Cdecl fprintf(FILE _FAR *__stream, const char _FAR *__format, ...);
int _Cdecl fputc(int __c, FILE _FAR *__stream);
int _Cdecl fputs(const char _FAR *__s, FILE _FAR *__stream);
size_t _Cdecl fread(void _FAR *__ptr, size_t __size, size_t __n,
FILE _FAR *__stream);
FILE _FAR *_Cdecl freopen(const char _FAR *__path, const char _FAR *__mode,
FILE _FAR *__stream);
int _Cdecl fscanf(FILE _FAR *__stream, const char _FAR *__format, ...);
int _Cdecl fseek(FILE _FAR *__stream, long __offset, int __whence);
int _Cdecl fsetpos(FILE _FAR *__stream, const fpos_t _FAR *__pos);
long _Cdecl ftell(FILE _FAR *__stream);
size_t _Cdecl fwrite(const void _FAR *__ptr, size_t __size, size_t __n,
FILE _FAR *__stream);
#if !defined( _Windows )
char _FAR *_Cdecl gets(char _FAR *__s);
#endif
void _Cdecl perror(const char _FAR *__s);
#if !defined( _Windows )
int _Cdecl printf(const char _FAR *__format, ...);
int _Cdecl puts(const char _FAR *__s);
#endif
int _CType remove(const char _FAR *__path);
int _Cdecl rename(const char _FAR *__oldname,const char _FAR *__newname);
void _Cdecl rewind(FILE _FAR *__stream);
#if !defined( _Windows )
int _Cdecl scanf(const char _FAR *__format, ...);
#endif
void _Cdecl setbuf(FILE _FAR *__stream, char _FAR *__buf);
int _Cdecl setvbuf(FILE _FAR *__stream, char _FAR *__buf,
int __type, size_t __size);
int _Cdecl sprintf(char _FAR *__buffer, const char _FAR *__format, ...);
int _Cdecl sscanf(const char _FAR *__buffer,
const char _FAR *__format, ...);
char _FAR *_Cdecl strerror(int __errnum);
FILE _FAR *_Cdecl tmpfile(void);
char _FAR *_Cdecl tmpnam(char _FAR *__s);
int _Cdecl ungetc(int __c, FILE _FAR *__stream);
int _Cdecl vfprintf(FILE _FAR *__stream, const char _FAR *__format,
void _FAR *__arglist);
int _Cdecl vfscanf(FILE _FAR *__stream, const char _FAR *__format,
void _FAR *__arglist);
#if !defined( _Windows )
int _CType vprintf(const char _FAR *__format, void _FAR *__arglist);
int _Cdecl vscanf(const char _FAR *__format, void _FAR *__arglist);
#endif
int _Cdecl vsprintf(char _FAR *__buffer, const char _FAR *__format,
void _FAR *__arglist);
int _Cdecl vsscanf(const char _FAR *__buffer, const char _FAR *__format,
void _FAR *__arglist);
int _CType unlink(const char _FAR *__path);
int _Cdecl getc(FILE _FAR *__fp);
#if !defined( _Windows )
int _Cdecl getchar(void);
int _Cdecl putchar(const int __c);
#endif
int _Cdecl putc(const int __c, FILE _FAR *__fp);
int _Cdecl feof(FILE _FAR *__fp);
int _Cdecl ferror(FILE _FAR *__fp);
#if !__STDC__
int _Cdecl fcloseall(void);
FILE _FAR *_Cdecl fdopen(int __handle, char _FAR *__type);
int _Cdecl fgetchar(void);
int _Cdecl flushall(void);
int _Cdecl fputchar(int __c);
int _Cdecl getw(FILE _FAR *__stream);
int _Cdecl putw(int __w, FILE _FAR *__stream);
char _FAR *_Cdecl _strerror(const char _FAR *__s);
#define fileno(f) ((f)->fd)
#endif
int _Cdecl _fgetc(FILE _FAR *__stream); /* used by getc() macro */
int _Cdecl _fputc(char __c, FILE _FAR *__stream); /* used by putc() macro */
#ifdef __cplusplus
}
#endif
/* The following macros provide for common functions */
#define ferror(f) ((f)->flags & _F_ERR)
#define feof(f) ((f)->flags & _F_EOF)
#define getc(f) \
((--((f)->level) >= 0) ? (unsigned char)(*(f)->curp++) : \
_fgetc (f))
#define putc(c,f) \
((++((f)->level) < 0) ? (unsigned char)(*(f)->curp++=(c)) : \
_fputc ((c),f))
#define getchar() getc(stdin)
#define putchar(c) putc((c), stdout)
#define ungetc(c,f) ungetc((c),f) /* traditionally a macro */
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment