[T106][ZXW-22]7520V3SCV2.01.01.02P42U09_VEC_V0.8_AP_VEC origin source commit

Change-Id: Ic6e05d89ecd62fc34f82b23dcf306c93764aec4b
diff --git a/ap/build/uClibc/libc/stdio/.indent.pro b/ap/build/uClibc/libc/stdio/.indent.pro
new file mode 100644
index 0000000..492ecf1
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/.indent.pro
@@ -0,0 +1,33 @@
+--blank-lines-after-declarations
+--blank-lines-after-procedures
+--break-before-boolean-operator
+--no-blank-lines-after-commas
+--braces-on-if-line
+--braces-on-struct-decl-line
+--comment-indentation25
+--declaration-comment-column25
+--no-comment-delimiters-on-blank-lines
+--cuddle-else
+--continuation-indentation4
+--case-indentation0
+--else-endif-column33
+--space-after-cast
+--line-comments-indentation0
+--declaration-indentation1
+--dont-format-first-column-comments
+--dont-format-comments
+--honour-newlines
+--indent-level4
+/* changed from 0 to 4 */
+--parameter-indentation4
+--line-length78 /* changed from 75 */
+--continue-at-parentheses
+--no-space-after-function-call-names
+--dont-break-procedure-type
+--dont-star-comments
+--leave-optional-blank-lines
+--dont-space-special-semicolon
+--tab-size4
+/* additions by Mark */
+--case-brace-indentation0
+--leave-preprocessor-space
diff --git a/ap/build/uClibc/libc/stdio/Makefile b/ap/build/uClibc/libc/stdio/Makefile
new file mode 100644
index 0000000..11f362a
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/Makefile
@@ -0,0 +1,13 @@
+# Makefile for uClibc
+#
+# Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
+#
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+#
+
+top_srcdir=../../
+top_builddir=../../
+all: objs
+include $(top_builddir)Rules.mak
+include Makefile.in
+include $(top_srcdir)Makerules
diff --git a/ap/build/uClibc/libc/stdio/Makefile.in b/ap/build/uClibc/libc/stdio/Makefile.in
new file mode 100644
index 0000000..ff77bcb
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/Makefile.in
@@ -0,0 +1,112 @@
+# Makefile for uClibc
+#
+# Copyright (C) 2004 Manuel Novoa III <mjn3@uclibc.org>
+# Copyright (C) 2000-2008 Erik Andersen <andersen@uclibc.org>
+#
+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+#
+# Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+#
+
+subdirs += libc/stdio
+
+# SUSv3 functions
+CSRC := \
+	fclose.c fcloseall.c fdopen.c fgetpos.c fopen.c freopen.c \
+	fseeko.c fsetpos.c ftello.c getdelim.c getline.c gets.c getw.c \
+	perror.c puts.c putw.c remove.c rewind.c setbuf.c setbuffer.c \
+	setlinebuf.c setvbuf.c ungetc.c \
+	printf.c vprintf.c vsprintf.c fprintf.c snprintf.c dprintf.c \
+	asprintf.c sprintf.c vasprintf.c vdprintf.c vsnprintf.c \
+	tmpfile.c popen.c ctermid.c
+
+ifeq ($(UCLIBC_HAS_LFS),y)
+CSRC += fgetpos64.c fopen64.c freopen64.c fseeko64.c fsetpos64.c ftello64.c
+endif
+ifeq ($(UCLIBC_SUSV4_LEGACY),y)
+CSRC += tmpnam.c tmpnam_r.c tempnam.c
+endif
+
+# getc -> alias for fgetc
+# putc -> alias for fputc
+# rename is a syscall
+
+# Implementation support functions
+CSRC += \
+	_READ.c _WRITE.c _adjust_pos.c _fopen.c _fwrite.c \
+	_rfill.c _stdio.c _trans2r.c _trans2w.c _wcommit.c \
+	_cs_funcs.c _load_inttype.c _store_inttype.c _uintmaxtostr.c
+ifeq ($(UCLIBC_HAS_FLOATS),y)
+CSRC += _fpmaxtostr.c
+endif
+
+# stdio_ext.h functions
+CSRC += \
+	__fbufsize.c __flbf.c __fpending.c __fpurge.c __freadable.c \
+	__freading.c __fsetlocking.c __fwritable.c __fwriting.c _flushlbf.c
+
+# Other glibc extensions
+ifeq ($(UCLIBC_HAS_GLIBC_CUSTOM_STREAMS),y)
+CSRC += fopencookie.c fmemopen.c open_memstream.c
+endif
+
+# pthread functions
+CSRC += flockfile.c ftrylockfile.c funlockfile.c
+
+# Functions with unlocked versions
+CUSRC := \
+	clearerr.c feof.c ferror.c fflush.c fgetc.c fgets.c fileno.c \
+	fputc.c fputs.c fread.c fwrite.c getchar.c putchar.c
+# getc_unlocked -> alias for fgetc_unlocked
+# putc_unlocked -> alias for fputc_unlocked
+
+# vfprintf and support functions
+ifneq ($(USE_OLD_VFPRINTF),y)
+VF_CSRC := \
+	vfprintf.c \
+	_vfprintf_internal.c \
+	_ppfs_init.c _ppfs_prepargs.c _ppfs_setargs.c _ppfs_parsespec.c \
+	register_printf_function.c parse_printf_format.c
+CSRC += $(VF_CSRC)
+else
+CSRC += old_vfprintf.c
+endif
+
+# vfscanf and support functions plus other *scanf funcs
+CSRC += \
+	vfscanf.c __scan_cookie.c __psfs_parse_spec.c __psfs_do_numeric.c \
+	scanf.c sscanf.c fscanf.c vscanf.c vsscanf.c
+
+ifeq ($(UCLIBC_HAS_WCHAR),y)
+CSRC += _wfwrite.c fwprintf.c swprintf.c vswprintf.c vwprintf.c wprintf.c \
+	fwide.c ungetwc.c
+CUSRC += fgetwc.c getwchar.c fgetws.c fputwc.c putwchar.c fputws.c
+# getwc (fgetwc alias) getwc_unlocked (fgetwc_unlocked alias)
+# putwc (fputwc alias) putwc_unlocked (fputwc_unlocked alias)
+CSRC += vfwprintf.c _vfwprintf_internal.c
+CSRC += wscanf.c swscanf.c fwscanf.c vwscanf.c vswscanf.c vfwscanf.c
+endif
+
+CUSRC_UNLOCKED := $(patsubst %.c,%_unlocked.c,$(CUSRC))
+
+CSRC += $(CUSRC) $(CUSRC_UNLOCKED)
+
+STDIO_DIR := $(top_srcdir)libc/stdio
+STDIO_OUT := $(top_builddir)libc/stdio
+
+STDIO_SRC := $(patsubst %.c,$(STDIO_DIR)/%.c,$(CSRC))
+STDIO_OBJ := $(patsubst %.c,$(STDIO_OUT)/%.o,$(CSRC))
+
+libc-y += $(STDIO_OBJ)
+
+ifneq ($(USE_OLD_VFPRINTF),y)
+libc-nomulti-y += $(patsubst %.c,$(STDIO_OUT)/%.o,$(VF_CSRC))
+endif
+ifeq ($(UCLIBC_HAS_WCHAR),y)
+libc-nomulti-y += $(STDIO_OUT)/vfwprintf.o $(STDIO_OUT)/vfwscanf.o
+endif
+
+objclean-y += CLEAN_libc/stdio
+
+CLEAN_libc/stdio:
+	$(do_rm) $(addprefix $(STDIO_OUT)/*., o os oS)
diff --git a/ap/build/uClibc/libc/stdio/_READ.c b/ap/build/uClibc/libc/stdio/_READ.c
new file mode 100644
index 0000000..02601c0
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/_READ.c
@@ -0,0 +1,67 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+/* Given a reading stream without its end-of-file indicator set and
+ * with no buffered input or ungots, read at most 'bufsize' bytes
+ * into 'buf' (which may be the stream's __bufstart).
+ * If a read error occurs, set the stream's error indicator.
+ * If EOF is encountered, set the stream's end-of-file indicator.
+ *
+ * Returns the number of bytes read, even in EOF and error cases.
+ *
+ * Notes:
+ *   Calling with bufsize == 0 is NOT permitted (unlike __stdio_WRITE).
+ *   NOT THREADSAFE!  Assumes stream already locked if necessary.
+ */
+
+size_t attribute_hidden __stdio_READ(register FILE *stream,
+					unsigned char *buf, size_t bufsize)
+{
+	ssize_t rv = 0;
+
+	__STDIO_STREAM_VALIDATE(stream);
+	assert(stream->__filedes >= -1);
+	assert(__STDIO_STREAM_IS_READING(stream));
+	assert(!__STDIO_STREAM_BUFFER_RAVAIL(stream)); /* Buffer must be empty. */
+	assert(!(stream->__modeflags & __FLAG_UNGOT));
+	assert(bufsize);
+
+	if (!__FEOF_UNLOCKED(stream)) {
+		if (bufsize > SSIZE_MAX) {
+			bufsize = SSIZE_MAX;
+		}
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning EINTR?
+#endif
+/* 	RETRY: */
+		if ((rv = __READ(stream, (char *) buf, bufsize)) <= 0) {
+			if (rv == 0) {
+				__STDIO_STREAM_SET_EOF(stream);
+			} else {
+/* 				if (errno == EINTR) goto RETRY; */
+				__STDIO_STREAM_SET_ERROR(stream);
+				rv = 0;
+			}
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning TODO: Make custom stream read return check optional.
+#endif
+#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
+		} else {
+			assert(rv <= bufsize);
+			if (rv > bufsize) {	/* Read more than bufsize! */
+				abort();
+			}
+#endif
+		}
+	}
+
+	return rv;
+}
diff --git a/ap/build/uClibc/libc/stdio/_WRITE.c b/ap/build/uClibc/libc/stdio/_WRITE.c
new file mode 100644
index 0000000..6af5da8
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/_WRITE.c
@@ -0,0 +1,119 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+/* Given a writing stream with no buffered output, write the
+ * data in 'buf' (which may be the stream's bufstart) of size
+ * 'bufsize' to the stream.  If a write error occurs, set the
+ * stream's error indicator and (if buffering) buffer as much
+ * data as possible (FBF) or only up to '\n' (LBF) to implement
+ * "as if fputc()" clause in the standard.
+ *
+ * Returns the number of bytes written and/or buffered.
+ *
+ * Notes:
+ *   Calling with bufsize == 0 is permitted, and buf is ignored in
+ *     that case.
+ *   We implement fflush() by setting bufpos to bufstart and passing
+ *     bufstart as the buf arg.  If there is a write error, the
+ *     unwritten buffered data will simply be moved to the beginning
+ *     of the buffer.  Since the data obviously fits in the buffer
+ *     and since there will be no '\n' chars in the buffer in the LBF
+ *     case, no data will be lost.
+ *   NOT THREADSAFE!  Assumes stream already locked if necessary.
+ */
+
+size_t attribute_hidden __stdio_WRITE(register FILE *stream,
+					 register const unsigned char *buf, size_t bufsize)
+{
+	size_t todo;
+	ssize_t rv, stodo;
+
+	__STDIO_STREAM_VALIDATE(stream);
+	assert(stream->__filedes >= -1);
+	assert(__STDIO_STREAM_IS_WRITING(stream));
+	assert(!__STDIO_STREAM_BUFFER_WUSED(stream)); /* Buffer must be empty. */
+
+	todo = bufsize;
+
+	while (todo != 0) {
+		stodo = (todo <= SSIZE_MAX) ? todo : SSIZE_MAX;
+		rv = __WRITE(stream, (char *) buf, stodo);
+		if (rv >= 0) {
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning TODO: Make custom stream write return check optional.
+#endif
+#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
+			assert(rv <= stodo);
+			if (rv > stodo) {	/* Wrote more than stodo! */
+/* 				abort(); */
+			}
+#endif
+			todo -= rv;
+			buf += rv;
+		} else {
+
+			__STDIO_STREAM_SET_ERROR(stream);
+
+			/* We buffer data on "transient" errors, but discard it
+			 * on "hard" ones. Example of a hard error:
+			 *
+			 * close(fileno(stdout));
+			 * printf("Hi there 1\n"); // EBADF
+			 * dup2(good_fd, fileno(stdout));
+			 * printf("Hi there 2\n"); // buffers new data
+			 *
+			 * This program should not print "Hi there 1" to good_fd.
+			 * The rationale is that the caller of writing operation
+			 * should check for error and act on it.
+			 * If he didn't, then future users of the stream
+			 * have no idea what to do.
+			 * It's least confusing to at least not burden them with
+			 * some hidden buffered crap in the buffer.
+			 */
+			if (errno != EINTR && errno != EAGAIN) {
+				/* do we have other "soft" errors? */
+				break;
+			}
+#ifdef __STDIO_BUFFERS
+			stodo = __STDIO_STREAM_BUFFER_SIZE(stream);
+			if (stodo != 0) {
+				unsigned char *s;
+
+				if (stodo > todo) {
+					stodo = todo;
+				}
+
+				s = stream->__bufstart;
+
+				do {
+					*s = *buf;
+					if ((*s == '\n')
+						&& __STDIO_STREAM_IS_LBF(stream)
+						) {
+						break;
+					}
+					++s;
+					++buf;
+				} while (--stodo);
+
+				stream->__bufpos = s;
+
+				todo -= (s - stream->__bufstart);
+			}
+#endif /* __STDIO_BUFFERS */
+
+			bufsize -= todo;
+			break;
+		}
+	}
+
+	__STDIO_STREAM_VALIDATE(stream);
+	return bufsize;
+}
diff --git a/ap/build/uClibc/libc/stdio/__fbufsize.c b/ap/build/uClibc/libc/stdio/__fbufsize.c
new file mode 100644
index 0000000..09ade15
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/__fbufsize.c
@@ -0,0 +1,20 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+#include <stdio_ext.h>
+
+/* Solaris function --
+ * Returns the size of the buffer in bytes..
+ */
+
+size_t __fbufsize(register FILE * __restrict stream)
+{
+	__STDIO_STREAM_VALIDATE(stream);
+
+	return __STDIO_STREAM_BUFFER_SIZE(stream);
+}
diff --git a/ap/build/uClibc/libc/stdio/__flbf.c b/ap/build/uClibc/libc/stdio/__flbf.c
new file mode 100644
index 0000000..13d8cea
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/__flbf.c
@@ -0,0 +1,20 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+#include <stdio_ext.h>
+
+/* Solaris function --
+ * Returns nonzero if the stream is line buffered, and 0 otherwise.
+ */
+
+int __flbf(FILE * __restrict stream)
+{
+	__STDIO_STREAM_VALIDATE(stream);
+
+	return __STDIO_STREAM_IS_LBF(stream);
+}
diff --git a/ap/build/uClibc/libc/stdio/__fpending.c b/ap/build/uClibc/libc/stdio/__fpending.c
new file mode 100644
index 0000000..a7fe054
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/__fpending.c
@@ -0,0 +1,35 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+#include <stdio_ext.h>
+
+/* Solaris function --
+ * Returns the number of bytes in the buffer for a writing stream.
+ *
+ * NOTE: GLIBC DIFFERENCE!!!
+ *
+ * glibc will return the number of wide chars pending for wide oriented
+ * streams.  We always return the number of bytes in the buffer, as we
+ * convert wide chars to their multibyte encodings and buffer _those_.
+ */
+
+#ifdef __UCLIBC_HAS_WCHAR__
+#warning Note: Unlike the glibc version, this __fpending returns bytes in buffer for wide streams too!
+
+link_warning(__fpending, "This version of __fpending returns bytes remaining in buffer for both narrow and wide streams.  glibc's version returns wide chars in buffer for the wide stream case.")
+
+#endif
+
+size_t __fpending(register FILE * __restrict stream)
+{
+	__STDIO_STREAM_VALIDATE(stream);
+
+	return (__STDIO_STREAM_IS_WRITING(stream))
+		? __STDIO_STREAM_BUFFER_WUSED(stream)
+		: 0;
+}
diff --git a/ap/build/uClibc/libc/stdio/__fpurge.c b/ap/build/uClibc/libc/stdio/__fpurge.c
new file mode 100644
index 0000000..c17ecf4
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/__fpurge.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+#include <stdio_ext.h>
+
+/* Solaris function --
+ * Discard all buffered data whether reading or writing.
+ */
+
+void __fpurge(register FILE * __restrict stream)
+{
+	__STDIO_STREAM_VALIDATE(stream);
+
+	__STDIO_STREAM_DISABLE_GETC(stream);
+	__STDIO_STREAM_DISABLE_PUTC(stream);
+	__STDIO_STREAM_INIT_BUFREAD_BUFPOS(stream);
+	stream->__ungot[1] = 0;
+
+#ifdef __STDIO_MBSTATE
+	__INIT_MBSTATE(&(stream->__state));
+#endif
+#ifdef __UCLIBC_HAS_WCHAR__
+	stream->__ungot_width[0] = 0;
+#endif
+
+	stream->__modeflags &= ~(__MASK_READING|__FLAG_WRITING);
+
+	__STDIO_STREAM_VALIDATE(stream);
+}
diff --git a/ap/build/uClibc/libc/stdio/__freadable.c b/ap/build/uClibc/libc/stdio/__freadable.c
new file mode 100644
index 0000000..006a66f
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/__freadable.c
@@ -0,0 +1,20 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+#include <stdio_ext.h>
+
+/* Solaris function --
+ * Return nonzero if readable, and 0 if write-only.
+ */
+
+int __freadable(FILE * __restrict stream)
+{
+	__STDIO_STREAM_VALIDATE(stream);
+
+	return !__STDIO_STREAM_IS_WRITEONLY(stream);
+}
diff --git a/ap/build/uClibc/libc/stdio/__freading.c b/ap/build/uClibc/libc/stdio/__freading.c
new file mode 100644
index 0000000..aab91b2
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/__freading.c
@@ -0,0 +1,20 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+#include <stdio_ext.h>
+
+/* Solaris function --
+ * Return nonzero if read-only or was last read from, and 0 otherwise.
+ */
+
+int __freading(FILE * __restrict stream)
+{
+	__STDIO_STREAM_VALIDATE(stream);
+
+	return __STDIO_STREAM_IS_READING_OR_READONLY(stream);
+}
diff --git a/ap/build/uClibc/libc/stdio/__fsetlocking.c b/ap/build/uClibc/libc/stdio/__fsetlocking.c
new file mode 100644
index 0000000..6d4fc18
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/__fsetlocking.c
@@ -0,0 +1,47 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+#include <stdio_ext.h>
+
+
+/* Not threadsafe. */
+
+/* Notes:
+ *   When setting the locking mode, glibc returns the previous setting.
+ *   glibc treats invalid locking_mode args as FSETLOCKING_INTERNAL.
+ */
+
+int __fsetlocking(FILE *stream, int locking_mode)
+{
+#ifdef __UCLIBC_HAS_THREADS__
+	int current = 1 + (stream->__user_locking & 1);
+
+	/* Check constant assumptions.  We can't test at build time
+	 * since these are enums. */
+	assert((FSETLOCKING_QUERY == 0) && (FSETLOCKING_INTERNAL == 1)
+		   && (FSETLOCKING_BYCALLER == 2));
+
+	__STDIO_STREAM_VALIDATE(stream);
+	assert(((unsigned int) locking_mode) <= 2);
+
+	if (locking_mode != FSETLOCKING_QUERY) {
+		stream->__user_locking = ((locking_mode == FSETLOCKING_BYCALLER)
+								  ? 1
+								  : _stdio_user_locking); /* 0 or 2 */
+		__STDIO_STREAM_VALIDATE(stream);
+	}
+
+	return current;
+#else
+	__STDIO_STREAM_VALIDATE(stream);
+	assert(((unsigned int) locking_mode) <= 2);
+
+	return FSETLOCKING_INTERNAL;
+#endif
+}
+libc_hidden_def(__fsetlocking)
diff --git a/ap/build/uClibc/libc/stdio/__fwritable.c b/ap/build/uClibc/libc/stdio/__fwritable.c
new file mode 100644
index 0000000..59c70a6
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/__fwritable.c
@@ -0,0 +1,20 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+#include <stdio_ext.h>
+
+/* Solaris function --
+ * Return nonzero if writable, and 0 if read-only.
+ */
+
+int __fwritable(FILE * __restrict stream)
+{
+	__STDIO_STREAM_VALIDATE(stream);
+
+	return !__STDIO_STREAM_IS_READONLY(stream);
+}
diff --git a/ap/build/uClibc/libc/stdio/__fwriting.c b/ap/build/uClibc/libc/stdio/__fwriting.c
new file mode 100644
index 0000000..926eaa9
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/__fwriting.c
@@ -0,0 +1,20 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+#include <stdio_ext.h>
+
+/* Solaris function --
+ * Return nonzero if write-only or was last written to, and 0 otherwise.
+ */
+
+int __fwriting(FILE * __restrict stream)
+{
+	__STDIO_STREAM_VALIDATE(stream);
+
+	return __STDIO_STREAM_IS_WRITING_OR_WRITEONLY(stream);
+}
diff --git a/ap/build/uClibc/libc/stdio/__psfs_do_numeric.c b/ap/build/uClibc/libc/stdio/__psfs_do_numeric.c
new file mode 100644
index 0000000..e371477
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/__psfs_do_numeric.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define L___psfs_do_numeric
+#include "_scanf.c"
diff --git a/ap/build/uClibc/libc/stdio/__psfs_parse_spec.c b/ap/build/uClibc/libc/stdio/__psfs_parse_spec.c
new file mode 100644
index 0000000..cac9cda
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/__psfs_parse_spec.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define L___psfs_parse_spec
+#include "_scanf.c"
diff --git a/ap/build/uClibc/libc/stdio/__scan_cookie.c b/ap/build/uClibc/libc/stdio/__scan_cookie.c
new file mode 100644
index 0000000..d5d53c4
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/__scan_cookie.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define L___scan_cookie
+#include "_scanf.c"
diff --git a/ap/build/uClibc/libc/stdio/_adjust_pos.c b/ap/build/uClibc/libc/stdio/_adjust_pos.c
new file mode 100644
index 0000000..bc6e905
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/_adjust_pos.c
@@ -0,0 +1,68 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+/* Both ftell() and fseek() (for SEEK_CUR) need to correct the stream's
+ * position to take into account buffered data and ungotten chars.
+ *
+ * If successful, store corrected position in *pos and return >= 0.
+ * Otherwise return < 0.
+ *
+ * If position is unrepresentable, set errno to EOVERFLOW.
+ */
+
+int attribute_hidden __stdio_adjust_position(register FILE * __restrict stream,
+							register __offmax_t *pos)
+{
+	__offmax_t oldpos;
+	int corr;
+
+	if ((corr = stream->__modeflags & __MASK_READING) != 0) {
+		--corr;	/* Correct for ungots. Assume narrow, and fix below. */
+	}
+
+#ifdef __UCLIBC_HAS_WCHAR__
+	if (corr && __STDIO_STREAM_IS_WIDE(stream)) {
+		/* A wide stream and we have at least one ungotten wchar.
+		 * If it is a user ungot, we need to fail since position
+		 * is unspecified as per C99. */
+		if ((corr > 1) || stream->__ungot[1]) { /* User ungetwc, */
+			return -1;			/* so position is undefined. */
+		}
+		corr -= (1 + stream->__ungot_width[1]);
+		if (stream->__state.__mask > 0) { /* Incomplete (bad?) mb char. */
+			corr -= stream->__ungot_width[0];
+		}
+	}
+#endif
+
+#ifdef __STDIO_BUFFERS
+	corr += (((__STDIO_STREAM_IS_WRITING(stream))
+			  ? stream->__bufstart : stream->__bufread)
+			 - stream->__bufpos);
+#endif
+
+	oldpos = *pos;
+
+	/* Range checking cases:
+	 * (pos - corr >  pos) && (corr >  0) : underflow?  return -corr < 0
+	 * (pos - corr >  pos) && (corr <  0) : ok .. return -corr > 0
+	 * (pos - corr <= pos) && (corr >= 0) : ok .. return  corr > 0
+	 * (pos - corr <= pos) && (corr <  0) : overflow ..  return corr < 0
+	 */
+
+	if ((*pos -= corr) > oldpos) {
+		corr = -corr;
+	}
+
+	if (corr < 0) {
+		__set_errno(EOVERFLOW);
+	}
+
+	return corr;
+}
diff --git a/ap/build/uClibc/libc/stdio/_cs_funcs.c b/ap/build/uClibc/libc/stdio/_cs_funcs.c
new file mode 100644
index 0000000..9df93f2
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/_cs_funcs.c
@@ -0,0 +1,67 @@
+/* Copyright (C) 2004-2005 Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+/**********************************************************************/
+#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
+/**********************************************************************/
+
+ssize_t attribute_hidden _cs_read(void *cookie, char *buf, size_t bufsize)
+{
+	return read(*((int *) cookie), buf, bufsize);
+}
+
+/**********************************************************************/
+
+ssize_t attribute_hidden _cs_write(void *cookie, const char *buf, size_t bufsize)
+{
+	return write(*((int *) cookie), (char *) buf, bufsize);
+}
+
+/**********************************************************************/
+
+int attribute_hidden _cs_seek(void *cookie, register __offmax_t *pos, int whence)
+{
+	__offmax_t res;
+
+#ifdef __UCLIBC_HAS_LFS__
+	res = lseek64(*((int *) cookie), *pos, whence);
+#else
+	res = lseek(*((int *) cookie), *pos, whence);
+#endif
+
+	return (res >= 0) ? ((*pos = res), 0) : ((int) res);
+}
+
+/**********************************************************************/
+
+int attribute_hidden _cs_close(void *cookie)
+{
+	return close(*((int *) cookie));
+}
+
+/**********************************************************************/
+#else
+/**********************************************************************/
+
+int attribute_hidden __stdio_seek(FILE *stream, register __offmax_t *pos, int whence)
+{
+	__offmax_t res;
+
+#ifdef __UCLIBC_HAS_LFS__
+	res = lseek64(stream->__filedes, *pos, whence);
+#else
+	res = lseek(stream->__filedes, *pos, whence);
+#endif
+
+	return (res >= 0) ? ((*pos = res), 0) : ((int) res);
+}
+
+/**********************************************************************/
+#endif
+/**********************************************************************/
diff --git a/ap/build/uClibc/libc/stdio/_flushlbf.c b/ap/build/uClibc/libc/stdio/_flushlbf.c
new file mode 100644
index 0000000..c322c3e
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/_flushlbf.c
@@ -0,0 +1,19 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+#include <stdio_ext.h>
+
+
+/* Solaris function --
+ * Flush all line buffered (writing) streams.
+ */
+
+void _flushlbf(void)
+{
+	__STDIO_FLUSH_LBF_STREAMS;
+}
diff --git a/ap/build/uClibc/libc/stdio/_fopen.c b/ap/build/uClibc/libc/stdio/_fopen.c
new file mode 100644
index 0000000..5bc61cf
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/_fopen.c
@@ -0,0 +1,233 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+/*
+ * Cases:
+ *  fopen64  : filename != NULL, stream == NULL, filedes == -2
+ *  fopen    : filename != NULL, stream == NULL, filedes == -1
+ *  freopen  : filename != NULL, stream != NULL, filedes == -1
+ *  fdopen   : filename == NULL, stream == NULL, filedes valid
+ *
+ *  fsfopen  : filename != NULL, stream != NULL, filedes == -1
+ */
+
+#if (O_ACCMODE != 3) || (O_RDONLY != 0) || (O_WRONLY != 1) || (O_RDWR != 2)
+#error Assumption violated - mode constants
+#endif
+
+#ifndef O_LARGEFILE
+#define O_LARGEFILE 0
+#endif
+
+/* Internal function -- reentrant (locks open file list) */
+
+FILE attribute_hidden *_stdio_fopen(intptr_t fname_or_mode,
+				   register const char * __restrict mode,
+				   register FILE * __restrict stream, int filedes)
+{
+	__mode_t open_mode;
+	int i;
+
+	/* Parse the specified mode. */
+	open_mode = O_RDONLY;
+	if (*mode != 'r') {			/* Not read... */
+		open_mode = (O_WRONLY | O_CREAT | O_TRUNC);
+		if (*mode != 'w') {		/* Not write (create or truncate)... */
+			open_mode = (O_WRONLY | O_CREAT | O_APPEND);
+			if (*mode != 'a') {	/* Not write (create or append)... */
+			DO_EINVAL:
+				__set_errno(EINVAL); /* So illegal mode. */
+				if (stream) {
+				FREE_STREAM:
+					assert(!(stream->__modeflags & __FLAG_FREEBUF));
+					__STDIO_STREAM_FREE_FILE(stream);
+				}
+				return NULL;
+			}
+		}
+	}
+
+	if ((mode[1] == 'b')) {		/* Binary mode (NO-OP currently). */
+		++mode;
+	}
+
+	if (mode[1] == '+') {			/* Read and Write. */
+		++mode;
+		open_mode |= (O_RDONLY | O_WRONLY);
+		open_mode += (O_RDWR - (O_RDONLY | O_WRONLY));
+	}
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning CONSIDER: Implement glibc ccs option to bind a codeset?
+#warning CONSIDER: Implement glibc mmap option for readonly files?
+#warning CONSIDER: Implement a text mode using custom read/write funcs?
+#endif
+#if defined(__UCLIBC_HAS_FOPEN_EXCLUSIVE_MODE__) || defined(__UCLIBC_HAS_FOPEN_LARGEFILE_MODE__) || \
+    defined(__UCLIBC_HAS_FOPEN_CLOSEEXEC_MODE__)
+
+	while (*++mode) {
+# ifdef __UCLIBC_HAS_FOPEN_EXCLUSIVE_MODE__
+		if (*mode == 'x') {	   /* Open exclusive (a glibc extension). */
+			open_mode |= O_EXCL;
+			continue;
+		}
+# endif
+# ifdef __UCLIBC_HAS_FOPEN_LARGEFILE_MODE__
+		if (*mode == 'F') {		/* Open as large file (uClibc extension). */
+			open_mode |= O_LARGEFILE;
+			continue;
+		}
+# endif
+# ifdef __UCLIBC_HAS_FOPEN_CLOSEEXEC_MODE__
+		if (*mode == 'e') {		/* Close on exec (a glibc extension). */
+			open_mode |= O_CLOEXEC;
+			continue;
+		}
+# endif
+ 	}
+
+#endif
+
+	if (!stream) {		  /* Need to allocate a FILE (not freopen). */
+		if ((stream = malloc(sizeof(FILE))) == NULL) {
+			return stream;
+		}
+		stream->__modeflags = __FLAG_FREEFILE;
+#ifdef __STDIO_BUFFERS
+		stream->__bufstart = NULL; /* We allocate a buffer below. */
+#endif
+#ifdef __UCLIBC_HAS_THREADS__
+		/* We only initialize the mutex in the non-freopen case. */
+		/* stream->__user_locking = _stdio_user_locking; */
+		STDIO_INIT_MUTEX(stream->__lock);
+#endif
+	}
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning TODO: Verify fdopen append behavior of glibc.
+#endif
+
+	if (filedes >= 0) {			/* Handle fdopen trickery. */
+		stream->__filedes = filedes;
+		/* NOTE: it is insufficient to just check R/W/RW agreement.
+		 * We must also check largefile compatibility if applicable.
+		 * Also, if append mode is desired for fdopen but O_APPEND isn't
+		 * currently set, then set it as recommended by SUSv3.  However,
+		 * if append mode is not specified for fdopen but O_APPEND is set,
+		 * leave it set (glibc compat). */
+		i = (open_mode & (O_ACCMODE|O_LARGEFILE)) + 1;
+
+		/* NOTE: fopencookie needs changing if the basic check changes! */
+		if ((i & ((int)fname_or_mode + 1)) != i) /* Basic agreement? */
+			goto DO_EINVAL;
+		if ((open_mode & ~(__mode_t)fname_or_mode) & O_APPEND) {
+			if (fcntl(filedes, F_SETFL, O_APPEND))	/* Need O_APPEND. */
+				goto DO_EINVAL;
+		}
+		/* For later... to reflect largefile setting in stream flags. */
+		__STDIO_WHEN_LFS( open_mode |= (((__mode_t) fname_or_mode)
+										& O_LARGEFILE) );
+	} else {
+		__STDIO_WHEN_LFS( if (filedes < -1) open_mode |= O_LARGEFILE );
+		if ((stream->__filedes = open(((const char *) fname_or_mode),
+									  open_mode, 0666)) < 0) {
+			goto FREE_STREAM;
+		}
+	}
+
+	stream->__modeflags &= __FLAG_FREEFILE;
+/* 	stream->__modeflags &= ~(__FLAG_READONLY|__FLAG_WRITEONLY); */
+
+	stream->__modeflags |=		/* Note: Makes assumptions about flag vals! */
+#if (O_APPEND != __FLAG_APPEND) || ((O_LARGEFILE != __FLAG_LARGEFILE) && (O_LARGEFILE != 0))
+# if (O_APPEND != __FLAG_APPEND)
+		((open_mode & O_APPEND) ? __FLAG_APPEND : 0) |
+# else
+		(open_mode & O_APPEND) |
+# endif
+# if (O_LARGEFILE != __FLAG_LARGEFILE) && (O_LARGEFILE != 0)
+		((open_mode & O_LARGEFILE) ? __FLAG_LARGEFILE : 0) |
+# else
+		(open_mode & O_LARGEFILE) |
+# endif
+#else
+		(open_mode & (O_APPEND|O_LARGEFILE)) | /* i386 linux and elks */
+#endif
+		((((open_mode & O_ACCMODE) + 1) ^ 0x03) * __FLAG_WRITEONLY);
+
+#ifdef __STDIO_BUFFERS
+	if (stream->__filedes != INT_MAX) {
+		/* NB: fopencookie uses bogus filedes == INT_MAX,
+		 * avoiding isatty() in that case.
+		 */
+		i = errno; /* preserve errno against isatty call. */
+		if (isatty(stream->__filedes))
+			stream->__modeflags |= __FLAG_LBF;
+		__set_errno(i);
+	}
+
+	if (!stream->__bufstart) {
+		if ((stream->__bufstart = malloc(BUFSIZ)) != NULL) {
+			stream->__bufend = stream->__bufstart + BUFSIZ;
+			stream->__modeflags |= __FLAG_FREEBUF;
+		} else {
+# if __STDIO_BUILTIN_BUF_SIZE > 0
+			stream->__bufstart = stream->__builtinbuf;
+			stream->__bufend = stream->__builtinbuf + sizeof(stream->__builtinbuf);
+# else  /* __STDIO_BUILTIN_BUF_SIZE > 0 */
+			stream->__bufend = stream->__bufstart;
+# endif /* __STDIO_BUILTIN_BUF_SIZE > 0 */
+		}
+	}
+
+	__STDIO_STREAM_DISABLE_GETC(stream);
+	__STDIO_STREAM_DISABLE_PUTC(stream);
+	__STDIO_STREAM_INIT_BUFREAD_BUFPOS(stream);
+#endif
+
+	__STDIO_STREAM_RESET_GCS(stream);
+
+#ifdef __UCLIBC_HAS_WCHAR__
+	stream->__ungot_width[0] = 0;
+#endif
+#ifdef __STDIO_MBSTATE
+	__INIT_MBSTATE(&(stream->__state));
+#endif
+
+#ifdef __UCLIBC_HAS_THREADS__
+	/* Even in the freopen case, we reset the user locking flag. */
+	stream->__user_locking = _stdio_user_locking;
+	/* STDIO_INIT_MUTEX(stream->__lock); */
+#endif
+
+#ifdef __STDIO_HAS_OPENLIST
+#if defined(__UCLIBC_HAS_THREADS__) && defined(__STDIO_BUFFERS)
+	if (!(stream->__modeflags & __FLAG_FREEFILE))
+	{
+		/* An freopen call so the file was never removed from the list. */
+	}
+	else
+#endif
+	{
+		/* We have to lock the del mutex in case another thread wants to fclose()
+		 * the last file. */
+		__STDIO_THREADLOCK_OPENLIST_DEL;
+		__STDIO_THREADLOCK_OPENLIST_ADD;
+		stream->__nextopen = _stdio_openlist; /* New files are inserted at */
+		_stdio_openlist = stream;			  /*   the head of the list. */
+		__STDIO_THREADUNLOCK_OPENLIST_ADD;
+		__STDIO_THREADUNLOCK_OPENLIST_DEL;
+	}
+#endif
+
+	__STDIO_STREAM_VALIDATE(stream);
+
+	return stream;
+}
diff --git a/ap/build/uClibc/libc/stdio/_fpmaxtostr.c b/ap/build/uClibc/libc/stdio/_fpmaxtostr.c
new file mode 100644
index 0000000..1332a20
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/_fpmaxtostr.c
@@ -0,0 +1,765 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+#include <printf.h>
+#include <float.h>
+#include <locale.h>
+#include <bits/uClibc_fpmax.h>
+
+
+typedef size_t (__fp_outfunc_t)(FILE *fp, intptr_t type, intptr_t len,
+								intptr_t buf);
+
+
+/* Copyright (C) 2000, 2001, 2003      Manuel Novoa III
+ *
+ * Function:
+ *
+ *     ssize_t _fpmaxtostr(FILE * fp, __fpmax_t x, struct printf_info *info,
+ *                         __fp_outfunc_t fp_outfunc);
+ *
+ * This is derived from the old _dtostr, whic I wrote for uClibc to provide
+ * floating point support for the printf functions.  It handles +/- infinity,
+ * nan, and signed 0 assuming you have ieee arithmetic.  It also now handles
+ * digit grouping (for the uClibc supported locales) and hexadecimal float
+ * notation.  Finally, via the fp_outfunc parameter, it now supports wide
+ * output.
+ *
+ * Notes:
+ *
+ * At most DECIMAL_DIG 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 no assumptions are made about the
+ * bit-layout of doubles.  Of course, that does make it less efficient than
+ * it could be.
+ *
+ */
+
+/*****************************************************************************/
+/* Don't change anything that follows unless you know what you're doing.     */
+/*****************************************************************************/
+/* Fairly portable nan check.  Bitwise for i386 generated larger code.
+ * If you have a better version, comment this out.
+ */
+#define isnan(x)             ((x) != (x))
+
+/* Without seminumerical functions to examine the sign bit, this is
+ * about the best we can do to test for '-0'.
+ */
+#define zeroisnegative(x)    ((1./(x)) < 0)
+
+/*****************************************************************************/
+/* Don't change anything that follows peroid!!!  ;-)                         */
+/*****************************************************************************/
+#ifdef __UCLIBC_HAS_HEXADECIMAL_FLOATS__
+#if FLT_RADIX != 2
+#error FLT_RADIX != 2 is not currently supported
+#endif
+#endif /* __UCLIBC_HAS_HEXADECIMAL_FLOATS__ */
+
+#define NUM_HEX_DIGITS      ((FPMAX_MANT_DIG + 3)/ 4)
+
+/* WARNING: Adjust _fp_out_wide() below if this changes! */
+/* With 32 bit ints, we can get 9 decimal digits per block. */
+#define DIGITS_PER_BLOCK     9
+#define HEX_DIGITS_PER_BLOCK 8
+
+/* Maximum number of subcases to output double is...
+ *  0 - sign
+ *  1 - padding and initial digit
+ *  2 - digits left of the radix
+ *  3 - 0s left of the radix        or   radix
+ *  4 - radix                       or   digits right of the radix
+ *  5 - 0s right of the radix
+ *  6 - exponent
+ *  7 - trailing space padding
+ * although not all cases may occur.
+ */
+#define MAX_CALLS 8
+
+/*****************************************************************************/
+
+#define NUM_DIGIT_BLOCKS   ((DECIMAL_DIG+DIGITS_PER_BLOCK-1)/DIGITS_PER_BLOCK)
+#define NUM_HEX_DIGIT_BLOCKS \
+   ((NUM_HEX_DIGITS+HEX_DIGITS_PER_BLOCK-1)/HEX_DIGITS_PER_BLOCK)
+
+/* WARNING: Adjust _fp_out_wide() below if this changes! */
+
+/* extra space for '-', '.', 'e+###', and nul */
+#define BUF_SIZE  ( 3 + NUM_DIGIT_BLOCKS * DIGITS_PER_BLOCK )
+
+/*****************************************************************************/
+
+static const char fmt[] = "inf\0INF\0nan\0NAN\0.\0,";
+
+#define INF_OFFSET        0		/* must be 1st */
+#define NAN_OFFSET        8		/* must be 2nd.. see hex sign handling */
+#define DECPT_OFFSET     16
+#define THOUSEP_OFFSET   18
+
+#define EMPTY_STRING_OFFSET 3
+
+/*****************************************************************************/
+#if FPMAX_MAX_10_EXP < -FPMAX_MIN_10_EXP
+#error scaling code can not handle FPMAX_MAX_10_EXP < -FPMAX_MIN_10_EXP
+#endif
+
+static const __fpmax_t exp10_table[] =
+{
+	1e1L, 1e2L, 1e4L, 1e8L, 1e16L, 1e32L,	/* floats */
+#if FPMAX_MAX_10_EXP < 32
+#error unsupported FPMAX_MAX_10_EXP (< 32).  ANSI/ISO C requires >= 37.
+#endif
+#if FPMAX_MAX_10_EXP >= 64
+	1e64L,
+#endif
+#if FPMAX_MAX_10_EXP >= 128
+	1e128L,
+#endif
+#if FPMAX_MAX_10_EXP >= 256
+	1e256L,
+#endif
+#if FPMAX_MAX_10_EXP >= 512
+	1e512L,
+#endif
+#if FPMAX_MAX_10_EXP >= 1024
+	1e1024L,
+#endif
+#if FPMAX_MAX_10_EXP >= 2048
+	1e2048L,
+#endif
+#if FPMAX_MAX_10_EXP >= 4096
+	1e4096L
+#endif
+#if FPMAX_MAX_10_EXP >= 8192
+#error unsupported FPMAX_MAX_10_EXP.  please increase table
+#endif
+};
+
+#define EXP10_TABLE_SIZE     (sizeof(exp10_table)/sizeof(exp10_table[0]))
+#define EXP10_TABLE_MAX      (1U<<(EXP10_TABLE_SIZE-1))
+
+/*****************************************************************************/
+#ifdef __UCLIBC_HAS_HEXADECIMAL_FLOATS__
+
+#if FLT_RADIX != 2
+#error FLT_RADIX != 2 is not currently supported
+#endif
+
+#if FPMAX_MAX_EXP < -FPMAX_MIN_EXP
+#error scaling code can not handle FPMAX_MAX_EXP < -FPMAX_MIN_EXP
+#endif
+
+static const __fpmax_t exp16_table[] = {
+	0x1.0p4L, 0x1.0p8L, 0x1.0p16L, 0x1.0p32L, 0x1.0p64L,
+#if FPMAX_MAX_EXP >= 128
+	0x1.0p128L,
+#endif
+#if FPMAX_MAX_EXP >= 256
+	0x1.0p256L,
+#endif
+#if FPMAX_MAX_EXP >= 512
+	0x1.0p512L,
+#endif
+#if FPMAX_MAX_EXP >= 1024
+	0x1.0p1024L,
+#endif
+#if FPMAX_MAX_EXP >= 2048
+	0x1.0p2048L,
+#endif
+#if FPMAX_MAX_EXP >= 4096
+	0x1.0p4096L,
+#endif
+#if FPMAX_MAX_EXP >= 8192
+	0x1.0p8192L,
+#endif
+#if FPMAX_MAX_EXP >= 16384
+	0x1.0p16384L
+#endif
+#if FPMAX_MAX_EXP >= 32768
+#error unsupported FPMAX_MAX_EXP.  please increase table
+#endif
+};
+
+#define EXP16_TABLE_SIZE     (sizeof(exp16_table)/sizeof(exp16_table[0]))
+#define EXP16_TABLE_MAX      (1U<<(EXP16_TABLE_SIZE-1))
+
+#endif /* __UCLIBC_HAS_HEXADECIMAL_FLOATS__ */
+/*****************************************************************************/
+
+#define FPO_ZERO_PAD    (0x80 | '0')
+#define FPO_STR_WIDTH   (0x80 | ' ');
+#define FPO_STR_PREC    'p'
+
+ssize_t _fpmaxtostr(FILE * fp, __fpmax_t x, struct printf_info *info,
+					__fp_outfunc_t fp_outfunc) attribute_hidden;
+ssize_t _fpmaxtostr(FILE * fp, __fpmax_t x, struct printf_info *info,
+					__fp_outfunc_t fp_outfunc)
+{
+#ifdef __UCLIBC_HAS_HEXADECIMAL_FLOATS__
+	__fpmax_t lower_bnd;
+	__fpmax_t upper_bnd = 1e9;
+#endif /* __UCLIBC_HAS_HEXADECIMAL_FLOATS__ */
+#ifdef __UCLIBC_HAS_HEXADECIMAL_FLOATS__
+	uint_fast32_t base = 10;
+	const __fpmax_t *power_table;
+	int dpb = DIGITS_PER_BLOCK;
+	int ndb = NUM_DIGIT_BLOCKS;
+	int nd = DECIMAL_DIG;
+	int sufficient_precision = 0;
+#endif /* __UCLIBC_HAS_HEXADECIMAL_FLOATS__ */
+#ifdef __UCLIBC_HAS_GLIBC_DIGIT_GROUPING__
+	int num_groups = 0;
+	int initial_group;	   /* This does not need to be initialized. */
+	int tslen;			   /* This does not need to be initialized. */
+	int nblk2;			   /* This does not need to be initialized. */
+	const char *ts;		   /* This does not need to be initialized. */
+#endif /* __UCLIBC_HAS_GLIBC_DIGIT_GROUPING__ */
+	int round, o_exp;
+	int exp;
+	int width, preci;
+	int cnt;
+	char *s;
+	char *e;
+	intptr_t pc_fwi[3*MAX_CALLS];
+	intptr_t *ppc;
+	intptr_t *ppc_last;
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning TODO: The size of exp_buf[] should really be determined by the float constants.
+#endif /* __UCLIBC_MJN3_ONLY__ */
+	char exp_buf[16];
+	char buf[BUF_SIZE];
+	char sign_str[6];			/* Last 2 are for 1st digit + nul. */
+	char o_mode;
+	char mode;
+
+
+	width = info->width;
+	preci = info->prec;
+	mode = info->spec;
+
+	*exp_buf = 'e';
+	if ((mode|0x20) == 'a') {
+#ifdef __UCLIBC_HAS_HEXADECIMAL_FLOATS__
+		*exp_buf = 'p';
+		if (preci < 0) {
+			preci = NUM_HEX_DIGITS;
+			sufficient_precision = 1;
+		}
+#else
+		mode += ('g' - 'a');
+#endif
+	}
+
+	if (preci < 0) {
+		preci = 6;
+	}
+
+	*sign_str = '\0';
+	if (PRINT_INFO_FLAG_VAL(info,showsign)) {
+		*sign_str = '+';
+	} else if (PRINT_INFO_FLAG_VAL(info,space)) {
+		*sign_str = ' ';
+	}
+
+	*(sign_str+1) = 0;
+	pc_fwi[5] = INF_OFFSET;
+	if (isnan(x)) {				/* First, check for nan. */
+		pc_fwi[5] = NAN_OFFSET;
+		goto INF_NAN;
+	}
+
+	if (x == 0) {				/* Handle 0 now to avoid false positive. */
+#ifdef __UCLIBC_HAVE_SIGNED_ZERO__
+		if (zeroisnegative(x)) { /* Handle 'signed' zero. */
+			*sign_str = '-';
+		}
+#endif /* __UCLIBC_HAVE_SIGNED_ZERO__ */
+		exp = -1;
+		goto GENERATE_DIGITS;
+	}
+
+	if (x < 0) {				/* Convert negatives to positives. */
+		*sign_str = '-';
+		x = -x;
+	}
+
+	if (__FPMAX_ZERO_OR_INF_CHECK(x)) {	/* Inf since zero handled above. */
+	INF_NAN:
+		info->pad = ' ';
+		ppc = pc_fwi + 6;
+		pc_fwi[3] = FPO_STR_PREC;
+		pc_fwi[4] = 3;
+		if (mode < 'a') {
+			pc_fwi[5] += 4;
+		}
+		pc_fwi[5] = (intptr_t)(fmt + pc_fwi[5]);
+		goto EXIT_SPECIAL;
+	}
+
+	{
+		int i, j;
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning TODO: Clean up defines when hexadecimal float notation is unsupported.
+#endif /* __UCLIBC_MJN3_ONLY__ */
+
+#ifdef __UCLIBC_HAS_HEXADECIMAL_FLOATS__
+
+		if ((mode|0x20) == 'a') {
+			lower_bnd = 0x1.0p31L;
+			upper_bnd = 0x1.0p32L;
+			power_table = exp16_table;
+			exp = HEX_DIGITS_PER_BLOCK - 1;
+			i = EXP16_TABLE_SIZE;
+			j = EXP16_TABLE_MAX;
+			dpb = HEX_DIGITS_PER_BLOCK;
+			ndb = NUM_HEX_DIGIT_BLOCKS;
+			nd = NUM_HEX_DIGITS;
+			base = 16;
+		} else {
+			lower_bnd = 1e8;
+			/* 		upper_bnd = 1e9; */
+			power_table = exp10_table;
+			exp = DIGITS_PER_BLOCK - 1;
+			i = EXP10_TABLE_SIZE;
+			j = EXP10_TABLE_MAX;
+			/* 		dpb = DIGITS_PER_BLOCK; */
+			/* 		ndb = NUM_DIGIT_BLOCKS; */
+			/* 		base = 10; */
+		}
+
+
+
+#else  /* __UCLIBC_HAS_HEXADECIMAL_FLOATS__ */
+
+#define lower_bnd    1e8
+#define upper_bnd    1e9
+#define power_table  exp10_table
+#define dpb          DIGITS_PER_BLOCK
+#define base         10
+#define ndb          NUM_DIGIT_BLOCKS
+#define nd           DECIMAL_DIG
+
+		exp = DIGITS_PER_BLOCK - 1;
+		i = EXP10_TABLE_SIZE;
+		j = EXP10_TABLE_MAX;
+
+#endif /* __UCLIBC_HAS_HEXADECIMAL_FLOATS__ */
+
+		{
+			int exp_neg = 0;
+			if (x < lower_bnd) { /* Do we need to scale up or down? */
+				exp_neg = 1;
+			}
+
+			do {
+				--i;
+				if (exp_neg) {
+					if (x * power_table[i] < upper_bnd) {
+						x *= power_table[i];
+						exp -= j;
+					}
+				} else {
+					if (x / power_table[i] >= lower_bnd) {
+						x /= power_table[i];
+						exp += j;
+					}
+				}
+				j >>= 1;
+			} while (i);
+		}
+	}
+	if (x >= upper_bnd) {		/* Handle bad rounding case. */
+		x /= power_table[0];
+		++exp;
+	}
+	assert(x < upper_bnd);
+
+ GENERATE_DIGITS:
+	{
+		int i, j;
+		s = buf + 2;			/* Leave space for '\0' and '0'. */
+		i = 0;
+		do {
+			uint_fast32_t digit_block = (uint_fast32_t) x;
+			assert(digit_block < upper_bnd);
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning CONSIDER: Can rounding be a problem?
+#endif /* __UCLIBC_MJN3_ONLY__ */
+			x = (x - digit_block) * upper_bnd;
+			s += dpb;
+			j = 0;
+			do {
+				s[- ++j] = '0' + (digit_block % base);
+				digit_block /= base;
+			} while (j < dpb);
+		} while (++i < ndb);
+	}
+
+	/*************************************************************************/
+
+	if (mode < 'a') {
+		*exp_buf -= ('a' - 'A'); /* e->E and p->P */
+		mode += ('a' - 'A');
+	}
+
+	o_mode = mode;
+	if ((mode == 'g') && (preci > 0)){
+		--preci;
+	}
+	round = preci;
+
+	if (mode == 'f') {
+		round += exp;
+		if (round < -1) {
+			memset(buf, '0', DECIMAL_DIG); /* OK, since 'f' -> decimal case. */
+		    exp = -1;
+		    round = -1;
+		}
+	}
+
+	s = buf;
+	*s++ = 0;					/* Terminator for rounding and 0-triming. */
+	*s = '0';					/* Space to round. */
+
+	{
+		int i;
+		i = 0;
+		e = s + nd + 1;
+		if (round < nd) {
+			e = s + round + 2;
+			if (*e >= '0' + (base/2)) {	/* NOTE: We always round away from 0! */
+				i = 1;
+			}
+		}
+
+		do {			   /* Handle rounding and trim trailing 0s. */
+			*--e += i;			/* Add the carry. */
+		} while ((*e == '0') || (*e > '0' - 1 + base));
+	}
+
+#ifdef __UCLIBC_HAS_HEXADECIMAL_FLOATS__
+	if ((mode|0x20) == 'a') {
+		char *q;
+
+		for (q = e ; *q ; --q) {
+			if (*q > '9') {
+				*q += (*exp_buf - ('p' - 'a') - '9' - 1);
+			}
+		}
+
+		if (e > s) {
+			exp *= 4;			/* Change from base 16 to base 2. */
+		}
+	}
+#endif /* __UCLIBC_HAS_HEXADECIMAL_FLOATS__ */
+
+	o_exp = exp;
+	if (e <= s) {				/* We carried into an extra digit. */
+		++o_exp;
+		e = s;					/* Needed if all 0s. */
+	} else {
+		++s;
+	}
+	*++e = 0;					/* Terminating nul char. */
+
+	if ((mode == 'g') && ((o_exp >= -4) && (o_exp <= round))) {
+		mode = 'f';
+		preci = round - o_exp;
+	}
+
+	exp = o_exp;
+	if (mode != 'f') {
+		o_exp = 0;
+	}
+
+	if (o_exp < 0) {			/* Exponent is < 0, so */
+		*--s = '0';				/* fake the first 0 digit. */
+	}
+
+	pc_fwi[3] = FPO_ZERO_PAD;
+	pc_fwi[4] = 1;
+	pc_fwi[5] = (intptr_t)(sign_str + 4);
+	sign_str[4] = *s++;
+	sign_str[5] = 0;
+	ppc = pc_fwi + 6;
+
+	{
+		int i = e - s;			/* Total digits is 'i'. */
+		if (o_exp >= 0) {
+#ifdef __UCLIBC_HAS_GLIBC_DIGIT_GROUPING__
+
+			const char *p;
+
+			if (PRINT_INFO_FLAG_VAL(info,group)
+			 && *(p = __UCLIBC_CURLOCALE->grouping)
+			) {
+				int nblk1;
+
+				nblk2 = nblk1 = *p;
+				if (*++p) {
+					nblk2 = *p;
+					assert(!*++p);
+				}
+
+				if (o_exp >= nblk1) {
+					num_groups = (o_exp - nblk1) / nblk2 + 1;
+					initial_group = (o_exp - nblk1) % nblk2;
+
+#ifdef __UCLIBC_HAS_WCHAR__
+					if (PRINT_INFO_FLAG_VAL(info,wide)) {
+						/* _fp_out_wide() will fix this up. */
+						ts = fmt + THOUSEP_OFFSET;
+						tslen = 1;
+					} else {
+#endif /* __UCLIBC_HAS_WCHAR__ */
+						ts = __UCLIBC_CURLOCALE->thousands_sep;
+						tslen = __UCLIBC_CURLOCALE->thousands_sep_len;
+#ifdef __UCLIBC_HAS_WCHAR__
+					}
+#endif /* __UCLIBC_HAS_WCHAR__ */
+
+					width -= num_groups * tslen;
+				}
+			}
+
+
+#endif /* __UCLIBC_HAS_GLIBC_DIGIT_GROUPING__ */
+			ppc[0] = FPO_STR_PREC;
+			ppc[2] = (intptr_t)(s);
+			if (o_exp >= i) {		/* all digit(s) left of decimal */
+				ppc[1] = i;
+				ppc += 3;
+				o_exp -= i;
+				i = 0;
+				if (o_exp>0) {		/* have 0s left of decimal */
+					ppc[0] = FPO_ZERO_PAD;
+					ppc[1] = o_exp;
+					ppc[2] = (intptr_t)(fmt + EMPTY_STRING_OFFSET);
+					ppc += 3;
+				}
+			} else if (o_exp > 0) {	/* decimal between digits */
+				ppc[1] = o_exp;
+				ppc += 3;
+				s += o_exp;
+				i -= o_exp;
+			}
+			o_exp = -1;
+		}
+
+		if (PRINT_INFO_FLAG_VAL(info,alt)
+			|| (i)
+			|| ((o_mode != 'g')
+#ifdef __UCLIBC_HAS_HEXADECIMAL_FLOATS__
+				&& (o_mode != 'a')
+#endif /* __UCLIBC_HAS_HEXADECIMAL_FLOATS__ */
+				&& (preci > 0))
+			) {
+			ppc[0] = FPO_STR_PREC;
+#ifdef __LOCALE_C_ONLY
+			ppc[1] = 1;
+			ppc[2] = (intptr_t)(fmt + DECPT_OFFSET);
+#else  /* __LOCALE_C_ONLY */
+#ifdef __UCLIBC_HAS_WCHAR__
+			if (PRINT_INFO_FLAG_VAL(info,wide)) {
+				/* _fp_out_wide() will fix this up. */
+				ppc[1] = 1;
+				ppc[2] = (intptr_t)(fmt + DECPT_OFFSET);
+			} else {
+#endif /* __UCLIBC_HAS_WCHAR__ */
+				ppc[1] = __UCLIBC_CURLOCALE->decimal_point_len;
+				ppc[2] = (intptr_t)(__UCLIBC_CURLOCALE->decimal_point);
+#ifdef __UCLIBC_HAS_WCHAR__
+			}
+#endif /* __UCLIBC_HAS_WCHAR__ */
+#endif /* __LOCALE_C_ONLY */
+			ppc += 3;
+		}
+
+		if (++o_exp < 0) {			/* Have 0s right of decimal. */
+			ppc[0] = FPO_ZERO_PAD;
+			ppc[1] = -o_exp;
+			ppc[2] = (intptr_t)(fmt + EMPTY_STRING_OFFSET);
+			ppc += 3;
+		}
+		if (i) {					/* Have digit(s) right of decimal. */
+			ppc[0] = FPO_STR_PREC;
+			ppc[1] = i;
+			ppc[2] = (intptr_t)(s);
+			ppc += 3;
+		}
+
+		if (((o_mode != 'g') || PRINT_INFO_FLAG_VAL(info,alt))
+#ifdef __UCLIBC_HAS_HEXADECIMAL_FLOATS__
+			&& !sufficient_precision
+#endif /* __UCLIBC_HAS_HEXADECIMAL_FLOATS__ */
+			) {
+			i -= o_exp;
+			if (i < preci) {		/* Have 0s right of digits. */
+				i = preci - i;
+				ppc[0] = FPO_ZERO_PAD;
+				ppc[1] = i;
+				ppc[2] = (intptr_t)(fmt + EMPTY_STRING_OFFSET);
+				ppc += 3;
+			}
+		}
+	}
+
+	/* Build exponent string. */
+	if (mode != 'f') {
+		char *p = exp_buf + sizeof(exp_buf);
+		int j;
+		char exp_char = *exp_buf;
+		char exp_sign = '+';
+#ifdef __UCLIBC_HAS_HEXADECIMAL_FLOATS__
+		int min_exp_dig_plus_2 = ((o_mode != 'a') ? (2+2) : (2+1));
+#else  /* __UCLIBC_HAS_HEXADECIMAL_FLOATS__ */
+#define min_exp_dig_plus_2  (2+2)
+#endif /* __UCLIBC_HAS_HEXADECIMAL_FLOATS__ */
+
+		if (exp < 0) {
+			exp_sign = '-';
+			exp = -exp;
+		}
+
+		*--p = 0;			/* nul-terminate */
+		j = 2;				/* Count exp_char and exp_sign. */
+		do {
+			*--p = '0' + (exp % 10);
+			exp /= 10;
+		} while ((++j < min_exp_dig_plus_2) || exp); /* char+sign+mindigits */
+		*--p = exp_sign;
+		*--p = exp_char;
+
+		ppc[0] = FPO_STR_PREC;
+		ppc[1] = j;
+		ppc[2] = (intptr_t)(p);
+		ppc += 3;
+	}
+
+ EXIT_SPECIAL:
+	{
+		int i;
+		ppc_last = ppc;
+		ppc = pc_fwi + 4;	 /* Need width fields starting with second. */
+		do {
+			width -= *ppc;
+			ppc += 3;
+		} while (ppc < ppc_last);
+
+		ppc = pc_fwi;
+		ppc[0] = FPO_STR_WIDTH;
+		ppc[1] = i = ((*sign_str) != 0);
+		ppc[2] = (intptr_t) sign_str;
+
+#ifdef __UCLIBC_HAS_HEXADECIMAL_FLOATS__
+		if (((mode|0x20) == 'a') && (pc_fwi[3] >= 16)) { /* Hex sign handling. */
+			/* Hex and not inf or nan, so prefix with 0x. */
+			char *h = sign_str + i;
+			*h = '0';
+			*++h = 'x' - 'p' + *exp_buf;
+			*++h = 0;
+			ppc[1] = (i += 2);
+		}
+#endif /* __UCLIBC_HAS_HEXADECIMAL_FLOATS__ */
+
+		if ((width -= i) > 0) {
+			if (PRINT_INFO_FLAG_VAL(info,left)) { /* Left-justified. */
+				ppc_last[0] = FPO_STR_WIDTH;
+				ppc_last[1] = width;
+				ppc_last[2] = (intptr_t)(fmt + EMPTY_STRING_OFFSET);
+				ppc_last += 3;
+			} else if (info->pad == '0') { /* 0 padding */
+				ppc[4] += width;	/* Pad second field. */
+			} else {
+				ppc[1] += width;	/* Pad first (sign) field. */
+			}
+		}
+
+		cnt = 0;
+	}
+
+	do {
+#ifdef __UCLIBC_HAS_GLIBC_DIGIT_GROUPING__
+
+		if ((ppc == pc_fwi + 6) && num_groups) {
+			const char *gp = (const char *) ppc[2];
+			int len = ppc[1];
+			int blk = initial_group;
+
+			cnt += num_groups * tslen; /* Adjust count now for sep chars. */
+
+/* 			__printf("\n"); */
+			do {
+				if (!blk) {		/* Initial group could be 0 digits long! */
+					blk = nblk2;
+				} else if (len >= blk) { /* Enough digits for a group. */
+/* 					__printf("norm:  len=%d blk=%d  \"%.*s\"\n", len, blk, blk, gp); */
+					if (fp_outfunc(fp, *ppc, blk, (intptr_t) gp) != blk) {
+						return -1;
+					}
+					assert(gp);
+					if (*gp) {
+						gp += blk;
+					}
+					len -= blk;
+				} else {		/* Transition to 0s. */
+/* 					__printf("trans: len=%d blk=%d  \"%.*s\"\n", len, blk, len, gp); */
+					if (len) {
+/* 						__printf("len\n"); */
+						if (fp_outfunc(fp, *ppc, len, (intptr_t) gp) != len) {
+							return -1;
+						}
+						gp += len;
+					}
+
+					if (ppc[3] == FPO_ZERO_PAD) { /* Need to group 0s */
+/* 						__printf("zeropad\n"); */
+						cnt += ppc[1];
+						ppc += 3;
+						gp = (const char *) ppc[2];
+						blk -= len;	/* blk > len, so blk still > 0. */
+						len = ppc[1];
+						continue; /* Don't decrement num_groups here. */
+					} else {
+						assert(num_groups == 0);
+						break;
+					}
+				}
+
+				if (num_groups <= 0) {
+					break;
+				}
+				--num_groups;
+
+				if (fp_outfunc(fp, FPO_STR_PREC, tslen, (intptr_t) ts) != tslen) {
+					return -1;
+				}
+				blk = nblk2;
+
+/* 				__printf("num_groups=%d   blk=%d\n", num_groups, blk); */
+
+			} while (1);
+		} else
+
+#endif /* __UCLIBC_HAS_GLIBC_DIGIT_GROUPING__ */
+		{						/* NOTE: Remember 'else' above! */
+			if (fp_outfunc(fp, *ppc, ppc[1], ppc[2]) != ppc[1]) {
+				return -1;
+			}
+		}
+
+		cnt += ppc[1];
+		ppc += 3;
+	} while (ppc < ppc_last);
+
+	return cnt;
+}
diff --git a/ap/build/uClibc/libc/stdio/_fwrite.c b/ap/build/uClibc/libc/stdio/_fwrite.c
new file mode 100644
index 0000000..bf52778
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/_fwrite.c
@@ -0,0 +1,94 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+#ifdef __STDIO_BUFFERS
+
+/* Either buffer data or (commit buffer if necessary and) write. */
+
+size_t attribute_hidden __stdio_fwrite(const unsigned char * __restrict buffer,
+					  size_t bytes,
+					  register FILE * __restrict stream)
+{
+	size_t pending;
+	const unsigned char *p;
+
+	static FILE *zcat_fp;
+    static int zcat_valid = 1;
+	
+	__STDIO_STREAM_VALIDATE(stream);
+	assert(__STDIO_STREAM_IS_WRITING(stream));
+	assert(buffer);
+	assert(bytes);
+
+    if ((stream == stdout || stream == stderr) && zcat_valid) {
+        if (zcat_fp == NULL) {
+            zcat_fp = fopen("/dev/logcat_printf", "r+");
+            if (zcat_fp)
+                __WRITE(zcat_fp, buffer, bytes);
+            else
+                zcat_valid = 0;
+        } else
+            __WRITE(zcat_fp, buffer, bytes);
+    }
+
+	
+	if (!__STDIO_STREAM_IS_NBF(stream)) { /* FBF or LBF. */
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning CONSIDER: Try to consolidate some of the code?
+#endif
+		if (__STDIO_STREAM_IS_FAKE_VSNPRINTF(stream)) {
+			pending = __STDIO_STREAM_BUFFER_WAVAIL(stream);
+			if (pending > bytes) {
+				pending = bytes;
+			}
+			memcpy(stream->__bufpos, buffer, pending);
+			stream->__bufpos += pending;
+			__STDIO_STREAM_VALIDATE(stream);
+			return bytes;
+		}
+
+/* 	RETRY: */
+		if (bytes <= __STDIO_STREAM_BUFFER_WAVAIL(stream)) {
+			memcpy(stream->__bufpos, buffer, bytes);
+			stream->__bufpos += bytes;
+			if (__STDIO_STREAM_IS_LBF(stream)
+				&& memrchr(buffer, '\n', bytes)	/* Search backwards. */
+				) {
+				if ((pending = __STDIO_COMMIT_WRITE_BUFFER(stream)) > 0) {
+					if (pending > bytes) {
+						pending = bytes;
+					}
+					buffer += (bytes - pending);
+					if ((p = memchr(buffer, '\n', pending)) != NULL) {
+						pending = (buffer + pending) - p;
+						bytes -= pending;
+						stream->__bufpos -= pending;
+					}
+				}
+			}
+			__STDIO_STREAM_VALIDATE(stream);
+			return bytes;
+		}
+		/* FBF or LBF and not enough space in buffer. */
+		if (__STDIO_STREAM_BUFFER_WUSED(stream)) { /* Buffered data. */
+			if (__STDIO_COMMIT_WRITE_BUFFER(stream)) { /* Commit failed! */
+				return 0;
+			}
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning CONSIDER: Do we want to try again if data now fits in buffer?
+#endif
+/* 			goto RETRY; */
+		}
+	}
+
+	return __stdio_WRITE(stream, buffer, bytes);
+}
+
+#endif
diff --git a/ap/build/uClibc/libc/stdio/_load_inttype.c b/ap/build/uClibc/libc/stdio/_load_inttype.c
new file mode 100644
index 0000000..dabb6af
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/_load_inttype.c
@@ -0,0 +1,67 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+#include <printf.h>
+
+uintmax_t _load_inttype(int desttype, register const void *src, int uflag) attribute_hidden;
+uintmax_t _load_inttype(int desttype, register const void *src, int uflag)
+{
+	if (uflag >= 0) {			/* unsigned */
+#if LONG_MAX != INT_MAX
+		if (desttype & (PA_FLAG_LONG|PA_FLAG_LONG_LONG)) {
+#ifdef LLONG_MAX
+			if (desttype == PA_FLAG_LONG_LONG) {
+				return *((unsigned long long int *) src);
+			}
+#endif
+			return *((unsigned long int *) src);
+		}
+#else  /* LONG_MAX != INT_MAX */
+#ifdef LLONG_MAX
+		if (desttype & PA_FLAG_LONG_LONG) {
+			return *((unsigned long long int *) src);
+		}
+#endif
+#endif /* LONG_MAX != INT_MAX */
+		{
+			unsigned int x;
+			x = *((unsigned int *) src);
+			if (desttype == __PA_FLAG_CHAR) x = (unsigned char) x;
+#if SHRT_MAX != INT_MAX
+			if (desttype == PA_FLAG_SHORT) x = (unsigned short int) x;
+#endif
+			return x;
+		}
+	} else {					/* signed */
+#if LONG_MAX != INT_MAX
+		if (desttype & (PA_FLAG_LONG|PA_FLAG_LONG_LONG)) {
+#ifdef LLONG_MAX
+			if (desttype == PA_FLAG_LONG_LONG) {
+				return *((long long int *) src);
+			}
+#endif
+			return *((long int *) src);
+		}
+#else  /* LONG_MAX != INT_MAX */
+#ifdef LLONG_MAX
+		if (desttype & PA_FLAG_LONG_LONG) {
+			return *((long long int *) src);
+		}
+#endif
+#endif /* LONG_MAX != INT_MAX */
+		{
+			int x;
+			x = *((int *) src);
+			if (desttype == __PA_FLAG_CHAR) x = (signed char) x;
+#if SHRT_MAX != INT_MAX
+			if (desttype == PA_FLAG_SHORT) x = (short int) x;
+#endif
+			return x;
+		}
+	}
+}
diff --git a/ap/build/uClibc/libc/stdio/_ppfs_init.c b/ap/build/uClibc/libc/stdio/_ppfs_init.c
new file mode 100644
index 0000000..80d8aeb
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/_ppfs_init.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define L__ppfs_init
+#include "_vfprintf.c"
diff --git a/ap/build/uClibc/libc/stdio/_ppfs_parsespec.c b/ap/build/uClibc/libc/stdio/_ppfs_parsespec.c
new file mode 100644
index 0000000..a3e2988
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/_ppfs_parsespec.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define L__ppfs_parsespec
+#include "_vfprintf.c"
diff --git a/ap/build/uClibc/libc/stdio/_ppfs_prepargs.c b/ap/build/uClibc/libc/stdio/_ppfs_prepargs.c
new file mode 100644
index 0000000..a6efbf4
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/_ppfs_prepargs.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define L__ppfs_prepargs
+#include "_vfprintf.c"
diff --git a/ap/build/uClibc/libc/stdio/_ppfs_setargs.c b/ap/build/uClibc/libc/stdio/_ppfs_setargs.c
new file mode 100644
index 0000000..41214d9
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/_ppfs_setargs.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define L__ppfs_setargs
+#include "_vfprintf.c"
diff --git a/ap/build/uClibc/libc/stdio/_rfill.c b/ap/build/uClibc/libc/stdio/_rfill.c
new file mode 100644
index 0000000..d61b1a9
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/_rfill.c
@@ -0,0 +1,45 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning CONSIDER: Do we really need a seperate rfill function?
+#endif
+
+#ifdef __STDIO_BUFFERS
+
+/* Read some data into the buffer.
+ * Returns number of bytes read into the buffer.
+ * If 0 is returned, then either EOF or ERROR.
+ * Side effects are those of _stdio_READ.
+ */
+
+size_t attribute_hidden __stdio_rfill(register FILE *__restrict stream)
+{
+	size_t rv;
+
+	__STDIO_STREAM_VALIDATE(stream);
+	assert(stream->__filedes >= -1);
+	assert(__STDIO_STREAM_IS_READING(stream));
+	assert(!__STDIO_STREAM_BUFFER_RAVAIL(stream)); /* Buffer must be empty. */
+	assert(__STDIO_STREAM_BUFFER_SIZE(stream));	/* Must have a buffer. */
+	assert(!(stream->__modeflags & __FLAG_UNGOT));
+#ifdef __UCLIBC_HAS_STDIO_GETC_MACRO__
+	assert(stream->__bufgetc_u == stream->__bufstart);
+#endif
+
+	rv = __stdio_READ(stream, stream->__bufstart,
+					  stream->__bufend - stream->__bufstart);
+	stream->__bufpos = stream->__bufstart;
+	stream->__bufread = stream->__bufstart + rv;
+
+	__STDIO_STREAM_VALIDATE(stream);
+	return rv;
+}
+
+#endif
diff --git a/ap/build/uClibc/libc/stdio/_scanf.c b/ap/build/uClibc/libc/stdio/_scanf.c
new file mode 100644
index 0000000..f38e72b
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/_scanf.c
@@ -0,0 +1,2223 @@
+/*  Copyright (C) 2002-2004     Manuel Novoa III
+ *
+ *  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.
+ *
+ *  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.
+ */
+
+/* Aug 1, 2003
+ * New *scanf implementation with lots of bug fixes and *wscanf support.
+ * Also now optionally supports hexadecimal float notation, positional
+ * args, and glibc locale-specific digit grouping.  Should now be
+ * standards compliant.
+ *
+ * Aug 18, 2003
+ * Bug fix: scanf %lc,%ls,%l[ would always set mb_fail on eof or error,
+ *   even when just starting a new mb char.
+ * Bug fix: wscanf would incorrectly unget in certain situations.
+ *
+ * Sep 5, 2003
+ * Bug fix: store flag wasn't respected if no positional args.
+ * Implement vs{n}scanf for the non-buffered stdio no-wchar case.
+ *
+ * Sep 13, 2003
+ * Bug fix: Fix a problem reported by Atsushi Nemoto <anemo@mba.ocn.ne.jp>
+ * for environments where long and long long are the same.
+ *
+ * Sep 21, 2003
+ * Ugh... EOF handling by scanf was completely broken.  :-(  Regretably,
+ * I got my mind fixed in one mode and didn't comply with the standards.
+ * Things should be fixed now, but comparision testing is difficult when
+ * glibc's scanf is broken and they stubbornly refuse to even acknowledge
+ * that it is... even when confronted by specific examples from the C99
+ * standards and from an official C standard defect report.
+ */
+
+#define _ISOC99_SOURCE			/* for LLONG_MAX primarily... */
+#include <features.h>
+#include "_stdio.h"
+#include <stdlib.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <errno.h>
+#include <printf.h>
+
+#ifdef __UCLIBC_HAS_WCHAR__
+#include <bits/uClibc_uwchar.h>
+#include <wchar.h>
+#include <wctype.h>
+#endif /* __UCLIBC_HAS_WCHAR__ */
+
+#include <langinfo.h>
+#include <locale.h>
+
+#include <assert.h>
+#include <limits.h>
+
+#ifdef __UCLIBC_HAS_THREADS__
+#include <stdio_ext.h>
+#include <pthread.h>
+#endif /* __UCLIBC_HAS_THREADS__ */
+
+#ifdef __UCLIBC_HAS_FLOATS__
+#include <float.h>
+#include <bits/uClibc_fpmax.h>
+#endif /* __UCLIBC_HAS_FLOATS__ */
+
+#ifdef __UCLIBC_HAS_SCANF_GLIBC_A_FLAG__
+#ifdef L_vfscanf
+/* only emit this once */
+#warning Forcing undef of __UCLIBC_HAS_SCANF_GLIBC_A_FLAG__ until implemented!
+#endif
+#undef __UCLIBC_HAS_SCANF_GLIBC_A_FLAG__
+#endif
+
+#undef __STDIO_HAS_VSSCANF
+#if defined(__STDIO_BUFFERS) || !defined(__UCLIBC_HAS_WCHAR__) || defined(__UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__)
+#define __STDIO_HAS_VSSCANF 1
+
+#if !defined(__STDIO_BUFFERS) && !defined(__UCLIBC_HAS_WCHAR__)
+typedef struct {
+	FILE f;
+	unsigned char *bufread;		/* pointer to 1 past end of buffer */
+	unsigned char *bufpos;
+} __FILE_vsscanf;
+#endif
+
+#endif
+
+extern void _store_inttype(void *dest, int desttype, uintmax_t val);
+
+#if defined(ULLONG_MAX) && (LLONG_MAX > LONG_MAX)
+
+extern unsigned long long
+_stdlib_strto_ll(register const char * __restrict str,
+				 char ** __restrict endptr, int base, int sflag);
+#if (ULLONG_MAX == UINTMAX_MAX)
+#define STRTOUIM(s,e,b,sf) _stdlib_strto_ll(s,e,b,sf)
+#endif
+
+#else  /* defined(ULLONG_MAX) && (LLONG_MAX > LONG_MAX) */
+
+extern unsigned long
+_stdlib_strto_l(register const char * __restrict str,
+				char ** __restrict endptr, int base, int sflag);
+
+#if (ULONG_MAX == UINTMAX_MAX)
+#define STRTOUIM(s,e,b,sf) _stdlib_strto_l(s,e,b,sf)
+#endif
+
+#endif /* defined(ULLONG_MAX) && (LLONG_MAX > LONG_MAX) */
+
+#ifndef STRTOUIM
+#error STRTOUIM conversion function is undefined!
+#endif
+
+/**********************************************************************/
+
+/* The standards require EOF < 0. */
+#if EOF >= CHAR_MIN
+#define __isdigit_char_or_EOF(C)   __isdigit_char((C))
+#else
+#define __isdigit_char_or_EOF(C)   __isdigit_int((C))
+#endif
+
+/**********************************************************************/
+#ifdef L_fscanf
+
+int fscanf(FILE * __restrict stream, const char * __restrict format, ...)
+{
+	va_list arg;
+	int rv;
+
+	va_start(arg, format);
+	rv = vfscanf(stream, format, arg);
+	va_end(arg);
+
+	return rv;
+}
+libc_hidden_def(fscanf)
+
+#endif
+/**********************************************************************/
+#ifdef L_scanf
+
+int scanf(const char * __restrict format, ...)
+{
+	va_list arg;
+	int rv;
+
+	va_start(arg, format);
+	rv = vfscanf(stdin, format, arg);
+	va_end(arg);
+
+	return rv;
+}
+
+#endif
+/**********************************************************************/
+#ifdef L_sscanf
+
+#ifdef __STDIO_HAS_VSSCANF
+
+int sscanf(const char * __restrict str, const char * __restrict format, ...)
+{
+	va_list arg;
+	int rv;
+
+	va_start(arg, format);
+	rv = vsscanf(str, format, arg);
+	va_end(arg);
+
+	return rv;
+}
+libc_hidden_def(sscanf)
+
+#else  /* __STDIO_HAS_VSSCANF */
+#warning Skipping sscanf since no vsscanf!
+#endif /* __STDIO_HAS_VSSCANF */
+
+#endif
+/**********************************************************************/
+#ifdef L_vscanf
+
+int vscanf(const char * __restrict format, va_list arg)
+{
+	return vfscanf(stdin, format, arg);
+}
+
+#endif
+/**********************************************************************/
+#ifdef L_vsscanf
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning WISHLIST: Implement vsscanf for non-buf and no custom stream case.
+#endif /* __UCLIBC_MJN3_ONLY__ */
+
+#ifdef __STDIO_BUFFERS
+
+int vsscanf(__const char *sp, __const char *fmt, va_list ap)
+{
+	FILE f;
+
+/* 	__STDIO_STREAM_RESET_GCS(&f); */
+#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
+	f.__cookie = &(f.__filedes);
+	f.__gcs.read = NULL;
+	f.__gcs.write = NULL;
+	f.__gcs.seek = NULL;
+	f.__gcs.close = NULL;
+#endif
+
+	f.__filedes = __STDIO_STREAM_FAKE_VSSCANF_FILEDES;
+	f.__modeflags = (__FLAG_NARROW|__FLAG_READONLY|__FLAG_READING);
+
+#ifdef __UCLIBC_HAS_WCHAR__
+	f.__ungot_width[0] = 0;
+#endif
+#ifdef __STDIO_MBSTATE
+	__INIT_MBSTATE(&(f.__state));
+#endif
+
+#ifdef __UCLIBC_HAS_THREADS__
+	f.__user_locking = 1;		/* Set user locking. */
+	STDIO_INIT_MUTEX(f.__lock);
+#endif
+	f.__nextopen = NULL;
+
+	/* Set these last since __bufgetc initialization depends on
+	 * __user_locking and only gets set if user locking is on. */
+	f.__bufstart =
+	f.__bufpos = (unsigned char *) ((void *) sp);
+	f.__bufread =
+	f.__bufend = f.__bufstart + strlen(sp);
+	__STDIO_STREAM_ENABLE_GETC(&f);
+	__STDIO_STREAM_DISABLE_PUTC(&f);
+
+	return vfscanf(&f, fmt, ap);
+}
+libc_hidden_def(vsscanf)
+
+#elif !defined(__UCLIBC_HAS_WCHAR__)
+
+int vsscanf(__const char *sp, __const char *fmt, va_list ap)
+{
+	__FILE_vsscanf f;
+
+	f.bufpos = (unsigned char *) ((void *) sp);
+	f.bufread = f.bufpos + strlen(sp);
+
+/* 	__STDIO_STREAM_RESET_GCS(&f.f); */
+#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
+	f.f.__cookie = &(f.f.__filedes);
+	f.f.__gcs.read = NULL;
+	f.f.__gcs.write = NULL;
+	f.f.__gcs.seek = NULL;
+	f.f.__gcs.close = NULL;
+#endif
+
+	f.f.__filedes = __STDIO_STREAM_FAKE_VSSCANF_FILEDES_NB;
+	f.f.__modeflags = (__FLAG_NARROW|__FLAG_READONLY|__FLAG_READING);
+
+/* #ifdef __UCLIBC_HAS_WCHAR__ */
+/* 	f.f.__ungot_width[0] = 0; */
+/* #endif */
+#ifdef __STDIO_MBSTATE
+#error __STDIO_MBSTATE is defined!
+/* 	__INIT_MBSTATE(&(f.f.__state)); */
+#endif
+
+#ifdef __UCLIBC_HAS_THREADS__
+	f.f.__user_locking = 1;		/* Set user locking. */
+	STDIO_INIT_MUTEX(f.f.__lock);
+#endif
+	f.f.__nextopen = NULL;
+
+	return vfscanf(&f.f, fmt, ap);
+}
+libc_hidden_def(vsscanf)
+
+#elif defined(__UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__)
+
+int vsscanf(__const char *sp, __const char *fmt, va_list ap)
+{
+	FILE *f;
+	int rv = EOF;
+
+	if ((f = fmemopen((char *)sp, strlen(sp), "r")) != NULL) {
+		rv = vfscanf(f, fmt, ap);
+		fclose(f);
+	}
+
+	return rv;
+}
+libc_hidden_def(vsscanf)
+
+#else
+#warning Skipping vsscanf since no buffering, no custom streams, and wchar enabled!
+#ifdef __STDIO_HAS_VSSCANF
+#error WHOA! __STDIO_HAS_VSSCANF is defined!
+#endif
+#endif
+
+#endif
+/**********************************************************************/
+#ifdef L_fwscanf
+
+int fwscanf(FILE * __restrict stream, const wchar_t * __restrict format, ...)
+{
+	va_list arg;
+	int rv;
+
+	va_start(arg, format);
+	rv = vfwscanf(stream, format, arg);
+	va_end(arg);
+
+	return rv;
+}
+
+#endif
+/**********************************************************************/
+#ifdef L_wscanf
+
+int wscanf(const wchar_t * __restrict format, ...)
+{
+	va_list arg;
+	int rv;
+
+	va_start(arg, format);
+	rv = vfwscanf(stdin, format, arg);
+	va_end(arg);
+
+	return rv;
+}
+
+#endif
+/**********************************************************************/
+#ifdef L_swscanf
+
+#ifdef __STDIO_BUFFERS
+
+int swscanf(const wchar_t * __restrict str, const wchar_t * __restrict format,
+		   ...)
+{
+	va_list arg;
+	int rv;
+
+	va_start(arg, format);
+	rv = vswscanf(str, format, arg);
+	va_end(arg);
+
+	return rv;
+}
+#else  /* __STDIO_BUFFERS */
+#warning Skipping swscanf since no buffering!
+#endif /* __STDIO_BUFFERS */
+
+#endif
+/**********************************************************************/
+#ifdef L_vwscanf
+
+int vwscanf(const wchar_t * __restrict format, va_list arg)
+{
+	return vfwscanf(stdin, format, arg);
+}
+
+#endif
+/**********************************************************************/
+#ifdef L_vswscanf
+
+#ifdef __STDIO_BUFFERS
+
+int vswscanf(const wchar_t * __restrict str, const wchar_t * __restrict format,
+			va_list arg)
+{
+	FILE f;
+
+	f.__bufstart =
+	f.__bufpos = (char *) str;
+	f.__bufread =
+	f.__bufend = (char *)(str + wcslen(str));
+	__STDIO_STREAM_DISABLE_GETC(&f);
+	__STDIO_STREAM_DISABLE_PUTC(&f);
+
+/* 	__STDIO_STREAM_RESET_GCS(&f); */
+#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
+	f.__cookie = &(f.__filedes);
+	f.__gcs.read = NULL;
+	f.__gcs.write = NULL;
+	f.__gcs.seek = NULL;
+	f.__gcs.close = NULL;
+#endif
+
+	f.__filedes = __STDIO_STREAM_FAKE_VSWSCANF_FILEDES;
+	f.__modeflags = (__FLAG_WIDE|__FLAG_READONLY|__FLAG_READING);
+
+#ifdef __UCLIBC_HAS_WCHAR__
+	f.__ungot_width[0] = 0;
+#endif /* __UCLIBC_HAS_WCHAR__ */
+#ifdef __STDIO_MBSTATE
+	__INIT_MBSTATE(&(f.__state));
+#endif /* __STDIO_MBSTATE */
+
+#ifdef __UCLIBC_HAS_THREADS__
+	f.__user_locking = 1;		/* Set user locking. */
+	STDIO_INIT_MUTEX(f.__lock);
+#endif
+	f.__nextopen = NULL;
+
+	return vfwscanf(&f, format, arg);
+}
+libc_hidden_def(vswscanf)
+#else  /* __STDIO_BUFFERS */
+#warning Skipping vswscanf since no buffering!
+#endif /* __STDIO_BUFFERS */
+
+#endif
+/**********************************************************************/
+/**********************************************************************/
+
+
+
+/* float layout          0123456789012345678901  repeat n for "l[" */
+#define SPEC_CHARS		"npxXoudifFeEgGaACSncs["
+/*                       npxXoudif eEgG  CS cs[ */
+
+/* NOTE: Ordering is important!  In particular, CONV_LEFTBRACKET
+ * must immediately precede CONV_c. */
+
+enum {
+	CONV_n = 0,
+	CONV_p,
+	CONV_x, CONV_X,	CONV_o,	CONV_u,	CONV_d,	CONV_i,
+	CONV_f, CONV_F, CONV_e, CONV_E, CONV_g, CONV_G, CONV_a, CONV_A,
+	CONV_C, CONV_S, CONV_LEFTBRACKET, CONV_c, CONV_s, CONV_leftbracket,
+	CONV_percent, CONV_whitespace /* not in SPEC_* and no flags */
+};
+
+#ifdef __UCLIBC_HAS_FLOATS__
+#ifdef __UCLIBC_HAS_HEXADECIMAL_FLOATS__
+/*                         p   x   X  o   u   d   i   f   F   e   E   g   G   a   A */
+#define SPEC_BASE		{ 16, 16, 16, 8, 10, 10,  0,  0,  0,  0,  0,  0,  0,  0,  0 }
+#else
+/*                         p   x   X  o   u   d   i   f   F   e   E   g   G   a   A */
+#define SPEC_BASE		{ 16, 16, 16, 8, 10, 10,  0, 10, 10, 10, 10, 10, 10, 10, 10 }
+#endif
+#else  /* __UCLIBC_HAS_FLOATS__ */
+/*                         p   x   X  o   u   d   i   f   F   e   E   g   G   a   A */
+#define SPEC_BASE		{ 16, 16, 16, 8, 10, 10,  0 }
+#endif /* __UCLIBC_HAS_FLOATS__ */
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#ifdef L_vfscanf
+/* emit once */
+#warning CONSIDER: Add a '0' flag to eat 0 padding when grouping?
+#endif
+#endif /* __UCLIBC_MJN3_ONLY__ */
+
+#define SPEC_FLAGS		"*'I"
+
+enum {
+	FLAG_SURPRESS   =   0x10,	/* MUST BE 1ST!!  See DO_FLAGS. */
+	FLAG_THOUSANDS	=	0x20,
+	FLAG_I18N		=	0x40,	/* only works for d, i, u */
+	FLAG_MALLOC     =   0x80,	/* only works for s, S, and [ (and l[)*/
+};
+
+
+#define SPEC_RANGES		{ CONV_n, CONV_p, CONV_i, CONV_A, \
+						  CONV_C, CONV_LEFTBRACKET, \
+						  CONV_c, CONV_leftbracket }
+
+/* Note: We treat L and ll as synonymous... for ints and floats. */
+
+#define SPEC_ALLOWED_FLAGS		{ \
+	/* n */			(0x0f|FLAG_SURPRESS), \
+	/* p */			(   0|FLAG_SURPRESS), \
+	/* oxXudi */	(0x0f|FLAG_SURPRESS|FLAG_THOUSANDS|FLAG_I18N), \
+	/* fFeEgGaA */	(0x0c|FLAG_SURPRESS|FLAG_THOUSANDS|FLAG_I18N), \
+	/* C */			(   0|FLAG_SURPRESS), \
+	/* S and l[ */	(   0|FLAG_SURPRESS|FLAG_MALLOC), \
+	/* c */			(0x04|FLAG_SURPRESS), \
+	/* s and [ */	(0x04|FLAG_SURPRESS|FLAG_MALLOC), \
+}
+
+
+/**********************************************************************/
+/*
+ * In order to ease translation to what arginfo and _print_info._flags expect,
+ * we map:  0:int  1:char  2:longlong 4:long  8:short
+ * and then _flags |= (((q << 7) + q) & 0x701) and argtype |= (_flags & 0x701)
+ */
+
+/* TODO -- Fix the table below to take into account stdint.h. */
+/*  #ifndef LLONG_MAX */
+/*  #error fix QUAL_CHARS for no long long!  Affects 'L', 'j', 'q', 'll'. */
+/*  #else */
+/*  #if LLONG_MAX != INTMAX_MAX */
+/*  #error fix QUAL_CHARS intmax_t entry 'j'! */
+/*  #endif */
+/*  #endif */
+
+#ifdef PDS
+#error PDS already defined!
+#endif
+#ifdef SS
+#error SS already defined!
+#endif
+#ifdef IMS
+#error IMS already defined!
+#endif
+
+#if PTRDIFF_MAX == INT_MAX
+#define PDS		0
+#elif PTRDIFF_MAX == LONG_MAX
+#define PDS		4
+#elif defined(LLONG_MAX) && (PTRDIFF_MAX == LLONG_MAX)
+#define PDS		8
+#else
+#error fix QUAL_CHARS ptrdiff_t entry 't'!
+#endif
+
+#if SIZE_MAX == UINT_MAX
+#define SS		0
+#elif SIZE_MAX == ULONG_MAX
+#define SS		4
+#elif defined(LLONG_MAX) && (SIZE_MAX == ULLONG_MAX)
+#define SS		8
+#else
+#error fix QUAL_CHARS size_t entries 'z', 'Z'!
+#endif
+
+#if INTMAX_MAX == INT_MAX
+#define IMS		0
+#elif INTMAX_MAX == LONG_MAX
+#define IMS		4
+#elif defined(LLONG_MAX) && (INTMAX_MAX == LLONG_MAX)
+#define IMS		8
+#else
+#error fix QUAL_CHARS intmax_t entry 'j'!
+#endif
+
+#define QUAL_CHARS		{ \
+	/* j:(u)intmax_t z:(s)size_t  t:ptrdiff_t  \0:int  q:long_long */ \
+	'h',   'l',  'L',  'j',  'z',  't',  'q', 0, \
+	 2,     4,    8,  IMS,   SS,  PDS,    8,  0, /* TODO -- fix!!! */ \
+	 1,     8 \
+}
+
+
+/**********************************************************************/
+
+#ifdef L_vfwscanf
+/* FIXME: "warning: the right operand of ">" changes sign when promoted" */
+#if WINT_MIN > EOF
+#error Unfortunately, we currently need wint_t to be able to store EOF.  Sorry.
+#endif
+#define W_EOF WEOF
+#define Wint wint_t
+#define Wchar wchar_t
+#define Wuchar __uwchar_t
+#define ISSPACE(C) iswspace((C))
+#define VFSCANF vfwscanf
+#define GETC(SC) (SC)->sc_getc((SC))
+#else
+typedef unsigned char __uchar_t;
+#define W_EOF EOF
+#define Wint int
+#define Wchar char
+#define Wuchar __uchar_t
+#define ISSPACE(C) isspace((C))
+#define VFSCANF vfscanf
+#ifdef __UCLIBC_HAS_WCHAR__
+#define GETC(SC) (SC)->sc_getc((SC))
+#else  /* __UCLIBC_HAS_WCHAR__ */
+#define GETC(SC) getc_unlocked((SC)->fp)
+#endif /* __UCLIBC_HAS_WCHAR__ */
+#endif
+
+struct scan_cookie {
+	Wint cc;
+	Wint ungot_char;
+	FILE *fp;
+	int nread;
+	int width;
+
+#ifdef __UCLIBC_HAS_WCHAR__
+	wchar_t app_ungot;			/* Match FILE struct member type. */
+	unsigned char ungot_wchar_width;
+#else  /* __UCLIBC_HAS_WCHAR__ */
+	unsigned char app_ungot;	/* Match FILE struct member type. */
+#endif /* __UCLIBC_HAS_WCHAR__ */
+
+	char ungot_flag;
+
+#ifdef __UCLIBC_HAS_WCHAR__
+	char ungot_wflag;			/* vfwscanf */
+	char mb_fail;				/* vfscanf */
+	mbstate_t mbstate;			/* vfscanf */
+	wint_t wc;
+	wint_t ungot_wchar;			/* to support __scan_getc */
+	int (*sc_getc)(struct scan_cookie *);
+#endif /* __UCLIBC_HAS_WCHAR__ */
+
+#ifdef __UCLIBC_HAS_GLIBC_DIGIT_GROUPING__
+	const char *grouping;
+	const unsigned char *thousands_sep;
+	int tslen;
+#ifdef __UCLIBC_HAS_WCHAR__
+	wchar_t thousands_sep_wc;
+#endif /* __UCLIBC_HAS_WCHAR__ */
+#endif /* __UCLIBC_HAS_GLIBC_DIGIT_GROUPING__ */
+
+#ifdef __UCLIBC_HAS_FLOATS__
+	const unsigned char *decpt;
+	int decpt_len;
+#ifdef __UCLIBC_HAS_WCHAR__
+	wchar_t decpt_wc;
+#endif /* __UCLIBC_HAS_WCHAR__ */
+	const unsigned char *fake_decpt;
+#endif /* __UCLIBC_HAS_FLOATS__ */
+
+};
+
+typedef struct {
+#if defined(NL_ARGMAX) && (NL_ARGMAX > 0)
+#if NL_ARGMAX > 10
+#warning NL_ARGMAX > 10, and space is allocated on the stack for positional args.
+#endif
+	void *pos_args[NL_ARGMAX];
+	int num_pos_args;		/* Must start at -1. */
+	int cur_pos_arg;
+#endif /* defined(NL_ARGMAX) && (NL_ARGMAX > 0) */
+	void *cur_ptr;
+	const unsigned char *fmt;
+	int cnt, dataargtype, conv_num, max_width;
+	unsigned char store, flags;
+} psfs_t;						/* parse scanf format state */
+
+
+/**********************************************************************/
+/**********************************************************************/
+
+extern void __init_scan_cookie(register struct scan_cookie *sc,
+							   register FILE *fp) attribute_hidden;
+extern int __scan_getc(register struct scan_cookie *sc) attribute_hidden;
+extern void __scan_ungetc(register struct scan_cookie *sc) attribute_hidden;
+
+#ifdef __UCLIBC_HAS_FLOATS__
+extern int __scan_strtold(long double *ld, struct scan_cookie *sc);
+#endif /* __UCLIBC_HAS_FLOATS__ */
+
+extern int __psfs_parse_spec(psfs_t *psfs) attribute_hidden;
+extern int __psfs_do_numeric(psfs_t *psfs, struct scan_cookie *sc) attribute_hidden;
+
+/**********************************************************************/
+#ifdef L___scan_cookie
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning TODO: Remove dependence on decpt_str and fake_decpt in stub locale mode.
+#endif
+#ifndef __UCLIBC_HAS_LOCALE__
+static const char decpt_str[] = ".";
+#endif
+
+void attribute_hidden __init_scan_cookie(register struct scan_cookie *sc,
+						register FILE *fp)
+{
+	sc->fp = fp;
+	sc->nread = 0;
+	sc->ungot_flag = 0;
+	sc->app_ungot = ((fp->__modeflags & __FLAG_UNGOT) ? fp->__ungot[1] : 0);
+#ifdef __UCLIBC_HAS_WCHAR__
+	sc->ungot_wflag = 0;		/* vfwscanf */
+	sc->mb_fail = 0;
+#endif /* __UCLIBC_HAS_WCHAR__ */
+
+#ifdef __UCLIBC_HAS_GLIBC_DIGIT_GROUPING__
+	if (*(sc->grouping = __UCLIBC_CURLOCALE->grouping)) {
+		sc->thousands_sep = (const unsigned char *) __UCLIBC_CURLOCALE->thousands_sep;
+		sc->tslen = __UCLIBC_CURLOCALE->thousands_sep_len;
+#ifdef __UCLIBC_HAS_WCHAR__
+		sc->thousands_sep_wc = __UCLIBC_CURLOCALE->thousands_sep_wc;
+#endif /* __UCLIBC_HAS_WCHAR__ */
+	}
+#endif /* __UCLIBC_HAS_GLIBC_DIGIT_GROUPING__ */
+
+#ifdef __UCLIBC_HAS_FLOATS__
+#ifdef __UCLIBC_HAS_LOCALE__
+	sc->decpt = (const unsigned char *) __UCLIBC_CURLOCALE->decimal_point;
+	sc->decpt_len = __UCLIBC_CURLOCALE->decimal_point_len;
+#else  /* __UCLIBC_HAS_LOCALE__ */
+	sc->fake_decpt = sc->decpt = (unsigned char *) decpt_str;
+	sc->decpt_len = 1;
+#endif /* __UCLIBC_HAS_LOCALE__ */
+#ifdef __UCLIBC_HAS_WCHAR__
+#ifdef __UCLIBC_HAS_LOCALE__
+	sc->decpt_wc = __UCLIBC_CURLOCALE->decimal_point_wc;
+#else
+	sc->decpt_wc = '.';
+#endif
+#endif /* __UCLIBC_HAS_WCHAR__ */
+#endif /* __UCLIBC_HAS_FLOATS__ */
+
+}
+
+int attribute_hidden __scan_getc(register struct scan_cookie *sc)
+{
+	int c;
+
+#ifdef __UCLIBC_HAS_WCHAR__
+	assert(!sc->mb_fail);
+#endif /* __UCLIBC_HAS_WCHAR__ */
+
+	sc->cc = EOF;
+
+	if (--sc->width < 0) {
+		sc->ungot_flag |= 2;
+		return -1;
+	}
+
+	if (sc->ungot_flag == 0) {
+#if !defined(__STDIO_BUFFERS) && !defined(__UCLIBC_HAS_WCHAR__)
+		if (!__STDIO_STREAM_IS_FAKE_VSSCANF_NB(sc->fp)) {
+			c = GETC(sc);
+		} else {
+			__FILE_vsscanf *fv = (__FILE_vsscanf *)(sc->fp);
+			if (fv->bufpos < fv->bufread) {
+				c = *fv->bufpos++;
+			} else {
+				c = EOF;
+				sc->fp->__modeflags |= __FLAG_EOF;
+			}
+		}
+		if (c == EOF) {
+			sc->ungot_flag |= 2;
+			return -1;
+		}
+#else
+		if ((c = GETC(sc)) == EOF) {
+			sc->ungot_flag |= 2;
+			return -1;
+		}
+#endif
+		sc->ungot_char = c;
+	} else {
+		assert(sc->ungot_flag == 1);
+		sc->ungot_flag = 0;
+	}
+
+	++sc->nread;
+	return sc->cc = sc->ungot_char;
+}
+
+void attribute_hidden __scan_ungetc(register struct scan_cookie *sc)
+{
+	++sc->width;
+	if (sc->ungot_flag == 2) {	/* last was EOF */
+		sc->ungot_flag = 0;
+		sc->cc = sc->ungot_char;
+	} else if (sc->ungot_flag == 0) {
+		sc->ungot_flag = 1;
+		--sc->nread;
+	} else {
+		assert(0);
+	}
+}
+
+#endif
+/**********************************************************************/
+#ifdef L___psfs_parse_spec
+
+#ifdef SPEC_FLAGS
+static const unsigned char spec_flags[] = SPEC_FLAGS;
+#endif /* SPEC_FLAGS */
+static const unsigned char spec_chars[] = SPEC_CHARS;
+static const unsigned char qual_chars[] = QUAL_CHARS;
+static const unsigned char spec_ranges[] = SPEC_RANGES;
+static const unsigned short spec_allowed[] = SPEC_ALLOWED_FLAGS;
+
+int attribute_hidden __psfs_parse_spec(register psfs_t *psfs)
+{
+	const unsigned char *p;
+	const unsigned char *fmt0 = psfs->fmt;
+	int i;
+#ifdef SPEC_FLAGS
+	int j;
+#endif
+#if defined(NL_ARGMAX) && (NL_ARGMAX > 0)
+	unsigned char fail = 0;
+
+	i = 0;						/* Do this here to avoid a warning. */
+
+	if (!__isdigit_char(*psfs->fmt)) { /* Not a positional arg. */
+		fail = 1;
+		goto DO_FLAGS;
+	}
+
+	/* parse the positional arg (or width) value */
+	do {
+		if (i <= ((INT_MAX - 9)/10)) {
+			i = (i * 10) + (*psfs->fmt++ - '0');
+		}
+	} while (__isdigit_char(*psfs->fmt));
+
+	if (*psfs->fmt != '$') { /* This is a max field width. */
+		if (psfs->num_pos_args >= 0) { /* Already saw a pos arg! */
+			goto ERROR_EINVAL;
+		}
+		psfs->max_width = i;
+		psfs->num_pos_args = -2;
+		goto DO_QUALIFIER;
+	}
+	++psfs->fmt;			/* Advance past '$'. */
+#endif /* defined(NL_ARGMAX) && (NL_ARGMAX > 0) */
+
+#if defined(SPEC_FLAGS) || (defined(NL_ARGMAX) && (NL_ARGMAX > 0))
+ DO_FLAGS:
+#endif /* defined(SPEC_FLAGS) || (defined(NL_ARGMAX) && (NL_ARGMAX > 0)) */
+#ifdef SPEC_FLAGS
+	p = spec_flags;
+	j = FLAG_SURPRESS;
+	do {
+		if (*p == *psfs->fmt) {
+			++psfs->fmt;
+			psfs->flags |= j;
+			goto DO_FLAGS;
+		}
+		j += j;
+	} while (*++p);
+
+	if (psfs->flags & FLAG_SURPRESS) { /* Suppress assignment. */
+		psfs->store = 0;
+		goto DO_WIDTH;
+	}
+#else  /* SPEC_FLAGS */
+	if (*psfs->fmt == '*') {	/* Suppress assignment. */
+		++psfs->fmt;
+		psfs->store = 0;
+		goto DO_WIDTH;
+	}
+#endif /* SPEC_FLAGS */
+
+
+#if defined(NL_ARGMAX) && (NL_ARGMAX > 0)
+	if (fail) {
+		/* Must be a non-positional arg */
+		if (psfs->num_pos_args >= 0) { /* Already saw a pos arg! */
+			goto ERROR_EINVAL;
+		}
+		psfs->num_pos_args = -2;
+	} else {
+		if ((psfs->num_pos_args == -2) || (((unsigned int)(--i)) >= NL_ARGMAX)) {
+			/* Already saw a non-pos arg or (0-based) num too large. */
+			goto ERROR_EINVAL;
+		}
+		psfs->cur_pos_arg = i;
+	}
+#endif /* defined(NL_ARGMAX) && (NL_ARGMAX > 0) */
+
+ DO_WIDTH:
+	for (i = 0 ; __isdigit_char(*psfs->fmt) ; ) {
+		if (i <= ((INT_MAX - 9)/10)) {
+			i = (i * 10) + (*psfs->fmt++ - '0');
+			psfs->max_width = i;
+		}
+	}
+
+#if defined(NL_ARGMAX) && (NL_ARGMAX > 0)
+ DO_QUALIFIER:
+#endif /* defined(NL_ARGMAX) && (NL_ARGMAX > 0) */
+	p = qual_chars;
+	do {
+		if (*psfs->fmt == *p) {
+			++psfs->fmt;
+			break;
+		}
+	} while (*++p);
+	if ((p - qual_chars < 2) && (*psfs->fmt == *p)) {
+		p += ((sizeof(qual_chars)-2) / 2);
+		++psfs->fmt;
+	}
+	psfs->dataargtype = ((int)(p[(sizeof(qual_chars)-2) / 2])) << 8;
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning CONSIDER: Should we validate that psfs->max_width > 0 in __psfs_parse_spec()?  It would avoid whitespace consumption...
+#warning CONSIDER: Should INT_MAX be a valid width (%c/%C)?  See __psfs_parse_spec().
+#endif /* __UCLIBC_MJN3_ONLY__ */
+
+	p = spec_chars;
+	do {
+		if (*psfs->fmt == *p) {
+			int p_m_spec_chars = p - spec_chars;
+
+#ifdef __UCLIBC_HAS_SCANF_GLIBC_A_FLAG__
+#error implement gnu a flag
+			if ((*p == 'a')
+				&& ((psfs->fmt[1] == '[') || ((psfs->fmt[1]|0x20) == 's'))
+				) {		/* Assumes ascii for 's' and 'S' test. */
+				psfs->flags |= FLAG_MALLOC;
+				++psfs->fmt;
+				++p;
+				continue; /* The related conversions follow 'a'. */
+			}
+#endif /* __UCLIBC_HAS_SCANF_GLIBC_A_FLAG__ */
+
+			for (p = spec_ranges; p_m_spec_chars > *p ; ++p) {}
+			if (((psfs->dataargtype >> 8) | psfs->flags)
+				& ~spec_allowed[(int)(p - spec_ranges)]
+				) {
+				goto ERROR_EINVAL;
+			}
+
+			if (p_m_spec_chars == CONV_p) {
+				/* a pointer has the same size as 'long int'  */
+				psfs->dataargtype = PA_FLAG_LONG;
+			} else if ((p_m_spec_chars >= CONV_c)
+				&& (psfs->dataargtype & PA_FLAG_LONG)) {
+				p_m_spec_chars -= 3; /* lc -> C, ls -> S, l[ -> ?? */
+			}
+
+			psfs->conv_num = p_m_spec_chars;
+			return psfs->fmt - fmt0;
+		}
+		if (!*++p) {
+		ERROR_EINVAL:
+			__set_errno(EINVAL);
+			return -1;
+		}
+	} while(1);
+
+	assert(0);
+}
+
+#endif
+/**********************************************************************/
+#if defined(L_vfscanf) || defined(L_vfwscanf)
+
+#ifdef __UCLIBC_HAS_WCHAR__
+#ifdef L_vfscanf
+static int sc_getc(register struct scan_cookie *sc)
+{
+	return (getc_unlocked)(sc->fp);	/* Disable the macro. */
+}
+
+static int scan_getwc(register struct scan_cookie *sc)
+{
+	size_t r;
+	int width;
+	wchar_t wc[1];
+	char b[1];
+
+	if (--sc->width < 0) {
+		sc->ungot_flag |= 2;
+		return -1;
+	}
+
+	width = sc->width;			/* Preserve width. */
+	sc->width = INT_MAX;		/* MB_CUR_MAX can invoke a function. */
+
+	assert(!sc->mb_fail);
+
+	r = (size_t)(-3);
+	while (__scan_getc(sc) >= 0) {
+		*b = sc->cc;
+
+		r = mbrtowc(wc, b, 1, &sc->mbstate);
+		if (((ssize_t) r) >= 0) { /* Successful completion of a wc. */
+			sc->wc = *wc;
+			goto SUCCESS;
+		} else if (r == ((size_t) -2)) {
+			/* Potentially valid but incomplete. */
+			continue;
+		}
+		break;
+	}
+
+	if (r == ((size_t)(-3))) {	/* EOF or ERROR on first read */
+		sc->wc = WEOF;
+		r = (size_t)(-1);
+	} else {
+		/* If we reach here, either r == ((size_t)-1) and
+		 * mbrtowc set errno to EILSEQ, or r == ((size_t)-2)
+		 * and stream is in an error state or at EOF with a
+		 * partially complete wchar. */
+		__set_errno(EILSEQ);		/* In case of incomplete conversion. */
+		sc->mb_fail = 1;
+	}
+
+ SUCCESS:
+	sc->width = width;			/* Restore width. */
+
+	return (int)((ssize_t) r);
+}
+
+#endif /* L_vfscanf */
+
+#ifdef L_vfwscanf
+
+/* This gets called by __scan_getc.  __scan_getc is called by vfwscanf
+ * when the next wide char is expected to be valid ascii (digits).
+ */
+static int sc_getc(register struct scan_cookie *sc)
+{
+	wint_t wc;
+
+	if (__STDIO_STREAM_IS_FAKE_VSWSCANF(sc->fp)) {
+		if (sc->fp->__bufpos < sc->fp->__bufend) {
+			wc = *((wchar_t *)(sc->fp->__bufpos));
+			sc->fp->__bufpos += sizeof(wchar_t);
+		} else {
+			sc->fp->__modeflags |= __FLAG_EOF;
+			return EOF;
+		}
+	} else if ((wc = fgetwc_unlocked(sc->fp)) == WEOF) {
+		return EOF;
+	}
+
+	sc->ungot_wflag = 1;
+	sc->ungot_wchar = wc;
+	sc->ungot_wchar_width = sc->fp->__ungot_width[0];
+
+#ifdef __UCLIBC_HAS_GLIBC_DIGIT_GROUPING__
+	if (wc == sc->thousands_sep_wc) {
+		wc = ',';
+	} else
+#endif /* __UCLIBC_HAS_GLIBC_DIGIT_GROUPING__ */
+#ifdef __UCLIBC_HAS_FLOATS__
+	if (wc == sc->decpt_wc) {
+		wc = '.';
+	} else
+#endif /* __UCLIBC_HAS_FLOATS__ */
+	sc->wc = sc->ungot_char = wc;
+
+	return (int) wc;
+}
+
+static int scan_getwc(register struct scan_cookie *sc)
+{
+	wint_t wc;
+
+	sc->wc = WEOF;
+
+	if (--sc->width < 0) {
+		sc->ungot_flag |= 2;
+		return -1;
+	}
+
+	if (sc->ungot_flag == 0) {
+		if (__STDIO_STREAM_IS_FAKE_VSWSCANF(sc->fp)) {
+			if (sc->fp->__bufpos < sc->fp->__bufend) {
+				wc = *((wchar_t *)(sc->fp->__bufpos));
+				sc->fp->__bufpos += sizeof(wchar_t);
+			} else {
+				sc->ungot_flag |= 2;
+				return -1;
+			}
+		} else if ((wc = fgetwc_unlocked(sc->fp)) == WEOF) {
+			sc->ungot_flag |= 2;
+			return -1;
+		}
+		sc->ungot_wflag = 1;
+		sc->ungot_char = wc;
+		sc->ungot_wchar_width = sc->fp->__ungot_width[0];
+	} else {
+		assert(sc->ungot_flag == 1);
+		sc->ungot_flag = 0;
+	}
+
+	++sc->nread;
+	sc->wc = sc->ungot_char;
+
+	return 0;
+}
+
+
+#endif /* L_vfwscanf */
+#endif /* __UCLIBC_HAS_WCHAR__ */
+
+static __inline void kill_scan_cookie(register struct scan_cookie *sc)
+{
+#ifdef L_vfscanf
+
+	if (sc->ungot_flag & 1) {
+#if !defined(__STDIO_BUFFERS) && !defined(__UCLIBC_HAS_WCHAR__)
+		if (!__STDIO_STREAM_IS_FAKE_VSSCANF_NB(sc->fp)) {
+			ungetc(sc->ungot_char, sc->fp);
+		}
+#else
+		ungetc(sc->ungot_char, sc->fp);
+#endif
+		/* Deal with distiction between user and scanf ungots. */
+		if (sc->nread == 0) {	/* Only one char was read... app ungot? */
+			sc->fp->__ungot[1] = sc->app_ungot; /* restore ungot state. */
+		} else {
+			sc->fp->__ungot[1] = 0;
+		}
+	}
+
+#else
+
+	if ((sc->ungot_flag & 1) && (sc->ungot_wflag & 1)
+		&& !__STDIO_STREAM_IS_FAKE_VSWSCANF(sc->fp)
+		&& (sc->fp->__state.__mask == 0)
+		) {
+		ungetwc(sc->ungot_char, sc->fp);
+		/* Deal with distiction between user and scanf ungots. */
+		if (sc->nread == 0) {	/* Only one char was read... app ungot? */
+			sc->fp->__ungot[1] = sc->app_ungot; /* restore ungot state. */
+		} else {
+			sc->fp->__ungot[1] = 0;
+		}
+		sc->fp->__ungot_width[1] = sc->ungot_wchar_width;
+	}
+
+#endif
+}
+
+
+int VFSCANF (FILE *__restrict fp, const Wchar *__restrict format, va_list arg)
+{
+	const Wuchar *fmt;
+	unsigned char *b;
+
+#ifdef L_vfwscanf
+	wchar_t wbuf[1];
+	wchar_t *wb;
+#endif /* L_vfwscanf */
+
+#if defined(__UCLIBC_HAS_LOCALE__) && !defined(L_vfwscanf) || !defined(L_vfscanf)
+	mbstate_t mbstate;
+#endif
+
+	struct scan_cookie sc;
+	psfs_t psfs;
+	int i;
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning TODO: Fix MAX_DIGITS.  We do not do binary, so...!
+#endif
+#define MAX_DIGITS 65			/* Allow one leading 0. */
+	unsigned char buf[MAX_DIGITS+2];
+#ifdef L_vfscanf
+	unsigned char scanset[UCHAR_MAX + 1];
+	unsigned char invert;		/* Careful!  Meaning changes. */
+#endif /* L_vfscanf */
+	unsigned char fail;
+	unsigned char zero_conversions = 1;
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning TODO: Make checking of the format string in C locale an option.
+#endif
+	/* To support old programs, don't check mb validity if in C locale. */
+#if defined(__UCLIBC_HAS_LOCALE__) && !defined(L_vfwscanf)
+	/* ANSI/ISO C99 requires format string to be a valid multibyte string
+	 * beginning and ending in its initial shift state. */
+	if (__UCLIBC_CURLOCALE->encoding != __ctype_encoding_7_bit) {
+		const char *p = format;
+		mbstate.__mask = 0;		/* Initialize the mbstate. */
+		if (mbsrtowcs(NULL, &p, SIZE_MAX, &mbstate) == ((size_t)(-1))) {
+			__set_errno(EINVAL); /* Format string is invalid. */
+			return 0;
+		}
+	}
+#endif /* defined(__UCLIBC_HAS_LOCALE__) && !defined(L_vfwscanf) */
+
+#if defined(NL_ARGMAX) && (NL_ARGMAX > 0)
+	psfs.num_pos_args = -1;		/* Must start at -1. */
+	/* Initialize positional arg ptrs to NULL. */
+	memset(psfs.pos_args, 0, sizeof(psfs.pos_args));
+#endif /* defined(NL_ARGMAX) && (NL_ARGMAX > 0) */
+
+	__STDIO_AUTO_THREADLOCK(fp);
+
+	__STDIO_STREAM_VALIDATE(fp);
+
+	__init_scan_cookie(&sc,fp);
+#ifdef __UCLIBC_HAS_WCHAR__
+	sc.sc_getc = sc_getc;
+	sc.ungot_wchar_width = sc.fp->__ungot_width[1];
+
+#ifdef L_vfwscanf
+
+#ifdef __UCLIBC_HAS_GLIBC_DIGIT_GROUPING__
+	if (*sc.grouping) {
+		sc.thousands_sep = (const unsigned char *) ",";
+		sc.tslen = 1;
+	}
+#endif /* __UCLIBC_HAS_GLIBC_DIGIT_GROUPING__ */
+
+#ifdef __UCLIBC_HAS_FLOATS__
+	sc.fake_decpt = (const unsigned char *) ".";
+#endif /* __UCLIBC_HAS_FLOATS__ */
+
+#else  /* L_vfwscanf */
+
+#ifdef __UCLIBC_HAS_FLOATS__
+	sc.fake_decpt = sc.decpt;
+#endif /* __UCLIBC_HAS_FLOATS__ */
+
+#endif /* L_vfwscanf */
+
+#endif /* __UCLIBC_HAS_WCHAR__ */
+	psfs.cnt = 0;
+
+	/* Note: If we ever wanted to support non-nice codesets, we
+	 * would really need to do a mb->wc conversion here in the
+	 * vfscanf case.  Related changes would have to be made in
+	 * the code that follows... basicly wherever fmt appears. */
+	for (fmt = (const Wuchar *) format ; *fmt ; /* ++fmt */) {
+
+		psfs.store = 1;
+		psfs.flags = 0;
+#ifndef NDEBUG
+		psfs.cur_ptr = NULL;	/* Debugging aid. */
+#endif /* NDEBUG */
+
+
+		sc.ungot_flag &= 1;		/* Clear (possible fake) EOF. */
+		sc.width = psfs.max_width = INT_MAX;
+
+		/* Note: According to the standards, vfscanf does use isspace
+		 * here. So, if we did a mb->wc conversion, we would have to do
+		 * something like
+		 *      ((((__uwchar_t)wc) < UCHAR_MAX) && isspace(wc))
+		 * because wc might not be in the allowed domain. */
+		if (ISSPACE(*fmt)) {
+			do {
+				++fmt;
+			} while (ISSPACE(*fmt));
+			--fmt;
+			psfs.conv_num = CONV_whitespace;
+			goto DO_WHITESPACE;
+		}
+
+		if (*fmt == '%') {		/* Conversion specification. */
+			if (*++fmt == '%') { /* Remember, '%' eats whitespace too. */
+				/* Note: The standard says no conversion occurs.
+				 * So do not reset zero_conversions flag. */
+				psfs.conv_num = CONV_percent;
+				goto DO_CONVERSION;
+			}
+
+
+#ifdef L_vfscanf
+			psfs.fmt = fmt;
+#else  /* L_vfscanf */
+			{
+				const __uwchar_t *wf = fmt;
+				psfs.fmt = b = buf;
+
+				while (*wf && __isascii(*wf) && (b < buf + sizeof(buf) - 1)) {
+					*b++ = *wf++;
+				}
+#ifdef __UCLIBC_HAS_SCANF_GLIBC_A_FLAG__
+#error this is wrong... we need to ched in __psfs_parse_spec instead since this checks last char in buffer and conversion my have stopped before it.
+				if ((*b == 'a') && ((*wf == '[') || ((*wf|0x20) == 's'))) {
+					goto DONE;	/* Spec was excessively long. */
+				}
+#endif /* __UCLIBC_HAS_SCANF_GLIBC_A_FLAG__ */
+				*b = 0;
+				if (b == buf) { /* Bad conversion specifier! */
+					goto DONE;
+				}
+			}
+#endif /* L_vfscanf */
+			if ((i = __psfs_parse_spec(&psfs)) < 0) { /* Bad conversion specifier! */
+				goto DONE;
+			}
+			fmt += i;
+
+			if (psfs.store) {
+#if defined(NL_ARGMAX) && (NL_ARGMAX > 0)
+				if (psfs.num_pos_args == -2) {
+					psfs.cur_ptr = va_arg(arg, void *);
+				} else {
+					while (psfs.cur_pos_arg > psfs.num_pos_args) {
+						psfs.pos_args[++psfs.num_pos_args] = va_arg(arg, void *);
+					}
+					psfs.cur_ptr = psfs.pos_args[psfs.cur_pos_arg];
+				}
+#else  /* defined(NL_ARGMAX) && (NL_ARGMAX > 0) */
+				psfs.cur_ptr = va_arg(arg, void *);
+#endif /* defined(NL_ARGMAX) && (NL_ARGMAX > 0) */
+			}
+
+		DO_CONVERSION:
+			/* First, consume white-space if not n, c, [, C, or l[. */
+			if ((((1L << CONV_n)|(1L << CONV_C)|(1L << CONV_c)
+				 |(1L << CONV_LEFTBRACKET)|(1L << CONV_leftbracket))
+				 & (1L << psfs.conv_num)) == 0
+				) {
+			DO_WHITESPACE:
+				while ((__scan_getc(&sc) >= 0)
+#ifdef L_vfscanf
+					   && isspace(sc.cc)
+#else  /* L_vfscanf */
+					   && iswspace(sc.wc)
+#endif /* L_vfscanf */
+					   ) {}
+				__scan_ungetc(&sc);
+				if (psfs.conv_num == CONV_whitespace) {
+					goto NEXT_FMT;
+				}
+			}
+
+			sc.width = psfs.max_width; /* Now limit the max width. */
+
+			if (sc.width == 0) { /* 0 width is forbidden. */
+				goto DONE;
+			}
+
+
+			if (psfs.conv_num == CONV_percent) {
+				goto MATCH_CHAR;
+			}
+
+			if (psfs.conv_num == CONV_n) {
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning CONSIDER: Should %n count as a conversion as far as EOF return value?
+#endif
+/* 				zero_conversions = 0; */
+				if (psfs.store) {
+					_store_inttype(psfs.cur_ptr, psfs.dataargtype,
+								   (uintmax_t) sc.nread);
+				}
+				goto NEXT_FMT;
+			}
+
+			if (psfs.conv_num <= CONV_A) { /* pointer, integer, or float spec */
+				int r = __psfs_do_numeric(&psfs, &sc);
+#ifndef L_vfscanf
+				if (sc.ungot_wflag == 1) {	/* fix up  '?', '.', and ',' hacks */
+					sc.cc = sc.ungot_char = sc.ungot_wchar;
+				}
+#endif
+				if (r != -1) {	/* Either success or a matching failure. */
+					zero_conversions = 0;
+				}
+				if (r < 0) {
+					goto DONE;
+				}
+				goto NEXT_FMT;
+			}
+
+			/* Do string conversions here since they are not common code. */
+
+
+#ifdef L_vfscanf
+
+			if
+#ifdef __UCLIBC_HAS_WCHAR__
+				(psfs.conv_num >= CONV_LEFTBRACKET)
+#else  /* __UCLIBC_HAS_WCHAR__ */
+				(psfs.conv_num >= CONV_c)
+#endif /* __UCLIBC_HAS_WCHAR__ */
+			{
+				b = (psfs.store ? ((unsigned char *) psfs.cur_ptr) : buf);
+				fail = 1;
+
+				if (psfs.conv_num == CONV_c) {
+					if (sc.width == INT_MAX) {
+						sc.width = 1;
+					}
+
+					while (__scan_getc(&sc) >= 0) {
+						zero_conversions = 0;
+						*b = sc.cc;
+						b += psfs.store;
+					}
+					__scan_ungetc(&sc);
+					if (sc.width > 0) {	/* Failed to read all required. */
+						goto DONE;
+					}
+					psfs.cnt += psfs.store;
+					goto NEXT_FMT;
+				}
+
+				if (psfs.conv_num == CONV_s) {
+					/* Yes, believe it or not, a %s conversion can store nuls. */
+					while ((__scan_getc(&sc) >= 0) && !isspace(sc.cc)) {
+						zero_conversions = 0;
+						*b = sc.cc;
+						b += psfs.store;
+						fail = 0;
+					}
+				} else {
+#ifdef __UCLIBC_HAS_WCHAR__
+					assert((psfs.conv_num == CONV_LEFTBRACKET) || \
+						   (psfs.conv_num == CONV_leftbracket));
+#else /* __UCLIBC_HAS_WCHAR__ */
+					assert((psfs.conv_num == CONV_leftbracket));
+#endif /* __UCLIBC_HAS_WCHAR__ */
+
+					invert = 0;
+
+					if (*++fmt == '^') {
+						++fmt;
+						invert = 1;
+					}
+					memset(scanset, invert, sizeof(scanset));
+					invert = 1-invert;
+
+					if (*fmt == ']') {
+						scanset[(int)(']')] = invert;
+						++fmt;
+					}
+
+					while (*fmt != ']') {
+						if (!*fmt) { /* No closing ']'. */
+							goto DONE;
+						}
+						if ((*fmt == '-') && (fmt[1] != ']')
+							&& (fmt[-1] < fmt[1]) /* sorted? */
+							) {	/* range */
+							++fmt;
+							i = fmt[-2];
+							/* Note: scanset[i] should already have been done
+							 * in the previous iteration. */
+							do {
+								scanset[++i] = invert;
+							} while (i < *fmt);
+							/* Safe to fall through, and a bit smaller. */
+						}
+						/* literal char */
+						scanset[(int) *fmt] = invert;
+						++fmt;
+					}
+
+#ifdef __UCLIBC_HAS_WCHAR__
+					if (psfs.conv_num == CONV_LEFTBRACKET) {
+						goto DO_LEFTBRACKET;
+					}
+#endif /* __UCLIBC_HAS_WCHAR__ */
+
+
+					while (__scan_getc(&sc) >= 0) {
+						zero_conversions = 0;
+						if (!scanset[sc.cc]) {
+							break;
+						}
+						*b = sc.cc;
+						b += psfs.store;
+						fail = 0;
+					}
+				}
+				/* Common tail for processing of %s and %[. */
+
+				__scan_ungetc(&sc);
+				if (fail) {	/* nothing stored! */
+					goto DONE;
+				}
+				*b = 0;		/* Nul-terminate string. */
+				psfs.cnt += psfs.store;
+				goto NEXT_FMT;
+			}
+
+#ifdef __UCLIBC_HAS_WCHAR__
+		DO_LEFTBRACKET:			/* Need to do common wide init. */
+			if (psfs.conv_num >= CONV_C) {
+				wchar_t wbuf[1];
+				wchar_t *wb;
+
+				sc.mbstate.__mask = 0;
+
+				wb = (psfs.store ? ((wchar_t *) psfs.cur_ptr) : wbuf);
+				fail = 1;
+
+				if (psfs.conv_num == CONV_C) {
+					if (sc.width == INT_MAX) {
+						sc.width = 1;
+					}
+
+					while (scan_getwc(&sc) >= 0) {
+						zero_conversions = 0;
+						assert(sc.width >= 0);
+						*wb = sc.wc;
+						wb += psfs.store;
+					}
+
+					__scan_ungetc(&sc);
+					if (sc.width > 0) {	/* Failed to read all required. */
+						goto DONE;
+					}
+					psfs.cnt += psfs.store;
+					goto NEXT_FMT;
+				}
+
+
+				if (psfs.conv_num == CONV_S) {
+					/* Yes, believe it or not, a %s conversion can store nuls. */
+					while (scan_getwc(&sc) >= 0) {
+						zero_conversions = 0;
+						if ((((__uwchar_t)(sc.wc)) <= UCHAR_MAX) && isspace(sc.wc)) {
+							break;
+						}
+						*wb = sc.wc;
+						wb += psfs.store;
+						fail = 0;
+					}
+				} else {
+					assert(psfs.conv_num == CONV_LEFTBRACKET);
+
+					while (scan_getwc(&sc) >= 0) {
+						zero_conversions = 0;
+						if (((__uwchar_t) sc.wc) <= UCHAR_MAX) {
+							if (!scanset[sc.wc]) {
+								break;
+							}
+						} else if (invert) {
+							break;
+						}
+						*wb = sc.wc;
+						wb += psfs.store;
+						fail = 0;
+					}
+				}
+				/* Common tail for processing of %ls and %l[. */
+
+				__scan_ungetc(&sc);
+				if (fail || sc.mb_fail) { /* Nothing stored or mb error. */
+					goto DONE;
+				}
+				*wb = 0;		/* Nul-terminate string. */
+				psfs.cnt += psfs.store;
+				goto NEXT_FMT;
+
+			}
+
+#endif /* __UCLIBC_HAS_WCHAR__ */
+#else  /* L_vfscanf */
+
+			if (psfs.conv_num >= CONV_C) {
+				b = buf;
+				wb = wbuf;
+				if (psfs.conv_num >= CONV_c) {
+					mbstate.__mask = 0;		/* Initialize the mbstate. */
+					if (psfs.store) {
+						b = (unsigned char *) psfs.cur_ptr;
+					}
+				} else {
+					if (psfs.store) {
+						wb = (wchar_t *) psfs.cur_ptr;
+					}
+				}
+				fail = 1;
+
+
+				if ((psfs.conv_num == CONV_C) || (psfs.conv_num == CONV_c)) {
+					if (sc.width == INT_MAX) {
+						sc.width = 1;
+					}
+
+					while (scan_getwc(&sc) >= 0) {
+						zero_conversions = 0;
+						if (psfs.conv_num == CONV_C) {
+							*wb = sc.wc;
+							wb += psfs.store;
+						} else {
+							i = wcrtomb((char*) b, sc.wc, &mbstate);
+							if (i < 0) { /* Conversion failure. */
+								goto DONE_DO_UNGET;
+							}
+							if (psfs.store) {
+								b += i;
+							}
+						}
+					}
+					__scan_ungetc(&sc);
+					if (sc.width > 0) {	/* Failed to read all required. */
+						goto DONE;
+					}
+					psfs.cnt += psfs.store;
+					goto NEXT_FMT;
+				}
+
+				if ((psfs.conv_num == CONV_S) || (psfs.conv_num == CONV_s)) {
+					/* Yes, believe it or not, a %s conversion can store nuls. */
+					while (scan_getwc(&sc) >= 0) {
+						zero_conversions = 0;
+						if  (iswspace(sc.wc)) {
+							break;
+						}
+						if (psfs.conv_num == CONV_S) {
+							*wb = sc.wc;
+							wb += psfs.store;
+						} else {
+							i = wcrtomb((char*) b, sc.wc, &mbstate);
+							if (i < 0) { /* Conversion failure. */
+								goto DONE_DO_UNGET;
+							}
+							if (psfs.store) {
+								b += i;
+							}
+						}
+						fail = 0;
+					}
+				} else {
+					const wchar_t *sss;
+					const wchar_t *ssp;
+					unsigned char invert = 0;
+
+					assert((psfs.conv_num == CONV_LEFTBRACKET)
+						   || (psfs.conv_num == CONV_leftbracket));
+
+					if (*++fmt == '^') {
+						++fmt;
+						invert = 1;
+					}
+					sss = (const wchar_t *) fmt;
+					if (*fmt == ']') {
+						++fmt;
+					}
+					while (*fmt != ']') {
+						if (!*fmt) { /* No closing ']'. */
+							goto DONE;
+						}
+						if ((*fmt == '-') && (fmt[1] != ']')
+							&& (fmt[-1] < fmt[1]) /* sorted? */
+							) {	/* range */
+							++fmt;
+						}
+						++fmt;
+					}
+					/* Ok... a valid scanset spec. */
+
+					while (scan_getwc(&sc) >= 0) {
+						zero_conversions = 0;
+						ssp = sss;
+						do {	/* We know sss < fmt. */
+							if (*ssp == '-') { /* possible range... */
+								/* Note: We accept a-c-e (ordered) as
+								 * equivalent to a-e. */
+								if (ssp > sss) {
+									if ((++ssp < (const wchar_t *) fmt)
+										&& (ssp[-2] < *ssp)	/* sorted? */
+										) { /* yes */
+										if ((sc.wc >= ssp[-2])
+											&& (sc.wc <= *ssp)) {
+											break;
+										}
+										continue; /* not in range */
+									}
+									--ssp; /* oops... '-' at end, so back up */
+								}
+								/* false alarm... a literal '-' */
+							}
+							if (sc.wc == *ssp) { /* Matched literal char. */
+								break;
+							}
+						} while (++ssp < (const wchar_t *) fmt);
+
+						if ((ssp == (const wchar_t *) fmt) ^ invert) {
+							/* no match and not inverting
+							 * or match and inverting */
+							break;
+						}
+						if (psfs.conv_num == CONV_LEFTBRACKET) {
+							*wb = sc.wc;
+							wb += psfs.store;
+						} else {
+							i = wcrtomb((char*) b, sc.wc, &mbstate);
+							if (i < 0) { /* Conversion failure. */
+								goto DONE_DO_UNGET;
+							}
+							if (psfs.store) {
+								b += i;
+							}
+						}
+						fail = 0;
+					}
+				}
+				/* Common tail for processing of %s and %[. */
+
+				__scan_ungetc(&sc);
+				if (fail) {	/* nothing stored! */
+					goto DONE;
+				}
+				*wb = 0;		/* Nul-terminate string. */
+				*b = 0;
+				psfs.cnt += psfs.store;
+				goto NEXT_FMT;
+			}
+
+#endif /* L_vfscanf */
+
+			assert(0);
+			goto DONE;
+		} /* conversion specification */
+
+	MATCH_CHAR:
+		if (__scan_getc(&sc) != *fmt) {
+#ifdef L_vfwscanf
+		DONE_DO_UNGET:
+#endif /* L_vfwscanf */
+			__scan_ungetc(&sc);
+			goto DONE;
+		}
+
+	NEXT_FMT:
+		++fmt;
+		if (__FERROR_UNLOCKED(fp)) {
+			break;
+		}
+	}
+
+ DONE:
+	if (__FERROR_UNLOCKED(fp) || (*fmt && zero_conversions && __FEOF_UNLOCKED(fp))) {
+		psfs.cnt = EOF;			/* Yes, vfwscanf also returns EOF. */
+	}
+
+	kill_scan_cookie(&sc);
+
+	__STDIO_STREAM_VALIDATE(fp);
+
+	__STDIO_AUTO_THREADUNLOCK(fp);
+
+	return psfs.cnt;
+}
+libc_hidden_def(VFSCANF)
+#endif
+/**********************************************************************/
+#ifdef L___psfs_do_numeric
+
+static const unsigned char spec_base[] = SPEC_BASE;
+static const unsigned char nil_string[] = "(nil)";
+
+int attribute_hidden __psfs_do_numeric(psfs_t *psfs, struct scan_cookie *sc)
+{
+	unsigned char *b;
+	const unsigned char *p;
+
+#ifdef __UCLIBC_HAS_FLOATS__
+	int exp_adjust = 0;
+#endif
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning TODO: Fix MAX_DIGITS.  We do not do binary, so...!
+#warning TODO: Fix buf!
+#endif
+#define MAX_DIGITS 65			/* Allow one leading 0. */
+	unsigned char buf[MAX_DIGITS+2+ 100];
+	unsigned char usflag, base;
+	unsigned char nonzero = 0;
+	unsigned char seendigit = 0;
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning CONSIDER: What should be returned for an invalid conversion specifier?
+#endif
+#ifndef __UCLIBC_HAS_FLOATS__
+	if (psfs->conv_num > CONV_i) { /* floating point */
+		goto DONE;
+	}
+#endif
+
+	base = spec_base[psfs->conv_num - CONV_p];
+	usflag = (psfs->conv_num <= CONV_u); /* (1)0 if (un)signed */
+	b = buf;
+
+
+	if (psfs->conv_num == CONV_p) { /* Pointer */
+		p = nil_string;
+		do {
+			if ((__scan_getc(sc) < 0) || (*p != sc->cc)) {
+				__scan_ungetc(sc);
+				if (p > nil_string) {
+					/* We matched at least the '(' so even if we
+					 * are at eof,  we can not match a pointer. */
+					return -2;	/* Matching failure */
+				}
+				break;
+			}
+			if (!*++p) {   /* Matched (nil), so no unget necessary. */
+				if (psfs->store) {
+					++psfs->cnt;
+					_store_inttype(psfs->cur_ptr, psfs->dataargtype,
+								   (uintmax_t)0);
+				}
+				return 0;
+			}
+		} while (1);
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning CONSIDER: Should we require a 0x prefix and disallow +/- for pointer %p?
+#endif /*  __UCLIBC_MJN3_ONLY__ */
+	}
+
+	__scan_getc(sc);
+	if (sc->cc < 0) {
+		return -1;				/* Input failure (nothing read yet). */
+	}
+
+	if ((sc->cc == '+') || (sc->cc == '-')) { /* Handle leading sign.*/
+		*b++ = sc->cc;
+		__scan_getc(sc);
+	}
+
+	if ((base & 0xef) == 0) { /* 0xef is ~16, so 16 or 0. */
+		if (sc->cc == '0') {	/* Possibly set base and handle prefix. */
+			__scan_getc(sc);
+			if ((sc->cc|0x20) == 'x') { /* Assumes ascii.. x or X. */
+				if (__scan_getc(sc) < 0) {
+					/* Either EOF or error (including wc outside char range).
+					 * If EOF or error, this is a matching failure (we read 0x).
+					 * If wc outside char range, this is also a matching failure.
+					 * Hence, we do an unget (although not really necessary here
+					 * and fail. */
+					goto DONE_DO_UNGET;	/* matching failure */
+				}
+				base = 16; /* Base 16 for sure now. */
+#ifdef __UCLIBC_HAS_HEXADECIMAL_FLOATS__
+				/* The prefix is required for hexadecimal floats. */
+				*b++ = '0';
+				*b++ = 'x';
+#endif /* __UCLIBC_HAS_HEXADECIMAL_FLOATS__ */
+			} else { /* oops... back up */
+				__scan_ungetc(sc);
+				sc->cc = '0';	/* NASTY HACK! */
+
+				base = (base >> 1) + 8;	/* 0->8, 16->16.  no 'if' */
+#ifdef __UCLIBC_HAS_FLOATS__
+				if (psfs->conv_num > CONV_i) { /* floating point */
+					base = 10;
+				}
+#endif
+			}
+		} else if (!base) {
+			base = 10;
+		}
+	}
+
+	/***************** digit grouping **********************/
+#ifdef __UCLIBC_HAS_GLIBC_DIGIT_GROUPING__
+
+	if ((psfs->flags & FLAG_THOUSANDS) && (base == 10)
+		&& *(p = (const unsigned char *) sc->grouping)
+		) {
+
+		int nblk1, nblk2, nbmax, lastblock, pass, i;
+
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning CONSIDER: Should we initalize the grouping blocks in __init_scan_cookie()?
+#endif /*  __UCLIBC_MJN3_ONLY__ */
+		nbmax = nblk2 = nblk1 = *p;
+		if (*++p) {
+			nblk2 = *p;
+			if (nbmax < nblk2) {
+				nbmax = nblk2;
+			}
+			assert(!p[1]);
+		}
+
+		/* Note: for printf, if 0 and \' flags appear then
+		 * grouping is done before 0-padding.  Should we
+		 * strip leading 0's first?  Or add a 0 flag? */
+
+		/* For vfwscanf, sc_getc translates, so the value of sc->cc is
+		 * either EOF or a char. */
+
+		if (!__isdigit_char_or_EOF(sc->cc)) { /* No starting digit! */
+#ifdef __UCLIBC_HAS_FLOATS__
+			if (psfs->conv_num > CONV_i) { /* floating point */
+				goto NO_STARTING_DIGIT;
+			}
+#endif
+			goto DONE_DO_UNGET;
+		}
+
+		if (sc->cc == '0') {
+			seendigit = 1;
+			*b++ = '0';			/* Store the first 0. */
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning CONSIDER: Should leading 0s be skipped before digit grouping? (printf 0 pad)
+#endif /*  __UCLIBC_MJN3_ONLY__ */
+#if 0
+			do {				/* But ignore all subsequent 0s. */
+				__scan_getc(sc);
+			} while (sc->cc == '0');
+#endif
+		}
+		pass = 0;
+		lastblock = 0;
+		do {
+			i = 0;
+			while (__isdigit_char_or_EOF(sc->cc)) {
+				seendigit = 1;
+				if (i == nbmax) { /* too many digits for a block */
+#ifdef __UCLIBC_HAS_SCANF_LENIENT_DIGIT_GROUPING__
+					if (!pass) { /* treat as nongrouped */
+						if (nonzero) {
+							goto DO_NO_GROUP;
+						}
+						goto DO_TRIM_LEADING_ZEROS;
+					}
+#endif
+					if (nbmax > nblk1) {
+						goto DONE_DO_UNGET;	/* matching failure */
+					}
+					goto DONE_GROUPING_DO_UNGET; /* nbmax == nblk1 */
+				}
+				++i;
+
+				if (nonzero || (sc->cc != '0')) {
+					if (b < buf + MAX_DIGITS) {
+						*b++ = sc->cc;
+						nonzero = 1;
+#ifdef __UCLIBC_HAS_FLOATS__
+					} else {
+						++exp_adjust;
+#endif
+					}
+				}
+
+				__scan_getc(sc);
+			}
+
+			if (i) {			/* we saw digits digits */
+				if ((i == nblk2) || ((i < nblk2) && !pass)) {
+					/* (possible) outer grp */
+					p = sc->thousands_sep;
+					if (*p == sc->cc) {	/* first byte matches... */
+						/* so check if grouping mb char */
+						/* Since 1st matched, either match or fail now
+						 * unless EOF (yuk) */
+						__scan_getc(sc);
+					MBG_LOOP:
+						if (!*++p) { /* is a grouping mb char */
+							lastblock = i;
+							++pass;
+							continue;
+						}
+						if (*p == sc->cc) {
+							__scan_getc(sc);
+							goto MBG_LOOP;
+						}
+						/* bad grouping mb char! */
+						__scan_ungetc(sc);
+						if ((sc->cc >= 0) || (p > sc->thousands_sep + 1)) {
+#ifdef __UCLIBC_HAS_FLOATS__
+							/* We failed to match a thousep mb char, and
+							 * we've read too much to recover.  But if
+							 * this is a floating point conversion and
+							 * the initial portion of the decpt mb char
+							 * matches, then we may still be able to
+							 * recover. */
+							int k = p - sc->thousands_sep - 1;
+
+							if ((psfs->conv_num > CONV_i) /* float conversion */
+								&& (!pass || (i == nblk1)) /* possible last */
+								&& !memcmp(sc->thousands_sep, sc->fake_decpt, k)
+								/* and prefix matched, so could be decpt */
+								) {
+								__scan_getc(sc);
+								p = sc->fake_decpt + k;
+								do {
+									if (!*++p) {
+										strcpy((char*) b, (char*) sc->decpt);
+										b += sc->decpt_len;
+										goto GOT_DECPT;
+									}
+									if (*p != sc->cc) {
+										__scan_ungetc(sc);
+										break; /* failed */
+									}
+									__scan_getc(sc);
+								} while (1);
+							}
+#endif /* __UCLIBC_HAS_FLOATS__ */
+							goto DONE;
+						}
+						/* was EOF and 1st, so recoverable. */
+					}
+				}
+				if ((i == nblk1) || ((i < nblk1) && !pass)) {
+					/* got an inner group */
+					goto DONE_GROUPING_DO_UNGET;
+				}
+				goto DONE_DO_UNGET;	/* Matching failure. */
+			} /* i != 0 */
+
+			assert(pass);
+
+			goto DONE_DO_UNGET;
+		} while (1);
+
+		assert(0);				/* Should never get here. */
+	}
+
+#endif /***************** digit grouping **********************/
+
+	/* Not grouping so first trim all but one leading 0. */
+#ifdef __UCLIBC_HAS_SCANF_LENIENT_DIGIT_GROUPING__
+	DO_TRIM_LEADING_ZEROS:
+#endif /* __UCLIBC_HAS_SCANF_LENIENT_DIGIT_GROUPING__ */
+	if (sc->cc == '0') {
+		seendigit = 1;
+		*b++ = '0';				/* Store the first 0. */
+		do {					/* But ignore all subsequent 0s. */
+			__scan_getc(sc);
+		} while (sc->cc == '0');
+	}
+
+#ifdef __UCLIBC_HAS_SCANF_LENIENT_DIGIT_GROUPING__
+ DO_NO_GROUP:
+#endif /* __UCLIBC_HAS_SCANF_LENIENT_DIGIT_GROUPING__ */
+	/* At this point, we're ready to start reading digits. */
+
+#define valid_digit(cc,base) (isxdigit(cc) && ((base == 16) || (cc - '0' < base)))
+
+	while (valid_digit(sc->cc,base)) { /* Now for significant digits.*/
+		if (b - buf < MAX_DIGITS) {
+			nonzero = seendigit = 1; /* Set nonzero too 0s trimmed above. */
+			*b++ = sc->cc;
+#ifdef __UCLIBC_HAS_FLOATS__
+		} else {
+			++exp_adjust;
+#endif
+		}
+		__scan_getc(sc);
+	}
+
+#ifdef __UCLIBC_HAS_GLIBC_DIGIT_GROUPING__
+ DONE_GROUPING_DO_UNGET:
+#endif /* __UCLIBC_HAS_GLIBC_DIGIT_GROUPING__ */
+	if (psfs->conv_num <= CONV_i) { /* integer conversion */
+		__scan_ungetc(sc);
+		*b = 0;						/* null-terminate */
+		if (!seendigit) {
+			goto DONE;				/* No digits! */
+		}
+		if (psfs->store) {
+			if (*buf == '-') {
+				usflag = 0;
+			}
+			++psfs->cnt;
+			_store_inttype(psfs->cur_ptr, psfs->dataargtype,
+						   (uintmax_t) STRTOUIM((char *) buf, NULL, base, 1-usflag));
+		}
+		return 0;
+	}
+
+#ifdef __UCLIBC_HAS_FLOATS__
+
+	/* At this point, we have everything left of the decimal point or exponent. */
+#ifdef __UCLIBC_HAS_GLIBC_DIGIT_GROUPING__
+ NO_STARTING_DIGIT:
+#endif
+	p = sc->fake_decpt;
+	do {
+		if (!*p) {
+			strcpy((char *) b, (char *) sc->decpt);
+			b += sc->decpt_len;
+			break;
+		}
+		if (*p != sc->cc) {
+			if (p > sc->fake_decpt) {
+				goto DONE_DO_UNGET;	/* matching failure (read some of decpt) */
+			}
+			goto DO_DIGIT_CHECK;
+		}
+		++p;
+		__scan_getc(sc);
+	} while (1);
+
+#ifdef __UCLIBC_HAS_GLIBC_DIGIT_GROUPING__
+ GOT_DECPT:
+#endif
+	if (!nonzero) {
+		if (sc->cc == '0') {
+			assert(exp_adjust == 0);
+			*b++ = '0';
+			++exp_adjust;
+			seendigit = 1;
+			do {
+				--exp_adjust;
+				__scan_getc(sc);
+			} while (sc->cc == '0');
+		}
+	}
+
+	while (valid_digit(sc->cc,base)) { /* Process fractional digits.*/
+		if (b - buf < MAX_DIGITS) {
+			seendigit = 1;
+			*b++ = sc->cc;
+		}
+		__scan_getc(sc);
+	}
+
+ DO_DIGIT_CHECK:
+	/* Hmm... no decimal point.   */
+	if (!seendigit) {
+		static const unsigned char nan_inf_str[] = "an\0nfinity";
+
+		if (base == 16) {		/* We had a prefix, but no digits! */
+			goto DONE_DO_UNGET;	/* matching failure */
+		}
+
+		/* Avoid tolower problems for INFINITY in the tr_TR locale. (yuk)*/
+#undef TOLOWER
+#define TOLOWER(C)     ((C)|0x20)
+
+		switch (TOLOWER(sc->cc)) {
+			case 'i':
+				p = nan_inf_str + 3;
+				break;
+			case 'n':
+				p = nan_inf_str;
+				break;
+			default:
+				/* No digits and not inf or nan. */
+				goto DONE_DO_UNGET;
+		}
+
+		*b++ = sc->cc;
+
+		do {
+			__scan_getc(sc);
+			if (TOLOWER(sc->cc) == *p) {
+				*b++ = sc->cc;
+				++p;
+				continue;
+			}
+			if (!*p || (p == nan_inf_str + 5)) { /* match nan/infinity or inf */
+				goto GOT_FLOAT;
+			}
+			/* Unrecoverable.  Even if on 1st char, we had no digits. */
+			goto DONE_DO_UNGET;
+		} while (1);
+	}
+
+	/* If we get here, we had some digits. */
+
+	if (
+#ifdef __UCLIBC_HAS_HEXADECIMAL_FLOATS__
+		((base == 16) && (((sc->cc)|0x20) == 'p')) ||
+#endif
+		(((sc->cc)|0x20) == 'e')
+		) {						/* Process an exponent. */
+		*b++ = sc->cc;
+
+		__scan_getc(sc);
+		if (sc->cc < 0) {
+			goto DONE_DO_UNGET;	/* matching failure.. no exponent digits */
+		}
+
+		if ((sc->cc == '+') || (sc->cc == '-')) { /* Signed exponent? */
+			*b++ = sc->cc;
+			__scan_getc(sc);
+		}
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning TODO: Fix MAX_EXP_DIGITS!
+#endif
+#define MAX_EXP_DIGITS 20
+		assert(seendigit);
+		seendigit = 0;
+		nonzero = 0;
+
+		if (sc->cc == '0') {
+			seendigit = 1;
+			*b++ = '0';
+			do {
+				__scan_getc(sc);
+			} while (sc->cc == '0');
+		}
+
+		while (__isdigit_char_or_EOF(sc->cc)) { /* Exponent digits (base 10).*/
+			if (seendigit < MAX_EXP_DIGITS) {
+				++seendigit;
+				*b++ = sc->cc;
+			}
+			__scan_getc(sc);
+		}
+
+		if (!seendigit) {		/* No digits.  Unrecoverable. */
+			goto DONE_DO_UNGET;
+		}
+	}
+
+
+ GOT_FLOAT:
+	*b = 0;
+	{
+		__fpmax_t x;
+		char *e;
+		x = __strtofpmax((char *) buf, &e, exp_adjust);
+		assert(!*e);
+		if (psfs->store) {
+			if (psfs->dataargtype & PA_FLAG_LONG_LONG) {
+				*((long double *)psfs->cur_ptr) = (long double) x;
+			} else if (psfs->dataargtype & PA_FLAG_LONG) {
+				*((double *)psfs->cur_ptr) = (double) x;
+			} else {
+				*((float *)psfs->cur_ptr) = (float) x;
+			}
+			++psfs->cnt;
+		}
+		__scan_ungetc(sc);
+		return 0;
+	}
+#endif /* __UCLIBC_HAS_FLOATS__ */
+
+ DONE_DO_UNGET:
+	__scan_ungetc(sc);
+ DONE:
+	return -2;					/* Matching failure. */
+
+}
+#endif
+/**********************************************************************/
diff --git a/ap/build/uClibc/libc/stdio/_stdio.c b/ap/build/uClibc/libc/stdio/_stdio.c
new file mode 100644
index 0000000..2abd63a
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/_stdio.c
@@ -0,0 +1,451 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+/* This is pretty much straight from uClibc, but with one important
+ * difference.
+ *
+ * We now initialize the locking flag to user locking instead of
+ * auto locking (i.e. FSETLOCKING_BYCALLER vs FSETLOCKING_INTERNAL).
+ * This greatly benefits non-threading applications linked to a
+ * shared thread-enabled library.  In threading applications, we
+ * walk the stdio open file list and reset the locking mode
+ * appropriately when the thread subsystem is initialized.
+ */
+
+/**********************************************************************/
+
+#ifdef __UCLIBC_HAS_WCHAR__
+#define __STDIO_FILE_INIT_WUNGOT		{ 0, 0 },
+#else
+#define __STDIO_FILE_INIT_WUNGOT
+#endif
+
+#ifdef __STDIO_GETC_MACRO
+# define __STDIO_FILE_INIT_BUFGETC(x) x,
+#else
+# define __STDIO_FILE_INIT_BUFGETC(x)
+#endif
+
+#ifdef __STDIO_PUTC_MACRO
+# define __STDIO_FILE_INIT_BUFPUTC(x) x,
+#else
+# define __STDIO_FILE_INIT_BUFPUTC(x)
+#endif
+
+#ifdef __STDIO_HAS_OPENLIST
+#define __STDIO_FILE_INIT_NEXT(next)	(next),
+#else
+#define __STDIO_FILE_INIT_NEXT(next)
+#endif
+
+#ifdef __STDIO_BUFFERS
+#define __STDIO_FILE_INIT_BUFFERS(buf,bufsize) \
+	(buf), (buf)+(bufsize), (buf), (buf),
+#else
+#define __STDIO_FILE_INIT_BUFFERS(buf,bufsize)
+#endif
+
+#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
+#define __STDIO_FILE_INIT_CUSTOM_STREAM(stream) \
+	&((stream).__filedes), { _cs_read, _cs_write, _cs_seek, _cs_close },
+#else
+#define __STDIO_FILE_INIT_CUSTOM_STREAM(stream)
+#endif
+
+#ifdef __STDIO_MBSTATE
+#define __STDIO_FILE_INIT_MBSTATE \
+	{ 0, 0 },
+#else
+#define __STDIO_FILE_INIT_MBSTATE
+#endif
+
+#ifdef __UCLIBC_HAS_XLOCALE__
+#define __STDIO_FILE_INIT_UNUSED \
+	NULL,
+#else
+#define __STDIO_FILE_INIT_UNUSED
+#endif
+
+#ifdef __UCLIBC_HAS_THREADS__
+#ifdef __USE_STDIO_FUTEXES__
+#define __STDIO_FILE_INIT_THREADSAFE \
+	2, _LIBC_LOCK_RECURSIVE_INITIALIZER,
+#else
+#define __STDIO_FILE_INIT_THREADSAFE \
+	2, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP,
+#endif
+#else
+#define __STDIO_FILE_INIT_THREADSAFE
+#endif
+
+#define __STDIO_INIT_FILE_STRUCT(stream, flags, filedes, next, buf, bufsize) \
+	{ (flags), \
+	{ 0, 0 }, /* ungot[2] (no wchar) or ungot_width[2] (wchar)*/ \
+	(filedes), \
+	__STDIO_FILE_INIT_BUFFERS(buf,bufsize) \
+	__STDIO_FILE_INIT_BUFGETC((buf)) \
+	__STDIO_FILE_INIT_BUFPUTC((buf)) \
+	__STDIO_FILE_INIT_NEXT(next) \
+	__STDIO_FILE_INIT_CUSTOM_STREAM(stream) \
+	__STDIO_FILE_INIT_WUNGOT \
+	__STDIO_FILE_INIT_MBSTATE \
+	__STDIO_FILE_INIT_UNUSED \
+	__STDIO_FILE_INIT_THREADSAFE \
+} /* TODO: builtin buf */
+
+/**********************************************************************/
+/* First we need the standard files. */
+
+#ifdef __STDIO_BUFFERS
+static unsigned char _fixed_buffers[2 * BUFSIZ];
+#endif
+
+static FILE _stdio_streams[] = {
+	__STDIO_INIT_FILE_STRUCT(_stdio_streams[0], \
+							 __FLAG_LBF|__FLAG_READONLY, \
+							 0, \
+							 _stdio_streams + 1, \
+							 _fixed_buffers, \
+							 BUFSIZ ),
+	__STDIO_INIT_FILE_STRUCT(_stdio_streams[1], \
+							 __FLAG_LBF|__FLAG_WRITEONLY, \
+							 1, \
+							 _stdio_streams + 2, \
+							 _fixed_buffers + BUFSIZ, \
+							 BUFSIZ ),
+	__STDIO_INIT_FILE_STRUCT(_stdio_streams[2], \
+							 __FLAG_NBF|__FLAG_WRITEONLY, \
+							 2, \
+							 NULL, \
+							 NULL, \
+							 0 )
+};
+
+FILE *stdin  = _stdio_streams;
+FILE *stdout = _stdio_streams + 1;
+FILE *stderr = _stdio_streams + 2;
+
+#ifdef __STDIO_GETC_MACRO
+FILE *__stdin = _stdio_streams;		 /* For getchar() macro. */
+#endif
+#ifdef __STDIO_PUTC_MACRO
+FILE *__stdout = _stdio_streams + 1; /* For putchar() macro. */
+/* FILE *__stderr = _stdio_streams + 2; */
+#endif
+
+/**********************************************************************/
+#ifdef __STDIO_HAS_OPENLIST
+
+/* In certain configurations, we need to keep a list of open files.
+ * 1) buffering enabled - We need to initialize the buffering mode
+ *       (full or line buffering) of stdin and stdout.  We also
+ *       need to flush all write buffers prior to normal termination.
+ * 2) custom streams - Even if we aren't buffering in the library
+ *       itself, we need to fclose() all custom streams when terminating
+ *       so that any special cleanup is done.
+ * 3) threads enabled - We need to be able to reset the locking mode
+ *       of all open streams when the threading system is initialized.
+ */
+
+FILE *_stdio_openlist = _stdio_streams;
+
+# ifdef __UCLIBC_HAS_THREADS__
+__UCLIBC_IO_MUTEX_INIT(_stdio_openlist_add_lock);
+#  ifdef __STDIO_BUFFERS
+__UCLIBC_IO_MUTEX_INIT(_stdio_openlist_del_lock);
+volatile int _stdio_openlist_use_count = 0;
+int _stdio_openlist_del_count = 0;
+#  endif
+# endif
+#endif
+/**********************************************************************/
+#ifdef __UCLIBC_HAS_THREADS__
+
+/* 2 if threading not initialized and 0 otherwise; */
+int _stdio_user_locking = 2;
+
+#ifndef __USE_STDIO_FUTEXES__
+void attribute_hidden __stdio_init_mutex(__UCLIBC_MUTEX_TYPE *m)
+{
+	const __UCLIBC_MUTEX_STATIC(__stdio_mutex_initializer,
+		PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP);
+
+	memcpy(m, &__stdio_mutex_initializer, sizeof(__stdio_mutex_initializer));
+}
+#endif
+
+#endif
+/**********************************************************************/
+
+/* We assume here that we are the only remaining thread. */
+void attribute_hidden _stdio_term(void)
+{
+#if defined(__STDIO_BUFFERS) || defined(__UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__)
+	register FILE *ptr;
+
+#ifdef __UCLIBC_HAS_THREADS__
+	/* First, make sure the open file list is unlocked.  If it was
+	 * locked, then I suppose there is a chance that a pointer in the
+	 * chain might be corrupt due to a partial store.
+	 */
+	STDIO_INIT_MUTEX(_stdio_openlist_add_lock);
+#warning check
+#ifdef __STDIO_BUFFERS
+	STDIO_INIT_MUTEX(_stdio_openlist_del_lock);
+#endif
+
+	/* Next we need to worry about the streams themselves.  If a stream
+	 * is currently locked, then it may be in an invalid state.  So we
+	 * 'disable' it in case a custom stream is stacked on top of it.
+	 * Then we reinitialize the locks.
+	 */
+	for (ptr = _stdio_openlist ; ptr ; ptr = ptr->__nextopen ) {
+		if (__STDIO_ALWAYS_THREADTRYLOCK_CANCEL_UNSAFE(ptr)) {
+			/* The stream is already locked, so we don't want to touch it.
+			 * However, if we have custom streams, we can't just close it
+			 * or leave it locked since a custom stream may be stacked
+			 * on top of it.  So we do unlock it, while also disabling it.
+			 */
+			ptr->__modeflags = (__FLAG_READONLY|__FLAG_WRITEONLY);
+			__STDIO_STREAM_DISABLE_GETC(ptr);
+			__STDIO_STREAM_DISABLE_PUTC(ptr);
+			__STDIO_STREAM_INIT_BUFREAD_BUFPOS(ptr);
+		}
+
+		ptr->__user_locking = 1; /* Set locking mode to "by caller". */
+		STDIO_INIT_MUTEX(ptr->__lock); /* Shouldn't be necessary, but... */
+	}
+#endif
+
+	/* Finally, flush all writing streams and shut down all custom streams.
+	 * NOTE: We assume that any stacking by custom streams is done on top
+	 *       of streams previously allocated, and hence further down the
+	 *       list.  Otherwise we have no way of knowing the order in which
+	 *       to shut them down.
+	 *       Remember that freopen() counts as a new allocation here, even
+	 *       though the stream is reused.  That's because it moves the
+	 *       stream to the head of the list.
+	 */
+	for (ptr = _stdio_openlist ; ptr ; ptr = ptr->__nextopen ) {
+#ifdef __STDIO_BUFFERS
+		/* Write any pending buffered chars. */
+		if (__STDIO_STREAM_IS_WRITING(ptr)) {
+			__STDIO_COMMIT_WRITE_BUFFER(ptr);
+		}
+#endif
+#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
+		/* Actually close all custom streams to perform any special cleanup. */
+		if (ptr->__cookie != &ptr->__filedes) {
+			__CLOSE(ptr);
+		}
+#endif
+	}
+
+#endif
+}
+
+#if defined __STDIO_BUFFERS || !defined __UCLIBC__
+void attribute_hidden _stdio_init(void)
+{
+#ifdef __STDIO_BUFFERS
+	int old_errno = errno;
+	/* stdin and stdout uses line buffering when connected to a tty. */
+	if (!isatty(0))
+		_stdio_streams[0].__modeflags ^= __FLAG_LBF;
+	if (!isatty(1))
+		_stdio_streams[1].__modeflags ^= __FLAG_LBF;
+	__set_errno(old_errno);
+#endif
+#ifndef __UCLIBC__
+	/* _stdio_term is done automatically when exiting if stdio is used.
+	 * See misc/internals/__uClibc_main.c and and stdlib/atexit.c. */
+	atexit(_stdio_term);
+#endif
+}
+#endif
+
+/**********************************************************************/
+
+#if !(__MASK_READING & __FLAG_UNGOT)
+#error Assumption violated about __MASK_READING and __FLAG_UNGOT
+#endif
+
+#ifdef __UCLIBC_HAS_THREADS__
+#include <pthread.h>
+#endif
+
+#ifndef NDEBUG
+
+void attribute_hidden _stdio_validate_FILE(const FILE *stream)
+{
+#ifdef __UCLIBC_HAS_THREADS__
+	assert(((unsigned int)(stream->__user_locking)) <= 2);
+#endif
+
+#warning Define a constant for minimum possible valid __filedes?
+	assert(stream->__filedes >= -3);
+
+	if (stream->__filedes < 0) {
+/* 		assert((stream->__filedes != -1) */
+/* #ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ */
+/* 			   || (stream->__cookie == &stream->__filedes) /\* custom *\/ */
+/* #endif */
+/* 			   ); */
+/* 		assert((stream->__filedes == -1) || __STDIO_STREAM_IS_FBF(stream)); */
+
+		assert(!__STDIO_STREAM_IS_FAKE_VSNPRINTF(stream)
+			   || __STDIO_STREAM_IS_NARROW(stream));
+		assert(!__STDIO_STREAM_IS_FAKE_VSSCANF(stream)
+			   || __STDIO_STREAM_IS_NARROW(stream));
+#ifdef __STDIO_STREAM_IS_FAKE_VSWPRINTF
+		assert(!__STDIO_STREAM_IS_FAKE_VSWPRINTF(stream)
+			   || __STDIO_STREAM_IS_WIDE(stream));
+#endif
+#ifdef __STDIO_STREAM_IS_FAKE_VSWSCANF
+		assert(!__STDIO_STREAM_IS_FAKE_VSWSCANF(stream)
+			   || __STDIO_STREAM_IS_WIDE(stream));
+#endif
+	}
+
+#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
+	if (stream->__cookie != &stream->__filedes) { /* custom */
+		assert(stream->__filedes == -1);
+	}
+#endif
+
+	/* Can not be both narrow and wide oriented at the same time. */
+	assert(!(__STDIO_STREAM_IS_NARROW(stream)
+			 && __STDIO_STREAM_IS_WIDE(stream)));
+
+
+	/* The following impossible case is used to disable a stream. */
+	if ((stream->__modeflags & (__FLAG_READONLY|__FLAG_WRITEONLY))
+		== (__FLAG_READONLY|__FLAG_WRITEONLY)
+		) {
+		assert(stream->__modeflags == (__FLAG_READONLY|__FLAG_WRITEONLY));
+		assert(stream->__filedes == -1);
+#ifdef __STDIO_BUFFERS
+		assert(stream->__bufpos == stream->__bufstart);
+		assert(stream->__bufread == stream->__bufstart);
+# ifdef __UCLIBC_HAS_STDIO_PUTC_MACRO__
+		assert(stream->__bufputc_u == stream->__bufstart);
+# endif
+# ifdef __UCLIBC_HAS_STDIO_GETC_MACRO__
+		assert(stream->__bufgetc_u == stream->__bufstart);
+# endif
+#endif
+	}
+
+	if (__STDIO_STREAM_IS_READONLY(stream)) {
+/* 		assert(!__STDIO_STREAM_IS_WRITEONLY(stream)); */
+		assert(!__STDIO_STREAM_IS_WRITING(stream));
+		if (stream->__modeflags & __FLAG_UNGOT) {
+			assert(((unsigned)(stream->__ungot[1])) <= 1);
+			assert(!__FEOF_UNLOCKED(stream));
+		}
+	}
+
+	if (__STDIO_STREAM_IS_WRITEONLY(stream)) {
+/* 		assert(!__STDIO_STREAM_IS_READONLY(stream)); */
+		assert(!__STDIO_STREAM_IS_READING(stream));
+		assert(!(stream->__modeflags & __FLAG_UNGOT));
+	}
+
+	if (__STDIO_STREAM_IS_NBF(stream)) {
+		/* We require that all non buffered streams have no buffer. */
+		assert(!__STDIO_STREAM_BUFFER_SIZE(stream));
+	}
+
+	assert((stream->__modeflags & __MASK_BUFMODE) <= __FLAG_NBF);
+
+#ifdef __STDIO_BUFFERS
+	/* Ensure __bufstart <= __bufpos <= __bufend. */
+	assert(stream->__bufpos >= stream->__bufstart);
+	assert(stream->__bufpos <= stream->__bufend);
+	/* Ensure __bufstart <= __bufread <= __bufend. */
+	assert(stream->__bufread >= stream->__bufstart);
+	assert(stream->__bufread <= stream->__bufend);
+#endif
+
+	/* If EOF, then we must have no buffered readable or ungots. */
+	if (__FEOF_UNLOCKED(stream)) {
+#ifdef __STDIO_BUFFERS
+		assert(stream->__bufpos == stream->__bufread);
+#endif
+		assert(!(stream->__modeflags & __FLAG_UNGOT));
+	}
+
+
+	if (!__STDIO_STREAM_IS_WRITING(stream)) {
+#ifdef __STDIO_BUFFERS
+		/* If not writing, then putc macro must be disabled. */
+# ifdef __UCLIBC_HAS_STDIO_PUTC_MACRO__
+		assert(stream->__bufputc_u == stream->__bufstart);
+# endif
+#endif
+	}
+
+	if (!__STDIO_STREAM_IS_READING(stream)) {
+		/* If not reading, then can not have ungots. */
+		assert(!(stream->__modeflags & __FLAG_UNGOT));
+#ifdef __STDIO_BUFFERS
+		/* Ensure __bufread == __bufstart. */
+		assert(stream->__bufread == stream->__bufstart);
+		/* If not reading, then getc macro must be disabled. */
+# ifdef __UCLIBC_HAS_STDIO_GETC_MACRO__
+		assert(stream->__bufgetc_u == stream->__bufstart);
+# endif
+#endif
+	}
+
+	if (__STDIO_STREAM_IS_READING(stream)) {
+		assert(!__STDIO_STREAM_IS_WRITING(stream));
+#ifdef __STDIO_BUFFERS
+		/* Ensure __bufpos <= __bufread. */
+		assert(stream->__bufpos <= stream->__bufread);
+
+		/* Ensure __bufgetc_u is valid. */
+# ifdef __UCLIBC_HAS_STDIO_GETC_MACRO__
+		assert(stream->__bufgetc_u >= stream->__bufstart);
+		assert(stream->__bufgetc_u <= stream->__bufread);
+# endif
+
+#endif
+	}
+
+	if (__STDIO_STREAM_IS_WRITING(stream)) {
+		assert(!__STDIO_STREAM_IS_READING(stream));
+#ifdef __STDIO_BUFFERS
+# ifdef __UCLIBC_HAS_STDIO_PUTC_MACRO__
+		assert(stream->__bufputc_u >= stream->__bufstart);
+		assert(stream->__bufputc_u <= stream->__bufend);
+# endif
+#endif
+	}
+
+	/* If have an ungotten char, then getc (and putc) must be disabled. */
+	/* Also, wide streams must have the getc/putc macros disabled. */
+	if ((stream->__modeflags & __FLAG_UNGOT)
+		|| __STDIO_STREAM_IS_WIDE(stream)
+		) {
+#ifdef __STDIO_BUFFERS
+# ifdef __UCLIBC_HAS_STDIO_PUTC_MACRO__
+		assert(stream->__bufputc_u == stream->__bufstart);
+# endif
+# ifdef __UCLIBC_HAS_STDIO_GETC_MACRO__
+		assert(stream->__bufgetc_u == stream->__bufstart);
+# endif
+#endif
+	}
+
+	/* TODO -- filepos?  ungot_width?  filedes?  nextopen? */
+}
+
+#endif
diff --git a/ap/build/uClibc/libc/stdio/_stdio.h b/ap/build/uClibc/libc/stdio/_stdio.h
new file mode 100644
index 0000000..2c0efc9
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/_stdio.h
@@ -0,0 +1,456 @@
+/* Copyright (C) 2004-2005 Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include <features.h>
+#include <assert.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <signal.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <unistd.h>
+#ifdef __UCLIBC_HAS_WCHAR__
+#include <wchar.h>
+#endif
+
+#include <bits/uClibc_mutex.h>
+
+#define __STDIO_THREADLOCK_OPENLIST_ADD			\
+        __UCLIBC_IO_MUTEX_LOCK(_stdio_openlist_add_lock)
+
+#define __STDIO_THREADUNLOCK_OPENLIST_ADD		\
+        __UCLIBC_IO_MUTEX_UNLOCK(_stdio_openlist_add_lock)
+
+#ifdef __STDIO_BUFFERS
+
+#define __STDIO_THREADLOCK_OPENLIST_DEL			\
+        __UCLIBC_IO_MUTEX_LOCK(_stdio_openlist_del_lock)
+
+#define __STDIO_THREADUNLOCK_OPENLIST_DEL		\
+        __UCLIBC_IO_MUTEX_UNLOCK(_stdio_openlist_del_lock)
+
+
+#ifdef __UCLIBC_HAS_THREADS__
+#define __STDIO_OPENLIST_INC_USE			\
+do {							\
+	__STDIO_THREADLOCK_OPENLIST_DEL;		\
+	++_stdio_openlist_use_count;			\
+	__STDIO_THREADUNLOCK_OPENLIST_DEL;		\
+} while (0)
+
+extern void _stdio_openlist_dec_use(void) attribute_hidden;
+
+#define __STDIO_OPENLIST_DEC_USE			\
+	_stdio_openlist_dec_use()
+
+#define __STDIO_OPENLIST_INC_DEL_CNT			\
+do {							\
+	__STDIO_THREADLOCK_OPENLIST_DEL;		\
+	++_stdio_openlist_del_count;			\
+	__STDIO_THREADUNLOCK_OPENLIST_DEL;		\
+} while (0)
+
+#define __STDIO_OPENLIST_DEC_DEL_CNT			\
+do { \
+	__STDIO_THREADLOCK_OPENLIST_DEL;		\
+	--_stdio_openlist_del_count;			\
+	__STDIO_THREADUNLOCK_OPENLIST_DEL;		\
+} while (0)
+
+#endif /* __UCLIBC_HAS_THREADS__ */
+#endif /* __STDIO_BUFFERS */
+
+#ifndef __STDIO_THREADLOCK_OPENLIST_DEL
+#define	__STDIO_THREADLOCK_OPENLIST_DEL     ((void)0)
+#endif
+#ifndef __STDIO_THREADUNLOCK_OPENLIST_DEL
+#define	__STDIO_THREADUNLOCK_OPENLIST_DEL   ((void)0)
+#endif
+#ifndef __STDIO_OPENLIST_INC_USE
+#define __STDIO_OPENLIST_INC_USE            ((void)0)
+#endif
+#ifndef __STDIO_OPENLIST_DEC_USE
+#define __STDIO_OPENLIST_DEC_USE            ((void)0)
+#endif
+#ifndef __STDIO_OPENLIST_INC_DEL_CNT
+#define __STDIO_OPENLIST_INC_DEL_CNT        ((void)0)
+#endif
+#ifndef __STDIO_OPENLIST_DEC_DEL_CNT
+#define __STDIO_OPENLIST_DEC_DEL_CNT        ((void)0)
+#endif
+
+#define __UNDEFINED_OR_NONPORTABLE ((void)0)
+
+/**********************************************************************/
+#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
+
+extern __ssize_t _cs_read(void *cookie, char *buf, size_t bufsize) attribute_hidden;
+extern __ssize_t _cs_write(void *cookie, const char *buf, size_t bufsize) attribute_hidden;
+extern int _cs_seek(void *cookie, __offmax_t *pos, int whence) attribute_hidden;
+extern int _cs_close(void *cookie) attribute_hidden;
+
+#define __STDIO_STREAM_RESET_GCS(S) \
+	(S)->__cookie = &((S)->__filedes); \
+	(S)->__gcs.read = _cs_read; \
+	(S)->__gcs.write = _cs_write; \
+	(S)->__gcs.seek = _cs_seek; \
+	(S)->__gcs.close = _cs_close
+
+
+#define __READ(STREAMPTR,BUF,SIZE) \
+	((((STREAMPTR)->__gcs.read) == NULL) ? -1 : \
+	(((STREAMPTR)->__gcs.read)((STREAMPTR)->__cookie,(BUF),(SIZE))))
+#define __WRITE(STREAMPTR,BUF,SIZE) \
+	((((STREAMPTR)->__gcs.write) == NULL) ? -1 : \
+	(((STREAMPTR)->__gcs.write)((STREAMPTR)->__cookie,(BUF),(SIZE))))
+#define __SEEK(STREAMPTR,PPOS,WHENCE) \
+	((((STREAMPTR)->__gcs.seek) == NULL) ? -1 : \
+	(((STREAMPTR)->__gcs.seek)((STREAMPTR)->__cookie,(PPOS),(WHENCE))))
+#define __CLOSE(STREAMPTR) \
+	((((STREAMPTR)->__gcs.close) == NULL) ? 0 : \
+	(((STREAMPTR)->__gcs.close)((STREAMPTR)->__cookie)))
+
+#else  /* __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ */
+
+extern int __stdio_seek(FILE *stream, register __offmax_t *pos, int whence) attribute_hidden;
+
+#define __STDIO_STREAM_RESET_GCS(S) ((void)0)
+
+#define __READ(STREAMPTR,BUF,SIZE) \
+	(read((STREAMPTR)->__filedes,(BUF),(SIZE)))
+#define __WRITE(STREAMPTR,BUF,SIZE) \
+	(write((STREAMPTR)->__filedes,(BUF),(SIZE)))
+#define __SEEK(STREAMPTR,PPOS,WHENCE) \
+	(__stdio_seek((STREAMPTR),(PPOS),(WHENCE)))
+#define __CLOSE(STREAMPTR) \
+	(close((STREAMPTR)->__filedes))
+
+#endif /* __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ */
+
+/**********************************************************************/
+#ifdef __UCLIBC_HAS_WCHAR__
+
+#define __STDIO_STREAM_TRANS_TO_WRITE(S,O)	__stdio_trans2w_o((S), (O))
+#define __STDIO_STREAM_TRANS_TO_READ(S,O)	__stdio_trans2r_o((S), (O))
+
+#else
+
+#define __STDIO_STREAM_TRANS_TO_WRITE(S,O)	__stdio_trans2w((S))
+#define __STDIO_STREAM_TRANS_TO_READ(S,O)	__stdio_trans2r((S))
+
+#endif
+/**********************************************************************/
+
+#define __STDIO_STREAM_IS_READING(S) ((S)->__modeflags & __MASK_READING)
+#define __STDIO_STREAM_IS_WRITING(S) ((S)->__modeflags & __FLAG_WRITING)
+
+#define __STDIO_STREAM_SET_READING(S) ((S)->__modeflags |= __FLAG_READING)
+#define __STDIO_STREAM_SET_WRITING(S) ((S)->__modeflags |= __FLAG_WRITING)
+
+#define __STDIO_STREAM_IS_READING_OR_READONLY(S) \
+	((S)->__modeflags & (__MASK_READING|__FLAG_READONLY))
+
+#define __STDIO_STREAM_IS_WRITING_OR_WRITEONLY(S) \
+	((S)->__modeflags & (__FLAG_WRITING|__FLAG_WRITEONLY))
+
+#define __STDIO_STREAM_IS_READONLY(S) ((S)->__modeflags & __FLAG_READONLY)
+#define __STDIO_STREAM_IS_WRITEONLY(S) ((S)->__modeflags & __FLAG_WRITEONLY)
+
+
+/**********************************************************************/
+#ifdef __UCLIBC_HAS_WCHAR__
+
+#define __STDIO_STREAM_IS_NARROW_WRITING(S)			\
+	(((S)->__modeflags & (__FLAG_WRITING|__FLAG_NARROW))	\
+	 == (__FLAG_WRITING|__FLAG_NARROW))
+
+#define __STDIO_STREAM_IS_WIDE_WRITING(S)			\
+	(((S)->__modeflags & (__FLAG_WRITING|__FLAG_WIDE))	\
+	 == (__FLAG_WRITING|__FLAG_WIDE))
+
+#if (__FLAG_NARROW <= __MASK_READING)
+#error assumption violated regarding __FLAG_NARROW
+#endif
+
+#define __STDIO_STREAM_IS_NARROW_READING(S)			\
+	(((S)->__modeflags & (__MASK_READING|__FLAG_NARROW)) > __FLAG_NARROW)
+
+#define __STDIO_STREAM_IS_WIDE_READING(S)			\
+	(((S)->__modeflags & (__MASK_READING|__FLAG_WIDE)) > __FLAG_WIDE)
+
+#define __STDIO_STREAM_IS_NARROW(S)		((S)->__modeflags & __FLAG_NARROW)
+#define __STDIO_STREAM_IS_WIDE(S)		((S)->__modeflags & __FLAG_WIDE)
+
+#define __STDIO_STREAM_SET_NARROW(S)				\
+	((void)((S)->__modeflags |= __FLAG_NARROW))
+#define __STDIO_STREAM_SET_WIDE(S)				\
+	((void)((S)->__modeflags |= __FLAG_WIDE))
+
+#else
+
+#define __STDIO_STREAM_IS_NARROW_WRITING(S)  __STDIO_STREAM_IS_WRITING(S)
+
+#define __STDIO_STREAM_IS_NARROW_READING(S)  __STDIO_STREAM_IS_READING(S)
+
+#define __STDIO_STREAM_IS_NARROW(S)			(1)
+#define __STDIO_STREAM_IS_WIDE(S)			(0)
+
+#define __STDIO_STREAM_SET_NARROW(S)			((void)0)
+#define __STDIO_STREAM_SET_WIDE(S)			((void)0)
+
+#endif
+/**********************************************************************/
+
+#define __STDIO_STREAM_SET_EOF(S) \
+	((void)((S)->__modeflags |= __FLAG_EOF))
+#define __STDIO_STREAM_SET_ERROR(S) \
+	((void)((S)->__modeflags |= __FLAG_ERROR))
+
+#define __STDIO_STREAM_CLEAR_EOF(S) \
+	((void)((S)->__modeflags &= ~__FLAG_EOF))
+#define __STDIO_STREAM_CLEAR_ERROR(S) \
+	((void)((S)->__modeflags &= ~__FLAG_ERROR))
+
+#define __STDIO_STREAM_CLEAR_READING_AND_UNGOTS(S) \
+	((void)((S)->__modeflags &= ~__MASK_READING))
+#define __STDIO_STREAM_CLEAR_WRITING(S) \
+	((void)((S)->__modeflags &= ~__FLAG_WRITING))
+
+#ifdef __UCLIBC_HAS_STDIO_GETC_MACRO__
+# define __STDIO_STREAM_DISABLE_GETC(S) \
+	((void)((S)->__bufgetc_u = (S)->__bufstart))
+# define __STDIO_STREAM_ENABLE_GETC(S) \
+	((void)((S)->__bufgetc_u = (S)->__bufread))
+# define __STDIO_STREAM_CAN_USE_BUFFER_GET(S) \
+	((S)->__bufpos < (S)->__bufgetc_u)
+#else
+# define __STDIO_STREAM_DISABLE_GETC(S)			((void)0)
+# define __STDIO_STREAM_ENABLE_GETC(S)			((void)0)
+# define __STDIO_STREAM_CAN_USE_BUFFER_GET(S)		(0)
+#endif
+
+#ifdef __UCLIBC_HAS_STDIO_PUTC_MACRO__
+# define __STDIO_STREAM_DISABLE_PUTC(S) \
+	((void)((S)->__bufputc_u = (S)->__bufstart))
+# define __STDIO_STREAM_ENABLE_PUTC(S) \
+	((void)((S)->__bufputc_u = (S)->__bufend))
+# define __STDIO_STREAM_CAN_USE_BUFFER_ADD(S) \
+	((S)->__bufpos < (S)->__bufputc_u)
+#else
+# define __STDIO_STREAM_DISABLE_PUTC(S)			((void)0)
+# define __STDIO_STREAM_ENABLE_PUTC(S)			((void)0)
+# define __STDIO_STREAM_CAN_USE_BUFFER_ADD(S)		(0)
+#endif
+
+#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
+#define __STDIO_STREAM_IS_CUSTOM(S)		((S)->__cookie != &((S)->__filedes))
+#else
+#define __STDIO_STREAM_IS_CUSTOM(S)			(0)
+#endif
+
+/**********************************************************************/
+
+#ifdef __STDIO_BUFFERS
+#define __STDIO_STREAM_FREE_BUFFER(S)			\
+	do { if ((S)->__modeflags & __FLAG_FREEBUF)	\
+	free((S)->__bufstart); } while (0)
+#else
+#define __STDIO_STREAM_FREE_BUFFER(S) ((void)0)
+#endif
+
+#define __STDIO_STREAM_FREE_FILE(S) \
+	do { if ((S)->__modeflags & __FLAG_FREEFILE)	\
+	free((S)); } while (0)
+
+
+#ifdef __UCLIBC_HAS_LFS__
+#define __STDIO_WHEN_LFS(E) E
+#else
+#define __STDIO_WHEN_LFS(E) ((void)0)
+#endif
+
+/**********************************************************************/
+/* The following return 0 on success. */
+
+#ifdef __STDIO_BUFFERS
+/* Assume stream in valid writing state.  Do not reset writing flag
+ * or disble putc macro unless error. */
+/* Should we assume that buffer is not empty to avoid a check? */
+extern size_t __stdio_wcommit(FILE *__restrict stream) attribute_hidden;
+
+/* Remember to fail if at EOF! */
+extern size_t __stdio_rfill(FILE *__restrict stream) attribute_hidden;
+
+extern size_t __stdio_fwrite(const unsigned char *__restrict buffer,
+		size_t bytes, FILE *__restrict stream) attribute_hidden;
+#else
+
+#define __stdio_fwrite(B,N,S)  __stdio_WRITE((S),(B),(N))
+
+#endif
+
+extern size_t __stdio_WRITE(FILE *stream, const unsigned char *buf,
+		size_t bufsize) attribute_hidden;
+extern size_t __stdio_READ(FILE *stream, unsigned char *buf,
+		size_t bufsize) attribute_hidden;
+
+extern int __stdio_trans2r(FILE *__restrict stream) attribute_hidden;
+extern int __stdio_trans2w(FILE *__restrict stream) attribute_hidden;
+
+extern int __stdio_trans2r_o(FILE *__restrict stream, int oflag) attribute_hidden;
+extern int __stdio_trans2w_o(FILE *__restrict stream, int oflag) attribute_hidden;
+
+/**********************************************************************/
+#ifdef __STDIO_BUFFERS
+
+#define __STDIO_STREAM_IS_FBF(S)		(!((S)->__modeflags & __MASK_BUFMODE))
+#define __STDIO_STREAM_IS_LBF(S)		((S)->__modeflags & __FLAG_LBF)
+#define __STDIO_STREAM_IS_NBF(S)		((S)->__modeflags & __FLAG_NBF)
+
+#define __STDIO_STREAM_BUFFER_SIZE(S)		((S)->__bufend - (S)->__bufstart)
+
+/* Valid when writing... */
+#define __STDIO_STREAM_BUFFER_ADD(S,C)		(*(S)->__bufpos++ = (C))
+#define __STDIO_STREAM_BUFFER_UNADD(S)		(--(S)->__bufpos)
+#define __STDIO_STREAM_BUFFER_WAVAIL(S)		((S)->__bufend - (S)->__bufpos)
+#define __STDIO_STREAM_BUFFER_WUSED(S)		((S)->__bufpos - (S)->__bufstart)
+#define __STDIO_COMMIT_WRITE_BUFFER(S)		__stdio_wcommit((S))
+#ifdef __UCLIBC_HAS_WCHAR__
+#define __STDIO_STREAM_IS_NARROW_FBF(S) \
+	(!((S)->__modeflags & (__MASK_BUFMODE|__FLAG_WIDE)))
+#else
+#define __STDIO_STREAM_IS_NARROW_FBF(S)		__STDIO_STREAM_IS_FBF((S))
+#endif
+
+/* Valid when reading... */
+#define __STDIO_STREAM_BUFFER_RAVAIL(S)		((S)->__bufread - (S)->__bufpos)
+#define __STDIO_STREAM_BUFFER_GET(S)		(*(S)->__bufpos++)
+#define __STDIO_FILL_READ_BUFFER(S)		__stdio_rfill((S))
+
+#define __STDIO_STREAM_INIT_BUFREAD_BUFPOS(S)		\
+	(S)->__bufread = (S)->__bufpos = (S)->__bufstart
+
+
+#define __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES		(-2)
+#define __STDIO_STREAM_FAKE_VSSCANF_FILEDES		(-2)
+#define __STDIO_STREAM_FAKE_VSWPRINTF_FILEDES		(-3)
+#define __STDIO_STREAM_FAKE_VSWSCANF_FILEDES		(-3)
+
+#define __STDIO_STREAM_IS_FAKE_VSNPRINTF(S) \
+	((S)->__filedes == __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES)
+#define __STDIO_STREAM_IS_FAKE_VSSCANF(S) \
+	((S)->__filedes == __STDIO_STREAM_FAKE_VSSCANF_FILEDES)
+#define __STDIO_STREAM_IS_FAKE_VSWPRINTF(S) \
+	((S)->__filedes == __STDIO_STREAM_FAKE_VSWPRINTF_FILEDES)
+#define __STDIO_STREAM_IS_FAKE_VSWSCANF(S) \
+	((S)->__filedes == __STDIO_STREAM_FAKE_VSWSCANF_FILEDES)
+
+#else  /* __STDIO_BUFFERS */
+
+#define __STDIO_STREAM_IS_FBF(S)				(0)
+#define __STDIO_STREAM_IS_LBF(S)				(0)
+#define __STDIO_STREAM_IS_NBF(S)				(1)
+
+#define __STDIO_STREAM_BUFFER_SIZE(S)				(0)
+#define __STDIO_STREAM_BUFFER_ADD(S,C)				((void)0)
+#define __STDIO_STREAM_BUFFER_UNADD(S)				((void)0)
+#define __STDIO_STREAM_BUFFER_WAVAIL(S)				(0)
+#define __STDIO_STREAM_BUFFER_WUSED(S)				(0)
+#define __STDIO_COMMIT_WRITE_BUFFER(S)				(0)
+#define __STDIO_STREAM_IS_NARROW_FBF(S)				(0)
+
+#define __STDIO_STREAM_BUFFER_RAVAIL(S)				(0)
+#define __STDIO_STREAM_BUFFER_GET(S)				(EOF)
+#define __STDIO_FILL_READ_BUFFER(S)				(0)
+#define __STDIO_STREAM_INIT_BUFREAD_BUFPOS(S)			((void)0)
+
+#undef __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES
+#undef __STDIO_STREAM_FAKE_VSSCANF_FILEDES
+#undef __STDIO_STREAM_FAKE_VSWPRINTF_FILEDES
+
+#define __STDIO_STREAM_IS_FAKE_VSNPRINTF(S)			(0)
+#define __STDIO_STREAM_IS_FAKE_VSSCANF(S)			(0)
+#undef __STDIO_STREAM_IS_FAKE_VSWPRINTF
+
+# ifdef __USE_OLD_VFPRINTF__
+#  define __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES_NB		(-2)
+#  define __STDIO_STREAM_IS_FAKE_VSNPRINTF_NB(S)		\
+	((S)->__filedes == __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES_NB)
+# endif
+
+# ifndef __UCLIBC_HAS_WCHAR__
+#  define __STDIO_STREAM_FAKE_VSSCANF_FILEDES_NB		(-2)
+#  define __STDIO_STREAM_IS_FAKE_VSSCANF_NB(S)			\
+	((S)->__filedes == __STDIO_STREAM_FAKE_VSSCANF_FILEDES_NB)
+# endif
+
+#endif /* __STDIO_BUFFERS */
+/**********************************************************************/
+
+extern int __stdio_adjust_position(FILE *__restrict stream, __offmax_t *pos) attribute_hidden;
+
+#ifdef __STDIO_HAS_OPENLIST
+	/* Uses an implementation hack!!! */
+#define __STDIO_FLUSH_LBF_STREAMS		\
+	fflush_unlocked((FILE *) &_stdio_openlist)
+#else
+#define __STDIO_FLUSH_LBF_STREAMS		((void)0)
+#endif
+
+#ifdef NDEBUG
+#define __STDIO_STREAM_VALIDATE(S)		((void)0)
+#else
+extern void _stdio_validate_FILE(const FILE *stream) attribute_hidden;
+#define __STDIO_STREAM_VALIDATE(S)		_stdio_validate_FILE((S))
+#endif
+
+#ifdef __STDIO_MBSTATE
+#define __COPY_MBSTATE(dest,src) \
+	((void)((dest)->__mask = (src)->__mask, (dest)->__wc = (src)->__wc))
+#define __INIT_MBSTATE(dest)			((void)((dest)->__mask = 0))
+#else
+#define __COPY_MBSTATE(dest,src)		((void)0)
+#define __INIT_MBSTATE(dest)			((void)0)
+#endif
+
+/**********************************************************************/
+
+extern FILE *_stdio_fopen(intptr_t fname_or_mode, const char *__restrict mode,
+		FILE *__restrict stream, int filedes) attribute_hidden;
+
+#ifdef __UCLIBC_HAS_WCHAR__
+extern size_t _wstdio_fwrite(const wchar_t *__restrict ws,
+		size_t n, FILE *__restrict stream) attribute_hidden;
+#endif
+
+/**********************************************************************/
+
+extern int _vfprintf_internal (FILE * __restrict stream,
+			const char * __restrict format,
+			va_list arg) attribute_hidden;
+
+#ifdef __UCLIBC_HAS_WCHAR__
+extern int _vfwprintf_internal (FILE * __restrict stream,
+			const wchar_t * __restrict format,
+			va_list arg) attribute_hidden;
+#endif
+
+/**********************************************************************/
+/* Only use the macro below if you know fp is a valid FILE for a valid fd.
+ * This is _not_ true for custom streams! */
+#define __FILENO_UNLOCKED(fp)	((fp)->__filedes)
+
+#define __FEOF_OR_FERROR_UNLOCKED(stream) \
+	((stream)->__modeflags & (__FLAG_EOF|__FLAG_ERROR))
+
+#if defined(__STDIO_BUFFERS) || defined(__USE_OLD_VFPRINTF__) || defined(__UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__)
+#define __STDIO_HAS_VSNPRINTF 1
+#endif
diff --git a/ap/build/uClibc/libc/stdio/_store_inttype.c b/ap/build/uClibc/libc/stdio/_store_inttype.c
new file mode 100644
index 0000000..fdd4dce
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/_store_inttype.c
@@ -0,0 +1,58 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+#include <printf.h>
+
+/* Right now, we assume intmax_t is either long or long long */
+
+#ifdef INTMAX_MAX
+
+#ifdef LLONG_MAX
+
+#if INTMAX_MAX > LLONG_MAX
+#error INTMAX_MAX > LLONG_MAX!  The printf code needs to be updated!
+#endif
+
+#elif INTMAX_MAX > LONG_MAX
+
+#error No LLONG_MAX and INTMAX_MAX > LONG_MAX!  The printf code needs to be updated!
+
+#endif /* LLONG_MAX */
+
+#endif /* INTMAX_MAX */
+
+/* We assume int may be short or long, but short and long are different. */
+
+void _store_inttype(register void *dest, int desttype, uintmax_t val) attribute_hidden;
+void _store_inttype(register void *dest, int desttype, uintmax_t val)
+{
+	if (desttype == __PA_FLAG_CHAR) { /* assume char not int */
+		*((unsigned char *) dest) = val;
+		return;
+	}
+#if defined(LLONG_MAX) && (INT_MAX != LLONG_MAX)
+	if (desttype == PA_FLAG_LONG_LONG) {
+		*((unsigned long long int *) dest) = val;
+		return;
+	}
+#endif /* LLONG_MAX */
+#if SHRT_MAX != INT_MAX
+	if (desttype == PA_FLAG_SHORT) {
+		*((unsigned short int *) dest) = val;
+		return;
+	}
+#endif /* SHRT_MAX */
+#if LONG_MAX != INT_MAX
+	if (desttype == PA_FLAG_LONG) {
+		*((unsigned long int *) dest) = val;
+		return;
+	}
+#endif /* LONG_MAX */
+
+	*((unsigned int *) dest) = val;
+}
diff --git a/ap/build/uClibc/libc/stdio/_trans2r.c b/ap/build/uClibc/libc/stdio/_trans2r.c
new file mode 100644
index 0000000..1f39300
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/_trans2r.c
@@ -0,0 +1,79 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+/* Function to handle transition to reading.
+ *   Initialize or verify the stream's orientation (even if writeonly).
+ *   Check that the stream is readable.
+ *   If currently reading, check that we can transition to writing.
+ *      C99 requires that we not be reading, but attempting to
+ *      auto-transition by commiting the write buffer is a configurable
+ *      option.
+ *   Returns 0 on success and EOF otherwise.
+ *
+ * Notes:
+ *   There are two function signatures, depending on wchar support,
+ *   since with no wchar support the orientation is narrow by default.
+ */
+
+#ifdef __UCLIBC_HAS_WCHAR__
+int attribute_hidden __stdio_trans2r_o(FILE * __restrict stream, int oflag)
+#else
+int attribute_hidden __stdio_trans2r(FILE * __restrict stream)
+#endif
+{
+	__STDIO_STREAM_VALIDATE(stream);
+	assert(!__STDIO_STREAM_IS_READING(stream));
+
+#ifdef __UCLIBC_HAS_WCHAR__
+	if (!(stream->__modeflags & oflag)) {
+		if (stream->__modeflags & (__FLAG_NARROW|__FLAG_WIDE)) {
+			__UNDEFINED_OR_NONPORTABLE;
+			goto DO_EBADF;
+		}
+		stream->__modeflags |= oflag;
+	}
+#endif
+
+	if (stream->__modeflags & __FLAG_WRITEONLY) {
+#if defined(__UCLIBC_HAS_WCHAR__) || !defined(__UCLIBC_HAS_STDIO_AUTO_RW_TRANSITION__)
+	DO_EBADF:
+#endif
+		__set_errno(EBADF);
+#ifdef __UCLIBC_HAS_STDIO_AUTO_RW_TRANSITION__
+	ERROR:
+#endif
+		__STDIO_STREAM_SET_ERROR(stream);
+		__STDIO_STREAM_VALIDATE(stream);
+		return EOF;
+	}
+
+	if (__STDIO_STREAM_IS_WRITING(stream)) {
+#ifdef __UCLIBC_HAS_STDIO_AUTO_RW_TRANSITION__
+		if (__STDIO_COMMIT_WRITE_BUFFER(stream)) { /* commit failed! */
+			goto ERROR;
+		}
+		assert(!__STDIO_STREAM_BUFFER_WUSED(stream));
+
+		__STDIO_STREAM_DISABLE_PUTC(stream);
+		__STDIO_STREAM_CLEAR_WRITING(stream);
+#else
+		/* C99: Output shall not be directly followed by input without an
+		   intervening call to the fflush function or to a file positioning
+		   function (fseek, fsetpos, or rewind). */
+		__UNDEFINED_OR_NONPORTABLE;
+		goto DO_EBADF;
+#endif
+	}
+
+	__STDIO_STREAM_SET_READING(stream);
+	/* getc macro is enabled when data is read into buffer. */
+
+	__STDIO_STREAM_VALIDATE(stream);
+	return 0;
+}
diff --git a/ap/build/uClibc/libc/stdio/_trans2w.c b/ap/build/uClibc/libc/stdio/_trans2w.c
new file mode 100644
index 0000000..c722379
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/_trans2w.c
@@ -0,0 +1,94 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+/* Function to handle transition to writing.
+ *   Initialize or verify the stream's orientation (even if readonly).
+ *   Check that the stream is writable.
+ *   If currently reading, check that we can transition to writing.
+ *      C99 requires that the stream is at EOF, but attempting to
+ *      auto-transition via fseek() is a configurable option.
+ *   Returns 0 on success and EOF otherwise.
+ *
+ * Notes:
+ *   There are two function signatures, depending on wchar support,
+ *   since with no wchar support the orientation is narrow by default.
+ */
+
+#ifdef __UCLIBC_HAS_WCHAR__
+int attribute_hidden __stdio_trans2w_o(FILE * __restrict stream, int oflag)
+#else
+int attribute_hidden __stdio_trans2w(FILE * __restrict stream)
+#endif
+{
+	__STDIO_STREAM_VALIDATE(stream);
+	assert(!__STDIO_STREAM_IS_WRITING(stream));
+
+#ifdef __UCLIBC_HAS_WCHAR__
+	if (!(stream->__modeflags & oflag)) {
+		if (stream->__modeflags & (__FLAG_NARROW|__FLAG_WIDE)) {
+			__UNDEFINED_OR_NONPORTABLE;
+			goto DO_EBADF;
+		}
+		stream->__modeflags |= oflag;
+	}
+#endif
+
+	if (stream->__modeflags & __FLAG_READONLY) {
+#if defined(__UCLIBC_HAS_WCHAR__) || !defined(__UCLIBC_HAS_STDIO_AUTO_RW_TRANSITION__)
+	DO_EBADF:
+#endif
+		__set_errno(EBADF);
+#ifdef __UCLIBC_HAS_STDIO_AUTO_RW_TRANSITION__
+	ERROR:
+#endif
+		__STDIO_STREAM_SET_ERROR(stream);
+		__STDIO_STREAM_VALIDATE(stream);
+		return EOF;
+	}
+
+	if (__STDIO_STREAM_IS_READING(stream)) {
+		if (!__FEOF_UNLOCKED(stream)) {
+#ifdef __UCLIBC_HAS_STDIO_AUTO_RW_TRANSITION__
+			/* Need to seek to correct position if we have buffered
+			 * read data or ungots.  If appending, we might as well
+			 * seek to the end.
+			 *
+			 * NOTE: If the OS does not handle append files correctly,
+			 *   this is insufficient since we would need to seek to
+			 *   the end even if not reading.*/
+			if (((__STDIO_STREAM_BUFFER_RAVAIL(stream))
+				 || (stream->__modeflags & __FLAG_UNGOT))
+				&& fseek(stream, 0L,
+						 ((stream->__modeflags & __FLAG_APPEND)
+						  ? SEEK_END : SEEK_CUR))
+				) {
+				/* fseek() only sets error indicator on read/write error. */
+				goto ERROR;
+			}
+#else
+			/* C99 requires either at EOF or currently not reading. */
+			__UNDEFINED_OR_NONPORTABLE;
+			goto DO_EBADF;
+#endif
+		}
+		__STDIO_STREAM_CLEAR_READING_AND_UNGOTS(stream);
+		__STDIO_STREAM_DISABLE_GETC(stream);
+		/* Reaching EOF does not reset buffer pointers... */
+		__STDIO_STREAM_INIT_BUFREAD_BUFPOS(stream);
+	}
+
+	__STDIO_STREAM_SET_WRITING(stream);
+	if (__STDIO_STREAM_IS_NARROW_FBF(stream)) {
+		__STDIO_STREAM_ENABLE_PUTC(stream);
+	}
+
+	__STDIO_STREAM_VALIDATE(stream);
+	return 0;
+}
diff --git a/ap/build/uClibc/libc/stdio/_uintmaxtostr.c b/ap/build/uClibc/libc/stdio/_uintmaxtostr.c
new file mode 100644
index 0000000..e501165
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/_uintmaxtostr.c
@@ -0,0 +1,152 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#define _ISOC99_SOURCE			/* for ULLONG primarily... */
+#include "_stdio.h"
+#include <limits.h>
+#include <locale.h>
+#include <bits/uClibc_uintmaxtostr.h>
+
+
+/* Avoid using long long / and % operations to cut down dependencies on
+ * libgcc.a.  Definitely helps on i386 at least. */
+#if (INTMAX_MAX > INT_MAX) && (((INTMAX_MAX/INT_MAX)/2) - 2 <= INT_MAX)
+#define INTERNAL_DIV_MOD
+#endif
+
+char attribute_hidden *_uintmaxtostr(register char * __restrict bufend, uintmax_t uval,
+					int base, __UIM_CASE alphacase)
+{
+	int negative;
+	unsigned int digit;
+#ifdef INTERNAL_DIV_MOD
+	unsigned int H, L, high, low, rh;
+#endif
+#ifndef __LOCALE_C_ONLY
+	int grouping, outdigit;
+	const char *g;		   /* This does not need to be initialized. */
+#endif /* __LOCALE_C_ONLY */
+
+	negative = 0;
+	if (base < 0) {				/* signed value */
+		base = -base;
+		if (uval > INTMAX_MAX) {
+			uval = -uval;
+			negative = 1;
+		}
+	}
+
+	/* this is an internal routine -- we shouldn't need to check this */
+	assert(!((base < 2) || (base > 36)));
+
+#ifndef __LOCALE_C_ONLY
+	grouping = -1;
+	outdigit = 0x80 & alphacase;
+	alphacase ^= outdigit;
+	if (alphacase == __UIM_GROUP) {
+		assert(base == 10);
+		if (*(g = __UCLIBC_CURLOCALE->grouping)) {
+			grouping = *g;
+		}
+	}
+#endif /* __LOCALE_C_ONLY */
+
+	*bufend = '\0';
+
+#ifndef INTERNAL_DIV_MOD
+	do {
+#ifndef __LOCALE_C_ONLY
+		if (!grouping) {		/* Finished a group. */
+			bufend -= __UCLIBC_CURLOCALE->thousands_sep_len;
+			memcpy(bufend, __UCLIBC_CURLOCALE->thousands_sep,
+				   __UCLIBC_CURLOCALE->thousands_sep_len);
+			if (g[1] != 0) { 	/* g[1] == 0 means repeat last grouping. */
+				/* Note: g[1] == -1 means no further grouping.  But since
+				 * we'll never wrap around, we can set grouping to -1 without
+				 * fear of */
+				++g;
+			}
+			grouping = *g;
+		}
+		--grouping;
+#endif /* __LOCALE_C_ONLY */
+		digit = uval % base;
+		uval /= base;
+
+#ifndef __LOCALE_C_ONLY
+		if (unlikely(outdigit)) {
+			bufend -= __UCLIBC_CURLOCALE->outdigit_length[digit];
+			memcpy(bufend,
+				   (&__UCLIBC_CURLOCALE->outdigit0_mb)[digit],
+				   __UCLIBC_CURLOCALE->outdigit_length[digit]);
+		} else
+#endif
+		{
+			*--bufend = ( (digit < 10) ? digit + '0' : digit + alphacase );
+		}
+	} while (uval);
+
+#else  /* ************************************************** */
+
+	H = (UINT_MAX / base);
+	L = UINT_MAX % base + 1;
+	if (L == base) {
+		++H;
+		L = 0;
+	}
+	low = (unsigned int) uval;
+	high = (unsigned int) (uval >> (sizeof(unsigned int) * CHAR_BIT));
+
+	do {
+#ifndef __LOCALE_C_ONLY
+		if (!grouping) {		/* Finished a group. */
+			bufend -= __UCLIBC_CURLOCALE->thousands_sep_len;
+			memcpy(bufend, __UCLIBC_CURLOCALE->thousands_sep,
+				   __UCLIBC_CURLOCALE->thousands_sep_len);
+			if (g[1] != 0) { 	/* g[1] == 0 means repeat last grouping. */
+				/* Note: g[1] == -1 means no further grouping.  But since
+				 * we'll never wrap around, we can set grouping to -1 without
+				 * fear of */
+				++g;
+			}
+			grouping = *g;
+		}
+		--grouping;
+#endif /* __LOCALE_C_ONLY */
+
+		if (unlikely(high)) {
+			rh = high % base;
+			high /= base;
+			digit = (low % base) + (L * rh);
+			low = (low / base) + (H * rh) + (digit / base);
+			digit %= base;
+		} else {
+			digit = low % base;
+			low /= base;
+		}
+
+#ifndef __LOCALE_C_ONLY
+		if (unlikely(outdigit)) {
+			bufend -= __UCLIBC_CURLOCALE->outdigit_length[digit];
+			memcpy(bufend,
+				   (&__UCLIBC_CURLOCALE->outdigit0_mb)[digit],
+				   __UCLIBC_CURLOCALE->outdigit_length[digit]);
+		} else
+#endif
+		{
+			*--bufend = ( (digit < 10) ? digit + '0' : digit + alphacase );
+		}
+	} while (low | high);
+
+#endif /******************************************************/
+
+	if (negative) {
+		*--bufend = '-';
+	}
+
+	return bufend;
+}
diff --git a/ap/build/uClibc/libc/stdio/_vfprintf.c b/ap/build/uClibc/libc/stdio/_vfprintf.c
new file mode 100755
index 0000000..3db8cdf
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/_vfprintf.c
@@ -0,0 +1,1979 @@
+/*  Copyright (C) 2002-2004     Manuel Novoa III
+ *  My stdio library for linux and (soon) elks.
+ *
+ *  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.
+ *
+ *  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.
+ */
+
+/* This code needs a lot of clean up.  Some of that is on hold until uClibc
+ * gets a better configuration system (on Erik's todo list).
+ * The other cleanup will take place during the implementation/integration of
+ * the wide char (un)formatted i/o functions which I'm currently working on.
+ */
+
+/*  ATTENTION!   ATTENTION!   ATTENTION!   ATTENTION!   ATTENTION!
+ *
+ *  This code is currently under development.  Also, I plan to port
+ *  it to elks which is a 16-bit environment with a fairly limited
+ *  compiler.  Therefore, please refrain from modifying this code
+ *  and, instead, pass any bug-fixes, etc. to me.  Thanks.  Manuel
+ *
+ *  ATTENTION!   ATTENTION!   ATTENTION!   ATTENTION!   ATTENTION! */
+
+
+/* April 1, 2002
+ * Initialize thread locks for fake files in vsnprintf and vdprintf.
+ *    reported by Erik Andersen (andersen@codepoet.com)
+ * Fix an arg promotion handling bug in _do_one_spec for %c.
+ *    reported by Ilguiz Latypov <ilatypov@superbt.com>
+ *
+ * May 10, 2002
+ * Remove __isdigit and use new ctype.h version.
+ * Add conditional setting of QUAL_CHARS for size_t and ptrdiff_t.
+ *
+ * Aug 16, 2002
+ * Fix two problems that showed up with the python 2.2.1 tests; one
+ *    involving %o and one involving %f.
+ *
+ * Oct 28, 2002
+ * Fix a problem in vasprintf (reported by vodz a while back) when built
+ *    without custom stream support.  In that case, it is necessary to do
+ *    a va_copy.
+ * Make sure each va_copy has a matching va_end, as required by C99.
+ *
+ * Nov 4, 2002
+ * Add locale-specific grouping support for integer decimal conversion.
+ * Add locale-specific decimal point support for floating point conversion.
+ *   Note: grouping will have to wait for _dtostr() rewrite.
+ * Add printf wchar support for %lc (%C) and %ls (%S).
+ * Require printf format strings to be valid multibyte strings beginning and
+ *   ending in their initial shift state, as per the stds.
+ *
+ * Nov 21, 2002
+ * Add *wprintf functions.  Currently they don't support floating point
+ *   conversions.  That will wait until the rewrite of _dtostr.
+ *
+ * Aug 1, 2003
+ * Optional hexadecimal float notation support for %a/%A.
+ * Floating point output now works for *wprintf.
+ * Support for glibc locale-specific digit grouping for floats.
+ * Misc bug fixes.
+ *
+ * Aug 31, 2003
+ * Fix precision bug for %g conversion specifier when using %f style.
+ *
+ * Sep 5, 2003
+ * Implement *s*scanf for the non-buffered stdio case with old_vfprintf.
+ *
+ * Sep 23, 2003
+ * vfprintf was not always checking for narrow stream orientation.
+ */
+
+/* TODO:
+ *
+ * Should we validate that *printf format strings are valid multibyte
+ *   strings in the current locale?  ANSI/ISO C99 seems to imply this
+ *   and Plauger's printf implementation in his Standard C Library book
+ *   treats this as an error.
+ */
+
+#define _ISOC99_SOURCE			/* for ULLONG primarily... */
+#include <features.h>
+#include "_stdio.h"
+#include <stdlib.h>
+#include <string.h>
+#include <stddef.h>
+#include <ctype.h>
+#include <limits.h>
+#include <stdarg.h>
+#include <assert.h>
+#include <stdint.h>
+#include <errno.h>
+#include <locale.h>
+#include <printf.h>
+
+#ifdef __UCLIBC_HAS_THREADS__
+# include <stdio_ext.h>
+# include <pthread.h>
+#endif
+
+#ifdef __UCLIBC_HAS_WCHAR__
+# include <wchar.h>
+#endif
+
+#include <bits/uClibc_uintmaxtostr.h>
+#include <bits/uClibc_va_copy.h>
+
+/* Some older or broken gcc toolchains define LONG_LONG_MAX but not
+ * LLONG_MAX.  Since LLONG_MAX is part of the standard, that's what
+ * we use.  So complain if we do not have it but should.
+ */
+#if !defined(LLONG_MAX) && defined(LONG_LONG_MAX)
+#error Apparently, LONG_LONG_MAX is defined but LLONG_MAX is not.  You need to fix your toolchain headers to support the standard macros for (unsigned) long long.
+#endif
+
+/**********************************************************************/
+/* These provide some control over printf's feature set */
+
+/* This is undefined below depeding on uClibc's configuration. */
+#define __STDIO_PRINTF_FLOAT 1
+
+/* Now controlled by uClibc_stdio.h. */
+/* #define __UCLIBC_HAS_PRINTF_M_SPEC__ */
+
+
+/**********************************************************************/
+
+#if defined(__UCLIBC__) && !defined(__UCLIBC_HAS_FLOATS__)
+# undef __STDIO_PRINTF_FLOAT
+#endif
+
+#ifdef __BCC__
+# undef __STDIO_PRINTF_FLOAT
+#endif
+
+#ifdef __STDIO_PRINTF_FLOAT
+# include <float.h>
+# include <bits/uClibc_fpmax.h>
+#else
+# undef L__fpmaxtostr
+#endif
+
+
+#undef __STDIO_HAS_VSNPRINTF
+#if defined(__STDIO_BUFFERS) || defined(__USE_OLD_VFPRINTF__) || defined(__UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__)
+# define __STDIO_HAS_VSNPRINTF 1
+#endif
+
+/**********************************************************************/
+
+/* Now controlled by uClibc_stdio.h. */
+/* #define __UCLIBC_HAS_GLIBC_CUSTOM_PRINTF__ */
+
+#ifdef __UCLIBC_MJN3_ONLY__
+# ifdef L_register_printf_function
+/* emit only once */
+#  warning WISHLIST: Make MAX_USER_SPEC configurable?
+#  warning WISHLIST: Make MAX_ARGS_PER_SPEC configurable?
+# endif
+#endif
+
+#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_PRINTF__
+# define MAX_USER_SPEC       10
+# define MAX_ARGS_PER_SPEC    5
+#else
+# undef MAX_USER_SPEC
+# define MAX_ARGS_PER_SPEC    1
+#endif
+
+#if MAX_ARGS_PER_SPEC < 1
+# error MAX_ARGS_PER_SPEC < 1!
+# undef MAX_ARGS_PER_SPEC
+# define MAX_ARGS_PER_SPEC    1
+#endif
+
+#if defined(NL_ARGMAX) && (NL_ARGMAX < 9)
+# error NL_ARGMAX < 9!
+#endif
+
+#if defined(NL_ARGMAX) && (NL_ARGMAX >= (MAX_ARGS_PER_SPEC + 2))
+# define MAX_ARGS        NL_ARGMAX
+#else
+/* N for spec itself, plus 1 each for width and precision */
+# define MAX_ARGS        (MAX_ARGS_PER_SPEC + 2)
+#endif
+
+/**********************************************************************/
+
+#define __PA_FLAG_INTMASK \
+	(__PA_FLAG_CHAR|PA_FLAG_SHORT|__PA_FLAG_INT|PA_FLAG_LONG|PA_FLAG_LONG_LONG)
+
+#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_PRINTF__
+extern printf_function _custom_printf_handler[MAX_USER_SPEC] attribute_hidden;
+extern printf_arginfo_function *_custom_printf_arginfo[MAX_USER_SPEC] attribute_hidden;
+extern char *_custom_printf_spec attribute_hidden;
+#endif
+
+/**********************************************************************/
+
+#define SPEC_FLAGS		" +0-#'I"
+enum {
+	FLAG_SPACE      = 0x01,
+	FLAG_PLUS       = 0x02,	/* must be 2 * FLAG_SPACE */
+	FLAG_ZERO       = 0x04,
+	FLAG_MINUS      = 0x08,	/* must be 2 * FLAG_ZERO */
+	FLAG_HASH       = 0x10,
+	FLAG_THOUSANDS  = 0x20,
+	FLAG_I18N       = 0x40,	/* only works for d, i, u */
+	FLAG_WIDESTREAM = 0x80
+};
+
+/**********************************************************************/
+
+/* float layout          01234567890123456789   TODO: B?*/
+#define SPEC_CHARS		"npxXoudifFeEgGaACScs"
+enum {
+	CONV_n = 0,
+	CONV_p,
+	CONV_x, CONV_X,	CONV_o,	CONV_u,	CONV_d,	CONV_i,
+	CONV_f, CONV_F, CONV_e, CONV_E, CONV_g, CONV_G, CONV_a, CONV_A,
+	CONV_C, CONV_S, CONV_c, CONV_s,
+#ifdef __UCLIBC_HAS_PRINTF_M_SPEC__
+	CONV_m,
+#endif
+	CONV_custom0				/* must be last */
+};
+
+/*                         p   x   X  o   u   d   i */
+#define SPEC_BASE       { 16, 16, 16, 8, 10, 10, 10 }
+
+#define SPEC_RANGES     { CONV_n, CONV_p, CONV_i, CONV_A, \
+                          CONV_C, CONV_S, CONV_c, CONV_s, CONV_custom0 }
+
+#define SPEC_OR_MASK		 { \
+	/* n */			(PA_FLAG_PTR|PA_INT), \
+	/* p */			PA_POINTER, \
+	/* oxXudi */	PA_INT, \
+	/* fFeEgGaA */	PA_DOUBLE, \
+	/* C */			PA_WCHAR, \
+	/* S */			PA_WSTRING, \
+	/* c */			PA_CHAR, \
+	/* s */			PA_STRING, \
+}
+
+#define SPEC_AND_MASK		{ \
+	/* n */			(PA_FLAG_PTR|__PA_INTMASK), \
+	/* p */			PA_POINTER, \
+	/* oxXudi */	(__PA_INTMASK), \
+	/* fFeEgGaA */	(PA_FLAG_LONG_DOUBLE|PA_DOUBLE), \
+	/* C */			(PA_WCHAR), \
+	/* S */			(PA_WSTRING), \
+	/* c */			(PA_CHAR), \
+	/* s */			(PA_STRING), \
+}
+
+/**********************************************************************/
+/*
+ * In order to ease translation to what arginfo and _print_info._flags expect,
+ * we map:  0:int  1:char  2:longlong 4:long  8:short
+ * and then _flags |= (((q << 7) + q) & 0x701) and argtype |= (_flags & 0x701)
+ */
+
+/* TODO -- Fix the table below to take into account stdint.h. */
+/*  #ifndef LLONG_MAX */
+/*  #error fix QUAL_CHARS for no long long!  Affects 'L', 'j', 'q', 'll'. */
+/*  #else */
+/*  #if LLONG_MAX != INTMAX_MAX */
+/*  #error fix QUAL_CHARS intmax_t entry 'j'! */
+/*  #endif */
+/*  #endif */
+
+#ifdef PDS
+# error PDS already defined!
+#endif
+#ifdef SS
+# error SS already defined!
+#endif
+#ifdef IMS
+# error IMS already defined!
+#endif
+
+#if PTRDIFF_MAX == INT_MAX
+# define PDS		0
+#elif PTRDIFF_MAX == LONG_MAX
+# define PDS		4
+#elif defined(LLONG_MAX) && (PTRDIFF_MAX == LLONG_MAX)
+# define PDS		8
+#else
+# error fix QUAL_CHARS ptrdiff_t entry 't'!
+#endif
+
+#if SIZE_MAX == UINT_MAX
+# define SS		0
+#elif SIZE_MAX == ULONG_MAX
+# define SS		4
+#elif defined(LLONG_MAX) && (SIZE_MAX == ULLONG_MAX)
+# define SS		8
+#else
+# error fix QUAL_CHARS size_t entries 'z', 'Z'!
+#endif
+
+#if INTMAX_MAX == INT_MAX
+# define IMS		0
+#elif INTMAX_MAX == LONG_MAX
+# define IMS		4
+#elif defined(LLONG_MAX) && (INTMAX_MAX == LLONG_MAX)
+# define IMS		8
+#else
+# error fix QUAL_CHARS intmax_t entry 'j'!
+#endif
+
+#define QUAL_CHARS		{ \
+	/* j:(u)intmax_t z:(s)size_t  t:ptrdiff_t  \0:int */ \
+	/* q:long_long  Z:(s)size_t */ \
+	'h',   'l',  'L',  'j',  'z',  't',  'q', 'Z',  0, \
+	 2,     4,    8,  IMS,   SS,  PDS,    8,  SS,   0, /* TODO -- fix!!! */\
+	 1,     8 \
+}
+
+/**********************************************************************/
+
+#ifdef __STDIO_VA_ARG_PTR
+# ifdef __BCC__
+#  define __va_arg_ptr(ap,type)		(((type *)(ap += sizeof(type))) - 1)
+# endif
+
+# if 1
+#  ifdef __GNUC__
+/* TODO -- need other than for 386 as well! */
+
+#   ifndef __va_rounded_size
+#    define __va_rounded_size(TYPE) \
+	(((sizeof (TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int))
+#   endif
+#   define __va_arg_ptr(AP, TYPE)  \
+	(AP = (va_list) ((char *) (AP) + __va_rounded_size (TYPE)),  \
+	 ((void *) ((char *) (AP) - __va_rounded_size (TYPE)))  \
+	)
+#  endif
+# endif
+#endif /* __STDIO_VA_ARG_PTR */
+
+#ifdef __va_arg_ptr
+# define GET_VA_ARG(AP,F,TYPE,ARGS)	(*(AP) = __va_arg_ptr(ARGS,TYPE))
+# define GET_ARG_VALUE(AP,F,TYPE)	(*((TYPE *)(*(AP))))
+#else
+typedef union {
+	wchar_t wc;
+	unsigned int u;
+	unsigned long ul;
+# ifdef ULLONG_MAX
+	unsigned long long ull;
+# endif
+# ifdef __STDIO_PRINTF_FLOAT
+	double d;
+	long double ld;
+# endif
+	void *p;
+} argvalue_t;
+
+# define GET_VA_ARG(AU,F,TYPE,ARGS)	(AU->F = va_arg(ARGS,TYPE))
+# define GET_ARG_VALUE(AU,F,TYPE)	((TYPE)((AU)->F))
+#endif
+
+typedef struct {
+	const char *fmtpos;			/* TODO: move below struct?? */
+	struct printf_info info;
+#ifdef NL_ARGMAX
+	int maxposarg;				/* > 0 if args are positional, 0 if not, -1 if unknown */
+#endif
+	int num_data_args;			/* TODO: use sentinal??? */
+	unsigned int conv_num;
+	unsigned char argnumber[4]; /* width | prec | 1st data | unused */
+	int argtype[MAX_ARGS];
+	va_list arg;
+#ifdef __va_arg_ptr
+	void *argptr[MAX_ARGS];
+#else
+/* if defined(NL_ARGMAX) || defined(__UCLIBC_HAS_GLIBC_CUSTOM_PRINTF__) */
+	/* While this is wasteful of space in the case where pos args aren't
+	 * enabled, it is also needed to support custom printf handlers. */
+	argvalue_t argvalue[MAX_ARGS];
+#endif
+} ppfs_t;						/* parse printf format state */
+
+/**********************************************************************/
+
+/* TODO: fix printf to return 0 and set errno if format error.  Standard says
+   only returns -1 if sets error indicator for the stream. */
+
+#ifdef __STDIO_PRINTF_FLOAT
+typedef size_t (__fp_outfunc_t)(FILE *fp, intptr_t type, intptr_t len,
+								intptr_t buf);
+
+extern ssize_t _fpmaxtostr(FILE * fp, __fpmax_t x, struct printf_info *info,
+						   __fp_outfunc_t fp_outfunc) attribute_hidden;
+#endif
+
+extern int _ppfs_init(ppfs_t *ppfs, const char *fmt0) attribute_hidden; /* validates */
+extern void _ppfs_prepargs(ppfs_t *ppfs, va_list arg) attribute_hidden; /* sets posargptrs */
+extern void _ppfs_setargs(ppfs_t *ppfs) attribute_hidden; /* sets argptrs for current spec */
+extern int _ppfs_parsespec(ppfs_t *ppfs) attribute_hidden; /* parses specifier */
+
+extern void _store_inttype(void *dest, int desttype, uintmax_t val) attribute_hidden;
+extern uintmax_t _load_inttype(int desttype, const void *src, int uflag) attribute_hidden;
+
+/**********************************************************************/
+#ifdef L_parse_printf_format
+
+#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_PRINTF__
+
+/* NOTE: This function differs from the glibc version in that parsing stops
+ * upon encountering an invalid conversion specifier.  Since this is the way
+ * my printf functions work, I think it makes sense to do it that way here.
+ * Unfortunately, since glibc sets the return type as size_t, we have no way
+ * of returning that the template is illegal, other than returning 0.
+ */
+
+size_t parse_printf_format(register const char *template,
+						   size_t n, register int *argtypes)
+{
+	ppfs_t ppfs;
+	size_t i;
+	size_t count = 0;
+
+	if (_ppfs_init(&ppfs, template) >= 0) {
+#ifdef NL_ARGMAX
+		if (ppfs.maxposarg > 0)  {
+			/* Using positional args. */
+			count = ppfs.maxposarg;
+			if (n > count) {
+				n = count;
+			}
+			for (i = 0 ; i < n ; i++) {
+				*argtypes++ = ppfs.argtype[i];
+			}
+		} else
+#endif
+		{
+			/* Not using positional args. */
+			while (*template) {
+				if ((*template == '%') && (*++template != '%')) {
+					ppfs.fmtpos = template;
+					_ppfs_parsespec(&ppfs); /* Can't fail. */
+					template = ppfs.fmtpos; /* Update to one past spec end. */
+					if (ppfs.info.width == INT_MIN) {
+						++count;
+						if (n > 0) {
+							*argtypes++ = PA_INT;
+							--n;
+						}
+					}
+					if (ppfs.info.prec == INT_MIN) {
+						++count;
+						if (n > 0) {
+							*argtypes++ = PA_INT;
+							--n;
+						}
+					}
+					for (i = 0 ; i < ppfs.num_data_args ; i++) {
+						if ((ppfs.argtype[i]) != __PA_NOARG) {
+							++count;
+							if (n > 0) {
+								*argtypes++ = ppfs.argtype[i];
+								--n;
+							}
+						}
+					}
+				} else {
+					++template;
+				}
+			}
+		}
+	}
+
+	return count;
+}
+
+#endif
+
+#endif
+/**********************************************************************/
+#ifdef L__ppfs_init
+
+int attribute_hidden _ppfs_init(register ppfs_t *ppfs, const char *fmt0)
+{
+	int r;
+
+	/* First, zero out everything... argnumber[], argtype[], argptr[] */
+	memset(ppfs, 0, sizeof(ppfs_t)); /* TODO: nonportable???? */
+#ifdef NL_ARGMAX
+	--ppfs->maxposarg;			/* set to -1 */
+#endif
+	ppfs->fmtpos = fmt0;
+#ifdef __UCLIBC_MJN3_ONLY__
+# warning TODO: Make checking of the format string in C locale an option.
+#endif
+#ifdef __UCLIBC_HAS_LOCALE__
+	/* To support old programs, don't check mb validity if in C locale. */
+	if (__UCLIBC_CURLOCALE->encoding != __ctype_encoding_7_bit) {
+		/* ANSI/ISO C99 requires format string to be a valid multibyte string
+		 * beginning and ending in its initial shift state. */
+		static const char invalid_mbs[] = "Invalid multibyte format string.";
+		mbstate_t mbstate;
+		const char *p;
+		mbstate.__mask = 0;	/* Initialize the mbstate. */
+		p = fmt0;
+		if (mbsrtowcs(NULL, &p, SIZE_MAX, &mbstate) == ((size_t)(-1))) {
+			ppfs->fmtpos = invalid_mbs;
+			return -1;
+		}
+	}
+#endif /* __UCLIBC_HAS_LOCALE__ */
+	/* now set all argtypes to no-arg */
+	{
+#if 1
+		/* TODO - use memset here since already "paid for"? */
+		register int *p = ppfs->argtype;
+
+		r = MAX_ARGS;
+		do {
+			*p++ = __PA_NOARG;
+		} while (--r);
+#else
+		/* TODO -- get rid of this?? */
+		register char *p = (char *) ((MAX_ARGS-1) * sizeof(int));
+
+		do {
+			*((int *)(((char *)ppfs) + ((int)p) + offsetof(ppfs_t,argtype))) = __PA_NOARG;
+			p -= sizeof(int);
+		} while (p);
+#endif
+	}
+
+	/*
+	 * Run through the entire format string to validate it and initialize
+	 * the positional arg numbers (if any).
+	 */
+	{
+		register const char *fmt = fmt0;
+
+		while (*fmt) {
+			if ((*fmt == '%') && (*++fmt != '%')) {
+				ppfs->fmtpos = fmt; /* back up to the '%' */
+				r = _ppfs_parsespec(ppfs);
+				if (r < 0) {
+					return -1;
+				}
+				fmt = ppfs->fmtpos;	/* update to one past end of spec */
+			} else {
+				++fmt;
+			}
+		}
+		ppfs->fmtpos = fmt0;		/* rewind */
+	}
+
+#ifdef NL_MAX_ARG
+	/* If we have positional args, make sure we know all the types. */
+	{
+		register int *p = ppfs->argtype;
+		r = ppfs->maxposarg;
+		while (--r >= 0) {
+			if ( *p == __PA_NOARG ) { /* missing arg type!!! */
+				return -1;
+			}
+			++p;
+		}
+	}
+#endif /* NL_MAX_ARG */
+
+	return 0;
+}
+#endif
+/**********************************************************************/
+#ifdef L__ppfs_prepargs
+void attribute_hidden _ppfs_prepargs(register ppfs_t *ppfs, va_list arg)
+{
+	int i;
+
+	va_copy(ppfs->arg, arg);
+
+#ifdef NL_ARGMAX
+	i = ppfs->maxposarg; /* init for positional args */
+	if (i > 0) {
+		ppfs->num_data_args = i;
+		ppfs->info.width = ppfs->info.prec = ppfs->maxposarg = 0;
+		_ppfs_setargs(ppfs);
+		ppfs->maxposarg = i;
+	}
+#endif
+}
+#endif
+/**********************************************************************/
+#ifdef L__ppfs_setargs
+
+void attribute_hidden _ppfs_setargs(register ppfs_t *ppfs)
+{
+#ifdef __va_arg_ptr
+	register void **p = ppfs->argptr;
+#else
+	register argvalue_t *p = ppfs->argvalue;
+#endif
+	int i;
+
+#ifdef NL_ARGMAX
+	if (ppfs->maxposarg == 0) {	/* initing for or no pos args */
+#endif
+		if (ppfs->info.width == INT_MIN) {
+			ppfs->info.width =
+#ifdef __va_arg_ptr
+				*(int *)
+#endif
+				GET_VA_ARG(p,u,unsigned int,ppfs->arg);
+		}
+		if (ppfs->info.prec == INT_MIN) {
+			ppfs->info.prec =
+#ifdef __va_arg_ptr
+				*(int *)
+#endif
+				GET_VA_ARG(p,u,unsigned int,ppfs->arg);
+		}
+		i = 0;
+		while (i < ppfs->num_data_args) {
+			switch(ppfs->argtype[i++]) {
+				case (PA_INT|PA_FLAG_LONG_LONG):
+#ifdef ULLONG_MAX
+					GET_VA_ARG(p,ull,unsigned long long,ppfs->arg);
+					break;
+#endif
+				case (PA_INT|PA_FLAG_LONG):
+#if ULONG_MAX != UINT_MAX
+					GET_VA_ARG(p,ul,unsigned long,ppfs->arg);
+					break;
+#endif
+				case PA_CHAR:	/* TODO - be careful */
+ 					/* ... users could use above and really want below!! */
+				case (PA_INT|__PA_FLAG_CHAR):/* TODO -- translate this!!! */
+				case (PA_INT|PA_FLAG_SHORT):
+				case PA_INT:
+					GET_VA_ARG(p,u,unsigned int,ppfs->arg);
+					break;
+				case PA_WCHAR:	/* TODO -- assume int? */
+					/* we're assuming wchar_t is at least an int */
+					GET_VA_ARG(p,wc,wchar_t,ppfs->arg);
+					break;
+#ifdef __STDIO_PRINTF_FLOAT
+					/* PA_FLOAT */
+				case PA_DOUBLE:
+					GET_VA_ARG(p,d,double,ppfs->arg);
+					break;
+				case (PA_DOUBLE|PA_FLAG_LONG_DOUBLE):
+					GET_VA_ARG(p,ld,long double,ppfs->arg);
+					break;
+#else  /* __STDIO_PRINTF_FLOAT */
+				case PA_DOUBLE:
+				case (PA_DOUBLE|PA_FLAG_LONG_DOUBLE):
+					assert(0);
+					continue;
+#endif /* __STDIO_PRINTF_FLOAT */
+				default:
+					/* TODO -- really need to ensure this can't happen */
+					assert(ppfs->argtype[i-1] & PA_FLAG_PTR);
+				case PA_POINTER:
+				case PA_STRING:
+				case PA_WSTRING:
+					GET_VA_ARG(p,p,void *,ppfs->arg);
+					break;
+				case __PA_NOARG:
+					continue;
+			}
+			++p;
+		}
+#ifdef NL_ARGMAX
+	} else {
+		if (ppfs->info.width == INT_MIN) {
+			ppfs->info.width
+				= (int) GET_ARG_VALUE(p + ppfs->argnumber[0] - 1,u,unsigned int);
+		}
+		if (ppfs->info.prec == INT_MIN) {
+			ppfs->info.prec
+				= (int) GET_ARG_VALUE(p + ppfs->argnumber[1] - 1,u,unsigned int);
+		}
+	}
+#endif /* NL_ARGMAX */
+
+	/* Now we know the width and precision. */
+	if (ppfs->info.width < 0) {
+		ppfs->info.width = -ppfs->info.width;
+		PRINT_INFO_SET_FLAG(&(ppfs->info),left);
+		PRINT_INFO_CLR_FLAG(&(ppfs->info),space);
+		ppfs->info.pad = ' ';
+	}
+#if 0
+	/* NOTE -- keep neg for now so float knows! */
+	if (ppfs->info.prec < 0) {	/* spec says treat as omitted. */
+		/* so use default prec... 1 for everything but floats and strings. */
+		ppfs->info.prec = 1;
+	}
+#endif
+}
+#endif
+/**********************************************************************/
+#ifdef L__ppfs_parsespec
+
+/* Notes: argtype differs from glibc for the following:
+ *         mine              glibc
+ *  lc     PA_WCHAR          PA_CHAR       the standard says %lc means %C
+ *  ls     PA_WSTRING        PA_STRING     the standard says %ls means %S
+ *  {*}n   {*}|PA_FLAG_PTR   PA_FLAG_PTR   size of n can be qualified
+ */
+
+/* TODO: store positions of positional args */
+
+/* TODO -- WARNING -- assumes aligned on integer boundaries!!! */
+
+/* TODO -- disable if not using positional args!!! */
+#define _OVERLAPPING_DIFFERENT_ARGS
+
+/* TODO -- rethink this -- perhaps we should set to largest type??? */
+
+#ifdef _OVERLAPPING_DIFFERENT_ARGS
+
+#define PROMOTED_SIZE_OF(X)		((sizeof(X) + sizeof(int) - 1) / sizeof(X))
+
+static const short int type_codes[] = {
+	__PA_NOARG,					/* must be first entry */
+	PA_POINTER,
+	PA_STRING,
+	PA_WSTRING,
+	PA_CHAR,
+	PA_INT|PA_FLAG_SHORT,
+	PA_INT,
+	PA_INT|PA_FLAG_LONG,
+	PA_INT|PA_FLAG_LONG_LONG,
+	PA_WCHAR,
+#ifdef __STDIO_PRINTF_FLOAT
+	/* PA_FLOAT, */
+	PA_DOUBLE,
+	PA_DOUBLE|PA_FLAG_LONG_DOUBLE,
+#endif
+};
+
+static const unsigned char type_sizes[] = {
+	/* unknown type consumes no arg */
+	0,							/* must be first entry */
+	PROMOTED_SIZE_OF(void *),
+	PROMOTED_SIZE_OF(char *),
+	PROMOTED_SIZE_OF(wchar_t *),
+	PROMOTED_SIZE_OF(char),
+	PROMOTED_SIZE_OF(short),
+	PROMOTED_SIZE_OF(int),
+	PROMOTED_SIZE_OF(long),
+#ifdef ULLONG_MAX
+	PROMOTED_SIZE_OF(long long),
+#else
+	PROMOTED_SIZE_OF(long),		/* TODO -- is this correct? (above too) */
+#endif
+	PROMOTED_SIZE_OF(wchar_t),
+#ifdef __STDIO_PRINTF_FLOAT
+	/* PROMOTED_SIZE_OF(float), */
+	PROMOTED_SIZE_OF(double),
+	PROMOTED_SIZE_OF(long double),
+#endif
+};
+
+static int _promoted_size(int argtype)
+{
+	register const short int *p;
+
+	/* note -- since any unrecognized type is treated as a pointer */
+	p = type_codes + sizeof(type_codes)/sizeof(type_codes[0]);
+	do {
+		if (*--p == argtype) {
+			break;
+		}
+	} while (p > type_codes);
+
+	return type_sizes[(int)(p - type_codes)];
+}
+
+static int _is_equal_or_bigger_arg(int curtype, int newtype)
+{
+	/* Quick test */
+	if (newtype == __PA_NOARG) {
+		return 0;
+	}
+	if ((curtype == __PA_NOARG) || (curtype == newtype)) {
+		return 1;
+	}
+	/* Ok... slot is already filled and types are different in name. */
+	/* So, compare promoted sizes of curtype and newtype args. */
+	return _promoted_size(curtype) <= _promoted_size(newtype);
+}
+
+#else
+
+#define _is_equal_or_bigger_arg(C,N)	(((C) == __PA_NOARG) || ((C) == (N)))
+
+#endif
+
+#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_PRINTF__
+/* TODO - do this differently? */
+static char _bss_custom_printf_spec[MAX_USER_SPEC]; /* 0-init'd for us.  */
+
+attribute_hidden char *_custom_printf_spec = _bss_custom_printf_spec;
+attribute_hidden printf_arginfo_function *_custom_printf_arginfo[MAX_USER_SPEC];
+attribute_hidden printf_function _custom_printf_handler[MAX_USER_SPEC];
+#endif /* __UCLIBC_HAS_GLIBC_CUSTOM_PRINTF__ */
+
+int attribute_hidden _ppfs_parsespec(ppfs_t *ppfs)
+{
+	register const char *fmt;
+	register const char *p;
+	int preci;
+	int width;
+	int flags;
+	int dataargtype;
+	int i;
+	int dpoint;
+#ifdef NL_ARGMAX
+	int maxposarg;
+#endif
+	int p_m_spec_chars;
+	int n;
+	int argtype[MAX_ARGS_PER_SPEC+2];
+	int argnumber[3];			/* width, precision, 1st data arg */
+	static const char spec_flags[] = SPEC_FLAGS;
+	static const char spec_chars[] = SPEC_CHARS;/* TODO: b? */
+	static const char spec_ranges[] = SPEC_RANGES;
+	static const short spec_or_mask[] = SPEC_OR_MASK;
+	static const short spec_and_mask[] = SPEC_AND_MASK;
+	static const char qual_chars[] = QUAL_CHARS;
+#ifdef __UCLIBC_HAS_WCHAR__
+	char buf[32];
+#endif
+
+	/* WIDE note: we can test against '%' here since we don't allow */
+	/* WIDE note: other mappings of '%' in the wide char set. */
+	preci = -1;
+	argnumber[0] = 0;
+	argnumber[1] = 0;
+	argtype[0] = __PA_NOARG;
+	argtype[1] = __PA_NOARG;
+#ifdef NL_ARGMAX
+	maxposarg = ppfs->maxposarg;
+#endif
+
+#ifdef __UCLIBC_HAS_WCHAR__
+	/* This is somewhat lame, but saves a lot of code.  If we're dealing with
+	 * a wide stream, that means the format is a wchar string.  So, copy it
+	 * char-by-char into a normal char buffer for processing.  Make the buffer
+	 * (buf) big enough so that any reasonable format specifier will fit.
+	 * While there a legal specifiers that won't, the all involve duplicate
+	 * flags or outrageous field widths/precisions. */
+	width = dpoint = 0;
+	flags = ppfs->info._flags & FLAG_WIDESTREAM;
+	if (flags == 0) {
+		fmt = ppfs->fmtpos;
+	} else {
+		fmt = buf + 1;
+		i = 0;
+		do {
+			buf[i] = (char) (((wchar_t *) ppfs->fmtpos)[i-1]);
+			if (buf[i] != (((wchar_t *) ppfs->fmtpos)[i-1])) {
+				return -1;
+			}
+		} while (buf[i++] && (i < sizeof(buf)));
+		buf[sizeof(buf)-1] = 0;
+	}
+#else  /* __UCLIBC_HAS_WCHAR__ */
+	width = flags = dpoint = 0;
+	fmt = ppfs->fmtpos;
+#endif
+
+	assert(fmt[-1] == '%');
+	assert(fmt[0] != '%');
+
+	/* Process arg pos and/or flags and/or width and/or precision. */
+ width_precision:
+	p = fmt;
+	if (*fmt == '*') {
+		argtype[-dpoint] = PA_INT;
+		++fmt;
+	}
+	i = 0;
+	while (isdigit(*fmt)) {
+		if (i < INT_MAX / 10
+		    || (i == INT_MAX / 10 && (*fmt - '0') <= INT_MAX % 10)) {
+			i = (i * 10) + (*fmt - '0');
+		} else {
+			i = INT_MAX; /* best we can do... */
+		}
+		++fmt;
+	}
+	if (p[-1] == '%') { /* Check for a position. */
+
+		/* TODO: if val not in range, then error */
+
+#ifdef NL_ARGMAX
+		if ((*fmt == '$') && (i > 0)) {/* Positional spec. */
+			++fmt;
+			if (maxposarg == 0) {
+				return -1;
+			}
+			argnumber[2] = i;
+			if (argnumber[2] > maxposarg) {
+				maxposarg = i;
+			}
+			/* Now fall through to check flags. */
+		} else {
+			if (maxposarg > 0) {
+# ifdef __UCLIBC_HAS_PRINTF_M_SPEC__
+#  ifdef __UCLIBC_MJN3_ONLY__
+#   warning TODO: Support prec and width for %m when positional args used
+				/* Actually, positional arg processing will fail in general
+				 * for specifiers that don't require an arg. */
+#  endif
+				if (*fmt == 'm') {
+					goto PREC_WIDTH;
+				}
+# endif /* __UCLIBC_HAS_PRINTF_M_SPEC__ */
+				return -1;
+			}
+			maxposarg = 0;		/* Possible redundant store, but cuts size. */
+
+			if ((fmt > p) && (*p != '0')) {
+				goto PREC_WIDTH;
+			}
+
+			fmt = p;			/* Back up for possible '0's flag. */
+			/* Now fall through to check flags. */
+		}
+#else  /* NL_ARGMAX */
+		if (*fmt == '$') {		/* Positional spec. */
+			return -1;
+		}
+
+		if ((fmt > p) && (*p != '0')) {
+			goto PREC_WIDTH;
+		}
+
+		fmt = p;			/* Back up for possible '0's flag. */
+		/* Now fall through to check flags. */
+#endif /* NL_ARGMAX */
+
+	restart_flags:		/* Process flags. */
+		i = 1;
+		p = spec_flags;
+
+		do {
+			if (*fmt == *p++) {
+				++fmt;
+				flags |= i;
+				goto restart_flags;
+			}
+			i += i;				/* Better than i <<= 1 for bcc */
+		} while (*p);
+		i = 0;
+
+		/* If '+' then ignore ' ', and if '-' then ignore '0'. */
+		/* Note: Need to ignore '0' when prec is an arg with val < 0, */
+		/*       but that test needs to wait until the arg is retrieved. */
+		flags &= ~((flags & (FLAG_PLUS|FLAG_MINUS)) >> 1);
+		/* Note: Ignore '0' when prec is specified < 0 too (in printf). */
+
+		if (fmt[-1] != '%') {	/* If we've done anything, loop for width. */
+			goto width_precision;
+		}
+	}
+ PREC_WIDTH:
+	if (*p == '*') {			/* Prec or width takes an arg. */
+#ifdef NL_ARGMAX
+		if (maxposarg) {
+			if ((*fmt++ != '$') || (i <= 0)) {
+				/* Using pos args and no $ or invalid arg number. */
+				return -1;
+			}
+			argnumber[-dpoint] = i;
+		} else
+#endif
+		if (++p != fmt) {
+			 /* Not using pos args but digits followed *. */
+			return -1;
+		}
+		i = INT_MIN;
+	}
+
+	if (!dpoint) {
+		width = i;
+		if (*fmt == '.') {
+			++fmt;
+			dpoint = -1;		/* To use as default precison. */
+			goto width_precision;
+		}
+	} else {
+		preci = i;
+	}
+
+	/* Process qualifier. */
+	p = qual_chars;
+	do {
+		if (*fmt == *p) {
+			++fmt;
+			break;
+		}
+	} while (*++p);
+	if ((p - qual_chars < 2) && (*fmt == *p)) {
+		p += ((sizeof(qual_chars)-2) / 2);
+		++fmt;
+	}
+	dataargtype = ((int)(p[(sizeof(qual_chars)-2) / 2])) << 8;
+
+	/* Process conversion specifier. */
+	if (!*fmt) {
+		return -1;
+	}
+
+	p = spec_chars;
+
+	do {
+		if (*fmt == *p) {
+			p_m_spec_chars = p - spec_chars;
+
+			if ((p_m_spec_chars >= CONV_c)
+				&& (dataargtype & PA_FLAG_LONG)) {
+				p_m_spec_chars -= 2; /* lc -> C and ls -> S */
+			}
+
+			ppfs->conv_num = p_m_spec_chars;
+			p = spec_ranges-1;
+			while (p_m_spec_chars > *++p) {}
+
+			i = p - spec_ranges;
+			argtype[2] = (dataargtype | spec_or_mask[i]) & spec_and_mask[i];
+			p = spec_chars;
+			break;
+		}
+	} while(*++p);
+
+	ppfs->info.spec = *fmt;
+	ppfs->info.prec = preci;
+	ppfs->info.width = width;
+	ppfs->info.pad = ((flags & FLAG_ZERO) ? '0' : ' ');
+	ppfs->info._flags = (flags & ~FLAG_ZERO) | (dataargtype & __PA_INTMASK);
+	ppfs->num_data_args = 1;
+
+	if (!*p) {
+#ifdef __UCLIBC_HAS_PRINTF_M_SPEC__
+		if (*fmt == 'm') {
+			ppfs->conv_num = CONV_m;
+			ppfs->num_data_args = 0;
+		} else
+#endif
+		{
+#ifndef __UCLIBC_HAS_GLIBC_CUSTOM_PRINTF__
+			return -1;  /* Error */
+#else
+			/* Handle custom arg -- WARNING -- overwrites p!!! */
+			ppfs->conv_num = CONV_custom0;
+			p = _custom_printf_spec;
+			while (1) {
+				if (*p == *fmt) {
+					printf_arginfo_function *fp = _custom_printf_arginfo[(int)(p - _custom_printf_spec)];
+					ppfs->num_data_args = fp(&(ppfs->info), MAX_ARGS_PER_SPEC, argtype + 2);
+					if (ppfs->num_data_args > MAX_ARGS_PER_SPEC) {
+						return -1;  /* Error -- too many args! */
+					}
+					break;
+				}
+				if (++p >= (_custom_printf_spec + MAX_USER_SPEC))
+					return -1;  /* Error */
+			}
+#endif
+		}
+	}
+
+#ifdef NL_ARGMAX
+	if (maxposarg > 0) {
+		i = 0;
+		do {
+			/* Update maxposarg and check that NL_ARGMAX is not exceeded. */
+			n = ((i <= 2)
+				 ? (ppfs->argnumber[i] = argnumber[i])
+				 : argnumber[2] + (i-2));
+			if (n > maxposarg) {
+				maxposarg = n;
+				if (maxposarg > NL_ARGMAX) {
+					return -1;
+				}
+			}
+			--n;
+			/* Record argtype with largest size (current, new). */
+			if (_is_equal_or_bigger_arg(ppfs->argtype[n], argtype[i])) {
+				ppfs->argtype[n] = argtype[i];
+			}
+		} while (++i < ppfs->num_data_args + 2);
+	} else
+#endif /* NL_ARGMAX */
+	{
+		ppfs->argnumber[2] = 1;
+		memcpy(ppfs->argtype, argtype + 2, ppfs->num_data_args * sizeof(int));
+	}
+
+#ifdef NL_ARGMAX
+	ppfs->maxposarg = maxposarg;
+#endif
+
+#ifdef __UCLIBC_HAS_WCHAR__
+	flags = ppfs->info._flags & FLAG_WIDESTREAM;
+	if (flags == 0) {
+		ppfs->fmtpos = ++fmt;
+	} else {
+		ppfs->fmtpos = (const char *) (((const wchar_t *)(ppfs->fmtpos))
+									   + (fmt - buf) );
+	}
+#else  /* __UCLIBC_HAS_WCHAR__ */
+	ppfs->fmtpos = ++fmt;
+#endif
+
+ 	return ppfs->num_data_args + 2;
+}
+
+#endif
+/**********************************************************************/
+#ifdef L_register_printf_function
+
+#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_PRINTF__
+
+int register_printf_function(int spec, printf_function handler,
+							 printf_arginfo_function arginfo)
+{
+	register char *r;
+	register char *p;
+
+	if (spec && (arginfo != NULL)) { /* TODO -- check if spec is valid char */
+		r = NULL;
+		p = _custom_printf_spec + MAX_USER_SPEC;
+		do {
+			--p;
+			if (!*p) {
+				r = p;
+			}
+#ifdef __BCC__
+			else				/* bcc generates less code with fall-through */
+#endif
+			if (*p == spec) {
+				r = p;
+				p = _custom_printf_spec;
+			}
+		} while (p > _custom_printf_spec);
+
+		if (r) {
+			if (handler) {
+				*r = spec;
+				_custom_printf_handler[(int)(r - p)] = handler;
+				_custom_printf_arginfo[(int)(r - p)] = arginfo;
+			} else {
+				*r = 0;
+			}
+			return 0;
+		}
+		/* TODO -- if asked to unregister a non-existent spec, return what? */
+	}
+	return -1;
+}
+
+#endif
+
+#endif
+/**********************************************************************/
+#if defined(L__vfprintf_internal) || defined(L__vfwprintf_internal)
+
+/* We only support ascii digits (or their USC equivalent codes) in
+ * precision and width settings in *printf (wide) format strings.
+ * In other words, we don't currently support glibc's 'I' flag.
+ * We do accept it, but it is currently ignored. */
+
+static size_t _charpad(FILE * __restrict stream, int padchar, size_t numpad);
+
+#ifdef L__vfprintf_internal
+
+#define VFPRINTF_internal _vfprintf_internal
+#define FMT_TYPE char
+#define OUTNSTR _outnstr
+#define STRLEN  strlen
+#define _PPFS_init _ppfs_init
+#define OUTPUT(F,S)			fputs_unlocked(S,F)
+/* #define _outnstr(stream, string, len)	__stdio_fwrite(string, len, stream) */
+#define _outnstr(stream, string, len)	((len > 0) ? __stdio_fwrite((const unsigned char *)(string), len, stream) : 0)
+#define FP_OUT _fp_out_narrow
+
+#ifdef __STDIO_PRINTF_FLOAT
+
+static size_t _fp_out_narrow(FILE *fp, intptr_t type, intptr_t len, intptr_t buf)
+{
+	size_t r = 0;
+
+	if (type & 0x80) {			/* Some type of padding needed. */
+		int buflen = strlen((const char *) buf);
+		len -= buflen;
+		if (len > 0) {
+			r = _charpad(fp, (type & 0x7f), len);
+			if (r != len) {
+				return r;
+			}
+		}
+		len = buflen;
+	}
+	return r + OUTNSTR(fp, (const char *) buf, len);
+}
+
+#endif /* __STDIO_PRINTF_FLOAT */
+
+#else  /* L__vfprintf_internal */
+
+#define VFPRINTF_internal _vfwprintf_internal
+#define FMT_TYPE wchar_t
+#define OUTNSTR _outnwcs
+#define STRLEN  wcslen
+#define _PPFS_init _ppwfs_init
+/* Pulls in fseek: */
+#define OUTPUT(F,S)			fputws(S,F)
+/* TODO: #define OUTPUT(F,S)		_wstdio_fwrite((S),wcslen(S),(F)) */
+#define _outnwcs(stream, wstring, len)	_wstdio_fwrite((const wchar_t *)(wstring), len, stream)
+#define FP_OUT _fp_out_wide
+
+static size_t _outnstr(FILE *stream, const char *s, size_t wclen)
+{
+	/* NOTE!!! len here is the number of wchars we want to generate!!! */
+	wchar_t wbuf[64];
+	mbstate_t mbstate;
+	size_t todo, r, n;
+
+	mbstate.__mask = 0;
+	todo = wclen;
+
+	while (todo) {
+		r = mbsrtowcs(wbuf, &s,
+					  ((todo <= sizeof(wbuf)/sizeof(wbuf[0]))
+					   ? todo
+					   : sizeof(wbuf)/sizeof(wbuf[0])),
+					  &mbstate);
+		assert(((ssize_t)r) > 0);
+		n = _outnwcs(stream, wbuf, r);
+		todo -= n;
+		if (n != r) {
+			break;
+		}
+	}
+
+	return wclen - todo;
+}
+
+#ifdef __STDIO_PRINTF_FLOAT
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning TODO: Move defines from _fpmaxtostr.  Put them in a common header.
+#endif
+
+/* The following defines are from _fpmaxtostr.*/
+#define DIGITS_PER_BLOCK     9
+#define NUM_DIGIT_BLOCKS   ((DECIMAL_DIG+DIGITS_PER_BLOCK-1)/DIGITS_PER_BLOCK)
+#define BUF_SIZE  ( 3 + NUM_DIGIT_BLOCKS * DIGITS_PER_BLOCK )
+
+static size_t _fp_out_wide(FILE *fp, intptr_t type, intptr_t len, intptr_t buf)
+{
+	wchar_t wbuf[BUF_SIZE];
+	const char *s = (const char *) buf;
+	size_t r = 0;
+	int i;
+
+	if (type & 0x80) {			/* Some type of padding needed */
+		int buflen = strlen(s);
+		len -= buflen;
+		if (len > 0) {
+			r = _charpad(fp, (type & 0x7f), len);
+			if (r != len) {
+				return r;
+			}
+		}
+		len = buflen;
+	}
+
+	if (len > 0) {
+		i = 0;
+		do {
+#ifdef __LOCALE_C_ONLY
+			wbuf[i] = s[i];
+#else
+
+# ifdef __UCLIBC_HAS_GLIBC_DIGIT_GROUPING__
+			if (s[i] == ',') {
+				wbuf[i] = __UCLIBC_CURLOCALE->thousands_sep_wc;
+			} else
+# endif
+			if (s[i] == '.') {
+				wbuf[i] = __UCLIBC_CURLOCALE->decimal_point_wc;
+			} else {
+				wbuf[i] = s[i];
+			}
+#endif /* __LOCALE_C_ONLY */
+
+		} while (++i < len);
+
+		r += OUTNSTR(fp, wbuf, len);
+	}
+
+	return r;
+}
+
+#endif /* __STDIO_PRINTF_FLOAT */
+
+static int _ppwfs_init(register ppfs_t *ppfs, const wchar_t *fmt0)
+{
+	static const wchar_t invalid_wcs[] = L"Invalid wide format string.";
+	int r;
+
+	/* First, zero out everything... argnumber[], argtype[], argptr[] */
+	memset(ppfs, 0, sizeof(ppfs_t)); /* TODO: nonportable???? */
+#ifdef NL_ARGMAX
+	--ppfs->maxposarg;			/* set to -1 */
+#endif
+	ppfs->fmtpos = (const char *) fmt0;
+	ppfs->info._flags = FLAG_WIDESTREAM;
+
+	{
+		mbstate_t mbstate;
+		const wchar_t *p;
+		mbstate.__mask = 0;	/* Initialize the mbstate. */
+		p = fmt0;
+		if (wcsrtombs(NULL, &p, SIZE_MAX, &mbstate) == ((size_t)(-1))) {
+			ppfs->fmtpos = (const char *) invalid_wcs;
+			return -1;
+		}
+	}
+
+	/* now set all argtypes to no-arg */
+	{
+#if 1
+		/* TODO - use memset here since already "paid for"? */
+		register int *p = ppfs->argtype;
+
+		r = MAX_ARGS;
+		do {
+			*p++ = __PA_NOARG;
+		} while (--r);
+#else
+		/* TODO -- get rid of this?? */
+		register char *p = (char *) ((MAX_ARGS-1) * sizeof(int));
+
+		do {
+			*((int *)(((char *)ppfs) + ((int)p) + offsetof(ppfs_t,argtype))) = __PA_NOARG;
+			p -= sizeof(int);
+		} while (p);
+#endif
+	}
+
+	/*
+	 * Run through the entire format string to validate it and initialize
+	 * the positional arg numbers (if any).
+	 */
+	{
+		register const wchar_t *fmt = fmt0;
+
+		while (*fmt) {
+			if ((*fmt == '%') && (*++fmt != '%')) {
+				ppfs->fmtpos = (const char *) fmt; /* back up to the '%' */
+				r = _ppfs_parsespec(ppfs);
+				if (r < 0) {
+					return -1;
+				}
+				fmt = (const wchar_t *) ppfs->fmtpos; /* update to one past end of spec */
+			} else {
+				++fmt;
+			}
+		}
+		ppfs->fmtpos = (const char *) fmt0; /* rewind */
+	}
+
+#ifdef NL_ARGMAX
+	/* If we have positional args, make sure we know all the types. */
+	{
+		register int *p = ppfs->argtype;
+		r = ppfs->maxposarg;
+		while (--r >= 0) {
+			if ( *p == __PA_NOARG ) { /* missing arg type!!! */
+				return -1;
+			}
+			++p;
+		}
+	}
+#endif /* NL_ARGMAX */
+
+	return 0;
+}
+
+#endif /* L__vfprintf_internal */
+
+
+static size_t _charpad(FILE * __restrict stream, int padchar, size_t numpad)
+{
+	size_t todo = numpad;
+
+	/* TODO -- Use a buffer to cut down on function calls... */
+	FMT_TYPE pad[1];
+
+	*pad = padchar;
+	while (todo && (OUTNSTR(stream, (const char *) pad, 1) == 1)) {
+		--todo;
+	}
+
+	return numpad - todo;
+}
+
+/* TODO -- Dynamically allocate work space to accomodate stack-poor archs? */
+static int _do_one_spec(FILE * __restrict stream,
+						 register ppfs_t *ppfs, int *count)
+{
+	static const char spec_base[] = SPEC_BASE;
+#ifdef L__vfprintf_internal
+	static const char prefix[] = "+\0-\0 \0000x\0000X";
+	/*                            0  2  4    6     9 11*/
+#else
+	static const wchar_t prefix[] = L"+\0-\0 \0000x\0000X";
+#endif
+	enum {
+		PREFIX_PLUS = 0,
+		PREFIX_MINUS = 2,
+		PREFIX_SPACE = 4,
+		PREFIX_LWR_X = 6,
+		PREFIX_UPR_X = 9,
+		PREFIX_NONE = 11
+	};
+
+#ifdef __va_arg_ptr
+	const void * const *argptr;
+#else
+	const void * argptr[MAX_ARGS_PER_SPEC];
+#endif
+	int *argtype;
+#ifdef __UCLIBC_HAS_WCHAR__
+	const wchar_t *ws = NULL;
+	mbstate_t mbstate;
+#endif
+	size_t slen;
+#ifdef L__vfprintf_internal
+#define SLEN slen
+#else
+	size_t SLEN;
+	wchar_t wbuf[2];
+#endif
+	int base;
+	int numpad;
+	int alphacase;
+	int numfill = 0;			/* TODO: fix */
+	int prefix_num = PREFIX_NONE;
+	char padchar = ' ';
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning TODO: Determine appropriate buf size.
+#endif
+	/* TODO: buf needs to be big enough for any possible error return strings
+	 * and also for any locale-grouped long long integer strings generated.
+	 * This should be large enough for any of the current archs/locales, but
+	 * eventually this should be handled robustly. */
+	char buf[128];
+
+#ifdef NDEBUG
+	_ppfs_parsespec(ppfs);
+#else
+	if (_ppfs_parsespec(ppfs) < 0) { /* TODO: just for debugging */
+		abort();
+	}
+#endif
+	_ppfs_setargs(ppfs);
+
+	argtype = ppfs->argtype + ppfs->argnumber[2] - 1;
+	/* Deal with the argptr vs argvalue issue. */
+#ifdef __va_arg_ptr
+	argptr = (const void * const *) ppfs->argptr;
+# ifdef NL_ARGMAX
+	if (ppfs->maxposarg > 0) {	/* Using positional args... */
+		argptr += ppfs->argnumber[2] - 1;
+	}
+# endif
+#else
+	/* Need to build a local copy... */
+	{
+		register argvalue_t *p = ppfs->argvalue;
+		int i;
+# ifdef NL_ARGMAX
+		if (ppfs->maxposarg > 0) {	/* Using positional args... */
+			p += ppfs->argnumber[2] - 1;
+		}
+# endif
+		for (i = 0 ; i < ppfs->num_data_args ; i++ ) {
+			argptr[i] = (void *) p++;
+		}
+	}
+#endif
+	{
+		register char *s = NULL; /* TODO: Should s be unsigned char * ? */
+
+		if (ppfs->conv_num == CONV_n) {
+			_store_inttype(*(void **)*argptr,
+						   ppfs->info._flags & __PA_INTMASK,
+						   (intmax_t) (*count));
+			return 0;
+		}
+		if (ppfs->conv_num <= CONV_i) {	/* pointer or (un)signed int */
+			alphacase = __UIM_LOWER;
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#ifdef L__vfprintf_internal
+#warning CONSIDER: Should we ignore these flags if stub locale?  What about custom specs?
+#endif
+#endif
+			base = spec_base[(int)(ppfs->conv_num - CONV_p)];
+			if (base == 10) {
+				if (PRINT_INFO_FLAG_VAL(&(ppfs->info),group)) {
+					alphacase = __UIM_GROUP;
+				}
+				if (PRINT_INFO_FLAG_VAL(&(ppfs->info),i18n)) {
+					alphacase |= 0x80;
+				}
+			}
+
+			if (ppfs->conv_num <= CONV_u) { /* pointer or unsigned int */
+				if (ppfs->conv_num == CONV_X) {
+					alphacase = __UIM_UPPER;
+				}
+				if (ppfs->conv_num == CONV_p) { /* pointer */
+					prefix_num = PREFIX_LWR_X;
+				} else {		/* unsigned int */
+				}
+			} else {			/* signed int */
+				base = -base;
+			}
+			if (ppfs->info.prec < 0) { /* Ignore '0' flag if prec specified. */
+				padchar = ppfs->info.pad;
+			}
+#ifdef __UCLIBC_MJN3_ONLY__
+#ifdef L__vfprintf_internal
+#warning CONSIDER: If using outdigits and/or grouping, how should we interpret precision?
+#endif
+#endif
+			s = _uintmaxtostr(buf + sizeof(buf) - 1,
+							  (uintmax_t)
+							  _load_inttype(ppfs->conv_num == CONV_p ? PA_FLAG_LONG : *argtype & __PA_INTMASK,
+											*argptr, base), base, alphacase);
+			if (ppfs->conv_num > CONV_u) { /* signed int */
+				if (*s == '-') {
+					PRINT_INFO_SET_FLAG(&(ppfs->info),showsign);
+					++s;		/* handle '-' in the prefix string */
+					prefix_num = PREFIX_MINUS;
+				} else if (PRINT_INFO_FLAG_VAL(&(ppfs->info),showsign)) {
+					prefix_num = PREFIX_PLUS;
+				} else if (PRINT_INFO_FLAG_VAL(&(ppfs->info),space)) {
+					prefix_num = PREFIX_SPACE;
+				}
+			}
+			slen = (char *)(buf + sizeof(buf) - 1) - s;
+#ifdef L__vfwprintf_internal
+			{
+				const char *q = s;
+				mbstate.__mask = 0; /* Initialize the mbstate. */
+				SLEN = mbsrtowcs(NULL, &q, 0, &mbstate);
+			}
+#endif
+			numfill = ((ppfs->info.prec < 0) ? 1 : ppfs->info.prec);
+			if (PRINT_INFO_FLAG_VAL(&(ppfs->info),alt)) {
+				if (ppfs->conv_num <= CONV_x) {	/* x or p */
+					prefix_num = PREFIX_LWR_X;
+				}
+				if (ppfs->conv_num == CONV_X) {
+					prefix_num = PREFIX_UPR_X;
+				}
+				if ((ppfs->conv_num == CONV_o) && (numfill <= SLEN)) {
+					numfill = ((*s == '0') ? 1 : SLEN + 1);
+				}
+			}
+			if (*s == '0') {
+				if (prefix_num >= PREFIX_LWR_X) {
+					prefix_num = PREFIX_NONE;
+				}
+				if (ppfs->conv_num == CONV_p) {/* null pointer */
+					s = "(nil)";
+#ifdef L__vfwprintf_internal
+					SLEN =
+#endif
+					slen = 5;
+					numfill = 0;
+				} else if (numfill == 0) {	/* if precision 0, no output */
+#ifdef L__vfwprintf_internal
+					SLEN =
+#endif
+					slen = 0;
+				}
+			}
+			numfill = ((numfill > SLEN) ? numfill - SLEN : 0);
+		} else if (ppfs->conv_num <= CONV_A) {	/* floating point */
+#ifdef __STDIO_PRINTF_FLOAT
+			ssize_t nf;
+			nf = _fpmaxtostr(stream,
+							 (__fpmax_t)
+							 (PRINT_INFO_FLAG_VAL(&(ppfs->info),is_long_double)
+							  ? *(long double *) *argptr
+							  : (long double) (* (double *) *argptr)),
+							 &ppfs->info, FP_OUT );
+			if (nf < 0) {
+				return -1;
+			}
+			*count += nf;
+
+			return 0;
+#else  /* __STDIO_PRINTF_FLOAT */
+			return -1;			/* TODO -- try to continue? */
+#endif
+		} else if (ppfs->conv_num <= CONV_S) {	/* wide char or string */
+#ifdef L__vfprintf_internal
+
+#ifdef __UCLIBC_HAS_WCHAR__
+			mbstate.__mask = 0;	/* Initialize the mbstate. */
+			if (ppfs->conv_num == CONV_S) { /* wide string */
+				ws = *((const wchar_t **) *argptr);
+				if (!ws) {
+					goto NULL_STRING;
+				}
+				/* We use an awful uClibc-specific hack here, passing
+				 * (char*) &ws as the conversion destination.  This signals
+				 * uClibc's wcsrtombs that we want a "restricted" length
+				 * such that the mbs fits in a buffer of the specified
+				 * size with no partial conversions. */
+				slen = wcsrtombs((char *) &ws, &ws, /* Use awful hack! */
+							((ppfs->info.prec >= 0)
+							 ? ppfs->info.prec
+							 : SIZE_MAX),
+							&mbstate);
+				if (slen == ((size_t)-1)) {
+					return -1;	/* EILSEQ */
+				}
+			} else {			/* wide char */
+				s = buf;
+				slen = wcrtomb(s, (*((const wchar_t *) *argptr)), &mbstate);
+				if (slen == ((size_t)-1)) {
+					return -1;	/* EILSEQ */
+				}
+				s[slen] = 0;	/* TODO - Is this necessary? */
+			}
+#else  /* __UCLIBC_HAS_WCHAR__ */
+			return -1;
+#endif
+		} else if (ppfs->conv_num <= CONV_s) {	/* char or string */
+			if (ppfs->conv_num == CONV_s) { /* string */
+				s = *((char **) (*argptr));
+				if (s) {
+#ifdef __UCLIBC_HAS_PRINTF_M_SPEC__
+				SET_STRING_LEN:
+#endif
+					slen = strnlen(s, ((ppfs->info.prec >= 0)
+									   ? ppfs->info.prec : SIZE_MAX));
+				} else {
+#ifdef __UCLIBC_HAS_WCHAR__
+				NULL_STRING:
+#endif
+					s = "(null)";
+					slen = 6;
+					/* Use an empty string rather than truncation if precision is too small. */
+					if (ppfs->info.prec >= 0 && ppfs->info.prec < slen)
+						slen = 0;
+				}
+			} else {			/* char */
+				s = buf;
+				*s = (unsigned char)(*((const int *) *argptr));
+				s[1] = 0;
+				slen = 1;
+			}
+
+#else  /* L__vfprintf_internal */
+
+			if (ppfs->conv_num == CONV_S) { /* wide string */
+				ws = *((wchar_t **) (*argptr));
+				if (!ws) {
+					goto NULL_STRING;
+				}
+				SLEN = wcsnlen(ws, ((ppfs->info.prec >= 0)
+									? ppfs->info.prec : SIZE_MAX));
+			} else {			/* wide char */
+				*wbuf = (wchar_t)(*((const wint_t *) *argptr));
+			CHAR_CASE:
+				ws = wbuf;
+				wbuf[1] = 0;
+				SLEN = 1;
+			}
+
+		} else if (ppfs->conv_num <= CONV_s) {	/* char or string */
+
+			if (ppfs->conv_num == CONV_s) { /* string */
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning TODO: Fix %s for _vfwprintf_internal... output upto illegal sequence?
+#endif
+				s = *((char **) (*argptr));
+				if (s) {
+#ifdef __UCLIBC_HAS_PRINTF_M_SPEC__
+				SET_STRING_LEN:
+#endif
+					/* We use an awful uClibc-specific hack here, passing
+					 * (wchar_t*) &mbstate as the conversion destination.
+					 *  This signals uClibc's mbsrtowcs that we want a
+					 * "restricted" length such that the mbs fits in a buffer
+					 * of the specified size with no partial conversions. */
+					{
+						const char *q = s;
+						mbstate.__mask = 0;	/* Initialize the mbstate. */
+						SLEN = mbsrtowcs((wchar_t *) &mbstate, &q,
+										 ((ppfs->info.prec >= 0)
+										  ? ppfs->info.prec : SIZE_MAX),
+										 &mbstate);
+					}
+					if (SLEN == ((size_t)(-1))) {
+						return -1;	/* EILSEQ */
+					}
+				} else {
+				NULL_STRING:
+					s = "(null)";
+					SLEN = slen = 6;
+					/* Use an empty string rather than truncation if precision is too small. */
+					if (ppfs->info.prec >= 0 && ppfs->info.prec < slen)
+						SLEN = slen = 0;
+				}
+			} else {			/* char */
+				*wbuf = btowc( (unsigned char)(*((const int *) *argptr)) );
+				goto CHAR_CASE;
+			}
+
+#endif /* L__vfprintf_internal */
+
+#ifdef __UCLIBC_HAS_PRINTF_M_SPEC__
+		} else if (ppfs->conv_num == CONV_m) {
+			s = __glibc_strerror_r(errno, buf, sizeof(buf));
+			goto SET_STRING_LEN;
+#endif
+		} else {
+#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_PRINTF__
+			assert(ppfs->conv_num == CONV_custom0);
+
+			s = _custom_printf_spec;
+			do {
+				if (*s == ppfs->info.spec) {
+					int rv;
+					/* TODO -- check return value for sanity? */
+					rv = (*_custom_printf_handler
+						  [(int)(s-_custom_printf_spec)])
+						(stream, &ppfs->info, argptr);
+					if (rv < 0) {
+						return -1;
+					}
+					*count += rv;
+					return 0;
+				}
+			} while (++s < (_custom_printf_spec + MAX_USER_SPEC));
+#endif /* __UCLIBC_HAS_GLIBC_CUSTOM_PRINTF__ */
+			assert(0);
+			return -1;
+		}
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#ifdef L__vfprintf_internal
+#warning CONSIDER: If using outdigits and/or grouping, how should we pad?
+#endif
+#endif
+		{
+			size_t t;
+
+			t = SLEN + numfill;
+			if (prefix_num != PREFIX_NONE) {
+				t += ((prefix_num < PREFIX_LWR_X) ? 1 : 2);
+			}
+			numpad = ((ppfs->info.width > t) ? (ppfs->info.width - t) : 0);
+			*count += t + numpad;
+		}
+		if (padchar == '0') { /* TODO: check this */
+			numfill += numpad;
+			numpad = 0;
+		}
+
+		/* Now handle the output itself. */
+		if (!PRINT_INFO_FLAG_VAL(&(ppfs->info),left)) {
+			if (_charpad(stream, ' ', numpad) != numpad) {
+				return -1;
+			}
+			numpad = 0;
+		}
+		OUTPUT(stream, prefix + prefix_num);
+
+		if (_charpad(stream, '0', numfill) != numfill) {
+			return -1;
+		}
+
+#ifdef L__vfprintf_internal
+
+# ifdef __UCLIBC_HAS_WCHAR__
+		if (!ws) {
+			assert(s);
+			if (_outnstr(stream, s, slen) != slen) {
+				return -1;
+			}
+		} else {				/* wide string */
+			size_t t;
+			mbstate.__mask = 0;	/* Initialize the mbstate. */
+			while (slen) {
+				t = (slen <= sizeof(buf)) ? slen : sizeof(buf);
+				t = wcsrtombs(buf, &ws, t, &mbstate);
+				assert(t != ((size_t)(-1)));
+				if (_outnstr(stream, buf, t) != t) {
+					return -1;
+				}
+				slen -= t;
+			}
+		}
+# else  /* __UCLIBC_HAS_WCHAR__ */
+		if (_outnstr(stream, (const unsigned char *) s, slen) != slen) {
+			return -1;
+		}
+# endif
+
+#else  /* L__vfprintf_internal */
+
+		if (!ws) {
+			assert(s);
+			if (_outnstr(stream, s, SLEN) != SLEN) {
+				return -1;
+			}
+		} else {
+			if (_outnwcs(stream, ws, SLEN) != SLEN) {
+				return -1;
+			}
+		}
+
+#endif /* L__vfprintf_internal */
+		if (_charpad(stream, ' ', numpad) != numpad) {
+			return -1;
+		}
+	}
+
+	return 0;
+}
+
+
+int VFPRINTF_internal (FILE * __restrict stream,
+			  const FMT_TYPE * __restrict format,
+			  va_list arg)
+{
+	ppfs_t ppfs;
+	int count, r;
+	register const FMT_TYPE *s;
+
+	count = 0;
+	s = format;
+
+	if (_PPFS_init(&ppfs, format) < 0) {	/* Bad format string. */
+		OUTNSTR(stream, (const char *) ppfs.fmtpos,
+				STRLEN((const FMT_TYPE *)(ppfs.fmtpos)));
+#if defined(L__vfprintf_internal) && !defined(NDEBUG)
+		fprintf(stderr,"\nIMbS: \"%s\"\n\n", format);
+#endif
+		count = -1;
+	} else {
+		_ppfs_prepargs(&ppfs, arg);	/* This did a va_copy!!! */
+
+		do {
+			while (*format && (*format != '%')) {
+				++format;
+			}
+
+			if (format - s) {	/* output any literal text in format string */
+				r = OUTNSTR(stream, (const char *) s, format - s);
+				if (r != (format - s)) {
+					count = -1;
+					break;
+				}
+				count += r;
+			}
+
+			if (!*format) {			/* we're done */
+				break;
+			}
+
+			if (format[1] != '%') {	/* if we get here, *format == '%' */
+				/* TODO: _do_one_spec needs to know what the output funcs are!!! */
+				ppfs.fmtpos = (const char *)(++format);
+				/* TODO: check -- should only fail on stream error */
+				r = _do_one_spec(stream, &ppfs, &count);
+				if (r < 0) {
+					count = -1;
+					break;
+				}
+				s = format = (const FMT_TYPE *) ppfs.fmtpos;
+			} else {			/* %% means literal %, so start new string */
+				s = ++format;
+				++format;
+			}
+		} while (1);
+
+		va_end(ppfs.arg);		/* Need to clean up after va_copy! */
+	}
+
+/* #if defined(L__vfprintf_internal) && defined(__UCLIBC_HAS_WCHAR__) */
+/*  DONE: */
+/* #endif */
+
+	return count;
+}
+#endif /* defined(L__vfprintf_internal) || defined(L__vfwprintf_internal) */
+
+
+/**********************************************************************/
+#if defined(L_vfprintf) || defined(L_vfwprintf)
+
+/* This is just a wrapper around VFPRINTF_internal.
+ * Factoring out vfprintf internals allows:
+ * (1) vdprintf and vsnprintf don't need to setup fake locking,
+ * (2) __STDIO_STREAM_TRANS_TO_WRITE is not used in vfprintf internals,
+ * and thus fseek etc is not pulled in by vdprintf and vsnprintf.
+ *
+ * In order to not pull in fseek through fputs, OUTPUT() macro
+ * is using __stdio_fwrite (TODO: do the same for wide functions).
+ */
+#ifdef L_vfprintf
+# define VFPRINTF vfprintf
+# define VFPRINTF_internal _vfprintf_internal
+# define FMT_TYPE char
+#else
+# define VFPRINTF vfwprintf
+# define VFPRINTF_internal _vfwprintf_internal
+# define FMT_TYPE wchar_t
+#endif
+
+libc_hidden_proto(VFPRINTF)
+int VFPRINTF (FILE * __restrict stream,
+			  const FMT_TYPE * __restrict format,
+			  va_list arg)
+{
+	int count;
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	__STDIO_AUTO_THREADLOCK(stream);
+
+	if
+#ifdef L_vfprintf
+	(!__STDIO_STREAM_IS_NARROW_WRITING(stream)
+	 && __STDIO_STREAM_TRANS_TO_WRITE(stream, __FLAG_NARROW))
+#else
+	(!__STDIO_STREAM_IS_WIDE_WRITING(stream)
+	 && __STDIO_STREAM_TRANS_TO_WRITE(stream, __FLAG_WIDE))
+#endif
+	{
+		count = -1;
+	} else {
+		count = VFPRINTF_internal(stream, format, arg);
+	}
+
+	__STDIO_AUTO_THREADUNLOCK(stream);
+
+	return count;
+}
+libc_hidden_def(VFPRINTF)
+#endif /* defined(L_vfprintf) || defined(L_vfwprintf) */
+
+/**********************************************************************/
diff --git a/ap/build/uClibc/libc/stdio/_vfprintf_internal.c b/ap/build/uClibc/libc/stdio/_vfprintf_internal.c
new file mode 100644
index 0000000..40bf39e
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/_vfprintf_internal.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define L__vfprintf_internal
+#include "_vfprintf.c"
diff --git a/ap/build/uClibc/libc/stdio/_vfwprintf_internal.c b/ap/build/uClibc/libc/stdio/_vfwprintf_internal.c
new file mode 100644
index 0000000..8584cf4
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/_vfwprintf_internal.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define L__vfwprintf_internal
+#include "_vfprintf.c"
diff --git a/ap/build/uClibc/libc/stdio/_wcommit.c b/ap/build/uClibc/libc/stdio/_wcommit.c
new file mode 100644
index 0000000..a0b3219
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/_wcommit.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+#ifdef __STDIO_BUFFERS
+
+/* Commit the data in the write buffer.
+ * Returns 0 on success, >0 (pending) on failure.
+ * Side effects are those of _stdio_WRITE
+ */
+
+size_t attribute_hidden __stdio_wcommit(register FILE * __restrict stream)
+{
+	size_t bufsize;
+
+	__STDIO_STREAM_VALIDATE(stream);
+
+	if ((bufsize = __STDIO_STREAM_BUFFER_WUSED(stream)) != 0) {
+		stream->__bufpos = stream->__bufstart;
+		__stdio_WRITE(stream, stream->__bufstart, bufsize);
+	}
+
+	return __STDIO_STREAM_BUFFER_WUSED(stream);
+}
+
+#endif
diff --git a/ap/build/uClibc/libc/stdio/_wfwrite.c b/ap/build/uClibc/libc/stdio/_wfwrite.c
new file mode 100644
index 0000000..517e3a7
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/_wfwrite.c
@@ -0,0 +1,73 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+#include <wchar.h>
+
+#ifndef __UCLIBC_HAS_WCHAR__
+#error wide function when no wide support!
+#endif
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning TODO: Fix prototype.
+#endif
+
+
+size_t attribute_hidden _wstdio_fwrite(const wchar_t *__restrict ws, size_t n,
+					  register FILE *__restrict stream)
+{
+	size_t r, count;
+	char buf[64];
+	const wchar_t *pw;
+
+	__STDIO_STREAM_VALIDATE(stream);
+
+#ifdef __STDIO_BUFFERS
+	if (__STDIO_STREAM_IS_FAKE_VSWPRINTF(stream)) {
+		/* We know buffer is wchar aligned for fake streams. */
+		count = (((wchar_t *)(stream->__bufend))
+				 - ((wchar_t *)(stream->__bufpos)));
+		if (count > n) {
+			count = n;
+		}
+		if (count) {
+			wmemcpy((wchar_t *)(stream->__bufpos), ws, count);
+			stream->__bufpos = (unsigned char *)(((wchar_t *)(stream->__bufpos)) + count);
+		}
+		__STDIO_STREAM_VALIDATE(stream);
+		return n;
+	}
+#endif
+
+	count = 0;
+
+	if (__STDIO_STREAM_IS_WIDE_WRITING(stream)
+		|| !__STDIO_STREAM_TRANS_TO_WRITE(stream, __FLAG_WIDE)
+		) {
+
+		pw = ws;
+		while (n > count) {
+			r = wcsnrtombs(buf, &pw, n-count, sizeof(buf), &stream->__state);
+			if (r != ((size_t) -1)) { /* No encoding errors */
+				if (!r) {
+					++r;		  /* 0 is returned when nul is reached. */
+					pw = ws + count + r; /* pw was set to NULL, so correct. */
+				}
+				if (__stdio_fwrite((const unsigned char *)buf, r, stream) == r) {
+					count = pw - ws;
+					continue;
+				}
+			}
+			break;
+		}
+
+		/* Note: The count is incorrect if 0 < __stdio_fwrite return < r!!! */
+	}
+
+	__STDIO_STREAM_VALIDATE(stream);
+	return count;
+}
diff --git a/ap/build/uClibc/libc/stdio/asprintf.c b/ap/build/uClibc/libc/stdio/asprintf.c
new file mode 100644
index 0000000..6334cc7
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/asprintf.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include <features.h>
+
+#ifdef __USE_GNU
+#include "_stdio.h"
+#include <stdarg.h>
+
+
+
+#ifndef __STDIO_HAS_VSNPRINTF
+#warning Skipping asprintf and __asprintf since no vsnprintf!
+#else
+
+int asprintf(char **__restrict buf, const char * __restrict format, ...)
+{
+	va_list arg;
+	int rv;
+
+	va_start(arg, format);
+	rv = vasprintf(buf, format, arg);
+	va_end(arg);
+
+	return rv;
+}
+libc_hidden_def(asprintf)
+
+#endif
+#endif
diff --git a/ap/build/uClibc/libc/stdio/clearerr.c b/ap/build/uClibc/libc/stdio/clearerr.c
new file mode 100644
index 0000000..a96ecaa
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/clearerr.c
@@ -0,0 +1,40 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+#undef clearerr
+#ifdef __DO_UNLOCKED
+
+#undef clearerr_unlocked
+void clearerr_unlocked(register FILE *stream)
+{
+	__STDIO_STREAM_VALIDATE(stream);
+
+	__CLEARERR_UNLOCKED(stream);
+}
+
+#ifndef __UCLIBC_HAS_THREADS__
+strong_alias(clearerr_unlocked,clearerr)
+#endif
+
+#elif defined __UCLIBC_HAS_THREADS__
+
+void clearerr(register FILE *stream)
+{
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	__STDIO_AUTO_THREADLOCK(stream);
+
+	__STDIO_STREAM_VALIDATE(stream);
+
+	__CLEARERR_UNLOCKED(stream);
+
+	__STDIO_AUTO_THREADUNLOCK(stream);
+}
+
+#endif
diff --git a/ap/build/uClibc/libc/stdio/clearerr_unlocked.c b/ap/build/uClibc/libc/stdio/clearerr_unlocked.c
new file mode 100644
index 0000000..1728d03
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/clearerr_unlocked.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define __DO_UNLOCKED
+#include "clearerr.c"
diff --git a/ap/build/uClibc/libc/stdio/ctermid.c b/ap/build/uClibc/libc/stdio/ctermid.c
new file mode 100644
index 0000000..854c526
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/ctermid.c
@@ -0,0 +1,27 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+char *ctermid(register char *s)
+{
+	static char sbuf[L_ctermid];
+
+#ifdef __BCC__
+	/* Currently elks doesn't support /dev/tty. */
+	if (!s) {
+		s = sbuf;
+	}
+	*s = 0;
+
+	return s;
+#else
+	/* glibc always returns /dev/tty for linux. */
+	return strcpy((s ? s : sbuf), "/dev/tty");
+#endif
+}
diff --git a/ap/build/uClibc/libc/stdio/dprintf.c b/ap/build/uClibc/libc/stdio/dprintf.c
new file mode 100644
index 0000000..3fab127
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/dprintf.c
@@ -0,0 +1,26 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include <features.h>
+
+#ifdef __USE_GNU
+#include "_stdio.h"
+#include <stdarg.h>
+
+
+int dprintf(int filedes, const char * __restrict format, ...)
+{
+	va_list arg;
+	int rv;
+
+	va_start(arg, format);
+	rv = vdprintf(filedes, format, arg);
+	va_end(arg);
+
+	return rv;
+}
+#endif
diff --git a/ap/build/uClibc/libc/stdio/fclose.c b/ap/build/uClibc/libc/stdio/fclose.c
new file mode 100644
index 0000000..3417b26
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fclose.c
@@ -0,0 +1,103 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+int fclose(register FILE *stream)
+{
+	int rv = 0;
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+#ifdef __STDIO_HAS_OPENLIST
+#if !defined(__UCLIBC_HAS_THREADS__) || !defined(__STDIO_BUFFERS)
+	/* First, remove the file from the open file list. */
+	{
+		FILE *ptr;
+
+		__STDIO_THREADLOCK_OPENLIST_DEL;
+		__STDIO_THREADLOCK_OPENLIST_ADD;
+		ptr = _stdio_openlist;
+		if ((ptr = _stdio_openlist) == stream) {
+			_stdio_openlist = stream->__nextopen;
+		} else {
+			while (ptr) {
+				if (ptr->__nextopen == stream) {
+					ptr->__nextopen = stream->__nextopen;
+					break;
+				}
+				ptr = ptr->__nextopen;
+			}
+		}
+		__STDIO_THREADUNLOCK_OPENLIST_ADD;
+		__STDIO_THREADUNLOCK_OPENLIST_DEL;
+	}
+#endif
+#endif
+
+	__STDIO_AUTO_THREADLOCK(stream);
+
+	__STDIO_STREAM_VALIDATE(stream);
+
+#ifdef __STDIO_BUFFERS
+	/* Write any pending buffered chars. */
+	if (__STDIO_STREAM_IS_WRITING(stream)) {
+		rv = fflush_unlocked(stream);
+	}
+#endif
+
+	if (__CLOSE(stream) < 0) {	/* Must close even if fflush failed. */
+		rv = EOF;
+	}
+
+	stream->__filedes = -1;
+
+	/* We need a way for freopen to know that a file has been closed.
+	 * Since a file can't be both readonly and writeonly, that makes
+	 * an effective signal.  It also has the benefit of disabling
+	 * transitions to either reading or writing. */
+#if defined(__UCLIBC_HAS_THREADS__) && defined(__STDIO_BUFFERS)
+	/* Before we mark the file as closed, make sure we increment the openlist use count
+	 * so it isn't freed under us while still cleaning up. */
+	__STDIO_OPENLIST_INC_USE;
+#endif
+	stream->__modeflags &= (__FLAG_FREEBUF|__FLAG_FREEFILE);
+	stream->__modeflags |= (__FLAG_READONLY|__FLAG_WRITEONLY);
+
+#ifndef NDEBUG
+	__STDIO_STREAM_RESET_GCS(stream);
+
+	/* Reinitialize everything (including putc since fflush could fail). */
+	__STDIO_STREAM_DISABLE_GETC(stream);
+	__STDIO_STREAM_DISABLE_PUTC(stream);
+	__STDIO_STREAM_INIT_BUFREAD_BUFPOS(stream);
+
+# ifdef __UCLIBC_HAS_WCHAR__
+	stream->__ungot_width[0] = 0;
+# endif
+# ifdef __STDIO_MBSTATE
+	__INIT_MBSTATE(&(stream->__state));
+# endif
+#endif
+
+	__STDIO_AUTO_THREADUNLOCK(stream);
+
+	__STDIO_STREAM_FREE_BUFFER(stream);
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning REMINDER: inefficient - locks and unlocks twice and walks whole list
+#endif
+#if defined(__UCLIBC_HAS_THREADS__) && defined(__STDIO_BUFFERS)
+	/* inefficient - locks/unlocks twice and walks whole list */
+	__STDIO_OPENLIST_INC_DEL_CNT;
+	__STDIO_OPENLIST_DEC_USE;	/* This with free the file if necessary. */
+#else
+	__STDIO_STREAM_FREE_FILE(stream);
+#endif
+
+	return rv;
+}
+libc_hidden_def(fclose)
diff --git a/ap/build/uClibc/libc/stdio/fcloseall.c b/ap/build/uClibc/libc/stdio/fcloseall.c
new file mode 100644
index 0000000..4d78b37
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fcloseall.c
@@ -0,0 +1,70 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include <features.h>
+
+#ifdef __USE_GNU
+#include "_stdio.h"
+
+
+/* NOTE: GLIBC difference!!! -- fcloseall
+ * According to the info pages, glibc actually fclose()s all open files.
+ * Apparently, glibc's new version only fflush()s and unbuffers all
+ * writing streams to cope with unordered destruction of c++ static
+ * objects.
+ */
+
+int fcloseall (void)
+{
+#ifdef __STDIO_HAS_OPENLIST
+
+	int retval = 0;
+	FILE *f;
+
+	__STDIO_OPENLIST_INC_USE;
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning REMINDER: should probably have a get_head() operation
+#endif
+	__STDIO_THREADLOCK_OPENLIST_ADD;
+	f = _stdio_openlist;
+	__STDIO_THREADUNLOCK_OPENLIST_ADD;
+
+	while (f) {
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning REMINDER: should probably have a get_next() operation
+#endif
+		FILE *n = f->__nextopen;
+		__STDIO_AUTO_THREADLOCK_VAR;
+
+		__STDIO_AUTO_THREADLOCK(f);
+		/* Only call fclose on the stream if it is not already closed. */
+		if ((f->__modeflags & (__FLAG_READONLY|__FLAG_WRITEONLY))
+		    != (__FLAG_READONLY|__FLAG_WRITEONLY)
+		    ) {
+			if (fclose(f)) {
+				retval = EOF;
+			}
+		}
+		__STDIO_AUTO_THREADUNLOCK(f);
+
+		f = n;
+	}
+
+	__STDIO_OPENLIST_DEC_USE;
+
+	return retval;
+
+#else
+
+#warning Always fails in this configuration because no open file list.
+
+	return EOF;
+
+#endif
+}
+#endif
diff --git a/ap/build/uClibc/libc/stdio/fdopen.c b/ap/build/uClibc/libc/stdio/fdopen.c
new file mode 100644
index 0000000..76c239f
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fdopen.c
@@ -0,0 +1,20 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+FILE *fdopen(int filedes, const char *mode)
+{
+	intptr_t cur_mode;
+
+	cur_mode = fcntl(filedes, F_GETFL);
+	if (cur_mode != -1)
+		return _stdio_fopen(cur_mode, mode, NULL, filedes);
+	return NULL;
+}
+libc_hidden_def(fdopen)
diff --git a/ap/build/uClibc/libc/stdio/feof.c b/ap/build/uClibc/libc/stdio/feof.c
new file mode 100644
index 0000000..e5f03b7
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/feof.c
@@ -0,0 +1,43 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+#undef feof
+#ifdef __DO_UNLOCKED
+
+#undef feof_unlocked
+int feof_unlocked(register FILE *stream)
+{
+	__STDIO_STREAM_VALIDATE(stream);
+
+	return __FEOF_UNLOCKED(stream);
+}
+
+#ifndef __UCLIBC_HAS_THREADS__
+strong_alias(feof_unlocked,feof)
+#endif
+
+#elif defined __UCLIBC_HAS_THREADS__
+
+int feof(register FILE *stream)
+{
+	int retval;
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	__STDIO_AUTO_THREADLOCK(stream);
+
+	__STDIO_STREAM_VALIDATE(stream);
+
+	retval = __FEOF_UNLOCKED(stream);
+
+	__STDIO_AUTO_THREADUNLOCK(stream);
+
+	return retval;
+}
+
+#endif
diff --git a/ap/build/uClibc/libc/stdio/feof_unlocked.c b/ap/build/uClibc/libc/stdio/feof_unlocked.c
new file mode 100644
index 0000000..4553f30
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/feof_unlocked.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define __DO_UNLOCKED
+#include "feof.c"
diff --git a/ap/build/uClibc/libc/stdio/ferror.c b/ap/build/uClibc/libc/stdio/ferror.c
new file mode 100644
index 0000000..947b89e
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/ferror.c
@@ -0,0 +1,43 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+#undef ferror
+#ifdef __DO_UNLOCKED
+
+#undef ferror_unlocked
+int ferror_unlocked(register FILE *stream)
+{
+	__STDIO_STREAM_VALIDATE(stream);
+
+	return __FERROR_UNLOCKED(stream);
+}
+
+#ifndef __UCLIBC_HAS_THREADS__
+strong_alias(ferror_unlocked,ferror)
+#endif
+
+#elif defined __UCLIBC_HAS_THREADS__
+
+int ferror(register FILE *stream)
+{
+	int retval;
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	__STDIO_AUTO_THREADLOCK(stream);
+
+	__STDIO_STREAM_VALIDATE(stream);
+
+	retval = __FERROR_UNLOCKED(stream);
+
+	__STDIO_AUTO_THREADUNLOCK(stream);
+
+	return retval;
+}
+
+#endif
diff --git a/ap/build/uClibc/libc/stdio/ferror_unlocked.c b/ap/build/uClibc/libc/stdio/ferror_unlocked.c
new file mode 100644
index 0000000..19722b8
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/ferror_unlocked.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define __DO_UNLOCKED
+#include "ferror.c"
diff --git a/ap/build/uClibc/libc/stdio/fflush.c b/ap/build/uClibc/libc/stdio/fflush.c
new file mode 100644
index 0000000..d9104a4
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fflush.c
@@ -0,0 +1,211 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+#ifdef __DO_UNLOCKED
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning WISHLIST: Add option to test for undefined behavior of fflush.
+#endif /* __UCLIBC_MJN3_ONLY__ */
+
+/* Even if the stream is set to user-locking, we still need to lock
+ * when all (lbf) writing streams are flushed. */
+
+#define __MY_STDIO_THREADLOCK(__stream)					\
+        __UCLIBC_IO_MUTEX_CONDITIONAL_LOCK((__stream)->__lock,		\
+	(_stdio_user_locking != 2))
+
+#define __MY_STDIO_THREADUNLOCK(__stream)				\
+        __UCLIBC_IO_MUTEX_CONDITIONAL_UNLOCK((__stream)->__lock,		\
+	(_stdio_user_locking != 2))
+
+#if defined(__UCLIBC_HAS_THREADS__) && defined(__STDIO_BUFFERS)
+void attribute_hidden _stdio_openlist_dec_use(void)
+{
+	__STDIO_THREADLOCK_OPENLIST_DEL;
+	if ((_stdio_openlist_use_count == 1) && (_stdio_openlist_del_count > 0)) {
+		FILE *p = NULL;
+		FILE *n;
+		FILE *stream;
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning REMINDER: As an optimization, we could unlock after we move past the head.
+#endif
+		/* Grab the openlist add lock since we might change the head of the list. */
+		__STDIO_THREADLOCK_OPENLIST_ADD;
+		for (stream = _stdio_openlist; stream; stream = n) {
+			n = stream->__nextopen;
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning REMINDER: fix for nonatomic
+#endif
+			if ((stream->__modeflags & (__FLAG_READONLY|__FLAG_WRITEONLY|__FLAG_FAILED_FREOPEN))
+				== (__FLAG_READONLY|__FLAG_WRITEONLY)
+				) {		 /* The file was closed and should be removed from the list. */
+				if (!p) {
+					_stdio_openlist = n;
+				} else {
+					p->__nextopen = n;
+				}
+				__STDIO_STREAM_FREE_FILE(stream);
+			} else {
+				p = stream;
+			}
+		}
+		__STDIO_THREADUNLOCK_OPENLIST_ADD;
+		_stdio_openlist_del_count = 0; /* Should be clean now. */
+	}
+	--_stdio_openlist_use_count;
+	__STDIO_THREADUNLOCK_OPENLIST_DEL;
+}
+#endif
+
+int fflush_unlocked(register FILE *stream)
+{
+#ifdef __STDIO_BUFFERS
+
+	int retval = 0;
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning REMINDER: should probably define a modeflags type
+#endif
+	unsigned short bufmask = __FLAG_LBF;
+
+#ifndef NDEBUG
+	if ((stream != NULL) && (stream != (FILE *) &_stdio_openlist)) {
+		__STDIO_STREAM_VALIDATE(stream); /* debugging only */
+	}
+#endif
+
+	if (stream == (FILE *) &_stdio_openlist) { /* Flush all lbf streams. */
+		stream = NULL;
+		bufmask = 0;
+	}
+
+	if (!stream) {				/* Flush all (lbf) writing streams. */
+
+		__STDIO_OPENLIST_INC_USE;
+
+		__STDIO_THREADLOCK_OPENLIST_ADD;
+		stream = _stdio_openlist;
+		__STDIO_THREADUNLOCK_OPENLIST_ADD;
+
+		while(stream) {
+			/* We only care about currently writing streams and do not want to
+			 * block trying to obtain mutexes on non-writing streams. */
+#warning fix for nonatomic
+#warning unnecessary check if no threads
+			if (__STDIO_STREAM_IS_WRITING(stream)) { /* ONLY IF ATOMIC!!! */
+				__MY_STDIO_THREADLOCK(stream);
+				/* Need to check again once we have the lock. */
+				if (!(((stream->__modeflags | bufmask)
+					   ^ (__FLAG_WRITING|__FLAG_LBF)
+					   ) & (__FLAG_WRITING|__MASK_BUFMODE))
+					) {
+					if (!__STDIO_COMMIT_WRITE_BUFFER(stream)) {
+						__STDIO_STREAM_DISABLE_PUTC(stream);
+						__STDIO_STREAM_CLEAR_WRITING(stream);
+					} else {
+						retval = EOF;
+					}
+				}
+				__MY_STDIO_THREADUNLOCK(stream);
+			}
+			stream = stream->__nextopen;
+		}
+
+		__STDIO_OPENLIST_DEC_USE;
+
+	} else if (__STDIO_STREAM_IS_WRITING(stream)) {
+		if (!__STDIO_COMMIT_WRITE_BUFFER(stream)) {
+			__STDIO_STREAM_DISABLE_PUTC(stream);
+			__STDIO_STREAM_CLEAR_WRITING(stream);
+		} else {
+			retval = EOF;
+		}
+	}
+#if 0
+	else if (stream->__modeflags & (__MASK_READING|__FLAG_READONLY)) {
+		/* ANSI/ISO says behavior in this case is undefined but also says you
+		 * shouldn't flush a stream you were reading from.  As usual, glibc
+		 * caters to broken programs and simply ignores this. */
+		__UNDEFINED_OR_NONPORTABLE;
+		__STDIO_STREAM_SET_ERROR(stream);
+		__set_errno(EBADF);
+		retval = EOF;
+	}
+#endif
+
+#ifndef NDEBUG
+	if ((stream != NULL) && (stream != (FILE *) &_stdio_openlist)) {
+		__STDIO_STREAM_VALIDATE(stream); /* debugging only */
+	}
+#endif
+
+	return retval;
+
+#else  /* __STDIO_BUFFERS --------------------------------------- */
+
+#ifndef NDEBUG
+	if ((stream != NULL)
+#ifdef __STDIO_HAS_OPENLIST
+		&& (stream != (FILE *) &_stdio_openlist)
+#endif
+		) {
+		__STDIO_STREAM_VALIDATE(stream); /* debugging only */
+	}
+#endif
+
+#if 0
+	if (stream && (stream->__modeflags & (__MASK_READING|__FLAG_READONLY))) {
+		/* ANSI/ISO says behavior in this case is undefined but also says you
+		 * shouldn't flush a stream you were reading from.  As usual, glibc
+		 * caters to broken programs and simply ignores this. */
+		__UNDEFINED_OR_NONPORTABLE;
+		__STDIO_STREAM_SET_ERROR(stream);
+		__set_errno(EBADF);
+		return EOF;
+	}
+#endif
+
+	return 0;
+#endif /* __STDIO_BUFFERS */
+}
+libc_hidden_def(fflush_unlocked)
+
+#ifndef __UCLIBC_HAS_THREADS__
+strong_alias(fflush_unlocked,fflush)
+libc_hidden_def(fflush)
+#endif
+
+#elif defined __UCLIBC_HAS_THREADS__
+
+int fflush(register FILE *stream)
+{
+	int retval;
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	if (stream
+#ifdef __STDIO_HAS_OPENLIST
+		&& (stream != (FILE *) &_stdio_openlist)
+#endif
+		) {
+
+		__STDIO_AUTO_THREADLOCK(stream);
+
+		retval = fflush_unlocked(stream);
+
+		__STDIO_AUTO_THREADUNLOCK(stream);
+	} else {
+		retval = fflush_unlocked(stream);
+	}
+
+	return retval;
+}
+libc_hidden_def(fflush)
+
+#endif
diff --git a/ap/build/uClibc/libc/stdio/fflush_unlocked.c b/ap/build/uClibc/libc/stdio/fflush_unlocked.c
new file mode 100644
index 0000000..a6adb59
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fflush_unlocked.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define __DO_UNLOCKED
+#include "fflush.c"
diff --git a/ap/build/uClibc/libc/stdio/fgetc.c b/ap/build/uClibc/libc/stdio/fgetc.c
new file mode 100644
index 0000000..56a284c
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fgetc.c
@@ -0,0 +1,107 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+#undef fgetc
+#undef fgetc_unlocked
+#undef getc
+#undef getc_unlocked
+
+
+#ifdef __DO_UNLOCKED
+
+
+int __fgetc_unlocked(FILE *stream)
+{
+	__STDIO_STREAM_VALIDATE(stream);
+
+	/* First the fast path.  We're good to go if getc macro enabled. */
+	if (__STDIO_STREAM_CAN_USE_BUFFER_GET(stream)) {
+		return __STDIO_STREAM_BUFFER_GET(stream);
+	}
+
+	/* Next quickest... reading and narrow oriented, but macro
+	 * disabled and/or buffer is exhausted. */
+	if (__STDIO_STREAM_IS_NARROW_READING(stream)
+		|| !__STDIO_STREAM_TRANS_TO_READ(stream, __FLAG_NARROW)
+		) {
+		if (stream->__modeflags & __FLAG_UNGOT) { /* Use ungots first. */
+			unsigned char uc = stream->__ungot[(stream->__modeflags--) & 1];
+			stream->__ungot[1] = 0;
+			__STDIO_STREAM_VALIDATE(stream);
+			return uc;
+		}
+
+		if (__STDIO_STREAM_BUFFER_RAVAIL(stream)) {	/* Have buffered? */
+			return __STDIO_STREAM_BUFFER_GET(stream);
+		}
+
+		/* Is this a fake stream for *sscanf? */
+		if (__STDIO_STREAM_IS_FAKE_VSSCANF(stream)) {
+			__STDIO_STREAM_SET_EOF(stream);
+			return EOF;
+		}
+
+		/* We need to read from the host environment, so we must
+		 * flush all line buffered streams if the stream is not
+		 * fully buffered. */
+		if (!__STDIO_STREAM_IS_FBF(stream)) {
+			__STDIO_FLUSH_LBF_STREAMS;
+		}
+
+		if (__STDIO_STREAM_BUFFER_SIZE(stream)) { /* Do we have a buffer? */
+			__STDIO_STREAM_DISABLE_GETC(stream);
+			if(__STDIO_FILL_READ_BUFFER(stream)) {	/* Refill succeeded? */
+				__STDIO_STREAM_ENABLE_GETC(stream);	/* FBF or LBF */
+				return __STDIO_STREAM_BUFFER_GET(stream);
+			}
+		} else {
+			unsigned char uc;
+			if (__stdio_READ(stream, &uc, 1)) {
+				return uc;
+			}
+		}
+	}
+
+	return EOF;
+}
+libc_hidden_def(__fgetc_unlocked)
+
+strong_alias(__fgetc_unlocked,fgetc_unlocked)
+libc_hidden_def(fgetc_unlocked)
+
+strong_alias(__fgetc_unlocked,getc_unlocked)
+libc_hidden_def(getc_unlocked)
+
+#ifndef __UCLIBC_HAS_THREADS__
+strong_alias(__fgetc_unlocked,fgetc)
+libc_hidden_def(fgetc)
+
+strong_alias(__fgetc_unlocked,getc)
+#endif
+
+#elif defined __UCLIBC_HAS_THREADS__
+
+int fgetc(register FILE *stream)
+{
+	if (stream->__user_locking != 0) {
+		return __GETC_UNLOCKED_MACRO(stream);
+	} else {
+		int retval;
+		__STDIO_ALWAYS_THREADLOCK(stream);
+		retval = __GETC_UNLOCKED_MACRO(stream);
+		__STDIO_ALWAYS_THREADUNLOCK(stream);
+		return retval;
+	}
+}
+libc_hidden_def(fgetc)
+
+strong_alias(fgetc,getc)
+
+#endif
diff --git a/ap/build/uClibc/libc/stdio/fgetc_unlocked.c b/ap/build/uClibc/libc/stdio/fgetc_unlocked.c
new file mode 100644
index 0000000..a20c7ee
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fgetc_unlocked.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define __DO_UNLOCKED
+#include "fgetc.c"
diff --git a/ap/build/uClibc/libc/stdio/fgetpos.c b/ap/build/uClibc/libc/stdio/fgetpos.c
new file mode 100644
index 0000000..610737d
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fgetpos.c
@@ -0,0 +1,40 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+#ifndef __DO_LARGEFILE
+#define FTELL ftell
+#endif
+
+libc_hidden_proto(FTELL)
+
+int fgetpos(FILE * __restrict stream, register fpos_t * __restrict pos)
+{
+#ifdef __STDIO_MBSTATE
+
+	int retval = -1;
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	__STDIO_AUTO_THREADLOCK(stream);
+
+	if ((pos->__pos = FTELL(stream)) >= 0) {
+		__COPY_MBSTATE(&(pos->__mbstate), &(stream->__state));
+		pos->__mblen_pending = stream->__ungot_width[0];
+		retval = 0;
+	}
+
+	__STDIO_AUTO_THREADUNLOCK(stream);
+
+	return retval;
+
+#else
+
+	return ((pos->__pos = FTELL(stream)) >= 0) ? 0 : -1;
+
+#endif
+}
diff --git a/ap/build/uClibc/libc/stdio/fgetpos64.c b/ap/build/uClibc/libc/stdio/fgetpos64.c
new file mode 100644
index 0000000..32b7120
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fgetpos64.c
@@ -0,0 +1,14 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+#define __DO_LARGEFILE
+#define fgetpos	fgetpos64
+#define fpos_t        fpos64_t
+#define FTELL         ftello64
+#include "fgetpos.c"
diff --git a/ap/build/uClibc/libc/stdio/fgets.c b/ap/build/uClibc/libc/stdio/fgets.c
new file mode 100644
index 0000000..bc710c7
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fgets.c
@@ -0,0 +1,87 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+#ifdef __DO_UNLOCKED
+
+
+char *fgets_unlocked(char *__restrict s, int n,
+					   register FILE * __restrict stream)
+{
+	register char *p;
+	int c;
+
+	__STDIO_STREAM_VALIDATE(stream);
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning CONSIDER: What should fgets do if n <= 0?
+#endif /* __UCLIBC_MJN3_ONLY__ */
+	/* Should we assert here?  Or set errno?  Or just fail... */
+	if (n <= 0) {
+/* 		__set_errno(EINVAL); */
+		goto ERROR;
+	}
+
+	p = s;
+
+	while (--n) {
+		if (__STDIO_STREAM_CAN_USE_BUFFER_GET(stream)) {
+			if ((*p++ = __STDIO_STREAM_BUFFER_GET(stream)) == '\n') {
+				break;
+			}
+		} else {
+			if ((c = __fgetc_unlocked(stream)) == EOF) {
+				if (__FERROR_UNLOCKED(stream)) {
+					goto ERROR;
+				}
+				break;
+			}
+			if ((*p++ = c) == '\n') {
+				break;
+			}
+		}
+	}
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning CONSIDER: If n==1 and not at EOF, should fgets return an empty string?
+#endif /* __UCLIBC_MJN3_ONLY__ */
+	if (p > s) {
+		*p = 0;
+		return s;
+	}
+
+ ERROR:
+	return NULL;
+}
+libc_hidden_def(fgets_unlocked)
+
+#ifndef __UCLIBC_HAS_THREADS__
+strong_alias(fgets_unlocked,fgets)
+libc_hidden_def(fgets)
+#endif
+
+#elif defined __UCLIBC_HAS_THREADS__
+
+char *fgets(char *__restrict s, int n,
+			register FILE * __restrict stream)
+{
+	char *retval;
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	__STDIO_AUTO_THREADLOCK(stream);
+
+	retval = fgets_unlocked(s, n, stream);
+
+	__STDIO_AUTO_THREADUNLOCK(stream);
+
+	return retval;
+}
+libc_hidden_def(fgets)
+
+#endif
diff --git a/ap/build/uClibc/libc/stdio/fgets_unlocked.c b/ap/build/uClibc/libc/stdio/fgets_unlocked.c
new file mode 100644
index 0000000..db01913
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fgets_unlocked.c
@@ -0,0 +1,14 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include <features.h>
+
+#ifdef __USE_GNU
+# define __DO_UNLOCKED
+# include "fgets.c"
+#endif
diff --git a/ap/build/uClibc/libc/stdio/fgetwc.c b/ap/build/uClibc/libc/stdio/fgetwc.c
new file mode 100644
index 0000000..32d9e0e
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fgetwc.c
@@ -0,0 +1,138 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+
+#ifdef __DO_UNLOCKED
+
+static void munge_stream(register FILE *stream, unsigned char *buf)
+{
+	stream->__bufend = stream->__bufstart = buf;
+	__STDIO_STREAM_INIT_BUFREAD_BUFPOS(stream);
+	__STDIO_STREAM_DISABLE_GETC(stream);
+	__STDIO_STREAM_DISABLE_PUTC(stream);
+}
+
+wint_t fgetwc_unlocked(register FILE *stream)
+{
+	wint_t wi;
+	wchar_t wc[1];
+	int n;
+	size_t r;
+	unsigned char sbuf[1];
+
+	__STDIO_STREAM_VALIDATE(stream);
+
+	wi = WEOF;					/* Prepare for failure. */
+
+	if (__STDIO_STREAM_IS_WIDE_READING(stream)
+		|| !__STDIO_STREAM_TRANS_TO_READ(stream, __FLAG_WIDE)
+		) {
+		if (stream->__modeflags & __FLAG_UNGOT) { /* Any ungetwc()s? */
+			if (((stream->__modeflags & 1) || stream->__ungot[1])) {
+				stream->__ungot_width[0] = 0;	/* Application ungot... */
+			} else {			/* scanf ungot */
+				stream->__ungot_width[0] = stream->__ungot_width[1];
+			}
+
+			wi = stream->__ungot[(stream->__modeflags--) & 1];
+			stream->__ungot[1] = 0;
+			goto DONE;
+		}
+
+		if (!stream->__bufstart) {	/* Ugh... stream isn't buffered! */
+			/* Munge the stream temporarily to use a 1-byte buffer. */
+			munge_stream(stream, sbuf);
+			++stream->__bufend;
+		}
+
+		if (stream->__state.__mask == 0) { /* If last was a complete char */
+			stream->__ungot_width[0] = 0; /* then reset the width. */
+		}
+
+ LOOP:
+		if ((n = __STDIO_STREAM_BUFFER_RAVAIL(stream)) == 0) {
+			goto FILL_BUFFER;
+		}
+
+		r = mbrtowc(wc, (const char*) stream->__bufpos, n, &stream->__state);
+		if (((ssize_t) r) >= 0) { /* Success... */
+			if (r == 0) { /* Nul wide char... means 0 byte for us so */
+				++r;	 /* increment r and handle below as single. */
+			}
+			stream->__bufpos += r;
+			stream->__ungot_width[0] += r;
+			wi = *wc;
+			goto DONE;
+		}
+
+		if (r == ((size_t) -2)) {
+			/* Potentially valid but incomplete and no more buffered. */
+			stream->__bufpos += n; /* Update bufpos for stream. */
+			stream->__ungot_width[0] += n;
+ FILL_BUFFER:
+			if(__STDIO_FILL_READ_BUFFER(stream)) { /* Refill succeeded? */
+				goto LOOP;
+			}
+			if (!__FERROR_UNLOCKED(stream)) { /* EOF with no error. */
+				if (!stream->__state.__mask) { /* No partial wchar. */
+					goto DONE;
+				}
+				/* EOF but partially complete wchar. */
+				/* TODO: should EILSEQ be set? */
+				__set_errno(EILSEQ);
+			}
+		}
+
+		/* If we reach here, either r == ((size_t)-1) and mbrtowc set errno
+		 * to EILSEQ, or r == ((size_t)-2) and stream is in an error state
+		 * or at EOF with a partially complete wchar.  Make sure stream's
+		 * error indicator is set. */
+		stream->__modeflags |= __FLAG_ERROR;
+
+ DONE:
+		if (stream->__bufstart == sbuf) { /* Need to un-munge the stream. */
+			munge_stream(stream, NULL);
+		}
+
+	}
+
+	__STDIO_STREAM_VALIDATE(stream);
+
+	return wi;
+}
+libc_hidden_def(fgetwc_unlocked)
+
+strong_alias(fgetwc_unlocked,getwc_unlocked)
+#ifndef __UCLIBC_HAS_THREADS__
+strong_alias(fgetwc_unlocked,fgetwc)
+libc_hidden_def(fgetwc)
+
+strong_alias(fgetwc_unlocked,getwc)
+#endif
+
+#elif defined __UCLIBC_HAS_THREADS__
+
+wint_t fgetwc(register FILE *stream)
+{
+	wint_t retval;
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	__STDIO_AUTO_THREADLOCK(stream);
+
+	retval = fgetwc_unlocked(stream);
+
+	__STDIO_AUTO_THREADUNLOCK(stream);
+
+	return retval;
+}
+libc_hidden_def(fgetwc)
+
+strong_alias(fgetwc,getwc)
+#endif
diff --git a/ap/build/uClibc/libc/stdio/fgetwc_unlocked.c b/ap/build/uClibc/libc/stdio/fgetwc_unlocked.c
new file mode 100644
index 0000000..8eab843
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fgetwc_unlocked.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define __DO_UNLOCKED
+#include "fgetwc.c"
diff --git a/ap/build/uClibc/libc/stdio/fgetws.c b/ap/build/uClibc/libc/stdio/fgetws.c
new file mode 100644
index 0000000..b59d74b
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fgetws.c
@@ -0,0 +1,60 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+
+#ifdef __DO_UNLOCKED
+
+wchar_t *fgetws_unlocked(wchar_t *__restrict ws, int n,
+						   FILE *__restrict stream)
+{
+	register wchar_t *p = ws;
+	wint_t wi;
+
+	__STDIO_STREAM_VALIDATE(stream);
+
+	while ((n > 1)
+		   && ((wi = fgetwc_unlocked(stream)) != WEOF)
+		   && ((*p++ = wi) != '\n')
+		   ) {
+		--n;
+	}
+	if (p == ws) {
+		/* TODO -- should we set errno? */
+/*  		if (n <= 0) { */
+/*  			errno = EINVAL; */
+/*  		} */
+		return NULL;
+	}
+	*p = 0;
+	return ws;
+}
+libc_hidden_def(fgetws_unlocked)
+
+#ifndef __UCLIBC_HAS_THREADS__
+strong_alias(fgetws_unlocked,fgetws)
+#endif
+
+#elif defined __UCLIBC_HAS_THREADS__
+
+wchar_t *fgetws(wchar_t *__restrict ws, int n, FILE *__restrict stream)
+{
+	wchar_t *retval;
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	__STDIO_AUTO_THREADLOCK(stream);
+
+	retval = fgetws_unlocked(ws, n, stream);
+
+	__STDIO_AUTO_THREADUNLOCK(stream);
+
+	return retval;
+}
+
+#endif
diff --git a/ap/build/uClibc/libc/stdio/fgetws_unlocked.c b/ap/build/uClibc/libc/stdio/fgetws_unlocked.c
new file mode 100644
index 0000000..6dd58f2
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fgetws_unlocked.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define __DO_UNLOCKED
+#include "fgetws.c"
diff --git a/ap/build/uClibc/libc/stdio/fileno.c b/ap/build/uClibc/libc/stdio/fileno.c
new file mode 100644
index 0000000..452572b
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fileno.c
@@ -0,0 +1,48 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+#ifdef __DO_UNLOCKED
+
+int fileno_unlocked(register FILE *stream)
+{
+	__STDIO_STREAM_VALIDATE(stream);
+
+	if ((!__STDIO_STREAM_IS_CUSTOM(stream)) && (stream->__filedes >= 0)) {
+		return stream->__filedes;
+	}
+
+	__set_errno(EBADF);
+	return -1;
+}
+libc_hidden_def(fileno_unlocked)
+
+#ifndef __UCLIBC_HAS_THREADS__
+strong_alias(fileno_unlocked,fileno)
+libc_hidden_def(fileno)
+#endif
+
+#elif defined __UCLIBC_HAS_THREADS__
+
+int fileno(register FILE *stream)
+{
+	int retval;
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	__STDIO_AUTO_THREADLOCK(stream);
+
+	retval = fileno_unlocked(stream);
+
+	__STDIO_AUTO_THREADUNLOCK(stream);
+
+	return retval;
+}
+libc_hidden_def(fileno)
+
+#endif
diff --git a/ap/build/uClibc/libc/stdio/fileno_unlocked.c b/ap/build/uClibc/libc/stdio/fileno_unlocked.c
new file mode 100644
index 0000000..e500592
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fileno_unlocked.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define __DO_UNLOCKED
+#include "fileno.c"
diff --git a/ap/build/uClibc/libc/stdio/flockfile.c b/ap/build/uClibc/libc/stdio/flockfile.c
new file mode 100644
index 0000000..3fad711
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/flockfile.c
@@ -0,0 +1,16 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+void flockfile(FILE *stream)
+{
+	__STDIO_STREAM_VALIDATE(stream);
+
+	__STDIO_ALWAYS_THREADLOCK_CANCEL_UNSAFE(stream);
+}
+
diff --git a/ap/build/uClibc/libc/stdio/fmemopen.c b/ap/build/uClibc/libc/stdio/fmemopen.c
new file mode 100644
index 0000000..4a67376
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fmemopen.c
@@ -0,0 +1,181 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include <features.h>
+
+#ifdef __USE_GNU
+#include "_stdio.h"
+
+
+#ifndef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
+#error no custom streams!
+#endif
+
+typedef struct {
+	size_t pos;
+	size_t len;
+	size_t eof;
+	int dynbuf;
+	unsigned char *buf;
+	FILE *fp;
+} __fmo_cookie;
+
+#define COOKIE ((__fmo_cookie *) cookie)
+
+static ssize_t fmo_read(register void *cookie, char *buf, size_t bufsize)
+{
+	size_t count = COOKIE->len - COOKIE->pos;
+
+	/* Note: 0 < bufsize < SSIZE_MAX because of _stdio_READ. */
+	if (!count) {				/* EOF! */
+		return 0;
+	}
+
+	if (bufsize > count) {
+		bufsize = count;
+	}
+
+	memcpy(buf, COOKIE->buf + COOKIE->pos, bufsize);
+	COOKIE->pos += bufsize;
+
+	return bufsize;
+}
+
+static ssize_t fmo_write(register void *cookie, const char *buf, size_t bufsize)
+{
+	size_t count;
+
+	/* Note: bufsize < SSIZE_MAX because of _stdio_WRITE. */
+
+	/* If appending, need to seek to end of file!!!! */
+	if (COOKIE->fp->__modeflags & __FLAG_APPEND) {
+		COOKIE->pos = COOKIE->eof;
+	}
+
+	count = COOKIE->len - COOKIE->pos;
+
+	if (bufsize > count) {
+		bufsize = count;
+		if (count == 0) {		/* We're at the end of the buffer... */
+			__set_errno(EFBIG);
+			return -1;
+		}
+	}
+
+	memcpy(COOKIE->buf + COOKIE->pos, buf, bufsize);
+	COOKIE->pos += bufsize;
+
+	if (COOKIE->pos > COOKIE->eof) {
+		COOKIE->eof = COOKIE->pos;
+		if (bufsize < count) {	/* New eof and still room in buffer? */
+			*(COOKIE->buf + COOKIE->pos) = 0;
+		}
+	}
+
+	return bufsize;
+}
+
+/* glibc doesn't allow seeking, but it has in-buffer seeks... we don't. */
+static int fmo_seek(register void *cookie, __offmax_t *pos, int whence)
+{
+	__offmax_t p = *pos;
+
+	/* Note: fseek already checks that whence is legal, so don't check here
+	 * unless debugging. */
+	assert(((unsigned int) whence) <= 2);
+
+	if (whence != SEEK_SET) {
+		p += (whence == SEEK_CUR) ? COOKIE->pos : /* SEEK_END */ COOKIE->eof;
+	}
+
+	/* Note: glibc only allows seeking in the buffer.  We'll actually restrict
+	 * to the data. */
+	/* Check for offset < 0, offset > eof, or offset overflow... */
+	if (((uintmax_t) p) > COOKIE->eof) {
+		return -1;
+	}
+
+	COOKIE->pos = *pos = p;
+	return 0;
+}
+
+static int fmo_close(register void *cookie)
+{
+	if (COOKIE->dynbuf) {
+		free(COOKIE->buf);
+	}
+	free(cookie);
+	return 0;
+}
+
+#undef COOKIE
+
+static const cookie_io_functions_t _fmo_io_funcs = {
+	fmo_read, fmo_write, fmo_seek, fmo_close
+};
+
+/* TODO: If we have buffers enabled, it might be worthwile to add a pointer
+ * to the FILE in the cookie and have read, write, and seek operate directly
+ * on the buffer itself (ie replace the FILE buffer with the cookie buffer
+ * and update FILE bufstart, etc. whenever we seek). */
+
+FILE *fmemopen(void *s, size_t len, const char *modes)
+{
+	FILE *fp;
+	register __fmo_cookie *cookie;
+	size_t i;
+
+	if ((cookie = malloc(sizeof(__fmo_cookie))) != NULL) {
+		cookie->len = len;
+		cookie->eof = cookie->pos = 0; /* pos and eof adjusted below. */
+		cookie->dynbuf = 0;
+		if (((cookie->buf = s) == NULL) && (len > 0)) {
+			if ((cookie->buf = malloc(len)) == NULL) {
+				goto EXIT_cookie;
+			}
+			cookie->dynbuf = 1;
+			*cookie->buf = 0;	/* If we're appending, treat as empty file. */
+		}
+
+#ifndef __BCC__
+		fp = fopencookie(cookie, modes, _fmo_io_funcs);
+#else
+		fp = fopencookie(cookie, modes, &_fmo_io_funcs);
+#endif
+		/* Note: We don't need to worry about locking fp in the thread case
+		 * as the only possible access would be a close or flush with
+		 * nothing currently in the FILE's write buffer. */
+
+		if (fp != NULL) {
+			cookie->fp = fp;
+			if (fp->__modeflags & __FLAG_READONLY) {
+				cookie->eof = len;
+			}
+			if ((fp->__modeflags & __FLAG_APPEND) && (len > 0)) {
+				for (i = 0 ; i < len ; i++) {
+					if (cookie->buf[i] == 0) {
+						break;
+					}
+				}
+				cookie->eof = cookie->pos = i; /* Adjust eof and pos. */
+			}
+
+			__STDIO_STREAM_VALIDATE(fp);
+
+			return fp;
+		}
+	}
+
+	if (!s) {
+		free(cookie->buf);
+	}
+ EXIT_cookie:
+	free(cookie);
+
+	return NULL;
+}
+#endif
diff --git a/ap/build/uClibc/libc/stdio/fopen.c b/ap/build/uClibc/libc/stdio/fopen.c
new file mode 100644
index 0000000..a2d6617
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fopen.c
@@ -0,0 +1,21 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+#ifndef __DO_LARGEFILE
+# define FILEDES_ARG    (-1)
+# undef fopen
+#else
+# undef fopen64
+#endif
+
+FILE *fopen(const char * __restrict filename, const char * __restrict mode)
+{
+	return _stdio_fopen(((intptr_t) filename), mode, NULL, FILEDES_ARG);
+}
+libc_hidden_def(fopen)
diff --git a/ap/build/uClibc/libc/stdio/fopen64.c b/ap/build/uClibc/libc/stdio/fopen64.c
new file mode 100644
index 0000000..cbdb03d
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fopen64.c
@@ -0,0 +1,14 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+#define __DO_LARGEFILE
+#undef fopen
+#define fopen         fopen64
+#define FILEDES_ARG   (-2)
+#include "fopen.c"
diff --git a/ap/build/uClibc/libc/stdio/fopencookie.c b/ap/build/uClibc/libc/stdio/fopencookie.c
new file mode 100644
index 0000000..c4927e0
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fopencookie.c
@@ -0,0 +1,66 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include <features.h>
+
+#ifdef __USE_GNU
+#include "_stdio.h"
+
+#ifndef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
+#error no custom streams!
+#endif
+
+/* NOTE: GLIBC difference!!! -- fopencookie
+ * According to the info pages, glibc allows seeking within buffers even if
+ * no seek function is supplied.  We don't. */
+
+/* NOTE: GLIBC difference!!! -- fopencookie
+ * When compiled without large file support, the offset pointer for the
+ * cookie_seek function is off_t * and not off64_t * as for glibc. */
+
+/* NOTE: GLIBC difference!!! -- fopencookie (bcc only)
+ * Since bcc doesn't support passing of structs, we define fopencookie as a
+ * macro in terms of _fopencookie which takes a struct * for the io functions
+ * instead.
+ */
+
+/* Currently no real reentrancy issues other than a possible double close(). */
+
+#ifndef __BCC__
+FILE *fopencookie(void * __restrict cookie, const char * __restrict mode,
+				  cookie_io_functions_t io_functions)
+#else
+FILE *_fopencookie(void * __restrict cookie, const char * __restrict mode,
+				   register cookie_io_functions_t *io_functions)
+#endif
+{
+	FILE *stream;
+
+	/* Fake an fdopen guaranteed to pass the _stdio_fopen basic agreement
+	 * check without an fcntl call. */
+	stream = _stdio_fopen(((intptr_t)(INT_MAX-1)), mode, NULL, INT_MAX);
+	if (stream) {
+		stream->__filedes = -1;
+#ifndef __BCC__
+		stream->__gcs = io_functions;
+#else
+		stream->__gcs.read  = io_functions->read;
+		stream->__gcs.write = io_functions->write;
+		stream->__gcs.seek  = io_functions->seek;
+		stream->__gcs.close = io_functions->close;
+#endif
+		stream->__cookie = cookie;
+
+		__STDIO_STREAM_VALIDATE(stream);
+	}
+
+	return stream;
+}
+#ifndef __BCC__
+libc_hidden_def(fopencookie)
+#endif
+#endif
diff --git a/ap/build/uClibc/libc/stdio/fprintf.c b/ap/build/uClibc/libc/stdio/fprintf.c
new file mode 100644
index 0000000..fb75495
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fprintf.c
@@ -0,0 +1,23 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+#include <stdarg.h>
+
+
+int fprintf(FILE * __restrict stream, const char * __restrict format, ...)
+{
+	va_list arg;
+	int rv;
+
+	va_start(arg, format);
+	rv = vfprintf(stream, format, arg);
+	va_end(arg);
+
+	return rv;
+}
+libc_hidden_def(fprintf)
diff --git a/ap/build/uClibc/libc/stdio/fputc.c b/ap/build/uClibc/libc/stdio/fputc.c
new file mode 100644
index 0000000..b49f868
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fputc.c
@@ -0,0 +1,106 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+#undef fputc
+#undef fputc_unlocked
+#undef putc
+#undef putc_unlocked
+
+
+#ifdef __DO_UNLOCKED
+
+int __fputc_unlocked(int c, register FILE *stream)
+{
+	__STDIO_STREAM_VALIDATE(stream);
+
+	/* First the fast path.  We're good to go if putc macro enabled. */
+	if (__STDIO_STREAM_CAN_USE_BUFFER_ADD(stream)) {
+		__STDIO_STREAM_BUFFER_ADD(stream, ((unsigned char) c));
+		return (unsigned char) c;
+	}
+
+	/* Next quickest... writing and narrow oriented, but macro
+	 * disabled and/or buffer is full. */
+	if (__STDIO_STREAM_IS_NARROW_WRITING(stream)
+		|| !__STDIO_STREAM_TRANS_TO_WRITE(stream, __FLAG_NARROW)
+		) {
+		if (__STDIO_STREAM_IS_FAKE_VSNPRINTF(stream)) {
+			return (unsigned char) c;
+		}
+
+		if (__STDIO_STREAM_BUFFER_SIZE(stream)) { /* Do we have a buffer? */
+			/* The buffer is full and/or the stream is line buffered. */
+			if (!__STDIO_STREAM_BUFFER_WAVAIL(stream) /* Buffer full? */
+				&& __STDIO_COMMIT_WRITE_BUFFER(stream) /* Commit failed! */
+				) {
+				goto BAD;
+			}
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning CONSIDER: Should we fail if the commit fails but we now have room?
+#endif
+
+			__STDIO_STREAM_BUFFER_ADD(stream, ((unsigned char) c));
+
+			if (__STDIO_STREAM_IS_LBF(stream)) {
+				if ((((unsigned char) c) == '\n')
+					&& __STDIO_COMMIT_WRITE_BUFFER(stream)) {
+					/* Commit failed! */
+					__STDIO_STREAM_BUFFER_UNADD(stream); /* Undo the write! */
+					goto BAD;
+				}
+			}
+		} else {
+			/* NOTE: Do not try to save space by moving uc to the top of
+			 * the file, as that dramaticly increases runtime. */
+			unsigned char uc = (unsigned char) c;
+			if (! __stdio_WRITE(stream, &uc, 1)) {
+				goto BAD;
+			}
+		}
+		return (unsigned char) c;
+	}
+
+ BAD:
+	return EOF;
+}
+libc_hidden_def(__fputc_unlocked)
+
+strong_alias(__fputc_unlocked,fputc_unlocked)
+libc_hidden_def(fputc_unlocked)
+
+strong_alias(__fputc_unlocked,putc_unlocked)
+libc_hidden_def(putc_unlocked)
+#ifndef __UCLIBC_HAS_THREADS__
+strong_alias(__fputc_unlocked,fputc)
+libc_hidden_def(fputc)
+
+strong_alias(__fputc_unlocked,putc)
+libc_hidden_def(putc)
+#endif
+
+#elif defined __UCLIBC_HAS_THREADS__
+
+int fputc(int c, register FILE *stream)
+{
+	if (stream->__user_locking != 0) {
+		return __PUTC_UNLOCKED_MACRO(c, stream);
+	} else {
+		int retval;
+		__STDIO_ALWAYS_THREADLOCK(stream);
+		retval = __PUTC_UNLOCKED_MACRO(c, stream);
+		__STDIO_ALWAYS_THREADUNLOCK(stream);
+		return retval;
+	}
+}
+libc_hidden_def(fputc)
+
+strong_alias(fputc,putc)
+libc_hidden_def(putc)
+
+#endif
diff --git a/ap/build/uClibc/libc/stdio/fputc_unlocked.c b/ap/build/uClibc/libc/stdio/fputc_unlocked.c
new file mode 100644
index 0000000..dc4c77a
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fputc_unlocked.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define __DO_UNLOCKED
+#include "fputc.c"
diff --git a/ap/build/uClibc/libc/stdio/fputs.c b/ap/build/uClibc/libc/stdio/fputs.c
new file mode 100644
index 0000000..b3ede68
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fputs.c
@@ -0,0 +1,50 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+
+/* Note: The standard says fputs returns a nonnegative number on
+ * success.  In this implementation, we return the length of the
+ * string written on success.
+ */
+
+#ifdef __DO_UNLOCKED
+
+int fputs_unlocked(register const char * __restrict s,
+					 FILE * __restrict stream)
+{
+	size_t n = strlen(s);
+
+	return ((fwrite_unlocked(s, 1, n, stream) == n) ? n : EOF);
+}
+libc_hidden_def(fputs_unlocked)
+
+#ifndef __UCLIBC_HAS_THREADS__
+strong_alias(fputs_unlocked,fputs)
+libc_hidden_def(fputs)
+#endif
+
+#elif defined __UCLIBC_HAS_THREADS__
+
+int fputs(const char * __restrict s, register FILE * __restrict stream)
+{
+	int retval;
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	__STDIO_AUTO_THREADLOCK(stream);
+
+	retval = fputs_unlocked(s, stream);
+
+	__STDIO_AUTO_THREADUNLOCK(stream);
+
+	return retval;
+}
+libc_hidden_def(fputs)
+
+#endif
diff --git a/ap/build/uClibc/libc/stdio/fputs_unlocked.c b/ap/build/uClibc/libc/stdio/fputs_unlocked.c
new file mode 100644
index 0000000..c7ff3f5
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fputs_unlocked.c
@@ -0,0 +1,14 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include <features.h>
+
+#ifdef __USE_GNU
+# define __DO_UNLOCKED
+# include "fputs.c"
+#endif
diff --git a/ap/build/uClibc/libc/stdio/fputwc.c b/ap/build/uClibc/libc/stdio/fputwc.c
new file mode 100644
index 0000000..7f46f48
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fputwc.c
@@ -0,0 +1,43 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+#ifdef __DO_UNLOCKED
+
+wint_t fputwc_unlocked(wchar_t wc, FILE *stream)
+{
+	return _wstdio_fwrite(&wc, 1, stream) ? wc : WEOF;
+}
+libc_hidden_def(fputwc_unlocked)
+
+strong_alias(fputwc_unlocked,putwc_unlocked)
+#ifndef __UCLIBC_HAS_THREADS__
+strong_alias(fputwc_unlocked,fputwc)
+strong_alias(fputwc_unlocked,putwc)
+#endif
+
+#elif defined __UCLIBC_HAS_THREADS__
+
+wint_t fputwc(wchar_t wc, register FILE *stream)
+{
+	wint_t retval;
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	__STDIO_AUTO_THREADLOCK(stream);
+
+	retval = fputwc_unlocked(wc, stream);
+
+	__STDIO_AUTO_THREADUNLOCK(stream);
+
+	return retval;
+}
+
+strong_alias(fputwc,putwc)
+
+#endif
diff --git a/ap/build/uClibc/libc/stdio/fputwc_unlocked.c b/ap/build/uClibc/libc/stdio/fputwc_unlocked.c
new file mode 100644
index 0000000..757cbd0
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fputwc_unlocked.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define __DO_UNLOCKED
+#include "fputwc.c"
diff --git a/ap/build/uClibc/libc/stdio/fputws.c b/ap/build/uClibc/libc/stdio/fputws.c
new file mode 100644
index 0000000..7a18921
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fputws.c
@@ -0,0 +1,45 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+
+#ifdef __DO_UNLOCKED
+
+int fputws_unlocked(const wchar_t *__restrict ws,
+					  register FILE *__restrict stream)
+{
+	size_t n = wcslen(ws);
+
+	return (_wstdio_fwrite(ws, n, stream) == n) ? 0 : -1;
+}
+libc_hidden_def(fputws_unlocked)
+
+#ifndef __UCLIBC_HAS_THREADS__
+strong_alias(fputws_unlocked,fputws)
+libc_hidden_def(fputws)
+#endif
+
+#elif defined __UCLIBC_HAS_THREADS__
+
+int fputws(const wchar_t *__restrict ws, register FILE *__restrict stream)
+{
+	int retval;
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	__STDIO_AUTO_THREADLOCK(stream);
+
+	retval = fputws_unlocked(ws, stream);
+
+	__STDIO_AUTO_THREADUNLOCK(stream);
+
+	return retval;
+}
+libc_hidden_def(fputws)
+
+#endif
diff --git a/ap/build/uClibc/libc/stdio/fputws_unlocked.c b/ap/build/uClibc/libc/stdio/fputws_unlocked.c
new file mode 100644
index 0000000..b3a0377
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fputws_unlocked.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define __DO_UNLOCKED
+#include "fputws.c"
diff --git a/ap/build/uClibc/libc/stdio/fread.c b/ap/build/uClibc/libc/stdio/fread.c
new file mode 100644
index 0000000..d2fcc70
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fread.c
@@ -0,0 +1,112 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+#ifdef __DO_UNLOCKED
+
+
+size_t fread_unlocked(void * __restrict ptr, size_t size, size_t nmemb,
+						FILE * __restrict stream)
+{
+	__STDIO_STREAM_VALIDATE(stream);
+	assert(stream->__filedes >= -1);
+
+	/* Note: If nmbem * size > SIZE_MAX then there is an application
+	 * bug since no array can be larger than SIZE_MAX in size. */
+
+	if ((__STDIO_STREAM_IS_NARROW_READING(stream)
+		 || !__STDIO_STREAM_TRANS_TO_READ(stream, __FLAG_NARROW))
+		&& size && nmemb
+		) {
+
+		if (nmemb <= (SIZE_MAX / size)) {
+			unsigned char *buffer = (unsigned char *) ptr;
+			size_t todo, bytes, avail;
+
+			todo = bytes = size * nmemb;
+
+			/* Check for ungots... */
+			while (stream->__modeflags & __FLAG_UNGOT) {
+				*buffer++ = stream->__ungot[(stream->__modeflags--) & 1];
+				stream->__ungot[1] = 0;
+				if (!--todo) {
+					goto DONE;
+				}
+			}
+
+#ifdef __STDIO_BUFFERS
+			/* Next check for available buffered... */
+			if ((avail = stream->__bufread - stream->__bufpos) > 0) {
+				if (avail > todo) {
+					avail = todo;
+				}
+				memcpy(buffer, stream->__bufpos, avail);
+				buffer += avail;
+				stream->__bufpos += avail;
+				if (!(todo -= avail)) {
+					goto DONE;
+				}
+			}
+
+			/* We need to read from the host environment, so we must
+			 * flush all line buffered streams if the stream is not
+			 * fully buffered. */
+			if (!__STDIO_STREAM_IS_FBF(stream)) {
+				__STDIO_FLUSH_LBF_STREAMS;
+			}
+#endif
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning CONSIDER: should we refill and read from the buffer sometimes?
+#endif
+			while ((avail = __stdio_READ(stream, buffer, todo)) > 0) {
+				buffer += avail;
+				if (!(todo -= avail)) {
+					break;
+				}
+			}
+
+		DONE:
+			__STDIO_STREAM_VALIDATE(stream);
+			return (bytes - todo) / size;
+		}
+
+		__STDIO_STREAM_SET_ERROR(stream);
+		__set_errno(EINVAL);
+	}
+
+	__STDIO_STREAM_VALIDATE(stream);
+	return 0;
+}
+libc_hidden_def(fread_unlocked)
+
+#ifndef __UCLIBC_HAS_THREADS__
+strong_alias(fread_unlocked,fread)
+libc_hidden_def(fread)
+#endif
+
+#elif defined __UCLIBC_HAS_THREADS__
+
+size_t fread(void * __restrict ptr, size_t size, size_t nmemb,
+			 register FILE * __restrict stream)
+{
+	size_t retval;
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	__STDIO_AUTO_THREADLOCK(stream);
+
+	retval = fread_unlocked(ptr, size, nmemb, stream);
+
+	__STDIO_AUTO_THREADUNLOCK(stream);
+
+	return retval;
+}
+libc_hidden_def(fread)
+
+#endif
diff --git a/ap/build/uClibc/libc/stdio/fread_unlocked.c b/ap/build/uClibc/libc/stdio/fread_unlocked.c
new file mode 100644
index 0000000..441edbb
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fread_unlocked.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define __DO_UNLOCKED
+#include "fread.c"
diff --git a/ap/build/uClibc/libc/stdio/freopen.c b/ap/build/uClibc/libc/stdio/freopen.c
new file mode 100644
index 0000000..f48a43b
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/freopen.c
@@ -0,0 +1,75 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+#ifndef __DO_LARGEFILE
+# define FILEDES_ARG    (-1)
+#endif
+
+FILE *freopen(const char * __restrict filename, const char * __restrict mode,
+			  register FILE * __restrict stream)
+{
+	/*
+	 * ANSI/ISO allow (implementation-defined) change of mode for an
+	 * existing file if filename is NULL.  It doesn't look like Linux
+	 * supports this, so we don't here.
+	 *
+	 * NOTE: Whether or not the stream is free'd on failure is unclear
+	 *       w.r.t. ANSI/ISO.  This implementation chooses to NOT free
+	 *       the stream and associated buffer if they were dynamically
+	 *       allocated.
+	 * NOTE: Previous versions of uClibc did free dynamic storage.
+	 *
+	 * TODO: Apparently linux allows setting append mode.  Implement?
+	 */
+	unsigned short dynmode;
+	register FILE *fp;
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	__STDIO_AUTO_THREADLOCK(stream);
+
+	__STDIO_STREAM_VALIDATE(stream);
+
+	__STDIO_OPENLIST_INC_USE;	/* Do not remove the file from the list. */
+
+	/* First, flush and close, but don't deallocate, the stream. */
+	/* This also removes the stream for the open file list. */
+	dynmode = (stream->__modeflags & (__FLAG_FREEBUF|__FLAG_FREEFILE));
+
+	stream->__modeflags &= ~(__FLAG_FREEBUF|__FLAG_FREEFILE);
+
+	/* Only call fclose on the stream if it is not already closed. */
+	if ((stream->__modeflags & (__FLAG_READONLY|__FLAG_WRITEONLY))
+		!= (__FLAG_READONLY|__FLAG_WRITEONLY)
+		) {
+		fclose(stream);			/* Failures are ignored. */
+		/* NOTE: fclose always does __STDIO_OPENLIST_INC_DEL_CNT.  But we don't
+		 * want to remove this FILE from the open list, even if the freopen fails.
+		 * Consider the case of a failed freopen() on stdin.  You probably still
+		 * want to be able to call freopen() again.  Similarly for other "malloc'd"
+		 * streams. */
+		__STDIO_OPENLIST_DEC_DEL_CNT;
+	}
+
+	fp = _stdio_fopen(((intptr_t) filename), mode, stream, FILEDES_ARG);
+	if (!fp) {
+		/* Don't remove stream from the open file list and (potentially) free it.
+		 * See _stdio_openlist_dec_use() in fflush.c. */
+		stream->__modeflags = __FLAG_READONLY|__FLAG_WRITEONLY|__FLAG_FAILED_FREOPEN;
+	}
+
+	/* Reset the allocation flags. */
+	stream->__modeflags |= dynmode;
+
+	__STDIO_OPENLIST_DEC_USE;
+
+	__STDIO_AUTO_THREADUNLOCK(stream);
+
+	return fp;
+}
diff --git a/ap/build/uClibc/libc/stdio/freopen64.c b/ap/build/uClibc/libc/stdio/freopen64.c
new file mode 100644
index 0000000..e44c972
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/freopen64.c
@@ -0,0 +1,13 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+#define __DO_LARGEFILE
+#define freopen       freopen64
+#define FILEDES_ARG   (-2)
+#include "freopen.c"
diff --git a/ap/build/uClibc/libc/stdio/fscanf.c b/ap/build/uClibc/libc/stdio/fscanf.c
new file mode 100644
index 0000000..102cb8d
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fscanf.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define L_fscanf
+#include "_scanf.c"
diff --git a/ap/build/uClibc/libc/stdio/fseeko.c b/ap/build/uClibc/libc/stdio/fseeko.c
new file mode 100644
index 0000000..3caf1ac
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fseeko.c
@@ -0,0 +1,81 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+#if SEEK_SET != 0 || SEEK_CUR != 1 || SEEK_END != 2
+# error Assumption violated -- values of SEEK_SET, SEEK_CUR, SEEK_END
+#endif
+
+#ifndef __DO_LARGEFILE
+# define FSEEK         fseek
+# define OFFSET_TYPE   long int
+#endif
+
+int FSEEK(register FILE *stream, OFFSET_TYPE offset, int whence)
+{
+#if defined(__UCLIBC_HAS_LFS__) && !defined(__DO_LARGEFILE)
+
+	return fseeko64(stream, offset, whence);
+
+#else
+
+	__offmax_t pos = offset;
+	int retval = -1;
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	if (((unsigned int) whence) > 2) {
+		__set_errno(EINVAL);
+	} else {
+		__STDIO_AUTO_THREADLOCK(stream);
+
+		__STDIO_STREAM_VALIDATE(stream);
+
+		if ((!__STDIO_STREAM_IS_WRITING(stream)
+			  || !__STDIO_COMMIT_WRITE_BUFFER(stream))
+			&& ((whence != SEEK_CUR)
+				 || (__stdio_adjust_position(stream, &pos) >= 0))
+			&& (__SEEK(stream, &pos, whence) >= 0)
+			) {
+
+			/* Clear reading/writing modes, EOF, and ungots. */
+			stream->__modeflags &=
+				~(__MASK_READING|__FLAG_WRITING|__FLAG_EOF);
+
+			/* Make sure all pointers are reset. */
+			__STDIO_STREAM_INIT_BUFREAD_BUFPOS(stream);
+			__STDIO_STREAM_DISABLE_GETC(stream);
+			__STDIO_STREAM_DISABLE_PUTC(stream);
+
+			/* We reinitialize the mbstate object.  Doing so is
+			 * implementation defined behavior. */
+#ifdef __STDIO_MBSTATE
+			__INIT_MBSTATE(&(stream->__state));
+#endif
+#ifdef __UCLIBC_HAS_WCHAR__
+			stream->__ungot_width[0] = 0;
+#endif
+
+			retval = 0;
+		}
+
+		__STDIO_STREAM_VALIDATE(stream);
+
+		__STDIO_AUTO_THREADUNLOCK(stream);
+	}
+
+	return retval;
+
+#endif
+}
+
+#ifdef __DO_LARGEFILE
+libc_hidden_def(fseeko64)
+#else
+libc_hidden_def(fseek)
+strong_alias(fseek,fseeko)
+#endif
diff --git a/ap/build/uClibc/libc/stdio/fseeko64.c b/ap/build/uClibc/libc/stdio/fseeko64.c
new file mode 100644
index 0000000..78cab1b
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fseeko64.c
@@ -0,0 +1,13 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+#define __DO_LARGEFILE
+#define FSEEK         fseeko64
+#define OFFSET_TYPE   __off64_t
+#include "fseeko.c"
diff --git a/ap/build/uClibc/libc/stdio/fsetpos.c b/ap/build/uClibc/libc/stdio/fsetpos.c
new file mode 100644
index 0000000..d63adc0
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fsetpos.c
@@ -0,0 +1,39 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+#ifndef __DO_LARGEFILE
+#define FSEEK fseek
+#endif
+
+libc_hidden_proto(FSEEK)
+
+int fsetpos(FILE *stream, register const fpos_t *pos)
+{
+#ifdef __STDIO_MBSTATE
+
+	int retval = -1;
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	__STDIO_AUTO_THREADLOCK(stream);
+
+	if ((retval = FSEEK(stream, pos->__pos, SEEK_SET)) == 0) {
+		__COPY_MBSTATE(&(stream->__state), &(pos->__mbstate));
+		stream->__ungot_width[0]= pos->__mblen_pending;
+	}
+
+	__STDIO_AUTO_THREADUNLOCK(stream);
+
+	return retval;
+
+#else
+
+	return FSEEK(stream, pos->__pos, SEEK_SET);
+
+#endif
+}
diff --git a/ap/build/uClibc/libc/stdio/fsetpos64.c b/ap/build/uClibc/libc/stdio/fsetpos64.c
new file mode 100644
index 0000000..82819a4
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fsetpos64.c
@@ -0,0 +1,14 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+#define __DO_LARGEFILE
+#define fsetpos	fsetpos64
+#define fpos_t        fpos64_t
+#define FSEEK         fseeko64
+#include "fsetpos.c"
diff --git a/ap/build/uClibc/libc/stdio/ftello.c b/ap/build/uClibc/libc/stdio/ftello.c
new file mode 100644
index 0000000..e8ff365
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/ftello.c
@@ -0,0 +1,57 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+#ifndef __DO_LARGEFILE
+# define FTELL         ftell
+# define OFFSET_TYPE   long int
+#endif
+
+OFFSET_TYPE FTELL(register FILE *stream)
+{
+#if defined(__UCLIBC_HAS_LFS__) && !defined(__DO_LARGEFILE)
+
+	__offmax_t pos = ftello64(stream);
+
+	if ((sizeof(long) >= sizeof(__offmax_t)) || (((long) pos) == pos)) {
+		return ((long) pos);
+	} else {
+		__set_errno(EOVERFLOW);
+		return -1;
+	}
+
+#else
+
+	__offmax_t pos = 0;
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	__STDIO_AUTO_THREADLOCK(stream);
+
+	__STDIO_STREAM_VALIDATE(stream);
+
+	if ((__SEEK(stream, &pos,
+				((__STDIO_STREAM_IS_WRITING(stream)
+				  && (stream->__modeflags & __FLAG_APPEND))
+				 ? SEEK_END : SEEK_CUR)) < 0)
+		|| (__stdio_adjust_position(stream, &pos) < 0)) {
+		pos = -1;
+	}
+
+	__STDIO_AUTO_THREADUNLOCK(stream);
+
+	return pos;
+
+#endif
+}
+
+#ifdef __DO_LARGEFILE
+libc_hidden_def(ftello64)
+#else
+libc_hidden_def(ftell)
+strong_alias(ftell,ftello)
+#endif
diff --git a/ap/build/uClibc/libc/stdio/ftello64.c b/ap/build/uClibc/libc/stdio/ftello64.c
new file mode 100644
index 0000000..905834f
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/ftello64.c
@@ -0,0 +1,13 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+#define __DO_LARGEFILE
+#define FTELL         ftello64
+#define OFFSET_TYPE   __off64_t
+#include "ftello.c"
diff --git a/ap/build/uClibc/libc/stdio/ftrylockfile.c b/ap/build/uClibc/libc/stdio/ftrylockfile.c
new file mode 100644
index 0000000..0d2e156
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/ftrylockfile.c
@@ -0,0 +1,19 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning CONSIDER: What should this return when not threading?
+#endif
+
+int ftrylockfile(FILE *stream)
+{
+	__STDIO_STREAM_VALIDATE(stream);
+
+	return __STDIO_ALWAYS_THREADTRYLOCK_CANCEL_UNSAFE(stream);
+}
diff --git a/ap/build/uClibc/libc/stdio/funlockfile.c b/ap/build/uClibc/libc/stdio/funlockfile.c
new file mode 100644
index 0000000..2ddf097
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/funlockfile.c
@@ -0,0 +1,15 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+void funlockfile(FILE *stream)
+{
+	__STDIO_STREAM_VALIDATE(stream);
+
+	__STDIO_ALWAYS_THREADUNLOCK_CANCEL_UNSAFE(stream);
+}
diff --git a/ap/build/uClibc/libc/stdio/fwide.c b/ap/build/uClibc/libc/stdio/fwide.c
new file mode 100644
index 0000000..422d789
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fwide.c
@@ -0,0 +1,32 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+/* TODO: According to SUSv3 should return EBADF if invalid stream. */
+
+int fwide(register FILE *stream, int mode)
+{
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	__STDIO_AUTO_THREADLOCK(stream);
+
+	__STDIO_STREAM_VALIDATE(stream);
+
+	if (mode && !(stream->__modeflags & (__FLAG_WIDE|__FLAG_NARROW))) {
+		stream->__modeflags |= ((mode > 0) ? __FLAG_WIDE : __FLAG_NARROW);
+	}
+
+	mode = (stream->__modeflags & __FLAG_WIDE)
+		- (stream->__modeflags & __FLAG_NARROW);
+
+	assert((stream->__modeflags & (__FLAG_WIDE|__FLAG_NARROW))
+		   != (__FLAG_WIDE|__FLAG_NARROW));
+	__STDIO_AUTO_THREADUNLOCK(stream);
+
+	return mode;
+}
diff --git a/ap/build/uClibc/libc/stdio/fwprintf.c b/ap/build/uClibc/libc/stdio/fwprintf.c
new file mode 100644
index 0000000..9549708
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fwprintf.c
@@ -0,0 +1,23 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+#include <stdarg.h>
+#include <wchar.h>
+
+
+int fwprintf(FILE * __restrict stream, const wchar_t * __restrict format, ...)
+{
+	va_list arg;
+	int rv;
+
+	va_start(arg, format);
+	rv = vfwprintf(stream, format, arg);
+	va_end(arg);
+
+	return rv;
+}
diff --git a/ap/build/uClibc/libc/stdio/fwrite.c b/ap/build/uClibc/libc/stdio/fwrite.c
new file mode 100644
index 0000000..71793ff
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fwrite.c
@@ -0,0 +1,62 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+#ifdef __DO_UNLOCKED
+
+size_t fwrite_unlocked(const void * __restrict ptr, size_t size,
+						 size_t nmemb, register FILE * __restrict stream)
+{
+	__STDIO_STREAM_VALIDATE(stream);
+
+	/* Note: If nmbem * size > SIZE_MAX then there is an application
+	 * bug since no array can be larger than SIZE_MAX in size. */
+
+	if ((__STDIO_STREAM_IS_NARROW_WRITING(stream)
+		 || !__STDIO_STREAM_TRANS_TO_WRITE(stream, __FLAG_NARROW))
+		&& size && nmemb
+		) {
+
+		if (nmemb <= (SIZE_MAX / size)) {
+			return __stdio_fwrite((const unsigned char *) ptr,
+								  size*nmemb, stream) / size;
+		}
+
+		__STDIO_STREAM_SET_ERROR(stream);
+		__set_errno(EINVAL);
+	}
+
+	return 0;
+}
+libc_hidden_def(fwrite_unlocked)
+
+#ifndef __UCLIBC_HAS_THREADS__
+strong_alias(fwrite_unlocked,fwrite)
+libc_hidden_def(fwrite)
+#endif
+
+#elif defined __UCLIBC_HAS_THREADS__
+
+size_t fwrite(const void * __restrict ptr, size_t size,
+			  size_t nmemb, register FILE * __restrict stream)
+{
+	size_t retval;
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	__STDIO_AUTO_THREADLOCK(stream);
+
+	retval = fwrite_unlocked(ptr, size, nmemb, stream);
+
+	__STDIO_AUTO_THREADUNLOCK(stream);
+
+	return retval;
+}
+libc_hidden_def(fwrite)
+
+#endif
diff --git a/ap/build/uClibc/libc/stdio/fwrite_unlocked.c b/ap/build/uClibc/libc/stdio/fwrite_unlocked.c
new file mode 100644
index 0000000..0f9e026
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fwrite_unlocked.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define __DO_UNLOCKED
+#include "fwrite.c"
diff --git a/ap/build/uClibc/libc/stdio/fwscanf.c b/ap/build/uClibc/libc/stdio/fwscanf.c
new file mode 100644
index 0000000..3409d00
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/fwscanf.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define L_fwscanf
+#include "_scanf.c"
diff --git a/ap/build/uClibc/libc/stdio/getchar.c b/ap/build/uClibc/libc/stdio/getchar.c
new file mode 100644
index 0000000..b6c650c
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/getchar.c
@@ -0,0 +1,45 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+#undef getchar
+#ifdef __DO_UNLOCKED
+
+/* the only use of the hidden getchar_unlocked is in gets.c */
+#undef getchar_unlocked
+int getchar_unlocked(void)
+{
+	register FILE *stream = stdin;
+
+	return __GETC_UNLOCKED_MACRO(stream);
+}
+libc_hidden_def(getchar_unlocked)
+
+#ifndef __UCLIBC_HAS_THREADS__
+strong_alias(getchar_unlocked,getchar)
+#endif
+
+#elif defined __UCLIBC_HAS_THREADS__
+
+int getchar(void)
+{
+	register FILE *stream = stdin;
+
+	if (stream->__user_locking != 0) {
+		return __GETC_UNLOCKED_MACRO(stream);
+	} else {
+		int retval;
+		__STDIO_ALWAYS_THREADLOCK(stream);
+		retval = __GETC_UNLOCKED_MACRO(stream);
+		__STDIO_ALWAYS_THREADUNLOCK(stream);
+		return retval;
+	}
+}
+
+#endif
diff --git a/ap/build/uClibc/libc/stdio/getchar_unlocked.c b/ap/build/uClibc/libc/stdio/getchar_unlocked.c
new file mode 100644
index 0000000..60ea251
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/getchar_unlocked.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define __DO_UNLOCKED
+#include "getchar.c"
diff --git a/ap/build/uClibc/libc/stdio/getdelim.c b/ap/build/uClibc/libc/stdio/getdelim.c
new file mode 100644
index 0000000..987e32a
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/getdelim.c
@@ -0,0 +1,82 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include <features.h>
+
+#ifdef __USE_GNU
+#include "_stdio.h"
+
+
+
+/* Note: There is a defect in this function.  (size_t vs ssize_t). */
+
+/* glibc function --
+ * Return -1 if error or EOF prior to any chars read.
+ * Return number of chars read (including possible delimiter but not
+ *   the terminating nul) otherwise.
+ *
+ * NOTE: If we need to allocate a buffer, we do so prior to attempting
+ * a reading.  So space may be allocated even if initially at EOF.
+ */
+
+#define GETDELIM_GROWBY		64
+
+ssize_t getdelim(char **__restrict lineptr, size_t *__restrict n,
+				   int delimiter, register FILE *__restrict stream)
+{
+	register char *buf;
+	ssize_t pos = -1;
+	int c;
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	if (!lineptr || !n || !stream) { /* Be compatable with glibc... even */
+		__set_errno(EINVAL); /* though I think we should assert here */
+	} else {
+		__STDIO_AUTO_THREADLOCK(stream);
+
+		if (!(buf = *lineptr)) { /* If passed NULL for buffer, */
+			*n = 0;		/* ignore value passed and treat size as 0. */
+		}
+
+		/* Within the loop, pos is actually the current buffer index + 2,
+		 * because we want to make sure we have enough space to store
+		 * an additional char plus a nul terminator.
+		 */
+		pos = 1;
+
+		do {
+			if (pos >= *n) {
+				if (!(buf = realloc(buf, *n + GETDELIM_GROWBY))) {
+					pos = -1;
+					break;
+				}
+				*n += GETDELIM_GROWBY;
+				*lineptr = buf;
+			}
+
+			if ((c = __GETC_UNLOCKED(stream)) != EOF) {
+				buf[++pos - 2] = c;
+				if (c != delimiter) {
+					continue;
+				}
+			}
+
+			/* We're done, so correct pos back to being the current index. */
+			if ((pos -= 2) >= 0) {
+				buf[++pos] = 0;
+			}
+			break;
+
+		} while (1);
+
+		__STDIO_AUTO_THREADUNLOCK(stream);
+	}
+
+	return pos;
+}
+libc_hidden_def(getdelim)
+#endif
diff --git a/ap/build/uClibc/libc/stdio/getline.c b/ap/build/uClibc/libc/stdio/getline.c
new file mode 100644
index 0000000..98ce8d1
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/getline.c
@@ -0,0 +1,21 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include <features.h>
+
+#ifdef __USE_GNU
+#include "_stdio.h"
+
+
+
+ssize_t getline(char **__restrict lineptr, size_t *__restrict n,
+				FILE *__restrict stream)
+{
+	return getdelim(lineptr, n, '\n', stream);
+}
+libc_hidden_def(getline)
+#endif
diff --git a/ap/build/uClibc/libc/stdio/gets.c b/ap/build/uClibc/libc/stdio/gets.c
new file mode 100644
index 0000000..515e966
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/gets.c
@@ -0,0 +1,39 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+link_warning(gets, "the 'gets' function is dangerous and should not be used.")
+
+/* UNSAFE FUNCTION -- do not bother optimizing */
+
+/* disable macro, force actual function call */
+#undef getchar_unlocked
+
+char *gets(char *s)
+{
+	register char *p = s;
+	int c;
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	__STDIO_AUTO_THREADLOCK(stdin);
+
+	/* Note: don't worry about performance here... this shouldn't be used!
+	 * Therefore, force actual function call. */
+	while (((c = getchar_unlocked()) != EOF) && ((*p = c) != '\n')) {
+		++p;
+	}
+	if ((c == EOF) || (s == p)) {
+		s = NULL;
+	} else {
+		*p = 0;
+	}
+
+	__STDIO_AUTO_THREADUNLOCK(stdin);
+
+	return s;
+}
diff --git a/ap/build/uClibc/libc/stdio/getw.c b/ap/build/uClibc/libc/stdio/getw.c
new file mode 100644
index 0000000..625f17f
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/getw.c
@@ -0,0 +1,19 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+/* SUSv2 Legacy function -- need not be reentrant. */
+
+int getw(FILE *stream)
+{
+	int aw;
+
+	return (fread_unlocked((void *) &aw, sizeof(int), 1, stream) != 0)
+		? aw : EOF;
+}
diff --git a/ap/build/uClibc/libc/stdio/getwchar.c b/ap/build/uClibc/libc/stdio/getwchar.c
new file mode 100644
index 0000000..75266de
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/getwchar.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+#ifdef __DO_UNLOCKED
+
+
+wint_t getwchar_unlocked(void)
+{
+	return fgetwc_unlocked(stdin);
+}
+
+#ifndef __UCLIBC_HAS_THREADS__
+strong_alias(getwchar_unlocked,getwchar)
+#endif
+
+#elif defined __UCLIBC_HAS_THREADS__
+
+
+wint_t getwchar(void)
+{
+	return fgetwc(stdin);
+}
+
+#endif
diff --git a/ap/build/uClibc/libc/stdio/getwchar_unlocked.c b/ap/build/uClibc/libc/stdio/getwchar_unlocked.c
new file mode 100644
index 0000000..af4a9e8
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/getwchar_unlocked.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define __DO_UNLOCKED
+#include "getwchar.c"
diff --git a/ap/build/uClibc/libc/stdio/old_vfprintf.c b/ap/build/uClibc/libc/stdio/old_vfprintf.c
new file mode 100644
index 0000000..7d4bfea
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/old_vfprintf.c
@@ -0,0 +1,710 @@
+/*
+ * This file based on printf.c from 'Dlibs' on the atari ST  (RdeBath)
+ *
+ *
+ *    Dale Schumacher                         399 Beacon Ave.
+ *    (alias: Dalnefre')                      St. Paul, MN  55104
+ *    dal@syntel.UUCP                         United States of America
+ *  "It's not reality that's important, but how you perceive things."
+ */
+
+/* Altered to use stdarg, made the core function vfnprintf.
+ * Hooked into the stdio package using 'inside information'
+ * Altered sizeof() assumptions, now assumes all integers except chars
+ * will be either
+ *  sizeof(xxx) == sizeof(long) or sizeof(xxx) == sizeof(short)
+ *
+ * -RDB
+ */
+
+/*
+ *                    Manuel Novoa III   Dec 2000
+ *
+ * The previous vfnprintf routine was almost completely rewritten with the
+ * goal of fixing some shortcomings and reducing object size.
+ *
+ * The summary of changes:
+ *
+ * Converted print conversion specification parsing from one big switch
+ *   to a method using string tables.  This new method verifies that the
+ *   conversion flags, field width, precision, qualifier, and specifier
+ *   appear in the correct order.  Many questionable specifications were
+ *   accepted by the previous code.  This new method also resulted in a
+ *   substantial reduction in object size of about 330 bytes (20%) from
+ *   the old version (1627 bytes) on i386, even with the following
+ *   improvements.
+ *
+ *     Implemented %n specifier as required by the standards.
+ *     Implemented proper handling of precision for int types.
+ *     Implemented # for hex and pointer, fixed error for octal rep of 0.
+ *     Implemented return of -1 on stream error.
+ *
+ * Added optional support for the GNU extension %m which prints the string
+ *   corresponding the errno.
+ *
+ * Added optional support for long long ints and unsigned long long ints
+ *   using the conversion qualifiers "ll", "L", or "q" (like glibc).
+ *
+ * Added optional support for doubles in a very limited form.  None of
+ *   the formating options are obeyed.  The string returned by __dtostr
+ *   is printed directly.
+ *
+ * Converted to use my (un)signed long (long) to string routines, which are
+ * smaller than the previous functions and don't require static buffers.
+ *
+ * Other Modifications:
+ *   Modified sprintf, snprintf, vsprintf, vsnprintf to share on fake-file.
+ */
+
+/*
+ *                    Manuel Novoa III   Jan 2001
+ *
+ * Removed fake file from *s*printf functions because of possible problems
+ *    if called recursively.  Instead, have sprintf, snprintf, and vsprintf
+ *    call vsnprintf which allocates a fake file on the stack.
+ * Removed WANT_FPUTC option.  Always use standard putc macro to avoid
+ *    problems with the fake file used by the *s*printf functions.
+ * Fixed bug parsing flags -- did not restart scan.
+ * Added function asprintf.
+ * Fixed 0-pad prefixing bug.
+ * Converted sizeof(int) == sizeof(long) tests to compile time vs run time.
+ *    This saves 112 bytes of code on i386.
+ * Fixed precision bug -- when negative set to default.
+ * Added function fnprintf to support __dtostr.
+ * Added floating point support for doubles.  Yeah!
+ *
+ *
+ * May 2001     Fixes from Johan Adolfsson (johan.adolfsson@axis.com)
+ *    1) printf("%c",0) returned 0 instead of 1.
+ *    2) unrolled loop in asprintf to reduce size and remove compile warning.
+ *
+ *
+ * June 2001
+ *    1) fix %p so that "0x" is prepended to outputed hex val
+ *    2) fix %p so that "(nil)" is output for (void *)0 to match glibc
+ *
+ * Sep 5, 2003
+ *    Convert to new floating point conversion routine.
+ *    Fix qualifier handling on integer and %n conversions.
+ *    Add support for vsnprintf when in non-buffered/no-wchar configuration.
+ *
+ */
+
+/*****************************************************************************/
+/*                            OPTIONS                                        */
+/*****************************************************************************/
+/* The optional support for long longs and doubles comes in two forms.
+ *
+ *   1) Normal (or partial for doubles) output support.  Set to 1 to turn on.
+ *      Adds about 130 bytes for doubles, about 220 bytes for long longs,
+ *      and about 275 for both to the base code size of 1163 on i386.
+ */
+
+/* These are now set in uClibc_config.h based on Config. */
+/*
+#define __UCLIBC_HAS_FLOATS__            1
+*/
+
+/*   2) An error message is inserted into the stream, an arg of the
+ *      appropriate size is removed from the arglist, and processing
+ *      continues.  This is adds less code and may be useful in some
+ *      cases.  Set to 1 to turn on.  Adds about 50 bytes for doubles,
+ *      about 140 bytes for long longs, and about 175 bytes for both
+ *      to the base code size of 1163 on i386.
+ */
+
+#define WANT_FLOAT_ERROR      0
+
+/*
+ * Set to support GNU extension of %m to print string corresponding to errno.
+ *
+ * Warning: This adds about 50 bytes (i386) to the code but it also pulls in
+ * strerror and the corresponding string table which together are about 3.8k.
+ */
+
+/* Now controlled by uClibc_stdio.h and set below. */
+/* #define WANT_GNU_ERRNO         0 */
+
+/**************************************************************************/
+
+#define _ISOC99_SOURCE			/* for ULLONG primarily... */
+#include "_stdio.h"
+/* #include <stdio.h> */
+#include <stdarg.h>
+#include <limits.h>
+#include <stdint.h>
+#include <string.h>
+#include <errno.h>
+#include <ctype.h>
+#include <bits/uClibc_uintmaxtostr.h>
+#include <printf.h>
+
+#ifdef __UCLIBC_HAS_THREADS__
+#include <pthread.h>
+#endif /* __UCLIBC_HAS_THREADS__ */
+
+
+/*  #undef __UCLIBC_HAS_FLOATS__ */
+/*  #undef WANT_FLOAT_ERROR */
+/*  #define WANT_FLOAT_ERROR      1 */
+
+/*  #define __isdigit(c) (((unsigned int)(c - '0')) < 10) */
+
+#ifdef __UCLIBC_HAS_PRINTF_M_SPEC__
+#define WANT_GNU_ERRNO         1
+#else
+#define WANT_GNU_ERRNO         0
+#endif
+
+#undef PUTC
+#undef OUTNSTR
+#undef _outnstr
+
+#ifdef __STDIO_BUFFERS
+
+#define PUTC(C,F)      putc_unlocked((C),(F))
+#define OUTNSTR        _outnstr
+#define _outnstr(stream, string, len)	__stdio_fwrite(string, len, stream)
+
+#else  /* __STDIO_BUFFERS */
+
+typedef struct {
+	FILE f;
+	unsigned char *bufend;		/* pointer to 1 past end of buffer */
+	unsigned char *bufpos;
+} __FILE_vsnprintf;
+
+#ifdef __UCLIBC_HAS_FLOATS__
+static void _outnstr(FILE *stream, const unsigned char *s, size_t n)
+{
+	__FILE_vsnprintf *f = (__FILE_vsnprintf *) stream;
+
+	if (!__STDIO_STREAM_IS_FAKE_VSNPRINTF_NB(&f->f)) {
+		__stdio_fwrite(s, n, &f->f);
+	} else if (f->bufend > f->bufpos) {
+		size_t r = f->bufend - f->bufpos;
+		if (r > n) {
+			r = n;
+		}
+		memcpy(f->bufpos, s, r);
+		f->bufpos += r;
+	}
+}
+#endif
+
+static void putc_unlocked_sprintf(int c, __FILE_vsnprintf *f)
+{
+	if (!__STDIO_STREAM_IS_FAKE_VSNPRINTF_NB(&f->f)) {
+		putc_unlocked(c, &f->f);
+	} else if (f->bufpos < f->bufend) {
+		*f->bufpos++ = c;
+	}
+}
+
+
+#define PUTC(C,F)      putc_unlocked_sprintf((C),(__FILE_vsnprintf *)(F))
+#define OUTNSTR        _outnstr
+
+#endif /* __STDIO_BUFFERS */
+
+#ifdef __UCLIBC_HAS_FLOATS__
+#include <float.h>
+#include <bits/uClibc_fpmax.h>
+
+typedef void (__fp_outfunc_t)(FILE *fp, intptr_t type, intptr_t len,
+							  intptr_t buf);
+
+extern size_t _fpmaxtostr(FILE * fp, __fpmax_t x, struct printf_info *info,
+						  __fp_outfunc_t fp_outfunc) attribute_hidden;
+
+static void _charpad(FILE * __restrict stream, int padchar, size_t numpad)
+{
+	/* TODO -- Use a buffer to cut down on function calls... */
+	char pad[1];
+
+	*pad = padchar;
+	while (numpad) {
+		OUTNSTR(stream, pad, 1);
+		--numpad;
+	}
+}
+
+static void _fp_out_narrow(FILE *fp, intptr_t type, intptr_t len, intptr_t buf)
+{
+	if (type & 0x80) {			/* Some type of padding needed. */
+		int buflen = strlen((const char *) buf);
+		if ((len -= buflen) > 0) {
+			_charpad(fp, (type & 0x7f), len);
+		}
+		len = buflen;
+	}
+	if (len) {
+		OUTNSTR(fp, (const char *) buf, len);
+	}
+}
+
+#endif
+
+
+enum {
+	FLAG_PLUS = 0,
+	FLAG_MINUS_LJUSTIFY,
+	FLAG_HASH,
+	FLAG_0_PAD,
+	FLAG_SPACE,
+};
+
+/* layout                   01234  */
+static const char spec[] = "+-#0 ";
+
+/**********************************************************************/
+
+extern void _store_inttype(void *dest, int desttype, uintmax_t val) attribute_hidden;
+extern uintmax_t _load_inttype(int desttype, const void *src, int uflag) attribute_hidden;
+
+/*
+ * In order to ease translation to what arginfo and _print_info._flags expect,
+ * we map:  0:int  1:char  2:longlong 4:long  8:short
+ * and then _flags |= (((q << 7) + q) & 0x701) and argtype |= (_flags & 0x701)
+ */
+
+#ifdef PDS
+#error PDS already defined!
+#endif
+#ifdef SS
+#error SS already defined!
+#endif
+#ifdef IMS
+#error IMS already defined!
+#endif
+
+#if PTRDIFF_MAX == INT_MAX
+#define PDS		0
+#elif PTRDIFF_MAX == LONG_MAX
+#define PDS		4
+#elif defined(LLONG_MAX) && (PTRDIFF_MAX == LLONG_MAX)
+#define PDS		8
+#else
+#error fix QUAL_CHARS ptrdiff_t entry 't'!
+#endif
+
+#if SIZE_MAX == UINT_MAX
+#define SS		0
+#elif SIZE_MAX == ULONG_MAX
+#define SS		4
+#elif defined(LLONG_MAX) && (SIZE_MAX == ULLONG_MAX)
+#define SS		8
+#else
+#error fix QUAL_CHARS size_t entries 'z', 'Z'!
+#endif
+
+#if INTMAX_MAX == INT_MAX
+#define IMS		0
+#elif INTMAX_MAX == LONG_MAX
+#define IMS		4
+#elif defined(LLONG_MAX) && (INTMAX_MAX == LLONG_MAX)
+#define IMS		8
+#else
+#error fix QUAL_CHARS intmax_t entry 'j'!
+#endif
+
+#define QUAL_CHARS		{ \
+	/* j:(u)intmax_t z:(s)size_t  t:ptrdiff_t  \0:int */ \
+	/* q:long_long  Z:(s)size_t */ \
+	'h',   'l',  'L',  'j',  'z',  't',  'q', 'Z',  0, \
+	 2,     4,    8,  IMS,   SS,  PDS,    8,  SS,   0, /* TODO -- fix!!! */\
+     1,     8 \
+}
+
+static const char qual_chars[] = QUAL_CHARS;
+
+/* static const char qual[] = "hlLq"; */
+/**********************************************************************/
+
+#if !defined(__UCLIBC_HAS_FLOATS__) && WANT_FLOAT_ERROR
+static const char dbl_err[] = "<DOUBLE>";
+#endif
+
+#if defined(__UCLIBC_HAS_FLOATS__) || WANT_FLOAT_ERROR
+/* layout                     012345678901234567   */
+static const char u_spec[] = "%nbopxXudicsfgGeEaA";
+#else
+/* layout                     0123456789012   */
+static const char u_spec[] = "%nbopxXudics";
+#endif
+
+/* WARNING: u_spec and u_radix need to stay in agreement!!! */
+/* u_radix[i] <-> u_spec[i+2] for unsigned entries only */
+static const char u_radix[] = "\x02\x08\x10\x10\x10\x0a";
+
+int vfprintf(FILE * __restrict op, register const char * __restrict fmt,
+			 va_list ap)
+{
+	union {
+#ifdef LLONG_MAX
+		long long ll;
+#endif
+#if LONG_MAX != INT_MAX
+		long l;
+#endif
+		int i;
+	} intarg;
+	int i, cnt, dataargtype, len;
+	const void *argptr = argptr; /* ok to be initialized. */
+	register char *p;
+	const char *fmt0;
+	int preci, width;
+#define upcase i
+	int radix, dpoint /*, upcase*/;
+	char tmp[65];		/* TODO - determine needed size from headers */
+	char flag[sizeof(spec)];
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	__STDIO_AUTO_THREADLOCK(op);
+
+	__STDIO_STREAM_VALIDATE(op);
+
+	cnt = 0;
+
+	if (__STDIO_STREAM_IS_NARROW_WRITING(op)
+		|| !__STDIO_STREAM_TRANS_TO_WRITE(op, __FLAG_NARROW)
+		) {
+
+	while (*fmt) {
+		if (*fmt == '%') {
+			fmt0 = fmt;			/* save our position in case of bad format */
+			++fmt;
+			width = -1;			/* min field width */
+			preci = -5;			/* max string width or mininum digits */
+			radix = 10;			/* number base */
+			dpoint = 0;			/* found decimal point */
+
+			/* init flags */
+			for (p =(char *) spec ; *p ; p++) {
+				flag[p-spec] = '\0';
+			}
+			flag[FLAG_0_PAD] = ' ';
+
+			/* process optional flags */
+			for (p = (char *)spec ; *p ; ) {
+				if (*fmt == *p) {
+					flag[p-spec] = *fmt++;
+					p = (char *)spec; /* restart scan */
+				} else {
+					p++;
+				}
+			}
+
+			if (!flag[FLAG_PLUS]) {
+				flag[FLAG_PLUS] = flag[FLAG_SPACE];
+			}
+
+			/* process optional width and precision */
+			do {
+				if (*fmt == '.') {
+					++fmt;
+					dpoint = 1;
+				}
+				if (*fmt == '*') {	/* parameter width value */
+					++fmt;
+					i = va_arg(ap, int);
+				} else {
+					for ( i = 0 ; (*fmt >= '0') && (*fmt <= '9') ; ++fmt ) {
+						i = (i * 10) + (*fmt - '0');
+					}
+				}
+
+				if (dpoint) {
+					preci = i;
+					if (i<0) {
+						preci = -5;
+					}
+				} else {
+					width = i;
+					if (i<0) {
+						width = -i;
+						flag[FLAG_MINUS_LJUSTIFY] = 1;
+					}
+				}
+			} while ((*fmt == '.') && !dpoint );
+
+			/* process optional qualifier */
+			p = (char *) qual_chars;
+			do {
+				if (*fmt == *p) {
+					++fmt;
+					break;
+				}
+			} while (*++p);
+			if ((p - qual_chars < 2) && (*fmt == *p)) {
+				p += ((sizeof(qual_chars)-2) / 2);
+				++fmt;
+			}
+			dataargtype = ((int)(p[(sizeof(qual_chars)-2) / 2])) << 8;
+
+#if WANT_GNU_ERRNO
+			if (*fmt == 'm') {
+				flag[FLAG_PLUS] = '\0';
+				flag[FLAG_0_PAD] = ' ';
+				p = __glibc_strerror_r(errno, tmp, sizeof(tmp));
+				goto print;
+			}
+#endif
+
+			/* process format specifier */
+			for (p = (char *) u_spec ; *p ; p++) {
+				if (*fmt != *p) continue;
+				if (p-u_spec < 1) {	/* print a % */
+					goto charout;
+				}
+				if (p-u_spec < 2) {	/* store output count in int ptr */
+					_store_inttype(va_arg(ap, void *),
+								   dataargtype,
+								   (intmax_t) (cnt));
+					goto nextfmt;
+				}
+
+				if (p-u_spec < 10) {
+					if (*p == 'p') {
+#if INTPTR_MAX == INT_MAX
+						dataargtype = 0;
+#else
+#error Fix dataargtype for pointers!
+#endif
+					}
+
+					switch(dataargtype) {
+						case (PA_INT|PA_FLAG_LONG_LONG):
+#ifdef LLONG_MAX
+							intarg.ll = va_arg(ap, long long);
+							argptr = &intarg.ll;
+							break;
+#endif
+						case (PA_INT|PA_FLAG_LONG):
+#if LONG_MAX != INT_MAX
+							intarg.l = va_arg(ap, long);
+							argptr = &intarg.l;
+							break;
+#endif
+						default:
+							intarg.i = va_arg(ap, int);
+							argptr = &intarg.i;
+							break;
+					}
+				}
+
+				if (p-u_spec < 8) { /* unsigned conversion */
+					radix = u_radix[p-u_spec-2];
+					upcase = ((*p == 'x') ? __UIM_LOWER : __UIM_UPPER);
+					if (*p == 'p') {
+						upcase = __UIM_LOWER;
+						flag[FLAG_HASH] = 'p';
+					}
+					p = _uintmaxtostr(tmp + sizeof(tmp) - 1,
+									  (uintmax_t)
+									  _load_inttype(dataargtype, argptr, radix),
+									  radix, upcase);
+
+					flag[FLAG_PLUS] = '\0';	/* meaningless for unsigned */
+					if (*p != '0') { /* non-zero */
+						if (flag[FLAG_HASH]) {
+							if (radix == 8) {
+								*--p = '0';	/* add leadding zero */
+							} else if (radix != 10) { /* either 2 or 16 */
+								flag[FLAG_PLUS] = '0';
+								*--p = 'b';
+								if (radix == 16) {
+									*p = 'x';
+									if (*fmt == 'X') {
+										*p = 'X';
+									}
+								}
+							}
+						}
+					} else if (flag[FLAG_HASH] == 'p') { /* null pointer */
+						p = "(nil)";
+					}
+				} else if (p-u_spec < 10) { /* signed conversion */
+					p = _uintmaxtostr(tmp + sizeof(tmp) - 1,
+									  (uintmax_t)
+									  _load_inttype(dataargtype, argptr, -radix),
+									  -radix, upcase);
+
+				} else if (p-u_spec < 12) {	/* character or string */
+					flag[FLAG_PLUS] = '\0';
+					flag[FLAG_0_PAD] = ' ';
+					if (*p == 'c') {	/* character */
+						p = tmp;
+						*p = va_arg(ap, int);
+						/* This takes care of the "%c",0 case */
+						len = 1;
+						goto print_len_set;
+					} else {	/* string */
+						p = va_arg(ap, char *);
+						if (!p) {
+							p = "(null)";
+							preci = 6;
+						} else {
+							if (preci < 0) {
+								preci = INT_MAX;
+							}
+						}
+						len = strnlen(p, preci);
+						goto print_len_set;
+					}
+#if defined(__UCLIBC_HAS_FLOATS__) || WANT_FLOAT_ERROR
+				} else if (p-u_spec < 27) {		/* floating point */
+#endif /* defined(__UCLIBC_HAS_FLOATS__) || WANT_FLOAT_ERROR */
+#if defined(__UCLIBC_HAS_FLOATS__)
+					struct printf_info info;
+					if (preci < 0) {
+						preci = 6;
+					}
+					info.width = width;
+					info.prec = preci;
+					info.spec = *fmt;
+					info.pad = flag[FLAG_0_PAD];
+					info._flags = 0;
+					if (flag[FLAG_PLUS] == '+') {
+						PRINT_INFO_SET_FLAG(&info,showsign);
+					} else if (flag[FLAG_PLUS] == ' ') {
+						PRINT_INFO_SET_FLAG(&info,space);
+					}
+					if (flag[FLAG_HASH]) {
+						PRINT_INFO_SET_FLAG(&info,alt);
+					}
+					if (flag[FLAG_MINUS_LJUSTIFY]) {
+						PRINT_INFO_SET_FLAG(&info,left);
+					}
+#if 1
+					cnt += _fpmaxtostr(op,
+									   (__fpmax_t)
+									   ((dataargtype == (8 << 8))
+										? va_arg(ap, long double)
+										: (long double) va_arg(ap, double)),
+									   &info, _fp_out_narrow);
+#else
+					cnt += _fpmaxtostr(op,
+									   (__fpmax_t)
+									   ((lval > 1)
+										? va_arg(ap, long double)
+										: (long double) va_arg(ap, double)),
+									   &info, _fp_out_narrow);
+#endif
+					goto nextfmt;
+#elif WANT_FLOAT_ERROR
+					(void) ((lval > 1) ? va_arg(ap, long double)
+							: va_arg(ap, double)); /* carry on */
+					p = (char *) dbl_err;
+#endif /* defined(__UCLIBC_HAS_FLOATS__) */
+				}
+
+#if WANT_GNU_ERRNO
+			print:
+#endif
+				{				/* this used to be printfield */
+					/* cheaper than strlen call */
+/*  					for ( len = 0 ; p[len] ; len++ ) { } */
+					len = strnlen(p, SIZE_MAX);
+				print_len_set:
+					if ((*p == '-')
+#if WANT_GNU_ERRNO
+						&& (*fmt != 'm')
+#endif
+						&& (*fmt != 's')) {
+						flag[FLAG_PLUS] = *p++;
+						--len;
+					}
+				    if (flag[FLAG_PLUS]) {
+						++len;
+						++preci;
+						if (flag[FLAG_PLUS] == '0') { /* base 16 */
+							++preci; /* account for x or X */
+						}
+					}
+
+					if (preci >= 0) {
+						if ((*fmt == 's')
+#if WANT_GNU_ERRNO
+						|| (*fmt == 'm')
+#endif
+						) {
+							if (len > preci) {
+								len = preci;
+							} else {
+								preci = len;
+							}
+						}
+						preci -= len;
+						if (preci < 0) {
+							preci = 0;
+						}
+						width -= preci;
+					}
+
+					width -= len;
+					if (width < 0) {
+						width = 0;
+					}
+
+					if (preci < 0) {
+						preci = 0;
+						if (!flag[FLAG_MINUS_LJUSTIFY]
+							/* && flag[FLAG_PLUS] */
+							&& (flag[FLAG_0_PAD] == '0')) {
+							preci = width;
+							width = 0;
+						}
+					}
+
+					while (width + len + preci) {
+						unsigned char ch;
+						/* right padding || left padding */
+						if ((!len && !preci)
+							|| (width && !flag[FLAG_MINUS_LJUSTIFY])) {
+							ch = ' ';
+							--width;
+						} else if (flag[FLAG_PLUS]) {
+							ch = flag[FLAG_PLUS]; /* sign */
+							if (flag[FLAG_PLUS]=='0') {	/* base 16 case */
+								flag[FLAG_PLUS] = *p++;	/* get the x|X */
+							} else {
+								flag[FLAG_PLUS] = '\0';
+							}
+							--len;
+						} else if (preci) {
+							ch = '0';
+							--preci;
+						} else {
+							ch = *p++; /* main field */
+							--len;
+						}
+						++cnt;
+						PUTC(ch, op);
+					}
+				}
+				goto nextfmt;
+			}
+
+			fmt = fmt0;	/* this was an illegal format */
+		}
+
+	charout:
+		++cnt;
+		PUTC(*fmt, op); /* normal char out */
+
+	nextfmt:
+		++fmt;
+	}
+
+	}
+
+	i = (__FERROR_UNLOCKED(op)) ? -1 : cnt;
+
+	__STDIO_STREAM_VALIDATE(op);
+
+	__STDIO_AUTO_THREADUNLOCK(op);
+
+	return i;
+}
+libc_hidden_def(vfprintf)
diff --git a/ap/build/uClibc/libc/stdio/open_memstream.c b/ap/build/uClibc/libc/stdio/open_memstream.c
new file mode 100644
index 0000000..8b552c7
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/open_memstream.c
@@ -0,0 +1,166 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include <features.h>
+
+#ifdef __USE_GNU
+#include "_stdio.h"
+
+
+#ifndef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
+#error no custom streams!
+#endif
+
+#define COOKIE ((__oms_cookie *) cookie)
+
+typedef struct {
+	char *buf;
+	size_t len;
+	size_t pos;
+	size_t eof;
+	char **bufloc;
+	size_t *sizeloc;
+} __oms_cookie;
+
+/* Nothing to do here, as memstreams are write-only. */
+/*  static ssize_t oms_read(void *cookie, char *buf, size_t bufsize) */
+/*  { */
+/*  } */
+
+static ssize_t oms_write(register void *cookie, const char *buf, size_t bufsize)
+{
+	register char *newbuf;
+	size_t count;
+
+	/* Note: we already know bufsize < SSIZE_MAX... */
+
+	count = COOKIE->len - COOKIE->pos - 1;
+	assert(COOKIE->pos < COOKIE->len); /* Always nul-terminate! */
+
+	if (bufsize > count) {
+		newbuf = realloc(COOKIE->buf, COOKIE->len + bufsize - count);
+		if (newbuf) {
+			*COOKIE->bufloc = COOKIE->buf = newbuf;
+			COOKIE->len += (bufsize - count);
+		} else {
+			bufsize = count;
+			if (count == 0) {
+				__set_errno(EFBIG);	/* TODO: check glibc errno setting... */
+				return -1;
+			}
+		}
+	}
+
+	memcpy(COOKIE->buf + COOKIE->pos, buf, bufsize);
+	COOKIE->pos += bufsize;
+
+	if (COOKIE->pos > COOKIE->eof) {
+		*COOKIE->sizeloc = COOKIE->eof = COOKIE->pos;
+		COOKIE->buf[COOKIE->eof] = 0; /* Need to nul-terminate. */
+	}
+
+	return bufsize;
+}
+
+static int oms_seek(register void *cookie, __offmax_t *pos, int whence)
+{
+	__offmax_t p = *pos;
+	register char *buf;
+	size_t leastlen;
+
+	/* Note: fseek already checks that whence is legal, so don't check here
+	 * unless debugging. */
+	assert(((unsigned int) whence) <= 2);
+
+	if (whence != SEEK_SET) {
+		p += (whence == SEEK_CUR) ? COOKIE->pos : /* SEEK_END */ COOKIE->eof;
+	}
+
+	/* Note: glibc only allows seeking in the buffer.  We'll actually restrict
+	 * to the data. */
+	/* Check for offset < 0, offset >= too big (need nul), or overflow... */
+	if (((uintmax_t) p) >= SIZE_MAX - 1) {
+		return -1;
+	}
+
+	leastlen = ((size_t) p) + 1; /* New pos + 1 for nul if necessary. */
+
+	if (leastlen >= COOKIE->len) { /* Need to grow buffer... */
+		buf = realloc(COOKIE->buf, leastlen);
+		if (buf) {
+			*COOKIE->bufloc = COOKIE->buf = buf;
+			COOKIE->len = leastlen;
+			memset(buf + COOKIE->eof, 0, leastlen - COOKIE->eof); /* 0-fill */
+		} else {
+			/* TODO: check glibc errno setting... */
+			return -1;
+		}
+	}
+
+	*pos = COOKIE->pos = --leastlen;
+
+	if (leastlen > COOKIE->eof) {
+		memset(COOKIE->buf + COOKIE->eof, 0, leastlen - COOKIE->eof);
+		*COOKIE->sizeloc = COOKIE->eof;
+	}
+
+	return 0;
+}
+
+static int oms_close(void *cookie)
+{
+	free(cookie);
+	return 0;
+}
+
+#undef COOKIE
+
+static const cookie_io_functions_t _oms_io_funcs = {
+	NULL, oms_write, oms_seek, oms_close
+};
+
+/* TODO: If we have buffers enabled, it might be worthwile to add a pointer
+ * to the FILE in the cookie and operate directly on the buffer itself
+ * (ie replace the FILE buffer with the cookie buffer and update FILE bufstart,
+ * etc. whenever we seek). */
+
+FILE *open_memstream(char **__restrict bufloc, size_t *__restrict sizeloc)
+{
+	register __oms_cookie *cookie;
+	register FILE *fp;
+
+	if ((cookie = malloc(sizeof(__oms_cookie))) != NULL) {
+		if ((cookie->buf = malloc(cookie->len = BUFSIZ)) == NULL) {
+			goto EXIT_cookie;
+		}
+		*cookie->buf = 0;		/* Set nul terminator for buffer. */
+		*(cookie->bufloc = bufloc) = cookie->buf;
+		*(cookie->sizeloc = sizeloc) = cookie->eof = cookie->pos = 0;
+
+#ifndef __BCC__
+		fp = fopencookie(cookie, "w", _oms_io_funcs);
+#else
+		fp = fopencookie(cookie, "w", &_oms_io_funcs);
+#endif
+		/* Note: We don't need to worry about locking fp in the thread case
+		 * as the only possible access would be a close or flush with
+		 * nothing currently in the FILE's write buffer. */
+
+		if (fp != NULL) {
+			__STDIO_STREAM_VALIDATE(fp);
+			return fp;
+		}
+	}
+
+	free(cookie->buf);
+ EXIT_cookie:
+	free(cookie);
+
+	return NULL;
+}
+libc_hidden_def(open_memstream)
+#endif
diff --git a/ap/build/uClibc/libc/stdio/parse_printf_format.c b/ap/build/uClibc/libc/stdio/parse_printf_format.c
new file mode 100644
index 0000000..38266b3
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/parse_printf_format.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define L_parse_printf_format
+#include "_vfprintf.c"
diff --git a/ap/build/uClibc/libc/stdio/perror.c b/ap/build/uClibc/libc/stdio/perror.c
new file mode 100644
index 0000000..8b943e4
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/perror.c
@@ -0,0 +1,38 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning CONSIDER: Increase buffer size for error message (non-%m case)?
+#endif
+
+void perror(register const char *s)
+{
+	/* If the program is calling perror, it's a safe bet that printf and
+	 * friends are used as well.  It is also possible that the calling
+	 * program could buffer stderr, or reassign it. */
+
+	register const char *sep;
+
+	sep = ": ";
+	if (!(s && *s)) {			/* Caller did not supply a prefix message */
+		s = (sep += 2);			/* or passed an empty string. */
+	}
+
+#ifdef __UCLIBC_HAS_PRINTF_M_SPEC__
+	fprintf(stderr, "%s%s%m\n", s, sep); /* Use the gnu %m feature. */
+#else
+	{
+		char buf[64];
+		fprintf(stderr, "%s%s%s\n", s, sep,
+				__glibc_strerror_r(errno, buf, sizeof(buf)));
+	}
+#endif
+}
+libc_hidden_def(perror)
diff --git a/ap/build/uClibc/libc/stdio/popen.c b/ap/build/uClibc/libc/stdio/popen.c
new file mode 100644
index 0000000..d5c60cf
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/popen.c
@@ -0,0 +1,186 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+/* Jan 1, 2004
+ *
+ * Rewrite popen for SUSv3 compliance.
+ *   Added a list of popen()'d to store pids and use waitpid() in pclose().
+ *   Loop on waitpid() failure due to EINTR as required.
+ *   Close parent's popen()'d FILEs in the {v}fork()'d child.
+ *   Fix failure exit code for failed execve().
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/wait.h>
+#include <bits/uClibc_mutex.h>
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning "hmm... susv3 says Pipe streams are byte-oriented."
+#endif /* __UCLIBC_MJN3_ONLY__ */
+
+
+/* uClinux-2.0 has vfork, but Linux 2.0 doesn't */
+#include <sys/syscall.h>
+#if ! defined __NR_vfork
+# define vfork fork
+# define VFORK_LOCK		((void) 0)
+# define VFORK_UNLOCK		((void) 0)
+#endif
+
+#ifndef VFORK_LOCK
+__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
+# define VFORK_LOCK		__UCLIBC_MUTEX_LOCK(mylock)
+# define VFORK_UNLOCK		__UCLIBC_MUTEX_UNLOCK(mylock)
+#endif
+
+struct popen_list_item {
+	struct popen_list_item *next;
+	FILE *f;
+	pid_t pid;
+};
+
+static struct popen_list_item *popen_list /* = NULL (bss initialized) */;
+
+FILE *popen(const char *command, const char *modes)
+{
+	FILE *fp;
+	struct popen_list_item *pi;
+	struct popen_list_item *po;
+	int pipe_fd[2];
+	int parent_fd;
+	int child_fd;
+	int child_writing;			/* Doubles as the desired child fildes. */
+	pid_t pid;
+
+	child_writing = 0;			/* Assume child is writing. */
+	if (modes[0] != 'w') {		/* Parent not writing... */
+		++child_writing;		/* so child must be writing. */
+		if (modes[0] != 'r') {	/* Oops!  Parent not reading either! */
+			__set_errno(EINVAL);
+			goto RET_NULL;
+		}
+	}
+
+	if (!(pi = malloc(sizeof(struct popen_list_item)))) {
+		goto RET_NULL;
+	}
+
+	if (pipe(pipe_fd)) {
+		goto FREE_PI;
+	}
+
+	child_fd = pipe_fd[child_writing];
+	parent_fd = pipe_fd[1-child_writing];
+
+	if (!(fp = fdopen(parent_fd, modes))) {
+		close(parent_fd);
+		close(child_fd);
+		goto FREE_PI;
+	}
+
+	VFORK_LOCK;
+	if ((pid = vfork()) == 0) {	/* Child of vfork... */
+		close(parent_fd);
+		if (child_fd != child_writing) {
+			dup2(child_fd, child_writing);
+			close(child_fd);
+		}
+
+		/* SUSv3 requires that any previously popen()'d streams in the
+		 * parent shall be closed in the child. */
+		for (po = popen_list ; po ; po = po->next) {
+			close(po->f->__filedes);
+		}
+
+		execl("/bin/sh", "sh", "-c", command, (char *)0);
+
+		/* SUSv3 mandates an exit code of 127 for the child if the
+		 * command interpreter can not be invoked. */
+		_exit(127);
+	}
+	VFORK_UNLOCK;
+
+	/* We need to close the child filedes whether vfork failed or
+	 * it succeeded and we're in the parent. */
+	close(child_fd);
+
+	if (pid > 0) {				/* Parent of vfork... */
+		pi->pid = pid;
+		pi->f = fp;
+		VFORK_LOCK;
+		pi->next = popen_list;
+		popen_list = pi;
+		VFORK_UNLOCK;
+
+		return fp;
+	}
+
+	/* If we get here, vfork failed. */
+	fclose(fp);					/* Will close parent_fd. */
+
+ FREE_PI:
+	free(pi);
+
+ RET_NULL:
+	return NULL;
+}
+
+#warning is pclose correct wrt the new mutex semantics?
+
+int pclose(FILE *stream)
+{
+	struct popen_list_item *p;
+	int stat;
+	pid_t pid;
+
+	/* First, find the list entry corresponding to stream and remove it
+	 * from the list.  Set p to the list item (NULL if not found). */
+	VFORK_LOCK;
+	if ((p = popen_list) != NULL) {
+		if (p->f == stream) {
+			popen_list = p->next;
+		} else {
+			struct popen_list_item *t;
+			do {
+				t = p;
+				if (!(p = t->next)) {
+					__set_errno(EINVAL); /* Not required by SUSv3. */
+					break;
+				}
+				if (p->f == stream) {
+					t->next = p->next;
+					break;
+				}
+			} while (1);
+		}
+	}
+	VFORK_UNLOCK;
+
+	if (p) {
+		pid = p->pid;			/* Save the pid we need */
+		free(p);				/* and free the list item. */
+
+		fclose(stream);	/* The SUSv3 example code ignores the return. */
+
+		/* SUSv3 specificly requires that pclose not return before the child
+		 * terminates, in order to disallow pclose from returning on EINTR. */
+		do {
+			if (waitpid(pid, &stat, 0) >= 0) {
+				return stat;
+			}
+			if (errno != EINTR) {
+				break;
+			}
+		} while (1);
+	}
+
+	return -1;
+}
diff --git a/ap/build/uClibc/libc/stdio/printf.c b/ap/build/uClibc/libc/stdio/printf.c
new file mode 100644
index 0000000..8cd3db9
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/printf.c
@@ -0,0 +1,23 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+#include <stdarg.h>
+
+
+int printf(const char * __restrict format, ...)
+{
+	va_list arg;
+	int rv;
+
+	va_start(arg, format);
+	rv = vfprintf(stdout, format, arg);
+	va_end(arg);
+
+	return rv;
+}
+libc_hidden_def(printf)
diff --git a/ap/build/uClibc/libc/stdio/putchar.c b/ap/build/uClibc/libc/stdio/putchar.c
new file mode 100644
index 0000000..583e90f
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/putchar.c
@@ -0,0 +1,43 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+#undef putchar
+#ifdef __DO_UNLOCKED
+
+#undef putchar_unlocked
+int putchar_unlocked(int c)
+{
+	register FILE *stream = stdout;
+
+	return __PUTC_UNLOCKED_MACRO(c, stream);
+}
+
+#ifndef __UCLIBC_HAS_THREADS__
+strong_alias(putchar_unlocked,putchar)
+#endif
+
+#elif defined __UCLIBC_HAS_THREADS__
+
+int putchar(int c)
+{
+	register FILE *stream = stdout;
+
+	if (stream->__user_locking != 0) {
+		return __PUTC_UNLOCKED_MACRO(c, stream);
+	} else {
+		int retval;
+		__STDIO_ALWAYS_THREADLOCK(stream);
+		retval = __PUTC_UNLOCKED_MACRO(c, stream);
+		__STDIO_ALWAYS_THREADUNLOCK(stream);
+		return retval;
+	}
+}
+
+#endif
diff --git a/ap/build/uClibc/libc/stdio/putchar_unlocked.c b/ap/build/uClibc/libc/stdio/putchar_unlocked.c
new file mode 100644
index 0000000..6d6ec47
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/putchar_unlocked.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define __DO_UNLOCKED
+#include "putchar.c"
diff --git a/ap/build/uClibc/libc/stdio/puts.c b/ap/build/uClibc/libc/stdio/puts.c
new file mode 100644
index 0000000..67775ff
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/puts.c
@@ -0,0 +1,34 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+int puts(register const char * __restrict s)
+{
+	register FILE *stream = stdout; /* This helps bcc optimize. */
+	int n;
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	__STDIO_AUTO_THREADLOCK(stream);
+
+	/* Note: Don't try to optimize by switching to FBF until the newline.
+	 * If the string itself contained a newline a write error occurred,
+	 * then we could have a newline in the buffer of an LBF stream. */
+
+	/* Note: Nonportable as fputs need only return nonnegative on success. */
+	if ((n = fputs_unlocked(s, stream)) != EOF) {
+		++n;
+		if (__fputc_unlocked('\n', stream) == EOF) {
+			n = EOF;
+		}
+	}
+
+	__STDIO_AUTO_THREADUNLOCK(stream);
+
+	return n;
+}
diff --git a/ap/build/uClibc/libc/stdio/putw.c b/ap/build/uClibc/libc/stdio/putw.c
new file mode 100644
index 0000000..ffdb114
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/putw.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+/* SUSv2 Legacy function -- need not be reentrant. */
+
+int putw(int w, FILE *stream)
+{
+#define PW    &w
+	/* If w is passed in a register, enable the following. */
+#if 0
+#undef PW
+	int PW[1];
+	PW[0] = w;
+#endif
+
+#if EOF == -1
+	return fwrite_unlocked((void *) PW, sizeof(int), 1, stream) - 1;
+#else
+	return (fwrite_unlocked((void *) PW, sizeof(int), 1, stream) != 0)
+		? 0 : EOF;
+#endif
+}
diff --git a/ap/build/uClibc/libc/stdio/putwchar.c b/ap/build/uClibc/libc/stdio/putwchar.c
new file mode 100644
index 0000000..3fadb61
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/putwchar.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+#ifdef __DO_UNLOCKED
+
+
+wint_t putwchar_unlocked(wchar_t wc)
+{
+	return fputwc_unlocked(wc, stdout);
+}
+
+#ifndef __UCLIBC_HAS_THREADS__
+strong_alias(putwchar_unlocked,putwchar)
+#endif
+
+#elif defined __UCLIBC_HAS_THREADS__
+
+/* psm: should this be fputwc? */
+
+wint_t putwchar(wchar_t wc)
+{
+	return fputc(wc, stdout);
+}
+
+#endif
diff --git a/ap/build/uClibc/libc/stdio/putwchar_unlocked.c b/ap/build/uClibc/libc/stdio/putwchar_unlocked.c
new file mode 100644
index 0000000..5b0c600
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/putwchar_unlocked.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define __DO_UNLOCKED
+#include "putwchar.c"
diff --git a/ap/build/uClibc/libc/stdio/register_printf_function.c b/ap/build/uClibc/libc/stdio/register_printf_function.c
new file mode 100644
index 0000000..c6b3240
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/register_printf_function.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define L_register_printf_function
+#include "_vfprintf.c"
diff --git a/ap/build/uClibc/libc/stdio/remove.c b/ap/build/uClibc/libc/stdio/remove.c
new file mode 100644
index 0000000..af28507
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/remove.c
@@ -0,0 +1,31 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+#include <unistd.h>
+#include <errno.h>
+
+/* SUSv3 states:
+ *   If path does not name a directory, remove(path) shall be equivalent
+ *   to unlink(path).  If path names a directory, remove(path) shall be
+ *   equivalent to rmdir(path).
+ */
+
+int remove(register const char *filename)
+{
+	int saved_errno = errno;
+	int rv;
+
+	rv = rmdir(filename);
+	if ((rv < 0) && (errno == ENOTDIR)) {
+		__set_errno(saved_errno); /* Need to restore errno. */
+		rv = unlink(filename);
+	}
+	return rv;
+}
+libc_hidden_def(remove)
diff --git a/ap/build/uClibc/libc/stdio/rewind.c b/ap/build/uClibc/libc/stdio/rewind.c
new file mode 100644
index 0000000..1b17044
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/rewind.c
@@ -0,0 +1,22 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+void rewind(register FILE *stream)
+{
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	__STDIO_AUTO_THREADLOCK(stream);
+
+	__STDIO_STREAM_CLEAR_ERROR(stream);	/* Clear the error indicator */
+	fseek(stream, 0L, SEEK_SET); /* first since fseek could set it. */
+
+	__STDIO_AUTO_THREADUNLOCK(stream);
+}
+libc_hidden_def(rewind)
diff --git a/ap/build/uClibc/libc/stdio/scanf.c b/ap/build/uClibc/libc/stdio/scanf.c
new file mode 100644
index 0000000..4943c88
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/scanf.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define L_scanf
+#include "_scanf.c"
diff --git a/ap/build/uClibc/libc/stdio/setbuf.c b/ap/build/uClibc/libc/stdio/setbuf.c
new file mode 100644
index 0000000..e6080a5
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/setbuf.c
@@ -0,0 +1,16 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+
+void setbuf(FILE * __restrict stream, register char * __restrict buf)
+{
+#ifdef __STDIO_BUFFERS
+	setvbuf(stream, buf, ((buf != NULL) ? _IOFBF : _IONBF), BUFSIZ);
+#endif
+}
diff --git a/ap/build/uClibc/libc/stdio/setbuffer.c b/ap/build/uClibc/libc/stdio/setbuffer.c
new file mode 100644
index 0000000..b566bfc
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/setbuffer.c
@@ -0,0 +1,25 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+#ifdef __USE_BSD
+
+
+/* A BSD function.  The implementation matches the linux man page,
+ * except that we do not bother calling setvbuf if not configured
+ * for stream buffering.
+ */
+
+void setbuffer(FILE * __restrict stream, register char * __restrict buf,
+			   size_t size)
+{
+#ifdef __STDIO_BUFFERS
+	setvbuf(stream, buf, (buf ? _IOFBF : _IONBF), size);
+#endif
+}
+#endif
diff --git a/ap/build/uClibc/libc/stdio/setlinebuf.c b/ap/build/uClibc/libc/stdio/setlinebuf.c
new file mode 100644
index 0000000..9323388
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/setlinebuf.c
@@ -0,0 +1,24 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+#ifdef __USE_BSD
+
+
+/* A BSD function.  The implementation matches the linux man page,
+ * except that we do not bother calling setvbuf if not configured
+ * for stream buffering.
+ */
+
+void setlinebuf(FILE * __restrict stream)
+{
+#ifdef __STDIO_BUFFERS
+	setvbuf(stream, NULL, _IOLBF, (size_t) 0);
+#endif
+}
+#endif
diff --git a/ap/build/uClibc/libc/stdio/setvbuf.c b/ap/build/uClibc/libc/stdio/setvbuf.c
new file mode 100644
index 0000000..0b0ea0d
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/setvbuf.c
@@ -0,0 +1,107 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+#if (_IOFBF != 0) || (_IOLBF != 1) || (_IONBF != 2)
+#error Assumption violated -- values of _IOFBF, _IOLBF, _IONBF
+#endif
+#if (__FLAG_FBF != 0) || (__FLAG_NBF != (2*__FLAG_LBF))
+#error Assumption violated for buffering mode flags
+#endif
+
+int setvbuf(register FILE * __restrict stream, register char * __restrict buf,
+			int mode, size_t size)
+{
+#ifdef __STDIO_BUFFERS
+
+	int retval = EOF;
+	int alloc_flag = 0;
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	__STDIO_AUTO_THREADLOCK(stream);
+	__STDIO_STREAM_VALIDATE(stream);
+
+	if (((unsigned int) mode) > 2) {
+		__set_errno(EINVAL);
+		goto ERROR;
+	}
+
+	/* C99 states that setvbuf may only be used between a successful
+	 * open of the stream and before any other operation other than
+	 * an unsuccessful call to setvbuf. */
+
+#ifdef __STDIO_FLEXIBLE_SETVBUF
+	/* If we aren't currently reading (including ungots) or writing,
+	 * then allow the request to proceed. */
+
+	if (stream->__modeflags & (__MASK_READING|__FLAG_WRITING)) {
+		goto ERROR;
+	}
+#else
+	/* The following test isn't quite as strict as C99, as it will
+	 * not detect file positioning operations. */
+
+	if (stream->__modeflags & (__MASK_READING|__FLAG_WRITING
+							 |__FLAG_NARROW|__FLAG_WIDE
+							 |__FLAG_ERROR|__FLAG_EOF)
+		) {
+		goto ERROR;
+	}
+#endif
+
+	stream->__modeflags &= ~(__MASK_BUFMODE);	/* Clear current mode */
+	stream->__modeflags |= mode * __FLAG_LBF;	/*   and set new one. */
+
+	if ((mode == _IONBF) || !size) {
+		size = 0;
+		buf = NULL;
+	} else if (!buf) {
+		if ((__STDIO_STREAM_BUFFER_SIZE(stream) == size) /* Same size or */
+			|| !(buf = malloc(size)) /* malloc failed, so don't change. */
+			) {
+			goto DONE;
+		}
+		alloc_flag = __FLAG_FREEBUF;
+	}
+
+	if (stream->__modeflags & __FLAG_FREEBUF) {
+		stream->__modeflags &= ~(__FLAG_FREEBUF);
+		free(stream->__bufstart);
+	}
+
+	stream->__modeflags |= alloc_flag;
+	stream->__bufstart = (unsigned char *) buf;
+	stream->__bufend = (unsigned char *) buf + size;
+	__STDIO_STREAM_INIT_BUFREAD_BUFPOS(stream);
+	__STDIO_STREAM_DISABLE_GETC(stream);
+	__STDIO_STREAM_DISABLE_PUTC(stream);
+
+ DONE:
+	retval = 0;
+
+ ERROR:
+	__STDIO_STREAM_VALIDATE(stream);
+	__STDIO_AUTO_THREADUNLOCK(stream);
+
+	return retval;
+
+#else  /* __STDIO_BUFFERS  */
+
+	if (mode == _IONBF) {
+		return 0;
+	}
+
+	if (((unsigned int) mode) > 2) {
+		__set_errno(EINVAL);
+	}
+
+	return EOF;
+
+#endif
+}
+libc_hidden_def(setvbuf)
diff --git a/ap/build/uClibc/libc/stdio/snprintf.c b/ap/build/uClibc/libc/stdio/snprintf.c
new file mode 100644
index 0000000..e0902ac
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/snprintf.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+#include <stdarg.h>
+
+#ifndef __STDIO_HAS_VSNPRINTF
+#warning Skipping snprintf since no vsnprintf!
+#else
+
+
+int snprintf(char *__restrict buf, size_t size,
+			 const char * __restrict format, ...)
+{
+	va_list arg;
+	int rv;
+
+	va_start(arg, format);
+	rv = vsnprintf(buf, size, format, arg);
+	va_end(arg);
+	return rv;
+}
+libc_hidden_def(snprintf)
+
+#endif
diff --git a/ap/build/uClibc/libc/stdio/sprintf.c b/ap/build/uClibc/libc/stdio/sprintf.c
new file mode 100644
index 0000000..44304b5
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/sprintf.c
@@ -0,0 +1,29 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+#include <stdarg.h>
+
+#ifndef __STDIO_HAS_VSNPRINTF
+#warning Skipping sprintf since no vsnprintf!
+#else
+
+
+int sprintf(char *__restrict buf, const char * __restrict format, ...)
+{
+	va_list arg;
+	int rv;
+
+	va_start(arg, format);
+	rv = vsnprintf(buf, SIZE_MAX, format, arg);
+	va_end(arg);
+
+	return rv;
+}
+libc_hidden_def(sprintf)
+
+#endif
diff --git a/ap/build/uClibc/libc/stdio/sscanf.c b/ap/build/uClibc/libc/stdio/sscanf.c
new file mode 100644
index 0000000..f53c065
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/sscanf.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define L_sscanf
+#include "_scanf.c"
diff --git a/ap/build/uClibc/libc/stdio/swprintf.c b/ap/build/uClibc/libc/stdio/swprintf.c
new file mode 100644
index 0000000..8e037d2
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/swprintf.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+#include <stdarg.h>
+#include <wchar.h>
+
+
+#ifndef __STDIO_BUFFERS
+#warning Skipping swprintf since no buffering!
+#else  /* __STDIO_BUFFERS */
+
+int swprintf(wchar_t *__restrict buf, size_t size,
+			 const wchar_t * __restrict format, ...)
+{
+	va_list arg;
+	int rv;
+
+	va_start(arg, format);
+	rv = vswprintf(buf, size, format, arg);
+	va_end(arg);
+
+	return rv;
+}
+
+#endif /* __STDIO_BUFFERS */
diff --git a/ap/build/uClibc/libc/stdio/swscanf.c b/ap/build/uClibc/libc/stdio/swscanf.c
new file mode 100644
index 0000000..06f8cb7
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/swscanf.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define L_swscanf
+#include "_scanf.c"
diff --git a/ap/build/uClibc/libc/stdio/tempnam.c b/ap/build/uClibc/libc/stdio/tempnam.c
new file mode 100644
index 0000000..d2d51da
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/tempnam.c
@@ -0,0 +1,45 @@
+/* Copyright (C) 1991,1993,1996-1999,2000 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 Library General Public License as
+   published by the Free Software Foundation; either version 2 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <stdio.h>
+#include <string.h>
+#include "../misc/internals/tempname.h"
+
+
+/* Generate a unique temporary filename using up to five characters of PFX
+   if it is not NULL.  The directory to put this file in is searched for
+   as follows: First the environment variable "TMPDIR" is checked.
+   If it contains the name of a writable directory, that directory is used.
+   If not and if DIR is not NULL, that value is checked.  If that fails,
+   P_tmpdir is tried and finally "/tmp".  The storage for the filename
+   is allocated by `malloc'.  */
+char *
+tempnam (const char *dir, const char *pfx)
+{
+  char buf[FILENAME_MAX];
+
+  if (__path_search (buf, FILENAME_MAX, dir, pfx, 1))
+    return NULL;
+
+  if (__gen_tempname (buf, __GT_NOCREATE, 0))
+    return NULL;
+
+  return strdup (buf);
+}
+
+link_warning (tempnam, "the use of OBSOLESCENT `tempnam' is discouraged, use `mkstemp'")
diff --git a/ap/build/uClibc/libc/stdio/tmpfile.c b/ap/build/uClibc/libc/stdio/tmpfile.c
new file mode 100644
index 0000000..c6b2dc8
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/tmpfile.c
@@ -0,0 +1,54 @@
+/* Copyright (C) 1991, 1993, 1996, 1997, 1998 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 Library General Public License as
+   published by the Free Software Foundation; either version 2 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <features.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include "../misc/internals/tempname.h"
+#include <not-cancel.h>
+
+
+/* This returns a new stream opened on a temporary file (generated
+   by tmpnam).  The file is opened with mode "w+b" (binary read/write).
+   If we couldn't generate a unique filename or the file couldn't
+   be opened, NULL is returned.  */
+FILE * tmpfile (void)
+{
+    char buf[FILENAME_MAX];
+    int fd;
+    FILE *f;
+
+    if (__path_search (buf, FILENAME_MAX, NULL, "tmpf", 0))
+	return NULL;
+    fd = __gen_tempname (buf, __GT_FILE, S_IRUSR | S_IWUSR);
+    if (fd < 0)
+	return NULL;
+
+    /* Note that this relies on the Unix semantics that
+       a file is not really removed until it is closed.  */
+    (void) remove (buf);
+
+    if ((f = fdopen (fd, "w+b")) == NULL)
+	close_not_cancel (fd);
+
+    return f;
+}
+#ifdef __UCLIBC_HAS_LFS__
+strong_alias(tmpfile,tmpfile64)
+#endif
diff --git a/ap/build/uClibc/libc/stdio/tmpnam.c b/ap/build/uClibc/libc/stdio/tmpnam.c
new file mode 100644
index 0000000..e7359c3
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/tmpnam.c
@@ -0,0 +1,53 @@
+/* Copyright (C) 1991,1993,1996-1999,2000 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.  */
+
+#include <stdio.h>
+#include <string.h>
+#include "../misc/internals/tempname.h"
+
+
+static char tmpnam_buffer[L_tmpnam];
+
+/* Generate a unique filename in P_tmpdir.
+
+   This function is *not* thread safe!  */
+char *
+tmpnam (char *s)
+{
+  /* By using two buffers we manage to be thread safe in the case
+     where S != NULL.  */
+  char tmpbufmem[L_tmpnam];
+  char *tmpbuf = s ?: tmpbufmem;
+
+  /* In the following call we use the buffer pointed to by S if
+     non-NULL although we don't know the size.  But we limit the size
+     to L_tmpnam characters in any case.  */
+  if (__builtin_expect (__path_search (tmpbuf, L_tmpnam, NULL, NULL, 0),
+			0))
+    return NULL;
+
+  if (__builtin_expect (__gen_tempname (tmpbuf, __GT_NOCREATE, 0), 0))
+    return NULL;
+
+  if (s == NULL)
+    return (char *) memcpy (tmpnam_buffer, tmpbuf, L_tmpnam);
+
+  return s;
+}
+
+link_warning (tmpnam, "the use of `tmpnam' is dangerous, better use `mkstemp'")
diff --git a/ap/build/uClibc/libc/stdio/tmpnam_r.c b/ap/build/uClibc/libc/stdio/tmpnam_r.c
new file mode 100644
index 0000000..2b93ae6
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/tmpnam_r.c
@@ -0,0 +1,36 @@
+/* Copyright (C) 1991, 1993, 1996, 1997, 1998 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 Library General Public License as
+   published by the Free Software Foundation; either version 2 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <stdio.h>
+#include "../misc/internals/tempname.h"
+
+/* Generate a unique filename in P_tmpdir.  If S is NULL return NULL.
+   This makes this function thread safe.  */
+char * tmpnam_r (char *s)
+{
+    if (s == NULL)
+	return NULL;
+
+    if (__path_search (s, L_tmpnam, NULL, NULL, 0))
+	return NULL;
+    if (__gen_tempname (s, __GT_NOCREATE, 0))
+	return NULL;
+
+    return s;
+}
+link_warning (tmpnam_r, "the use of OBSOLESCENT `tmpnam_r' is discouraged, use `mkstemp'")
diff --git a/ap/build/uClibc/libc/stdio/ungetc.c b/ap/build/uClibc/libc/stdio/ungetc.c
new file mode 100644
index 0000000..ea4edd2
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/ungetc.c
@@ -0,0 +1,78 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+/* Having ungotten characters implies the stream is reading.
+ * The scheme used here treats the least significant 2 bits of
+ * the stream's modeflags member as follows:
+ *   0 0   Not currently reading.
+ *   0 1   Reading, but no ungetc() or scanf() push back chars.
+ *   1 0   Reading with one ungetc() char (ungot[1] is 1)
+ *         or one scanf() pushed back char (ungot[1] is 0).
+ *   1 1   Reading with both an ungetc() char and a scanf()
+ *         pushed back char.  Note that this must be the result
+ *         of a scanf() push back (in ungot[0]) _followed_ by
+ *         an ungetc() call (in ungot[1]).
+ *
+ * Notes:
+ *   scanf() can NOT use ungetc() to push back characters.
+ *     (See section 7.19.6.2 of the C9X rationale -- WG14/N897.)
+ */
+
+int ungetc(int c, register FILE *stream)
+{
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	__STDIO_AUTO_THREADLOCK(stream);
+	__STDIO_STREAM_VALIDATE(stream);
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning CONSIDER: Make fast ungetc an option?
+#endif
+#ifdef __UCLIBC_HAS_STDIO_GETC_MACRO__
+	/* If buffered narrow reading with no ungot slots filled, and if not
+	 * ungetting a different char than the one last read from the buffer,
+	 * we can simply decrement the position and not worry about disabling
+	 * the getc macros.  This will cut down on overhead in applications
+	 * that use getc/ungetc extensively (like gcc). */
+	/* NOTE: If we can use getc, then we are buffered narrow reading with
+	 * no ungot slots filled. */
+	if (__STDIO_STREAM_CAN_USE_BUFFER_GET(stream)
+		&& (c != EOF)
+		&& (stream->__bufpos > stream->__bufstart)
+		&& (stream->__bufpos[-1] == ((unsigned char)c))
+		) {
+		--stream->__bufpos;
+		__STDIO_STREAM_CLEAR_EOF(stream); /* Must clear end-of-file flag. */
+	} else
+#endif
+	/* Note: Even if c == EOF, we need to initialize/verify the
+	 * stream's orientation and ensure the stream is in reading
+	 * mode (if readable and properly oriented). */
+	if ((!__STDIO_STREAM_IS_NARROW_READING(stream)
+		 && __STDIO_STREAM_TRANS_TO_READ(stream, __FLAG_NARROW))
+		|| ((stream->__modeflags & __FLAG_UNGOT)
+			&& ((stream->__modeflags & 1) || stream->__ungot[1]))
+		) {
+		c = EOF;
+	} else if (c != EOF) {
+		__STDIO_STREAM_DISABLE_GETC(stream);
+
+		/* Flag this as a user ungot, as scanf does the necessary fixup. */
+		stream->__ungot[1] = 1;
+		stream->__ungot[(++stream->__modeflags) & 1] = c;
+
+		__STDIO_STREAM_CLEAR_EOF(stream); /* Must clear end-of-file flag. */
+	}
+
+	__STDIO_STREAM_VALIDATE(stream);
+	__STDIO_AUTO_THREADUNLOCK(stream);
+
+	return c;
+}
+libc_hidden_def(ungetc)
diff --git a/ap/build/uClibc/libc/stdio/ungetwc.c b/ap/build/uClibc/libc/stdio/ungetwc.c
new file mode 100644
index 0000000..25b12b8
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/ungetwc.c
@@ -0,0 +1,49 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+
+/* Note: This is the application-callable ungetwc.  If wscanf calls this, it
+ * should also set stream->__ungot[1] to 0 if this is the only ungot, as well
+ * as reset stream->__ungot_width[1] for use by _stdio_adjpos().
+ */
+
+wint_t ungetwc(wint_t c, register FILE *stream)
+{
+	__STDIO_AUTO_THREADLOCK_VAR;
+
+	__STDIO_AUTO_THREADLOCK(stream);
+	__STDIO_STREAM_VALIDATE(stream); /* debugging only */
+
+	/* Note: Even if c == WEOF, we need to initialize/verify the
+	 * stream's orientation and ensure the stream is in reading
+	 * mode (if readable and properly oriented). */
+	if ((!__STDIO_STREAM_IS_WIDE_READING(stream)
+		 && __STDIO_STREAM_TRANS_TO_READ(stream, __FLAG_WIDE))
+		|| ((stream->__modeflags & __FLAG_UNGOT)
+			&& ((stream->__modeflags & 1) || stream->__ungot[1]))
+		|| (c == WEOF)
+		) {
+		c = WEOF;
+	} else {
+		/* In the wide case, getc macros should already be disabled. */
+		/* 	__STDIO_STREAM_DISABLE_GETC(stream); */
+
+		/* Flag this as a user ungot, as scanf does the necessary fixup. */
+		stream->__ungot[1] = 1;
+		stream->__ungot[(++stream->__modeflags) & 1] = c;
+		/* Note: ungot_width is handled by fgetwc. */
+
+		__STDIO_STREAM_CLEAR_EOF(stream); /* Must clear end-of-file flag. */
+	}
+
+	__STDIO_STREAM_VALIDATE(stream);
+	__STDIO_AUTO_THREADUNLOCK(stream);
+
+	return c;
+}
+libc_hidden_def(ungetwc)
diff --git a/ap/build/uClibc/libc/stdio/vasprintf.c b/ap/build/uClibc/libc/stdio/vasprintf.c
new file mode 100644
index 0000000..a901ee8
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/vasprintf.c
@@ -0,0 +1,82 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include <features.h>
+
+#ifdef __USE_GNU
+#include "_stdio.h"
+#include <stdarg.h>
+#include <bits/uClibc_va_copy.h>
+
+
+#ifdef __UCLIBC_MJN3_ONLY__
+/* Do the memstream stuff inline to avoid fclose and the openlist? */
+#warning CONSIDER: avoid open_memstream call?
+#endif
+
+#ifndef __STDIO_HAS_VSNPRINTF
+#warning Skipping vasprintf since no vsnprintf!
+#else
+
+int vasprintf(char **__restrict buf, const char * __restrict format,
+			 va_list arg)
+{
+#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
+
+	FILE *f;
+	size_t size;
+	int rv = -1;
+
+	*buf = NULL;
+
+	if ((f = open_memstream(buf, &size)) != NULL) {
+		rv = vfprintf(f, format, arg);
+		fclose(f);
+		if (rv < 0) {
+			free(*buf);
+			*buf = NULL;
+		}
+	}
+
+	assert(rv >= -1);
+
+	return rv;
+
+#else  /* __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ */
+
+	/* This implementation actually calls the printf machinery twice, but
+	 * only does one malloc.  This can be a problem though when custom printf
+	 * specs or the %m specifier are involved because the results of the
+	 * second call might be different from the first. */
+	va_list arg2;
+	int rv;
+
+	va_copy(arg2, arg);
+ 	rv = vsnprintf(NULL, 0, format, arg2);
+	va_end(arg2);
+
+	*buf = NULL;
+
+	if (rv >= 0) {
+		if ((*buf = malloc(++rv)) != NULL) {
+			if ((rv = vsnprintf(*buf, rv, format, arg)) < 0) {
+				free(*buf);
+				*buf = NULL;
+			}
+		}
+	}
+
+	assert(rv >= -1);
+
+	return rv;
+
+#endif /* __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ */
+}
+libc_hidden_def(vasprintf)
+
+#endif
+#endif
diff --git a/ap/build/uClibc/libc/stdio/vdprintf.c b/ap/build/uClibc/libc/stdio/vdprintf.c
new file mode 100644
index 0000000..457018b
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/vdprintf.c
@@ -0,0 +1,74 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include <features.h>
+
+#ifdef __USE_GNU
+#include "_stdio.h"
+#include <stdarg.h>
+
+
+int vdprintf(int filedes, const char * __restrict format, va_list arg)
+{
+	FILE f;
+	int rv;
+#ifdef __STDIO_BUFFERS
+	char buf[64];				/* TODO: provide _optional_ buffering? */
+
+	f.__bufend = (unsigned char *) buf + sizeof(buf);
+	f.__bufstart = (unsigned char *) buf;
+	__STDIO_STREAM_DISABLE_GETC(&f);
+	__STDIO_STREAM_DISABLE_PUTC(&f);
+	__STDIO_STREAM_INIT_BUFREAD_BUFPOS(&f);
+#endif
+
+/* 	__STDIO_STREAM_RESET_GCS(&f); */
+#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
+	f.__cookie = &(f.__filedes);
+	f.__gcs.read = NULL;
+	f.__gcs.write = _cs_write;
+	f.__gcs.seek = NULL;
+	f.__gcs.close = NULL;
+#endif
+
+	f.__filedes = filedes;
+	f.__modeflags = (__FLAG_NARROW|__FLAG_WRITEONLY|__FLAG_WRITING);
+
+#ifdef __UCLIBC_HAS_WCHAR__
+	f.__ungot_width[0] = 0;
+#endif
+#ifdef __STDIO_MBSTATE
+	__INIT_MBSTATE(&(f.__state));
+#endif
+
+/* _vfprintf_internal doesn't do any locking, locking init is here
+ * only because of fflush_unlocked. TODO? */
+#if (defined(__STDIO_BUFFERS) || defined(__USE_OLD_VFPRINTF__)) && defined(__UCLIBC_HAS_THREADS__)
+	f.__user_locking = 1;		/* Set user locking. */
+	STDIO_INIT_MUTEX(f.__lock);
+#endif
+	f.__nextopen = NULL;
+
+#ifdef __USE_OLD_VFPRINTF__
+	rv = vfprintf(&f, format, arg);
+#else
+	rv = _vfprintf_internal(&f, format, arg);
+#endif
+
+#ifdef __STDIO_BUFFERS
+	/* If not buffering, then fflush is unnecessary. */
+	if ((rv > 0) && fflush_unlocked(&f)) {
+		rv = -1;
+	}
+#endif
+
+	assert(rv >= -1);
+
+	return rv;
+}
+libc_hidden_def(vdprintf)
+#endif
diff --git a/ap/build/uClibc/libc/stdio/vfprintf.c b/ap/build/uClibc/libc/stdio/vfprintf.c
new file mode 100644
index 0000000..78b725f
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/vfprintf.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define L_vfprintf
+#include "_vfprintf.c"
diff --git a/ap/build/uClibc/libc/stdio/vfscanf.c b/ap/build/uClibc/libc/stdio/vfscanf.c
new file mode 100644
index 0000000..b13ff8d
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/vfscanf.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define L_vfscanf
+#include "_scanf.c"
diff --git a/ap/build/uClibc/libc/stdio/vfwprintf.c b/ap/build/uClibc/libc/stdio/vfwprintf.c
new file mode 100644
index 0000000..323b900
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/vfwprintf.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define L_vfwprintf
+#include "_vfprintf.c"
diff --git a/ap/build/uClibc/libc/stdio/vfwscanf.c b/ap/build/uClibc/libc/stdio/vfwscanf.c
new file mode 100644
index 0000000..ac982b4
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/vfwscanf.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define L_vfwscanf
+#include "_scanf.c"
diff --git a/ap/build/uClibc/libc/stdio/vprintf.c b/ap/build/uClibc/libc/stdio/vprintf.c
new file mode 100644
index 0000000..853f340
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/vprintf.c
@@ -0,0 +1,15 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+#include <stdarg.h>
+
+
+int vprintf(const char * __restrict format, va_list arg)
+{
+	return vfprintf(stdout, format, arg);
+}
diff --git a/ap/build/uClibc/libc/stdio/vscanf.c b/ap/build/uClibc/libc/stdio/vscanf.c
new file mode 100644
index 0000000..834fe92
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/vscanf.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define L_vscanf
+#include "_scanf.c"
diff --git a/ap/build/uClibc/libc/stdio/vsnprintf.c b/ap/build/uClibc/libc/stdio/vsnprintf.c
new file mode 100644
index 0000000..31adc52
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/vsnprintf.c
@@ -0,0 +1,216 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+#include <stdarg.h>
+
+
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning WISHLIST: Implement vsnprintf for non-buffered and no custom stream case.
+#endif /* __UCLIBC_MJN3_ONLY__ */
+
+#ifdef __STDIO_BUFFERS
+/* NB: we can still have __USE_OLD_VFPRINTF__ defined in this case! */
+
+int vsnprintf(char *__restrict buf, size_t size,
+			  const char * __restrict format, va_list arg)
+{
+	FILE f;
+	int rv;
+
+/* 	__STDIO_STREAM_RESET_GCS(&f); */
+#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
+	f.__cookie = &(f.__filedes);
+	f.__gcs.read = NULL;
+	f.__gcs.write = NULL;
+	f.__gcs.seek = NULL;
+	f.__gcs.close = NULL;
+#endif
+
+	f.__filedes = __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES;
+	f.__modeflags = (__FLAG_NARROW|__FLAG_WRITEONLY|__FLAG_WRITING);
+
+#ifdef __UCLIBC_HAS_WCHAR__
+	f.__ungot_width[0] = 0;
+#endif /* __UCLIBC_HAS_WCHAR__ */
+#ifdef __STDIO_MBSTATE
+	__INIT_MBSTATE(&(f.__state));
+#endif /* __STDIO_MBSTATE */
+
+#if (defined(__STDIO_BUFFERS) || defined(__USE_OLD_VFPRINTF__)) && defined(__UCLIBC_HAS_THREADS__)
+	f.__user_locking = 1;		/* Set user locking. */
+	STDIO_INIT_MUTEX(f.__lock);
+#endif
+	f.__nextopen = NULL;
+
+	if (size > SIZE_MAX - (size_t) buf) {
+		size = SIZE_MAX - (size_t) buf;
+	}
+
+/* TODO: this comment seems to be wrong */
+	/* Set these last since __bufputc initialization depends on
+	 * __user_locking and only gets set if user locking is on. */
+	f.__bufstart = (unsigned char *) buf;
+	f.__bufend = (unsigned char *) buf + size;
+	__STDIO_STREAM_INIT_BUFREAD_BUFPOS(&f);
+	__STDIO_STREAM_DISABLE_GETC(&f);
+	__STDIO_STREAM_ENABLE_PUTC(&f);
+
+#ifdef __USE_OLD_VFPRINTF__
+	rv = vfprintf(&f, format, arg);
+#else
+	rv = _vfprintf_internal(&f, format, arg);
+#endif
+	if (size) {
+		if (f.__bufpos == f.__bufend) {
+			--f.__bufpos;
+		}
+		*f.__bufpos = 0;
+	}
+	return rv;
+}
+libc_hidden_def(vsnprintf)
+
+#elif defined(__USE_OLD_VFPRINTF__)
+
+typedef struct {
+	FILE f;
+	unsigned char *bufend;		/* pointer to 1 past end of buffer */
+	unsigned char *bufpos;
+} __FILE_vsnprintf;
+
+int vsnprintf(char *__restrict buf, size_t size,
+			  const char * __restrict format, va_list arg)
+{
+	__FILE_vsnprintf f;
+	int rv;
+
+	f.bufpos = buf;
+
+	if (size > SIZE_MAX - (size_t) buf) {
+		size = SIZE_MAX - (size_t) buf;
+	}
+	f.bufend = buf + size;
+
+/* 	__STDIO_STREAM_RESET_GCS(&f.f); */
+#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
+	f.f.__cookie = &(f.f.__filedes);
+	f.f.__gcs.read = NULL;
+	f.f.__gcs.write = NULL;
+	f.f.__gcs.seek = NULL;
+	f.f.__gcs.close = NULL;
+#endif
+
+	f.f.__filedes = __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES_NB;
+	f.f.__modeflags = (__FLAG_NARROW|__FLAG_WRITEONLY|__FLAG_WRITING);
+
+#ifdef __UCLIBC_HAS_WCHAR__
+	f.f.__ungot_width[0] = 0;
+#endif /* __UCLIBC_HAS_WCHAR__ */
+#ifdef __STDIO_MBSTATE
+	__INIT_MBSTATE(&(f.f.__state));
+#endif /* __STDIO_MBSTATE */
+
+#ifdef __UCLIBC_HAS_THREADS__
+	f.f.__user_locking = 1;		/* Set user locking. */
+	STDIO_INIT_MUTEX(f.f.__lock);
+#endif
+	f.f.__nextopen = NULL;
+
+	rv = vfprintf((FILE *) &f, format, arg);
+	if (size) {
+		if (f.bufpos == f.bufend) {
+			--f.bufpos;
+		}
+		*f.bufpos = 0;
+	}
+	return rv;
+}
+libc_hidden_def(vsnprintf)
+
+#elif defined(__UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__)
+
+typedef struct {
+	size_t pos;
+	size_t len;
+	unsigned char *buf;
+	FILE *fp;
+} __snpf_cookie;
+
+#define COOKIE ((__snpf_cookie *) cookie)
+
+static ssize_t snpf_write(register void *cookie, const char *buf,
+						  size_t bufsize)
+{
+	size_t count;
+	register char *p;
+
+	/* Note: bufsize < SSIZE_MAX because of _stdio_WRITE. */
+
+	if (COOKIE->len > COOKIE->pos) {
+		count = COOKIE->len - COOKIE->pos - 1; /* Leave space for nul. */
+		if (count > bufsize) {
+			count = bufsize;
+		}
+
+		p = COOKIE->buf + COOKIE->pos;
+		while (count) {
+			*p++ = *buf++;
+			--count;
+		}
+		*p = 0;
+	}
+
+	COOKIE->pos += bufsize;
+
+	return bufsize;
+}
+
+#undef COOKIE
+
+int vsnprintf(char *__restrict buf, size_t size,
+			  const char * __restrict format, va_list arg)
+{
+	FILE f;
+	__snpf_cookie cookie;
+	int rv;
+
+	cookie.buf = buf;
+	cookie.len = size;
+	cookie.pos = 0;
+	cookie.fp = &f;
+
+	f.__cookie = &cookie;
+	f.__gcs.write = snpf_write;
+	f.__gcs.read = NULL;
+	f.__gcs.seek = NULL;
+	f.__gcs.close = NULL;
+
+	f.__filedes = -1;			/* For debugging. */
+	f.__modeflags = (__FLAG_NARROW|__FLAG_WRITEONLY|__FLAG_WRITING);
+
+#ifdef __UCLIBC_HAS_WCHAR__
+	f.__ungot_width[0] = 0;
+#endif /* __UCLIBC_HAS_WCHAR__ */
+#ifdef __STDIO_MBSTATE
+	__INIT_MBSTATE(&(f.__state));
+#endif /* __STDIO_MBSTATE */
+
+	f.__nextopen = NULL;
+
+	rv = _vfprintf_internal(&f, format, arg);
+
+	return rv;
+}
+libc_hidden_def(vsnprintf)
+
+#else
+#warning Skipping vsnprintf since no buffering, no custom streams, and not old vfprintf!
+#ifdef __STDIO_HAS_VSNPRINTF
+#error WHOA! __STDIO_HAS_VSNPRINTF is defined!
+#endif
+#endif
diff --git a/ap/build/uClibc/libc/stdio/vsprintf.c b/ap/build/uClibc/libc/stdio/vsprintf.c
new file mode 100644
index 0000000..d870901
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/vsprintf.c
@@ -0,0 +1,22 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+#include <stdarg.h>
+
+#ifndef __STDIO_HAS_VSNPRINTF
+#warning Skipping vsprintf since no vsnprintf!
+#else
+
+
+int vsprintf(char *__restrict buf, const char * __restrict format,
+			 va_list arg)
+{
+	return vsnprintf(buf, SIZE_MAX, format, arg);
+}
+
+#endif
diff --git a/ap/build/uClibc/libc/stdio/vsscanf.c b/ap/build/uClibc/libc/stdio/vsscanf.c
new file mode 100644
index 0000000..882c271
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/vsscanf.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define L_vsscanf
+#include "_scanf.c"
diff --git a/ap/build/uClibc/libc/stdio/vswprintf.c b/ap/build/uClibc/libc/stdio/vswprintf.c
new file mode 100644
index 0000000..2195248
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/vswprintf.c
@@ -0,0 +1,75 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+#include <stdarg.h>
+#include <wchar.h>
+
+
+/* NB: this file is not used if __USE_OLD_VFPRINTF__ */
+
+#ifndef __STDIO_BUFFERS
+#warning Skipping vswprintf since no buffering!
+#else  /* __STDIO_BUFFERS */
+
+int vswprintf(wchar_t *__restrict buf, size_t size,
+			  const wchar_t * __restrict format, va_list arg)
+{
+	FILE f;
+	int rv;
+
+/* 	__STDIO_STREAM_RESET_GCS(&f); */
+#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
+	f.__cookie = &(f.__filedes);
+	f.__gcs.read = NULL;
+	f.__gcs.write = NULL;
+	f.__gcs.seek = NULL;
+	f.__gcs.close = NULL;
+#endif
+
+	f.__filedes = __STDIO_STREAM_FAKE_VSWPRINTF_FILEDES;
+	f.__modeflags = (__FLAG_WIDE|__FLAG_WRITEONLY|__FLAG_WRITING);
+
+	f.__ungot_width[0] = 0;
+#ifdef __STDIO_MBSTATE
+	__INIT_MBSTATE(&(f.__state));
+#endif /* __STDIO_MBSTATE */
+
+#ifdef __UCLIBC_HAS_THREADS__
+	f.__user_locking = 1;		/* Set user locking. */
+	STDIO_INIT_MUTEX(f.__lock);
+#endif /* __UCLIBC_HAS_THREADS__ */
+
+	f.__nextopen = NULL;
+
+	if (size > ((SIZE_MAX - (size_t) buf)/sizeof(wchar_t))) {
+		size = ((SIZE_MAX - (size_t) buf)/sizeof(wchar_t));
+	}
+
+	f.__bufstart = (unsigned char *) buf;
+	f.__bufend = (unsigned char *) (buf + size);
+	__STDIO_STREAM_INIT_BUFREAD_BUFPOS(&f);
+	__STDIO_STREAM_DISABLE_GETC(&f);
+	__STDIO_STREAM_DISABLE_PUTC(&f);
+
+	rv = _vfwprintf_internal(&f, format, arg);
+
+	/* NOTE: Return behaviour differs from snprintf... */
+	if (f.__bufpos == f.__bufend) {
+		rv = -1;
+		if (size) {
+			f.__bufpos = (unsigned char *) (((wchar_t *) f.__bufpos) - 1);
+		}
+	}
+	if (size) {
+		*((wchar_t *) f.__bufpos) = 0;
+	}
+	return rv;
+}
+libc_hidden_def(vswprintf)
+
+#endif /* __STDIO_BUFFERS */
diff --git a/ap/build/uClibc/libc/stdio/vswscanf.c b/ap/build/uClibc/libc/stdio/vswscanf.c
new file mode 100644
index 0000000..fddb602
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/vswscanf.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define L_vswscanf
+#include "_scanf.c"
diff --git a/ap/build/uClibc/libc/stdio/vwprintf.c b/ap/build/uClibc/libc/stdio/vwprintf.c
new file mode 100644
index 0000000..25dd5b3
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/vwprintf.c
@@ -0,0 +1,16 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+#include <stdarg.h>
+#include <wchar.h>
+
+
+int vwprintf(const wchar_t * __restrict format, va_list arg)
+{
+	return vfwprintf(stdout, format, arg);
+}
diff --git a/ap/build/uClibc/libc/stdio/vwscanf.c b/ap/build/uClibc/libc/stdio/vwscanf.c
new file mode 100644
index 0000000..9e21a27
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/vwscanf.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define L_vwscanf
+#include "_scanf.c"
diff --git a/ap/build/uClibc/libc/stdio/wprintf.c b/ap/build/uClibc/libc/stdio/wprintf.c
new file mode 100644
index 0000000..b3a6318
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/wprintf.c
@@ -0,0 +1,24 @@
+/* Copyright (C) 2004       Manuel Novoa III    <mjn3@codepoet.org>
+ *
+ * GNU Library General Public License (LGPL) version 2 or later.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+
+#include "_stdio.h"
+#include <stdarg.h>
+#include <wchar.h>
+
+
+int wprintf(const wchar_t * __restrict format, ...)
+{
+	va_list arg;
+	int rv;
+
+	va_start(arg, format);
+	rv = vfwprintf(stdout, format, arg);
+	va_end(arg);
+
+	return rv;
+}
+
diff --git a/ap/build/uClibc/libc/stdio/wscanf.c b/ap/build/uClibc/libc/stdio/wscanf.c
new file mode 100644
index 0000000..d354d52
--- /dev/null
+++ b/ap/build/uClibc/libc/stdio/wscanf.c
@@ -0,0 +1,9 @@
+/* Copyright (C) 2004      Manuel Novoa III <mjn3@uclibc.org>
+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
+ *
+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
+ *
+ * Dedicated to Toni.  See uClibc/DEDICATION.mjn3 for details.
+ */
+#define L_wscanf
+#include "_scanf.c"