Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'newlib/libc/reent')
-rw-r--r--newlib/libc/reent/Makefile.am55
-rw-r--r--newlib/libc/reent/Makefile.in329
-rw-r--r--newlib/libc/reent/closer.c58
-rw-r--r--newlib/libc/reent/execr.c144
-rw-r--r--newlib/libc/reent/fstatr.c66
-rw-r--r--newlib/libc/reent/impure.c13
-rw-r--r--newlib/libc/reent/linkr.c102
-rw-r--r--newlib/libc/reent/lseekr.c63
-rw-r--r--newlib/libc/reent/openr.c64
-rw-r--r--newlib/libc/reent/readr.c63
-rw-r--r--newlib/libc/reent/reent.c107
-rw-r--r--newlib/libc/reent/reent.tex108
-rw-r--r--newlib/libc/reent/sbrkr.c66
-rw-r--r--newlib/libc/reent/signalr.c98
-rw-r--r--newlib/libc/reent/statr.c67
-rw-r--r--newlib/libc/reent/timer.c112
-rw-r--r--newlib/libc/reent/writer.c63
17 files changed, 1578 insertions, 0 deletions
diff --git a/newlib/libc/reent/Makefile.am b/newlib/libc/reent/Makefile.am
new file mode 100644
index 000000000..20baf3f24
--- /dev/null
+++ b/newlib/libc/reent/Makefile.am
@@ -0,0 +1,55 @@
+## Process this file with automake to generate Makefile.in
+
+AUTOMAKE_OPTIONS = cygnus
+
+INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
+
+noinst_LIBRARIES = lib.a
+
+lib_a_SOURCES = \
+ closer.c \
+ reent.c \
+ impure.c \
+ execr.c \
+ fstatr.c \
+ linkr.c \
+ lseekr.c \
+ openr.c \
+ readr.c \
+ signalr.c \
+ sbrkr.c \
+ statr.c \
+ timer.c \
+ writer.c
+
+CHEWOUT_FILES = \
+ closer.def \
+ reent.def \
+ execr.def \
+ fstatr.def \
+ linkr.def \
+ lseekr.def \
+ openr.def \
+ readr.def \
+ signalr.def \
+ sbrkr.def \
+ statr.def \
+ timer.def \
+ writer.def
+
+SUFFIXES = .def .h
+
+CHEW = ../../doc/makedoc -f $(srcdir)/../../doc/doc.str
+
+.c.def:
+ $(CHEW) < $< > $*.def 2> $*.ref
+ touch stmp-def
+
+TARGETDOC = ../tmp.texi
+
+doc: $(CHEWOUT_FILES)
+ cat $(srcdir)/reent.tex >> $(TARGETDOC)
+
+impure.o: $(srcdir)/impure.c $(srcdir)/../include/sys/reent.h
+
+CLEANFILES = $(CHEWOUT_FILES) *.ref
diff --git a/newlib/libc/reent/Makefile.in b/newlib/libc/reent/Makefile.in
new file mode 100644
index 000000000..ad174b184
--- /dev/null
+++ b/newlib/libc/reent/Makefile.in
@@ -0,0 +1,329 @@
+# Makefile.in generated automatically by automake 1.4 from Makefile.am
+
+# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+
+SHELL = @SHELL@
+
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+VPATH = @srcdir@
+prefix = @prefix@
+exec_prefix = @exec_prefix@
+
+bindir = @bindir@
+sbindir = @sbindir@
+libexecdir = @libexecdir@
+datadir = @datadir@
+sysconfdir = @sysconfdir@
+sharedstatedir = @sharedstatedir@
+localstatedir = @localstatedir@
+libdir = @libdir@
+infodir = @infodir@
+mandir = @mandir@
+includedir = @includedir@
+oldincludedir = /usr/include
+
+DESTDIR =
+
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+
+top_builddir = ..
+
+ACLOCAL = @ACLOCAL@
+AUTOCONF = @AUTOCONF@
+AUTOMAKE = @AUTOMAKE@
+AUTOHEADER = @AUTOHEADER@
+
+INSTALL = @INSTALL@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS)
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+transform = @program_transform_name@
+
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+host_alias = @host_alias@
+host_triplet = @host@
+AR = @AR@
+AS = @AS@
+CC = @CC@
+CPP = @CPP@
+CRT0 = @CRT0@
+EXEEXT = @EXEEXT@
+LIBC_MACHINE_LIB = @LIBC_MACHINE_LIB@
+LIBC_POSIX_LIB = @LIBC_POSIX_LIB@
+LIBC_SIGNAL_DEF = @LIBC_SIGNAL_DEF@
+LIBC_SIGNAL_LIB = @LIBC_SIGNAL_LIB@
+LIBC_SYSCALL_LIB = @LIBC_SYSCALL_LIB@
+LIBC_SYS_LIB = @LIBC_SYS_LIB@
+LIBC_UNIX_LIB = @LIBC_UNIX_LIB@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+NEWLIB_CFLAGS = @NEWLIB_CFLAGS@
+PACKAGE = @PACKAGE@
+RANLIB = @RANLIB@
+VERSION = @VERSION@
+machine_dir = @machine_dir@
+newlib_basedir = @newlib_basedir@
+sys_dir = @sys_dir@
+
+AUTOMAKE_OPTIONS = cygnus
+
+INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
+
+noinst_LIBRARIES = lib.a
+
+lib_a_SOURCES = \
+ closer.c \
+ reent.c \
+ impure.c \
+ execr.c \
+ fstatr.c \
+ linkr.c \
+ lseekr.c \
+ openr.c \
+ readr.c \
+ signalr.c \
+ sbrkr.c \
+ statr.c \
+ timer.c \
+ writer.c
+
+
+CHEWOUT_FILES = \
+ closer.def \
+ reent.def \
+ execr.def \
+ fstatr.def \
+ linkr.def \
+ lseekr.def \
+ openr.def \
+ readr.def \
+ signalr.def \
+ sbrkr.def \
+ statr.def \
+ timer.def \
+ writer.def
+
+
+SUFFIXES = .def .h
+
+CHEW = ../../doc/makedoc -f $(srcdir)/../../doc/doc.str
+
+TARGETDOC = ../tmp.texi
+
+CLEANFILES = $(CHEWOUT_FILES) *.ref
+mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs
+CONFIG_CLEAN_FILES =
+LIBRARIES = $(noinst_LIBRARIES)
+
+
+DEFS = @DEFS@ -I. -I$(srcdir)
+CPPFLAGS = @CPPFLAGS@
+LDFLAGS = @LDFLAGS@
+LIBS = @LIBS@
+lib_a_LIBADD =
+lib_a_OBJECTS = closer.o reent.o impure.o execr.o fstatr.o linkr.o \
+lseekr.o openr.o readr.o signalr.o sbrkr.o statr.o timer.o writer.o
+CFLAGS = @CFLAGS@
+COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@
+DIST_COMMON = Makefile.am Makefile.in
+
+
+DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
+
+TAR = tar
+GZIP_ENV = --best
+SOURCES = $(lib_a_SOURCES)
+OBJECTS = $(lib_a_OBJECTS)
+
+all: all-redirect
+.SUFFIXES:
+.SUFFIXES: .S .c .def .h .o .s
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4)
+ cd $(top_srcdir) && $(AUTOMAKE) --cygnus reent/Makefile
+
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ cd $(top_builddir) \
+ && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
+
+
+mostlyclean-noinstLIBRARIES:
+
+clean-noinstLIBRARIES:
+ -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
+
+distclean-noinstLIBRARIES:
+
+maintainer-clean-noinstLIBRARIES:
+
+.c.o:
+ $(COMPILE) -c $<
+
+.s.o:
+ $(COMPILE) -c $<
+
+.S.o:
+ $(COMPILE) -c $<
+
+mostlyclean-compile:
+ -rm -f *.o core *.core
+
+clean-compile:
+
+distclean-compile:
+ -rm -f *.tab.c
+
+maintainer-clean-compile:
+
+lib.a: $(lib_a_OBJECTS) $(lib_a_DEPENDENCIES)
+ -rm -f lib.a
+ $(AR) cru lib.a $(lib_a_OBJECTS) $(lib_a_LIBADD)
+ $(RANLIB) lib.a
+
+tags: TAGS
+
+ID: $(HEADERS) $(SOURCES) $(LISP)
+ list='$(SOURCES) $(HEADERS)'; \
+ unique=`for i in $$list; do echo $$i; done | \
+ awk ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ here=`pwd` && cd $(srcdir) \
+ && mkid -f$$here/ID $$unique $(LISP)
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP)
+ tags=; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS)'; \
+ unique=`for i in $$list; do echo $$i; done | \
+ awk ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \
+ || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS)
+
+mostlyclean-tags:
+
+clean-tags:
+
+distclean-tags:
+ -rm -f TAGS ID
+
+maintainer-clean-tags:
+
+distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
+
+subdir = reent
+
+distdir: $(DISTFILES)
+ @for file in $(DISTFILES); do \
+ if test -f $$file; then d=.; else d=$(srcdir); fi; \
+ if test -d $$d/$$file; then \
+ cp -pr $$/$$file $(distdir)/$$file; \
+ else \
+ test -f $(distdir)/$$file \
+ || ln $$d/$$file $(distdir)/$$file 2> /dev/null \
+ || cp -p $$d/$$file $(distdir)/$$file || :; \
+ fi; \
+ done
+info-am:
+info: info-am
+dvi-am:
+dvi: dvi-am
+check-am:
+check: check-am
+installcheck-am:
+installcheck: installcheck-am
+install-info-am:
+install-info: install-info-am
+install-exec-am:
+install-exec: install-exec-am
+
+install-data-am:
+install-data: install-data-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+install: install-am
+uninstall-am:
+uninstall: uninstall-am
+all-am: Makefile $(LIBRARIES)
+all-redirect: all-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install
+installdirs:
+
+
+mostlyclean-generic:
+
+clean-generic:
+ -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES)
+
+distclean-generic:
+ -rm -f Makefile $(CONFIG_CLEAN_FILES)
+ -rm -f config.cache config.log stamp-h stamp-h[0-9]*
+
+maintainer-clean-generic:
+mostlyclean-am: mostlyclean-noinstLIBRARIES mostlyclean-compile \
+ mostlyclean-tags mostlyclean-generic
+
+mostlyclean: mostlyclean-am
+
+clean-am: clean-noinstLIBRARIES clean-compile clean-tags clean-generic \
+ mostlyclean-am
+
+clean: clean-am
+
+distclean-am: distclean-noinstLIBRARIES distclean-compile \
+ distclean-tags distclean-generic clean-am
+
+distclean: distclean-am
+
+maintainer-clean-am: maintainer-clean-noinstLIBRARIES \
+ maintainer-clean-compile maintainer-clean-tags \
+ maintainer-clean-generic distclean-am
+ @echo "This command is intended for maintainers to use;"
+ @echo "it deletes files that may require special tools to rebuild."
+
+maintainer-clean: maintainer-clean-am
+
+.PHONY: mostlyclean-noinstLIBRARIES distclean-noinstLIBRARIES \
+clean-noinstLIBRARIES maintainer-clean-noinstLIBRARIES \
+mostlyclean-compile distclean-compile clean-compile \
+maintainer-clean-compile tags mostlyclean-tags distclean-tags \
+clean-tags maintainer-clean-tags distdir info-am info dvi-am dvi check \
+check-am installcheck-am installcheck install-info-am install-info \
+install-exec-am install-exec install-data-am install-data install-am \
+install uninstall-am uninstall all-redirect all-am all installdirs \
+mostlyclean-generic distclean-generic clean-generic \
+maintainer-clean-generic clean mostlyclean distclean maintainer-clean
+
+
+.c.def:
+ $(CHEW) < $< > $*.def 2> $*.ref
+ touch stmp-def
+
+doc: $(CHEWOUT_FILES)
+ cat $(srcdir)/reent.tex >> $(TARGETDOC)
+
+impure.o: $(srcdir)/impure.c $(srcdir)/../include/sys/reent.h
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/newlib/libc/reent/closer.c b/newlib/libc/reent/closer.c
new file mode 100644
index 000000000..aeacebd6c
--- /dev/null
+++ b/newlib/libc/reent/closer.c
@@ -0,0 +1,58 @@
+/* Reentrant version of close system call. */
+
+#include <reent.h>
+#include <unistd.h>
+#include <_syslist.h>
+
+/* Some targets provides their own versions of this functions. Those
+ targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */
+
+#ifdef _REENT_ONLY
+#ifndef REENTRANT_SYSCALLS_PROVIDED
+#define REENTRANT_SYSCALLS_PROVIDED
+#endif
+#endif
+
+#ifndef REENTRANT_SYSCALLS_PROVIDED
+
+/* We use the errno variable used by the system dependent layer. */
+#undef errno
+extern int errno;
+
+/*
+FUNCTION
+ <<_close_r>>---Reentrant version of close
+
+INDEX
+ _close_r
+
+ANSI_SYNOPSIS
+ #include <reent.h>
+ int _close_r(struct _reent *<[ptr]>, int <[fd]>);
+
+TRAD_SYNOPSIS
+ #include <reent.h>
+ int _close_r(<[ptr]>, <[fd]>)
+ struct _reent *<[ptr]>;
+ int <[fd]>;
+
+DESCRIPTION
+ This is a reentrant version of <<close>>. It
+ takes a pointer to the global data block, which holds
+ <<errno>>.
+*/
+
+int
+_close_r (ptr, fd)
+ struct _reent *ptr;
+ int fd;
+{
+ int ret;
+
+ errno = 0;
+ if ((ret = _close (fd)) == -1 && errno != 0)
+ ptr->_errno = errno;
+ return ret;
+}
+
+#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */
diff --git a/newlib/libc/reent/execr.c b/newlib/libc/reent/execr.c
new file mode 100644
index 000000000..9e8f75a65
--- /dev/null
+++ b/newlib/libc/reent/execr.c
@@ -0,0 +1,144 @@
+/* Reentrant versions of execution system calls. These
+ implementations just call the usual system calls. */
+
+#include <reent.h>
+#include <unistd.h>
+#include <_syslist.h>
+
+/* Some targets provides their own versions of these functions. Those
+ targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */
+
+#ifdef _REENT_ONLY
+#ifndef REENTRANT_SYSCALLS_PROVIDED
+#define REENTRANT_SYSCALLS_PROVIDED
+#endif
+#endif
+
+/* If NO_EXEC is defined, we don't need these functions. */
+
+#if defined (REENTRANT_SYSCALLS_PROVIDED) || defined (NO_EXEC)
+
+int _dummy_exec_syscalls = 1;
+
+#else
+
+/* We use the errno variable used by the system dependent layer. */
+#undef errno
+extern int errno;
+
+/*
+FUNCTION
+ <<_execve_r>>---Reentrant version of execve
+INDEX
+ _execve_r
+
+ANSI_SYNOPSIS
+ #include <reent.h>
+ int _execve_r(struct _reent *<[ptr]>, char *<[name]>,
+ char **<[argv]>, char **<[env]>);
+
+TRAD_SYNOPSIS
+ #include <reent.h>
+ int _execve_r(<[ptr]>, <[name]>, <[argv]>, <[env]>)
+ struct _reent *<[ptr]>;
+ char *<[name]>;
+ char **<[argv]>;
+ char **<[env]>;
+
+DESCRIPTION
+ This is a reentrant version of <<execve>>. It
+ takes a pointer to the global data block, which holds
+ <<errno>>.
+*/
+
+int
+_execve_r (ptr, name, argv, env)
+ struct _reent *ptr;
+ char *name;
+ char **argv;
+ char **env;
+{
+ int ret;
+
+ errno = 0;
+ if ((ret = _execve (name, argv, env)) == -1 && errno != 0)
+ ptr->_errno = errno;
+ return ret;
+}
+
+
+/*
+FUNCTION
+ <<_fork_r>>---Reentrant version of fork
+
+INDEX
+ _fork_r
+
+ANSI_SYNOPSIS
+ #include <reent.h>
+ int _fork_r(struct _reent *<[ptr]>);
+
+TRAD_SYNOPSIS
+ #include <reent.h>
+ int _fork_r(<[ptr]>)
+ struct _reent *<[ptr]>;
+
+DESCRIPTION
+ This is a reentrant version of <<fork>>. It
+ takes a pointer to the global data block, which holds
+ <<errno>>.
+*/
+
+#ifndef NO_FORK
+
+int
+_fork_r (ptr)
+ struct _reent *ptr;
+{
+ int ret;
+
+ errno = 0;
+ if ((ret = _fork ()) == -1 && errno != 0)
+ ptr->_errno = errno;
+ return ret;
+}
+
+#endif
+
+/*
+FUNCTION
+ <<_wait_r>>---Reentrant version of wait
+
+INDEX
+ _wait_r
+
+ANSI_SYNOPSIS
+ #include <reent.h>
+ int _wait_r(struct _reent *<[ptr]>, int *<[status]>);
+
+TRAD_SYNOPSIS
+ #include <reent.h>
+ int _wait_r(<[ptr]>, <[status]>)
+ struct _reent *<[ptr]>;
+ int *<[status]>;
+
+DESCRIPTION
+ This is a reentrant version of <<wait>>. It
+ takes a pointer to the global data block, which holds
+ <<errno>>.
+*/
+
+int
+_wait_r (ptr, status)
+ struct _reent *ptr;
+ int *status;
+{
+ int ret;
+
+ errno = 0;
+ if ((ret = _wait (status)) == -1 && errno != 0)
+ ptr->_errno = errno;
+ return ret;
+}
+
+#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */
diff --git a/newlib/libc/reent/fstatr.c b/newlib/libc/reent/fstatr.c
new file mode 100644
index 000000000..df132d799
--- /dev/null
+++ b/newlib/libc/reent/fstatr.c
@@ -0,0 +1,66 @@
+/* Reentrant versions of fstat system call. This implementation just
+ calls the fstat system call. */
+
+#include <reent.h>
+#include <unistd.h>
+#include <_syslist.h>
+
+/* Some targets provides their own versions of these functions. Those
+ targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */
+
+#ifdef _REENT_ONLY
+#ifndef REENTRANT_SYSCALLS_PROVIDED
+#define REENTRANT_SYSCALLS_PROVIDED
+#endif
+#endif
+
+#ifdef REENTRANT_SYSCALLS_PROVIDED
+
+int _dummy_fstat_syscalls = 1;
+
+#else
+
+/* We use the errno variable used by the system dependent layer. */
+#undef errno
+extern int errno;
+
+/*
+FUNCTION
+ <<_fstat_r>>---Reentrant version of fstat
+
+INDEX
+ _fstat_r
+
+ANSI_SYNOPSIS
+ #include <reent.h>
+ int _fstat_r(struct _reent *<[ptr]>,
+ int <[fd]>, struct stat *<[pstat]>);
+
+TRAD_SYNOPSIS
+ #include <reent.h>
+ int _fstat_r(<[ptr]>, <[fd]>, <[pstat]>)
+ struct _reent *<[ptr]>;
+ int <[fd]>;
+ struct stat *<[pstat]>;
+
+DESCRIPTION
+ This is a reentrant version of <<fstat>>. It
+ takes a pointer to the global data block, which holds
+ <<errno>>.
+*/
+
+int
+_fstat_r (ptr, fd, pstat)
+ struct _reent *ptr;
+ int fd;
+ struct stat *pstat;
+{
+ int ret;
+
+ errno = 0;
+ if ((ret = _fstat (fd, pstat)) == -1 && errno != 0)
+ ptr->_errno = errno;
+ return ret;
+}
+
+#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */
diff --git a/newlib/libc/reent/impure.c b/newlib/libc/reent/impure.c
new file mode 100644
index 000000000..a14f5c3cd
--- /dev/null
+++ b/newlib/libc/reent/impure.c
@@ -0,0 +1,13 @@
+#include <reent.h>
+
+/* Note that there is a copy of this in sys/reent.h. */
+#ifndef __ATTRIBUTE_IMPURE_PTR__
+#define __ATTRIBUTE_IMPURE_PTR__
+#endif
+
+#ifndef __ATTRIBUTE_IMPURE_DATA__
+#define __ATTRIBUTE_IMPURE_DATA__
+#endif
+
+static struct _reent __ATTRIBUTE_IMPURE_DATA__ impure_data = _REENT_INIT (impure_data);
+struct _reent *__ATTRIBUTE_IMPURE_PTR__ _impure_ptr = &impure_data;
diff --git a/newlib/libc/reent/linkr.c b/newlib/libc/reent/linkr.c
new file mode 100644
index 000000000..a15d2238c
--- /dev/null
+++ b/newlib/libc/reent/linkr.c
@@ -0,0 +1,102 @@
+/* Reentrant versions of file system calls. These implementations
+ just call the usual system calls. */
+
+#include <reent.h>
+#include <unistd.h>
+#include <_syslist.h>
+
+/* Some targets provides their own versions of these functions. Those
+ targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */
+
+#ifdef _REENT_ONLY
+#ifndef REENTRANT_SYSCALLS_PROVIDED
+#define REENTRANT_SYSCALLS_PROVIDED
+#endif
+#endif
+
+#ifdef REENTRANT_SYSCALLS_PROVIDED
+
+int _dummy_link_syscalls = 1;
+
+#else
+
+/* We use the errno variable used by the system dependent layer. */
+#undef errno
+extern int errno;
+
+/*
+FUNCTION
+ <<_link_r>>---Reentrant version of link
+
+INDEX
+ _link_r
+
+ANSI_SYNOPSIS
+ #include <reent.h>
+ int _link_r(struct _reent *<[ptr]>,
+ const char *<[old]>, const char *<[new]>);
+
+TRAD_SYNOPSIS
+ #include <reent.h>
+ int _link_r(<[ptr]>, <[old]>, <[new]>)
+ struct _reent *<[ptr]>;
+ char *<[old]>;
+ char *<[new]>;
+
+DESCRIPTION
+ This is a reentrant version of <<link>>. It
+ takes a pointer to the global data block, which holds
+ <<errno>>.
+*/
+
+int
+_link_r (ptr, old, new)
+ struct _reent *ptr;
+ _CONST char *old;
+ _CONST char *new;
+{
+ int ret;
+
+ errno = 0;
+ if ((ret = _link (old, new)) == -1 && errno != 0)
+ ptr->_errno = errno;
+ return ret;
+}
+
+/*
+FUNCTION
+ <<_unlink_r>>---Reentrant version of unlink
+
+INDEX
+ _unlink_r
+
+ANSI_SYNOPSIS
+ #include <reent.h>
+ int _unlink_r(struct _reent *<[ptr]>, const char *<[file]>);
+
+TRAD_SYNOPSIS
+ #include <reent.h>
+ int _unlink_r(<[ptr]>, <[file]>)
+ struct _reent *<[ptr]>;
+ char *<[file]>;
+
+DESCRIPTION
+ This is a reentrant version of <<unlink>>. It
+ takes a pointer to the global data block, which holds
+ <<errno>>.
+*/
+
+int
+_unlink_r (ptr, file)
+ struct _reent *ptr;
+ _CONST char *file;
+{
+ int ret;
+
+ errno = 0;
+ if ((ret = _unlink (file)) == -1 && errno != 0)
+ ptr->_errno = errno;
+ return ret;
+}
+
+#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */
diff --git a/newlib/libc/reent/lseekr.c b/newlib/libc/reent/lseekr.c
new file mode 100644
index 000000000..ed8ba13ed
--- /dev/null
+++ b/newlib/libc/reent/lseekr.c
@@ -0,0 +1,63 @@
+/* Reentrant versions of lseek system call. */
+
+#include <reent.h>
+#include <unistd.h>
+#include <_syslist.h>
+
+/* Some targets provides their own versions of this functions. Those
+ targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */
+
+#ifdef _REENT_ONLY
+#ifndef REENTRANT_SYSCALLS_PROVIDED
+#define REENTRANT_SYSCALLS_PROVIDED
+#endif
+#endif
+
+#ifndef REENTRANT_SYSCALLS_PROVIDED
+
+/* We use the errno variable used by the system dependent layer. */
+#undef errno
+extern int errno;
+
+/*
+FUNCTION
+ <<_lseek_r>>---Reentrant version of lseek
+
+INDEX
+ _lseek_r
+
+ANSI_SYNOPSIS
+ #include <reent.h>
+ off_t _lseek_r(struct _reent *<[ptr]>,
+ int <[fd]>, off_t <[pos]>, int <[whence]>);
+
+TRAD_SYNOPSIS
+ #include <reent.h>
+ off_t _lseek_r(<[ptr]>, <[fd]>, <[pos]>, <[whence]>)
+ struct _reent *<[ptr]>;
+ int <[fd]>;
+ off_t <[pos]>;
+ int <[whence]>;
+
+DESCRIPTION
+ This is a reentrant version of <<lseek>>. It
+ takes a pointer to the global data block, which holds
+ <<errno>>.
+*/
+
+off_t
+_lseek_r (ptr, fd, pos, whence)
+ struct _reent *ptr;
+ int fd;
+ off_t pos;
+ int whence;
+{
+ off_t ret;
+
+ errno = 0;
+ if ((ret = _lseek (fd, pos, whence)) == (off_t) -1 && errno != 0)
+ ptr->_errno = errno;
+ return ret;
+}
+
+#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */
diff --git a/newlib/libc/reent/openr.c b/newlib/libc/reent/openr.c
new file mode 100644
index 000000000..2e3b608d7
--- /dev/null
+++ b/newlib/libc/reent/openr.c
@@ -0,0 +1,64 @@
+/* Reentrant versions of open system call. */
+
+#include <reent.h>
+#include <unistd.h>
+#include <_syslist.h>
+
+/* Some targets provides their own versions of this functions. Those
+ targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */
+
+#ifdef _REENT_ONLY
+#ifndef REENTRANT_SYSCALLS_PROVIDED
+#define REENTRANT_SYSCALLS_PROVIDED
+#endif
+#endif
+
+#ifndef REENTRANT_SYSCALLS_PROVIDED
+
+/* We use the errno variable used by the system dependent layer. */
+#undef errno
+extern int errno;
+
+/*
+FUNCTION
+ <<_open_r>>---Reentrant version of open
+
+INDEX
+ _open_r
+
+ANSI_SYNOPSIS
+ #include <reent.h>
+ int _open_r(struct _reent *<[ptr]>,
+ const char *<[file]>, int <[flags]>, int <[mode]>);
+
+TRAD_SYNOPSIS
+ #include <reent.h>
+ int _open_r(<[ptr]>, <[file]>, <[flags]>, <[mode]>)
+ struct _reent *<[ptr]>;
+ char *<[file]>;
+ int <[flags]>;
+ int <[mode]>;
+
+DESCRIPTION
+ This is a reentrant version of <<open>>. It
+ takes a pointer to the global data block, which holds
+ <<errno>>.
+*/
+
+int
+_open_r (ptr, file, flags, mode)
+ struct _reent *ptr;
+ _CONST char *file;
+ int flags;
+ int mode;
+{
+ int ret;
+
+ errno = 0;
+ if ((ret = _open (file, flags, mode)) == -1 && errno != 0)
+ ptr->_errno = errno;
+ return ret;
+}
+
+
+#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */
diff --git a/newlib/libc/reent/readr.c b/newlib/libc/reent/readr.c
new file mode 100644
index 000000000..e3deca9a7
--- /dev/null
+++ b/newlib/libc/reent/readr.c
@@ -0,0 +1,63 @@
+/* Reentrant versions of read system call. */
+
+#include <reent.h>
+#include <unistd.h>
+#include <_syslist.h>
+
+/* Some targets provides their own versions of this functions. Those
+ targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */
+
+#ifdef _REENT_ONLY
+#ifndef REENTRANT_SYSCALLS_PROVIDED
+#define REENTRANT_SYSCALLS_PROVIDED
+#endif
+#endif
+
+#ifndef REENTRANT_SYSCALLS_PROVIDED
+
+/* We use the errno variable used by the system dependent layer. */
+#undef errno
+extern int errno;
+
+/*
+FUNCTION
+ <<_read_r>>---Reentrant version of read
+
+INDEX
+ _read_r
+
+ANSI_SYNOPSIS
+ #include <reent.h>
+ long _read_r(struct _reent *<[ptr]>,
+ int <[fd]>, void *<[buf]>, size_t <[cnt]>);
+
+TRAD_SYNOPSIS
+ #include <reent.h>
+ long _read_r(<[ptr]>, <[fd]>, <[buf]>, <[cnt]>)
+ struct _reent *<[ptr]>;
+ int <[fd]>;
+ char *<[buf]>;
+ size_t <[cnt]>;
+
+DESCRIPTION
+ This is a reentrant version of <<read>>. It
+ takes a pointer to the global data block, which holds
+ <<errno>>.
+*/
+
+long
+_read_r (ptr, fd, buf, cnt)
+ struct _reent *ptr;
+ int fd;
+ _PTR buf;
+ size_t cnt;
+{
+ long ret;
+
+ errno = 0;
+ if ((ret = _read (fd, buf, cnt)) == -1 && errno != 0)
+ ptr->_errno = errno;
+ return ret;
+}
+
+#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */
diff --git a/newlib/libc/reent/reent.c b/newlib/libc/reent/reent.c
new file mode 100644
index 000000000..93b3e86c8
--- /dev/null
+++ b/newlib/libc/reent/reent.c
@@ -0,0 +1,107 @@
+/*
+FUNCTION
+ <<reent>>---definition of impure data.
+
+INDEX
+ reent
+
+DESCRIPTION
+ This module defines the impure data area used by the
+ non-rentrant functions, such as strtok.
+*/
+
+#include <reent.h>
+
+/* Interim cleanup code */
+
+void
+cleanup_glue (ptr, glue)
+ struct _reent *ptr;
+ struct _glue *glue;
+{
+ /* Have to reclaim these in reverse order: */
+ if (glue->_next)
+ cleanup_glue (ptr, glue->_next);
+
+ _free_r (ptr, glue);
+}
+
+void
+_reclaim_reent (ptr)
+ struct _reent *ptr;
+{
+ if (ptr != _impure_ptr)
+ {
+ /* used by mprec routines. */
+ if (ptr->_freelist)
+ {
+ int i;
+ for (i = 0; i < 15 /* _Kmax */; i++)
+ {
+ struct _Bigint *thisone, *nextone;
+
+ nextone = ptr->_freelist[i];
+ while (nextone)
+ {
+ thisone = nextone;
+ nextone = nextone->_next;
+ _free_r (ptr, thisone);
+ }
+ }
+
+ _free_r (ptr, ptr->_freelist);
+ }
+
+ /* atexit stuff */
+ if ((ptr->_atexit) && (ptr->_atexit != &ptr->_atexit0))
+ {
+ struct _atexit *p, *q;
+ for (p = ptr->_atexit; p != &ptr->_atexit0;)
+ {
+ q = p;
+ p = p->_next;
+ _free_r (ptr, q);
+ }
+ }
+
+ if (ptr->_cvtbuf)
+ _free_r (ptr, ptr->_cvtbuf);
+
+ if (ptr->__sdidinit)
+ {
+ /* cleanup won't reclaim memory 'coz usually it's run
+ before the program exits, and who wants to wait for that? */
+ ptr->__cleanup (ptr);
+
+ if (ptr->__sglue._next)
+ cleanup_glue (ptr, ptr->__sglue._next);
+ }
+
+ /* Malloc memory not reclaimed; no good way to return memory anyway. */
+
+ }
+}
+
+/*
+ * Do atexit() processing and cleanup
+ *
+ * NOTE: This is to be executed at task exit. It does not tear anything
+ * down which is used on a global basis.
+ */
+
+void
+_wrapup_reent(struct _reent *ptr)
+{
+ register struct _atexit *p;
+ register int n;
+
+ if (ptr == 0)
+ ptr = _REENT;
+
+ for (p = ptr->_atexit; p; p = p->_next)
+ for (n = p->_ind; --n >= 0;)
+ (*p->_fns[n]) ();
+ if (ptr->__cleanup)
+ (*ptr->__cleanup) (ptr);
+}
+
diff --git a/newlib/libc/reent/reent.tex b/newlib/libc/reent/reent.tex
new file mode 100644
index 000000000..71a0a0dcd
--- /dev/null
+++ b/newlib/libc/reent/reent.tex
@@ -0,0 +1,108 @@
+@node Reentrancy
+@chapter Reentrancy
+
+@cindex reentrancy
+Reentrancy is a characteristic of library functions which allows multiple
+processes to use the same address space with assurance that the values stored
+in those spaces will remain constant between calls. Cygnus's implementation
+of the library functions ensures that
+whenever possible, these library functions are reentrant. However,
+there are some functions that can not be trivially made reentrant.
+Hooks have been provided to allow you to use these functions in a fully
+reentrant fashion.
+
+@findex _reent
+@findex reent.h
+@cindex reentrancy structure
+These hooks use the structure @code{_reent} defined in @file{reent.h}.
+A variable defined as @samp{struct _reent} is called a @dfn{reentrancy
+structure}. All functions which must manipulate global information are
+available in two versions. The first version has the usual name, and
+uses a single global instance of the reentrancy structure. The second
+has a different name, normally formed by prepending @samp{_} and
+appending @samp{_r}, and takes a pointer to the particular reentrancy
+structure to use.
+
+For example, the function @code{fopen} takes two arguments, @var{file}
+and @var{mode}, and uses the global reentrancy structure. The function
+@code{_fopen_r} takes the arguments, @var{struct_reent}, which is a
+pointer to an instance of the reentrancy structure, @var{file}
+and @var{mode}.
+
+@cindex global reentrancy structure
+@findex _impure_ptr
+Each function which uses the global reentrancy structure uses the global
+variable @code{_impure_ptr}, which points to a reentrancy structure.
+
+This means that you have two ways to achieve reentrancy. Both require
+that each thread of execution control initialize a unique global
+variable of type @samp{struct _reent}:
+
+@enumerate
+@item
+@cindex extra argument, reentrant fns
+Use the reentrant versions of the library functions, after initializing
+a global reentrancy structure for each process. Use the pointer to this
+structure as the extra argument for all library functions.
+
+@item
+Ensure that each thread of execution control has a pointer to its own
+unique reentrancy structure in the global variable @code{_impure_ptr},
+and call the standard library subroutines.
+@end enumerate
+
+@cindex list of reentrant functions
+@cindex reentrant function list
+The following functions are provided in both reentrant
+and non-reentrant versions.
+
+@example
+@exdent @emph{Equivalent for errno variable:}
+_errno_r
+
+@exdent @emph{Locale functions:}
+_localeconv_r _setlocale_r
+
+@exdent @emph{Equivalents for stdio variables:}
+_stdin_r _stdout_r _stderr_r
+
+@page
+@exdent @emph{Stdio functions:}
+_fdopen_r _perror_r _tempnam_r
+_fopen_r _putchar_r _tmpnam_r
+_getchar_r _puts_r _tmpfile_r
+_gets_r _remove_r _vfprintf_r
+_iprintf_r _rename_r _vsnprintf_r
+_mkstemp_r _snprintf_r _vsprintf_r
+_mktemp_t _sprintf_r
+
+@exdent @emph{Signal functions:}
+_init_signal_r _signal_r
+_kill_r __sigtramp_r
+_raise_r
+
+@exdent @emph{Stdlib functions:}
+_calloc_r _mblen_r _setenv_r
+_dtoa_r _mbstowcs_r _srand_r
+_free_r _mbtowc_r _strtod_r
+_getenv_r _memalign_r _strtol_r
+_mallinfo_r _mstats_r _strtoul_r
+_malloc_r _putenv_r _system_r
+_malloc_r _rand_r _wcstombs_r
+_malloc_stats_r _realloc_r _wctomb_r
+
+@exdent @emph{String functions:}
+_strdup_r _strtok_r
+
+@exdent @emph{System functions:}
+_close_r _link_r _unlink_r
+_execve_r _lseek_r _wait_r
+_fcntl_r _open_r _write_r
+_fork_r _read_r
+_fstat_r _sbrk_r
+_gettimeofday_r _stat_r
+_getpid_r _times_r
+
+@exdent @emph{Time function:}
+_asctime_r
+@end example
diff --git a/newlib/libc/reent/sbrkr.c b/newlib/libc/reent/sbrkr.c
new file mode 100644
index 000000000..7f6930ead
--- /dev/null
+++ b/newlib/libc/reent/sbrkr.c
@@ -0,0 +1,66 @@
+/* Reentrant versions of sbrk system call. This implementation just
+ calls the stat system call. */
+
+#include <reent.h>
+#include <unistd.h>
+#include <_syslist.h>
+
+/* Some targets provides their own versions of these functions. Those
+ targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */
+
+#ifdef _REENT_ONLY
+#ifndef REENTRANT_SYSCALLS_PROVIDED
+#define REENTRANT_SYSCALLS_PROVIDED
+#endif
+#endif
+
+/* If MALLOC_PROVIDED is defined, we don't need this function. */
+
+#if defined (REENTRANT_SYSCALLS_PROVIDED) || defined (MALLOC_PROVIDED)
+
+int _dummy_sbrk_syscalls = 1;
+
+#else
+
+/* We use the errno variable used by the system dependent layer. */
+#undef errno
+int errno;
+
+/*
+FUNCTION
+ <<_sbrk_r>>---Reentrant version of sbrk
+
+INDEX
+ _sbrk_r
+
+ANSI_SYNOPSIS
+ #include <reent.h>
+ void *_sbrk_r(struct _reent *<[ptr]>, size_t <[incr]>);
+
+TRAD_SYNOPSIS
+ #include <reent.h>
+ void *_sbrk_r(<[ptr]>, <[incr]>)
+ struct _reent *<[ptr]>;
+ size_t <[incr]>;
+
+DESCRIPTION
+ This is a reentrant version of <<sbrk>>. It
+ takes a pointer to the global data block, which holds
+ <<errno>>.
+*/
+
+void *
+_sbrk_r (ptr, incr)
+ struct _reent *ptr;
+ size_t incr;
+{
+ char *ret;
+ void *_sbrk(size_t);
+
+ errno = 0;
+ if ((ret = (char *)(_sbrk (incr))) == (void *) -1 && errno != 0)
+ ptr->_errno = errno;
+ return ret;
+}
+
+#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */
diff --git a/newlib/libc/reent/signalr.c b/newlib/libc/reent/signalr.c
new file mode 100644
index 000000000..7c85af142
--- /dev/null
+++ b/newlib/libc/reent/signalr.c
@@ -0,0 +1,98 @@
+/* Reentrant versions of syscalls need to support signal/raise.
+ These implementations just call the usual system calls. */
+
+#include <reent.h>
+#include <_syslist.h>
+
+/* Some targets provides their own versions of these functions. Those
+ targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */
+
+#ifdef _REENT_ONLY
+#ifndef REENTRANT_SYSCALLS_PROVIDED
+#define REENTRANT_SYSCALLS_PROVIDED
+#endif
+#endif
+
+#ifdef REENTRANT_SYSCALLS_PROVIDED
+
+int _dummy_link_syscalls = 1;
+
+#else
+
+/* We use the errno variable used by the system dependent layer. */
+#undef errno
+extern int errno;
+
+/*
+FUNCTION
+ <<_kill_r>>---Reentrant version of kill
+
+INDEX
+ _kill_r
+
+ANSI_SYNOPSIS
+ #include <reent.h>
+ int _kill_r(struct _reent *<[ptr]>, int <[pid]>, int <[sig]>);
+
+TRAD_SYNOPSIS
+ #include <reent.h>
+ int _kill_r(<[ptr]>, <[pid]>, <[sig]>)
+ struct _reent *<[ptr]>;
+ int <[pid]>;
+ int <[sig]>;
+
+DESCRIPTION
+ This is a reentrant version of <<kill>>. It
+ takes a pointer to the global data block, which holds
+ <<errno>>.
+*/
+
+int
+_kill_r (ptr, pid, sig)
+ struct _reent *ptr;
+ int pid;
+ int sig;
+{
+ int ret;
+
+ errno = 0;
+ if ((ret = _kill (pid, sig)) == -1 && errno != 0)
+ ptr->_errno = errno;
+ return ret;
+}
+
+/*
+FUNCTION
+ <<_getpid_r>>---Reentrant version of getpid
+
+INDEX
+ _getpid_r
+
+ANSI_SYNOPSIS
+ #include <reent.h>
+ int _getpid_r(struct _reent *<[ptr]>);
+
+TRAD_SYNOPSIS
+ #include <reent.h>
+ int _getpid_r(<[ptr]>)
+ struct _reent *<[ptr]>;
+
+DESCRIPTION
+ This is a reentrant version of <<getpid>>. It
+ takes a pointer to the global data block, which holds
+ <<errno>>.
+
+ We never need <<errno>>, of course, but for consistency we
+ still must have the reentrant pointer argument.
+*/
+
+int
+_getpid_r (ptr)
+ struct _reent *ptr;
+{
+ int ret;
+ ret = _getpid ();
+ return ret;
+}
+
+#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */
diff --git a/newlib/libc/reent/statr.c b/newlib/libc/reent/statr.c
new file mode 100644
index 000000000..55d29bdb8
--- /dev/null
+++ b/newlib/libc/reent/statr.c
@@ -0,0 +1,67 @@
+/* Reentrant versions of stat system call. This implementation just
+ calls the stat system call. */
+
+#include <reent.h>
+#include <unistd.h>
+#include <_syslist.h>
+
+/* Some targets provides their own versions of these functions. Those
+ targets should define REENTRANT_SYSCALLS_PROVIDED in
+ TARGET_CFLAGS. */
+
+#ifdef _REENT_ONLY
+#ifndef REENTRANT_SYSCALLS_PROVIDED
+#define REENTRANT_SYSCALLS_PROVIDED
+#endif
+#endif
+
+#ifdef REENTRANT_SYSCALLS_PROVIDED
+
+int _dummy_stat_syscalls = 1;
+
+#else
+
+/* We use the errno variable used by the system dependent layer. */
+#undef errno
+extern int errno;
+
+/*
+FUNCTION
+ <<_stat_r>>---Reentrant version of stat
+
+INDEX
+ _stat_r
+
+ANSI_SYNOPSIS
+ #include <reent.h>
+ int _stat_r(struct _reent *<[ptr]>,
+ const char *<[file]>, struct stat *<[pstat]>);
+
+TRAD_SYNOPSIS
+ #include <reent.h>
+ int _stat_r(<[ptr]>, <[file]>, <[pstat]>)
+ struct _reent *<[ptr]>;
+ char *<[file]>;
+ struct stat *<[pstat]>;
+
+DESCRIPTION
+ This is a reentrant version of <<stat>>. It
+ takes a pointer to the global data block, which holds
+ <<errno>>.
+*/
+
+int
+_stat_r (ptr, file, pstat)
+ struct _reent *ptr;
+ _CONST char *file;
+ struct stat *pstat;
+{
+ int ret;
+
+ errno = 0;
+ if ((ret = _stat (file, pstat)) == -1 && errno != 0)
+ ptr->_errno = errno;
+ return ret;
+}
+
+#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */
diff --git a/newlib/libc/reent/timer.c b/newlib/libc/reent/timer.c
new file mode 100644
index 000000000..526b4d135
--- /dev/null
+++ b/newlib/libc/reent/timer.c
@@ -0,0 +1,112 @@
+/* Reentrant versions of times and gettimeofday system calls for the
+ clock and time ANSI C routines.
+ This implementation just calls the times/gettimeofday system calls.
+ Gettimeofday may not be available on all targets. It's presence
+ here is dubious. Consider it for internal use only. */
+
+#include <reent.h>
+#include <time.h>
+#include <sys/times.h>
+#include <_syslist.h>
+
+/* Some targets provides their own versions of these functions. Those
+ targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */
+
+#ifdef _REENT_ONLY
+#ifndef REENTRANT_SYSCALLS_PROVIDED
+#define REENTRANT_SYSCALLS_PROVIDED
+#endif
+#endif
+
+#ifdef REENTRANT_SYSCALLS_PROVIDED
+
+int _dummy_time_syscalls = 1;
+
+#else
+
+/* We use the errno variable used by the system dependent layer. */
+#undef errno
+extern int errno;
+
+/*
+FUNCTION
+ <<_times_r>>---Reentrant version of times
+
+INDEX
+ _times_r
+
+ANSI_SYNOPSIS
+ #include <reent.h>
+ #include <sys/times.h>
+ clock_t _times_r(struct _reent *<[ptr]>, struct tms *<[ptms]>);
+
+TRAD_SYNOPSIS
+ #include <reent.h>
+ #include <sys/times.h>
+ clock_t _times_r(<[ptr]>, <[ptms]>)
+ struct _reent *<[ptr]>;
+ struct tms *<[ptms]>;
+
+DESCRIPTION
+ This is a reentrant version of <<times>>. It
+ takes a pointer to the global data block, which holds
+ <<errno>>.
+*/
+
+clock_t
+_times_r (ptr, ptms)
+ struct _reent *ptr;
+ struct tms *ptms;
+{
+ clock_t ret;
+
+ ret = _times (ptms);
+ return ret;
+}
+
+/*
+FUNCTION
+ <<_gettimeofday_r>>---Reentrant version of gettimeofday
+
+INDEX
+ _gettimeofday_r
+
+ANSI_SYNOPSIS
+ #include <reent.h>
+ #include <time.h>
+ int _gettimeofday_r(struct _reent *<[ptr]>,
+ struct timeval *<[ptimeval]>,
+ struct timezone *<[ptimezone]>);
+
+TRAD_SYNOPSIS
+ #include <reent.h>
+ #include <time.h>
+ int _gettimeofday_r(<[ptr]>, <[ptimeval]>, <[ptimezone]>)
+ struct _reent *<[ptr]>;
+ struct timeval *<[ptimeval]>;
+ struct timezone *<[ptimezone]>;
+
+DESCRIPTION
+ This is a reentrant version of <<gettimeofday>>. It
+ takes a pointer to the global data block, which holds
+ <<errno>>.
+
+ This function is only available for a few targets.
+ Check libc.a to see if its available on yours.
+*/
+
+int
+_gettimeofday_r (ptr, ptimeval, ptimezone)
+ struct _reent *ptr;
+ struct timeval *ptimeval;
+ struct timezone *ptimezone;
+{
+ int ret;
+
+ errno = 0;
+ if ((ret = _gettimeofday (ptimeval, ptimezone)) == -1 && errno != 0)
+ ptr->_errno = errno;
+ return ret;
+}
+
+#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */
diff --git a/newlib/libc/reent/writer.c b/newlib/libc/reent/writer.c
new file mode 100644
index 000000000..ac10286e8
--- /dev/null
+++ b/newlib/libc/reent/writer.c
@@ -0,0 +1,63 @@
+/* Reentrant versions of write system call. */
+
+#include <reent.h>
+#include <unistd.h>
+#include <_syslist.h>
+
+/* Some targets provides their own versions of this functions. Those
+ targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */
+
+#ifdef _REENT_ONLY
+#ifndef REENTRANT_SYSCALLS_PROVIDED
+#define REENTRANT_SYSCALLS_PROVIDED
+#endif
+#endif
+
+#ifndef REENTRANT_SYSCALLS_PROVIDED
+
+/* We use the errno variable used by the system dependent layer. */
+#undef errno
+extern int errno;
+
+/*
+FUNCTION
+ <<_write_r>>---Reentrant version of write
+
+INDEX
+ _write_r
+
+ANSI_SYNOPSIS
+ #include <reent.h>
+ long _write_r(struct _reent *<[ptr]>,
+ int <[fd]>, const void *<[buf]>, size_t <[cnt]>);
+
+TRAD_SYNOPSIS
+ #include <reent.h>
+ long _write_r(<[ptr]>, <[fd]>, <[buf]>, <[cnt]>)
+ struct _reent *<[ptr]>;
+ int <[fd]>;
+ char *<[buf]>;
+ size_t <[cnt]>;
+
+DESCRIPTION
+ This is a reentrant version of <<write>>. It
+ takes a pointer to the global data block, which holds
+ <<errno>>.
+*/
+
+long
+_write_r (ptr, fd, buf, cnt)
+ struct _reent *ptr;
+ int fd;
+ _CONST _PTR buf;
+ size_t cnt;
+{
+ long ret;
+
+ errno = 0;
+ if ((ret = _write (fd, buf, cnt)) == -1 && errno != 0)
+ ptr->_errno = errno;
+ return ret;
+}
+
+#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */