summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/printf.h247
-rw-r--r--include/stdio.h92
-rw-r--r--include/stdio_ext.h87
-rw-r--r--libc/inet/addr.c17
-rw-r--r--libc/misc/assert/__assert.c81
-rw-r--r--libc/misc/internals/Makefile8
-rw-r--r--libc/misc/internals/__uClibc_main.c18
-rw-r--r--libc/misc/internals/dtostr.c423
-rw-r--r--libc/misc/internals/lltostr.c39
-rw-r--r--libc/misc/internals/ltostr.c39
-rw-r--r--libc/misc/internals/tempname.c37
-rw-r--r--libc/misc/internals/ulltostr.c37
-rw-r--r--libc/misc/internals/ultostr.c37
-rw-r--r--libc/misc/internals/zoicheck.c16
-rw-r--r--libc/stdio/Makefile75
-rw-r--r--libc/stdio/getw.c36
-rw-r--r--libc/stdio/old_vfprintf.c (renamed from libc/stdio/printf.c)376
-rw-r--r--libc/stdio/perror.c27
-rw-r--r--libc/stdio/putw.c34
-rw-r--r--libc/stdio/remove.c23
-rw-r--r--libc/stdio/scanf.c83
-rw-r--r--libc/stdio/stdio.c1117
-rw-r--r--libc/stdlib/atexit.c13
-rw-r--r--libc/stdlib/ptsname.c13
-rw-r--r--libc/string/strerror.c26
-rw-r--r--libc/string/strsignal.c28
-rw-r--r--libc/sysdeps/linux/common/bits/uClibc_stdio.h494
-rw-r--r--libpthread/linuxthreads/lockfile.c47
28 files changed, 1190 insertions, 2380 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 */
diff --git a/libc/inet/addr.c b/libc/inet/addr.c
index d1f9c04e6..6b143c6ba 100644
--- a/libc/inet/addr.c
+++ b/libc/inet/addr.c
@@ -10,10 +10,16 @@
* are smaller than the previous functions and don't require static buffers.
* In the process, removed the reference to strcat and cut object size of
* inet_ntoa in half (from 190 bytes down to 94).
+ *
+ * Manuel Novoa III Feb 2002
+ *
+ * Changed to use _int10tostr.
*/
#define __FORCE_GLIBC
#include <features.h>
+#define _STDIO_UTILITY /* For _int10tostr. */
+#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <netinet/in.h>
@@ -80,15 +86,6 @@ const char *cp;
#ifdef L_inet_ntoa
-#include <limits.h>
-
-#if (ULONG_MAX >> 32)
-/* We're set up for 32 bit unsigned longs */
-#error need to check size allocation for static buffer 'buf'
-#endif
-
-extern char *__ultostr(char *buf, unsigned long uval, int base, int uppercase);
-
char *inet_ntoa(in)
struct in_addr in;
{
@@ -101,7 +98,7 @@ struct in_addr in;
q = 0;
p = buf + sizeof(buf) - 1;
for (i=0 ; i < 4 ; i++ ) {
- p = __ultostr(p, addr & 0xff, 10, 0 ) - 1;
+ p = _int10tostr(p, addr & 0xff) - 1;
addr >>= 8;
if (q) {
*q = '.';
diff --git a/libc/misc/assert/__assert.c b/libc/misc/assert/__assert.c
index b98958f43..fba9dc719 100644
--- a/libc/misc/assert/__assert.c
+++ b/libc/misc/assert/__assert.c
@@ -1,49 +1,52 @@
-/* Copyright (C) 1996 Robert de Bath <rdebath@cix.compulink.co.uk>
- * This file is part of the Linux-8086 C library and is distributed
- * under the GNU Library General Public License.
- */
-
-/*
- * Manuel Novoa III Dec 2000
+/* Copyright (C) 2002 Manuel Novoa III
+ * An __assert() function compatible with the modified glibc assert.h
+ * that is used by uClibc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
*
- * Converted to use my new (un)signed long (long) to string routines, which
- * are smaller than the previous functions and don't require static buffers.
+ * This 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#include <unistd.h>
-#include <string.h>
+#define _STDIO_UTILITY /* For _stdio_fdout and _int10tostr. */
+#include <stdio.h>
#include <stdlib.h>
-#include <limits.h>
-
-#if (INT_MAX >> 31)
-/* We're set up for 32 bit ints */
-#error need to check size allocation for buffer 'buf'
-#endif
-
-extern char *__ltostr(char *buf, unsigned long uval, int base, int uppercase);
+#include <unistd.h>
-static void errput(str)
-const char *str;
-{
- write(2, str, strlen(str));
-}
+/* Get the prototype from assert.h as a double-check. */
+#undef NDEBUG
+#include <assert.h>
+#undef assert
-void __assert(assertion, filename, linenumber, function)
-const char *assertion;
-const char *filename;
-int linenumber;
-const char *function;
+void __assert(const char *assertion, const char * filename,
+ int linenumber, const char * function)
{
- char buf[12];
+ char buf[__BUFLEN_INT10TOSTR];
- errput(filename);
- errput(":");
- errput(__ltostr(buf + sizeof(buf) - 1, linenumber, 10, 0));
- errput(function ? ": " : "");
- errput(function ? function : "");
- errput(function ? "() " : "");
- errput(": Assertion \"");
- errput(assertion);
- errput("\" failed.\n");
+ _stdio_fdout(STDERR_FILENO,
+#if 0
+ program_name, /* TODO: support program_name like glibc? */
+ ": ",
+#endif
+ filename,
+ ":",
+ _int10tostr(buf+sizeof(buf)-1, linenumber),
+ ": ",
+ /* Function name isn't available with some compilers. */
+ ((function == NULL) ? "?function?" : function),
+ ": Assertion `",
+ assertion,
+ "' failed.\n",
+ NULL
+ );
abort();
}
diff --git a/libc/misc/internals/Makefile b/libc/misc/internals/Makefile
index 6e1c2c29d..c35c636ef 100644
--- a/libc/misc/internals/Makefile
+++ b/libc/misc/internals/Makefile
@@ -24,13 +24,7 @@
TOPDIR=../../../
include $(TOPDIR)Rules.mak
-CSRC=ultostr.c ltostr.c __uClibc_main.c tempname.c errno.c __errno_location.c __h_errno_location.c
-ifeq ($(HAS_FLOATING_POINT),true)
- CSRC += dtostr.c zoicheck.c
-endif
-ifeq ($(HAS_LONG_LONG),true)
- CSRC += ulltostr.c lltostr.c
-endif
+CSRC=__uClibc_main.c tempname.c errno.c __errno_location.c __h_errno_location.c
COBJS=$(patsubst %.c,%.o, $(CSRC))
OBJS=$(COBJS)
diff --git a/libc/misc/internals/__uClibc_main.c b/libc/misc/internals/__uClibc_main.c
index 7f5e6e805..7c2eaf35c 100644
--- a/libc/misc/internals/__uClibc_main.c
+++ b/libc/misc/internals/__uClibc_main.c
@@ -28,13 +28,13 @@ void __uClibc_main(int argc, char **argv, char **envp)
#ifdef HAVE_ELF
weak_alias(__environ, environ);
-extern void weak_function __init_stdio(void);
-extern void weak_function __stdio_flush_buffers(void);
+extern void weak_function _stdio_init(void);
+extern void weak_function _stdio_term(void);
extern int *weak_const_function __errno_location (void);
extern int *weak_const_function __h_errno_location (void);
#else
-extern void __init_stdio(void);
-extern void __stdio_flush_buffers(void);
+extern void _stdio_init(void);
+extern void _stdio_term(void);
extern int *__errno_location (void);
extern int *__h_errno_location (void);
#endif
@@ -71,8 +71,8 @@ void __uClibc_main(int argc, char **argv, char **envp)
* Initialize stdio here. In the static library case, this will
* be bypassed if not needed because of the weak alias above.
*/
- if (__init_stdio)
- __init_stdio();
+ if (_stdio_init)
+ _stdio_init();
/*
* Note: It is possible that any initialization done above could
@@ -95,7 +95,7 @@ void __uClibc_main(int argc, char **argv, char **envp)
/*
* Define an empty function and use it as a weak alias for the stdio
* initialization routine. That way we don't pull in all the stdio
- * code unless we need to. Similarly, do the same for __stdio_flush_buffers
+ * code unless we need to. Similarly, do the same for _stdio_term
* so as not to include atexit unnecessarily.
*
* NOTE!!! This is only true for the _static_ case!!!
@@ -106,7 +106,7 @@ weak_alias(__environ, environ);
void __uClibc_empty_func(void)
{
}
-weak_alias(__uClibc_empty_func, __init_stdio);
-weak_alias(__uClibc_empty_func, __stdio_flush_buffers);
+weak_alias(__uClibc_empty_func, _stdio_init);
+weak_alias(__uClibc_empty_func, _stdio_term);
#endif
#endif
diff --git a/libc/misc/internals/dtostr.c b/libc/misc/internals/dtostr.c
deleted file mode 100644
index 85ec69b12..000000000
--- a/libc/misc/internals/dtostr.c
+++ /dev/null
@@ -1,423 +0,0 @@
-/*
- * Copyright (C) 2000, 2001 Manuel Novoa III
- *
- * Function: int __dtostr(FILE * fp, size_t size, long double x,
- * char flag[], int width, int preci, char mode)
- *
- * This was written for uClibc to provide floating point support for
- * the printf functions. It handles +/- infinity and nan on i386.
- *
- * Notes:
- *
- * At most MAX_DIGITS significant digits are kept. Any trailing digits
- * are treated as 0 as they are really just the results of rounding noise
- * anyway. If you want to do better, use an arbitary precision arithmetic
- * package. ;-)
- *
- * It should also be fairly portable, as not assumptions are made about the
- * bit-layout of doubles.
- *
- * It should be too difficult to convert this to handle long doubles on i386.
- * For information, see the comments below.
- *
- * TODO:
- * long double and/or float version? (note: for float can trim code some).
- *
- * Decrease the size. This is really much bigger than I'd like.
- */
-
-/*****************************************************************************/
-/* Don't change anything that follows unless you know what you're doing. */
-/*****************************************************************************/
-
-/*
- * Configuration for the scaling power table. Ignoring denormals, you
- * should have 2**EXP_TABLE_SIZE >= LDBL_MAX_EXP >= 2**(EXP_TABLE_SIZE-1).
- * The minimum for standard C is 6. For IEEE 8bit doubles, 9 suffices.