5753632 [rkeene@sledge /home/rkeene/devel/cygwin-stuff/cyg-root/usr/include]$ cat -n stdio.h
  1 /*
  2  * Copyright (c) 1990 The Regents of the University of California.
  3  * All rights reserved.
  4  *
  5  * Redistribution and use in source and binary forms are permitted
  6  * provided that the above copyright notice and this paragraph are
  7  * duplicated in all such forms and that any documentation,
  8  * advertising materials, and other materials related to such
  9  * distribution and use acknowledge that the software was developed
 10  * by the University of California, Berkeley.  The name of the
 11  * University may not be used to endorse or promote products derived
 12  * from this software without specific prior written permission.
 13  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 14  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 16  *
 17  *  @(#)stdio.h 5.3 (Berkeley) 3/15/86
 18  */
 19 
 20 /*
 21  * NB: to fit things in six character monocase externals, the
 22  * stdio code uses the prefix `__s' for stdio objects, typically
 23  * followed by a three-character attempt at a mnemonic.
 24  */
 25 
 26 #ifndef _STDIO_H_
 27 #ifdef __cplusplus
 28 extern "C" {
 29 #endif
 30 #define _STDIO_H_
 31 
 32 #include "_ansi.h"
 33 
 34 #define _FSTDIO         /* ``function stdio'' */
 35 
 36 #define __need_size_t
 37 #include <stddef.h>
 38 
 39 #define __need___va_list
 40 #include <stdarg.h>
 41 
 42 /*
 43  * <sys/reent.h> defines __sFILE, _fpos_t.
 44  * They must be defined there because struct _reent needs them (and we don't
 45  * want reent.h to include this file.
 46  */
 47 
 48 #include <sys/reent.h>
 49 
 50 typedef _fpos_t fpos_t;
 51 
 52 typedef struct __sFILE FILE;
 53 
 54 #define __SLBF  0x0001      /* line buffered */
 55 #define __SNBF  0x0002      /* unbuffered */
 56 #define __SRD   0x0004      /* OK to read */
 57 #define __SWR   0x0008      /* OK to write */
 58     /* RD and WR are never simultaneously asserted */
 59 #define __SRW   0x0010      /* open for reading & writing */
 60 #define __SEOF  0x0020      /* found EOF */
 61 #define __SERR  0x0040      /* found error */
 62 #define __SMBF  0x0080      /* _buf is from malloc */
 63 #define __SAPP  0x0100      /* fdopen()ed in append mode - so must  write to end */
 64 #define __SSTR  0x0200      /* this is an sprintf/snprintf string */
 65 #define __SOPT  0x0400      /* do fseek() optimisation */
 66 #define __SNPT  0x0800      /* do not do fseek() optimisation */
 67 #define __SOFF  0x1000      /* set iff _offset is in fact correct */
 68 #define __SMOD  0x2000      /* true => fgetline modified _p text */
 69 #if defined(__CYGWIN__) || defined(__CYGWIN__)
 70 #define __SCLE        0x4000          /* convert line endings CR/LF <-> NL */
 71 #endif
 72 
 73 /*
 74  * The following three definitions are for ANSI C, which took them
 75  * from System V, which stupidly took internal interface macros and
 76  * made them official arguments to setvbuf(), without renaming them.
 77  * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
 78  *
 79  * Although these happen to match their counterparts above, the
 80  * implementation does not rely on that (so these could be renumbered).
 81  */
 82 #define _IOFBF  0       /* setvbuf should set fully buffered */
 83 #define _IOLBF  1       /* setvbuf should set line buffered */
 84 #define _IONBF  2       /* setvbuf should set unbuffered */
 85 
 86 #ifndef NULL
 87 #define NULL    0
 88 #endif
 89 
 90 #define BUFSIZ  1024
 91 #define EOF (-1)
 92 
 93 #define FOPEN_MAX   20  /* must be <= OPEN_MAX <sys/syslimits.h> */
 94 #define FILENAME_MAX    1024    /* must be <= PATH_MAX <sys/syslimits.h> */
 95 #define L_tmpnam    1024    /* XXX must be == PATH_MAX */
 96 #ifndef __STRICT_ANSI__
 97 #define P_tmpdir        "/tmp"
 98 #endif
 99 
100 #ifndef SEEK_SET
101 #define SEEK_SET    0   /* set file offset to offset */
102 #endif
103 #ifndef SEEK_CUR
104 #define SEEK_CUR    1   /* set file offset to current plus offset */
105 #endif
106 #ifndef SEEK_END
107 #define SEEK_END    2   /* set file offset to EOF plus offset */
108 #endif
109 
110 #define TMP_MAX     26
111 
112 #define stdin   (_impure_ptr->_stdin)
113 #define stdout  (_impure_ptr->_stdout)
114 #define stderr  (_impure_ptr->_stderr)
115 
116 #define _stdin_r(x) ((x)->_stdin)
117 #define _stdout_r(x)    ((x)->_stdout)
118 #define _stderr_r(x)    ((x)->_stderr)
119 
120 /*
121  * Functions defined in ANSI C standard.
122  */
123 
124 #ifdef __GNUC__
125 #define __VALIST __gnuc_va_list
126 #else
127 #define __VALIST char*
128 #endif
129 
130 #ifndef _REENT_ONLY
131 int _EXFUN(remove, (const char *));
132 int _EXFUN(rename, (const char *, const char *));
133 #endif
134 char *  _EXFUN(tempnam, (const char *, const char *));
135 FILE *  _EXFUN(tmpfile, (void));
136 char *  _EXFUN(tmpnam, (char *));
137 int _EXFUN(fclose, (FILE *));
138 int _EXFUN(fflush, (FILE *));
139 FILE *  _EXFUN(freopen, (const char *, const char *, FILE *));
140 void    _EXFUN(setbuf, (FILE *, char *));
141 int _EXFUN(setvbuf, (FILE *, char *, int, size_t));
142 int _EXFUN(fprintf, (FILE *, const char *, ...));
143 int _EXFUN(fscanf, (FILE *, const char *, ...));
144 int _EXFUN(printf, (const char *, ...));
145 int _EXFUN(scanf, (const char *, ...));
146 int _EXFUN(sscanf, (const char *, const char *, ...));
147 int _EXFUN(vfprintf, (FILE *, const char *, __VALIST));
148 int _EXFUN(vprintf, (const char *, __VALIST));
149 int _EXFUN(vsprintf, (char *, const char *, __VALIST));
150 int _EXFUN(vsnprintf, (char *, size_t, const char *, __VALIST));
151 int _EXFUN(fgetc, (FILE *));
152 char *  _EXFUN(fgets, (char *, int, FILE *));
153 int _EXFUN(fputc, (int, FILE *));
154 int _EXFUN(fputs, (const char *, FILE *));
155 int _EXFUN(getc, (FILE *));
156 int _EXFUN(getchar, (void));
157 char *  _EXFUN(gets, (char *));
158 int _EXFUN(putc, (int, FILE *));
159 int _EXFUN(putchar, (int));
160 int _EXFUN(puts, (const char *));
161 int _EXFUN(ungetc, (int, FILE *));
162 size_t  _EXFUN(fread, (_PTR, size_t _size, size_t _n, FILE *));
163 size_t  _EXFUN(fwrite, (const _PTR , size_t _size, size_t _n, FILE *));
164 int _EXFUN(fgetpos, (FILE *, fpos_t *));
165 int _EXFUN(fseek, (FILE *, long, int));
166 int _EXFUN(fsetpos, (FILE *, const fpos_t *));
167 long    _EXFUN(ftell, ( FILE *));
168 void    _EXFUN(rewind, (FILE *));
169 void    _EXFUN(clearerr, (FILE *));
170 int _EXFUN(feof, (FILE *));
171 int _EXFUN(ferror, (FILE *));
172 void    _EXFUN(perror, (const char *));
173 #ifndef _REENT_ONLY
174 FILE *  _EXFUN(fopen, (const char *_name, const char *_type));
175 int _EXFUN(sprintf, (char *, const char *, ...));
176 int _EXFUN(snprintf, (char *, size_t, const char *, ...));
177 #endif
178 #ifndef __STRICT_ANSI__
179 int _EXFUN(vfiprintf, (FILE *, const char *, __VALIST));
180 int _EXFUN(iprintf, (const char *, ...));
181 int _EXFUN(fiprintf, (FILE *, const char *, ...));
182 int _EXFUN(siprintf, (char *, const char *, ...));
183 #endif
184 
185 /*
186  * Routines in POSIX 1003.1.
187  */
188 
189 #ifndef __STRICT_ANSI__
190 #ifndef _REENT_ONLY
191 FILE *  _EXFUN(fdopen, (int, const char *));
192 #endif
193 int _EXFUN(fileno, (FILE *));
194 int _EXFUN(getw, (FILE *));
195 int _EXFUN(pclose, (FILE *));
196 FILE *  _EXFUN(popen, (const char *, const char *));
197 int _EXFUN(putw, (int, FILE *));
198 void    _EXFUN(setbuffer, (FILE *, char *, int));
199 int _EXFUN(setlinebuf, (FILE *));
200 #endif
201 
202 /*
203  * Recursive versions of the above.
204  */
205 
206 FILE *  _EXFUN(_fdopen_r, (struct _reent *, int, const char *));
207 FILE *  _EXFUN(_fopen_r, (struct _reent *, const char *, const char *));
208 int _EXFUN(_getchar_r, (struct _reent *));
209 char *  _EXFUN(_gets_r, (struct _reent *, char *));
210 int _EXFUN(_iprintf_r, (struct _reent *, const char *, ...));
211 int _EXFUN(_mkstemp_r, (struct _reent *, char *));
212 char *  _EXFUN(_mktemp_r, (struct _reent *, char *));
213 void    _EXFUN(_perror_r, (struct _reent *, const char *));
214 int _EXFUN(_printf_r, (struct _reent *, const char *, ...));
215 int _EXFUN(_putchar_r, (struct _reent *, int));
216 int _EXFUN(_puts_r, (struct _reent *, const char *));
217 int _EXFUN(_remove_r, (struct _reent *, const char *));
218 int _EXFUN(_rename_r, (struct _reent *,
219                const char *_old, const char *_new));
220 int _EXFUN(_scanf_r, (struct _reent *, const char *, ...));
221 int _EXFUN(_sprintf_r, (struct _reent *, char *, const char *, ...));
222 int _EXFUN(_snprintf_r, (struct _reent *, char *, size_t, const char *, ...));
223 char *  _EXFUN(_tempnam_r, (struct _reent *, const char *, const char *));
224 FILE *  _EXFUN(_tmpfile_r, (struct _reent *));
225 char *  _EXFUN(_tmpnam_r, (struct _reent *, char *));
226 int _EXFUN(_vfprintf_r, (struct _reent *, FILE *, const char *, __VALIST));
227 int _EXFUN(_vprintf_r, (struct _reent *, const char *, __VALIST));
228 int _EXFUN(_vsprintf_r, (struct _reent *, char *, const char *, __VALIST));
229 int _EXFUN(_vsnprintf_r, (struct _reent *, char *, size_t, const char *, __VALIST));
230 
231 /*
232  * Routines internal to the implementation.
233  */
234 
235 int _EXFUN(__srget, (FILE *));
236 int _EXFUN(__swbuf, (int, FILE *));
237 
238 /*
239  * Stdio function-access interface.
240  */
241 
242 #ifndef __STRICT_ANSI__
243 FILE    *_EXFUN(funopen,(const _PTR _cookie,
244         int (*readfn)(_PTR _cookie, char *_buf, int _n),
245         int (*writefn)(_PTR _cookie, const char *_buf, int _n),
246         fpos_t (*seekfn)(_PTR _cookie, fpos_t _off, int _whence),
247         int (*closefn)(_PTR _cookie)));
248 
249 #define fropen(cookie, fn) funopen(cookie, fn, (int (*)())0, (fpos_t (*)())0, (int (*)())0)
250 #define fwopen(cookie, fn) funopen(cookie, (int (*)())0, fn, (fpos_t (*)())0, (int (*)())0)
251 #endif
252 
253 /*
254  * The __sfoo macros are here so that we can 
255  * define function versions in the C library.
256  */
257 #define       __sgetc_raw(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
258 
259 #ifdef __SCLE
260 static __inline__ int __sgetc(FILE *__p)
261   {
262     int __c = __sgetc_raw(__p);
263     if ((__p->_flags & __SCLE) && (__c == '\r'))
264       {
265       int __c2 = __sgetc_raw(__p);
266       if (__c2 == '\n')
267         __c = __c2;
268       else
269         ungetc(__c2, __p);
270       }
271     return __c;
272   }
273 #else
274 #define __sgetc(p) __sgetc_raw(p)
275 #endif
276 
277 #ifdef _never /* __GNUC__ */
278 /* If this inline is actually used, then systems using coff debugging
279    info get hopelessly confused.  21sept93 rich@cygnus.com.  */
280 static __inline int __sputc(int _c, FILE *_p) {
281     if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
282         return (*_p->_p++ = _c);
283     else
284         return (__swbuf(_c, _p));
285 }
286 #else
287 /*
288  * This has been tuned to generate reasonable code on the vax using pcc
289  */
290 #define       __sputc_raw(c, p) \
291     (--(p)->_w < 0 ? \
292         (p)->_w >= (p)->_lbfsize ? \
293             (*(p)->_p = (c)), *(p)->_p != '\n' ? \
294                 (int)*(p)->_p++ : \
295                 __swbuf('\n', p) : \
296             __swbuf((int)(c), p) : \
297         (*(p)->_p = (c), (int)*(p)->_p++))
298 #ifdef __SCLE
299 #define __sputc(c, p) \
300         ((((p)->_flags & __SCLE) && ((c) == '\n')) \
301           ? __sputc_raw('\r', (p)) : 0 , \
302         __sputc_raw((c), (p)))
303 #else
304 #define __sputc(c, p) __sputc_raw(c, p)
305 #endif
306 #endif
307 
308 #define __sfeof(p)  (((p)->_flags & __SEOF) != 0)
309 #define __sferror(p)    (((p)->_flags & __SERR) != 0)
310 #define __sclearerr(p)  ((void)((p)->_flags &= ~(__SERR|__SEOF)))
311 #define __sfileno(p)    ((p)->_file)
312 
313 #define feof(p)     __sfeof(p)
314 #define ferror(p)   __sferror(p)
315 #define clearerr(p) __sclearerr(p)
316 
317 #if 0 /*ndef __STRICT_ANSI__ - FIXME: must initialize stdio first, use fn */
318 #define fileno(p)   __sfileno(p)
319 #endif
320 
321 #ifndef __CYGWIN__
322 #ifndef lint
323 #define getc(fp)    __sgetc(fp)
324 #define putc(x, fp) __sputc(x, fp)
325 #endif /* lint */
326 #endif /* __CYGWIN__ */
327 
328 #define getchar()   getc(stdin)
329 #define putchar(x)  putc(x, stdout)
330 
331 #ifndef __STRICT_ANSI__
332 /* fast always-buffered version, true iff error */
333 #define fast_putc(x,p) (--(p)->_w < 0 ? \
334     __swbuf((int)(x), p) == EOF : (*(p)->_p = (x), (p)->_p++, 0))
335 
336 #define L_cuserid   9       /* posix says it goes in stdio.h :( */
337 #ifdef __CYGWIN__
338 #define L_ctermid       16
339 #endif
340 #endif
341 
342 #ifdef __cplusplus
343 }
344 #endif
345 #endif /* _STDIO_H_ */
5753633 [rkeene@sledge /home/rkeene/devel/cygwin-stuff/cyg-root/usr/include]$

Click here to go back to the directory listing.
Click here to download this file.
last modified: 2001-01-31 15:09:06