diff options
author | Manuel Novoa III <mjn3@codepoet.org> | 2002-03-12 01:18:50 +0000 |
---|---|---|
committer | Manuel Novoa III <mjn3@codepoet.org> | 2002-03-12 01:18:50 +0000 |
commit | 03e039820dc5092e27e81f3671652f25da7f25f1 (patch) | |
tree | 37bddad6951b8a6aa5d75184353705f672217812 /include | |
parent | ff3e48d94097ed02480bb0df538620b221ccd72f (diff) |
Swap in the new stdio code.
Diffstat (limited to 'include')
-rw-r--r-- | include/printf.h | 247 | ||||
-rw-r--r-- | include/stdio.h | 92 | ||||
-rw-r--r-- | include/stdio_ext.h | 87 |
3 files changed, 364 insertions, 62 deletions
diff --git a/include/printf.h b/include/printf.h new file mode 100644 index 000000000..8b0a66c88 --- /dev/null +++ b/include/printf.h @@ -0,0 +1,247 @@ +/* Copyright (C) 1991-1993,1995-1999,2000,2001 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* March 11, 2001 Manuel Novoa III + * + * Modified as appropriate for my new stdio lib. + */ + +#ifndef _PRINTF_H + +#define _PRINTF_H 1 +#include <features.h> + +__BEGIN_DECLS + +#define __need_FILE +#include <stdio.h> +#define __need_size_t +#define __need_wchar_t +#include <stddef.h> + +/* WARNING -- This is definitely nonportable... but it seems to work + * with gcc, which is currently the only "supported" compiler. + * The library code uses bitmasks for space-efficiency (you can't + * set/test multiple bitfields in one operation). Unfortunatly, we + * need to support bitfields since that's what glibc uses. So, we take + * advantage of how gcc lays out bitfields to create an appropriate + * mapping. By defining __PRINTF_INFO_NO_BITFIELD we access the + * bitfields using bitmasks in a single flag variable. + * + * WARNING -- This may very well fail if built with -fpack-struct!!! + * + * TODO -- Add a validation test. + * TODO -- Add an option to build in a shim translation function if + * the bitfield<->bitmask mapping fails. + */ +/* #define __PRINTF_INFO_NO_BITFIELD */ +#include <endian.h> + +struct printf_info +{ + int prec; /* Precision. */ + int width; /* Width. */ +#ifdef __STDIO_WIDE /* TODO: temporary fix for uClibc */ + wchar_t spec; /* Format letter. */ +#else + int spec; +#endif +#ifndef __PRINTF_INFO_NO_BITFIELD +#if __BYTE_ORDER == __LITTLE_ENDIAN + unsigned int space:1; /* Space flag. */ + unsigned int showsign:1; /* + flag. */ + unsigned int extra:1; /* For special use. */ + unsigned int left:1; /* - flag. */ + unsigned int alt:1; /* # flag. */ + unsigned int group:1; /* ' flag. */ + unsigned int i18n:1; /* I flag. */ + unsigned int wide:1; /* Nonzero for wide character streams. */ + unsigned int is_char:1; /* hh flag. */ + unsigned int is_short:1; /* h flag. */ + unsigned int is_long:1; /* l flag. */ + unsigned int is_long_double:1;/* L flag. */ + +#elif __BYTE_ORDER == __BIG_ENDIAN + + unsigned int __padding:20;/* non-gnu -- total of 32 bits on 32bit arch */ + unsigned int is_long_double:1;/* L flag. */ + unsigned int is_long:1; /* l flag. */ + unsigned int is_short:1; /* h flag. */ + unsigned int is_char:1; /* hh flag. */ + unsigned int wide:1; /* Nonzero for wide character streams. */ + unsigned int i18n:1; /* I flag. */ + unsigned int group:1; /* ' flag. */ + unsigned int alt:1; /* # flag. */ + unsigned int left:1; /* - flag. */ + unsigned int extra:1; /* For special use. */ + unsigned int showsign:1; /* + flag. */ + unsigned int space:1; /* Space flag. */ + +#else +#error unsupported byte order! +#endif + +#define PRINT_INFO_FLAG_VAL(INFO_PTR,BITFIELD) (INFO_PTR)->BITFIELD +#define PRINT_INFO_SET_FLAG(INFO_PTR,BITFIELD) (INFO_PTR)->BITFIELD = 1 +#define PRINT_INFO_CLR_FLAG(INFO_PTR,BITFIELD) (INFO_PTR)->BITFIELD = 0 +#define PRINT_INFO_SET_extra(INFO_PTR,VAL) (INFO_PTR)->extra = (VAL) + +#else /* __PRINTF_INFO_NO_BITFIELD */ + + unsigned int _flags; /* non-gnu */ +#define __PRINT_INFO_FLAG_space (1<<0) +#define __PRINT_INFO_FLAG_showsign (1<<1) +#define __PRINT_INFO_FLAG_extra (1<<2) +#define __PRINT_INFO_FLAG_left (1<<3) +#define __PRINT_INFO_FLAG_alt (1<<4) +#define __PRINT_INFO_FLAG_group (1<<5) +#define __PRINT_INFO_FLAG_i18n (1<<6) +#define __PRINT_INFO_FLAG_wide (1<<7) + +#define __PRINT_INFO_FLAG_is_char (1<<8) +#define __PRINT_INFO_FLAG_is_short (1<<9) +#define __PRINT_INFO_FLAG_is_long (1<<10) +#define __PRINT_INFO_FLAG_is_long_double (1<<11) + +#if defined(__STDC__) && __STDC__ +#define PRINT_INFO_FLAG_VAL(INFO_PTR,BITFIELD) \ + ((INFO_PTR)->_flags & __PRINT_INFO_FLAG_##BITFIELD) +#define PRINT_INFO_SET_FLAG(INFO_PTR,BITFIELD) \ + ((INFO_PTR)->_flags |= __PRINT_INFO_FLAG_##BITFIELD) +#define PRINT_INFO_CLR_FLAG(INFO_PTR,BITFIELD) \ + ((INFO_PTR)->_flags &= ~__PRINT_INFO_FLAG_##BITFIELD) +#else +#define PRINT_INFO_FLAG_VAL(INFO_PTR,BITFIELD) \ + ((INFO_PTR)->_flags & __PRINT_INFO_FLAG_/**/BITFIELD) +#define PRINT_INFO_SET_FLAG(INFO_PTR,BITFIELD) \ + ((INFO_PTR)->_flags |= __PRINT_INFO_FLAG_/**/BITFIELD) +#define PRINT_INFO_CLR_FLAG(INFO_PTR,BITFIELD) \ + ((INFO_PTR)->_flags &= ~__PRINT_INFO_FLAG_/**/BITFIELD) +#endif +#define PRINT_INFO_SET_extra(INFO_PTR,VAL) \ + ((INFO_PTR)->_flags |= (((INFO_PTR)->_flags & ~1) | ((VAL) & 1))) +#endif /* __PRINTF_INFO_NO_BITFIELD */ +#ifdef __STDIO_WIDE /* TODO: temporary fix for uClibc */ + wchar_t pad; /* Padding character. */ +#else + int pad; +#endif +}; + + +/* Type of a printf specifier-handler function. + STREAM is the FILE on which to write output. + INFO gives information about the format specification. + ARGS is a vector of pointers to the argument data; + the number of pointers will be the number returned + by the associated arginfo function for the same INFO. + + The function should return the number of characters written, + or -1 for errors. */ + +typedef int printf_function (FILE *__stream, + __const struct printf_info *__info, + __const void *__const *__args); + +/* Type of a printf specifier-arginfo function. + INFO gives information about the format specification. + N, ARGTYPES, and return value are as for parse_printf_format. */ + +typedef int printf_arginfo_function (__const struct printf_info *__info, + size_t __n, int *__argtypes); + + +/* Register FUNC to be called to format SPEC specifiers; ARGINFO must be + specified to determine how many arguments a SPEC conversion requires and + what their types are. */ + +extern int register_printf_function (int __spec, printf_function __func, + printf_arginfo_function __arginfo); + + +/* Parse FMT, and fill in N elements of ARGTYPES with the + types needed for the conversions FMT specifies. Returns + the number of arguments required by FMT. + + The ARGINFO function registered with a user-defined format is passed a + `struct printf_info' describing the format spec being parsed. A width + or precision of INT_MIN means a `*' was used to indicate that the + width/precision will come from an arg. The function should fill in the + array it is passed with the types of the arguments it wants, and return + the number of arguments it wants. */ + +extern size_t parse_printf_format (__const char *__restrict __fmt, size_t __n, + int *__restrict __argtypes) __THROW; + + +/* Codes returned by `parse_printf_format' for basic types. + + These values cover all the standard format specifications. + Users can add new values after PA_LAST for their own types. */ + +/* WARNING -- The above is not entirely true, even for glibc. + * As far as the library code is concerned, such args are treated + * as 'your type' pointers if qualified by PA_FLAG_PTR. If they + * aren't qualified as pointers, I _think_ glibc just ignores them + * and carries on. I think it should be treated as an error. */ + +enum +{ /* C type: */ + PA_INT, /* int */ + PA_CHAR, /* int, cast to char */ + PA_WCHAR, /* wide char */ + PA_STRING, /* const char *, a '\0'-terminated string */ + PA_WSTRING, /* const wchar_t *, wide character string */ + PA_POINTER, /* void * */ + PA_FLOAT, /* float */ + PA_DOUBLE, /* double */ + __PA_NOARG, /* non-glibc -- signals non-arg width or prec */ + PA_LAST +}; + +/* Flag bits that can be set in a type returned by `parse_printf_format'. */ +/* WARNING -- These differ in value from what glibc uses. */ +#define PA_FLAG_MASK (0xff00) +#define __PA_FLAG_CHAR (0x0100) /* non-gnu -- to deal with hh */ +#define PA_FLAG_SHORT (0x0200) +#define PA_FLAG_LONG (0x0400) +#define PA_FLAG_LONG_LONG (0x0800) +#define PA_FLAG_LONG_DOUBLE PA_FLAG_LONG_LONG +#define PA_FLAG_PTR (0x1000) /* TODO -- make dynamic??? */ + +#define __PA_INTMASK (0x0f00) /* non-gnu -- all int flags */ + +/* Function which can be registered as `printf'-handlers. */ + +/* Print floating point value using using abbreviations for the orders + of magnitude used for numbers ('k' for kilo, 'm' for mega etc). If + the format specifier is a uppercase character powers of 1000 are + used. Otherwise powers of 1024. */ +extern int printf_size (FILE *__restrict __fp, + __const struct printf_info *__info, + __const void *__const *__restrict __args) __THROW; + +/* This is the appropriate argument information function for `printf_size'. */ +extern int printf_size_info (__const struct printf_info *__restrict + __info, size_t __n, int *__restrict __argtypes) + __THROW; + + +__END_DECLS + +#endif /* printf.h */ diff --git a/include/stdio.h b/include/stdio.h index e418b2f0b..f39ab8481 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -1,4 +1,4 @@ -/* Define ISO C stdio on top of C++ iostreams. +/* Copyright (C) 1991, 1994-1999, 2000, 2001, 2002 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -37,32 +37,11 @@ __BEGIN_DECLS # define __need_FILE # define __need___FILE #endif /* Don't need FILE. */ -#include <sys/types.h> #if !defined __FILE_defined && defined __need_FILE /* The opaque type of streams. This is the definition used elsewhere. */ - -/* when you add or change fields here, be sure to change the initialization - * in stdio_init and fopen */ - -struct _UC_FILE { - unsigned char *bufpos; /* the next byte to write to or read from */ - unsigned char *bufread; /* the end of data returned by last read() */ - unsigned char *bufwrite; /* 1 + highest address writable by macro */ - unsigned char *bufstart; /* the start of the buffer */ - unsigned char *bufend; /* the end of the buffer; ie the byte after the last - malloc()ed byte */ - struct _UC_FILE * next; - - int fd; /* the file descriptor associated with the stream */ - - unsigned char mode; - unsigned char ungot; - unsigned char unbuf[2]; /* The buffer for 'unbuffered' streams */ -}; - typedef struct _UC_FILE FILE; # define __FILE_defined 1 @@ -83,39 +62,33 @@ typedef struct _UC_FILE __FILE; #ifdef _STDIO_H #undef _STDIO_USES_IOSTREAM +#include <sys/types.h> + +#include <bits/uClibc_stdio.h> + /* This define avoids name pollution if we're using GNU stdarg.h */ # define __need___va_list #include <stdarg.h> - /* The type of the second argument to `fgetpos' and `fsetpos'. */ #ifndef __USE_FILE_OFFSET64 -typedef __off_t fpos_t; +typedef _UC_fpos_t fpos_t; #else -typedef __off64_t fpos_t; +typedef _UC_fpos64_t fpos_t; #endif #ifdef __USE_LARGEFILE64 -typedef __off64_t fpos64_t; +typedef _UC_fpos64_t fpos64_t; #endif /* The possibilities for the third argument to `setvbuf'. */ -#define _IOFBF 0 /* Fully buffered. */ -#define _IOLBF 1 /* Line buffered. */ -#define _IONBF 2 /* No buffering. */ - -/* Possible states for a file stream -- internal use only */ -#define __MODE_BUF 0x03 /* Modal buffering dependent on isatty */ -#define __MODE_FREEBUF 0x04 /* Buffer allocated by stdio code, can free */ -#define __MODE_FREEFIL 0x08 /* FILE allocated by stdio code, can free */ -#define __MODE_UNGOT 0x10 /* Buffer has been polluted by ungetc */ -#define __MODE_TIED 0x20 /* FILE is tied with stdin/stdout */ -#define __MODE_EOF 0x40 /* EOF status */ -#define __MODE_ERR 0x80 /* Error status */ +#define _IOFBF _UC_IOFBF /* Fully buffered. */ +#define _IOLBF _UC_IOLBF /* Line buffered. */ +#define _IONBF _UC_IONBF /* No buffering. */ /* Default buffer size. */ #ifndef BUFSIZ -# define BUFSIZ (512) +# define BUFSIZ _UC_BUFSIZ #endif @@ -155,10 +128,12 @@ typedef __off64_t fpos64_t; extern FILE *stdin; /* Standard input stream. */ extern FILE *stdout; /* Standard output stream. */ extern FILE *stderr; /* Standard error output stream. */ +#ifdef __STDC__ /* C89/C99 say they're macros. Make them happy. */ #define stdin stdin #define stdout stdout #define stderr stderr +#endif /* Remove file FILENAME. */ extern int remove (__const char *__filename) __THROW; @@ -212,8 +187,7 @@ extern int fflush (FILE *__stream) __THROW; extern int fflush_unlocked (FILE *__stream) __THROW; #endif -#if 0 -/*#ifdef __USE_GNU*/ +#ifdef __USE_GNU /* Close all streams. */ extern int fcloseall (void) __THROW; #endif @@ -254,8 +228,8 @@ extern FILE *freopen64 (__const char *__restrict __filename, extern FILE *fdopen (int __fd, __const char *__modes) __THROW; #endif -#if 0 -/*#ifdef __USE_GNU*/ +#ifdef __USE_GNU +#ifdef __STDIO_GLIBC_CUSTOM_STREAMS /* Create a new stream that refers to the given magic cookie, and uses the given functions for input and output. */ extern FILE *fopencookie (void *__restrict __magic_cookie, @@ -271,6 +245,7 @@ extern FILE *fmemopen (void *__s, size_t __len, __const char *__modes) __THROW; extern FILE *open_memstream (char **__restrict __bufloc, size_t *__restrict __sizeloc) __THROW; #endif +#endif /* If BUF is NULL, make STREAM unbuffered. @@ -380,9 +355,7 @@ extern int getchar (void) __THROW; /* The C standard explicitly says this is a macro, so we always do the optimization for it. */ -#define getc(stream) \ - (((stream)->bufpos >= (stream)->bufread) ? fgetc(stream): \ - (*(stream)->bufpos++)) +#define getc(_fp) __GETC(_fp) #if defined __USE_POSIX || defined __USE_MISC /* These are defined in POSIX.1:1996. */ @@ -405,9 +378,7 @@ extern int putchar (int __c) __THROW; /* The C standard explicitly says this can be a macro, so we always do the optimization for it. */ -#define putc(c, stream) \ - (((stream)->bufpos >= (stream)->bufwrite) ? fputc((c), (stream)) \ - : (unsigned char) (*(stream)->bufpos++ = (c)) ) +#define putc(_ch, _fp) __PUTC(_ch, _fp) #ifdef __USE_MISC /* Faster version when locking is not necessary. */ @@ -434,8 +405,7 @@ extern int putw (int __w, FILE *__stream) __THROW; extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream) __THROW; -#if 0 -/*#ifdef __USE_GNU*/ +#ifdef __USE_GNU /* This function does the same as `fgets' but does not lock the stream. */ extern char *fgets_unlocked (char *__restrict __s, int __n, FILE *__restrict __stream) __THROW; @@ -452,15 +422,15 @@ extern char *gets (char *__s) __THROW; NULL), pointing to *N characters of space. It is realloc'd as necessary. Returns the number of characters read (not including the null terminator), or -1 on error or EOF. */ -extern ssize_t __getdelim (char **__restrict __lineptr, +extern __ssize_t __getdelim (char **__restrict __lineptr, size_t *__restrict __n, int __delimiter, FILE *__restrict __stream) __THROW; -extern ssize_t getdelim (char **__restrict __lineptr, +extern __ssize_t getdelim (char **__restrict __lineptr, size_t *__restrict __n, int __delimiter, FILE *__restrict __stream) __THROW; /* Like `getdelim', but reads up to a newline. */ -extern ssize_t getline (char **__restrict __lineptr, +extern __ssize_t getline (char **__restrict __lineptr, size_t *__restrict __n, FILE *__restrict __stream) __THROW; #endif @@ -470,8 +440,7 @@ extern ssize_t getline (char **__restrict __lineptr, extern int fputs (__const char *__restrict __s, FILE *__restrict __stream) __THROW; -#if 0 -/*#ifdef __USE_GNU*/ +#ifdef __USE_GNU /* This function does the same as `fputs' but does not lock the stream. */ extern int fputs_unlocked (__const char *__restrict __s, FILE *__restrict __stream) __THROW; @@ -582,7 +551,7 @@ extern int sys_nerr; extern __const char *__const sys_errlist[]; #endif #if 0 -/*#ifdef __USE_GNU*/ +/* #ifdef __USE_GNU */ extern int _sys_nerr; extern __const char *__const _sys_errlist[]; #endif @@ -591,8 +560,6 @@ extern __const char *__const _sys_errlist[]; #ifdef __USE_POSIX /* Return the system file descriptor for STREAM. */ extern int fileno (FILE *__stream) __THROW; -/* Only use the macro below if you know fp is a valid FILE for a valid fd. */ -#define __fileno(fp) ((fp)->fd) #endif /* Use POSIX. */ #ifdef __USE_MISC @@ -624,7 +591,7 @@ extern char *cuserid (char *__s) __THROW; #if 0 -/*#ifdef __USE_GNU*/ +/* #ifdef __USE_GNU */ struct obstack; /* See <obstack.h>. */ /* Write formatted output to an obstack. */ @@ -636,7 +603,7 @@ extern int obstack_vprintf (struct obstack *__restrict __obstack, #endif /* Use GNU. */ -#if defined __USE_POSIX || defined __USE_MISC +#if (defined __USE_POSIX || defined __USE_MISC) && defined __UCLIBC_HAS_THREADS__ /* These are defined in POSIX.1:1996. */ /* Acquire ownership of STREAM. */ @@ -660,7 +627,8 @@ extern void funlockfile (FILE *__stream) __THROW; /* If we are compiling with optimizing read this file. It contains several optimizing inline functions and macros. */ -#ifdef __USE_EXTERN_INLINES +#if 0 +/* #ifdef __USE_EXTERN_INLINES */ # include <bits/stdio.h> #endif diff --git a/include/stdio_ext.h b/include/stdio_ext.h new file mode 100644 index 000000000..55586ea84 --- /dev/null +++ b/include/stdio_ext.h @@ -0,0 +1,87 @@ +/* Functions to access FILE structure internals. + Copyright (C) 2000, 2001 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* This header contains the same definitions as the header of the same name + on Sun's Solaris OS. */ + +#ifndef _STDIO_EXT_H +#define _STDIO_EXT_H 1 + +#include <stdio.h> + +enum +{ + /* Query current state of the locking status. */ + FSETLOCKING_QUERY = 0, +#define FSETLOCKING_QUERY FSETLOCKING_QUERY + /* The library protects all uses of the stream functions, except for + uses of the *_unlocked functions, by calls equivalent to flockfile(). */ + FSETLOCKING_INTERNAL, +#define FSETLOCKING_INTERNAL FSETLOCKING_INTERNAL + /* The user will take care of locking. */ + FSETLOCKING_BYCALLER +#define FSETLOCKING_BYCALLER FSETLOCKING_BYCALLER +}; + + +__BEGIN_DECLS + +/* Return the size of the buffer of FP in bytes currently in use by + the given stream. */ +extern size_t __fbufsize (FILE *__fp); + + +/* Return non-zero value iff the stream FP is opened readonly, or if the + last operation on the stream was a read operation. */ +extern int __freading (FILE *__fp); + +/* Return non-zero value iff the stream FP is opened write-only or + append-only, or if the last operation on the stream was a write + operation. */ +extern int __fwriting (FILE *__fp); + + +/* Return non-zero value iff stream FP is not opened write-only or + append-only. */ +extern int __freadable (FILE *__fp); + +/* Return non-zero value iff stream FP is not opened read-only. */ +extern int __fwritable (FILE *__fp); + + +/* Return non-zero value iff the stream FP is line-buffered. */ +extern int __flbf (FILE *__fp); + + +/* Discard all pending buffered I/O on the stream FP. */ +extern void __fpurge (FILE *__fp); + +/* Return amount of output in bytes pending on a stream FP. */ +extern size_t __fpending (FILE *__fp); + +/* Flush all line-buffered files. */ +extern void _flushlbf (void); + + +/* Set locking status of stream FP to TYPE. */ +extern int __fsetlocking (FILE *__fp, int __type); + +__END_DECLS + +#endif /* stdio_ext.h */ |