Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#pragma	src	"/sys/src/libstdio"
2
#pragma	lib	"libstdio.a"
3
 
4
/*
5
 * pANS astdio.h
6
 */
7
/*
8
 * According to X3J11, there is only one i/o buffer
9
 * and it must not be occupied by both input and output data.
10
 *	If rp<wp, we must have state==RD and
11
 *	if wp<rp, we must have state==WR, so that getc and putc work correctly.
12
 *	On open, rp, wp and buf are set to 0, so first getc or putc will call _IO_getc
13
 *	or _IO_putc, which will allocate the buffer.
14
 *	If setvbuf(., ., _IONBF, .) is called, bufl is set to 0 and
15
 *	buf, rp and wp are pointed at unbuf.
16
 *	If setvbuf(., ., _IOLBF, .) is called, _IO_putc leaves wp and rp pointed at the
17
 *	end of the buffer so that it can be called on each putc to check whether it's got
18
 *	a newline.  This nonsense is in order to avoid impacting performance of the other
19
 *	buffering modes more than necessary -- putting the test in putc adds many
20
 *	instructions that are wasted in non-_IOLBF mode:
21
 *	#define putc(c, f)	(_IO_ctmp=(c),\
22
 *				(f)->wp>=(f)->rp || (f)->flags&LINEBUF && _IO_ctmp=='\n'\
23
 *					?_IO_putc(_IO_ctmp, f)\
24
 *					:*(f)->wp++=_IO_ctmp)
25
 *				
26
 */
27
typedef struct{
28
	int fd;		/* UNIX file pointer */
29
	char flags;	/* bits for must free buffer on close, line-buffered */
30
	char state;	/* last operation was read, write, position, error, eof */
31
	char *buf;	/* pointer to i/o buffer */
32
	char *rp;	/* read pointer (or write end-of-buffer) */
33
	char *wp;	/* write pointer (or read end-of-buffer) */
34
	char *lp;	/* actual write pointer used when line-buffering */
35
	long bufl;	/* actual length of buffer */
36
	char unbuf[1];	/* tiny buffer for unbuffered io (used for ungetc?) */
37
}FILE;
38
typedef long fpos_t;
39
#ifndef NULL
40
#define	NULL	((void*)0)
41
#endif
42
/*
43
 * Third arg of setvbuf
44
 */
45
#define	_IOFBF	1			/* block-buffered */
46
#define	_IOLBF	2			/* line-buffered */
47
#define	_IONBF	3			/* unbuffered */
48
#define	BUFSIZ	4096			/* size of setbuf buffer */
49
#define	EOF	(-1)			/* returned on end of file */
50
#define	FOPEN_MAX	100		/* max files open */
51
#define	FILENAME_MAX	BUFSIZ		/* silly filename length */
52
#define	L_tmpnam	20		/* sizeof "/tmp/abcdefghij9999 */
53
#ifndef SEEK_SET			/* also defined in unistd.h */
54
#define	SEEK_CUR	1
55
#define	SEEK_END	2
56
#define	SEEK_SET	0
57
#endif
58
#define	TMP_MAX		64		/* very hard to set correctly */
59
#define	stderr	(&_IO_stream[2])
60
#define	stdin	(&_IO_stream[0])
61
#define	stdout	(&_IO_stream[1])
62
#define	_IO_CHMASK	0377		/* mask for 8 bit characters */
63
FILE *tmpfile(void);
64
char *tmpnam(char *);
65
int fclose(FILE *);
66
int fflush(FILE *);
67
FILE *fopen(const char *, const char *);
68
FILE *fdopen(const int, const char *);
69
FILE *freopen(const char *, const char *, FILE *);
70
void setbuf(FILE *, char *);
71
int setvbuf(FILE *, char *, int, long);
72
int fprintf(FILE *, const char *, ...);
73
int fscanf(FILE *, const char *, ...);
74
int printf(const char *, ...);
75
int scanf(const char *, ...);
76
int sprintf(char *, const char *, ...);
77
int snprintf(char *, int, const char *, ...);
78
int sscanf(const char *, const char *, ...);
79
int vfprintf(FILE *, const char *, va_list);
80
int vprintf(const char *, va_list);
81
int vsprintf(char *, const char *, va_list);
82
int vsnprintf(char *, int, const char *, va_list);
83
int vfscanf(FILE *, const char *, va_list);
84
int fgetc(FILE *);
85
char *fgets(char *, int, FILE *);
86
int fputc(int, FILE *);
87
int fputs(const char *, FILE *);
88
int getc(FILE *);
89
#define	getc(f)	((f)->rp>=(f)->wp?_IO_getc(f):*(f)->rp++&_IO_CHMASK)
90
int _IO_getc(FILE *f);
91
int getchar(void);
92
#define	getchar()	getc(stdin)
93
char *gets(char *);
94
int putc(int, FILE *);
95
#define	putc(c, f) ((f)->wp>=(f)->rp?_IO_putc(c, f):(*(f)->wp++=c)&_IO_CHMASK)
96
int _IO_putc(int, FILE *);
97
int putchar(int);
98
#define	putchar(c)	putc(c, stdout)
99
int puts(const char *);
100
int ungetc(int, FILE *);
101
long fread(void *, long, long, FILE *);
102
long fwrite(const void *, long, long, FILE *);
103
int fgetpos(FILE *, fpos_t *);
104
int fseek(FILE *, long, int);
105
int fseeko(FILE *, long long, int);
106
int fsetpos(FILE *, const fpos_t *);
107
long ftell(FILE *);
108
long long ftello(FILE *);
109
void rewind(FILE *);
110
void clearerr(FILE *);
111
int feof(FILE *);
112
int ferror(FILE *);
113
void perror(const char *);
114
extern FILE _IO_stream[FOPEN_MAX];
115
FILE *sopenr(const char *);
116
FILE *sopenw(void);
117
char *sclose(FILE *);
118
int fileno(FILE *);