1 |
199 |
simons |
|
2 |
|
|
#ifndef __STDIO_H
|
3 |
|
|
#define __STDIO_H
|
4 |
|
|
|
5 |
|
|
#include <features.h>
|
6 |
|
|
#include <sys/types.h>
|
7 |
|
|
|
8 |
|
|
#ifndef SEEK_SET
|
9 |
|
|
#define SEEK_SET 0
|
10 |
|
|
#define SEEK_CUR 1
|
11 |
|
|
#define SEEK_END 2
|
12 |
|
|
#endif
|
13 |
|
|
|
14 |
|
|
#define _IOFBF 0x00 /* full buffering */
|
15 |
|
|
#define _IOLBF 0x01 /* line buffering */
|
16 |
|
|
#define _IONBF 0x02 /* no buffering */
|
17 |
|
|
#define __MODE_BUF 0x03 /* Modal buffering dependent on isatty */
|
18 |
|
|
|
19 |
|
|
#define __MODE_FREEBUF 0x04 /* Buffer allocated with malloc, can free */
|
20 |
|
|
#define __MODE_FREEFIL 0x08 /* FILE allocated with malloc, can free */
|
21 |
|
|
|
22 |
|
|
#define __MODE_READ 0x10 /* Opened in read only */
|
23 |
|
|
#define __MODE_WRITE 0x20 /* Opened in write only */
|
24 |
|
|
#define __MODE_RDWR 0x30 /* Opened in read/write */
|
25 |
|
|
|
26 |
|
|
#define __MODE_READING 0x40 /* Buffer has pending read data */
|
27 |
|
|
#define __MODE_WRITING 0x80 /* Buffer has pending write data */
|
28 |
|
|
|
29 |
|
|
#define __MODE_EOF 0x100 /* EOF status */
|
30 |
|
|
#define __MODE_ERR 0x200 /* Error status */
|
31 |
|
|
#define __MODE_UNGOT 0x400 /* Buffer has been polluted by ungetc */
|
32 |
|
|
|
33 |
|
|
#define __MODE_IOTRAN 0
|
34 |
|
|
|
35 |
|
|
/* when you add or change fields here, be sure to change the initialization
|
36 |
|
|
* in stdio_init and fopen */
|
37 |
|
|
struct __stdio_file {
|
38 |
|
|
unsigned char *bufpos; /* the next byte to write to or read from */
|
39 |
|
|
unsigned char *bufread; /* the end of data returned by last read() */
|
40 |
|
|
unsigned char *bufwrite; /* highest address writable by macro */
|
41 |
|
|
unsigned char *bufstart; /* the start of the buffer */
|
42 |
|
|
unsigned char *bufend; /* the end of the buffer; ie the byte after the last
|
43 |
|
|
malloc()ed byte */
|
44 |
|
|
|
45 |
|
|
int fd; /* the file descriptor associated with the stream */
|
46 |
|
|
int mode;
|
47 |
|
|
|
48 |
|
|
char unbuf[8]; /* The buffer for 'unbuffered' streams */
|
49 |
|
|
|
50 |
|
|
struct __stdio_file * next;
|
51 |
|
|
};
|
52 |
|
|
|
53 |
|
|
#define EOF (-1)
|
54 |
|
|
#ifndef NULL
|
55 |
|
|
#define NULL (0)
|
56 |
|
|
#endif
|
57 |
|
|
|
58 |
|
|
typedef struct __stdio_file FILE;
|
59 |
|
|
|
60 |
|
|
#define BUFSIZ (500) /*(508) should get us a fully used kmalloc bucket */
|
61 |
|
|
|
62 |
|
|
extern FILE stdin[1];
|
63 |
|
|
extern FILE stdout[1];
|
64 |
|
|
extern FILE stderr[1];
|
65 |
|
|
|
66 |
|
|
|
67 |
|
|
#define putc(c, stream) \
|
68 |
|
|
(((stream)->bufpos >= (stream)->bufwrite) ? fputc((c), (stream)) \
|
69 |
|
|
: (unsigned char) (*(stream)->bufpos++ = (c)) )
|
70 |
|
|
|
71 |
|
|
#define getc(stream) \
|
72 |
|
|
(((stream)->bufpos >= (stream)->bufread) ? fgetc(stream): \
|
73 |
|
|
(*(stream)->bufpos++))
|
74 |
|
|
|
75 |
|
|
#define putchar(c) putc((c), stdout)
|
76 |
|
|
#define getchar() getc(stdin)
|
77 |
|
|
|
78 |
|
|
#define ferror(fp) (((fp)->mode&__MODE_ERR) != 0)
|
79 |
|
|
#define feof(fp) (((fp)->mode&__MODE_EOF) != 0)
|
80 |
|
|
#define clearerr(fp) ((fp)->mode &= ~(__MODE_EOF|__MODE_ERR),0)
|
81 |
|
|
#define fileno(fp) ((fp)->fd)
|
82 |
|
|
|
83 |
|
|
/* These two call malloc */
|
84 |
|
|
#define setlinebuf(__fp) setvbuf((__fp), (char*)0, _IOLBF, 0)
|
85 |
|
|
extern int setvbuf __P((FILE*, char*, int, size_t));
|
86 |
|
|
|
87 |
|
|
/* These don't */
|
88 |
|
|
#define setbuf(__fp, __buf) setbuffer((__fp), (__buf), BUFSIZ)
|
89 |
|
|
extern void setbuffer __P((FILE*, char*, int));
|
90 |
|
|
|
91 |
|
|
extern int fgetc __P((FILE*));
|
92 |
|
|
extern int fputc __P((int, FILE*));
|
93 |
|
|
|
94 |
|
|
extern int fclose __P((FILE*));
|
95 |
|
|
extern int fflush __P((FILE*));
|
96 |
|
|
extern char *fgets __P((char*, size_t, FILE*));
|
97 |
|
|
extern FILE *__fopen __P((char*, int, FILE*, char*));
|
98 |
|
|
|
99 |
|
|
#define fopen(__file, __mode) __fopen((__file), -1, (FILE*)0, (__mode))
|
100 |
|
|
#define freopen(__file, __mode, __fp) __fopen((__file), -1, (__fp), (__mode))
|
101 |
|
|
#define fdopen(__file, __mode) __fopen((char*)0, (__file), (FILE*)0, (__mode))
|
102 |
|
|
|
103 |
|
|
extern int fseek __P((FILE*, long, int));
|
104 |
|
|
extern long ftell __P((FILE*));
|
105 |
|
|
extern void rewind __P((FILE*));
|
106 |
|
|
|
107 |
|
|
extern int fputs __P((char*, FILE*));
|
108 |
|
|
extern int puts __P((char*));
|
109 |
|
|
|
110 |
|
|
extern int printf __P ((__const char*, ...));
|
111 |
|
|
extern int fprintf __P ((FILE*, __const char*, ...));
|
112 |
|
|
extern int sprintf __P ((char*, __const char*, ...));
|
113 |
|
|
|
114 |
|
|
extern int ungetc __P ((int c, FILE * stream));
|
115 |
|
|
|
116 |
|
|
#define stdio_pending(fp) ((fp)->bufread>(fp)->bufpos)
|
117 |
|
|
|
118 |
|
|
#endif /* __STDIO_H */
|