From d201fe46e355212750b727061e6a7ac005267852 Mon Sep 17 00:00:00 2001 From: Daniel Eischen Date: Wed, 24 Jan 2001 13:01:12 +0000 Subject: Remove _THREAD_SAFE and make libc thread-safe by default by adding (weak definitions to) stubs for some of the pthread functions. If the threads library is linked in, the real pthread functions will pulled in. Use the following convention for system calls wrapped by the threads library: __sys_foo - actual system call _foo - weak definition to __sys_foo foo - weak definition to __sys_foo Change all libc uses of system calls wrapped by the threads library from foo to _foo. In order to define the prototypes for _foo(), we introduce namespace.h and un-namespace.h (suggested by bde). All files that need to reference these system calls, should include namespace.h before any standard includes, then include un-namespace.h after the standard includes and before any local includes. is an exception and shouldn't be included in between namespace.h and un-namespace.h namespace.h will define foo to _foo, and un-namespace.h will undefine foo. Try to eliminate some of the recursive calls to MT-safe functions in libc/stdio in preparation for adding a mutex to FILE. We have recursive mutexes, but would like to avoid using them if possible. Remove uneeded includes of from a few files. Add $FreeBSD$ to a few files in order to pass commitprep. Approved by: -arch --- lib/libc/Makefile | 17 +++- lib/libc/alpha/SYS.h | 35 +++----- lib/libc/alpha/gen/_setjmp.S | 10 +-- lib/libc/alpha/gen/setjmp.S | 16 +--- lib/libc/alpha/gen/sigsetjmp.S | 14 +-- lib/libc/alpha/sys/setlogin.S | 4 +- lib/libc/amd64/SYS.h | 31 +++---- lib/libc/amd64/gen/_setjmp.S | 7 +- lib/libc/amd64/gen/setjmp.S | 18 +--- lib/libc/amd64/gen/sigsetjmp.S | 21 +---- lib/libc/amd64/sys/setlogin.S | 2 +- lib/libc/amd64/sys/vfork.S | 11 ++- lib/libc/compat-43/creat.c | 12 +-- lib/libc/compat-43/sigcompat.c | 9 +- lib/libc/db/btree/bt_close.c | 2 + lib/libc/db/btree/bt_open.c | 8 +- lib/libc/db/hash/hash.c | 7 +- lib/libc/db/hash/hash_buf.c | 3 +- lib/libc/db/hash/hash_page.c | 6 +- lib/libc/db/mpool/mpool.c | 4 +- lib/libc/db/recno/rec_close.c | 4 +- lib/libc/db/recno/rec_open.c | 4 +- lib/libc/gen/Makefile.inc | 4 +- lib/libc/gen/_pthread_stubs.c | 131 ++++++++++++++++++++++++++++ lib/libc/gen/_spinlock_stub.c | 16 +++- lib/libc/gen/_thread_init.c | 38 +++++++++ lib/libc/gen/arc4random.c | 2 + lib/libc/gen/closedir.c | 12 ++- lib/libc/gen/daemon.c | 8 +- lib/libc/gen/devname.c | 1 - lib/libc/gen/disklabel.c | 1 - lib/libc/gen/exec.c | 12 +-- lib/libc/gen/fstab.c | 2 + lib/libc/gen/fts-compat.c | 4 +- lib/libc/gen/fts.c | 4 +- lib/libc/gen/getcap.c | 5 +- lib/libc/gen/getcwd.c | 4 +- lib/libc/gen/getlogin.c | 23 +++-- lib/libc/gen/getpass.c | 6 +- lib/libc/gen/getpwent.c | 2 + lib/libc/gen/getvfsent.c | 3 +- lib/libc/gen/isatty.c | 17 +--- lib/libc/gen/lockf.c | 2 + lib/libc/gen/nlist.c | 6 +- lib/libc/gen/opendir.c | 19 +++-- lib/libc/gen/pause.c | 4 +- lib/libc/gen/popen.c | 16 ++-- lib/libc/gen/posixshm.c | 4 +- lib/libc/gen/pselect.c | 8 +- lib/libc/gen/psignal.c | 2 + lib/libc/gen/readdir.c | 56 ++++++------ lib/libc/gen/scandir.c | 6 +- lib/libc/gen/seekdir.c | 8 ++ lib/libc/gen/setjmperr.c | 2 + lib/libc/gen/setmode.c | 7 +- lib/libc/gen/siginterrupt.c | 9 +- lib/libc/gen/signal.c | 7 +- lib/libc/gen/sleep.c | 5 +- lib/libc/gen/syslog.c | 12 +-- lib/libc/gen/telldir.c | 10 ++- lib/libc/gen/telldir.h | 5 +- lib/libc/gen/termios.c | 31 +++---- lib/libc/gen/ttyname.c | 124 ++++++++++++--------------- lib/libc/gen/usleep.c | 2 + lib/libc/gen/vis.c | 1 + lib/libc/gen/wait.c | 10 +-- lib/libc/gen/wait3.c | 6 +- lib/libc/gen/waitpid.c | 14 +-- lib/libc/gmon/gmon.c | 3 + lib/libc/i386/SYS.h | 31 +++---- lib/libc/i386/gen/_setjmp.S | 7 +- lib/libc/i386/gen/setjmp.S | 18 +--- lib/libc/i386/gen/sigsetjmp.S | 21 +---- lib/libc/i386/sys/Ovfork.S | 11 ++- lib/libc/i386/sys/setlogin.S | 2 +- lib/libc/ia64/SYS.h | 33 ++----- lib/libc/ia64/gen/_setjmp.S | 10 +-- lib/libc/ia64/gen/modf.c | 1 - lib/libc/ia64/gen/setjmp.S | 17 +--- lib/libc/ia64/gen/sigsetjmp.S | 10 +-- lib/libc/include/libc_private.h | 4 +- lib/libc/include/namespace.h | 134 +++++++++++++++++++++++++++++ lib/libc/include/un-namespace.h | 134 +++++++++++++++++++++++++++++ lib/libc/locale/big5.c | 1 - lib/libc/locale/collate.c | 5 +- lib/libc/locale/mskanji.c | 1 - lib/libc/locale/none.c | 3 +- lib/libc/locale/rune.c | 6 +- lib/libc/locale/utf2.c | 1 - lib/libc/net/getaddrinfo.c | 10 ++- lib/libc/net/gethostbyht.c | 1 - lib/libc/net/gethostnamadr.c | 3 - lib/libc/net/getifaddrs.c | 9 +- lib/libc/net/getnetbydns.c | 1 - lib/libc/net/getnetnamadr.c | 1 - lib/libc/net/herror.c | 4 +- lib/libc/net/map_v4v6.c | 1 - lib/libc/net/name6.c | 18 ++-- lib/libc/net/rcmd.c | 32 ++++--- lib/libc/net/recv.c | 6 +- lib/libc/net/res_mkupdate.c | 1 - lib/libc/net/res_send.c | 24 +++--- lib/libc/net/res_update.c | 1 - lib/libc/net/send.c | 6 +- lib/libc/nls/msgcat.c | 2 + lib/libc/rpc/auth_time.c | 12 +-- lib/libc/rpc/bindresvport.c | 14 +-- lib/libc/rpc/clnt_generic.c | 4 +- lib/libc/rpc/clnt_simple.c | 2 + lib/libc/rpc/clnt_tcp.c | 10 ++- lib/libc/rpc/clnt_udp.c | 14 +-- lib/libc/rpc/clnt_unix.c | 16 ++-- lib/libc/rpc/get_myaddress.c | 8 +- lib/libc/rpc/key_call.c | 4 +- lib/libc/rpc/pmap_clnt.c | 2 + lib/libc/rpc/pmap_getmaps.c | 3 + lib/libc/rpc/pmap_getport.c | 2 + lib/libc/rpc/pmap_rmt.c | 21 +++-- lib/libc/rpc/rpc_dtablesize.c | 2 +- lib/libc/rpc/rtime.c | 12 +-- lib/libc/rpc/svc.c | 1 - lib/libc/rpc/svc_auth_des.c | 1 + lib/libc/rpc/svc_run.c | 6 +- lib/libc/rpc/svc_tcp.c | 22 ++--- lib/libc/rpc/svc_udp.c | 14 +-- lib/libc/rpc/svc_unix.c | 22 ++--- lib/libc/stdio/_flock_stub.c | 6 +- lib/libc/stdio/clrerr.c | 4 +- lib/libc/stdio/fclose.c | 14 ++- lib/libc/stdio/fdopen.c | 2 + lib/libc/stdio/fflush.c | 41 ++++++--- lib/libc/stdio/fgetc.c | 2 + lib/libc/stdio/fgetpos.c | 2 + lib/libc/stdio/fgets.c | 2 + lib/libc/stdio/findfp.c | 57 +++++++++---- lib/libc/stdio/flags.c | 3 +- lib/libc/stdio/fopen.c | 9 +- lib/libc/stdio/fpurge.c | 2 + lib/libc/stdio/fputc.c | 2 + lib/libc/stdio/fputs.c | 2 + lib/libc/stdio/fread.c | 2 + lib/libc/stdio/freopen.c | 6 +- lib/libc/stdio/fscanf.c | 2 + lib/libc/stdio/fseek.c | 48 ++++++----- lib/libc/stdio/ftell.c | 2 + lib/libc/stdio/funopen.c | 3 + lib/libc/stdio/fvwrite.c | 6 +- lib/libc/stdio/fwalk.c | 16 ++-- lib/libc/stdio/fwrite.c | 2 + lib/libc/stdio/getc.c | 6 +- lib/libc/stdio/getchar.c | 2 + lib/libc/stdio/gets.c | 2 + lib/libc/stdio/local.h | 8 ++ lib/libc/stdio/makebuf.c | 8 +- lib/libc/stdio/mktemp.c | 2 + lib/libc/stdio/perror.c | 6 +- lib/libc/stdio/putc.c | 11 ++- lib/libc/stdio/putchar.c | 12 ++- lib/libc/stdio/puts.c | 2 + lib/libc/stdio/putw.c | 2 + lib/libc/stdio/refill.c | 1 + lib/libc/stdio/rewind.c | 10 ++- lib/libc/stdio/scanf.c | 2 + lib/libc/stdio/setvbuf.c | 2 + lib/libc/stdio/stdio.c | 2 + lib/libc/stdio/tmpfile.c | 6 +- lib/libc/stdio/ungetc.c | 46 +++++----- lib/libc/stdio/vasprintf.c | 3 +- lib/libc/stdio/vfprintf.c | 111 +++++++++++------------- lib/libc/stdio/vfscanf.c | 48 +++++++---- lib/libc/stdio/vscanf.c | 2 + lib/libc/stdio/vsnprintf.c | 3 +- lib/libc/stdio/vsprintf.c | 3 +- lib/libc/stdio/wbuf.c | 6 +- lib/libc/stdlib/abort.c | 33 ++++--- lib/libc/stdlib/exit.c | 9 +- lib/libc/stdlib/malloc.c | 2 + lib/libc/stdlib/random.c | 2 + lib/libc/stdlib/realpath.c | 2 + lib/libc/stdlib/system.c | 24 +++--- lib/libc/stdtime/asctime.c | 4 + lib/libc/stdtime/difftime.c | 4 + lib/libc/stdtime/localtime.c | 184 +++++++++++++++++----------------------- lib/libc/stdtime/strftime.c | 2 + lib/libc/stdtime/strptime.c | 23 ++--- lib/libc/stdtime/timelocal.c | 6 +- lib/libc/sys/__error.c | 4 +- lib/libc/sys/ftruncate.c | 17 +--- lib/libc/sys/lseek.c | 18 +--- lib/libc/yp/yplib.c | 23 ++--- 190 files changed, 1582 insertions(+), 997 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 (limited to 'lib') diff --git a/lib/libc/Makefile b/lib/libc/Makefile index 8862755c9035..2a73a6cf7992 100644 --- a/lib/libc/Makefile +++ b/lib/libc/Makefile @@ -16,9 +16,22 @@ INSTALL_PIC_ARCHIVE= yes PRECIOUSLIB= yes # -# Don't bother hiding any syscalls (like libc_r does). +# This is a list of syscalls that are renamed as _thread_sys_{syscall} +# so that libpthread and libc_r can override and/or replace them. +# In the case of libc_r replacement functions are provided, whereas +# libpthread can both override and provide replacement functions. # -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/alpha/SYS.h b/lib/libc/alpha/SYS.h index 923300b6afc7..d53e1fbed03f 100644 --- a/lib/libc/alpha/SYS.h +++ b/lib/libc/alpha/SYS.h @@ -83,50 +83,41 @@ END(label); * 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 _thread_sys_ to the function + * For the thread_safe versions, we prepend __sys_ to the function * name so that the 'C' wrapper can go around the real name. */ +#define PNAME(name) __CONCAT(__sys_,name) + #define PCALL(name) \ - CALL(___CONCAT(_thread_sys_,name)) + CALL(PNAME(name)) #define PLEAF(name, args) \ -LEAF(___CONCAT(_thread_sys_,name),args) +LEAF(PNAME(name),args) #define PEND(name) \ -END(___CONCAT(_thread_sys_,name)) +END(PNAME(name)) #define PSYSCALL(name) \ PLEAF(name,0); /* XXX # of args? */ \ + WEAK_ALIAS(name, PNAME(name)); \ + WEAK_ALIAS(__CONCAT(_,name), PNAME(name)); \ CALLSYS_ERROR(name) #define PRSYSCALL(name) \ PLEAF(name,0); /* XXX # of args? */ \ + WEAK_ALIAS(name, PNAME(name)); \ + WEAK_ALIAS(__CONCAT(_,name), PNAME(name)); \ CALLSYS_ERROR(name) \ RET; \ PEND(name) #define PPSEUDO(label,name) \ PLEAF(label,0); /* XXX # of args? */ \ + WEAK_ALIAS(label, PNAME(label)); \ + WEAK_ALIAS(__CONCAT(_,label), PNAME(label)); \ CALLSYS_ERROR(name); \ RET; \ PEND(label) - -#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) -#define PLEAF(x,y) LEAF(x,y) -#define PEND(x) END(x) -#define PCALL(x) CALL(x) -#endif diff --git a/lib/libc/alpha/gen/_setjmp.S b/lib/libc/alpha/gen/_setjmp.S index 0d032e7543c4..f3aa6ff8d484 100644 --- a/lib/libc/alpha/gen/_setjmp.S +++ b/lib/libc/alpha/gen/_setjmp.S @@ -87,12 +87,8 @@ LEAF(_setjmp, 1) RET END(_setjmp) -#ifdef _THREAD_SAFE +XLEAF(_longjmp, 2) LEAF(___longjmp, 2) -#else -XLEAF(___longjmp, 2) -LEAF(_longjmp, 2) -#endif LDGP(pv) ldq t0, ((31 + 4) * 8)(a0) /* magic in sc_regs[31] */ ldiq t1, 0xacedbadd @@ -127,8 +123,4 @@ botch: CALL(longjmperror) CALL(abort) RET /* "can't" get here... */ -#ifdef _THREAD_SAFE END(___longjmp) -#else -END(_longjmp) -#endif diff --git a/lib/libc/alpha/gen/setjmp.S b/lib/libc/alpha/gen/setjmp.S index 04202ce4b721..297e6015010b 100644 --- a/lib/libc/alpha/gen/setjmp.S +++ b/lib/libc/alpha/gen/setjmp.S @@ -66,12 +66,12 @@ LEAF(setjmp, 1) lda a2, (71 * 8)(a0) /* oset: sc_reserved */ mov zero, a1 /* set: NULL */ addq a1, 1, a0 /* how: SIG_BLOCK */ - PCALL(sigprocmask) /* see what's blocked */ + CALL(_sigprocmask) /* see what's blocked */ lda sp, -24(sp) /* sizeof struct sigaltstack */ mov zero, a0 mov sp, a1 - PCALL(sigaltstack) + CALL(_sigaltstack) ldl t0, 16(sp) /* offset of ss_flags */ lda sp, 24(sp) /* sizeof struct sigaltstack */ ldq ra, ((26 + 4) * 8)(s0) /* restore return address */ @@ -115,22 +115,14 @@ LEAF(setjmp, 1) RET END(setjmp) -#ifdef _THREAD_SAFE +XLEAF(longjmp, 2) LEAF(__longjmp, 2) -#else -XLEAF(__longjmp, 2) -LEAF(longjmp, 2) -#endif LDGP(pv) stq a1, (( 0 + 4) * 8)(a0) /* save return value */ - PCALL(sigreturn) /* use sigreturn to return */ + CALL(_sigreturn) /* use sigreturn to return */ botch: CALL(longjmperror) CALL(abort) RET /* "can't" get here... */ -#ifdef _THREAD_SAFE END(__longjmp) -#else -END(longjmp) -#endif diff --git a/lib/libc/alpha/gen/sigsetjmp.S b/lib/libc/alpha/gen/sigsetjmp.S index 0a3992dd1ce3..ddc0636894c5 100644 --- a/lib/libc/alpha/gen/sigsetjmp.S +++ b/lib/libc/alpha/gen/sigsetjmp.S @@ -54,20 +54,12 @@ Lsavesig: jmp zero, setjmp END(sigsetjmp) -#ifdef _THREAD_SAFE +XLEAF(siglongjmp, 2) LEAF(__siglongjmp, 2) -#else -XLEAF(__siglongjmp, 2) -LEAF(siglongjmp, 2) -#endif LDGP(pv) ldq t0, (81 * 8)(a0) /* get the mask */ bne t0, Lrestoresig /* if !zero, restore signals */ - jmp zero, _longjmp + jmp zero, ___longjmp Lrestoresig: - jmp zero, longjmp -#ifdef _THREAD_SAFE + jmp zero, __longjmp END(__siglongjmp) -#else -END(siglongjmp) -#endif diff --git a/lib/libc/alpha/sys/setlogin.S b/lib/libc/alpha/sys/setlogin.S index 9657cb1c2a0a..e542b2d7bb37 100644 --- a/lib/libc/alpha/sys/setlogin.S +++ b/lib/libc/alpha/sys/setlogin.S @@ -25,11 +25,13 @@ * * any improvements or extensions that they make and grant Carnegie the * rights to redistribute these changes. + * + * $FreeBSD$ */ #include "SYS.h" -IMPORT(_logname_valid, 4) /* in getlogin() */ +IMPORT(_logname_valid, 4) /* in _getlogin() */ SYSCALL(setlogin) stl zero, _logname_valid /* clear it */ diff --git a/lib/libc/amd64/SYS.h b/lib/libc/amd64/SYS.h index cadbecb1b31a..2d585628107c 100644 --- a/lib/libc/amd64/SYS.h +++ b/lib/libc/amd64/SYS.h @@ -61,31 +61,28 @@ * 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 _thread_sys_ to the function + * 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(_thread_sys_,x)); \ + 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(_thread_sys_,x)); \ + +#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 #ifdef __ELF__ #define KERNCALL int $0x80 /* Faster */ diff --git a/lib/libc/amd64/gen/_setjmp.S b/lib/libc/amd64/gen/_setjmp.S index 9c66308dc502..5932feeee0c5 100644 --- a/lib/libc/amd64/gen/_setjmp.S +++ b/lib/libc/amd64/gen/_setjmp.S @@ -66,12 +66,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/amd64/gen/setjmp.S b/lib/libc/amd64/gen/setjmp.S index 738407a1a8f2..5e92c979a7dc 100644 --- a/lib/libc/amd64/gen/setjmp.S +++ b/lib/libc/amd64/gen/setjmp.S @@ -61,11 +61,7 @@ ENTRY(setjmp) pushl %eax /* (sigset_t*)oset */ pushl $0 /* (sigset_t*)set */ pushl $1 /* SIG_BLOCK */ -#ifdef _THREAD_SAFE - call PIC_PLT(CNAME(_thread_sys_sigprocmask)) -#else - call PIC_PLT(CNAME(sigprocmask)) -#endif + call PIC_PLT(CNAME(_sigprocmask)) addl $12,%esp PIC_EPILOGUE movl 4(%esp),%ecx @@ -80,10 +76,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 @@ -91,11 +85,7 @@ ENTRY(__longjmp) leal 28(%edx), %eax pushl %eax /* (sigset_t*)set */ pushl $3 /* SIG_SETMASK */ -#ifdef _THREAD_SAFE - call PIC_PLT(CNAME(_thread_sys_sigprocmask)) -#else - call PIC_PLT(CNAME(sigprocmask)) -#endif + call PIC_PLT(CNAME(_sigprocmask)) addl $12,%esp PIC_EPILOGUE movl 4(%esp),%edx diff --git a/lib/libc/amd64/gen/sigsetjmp.S b/lib/libc/amd64/gen/sigsetjmp.S index 40aebb65e53f..96aae6897034 100644 --- a/lib/libc/amd64/gen/sigsetjmp.S +++ b/lib/libc/amd64/gen/sigsetjmp.S @@ -52,9 +52,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. */ @@ -70,11 +67,7 @@ ENTRY(sigsetjmp) pushl %eax /* (sigset_t*)oset */ pushl $0 /* (sigset_t*)set */ pushl $1 /* SIG_BLOCK */ -#ifdef _THREAD_SAFE - call PIC_PLT(CNAME(_thread_sys_sigprocmask)) -#else - call PIC_PLT(CNAME(sigprocmask)) -#endif + call PIC_PLT(CNAME(_sigprocmask)) addl $12,%esp PIC_EPILOGUE movl 4(%esp),%ecx @@ -89,10 +82,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) @@ -102,11 +93,7 @@ ENTRY(__siglongjmp); leal 28(%edx), %eax pushl %eax /* (sigset_t*)set */ pushl $3 /* SIG_SETMASK */ -#ifdef _THREAD_SAFE - call PIC_PLT(CNAME(_thread_sys_sigprocmask)) -#else - call PIC_PLT(CNAME(sigprocmask)) -#endif + call PIC_PLT(CNAME(_sigprocmask)) addl $12,%esp PIC_EPILOGUE movl 4(%esp),%edx diff --git a/lib/libc/amd64/sys/setlogin.S b/lib/libc/amd64/sys/setlogin.S index a4d74b0d10cf..3ba52c5cde38 100644 --- a/lib/libc/amd64/sys/setlogin.S +++ b/lib/libc/amd64/sys/setlogin.S @@ -43,7 +43,7 @@ #include "SYS.h" -.globl CNAME(_logname_valid) /* in getlogin() */ +.globl CNAME(_logname_valid) /* in _getlogin() */ SYSCALL(setlogin) #ifdef PIC diff --git a/lib/libc/amd64/sys/vfork.S b/lib/libc/amd64/sys/vfork.S index 8ec99aeaad21..8981308dbdb3 100644 --- a/lib/libc/amd64/sys/vfork.S +++ b/lib/libc/amd64/sys/vfork.S @@ -51,12 +51,11 @@ * %eax == pid of child in parent, %eax == pid of parent in child. * */ - -#ifdef _THREAD_SAFE -ENTRY(_thread_sys_vfork) -#else -ENTRY(vfork) -#endif + .weak _vfork + .set _vfork,__sys_vfork + .weak vfork + .set vfork,__sys_vfork +ENTRY(__sys_vfork) popl %ecx /* my rta into ecx */ lea SYS_vfork,%eax KERNCALL diff --git a/lib/libc/compat-43/creat.c b/lib/libc/compat-43/creat.c index 42759e7d9389..88a3c5f64108 100644 --- a/lib/libc/compat-43/creat.c +++ b/lib/libc/compat-43/creat.c @@ -37,20 +37,14 @@ static char sccsid[] = "@(#)creat.c 8.1 (Berkeley) 6/2/93"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include +#include "un-namespace.h" int -#if __STDC__ __creat(const char *path, mode_t mode) -#else -__creat(path, mode) - char *path; - mode_t mode; -#endif { 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 9401e73d2b32..23f1eff8b9cb 100644 --- a/lib/libc/compat-43/sigcompat.c +++ b/lib/libc/compat-43/sigcompat.c @@ -41,8 +41,11 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include +#include "un-namespace.h" +#include "libc_private.h" int sigvec(signo, sv, osv) @@ -62,7 +65,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; @@ -80,7 +83,7 @@ sigsetmask(mask) 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]); @@ -95,7 +98,7 @@ sigblock(mask) 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]); diff --git a/lib/libc/db/btree/bt_close.c b/lib/libc/db/btree/bt_close.c index c5e0d52ac0c1..878c4c4485a3 100644 --- a/lib/libc/db/btree/bt_close.c +++ b/lib/libc/db/btree/bt_close.c @@ -40,6 +40,7 @@ static char sccsid[] = "@(#)bt_close.c 8.7 (Berkeley) 8/17/94"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include @@ -47,6 +48,7 @@ static char sccsid[] = "@(#)bt_close.c 8.7 (Berkeley) 8/17/94"; #include #include #include +#include "un-namespace.h" #include #include "btree.h" diff --git a/lib/libc/db/btree/bt_open.c b/lib/libc/db/btree/bt_open.c index d3c353fd6c71..e2e9a24e3d65 100644 --- a/lib/libc/db/btree/bt_open.c +++ b/lib/libc/db/btree/bt_open.c @@ -48,6 +48,7 @@ static char sccsid[] = "@(#)bt_open.c 8.10 (Berkeley) 8/17/94"; * is wholly independent of the Postgres code. */ +#include "namespace.h" #include #include @@ -59,6 +60,7 @@ static char sccsid[] = "@(#)bt_open.c 8.10 (Berkeley) 8/17/94"; #include #include #include +#include "un-namespace.h" #include #include "btree.h" @@ -217,7 +219,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) @@ -399,10 +401,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 dcef5df36714..34fe4ad74c98 100644 --- a/lib/libc/db/hash/hash.c +++ b/lib/libc/db/hash/hash.c @@ -40,6 +40,7 @@ static char sccsid[] = "@(#)hash.c 8.9 (Berkeley) 6/16/94"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include @@ -52,6 +53,7 @@ static char sccsid[] = "@(#)hash.c 8.9 (Berkeley) 6/16/94"; #ifdef DEBUG #include #endif +#include "un-namespace.h" #include #include "hash.h" @@ -136,7 +138,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); @@ -562,7 +564,8 @@ hash_put(dbp, key, data, flag) hashp = (HTAB *)dbp->internal; if (flag && flag != R_NOOVERWRITE) { - hashp->error = errno = EINVAL; + hashp->error = EINVAL; + errno = EINVAL; return (ERROR); } if ((hashp->flags & O_ACCMODE) == O_RDONLY) { diff --git a/lib/libc/db/hash/hash_buf.c b/lib/libc/db/hash/hash_buf.c index 92e1f933adb2..afa916470f9b 100644 --- a/lib/libc/db/hash/hash_buf.c +++ b/lib/libc/db/hash/hash_buf.c @@ -32,6 +32,8 @@ * 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$ */ #if defined(LIBC_SCCS) && !defined(lint) @@ -56,7 +58,6 @@ static char sccsid[] = "@(#)hash_buf.c 8.5 (Berkeley) 7/15/94"; #include -#include #include #include #include diff --git a/lib/libc/db/hash/hash_page.c b/lib/libc/db/hash/hash_page.c index 30445e40434a..dd042c8320f3 100644 --- a/lib/libc/db/hash/hash_page.c +++ b/lib/libc/db/hash/hash_page.c @@ -56,6 +56,7 @@ static char sccsid[] = "@(#)hash_page.c 8.7 (Berkeley) 8/16/94"; * open_temp */ +#include "namespace.h" #include #include @@ -68,6 +69,7 @@ static char sccsid[] = "@(#)hash_page.c 8.7 (Berkeley) 8/16/94"; #ifdef DEBUG #include #endif +#include "un-namespace.h" #include #include "hash.h" @@ -866,12 +868,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 a4ab9126b77b..303d8c0adc8d 100644 --- a/lib/libc/db/mpool/mpool.c +++ b/lib/libc/db/mpool/mpool.c @@ -37,6 +37,7 @@ static char sccsid[] = "@(#)mpool.c 8.5 (Berkeley) 7/26/94"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include @@ -46,6 +47,7 @@ static char sccsid[] = "@(#)mpool.c 8.5 (Berkeley) 7/26/94"; #include #include #include +#include "un-namespace.h" #include @@ -76,7 +78,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 25d01de75ab1..1f19bd3191f1 100644 --- a/lib/libc/db/recno/rec_close.c +++ b/lib/libc/db/recno/rec_close.c @@ -37,6 +37,7 @@ static char sccsid[] = "@(#)rec_close.c 8.6 (Berkeley) 8/18/94"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include @@ -45,6 +46,7 @@ static char sccsid[] = "@(#)rec_close.c 8.6 (Berkeley) 8/18/94"; #include #include #include +#include "un-namespace.h" #include #include "recno.h" @@ -165,7 +167,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 eaeacc5b178f..4098b180994c 100644 --- a/lib/libc/db/recno/rec_open.c +++ b/lib/libc/db/recno/rec_open.c @@ -40,6 +40,7 @@ static char sccsid[] = "@(#)rec_open.c 8.10 (Berkeley) 9/1/94"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include @@ -50,6 +51,7 @@ static char sccsid[] = "@(#)rec_open.c 8.10 (Berkeley) 9/1/94"; #include #include #include +#include "un-namespace.h" #include #include "recno.h" @@ -146,7 +148,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 afe8e917027c..3f7bbb42fe2c 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -4,8 +4,8 @@ # 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 000000000000..87b0ad2044a7 --- /dev/null +++ b/lib/libc/gen/_pthread_stubs.c @@ -0,0 +1,131 @@ +/* + * 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$ + */ + +#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 e3a800d0e1c0..071fc206e53c 100644 --- a/lib/libc/gen/_spinlock_stub.c +++ b/lib/libc/gen/_spinlock_stub.c @@ -35,17 +35,26 @@ #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 +/* + * 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. */ @@ -61,4 +70,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 000000000000..d6be5f22717c --- /dev/null +++ b/lib/libc/gen/_thread_init.c @@ -0,0 +1,38 @@ +/* + * 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. + * + * $FreeBSD$ + */ + +#pragma weak _thread_init=_thread_init_stub +#pragma weak _thread_autoinit_dummy_decl=_thread_autoinit_dummy_decl_stub + +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 c0569e519c46..ad063b844c3e 100644 --- a/lib/libc/gen/arc4random.c +++ b/lib/libc/gen/arc4random.c @@ -25,11 +25,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 b1d0842fe2a1..317bbf8b4beb 100644 --- a/lib/libc/gen/closedir.c +++ b/lib/libc/gen/closedir.c @@ -37,11 +37,15 @@ static char sccsid[] = "@(#)closedir.c 8.1 (Berkeley) 6/10/93"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include +#include #include #include +#include "un-namespace.h" +#include "libc_private.h" #include "telldir.h" /* @@ -53,12 +57,18 @@ closedir(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 4f6c2f3c69e3..6f1639f8a7fc 100644 --- a/lib/libc/gen/daemon.c +++ b/lib/libc/gen/daemon.c @@ -37,9 +37,11 @@ static char sccsid[] = "@(#)daemon.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include +#include "un-namespace.h" int daemon(nochdir, noclose) @@ -63,9 +65,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 69c51e3d92d7..f7532b11d4b1 100644 --- a/lib/libc/gen/devname.c +++ b/lib/libc/gen/devname.c @@ -42,7 +42,6 @@ static char sccsid[] = "@(#)devname.c 8.2 (Berkeley) 4/29/95"; #include #include -#include #include #include #include diff --git a/lib/libc/gen/disklabel.c b/lib/libc/gen/disklabel.c index c7ac0b4f8a99..19c0d19525d0 100644 --- a/lib/libc/gen/disklabel.c +++ b/lib/libc/gen/disklabel.c @@ -45,7 +45,6 @@ static const char rcsid[] = #include #include -#include #include #include #include diff --git a/lib/libc/gen/exec.c b/lib/libc/gen/exec.c index 04bd2d2a5ad0..51ee6ed8455a 100644 --- a/lib/libc/gen/exec.c +++ b/lib/libc/gen/exec.c @@ -41,6 +41,7 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include @@ -56,6 +57,7 @@ static const char rcsid[] = #else #include #endif +#include "un-namespace.h" extern char **environ; @@ -97,7 +99,7 @@ execl(name, arg, va_alist) while ((argv[n] = va_arg(ap, char *)) != NULL) n++; va_end(ap); - return (execve(name, argv, environ)); + return (_execve(name, argv, environ)); } int @@ -139,7 +141,7 @@ execle(name, arg, va_alist) n++; envp = va_arg(ap, char **); va_end(ap); - return (execve(name, argv, envp)); + return (_execve(name, argv, envp)); } int @@ -189,7 +191,7 @@ execv(name, argv) const char *name; char * const *argv; { - (void)execve(name, argv, environ); + (void)_execve(name, argv, environ); return (-1); } @@ -260,7 +262,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; @@ -279,7 +281,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 ecd79fb1600d..9170ae91503f 100644 --- a/lib/libc/gen/fstab.c +++ b/lib/libc/gen/fstab.c @@ -42,6 +42,7 @@ static char rcsid[] = #endif #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include @@ -53,6 +54,7 @@ static char rcsid[] = #include #include #include +#include "un-namespace.h" static FILE *_fs_fp; static struct fstab _fs_fstab; diff --git a/lib/libc/gen/fts-compat.c b/lib/libc/gen/fts-compat.c index f38f24e36110..c6b09ffaac5c 100644 --- a/lib/libc/gen/fts-compat.c +++ b/lib/libc/gen/fts-compat.c @@ -43,6 +43,7 @@ static char rcsid[] = "$FreeBSD$"; #endif #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include @@ -53,6 +54,7 @@ static char rcsid[] = "$FreeBSD$"; #include #include #include +#include "un-namespace.h" static FTSENT *fts_alloc __P((FTS *, char *, int)); static FTSENT *fts_build __P((FTS *, int)); @@ -1082,7 +1084,7 @@ fts_safe_changedir(sp, p, fd) return (0); if (fd < 0 && (newfd = _open(p->fts_accpath, O_RDONLY, 0)) < 0) return (-1); - if (fstat(newfd, &sb)) { + if (_fstat(newfd, &sb)) { ret = -1; goto bail; } diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c index f38f24e36110..c6b09ffaac5c 100644 --- a/lib/libc/gen/fts.c +++ b/lib/libc/gen/fts.c @@ -43,6 +43,7 @@ static char rcsid[] = "$FreeBSD$"; #endif #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include @@ -53,6 +54,7 @@ static char rcsid[] = "$FreeBSD$"; #include #include #include +#include "un-namespace.h" static FTSENT *fts_alloc __P((FTS *, char *, int)); static FTSENT *fts_build __P((FTS *, int)); @@ -1082,7 +1084,7 @@ fts_safe_changedir(sp, p, fd) return (0); if (fd < 0 && (newfd = _open(p->fts_accpath, 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 edb828b0fad0..4500062ef2a2 100644 --- a/lib/libc/gen/getcap.c +++ b/lib/libc/gen/getcap.c @@ -40,10 +40,10 @@ static char sccsid[] = "@(#)getcap.c 8.3 (Berkeley) 3/25/94"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include -#include #include #include #include @@ -51,6 +51,9 @@ static char sccsid[] = "@(#)getcap.c 8.3 (Berkeley) 3/25/94"; #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 e2ea8200be58..365538880b20 100644 --- a/lib/libc/gen/getcwd.c +++ b/lib/libc/gen/getcwd.c @@ -37,6 +37,7 @@ static char sccsid[] = "@(#)getcwd.c 8.5 (Berkeley) 2/7/95"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include @@ -47,6 +48,7 @@ static char sccsid[] = "@(#)getcwd.c 8.5 (Berkeley) 2/7/95"; #include #include #include +#include "un-namespace.h" #define ISDOT(dp) \ (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || \ @@ -166,7 +168,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 5adc46cc28f3..10261ae88131 100644 --- a/lib/libc/gen/getlogin.c +++ b/lib/libc/gen/getlogin.c @@ -44,22 +44,19 @@ static char sccsid[] = "@(#)getlogin.c 8.1 (Berkeley) 6/4/93"; #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) + +extern int _getlogin(char *, int); -int _logname_valid; /* known to setlogin() */ +int _logname_valid; /* known to setlogin() */ +static pthread_mutex_t logname_mutex = PTHREAD_MUTEX_INITIALIZER; static char * getlogin_basic(int *status) @@ -68,7 +65,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/getpass.c b/lib/libc/gen/getpass.c index 60e92b73e75e..f44cf17d2345 100644 --- a/lib/libc/gen/getpass.c +++ b/lib/libc/gen/getpass.c @@ -37,6 +37,7 @@ static char sccsid[] = "@(#)getpass.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include @@ -44,6 +45,7 @@ static char sccsid[] = "@(#)getpass.c 8.1 (Berkeley) 6/4/93"; #include #include #include +#include "un-namespace.h" static struct termios oterm, term; static FILE *fp; @@ -74,7 +76,7 @@ getpass(prompt) sigemptyset(&nset); sigaddset(&nset, SIGINT); sigaddset(&nset, SIGTSTP); - (void)sigprocmask(SIG_BLOCK, &nset, &oset); + (void)_sigprocmask(SIG_BLOCK, &nset, &oset); (void)tcgetattr(fileno(fp), &oterm); term = oterm; @@ -89,7 +91,7 @@ getpass(prompt) (void)_write(fileno(outfp), "\n", 1); (void)tcsetattr(fileno(fp), TCSAFLUSH|TCSASOFT, &oterm); - (void)sigprocmask(SIG_SETMASK, &oset, NULL); + (void)_sigprocmask(SIG_SETMASK, &oset, NULL); if (fp != stdin) (void)fclose(fp); diff --git a/lib/libc/gen/getpwent.c b/lib/libc/gen/getpwent.c index 38c90b48e855..f3bccd5037b9 100644 --- a/lib/libc/gen/getpwent.c +++ b/lib/libc/gen/getpwent.c @@ -40,6 +40,7 @@ static const char *rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#include "un-namespace.h" #include #include #include @@ -62,6 +63,7 @@ static const char *rcsid[] = #include #include #endif +#include "un-namespace.h" extern void setnetgrent __P((char *)); extern int getnetgrent __P((char **, char **, char **)); diff --git a/lib/libc/gen/getvfsent.c b/lib/libc/gen/getvfsent.c index bf3ca20f643a..2b8998cbd0f2 100644 --- a/lib/libc/gen/getvfsent.c +++ b/lib/libc/gen/getvfsent.c @@ -2,6 +2,8 @@ * getvfsent.c - get a listing of installed filesystems * Written September 1994 by Garrett A. Wollman * This file is in the public domain. + * + * $FreeBSD$ */ #include @@ -14,7 +16,6 @@ #include #include #include -#include #include /* XXX hide some compatibility problems. */ diff --git a/lib/libc/gen/isatty.c b/lib/libc/gen/isatty.c index f14f4704d9a3..2339c3a82298 100644 --- a/lib/libc/gen/isatty.c +++ b/lib/libc/gen/isatty.c @@ -29,6 +29,8 @@ * 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$ */ #if defined(LIBC_SCCS) && !defined(lint) @@ -37,10 +39,6 @@ static char sccsid[] = "@(#)isatty.c 8.1 (Berkeley) 6/4/93"; #include #include -#ifdef _THREAD_SAFE -#include -#include "pthread_private.h" -#endif int isatty(fd) @@ -49,15 +47,6 @@ isatty(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 15b5b210da87..b881b119d69f 100644 --- a/lib/libc/gen/lockf.c +++ b/lib/libc/gen/lockf.c @@ -43,9 +43,11 @@ static const char rcsid[]= "$FreeBSD$"; #endif +#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 f45906785c72..ed0fd48ab052 100644 --- a/lib/libc/gen/nlist.c +++ b/lib/libc/gen/nlist.c @@ -37,6 +37,7 @@ static char sccsid[] = "@(#)nlist.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include @@ -47,6 +48,7 @@ static char sccsid[] = "@(#)nlist.c 8.1 (Berkeley) 6/4/93"; #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 bd7fc82ab0b7..51d7090fd20f 100644 --- a/lib/libc/gen/opendir.c +++ b/lib/libc/gen/opendir.c @@ -37,6 +37,7 @@ static char sccsid[] = "@(#)opendir.c 8.8 (Berkeley) 5/1/95"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include @@ -46,9 +47,9 @@ static char sccsid[] = "@(#)opendir.c 8.8 (Berkeley) 5/1/95"; #include #include #include +#include "un-namespace.h" #include "telldir.h" - /* * Open a directory. */ @@ -56,7 +57,6 @@ DIR * opendir(name) const char *name; { - return (__opendir2(name, DTF_HIDEW|DTF_NODUP)); } @@ -73,8 +73,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); @@ -85,7 +85,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; @@ -102,7 +102,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) @@ -114,7 +114,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"); } else { @@ -140,7 +140,7 @@ __opendir2(name, flags) do { /* * Always make at least DIRBLKSIZ bytes - * available to getdirentries + * available to _getdirentries */ if (space < DIRBLKSIZ) { space += incr; @@ -151,7 +151,7 @@ __opendir2(name, flags) ddptr = buf + (len - space); } - n = getdirentries(fd, ddptr, space, &dirp->dd_seek); + n = _getdirentries(fd, ddptr, space, &dirp->dd_seek); if (n > 0) { ddptr += n; space -= n; @@ -265,6 +265,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 f7ddb1805b2f..ca98a65da401 100644 --- a/lib/libc/gen/pause.c +++ b/lib/libc/gen/pause.c @@ -48,7 +48,5 @@ __pause() { return sigpause(sigblock(0L)); } - -#ifndef _THREAD_SAFE __weak_reference(__pause, pause); -#endif +__weak_reference(__pause, _pause); diff --git a/lib/libc/gen/popen.c b/lib/libc/gen/popen.c index 7939b8fb1b7c..2070f8369a4a 100644 --- a/lib/libc/gen/popen.c +++ b/lib/libc/gen/popen.c @@ -40,6 +40,7 @@ static char sccsid[] = "@(#)popen.c 8.3 (Berkeley) 5/3/95"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include @@ -50,6 +51,7 @@ static char sccsid[] = "@(#)popen.c 8.3 (Berkeley) 5/3/95"; #include #include #include +#include "un-namespace.h" extern char **environ; @@ -70,7 +72,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, '+')) { @@ -105,7 +107,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 @@ -114,15 +116,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]); @@ -130,7 +132,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 e437940ba881..51713f225cea 100644 --- a/lib/libc/gen/posixshm.c +++ b/lib/libc/gen/posixshm.c @@ -29,6 +29,7 @@ * $FreeBSD$ */ +#include "namespace.h" #include #include #include @@ -36,6 +37,7 @@ #include #include +#include "un-namespace.h" int shm_open(const char *path, int flags, mode_t mode) @@ -48,7 +50,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/pselect.c b/lib/libc/gen/pselect.c index 02456e27b3b7..abf273f7381a 100644 --- a/lib/libc/gen/pselect.c +++ b/lib/libc/gen/pselect.c @@ -29,11 +29,13 @@ * $FreeBSD$ */ +#include "namespace.h" #include #include #include #include +#include "un-namespace.h" /* * Emulate the POSIX 1003.1g-2000 `pselect' interface. This is the @@ -56,15 +58,15 @@ pselect(int count, fd_set *rfds, fd_set *wfds, fd_set *efds, tvp = 0; if (mask != 0) { - rv = sigprocmask(SIG_SETMASK, mask, &omask); + rv = _sigprocmask(SIG_SETMASK, mask, &omask); if (rv != 0) return rv; } - rv = select(count, rfds, wfds, efds, tvp); + rv = _select(count, rfds, wfds, efds, tvp); if (mask != 0) { sverrno = errno; - sigprocmask(SIG_SETMASK, &omask, (sigset_t *)0); + _sigprocmask(SIG_SETMASK, &omask, (sigset_t *)0); errno = sverrno; } diff --git a/lib/libc/gen/psignal.c b/lib/libc/gen/psignal.c index 7c254767ab18..e51c463fce17 100644 --- a/lib/libc/gen/psignal.c +++ b/lib/libc/gen/psignal.c @@ -41,9 +41,11 @@ static char sccsid[] = "@(#)psignal.c 8.1 (Berkeley) 6/4/93"; * 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 43c7bc20255a..9698415edf79 100644 --- a/lib/libc/gen/readdir.c +++ b/lib/libc/gen/readdir.c @@ -38,20 +38,21 @@ static char sccsid[] = "@(#)readdir.c 8.3 (Berkeley) 9/29/94"; #endif /* LIBC_SCCS and not lint */ +#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; @@ -63,7 +64,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); @@ -83,6 +84,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; @@ -91,33 +108,24 @@ readdir_r(dirp, entry, result) { struct dirent *dp; int saved_errno; -#ifdef _THREAD_SAFE - int ret; - - 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 + if (dp == NULL) return (errno); - } } else errno = saved_errno; - if (dp != NULL) - memcpy(entry, dp, sizeof *entry); - -#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 5c64b2969e46..59128c8dbf52 100644 --- a/lib/libc/gen/scandir.c +++ b/lib/libc/gen/scandir.c @@ -29,6 +29,8 @@ * 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$ */ #if defined(LIBC_SCCS) && !defined(lint) @@ -42,11 +44,13 @@ static char sccsid[] = "@(#)scandir.c 8.3 (Berkeley) 1/2/94"; * 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 @@ -74,7 +78,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 8ce57d2bf32d..2057b98fd758 100644 --- a/lib/libc/gen/seekdir.c +++ b/lib/libc/gen/seekdir.c @@ -37,9 +37,13 @@ static char sccsid[] = "@(#)seekdir.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include +#include +#include "un-namespace.h" +#include "libc_private.h" #include "telldir.h" /* @@ -51,5 +55,9 @@ seekdir(dirp, loc) DIR *dirp; long 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 e9b5d45bc4a8..fd69cdb1500b 100644 --- a/lib/libc/gen/setjmperr.c +++ b/lib/libc/gen/setjmperr.c @@ -44,8 +44,10 @@ static char sccsid[] = "@(#)setjmperr.c 8.1 (Berkeley) 6/4/93"; * 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 2c12b818b614..f05607f46e51 100644 --- a/lib/libc/gen/setmode.c +++ b/lib/libc/gen/setmode.c @@ -42,11 +42,11 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include -#include #include #include #include @@ -54,6 +54,7 @@ static const char rcsid[] = #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 */ @@ -188,10 +189,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 06960abe4b7b..245d73888e23 100644 --- a/lib/libc/gen/siginterrupt.c +++ b/lib/libc/gen/siginterrupt.c @@ -29,13 +29,18 @@ * 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$ */ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)siginterrupt.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include +#include "un-namespace.h" +#include "libc_private.h" /* * Set signal state to prevent restart of system calls @@ -49,7 +54,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); @@ -58,5 +63,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 c4057f5d33a7..5b3d71a9e730 100644 --- a/lib/libc/gen/signal.c +++ b/lib/libc/gen/signal.c @@ -29,6 +29,8 @@ * 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$ */ #if defined(LIBC_SCCS) && !defined(lint) @@ -38,7 +40,10 @@ static char sccsid[] = "@(#)signal.c 8.1 (Berkeley) 6/4/93"; /* * Almost backwards compatible signal. */ +#include "namespace.h" #include +#include "un-namespace.h" +#include "libc_private.h" sigset_t _sigintr; /* shared with siginterrupt */ @@ -54,7 +59,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 e4c4fbdc494c..701eccda5a78 100644 --- a/lib/libc/gen/sleep.c +++ b/lib/libc/gen/sleep.c @@ -39,10 +39,12 @@ static char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include #include +#include "un-namespace.h" unsigned int __sleep(seconds) @@ -68,6 +70,5 @@ __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 18d00d7dd939..d3326ed6439c 100644 --- a/lib/libc/gen/syslog.c +++ b/lib/libc/gen/syslog.c @@ -39,6 +39,7 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include @@ -59,6 +60,7 @@ static const char rcsid[] = #else #include #endif +#include "un-namespace.h" static int LogFile = -1; /* fd for log */ static int connected; /* have done connect */ @@ -235,7 +237,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. */ @@ -270,7 +272,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); } } @@ -295,7 +297,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); } @@ -304,7 +306,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) { @@ -314,7 +316,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 3c4b781e2606..6661c23d7ebd 100644 --- a/lib/libc/gen/telldir.c +++ b/lib/libc/gen/telldir.c @@ -37,12 +37,16 @@ static char sccsid[] = "@(#)telldir.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include +#include #include #include +#include "un-namespace.h" +#include "libc_private.h" #include "telldir.h" /* @@ -63,10 +67,14 @@ telldir(dirp) if ((lp = (struct ddloc *)malloc(sizeof(struct ddloc))) == NULL) return (-1); + if (__isthreaded) + _pthread_mutex_lock((pthread_mutex_t *)&dirp->dd_lock); lp->loc_index = dirp->dd_td->td_loccnt++; lp->loc_seek = dirp->dd_seek; lp->loc_loc = dirp->dd_loc; LIST_INSERT_HEAD(&dirp->dd_td->td_locq, lp, loc_lqe); + if (__isthreaded) + _pthread_mutex_unlock((pthread_mutex_t *)&dirp->dd_lock); return (lp->loc_index); } @@ -94,7 +102,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; } diff --git a/lib/libc/gen/telldir.h b/lib/libc/gen/telldir.h index be8a9f5417c2..4fb4cb6ca8aa 100644 --- a/lib/libc/gen/telldir.h +++ b/lib/libc/gen/telldir.h @@ -59,7 +59,8 @@ struct _telldir { long td_loccnt; /* index of entry for sequential readdir's */ }; -void _reclaim_telldir __P((DIR *)); -void _seekdir __P((DIR *, long)); +struct dirent *_readdir_unlocked(DIR *); +void _reclaim_telldir(DIR *); +void _seekdir(DIR *, long); #endif diff --git a/lib/libc/gen/termios.c b/lib/libc/gen/termios.c index f321876e9430..b262305458d5 100644 --- a/lib/libc/gen/termios.c +++ b/lib/libc/gen/termios.c @@ -37,6 +37,7 @@ static char sccsid[] = "@(#)termios.c 8.2 (Berkeley) 2/21/94"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include @@ -45,6 +46,7 @@ static char sccsid[] = "@(#)termios.c 8.2 (Berkeley) 2/21/94"; #include #include #include +#include "un-namespace.h" int tcgetattr(fd, t) @@ -52,7 +54,7 @@ tcgetattr(fd, t) struct termios *t; { - return (ioctl(fd, TIOCGETA, t)); + return (_ioctl(fd, TIOCGETA, t)); } int @@ -69,11 +71,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); @@ -92,7 +94,7 @@ tcsetpgrp(fd, pgrp) int s; s = pgrp; - return (ioctl(fd, TIOCSPGRP, &s)); + return (_ioctl(fd, TIOCSPGRP, &s)); } pid_t @@ -101,7 +103,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); @@ -180,10 +182,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); } @@ -192,12 +194,11 @@ int __tcdrain(fd) int fd; { - return (ioctl(fd, TIOCDRAIN, 0)); + return (_ioctl(fd, TIOCDRAIN, 0)); } -#ifndef _THREAD_SAFE __weak_reference(__tcdrain, tcdrain); -#endif +__weak_reference(__tcdrain, _tcdrain); int tcflush(fd, which) @@ -219,7 +220,7 @@ tcflush(fd, which) errno = EINVAL; return (-1); } - return (ioctl(fd, TIOCFLUSH, &com)); + return (_ioctl(fd, TIOCFLUSH, &com)); } int @@ -231,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 cb01870e3d3b..55fc91867223 100644 --- a/lib/libc/gen/ttyname.c +++ b/lib/libc/gen/ttyname.c @@ -29,12 +29,15 @@ * 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$ */ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)ttyname.c 8.2 (Berkeley) 1/27/94"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include @@ -42,42 +45,44 @@ static char sccsid[] = "@(#)ttyname.c 8.2 (Berkeley) 1/27/94"; #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); -char * +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) +char * +ttyname_r(int fd, char *buf, size_t len) { - register struct dirent *dirp; - register DIR *dp; - struct stat dsb; - struct stat sb; - char *rval; - int minlen; + struct dirent *dirp; + DIR *dp; + struct stat dsb; + struct stat sb; + char *rval; + int minlen; rval = NULL; @@ -85,7 +90,7 @@ __ttyname_r_basic(int fd, char *buf, size_t len) if (!isatty(fd)) return (rval); /* Must be a character device. */ - if (_thread_sys_fstat(fd, &sb) || !S_ISCHR(sb.st_mode)) + if (_fstat(fd, &sb) || !S_ISCHR(sb.st_mode)) return (rval); /* Must have enough room */ if (len <= sizeof(_PATH_DEV)) @@ -110,25 +115,27 @@ __ttyname_r_basic(int fd, char *buf, size_t len) return (rval); } -char * -__ttyname_basic(int fd) +static char * +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); - return (NULL); + _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; } - 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); } @@ -136,34 +143,16 @@ __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 __P((int, struct stat *)); - -char * -ttyname(fd) - int fd; +static char * +ttyname_unthreaded(int fd) { - struct stat sb; - struct termios ttyb; - DB *db; - DBT data, key; + struct stat sb; + struct termios ttyb; + DB *db; + DBT data, key; struct { mode_t type; dev_t dev; @@ -173,7 +162,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)) ) { @@ -194,13 +183,11 @@ ttyname(fd) } static char * -oldttyname(fd, sb) - int fd; - struct stat *sb; +oldttyname(int fd, struct stat *sb) { - register struct dirent *dirp; - register DIR *dp; - struct stat dsb; + struct dirent *dirp; + struct stat dsb; + DIR *dp; if ((dp = opendir(_PATH_DEV)) == NULL) return (NULL); @@ -219,4 +206,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 651edf98b882..647b5c066980 100644 --- a/lib/libc/gen/usleep.c +++ b/lib/libc/gen/usleep.c @@ -39,8 +39,10 @@ static char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include +#include "un-namespace.h" int usleep(useconds) diff --git a/lib/libc/gen/vis.c b/lib/libc/gen/vis.c index 7f10aa558d64..35f24bf1b360 100644 --- a/lib/libc/gen/vis.c +++ b/lib/libc/gen/vis.c @@ -40,6 +40,7 @@ static char sccsid[] = "@(#)vis.c 8.1 (Berkeley) 7/19/93"; #include #include #include +#include #include #define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') diff --git a/lib/libc/gen/wait.c b/lib/libc/gen/wait.c index 366e2623b44e..baba6cdf38c6 100644 --- a/lib/libc/gen/wait.c +++ b/lib/libc/gen/wait.c @@ -37,18 +37,18 @@ static char sccsid[] = "@(#)wait.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include #include +#include "un-namespace.h" pid_t -__wait(istat) - int *istat; +__wait(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 c8d8f9e28027..21623d49f465 100644 --- a/lib/libc/gen/wait3.c +++ b/lib/libc/gen/wait3.c @@ -29,16 +29,20 @@ * 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$ */ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)wait3.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include #include +#include "un-namespace.h" pid_t wait3(istat, options, rup) @@ -46,5 +50,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 350157a9c393..fbdf16b90a8d 100644 --- a/lib/libc/gen/waitpid.c +++ b/lib/libc/gen/waitpid.c @@ -37,24 +37,18 @@ static char sccsid[] = "@(#)waitpid.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ +#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 6bf3d5b96f68..f0209bbdb25d 100644 --- a/lib/libc/gmon/gmon.c +++ b/lib/libc/gmon/gmon.c @@ -37,6 +37,7 @@ static char sccsid[] = "@(#)gmon.c 8.1 (Berkeley) 6/4/93"; #endif +#include "namespace.h" #include #include #include @@ -46,7 +47,9 @@ static char sccsid[] = "@(#)gmon.c 8.1 (Berkeley) 6/4/93"; #include #include #include +#include #include +#include "un-namespace.h" #if defined(__ELF__) && defined(i386) extern char *minbrk asm (".minbrk"); diff --git a/lib/libc/i386/SYS.h b/lib/libc/i386/SYS.h index cadbecb1b31a..2d585628107c 100644 --- a/lib/libc/i386/SYS.h +++ b/lib/libc/i386/SYS.h @@ -61,31 +61,28 @@ * 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 _thread_sys_ to the function + * 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(_thread_sys_,x)); \ + 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(_thread_sys_,x)); \ + +#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 #ifdef __ELF__ #define KERNCALL int $0x80 /* Faster */ diff --git a/lib/libc/i386/gen/_setjmp.S b/lib/libc/i386/gen/_setjmp.S index 9c66308dc502..5932feeee0c5 100644 --- a/lib/libc/i386/gen/_setjmp.S +++ b/lib/libc/i386/gen/_setjmp.S @@ -66,12 +66,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 738407a1a8f2..5e92c979a7dc 100644 --- a/lib/libc/i386/gen/setjmp.S +++ b/lib/libc/i386/gen/setjmp.S @@ -61,11 +61,7 @@ ENTRY(setjmp) pushl %eax /* (sigset_t*)oset */ pushl $0 /* (sigset_t*)set */ pushl $1 /* SIG_BLOCK */ -#ifdef _THREAD_SAFE - call PIC_PLT(CNAME(_thread_sys_sigprocmask)) -#else - call PIC_PLT(CNAME(sigprocmask)) -#endif + call PIC_PLT(CNAME(_sigprocmask)) addl $12,%esp PIC_EPILOGUE movl 4(%esp),%ecx @@ -80,10 +76,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 @@ -91,11 +85,7 @@ ENTRY(__longjmp) leal 28(%edx), %eax pushl %eax /* (sigset_t*)set */ pushl $3 /* SIG_SETMASK */ -#ifdef _THREAD_SAFE - call PIC_PLT(CNAME(_thread_sys_sigprocmask)) -#else - call PIC_PLT(CNAME(sigprocmask)) -#endif + 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 40aebb65e53f..96aae6897034 100644 --- a/lib/libc/i386/gen/sigsetjmp.S +++ b/lib/libc/i386/gen/sigsetjmp.S @@ -52,9 +52,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. */ @@ -70,11 +67,7 @@ ENTRY(sigsetjmp) pushl %eax /* (sigset_t*)oset */ pushl $0 /* (sigset_t*)set */ pushl $1 /* SIG_BLOCK */ -#ifdef _THREAD_SAFE - call PIC_PLT(CNAME(_thread_sys_sigprocmask)) -#else - call PIC_PLT(CNAME(sigprocmask)) -#endif + call PIC_PLT(CNAME(_sigprocmask)) addl $12,%esp PIC_EPILOGUE movl 4(%esp),%ecx @@ -89,10 +82,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) @@ -102,11 +93,7 @@ ENTRY(__siglongjmp); leal 28(%edx), %eax pushl %eax /* (sigset_t*)set */ pushl $3 /* SIG_SETMASK */ -#ifdef _THREAD_SAFE - call PIC_PLT(CNAME(_thread_sys_sigprocmask)) -#else - call PIC_PLT(CNAME(sigprocmask)) -#endif + call PIC_PLT(CNAME(_sigprocmask)) addl $12,%esp PIC_EPILOGUE movl 4(%esp),%edx diff --git a/lib/libc/i386/sys/Ovfork.S b/lib/libc/i386/sys/Ovfork.S index 8ec99aeaad21..8981308dbdb3 100644 --- a/lib/libc/i386/sys/Ovfork.S +++ b/lib/libc/i386/sys/Ovfork.S @@ -51,12 +51,11 @@ * %eax == pid of child in parent, %eax == pid of parent in child. * */ - -#ifdef _THREAD_SAFE -ENTRY(_thread_sys_vfork) -#else -ENTRY(vfork) -#endif + .weak _vfork + .set _vfork,__sys_vfork + .weak vfork + .set vfork,__sys_vfork +ENTRY(__sys_vfork) popl %ecx /* my rta into ecx */ lea SYS_vfork,%eax KERNCALL diff --git a/lib/libc/i386/sys/setlogin.S b/lib/libc/i386/sys/setlogin.S index a4d74b0d10cf..3ba52c5cde38 100644 --- a/lib/libc/i386/sys/setlogin.S +++ b/lib/libc/i386/sys/setlogin.S @@ -43,7 +43,7 @@ #include "SYS.h" -.globl CNAME(_logname_valid) /* in getlogin() */ +.globl CNAME(_logname_valid) /* in _getlogin() */ SYSCALL(setlogin) #ifdef PIC diff --git a/lib/libc/ia64/SYS.h b/lib/libc/ia64/SYS.h index 303b50e34b58..1cbc970a65b2 100644 --- a/lib/libc/ia64/SYS.h +++ b/lib/libc/ia64/SYS.h @@ -75,50 +75,35 @@ END(label); * 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 _thread_sys_ to the function + * For the thread_safe versions, we prepend __sys_ to the function * name so that the 'C' wrapper can go around the real name. */ #define PCALL(name) \ - CALL(_thread_sys_ ## name) + CALL(__sys_ ## name) #define PENTRY(name, args) \ -ENTRY(_thread_sys_ ## name,args) +ENTRY(__sys_ ## name,args) #define PEND(name) \ -END(_thread_sys_ ## name) +END(__sys_ ## name) #define PSYSCALL(name) \ PENTRY(name,0); /* XXX # of args? */ \ CALLSYS_ERROR(name) #define PRSYSCALL(name) \ -PENTRY(name,0); /* XXX # of args? */ \ +PENTRY(_sys_ ## name,0); /* XXX # of args? */ \ + WEAK_ALIAS(name, __sys_ ## name); \ + WEAK_ALIAS(_ ## name, __sys_ ## name); \ CALLSYS_ERROR(name) \ br.ret.sptk.few rp; \ PEND(name) #define PPSEUDO(label,name) \ -PENTRY(label,0); /* XXX # of args? */ \ +PENTRY(label,0); /* XXX # of args? */ \ CALLSYS_ERROR(name); \ br.ret.sptk.few rp; \ PEND(label) - -#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) -#define PENTRY(x,y) ENTRY(x,y) -#define PEND(x) END(x) -#define PCALL(x) CALL(x) -#endif diff --git a/lib/libc/ia64/gen/_setjmp.S b/lib/libc/ia64/gen/_setjmp.S index 5baf3ffa59a6..cd2482fba3f3 100644 --- a/lib/libc/ia64/gen/_setjmp.S +++ b/lib/libc/ia64/gen/_setjmp.S @@ -90,12 +90,8 @@ ENTRY(_setjmp, 1) #endif END(_setjmp) -#ifdef _THREAD_SAFE +XENTRY(_longjmp) ENTRY(___longjmp, 2) -#else -XENTRY(___longjmp) -ENTRY(_longjmp, 2) -#endif #if 0 LDGP(pv) ldq t0, ((31 + 4) * 8)(a0) /* magic in sc_regs[31] */ @@ -132,8 +128,4 @@ botch: CALL(abort) RET /* "can't" get here... */ #endif -#ifdef _THREAD_SAFE END(___longjmp) -#else -END(_longjmp) -#endif diff --git a/lib/libc/ia64/gen/modf.c b/lib/libc/ia64/gen/modf.c index 42c79cf79f62..0dae6573f8fe 100644 --- a/lib/libc/ia64/gen/modf.c +++ b/lib/libc/ia64/gen/modf.c @@ -30,7 +30,6 @@ #include #include -#include #include /* diff --git a/lib/libc/ia64/gen/setjmp.S b/lib/libc/ia64/gen/setjmp.S index f1c5399523f3..e61850a60323 100644 --- a/lib/libc/ia64/gen/setjmp.S +++ b/lib/libc/ia64/gen/setjmp.S @@ -69,12 +69,12 @@ ENTRY(setjmp, 1) lda a2, (71 * 8)(a0) /* oset: sc_reserved */ mov zero, a1 /* set: NULL */ addq a1, 1, a0 /* how: SIG_BLOCK */ - PCALL(sigprocmask) /* see what's blocked */ + CALL(_sigprocmask) /* see what's blocked */ lda sp, -24(sp) /* sizeof struct sigaltstack */ mov zero, a0 mov sp, a1 - PCALL(sigaltstack) + CALL(_sigaltstack) ldl t0, 16(sp) /* offset of ss_flags */ lda sp, 24(sp) /* sizeof struct sigaltstack */ ldq ra, ((26 + 4) * 8)(s0) /* restore return address */ @@ -119,24 +119,15 @@ ENTRY(setjmp, 1) #endif END(setjmp) -#ifdef _THREAD_SAFE +XENTRY(longjmp) ENTRY(__longjmp, 2) -#else -XENTRY(__longjmp) -ENTRY(longjmp, 2) -#endif #if 0 LDGP(pv) stq a1, (( 0 + 4) * 8)(a0) /* save return value */ - PCALL(sigreturn) /* use sigreturn to return */ + PCALL(_sigreturn) /* use sigreturn to return */ botch: CALL(longjmperror) CALL(abort) RET /* "can't" get here... */ -#endif -#ifdef _THREAD_SAFE END(__longjmp) -#else -END(longjmp) -#endif diff --git a/lib/libc/ia64/gen/sigsetjmp.S b/lib/libc/ia64/gen/sigsetjmp.S index a9419782ebef..8ef32ccfaff0 100644 --- a/lib/libc/ia64/gen/sigsetjmp.S +++ b/lib/libc/ia64/gen/sigsetjmp.S @@ -55,12 +55,8 @@ Lsavesig: #endif END(sigsetjmp) -#ifdef _THREAD_SAFE +XENTRY(siglongjmp) ENTRY(__siglongjmp, 2) -#else -XENTRY(__siglongjmp) -ENTRY(siglongjmp, 2) -#endif #if 0 LDGP(pv) ldq t0, (81 * 8)(a0) /* get the mask */ @@ -69,8 +65,4 @@ ENTRY(siglongjmp, 2) Lrestoresig: jmp zero, longjmp #endif -#ifdef _THREAD_SAFE END(__siglongjmp) -#else -END(siglongjmp) -#endif diff --git a/lib/libc/include/libc_private.h b/lib/libc/include/libc_private.h index 1e20bc7fcb74..f356e1862f15 100644 --- a/lib/libc/include/libc_private.h +++ b/lib/libc/include/libc_private.h @@ -53,7 +53,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 /* @@ -61,6 +61,6 @@ 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) #endif /* _LIBC_PRIVATE_H_ */ diff --git a/lib/libc/include/namespace.h b/lib/libc/include/namespace.h new file mode 100644 index 000000000000..95acce4019a0 --- /dev/null +++ b/lib/libc/include/namespace.h @@ -0,0 +1,134 @@ +/* + * 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$ + * + */ + +#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/un-namespace.h b/lib/libc/include/un-namespace.h new file mode 100644 index 000000000000..4d2e8bd8807a --- /dev/null +++ b/lib/libc/include/un-namespace.h @@ -0,0 +1,134 @@ +/* + * 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$ + */ + +#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/big5.c b/lib/libc/locale/big5.c index b8628ddcfd94..dcbe168d8ebf 100644 --- a/lib/libc/locale/big5.c +++ b/lib/libc/locale/big5.c @@ -40,7 +40,6 @@ static char sccsid[] = "@(#)big5.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ -#include #include #include #include diff --git a/lib/libc/locale/collate.c b/lib/libc/locale/collate.c index 373019cca40d..13ad7706ba1b 100644 --- a/lib/libc/locale/collate.c +++ b/lib/libc/locale/collate.c @@ -27,6 +27,7 @@ * $FreeBSD$ */ +#include "namespace.h" #include #include #include @@ -34,6 +35,8 @@ #include #include #include +#include "un-namespace.h" + #include "collate.h" #include "setlocale.h" @@ -46,7 +49,7 @@ struct __collate_st_chain_pri __collate_chain_pri_table[TABLE_SIZE]; #define FREAD(a, b, c, d) \ do { \ - if(fread(a, b, c, d) != c) { \ + if (fread(a, b, c, d) != c) { \ fclose(d); \ return -1; \ } \ diff --git a/lib/libc/locale/mskanji.c b/lib/libc/locale/mskanji.c index 6c3199ebbfa3..0b6ced8d37f6 100644 --- a/lib/libc/locale/mskanji.c +++ b/lib/libc/locale/mskanji.c @@ -39,7 +39,6 @@ static char sccsid[] = "@(#)mskanji.c 1.0 (Phase One) 5/5/95"; #include -#include #include #include #include diff --git a/lib/libc/locale/none.c b/lib/libc/locale/none.c index 41f70aef7a10..ff736ffd5605 100644 --- a/lib/libc/locale/none.c +++ b/lib/libc/locale/none.c @@ -32,6 +32,8 @@ * 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$ */ #if defined(LIBC_SCCS) && !defined(lint) @@ -41,7 +43,6 @@ static char sccsid[] = "@(#)none.c 8.1 (Berkeley) 6/4/93"; #include #include #include -#include #include rune_t _none_sgetrune __P((const char *, size_t, char const **)); diff --git a/lib/libc/locale/rune.c b/lib/libc/locale/rune.c index bc4d07cf2c24..f0a54907c917 100644 --- a/lib/libc/locale/rune.c +++ b/lib/libc/locale/rune.c @@ -32,18 +32,22 @@ * 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$ */ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)rune.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include #include #include #include +#include "un-namespace.h" _RuneLocale * _Read_RuneMagi(fp) @@ -56,7 +60,7 @@ _Read_RuneMagi(fp) struct stat sb; int x; - if (fstat(fileno(fp), &sb) < 0) + if (_fstat(fileno(fp), &sb) < 0) return(0); if (sb.st_size < sizeof(_RuneLocale)) diff --git a/lib/libc/locale/utf2.c b/lib/libc/locale/utf2.c index 81a9412b74e2..3fbe9c504aa8 100644 --- a/lib/libc/locale/utf2.c +++ b/lib/libc/locale/utf2.c @@ -40,7 +40,6 @@ static char sccsid[] = "@(#)utf2.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ -#include #include #include #include diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c index 10ddd3a48be8..9e498e5d70bd 100644 --- a/lib/libc/net/getaddrinfo.c +++ b/lib/libc/net/getaddrinfo.c @@ -86,6 +86,7 @@ * - classful IPv4 numeric (127.1) is allowed. */ +#include "namespace.h" #include #include #include @@ -106,6 +107,7 @@ #include #include #include +#include "un-namespace.h" #if defined(__KAME__) && defined(INET6) # define FAITH @@ -665,7 +667,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; @@ -1059,18 +1061,18 @@ 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); } } 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 eeecd22cded5..478d2d21d5ba 100644 --- a/lib/libc/net/gethostbyht.c +++ b/lib/libc/net/gethostbyht.c @@ -63,7 +63,6 @@ static char rcsid[] = "$FreeBSD$"; #include #include #include -#include #include #include #include diff --git a/lib/libc/net/gethostnamadr.c b/lib/libc/net/gethostnamadr.c index d5644a845c50..80e663741b5e 100644 --- a/lib/libc/net/gethostnamadr.c +++ b/lib/libc/net/gethostnamadr.c @@ -35,7 +35,6 @@ static char rcsid[] = "$FreeBSD$"; #include #include #include -#include #include #include #include @@ -117,7 +116,6 @@ gethostbyaddr(const char *addr, int len, int type) return hp; } -#ifdef _THREAD_SAFE struct hostent_data; /* @@ -136,7 +134,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 a0a034e2917d..6b8119612bca 100644 --- a/lib/libc/net/getifaddrs.c +++ b/lib/libc/net/getifaddrs.c @@ -28,6 +28,7 @@ * NOTE: SIOCGIFCONF case is not LP64 friendly. it also does not perform * try-and-error for region size. */ +#include "namespace.h" #include #include #include @@ -39,10 +40,10 @@ #include #endif -#include #include #include #include +#include "un-namespace.h" #if !defined(AF_LINK) #define SA_LEN(sa) sizeof(struct sockaddr) @@ -194,10 +195,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/getnetbydns.c b/lib/libc/net/getnetbydns.c index 582710350685..433b3b8451fd 100644 --- a/lib/libc/net/getnetbydns.c +++ b/lib/libc/net/getnetbydns.c @@ -73,7 +73,6 @@ static char rcsid[] = "$FreeBSD$"; #include #include #include -#include #include #include #include diff --git a/lib/libc/net/getnetnamadr.c b/lib/libc/net/getnetnamadr.c index 6d9dbfa891d5..2c5c9185bb90 100644 --- a/lib/libc/net/getnetnamadr.c +++ b/lib/libc/net/getnetnamadr.c @@ -34,7 +34,6 @@ static char rcsid[] = "$FreeBSD$"; #include #include #include -#include #include #include #include diff --git a/lib/libc/net/herror.c b/lib/libc/net/herror.c index 0ab744843251..e42badfd8723 100644 --- a/lib/libc/net/herror.c +++ b/lib/libc/net/herror.c @@ -53,11 +53,13 @@ static char sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93"; static char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include #include #include +#include "un-namespace.h" const char *h_errlist[] = { "Resolver Error 0 (no error)", @@ -94,7 +96,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/map_v4v6.c b/lib/libc/net/map_v4v6.c index ca5e55388f6e..cc6bb36c84b3 100644 --- a/lib/libc/net/map_v4v6.c +++ b/lib/libc/net/map_v4v6.c @@ -70,7 +70,6 @@ static char rcsid[] = "$FreeBSD$"; #include #include #include -#include #include typedef union { diff --git a/lib/libc/net/name6.c b/lib/libc/net/name6.c index 36df9a0c037a..4ab24b317596 100644 --- a/lib/libc/net/name6.c +++ b/lib/libc/net/name6.c @@ -94,6 +94,7 @@ * rewrite resolvers to be thread safe */ +#include "namespace.h" #include #include #include @@ -112,6 +113,7 @@ #include #include #include +#include "un-namespace.h" #ifndef _PATH_HOSTS #define _PATH_HOSTS "/etc/hosts" @@ -255,11 +257,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); @@ -267,7 +269,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); } @@ -1699,11 +1701,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; @@ -1711,12 +1713,12 @@ _icmp_fqdn_query(const struct in6_addr *addr, int ifindex) FD_SET(s, &s_fds); for (;;) { fds = s_fds; - if (select(s + 1, &fds, NULL, NULL, &tout) <= 0) { + if (_select(s + 1, &fds, NULL, NULL, &tout) <= 0) { _close(s); 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 3392cd532e21..3fad8d6b9b90 100644 --- a/lib/libc/net/rcmd.c +++ b/lib/libc/net/rcmd.c @@ -37,6 +37,7 @@ static char sccsid[] = "@(#)rcmd.c 8.3 (Berkeley) 3/26/94"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include @@ -59,6 +60,7 @@ static char sccsid[] = "@(#)rcmd.c 8.3 (Berkeley) 3/26/94"; #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; @@ -136,7 +138,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) { @@ -151,11 +155,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) { @@ -168,7 +173,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) { @@ -214,7 +220,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, @@ -234,7 +240,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", @@ -245,7 +251,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); @@ -297,7 +303,7 @@ again: } goto bad2; } - sigsetmask(oldmask); + _sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, NULL); freeaddrinfo(res); return (s); bad2: @@ -305,7 +311,7 @@ bad2: (void)_close(*fd2p); bad: (void)_close(s); - sigsetmask(oldmask); + _sigprocmask(SIG_SETMASK, (const sigset_t *)&oldmask, NULL); freeaddrinfo(res); return (-1); } @@ -345,12 +351,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); @@ -486,7 +492,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 65ec9d4b3878..6d4ac0e5fe93 100644 --- a/lib/libc/net/recv.c +++ b/lib/libc/net/recv.c @@ -29,16 +29,20 @@ * 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$ */ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)recv.c 8.2 (Berkeley) 2/21/94"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include +#include "un-namespace.h" ssize_t recv(s, buf, len, flags) @@ -46,5 +50,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_mkupdate.c b/lib/libc/net/res_mkupdate.c index eb31bac4dd78..7344197d1e57 100644 --- a/lib/libc/net/res_mkupdate.c +++ b/lib/libc/net/res_mkupdate.c @@ -31,7 +31,6 @@ static char rcsid[] = "$FreeBSD$"; #include #include -#include #include #include #include diff --git a/lib/libc/net/res_send.c b/lib/libc/net/res_send.c index cfcf81529408..4173f65fc1e3 100644 --- a/lib/libc/net/res_send.c +++ b/lib/libc/net/res_send.c @@ -78,6 +78,7 @@ static char rcsid[] = "$FreeBSD$"; * Send query to name server and wait for reply. */ +#include "namespace.h" #include #include #include @@ -96,6 +97,7 @@ static char rcsid[] = "$FreeBSD$"; #include #include #include +#include "un-namespace.h" #include "res_config.h" @@ -460,7 +462,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); @@ -469,7 +471,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); @@ -487,7 +489,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: @@ -639,7 +641,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); @@ -668,15 +670,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")) @@ -685,7 +687,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); @@ -717,7 +719,7 @@ read_len: kv.flags = EV_ADD | EV_ONESHOT; kv.filter = EVFILT_READ; - n = kevent(kq, &kv, 1, &kv, 1, &timeout); + n = _kevent(kq, &kv, 1, &kv, 1, &timeout); if (n < 0) { if (errno == EINTR) goto wait; @@ -738,7 +740,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/res_update.c b/lib/libc/net/res_update.c index a877d4aa1a82..6622efda3cd5 100644 --- a/lib/libc/net/res_update.c +++ b/lib/libc/net/res_update.c @@ -30,7 +30,6 @@ static char rcsid[] = "$FreeBSD$"; #include #include #include -#include #include #include #include diff --git a/lib/libc/net/send.c b/lib/libc/net/send.c index 81151c4909cd..81ded526b635 100644 --- a/lib/libc/net/send.c +++ b/lib/libc/net/send.c @@ -29,16 +29,20 @@ * 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$ */ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)send.c 8.2 (Berkeley) 2/21/94"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include +#include "un-namespace.h" ssize_t send(s, msg, len, flags) @@ -46,5 +50,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 07ba4d3af84c..063c0218f200 100644 --- a/lib/libc/nls/msgcat.c +++ b/lib/libc/nls/msgcat.c @@ -41,6 +41,7 @@ static char *rcsid = "$FreeBSD$"; * to add an error handling routine. */ +#include "namespace.h" #include #include #include @@ -52,6 +53,7 @@ static char *rcsid = "$FreeBSD$"; #include #include #include +#include "un-namespace.h" #include "msgcat.h" diff --git a/lib/libc/rpc/auth_time.c b/lib/libc/rpc/auth_time.c index 836a69ff2222..114d59d4428c 100644 --- a/lib/libc/rpc/auth_time.c +++ b/lib/libc/rpc/auth_time.c @@ -31,6 +31,7 @@ * * $FreeBSD$ */ +#include "namespace.h" #include #include #include @@ -46,6 +47,7 @@ #include #undef NIS #include +#include "un-namespace.h" /* * FreeBSD currently uses RPC 4.0, which uses portmap rather than @@ -385,7 +387,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; @@ -401,7 +403,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; @@ -409,13 +411,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."); @@ -428,7 +430,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 fb43eeddd569..2aed9ddc48c8 100644 --- a/lib/libc/rpc/bindresvport.c +++ b/lib/libc/rpc/bindresvport.c @@ -40,12 +40,14 @@ static char *rcsid = "$FreeBSD$"; * 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 @@ -78,7 +80,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; @@ -110,23 +112,23 @@ 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); - error = setsockopt(sd, proto, portrange, &portlow, + error = _setsockopt(sd, proto, portrange, &portlow, sizeof(portlow)); if (error < 0) 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); @@ -134,7 +136,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 5e3cb7bb922b..d885f1820d17 100644 --- a/lib/libc/rpc/clnt_generic.c +++ b/lib/libc/rpc/clnt_generic.c @@ -38,14 +38,14 @@ static char *rcsid = "$FreeBSD$"; */ #include #include -#include +#include #include #include /* * 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(hostname, prog, vers, proto) diff --git a/lib/libc/rpc/clnt_simple.c b/lib/libc/rpc/clnt_simple.c index 897eab5713ab..46d959b22011 100644 --- a/lib/libc/rpc/clnt_simple.c +++ b/lib/libc/rpc/clnt_simple.c @@ -40,6 +40,7 @@ static char *rcsid = "$FreeBSD$"; * Copyright (C) 1984, Sun Microsystems, Inc. */ +#include "namespace.h" #include #include #include @@ -48,6 +49,7 @@ static char *rcsid = "$FreeBSD$"; #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 18896940ef35..9e8e3948d26b 100644 --- a/lib/libc/rpc/clnt_tcp.c +++ b/lib/libc/rpc/clnt_tcp.c @@ -52,6 +52,7 @@ static char *rcsid = "$FreeBSD$"; * Now go hang yourself. */ +#include "namespace.h" #include #include #include @@ -61,6 +62,7 @@ static char *rcsid = "$FreeBSD$"; #include #include #include +#include "un-namespace.h" #define MCALL_MSG_SIZE 24 @@ -159,10 +161,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; @@ -450,7 +452,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: @@ -516,7 +518,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 3dc7710c050e..bc103ed09503 100644 --- a/lib/libc/rpc/clnt_udp.c +++ b/lib/libc/rpc/clnt_udp.c @@ -39,6 +39,7 @@ static char *rcsid = "$FreeBSD$"; * Copyright (C) 1984, Sun Microsystems, Inc. */ +#include "namespace.h" #include #include #include @@ -49,6 +50,7 @@ static char *rcsid = "$FreeBSD$"; #include #include #include +#include "un-namespace.h" /* * UDP bases client side rpc operations @@ -173,7 +175,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; @@ -182,7 +184,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; @@ -271,7 +273,7 @@ call_again: outlen = (int)XDR_GETPOS(xdrs); send_again: - if (sendto(cu->cu_sock, cu->cu_outbuf, outlen, 0, + if (_sendto(cu->cu_sock, cu->cu_outbuf, outlen, 0, (struct sockaddr *)&(cu->cu_raddr), cu->cu_rlen) != outlen) { cu->cu_error.re_errno = errno; if (fds != &readfds) @@ -301,7 +303,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); @@ -332,7 +334,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); @@ -539,7 +541,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 CLGET_SVC_ADDR: diff --git a/lib/libc/rpc/clnt_unix.c b/lib/libc/rpc/clnt_unix.c index 3b28bf841348..d55859ca1fdb 100644 --- a/lib/libc/rpc/clnt_unix.c +++ b/lib/libc/rpc/clnt_unix.c @@ -52,6 +52,7 @@ static char *rcsid = "$FreeBSD$"; * Now go hang yourself. */ +#include "namespace.h" #include #include #include @@ -63,6 +64,7 @@ static char *rcsid = "$FreeBSD$"; #include #include #include +#include "un-namespace.h" #define MCALL_MSG_SIZE 24 @@ -149,12 +151,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) @@ -441,7 +443,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: @@ -473,7 +475,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 @@ -505,7 +507,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) @@ -533,7 +535,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)); } /* @@ -571,7 +573,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 eb2917edb5c7..70c3ac00fb99 100644 --- a/lib/libc/rpc/get_myaddress.c +++ b/lib/libc/rpc/get_myaddress.c @@ -40,6 +40,7 @@ static char *rcsid = "$FreeBSD$"; * Copyright (C) 1984, Sun Microsystems, Inc. */ +#include "namespace.h" #include #include #include @@ -50,6 +51,7 @@ static char *rcsid = "$FreeBSD$"; #include #include #include +#include "un-namespace.h" /* * don't use gethostbyname, which would invoke yellow pages @@ -67,12 +69,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); } @@ -82,7 +84,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 703e038aa241..c6c3e78f1558 100644 --- a/lib/libc/rpc/key_call.c +++ b/lib/libc/rpc/key_call.c @@ -43,6 +43,7 @@ * gendeskey(deskey) - generate a secure des key */ +#include "namespace.h" #include #include #include @@ -57,6 +58,7 @@ #include #include #include +#include "un-namespace.h" #define KEY_TIMEOUT 5 /* per-try timeout in seconds */ @@ -322,7 +324,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 540187b46b6b..41bb78d582db 100644 --- a/lib/libc/rpc/pmap_clnt.c +++ b/lib/libc/rpc/pmap_clnt.c @@ -40,6 +40,7 @@ static char *rcsid = "$FreeBSD$"; * Copyright (C) 1984, Sun Microsystems, Inc. */ +#include "namespace.h" #include #include #include @@ -47,6 +48,7 @@ static char *rcsid = "$FreeBSD$"; #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 777877bac169..b51ac696b0f3 100644 --- a/lib/libc/rpc/pmap_getmaps.c +++ b/lib/libc/rpc/pmap_getmaps.c @@ -41,6 +41,7 @@ static char *rcsid = "$FreeBSD$"; * Copyright (C) 1984, Sun Microsystems, Inc. */ +#include "namespace.h" #include #include #include @@ -51,6 +52,8 @@ static char *rcsid = "$FreeBSD$"; #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 2d6f5acbe65e..bef94fdf45eb 100644 --- a/lib/libc/rpc/pmap_getport.c +++ b/lib/libc/rpc/pmap_getport.c @@ -40,12 +40,14 @@ static char *rcsid = "$FreeBSD$"; * 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 f36acf11235b..298c95613e4e 100644 --- a/lib/libc/rpc/pmap_rmt.c +++ b/lib/libc/rpc/pmap_rmt.c @@ -41,6 +41,7 @@ static char *rcsid = "$FreeBSD$"; * Copyright (C) 1984, Sun Microsystems, Inc. */ +#include "namespace.h" #include #include #include @@ -54,6 +55,8 @@ static char *rcsid = "$FreeBSD$"; #include #include #include +#include "un-namespace.h" + #define MAX_BROADCAST_SIZE 1400 static struct timeval timeout = { 3, 0 }; @@ -177,7 +180,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); } @@ -190,7 +193,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; } @@ -198,7 +201,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); @@ -263,13 +266,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) for (t.tv_sec = 4; t.tv_sec <= 14; t.tv_sec += 2) { 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) { perror("Cannot send broadcast packet"); @@ -350,8 +353,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; @@ -367,7 +370,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 1ce5617655d6..44b327966039 100644 --- a/lib/libc/rpc/rpc_dtablesize.c +++ b/lib/libc/rpc/rpc_dtablesize.c @@ -45,7 +45,7 @@ static char *rcsid = "$FreeBSD$"; * 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 0aaf7c0cdd71..61d0e864b4d4 100644 --- a/lib/libc/rpc/rtime.c +++ b/lib/libc/rpc/rtime.c @@ -41,6 +41,7 @@ * subtract seconds before Jan 1, 1970 to get * what unix uses. */ +#include "namespace.h" #include #include #include @@ -51,6 +52,7 @@ #include #include #include +#include "un-namespace.h" #if defined(LIBC_SCCS) && !defined(lint) /* from: static char sccsid[] = "@(#)rtime.c 2.2 88/08/10 4.0 RPCSRC; from 1.8 88/02/08 SMI"; */ @@ -84,7 +86,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); } @@ -98,7 +100,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); @@ -107,7 +109,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) { @@ -118,14 +120,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.c b/lib/libc/rpc/svc.c index 1f9803bb6640..94d6057e6004 100644 --- a/lib/libc/rpc/svc.c +++ b/lib/libc/rpc/svc.c @@ -45,7 +45,6 @@ static char *rcsid = "$FreeBSD$"; #include #include -#include #include #include diff --git a/lib/libc/rpc/svc_auth_des.c b/lib/libc/rpc/svc_auth_des.c index 6a937f503913..f3af780f1683 100644 --- a/lib/libc/rpc/svc_auth_des.c +++ b/lib/libc/rpc/svc_auth_des.c @@ -48,6 +48,7 @@ #include #include +#include #include #include #include diff --git a/lib/libc/rpc/svc_run.c b/lib/libc/rpc/svc_run.c index f39886a4e3d7..bc5b48a7d0dd 100644 --- a/lib/libc/rpc/svc_run.c +++ b/lib/libc/rpc/svc_run.c @@ -37,6 +37,7 @@ static char *rcsid = "$FreeBSD$"; * This is the rpc server side idle loop * Wait for input, call server program. */ +#include "namespace.h" #include #include #include @@ -45,6 +46,7 @@ static char *rcsid = "$FreeBSD$"; #include #include #include +#include "un-namespace.h" extern int __svc_fdsetsize; extern fd_set *__svc_fdset; @@ -62,7 +64,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) { @@ -79,7 +81,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 3e140104b799..b06099791f21 100644 --- a/lib/libc/rpc/svc_tcp.c +++ b/lib/libc/rpc/svc_tcp.c @@ -43,6 +43,7 @@ static char *rcsid = "$FreeBSD$"; * and a record/tcp stream. */ +#include "namespace.h" #include #include #include @@ -51,6 +52,7 @@ static char *rcsid = "$FreeBSD$"; #include #include #include +#include "un-namespace.h" /* * Ops vector for TCP/IP based rpc service handle @@ -135,14 +137,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 - udp 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); @@ -153,10 +155,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); @@ -247,7 +249,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; @@ -264,7 +266,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); } @@ -317,7 +319,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. */ @@ -349,8 +351,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: if (errno != EINTR) goto fatal_err; diff --git a/lib/libc/rpc/svc_udp.c b/lib/libc/rpc/svc_udp.c index 9849d53bb38f..0abd48696bdb 100644 --- a/lib/libc/rpc/svc_udp.c +++ b/lib/libc/rpc/svc_udp.c @@ -41,6 +41,7 @@ static char *rcsid = "$FreeBSD$"; * Copyright (C) 1984, Sun Microsystems, Inc. */ +#include "namespace.h" #include #include #include @@ -48,6 +49,7 @@ static char *rcsid = "$FreeBSD$"; #include #include #include +#include "un-namespace.h" #define rpc_buffer(xprt) ((xprt)->xp_p1) #define MAX(a, b) ((a > b) ? a : b) @@ -107,7 +109,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); } @@ -118,9 +120,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); @@ -182,7 +184,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; @@ -195,7 +197,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); } @@ -218,7 +220,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 dc680d072fed..ac92bc58a8b9 100644 --- a/lib/libc/rpc/svc_unix.c +++ b/lib/libc/rpc/svc_unix.c @@ -43,6 +43,7 @@ static char *rcsid = "$FreeBSD$"; * and a record/unix stream. */ +#include "namespace.h" #include #include #include @@ -52,6 +53,7 @@ static char *rcsid = "$FreeBSD$"; #include #include #include +#include "un-namespace.h" /* * Ops vector for AF_UNIX based rpc service handle @@ -130,7 +132,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) @@ -157,7 +159,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)); } /* @@ -194,7 +196,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); } @@ -207,10 +209,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); @@ -301,7 +303,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; @@ -359,7 +361,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. */ @@ -391,8 +393,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: if (errno != EINTR) goto fatal_err; diff --git a/lib/libc/stdio/_flock_stub.c b/lib/libc/stdio/_flock_stub.c index ada714c05db4..83a3e862ec83 100644 --- a/lib/libc/stdio/_flock_stub.c +++ b/lib/libc/stdio/_flock_stub.c @@ -35,16 +35,17 @@ #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 /* * This function is a stub for the _flockfile function in libpthread. @@ -78,4 +79,3 @@ void _funlockfile_stub(FILE *fp) { } -#endif diff --git a/lib/libc/stdio/clrerr.c b/lib/libc/stdio/clrerr.c index 4e6b72027287..3232088628a6 100644 --- a/lib/libc/stdio/clrerr.c +++ b/lib/libc/stdio/clrerr.c @@ -42,9 +42,11 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include -#undef clearerr +#include "un-namespace.h" #include "libc_private.h" +#undef clearerr void clearerr(fp) diff --git a/lib/libc/stdio/fclose.c b/lib/libc/stdio/fclose.c index 8ddb98bd11aa..0d6fd80cb92e 100644 --- a/lib/libc/stdio/fclose.c +++ b/lib/libc/stdio/fclose.c @@ -42,17 +42,19 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include -#include "local.h" +#include "un-namespace.h" #include "libc_private.h" +#include "local.h" int fclose(fp) - register FILE *fp; + FILE *fp; { - register int r; + int r; if (fp->_flags == 0) { /* not open! */ errno = EBADF; @@ -71,6 +73,12 @@ fclose(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 44341b39a500..2e72e7175a5a 100644 --- a/lib/libc/stdio/fdopen.c +++ b/lib/libc/stdio/fdopen.c @@ -40,11 +40,13 @@ static char sccsid[] = "@(#)fdopen.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ +#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 cd7fbe8a49ee..09d346bc0f8b 100644 --- a/lib/libc/stdio/fflush.c +++ b/lib/libc/stdio/fflush.c @@ -42,15 +42,19 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#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(fp) - register FILE *fp; +fflush(FILE *fp) { int retval; @@ -60,19 +64,36 @@ fflush(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(fp) - register FILE *fp; +__sflush(FILE *fp) { - register unsigned char *p; - register int n, t; + unsigned char *p; + int n, t; t = fp->_flags; if ((t & __SWR) == 0) diff --git a/lib/libc/stdio/fgetc.c b/lib/libc/stdio/fgetc.c index 4e527053c52e..a367af32dc15 100644 --- a/lib/libc/stdio/fgetc.c +++ b/lib/libc/stdio/fgetc.c @@ -42,7 +42,9 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#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 6d6cfa19ff25..239f6d1e0db2 100644 --- a/lib/libc/stdio/fgetpos.c +++ b/lib/libc/stdio/fgetpos.c @@ -42,7 +42,9 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#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 33b7144e6ff2..ccf5535d68c0 100644 --- a/lib/libc/stdio/fgets.c +++ b/lib/libc/stdio/fgets.c @@ -42,8 +42,10 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#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 3cc08a94c56b..50edcb6d5a77 100644 --- a/lib/libc/stdio/findfp.c +++ b/lib/libc/stdio/findfp.c @@ -43,15 +43,15 @@ static const char rcsid[] = #endif /* LIBC_SCCS and not lint */ #include +#include #include #include -#include #include #include -#include #include +#include "libc_private.h" #include "local.h" #include "glue.h" @@ -65,7 +65,7 @@ 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 */ @@ -73,6 +73,7 @@ FILE __sF[3] = { std(__SWR|__SNBF, STDERR_FILENO) /* stderr */ }; struct glue __sglue = { &uglue, 3, __sF }; +static struct glue *lastglue = &uglue; static struct glue * moreglue __P((int)); @@ -80,12 +81,18 @@ 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(n) - register int n; + int n; { - register struct glue *g; - register FILE *p; + struct glue *g; + FILE *p; static FILE empty; g = (struct glue *)malloc(sizeof(*g) + ALIGNBYTES + n * sizeof(FILE)); @@ -106,22 +113,28 @@ moreglue(n) FILE * __sfp() { - register FILE *fp; - register int n; - register struct glue *g; + FILE *fp; + int n; + struct glue *g; 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(); @@ -137,6 +150,7 @@ found: fp->_ub._size = 0; fp->_lb._base = NULL; /* no line buffer */ fp->_lb._size = 0; + /* fp->_lock = NULL; */ return (fp); } @@ -150,14 +164,23 @@ __warn_references(f_prealloc, void f_prealloc() { - register struct glue *g; + struct glue *g; 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 afcc4d80f8ec..4f394609cad7 100644 --- a/lib/libc/stdio/flags.c +++ b/lib/libc/stdio/flags.c @@ -46,11 +46,12 @@ static const char rcsid[] = #include #include #include + #include "local.h" /* * 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 1ef6bda15da1..4ea2eb99f8bb 100644 --- a/lib/libc/stdio/fopen.c +++ b/lib/libc/stdio/fopen.c @@ -40,11 +40,14 @@ static char sccsid[] = "@(#)fopen.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include #include #include +#include "un-namespace.h" + #include "local.h" FILE * @@ -52,8 +55,8 @@ fopen(file, mode) const char *file; const char *mode; { - register FILE *fp; - register int f; + FILE *fp; + int f; int flags, oflags; if ((flags = __sflags(mode, &oflags)) == 0) @@ -71,7 +74,7 @@ fopen(file, 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 acf0b8b451e1..4959098a46fb 100644 --- a/lib/libc/stdio/fpurge.c +++ b/lib/libc/stdio/fpurge.c @@ -42,9 +42,11 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#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 60079f13c0ed..24eb560d03d6 100644 --- a/lib/libc/stdio/fputc.c +++ b/lib/libc/stdio/fputc.c @@ -42,7 +42,9 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#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 63a5321f0f2f..0967c6a05e8a 100644 --- a/lib/libc/stdio/fputs.c +++ b/lib/libc/stdio/fputs.c @@ -42,8 +42,10 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#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 886a9fc5517c..f7e8985fbe86 100644 --- a/lib/libc/stdio/fread.c +++ b/lib/libc/stdio/fread.c @@ -42,8 +42,10 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#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 f6fa7541f5a7..fd8612c4613c 100644 --- a/lib/libc/stdio/freopen.c +++ b/lib/libc/stdio/freopen.c @@ -42,6 +42,7 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include @@ -49,7 +50,8 @@ static const char rcsid[] = #include #include #include -#include +#include "un-namespace.h" +#include "libc_private.h" #include "local.h" /* @@ -146,7 +148,7 @@ freopen(file, mode, fp) * 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 8b7b9411a934..45c399ae7574 100644 --- a/lib/libc/stdio/fscanf.c +++ b/lib/libc/stdio/fscanf.c @@ -42,12 +42,14 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #if __STDC__ #include #else #include #endif +#include "un-namespace.h" #include "libc_private.h" #if __STDC__ diff --git a/lib/libc/stdio/fseek.c b/lib/libc/stdio/fseek.c index 8c2732e1b924..f87397552a75 100644 --- a/lib/libc/stdio/fseek.c +++ b/lib/libc/stdio/fseek.c @@ -42,12 +42,14 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include #include #include #include +#include "un-namespace.h" #include "local.h" #include "libc_private.h" @@ -62,13 +64,31 @@ fseek(fp, offset, 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(fp, offset, whence) - register FILE *fp; +_fseeko(fp, offset, whence) + FILE *fp; off_t offset; int whence; { @@ -78,17 +98,11 @@ fseeko(fp, offset, 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); + errno = ESPIPE; /* historic practice */ return (EOF); } @@ -108,10 +122,8 @@ fseeko(fp, offset, whence) curoff = fp->_offset; else { curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR); - if (curoff == -1) { - FUNLOCKFILE(fp); + if (curoff == -1) return (EOF); - } } if (fp->_flags & __SRD) { curoff -= fp->_r; @@ -133,7 +145,6 @@ fseeko(fp, offset, whence) default: errno = EINVAL; - FUNLOCKFILE(fp); return (EOF); } @@ -151,7 +162,7 @@ fseeko(fp, offset, 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; @@ -167,7 +178,7 @@ fseeko(fp, offset, 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; } @@ -217,7 +228,6 @@ fseeko(fp, offset, whence) if (HASUB(fp)) FREEUB(fp); fp->_flags &= ~__SEOF; - FUNLOCKFILE(fp); return (0); } @@ -244,7 +254,6 @@ fseeko(fp, offset, whence) fp->_p += n; fp->_r -= n; } - FUNLOCKFILE(fp); return (0); /* @@ -253,10 +262,8 @@ fseeko(fp, offset, whence) */ dumb: if (__sflush(fp) || - (*seekfn)(fp->_cookie, (fpos_t)offset, whence) == POS_ERR) { - FUNLOCKFILE(fp); + (*seekfn)(fp->_cookie, (fpos_t)offset, whence) == POS_ERR) return (EOF); - } /* success: clear EOF indicator and discard ungetc() data */ if (HASUB(fp)) FREEUB(fp); @@ -264,6 +271,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 9057f89b7aef..e4a4e11c662a 100644 --- a/lib/libc/stdio/ftell.c +++ b/lib/libc/stdio/ftell.c @@ -42,9 +42,11 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include +#include "un-namespace.h" #include "local.h" #include "libc_private.h" diff --git a/lib/libc/stdio/funopen.c b/lib/libc/stdio/funopen.c index 4d65b68c64ce..f66c60e65efa 100644 --- a/lib/libc/stdio/funopen.c +++ b/lib/libc/stdio/funopen.c @@ -32,6 +32,8 @@ * 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$ */ #if defined(LIBC_SCCS) && !defined(lint) @@ -40,6 +42,7 @@ static char sccsid[] = "@(#)funopen.c 8.1 (Berkeley) 6/4/93"; #include #include + #include "local.h" FILE * diff --git a/lib/libc/stdio/fvwrite.c b/lib/libc/stdio/fvwrite.c index 75d719132e9c..82a49cb14986 100644 --- a/lib/libc/stdio/fvwrite.c +++ b/lib/libc/stdio/fvwrite.c @@ -143,7 +143,7 @@ __sfvwrite(fp, 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 */ @@ -183,7 +183,7 @@ __sfvwrite(fp, 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); @@ -197,7 +197,7 @@ __sfvwrite(fp, 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 b1a25d1f8707..17cb5ced5a32 100644 --- a/lib/libc/stdio/fwalk.c +++ b/lib/libc/stdio/fwalk.c @@ -42,20 +42,26 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ -#include +#include +#include #include #include "local.h" #include "glue.h" int _fwalk(function) - register int (*function)(FILE *); + int (*function)(FILE *); { - register FILE *fp; - register int n, ret; - register struct glue *g; + FILE *fp; + int n, ret; + 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 681b9d313b42..13653b648bf1 100644 --- a/lib/libc/stdio/fwrite.c +++ b/lib/libc/stdio/fwrite.c @@ -42,7 +42,9 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#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 eff320aa432d..16684071af03 100644 --- a/lib/libc/stdio/getc.c +++ b/lib/libc/stdio/getc.c @@ -42,14 +42,12 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include +#include "un-namespace.h" #include "libc_private.h" -/* - * A subroutine version of the macro getc. - */ #undef getc - int getc(fp) register FILE *fp; diff --git a/lib/libc/stdio/getchar.c b/lib/libc/stdio/getchar.c index ec8810d64b07..92f714e5e372 100644 --- a/lib/libc/stdio/getchar.c +++ b/lib/libc/stdio/getchar.c @@ -45,7 +45,9 @@ static const char rcsid[] = /* * 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 1f9be80c6dd6..7a368cf14fea 100644 --- a/lib/libc/stdio/gets.c +++ b/lib/libc/stdio/gets.c @@ -42,9 +42,11 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#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/local.h b/lib/libc/stdio/local.h index cbc07a9d727b..2f95a58e9081 100644 --- a/lib/libc/stdio/local.h +++ b/lib/libc/stdio/local.h @@ -34,13 +34,19 @@ * SUCH DAMAGE. * * @(#)local.h 8.3 (Berkeley) 7/3/94 + * + * $FreeBSD$ */ +#include /* for off_t */ + /* * Information local to this implementation of stdio, * in particular, macros and private variables. */ +extern int _fseeko __P((FILE *, off_t, int)); +extern int __fflush __P((FILE *fp)); extern int __sflush __P((FILE *)); extern FILE *__sfp __P((void)); extern int __srefill __P((FILE *)); @@ -56,6 +62,8 @@ extern int __swhatbuf __P((FILE *, size_t *, int *)); extern int _fwalk __P((int (*)(FILE *))); extern int __swsetup __P((FILE *)); extern int __sflags __P((const char *, int *)); +extern int __ungetc __P((int, FILE *)); +extern int __vfprintf __P((FILE *, const char *, _BSD_VA_LIST_)); extern int __sdidinit; diff --git a/lib/libc/stdio/makebuf.c b/lib/libc/stdio/makebuf.c index 7dcbd70e0f6e..34fe8e6e9731 100644 --- a/lib/libc/stdio/makebuf.c +++ b/lib/libc/stdio/makebuf.c @@ -32,25 +32,29 @@ * 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$ */ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)makebuf.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ +#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(fp) @@ -93,7 +97,7 @@ __swhatbuf(fp, bufsize, 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 870e4db37597..e4c8c2872052 100644 --- a/lib/libc/stdio/mktemp.c +++ b/lib/libc/stdio/mktemp.c @@ -39,6 +39,7 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +/* #include "namespace.h" */ #include #include #include @@ -48,6 +49,7 @@ static const char rcsid[] = #include #include #include +/* #include "un-namespace.h" */ char *_mktemp __P((char *)); diff --git a/lib/libc/stdio/perror.c b/lib/libc/stdio/perror.c index bb618247e96f..c137e063225e 100644 --- a/lib/libc/stdio/perror.c +++ b/lib/libc/stdio/perror.c @@ -29,18 +29,22 @@ * 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$ */ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)perror.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include #include #include #include +#include "un-namespace.h" void perror(s) @@ -63,5 +67,5 @@ perror(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 fe1591c0dec4..72d6bbff12d8 100644 --- a/lib/libc/stdio/putc.c +++ b/lib/libc/stdio/putc.c @@ -42,14 +42,19 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#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(c, fp) int c; diff --git a/lib/libc/stdio/putchar.c b/lib/libc/stdio/putchar.c index cebd872c38cb..a611fbbb0679 100644 --- a/lib/libc/stdio/putchar.c +++ b/lib/libc/stdio/putchar.c @@ -42,11 +42,19 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#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 59f153d68b32..cdf1b53dec94 100644 --- a/lib/libc/stdio/puts.c +++ b/lib/libc/stdio/puts.c @@ -42,8 +42,10 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#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 8eac4cfd8188..a7e93b7e9e2b 100644 --- a/lib/libc/stdio/putw.c +++ b/lib/libc/stdio/putw.c @@ -42,7 +42,9 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#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 87938302157f..2db485bbae39 100644 --- a/lib/libc/stdio/refill.c +++ b/lib/libc/stdio/refill.c @@ -45,6 +45,7 @@ static const char rcsid[] = #include #include #include + #include "local.h" static int lflush __P((FILE *)); diff --git a/lib/libc/stdio/rewind.c b/lib/libc/stdio/rewind.c index 98c5846306bb..c4de2c14e40b 100644 --- a/lib/libc/stdio/rewind.c +++ b/lib/libc/stdio/rewind.c @@ -42,17 +42,19 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include +#include "un-namespace.h" #include "libc_private.h" +#include "local.h" void -rewind(fp) - register FILE *fp; +rewind(FILE *fp) { FLOCKFILE(fp); - (void) fseek(fp, 0L, SEEK_SET); + (void) _fseeko(fp, (off_t)0, SEEK_SET); clearerr(fp); FUNLOCKFILE(fp); - errno = 0; /* not required, but seems reasonable */ + errno = 0; /* not required, but seems reasonable */ } diff --git a/lib/libc/stdio/scanf.c b/lib/libc/stdio/scanf.c index b183c1784ced..fac6ceead26e 100644 --- a/lib/libc/stdio/scanf.c +++ b/lib/libc/stdio/scanf.c @@ -42,12 +42,14 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #if __STDC__ #include #else #include #endif +#include "un-namespace.h" #include "libc_private.h" #if __STDC__ diff --git a/lib/libc/stdio/setvbuf.c b/lib/libc/stdio/setvbuf.c index 4693b9f8a68b..f25391ffa26a 100644 --- a/lib/libc/stdio/setvbuf.c +++ b/lib/libc/stdio/setvbuf.c @@ -42,8 +42,10 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#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 b8a3f47aa148..57be5bb42140 100644 --- a/lib/libc/stdio/stdio.c +++ b/lib/libc/stdio/stdio.c @@ -42,9 +42,11 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#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 a0162c24f153..e3e296b63487 100644 --- a/lib/libc/stdio/tmpfile.c +++ b/lib/libc/stdio/tmpfile.c @@ -40,6 +40,7 @@ static char sccsid[] = "@(#)tmpfile.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include @@ -47,6 +48,7 @@ static char sccsid[] = "@(#)tmpfile.c 8.1 (Berkeley) 6/4/93"; #include #include #include +#include "un-namespace.h" FILE * tmpfile() @@ -61,13 +63,13 @@ tmpfile() (void)memcpy(buf + sizeof(_PATH_TMP) - 1, TRAILER, sizeof(TRAILER)); sigfillset(&set); - (void)sigprocmask(SIG_BLOCK, &set, &oset); + (void)_sigprocmask(SIG_BLOCK, &set, &oset); fd = mkstemp(buf); if (fd != -1) (void)unlink(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 3f4b32cb4313..872abadc6817 100644 --- a/lib/libc/stdio/ungetc.c +++ b/lib/libc/stdio/ungetc.c @@ -42,9 +42,11 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include +#include "un-namespace.h" #include "local.h" #include "libc_private.h" @@ -57,11 +59,10 @@ static int __submore __P((FILE *)); * are all at the end (stack-style). */ static int -__submore(fp) - register FILE *fp; +__submore(FILE *fp) { - register int i; - register unsigned char *p; + int i; + unsigned char *p; if (fp->_ub._base == fp->_ubuf) { /* @@ -89,30 +90,42 @@ __submore(fp) return (0); } +/* + * MT-safe version + */ int -ungetc(c, fp) - int c; - register FILE *fp; +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); + if ((fp->_flags & __SRW) == 0) return (EOF); - } if (fp->_flags & __SWR) { - if (__sflush(fp)) { - FUNLOCKFILE(fp); + if (__sflush(fp)) return (EOF); - } fp->_flags &= ~__SWR; fp->_w = 0; fp->_lbfsize = 0; @@ -126,13 +139,10 @@ ungetc(c, fp) * This may require expanding the current ungetc buffer. */ if (HASUB(fp)) { - if (fp->_r >= fp->_ub._size && __submore(fp)) { - FUNLOCKFILE(fp); + if (fp->_r >= fp->_ub._size && __submore(fp)) return (EOF); - } *--fp->_p = c; fp->_r++; - FUNLOCKFILE(fp); return (c); } fp->_flags &= ~__SEOF; @@ -146,7 +156,6 @@ ungetc(c, fp) fp->_p[-1] == c) { fp->_p--; fp->_r++; - FUNLOCKFILE(fp); return (c); } @@ -161,6 +170,5 @@ ungetc(c, 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 37fb0fd93b6c..98180cb31b3b 100644 --- a/lib/libc/stdio/vasprintf.c +++ b/lib/libc/stdio/vasprintf.c @@ -34,6 +34,7 @@ static char rcsid[] = "$FreeBSD$"; #include #include #include +#include "local.h" int vasprintf(str, fmt, ap) @@ -53,7 +54,7 @@ vasprintf(str, fmt, 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 f8eb9ca3a981..fff9aa8014f5 100644 --- a/lib/libc/stdio/vfprintf.c +++ b/lib/libc/stdio/vfprintf.c @@ -48,6 +48,7 @@ static const char rcsid[] = * This code is large and complicated... */ +#include "namespace.h" #include #include @@ -60,10 +61,11 @@ static const char rcsid[] = #else #include #endif +#include "un-namespace.h" +#include "libc_private.h" #include "local.h" #include "fvwrite.h" -#include "libc_private.h" /* Define FLOATING_POINT to get floating point. */ #define FLOATING_POINT @@ -80,11 +82,9 @@ static void __grow_type_table __P((int, unsigned char **, int *)); * then reset it so that it can be reused. */ static int -__sprint(fp, uio) - FILE *fp; - register struct __suio *uio; +__sprint(FILE *fp, struct __suio *uio) { - register int err; + int err; if (uio->uio_resid == 0) { uio->uio_iovcnt = 0; @@ -102,10 +102,7 @@ __sprint(fp, uio) * worries about ungetc buffers and so forth. */ static int -__sbprintf(fp, fmt, ap) - register FILE *fp; - const char *fmt; - va_list ap; +__sbprintf(FILE *fp, const char *fmt, va_list ap) { int ret; FILE fake; @@ -123,8 +120,8 @@ __sbprintf(fp, fmt, 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; @@ -145,11 +142,7 @@ __sbprintf(fp, fmt, ap) * use the given digits. */ static char * -__ultoa(val, endp, base, octzero, xdigs) - register u_long val; - char *endp; - int base, octzero; - char *xdigs; +__ultoa(u_long val, char *endp, int base, int octzero, char *xdigs) { register char *cp = endp; register long sval; @@ -205,14 +198,10 @@ __ultoa(val, endp, base, octzero, xdigs) /* Identical to __ultoa, but for quads. */ static char * -__uqtoa(val, endp, base, octzero, xdigs) - register u_quad_t val; - char *endp; - int base, octzero; - char *xdigs; +__uqtoa(u_quad_t val, char *endp, int base, int octzero, char *xdigs) { - register char *cp = endp; - register quad_t sval; + char *cp = endp; + quad_t sval; /* quick test for small values; __ultoa is typically much faster */ /* (perhaps instead we should run until small, then call __ultoa?) */ @@ -257,6 +246,20 @@ __uqtoa(val, endp, base, octzero, 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 "floatio.h" @@ -287,18 +290,18 @@ static int exponent __P((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(fp, fmt0, ap) - FILE *fp; - const char *fmt0; - va_list ap; +__vfprintf(FILE *fp, const char *fmt0, va_list ap) { - register char *fmt; /* format string */ - register int ch; /* character from fmt */ - register int n, n2; /* handy integer (short term usage) */ - register char *cp; /* handy char pointer (short term usage) */ - register struct __siov *iovp;/* for PRINT macro */ - register int flags; /* flags as above */ + char *fmt; /* format string */ + int ch; /* character from fmt */ + int n, n2; /* handy integer (short term usage) */ + char *cp; /* handy char pointer (short term usage) */ + struct __siov *iovp; /* for PRINT macro */ + int flags; /* flags as above */ int ret; /* return value accumulator */ int width; /* width from format (%8d), or 0 */ int prec; /* precision from format (%.3d), or -1 */ @@ -418,19 +421,14 @@ vfprintf(fp, fmt0, ap) } - FLOCKFILE(fp); /* sorry, fprintf(read_only_file, "") returns EOF, not 0 */ - if (cantwrite(fp)) { - FUNLOCKFILE(fp); + if (cantwrite(fp)) return (EOF); - } /* optimise fprintf(stderr) (and other unbuffered Unix files) */ if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) && - fp->_file >= 0) { - FUNLOCKFILE(fp); + fp->_file >= 0) return (__sbprintf(fp, fmt0, ap)); - } fmt = (char *)fmt0; argtable = NULL; @@ -867,7 +865,6 @@ done: error: if (__sferror(fp)) ret = EOF; - FUNLOCKFILE(fp); if ((argtable != NULL) && (argtable != statargtable)) free (argtable); return (ret); @@ -902,16 +899,13 @@ error: * It will be replaces with a malloc-ed one if it overflows. */ static void -__find_arguments (fmt0, ap, argtable) - const char *fmt0; - va_list ap; - void ***argtable; +__find_arguments (const char *fmt0, va_list ap, void ***argtable) { - register char *fmt; /* format string */ - register int ch; /* character from fmt */ - register int n, n2; /* handy integer (short term usage) */ - register char *cp; /* handy char pointer (short term usage) */ - register int flags; /* flags as above */ + char *fmt; /* format string */ + int ch; /* character from fmt */ + int n, n2; /* handy integer (short term usage) */ + char *cp; /* handy char pointer (short term usage) */ + int flags; /* flags as above */ int width; /* width from format (%8d), or 0 */ unsigned char *typetable; /* table of types */ unsigned char stattypetable [STATIC_ARG_TBL_SIZE]; @@ -1174,10 +1168,7 @@ done: * Increase the size of the type table. */ static void -__grow_type_table (nextarg, typetable, tablesize) - int nextarg; - unsigned char **typetable; - int *tablesize; +__grow_type_table (int nextarg, unsigned char **typetable, int *tablesize) { unsigned char *const oldtable = *typetable; const int oldsize = *tablesize; @@ -1206,10 +1197,8 @@ __grow_type_table (nextarg, typetable, tablesize) extern char *__dtoa __P((double, int, int, int *, int *, char **)); static char * -cvt(value, ndigits, flags, sign, decpt, ch, length) - double value; - int ndigits, flags, *decpt, ch, *length; - char *sign; +cvt(double value, int ndigits, int flags, char *sign, int *decpt, + int ch, int *length) { int mode, dsgn; char *digits, *bp, *rve; @@ -1250,11 +1239,9 @@ cvt(value, ndigits, flags, sign, decpt, ch, length) } static int -exponent(p0, exp, fmtch) - char *p0; - int exp, fmtch; +exponent(char *p0, int exp, int fmtch) { - register char *p, *t; + char *p, *t; char expbuf[MAXEXP]; p = p0; diff --git a/lib/libc/stdio/vfscanf.c b/lib/libc/stdio/vfscanf.c index 6a832162fa20..04ce95c597ff 100644 --- a/lib/libc/stdio/vfscanf.c +++ b/lib/libc/stdio/vfscanf.c @@ -42,6 +42,7 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include @@ -51,8 +52,10 @@ static const char rcsid[] = #include #endif #include +#include "un-namespace.h" #include "collate.h" +#include "libc_private.h" #include "local.h" #define FLOATING_POINT @@ -100,21 +103,32 @@ static const char rcsid[] = static u_char *__sccl(char *, u_char *); /* - * vfscanf + * __vfscanf - MT-safe version */ int -__svfscanf(fp, fmt0, ap) - register FILE *fp; - char const *fmt0; - va_list ap; +__vfscanf(FILE *fp, char const *fmt0, va_list ap) { - register u_char *fmt = (u_char *)fmt0; - register int c; /* character from format, or conversion */ - register size_t width; /* field width, or 0 */ - register char *p; /* points into all kinds of strings */ - register int n; /* handy integer */ - register int flags; /* flags as defined above */ - register char *p0; /* saves original value of p when necessary */ + 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) +{ + u_char *fmt = (u_char *)fmt0; + int c; /* character from format, or conversion */ + size_t width; /* field width, or 0 */ + char *p; /* points into all kinds of strings */ + int n; /* handy integer */ + int flags; /* flags as defined above */ + char *p0; /* saves original value of p when necessary */ int nassigned; /* number of fields assigned */ int nconversions; /* number of conversions */ int nread; /* number of characters consumed from fp */ @@ -539,13 +553,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; @@ -635,16 +649,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 53fb362c1692..64541c8121da 100644 --- a/lib/libc/stdio/vscanf.c +++ b/lib/libc/stdio/vscanf.c @@ -42,7 +42,9 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #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 b8e4c8c271cd..b301b08f9fe5 100644 --- a/lib/libc/stdio/vsnprintf.c +++ b/lib/libc/stdio/vsnprintf.c @@ -44,6 +44,7 @@ static const char rcsid[] = #include #include +#include "local.h" int vsnprintf(str, n, fmt, ap) @@ -65,7 +66,7 @@ vsnprintf(str, n, fmt, 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 d357af0c297c..dbfd339e2d3e 100644 --- a/lib/libc/stdio/vsprintf.c +++ b/lib/libc/stdio/vsprintf.c @@ -44,6 +44,7 @@ static const char rcsid[] = #include #include +#include "local.h" int vsprintf(str, fmt, ap) @@ -58,7 +59,7 @@ vsprintf(str, fmt, 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 847699ad7cf4..54da709e77f2 100644 --- a/lib/libc/stdio/wbuf.c +++ b/lib/libc/stdio/wbuf.c @@ -49,6 +49,8 @@ static const char rcsid[] = * 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(c, fp) @@ -80,14 +82,14 @@ __swbuf(c, 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 b6b4be950341..0b85182c9715 100644 --- a/lib/libc/stdlib/abort.c +++ b/lib/libc/stdlib/abort.c @@ -29,6 +29,8 @@ * 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$ */ #if defined(LIBC_SCCS) && !defined(lint) @@ -39,17 +41,18 @@ static char sccsid[] = "@(#)abort.c 8.1 (Berkeley) 6/4/93"; #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 @@ -57,29 +60,25 @@ 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) _thread_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) _thread_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 b0f6d3a51882..32f51d427302 100644 --- a/lib/libc/stdlib/exit.c +++ b/lib/libc/stdlib/exit.c @@ -29,14 +29,18 @@ * 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$ */ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)exit.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include +#include "un-namespace.h" #include "atexit.h" void (*__cleanup)(); @@ -60,11 +64,10 @@ exit(status) register struct atexit *p; register int n; -#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 for (p = __atexit; p; p = p->next) for (n = p->ind; --n >= 0;) diff --git a/lib/libc/stdlib/malloc.c b/lib/libc/stdlib/malloc.c index 91236df211a5..bf6a495063a9 100644 --- a/lib/libc/stdlib/malloc.c +++ b/lib/libc/stdlib/malloc.c @@ -42,6 +42,7 @@ * */ +#include "namespace.h" #if defined(__FreeBSD__) # if defined(__i386__) # define malloc_pageshift 12U @@ -97,6 +98,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 e8e82544d99c..a271669f5064 100644 --- a/lib/libc/stdlib/random.c +++ b/lib/libc/stdlib/random.c @@ -38,11 +38,13 @@ static char sccsid[] = "@(#)random.c 8.2 (Berkeley) 5/19/95"; #endif /* LIBC_SCCS and not lint */ +#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 0217dde5f6a6..2bb8c893b595 100644 --- a/lib/libc/stdlib/realpath.c +++ b/lib/libc/stdlib/realpath.c @@ -40,6 +40,7 @@ static char sccsid[] = "@(#)realpath.c 8.1 (Berkeley) 2/16/94"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include @@ -48,6 +49,7 @@ static char sccsid[] = "@(#)realpath.c 8.1 (Berkeley) 2/16/94"; #include #include #include +#include "un-namespace.h" /* * char *realpath(const char *path, char resolved_path[MAXPATHLEN]); diff --git a/lib/libc/stdlib/system.c b/lib/libc/stdlib/system.c index c7e68bae69b7..3b1645414069 100644 --- a/lib/libc/stdlib/system.c +++ b/lib/libc/stdlib/system.c @@ -37,6 +37,7 @@ static char sccsid[] = "@(#)system.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ +#include "namespace.h" #include #include #include @@ -45,6 +46,8 @@ static char sccsid[] = "@(#)system.c 8.1 (Berkeley) 6/4/93"; #include #include #include +#include "un-namespace.h" +#include "libc_private.h" int __system(command) @@ -65,11 +68,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; @@ -77,9 +80,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 832f18592ff3..d6e02b8324fa 100644 --- a/lib/libc/stdtime/asctime.c +++ b/lib/libc/stdtime/asctime.c @@ -1,6 +1,8 @@ /* ** This file is in the public domain, so clarified as of ** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov). +* +* $FreeBSD$ */ #ifndef lint @@ -11,7 +13,9 @@ static char elsieid[] = "@(#)asctime.c 7.7"; /*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 f178524f5152..64a5ea204f15 100644 --- a/lib/libc/stdtime/difftime.c +++ b/lib/libc/stdtime/difftime.c @@ -1,6 +1,8 @@ /* ** This file is in the public domain, so clarified as of ** June 5, 1996 by Arthur David Olson (arthur_david_olson@nih.gov). +* +* $FreeBSD$ */ #ifndef lint @@ -11,7 +13,9 @@ static char elsieid[] = "@(#)difftime.c 7.7"; /*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 84a4ca9d7a19..e336414da018 100644 --- a/lib/libc/stdtime/localtime.c +++ b/lib/libc/stdtime/localtime.c @@ -19,16 +19,20 @@ static char elsieid[] = "@(#)localtime.c 7.57"; /*LINTLIBRARY*/ +#include "namespace.h" #include #include - +#include +#include #include "private.h" +#include "un-namespace.h" + #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. @@ -172,12 +176,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, @@ -316,7 +316,7 @@ register 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)) return -1; } { @@ -929,20 +929,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; @@ -962,23 +950,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) { register const char * name; @@ -1018,15 +999,13 @@ tzset P((void)) settzname(); } -#ifdef _THREAD_SAFE void tzset P((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 @@ -1089,14 +1068,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); } @@ -1104,36 +1079,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 } /* @@ -1146,9 +1121,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 @@ -1157,9 +1130,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 /* @@ -1186,36 +1157,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 * @@ -1635,14 +1607,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 cd506c1cbeaa..83bddc9a48c2 100644 --- a/lib/libc/stdtime/strftime.c +++ b/lib/libc/stdtime/strftime.c @@ -30,6 +30,7 @@ static const char elsieid[] = "@(#)strftime.c 7.38"; #endif /* !defined NOID */ #endif /* !defined lint */ +#include "namespace.h" #include "private.h" #ifndef LIBC_SCCS @@ -41,6 +42,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 ca4dcefbf2b2..88d04ce8a5fd 100644 --- a/lib/libc/stdtime/strptime.c +++ b/lib/libc/stdtime/strptime.c @@ -64,21 +64,18 @@ static char sccsid[] = "@(#)strptime.c 0.1 (Powerdog) 94/03/27"; #endif /* !defined NOID */ #endif /* not lint */ +#include "namespace.h" #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])) @@ -524,21 +521,19 @@ 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 3a810edfb523..c39b956001ba 100644 --- a/lib/libc/stdtime/timelocal.c +++ b/lib/libc/stdtime/timelocal.c @@ -26,6 +26,7 @@ * $FreeBSD$ */ +#include "namespace.h" #include #include #include @@ -34,6 +35,9 @@ #include #include #include +#include +#include "un-namespace.h" + #include "setlocale.h" #include "timelocal.h" @@ -158,7 +162,7 @@ __time_load_locale(const char *name) fd = _open(filename, O_RDONLY); if (fd < 0) goto no_locale; - if (fstat(fd, &st) != 0) + if (_fstat(fd, &st) != 0) goto bad_locale; if (st.st_size <= 0) goto bad_locale; diff --git a/lib/libc/sys/__error.c b/lib/libc/sys/__error.c index 9b0c25f2fae3..8c14b0f75153 100644 --- a/lib/libc/sys/__error.c +++ b/lib/libc/sys/__error.c @@ -29,6 +29,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * + * $FreeBSD$ */ #include @@ -41,7 +42,8 @@ extern int errno; */ #pragma weak __error=__error_unthreaded -int * __error_unthreaded() +int * +__error_unthreaded() { return(&errno); } diff --git a/lib/libc/sys/ftruncate.c b/lib/libc/sys/ftruncate.c index 9d7d5fb77f93..da81b438a26e 100644 --- a/lib/libc/sys/ftruncate.c +++ b/lib/libc/sys/ftruncate.c @@ -29,6 +29,8 @@ * 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$ */ #if defined(LIBC_SCCS) && !defined(lint) @@ -38,10 +40,6 @@ static char sccsid[] = "@(#)ftruncate.c 8.1 (Berkeley) 6/17/93"; #include #include #include -#ifdef _THREAD_SAFE -#include -#include "pthread_private.h" -#endif /* * This function provides 64-bit offset padding that @@ -53,16 +51,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 284885f597b1..230940c34ecb 100644 --- a/lib/libc/sys/lseek.c +++ b/lib/libc/sys/lseek.c @@ -29,6 +29,8 @@ * 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$ */ #if defined(LIBC_SCCS) && !defined(lint) @@ -38,10 +40,6 @@ static char sccsid[] = "@(#)lseek.c 8.1 (Berkeley) 6/17/93"; #include #include #include -#ifdef _THREAD_SAFE -#include -#include "pthread_private.h" -#endif /* * This function provides 64-bit offset padding that @@ -53,17 +51,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/yp/yplib.c b/lib/libc/yp/yplib.c index 5c72573373fc..e1755afd6eb5 100644 --- a/lib/libc/yp/yplib.c +++ b/lib/libc/yp/yplib.c @@ -32,6 +32,7 @@ static char *rcsid = "$FreeBSD$"; #endif +#include "namespace.h" #include #include #include @@ -45,6 +46,8 @@ static char *rcsid = "$FreeBSD$"; #include #include #include +#include "un-namespace.h" +#include "libc_private.h" /* * We have to define these here due to clashes between yp_prot.h and @@ -337,19 +340,19 @@ _yp_dobind(dom, 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); } } @@ -379,7 +382,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; @@ -389,7 +392,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; @@ -532,9 +535,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 { @@ -564,15 +567,15 @@ _yp_unbind(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); -- cgit v1.3