diff options
Diffstat (limited to 'libc/reent')
-rw-r--r-- | libc/reent/closer.c | 58 | ||||
-rw-r--r-- | libc/reent/execr.c | 144 | ||||
-rw-r--r-- | libc/reent/fstatr.c | 66 | ||||
-rw-r--r-- | libc/reent/impure.c | 13 | ||||
-rw-r--r-- | libc/reent/linkr.c | 102 | ||||
-rw-r--r-- | libc/reent/lseekr.c | 63 | ||||
-rw-r--r-- | libc/reent/openr.c | 64 | ||||
-rw-r--r-- | libc/reent/readr.c | 63 | ||||
-rw-r--r-- | libc/reent/reent.c | 107 | ||||
-rw-r--r-- | libc/reent/sbrkr.c | 66 | ||||
-rw-r--r-- | libc/reent/signalr.c | 98 | ||||
-rw-r--r-- | libc/reent/statr.c | 67 | ||||
-rw-r--r-- | libc/reent/timer.c | 112 | ||||
-rw-r--r-- | libc/reent/writer.c | 63 |
14 files changed, 1086 insertions, 0 deletions
diff --git a/libc/reent/closer.c b/libc/reent/closer.c new file mode 100644 index 0000000..aeacebd --- /dev/null +++ b/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/libc/reent/execr.c b/libc/reent/execr.c new file mode 100644 index 0000000..9e8f75a --- /dev/null +++ b/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/libc/reent/fstatr.c b/libc/reent/fstatr.c new file mode 100644 index 0000000..df132d7 --- /dev/null +++ b/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/libc/reent/impure.c b/libc/reent/impure.c new file mode 100644 index 0000000..a14f5c3 --- /dev/null +++ b/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/libc/reent/linkr.c b/libc/reent/linkr.c new file mode 100644 index 0000000..a15d223 --- /dev/null +++ b/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/libc/reent/lseekr.c b/libc/reent/lseekr.c new file mode 100644 index 0000000..ed8ba13 --- /dev/null +++ b/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/libc/reent/openr.c b/libc/reent/openr.c new file mode 100644 index 0000000..2e3b608 --- /dev/null +++ b/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/libc/reent/readr.c b/libc/reent/readr.c new file mode 100644 index 0000000..e3deca9 --- /dev/null +++ b/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/libc/reent/reent.c b/libc/reent/reent.c new file mode 100644 index 0000000..93b3e86 --- /dev/null +++ b/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/libc/reent/sbrkr.c b/libc/reent/sbrkr.c new file mode 100644 index 0000000..7f6930e --- /dev/null +++ b/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/libc/reent/signalr.c b/libc/reent/signalr.c new file mode 100644 index 0000000..7c85af1 --- /dev/null +++ b/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/libc/reent/statr.c b/libc/reent/statr.c new file mode 100644 index 0000000..55d29bd --- /dev/null +++ b/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/libc/reent/timer.c b/libc/reent/timer.c new file mode 100644 index 0000000..526b4d1 --- /dev/null +++ b/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/libc/reent/writer.c b/libc/reent/writer.c new file mode 100644 index 0000000..ac10286 --- /dev/null +++ b/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) */ |