From 17ea22213f86a5c5966c1e6bf8e95f022ebb92b9 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Mon, 31 Jan 2005 22:29:48 +0000 Subject: [PATCH] Remove _THREAD_SAFE depenendancies. Create weakly associated stubs for posix threading calls used by libc and weak associations for procedures that a threading library would otherwise have to override. This allows a program to be linked with libc, or linked with libc + a threading library. libc_r will be deprecated over time. Traditionally libc_r had to be linked against a threading library rather then libc. Linux, FreeBSD, and other UNIXes have moved either t oa thread-safe libc or a thread-capable libc. The threading capability is accomplished by making the appropriate thread locking calls and providing weakly referenced dummy stub functions for the case where a threading library is not linked in. Certain third party software, namely XFree/XOrg, also assume threading stubs in libc. This is precursor work to a port of David Xu's 1:1 threading library and is also intended as a basis to allow DragonFly to support multiple threading libraries. Ported-by: David Rhodus Primarily-ported-from: FreeBSD Testing and bug fixes by David Xu and Matt Dillon --- include/dirent.h | 7 +- include/stdio.h | 61 +-------- lib/libc/Makefile | 14 +- lib/libc/Makefile.inc | 4 +- lib/libc/compat-43/creat.c | 8 +- lib/libc/compat-43/sigcompat.c | 27 ++-- lib/libc/db/btree/bt_close.c | 14 +- lib/libc/db/btree/bt_open.c | 10 +- lib/libc/db/hash/hash.c | 9 +- lib/libc/db/hash/hash_page.c | 8 +- lib/libc/db/mpool/mpool.c | 6 +- lib/libc/db/recno/rec_close.c | 6 +- lib/libc/db/recno/rec_open.c | 6 +- lib/libc/gen/Makefile.inc | 6 +- lib/libc/gen/_pthread_stubs.c | 133 ++++++++++++++++++ lib/libc/gen/_spinlock_stub.c | 25 +++- lib/libc/gen/_thread_init.c | 42 ++++++ lib/libc/gen/arc4random.c | 4 +- lib/libc/gen/closedir.c | 18 ++- lib/libc/gen/daemon.c | 10 +- lib/libc/gen/devname.c | 3 +- lib/libc/gen/exec.c | 14 +- lib/libc/gen/fstab.c | 4 +- lib/libc/gen/fts.c | 6 +- lib/libc/gen/getcap.c | 7 +- lib/libc/gen/getcwd.c | 8 +- lib/libc/gen/getlogin.c | 25 ++-- lib/libc/gen/getpwent.c | 7 +- lib/libc/gen/isatty.c | 20 +-- lib/libc/gen/lockf.c | 6 +- lib/libc/gen/nlist.c | 8 +- lib/libc/gen/opendir.c | 18 +-- lib/libc/gen/pause.c | 4 +- lib/libc/gen/popen.c | 18 +-- lib/libc/gen/posixshm.c | 6 +- lib/libc/gen/psignal.c | 4 +- lib/libc/gen/readdir.c | 53 +++++--- lib/libc/gen/scandir.c | 6 +- lib/libc/gen/seekdir.c | 14 +- lib/libc/gen/setjmperr.c | 4 +- lib/libc/gen/setmode.c | 8 +- lib/libc/gen/siginterrupt.c | 9 +- lib/libc/gen/signal.c | 7 +- lib/libc/gen/sleep.c | 8 +- lib/libc/gen/syslog.c | 14 +- lib/libc/gen/telldir.c | 15 ++- lib/libc/gen/termios.c | 30 +++-- lib/libc/gen/ttyname.c | 83 +++++------- lib/libc/gen/usleep.c | 4 +- lib/libc/gen/wait.c | 9 +- lib/libc/gen/wait3.c | 6 +- lib/libc/gen/waitpid.c | 16 +-- lib/libc/gmon/gmon.c | 5 +- lib/libc/i386/SYS.h | 27 ++-- lib/libc/i386/gen/_setjmp.S | 9 +- lib/libc/i386/gen/setjmp.S | 12 +- lib/libc/i386/gen/sigsetjmp.S | 15 +-- lib/libc/i386/sys/setlogin.S | 4 +- lib/libc/include/libc_private.h | 14 +- lib/libc/include/namespace.h | 136 +++++++++++++++++++ lib/libc/include/spinlock.h | 5 +- lib/libc/include/un-namespace.h | 136 +++++++++++++++++++ lib/libc/locale/collate.c | 6 +- lib/libc/locale/rune.c | 4 +- lib/libc/net/getaddrinfo.c | 12 +- lib/libc/net/gethostbyht.c | 3 +- lib/libc/net/gethostnamadr.c | 4 +- lib/libc/net/getifaddrs.c | 12 +- lib/libc/net/herror.c | 6 +- lib/libc/net/name6.c | 18 +-- lib/libc/net/rcmd.c | 34 +++-- lib/libc/net/recv.c | 6 +- lib/libc/net/res_send.c | 26 ++-- lib/libc/net/send.c | 6 +- lib/libc/nls/msgcat.c | 4 +- lib/libc/rpc/auth_time.c | 14 +- lib/libc/rpc/bindresvport.c | 14 +- lib/libc/rpc/clnt_generic.c | 4 +- lib/libc/rpc/clnt_simple.c | 4 +- lib/libc/rpc/clnt_tcp.c | 12 +- lib/libc/rpc/clnt_udp.c | 16 ++- lib/libc/rpc/clnt_unix.c | 18 +-- lib/libc/rpc/get_myaddress.c | 10 +- lib/libc/rpc/key_call.c | 6 +- lib/libc/rpc/pmap_clnt.c | 4 +- lib/libc/rpc/pmap_getmaps.c | 5 +- lib/libc/rpc/pmap_getport.c | 4 +- lib/libc/rpc/pmap_rmt.c | 23 ++-- lib/libc/rpc/rpc_dtablesize.c | 4 +- lib/libc/rpc/rtime.c | 14 +- lib/libc/rpc/svc_auth_des.c | 3 +- lib/libc/rpc/svc_run.c | 8 +- lib/libc/rpc/svc_tcp.c | 24 ++-- lib/libc/rpc/svc_udp.c | 16 ++- lib/libc/rpc/svc_unix.c | 24 ++-- lib/libc/stdio/_flock_stub.c | 7 +- lib/libc/stdio/clrerr.c | 6 +- lib/libc/stdio/fclose.c | 12 +- lib/libc/stdio/fdopen.c | 4 +- lib/libc/stdio/fflush.c | 34 ++++- lib/libc/stdio/fgetc.c | 4 +- lib/libc/stdio/fgetpos.c | 4 +- lib/libc/stdio/fgets.c | 4 +- lib/libc/stdio/findfp.c | 51 +++++-- lib/libc/stdio/flags.c | 4 +- lib/libc/stdio/fopen.c | 5 +- lib/libc/stdio/fpurge.c | 4 +- lib/libc/stdio/fputc.c | 4 +- lib/libc/stdio/fputs.c | 4 +- lib/libc/stdio/fread.c | 4 +- lib/libc/stdio/freopen.c | 8 +- lib/libc/stdio/fscanf.c | 4 +- lib/libc/stdio/fseek.c | 40 +++--- lib/libc/stdio/ftell.c | 4 +- lib/libc/stdio/fvwrite.c | 8 +- lib/libc/stdio/fwalk.c | 9 +- lib/libc/stdio/fwrite.c | 4 +- lib/libc/stdio/getc.c | 9 +- lib/libc/stdio/getchar.c | 4 +- lib/libc/stdio/gets.c | 4 +- lib/libc/stdio/glue.h | 7 +- lib/libc/stdio/local.h | 4 +- lib/libc/stdio/makebuf.c | 8 +- lib/libc/stdio/mktemp.c | 4 +- lib/libc/stdio/perror.c | 6 +- lib/libc/stdio/putc.c | 13 +- lib/libc/stdio/putchar.c | 14 +- lib/libc/stdio/puts.c | 4 +- lib/libc/stdio/putw.c | 4 +- lib/libc/stdio/refill.c | 3 +- lib/libc/stdio/rewind.c | 7 +- lib/libc/stdio/scanf.c | 4 +- lib/libc/stdio/setvbuf.c | 4 +- lib/libc/stdio/stdio.c | 4 +- lib/libc/stdio/tmpfile.c | 8 +- lib/libc/stdio/ungetc.c | 28 +++- lib/libc/stdio/vasprintf.c | 5 +- lib/libc/stdio/vfprintf.c | 31 +++-- lib/libc/stdio/vfscanf.c | 31 ++++- lib/libc/stdio/vscanf.c | 4 +- lib/libc/stdio/vsnprintf.c | 5 +- lib/libc/stdio/vsprintf.c | 5 +- lib/libc/stdio/wbuf.c | 8 +- lib/libc/stdlib/abort.c | 34 +++-- lib/libc/stdlib/exit.c | 9 +- lib/libc/stdlib/malloc.c | 4 +- lib/libc/stdlib/random.c | 4 +- lib/libc/stdlib/realpath.c | 4 +- lib/libc/stdlib/system.c | 26 ++-- lib/libc/stdtime/asctime.c | 4 +- lib/libc/stdtime/difftime.c | 4 +- lib/libc/stdtime/localtime.c | 186 +++++++++++--------------- lib/libc/stdtime/strftime.c | 4 +- lib/libc/stdtime/strptime.c | 26 ++-- lib/libc/stdtime/timelocal.c | 5 +- lib/libc/sys/ftruncate.c | 17 +-- lib/libc/sys/lseek.c | 17 +-- lib/libc/sys/stack_protector.c | 12 +- lib/libc/yp/yplib.c | 24 ++-- lib/libc_r/uthread/uthread_spinlock.c | 8 +- 160 files changed, 1572 insertions(+), 865 deletions(-) create mode 100644 lib/libc/gen/_pthread_stubs.c create mode 100644 lib/libc/gen/_thread_init.c create mode 100644 lib/libc/include/namespace.h create mode 100644 lib/libc/include/un-namespace.h diff --git a/include/dirent.h b/include/dirent.h index 0ee086b09b..6b2491cd63 100644 --- a/include/dirent.h +++ b/include/dirent.h @@ -32,7 +32,7 @@ * * @(#)dirent.h 8.2 (Berkeley) 7/28/94 * $FreeBSD: src/include/dirent.h,v 1.7 1999/12/29 05:01:20 peter Exp $ - * $DragonFly: src/include/dirent.h,v 1.3 2003/11/14 01:01:43 dillon Exp $ + * $DragonFly: src/include/dirent.h,v 1.4 2005/01/31 22:28:58 dillon Exp $ */ #ifndef _DIRENT_H_ @@ -63,6 +63,7 @@ typedef struct _dirdesc { long dd_seek; /* magic cookie returned by getdirentries */ long dd_rewind; /* magic cookie for rewinding */ int dd_flags; /* flags for readdir */ + void *dd_lock; /* hack to avoid include */ } DIR; #define dirfd(dirp) ((dirp)->dd_fd) @@ -91,7 +92,9 @@ int closedir (DIR *); #ifndef _POSIX_SOURCE DIR *__opendir2 (const char *, int); long telldir (const DIR *); -void seekdir (DIR *, long); +struct dirent *_readdir_unlocked(DIR *); +void _reclaim_telldir(DIR *); +void _seekdir (DIR *, long); int scandir (const char *, struct dirent ***, int (*)(struct dirent *), int (*)(const void *, const void *)); int alphasort (const void *, const void *); diff --git a/include/stdio.h b/include/stdio.h index 56b370200d..8adfc8c768 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -35,7 +35,7 @@ * * @(#)stdio.h 8.5 (Berkeley) 4/29/95 * $FreeBSD: src/include/stdio.h,v 1.24.2.5 2002/11/09 08:07:20 imp Exp $ - * $DragonFly: src/include/stdio.h,v 1.5 2003/11/15 19:28:42 asmodai Exp $ + * $DragonFly: src/include/stdio.h,v 1.6 2005/01/31 22:28:58 dillon Exp $ */ #ifndef _STDIO_H_ @@ -330,10 +330,10 @@ __END_DECLS /* * This is a #define because the function is used internally and - * (unlike vfscanf) the name __svfscanf is guaranteed not to collide + * (unlike vfscanf) the name __vfscanf is guaranteed not to collide * with a user function when _ANSI_SOURCE or _POSIX_SOURCE is defined. */ -#define vfscanf __svfscanf +#define vfscanf __vfscanf /* * Stdio function-access interface. @@ -354,6 +354,7 @@ __END_DECLS */ __BEGIN_DECLS int __srget (FILE *); +int __vfscanf (FILE *, const char *, __va_list); int __svfscanf (FILE *, const char *, __va_list); int __swbuf (int, FILE *); __END_DECLS @@ -401,60 +402,10 @@ static __inline int __sputc(int _c, FILE *_p) { #define fileno_unlocked(p) __sfileno(p) #endif -#ifndef _THREAD_SAFE -#define feof(p) feof_unlocked(p) -#define ferror(p) ferror_unlocked(p) -#define clearerr(p) clearerr_unlocked(p) +#define getc_unlocked(fp) __sgetc(fp) +#define putc_unlocked(x, fp) __sputc(x, fp) -#ifndef _ANSI_SOURCE -#define fileno(p) fileno_unlocked(p) -#endif -#endif - -#ifndef lint -#define getc_unlocked(fp) __sgetc(fp) -#define putc_unlocked(x, fp) __sputc(x, fp) -#ifdef _THREAD_SAFE -void _flockfile_debug (FILE *, char *, int); -#ifdef _FLOCK_DEBUG -#define _FLOCKFILE(x) _flockfile_debug(x, __FILE__, __LINE__) -#else -#define _FLOCKFILE(x) flockfile(x) -#endif -extern int __isthreaded; -static __inline int \ -__getc_locked(FILE *_fp) \ -{ \ - int _ret; \ - if (__isthreaded) \ - _FLOCKFILE(_fp); \ - _ret = getc_unlocked(_fp); \ - if (__isthreaded) \ - funlockfile(_fp); \ - return (_ret); \ -} -static __inline int \ -__putc_locked(int _x, FILE *_fp) \ -{ \ - int _ret; \ - if (__isthreaded) \ - _FLOCKFILE(_fp); \ - _ret = putc_unlocked(_x, _fp); \ - if (__isthreaded) \ - funlockfile(_fp); \ - return (_ret); \ -} -#define getc(fp) __getc_locked(fp) -#define putc(x, fp) __putc_locked(x, fp) -#else -#define getc(fp) getc_unlocked(fp) -#define putc(x, fp) putc_unlocked(x, fp) -#endif -#endif /* lint */ - -#define getchar() getc(stdin) #define getchar_unlocked() getc_unlocked(stdin) -#define putchar(x) putc(x, stdout) #define putchar_unlocked(x) putc_unlocked(x, stdout) #endif /* !_STDIO_H_ */ diff --git a/lib/libc/Makefile b/lib/libc/Makefile index b349bfecc6..e3dec5fdab 100644 --- a/lib/libc/Makefile +++ b/lib/libc/Makefile @@ -1,6 +1,6 @@ # @(#)Makefile 8.2 (Berkeley) 2/3/94 # $FreeBSD: src/lib/libc/Makefile,v 1.24 1999/09/29 15:18:29 marcel Exp $ -# $DragonFly: src/lib/libc/Makefile,v 1.4 2004/06/06 22:44:34 dillon Exp $ +# $DragonFly: src/lib/libc/Makefile,v 1.5 2005/01/31 22:29:01 dillon Exp $ # # All library objects contain rcsid strings by default; they may be # excluded as a space-saving measure. To produce a library that does @@ -19,7 +19,17 @@ PRECIOUSLIB= yes # # Don't bother hiding any syscalls (like libc_r does). # -HIDDEN_SYSCALLS= +HIDDEN_SYSCALLS= _exit.o accept.o aio_suspend.o bind.o close.o connect.o \ + dup.o dup2.o execve.o fchflags.o fchmod.o fchown.o fcntl.o \ + flock.o fpathconf.o fstat.o fstatfs.o fsync.o getdirentries.o \ + getpeername.o getsockname.o getsockopt.o ioctl.o \ + kevent.o listen.o \ + msync.o nanosleep.o nfssvc.o open.o poll.o read.o readv.o recvfrom.o \ + recvmsg.o sched_yield.o select.o sendfile.o sendmsg.o sendto.o \ + setsockopt.o shutdown.o sigaction.o sigaltstack.o \ + sigpending.o sigprocmask.o sigreturn.o \ + sigsuspend.o socket.o \ + socketpair.o wait4.o write.o writev.o # # Include make rules that are shared with libc_r. diff --git a/lib/libc/Makefile.inc b/lib/libc/Makefile.inc index 631962120e..016bf4b223 100644 --- a/lib/libc/Makefile.inc +++ b/lib/libc/Makefile.inc @@ -1,5 +1,5 @@ # $FreeBSD: src/lib/libc/Makefile.inc,v 1.5 1999/08/27 23:58:06 peter Exp $ -# $DragonFly: src/lib/libc/Makefile.inc,v 1.2 2003/06/17 04:26:41 dillon Exp $ +# $DragonFly: src/lib/libc/Makefile.inc,v 1.3 2005/01/31 22:29:01 dillon Exp $ # # This file contains make rules that are shared by libc and libc_r. # @@ -11,6 +11,8 @@ MDASM= MIASM= NOASM= +WARNS=6 + # # If there is a machine dependent makefile, use it: # diff --git a/lib/libc/compat-43/creat.c b/lib/libc/compat-43/creat.c index ca791e6b26..163a693935 100644 --- a/lib/libc/compat-43/creat.c +++ b/lib/libc/compat-43/creat.c @@ -31,12 +31,14 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/compat-43/creat.c,v 1.4.2.2 2001/03/05 07:28:35 obrien Exp $ - * $DragonFly: src/lib/libc/compat-43/creat.c,v 1.2 2003/06/17 04:26:41 dillon Exp $ + * $DragonFly: src/lib/libc/compat-43/creat.c,v 1.3 2005/01/31 22:29:03 dillon Exp $ * * @(#)creat.c 8.1 (Berkeley) 6/2/93 */ +#include "namespace.h" #include +#include "un-namespace.h" int __creat(const char *path, mode_t mode) @@ -44,6 +46,6 @@ __creat(const char *path, mode_t mode) return(_open(path, O_WRONLY|O_CREAT|O_TRUNC, mode)); } -#ifndef _THREAD_SAFE __weak_reference(__creat, creat); -#endif +__weak_reference(__creat, _creat); + diff --git a/lib/libc/compat-43/sigcompat.c b/lib/libc/compat-43/sigcompat.c index 5bf66196bc..00eb72123d 100644 --- a/lib/libc/compat-43/sigcompat.c +++ b/lib/libc/compat-43/sigcompat.c @@ -31,19 +31,17 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/compat-43/sigcompat.c,v 1.7 2000/01/27 23:06:04 jasone Exp $ - * $DragonFly: src/lib/libc/compat-43/sigcompat.c,v 1.2 2003/06/17 04:26:41 dillon Exp $ - * - * @(#)sigcompat.c 8.1 (Berkeley) 6/2/93 - * $FreeBSD: src/lib/libc/compat-43/sigcompat.c,v 1.7 2000/01/27 23:06:04 jasone Exp $ + * $DragonFly: src/lib/libc/compat-43/sigcompat.c,v 1.3 2005/01/31 22:29:03 dillon Exp $ */ +#include "namespace.h" #include #include +#include "un-namespace.h" +#include "libc_private.h" int -sigvec(signo, sv, osv) - int signo; - struct sigvec *sv, *osv; +sigvec(int signo, struct sigvec *sv, struct sigvec *osv) { struct sigaction sa, osa; struct sigaction *sap, *osap; @@ -58,7 +56,7 @@ sigvec(signo, sv, osv) } else sap = NULL; osap = osv != NULL ? &osa : NULL; - ret = sigaction(signo, sap, osap); + ret = _sigaction(signo, sap, osap); if (ret == 0 && osv != NULL) { osv->sv_handler = osa.sa_handler; osv->sv_flags = osa.sa_flags ^ SV_INTERRUPT; @@ -68,38 +66,35 @@ sigvec(signo, sv, osv) } int -sigsetmask(mask) - int mask; +sigsetmask(int mask) { sigset_t set, oset; int n; sigemptyset(&set); set.__bits[0] = mask; - n = sigprocmask(SIG_SETMASK, &set, &oset); + n = _sigprocmask(SIG_SETMASK, &set, &oset); if (n) return (n); return (oset.__bits[0]); } int -sigblock(mask) - int mask; +sigblock(int mask) { sigset_t set, oset; int n; sigemptyset(&set); set.__bits[0] = mask; - n = sigprocmask(SIG_BLOCK, &set, &oset); + n = _sigprocmask(SIG_BLOCK, &set, &oset); if (n) return (n); return (oset.__bits[0]); } int -sigpause(mask) - int mask; +sigpause(int mask) { sigset_t set; diff --git a/lib/libc/db/btree/bt_close.c b/lib/libc/db/btree/bt_close.c index 2c9bb1e913..8ec5acb313 100644 --- a/lib/libc/db/btree/bt_close.c +++ b/lib/libc/db/btree/bt_close.c @@ -34,11 +34,12 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/db/btree/bt_close.c,v 1.5 2000/01/27 23:06:05 jasone Exp $ - * $DragonFly: src/lib/libc/db/btree/bt_close.c,v 1.3 2003/11/12 20:21:22 eirikn Exp $ + * $DragonFly: src/lib/libc/db/btree/bt_close.c,v 1.4 2005/01/31 22:29:07 dillon Exp $ * * @(#)bt_close.c 8.7 (Berkeley) 8/17/94 */ +#include "namespace.h" #include #include @@ -46,6 +47,7 @@ #include #include #include +#include "un-namespace.h" #include #include "btree.h" @@ -62,8 +64,7 @@ static int bt_meta (BTREE *); * RET_ERROR, RET_SUCCESS */ int -__bt_close(dbp) - DB *dbp; +__bt_close(DB *dbp) { BTREE *t; int fd; @@ -117,9 +118,7 @@ __bt_close(dbp) * RET_SUCCESS, RET_ERROR. */ int -__bt_sync(dbp, flags) - const DB *dbp; - u_int flags; +__bt_sync(const DB *dbp, u_int flags) { BTREE *t; int status; @@ -160,8 +159,7 @@ __bt_sync(dbp, flags) * RET_ERROR, RET_SUCCESS */ static int -bt_meta(t) - BTREE *t; +bt_meta(BTREE *t) { BTMETA m; void *p; diff --git a/lib/libc/db/btree/bt_open.c b/lib/libc/db/btree/bt_open.c index 1083e9fc4b..e04857e293 100644 --- a/lib/libc/db/btree/bt_open.c +++ b/lib/libc/db/btree/bt_open.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/db/btree/bt_open.c,v 1.7.2.1 2000/11/02 10:30:07 kris Exp $ - * $DragonFly: src/lib/libc/db/btree/bt_open.c,v 1.3 2003/11/12 20:21:22 eirikn Exp $ + * $DragonFly: src/lib/libc/db/btree/bt_open.c,v 1.4 2005/01/31 22:29:07 dillon Exp $ * * @(#)bt_open.c 8.10 (Berkeley) 8/17/94 */ @@ -47,6 +47,7 @@ * is wholly independent of the Postgres code. */ +#include "namespace.h" #include #include @@ -58,6 +59,7 @@ #include #include #include +#include "un-namespace.h" #include #include "btree.h" @@ -216,7 +218,7 @@ __bt_open(fname, flags, mode, openinfo, dflags) if (_fcntl(t->bt_fd, F_SETFD, 1) == -1) goto err; - if (fstat(t->bt_fd, &sb)) + if (_fstat(t->bt_fd, &sb)) goto err; if (sb.st_size) { if ((nr = _read(t->bt_fd, &m, sizeof(BTMETA))) < 0) @@ -398,10 +400,10 @@ tmp() sizeof(path), "%s/bt.XXXXXXXXXX", envtmp ? envtmp : "/tmp"); (void)sigfillset(&set); - (void)sigprocmask(SIG_BLOCK, &set, &oset); + (void)_sigprocmask(SIG_BLOCK, &set, &oset); if ((fd = mkstemp(path)) != -1) (void)unlink(path); - (void)sigprocmask(SIG_SETMASK, &oset, NULL); + (void)_sigprocmask(SIG_SETMASK, &oset, NULL); return(fd); } diff --git a/lib/libc/db/hash/hash.c b/lib/libc/db/hash/hash.c index 7d05478a8a..329d10b1b4 100644 --- a/lib/libc/db/hash/hash.c +++ b/lib/libc/db/hash/hash.c @@ -34,11 +34,12 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/db/hash/hash.c,v 1.8 2000/01/27 23:06:08 jasone Exp $ - * $DragonFly: src/lib/libc/db/hash/hash.c,v 1.4 2004/10/25 19:38:01 drhodus Exp $ + * $DragonFly: src/lib/libc/db/hash/hash.c,v 1.5 2005/01/31 22:29:09 dillon Exp $ * * @(#)hash.c 8.9 (Berkeley) 6/16/94 */ +#include "namespace.h" #include #include @@ -51,6 +52,7 @@ #ifdef DEBUG #include #endif +#include "un-namespace.h" #include #include "hash.h" @@ -135,7 +137,7 @@ __hash_open(file, flags, mode, info, dflags) /* if the .db file is empty, and we had permission to create a new .db file, then reinitialize the database */ if ((flags & O_CREAT) && - fstat(hashp->fp, &statbuf) == 0 && statbuf.st_size == 0) + _fstat(hashp->fp, &statbuf) == 0 && statbuf.st_size == 0) new_table = 1; (void)_fcntl(hashp->fp, F_SETFD, 1); @@ -544,7 +546,8 @@ hash_get(dbp, key, data, flag) hashp = (HTAB *)dbp->internal; if (flag) { - hashp->error = errno = EINVAL; + hashp->error = EINVAL; + errno = EINVAL; return (ERROR); } return (hash_access(hashp, HASH_GET, (DBT *)key, data)); diff --git a/lib/libc/db/hash/hash_page.c b/lib/libc/db/hash/hash_page.c index b42f30fc9e..2cbac96056 100644 --- a/lib/libc/db/hash/hash_page.c +++ b/lib/libc/db/hash/hash_page.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/db/hash/hash_page.c,v 1.5 2000/01/27 23:06:08 jasone Exp $ - * $DragonFly: src/lib/libc/db/hash/hash_page.c,v 1.4 2004/10/25 19:38:01 drhodus Exp $ + * $DragonFly: src/lib/libc/db/hash/hash_page.c,v 1.5 2005/01/31 22:29:09 dillon Exp $ * * @(#)hash_page.c 8.7 (Berkeley) 8/16/94 */ @@ -55,6 +55,7 @@ * open_temp */ +#include "namespace.h" #include #include @@ -67,6 +68,7 @@ #ifdef DEBUG #include #endif +#include "un-namespace.h" #include #include "hash.h" @@ -865,12 +867,12 @@ open_temp(hashp) /* Block signals; make sure file goes away at process exit. */ (void)sigfillset(&set); - (void)sigprocmask(SIG_BLOCK, &set, &oset); + (void)_sigprocmask(SIG_BLOCK, &set, &oset); if ((hashp->fp = mkstemp(namestr)) != -1) { (void)unlink(namestr); (void)_fcntl(hashp->fp, F_SETFD, 1); } - (void)sigprocmask(SIG_SETMASK, &oset, (sigset_t *)NULL); + (void)_sigprocmask(SIG_SETMASK, &oset, (sigset_t *)NULL); return (hashp->fp != -1 ? 0 : -1); } diff --git a/lib/libc/db/mpool/mpool.c b/lib/libc/db/mpool/mpool.c index 488c773675..22889c6a53 100644 --- a/lib/libc/db/mpool/mpool.c +++ b/lib/libc/db/mpool/mpool.c @@ -31,11 +31,12 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/db/mpool/mpool.c,v 1.5.2.1 2001/03/05 23:05:01 obrien Exp $ - * $DragonFly: src/lib/libc/db/mpool/mpool.c,v 1.3 2003/11/12 20:21:23 eirikn Exp $ + * $DragonFly: src/lib/libc/db/mpool/mpool.c,v 1.4 2005/01/31 22:29:11 dillon Exp $ * * @(#)mpool.c 8.5 (Berkeley) 7/26/94 */ +#include "namespace.h" #include #include #include @@ -45,6 +46,7 @@ #include #include #include +#include "un-namespace.h" #include @@ -75,7 +77,7 @@ mpool_open(key, fd, pagesize, maxcache) * XXX * We don't currently handle pipes, although we should. */ - if (fstat(fd, &sb)) + if (_fstat(fd, &sb)) return (NULL); if (!S_ISREG(sb.st_mode)) { errno = ESPIPE; diff --git a/lib/libc/db/recno/rec_close.c b/lib/libc/db/recno/rec_close.c index fb4c5df122..cc3ef223de 100644 --- a/lib/libc/db/recno/rec_close.c +++ b/lib/libc/db/recno/rec_close.c @@ -32,9 +32,10 @@ * * @(#)rec_close.c 8.6 (Berkeley) 8/18/94 * $FreeBSD: src/lib/libc/db/recno/rec_close.c,v 1.4 2000/01/27 23:06:11 jasone Exp $ - * $DragonFly: src/lib/libc/db/recno/rec_close.c,v 1.2 2003/06/17 04:26:42 dillon Exp $ + * $DragonFly: src/lib/libc/db/recno/rec_close.c,v 1.3 2005/01/31 22:29:13 dillon Exp $ */ +#include "namespace.h" #include #include #include @@ -43,6 +44,7 @@ #include #include #include +#include "un-namespace.h" #include #include "recno.h" @@ -163,7 +165,7 @@ __rec_sync(dbp, flags) while (status == RET_SUCCESS) { iov[0].iov_base = data.data; iov[0].iov_len = data.size; - if (writev(t->bt_rfd, iov, 2) != data.size + 1) + if (_writev(t->bt_rfd, iov, 2) != data.size + 1) return (RET_ERROR); status = (dbp->seq)(dbp, &key, &data, R_NEXT); } diff --git a/lib/libc/db/recno/rec_open.c b/lib/libc/db/recno/rec_open.c index 5ab519fa89..07812df3d4 100644 --- a/lib/libc/db/recno/rec_open.c +++ b/lib/libc/db/recno/rec_open.c @@ -35,9 +35,10 @@ * * @(#)rec_open.c 8.10 (Berkeley) 9/1/94 * $FreeBSD: src/lib/libc/db/recno/rec_open.c,v 1.4 2000/01/27 23:06:11 jasone Exp $ - * $DragonFly: src/lib/libc/db/recno/rec_open.c,v 1.2 2003/06/17 04:26:42 dillon Exp $ + * $DragonFly: src/lib/libc/db/recno/rec_open.c,v 1.3 2005/01/31 22:29:13 dillon Exp $ */ +#include "namespace.h" #include #include #include @@ -48,6 +49,7 @@ #include #include #include +#include "un-namespace.h" #include #include "recno.h" @@ -144,7 +146,7 @@ slow: if ((t->bt_rfp = fdopen(rfd, "r")) == NULL) goto einval; } - if (fstat(rfd, &sb)) + if (_fstat(rfd, &sb)) goto err; /* * Kluge -- we'd like to test to see if the file is too diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index 7d7b13838b..7a32a81e7c 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -1,12 +1,12 @@ # @(#)Makefile.inc 8.6 (Berkeley) 5/4/95 # $FreeBSD: src/lib/libc/gen/Makefile.inc,v 1.62.2.19 2003/02/21 13:46:16 phantom Exp $ -# $DragonFly: src/lib/libc/gen/Makefile.inc,v 1.5 2004/12/16 22:55:29 joerg Exp $ +# $DragonFly: src/lib/libc/gen/Makefile.inc,v 1.6 2005/01/31 22:29:15 dillon Exp $ # machine-independent gen sources .PATH: ${.CURDIR}/../libc/${MACHINE_ARCH}/gen ${.CURDIR}/../libc/gen -SRCS+= _rand48.c _spinlock_stub.c alarm.c arc4random.c assert.c \ - basename.c \ +SRCS+= _pthread_stubs.c _rand48.c _spinlock_stub.c _thread_init.c \ + alarm.c arc4random.c assert.c basename.c \ clock.c closedir.c confstr.c \ crypt.c ctermid.c daemon.c devname.c dirname.c disklabel.c \ dlfcn.c drand48.c erand48.c err.c errlst.c \ diff --git a/lib/libc/gen/_pthread_stubs.c b/lib/libc/gen/_pthread_stubs.c new file mode 100644 index 0000000000..0f6341e482 --- /dev/null +++ b/lib/libc/gen/_pthread_stubs.c @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2001 Daniel Eischen . + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: /repoman/r/ncvs/src/lib/libc/gen/_pthread_stubs.c,v 1.1 2001/01/24 12:59:20 deischen Exp $ + * $DragonFly: src/lib/libc/gen/_pthread_stubs.c,v 1.1 2005/01/31 22:29:15 dillon Exp $ + */ + +#include + +/* + * Weak symbols: All libc internal usage of these functions should + * use the weak symbol versions (_pthread_XXX). If libpthread is + * linked, it will override these functions with (non-weak) routines. + * The _pthread_XXX functions are provided solely for internal libc + * usage to avoid unwanted cancellation points and to differentiate + * between application locks and libc locks (threads holding the + * latter can't be allowed to exit/terminate). + */ +#pragma weak _pthread_getspecific=_pthread_getspecific_stub +#pragma weak _pthread_key_create=_pthread_key_create_stub +#pragma weak _pthread_key_delete=_pthread_key_delete_stub +#pragma weak _pthread_mutex_destroy=_pthread_mutex_destroy_stub +#pragma weak _pthread_mutex_init=_pthread_mutex_init_stub +#pragma weak _pthread_mutex_lock=_pthread_mutex_lock_stub +#pragma weak _pthread_mutex_trylock=_pthread_mutex_trylock_stub +#pragma weak _pthread_mutex_unlock=_pthread_mutex_unlock_stub +#pragma weak _pthread_mutexattr_init=_pthread_mutexattr_init_stub +#pragma weak _pthread_mutexattr_destroy=_pthread_mutexattr_destroy_stub +#pragma weak _pthread_mutexattr_settype=_pthread_mutexattr_settype_stub +#pragma weak _pthread_once=_pthread_once_stub +#pragma weak _pthread_setspecific=_pthread_setspecific_stub + + +void * +_pthread_getspecific_stub(pthread_key_t key) +{ + return (NULL); +} + +int +_pthread_key_create_stub(pthread_key_t *key, void (*destructor) (void *)) +{ + return (0); +} + +int +_pthread_key_delete_stub(pthread_key_t key) +{ + return (0); +} + +int +_pthread_mutex_destroy_stub(pthread_mutex_t *mattr) +{ + return (0); +} + +int +_pthread_mutex_init_stub(pthread_mutex_t *mutex, const pthread_mutexattr_t *mattr) +{ + return (0); +} + +int +_pthread_mutex_lock_stub(pthread_mutex_t *mutex) +{ + return (0); +} + +int +_pthread_mutex_trylock_stub(pthread_mutex_t *mutex) +{ + return (0); +} + +int +_pthread_mutex_unlock_stub(pthread_mutex_t *mutex) +{ + return (0); +} + +int +_pthread_mutexattr_init_stub(pthread_mutexattr_t *mattr) +{ + return (0); +} + +int +_pthread_mutexattr_destroy_stub(pthread_mutexattr_t *mattr) +{ + return (0); +} + +int +_pthread_mutexattr_settype_stub(pthread_mutexattr_t *mattr, int type) +{ + return (0); +} + +int +_pthread_once_stub(pthread_once_t *once_control, void (*init_routine) (void)) +{ + return (0); +} + +int +_pthread_setspecific_stub(pthread_key_t key, const void *value) +{ + return (0); +} + diff --git a/lib/libc/gen/_spinlock_stub.c b/lib/libc/gen/_spinlock_stub.c index 344b98fb26..454233e9c6 100644 --- a/lib/libc/gen/_spinlock_stub.c +++ b/lib/libc/gen/_spinlock_stub.c @@ -30,26 +30,36 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/_spinlock_stub.c,v 1.4 1999/08/27 23:58:27 peter Exp $ - * $DragonFly: src/lib/libc/gen/_spinlock_stub.c,v 1.3 2004/01/23 11:30:27 joerg Exp $ + * $DragonFly: src/lib/libc/gen/_spinlock_stub.c,v 1.4 2005/01/31 22:29:15 dillon Exp $ * */ #include /* Don't build these stubs into libc_r: */ -#ifndef _THREAD_SAFE #include "spinlock.h" /* - * Declare weak references in case the application is not linked + * Declare weak definitions in case the application is not linked * with libpthread. */ +#pragma weak _atomic_lock=_atomic_lock_stub #pragma weak _spinlock=_spinlock_stub #pragma weak _spinlock_debug=_spinlock_debug_stub +#pragma weak _spinunlock=_spinunlock_stub void _spinlock(spinlock_t *); void _spinlock_debug(spinlock_t *, char *, int); +/* + * This function is a stub for the _atomic_lock function in libpthread. + */ +long +_atomic_lock_stub(volatile long *lck) +{ + return (0L); +} + /* * This function is a stub for the spinlock function in libpthread. */ @@ -58,6 +68,14 @@ _spinlock_stub(spinlock_t *lck) { } +/* + * This function is a stub for the spinunlock function in libpthread. + */ +void +_spinunlock_stub(spinlock_t *lck) +{ +} + /* * This function is a stub for the debug spinlock function in libpthread. */ @@ -65,4 +83,3 @@ void _spinlock_debug_stub(spinlock_t *lck, char *fname, int lineno) { } -#endif diff --git a/lib/libc/gen/_thread_init.c b/lib/libc/gen/_thread_init.c new file mode 100644 index 0000000000..1eba8adbc8 --- /dev/null +++ b/lib/libc/gen/_thread_init.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2001 Daniel Eischen + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY DANIEL EISCHEN AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $DragonFly: src/lib/libc/gen/_thread_init.c,v 1.1 2005/01/31 22:29:15 dillon Exp $ + */ + +#include + +#include + +__weak_reference(_thread_init_stub, _thread_init); +__weak_reference(_thread_autoinit_dummy_decl_stub, _thread_autoinit_dummy_decl); + +int _thread_autoinit_dummy_decl_stub = 0; + +void +_thread_init_stub(void) +{ + /* This is just a stub; there is nothing to do. */ +} diff --git a/lib/libc/gen/arc4random.c b/lib/libc/gen/arc4random.c index c07453666b..9af7f5ab20 100644 --- a/lib/libc/gen/arc4random.c +++ b/lib/libc/gen/arc4random.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/lib/libc/gen/arc4random.c,v 1.4 2000/01/27 23:06:13 jasone Exp $ */ -/* $DragonFly: src/lib/libc/gen/arc4random.c,v 1.4 2004/06/19 18:55:47 joerg Exp $ */ +/* $DragonFly: src/lib/libc/gen/arc4random.c,v 1.5 2005/01/31 22:29:15 dillon Exp $ */ /* * Arc4 random number generator for OpenBSD. @@ -26,11 +26,13 @@ * RC4 is a registered trademark of RSA Laboratories. */ +#include "namespace.h" #include #include #include #include #include +#include "un-namespace.h" struct arc4_stream { u_int8_t i; diff --git a/lib/libc/gen/closedir.c b/lib/libc/gen/closedir.c index d4201c847d..8a953b3a92 100644 --- a/lib/libc/gen/closedir.c +++ b/lib/libc/gen/closedir.c @@ -31,15 +31,20 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/closedir.c,v 1.6.2.1 2001/03/05 08:29:56 obrien Exp $ - * $DragonFly: src/lib/libc/gen/closedir.c,v 1.3 2003/11/12 20:21:23 eirikn Exp $ + * $DragonFly: src/lib/libc/gen/closedir.c,v 1.4 2005/01/31 22:29:15 dillon Exp $ * * @(#)closedir.c 8.1 (Berkeley) 6/10/93 */ +#include "namespace.h" #include #include +#include #include #include +#include "un-namespace.h" + +#include "libc_private.h" extern void _reclaim_telldir (DIR *); @@ -47,17 +52,22 @@ extern void _reclaim_telldir (DIR *); * close a directory. */ int -closedir(dirp) - DIR *dirp; +closedir(DIR *dirp) { int fd; - seekdir(dirp, dirp->dd_rewind); /* free seekdir storage */ + if (__isthreaded) + _pthread_mutex_lock((pthread_mutex_t *)&dirp->dd_lock); + _seekdir(dirp, dirp->dd_rewind); /* free seekdir storage */ fd = dirp->dd_fd; dirp->dd_fd = -1; dirp->dd_loc = 0; free((void *)dirp->dd_buf); _reclaim_telldir(dirp); + if (__isthreaded) { + _pthread_mutex_unlock((pthread_mutex_t *)&dirp->dd_lock); + _pthread_mutex_destroy((pthread_mutex_t *)&dirp->dd_lock); + } free((void *)dirp); return(_close(fd)); } diff --git a/lib/libc/gen/daemon.c b/lib/libc/gen/daemon.c index 4725b7ca74..4550478f6c 100644 --- a/lib/libc/gen/daemon.c +++ b/lib/libc/gen/daemon.c @@ -31,14 +31,16 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/daemon.c,v 1.3 2000/01/27 23:06:14 jasone Exp $ - * $DragonFly: src/lib/libc/gen/daemon.c,v 1.2 2003/06/17 04:26:42 dillon Exp $ + * $DragonFly: src/lib/libc/gen/daemon.c,v 1.3 2005/01/31 22:29:15 dillon Exp $ * * @(#)daemon.c 8.1 (Berkeley) 6/4/93 */ +#include "namespace.h" #include #include #include +#include "un-namespace.h" int daemon(nochdir, noclose) @@ -62,9 +64,9 @@ daemon(nochdir, noclose) (void)chdir("/"); if (!noclose && (fd = _open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { - (void)dup2(fd, STDIN_FILENO); - (void)dup2(fd, STDOUT_FILENO); - (void)dup2(fd, STDERR_FILENO); + (void)_dup2(fd, STDIN_FILENO); + (void)_dup2(fd, STDOUT_FILENO); + (void)_dup2(fd, STDERR_FILENO); if (fd > 2) (void)_close(fd); } diff --git a/lib/libc/gen/devname.c b/lib/libc/gen/devname.c index b90a8fae2b..b922220da1 100644 --- a/lib/libc/gen/devname.c +++ b/lib/libc/gen/devname.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/devname.c,v 1.2.2.2 2001/07/31 20:10:19 tmm Exp $ - * $DragonFly: src/lib/libc/gen/devname.c,v 1.4 2004/01/06 15:38:09 eirikn Exp $ + * $DragonFly: src/lib/libc/gen/devname.c,v 1.5 2005/01/31 22:29:15 dillon Exp $ * * @(#)devname.c 8.2 (Berkeley) 4/29/95 */ @@ -41,7 +41,6 @@ #include #include -#include #include #include #include diff --git a/lib/libc/gen/exec.c b/lib/libc/gen/exec.c index c874cee7ca..fa2c5fa0db 100644 --- a/lib/libc/gen/exec.c +++ b/lib/libc/gen/exec.c @@ -31,12 +31,13 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/exec.c,v 1.15 2000/01/27 23:06:14 jasone Exp $ - * $DragonFly: src/lib/libc/gen/exec.c,v 1.4 2004/07/27 07:59:10 asmodai Exp $ + * $DragonFly: src/lib/libc/gen/exec.c,v 1.5 2005/01/31 22:29:15 dillon Exp $ * * @(#)exec.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/gen/exec.c,v 1.15 2000/01/27 23:06:14 jasone Exp $ */ +#include "namespace.h" #include #include #include @@ -46,6 +47,7 @@ #include #include #include +#include "un-namespace.h" #include @@ -74,7 +76,7 @@ execl(const char *name, const char *arg, ...) while ((argv[n] = va_arg(ap, char *)) != NULL) n++; va_end(ap); - return (execve(name, argv, environ)); + return (_execve(name, argv, environ)); } int @@ -101,7 +103,7 @@ execle(const char *name, const char *arg, ...) n++; envp = va_arg(ap, char **); va_end(ap); - return (execve(name, argv, envp)); + return (_execve(name, argv, envp)); } int @@ -136,7 +138,7 @@ execv(name, argv) const char *name; char * const *argv; { - (void)execve(name, argv, environ); + (void)_execve(name, argv, environ); return (-1); } @@ -207,7 +209,7 @@ execvp(name, argv) bcopy(name, buf + lp + 1, ln); buf[lp + ln + 1] = '\0'; -retry: (void)execve(bp, argv, environ); +retry: (void)_execve(bp, argv, environ); switch(errno) { case E2BIG: goto done; @@ -226,7 +228,7 @@ retry: (void)execve(bp, argv, environ); memp[0] = "sh"; memp[1] = bp; bcopy(argv + 1, memp + 2, cnt * sizeof(char *)); - (void)execve(_PATH_BSHELL, memp, environ); + (void)_execve(_PATH_BSHELL, memp, environ); goto done; case ENOMEM: goto done; diff --git a/lib/libc/gen/fstab.c b/lib/libc/gen/fstab.c index 773030bb6d..6ad3086f1f 100644 --- a/lib/libc/gen/fstab.c +++ b/lib/libc/gen/fstab.c @@ -31,12 +31,13 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/fstab.c,v 1.8 2000/01/27 23:06:15 jasone Exp $ - * $DragonFly: src/lib/libc/gen/fstab.c,v 1.4 2004/06/06 15:05:55 hmp Exp $ + * $DragonFly: src/lib/libc/gen/fstab.c,v 1.5 2005/01/31 22:29:15 dillon Exp $ * * @(#)fstab.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/gen/fstab.c,v 1.8 2000/01/27 23:06:15 jasone Exp $ */ +#include "namespace.h" #include #include #include @@ -48,6 +49,7 @@ #include #include #include +#include "un-namespace.h" static FILE *_fs_fp; static struct fstab _fs_fstab; diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c index 156e8cdfeb..80cb8e2c16 100644 --- a/lib/libc/gen/fts.c +++ b/lib/libc/gen/fts.c @@ -33,12 +33,13 @@ * $OpenBSD: fts.c,v 1.22 1999/10/03 19:22:22 millert Exp $ * * $FreeBSD: src/lib/libc/gen/fts.c,v 1.14.2.4 2001/06/01 22:00:34 kris Exp $ - * $DragonFly: src/lib/libc/gen/fts.c,v 1.4 2004/06/06 15:05:55 hmp Exp $ + * $DragonFly: src/lib/libc/gen/fts.c,v 1.5 2005/01/31 22:29:15 dillon Exp $ * * @(#)fts.c 8.6 (Berkeley) 8/14/94 * $FreeBSD: src/lib/libc/gen/fts.c,v 1.14.2.4 2001/06/01 22:00:34 kris Exp $ */ +#include "namespace.h" #include #include @@ -49,6 +50,7 @@ #include #include #include +#include "un-namespace.h" static FTSENT *fts_alloc (FTS *, char *, int); static FTSENT *fts_build (FTS *, int); @@ -1079,7 +1081,7 @@ fts_safe_changedir(sp, p, fd, path) return (0); if (fd < 0 && (newfd = _open(path, O_RDONLY, 0)) < 0) return (-1); - if (fstat(newfd, &sb)) { + if (_fstat(newfd, &sb)) { ret = -1; goto bail; } diff --git a/lib/libc/gen/getcap.c b/lib/libc/gen/getcap.c index cf3081afa2..f71fbf0f1c 100644 --- a/lib/libc/gen/getcap.c +++ b/lib/libc/gen/getcap.c @@ -34,15 +34,15 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/getcap.c,v 1.11.2.2 2001/01/15 06:48:09 gad Exp $ - * $DragonFly: src/lib/libc/gen/getcap.c,v 1.4 2004/06/06 15:05:55 hmp Exp $ + * $DragonFly: src/lib/libc/gen/getcap.c,v 1.5 2005/01/31 22:29:15 dillon Exp $ * * @(#)getcap.c 8.3 (Berkeley) 3/25/94 */ +#include "namespace.h" #include #include -#include #include #include #include @@ -50,6 +50,9 @@ #include #include #include +#include "un-namespace.h" + +#include #define BFRAG 1024 #define BSIZE 1024 diff --git a/lib/libc/gen/getcwd.c b/lib/libc/gen/getcwd.c index 6d00b2413b..c98029d61a 100644 --- a/lib/libc/gen/getcwd.c +++ b/lib/libc/gen/getcwd.c @@ -31,22 +31,24 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/getcwd.c,v 1.18 1999/09/28 13:24:13 marcel Exp $ - * $DragonFly: src/lib/libc/gen/getcwd.c,v 1.3 2004/06/06 15:05:55 hmp Exp $ + * $DragonFly: src/lib/libc/gen/getcwd.c,v 1.4 2005/01/31 22:29:15 dillon Exp $ * * @(#)getcwd.c 8.5 (Berkeley) 2/7/95 */ +#include "namespace.h" #include #include #include #include #include +#include #include #include #include #include -#include +#include "un-namespace.h" #define ISDOT(dp) \ (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || \ @@ -194,7 +196,7 @@ getcwd(pt, size) *bup = '\0'; /* Open and stat parent directory. */ - if (!(dir = opendir(up)) || fstat(dirfd(dir), &s)) + if (!(dir = opendir(up)) || _fstat(dirfd(dir), &s)) goto err; /* Add trailing slash for next directory. */ diff --git a/lib/libc/gen/getlogin.c b/lib/libc/gen/getlogin.c index 6463f14dbe..74013a4d8e 100644 --- a/lib/libc/gen/getlogin.c +++ b/lib/libc/gen/getlogin.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/getlogin.c,v 1.4.2.1 2001/03/05 09:06:50 obrien Exp $ - * $DragonFly: src/lib/libc/gen/getlogin.c,v 1.2 2003/06/17 04:26:42 dillon Exp $ + * $DragonFly: src/lib/libc/gen/getlogin.c,v 1.3 2005/01/31 22:29:15 dillon Exp $ * * @(#)getlogin.c 8.1 (Berkeley) 6/4/93 */ @@ -43,22 +43,19 @@ #include #include #include +#include "namespace.h" +#include +#include "un-namespace.h" #include -#ifndef _THREAD_SAFE -#define THREAD_LOCK() -#define THREAD_UNLOCK() -#else -#include -#include "pthread_private.h" -static struct pthread_mutex logname_lock = PTHREAD_MUTEX_STATIC_INITIALIZER; -static pthread_mutex_t logname_mutex = &logname_lock; -#define THREAD_LOCK() if (__isthreaded) pthread_mutex_lock(&logname_mutex) -#define THREAD_UNLOCK() if (__isthreaded) pthread_mutex_unlock(&logname_mutex) -#endif /* _THREAD_SAFE */ +#define THREAD_LOCK() if (__isthreaded) _pthread_mutex_lock(&logname_mutex) +#define THREAD_UNLOCK() if (__isthreaded) _pthread_mutex_unlock(&logname_mutex) -int _logname_valid; /* known to setlogin() */ +extern int _getlogin(char *, int); + +int _logname_valid; /* known to setlogin() */ +static pthread_mutex_t logname_mutex = PTHREAD_MUTEX_INITIALIZER; static char * getlogin_basic(int *status) @@ -67,7 +64,7 @@ getlogin_basic(int *status) if (_logname_valid == 0) { #ifdef __NETBSD_SYSCALLS - if (__getlogin(logname, sizeof(logname) - 1) < 0) { + if (_getlogin(logname, sizeof(logname) - 1) < 0) { #else if (_getlogin(logname, sizeof(logname)) < 0) { #endif diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c index 01db1dfc7d..10069200f7 100644 --- a/lib/libc/gen/getpwent.c +++ b/lib/libc/gen/getpwent.c @@ -32,13 +32,13 @@ * * @(#)getpwent.c 8.2 (Berkeley) 4/27/95 * $FreeBSD: src/lib/libc/gen/getpwent.c,v 1.53.2.2 2001/03/05 09:52:13 obrien Exp $ - * $DragonFly: src/lib/libc/gen/getpwent.c,v 1.4 2004/06/06 15:05:55 hmp Exp $ + * $DragonFly: src/lib/libc/gen/getpwent.c,v 1.5 2005/01/31 22:29:15 dillon Exp $ */ +#include "namespace.h" #include #include #include -#include #include #include #include @@ -48,6 +48,9 @@ #include #include #include +#include "un-namespace.h" + +#include extern void setnetgrent ( char * ); extern int getnetgrent ( char **, char **, char ** ); diff --git a/lib/libc/gen/isatty.c b/lib/libc/gen/isatty.c index f82437506d..3d8ffb621f 100644 --- a/lib/libc/gen/isatty.c +++ b/lib/libc/gen/isatty.c @@ -31,34 +31,20 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/isatty.c,v 1.3.6.1 2001/03/05 09:52:13 obrien Exp $ - * $DragonFly: src/lib/libc/gen/isatty.c,v 1.2 2003/06/17 04:26:42 dillon Exp $ + * $DragonFly: src/lib/libc/gen/isatty.c,v 1.3 2005/01/31 22:29:15 dillon Exp $ * * @(#)isatty.c 8.1 (Berkeley) 6/4/93 */ #include #include -#ifdef _THREAD_SAFE -#include -#include "pthread_private.h" -#endif int -isatty(fd) - int fd; +isatty(int fd) { int retval; struct termios t; -#ifdef _THREAD_SAFE - if (_FD_LOCK(fd, FD_READ, NULL) == 0) { -#endif - retval = (tcgetattr(fd, &t) != -1); -#ifdef _THREAD_SAFE - _FD_UNLOCK(fd, FD_READ); - } else { - retval = 0; - } -#endif + retval = (tcgetattr(fd, &t) != -1); return(retval); } diff --git a/lib/libc/gen/lockf.c b/lib/libc/gen/lockf.c index 0dfad2431b..38cb99b381 100644 --- a/lib/libc/gen/lockf.c +++ b/lib/libc/gen/lockf.c @@ -36,14 +36,14 @@ * POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/lockf.c,v 1.5 2000/01/27 23:06:17 jasone Exp $ - * $DragonFly: src/lib/libc/gen/lockf.c,v 1.2 2003/06/17 04:26:42 dillon Exp $ - * - * $FreeBSD: src/lib/libc/gen/lockf.c,v 1.5 2000/01/27 23:06:17 jasone Exp $ + * $DragonFly: src/lib/libc/gen/lockf.c,v 1.3 2005/01/31 22:29:15 dillon Exp $ */ +#include "namespace.h" #include #include #include +#include "un-namespace.h" int lockf(filedes, function, size) diff --git a/lib/libc/gen/nlist.c b/lib/libc/gen/nlist.c index f8aca946eb..f3981c61f9 100644 --- a/lib/libc/gen/nlist.c +++ b/lib/libc/gen/nlist.c @@ -31,11 +31,12 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/nlist.c,v 1.12.2.1 2001/07/11 23:59:09 obrien Exp $ - * $DragonFly: src/lib/libc/gen/nlist.c,v 1.4 2004/06/06 15:05:55 hmp Exp $ + * $DragonFly: src/lib/libc/gen/nlist.c,v 1.5 2005/01/31 22:29:15 dillon Exp $ * * @(#)nlist.c 8.1 (Berkeley) 6/4/93 */ +#include "namespace.h" #include #include #include @@ -46,6 +47,7 @@ #include #include #include +#include "un-namespace.h" #define _NLIST_DO_AOUT #define _NLIST_DO_ELF @@ -117,7 +119,7 @@ __aout_fdnlist(fd, list) struct stat st; /* check that file is at least as large as struct exec! */ - if ((fstat(fd, &st) < 0) || (st.st_size < sizeof(struct exec))) + if ((_fstat(fd, &st) < 0) || (st.st_size < sizeof(struct exec))) return (-1); /* Check for files too large to mmap. */ @@ -257,7 +259,7 @@ __elf_fdnlist(fd, list) if (lseek(fd, (off_t)0, SEEK_SET) == -1 || _read(fd, &ehdr, sizeof(Elf_Ehdr)) != sizeof(Elf_Ehdr) || !__elf_is_okay__(&ehdr) || - fstat(fd, &st) < 0) + _fstat(fd, &st) < 0) return (-1); /* calculate section header table size */ diff --git a/lib/libc/gen/opendir.c b/lib/libc/gen/opendir.c index 9605e6a1ce..d272c63d16 100644 --- a/lib/libc/gen/opendir.c +++ b/lib/libc/gen/opendir.c @@ -31,11 +31,12 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/opendir.c,v 1.10.2.1 2001/06/04 20:59:48 joerg Exp $ - * $DragonFly: src/lib/libc/gen/opendir.c,v 1.2 2003/06/17 04:26:42 dillon Exp $ + * $DragonFly: src/lib/libc/gen/opendir.c,v 1.3 2005/01/31 22:29:15 dillon Exp $ * * @(#)opendir.c 8.8 (Berkeley) 5/1/95 */ +#include "namespace.h" #include #include #include @@ -45,6 +46,7 @@ #include #include #include +#include "un-namespace.h" /* * Open a directory. @@ -53,7 +55,6 @@ DIR * opendir(name) const char *name; { - return (__opendir2(name, DTF_HIDEW|DTF_NODUP)); } @@ -70,8 +71,8 @@ __opendir2(name, flags) struct stat statb; /* - * stat() before open() because opening of special files may be - * harmful. fstat() after open because the file may have changed. + * stat() before _open() because opening of special files may be + * harmful. _fstat() after open because the file may have changed. */ if (stat(name, &statb) != 0) return (NULL); @@ -82,7 +83,7 @@ __opendir2(name, flags) if ((fd = _open(name, O_RDONLY | O_NONBLOCK)) == -1) return (NULL); dirp = NULL; - if (fstat(fd, &statb) != 0) + if (_fstat(fd, &statb) != 0) goto fail; if (!S_ISDIR(statb.st_mode)) { errno = ENOTDIR; @@ -95,7 +96,7 @@ __opendir2(name, flags) /* * Use the system page size if that is a multiple of DIRBLKSIZ. * Hopefully this can be a big win someday by allowing page - * trades to user space to be done by getdirentries(). + * trades to user space to be done by _getdirentries(). */ incr = getpagesize(); if ((incr % DIRBLKSIZ) != 0) @@ -107,7 +108,7 @@ __opendir2(name, flags) if (flags & DTF_NODUP) { struct statfs sfb; - if (fstatfs(fd, &sfb) < 0) + if (_fstatfs(fd, &sfb) < 0) goto fail; unionstack = !strcmp(sfb.f_fstypename, "union") || (sfb.f_flags & MNT_UNION); @@ -134,7 +135,7 @@ __opendir2(name, flags) do { /* * Always make at least DIRBLKSIZ bytes - * available to getdirentries + * available to _getdirentries */ if (space < DIRBLKSIZ) { space += incr; @@ -259,6 +260,7 @@ __opendir2(name, flags) dirp->dd_loc = 0; dirp->dd_fd = fd; dirp->dd_flags = flags; + dirp->dd_lock = NULL; /* * Set up seek point for rewinddir. diff --git a/lib/libc/gen/pause.c b/lib/libc/gen/pause.c index 81a8d448ff..1025dfaf58 100644 --- a/lib/libc/gen/pause.c +++ b/lib/libc/gen/pause.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/pause.c,v 1.3.2.1 2000/03/18 23:13:23 jasone Exp $ - * $DragonFly: src/lib/libc/gen/pause.c,v 1.2 2003/06/17 04:26:42 dillon Exp $ + * $DragonFly: src/lib/libc/gen/pause.c,v 1.3 2005/01/31 22:29:15 dillon Exp $ * * @(#)pause.c 8.1 (Berkeley) 6/4/93 */ @@ -48,6 +48,4 @@ __pause() return sigpause(sigblock(0L)); } -#ifndef _THREAD_SAFE __weak_reference(__pause, pause); -#endif diff --git a/lib/libc/gen/popen.c b/lib/libc/gen/popen.c index 603fa6a98d..c848ca2d89 100644 --- a/lib/libc/gen/popen.c +++ b/lib/libc/gen/popen.c @@ -34,11 +34,12 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/popen.c,v 1.14 2000/01/27 23:06:19 jasone Exp $ - * $DragonFly: src/lib/libc/gen/popen.c,v 1.3 2004/06/06 15:05:55 hmp Exp $ + * $DragonFly: src/lib/libc/gen/popen.c,v 1.4 2005/01/31 22:29:15 dillon Exp $ * * @(#)popen.c 8.3 (Berkeley) 5/3/95 */ +#include "namespace.h" #include #include @@ -49,6 +50,7 @@ #include #include #include +#include "un-namespace.h" extern char **environ; @@ -69,7 +71,7 @@ popen(command, type) struct pid *p; /* - * Lite2 introduced two-way popen() pipes using socketpair(). + * Lite2 introduced two-way popen() pipes using _socketpair(). * FreeBSD's pipe() is bidirectional, so we use that. */ if (strchr(type, '+')) { @@ -104,7 +106,7 @@ popen(command, type) case 0: /* Child. */ if (*type == 'r') { /* - * The dup2() to STDIN_FILENO is repeated to avoid + * The _dup2() to STDIN_FILENO is repeated to avoid * writing to pdes[1], which might corrupt the * parent's copy. This isn't good enough in * general, since the _exit() is no return, so @@ -113,15 +115,15 @@ popen(command, type) */ (void)_close(pdes[0]); if (pdes[1] != STDOUT_FILENO) { - (void)dup2(pdes[1], STDOUT_FILENO); + (void)_dup2(pdes[1], STDOUT_FILENO); (void)_close(pdes[1]); if (twoway) - (void)dup2(STDOUT_FILENO, STDIN_FILENO); + (void)_dup2(STDOUT_FILENO, STDIN_FILENO); } else if (twoway && (pdes[1] != STDIN_FILENO)) - (void)dup2(pdes[1], STDIN_FILENO); + (void)_dup2(pdes[1], STDIN_FILENO); } else { if (pdes[0] != STDIN_FILENO) { - (void)dup2(pdes[0], STDIN_FILENO); + (void)_dup2(pdes[0], STDIN_FILENO); (void)_close(pdes[0]); } (void)_close(pdes[1]); @@ -129,7 +131,7 @@ popen(command, type) for (p = pidlist; p; p = p->next) { (void)_close(fileno(p->fp)); } - execve(_PATH_BSHELL, argv, environ); + _execve(_PATH_BSHELL, argv, environ); _exit(127); /* NOTREACHED */ } diff --git a/lib/libc/gen/posixshm.c b/lib/libc/gen/posixshm.c index 1086465282..8c9545358f 100644 --- a/lib/libc/gen/posixshm.c +++ b/lib/libc/gen/posixshm.c @@ -27,9 +27,10 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/posixshm.c,v 1.2.2.1 2000/08/22 01:48:12 jhb Exp $ - * $DragonFly: src/lib/libc/gen/posixshm.c,v 1.2 2003/06/17 04:26:42 dillon Exp $ + * $DragonFly: src/lib/libc/gen/posixshm.c,v 1.3 2005/01/31 22:29:15 dillon Exp $ */ +#include "namespace.h" #include #include #include @@ -37,6 +38,7 @@ #include #include +#include "un-namespace.h" int shm_open(const char *path, int flags, mode_t mode) @@ -49,7 +51,7 @@ shm_open(const char *path, int flags, mode_t mode) fd = _open(path, flags, mode); if (fd != -1) { - if (fstat(fd, &stab) != 0 || !S_ISREG(stab.st_mode)) { + if (_fstat(fd, &stab) != 0 || !S_ISREG(stab.st_mode)) { _close(fd); errno = EINVAL; return (-1); diff --git a/lib/libc/gen/psignal.c b/lib/libc/gen/psignal.c index 07577317fe..d2a083bda1 100644 --- a/lib/libc/gen/psignal.c +++ b/lib/libc/gen/psignal.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/psignal.c,v 1.5 2000/01/27 23:06:19 jasone Exp $ - * $DragonFly: src/lib/libc/gen/psignal.c,v 1.3 2004/06/06 15:05:55 hmp Exp $ + * $DragonFly: src/lib/libc/gen/psignal.c,v 1.4 2005/01/31 22:29:15 dillon Exp $ * * @(#)psignal.c 8.1 (Berkeley) 6/4/93 */ @@ -40,9 +40,11 @@ * Print the name of the signal indicated * along with the supplied message. */ +#include "namespace.h" #include #include #include +#include "un-namespace.h" void psignal(sig, s) diff --git a/lib/libc/gen/readdir.c b/lib/libc/gen/readdir.c index bdd9f28349..1b525650d4 100644 --- a/lib/libc/gen/readdir.c +++ b/lib/libc/gen/readdir.c @@ -31,25 +31,26 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/readdir.c,v 1.5.2.4 2002/02/26 22:53:57 alfred Exp $ - * $DragonFly: src/lib/libc/gen/readdir.c,v 1.2 2003/06/17 04:26:42 dillon Exp $ + * $DragonFly: src/lib/libc/gen/readdir.c,v 1.3 2005/01/31 22:29:15 dillon Exp $ * * @(#)readdir.c 8.3 (Berkeley) 9/29/94 */ +#include "namespace.h" #include #include #include #include -#ifdef _THREAD_SAFE #include -#include "pthread_private.h" -#endif /* _THREAD_SAFE */ +#include "un-namespace.h" + +#include "libc_private.h" /* * get next entry in a directory. */ struct dirent * -readdir(dirp) +_readdir_unlocked(dirp) DIR *dirp; { struct dirent *dp; @@ -61,7 +62,7 @@ readdir(dirp) dirp->dd_loc = 0; } if (dirp->dd_loc == 0 && !(dirp->dd_flags & __DTF_READALL)) { - dirp->dd_size = getdirentries(dirp->dd_fd, + dirp->dd_size = _getdirentries(dirp->dd_fd, dirp->dd_buf, dirp->dd_len, &dirp->dd_seek); if (dirp->dd_size <= 0) return (NULL); @@ -81,6 +82,22 @@ readdir(dirp) } } +struct dirent * +readdir(dirp) + DIR *dirp; +{ + struct dirent *dp; + + if (__isthreaded) { + _pthread_mutex_lock((pthread_mutex_t *)&dirp->dd_lock); + dp = _readdir_unlocked(dirp); + _pthread_mutex_unlock((pthread_mutex_t *)&dirp->dd_lock); + } + else + dp = _readdir_unlocked(dirp); + return (dp); +} + int readdir_r(dirp, entry, result) DIR *dirp; @@ -90,31 +107,25 @@ readdir_r(dirp, entry, result) struct dirent *dp; int ret, saved_errno; -#ifdef _THREAD_SAFE - if ((ret = _FD_LOCK(dirp->dd_fd, FD_READ, NULL)) != 0) - return (ret); -#endif - saved_errno = errno; errno = 0; dp = readdir(dirp); + if (__isthreaded) { + _pthread_mutex_lock((pthread_mutex_t *)&dirp->dd_lock); + if ((dp = _readdir_unlocked(dirp)) != NULL) + memcpy(entry, dp, sizeof *entry); + _pthread_mutex_unlock((pthread_mutex_t *)&dirp->dd_lock); + } + else if ((dp = _readdir_unlocked(dirp)) != NULL) + memcpy(entry, dp, sizeof *entry); + if (errno != 0) { if (dp == NULL) { -#ifdef _THREAD_SAFE - _FD_UNLOCK(dirp->dd_fd, FD_READ); -#endif return (errno); } } else errno = saved_errno; - if (dp != NULL) - memcpy(entry, dp, _GENERIC_DIRSIZ(dp)); - -#ifdef _THREAD_SAFE - _FD_UNLOCK(dirp->dd_fd, FD_READ); -#endif - if (dp != NULL) *result = entry; else diff --git a/lib/libc/gen/scandir.c b/lib/libc/gen/scandir.c index c1830445f1..054e641b2b 100644 --- a/lib/libc/gen/scandir.c +++ b/lib/libc/gen/scandir.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/scandir.c,v 1.5.6.1 2001/03/05 09:52:13 obrien Exp $ - * $DragonFly: src/lib/libc/gen/scandir.c,v 1.4 2004/06/06 15:05:55 hmp Exp $ + * $DragonFly: src/lib/libc/gen/scandir.c,v 1.5 2005/01/31 22:29:15 dillon Exp $ * * @(#)scandir.c 8.3 (Berkeley) 1/2/94 */ @@ -43,11 +43,13 @@ * struct dirent (through namelist). Returns -1 if there were any errors. */ +#include "namespace.h" #include #include #include #include #include +#include "un-namespace.h" /* * The DIRSIZ macro is the minimum record length which will hold the directory @@ -75,7 +77,7 @@ scandir(dirname, namelist, select, dcomp) if ((dirp = opendir(dirname)) == NULL) return(-1); - if (fstat(dirp->dd_fd, &stb) < 0) + if (_fstat(dirp->dd_fd, &stb) < 0) goto fail; /* diff --git a/lib/libc/gen/seekdir.c b/lib/libc/gen/seekdir.c index c099d9cafb..0d39deca0e 100644 --- a/lib/libc/gen/seekdir.c +++ b/lib/libc/gen/seekdir.c @@ -31,13 +31,18 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/seekdir.c,v 1.2.8.1 2001/03/05 09:52:13 obrien Exp $ - * $DragonFly: src/lib/libc/gen/seekdir.c,v 1.3 2003/11/12 20:21:23 eirikn Exp $ + * $DragonFly: src/lib/libc/gen/seekdir.c,v 1.4 2005/01/31 22:29:15 dillon Exp $ * * @(#)seekdir.c 8.1 (Berkeley) 6/4/93 */ +#include "namespace.h" #include #include +#include +#include "un-namespace.h" + +#include "libc_private.h" extern void _seekdir ( DIR *, long ); @@ -50,6 +55,9 @@ seekdir(dirp, loc) DIR *dirp; long loc; { - - _seekdir(dirp, loc); + if (__isthreaded) + _pthread_mutex_lock((pthread_mutex_t *)&dirp->dd_lock); + _seekdir(dirp, loc); + if (__isthreaded) + _pthread_mutex_unlock((pthread_mutex_t *)&dirp->dd_lock); } diff --git a/lib/libc/gen/setjmperr.c b/lib/libc/gen/setjmperr.c index f698eadea3..dcbed2baba 100644 --- a/lib/libc/gen/setjmperr.c +++ b/lib/libc/gen/setjmperr.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/setjmperr.c,v 1.3 2000/01/27 23:06:19 jasone Exp $ - * $DragonFly: src/lib/libc/gen/setjmperr.c,v 1.2 2003/06/17 04:26:42 dillon Exp $ + * $DragonFly: src/lib/libc/gen/setjmperr.c,v 1.3 2005/01/31 22:29:15 dillon Exp $ * * @(#)setjmperr.c 8.1 (Berkeley) 6/4/93 */ @@ -43,8 +43,10 @@ * If this routine returns, the program is aborted. */ +#include "namespace.h" #include #include +#include "un-namespace.h" void longjmperror() diff --git a/lib/libc/gen/setmode.c b/lib/libc/gen/setmode.c index 34faffd1b2..08bfd034b0 100644 --- a/lib/libc/gen/setmode.c +++ b/lib/libc/gen/setmode.c @@ -35,9 +35,10 @@ * * @(#)setmode.c 8.2 (Berkeley) 3/25/94 * $FreeBSD: src/lib/libc/gen/setmode.c,v 1.5.2.1 2001/03/05 09:34:10 obrien Exp $ - * $DragonFly: src/lib/libc/gen/setmode.c,v 1.4 2004/06/06 15:05:55 hmp Exp $ + * $DragonFly: src/lib/libc/gen/setmode.c,v 1.5 2005/01/31 22:29:15 dillon Exp $ */ +#include "namespace.h" #include #include @@ -49,6 +50,7 @@ #ifdef SETMODE_DEBUG #include #endif +#include "un-namespace.h" #define SET_LEN 6 /* initial # of bitcmd struct to malloc */ #define SET_LEN_INCR 4 /* # of bitcmd structs to add as needed */ @@ -183,10 +185,10 @@ setmode(p) * as best we can. */ sigfillset(&sigset); - (void)sigprocmask(SIG_BLOCK, &sigset, &sigoset); + (void)_sigprocmask(SIG_BLOCK, &sigset, &sigoset); (void)umask(mask = umask(0)); mask = ~mask; - (void)sigprocmask(SIG_SETMASK, &sigoset, NULL); + (void)_sigprocmask(SIG_SETMASK, &sigoset, NULL); setlen = SET_LEN + 2; diff --git a/lib/libc/gen/siginterrupt.c b/lib/libc/gen/siginterrupt.c index b65b4f96cd..4b74f43719 100644 --- a/lib/libc/gen/siginterrupt.c +++ b/lib/libc/gen/siginterrupt.c @@ -31,12 +31,15 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/siginterrupt.c,v 1.2.8.1 2001/03/05 09:34:53 obrien Exp $ - * $DragonFly: src/lib/libc/gen/siginterrupt.c,v 1.2 2003/06/17 04:26:42 dillon Exp $ + * $DragonFly: src/lib/libc/gen/siginterrupt.c,v 1.3 2005/01/31 22:29:15 dillon Exp $ * * @(#)siginterrupt.c 8.1 (Berkeley) 6/4/93 */ +#include "namespace.h" #include +#include "un-namespace.h" +#include "libc_private.h" /* * Set signal state to prevent restart of system calls @@ -50,7 +53,7 @@ siginterrupt(sig, flag) struct sigaction sa; int ret; - if ((ret = sigaction(sig, (struct sigaction *)0, &sa)) < 0) + if ((ret = _sigaction(sig, (struct sigaction *)0, &sa)) < 0) return (ret); if (flag) { sigaddset(&_sigintr, sig); @@ -59,5 +62,5 @@ siginterrupt(sig, flag) sigdelset(&_sigintr, sig); sa.sa_flags |= SA_RESTART; } - return (sigaction(sig, &sa, (struct sigaction *)0)); + return (_sigaction(sig, &sa, (struct sigaction *)0)); } diff --git a/lib/libc/gen/signal.c b/lib/libc/gen/signal.c index 9d9b4ec880..1fd0016e88 100644 --- a/lib/libc/gen/signal.c +++ b/lib/libc/gen/signal.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/signal.c,v 1.1.1.1.14.1 2001/03/05 09:52:13 obrien Exp $ - * $DragonFly: src/lib/libc/gen/signal.c,v 1.2 2003/06/17 04:26:42 dillon Exp $ + * $DragonFly: src/lib/libc/gen/signal.c,v 1.3 2005/01/31 22:29:15 dillon Exp $ * * @(#)signal.c 8.1 (Berkeley) 6/4/93 */ @@ -39,7 +39,10 @@ /* * Almost backwards compatible signal. */ +#include "namespace.h" #include +#include "un-namespace.h" +#include "libc_private.h" sigset_t _sigintr; /* shared with siginterrupt */ @@ -55,7 +58,7 @@ signal(s, a) sa.sa_flags = 0; if (!sigismember(&_sigintr, s)) sa.sa_flags |= SA_RESTART; - if (sigaction(s, &sa, &osa) < 0) + if (_sigaction(s, &sa, &osa) < 0) return (SIG_ERR); return (osa.sa_handler); } diff --git a/lib/libc/gen/sleep.c b/lib/libc/gen/sleep.c index 7a6c42c318..6d05dca8ce 100644 --- a/lib/libc/gen/sleep.c +++ b/lib/libc/gen/sleep.c @@ -32,13 +32,15 @@ * * @(#)sleep.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/gen/sleep.c,v 1.28.2.1 2000/03/18 23:13:24 jasone Exp $ - * $DragonFly: src/lib/libc/gen/sleep.c,v 1.2 2003/06/17 04:26:42 dillon Exp $ + * $DragonFly: src/lib/libc/gen/sleep.c,v 1.3 2005/01/31 22:29:15 dillon Exp $ */ +#include "namespace.h" #include #include #include #include +#include "un-namespace.h" unsigned int __sleep(seconds) @@ -64,6 +66,6 @@ __sleep(seconds) (time_remaining.tv_nsec != 0)); /* round up */ } -#ifndef _THREAD_SAFE __weak_reference(__sleep, sleep); -#endif +__weak_reference(__sleep, _sleep); + diff --git a/lib/libc/gen/syslog.c b/lib/libc/gen/syslog.c index 24561b84ce..ea08bd5ab5 100644 --- a/lib/libc/gen/syslog.c +++ b/lib/libc/gen/syslog.c @@ -32,9 +32,10 @@ * * @(#)syslog.c 8.5 (Berkeley) 4/29/95 * $FreeBSD: src/lib/libc/gen/syslog.c,v 1.21.2.3 2002/11/18 11:49:55 ru Exp $ - * $DragonFly: src/lib/libc/gen/syslog.c,v 1.5 2004/07/27 07:59:10 asmodai Exp $ + * $DragonFly: src/lib/libc/gen/syslog.c,v 1.6 2005/01/31 22:29:15 dillon Exp $ */ +#include "namespace.h" #include #include #include @@ -49,6 +50,7 @@ #include #include #include +#include "un-namespace.h" #include @@ -216,7 +218,7 @@ vsyslog(pri, fmt, ap) ++v; v->iov_base = "\n"; v->iov_len = 1; - (void)writev(STDERR_FILENO, iov, 2); + (void)_writev(STDERR_FILENO, iov, 2); } /* Get connected, output the message to the local logger. */ @@ -251,7 +253,7 @@ vsyslog(pri, fmt, ap) ++v; v->iov_base = "\r\n"; v->iov_len = 2; - (void)writev(fd, iov, 2); + (void)_writev(fd, iov, 2); (void)_close(fd); } } @@ -276,7 +278,7 @@ connectlog() struct sockaddr_un SyslogAddr; /* AF_UNIX address of local logger */ if (LogFile == -1) { - if ((LogFile = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) + if ((LogFile = _socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) return; (void)_fcntl(LogFile, F_SETFD, 1); } @@ -285,7 +287,7 @@ connectlog() SyslogAddr.sun_family = AF_UNIX; (void)strncpy(SyslogAddr.sun_path, _PATH_LOG, sizeof SyslogAddr.sun_path); - connected = connect(LogFile, (struct sockaddr *)&SyslogAddr, + connected = _connect(LogFile, (struct sockaddr *)&SyslogAddr, sizeof(SyslogAddr)) != -1; if (!connected) { @@ -295,7 +297,7 @@ connectlog() */ (void)strncpy(SyslogAddr.sun_path, _PATH_OLDLOG, sizeof SyslogAddr.sun_path); - connected = connect(LogFile, + connected = _connect(LogFile, (struct sockaddr *)&SyslogAddr, sizeof(SyslogAddr)) != -1; } diff --git a/lib/libc/gen/telldir.c b/lib/libc/gen/telldir.c index 70a82c1ef3..6e1f3c909b 100644 --- a/lib/libc/gen/telldir.c +++ b/lib/libc/gen/telldir.c @@ -31,15 +31,20 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/telldir.c,v 1.4.12.1 2001/03/05 09:39:59 obrien Exp $ - * $DragonFly: src/lib/libc/gen/telldir.c,v 1.2 2003/06/17 04:26:42 dillon Exp $ + * $DragonFly: src/lib/libc/gen/telldir.c,v 1.3 2005/01/31 22:29:15 dillon Exp $ * * @(#)telldir.c 8.1 (Berkeley) 6/4/93 */ +#include "namespace.h" #include #include +#include #include #include +#include "un-namespace.h" + +#include "libc_private.h" /* * The option SINGLEUSE may be defined to say that a telldir @@ -80,6 +85,8 @@ telldir(dirp) if ((lp = (struct ddloc *)malloc(sizeof(struct ddloc))) == NULL) return (-1); + if (__isthreaded) + _pthread_mutex_lock((pthread_mutex_t *)&dirp->dd_lock); index = dd_loccnt++; lp->loc_index = index; lp->loc_seek = dirp->dd_seek; @@ -87,6 +94,8 @@ telldir(dirp) lp->loc_dirp = dirp; lp->loc_next = dd_hash[LOCHASH(index)]; dd_hash[LOCHASH(index)] = lp; + if (__isthreaded) + _pthread_mutex_unlock((pthread_mutex_t *)&dirp->dd_lock); return (index); } @@ -119,7 +128,7 @@ _seekdir(dirp, loc) dirp->dd_seek = lp->loc_seek; dirp->dd_loc = 0; while (dirp->dd_loc < lp->loc_loc) { - dp = readdir(dirp); + dp = _readdir_unlocked(dirp); if (dp == NULL) break; } @@ -135,7 +144,7 @@ found: */ void _reclaim_telldir(dirp) - const DIR *dirp; + DIR *dirp; { struct ddloc *lp; struct ddloc **prevlp; diff --git a/lib/libc/gen/termios.c b/lib/libc/gen/termios.c index 1f428a5cd0..ba26742561 100644 --- a/lib/libc/gen/termios.c +++ b/lib/libc/gen/termios.c @@ -31,11 +31,12 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/termios.c,v 1.9.2.1 2000/03/18 23:13:25 jasone Exp $ - * $DragonFly: src/lib/libc/gen/termios.c,v 1.2 2003/06/17 04:26:42 dillon Exp $ + * $DragonFly: src/lib/libc/gen/termios.c,v 1.3 2005/01/31 22:29:15 dillon Exp $ * * @(#)termios.c 8.2 (Berkeley) 2/21/94 */ +#include "namespace.h" #include #include #include @@ -44,6 +45,7 @@ #include #include #include +#include "un-namespace.h" int tcgetattr(fd, t) @@ -51,7 +53,7 @@ tcgetattr(fd, t) struct termios *t; { - return (ioctl(fd, TIOCGETA, t)); + return (_ioctl(fd, TIOCGETA, t)); } int @@ -68,11 +70,11 @@ tcsetattr(fd, opt, t) } switch (opt & ~TCSASOFT) { case TCSANOW: - return (ioctl(fd, TIOCSETA, t)); + return (_ioctl(fd, TIOCSETA, t)); case TCSADRAIN: - return (ioctl(fd, TIOCSETAW, t)); + return (_ioctl(fd, TIOCSETAW, t)); case TCSAFLUSH: - return (ioctl(fd, TIOCSETAF, t)); + return (_ioctl(fd, TIOCSETAF, t)); default: errno = EINVAL; return (-1); @@ -91,7 +93,7 @@ tcsetpgrp(fd, pgrp) int s; s = pgrp; - return (ioctl(fd, TIOCSPGRP, &s)); + return (_ioctl(fd, TIOCSPGRP, &s)); } pid_t @@ -100,7 +102,7 @@ tcgetpgrp(fd) { int s; - if (ioctl(fd, TIOCGPGRP, &s) < 0) + if (_ioctl(fd, TIOCGPGRP, &s) < 0) return ((pid_t)-1); return ((pid_t)s); @@ -179,10 +181,10 @@ tcsendbreak(fd, len) sleepytime.tv_sec = 0; sleepytime.tv_usec = 400000; - if (ioctl(fd, TIOCSBRK, 0) == -1) + if (_ioctl(fd, TIOCSBRK, 0) == -1) return (-1); - (void)select(0, 0, 0, 0, &sleepytime); - if (ioctl(fd, TIOCCBRK, 0) == -1) + (void)_select(0, 0, 0, 0, &sleepytime); + if (_ioctl(fd, TIOCCBRK, 0) == -1) return (-1); return (0); } @@ -191,7 +193,7 @@ int __tcdrain(fd) int fd; { - return (ioctl(fd, TIOCDRAIN, 0)); + return (_ioctl(fd, TIOCDRAIN, 0)); } #ifndef _THREAD_SAFE @@ -218,7 +220,7 @@ tcflush(fd, which) errno = EINVAL; return (-1); } - return (ioctl(fd, TIOCFLUSH, &com)); + return (_ioctl(fd, TIOCFLUSH, &com)); } int @@ -230,9 +232,9 @@ tcflow(fd, action) switch (action) { case TCOOFF: - return (ioctl(fd, TIOCSTOP, 0)); + return (_ioctl(fd, TIOCSTOP, 0)); case TCOON: - return (ioctl(fd, TIOCSTART, 0)); + return (_ioctl(fd, TIOCSTART, 0)); case TCION: case TCIOFF: if (tcgetattr(fd, &term) == -1) diff --git a/lib/libc/gen/ttyname.c b/lib/libc/gen/ttyname.c index 2eaefcf79b..59aff7cfdf 100644 --- a/lib/libc/gen/ttyname.c +++ b/lib/libc/gen/ttyname.c @@ -31,11 +31,12 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/ttyname.c,v 1.10.6.2 2002/10/15 19:46:46 fjoe Exp $ - * $DragonFly: src/lib/libc/gen/ttyname.c,v 1.4 2004/06/06 15:05:55 hmp Exp $ + * $DragonFly: src/lib/libc/gen/ttyname.c,v 1.5 2005/01/31 22:29:15 dillon Exp $ * * @(#)ttyname.c 8.2 (Berkeley) 1/27/94 */ +#include "namespace.h" #include #include #include @@ -43,35 +44,38 @@ #include #include #include -#include #include #include -#ifdef _THREAD_SAFE #include -#include "pthread_private.h" -static struct pthread_mutex _ttyname_lockd = PTHREAD_MUTEX_STATIC_INITIALIZER; -static pthread_mutex_t ttyname_lock = &_ttyname_lockd; -static pthread_key_t ttyname_key; -static int ttyname_init = 0; +#include "un-namespace.h" + +#include +#include "libc_private.h" + +static char buf[sizeof(_PATH_DEV) + MAXNAMLEN] = _PATH_DEV; +static char *oldttyname __P((int, struct stat *)); +static char *ttyname_threaded(int fd); +static char *ttyname_unthreaded(int fd); + +static pthread_mutex_t ttyname_lock = PTHREAD_MUTEX_INITIALIZER; +static pthread_key_t ttyname_key; +static int ttyname_init = 0; char * ttyname(int fd) { char *ret; - if (_FD_LOCK(fd, FD_READ, NULL) == 0) { - ret = __ttyname_basic(fd); - _FD_UNLOCK(fd, FD_READ); - } else { - ret = NULL; - } - + if (__isthreaded == 0) + ret = ttyname_unthreaded(fd); + else + ret = ttyname_threaded(fd); return (ret); } char * -__ttyname_r_basic(int fd, char *buf, size_t len) +ttyname_r(int fd, char *buf, size_t len) { struct dirent *dirp; DIR *dp; @@ -112,24 +116,28 @@ __ttyname_r_basic(int fd, char *buf, size_t len) } char * -__ttyname_basic(int fd) +ttyname_threaded(int fd) { - char *buf; + char *buf; - pthread_mutex_lock(&ttyname_lock); if (ttyname_init == 0) { - if (pthread_key_create(&ttyname_key, free)) { - pthread_mutex_unlock(&ttyname_lock); + _pthread_mutex_lock(&ttyname_lock); + if (ttyname_init == 0) { + if (_pthread_key_create(&ttyname_key, free)) { + _pthread_mutex_unlock(&ttyname_lock); + return (NULL); + } + ttyname_init = 1; return (NULL); } ttyname_init = 1; + _pthread_mutex_unlock(&ttyname_lock); } - pthread_mutex_unlock(&ttyname_lock); /* Must have thread specific data field to put data */ - if ((buf = pthread_getspecific(ttyname_key)) == NULL) { + if ((buf = _pthread_getspecific(ttyname_key)) == NULL) { if ((buf = malloc(sizeof(_PATH_DEV) + MAXNAMLEN)) != NULL) { - if (pthread_setspecific(ttyname_key, buf) != 0) { + if (_pthread_setspecific(ttyname_key, buf) != 0) { free(buf); return (NULL); } @@ -137,29 +145,11 @@ __ttyname_basic(int fd) return (NULL); } } - return (__ttyname_r_basic(fd, buf, sizeof(_PATH_DEV) + MAXNAMLEN)); + return (ttyname_r(fd, buf, sizeof(_PATH_DEV) + MAXNAMLEN)); } -char * -ttyname_r(int fd, char *buf, size_t len) -{ - char *ret; - - if (_FD_LOCK(fd, FD_READ, NULL) == 0) { - ret = __ttyname_r_basic(fd, buf, len); - _FD_UNLOCK(fd, FD_READ); - } else { - ret = NULL; - } - return (ret); -} -#else -static char buf[sizeof(_PATH_DEV) + MAXNAMLEN] = _PATH_DEV; -static char *oldttyname (int, struct stat *); - -char * -ttyname(fd) - int fd; +static char * +ttyname_unthreaded(int fd) { struct stat sb; struct termios ttyb; @@ -174,7 +164,7 @@ ttyname(fd) if (tcgetattr(fd, &ttyb) < 0) return (NULL); /* Must be a character device. */ - if (fstat(fd, &sb) || !S_ISCHR(sb.st_mode)) + if (_fstat(fd, &sb) || !S_ISCHR(sb.st_mode)) return (NULL); if ( (db = dbopen(_PATH_DEVDB, O_RDONLY, 0, DB_HASH, NULL)) ) { @@ -220,4 +210,3 @@ oldttyname(fd, sb) (void)closedir(dp); return (NULL); } -#endif diff --git a/lib/libc/gen/usleep.c b/lib/libc/gen/usleep.c index 7ac67ccee4..f5a110a119 100644 --- a/lib/libc/gen/usleep.c +++ b/lib/libc/gen/usleep.c @@ -32,11 +32,13 @@ * * @(#)usleep.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/gen/usleep.c,v 1.25 2000/01/27 23:06:22 jasone Exp $ - * $DragonFly: src/lib/libc/gen/usleep.c,v 1.2 2003/06/17 04:26:42 dillon Exp $ + * $DragonFly: src/lib/libc/gen/usleep.c,v 1.3 2005/01/31 22:29:15 dillon Exp $ */ +#include "namespace.h" #include #include +#include "un-namespace.h" int usleep(useconds) diff --git a/lib/libc/gen/wait.c b/lib/libc/gen/wait.c index da4f966430..1c312afd0c 100644 --- a/lib/libc/gen/wait.c +++ b/lib/libc/gen/wait.c @@ -31,23 +31,24 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/wait.c,v 1.3.2.1 2000/03/18 23:13:25 jasone Exp $ - * $DragonFly: src/lib/libc/gen/wait.c,v 1.2 2003/06/17 04:26:42 dillon Exp $ + * $DragonFly: src/lib/libc/gen/wait.c,v 1.3 2005/01/31 22:29:15 dillon Exp $ * * @(#)wait.c 8.1 (Berkeley) 6/4/93 */ +#include "namespace.h" #include #include #include #include +#include "un-namespace.h" pid_t __wait(istat) int *istat; { - return (wait4(WAIT_ANY, istat, 0, (struct rusage *)0)); + return (_wait4(WAIT_ANY, istat, 0, (struct rusage *)0)); } -#ifndef _THREAD_SAFE __weak_reference(__wait, wait); -#endif +__weak_reference(__wait, _wait); diff --git a/lib/libc/gen/wait3.c b/lib/libc/gen/wait3.c index ed04403f17..f13edc5a32 100644 --- a/lib/libc/gen/wait3.c +++ b/lib/libc/gen/wait3.c @@ -31,15 +31,17 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/wait3.c,v 1.1.1.1.14.1 2001/03/05 09:52:13 obrien Exp $ - * $DragonFly: src/lib/libc/gen/wait3.c,v 1.2 2003/06/17 04:26:42 dillon Exp $ + * $DragonFly: src/lib/libc/gen/wait3.c,v 1.3 2005/01/31 22:29:15 dillon Exp $ * * @(#)wait3.c 8.1 (Berkeley) 6/4/93 */ +#include "namespace.h" #include #include #include #include +#include "un-namespace.h" pid_t wait3(istat, options, rup) @@ -47,5 +49,5 @@ wait3(istat, options, rup) int options; struct rusage *rup; { - return (wait4(WAIT_ANY, istat, options, rup)); + return (_wait4(WAIT_ANY, istat, options, rup)); } diff --git a/lib/libc/gen/waitpid.c b/lib/libc/gen/waitpid.c index 7af70664f8..acc56f827d 100644 --- a/lib/libc/gen/waitpid.c +++ b/lib/libc/gen/waitpid.c @@ -31,29 +31,23 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gen/waitpid.c,v 1.3.2.1 2000/03/18 23:13:26 jasone Exp $ - * $DragonFly: src/lib/libc/gen/waitpid.c,v 1.2 2003/06/17 04:26:42 dillon Exp $ + * $DragonFly: src/lib/libc/gen/waitpid.c,v 1.3 2005/01/31 22:29:15 dillon Exp $ * * @(#)waitpid.c 8.1 (Berkeley) 6/4/93 */ +#include "namespace.h" #include #include #include #include +#include "un-namespace.h" pid_t -#if __STDC__ __waitpid(pid_t pid, int *istat, int options) -#else -__waitpid(pid, istat, options) - pid_t pid; - int *istat; - int options; -#endif { - return (wait4(pid, istat, options, (struct rusage *)0)); + return (_wait4(pid, istat, options, (struct rusage *)0)); } -#ifndef _THREAD_SAFE __weak_reference(__waitpid, waitpid); -#endif +__weak_reference(__waitpid, _waitpid); diff --git a/lib/libc/gmon/gmon.c b/lib/libc/gmon/gmon.c index 589e6e6104..219b830eb6 100644 --- a/lib/libc/gmon/gmon.c +++ b/lib/libc/gmon/gmon.c @@ -31,11 +31,12 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/gmon/gmon.c,v 1.8 2000/01/27 23:06:25 jasone Exp $ - * $DragonFly: src/lib/libc/gmon/gmon.c,v 1.5 2004/10/25 19:38:01 drhodus Exp $ + * $DragonFly: src/lib/libc/gmon/gmon.c,v 1.6 2005/01/31 22:29:17 dillon Exp $ * * @(#)gmon.c 8.1 (Berkeley) 6/4/93 */ +#include "namespace.h" #include #include #include @@ -45,7 +46,9 @@ #include #include #include +#include #include +#include "un-namespace.h" #if defined(__i386__) || defined(__amd64__) extern char *minbrk asm (".minbrk"); diff --git a/lib/libc/i386/SYS.h b/lib/libc/i386/SYS.h index eabe258a6c..7d6111484b 100644 --- a/lib/libc/i386/SYS.h +++ b/lib/libc/i386/SYS.h @@ -36,7 +36,7 @@ * from: @(#)SYS.h 5.5 (Berkeley) 5/7/91 * * $FreeBSD: src/lib/libc/i386/SYS.h,v 1.17.2.2 2002/10/15 19:46:46 fjoe Exp $ - * $DragonFly: src/lib/libc/i386/SYS.h,v 1.3 2004/03/20 16:27:40 drhodus Exp $ + * $DragonFly: src/lib/libc/i386/SYS.h,v 1.4 2005/01/31 22:29:20 dillon Exp $ */ #include @@ -62,30 +62,27 @@ * Design note: * * The macros PSYSCALL() and PRSYSCALL() are intended for use where a - * syscall needs to be renamed in the threaded library. When building - * a normal library, they default to the traditional SYSCALL() and - * RSYSCALL(). This avoids the need to #ifdef _THREAD_SAFE everywhere - * that the renamed function needs to be called. + * syscall needs to be renamed in the threaded library. */ -#ifdef _THREAD_SAFE /* * For the thread_safe versions, we prepend __sys_ to the function * name so that the 'C' wrapper can go around the real name. */ #define PSYSCALL(x) 2: PIC_PROLOGUE; jmp PIC_PLT(HIDENAME(cerror)); \ ENTRY(__CONCAT(__sys_,x)); \ + .weak CNAME(x); \ + .set CNAME(x),CNAME(__CONCAT(__sys_,x)); \ + .weak CNAME(__CONCAT(_,x)); \ + .set CNAME(__CONCAT(_,x)),CNAME(__CONCAT(__sys_,x)); \ lea __CONCAT(SYS_,x),%eax; KERNCALL; jb 2b + #define PRSYSCALL(x) PSYSCALL(x); ret + #define PPSEUDO(x,y) ENTRY(__CONCAT(__sys_,x)); \ + .weak CNAME(x); \ + .set CNAME(x),CNAME(__CONCAT(__sys_,x)); \ + .weak CNAME(__CONCAT(_,x)); \ + .set CNAME(__CONCAT(_,x)),CNAME(__CONCAT(__sys_,x)); \ lea __CONCAT(SYS_,y), %eax; KERNCALL; ret -#else -/* - * The non-threaded library defaults to traditional syscalls where - * the function name matches the syscall name. - */ -#define PSYSCALL(x) SYSCALL(x) -#define PRSYSCALL(x) RSYSCALL(x) -#define PPSEUDO(x,y) PSEUDO(x,y) -#endif #define KERNCALL int $0x80 diff --git a/lib/libc/i386/gen/_setjmp.S b/lib/libc/i386/gen/_setjmp.S index 4156a46f8b..2fa70c396c 100644 --- a/lib/libc/i386/gen/_setjmp.S +++ b/lib/libc/i386/gen/_setjmp.S @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/i386/gen/_setjmp.S,v 1.12 2000/01/20 21:58:26 jasone Exp $ - * $DragonFly: src/lib/libc/i386/gen/_setjmp.S,v 1.3 2003/12/06 03:11:35 drhodus Exp $ + * $DragonFly: src/lib/libc/i386/gen/_setjmp.S,v 1.4 2005/01/31 22:29:24 dillon Exp $ */ /* @@ -62,12 +62,9 @@ ENTRY(_setjmp) xorl %eax,%eax ret -#ifdef _THREAD_SAFE + .weak CNAME(_longjmp) + .set CNAME(_longjmp),CNAME(___longjmp) ENTRY(___longjmp) -#else -ALTENTRY(___longjmp) -ENTRY(_longjmp) -#endif movl 4(%esp),%edx movl 8(%esp),%eax movl 0(%edx),%ecx diff --git a/lib/libc/i386/gen/setjmp.S b/lib/libc/i386/gen/setjmp.S index 4db4c04304..e3dcc489b0 100644 --- a/lib/libc/i386/gen/setjmp.S +++ b/lib/libc/i386/gen/setjmp.S @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/i386/gen/setjmp.S,v 1.17.2.2 2001/07/06 12:41:44 deischen Exp $ - * $DragonFly: src/lib/libc/i386/gen/setjmp.S,v 1.3 2003/12/06 03:11:35 drhodus Exp $ + * $DragonFly: src/lib/libc/i386/gen/setjmp.S,v 1.4 2005/01/31 22:29:24 dillon Exp $ */ /* @@ -57,7 +57,7 @@ ENTRY(setjmp) pushl %eax /* (sigset_t*)oset */ pushl $0 /* (sigset_t*)set */ pushl $1 /* SIG_BLOCK */ - call PIC_PLT(CNAME(sigprocmask)) + call PIC_PLT(CNAME(_sigprocmask)) addl $12,%esp PIC_EPILOGUE movl 4(%esp),%ecx @@ -72,10 +72,8 @@ ENTRY(setjmp) xorl %eax,%eax ret -#ifndef _THREAD_SAFE -.weak CNAME(longjmp); -.set CNAME(longjmp),CNAME(__longjmp); -#endif + .weak CNAME(longjmp); + .set CNAME(longjmp),CNAME(__longjmp); ENTRY(__longjmp) movl 4(%esp),%edx PIC_PROLOGUE @@ -83,7 +81,7 @@ ENTRY(__longjmp) leal 28(%edx), %eax pushl %eax /* (sigset_t*)set */ pushl $3 /* SIG_SETMASK */ - call PIC_PLT(CNAME(sigprocmask)) + call PIC_PLT(CNAME(_sigprocmask)) addl $12,%esp PIC_EPILOGUE movl 4(%esp),%edx diff --git a/lib/libc/i386/gen/sigsetjmp.S b/lib/libc/i386/gen/sigsetjmp.S index 7aee9c4ede..919f4242dc 100644 --- a/lib/libc/i386/gen/sigsetjmp.S +++ b/lib/libc/i386/gen/sigsetjmp.S @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/i386/gen/sigsetjmp.S,v 1.19.2.2 2001/07/06 12:41:44 deischen Exp $ - * $DragonFly: src/lib/libc/i386/gen/sigsetjmp.S,v 1.3 2003/12/06 03:11:35 drhodus Exp $ + * $DragonFly: src/lib/libc/i386/gen/sigsetjmp.S,v 1.4 2005/01/31 22:29:24 dillon Exp $ */ #include "DEFS.h" @@ -48,9 +48,6 @@ * the renamed functions (introduced in gcc-2.5.3; previous versions * only supported *jmp with 0 or 1 leading underscores). * - * Use sigprocmask() instead of sigblock() and sigsetmask(), and - * check for and handle errors. - * * Restore _all_ the registers and the signal mask atomically. Can * use sigreturn() if sigreturn() works. */ @@ -66,7 +63,7 @@ ENTRY(sigsetjmp) pushl %eax /* (sigset_t*)oset */ pushl $0 /* (sigset_t*)set */ pushl $1 /* SIG_BLOCK */ - call PIC_PLT(CNAME(sigprocmask)) + call PIC_PLT(CNAME(_sigprocmask)) addl $12,%esp PIC_EPILOGUE movl 4(%esp),%ecx @@ -81,10 +78,8 @@ ENTRY(sigsetjmp) xorl %eax,%eax ret -#ifndef _THREAD_SAFE -.weak CNAME(siglongjmp); -.set CNAME(siglongjmp),CNAME(__siglongjmp); -#endif + .weak CNAME(siglongjmp); + .set CNAME(siglongjmp),CNAME(__siglongjmp); ENTRY(__siglongjmp); movl 4(%esp),%edx cmpl $0,44(%edx) @@ -94,7 +89,7 @@ ENTRY(__siglongjmp); leal 28(%edx), %eax pushl %eax /* (sigset_t*)set */ pushl $3 /* SIG_SETMASK */ - call PIC_PLT(CNAME(sigprocmask)) + call PIC_PLT(CNAME(_sigprocmask)) addl $12,%esp PIC_EPILOGUE movl 4(%esp),%edx diff --git a/lib/libc/i386/sys/setlogin.S b/lib/libc/i386/sys/setlogin.S index c240c2ad9c..3c520f9e65 100644 --- a/lib/libc/i386/sys/setlogin.S +++ b/lib/libc/i386/sys/setlogin.S @@ -34,12 +34,12 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/i386/sys/setlogin.S,v 1.6 1999/08/27 23:59:44 peter Exp $ - * $DragonFly: src/lib/libc/i386/sys/setlogin.S,v 1.3 2003/12/06 03:11:36 drhodus Exp $ + * $DragonFly: src/lib/libc/i386/sys/setlogin.S,v 1.4 2005/01/31 22:29:27 dillon Exp $ */ #include "SYS.h" -.globl CNAME(_logname_valid) /* in getlogin() */ +.globl CNAME(_logname_valid) /* in _getlogin() */ SYSCALL(setlogin) #ifdef PIC diff --git a/lib/libc/include/libc_private.h b/lib/libc/include/libc_private.h index 1cad469a72..a6338520da 100644 --- a/lib/libc/include/libc_private.h +++ b/lib/libc/include/libc_private.h @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/include/libc_private.h,v 1.3 1999/08/27 23:59:47 peter Exp $ - * $DragonFly: src/lib/libc/include/libc_private.h,v 1.2 2003/06/17 04:26:43 dillon Exp $ + * $DragonFly: src/lib/libc/include/libc_private.h,v 1.3 2005/01/31 22:29:29 dillon Exp $ * * Private definitions for libc, libc_r and libpthread. * @@ -54,7 +54,7 @@ extern int __isthreaded; #ifdef _FLOCK_DEBUG #define _FLOCKFILE(x) _flockfile_debug(x, __FILE__, __LINE__) #else -#define _FLOCKFILE(x) flockfile(x) +#define _FLOCKFILE(x) _flockfile(x) #endif /* @@ -62,6 +62,14 @@ extern int __isthreaded; * process is threaded to avoid locking when not required. */ #define FLOCKFILE(fp) if (__isthreaded) _FLOCKFILE(fp) -#define FUNLOCKFILE(fp) if (__isthreaded) funlockfile(fp) +#define FUNLOCKFILE(fp) if (__isthreaded) _funlockfile(fp) + +/* + * Internal _*() functions (XXX add all of them) + */ + +#ifdef _STDIO_H_ +int _fseeko(FILE *, __off_t, int); +#endif #endif /* _LIBC_PRIVATE_H_ */ diff --git a/lib/libc/include/namespace.h b/lib/libc/include/namespace.h new file mode 100644 index 0000000000..f22ef7db06 --- /dev/null +++ b/lib/libc/include/namespace.h @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2001 Daniel Eischen . + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: /repoman/r/ncvs/src/lib/libc/include/namespace.h,v 1.1 2001/01/24 13:00:08 deischen Exp $ + * $DragonFly: src/lib/libc/include/namespace.h,v 1.1 2005/01/31 22:29:29 dillon Exp $ + * + */ + +#ifndef _NAMESPACE_H_ +#define _NAMESPACE_H_ + +/* + * Prototypes for syscalls/functions that need to be overridden + * in libc_r/libpthread. + */ +#define accept _accept +#define bind _bind +#define close _close +#define connect _connect +#define dup _dup +#define dup2 _dup2 +#define execve _execve +#define fcntl _fcntl +/*#define flock _flock */ +#define flockfile _flockfile +#define fstat _fstat +#define fstatfs _fstatfs +#define fsync _fsync +#define funlockfile _funlockfile +#define getdirentries _getdirentries +#define getlogin _getlogin +#define getpeername _getpeername +#define getsockname _getsockname +#define getsockopt _getsockopt +#define ioctl _ioctl +/* #define kevent _kevent */ +#define listen _listen +#define nanosleep _nanosleep +#define open _open +#define pthread_getspecific _pthread_getspecific +#define pthread_key_create _pthread_key_create +#define pthread_key_delete _pthread_key_delete +#define pthread_mutex_destroy _pthread_mutex_destroy +#define pthread_mutex_init _pthread_mutex_init +#define pthread_mutex_lock _pthread_mutex_lock +#define pthread_mutex_trylock _pthread_mutex_trylock +#define pthread_mutex_unlock _pthread_mutex_unlock +#define pthread_mutexattr_init _pthread_mutexattr_init +#define pthread_mutexattr_destroy _pthread_mutexattr_destroy +#define pthread_mutexattr_settype _pthread_mutexattr_settype +#define pthread_once _pthread_once +#define pthread_setspecific _pthread_setspecific +#define read _read +#define readv _readv +#define recvfrom _recvfrom +#define recvmsg _recvmsg +#define select _select +#define sendmsg _sendmsg +#define sendto _sendto +#define setsockopt _setsockopt +/*#define sigaction _sigaction*/ +#define sigprocmask _sigprocmask +#define sigsuspend _sigsuspend +#define socket _socket +#define socketpair _socketpair +#define wait4 _wait4 +#define write _write +#define writev _writev + + +/* + * Other hidden syscalls/functions that libc_r needs to override + * but are not used internally by libc. + * + * XXX - When modifying libc to use one of the following, remove + * the prototype from below and place it in the list above. + */ +#if 0 +#define creat _creat +#define fchflags _fchflags +#define fchmod _fchmod +#define fpathconf _fpathconf +#define ftrylockfile _ftrylockfile +#define msync _msync +#define nfssvc _nfssvc +#define pause _pause +#define poll _poll +#define pthread_rwlock_destroy _pthread_rwlock_destroy +#define pthread_rwlock_init _pthread_rwlock_init +#define pthread_rwlock_rdlock _pthread_rwlock_rdlock +#define pthread_rwlock_tryrdlock _pthread_rwlock_tryrdlock +#define pthread_rwlock_trywrlock _pthread_rwlock_trywrlock +#define pthread_rwlock_unlock _pthread_rwlock_unlock +#define pthread_rwlock_wrlock _pthread_rwlock_wrlock +#define pthread_rwlockattr_init _pthread_rwlockattr_init +#define pthread_rwlockattr_destroy _pthread_rwlockattr_destroy +#define pthread_self _pthread_self +#define sched_yield _sched_yield +#define sendfile _sendfile +#define shutdown _shutdown +#define sigaltstack _sigaltstack +#define signanosleep _signanosleep +#define sigpending _sigpending +#define sigreturn _sigreturn +#define sigsetmask _sigsetmask +#define sleep _sleep +#define system _system +#define tcdrain _tcdrain +#define wait _wait +#define waitpid _waitpid +#endif + +#endif /* _NAMESPACE_H_ */ + diff --git a/lib/libc/include/spinlock.h b/lib/libc/include/spinlock.h index 047f41140d..e6961e4d70 100644 --- a/lib/libc/include/spinlock.h +++ b/lib/libc/include/spinlock.h @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/include/spinlock.h,v 1.4 1999/08/27 23:59:48 peter Exp $ - * $DragonFly: src/lib/libc/include/spinlock.h,v 1.3 2003/11/12 20:21:24 eirikn Exp $ + * $DragonFly: src/lib/libc/include/spinlock.h,v 1.4 2005/01/31 22:29:29 dillon Exp $ * * Lock definitions used in both libc and libpthread. * @@ -53,7 +53,7 @@ typedef struct { #define _SPINLOCK_INITIALIZER { 0, 0, 0, 0 } -#define _SPINUNLOCK(_lck) (_lck)->access_lock = 0 +#define _SPINUNLOCK(_lck) _spinunlock(_lck) #ifdef _LOCK_DEBUG #define _SPINLOCK(_lck) _spinlock_debug(_lck, __FILE__, __LINE__) #else @@ -67,6 +67,7 @@ __BEGIN_DECLS long _atomic_lock (volatile long *); void _spinlock (spinlock_t *); void _spinlock_debug (spinlock_t *, char *, int); +void _spinunlock (spinlock_t *); __END_DECLS #endif /* _SPINLOCK_H_ */ diff --git a/lib/libc/include/un-namespace.h b/lib/libc/include/un-namespace.h new file mode 100644 index 0000000000..2be4f6aeb0 --- /dev/null +++ b/lib/libc/include/un-namespace.h @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2001 Daniel Eischen . + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: /repoman/r/ncvs/src/lib/libc/include/un-namespace.h,v 1.1 2001/01/24 13:00:09 deischen Exp $ + * $DragonFly: src/lib/libc/include/un-namespace.h,v 1.1 2005/01/31 22:29:29 dillon Exp $ + */ + +#ifndef _UN_NAMESPACE_H_ +#define _UN_NAMESPACE_H_ + +#undef accept +#undef bind +#undef close +#undef connect +#undef dup +#undef dup2 +#undef execve +#undef fcntl +#undef flock +#undef flockfile +#undef fstat +#undef fstatfs +#undef fsync +#undef funlockfile +#undef getdirentries +#undef getlogin +#undef getpeername +#undef getsockname +#undef getsockopt +#undef ioctl +#undef kevent +#undef listen +#undef nanosleep +#undef open +#undef pthread_getspecific +#undef pthread_key_create +#undef pthread_key_delete +#undef pthread_mutex_destroy +#undef pthread_mutex_init +#undef pthread_mutex_lock +#undef pthread_mutex_trylock +#undef pthread_mutex_unlock +#undef pthread_mutexattr_init +#undef pthread_mutexattr_destroy +#undef pthread_mutexattr_settype +#undef pthread_once +#undef pthread_setspecific +#undef read +#undef readv +#undef recvfrom +#undef recvmsg +#undef select +#undef sendmsg +#undef sendto +#undef setsockopt +#undef sigaction +#undef sigprocmask +#undef sigsuspend +#undef socket +#undef socketpair +#undef wait4 +#undef write +#undef writev + +#if 0 +#undef creat +#undef fchflags +#undef fchmod +#undef fpathconf +#undef ftrylockfile +#undef msync +#undef nfssvc +#undef pause +#undef poll +#undef pthread_rwlock_destroy +#undef pthread_rwlock_init +#undef pthread_rwlock_rdlock +#undef pthread_rwlock_tryrdlock +#undef pthread_rwlock_trywrlock +#undef pthread_rwlock_unlock +#undef pthread_rwlock_wrlock +#undef pthread_rwlockattr_init +#undef pthread_rwlockattr_destroy +#undef pthread_self +#undef sched_yield +#undef sendfile +#undef shutdown +#undef sigaltstack +#undef signanosleep +#undef sigpending +#undef sigreturn +#undef sigsetmask +#undef sleep +#undef system +#undef tcdrain +#undef wait +#undef waitpid +#endif /* 0 */ + +#ifdef _SIGNAL_H_ +int _sigaction(int, const struct sigaction *, struct sigaction *); +#endif + +#ifdef _SYS_EVENT_H_ +int _kevent(int, const struct kevent *, int, struct kevent *, + int, const struct timespec *); +#endif + +#ifdef _SYS_FCNTL_H_ +int _flock(int, int); +#endif + +#endif /* _UN_NAMESPACE_H_ */ + diff --git a/lib/libc/locale/collate.c b/lib/libc/locale/collate.c index c870d6faae..601e629fd7 100644 --- a/lib/libc/locale/collate.c +++ b/lib/libc/locale/collate.c @@ -25,9 +25,10 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/locale/collate.c,v 1.21.2.4 2002/10/11 10:36:47 ache Exp $ - * $DragonFly: src/lib/libc/locale/collate.c,v 1.2 2003/06/17 04:26:43 dillon Exp $ + * $DragonFly: src/lib/libc/locale/collate.c,v 1.3 2005/01/31 22:29:31 dillon Exp $ */ +#include "namespace.h" #include #include #include @@ -36,6 +37,7 @@ #include #include #include +#include "un-namespace.h" #include "collate.h" #include "setlocale.h" @@ -145,7 +147,7 @@ __collate_load_tables(const char *encoding) #define FREAD(a, b, c, d) \ { \ - if (fread(a, b, c, d) != c) { \ + if ( fread(a, b, c, d) != c) { \ saverr = errno; \ free(TMP_substitute_table); \ free(TMP_char_pri_table); \ diff --git a/lib/libc/locale/rune.c b/lib/libc/locale/rune.c index 904c1a46bb..951fd4681b 100644 --- a/lib/libc/locale/rune.c +++ b/lib/libc/locale/rune.c @@ -35,9 +35,10 @@ * * @(#)rune.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/locale/rune.c,v 1.5.8.2 2002/08/12 11:17:38 ache Exp $ - * $DragonFly: src/lib/libc/locale/rune.c,v 1.2 2003/06/17 04:26:44 dillon Exp $ + * $DragonFly: src/lib/libc/locale/rune.c,v 1.3 2005/01/31 22:29:31 dillon Exp $ */ +#include "namespace.h" #include #include #include @@ -46,6 +47,7 @@ #include #include #include +#include "un-namespace.h" _RuneLocale * _Read_RuneMagi(fp) diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c index dae9fc1134..f1cfafc444 100644 --- a/lib/libc/net/getaddrinfo.c +++ b/lib/libc/net/getaddrinfo.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/lib/libc/net/getaddrinfo.c,v 1.9.2.14 2002/11/08 17:49:31 ume Exp $ */ -/* $DragonFly: src/lib/libc/net/getaddrinfo.c,v 1.3 2003/11/12 20:21:24 eirikn Exp $ */ +/* $DragonFly: src/lib/libc/net/getaddrinfo.c,v 1.4 2005/01/31 22:29:33 dillon Exp $ */ /* $KAME: getaddrinfo.c,v 1.15 2000/07/09 04:37:24 itojun Exp $ */ /* @@ -64,6 +64,7 @@ * - FreeBSD allowed classful IPv4 numeric (127.1), the code does not. */ +#include "namespace.h" #include #include #include @@ -80,6 +81,7 @@ #include #include #include +#include "un-namespace.h" #include "res_config.h" @@ -739,7 +741,7 @@ explore_null(pai, servname, res) * filter out AFs that are not supported by the kernel * XXX errno? */ - s = socket(pai->ai_family, SOCK_DGRAM, 0); + s = _socket(pai->ai_family, SOCK_DGRAM, 0); if (s < 0) { if (errno != EMFILE) return 0; @@ -1134,11 +1136,11 @@ addrconfig(pai) */ af = pai->ai_family; if (af == AF_UNSPEC) { - if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) + if ((s = _socket(AF_INET6, SOCK_DGRAM, 0)) < 0) af = AF_INET; else { _close(s); - if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) + if ((s = _socket(AF_INET, SOCK_DGRAM, 0)) < 0) af = AF_INET6; else _close(s); @@ -1146,7 +1148,7 @@ addrconfig(pai) } if (af != AF_UNSPEC) { - if ((s = socket(af, SOCK_DGRAM, 0)) < 0) + if ((s = _socket(af, SOCK_DGRAM, 0)) < 0) return 0; _close(s); } diff --git a/lib/libc/net/gethostbyht.c b/lib/libc/net/gethostbyht.c index 8a0205fd06..3d8d113425 100644 --- a/lib/libc/net/gethostbyht.c +++ b/lib/libc/net/gethostbyht.c @@ -52,7 +52,7 @@ * * @(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/net/gethostbyht.c,v 1.12 1999/08/28 00:00:05 peter Exp $ - * $DragonFly: src/lib/libc/net/gethostbyht.c,v 1.3 2004/10/25 19:38:01 drhodus Exp $ + * $DragonFly: src/lib/libc/net/gethostbyht.c,v 1.4 2005/01/31 22:29:33 dillon Exp $ */ #include @@ -62,7 +62,6 @@ #include #include #include -#include #include #include /* XXX */ #include /* XXX */ diff --git a/lib/libc/net/gethostnamadr.c b/lib/libc/net/gethostnamadr.c index 3b2bd31a3f..890b3400ad 100644 --- a/lib/libc/net/gethostnamadr.c +++ b/lib/libc/net/gethostnamadr.c @@ -23,7 +23,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/net/gethostnamadr.c,v 1.15.2.2 2001/03/05 10:40:42 obrien Exp $ - * $DragonFly: src/lib/libc/net/gethostnamadr.c,v 1.3 2004/10/25 19:38:01 drhodus Exp $ + * $DragonFly: src/lib/libc/net/gethostnamadr.c,v 1.4 2005/01/31 22:29:33 dillon Exp $ */ #include @@ -188,7 +188,6 @@ gethostbyaddr(const char *addr, int len, int type) return hp; } -#ifdef _THREAD_SAFE struct hostent_data; /* @@ -207,7 +206,6 @@ int gethostbyaddr_r(const char *addr, int len, int type, } return(ret); } -#endif void sethostent(stayopen) diff --git a/lib/libc/net/getifaddrs.c b/lib/libc/net/getifaddrs.c index 8b117242b1..3a96bbf1a9 100644 --- a/lib/libc/net/getifaddrs.c +++ b/lib/libc/net/getifaddrs.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/lib/libc/net/getifaddrs.c,v 1.1.2.4 2002/08/01 19:31:06 ume Exp $ */ -/* $DragonFly: src/lib/libc/net/getifaddrs.c,v 1.4 2004/02/03 07:34:09 dillon Exp $ */ +/* $DragonFly: src/lib/libc/net/getifaddrs.c,v 1.5 2005/01/31 22:29:33 dillon Exp $ */ /* $KAME: getifaddrs.c,v 1.9 2001/08/20 02:31:20 itojun Exp $ */ /* @@ -30,12 +30,13 @@ * NOTE: SIOCGIFCONF case is not LP64 friendly. it also does not perform * try-and-error for region size. */ -#include +#include "namespace.h" #include #include #include #include #ifdef NET_RT_IFLIST +#include #include #include #include @@ -45,6 +46,7 @@ #include #include #include +#include "un-namespace.h" #if !defined(AF_LINK) #define SA_LEN(sa) sizeof(struct sockaddr) @@ -217,10 +219,10 @@ getifaddrs(struct ifaddrs **pif) ifc.ifc_buf = buf; ifc.ifc_len = sizeof(buf); - if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) + if ((sock = _socket(AF_INET, SOCK_STREAM, 0)) < 0) return (-1); - i = ioctl(sock, SIOCGIFCONF, (char *)&ifc); - close(sock); + i = _ioctl(sock, SIOCGIFCONF, (char *)&ifc); + _close(sock); if (i < 0) return (-1); diff --git a/lib/libc/net/herror.c b/lib/libc/net/herror.c index 278a84eae7..070229ac25 100644 --- a/lib/libc/net/herror.c +++ b/lib/libc/net/herror.c @@ -32,7 +32,7 @@ * * @(#)herror.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/net/herror.c,v 1.8 1999/08/28 00:00:09 peter Exp $ - * $DragonFly: src/lib/libc/net/herror.c,v 1.3 2004/10/25 19:38:01 drhodus Exp $ + * $DragonFly: src/lib/libc/net/herror.c,v 1.4 2005/01/31 22:29:33 dillon Exp $ */ /* @@ -52,11 +52,13 @@ * SOFTWARE. */ +#include "namespace.h" #include #include #include #include #include +#include "un-namespace.h" const char *h_errlist[] = { "Resolver Error 0 (no error)", @@ -93,7 +95,7 @@ herror(s) v++; v->iov_base = "\n"; v->iov_len = 1; - writev(STDERR_FILENO, iov, (v - iov) + 1); + _writev(STDERR_FILENO, iov, (v - iov) + 1); } const char * diff --git a/lib/libc/net/name6.c b/lib/libc/net/name6.c index 38c85e698e..2c71b93339 100644 --- a/lib/libc/net/name6.c +++ b/lib/libc/net/name6.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/lib/libc/net/name6.c,v 1.6.2.9 2002/11/02 18:54:57 ume Exp $ */ -/* $DragonFly: src/lib/libc/net/name6.c,v 1.4 2004/10/25 19:38:01 drhodus Exp $ */ +/* $DragonFly: src/lib/libc/net/name6.c,v 1.5 2005/01/31 22:29:33 dillon Exp $ */ /* $KAME: name6.c,v 1.25 2000/06/26 16:44:40 itojun Exp $ */ /* @@ -95,6 +95,7 @@ * rewrite resolvers to be thread safe */ +#include "namespace.h" #include #include #include @@ -111,6 +112,7 @@ #include #include #include +#include "un-namespace.h" #ifndef _PATH_HOSTS #define _PATH_HOSTS "/etc/hosts" @@ -340,11 +342,11 @@ _ghbyname(const char *name, int af, int flags, int *errp) * because addresses will be dynamically assigned or deleted. */ if (af == AF_UNSPEC) { - if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) + if ((s = _socket(AF_INET6, SOCK_DGRAM, 0)) < 0) af = AF_INET; else { _close(s); - if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) + if ((s = _socket(AF_INET, SOCK_DGRAM, 0)) < 0) af = AF_INET6; else _close(s); @@ -352,7 +354,7 @@ _ghbyname(const char *name, int af, int flags, int *errp) } if (af != AF_UNSPEC) { - if ((s = socket(af, SOCK_DGRAM, 0)) < 0) + if ((s = _socket(af, SOCK_DGRAM, 0)) < 0) return NULL; _close(s); } @@ -1783,11 +1785,11 @@ _icmp_fqdn_query(const struct in6_addr *addr, int ifindex) msg.msg_controllen = (char *)cmsg - cbuf; } - if ((s = socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0) + if ((s = _socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0) return NULL; - (void)setsockopt(s, IPPROTO_ICMPV6, ICMP6_FILTER, + (void)_setsockopt(s, IPPROTO_ICMPV6, ICMP6_FILTER, (char *)&filter, sizeof(filter)); - cc = sendmsg(s, &msg, 0); + cc = _sendmsg(s, &msg, 0); if (cc < 0) { _close(s); return NULL; @@ -1800,7 +1802,7 @@ _icmp_fqdn_query(const struct in6_addr *addr, int ifindex) return NULL; } len = sizeof(sin6); - cc = recvfrom(s, buf, sizeof(buf), 0, + cc = _recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr *)&sin6, &len); if (cc <= 0) { _close(s); diff --git a/lib/libc/net/rcmd.c b/lib/libc/net/rcmd.c index cfd9337574..7ffab62d63 100644 --- a/lib/libc/net/rcmd.c +++ b/lib/libc/net/rcmd.c @@ -31,11 +31,12 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/net/rcmd.c,v 1.23.2.7 2002/08/26 16:17:49 jdp Exp $ - * $DragonFly: src/lib/libc/net/rcmd.c,v 1.4 2004/10/25 19:38:01 drhodus Exp $ + * $DragonFly: src/lib/libc/net/rcmd.c,v 1.5 2005/01/31 22:29:33 dillon Exp $ * * @(#)rcmd.c 8.3 (Berkeley) 3/26/94 */ +#include "namespace.h" #include #include #include @@ -59,6 +60,7 @@ #include #endif #include +#include "un-namespace.h" /* wrapper for KAME-special getnameinfo() */ #ifndef NI_WITHSCOPEID @@ -100,7 +102,7 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af) struct addrinfo hints, *res, *ai; struct sockaddr_storage from; fd_set reads; - long oldmask; + sigset_t oldmask, newmask; pid_t pid; int s, aport, lport, timo, error; char c, *p; @@ -154,7 +156,9 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af) nres++; ai = res; refused = 0; - oldmask = sigblock(sigmask(SIGURG)); + sigemptyset(&newmask); + sigaddset(&newmask, SIGURG); + _sigprocmask(SIG_BLOCK, (const sigset_t *)&newmask, &oldmask); for (timo = 1, lport = IPPORT_RESERVED - 1;;) { s = rresvport_af(&lport, ai->ai_family); if (s < 0) { @@ -169,11 +173,12 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af) (void)fprintf(stderr, "rcmd: socket: %s\n", strerror(errno)); freeaddrinfo(res); - sigsetmask(oldmask); + _sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, + NULL); return (-1); } _fcntl(s, F_SETOWN, pid); - if (connect(s, ai->ai_addr, ai->ai_addrlen) >= 0) + if (_connect(s, ai->ai_addr, ai->ai_addrlen) >= 0) break; (void)_close(s); if (errno == EADDRINUSE) { @@ -186,7 +191,8 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af) (void)fprintf(stderr, "%s: %s\n", *ahost, strerror(errno)); freeaddrinfo(res); - sigsetmask(oldmask); + _sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, + NULL); return (-1); } if (nres > 1) { @@ -232,7 +238,7 @@ rcmd_af(ahost, rport, locuser, remuser, cmd, fd2p, af) if (s2 < 0) goto bad; - listen(s2, 1); + _listen(s2, 1); (void)snprintf(num, sizeof(num), "%d", lport); if (_write(s, num, strlen(num)+1) != strlen(num)+1) { (void)fprintf(stderr, @@ -252,7 +258,7 @@ again: FD_SET(s, &reads); FD_SET(s2, &reads); errno = 0; - if (select(nfds, &reads, 0, 0, 0) < 1 || !FD_ISSET(s2, &reads)){ + if (_select(nfds, &reads, 0, 0, 0) < 1 || !FD_ISSET(s2, &reads)){ if (errno != 0) (void)fprintf(stderr, "rcmd: select (setting up stderr): %s\n", @@ -263,7 +269,7 @@ again: (void)_close(s2); goto bad; } - s3 = accept(s2, (struct sockaddr *)&from, &len); + s3 = _accept(s2, (struct sockaddr *)&from, &len); switch (from.ss_family) { case AF_INET: aport = ntohs(((struct sockaddr_in *)&from)->sin_port); @@ -315,7 +321,7 @@ again: } goto bad2; } - sigsetmask(oldmask); + _sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, NULL); freeaddrinfo(res); return (s); bad2: @@ -323,7 +329,7 @@ bad2: (void)_close(*fd2p); bad: (void)_close(s); - sigsetmask(oldmask); + _sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, NULL); freeaddrinfo(res); return (-1); } @@ -363,12 +369,12 @@ rresvport_af(alport, family) return -1; } - s = socket(ss.ss_family, SOCK_STREAM, 0); + s = _socket(ss.ss_family, SOCK_STREAM, 0); if (s < 0) return (-1); #if 0 /* compat_exact_traditional_rresvport_semantics */ sin.sin_port = htons((u_short)*alport); - if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0) + if (_bind(s, (struct sockaddr *)&sin, sizeof(sin)) >= 0) return (s); if (errno != EADDRINUSE) { (void)_close(s); @@ -504,7 +510,7 @@ again: cp = ".rhosts lstat failed"; else if (!S_ISREG(sbuf.st_mode)) cp = ".rhosts not regular file"; - else if (fstat(fileno(hostf), &sbuf) < 0) + else if (_fstat(fileno(hostf), &sbuf) < 0) cp = ".rhosts fstat failed"; else if (sbuf.st_uid && sbuf.st_uid != pwd->pw_uid) cp = "bad .rhosts owner"; diff --git a/lib/libc/net/recv.c b/lib/libc/net/recv.c index 0cc131c953..2d137a4b5a 100644 --- a/lib/libc/net/recv.c +++ b/lib/libc/net/recv.c @@ -31,15 +31,17 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/net/recv.c,v 1.1.1.1.14.1 2001/03/05 10:47:11 obrien Exp $ - * $DragonFly: src/lib/libc/net/recv.c,v 1.2 2003/06/17 04:26:44 dillon Exp $ + * $DragonFly: src/lib/libc/net/recv.c,v 1.3 2005/01/31 22:29:33 dillon Exp $ * * @(#)recv.c 8.2 (Berkeley) 2/21/94 */ +#include "namespace.h" #include #include #include +#include "un-namespace.h" ssize_t recv(s, buf, len, flags) @@ -47,5 +49,5 @@ recv(s, buf, len, flags) size_t len; void *buf; { - return (recvfrom(s, buf, len, flags, NULL, 0)); + return (_recvfrom(s, buf, len, flags, NULL, 0)); } diff --git a/lib/libc/net/res_send.c b/lib/libc/net/res_send.c index 79a79970f2..b68a622cf3 100644 --- a/lib/libc/net/res_send.c +++ b/lib/libc/net/res_send.c @@ -33,7 +33,7 @@ * @(#)res_send.c 8.1 (Berkeley) 6/4/93 * $From: Id: res_send.c,v 8.20 1998/04/06 23:27:51 halley Exp $ * $FreeBSD: src/lib/libc/net/res_send.c,v 1.31.2.9 2002/04/11 17:30:24 ume Exp $ - * $DragonFly: src/lib/libc/net/res_send.c,v 1.3 2003/11/12 20:21:24 eirikn Exp $ + * $DragonFly: src/lib/libc/net/res_send.c,v 1.4 2005/01/31 22:29:33 dillon Exp $ */ /* @@ -77,6 +77,7 @@ * Send query to name server and wait for reply. */ +#include "namespace.h" #include #include #include @@ -95,6 +96,7 @@ #include #include #include +#include "un-namespace.h" #include "res_config.h" @@ -459,7 +461,7 @@ res_send(buf, buflen, ans, anssiz) res_close(); af = nsap->sa_family; - s = socket(af, SOCK_STREAM, 0); + s = _socket(af, SOCK_STREAM, 0); if (s < 0) { terrno = errno; Perror(stderr, "socket(vc)", errno); @@ -468,7 +470,7 @@ res_send(buf, buflen, ans, anssiz) goto next_ns; } errno = 0; - if (connect(s, nsap, salen) < 0) { + if (_connect(s, nsap, salen) < 0) { terrno = errno; Aerror(stderr, "connect/vc", errno, nsap); @@ -486,7 +488,7 @@ res_send(buf, buflen, ans, anssiz) iov[0].iov_len = INT16SZ; iov[1].iov_base = (caddr_t)buf; iov[1].iov_len = buflen; - if (writev(s, iov, 2) != (INT16SZ + buflen)) { + if (_writev(s, iov, 2) != (INT16SZ + buflen)) { terrno = errno; Perror(stderr, "write failed", errno); badns |= (1 << ns); @@ -604,7 +606,7 @@ read_len: if (vc) res_close(); af = nsap->sa_family; - s = socket(af, SOCK_DGRAM, 0); + s = _socket(af, SOCK_DGRAM, 0); if (s < 0) { #ifndef CAN_RECONNECT bad_dg_sock: @@ -647,7 +649,7 @@ read_len: * receive a response from another server. */ if (!connected) { - if (connect(s, nsap, salen) < 0) { + if (_connect(s, nsap, salen) < 0) { Aerror(stderr, "connect(dg)", errno, nsap); @@ -676,15 +678,15 @@ read_len: no_addr.sin_family = AF_INET; no_addr.sin_addr.s_addr = INADDR_ANY; no_addr.sin_port = 0; - (void) connect(s, + (void)_connect(s, (struct sockaddr *) &no_addr, sizeof no_addr); #else - int s1 = socket(af, SOCK_DGRAM,0); + int s1 = _socket(af, SOCK_DGRAM,0); if (s1 < 0) goto bad_dg_sock; - (void)dup2(s1, s); + (void)_dup2(s1, s); (void)_close(s1); Dprint(_res.options & RES_DEBUG, (stdout, ";; new DG socket\n")) @@ -693,7 +695,7 @@ read_len: errno = 0; } #endif /* !CANNOT_CONNECT_DGRAM */ - if (sendto(s, (char*)buf, buflen, 0, + if (_sendto(s, (char*)buf, buflen, 0, nsap, salen) != buflen) { Aerror(stderr, "sendto", errno, nsap); badns |= (1 << ns); @@ -726,7 +728,7 @@ read_len: EV_SET(&kv, s, EVFILT_READ, EV_ADD | EV_ONESHOT, 0,0,0); - n = kevent(kq, &kv, 1, &kv, 1, &ts); + n = _kevent(kq, &kv, 1, &kv, 1, &ts); if (n < 0) { if (errno == EINTR) { (void) gettimeofday(&ctv, NULL); @@ -753,7 +755,7 @@ read_len: } errno = 0; fromlen = sizeof(from); - resplen = recvfrom(s, (char*)ans, anssiz, 0, + resplen = _recvfrom(s, (char*)ans, anssiz, 0, (struct sockaddr *)&from, &fromlen); if (resplen <= 0) { Perror(stderr, "recvfrom", errno); diff --git a/lib/libc/net/send.c b/lib/libc/net/send.c index 03af1867f7..881e80625b 100644 --- a/lib/libc/net/send.c +++ b/lib/libc/net/send.c @@ -31,15 +31,17 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/net/send.c,v 1.1.1.1.14.1 2001/03/05 10:47:11 obrien Exp $ - * $DragonFly: src/lib/libc/net/send.c,v 1.2 2003/06/17 04:26:44 dillon Exp $ + * $DragonFly: src/lib/libc/net/send.c,v 1.3 2005/01/31 22:29:33 dillon Exp $ * * @(#)send.c 8.2 (Berkeley) 2/21/94 */ +#include "namespace.h" #include #include #include +#include "un-namespace.h" ssize_t send(s, msg, len, flags) @@ -47,5 +49,5 @@ send(s, msg, len, flags) size_t len; const void *msg; { - return (sendto(s, msg, len, flags, NULL, 0)); + return (_sendto(s, msg, len, flags, NULL, 0)); } diff --git a/lib/libc/nls/msgcat.c b/lib/libc/nls/msgcat.c index d4911b341c..c0226e67d8 100644 --- a/lib/libc/nls/msgcat.c +++ b/lib/libc/nls/msgcat.c @@ -31,7 +31,7 @@ up-to-date. Many thanks. ******************************************************************/ /* * $FreeBSD: src/lib/libc/nls/msgcat.c,v 1.21.2.6 2002/08/12 11:23:54 ache Exp $ - * $DragonFly: src/lib/libc/nls/Attic/msgcat.c,v 1.3 2003/08/22 19:31:21 asmodai Exp $ + * $DragonFly: src/lib/libc/nls/Attic/msgcat.c,v 1.4 2005/01/31 22:29:36 dillon Exp $ */ /* @@ -39,6 +39,7 @@ up-to-date. Many thanks. * to add an error handling routine. */ +#include "namespace.h" #include #include #include @@ -50,6 +51,7 @@ up-to-date. Many thanks. #include #include #include +#include "un-namespace.h" #include "msgcat.h" #include "../locale/setlocale.h" /* for ENCODING_LEN */ diff --git a/lib/libc/rpc/auth_time.c b/lib/libc/rpc/auth_time.c index ecaa12d3b3..5f4a857b20 100644 --- a/lib/libc/rpc/auth_time.c +++ b/lib/libc/rpc/auth_time.c @@ -30,8 +30,9 @@ * it from TI-RPC back to TD-RPC for use on FreeBSD. * * $FreeBSD: src/lib/libc/rpc/auth_time.c,v 1.4 2000/01/27 23:06:35 jasone Exp $ - * $DragonFly: src/lib/libc/rpc/auth_time.c,v 1.2 2003/06/17 04:26:44 dillon Exp $ + * $DragonFly: src/lib/libc/rpc/auth_time.c,v 1.3 2005/01/31 22:29:38 dillon Exp $ */ +#include "namespace.h" #include #include #include @@ -47,6 +48,7 @@ #include #undef NIS #include +#include "un-namespace.h" /* * FreeBSD currently uses RPC 4.0, which uses portmap rather than @@ -386,7 +388,7 @@ __rpc_get_time_offset(td, srv, thost, uaddr, netid) goto error; } - s = socket(AF_INET, type, 0); + s = _socket(AF_INET, type, 0); if (s == -1) { msg("unable to open fd to network."); goto error; @@ -402,7 +404,7 @@ __rpc_get_time_offset(td, srv, thost, uaddr, netid) fd_set readfds; int res; - if (sendto(s, &thetime, sizeof(thetime), 0, + if (_sendto(s, &thetime, sizeof(thetime), 0, (struct sockaddr *)&sin, sizeof(sin)) == -1) { msg("udp : sendto failed."); goto error; @@ -410,13 +412,13 @@ __rpc_get_time_offset(td, srv, thost, uaddr, netid) do { FD_ZERO(&readfds); FD_SET(s, &readfds); - res = select(_rpc_dtablesize(), &readfds, + res = _select(_rpc_dtablesize(), &readfds, (fd_set *)NULL, (fd_set *)NULL, &timeout); } while (res < 0 && errno == EINTR); if (res <= 0) goto error; len = sizeof(from); - res = recvfrom(s, (char *)&thetime, sizeof(thetime), 0, + res = _recvfrom(s, (char *)&thetime, sizeof(thetime), 0, (struct sockaddr *)&from, &len); if (res == -1) { msg("recvfrom failed on udp transport."); @@ -429,7 +431,7 @@ __rpc_get_time_offset(td, srv, thost, uaddr, netid) oldsig = (void (*)())signal(SIGALRM, alarm_hndler); saw_alarm = 0; /* global tracking the alarm */ alarm(20); /* only wait 20 seconds */ - res = connect(s, (struct sockaddr *)&sin, sizeof(sin)); + res = _connect(s, (struct sockaddr *)&sin, sizeof(sin)); if (res == -1) { msg("failed to connect to tcp endpoint."); goto error; diff --git a/lib/libc/rpc/bindresvport.c b/lib/libc/rpc/bindresvport.c index aeeaa297a6..3418c7e181 100644 --- a/lib/libc/rpc/bindresvport.c +++ b/lib/libc/rpc/bindresvport.c @@ -29,7 +29,7 @@ * @(#)bindresvport.c 1.8 88/02/08 SMI * @(#)bindresvport.c 2.2 88/07/29 4.0 RPCSRC * $FreeBSD: src/lib/libc/rpc/bindresvport.c,v 1.12 2000/01/26 09:02:42 shin Exp $ - * $DragonFly: src/lib/libc/rpc/bindresvport.c,v 1.2 2003/06/17 04:26:44 dillon Exp $ + * $DragonFly: src/lib/libc/rpc/bindresvport.c,v 1.3 2005/01/31 22:29:38 dillon Exp $ */ /* @@ -38,12 +38,14 @@ * Portions Copyright(C) 1996, Jason Downs. All rights reserved. */ +#include "namespace.h" #include #include #include #include #include #include +#include "un-namespace.h" /* * Bind a socket to a privileged IP port @@ -76,7 +78,7 @@ bindresvport_sa(sd, sa) salen = sizeof(myaddr); sa = (struct sockaddr *)&myaddr; - if (getsockname(sd, sa, &salen) == -1) + if (_getsockname(sd, sa, &salen) == -1) return -1; /* errno is correctly set */ af = sa->sa_family; @@ -108,7 +110,7 @@ bindresvport_sa(sd, sa) if (port == 0) { int oldlen = sizeof(old); - error = getsockopt(sd, proto, portrange, &old, &oldlen); + error = _getsockopt(sd, proto, portrange, &old, &oldlen); if (error < 0) return (error); @@ -118,13 +120,13 @@ bindresvport_sa(sd, sa) return (error); } - error = bind(sd, sa, salen); + error = _bind(sd, sa, salen); if (port == 0) { int saved_errno = errno; if (error) { - if (setsockopt(sd, proto, portrange, &old, + if (_setsockopt(sd, proto, portrange, &old, sizeof(old)) < 0) errno = saved_errno; return (error); @@ -132,7 +134,7 @@ bindresvport_sa(sd, sa) if (sa != (struct sockaddr *)&myaddr) { /* Hmm, what did the kernel assign... */ - if (getsockname(sd, sa, &salen) < 0) + if (_getsockname(sd, sa, &salen) < 0) errno = saved_errno; return (error); } diff --git a/lib/libc/rpc/clnt_generic.c b/lib/libc/rpc/clnt_generic.c index ad22653a61..316ca9c5a9 100644 --- a/lib/libc/rpc/clnt_generic.c +++ b/lib/libc/rpc/clnt_generic.c @@ -29,7 +29,7 @@ * @(#)clnt_generic.c 1.4 87/08/11 (C) 1987 SMI * @(#)clnt_generic.c 2.2 88/08/01 4.0 RPCSRC * $FreeBSD: src/lib/libc/rpc/clnt_generic.c,v 1.9.2.1 2001/03/05 10:48:28 obrien Exp $ - * $DragonFly: src/lib/libc/rpc/clnt_generic.c,v 1.3 2004/09/14 18:23:15 joerg Exp $ + * $DragonFly: src/lib/libc/rpc/clnt_generic.c,v 1.4 2005/01/31 22:29:38 dillon Exp $ */ /* @@ -44,7 +44,7 @@ /* * Generic client creation: takes (hostname, program-number, protocol) and * returns client handle. Default options are set, which the user can - * change using the rpc equivalent of ioctl()'s. + * change using the rpc equivalent of _ioctl()'s. */ CLIENT * clnt_create(const char *hostname, u_long prog, u_long vers, const char *proto) diff --git a/lib/libc/rpc/clnt_simple.c b/lib/libc/rpc/clnt_simple.c index ac5dae92d9..750add4707 100644 --- a/lib/libc/rpc/clnt_simple.c +++ b/lib/libc/rpc/clnt_simple.c @@ -29,7 +29,7 @@ * @(#)clnt_simple.c 1.35 87/08/11 Copyr 1984 Sun Micro * @(#)clnt_simple.c 2.2 88/08/01 4.0 RPCSRC * $FreeBSD: src/lib/libc/rpc/clnt_simple.c,v 1.12 2000/01/27 23:06:35 jasone Exp $ - * $DragonFly: src/lib/libc/rpc/clnt_simple.c,v 1.3 2004/10/25 19:38:01 drhodus Exp $ + * $DragonFly: src/lib/libc/rpc/clnt_simple.c,v 1.4 2005/01/31 22:29:38 dillon Exp $ */ /* @@ -39,6 +39,7 @@ * Copyright (C) 1984, Sun Microsystems, Inc. */ +#include "namespace.h" #include #include #include @@ -47,6 +48,7 @@ #include #include #include +#include "un-namespace.h" static struct callrpc_private { CLIENT *client; diff --git a/lib/libc/rpc/clnt_tcp.c b/lib/libc/rpc/clnt_tcp.c index 5d0e270c8e..657bad3883 100644 --- a/lib/libc/rpc/clnt_tcp.c +++ b/lib/libc/rpc/clnt_tcp.c @@ -29,7 +29,7 @@ * @(#)clnt_tcp.c 1.37 87/10/05 Copyr 1984 Sun Micro * @(#)clnt_tcp.c 2.2 88/08/01 4.0 RPCSRC * $FreeBSD: src/lib/libc/rpc/clnt_tcp.c,v 1.14 2000/01/27 23:06:36 jasone Exp $ - * $DragonFly: src/lib/libc/rpc/clnt_tcp.c,v 1.3 2004/10/25 19:38:01 drhodus Exp $ + * $DragonFly: src/lib/libc/rpc/clnt_tcp.c,v 1.4 2005/01/31 22:29:38 dillon Exp $ */ /* @@ -51,6 +51,7 @@ * Now go hang yourself. */ +#include "namespace.h" #include #include #include @@ -60,6 +61,7 @@ #include #include #include +#include "un-namespace.h" #define MCALL_MSG_SIZE 24 @@ -158,10 +160,10 @@ clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz) * If no socket given, open one */ if (*sockp < 0) { - *sockp = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + *sockp = _socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); (void)bindresvport(*sockp, (struct sockaddr_in *)0); if ((*sockp < 0) - || (connect(*sockp, (struct sockaddr *)raddr, + || (_connect(*sockp, (struct sockaddr *)raddr, sizeof(*raddr)) < 0)) { rpc_createerr.cf_stat = RPC_SYSTEMERROR; rpc_createerr.cf_error.re_errno = errno; @@ -449,7 +451,7 @@ clnttcp_control(cl, request, info) break; case CLGET_LOCAL_ADDR: len = sizeof(struct sockaddr); - if (getsockname(ct->ct_sock, (struct sockaddr *)info, &len) <0) + if (_getsockname(ct->ct_sock, (struct sockaddr *)info, &len) <0) return(FALSE); break; case CLGET_RETRY_TIMEOUT: @@ -515,7 +517,7 @@ readtcp(ct, buf, len) /* XXX we know the other bits are still clear */ FD_SET(ct->ct_sock, fds); tv = delta; /* in case select writes back */ - r = select(ct->ct_sock+1, fds, NULL, NULL, &tv); + r = _select(ct->ct_sock+1, fds, NULL, NULL, &tv); save_errno = errno; gettimeofday(&after, NULL); diff --git a/lib/libc/rpc/clnt_udp.c b/lib/libc/rpc/clnt_udp.c index 441fcca3cd..f98fb12eab 100644 --- a/lib/libc/rpc/clnt_udp.c +++ b/lib/libc/rpc/clnt_udp.c @@ -29,7 +29,7 @@ * @(#)clnt_udp.c 1.39 87/08/11 Copyr 1984 Sun Micro * @(#)clnt_udp.c 2.2 88/08/01 4.0 RPCSRC * $FreeBSD: src/lib/libc/rpc/clnt_udp.c,v 1.15.2.1 2001/06/28 21:44:24 iedowse Exp $ - * $DragonFly: src/lib/libc/rpc/clnt_udp.c,v 1.3 2004/10/25 19:38:01 drhodus Exp $ + * $DragonFly: src/lib/libc/rpc/clnt_udp.c,v 1.4 2005/01/31 22:29:38 dillon Exp $ */ /* @@ -38,6 +38,7 @@ * Copyright (C) 1984, Sun Microsystems, Inc. */ +#include "namespace.h" #include #include #include @@ -48,6 +49,7 @@ #include #include #include +#include "un-namespace.h" /* * UDP bases client side rpc operations @@ -176,7 +178,7 @@ clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz) if (*sockp < 0) { int dontblock = 1; - *sockp = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + *sockp = _socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (*sockp < 0) { rpc_createerr.cf_stat = RPC_SYSTEMERROR; rpc_createerr.cf_error.re_errno = errno; @@ -185,7 +187,7 @@ clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz) /* attempt to bind to priv port */ (void)bindresvport(*sockp, (struct sockaddr_in *)0); /* the sockets rpc controls are non-blocking */ - (void)ioctl(*sockp, FIONBIO, (char *) &dontblock); + (void)_ioctl(*sockp, FIONBIO, (char *) &dontblock); cu->cu_closeit = TRUE; } else { cu->cu_closeit = FALSE; @@ -293,7 +295,7 @@ call_again: outlen = (int)XDR_GETPOS(xdrs); send_again: - if (sendto(cu->cu_sock, cu->cu_outbuf, outlen, 0, sa, salen) + if (_sendto(cu->cu_sock, cu->cu_outbuf, outlen, 0, sa, salen) != outlen) { cu->cu_error.re_errno = errno; if (fds != &readfds) @@ -323,7 +325,7 @@ send_again: /* XXX we know the other bits are still clear */ FD_SET(cu->cu_sock, fds); tv = cu->cu_wait; - switch (select(cu->cu_sock+1, fds, NULL, NULL, &tv)) { + switch (_select(cu->cu_sock+1, fds, NULL, NULL, &tv)) { case 0: timeradd(&time_waited, &cu->cu_wait, &tmp1); @@ -354,7 +356,7 @@ send_again: do { fromlen = sizeof(struct sockaddr); - inlen = recvfrom(cu->cu_sock, cu->cu_inbuf, + inlen = _recvfrom(cu->cu_sock, cu->cu_inbuf, (int) cu->cu_recvsz, 0, (struct sockaddr *)&from, &fromlen); } while (inlen < 0 && errno == EINTR); @@ -561,7 +563,7 @@ clntudp_control(cl, request, info) break; case CLGET_LOCAL_ADDR: len = sizeof(struct sockaddr); - if (getsockname(cu->cu_sock, (struct sockaddr *)info, &len) <0) + if (_getsockname(cu->cu_sock, (struct sockaddr *)info, &len) <0) return(FALSE); break; case CLSET_CONNECT: diff --git a/lib/libc/rpc/clnt_unix.c b/lib/libc/rpc/clnt_unix.c index af7a765a73..6bef9e9214 100644 --- a/lib/libc/rpc/clnt_unix.c +++ b/lib/libc/rpc/clnt_unix.c @@ -29,7 +29,7 @@ * @(#)clnt_unix.c 1.37 87/10/05 Copyr 1984 Sun Micro * @(#)clnt_unix.c 2.2 88/08/01 4.0 RPCSRC * $FreeBSD: src/lib/libc/rpc/clnt_unix.c,v 1.5 2000/01/27 23:06:37 jasone Exp $ - * $DragonFly: src/lib/libc/rpc/clnt_unix.c,v 1.3 2004/10/25 19:38:01 drhodus Exp $ + * $DragonFly: src/lib/libc/rpc/clnt_unix.c,v 1.4 2005/01/31 22:29:38 dillon Exp $ */ /* @@ -51,6 +51,7 @@ * Now go hang yourself. */ +#include "namespace.h" #include #include #include @@ -62,6 +63,7 @@ #include #include #include +#include "un-namespace.h" #define MCALL_MSG_SIZE 24 @@ -148,12 +150,12 @@ clntunix_create(raddr, prog, vers, sockp, sendsz, recvsz) * If no socket given, open one */ if (*sockp < 0) { - *sockp = socket(AF_UNIX, SOCK_STREAM, 0); + *sockp = _socket(AF_UNIX, SOCK_STREAM, 0); len = strlen(raddr->sun_path) + sizeof(raddr->sun_family) + sizeof(raddr->sun_len) + 1; raddr->sun_len = len; if ((*sockp < 0) - || (connect(*sockp, (struct sockaddr *)raddr, len) < 0)) { + || (_connect(*sockp, (struct sockaddr *)raddr, len) < 0)) { rpc_createerr.cf_stat = RPC_SYSTEMERROR; rpc_createerr.cf_error.re_errno = errno; if (*sockp != -1) @@ -440,7 +442,7 @@ clntunix_control(cl, request, info) break; case CLGET_LOCAL_ADDR: len = sizeof(struct sockaddr); - if (getsockname(ct->ct_sock, (struct sockaddr *)info, &len) <0) + if (_getsockname(ct->ct_sock, (struct sockaddr *)info, &len) <0) return(FALSE); break; case CLGET_RETRY_TIMEOUT: @@ -472,7 +474,7 @@ clntunix_destroy(h) } /* - * read() and write() are replaced with recvmsg()/sendmsg() so that + * _read() and _write() are replaced with _recvmsg()/_sendmsg() so that * we can pass ancillary control data. In this case, the data constists * of credential information which the kernel will fill in for us. * XXX: This code is specific to FreeBSD and will not work on other @@ -504,7 +506,7 @@ static int __msgread(sock, buf, cnt) msg.msg_controllen = sizeof(struct cmessage); msg.msg_flags = 0; - return(recvmsg(sock, &msg, 0)); + return(_recvmsg(sock, &msg, 0)); } static int __msgwrite(sock, buf, cnt) @@ -532,7 +534,7 @@ static int __msgwrite(sock, buf, cnt) msg.msg_controllen = sizeof(struct cmessage); msg.msg_flags = 0; - return(sendmsg(sock, &msg, 0)); + return(_sendmsg(sock, &msg, 0)); } /* @@ -570,7 +572,7 @@ readunix(ct, buf, len) /* XXX we know the other bits are still clear */ FD_SET(ct->ct_sock, fds); tv = delta; /* in case select writes back */ - r = select(ct->ct_sock+1, fds, NULL, NULL, &tv); + r = _select(ct->ct_sock+1, fds, NULL, NULL, &tv); save_errno = errno; gettimeofday(&after, NULL); diff --git a/lib/libc/rpc/get_myaddress.c b/lib/libc/rpc/get_myaddress.c index fa6d6d62f5..f4a6bb0271 100644 --- a/lib/libc/rpc/get_myaddress.c +++ b/lib/libc/rpc/get_myaddress.c @@ -29,7 +29,7 @@ * @(#)get_myaddress.c 1.4 87/08/11 Copyr 1984 Sun Micro * @(#)get_myaddress.c 2.1 88/07/29 4.0 RPCSRC * $FreeBSD: src/lib/libc/rpc/get_myaddress.c,v 1.18.2.1 2003/01/01 23:55:34 jdp Exp $ - * $DragonFly: src/lib/libc/rpc/get_myaddress.c,v 1.2 2003/06/17 04:26:44 dillon Exp $ + * $DragonFly: src/lib/libc/rpc/get_myaddress.c,v 1.3 2005/01/31 22:29:38 dillon Exp $ */ /* @@ -39,6 +39,7 @@ * Copyright (C) 1984, Sun Microsystems, Inc. */ +#include "namespace.h" #include #include #include @@ -49,6 +50,7 @@ #include #include #include +#include "un-namespace.h" /* * don't use gethostbyname, which would invoke yellow pages @@ -66,12 +68,12 @@ get_myaddress(addr) struct ifreq ifreq, *ifr, *end; int loopback = 0, gotit = 0; - if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + if ((s = _socket(AF_INET, SOCK_DGRAM, 0)) < 0) { return(-1); } ifc.ifc_len = sizeof (buf); ifc.ifc_buf = buf; - if (ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0) { + if (_ioctl(s, SIOCGIFCONF, (char *)&ifc) < 0) { _close(s); return(-1); } @@ -81,7 +83,7 @@ again: while (ifr < end) { memcpy(&ifreq, ifr, sizeof(ifreq)); - if (ioctl(s, SIOCGIFFLAGS, (char *)&ifreq) < 0) { + if (_ioctl(s, SIOCGIFFLAGS, (char *)&ifreq) < 0) { _close(s); return(-1); } diff --git a/lib/libc/rpc/key_call.c b/lib/libc/rpc/key_call.c index 6a310e95fc..49b36dfb64 100644 --- a/lib/libc/rpc/key_call.c +++ b/lib/libc/rpc/key_call.c @@ -30,7 +30,7 @@ * Copyright (c) 1986-1991 by Sun Microsystems Inc. * * $FreeBSD: src/lib/libc/rpc/key_call.c,v 1.3 2000/01/27 23:06:39 jasone Exp $ - * $DragonFly: src/lib/libc/rpc/key_call.c,v 1.4 2004/10/25 19:38:01 drhodus Exp $ + * $DragonFly: src/lib/libc/rpc/key_call.c,v 1.5 2005/01/31 22:29:38 dillon Exp $ */ #ident "@(#)key_call.c 1.25 94/04/24 SMI" @@ -44,6 +44,7 @@ * gendeskey(deskey) - generate a secure des key */ +#include "namespace.h" #include #include #include @@ -58,6 +59,7 @@ #include #include #include +#include "un-namespace.h" #define KEY_TIMEOUT 5 /* per-try timeout in seconds */ @@ -323,7 +325,7 @@ int vers; if (kcp->client != NULL) { /* if other side closed socket, build handle again */ clnt_control(kcp->client, CLGET_FD, (char *)&fd); - if (getpeername(fd,(struct sockaddr *)&name,&namelen) == -1) { + if (_getpeername(fd,(struct sockaddr *)&name,&namelen) == -1) { auth_destroy(kcp->client->cl_auth); clnt_destroy(kcp->client); kcp->client = NULL; diff --git a/lib/libc/rpc/pmap_clnt.c b/lib/libc/rpc/pmap_clnt.c index 10153646db..fad87fa926 100644 --- a/lib/libc/rpc/pmap_clnt.c +++ b/lib/libc/rpc/pmap_clnt.c @@ -29,7 +29,7 @@ * @(#)pmap_clnt.c 1.37 87/08/11 Copyr 1984 Sun Micro * @(#)pmap_clnt.c 2.2 88/08/01 4.0 RPCSRC * $FreeBSD: src/lib/libc/rpc/pmap_clnt.c,v 1.11 2000/01/27 23:06:39 jasone Exp $ - * $DragonFly: src/lib/libc/rpc/pmap_clnt.c,v 1.3 2004/10/25 19:38:01 drhodus Exp $ + * $DragonFly: src/lib/libc/rpc/pmap_clnt.c,v 1.4 2005/01/31 22:29:38 dillon Exp $ */ /* @@ -39,6 +39,7 @@ * Copyright (C) 1984, Sun Microsystems, Inc. */ +#include "namespace.h" #include #include #include @@ -46,6 +47,7 @@ #include #include #include +#include "un-namespace.h" static struct timeval timeout = { 5, 0 }; static struct timeval tottimeout = { 60, 0 }; diff --git a/lib/libc/rpc/pmap_getmaps.c b/lib/libc/rpc/pmap_getmaps.c index a08647844e..183e4f778c 100644 --- a/lib/libc/rpc/pmap_getmaps.c +++ b/lib/libc/rpc/pmap_getmaps.c @@ -29,7 +29,7 @@ * @(#)pmap_getmaps.c 1.10 87/08/11 Copyr 1984 Sun Micro * @(#)pmap_getmaps.c 2.2 88/08/01 4.0 RPCSRC * $FreeBSD: src/lib/libc/rpc/pmap_getmaps.c,v 1.11 2000/01/27 23:06:39 jasone Exp $ - * $DragonFly: src/lib/libc/rpc/pmap_getmaps.c,v 1.3 2004/10/25 19:38:01 drhodus Exp $ + * $DragonFly: src/lib/libc/rpc/pmap_getmaps.c,v 1.4 2005/01/31 22:29:38 dillon Exp $ */ /* @@ -40,6 +40,7 @@ * Copyright (C) 1984, Sun Microsystems, Inc. */ +#include "namespace.h" #include #include #include @@ -50,6 +51,8 @@ #include #include #include +#include "un-namespace.h" + #define NAMELEN 255 #define MAX_BROADCAST_SIZE 1400 diff --git a/lib/libc/rpc/pmap_getport.c b/lib/libc/rpc/pmap_getport.c index 4d1a777dcb..2cbbb4b0f6 100644 --- a/lib/libc/rpc/pmap_getport.c +++ b/lib/libc/rpc/pmap_getport.c @@ -29,7 +29,7 @@ * @(#)pmap_getport.c 1.9 87/08/11 Copyr 1984 Sun Micro * @(#)pmap_getport.c 2.2 88/08/01 4.0 RPCSRC * $FreeBSD: src/lib/libc/rpc/pmap_getport.c,v 1.10 2000/01/27 23:06:40 jasone Exp $ - * $DragonFly: src/lib/libc/rpc/pmap_getport.c,v 1.4 2004/10/25 19:38:01 drhodus Exp $ + * $DragonFly: src/lib/libc/rpc/pmap_getport.c,v 1.5 2005/01/31 22:29:38 dillon Exp $ */ /* @@ -39,12 +39,14 @@ * Copyright (C) 1984, Sun Microsystems, Inc. */ +#include "namespace.h" #include #include #include #include #include #include +#include "un-namespace.h" static struct timeval timeout = { 5, 0 }; static struct timeval tottimeout = { 60, 0 }; diff --git a/lib/libc/rpc/pmap_rmt.c b/lib/libc/rpc/pmap_rmt.c index c852cd5022..2ab850aedf 100644 --- a/lib/libc/rpc/pmap_rmt.c +++ b/lib/libc/rpc/pmap_rmt.c @@ -29,7 +29,7 @@ * @(#)pmap_rmt.c 1.21 87/08/27 Copyr 1984 Sun Micro * @(#)pmap_rmt.c 2.2 88/08/01 4.0 RPCSRC * $FreeBSD: src/lib/libc/rpc/pmap_rmt.c,v 1.16.2.1 2002/06/30 23:34:58 iedowse Exp $ - * $DragonFly: src/lib/libc/rpc/pmap_rmt.c,v 1.3 2004/10/25 19:38:02 drhodus Exp $ + * $DragonFly: src/lib/libc/rpc/pmap_rmt.c,v 1.4 2005/01/31 22:29:38 dillon Exp $ */ /* @@ -40,6 +40,7 @@ * Copyright (C) 1984, Sun Microsystems, Inc. */ +#include "namespace.h" #include #include #include @@ -53,6 +54,8 @@ #include #include #include +#include "un-namespace.h" + #define MAX_BROADCAST_SIZE 1400 static struct timeval timeout = { 3, 0 }; @@ -176,7 +179,7 @@ getbroadcastnets(addrs, sock, buf) ifc.ifc_len = UDPMSGSIZE; ifc.ifc_buf = buf; - if (ioctl(sock, SIOCGIFCONF, (char *)&ifc) < 0) { + if (_ioctl(sock, SIOCGIFCONF, (char *)&ifc) < 0) { perror("broadcast: ioctl (get interface configuration)"); return (0); } @@ -189,7 +192,7 @@ getbroadcastnets(addrs, sock, buf) if (ifr->ifr_addr.sa_family != AF_INET) continue; memcpy(&ifreq, ifr, sizeof(ifreq)); - if (ioctl(sock, SIOCGIFFLAGS, (char *)&ifreq) < 0) { + if (_ioctl(sock, SIOCGIFFLAGS, (char *)&ifreq) < 0) { perror("broadcast: ioctl (get interface flags)"); continue; } @@ -197,7 +200,7 @@ getbroadcastnets(addrs, sock, buf) (ifreq.ifr_flags & IFF_UP)) { sin = (struct sockaddr_in *)&ifr->ifr_addr; #ifdef SIOCGIFBRDADDR /* 4.3BSD */ - if (ioctl(sock, SIOCGIFBRDADDR, (char *)&ifreq) < 0) { + if (_ioctl(sock, SIOCGIFBRDADDR, (char *)&ifreq) < 0) { addr = inet_makeaddr(inet_netof(sin->sin_addr), INADDR_ANY); @@ -262,13 +265,13 @@ clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult) * initialization: create a socket, a broadcast address, and * preserialize the arguments into a send buffer. */ - if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { + if ((sock = _socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { perror("Cannot create socket for broadcast rpc"); stat = RPC_CANTSEND; goto done_broad; } #ifdef SO_BROADCAST - if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof (on)) < 0) { + if (_setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof (on)) < 0) { perror("Cannot set socket option SO_BROADCAST"); stat = RPC_CANTSEND; goto done_broad; @@ -332,7 +335,7 @@ clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult) int success = 0; for (i = 0; i < nets; i++) { baddr.sin_addr = addrs[i]; - if (sendto(sock, outbuf, outlen, 0, + if (_sendto(sock, outbuf, outlen, 0, (struct sockaddr *)&baddr, sizeof (struct sockaddr)) == outlen) { success++; @@ -353,8 +356,8 @@ clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult) msg.acpted_rply.ar_results.proc = xdr_rmtcallres; /* XXX we know the other bits are still clear */ FD_SET(sock, fds); - tv = t; /* for select() that copies back */ - switch (select(sock + 1, fds, NULL, NULL, &tv)) { + tv = t; /* for _select() that copies back */ + switch (_select(sock + 1, fds, NULL, NULL, &tv)) { case 0: /* timed out */ stat = RPC_TIMEDOUT; @@ -370,7 +373,7 @@ clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult) } /* end of select results switch */ try_again: fromlen = sizeof(struct sockaddr); - inlen = recvfrom(sock, inbuf, UDPMSGSIZE, 0, + inlen = _recvfrom(sock, inbuf, UDPMSGSIZE, 0, (struct sockaddr *)&raddr, &fromlen); if (inlen < 0) { if (errno == EINTR) diff --git a/lib/libc/rpc/rpc_dtablesize.c b/lib/libc/rpc/rpc_dtablesize.c index be33f5c8b7..4f28d01db7 100644 --- a/lib/libc/rpc/rpc_dtablesize.c +++ b/lib/libc/rpc/rpc_dtablesize.c @@ -29,7 +29,7 @@ * @(#)rpc_dtablesize.c 1.2 87/08/11 Copyr 1987 Sun Micro * @(#)rpc_dtablesize.c 2.1 88/07/29 4.0 RPCSRC * $FreeBSD: src/lib/libc/rpc/rpc_dtablesize.c,v 1.10 1999/08/28 00:00:45 peter Exp $ - * $DragonFly: src/lib/libc/rpc/rpc_dtablesize.c,v 1.2 2003/06/17 04:26:45 dillon Exp $ + * $DragonFly: src/lib/libc/rpc/rpc_dtablesize.c,v 1.3 2005/01/31 22:29:38 dillon Exp $ */ #include @@ -44,7 +44,7 @@ * descriptors be greater than FD_SETSIZE (which us 256 by default). * * Since old programs tend to use this call to determine the first arg - * for select(), having this return > FD_SETSIZE is a Bad Idea(TM)! + * for _select(), having this return > FD_SETSIZE is a Bad Idea(TM)! */ int _rpc_dtablesize(void) diff --git a/lib/libc/rpc/rtime.c b/lib/libc/rpc/rtime.c index c47879a748..831888b895 100644 --- a/lib/libc/rpc/rtime.c +++ b/lib/libc/rpc/rtime.c @@ -28,7 +28,7 @@ * * @(#)rtime.c 2.2 88/08/10 4.0 RPCSRC; from 1.8 88/02/08 SMI * $FreeBSD: src/lib/libc/rpc/rtime.c,v 1.5 2000/01/27 23:06:41 jasone Exp $ - * $DragonFly: src/lib/libc/rpc/rtime.c,v 1.3 2003/11/12 20:21:25 eirikn Exp $ + * $DragonFly: src/lib/libc/rpc/rtime.c,v 1.4 2005/01/31 22:29:38 dillon Exp $ */ /* @@ -45,6 +45,7 @@ * subtract seconds before Jan 1, 1970 to get * what unix uses. */ +#include "namespace.h" #include #include #include @@ -55,6 +56,7 @@ #include #include #include +#include "un-namespace.h" extern int _rpc_dtablesize ( void ); @@ -83,7 +85,7 @@ rtime(addrp, timep, timeout) } else { type = SOCK_DGRAM; } - s = socket(AF_INET, type, 0); + s = _socket(AF_INET, type, 0); if (s < 0) { return(-1); } @@ -97,7 +99,7 @@ rtime(addrp, timep, timeout) addrp->sin_port = serv->s_port; if (type == SOCK_DGRAM) { - res = sendto(s, (char *)&thetime, sizeof(thetime), 0, + res = _sendto(s, (char *)&thetime, sizeof(thetime), 0, (struct sockaddr *)addrp, sizeof(*addrp)); if (res < 0) { do_close(s); @@ -106,7 +108,7 @@ rtime(addrp, timep, timeout) do { FD_ZERO(&readfds); FD_SET(s, &readfds); - res = select(_rpc_dtablesize(), &readfds, + res = _select(_rpc_dtablesize(), &readfds, (fd_set *)NULL, (fd_set *)NULL, timeout); } while (res < 0 && errno == EINTR); if (res <= 0) { @@ -117,14 +119,14 @@ rtime(addrp, timep, timeout) return(-1); } fromlen = sizeof(from); - res = recvfrom(s, (char *)&thetime, sizeof(thetime), 0, + res = _recvfrom(s, (char *)&thetime, sizeof(thetime), 0, (struct sockaddr *)&from, &fromlen); do_close(s); if (res < 0) { return(-1); } } else { - if (connect(s, (struct sockaddr *)addrp, sizeof(*addrp)) < 0) { + if (_connect(s, (struct sockaddr *)addrp, sizeof(*addrp)) < 0) { do_close(s); return(-1); } diff --git a/lib/libc/rpc/svc_auth_des.c b/lib/libc/rpc/svc_auth_des.c index 2fd6ea19df..b1d699fe57 100644 --- a/lib/libc/rpc/svc_auth_des.c +++ b/lib/libc/rpc/svc_auth_des.c @@ -4,7 +4,7 @@ * * @(#)svcauth_des.c 2.3 89/07/11 4.0 RPCSRC; from 1.15 88/02/08 SMI * $FreeBSD: src/lib/libc/rpc/svc_auth_des.c,v 1.3 1999/08/28 00:00:48 peter Exp $ - * $DragonFly: src/lib/libc/rpc/svc_auth_des.c,v 1.4 2004/10/25 19:38:02 drhodus Exp $ + * $DragonFly: src/lib/libc/rpc/svc_auth_des.c,v 1.5 2005/01/31 22:29:38 dillon Exp $ */ /* @@ -52,6 +52,7 @@ #include #include +#include #include #include #include diff --git a/lib/libc/rpc/svc_run.c b/lib/libc/rpc/svc_run.c index dce640d155..ce46973655 100644 --- a/lib/libc/rpc/svc_run.c +++ b/lib/libc/rpc/svc_run.c @@ -29,13 +29,14 @@ * @(#)svc_run.c 1.1 87/10/13 Copyr 1984 Sun Micro * @(#)svc_run.c 2.1 88/07/29 4.0 RPCSRC * $FreeBSD: src/lib/libc/rpc/svc_run.c,v 1.10 1999/08/28 00:00:49 peter Exp $ - * $DragonFly: src/lib/libc/rpc/svc_run.c,v 1.2 2003/06/17 04:26:45 dillon Exp $ + * $DragonFly: src/lib/libc/rpc/svc_run.c,v 1.3 2005/01/31 22:29:38 dillon Exp $ */ /* * This is the rpc server side idle loop * Wait for input, call server program. */ +#include "namespace.h" #include #include #include @@ -44,6 +45,7 @@ #include #include #include +#include "un-namespace.h" extern int __svc_fdsetsize; extern fd_set *__svc_fdset; @@ -61,7 +63,7 @@ svc_run() memcpy(fds, __svc_fdset, bytes); } else fds = NULL; - switch (select(svc_maxfd + 1, fds, NULL, NULL, + switch (_select(svc_maxfd + 1, fds, NULL, NULL, (struct timeval *)0)) { case -1: if (errno == EINTR) { @@ -78,7 +80,7 @@ svc_run() free(fds); continue; default: - /* if fds == NULL, select() can't return a result */ + /* if fds == NULL, _select() can't return a result */ svc_getreqset2(fds, svc_maxfd + 1); free(fds); } diff --git a/lib/libc/rpc/svc_tcp.c b/lib/libc/rpc/svc_tcp.c index bcc4831a45..9688521409 100644 --- a/lib/libc/rpc/svc_tcp.c +++ b/lib/libc/rpc/svc_tcp.c @@ -29,7 +29,7 @@ * @(#)svc_tcp.c 1.21 87/08/11 Copyr 1984 Sun Micro * @(#)svc_tcp.c 2.2 88/08/01 4.0 RPCSRC * $FreeBSD: src/lib/libc/rpc/svc_tcp.c,v 1.18.2.3 2001/09/05 22:29:23 dec Exp $ - * $DragonFly: src/lib/libc/rpc/svc_tcp.c,v 1.3 2004/10/25 19:38:02 drhodus Exp $ + * $DragonFly: src/lib/libc/rpc/svc_tcp.c,v 1.4 2005/01/31 22:29:38 dillon Exp $ */ /* @@ -42,6 +42,7 @@ * and a record/tcp stream. */ +#include "namespace.h" #include #include #include @@ -50,6 +51,7 @@ #include #include #include +#include "un-namespace.h" /* * Ops vector for TCP/IP based rpc service handle @@ -134,14 +136,14 @@ svctcp_create(sock, sendsize, recvsize) int on; if (sock == RPC_ANYSOCK) { - if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { + if ((sock = _socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { perror("svctcp_.c - tcp socket creation problem"); return ((SVCXPRT *)NULL); } madesock = TRUE; } on = 1; - if (ioctl(sock, FIONBIO, &on) < 0) { + if (_ioctl(sock, FIONBIO, &on) < 0) { perror("svc_tcp.c - cannot turn on non-blocking mode"); if (madesock) (void)_close(sock); @@ -152,10 +154,10 @@ svctcp_create(sock, sendsize, recvsize) addr.sin_family = AF_INET; if (bindresvport(sock, &addr)) { addr.sin_port = 0; - (void)bind(sock, (struct sockaddr *)&addr, len); + (void)_bind(sock, (struct sockaddr *)&addr, len); } - if ((getsockname(sock, (struct sockaddr *)&addr, &len) != 0) || - (listen(sock, 2) != 0)) { + if ((_getsockname(sock, (struct sockaddr *)&addr, &len) != 0) || + (_listen(sock, 2) != 0)) { perror("svctcp_.c - cannot getsockname or listen"); if (madesock) (void)_close(sock); @@ -246,7 +248,7 @@ rendezvous_request(xprt) r = (struct tcp_rendezvous *)xprt->xp_p1; again: len = sizeof(struct sockaddr_in); - if ((sock = accept(xprt->xp_sock, (struct sockaddr *)&addr, + if ((sock = _accept(xprt->xp_sock, (struct sockaddr *)&addr, &len)) < 0) { if (errno == EINTR) goto again; @@ -263,7 +265,7 @@ rendezvous_request(xprt) * The listening socket is in FIONBIO mode and we inherit it. */ off = 0; - if (ioctl(sock, FIONBIO, &off) < 0) { + if (_ioctl(sock, FIONBIO, &off) < 0) { _close(sock); return (FALSE); } @@ -316,7 +318,7 @@ static struct timeval wait_per_try = { 35, 0 }; * Note: we have to be careful here not to allow ourselves to become * blocked too long in this routine. While we're waiting for data from one * client, another client may be trying to connect. To avoid this situation, - * some code from svc_run() is transplanted here: the select() loop checks + * some code from svc_run() is transplanted here: the _select() loop checks * all RPC descriptors including the one we want and calls svc_getreqset2() * to handle new requests if any are detected. */ @@ -348,8 +350,8 @@ readtcp(xprt, buf, len) /* XXX we know the other bits are still clear */ FD_SET(sock, fds); - tv = delta; /* in case select() implements writeback */ - switch (select(svc_maxfd + 1, fds, NULL, NULL, &tv)) { + tv = delta; /* in case _select() implements writeback */ + switch (_select(svc_maxfd + 1, fds, NULL, NULL, &tv)) { case -1: memset(fds, 0, bytes); if (errno != EINTR) diff --git a/lib/libc/rpc/svc_udp.c b/lib/libc/rpc/svc_udp.c index 33d3d4e3ff..81a7a2004b 100644 --- a/lib/libc/rpc/svc_udp.c +++ b/lib/libc/rpc/svc_udp.c @@ -29,7 +29,7 @@ * @(#)svc_udp.c 1.24 87/08/11 Copyr 1984 Sun Micro * @(#)svc_udp.c 2.2 88/07/29 4.0 RPCSRC * $FreeBSD: src/lib/libc/rpc/svc_udp.c,v 1.13 2000/01/27 23:06:41 jasone Exp $ - * $DragonFly: src/lib/libc/rpc/svc_udp.c,v 1.4 2004/10/25 19:38:02 drhodus Exp $ + * $DragonFly: src/lib/libc/rpc/svc_udp.c,v 1.5 2005/01/31 22:29:38 dillon Exp $ */ /* @@ -40,6 +40,7 @@ * Copyright (C) 1984, Sun Microsystems, Inc. */ +#include "namespace.h" #include #include #include @@ -47,6 +48,7 @@ #include #include #include +#include "un-namespace.h" #define rpc_buffer(xprt) ((xprt)->xp_p1) #define MAX(a, b) ((a > b) ? a : b) @@ -106,7 +108,7 @@ svcudp_bufcreate(sock, sendsz, recvsz) int len = sizeof(struct sockaddr_in); if (sock == RPC_ANYSOCK) { - if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { + if ((sock = _socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { perror("svcudp_create: socket creation problem"); return ((SVCXPRT *)NULL); } @@ -117,9 +119,9 @@ svcudp_bufcreate(sock, sendsz, recvsz) addr.sin_family = AF_INET; if (bindresvport(sock, &addr)) { addr.sin_port = 0; - (void)bind(sock, (struct sockaddr *)&addr, len); + (void)_bind(sock, (struct sockaddr *)&addr, len); } - if (getsockname(sock, (struct sockaddr *)&addr, &len) != 0) { + if (_getsockname(sock, (struct sockaddr *)&addr, &len) != 0) { perror("svcudp_create - cannot getsockname"); if (madesock) (void)_close(sock); @@ -181,7 +183,7 @@ svcudp_recv(xprt, msg) again: xprt->xp_addrlen = sizeof(struct sockaddr_in); - rlen = recvfrom(xprt->xp_sock, rpc_buffer(xprt), (int) su->su_iosz, + rlen = _recvfrom(xprt->xp_sock, rpc_buffer(xprt), (int) su->su_iosz, 0, (struct sockaddr *)&(xprt->xp_raddr), &(xprt->xp_addrlen)); if (rlen == -1 && errno == EINTR) goto again; @@ -194,7 +196,7 @@ svcudp_recv(xprt, msg) su->su_xid = msg->rm_xid; if (su->su_cache != NULL) { if (cache_get(xprt, msg, &reply, &replylen)) { - (void) sendto(xprt->xp_sock, reply, (int) replylen, 0, + (void) _sendto(xprt->xp_sock, reply, (int) replylen, 0, (struct sockaddr *) &xprt->xp_raddr, xprt->xp_addrlen); return (TRUE); } @@ -217,7 +219,7 @@ svcudp_reply(xprt, msg) msg->rm_xid = su->su_xid; if (xdr_replymsg(xdrs, msg)) { slen = (int)XDR_GETPOS(xdrs); - if (sendto(xprt->xp_sock, rpc_buffer(xprt), slen, 0, + if (_sendto(xprt->xp_sock, rpc_buffer(xprt), slen, 0, (struct sockaddr *)&(xprt->xp_raddr), xprt->xp_addrlen) == slen) { stat = TRUE; diff --git a/lib/libc/rpc/svc_unix.c b/lib/libc/rpc/svc_unix.c index 8cb630a580..13acbc9983 100644 --- a/lib/libc/rpc/svc_unix.c +++ b/lib/libc/rpc/svc_unix.c @@ -29,7 +29,7 @@ * @(#)svc_unix.c 1.21 87/08/11 Copyr 1984 Sun Micro * @(#)svc_unix.c 2.2 88/08/01 4.0 RPCSRC * $FreeBSD: src/lib/libc/rpc/svc_unix.c,v 1.7.2.2 2001/09/05 22:29:23 dec Exp $ - * $DragonFly: src/lib/libc/rpc/svc_unix.c,v 1.3 2004/10/25 19:38:02 drhodus Exp $ + * $DragonFly: src/lib/libc/rpc/svc_unix.c,v 1.4 2005/01/31 22:29:38 dillon Exp $ */ /* @@ -42,6 +42,7 @@ * and a record/unix stream. */ +#include "namespace.h" #include #include #include @@ -51,6 +52,7 @@ #include #include #include +#include "un-namespace.h" /* * Ops vector for AF_UNIX based rpc service handle @@ -129,7 +131,7 @@ static int __msgread(sock, buf, cnt) msg.msg_controllen = sizeof(struct cmessage); msg.msg_flags = 0; - return(recvmsg(sock, &msg, 0)); + return(_recvmsg(sock, &msg, 0)); } static int __msgwrite(sock, buf, cnt) @@ -156,7 +158,7 @@ static int __msgwrite(sock, buf, cnt) msg.msg_controllen = sizeof(struct cmessage); msg.msg_flags = 0; - return(sendmsg(sock, &msg, 0)); + return(_sendmsg(sock, &msg, 0)); } /* @@ -193,7 +195,7 @@ svcunix_create(sock, sendsize, recvsize, path) int len = sizeof(struct sockaddr_un); if (sock == RPC_ANYSOCK) { - if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { + if ((sock = _socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { perror("svc_unix.c - AF_UNIX socket creation problem"); return ((SVCXPRT *)NULL); } @@ -206,10 +208,10 @@ svcunix_create(sock, sendsize, recvsize, path) sizeof(addr.sun_len) + 1; addr.sun_len = len; - bind(sock, (struct sockaddr *)&addr, len); + _bind(sock, (struct sockaddr *)&addr, len); - if ((getsockname(sock, (struct sockaddr *)&addr, &len) != 0) || - (listen(sock, 2) != 0)) { + if ((_getsockname(sock, (struct sockaddr *)&addr, &len) != 0) || + (_listen(sock, 2) != 0)) { perror("svc_unix.c - cannot getsockname or listen"); if (madesock) (void)_close(sock); @@ -300,7 +302,7 @@ rendezvous_request(xprt) r = (struct unix_rendezvous *)xprt->xp_p1; again: len = sizeof(struct sockaddr_in); - if ((sock = accept(xprt->xp_sock, (struct sockaddr *)&addr, + if ((sock = _accept(xprt->xp_sock, (struct sockaddr *)&addr, &len)) < 0) { if (errno == EINTR) goto again; @@ -358,7 +360,7 @@ static struct timeval wait_per_try = { 35, 0 }; * Note: we have to be careful here not to allow ourselves to become * blocked too long in this routine. While we're waiting for data from one * client, another client may be trying to connect. To avoid this situation, - * some code from svc_run() is transplanted here: the select() loop checks + * some code from svc_run() is transplanted here: the _select() loop checks * all RPC descriptors including the one we want and calls svc_getreqset2() * to handle new requests if any are detected. */ @@ -390,8 +392,8 @@ readunix(xprt, buf, len) /* XXX we know the other bits are still clear */ FD_SET(sock, fds); - tv = delta; /* in case select() implements writeback */ - switch (select(svc_maxfd + 1, fds, NULL, NULL, &tv)) { + tv = delta; /* in case _select() implements writeback */ + switch (_select(svc_maxfd + 1, fds, NULL, NULL, &tv)) { case -1: memset(fds, 0, bytes); if (errno != EINTR) diff --git a/lib/libc/stdio/_flock_stub.c b/lib/libc/stdio/_flock_stub.c index 7793d7486e..83ac6fd27b 100644 --- a/lib/libc/stdio/_flock_stub.c +++ b/lib/libc/stdio/_flock_stub.c @@ -30,22 +30,24 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/stdio/_flock_stub.c,v 1.3 1999/08/28 00:00:55 peter Exp $ - * $DragonFly: src/lib/libc/stdio/_flock_stub.c,v 1.3 2004/01/23 11:30:27 joerg Exp $ + * $DragonFly: src/lib/libc/stdio/_flock_stub.c,v 1.4 2005/01/31 22:29:40 dillon Exp $ * */ #include /* Don't build this in libc_r, just libc: */ -#ifndef _THREAD_SAFE /* * Declare weak references in case the application is not linked * with libpthread. */ #pragma weak flockfile=_flockfile_stub +#pragma weak _flockfile=_flockfile_stub #pragma weak _flockfile_debug=_flockfile_debug_stub #pragma weak ftrylockfile=_ftrylockfile_stub +#pragma weak _ftrylockfile=_ftrylockfile_stub #pragma weak funlockfile=_funlockfile_stub +#pragma weak _funlockfile=_funlockfile_stub void flockfile(FILE *); void _flockfile_debug(FILE *, char *, int); @@ -84,4 +86,3 @@ void _funlockfile_stub(FILE *fp) { } -#endif diff --git a/lib/libc/stdio/clrerr.c b/lib/libc/stdio/clrerr.c index aecc8a931e..9d6b509e52 100644 --- a/lib/libc/stdio/clrerr.c +++ b/lib/libc/stdio/clrerr.c @@ -35,12 +35,14 @@ * * @(#)clrerr.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/clrerr.c,v 1.7 1999/08/28 00:00:55 peter Exp $ - * $DragonFly: src/lib/libc/stdio/clrerr.c,v 1.3 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/clrerr.c,v 1.4 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include -#undef clearerr +#include "un-namespace.h" #include "libc_private.h" +#undef clearerr void clearerr(FILE *fp) diff --git a/lib/libc/stdio/fclose.c b/lib/libc/stdio/fclose.c index dabe772407..e770b46366 100644 --- a/lib/libc/stdio/fclose.c +++ b/lib/libc/stdio/fclose.c @@ -35,14 +35,16 @@ * * @(#)fclose.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/fclose.c,v 1.8 1999/11/21 22:34:57 dt Exp $ - * $DragonFly: src/lib/libc/stdio/fclose.c,v 1.7 2004/06/09 19:40:59 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/fclose.c,v 1.8 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include #include #include -#include "local.h" +#include "un-namespace.h" #include "libc_private.h" +#include "local.h" int fclose(FILE *fp) @@ -74,6 +76,12 @@ fclose(FILE *fp) FUNLOCKFILE(fp); fp->_file = -1; fp->_r = fp->_w = 0; /* Mess up if reaccessed. */ +#if 0 + if (fp->_lock != NULL) { + _pthread_mutex_destroy((pthread_mutex_t *)&fp->_lock); + fp->_lock = NULL; + } +#endif fp->_flags = 0; /* Release this FILE for reuse. */ return (r); } diff --git a/lib/libc/stdio/fdopen.c b/lib/libc/stdio/fdopen.c index d452811d26..c72fc8d265 100644 --- a/lib/libc/stdio/fdopen.c +++ b/lib/libc/stdio/fdopen.c @@ -34,16 +34,18 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/stdio/fdopen.c,v 1.3 2000/01/27 23:06:44 jasone Exp $ - * $DragonFly: src/lib/libc/stdio/fdopen.c,v 1.4 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/fdopen.c,v 1.5 2005/01/31 22:29:40 dillon Exp $ * * @(#)fdopen.c 8.1 (Berkeley) 6/4/93 */ +#include "namespace.h" #include #include #include #include #include +#include "un-namespace.h" #include "local.h" FILE * diff --git a/lib/libc/stdio/fflush.c b/lib/libc/stdio/fflush.c index 9c476c3567..f7356e6958 100644 --- a/lib/libc/stdio/fflush.c +++ b/lib/libc/stdio/fflush.c @@ -35,15 +35,20 @@ * * @(#)fflush.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/fflush.c,v 1.7 1999/08/28 00:00:58 peter Exp $ - * $DragonFly: src/lib/libc/stdio/fflush.c,v 1.4 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/fflush.c,v 1.5 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include #include -#include "local.h" +#include "un-namespace.h" #include "libc_private.h" +#include "local.h" -/* Flush a single file, or (if fp is NULL) all files. */ +/* + * Flush a single file, or (if fp is NULL) all files. + * MT-safe version + */ int fflush(FILE *fp) { @@ -55,13 +60,32 @@ fflush(FILE *fp) if ((fp->_flags & (__SWR | __SRW)) == 0) { errno = EBADF; retval = EOF; - } else { + } else retval = __sflush(fp); - } + FUNLOCKFILE(fp); return (retval); } +/* + * Flush a single file, or (if fp is NULL) all files. + * Non-MT-safe version + */ +int +__fflush(FILE *fp) +{ + int retval; + + if (fp == NULL) + return (_fwalk(__sflush)); + if ((fp->_flags & (__SWR | __SRW)) == 0) { + errno = EBADF; + retval = EOF; + } else + retval = __sflush(fp); + return (retval); +} + int __sflush(FILE *fp) { diff --git a/lib/libc/stdio/fgetc.c b/lib/libc/stdio/fgetc.c index 6dfd9709d9..368982c804 100644 --- a/lib/libc/stdio/fgetc.c +++ b/lib/libc/stdio/fgetc.c @@ -35,10 +35,12 @@ * * @(#)fgetc.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/fgetc.c,v 1.7 1999/08/28 00:00:58 peter Exp $ - * $DragonFly: src/lib/libc/stdio/fgetc.c,v 1.3 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/fgetc.c,v 1.4 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include +#include "un-namespace.h" #include "libc_private.h" int diff --git a/lib/libc/stdio/fgetpos.c b/lib/libc/stdio/fgetpos.c index 2c0186e739..59f1596880 100644 --- a/lib/libc/stdio/fgetpos.c +++ b/lib/libc/stdio/fgetpos.c @@ -35,10 +35,12 @@ * * @(#)fgetpos.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/fgetpos.c,v 1.8 1999/08/28 00:00:59 peter Exp $ - * $DragonFly: src/lib/libc/stdio/fgetpos.c,v 1.4 2004/06/07 20:57:15 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/fgetpos.c,v 1.5 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include +#include "un-namespace.h" #include "libc_private.h" int diff --git a/lib/libc/stdio/fgets.c b/lib/libc/stdio/fgets.c index 9458158797..539f726562 100644 --- a/lib/libc/stdio/fgets.c +++ b/lib/libc/stdio/fgets.c @@ -35,11 +35,13 @@ * * @(#)fgets.c 8.2 (Berkeley) 12/22/93 * $FreeBSD: src/lib/libc/stdio/fgets.c,v 1.9 1999/08/28 00:01:00 peter Exp $ - * $DragonFly: src/lib/libc/stdio/fgets.c,v 1.4 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/fgets.c,v 1.5 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include #include +#include "un-namespace.h" #include "local.h" #include "libc_private.h" diff --git a/lib/libc/stdio/findfp.c b/lib/libc/stdio/findfp.c index 524e3e524f..2a1a95a681 100644 --- a/lib/libc/stdio/findfp.c +++ b/lib/libc/stdio/findfp.c @@ -35,19 +35,19 @@ * * @(#)findfp.c 8.2 (Berkeley) 1/4/94 * $FreeBSD: src/lib/libc/stdio/findfp.c,v 1.7.2.3 2001/08/17 02:56:31 peter Exp $ - * $DragonFly: src/lib/libc/stdio/findfp.c,v 1.5 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/findfp.c,v 1.6 2005/01/31 22:29:40 dillon Exp $ */ #include +#include #include #include -#include #include #include -#include #include +#include #include "local.h" #include "glue.h" @@ -61,14 +61,19 @@ int __sdidinit; /* the usual - (stdin + stdout + stderr) */ static FILE usual[FOPEN_MAX - 3]; -static struct glue uglue = { 0, FOPEN_MAX - 3, usual }; +static struct glue uglue = { NULL, FOPEN_MAX - 3, usual }; FILE __sF[3] = { std(__SRD, STDIN_FILENO), /* stdin */ std(__SWR, STDOUT_FILENO), /* stdout */ std(__SWR|__SNBF, STDERR_FILENO) /* stderr */ }; -struct glue __sglue = { &uglue, 3, __sF }; + +/* + * note: __sglue starts the walk chain for exit flushing and other things. + */ +struct glue __sglue = { &uglue, 3, __sF }; /* GLOBAL, START OF LIST */ +static struct glue *lastglue = &uglue; /* * The following kludge is done to ensure enough binary compatibility @@ -87,6 +92,12 @@ static spinlock_t thread_lock = _SPINLOCK_INITIALIZER; #define THREAD_LOCK() if (__isthreaded) _SPINLOCK(&thread_lock) #define THREAD_UNLOCK() if (__isthreaded) _SPINUNLOCK(&thread_lock) +#if NOT_YET +#define SET_GLUE_PTR(ptr, val) atomic_set_ptr(&(ptr), (uintptr_t)(val)) +#else +#define SET_GLUE_PTR(ptr, val) ptr = val +#endif + static struct glue * moreglue(int n) @@ -119,16 +130,22 @@ __sfp(void) if (!__sdidinit) __sinit(); + /* + * The list must be locked because a FILE may be updated. + */ THREAD_LOCK(); - for (g = &__sglue;; g = g->next) { + for (g = &__sglue; g != NULL; g = g->next) { for (fp = g->iobs, n = g->niobs; --n >= 0; fp++) if (fp->_flags == 0) goto found; - if (g->next == NULL && (g->next = moreglue(NDYNAMIC)) == NULL) - break; } - THREAD_UNLOCK(); - return (NULL); + THREAD_UNLOCK(); /* don't hold lock while malloc()ing. */ + if ((g = moreglue(NDYNAMIC)) == NULL) + return (NULL); + THREAD_LOCK(); /* reacquire the lock */ + SET_GLUE_PTR(lastglue->next, g); /* atomically append glue to list */ + lastglue = g; /* not atomic; only accessed when locked */ + fp = g->iobs; found: fp->_flags = 1; /* reserve this slot; caller sets real flags */ THREAD_UNLOCK(); @@ -144,6 +161,7 @@ found: fp->_ub._size = 0; fp->_lb._base = NULL; /* no line buffer */ fp->_lb._size = 0; + /* fp->_lock = NULL; */ return (fp); } @@ -161,10 +179,19 @@ f_prealloc(void) int n; n = getdtablesize() - FOPEN_MAX + 20; /* 20 for slop. */ + /* + * It should be safe to walk the list without locking it; + * new nodes are only added to the end and none are ever + * removed. + */ for (g = &__sglue; (n -= g->niobs) > 0 && g->next; g = g->next) /* void */; - if (n > 0) - g->next = moreglue(n); + if ((n > 0) && ((g = moreglue(n)) != NULL)) { + THREAD_LOCK(); + SET_GLUE_PTR(lastglue->next, g); + lastglue = g; + THREAD_UNLOCK(); + } } /* diff --git a/lib/libc/stdio/flags.c b/lib/libc/stdio/flags.c index 5b813a6a6d..0323e37497 100644 --- a/lib/libc/stdio/flags.c +++ b/lib/libc/stdio/flags.c @@ -35,7 +35,7 @@ * * @(#)flags.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/flags.c,v 1.6.2.1 2001/03/05 10:51:22 obrien Exp $ - * $DragonFly: src/lib/libc/stdio/flags.c,v 1.4 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/flags.c,v 1.5 2005/01/31 22:29:40 dillon Exp $ */ #include @@ -47,7 +47,7 @@ /* * Return the (stdio) flags for a given mode. Store the flags - * to be passed to an open() syscall through *optr. + * to be passed to an _open() syscall through *optr. * Return 0 on error. */ int diff --git a/lib/libc/stdio/fopen.c b/lib/libc/stdio/fopen.c index f43ce2afd2..cb502b560f 100644 --- a/lib/libc/stdio/fopen.c +++ b/lib/libc/stdio/fopen.c @@ -34,16 +34,18 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/stdio/fopen.c,v 1.3.2.1 2001/03/05 10:53:51 obrien Exp $ - * $DragonFly: src/lib/libc/stdio/fopen.c,v 1.3 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/fopen.c,v 1.4 2005/01/31 22:29:40 dillon Exp $ * * @(#)fopen.c 8.1 (Berkeley) 6/4/93 */ +#include "namespace.h" #include #include #include #include #include +#include "un-namespace.h" #include "local.h" @@ -69,6 +71,7 @@ fopen(const char *file, const char *mode) fp->_write = __swrite; fp->_seek = __sseek; fp->_close = __sclose; + /* fp->_lock = NULL; */ /* * When opening in append mode, even though we use O_APPEND, * we need to seek to the end so that ftell() gets the right diff --git a/lib/libc/stdio/fpurge.c b/lib/libc/stdio/fpurge.c index bc4a4ec368..68467d9d42 100644 --- a/lib/libc/stdio/fpurge.c +++ b/lib/libc/stdio/fpurge.c @@ -35,12 +35,14 @@ * * @(#)fpurge.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/fpurge.c,v 1.7 1999/08/28 00:01:02 peter Exp $ - * $DragonFly: src/lib/libc/stdio/fpurge.c,v 1.4 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/fpurge.c,v 1.5 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include #include #include +#include "un-namespace.h" #include "local.h" #include "libc_private.h" diff --git a/lib/libc/stdio/fputc.c b/lib/libc/stdio/fputc.c index fb5603d280..5837049583 100644 --- a/lib/libc/stdio/fputc.c +++ b/lib/libc/stdio/fputc.c @@ -35,10 +35,12 @@ * * @(#)fputc.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/fputc.c,v 1.7 1999/08/28 00:01:03 peter Exp $ - * $DragonFly: src/lib/libc/stdio/fputc.c,v 1.4 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/fputc.c,v 1.5 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include +#include "un-namespace.h" #include "libc_private.h" int diff --git a/lib/libc/stdio/fputs.c b/lib/libc/stdio/fputs.c index 446e2849b5..70b495db37 100644 --- a/lib/libc/stdio/fputs.c +++ b/lib/libc/stdio/fputs.c @@ -35,11 +35,13 @@ * * @(#)fputs.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/fputs.c,v 1.7 1999/08/28 00:01:03 peter Exp $ - * $DragonFly: src/lib/libc/stdio/fputs.c,v 1.3 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/fputs.c,v 1.4 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include #include +#include "un-namespace.h" #include "fvwrite.h" #include "libc_private.h" diff --git a/lib/libc/stdio/fread.c b/lib/libc/stdio/fread.c index f040667e18..732b171c88 100644 --- a/lib/libc/stdio/fread.c +++ b/lib/libc/stdio/fread.c @@ -35,11 +35,13 @@ * * @(#)fread.c 8.2 (Berkeley) 12/11/93 * $FreeBSD: src/lib/libc/stdio/fread.c,v 1.7 1999/08/28 00:01:04 peter Exp $ - * $DragonFly: src/lib/libc/stdio/fread.c,v 1.4 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/fread.c,v 1.5 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include #include +#include "un-namespace.h" #include "local.h" #include "libc_private.h" diff --git a/lib/libc/stdio/freopen.c b/lib/libc/stdio/freopen.c index 6afca27159..a2f4a36384 100644 --- a/lib/libc/stdio/freopen.c +++ b/lib/libc/stdio/freopen.c @@ -35,9 +35,10 @@ * * @(#)freopen.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/freopen.c,v 1.5.2.1 2001/03/05 10:54:53 obrien Exp $ - * $DragonFly: src/lib/libc/stdio/freopen.c,v 1.4 2004/06/08 00:45:00 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/freopen.c,v 1.5 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include #include #include @@ -45,6 +46,7 @@ #include #include #include +#include "un-namespace.h" #include "libc_private.h" #include "local.h" @@ -110,7 +112,7 @@ freopen(const char *file, const char *mode, FILE *fp) } if (oflags & O_TRUNC) ftruncate(fp->_file, 0); - if (fseeko(fp, 0, oflags & O_APPEND ? SEEK_END : SEEK_SET) < 0 && + if (_fseeko(fp, 0, oflags & O_APPEND ? SEEK_END : SEEK_SET) < 0 && errno != ESPIPE) { sverrno = errno; fclose(fp); @@ -196,7 +198,7 @@ finish: * assume stderr is always fd STDERR_FILENO, even if being freopen'd. */ if (wantfd >= 0 && f != wantfd) { - if (dup2(f, wantfd) >= 0) { + if (_dup2(f, wantfd) >= 0) { (void)_close(f); f = wantfd; } diff --git a/lib/libc/stdio/fscanf.c b/lib/libc/stdio/fscanf.c index 720e4a5a09..7cb4519eb7 100644 --- a/lib/libc/stdio/fscanf.c +++ b/lib/libc/stdio/fscanf.c @@ -35,11 +35,13 @@ * * @(#)fscanf.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/fscanf.c,v 1.7 1999/08/28 00:01:04 peter Exp $ - * $DragonFly: src/lib/libc/stdio/fscanf.c,v 1.3 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/fscanf.c,v 1.4 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include #include +#include "un-namespace.h" #include "libc_private.h" int diff --git a/lib/libc/stdio/fseek.c b/lib/libc/stdio/fseek.c index 4879e4223e..204b96e781 100644 --- a/lib/libc/stdio/fseek.c +++ b/lib/libc/stdio/fseek.c @@ -35,15 +35,17 @@ * * @(#)fseek.c 8.3 (Berkeley) 1/2/94 * $FreeBSD: src/lib/libc/stdio/fseek.c,v 1.9.2.1 2001/03/05 10:56:58 obrien Exp $ - * $DragonFly: src/lib/libc/stdio/fseek.c,v 1.5 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/fseek.c,v 1.6 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include #include #include #include #include #include +#include "un-namespace.h" #include "local.h" #include "libc_private.h" @@ -55,12 +57,30 @@ fseek(FILE *fp, long offset, int whence) return (fseeko(fp, offset, whence)); } +int +fseeko(fp, offset, whence) + FILE *fp; + off_t offset; + int whence; +{ + int ret; + + /* make sure stdio is set up */ + if (!__sdidinit) + __sinit(); + + FLOCKFILE(fp); + ret = _fseeko(fp, offset, whence); + FUNLOCKFILE(fp); + return (ret); +} + /* * Seek the given file to the given offset. * `Whence' must be one of the three SEEK_* macros. */ int -fseeko(FILE *fp, off_t offset, int whence) +_fseeko(FILE *fp, off_t offset, int whence) { fpos_t (*seekfn) (void *, fpos_t, int); fpos_t target, curoff; @@ -68,17 +88,11 @@ fseeko(FILE *fp, off_t offset, int whence) struct stat st; int havepos; - /* make sure stdio is set up */ - if (!__sdidinit) - __sinit(); - - FLOCKFILE(fp); /* * Have to be able to seek. */ if ((seekfn = fp->_seek) == NULL) { errno = ESPIPE; /* historic practice */ - FUNLOCKFILE(fp); return (EOF); } @@ -99,7 +113,6 @@ fseeko(FILE *fp, off_t offset, int whence) else { curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR); if (curoff == -1) { - FUNLOCKFILE(fp); return (EOF); } } @@ -123,7 +136,6 @@ fseeko(FILE *fp, off_t offset, int whence) default: errno = EINVAL; - FUNLOCKFILE(fp); return (EOF); } @@ -141,7 +153,7 @@ fseeko(FILE *fp, off_t offset, int whence) goto dumb; if ((fp->_flags & __SOPT) == 0) { if (seekfn != __sseek || - fp->_file < 0 || fstat(fp->_file, &st) || + fp->_file < 0 || _fstat(fp->_file, &st) || (st.st_mode & S_IFMT) != S_IFREG) { fp->_flags |= __SNPT; goto dumb; @@ -157,7 +169,7 @@ fseeko(FILE *fp, off_t offset, int whence) if (whence == SEEK_SET) target = offset; else { - if (fstat(fp->_file, &st)) + if (_fstat(fp->_file, &st)) goto dumb; target = st.st_size + offset; } @@ -207,7 +219,6 @@ fseeko(FILE *fp, off_t offset, int whence) if (HASUB(fp)) FREEUB(fp); fp->_flags &= ~__SEOF; - FUNLOCKFILE(fp); return (0); } @@ -234,7 +245,6 @@ fseeko(FILE *fp, off_t offset, int whence) fp->_p += n; fp->_r -= n; } - FUNLOCKFILE(fp); return (0); /* @@ -244,7 +254,6 @@ fseeko(FILE *fp, off_t offset, int whence) dumb: if (__sflush(fp) || (*seekfn)(fp->_cookie, (fpos_t)offset, whence) == POS_ERR) { - FUNLOCKFILE(fp); return (EOF); } /* success: clear EOF indicator and discard ungetc() data */ @@ -254,6 +263,5 @@ dumb: fp->_r = 0; /* fp->_w = 0; */ /* unnecessary (I think...) */ fp->_flags &= ~__SEOF; - FUNLOCKFILE(fp); return (0); } diff --git a/lib/libc/stdio/ftell.c b/lib/libc/stdio/ftell.c index 1633de5616..5f1e755149 100644 --- a/lib/libc/stdio/ftell.c +++ b/lib/libc/stdio/ftell.c @@ -35,12 +35,14 @@ * * @(#)ftell.c 8.2 (Berkeley) 5/4/95 * $FreeBSD: src/lib/libc/stdio/ftell.c,v 1.11 1999/08/28 00:01:06 peter Exp $ - * $DragonFly: src/lib/libc/stdio/ftell.c,v 1.4 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/ftell.c,v 1.5 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include #include #include +#include "un-namespace.h" #include "local.h" #include "libc_private.h" diff --git a/lib/libc/stdio/fvwrite.c b/lib/libc/stdio/fvwrite.c index 2623dd0e03..af16b2b20d 100644 --- a/lib/libc/stdio/fvwrite.c +++ b/lib/libc/stdio/fvwrite.c @@ -35,7 +35,7 @@ * * @(#)fvwrite.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/fvwrite.c,v 1.10 1999/08/28 00:01:06 peter Exp $ - * $DragonFly: src/lib/libc/stdio/fvwrite.c,v 1.5 2004/06/08 04:04:11 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/fvwrite.c,v 1.6 2005/01/31 22:29:40 dillon Exp $ */ #include @@ -140,7 +140,7 @@ __sfvwrite(FILE *fp, struct __suio *uio) COPY(w); /* fp->_w -= w; */ /* unneeded */ fp->_p += w; - if (fflush(fp)) + if (__fflush(fp)) goto err; } else if (len >= (w = fp->_bf._size)) { /* write directly */ @@ -180,7 +180,7 @@ __sfvwrite(FILE *fp, struct __suio *uio) COPY(w); /* fp->_w -= w; */ fp->_p += w; - if (fflush(fp)) + if (__fflush(fp)) goto err; } else if (s >= (w = fp->_bf._size)) { w = (*fp->_write)(fp->_cookie, p, w); @@ -194,7 +194,7 @@ __sfvwrite(FILE *fp, struct __suio *uio) } if ((nldist -= w) == 0) { /* copied the newline: flush and forget */ - if (fflush(fp)) + if (__fflush(fp)) goto err; nlknown = 0; } diff --git a/lib/libc/stdio/fwalk.c b/lib/libc/stdio/fwalk.c index 90e9c3765f..80d9bb99d3 100644 --- a/lib/libc/stdio/fwalk.c +++ b/lib/libc/stdio/fwalk.c @@ -35,10 +35,12 @@ * * @(#)fwalk.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/fwalk.c,v 1.6.2.1 2001/03/05 11:27:49 obrien Exp $ - * $DragonFly: src/lib/libc/stdio/fwalk.c,v 1.3 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/fwalk.c,v 1.4 2005/01/31 22:29:40 dillon Exp $ */ #include +#include +#include #include "local.h" #include "glue.h" @@ -50,6 +52,11 @@ _fwalk(int (*function)(FILE *)) struct glue *g; ret = 0; + /* + * It should be safe to walk the list without locking it; + * new nodes are only added to the end and none are ever + * removed. + */ for (g = &__sglue; g != NULL; g = g->next) for (fp = g->iobs, n = g->niobs; --n >= 0; fp++) if (fp->_flags != 0) diff --git a/lib/libc/stdio/fwrite.c b/lib/libc/stdio/fwrite.c index c83ce422ec..09930ab6d6 100644 --- a/lib/libc/stdio/fwrite.c +++ b/lib/libc/stdio/fwrite.c @@ -35,10 +35,12 @@ * * @(#)fwrite.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/fwrite.c,v 1.7 1999/08/28 00:01:07 peter Exp $ - * $DragonFly: src/lib/libc/stdio/fwrite.c,v 1.3 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/fwrite.c,v 1.4 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include +#include "un-namespace.h" #include "local.h" #include "fvwrite.h" #include "libc_private.h" diff --git a/lib/libc/stdio/getc.c b/lib/libc/stdio/getc.c index a4fd461924..a724c6b9b2 100644 --- a/lib/libc/stdio/getc.c +++ b/lib/libc/stdio/getc.c @@ -35,17 +35,14 @@ * * @(#)getc.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/getc.c,v 1.7.2.1 2001/03/05 11:27:49 obrien Exp $ - * $DragonFly: src/lib/libc/stdio/getc.c,v 1.2 2003/06/17 04:26:46 dillon Exp $ + * $DragonFly: src/lib/libc/stdio/getc.c,v 1.3 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include +#include "un-namespace.h" #include "libc_private.h" -/* - * A subroutine version of the macro getc. - */ -#undef getc - int getc(FILE *fp) { diff --git a/lib/libc/stdio/getchar.c b/lib/libc/stdio/getchar.c index e062a8c16a..6c1a3021c3 100644 --- a/lib/libc/stdio/getchar.c +++ b/lib/libc/stdio/getchar.c @@ -35,13 +35,15 @@ * * @(#)getchar.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/getchar.c,v 1.7 1999/08/28 00:01:09 peter Exp $ - * $DragonFly: src/lib/libc/stdio/getchar.c,v 1.3 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/getchar.c,v 1.4 2005/01/31 22:29:40 dillon Exp $ */ /* * A subroutine version of the macro getchar. */ +#include "namespace.h" #include +#include "un-namespace.h" #include "libc_private.h" #undef getchar diff --git a/lib/libc/stdio/gets.c b/lib/libc/stdio/gets.c index 605d6ece38..1655e2c8da 100644 --- a/lib/libc/stdio/gets.c +++ b/lib/libc/stdio/gets.c @@ -35,12 +35,14 @@ * * @(#)gets.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/gets.c,v 1.9 2000/01/27 23:06:45 jasone Exp $ - * $DragonFly: src/lib/libc/stdio/gets.c,v 1.4 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/gets.c,v 1.5 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include #include #include +#include "un-namespace.h" __warn_references(gets, "warning: this program uses gets(), which is unsafe."); diff --git a/lib/libc/stdio/glue.h b/lib/libc/stdio/glue.h index 5dcdafff18..bd6e94e9fb 100644 --- a/lib/libc/stdio/glue.h +++ b/lib/libc/stdio/glue.h @@ -33,7 +33,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)glue.h 8.1 (Berkeley) 6/4/93 + * @(#)glue.h 8.1 (Berkeley) 6/4/93 + * $DragonFly: src/lib/libc/stdio/Attic/glue.h,v 1.2 2005/01/31 22:29:40 dillon Exp $ */ /* @@ -44,4 +45,6 @@ struct glue { struct glue *next; int niobs; FILE *iobs; -} __sglue; +}; + +extern struct glue __sglue; diff --git a/lib/libc/stdio/local.h b/lib/libc/stdio/local.h index 95619297b6..1b428ed643 100644 --- a/lib/libc/stdio/local.h +++ b/lib/libc/stdio/local.h @@ -36,9 +36,11 @@ * @(#)local.h 8.3 (Berkeley) 7/3/94 * * $FreeBSD: src/lib/libc/stdio/local.h,v 1.1.1.2.6.1 2001/03/05 11:27:49 obrien Exp $ - * $DragonFly: src/lib/libc/stdio/local.h,v 1.4 2003/11/12 20:21:25 eirikn Exp $ + * $DragonFly: src/lib/libc/stdio/local.h,v 1.5 2005/01/31 22:29:40 dillon Exp $ */ +#include /* for off_t */ + #ifndef _MACHINE_STDINT_H_ #include /* __size_t */ #endif diff --git a/lib/libc/stdio/makebuf.c b/lib/libc/stdio/makebuf.c index 738f6b55e2..9d41957894 100644 --- a/lib/libc/stdio/makebuf.c +++ b/lib/libc/stdio/makebuf.c @@ -34,24 +34,26 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/stdio/makebuf.c,v 1.1.1.1.14.1 2001/03/05 11:27:49 obrien Exp $ - * $DragonFly: src/lib/libc/stdio/makebuf.c,v 1.4 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/makebuf.c,v 1.5 2005/01/31 22:29:40 dillon Exp $ * * @(#)makebuf.c 8.1 (Berkeley) 6/4/93 */ +#include "namespace.h" #include #include #include #include #include #include "local.h" +#include "un-namespace.h" /* * Allocate a file buffer, or switch to unbuffered I/O. * Per the ANSI C standard, ALL tty devices default to line buffered. * * As a side effect, we set __SOPT or __SNPT (en/dis-able fseek - * optimisation) right after the fstat() that finds the buffer size. + * optimisation) right after the _fstat() that finds the buffer size. */ void __smakebuf(FILE *fp) @@ -90,7 +92,7 @@ __swhatbuf(FILE *fp, size_t *bufsize, int *couldbetty) { struct stat st; - if (fp->_file < 0 || fstat(fp->_file, &st) < 0) { + if (fp->_file < 0 || _fstat(fp->_file, &st) < 0) { *couldbetty = 0; *bufsize = BUFSIZ; return (__SNPT); diff --git a/lib/libc/stdio/mktemp.c b/lib/libc/stdio/mktemp.c index 68ed5666e3..cbc01019ff 100644 --- a/lib/libc/stdio/mktemp.c +++ b/lib/libc/stdio/mktemp.c @@ -32,9 +32,10 @@ * * @(#)mktemp.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/mktemp.c,v 1.19.2.3 2002/06/18 09:53:07 robert Exp $ - * $DragonFly: src/lib/libc/stdio/mktemp.c,v 1.5 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/mktemp.c,v 1.6 2005/01/31 22:29:40 dillon Exp $ */ +/* #include "namespace.h" */ #include #include #include @@ -44,6 +45,7 @@ #include #include #include +/* #include "un-namespace.h" */ char *_mktemp (char *); diff --git a/lib/libc/stdio/perror.c b/lib/libc/stdio/perror.c index 4c0c924599..e049e9a550 100644 --- a/lib/libc/stdio/perror.c +++ b/lib/libc/stdio/perror.c @@ -31,17 +31,19 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/stdio/perror.c,v 1.3.6.1 2001/03/05 11:27:49 obrien Exp $ - * $DragonFly: src/lib/libc/stdio/perror.c,v 1.4 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/perror.c,v 1.5 2005/01/31 22:29:40 dillon Exp $ * * @(#)perror.c 8.1 (Berkeley) 6/4/93 */ +#include "namespace.h" #include #include #include #include #include #include +#include "un-namespace.h" void perror(const char *s) @@ -63,5 +65,5 @@ perror(const char *s) v++; v->iov_base = "\n"; v->iov_len = 1; - (void)writev(STDERR_FILENO, iov, (v - iov) + 1); + (void)_writev(STDERR_FILENO, iov, (v - iov) + 1); } diff --git a/lib/libc/stdio/putc.c b/lib/libc/stdio/putc.c index 4579438150..261387902e 100644 --- a/lib/libc/stdio/putc.c +++ b/lib/libc/stdio/putc.c @@ -35,17 +35,22 @@ * * @(#)putc.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/putc.c,v 1.7 1999/08/28 00:01:12 peter Exp $ - * $DragonFly: src/lib/libc/stdio/putc.c,v 1.4 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/putc.c,v 1.5 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include +#include "un-namespace.h" #include "libc_private.h" /* - * A subroutine version of the macro putc. + * putc has traditionally been a macro in . That is no + * longer true because POSIX requires it to be thread-safe. POSIX + * does define putc_unlocked() which is defined as a macro and is + * probably what you want to use instead. + * + * #undef putc */ -#undef putc - int putc(int c, FILE *fp) { diff --git a/lib/libc/stdio/putchar.c b/lib/libc/stdio/putchar.c index b7162da28b..0c85aad919 100644 --- a/lib/libc/stdio/putchar.c +++ b/lib/libc/stdio/putchar.c @@ -35,14 +35,22 @@ * * @(#)putchar.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/putchar.c,v 1.7 1999/08/28 00:01:12 peter Exp $ - * $DragonFly: src/lib/libc/stdio/putchar.c,v 1.4 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/putchar.c,v 1.5 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include +#include "un-namespace.h" #include "libc_private.h" -#undef putchar - +/* + * putchar has traditionally been a macro in . That is no + * longer true because POSIX requires it to be thread-safe. POSIX + * does define putchar_unlocked() which is defined as a macro and is + * probably what you want to use instead. + * + * #undef putchar + */ /* * A subroutine version of the macro putchar */ diff --git a/lib/libc/stdio/puts.c b/lib/libc/stdio/puts.c index 9edd9d2b6d..62eef31031 100644 --- a/lib/libc/stdio/puts.c +++ b/lib/libc/stdio/puts.c @@ -35,11 +35,13 @@ * * @(#)puts.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/puts.c,v 1.7 1999/08/28 00:01:12 peter Exp $ - * $DragonFly: src/lib/libc/stdio/puts.c,v 1.3 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/puts.c,v 1.4 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include #include +#include "un-namespace.h" #include "fvwrite.h" #include "libc_private.h" diff --git a/lib/libc/stdio/putw.c b/lib/libc/stdio/putw.c index 2f6eedda5a..5bfb542219 100644 --- a/lib/libc/stdio/putw.c +++ b/lib/libc/stdio/putw.c @@ -35,10 +35,12 @@ * * @(#)putw.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/putw.c,v 1.7 1999/08/28 00:01:13 peter Exp $ - * $DragonFly: src/lib/libc/stdio/putw.c,v 1.3 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/putw.c,v 1.4 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include +#include "un-namespace.h" #include "fvwrite.h" #include "libc_private.h" diff --git a/lib/libc/stdio/refill.c b/lib/libc/stdio/refill.c index 8744bdc479..a71112dda5 100644 --- a/lib/libc/stdio/refill.c +++ b/lib/libc/stdio/refill.c @@ -35,12 +35,13 @@ * * @(#)refill.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/refill.c,v 1.8.2.1 2001/03/05 11:27:49 obrien Exp $ - * $DragonFly: src/lib/libc/stdio/refill.c,v 1.5 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/refill.c,v 1.6 2005/01/31 22:29:40 dillon Exp $ */ #include #include #include + #include "local.h" static int lflush (FILE *); diff --git a/lib/libc/stdio/rewind.c b/lib/libc/stdio/rewind.c index 32341efadd..33c976e32d 100644 --- a/lib/libc/stdio/rewind.c +++ b/lib/libc/stdio/rewind.c @@ -35,18 +35,21 @@ * * @(#)rewind.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/rewind.c,v 1.7.2.1 2001/03/05 11:27:49 obrien Exp $ - * $DragonFly: src/lib/libc/stdio/rewind.c,v 1.2 2003/06/17 04:26:46 dillon Exp $ + * $DragonFly: src/lib/libc/stdio/rewind.c,v 1.3 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include #include +#include "un-namespace.h" #include "libc_private.h" +#include "local.h" void rewind(FILE *fp) { FLOCKFILE(fp); - (void) fseek(fp, 0L, SEEK_SET); + (void)_fseeko(fp, 0L, SEEK_SET); clearerr(fp); FUNLOCKFILE(fp); errno = 0; /* not required, but seems reasonable */ diff --git a/lib/libc/stdio/scanf.c b/lib/libc/stdio/scanf.c index 9026e47b91..9e0686e3f7 100644 --- a/lib/libc/stdio/scanf.c +++ b/lib/libc/stdio/scanf.c @@ -35,11 +35,13 @@ * * @(#)scanf.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/scanf.c,v 1.7 1999/08/28 00:01:15 peter Exp $ - * $DragonFly: src/lib/libc/stdio/scanf.c,v 1.3 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/scanf.c,v 1.4 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include #include +#include "un-namespace.h" #include "libc_private.h" int diff --git a/lib/libc/stdio/setvbuf.c b/lib/libc/stdio/setvbuf.c index 8b394ab81a..135a7df2cc 100644 --- a/lib/libc/stdio/setvbuf.c +++ b/lib/libc/stdio/setvbuf.c @@ -35,11 +35,13 @@ * * @(#)setvbuf.c 8.2 (Berkeley) 11/16/93 * $FreeBSD: src/lib/libc/stdio/setvbuf.c,v 1.7 1999/08/28 00:01:16 peter Exp $ - * $DragonFly: src/lib/libc/stdio/setvbuf.c,v 1.4 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/setvbuf.c,v 1.5 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include #include +#include "un-namespace.h" #include "local.h" #include "libc_private.h" diff --git a/lib/libc/stdio/stdio.c b/lib/libc/stdio/stdio.c index 1e819e1a4d..c9ecf4338d 100644 --- a/lib/libc/stdio/stdio.c +++ b/lib/libc/stdio/stdio.c @@ -35,12 +35,14 @@ * * @(#)stdio.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/stdio.c,v 1.9 2000/01/27 23:06:46 jasone Exp $ - * $DragonFly: src/lib/libc/stdio/stdio.c,v 1.4 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/stdio.c,v 1.5 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include #include #include +#include "un-namespace.h" #include "local.h" /* diff --git a/lib/libc/stdio/tmpfile.c b/lib/libc/stdio/tmpfile.c index b8e571bf05..c2036f1475 100644 --- a/lib/libc/stdio/tmpfile.c +++ b/lib/libc/stdio/tmpfile.c @@ -34,11 +34,12 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/stdio/tmpfile.c,v 1.4.2.2 2003/02/15 05:34:52 kris Exp $ - * $DragonFly: src/lib/libc/stdio/tmpfile.c,v 1.2 2003/06/17 04:26:46 dillon Exp $ + * $DragonFly: src/lib/libc/stdio/tmpfile.c,v 1.3 2005/01/31 22:29:40 dillon Exp $ * * @(#)tmpfile.c 8.1 (Berkeley) 6/4/93 */ +#include "namespace.h" #include #include #include @@ -47,6 +48,7 @@ #include #include #include +#include "un-namespace.h" FILE * tmpfile() @@ -70,7 +72,7 @@ tmpfile() return (NULL); sigfillset(&set); - (void)sigprocmask(SIG_BLOCK, &set, &oset); + (void)_sigprocmask(SIG_BLOCK, &set, &oset); fd = mkstemp(buf); if (fd != -1) @@ -78,7 +80,7 @@ tmpfile() free(buf); - (void)sigprocmask(SIG_SETMASK, &oset, NULL); + (void)_sigprocmask(SIG_SETMASK, &oset, NULL); if (fd == -1) return (NULL); diff --git a/lib/libc/stdio/ungetc.c b/lib/libc/stdio/ungetc.c index 5ac7348a63..c266370439 100644 --- a/lib/libc/stdio/ungetc.c +++ b/lib/libc/stdio/ungetc.c @@ -35,12 +35,14 @@ * * @(#)ungetc.c 8.2 (Berkeley) 11/3/93 * $FreeBSD: src/lib/libc/stdio/ungetc.c,v 1.7.2.1 2001/03/05 11:27:49 obrien Exp $ - * $DragonFly: src/lib/libc/stdio/ungetc.c,v 1.3 2003/11/12 20:21:25 eirikn Exp $ + * $DragonFly: src/lib/libc/stdio/ungetc.c,v 1.4 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include #include #include +#include "un-namespace.h" #include "local.h" #include "libc_private.h" @@ -84,26 +86,42 @@ __submore(FILE *fp) return (0); } +/* + * MT-safe version + */ int ungetc(int c, FILE *fp) { + int ret; + if (c == EOF) return (EOF); if (!__sdidinit) __sinit(); FLOCKFILE(fp); + ret = __ungetc(c, fp); + FUNLOCKFILE(fp); + return(ret); +} + +/* + * Non-MT-safe version + */ +int +__ungetc(int c, FILE *fp) +{ + if (c == EOF) + return(EOF); if ((fp->_flags & __SRD) == 0) { /* * Not already reading: no good unless reading-and-writing. * Otherwise, flush any current write stuff. */ if ((fp->_flags & __SRW) == 0) { - FUNLOCKFILE(fp); return (EOF); } if (fp->_flags & __SWR) { if (__sflush(fp)) { - FUNLOCKFILE(fp); return (EOF); } fp->_flags &= ~__SWR; @@ -120,12 +138,10 @@ ungetc(int c, FILE *fp) */ if (HASUB(fp)) { if (fp->_r >= fp->_ub._size && __submore(fp)) { - FUNLOCKFILE(fp); return (EOF); } *--fp->_p = c; fp->_r++; - FUNLOCKFILE(fp); return (c); } fp->_flags &= ~__SEOF; @@ -139,7 +155,6 @@ ungetc(int c, FILE *fp) fp->_p[-1] == c) { fp->_p--; fp->_r++; - FUNLOCKFILE(fp); return (c); } @@ -154,6 +169,5 @@ ungetc(int c, FILE *fp) fp->_ubuf[sizeof(fp->_ubuf) - 1] = c; fp->_p = &fp->_ubuf[sizeof(fp->_ubuf) - 1]; fp->_r = 1; - FUNLOCKFILE(fp); return (c); } diff --git a/lib/libc/stdio/vasprintf.c b/lib/libc/stdio/vasprintf.c index 2644c9e0dd..483a1c1293 100644 --- a/lib/libc/stdio/vasprintf.c +++ b/lib/libc/stdio/vasprintf.c @@ -27,13 +27,14 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * $FreeBSD: src/lib/libc/stdio/vasprintf.c,v 1.11 1999/08/28 00:01:19 peter Exp $ - * $DragonFly: src/lib/libc/stdio/vasprintf.c,v 1.3 2003/11/09 02:34:02 dillon Exp $ + * $DragonFly: src/lib/libc/stdio/vasprintf.c,v 1.4 2005/01/31 22:29:40 dillon Exp $ */ #include #include #include #include +#include "local.h" int vasprintf(char **str, const char *fmt, va_list ap) @@ -50,7 +51,7 @@ vasprintf(char **str, const char *fmt, va_list ap) return (-1); } f._bf._size = f._w = 127; /* Leave room for the NULL */ - ret = vfprintf(&f, fmt, ap); + ret = __vfprintf(&f, fmt, ap); *f._p = '\0'; f._bf._base = reallocf(f._bf._base, f._bf._size + 1); if (f._bf._base == NULL) { diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c index df0b58becb..8bc8cb97d3 100644 --- a/lib/libc/stdio/vfprintf.c +++ b/lib/libc/stdio/vfprintf.c @@ -35,7 +35,7 @@ * * @(#)vfprintf.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/vfprintf.c,v 1.22.2.5 2002/10/12 10:46:37 schweikh Exp $ - * $DragonFly: src/lib/libc/stdio/vfprintf.c,v 1.5 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/vfprintf.c,v 1.6 2005/01/31 22:29:40 dillon Exp $ */ /* @@ -44,6 +44,7 @@ * This code is large and complicated... */ +#include "namespace.h" #include #include @@ -52,6 +53,7 @@ #include #include +#include "un-namespace.h" #include "libc_private.h" #include "local.h" @@ -110,8 +112,8 @@ __sbprintf(FILE *fp, const char *fmt, va_list ap) fake._lbfsize = 0; /* not actually used, but Just In Case */ /* do the work, then copy any error status */ - ret = vfprintf(&fake, fmt, ap); - if (ret >= 0 && fflush(&fake)) + ret = __vfprintf(&fake, fmt, ap); + if (ret >= 0 && __fflush(&fake)) ret = EOF; if (fake._flags & __SERR) fp->_flags |= __SERR; @@ -236,6 +238,20 @@ __uqtoa(u_quad_t val, char *endp, int base, int octzero, char *xdigs) return (cp); } +/* + * MT-safe version + */ +int +vfprintf(FILE *fp, const char *fmt0, va_list ap) +{ + int ret; + + FLOCKFILE(fp); + ret = __vfprintf(fp, fmt0, ap); + FUNLOCKFILE(fp); + return (ret); +} + #ifdef FLOATING_POINT #include #include @@ -267,8 +283,11 @@ static int exponent (char *, int, int); #define SHORTINT 0x040 /* short integer */ #define ZEROPAD 0x080 /* zero (as opposed to blank) pad */ #define FPT 0x100 /* Floating point number */ +/* + * Non-MT-safe version + */ int -vfprintf(FILE *fp, const char *fmt0, va_list ap) +__vfprintf(FILE *fp, const char *fmt0, va_list ap) { char *fmt; /* format string */ int ch; /* character from fmt */ @@ -400,17 +419,14 @@ vfprintf(FILE *fp, const char *fmt0, va_list ap) #ifdef FLOATING_POINT dtoaresult = NULL; #endif - FLOCKFILE(fp); /* sorry, fprintf(read_only_file, "") returns EOF, not 0 */ if (cantwrite(fp)) { - FUNLOCKFILE(fp); return (EOF); } /* optimise fprintf(stderr) (and other unbuffered Unix files) */ if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) && fp->_file >= 0) { - FUNLOCKFILE(fp); return (__sbprintf(fp, fmt0, ap)); } @@ -856,7 +872,6 @@ error: #endif if (__sferror(fp)) ret = EOF; - FUNLOCKFILE(fp); if ((argtable != NULL) && (argtable != statargtable)) free (argtable); return (ret); diff --git a/lib/libc/stdio/vfscanf.c b/lib/libc/stdio/vfscanf.c index a6364ba599..ff73dbefb0 100644 --- a/lib/libc/stdio/vfscanf.c +++ b/lib/libc/stdio/vfscanf.c @@ -35,16 +35,19 @@ * * @(#)vfscanf.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: /repoman/r/ncvs/src/lib/libc/stdio/vfscanf.c,v 1.35 2004/01/31 23:16:09 das Exp $ - * $DragonFly: src/lib/libc/stdio/vfscanf.c,v 1.5 2004/07/08 17:56:46 cpressey Exp $ + * $DragonFly: src/lib/libc/stdio/vfscanf.c,v 1.6 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include #include #include #include #include +#include "un-namespace.h" #include "collate.h" +#include "libc_private.h" #include "local.h" #define FLOATING_POINT @@ -97,7 +100,21 @@ static u_char *__sccl(char *, u_char *); /* - * vfscanf + * __vfscanf MT-safe version + */ +int +__vfscanf(FILE *fp, char const *fmt0, va_list ap) +{ + int ret; + + FLOCKFILE(fp); + ret = __svfscanf(fp, fmt0, ap); + FUNLOCKFILE(fp); + return (ret); +} + +/* + * __svfscanf - non-MT-safe version of __vfscanf */ int __svfscanf(FILE *fp, char const *fmt0, va_list ap) @@ -541,13 +558,13 @@ literal: */ if (flags & NDIGITS) { if (p > buf) - (void) ungetc(*(u_char *)--p, fp); + (void)__ungetc(*(u_char *)--p, fp); goto match_failure; } c = ((u_char *)p)[-1]; if (c == 'x' || c == 'X') { --p; - (void) ungetc(c, fp); + (void)__ungetc(c, fp); } if ((flags & SUPPRESS) == 0) { u_quad_t res; @@ -638,16 +655,16 @@ literal: if (flags & EXPOK) { /* no digits at all */ while (p > buf) - ungetc(*(u_char *)--p, fp); + __ungetc(*(u_char *)--p, fp); goto match_failure; } /* just a bad exponent (e and maybe sign) */ c = *(u_char *)--p; if (c != 'e' && c != 'E') { - (void) ungetc(c, fp);/* sign */ + (void)__ungetc(c, fp);/* sign */ c = *(u_char *)--p; } - (void) ungetc(c, fp); + (void)__ungetc(c, fp); } if ((flags & SUPPRESS) == 0) { double res; diff --git a/lib/libc/stdio/vscanf.c b/lib/libc/stdio/vscanf.c index 969666d31e..8d23170906 100644 --- a/lib/libc/stdio/vscanf.c +++ b/lib/libc/stdio/vscanf.c @@ -35,11 +35,13 @@ * * @(#)vscanf.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/vscanf.c,v 1.7 1999/08/28 00:01:21 peter Exp $ - * $DragonFly: src/lib/libc/stdio/vscanf.c,v 1.3 2003/11/09 02:34:02 dillon Exp $ + * $DragonFly: src/lib/libc/stdio/vscanf.c,v 1.4 2005/01/31 22:29:40 dillon Exp $ */ +#include "namespace.h" #include #include +#include "un-namespace.h" #include "libc_private.h" int diff --git a/lib/libc/stdio/vsnprintf.c b/lib/libc/stdio/vsnprintf.c index 010118541a..d4c75fdd77 100644 --- a/lib/libc/stdio/vsnprintf.c +++ b/lib/libc/stdio/vsnprintf.c @@ -35,12 +35,13 @@ * * @(#)vsnprintf.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/vsnprintf.c,v 1.12.2.1 2002/09/23 06:58:17 maxim Exp $ - * $DragonFly: src/lib/libc/stdio/vsnprintf.c,v 1.3 2003/11/09 02:34:02 dillon Exp $ + * $DragonFly: src/lib/libc/stdio/vsnprintf.c,v 1.4 2005/01/31 22:29:40 dillon Exp $ */ #include #include #include +#include "local.h" int vsnprintf(char *str, size_t n, const char *fmt, va_list ap) @@ -64,7 +65,7 @@ vsnprintf(char *str, size_t n, const char *fmt, va_list ap) f._flags = __SWR | __SSTR; f._bf._base = f._p = (unsigned char *)str; f._bf._size = f._w = n; - ret = vfprintf(&f, fmt, ap); + ret = __vfprintf(&f, fmt, ap); if (on > 0) *f._p = '\0'; return (ret); diff --git a/lib/libc/stdio/vsprintf.c b/lib/libc/stdio/vsprintf.c index 0a7ce29f71..8739ab1ec9 100644 --- a/lib/libc/stdio/vsprintf.c +++ b/lib/libc/stdio/vsprintf.c @@ -35,12 +35,13 @@ * * @(#)vsprintf.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/vsprintf.c,v 1.6 1999/08/28 00:01:21 peter Exp $ - * $DragonFly: src/lib/libc/stdio/vsprintf.c,v 1.3 2003/11/09 02:34:02 dillon Exp $ + * $DragonFly: src/lib/libc/stdio/vsprintf.c,v 1.4 2005/01/31 22:29:40 dillon Exp $ */ #include #include #include +#include "local.h" int vsprintf(char *str, const char *fmt, va_list ap) @@ -52,7 +53,7 @@ vsprintf(char *str, const char *fmt, va_list ap) f._flags = __SWR | __SSTR; f._bf._base = f._p = (unsigned char *)str; f._bf._size = f._w = INT_MAX; - ret = vfprintf(&f, fmt, ap); + ret = __vfprintf(&f, fmt, ap); *f._p = 0; return (ret); } diff --git a/lib/libc/stdio/wbuf.c b/lib/libc/stdio/wbuf.c index 9dac5a394e..04034b9a28 100644 --- a/lib/libc/stdio/wbuf.c +++ b/lib/libc/stdio/wbuf.c @@ -35,7 +35,7 @@ * * @(#)wbuf.c 8.1 (Berkeley) 6/4/93 * $FreeBSD: src/lib/libc/stdio/wbuf.c,v 1.6 1999/08/28 00:01:22 peter Exp $ - * $DragonFly: src/lib/libc/stdio/wbuf.c,v 1.4 2004/06/07 20:35:41 hmp Exp $ + * $DragonFly: src/lib/libc/stdio/wbuf.c,v 1.5 2005/01/31 22:29:40 dillon Exp $ */ #include @@ -45,6 +45,8 @@ * Write the given character into the (probably full) buffer for * the given file. Flush the buffer out if it is or becomes full, * or if c=='\n' and the file is line buffered. + * + * Non-MT-safe */ int __swbuf(int c, FILE *fp) @@ -74,14 +76,14 @@ __swbuf(int c, FILE *fp) */ n = fp->_p - fp->_bf._base; if (n >= fp->_bf._size) { - if (fflush(fp)) + if (__fflush(fp)) return (EOF); n = 0; } fp->_w--; *fp->_p++ = c; if (++n == fp->_bf._size || (fp->_flags & __SLBF && c == '\n')) - if (fflush(fp)) + if (__fflush(fp)) return (EOF); return (c); } diff --git a/lib/libc/stdlib/abort.c b/lib/libc/stdlib/abort.c index bee10d3e3c..7ad5edd540 100644 --- a/lib/libc/stdlib/abort.c +++ b/lib/libc/stdlib/abort.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/stdlib/abort.c,v 1.5.6.2 2002/10/15 19:46:46 fjoe Exp $ - * $DragonFly: src/lib/libc/stdlib/abort.c,v 1.2 2003/06/17 04:26:46 dillon Exp $ + * $DragonFly: src/lib/libc/stdlib/abort.c,v 1.3 2005/01/31 22:29:42 dillon Exp $ * * @(#)abort.c 8.1 (Berkeley) 6/4/93 */ @@ -40,17 +40,18 @@ #include #include #include -#ifdef _THREAD_SAFE #include -#include "pthread_private.h" -#endif void (*__cleanup)(); +extern int __sys_sigprocmask(int, const sigset_t *, sigset_t *); +extern int __sys_sigaction(int, const struct sigaction *, + struct sigaction *); + void abort() { - sigset_t mask; + struct sigaction act; /* * POSIX requires we flush stdio buffers on abort @@ -58,29 +59,26 @@ abort() if (__cleanup) (*__cleanup)(); - sigfillset(&mask); + sigfillset(&act.sa_mask); /* * don't block SIGABRT to give any handler a chance; we ignore * any errors -- X311J doesn't allow abort to return anyway. */ - sigdelset(&mask, SIGABRT); -#ifdef _THREAD_SAFE - (void) __sys_sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL); -#else - (void)sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL); -#endif + sigdelset(&act.sa_mask, SIGABRT); + (void)__sys_sigprocmask(SIG_SETMASK, &act.sa_mask, NULL); (void)kill(getpid(), SIGABRT); /* * if SIGABRT ignored, or caught and the handler returns, do * it again, only harder. */ - (void)signal(SIGABRT, SIG_DFL); -#ifdef _THREAD_SAFE - (void) __sys_sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL); -#else - (void)sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL); -#endif + act.sa_handler = SIG_DFL; + act.sa_flags = 0; + sigfillset(&act.sa_mask); + (void)__sys_sigaction(SIGABRT, &act, NULL); + sigdelset(&act.sa_mask, SIGABRT); + (void)__sys_sigprocmask(SIG_SETMASK, &act.sa_mask, NULL); (void)kill(getpid(), SIGABRT); exit(1); } + diff --git a/lib/libc/stdlib/exit.c b/lib/libc/stdlib/exit.c index 34f5853473..f0783e3746 100644 --- a/lib/libc/stdlib/exit.c +++ b/lib/libc/stdlib/exit.c @@ -31,13 +31,15 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/stdlib/exit.c,v 1.3.6.1 2001/03/05 11:33:57 obrien Exp $ - * $DragonFly: src/lib/libc/stdlib/exit.c,v 1.6 2005/01/05 11:51:18 joerg Exp $ + * $DragonFly: src/lib/libc/stdlib/exit.c,v 1.7 2005/01/31 22:29:42 dillon Exp $ * * @(#)exit.c 8.1 (Berkeley) 6/4/93 */ +#include "namespace.h" #include #include +#include "un-namespace.h" #include "atexit.h" void (*__cleanup)(); @@ -58,11 +60,10 @@ void exit(status) int status; { -#ifdef _THREAD_SAFE - extern int _thread_autoinit_dummy_decl; /* Ensure that the auto-initialization routine is linked in: */ + extern int _thread_autoinit_dummy_decl; + _thread_autoinit_dummy_decl = 1; -#endif __cxa_finalize(NULL); diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c index 09f97ed3c8..1907f39289 100644 --- a/lib/libc/stdlib/malloc.c +++ b/lib/libc/stdlib/malloc.c @@ -7,7 +7,7 @@ * ---------------------------------------------------------------------------- * * $FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.49.2.4 2001/12/29 08:10:14 knu Exp $ - * $DragonFly: src/lib/libc/stdlib/malloc.c,v 1.5 2004/02/03 07:34:10 dillon Exp $ + * $DragonFly: src/lib/libc/stdlib/malloc.c,v 1.6 2005/01/31 22:29:42 dillon Exp $ * */ @@ -43,6 +43,7 @@ * */ +#include "namespace.h" #if defined(__FreeBSD__) || defined(__DragonFly__) # if defined(__i386__) # define malloc_pageshift 12U @@ -98,6 +99,7 @@ #include #include #include +#include "un-namespace.h" /* * This structure describes a page worth of chunks. diff --git a/lib/libc/stdlib/random.c b/lib/libc/stdlib/random.c index 83384b1947..46367873ad 100644 --- a/lib/libc/stdlib/random.c +++ b/lib/libc/stdlib/random.c @@ -31,16 +31,18 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/stdlib/random.c,v 1.13 2000/01/27 23:06:49 jasone Exp $ - * $DragonFly: src/lib/libc/stdlib/random.c,v 1.5 2003/09/06 08:19:16 asmodai Exp $ + * $DragonFly: src/lib/libc/stdlib/random.c,v 1.6 2005/01/31 22:29:42 dillon Exp $ * * @(#)random.c 8.2 (Berkeley) 5/19/95 */ +#include "namespace.h" #include /* for srandomdev() */ #include /* for srandomdev() */ #include #include #include /* for srandomdev() */ +#include "un-namespace.h" /* * random.c: diff --git a/lib/libc/stdlib/realpath.c b/lib/libc/stdlib/realpath.c index fb5d0444c5..30f6bf0296 100644 --- a/lib/libc/stdlib/realpath.c +++ b/lib/libc/stdlib/realpath.c @@ -27,9 +27,10 @@ * * @(#)realpath.c 8.1 (Berkeley) 2/16/94 * $FreeBSD: src/lib/libc/stdlib/realpath.c,v 1.9.2.2 2003/06/02 13:31:16 fjoe Exp $ - * $DragonFly: src/lib/libc/stdlib/realpath.c,v 1.2 2003/06/17 04:26:46 dillon Exp $ + * $DragonFly: src/lib/libc/stdlib/realpath.c,v 1.3 2005/01/31 22:29:42 dillon Exp $ */ +#include "namespace.h" #include #include @@ -37,6 +38,7 @@ #include #include #include +#include "un-namespace.h" /* * char *realpath(const char *path, char resolved[PATH_MAX]); diff --git a/lib/libc/stdlib/system.c b/lib/libc/stdlib/system.c index 15a0040087..35261f8abd 100644 --- a/lib/libc/stdlib/system.c +++ b/lib/libc/stdlib/system.c @@ -31,11 +31,12 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/stdlib/system.c,v 1.5.2.2 2001/10/10 12:50:22 alfred Exp $ - * $DragonFly: src/lib/libc/stdlib/system.c,v 1.2 2003/06/17 04:26:46 dillon Exp $ + * $DragonFly: src/lib/libc/stdlib/system.c,v 1.3 2005/01/31 22:29:42 dillon Exp $ * * @(#)system.c 8.1 (Berkeley) 6/4/93 */ +#include "namespace.h" #include #include #include @@ -44,6 +45,8 @@ #include #include #include +#include "un-namespace.h" +#include "libc_private.h" int __system(command) @@ -64,11 +67,11 @@ __system(command) ign.sa_handler = SIG_IGN; (void)sigemptyset(&ign.sa_mask); ign.sa_flags = 0; - (void)sigaction(SIGINT, &ign, &intact); - (void)sigaction(SIGQUIT, &ign, &quitact); + (void)_sigaction(SIGINT, &ign, &intact); + (void)_sigaction(SIGQUIT, &ign, &quitact); (void)sigemptyset(&newsigblock); (void)sigaddset(&newsigblock, SIGCHLD); - (void)sigprocmask(SIG_BLOCK, &newsigblock, &oldsigblock); + (void)_sigprocmask(SIG_BLOCK, &newsigblock, &oldsigblock); switch(pid = fork()) { case -1: /* error */ break; @@ -76,9 +79,9 @@ __system(command) /* * Restore original signal dispositions and exec the command. */ - (void)sigaction(SIGINT, &intact, NULL); - (void)sigaction(SIGQUIT, &quitact, NULL); - (void)sigprocmask(SIG_SETMASK, &oldsigblock, NULL); + (void)_sigaction(SIGINT, &intact, NULL); + (void)_sigaction(SIGQUIT, &quitact, NULL); + (void)_sigprocmask(SIG_SETMASK, &oldsigblock, NULL); execl(_PATH_BSHELL, "sh", "-c", command, (char *)NULL); _exit(127); default: /* parent */ @@ -88,12 +91,11 @@ __system(command) } while (pid == -1 && errno == EINTR); break; } - (void)sigaction(SIGINT, &intact, NULL); - (void)sigaction(SIGQUIT, &quitact, NULL); - (void)sigprocmask(SIG_SETMASK, &oldsigblock, NULL); + (void)_sigaction(SIGINT, &intact, NULL); + (void)_sigaction(SIGQUIT, &quitact, NULL); + (void)_sigprocmask(SIG_SETMASK, &oldsigblock, NULL); return(pid == -1 ? -1 : pstat); } -#ifndef _THREAD_SAFE __weak_reference(__system, system); -#endif +__weak_reference(__system, _system); diff --git a/lib/libc/stdtime/asctime.c b/lib/libc/stdtime/asctime.c index 1ce2a3b4ae..b550fab498 100644 --- a/lib/libc/stdtime/asctime.c +++ b/lib/libc/stdtime/asctime.c @@ -3,7 +3,7 @@ ** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov). ** ** $FreeBSD: src/lib/libc/stdtime/asctime.c,v 1.7.6.1 2001/03/05 11:37:20 obrien Exp $ -** $DragonFly: src/lib/libc/stdtime/asctime.c,v 1.3 2004/10/25 19:38:02 drhodus Exp $ +** $DragonFly: src/lib/libc/stdtime/asctime.c,v 1.4 2005/01/31 22:29:44 dillon Exp $ */ /* @@ -11,7 +11,9 @@ */ /*LINTLIBRARY*/ +#include "namespace.h" #include "private.h" +#include "un-namespace.h" #include "tzfile.h" /* diff --git a/lib/libc/stdtime/difftime.c b/lib/libc/stdtime/difftime.c index 7f92116b9f..38531ca849 100644 --- a/lib/libc/stdtime/difftime.c +++ b/lib/libc/stdtime/difftime.c @@ -3,7 +3,7 @@ ** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov). ** ** $FreeBSD: src/lib/libc/stdtime/difftime.c,v 1.4.8.1 2001/03/05 11:37:21 obrien Exp $ -** $DragonFly: src/lib/libc/stdtime/difftime.c,v 1.2 2003/06/17 04:26:46 dillon Exp $ +** $DragonFly: src/lib/libc/stdtime/difftime.c,v 1.3 2005/01/31 22:29:44 dillon Exp $ */ /* @@ -11,7 +11,9 @@ */ /*LINTLIBRARY*/ +#include "namespace.h" #include "private.h" +#include "un-namespace.h" /* ** Algorithm courtesy Paul Eggert (eggert@twinsun.com). diff --git a/lib/libc/stdtime/localtime.c b/lib/libc/stdtime/localtime.c index 5261120486..5206620822 100644 --- a/lib/libc/stdtime/localtime.c +++ b/lib/libc/stdtime/localtime.c @@ -3,7 +3,7 @@ ** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov). ** ** $FreeBSD: src/lib/libc/stdtime/localtime.c,v 1.25.2.2 2002/08/13 16:08:07 bmilekic Exp $ -** $DragonFly: src/lib/libc/stdtime/localtime.c,v 1.3 2004/10/25 19:38:02 drhodus Exp $ +** $DragonFly: src/lib/libc/stdtime/localtime.c,v 1.4 2005/01/31 22:29:44 dillon Exp $ */ /* @@ -17,15 +17,21 @@ /*LINTLIBRARY*/ +#include "namespace.h" #include #include + +#include +#include #include "private.h" +#include + #include "tzfile.h" -#include "fcntl.h" -#ifdef _THREAD_SAFE -#include -#include "pthread_private.h" -#endif + +#include "libc_private.h" + +#define _MUTEX_LOCK(x) if (__isthreaded) _pthread_mutex_lock(x) +#define _MUTEX_UNLOCK(x) if (__isthreaded) _pthread_mutex_unlock(x) /* ** SunOS 4.1.1 headers lack O_BINARY. @@ -169,12 +175,8 @@ static struct state gmtmem; static char lcl_TZname[TZ_STRLEN_MAX + 1]; static int lcl_is_set; static int gmt_is_set; -#ifdef _THREAD_SAFE -static struct pthread_mutex _lcl_mutexd = PTHREAD_MUTEX_STATIC_INITIALIZER; -static struct pthread_mutex _gmt_mutexd = PTHREAD_MUTEX_STATIC_INITIALIZER; -static pthread_mutex_t lcl_mutex = &_lcl_mutexd; -static pthread_mutex_t gmt_mutex = &_gmt_mutexd; -#endif +static pthread_mutex_t lcl_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t gmt_mutex = PTHREAD_MUTEX_INITIALIZER; char * tzname[2] = { wildabbr, @@ -313,7 +315,7 @@ struct state * const sp; return -1; if ((fid = _open(name, OPEN_MODE)) == -1) return -1; - if ((fstat(fid, &stab) < 0) || !S_ISREG(stab.st_mode)) { + if ((_fstat(fid, &stab) < 0) || !S_ISREG(stab.st_mode)) { _close(fid); return -1; } @@ -928,20 +930,8 @@ struct state * const sp; (void) tzparse(gmt, sp, TRUE); } -#ifndef STD_INSPIRED -/* -** A non-static declaration of tzsetwall in a system header file -** may cause a warning about this upcoming static declaration... -*/ -static -#endif /* !defined STD_INSPIRED */ -#ifdef _THREAD_SAFE -void -tzsetwall_basic P((void)) -#else -void -tzsetwall P((void)) -#endif +static void +tzsetwall_basic(void) { if (lcl_is_set < 0) return; @@ -961,23 +951,16 @@ tzsetwall P((void)) settzname(); } -#ifdef _THREAD_SAFE void tzsetwall P((void)) { - pthread_mutex_lock(&lcl_mutex); + _MUTEX_LOCK(&lcl_mutex); tzsetwall_basic(); - pthread_mutex_unlock(&lcl_mutex); + _MUTEX_UNLOCK(&lcl_mutex); } -#endif -#ifdef _THREAD_SAFE static void -tzset_basic P((void)) -#else -void -tzset P((void)) -#endif +tzset_basic (void) { const char * name; @@ -1017,15 +1000,13 @@ tzset P((void)) settzname(); } -#ifdef _THREAD_SAFE void -tzset P((void)) +tzset(void) { - pthread_mutex_lock(&lcl_mutex); + _MUTEX_LOCK(&lcl_mutex); tzset_basic(); - pthread_mutex_unlock(&lcl_mutex); + _MUTEX_UNLOCK(&lcl_mutex); } -#endif /* ** The easy way to behave "as if no library function calls" localtime @@ -1088,14 +1069,10 @@ localtime_r(timep, p_tm) const time_t * const timep; struct tm *p_tm; { -#ifdef _THREAD_SAFE - pthread_mutex_lock(&lcl_mutex); -#endif + _MUTEX_LOCK(&lcl_mutex); tzset(); localsub(timep, 0L, p_tm); -#ifdef _THREAD_SAFE - pthread_mutex_unlock(&lcl_mutex); -#endif + _MUTEX_UNLOCK(&lcl_mutex); return(p_tm); } @@ -1103,36 +1080,36 @@ struct tm * localtime(timep) const time_t * const timep; { -#ifdef _THREAD_SAFE - static struct pthread_mutex _localtime_mutex = PTHREAD_MUTEX_STATIC_INITIALIZER; - static pthread_mutex_t localtime_mutex = &_localtime_mutex; + static pthread_mutex_t localtime_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_key_t localtime_key = -1; struct tm *p_tm; - pthread_mutex_lock(&localtime_mutex); - if (localtime_key < 0) { - if (pthread_key_create(&localtime_key, free) < 0) { - pthread_mutex_unlock(&localtime_mutex); - return(NULL); + if (__isthreaded != 0) { + _pthread_mutex_lock(&localtime_mutex); + if (localtime_key < 0) { + if (_pthread_key_create(&localtime_key, free) < 0) { + _pthread_mutex_unlock(&localtime_mutex); + return(NULL); + } } + _pthread_mutex_unlock(&localtime_mutex); + p_tm = _pthread_getspecific(localtime_key); + if (p_tm == NULL) { + if ((p_tm = (struct tm *)malloc(sizeof(struct tm))) + == NULL) + return(NULL); + _pthread_setspecific(localtime_key, p_tm); + } + _pthread_mutex_lock(&lcl_mutex); + tzset(); + localsub(timep, 0L, p_tm); + _pthread_mutex_unlock(&lcl_mutex); + return(p_tm); + } else { + tzset(); + localsub(timep, 0L, &tm); + return(&tm); } - pthread_mutex_unlock(&localtime_mutex); - p_tm = pthread_getspecific(localtime_key); - if (p_tm == NULL) { - if ((p_tm = (struct tm *)malloc(sizeof(struct tm))) == NULL) - return(NULL); - pthread_setspecific(localtime_key, p_tm); - } - pthread_mutex_lock(&lcl_mutex); - tzset(); - localsub(timep, 0L, p_tm); - pthread_mutex_unlock(&lcl_mutex); - return p_tm; -#else - tzset(); - localsub(timep, 0L, &tm); - return &tm; -#endif } /* @@ -1145,9 +1122,7 @@ const time_t * const timep; const long offset; struct tm * const tmp; { -#ifdef _THREAD_SAFE - pthread_mutex_lock(&gmt_mutex); -#endif + _MUTEX_LOCK(&gmt_mutex); if (!gmt_is_set) { gmt_is_set = TRUE; #ifdef ALL_STATE @@ -1156,9 +1131,7 @@ struct tm * const tmp; #endif /* defined ALL_STATE */ gmtload(gmtptr); } -#ifdef _THREAD_SAFE - pthread_mutex_unlock(&gmt_mutex); -#endif + _MUTEX_UNLOCK(&gmt_mutex); timesub(timep, offset, gmtptr, tmp); #ifdef TM_ZONE /* @@ -1185,36 +1158,37 @@ struct tm * gmtime(timep) const time_t * const timep; { -#ifdef _THREAD_SAFE - static struct pthread_mutex _gmtime_mutex = PTHREAD_MUTEX_STATIC_INITIALIZER; - static pthread_mutex_t gmtime_mutex = &_gmtime_mutex; + static pthread_mutex_t gmtime_mutex = PTHREAD_MUTEX_INITIALIZER; static pthread_key_t gmtime_key = -1; struct tm *p_tm; - pthread_mutex_lock(&gmtime_mutex); - if (gmtime_key < 0) { - if (pthread_key_create(&gmtime_key, free) < 0) { - pthread_mutex_unlock(&gmtime_mutex); - return(NULL); + if (__isthreaded != 0) { + _pthread_mutex_lock(&gmtime_mutex); + if (gmtime_key < 0) { + if (_pthread_key_create(&gmtime_key, free) < 0) { + _pthread_mutex_unlock(&gmtime_mutex); + return(NULL); } } - pthread_mutex_unlock(&gmtime_mutex); - /* - * Changed to follow draft 4 pthreads standard, which - * is what BSD currently has. - */ - if ((p_tm = pthread_getspecific(gmtime_key)) == NULL) { - if ((p_tm = (struct tm *)malloc(sizeof(struct tm))) == NULL) { - return(NULL); + _pthread_mutex_unlock(&gmtime_mutex); + /* + * Changed to follow POSIX.1 threads standard, which + * is what BSD currently has. + */ + if ((p_tm = _pthread_getspecific(gmtime_key)) == NULL) { + if ((p_tm = (struct tm *)malloc(sizeof(struct tm))) + == NULL) { + return(NULL); + } + _pthread_setspecific(gmtime_key, p_tm); } - pthread_setspecific(gmtime_key, p_tm); + gmtsub(timep, 0L, p_tm); + return(p_tm); + } + else { + gmtsub(timep, 0L, &tm); + return(&tm); } - gmtsub(timep, 0L, p_tm); - return(p_tm); -#else - gmtsub(timep, 0L, &tm); - return &tm; -#endif } struct tm * @@ -1634,14 +1608,10 @@ mktime(tmp) struct tm * const tmp; { time_t mktime_return_value; -#ifdef _THREAD_SAFE - pthread_mutex_lock(&lcl_mutex); -#endif + _MUTEX_LOCK(&lcl_mutex); tzset(); mktime_return_value = time1(tmp, localsub, 0L); -#ifdef _THREAD_SAFE - pthread_mutex_unlock(&lcl_mutex); -#endif + _MUTEX_UNLOCK(&lcl_mutex); return(mktime_return_value); } diff --git a/lib/libc/stdtime/strftime.c b/lib/libc/stdtime/strftime.c index d6e9dde818..54439c601d 100644 --- a/lib/libc/stdtime/strftime.c +++ b/lib/libc/stdtime/strftime.c @@ -16,9 +16,10 @@ * * @(#)strftime.c 7.38 * $FreeBSD: src/lib/libc/stdtime/strftime.c,v 1.25.2.4 2002/03/12 17:24:54 phantom Exp $ - * $DragonFly: src/lib/libc/stdtime/strftime.c,v 1.2 2003/06/17 04:26:46 dillon Exp $ + * $DragonFly: src/lib/libc/stdtime/strftime.c,v 1.3 2005/01/31 22:29:44 dillon Exp $ */ +#include "namespace.h" #include "private.h" #ifndef LIBC_SCCS @@ -30,6 +31,7 @@ static const char sccsid[] = "@(#)strftime.c 5.4 (Berkeley) 3/14/89"; #include "tzfile.h" #include #include +#include "un-namespace.h" #include "timelocal.h" static char * _add P((const char *, char *, const char *)); diff --git a/lib/libc/stdtime/strptime.c b/lib/libc/stdtime/strptime.c index 35ceec936c..1fa4dbbc7f 100644 --- a/lib/libc/stdtime/strptime.c +++ b/lib/libc/stdtime/strptime.c @@ -22,7 +22,7 @@ * @(#) Copyright (c) 1994 Powerdog Industries. All rights reserved. * @(#)strptime.c 0.1 (Powerdog) 94/03/27 * $FreeBSD: src/lib/libc/stdtime/strptime.c,v 1.17.2.3 2002/03/12 17:24:54 phantom Exp $ - * $DragonFly: src/lib/libc/stdtime/strptime.c,v 1.2 2003/06/17 04:26:46 dillon Exp $ + * $DragonFly: src/lib/libc/stdtime/strptime.c,v 1.3 2005/01/31 22:29:44 dillon Exp $ */ /* * Copyright (c) 1994 Powerdog Industries. All rights reserved. @@ -56,23 +56,20 @@ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "namespace.h" #include #include #include #include #include -#ifdef _THREAD_SAFE #include -#include "pthread_private.h" -#endif +#include "un-namespace.h" +#include "libc_private.h" #include "timelocal.h" static char * _strptime(const char *, const char *, struct tm *); -#ifdef _THREAD_SAFE -static struct pthread_mutex _gotgmt_mutexd = PTHREAD_MUTEX_STATIC_INITIALIZER; -static pthread_mutex_t gotgmt_mutex = &_gotgmt_mutexd; -#endif +static pthread_mutex_t gotgmt_mutex = PTHREAD_MUTEX_INITIALIZER; static int got_GMT; #define asizeof(a) (sizeof (a) / sizeof ((a)[0])) @@ -519,21 +516,18 @@ strptime(const char *buf, const char *fmt, struct tm *tm) { char *ret; -#ifdef _THREAD_SAFE - pthread_mutex_lock(&gotgmt_mutex); -#endif + if (__isthreaded) + _pthread_mutex_lock(&gotgmt_mutex); got_GMT = 0; ret = _strptime(buf, fmt, tm); if (ret && got_GMT) { time_t t = timegm(tm); - localtime_r(&t, tm); + localtime_r(&t, tm); got_GMT = 0; } -#ifdef _THREAD_SAFE - pthread_mutex_unlock(&gotgmt_mutex); -#endif - + if (__isthreaded) + _pthread_mutex_unlock(&gotgmt_mutex); return ret; } diff --git a/lib/libc/stdtime/timelocal.c b/lib/libc/stdtime/timelocal.c index b1214825a5..afe07afa3b 100644 --- a/lib/libc/stdtime/timelocal.c +++ b/lib/libc/stdtime/timelocal.c @@ -25,10 +25,13 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/stdtime/timelocal.c,v 1.8.2.4 2002/08/12 11:20:24 ache Exp $ - * $DragonFly: src/lib/libc/stdtime/timelocal.c,v 1.2 2003/06/17 04:26:46 dillon Exp $ + * $DragonFly: src/lib/libc/stdtime/timelocal.c,v 1.3 2005/01/31 22:29:44 dillon Exp $ */ +#include "namespace.h" #include +#include +#include "un-namespace.h" #include "ldpart.h" #include "timelocal.h" diff --git a/lib/libc/sys/ftruncate.c b/lib/libc/sys/ftruncate.c index 31ee2a0f18..52eebfedbb 100644 --- a/lib/libc/sys/ftruncate.c +++ b/lib/libc/sys/ftruncate.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/sys/ftruncate.c,v 1.3.6.1 2001/03/05 11:45:51 obrien Exp $ - * $DragonFly: src/lib/libc/sys/ftruncate.c,v 1.2 2003/06/17 04:26:47 dillon Exp $ + * $DragonFly: src/lib/libc/sys/ftruncate.c,v 1.3 2005/01/31 22:29:46 dillon Exp $ * * @(#)ftruncate.c 8.1 (Berkeley) 6/17/93 */ @@ -39,10 +39,6 @@ #include #include #include -#ifdef _THREAD_SAFE -#include -#include "pthread_private.h" -#endif /* * This function provides 64-bit offset padding that @@ -54,16 +50,5 @@ ftruncate(fd, length) off_t length; { -#ifdef _THREAD_SAFE - int retval; - if (_FD_LOCK(fd, FD_RDWR, NULL) != 0) { - retval = -1; - } else { - retval = __syscall((quad_t)SYS_ftruncate, fd, 0, length); - _FD_UNLOCK(fd, FD_RDWR); - } - return(retval); -#else return(__syscall((quad_t)SYS_ftruncate, fd, 0, length)); -#endif } diff --git a/lib/libc/sys/lseek.c b/lib/libc/sys/lseek.c index 61ccfd09ba..dff1f25ce4 100644 --- a/lib/libc/sys/lseek.c +++ b/lib/libc/sys/lseek.c @@ -31,15 +31,12 @@ * SUCH DAMAGE. * * @(#)lseek.c 8.1 (Berkeley) 6/17/93 + * $DragonFly: src/lib/libc/sys/lseek.c,v 1.3 2005/01/31 22:29:46 dillon Exp $ */ #include #include #include -#ifdef _THREAD_SAFE -#include -#include "pthread_private.h" -#endif /* * This function provides 64-bit offset padding that @@ -51,17 +48,5 @@ lseek(fd, offset, whence) off_t offset; int whence; { -#ifdef _THREAD_SAFE - off_t offs; - if (_FD_LOCK(fd, FD_RDWR, NULL) != 0) { - offs = -1; - } else { - offs = __syscall((quad_t) SYS_lseek,fd, 0, offset, whence); - _FD_UNLOCK(fd, FD_RDWR); - } - return(offs); - -#else return(__syscall((quad_t)SYS_lseek, fd, 0, offset, whence)); -#endif } diff --git a/lib/libc/sys/stack_protector.c b/lib/libc/sys/stack_protector.c index 587613e8ce..665dd25f51 100644 --- a/lib/libc/sys/stack_protector.c +++ b/lib/libc/sys/stack_protector.c @@ -24,12 +24,14 @@ * POSSIBILITY OF SUCH DAMAGE. * * $OpenBSD: stack_protector.c,v 1.3 2002/12/10 08:53:42 etoh Exp $ - * $DragonFly: src/lib/libc/sys/stack_protector.c,v 1.1 2003/12/10 22:15:36 dillon Exp $ + * $DragonFly: src/lib/libc/sys/stack_protector.c,v 1.2 2005/01/31 22:29:46 dillon Exp $ */ +#include "namespace.h" #include #include #include +#include "un-namespace.h" void __stack_smash_handler(char func[], int damaged __attribute__((unused))); static void __guard_setup(void) __attribute__ ((constructor)); @@ -44,9 +46,9 @@ __guard_setup(void) if (__guard[0] != 0) return; - if ((fd = open ("/dev/urandom", 0)) >= 0) { - size = read (fd, (char*)&__guard, sizeof(__guard)); - close (fd); + if ((fd = _open ("/dev/urandom", 0)) >= 0) { + size = _read (fd, (char*)&__guard, sizeof(__guard)); + _close (fd); if (size == sizeof(__guard)) return; } @@ -74,7 +76,7 @@ __stack_smash_handler(char func[], int damaged) sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = SIG_DFL; - sigaction(SIGABRT, &sa, NULL); + __sys_sigaction(SIGABRT, &sa, NULL); kill(getpid(), SIGABRT); diff --git a/lib/libc/yp/yplib.c b/lib/libc/yp/yplib.c index 3780012a02..bbd5571881 100644 --- a/lib/libc/yp/yplib.c +++ b/lib/libc/yp/yplib.c @@ -28,9 +28,10 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc/yp/yplib.c,v 1.34.2.2 2002/02/15 00:46:53 des Exp $ - * $DragonFly: src/lib/libc/yp/yplib.c,v 1.3 2004/06/06 16:41:05 hmp Exp $ + * $DragonFly: src/lib/libc/yp/yplib.c,v 1.4 2005/01/31 22:29:47 dillon Exp $ */ +#include "namespace.h" #include #include #include @@ -44,6 +45,7 @@ #include #include #include +#include "un-namespace.h" /* * We have to define these here due to clashes between yp_prot.h and @@ -328,19 +330,19 @@ _yp_dobind(char *dom, struct dom_binding **ypdb) new = 1; } else { /* Check the socket -- may have been hosed by the caller. */ - if (getsockname(ysd->dom_socket, (struct sockaddr *)&check, + if (_getsockname(ysd->dom_socket, (struct sockaddr *)&check, &checklen) == -1 || check.sin_family != AF_INET || check.sin_port != ysd->dom_local_port) { /* Socket became bogus somehow... need to rebind. */ int save, sock; sock = ysd->dom_socket; - save = dup(ysd->dom_socket); + save = _dup(ysd->dom_socket); if (ysd->dom_client != NULL) clnt_destroy(ysd->dom_client); ysd->dom_vers = 0; ysd->dom_client = NULL; - sock = dup2(save, sock); + sock = _dup2(save, sock); _close(save); } } @@ -370,7 +372,7 @@ again: _close(fd); goto skipit; } - if (flock(fd, LOCK_EX|LOCK_NB) == -1 && errno == EWOULDBLOCK) { + if (_flock(fd, LOCK_EX|LOCK_NB) == -1 && errno == EWOULDBLOCK) { struct iovec iov[2]; struct ypbind_resp ybr; u_short ypb_port; @@ -380,7 +382,7 @@ again: iov[1].iov_base = (caddr_t)&ybr; iov[1].iov_len = sizeof ybr; - r = readv(fd, iov, 2); + r = _readv(fd, iov, 2); if (r != iov[0].iov_len + iov[1].iov_len) { _close(fd); ysd->dom_vers = -1; @@ -523,9 +525,9 @@ gotit: */ checklen = sizeof(struct sockaddr_in); bzero((char *)&check, checklen); - bind(ysd->dom_socket, (struct sockaddr *)&check, checklen); + _bind(ysd->dom_socket, (struct sockaddr *)&check, checklen); check.sin_family = AF_INET; - if (!getsockname(ysd->dom_socket, + if (!_getsockname(ysd->dom_socket, (struct sockaddr *)&check, &checklen)) { ysd->dom_local_port = check.sin_port; } else { @@ -554,15 +556,15 @@ _yp_unbind(struct dom_binding *ypb) if (ypb->dom_client != NULL) { /* Check the socket -- may have been hosed by the caller. */ - if (getsockname(ypb->dom_socket, (struct sockaddr *)&check, + if (_getsockname(ypb->dom_socket, (struct sockaddr *)&check, &checklen) == -1 || check.sin_family != AF_INET || check.sin_port != ypb->dom_local_port) { int save, sock; sock = ypb->dom_socket; - save = dup(ypb->dom_socket); + save = _dup(ypb->dom_socket); clnt_destroy(ypb->dom_client); - sock = dup2(save, sock); + sock = _dup2(save, sock); _close(save); } else clnt_destroy(ypb->dom_client); diff --git a/lib/libc_r/uthread/uthread_spinlock.c b/lib/libc_r/uthread/uthread_spinlock.c index 599fae5a2d..9336804ea7 100644 --- a/lib/libc_r/uthread/uthread_spinlock.c +++ b/lib/libc_r/uthread/uthread_spinlock.c @@ -30,7 +30,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/lib/libc_r/uthread/uthread_spinlock.c,v 1.8.2.2 2002/10/17 19:37:39 fjoe Exp $ - * $DragonFly: src/lib/libc_r/uthread/uthread_spinlock.c,v 1.2 2003/06/17 04:26:48 dillon Exp $ + * $DragonFly: src/lib/libc_r/uthread/uthread_spinlock.c,v 1.3 2005/01/31 22:29:48 dillon Exp $ * */ @@ -43,6 +43,12 @@ extern char *__progname; +void +_spinunlock(spinlock_t *lck) +{ + lck->access_lock = 0; +} + /* * Lock a location for the running thread. Yield to allow other * threads to run if this thread is blocked because the lock is -- 2.41.0