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