summaryrefslogtreecommitdiffstats
path: root/nsprpub/pr/src
diff options
context:
space:
mode:
Diffstat (limited to 'nsprpub/pr/src')
-rw-r--r--nsprpub/pr/src/Makefile.in16
-rw-r--r--nsprpub/pr/src/bthreads/.cvsignore1
-rw-r--r--nsprpub/pr/src/bthreads/Makefile.in31
-rw-r--r--nsprpub/pr/src/bthreads/bsrcs.mk17
-rw-r--r--nsprpub/pr/src/bthreads/btcvar.c244
-rw-r--r--nsprpub/pr/src/bthreads/btlocks.c91
-rw-r--r--nsprpub/pr/src/bthreads/btmisc.c72
-rw-r--r--nsprpub/pr/src/bthreads/btmon.c201
-rw-r--r--nsprpub/pr/src/bthreads/btsem.c98
-rw-r--r--nsprpub/pr/src/bthreads/btthread.c662
-rw-r--r--nsprpub/pr/src/bthreads/objs.mk11
-rw-r--r--nsprpub/pr/src/cplus/rcascii.h2
-rw-r--r--nsprpub/pr/src/cplus/rcbase.cpp16
-rw-r--r--nsprpub/pr/src/cplus/rcbase.h8
-rw-r--r--nsprpub/pr/src/cplus/rccv.cpp11
-rw-r--r--nsprpub/pr/src/cplus/rccv.h2
-rw-r--r--nsprpub/pr/src/cplus/rcfileio.cpp140
-rw-r--r--nsprpub/pr/src/cplus/rcfileio.h40
-rw-r--r--nsprpub/pr/src/cplus/rcinrval.cpp22
-rw-r--r--nsprpub/pr/src/cplus/rcinrval.h106
-rw-r--r--nsprpub/pr/src/cplus/rcio.h39
-rw-r--r--nsprpub/pr/src/cplus/rclock.cpp4
-rw-r--r--nsprpub/pr/src/cplus/rclock.h14
-rw-r--r--nsprpub/pr/src/cplus/rcnetdb.cpp75
-rw-r--r--nsprpub/pr/src/cplus/rcnetdb.h14
-rw-r--r--nsprpub/pr/src/cplus/rcnetio.cpp128
-rw-r--r--nsprpub/pr/src/cplus/rcnetio.h34
-rwxr-xr-xnsprpub/pr/src/cplus/rcthread.cpp81
-rw-r--r--nsprpub/pr/src/cplus/rcthread.h22
-rw-r--r--nsprpub/pr/src/cplus/rctime.cpp40
-rw-r--r--nsprpub/pr/src/cplus/rctime.h58
-rw-r--r--nsprpub/pr/src/cplus/tests/Makefile.in22
-rw-r--r--nsprpub/pr/src/cplus/tests/ranfile.cpp205
-rw-r--r--nsprpub/pr/src/cplus/tests/switch.cpp168
-rw-r--r--nsprpub/pr/src/cplus/tests/thread.cpp6
-rw-r--r--nsprpub/pr/src/cplus/tests/tpd.cpp57
-rw-r--r--nsprpub/pr/src/io/prdir.c92
-rw-r--r--nsprpub/pr/src/io/prfdcach.c52
-rw-r--r--nsprpub/pr/src/io/prfile.c349
-rw-r--r--nsprpub/pr/src/io/prio.c130
-rw-r--r--nsprpub/pr/src/io/priometh.c139
-rw-r--r--nsprpub/pr/src/io/pripv6.c338
-rw-r--r--nsprpub/pr/src/io/prlayer.c279
-rw-r--r--nsprpub/pr/src/io/prlog.c52
-rw-r--r--nsprpub/pr/src/io/prmapopt.c66
-rw-r--r--nsprpub/pr/src/io/prmmap.c14
-rw-r--r--nsprpub/pr/src/io/prmwait.c267
-rw-r--r--nsprpub/pr/src/io/prpolevt.c50
-rw-r--r--nsprpub/pr/src/io/prprf.c1486
-rw-r--r--nsprpub/pr/src/io/prscanf.c82
-rw-r--r--nsprpub/pr/src/io/prsocket.c2011
-rw-r--r--nsprpub/pr/src/linking/prlink.c628
-rw-r--r--nsprpub/pr/src/malloc/prmalloc.c800
-rw-r--r--nsprpub/pr/src/malloc/prmem.c210
-rw-r--r--nsprpub/pr/src/md/beos/.cvsignore1
-rw-r--r--nsprpub/pr/src/md/beos/Makefile.in28
-rw-r--r--nsprpub/pr/src/md/beos/bcpu.c23
-rw-r--r--nsprpub/pr/src/md/beos/beos.c232
-rw-r--r--nsprpub/pr/src/md/beos/beos_errors.c1494
-rw-r--r--nsprpub/pr/src/md/beos/bfile.c873
-rw-r--r--nsprpub/pr/src/md/beos/bmemory.c10
-rw-r--r--nsprpub/pr/src/md/beos/bmisc.c91
-rw-r--r--nsprpub/pr/src/md/beos/bmmap.c41
-rw-r--r--nsprpub/pr/src/md/beos/bnet.c911
-rw-r--r--nsprpub/pr/src/md/beos/bproc.c212
-rw-r--r--nsprpub/pr/src/md/beos/brng.c40
-rw-r--r--nsprpub/pr/src/md/beos/bseg.c22
-rw-r--r--nsprpub/pr/src/md/beos/bsrcs.mk22
-rw-r--r--nsprpub/pr/src/md/beos/btime.c43
-rw-r--r--nsprpub/pr/src/md/beos/objs.mk11
-rw-r--r--nsprpub/pr/src/md/os2/os2_errors.c1684
-rw-r--r--nsprpub/pr/src/md/os2/os2cv.c96
-rw-r--r--nsprpub/pr/src/md/os2/os2gc.c10
-rw-r--r--nsprpub/pr/src/md/os2/os2inrval.c11
-rw-r--r--nsprpub/pr/src/md/os2/os2io.c438
-rw-r--r--nsprpub/pr/src/md/os2/os2misc.c83
-rw-r--r--nsprpub/pr/src/md/os2/os2poll.c85
-rw-r--r--nsprpub/pr/src/md/os2/os2rng.c25
-rw-r--r--nsprpub/pr/src/md/os2/os2sem.c20
-rw-r--r--nsprpub/pr/src/md/os2/os2sock.c145
-rw-r--r--nsprpub/pr/src/md/os2/os2thred.c114
-rw-r--r--nsprpub/pr/src/md/prosdep.c19
-rw-r--r--nsprpub/pr/src/md/unix/aix.c133
-rw-r--r--nsprpub/pr/src/md/unix/aixwrap.c2
-rw-r--r--nsprpub/pr/src/md/unix/bsdi.c8
-rw-r--r--nsprpub/pr/src/md/unix/darwin.c12
-rw-r--r--nsprpub/pr/src/md/unix/freebsd.c12
-rw-r--r--nsprpub/pr/src/md/unix/hpux.c26
-rw-r--r--nsprpub/pr/src/md/unix/irix.c1648
-rw-r--r--nsprpub/pr/src/md/unix/linux.c24
-rw-r--r--nsprpub/pr/src/md/unix/nto.c10
-rw-r--r--nsprpub/pr/src/md/unix/os_Irix.s134
-rw-r--r--nsprpub/pr/src/md/unix/osf1.c75
-rw-r--r--nsprpub/pr/src/md/unix/pthreads_user.c424
-rw-r--r--nsprpub/pr/src/md/unix/qnx.c6
-rw-r--r--nsprpub/pr/src/md/unix/riscos.c24
-rw-r--r--nsprpub/pr/src/md/unix/scoos.c13
-rw-r--r--nsprpub/pr/src/md/unix/solaris.c24
-rw-r--r--nsprpub/pr/src/md/unix/symbian.c16
-rw-r--r--nsprpub/pr/src/md/unix/unix.c963
-rw-r--r--nsprpub/pr/src/md/unix/unix_errors.c36
-rw-r--r--nsprpub/pr/src/md/unix/unixware.c218
-rw-r--r--nsprpub/pr/src/md/unix/uxpoll.c158
-rw-r--r--nsprpub/pr/src/md/unix/uxproces.c336
-rw-r--r--nsprpub/pr/src/md/unix/uxrng.c111
-rw-r--r--nsprpub/pr/src/md/unix/uxshm.c243
-rw-r--r--nsprpub/pr/src/md/unix/uxwrap.c119
-rw-r--r--nsprpub/pr/src/md/windows/ntdllmn.c5
-rw-r--r--nsprpub/pr/src/md/windows/ntgc.c16
-rw-r--r--nsprpub/pr/src/md/windows/ntinrval.c6
-rw-r--r--nsprpub/pr/src/md/windows/ntio.c2066
-rw-r--r--nsprpub/pr/src/md/windows/ntmisc.c645
-rw-r--r--nsprpub/pr/src/md/windows/ntsec.c66
-rw-r--r--nsprpub/pr/src/md/windows/ntsem.c16
-rw-r--r--nsprpub/pr/src/md/windows/ntthread.c185
-rw-r--r--nsprpub/pr/src/md/windows/w32ipcsem.c20
-rw-r--r--nsprpub/pr/src/md/windows/w32poll.c58
-rw-r--r--nsprpub/pr/src/md/windows/w32rng.c15
-rw-r--r--nsprpub/pr/src/md/windows/w32shm.c139
-rw-r--r--nsprpub/pr/src/md/windows/w95cv.c30
-rw-r--r--nsprpub/pr/src/md/windows/w95dllmain.c5
-rw-r--r--nsprpub/pr/src/md/windows/w95io.c363
-rw-r--r--nsprpub/pr/src/md/windows/w95sock.c114
-rw-r--r--nsprpub/pr/src/md/windows/w95thred.c143
-rw-r--r--nsprpub/pr/src/md/windows/win32_errors.c6
-rw-r--r--nsprpub/pr/src/memory/prseg.c26
-rw-r--r--nsprpub/pr/src/memory/prshm.c54
-rw-r--r--nsprpub/pr/src/memory/prshma.c22
-rw-r--r--nsprpub/pr/src/misc/dtoa.c6650
-rw-r--r--nsprpub/pr/src/misc/pralarm.c65
-rw-r--r--nsprpub/pr/src/misc/pratom.c215
-rw-r--r--nsprpub/pr/src/misc/praton.c87
-rw-r--r--nsprpub/pr/src/misc/prcountr.c211
-rw-r--r--nsprpub/pr/src/misc/prdtoa.c5042
-rw-r--r--nsprpub/pr/src/misc/prenv.c68
-rw-r--r--nsprpub/pr/src/misc/prerr.c156
-rw-r--r--nsprpub/pr/src/misc/prerror.c21
-rw-r--r--nsprpub/pr/src/misc/prerrortable.c94
-rw-r--r--nsprpub/pr/src/misc/prinit.c216
-rw-r--r--nsprpub/pr/src/misc/prinrval.c12
-rw-r--r--nsprpub/pr/src/misc/pripc.c2
-rw-r--r--nsprpub/pr/src/misc/pripcsem.c12
-rw-r--r--nsprpub/pr/src/misc/prlong.c355
-rw-r--r--nsprpub/pr/src/misc/prnetdb.c1301
-rw-r--r--nsprpub/pr/src/misc/prolock.c30
-rw-r--r--nsprpub/pr/src/misc/prrng.c16
-rw-r--r--nsprpub/pr/src/misc/prsystem.c141
-rw-r--r--nsprpub/pr/src/misc/prthinfo.c29
-rw-r--r--nsprpub/pr/src/misc/prtime.c1978
-rw-r--r--nsprpub/pr/src/misc/prtpool.c1919
-rw-r--r--nsprpub/pr/src/misc/prtrace.c369
-rw-r--r--nsprpub/pr/src/prvrsion.c8
-rw-r--r--nsprpub/pr/src/pthreads/ptio.c2308
-rw-r--r--nsprpub/pr/src/pthreads/ptmisc.c18
-rw-r--r--nsprpub/pr/src/pthreads/ptsynch.c164
-rw-r--r--nsprpub/pr/src/pthreads/ptthread.c562
-rw-r--r--nsprpub/pr/src/threads/combined/prucpu.c83
-rw-r--r--nsprpub/pr/src/threads/combined/prucv.c256
-rw-r--r--nsprpub/pr/src/threads/combined/prulock.c201
-rw-r--r--nsprpub/pr/src/threads/combined/prustack.c133
-rw-r--r--nsprpub/pr/src/threads/combined/pruthr.c765
-rw-r--r--nsprpub/pr/src/threads/prcmon.c56
-rw-r--r--nsprpub/pr/src/threads/prcthr.c199
-rw-r--r--nsprpub/pr/src/threads/prdump.c40
-rw-r--r--nsprpub/pr/src/threads/prmon.c37
-rw-r--r--nsprpub/pr/src/threads/prrwlock.c559
-rw-r--r--nsprpub/pr/src/threads/prsem.c89
-rw-r--r--nsprpub/pr/src/threads/prtpd.c42
168 files changed, 22343 insertions, 27528 deletions
diff --git a/nsprpub/pr/src/Makefile.in b/nsprpub/pr/src/Makefile.in
index 19c5a6987..2258dae61 100644
--- a/nsprpub/pr/src/Makefile.in
+++ b/nsprpub/pr/src/Makefile.in
@@ -66,13 +66,6 @@ endif
endif # sparc
endif # SunOS
-ifeq ($(OS_ARCH), IRIX)
-ifeq ($(USE_PTHREADS), 1)
-OS_LIBS = -lpthread
-endif
-OS_LIBS += -lc
-endif
-
ifeq ($(OS_ARCH),AIX)
DSO_LDOPTS += -binitfini::_PR_Fini
OS_LIBS = -lodm -lcfg
@@ -109,15 +102,6 @@ GARBAGE += $(MAPFILE)
MKSHLIB += $(MAPFILE)
endif
-ifeq ($(OS_ARCH),OSF1)
-ifeq ($(USE_PTHREADS), 1)
-OS_LIBS = -lpthread -lrt
-endif
-ifneq ($(OS_RELEASE),V2.0)
-OS_LIBS += -lc_r
-endif
-endif
-
# Linux, GNU/Hurd, and GNU/kFreeBSD systems
ifneq (,$(filter Linux GNU%,$(OS_ARCH)))
ifeq ($(USE_PTHREADS), 1)
diff --git a/nsprpub/pr/src/bthreads/.cvsignore b/nsprpub/pr/src/bthreads/.cvsignore
deleted file mode 100644
index f3c7a7c5d..000000000
--- a/nsprpub/pr/src/bthreads/.cvsignore
+++ /dev/null
@@ -1 +0,0 @@
-Makefile
diff --git a/nsprpub/pr/src/bthreads/Makefile.in b/nsprpub/pr/src/bthreads/Makefile.in
deleted file mode 100644
index a85e6db67..000000000
--- a/nsprpub/pr/src/bthreads/Makefile.in
+++ /dev/null
@@ -1,31 +0,0 @@
-#
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-
-#! gmake
-
-MOD_DEPTH = ../../..
-topsrcdir = @top_srcdir@
-srcdir = @srcdir@
-VPATH = @srcdir@
-
-include $(MOD_DEPTH)/config/autoconf.mk
-
-include $(topsrcdir)/config/config.mk
-
-include $(srcdir)/bsrcs.mk
-CSRCS += $(BTCSRCS)
-
-TARGETS = $(OBJS)
-
-INCLUDES = -I$(dist_includedir) -I$(topsrcdir)/pr/include -I$(topsrcdir)/pr/include/private
-
-include $(topsrcdir)/config/rules.mk
-
-DEFINES += -D_NSPR_BUILD_
-
-export:: $(TARGETS)
-
-
diff --git a/nsprpub/pr/src/bthreads/bsrcs.mk b/nsprpub/pr/src/bthreads/bsrcs.mk
deleted file mode 100644
index 70832990c..000000000
--- a/nsprpub/pr/src/bthreads/bsrcs.mk
+++ /dev/null
@@ -1,17 +0,0 @@
-#
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-# this file lists the source files to be compiled (used in Makefile) and
-# then enumerated as object files (in objs.mk) for inclusion in the NSPR
-# shared library
-
-BTCSRCS = \
- btthread.c \
- btlocks.c \
- btcvar.c \
- btmon.c \
- btsem.c \
- btmisc.c \
- $(NULL)
diff --git a/nsprpub/pr/src/bthreads/btcvar.c b/nsprpub/pr/src/bthreads/btcvar.c
deleted file mode 100644
index c74837907..000000000
--- a/nsprpub/pr/src/bthreads/btcvar.c
+++ /dev/null
@@ -1,244 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <kernel/OS.h>
-
-#include "primpl.h"
-
-/*
-** Create a new condition variable.
-**
-** "lock" is the lock used to protect the condition variable.
-**
-** Condition variables are synchronization objects that threads can use
-** to wait for some condition to occur.
-**
-** This may fail if memory is tight or if some operating system resource
-** is low. In such cases, a NULL will be returned.
-*/
-PR_IMPLEMENT(PRCondVar*)
- PR_NewCondVar (PRLock *lock)
-{
- PRCondVar *cv = PR_NEW( PRCondVar );
- PR_ASSERT( NULL != lock );
- if( NULL != cv )
- {
- cv->lock = lock;
- cv->sem = create_sem(0, "CVSem");
- cv->handshakeSem = create_sem(0, "CVHandshake");
- cv->signalSem = create_sem( 0, "CVSignal");
- cv->signalBenCount = 0;
- cv->ns = cv->nw = 0;
- PR_ASSERT( cv->sem >= B_NO_ERROR );
- PR_ASSERT( cv->handshakeSem >= B_NO_ERROR );
- PR_ASSERT( cv->signalSem >= B_NO_ERROR );
- }
- return cv;
-} /* PR_NewCondVar */
-
-/*
-** Destroy a condition variable. There must be no thread
-** waiting on the condvar. The caller is responsible for guaranteeing
-** that the condvar is no longer in use.
-**
-*/
-PR_IMPLEMENT(void)
- PR_DestroyCondVar (PRCondVar *cvar)
-{
- status_t result = delete_sem( cvar->sem );
- PR_ASSERT( result == B_NO_ERROR );
-
- result = delete_sem( cvar->handshakeSem );
- PR_ASSERT( result == B_NO_ERROR );
-
- result = delete_sem( cvar->signalSem );
- PR_ASSERT( result == B_NO_ERROR );
-
- PR_DELETE( cvar );
-}
-
-/*
-** The thread that waits on a condition is blocked in a "waiting on
-** condition" state until another thread notifies the condition or a
-** caller specified amount of time expires. The lock associated with
-** the condition variable will be released, which must have be held
-** prior to the call to wait.
-**
-** Logically a notified thread is moved from the "waiting on condition"
-** state and made "ready." When scheduled, it will attempt to reacquire
-** the lock that it held when wait was called.
-**
-** The timeout has two well known values, PR_INTERVAL_NO_TIMEOUT and
-** PR_INTERVAL_NO_WAIT. The former value requires that a condition be
-** notified (or the thread interrupted) before it will resume from the
-** wait. If the timeout has a value of PR_INTERVAL_NO_WAIT, the effect
-** is to release the lock, possibly causing a rescheduling within the
-** runtime, then immediately attempting to reacquire the lock and resume.
-**
-** Any other value for timeout will cause the thread to be rescheduled
-** either due to explicit notification or an expired interval. The latter
-** must be determined by treating time as one part of the monitored data
-** being protected by the lock and tested explicitly for an expired
-** interval.
-**
-** Returns PR_FAILURE if the caller has not locked the lock associated
-** with the condition variable or the thread was interrupted (PR_Interrupt()).
-** The particular reason can be extracted with PR_GetError().
-*/
-PR_IMPLEMENT(PRStatus)
- PR_WaitCondVar (PRCondVar *cvar, PRIntervalTime timeout)
-{
- status_t err;
- if( timeout == PR_INTERVAL_NO_WAIT )
- {
- PR_Unlock( cvar->lock );
- PR_Lock( cvar->lock );
- return PR_SUCCESS;
- }
-
- if( atomic_add( &cvar->signalBenCount, 1 ) > 0 )
- {
- if (acquire_sem(cvar->signalSem) == B_INTERRUPTED)
- {
- atomic_add( &cvar->signalBenCount, -1 );
- return PR_FAILURE;
- }
- }
- cvar->nw += 1;
- if( atomic_add( &cvar->signalBenCount, -1 ) > 1 )
- {
- release_sem_etc(cvar->signalSem, 1, B_DO_NOT_RESCHEDULE);
- }
-
- PR_Unlock( cvar->lock );
- if( timeout==PR_INTERVAL_NO_TIMEOUT )
- {
- err = acquire_sem(cvar->sem);
- }
- else
- {
- err = acquire_sem_etc(cvar->sem, 1, B_RELATIVE_TIMEOUT, PR_IntervalToMicroseconds(timeout) );
- }
-
- if( atomic_add( &cvar->signalBenCount, 1 ) > 0 )
- {
- while (acquire_sem(cvar->signalSem) == B_INTERRUPTED);
- }
-
- if (cvar->ns > 0)
- {
- release_sem_etc(cvar->handshakeSem, 1, B_DO_NOT_RESCHEDULE);
- cvar->ns -= 1;
- }
- cvar->nw -= 1;
- if( atomic_add( &cvar->signalBenCount, -1 ) > 1 )
- {
- release_sem_etc(cvar->signalSem, 1, B_DO_NOT_RESCHEDULE);
- }
-
- PR_Lock( cvar->lock );
- if(err!=B_NO_ERROR)
- {
- return PR_FAILURE;
- }
- return PR_SUCCESS;
-}
-
-/*
-** Notify ONE thread that is currently waiting on 'cvar'. Which thread is
-** dependent on the implementation of the runtime. Common sense would dictate
-** that all threads waiting on a single condition have identical semantics,
-** therefore which one gets notified is not significant.
-**
-** The calling thead must hold the lock that protects the condition, as
-** well as the invariants that are tightly bound to the condition, when
-** notify is called.
-**
-** Returns PR_FAILURE if the caller has not locked the lock associated
-** with the condition variable.
-*/
-PR_IMPLEMENT(PRStatus)
- PR_NotifyCondVar (PRCondVar *cvar)
-{
- status_t err ;
- if( atomic_add( &cvar->signalBenCount, 1 ) > 0 )
- {
- if (acquire_sem(cvar->signalSem) == B_INTERRUPTED)
- {
- atomic_add( &cvar->signalBenCount, -1 );
- return PR_FAILURE;
- }
- }
- if (cvar->nw > cvar->ns)
- {
- cvar->ns += 1;
- release_sem_etc(cvar->sem, 1, B_DO_NOT_RESCHEDULE);
- if( atomic_add( &cvar->signalBenCount, -1 ) > 1 )
- {
- release_sem_etc(cvar->signalSem, 1, B_DO_NOT_RESCHEDULE);
- }
-
- while (acquire_sem(cvar->handshakeSem) == B_INTERRUPTED)
- {
- err = B_INTERRUPTED;
- }
- }
- else
- {
- if( atomic_add( &cvar->signalBenCount, -1 ) > 1 )
- {
- release_sem_etc(cvar->signalSem, 1, B_DO_NOT_RESCHEDULE);
- }
- }
- return PR_SUCCESS;
-}
-
-/*
-** Notify all of the threads waiting on the condition variable. The order
-** that the threads are notified is indeterminant. The lock that protects
-** the condition must be held.
-**
-** Returns PR_FAILURE if the caller has not locked the lock associated
-** with the condition variable.
-*/
-PR_IMPLEMENT(PRStatus)
- PR_NotifyAllCondVar (PRCondVar *cvar)
-{
- int32 handshakes;
- status_t err = B_OK;
-
- if( atomic_add( &cvar->signalBenCount, 1 ) > 0 )
- {
- if (acquire_sem(cvar->signalSem) == B_INTERRUPTED)
- {
- atomic_add( &cvar->signalBenCount, -1 );
- return PR_FAILURE;
- }
- }
-
- if (cvar->nw > cvar->ns)
- {
- handshakes = cvar->nw - cvar->ns;
- cvar->ns = cvar->nw;
- release_sem_etc(cvar->sem, handshakes, B_DO_NOT_RESCHEDULE);
- if( atomic_add( &cvar->signalBenCount, -1 ) > 1 )
- {
- release_sem_etc(cvar->signalSem, 1, B_DO_NOT_RESCHEDULE);
- }
-
- while (acquire_sem_etc(cvar->handshakeSem, handshakes, 0, 0) == B_INTERRUPTED)
- {
- err = B_INTERRUPTED;
- }
- }
- else
- {
- if( atomic_add( &cvar->signalBenCount, -1 ) > 1 )
- {
- release_sem_etc(cvar->signalSem, 1, B_DO_NOT_RESCHEDULE);
- }
- }
- return PR_SUCCESS;
-}
diff --git a/nsprpub/pr/src/bthreads/btlocks.c b/nsprpub/pr/src/bthreads/btlocks.c
deleted file mode 100644
index 994c09c40..000000000
--- a/nsprpub/pr/src/bthreads/btlocks.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/* -*- Mode: C++; c-basic-offset: 4 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/*
-** File: btlocks.c
-** Description: Implemenation for thread locks using bthreads
-** Exports: prlock.h
-*/
-
-#include "primpl.h"
-
-#include <string.h>
-#include <sys/time.h>
-
-void
-_PR_InitLocks (void)
-{
-}
-
-PR_IMPLEMENT(PRLock*)
- PR_NewLock (void)
-{
- PRLock *lock;
- status_t semresult;
-
- if (!_pr_initialized) _PR_ImplicitInitialization();
-
- lock = PR_NEWZAP(PRLock);
- if (lock != NULL) {
-
- lock->benaphoreCount = 0;
- lock->semaphoreID = create_sem( 0, "nsprLockSem" );
- if( lock->semaphoreID < B_NO_ERROR ) {
-
- PR_DELETE( lock );
- lock = NULL;
- }
- }
-
- return lock;
-}
-
-PR_IMPLEMENT(void)
- PR_DestroyLock (PRLock* lock)
-{
- status_t result;
-
- PR_ASSERT(NULL != lock);
- result = delete_sem(lock->semaphoreID);
- PR_ASSERT(result == B_NO_ERROR);
- PR_DELETE(lock);
-}
-
-PR_IMPLEMENT(void)
- PR_Lock (PRLock* lock)
-{
- PR_ASSERT(lock != NULL);
-
- if( atomic_add( &lock->benaphoreCount, 1 ) > 0 ) {
-
- if( acquire_sem(lock->semaphoreID ) != B_NO_ERROR ) {
-
- atomic_add( &lock->benaphoreCount, -1 );
- return;
- }
- }
-
- lock->owner = find_thread( NULL );
-}
-
-PR_IMPLEMENT(PRStatus)
- PR_Unlock (PRLock* lock)
-{
- PR_ASSERT(lock != NULL);
- lock->owner = NULL;
- if( atomic_add( &lock->benaphoreCount, -1 ) > 1 ) {
-
- release_sem_etc( lock->semaphoreID, 1, B_DO_NOT_RESCHEDULE );
- }
-
- return PR_SUCCESS;
-}
-
-PR_IMPLEMENT(void)
- PR_AssertCurrentThreadOwnsLock(PRLock *lock)
-{
- PR_ASSERT(lock != NULL);
- PR_ASSERT(lock->owner == find_thread( NULL ));
-}
diff --git a/nsprpub/pr/src/bthreads/btmisc.c b/nsprpub/pr/src/bthreads/btmisc.c
deleted file mode 100644
index 8d84a6069..000000000
--- a/nsprpub/pr/src/bthreads/btmisc.c
+++ /dev/null
@@ -1,72 +0,0 @@
-/* -*- Mode: C++; c-basic-offset: 4 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "primpl.h"
-#include <stdio.h>
-
-// void _PR_InitCPUs(void) {PT_LOG("_PR_InitCPUs")}
-// void _MD_StartInterrupts(void) {PT_LOG("_MD_StartInterrupts")}
-
-/* this is a total hack.. */
-
-struct protoent* getprotobyname(const char* name)
-{
- return 0;
-}
-
-struct protoent* getprotobynumber(int number)
-{
- return 0;
-}
-
-/* this is needed by prinit for some reason */
-void
-_PR_InitStacks (void)
-{
-}
-
-/* this is needed by prinit for some reason */
-void
-_PR_InitTPD (void)
-{
-}
-
-/*
-** Create extra virtual processor threads. Generally used with MP systems.
-*/
-PR_IMPLEMENT(void)
- PR_SetConcurrency (PRUintn numCPUs)
-{
-}
-
-/*
-** Set thread recycle mode to on (1) or off (0)
-*/
-PR_IMPLEMENT(void)
- PR_SetThreadRecycleMode (PRUint32 flag)
-{
-}
-
-/*
-** Get context registers, return with error for now.
-*/
-
-PR_IMPLEMENT(PRWord *)
-_MD_HomeGCRegisters( PRThread *t, int isCurrent, int *np )
-{
- return 0;
-}
-
-PR_IMPLEMENT(void *)
-PR_GetSP( PRThread *t )
-{
- return 0;
-}
-
-PR_IMPLEMENT(PRStatus)
-PR_EnumerateThreads( PREnumerator func, void *arg )
-{
- return PR_FAILURE;
-}
diff --git a/nsprpub/pr/src/bthreads/btmon.c b/nsprpub/pr/src/bthreads/btmon.c
deleted file mode 100644
index bd05e73dc..000000000
--- a/nsprpub/pr/src/bthreads/btmon.c
+++ /dev/null
@@ -1,201 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <kernel/OS.h>
-
-#include "primpl.h"
-
-/*
-** Create a new monitor. Monitors are re-entrant locks with a single built-in
-** condition variable.
-**
-** This may fail if memory is tight or if some operating system resource
-** is low.
-*/
-PR_IMPLEMENT(PRMonitor*)
- PR_NewMonitor (void)
-{
- PRMonitor *mon;
- PRCondVar *cvar;
- PRLock *lock;
-
- mon = PR_NEWZAP( PRMonitor );
- if( mon )
- {
- lock = PR_NewLock();
- if( !lock )
- {
- PR_DELETE( mon );
- return( 0 );
- }
-
- cvar = PR_NewCondVar( lock );
- if( !cvar )
- {
- PR_DestroyLock( lock );
- PR_DELETE( mon );
- return( 0 );
- }
-
- mon->cvar = cvar;
- mon->name = NULL;
- }
-
- return( mon );
-}
-
-PR_IMPLEMENT(PRMonitor*) PR_NewNamedMonitor(const char* name)
-{
- PRMonitor* mon = PR_NewMonitor();
- if( mon )
- {
- mon->name = name;
- }
- return mon;
-}
-
-/*
-** Destroy a monitor. The caller is responsible for guaranteeing that the
-** monitor is no longer in use. There must be no thread waiting on the
-** monitor's condition variable and that the lock is not held.
-**
-*/
-PR_IMPLEMENT(void)
- PR_DestroyMonitor (PRMonitor *mon)
-{
- PR_DestroyLock( mon->cvar->lock );
- PR_DestroyCondVar( mon->cvar );
- PR_DELETE( mon );
-}
-
-/*
-** Enter the lock associated with the monitor. If the calling thread currently
-** is in the monitor, the call to enter will silently succeed. In either case,
-** it will increment the entry count by one.
-*/
-PR_IMPLEMENT(void)
- PR_EnterMonitor (PRMonitor *mon)
-{
- if( mon->cvar->lock->owner == find_thread( NULL ) )
- {
- mon->entryCount++;
-
- } else
- {
- PR_Lock( mon->cvar->lock );
- mon->entryCount = 1;
- }
-}
-
-/*
-** Decrement the entry count associated with the monitor. If the decremented
-** entry count is zero, the monitor is exited. Returns PR_FAILURE if the
-** calling thread has not entered the monitor.
-*/
-PR_IMPLEMENT(PRStatus)
- PR_ExitMonitor (PRMonitor *mon)
-{
- if( mon->cvar->lock->owner != find_thread( NULL ) )
- {
- return( PR_FAILURE );
- }
- if( --mon->entryCount == 0 )
- {
- return( PR_Unlock( mon->cvar->lock ) );
- }
- return( PR_SUCCESS );
-}
-
-/*
-** Wait for a notify on the monitor's condition variable. Sleep for "ticks"
-** amount of time (if "ticks" is PR_INTERVAL_NO_TIMEOUT then the sleep is
-** indefinite).
-**
-** While the thread is waiting it exits the monitor (as if it called
-** PR_ExitMonitor as many times as it had called PR_EnterMonitor). When
-** the wait has finished the thread regains control of the monitors lock
-** with the same entry count as before the wait began.
-**
-** The thread waiting on the monitor will be resumed when the monitor is
-** notified (assuming the thread is the next in line to receive the
-** notify) or when the "ticks" timeout elapses.
-**
-** Returns PR_FAILURE if the caller has not entered the monitor.
-*/
-PR_IMPLEMENT(PRStatus)
- PR_Wait (PRMonitor *mon, PRIntervalTime ticks)
-{
- PRUint32 entryCount;
- PRUintn status;
- PRThread *meThread;
- thread_id me = find_thread( NULL );
- meThread = PR_GetCurrentThread();
-
- if( mon->cvar->lock->owner != me ) return( PR_FAILURE );
-
- entryCount = mon->entryCount;
- mon->entryCount = 0;
-
- status = PR_WaitCondVar( mon->cvar, ticks );
-
- mon->entryCount = entryCount;
-
- return( status );
-}
-
-/*
-** Notify a thread waiting on the monitor's condition variable. If a thread
-** is waiting on the condition variable (using PR_Wait) then it is awakened
-** and attempts to reenter the monitor.
-*/
-PR_IMPLEMENT(PRStatus)
- PR_Notify (PRMonitor *mon)
-{
- if( mon->cvar->lock->owner != find_thread( NULL ) )
- {
- return( PR_FAILURE );
- }
-
- PR_NotifyCondVar( mon->cvar );
- return( PR_SUCCESS );
-}
-
-/*
-** Notify all of the threads waiting on the monitor's condition variable.
-** All of threads waiting on the condition are scheduled to reenter the
-** monitor.
-*/
-PR_IMPLEMENT(PRStatus)
- PR_NotifyAll (PRMonitor *mon)
-{
- if( mon->cvar->lock->owner != find_thread( NULL ) )
- {
- return( PR_FAILURE );
- }
-
- PR_NotifyAllCondVar( mon->cvar );
- return( PR_SUCCESS );
-}
-
-/*
-** Return the number of times that the current thread has entered the
-** lock. Returns zero if the current thread has not entered the lock.
-*/
-PR_IMPLEMENT(PRIntn)
- PR_GetMonitorEntryCount(PRMonitor *mon)
-{
- return( (mon->cvar->lock->owner == find_thread( NULL )) ?
- mon->entryCount : 0 );
-}
-
-/*
-** If the current thread is in |mon|, this assertion is guaranteed to
-** succeed. Otherwise, the behavior of this function is undefined.
-*/
-PR_IMPLEMENT(void)
- PR_AssertCurrentThreadInMonitor(PRMonitor *mon)
-{
- PR_ASSERT_CURRENT_THREAD_OWNS_LOCK(mon->cvar->lock);
-}
diff --git a/nsprpub/pr/src/bthreads/btsem.c b/nsprpub/pr/src/bthreads/btsem.c
deleted file mode 100644
index 011ee6bd3..000000000
--- a/nsprpub/pr/src/bthreads/btsem.c
+++ /dev/null
@@ -1,98 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <kernel/OS.h>
-
-#include "primpl.h"
-
-/*
-** Create a new semaphore object.
-*/
-PR_IMPLEMENT(PRSemaphore*)
- PR_NewSem (PRUintn value)
-{
- PRSemaphore *semaphore;
-
- if (!_pr_initialized) _PR_ImplicitInitialization();
-
- semaphore = PR_NEWZAP(PRSemaphore);
- if (NULL != semaphore) {
- if ((semaphore->sem = create_sem(value, "nspr_sem")) < B_NO_ERROR)
- return NULL;
- else
- return semaphore;
- }
- return NULL;
-}
-
-/*
-** Destroy the given semaphore object.
-**
-*/
-PR_IMPLEMENT(void)
- PR_DestroySem (PRSemaphore *sem)
-{
- status_t result;
-
- PR_ASSERT(sem != NULL);
- result = delete_sem(sem->sem);
- PR_ASSERT(result == B_NO_ERROR);
- PR_DELETE(sem);
-}
-
-/*
-** Wait on a Semaphore.
-**
-** This routine allows a calling thread to wait or proceed depending upon
-** the state of the semahore sem. The thread can proceed only if the
-** counter value of the semaphore sem is currently greater than 0. If the
-** value of semaphore sem is positive, it is decremented by one and the
-** routine returns immediately allowing the calling thread to continue. If
-** the value of semaphore sem is 0, the calling thread blocks awaiting the
-** semaphore to be released by another thread.
-**
-** This routine can return PR_PENDING_INTERRUPT if the waiting thread
-** has been interrupted.
-*/
-PR_IMPLEMENT(PRStatus)
- PR_WaitSem (PRSemaphore *sem)
-{
- PR_ASSERT(sem != NULL);
- if (acquire_sem(sem->sem) == B_NO_ERROR)
- return PR_SUCCESS;
- else
- return PR_FAILURE;
-}
-
-/*
-** This routine increments the counter value of the semaphore. If other
-** threads are blocked for the semaphore, then the scheduler will
-** determine which ONE thread will be unblocked.
-*/
-PR_IMPLEMENT(void)
- PR_PostSem (PRSemaphore *sem)
-{
- status_t result;
-
- PR_ASSERT(sem != NULL);
- result = release_sem_etc(sem->sem, 1, B_DO_NOT_RESCHEDULE);
- PR_ASSERT(result == B_NO_ERROR);
-}
-
-/*
-** Returns the value of the semaphore referenced by sem without affecting
-** the state of the semaphore. The value represents the semaphore value
-** at the time of the call, but may not be the actual value when the
-** caller inspects it.
-*/
-PR_IMPLEMENT(PRUintn)
- PR_GetValueSem (PRSemaphore *sem)
-{
- sem_info info;
-
- PR_ASSERT(sem != NULL);
- get_sem_info(sem->sem, &info);
- return info.count;
-}
diff --git a/nsprpub/pr/src/bthreads/btthread.c b/nsprpub/pr/src/bthreads/btthread.c
deleted file mode 100644
index c2a1cd82b..000000000
--- a/nsprpub/pr/src/bthreads/btthread.c
+++ /dev/null
@@ -1,662 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <kernel/OS.h>
-#include <support/TLS.h>
-
-#include "prlog.h"
-#include "primpl.h"
-#include "prcvar.h"
-#include "prpdce.h"
-
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-
-/* values for PRThread.state */
-#define BT_THREAD_PRIMORD 0x01 /* this is the primordial thread */
-#define BT_THREAD_SYSTEM 0x02 /* this is a system thread */
-#define BT_THREAD_JOINABLE 0x04 /* this is a joinable thread */
-
-struct _BT_Bookeeping
-{
- PRLock *ml; /* a lock to protect ourselves */
- sem_id cleanUpSem; /* the primoridal thread will block on this
- sem while waiting for the user threads */
- PRInt32 threadCount; /* user thred count */
-
-} bt_book = { NULL, B_ERROR, 0 };
-
-
-#define BT_TPD_LIMIT 128 /* number of TPD slots we'll provide (arbitrary) */
-
-/* these will be used to map an index returned by PR_NewThreadPrivateIndex()
- to the corresponding beos native TLS slot number, and to the destructor
- for that slot - note that, because it is allocated globally, this data
- will be automatically zeroed for us when the program begins */
-static int32 tpd_beosTLSSlots[BT_TPD_LIMIT];
-static PRThreadPrivateDTOR tpd_dtors[BT_TPD_LIMIT];
-
-static vint32 tpd_slotsUsed=0; /* number of currently-allocated TPD slots */
-static int32 tls_prThreadSlot; /* TLS slot in which PRThread will be stored */
-
-/* this mutex will be used to synchronize access to every
- PRThread.md.joinSem and PRThread.md.is_joining (we could
- actually allocate one per thread, but that seems a bit excessive,
- especially considering that there will probably be little
- contention, PR_JoinThread() is allowed to block anyway, and the code
- protected by the mutex is short/fast) */
-static PRLock *joinSemLock;
-
-static PRUint32 _bt_MapNSPRToNativePriority( PRThreadPriority priority );
-static PRThreadPriority _bt_MapNativeToNSPRPriority( PRUint32 priority );
-static void _bt_CleanupThread(void *arg);
-static PRThread *_bt_AttachThread();
-
-void
-_PR_InitThreads (PRThreadType type, PRThreadPriority priority,
- PRUintn maxPTDs)
-{
- PRThread *primordialThread;
- PRUint32 beThreadPriority;
-
- /* allocate joinSem mutex */
- joinSemLock = PR_NewLock();
- if (joinSemLock == NULL)
- {
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
- return;
- }
-
- /*
- ** Create and initialize NSPR structure for our primordial thread.
- */
-
- primordialThread = PR_NEWZAP(PRThread);
- if( NULL == primordialThread )
- {
- PR_SetError( PR_OUT_OF_MEMORY_ERROR, 0 );
- return;
- }
-
- primordialThread->md.joinSem = B_ERROR;
-
- /*
- ** Set the priority to the desired level.
- */
-
- beThreadPriority = _bt_MapNSPRToNativePriority( priority );
-
- set_thread_priority( find_thread( NULL ), beThreadPriority );
-
- primordialThread->priority = priority;
-
-
- /* set the thread's state - note that the thread is not joinable */
- primordialThread->state |= BT_THREAD_PRIMORD;
- if (type == PR_SYSTEM_THREAD)
- primordialThread->state |= BT_THREAD_SYSTEM;
-
- /*
- ** Allocate a TLS slot for the PRThread structure (just using
- ** native TLS, as opposed to NSPR TPD, will make PR_GetCurrentThread()
- ** somewhat faster, and will leave one more TPD slot for our client)
- */
-
- tls_prThreadSlot = tls_allocate();
-
- /*
- ** Stuff our new PRThread structure into our thread specific
- ** slot.
- */
-
- tls_set(tls_prThreadSlot, primordialThread);
-
- /* allocate lock for bt_book */
- bt_book.ml = PR_NewLock();
- if( NULL == bt_book.ml )
- {
- PR_SetError( PR_OUT_OF_MEMORY_ERROR, 0 );
- return;
- }
-}
-
-PRUint32
-_bt_MapNSPRToNativePriority( PRThreadPriority priority )
- {
- switch( priority )
- {
- case PR_PRIORITY_LOW: return( B_LOW_PRIORITY );
- case PR_PRIORITY_NORMAL: return( B_NORMAL_PRIORITY );
- case PR_PRIORITY_HIGH: return( B_DISPLAY_PRIORITY );
- case PR_PRIORITY_URGENT: return( B_URGENT_DISPLAY_PRIORITY );
- default: return( B_NORMAL_PRIORITY );
- }
-}
-
-PRThreadPriority
-_bt_MapNativeToNSPRPriority(PRUint32 priority)
- {
- if (priority < B_NORMAL_PRIORITY)
- return PR_PRIORITY_LOW;
- if (priority < B_DISPLAY_PRIORITY)
- return PR_PRIORITY_NORMAL;
- if (priority < B_URGENT_DISPLAY_PRIORITY)
- return PR_PRIORITY_HIGH;
- return PR_PRIORITY_URGENT;
-}
-
-PRUint32
-_bt_mapNativeToNSPRPriority( int32 priority )
-{
- switch( priority )
- {
- case PR_PRIORITY_LOW: return( B_LOW_PRIORITY );
- case PR_PRIORITY_NORMAL: return( B_NORMAL_PRIORITY );
- case PR_PRIORITY_HIGH: return( B_DISPLAY_PRIORITY );
- case PR_PRIORITY_URGENT: return( B_URGENT_DISPLAY_PRIORITY );
- default: return( B_NORMAL_PRIORITY );
- }
-}
-
-/* This method is called by all NSPR threads as they exit */
-void _bt_CleanupThread(void *arg)
-{
- PRThread *me = PR_GetCurrentThread();
- int32 i;
-
- /* first, clean up all thread-private data */
- for (i = 0; i < tpd_slotsUsed; i++)
- {
- void *oldValue = tls_get(tpd_beosTLSSlots[i]);
- if ( oldValue != NULL && tpd_dtors[i] != NULL )
- (*tpd_dtors[i])(oldValue);
- }
-
- /* if this thread is joinable, wait for someone to join it */
- if (me->state & BT_THREAD_JOINABLE)
- {
- /* protect access to our joinSem */
- PR_Lock(joinSemLock);
-
- if (me->md.is_joining)
- {
- /* someone is already waiting to join us (they've
- allocated a joinSem for us) - let them know we're
- ready */
- delete_sem(me->md.joinSem);
-
- PR_Unlock(joinSemLock);
-
- }
- else
- {
- /* noone is currently waiting for our demise - it
- is our responsibility to allocate the joinSem
- and block on it */
- me->md.joinSem = create_sem(0, "join sem");
-
- /* we're done accessing our joinSem */
- PR_Unlock(joinSemLock);
-
- /* wait for someone to join us */
- while (acquire_sem(me->md.joinSem) == B_INTERRUPTED);
- }
- }
-
- /* if this is a user thread, we must update our books */
- if ((me->state & BT_THREAD_SYSTEM) == 0)
- {
- /* synchronize access to bt_book */
- PR_Lock( bt_book.ml );
-
- /* decrement the number of currently-alive user threads */
- bt_book.threadCount--;
-
- if (bt_book.threadCount == 0 && bt_book.cleanUpSem != B_ERROR) {
- /* we are the last user thread, and the primordial thread is
- blocked in PR_Cleanup() waiting for us to finish - notify
- it */
- delete_sem(bt_book.cleanUpSem);
- }
-
- PR_Unlock( bt_book.ml );
- }
-
- /* finally, delete this thread's PRThread */
- PR_DELETE(me);
-}
-
-/**
- * This is a wrapper that all threads invoke that allows us to set some
- * things up prior to a thread's invocation and clean up after a thread has
- * exited.
- */
-static void*
-_bt_root (void* arg)
- {
- PRThread *thred = (PRThread*)arg;
- PRIntn rv;
- void *privData;
- status_t result;
- int i;
-
- /* save our PRThread object into our TLS */
- tls_set(tls_prThreadSlot, thred);
-
- thred->startFunc(thred->arg); /* run the dang thing */
-
- /* clean up */
- _bt_CleanupThread(NULL);
-
- return 0;
-}
-
-PR_IMPLEMENT(PRThread*)
- PR_CreateThread (PRThreadType type, void (*start)(void* arg), void* arg,
- PRThreadPriority priority, PRThreadScope scope,
- PRThreadState state, PRUint32 stackSize)
-{
- PRUint32 bePriority;
-
- PRThread* thred;
-
- if (!_pr_initialized) _PR_ImplicitInitialization();
-
- thred = PR_NEWZAP(PRThread);
- if (thred == NULL)
- {
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
- return NULL;
- }
-
- thred->md.joinSem = B_ERROR;
-
- thred->arg = arg;
- thred->startFunc = start;
- thred->priority = priority;
-
- if( state == PR_JOINABLE_THREAD )
- {
- thred->state |= BT_THREAD_JOINABLE;
- }
-
- /* keep some books */
-
- PR_Lock( bt_book.ml );
-
- if (type == PR_USER_THREAD)
- {
- bt_book.threadCount++;
- }
-
- PR_Unlock( bt_book.ml );
-
- bePriority = _bt_MapNSPRToNativePriority( priority );
-
- thred->md.tid = spawn_thread((thread_func)_bt_root, "moz-thread",
- bePriority, thred);
- if (thred->md.tid < B_OK) {
- PR_SetError(PR_UNKNOWN_ERROR, thred->md.tid);
- PR_DELETE(thred);
- return NULL;
- }
-
- if (resume_thread(thred->md.tid) < B_OK) {
- PR_SetError(PR_UNKNOWN_ERROR, 0);
- PR_DELETE(thred);
- return NULL;
- }
-
- return thred;
- }
-
-PR_IMPLEMENT(PRThread*)
- PR_AttachThread(PRThreadType type, PRThreadPriority priority,
- PRThreadStack *stack)
-{
- /* PR_GetCurrentThread() will attach a thread if necessary */
- return PR_GetCurrentThread();
-}
-
-PR_IMPLEMENT(void)
- PR_DetachThread()
-{
- /* we don't support detaching */
-}
-
-PR_IMPLEMENT(PRStatus)
- PR_JoinThread (PRThread* thred)
-{
- status_t eval, status;
-
- PR_ASSERT(thred != NULL);
-
- if ((thred->state & BT_THREAD_JOINABLE) == 0)
- {
- PR_SetError( PR_INVALID_ARGUMENT_ERROR, 0 );
- return( PR_FAILURE );
- }
-
- /* synchronize access to the thread's joinSem */
- PR_Lock(joinSemLock);
-
- if (thred->md.is_joining)
- {
- /* another thread is already waiting to join the specified
- thread - we must fail */
- PR_Unlock(joinSemLock);
- return PR_FAILURE;
- }
-
- /* let others know we are waiting to join */
- thred->md.is_joining = PR_TRUE;
-
- if (thred->md.joinSem == B_ERROR)
- {
- /* the thread hasn't finished yet - it is our responsibility to
- allocate a joinSem and wait on it */
- thred->md.joinSem = create_sem(0, "join sem");
-
- /* we're done changing the joinSem now */
- PR_Unlock(joinSemLock);
-
- /* wait for the thread to finish */
- while (acquire_sem(thred->md.joinSem) == B_INTERRUPTED);
-
- }
- else
- {
- /* the thread has already finished, and has allocated the
- joinSem itself - let it know it can finally die */
- delete_sem(thred->md.joinSem);
-
- PR_Unlock(joinSemLock);
- }
-
- /* make sure the thread is dead */
- wait_for_thread(thred->md.tid, &eval);
-
- return PR_SUCCESS;
-}
-
-PR_IMPLEMENT(PRThread*)
- PR_GetCurrentThread ()
-{
- PRThread* thred;
-
- if (!_pr_initialized) _PR_ImplicitInitialization();
-
- thred = (PRThread *)tls_get( tls_prThreadSlot);
- if (thred == NULL)
- {
- /* this thread doesn't have a PRThread structure (it must be
- a native thread not created by the NSPR) - assimilate it */
- thred = _bt_AttachThread();
- }
- PR_ASSERT(NULL != thred);
-
- return thred;
-}
-
-PR_IMPLEMENT(PRThreadScope)
- PR_GetThreadScope (const PRThread* thred)
-{
- PR_ASSERT(thred != NULL);
- return PR_GLOBAL_THREAD;
-}
-
-PR_IMPLEMENT(PRThreadType)
- PR_GetThreadType (const PRThread* thred)
-{
- PR_ASSERT(thred != NULL);
- return (thred->state & BT_THREAD_SYSTEM) ?
- PR_SYSTEM_THREAD : PR_USER_THREAD;
-}
-
-PR_IMPLEMENT(PRThreadState)
- PR_GetThreadState (const PRThread* thred)
-{
- PR_ASSERT(thred != NULL);
- return (thred->state & BT_THREAD_JOINABLE)?
- PR_JOINABLE_THREAD: PR_UNJOINABLE_THREAD;
-}
-
-PR_IMPLEMENT(PRThreadPriority)
- PR_GetThreadPriority (const PRThread* thred)
-{
- PR_ASSERT(thred != NULL);
- return thred->priority;
-} /* PR_GetThreadPriority */
-
-PR_IMPLEMENT(void) PR_SetThreadPriority(PRThread *thred,
- PRThreadPriority newPri)
-{
- PRUint32 bePriority;
-
- PR_ASSERT( thred != NULL );
-
- thred->priority = newPri;
- bePriority = _bt_MapNSPRToNativePriority( newPri );
- set_thread_priority( thred->md.tid, bePriority );
-}
-
-PR_IMPLEMENT(PRStatus)
- PR_NewThreadPrivateIndex (PRUintn* newIndex,
- PRThreadPrivateDTOR destructor)
-{
- int32 index;
-
- if (!_pr_initialized) _PR_ImplicitInitialization();
-
- /* reserve the next available tpd slot */
- index = atomic_add( &tpd_slotsUsed, 1 );
- if (index >= BT_TPD_LIMIT)
- {
- /* no slots left - decrement value, then fail */
- atomic_add( &tpd_slotsUsed, -1 );
- PR_SetError( PR_TPD_RANGE_ERROR, 0 );
- return( PR_FAILURE );
- }
-
- /* allocate a beos-native TLS slot for this index (the new slot
- automatically contains NULL) */
- tpd_beosTLSSlots[index] = tls_allocate();
-
- /* remember the destructor */
- tpd_dtors[index] = destructor;
-
- *newIndex = (PRUintn)index;
-
- return( PR_SUCCESS );
-}
-
-PR_IMPLEMENT(PRStatus)
- PR_SetThreadPrivate (PRUintn index, void* priv)
-{
- void *oldValue;
-
- /*
- ** Sanity checking
- */
-
- if(index < 0 || index >= tpd_slotsUsed || index >= BT_TPD_LIMIT)
- {
- PR_SetError( PR_TPD_RANGE_ERROR, 0 );
- return( PR_FAILURE );
- }
-
- /* if the old value isn't NULL, and the dtor for this slot isn't
- NULL, we must destroy the data */
- oldValue = tls_get(tpd_beosTLSSlots[index]);
- if (oldValue != NULL && tpd_dtors[index] != NULL)
- (*tpd_dtors[index])(oldValue);
-
- /* save new value */
- tls_set(tpd_beosTLSSlots[index], priv);
-
- return( PR_SUCCESS );
- }
-
-PR_IMPLEMENT(void*)
- PR_GetThreadPrivate (PRUintn index)
-{
- /* make sure the index is valid */
- if (index < 0 || index >= tpd_slotsUsed || index >= BT_TPD_LIMIT)
- {
- PR_SetError( PR_TPD_RANGE_ERROR, 0 );
- return NULL;
- }
-
- /* return the value */
- return tls_get( tpd_beosTLSSlots[index] );
- }
-
-
-PR_IMPLEMENT(PRStatus)
- PR_Interrupt (PRThread* thred)
-{
- PRIntn rv;
-
- PR_ASSERT(thred != NULL);
-
- /*
- ** there seems to be a bug in beos R5 in which calling
- ** resume_thread() on a blocked thread returns B_OK instead
- ** of B_BAD_THREAD_STATE (beos bug #20000422-19095). as such,
- ** to interrupt a thread, we will simply suspend then resume it
- ** (no longer call resume_thread(), check for B_BAD_THREAD_STATE,
- ** the suspend/resume to wake up a blocked thread). this wakes
- ** up blocked threads properly, and doesn't hurt unblocked threads
- ** (they simply get stopped then re-started immediately)
- */
-
- rv = suspend_thread( thred->md.tid );
- if( rv != B_NO_ERROR )
- {
- /* this doesn't appear to be a valid thread_id */
- PR_SetError( PR_UNKNOWN_ERROR, rv );
- return PR_FAILURE;
- }
-
- rv = resume_thread( thred->md.tid );
- if( rv != B_NO_ERROR )
- {
- PR_SetError( PR_UNKNOWN_ERROR, rv );
- return PR_FAILURE;
- }
-
- return PR_SUCCESS;
-}
-
-PR_IMPLEMENT(void)
- PR_ClearInterrupt ()
-{
-}
-
-PR_IMPLEMENT(PRStatus)
- PR_Yield ()
-{
- /* we just sleep for long enough to cause a reschedule (100
- microseconds) */
- snooze(100);
-}
-
-#define BT_MILLION 1000000UL
-
-PR_IMPLEMENT(PRStatus)
- PR_Sleep (PRIntervalTime ticks)
-{
- bigtime_t tps;
- status_t status;
-
- if (!_pr_initialized) _PR_ImplicitInitialization();
-
- tps = PR_IntervalToMicroseconds( ticks );
-
- status = snooze(tps);
- if (status == B_NO_ERROR) return PR_SUCCESS;
-
- PR_SetError(PR_NOT_IMPLEMENTED_ERROR, status);
- return PR_FAILURE;
-}
-
-PR_IMPLEMENT(PRStatus)
- PR_Cleanup ()
-{
- PRThread *me = PR_GetCurrentThread();
-
- PR_ASSERT(me->state & BT_THREAD_PRIMORD);
- if ((me->state & BT_THREAD_PRIMORD) == 0) {
- return PR_FAILURE;
- }
-
- PR_Lock( bt_book.ml );
-
- if (bt_book.threadCount != 0)
- {
- /* we'll have to wait for some threads to finish - create a
- sem to block on */
- bt_book.cleanUpSem = create_sem(0, "cleanup sem");
- }
-
- PR_Unlock( bt_book.ml );
-
- /* note that, if all the user threads were already dead, we
- wouldn't have created a sem above, so this acquire_sem()
- will fail immediately */
- while (acquire_sem(bt_book.cleanUpSem) == B_INTERRUPTED);
-
- return PR_SUCCESS;
-}
-
-PR_IMPLEMENT(void)
- PR_ProcessExit (PRIntn status)
-{
- exit(status);
-}
-
-PRThread *_bt_AttachThread()
-{
- PRThread *thread;
- thread_info tInfo;
-
- /* make sure this thread doesn't already have a PRThread structure */
- PR_ASSERT(tls_get(tls_prThreadSlot) == NULL);
-
- /* allocate a PRThread structure for this thread */
- thread = PR_NEWZAP(PRThread);
- if (thread == NULL)
- {
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
- return NULL;
- }
-
- /* get the native thread's current state */
- get_thread_info(find_thread(NULL), &tInfo);
-
- /* initialize new PRThread */
- thread->md.tid = tInfo.thread;
- thread->md.joinSem = B_ERROR;
- thread->priority = _bt_MapNativeToNSPRPriority(tInfo.priority);
-
- /* attached threads are always non-joinable user threads */
- thread->state = 0;
-
- /* increment user thread count */
- PR_Lock(bt_book.ml);
- bt_book.threadCount++;
- PR_Unlock(bt_book.ml);
-
- /* store this thread's PRThread */
- tls_set(tls_prThreadSlot, thread);
-
- /* the thread must call _bt_CleanupThread() before it dies, in order
- to clean up its PRThread, synchronize with the primordial thread,
- etc. */
- on_exit_thread(_bt_CleanupThread, NULL);
-
- return thread;
-}
diff --git a/nsprpub/pr/src/bthreads/objs.mk b/nsprpub/pr/src/bthreads/objs.mk
deleted file mode 100644
index b273ba46e..000000000
--- a/nsprpub/pr/src/bthreads/objs.mk
+++ /dev/null
@@ -1,11 +0,0 @@
-#
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-# This makefile appends to the variable OBJS the bthread object modules
-# that will be part of the nspr20 library.
-
-include $(srcdir)/bthreads/bsrcs.mk
-
-OBJS += $(BTCSRCS:%.c=bthreads/$(OBJDIR)/%.$(OBJ_SUFFIX))
diff --git a/nsprpub/pr/src/cplus/rcascii.h b/nsprpub/pr/src/cplus/rcascii.h
index 7383d8d66..f8b59ce0f 100644
--- a/nsprpub/pr/src/cplus/rcascii.h
+++ b/nsprpub/pr/src/cplus/rcascii.h
@@ -81,7 +81,7 @@ private:
** for this class.
*/
PRSize StuffFunction(void*, const char*, PRSize);
-
+
}; /* RCFormatBuffer */
/*
diff --git a/nsprpub/pr/src/cplus/rcbase.cpp b/nsprpub/pr/src/cplus/rcbase.cpp
index c258081d3..7c12e6d3d 100644
--- a/nsprpub/pr/src/cplus/rcbase.cpp
+++ b/nsprpub/pr/src/cplus/rcbase.cpp
@@ -11,13 +11,21 @@
RCBase::~RCBase() { }
-PRSize RCBase::GetErrorTextLength() { return PR_GetErrorTextLength(); }
-PRSize RCBase::CopyErrorText(char *text) { return PR_GetErrorText(text); }
+PRSize RCBase::GetErrorTextLength() {
+ return PR_GetErrorTextLength();
+}
+PRSize RCBase::CopyErrorText(char *text) {
+ return PR_GetErrorText(text);
+}
void RCBase::SetError(PRErrorCode error, PRInt32 oserror)
- { PR_SetError(error, oserror); }
+{
+ PR_SetError(error, oserror);
+}
void RCBase::SetErrorText(PRSize text_length, const char *text)
- { PR_SetErrorText(text_length, text); }
+{
+ PR_SetErrorText(text_length, text);
+}
/* rcbase.cpp */
diff --git a/nsprpub/pr/src/cplus/rcbase.h b/nsprpub/pr/src/cplus/rcbase.h
index 58df43c12..3cc91f804 100644
--- a/nsprpub/pr/src/cplus/rcbase.h
+++ b/nsprpub/pr/src/cplus/rcbase.h
@@ -43,8 +43,12 @@ protected:
RCBase() { }
}; /* RCObject */
-inline PRErrorCode RCBase::GetError() { return PR_GetError(); }
-inline PRInt32 RCBase::GetOSError() { return PR_GetOSError(); }
+inline PRErrorCode RCBase::GetError() {
+ return PR_GetError();
+}
+inline PRInt32 RCBase::GetOSError() {
+ return PR_GetOSError();
+}
#endif /* defined(_RCRUNTIME_H) */
diff --git a/nsprpub/pr/src/cplus/rccv.cpp b/nsprpub/pr/src/cplus/rccv.cpp
index 32b84b1cb..f12438535 100644
--- a/nsprpub/pr/src/cplus/rccv.cpp
+++ b/nsprpub/pr/src/cplus/rccv.cpp
@@ -22,7 +22,9 @@ RCCondition::RCCondition(class RCLock *lock): RCBase()
RCCondition::~RCCondition()
{
- if (NULL != cv) PR_DestroyCondVar(cv);
+ if (NULL != cv) {
+ PR_DestroyCondVar(cv);
+ }
} /* RCCondition::~RCCondition */
PRStatus RCCondition::Wait()
@@ -34,8 +36,9 @@ PRStatus RCCondition::Wait()
SetError(PR_INVALID_ARGUMENT_ERROR, 0);
rv = PR_FAILURE;
}
- else
+ else {
rv = PR_WaitCondVar(cv, timeout.interval);
+ }
return rv;
} /* RCCondition::Wait */
@@ -60,6 +63,8 @@ PRStatus RCCondition::SetTimeout(const RCInterval& tmo)
return PR_SUCCESS;
} /* RCCondition::SetTimeout */
-RCInterval RCCondition::GetTimeout() const { return timeout; }
+RCInterval RCCondition::GetTimeout() const {
+ return timeout;
+}
/* rccv.cpp */
diff --git a/nsprpub/pr/src/cplus/rccv.h b/nsprpub/pr/src/cplus/rccv.h
index e5c89135f..afeec6161 100644
--- a/nsprpub/pr/src/cplus/rccv.h
+++ b/nsprpub/pr/src/cplus/rccv.h
@@ -41,7 +41,7 @@ public:
virtual PRStatus Broadcast(); /* perhaps ready many threads */
virtual PRStatus SetTimeout(const RCInterval&);
- /* set object's current timeout value */
+ /* set object's current timeout value */
private:
PRCondVar *cv;
diff --git a/nsprpub/pr/src/cplus/rcfileio.cpp b/nsprpub/pr/src/cplus/rcfileio.cpp
index cdf6318a0..91c5fde6f 100644
--- a/nsprpub/pr/src/cplus/rcfileio.cpp
+++ b/nsprpub/pr/src/cplus/rcfileio.cpp
@@ -13,24 +13,42 @@
RCFileIO::RCFileIO(): RCIO(RCIO::file) { }
-RCFileIO::~RCFileIO() { if (NULL != fd) (void)Close(); }
+RCFileIO::~RCFileIO() {
+ if (NULL != fd) {
+ (void)Close();
+ }
+}
PRInt64 RCFileIO::Available()
- { return fd->methods->available(fd); }
+{
+ return fd->methods->available(fd);
+}
PRStatus RCFileIO::Close()
- { PRStatus rv = fd->methods->close(fd); fd = NULL; return rv; }
+{
+ PRStatus rv = fd->methods->close(fd);
+ fd = NULL;
+ return rv;
+}
-PRStatus RCFileIO::Delete(const char* filename) { return PR_Delete(filename); }
+PRStatus RCFileIO::Delete(const char* filename) {
+ return PR_Delete(filename);
+}
PRStatus RCFileIO::FileInfo(RCFileInfo* info) const
- { return fd->methods->fileInfo64(fd, &info->info); }
+{
+ return fd->methods->fileInfo64(fd, &info->info);
+}
PRStatus RCFileIO::FileInfo(const char *name, RCFileInfo* info)
- { return PR_GetFileInfo64(name, &info->info); }
+{
+ return PR_GetFileInfo64(name, &info->info);
+}
PRStatus RCFileIO::Fsync()
- { return fd->methods->fsync(fd); }
+{
+ return fd->methods->fsync(fd);
+}
PRStatus RCFileIO::Open(const char *filename, PRIntn flags, PRIntn mode)
{
@@ -39,7 +57,9 @@ PRStatus RCFileIO::Open(const char *filename, PRIntn flags, PRIntn mode)
} /* RCFileIO::Open */
PRInt32 RCFileIO::Read(void *buf, PRSize amount)
- { return fd->methods->read(fd, buf, amount); }
+{
+ return fd->methods->read(fd, buf, amount);
+}
PRInt64 RCFileIO::Seek(PRInt64 offset, RCIO::Whence how)
{
@@ -55,11 +75,15 @@ PRInt64 RCFileIO::Seek(PRInt64 offset, RCIO::Whence how)
} /* RCFileIO::Seek */
PRInt32 RCFileIO::Write(const void *buf, PRSize amount)
- { return fd->methods->write(fd, buf, amount); }
+{
+ return fd->methods->write(fd, buf, amount);
+}
PRInt32 RCFileIO::Writev(
const PRIOVec *iov, PRSize size, const RCInterval& timeout)
- { return fd->methods->writev(fd, iov, size, timeout); }
+{
+ return fd->methods->writev(fd, iov, size, timeout);
+}
RCIO *RCFileIO::GetSpecialFile(RCFileIO::SpecialFile special)
{
@@ -78,7 +102,9 @@ RCIO *RCFileIO::GetSpecialFile(RCFileIO::SpecialFile special)
if (NULL != fd)
{
spec = new RCFileIO();
- if (NULL != spec) spec->fd = fd;
+ if (NULL != spec) {
+ spec->fd = fd;
+ }
}
return spec;
} /* RCFileIO::GetSpecialFile */
@@ -90,56 +116,104 @@ RCIO *RCFileIO::GetSpecialFile(RCFileIO::SpecialFile special)
** are not valid for this type of I/O class (normal and special file).
*/
PRStatus RCFileIO::Connect(const RCNetAddr&, const RCInterval&)
-{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
+{
+ PR_SetError(PR_INVALID_METHOD_ERROR, 0);
+ return PR_FAILURE;
+}
PRStatus RCFileIO::GetLocalName(RCNetAddr*) const
-{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
+{
+ PR_SetError(PR_INVALID_METHOD_ERROR, 0);
+ return PR_FAILURE;
+}
PRStatus RCFileIO::GetPeerName(RCNetAddr*) const
-{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
+{
+ PR_SetError(PR_INVALID_METHOD_ERROR, 0);
+ return PR_FAILURE;
+}
PRStatus RCFileIO::GetSocketOption(PRSocketOptionData*) const
-{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
+{
+ PR_SetError(PR_INVALID_METHOD_ERROR, 0);
+ return PR_FAILURE;
+}
PRStatus RCFileIO::Listen(PRIntn)
-{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
+{
+ PR_SetError(PR_INVALID_METHOD_ERROR, 0);
+ return PR_FAILURE;
+}
PRInt16 RCFileIO::Poll(PRInt16, PRInt16*)
-{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return 0; }
+{
+ PR_SetError(PR_INVALID_METHOD_ERROR, 0);
+ return 0;
+}
PRInt32 RCFileIO::Recv(void*, PRSize, PRIntn, const RCInterval&)
-{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
+{
+ PR_SetError(PR_INVALID_METHOD_ERROR, 0);
+ return -1;
+}
PRInt32 RCFileIO::Recvfrom(void*, PRSize, PRIntn, RCNetAddr*, const RCInterval&)
-{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
+{
+ PR_SetError(PR_INVALID_METHOD_ERROR, 0);
+ return -1;
+}
PRInt32 RCFileIO::Send(
const void*, PRSize, PRIntn, const RCInterval&)
-{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
+{
+ PR_SetError(PR_INVALID_METHOD_ERROR, 0);
+ return -1;
+}
PRInt32 RCFileIO::Sendto(
const void*, PRSize, PRIntn, const RCNetAddr&, const RCInterval&)
-{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
+{
+ PR_SetError(PR_INVALID_METHOD_ERROR, 0);
+ return -1;
+}
RCIO* RCFileIO::Accept(RCNetAddr*, const RCInterval&)
-{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return NULL; }
+{
+ PR_SetError(PR_INVALID_METHOD_ERROR, 0);
+ return NULL;
+}
PRStatus RCFileIO::Bind(const RCNetAddr&)
-{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
+{
+ PR_SetError(PR_INVALID_METHOD_ERROR, 0);
+ return PR_FAILURE;
+}
PRInt32 RCFileIO::AcceptRead(
RCIO**, RCNetAddr**, void*, PRSize, const RCInterval&)
-{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
+{
+ PR_SetError(PR_INVALID_METHOD_ERROR, 0);
+ return -1;
+}
PRStatus RCFileIO::SetSocketOption(const PRSocketOptionData*)
-{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
+{
+ PR_SetError(PR_INVALID_METHOD_ERROR, 0);
+ return PR_FAILURE;
+}
PRStatus RCFileIO::Shutdown(RCIO::ShutdownHow)
-{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
+{
+ PR_SetError(PR_INVALID_METHOD_ERROR, 0);
+ return PR_FAILURE;
+}
PRInt32 RCFileIO::TransmitFile(
RCIO*, const void*, PRSize, RCIO::FileDisposition, const RCInterval&)
-{ PR_SetError(PR_INVALID_METHOD_ERROR, 0); return -1; }
+{
+ PR_SetError(PR_INVALID_METHOD_ERROR, 0);
+ return -1;
+}
/*
** Class implementation for file information object (ref: prio.h)
@@ -148,11 +222,17 @@ PRInt32 RCFileIO::TransmitFile(
RCFileInfo::~RCFileInfo() { }
RCFileInfo::RCFileInfo(const RCFileInfo& her): RCBase()
- { info = her.info; } /* RCFileInfo::RCFileInfo */
+{
+ info = her.info; /* RCFileInfo::RCFileInfo */
+}
-RCTime RCFileInfo::CreationTime() const { return RCTime(info.creationTime); }
+RCTime RCFileInfo::CreationTime() const {
+ return RCTime(info.creationTime);
+}
-RCTime RCFileInfo::ModifyTime() const { return RCTime(info.modifyTime); }
+RCTime RCFileInfo::ModifyTime() const {
+ return RCTime(info.modifyTime);
+}
RCFileInfo::FileType RCFileInfo::Type() const
{
diff --git a/nsprpub/pr/src/cplus/rcfileio.h b/nsprpub/pr/src/cplus/rcfileio.h
index d9c82582d..9e28b36ac 100644
--- a/nsprpub/pr/src/cplus/rcfileio.h
+++ b/nsprpub/pr/src/cplus/rcfileio.h
@@ -41,8 +41,8 @@ public:
virtual PRInt64 Seek(PRInt64 offset, RCIO::Whence how);
virtual PRInt32 Write(const void *buf, PRSize amount);
virtual PRInt32 Writev(
- const PRIOVec *iov, PRSize size,
- const RCInterval& timeout);
+ const PRIOVec *iov, PRSize size,
+ const RCInterval& timeout);
private:
@@ -52,8 +52,8 @@ private:
RCIO* Accept(RCNetAddr* addr, const RCInterval& timeout);
PRInt32 AcceptRead(
- RCIO **newfd, RCNetAddr **address, void *buffer,
- PRSize amount, const RCInterval& timeout);
+ RCIO **newfd, RCNetAddr **address, void *buffer,
+ PRSize amount, const RCInterval& timeout);
PRStatus Bind(const RCNetAddr& addr);
PRStatus Connect(const RCNetAddr& addr, const RCInterval& timeout);
PRStatus GetLocalName(RCNetAddr *addr) const;
@@ -62,24 +62,24 @@ private:
PRStatus Listen(PRIntn backlog);
PRInt16 Poll(PRInt16 in_flags, PRInt16 *out_flags);
PRInt32 Recv(
- void *buf, PRSize amount, PRIntn flags,
- const RCInterval& timeout);
+ void *buf, PRSize amount, PRIntn flags,
+ const RCInterval& timeout);
PRInt32 Recvfrom(
- void *buf, PRSize amount, PRIntn flags,
- RCNetAddr* addr, const RCInterval& timeout);
+ void *buf, PRSize amount, PRIntn flags,
+ RCNetAddr* addr, const RCInterval& timeout);
PRInt32 Send(
- const void *buf, PRSize amount, PRIntn flags,
- const RCInterval& timeout);
+ const void *buf, PRSize amount, PRIntn flags,
+ const RCInterval& timeout);
PRInt32 Sendto(
- const void *buf, PRSize amount, PRIntn flags,
- const RCNetAddr& addr,
- const RCInterval& timeout);
+ const void *buf, PRSize amount, PRIntn flags,
+ const RCNetAddr& addr,
+ const RCInterval& timeout);
PRStatus SetSocketOption(const PRSocketOptionData *data);
PRStatus Shutdown(RCIO::ShutdownHow how);
PRInt32 TransmitFile(
- RCIO *source, const void *headers,
- PRSize hlen, RCIO::FileDisposition flags,
- const RCInterval& timeout);
+ RCIO *source, const void *headers,
+ PRSize hlen, RCIO::FileDisposition flags,
+ const RCInterval& timeout);
public:
/*
@@ -116,14 +116,16 @@ public:
RCTime ModifyTime() const;
RCFileInfo::FileType Type() const;
-friend PRStatus RCFileIO::FileInfo(RCFileInfo*) const;
-friend PRStatus RCFileIO::FileInfo(const char *name, RCFileInfo*);
+ friend PRStatus RCFileIO::FileInfo(RCFileInfo*) const;
+ friend PRStatus RCFileIO::FileInfo(const char *name, RCFileInfo*);
private:
PRFileInfo64 info;
}; /* RCFileInfo */
inline RCFileInfo::RCFileInfo(): RCBase() { }
-inline PRInt64 RCFileInfo::Size() const { return info.size; }
+inline PRInt64 RCFileInfo::Size() const {
+ return info.size;
+}
#endif /* defined(_RCFILEIO_H) */
diff --git a/nsprpub/pr/src/cplus/rcinrval.cpp b/nsprpub/pr/src/cplus/rcinrval.cpp
index cda5f8dfd..3805a5766 100644
--- a/nsprpub/pr/src/cplus/rcinrval.cpp
+++ b/nsprpub/pr/src/cplus/rcinrval.cpp
@@ -20,17 +20,17 @@ RCInterval::RCInterval(RCInterval::RCReservedInterval special): RCBase()
{
switch (special)
{
- case RCInterval::now:
- interval = PR_IntervalNow();
- break;
- case RCInterval::no_timeout:
- interval = PR_INTERVAL_NO_TIMEOUT;
- break;
- case RCInterval::no_wait:
- interval = PR_INTERVAL_NO_WAIT;
- break;
- default:
- break;
+ case RCInterval::now:
+ interval = PR_IntervalNow();
+ break;
+ case RCInterval::no_timeout:
+ interval = PR_INTERVAL_NO_TIMEOUT;
+ break;
+ case RCInterval::no_wait:
+ interval = PR_INTERVAL_NO_WAIT;
+ break;
+ default:
+ break;
}
} /* RCInterval::RCInterval */
diff --git a/nsprpub/pr/src/cplus/rcinrval.h b/nsprpub/pr/src/cplus/rcinrval.h
index bcf755fa8..333209e61 100644
--- a/nsprpub/pr/src/cplus/rcinrval.h
+++ b/nsprpub/pr/src/cplus/rcinrval.h
@@ -66,71 +66,125 @@ public:
private:
PRIntervalTime interval;
-
+
}; /* RCInterval */
inline RCInterval::RCInterval(): RCBase() { }
inline RCInterval::RCInterval(const RCInterval& his): RCBase()
- { interval = his.interval; }
+{
+ interval = his.interval;
+}
inline RCInterval::RCInterval(PRIntervalTime ticks): RCBase()
- { interval = ticks; }
+{
+ interval = ticks;
+}
-inline void RCInterval::SetToNow() { interval = PR_IntervalNow(); }
+inline void RCInterval::SetToNow() {
+ interval = PR_IntervalNow();
+}
inline void RCInterval::operator=(const RCInterval& his)
- { interval = his.interval; }
+{
+ interval = his.interval;
+}
inline void RCInterval::operator=(PRIntervalTime his)
- { interval = his; }
+{
+ interval = his;
+}
inline PRBool RCInterval::operator==(const RCInterval& his)
- { return (interval == his.interval) ? PR_TRUE : PR_FALSE; }
+{
+ return (interval == his.interval) ? PR_TRUE : PR_FALSE;
+}
inline PRBool RCInterval::operator<(const RCInterval& his)
- { return (interval < his.interval)? PR_TRUE : PR_FALSE; }
+{
+ return (interval < his.interval)? PR_TRUE : PR_FALSE;
+}
inline PRBool RCInterval::operator>(const RCInterval& his)
- { return (interval > his.interval) ? PR_TRUE : PR_FALSE; }
+{
+ return (interval > his.interval) ? PR_TRUE : PR_FALSE;
+}
inline PRBool RCInterval::operator<=(const RCInterval& his)
- { return (interval <= his.interval) ? PR_TRUE : PR_FALSE; }
+{
+ return (interval <= his.interval) ? PR_TRUE : PR_FALSE;
+}
inline PRBool RCInterval::operator>=(const RCInterval& his)
- { return (interval <= his.interval) ? PR_TRUE : PR_FALSE; }
+{
+ return (interval <= his.interval) ? PR_TRUE : PR_FALSE;
+}
inline RCInterval RCInterval::operator+(const RCInterval& his)
- { return RCInterval((PRIntervalTime)(interval + his.interval)); }
+{
+ return RCInterval((PRIntervalTime)(interval + his.interval));
+}
inline RCInterval RCInterval::operator-(const RCInterval& his)
- { return RCInterval((PRIntervalTime)(interval - his.interval)); }
+{
+ return RCInterval((PRIntervalTime)(interval - his.interval));
+}
inline RCInterval& RCInterval::operator+=(const RCInterval& his)
- { interval += his.interval; return *this; }
+{
+ interval += his.interval;
+ return *this;
+}
inline RCInterval& RCInterval::operator-=(const RCInterval& his)
- { interval -= his.interval; return *this; }
+{
+ interval -= his.interval;
+ return *this;
+}
inline RCInterval RCInterval::operator/(PRUint32 him)
- { return RCInterval((PRIntervalTime)(interval / him)); }
+{
+ return RCInterval((PRIntervalTime)(interval / him));
+}
inline RCInterval RCInterval::operator*(PRUint32 him)
- { return RCInterval((PRIntervalTime)(interval * him)); }
+{
+ return RCInterval((PRIntervalTime)(interval * him));
+}
inline RCInterval& RCInterval::operator/=(PRUint32 him)
- { interval /= him; return *this; }
+{
+ interval /= him;
+ return *this;
+}
inline RCInterval& RCInterval::operator*=(PRUint32 him)
- { interval *= him; return *this; }
+{
+ interval *= him;
+ return *this;
+}
inline PRUint32 RCInterval::ToSeconds() const
- { return PR_IntervalToSeconds(interval); }
+{
+ return PR_IntervalToSeconds(interval);
+}
inline PRUint32 RCInterval::ToMilliseconds() const
- { return PR_IntervalToMilliseconds(interval); }
+{
+ return PR_IntervalToMilliseconds(interval);
+}
inline PRUint32 RCInterval::ToMicroseconds() const
- { return PR_IntervalToMicroseconds(interval); }
-inline RCInterval::operator PRIntervalTime() const { return interval; }
+{
+ return PR_IntervalToMicroseconds(interval);
+}
+inline RCInterval::operator PRIntervalTime() const {
+ return interval;
+}
inline PRIntervalTime RCInterval::FromSeconds(PRUint32 seconds)
- { return PR_SecondsToInterval(seconds); }
+{
+ return PR_SecondsToInterval(seconds);
+}
inline PRIntervalTime RCInterval::FromMilliseconds(PRUint32 milli)
- { return PR_MillisecondsToInterval(milli); }
+{
+ return PR_MillisecondsToInterval(milli);
+}
inline PRIntervalTime RCInterval::FromMicroseconds(PRUint32 micro)
- { return PR_MicrosecondsToInterval(micro); }
+{
+ return PR_MicrosecondsToInterval(micro);
+}
#endif /* defined(_RCINTERVAL_H) */
diff --git a/nsprpub/pr/src/cplus/rcio.h b/nsprpub/pr/src/cplus/rcio.h
index a4278d2ae..1bd3ac414 100644
--- a/nsprpub/pr/src/cplus/rcio.h
+++ b/nsprpub/pr/src/cplus/rcio.h
@@ -49,14 +49,14 @@ public:
virtual RCIO* Accept(RCNetAddr* addr, const RCInterval& timeout) = 0;
virtual PRInt32 AcceptRead(
- RCIO **nd, RCNetAddr **raddr, void *buf,
- PRSize amount, const RCInterval& timeout) = 0;
+ RCIO **nd, RCNetAddr **raddr, void *buf,
+ PRSize amount, const RCInterval& timeout) = 0;
virtual PRInt64 Available() = 0;
virtual PRStatus Bind(const RCNetAddr& addr) = 0;
virtual PRStatus Close() = 0;
virtual PRStatus Connect(
- const RCNetAddr& addr,
- const RCInterval& timeout) = 0;
+ const RCNetAddr& addr,
+ const RCInterval& timeout) = 0;
virtual PRStatus FileInfo(RCFileInfo *info) const = 0;
virtual PRStatus Fsync() = 0;
virtual PRStatus GetLocalName(RCNetAddr *addr) const = 0;
@@ -67,36 +67,37 @@ public:
virtual PRInt16 Poll(PRInt16 in_flags, PRInt16 *out_flags) = 0;
virtual PRInt32 Read(void *buf, PRSize amount) = 0;
virtual PRInt32 Recv(
- void *buf, PRSize amount, PRIntn flags,
- const RCInterval& timeout) = 0;
+ void *buf, PRSize amount, PRIntn flags,
+ const RCInterval& timeout) = 0;
virtual PRInt32 Recvfrom(
- void *buf, PRSize amount, PRIntn flags,
- RCNetAddr* addr, const RCInterval& timeout) = 0;
+ void *buf, PRSize amount, PRIntn flags,
+ RCNetAddr* addr, const RCInterval& timeout) = 0;
virtual PRInt64 Seek(PRInt64 offset, Whence how) = 0;
virtual PRInt32 Send(
- const void *buf, PRSize amount, PRIntn flags,
- const RCInterval& timeout) = 0;
+ const void *buf, PRSize amount, PRIntn flags,
+ const RCInterval& timeout) = 0;
virtual PRInt32 Sendto(
- const void *buf, PRSize amount, PRIntn flags,
- const RCNetAddr& addr,
- const RCInterval& timeout) = 0;
+ const void *buf, PRSize amount, PRIntn flags,
+ const RCNetAddr& addr,
+ const RCInterval& timeout) = 0;
virtual PRStatus SetSocketOption(const PRSocketOptionData *data) = 0;
virtual PRStatus Shutdown(ShutdownHow how) = 0;
virtual PRInt32 TransmitFile(
- RCIO *source, const void *headers,
- PRSize hlen, RCIO::FileDisposition flags,
- const RCInterval& timeout) = 0;
+ RCIO *source, const void *headers,
+ PRSize hlen, RCIO::FileDisposition flags,
+ const RCInterval& timeout) = 0;
virtual PRInt32 Write(const void *buf, PRSize amount) = 0;
virtual PRInt32 Writev(
- const PRIOVec *iov, PRSize size,
- const RCInterval& timeout) = 0;
+ const PRIOVec *iov, PRSize size,
+ const RCInterval& timeout) = 0;
protected:
typedef enum {
file = PR_DESC_FILE,
tcp = PR_DESC_SOCKET_TCP,
udp = PR_DESC_SOCKET_UDP,
- layered = PR_DESC_LAYERED} RCIOType;
+ layered = PR_DESC_LAYERED
+ } RCIOType;
RCIO(RCIOType);
diff --git a/nsprpub/pr/src/cplus/rclock.cpp b/nsprpub/pr/src/cplus/rclock.cpp
index 60d13b887..8c106de08 100644
--- a/nsprpub/pr/src/cplus/rclock.cpp
+++ b/nsprpub/pr/src/cplus/rclock.cpp
@@ -18,7 +18,9 @@ RCLock::RCLock()
RCLock::~RCLock()
{
- if (NULL != lock) PR_DestroyLock(lock);
+ if (NULL != lock) {
+ PR_DestroyLock(lock);
+ }
lock = NULL;
} /* RCLock::~RCLock */
diff --git a/nsprpub/pr/src/cplus/rclock.h b/nsprpub/pr/src/cplus/rclock.h
index 511b6fa4b..c86c2f17b 100644
--- a/nsprpub/pr/src/cplus/rclock.h
+++ b/nsprpub/pr/src/cplus/rclock.h
@@ -53,13 +53,21 @@ private:
RCEnter(const RCEnter&);
void operator=(const RCEnter&);
- void *operator new(PRSize) { return NULL; }
+ void *operator new(PRSize) {
+ return NULL;
+ }
void operator delete(void*) { }
}; /* RCEnter */
-inline RCEnter::RCEnter(RCLock* ml) { lock = ml; lock->Acquire(); }
-inline RCEnter::~RCEnter() { lock->Release(); lock = NULL; }
+inline RCEnter::RCEnter(RCLock* ml) {
+ lock = ml;
+ lock->Acquire();
+}
+inline RCEnter::~RCEnter() {
+ lock->Release();
+ lock = NULL;
+}
#endif /* defined(_RCLOCK_H) */
diff --git a/nsprpub/pr/src/cplus/rcnetdb.cpp b/nsprpub/pr/src/cplus/rcnetdb.cpp
index 042943bc4..19eb66540 100644
--- a/nsprpub/pr/src/cplus/rcnetdb.cpp
+++ b/nsprpub/pr/src/cplus/rcnetdb.cpp
@@ -15,7 +15,9 @@
#include <string.h>
RCNetAddr::RCNetAddr(const RCNetAddr& his): RCBase()
- { address = his.address; }
+{
+ address = his.address;
+}
RCNetAddr::RCNetAddr(const RCNetAddr& his, PRUint16 port): RCBase()
{
@@ -42,12 +44,18 @@ RCNetAddr::RCNetAddr(RCNetAddr::HostValue host, PRUint16 port): RCBase()
RCNetAddr::~RCNetAddr() { }
-void RCNetAddr::operator=(const RCNetAddr& his) { address = his.address; }
+void RCNetAddr::operator=(const RCNetAddr& his) {
+ address = his.address;
+}
PRStatus RCNetAddr::FromString(const char* string)
- { return PR_StringToNetAddr(string, &address); }
+{
+ return PR_StringToNetAddr(string, &address);
+}
-void RCNetAddr::operator=(const PRNetAddr* addr) { address = *addr; }
+void RCNetAddr::operator=(const PRNetAddr* addr) {
+ address = *addr;
+}
PRBool RCNetAddr::operator==(const RCNetAddr& his) const
{
@@ -76,14 +84,14 @@ PRBool RCNetAddr::EqualHost(const RCNetAddr& his) const
rv = (address.inet.ip == his.address.inet.ip); break;
case PR_AF_INET6:
rv = (0 == memcmp(
- &address.ipv6.ip, &his.address.ipv6.ip,
- sizeof(address.ipv6.ip)));
+ &address.ipv6.ip, &his.address.ipv6.ip,
+ sizeof(address.ipv6.ip)));
break;
#if defined(XP_UNIX)
case PR_AF_LOCAL:
rv = (0 == strncmp(
- address.local.path, his.address.local.path,
- sizeof(address.local.path)));
+ address.local.path, his.address.local.path,
+ sizeof(address.local.path)));
break;
#endif
default: break;
@@ -92,7 +100,9 @@ PRBool RCNetAddr::EqualHost(const RCNetAddr& his) const
} /* RCNetAddr::operator== */
PRStatus RCNetAddr::ToString(char *string, PRSize size) const
- { return PR_NetAddrToString(&address, string, size); }
+{
+ return PR_NetAddrToString(&address, string, size);
+}
/*
** RCHostLookup
@@ -100,7 +110,9 @@ PRStatus RCNetAddr::ToString(char *string, PRSize size) const
RCHostLookup::~RCHostLookup()
{
- if (NULL != address) delete [] address;
+ if (NULL != address) {
+ delete [] address;
+ }
} /* RCHostLookup::~RCHostLookup */
RCHostLookup::RCHostLookup(): RCBase()
@@ -118,14 +130,18 @@ PRStatus RCHostLookup::ByName(const char* name)
RCNetAddr* vector = NULL;
RCNetAddr* old_vector = NULL;
void* buffer = PR_Malloc(PR_NETDB_BUF_SIZE);
- if (NULL == buffer) return PR_FAILURE;
+ if (NULL == buffer) {
+ return PR_FAILURE;
+ }
rv = PR_GetHostByName(name, (char*)buffer, PR_NETDB_BUF_SIZE, &hostentry);
if (PR_SUCCESS == rv)
{
for (max = 0, index = 0;; ++max)
{
index = PR_EnumerateHostEnt(index, &hostentry, 0, &addr);
- if (0 == index) break;
+ if (0 == index) {
+ break;
+ }
}
if (max > 0)
{
@@ -133,7 +149,9 @@ PRStatus RCHostLookup::ByName(const char* name)
while (--max > 0)
{
index = PR_EnumerateHostEnt(index, &hostentry, 0, &addr);
- if (0 == index) break;
+ if (0 == index) {
+ break;
+ }
vector[index] = &addr;
}
{
@@ -142,10 +160,14 @@ PRStatus RCHostLookup::ByName(const char* name)
address = vector;
max_index = max;
}
- if (NULL != old_vector) delete [] old_vector;
+ if (NULL != old_vector) {
+ delete [] old_vector;
+ }
}
}
- if (NULL != buffer) PR_DELETE(buffer);
+ if (NULL != buffer) {
+ PR_DELETE(buffer);
+ }
return PR_SUCCESS;
} /* RCHostLookup::ByName */
@@ -158,14 +180,18 @@ PRStatus RCHostLookup::ByAddress(const RCNetAddr& host_addr)
RCNetAddr* vector = NULL;
RCNetAddr* old_vector = NULL;
char *buffer = (char*)PR_Malloc(PR_NETDB_BUF_SIZE);
- if (NULL == buffer) return PR_FAILURE;
+ if (NULL == buffer) {
+ return PR_FAILURE;
+ }
rv = PR_GetHostByAddr(host_addr, buffer, PR_NETDB_BUF_SIZE, &hostentry);
if (PR_SUCCESS == rv)
{
for (max = 0, index = 0;; ++max)
{
index = PR_EnumerateHostEnt(index, &hostentry, 0, &addr);
- if (0 == index) break;
+ if (0 == index) {
+ break;
+ }
}
if (max > 0)
{
@@ -173,7 +199,9 @@ PRStatus RCHostLookup::ByAddress(const RCNetAddr& host_addr)
while (--max > 0)
{
index = PR_EnumerateHostEnt(index, &hostentry, 0, &addr);
- if (0 == index) break;
+ if (0 == index) {
+ break;
+ }
vector[index] = &addr;
}
{
@@ -182,18 +210,23 @@ PRStatus RCHostLookup::ByAddress(const RCNetAddr& host_addr)
address = vector;
max_index = max;
}
- if (NULL != old_vector) delete [] old_vector;
+ if (NULL != old_vector) {
+ delete [] old_vector;
+ }
}
}
- if (NULL != buffer) PR_DELETE(buffer);
+ if (NULL != buffer) {
+ PR_DELETE(buffer);
+ }
return PR_SUCCESS;
} /* RCHostLookup::ByAddress */
const RCNetAddr* RCHostLookup::operator[](PRUintn which)
{
RCNetAddr* addr = NULL;
- if (which < max_index)
+ if (which < max_index) {
addr = &address[which];
+ }
return addr;
} /* RCHostLookup::operator[] */
diff --git a/nsprpub/pr/src/cplus/rcnetdb.h b/nsprpub/pr/src/cplus/rcnetdb.h
index 8096113bd..14e96ecd8 100644
--- a/nsprpub/pr/src/cplus/rcnetdb.h
+++ b/nsprpub/pr/src/cplus/rcnetdb.h
@@ -28,16 +28,16 @@ public:
RCNetAddr(const RCNetAddr&); /* copy constructor */
RCNetAddr(HostValue, PRUint16 port);/* init'd w/ 'special' assignments */
RCNetAddr(const RCNetAddr&, PRUint16 port);
- /* copy w/ port reassigment */
+ /* copy w/ port reassigment */
virtual ~RCNetAddr();
void operator=(const RCNetAddr&);
virtual PRBool operator==(const RCNetAddr&) const;
- /* compare of all relavent fields */
+ /* compare of all relavent fields */
virtual PRBool EqualHost(const RCNetAddr&) const;
- /* compare of just host field */
+ /* compare of just host field */
public:
@@ -45,9 +45,9 @@ public:
void operator=(const PRNetAddr*); /* construction from more primitive data */
operator const PRNetAddr*() const; /* extraction of underlying representation */
virtual PRStatus FromString(const char* string);
- /* initialization from an ASCII string */
+ /* initialization from an ASCII string */
virtual PRStatus ToString(char *string, PRSize size) const;
- /* convert internal fromat to a string */
+ /* convert internal fromat to a string */
private:
@@ -87,7 +87,9 @@ private:
};
inline RCNetAddr::RCNetAddr(): RCBase() { }
-inline RCNetAddr::operator const PRNetAddr*() const { return &address; }
+inline RCNetAddr::operator const PRNetAddr*() const {
+ return &address;
+}
#endif /* defined(_RCNETDB_H) */
diff --git a/nsprpub/pr/src/cplus/rcnetio.cpp b/nsprpub/pr/src/cplus/rcnetio.cpp
index f511d81dc..e351345e4 100644
--- a/nsprpub/pr/src/cplus/rcnetio.cpp
+++ b/nsprpub/pr/src/cplus/rcnetio.cpp
@@ -12,13 +12,20 @@
#include <private/pprio.h>
RCNetStreamIO::~RCNetStreamIO()
- { PRStatus rv = (fd->methods->close)(fd); fd = NULL; }
+{
+ PRStatus rv = (fd->methods->close)(fd);
+ fd = NULL;
+}
RCNetStreamIO::RCNetStreamIO(): RCIO(RCIO::tcp)
- { fd = PR_NewTCPSocket(); }
+{
+ fd = PR_NewTCPSocket();
+}
RCNetStreamIO::RCNetStreamIO(PRIntn protocol): RCIO(RCIO::tcp)
- { fd = PR_Socket(PR_AF_INET, PR_SOCK_STREAM, protocol); }
+{
+ fd = PR_Socket(PR_AF_INET, PR_SOCK_STREAM, protocol);
+}
RCIO* RCNetStreamIO::Accept(RCNetAddr* addr, const RCInterval& timeout)
{
@@ -33,8 +40,9 @@ RCIO* RCNetStreamIO::Accept(RCNetAddr* addr, const RCInterval& timeout)
*addr = &peer;
rcio->fd = newfd;
}
- else
+ else {
(void)(newfd->methods->close)(newfd);
+ }
}
return rcio;
} /* RCNetStreamIO::Accept */
@@ -42,35 +50,48 @@ RCIO* RCNetStreamIO::Accept(RCNetAddr* addr, const RCInterval& timeout)
PRInt32 RCNetStreamIO::AcceptRead(
RCIO **nd, RCNetAddr **raddr, void *buf,
PRSize amount, const RCInterval& timeout)
-{
+{
PRNetAddr *from;
PRFileDesc *accepted;
PRInt32 rv = (fd->methods->acceptread)(
- fd, &accepted, &from, buf, amount, timeout);
+ fd, &accepted, &from, buf, amount, timeout);
if (rv >= 0)
{
RCNetStreamIO *ns = new RCNetStreamIO();
- if (NULL != *nd) ns->fd = accepted;
- else {PR_Close(accepted); rv = -1; }
+ if (NULL != *nd) {
+ ns->fd = accepted;
+ }
+ else {
+ PR_Close(accepted);
+ rv = -1;
+ }
*nd = ns;
}
return rv;
} /* RCNetStreamIO::AcceptRead */
PRInt64 RCNetStreamIO::Available()
- { return (fd->methods->available64)(fd); }
+{
+ return (fd->methods->available64)(fd);
+}
PRStatus RCNetStreamIO::Bind(const RCNetAddr& addr)
- { return (fd->methods->bind)(fd, addr); }
+{
+ return (fd->methods->bind)(fd, addr);
+}
PRStatus RCNetStreamIO::Connect(const RCNetAddr& addr, const RCInterval& timeout)
- { return (fd->methods->connect)(fd, addr, timeout); }
+{
+ return (fd->methods->connect)(fd, addr, timeout);
+}
PRStatus RCNetStreamIO::GetLocalName(RCNetAddr *addr) const
{
PRNetAddr local;
PRStatus rv = (fd->methods->getsockname)(fd, &local);
- if (PR_SUCCESS == rv) *addr = &local;
+ if (PR_SUCCESS == rv) {
+ *addr = &local;
+ }
return rv;
} /* RCNetStreamIO::GetLocalName */
@@ -78,25 +99,37 @@ PRStatus RCNetStreamIO::GetPeerName(RCNetAddr *addr) const
{
PRNetAddr peer;
PRStatus rv = (fd->methods->getpeername)(fd, &peer);
- if (PR_SUCCESS == rv) *addr = &peer;
+ if (PR_SUCCESS == rv) {
+ *addr = &peer;
+ }
return rv;
} /* RCNetStreamIO::GetPeerName */
PRStatus RCNetStreamIO::GetSocketOption(PRSocketOptionData *data) const
- { return (fd->methods->getsocketoption)(fd, data); }
+{
+ return (fd->methods->getsocketoption)(fd, data);
+}
PRStatus RCNetStreamIO::Listen(PRIntn backlog)
- { return (fd->methods->listen)(fd, backlog); }
+{
+ return (fd->methods->listen)(fd, backlog);
+}
PRInt16 RCNetStreamIO::Poll(PRInt16 in_flags, PRInt16 *out_flags)
- { return (fd->methods->poll)(fd, in_flags, out_flags); }
+{
+ return (fd->methods->poll)(fd, in_flags, out_flags);
+}
PRInt32 RCNetStreamIO::Read(void *buf, PRSize amount)
- { return (fd->methods->read)(fd, buf, amount); }
+{
+ return (fd->methods->read)(fd, buf, amount);
+}
PRInt32 RCNetStreamIO::Recv(
void *buf, PRSize amount, PRIntn flags, const RCInterval& timeout)
- { return (fd->methods->recv)(fd, buf, amount, flags, timeout); }
+{
+ return (fd->methods->recv)(fd, buf, amount, flags, timeout);
+}
PRInt32 RCNetStreamIO::Recvfrom(
void *buf, PRSize amount, PRIntn flags,
@@ -104,25 +137,35 @@ PRInt32 RCNetStreamIO::Recvfrom(
{
PRNetAddr peer;
PRInt32 rv = (fd->methods->recvfrom)(
- fd, buf, amount, flags, &peer, timeout);
- if (-1 != rv) *addr = &peer;
+ fd, buf, amount, flags, &peer, timeout);
+ if (-1 != rv) {
+ *addr = &peer;
+ }
return rv;
} /* RCNetStreamIO::Recvfrom */
PRInt32 RCNetStreamIO::Send(
const void *buf, PRSize amount, PRIntn flags, const RCInterval& timeout)
- { return (fd->methods->send)(fd, buf, amount, flags, timeout); }
+{
+ return (fd->methods->send)(fd, buf, amount, flags, timeout);
+}
PRInt32 RCNetStreamIO::Sendto(
const void *buf, PRSize amount, PRIntn flags,
const RCNetAddr& addr, const RCInterval& timeout)
- { return (fd->methods->sendto)(fd, buf, amount, flags, addr, timeout); }
+{
+ return (fd->methods->sendto)(fd, buf, amount, flags, addr, timeout);
+}
PRStatus RCNetStreamIO::SetSocketOption(const PRSocketOptionData *data)
- { return (fd->methods->setsocketoption)(fd, data); }
+{
+ return (fd->methods->setsocketoption)(fd, data);
+}
PRStatus RCNetStreamIO::Shutdown(RCIO::ShutdownHow how)
- { return (fd->methods->shutdown)(fd, (PRIntn)how); }
+{
+ return (fd->methods->shutdown)(fd, (PRIntn)how);
+}
PRInt32 RCNetStreamIO::TransmitFile(
RCIO *source, const void *headers, PRSize hlen,
@@ -130,33 +173,52 @@ PRInt32 RCNetStreamIO::TransmitFile(
{
RCNetStreamIO *src = (RCNetStreamIO*)source;
return (fd->methods->transmitfile)(
- fd, src->fd, headers, hlen, (PRTransmitFileFlags)flags, timeout); }
+ fd, src->fd, headers, hlen, (PRTransmitFileFlags)flags, timeout);
+}
PRInt32 RCNetStreamIO::Write(const void *buf, PRSize amount)
- { return (fd->methods->write)(fd, buf, amount); }
+{
+ return (fd->methods->write)(fd, buf, amount);
+}
PRInt32 RCNetStreamIO::Writev(
const PRIOVec *iov, PRSize size, const RCInterval& timeout)
- { return (fd->methods->writev)(fd, iov, size, timeout); }
-
+{
+ return (fd->methods->writev)(fd, iov, size, timeout);
+}
+
/*
** Invalid functions
*/
PRStatus RCNetStreamIO::Close()
- { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
+{
+ PR_SetError(PR_INVALID_METHOD_ERROR, 0);
+ return PR_FAILURE;
+}
PRStatus RCNetStreamIO::FileInfo(RCFileInfo*) const
- { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
+{
+ PR_SetError(PR_INVALID_METHOD_ERROR, 0);
+ return PR_FAILURE;
+}
PRStatus RCNetStreamIO::Fsync()
- { return (fd->methods->fsync)(fd); }
+{
+ return (fd->methods->fsync)(fd);
+}
PRStatus RCNetStreamIO::Open(const char*, PRIntn, PRIntn)
- { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
+{
+ PR_SetError(PR_INVALID_METHOD_ERROR, 0);
+ return PR_FAILURE;
+}
PRInt64 RCNetStreamIO::Seek(PRInt64, RCIO::Whence)
- { PR_SetError(PR_INVALID_METHOD_ERROR, 0); return PR_FAILURE; }
+{
+ PR_SetError(PR_INVALID_METHOD_ERROR, 0);
+ return PR_FAILURE;
+}
/* RCNetStreamIO.cpp */
diff --git a/nsprpub/pr/src/cplus/rcnetio.h b/nsprpub/pr/src/cplus/rcnetio.h
index 44b8bf071..7f6b669d5 100644
--- a/nsprpub/pr/src/cplus/rcnetio.h
+++ b/nsprpub/pr/src/cplus/rcnetio.h
@@ -37,12 +37,12 @@ public:
virtual RCIO* Accept(RCNetAddr* addr, const RCInterval& timeout);
virtual PRInt32 AcceptRead(
- RCIO **nd, RCNetAddr **raddr, void *buf,
- PRSize amount, const RCInterval& timeout);
+ RCIO **nd, RCNetAddr **raddr, void *buf,
+ PRSize amount, const RCInterval& timeout);
virtual PRInt64 Available();
virtual PRStatus Bind(const RCNetAddr& addr);
virtual PRStatus Connect(
- const RCNetAddr& addr, const RCInterval& timeout);
+ const RCNetAddr& addr, const RCInterval& timeout);
virtual PRStatus GetLocalName(RCNetAddr *addr) const;
virtual PRStatus GetPeerName(RCNetAddr *addr) const;
virtual PRStatus GetSocketOption(PRSocketOptionData *data) const;
@@ -50,28 +50,28 @@ public:
virtual PRInt16 Poll(PRInt16 in_flags, PRInt16 *out_flags);
virtual PRInt32 Read(void *buf, PRSize amount);
virtual PRInt32 Recv(
- void *buf, PRSize amount, PRIntn flags,
- const RCInterval& timeout);
+ void *buf, PRSize amount, PRIntn flags,
+ const RCInterval& timeout);
virtual PRInt32 Recvfrom(
- void *buf, PRSize amount, PRIntn flags,
- RCNetAddr* addr, const RCInterval& timeout);
+ void *buf, PRSize amount, PRIntn flags,
+ RCNetAddr* addr, const RCInterval& timeout);
virtual PRInt32 Send(
- const void *buf, PRSize amount, PRIntn flags,
- const RCInterval& timeout);
+ const void *buf, PRSize amount, PRIntn flags,
+ const RCInterval& timeout);
virtual PRInt32 Sendto(
- const void *buf, PRSize amount, PRIntn flags,
- const RCNetAddr& addr,
- const RCInterval& timeout);
+ const void *buf, PRSize amount, PRIntn flags,
+ const RCNetAddr& addr,
+ const RCInterval& timeout);
virtual PRStatus SetSocketOption(const PRSocketOptionData *data);
virtual PRStatus Shutdown(ShutdownHow how);
virtual PRInt32 TransmitFile(
- RCIO *source, const void *headers,
- PRSize hlen, RCIO::FileDisposition flags,
- const RCInterval& timeout);
+ RCIO *source, const void *headers,
+ PRSize hlen, RCIO::FileDisposition flags,
+ const RCInterval& timeout);
virtual PRInt32 Write(const void *buf, PRSize amount);
virtual PRInt32 Writev(
- const PRIOVec *iov, PRSize size,
- const RCInterval& timeout);
+ const PRIOVec *iov, PRSize size,
+ const RCInterval& timeout);
private:
/* functions unavailable to this clients of this class */
diff --git a/nsprpub/pr/src/cplus/rcthread.cpp b/nsprpub/pr/src/cplus/rcthread.cpp
index 3db00d369..471e580a2 100755
--- a/nsprpub/pr/src/cplus/rcthread.cpp
+++ b/nsprpub/pr/src/cplus/rcthread.cpp
@@ -18,11 +18,13 @@ static RCPrimordialThread *primordial = NULL;
void nas_Root(void *arg)
{
RCThread *him = (RCThread*)arg;
- while (RCThread::ex_unstarted == him->execution)
- (void)PR_Sleep(PR_INTERVAL_NO_TIMEOUT); /* wait for Start() */
+ while (RCThread::ex_unstarted == him->execution) {
+ (void)PR_Sleep(PR_INTERVAL_NO_TIMEOUT); /* wait for Start() */
+ }
him->RootFunction(); /* he gets a self reference */
- if (PR_UNJOINABLE_THREAD == PR_GetThreadState(him->identity))
+ if (PR_UNJOINABLE_THREAD == PR_GetThreadState(him->identity)) {
delete him;
+ }
} /* nas_Root */
RCThread::~RCThread() { }
@@ -40,9 +42,9 @@ RCThread::RCThread(
{
execution = ex_unstarted;
identity = PR_CreateThread(
- PR_USER_THREAD, nas_Root, this,
- PR_GetThreadPriority(PR_GetCurrentThread()),
- (PRThreadScope)scope, (PRThreadState)join, stackSize);
+ PR_USER_THREAD, nas_Root, this,
+ PR_GetThreadPriority(PR_GetCurrentThread()),
+ (PRThreadScope)scope, (PRThreadState)join, stackSize);
} /* RCThread::RCThread */
void RCThread::operator=(const RCThread&)
@@ -77,8 +79,12 @@ PRStatus RCThread::Join()
rv = PR_FAILURE;
PR_SetError(PR_INVALID_STATE_ERROR, 0);
}
- else rv = PR_JoinThread(identity);
- if (PR_SUCCESS == rv) delete this;
+ else {
+ rv = PR_JoinThread(identity);
+ }
+ if (PR_SUCCESS == rv) {
+ delete this;
+ }
return rv;
} /* RCThread::Join */
@@ -90,27 +96,41 @@ PRStatus RCThread::Interrupt()
rv = PR_FAILURE;
PR_SetError(PR_INVALID_STATE_ERROR, 0);
}
- else rv = PR_Interrupt(identity);
+ else {
+ rv = PR_Interrupt(identity);
+ }
return rv;
} /* RCThread::Interrupt */
-void RCThread::ClearInterrupt() { PR_ClearInterrupt(); }
+void RCThread::ClearInterrupt() {
+ PR_ClearInterrupt();
+}
void RCThread::SetPriority(RCThread::Priority new_priority)
- { PR_SetThreadPriority(identity, (PRThreadPriority)new_priority); }
+{
+ PR_SetThreadPriority(identity, (PRThreadPriority)new_priority);
+}
PRThread *RCThread::Self()
- { return PR_GetCurrentThread(); }
+{
+ return PR_GetCurrentThread();
+}
RCThread::Scope RCThread::GetScope() const
- { return (RCThread::Scope)PR_GetThreadScope(identity); }
+{
+ return (RCThread::Scope)PR_GetThreadScope(identity);
+}
RCThread::State RCThread::GetState() const
- { return (RCThread::State)PR_GetThreadState(identity); }
+{
+ return (RCThread::State)PR_GetThreadState(identity);
+}
RCThread::Priority RCThread::GetPriority() const
- { return (RCThread::Priority)PR_GetThreadPriority(identity); }
-
+{
+ return (RCThread::Priority)PR_GetThreadPriority(identity);
+}
+
static void _rc_PDDestructor(RCThreadPrivateData* privateData)
{
PR_ASSERT(NULL != privateData);
@@ -120,10 +140,14 @@ static void _rc_PDDestructor(RCThreadPrivateData* privateData)
static PRThreadPrivateDTOR _tpd_dtor = (PRThreadPrivateDTOR)_rc_PDDestructor;
PRStatus RCThread::NewPrivateIndex(PRUintn* index)
- { return PR_NewThreadPrivateIndex(index, _tpd_dtor); }
+{
+ return PR_NewThreadPrivateIndex(index, _tpd_dtor);
+}
PRStatus RCThread::SetPrivateData(PRUintn index)
- { return PR_SetThreadPrivate(index, NULL); }
+{
+ return PR_SetThreadPrivate(index, NULL);
+}
PRStatus RCThread::SetPrivateData(PRUintn index, RCThreadPrivateData* data)
{
@@ -131,10 +155,15 @@ PRStatus RCThread::SetPrivateData(PRUintn index, RCThreadPrivateData* data)
}
RCThreadPrivateData* RCThread::GetPrivateData(PRUintn index)
- { return (RCThreadPrivateData*)PR_GetThreadPrivate(index); }
+{
+ return (RCThreadPrivateData*)PR_GetThreadPrivate(index);
+}
PRStatus RCThread::Sleep(const RCInterval& ticks)
- { PRIntervalTime tmo = ticks; return PR_Sleep(tmo); }
+{
+ PRIntervalTime tmo = ticks;
+ return PR_Sleep(tmo);
+}
RCPrimordialThread *RCThread::WrapPrimordialThread()
{
@@ -155,7 +184,9 @@ RCPrimordialThread *RCThread::WrapPrimordialThread()
me->execution = RCThread::ex_started;
me->identity = PR_GetCurrentThread();
}
- else delete me; /* somebody beat us to it */
+ else {
+ delete me; /* somebody beat us to it */
+ }
}
return primordial;
} /* RCThread::WrapPrimordialThread */
@@ -166,10 +197,12 @@ RCPrimordialThread::~RCPrimordialThread() { }
void RCPrimordialThread::RootFunction()
{
- PR_NOT_REACHED("Primordial thread calling root function");
+ PR_NOT_REACHED("Primordial thread calling root function");
} /* RCPrimordialThread::RootFunction */
-
-PRStatus RCPrimordialThread::Cleanup() { return PR_Cleanup(); }
+
+PRStatus RCPrimordialThread::Cleanup() {
+ return PR_Cleanup();
+}
PRStatus RCPrimordialThread::SetVirtualProcessors(PRIntn count)
{
diff --git a/nsprpub/pr/src/cplus/rcthread.h b/nsprpub/pr/src/cplus/rcthread.h
index 8683c0a55..b7716d4b9 100644
--- a/nsprpub/pr/src/cplus/rcthread.h
+++ b/nsprpub/pr/src/cplus/rcthread.h
@@ -31,7 +31,7 @@ class PR_IMPLEMENT(RCThread): public RCBase
{
public:
- typedef enum
+ typedef enum
{
local = PR_LOCAL_THREAD, global = PR_GLOBAL_THREAD
} Scope;
@@ -68,12 +68,12 @@ public:
* the target thread returns from it's root function.
*/
virtual PRStatus Join();
-
+
/*
* The priority of a newly created thread is the same as the creator.
* The priority may be changed either by the new thread itself, by
* the creator or any other arbitrary thread.
- */
+ */
virtual void SetPriority(Priority newPriority);
@@ -82,14 +82,14 @@ public:
* is doing and return with a well known error code.
*/
virtual PRStatus Interrupt();
-
+
/*
* And in case a thread was interrupted and didn't get a chance
* to have the notification delivered, a way to cancel the pending
* status.
*/
static void ClearInterrupt();
-
+
/*
* Methods to discover the attributes of an existing thread.
*/
@@ -150,15 +150,15 @@ private:
/* There is no public default constructor or copy constructor */
RCThread();
RCThread(const RCThread&);
-
+
/* And there is no assignment operator */
void operator=(const RCThread&);
public:
- static RCPrimordialThread *WrapPrimordialThread();
+ static RCPrimordialThread *WrapPrimordialThread();
+
+};
- };
-
/*
** class RCPrimordialThread
*/
@@ -180,7 +180,7 @@ public:
*/
static PRStatus SetVirtualProcessors(PRIntn count=10);
-friend class RCThread;
+ friend class RCThread;
private:
/*
** None other than the runtime can create of destruct
@@ -192,4 +192,4 @@ private:
void RootFunction();
}; /* RCPrimordialThread */
- #endif /* defined(_RCTHREAD_H) */
+#endif /* defined(_RCTHREAD_H) */
diff --git a/nsprpub/pr/src/cplus/rctime.cpp b/nsprpub/pr/src/cplus/rctime.cpp
index d65510402..2c9823e15 100644
--- a/nsprpub/pr/src/cplus/rctime.cpp
+++ b/nsprpub/pr/src/cplus/rctime.cpp
@@ -11,24 +11,46 @@
RCTime::~RCTime() { }
-RCTime::RCTime(PRTime time): RCBase() { gmt = time; }
-RCTime::RCTime(const RCTime& his): RCBase() { gmt = his.gmt; }
-RCTime::RCTime(RCTime::Current): RCBase() { gmt = PR_Now(); }
+RCTime::RCTime(PRTime time): RCBase() {
+ gmt = time;
+}
+RCTime::RCTime(const RCTime& his): RCBase() {
+ gmt = his.gmt;
+}
+RCTime::RCTime(RCTime::Current): RCBase() {
+ gmt = PR_Now();
+}
RCTime::RCTime(const PRExplodedTime& time): RCBase()
-{ gmt = PR_ImplodeTime(&time); }
+{
+ gmt = PR_ImplodeTime(&time);
+}
void RCTime::operator=(const PRExplodedTime& time)
-{ gmt = PR_ImplodeTime(&time); }
+{
+ gmt = PR_ImplodeTime(&time);
+}
RCTime RCTime::operator+(const RCTime& his)
-{ RCTime sum(gmt + his.gmt); return sum; }
+{
+ RCTime sum(gmt + his.gmt);
+ return sum;
+}
RCTime RCTime::operator-(const RCTime& his)
-{ RCTime difference(gmt - his.gmt); return difference; }
+{
+ RCTime difference(gmt - his.gmt);
+ return difference;
+}
RCTime RCTime::operator/(PRUint64 his)
-{ RCTime quotient(gmt / gmt); return quotient; }
+{
+ RCTime quotient(gmt / gmt);
+ return quotient;
+}
RCTime RCTime::operator*(PRUint64 his)
-{ RCTime product(gmt * his); return product; }
+{
+ RCTime product(gmt * his);
+ return product;
+}
diff --git a/nsprpub/pr/src/cplus/rctime.h b/nsprpub/pr/src/cplus/rctime.h
index 4cf7b9042..3752a3d53 100644
--- a/nsprpub/pr/src/cplus/rctime.h
+++ b/nsprpub/pr/src/cplus/rctime.h
@@ -39,7 +39,7 @@ public:
virtual ~RCTime();
/* assignment operators */
- void operator=(const RCTime&);
+ void operator=(const RCTime&);
void operator=(const PRExplodedTime&);
/* comparitive operators */
@@ -75,31 +75,61 @@ public:
inline RCTime::RCTime(): RCBase() { }
-inline void RCTime::Now() { gmt = PR_Now(); }
-inline RCTime::operator PRTime() const { return gmt; }
+inline void RCTime::Now() {
+ gmt = PR_Now();
+}
+inline RCTime::operator PRTime() const {
+ return gmt;
+}
-inline void RCTime::operator=(PRTime his) { gmt = his; }
-inline void RCTime::operator=(const RCTime& his) { gmt = his.gmt; }
+inline void RCTime::operator=(PRTime his) {
+ gmt = his;
+}
+inline void RCTime::operator=(const RCTime& his) {
+ gmt = his.gmt;
+}
inline PRBool RCTime::operator<(const RCTime& his)
- { return (gmt < his.gmt) ? PR_TRUE : PR_FALSE; }
+{
+ return (gmt < his.gmt) ? PR_TRUE : PR_FALSE;
+}
inline PRBool RCTime::operator>(const RCTime& his)
- { return (gmt > his.gmt) ? PR_TRUE : PR_FALSE; }
+{
+ return (gmt > his.gmt) ? PR_TRUE : PR_FALSE;
+}
inline PRBool RCTime::operator<=(const RCTime& his)
- { return (gmt <= his.gmt) ? PR_TRUE : PR_FALSE; }
+{
+ return (gmt <= his.gmt) ? PR_TRUE : PR_FALSE;
+}
inline PRBool RCTime::operator>=(const RCTime& his)
- { return (gmt >= his.gmt) ? PR_TRUE : PR_FALSE; }
+{
+ return (gmt >= his.gmt) ? PR_TRUE : PR_FALSE;
+}
inline PRBool RCTime::operator==(const RCTime& his)
- { return (gmt == his.gmt) ? PR_TRUE : PR_FALSE; }
+{
+ return (gmt == his.gmt) ? PR_TRUE : PR_FALSE;
+}
inline RCTime& RCTime::operator+=(const RCTime& his)
- { gmt += his.gmt; return *this; }
+{
+ gmt += his.gmt;
+ return *this;
+}
inline RCTime& RCTime::operator-=(const RCTime& his)
- { gmt -= his.gmt; return *this; }
+{
+ gmt -= his.gmt;
+ return *this;
+}
inline RCTime& RCTime::operator/=(PRUint64 his)
- { gmt /= his; return *this; }
+{
+ gmt /= his;
+ return *this;
+}
inline RCTime& RCTime::operator*=(PRUint64 his)
- { gmt *= his; return *this; }
+{
+ gmt *= his;
+ return *this;
+}
#endif /* defined(_RCTIME_H) */
diff --git a/nsprpub/pr/src/cplus/tests/Makefile.in b/nsprpub/pr/src/cplus/tests/Makefile.in
index c16423872..df4827656 100644
--- a/nsprpub/pr/src/cplus/tests/Makefile.in
+++ b/nsprpub/pr/src/cplus/tests/Makefile.in
@@ -49,24 +49,6 @@ LDOPTS = -L$(dist_libdir)
LIBPR = -lnspr$(MOD_MAJOR_VERSION)
LIBPL = -lplc$(MOD_MAJOR_VERSION)
-ifeq ($(OS_ARCH), IRIX)
- LDOPTS += -rpath $(PWD)/$(dist_libdir) -rdata_shared
- # For 6.x machines, include this flag
- ifeq ($(basename $(OS_RELEASE)),6)
- ifeq ($(USE_N32),1)
- LDOPTS += -n32
- else
- LDOPTS += -32
- endif
-
- ifeq ($(USE_PTHREADS), 1)
- ifeq ($(OS_RELEASE), 6.2)
- LDOPTS += -Wl,-woff,85
- endif
- endif
- endif
-endif
-
# Solaris
ifeq ($(OS_ARCH), SunOS)
ifdef NS_USE_GCC
@@ -103,10 +85,6 @@ ifneq ($(OS_ARCH), WINNT)
PWD = $(shell pwd)
endif
-ifeq ($(OS_ARCH), OSF1)
-LDOPTS += -rpath $(PWD)/$(dist_libdir)
-endif
-
ifeq ($(OS_ARCH), HP-UX)
LDOPTS += -Wl,+s,+b,$(PWD)/$(dist_libdir)
endif
diff --git a/nsprpub/pr/src/cplus/tests/ranfile.cpp b/nsprpub/pr/src/cplus/tests/ranfile.cpp
index c3ac0d3a4..0fb4c5d23 100644
--- a/nsprpub/pr/src/cplus/tests/ranfile.cpp
+++ b/nsprpub/pr/src/cplus/tests/ranfile.cpp
@@ -12,12 +12,12 @@
** Description: Test to hammer on various components of NSPR
** Modification History:
** 20-May-97 AGarcia- Converted the test to accomodate the debug_mode flag.
-** The debug mode will print all of the printfs associated with this test.
-** The regress mode will be the default mode. Since the regress tool limits
+** The debug mode will print all of the printfs associated with this test.
+** The regress mode will be the default mode. Since the regress tool limits
** the output to a one line status:PASS or FAIL,all of the printf statements
-** have been handled with an if (debug_mode) statement.
+** have been handled with an if (debug_mode) statement.
** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
-** recognize the return code from tha main program.
+** recognize the return code from tha main program.
***********************************************************************/
@@ -46,19 +46,21 @@ class HammerData
{
public:
typedef enum {
- sg_go, sg_stop, sg_done} Action;
+ sg_go, sg_stop, sg_done
+ } Action;
typedef enum {
- sg_okay, sg_open, sg_close, sg_delete, sg_write, sg_seek} Problem;
+ sg_okay, sg_open, sg_close, sg_delete, sg_write, sg_seek
+ } Problem;
- virtual ~HammerData();
- HammerData(RCLock* lock, RCCondition *cond, PRUint32 clip);
+ virtual ~HammerData();
+ HammerData(RCLock* lock, RCCondition *cond, PRUint32 clip);
virtual PRUint32 Random();
Action action;
Problem problem;
PRUint32 writes;
RCInterval timein;
-friend class Hammer;
+ friend class Hammer;
private:
RCLock *ml;
RCCondition *cv;
@@ -117,7 +119,7 @@ Hammer::~Hammer() { }
Hammer::Hammer(
RCThread::Scope scope, RCLock* lock, RCCondition *cond, PRUint32 clip):
- HammerData(lock, cond, clip), RCThread(scope, RCThread::joinable, 0) { }
+ HammerData(lock, cond, clip), RCThread(scope, RCThread::joinable, 0) { }
HammerData::~HammerData() { }
@@ -171,7 +173,9 @@ void Hammer::RootFunction()
(void)sprintf(filename, "%ssg%04p.dat", baseName, this);
- if (debug_mode) PR_fprintf(output, "Starting work on %s\n", filename);
+ if (debug_mode) {
+ PR_fprintf(output, "Starting work on %s\n", filename);
+ }
while (PR_TRUE)
{
@@ -182,52 +186,78 @@ void Hammer::RootFunction()
while (minor-- > 0)
{
problem = sg_okay;
- if (action != sg_go) goto finished;
+ if (action != sg_go) {
+ goto finished;
+ }
problem = sg_open;
rv = file.Open(filename, PR_RDWR|PR_CREATE_FILE, 0666);
- if (PR_FAILURE == rv) goto finished;
+ if (PR_FAILURE == rv) {
+ goto finished;
+ }
for (index = 0; index < pages; index++)
{
problem = sg_okay;
- if (action != sg_go) goto close;
+ if (action != sg_go) {
+ goto close;
+ }
problem = sg_seek;
bytes = file.Seek(pageSize * index, RCFileIO::set);
- if (bytes != pageSize * index) goto close;
+ if (bytes != pageSize * index) {
+ goto close;
+ }
problem = sg_write;
bytes = file.Write(&zero, sizeof(zero));
- if (bytes <= 0) goto close;
+ if (bytes <= 0) {
+ goto close;
+ }
writes += 1;
}
problem = sg_close;
rv = file.Close();
- if (rv != PR_SUCCESS) goto purge;
+ if (rv != PR_SUCCESS) {
+ goto purge;
+ }
problem = sg_okay;
- if (action != sg_go) goto purge;
+ if (action != sg_go) {
+ goto purge;
+ }
problem = sg_open;
rv = file.Open(filename, PR_RDWR, 0666);
- if (PR_FAILURE == rv) goto finished;
+ if (PR_FAILURE == rv) {
+ goto finished;
+ }
for (index = 0; index < pages; index++)
{
problem = sg_okay;
- if (action != sg_go) goto close;
+ if (action != sg_go) {
+ goto close;
+ }
problem = sg_seek;
bytes = file.Seek(pageSize * index, RCFileIO::set);
- if (bytes != pageSize * index) goto close;
+ if (bytes != pageSize * index) {
+ goto close;
+ }
problem = sg_write;
bytes = file.Write(&zero, sizeof(zero));
- if (bytes <= 0) goto close;
+ if (bytes <= 0) {
+ goto close;
+ }
writes += 1;
random = (random + 511) % pages;
}
problem = sg_close;
rv = file.Close();
- if (rv != PR_SUCCESS) goto purge;
+ if (rv != PR_SUCCESS) {
+ goto purge;
+ }
problem = sg_delete;
rv = file.Delete(filename);
- if (rv != PR_SUCCESS) goto finished;
- }
+ if (rv != PR_SUCCESS) {
+ goto finished;
+ }
+ }
}
close:
@@ -239,7 +269,9 @@ finished:
action = HammerData::sg_done;
cv->Notify();
- if (debug_mode) PR_fprintf(output, "Ending work on %s\n", filename);
+ if (debug_mode) {
+ PR_fprintf(output, "Ending work on %s\n", filename);
+ }
return;
} /* Hammer::RootFunction */
@@ -278,7 +310,7 @@ static Hammer* hammer[100];
PRIntn main (PRIntn argc, char *argv[])
{
RCLock ml;
- PLOptStatus os;
+ PLOptStatus os;
RCCondition cv(&ml);
PRUint32 writesMax = 0, durationTot = 0;
RCThread::Scope thread_scope = RCThread::local;
@@ -288,57 +320,65 @@ PRIntn main (PRIntn argc, char *argv[])
const char *where[] = {"okay", "open", "close", "delete", "write", "seek"};
- PLOptState *opt = PL_CreateOptState(argc, argv, "Gdl:t:i:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ PLOptState *opt = PL_CreateOptState(argc, argv, "Gdl:t:i:");
+ while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
- if (PL_OPT_BAD == os) continue;
+ if (PL_OPT_BAD == os) {
+ continue;
+ }
switch (opt->option)
{
- case 0:
- baseName = opt->value;
- break;
- case 'G': /* global threads */
- thread_scope = RCThread::global;
- break;
- case 'd': /* debug mode */
- debug_mode = 1;
- break;
- case 'l': /* limiting number */
- limit = atoi(opt->value);
- break;
- case 't': /* number of threads */
- threads = atoi(opt->value);
- break;
- case 'i': /* iteration counter */
- max_virtual_procs = atoi(opt->value);
- break;
- default:
- break;
+ case 0:
+ baseName = opt->value;
+ break;
+ case 'G': /* global threads */
+ thread_scope = RCThread::global;
+ break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ case 'l': /* limiting number */
+ limit = atoi(opt->value);
+ break;
+ case 't': /* number of threads */
+ threads = atoi(opt->value);
+ break;
+ case 'i': /* iteration counter */
+ max_virtual_procs = atoi(opt->value);
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
output = PR_GetSpecialFD(PR_StandardOutput);
- /* main test */
-
+ /* main test */
+
cv.SetTimeout(interleave);
-
- if (max_virtual_procs == 0) max_virtual_procs = 2;
- if (limit == 0) limit = 57;
- if (threads == 0) threads = 10;
+
+ if (max_virtual_procs == 0) {
+ max_virtual_procs = 2;
+ }
+ if (limit == 0) {
+ limit = 57;
+ }
+ if (threads == 0) {
+ threads = 10;
+ }
if (debug_mode) PR_fprintf(output,
- "%s: Using %d virtual processors, %d threads, limit = %d and %s threads\n",
- programName, max_virtual_procs, threads, limit,
- (thread_scope == RCThread::local) ? "LOCAL" : "GLOBAL");
+ "%s: Using %d virtual processors, %d threads, limit = %d and %s threads\n",
+ programName, max_virtual_procs, threads, limit,
+ (thread_scope == RCThread::local) ? "LOCAL" : "GLOBAL");
for (virtual_procs = 0; virtual_procs < max_virtual_procs; ++virtual_procs)
{
if (debug_mode)
- PR_fprintf(output,
- "%s: Setting number of virtual processors to %d\n",
- programName, virtual_procs + 1);
- RCPrimordialThread::SetVirtualProcessors(virtual_procs + 1);
+ PR_fprintf(output,
+ "%s: Setting number of virtual processors to %d\n",
+ programName, virtual_procs + 1);
+ RCPrimordialThread::SetVirtualProcessors(virtual_procs + 1);
for (active = 0; active < threads; active++)
{
hammer[active] = new Hammer(thread_scope, &ml, &cv, limit);
@@ -354,8 +394,9 @@ PRIntn main (PRIntn argc, char *argv[])
RCEnter scope(&ml);
for (poll = 0; poll < threads; poll++)
{
- if (hammer[poll]->action == HammerData::sg_go) /* don't overwrite done */
- hammer[poll]->action = HammerData::sg_stop; /* ask him to stop */
+ if (hammer[poll]->action == HammerData::sg_go) { /* don't overwrite done */
+ hammer[poll]->action = HammerData::sg_stop; /* ask him to stop */
+ }
}
}
@@ -364,24 +405,32 @@ PRIntn main (PRIntn argc, char *argv[])
for (poll = 0; poll < threads; poll++)
{
ml.Acquire();
- while (hammer[poll]->action < HammerData::sg_done) cv.Wait();
+ while (hammer[poll]->action < HammerData::sg_done) {
+ cv.Wait();
+ }
ml.Release();
if (hammer[poll]->problem == HammerData::sg_okay)
{
duration = RCInterval(RCInterval::now) - hammer[poll]->timein;
writes = hammer[poll]->writes * 1000 / duration;
- if (writes < writesMin) writesMin = writes;
- if (writes > writesMax) writesMax = writes;
+ if (writes < writesMin) {
+ writesMin = writes;
+ }
+ if (writes > writesMax) {
+ writesMax = writes;
+ }
writesTot += hammer[poll]->writes;
durationTot += duration;
}
else
{
if (debug_mode) PR_fprintf(output,
- "%s: test failed %s after %ld seconds\n",
- programName, where[hammer[poll]->problem], duration);
- else failed_already=1;
+ "%s: test failed %s after %ld seconds\n",
+ programName, where[hammer[poll]->problem], duration);
+ else {
+ failed_already=1;
+ }
}
active -= 1; /* this is another one down */
(void)hammer[poll]->Join();
@@ -389,12 +438,12 @@ PRIntn main (PRIntn argc, char *argv[])
}
}
if (debug_mode) PR_fprintf(output,
- "%s: [%ld [%ld] %ld] writes/sec average\n",
- programName, writesMin,
- writesTot * 1000 / durationTot, writesMax);
+ "%s: [%ld [%ld] %ld] writes/sec average\n",
+ programName, writesMin,
+ writesTot * 1000 / durationTot, writesMax);
}
- failed_already |= (PR_FAILURE == RCPrimordialThread::Cleanup());
- PR_fprintf(output, "%s\n", (failed_already) ? "FAIL\n" : "PASS\n");
- return failed_already;
+ failed_already |= (PR_FAILURE == RCPrimordialThread::Cleanup());
+ PR_fprintf(output, "%s\n", (failed_already) ? "FAIL\n" : "PASS\n");
+ return failed_already;
} /* main */
diff --git a/nsprpub/pr/src/cplus/tests/switch.cpp b/nsprpub/pr/src/cplus/tests/switch.cpp
index 4cb14c48f..00de8e306 100644
--- a/nsprpub/pr/src/cplus/tests/switch.cpp
+++ b/nsprpub/pr/src/cplus/tests/switch.cpp
@@ -70,8 +70,12 @@ void Shared::RootFunction()
while (PR_SUCCESS == status)
{
RCEnter entry(ml);
- while (twiddle && (PR_SUCCESS == status)) status = Wait();
- if (verbosity) PR_fprintf(debug_out, "+");
+ while (twiddle && (PR_SUCCESS == status)) {
+ status = Wait();
+ }
+ if (verbosity) {
+ PR_fprintf(debug_out, "+");
+ }
twiddle = PR_TRUE;
next->twiddle = PR_FALSE;
next->Notify();
@@ -83,11 +87,11 @@ static void Help(void)
debug_out = PR_STDOUT;
PR_fprintf(
- debug_out, "Usage: >./switch [-d] [-c n] [-t n] [-T n] [-G]\n");
+ debug_out, "Usage: >./switch [-d] [-c n] [-t n] [-T n] [-G]\n");
PR_fprintf(
- debug_out, "-c n\tloops at thread level (default: %d)\n", DEFAULT_LOOPS);
+ debug_out, "-c n\tloops at thread level (default: %d)\n", DEFAULT_LOOPS);
PR_fprintf(
- debug_out, "-t n\tnumber of threads (default: %d)\n", DEFAULT_THREADS);
+ debug_out, "-t n\tnumber of threads (default: %d)\n", DEFAULT_THREADS);
PR_fprintf(debug_out, "-d\tturn on debugging output (default: FALSE)\n");
PR_fprintf(debug_out, "-v\tturn on verbose output (default: FALSE)\n");
PR_fprintf(debug_out, "-G n\tglobal threads only (default: FALSE)\n");
@@ -96,59 +100,63 @@ static void Help(void)
PRIntn main(PRIntn argc, char **argv)
{
- PLOptStatus os;
+ PLOptStatus os;
PRStatus status;
PRBool help = PR_FALSE;
PRUintn concurrency = 1;
RCThread::Scope thread_scope = RCThread::local;
PRUintn thread_count, inner_count, loop_count, average;
PRUintn thread_limit = DEFAULT_THREADS, loop_limit = DEFAULT_LOOPS;
- PLOptState *opt = PL_CreateOptState(argc, argv, "hdvc:t:C:G");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ PLOptState *opt = PL_CreateOptState(argc, argv, "hdvc:t:C:G");
+ while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
- if (PL_OPT_BAD == os) continue;
+ if (PL_OPT_BAD == os) {
+ continue;
+ }
switch (opt->option)
{
- case 'v': /* verbose mode */
- verbosity = PR_TRUE;
- case 'd': /* debug mode */
- debug_mode = PR_TRUE;
- break;
- case 'c': /* loop counter */
- loop_limit = atoi(opt->value);
- break;
- case 't': /* thread limit */
- thread_limit = atoi(opt->value);
- break;
- case 'C': /* Concurrency limit */
- concurrency = atoi(opt->value);
- break;
- case 'G': /* global threads only */
- thread_scope = RCThread::global;
- break;
- case 'h': /* help message */
- Help();
- help = PR_TRUE;
- break;
- default:
- break;
+ case 'v': /* verbose mode */
+ verbosity = PR_TRUE;
+ case 'd': /* debug mode */
+ debug_mode = PR_TRUE;
+ break;
+ case 'c': /* loop counter */
+ loop_limit = atoi(opt->value);
+ break;
+ case 't': /* thread limit */
+ thread_limit = atoi(opt->value);
+ break;
+ case 'C': /* Concurrency limit */
+ concurrency = atoi(opt->value);
+ break;
+ case 'G': /* global threads only */
+ thread_scope = RCThread::global;
+ break;
+ case 'h': /* help message */
+ Help();
+ help = PR_TRUE;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
-
- if (help) return -1;
-
- if (PR_TRUE == debug_mode)
- {
- debug_out = PR_STDOUT;
- PR_fprintf(debug_out, "Test parameters\n");
- PR_fprintf(debug_out, "\tThreads involved: %d\n", thread_limit);
- PR_fprintf(debug_out, "\tIteration limit: %d\n", loop_limit);
- PR_fprintf(debug_out, "\tConcurrency: %d\n", concurrency);
- PR_fprintf(
- debug_out, "\tThread type: %s\n",
- (PR_GLOBAL_THREAD == thread_scope) ? "GLOBAL" : "LOCAL");
- }
+ PL_DestroyOptState(opt);
+
+ if (help) {
+ return -1;
+ }
+
+ if (PR_TRUE == debug_mode)
+ {
+ debug_out = PR_STDOUT;
+ PR_fprintf(debug_out, "Test parameters\n");
+ PR_fprintf(debug_out, "\tThreads involved: %d\n", thread_limit);
+ PR_fprintf(debug_out, "\tIteration limit: %d\n", loop_limit);
+ PR_fprintf(debug_out, "\tConcurrency: %d\n", concurrency);
+ PR_fprintf(
+ debug_out, "\tThread type: %s\n",
+ (PR_GLOBAL_THREAD == thread_scope) ? "GLOBAL" : "LOCAL");
+ }
/*
** The interesting part starts here
@@ -165,62 +173,68 @@ PRIntn main(PRIntn argc, char **argv)
shared = new Shared(thread_scope, link, &lock);
shared->Start(); /* make it run */
link = (Home*)shared;
- }
+ }
/* Pass the message around the horn a few times */
for (loop_count = 1; loop_count <= loop_limit; ++loop_count)
{
- timein.SetToNow();
- for (inner_count = 0; inner_count < INNER_LOOPS; ++inner_count)
- {
- RCEnter entry(&lock);
- home.twiddle = PR_TRUE;
- shared->twiddle = PR_FALSE;
- shared->Notify();
- while (home.twiddle)
+ timein.SetToNow();
+ for (inner_count = 0; inner_count < INNER_LOOPS; ++inner_count)
+ {
+ RCEnter entry(&lock);
+ home.twiddle = PR_TRUE;
+ shared->twiddle = PR_FALSE;
+ shared->Notify();
+ while (home.twiddle)
{
- failed = (PR_FAILURE == home.Wait()) ? PR_TRUE : PR_FALSE;
+ failed = (PR_FAILURE == home.Wait()) ? PR_TRUE : PR_FALSE;
}
- }
- timeout += (RCInterval(RCInterval::now) - timein);
- }
+ }
+ timeout += (RCInterval(RCInterval::now) - timein);
+ }
/* Figure out how well we did */
- if (debug_mode)
- {
- average = timeout.ToMicroseconds()
- / (INNER_LOOPS * loop_limit * thread_count);
- PR_fprintf(
- debug_out, "Average switch times %d usecs for %d threads\n",
+ if (debug_mode)
+ {
+ average = timeout.ToMicroseconds()
+ / (INNER_LOOPS * loop_limit * thread_count);
+ PR_fprintf(
+ debug_out, "Average switch times %d usecs for %d threads\n",
average, thread_limit);
- }
+ }
/* Start reclamation process */
link = shared;
for (thread_count = 1; thread_count <= thread_limit; ++thread_count)
{
- if (&home == link) break;
+ if (&home == link) {
+ break;
+ }
status = ((Shared*)link)->Interrupt();
- if (PR_SUCCESS != status)
+ if (PR_SUCCESS != status)
{
failed = PR_TRUE;
- if (debug_mode)
- PL_FPrintError(debug_out, "Failed to interrupt");
+ if (debug_mode) {
+ PL_FPrintError(debug_out, "Failed to interrupt");
+ }
}
- link = link->next;
+ link = link->next;
}
for (thread_count = 1; thread_count <= thread_limit; ++thread_count)
{
link = shared->next;
status = shared->Join();
- if (PR_SUCCESS != status)
- {
+ if (PR_SUCCESS != status)
+ {
failed = PR_TRUE;
- if (debug_mode)
- PL_FPrintError(debug_out, "Failed to join");
+ if (debug_mode) {
+ PL_FPrintError(debug_out, "Failed to join");
+ }
+ }
+ if (&home == link) {
+ break;
}
- if (&home == link) break;
shared = (Shared*)link;
}
diff --git a/nsprpub/pr/src/cplus/tests/thread.cpp b/nsprpub/pr/src/cplus/tests/thread.cpp
index 442c534d0..ff01402d8 100644
--- a/nsprpub/pr/src/cplus/tests/thread.cpp
+++ b/nsprpub/pr/src/cplus/tests/thread.cpp
@@ -28,7 +28,9 @@ private:
TestThread::~TestThread() { }
TestThread::TestThread(RCThread::State state, PRIntn count):
- RCThread(RCThread::global, state, 0) { mydata = count; }
+ RCThread(RCThread::global, state, 0) {
+ mydata = count;
+}
void TestThread::RootFunction()
{
@@ -46,7 +48,7 @@ public:
PRIntn data;
};
-Foo1::Foo1()
+Foo1::Foo1()
{
data = 0xafaf;
thread = new TestThread(RCThread::joinable, 0xafaf);
diff --git a/nsprpub/pr/src/cplus/tests/tpd.cpp b/nsprpub/pr/src/cplus/tests/tpd.cpp
index 42290ab11..2a18c9cb1 100644
--- a/nsprpub/pr/src/cplus/tests/tpd.cpp
+++ b/nsprpub/pr/src/cplus/tests/tpd.cpp
@@ -68,8 +68,9 @@ static void PrintProgress(PRIntn line)
static void MyAssert(const char *expr, const char *file, PRIntn line)
{
- if (debug > 0)
+ if (debug > 0) {
(void)PR_fprintf(fout, "'%s' in file: %s: %d\n", expr, file, line);
+ }
} /* MyAssert */
#define MY_ASSERT(_expr) \
@@ -86,14 +87,16 @@ int main(PRIntn argc, char *argv[])
RCThread *primordial = RCThread::WrapPrimordialThread();
while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
- if (PL_OPT_BAD == os) continue;
+ if (PL_OPT_BAD == os) {
+ continue;
+ }
switch (opt->option)
{
- case 'd': /* debug mode */
- debug = PR_TRUE;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug = PR_TRUE;
+ break;
+ default:
+ break;
}
}
PL_DestroyOptState(opt);
@@ -103,8 +106,9 @@ int main(PRIntn argc, char *argv[])
MyPrivateData extension = MyPrivateData("EXTENSION");
MyPrivateData key_string[] = {
"Key #0", "Key #1", "Key #2", "Key #3",
- "Bogus #5", "Bogus #6", "Bogus #7", "Bogus #8"};
-
+ "Bogus #5", "Bogus #6", "Bogus #7", "Bogus #8"
+ };
+
did = should = PR_FALSE;
for (keys = 0; keys < 4; ++keys)
@@ -133,7 +137,7 @@ int main(PRIntn argc, char *argv[])
}
PrintProgress(__LINE__);
- /* re-assign the private data, albeit the same content */
+ /* re-assign the private data, albeit the same content */
did = PR_FALSE; should = PR_TRUE;
for (keys = 0; keys < 4; ++keys)
{
@@ -190,13 +194,21 @@ int main(PRIntn argc, char *argv[])
MY_ASSERT(PR_SUCCESS == rv);
}
- if (debug) PR_fprintf(fout, "Creating thread\n");
+ if (debug) {
+ PR_fprintf(fout, "Creating thread\n");
+ }
thread = new MyThread();
- if (debug) PR_fprintf(fout, "Starting thread\n");
+ if (debug) {
+ PR_fprintf(fout, "Starting thread\n");
+ }
thread->Start();
- if (debug) PR_fprintf(fout, "Joining thread\n");
+ if (debug) {
+ PR_fprintf(fout, "Joining thread\n");
+ }
(void)thread->Join();
- if (debug) PR_fprintf(fout, "Joined thread\n");
+ if (debug) {
+ PR_fprintf(fout, "Joined thread\n");
+ }
failed |= (PR_FAILURE == RCPrimordialThread::Cleanup());
@@ -237,8 +249,12 @@ MyPrivateData::MyPrivateData(const MyPrivateData& him): RCThreadPrivateData(him)
void MyPrivateData::Release()
{
- if (should) did = PR_TRUE;
- else failed = PR_TRUE;
+ if (should) {
+ did = PR_TRUE;
+ }
+ else {
+ failed = PR_TRUE;
+ }
} /* MyPrivateData::operator= */
/*
@@ -253,12 +269,13 @@ void MyThread::RootFunction()
PRStatus rv;
PRUintn keys;
const RCThreadPrivateData *pd;
-
+
MyPrivateData extension = MyPrivateData("EXTENSION");
MyPrivateData key_string[] = {
"Key #0", "Key #1", "Key #2", "Key #3",
- "Bogus #5", "Bogus #6", "Bogus #7", "Bogus #8"};
-
+ "Bogus #5", "Bogus #6", "Bogus #7", "Bogus #8"
+ };
+
did = should = PR_FALSE;
for (keys = 0; keys < 8; ++keys)
{
@@ -284,7 +301,7 @@ void MyThread::RootFunction()
}
PrintProgress(__LINE__);
#endif
-
+
did = PR_FALSE; should = PR_TRUE;
for (keys = 0; keys < 4; ++keys)
{
diff --git a/nsprpub/pr/src/io/prdir.c b/nsprpub/pr/src/io/prdir.c
index 3701a6a4b..365afefd2 100644
--- a/nsprpub/pr/src/io/prdir.c
+++ b/nsprpub/pr/src/io/prdir.c
@@ -18,8 +18,8 @@ PR_IMPLEMENT(PRDir*) PR_OpenDir(const char *name)
return NULL;
}
} else {
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
- }
+ PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+ }
return dir;
}
@@ -33,51 +33,57 @@ PR_IMPLEMENT(PRDirEntry*) PR_ReadDir(PRDir *dir, PRDirFlags flags)
PR_IMPLEMENT(PRStatus) PR_CloseDir(PRDir *dir)
{
-PRInt32 rv;
+ PRInt32 rv;
if (dir) {
rv = _PR_MD_CLOSE_DIR(&dir->md);
- PR_DELETE(dir);
- if (rv < 0) {
- return PR_FAILURE;
- } else
- return PR_SUCCESS;
+ PR_DELETE(dir);
+ if (rv < 0) {
+ return PR_FAILURE;
+ } else {
+ return PR_SUCCESS;
+ }
}
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
PR_IMPLEMENT(PRStatus) PR_MkDir(const char *name, PRIntn mode)
{
-PRInt32 rv;
+ PRInt32 rv;
- rv = _PR_MD_MKDIR(name, mode);
- if (rv < 0) {
- return PR_FAILURE;
- } else
- return PR_SUCCESS;
+ rv = _PR_MD_MKDIR(name, mode);
+ if (rv < 0) {
+ return PR_FAILURE;
+ } else {
+ return PR_SUCCESS;
+ }
}
PR_IMPLEMENT(PRStatus) PR_MakeDir(const char *name, PRIntn mode)
{
-PRInt32 rv;
-
- if (!_pr_initialized) _PR_ImplicitInitialization();
- rv = _PR_MD_MAKE_DIR(name, mode);
- if (rv < 0) {
- return PR_FAILURE;
- } else
- return PR_SUCCESS;
+ PRInt32 rv;
+
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
+ rv = _PR_MD_MAKE_DIR(name, mode);
+ if (rv < 0) {
+ return PR_FAILURE;
+ } else {
+ return PR_SUCCESS;
+ }
}
PR_IMPLEMENT(PRStatus) PR_RmDir(const char *name)
{
-PRInt32 rv;
+ PRInt32 rv;
- rv = _PR_MD_RMDIR(name);
- if (rv < 0) {
- return PR_FAILURE;
- } else
- return PR_SUCCESS;
+ rv = _PR_MD_RMDIR(name);
+ if (rv < 0) {
+ return PR_FAILURE;
+ } else {
+ return PR_SUCCESS;
+ }
}
#ifdef MOZ_UNICODE
@@ -85,7 +91,7 @@ PRInt32 rv;
* UTF16 Interface
*/
PR_IMPLEMENT(PRDirUTF16*) PR_OpenDirUTF16(const PRUnichar *name)
-{
+{
PRDirUTF16 *dir;
PRStatus sts;
@@ -100,10 +106,10 @@ PR_IMPLEMENT(PRDirUTF16*) PR_OpenDirUTF16(const PRUnichar *name)
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
}
return dir;
-}
-
+}
+
PR_IMPLEMENT(PRDirEntryUTF16*) PR_ReadDirUTF16(PRDirUTF16 *dir, PRDirFlags flags)
-{
+{
/*
* _MD_READ_DIR_UTF16 return a PRUnichar* to the name; allocation in
* machine-dependent code
@@ -111,20 +117,22 @@ PR_IMPLEMENT(PRDirEntryUTF16*) PR_ReadDirUTF16(PRDirUTF16 *dir, PRDirFlags flags
PRUnichar* name = _PR_MD_READ_DIR_UTF16(&dir->md, flags);
dir->d.name = name;
return name ? &dir->d : NULL;
-}
-
+}
+
PR_IMPLEMENT(PRStatus) PR_CloseDirUTF16(PRDirUTF16 *dir)
-{
- PRInt32 rv;
+{
+ PRInt32 rv;
if (dir) {
rv = _PR_MD_CLOSE_DIR_UTF16(&dir->md);
PR_DELETE(dir);
- if (rv < 0)
- return PR_FAILURE;
- else
- return PR_SUCCESS;
- }
+ if (rv < 0) {
+ return PR_FAILURE;
+ }
+ else {
+ return PR_SUCCESS;
+ }
+ }
return PR_SUCCESS;
}
diff --git a/nsprpub/pr/src/io/prfdcach.c b/nsprpub/pr/src/io/prfdcach.c
index 17b71fe6b..ecfe3d39c 100644
--- a/nsprpub/pr/src/io/prfdcach.c
+++ b/nsprpub/pr/src/io/prfdcach.c
@@ -63,8 +63,12 @@ PRFileDesc *_PR_Getfd(void)
{
do
{
- if (NULL == _pr_fd_cache.head) goto allocate; /* nothing there */
- if (_pr_fd_cache.count < _pr_fd_cache.limit_low) goto allocate;
+ if (NULL == _pr_fd_cache.head) {
+ goto allocate; /* nothing there */
+ }
+ if (_pr_fd_cache.count < _pr_fd_cache.limit_low) {
+ goto allocate;
+ }
/* we "should" be able to extract an fd from the cache */
PR_Lock(_pr_fd_cache.ml); /* need the lock to do this safely */
@@ -104,10 +108,16 @@ allocate:
if (NULL != fd)
{
fd->secret = PR_NEW(PRFilePrivate);
- if (NULL == fd->secret) PR_DELETE(fd);
+ if (NULL == fd->secret) {
+ PR_DELETE(fd);
+ }
+ }
+ if (NULL != fd) {
+ goto finished;
+ }
+ else {
+ return NULL;
}
- if (NULL != fd) goto finished;
- else return NULL;
} /* _PR_Getfd */
@@ -157,10 +167,14 @@ PR_IMPLEMENT(PRStatus) PR_SetFDCacheSize(PRIntn low, PRIntn high)
** turn the caches off, or turn them on. It is not dependent
** on the compilation setting of DEBUG.
*/
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
+
+ if (low > high) {
+ low = high; /* sanity check the params */
+ }
- if (low > high) low = high; /* sanity check the params */
-
PR_Lock(_pr_fd_cache.ml);
_pr_fd_cache.limit_high = high;
_pr_fd_cache.limit_low = low;
@@ -179,7 +193,7 @@ void _PR_InitFdCache(void)
const char *low = PR_GetEnv("NSPR_FD_CACHE_SIZE_LOW");
const char *high = PR_GetEnv("NSPR_FD_CACHE_SIZE_HIGH");
- /*
+ /*
** _low is allowed to be zero, _high is not.
** If _high is zero, we're not doing the caching.
*/
@@ -191,19 +205,27 @@ void _PR_InitFdCache(void)
_pr_fd_cache.limit_high = 0;
#endif /* defined(DEBUG) */
- if (NULL != low) _pr_fd_cache.limit_low = atoi(low);
- if (NULL != high) _pr_fd_cache.limit_high = atoi(high);
+ if (NULL != low) {
+ _pr_fd_cache.limit_low = atoi(low);
+ }
+ if (NULL != high) {
+ _pr_fd_cache.limit_high = atoi(high);
+ }
- if (_pr_fd_cache.limit_low < 0)
+ if (_pr_fd_cache.limit_low < 0) {
_pr_fd_cache.limit_low = 0;
- if (_pr_fd_cache.limit_low > FD_SETSIZE)
+ }
+ if (_pr_fd_cache.limit_low > FD_SETSIZE) {
_pr_fd_cache.limit_low = FD_SETSIZE;
+ }
- if (_pr_fd_cache.limit_high > FD_SETSIZE)
+ if (_pr_fd_cache.limit_high > FD_SETSIZE) {
_pr_fd_cache.limit_high = FD_SETSIZE;
+ }
- if (_pr_fd_cache.limit_high < _pr_fd_cache.limit_low)
+ if (_pr_fd_cache.limit_high < _pr_fd_cache.limit_low) {
_pr_fd_cache.limit_high = _pr_fd_cache.limit_low;
+ }
_pr_fd_cache.ml = PR_NewLock();
PR_ASSERT(NULL != _pr_fd_cache.ml);
diff --git a/nsprpub/pr/src/io/prfile.c b/nsprpub/pr/src/io/prfile.c
index e32031bbb..4b07baf41 100644
--- a/nsprpub/pr/src/io/prfile.c
+++ b/nsprpub/pr/src/io/prfile.c
@@ -28,21 +28,22 @@ static PRInt32 PR_CALLBACK FileRead(PRFileDesc *fd, void *buf, PRInt32 amount)
PRThread *me = _PR_MD_CURRENT_THREAD();
if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- rv = -1;
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ rv = -1;
}
if (_PR_IO_PENDING(me)) {
PR_SetError(PR_IO_PENDING_ERROR, 0);
- rv = -1;
+ rv = -1;
+ }
+ if (rv == -1) {
+ return rv;
}
- if (rv == -1)
- return rv;
- rv = _PR_MD_READ(fd, buf, amount);
- if (rv < 0) {
- PR_ASSERT(rv == -1);
- }
+ rv = _PR_MD_READ(fd, buf, amount);
+ if (rv < 0) {
+ PR_ASSERT(rv == -1);
+ }
PR_LOG(_pr_io_lm, PR_LOG_MAX, ("read -> %d", rv));
return rv;
}
@@ -56,14 +57,15 @@ static PRInt32 PR_CALLBACK FileWrite(PRFileDesc *fd, const void *buf, PRInt32 am
if (_PR_PENDING_INTERRUPT(me)) {
me->flags &= ~_PR_INTERRUPT;
PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- rv = -1;
+ rv = -1;
}
if (_PR_IO_PENDING(me)) {
PR_SetError(PR_IO_PENDING_ERROR, 0);
- rv = -1;
+ rv = -1;
+ }
+ if (rv != 0) {
+ return rv;
}
- if (rv != 0)
- return rv;
count = 0;
#if !defined(_PR_HAVE_O_APPEND) /* Bugzilla: 4090, 276330 */
@@ -74,17 +76,17 @@ static PRInt32 PR_CALLBACK FileWrite(PRFileDesc *fd, const void *buf, PRInt32 am
} /* if (fd->secret->appendMode...) */
#endif /* _PR_HAVE_O_APPEND */
while (amount > 0) {
- temp = _PR_MD_WRITE(fd, buf, amount);
- if (temp < 0) {
- count = -1;
- break;
- }
- count += temp;
- if (fd->secret->nonblocking) {
- break;
- }
- buf = (const void*) ((const char*)buf + temp);
- amount -= temp;
+ temp = _PR_MD_WRITE(fd, buf, amount);
+ if (temp < 0) {
+ count = -1;
+ break;
+ }
+ count += temp;
+ if (fd->secret->nonblocking) {
+ break;
+ }
+ buf = (const void*) ((const char*)buf + temp);
+ amount -= temp;
}
PR_LOG(_pr_io_lm, PR_LOG_MAX, ("write -> %d", count));
return count;
@@ -112,8 +114,9 @@ static PRInt32 PR_CALLBACK FileAvailable(PRFileDesc *fd)
cur = _PR_MD_LSEEK(fd, 0, PR_SEEK_CUR);
- if (cur >= 0)
- end = _PR_MD_LSEEK(fd, 0, PR_SEEK_END);
+ if (cur >= 0) {
+ end = _PR_MD_LSEEK(fd, 0, PR_SEEK_END);
+ }
if ((cur < 0) || (end < 0)) {
return -1;
@@ -133,10 +136,13 @@ static PRInt64 PR_CALLBACK FileAvailable64(PRFileDesc *fd)
LL_I2L(minus_one, -1);
cur = _PR_MD_LSEEK64(fd, LL_ZERO, PR_SEEK_CUR);
- if (LL_GE_ZERO(cur))
- end = _PR_MD_LSEEK64(fd, LL_ZERO, PR_SEEK_END);
+ if (LL_GE_ZERO(cur)) {
+ end = _PR_MD_LSEEK64(fd, LL_ZERO, PR_SEEK_END);
+ }
- if (!LL_GE_ZERO(cur) || !LL_GE_ZERO(end)) return minus_one;
+ if (!LL_GE_ZERO(cur) || !LL_GE_ZERO(end)) {
+ return minus_one;
+ }
LL_SUB(result, end, cur);
(void)_PR_MD_LSEEK64(fd, cur, PR_SEEK_SET);
@@ -146,42 +152,47 @@ static PRInt64 PR_CALLBACK FileAvailable64(PRFileDesc *fd)
static PRInt32 PR_CALLBACK PipeAvailable(PRFileDesc *fd)
{
- PRInt32 rv;
- rv = _PR_MD_PIPEAVAILABLE(fd);
- return rv;
+ PRInt32 rv;
+ rv = _PR_MD_PIPEAVAILABLE(fd);
+ return rv;
}
static PRInt64 PR_CALLBACK PipeAvailable64(PRFileDesc *fd)
{
PRInt64 rv;
LL_I2L(rv, _PR_MD_PIPEAVAILABLE(fd));
- return rv;
+ return rv;
}
static PRStatus PR_CALLBACK PipeSync(PRFileDesc *fd)
{
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
static PRStatus PR_CALLBACK FileGetInfo(PRFileDesc *fd, PRFileInfo *info)
{
- PRInt32 rv;
+ PRInt32 rv;
rv = _PR_MD_GETOPENFILEINFO(fd, info);
if (rv < 0) {
- return PR_FAILURE;
- } else
- return PR_SUCCESS;
+ return PR_FAILURE;
+ } else {
+ return PR_SUCCESS;
+ }
}
static PRStatus PR_CALLBACK FileGetInfo64(PRFileDesc *fd, PRFileInfo64 *info)
{
/* $$$$ NOT YET IMPLEMENTED */
- PRInt32 rv;
+ PRInt32 rv;
rv = _PR_MD_GETOPENFILEINFO64(fd, info);
- if (rv < 0) return PR_FAILURE;
- else return PR_SUCCESS;
+ if (rv < 0) {
+ return PR_FAILURE;
+ }
+ else {
+ return PR_SUCCESS;
+ }
}
static PRStatus PR_CALLBACK FileSync(PRFileDesc *fd)
@@ -189,7 +200,7 @@ static PRStatus PR_CALLBACK FileSync(PRFileDesc *fd)
PRInt32 result;
result = _PR_MD_FSYNC(fd);
if (result < 0) {
- return PR_FAILURE;
+ return PR_FAILURE;
}
return PR_SUCCESS;
}
@@ -197,7 +208,7 @@ static PRStatus PR_CALLBACK FileSync(PRFileDesc *fd)
static PRStatus PR_CALLBACK FileClose(PRFileDesc *fd)
{
if (!fd || !fd->secret
- || (fd->secret->state != _PR_FILEDESC_OPEN
+ || (fd->secret->state != _PR_FILEDESC_OPEN
&& fd->secret->state != _PR_FILEDESC_CLOSED)) {
PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
return PR_FAILURE;
@@ -232,30 +243,30 @@ static PRIOMethods _pr_fileMethods = {
FileSeek64,
FileGetInfo,
FileGetInfo64,
- (PRWritevFN)_PR_InvalidInt,
- (PRConnectFN)_PR_InvalidStatus,
- (PRAcceptFN)_PR_InvalidDesc,
- (PRBindFN)_PR_InvalidStatus,
- (PRListenFN)_PR_InvalidStatus,
- (PRShutdownFN)_PR_InvalidStatus,
- (PRRecvFN)_PR_InvalidInt,
- (PRSendFN)_PR_InvalidInt,
- (PRRecvfromFN)_PR_InvalidInt,
- (PRSendtoFN)_PR_InvalidInt,
- FilePoll,
- (PRAcceptreadFN)_PR_InvalidInt,
- (PRTransmitfileFN)_PR_InvalidInt,
- (PRGetsocknameFN)_PR_InvalidStatus,
- (PRGetpeernameFN)_PR_InvalidStatus,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
- (PRGetsocketoptionFN)_PR_InvalidStatus,
+ (PRWritevFN)_PR_InvalidInt,
+ (PRConnectFN)_PR_InvalidStatus,
+ (PRAcceptFN)_PR_InvalidDesc,
+ (PRBindFN)_PR_InvalidStatus,
+ (PRListenFN)_PR_InvalidStatus,
+ (PRShutdownFN)_PR_InvalidStatus,
+ (PRRecvFN)_PR_InvalidInt,
+ (PRSendFN)_PR_InvalidInt,
+ (PRRecvfromFN)_PR_InvalidInt,
+ (PRSendtoFN)_PR_InvalidInt,
+ FilePoll,
+ (PRAcceptreadFN)_PR_InvalidInt,
+ (PRTransmitfileFN)_PR_InvalidInt,
+ (PRGetsocknameFN)_PR_InvalidStatus,
+ (PRGetpeernameFN)_PR_InvalidStatus,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRGetsocketoptionFN)_PR_InvalidStatus,
(PRSetsocketoptionFN)_PR_InvalidStatus,
- (PRSendfileFN)_PR_InvalidInt,
- (PRConnectcontinueFN)_PR_InvalidStatus,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
+ (PRSendfileFN)_PR_InvalidInt,
+ (PRConnectcontinueFN)_PR_InvalidStatus,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
(PRReservedFN)_PR_InvalidInt
};
@@ -276,30 +287,30 @@ static PRIOMethods _pr_pipeMethods = {
(PRSeek64FN)_PR_InvalidInt64,
(PRFileInfoFN)_PR_InvalidStatus,
(PRFileInfo64FN)_PR_InvalidStatus,
- (PRWritevFN)_PR_InvalidInt,
- (PRConnectFN)_PR_InvalidStatus,
- (PRAcceptFN)_PR_InvalidDesc,
- (PRBindFN)_PR_InvalidStatus,
- (PRListenFN)_PR_InvalidStatus,
- (PRShutdownFN)_PR_InvalidStatus,
- (PRRecvFN)_PR_InvalidInt,
- (PRSendFN)_PR_InvalidInt,
- (PRRecvfromFN)_PR_InvalidInt,
- (PRSendtoFN)_PR_InvalidInt,
- FilePoll,
- (PRAcceptreadFN)_PR_InvalidInt,
- (PRTransmitfileFN)_PR_InvalidInt,
- (PRGetsocknameFN)_PR_InvalidStatus,
- (PRGetpeernameFN)_PR_InvalidStatus,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
- (PRGetsocketoptionFN)_PR_InvalidStatus,
+ (PRWritevFN)_PR_InvalidInt,
+ (PRConnectFN)_PR_InvalidStatus,
+ (PRAcceptFN)_PR_InvalidDesc,
+ (PRBindFN)_PR_InvalidStatus,
+ (PRListenFN)_PR_InvalidStatus,
+ (PRShutdownFN)_PR_InvalidStatus,
+ (PRRecvFN)_PR_InvalidInt,
+ (PRSendFN)_PR_InvalidInt,
+ (PRRecvfromFN)_PR_InvalidInt,
+ (PRSendtoFN)_PR_InvalidInt,
+ FilePoll,
+ (PRAcceptreadFN)_PR_InvalidInt,
+ (PRTransmitfileFN)_PR_InvalidInt,
+ (PRGetsocknameFN)_PR_InvalidStatus,
+ (PRGetpeernameFN)_PR_InvalidStatus,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRGetsocketoptionFN)_PR_InvalidStatus,
(PRSetsocketoptionFN)_PR_InvalidStatus,
- (PRSendfileFN)_PR_InvalidInt,
- (PRConnectcontinueFN)_PR_InvalidStatus,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
+ (PRSendfileFN)_PR_InvalidInt,
+ (PRConnectcontinueFN)_PR_InvalidStatus,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
(PRReservedFN)_PR_InvalidInt
};
@@ -316,7 +327,9 @@ PR_IMPLEMENT(PRFileDesc*) PR_Open(const char *name, PRIntn flags, PRIntn mode)
PRBool appendMode = ( PR_APPEND & flags )? PR_TRUE : PR_FALSE;
#endif
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
/* Map pr open flags and mode to os specific flags */
@@ -344,7 +357,9 @@ PR_IMPLEMENT(PRFileDesc*) PR_OpenFile(
PRBool appendMode = ( PR_APPEND & flags )? PR_TRUE : PR_FALSE;
#endif
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
/* Map pr open flags and mode to os specific flags */
@@ -369,8 +384,8 @@ PR_IMPLEMENT(PRInt32) PR_GetSysfdTableMax(void)
struct rlimit rlim;
if ( getrlimit(RLIMIT_NOFILE, &rlim) < 0) {
- /* XXX need to call PR_SetError() */
- return -1;
+ /* XXX need to call PR_SetError() */
+ return -1;
}
return rlim.rlim_max;
@@ -388,9 +403,6 @@ PR_IMPLEMENT(PRInt32) PR_GetSysfdTableMax(void)
ULONG ulCurMaxFH = 0;
DosSetRelMaxFH(&ulReqCount, &ulCurMaxFH);
return ulCurMaxFH;
-#elif defined(XP_BEOS)
- PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
- return -1;
#else
write me;
#endif
@@ -402,19 +414,23 @@ PR_IMPLEMENT(PRInt32) PR_SetSysfdTableSize(int table_size)
struct rlimit rlim;
PRInt32 tableMax = PR_GetSysfdTableMax();
- if (tableMax < 0)
+ if (tableMax < 0) {
return -1;
+ }
- if (tableMax > FD_SETSIZE)
+ if (tableMax > FD_SETSIZE) {
tableMax = FD_SETSIZE;
+ }
rlim.rlim_max = tableMax;
/* Grow as much as we can; even if too big */
- if ( rlim.rlim_max < table_size )
+ if ( rlim.rlim_max < table_size ) {
rlim.rlim_cur = rlim.rlim_max;
- else
+ }
+ else {
rlim.rlim_cur = table_size;
+ }
if ( setrlimit(RLIMIT_NOFILE, &rlim) < 0) {
/* XXX need to call PR_SetError() */
@@ -425,16 +441,18 @@ PR_IMPLEMENT(PRInt32) PR_SetSysfdTableSize(int table_size)
#elif defined(XP_OS2)
PRInt32 tableMax = PR_GetSysfdTableMax();
if (table_size > tableMax) {
- APIRET rc = NO_ERROR;
- rc = DosSetMaxFH(table_size);
- if (rc == NO_ERROR)
- return table_size;
- else
- return -1;
- }
+ APIRET rc = NO_ERROR;
+ rc = DosSetMaxFH(table_size);
+ if (rc == NO_ERROR) {
+ return table_size;
+ }
+ else {
+ return -1;
+ }
+ }
return tableMax;
#elif defined(AIX) || defined(QNX) \
- || defined(WIN32) || defined(WIN16) || defined(XP_BEOS)
+ || defined(WIN32) || defined(WIN16)
PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
return -1;
#else
@@ -444,31 +462,35 @@ PR_IMPLEMENT(PRInt32) PR_SetSysfdTableSize(int table_size)
PR_IMPLEMENT(PRStatus) PR_Delete(const char *name)
{
- PRInt32 rv;
+ PRInt32 rv;
- rv = _PR_MD_DELETE(name);
- if (rv < 0) {
- return PR_FAILURE;
- } else
- return PR_SUCCESS;
+ rv = _PR_MD_DELETE(name);
+ if (rv < 0) {
+ return PR_FAILURE;
+ } else {
+ return PR_SUCCESS;
+ }
}
PR_IMPLEMENT(PRStatus) PR_GetFileInfo(const char *fn, PRFileInfo *info)
{
- PRInt32 rv;
+ PRInt32 rv;
- rv = _PR_MD_GETFILEINFO(fn, info);
- if (rv < 0) {
- return PR_FAILURE;
- } else
- return PR_SUCCESS;
+ rv = _PR_MD_GETFILEINFO(fn, info);
+ if (rv < 0) {
+ return PR_FAILURE;
+ } else {
+ return PR_SUCCESS;
+ }
}
PR_IMPLEMENT(PRStatus) PR_GetFileInfo64(const char *fn, PRFileInfo64 *info)
{
PRInt32 rv;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
rv = _PR_MD_GETFILEINFO64(fn, info);
if (rv < 0) {
return PR_FAILURE;
@@ -479,34 +501,38 @@ PR_IMPLEMENT(PRStatus) PR_GetFileInfo64(const char *fn, PRFileInfo64 *info)
PR_IMPLEMENT(PRStatus) PR_Rename(const char *from, const char *to)
{
- PRInt32 rv;
+ PRInt32 rv;
- rv = _PR_MD_RENAME(from, to);
- if (rv < 0) {
- return PR_FAILURE;
- } else
- return PR_SUCCESS;
+ rv = _PR_MD_RENAME(from, to);
+ if (rv < 0) {
+ return PR_FAILURE;
+ } else {
+ return PR_SUCCESS;
+ }
}
PR_IMPLEMENT(PRStatus) PR_Access(const char *name, PRAccessHow how)
{
-PRInt32 rv;
+ PRInt32 rv;
- rv = _PR_MD_ACCESS(name, how);
- if (rv < 0) {
- return PR_FAILURE;
- } else
- return PR_SUCCESS;
+ rv = _PR_MD_ACCESS(name, how);
+ if (rv < 0) {
+ return PR_FAILURE;
+ } else {
+ return PR_SUCCESS;
+ }
}
/*
-** Import an existing OS file to NSPR
+** Import an existing OS file to NSPR
*/
PR_IMPLEMENT(PRFileDesc*) PR_ImportFile(PROsfd osfd)
{
PRFileDesc *fd = NULL;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
fd = PR_AllocFileDesc(osfd, &_pr_fileMethods);
if( !fd ) {
@@ -519,13 +545,15 @@ PR_IMPLEMENT(PRFileDesc*) PR_ImportFile(PROsfd osfd)
}
/*
-** Import an existing OS pipe to NSPR
+** Import an existing OS pipe to NSPR
*/
PR_IMPLEMENT(PRFileDesc*) PR_ImportPipe(PROsfd osfd)
{
PRFileDesc *fd = NULL;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
fd = PR_AllocFileDesc(osfd, &_pr_pipeMethods);
if( !fd ) {
@@ -552,7 +580,7 @@ PR_IMPLEMENT(PRFileDesc*) PR_ImportPipe(PROsfd osfd)
* nspr 1.0. Therefore, it still uses the nspr 1.0 error-reporting
* mechanism -- returns a PRInt32, which is the error code when the call
* fails.
- *
+ *
* If we need this function in nspr 2.0, it should be changed to
* return PRStatus, as follows:
*
@@ -574,7 +602,7 @@ PR_IMPLEMENT(PRInt32) PR_Stat(const char *name, struct stat *buf)
PRInt32 rv;
rv = _PR_MD_STAT(name, buf);
- return rv;
+ return rv;
}
#endif /* !defined(WIN16) */
@@ -594,8 +622,9 @@ PR_IMPLEMENT(PRStatus) PR_LockFile(PRFileDesc *fd)
#endif
PR_Lock(_pr_flock_lock);
- while (fd->secret->lockCount == -1)
+ while (fd->secret->lockCount == -1) {
PR_WaitCondVar(_pr_flock_cv, PR_INTERVAL_NO_TIMEOUT);
+ }
if (fd->secret->lockCount == 0) {
fd->secret->lockCount = -1;
PR_Unlock(_pr_flock_lock);
@@ -607,7 +636,7 @@ PR_IMPLEMENT(PRStatus) PR_LockFile(PRFileDesc *fd)
fd->secret->lockCount++;
}
PR_Unlock(_pr_flock_lock);
-
+
return status;
}
@@ -628,8 +657,9 @@ PR_IMPLEMENT(PRStatus) PR_TLockFile(PRFileDesc *fd)
if (fd->secret->lockCount == 0) {
status = _PR_MD_TLOCKFILE(fd->secret->md.osfd);
PR_ASSERT(status == PR_SUCCESS || fd->secret->lockCount == 0);
- if (status == PR_SUCCESS)
+ if (status == PR_SUCCESS) {
fd->secret->lockCount = 1;
+ }
} else {
fd->secret->lockCount++;
}
@@ -645,8 +675,9 @@ PR_IMPLEMENT(PRStatus) PR_UnlockFile(PRFileDesc *fd)
PR_Lock(_pr_flock_lock);
if (fd->secret->lockCount == 1) {
rv = _PR_MD_UNLOCKFILE(fd->secret->md.osfd);
- if (rv == PR_SUCCESS)
+ if (rv == PR_SUCCESS) {
fd->secret->lockCount = 0;
+ }
} else {
fd->secret->lockCount--;
}
@@ -664,7 +695,9 @@ PR_IMPLEMENT(PRStatus) PR_CreatePipe(
HANDLE readEnd, writeEnd;
SECURITY_ATTRIBUTES pipeAttributes;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
ZeroMemory(&pipeAttributes, sizeof(pipeAttributes));
pipeAttributes.nLength = sizeof(pipeAttributes);
@@ -692,14 +725,16 @@ PR_IMPLEMENT(PRStatus) PR_CreatePipe(
(*readPipe)->secret->inheritable = _PR_TRI_TRUE;
(*writePipe)->secret->inheritable = _PR_TRI_TRUE;
return PR_SUCCESS;
-#elif defined(XP_UNIX) || defined(XP_OS2) || defined(XP_BEOS)
+#elif defined(XP_UNIX) || defined(XP_OS2)
#ifdef XP_OS2
HFILE pipefd[2];
#else
int pipefd[2];
#endif
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
#ifdef XP_OS2
if (DosCreatePipe(&pipefd[0], &pipefd[1], 4096) != 0) {
@@ -722,13 +757,9 @@ PR_IMPLEMENT(PRStatus) PR_CreatePipe(
close(pipefd[1]);
return PR_FAILURE;
}
-#ifndef XP_BEOS /* Pipes are nonblocking on BeOS */
_PR_MD_MAKE_NONBLOCK(*readPipe);
-#endif
_PR_MD_INIT_FD_INHERITABLE(*readPipe, PR_FALSE);
-#ifndef XP_BEOS /* Pipes are nonblocking on BeOS */
_PR_MD_MAKE_NONBLOCK(*writePipe);
-#endif
_PR_MD_INIT_FD_INHERITABLE(*writePipe, PR_FALSE);
return PR_SUCCESS;
#else
@@ -741,15 +772,17 @@ PR_IMPLEMENT(PRStatus) PR_CreatePipe(
/* ================ UTF16 Interfaces ================================ */
PR_IMPLEMENT(PRFileDesc*) PR_OpenFileUTF16(
const PRUnichar *name, PRIntn flags, PRIntn mode)
-{
+{
PROsfd osfd;
PRFileDesc *fd = 0;
#if !defined(_PR_HAVE_O_APPEND)
PRBool appendMode = ( PR_APPEND & flags )? PR_TRUE : PR_FALSE;
#endif
-
- if (!_pr_initialized) _PR_ImplicitInitialization();
-
+
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
+
/* Map pr open flags and mode to os specific flags */
osfd = _PR_MD_OPEN_FILE_UTF16(name, flags, mode);
if (osfd != -1) {
@@ -765,12 +798,14 @@ PR_IMPLEMENT(PRFileDesc*) PR_OpenFileUTF16(
}
return fd;
}
-
+
PR_IMPLEMENT(PRStatus) PR_GetFileInfo64UTF16(const PRUnichar *fn, PRFileInfo64 *info)
{
PRInt32 rv;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
rv = _PR_MD_GETFILEINFO64_UTF16(fn, info);
if (rv < 0) {
return PR_FAILURE;
diff --git a/nsprpub/pr/src/io/prio.c b/nsprpub/pr/src/io/prio.c
index 10ae5e098..745d7721b 100644
--- a/nsprpub/pr/src/io/prio.c
+++ b/nsprpub/pr/src/io/prio.c
@@ -40,11 +40,11 @@ void _PR_InitIO(void)
#ifdef WIN32
_pr_stdin = PR_AllocFileDesc((PROsfd)GetStdHandle(STD_INPUT_HANDLE),
- methods);
+ methods);
_pr_stdout = PR_AllocFileDesc((PROsfd)GetStdHandle(STD_OUTPUT_HANDLE),
- methods);
+ methods);
_pr_stderr = PR_AllocFileDesc((PROsfd)GetStdHandle(STD_ERROR_HANDLE),
- methods);
+ methods);
#ifdef WINNT
_pr_stdin->secret->md.sync_file_io = PR_TRUE;
_pr_stdout->secret->md.sync_file_io = PR_TRUE;
@@ -88,8 +88,10 @@ PR_IMPLEMENT(PRFileDesc*) PR_GetSpecialFD(PRSpecialFD osfd)
PRFileDesc *result = NULL;
PR_ASSERT((int) osfd >= PR_StandardInput && osfd <= PR_StandardError);
- if (!_pr_initialized) _PR_ImplicitInitialization();
-
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
+
switch (osfd)
{
case PR_StandardInput: result = _pr_stdin; break;
@@ -107,25 +109,25 @@ PR_IMPLEMENT(PRFileDesc*) PR_AllocFileDesc(
PRFileDesc *fd;
#ifdef XP_UNIX
- /*
- * Assert that the file descriptor is small enough to fit in the
- * fd_set passed to select
- */
- PR_ASSERT(osfd < FD_SETSIZE);
+ /*
+ * Assert that the file descriptor is small enough to fit in the
+ * fd_set passed to select
+ */
+ PR_ASSERT(osfd < FD_SETSIZE);
#endif
fd = _PR_Getfd();
if (fd) {
/* Initialize the members of PRFileDesc and PRFilePrivate */
fd->methods = methods;
fd->secret->state = _PR_FILEDESC_OPEN;
- fd->secret->md.osfd = osfd;
+ fd->secret->md.osfd = osfd;
#if defined(_WIN64)
fd->secret->alreadyConnected = PR_FALSE;
fd->secret->overlappedActive = PR_FALSE;
#endif
_PR_MD_INIT_FILEDESC(fd);
} else {
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+ PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
}
return fd;
@@ -144,62 +146,62 @@ PRLock *_fd_waiting_for_overlapped_done_lock = NULL;
void CheckOverlappedPendingSocketsAreDone()
{
- if (!_fd_waiting_for_overlapped_done_lock ||
- !_fd_waiting_for_overlapped_done) {
- return;
- }
-
- PR_Lock(_fd_waiting_for_overlapped_done_lock);
-
- PRFileDescList *cur = _fd_waiting_for_overlapped_done;
- PRFileDescList *previous = NULL;
- while (cur) {
- PR_ASSERT(cur->fd->secret->overlappedActive);
- PRFileDesc *fd = cur->fd;
- DWORD rvSent;
- if (GetOverlappedResult((HANDLE)fd->secret->md.osfd, &fd->secret->ol, &rvSent, FALSE) == TRUE) {
- fd->secret->overlappedActive = PR_FALSE;
- PR_LOG(_pr_io_lm, PR_LOG_MIN,
- ("CheckOverlappedPendingSocketsAreDone GetOverlappedResult succeeded\n"));
- } else {
- DWORD err = WSAGetLastError();
- PR_LOG(_pr_io_lm, PR_LOG_MIN,
- ("CheckOverlappedPendingSocketsAreDone GetOverlappedResult failed %d\n", err));
- if (err != ERROR_IO_INCOMPLETE) {
- fd->secret->overlappedActive = PR_FALSE;
- }
+ if (!_fd_waiting_for_overlapped_done_lock ||
+ !_fd_waiting_for_overlapped_done) {
+ return;
}
- if (!fd->secret->overlappedActive) {
+ PR_Lock(_fd_waiting_for_overlapped_done_lock);
+
+ PRFileDescList *cur = _fd_waiting_for_overlapped_done;
+ PRFileDescList *previous = NULL;
+ while (cur) {
+ PR_ASSERT(cur->fd->secret->overlappedActive);
+ PRFileDesc *fd = cur->fd;
+ DWORD rvSent;
+ if (GetOverlappedResult((HANDLE)fd->secret->md.osfd, &fd->secret->ol, &rvSent, FALSE) == TRUE) {
+ fd->secret->overlappedActive = PR_FALSE;
+ PR_LOG(_pr_io_lm, PR_LOG_MIN,
+ ("CheckOverlappedPendingSocketsAreDone GetOverlappedResult succeeded\n"));
+ } else {
+ DWORD err = WSAGetLastError();
+ PR_LOG(_pr_io_lm, PR_LOG_MIN,
+ ("CheckOverlappedPendingSocketsAreDone GetOverlappedResult failed %d\n", err));
+ if (err != ERROR_IO_INCOMPLETE) {
+ fd->secret->overlappedActive = PR_FALSE;
+ }
+ }
+
+ if (!fd->secret->overlappedActive) {
- _PR_MD_CLOSE_SOCKET(fd->secret->md.osfd);
- fd->secret->state = _PR_FILEDESC_CLOSED;
+ _PR_MD_CLOSE_SOCKET(fd->secret->md.osfd);
+ fd->secret->state = _PR_FILEDESC_CLOSED;
#ifdef _PR_HAVE_PEEK_BUFFER
- if (fd->secret->peekBuffer) {
- PR_ASSERT(fd->secret->peekBufSize > 0);
- PR_DELETE(fd->secret->peekBuffer);
- fd->secret->peekBufSize = 0;
- fd->secret->peekBytes = 0;
- }
+ if (fd->secret->peekBuffer) {
+ PR_ASSERT(fd->secret->peekBufSize > 0);
+ PR_DELETE(fd->secret->peekBuffer);
+ fd->secret->peekBufSize = 0;
+ fd->secret->peekBytes = 0;
+ }
#endif
- PR_FreeFileDesc(fd);
-
- if (previous) {
- previous->next = cur->next;
- } else {
- _fd_waiting_for_overlapped_done = cur->next;
- }
- PRFileDescList *del = cur;
- cur = cur->next;
- PR_Free(del);
- } else {
- previous = cur;
- cur = cur->next;
+ PR_FreeFileDesc(fd);
+
+ if (previous) {
+ previous->next = cur->next;
+ } else {
+ _fd_waiting_for_overlapped_done = cur->next;
+ }
+ PRFileDescList *del = cur;
+ cur = cur->next;
+ PR_Free(del);
+ } else {
+ previous = cur;
+ cur = cur->next;
+ }
}
- }
- PR_Unlock(_fd_waiting_for_overlapped_done_lock);
+ PR_Unlock(_fd_waiting_for_overlapped_done_lock);
}
#endif
@@ -209,11 +211,11 @@ void CheckOverlappedPendingSocketsAreDone()
PR_IMPLEMENT(PRInt32) PR_Poll(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
{
#if defined(_WIN64) && defined(WIN95)
- // For each iteration check if TFO overlapped IOs are down.
- CheckOverlappedPendingSocketsAreDone();
+ // For each iteration check if TFO overlapped IOs are down.
+ CheckOverlappedPendingSocketsAreDone();
#endif
- return(_PR_MD_PR_POLL(pds, npds, timeout));
+ return(_PR_MD_PR_POLL(pds, npds, timeout));
}
/*
@@ -223,7 +225,7 @@ PR_IMPLEMENT(PRStatus) PR_SetFDInheritable(
PRFileDesc *fd,
PRBool inheritable)
{
-#if defined(XP_UNIX) || defined(WIN32) || defined(XP_OS2) || defined(XP_BEOS)
+#if defined(XP_UNIX) || defined(WIN32) || defined(XP_OS2)
/*
* Only a non-layered, NSPR file descriptor can be inherited
* by a child process.
diff --git a/nsprpub/pr/src/io/priometh.c b/nsprpub/pr/src/io/priometh.c
index 4208767d5..508719a80 100644
--- a/nsprpub/pr/src/io/priometh.c
+++ b/nsprpub/pr/src/io/priometh.c
@@ -22,26 +22,26 @@ PRIOMethods _pr_faulty_methods = {
(PRSeek64FN)_PR_InvalidInt64,
(PRFileInfoFN)_PR_InvalidStatus,
(PRFileInfo64FN)_PR_InvalidStatus,
- (PRWritevFN)_PR_InvalidInt,
- (PRConnectFN)_PR_InvalidStatus,
- (PRAcceptFN)_PR_InvalidDesc,
- (PRBindFN)_PR_InvalidStatus,
- (PRListenFN)_PR_InvalidStatus,
- (PRShutdownFN)_PR_InvalidStatus,
- (PRRecvFN)_PR_InvalidInt,
- (PRSendFN)_PR_InvalidInt,
- (PRRecvfromFN)_PR_InvalidInt,
- (PRSendtoFN)_PR_InvalidInt,
+ (PRWritevFN)_PR_InvalidInt,
+ (PRConnectFN)_PR_InvalidStatus,
+ (PRAcceptFN)_PR_InvalidDesc,
+ (PRBindFN)_PR_InvalidStatus,
+ (PRListenFN)_PR_InvalidStatus,
+ (PRShutdownFN)_PR_InvalidStatus,
+ (PRRecvFN)_PR_InvalidInt,
+ (PRSendFN)_PR_InvalidInt,
+ (PRRecvfromFN)_PR_InvalidInt,
+ (PRSendtoFN)_PR_InvalidInt,
(PRPollFN)_PR_InvalidInt16,
- (PRAcceptreadFN)_PR_InvalidInt,
- (PRTransmitfileFN)_PR_InvalidInt,
- (PRGetsocknameFN)_PR_InvalidStatus,
- (PRGetpeernameFN)_PR_InvalidStatus,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
+ (PRAcceptreadFN)_PR_InvalidInt,
+ (PRTransmitfileFN)_PR_InvalidInt,
+ (PRGetsocknameFN)_PR_InvalidStatus,
+ (PRGetpeernameFN)_PR_InvalidStatus,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
(PRGetsocketoptionFN)_PR_InvalidStatus,
(PRSetsocketoptionFN)_PR_InvalidStatus,
- (PRSendfileFN)_PR_InvalidInt,
+ (PRSendfileFN)_PR_InvalidInt,
(PRConnectcontinueFN)_PR_InvalidStatus,
(PRReservedFN)_PR_InvalidInt,
(PRReservedFN)_PR_InvalidInt,
@@ -106,159 +106,159 @@ PR_IMPLEMENT(PRStatus) PR_Close(PRFileDesc *fd)
PR_IMPLEMENT(PRInt32) PR_Read(PRFileDesc *fd, void *buf, PRInt32 amount)
{
- return((fd->methods->read)(fd,buf,amount));
+ return((fd->methods->read)(fd,buf,amount));
}
PR_IMPLEMENT(PRInt32) PR_Write(PRFileDesc *fd, const void *buf, PRInt32 amount)
{
- return((fd->methods->write)(fd,buf,amount));
+ return((fd->methods->write)(fd,buf,amount));
}
PR_IMPLEMENT(PRInt32) PR_Seek(PRFileDesc *fd, PRInt32 offset, PRSeekWhence whence)
{
- return((fd->methods->seek)(fd, offset, whence));
+ return((fd->methods->seek)(fd, offset, whence));
}
PR_IMPLEMENT(PRInt64) PR_Seek64(PRFileDesc *fd, PRInt64 offset, PRSeekWhence whence)
{
- return((fd->methods->seek64)(fd, offset, whence));
+ return((fd->methods->seek64)(fd, offset, whence));
}
PR_IMPLEMENT(PRInt32) PR_Available(PRFileDesc *fd)
{
- return((fd->methods->available)(fd));
+ return((fd->methods->available)(fd));
}
PR_IMPLEMENT(PRInt64) PR_Available64(PRFileDesc *fd)
{
- return((fd->methods->available64)(fd));
+ return((fd->methods->available64)(fd));
}
PR_IMPLEMENT(PRStatus) PR_GetOpenFileInfo(PRFileDesc *fd, PRFileInfo *info)
{
- return((fd->methods->fileInfo)(fd, info));
+ return((fd->methods->fileInfo)(fd, info));
}
PR_IMPLEMENT(PRStatus) PR_GetOpenFileInfo64(PRFileDesc *fd, PRFileInfo64 *info)
{
- return((fd->methods->fileInfo64)(fd, info));
+ return((fd->methods->fileInfo64)(fd, info));
}
PR_IMPLEMENT(PRStatus) PR_Sync(PRFileDesc *fd)
{
- return((fd->methods->fsync)(fd));
+ return((fd->methods->fsync)(fd));
}
PR_IMPLEMENT(PRStatus) PR_Connect(
PRFileDesc *fd, const PRNetAddr *addr, PRIntervalTime timeout)
{
- return((fd->methods->connect)(fd,addr,timeout));
+ return((fd->methods->connect)(fd,addr,timeout));
}
PR_IMPLEMENT(PRStatus) PR_ConnectContinue(
PRFileDesc *fd, PRInt16 out_flags)
{
- return((fd->methods->connectcontinue)(fd,out_flags));
+ return((fd->methods->connectcontinue)(fd,out_flags));
}
PR_IMPLEMENT(PRFileDesc*) PR_Accept(PRFileDesc *fd, PRNetAddr *addr,
-PRIntervalTime timeout)
+ PRIntervalTime timeout)
{
- return((fd->methods->accept)(fd,addr,timeout));
+ return((fd->methods->accept)(fd,addr,timeout));
}
PR_IMPLEMENT(PRStatus) PR_Bind(PRFileDesc *fd, const PRNetAddr *addr)
{
- return((fd->methods->bind)(fd,addr));
+ return((fd->methods->bind)(fd,addr));
}
PR_IMPLEMENT(PRStatus) PR_Shutdown(PRFileDesc *fd, PRShutdownHow how)
{
- return((fd->methods->shutdown)(fd,how));
+ return((fd->methods->shutdown)(fd,how));
}
PR_IMPLEMENT(PRStatus) PR_Listen(PRFileDesc *fd, PRIntn backlog)
{
- return((fd->methods->listen)(fd,backlog));
+ return((fd->methods->listen)(fd,backlog));
}
PR_IMPLEMENT(PRInt32) PR_Recv(PRFileDesc *fd, void *buf, PRInt32 amount,
-PRIntn flags, PRIntervalTime timeout)
+ PRIntn flags, PRIntervalTime timeout)
{
- return((fd->methods->recv)(fd,buf,amount,flags,timeout));
+ return((fd->methods->recv)(fd,buf,amount,flags,timeout));
}
PR_IMPLEMENT(PRInt32) PR_Send(PRFileDesc *fd, const void *buf, PRInt32 amount,
-PRIntn flags, PRIntervalTime timeout)
+ PRIntn flags, PRIntervalTime timeout)
{
- return((fd->methods->send)(fd,buf,amount,flags,timeout));
+ return((fd->methods->send)(fd,buf,amount,flags,timeout));
}
PR_IMPLEMENT(PRInt32) PR_Writev(PRFileDesc *fd, const PRIOVec *iov,
-PRInt32 iov_size, PRIntervalTime timeout)
+ PRInt32 iov_size, PRIntervalTime timeout)
{
if (iov_size > PR_MAX_IOVECTOR_SIZE)
{
PR_SetError(PR_BUFFER_OVERFLOW_ERROR, 0);
return -1;
}
- return((fd->methods->writev)(fd,iov,iov_size,timeout));
+ return((fd->methods->writev)(fd,iov,iov_size,timeout));
}
PR_IMPLEMENT(PRInt32) PR_RecvFrom(PRFileDesc *fd, void *buf, PRInt32 amount,
-PRIntn flags, PRNetAddr *addr, PRIntervalTime timeout)
+ PRIntn flags, PRNetAddr *addr, PRIntervalTime timeout)
{
- return((fd->methods->recvfrom)(fd,buf,amount,flags,addr,timeout));
+ return((fd->methods->recvfrom)(fd,buf,amount,flags,addr,timeout));
}
PR_IMPLEMENT(PRInt32) PR_SendTo(
PRFileDesc *fd, const void *buf, PRInt32 amount,
PRIntn flags, const PRNetAddr *addr, PRIntervalTime timeout)
{
- return((fd->methods->sendto)(fd,buf,amount,flags,addr,timeout));
+ return((fd->methods->sendto)(fd,buf,amount,flags,addr,timeout));
}
PR_IMPLEMENT(PRInt32) PR_TransmitFile(
PRFileDesc *sd, PRFileDesc *fd, const void *hdr, PRInt32 hlen,
PRTransmitFileFlags flags, PRIntervalTime timeout)
{
- return((sd->methods->transmitfile)(sd,fd,hdr,hlen,flags,timeout));
+ return((sd->methods->transmitfile)(sd,fd,hdr,hlen,flags,timeout));
}
PR_IMPLEMENT(PRInt32) PR_AcceptRead(
PRFileDesc *sd, PRFileDesc **nd, PRNetAddr **raddr,
void *buf, PRInt32 amount, PRIntervalTime timeout)
{
- return((sd->methods->acceptread)(sd, nd, raddr, buf, amount,timeout));
+ return((sd->methods->acceptread)(sd, nd, raddr, buf, amount,timeout));
}
PR_IMPLEMENT(PRStatus) PR_GetSockName(PRFileDesc *fd, PRNetAddr *addr)
{
- return((fd->methods->getsockname)(fd,addr));
+ return((fd->methods->getsockname)(fd,addr));
}
PR_IMPLEMENT(PRStatus) PR_GetPeerName(PRFileDesc *fd, PRNetAddr *addr)
{
- return((fd->methods->getpeername)(fd,addr));
+ return((fd->methods->getpeername)(fd,addr));
}
PR_IMPLEMENT(PRStatus) PR_GetSocketOption(
PRFileDesc *fd, PRSocketOptionData *data)
{
- return((fd->methods->getsocketoption)(fd, data));
+ return((fd->methods->getsocketoption)(fd, data));
}
PR_IMPLEMENT(PRStatus) PR_SetSocketOption(
PRFileDesc *fd, const PRSocketOptionData *data)
{
- return((fd->methods->setsocketoption)(fd, data));
+ return((fd->methods->setsocketoption)(fd, data));
}
PR_IMPLEMENT(PRInt32) PR_SendFile(
- PRFileDesc *sd, PRSendFileData *sfd,
- PRTransmitFileFlags flags, PRIntervalTime timeout)
+ PRFileDesc *sd, PRSendFileData *sfd,
+ PRTransmitFileFlags flags, PRIntervalTime timeout)
{
- return((sd->methods->sendfile)(sd,sfd,flags,timeout));
+ return((sd->methods->sendfile)(sd,sfd,flags,timeout));
}
PR_IMPLEMENT(PRInt32) PR_EmulateAcceptRead(
@@ -274,7 +274,9 @@ PR_IMPLEMENT(PRInt32) PR_EmulateAcceptRead(
** operation - it waits indefinitely.
*/
accepted = PR_Accept(sd, &remote, PR_INTERVAL_NO_TIMEOUT);
- if (NULL == accepted) return rv;
+ if (NULL == accepted) {
+ return rv;
+ }
rv = PR_Recv(accepted, buf, amount, 0, timeout);
if (rv >= 0)
@@ -299,7 +301,7 @@ PR_IMPLEMENT(PRInt32) PR_EmulateAcceptRead(
* they are sent before and after the file, respectively.
*
* PR_TRANSMITFILE_CLOSE_SOCKET flag - close socket after sending file
- *
+ *
* return number of bytes sent or -1 on error
*
*/
@@ -310,7 +312,7 @@ PR_IMPLEMENT(PRInt32) PR_EmulateAcceptRead(
* An implementation based on memory-mapped files
*/
-#define SENDFILE_MMAP_CHUNK (256 * 1024)
+#define SENDFILE_MMAP_CHUNK (256 * 1024)
PR_IMPLEMENT(PRInt32) PR_EmulateSendFile(
PRFileDesc *sd, PRSendFileData *sfd,
@@ -333,7 +335,7 @@ PR_IMPLEMENT(PRInt32) PR_EmulateSendFile(
goto done;
}
if (sfd->file_nbytes &&
- (info.size < (sfd->file_offset + sfd->file_nbytes))) {
+ (info.size < (sfd->file_offset + sfd->file_nbytes))) {
/*
* there are fewer bytes in file to send than specified
*/
@@ -341,10 +343,12 @@ PR_IMPLEMENT(PRInt32) PR_EmulateSendFile(
count = -1;
goto done;
}
- if (sfd->file_nbytes)
+ if (sfd->file_nbytes) {
file_bytes = sfd->file_nbytes;
- else
+ }
+ else {
file_bytes = info.size - sfd->file_offset;
+ }
alignment = PR_GetMemMapAlignment();
@@ -400,8 +404,9 @@ PR_IMPLEMENT(PRInt32) PR_EmulateSendFile(
index++;
}
rv = PR_Writev(sd, iov, index, timeout);
- if (len)
+ if (len) {
PR_MemUnmap(addr, mmap_len);
+ }
if (rv < 0) {
count = -1;
goto done;
@@ -411,8 +416,9 @@ PR_IMPLEMENT(PRInt32) PR_EmulateSendFile(
file_bytes -= len;
count += rv;
- if (!file_bytes) /* header, file and trailer are sent */
+ if (!file_bytes) { /* header, file and trailer are sent */
goto done;
+ }
/*
* send remaining bytes of the file, if any
@@ -449,14 +455,17 @@ PR_IMPLEMENT(PRInt32) PR_EmulateSendFile(
if (rv >= 0) {
PR_ASSERT(rv == sfd->tlen);
count += rv;
- } else
+ } else {
count = -1;
+ }
}
done:
- if (mapHandle)
+ if (mapHandle) {
PR_CloseFileMap(mapHandle);
- if ((count >= 0) && (flags & PR_TRANSMITFILE_CLOSE_SOCKET))
+ }
+ if ((count >= 0) && (flags & PR_TRANSMITFILE_CLOSE_SOCKET)) {
PR_Close(sd);
+ }
return count;
}
@@ -584,10 +593,12 @@ PR_IMPLEMENT(PRInt32) PR_EmulateSendFile(
rv = count;
done:
- if (buf)
+ if (buf) {
PR_DELETE(buf);
- if ((rv >= 0) && (flags & PR_TRANSMITFILE_CLOSE_SOCKET))
+ }
+ if ((rv >= 0) && (flags & PR_TRANSMITFILE_CLOSE_SOCKET)) {
PR_Close(sd);
+ }
return rv;
}
diff --git a/nsprpub/pr/src/io/pripv6.c b/nsprpub/pr/src/io/pripv6.c
index af7de49de..1c299652e 100644
--- a/nsprpub/pr/src/io/pripv6.c
+++ b/nsprpub/pr/src/io/pripv6.c
@@ -16,117 +16,117 @@ static PRIOMethods ipv6_to_v4_tcpMethods;
static PRIOMethods ipv6_to_v4_udpMethods;
static PRDescIdentity _pr_ipv6_to_ipv4_id;
extern PRBool IsValidNetAddr(const PRNetAddr *addr);
-extern PRIPv6Addr _pr_in6addr_any;
-extern PRIPv6Addr _pr_in6addr_loopback;
+extern const PRIPv6Addr _pr_in6addr_any;
+extern const PRIPv6Addr _pr_in6addr_loopback;
/*
* convert an IPv4-mapped IPv6 addr to an IPv4 addr
*/
static void _PR_ConvertToIpv4NetAddr(const PRNetAddr *src_v6addr,
- PRNetAddr *dst_v4addr)
+ PRNetAddr *dst_v4addr)
{
-const PRUint8 *srcp;
+ const PRUint8 *srcp;
- PR_ASSERT(PR_AF_INET6 == src_v6addr->ipv6.family);
+ PR_ASSERT(PR_AF_INET6 == src_v6addr->ipv6.family);
- if (PR_IsNetAddrType(src_v6addr, PR_IpAddrV4Mapped)) {
- srcp = src_v6addr->ipv6.ip.pr_s6_addr;
- memcpy((char *) &dst_v4addr->inet.ip, srcp + 12, 4);
+ if (PR_IsNetAddrType(src_v6addr, PR_IpAddrV4Mapped)) {
+ srcp = src_v6addr->ipv6.ip.pr_s6_addr;
+ memcpy((char *) &dst_v4addr->inet.ip, srcp + 12, 4);
} else if (PR_IsNetAddrType(src_v6addr, PR_IpAddrAny)) {
dst_v4addr->inet.ip = htonl(INADDR_ANY);
} else if (PR_IsNetAddrType(src_v6addr, PR_IpAddrLoopback)) {
dst_v4addr->inet.ip = htonl(INADDR_LOOPBACK);
}
- dst_v4addr->inet.family = PR_AF_INET;
- dst_v4addr->inet.port = src_v6addr->ipv6.port;
+ dst_v4addr->inet.family = PR_AF_INET;
+ dst_v4addr->inet.port = src_v6addr->ipv6.port;
}
/*
* convert an IPv4 addr to an IPv4-mapped IPv6 addr
*/
static void _PR_ConvertToIpv6NetAddr(const PRNetAddr *src_v4addr,
- PRNetAddr *dst_v6addr)
+ PRNetAddr *dst_v6addr)
{
-PRUint8 *dstp;
-
- PR_ASSERT(PR_AF_INET == src_v4addr->inet.family);
- dst_v6addr->ipv6.family = PR_AF_INET6;
- dst_v6addr->ipv6.port = src_v4addr->inet.port;
-
- if (htonl(INADDR_ANY) == src_v4addr->inet.ip) {
- dst_v6addr->ipv6.ip = _pr_in6addr_any;
- } else {
- dstp = dst_v6addr->ipv6.ip.pr_s6_addr;
- memset(dstp, 0, 10);
- memset(dstp + 10, 0xff, 2);
- memcpy(dstp + 12,(char *) &src_v4addr->inet.ip, 4);
- }
+ PRUint8 *dstp;
+
+ PR_ASSERT(PR_AF_INET == src_v4addr->inet.family);
+ dst_v6addr->ipv6.family = PR_AF_INET6;
+ dst_v6addr->ipv6.port = src_v4addr->inet.port;
+
+ if (htonl(INADDR_ANY) == src_v4addr->inet.ip) {
+ dst_v6addr->ipv6.ip = _pr_in6addr_any;
+ } else {
+ dstp = dst_v6addr->ipv6.ip.pr_s6_addr;
+ memset(dstp, 0, 10);
+ memset(dstp + 10, 0xff, 2);
+ memcpy(dstp + 12,(char *) &src_v4addr->inet.ip, 4);
+ }
}
static PRStatus PR_CALLBACK Ipv6ToIpv4SocketBind(PRFileDesc *fd,
- const PRNetAddr *addr)
+ const PRNetAddr *addr)
{
- PRNetAddr tmp_ipv4addr;
- const PRNetAddr *tmp_addrp;
- PRFileDesc *lo = fd->lower;
+ PRNetAddr tmp_ipv4addr;
+ const PRNetAddr *tmp_addrp;
+ PRFileDesc *lo = fd->lower;
- if (PR_AF_INET6 != addr->raw.family) {
+ if (PR_AF_INET6 != addr->raw.family) {
PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, 0);
- return PR_FAILURE;
- }
- if (PR_IsNetAddrType(addr, PR_IpAddrV4Mapped) ||
- PR_IsNetAddrType(addr, PR_IpAddrAny)) {
- _PR_ConvertToIpv4NetAddr(addr, &tmp_ipv4addr);
- tmp_addrp = &tmp_ipv4addr;
- } else {
+ return PR_FAILURE;
+ }
+ if (PR_IsNetAddrType(addr, PR_IpAddrV4Mapped) ||
+ PR_IsNetAddrType(addr, PR_IpAddrAny)) {
+ _PR_ConvertToIpv4NetAddr(addr, &tmp_ipv4addr);
+ tmp_addrp = &tmp_ipv4addr;
+ } else {
PR_SetError(PR_NETWORK_UNREACHABLE_ERROR, 0);
- return PR_FAILURE;
- }
- return((lo->methods->bind)(lo,tmp_addrp));
+ return PR_FAILURE;
+ }
+ return((lo->methods->bind)(lo,tmp_addrp));
}
static PRStatus PR_CALLBACK Ipv6ToIpv4SocketConnect(
PRFileDesc *fd, const PRNetAddr *addr, PRIntervalTime timeout)
{
- PRNetAddr tmp_ipv4addr;
- const PRNetAddr *tmp_addrp;
+ PRNetAddr tmp_ipv4addr;
+ const PRNetAddr *tmp_addrp;
- if (PR_AF_INET6 != addr->raw.family) {
+ if (PR_AF_INET6 != addr->raw.family) {
PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, 0);
- return PR_FAILURE;
- }
- if (PR_IsNetAddrType(addr, PR_IpAddrV4Mapped) ||
- PR_IsNetAddrType(addr, PR_IpAddrLoopback)) {
- _PR_ConvertToIpv4NetAddr(addr, &tmp_ipv4addr);
- tmp_addrp = &tmp_ipv4addr;
- } else {
+ return PR_FAILURE;
+ }
+ if (PR_IsNetAddrType(addr, PR_IpAddrV4Mapped) ||
+ PR_IsNetAddrType(addr, PR_IpAddrLoopback)) {
+ _PR_ConvertToIpv4NetAddr(addr, &tmp_ipv4addr);
+ tmp_addrp = &tmp_ipv4addr;
+ } else {
PR_SetError(PR_NETWORK_UNREACHABLE_ERROR, 0);
- return PR_FAILURE;
- }
- return (fd->lower->methods->connect)(fd->lower, tmp_addrp, timeout);
+ return PR_FAILURE;
+ }
+ return (fd->lower->methods->connect)(fd->lower, tmp_addrp, timeout);
}
static PRInt32 PR_CALLBACK Ipv6ToIpv4SocketSendTo(
PRFileDesc *fd, const void *buf, PRInt32 amount,
PRIntn flags, const PRNetAddr *addr, PRIntervalTime timeout)
{
- PRNetAddr tmp_ipv4addr;
- const PRNetAddr *tmp_addrp;
+ PRNetAddr tmp_ipv4addr;
+ const PRNetAddr *tmp_addrp;
- if (PR_AF_INET6 != addr->raw.family) {
+ if (PR_AF_INET6 != addr->raw.family) {
PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, 0);
- return PR_FAILURE;
- }
- if (PR_IsNetAddrType(addr, PR_IpAddrV4Mapped) ||
- PR_IsNetAddrType(addr, PR_IpAddrLoopback)) {
- _PR_ConvertToIpv4NetAddr(addr, &tmp_ipv4addr);
- tmp_addrp = &tmp_ipv4addr;
- } else {
+ return PR_FAILURE;
+ }
+ if (PR_IsNetAddrType(addr, PR_IpAddrV4Mapped) ||
+ PR_IsNetAddrType(addr, PR_IpAddrLoopback)) {
+ _PR_ConvertToIpv4NetAddr(addr, &tmp_ipv4addr);
+ tmp_addrp = &tmp_ipv4addr;
+ } else {
PR_SetError(PR_NETWORK_UNREACHABLE_ERROR, 0);
- return PR_FAILURE;
- }
+ return PR_FAILURE;
+ }
return (fd->lower->methods->sendto)(
- fd->lower, buf, amount, flags, tmp_addrp, timeout);
+ fd->lower, buf, amount, flags, tmp_addrp, timeout);
}
static PRFileDesc* PR_CALLBACK Ipv6ToIpv4SocketAccept (
@@ -135,7 +135,7 @@ static PRFileDesc* PR_CALLBACK Ipv6ToIpv4SocketAccept (
PRStatus rv;
PRFileDesc *newfd;
PRFileDesc *newstack;
- PRNetAddr tmp_ipv4addr;
+ PRNetAddr tmp_ipv4addr;
PRNetAddr *addrlower = NULL;
PR_ASSERT(fd != NULL);
@@ -149,16 +149,18 @@ static PRFileDesc* PR_CALLBACK Ipv6ToIpv4SocketAccept (
}
*newstack = *fd; /* make a copy of the accepting layer */
- if (addr)
+ if (addr) {
addrlower = &tmp_ipv4addr;
+ }
newfd = (fd->lower->methods->accept)(fd->lower, addrlower, timeout);
if (NULL == newfd)
{
PR_DELETE(newstack);
return NULL;
}
- if (addr)
+ if (addr) {
_PR_ConvertToIpv6NetAddr(&tmp_ipv4addr, addr);
+ }
rv = PR_PushIOLayer(newfd, PR_TOP_IO_LAYER, newstack);
PR_ASSERT(PR_SUCCESS == rv);
@@ -166,12 +168,12 @@ static PRFileDesc* PR_CALLBACK Ipv6ToIpv4SocketAccept (
}
static PRInt32 PR_CALLBACK Ipv6ToIpv4SocketAcceptRead(PRFileDesc *sd,
- PRFileDesc **nd, PRNetAddr **ipv6_raddr, void *buf, PRInt32 amount,
- PRIntervalTime timeout)
+ PRFileDesc **nd, PRNetAddr **ipv6_raddr, void *buf, PRInt32 amount,
+ PRIntervalTime timeout)
{
PRInt32 nbytes;
PRStatus rv;
- PRNetAddr tmp_ipv4addr;
+ PRNetAddr tmp_ipv4addr;
PRFileDesc *newstack;
PR_ASSERT(sd != NULL);
@@ -186,14 +188,14 @@ static PRInt32 PR_CALLBACK Ipv6ToIpv4SocketAcceptRead(PRFileDesc *sd,
*newstack = *sd; /* make a copy of the accepting layer */
nbytes = sd->lower->methods->acceptread(
- sd->lower, nd, ipv6_raddr, buf, amount, timeout);
+ sd->lower, nd, ipv6_raddr, buf, amount, timeout);
if (-1 == nbytes)
{
PR_DELETE(newstack);
return nbytes;
}
- tmp_ipv4addr = **ipv6_raddr; /* copy */
- _PR_ConvertToIpv6NetAddr(&tmp_ipv4addr, *ipv6_raddr);
+ tmp_ipv4addr = **ipv6_raddr; /* copy */
+ _PR_ConvertToIpv6NetAddr(&tmp_ipv4addr, *ipv6_raddr);
/* this PR_PushIOLayer call cannot fail */
rv = PR_PushIOLayer(*nd, PR_TOP_IO_LAYER, newstack);
@@ -202,52 +204,52 @@ static PRInt32 PR_CALLBACK Ipv6ToIpv4SocketAcceptRead(PRFileDesc *sd,
}
static PRStatus PR_CALLBACK Ipv6ToIpv4SocketGetName(PRFileDesc *fd,
- PRNetAddr *ipv6addr)
+ PRNetAddr *ipv6addr)
{
- PRStatus result;
- PRNetAddr tmp_ipv4addr;
-
- result = (fd->lower->methods->getsockname)(fd->lower, &tmp_ipv4addr);
- if (PR_SUCCESS == result) {
- _PR_ConvertToIpv6NetAddr(&tmp_ipv4addr, ipv6addr);
- PR_ASSERT(IsValidNetAddr(ipv6addr) == PR_TRUE);
- }
- return result;
+ PRStatus result;
+ PRNetAddr tmp_ipv4addr;
+
+ result = (fd->lower->methods->getsockname)(fd->lower, &tmp_ipv4addr);
+ if (PR_SUCCESS == result) {
+ _PR_ConvertToIpv6NetAddr(&tmp_ipv4addr, ipv6addr);
+ PR_ASSERT(IsValidNetAddr(ipv6addr) == PR_TRUE);
+ }
+ return result;
}
static PRStatus PR_CALLBACK Ipv6ToIpv4SocketGetPeerName(PRFileDesc *fd,
- PRNetAddr *ipv6addr)
+ PRNetAddr *ipv6addr)
{
- PRStatus result;
- PRNetAddr tmp_ipv4addr;
-
- result = (fd->lower->methods->getpeername)(fd->lower, &tmp_ipv4addr);
- if (PR_SUCCESS == result) {
- _PR_ConvertToIpv6NetAddr(&tmp_ipv4addr, ipv6addr);
- PR_ASSERT(IsValidNetAddr(ipv6addr) == PR_TRUE);
- }
- return result;
+ PRStatus result;
+ PRNetAddr tmp_ipv4addr;
+
+ result = (fd->lower->methods->getpeername)(fd->lower, &tmp_ipv4addr);
+ if (PR_SUCCESS == result) {
+ _PR_ConvertToIpv6NetAddr(&tmp_ipv4addr, ipv6addr);
+ PR_ASSERT(IsValidNetAddr(ipv6addr) == PR_TRUE);
+ }
+ return result;
}
static PRInt32 PR_CALLBACK Ipv6ToIpv4SocketRecvFrom(PRFileDesc *fd, void *buf,
- PRInt32 amount, PRIntn flags, PRNetAddr *ipv6addr,
- PRIntervalTime timeout)
+ PRInt32 amount, PRIntn flags, PRNetAddr *ipv6addr,
+ PRIntervalTime timeout)
{
- PRNetAddr tmp_ipv4addr;
- PRInt32 result;
+ PRNetAddr tmp_ipv4addr;
+ PRInt32 result;
result = (fd->lower->methods->recvfrom)(
- fd->lower, buf, amount, flags, &tmp_ipv4addr, timeout);
- if (-1 != result) {
- _PR_ConvertToIpv6NetAddr(&tmp_ipv4addr, ipv6addr);
- PR_ASSERT(IsValidNetAddr(ipv6addr) == PR_TRUE);
- }
- return result;
+ fd->lower, buf, amount, flags, &tmp_ipv4addr, timeout);
+ if (-1 != result) {
+ _PR_ConvertToIpv6NetAddr(&tmp_ipv4addr, ipv6addr);
+ PR_ASSERT(IsValidNetAddr(ipv6addr) == PR_TRUE);
+ }
+ return result;
}
#if defined(_PR_INET6_PROBE)
static PRBool ipv6_is_present;
-extern PRBool _pr_test_ipv6_socket(void);
+PR_EXTERN(PRBool) _pr_test_ipv6_socket(void);
#if !defined(_PR_INET6) && defined(_PR_HAVE_GETIPNODEBYNAME)
extern PRStatus _pr_find_getipnodebyname(void);
@@ -261,13 +263,15 @@ static PRBool
_pr_probe_ipv6_presence(void)
{
#if !defined(_PR_INET6) && defined(_PR_HAVE_GETIPNODEBYNAME)
- if (_pr_find_getipnodebyname() != PR_SUCCESS)
+ if (_pr_find_getipnodebyname() != PR_SUCCESS) {
return PR_FALSE;
+ }
#endif
#if !defined(_PR_INET6) && defined(_PR_HAVE_GETADDRINFO)
- if (_pr_find_getaddrinfo() != PR_SUCCESS)
+ if (_pr_find_getaddrinfo() != PR_SUCCESS) {
return PR_FALSE;
+ }
#endif
return _pr_test_ipv6_socket();
@@ -282,83 +286,87 @@ static PRStatus PR_CALLBACK _pr_init_ipv6(void)
#if defined(_PR_INET6_PROBE)
ipv6_is_present = _pr_probe_ipv6_presence();
- if (ipv6_is_present)
+ if (ipv6_is_present) {
return PR_SUCCESS;
+ }
#endif
_pr_ipv6_to_ipv4_id = PR_GetUniqueIdentity("Ipv6_to_Ipv4 layer");
PR_ASSERT(PR_INVALID_IO_LAYER != _pr_ipv6_to_ipv4_id);
- stubMethods = PR_GetDefaultIOMethods();
-
- ipv6_to_v4_tcpMethods = *stubMethods; /* first get the entire batch */
- /* then override the ones we care about */
- ipv6_to_v4_tcpMethods.connect = Ipv6ToIpv4SocketConnect;
- ipv6_to_v4_tcpMethods.bind = Ipv6ToIpv4SocketBind;
- ipv6_to_v4_tcpMethods.accept = Ipv6ToIpv4SocketAccept;
- ipv6_to_v4_tcpMethods.acceptread = Ipv6ToIpv4SocketAcceptRead;
- ipv6_to_v4_tcpMethods.getsockname = Ipv6ToIpv4SocketGetName;
- ipv6_to_v4_tcpMethods.getpeername = Ipv6ToIpv4SocketGetPeerName;
-/*
- ipv6_to_v4_tcpMethods.getsocketoption = Ipv6ToIpv4GetSocketOption;
- ipv6_to_v4_tcpMethods.setsocketoption = Ipv6ToIpv4SetSocketOption;
-*/
- ipv6_to_v4_udpMethods = *stubMethods; /* first get the entire batch */
- /* then override the ones we care about */
- ipv6_to_v4_udpMethods.connect = Ipv6ToIpv4SocketConnect;
- ipv6_to_v4_udpMethods.bind = Ipv6ToIpv4SocketBind;
- ipv6_to_v4_udpMethods.sendto = Ipv6ToIpv4SocketSendTo;
- ipv6_to_v4_udpMethods.recvfrom = Ipv6ToIpv4SocketRecvFrom;
- ipv6_to_v4_udpMethods.getsockname = Ipv6ToIpv4SocketGetName;
- ipv6_to_v4_udpMethods.getpeername = Ipv6ToIpv4SocketGetPeerName;
-/*
- ipv6_to_v4_udpMethods.getsocketoption = Ipv6ToIpv4GetSocketOption;
- ipv6_to_v4_udpMethods.setsocketoption = Ipv6ToIpv4SetSocketOption;
-*/
- return PR_SUCCESS;
+ stubMethods = PR_GetDefaultIOMethods();
+
+ ipv6_to_v4_tcpMethods = *stubMethods; /* first get the entire batch */
+ /* then override the ones we care about */
+ ipv6_to_v4_tcpMethods.connect = Ipv6ToIpv4SocketConnect;
+ ipv6_to_v4_tcpMethods.bind = Ipv6ToIpv4SocketBind;
+ ipv6_to_v4_tcpMethods.accept = Ipv6ToIpv4SocketAccept;
+ ipv6_to_v4_tcpMethods.acceptread = Ipv6ToIpv4SocketAcceptRead;
+ ipv6_to_v4_tcpMethods.getsockname = Ipv6ToIpv4SocketGetName;
+ ipv6_to_v4_tcpMethods.getpeername = Ipv6ToIpv4SocketGetPeerName;
+ /*
+ ipv6_to_v4_tcpMethods.getsocketoption = Ipv6ToIpv4GetSocketOption;
+ ipv6_to_v4_tcpMethods.setsocketoption = Ipv6ToIpv4SetSocketOption;
+ */
+ ipv6_to_v4_udpMethods = *stubMethods; /* first get the entire batch */
+ /* then override the ones we care about */
+ ipv6_to_v4_udpMethods.connect = Ipv6ToIpv4SocketConnect;
+ ipv6_to_v4_udpMethods.bind = Ipv6ToIpv4SocketBind;
+ ipv6_to_v4_udpMethods.sendto = Ipv6ToIpv4SocketSendTo;
+ ipv6_to_v4_udpMethods.recvfrom = Ipv6ToIpv4SocketRecvFrom;
+ ipv6_to_v4_udpMethods.getsockname = Ipv6ToIpv4SocketGetName;
+ ipv6_to_v4_udpMethods.getpeername = Ipv6ToIpv4SocketGetPeerName;
+ /*
+ ipv6_to_v4_udpMethods.getsocketoption = Ipv6ToIpv4GetSocketOption;
+ ipv6_to_v4_udpMethods.setsocketoption = Ipv6ToIpv4SetSocketOption;
+ */
+ return PR_SUCCESS;
}
#if defined(_PR_INET6_PROBE)
PRBool _pr_ipv6_is_present(void)
{
- if (PR_CallOnce(&_pr_init_ipv6_once, _pr_init_ipv6) != PR_SUCCESS)
+ if (PR_CallOnce(&_pr_init_ipv6_once, _pr_init_ipv6) != PR_SUCCESS) {
return PR_FALSE;
+ }
return ipv6_is_present;
}
#endif
PR_IMPLEMENT(PRStatus) _pr_push_ipv6toipv4_layer(PRFileDesc *fd)
{
- PRFileDesc *ipv6_fd = NULL;
-
- if (PR_CallOnce(&_pr_init_ipv6_once, _pr_init_ipv6) != PR_SUCCESS)
- return PR_FAILURE;
-
- /*
- * For platforms with no support for IPv6
- * create layered socket for IPv4-mapped IPv6 addresses
- */
- if (fd->methods->file_type == PR_DESC_SOCKET_TCP)
- ipv6_fd = PR_CreateIOLayerStub(_pr_ipv6_to_ipv4_id,
- &ipv6_to_v4_tcpMethods);
- else
- ipv6_fd = PR_CreateIOLayerStub(_pr_ipv6_to_ipv4_id,
- &ipv6_to_v4_udpMethods);
- if (NULL == ipv6_fd) {
- goto errorExit;
- }
- ipv6_fd->secret = NULL;
-
- if (PR_PushIOLayer(fd, PR_TOP_IO_LAYER, ipv6_fd) == PR_FAILURE) {
- goto errorExit;
- }
-
- return PR_SUCCESS;
+ PRFileDesc *ipv6_fd = NULL;
+
+ if (PR_CallOnce(&_pr_init_ipv6_once, _pr_init_ipv6) != PR_SUCCESS) {
+ return PR_FAILURE;
+ }
+
+ /*
+ * For platforms with no support for IPv6
+ * create layered socket for IPv4-mapped IPv6 addresses
+ */
+ if (fd->methods->file_type == PR_DESC_SOCKET_TCP)
+ ipv6_fd = PR_CreateIOLayerStub(_pr_ipv6_to_ipv4_id,
+ &ipv6_to_v4_tcpMethods);
+ else
+ ipv6_fd = PR_CreateIOLayerStub(_pr_ipv6_to_ipv4_id,
+ &ipv6_to_v4_udpMethods);
+ if (NULL == ipv6_fd) {
+ goto errorExit;
+ }
+ ipv6_fd->secret = NULL;
+
+ if (PR_PushIOLayer(fd, PR_TOP_IO_LAYER, ipv6_fd) == PR_FAILURE) {
+ goto errorExit;
+ }
+
+ return PR_SUCCESS;
errorExit:
- if (ipv6_fd)
- ipv6_fd->dtor(ipv6_fd);
- return PR_FAILURE;
+ if (ipv6_fd) {
+ ipv6_fd->dtor(ipv6_fd);
+ }
+ return PR_FAILURE;
}
#endif /* !defined(_PR_INET6) || defined(_PR_INET6_PROBE) */
diff --git a/nsprpub/pr/src/io/prlayer.c b/nsprpub/pr/src/io/prlayer.c
index 00da0287a..1e63b7b72 100644
--- a/nsprpub/pr/src/io/prlayer.c
+++ b/nsprpub/pr/src/io/prlayer.c
@@ -21,8 +21,12 @@ static PRStatus _PR_DestroyIOLayer(PRFileDesc *stack);
void PR_CALLBACK pl_FDDestructor(PRFileDesc *fd)
{
PR_ASSERT(fd != NULL);
- if (NULL != fd->lower) fd->lower->higher = fd->higher;
- if (NULL != fd->higher) fd->higher->lower = fd->lower;
+ if (NULL != fd->lower) {
+ fd->lower->higher = fd->higher;
+ }
+ if (NULL != fd->higher) {
+ fd->higher->lower = fd->lower;
+ }
PR_DELETE(fd);
}
@@ -32,42 +36,42 @@ void PR_CALLBACK pl_FDDestructor(PRFileDesc *fd)
static PRStatus PR_CALLBACK pl_TopClose (PRFileDesc *fd)
{
PRFileDesc *top, *lower;
- PRStatus rv;
+ PRStatus rv;
PR_ASSERT(fd != NULL);
PR_ASSERT(fd->lower != NULL);
PR_ASSERT(fd->secret == NULL);
PR_ASSERT(fd->methods->file_type == PR_DESC_LAYERED);
- if (PR_IO_LAYER_HEAD == fd->identity) {
- /*
- * new style stack; close all the layers, before deleting the
- * stack head
- */
- rv = fd->lower->methods->close(fd->lower);
- _PR_DestroyIOLayer(fd);
- return rv;
- }
- if ((fd->higher) && (PR_IO_LAYER_HEAD == fd->higher->identity)) {
- /*
- * lower layers of new style stack
- */
- lower = fd->lower;
- /*
- * pop and cleanup current layer
- */
- top = PR_PopIOLayer(fd->higher, PR_TOP_IO_LAYER);
- top->dtor(top);
- /*
- * then call lower layer
- */
- return (lower->methods->close(lower));
- } else {
- /* old style stack */
- top = PR_PopIOLayer(fd, PR_TOP_IO_LAYER);
- top->dtor(top);
- return (fd->methods->close)(fd);
- }
+ if (PR_IO_LAYER_HEAD == fd->identity) {
+ /*
+ * new style stack; close all the layers, before deleting the
+ * stack head
+ */
+ rv = fd->lower->methods->close(fd->lower);
+ _PR_DestroyIOLayer(fd);
+ return rv;
+ }
+ if ((fd->higher) && (PR_IO_LAYER_HEAD == fd->higher->identity)) {
+ /*
+ * lower layers of new style stack
+ */
+ lower = fd->lower;
+ /*
+ * pop and cleanup current layer
+ */
+ top = PR_PopIOLayer(fd->higher, PR_TOP_IO_LAYER);
+ top->dtor(top);
+ /*
+ * then call lower layer
+ */
+ return (lower->methods->close(lower));
+ } else {
+ /* old style stack */
+ top = PR_PopIOLayer(fd, PR_TOP_IO_LAYER);
+ top->dtor(top);
+ return (fd->methods->close)(fd);
+ }
}
static PRInt32 PR_CALLBACK pl_DefRead (PRFileDesc *fd, void *buf, PRInt32 amount)
@@ -146,7 +150,7 @@ static PRStatus PR_CALLBACK pl_DefFileInfo64 (PRFileDesc *fd, PRFileInfo64 *info
}
static PRInt32 PR_CALLBACK pl_DefWritev (PRFileDesc *fd, const PRIOVec *iov,
- PRInt32 size, PRIntervalTime timeout)
+ PRInt32 size, PRIntervalTime timeout)
{
PR_ASSERT(fd != NULL);
PR_ASSERT(fd->lower != NULL);
@@ -178,15 +182,16 @@ static PRFileDesc* PR_CALLBACK pl_TopAccept (
PRStatus rv;
PRFileDesc *newfd, *layer = fd;
PRFileDesc *newstack;
- PRBool newstyle_stack = PR_FALSE;
+ PRBool newstyle_stack = PR_FALSE;
PR_ASSERT(fd != NULL);
PR_ASSERT(fd->lower != NULL);
- /* test for new style stack */
- while (NULL != layer->higher)
- layer = layer->higher;
- newstyle_stack = (PR_IO_LAYER_HEAD == layer->identity) ? PR_TRUE : PR_FALSE;
+ /* test for new style stack */
+ while (NULL != layer->higher) {
+ layer = layer->higher;
+ }
+ newstyle_stack = (PR_IO_LAYER_HEAD == layer->identity) ? PR_TRUE : PR_FALSE;
newstack = PR_NEW(PRFileDesc);
if (NULL == newstack)
{
@@ -246,7 +251,7 @@ static PRInt32 PR_CALLBACK pl_DefRecv (
PR_ASSERT(fd->lower != NULL);
return (fd->lower->methods->recv)(
- fd->lower, buf, amount, flags, timeout);
+ fd->lower, buf, amount, flags, timeout);
}
static PRInt32 PR_CALLBACK pl_DefSend (
@@ -267,7 +272,7 @@ static PRInt32 PR_CALLBACK pl_DefRecvfrom (
PR_ASSERT(fd->lower != NULL);
return (fd->lower->methods->recvfrom)(
- fd->lower, buf, amount, flags, addr, timeout);
+ fd->lower, buf, amount, flags, addr, timeout);
}
static PRInt32 PR_CALLBACK pl_DefSendto (
@@ -278,7 +283,7 @@ static PRInt32 PR_CALLBACK pl_DefSendto (
PR_ASSERT(fd->lower != NULL);
return (fd->lower->methods->sendto)(
- fd->lower, buf, amount, flags, addr, timeout);
+ fd->lower, buf, amount, flags, addr, timeout);
}
static PRInt16 PR_CALLBACK pl_DefPoll (
@@ -298,15 +303,16 @@ static PRInt32 PR_CALLBACK pl_DefAcceptread (
PRStatus rv;
PRFileDesc *newstack;
PRFileDesc *layer = sd;
- PRBool newstyle_stack = PR_FALSE;
+ PRBool newstyle_stack = PR_FALSE;
PR_ASSERT(sd != NULL);
PR_ASSERT(sd->lower != NULL);
- /* test for new style stack */
- while (NULL != layer->higher)
- layer = layer->higher;
- newstyle_stack = (PR_IO_LAYER_HEAD == layer->identity) ? PR_TRUE : PR_FALSE;
+ /* test for new style stack */
+ while (NULL != layer->higher) {
+ layer = layer->higher;
+ }
+ newstyle_stack = (PR_IO_LAYER_HEAD == layer->identity) ? PR_TRUE : PR_FALSE;
newstack = PR_NEW(PRFileDesc);
if (NULL == newstack)
{
@@ -316,18 +322,18 @@ static PRInt32 PR_CALLBACK pl_DefAcceptread (
*newstack = *sd; /* make a copy of the accepting layer */
nbytes = sd->lower->methods->acceptread(
- sd->lower, nd, raddr, buf, amount, t);
+ sd->lower, nd, raddr, buf, amount, t);
if (-1 == nbytes)
{
PR_DELETE(newstack);
return nbytes;
}
if (newstyle_stack) {
- newstack->lower = *nd;
- (*nd)->higher = newstack;
- *nd = newstack;
- return nbytes;
- }
+ newstack->lower = *nd;
+ (*nd)->higher = newstack;
+ *nd = newstack;
+ return nbytes;
+ }
/* this PR_PushIOLayer call cannot fail */
rv = PR_PushIOLayer(*nd, PR_TOP_IO_LAYER, newstack);
PR_ASSERT(PR_SUCCESS == rv);
@@ -342,7 +348,7 @@ static PRInt32 PR_CALLBACK pl_DefTransmitfile (
PR_ASSERT(sd->lower != NULL);
return sd->lower->methods->transmitfile(
- sd->lower, fd, headers, hlen, flags, t);
+ sd->lower, fd, headers, hlen, flags, t);
}
static PRStatus PR_CALLBACK pl_DefGetsockname (PRFileDesc *fd, PRNetAddr *addr)
@@ -380,14 +386,14 @@ static PRStatus PR_CALLBACK pl_DefSetsocketoption (
}
static PRInt32 PR_CALLBACK pl_DefSendfile (
- PRFileDesc *sd, PRSendFileData *sfd,
- PRTransmitFileFlags flags, PRIntervalTime timeout)
+ PRFileDesc *sd, PRSendFileData *sfd,
+ PRTransmitFileFlags flags, PRIntervalTime timeout)
{
PR_ASSERT(sd != NULL);
PR_ASSERT(sd->lower != NULL);
return sd->lower->methods->sendfile(
- sd->lower, sfd, flags, timeout);
+ sd->lower, sfd, flags, timeout);
}
/* Methods for the top of the stack. Just call down to the next fd. */
@@ -440,13 +446,15 @@ PR_IMPLEMENT(PRFileDesc*) PR_CreateIOLayerStub(
{
PRFileDesc *fd = NULL;
PR_ASSERT((PR_NSPR_IO_LAYER != ident) && (PR_TOP_IO_LAYER != ident));
- if ((PR_NSPR_IO_LAYER == ident) || (PR_TOP_IO_LAYER == ident))
+ if ((PR_NSPR_IO_LAYER == ident) || (PR_TOP_IO_LAYER == ident)) {
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+ }
else
{
fd = PR_NEWZAP(PRFileDesc);
- if (NULL == fd)
+ if (NULL == fd) {
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+ }
else
{
fd->methods = methods;
@@ -459,41 +467,43 @@ PR_IMPLEMENT(PRFileDesc*) PR_CreateIOLayerStub(
/*
* PR_CreateIOLayer
- * Create a new style stack, where the stack top is a dummy header.
- * Unlike the old style stacks, the contents of the stack head
- * are not modified when a layer is pushed onto or popped from a new
- * style stack.
+ * Create a new style stack, where the stack top is a dummy header.
+ * Unlike the old style stacks, the contents of the stack head
+ * are not modified when a layer is pushed onto or popped from a new
+ * style stack.
*/
PR_IMPLEMENT(PRFileDesc*) PR_CreateIOLayer(PRFileDesc *top)
{
PRFileDesc *fd = NULL;
- fd = PR_NEWZAP(PRFileDesc);
- if (NULL == fd)
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
- else
- {
- fd->methods = &pl_methods;
- fd->dtor = pl_FDDestructor;
- fd->identity = PR_IO_LAYER_HEAD;
- fd->higher = NULL;
- fd->lower = top;
- top->higher = fd;
- top->lower = NULL;
- }
+ fd = PR_NEWZAP(PRFileDesc);
+ if (NULL == fd) {
+ PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+ }
+ else
+ {
+ fd->methods = &pl_methods;
+ fd->dtor = pl_FDDestructor;
+ fd->identity = PR_IO_LAYER_HEAD;
+ fd->higher = NULL;
+ fd->lower = top;
+ top->higher = fd;
+ top->lower = NULL;
+ }
return fd;
} /* PR_CreateIOLayer */
/*
* _PR_DestroyIOLayer
- * Delete the stack head of a new style stack.
+ * Delete the stack head of a new style stack.
*/
static PRStatus _PR_DestroyIOLayer(PRFileDesc *stack)
{
- if (NULL == stack)
+ if (NULL == stack) {
return PR_FAILURE;
+ }
PR_DELETE(stack);
return PR_SUCCESS;
@@ -516,24 +526,24 @@ PR_IMPLEMENT(PRStatus) PR_PushIOLayer(
if (stack == insert)
{
- /* going on top of the stack */
- /* old-style stack */
- PRFileDesc copy = *stack;
- *stack = *fd;
- *fd = copy;
- fd->higher = stack;
- if (fd->lower)
- {
- PR_ASSERT(fd->lower->higher == stack);
- fd->lower->higher = fd;
- }
- stack->lower = fd;
- stack->higher = NULL;
- } else {
+ /* going on top of the stack */
+ /* old-style stack */
+ PRFileDesc copy = *stack;
+ *stack = *fd;
+ *fd = copy;
+ fd->higher = stack;
+ if (fd->lower)
+ {
+ PR_ASSERT(fd->lower->higher == stack);
+ fd->lower->higher = fd;
+ }
+ stack->lower = fd;
+ stack->higher = NULL;
+ } else {
/*
- * going somewhere in the middle of the stack for both old and new
- * style stacks, or going on top of stack for new style stack
- */
+ * going somewhere in the middle of the stack for both old and new
+ * style stacks, or going on top of stack for new style stack
+ */
fd->lower = insert;
fd->higher = insert->higher;
@@ -559,7 +569,7 @@ PR_IMPLEMENT(PRFileDesc*) PR_PopIOLayer(PRFileDesc *stack, PRDescIdentity id)
if (extract == stack) {
/* popping top layer of the stack */
- /* old style stack */
+ /* old style stack */
PRFileDesc copy = *stack;
extract = stack->lower;
*stack = *extract;
@@ -569,16 +579,16 @@ PR_IMPLEMENT(PRFileDesc*) PR_PopIOLayer(PRFileDesc *stack, PRDescIdentity id)
PR_ASSERT(stack->lower->higher == extract);
stack->lower->higher = stack;
}
- } else if ((PR_IO_LAYER_HEAD == stack->identity) &&
- (extract == stack->lower) && (extract->lower == NULL)) {
- /*
- * new style stack
- * popping the only layer in the stack; delete the stack too
- */
- stack->lower = NULL;
- _PR_DestroyIOLayer(stack);
- } else {
- /* for both kinds of stacks */
+ } else if ((PR_IO_LAYER_HEAD == stack->identity) &&
+ (extract == stack->lower) && (extract->lower == NULL)) {
+ /*
+ * new style stack
+ * popping the only layer in the stack; delete the stack too
+ */
+ stack->lower = NULL;
+ _PR_DestroyIOLayer(stack);
+ } else {
+ /* for both kinds of stacks */
extract->lower->higher = extract->higher;
extract->higher->lower = extract->lower;
}
@@ -602,7 +612,9 @@ PR_IMPLEMENT(PRDescIdentity) PR_GetUniqueIdentity(const char *layer_name)
PRDescIdentity identity, length;
char **names = NULL, *name = NULL, **old = NULL;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
PR_ASSERT((PRDescIdentity)0x7fff > identity_cache.ident);
@@ -634,7 +646,9 @@ retry:
names = (char**)PR_CALLOC(length * sizeof(char*));
if (NULL == names)
{
- if (NULL != name) PR_DELETE(name);
+ if (NULL != name) {
+ PR_DELETE(name);
+ }
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
return PR_INVALID_IO_LAYER;
}
@@ -664,7 +678,9 @@ retry:
else
{
PR_Unlock(identity_cache.ml);
- if (NULL != names) PR_DELETE(names);
+ if (NULL != names) {
+ PR_DELETE(names);
+ }
goto retry;
}
}
@@ -676,8 +692,12 @@ retry:
PR_ASSERT(identity_cache.ident < identity_cache.length);
PR_Unlock(identity_cache.ml);
- if (NULL != old) PR_DELETE(old);
- if (NULL != names) PR_DELETE(names);
+ if (NULL != old) {
+ PR_DELETE(old);
+ }
+ if (NULL != names) {
+ PR_DELETE(names);
+ }
return identity;
} /* PR_GetUniqueIdentity */
@@ -685,13 +705,15 @@ retry:
PR_IMPLEMENT(const char*) PR_GetNameForIdentity(PRDescIdentity ident)
{
const char *rv = NULL;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
if ((PR_TOP_IO_LAYER != ident) && (ident >= 0)) {
- PR_Lock(identity_cache.ml);
- PR_ASSERT(ident <= identity_cache.ident);
- rv = (ident > identity_cache.ident) ? NULL : identity_cache.name[ident];
- PR_Unlock(identity_cache.ml);
+ PR_Lock(identity_cache.ml);
+ PR_ASSERT(ident <= identity_cache.ident);
+ rv = (ident > identity_cache.ident) ? NULL : identity_cache.name[ident];
+ PR_Unlock(identity_cache.ml);
}
return rv;
@@ -701,9 +723,9 @@ PR_IMPLEMENT(PRDescIdentity) PR_GetLayersIdentity(PRFileDesc* fd)
{
PR_ASSERT(NULL != fd);
if (PR_IO_LAYER_HEAD == fd->identity) {
- PR_ASSERT(NULL != fd->lower);
- return fd->lower->identity;
- }
+ PR_ASSERT(NULL != fd->lower);
+ return fd->lower->identity;
+ }
return fd->identity;
} /* PR_GetLayersIdentity */
@@ -712,19 +734,23 @@ PR_IMPLEMENT(PRFileDesc*) PR_GetIdentitiesLayer(PRFileDesc* fd, PRDescIdentity i
PRFileDesc *layer = fd;
if (PR_TOP_IO_LAYER == id) {
- if (PR_IO_LAYER_HEAD == fd->identity) {
- return fd->lower;
- }
- return fd;
- }
+ if (PR_IO_LAYER_HEAD == fd->identity) {
+ return fd->lower;
+ }
+ return fd;
+ }
for (layer = fd; layer != NULL; layer = layer->lower)
{
- if (id == layer->identity) return layer;
+ if (id == layer->identity) {
+ return layer;
+ }
}
for (layer = fd; layer != NULL; layer = layer->higher)
{
- if (id == layer->identity) return layer;
+ if (id == layer->identity) {
+ return layer;
+ }
}
return NULL;
} /* PR_GetIdentitiesLayer */
@@ -748,8 +774,9 @@ void _PR_CleanupLayerCache(void)
{
PRDescIdentity ident;
- for (ident = 0; ident <= identity_cache.ident; ident++)
+ for (ident = 0; ident <= identity_cache.ident; ident++) {
PR_DELETE(identity_cache.name[ident]);
+ }
PR_DELETE(identity_cache.name);
}
diff --git a/nsprpub/pr/src/io/prlog.c b/nsprpub/pr/src/io/prlog.c
index 6098460ed..52bd6abc5 100644
--- a/nsprpub/pr/src/io/prlog.c
+++ b/nsprpub/pr/src/io/prlog.c
@@ -166,8 +166,9 @@ PRIntn strcasecmp(const char *a, const char *b)
const unsigned char *ua = (const unsigned char *)a;
const unsigned char *ub = (const unsigned char *)b;
- if( ((const char *)0 == a) || (const char *)0 == b )
+ if( ((const char *)0 == a) || (const char *)0 == b ) {
return (PRIntn)(a-b);
+ }
while( (uc[*ua] == uc[*ub]) && ('\0' != *a) )
{
@@ -201,7 +202,9 @@ void _PR_InitLog(void)
count = sscanf(&ev[pos], "%63[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-]%n:%d%n",
module, &delta, &level, &delta);
pos += delta;
- if (count == 0) break;
+ if (count == 0) {
+ break;
+ }
/*
** If count == 2, then we got module and level. If count
@@ -223,7 +226,9 @@ void _PR_InitLog(void)
(0 == strcasecmp (module, "all")) ? PR_TRUE : PR_FALSE;
while (lm != NULL) {
- if (skip_modcheck) lm -> level = (PRLogModuleLevel)level;
+ if (skip_modcheck) {
+ lm -> level = (PRLogModuleLevel)level;
+ }
else if (strcasecmp(module, lm->name) == 0) {
lm->level = (PRLogModuleLevel)level;
break;
@@ -234,7 +239,9 @@ void _PR_InitLog(void)
/*found:*/
count = sscanf(&ev[pos], " , %n", &delta);
pos += delta;
- if (count == EOF) break;
+ if (count == EOF) {
+ break;
+ }
}
PR_SetLogBuffering(isSync ? 0 : bufSize);
@@ -274,7 +281,7 @@ void _PR_LogCleanup(void)
#ifdef XP_PC
&& logFile != WIN32_DEBUG_FILE
#endif
- ) {
+ ) {
fclose(logFile);
}
#else
@@ -284,8 +291,9 @@ void _PR_LogCleanup(void)
#endif
logFile = NULL;
- if (logBuf)
+ if (logBuf) {
PR_DELETE(logBuf);
+ }
while (lm != NULL) {
PRLogModuleInfo *next = lm->next;
@@ -318,7 +326,9 @@ static void _PR_SetLogModuleLevel( PRLogModuleInfo *lm )
count = sscanf(&ev[pos], "%63[ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-]%n:%d%n",
module, &delta, &level, &delta);
pos += delta;
- if (count == 0) break;
+ if (count == 0) {
+ break;
+ }
/*
** If count == 2, then we got module and level. If count
@@ -334,7 +344,9 @@ static void _PR_SetLogModuleLevel( PRLogModuleInfo *lm )
}
count = sscanf(&ev[pos], " , %n", &delta);
pos += delta;
- if (count == EOF) break;
+ if (count == EOF) {
+ break;
+ }
}
}
} /* end _PR_SetLogModuleLevel() */
@@ -343,7 +355,9 @@ PR_IMPLEMENT(PRLogModuleInfo*) PR_NewLogModule(const char *name)
{
PRLogModuleInfo *lm;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
lm = PR_NEWZAP(PRLogModuleInfo);
if (lm) {
@@ -371,8 +385,9 @@ PR_IMPLEMENT(PRBool) PR_SetLogFile(const char *file)
{
const char *mode = appendToLog ? "a" : "w";
newLogFile = fopen(file, mode);
- if (!newLogFile)
+ if (!newLogFile) {
return PR_FALSE;
+ }
#ifndef WINCE /* _IONBF does not exist in the Windows Mobile 6 SDK. */
/* We do buffering ourselves. */
@@ -385,7 +400,7 @@ PR_IMPLEMENT(PRBool) PR_SetLogFile(const char *file)
#ifdef XP_PC
&& logFile != WIN32_DEBUG_FILE
#endif
- ) {
+ ) {
fclose(logFile);
}
logFile = newLogFile;
@@ -414,8 +429,9 @@ PR_IMPLEMENT(void) PR_SetLogBuffering(PRIntn buffer_size)
{
PR_LogFlush();
- if (logBuf)
+ if (logBuf) {
PR_DELETE(logBuf);
+ }
if (buffer_size >= LINE_BUF_SIZE) {
logp = logBuf = (char*) PR_MALLOC(buffer_size);
@@ -432,7 +448,9 @@ PR_IMPLEMENT(void) PR_LogPrint(const char *fmt, ...)
PRThread *me;
PRExplodedTime now;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
if (!logFile) {
return;
@@ -520,10 +538,10 @@ PR_IMPLEMENT(void) PR_LogFlush(void)
{
if (logBuf && logFile) {
_PR_LOCK_LOG();
- if (logp > logBuf) {
- _PUT_LOG(logFile, logBuf, logp - logBuf);
- logp = logBuf;
- }
+ if (logp > logBuf) {
+ _PUT_LOG(logFile, logBuf, logp - logBuf);
+ logp = logBuf;
+ }
_PR_UNLOCK_LOG();
}
}
diff --git a/nsprpub/pr/src/io/prmapopt.c b/nsprpub/pr/src/io/prmapopt.c
index f92a76b2b..b6653e4ba 100644
--- a/nsprpub/pr/src/io/prmapopt.c
+++ b/nsprpub/pr/src/io/prmapopt.c
@@ -62,11 +62,10 @@ PRStatus PR_CALLBACK _PR_SocketGetSocketOption(PRFileDesc *fd, PRSocketOptionDat
{
case PR_SockOpt_Linger:
{
-#if !defined(XP_BEOS) || defined(BONE_VERSION)
struct linger linger;
length = sizeof(linger);
rv = _PR_MD_GETSOCKOPT(
- fd, level, name, (char *) &linger, &length);
+ fd, level, name, (char *) &linger, &length);
if (PR_SUCCESS == rv)
{
PR_ASSERT(sizeof(linger) == length);
@@ -76,10 +75,6 @@ PRStatus PR_CALLBACK _PR_SocketGetSocketOption(PRFileDesc *fd, PRSocketOptionDat
PR_SecondsToInterval(linger.l_linger);
}
break;
-#else
- PR_SetError( PR_NOT_IMPLEMENTED_ERROR, 0 );
- return PR_FAILURE;
-#endif
}
case PR_SockOpt_Reuseaddr:
case PR_SockOpt_Keepalive:
@@ -94,9 +89,10 @@ PRStatus PR_CALLBACK _PR_SocketGetSocketOption(PRFileDesc *fd, PRSocketOptionDat
#endif
length = sizeof(value);
rv = _PR_MD_GETSOCKOPT(
- fd, level, name, (char*)&value, &length);
- if (PR_SUCCESS == rv)
+ fd, level, name, (char*)&value, &length);
+ if (PR_SUCCESS == rv) {
data->value.reuse_addr = (0 == value) ? PR_FALSE : PR_TRUE;
+ }
break;
}
case PR_SockOpt_McastLoopback:
@@ -108,9 +104,10 @@ PRStatus PR_CALLBACK _PR_SocketGetSocketOption(PRFileDesc *fd, PRSocketOptionDat
#endif
length = sizeof(bool);
rv = _PR_MD_GETSOCKOPT(
- fd, level, name, (char*)&bool, &length);
- if (PR_SUCCESS == rv)
+ fd, level, name, (char*)&bool, &length);
+ if (PR_SUCCESS == rv) {
data->value.mcast_loopback = (0 == bool) ? PR_FALSE : PR_TRUE;
+ }
break;
}
case PR_SockOpt_RecvBufferSize:
@@ -120,9 +117,10 @@ PRStatus PR_CALLBACK _PR_SocketGetSocketOption(PRFileDesc *fd, PRSocketOptionDat
PRIntn value;
length = sizeof(value);
rv = _PR_MD_GETSOCKOPT(
- fd, level, name, (char*)&value, &length);
- if (PR_SUCCESS == rv)
+ fd, level, name, (char*)&value, &length);
+ if (PR_SUCCESS == rv) {
data->value.recv_buffer_size = value;
+ }
break;
}
case PR_SockOpt_IpTimeToLive:
@@ -131,7 +129,7 @@ PRStatus PR_CALLBACK _PR_SocketGetSocketOption(PRFileDesc *fd, PRSocketOptionDat
/* These options should really be an int (or PRIntn). */
length = sizeof(PRUintn);
rv = _PR_MD_GETSOCKOPT(
- fd, level, name, (char*)&data->value.ip_ttl, &length);
+ fd, level, name, (char*)&data->value.ip_ttl, &length);
break;
}
case PR_SockOpt_McastTimeToLive:
@@ -143,9 +141,10 @@ PRStatus PR_CALLBACK _PR_SocketGetSocketOption(PRFileDesc *fd, PRSocketOptionDat
#endif
length = sizeof(ttl);
rv = _PR_MD_GETSOCKOPT(
- fd, level, name, (char*)&ttl, &length);
- if (PR_SUCCESS == rv)
+ fd, level, name, (char*)&ttl, &length);
+ if (PR_SUCCESS == rv) {
data->value.mcast_ttl = ttl;
+ }
break;
}
#ifdef IP_ADD_MEMBERSHIP
@@ -155,7 +154,7 @@ PRStatus PR_CALLBACK _PR_SocketGetSocketOption(PRFileDesc *fd, PRSocketOptionDat
struct ip_mreq mreq;
length = sizeof(mreq);
rv = _PR_MD_GETSOCKOPT(
- fd, level, name, (char*)&mreq, &length);
+ fd, level, name, (char*)&mreq, &length);
if (PR_SUCCESS == rv)
{
data->value.add_member.mcaddr.inet.ip =
@@ -171,14 +170,14 @@ PRStatus PR_CALLBACK _PR_SocketGetSocketOption(PRFileDesc *fd, PRSocketOptionDat
/* This option is a struct in_addr. */
length = sizeof(data->value.mcast_if.inet.ip);
rv = _PR_MD_GETSOCKOPT(
- fd, level, name,
- (char*)&data->value.mcast_if.inet.ip, &length);
+ fd, level, name,
+ (char*)&data->value.mcast_if.inet.ip, &length);
break;
}
default:
PR_NOT_REACHED("Unknown socket option");
break;
- }
+ }
}
return rv;
} /* _PR_SocketGetSocketOption */
@@ -196,7 +195,7 @@ PRStatus PR_CALLBACK _PR_SocketSetSocketOption(PRFileDesc *fd, const PRSocketOpt
{
#ifdef WINNT
PR_ASSERT((fd->secret->md.io_model_committed == PR_FALSE)
- || (fd->secret->nonblocking == data->value.non_blocking));
+ || (fd->secret->nonblocking == data->value.non_blocking));
if (fd->secret->md.io_model_committed
&& (fd->secret->nonblocking != data->value.non_blocking))
{
@@ -221,17 +220,12 @@ PRStatus PR_CALLBACK _PR_SocketSetSocketOption(PRFileDesc *fd, const PRSocketOpt
{
case PR_SockOpt_Linger:
{
-#if !defined(XP_BEOS) || defined(BONE_VERSION)
struct linger linger;
linger.l_onoff = data->value.linger.polarity;
linger.l_linger = PR_IntervalToSeconds(data->value.linger.linger);
rv = _PR_MD_SETSOCKOPT(
- fd, level, name, (char*)&linger, sizeof(linger));
+ fd, level, name, (char*)&linger, sizeof(linger));
break;
-#else
- PR_SetError( PR_NOT_IMPLEMENTED_ERROR, 0 );
- return PR_FAILURE;
-#endif
}
case PR_SockOpt_Reuseaddr:
case PR_SockOpt_Keepalive:
@@ -246,7 +240,7 @@ PRStatus PR_CALLBACK _PR_SocketSetSocketOption(PRFileDesc *fd, const PRSocketOpt
#endif
value = (data->value.reuse_addr) ? 1 : 0;
rv = _PR_MD_SETSOCKOPT(
- fd, level, name, (char*)&value, sizeof(value));
+ fd, level, name, (char*)&value, sizeof(value));
break;
}
case PR_SockOpt_McastLoopback:
@@ -258,7 +252,7 @@ PRStatus PR_CALLBACK _PR_SocketSetSocketOption(PRFileDesc *fd, const PRSocketOpt
#endif
bool = data->value.mcast_loopback ? 1 : 0;
rv = _PR_MD_SETSOCKOPT(
- fd, level, name, (char*)&bool, sizeof(bool));
+ fd, level, name, (char*)&bool, sizeof(bool));
break;
}
case PR_SockOpt_RecvBufferSize:
@@ -267,7 +261,7 @@ PRStatus PR_CALLBACK _PR_SocketSetSocketOption(PRFileDesc *fd, const PRSocketOpt
{
PRIntn value = data->value.recv_buffer_size;
rv = _PR_MD_SETSOCKOPT(
- fd, level, name, (char*)&value, sizeof(value));
+ fd, level, name, (char*)&value, sizeof(value));
break;
}
case PR_SockOpt_IpTimeToLive:
@@ -275,7 +269,7 @@ PRStatus PR_CALLBACK _PR_SocketSetSocketOption(PRFileDesc *fd, const PRSocketOpt
{
/* These options should really be an int (or PRIntn). */
rv = _PR_MD_SETSOCKOPT(
- fd, level, name, (char*)&data->value.ip_ttl, sizeof(PRUintn));
+ fd, level, name, (char*)&data->value.ip_ttl, sizeof(PRUintn));
break;
}
case PR_SockOpt_McastTimeToLive:
@@ -287,7 +281,7 @@ PRStatus PR_CALLBACK _PR_SocketSetSocketOption(PRFileDesc *fd, const PRSocketOpt
#endif
ttl = data->value.mcast_ttl;
rv = _PR_MD_SETSOCKOPT(
- fd, level, name, (char*)&ttl, sizeof(ttl));
+ fd, level, name, (char*)&ttl, sizeof(ttl));
break;
}
#ifdef IP_ADD_MEMBERSHIP
@@ -300,7 +294,7 @@ PRStatus PR_CALLBACK _PR_SocketSetSocketOption(PRFileDesc *fd, const PRSocketOpt
mreq.imr_interface.s_addr =
data->value.add_member.ifaddr.inet.ip;
rv = _PR_MD_SETSOCKOPT(
- fd, level, name, (char*)&mreq, sizeof(mreq));
+ fd, level, name, (char*)&mreq, sizeof(mreq));
break;
}
#endif /* IP_ADD_MEMBERSHIP */
@@ -308,14 +302,14 @@ PRStatus PR_CALLBACK _PR_SocketSetSocketOption(PRFileDesc *fd, const PRSocketOpt
{
/* This option is a struct in_addr. */
rv = _PR_MD_SETSOCKOPT(
- fd, level, name, (char*)&data->value.mcast_if.inet.ip,
- sizeof(data->value.mcast_if.inet.ip));
+ fd, level, name, (char*)&data->value.mcast_if.inet.ip,
+ sizeof(data->value.mcast_if.inet.ip));
break;
}
default:
PR_NOT_REACHED("Unknown socket option");
break;
- }
+ }
}
return rv;
} /* _PR_SocketSetSocketOption */
@@ -441,7 +435,7 @@ PRStatus _PR_MapOptionName(
};
if ((optname < PR_SockOpt_Linger)
- || (optname >= PR_SockOpt_Last))
+ || (optname >= PR_SockOpt_Last))
{
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return PR_FAILURE;
diff --git a/nsprpub/pr/src/io/prmmap.c b/nsprpub/pr/src/io/prmmap.c
index 64f7ed4e8..b0adf8867 100644
--- a/nsprpub/pr/src/io/prmmap.c
+++ b/nsprpub/pr/src/io/prmmap.c
@@ -21,19 +21,19 @@ PR_IMPLEMENT(PRFileMap *) PR_CreateFileMap(
PRFileMap *fmap;
PR_ASSERT(prot == PR_PROT_READONLY || prot == PR_PROT_READWRITE
- || prot == PR_PROT_WRITECOPY);
+ || prot == PR_PROT_WRITECOPY);
fmap = PR_NEWZAP(PRFileMap);
if (NULL == fmap) {
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
- return NULL;
+ PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+ return NULL;
}
fmap->fd = fd;
fmap->prot = prot;
if (_PR_MD_CREATE_FILE_MAP(fmap, size) == PR_SUCCESS) {
- return fmap;
+ return fmap;
}
- PR_DELETE(fmap);
- return NULL;
+ PR_DELETE(fmap);
+ return NULL;
}
PR_IMPLEMENT(PRInt32) PR_GetMemMapAlignment(void)
@@ -64,5 +64,5 @@ PR_IMPLEMENT(PRStatus) PR_SyncMemMap(
void *addr,
PRUint32 len)
{
- return _PR_MD_SYNC_MEM_MAP(fd, addr, len);
+ return _PR_MD_SYNC_MEM_MAP(fd, addr, len);
}
diff --git a/nsprpub/pr/src/io/prmwait.c b/nsprpub/pr/src/io/prmwait.c
index ab32fb5d8..62e35ab6f 100644
--- a/nsprpub/pr/src/io/prmwait.c
+++ b/nsprpub/pr/src/io/prmwait.c
@@ -37,7 +37,7 @@ struct {
static PRStatus TimerInit(void);
static void TimerManager(void *arg);
static TimerEvent *CreateTimer(PRIntervalTime timeout,
- void (*func)(void *), void *arg);
+ void (*func)(void *), void *arg);
static PRBool CancelTimer(TimerEvent *timer);
static void TimerManager(void *arg)
@@ -81,7 +81,7 @@ static void TimerManager(void *arg)
{
timeout = (PRIntervalTime)(timer->absolute - now);
PR_WaitCondVar(tm_vars.new_timer, timeout);
- }
+ }
}
}
PR_Unlock(tm_vars.ml);
@@ -143,7 +143,7 @@ static PRBool CancelTimer(TimerEvent *timer)
}
PR_Unlock(tm_vars.ml);
PR_DELETE(timer);
- return canceled;
+ return canceled;
}
static PRStatus TimerInit(void)
@@ -165,8 +165,8 @@ static PRStatus TimerInit(void)
}
PR_INIT_CLIST(&tm_vars.timer_queue);
tm_vars.manager_thread = PR_CreateThread(
- PR_SYSTEM_THREAD, TimerManager, NULL, PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD, PR_UNJOINABLE_THREAD, 0);
+ PR_SYSTEM_THREAD, TimerManager, NULL, PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD, PR_UNJOINABLE_THREAD, 0);
if (NULL == tm_vars.manager_thread)
{
goto failed;
@@ -231,7 +231,9 @@ static PRWaitGroup *MW_Init2(void)
if (NULL == group) /* there is this special case */
{
group = PR_CreateWaitGroup(_PR_DEFAULT_HASH_LENGTH);
- if (NULL == group) goto failed_alloc;
+ if (NULL == group) {
+ goto failed_alloc;
+ }
PR_Lock(mw_lock);
if (NULL == mw_state->group)
{
@@ -239,7 +241,9 @@ static PRWaitGroup *MW_Init2(void)
group = NULL;
}
PR_Unlock(mw_lock);
- if (group != NULL) (void)PR_DestroyWaitGroup(group);
+ if (group != NULL) {
+ (void)PR_DestroyWaitGroup(group);
+ }
group = mw_state->group; /* somebody beat us to it */
}
failed_alloc:
@@ -301,7 +305,7 @@ static _PR_HashStory MW_AddHashInternal(PRRecvWait *desc, _PRWaiterHash *hash)
}
hidx = (hidx + hoffset) % (hash->length);
}
- return _prmw_rehash;
+ return _prmw_rehash;
} /* MW_AddHashInternal */
static _PR_HashStory MW_ExpandHashInternal(PRWaitGroup *group)
@@ -314,7 +318,8 @@ static _PR_HashStory MW_ExpandHashInternal(PRWaitGroup *group)
static const PRInt32 prime_number[] = {
_PR_DEFAULT_HASH_LENGTH, 179, 521, 907, 1427,
- 2711, 3917, 5021, 8219, 11549, 18911, 26711, 33749, 44771};
+ 2711, 3917, 5021, 8219, 11549, 18911, 26711, 33749, 44771
+ };
PRUintn primes = (sizeof(prime_number) / sizeof(PRInt32));
/* look up the next size we'd like to use for the hash table */
@@ -337,7 +342,7 @@ static _PR_HashStory MW_ExpandHashInternal(PRWaitGroup *group)
/* allocate the new hash table and fill it in with the old */
newHash = (_PRWaiterHash*)PR_CALLOC(
- sizeof(_PRWaiterHash) + (length * sizeof(PRRecvWait*)));
+ sizeof(_PRWaiterHash) + (length * sizeof(PRRecvWait*)));
if (NULL == newHash)
{
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
@@ -347,7 +352,7 @@ static _PR_HashStory MW_ExpandHashInternal(PRWaitGroup *group)
newHash->length = length;
retry = PR_FALSE;
for (desc = &oldHash->recv_wait;
- newHash->count < oldHash->count; ++desc)
+ newHash->count < oldHash->count; ++desc)
{
PR_ASSERT(desc < &oldHash->recv_wait + oldHash->length);
if (NULL != *desc)
@@ -362,7 +367,9 @@ static _PR_HashStory MW_ExpandHashInternal(PRWaitGroup *group)
}
}
}
- if (retry) continue;
+ if (retry) {
+ continue;
+ }
PR_DELETE(group->waiter);
group->waiter = newHash;
@@ -408,11 +415,13 @@ static PRRecvWait **_MW_LookupInternal(PRWaitGroup *group, PRFileDesc *fd)
_PRWaiterHash *hash = group->waiter;
PRUintn hidx = _MW_HASH(fd, hash->length);
PRUintn hoffset = 0;
-
+
while (rehash-- > 0)
{
desc = (&hash->recv_wait) + hidx;
- if ((*desc != NULL) && ((*desc)->fd == fd)) return desc;
+ if ((*desc != NULL) && ((*desc)->fd == fd)) {
+ return desc;
+ }
if (0 == hoffset)
{
hoffset = _MW_HASH2(fd, hash->length);
@@ -447,7 +456,9 @@ static PRStatus _MW_PollInternal(PRWaitGroup *group)
PR_SetError(PR_INVALID_STATE_ERROR, 0);
goto aborted;
}
- if (_MW_ABORTED(st)) goto aborted;
+ if (_MW_ABORTED(st)) {
+ goto aborted;
+ }
}
/*
@@ -470,8 +481,9 @@ static PRStatus _MW_PollInternal(PRWaitGroup *group)
PR_Lock(group->ml);
goto failed_alloc;
}
- if (NULL != old_polling_list)
+ if (NULL != old_polling_list) {
PR_DELETE(old_polling_list);
+ }
PR_Lock(group->ml);
if (_prmw_running != group->state)
{
@@ -492,22 +504,24 @@ static PRStatus _MW_PollInternal(PRWaitGroup *group)
for (count = 0; count < group->waiter->count; ++waiter)
{
PR_ASSERT(waiter < &group->waiter->recv_wait
- + group->waiter->length);
+ + group->waiter->length);
if (NULL != *waiter) /* a live one! */
{
if ((PR_INTERVAL_NO_TIMEOUT != (*waiter)->timeout)
- && (since_last_poll >= (*waiter)->timeout))
+ && (since_last_poll >= (*waiter)->timeout)) {
_MW_DoneInternal(group, waiter, PR_MW_TIMEOUT);
+ }
else
{
if (PR_INTERVAL_NO_TIMEOUT != (*waiter)->timeout)
{
(*waiter)->timeout -= since_last_poll;
- if ((*waiter)->timeout < polling_interval)
+ if ((*waiter)->timeout < polling_interval) {
polling_interval = (*waiter)->timeout;
+ }
}
PR_ASSERT(poll_list < group->polling_list
- + group->polling_count);
+ + group->polling_count);
poll_list->fd = (*waiter)->fd;
poll_list->in_flags = PR_POLL_READ;
poll_list->out_flags = 0;
@@ -520,7 +534,7 @@ static PRStatus _MW_PollInternal(PRWaitGroup *group)
count += 1;
}
}
- }
+ }
PR_ASSERT(count == group->waiter->count);
@@ -529,9 +543,13 @@ static PRStatus _MW_PollInternal(PRWaitGroup *group)
** we need to return.
*/
if ((!PR_CLIST_IS_EMPTY(&group->io_ready))
- && (1 == group->waiting_threads)) break;
+ && (1 == group->waiting_threads)) {
+ break;
+ }
- if (0 == count) continue; /* wait for new business */
+ if (0 == count) {
+ continue; /* wait for new business */
+ }
group->last_poll = now;
@@ -553,7 +571,7 @@ static PRStatus _MW_PollInternal(PRWaitGroup *group)
else if (0 < count_ready)
{
for (poll_list = group->polling_list; count > 0;
- poll_list++, count--)
+ poll_list++, count--)
{
PR_ASSERT(
poll_list < group->polling_list + group->polling_count);
@@ -564,8 +582,9 @@ static PRStatus _MW_PollInternal(PRWaitGroup *group)
** If 'waiter' is NULL, that means the wait receive
** descriptor has been canceled.
*/
- if (NULL != waiter)
+ if (NULL != waiter) {
_MW_DoneInternal(group, waiter, PR_MW_SUCCESS);
+ }
}
}
}
@@ -576,7 +595,9 @@ static PRStatus _MW_PollInternal(PRWaitGroup *group)
** belongs to the client.
*/
if ((!PR_CLIST_IS_EMPTY(&group->io_ready))
- && (1 == group->waiting_threads)) break;
+ && (1 == group->waiting_threads)) {
+ break;
+ }
}
rv = PR_SUCCESS;
@@ -604,7 +625,7 @@ static PRMWGroupState MW_TestForShutdownInternal(PRWaitGroup *group)
** to make sure no more threads are made to wait.
*/
if ((_prmw_stopping == rv)
- && (0 == group->waiting_threads))
+ && (0 == group->waiting_threads))
{
rv = group->state = _prmw_stopped;
PR_NotifyCondVar(group->mw_manage);
@@ -617,15 +638,17 @@ static void _MW_InitialRecv(PRCList *io_ready)
{
PRRecvWait *desc = (PRRecvWait*)io_ready;
if ((NULL == desc->buffer.start)
- || (0 == desc->buffer.length))
+ || (0 == desc->buffer.length)) {
desc->bytesRecv = 0;
+ }
else
{
desc->bytesRecv = (desc->fd->methods->recv)(
- desc->fd, desc->buffer.start,
- desc->buffer.length, 0, desc->timeout);
- if (desc->bytesRecv < 0) /* SetError should already be there */
+ desc->fd, desc->buffer.start,
+ desc->buffer.length, 0, desc->timeout);
+ if (desc->bytesRecv < 0) { /* SetError should already be there */
desc->outcome = PR_MW_FAILURE;
+ }
}
} /* _MW_InitialRecv */
#endif
@@ -636,9 +659,9 @@ static void NT_TimeProc(void *arg)
_MDOverlapped *overlapped = (_MDOverlapped *)arg;
PRRecvWait *desc = overlapped->data.mw.desc;
PRFileDesc *bottom;
-
+
if (InterlockedCompareExchange((LONG *)&desc->outcome,
- (LONG)PR_MW_TIMEOUT, (LONG)PR_MW_PENDING) != (LONG)PR_MW_PENDING)
+ (LONG)PR_MW_TIMEOUT, (LONG)PR_MW_PENDING) != (LONG)PR_MW_PENDING)
{
/* This wait recv descriptor has already completed. */
return;
@@ -712,7 +735,9 @@ PR_IMPLEMENT(PRStatus) PR_AddWaitFileDesc(
PRFileDesc *bottom;
#endif
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
if ((NULL == group) && (NULL == (group = MW_Init2())))
{
return rv;
@@ -744,15 +769,20 @@ PR_IMPLEMENT(PRStatus) PR_AddWaitFileDesc(
** of the timing interval. As long as the list doesn't go empty,
** it will maintain itself.
*/
- if (0 == group->waiter->count)
+ if (0 == group->waiter->count) {
group->last_poll = PR_IntervalNow();
+ }
do
{
hrv = MW_AddHashInternal(desc, group->waiter);
- if (_prmw_rehash != hrv) break;
+ if (_prmw_rehash != hrv) {
+ break;
+ }
hrv = MW_ExpandHashInternal(group); /* gruesome */
- if (_prmw_success != hrv) break;
+ if (_prmw_success != hrv) {
+ break;
+ }
} while (PR_TRUE);
#ifdef WINNT
@@ -777,9 +807,9 @@ PR_IMPLEMENT(PRStatus) PR_AddWaitFileDesc(
if (desc->timeout != PR_INTERVAL_NO_TIMEOUT)
{
overlapped->data.mw.timer = CreateTimer(
- desc->timeout,
- NT_TimeProc,
- overlapped);
+ desc->timeout,
+ NT_TimeProc,
+ overlapped);
if (0 == overlapped->data.mw.timer)
{
NT_HashRemove(group, desc->fd);
@@ -801,7 +831,7 @@ PR_IMPLEMENT(PRStatus) PR_AddWaitFileDesc(
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return PR_FAILURE;
}
- hFile = (HANDLE)bottom->secret->md.osfd;
+ hFile = (HANDLE)bottom->secret->md.osfd;
if (!bottom->secret->md.io_model_committed)
{
PRInt32 st;
@@ -810,16 +840,16 @@ PR_IMPLEMENT(PRStatus) PR_AddWaitFileDesc(
bottom->secret->md.io_model_committed = PR_TRUE;
}
bResult = ReadFile(hFile,
- desc->buffer.start,
- (DWORD)desc->buffer.length,
- NULL,
- &overlapped->overlapped);
+ desc->buffer.start,
+ (DWORD)desc->buffer.length,
+ NULL,
+ &overlapped->overlapped);
if (FALSE == bResult && (dwError = GetLastError()) != ERROR_IO_PENDING)
{
if (desc->timeout != PR_INTERVAL_NO_TIMEOUT)
{
if (InterlockedCompareExchange((LONG *)&desc->outcome,
- (LONG)PR_MW_FAILURE, (LONG)PR_MW_PENDING)
+ (LONG)PR_MW_FAILURE, (LONG)PR_MW_PENDING)
== (LONG)PR_MW_PENDING)
{
CancelTimer(overlapped->data.mw.timer);
@@ -840,11 +870,15 @@ PR_IMPLEMENT(PRRecvWait*) PR_WaitRecvReady(PRWaitGroup *group)
PRCList *io_ready = NULL;
#ifdef WINNT
PRThread *me = _PR_MD_CURRENT_THREAD();
- _MDOverlapped *overlapped;
+ _MDOverlapped *overlapped;
#endif
- if (!_pr_initialized) _PR_ImplicitInitialization();
- if ((NULL == group) && (NULL == (group = MW_Init2()))) goto failed_init;
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
+ if ((NULL == group) && (NULL == (group = MW_Init2()))) {
+ goto failed_init;
+ }
PR_Lock(group->ml);
@@ -890,7 +924,7 @@ PR_IMPLEMENT(PRRecvWait*) PR_WaitRecvReady(PRWaitGroup *group)
PR_REMOVE_LINK(io_ready);
_PR_MD_UNLOCK(&group->mdlock);
overlapped = (_MDOverlapped *)
- ((char *)io_ready - offsetof(_MDOverlapped, data));
+ ((char *)io_ready - offsetof(_MDOverlapped, data));
io_ready = &overlapped->data.mw.desc->internal;
#else
do
@@ -915,7 +949,9 @@ PR_IMPLEMENT(PRRecvWait*) PR_WaitRecvReady(PRWaitGroup *group)
** The polling function should only return w/ failure or
** with some I/O ready.
*/
- if (PR_FAILURE == _MW_PollInternal(group)) goto failed_poll;
+ if (PR_FAILURE == _MW_PollInternal(group)) {
+ goto failed_poll;
+ }
}
else
{
@@ -934,7 +970,7 @@ PR_IMPLEMENT(PRRecvWait*) PR_WaitRecvReady(PRWaitGroup *group)
** it is still full of if's with continue and goto.
*/
PRStatus st;
- do
+ do
{
st = PR_WaitCondVar(group->io_complete, PR_INTERVAL_NO_TIMEOUT);
if (_prmw_running != group->state)
@@ -942,7 +978,9 @@ PR_IMPLEMENT(PRRecvWait*) PR_WaitRecvReady(PRWaitGroup *group)
PR_SetError(PR_INVALID_STATE_ERROR, 0);
goto aborted;
}
- if (_MW_ABORTED(st) || (NULL == group->poller)) break;
+ if (_MW_ABORTED(st) || (NULL == group->poller)) {
+ break;
+ }
} while (PR_CLIST_IS_EMPTY(&group->io_ready));
/*
@@ -954,9 +992,10 @@ PR_IMPLEMENT(PRRecvWait*) PR_WaitRecvReady(PRWaitGroup *group)
if (_MW_ABORTED(st))
{
if ((NULL == group->poller
- || !PR_CLIST_IS_EMPTY(&group->io_ready))
- && group->waiting_threads > 1)
+ || !PR_CLIST_IS_EMPTY(&group->io_ready))
+ && group->waiting_threads > 1) {
PR_NotifyCondVar(group->io_complete);
+ }
goto aborted;
}
@@ -966,13 +1005,15 @@ PR_IMPLEMENT(PRRecvWait*) PR_WaitRecvReady(PRWaitGroup *group)
** i/o ready, it has a higher priority. I want to
** process the ready i/o first and wake up another
** thread to be the new poller.
- */
+ */
if (NULL == group->poller)
{
- if (PR_CLIST_IS_EMPTY(&group->io_ready))
+ if (PR_CLIST_IS_EMPTY(&group->io_ready)) {
continue;
- if (group->waiting_threads > 1)
+ }
+ if (group->waiting_threads > 1) {
PR_NotifyCondVar(group->io_complete);
+ }
}
}
PR_ASSERT(!PR_CLIST_IS_EMPTY(&group->io_ready));
@@ -1025,13 +1066,13 @@ failed_init:
if (NULL != overlapped->data.mw.timer)
{
PR_ASSERT(PR_INTERVAL_NO_TIMEOUT
- != overlapped->data.mw.desc->timeout);
+ != overlapped->data.mw.desc->timeout);
CancelTimer(overlapped->data.mw.timer);
}
else
{
PR_ASSERT(PR_INTERVAL_NO_TIMEOUT
- == overlapped->data.mw.desc->timeout);
+ == overlapped->data.mw.desc->timeout);
}
PR_DELETE(overlapped);
#endif
@@ -1045,7 +1086,9 @@ PR_IMPLEMENT(PRStatus) PR_CancelWaitFileDesc(PRWaitGroup *group, PRRecvWait *des
PRRecvWait **recv_wait;
#endif
PRStatus rv = PR_SUCCESS;
- if (NULL == group) group = mw_state->group;
+ if (NULL == group) {
+ group = mw_state->group;
+ }
PR_ASSERT(NULL != group);
if (NULL == group)
{
@@ -1064,7 +1107,7 @@ PR_IMPLEMENT(PRStatus) PR_CancelWaitFileDesc(PRWaitGroup *group, PRRecvWait *des
#ifdef WINNT
if (InterlockedCompareExchange((LONG *)&desc->outcome,
- (LONG)PR_MW_INTERRUPT, (LONG)PR_MW_PENDING) == (LONG)PR_MW_PENDING)
+ (LONG)PR_MW_INTERRUPT, (LONG)PR_MW_PENDING) == (LONG)PR_MW_PENDING)
{
PRFileDesc *bottom = PR_GetIdentitiesLayer(desc->fd, PR_NSPR_IO_LAYER);
PR_ASSERT(NULL != bottom);
@@ -1097,7 +1140,9 @@ PR_IMPLEMENT(PRStatus) PR_CancelWaitFileDesc(PRWaitGroup *group, PRRecvWait *des
do
{
PRRecvWait *done = (PRRecvWait*)head;
- if (done == desc) goto unlock;
+ if (done == desc) {
+ goto unlock;
+ }
head = PR_NEXT_LINK(head);
} while (head != &group->io_ready);
}
@@ -1120,7 +1165,9 @@ PR_IMPLEMENT(PRRecvWait*) PR_CancelWaitGroup(PRWaitGroup *group)
PRThread *me = _PR_MD_CURRENT_THREAD();
#endif
- if (NULL == group) group = mw_state->group;
+ if (NULL == group) {
+ group = mw_state->group;
+ }
PR_ASSERT(NULL != group);
if (NULL == group)
{
@@ -1131,17 +1178,20 @@ PR_IMPLEMENT(PRRecvWait*) PR_CancelWaitGroup(PRWaitGroup *group)
PR_Lock(group->ml);
if (_prmw_stopped != group->state)
{
- if (_prmw_running == group->state)
- group->state = _prmw_stopping; /* so nothing new comes in */
- if (0 == group->waiting_threads) /* is there anybody else? */
- group->state = _prmw_stopped; /* we can stop right now */
+ if (_prmw_running == group->state) {
+ group->state = _prmw_stopping; /* so nothing new comes in */
+ }
+ if (0 == group->waiting_threads) { /* is there anybody else? */
+ group->state = _prmw_stopped; /* we can stop right now */
+ }
else
{
PR_NotifyAllCondVar(group->new_business);
PR_NotifyAllCondVar(group->io_complete);
}
- while (_prmw_stopped != group->state)
+ while (_prmw_stopped != group->state) {
(void)PR_WaitCondVar(group->mw_manage, PR_INTERVAL_NO_TIMEOUT);
+ }
}
#ifdef WINNT
@@ -1155,11 +1205,11 @@ PR_IMPLEMENT(PRRecvWait*) PR_CancelWaitGroup(PRWaitGroup *group)
if (NULL != *desc)
{
if (InterlockedCompareExchange((LONG *)&(*desc)->outcome,
- (LONG)PR_MW_INTERRUPT, (LONG)PR_MW_PENDING)
+ (LONG)PR_MW_INTERRUPT, (LONG)PR_MW_PENDING)
== (LONG)PR_MW_PENDING)
{
PRFileDesc *bottom = PR_GetIdentitiesLayer(
- (*desc)->fd, PR_NSPR_IO_LAYER);
+ (*desc)->fd, PR_NSPR_IO_LAYER);
PR_ASSERT(NULL != bottom);
if (NULL == bottom)
{
@@ -1173,7 +1223,7 @@ PR_IMPLEMENT(PRRecvWait*) PR_CancelWaitGroup(PRWaitGroup *group)
if (closesocket(bottom->secret->md.osfd) == SOCKET_ERROR)
{
fprintf(stderr, "closesocket failed: %d\n",
- WSAGetLastError());
+ WSAGetLastError());
exit(1);
}
}
@@ -1202,32 +1252,34 @@ PR_IMPLEMENT(PRRecvWait*) PR_CancelWaitGroup(PRWaitGroup *group)
for (desc = &group->waiter->recv_wait; group->waiter->count > 0; ++desc)
{
PR_ASSERT(desc < &group->waiter->recv_wait + group->waiter->length);
- if (NULL != *desc)
+ if (NULL != *desc) {
_MW_DoneInternal(group, desc, PR_MW_INTERRUPT);
+ }
}
#endif
/* take first element of finished list and return it or NULL */
- if (PR_CLIST_IS_EMPTY(&group->io_ready))
+ if (PR_CLIST_IS_EMPTY(&group->io_ready)) {
PR_SetError(PR_GROUP_EMPTY_ERROR, 0);
+ }
else
{
PRCList *head = PR_LIST_HEAD(&group->io_ready);
PR_REMOVE_AND_INIT_LINK(head);
#ifdef WINNT
overlapped = (_MDOverlapped *)
- ((char *)head - offsetof(_MDOverlapped, data));
+ ((char *)head - offsetof(_MDOverlapped, data));
head = &overlapped->data.mw.desc->internal;
if (NULL != overlapped->data.mw.timer)
{
PR_ASSERT(PR_INTERVAL_NO_TIMEOUT
- != overlapped->data.mw.desc->timeout);
+ != overlapped->data.mw.desc->timeout);
CancelTimer(overlapped->data.mw.timer);
}
else
{
PR_ASSERT(PR_INTERVAL_NO_TIMEOUT
- == overlapped->data.mw.desc->timeout);
+ == overlapped->data.mw.desc->timeout);
}
PR_DELETE(overlapped);
#endif
@@ -1253,23 +1305,33 @@ PR_IMPLEMENT(PRWaitGroup*) PR_CreateWaitGroup(PRInt32 size /* ignored */)
}
/* the wait group itself */
wg->ml = PR_NewLock();
- if (NULL == wg->ml) goto failed_lock;
+ if (NULL == wg->ml) {
+ goto failed_lock;
+ }
wg->io_taken = PR_NewCondVar(wg->ml);
- if (NULL == wg->io_taken) goto failed_cvar0;
+ if (NULL == wg->io_taken) {
+ goto failed_cvar0;
+ }
wg->io_complete = PR_NewCondVar(wg->ml);
- if (NULL == wg->io_complete) goto failed_cvar1;
+ if (NULL == wg->io_complete) {
+ goto failed_cvar1;
+ }
wg->new_business = PR_NewCondVar(wg->ml);
- if (NULL == wg->new_business) goto failed_cvar2;
+ if (NULL == wg->new_business) {
+ goto failed_cvar2;
+ }
wg->mw_manage = PR_NewCondVar(wg->ml);
- if (NULL == wg->mw_manage) goto failed_cvar3;
+ if (NULL == wg->mw_manage) {
+ goto failed_cvar3;
+ }
PR_INIT_CLIST(&wg->group_link);
PR_INIT_CLIST(&wg->io_ready);
/* the waiters sequence */
wg->waiter = (_PRWaiterHash*)PR_CALLOC(
- sizeof(_PRWaiterHash) +
- (_PR_DEFAULT_HASH_LENGTH * sizeof(PRRecvWait*)));
+ sizeof(_PRWaiterHash) +
+ (_PR_DEFAULT_HASH_LENGTH * sizeof(PRRecvWait*)));
if (NULL == wg->waiter)
{
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
@@ -1309,14 +1371,16 @@ failed:
PR_IMPLEMENT(PRStatus) PR_DestroyWaitGroup(PRWaitGroup *group)
{
PRStatus rv = PR_SUCCESS;
- if (NULL == group) group = mw_state->group;
+ if (NULL == group) {
+ group = mw_state->group;
+ }
PR_ASSERT(NULL != group);
if (NULL != group)
{
PR_Lock(group->ml);
if ((group->waiting_threads == 0)
- && (group->waiter->count == 0)
- && PR_CLIST_IS_EMPTY(&group->io_ready))
+ && (group->waiter->count == 0)
+ && PR_CLIST_IS_EMPTY(&group->io_ready))
{
group->state = _prmw_stopped;
}
@@ -1326,7 +1390,9 @@ PR_IMPLEMENT(PRStatus) PR_DestroyWaitGroup(PRWaitGroup *group)
rv = PR_FAILURE;
}
PR_Unlock(group->ml);
- if (PR_FAILURE == rv) return rv;
+ if (PR_FAILURE == rv) {
+ return rv;
+ }
PR_Lock(mw_lock);
PR_REMOVE_LINK(&group->group_link);
@@ -1347,7 +1413,9 @@ PR_IMPLEMENT(PRStatus) PR_DestroyWaitGroup(PRWaitGroup *group)
PR_DestroyCondVar(group->io_complete);
PR_DestroyCondVar(group->io_taken);
PR_DestroyLock(group->ml);
- if (group == mw_state->group) mw_state->group = NULL;
+ if (group == mw_state->group) {
+ mw_state->group = NULL;
+ }
PR_DELETE(group);
}
else
@@ -1368,7 +1436,9 @@ PR_IMPLEMENT(PRStatus) PR_DestroyWaitGroup(PRWaitGroup *group)
PR_IMPLEMENT(PRMWaitEnumerator*) PR_CreateMWaitEnumerator(PRWaitGroup *group)
{
PRMWaitEnumerator *enumerator = PR_NEWZAP(PRMWaitEnumerator);
- if (NULL == enumerator) PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+ if (NULL == enumerator) {
+ PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+ }
else
{
enumerator->group = group;
@@ -1395,12 +1465,14 @@ PR_IMPLEMENT(PRRecvWait*) PR_EnumerateWaitGroup(
PRMWaitEnumerator *enumerator, const PRRecvWait *previous)
{
PRRecvWait *result = NULL;
-
+
/* entry point sanity checking */
PR_ASSERT(NULL != enumerator);
PR_ASSERT(_PR_ENUM_SEALED == enumerator->seal);
if ((NULL == enumerator)
- || (_PR_ENUM_SEALED != enumerator->seal)) goto bad_argument;
+ || (_PR_ENUM_SEALED != enumerator->seal)) {
+ goto bad_argument;
+ }
/* beginning of enumeration */
if (NULL == previous)
@@ -1424,11 +1496,14 @@ PR_IMPLEMENT(PRRecvWait*) PR_EnumerateWaitGroup(
{
PRThread *me = PR_GetCurrentThread();
PR_ASSERT(me == enumerator->thread);
- if (me != enumerator->thread) goto bad_argument;
+ if (me != enumerator->thread) {
+ goto bad_argument;
+ }
/* need to restart the enumeration */
- if (enumerator->p_timestamp != enumerator->group->p_timestamp)
+ if (enumerator->p_timestamp != enumerator->group->p_timestamp) {
return PR_EnumerateWaitGroup(enumerator, NULL);
+ }
}
/* actually progress the enumeration */
@@ -1439,7 +1514,9 @@ PR_IMPLEMENT(PRRecvWait*) PR_EnumerateWaitGroup(
#endif
while (enumerator->index++ < enumerator->group->waiter->length)
{
- if (NULL != (result = *(enumerator->waiter)++)) break;
+ if (NULL != (result = *(enumerator->waiter)++)) {
+ break;
+ }
}
#if defined(WINNT)
_PR_MD_UNLOCK(&enumerator->group->mdlock);
diff --git a/nsprpub/pr/src/io/prpolevt.c b/nsprpub/pr/src/io/prpolevt.c
index ac3eb101a..1b664ba24 100644
--- a/nsprpub/pr/src/io/prpolevt.c
+++ b/nsprpub/pr/src/io/prpolevt.c
@@ -62,30 +62,30 @@ static PRIOMethods _pr_polevt_methods = {
(PRSeek64FN)_PR_InvalidInt64,
(PRFileInfoFN)_PR_InvalidStatus,
(PRFileInfo64FN)_PR_InvalidStatus,
- (PRWritevFN)_PR_InvalidInt,
- (PRConnectFN)_PR_InvalidStatus,
- (PRAcceptFN)_PR_InvalidDesc,
- (PRBindFN)_PR_InvalidStatus,
- (PRListenFN)_PR_InvalidStatus,
- (PRShutdownFN)_PR_InvalidStatus,
- (PRRecvFN)_PR_InvalidInt,
- (PRSendFN)_PR_InvalidInt,
- (PRRecvfromFN)_PR_InvalidInt,
- (PRSendtoFN)_PR_InvalidInt,
+ (PRWritevFN)_PR_InvalidInt,
+ (PRConnectFN)_PR_InvalidStatus,
+ (PRAcceptFN)_PR_InvalidDesc,
+ (PRBindFN)_PR_InvalidStatus,
+ (PRListenFN)_PR_InvalidStatus,
+ (PRShutdownFN)_PR_InvalidStatus,
+ (PRRecvFN)_PR_InvalidInt,
+ (PRSendFN)_PR_InvalidInt,
+ (PRRecvfromFN)_PR_InvalidInt,
+ (PRSendtoFN)_PR_InvalidInt,
_pr_PolEvtPoll,
- (PRAcceptreadFN)_PR_InvalidInt,
- (PRTransmitfileFN)_PR_InvalidInt,
- (PRGetsocknameFN)_PR_InvalidStatus,
- (PRGetpeernameFN)_PR_InvalidStatus,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
+ (PRAcceptreadFN)_PR_InvalidInt,
+ (PRTransmitfileFN)_PR_InvalidInt,
+ (PRGetsocknameFN)_PR_InvalidStatus,
+ (PRGetpeernameFN)_PR_InvalidStatus,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
(PRGetsocketoptionFN)_PR_InvalidStatus,
(PRSetsocketoptionFN)_PR_InvalidStatus,
- (PRSendfileFN)_PR_InvalidInt,
- (PRConnectcontinueFN)_PR_InvalidStatus,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
+ (PRSendfileFN)_PR_InvalidInt,
+ (PRConnectcontinueFN)_PR_InvalidStatus,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
(PRReservedFN)_PR_InvalidInt
};
@@ -130,7 +130,7 @@ PR_IMPLEMENT(PRFileDesc *) PR_NewPollableEvent(void)
event = PR_CreateIOLayerStub(_pr_polevt_id, &_pr_polevt_methods);
if (NULL == event) {
goto errorExit;
- }
+ }
event->secret = PR_NEW(PRFilePrivate);
if (event->secret == NULL) {
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
@@ -147,9 +147,9 @@ PR_IMPLEMENT(PRFileDesc *) PR_NewPollableEvent(void)
fd[0] = fd[1] = NULL;
goto errorExit;
}
- /*
- * set the TCP_NODELAY option to reduce notification latency
- */
+ /*
+ * set the TCP_NODELAY option to reduce notification latency
+ */
socket_opt.option = PR_SockOpt_NoDelay;
socket_opt.value.no_delay = PR_TRUE;
rv = PR_SetSocketOption(fd[1], &socket_opt);
diff --git a/nsprpub/pr/src/io/prprf.c b/nsprpub/pr/src/io/prprf.c
index 8475c7713..9b6072e26 100644
--- a/nsprpub/pr/src/io/prprf.c
+++ b/nsprpub/pr/src/io/prprf.c
@@ -49,17 +49,17 @@ struct SprintfStateStr {
struct NumArg {
int type; /* type of the numbered argument */
union { /* the numbered argument */
- int i;
- unsigned int ui;
- PRInt32 i32;
- PRUint32 ui32;
- PRInt64 ll;
- PRUint64 ull;
- double d;
- const char *s;
- int *ip;
+ int i;
+ unsigned int ui;
+ PRInt32 i32;
+ PRUint32 ui32;
+ PRInt64 ll;
+ PRUint64 ull;
+ double d;
+ const char *s;
+ int *ip;
#ifdef WIN32
- const WCHAR *ws;
+ const WCHAR *ws;
#endif
} u;
};
@@ -71,63 +71,63 @@ struct NumArg {
** and their corresponding unsigned versions must have the subsequent
** odd value.
*/
-#define TYPE_INT16 0
-#define TYPE_UINT16 1
-#define TYPE_INTN 2
-#define TYPE_UINTN 3
-#define TYPE_INT32 4
-#define TYPE_UINT32 5
-#define TYPE_INT64 6
-#define TYPE_UINT64 7
-#define TYPE_STRING 8
-#define TYPE_DOUBLE 9
-#define TYPE_INTSTR 10
+#define TYPE_INT16 0
+#define TYPE_UINT16 1
+#define TYPE_INTN 2
+#define TYPE_UINTN 3
+#define TYPE_INT32 4
+#define TYPE_UINT32 5
+#define TYPE_INT64 6
+#define TYPE_UINT64 7
+#define TYPE_STRING 8
+#define TYPE_DOUBLE 9
+#define TYPE_INTSTR 10
#ifdef WIN32
-#define TYPE_WSTRING 11
+#define TYPE_WSTRING 11
#endif
-#define TYPE_UNKNOWN 20
+#define TYPE_UNKNOWN 20
-#define FLAG_LEFT 0x1
-#define FLAG_SIGNED 0x2
-#define FLAG_SPACED 0x4
-#define FLAG_ZEROS 0x8
-#define FLAG_NEG 0x10
+#define FLAG_LEFT 0x1
+#define FLAG_SIGNED 0x2
+#define FLAG_SPACED 0x4
+#define FLAG_ZEROS 0x8
+#define FLAG_NEG 0x10
/*
** Fill into the buffer using the data in src
*/
static int fill2(SprintfState *ss, const char *src, int srclen, int width,
- int flags)
+ int flags)
{
char space = ' ';
int rv;
width -= srclen;
- if ((width > 0) && ((flags & FLAG_LEFT) == 0)) { /* Right adjusting */
- if (flags & FLAG_ZEROS) {
- space = '0';
- }
- while (--width >= 0) {
- rv = (*ss->stuff)(ss, &space, 1);
- if (rv < 0) {
- return rv;
- }
- }
+ if ((width > 0) && ((flags & FLAG_LEFT) == 0)) { /* Right adjusting */
+ if (flags & FLAG_ZEROS) {
+ space = '0';
+ }
+ while (--width >= 0) {
+ rv = (*ss->stuff)(ss, &space, 1);
+ if (rv < 0) {
+ return rv;
+ }
+ }
}
/* Copy out the source data */
rv = (*ss->stuff)(ss, src, srclen);
if (rv < 0) {
- return rv;
+ return rv;
}
- if ((width > 0) && ((flags & FLAG_LEFT) != 0)) { /* Left adjusting */
- while (--width >= 0) {
- rv = (*ss->stuff)(ss, &space, 1);
- if (rv < 0) {
- return rv;
- }
- }
+ if ((width > 0) && ((flags & FLAG_LEFT) != 0)) { /* Left adjusting */
+ while (--width >= 0) {
+ rv = (*ss->stuff)(ss, &space, 1);
+ if (rv < 0) {
+ return rv;
+ }
+ }
}
return 0;
}
@@ -136,7 +136,7 @@ static int fill2(SprintfState *ss, const char *src, int srclen, int width,
** Fill a number. The order is: optional-sign zero-filling conversion-digits
*/
static int fill_n(SprintfState *ss, const char *src, int srclen, int width,
- int prec, int type, int flags)
+ int prec, int type, int flags)
{
int zerowidth = 0;
int precwidth = 0;
@@ -148,77 +148,77 @@ static int fill_n(SprintfState *ss, const char *src, int srclen, int width,
char sign;
if ((type & 1) == 0) {
- if (flags & FLAG_NEG) {
- sign = '-';
- signwidth = 1;
- } else if (flags & FLAG_SIGNED) {
- sign = '+';
- signwidth = 1;
- } else if (flags & FLAG_SPACED) {
- sign = ' ';
- signwidth = 1;
- }
+ if (flags & FLAG_NEG) {
+ sign = '-';
+ signwidth = 1;
+ } else if (flags & FLAG_SIGNED) {
+ sign = '+';
+ signwidth = 1;
+ } else if (flags & FLAG_SPACED) {
+ sign = ' ';
+ signwidth = 1;
+ }
}
cvtwidth = signwidth + srclen;
if (prec > 0) {
- if (prec > srclen) {
- precwidth = prec - srclen; /* Need zero filling */
- cvtwidth += precwidth;
- }
+ if (prec > srclen) {
+ precwidth = prec - srclen; /* Need zero filling */
+ cvtwidth += precwidth;
+ }
}
if ((flags & FLAG_ZEROS) && (prec < 0)) {
- if (width > cvtwidth) {
- zerowidth = width - cvtwidth; /* Zero filling */
- cvtwidth += zerowidth;
- }
+ if (width > cvtwidth) {
+ zerowidth = width - cvtwidth; /* Zero filling */
+ cvtwidth += zerowidth;
+ }
}
if (flags & FLAG_LEFT) {
- if (width > cvtwidth) {
- /* Space filling on the right (i.e. left adjusting) */
- rightspaces = width - cvtwidth;
- }
+ if (width > cvtwidth) {
+ /* Space filling on the right (i.e. left adjusting) */
+ rightspaces = width - cvtwidth;
+ }
} else {
- if (width > cvtwidth) {
- /* Space filling on the left (i.e. right adjusting) */
- leftspaces = width - cvtwidth;
- }
+ if (width > cvtwidth) {
+ /* Space filling on the left (i.e. right adjusting) */
+ leftspaces = width - cvtwidth;
+ }
}
while (--leftspaces >= 0) {
- rv = (*ss->stuff)(ss, " ", 1);
- if (rv < 0) {
- return rv;
- }
+ rv = (*ss->stuff)(ss, " ", 1);
+ if (rv < 0) {
+ return rv;
+ }
}
if (signwidth) {
- rv = (*ss->stuff)(ss, &sign, 1);
- if (rv < 0) {
- return rv;
- }
+ rv = (*ss->stuff)(ss, &sign, 1);
+ if (rv < 0) {
+ return rv;
+ }
}
while (--precwidth >= 0) {
- rv = (*ss->stuff)(ss, "0", 1);
- if (rv < 0) {
- return rv;
- }
+ rv = (*ss->stuff)(ss, "0", 1);
+ if (rv < 0) {
+ return rv;
+ }
}
while (--zerowidth >= 0) {
- rv = (*ss->stuff)(ss, "0", 1);
- if (rv < 0) {
- return rv;
- }
+ rv = (*ss->stuff)(ss, "0", 1);
+ if (rv < 0) {
+ return rv;
+ }
}
rv = (*ss->stuff)(ss, src, srclen);
if (rv < 0) {
- return rv;
+ return rv;
}
while (--rightspaces >= 0) {
- rv = (*ss->stuff)(ss, " ", 1);
- if (rv < 0) {
- return rv;
- }
+ rv = (*ss->stuff)(ss, " ", 1);
+ if (rv < 0) {
+ return rv;
+ }
}
return 0;
}
@@ -227,7 +227,7 @@ static int fill_n(SprintfState *ss, const char *src, int srclen, int width,
** Convert a long into its printable form
*/
static int cvt_l(SprintfState *ss, long num, int width, int prec, int radix,
- int type, int flags, const char *hexp)
+ int type, int flags, const char *hexp)
{
char cvtbuf[100];
char *cvt;
@@ -235,7 +235,7 @@ static int cvt_l(SprintfState *ss, long num, int width, int prec, int radix,
/* according to the man page this needs to happen */
if ((prec == 0) && (num == 0)) {
- return 0;
+ return 0;
}
/*
@@ -246,14 +246,14 @@ static int cvt_l(SprintfState *ss, long num, int width, int prec, int radix,
cvt = cvtbuf + sizeof(cvtbuf);
digits = 0;
while (num) {
- int digit = (((unsigned long)num) % radix) & 0xF;
- *--cvt = hexp[digit];
- digits++;
- num = (long)(((unsigned long)num) / radix);
+ int digit = (((unsigned long)num) % radix) & 0xF;
+ *--cvt = hexp[digit];
+ digits++;
+ num = (long)(((unsigned long)num) / radix);
}
if (digits == 0) {
- *--cvt = '0';
- digits++;
+ *--cvt = '0';
+ digits++;
}
/*
@@ -267,7 +267,7 @@ static int cvt_l(SprintfState *ss, long num, int width, int prec, int radix,
** Convert a 64-bit integer into its printable form
*/
static int cvt_ll(SprintfState *ss, PRInt64 num, int width, int prec, int radix,
- int type, int flags, const char *hexp)
+ int type, int flags, const char *hexp)
{
char cvtbuf[100];
char *cvt;
@@ -276,7 +276,7 @@ static int cvt_ll(SprintfState *ss, PRInt64 num, int width, int prec, int radix,
/* according to the man page this needs to happen */
if ((prec == 0) && (LL_IS_ZERO(num))) {
- return 0;
+ return 0;
}
/*
@@ -288,17 +288,17 @@ static int cvt_ll(SprintfState *ss, PRInt64 num, int width, int prec, int radix,
cvt = cvtbuf + sizeof(cvtbuf);
digits = 0;
while (!LL_IS_ZERO(num)) {
- PRInt32 digit;
- PRInt64 quot, rem;
- LL_UDIVMOD(&quot, &rem, num, rad);
- LL_L2I(digit, rem);
- *--cvt = hexp[digit & 0xf];
- digits++;
- num = quot;
+ PRInt32 digit;
+ PRInt64 quot, rem;
+ LL_UDIVMOD(&quot, &rem, num, rad);
+ LL_L2I(digit, rem);
+ *--cvt = hexp[digit & 0xf];
+ digits++;
+ num = quot;
}
if (digits == 0) {
- *--cvt = '0';
- digits++;
+ *--cvt = '0';
+ digits++;
}
/*
@@ -321,8 +321,8 @@ static int cvt_f(SprintfState *ss, double d, const char *fmt0, const char *fmt1)
int amount = fmt1 - fmt0;
if (amount <= 0 || amount >= sizeof(fin)) {
- /* Totally bogus % command to snprintf. Just ignore it */
- return 0;
+ /* Totally bogus % command to snprintf. Just ignore it */
+ return 0;
}
memcpy(fin, fmt0, amount);
fin[amount] = 0;
@@ -352,26 +352,27 @@ static int cvt_f(SprintfState *ss, double d, const char *fmt0, const char *fmt1)
** where -1 means until NUL.
*/
static int cvt_s(SprintfState *ss, const char *str, int width, int prec,
- int flags)
+ int flags)
{
int slen;
- if (prec == 0)
- return 0;
+ if (prec == 0) {
+ return 0;
+ }
/* Limit string length by precision value */
if (!str) {
- str = "(null)";
- }
+ str = "(null)";
+ }
if (prec > 0) {
- /* this is: slen = strnlen(str, prec); */
- register const char *s;
+ /* this is: slen = strnlen(str, prec); */
+ register const char *s;
- for(s = str; prec && *s; s++, prec-- )
- ;
- slen = s - str;
+ for(s = str; prec && *s; s++, prec-- )
+ ;
+ slen = s - str;
} else {
- slen = strlen(str);
+ slen = strlen(str);
}
/* and away we go */
@@ -381,7 +382,7 @@ static int cvt_s(SprintfState *ss, const char *str, int width, int prec,
/*
** BuildArgArray stands for Numbered Argument list Sprintf
** for example,
-** fmt = "%4$i, %2$d, %3s, %1d";
+** fmt = "%4$i, %2$d, %3s, %1d";
** the number must start from 1, and no gap among them
*/
@@ -391,61 +392,63 @@ static struct NumArg* BuildArgArray( const char *fmt, va_list ap, int* rv, struc
const char* p;
char c;
struct NumArg* nas;
-
+
/*
- ** first pass:
- ** determine how many legal % I have got, then allocate space
+ ** first pass:
+ ** determine how many legal % I have got, then allocate space
*/
p = fmt;
*rv = 0;
i = 0;
- while( ( c = *p++ ) != 0 ){
- if( c != '%' )
- continue;
- if( ( c = *p++ ) == '%' ) /* skip %% case */
- continue;
-
- while( c != 0 ){
- if( c > '9' || c < '0' ){
- if( c == '$' ){ /* numbered argument case */
- if( i > 0 ){
- *rv = -1;
- return NULL;
- }
- number++;
- } else{ /* non-numbered argument case */
- if( number > 0 ){
- *rv = -1;
- return NULL;
- }
- i = 1;
- }
- break;
- }
-
- c = *p++;
- }
+ while( ( c = *p++ ) != 0 ) {
+ if( c != '%' ) {
+ continue;
+ }
+ if( ( c = *p++ ) == '%' ) { /* skip %% case */
+ continue;
+ }
+
+ while( c != 0 ) {
+ if( c > '9' || c < '0' ) {
+ if( c == '$' ) { /* numbered argument case */
+ if( i > 0 ) {
+ *rv = -1;
+ return NULL;
+ }
+ number++;
+ } else { /* non-numbered argument case */
+ if( number > 0 ) {
+ *rv = -1;
+ return NULL;
+ }
+ i = 1;
+ }
+ break;
+ }
+
+ c = *p++;
+ }
}
- if( number == 0 ){
- return NULL;
+ if( number == 0 ) {
+ return NULL;
}
-
- if( number > NAS_DEFAULT_NUM ){
- nas = (struct NumArg*)PR_MALLOC( number * sizeof( struct NumArg ) );
- if( !nas ){
- *rv = -1;
- return NULL;
- }
+
+ if( number > NAS_DEFAULT_NUM ) {
+ nas = (struct NumArg*)PR_MALLOC( number * sizeof( struct NumArg ) );
+ if( !nas ) {
+ *rv = -1;
+ return NULL;
+ }
} else {
- nas = nasArray;
+ nas = nasArray;
}
- for( i = 0; i < number; i++ ){
- nas[i].type = TYPE_UNKNOWN;
+ for( i = 0; i < number; i++ ) {
+ nas[i].type = TYPE_UNKNOWN;
}
@@ -455,143 +458,148 @@ static struct NumArg* BuildArgArray( const char *fmt, va_list ap, int* rv, struc
*/
p = fmt;
- while( ( c = *p++ ) != 0 ){
- if( c != '%' ) continue;
- c = *p++;
- if( c == '%' ) continue;
-
- cn = 0;
- while( c && c != '$' ){ /* should improve error check later */
- cn = cn*10 + c - '0';
- c = *p++;
- }
-
- if( !c || cn < 1 || cn > number ){
- *rv = -1;
- break;
+ while( ( c = *p++ ) != 0 ) {
+ if( c != '%' ) {
+ continue;
+ }
+ c = *p++;
+ if( c == '%' ) {
+ continue;
+ }
+
+ cn = 0;
+ while( c && c != '$' ) { /* should improve error check later */
+ cn = cn*10 + c - '0';
+ c = *p++;
+ }
+
+ if( !c || cn < 1 || cn > number ) {
+ *rv = -1;
+ break;
}
- /* nas[cn] starts from 0, and make sure nas[cn].type is not assigned */
+ /* nas[cn] starts from 0, and make sure nas[cn].type is not assigned */
cn--;
- if( nas[cn].type != TYPE_UNKNOWN )
- continue;
+ if( nas[cn].type != TYPE_UNKNOWN ) {
+ continue;
+ }
c = *p++;
/* width */
if (c == '*') {
- /* not supported feature, for the argument is not numbered */
- *rv = -1;
- break;
- }
-
- while ((c >= '0') && (c <= '9')) {
- c = *p++;
- }
-
- /* precision */
- if (c == '.') {
- c = *p++;
- if (c == '*') {
- /* not supported feature, for the argument is not numbered */
- *rv = -1;
- break;
- }
-
- while ((c >= '0') && (c <= '9')) {
- c = *p++;
- }
- }
-
- /* size */
- nas[cn].type = TYPE_INTN;
- if (c == 'h') {
- nas[cn].type = TYPE_INT16;
- c = *p++;
- } else if (c == 'L') {
- /* XXX not quite sure here */
- nas[cn].type = TYPE_INT64;
- c = *p++;
- } else if (c == 'l') {
- nas[cn].type = TYPE_INT32;
- c = *p++;
- if (c == 'l') {
- nas[cn].type = TYPE_INT64;
- c = *p++;
- }
- } else if (c == 'z') {
- if (sizeof(size_t) == sizeof(PRInt32)) {
- nas[ cn ].type = TYPE_INT32;
- } else if (sizeof(size_t) == sizeof(PRInt64)) {
- nas[ cn ].type = TYPE_INT64;
- } else {
- nas[ cn ].type = TYPE_UNKNOWN;
- }
- c = *p++;
- }
-
- /* format */
- switch (c) {
- case 'd':
- case 'c':
- case 'i':
- case 'o':
- case 'u':
- case 'x':
- case 'X':
- break;
-
- case 'e':
- case 'f':
- case 'g':
- nas[ cn ].type = TYPE_DOUBLE;
- break;
-
- case 'p':
- /* XXX should use cpp */
- if (sizeof(void *) == sizeof(PRInt32)) {
- nas[ cn ].type = TYPE_UINT32;
- } else if (sizeof(void *) == sizeof(PRInt64)) {
- nas[ cn ].type = TYPE_UINT64;
- } else if (sizeof(void *) == sizeof(PRIntn)) {
- nas[ cn ].type = TYPE_UINTN;
- } else {
- nas[ cn ].type = TYPE_UNKNOWN;
- }
- break;
-
- case 'S':
+ /* not supported feature, for the argument is not numbered */
+ *rv = -1;
+ break;
+ }
+
+ while ((c >= '0') && (c <= '9')) {
+ c = *p++;
+ }
+
+ /* precision */
+ if (c == '.') {
+ c = *p++;
+ if (c == '*') {
+ /* not supported feature, for the argument is not numbered */
+ *rv = -1;
+ break;
+ }
+
+ while ((c >= '0') && (c <= '9')) {
+ c = *p++;
+ }
+ }
+
+ /* size */
+ nas[cn].type = TYPE_INTN;
+ if (c == 'h') {
+ nas[cn].type = TYPE_INT16;
+ c = *p++;
+ } else if (c == 'L') {
+ /* XXX not quite sure here */
+ nas[cn].type = TYPE_INT64;
+ c = *p++;
+ } else if (c == 'l') {
+ nas[cn].type = TYPE_INT32;
+ c = *p++;
+ if (c == 'l') {
+ nas[cn].type = TYPE_INT64;
+ c = *p++;
+ }
+ } else if (c == 'z') {
+ if (sizeof(size_t) == sizeof(PRInt32)) {
+ nas[ cn ].type = TYPE_INT32;
+ } else if (sizeof(size_t) == sizeof(PRInt64)) {
+ nas[ cn ].type = TYPE_INT64;
+ } else {
+ nas[ cn ].type = TYPE_UNKNOWN;
+ }
+ c = *p++;
+ }
+
+ /* format */
+ switch (c) {
+ case 'd':
+ case 'c':
+ case 'i':
+ case 'o':
+ case 'u':
+ case 'x':
+ case 'X':
+ break;
+
+ case 'e':
+ case 'f':
+ case 'g':
+ nas[ cn ].type = TYPE_DOUBLE;
+ break;
+
+ case 'p':
+ /* XXX should use cpp */
+ if (sizeof(void *) == sizeof(PRInt32)) {
+ nas[ cn ].type = TYPE_UINT32;
+ } else if (sizeof(void *) == sizeof(PRInt64)) {
+ nas[ cn ].type = TYPE_UINT64;
+ } else if (sizeof(void *) == sizeof(PRIntn)) {
+ nas[ cn ].type = TYPE_UINTN;
+ } else {
+ nas[ cn ].type = TYPE_UNKNOWN;
+ }
+ break;
+
+ case 'S':
#ifdef WIN32
- nas[ cn ].type = TYPE_WSTRING;
- break;
+ nas[ cn ].type = TYPE_WSTRING;
+ break;
#endif
- case 'C':
- case 'E':
- case 'G':
- /* XXX not supported I suppose */
- PR_ASSERT(0);
- nas[ cn ].type = TYPE_UNKNOWN;
- break;
-
- case 's':
- nas[ cn ].type = TYPE_STRING;
- break;
-
- case 'n':
- nas[ cn ].type = TYPE_INTSTR;
- break;
-
- default:
- PR_ASSERT(0);
- nas[ cn ].type = TYPE_UNKNOWN;
- break;
- }
-
- /* get a legal para. */
- if( nas[ cn ].type == TYPE_UNKNOWN ){
- *rv = -1;
- break;
- }
+ case 'C':
+ case 'E':
+ case 'G':
+ /* XXX not supported I suppose */
+ PR_ASSERT(0);
+ nas[ cn ].type = TYPE_UNKNOWN;
+ break;
+
+ case 's':
+ nas[ cn ].type = TYPE_STRING;
+ break;
+
+ case 'n':
+ nas[ cn ].type = TYPE_INTSTR;
+ break;
+
+ default:
+ PR_ASSERT(0);
+ nas[ cn ].type = TYPE_UNKNOWN;
+ break;
+ }
+
+ /* get a legal para. */
+ if( nas[ cn ].type == TYPE_UNKNOWN ) {
+ *rv = -1;
+ break;
+ }
}
@@ -600,72 +608,74 @@ static struct NumArg* BuildArgArray( const char *fmt, va_list ap, int* rv, struc
** fill the nas[cn].ap
*/
- if( *rv < 0 ){
- if( nas != nasArray )
- PR_DELETE( nas );
- return NULL;
+ if( *rv < 0 ) {
+ if( nas != nasArray ) {
+ PR_DELETE( nas );
+ }
+ return NULL;
}
cn = 0;
- while( cn < number ){
- if( nas[cn].type == TYPE_UNKNOWN ){
- cn++;
- continue;
- }
-
- switch( nas[cn].type ){
- case TYPE_INT16:
- case TYPE_UINT16:
- case TYPE_INTN:
- nas[cn].u.i = va_arg( ap, int );
- break;
-
- case TYPE_UINTN:
- nas[cn].u.ui = va_arg( ap, unsigned int );
- break;
-
- case TYPE_INT32:
- nas[cn].u.i32 = va_arg( ap, PRInt32 );
- break;
-
- case TYPE_UINT32:
- nas[cn].u.ui32 = va_arg( ap, PRUint32 );
- break;
-
- case TYPE_INT64:
- nas[cn].u.ll = va_arg( ap, PRInt64 );
- break;
-
- case TYPE_UINT64:
- nas[cn].u.ull = va_arg( ap, PRUint64 );
- break;
-
- case TYPE_STRING:
- nas[cn].u.s = va_arg( ap, char* );
- break;
+ while( cn < number ) {
+ if( nas[cn].type == TYPE_UNKNOWN ) {
+ cn++;
+ continue;
+ }
+
+ switch( nas[cn].type ) {
+ case TYPE_INT16:
+ case TYPE_UINT16:
+ case TYPE_INTN:
+ nas[cn].u.i = va_arg( ap, int );
+ break;
+
+ case TYPE_UINTN:
+ nas[cn].u.ui = va_arg( ap, unsigned int );
+ break;
+
+ case TYPE_INT32:
+ nas[cn].u.i32 = va_arg( ap, PRInt32 );
+ break;
+
+ case TYPE_UINT32:
+ nas[cn].u.ui32 = va_arg( ap, PRUint32 );
+ break;
+
+ case TYPE_INT64:
+ nas[cn].u.ll = va_arg( ap, PRInt64 );
+ break;
+
+ case TYPE_UINT64:
+ nas[cn].u.ull = va_arg( ap, PRUint64 );
+ break;
+
+ case TYPE_STRING:
+ nas[cn].u.s = va_arg( ap, char* );
+ break;
#ifdef WIN32
- case TYPE_WSTRING:
- nas[cn].u.ws = va_arg( ap, WCHAR* );
- break;
+ case TYPE_WSTRING:
+ nas[cn].u.ws = va_arg( ap, WCHAR* );
+ break;
#endif
- case TYPE_INTSTR:
- nas[cn].u.ip = va_arg( ap, int* );
- break;
+ case TYPE_INTSTR:
+ nas[cn].u.ip = va_arg( ap, int* );
+ break;
- case TYPE_DOUBLE:
- nas[cn].u.d = va_arg( ap, double );
- break;
+ case TYPE_DOUBLE:
+ nas[cn].u.d = va_arg( ap, double );
+ break;
- default:
- if( nas != nasArray )
- PR_DELETE( nas );
- *rv = -1;
- return NULL;
- }
+ default:
+ if( nas != nasArray ) {
+ PR_DELETE( nas );
+ }
+ *rv = -1;
+ return NULL;
+ }
- cn++;
+ cn++;
}
@@ -680,15 +690,15 @@ static int dosprintf(SprintfState *ss, const char *fmt, va_list ap)
char c;
int flags, width, prec, radix, type;
union {
- char ch;
- int i;
- long l;
- PRInt64 ll;
- double d;
- const char *s;
- int *ip;
+ char ch;
+ int i;
+ long l;
+ PRInt64 ll;
+ double d;
+ const char *s;
+ int *ip;
#ifdef WIN32
- const WCHAR *ws;
+ const WCHAR *ws;
#endif
} u;
const char *fmt0;
@@ -711,344 +721,359 @@ static int dosprintf(SprintfState *ss, const char *fmt, va_list ap)
*/
nas = BuildArgArray( fmt, ap, &rv, nasArray );
- if( rv < 0 ){
- /* the fmt contains error Numbered Argument format, jliu@netscape.com */
- PR_ASSERT(0);
- return rv;
+ if( rv < 0 ) {
+ /* the fmt contains error Numbered Argument format, jliu@netscape.com */
+ PR_ASSERT(0);
+ return rv;
}
while ((c = *fmt++) != 0) {
- if (c != '%') {
- rv = (*ss->stuff)(ss, fmt - 1, 1);
- if (rv < 0) {
- return rv;
- }
- continue;
- }
- fmt0 = fmt - 1;
-
- /*
- ** Gobble up the % format string. Hopefully we have handled all
- ** of the strange cases!
- */
- flags = 0;
- c = *fmt++;
- if (c == '%') {
- /* quoting a % with %% */
- rv = (*ss->stuff)(ss, fmt - 1, 1);
- if (rv < 0) {
- return rv;
- }
- continue;
- }
-
- if( nas != NULL ){
- /* the fmt contains the Numbered Arguments feature */
- i = 0;
- while( c && c != '$' ){ /* should improve error check later */
- i = ( i * 10 ) + ( c - '0' );
- c = *fmt++;
- }
-
- if( nas[i-1].type == TYPE_UNKNOWN ){
- if( nas && ( nas != nasArray ) )
- PR_DELETE( nas );
- return -1;
- }
-
- nap = &nas[i-1];
- dolPt = fmt;
- c = *fmt++;
- }
-
- /*
- * Examine optional flags. Note that we do not implement the
- * '#' flag of sprintf(). The ANSI C spec. of the '#' flag is
- * somewhat ambiguous and not ideal, which is perhaps why
- * the various sprintf() implementations are inconsistent
- * on this feature.
- */
- while ((c == '-') || (c == '+') || (c == ' ') || (c == '0')) {
- if (c == '-') flags |= FLAG_LEFT;
- if (c == '+') flags |= FLAG_SIGNED;
- if (c == ' ') flags |= FLAG_SPACED;
- if (c == '0') flags |= FLAG_ZEROS;
- c = *fmt++;
- }
- if (flags & FLAG_SIGNED) flags &= ~FLAG_SPACED;
- if (flags & FLAG_LEFT) flags &= ~FLAG_ZEROS;
-
- /* width */
- if (c == '*') {
- c = *fmt++;
- width = va_arg(ap, int);
- } else {
- width = 0;
- while ((c >= '0') && (c <= '9')) {
- width = (width * 10) + (c - '0');
- c = *fmt++;
- }
- }
-
- /* precision */
- prec = -1;
- if (c == '.') {
- c = *fmt++;
- if (c == '*') {
- c = *fmt++;
- prec = va_arg(ap, int);
- } else {
- prec = 0;
- while ((c >= '0') && (c <= '9')) {
- prec = (prec * 10) + (c - '0');
- c = *fmt++;
- }
- }
- }
-
- /* size */
- type = TYPE_INTN;
- if (c == 'h') {
- type = TYPE_INT16;
- c = *fmt++;
- } else if (c == 'L') {
- /* XXX not quite sure here */
- type = TYPE_INT64;
- c = *fmt++;
- } else if (c == 'l') {
- type = TYPE_INT32;
- c = *fmt++;
- if (c == 'l') {
- type = TYPE_INT64;
- c = *fmt++;
- }
- } else if (c == 'z') {
- if (sizeof(size_t) == sizeof(PRInt32)) {
- type = TYPE_INT32;
- } else if (sizeof(size_t) == sizeof(PRInt64)) {
- type = TYPE_INT64;
- }
- c = *fmt++;
- }
-
- /* format */
- hexp = hex;
- switch (c) {
- case 'd': case 'i': /* decimal/integer */
- radix = 10;
- goto fetch_and_convert;
-
- case 'o': /* octal */
- radix = 8;
- type |= 1;
- goto fetch_and_convert;
-
- case 'u': /* unsigned decimal */
- radix = 10;
- type |= 1;
- goto fetch_and_convert;
-
- case 'x': /* unsigned hex */
- radix = 16;
- type |= 1;
- goto fetch_and_convert;
-
- case 'X': /* unsigned HEX */
- radix = 16;
- hexp = HEX;
- type |= 1;
- goto fetch_and_convert;
-
- fetch_and_convert:
- switch (type) {
- case TYPE_INT16:
- u.l = nas ? nap->u.i : va_arg(ap, int);
- if (u.l < 0) {
- u.l = -u.l;
- flags |= FLAG_NEG;
- }
- goto do_long;
- case TYPE_UINT16:
- u.l = (nas ? nap->u.i : va_arg(ap, int)) & 0xffff;
- goto do_long;
- case TYPE_INTN:
- u.l = nas ? nap->u.i : va_arg(ap, int);
- if (u.l < 0) {
- u.l = -u.l;
- flags |= FLAG_NEG;
- }
- goto do_long;
- case TYPE_UINTN:
- u.l = (long)(nas ? nap->u.ui : va_arg(ap, unsigned int));
- goto do_long;
-
- case TYPE_INT32:
- u.l = nas ? nap->u.i32 : va_arg(ap, PRInt32);
- if (u.l < 0) {
- u.l = -u.l;
- flags |= FLAG_NEG;
- }
- goto do_long;
- case TYPE_UINT32:
- u.l = (long)(nas ? nap->u.ui32 : va_arg(ap, PRUint32));
- do_long:
- rv = cvt_l(ss, u.l, width, prec, radix, type, flags, hexp);
- if (rv < 0) {
- return rv;
- }
- break;
-
- case TYPE_INT64:
- u.ll = nas ? nap->u.ll : va_arg(ap, PRInt64);
- if (!LL_GE_ZERO(u.ll)) {
- LL_NEG(u.ll, u.ll);
- flags |= FLAG_NEG;
- }
- goto do_longlong;
- case TYPE_UINT64:
- u.ll = nas ? nap->u.ull : va_arg(ap, PRUint64);
- do_longlong:
- rv = cvt_ll(ss, u.ll, width, prec, radix, type, flags, hexp);
- if (rv < 0) {
- return rv;
- }
- break;
- }
- break;
-
- case 'e':
- case 'E':
- case 'f':
- case 'g':
- u.d = nas ? nap->u.d : va_arg(ap, double);
- if( nas != NULL ){
- i = fmt - dolPt;
- if( i < sizeof( pattern ) ){
- pattern[0] = '%';
- memcpy( &pattern[1], dolPt, i );
- rv = cvt_f(ss, u.d, pattern, &pattern[i+1] );
- }
- } else
- rv = cvt_f(ss, u.d, fmt0, fmt);
-
- if (rv < 0) {
- return rv;
- }
- break;
-
- case 'c':
- u.ch = nas ? nap->u.i : va_arg(ap, int);
- if ((flags & FLAG_LEFT) == 0) {
- while (width-- > 1) {
- rv = (*ss->stuff)(ss, " ", 1);
- if (rv < 0) {
- return rv;
- }
+ if (c != '%') {
+ rv = (*ss->stuff)(ss, fmt - 1, 1);
+ if (rv < 0) {
+ return rv;
+ }
+ continue;
+ }
+ fmt0 = fmt - 1;
+
+ /*
+ ** Gobble up the % format string. Hopefully we have handled all
+ ** of the strange cases!
+ */
+ flags = 0;
+ c = *fmt++;
+ if (c == '%') {
+ /* quoting a % with %% */
+ rv = (*ss->stuff)(ss, fmt - 1, 1);
+ if (rv < 0) {
+ return rv;
+ }
+ continue;
+ }
+
+ if( nas != NULL ) {
+ /* the fmt contains the Numbered Arguments feature */
+ i = 0;
+ while( c && c != '$' ) { /* should improve error check later */
+ i = ( i * 10 ) + ( c - '0' );
+ c = *fmt++;
+ }
+
+ if( nas[i-1].type == TYPE_UNKNOWN ) {
+ if( nas && ( nas != nasArray ) ) {
+ PR_DELETE( nas );
}
+ return -1;
}
- rv = (*ss->stuff)(ss, &u.ch, 1);
- if (rv < 0) {
- return rv;
- }
- if (flags & FLAG_LEFT) {
- while (width-- > 1) {
- rv = (*ss->stuff)(ss, " ", 1);
- if (rv < 0) {
- return rv;
- }
+
+ nap = &nas[i-1];
+ dolPt = fmt;
+ c = *fmt++;
+ }
+
+ /*
+ * Examine optional flags. Note that we do not implement the
+ * '#' flag of sprintf(). The ANSI C spec. of the '#' flag is
+ * somewhat ambiguous and not ideal, which is perhaps why
+ * the various sprintf() implementations are inconsistent
+ * on this feature.
+ */
+ while ((c == '-') || (c == '+') || (c == ' ') || (c == '0')) {
+ if (c == '-') {
+ flags |= FLAG_LEFT;
+ }
+ if (c == '+') {
+ flags |= FLAG_SIGNED;
+ }
+ if (c == ' ') {
+ flags |= FLAG_SPACED;
+ }
+ if (c == '0') {
+ flags |= FLAG_ZEROS;
+ }
+ c = *fmt++;
+ }
+ if (flags & FLAG_SIGNED) {
+ flags &= ~FLAG_SPACED;
+ }
+ if (flags & FLAG_LEFT) {
+ flags &= ~FLAG_ZEROS;
+ }
+
+ /* width */
+ if (c == '*') {
+ c = *fmt++;
+ width = va_arg(ap, int);
+ } else {
+ width = 0;
+ while ((c >= '0') && (c <= '9')) {
+ width = (width * 10) + (c - '0');
+ c = *fmt++;
+ }
+ }
+
+ /* precision */
+ prec = -1;
+ if (c == '.') {
+ c = *fmt++;
+ if (c == '*') {
+ c = *fmt++;
+ prec = va_arg(ap, int);
+ } else {
+ prec = 0;
+ while ((c >= '0') && (c <= '9')) {
+ prec = (prec * 10) + (c - '0');
+ c = *fmt++;
}
}
- break;
-
- case 'p':
- if (sizeof(void *) == sizeof(PRInt32)) {
- type = TYPE_UINT32;
- } else if (sizeof(void *) == sizeof(PRInt64)) {
- type = TYPE_UINT64;
- } else if (sizeof(void *) == sizeof(int)) {
- type = TYPE_UINTN;
- } else {
- PR_ASSERT(0);
- break;
- }
- radix = 16;
- goto fetch_and_convert;
+ }
+
+ /* size */
+ type = TYPE_INTN;
+ if (c == 'h') {
+ type = TYPE_INT16;
+ c = *fmt++;
+ } else if (c == 'L') {
+ /* XXX not quite sure here */
+ type = TYPE_INT64;
+ c = *fmt++;
+ } else if (c == 'l') {
+ type = TYPE_INT32;
+ c = *fmt++;
+ if (c == 'l') {
+ type = TYPE_INT64;
+ c = *fmt++;
+ }
+ } else if (c == 'z') {
+ if (sizeof(size_t) == sizeof(PRInt32)) {
+ type = TYPE_INT32;
+ } else if (sizeof(size_t) == sizeof(PRInt64)) {
+ type = TYPE_INT64;
+ }
+ c = *fmt++;
+ }
+
+ /* format */
+ hexp = hex;
+ switch (c) {
+ case 'd': case 'i': /* decimal/integer */
+ radix = 10;
+ goto fetch_and_convert;
+
+ case 'o': /* octal */
+ radix = 8;
+ type |= 1;
+ goto fetch_and_convert;
+
+ case 'u': /* unsigned decimal */
+ radix = 10;
+ type |= 1;
+ goto fetch_and_convert;
+
+ case 'x': /* unsigned hex */
+ radix = 16;
+ type |= 1;
+ goto fetch_and_convert;
+
+ case 'X': /* unsigned HEX */
+ radix = 16;
+ hexp = HEX;
+ type |= 1;
+ goto fetch_and_convert;
+
+fetch_and_convert:
+ switch (type) {
+ case TYPE_INT16:
+ u.l = nas ? nap->u.i : va_arg(ap, int);
+ if (u.l < 0) {
+ u.l = -u.l;
+ flags |= FLAG_NEG;
+ }
+ goto do_long;
+ case TYPE_UINT16:
+ u.l = (nas ? nap->u.i : va_arg(ap, int)) & 0xffff;
+ goto do_long;
+ case TYPE_INTN:
+ u.l = nas ? nap->u.i : va_arg(ap, int);
+ if (u.l < 0) {
+ u.l = -u.l;
+ flags |= FLAG_NEG;
+ }
+ goto do_long;
+ case TYPE_UINTN:
+ u.l = (long)(nas ? nap->u.ui : va_arg(ap, unsigned int));
+ goto do_long;
+
+ case TYPE_INT32:
+ u.l = nas ? nap->u.i32 : va_arg(ap, PRInt32);
+ if (u.l < 0) {
+ u.l = -u.l;
+ flags |= FLAG_NEG;
+ }
+ goto do_long;
+ case TYPE_UINT32:
+ u.l = (long)(nas ? nap->u.ui32 : va_arg(ap, PRUint32));
+do_long:
+ rv = cvt_l(ss, u.l, width, prec, radix, type, flags, hexp);
+ if (rv < 0) {
+ return rv;
+ }
+ break;
+
+ case TYPE_INT64:
+ u.ll = nas ? nap->u.ll : va_arg(ap, PRInt64);
+ if (!LL_GE_ZERO(u.ll)) {
+ LL_NEG(u.ll, u.ll);
+ flags |= FLAG_NEG;
+ }
+ goto do_longlong;
+ case TYPE_UINT64:
+ u.ll = nas ? nap->u.ull : va_arg(ap, PRUint64);
+do_longlong:
+ rv = cvt_ll(ss, u.ll, width, prec, radix, type, flags, hexp);
+ if (rv < 0) {
+ return rv;
+ }
+ break;
+ }
+ break;
+
+ case 'e':
+ case 'E':
+ case 'f':
+ case 'g':
+ u.d = nas ? nap->u.d : va_arg(ap, double);
+ if( nas != NULL ) {
+ i = fmt - dolPt;
+ if( i < sizeof( pattern ) ) {
+ pattern[0] = '%';
+ memcpy( &pattern[1], dolPt, i );
+ rv = cvt_f(ss, u.d, pattern, &pattern[i+1] );
+ }
+ } else {
+ rv = cvt_f(ss, u.d, fmt0, fmt);
+ }
+
+ if (rv < 0) {
+ return rv;
+ }
+ break;
+
+ case 'c':
+ u.ch = nas ? nap->u.i : va_arg(ap, int);
+ if ((flags & FLAG_LEFT) == 0) {
+ while (width-- > 1) {
+ rv = (*ss->stuff)(ss, " ", 1);
+ if (rv < 0) {
+ return rv;
+ }
+ }
+ }
+ rv = (*ss->stuff)(ss, &u.ch, 1);
+ if (rv < 0) {
+ return rv;
+ }
+ if (flags & FLAG_LEFT) {
+ while (width-- > 1) {
+ rv = (*ss->stuff)(ss, " ", 1);
+ if (rv < 0) {
+ return rv;
+ }
+ }
+ }
+ break;
+
+ case 'p':
+ if (sizeof(void *) == sizeof(PRInt32)) {
+ type = TYPE_UINT32;
+ } else if (sizeof(void *) == sizeof(PRInt64)) {
+ type = TYPE_UINT64;
+ } else if (sizeof(void *) == sizeof(int)) {
+ type = TYPE_UINTN;
+ } else {
+ PR_ASSERT(0);
+ break;
+ }
+ radix = 16;
+ goto fetch_and_convert;
#ifndef WIN32
- case 'S':
- /* XXX not supported I suppose */
- PR_ASSERT(0);
- break;
+ case 'S':
+ /* XXX not supported I suppose */
+ PR_ASSERT(0);
+ break;
#endif
#if 0
- case 'C':
- case 'E':
- case 'G':
- /* XXX not supported I suppose */
- PR_ASSERT(0);
- break;
+ case 'C':
+ case 'E':
+ case 'G':
+ /* XXX not supported I suppose */
+ PR_ASSERT(0);
+ break;
#endif
#ifdef WIN32
- case 'S':
- u.ws = nas ? nap->u.ws : va_arg(ap, const WCHAR*);
-
- /* Get the required size in rv */
- rv = WideCharToMultiByte(CP_ACP, 0, u.ws, -1, NULL, 0, NULL, NULL);
- if (rv == 0)
- rv = 1;
- pBuf = PR_MALLOC(rv);
- WideCharToMultiByte(CP_ACP, 0, u.ws, -1, pBuf, (int)rv, NULL, NULL);
- pBuf[rv-1] = '\0';
-
- rv = cvt_s(ss, pBuf, width, prec, flags);
-
- /* We don't need the allocated buffer anymore */
- PR_Free(pBuf);
- if (rv < 0) {
- return rv;
- }
- break;
+ case 'S':
+ u.ws = nas ? nap->u.ws : va_arg(ap, const WCHAR*);
+
+ /* Get the required size in rv */
+ rv = WideCharToMultiByte(CP_ACP, 0, u.ws, -1, NULL, 0, NULL, NULL);
+ if (rv == 0) {
+ rv = 1;
+ }
+ pBuf = PR_MALLOC(rv);
+ WideCharToMultiByte(CP_ACP, 0, u.ws, -1, pBuf, (int)rv, NULL, NULL);
+ pBuf[rv-1] = '\0';
+
+ rv = cvt_s(ss, pBuf, width, prec, flags);
+
+ /* We don't need the allocated buffer anymore */
+ PR_Free(pBuf);
+ if (rv < 0) {
+ return rv;
+ }
+ break;
#endif
- case 's':
- u.s = nas ? nap->u.s : va_arg(ap, const char*);
- rv = cvt_s(ss, u.s, width, prec, flags);
- if (rv < 0) {
- return rv;
- }
- break;
-
- case 'n':
- u.ip = nas ? nap->u.ip : va_arg(ap, int*);
- if (u.ip) {
- *u.ip = ss->cur - ss->base;
- }
- break;
-
- default:
- /* Not a % token after all... skip it */
+ case 's':
+ u.s = nas ? nap->u.s : va_arg(ap, const char*);
+ rv = cvt_s(ss, u.s, width, prec, flags);
+ if (rv < 0) {
+ return rv;
+ }
+ break;
+
+ case 'n':
+ u.ip = nas ? nap->u.ip : va_arg(ap, int*);
+ if (u.ip) {
+ *u.ip = ss->cur - ss->base;
+ }
+ break;
+
+ default:
+ /* Not a % token after all... skip it */
#if 0
- PR_ASSERT(0);
+ PR_ASSERT(0);
#endif
- rv = (*ss->stuff)(ss, "%", 1);
- if (rv < 0) {
- return rv;
- }
- rv = (*ss->stuff)(ss, fmt - 1, 1);
- if (rv < 0) {
- return rv;
- }
- }
+ rv = (*ss->stuff)(ss, "%", 1);
+ if (rv < 0) {
+ return rv;
+ }
+ rv = (*ss->stuff)(ss, fmt - 1, 1);
+ if (rv < 0) {
+ return rv;
+ }
+ }
}
/* Stuff trailing NUL */
rv = (*ss->stuff)(ss, "\0", 1);
- if( nas && ( nas != nasArray ) ){
- PR_DELETE( nas );
+ if( nas && ( nas != nasArray ) ) {
+ PR_DELETE( nas );
}
return rv;
@@ -1065,18 +1090,18 @@ static int FuncStuff(SprintfState *ss, const char *sp, PRUint32 len)
** if ss->maxlen + len would overflow or be greater than PR_INT32_MAX.
*/
if (PR_UINT32_MAX - ss->maxlen < len || ss->maxlen + len > PR_INT32_MAX) {
- return -1;
+ return -1;
}
rv = (*ss->func)(ss->arg, sp, len);
if (rv < 0) {
- return rv;
+ return rv;
}
ss->maxlen += len;
return 0;
}
-PR_IMPLEMENT(PRUint32) PR_sxprintf(PRStuffFunc func, void *arg,
- const char *fmt, ...)
+PR_IMPLEMENT(PRUint32) PR_sxprintf(PRStuffFunc func, void *arg,
+ const char *fmt, ...)
{
va_list ap;
PRUint32 rv;
@@ -1087,8 +1112,8 @@ PR_IMPLEMENT(PRUint32) PR_sxprintf(PRStuffFunc func, void *arg,
return rv;
}
-PR_IMPLEMENT(PRUint32) PR_vsxprintf(PRStuffFunc func, void *arg,
- const char *fmt, va_list ap)
+PR_IMPLEMENT(PRUint32) PR_vsxprintf(PRStuffFunc func, void *arg,
+ const char *fmt, va_list ap)
{
SprintfState ss;
int rv;
@@ -1113,38 +1138,38 @@ static int GrowStuff(SprintfState *ss, const char *sp, PRUint32 len)
off = ss->cur - ss->base;
if (PR_UINT32_MAX - len < off) {
- /* off + len would be too big. */
- return -1;
+ /* off + len would be too big. */
+ return -1;
}
if (off + len >= ss->maxlen) {
- /* Grow the buffer */
- PRUint32 increment = (len > 32) ? len : 32;
- if (PR_UINT32_MAX - ss->maxlen < increment) {
- /* ss->maxlen + increment would overflow. */
- return -1;
- }
- newlen = ss->maxlen + increment;
- if (newlen > PR_INT32_MAX) {
- return -1;
- }
- if (ss->base) {
- newbase = (char*) PR_REALLOC(ss->base, newlen);
- } else {
- newbase = (char*) PR_MALLOC(newlen);
- }
- if (!newbase) {
- /* Ran out of memory */
- return -1;
- }
- ss->base = newbase;
- ss->maxlen = newlen;
- ss->cur = ss->base + off;
+ /* Grow the buffer */
+ PRUint32 increment = (len > 32) ? len : 32;
+ if (PR_UINT32_MAX - ss->maxlen < increment) {
+ /* ss->maxlen + increment would overflow. */
+ return -1;
+ }
+ newlen = ss->maxlen + increment;
+ if (newlen > PR_INT32_MAX) {
+ return -1;
+ }
+ if (ss->base) {
+ newbase = (char*) PR_REALLOC(ss->base, newlen);
+ } else {
+ newbase = (char*) PR_MALLOC(newlen);
+ }
+ if (!newbase) {
+ /* Ran out of memory */
+ return -1;
+ }
+ ss->base = newbase;
+ ss->maxlen = newlen;
+ ss->cur = ss->base + off;
}
/* Copy data */
while (len) {
- --len;
- *ss->cur++ = *sp++;
+ --len;
+ *ss->cur++ = *sp++;
}
PR_ASSERT((PRUint32)(ss->cur - ss->base) <= ss->maxlen);
return 0;
@@ -1169,7 +1194,7 @@ PR_IMPLEMENT(char *) PR_smprintf(const char *fmt, ...)
*/
PR_IMPLEMENT(void) PR_smprintf_free(char *mem)
{
- PR_DELETE(mem);
+ PR_DELETE(mem);
}
PR_IMPLEMENT(char *) PR_vsmprintf(const char *fmt, va_list ap)
@@ -1183,10 +1208,10 @@ PR_IMPLEMENT(char *) PR_vsmprintf(const char *fmt, va_list ap)
ss.maxlen = 0;
rv = dosprintf(&ss, fmt, ap);
if (rv < 0) {
- if (ss.base) {
- PR_DELETE(ss.base);
- }
- return 0;
+ if (ss.base) {
+ PR_DELETE(ss.base);
+ }
+ return 0;
}
return ss.base;
}
@@ -1199,11 +1224,11 @@ static int LimitStuff(SprintfState *ss, const char *sp, PRUint32 len)
PRUint32 limit = ss->maxlen - (ss->cur - ss->base);
if (len > limit) {
- len = limit;
+ len = limit;
}
while (len) {
- --len;
- *ss->cur++ = *sp++;
+ --len;
+ *ss->cur++ = *sp++;
}
return 0;
}
@@ -1224,14 +1249,14 @@ PR_IMPLEMENT(PRUint32) PR_snprintf(char *out, PRUint32 outlen, const char *fmt,
}
PR_IMPLEMENT(PRUint32) PR_vsnprintf(char *out, PRUint32 outlen,const char *fmt,
- va_list ap)
+ va_list ap)
{
SprintfState ss;
PRUint32 n;
PR_ASSERT(outlen != 0 && outlen <= PR_INT32_MAX);
if (outlen == 0 || outlen > PR_INT32_MAX) {
- return 0;
+ return 0;
}
ss.stuff = LimitStuff;
@@ -1241,8 +1266,9 @@ PR_IMPLEMENT(PRUint32) PR_vsnprintf(char *out, PRUint32 outlen,const char *fmt,
(void) dosprintf(&ss, fmt, ap);
/* If we added chars, and we didn't append a null, do it now. */
- if( (ss.cur != ss.base) && (*(ss.cur - 1) != '\0') )
+ if( (ss.cur != ss.base) && (*(ss.cur - 1) != '\0') ) {
*(ss.cur - 1) = '\0';
+ }
n = ss.cur - ss.base;
return n ? n - 1 : n;
@@ -1266,24 +1292,24 @@ PR_IMPLEMENT(char *) PR_vsprintf_append(char *last, const char *fmt, va_list ap)
ss.stuff = GrowStuff;
if (last) {
- size_t lastlen = strlen(last);
- if (lastlen > PR_INT32_MAX) {
- return 0;
- }
- ss.base = last;
- ss.cur = last + lastlen;
- ss.maxlen = lastlen;
+ size_t lastlen = strlen(last);
+ if (lastlen > PR_INT32_MAX) {
+ return 0;
+ }
+ ss.base = last;
+ ss.cur = last + lastlen;
+ ss.maxlen = lastlen;
} else {
- ss.base = 0;
- ss.cur = 0;
- ss.maxlen = 0;
+ ss.base = 0;
+ ss.cur = 0;
+ ss.maxlen = 0;
}
rv = dosprintf(&ss, fmt, ap);
if (rv < 0) {
- if (ss.base) {
- PR_DELETE(ss.base);
- }
- return 0;
+ if (ss.base) {
+ PR_DELETE(ss.base);
+ }
+ return 0;
}
return ss.base;
}
diff --git a/nsprpub/pr/src/io/prscanf.c b/nsprpub/pr/src/io/prscanf.c
index 377a6e643..9923ea27c 100644
--- a/nsprpub/pr/src/io/prscanf.c
+++ b/nsprpub/pr/src/io/prscanf.c
@@ -30,7 +30,7 @@ typedef int (*_PRGetCharFN)(void *stream);
/*
* A function that pushes the character 'ch' back to 'stream'.
*/
-typedef void (*_PRUngetCharFN)(void *stream, int ch);
+typedef void (*_PRUngetCharFN)(void *stream, int ch);
/*
* The size specifier for the integer and floating point number
@@ -89,7 +89,7 @@ typedef struct {
* 'str' is assumed to be a representation of the integer in
* base 'base'.
*
- * Warning:
+ * Warning:
* - Only handle base 8, 10, and 16.
* - No overflow checking.
*/
@@ -139,7 +139,7 @@ _pr_strtoull(const char *str, char **endptr, int base)
cPtr += 2;
} else {
base = 8;
- }
+ }
}
PR_ASSERT(base != 0);
LL_I2L(base64, base);
@@ -230,8 +230,8 @@ GetInt(ScanfState *state, int code)
*p++ = ch;
GET_IF_WITHIN_WIDTH(state, ch);
if (WITHIN_WIDTH(state)
- && (ch == 'x' || ch == 'X')
- && (base == 0 || base == 16)) {
+ && (ch == 'x' || ch == 'X')
+ && (base == 0 || base == 16)) {
base = 16;
*p++ = ch;
GET_IF_WITHIN_WIDTH(state, ch);
@@ -365,11 +365,7 @@ GetFloat(ScanfState *state)
if (state->sizeSpec == _PR_size_l) {
*va_arg(state->ap, PRFloat64 *) = dval;
} else if (state->sizeSpec == _PR_size_L) {
-#if defined(OSF1) || defined(IRIX)
- *va_arg(state->ap, double *) = dval;
-#else
*va_arg(state->ap, long double *) = dval;
-#endif
} else {
*va_arg(state->ap, float *) = (float) dval;
}
@@ -482,45 +478,45 @@ Convert(ScanfState *state, const char *fmt)
}
break;
case '[':
- {
- PRBool complement = PR_FALSE;
- const char *closeBracket;
- size_t n;
+ {
+ PRBool complement = PR_FALSE;
+ const char *closeBracket;
+ size_t n;
- if (*++cPtr == '^') {
- complement = PR_TRUE;
- cPtr++;
- }
- closeBracket = strchr(*cPtr == ']' ? cPtr + 1 : cPtr, ']');
- if (closeBracket == NULL) {
- return NULL;
- }
- n = closeBracket - cPtr;
- if (state->width == 0) {
- state->width = INT_MAX;
- }
- if (state->assign) {
- cArg = va_arg(state->ap, char *);
- }
- for (; state->width > 0; state->width--) {
- ch = GET(state);
- if ((ch == EOF)
- || (!complement && !memchr(cPtr, ch, n))
- || (complement && memchr(cPtr, ch, n))) {
- UNGET(state, ch);
- break;
- }
- if (state->assign) {
- *cArg++ = ch;
- }
+ if (*++cPtr == '^') {
+ complement = PR_TRUE;
+ cPtr++;
+ }
+ closeBracket = strchr(*cPtr == ']' ? cPtr + 1 : cPtr, ']');
+ if (closeBracket == NULL) {
+ return NULL;
+ }
+ n = closeBracket - cPtr;
+ if (state->width == 0) {
+ state->width = INT_MAX;
+ }
+ if (state->assign) {
+ cArg = va_arg(state->ap, char *);
+ }
+ for (; state->width > 0; state->width--) {
+ ch = GET(state);
+ if ((ch == EOF)
+ || (!complement && !memchr(cPtr, ch, n))
+ || (complement && memchr(cPtr, ch, n))) {
+ UNGET(state, ch);
+ break;
}
if (state->assign) {
- *cArg = '\0';
- state->converted = PR_TRUE;
+ *cArg++ = ch;
}
- cPtr = closeBracket;
}
- break;
+ if (state->assign) {
+ *cArg = '\0';
+ state->converted = PR_TRUE;
+ }
+ cPtr = closeBracket;
+ }
+ break;
default:
return NULL;
}
diff --git a/nsprpub/pr/src/io/prsocket.c b/nsprpub/pr/src/io/prsocket.c
index 26f7a245d..e0f917c16 100644
--- a/nsprpub/pr/src/io/prsocket.c
+++ b/nsprpub/pr/src/io/prsocket.c
@@ -22,10 +22,10 @@ PRBool IsValidNetAddr(const PRNetAddr *addr)
{
if ((addr != NULL)
#if defined(XP_UNIX) || defined(XP_OS2)
- && (addr->raw.family != PR_AF_LOCAL)
+ && (addr->raw.family != PR_AF_LOCAL)
#endif
- && (addr->raw.family != PR_AF_INET6)
- && (addr->raw.family != PR_AF_INET)) {
+ && (addr->raw.family != PR_AF_INET6)
+ && (addr->raw.family != PR_AF_INET)) {
return PR_FALSE;
}
return PR_TRUE;
@@ -39,9 +39,9 @@ static PRBool IsValidNetAddrLen(const PRNetAddr *addr, PRInt32 addr_len)
*/
if ((addr != NULL)
#if defined(XP_UNIX) || defined(XP_OS2)
- && (addr->raw.family != AF_UNIX)
+ && (addr->raw.family != AF_UNIX)
#endif
- && (PR_NETADDR_SIZE(addr) != addr_len)) {
+ && (PR_NETADDR_SIZE(addr) != addr_len)) {
#if defined(LINUX) && __GLIBC__ == 2 && __GLIBC_MINOR__ == 1
/*
* In glibc 2.1, struct sockaddr_in6 is 24 bytes. In glibc 2.2
@@ -51,7 +51,7 @@ static PRBool IsValidNetAddrLen(const PRNetAddr *addr, PRInt32 addr_len)
* We need to allow that. (Bugzilla bug #77264)
*/
if ((PR_AF_INET6 == addr->raw.family)
- && (sizeof(addr->ipv6) == addr_len)) {
+ && (sizeof(addr->ipv6) == addr_len)) {
return PR_TRUE;
}
#endif
@@ -74,129 +74,138 @@ static PRBool IsValidNetAddrLen(const PRNetAddr *addr, PRInt32 addr_len)
#endif /* DEBUG */
static PRInt32 PR_CALLBACK SocketWritev(PRFileDesc *fd, const PRIOVec *iov,
-PRInt32 iov_size, PRIntervalTime timeout)
+ PRInt32 iov_size, PRIntervalTime timeout)
{
- PRThread *me = _PR_MD_CURRENT_THREAD();
- int w = 0;
- const PRIOVec *tmp_iov;
+ PRThread *me = _PR_MD_CURRENT_THREAD();
+ int w = 0;
+ const PRIOVec *tmp_iov;
#define LOCAL_MAXIOV 8
- PRIOVec local_iov[LOCAL_MAXIOV];
- PRIOVec *iov_copy = NULL;
- int tmp_out;
- int index, iov_cnt;
- int count=0, sz = 0; /* 'count' is the return value. */
-
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- return -1;
- }
- if (_PR_IO_PENDING(me)) {
- PR_SetError(PR_IO_PENDING_ERROR, 0);
- return -1;
- }
+ PRIOVec local_iov[LOCAL_MAXIOV];
+ PRIOVec *iov_copy = NULL;
+ int tmp_out;
+ int index, iov_cnt;
+ int count=0, sz = 0; /* 'count' is the return value. */
+
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ return -1;
+ }
+ if (_PR_IO_PENDING(me)) {
+ PR_SetError(PR_IO_PENDING_ERROR, 0);
+ return -1;
+ }
/*
* Assume the first writev will succeed. Copy iov's only on
* failure.
*/
tmp_iov = iov;
- for (index = 0; index < iov_size; index++)
+ for (index = 0; index < iov_size; index++) {
sz += iov[index].iov_len;
+ }
+
+ iov_cnt = iov_size;
+
+ while (sz > 0) {
+
+ w = _PR_MD_WRITEV(fd, tmp_iov, iov_cnt, timeout);
+ if (w < 0) {
+ count = -1;
+ break;
+ }
+ count += w;
+ if (fd->secret->nonblocking) {
+ break;
+ }
+ sz -= w;
+
+ if (sz > 0) {
+ /* find the next unwritten vector */
+ for ( index = 0, tmp_out = count;
+ tmp_out >= iov[index].iov_len;
+ tmp_out -= iov[index].iov_len, index++) {;} /* nothing to execute */
+
+ if (tmp_iov == iov) {
+ /*
+ * The first writev failed so we
+ * must copy iov's around.
+ * Avoid calloc/free if there
+ * are few enough iov's.
+ */
+ if (iov_size - index <= LOCAL_MAXIOV) {
+ iov_copy = local_iov;
+ }
+ else if ((iov_copy = (PRIOVec *) PR_CALLOC((iov_size - index) *
+ sizeof *iov_copy)) == NULL) {
+ PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+ return -1;
+ }
+ tmp_iov = iov_copy;
+ }
+
+ PR_ASSERT(tmp_iov == iov_copy);
+
+ /* fill in the first partial read */
+ iov_copy[0].iov_base = &(((char *)iov[index].iov_base)[tmp_out]);
+ iov_copy[0].iov_len = iov[index].iov_len - tmp_out;
+ index++;
+
+ /* copy the remaining vectors */
+ for (iov_cnt=1; index<iov_size; iov_cnt++, index++) {
+ iov_copy[iov_cnt].iov_base = iov[index].iov_base;
+ iov_copy[iov_cnt].iov_len = iov[index].iov_len;
+ }
+ }
+ }
- iov_cnt = iov_size;
-
- while (sz > 0) {
-
- w = _PR_MD_WRITEV(fd, tmp_iov, iov_cnt, timeout);
- if (w < 0) {
- count = -1;
- break;
- }
- count += w;
- if (fd->secret->nonblocking) {
- break;
- }
- sz -= w;
-
- if (sz > 0) {
- /* find the next unwritten vector */
- for ( index = 0, tmp_out = count;
- tmp_out >= iov[index].iov_len;
- tmp_out -= iov[index].iov_len, index++){;} /* nothing to execute */
-
- if (tmp_iov == iov) {
- /*
- * The first writev failed so we
- * must copy iov's around.
- * Avoid calloc/free if there
- * are few enough iov's.
- */
- if (iov_size - index <= LOCAL_MAXIOV)
- iov_copy = local_iov;
- else if ((iov_copy = (PRIOVec *) PR_CALLOC((iov_size - index) *
- sizeof *iov_copy)) == NULL) {
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
- return -1;
- }
- tmp_iov = iov_copy;
- }
-
- PR_ASSERT(tmp_iov == iov_copy);
-
- /* fill in the first partial read */
- iov_copy[0].iov_base = &(((char *)iov[index].iov_base)[tmp_out]);
- iov_copy[0].iov_len = iov[index].iov_len - tmp_out;
- index++;
-
- /* copy the remaining vectors */
- for (iov_cnt=1; index<iov_size; iov_cnt++, index++) {
- iov_copy[iov_cnt].iov_base = iov[index].iov_base;
- iov_copy[iov_cnt].iov_len = iov[index].iov_len;
- }
- }
- }
-
- if (iov_copy != local_iov)
- PR_DELETE(iov_copy);
- return count;
+ if (iov_copy != local_iov) {
+ PR_DELETE(iov_copy);
+ }
+ return count;
}
/************************************************************************/
PR_IMPLEMENT(PRFileDesc *) PR_ImportTCPSocket(PROsfd osfd)
{
-PRFileDesc *fd;
+ PRFileDesc *fd;
- if (!_pr_initialized) _PR_ImplicitInitialization();
- fd = PR_AllocFileDesc(osfd, PR_GetTCPMethods());
- if (fd != NULL) {
- _PR_MD_MAKE_NONBLOCK(fd);
- _PR_MD_INIT_FD_INHERITABLE(fd, PR_TRUE);
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
+ fd = PR_AllocFileDesc(osfd, PR_GetTCPMethods());
+ if (fd != NULL) {
+ _PR_MD_MAKE_NONBLOCK(fd);
+ _PR_MD_INIT_FD_INHERITABLE(fd, PR_TRUE);
#ifdef _PR_NEED_SECRET_AF
- /* this means we can only import IPv4 sockets here.
- * but this is what the function in ptio.c does.
- * We need a way to import IPv6 sockets, too.
- */
- fd->secret->af = AF_INET;
+ /* this means we can only import IPv4 sockets here.
+ * but this is what the function in ptio.c does.
+ * We need a way to import IPv6 sockets, too.
+ */
+ fd->secret->af = AF_INET;
#endif
- } else
- _PR_MD_CLOSE_SOCKET(osfd);
- return(fd);
+ } else {
+ _PR_MD_CLOSE_SOCKET(osfd);
+ }
+ return(fd);
}
PR_IMPLEMENT(PRFileDesc *) PR_ImportUDPSocket(PROsfd osfd)
{
-PRFileDesc *fd;
-
- if (!_pr_initialized) _PR_ImplicitInitialization();
- fd = PR_AllocFileDesc(osfd, PR_GetUDPMethods());
- if (fd != NULL) {
- _PR_MD_MAKE_NONBLOCK(fd);
- _PR_MD_INIT_FD_INHERITABLE(fd, PR_TRUE);
- } else
- _PR_MD_CLOSE_SOCKET(osfd);
- return(fd);
+ PRFileDesc *fd;
+
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
+ fd = PR_AllocFileDesc(osfd, PR_GetUDPMethods());
+ if (fd != NULL) {
+ _PR_MD_MAKE_NONBLOCK(fd);
+ _PR_MD_INIT_FD_INHERITABLE(fd, PR_TRUE);
+ } else {
+ _PR_MD_CLOSE_SOCKET(osfd);
+ }
+ return(fd);
}
@@ -206,16 +215,20 @@ PR_IMPLEMENT(PRFileDesc*) PR_CreateSocketPollFd(PROsfd osfd)
{
PRFileDesc *fd;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
fd = _PR_Getfd();
- if (fd == NULL) PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+ if (fd == NULL) {
+ PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+ }
else
{
fd->secret->md.osfd = osfd;
fd->secret->inheritable = _PR_TRI_FALSE;
- fd->secret->state = _PR_FILEDESC_OPEN;
+ fd->secret->state = _PR_FILEDESC_OPEN;
fd->methods = PR_GetSocketPollFdMethods();
}
@@ -237,32 +250,34 @@ PR_IMPLEMENT(PRStatus) PR_DestroySocketPollFd(PRFileDesc *fd)
static PRStatus PR_CALLBACK SocketConnect(
PRFileDesc *fd, const PRNetAddr *addr, PRIntervalTime timeout)
{
- PRInt32 rv; /* Return value of _PR_MD_CONNECT */
+ PRInt32 rv; /* Return value of _PR_MD_CONNECT */
const PRNetAddr *addrp = addr;
#if defined(_PR_INET6)
- PRNetAddr addrCopy;
+ PRNetAddr addrCopy;
#endif
- PRThread *me = _PR_MD_CURRENT_THREAD();
+ PRThread *me = _PR_MD_CURRENT_THREAD();
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- return PR_FAILURE;
- }
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ return PR_FAILURE;
+ }
#if defined(_PR_INET6)
- if (addr->raw.family == PR_AF_INET6) {
- addrCopy = *addr;
- addrCopy.raw.family = AF_INET6;
- addrp = &addrCopy;
- }
+ if (addr->raw.family == PR_AF_INET6) {
+ addrCopy = *addr;
+ addrCopy.raw.family = AF_INET6;
+ addrp = &addrCopy;
+ }
#endif
- rv = _PR_MD_CONNECT(fd, addrp, PR_NETADDR_SIZE(addr), timeout);
- PR_LOG(_pr_io_lm, PR_LOG_MAX, ("connect -> %d", rv));
- if (rv == 0)
- return PR_SUCCESS;
- else
- return PR_FAILURE;
+ rv = _PR_MD_CONNECT(fd, addrp, PR_NETADDR_SIZE(addr), timeout);
+ PR_LOG(_pr_io_lm, PR_LOG_MAX, ("connect -> %d", rv));
+ if (rv == 0) {
+ return PR_SUCCESS;
+ }
+ else {
+ return PR_FAILURE;
+ }
}
static PRStatus PR_CALLBACK SocketConnectContinue(
@@ -297,7 +312,7 @@ static PRStatus PR_CALLBACK SocketConnectContinue(
if (out_flags & PR_POLL_EXCEPT) {
int len = sizeof(err);
if (getsockopt(osfd, (int)SOL_SOCKET, SO_ERROR, (char *) &err, &len)
- == SOCKET_ERROR) {
+ == SOCKET_ERROR) {
_PR_MD_MAP_GETSOCKOPT_ERROR(WSAGetLastError());
return PR_FAILURE;
}
@@ -342,7 +357,7 @@ static PRStatus PR_CALLBACK SocketConnectContinue(
if (GetOverlappedResult(osfd, &fd->secret->ol, &rvSent, FALSE) == TRUE) {
fd->secret->overlappedActive = PR_FALSE;
PR_LOG(_pr_io_lm, PR_LOG_MIN,
- ("SocketConnectContinue GetOverlappedResult succeeded\n"));
+ ("SocketConnectContinue GetOverlappedResult succeeded\n"));
/* When ConnectEx is used, all previously set socket options and
* property are not enabled and to enable them
* SO_UPDATE_CONNECT_CONTEXT option need to be set. */
@@ -357,7 +372,7 @@ static PRStatus PR_CALLBACK SocketConnectContinue(
} else {
err = WSAGetLastError();
PR_LOG(_pr_io_lm, PR_LOG_MIN,
- ("SocketConnectContinue GetOverlappedResult failed %d\n", err));
+ ("SocketConnectContinue GetOverlappedResult failed %d\n", err));
if (err != ERROR_IO_INCOMPLETE) {
_PR_MD_MAP_CONNECT_ERROR(err);
fd->secret->overlappedActive = PR_FALSE;
@@ -381,25 +396,6 @@ static PRStatus PR_CALLBACK SocketConnectContinue(
}
return PR_SUCCESS;
-#elif defined(XP_BEOS)
-
-#ifdef BONE_VERSION /* bug 122364 */
- /* temporary workaround until getsockopt(SO_ERROR) works in BONE */
- if (out_flags & PR_POLL_EXCEPT) {
- PR_SetError(PR_CONNECT_REFUSED_ERROR, 0);
- return PR_FAILURE;
- }
- PR_ASSERT(out_flags & PR_POLL_WRITE);
- return PR_SUCCESS;
-#else
- err = _MD_beos_get_nonblocking_connect_error(fd);
- if( err != 0 ) {
- _PR_MD_MAP_CONNECT_ERROR(err);
- return PR_FAILURE;
- }
- else
- return PR_SUCCESS;
-#endif /* BONE_VERSION */
#else
PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
@@ -420,402 +416,405 @@ PR_IMPLEMENT(PRStatus) PR_GetConnectStatus(const PRPollDesc *pd)
}
static PRFileDesc* PR_CALLBACK SocketAccept(PRFileDesc *fd, PRNetAddr *addr,
-PRIntervalTime timeout)
+ PRIntervalTime timeout)
{
- PROsfd osfd;
- PRFileDesc *fd2;
- PRUint32 al;
- PRThread *me = _PR_MD_CURRENT_THREAD();
+ PROsfd osfd;
+ PRFileDesc *fd2;
+ PRUint32 al;
+ PRThread *me = _PR_MD_CURRENT_THREAD();
#ifdef WINNT
- PRNetAddr addrCopy;
+ PRNetAddr addrCopy;
#endif
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- return 0;
- }
- if (_PR_IO_PENDING(me)) {
- PR_SetError(PR_IO_PENDING_ERROR, 0);
- return 0;
- }
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ return 0;
+ }
+ if (_PR_IO_PENDING(me)) {
+ PR_SetError(PR_IO_PENDING_ERROR, 0);
+ return 0;
+ }
#ifdef WINNT
- if (addr == NULL) {
- addr = &addrCopy;
- }
+ if (addr == NULL) {
+ addr = &addrCopy;
+ }
#endif
- al = sizeof(PRNetAddr);
- osfd = _PR_MD_ACCEPT(fd, addr, &al, timeout);
- if (osfd == -1)
- return 0;
-
- fd2 = PR_AllocFileDesc(osfd, PR_GetTCPMethods());
- if (!fd2) {
- _PR_MD_CLOSE_SOCKET(osfd);
- return NULL;
- }
-
- fd2->secret->nonblocking = fd->secret->nonblocking;
- fd2->secret->inheritable = fd->secret->inheritable;
+ al = sizeof(PRNetAddr);
+ osfd = _PR_MD_ACCEPT(fd, addr, &al, timeout);
+ if (osfd == -1) {
+ return 0;
+ }
+
+ fd2 = PR_AllocFileDesc(osfd, PR_GetTCPMethods());
+ if (!fd2) {
+ _PR_MD_CLOSE_SOCKET(osfd);
+ return NULL;
+ }
+
+ fd2->secret->nonblocking = fd->secret->nonblocking;
+ fd2->secret->inheritable = fd->secret->inheritable;
#ifdef WINNT
- if (!fd2->secret->nonblocking && fd2->secret->inheritable != _PR_TRI_TRUE) {
- /*
- * The new socket has been associated with an I/O
- * completion port. There is no going back.
- */
- fd2->secret->md.io_model_committed = PR_TRUE;
- }
- PR_ASSERT(al == PR_NETADDR_SIZE(addr));
- fd2->secret->md.accepted_socket = PR_TRUE;
- memcpy(&fd2->secret->md.peer_addr, addr, al);
+ if (!fd2->secret->nonblocking && fd2->secret->inheritable != _PR_TRI_TRUE) {
+ /*
+ * The new socket has been associated with an I/O
+ * completion port. There is no going back.
+ */
+ fd2->secret->md.io_model_committed = PR_TRUE;
+ }
+ PR_ASSERT(al == PR_NETADDR_SIZE(addr));
+ fd2->secret->md.accepted_socket = PR_TRUE;
+ memcpy(&fd2->secret->md.peer_addr, addr, al);
#endif
- /*
- * On some platforms, the new socket created by accept()
- * inherits the nonblocking (or overlapped io) attribute
- * of the listening socket. As an optimization, these
- * platforms can skip the following _PR_MD_MAKE_NONBLOCK
- * call.
- */
-#if !defined(SOLARIS) && !defined(IRIX) && !defined(WINNT)
- _PR_MD_MAKE_NONBLOCK(fd2);
+ /*
+ * On some platforms, the new socket created by accept()
+ * inherits the nonblocking (or overlapped io) attribute
+ * of the listening socket. As an optimization, these
+ * platforms can skip the following _PR_MD_MAKE_NONBLOCK
+ * call.
+ */
+#if !defined(SOLARIS) && !defined(WINNT)
+ _PR_MD_MAKE_NONBLOCK(fd2);
#endif
#ifdef _PR_INET6
- if (addr && (AF_INET6 == addr->raw.family))
+ if (addr && (AF_INET6 == addr->raw.family)) {
addr->raw.family = PR_AF_INET6;
+ }
#endif
- PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
- PR_ASSERT(IsValidNetAddrLen(addr, al) == PR_TRUE);
+ PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
+ PR_ASSERT(IsValidNetAddrLen(addr, al) == PR_TRUE);
- return fd2;
+ return fd2;
}
#ifdef WINNT
PR_IMPLEMENT(PRFileDesc*) PR_NTFast_Accept(PRFileDesc *fd, PRNetAddr *addr,
-PRIntervalTime timeout)
+ PRIntervalTime timeout)
{
- PROsfd osfd;
- PRFileDesc *fd2;
- PRIntn al;
- PRThread *me = _PR_MD_CURRENT_THREAD();
- PRNetAddr addrCopy;
-
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- return 0;
- }
- if (_PR_IO_PENDING(me)) {
- PR_SetError(PR_IO_PENDING_ERROR, 0);
- return 0;
- }
-
- if (addr == NULL) {
- addr = &addrCopy;
- }
- al = PR_NETADDR_SIZE(addr);
- osfd = _PR_MD_FAST_ACCEPT(fd, addr, &al, timeout, PR_TRUE, NULL, NULL);
- if (osfd == -1) {
- return 0;
- }
-
- fd2 = PR_AllocFileDesc(osfd, PR_GetTCPMethods());
- if (!fd2) {
- _PR_MD_CLOSE_SOCKET(osfd);
- } else {
- fd2->secret->nonblocking = fd->secret->nonblocking;
- fd2->secret->md.io_model_committed = PR_TRUE;
- PR_ASSERT(al == PR_NETADDR_SIZE(addr));
- fd2->secret->md.accepted_socket = PR_TRUE;
- memcpy(&fd2->secret->md.peer_addr, addr, al);
+ PROsfd osfd;
+ PRFileDesc *fd2;
+ PRIntn al;
+ PRThread *me = _PR_MD_CURRENT_THREAD();
+ PRNetAddr addrCopy;
+
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ return 0;
+ }
+ if (_PR_IO_PENDING(me)) {
+ PR_SetError(PR_IO_PENDING_ERROR, 0);
+ return 0;
+ }
+
+ if (addr == NULL) {
+ addr = &addrCopy;
+ }
+ al = PR_NETADDR_SIZE(addr);
+ osfd = _PR_MD_FAST_ACCEPT(fd, addr, &al, timeout, PR_TRUE, NULL, NULL);
+ if (osfd == -1) {
+ return 0;
+ }
+
+ fd2 = PR_AllocFileDesc(osfd, PR_GetTCPMethods());
+ if (!fd2) {
+ _PR_MD_CLOSE_SOCKET(osfd);
+ } else {
+ fd2->secret->nonblocking = fd->secret->nonblocking;
+ fd2->secret->md.io_model_committed = PR_TRUE;
+ PR_ASSERT(al == PR_NETADDR_SIZE(addr));
+ fd2->secret->md.accepted_socket = PR_TRUE;
+ memcpy(&fd2->secret->md.peer_addr, addr, al);
#ifdef _PR_INET6
- if (AF_INET6 == addr->raw.family)
- addr->raw.family = PR_AF_INET6;
+ if (AF_INET6 == addr->raw.family) {
+ addr->raw.family = PR_AF_INET6;
+ }
#endif
#ifdef _PR_NEED_SECRET_AF
- fd2->secret->af = fd->secret->af;
+ fd2->secret->af = fd->secret->af;
#endif
- }
- return fd2;
+ }
+ return fd2;
}
#endif /* WINNT */
static PRStatus PR_CALLBACK SocketBind(PRFileDesc *fd, const PRNetAddr *addr)
{
- PRInt32 result;
+ PRInt32 result;
const PRNetAddr *addrp = addr;
#if defined(_PR_INET6)
- PRNetAddr addrCopy;
+ PRNetAddr addrCopy;
#endif
- PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
+ PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
#ifdef XP_UNIX
- if (addr->raw.family == AF_UNIX) {
- /* Disallow relative pathnames */
- if (addr->local.path[0] != '/') {
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
- return PR_FAILURE;
- }
- }
+ if (addr->raw.family == AF_UNIX) {
+ /* Disallow relative pathnames */
+ if (addr->local.path[0] != '/') {
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+ return PR_FAILURE;
+ }
+ }
#endif /* XP_UNIX */
#if defined(_PR_INET6)
- if (addr->raw.family == PR_AF_INET6) {
- addrCopy = *addr;
- addrCopy.raw.family = AF_INET6;
- addrp = &addrCopy;
- }
+ if (addr->raw.family == PR_AF_INET6) {
+ addrCopy = *addr;
+ addrCopy.raw.family = AF_INET6;
+ addrp = &addrCopy;
+ }
#endif
- result = _PR_MD_BIND(fd, addrp, PR_NETADDR_SIZE(addr));
- if (result < 0) {
- return PR_FAILURE;
- }
- return PR_SUCCESS;
+ result = _PR_MD_BIND(fd, addrp, PR_NETADDR_SIZE(addr));
+ if (result < 0) {
+ return PR_FAILURE;
+ }
+ return PR_SUCCESS;
}
static PRStatus PR_CALLBACK SocketListen(PRFileDesc *fd, PRIntn backlog)
{
- PRInt32 result;
+ PRInt32 result;
- result = _PR_MD_LISTEN(fd, backlog);
- if (result < 0) {
- return PR_FAILURE;
- }
- return PR_SUCCESS;
+ result = _PR_MD_LISTEN(fd, backlog);
+ if (result < 0) {
+ return PR_FAILURE;
+ }
+ return PR_SUCCESS;
}
static PRStatus PR_CALLBACK SocketShutdown(PRFileDesc *fd, PRIntn how)
{
- PRInt32 result;
+ PRInt32 result;
- result = _PR_MD_SHUTDOWN(fd, how);
- if (result < 0) {
- return PR_FAILURE;
- }
- return PR_SUCCESS;
+ result = _PR_MD_SHUTDOWN(fd, how);
+ if (result < 0) {
+ return PR_FAILURE;
+ }
+ return PR_SUCCESS;
}
static PRInt32 PR_CALLBACK SocketRecv(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
-PRIntervalTime timeout)
+ PRIntervalTime timeout)
{
- PRInt32 rv;
- PRThread *me = _PR_MD_CURRENT_THREAD();
-
- if ((flags != 0) && (flags != PR_MSG_PEEK)) {
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
- return -1;
- }
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- return -1;
- }
- if (_PR_IO_PENDING(me)) {
- PR_SetError(PR_IO_PENDING_ERROR, 0);
- return -1;
- }
-
- PR_LOG(_pr_io_lm, PR_LOG_MAX,
- ("recv: fd=%p osfd=%" PR_PRIdOSFD " buf=%p amount=%d flags=%d",
- fd, fd->secret->md.osfd, buf, amount, flags));
+ PRInt32 rv;
+ PRThread *me = _PR_MD_CURRENT_THREAD();
+
+ if ((flags != 0) && (flags != PR_MSG_PEEK)) {
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+ return -1;
+ }
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ return -1;
+ }
+ if (_PR_IO_PENDING(me)) {
+ PR_SetError(PR_IO_PENDING_ERROR, 0);
+ return -1;
+ }
+
+ PR_LOG(_pr_io_lm, PR_LOG_MAX,
+ ("recv: fd=%p osfd=%" PR_PRIdOSFD " buf=%p amount=%d flags=%d",
+ fd, fd->secret->md.osfd, buf, amount, flags));
#ifdef _PR_HAVE_PEEK_BUFFER
- if (fd->secret->peekBytes != 0) {
- rv = (amount < fd->secret->peekBytes) ?
- amount : fd->secret->peekBytes;
- memcpy(buf, fd->secret->peekBuffer, rv);
- if (flags == 0) {
- /* consume the bytes in the peek buffer */
- fd->secret->peekBytes -= rv;
- if (fd->secret->peekBytes != 0) {
- memmove(fd->secret->peekBuffer,
- fd->secret->peekBuffer + rv,
- fd->secret->peekBytes);
- }
- }
- return rv;
- }
-
- /* allocate peek buffer, if necessary */
- if ((PR_MSG_PEEK == flags) && _PR_FD_NEED_EMULATE_MSG_PEEK(fd)) {
- PR_ASSERT(0 == fd->secret->peekBytes);
- /* impose a max size on the peek buffer */
- if (amount > _PR_PEEK_BUFFER_MAX) {
- amount = _PR_PEEK_BUFFER_MAX;
- }
- if (fd->secret->peekBufSize < amount) {
- if (fd->secret->peekBuffer) {
- PR_Free(fd->secret->peekBuffer);
- }
- fd->secret->peekBufSize = amount;
- fd->secret->peekBuffer = PR_Malloc(amount);
- if (NULL == fd->secret->peekBuffer) {
- fd->secret->peekBufSize = 0;
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
- return -1;
- }
- }
- }
+ if (fd->secret->peekBytes != 0) {
+ rv = (amount < fd->secret->peekBytes) ?
+ amount : fd->secret->peekBytes;
+ memcpy(buf, fd->secret->peekBuffer, rv);
+ if (flags == 0) {
+ /* consume the bytes in the peek buffer */
+ fd->secret->peekBytes -= rv;
+ if (fd->secret->peekBytes != 0) {
+ memmove(fd->secret->peekBuffer,
+ fd->secret->peekBuffer + rv,
+ fd->secret->peekBytes);
+ }
+ }
+ return rv;
+ }
+
+ /* allocate peek buffer, if necessary */
+ if ((PR_MSG_PEEK == flags) && _PR_FD_NEED_EMULATE_MSG_PEEK(fd)) {
+ PR_ASSERT(0 == fd->secret->peekBytes);
+ /* impose a max size on the peek buffer */
+ if (amount > _PR_PEEK_BUFFER_MAX) {
+ amount = _PR_PEEK_BUFFER_MAX;
+ }
+ if (fd->secret->peekBufSize < amount) {
+ if (fd->secret->peekBuffer) {
+ PR_Free(fd->secret->peekBuffer);
+ }
+ fd->secret->peekBufSize = amount;
+ fd->secret->peekBuffer = PR_Malloc(amount);
+ if (NULL == fd->secret->peekBuffer) {
+ fd->secret->peekBufSize = 0;
+ PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+ return -1;
+ }
+ }
+ }
#endif
- rv = _PR_MD_RECV(fd, buf, amount, flags, timeout);
- PR_LOG(_pr_io_lm, PR_LOG_MAX, ("recv -> %d, error = %d, os error = %d",
- rv, PR_GetError(), PR_GetOSError()));
+ rv = _PR_MD_RECV(fd, buf, amount, flags, timeout);
+ PR_LOG(_pr_io_lm, PR_LOG_MAX, ("recv -> %d, error = %d, os error = %d",
+ rv, PR_GetError(), PR_GetOSError()));
#ifdef _PR_HAVE_PEEK_BUFFER
- if ((PR_MSG_PEEK == flags) && _PR_FD_NEED_EMULATE_MSG_PEEK(fd)) {
- if (rv > 0) {
- memcpy(fd->secret->peekBuffer, buf, rv);
- fd->secret->peekBytes = rv;
- }
- }
+ if ((PR_MSG_PEEK == flags) && _PR_FD_NEED_EMULATE_MSG_PEEK(fd)) {
+ if (rv > 0) {
+ memcpy(fd->secret->peekBuffer, buf, rv);
+ fd->secret->peekBytes = rv;
+ }
+ }
#endif
- return rv;
+ return rv;
}
static PRInt32 PR_CALLBACK SocketRead(PRFileDesc *fd, void *buf, PRInt32 amount)
{
- return SocketRecv(fd, buf, amount, 0, PR_INTERVAL_NO_TIMEOUT);
+ return SocketRecv(fd, buf, amount, 0, PR_INTERVAL_NO_TIMEOUT);
}
static PRInt32 PR_CALLBACK SocketSend(PRFileDesc *fd, const void *buf, PRInt32 amount,
-PRIntn flags, PRIntervalTime timeout)
+ PRIntn flags, PRIntervalTime timeout)
{
- PRInt32 temp, count;
- PRThread *me = _PR_MD_CURRENT_THREAD();
-
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- return -1;
- }
- if (_PR_IO_PENDING(me)) {
- PR_SetError(PR_IO_PENDING_ERROR, 0);
- return -1;
- }
-
- count = 0;
- while (amount > 0) {
- PR_LOG(_pr_io_lm, PR_LOG_MAX,
- ("send: fd=%p osfd=%" PR_PRIdOSFD " buf=%p amount=%d",
- fd, fd->secret->md.osfd, buf, amount));
- temp = _PR_MD_SEND(fd, buf, amount, flags, timeout);
- if (temp < 0) {
- count = -1;
- break;
- }
-
- count += temp;
- if (fd->secret->nonblocking) {
- break;
- }
- buf = (const void*) ((const char*)buf + temp);
-
- amount -= temp;
- }
- PR_LOG(_pr_io_lm, PR_LOG_MAX, ("send -> %d", count));
- return count;
+ PRInt32 temp, count;
+ PRThread *me = _PR_MD_CURRENT_THREAD();
+
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ return -1;
+ }
+ if (_PR_IO_PENDING(me)) {
+ PR_SetError(PR_IO_PENDING_ERROR, 0);
+ return -1;
+ }
+
+ count = 0;
+ while (amount > 0) {
+ PR_LOG(_pr_io_lm, PR_LOG_MAX,
+ ("send: fd=%p osfd=%" PR_PRIdOSFD " buf=%p amount=%d",
+ fd, fd->secret->md.osfd, buf, amount));
+ temp = _PR_MD_SEND(fd, buf, amount, flags, timeout);
+ if (temp < 0) {
+ count = -1;
+ break;
+ }
+
+ count += temp;
+ if (fd->secret->nonblocking) {
+ break;
+ }
+ buf = (const void*) ((const char*)buf + temp);
+
+ amount -= temp;
+ }
+ PR_LOG(_pr_io_lm, PR_LOG_MAX, ("send -> %d", count));
+ return count;
}
static PRInt32 PR_CALLBACK SocketWrite(PRFileDesc *fd, const void *buf, PRInt32 amount)
{
- return SocketSend(fd, buf, amount, 0, PR_INTERVAL_NO_TIMEOUT);
+ return SocketSend(fd, buf, amount, 0, PR_INTERVAL_NO_TIMEOUT);
}
static PRStatus PR_CALLBACK SocketClose(PRFileDesc *fd)
{
- if (!fd || !fd->secret
- || (fd->secret->state != _PR_FILEDESC_OPEN
- && fd->secret->state != _PR_FILEDESC_CLOSED)) {
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
- return PR_FAILURE;
- }
-
- if (fd->secret->state == _PR_FILEDESC_OPEN) {
+ if (!fd || !fd->secret
+ || (fd->secret->state != _PR_FILEDESC_OPEN
+ && fd->secret->state != _PR_FILEDESC_CLOSED)) {
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
+ return PR_FAILURE;
+ }
+
+ if (fd->secret->state == _PR_FILEDESC_OPEN) {
#if defined(_WIN64) && defined(WIN95)
- /* TCP Fast Open on Windows must use ConnectEx, which uses overlapped
- * input/output. Before closing such a socket we must cancelIO.
- */
- if (fd->secret->overlappedActive) {
- PR_ASSERT(fd->secret->nonblocking);
- if (CancelIo((HANDLE) fd->secret->md.osfd) == TRUE) {
- PR_LOG(_pr_io_lm, PR_LOG_MIN,
- ("SocketClose - CancelIo succeeded\n"));
- } else {
- DWORD err = WSAGetLastError();
- PR_LOG(_pr_io_lm, PR_LOG_MIN,
- ("SocketClose - CancelIo failed err=%x\n", err));
- }
-
- DWORD rvSent;
- if (GetOverlappedResult((HANDLE)fd->secret->md.osfd, &fd->secret->ol, &rvSent, FALSE) == TRUE) {
- fd->secret->overlappedActive = PR_FALSE;
- PR_LOG(_pr_io_lm, PR_LOG_MIN,
- ("SocketClose GetOverlappedResult succeeded\n"));
- } else {
- DWORD err = WSAGetLastError();
- PR_LOG(_pr_io_lm, PR_LOG_MIN,
- ("SocketClose GetOverlappedResult failed %d\n", err));
- if (err != ERROR_IO_INCOMPLETE) {
- _PR_MD_MAP_CONNECT_ERROR(err);
- fd->secret->overlappedActive = PR_FALSE;
+ /* TCP Fast Open on Windows must use ConnectEx, which uses overlapped
+ * input/output. Before closing such a socket we must cancelIO.
+ */
+ if (fd->secret->overlappedActive) {
+ PR_ASSERT(fd->secret->nonblocking);
+ if (CancelIo((HANDLE) fd->secret->md.osfd) == TRUE) {
+ PR_LOG(_pr_io_lm, PR_LOG_MIN,
+ ("SocketClose - CancelIo succeeded\n"));
+ } else {
+ DWORD err = WSAGetLastError();
+ PR_LOG(_pr_io_lm, PR_LOG_MIN,
+ ("SocketClose - CancelIo failed err=%x\n", err));
+ }
+
+ DWORD rvSent;
+ if (GetOverlappedResult((HANDLE)fd->secret->md.osfd, &fd->secret->ol, &rvSent, FALSE) == TRUE) {
+ fd->secret->overlappedActive = PR_FALSE;
+ PR_LOG(_pr_io_lm, PR_LOG_MIN,
+ ("SocketClose GetOverlappedResult succeeded\n"));
+ } else {
+ DWORD err = WSAGetLastError();
+ PR_LOG(_pr_io_lm, PR_LOG_MIN,
+ ("SocketClose GetOverlappedResult failed %d\n", err));
+ if (err != ERROR_IO_INCOMPLETE) {
+ _PR_MD_MAP_CONNECT_ERROR(err);
+ fd->secret->overlappedActive = PR_FALSE;
+ }
+ }
}
- }
- }
- if (fd->secret->overlappedActive &&
- _fd_waiting_for_overlapped_done_lock) {
- // Put osfd into the list to be checked later.
- PRFileDescList *forWaiting = PR_NEW(PRFileDescList);
- if (!forWaiting) {
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
- return PR_FAILURE;
- }
- forWaiting->fd = fd;
+ if (fd->secret->overlappedActive &&
+ _fd_waiting_for_overlapped_done_lock) {
+ // Put osfd into the list to be checked later.
+ PRFileDescList *forWaiting = PR_NEW(PRFileDescList);
+ if (!forWaiting) {
+ PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+ return PR_FAILURE;
+ }
+ forWaiting->fd = fd;
- PR_Lock(_fd_waiting_for_overlapped_done_lock);
- forWaiting->next = _fd_waiting_for_overlapped_done;
- _fd_waiting_for_overlapped_done = forWaiting;
- PR_Unlock(_fd_waiting_for_overlapped_done_lock);
+ PR_Lock(_fd_waiting_for_overlapped_done_lock);
+ forWaiting->next = _fd_waiting_for_overlapped_done;
+ _fd_waiting_for_overlapped_done = forWaiting;
+ PR_Unlock(_fd_waiting_for_overlapped_done_lock);
- return PR_SUCCESS;
- }
+ return PR_SUCCESS;
+ }
#endif
- if (_PR_MD_CLOSE_SOCKET(fd->secret->md.osfd) < 0) {
- return PR_FAILURE;
- }
- fd->secret->state = _PR_FILEDESC_CLOSED;
- }
+ if (_PR_MD_CLOSE_SOCKET(fd->secret->md.osfd) < 0) {
+ return PR_FAILURE;
+ }
+ fd->secret->state = _PR_FILEDESC_CLOSED;
+ }
#ifdef _PR_HAVE_PEEK_BUFFER
- if (fd->secret->peekBuffer) {
- PR_ASSERT(fd->secret->peekBufSize > 0);
- PR_DELETE(fd->secret->peekBuffer);
- fd->secret->peekBufSize = 0;
- fd->secret->peekBytes = 0;
- }
+ if (fd->secret->peekBuffer) {
+ PR_ASSERT(fd->secret->peekBufSize > 0);
+ PR_DELETE(fd->secret->peekBuffer);
+ fd->secret->peekBufSize = 0;
+ fd->secret->peekBytes = 0;
+ }
#endif
- PR_FreeFileDesc(fd);
- return PR_SUCCESS;
+ PR_FreeFileDesc(fd);
+ return PR_SUCCESS;
}
static PRInt32 PR_CALLBACK SocketAvailable(PRFileDesc *fd)
{
- PRInt32 rv;
+ PRInt32 rv;
#ifdef _PR_HAVE_PEEK_BUFFER
- if (fd->secret->peekBytes != 0) {
- return fd->secret->peekBytes;
- }
+ if (fd->secret->peekBytes != 0) {
+ return fd->secret->peekBytes;
+ }
#endif
- rv = _PR_MD_SOCKETAVAILABLE(fd);
- return rv;
+ rv = _PR_MD_SOCKETAVAILABLE(fd);
+ return rv;
}
static PRInt64 PR_CALLBACK SocketAvailable64(PRFileDesc *fd)
@@ -828,60 +827,60 @@ static PRInt64 PR_CALLBACK SocketAvailable64(PRFileDesc *fd)
}
#endif
LL_I2L(rv, _PR_MD_SOCKETAVAILABLE(fd));
- return rv;
+ return rv;
}
static PRStatus PR_CALLBACK SocketSync(PRFileDesc *fd)
{
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
static PRInt32 PR_CALLBACK SocketSendTo(
PRFileDesc *fd, const void *buf, PRInt32 amount,
PRIntn flags, const PRNetAddr *addr, PRIntervalTime timeout)
{
- PRInt32 temp, count;
+ PRInt32 temp, count;
const PRNetAddr *addrp = addr;
#if defined(_PR_INET6)
- PRNetAddr addrCopy;
+ PRNetAddr addrCopy;
#endif
- PRThread *me = _PR_MD_CURRENT_THREAD();
-
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- return -1;
- }
- if (_PR_IO_PENDING(me)) {
- PR_SetError(PR_IO_PENDING_ERROR, 0);
- return -1;
- }
-
- PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
+ PRThread *me = _PR_MD_CURRENT_THREAD();
+
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ return -1;
+ }
+ if (_PR_IO_PENDING(me)) {
+ PR_SetError(PR_IO_PENDING_ERROR, 0);
+ return -1;
+ }
+
+ PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
#if defined(_PR_INET6)
- if (addr->raw.family == PR_AF_INET6) {
- addrCopy = *addr;
- addrCopy.raw.family = AF_INET6;
- addrp = &addrCopy;
- }
+ if (addr->raw.family == PR_AF_INET6) {
+ addrCopy = *addr;
+ addrCopy.raw.family = AF_INET6;
+ addrp = &addrCopy;
+ }
#endif
- count = 0;
- do {
- temp = _PR_MD_SENDTO(fd, buf, amount, flags,
- addrp, PR_NETADDR_SIZE(addr), timeout);
- if (temp < 0) {
- count = -1;
- break;
- }
- count += temp;
- if (fd->secret->nonblocking) {
- break;
- }
- buf = (const void*) ((const char*)buf + temp);
- amount -= temp;
- } while (amount > 0);
- return count;
+ count = 0;
+ do {
+ temp = _PR_MD_SENDTO(fd, buf, amount, flags,
+ addrp, PR_NETADDR_SIZE(addr), timeout);
+ if (temp < 0) {
+ count = -1;
+ break;
+ }
+ count += temp;
+ if (fd->secret->nonblocking) {
+ break;
+ }
+ buf = (const void*) ((const char*)buf + temp);
+ amount -= temp;
+ } while (amount > 0);
+ return count;
}
#if defined(_WIN64) && defined(WIN95)
@@ -935,194 +934,198 @@ static PRInt32 PR_CALLBACK SocketTCPSendTo(
#endif
static PRInt32 PR_CALLBACK SocketRecvFrom(PRFileDesc *fd, void *buf, PRInt32 amount,
-PRIntn flags, PRNetAddr *addr, PRIntervalTime timeout)
+ PRIntn flags, PRNetAddr *addr, PRIntervalTime timeout)
{
- PRInt32 rv;
- PRUint32 al;
- PRThread *me = _PR_MD_CURRENT_THREAD();
-
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- return -1;
- }
- if (_PR_IO_PENDING(me)) {
- PR_SetError(PR_IO_PENDING_ERROR, 0);
- return -1;
- }
-
- al = sizeof(PRNetAddr);
- rv = _PR_MD_RECVFROM(fd, buf, amount, flags, addr, &al, timeout);
+ PRInt32 rv;
+ PRUint32 al;
+ PRThread *me = _PR_MD_CURRENT_THREAD();
+
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ return -1;
+ }
+ if (_PR_IO_PENDING(me)) {
+ PR_SetError(PR_IO_PENDING_ERROR, 0);
+ return -1;
+ }
+
+ al = sizeof(PRNetAddr);
+ rv = _PR_MD_RECVFROM(fd, buf, amount, flags, addr, &al, timeout);
#ifdef _PR_INET6
- if (addr && (AF_INET6 == addr->raw.family))
+ if (addr && (AF_INET6 == addr->raw.family)) {
addr->raw.family = PR_AF_INET6;
+ }
#endif
- return rv;
+ return rv;
}
-static PRInt32 PR_CALLBACK SocketAcceptRead(PRFileDesc *sd, PRFileDesc **nd,
-PRNetAddr **raddr, void *buf, PRInt32 amount,
-PRIntervalTime timeout)
+static PRInt32 PR_CALLBACK SocketAcceptRead(PRFileDesc *sd, PRFileDesc **nd,
+ PRNetAddr **raddr, void *buf, PRInt32 amount,
+ PRIntervalTime timeout)
{
- PRInt32 rv;
- PRThread *me = _PR_MD_CURRENT_THREAD();
-
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- return -1;
- }
- if (_PR_IO_PENDING(me)) {
- PR_SetError(PR_IO_PENDING_ERROR, 0);
- return -1;
- }
- /* The socket must be in blocking mode. */
- if (sd->secret->nonblocking) {
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
- return -1;
- }
- *nd = NULL;
+ PRInt32 rv;
+ PRThread *me = _PR_MD_CURRENT_THREAD();
+
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ return -1;
+ }
+ if (_PR_IO_PENDING(me)) {
+ PR_SetError(PR_IO_PENDING_ERROR, 0);
+ return -1;
+ }
+ /* The socket must be in blocking mode. */
+ if (sd->secret->nonblocking) {
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+ return -1;
+ }
+ *nd = NULL;
#if defined(WINNT)
- {
- PROsfd newSock;
- PRNetAddr *raddrCopy;
-
- if (raddr == NULL) {
- raddr = &raddrCopy;
- }
- rv = _PR_MD_ACCEPT_READ(sd, &newSock, raddr, buf, amount, timeout);
- if (rv < 0) {
- rv = -1;
- } else {
- /* Successfully accepted and read; create the new PRFileDesc */
- *nd = PR_AllocFileDesc(newSock, PR_GetTCPMethods());
- if (*nd == 0) {
- _PR_MD_CLOSE_SOCKET(newSock);
- /* PR_AllocFileDesc() has invoked PR_SetError(). */
- rv = -1;
- } else {
- (*nd)->secret->md.io_model_committed = PR_TRUE;
- (*nd)->secret->md.accepted_socket = PR_TRUE;
- memcpy(&(*nd)->secret->md.peer_addr, *raddr,
- PR_NETADDR_SIZE(*raddr));
+ {
+ PROsfd newSock;
+ PRNetAddr *raddrCopy;
+
+ if (raddr == NULL) {
+ raddr = &raddrCopy;
+ }
+ rv = _PR_MD_ACCEPT_READ(sd, &newSock, raddr, buf, amount, timeout);
+ if (rv < 0) {
+ rv = -1;
+ } else {
+ /* Successfully accepted and read; create the new PRFileDesc */
+ *nd = PR_AllocFileDesc(newSock, PR_GetTCPMethods());
+ if (*nd == 0) {
+ _PR_MD_CLOSE_SOCKET(newSock);
+ /* PR_AllocFileDesc() has invoked PR_SetError(). */
+ rv = -1;
+ } else {
+ (*nd)->secret->md.io_model_committed = PR_TRUE;
+ (*nd)->secret->md.accepted_socket = PR_TRUE;
+ memcpy(&(*nd)->secret->md.peer_addr, *raddr,
+ PR_NETADDR_SIZE(*raddr));
#ifdef _PR_INET6
- if (AF_INET6 == *raddr->raw.family)
- *raddr->raw.family = PR_AF_INET6;
+ if (AF_INET6 == *raddr->raw.family) {
+ *raddr->raw.family = PR_AF_INET6;
+ }
#endif
- }
- }
- }
+ }
+ }
+ }
#else
- rv = PR_EmulateAcceptRead(sd, nd, raddr, buf, amount, timeout);
+ rv = PR_EmulateAcceptRead(sd, nd, raddr, buf, amount, timeout);
#endif
- return rv;
+ return rv;
}
#ifdef WINNT
-PR_IMPLEMENT(PRInt32) PR_NTFast_AcceptRead(PRFileDesc *sd, PRFileDesc **nd,
-PRNetAddr **raddr, void *buf, PRInt32 amount,
-PRIntervalTime timeout)
+PR_IMPLEMENT(PRInt32) PR_NTFast_AcceptRead(PRFileDesc *sd, PRFileDesc **nd,
+ PRNetAddr **raddr, void *buf, PRInt32 amount,
+ PRIntervalTime timeout)
{
- PRInt32 rv;
- PROsfd newSock;
- PRThread *me = _PR_MD_CURRENT_THREAD();
- PRNetAddr *raddrCopy;
-
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- return -1;
- }
- if (_PR_IO_PENDING(me)) {
- PR_SetError(PR_IO_PENDING_ERROR, 0);
- return -1;
- }
- *nd = NULL;
-
- if (raddr == NULL) {
- raddr = &raddrCopy;
- }
- rv = _PR_MD_FAST_ACCEPT_READ(sd, &newSock, raddr, buf, amount,
- timeout, PR_TRUE, NULL, NULL);
- if (rv < 0) {
- rv = -1;
- } else {
- /* Successfully accepted and read; create the new PRFileDesc */
- *nd = PR_AllocFileDesc(newSock, PR_GetTCPMethods());
- if (*nd == 0) {
- _PR_MD_CLOSE_SOCKET(newSock);
- /* PR_AllocFileDesc() has invoked PR_SetError(). */
- rv = -1;
- } else {
- (*nd)->secret->md.io_model_committed = PR_TRUE;
- (*nd)->secret->md.accepted_socket = PR_TRUE;
- memcpy(&(*nd)->secret->md.peer_addr, *raddr,
- PR_NETADDR_SIZE(*raddr));
+ PRInt32 rv;
+ PROsfd newSock;
+ PRThread *me = _PR_MD_CURRENT_THREAD();
+ PRNetAddr *raddrCopy;
+
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ return -1;
+ }
+ if (_PR_IO_PENDING(me)) {
+ PR_SetError(PR_IO_PENDING_ERROR, 0);
+ return -1;
+ }
+ *nd = NULL;
+
+ if (raddr == NULL) {
+ raddr = &raddrCopy;
+ }
+ rv = _PR_MD_FAST_ACCEPT_READ(sd, &newSock, raddr, buf, amount,
+ timeout, PR_TRUE, NULL, NULL);
+ if (rv < 0) {
+ rv = -1;
+ } else {
+ /* Successfully accepted and read; create the new PRFileDesc */
+ *nd = PR_AllocFileDesc(newSock, PR_GetTCPMethods());
+ if (*nd == 0) {
+ _PR_MD_CLOSE_SOCKET(newSock);
+ /* PR_AllocFileDesc() has invoked PR_SetError(). */
+ rv = -1;
+ } else {
+ (*nd)->secret->md.io_model_committed = PR_TRUE;
+ (*nd)->secret->md.accepted_socket = PR_TRUE;
+ memcpy(&(*nd)->secret->md.peer_addr, *raddr,
+ PR_NETADDR_SIZE(*raddr));
#ifdef _PR_INET6
- if (AF_INET6 == *raddr->raw.family)
- *raddr->raw.family = PR_AF_INET6;
+ if (AF_INET6 == *raddr->raw.family) {
+ *raddr->raw.family = PR_AF_INET6;
+ }
#endif
#ifdef _PR_NEED_SECRET_AF
- (*nd)->secret->af = sd->secret->af;
+ (*nd)->secret->af = sd->secret->af;
#endif
- }
- }
- return rv;
+ }
+ }
+ return rv;
}
PR_IMPLEMENT(PRInt32) PR_NTFast_AcceptRead_WithTimeoutCallback(
-PRFileDesc *sd, PRFileDesc **nd,
-PRNetAddr **raddr, void *buf, PRInt32 amount,
-PRIntervalTime timeout,
-_PR_AcceptTimeoutCallback callback,
-void *callbackArg)
+ PRFileDesc *sd, PRFileDesc **nd,
+ PRNetAddr **raddr, void *buf, PRInt32 amount,
+ PRIntervalTime timeout,
+ _PR_AcceptTimeoutCallback callback,
+ void *callbackArg)
{
- PRInt32 rv;
- PROsfd newSock;
- PRThread *me = _PR_MD_CURRENT_THREAD();
- PRNetAddr *raddrCopy;
-
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- return -1;
- }
- if (_PR_IO_PENDING(me)) {
- PR_SetError(PR_IO_PENDING_ERROR, 0);
- return -1;
- }
- *nd = NULL;
-
- if (raddr == NULL) {
- raddr = &raddrCopy;
- }
- rv = _PR_MD_FAST_ACCEPT_READ(sd, &newSock, raddr, buf, amount,
- timeout, PR_TRUE, callback, callbackArg);
- if (rv < 0) {
- rv = -1;
- } else {
- /* Successfully accepted and read; create the new PRFileDesc */
- *nd = PR_AllocFileDesc(newSock, PR_GetTCPMethods());
- if (*nd == 0) {
- _PR_MD_CLOSE_SOCKET(newSock);
- /* PR_AllocFileDesc() has invoked PR_SetError(). */
- rv = -1;
- } else {
- (*nd)->secret->md.io_model_committed = PR_TRUE;
- (*nd)->secret->md.accepted_socket = PR_TRUE;
- memcpy(&(*nd)->secret->md.peer_addr, *raddr,
- PR_NETADDR_SIZE(*raddr));
+ PRInt32 rv;
+ PROsfd newSock;
+ PRThread *me = _PR_MD_CURRENT_THREAD();
+ PRNetAddr *raddrCopy;
+
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ return -1;
+ }
+ if (_PR_IO_PENDING(me)) {
+ PR_SetError(PR_IO_PENDING_ERROR, 0);
+ return -1;
+ }
+ *nd = NULL;
+
+ if (raddr == NULL) {
+ raddr = &raddrCopy;
+ }
+ rv = _PR_MD_FAST_ACCEPT_READ(sd, &newSock, raddr, buf, amount,
+ timeout, PR_TRUE, callback, callbackArg);
+ if (rv < 0) {
+ rv = -1;
+ } else {
+ /* Successfully accepted and read; create the new PRFileDesc */
+ *nd = PR_AllocFileDesc(newSock, PR_GetTCPMethods());
+ if (*nd == 0) {
+ _PR_MD_CLOSE_SOCKET(newSock);
+ /* PR_AllocFileDesc() has invoked PR_SetError(). */
+ rv = -1;
+ } else {
+ (*nd)->secret->md.io_model_committed = PR_TRUE;
+ (*nd)->secret->md.accepted_socket = PR_TRUE;
+ memcpy(&(*nd)->secret->md.peer_addr, *raddr,
+ PR_NETADDR_SIZE(*raddr));
#ifdef _PR_INET6
- if (AF_INET6 == *raddr->raw.family)
- *raddr->raw.family = PR_AF_INET6;
+ if (AF_INET6 == *raddr->raw.family) {
+ *raddr->raw.family = PR_AF_INET6;
+ }
#endif
#ifdef _PR_NEED_SECRET_AF
- (*nd)->secret->af = sd->secret->af;
+ (*nd)->secret->af = sd->secret->af;
#endif
- }
- }
- return rv;
+ }
+ }
+ return rv;
}
#endif /* WINNT */
@@ -1130,8 +1133,8 @@ void *callbackArg)
PR_IMPLEMENT(void)
PR_NTFast_UpdateAcceptContext(PRFileDesc *socket, PRFileDesc *acceptSocket)
{
- _PR_MD_UPDATE_ACCEPT_CONTEXT(
- socket->secret->md.osfd, acceptSocket->secret->md.osfd);
+ _PR_MD_UPDATE_ACCEPT_CONTEXT(
+ socket->secret->md.osfd, acceptSocket->secret->md.osfd);
}
#endif /* WINNT */
@@ -1139,93 +1142,95 @@ static PRInt32 PR_CALLBACK SocketSendFile(
PRFileDesc *sd, PRSendFileData *sfd,
PRTransmitFileFlags flags, PRIntervalTime timeout)
{
- PRInt32 rv;
- PRThread *me = _PR_MD_CURRENT_THREAD();
-
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- return -1;
- }
- if (_PR_IO_PENDING(me)) {
- PR_SetError(PR_IO_PENDING_ERROR, 0);
- return -1;
- }
- /* The socket must be in blocking mode. */
- if (sd->secret->nonblocking) {
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
- return -1;
- }
+ PRInt32 rv;
+ PRThread *me = _PR_MD_CURRENT_THREAD();
+
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ return -1;
+ }
+ if (_PR_IO_PENDING(me)) {
+ PR_SetError(PR_IO_PENDING_ERROR, 0);
+ return -1;
+ }
+ /* The socket must be in blocking mode. */
+ if (sd->secret->nonblocking) {
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+ return -1;
+ }
#if defined(WINNT)
- rv = _PR_MD_SENDFILE(sd, sfd, flags, timeout);
- if ((rv >= 0) && (flags == PR_TRANSMITFILE_CLOSE_SOCKET)) {
- /*
- * This should be kept the same as SocketClose, except
- * that _PR_MD_CLOSE_SOCKET(sd->secret->md.osfd) should
- * not be called because the socket will be recycled.
- */
- PR_FreeFileDesc(sd);
- }
+ rv = _PR_MD_SENDFILE(sd, sfd, flags, timeout);
+ if ((rv >= 0) && (flags == PR_TRANSMITFILE_CLOSE_SOCKET)) {
+ /*
+ * This should be kept the same as SocketClose, except
+ * that _PR_MD_CLOSE_SOCKET(sd->secret->md.osfd) should
+ * not be called because the socket will be recycled.
+ */
+ PR_FreeFileDesc(sd);
+ }
#else
- rv = PR_EmulateSendFile(sd, sfd, flags, timeout);
-#endif /* WINNT */
+ rv = PR_EmulateSendFile(sd, sfd, flags, timeout);
+#endif /* WINNT */
- return rv;
+ return rv;
}
-static PRInt32 PR_CALLBACK SocketTransmitFile(PRFileDesc *sd, PRFileDesc *fd,
-const void *headers, PRInt32 hlen, PRTransmitFileFlags flags,
-PRIntervalTime timeout)
+static PRInt32 PR_CALLBACK SocketTransmitFile(PRFileDesc *sd, PRFileDesc *fd,
+ const void *headers, PRInt32 hlen, PRTransmitFileFlags flags,
+ PRIntervalTime timeout)
{
- PRSendFileData sfd;
+ PRSendFileData sfd;
- sfd.fd = fd;
- sfd.file_offset = 0;
- sfd.file_nbytes = 0;
- sfd.header = headers;
- sfd.hlen = hlen;
- sfd.trailer = NULL;
- sfd.tlen = 0;
+ sfd.fd = fd;
+ sfd.file_offset = 0;
+ sfd.file_nbytes = 0;
+ sfd.header = headers;
+ sfd.hlen = hlen;
+ sfd.trailer = NULL;
+ sfd.tlen = 0;
- return(SocketSendFile(sd, &sfd, flags, timeout));
+ return(SocketSendFile(sd, &sfd, flags, timeout));
}
static PRStatus PR_CALLBACK SocketGetName(PRFileDesc *fd, PRNetAddr *addr)
{
- PRInt32 result;
- PRUint32 addrlen;
-
- addrlen = sizeof(PRNetAddr);
- result = _PR_MD_GETSOCKNAME(fd, addr, &addrlen);
- if (result < 0) {
- return PR_FAILURE;
- }
+ PRInt32 result;
+ PRUint32 addrlen;
+
+ addrlen = sizeof(PRNetAddr);
+ result = _PR_MD_GETSOCKNAME(fd, addr, &addrlen);
+ if (result < 0) {
+ return PR_FAILURE;
+ }
#ifdef _PR_INET6
- if (AF_INET6 == addr->raw.family)
+ if (AF_INET6 == addr->raw.family) {
addr->raw.family = PR_AF_INET6;
+ }
#endif
- PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
- PR_ASSERT(IsValidNetAddrLen(addr, addrlen) == PR_TRUE);
- return PR_SUCCESS;
+ PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
+ PR_ASSERT(IsValidNetAddrLen(addr, addrlen) == PR_TRUE);
+ return PR_SUCCESS;
}
static PRStatus PR_CALLBACK SocketGetPeerName(PRFileDesc *fd, PRNetAddr *addr)
{
- PRInt32 result;
- PRUint32 addrlen;
-
- addrlen = sizeof(PRNetAddr);
- result = _PR_MD_GETPEERNAME(fd, addr, &addrlen);
- if (result < 0) {
- return PR_FAILURE;
- }
+ PRInt32 result;
+ PRUint32 addrlen;
+
+ addrlen = sizeof(PRNetAddr);
+ result = _PR_MD_GETPEERNAME(fd, addr, &addrlen);
+ if (result < 0) {
+ return PR_FAILURE;
+ }
#ifdef _PR_INET6
- if (AF_INET6 == addr->raw.family)
+ if (AF_INET6 == addr->raw.family) {
addr->raw.family = PR_AF_INET6;
+ }
#endif
- PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
- PR_ASSERT(IsValidNetAddrLen(addr, addrlen) == PR_TRUE);
- return PR_SUCCESS;
+ PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
+ PR_ASSERT(IsValidNetAddrLen(addr, addrlen) == PR_TRUE);
+ return PR_SUCCESS;
}
static PRInt16 PR_CALLBACK SocketPoll(
@@ -1236,7 +1241,7 @@ static PRInt16 PR_CALLBACK SocketPoll(
#if defined(_WIN64)
if (in_flags & PR_POLL_WRITE) {
if (fd->secret->alreadyConnected) {
- out_flags = PR_POLL_WRITE;
+ *out_flags = PR_POLL_WRITE;
return PR_POLL_WRITE;
}
}
@@ -1245,84 +1250,84 @@ static PRInt16 PR_CALLBACK SocketPoll(
} /* SocketPoll */
static PRIOMethods tcpMethods = {
- PR_DESC_SOCKET_TCP,
- SocketClose,
- SocketRead,
- SocketWrite,
- SocketAvailable,
- SocketAvailable64,
- SocketSync,
- (PRSeekFN)_PR_InvalidInt,
- (PRSeek64FN)_PR_InvalidInt64,
- (PRFileInfoFN)_PR_InvalidStatus,
- (PRFileInfo64FN)_PR_InvalidStatus,
- SocketWritev,
- SocketConnect,
- SocketAccept,
- SocketBind,
- SocketListen,
- SocketShutdown,
- SocketRecv,
- SocketSend,
- (PRRecvfromFN)_PR_InvalidInt,
+ PR_DESC_SOCKET_TCP,
+ SocketClose,
+ SocketRead,
+ SocketWrite,
+ SocketAvailable,
+ SocketAvailable64,
+ SocketSync,
+ (PRSeekFN)_PR_InvalidInt,
+ (PRSeek64FN)_PR_InvalidInt64,
+ (PRFileInfoFN)_PR_InvalidStatus,
+ (PRFileInfo64FN)_PR_InvalidStatus,
+ SocketWritev,
+ SocketConnect,
+ SocketAccept,
+ SocketBind,
+ SocketListen,
+ SocketShutdown,
+ SocketRecv,
+ SocketSend,
+ (PRRecvfromFN)_PR_InvalidInt,
#if defined(_WIN64) && defined(WIN95)
- SocketTCPSendTo, /* This is for fast open. We imitate Linux interface. */
+ SocketTCPSendTo, /* This is for fast open. We imitate Linux interface. */
#else
- (PRSendtoFN)_PR_InvalidInt,
+ (PRSendtoFN)_PR_InvalidInt,
#endif
- SocketPoll,
- SocketAcceptRead,
- SocketTransmitFile,
- SocketGetName,
- SocketGetPeerName,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
- _PR_SocketGetSocketOption,
- _PR_SocketSetSocketOption,
- SocketSendFile,
+ SocketPoll,
+ SocketAcceptRead,
+ SocketTransmitFile,
+ SocketGetName,
+ SocketGetPeerName,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
+ _PR_SocketGetSocketOption,
+ _PR_SocketSetSocketOption,
+ SocketSendFile,
SocketConnectContinue,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
(PRReservedFN)_PR_InvalidInt
};
static PRIOMethods udpMethods = {
- PR_DESC_SOCKET_UDP,
- SocketClose,
- SocketRead,
- SocketWrite,
- SocketAvailable,
- SocketAvailable64,
- SocketSync,
- (PRSeekFN)_PR_InvalidInt,
- (PRSeek64FN)_PR_InvalidInt64,
- (PRFileInfoFN)_PR_InvalidStatus,
- (PRFileInfo64FN)_PR_InvalidStatus,
- SocketWritev,
- SocketConnect,
- (PRAcceptFN)_PR_InvalidDesc,
- SocketBind,
- SocketListen,
- SocketShutdown,
- SocketRecv,
- SocketSend,
- SocketRecvFrom,
- SocketSendTo,
- SocketPoll,
- (PRAcceptreadFN)_PR_InvalidInt,
- (PRTransmitfileFN)_PR_InvalidInt,
- SocketGetName,
- SocketGetPeerName,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
- _PR_SocketGetSocketOption,
- _PR_SocketSetSocketOption,
- (PRSendfileFN)_PR_InvalidInt,
- (PRConnectcontinueFN)_PR_InvalidStatus,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
+ PR_DESC_SOCKET_UDP,
+ SocketClose,
+ SocketRead,
+ SocketWrite,
+ SocketAvailable,
+ SocketAvailable64,
+ SocketSync,
+ (PRSeekFN)_PR_InvalidInt,
+ (PRSeek64FN)_PR_InvalidInt64,
+ (PRFileInfoFN)_PR_InvalidStatus,
+ (PRFileInfo64FN)_PR_InvalidStatus,
+ SocketWritev,
+ SocketConnect,
+ (PRAcceptFN)_PR_InvalidDesc,
+ SocketBind,
+ SocketListen,
+ SocketShutdown,
+ SocketRecv,
+ SocketSend,
+ SocketRecvFrom,
+ SocketSendTo,
+ SocketPoll,
+ (PRAcceptreadFN)_PR_InvalidInt,
+ (PRTransmitfileFN)_PR_InvalidInt,
+ SocketGetName,
+ SocketGetPeerName,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
+ _PR_SocketGetSocketOption,
+ _PR_SocketSetSocketOption,
+ (PRSendfileFN)_PR_InvalidInt,
+ (PRConnectcontinueFN)_PR_InvalidStatus,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
(PRReservedFN)_PR_InvalidInt
};
@@ -1339,41 +1344,41 @@ static PRIOMethods socketpollfdMethods = {
(PRSeek64FN)_PR_InvalidInt64,
(PRFileInfoFN)_PR_InvalidStatus,
(PRFileInfo64FN)_PR_InvalidStatus,
- (PRWritevFN)_PR_InvalidInt,
- (PRConnectFN)_PR_InvalidStatus,
- (PRAcceptFN)_PR_InvalidDesc,
- (PRBindFN)_PR_InvalidStatus,
- (PRListenFN)_PR_InvalidStatus,
- (PRShutdownFN)_PR_InvalidStatus,
- (PRRecvFN)_PR_InvalidInt,
- (PRSendFN)_PR_InvalidInt,
- (PRRecvfromFN)_PR_InvalidInt,
- (PRSendtoFN)_PR_InvalidInt,
- SocketPoll,
- (PRAcceptreadFN)_PR_InvalidInt,
- (PRTransmitfileFN)_PR_InvalidInt,
- (PRGetsocknameFN)_PR_InvalidStatus,
- (PRGetpeernameFN)_PR_InvalidStatus,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
+ (PRWritevFN)_PR_InvalidInt,
+ (PRConnectFN)_PR_InvalidStatus,
+ (PRAcceptFN)_PR_InvalidDesc,
+ (PRBindFN)_PR_InvalidStatus,
+ (PRListenFN)_PR_InvalidStatus,
+ (PRShutdownFN)_PR_InvalidStatus,
+ (PRRecvFN)_PR_InvalidInt,
+ (PRSendFN)_PR_InvalidInt,
+ (PRRecvfromFN)_PR_InvalidInt,
+ (PRSendtoFN)_PR_InvalidInt,
+ SocketPoll,
+ (PRAcceptreadFN)_PR_InvalidInt,
+ (PRTransmitfileFN)_PR_InvalidInt,
+ (PRGetsocknameFN)_PR_InvalidStatus,
+ (PRGetpeernameFN)_PR_InvalidStatus,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
(PRGetsocketoptionFN)_PR_InvalidStatus,
(PRSetsocketoptionFN)_PR_InvalidStatus,
- (PRSendfileFN)_PR_InvalidInt,
- (PRConnectcontinueFN)_PR_InvalidStatus,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
+ (PRSendfileFN)_PR_InvalidInt,
+ (PRConnectcontinueFN)_PR_InvalidStatus,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
(PRReservedFN)_PR_InvalidInt
};
PR_IMPLEMENT(const PRIOMethods*) PR_GetTCPMethods()
{
- return &tcpMethods;
+ return &tcpMethods;
}
PR_IMPLEMENT(const PRIOMethods*) PR_GetUDPMethods()
{
- return &udpMethods;
+ return &udpMethods;
}
static const PRIOMethods* PR_GetSocketPollFdMethods()
@@ -1390,136 +1395,146 @@ extern PRBool _pr_ipv6_is_present(void);
PR_IMPLEMENT(PRBool) _pr_test_ipv6_socket()
{
- PROsfd osfd;
-
- osfd = _PR_MD_SOCKET(AF_INET6, SOCK_STREAM, 0);
- if (osfd != -1) {
- _PR_MD_CLOSE_SOCKET(osfd);
- return PR_TRUE;
- }
- return PR_FALSE;
+ PROsfd osfd;
+
+ osfd = _PR_MD_SOCKET(AF_INET6, SOCK_STREAM, 0);
+ if (osfd != -1) {
+ _PR_MD_CLOSE_SOCKET(osfd);
+ return PR_TRUE;
+ }
+ return PR_FALSE;
}
-#endif /* _PR_INET6_PROBE */
+#endif /* _PR_INET6_PROBE */
#endif
PR_IMPLEMENT(PRFileDesc*) PR_Socket(PRInt32 domain, PRInt32 type, PRInt32 proto)
{
- PROsfd osfd;
- PRFileDesc *fd;
- PRInt32 tmp_domain = domain;
+ PROsfd osfd;
+ PRFileDesc *fd;
+ PRInt32 tmp_domain = domain;
- if (!_pr_initialized) _PR_ImplicitInitialization();
- if (PR_AF_INET != domain
- && PR_AF_INET6 != domain
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
+ if (PR_AF_INET != domain
+ && PR_AF_INET6 != domain
#if defined(XP_UNIX) || defined(XP_OS2)
- && PR_AF_LOCAL != domain
+ && PR_AF_LOCAL != domain
#endif
- ) {
- PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, 0);
- return NULL;
- }
+ ) {
+ PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, 0);
+ return NULL;
+ }
#if defined(_PR_INET6_PROBE)
- if (PR_AF_INET6 == domain)
- domain = _pr_ipv6_is_present() ? AF_INET6 : AF_INET;
+ if (PR_AF_INET6 == domain) {
+ domain = _pr_ipv6_is_present() ? AF_INET6 : AF_INET;
+ }
#elif defined(_PR_INET6)
- if (PR_AF_INET6 == domain)
- domain = AF_INET6;
+ if (PR_AF_INET6 == domain) {
+ domain = AF_INET6;
+ }
#else
- if (PR_AF_INET6 == domain)
- domain = AF_INET;
-#endif /* _PR_INET6 */
- osfd = _PR_MD_SOCKET(domain, type, proto);
- if (osfd == -1) {
- return 0;
- }
- if (type == SOCK_STREAM)
- fd = PR_AllocFileDesc(osfd, PR_GetTCPMethods());
- else
- fd = PR_AllocFileDesc(osfd, PR_GetUDPMethods());
- /*
- * Make the sockets non-blocking
- */
- if (fd != NULL) {
- _PR_MD_MAKE_NONBLOCK(fd);
- _PR_MD_INIT_FD_INHERITABLE(fd, PR_FALSE);
+ if (PR_AF_INET6 == domain) {
+ domain = AF_INET;
+ }
+#endif /* _PR_INET6 */
+ osfd = _PR_MD_SOCKET(domain, type, proto);
+ if (osfd == -1) {
+ return 0;
+ }
+ if (type == SOCK_STREAM) {
+ fd = PR_AllocFileDesc(osfd, PR_GetTCPMethods());
+ }
+ else {
+ fd = PR_AllocFileDesc(osfd, PR_GetUDPMethods());
+ }
+ /*
+ * Make the sockets non-blocking
+ */
+ if (fd != NULL) {
+ _PR_MD_MAKE_NONBLOCK(fd);
+ _PR_MD_INIT_FD_INHERITABLE(fd, PR_FALSE);
#ifdef _PR_NEED_SECRET_AF
- fd->secret->af = domain;
+ fd->secret->af = domain;
#endif
#if defined(_PR_INET6_PROBE) || !defined(_PR_INET6)
- /*
- * For platforms with no support for IPv6
- * create layered socket for IPv4-mapped IPv6 addresses
- */
- if (PR_AF_INET6 == tmp_domain && PR_AF_INET == domain) {
- if (PR_FAILURE == _pr_push_ipv6toipv4_layer(fd)) {
- PR_Close(fd);
- fd = NULL;
- }
- }
+ /*
+ * For platforms with no support for IPv6
+ * create layered socket for IPv4-mapped IPv6 addresses
+ */
+ if (PR_AF_INET6 == tmp_domain && PR_AF_INET == domain) {
+ if (PR_FAILURE == _pr_push_ipv6toipv4_layer(fd)) {
+ PR_Close(fd);
+ fd = NULL;
+ }
+ }
#endif
- } else
- _PR_MD_CLOSE_SOCKET(osfd);
+ } else {
+ _PR_MD_CLOSE_SOCKET(osfd);
+ }
- return fd;
+ return fd;
}
PR_IMPLEMENT(PRFileDesc *) PR_NewTCPSocket(void)
{
- PRInt32 domain = AF_INET;
+ PRInt32 domain = AF_INET;
- return PR_Socket(domain, SOCK_STREAM, 0);
+ return PR_Socket(domain, SOCK_STREAM, 0);
}
PR_IMPLEMENT(PRFileDesc*) PR_NewUDPSocket(void)
{
- PRInt32 domain = AF_INET;
+ PRInt32 domain = AF_INET;
- return PR_Socket(domain, SOCK_DGRAM, 0);
+ return PR_Socket(domain, SOCK_DGRAM, 0);
}
PR_IMPLEMENT(PRFileDesc *) PR_OpenTCPSocket(PRIntn af)
{
- return PR_Socket(af, SOCK_STREAM, 0);
+ return PR_Socket(af, SOCK_STREAM, 0);
}
PR_IMPLEMENT(PRFileDesc*) PR_OpenUDPSocket(PRIntn af)
{
- return PR_Socket(af, SOCK_DGRAM, 0);
+ return PR_Socket(af, SOCK_DGRAM, 0);
}
PR_IMPLEMENT(PRStatus) PR_NewTCPSocketPair(PRFileDesc *f[])
{
#ifdef XP_UNIX
- PRInt32 rv, osfd[2];
-
- if (!_pr_initialized) _PR_ImplicitInitialization();
-
- rv = _PR_MD_SOCKETPAIR(AF_UNIX, SOCK_STREAM, 0, osfd);
- if (rv == -1) {
- return PR_FAILURE;
- }
-
- f[0] = PR_AllocFileDesc(osfd[0], PR_GetTCPMethods());
- if (!f[0]) {
- _PR_MD_CLOSE_SOCKET(osfd[0]);
- _PR_MD_CLOSE_SOCKET(osfd[1]);
- /* PR_AllocFileDesc() has invoked PR_SetError(). */
- return PR_FAILURE;
- }
- f[1] = PR_AllocFileDesc(osfd[1], PR_GetTCPMethods());
- if (!f[1]) {
- PR_Close(f[0]);
- _PR_MD_CLOSE_SOCKET(osfd[1]);
- /* PR_AllocFileDesc() has invoked PR_SetError(). */
- return PR_FAILURE;
- }
- _PR_MD_MAKE_NONBLOCK(f[0]);
- _PR_MD_INIT_FD_INHERITABLE(f[0], PR_FALSE);
- _PR_MD_MAKE_NONBLOCK(f[1]);
- _PR_MD_INIT_FD_INHERITABLE(f[1], PR_FALSE);
- return PR_SUCCESS;
+ PRInt32 rv, osfd[2];
+
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
+
+ rv = _PR_MD_SOCKETPAIR(AF_UNIX, SOCK_STREAM, 0, osfd);
+ if (rv == -1) {
+ return PR_FAILURE;
+ }
+
+ f[0] = PR_AllocFileDesc(osfd[0], PR_GetTCPMethods());
+ if (!f[0]) {
+ _PR_MD_CLOSE_SOCKET(osfd[0]);
+ _PR_MD_CLOSE_SOCKET(osfd[1]);
+ /* PR_AllocFileDesc() has invoked PR_SetError(). */
+ return PR_FAILURE;
+ }
+ f[1] = PR_AllocFileDesc(osfd[1], PR_GetTCPMethods());
+ if (!f[1]) {
+ PR_Close(f[0]);
+ _PR_MD_CLOSE_SOCKET(osfd[1]);
+ /* PR_AllocFileDesc() has invoked PR_SetError(). */
+ return PR_FAILURE;
+ }
+ _PR_MD_MAKE_NONBLOCK(f[0]);
+ _PR_MD_INIT_FD_INHERITABLE(f[0], PR_FALSE);
+ _PR_MD_MAKE_NONBLOCK(f[1]);
+ _PR_MD_INIT_FD_INHERITABLE(f[1], PR_FALSE);
+ return PR_SUCCESS;
#elif defined(WINNT)
/*
* A socket pair is often used for interprocess communication,
@@ -1536,7 +1551,9 @@ PR_IMPLEMENT(PRStatus) PR_NewTCPSocketPair(PRFileDesc *f[])
struct sockaddr_in selfAddr, peerAddr;
int addrLen;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
osfd[0] = osfd[1] = INVALID_SOCKET;
listenSock = socket(AF_INET, SOCK_STREAM, 0);
@@ -1548,11 +1565,11 @@ PR_IMPLEMENT(PRStatus) PR_NewTCPSocketPair(PRFileDesc *f[])
selfAddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); /* BugZilla: 35408 */
addrLen = sizeof(selfAddr);
if (bind(listenSock, (struct sockaddr *) &selfAddr,
- addrLen) == SOCKET_ERROR) {
+ addrLen) == SOCKET_ERROR) {
goto failed;
}
if (getsockname(listenSock, (struct sockaddr *) &selfAddr,
- &addrLen) == SOCKET_ERROR) {
+ &addrLen) == SOCKET_ERROR) {
goto failed;
}
if (listen(listenSock, 5) == SOCKET_ERROR) {
@@ -1574,7 +1591,7 @@ PR_IMPLEMENT(PRStatus) PR_NewTCPSocketPair(PRFileDesc *f[])
* will need to create another thread to call connect.
*/
if (connect(osfd[0], (struct sockaddr *) &selfAddr,
- addrLen) == SOCKET_ERROR) {
+ addrLen) == SOCKET_ERROR) {
goto failed;
}
/*
@@ -1583,7 +1600,7 @@ PR_IMPLEMENT(PRStatus) PR_NewTCPSocketPair(PRFileDesc *f[])
* is made from our own socket osfd[0].
*/
if (getsockname(osfd[0], (struct sockaddr *) &selfAddr,
- &addrLen) == SOCKET_ERROR) {
+ &addrLen) == SOCKET_ERROR) {
goto failed;
}
osfd[1] = accept(listenSock, (struct sockaddr *) &peerAddr, &addrLen);
@@ -1677,7 +1694,7 @@ failed:
* will need to create another thread to call connect.
*/
if (PR_Connect(f[0], &selfAddr, PR_INTERVAL_NO_TIMEOUT)
- == PR_FAILURE) {
+ == PR_FAILURE) {
goto failed;
}
/*
@@ -1730,8 +1747,9 @@ PR_FileDesc2NativeHandle(PRFileDesc *fd)
PR_IMPLEMENT(void)
PR_ChangeFileDescNativeHandle(PRFileDesc *fd, PROsfd handle)
{
- if (fd)
- fd->secret->md.osfd = handle;
+ if (fd) {
+ fd->secret->md.osfd = handle;
+ }
}
/*
@@ -1741,69 +1759,69 @@ PR_ChangeFileDescNativeHandle(PRFileDesc *fd, PROsfd handle)
PR_IMPLEMENT(void) PR_FD_ZERO(PR_fd_set *set)
{
- memset(set, 0, sizeof(PR_fd_set));
+ memset(set, 0, sizeof(PR_fd_set));
}
PR_IMPLEMENT(void) PR_FD_SET(PRFileDesc *fh, PR_fd_set *set)
{
- PR_ASSERT( set->hsize < PR_MAX_SELECT_DESC );
+ PR_ASSERT( set->hsize < PR_MAX_SELECT_DESC );
- set->harray[set->hsize++] = fh;
+ set->harray[set->hsize++] = fh;
}
PR_IMPLEMENT(void) PR_FD_CLR(PRFileDesc *fh, PR_fd_set *set)
{
- PRUint32 index, index2;
-
- for (index = 0; index<set->hsize; index++)
- if (set->harray[index] == fh) {
- for (index2=index; index2 < (set->hsize-1); index2++) {
- set->harray[index2] = set->harray[index2+1];
- }
- set->hsize--;
- break;
- }
+ PRUint32 index, index2;
+
+ for (index = 0; index<set->hsize; index++)
+ if (set->harray[index] == fh) {
+ for (index2=index; index2 < (set->hsize-1); index2++) {
+ set->harray[index2] = set->harray[index2+1];
+ }
+ set->hsize--;
+ break;
+ }
}
PR_IMPLEMENT(PRInt32) PR_FD_ISSET(PRFileDesc *fh, PR_fd_set *set)
{
- PRUint32 index;
- for (index = 0; index<set->hsize; index++)
- if (set->harray[index] == fh) {
- return 1;
- }
- return 0;
+ PRUint32 index;
+ for (index = 0; index<set->hsize; index++)
+ if (set->harray[index] == fh) {
+ return 1;
+ }
+ return 0;
}
PR_IMPLEMENT(void) PR_FD_NSET(PROsfd fd, PR_fd_set *set)
{
- PR_ASSERT( set->nsize < PR_MAX_SELECT_DESC );
+ PR_ASSERT( set->nsize < PR_MAX_SELECT_DESC );
- set->narray[set->nsize++] = fd;
+ set->narray[set->nsize++] = fd;
}
PR_IMPLEMENT(void) PR_FD_NCLR(PROsfd fd, PR_fd_set *set)
{
- PRUint32 index, index2;
-
- for (index = 0; index<set->nsize; index++)
- if (set->narray[index] == fd) {
- for (index2=index; index2 < (set->nsize-1); index2++) {
- set->narray[index2] = set->narray[index2+1];
- }
- set->nsize--;
- break;
- }
+ PRUint32 index, index2;
+
+ for (index = 0; index<set->nsize; index++)
+ if (set->narray[index] == fd) {
+ for (index2=index; index2 < (set->nsize-1); index2++) {
+ set->narray[index2] = set->narray[index2+1];
+ }
+ set->nsize--;
+ break;
+ }
}
PR_IMPLEMENT(PRInt32) PR_FD_NISSET(PROsfd fd, PR_fd_set *set)
{
- PRUint32 index;
- for (index = 0; index<set->nsize; index++)
- if (set->narray[index] == fd) {
- return 1;
- }
- return 0;
+ PRUint32 index;
+ for (index = 0; index<set->nsize; index++)
+ if (set->narray[index] == fd) {
+ return 1;
+ }
+ return 0;
}
@@ -1818,26 +1836,30 @@ static PRPollDesc *_pr_setfd(
PRUintn fsidx, pdidx;
PRPollDesc *poll = polldesc;
- if (NULL == set) return poll;
+ if (NULL == set) {
+ return poll;
+ }
- /* First set the pr file handle osfds */
- for (fsidx = 0; fsidx < set->hsize; fsidx++)
- {
- for (pdidx = 0; 1; pdidx++)
+ /* First set the pr file handle osfds */
+ for (fsidx = 0; fsidx < set->hsize; fsidx++)
+ {
+ for (pdidx = 0; 1; pdidx++)
{
if ((PRFileDesc*)-1 == poll[pdidx].fd)
{
/* our vector is full - extend and condition it */
poll = (PRPollDesc*)PR_Realloc(
- poll, (pdidx + 1 + PD_INCR) * sizeof(PRPollDesc));
- if (NULL == poll) goto out_of_memory;
+ poll, (pdidx + 1 + PD_INCR) * sizeof(PRPollDesc));
+ if (NULL == poll) {
+ goto out_of_memory;
+ }
memset(
poll + pdidx * sizeof(PRPollDesc),
0, PD_INCR * sizeof(PRPollDesc));
poll[pdidx + PD_INCR].fd = (PRFileDesc*)-1;
}
if ((NULL == poll[pdidx].fd)
- || (poll[pdidx].fd == set->harray[fsidx]))
+ || (poll[pdidx].fd == set->harray[fsidx]))
{
/* PR_ASSERT(0 == (poll[pdidx].in_flags & flags)); */
/* either empty or prevously defined */
@@ -1846,27 +1868,29 @@ static PRPollDesc *_pr_setfd(
break;
}
}
- }
+ }
#if 0
- /* Second set the native osfds */
- for (fsidx = 0; fsidx < set->nsize; fsidx++)
- {
- for (pdidx = 0; ((PRFileDesc*)-1 != poll[pdidx].fd); pdidx++)
+ /* Second set the native osfds */
+ for (fsidx = 0; fsidx < set->nsize; fsidx++)
+ {
+ for (pdidx = 0; ((PRFileDesc*)-1 != poll[pdidx].fd); pdidx++)
{
if ((PRFileDesc*)-1 == poll[pdidx].fd)
{
/* our vector is full - extend and condition it */
poll = PR_Realloc(
- poll, (pdidx + PD_INCR) * sizeof(PRPollDesc));
- if (NULL == poll) goto out_of_memory;
+ poll, (pdidx + PD_INCR) * sizeof(PRPollDesc));
+ if (NULL == poll) {
+ goto out_of_memory;
+ }
memset(
poll + pdidx * sizeof(PRPollDesc),
0, PD_INCR * sizeof(PRPollDesc));
poll[(pdidx + PD_INCR)].fd = (PRFileDesc*)-1;
}
if ((NULL == poll[pdidx].fd)
- || (poll[pdidx].fd == set->narray[fsidx]))
+ || (poll[pdidx].fd == set->narray[fsidx]))
{
/* either empty or prevously defined */
poll[pdidx].fd = set->narray[fsidx];
@@ -1875,25 +1899,27 @@ static PRPollDesc *_pr_setfd(
break;
}
}
- }
+ }
#endif /* 0 */
- return poll;
+ return poll;
out_of_memory:
- if (NULL != polldesc) PR_DELETE(polldesc);
+ if (NULL != polldesc) {
+ PR_DELETE(polldesc);
+ }
return NULL;
} /* _pr_setfd */
#endif /* !defined(NEED_SELECT) */
PR_IMPLEMENT(PRInt32) PR_Select(
- PRInt32 unused, PR_fd_set *pr_rd, PR_fd_set *pr_wr,
+ PRInt32 unused, PR_fd_set *pr_rd, PR_fd_set *pr_wr,
PR_fd_set *pr_ex, PRIntervalTime timeout)
{
#if !defined(NEED_SELECT)
- PRInt32 npds = 0;
+ PRInt32 npds = 0;
/*
** Find out how many fds are represented in the three lists.
** Then allocate a polling descriptor for the logical union
@@ -1903,16 +1929,21 @@ PR_IMPLEMENT(PRInt32) PR_Select(
PRPollDesc *copy, *poll;
static PRBool warning = PR_TRUE;
- if (warning) warning = _PR_Obsolete( "PR_Select()", "PR_Poll()");
+ if (warning) {
+ warning = _PR_Obsolete( "PR_Select()", "PR_Poll()");
+ }
/* try to get an initial guesss at how much space we need */
npds = 0;
- if ((NULL != pr_rd) && ((pr_rd->hsize + pr_rd->nsize - npds) > 0))
+ if ((NULL != pr_rd) && ((pr_rd->hsize + pr_rd->nsize - npds) > 0)) {
npds = pr_rd->hsize + pr_rd->nsize;
- if ((NULL != pr_wr) && ((pr_wr->hsize + pr_wr->nsize - npds) > 0))
+ }
+ if ((NULL != pr_wr) && ((pr_wr->hsize + pr_wr->nsize - npds) > 0)) {
npds = pr_wr->hsize + pr_wr->nsize;
- if ((NULL != pr_ex) && ((pr_ex->hsize + pr_ex->nsize - npds) > 0))
+ }
+ if ((NULL != pr_ex) && ((pr_ex->hsize + pr_ex->nsize - npds) > 0)) {
npds = pr_ex->hsize + pr_ex->nsize;
+ }
if (0 == npds)
{
@@ -1921,15 +1952,23 @@ PR_IMPLEMENT(PRInt32) PR_Select(
}
copy = poll = (PRPollDesc*)PR_Calloc(npds + PD_INCR, sizeof(PRPollDesc));
- if (NULL == poll) goto out_of_memory;
+ if (NULL == poll) {
+ goto out_of_memory;
+ }
poll[npds + PD_INCR - 1].fd = (PRFileDesc*)-1;
poll = _pr_setfd(pr_rd, PR_POLL_READ, poll);
- if (NULL == poll) goto out_of_memory;
+ if (NULL == poll) {
+ goto out_of_memory;
+ }
poll = _pr_setfd(pr_wr, PR_POLL_WRITE, poll);
- if (NULL == poll) goto out_of_memory;
+ if (NULL == poll) {
+ goto out_of_memory;
+ }
poll = _pr_setfd(pr_ex, PR_POLL_EXCEPT, poll);
- if (NULL == poll) goto out_of_memory;
+ if (NULL == poll) {
+ goto out_of_memory;
+ }
unused = 0;
while (NULL != poll[unused].fd && (PRFileDesc*)-1 != poll[unused].fd)
{
@@ -1942,9 +1981,15 @@ PR_IMPLEMENT(PRInt32) PR_Select(
if (npds > 0)
{
/* Copy the results back into the fd sets */
- if (NULL != pr_rd) pr_rd->nsize = pr_rd->hsize = 0;
- if (NULL != pr_wr) pr_wr->nsize = pr_wr->hsize = 0;
- if (NULL != pr_ex) pr_ex->nsize = pr_ex->hsize = 0;
+ if (NULL != pr_rd) {
+ pr_rd->nsize = pr_rd->hsize = 0;
+ }
+ if (NULL != pr_wr) {
+ pr_wr->nsize = pr_wr->hsize = 0;
+ }
+ if (NULL != pr_ex) {
+ pr_ex->nsize = pr_ex->hsize = 0;
+ }
for (copy = &poll[unused - 1]; copy >= poll; --copy)
{
if (copy->out_flags & PR_POLL_NVAL)
@@ -1954,11 +1999,17 @@ PR_IMPLEMENT(PRInt32) PR_Select(
break;
}
if (copy->out_flags & PR_POLL_READ)
- if (NULL != pr_rd) pr_rd->harray[pr_rd->hsize++] = copy->fd;
+ if (NULL != pr_rd) {
+ pr_rd->harray[pr_rd->hsize++] = copy->fd;
+ }
if (copy->out_flags & PR_POLL_WRITE)
- if (NULL != pr_wr) pr_wr->harray[pr_wr->hsize++] = copy->fd;
+ if (NULL != pr_wr) {
+ pr_wr->harray[pr_wr->hsize++] = copy->fd;
+ }
if (copy->out_flags & PR_POLL_EXCEPT)
- if (NULL != pr_ex) pr_ex->harray[pr_ex->hsize++] = copy->fd;
+ if (NULL != pr_ex) {
+ pr_ex->harray[pr_ex->hsize++] = copy->fd;
+ }
}
}
PR_DELETE(poll);
@@ -1966,8 +2017,8 @@ PR_IMPLEMENT(PRInt32) PR_Select(
return npds;
out_of_memory:
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
- return -1;
+ return -1;
#endif /* !defined(NEED_SELECT) */
-
+
}
diff --git a/nsprpub/pr/src/linking/prlink.c b/nsprpub/pr/src/linking/prlink.c
index 47154608a..1f3430714 100644
--- a/nsprpub/pr/src/linking/prlink.c
+++ b/nsprpub/pr/src/linking/prlink.c
@@ -7,10 +7,6 @@
#include <string.h>
-#ifdef XP_BEOS
-#include <image.h>
-#endif
-
#if defined(XP_MACOSX) && defined(USE_MACH_DYLD)
#include <Carbon/Carbon.h>
#include <CoreFoundation/CoreFoundation.h>
@@ -38,10 +34,6 @@
#define L_IGNOREUNLOAD 0x10000000
#endif
#endif
-#ifdef OSF1
-#include <loader.h>
-#include <rld_interface.h>
-#endif
#elif defined(USE_HPSHL)
#include <dl.h>
#elif defined(USE_MACH_DYLD)
@@ -93,13 +85,9 @@ struct PRLibrary {
NSModule dlh;
#else
void* dlh;
-#endif
-#endif
-
-#ifdef XP_BEOS
- void* dlh;
- void* stub_dlh;
#endif
+#endif
+
};
static PRLibrary *pr_loadmap;
@@ -132,8 +120,9 @@ static void DLLErrorInternal(PRIntn oserr)
PR_snprintf(errStrBuf, sizeof(errStrBuf), "error %d", oserr);
error = errStrBuf;
#endif
- if (NULL != error)
+ if (NULL != error) {
PR_SetErrorText(strlen(error), error);
+ }
} /* DLLErrorInternal */
void _PR_InitLinker(void)
@@ -169,12 +158,12 @@ void _PR_InitLinker(void)
h = dlopen(0, RTLD_LAZY);
if (!h) {
char *error;
-
+
DLLErrorInternal(_MD_ERRNO());
error = (char*)PR_MALLOC(PR_GetErrorTextLength());
(void) PR_GetErrorText(error);
fprintf(stderr, "failed to initialize shared libraries [%s]\n",
- error);
+ error);
PR_DELETE(error);
abort();/* XXX */
}
@@ -201,7 +190,7 @@ void _PR_InitLinker(void)
if (lm) {
PR_LOG(_pr_linker_lm, PR_LOG_MIN,
- ("Loaded library %s (init)", lm->name));
+ ("Loaded library %s (init)", lm->name));
}
PR_ExitMonitor(pr_linker_lock);
@@ -217,7 +206,7 @@ void _PR_InitLinker(void)
void _PR_ShutdownLinker(void)
{
/* FIXME: pr_exe_loadmap should be destroyed. */
-
+
PR_DestroyMonitor(pr_linker_lock);
pr_linker_lock = NULL;
@@ -233,7 +222,9 @@ PR_IMPLEMENT(PRStatus) PR_SetLibraryPath(const char *path)
{
PRStatus rv = PR_SUCCESS;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
PR_EnterMonitor(pr_linker_lock);
if (_pr_currentLibPath) {
free(_pr_currentLibPath);
@@ -242,7 +233,7 @@ PR_IMPLEMENT(PRStatus) PR_SetLibraryPath(const char *path)
_pr_currentLibPath = strdup(path);
if (!_pr_currentLibPath) {
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
- rv = PR_FAILURE;
+ rv = PR_FAILURE;
}
} else {
_pr_currentLibPath = 0;
@@ -254,13 +245,15 @@ PR_IMPLEMENT(PRStatus) PR_SetLibraryPath(const char *path)
/*
** Return the library path for finding shared libraries.
*/
-PR_IMPLEMENT(char *)
+PR_IMPLEMENT(char *)
PR_GetLibraryPath(void)
{
char *ev;
char *copy = NULL; /* a copy of _pr_currentLibPath */
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
PR_EnterMonitor(pr_linker_lock);
if (_pr_currentLibPath != NULL) {
goto exit;
@@ -271,36 +264,29 @@ PR_GetLibraryPath(void)
#ifdef XP_PC
ev = getenv("LD_LIBRARY_PATH");
if (!ev) {
- ev = ".;\\lib";
+ ev = ".;\\lib";
}
ev = strdup(ev);
#endif
-#if defined(XP_UNIX) || defined(XP_BEOS)
-#if defined(USE_DLFCN) || defined(USE_MACH_DYLD) || defined(XP_BEOS)
+#if defined(XP_UNIX)
+#if defined(USE_DLFCN) || defined(USE_MACH_DYLD)
{
- char *p=NULL;
- int len;
+ char *p=NULL;
+ int len;
-#ifdef XP_BEOS
- ev = getenv("LIBRARY_PATH");
- if (!ev) {
- ev = "%A/lib:/boot/home/config/lib:/boot/beos/system/lib";
- }
-#else
- ev = getenv("LD_LIBRARY_PATH");
- if (!ev) {
- ev = "/usr/lib:/lib";
- }
-#endif
- len = strlen(ev) + 1; /* +1 for the null */
+ ev = getenv("LD_LIBRARY_PATH");
+ if (!ev) {
+ ev = "/usr/lib:/lib";
+ }
+ len = strlen(ev) + 1; /* +1 for the null */
- p = (char*) malloc(len);
- if (p) {
- strcpy(p, ev);
- } /* if (p) */
- ev = p;
- PR_LOG(_pr_io_lm, PR_LOG_NOTICE, ("linker path '%s'", ev));
+ p = (char*) malloc(len);
+ if (p) {
+ strcpy(p, ev);
+ } /* if (p) */
+ ev = p;
+ PR_LOG(_pr_io_lm, PR_LOG_NOTICE, ("linker path '%s'", ev));
}
#else
@@ -314,7 +300,7 @@ PR_GetLibraryPath(void)
*/
_pr_currentLibPath = ev;
- exit:
+exit:
if (_pr_currentLibPath) {
copy = strdup(_pr_currentLibPath);
}
@@ -328,7 +314,7 @@ PR_GetLibraryPath(void)
/*
** Build library name from path, lib and extensions
*/
-PR_IMPLEMENT(char*)
+PR_IMPLEMENT(char*)
PR_GetLibraryName(const char *path, const char *lib)
{
char *fullname;
@@ -349,7 +335,7 @@ PR_GetLibraryName(const char *path, const char *lib)
}
}
#endif /* XP_PC */
-#if defined(XP_UNIX) || defined(XP_BEOS)
+#if defined(XP_UNIX)
if (strstr(lib, PR_DLL_SUFFIX) == NULL)
{
if (path) {
@@ -364,45 +350,45 @@ PR_GetLibraryName(const char *path, const char *lib)
fullname = PR_smprintf("%s", lib);
}
}
-#endif /* XP_UNIX || XP_BEOS */
+#endif /* XP_UNIX */
return fullname;
}
/*
** Free the memory allocated, for the caller, by PR_GetLibraryName
*/
-PR_IMPLEMENT(void)
+PR_IMPLEMENT(void)
PR_FreeLibraryName(char *mem)
{
PR_smprintf_free(mem);
}
-static PRLibrary*
+static PRLibrary*
pr_UnlockedFindLibrary(const char *name)
{
PRLibrary* lm = pr_loadmap;
const char* np = strrchr(name, PR_DIRECTORY_SEPARATOR);
np = np ? np + 1 : name;
while (lm) {
- const char* cp = strrchr(lm->name, PR_DIRECTORY_SEPARATOR);
- cp = cp ? cp + 1 : lm->name;
+ const char* cp = strrchr(lm->name, PR_DIRECTORY_SEPARATOR);
+ cp = cp ? cp + 1 : lm->name;
#ifdef WIN32
/* Windows DLL names are case insensitive... */
- if (strcmpi(np, cp) == 0)
+ if (strcmpi(np, cp) == 0)
#elif defined(XP_OS2)
- if (stricmp(np, cp) == 0)
+ if (stricmp(np, cp) == 0)
#else
- if (strcmp(np, cp) == 0)
+ if (strcmp(np, cp) == 0)
#endif
- {
- /* found */
- lm->refCount++;
- PR_LOG(_pr_linker_lm, PR_LOG_MIN,
- ("%s incr => %d (find lib)",
- lm->name, lm->refCount));
- return lm;
- }
- lm = lm->next;
+ {
+ /* found */
+ lm->refCount++;
+ PR_LOG(_pr_linker_lm, PR_LOG_MIN,
+ ("%s incr => %d (find lib)",
+ lm->name, lm->refCount));
+ return lm;
+ }
+ lm = lm->next;
}
return NULL;
}
@@ -422,8 +408,8 @@ PR_LoadLibraryWithFlags(PRLibSpec libSpec, PRIntn flags)
* cast to |char *| and set PR_LD_PATHW flag so that
* it can be cast back to PRUnichar* in the callee.
*/
- return pr_LoadLibraryByPathname((const char*)
- libSpec.value.pathname_u,
+ return pr_LoadLibraryByPathname((const char*)
+ libSpec.value.pathname_u,
flags | PR_LD_PATHW);
#endif
default:
@@ -431,8 +417,8 @@ PR_LoadLibraryWithFlags(PRLibSpec libSpec, PRIntn flags)
return NULL;
}
}
-
-PR_IMPLEMENT(PRLibrary*)
+
+PR_IMPLEMENT(PRLibrary*)
PR_LoadLibrary(const char *name)
{
PRLibSpec libSpec;
@@ -449,7 +435,7 @@ pr_LoadMachDyldModule(const char *name)
NSObjectFileImage ofi;
NSModule h = NULL;
if (NSCreateObjectFileImageFromFile(name, &ofi)
- == NSObjectFileImageSuccess) {
+ == NSObjectFileImageSuccess) {
h = NSLinkModule(ofi, name, NSLINKMODULE_OPTION_PRIVATE
| NSLINKMODULE_OPTION_RETURN_ON_ERROR);
if (h == NULL) {
@@ -458,7 +444,7 @@ pr_LoadMachDyldModule(const char *name)
const char *fileName;
const char *errorString;
NSLinkEditError(&linkEditError, &errorNum, &fileName, &errorString);
- PR_LOG(_pr_linker_lm, PR_LOG_MIN,
+ PR_LOG(_pr_linker_lm, PR_LOG_MIN,
("LoadMachDyldModule error %d:%d for file %s:\n%s",
linkEditError, errorNum, fileName, errorString));
}
@@ -522,7 +508,7 @@ static void* TV2FP(CFMutableDictionaryRef dict, const char* name, void *tvp)
CFRelease(nameRef);
}
}
-
+
return newGlue;
}
@@ -541,18 +527,21 @@ pr_LoadViaCFM(const char *name, PRLibrary *lm)
/* Use direct conversion of POSIX path to FSRef to FSSpec. */
err = FSPathMakeRef((const UInt8*)name, &ref, NULL);
- if (err != noErr)
+ if (err != noErr) {
return PR_FAILURE;
+ }
err = FSGetCatalogInfo(&ref, kFSCatInfoNone, NULL, NULL,
&fileSpec, NULL);
- if (err != noErr)
+ if (err != noErr) {
return PR_FAILURE;
+ }
/* Resolve an alias if this was one */
err = ResolveAliasFile(&fileSpec, true, &tempUnusedBool,
&tempUnusedBool);
- if (err != noErr)
+ if (err != noErr) {
return PR_FAILURE;
+ }
/* Finally, try to load the library */
err = GetDiskFragment(&fileSpec, 0, kCFragGoesToEOF, fileSpec.name,
@@ -569,8 +558,9 @@ pr_LoadViaCFM(const char *name, PRLibrary *lm)
&kCFTypeDictionaryValueCallBacks);
if (lm->wrappers) {
lm->main = TV2FP(lm->wrappers, "main", lm->main);
- } else
+ } else {
err = memFullErr;
+ }
}
return (err == noErr) ? PR_SUCCESS : PR_FAILURE;
}
@@ -593,13 +583,14 @@ pr_LoadCFBundle(const char *name, PRLibrary *lm)
/* Takes care of relative paths and symlinks */
resolvedPath = realpath(name, pathBuf);
- if (!resolvedPath)
+ if (!resolvedPath) {
return PR_FAILURE;
-
+ }
+
pathRef = CFStringCreateWithCString(NULL, pathBuf, kCFStringEncodingUTF8);
if (pathRef) {
bundleURL = CFURLCreateWithFileSystemPath(NULL, pathRef,
- kCFURLPOSIXPathStyle, true);
+ kCFURLPOSIXPathStyle, true);
if (bundleURL) {
bundle = CFBundleCreate(NULL, bundleURL);
CFRelease(bundleURL);
@@ -624,7 +615,7 @@ pr_LoadViaDyld(const char *name, PRLibrary *lm)
const char *fileName;
const char *errorString;
NSLinkEditError(&linkEditError, &errorNum, &fileName, &errorString);
- PR_LOG(_pr_linker_lm, PR_LOG_MIN,
+ PR_LOG(_pr_linker_lm, PR_LOG_MIN,
("LoadMachDyldModule error %d:%d for file %s:\n%s",
linkEditError, errorNum, fileName, errorString));
}
@@ -654,7 +645,9 @@ pr_LoadLibraryByPathname(const char *name, PRIntn flags)
int len;
#endif
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
/* See if library is already loaded */
PR_EnterMonitor(pr_linker_lock);
@@ -665,8 +658,9 @@ pr_LoadLibraryByPathname(const char *name, PRIntn flags)
wname = (LPWSTR) name;
} else {
int wlen = MultiByteToWideChar(CP_ACP, 0, name, -1, NULL, 0);
- if (wlen > MAX_PATH)
+ if (wlen > MAX_PATH) {
wname = wname_malloc = PR_Malloc(wlen * sizeof(PRUnichar));
+ }
if (wname == NULL ||
!MultiByteToWideChar(CP_ACP, 0, name, -1, wname, wlen)) {
oserr = _MD_ERRNO();
@@ -674,22 +668,25 @@ pr_LoadLibraryByPathname(const char *name, PRIntn flags)
}
}
len = WideCharToMultiByte(CP_UTF8, 0, wname, -1, NULL, 0, NULL, NULL);
- if (len > MAX_PATH)
+ if (len > MAX_PATH) {
utf8name = utf8name_malloc = PR_Malloc(len);
+ }
if (utf8name == NULL ||
!WideCharToMultiByte(CP_UTF8, 0, wname, -1,
utf8name, len, NULL, NULL)) {
oserr = _MD_ERRNO();
goto unlock;
}
- /* the list of loaded library names are always kept in UTF-8
+ /* the list of loaded library names are always kept in UTF-8
* on Win32 platforms */
result = pr_UnlockedFindLibrary(utf8name);
#else
result = pr_UnlockedFindLibrary(name);
#endif
- if (result != NULL) goto unlock;
+ if (result != NULL) {
+ goto unlock;
+ }
lm = PR_NEWZAP(PRLibrary);
if (lm == NULL) {
@@ -704,63 +701,64 @@ pr_LoadLibraryByPathname(const char *name, PRIntn flags)
UCHAR pszError[_MAX_PATH];
ULONG ulRc = NO_ERROR;
- ulRc = DosLoadModule(pszError, _MAX_PATH, (PSZ) name, &h);
- if (ulRc != NO_ERROR) {
- oserr = ulRc;
- PR_DELETE(lm);
- goto unlock;
- }
- lm->name = strdup(name);
- lm->dlh = h;
- lm->next = pr_loadmap;
- pr_loadmap = lm;
+ ulRc = DosLoadModule(pszError, _MAX_PATH, (PSZ) name, &h);
+ if (ulRc != NO_ERROR) {
+ oserr = ulRc;
+ PR_DELETE(lm);
+ goto unlock;
+ }
+ lm->name = strdup(name);
+ lm->dlh = h;
+ lm->next = pr_loadmap;
+ pr_loadmap = lm;
}
#endif /* XP_OS2 */
#ifdef WIN32
{
- HINSTANCE h;
+ HINSTANCE h;
- h = LoadLibraryExW(wname, NULL,
- (flags & PR_LD_ALT_SEARCH_PATH) ?
- LOAD_WITH_ALTERED_SEARCH_PATH : 0);
- if (h == NULL) {
- oserr = _MD_ERRNO();
- PR_DELETE(lm);
- goto unlock;
- }
- lm->name = strdup(utf8name);
- lm->dlh = h;
- lm->next = pr_loadmap;
- pr_loadmap = lm;
+ h = LoadLibraryExW(wname, NULL,
+ (flags & PR_LD_ALT_SEARCH_PATH) ?
+ LOAD_WITH_ALTERED_SEARCH_PATH : 0);
+ if (h == NULL) {
+ oserr = _MD_ERRNO();
+ PR_DELETE(lm);
+ goto unlock;
+ }
+ lm->name = strdup(utf8name);
+ lm->dlh = h;
+ lm->next = pr_loadmap;
+ pr_loadmap = lm;
}
#endif /* WIN32 */
#if defined(XP_MACOSX) && defined(USE_MACH_DYLD)
{
- int i;
- PRStatus status;
+ int i;
+ PRStatus status;
- static const macLibraryLoadProc loadProcs[] = {
+ static const macLibraryLoadProc loadProcs[] = {
#ifdef __ppc__
- pr_LoadViaDyld, pr_LoadCFBundle, pr_LoadViaCFM
+ pr_LoadViaDyld, pr_LoadCFBundle, pr_LoadViaCFM
#else /* __ppc__ */
- pr_LoadViaDyld, pr_LoadCFBundle
+ pr_LoadViaDyld, pr_LoadCFBundle
#endif /* __ppc__ */
- };
+ };
- for (i = 0; i < sizeof(loadProcs) / sizeof(loadProcs[0]); i++) {
- if ((status = loadProcs[i](name, lm)) == PR_SUCCESS)
- break;
- }
- if (status != PR_SUCCESS) {
- oserr = cfragNoLibraryErr;
- PR_DELETE(lm);
- goto unlock;
- }
- lm->name = strdup(name);
- lm->next = pr_loadmap;
- pr_loadmap = lm;
+ for (i = 0; i < sizeof(loadProcs) / sizeof(loadProcs[0]); i++) {
+ if ((status = loadProcs[i](name, lm)) == PR_SUCCESS) {
+ break;
+ }
+ }
+ if (status != PR_SUCCESS) {
+ oserr = cfragNoLibraryErr;
+ PR_DELETE(lm);
+ goto unlock;
+ }
+ lm->name = strdup(name);
+ lm->next = pr_loadmap;
+ pr_loadmap = lm;
}
#endif
@@ -769,182 +767,94 @@ pr_LoadLibraryByPathname(const char *name, PRIntn flags)
{
#if defined(USE_DLFCN)
#ifdef NTO
- /* Neutrino needs RTLD_GROUP to load Netscape plugins. (bug 71179) */
- int dl_flags = RTLD_GROUP;
+ /* Neutrino needs RTLD_GROUP to load Netscape plugins. (bug 71179) */
+ int dl_flags = RTLD_GROUP;
#elif defined(AIX)
- /* AIX needs RTLD_MEMBER to load an archive member. (bug 228899) */
- int dl_flags = RTLD_MEMBER;
+ /* AIX needs RTLD_MEMBER to load an archive member. (bug 228899) */
+ int dl_flags = RTLD_MEMBER;
#else
- int dl_flags = 0;
+ int dl_flags = 0;
#endif
- void *h = NULL;
+ void *h = NULL;
- if (flags & PR_LD_LAZY) {
- dl_flags |= RTLD_LAZY;
- }
- if (flags & PR_LD_NOW) {
- dl_flags |= RTLD_NOW;
- }
- if (flags & PR_LD_GLOBAL) {
- dl_flags |= RTLD_GLOBAL;
- }
- if (flags & PR_LD_LOCAL) {
- dl_flags |= RTLD_LOCAL;
- }
+ if (flags & PR_LD_LAZY) {
+ dl_flags |= RTLD_LAZY;
+ }
+ if (flags & PR_LD_NOW) {
+ dl_flags |= RTLD_NOW;
+ }
+ if (flags & PR_LD_GLOBAL) {
+ dl_flags |= RTLD_GLOBAL;
+ }
+ if (flags & PR_LD_LOCAL) {
+ dl_flags |= RTLD_LOCAL;
+ }
#if defined(DARWIN)
- /* ensure the file exists if it contains a slash character i.e. path */
- /* DARWIN's dlopen ignores the provided path and checks for the */
- /* plain filename in DYLD_LIBRARY_PATH */
- if (strchr(name, PR_DIRECTORY_SEPARATOR) == NULL ||
- PR_Access(name, PR_ACCESS_EXISTS) == PR_SUCCESS) {
+ /* ensure the file exists if it contains a slash character i.e. path */
+ /* DARWIN's dlopen ignores the provided path and checks for the */
+ /* plain filename in DYLD_LIBRARY_PATH */
+ if (strchr(name, PR_DIRECTORY_SEPARATOR) == NULL ||
+ PR_Access(name, PR_ACCESS_EXISTS) == PR_SUCCESS) {
h = dlopen(name, dl_flags);
}
#else
- h = dlopen(name, dl_flags);
+ h = dlopen(name, dl_flags);
#endif
#elif defined(USE_HPSHL)
- int shl_flags = 0;
- shl_t h;
+ int shl_flags = 0;
+ shl_t h;
- /*
- * Use the DYNAMIC_PATH flag only if 'name' is a plain file
- * name (containing no directory) to match the behavior of
- * dlopen().
- */
- if (strchr(name, PR_DIRECTORY_SEPARATOR) == NULL) {
- shl_flags |= DYNAMIC_PATH;
- }
- if (flags & PR_LD_LAZY) {
- shl_flags |= BIND_DEFERRED;
- }
- if (flags & PR_LD_NOW) {
- shl_flags |= BIND_IMMEDIATE;
- }
- /* No equivalent of PR_LD_GLOBAL and PR_LD_LOCAL. */
- h = shl_load(name, shl_flags, 0L);
+ /*
+ * Use the DYNAMIC_PATH flag only if 'name' is a plain file
+ * name (containing no directory) to match the behavior of
+ * dlopen().
+ */
+ if (strchr(name, PR_DIRECTORY_SEPARATOR) == NULL) {
+ shl_flags |= DYNAMIC_PATH;
+ }
+ if (flags & PR_LD_LAZY) {
+ shl_flags |= BIND_DEFERRED;
+ }
+ if (flags & PR_LD_NOW) {
+ shl_flags |= BIND_IMMEDIATE;
+ }
+ /* No equivalent of PR_LD_GLOBAL and PR_LD_LOCAL. */
+ h = shl_load(name, shl_flags, 0L);
#elif defined(USE_MACH_DYLD)
- NSModule h = pr_LoadMachDyldModule(name);
+ NSModule h = pr_LoadMachDyldModule(name);
#else
#error Configuration error
#endif
- if (!h) {
- oserr = _MD_ERRNO();
- PR_DELETE(lm);
- goto unlock;
- }
- lm->name = strdup(name);
- lm->dlh = h;
- lm->next = pr_loadmap;
- pr_loadmap = lm;
- }
-#endif /* HAVE_DLL */
-#endif /* XP_UNIX && !(XP_MACOSX && USE_MACH_DYLD) */
-
- lm->refCount = 1;
-
-#ifdef XP_BEOS
- {
- image_info info;
- int32 cookie = 0;
- image_id imageid = B_ERROR;
- image_id stubid = B_ERROR;
- PRLibrary *p;
-
- for (p = pr_loadmap; p != NULL; p = p->next) {
- /* hopefully, our caller will always use the same string
- to refer to the same library */
- if (strcmp(name, p->name) == 0) {
- /* we've already loaded this library */
- imageid = info.id;
- lm->refCount++;
- break;
- }
- }
-
- if(imageid == B_ERROR) {
- /* it appears the library isn't yet loaded - load it now */
- char stubName [B_PATH_NAME_LENGTH + 1];
-
- /* the following is a work-around to a "bug" in the beos -
- the beos system loader allows only 32M (system-wide)
- to be used by code loaded as "add-ons" (code loaded
- through the 'load_add_on()' system call, which includes
- mozilla components), but allows 256M to be used by
- shared libraries.
-
- unfortunately, mozilla is too large to fit into the
- "add-on" space, so we must trick the loader into
- loading some of the components as shared libraries. this
- is accomplished by creating a "stub" add-on (an empty
- shared object), and linking it with the component
- (the actual .so file generated by the build process,
- without any modifications). when this stub is loaded
- by load_add_on(), the loader will automatically load the
- component into the shared library space.
- */
-
- strcpy(stubName, name);
- strcat(stubName, ".stub");
-
- /* first, attempt to load the stub (thereby loading the
- component as a shared library */
- if ((stubid = load_add_on(stubName)) > B_ERROR) {
- /* the stub was loaded successfully. */
- imageid = B_FILE_NOT_FOUND;
-
- cookie = 0;
- while (get_next_image_info(0, &cookie, &info) == B_OK) {
- const char *endOfSystemName = strrchr(info.name, '/');
- const char *endOfPassedName = strrchr(name, '/');
- if( 0 == endOfSystemName )
- endOfSystemName = info.name;
- else
- endOfSystemName++;
- if( 0 == endOfPassedName )
- endOfPassedName = name;
- else
- endOfPassedName++;
- if (strcmp(endOfSystemName, endOfPassedName) == 0) {
- /* this is the actual component - remember it */
- imageid = info.id;
- break;
- }
- }
-
- } else {
- /* we failed to load the "stub" - try to load the
- component directly as an add-on */
- stubid = B_ERROR;
- imageid = load_add_on(name);
- }
- }
-
- if (imageid <= B_ERROR) {
- oserr = imageid;
- PR_DELETE( lm );
+ if (!h) {
+ oserr = _MD_ERRNO();
+ PR_DELETE(lm);
goto unlock;
}
lm->name = strdup(name);
- lm->dlh = (void*)imageid;
- lm->stub_dlh = (void*)stubid;
+ lm->dlh = h;
lm->next = pr_loadmap;
pr_loadmap = lm;
}
-#endif
+#endif /* HAVE_DLL */
+#endif /* XP_UNIX && !(XP_MACOSX && USE_MACH_DYLD) */
+
+ lm->refCount = 1;
result = lm; /* success */
PR_LOG(_pr_linker_lm, PR_LOG_MIN, ("Loaded library %s (load lib)", lm->name));
- unlock:
+unlock:
if (result == NULL) {
PR_SetError(PR_LOAD_LIBRARY_ERROR, oserr);
DLLErrorInternal(oserr); /* sets error text */
}
#ifdef WIN32
- if (utf8name_malloc)
+ if (utf8name_malloc) {
PR_Free(utf8name_malloc);
- if (wname_malloc)
+ }
+ if (wname_malloc) {
PR_Free(wname_malloc);
+ }
#endif
PR_ExitMonitor(pr_linker_lock);
return result;
@@ -953,7 +863,7 @@ pr_LoadLibraryByPathname(const char *name, PRIntn flags)
/*
** Unload a shared library which was loaded via PR_LoadLibrary
*/
-PR_IMPLEMENT(PRStatus)
+PR_IMPLEMENT(PRStatus)
PR_UnloadLibrary(PRLibrary *lib)
{
int result = 0;
@@ -973,19 +883,12 @@ PR_UnloadLibrary(PRLibrary *lib)
}
if (--lib->refCount > 0) {
- PR_LOG(_pr_linker_lm, PR_LOG_MIN,
- ("%s decr => %d",
- lib->name, lib->refCount));
- goto done;
+ PR_LOG(_pr_linker_lm, PR_LOG_MIN,
+ ("%s decr => %d",
+ lib->name, lib->refCount));
+ goto done;
}
-#ifdef XP_BEOS
- if(((image_id)lib->stub_dlh) == B_ERROR)
- unload_add_on( (image_id) lib->dlh );
- else
- unload_add_on( (image_id) lib->stub_dlh);
-#endif
-
#ifdef XP_UNIX
#ifdef HAVE_DLL
#ifdef USE_DLFCN
@@ -993,8 +896,9 @@ PR_UnloadLibrary(PRLibrary *lib)
#elif defined(USE_HPSHL)
result = shl_unload(lib->dlh);
#elif defined(USE_MACH_DYLD)
- if (lib->dlh)
+ if (lib->dlh) {
result = NSUnLinkModule(lib->dlh, NSUNLINKMODULE_OPTION_NONE) ? 0 : -1;
+ }
#else
#error Configuration error
#endif
@@ -1009,18 +913,22 @@ PR_UnloadLibrary(PRLibrary *lib)
#if defined(XP_MACOSX) && defined(USE_MACH_DYLD)
/* Close the connection */
- if (lib->connection)
+ if (lib->connection) {
CloseConnection(&(lib->connection));
- if (lib->bundle)
+ }
+ if (lib->bundle) {
CFRelease(lib->bundle);
- if (lib->wrappers)
+ }
+ if (lib->wrappers) {
CFRelease(lib->wrappers);
+ }
/* No way to unload an image (lib->image) */
#endif
/* unlink from library search list */
- if (pr_loadmap == lib)
+ if (pr_loadmap == lib) {
pr_loadmap = pr_loadmap->next;
+ }
else if (pr_loadmap != NULL) {
PRLibrary* prev = pr_loadmap;
PRLibrary* next = pr_loadmap->next;
@@ -1047,7 +955,7 @@ PR_UnloadLibrary(PRLibrary *lib)
* succeeds or not.
*/
- freeLib:
+freeLib:
PR_LOG(_pr_linker_lm, PR_LOG_MIN, ("Unloaded library %s", lib->name));
free(lib->name);
lib->name = NULL;
@@ -1063,7 +971,7 @@ done:
return status;
}
-static void*
+static void*
pr_FindSymbolInLib(PRLibrary *lm, const char *name)
{
void *f = NULL;
@@ -1078,16 +986,16 @@ pr_FindSymbolInLib(PRLibrary *lm, const char *name)
return (void*) tp->fp;
}
}
- /*
+ /*
** If the symbol was not found in the static table then check if
** the symbol was exported in the DLL... Win16 only!!
*/
-#if !defined(WIN16) && !defined(XP_BEOS)
+#if !defined(WIN16)
PR_SetError(PR_FIND_SYMBOL_ERROR, 0);
return (void*)NULL;
#endif
}
-
+
#ifdef XP_OS2
rc = DosQueryProcAddr(lm->dlh, 0, (PSZ) name, (PFN *) &f);
#if defined(NEED_LEADING_UNDERSCORE)
@@ -1107,7 +1015,7 @@ pr_FindSymbolInLib(PRLibrary *lm, const char *name)
#endif /* WIN32 */
#if defined(XP_MACOSX) && defined(USE_MACH_DYLD)
-/* add this offset to skip the leading underscore in name */
+ /* add this offset to skip the leading underscore in name */
#define SYM_OFFSET 1
if (lm->bundle) {
CFStringRef nameRef = CFStringCreateWithCString(NULL, name + SYM_OFFSET, kCFStringEncodingASCII);
@@ -1120,41 +1028,39 @@ pr_FindSymbolInLib(PRLibrary *lm, const char *name)
Ptr symAddr;
CFragSymbolClass symClass;
Str255 pName;
-
+
PR_LOG(_pr_linker_lm, PR_LOG_MIN, ("Looking up symbol: %s", name + SYM_OFFSET));
-
+
c2pstrcpy(pName, name + SYM_OFFSET);
-
+
f = (FindSymbol(lm->connection, pName, &symAddr, &symClass) == noErr) ? symAddr : NULL;
-
+
#ifdef __ppc__
/* callers expect mach-o function pointers, so must wrap tvectors with glue. */
if (f && symClass == kTVectorCFragSymbol) {
f = TV2FP(lm->wrappers, name + SYM_OFFSET, f);
}
#endif /* __ppc__ */
-
- if (f == NULL && strcmp(name + SYM_OFFSET, "main") == 0) f = lm->main;
+
+ if (f == NULL && strcmp(name + SYM_OFFSET, "main") == 0) {
+ f = lm->main;
+ }
}
if (lm->image) {
NSSymbol symbol;
symbol = NSLookupSymbolInImage(lm->image, name,
- NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
- | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
- if (symbol != NULL)
+ NSLOOKUPSYMBOLINIMAGE_OPTION_BIND
+ | NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
+ if (symbol != NULL) {
f = NSAddressOfSymbol(symbol);
- else
+ }
+ else {
f = NULL;
+ }
}
#undef SYM_OFFSET
#endif /* XP_MACOSX && USE_MACH_DYLD */
-#ifdef XP_BEOS
- if( B_NO_ERROR != get_image_symbol( (image_id)lm->dlh, name, B_SYMBOL_TYPE_TEXT, &f ) ) {
- f = NULL;
- }
-#endif
-
#ifdef XP_UNIX
#ifdef HAVE_DLL
#ifdef USE_DLFCN
@@ -1167,10 +1073,12 @@ pr_FindSymbolInLib(PRLibrary *lm, const char *name)
if (lm->dlh) {
NSSymbol symbol;
symbol = NSLookupSymbolInModule(lm->dlh, name);
- if (symbol != NULL)
+ if (symbol != NULL) {
f = NSAddressOfSymbol(symbol);
- else
+ }
+ else {
f = NULL;
+ }
}
#endif
#endif /* HAVE_DLL */
@@ -1185,7 +1093,7 @@ pr_FindSymbolInLib(PRLibrary *lm, const char *name)
/*
** Called by class loader to resolve missing native's
*/
-PR_IMPLEMENT(void*)
+PR_IMPLEMENT(void*)
PR_FindSymbol(PRLibrary *lib, const char *raw_name)
{
void *f = NULL;
@@ -1226,13 +1134,13 @@ PR_FindSymbol(PRLibrary *lib, const char *raw_name)
/*
** Return the address of the function 'raw_name' in the library 'lib'
*/
-PR_IMPLEMENT(PRFuncPtr)
+PR_IMPLEMENT(PRFuncPtr)
PR_FindFunctionSymbol(PRLibrary *lib, const char *raw_name)
{
return ((PRFuncPtr) PR_FindSymbol(lib, raw_name));
}
-PR_IMPLEMENT(void*)
+PR_IMPLEMENT(void*)
PR_FindSymbolAndLibrary(const char *raw_name, PRLibrary* *lib)
{
void *f = NULL;
@@ -1243,7 +1151,9 @@ PR_FindSymbolAndLibrary(const char *raw_name, PRLibrary* *lib)
#endif
PRLibrary* lm;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
/*
** Mangle the raw symbol name in any way that is platform specific.
*/
@@ -1270,7 +1180,7 @@ PR_FindSymbolAndLibrary(const char *raw_name, PRLibrary* *lib)
*lib = lm;
lm->refCount++;
PR_LOG(_pr_linker_lm, PR_LOG_MIN,
- ("%s incr => %d (for %s)",
+ ("%s incr => %d (for %s)",
lm->name, lm->refCount, name));
break;
}
@@ -1283,7 +1193,7 @@ PR_FindSymbolAndLibrary(const char *raw_name, PRLibrary* *lib)
return f;
}
-PR_IMPLEMENT(PRFuncPtr)
+PR_IMPLEMENT(PRFuncPtr)
PR_FindFunctionSymbolAndLibrary(const char *raw_name, PRLibrary* *lib)
{
return ((PRFuncPtr) PR_FindSymbolAndLibrary(raw_name, lib));
@@ -1293,13 +1203,15 @@ PR_FindFunctionSymbolAndLibrary(const char *raw_name, PRLibrary* *lib)
** Add a static library to the list of loaded libraries. If LoadLibrary
** is called with the name then we will pretend it was already loaded
*/
-PR_IMPLEMENT(PRLibrary*)
+PR_IMPLEMENT(PRLibrary*)
PR_LoadStaticLibrary(const char *name, const PRStaticLinkTable *slt)
{
PRLibrary *lm=NULL;
PRLibrary* result = NULL;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
/* See if library is already loaded */
PR_EnterMonitor(pr_linker_lock);
@@ -1314,7 +1226,9 @@ PR_LoadStaticLibrary(const char *name, const PRStaticLinkTable *slt)
/* Add library to list...Mark it static */
lm = PR_NEWZAP(PRLibrary);
- if (lm == NULL) goto unlock;
+ if (lm == NULL) {
+ goto unlock;
+ }
lm->name = strdup(name);
lm->refCount = 1;
@@ -1326,7 +1240,7 @@ PR_LoadStaticLibrary(const char *name, const PRStaticLinkTable *slt)
result = lm; /* success */
PR_ASSERT(lm->refCount == 1);
PR_LOG(_pr_linker_lm, PR_LOG_MIN, ("Loaded library %s (static lib)", lm->name));
- unlock:
+unlock:
PR_ExitMonitor(pr_linker_lock);
return result;
}
@@ -1425,74 +1339,6 @@ PR_GetLibraryFilePathname(const char *name, PRFuncPtr addr)
}
PR_Free(info);
return result;
-#elif defined(OSF1)
- /* Contributed by Steve Streeter of HP */
- ldr_process_t process, ldr_my_process();
- ldr_module_t mod_id;
- ldr_module_info_t info;
- ldr_region_t regno;
- ldr_region_info_t reginfo;
- size_t retsize;
- int rv;
- char *result;
-
- /* Get process for which dynamic modules will be listed */
-
- process = ldr_my_process();
-
- /* Attach to process */
-
- rv = ldr_xattach(process);
- if (rv) {
- /* should not happen */
- _PR_MD_MAP_DEFAULT_ERROR(_MD_ERRNO());
- return NULL;
- }
-
- /* Print information for list of modules */
-
- mod_id = LDR_NULL_MODULE;
-
- for (;;) {
-
- /* Get information for the next module in the module list. */
-
- ldr_next_module(process, &mod_id);
- if (ldr_inq_module(process, mod_id, &info, sizeof(info),
- &retsize) != 0) {
- /* No more modules */
- break;
- }
- if (retsize < sizeof(info)) {
- continue;
- }
-
- /*
- * Get information for each region in the module and check if any
- * contain the address of this function.
- */
-
- for (regno = 0; ; regno++) {
- if (ldr_inq_region(process, mod_id, regno, &reginfo,
- sizeof(reginfo), &retsize) != 0) {
- /* No more regions */
- break;
- }
- if (((unsigned long)reginfo.lri_mapaddr <=
- (unsigned long)addr) &&
- (((unsigned long)reginfo.lri_mapaddr + reginfo.lri_size) >
- (unsigned long)addr)) {
- /* Found it. */
- result = PR_Malloc(strlen(info.lmi_name)+1);
- if (result != NULL) {
- strcpy(result, info.lmi_name);
- }
- return result;
- }
- }
- }
- PR_SetError(PR_LIBRARY_NOT_LOADED_ERROR, 0);
- return NULL;
#elif defined(HPUX) && defined(USE_HPSHL)
int index;
struct shl_descriptor desc;
@@ -1516,7 +1362,7 @@ PR_GetLibraryFilePathname(const char *name, PRFuncPtr addr)
*/
for (index--; index >= 0; index--) {
if ((shl_get_r(index, &desc) == 0)
- && (strstr(desc.filename, name) != NULL)) {
+ && (strstr(desc.filename, name) != NULL)) {
result = PR_Malloc(strlen(desc.filename)+1);
if (result != NULL) {
strcpy(result, desc.filename);
diff --git a/nsprpub/pr/src/malloc/prmalloc.c b/nsprpub/pr/src/malloc/prmalloc.c
index 174d0daf7..c03b7d11e 100644
--- a/nsprpub/pr/src/malloc/prmalloc.c
+++ b/nsprpub/pr/src/malloc/prmalloc.c
@@ -60,12 +60,12 @@ void *_PR_UnlockedCalloc(size_t n, size_t elsize);
# define TRACE(foo) printf foo
static int malloc_event;
#else
-# define TRACE(foo)
+# define TRACE(foo)
#endif
/* XXX Pick a number, any number */
-# define malloc_pagesize 4096UL
-# define malloc_pageshift 12UL
+# define malloc_pagesize 4096UL
+# define malloc_pageshift 12UL
#ifdef XP_UNIX
#include <stdio.h>
@@ -82,61 +82,61 @@ static int malloc_event;
*/
struct pginfo {
- struct pginfo *next; /* next on the free list */
- char *page; /* Pointer to the page */
- u_short size; /* size of this page's chunks */
- u_short shift; /* How far to shift for this size chunks */
- u_short free; /* How many free chunks */
- u_short total; /* How many chunk */
- u_long bits[1]; /* Which chunks are free */
+ struct pginfo *next; /* next on the free list */
+ char *page; /* Pointer to the page */
+ u_short size; /* size of this page's chunks */
+ u_short shift; /* How far to shift for this size chunks */
+ u_short free; /* How many free chunks */
+ u_short total; /* How many chunk */
+ u_long bits[1]; /* Which chunks are free */
};
struct pgfree {
- struct pgfree *next; /* next run of free pages */
- struct pgfree *prev; /* prev run of free pages */
- char *page; /* pointer to free pages */
- char *end; /* pointer to end of free pages */
- u_long size; /* number of bytes free */
+ struct pgfree *next; /* next run of free pages */
+ struct pgfree *prev; /* prev run of free pages */
+ char *page; /* pointer to free pages */
+ char *end; /* pointer to end of free pages */
+ u_long size; /* number of bytes free */
};
/*
* How many bits per u_long in the bitmap.
* Change only if not 8 bits/byte
*/
-#define MALLOC_BITS (8*sizeof(u_long))
+#define MALLOC_BITS (8*sizeof(u_long))
/*
* Magic values to put in the page_directory
*/
-#define MALLOC_NOT_MINE ((struct pginfo*) 0)
-#define MALLOC_FREE ((struct pginfo*) 1)
-#define MALLOC_FIRST ((struct pginfo*) 2)
-#define MALLOC_FOLLOW ((struct pginfo*) 3)
-#define MALLOC_MAGIC ((struct pginfo*) 4)
+#define MALLOC_NOT_MINE ((struct pginfo*) 0)
+#define MALLOC_FREE ((struct pginfo*) 1)
+#define MALLOC_FIRST ((struct pginfo*) 2)
+#define MALLOC_FOLLOW ((struct pginfo*) 3)
+#define MALLOC_MAGIC ((struct pginfo*) 4)
/*
* Set to one when malloc_init has been called
*/
-static unsigned initialized;
+static unsigned initialized;
/*
* The size of a page.
* Must be a integral multiplum of the granularity of mmap(2).
* Your toes will curl if it isn't a power of two
*/
-#define malloc_pagemask ((malloc_pagesize)-1)
+#define malloc_pagemask ((malloc_pagesize)-1)
/*
* The size of the largest chunk.
* Half a page.
*/
-#define malloc_maxsize ((malloc_pagesize)>>1)
+#define malloc_maxsize ((malloc_pagesize)>>1)
/*
* malloc_pagesize == 1 << malloc_pageshift
*/
#ifndef malloc_pageshift
-static unsigned malloc_pageshift;
+static unsigned malloc_pageshift;
#endif /* malloc_pageshift */
/*
@@ -144,7 +144,7 @@ static unsigned malloc_pageshift;
* Must be power of two
*/
#ifndef malloc_minsize
-static unsigned malloc_minsize;
+static unsigned malloc_minsize;
#endif /* malloc_minsize */
/*
@@ -153,38 +153,38 @@ static unsigned malloc_minsize;
* Must be power of two
*/
#ifndef malloc_maxsize
-static unsigned malloc_maxsize;
+static unsigned malloc_maxsize;
#endif /* malloc_maxsize */
#ifndef malloc_cache
-static unsigned malloc_cache;
+static unsigned malloc_cache;
#endif /* malloc_cache */
/*
* The offset from pagenumber to index into the page directory
*/
-static u_long malloc_origo;
+static u_long malloc_origo;
/*
* The last index in the page directory we care about
*/
-static u_long last_index;
+static u_long last_index;
/*
* Pointer to page directory.
* Allocated "as if with" malloc
*/
-static struct pginfo **page_dir;
+static struct pginfo **page_dir;
/*
* How many slots in the page directory
*/
-static unsigned malloc_ninfo;
+static unsigned malloc_ninfo;
/*
- * Free pages line up here
+ * Free pages line up here
*/
-static struct pgfree free_list;
+static struct pgfree free_list;
/*
* Abort() if we fail to get VM ?
@@ -232,39 +232,39 @@ malloc_dump(FILE *fd)
pd = page_dir;
/* print out all the pages */
- for(j=0;j<=last_index;j++) {
- fprintf(fd,"%08lx %5d ",(j+malloc_origo) << malloc_pageshift,j);
- if (pd[j] == MALLOC_NOT_MINE) {
- for(j++;j<=last_index && pd[j] == MALLOC_NOT_MINE;j++)
- ;
- j--;
- fprintf(fd,".. %5d not mine\n", j);
- } else if (pd[j] == MALLOC_FREE) {
- for(j++;j<=last_index && pd[j] == MALLOC_FREE;j++)
- ;
- j--;
- fprintf(fd,".. %5d free\n", j);
- } else if (pd[j] == MALLOC_FIRST) {
- for(j++;j<=last_index && pd[j] == MALLOC_FOLLOW;j++)
- ;
- j--;
- fprintf(fd,".. %5d in use\n", j);
- } else if (pd[j] < MALLOC_MAGIC) {
- fprintf(fd,"(%p)\n", pd[j]);
- } else {
- fprintf(fd,"%p %d (of %d) x %d @ %p --> %p\n",
- pd[j],pd[j]->free, pd[j]->total,
- pd[j]->size, pd[j]->page, pd[j]->next);
- }
+ for(j=0; j<=last_index; j++) {
+ fprintf(fd,"%08lx %5d ",(j+malloc_origo) << malloc_pageshift,j);
+ if (pd[j] == MALLOC_NOT_MINE) {
+ for(j++; j<=last_index && pd[j] == MALLOC_NOT_MINE; j++)
+ ;
+ j--;
+ fprintf(fd,".. %5d not mine\n", j);
+ } else if (pd[j] == MALLOC_FREE) {
+ for(j++; j<=last_index && pd[j] == MALLOC_FREE; j++)
+ ;
+ j--;
+ fprintf(fd,".. %5d free\n", j);
+ } else if (pd[j] == MALLOC_FIRST) {
+ for(j++; j<=last_index && pd[j] == MALLOC_FOLLOW; j++)
+ ;
+ j--;
+ fprintf(fd,".. %5d in use\n", j);
+ } else if (pd[j] < MALLOC_MAGIC) {
+ fprintf(fd,"(%p)\n", pd[j]);
+ } else {
+ fprintf(fd,"%p %d (of %d) x %d @ %p --> %p\n",
+ pd[j],pd[j]->free, pd[j]->total,
+ pd[j]->size, pd[j]->page, pd[j]->next);
+ }
}
for(pf=free_list.next; pf; pf=pf->next) {
- fprintf(fd,"Free: @%p [%p...%p[ %ld ->%p <-%p\n",
- pf,pf->page,pf->end,pf->size,pf->prev,pf->next);
- if (pf == pf->next) {
- fprintf(fd,"Free_list loops.\n");
- break;
- }
+ fprintf(fd,"Free: @%p [%p...%p[ %ld ->%p <-%p\n",
+ pf,pf->page,pf->end,pf->size,pf->prev,pf->next);
+ if (pf == pf->next) {
+ fprintf(fd,"Free_list loops.\n");
+ break;
+ }
}
/* print out various info */
@@ -274,7 +274,7 @@ malloc_dump(FILE *fd)
fprintf(fd,"Pageshift\t%ld\n",malloc_pageshift);
fprintf(fd,"FirstPage\t%ld\n",malloc_origo);
fprintf(fd,"LastPage\t%ld %lx\n",last_index+malloc_pageshift,
- (last_index + malloc_pageshift) << malloc_pageshift);
+ (last_index + malloc_pageshift) << malloc_pageshift);
fprintf(fd,"Break\t%ld\n",(u_long)sbrk(0) >> malloc_pageshift);
}
@@ -323,12 +323,13 @@ map_pages(int pages, int update)
result = (caddr_t) ((u_long)result & ~malloc_pagemask);
tail = result + (pages << malloc_pageshift);
if (!brk(tail)) {
- last_index = ((u_long)tail >> malloc_pageshift) - malloc_origo -1;
- malloc_brk = tail;
- TRACE(("%6d S %p .. %p\n",malloc_event++, result, tail));
- if (!update || last_index < malloc_ninfo ||
- extend_page_directory(last_index))
- return result;
+ last_index = ((u_long)tail >> malloc_pageshift) - malloc_origo -1;
+ malloc_brk = tail;
+ TRACE(("%6d S %p .. %p\n",malloc_event++, result, tail));
+ if (!update || last_index < malloc_ninfo ||
+ extend_page_directory(last_index)) {
+ return result;
+ }
}
TRACE(("%6d s %d %p %d\n",malloc_event++,pages,sbrk(0),errno));
#ifdef EXTRA_SANITY
@@ -356,7 +357,7 @@ extend_page_directory(u_long index)
int i;
TRACE(("%6d E %lu\n",malloc_event++,index));
-
+
/* Make it this many pages */
i = index * sizeof *page_dir;
i /= malloc_pagesize;
@@ -364,13 +365,14 @@ extend_page_directory(u_long index)
/* Get new pages, if you used this much mem you don't care :-) */
young = (struct pginfo**) map_pages(i,0);
- if (!young)
- return 0;
+ if (!young) {
+ return 0;
+ }
/* Copy the old stuff */
memset(young, 0, i * malloc_pagesize);
memcpy(young, page_dir,
- malloc_ninfo * sizeof *page_dir);
+ malloc_ninfo * sizeof *page_dir);
/* register the new size */
malloc_ninfo = i * malloc_pagesize / sizeof *page_dir;
@@ -383,7 +385,7 @@ extend_page_directory(u_long index)
index = ((u_long)young >> malloc_pageshift) - malloc_origo;
page_dir[index] = MALLOC_FIRST;
while (--i) {
- page_dir[++index] = MALLOC_FOLLOW;
+ page_dir[++index] = MALLOC_FOLLOW;
}
/* Now free the old stuff */
@@ -400,8 +402,9 @@ set_pgdir(void *ptr, struct pginfo *info)
{
u_long index = ((u_long)ptr >> malloc_pageshift) - malloc_origo;
- if (index >= malloc_ninfo && !extend_page_directory(index))
- return 0;
+ if (index >= malloc_ninfo && !extend_page_directory(index)) {
+ return 0;
+ }
page_dir[index] = info;
return 1;
}
@@ -418,17 +421,17 @@ malloc_init (void)
TRACE(("%6d I\n",malloc_event++));
#ifdef DEBUG
for (p=getenv("MALLOC_OPTIONS"); p && *p; p++) {
- switch (*p) {
- case 'a': malloc_abort = 0; break;
- case 'A': malloc_abort = 1; break;
- case 'd': malloc_stats = 0; break;
- case 'D': malloc_stats = 1; break;
- case 'r': malloc_realloc = 0; break;
- case 'R': malloc_realloc = 1; break;
- default:
- wrtwarning("Unknown chars in MALLOC_OPTIONS\n");
- break;
- }
+ switch (*p) {
+ case 'a': malloc_abort = 0; break;
+ case 'A': malloc_abort = 1; break;
+ case 'd': malloc_stats = 0; break;
+ case 'D': malloc_stats = 1; break;
+ case 'r': malloc_realloc = 0; break;
+ case 'R': malloc_realloc = 1; break;
+ default:
+ wrtwarning("Unknown chars in MALLOC_OPTIONS\n");
+ break;
+ }
}
#endif
@@ -439,12 +442,13 @@ malloc_init (void)
#ifndef malloc_pageshift
/* determine how much we shift by to get there */
- for (i = malloc_pagesize; i > 1; i >>= 1)
- malloc_pageshift++;
+ for (i = malloc_pagesize; i > 1; i >>= 1) {
+ malloc_pageshift++;
+ }
#endif /* malloc_pageshift */
#ifndef malloc_cache
- malloc_cache = 50 << malloc_pageshift;
+ malloc_cache = 50 << malloc_pageshift;
#endif /* malloc_cache */
#ifndef malloc_minsize
@@ -455,16 +459,18 @@ malloc_init (void)
*/
i = 2;
for(;;) {
- int j;
+ int j;
- /* Figure out the size of the bits */
- j = malloc_pagesize/i;
- j /= 8;
- if (j < sizeof(u_long))
- j = sizeof (u_long);
- if (sizeof(struct pginfo) + j - sizeof (u_long) <= i)
- break;
- i += i;
+ /* Figure out the size of the bits */
+ j = malloc_pagesize/i;
+ j /= 8;
+ if (j < sizeof(u_long)) {
+ j = sizeof (u_long);
+ }
+ if (sizeof(struct pginfo) + j - sizeof (u_long) <= i) {
+ break;
+ }
+ i += i;
}
malloc_minsize = i;
#endif /* malloc_minsize */
@@ -473,8 +479,9 @@ malloc_init (void)
/* Allocate one page for the page directory */
page_dir = (struct pginfo **) map_pages(1,0);
#ifdef SANITY
- if (!page_dir)
- wrterror("fatal: my first mmap failed. (check limits ?)\n");
+ if (!page_dir) {
+ wrterror("fatal: my first mmap failed. (check limits ?)\n");
+ }
#endif
/*
@@ -493,8 +500,9 @@ malloc_init (void)
/* Plug the page directory into itself */
i = set_pgdir(page_dir,MALLOC_FIRST);
#ifdef SANITY
- if (!i)
- wrterror("fatal: couldn't set myself in the page directory\n");
+ if (!i) {
+ wrterror("fatal: couldn't set myself in the page directory\n");
+ }
#endif
/* Been here, done that */
@@ -519,66 +527,75 @@ static void *malloc_pages(size_t size)
/* Look for free pages before asking for more */
for(pf = free_list.next; pf; pf = pf->next) {
#ifdef EXTRA_SANITY
- if (pf->page == pf->end)
- wrterror("zero entry on free_list\n");
- if (pf->page > pf->end) {
- TRACE(("%6d !s %p %p %p <%d>\n",malloc_event++,
- pf,pf->page,pf->end,__LINE__));
- wrterror("sick entry on free_list\n");
- }
- if ((void*)pf->page >= (void*)sbrk(0))
- wrterror("entry on free_list past brk\n");
- if (page_dir[((u_long)pf->page >> malloc_pageshift) - malloc_origo]
- != MALLOC_FREE) {
- TRACE(("%6d !f %p %p %p <%d>\n",malloc_event++,
- pf,pf->page,pf->end,__LINE__));
- wrterror("non-free first page on free-list\n");
- }
- if (page_dir[((u_long)pf->end >> malloc_pageshift) - 1 - malloc_origo]
- != MALLOC_FREE)
- wrterror("non-free last page on free-list\n");
+ if (pf->page == pf->end) {
+ wrterror("zero entry on free_list\n");
+ }
+ if (pf->page > pf->end) {
+ TRACE(("%6d !s %p %p %p <%d>\n",malloc_event++,
+ pf,pf->page,pf->end,__LINE__));
+ wrterror("sick entry on free_list\n");
+ }
+ if ((void*)pf->page >= (void*)sbrk(0)) {
+ wrterror("entry on free_list past brk\n");
+ }
+ if (page_dir[((u_long)pf->page >> malloc_pageshift) - malloc_origo]
+ != MALLOC_FREE) {
+ TRACE(("%6d !f %p %p %p <%d>\n",malloc_event++,
+ pf,pf->page,pf->end,__LINE__));
+ wrterror("non-free first page on free-list\n");
+ }
+ if (page_dir[((u_long)pf->end >> malloc_pageshift) - 1 - malloc_origo]
+ != MALLOC_FREE) {
+ wrterror("non-free last page on free-list\n");
+ }
#endif /* EXTRA_SANITY */
- if (pf->size < size)
- continue;
- else if (pf->size == size) {
- p = pf->page;
- if (pf->next)
- pf->next->prev = pf->prev;
- pf->prev->next = pf->next;
- delay_free = pf;
- break;
- } else {
- p = pf->page;
- pf->page += size;
- pf->size -= size;
- break;
+ if (pf->size < size) {
+ continue;
+ }
+ else if (pf->size == size) {
+ p = pf->page;
+ if (pf->next) {
+ pf->next->prev = pf->prev;
+ }
+ pf->prev->next = pf->next;
+ delay_free = pf;
+ break;
+ } else {
+ p = pf->page;
+ pf->page += size;
+ pf->size -= size;
+ break;
}
}
#ifdef EXTRA_SANITY
- if (p && page_dir[((u_long)p >> malloc_pageshift) - malloc_origo]
- != MALLOC_FREE) {
- wrterror("allocated non-free page on free-list\n");
+ if (p && page_dir[((u_long)p >> malloc_pageshift) - malloc_origo]
+ != MALLOC_FREE) {
+ wrterror("allocated non-free page on free-list\n");
}
#endif /* EXTRA_SANITY */
size >>= malloc_pageshift;
/* Map new pages */
- if (!p)
- p = map_pages(size,1);
+ if (!p) {
+ p = map_pages(size,1);
+ }
if (p) {
- /* Mark the pages in the directory */
- index = ((u_long)p >> malloc_pageshift) - malloc_origo;
- page_dir[index] = MALLOC_FIRST;
- for (i=1;i<size;i++)
- page_dir[index+i] = MALLOC_FOLLOW;
+ /* Mark the pages in the directory */
+ index = ((u_long)p >> malloc_pageshift) - malloc_origo;
+ page_dir[index] = MALLOC_FIRST;
+ for (i=1; i<size; i++) {
+ page_dir[index+i] = MALLOC_FOLLOW;
+ }
}
if (delay_free) {
- if (!px)
- px = (struct pgfree*)delay_free;
- else
- _PR_UnlockedFree(delay_free);
+ if (!px) {
+ px = (struct pgfree*)delay_free;
+ }
+ else {
+ _PR_UnlockedFree(delay_free);
+ }
}
return p;
}
@@ -596,26 +613,29 @@ malloc_make_chunks(int bits)
/* Allocate a new bucket */
pp = malloc_pages(malloc_pagesize);
- if (!pp)
- return 0;
+ if (!pp) {
+ return 0;
+ }
l = sizeof *bp - sizeof(u_long);
l += sizeof(u_long) *
- (((malloc_pagesize >> bits)+MALLOC_BITS-1) / MALLOC_BITS);
+ (((malloc_pagesize >> bits)+MALLOC_BITS-1) / MALLOC_BITS);
if ((1<<(bits)) <= l+l) {
- bp = (struct pginfo *)pp;
+ bp = (struct pginfo *)pp;
} else {
- bp = (struct pginfo *)_PR_UnlockedMalloc(l);
+ bp = (struct pginfo *)_PR_UnlockedMalloc(l);
+ }
+ if (!bp) {
+ return 0;
}
- if (!bp)
- return 0;
bp->size = (1<<bits);
bp->shift = bits;
bp->total = bp->free = malloc_pagesize >> bits;
bp->next = page_dir[bits];
bp->page = (char*)pp;
i = set_pgdir(pp,bp);
- if (!i)
- return 0;
+ if (!i) {
+ return 0;
+ }
/* We can safely assume that there is nobody in this chain */
page_dir[bits] = bp;
@@ -623,22 +643,24 @@ malloc_make_chunks(int bits)
/* set all valid bits in the bits */
k = bp->total;
i = 0;
-/*
- for(;k-i >= MALLOC_BITS; i += MALLOC_BITS)
- bp->bits[i / MALLOC_BITS] = ~0;
-*/
- for(; i < k; i++)
- set_bit(bp,i);
+ /*
+ for(;k-i >= MALLOC_BITS; i += MALLOC_BITS)
+ bp->bits[i / MALLOC_BITS] = ~0;
+ */
+ for(; i < k; i++) {
+ set_bit(bp,i);
+ }
- if (bp != pp)
- return 1;
+ if (bp != pp) {
+ return 1;
+ }
/* We may have used the first ones already */
- for(i=0;l > 0;i++) {
- clr_bit(bp,i);
- bp->free--;
- bp->total--;
- l -= (1 << bits);
+ for(i=0; l > 0; i++) {
+ clr_bit(bp,i);
+ bp->free--;
+ bp->total--;
+ l -= (1 << bits);
}
return 1;
}
@@ -656,7 +678,7 @@ static void *malloc_bytes(size_t size)
/* Don't bother with anything less than this */
if (size < malloc_minsize) {
- size = malloc_minsize;
+ size = malloc_minsize;
}
/* Find the right bucket */
@@ -667,27 +689,28 @@ static void *malloc_bytes(size_t size)
}
/* If it's empty, make a page more of that size chunks */
- if (!page_dir[j] && !malloc_make_chunks(j))
- return 0;
+ if (!page_dir[j] && !malloc_make_chunks(j)) {
+ return 0;
+ }
/* Find first word of bitmap which isn't empty */
bp = page_dir[j];
for (lp = bp->bits; !*lp; lp++)
- ;
+ ;
/* Find that bit */
bf = *lp;
k = 0;
while ((bf & 1) == 0) {
- bf >>= 1;
- k++;
+ bf >>= 1;
+ k++;
}
*lp ^= 1L<<k; /* clear it */
bp->free--;
if (!bp->free) {
- page_dir[j] = bp->next;
- bp->next = 0;
+ page_dir[j] = bp->next;
+ bp->next = 0;
}
k += (lp - bp->bits)*MALLOC_BITS;
return bp->page + (k << bp->shift);
@@ -699,24 +722,29 @@ void *_PR_UnlockedMalloc(size_t size)
/* Round up to a multiple of 8 bytes */
if (size & 7) {
- size = size + 8 - (size & 7);
+ size = size + 8 - (size & 7);
}
- if (!initialized)
- malloc_init();
+ if (!initialized) {
+ malloc_init();
+ }
#ifdef SANITY
- if (suicide)
- PR_Abort();
+ if (suicide) {
+ PR_Abort();
+ }
#endif
- if (size <= malloc_maxsize)
- result = malloc_bytes(size);
- else
- result = malloc_pages(size);
+ if (size <= malloc_maxsize) {
+ result = malloc_bytes(size);
+ }
+ else {
+ result = malloc_pages(size);
+ }
#ifdef SANITY
- if (malloc_abort && !result)
- wrterror("malloc() returns NULL\n");
+ if (malloc_abort && !result) {
+ wrterror("malloc() returns NULL\n");
+ }
#endif
TRACE(("%6d M %p %d\n",malloc_event++,result,size));
@@ -731,38 +759,47 @@ void *_PR_UnlockedMemalign(size_t alignment, size_t size)
* alignment has to be a power of 2
*/
- if ((size <= alignment) && (alignment <= malloc_maxsize))
- size = alignment;
- else
- size += alignment - 1;
+ if ((size <= alignment) && (alignment <= malloc_maxsize)) {
+ size = alignment;
+ }
+ else {
+ size += alignment - 1;
+ }
/* Round up to a multiple of 8 bytes */
if (size & 7) {
- size = size + 8 - (size & 7);
+ size = size + 8 - (size & 7);
}
- if (!initialized)
- malloc_init();
+ if (!initialized) {
+ malloc_init();
+ }
#ifdef SANITY
- if (suicide)
- abort();
+ if (suicide) {
+ abort();
+ }
#endif
- if (size <= malloc_maxsize)
- result = malloc_bytes(size);
- else
- result = malloc_pages(size);
+ if (size <= malloc_maxsize) {
+ result = malloc_bytes(size);
+ }
+ else {
+ result = malloc_pages(size);
+ }
#ifdef SANITY
- if (malloc_abort && !result)
- wrterror("malloc() returns NULL\n");
+ if (malloc_abort && !result) {
+ wrterror("malloc() returns NULL\n");
+ }
#endif
TRACE(("%6d A %p %d\n",malloc_event++,result,size));
- if ((u_long)result & (alignment - 1))
- return ((void *)(((u_long)result + alignment) & ~(alignment - 1)));
- else
- return result;
+ if ((u_long)result & (alignment - 1)) {
+ return ((void *)(((u_long)result + alignment) & ~(alignment - 1)));
+ }
+ else {
+ return result;
+ }
}
void *_PR_UnlockedCalloc(size_t n, size_t nelem)
@@ -772,14 +809,14 @@ void *_PR_UnlockedCalloc(size_t n, size_t nelem)
/* Compute total size and then round up to a double word amount */
n *= nelem;
if (n & 7) {
- n = n + 8 - (n & 7);
+ n = n + 8 - (n & 7);
}
/* Get the memory */
p = _PR_UnlockedMalloc(n);
if (p) {
- /* Zero it */
- memset(p, 0, n);
+ /* Zero it */
+ memset(p, 0, n);
}
return p;
}
@@ -793,25 +830,27 @@ void *_PR_UnlockedRealloc(void *ptr, size_t size)
u_long osize,page,index,tmp_index;
struct pginfo **mp;
- if (!initialized)
- malloc_init();
+ if (!initialized) {
+ malloc_init();
+ }
#ifdef SANITY
- if (suicide)
- PR_Abort();
+ if (suicide) {
+ PR_Abort();
+ }
#endif
/* used as free() */
TRACE(("%6d R %p %d\n",malloc_event++, ptr, size));
if (ptr && !size) {
- _PR_UnlockedFree(ptr);
- return _PR_UnlockedMalloc (1);
+ _PR_UnlockedFree(ptr);
+ return _PR_UnlockedMalloc (1);
}
/* used as malloc() */
if (!ptr) {
- p = _PR_UnlockedMalloc(size);
- return p;
+ p = _PR_UnlockedMalloc(size);
+ return p;
}
/* Find the page directory entry for the page in question */
@@ -822,50 +861,51 @@ void *_PR_UnlockedRealloc(void *ptr, size_t size)
* check if memory was allocated by memalign
*/
tmp_index = index;
- while (page_dir[tmp_index] == MALLOC_FOLLOW)
- tmp_index--;
+ while (page_dir[tmp_index] == MALLOC_FOLLOW) {
+ tmp_index--;
+ }
if (tmp_index != index) {
- /*
- * memalign-allocated memory
- */
- index = tmp_index;
- page = index + malloc_origo;
- ptr = (void *) (page << malloc_pageshift);
+ /*
+ * memalign-allocated memory
+ */
+ index = tmp_index;
+ page = index + malloc_origo;
+ ptr = (void *) (page << malloc_pageshift);
}
TRACE(("%6d R2 %p %d\n",malloc_event++, ptr, size));
/* make sure it makes sense in some fashion */
if (index < malloc_pageshift || index > last_index) {
#ifdef SANITY
- wrtwarning("junk pointer passed to realloc()\n");
+ wrtwarning("junk pointer passed to realloc()\n");
#endif
- return 0;
+ return 0;
}
/* find the size of that allocation, and see if we need to relocate */
mp = &page_dir[index];
if (*mp == MALLOC_FIRST) {
- osize = malloc_pagesize;
- while (mp[1] == MALLOC_FOLLOW) {
- osize += malloc_pagesize;
- mp++;
- }
- if (!malloc_realloc &&
- size < osize &&
- size > malloc_maxsize &&
- size > (osize - malloc_pagesize)) {
- return ptr;
- }
+ osize = malloc_pagesize;
+ while (mp[1] == MALLOC_FOLLOW) {
+ osize += malloc_pagesize;
+ mp++;
+ }
+ if (!malloc_realloc &&
+ size < osize &&
+ size > malloc_maxsize &&
+ size > (osize - malloc_pagesize)) {
+ return ptr;
+ }
} else if (*mp >= MALLOC_MAGIC) {
- osize = (*mp)->size;
- if (!malloc_realloc &&
- size < osize &&
- (size > (*mp)->size/2 || (*mp)->size == malloc_minsize)) {
- return ptr;
- }
+ osize = (*mp)->size;
+ if (!malloc_realloc &&
+ size < osize &&
+ (size > (*mp)->size/2 || (*mp)->size == malloc_minsize)) {
+ return ptr;
+ }
} else {
#ifdef SANITY
- wrterror("realloc() of wrong page.\n");
+ wrterror("realloc() of wrong page.\n");
#endif
}
@@ -873,16 +913,19 @@ void *_PR_UnlockedRealloc(void *ptr, size_t size)
p = _PR_UnlockedMalloc(size);
if (p) {
- /* copy the lesser of the two sizes */
- if (osize < size)
- memcpy(p,ptr,osize);
- else
- memcpy(p,ptr,size);
- _PR_UnlockedFree(ptr);
+ /* copy the lesser of the two sizes */
+ if (osize < size) {
+ memcpy(p,ptr,osize);
+ }
+ else {
+ memcpy(p,ptr,size);
+ }
+ _PR_UnlockedFree(ptr);
}
#ifdef DEBUG
- else if (malloc_abort)
- wrterror("realloc() returns NULL\n");
+ else if (malloc_abort) {
+ wrterror("realloc() returns NULL\n");
+ }
#endif
return p;
@@ -904,100 +947,106 @@ free_pages(char *ptr, u_long page, int index, struct pginfo *info)
/* Is it free already ? */
if (info == MALLOC_FREE) {
#ifdef SANITY
- wrtwarning("freeing free page at %p.\n", ptr);
+ wrtwarning("freeing free page at %p.\n", ptr);
#endif
- return;
+ return;
}
#ifdef SANITY
/* Is it not the right place to begin ? */
- if (info != MALLOC_FIRST)
- wrterror("freeing wrong page.\n");
+ if (info != MALLOC_FIRST) {
+ wrterror("freeing wrong page.\n");
+ }
/* Is this really a pointer to a page ? */
- if ((u_long)ptr & malloc_pagemask)
- wrterror("freeing messed up page pointer.\n");
+ if ((u_long)ptr & malloc_pagemask) {
+ wrterror("freeing messed up page pointer.\n");
+ }
#endif
/* Count how many pages it is anyway */
page_dir[index] = MALLOC_FREE;
- for (i = 1; page_dir[index+i] == MALLOC_FOLLOW; i++)
- page_dir[index + i] = MALLOC_FREE;
+ for (i = 1; page_dir[index+i] == MALLOC_FOLLOW; i++) {
+ page_dir[index + i] = MALLOC_FREE;
+ }
l = i << malloc_pageshift;
tail = ptr+l;
/* add to free-list */
- if (!px)
- px = (struct pgfree*)_PR_UnlockedMalloc(sizeof *pt);
+ if (!px) {
+ px = (struct pgfree*)_PR_UnlockedMalloc(sizeof *pt);
+ }
/* XXX check success */
px->page = ptr;
px->end = tail;
px->size = l;
if (!free_list.next) {
- px->next = free_list.next;
- px->prev = &free_list;
- free_list.next = px;
- pf = px;
- px = 0;
+ px->next = free_list.next;
+ px->prev = &free_list;
+ free_list.next = px;
+ pf = px;
+ px = 0;
} else {
- tail = ptr+l;
- for(pf = free_list.next; pf->next && pf->end < ptr; pf = pf->next)
- ;
- for(; pf; pf = pf->next) {
- if (pf->end == ptr ) {
- /* append to entry */
- pf->end += l;
- pf->size += l;
- if (pf->next && pf->end == pf->next->page ) {
- pt = pf->next;
- pf->end = pt->end;
- pf->size += pt->size;
- pf->next = pt->next;
- if (pf->next)
- pf->next->prev = pf;
- _PR_UnlockedFree(pt);
- }
- } else if (pf->page == tail) {
- /* prepend to entry */
- pf->size += l;
- pf->page = ptr;
- } else if (pf->page > ptr) {
- px->next = pf;
- px->prev = pf->prev;
- pf->prev = px;
- px->prev->next = px;
- pf = px;
- px = 0;
- } else if (!pf->next) {
- px->next = 0;
- px->prev = pf;
- pf->next = px;
- pf = px;
- px = 0;
- } else {
- continue;
- }
- break;
- }
+ tail = ptr+l;
+ for(pf = free_list.next; pf->next && pf->end < ptr; pf = pf->next)
+ ;
+ for(; pf; pf = pf->next) {
+ if (pf->end == ptr ) {
+ /* append to entry */
+ pf->end += l;
+ pf->size += l;
+ if (pf->next && pf->end == pf->next->page ) {
+ pt = pf->next;
+ pf->end = pt->end;
+ pf->size += pt->size;
+ pf->next = pt->next;
+ if (pf->next) {
+ pf->next->prev = pf;
+ }
+ _PR_UnlockedFree(pt);
+ }
+ } else if (pf->page == tail) {
+ /* prepend to entry */
+ pf->size += l;
+ pf->page = ptr;
+ } else if (pf->page > ptr) {
+ px->next = pf;
+ px->prev = pf->prev;
+ pf->prev = px;
+ px->prev->next = px;
+ pf = px;
+ px = 0;
+ } else if (!pf->next) {
+ px->next = 0;
+ px->prev = pf;
+ pf->next = px;
+ pf = px;
+ px = 0;
+ } else {
+ continue;
+ }
+ break;
+ }
}
if (!pf->next &&
- pf->size > malloc_cache &&
- pf->end == malloc_brk &&
- malloc_brk == (void*)sbrk(0)) {
- pf->end = pf->page + malloc_cache;
- pf->size = malloc_cache;
- TRACE(("%6d U %p %d\n",malloc_event++,pf->end,pf->end - pf->page));
- brk(pf->end);
- malloc_brk = pf->end;
- /* Find the page directory entry for the page in question */
- page = (u_long)pf->end >> malloc_pageshift;
- index = page - malloc_origo;
- /* Now update the directory */
- for(i=index;i <= last_index;)
- page_dir[i++] = MALLOC_NOT_MINE;
- last_index = index - 1;
+ pf->size > malloc_cache &&
+ pf->end == malloc_brk &&
+ malloc_brk == (void*)sbrk(0)) {
+ pf->end = pf->page + malloc_cache;
+ pf->size = malloc_cache;
+ TRACE(("%6d U %p %d\n",malloc_event++,pf->end,pf->end - pf->page));
+ brk(pf->end);
+ malloc_brk = pf->end;
+ /* Find the page directory entry for the page in question */
+ page = (u_long)pf->end >> malloc_pageshift;
+ index = page - malloc_origo;
+ /* Now update the directory */
+ for(i=index; i <= last_index;) {
+ page_dir[i++] = MALLOC_NOT_MINE;
+ }
+ last_index = index - 1;
}
}
@@ -1014,8 +1063,9 @@ free_bytes(void *ptr, u_long page, int index, struct pginfo *info)
/* Make sure that pointer is multiplum of chunk-size */
#ifdef SANITY
- if ((u_long)ptr & (info->size - 1))
- wrterror("freeing messed up chunk pointer\n");
+ if ((u_long)ptr & (info->size - 1)) {
+ wrterror("freeing messed up chunk pointer\n");
+ }
#endif
/* Find the chunk number on the page */
@@ -1024,9 +1074,9 @@ free_bytes(void *ptr, u_long page, int index, struct pginfo *info)
/* See if it's free already */
if (tst_bit(info,i)) {
#ifdef SANITY
- wrtwarning("freeing free chunk at %p\n", ptr);
+ wrtwarning("freeing free chunk at %p\n", ptr);
#endif
- return;
+ return;
}
/* Mark it free */
@@ -1035,31 +1085,34 @@ free_bytes(void *ptr, u_long page, int index, struct pginfo *info)
/* If the page was full before, we need to put it on the queue now */
if (info->free == 1) {
- mp = page_dir + info->shift;
- while (*mp && (*mp)->next && (*mp)->next->page < info->page)
- mp = &(*mp)->next;
- info->next = *mp;
- *mp = info;
- return;
+ mp = page_dir + info->shift;
+ while (*mp && (*mp)->next && (*mp)->next->page < info->page) {
+ mp = &(*mp)->next;
+ }
+ info->next = *mp;
+ *mp = info;
+ return;
}
/* If this page isn't empty, don't do anything. */
- if (info->free != info->total)
- return;
+ if (info->free != info->total) {
+ return;
+ }
/* We may want to keep at least one page of each size chunks around. */
mp = page_dir + info->shift;
- if (0 && (*mp == info) && !info->next)
- return;
+ if (0 && (*mp == info) && !info->next) {
+ return;
+ }
/* Find & remove this page in the queue */
while (*mp != info) {
- mp = &((*mp)->next);
+ mp = &((*mp)->next);
#ifdef EXTRA_SANITY
- if (!*mp) {
- TRACE(("%6d !q %p\n",malloc_event++,info));
- wrterror("Not on queue\n");
- }
+ if (!*mp) {
+ TRACE(("%6d !q %p\n",malloc_event++,info));
+ wrterror("Not on queue\n");
+ }
#endif
}
*mp = info->next;
@@ -1067,11 +1120,11 @@ free_bytes(void *ptr, u_long page, int index, struct pginfo *info)
/* Free the page & the info structure if need be */
set_pgdir(info->page,MALLOC_FIRST);
if((void*)info->page == (void*)info) {
- _PR_UnlockedFree(info->page);
+ _PR_UnlockedFree(info->page);
} else {
- vp = info->page;
- _PR_UnlockedFree(info);
- _PR_UnlockedFree(vp);
+ vp = info->page;
+ _PR_UnlockedFree(info);
+ _PR_UnlockedFree(vp);
}
}
@@ -1083,20 +1136,22 @@ void _PR_UnlockedFree(void *ptr)
TRACE(("%6d F %p\n",malloc_event++,ptr));
/* This is legal */
- if (!ptr)
- return;
+ if (!ptr) {
+ return;
+ }
#ifdef SANITY
/* There wouldn't be anything to free */
if (!initialized) {
- wrtwarning("free() called before malloc() ever got called\n");
- return;
+ wrtwarning("free() called before malloc() ever got called\n");
+ return;
}
#endif
#ifdef SANITY
- if (suicide)
- PR_Abort();
+ if (suicide) {
+ PR_Abort();
+ }
#endif
/* Find the page directory entry for the page in question */
@@ -1107,36 +1162,39 @@ void _PR_UnlockedFree(void *ptr)
* check if memory was allocated by memalign
*/
tmp_index = index;
- while (page_dir[tmp_index] == MALLOC_FOLLOW)
- tmp_index--;
+ while (page_dir[tmp_index] == MALLOC_FOLLOW) {
+ tmp_index--;
+ }
if (tmp_index != index) {
- /*
- * memalign-allocated memory
- */
- index = tmp_index;
- page = index + malloc_origo;
- ptr = (void *) (page << malloc_pageshift);
+ /*
+ * memalign-allocated memory
+ */
+ index = tmp_index;
+ page = index + malloc_origo;
+ ptr = (void *) (page << malloc_pageshift);
}
/* make sure it makes sense in some fashion */
if (index < malloc_pageshift) {
#ifdef SANITY
- wrtwarning("junk pointer %p (low) passed to free()\n", ptr);
+ wrtwarning("junk pointer %p (low) passed to free()\n", ptr);
#endif
- return;
+ return;
}
if (index > last_index) {
#ifdef SANITY
- wrtwarning("junk pointer %p (high) passed to free()\n", ptr);
+ wrtwarning("junk pointer %p (high) passed to free()\n", ptr);
#endif
- return;
+ return;
}
/* handle as page-allocation or chunk allocation */
info = page_dir[index];
- if (info < MALLOC_MAGIC)
+ if (info < MALLOC_MAGIC) {
free_pages((char*)ptr, page, index, info);
- else
- free_bytes(ptr,page,index,info);
+ }
+ else {
+ free_bytes(ptr,page,index,info);
+ }
return;
}
#endif /* _PR_OVERRIDE_MALLOC */
diff --git a/nsprpub/pr/src/malloc/prmem.c b/nsprpub/pr/src/malloc/prmem.c
index e4ae42a91..08a700f7a 100644
--- a/nsprpub/pr/src/malloc/prmem.c
+++ b/nsprpub/pr/src/malloc/prmem.c
@@ -17,7 +17,7 @@
** in cyclic dependency of initialization.
*/
-#include <string.h>
+#include <string.h>
union memBlkHdrUn;
@@ -55,12 +55,13 @@ static void pr_ZoneFree(void *ptr);
void
_PR_DestroyZones(void)
-{
+{
int i, j;
- if (!use_zone_allocator)
+ if (!use_zone_allocator) {
return;
-
+ }
+
for (j = 0; j < THREAD_POOLS; j++) {
for (i = 0; i < MEM_ZONES; i++) {
MemoryZone *mz = &zones[i][j];
@@ -72,9 +73,9 @@ _PR_DestroyZones(void)
mz->elements--;
}
}
- }
+ }
use_zone_allocator = PR_FALSE;
-}
+}
/*
** pr_FindSymbolInProg
@@ -96,8 +97,9 @@ pr_FindSymbolInProg(const char *name)
void *sym;
h = dlopen(0, RTLD_LAZY);
- if (h == NULL)
+ if (h == NULL) {
return NULL;
+ }
sym = dlsym(h, name);
(void)dlclose(h);
return sym;
@@ -113,8 +115,9 @@ pr_FindSymbolInProg(const char *name)
shl_t h = NULL;
void *sym;
- if (shl_findsym(&h, name, TYPE_DATA, &sym) == -1)
+ if (shl_findsym(&h, name, TYPE_DATA, &sym) == -1) {
return NULL;
+ }
return sym;
}
@@ -157,17 +160,18 @@ _PR_InitZones(void)
use_zone_allocator = (atoi(envp) == 1);
}
- if (!use_zone_allocator)
+ if (!use_zone_allocator) {
return;
+ }
- for (j = 0; j < THREAD_POOLS; j++) {
+ for (j = 0; j < THREAD_POOLS; j++) {
for (i = 0; i < MEM_ZONES; i++) {
MemoryZone *mz = &zones[i][j];
int rv = pthread_mutex_init(&mz->lock, NULL);
PR_ASSERT(0 == rv);
if (rv != 0) {
goto loser;
- }
+ }
mz->blockSize = 16 << ( 2 * i);
}
}
@@ -189,11 +193,11 @@ PR_FPrintZoneStats(PRFileDesc *debug_out)
MemoryZone zone = *mz;
if (zone.elements || zone.misses || zone.hits) {
PR_fprintf(debug_out,
-"pool: %d, zone: %d, size: %d, free: %d, hit: %d, miss: %d, contend: %d\n",
- j, i, zone.blockSize, zone.elements,
- zone.hits, zone.misses, zone.contention);
+ "pool: %d, zone: %d, size: %d, free: %d, hit: %d, miss: %d, contend: %d\n",
+ j, i, zone.blockSize, zone.elements,
+ zone.hits, zone.misses, zone.contention);
}
- }
+ }
}
}
@@ -223,8 +227,9 @@ pr_ZoneMalloc(PRUint32 size)
wasLocked = mz->locked;
pthread_mutex_lock(&mz->lock);
mz->locked = 1;
- if (wasLocked)
+ if (wasLocked) {
mz->contention++;
+ }
if (mz->head) {
mb = mz->head;
PR_ASSERT(mb->s.magic == ZONE_MAGIC);
@@ -312,15 +317,16 @@ pr_ZoneRealloc(void *oldptr, PRUint32 bytes)
int ours;
MemBlockHdr phony;
- if (!oldptr)
+ if (!oldptr) {
return pr_ZoneMalloc(bytes);
+ }
mb = (MemBlockHdr *)((char *)oldptr - (sizeof *mb));
if (mb->s.magic != ZONE_MAGIC) {
/* Maybe this just came from ordinary malloc */
#ifdef DEBUG
fprintf(stderr,
- "Warning: reallocing memory block %p from ordinary malloc\n",
- oldptr);
+ "Warning: reallocing memory block %p from ordinary malloc\n",
+ oldptr);
#endif
/*
* We are going to realloc oldptr. If realloc succeeds, the
@@ -358,7 +364,7 @@ pr_ZoneRealloc(void *oldptr, PRUint32 bytes)
PR_ASSERT(mt->s.magic == ZONE_MAGIC);
PR_ASSERT(mt->s.zone == mb->s.zone);
PR_ASSERT(mt->s.blockSize == blockSize);
-
+
if (bytes <= blockSize) {
/* The block is already big enough. */
mt->s.requestedSize = mb->s.requestedSize = bytes;
@@ -370,13 +376,16 @@ pr_ZoneRealloc(void *oldptr, PRUint32 bytes)
return rv;
}
}
-
- if (oldptr && mb->s.requestedSize)
+
+ if (oldptr && mb->s.requestedSize) {
memcpy(rv, oldptr, mb->s.requestedSize);
- if (ours)
+ }
+ if (ours) {
pr_ZoneFree(oldptr);
- else if (oldptr)
+ }
+ else if (oldptr) {
free(oldptr);
+ }
return rv;
}
@@ -388,8 +397,9 @@ pr_ZoneFree(void *ptr)
size_t blockSize;
PRUint32 wasLocked;
- if (!ptr)
+ if (!ptr) {
return;
+ }
mb = (MemBlockHdr *)((char *)ptr - (sizeof *mb));
@@ -397,7 +407,7 @@ pr_ZoneFree(void *ptr)
/* maybe this came from ordinary malloc */
#ifdef DEBUG
fprintf(stderr,
- "Warning: freeing memory block %p from ordinary malloc\n", ptr);
+ "Warning: freeing memory block %p from ordinary malloc\n", ptr);
#endif
free(ptr);
return;
@@ -419,8 +429,9 @@ pr_ZoneFree(void *ptr)
wasLocked = mz->locked;
pthread_mutex_lock(&mz->lock);
mz->locked = 1;
- if (wasLocked)
+ if (wasLocked) {
mz->contention++;
+ }
mt->s.next = mb->s.next = mz->head; /* put on head of list */
mz->head = mb;
mz->elements++;
@@ -430,32 +441,40 @@ pr_ZoneFree(void *ptr)
PR_IMPLEMENT(void *) PR_Malloc(PRUint32 size)
{
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
return use_zone_allocator ? pr_ZoneMalloc(size) : malloc(size);
}
PR_IMPLEMENT(void *) PR_Calloc(PRUint32 nelem, PRUint32 elsize)
{
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
return use_zone_allocator ?
- pr_ZoneCalloc(nelem, elsize) : calloc(nelem, elsize);
+ pr_ZoneCalloc(nelem, elsize) : calloc(nelem, elsize);
}
PR_IMPLEMENT(void *) PR_Realloc(void *ptr, PRUint32 size)
{
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
return use_zone_allocator ? pr_ZoneRealloc(ptr, size) : realloc(ptr, size);
}
PR_IMPLEMENT(void) PR_Free(void *ptr)
{
- if (use_zone_allocator)
+ if (use_zone_allocator) {
pr_ZoneFree(ptr);
- else
+ }
+ else {
free(ptr);
+ }
}
#else /* !defined(_PR_ZONE_ALLOCATOR) */
@@ -481,7 +500,7 @@ PR_IMPLEMENT(void *) PR_Calloc(PRUint32 nelem, PRUint32 elsize)
{
#if defined (WIN16)
return PR_MD_calloc( (size_t)nelem, (size_t)elsize );
-
+
#else
return calloc(nelem, elsize);
#endif
@@ -519,7 +538,7 @@ PR_IMPLEMENT(void) PR_Free(void *ptr)
** PR_AttachThread has been called (on a native thread that nspr has yet
** to be told about) we could get royally screwed if the lock was busy
** and we tried to context switch the thread away. In this scenario
-** PR_CURRENT_THREAD() == NULL
+** PR_CURRENT_THREAD() == NULL
**
** To avoid this unfortunate case, we use the low level locking
** facilities for malloc protection instead of the slightly higher level
@@ -540,80 +559,61 @@ static PRBool _PR_malloc_initialised = PR_FALSE;
#ifdef _PR_PTHREADS
static pthread_mutex_t _PR_MD_malloc_crustylock;
-#define _PR_Lock_Malloc() { \
- if(PR_TRUE == _PR_malloc_initialised) { \
- PRStatus rv; \
- rv = pthread_mutex_lock(&_PR_MD_malloc_crustylock); \
- PR_ASSERT(0 == rv); \
- }
-
-#define _PR_Unlock_Malloc() if(PR_TRUE == _PR_malloc_initialised) { \
- PRStatus rv; \
- rv = pthread_mutex_unlock(&_PR_MD_malloc_crustylock); \
- PR_ASSERT(0 == rv); \
- } \
- }
+#define _PR_Lock_Malloc() { \
+ if(PR_TRUE == _PR_malloc_initialised) { \
+ PRStatus rv; \
+ rv = pthread_mutex_lock(&_PR_MD_malloc_crustylock); \
+ PR_ASSERT(0 == rv); \
+ }
+
+#define _PR_Unlock_Malloc() if(PR_TRUE == _PR_malloc_initialised) { \
+ PRStatus rv; \
+ rv = pthread_mutex_unlock(&_PR_MD_malloc_crustylock); \
+ PR_ASSERT(0 == rv); \
+ } \
+ }
#else /* _PR_PTHREADS */
static _MDLock _PR_MD_malloc_crustylock;
-#ifdef IRIX
-#define _PR_Lock_Malloc() { \
- PRIntn _is; \
- if(PR_TRUE == _PR_malloc_initialised) { \
- if (_PR_MD_GET_ATTACHED_THREAD() && \
- !_PR_IS_NATIVE_THREAD( \
- _PR_MD_GET_ATTACHED_THREAD())) \
- _PR_INTSOFF(_is); \
- _PR_MD_LOCK(&_PR_MD_malloc_crustylock); \
- }
-
-#define _PR_Unlock_Malloc() if(PR_TRUE == _PR_malloc_initialised) { \
- _PR_MD_UNLOCK(&_PR_MD_malloc_crustylock); \
- if (_PR_MD_GET_ATTACHED_THREAD() && \
- !_PR_IS_NATIVE_THREAD( \
- _PR_MD_GET_ATTACHED_THREAD())) \
- _PR_INTSON(_is); \
- } \
- }
-#else /* IRIX */
-#define _PR_Lock_Malloc() { \
- PRIntn _is; \
- if(PR_TRUE == _PR_malloc_initialised) { \
- if (_PR_MD_CURRENT_THREAD() && \
- !_PR_IS_NATIVE_THREAD( \
- _PR_MD_CURRENT_THREAD())) \
- _PR_INTSOFF(_is); \
- _PR_MD_LOCK(&_PR_MD_malloc_crustylock); \
- }
-
-#define _PR_Unlock_Malloc() if(PR_TRUE == _PR_malloc_initialised) { \
- _PR_MD_UNLOCK(&_PR_MD_malloc_crustylock); \
- if (_PR_MD_CURRENT_THREAD() && \
- !_PR_IS_NATIVE_THREAD( \
- _PR_MD_CURRENT_THREAD())) \
- _PR_INTSON(_is); \
- } \
- }
-#endif /* IRIX */
+#define _PR_Lock_Malloc() { \
+ PRIntn _is; \
+ if(PR_TRUE == _PR_malloc_initialised) { \
+ if (_PR_MD_CURRENT_THREAD() && \
+ !_PR_IS_NATIVE_THREAD( \
+ _PR_MD_CURRENT_THREAD())) \
+ _PR_INTSOFF(_is); \
+ _PR_MD_LOCK(&_PR_MD_malloc_crustylock); \
+ }
+
+#define _PR_Unlock_Malloc() if(PR_TRUE == _PR_malloc_initialised) { \
+ _PR_MD_UNLOCK(&_PR_MD_malloc_crustylock); \
+ if (_PR_MD_CURRENT_THREAD() && \
+ !_PR_IS_NATIVE_THREAD( \
+ _PR_MD_CURRENT_THREAD())) \
+ _PR_INTSON(_is); \
+ } \
+ }
#endif /* _PR_PTHREADS */
PR_IMPLEMENT(PRStatus) _PR_MallocInit(void)
{
PRStatus rv = PR_SUCCESS;
- if( PR_TRUE == _PR_malloc_initialised ) return PR_SUCCESS;
+ if( PR_TRUE == _PR_malloc_initialised ) {
+ return PR_SUCCESS;
+ }
#ifdef _PR_PTHREADS
{
- int status;
- pthread_mutexattr_t mattr;
-
- status = _PT_PTHREAD_MUTEXATTR_INIT(&mattr);
- PR_ASSERT(0 == status);
- status = _PT_PTHREAD_MUTEX_INIT(_PR_MD_malloc_crustylock, mattr);
- PR_ASSERT(0 == status);
- status = _PT_PTHREAD_MUTEXATTR_DESTROY(&mattr);
- PR_ASSERT(0 == status);
+ int status;
+ pthread_mutexattr_t mattr;
+
+ status = _PT_PTHREAD_MUTEXATTR_INIT(&mattr);
+ PR_ASSERT(0 == status);
+ status = _PT_PTHREAD_MUTEX_INIT(_PR_MD_malloc_crustylock, mattr);
+ PR_ASSERT(0 == status);
+ status = _PT_PTHREAD_MUTEXATTR_DESTROY(&mattr);
+ PR_ASSERT(0 == status);
}
#else /* _PR_PTHREADS */
_MD_NEW_LOCK(&_PR_MD_malloc_crustylock);
@@ -636,22 +636,6 @@ void *malloc(size_t size)
return p;
}
-#if defined(IRIX)
-void *memalign(size_t alignment, size_t size)
-{
- void *p;
- _PR_Lock_Malloc();
- p = _PR_UnlockedMemalign(alignment, size);
- _PR_Unlock_Malloc();
- return p;
-}
-
-void *valloc(size_t size)
-{
- return(memalign(sysconf(_SC_PAGESIZE),size));
-}
-#endif /* IRIX */
-
void free(void *ptr)
{
_PR_Lock_Malloc();
diff --git a/nsprpub/pr/src/md/beos/.cvsignore b/nsprpub/pr/src/md/beos/.cvsignore
deleted file mode 100644
index f3c7a7c5d..000000000
--- a/nsprpub/pr/src/md/beos/.cvsignore
+++ /dev/null
@@ -1 +0,0 @@
-Makefile
diff --git a/nsprpub/pr/src/md/beos/Makefile.in b/nsprpub/pr/src/md/beos/Makefile.in
deleted file mode 100644
index 340f144a8..000000000
--- a/nsprpub/pr/src/md/beos/Makefile.in
+++ /dev/null
@@ -1,28 +0,0 @@
-#
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-
-MOD_DEPTH = ../../../..
-topsrcdir = @top_srcdir@
-srcdir = @srcdir@
-VPATH = @srcdir@
-
-include $(MOD_DEPTH)/config/autoconf.mk
-
-include $(topsrcdir)/config/config.mk
-
-include $(srcdir)/bsrcs.mk
-CSRCS += $(MDCSRCS)
-
-TARGETS = $(OBJS)
-
-INCLUDES = -I$(dist_includedir) -I$(topsrcdir)/pr/include -I$(topsrcdir)/pr/include/private
-
-DEFINES += -D_NSPR_BUILD_
-
-include $(topsrcdir)/config/rules.mk
-
-export:: $(TARGETS)
-
diff --git a/nsprpub/pr/src/md/beos/bcpu.c b/nsprpub/pr/src/md/beos/bcpu.c
deleted file mode 100644
index 6c2538654..000000000
--- a/nsprpub/pr/src/md/beos/bcpu.c
+++ /dev/null
@@ -1,23 +0,0 @@
-/* -*- Mode: C++; c-basic-offset: 4 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "primpl.h"
-
-PR_EXTERN(void) _PR_MD_INIT_CPUS();
-PR_EXTERN(void) _PR_MD_WAKEUP_CPUS();
-PR_EXTERN(void) _PR_MD_START_INTERRUPTS(void);
-PR_EXTERN(void) _PR_MD_STOP_INTERRUPTS(void);
-PR_EXTERN(void) _PR_MD_DISABLE_CLOCK_INTERRUPTS(void);
-PR_EXTERN(void) _PR_MD_BLOCK_CLOCK_INTERRUPTS(void);
-PR_EXTERN(void) _PR_MD_UNBLOCK_CLOCK_INTERRUPTS(void);
-PR_EXTERN(void) _PR_MD_CLOCK_INTERRUPT(void);
-PR_EXTERN(void) _PR_MD_INIT_STACK(PRThreadStack *ts, PRIntn redzone);
-PR_EXTERN(void) _PR_MD_CLEAR_STACK(PRThreadStack* ts);
-PR_EXTERN(PRInt32) _PR_MD_GET_INTSOFF(void);
-PR_EXTERN(void) _PR_MD_SET_INTSOFF(PRInt32 _val);
-PR_EXTERN(_PRCPU*) _PR_MD_CURRENT_CPU(void);
-PR_EXTERN(void) _PR_MD_SET_CURRENT_CPU(_PRCPU *cpu);
-PR_EXTERN(void) _PR_MD_INIT_RUNNING_CPU(_PRCPU *cpu);
-PR_EXTERN(PRInt32) _PR_MD_PAUSE_CPU(PRIntervalTime timeout);
diff --git a/nsprpub/pr/src/md/beos/beos.c b/nsprpub/pr/src/md/beos/beos.c
deleted file mode 100644
index a1df7d2f1..000000000
--- a/nsprpub/pr/src/md/beos/beos.c
+++ /dev/null
@@ -1,232 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "primpl.h"
-
-#include <signal.h>
-#include <unistd.h>
-#include <memory.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <sys/ioctl.h>
-#include <errno.h>
-
-/*
- * Make sure _PRSockLen_t is 32-bit, because we will cast a PRUint32* or
- * PRInt32* pointer to a _PRSockLen_t* pointer.
- */
-#define _PRSockLen_t int
-
-/*
-** Global lock variable used to bracket calls into rusty libraries that
-** aren't thread safe (like libc, libX, etc).
-*/
-static PRLock *_pr_rename_lock = NULL;
-static PRMonitor *_pr_Xfe_mon = NULL;
-
-/*
- * Variables used by the GC code, initialized in _MD_InitSegs().
- * _pr_zero_fd should be a static variable. Unfortunately, there is
- * still some Unix-specific code left in function PR_GrowSegment()
- * in file memory/prseg.c that references it, so it needs
- * to be a global variable for now.
- */
-PRInt32 _pr_zero_fd = -1;
-static PRLock *_pr_md_lock = NULL;
-
-sigset_t timer_set;
-
-void _PR_UnixInit()
-{
- struct sigaction sigact;
- int rv;
-
- sigemptyset(&timer_set);
-
- sigact.sa_handler = SIG_IGN;
- sigemptyset(&sigact.sa_mask);
- sigact.sa_flags = 0;
- rv = sigaction(SIGPIPE, &sigact, 0);
- PR_ASSERT(0 == rv);
-
- _pr_rename_lock = PR_NewLock();
- PR_ASSERT(NULL != _pr_rename_lock);
- _pr_Xfe_mon = PR_NewMonitor();
- PR_ASSERT(NULL != _pr_Xfe_mon);
-}
-
-/*
- *-----------------------------------------------------------------------
- *
- * PR_Now --
- *
- * Returns the current time in microseconds since the epoch.
- * The epoch is midnight January 1, 1970 GMT.
- * The implementation is machine dependent. This is the Unix
- * implementation.
- * Cf. time_t time(time_t *tp)
- *
- *-----------------------------------------------------------------------
- */
-
-PR_IMPLEMENT(PRTime)
-PR_Now(void)
-{
- struct timeval tv;
- PRInt64 s, us, s2us;
-
- GETTIMEOFDAY(&tv);
- LL_I2L(s2us, PR_USEC_PER_SEC);
- LL_I2L(s, tv.tv_sec);
- LL_I2L(us, tv.tv_usec);
- LL_MUL(s, s, s2us);
- LL_ADD(s, s, us);
- return s;
-}
-
-PRIntervalTime
-_PR_UNIX_GetInterval()
-{
- struct timeval time;
- PRIntervalTime ticks;
-
- (void)GETTIMEOFDAY(&time); /* fallicy of course */
- ticks = (PRUint32)time.tv_sec * PR_MSEC_PER_SEC; /* that's in milliseconds */
- ticks += (PRUint32)time.tv_usec / PR_USEC_PER_MSEC; /* so's that */
- return ticks;
-} /* _PR_SUNOS_GetInterval */
-
-PRIntervalTime _PR_UNIX_TicksPerSecond()
-{
- return 1000; /* this needs some work :) */
-}
-
-/************************************************************************/
-
-/*
-** Special hacks for xlib. Xlib/Xt/Xm is not re-entrant nor is it thread
-** safe. Unfortunately, neither is mozilla. To make these programs work
-** in a pre-emptive threaded environment, we need to use a lock.
-*/
-
-void PR_XLock()
-{
- PR_EnterMonitor(_pr_Xfe_mon);
-}
-
-void PR_XUnlock()
-{
- PR_ExitMonitor(_pr_Xfe_mon);
-}
-
-PRBool PR_XIsLocked()
-{
- return (PR_InMonitor(_pr_Xfe_mon)) ? PR_TRUE : PR_FALSE;
-}
-
-void PR_XWait(int ms)
-{
- PR_Wait(_pr_Xfe_mon, PR_MillisecondsToInterval(ms));
-}
-
-void PR_XNotify(void)
-{
- PR_Notify(_pr_Xfe_mon);
-}
-
-void PR_XNotifyAll(void)
-{
- PR_NotifyAll(_pr_Xfe_mon);
-}
-
-#if !defined(BEOS)
-#ifdef HAVE_BSD_FLOCK
-
-#include <sys/file.h>
-
-PR_IMPLEMENT(PRStatus)
-_MD_LOCKFILE (PRInt32 f)
-{
- PRInt32 rv;
- rv = flock(f, LOCK_EX);
- if (rv == 0)
- return PR_SUCCESS;
- _PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
- return PR_FAILURE;
-}
-
-PR_IMPLEMENT(PRStatus)
-_MD_TLOCKFILE (PRInt32 f)
-{
- PRInt32 rv;
- rv = flock(f, LOCK_EX|LOCK_NB);
- if (rv == 0)
- return PR_SUCCESS;
- _PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
- return PR_FAILURE;
-}
-
-PR_IMPLEMENT(PRStatus)
-_MD_UNLOCKFILE (PRInt32 f)
-{
- PRInt32 rv;
- rv = flock(f, LOCK_UN);
- if (rv == 0)
- return PR_SUCCESS;
- _PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
- return PR_FAILURE;
-}
-#else
-
-PR_IMPLEMENT(PRStatus)
-_MD_LOCKFILE (PRInt32 f)
-{
- PRInt32 rv;
- rv = lockf(f, F_LOCK, 0);
- if (rv == 0)
- return PR_SUCCESS;
- _PR_MD_MAP_LOCKF_ERROR(_MD_ERRNO());
- return PR_FAILURE;
-}
-
-PR_IMPLEMENT(PRStatus)
-_MD_TLOCKFILE (PRInt32 f)
-{
- PRInt32 rv;
- rv = lockf(f, F_TLOCK, 0);
- if (rv == 0)
- return PR_SUCCESS;
- _PR_MD_MAP_LOCKF_ERROR(_MD_ERRNO());
- return PR_FAILURE;
-}
-
-PR_IMPLEMENT(PRStatus)
-_MD_UNLOCKFILE (PRInt32 f)
-{
- PRInt32 rv;
- rv = lockf(f, F_ULOCK, 0);
- if (rv == 0)
- return PR_SUCCESS;
- _PR_MD_MAP_LOCKF_ERROR(_MD_ERRNO());
- return PR_FAILURE;
-}
-#endif
-
-PR_IMPLEMENT(PRStatus)
- _MD_GETHOSTNAME (char *name, PRUint32 namelen)
-{
- PRIntn rv;
-
- rv = gethostname(name, namelen);
- if (0 == rv) {
- return PR_SUCCESS;
- }
- _PR_MD_MAP_GETHOSTNAME_ERROR(_MD_ERRNO());
- return PR_FAILURE;
-}
-
-#endif
diff --git a/nsprpub/pr/src/md/beos/beos_errors.c b/nsprpub/pr/src/md/beos/beos_errors.c
deleted file mode 100644
index 687a53519..000000000
--- a/nsprpub/pr/src/md/beos/beos_errors.c
+++ /dev/null
@@ -1,1494 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "prtypes.h"
-#include "md/_unix_errors.h"
-#include "prerror.h"
-#include <errno.h>
-
-void _MD_unix_map_opendir_error(int err)
-{
- switch (err) {
- case ENOTDIR:
- PR_SetError(PR_NOT_DIRECTORY_ERROR, err);
- break;
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case EMFILE:
- PR_SetError(PR_PROC_DESC_TABLE_FULL_ERROR, err);
- break;
- case ENFILE:
- PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ELOOP:
- PR_SetError(PR_LOOP_ERROR, err);
- break;
- case ENAMETOOLONG:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case ENOENT:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_closedir_error(int err)
-{
- switch (err) {
- case EINVAL:
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_readdir_error(int err)
-{
-
- switch (err) {
- case 0:
- case ENOENT:
- PR_SetError(PR_NO_MORE_FILES_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#ifdef IRIX
-#ifdef IRIX5_3
-#else
- case EDIRCORRUPTED:
- PR_SetError(PR_DIRECTORY_CORRUPTED_ERROR, err);
- break;
-#endif
-#endif
-#ifdef EOVERFLOW
- case EOVERFLOW:
- PR_SetError(PR_IO_ERROR, err);
- break;
-#endif
- case EINVAL:
- PR_SetError(PR_IO_ERROR, err);
- break;
-#ifdef EBADMSG
- case EBADMSG:
- PR_SetError(PR_IO_ERROR, err);
- break;
-#endif
- case EDEADLK:
- PR_SetError(PR_DEADLOCK_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case EIO:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ENOLCK:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
-#ifdef ENOLINK
- case ENOLINK:
- PR_SetError(PR_REMOTE_FILE_ERROR, err);
- break;
-#endif
- case ENXIO:
- PR_SetError(PR_IO_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_unlink_error(int err)
-{
- switch (err) {
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case EBUSY:
- PR_SetError(PR_FILESYSTEM_MOUNTED_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case ELOOP:
- PR_SetError(PR_LOOP_ERROR, err);
- break;
- case ENAMETOOLONG:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case ENOENT:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ENOTDIR:
- PR_SetError(PR_NOT_DIRECTORY_ERROR, err);
- break;
- case EPERM:
- PR_SetError(PR_IS_DIRECTORY_ERROR, err);
- break;
- case EROFS:
- PR_SetError(PR_READ_ONLY_FILESYSTEM_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_stat_error(int err)
-{
- switch (err) {
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case ETIMEDOUT:
- PR_SetError(PR_REMOTE_FILE_ERROR, err);
- break;
- case ELOOP:
- PR_SetError(PR_LOOP_ERROR, err);
- break;
- case ENAMETOOLONG:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case ENOENT:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ENOTDIR:
- PR_SetError(PR_NOT_DIRECTORY_ERROR, err);
- break;
-#ifdef EOVERFLOW
- case EOVERFLOW:
- PR_SetError(PR_BUFFER_OVERFLOW_ERROR, err);
- break;
-#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_fstat_error(int err)
-{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case ETIMEDOUT:
-#ifdef ENOLINK
- case ENOLINK:
-#endif
- PR_SetError(PR_REMOTE_FILE_ERROR, err);
- break;
-#ifdef EOVERFLOW
- case EOVERFLOW:
- PR_SetError(PR_BUFFER_OVERFLOW_ERROR, err);
- break;
-#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_rename_error(int err)
-{
- switch (err) {
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case EBUSY:
- PR_SetError(PR_FILESYSTEM_MOUNTED_ERROR, err);
- break;
-#ifdef EDQUOT
- case EDQUOT:
- PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
- break;
-#endif
- case EEXIST:
- PR_SetError(PR_DIRECTORY_NOT_EMPTY_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case EIO:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case EISDIR:
- PR_SetError(PR_IS_DIRECTORY_ERROR, err);
- break;
- case ELOOP:
- PR_SetError(PR_LOOP_ERROR, err);
- break;
- case ENAMETOOLONG:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case ENOENT:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ENOSPC:
- PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
- break;
- case ENOTDIR:
- PR_SetError(PR_NOT_DIRECTORY_ERROR, err);
- break;
- case EROFS:
- PR_SetError(PR_READ_ONLY_FILESYSTEM_ERROR, err);
- break;
- case EXDEV:
- PR_SetError(PR_NOT_SAME_DEVICE_ERROR, err);
- break;
- case EMLINK:
- PR_SetError(PR_MAX_DIRECTORY_ENTRIES_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_access_error(int err)
-{
- switch (err) {
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case ELOOP:
- PR_SetError(PR_LOOP_ERROR, err);
- break;
- case ETIMEDOUT:
- PR_SetError(PR_REMOTE_FILE_ERROR, err);
- break;
- case ENAMETOOLONG:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case ENOENT:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ENOTDIR:
- PR_SetError(PR_NOT_DIRECTORY_ERROR, err);
- break;
- case EROFS:
- PR_SetError(PR_READ_ONLY_FILESYSTEM_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_mkdir_error(int err)
-{
- switch (err) {
- case ENOTDIR:
- PR_SetError(PR_NOT_DIRECTORY_ERROR, err);
- break;
- case ENOENT:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ENAMETOOLONG:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case EEXIST:
- PR_SetError(PR_FILE_EXISTS_ERROR, err);
- break;
- case EROFS:
- PR_SetError(PR_READ_ONLY_FILESYSTEM_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ELOOP:
- PR_SetError(PR_LOOP_ERROR, err);
- break;
- case EMLINK:
- PR_SetError(PR_MAX_DIRECTORY_ENTRIES_ERROR, err);
- break;
- case ENOSPC:
- PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
- break;
-#ifdef EDQUOT
- case EDQUOT:
- PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
- break;
-#endif
- case EIO:
- PR_SetError(PR_IO_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_rmdir_error(int err)
-{
-
- switch (err) {
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case EBUSY:
- PR_SetError(PR_FILESYSTEM_MOUNTED_ERROR, err);
- break;
- case EEXIST:
- PR_SetError(PR_DIRECTORY_NOT_EMPTY_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_DIRECTORY_NOT_EMPTY_ERROR, err);
- break;
- case EIO:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ELOOP:
- PR_SetError(PR_LOOP_ERROR, err);
- break;
- case ETIMEDOUT:
- PR_SetError(PR_REMOTE_FILE_ERROR, err);
- break;
- case ENAMETOOLONG:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case ENOENT:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ENOTDIR:
- PR_SetError(PR_NOT_DIRECTORY_ERROR, err);
- break;
- case EROFS:
- PR_SetError(PR_READ_ONLY_FILESYSTEM_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_read_error(int err)
-{
- switch (err) {
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case EAGAIN:
-#if EWOULDBLOCK != EAGAIN
- case EWOULDBLOCK:
-#endif
- PR_SetError(PR_WOULD_BLOCK_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#ifdef EBADMSG
- case EBADMSG:
- PR_SetError(PR_IO_ERROR, err);
- break;
-#endif
- case EDEADLK:
- PR_SetError(PR_DEADLOCK_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_INVALID_METHOD_ERROR, err);
- break;
- case EIO:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ENOLCK:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- case ENXIO:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case EISDIR:
- PR_SetError(PR_IS_DIRECTORY_ERROR, err);
- break;
- case ECONNRESET:
- case EPIPE:
- PR_SetError(PR_CONNECT_RESET_ERROR, err);
- break;
-#ifdef ENOLINK
- case ENOLINK:
- PR_SetError(PR_REMOTE_FILE_ERROR, err);
- break;
-#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_write_error(int err)
-{
- switch (err) {
- case EAGAIN:
-#if EWOULDBLOCK != EAGAIN
- case EWOULDBLOCK:
-#endif
- PR_SetError(PR_WOULD_BLOCK_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case EDEADLK:
- PR_SetError(PR_DEADLOCK_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EFBIG:
- PR_SetError(PR_FILE_TOO_BIG_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_INVALID_METHOD_ERROR, err);
- break;
- case EIO:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ENOLCK:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
-#ifdef ENOSR
- case ENOSR:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
-#endif
- case ENOSPC:
- PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
- break;
- case ENXIO:
- PR_SetError(PR_INVALID_METHOD_ERROR, err);
- break;
- case ERANGE:
- PR_SetError(PR_INVALID_METHOD_ERROR, err);
- break;
- case ETIMEDOUT:
- PR_SetError(PR_REMOTE_FILE_ERROR, err);
- break;
- case ECONNRESET:
- case EPIPE:
- PR_SetError(PR_CONNECT_RESET_ERROR, err);
- break;
-#ifdef EDQUOT
- case EDQUOT:
- PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
- break;
-#endif
-#ifdef ENOLINK
- case ENOLINK:
- PR_SetError(PR_REMOTE_FILE_ERROR, err);
- break;
-#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_lseek_error(int err)
-{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ESPIPE:
- PR_SetError(PR_INVALID_METHOD_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_fsync_error(int err)
-{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#ifdef ENOLINK
- case ENOLINK:
-#endif
- case ETIMEDOUT:
- PR_SetError(PR_REMOTE_FILE_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case EIO:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_INVALID_METHOD_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_close_error(int err)
-{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
-#ifdef ENOLINK
- case ENOLINK:
-#endif
- case ETIMEDOUT:
- PR_SetError(PR_REMOTE_FILE_ERROR, err);
- break;
- case EIO:
- PR_SetError(PR_IO_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_socket_error(int err)
-{
- switch (err) {
- case EPROTONOSUPPORT:
- PR_SetError(PR_PROTOCOL_NOT_SUPPORTED_ERROR, err);
- break;
- case EMFILE:
- PR_SetError(PR_PROC_DESC_TABLE_FULL_ERROR, err);
- break;
- case ENFILE:
- PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
- break;
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
-#if !defined(SCO)
- case ENOBUFS:
-#endif /* !defined(SCO) */
- case ENOMEM:
-#ifdef ENOSR
- case ENOSR:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
-#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_socketavailable_error(int err)
-{
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
-}
-
-void _MD_unix_map_recv_error(int err)
-{
- switch (err) {
- case EAGAIN:
-#if EWOULDBLOCK != EAGAIN
- case EWOULDBLOCK:
-#endif
- PR_SetError(PR_WOULD_BLOCK_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#if !defined(BEOS)
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
-#endif
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ENOMEM:
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, err);
- break;
- case ECONNRESET:
- case EPIPE:
- PR_SetError(PR_CONNECT_RESET_ERROR, err);
- break;
-#ifdef ENOSR
- case ENOSR:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
-#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_recvfrom_error(int err)
-{
- switch (err) {
- case EAGAIN:
-#if EWOULDBLOCK != EAGAIN
- case EWOULDBLOCK:
-#endif
- PR_SetError(PR_WOULD_BLOCK_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#if !defined(BEOS)
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
-#endif
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ENOMEM:
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, err);
- break;
-#ifdef ENOSR
- case ENOSR:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
-#endif
- case ECONNRESET:
- PR_SetError(PR_CONNECT_RESET_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_send_error(int err)
-{
- switch (err) {
- case EAGAIN:
-#if EWOULDBLOCK != EAGAIN
- case EWOULDBLOCK:
-#endif
- PR_SetError(PR_WOULD_BLOCK_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#if !defined(BEOS)
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
-#endif
-#if !defined(BEOS)
- case EMSGSIZE:
-#endif
- case EINVAL:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
-#if !defined(SCO)
- case ENOBUFS:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
-#endif /* !defined(SCO) */
- case ECONNREFUSED:
- PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
- break;
- case EISCONN:
- PR_SetError(PR_IS_CONNECTED_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case ENOMEM:
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, err);
- break;
-#ifdef ENOSR
- case ENOSR:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
-#endif
- case ECONNRESET:
- case EPIPE:
- PR_SetError(PR_CONNECT_RESET_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_sendto_error(int err)
-{
- switch (err) {
- case EAGAIN:
-#if EWOULDBLOCK != EAGAIN
- case EWOULDBLOCK:
-#endif
- PR_SetError(PR_WOULD_BLOCK_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#if !defined(BEOS)
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
-#endif
-#if !defined(BEOS)
- case EMSGSIZE:
-#endif
- case EINVAL:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
-#if !defined(SCO)
- case ENOBUFS:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
-#endif /* !defined(SCO) */
- case ECONNREFUSED:
- PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
- break;
- case EISCONN:
- PR_SetError(PR_IS_CONNECTED_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case ENOMEM:
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, err);
- break;
-#ifdef ENOSR
- case ENOSR:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
-#endif
- case ECONNRESET:
- case EPIPE:
- PR_SetError(PR_CONNECT_RESET_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_writev_error(int err)
-{
- switch (err) {
- case EAGAIN:
-#if EWOULDBLOCK != EAGAIN
- case EWOULDBLOCK:
-#endif
- PR_SetError(PR_WOULD_BLOCK_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
-#ifdef ENOSR
- case ENOSR:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
-#endif
- case EINVAL:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case ECONNRESET:
- case EPIPE:
- PR_SetError(PR_CONNECT_RESET_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_accept_error(int err)
-{
- switch (err) {
- case EAGAIN:
-#if EWOULDBLOCK != EAGAIN
- case EWOULDBLOCK:
-#endif
- PR_SetError(PR_WOULD_BLOCK_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#if !defined(BEOS)
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
-#endif
-#if !defined(BEOS)
- case EOPNOTSUPP:
-#endif
- case ENODEV:
- PR_SetError(PR_NOT_TCP_SOCKET_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EMFILE:
- PR_SetError(PR_PROC_DESC_TABLE_FULL_ERROR, err);
- break;
- case ENFILE:
- PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case ENOMEM:
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, err);
- break;
-#ifdef ENOSR
- case ENOSR:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
-#endif
-#ifdef EPROTO
- case EPROTO:
- PR_SetError(PR_IO_ERROR, err);
- break;
-#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_connect_error(int err)
-{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case EADDRNOTAVAIL:
- PR_SetError(PR_ADDRESS_NOT_AVAILABLE_ERROR, err);
- break;
- case EINPROGRESS:
- PR_SetError(PR_IN_PROGRESS_ERROR, err);
- break;
- case EALREADY:
- PR_SetError(PR_ALREADY_INITIATED_ERROR, err);
- break;
-#if !defined(BEOS)
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
-#endif
- case EAFNOSUPPORT:
- PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
- break;
- case EISCONN:
- PR_SetError(PR_IS_CONNECTED_ERROR, err);
- break;
- case ETIMEDOUT:
- PR_SetError(PR_IO_TIMEOUT_ERROR, err);
- break;
- case ECONNREFUSED:
- PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
- break;
- case ENETUNREACH:
- PR_SetError(PR_NETWORK_UNREACHABLE_ERROR, err);
- break;
- case EADDRINUSE:
- PR_SetError(PR_ADDRESS_IN_USE_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- /*
- * UNIX domain sockets are not supported in NSPR
- */
- case EACCES:
- PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case EIO:
-#if defined(UNIXWARE)
- /*
- * On some platforms, if we connect to a port on
- * the local host (the loopback address) that no
- * process is listening on, we get EIO instead
- * of ECONNREFUSED.
- */
- PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
-#else
- PR_SetError(PR_IO_ERROR, err);
-#endif
- break;
- case ELOOP:
- PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
- break;
- case ENOENT:
- PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
- break;
-#ifdef ENOSR
- case ENOSR:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
-#endif
- case ENXIO:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case EPROTOTYPE:
- PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_bind_error(int err)
-{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#if !defined(BEOS)
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
-#endif
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EADDRNOTAVAIL:
- PR_SetError(PR_ADDRESS_NOT_AVAILABLE_ERROR, err);
- break;
- case EADDRINUSE:
- PR_SetError(PR_ADDRESS_IN_USE_ERROR, err);
- break;
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_SOCKET_ADDRESS_IS_BOUND_ERROR, err);
- break;
-#ifdef ENOSR
- case ENOSR:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
-#endif
- /*
- * UNIX domain sockets are not supported in NSPR
- */
- case EIO:
- case EISDIR:
- case ELOOP:
- case ENOENT:
- case ENOTDIR:
- case EROFS:
- PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_listen_error(int err)
-{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#if !defined(BEOS)
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
-#endif
-#if !defined(BEOS)
- case EOPNOTSUPP:
- PR_SetError(PR_NOT_TCP_SOCKET_ERROR, err);
- break;
-#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_shutdown_error(int err)
-{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#if !defined(BEOS)
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
-#endif
- case ENOTCONN:
- PR_SetError(PR_NOT_CONNECTED_ERROR, err);
- break;
- case ENOMEM:
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, err);
- break;
-#ifdef ENOSR
- case ENOSR:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
-#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_socketpair_error(int err)
-{
- switch (err) {
- case EMFILE:
- PR_SetError(PR_PROC_DESC_TABLE_FULL_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ENOMEM:
-#ifdef ENOSR
- case ENOSR:
-#endif
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case EAFNOSUPPORT:
- case EPROTONOSUPPORT:
-#if !defined(BEOS)
- case EOPNOTSUPP:
-#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_getsockname_error(int err)
-{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#if !defined(BEOS)
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
-#endif
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
-#if !defined(SCO)
- case ENOBUFS:
-#endif /* !defined(SCO) */
- case ENOMEM:
-#ifdef ENOSR
- case ENOSR:
-#endif
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_getpeername_error(int err)
-{
-
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#if !defined(BEOS)
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
-#endif
- case ENOTCONN:
- PR_SetError(PR_NOT_CONNECTED_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
-#if !defined(SCO)
- case ENOBUFS:
-#endif /* !defined(SCO) */
- case ENOMEM:
-#ifdef ENOSR
- case ENOSR:
-#endif
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_getsockopt_error(int err)
-{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#if !defined(BEOS)
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
-#endif
- case ENOPROTOOPT:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_BUFFER_OVERFLOW_ERROR, err);
- break;
- case ENOMEM:
-#ifdef ENOSR
- case ENOSR:
-#endif
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_setsockopt_error(int err)
-{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
-#if !defined(BEOS)
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
-#endif
- case ENOPROTOOPT:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_BUFFER_OVERFLOW_ERROR, err);
- break;
- case ENOMEM:
-#ifdef ENOSR
- case ENOSR:
-#endif
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_open_error(int err)
-{
- switch (err) {
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case EAGAIN:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case EBUSY:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case EEXIST:
- PR_SetError(PR_FILE_EXISTS_ERROR, err);
- break;
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case EIO:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case EISDIR:
- PR_SetError(PR_IS_DIRECTORY_ERROR, err);
- break;
- case ELOOP:
- PR_SetError(PR_LOOP_ERROR, err);
- break;
- case EMFILE:
- PR_SetError(PR_PROC_DESC_TABLE_FULL_ERROR, err);
- break;
- case ENAMETOOLONG:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case ENFILE:
- PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
- break;
- case ENODEV:
- case ENOENT:
- case ENXIO:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ENOMEM:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case ENOSPC:
- PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
- break;
-#ifdef ENOSR
- case ENOSR:
-#endif
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case ENOTDIR:
- PR_SetError(PR_NOT_DIRECTORY_ERROR, err);
- break;
- case EPERM:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ETIMEDOUT:
- PR_SetError(PR_REMOTE_FILE_ERROR, err);
- break;
- case EROFS:
- PR_SetError(PR_READ_ONLY_FILESYSTEM_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_mmap_error(int err)
-{
-
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case EAGAIN:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ENOMEM:
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_gethostname_error(int err)
-{
- switch (err) {
- case EFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_select_error(int err)
-{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case EINTR:
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_poll_error(int err)
-{
- PRErrorCode prerror;
- switch (err) {
- case EAGAIN:
- prerror = PR_INSUFFICIENT_RESOURCES_ERROR;
- break;
- case EINVAL:
- prerror = PR_INVALID_ARGUMENT_ERROR;
- break;
- case EFAULT:
- prerror = PR_ACCESS_FAULT_ERROR;
- break;
- default:
- prerror = PR_UNKNOWN_ERROR;
- break;
- }
- PR_SetError(prerror, err);
-}
-
-void _MD_unix_map_flock_error(int err)
-{
- switch (err) {
- case EBADF:
- case EINVAL:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case EWOULDBLOCK:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-void _MD_unix_map_lockf_error(int err)
-{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case EACCES:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- case EDEADLK:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
-}
-
-#ifdef HPUX11
-void _MD_hpux_map_sendfile_error(int oserror)
-{
- PRErrorCode prerror;
-
- switch (oserror) {
- case ENOTSOCK:
- prerror = PR_NOT_SOCKET_ERROR;
- break;
- case EFAULT:
- prerror = PR_ACCESS_FAULT_ERROR;
- break;
- case ENOBUFS:
- prerror = PR_INSUFFICIENT_RESOURCES_ERROR;
- break;
- case EINVAL:
- prerror = PR_INVALID_ARGUMENT_ERROR;
- break;
- case ENOTCONN:
- prerror = PR_NOT_CONNECTED_ERROR;
- break;
- case EPIPE:
- prerror = PR_CONNECT_RESET_ERROR;
- break;
- case ENOMEM:
- prerror = PR_OUT_OF_MEMORY_ERROR;
- break;
- case EOPNOTSUPP:
- prerror = PR_NOT_TCP_SOCKET_ERROR;
- break;
- default:
- prerror = PR_UNKNOWN_ERROR;
- }
- PR_SetError(prerror, oserror);
-}
-#endif /* HPUX11 */
diff --git a/nsprpub/pr/src/md/beos/bfile.c b/nsprpub/pr/src/md/beos/bfile.c
deleted file mode 100644
index 89fea29a2..000000000
--- a/nsprpub/pr/src/md/beos/bfile.c
+++ /dev/null
@@ -1,873 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; c-basic-offset: 8 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "primpl.h"
-
-/*
-** Global lock variable used to bracket calls into rusty libraries that
-** aren't thread safe (like libc, libX, etc).
-*/
-static PRLock *_pr_rename_lock = NULL;
-
-void
-_MD_InitIO (void)
-{
-}
-
-PRStatus
-_MD_open_dir (_MDDir *md,const char *name)
-{
-int err;
-
- md->d = opendir(name);
- if (!md->d) {
- err = _MD_ERRNO();
- _PR_MD_MAP_OPENDIR_ERROR(err);
- return PR_FAILURE;
- }
- return PR_SUCCESS;
-}
-
-char*
-_MD_read_dir (_MDDir *md, PRIntn flags)
-{
-struct dirent *de;
-int err;
-
- for (;;) {
- /*
- * XXX: readdir() is not MT-safe
- */
- _MD_ERRNO() = 0;
- de = readdir(md->d);
-
- if (!de) {
- err = _MD_ERRNO();
- _PR_MD_MAP_READDIR_ERROR(err);
- return 0;
- }
-
- if ((flags & PR_SKIP_DOT) &&
- (de->d_name[0] == '.') && (de->d_name[1] == 0))
- continue;
-
- if ((flags & PR_SKIP_DOT_DOT) &&
- (de->d_name[0] == '.') && (de->d_name[1] == '.') &&
- (de->d_name[2] == 0))
- continue;
-
- if ((flags & PR_SKIP_HIDDEN) && (de->d_name[1] == '.'))
- continue;
-
- break;
- }
- return de->d_name;
-}
-
-
-PRInt32
-_MD_close_dir (_MDDir *md)
-{
-int rv = 0, err;
-
- if (md->d) {
- rv = closedir(md->d);
- if (rv == -1) {
- err = _MD_ERRNO();
- _PR_MD_MAP_CLOSEDIR_ERROR(err);
- }
- }
- return(rv);
-}
-
-void
-_MD_make_nonblock (PRFileDesc *fd)
-{
- int blocking = 1;
- setsockopt(fd->secret->md.osfd, SOL_SOCKET, SO_NONBLOCK, &blocking, sizeof(blocking));
-
-}
-
-PRStatus
-_MD_set_fd_inheritable (PRFileDesc *fd, PRBool inheritable)
-{
- int rv;
-
- rv = fcntl(fd->secret->md.osfd, F_SETFD, inheritable ? 0 : FD_CLOEXEC);
- if (-1 == rv) {
- PR_SetError(PR_UNKNOWN_ERROR, _MD_ERRNO());
- return PR_FAILURE;
- }
- return PR_SUCCESS;
-}
-
-void
-_MD_init_fd_inheritable (PRFileDesc *fd, PRBool imported)
-{
- if (imported) {
- fd->secret->inheritable = _PR_TRI_UNKNOWN;
- } else {
- int flags = fcntl(fd->secret->md.osfd, F_GETFD, 0);
- if (flags == -1) {
- PR_SetError(PR_UNKNOWN_ERROR, _MD_ERRNO());
- return;
- }
- fd->secret->inheritable = (flags & FD_CLOEXEC) ?
- _PR_TRI_TRUE : _PR_TRI_FALSE;
- }
-}
-
-void
-_MD_query_fd_inheritable (PRFileDesc *fd)
-{
- int flags;
-
- PR_ASSERT(_PR_TRI_UNKNOWN == fd->secret->inheritable);
- flags = fcntl(fd->secret->md.osfd, F_GETFD, 0);
- PR_ASSERT(-1 != flags);
- fd->secret->inheritable = (flags & FD_CLOEXEC) ?
- _PR_TRI_FALSE : _PR_TRI_TRUE;
-}
-
-PRInt32
-_MD_open (const char *name, PRIntn flags, PRIntn mode)
-{
- PRInt32 osflags;
- PRInt32 rv, err;
-
- if (flags & PR_RDWR) {
- osflags = O_RDWR;
- } else if (flags & PR_WRONLY) {
- osflags = O_WRONLY;
- } else {
- osflags = O_RDONLY;
- }
-
- if (flags & PR_EXCL)
- osflags |= O_EXCL;
- if (flags & PR_APPEND)
- osflags |= O_APPEND;
- if (flags & PR_TRUNCATE)
- osflags |= O_TRUNC;
- if (flags & PR_SYNC) {
-/* Ummmm. BeOS doesn't appear to
- support sync in any way shape or
- form. */
- return PR_NOT_IMPLEMENTED_ERROR;
- }
-
- /*
- ** On creations we hold the 'create' lock in order to enforce
- ** the semantics of PR_Rename. (see the latter for more details)
- */
- if (flags & PR_CREATE_FILE)
- {
- osflags |= O_CREAT ;
- if (NULL !=_pr_rename_lock)
- PR_Lock(_pr_rename_lock);
- }
-
- rv = open(name, osflags, mode);
-
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_OPEN_ERROR(err);
- }
-
- if ((flags & PR_CREATE_FILE) && (NULL !=_pr_rename_lock))
- PR_Unlock(_pr_rename_lock);
- return rv;
-}
-
-PRInt32
-_MD_close_file (PRInt32 osfd)
-{
-PRInt32 rv, err;
-
- rv = close(osfd);
- if (rv == -1) {
- err = _MD_ERRNO();
- _PR_MD_MAP_CLOSE_ERROR(err);
- }
- return(rv);
-}
-
-PRInt32
-_MD_read (PRFileDesc *fd, void *buf, PRInt32 amount)
-{
- PRInt32 rv, err;
- PRInt32 osfd = fd->secret->md.osfd;
-
- rv = read( osfd, buf, amount );
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_READ_ERROR(err);
- }
- return(rv);
-}
-
-PRInt32
-_MD_write (PRFileDesc *fd, const void *buf, PRInt32 amount)
-{
- PRInt32 rv, err;
- PRInt32 osfd = fd->secret->md.osfd;
-
- rv = write( osfd, buf, amount );
-
- if( rv < 0 ) {
-
- err = _MD_ERRNO();
- _PR_MD_MAP_WRITE_ERROR(err);
- }
- return( rv );
-}
-
-#ifndef BONE_VERSION /* Writev moves to bnet.c with BONE */
-PRInt32
-_MD_writev (PRFileDesc *fd, const PRIOVec *iov, PRInt32 iov_size,
- PRIntervalTime timeout)
-{
- return PR_NOT_IMPLEMENTED_ERROR;
-}
-#endif
-
-PRInt32
-_MD_lseek (PRFileDesc *fd, PRInt32 offset, int whence)
-{
-PRInt32 rv, err;
-
- rv = lseek (fd->secret->md.osfd, offset, whence);
- if (rv == -1) {
- err = _MD_ERRNO();
- _PR_MD_MAP_LSEEK_ERROR(err);
- }
- return( rv );
-}
-
-PRInt64
-_MD_lseek64 (PRFileDesc *fd, PRInt64 offset, int whence)
-{
-PRInt32 rv, err;
-
-/* According to the BeOS headers, lseek accepts a
- * variable of type off_t for the offset, and off_t
- * is defined to be a 64-bit value. So no special
- * cracking needs to be done on "offset".
- */
-
- rv = lseek (fd->secret->md.osfd, offset, whence);
- if (rv == -1) {
- err = _MD_ERRNO();
- _PR_MD_MAP_LSEEK_ERROR(err);
- }
- return( rv );
-}
-
-PRInt32
-_MD_fsync (PRFileDesc *fd)
-{
-PRInt32 rv, err;
-
- rv = fsync(fd->secret->md.osfd);
- if (rv == -1) {
- err = _MD_ERRNO();
- _PR_MD_MAP_FSYNC_ERROR(err);
- }
- return(rv);
-}
-
-PRInt32
-_MD_delete (const char *name)
-{
-PRInt32 rv, err;
-
- rv = unlink(name);
- if (rv == -1)
- {
- err = _MD_ERRNO();
- _PR_MD_MAP_UNLINK_ERROR(err);
- }
- return (rv);
-}
-
-PRInt32
-_MD_getfileinfo (const char *fn, PRFileInfo *info)
-{
-struct stat sb;
-PRInt32 rv, err;
-PRInt64 s, s2us;
-
- rv = stat(fn, &sb);
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_STAT_ERROR(err);
- } else if (info) {
- if (S_IFREG & sb.st_mode)
- info->type = PR_FILE_FILE;
- else if (S_IFDIR & sb.st_mode)
- info->type = PR_FILE_DIRECTORY;
- else
- info->type = PR_FILE_OTHER;
-
- /* Must truncate file size for the 32 bit
- version */
- info->size = (sb.st_size & 0xffffffff);
- LL_I2L(s, sb.st_mtime);
- LL_I2L(s2us, PR_USEC_PER_SEC);
- LL_MUL(s, s, s2us);
- info->modifyTime = s;
- LL_I2L(s, sb.st_ctime);
- LL_MUL(s, s, s2us);
- info->creationTime = s;
- }
- return rv;
-}
-
-PRInt32
-_MD_getfileinfo64 (const char *fn, PRFileInfo64 *info)
-{
-struct stat sb;
-PRInt32 rv, err;
-PRInt64 s, s2us;
-
- rv = stat(fn, &sb);
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_STAT_ERROR(err);
- } else if (info) {
- if (S_IFREG & sb.st_mode)
- info->type = PR_FILE_FILE;
- else if (S_IFDIR & sb.st_mode)
- info->type = PR_FILE_DIRECTORY;
- else
- info->type = PR_FILE_OTHER;
-
- /* For the 64 bit version we can use
- * the native st_size without modification
- */
- info->size = sb.st_size;
- LL_I2L(s, sb.st_mtime);
- LL_I2L(s2us, PR_USEC_PER_SEC);
- LL_MUL(s, s, s2us);
- info->modifyTime = s;
- LL_I2L(s, sb.st_ctime);
- LL_MUL(s, s, s2us);
- info->creationTime = s;
- }
- return rv;
-}
-
-PRInt32
-_MD_getopenfileinfo (const PRFileDesc *fd, PRFileInfo *info)
-{
- struct stat sb;
- PRInt64 s, s2us;
- PRInt32 rv, err;
-
- rv = fstat(fd->secret->md.osfd, &sb);
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_FSTAT_ERROR(err);
- } else if (info) {
- if (info) {
- if (S_IFREG & sb.st_mode)
- info->type = PR_FILE_FILE ;
- else if (S_IFDIR & sb.st_mode)
- info->type = PR_FILE_DIRECTORY;
- else
- info->type = PR_FILE_OTHER;
- /* Use lower 32 bits of file size */
- info->size = ( sb.st_size & 0xffffffff);
- LL_I2L(s, sb.st_mtime);
- LL_I2L(s2us, PR_USEC_PER_SEC);
- LL_MUL(s, s, s2us);
- info->modifyTime = s;
- LL_I2L(s, sb.st_ctime);
- LL_MUL(s, s, s2us);
- info->creationTime = s;
- }
- }
- return rv;
-}
-
-PRInt32
-_MD_getopenfileinfo64 (const PRFileDesc *fd, PRFileInfo64 *info)
-{
- struct stat sb;
- PRInt64 s, s2us;
- PRInt32 rv, err;
-
- rv = fstat(fd->secret->md.osfd, &sb);
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_FSTAT_ERROR(err);
- } else if (info) {
- if (info) {
- if (S_IFREG & sb.st_mode)
- info->type = PR_FILE_FILE ;
- else if (S_IFDIR & sb.st_mode)
- info->type = PR_FILE_DIRECTORY;
- else
- info->type = PR_FILE_OTHER;
- info->size = sb.st_size;
- LL_I2L(s, sb.st_mtime);
- LL_I2L(s2us, PR_USEC_PER_SEC);
- LL_MUL(s, s, s2us);
- info->modifyTime = s;
- LL_I2L(s, sb.st_ctime);
- LL_MUL(s, s, s2us);
- info->creationTime = s;
- }
- }
- return rv;
-}
-
-PRInt32
-_MD_rename (const char *from, const char *to)
-{
- PRInt32 rv = -1, err;
-
- /*
- ** This is trying to enforce the semantics of WINDOZE' rename
- ** operation. That means one is not allowed to rename over top
- ** of an existing file. Holding a lock across these two function
- ** and the open function is known to be a bad idea, but ....
- */
- if (NULL != _pr_rename_lock)
- PR_Lock(_pr_rename_lock);
- if (0 == access(to, F_OK))
- PR_SetError(PR_FILE_EXISTS_ERROR, 0);
- else
- {
- rv = rename(from, to);
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_RENAME_ERROR(err);
- }
- }
- if (NULL != _pr_rename_lock)
- PR_Unlock(_pr_rename_lock);
- return rv;
-}
-
-PRInt32
-_MD_access (const char *name, PRIntn how)
-{
-PRInt32 rv, err;
-int checkFlags;
-struct stat buf;
-
- switch (how) {
- case PR_ACCESS_WRITE_OK:
- checkFlags = S_IWUSR | S_IWGRP | S_IWOTH;
- break;
-
- case PR_ACCESS_READ_OK:
- checkFlags = S_IRUSR | S_IRGRP | S_IROTH;
- break;
-
- case PR_ACCESS_EXISTS:
- /* we don't need to examine st_mode. */
- break;
-
- default:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
- return -1;
- }
-
- rv = stat(name, &buf);
- if (rv == 0 && how != PR_ACCESS_EXISTS && (!(buf.st_mode & checkFlags))) {
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, 0);
- return -1;
- }
-
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_STAT_ERROR(err);
- }
-
- return(rv);
-}
-
-PRInt32
-_MD_stat (const char *name, struct stat *buf)
-{
- return PR_NOT_IMPLEMENTED_ERROR;
-}
-
-PRInt32
-_MD_mkdir (const char *name, PRIntn mode)
-{
- status_t rv;
- int err;
-
- /*
- ** This lock is used to enforce rename semantics as described
- ** in PR_Rename. Look there for more fun details.
- */
- if (NULL !=_pr_rename_lock)
- PR_Lock(_pr_rename_lock);
-
- rv = mkdir(name, mode);
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_MKDIR_ERROR(err);
- }
- if (NULL !=_pr_rename_lock)
- PR_Unlock(_pr_rename_lock);
- return rv;
-}
-
-PRInt32
-_MD_rmdir (const char *name)
-{
-int rv, err;
-
- rv = rmdir(name);
- if (rv == -1) {
- err = _MD_ERRNO();
- _PR_MD_MAP_RMDIR_ERROR(err);
- }
- return rv;
-}
-
-PRInt32
-_MD_pr_poll(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
-{
- PRInt32 rv = 0;
- PRThread *me = _PR_MD_CURRENT_THREAD();
- /*
- * This code is almost a duplicate of w32poll.c's _PR_MD_PR_POLL().
- */
- fd_set rd, wt, ex;
- PRFileDesc *bottom;
- PRPollDesc *pd, *epd;
- PRInt32 maxfd = -1, ready, err;
- PRIntervalTime remaining, elapsed, start;
-
- struct timeval tv, *tvp = NULL;
-
- if (_PR_PENDING_INTERRUPT(me))
- {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- return -1;
- }
-
- if (0 == npds) {
- PR_Sleep(timeout);
- return rv;
- }
-
- FD_ZERO(&rd);
- FD_ZERO(&wt);
- FD_ZERO(&ex);
-
- ready = 0;
- for (pd = pds, epd = pd + npds; pd < epd; pd++)
- {
- PRInt16 in_flags_read = 0, in_flags_write = 0;
- PRInt16 out_flags_read = 0, out_flags_write = 0;
-
- if ((NULL != pd->fd) && (0 != pd->in_flags))
- {
- if (pd->in_flags & PR_POLL_READ)
- {
- in_flags_read = (pd->fd->methods->poll)(pd->fd, pd->in_flags & ~PR_POLL_WRITE, &out_flags_read);
- }
- if (pd->in_flags & PR_POLL_WRITE)
- {
- in_flags_write = (pd->fd->methods->poll)(pd->fd, pd->in_flags & ~PR_POLL_READ, &out_flags_write);
- }
- if ((0 != (in_flags_read & out_flags_read))
- || (0 != (in_flags_write & out_flags_write)))
- {
- /* this one's ready right now */
- if (0 == ready)
- {
- /*
- * We will have to return without calling the
- * system poll/select function. So zero the
- * out_flags fields of all the poll descriptors
- * before this one.
- */
- PRPollDesc *prev;
- for (prev = pds; prev < pd; prev++)
- {
- prev->out_flags = 0;
- }
- }
- ready += 1;
- pd->out_flags = out_flags_read | out_flags_write;
- }
- else
- {
- pd->out_flags = 0; /* pre-condition */
-
- /* make sure this is an NSPR supported stack */
- bottom = PR_GetIdentitiesLayer(pd->fd, PR_NSPR_IO_LAYER);
- PR_ASSERT(NULL != bottom); /* what to do about that? */
- if ((NULL != bottom)
- && (_PR_FILEDESC_OPEN == bottom->secret->state))
- {
- if (0 == ready)
- {
- PRInt32 osfd = bottom->secret->md.osfd;
- if (osfd > maxfd) maxfd = osfd;
- if (in_flags_read & PR_POLL_READ)
- {
- pd->out_flags |= _PR_POLL_READ_SYS_READ;
- FD_SET(osfd, &rd);
- }
- if (in_flags_read & PR_POLL_WRITE)
- {
- pd->out_flags |= _PR_POLL_READ_SYS_WRITE;
- FD_SET(osfd, &wt);
- }
- if (in_flags_write & PR_POLL_READ)
- {
- pd->out_flags |= _PR_POLL_WRITE_SYS_READ;
- FD_SET(osfd, &rd);
- }
- if (in_flags_write & PR_POLL_WRITE)
- {
- pd->out_flags |= _PR_POLL_WRITE_SYS_WRITE;
- FD_SET(osfd, &wt);
- }
- if (pd->in_flags & PR_POLL_EXCEPT) FD_SET(osfd, &ex);
- }
- }
- else
- {
- if (0 == ready)
- {
- PRPollDesc *prev;
- for (prev = pds; prev < pd; prev++)
- {
- prev->out_flags = 0;
- }
- }
- ready += 1; /* this will cause an abrupt return */
- pd->out_flags = PR_POLL_NVAL; /* bogii */
- }
- }
- }
- else
- {
- pd->out_flags = 0;
- }
- }
-
- if (0 != ready) return ready; /* no need to block */
-
- remaining = timeout;
- start = PR_IntervalNow();
-
- retry:
- if (timeout != PR_INTERVAL_NO_TIMEOUT)
- {
- PRInt32 ticksPerSecond = PR_TicksPerSecond();
- tv.tv_sec = remaining / ticksPerSecond;
- tv.tv_usec = PR_IntervalToMicroseconds( remaining % ticksPerSecond );
- tvp = &tv;
- }
-
- ready = _MD_SELECT(maxfd + 1, &rd, &wt, &ex, tvp);
-
- if (ready == -1 && errno == EINTR)
- {
- if (timeout == PR_INTERVAL_NO_TIMEOUT) goto retry;
- else
- {
- elapsed = (PRIntervalTime) (PR_IntervalNow() - start);
- if (elapsed > timeout) ready = 0; /* timed out */
- else
- {
- remaining = timeout - elapsed;
- goto retry;
- }
- }
- }
-
- /*
- ** Now to unravel the select sets back into the client's poll
- ** descriptor list. Is this possibly an area for pissing away
- ** a few cycles or what?
- */
- if (ready > 0)
- {
- ready = 0;
- for (pd = pds, epd = pd + npds; pd < epd; pd++)
- {
- PRInt16 out_flags = 0;
- if ((NULL != pd->fd) && (0 != pd->in_flags))
- {
- PRInt32 osfd;
- bottom = PR_GetIdentitiesLayer(pd->fd, PR_NSPR_IO_LAYER);
- PR_ASSERT(NULL != bottom);
-
- osfd = bottom->secret->md.osfd;
-
- if (FD_ISSET(osfd, &rd))
- {
- if (pd->out_flags & _PR_POLL_READ_SYS_READ)
- out_flags |= PR_POLL_READ;
- if (pd->out_flags & _PR_POLL_WRITE_SYS_READ)
- out_flags |= PR_POLL_WRITE;
- }
- if (FD_ISSET(osfd, &wt))
- {
- if (pd->out_flags & _PR_POLL_READ_SYS_WRITE)
- out_flags |= PR_POLL_READ;
- if (pd->out_flags & _PR_POLL_WRITE_SYS_WRITE)
- out_flags |= PR_POLL_WRITE;
- }
- if (FD_ISSET(osfd, &ex)) out_flags |= PR_POLL_EXCEPT;
-
-/* Workaround for nonblocking connects under net_server */
-#ifndef BONE_VERSION
- if (out_flags)
- {
- /* check if it is a pending connect */
- int i = 0, j = 0;
- PR_Lock( _connectLock );
- for( i = 0; i < connectCount; i++ )
- {
- if(connectList[i].osfd == osfd)
- {
- int connectError;
- int connectResult;
-
- connectResult = connect(connectList[i].osfd,
- &connectList[i].addr,
- connectList[i].addrlen);
- connectError = errno;
-
- if(connectResult < 0 )
- {
- if(connectError == EINTR || connectError == EWOULDBLOCK ||
- connectError == EINPROGRESS || connectError == EALREADY)
- {
- break;
- }
- }
-
- if(i == (connectCount - 1))
- {
- connectList[i].osfd = -1;
- } else {
- for(j = i; j < connectCount; j++ )
- {
- memcpy( &connectList[j], &connectList[j+1],
- sizeof(connectList[j]));
- }
- }
- connectCount--;
-
- bottom->secret->md.connectReturnValue = connectResult;
- bottom->secret->md.connectReturnError = connectError;
- bottom->secret->md.connectValueValid = PR_TRUE;
- break;
- }
- }
- PR_Unlock( _connectLock );
- }
-#endif
- }
- pd->out_flags = out_flags;
- if (out_flags) ready++;
- }
- PR_ASSERT(ready > 0);
- }
- else if (ready < 0)
- {
- err = _MD_ERRNO();
- if (err == EBADF)
- {
- /* Find the bad fds */
- ready = 0;
- for (pd = pds, epd = pd + npds; pd < epd; pd++)
- {
- pd->out_flags = 0;
- if ((NULL != pd->fd) && (0 != pd->in_flags))
- {
- bottom = PR_GetIdentitiesLayer(pd->fd, PR_NSPR_IO_LAYER);
- if (fcntl(bottom->secret->md.osfd, F_GETFL, 0) == -1)
- {
- pd->out_flags = PR_POLL_NVAL;
- ready++;
- }
- }
- }
- PR_ASSERT(ready > 0);
- }
- else _PR_MD_MAP_SELECT_ERROR(err);
- }
-
- return ready;
-} /* _MD_pr_poll */
-
-/*
- * File locking.
- */
-
-PRStatus
-_MD_lockfile (PRInt32 osfd)
-{
- PRInt32 rv;
- struct flock linfo;
-
- linfo.l_type =
- linfo.l_whence = SEEK_SET;
- linfo.l_start = 0;
- linfo.l_len = 0;
-
- rv = fcntl(osfd, F_SETLKW, &linfo);
- if (rv == 0)
- return PR_SUCCESS;
-
- _PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
- return PR_FAILURE;
-}
-
-PRStatus
-_MD_tlockfile (PRInt32 osfd)
-{
- PRInt32 rv;
- struct flock linfo;
-
- linfo.l_type =
- linfo.l_whence = SEEK_SET;
- linfo.l_start = 0;
- linfo.l_len = 0;
-
- rv = fcntl(osfd, F_SETLK, &linfo);
- if (rv == 0)
- return PR_SUCCESS;
-
- _PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
- return PR_FAILURE;
-}
-
-PRStatus
-_MD_unlockfile (PRInt32 osfd)
-{
- PRInt32 rv;
- struct flock linfo;
-
- linfo.l_type =
- linfo.l_whence = SEEK_SET;
- linfo.l_start = 0;
- linfo.l_len = 0;
-
- rv = fcntl(osfd, F_UNLCK, &linfo);
-
- if (rv == 0)
- return PR_SUCCESS;
-
- _PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
- return PR_FAILURE;
-}
-
diff --git a/nsprpub/pr/src/md/beos/bmemory.c b/nsprpub/pr/src/md/beos/bmemory.c
deleted file mode 100644
index fb906f0f9..000000000
--- a/nsprpub/pr/src/md/beos/bmemory.c
+++ /dev/null
@@ -1,10 +0,0 @@
-/* -*- Mode: C++; c-basic-offset: 4 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "primpl.h"
-
-PR_EXTERN(void) _PR_MD_INIT_SEGS(void);
-PR_EXTERN(PRStatus) _PR_MD_ALLOC_SEGMENT(PRSegment *seg, PRUint32 size, void *vaddr);
-PR_EXTERN(void) _PR_MD_FREE_SEGMENT(PRSegment *seg);
diff --git a/nsprpub/pr/src/md/beos/bmisc.c b/nsprpub/pr/src/md/beos/bmisc.c
deleted file mode 100644
index 4bdad411e..000000000
--- a/nsprpub/pr/src/md/beos/bmisc.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/* -*- Mode: C++; c-basic-offset: 4 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "primpl.h"
-
-#include <stdlib.h>
-
-PRLock *_connectLock = NULL;
-
-#ifndef BONE_VERSION
-/* Workaround for nonblocking connects under net_server */
-PRUint32 connectCount = 0;
-ConnectListNode connectList[64];
-#endif
-
-void
-_MD_cleanup_before_exit (void)
-{
-}
-
-void
-_MD_exit (PRIntn status)
-{
- exit(status);
-}
-
-void
-_MD_early_init (void)
-{
-}
-
-static PRLock *monitor = NULL;
-
-void
-_MD_final_init (void)
-{
- _connectLock = PR_NewLock();
- PR_ASSERT(NULL != _connectLock);
-#ifndef BONE_VERSION
- /* Workaround for nonblocking connects under net_server */
- connectCount = 0;
-#endif
-}
-
-void
-_MD_AtomicInit (void)
-{
- if (monitor == NULL) {
- monitor = PR_NewLock();
- }
-}
-
-/*
-** This is exceedingly messy. atomic_add returns the last value, NSPR expects the new value.
-** We just add or subtract 1 from the result. The actual memory update is atomic.
-*/
-
-PRInt32
-_MD_AtomicAdd( PRInt32 *ptr, PRInt32 val )
-{
- return( ( atomic_add( (long *)ptr, val ) ) + val );
-}
-
-PRInt32
-_MD_AtomicIncrement( PRInt32 *val )
-{
- return( ( atomic_add( (long *)val, 1 ) ) + 1 );
-}
-
-PRInt32
-_MD_AtomicDecrement( PRInt32 *val )
-{
- return( ( atomic_add( (long *)val, -1 ) ) - 1 );
-}
-
-PRInt32
-_MD_AtomicSet( PRInt32 *val, PRInt32 newval )
-{
- PRInt32 rv;
-
- if (!_pr_initialized) {
- _PR_ImplicitInitialization();
- }
- PR_Lock(monitor);
- rv = *val;
- *val = newval;
- PR_Unlock(monitor);
- return rv;
-}
diff --git a/nsprpub/pr/src/md/beos/bmmap.c b/nsprpub/pr/src/md/beos/bmmap.c
deleted file mode 100644
index a9b3ac589..000000000
--- a/nsprpub/pr/src/md/beos/bmmap.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/* -*- Mode: C++; c-basic-offset: 4 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "primpl.h"
-
-PR_EXTERN(PRStatus)
-_PR_MD_CREATE_FILE_MAP(PRFileMap *fmap, PRInt64 size)
-{
- PR_SetError( PR_NOT_IMPLEMENTED_ERROR, 0 );
- return PR_FAILURE;
-}
-
-PR_EXTERN(PRInt32)
-_PR_MD_GET_MEM_MAP_ALIGNMENT(void)
-{
- PR_SetError( PR_NOT_IMPLEMENTED_ERROR, 0 );
- return -1;
-}
-
-PR_EXTERN(void *)
-_PR_MD_MEM_MAP(PRFileMap *fmap, PRInt64 offset, PRUint32 len)
-{
- PR_SetError( PR_NOT_IMPLEMENTED_ERROR, 0 );
- return 0;
-}
-
-PR_EXTERN(PRStatus)
-_PR_MD_MEM_UNMAP(void *addr, PRUint32 size)
-{
- PR_SetError( PR_NOT_IMPLEMENTED_ERROR, 0 );
- return PR_FAILURE;
-}
-
-PR_EXTERN(PRStatus)
-_PR_MD_CLOSE_FILE_MAP(PRFileMap *fmap)
-{
- PR_SetError( PR_NOT_IMPLEMENTED_ERROR, 0 );
- return PR_FAILURE;
-}
diff --git a/nsprpub/pr/src/md/beos/bnet.c b/nsprpub/pr/src/md/beos/bnet.c
deleted file mode 100644
index 8bfd4aead..000000000
--- a/nsprpub/pr/src/md/beos/bnet.c
+++ /dev/null
@@ -1,911 +0,0 @@
-/* -*- Mode: C++; c-basic-offset: 4 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "primpl.h"
-
-#include <signal.h>
-#include <unistd.h>
-#include <memory.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/time.h>
-#include <sys/ioctl.h>
-
-/*
- * Make sure _PRSockLen_t is 32-bit, because we will cast a PRUint32* or
- * PRInt32* pointer to a _PRSockLen_t* pointer.
- */
-#define _PRSockLen_t int
-
-
-/*
-** Global lock variable used to bracket calls into rusty libraries that
-** aren't thread safe (like libc, libX, etc).
-*/
-static PRLock *_pr_rename_lock = NULL;
-static PRMonitor *_pr_Xfe_mon = NULL;
-
-#define READ_FD 1
-#define WRITE_FD 2
-
-/*
-** This is a support routine to handle "deferred" i/o on sockets.
-** It uses "select", so it is subject to all of the BeOS limitations
-** (only READ notification, only sockets)
-*/
-
-/*
- * socket_io_wait --
- *
- * wait for socket i/o, periodically checking for interrupt
- *
- */
-
-static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type,
- PRIntervalTime timeout)
-{
- PRInt32 rv = -1;
- struct timeval tv;
- PRThread *me = _PR_MD_CURRENT_THREAD();
- PRIntervalTime epoch, now, elapsed, remaining;
- PRBool wait_for_remaining;
- PRInt32 syserror;
- fd_set rd_wr;
-
- switch (timeout) {
- case PR_INTERVAL_NO_WAIT:
- PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
- break;
- case PR_INTERVAL_NO_TIMEOUT:
- /*
- * This is a special case of the 'default' case below.
- * Please see the comments there.
- */
- tv.tv_sec = _PR_INTERRUPT_CHECK_INTERVAL_SECS;
- tv.tv_usec = 0;
- FD_ZERO(&rd_wr);
- do {
- FD_SET(osfd, &rd_wr);
- if (fd_type == READ_FD)
- rv = _MD_SELECT(osfd + 1, &rd_wr, NULL, NULL, &tv);
- else
- rv = _MD_SELECT(osfd + 1, NULL, &rd_wr, NULL, &tv);
- if (rv == -1 && (syserror = _MD_ERRNO()) != EINTR) {
-#ifdef BONE_VERSION
- _PR_MD_MAP_SELECT_ERROR(syserror);
-#else
- if (syserror == EBADF) {
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, EBADF);
- } else {
- PR_SetError(PR_UNKNOWN_ERROR, syserror);
- }
-#endif
- break;
- }
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- rv = -1;
- break;
- }
- } while (rv == 0 || (rv == -1 && syserror == EINTR));
- break;
- default:
- now = epoch = PR_IntervalNow();
- remaining = timeout;
- FD_ZERO(&rd_wr);
- do {
- /*
- * We block in _MD_SELECT for at most
- * _PR_INTERRUPT_CHECK_INTERVAL_SECS seconds,
- * so that there is an upper limit on the delay
- * before the interrupt bit is checked.
- */
- wait_for_remaining = PR_TRUE;
- tv.tv_sec = PR_IntervalToSeconds(remaining);
- if (tv.tv_sec > _PR_INTERRUPT_CHECK_INTERVAL_SECS) {
- wait_for_remaining = PR_FALSE;
- tv.tv_sec = _PR_INTERRUPT_CHECK_INTERVAL_SECS;
- tv.tv_usec = 0;
- } else {
- tv.tv_usec = PR_IntervalToMicroseconds(
- remaining -
- PR_SecondsToInterval(tv.tv_sec));
- }
- FD_SET(osfd, &rd_wr);
- if (fd_type == READ_FD)
- rv = _MD_SELECT(osfd + 1, &rd_wr, NULL, NULL, &tv);
- else
- rv = _MD_SELECT(osfd + 1, NULL, &rd_wr, NULL, &tv);
- /*
- * we don't consider EINTR a real error
- */
- if (rv == -1 && (syserror = _MD_ERRNO()) != EINTR) {
-#ifdef BONE_VERSION
- _PR_MD_MAP_SELECT_ERROR(syserror);
-#else
- if (syserror == EBADF) {
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, EBADF);
- } else {
- PR_SetError(PR_UNKNOWN_ERROR, syserror);
- }
-#endif
- break;
- }
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- rv = -1;
- break;
- }
- /*
- * We loop again if _MD_SELECT timed out or got interrupted
- * by a signal, and the timeout deadline has not passed yet.
- */
- if (rv == 0 || (rv == -1 && syserror == EINTR)) {
- /*
- * If _MD_SELECT timed out, we know how much time
- * we spent in blocking, so we can avoid a
- * PR_IntervalNow() call.
- */
- if (rv == 0) {
- if (wait_for_remaining) {
- now += remaining;
- } else {
- now += PR_SecondsToInterval(tv.tv_sec)
- + PR_MicrosecondsToInterval(tv.tv_usec);
- }
- } else {
- now = PR_IntervalNow();
- }
- elapsed = (PRIntervalTime) (now - epoch);
- if (elapsed >= timeout) {
- PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
- rv = -1;
- break;
- } else {
- remaining = timeout - elapsed;
- }
- }
- } while (rv == 0 || (rv == -1 && syserror == EINTR));
- break;
- }
- return(rv);
-}
-
-PRInt32
-_MD_recv (PRFileDesc *fd, void *buf, PRInt32 amount, PRInt32 flags,
- PRIntervalTime timeout)
-{
- PRInt32 osfd = fd->secret->md.osfd;
- PRInt32 rv, err;
- PRThread *me = _PR_MD_CURRENT_THREAD();
-
-#ifndef BONE_VERSION
- if (fd->secret->md.sock_state & BE_SOCK_SHUTDOWN_READ) {
- _PR_MD_MAP_RECV_ERROR(EPIPE);
- return -1;
- }
-#endif
-
-#ifdef BONE_VERSION
- /*
- ** Gah, stupid hack. If reading a zero amount, instantly return success.
- ** BONE beta 6 returns EINVAL for reads of zero bytes, which parts of
- ** mozilla use to check for socket availability.
- */
-
- if( 0 == amount ) return(0);
-#endif
-
- while ((rv = recv(osfd, buf, amount, flags)) == -1) {
- err = _MD_ERRNO();
-
- if ((err == EAGAIN) || (err == EWOULDBLOCK)) {
- if (fd->secret->nonblocking) {
- break;
- }
- /* If socket was supposed to be blocking,
- wait a while for the condition to be
- satisfied. */
- if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0)
- goto done;
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
- continue;
-
- } else
- break;
- }
-
- if (rv < 0) {
- _PR_MD_MAP_RECV_ERROR(err);
- }
-
-done:
- return(rv);
-}
-
-PRInt32
-_MD_recvfrom (PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
- PRNetAddr *addr, PRUint32 *addrlen, PRIntervalTime timeout)
-{
- PRInt32 osfd = fd->secret->md.osfd;
- PRInt32 rv, err;
- PRThread *me = _PR_MD_CURRENT_THREAD();
-
- while ((*addrlen = PR_NETADDR_SIZE(addr)),
- ((rv = recvfrom(osfd, buf, amount, flags,
- (struct sockaddr *) addr,
- (_PRSockLen_t *)addrlen)) == -1)) {
- err = _MD_ERRNO();
-
- if ((err == EAGAIN) || (err == EWOULDBLOCK)) {
- if (fd->secret->nonblocking) {
- break;
- }
- if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0)
- goto done;
-
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
- continue;
- } else {
- break;
- }
- }
-
- if (rv < 0) {
- _PR_MD_MAP_RECVFROM_ERROR(err);
- }
-
-done:
-#ifdef _PR_HAVE_SOCKADDR_LEN
- if (rv != -1) {
- /* ignore the sa_len field of struct sockaddr */
- if (addr) {
- addr->raw.family = ((struct sockaddr *) addr)->sa_family;
- }
- }
-#endif /* _PR_HAVE_SOCKADDR_LEN */
- return(rv);
-}
-
-PRInt32
-_MD_send (PRFileDesc *fd, const void *buf, PRInt32 amount, PRInt32 flags,
- PRIntervalTime timeout)
-{
- PRInt32 osfd = fd->secret->md.osfd;
- PRInt32 rv, err;
- PRThread *me = _PR_MD_CURRENT_THREAD();
-
-#ifndef BONE_VERSION
- if (fd->secret->md.sock_state & BE_SOCK_SHUTDOWN_WRITE)
- {
- _PR_MD_MAP_SEND_ERROR(EPIPE);
- return -1;
- }
-#endif
-
- while ((rv = send(osfd, buf, amount, flags)) == -1) {
- err = _MD_ERRNO();
-
- if ((err == EAGAIN) || (err == EWOULDBLOCK)) {
- if (fd->secret->nonblocking) {
- break;
- }
-
-#ifndef BONE_VERSION
- if( _PR_PENDING_INTERRUPT(me)) {
-
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError( PR_PENDING_INTERRUPT_ERROR, 0);
- return -1;
- }
-
- /* in UNIX implementations, you could do a socket_io_wait here.
- * but since BeOS doesn't yet support WRITE notification in select,
- * you're spanked.
- */
- snooze( 10000L );
- continue;
-#else /* BONE_VERSION */
- if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))< 0)
- goto done;
-#endif
-
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
- continue;
-
- } else {
- break;
- }
- }
-
-#ifdef BONE_VERSION
- /*
- * optimization; if bytes sent is less than "amount" call
- * select before returning. This is because it is likely that
- * the next writev() call will return EWOULDBLOCK.
- */
- if ((!fd->secret->nonblocking) && (rv > 0) && (rv < amount)
- && (timeout != PR_INTERVAL_NO_WAIT)) {
- if (socket_io_wait(osfd, WRITE_FD, timeout) < 0) {
- rv = -1;
- goto done;
- }
- }
-#endif /* BONE_VERSION */
-
- if (rv < 0) {
- _PR_MD_MAP_SEND_ERROR(err);
- }
-
-#ifdef BONE_VERSION
-done:
-#endif
- return(rv);
-}
-
-PRInt32
-_MD_sendto (PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
- const PRNetAddr *addr, PRUint32 addrlen, PRIntervalTime timeout)
-{
- PRInt32 osfd = fd->secret->md.osfd;
- PRInt32 rv, err;
- PRThread *me = _PR_MD_CURRENT_THREAD();
-#ifdef _PR_HAVE_SOCKADDR_LEN
- PRNetAddr addrCopy;
-
- addrCopy = *addr;
- ((struct sockaddr *) &addrCopy)->sa_len = addrlen;
- ((struct sockaddr *) &addrCopy)->sa_family = addr->raw.family;
-
- while ((rv = sendto(osfd, buf, amount, flags,
- (struct sockaddr *) &addrCopy, addrlen)) == -1) {
-#else
- while ((rv = sendto(osfd, buf, amount, flags,
- (struct sockaddr *) addr, addrlen)) == -1) {
-#endif
- err = _MD_ERRNO();
-
- if ((err == EAGAIN) || (err == EWOULDBLOCK)) {
- if (fd->secret->nonblocking) {
- break;
- }
-
-#ifdef BONE_VERSION
- if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))< 0)
- goto done;
-#endif
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
- continue;
-
- } else {
- break;
- }
- }
-
- if (rv < 0) {
- _PR_MD_MAP_SENDTO_ERROR(err);
- }
-
-#ifdef BONE_VERSION
-done:
-#endif
- return(rv);
-}
-
-#ifdef BONE_VERSION
-
-PRInt32 _MD_writev(
- PRFileDesc *fd, const PRIOVec *iov,
- PRInt32 iov_size, PRIntervalTime timeout)
-{
- PRInt32 rv, err;
- PRThread *me = _PR_MD_CURRENT_THREAD();
- PRInt32 index, amount = 0;
- PRInt32 osfd = fd->secret->md.osfd;
- struct iovec osiov[PR_MAX_IOVECTOR_SIZE];
-
- /* Ensured by PR_Writev */
- PR_ASSERT(iov_size <= PR_MAX_IOVECTOR_SIZE);
-
- /*
- * We can't pass iov to writev because PRIOVec and struct iovec
- * may not be binary compatible. Make osiov a copy of iov and
- * pass osiov to writev.
- */
- for (index = 0; index < iov_size; index++) {
- osiov[index].iov_base = iov[index].iov_base;
- osiov[index].iov_len = iov[index].iov_len;
- }
-
- /*
- * Calculate the total number of bytes to be sent; needed for
- * optimization later.
- * We could avoid this if this number was passed in; but it is
- * probably not a big deal because iov_size is usually small (less than
- * 3)
- */
- if (!fd->secret->nonblocking) {
- for (index=0; index<iov_size; index++) {
- amount += iov[index].iov_len;
- }
- }
-
- while ((rv = writev(osfd, osiov, iov_size)) == -1) {
- err = _MD_ERRNO();
- if ((err == EAGAIN) || (err == EWOULDBLOCK)) {
- if (fd->secret->nonblocking) {
- break;
- }
- if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))<0)
- goto done;
-
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
- continue;
- } else {
- break;
- }
- }
-
- /*
- * optimization; if bytes sent is less than "amount" call
- * select before returning. This is because it is likely that
- * the next writev() call will return EWOULDBLOCK.
- */
- if ((!fd->secret->nonblocking) && (rv > 0) && (rv < amount)
- && (timeout != PR_INTERVAL_NO_WAIT)) {
- if (socket_io_wait(osfd, WRITE_FD, timeout) < 0) {
- rv = -1;
- goto done;
- }
- }
-
-
- if (rv < 0) {
- _PR_MD_MAP_WRITEV_ERROR(err);
- }
-done:
- return(rv);
-}
-
-#endif /* BONE_VERSION */
-
-PRInt32
-_MD_accept (PRFileDesc *fd, PRNetAddr *addr, PRUint32 *addrlen,
- PRIntervalTime timeout)
-{
- PRInt32 osfd = fd->secret->md.osfd;
- PRInt32 rv, err;
- PRThread *me = _PR_MD_CURRENT_THREAD();
-
- while ((rv = accept(osfd, (struct sockaddr *) addr,
- (_PRSockLen_t *)addrlen)) == -1) {
- err = _MD_ERRNO();
-
- if ((err == EAGAIN) || (err == EWOULDBLOCK)) {
- if (fd->secret->nonblocking) {
- break;
- }
- /* If it's SUPPOSED to be a blocking thread, wait
- * a while to see if the triggering condition gets
- * satisfied.
- */
- /* Assume that we're always using a native thread */
- if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0)
- goto done;
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
- continue;
- } else {
- break;
- }
- }
- if (rv < 0) {
- _PR_MD_MAP_ACCEPT_ERROR(err);
- } else if (addr != NULL) {
- /* bug 134099 */
- err = getpeername(rv, (struct sockaddr *) addr, (_PRSockLen_t *)addrlen);
- }
-done:
-#ifdef _PR_HAVE_SOCKADDR_LEN
- if (rv != -1) {
- /* Mask off the first byte of struct sockaddr (the length field) */
- if (addr) {
- addr->raw.family = ((struct sockaddr *) addr)->sa_family;
- }
- }
-#endif /* _PR_HAVE_SOCKADDR_LEN */
- return(rv);
-}
-
-PRInt32
-_MD_connect (PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,
- PRIntervalTime timeout)
-{
- PRInt32 rv, err;
- PRThread *me = _PR_MD_CURRENT_THREAD();
- PRInt32 osfd = fd->secret->md.osfd;
-
-#ifndef BONE_VERSION
- fd->secret->md.connectValueValid = PR_FALSE;
-#endif
-#ifdef _PR_HAVE_SOCKADDR_LEN
- PRNetAddr addrCopy;
-
- addrCopy = *addr;
- ((struct sockaddr *) &addrCopy)->sa_len = addrlen;
- ((struct sockaddr *) &addrCopy)->sa_family = addr->raw.family;
-#endif
-
- /* (Copied from unix.c)
- * We initiate the connection setup by making a nonblocking connect()
- * call. If the connect() call fails, there are two cases we handle
- * specially:
- * 1. The connect() call was interrupted by a signal. In this case
- * we simply retry connect().
- * 2. The NSPR socket is nonblocking and connect() fails with
- * EINPROGRESS. We first wait until the socket becomes writable.
- * Then we try to find out whether the connection setup succeeded
- * or failed.
- */
-
-retry:
-#ifdef _PR_HAVE_SOCKADDR_LEN
- if ((rv = connect(osfd, (struct sockaddr *)&addrCopy, addrlen)) == -1) {
-#else
- if ((rv = connect(osfd, (struct sockaddr *)addr, addrlen)) == -1) {
-#endif
- err = _MD_ERRNO();
-#ifndef BONE_VERSION
- fd->secret->md.connectReturnValue = rv;
- fd->secret->md.connectReturnError = err;
- fd->secret->md.connectValueValid = PR_TRUE;
-#endif
- if( err == EINTR ) {
-
- if( _PR_PENDING_INTERRUPT(me)) {
-
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError( PR_PENDING_INTERRUPT_ERROR, 0);
- return -1;
- }
-#ifndef BONE_VERSION
- snooze( 100000L );
-#endif
- goto retry;
- }
-
-#ifndef BONE_VERSION
- if(!fd->secret->nonblocking && ((err == EINPROGRESS) || (err==EAGAIN) || (err==EALREADY))) {
-
- /*
- ** There's no timeout on this connect, but that's not
- ** a big deal, since the connect times out anyways
- ** after 30 seconds. Just sleep for 1/10th of a second
- ** and retry until we go through or die.
- */
-
- if( _PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError( PR_PENDING_INTERRUPT_ERROR, 0);
- return -1;
- }
-
- goto retry;
- }
-
- if( fd->secret->nonblocking && ((err == EAGAIN) || (err == EINPROGRESS))) {
- PR_Lock(_connectLock);
- if (connectCount < sizeof(connectList)/sizeof(connectList[0])) {
- connectList[connectCount].osfd = osfd;
- memcpy(&connectList[connectCount].addr, addr, addrlen);
- connectList[connectCount].addrlen = addrlen;
- connectList[connectCount].timeout = timeout;
- connectCount++;
- PR_Unlock(_connectLock);
- _PR_MD_MAP_CONNECT_ERROR(err);
- } else {
- PR_Unlock(_connectLock);
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
- }
- return rv;
- }
-#else /* BONE_VERSION */
- if(!fd->secret->nonblocking && (err == EINTR)) {
-
- rv = socket_io_wait(osfd, WRITE_FD, timeout);
- if (rv == -1) {
- return -1;
- }
-
- PR_ASSERT(rv == 1);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError( PR_PENDING_INTERRUPT_ERROR, 0);
- return -1;
- }
- err = _MD_beos_get_nonblocking_connect_error(osfd);
- if (err != 0) {
- _PR_MD_MAP_CONNECT_ERROR(err);
- return -1;
- }
- return 0;
- }
-#endif
-
- _PR_MD_MAP_CONNECT_ERROR(err);
- }
-
- return rv;
-}
-
-PRInt32
-_MD_bind (PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen)
-{
- PRInt32 rv, err;
-#ifdef _PR_HAVE_SOCKADDR_LEN
- PRNetAddr addrCopy;
-
- addrCopy = *addr;
- ((struct sockaddr *) &addrCopy)->sa_len = addrlen;
- ((struct sockaddr *) &addrCopy)->sa_family = addr->raw.family;
- rv = bind(fd->secret->md.osfd, (struct sockaddr *) &addrCopy, (int )addrlen);
-#else
- rv = bind(fd->secret->md.osfd, (struct sockaddr *) addr, (int )addrlen);
-#endif
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_BIND_ERROR(err);
- }
-
- return(rv);
-}
-
-PRInt32
-_MD_listen (PRFileDesc *fd, PRIntn backlog)
-{
- PRInt32 rv, err;
-
-#ifndef BONE_VERSION
- /* Bug workaround! Setting listen to 0 on Be accepts no connections.
- ** On most UN*Xes this sets the default.
- */
-
- if( backlog == 0 ) backlog = 5;
-#endif
-
- rv = listen(fd->secret->md.osfd, backlog);
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_LISTEN_ERROR(err);
- }
-
- return(rv);
-}
-
-PRInt32
-_MD_shutdown (PRFileDesc *fd, PRIntn how)
-{
- PRInt32 rv, err;
-
-#ifndef BONE_VERSION
- if (how == PR_SHUTDOWN_SEND)
- fd->secret->md.sock_state = BE_SOCK_SHUTDOWN_WRITE;
- else if (how == PR_SHUTDOWN_RCV)
- fd->secret->md.sock_state = BE_SOCK_SHUTDOWN_READ;
- else if (how == PR_SHUTDOWN_BOTH) {
- fd->secret->md.sock_state = (BE_SOCK_SHUTDOWN_WRITE | BE_SOCK_SHUTDOWN_READ);
- }
-
- return 0;
-#else /* BONE_VERSION */
- rv = shutdown(fd->secret->md.osfd, how);
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_SHUTDOWN_ERROR(err);
- }
- return(rv);
-#endif
-}
-
-PRInt32
-_MD_socketpair (int af, int type, int flags, PRInt32 *osfd)
-{
- return PR_NOT_IMPLEMENTED_ERROR;
-}
-
-PRInt32
-_MD_close_socket (PRInt32 osfd)
-{
-#ifdef BONE_VERSION
- close( osfd );
-#else
- closesocket( osfd );
-#endif
-}
-
-PRStatus
-_MD_getsockname (PRFileDesc *fd, PRNetAddr *addr, PRUint32 *addrlen)
-{
- PRInt32 rv, err;
-
- rv = getsockname(fd->secret->md.osfd,
- (struct sockaddr *) addr, (_PRSockLen_t *)addrlen);
-#ifdef _PR_HAVE_SOCKADDR_LEN
- if (rv == 0) {
- /* ignore the sa_len field of struct sockaddr */
- if (addr) {
- addr->raw.family = ((struct sockaddr *) addr)->sa_family;
- }
- }
-#endif /* _PR_HAVE_SOCKADDR_LEN */
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_GETSOCKNAME_ERROR(err);
- }
-
- return rv==0?PR_SUCCESS:PR_FAILURE;
-}
-
-PRStatus
-_MD_getpeername (PRFileDesc *fd, PRNetAddr *addr, PRUint32 *addrlen)
-{
- PRInt32 rv, err;
-
- rv = getpeername(fd->secret->md.osfd,
- (struct sockaddr *) addr, (_PRSockLen_t *)addrlen);
-
-#ifdef _PR_HAVE_SOCKADDR_LEN
- if (rv == 0) {
- /* ignore the sa_len field of struct sockaddr */
- if (addr) {
- addr->raw.family = ((struct sockaddr *) addr)->sa_family;
- }
- }
-#endif /* _PR_HAVE_SOCKADDR_LEN */
-
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_GETPEERNAME_ERROR(err);
- }
- return rv==0?PR_SUCCESS:PR_FAILURE;
-}
-
-PRStatus
-_MD_getsockopt (PRFileDesc *fd, PRInt32 level,
- PRInt32 optname, char* optval, PRInt32* optlen)
-{
- PRInt32 rv, err;
-
- rv = getsockopt(fd->secret->md.osfd, level, optname,
- optval, (_PRSockLen_t *)optlen);
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_GETSOCKOPT_ERROR(err);
- }
-
- return rv==0?PR_SUCCESS:PR_FAILURE;
-}
-
-PRStatus
-_MD_setsockopt (PRFileDesc *fd, PRInt32 level,
- PRInt32 optname, const char* optval, PRInt32 optlen)
-{
- PRInt32 rv, err;
-
- rv = setsockopt(fd->secret->md.osfd, level, optname, optval, optlen);
- if (rv < 0) {
- err = _MD_ERRNO();
- _PR_MD_MAP_SETSOCKOPT_ERROR(err);
- }
- return rv==0?PR_SUCCESS:PR_FAILURE;
-}
-
-PRInt32
-_MD_accept_read (PRFileDesc *sd, PRInt32 *newSock, PRNetAddr **raddr,
- void *buf, PRInt32 amount, PRIntervalTime timeout)
-{
- return PR_NOT_IMPLEMENTED_ERROR;
-}
-
-#ifndef BONE_VERSION
-PRInt32
-_MD_socket (int af, int type, int flags)
-{
- PRInt32 osfd, err;
-
- osfd = socket( af, type, 0 );
-
- if( -1 == osfd ) {
-
- err = _MD_ERRNO();
- _PR_MD_MAP_SOCKET_ERROR( err );
- }
-
- return( osfd );
-}
-#else
-PRInt32
-_MD_socket(PRInt32 domain, PRInt32 type, PRInt32 proto)
-{
- PRInt32 osfd, err;
-
- osfd = socket(domain, type, proto);
-
- if (osfd == -1) {
- err = _MD_ERRNO();
- _PR_MD_MAP_SOCKET_ERROR(err);
- }
-
- return(osfd);
-}
-#endif
-
-PRInt32
-_MD_socketavailable (PRFileDesc *fd)
-{
-#ifdef BONE_VERSION
- PRInt32 result;
-
- if (ioctl(fd->secret->md.osfd, FIONREAD, &result) < 0) {
- _PR_MD_MAP_SOCKETAVAILABLE_ERROR(_MD_ERRNO());
- return -1;
- }
- return result;
-#else
- return PR_NOT_IMPLEMENTED_ERROR;
-#endif
-}
-
-PRInt32
-_MD_get_socket_error (void)
-{
- return PR_NOT_IMPLEMENTED_ERROR;
-}
-
-PRStatus
-_MD_gethostname (char *name, PRUint32 namelen)
-{
- PRInt32 rv, err;
-
- rv = gethostname(name, namelen);
- if (rv == 0)
- {
- err = _MD_ERRNO();
- _PR_MD_MAP_GETHOSTNAME_ERROR(err);
- return PR_FAILURE;
- }
- return PR_SUCCESS;
-}
-
-#ifndef BONE_VERSION
-PRInt32
-_MD_beos_get_nonblocking_connect_error(PRFileDesc *fd)
-{
- int rv;
- int flags = 0;
-
- rv = recv(fd->secret->md.osfd, NULL, 0, flags);
- PR_ASSERT(-1 == rv || 0 == rv);
- if (-1 == rv && errno != EAGAIN && errno != EWOULDBLOCK) {
- return errno;
- }
- return 0; /* no error */
-}
-#else
-PRInt32
-_MD_beos_get_nonblocking_connect_error(int osfd)
-{
- return PR_NOT_IMPLEMENTED_ERROR;
- // int err;
- // _PRSockLen_t optlen = sizeof(err);
- // if (getsockopt(osfd, SOL_SOCKET, SO_ERROR, (char *) &err, &optlen) == -1) {
- // return errno;
- // } else {
- // return err;
- // }
-}
-#endif /* BONE_VERSION */
diff --git a/nsprpub/pr/src/md/beos/bproc.c b/nsprpub/pr/src/md/beos/bproc.c
deleted file mode 100644
index 30ac56990..000000000
--- a/nsprpub/pr/src/md/beos/bproc.c
+++ /dev/null
@@ -1,212 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; c-basic-offset: 8 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "primpl.h"
-#include <stdio.h>
-#include <signal.h>
-
-#define _PR_SIGNALED_EXITSTATUS 256
-
-PRProcess*
-_MD_create_process (const char *path, char *const *argv,
- char *const *envp, const PRProcessAttr *attr)
-{
- PRProcess *process;
- int nEnv, idx;
- char *const *childEnvp;
- char **newEnvp = NULL;
- int flags;
- PRBool found = PR_FALSE;
-
- process = PR_NEW(PRProcess);
- if (!process) {
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
- return NULL;
- }
-
- childEnvp = envp;
- if (attr && attr->fdInheritBuffer) {
- if (NULL == childEnvp) {
- childEnvp = environ;
- }
- for (nEnv = 0; childEnvp[nEnv]; nEnv++) {
- }
- newEnvp = (char **) PR_MALLOC((nEnv + 2) * sizeof(char *));
- if (NULL == newEnvp) {
- PR_DELETE(process);
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
- return NULL;
- }
- for (idx = 0; idx < nEnv; idx++) {
- newEnvp[idx] = childEnvp[idx];
- if (!found && !strncmp(newEnvp[idx], "NSPR_INHERIT_FDS=", 17)) {
- newEnvp[idx] = attr->fdInheritBuffer;
- found = PR_TRUE;
- }
- }
- if (!found) {
- newEnvp[idx++] = attr->fdInheritBuffer;
- }
- newEnvp[idx] = NULL;
- childEnvp = newEnvp;
- }
-
- process->md.pid = fork();
-
- if ((pid_t) -1 == process->md.pid) {
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, errno);
- PR_DELETE(process);
- if (newEnvp) {
- PR_DELETE(newEnvp);
- }
- return NULL;
- } else if (0 == process->md.pid) { /* the child process */
- /*
- * If the child process needs to exit, it must call _exit().
- * Do not call exit(), because exit() will flush and close
- * the standard I/O file descriptors, and hence corrupt
- * the parent process's standard I/O data structures.
- */
-
- if (attr) {
- /* the osfd's to redirect stdin, stdout, and stderr to */
- int in_osfd = -1, out_osfd = -1, err_osfd = -1;
-
- if (attr->stdinFd
- && attr->stdinFd->secret->md.osfd != 0) {
- in_osfd = attr->stdinFd->secret->md.osfd;
- if (dup2(in_osfd, 0) != 0) {
- _exit(1); /* failed */
- }
- flags = fcntl(0, F_GETFL, 0);
- if (flags & O_NONBLOCK) {
- fcntl(0, F_SETFL, flags & ~O_NONBLOCK);
- }
- }
- if (attr->stdoutFd
- && attr->stdoutFd->secret->md.osfd != 1) {
- out_osfd = attr->stdoutFd->secret->md.osfd;
- if (dup2(out_osfd, 1) != 1) {
- _exit(1); /* failed */
- }
- flags = fcntl(1, F_GETFL, 0);
- if (flags & O_NONBLOCK) {
- fcntl(1, F_SETFL, flags & ~O_NONBLOCK);
- }
- }
- if (attr->stderrFd
- && attr->stderrFd->secret->md.osfd != 2) {
- err_osfd = attr->stderrFd->secret->md.osfd;
- if (dup2(err_osfd, 2) != 2) {
- _exit(1); /* failed */
- }
- flags = fcntl(2, F_GETFL, 0);
- if (flags & O_NONBLOCK) {
- fcntl(2, F_SETFL, flags & ~O_NONBLOCK);
- }
- }
- if (in_osfd != -1) {
- close(in_osfd);
- }
- if (out_osfd != -1 && out_osfd != in_osfd) {
- close(out_osfd);
- }
- if (err_osfd != -1 && err_osfd != in_osfd
- && err_osfd != out_osfd) {
- close(err_osfd);
- }
- if (attr->currentDirectory) {
- if (chdir(attr->currentDirectory) < 0) {
- _exit(1); /* failed */
- }
- }
- }
-
- if (childEnvp) {
- (void)execve(path, argv, childEnvp);
- } else {
- /* Inherit the environment of the parent. */
- (void)execv(path, argv);
- }
- /* Whoops! It returned. That's a bad sign. */
- _exit(1);
- }
-
- if (newEnvp) {
- PR_DELETE(newEnvp);
- }
-
- return process;
-}
-
-PRStatus
-_MD_detach_process (PRProcess *process)
-{
- /* If we kept a process table like unix does,
- * we'd remove the entry here.
- * Since we dont', just delete the process variable
- */
- PR_DELETE(process);
- return PR_SUCCESS;
-}
-
-PRStatus
-_MD_wait_process (PRProcess *process, PRInt32 *exitCode)
-{
- PRStatus retVal = PR_SUCCESS;
- int ret, status;
-
- /* Ignore interruptions */
- do {
- ret = waitpid(process->md.pid, &status, 0);
- } while (ret == -1 && errno == EINTR);
-
- /*
- * waitpid() cannot return 0 because we did not invoke it
- * with the WNOHANG option.
- */
- PR_ASSERT(0 != ret);
-
- if (ret < 0) {
- PR_SetError(PR_UNKNOWN_ERROR, _MD_ERRNO());
- return PR_FAILURE;
- }
-
- /* If child process exited normally, return child exit code */
- if (WIFEXITED(status)) {
- *exitCode = WEXITSTATUS(status);
- } else {
- PR_ASSERT(WIFSIGNALED(status));
- *exitCode = _PR_SIGNALED_EXITSTATUS;
- }
-
- PR_DELETE(process);
- return PR_SUCCESS;
-}
-
-PRStatus
-_MD_kill_process (PRProcess *process)
-{
- PRErrorCode prerror;
- PRInt32 oserror;
-
- if (kill(process->md.pid, SIGKILL) == 0) {
- return PR_SUCCESS;
- }
- oserror = errno;
- switch (oserror) {
- case EPERM:
- prerror = PR_NO_ACCESS_RIGHTS_ERROR;
- break;
- case ESRCH:
- prerror = PR_INVALID_ARGUMENT_ERROR;
- break;
- default:
- prerror = PR_UNKNOWN_ERROR;
- break;
- }
- PR_SetError(prerror, oserror);
- return PR_FAILURE;
-}
diff --git a/nsprpub/pr/src/md/beos/brng.c b/nsprpub/pr/src/md/beos/brng.c
deleted file mode 100644
index 18a3bbf1e..000000000
--- a/nsprpub/pr/src/md/beos/brng.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-
-#include <stdio.h>
-#include <string.h>
-#include <signal.h>
-#include <unistd.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <assert.h>
-#include <time.h>
-#include "primpl.h"
-
-extern PRSize _PR_MD_GetRandomNoise( void *buf, PRSize size )
-{
- struct timeval tv;
- int n = 0;
- int s;
-
- GETTIMEOFDAY(&tv);
-
- if ( size > 0 ) {
- s = _pr_CopyLowBits((char*)buf+n, size, &tv.tv_usec, sizeof(tv.tv_usec));
- size -= s;
- n += s;
- }
- if ( size > 0 ) {
- s = _pr_CopyLowBits((char*)buf+n, size, &tv.tv_sec, sizeof(tv.tv_usec));
- size -= s;
- n += s;
- }
-
- return n;
-} /* end _PR_MD_GetRandomNoise() */
diff --git a/nsprpub/pr/src/md/beos/bseg.c b/nsprpub/pr/src/md/beos/bseg.c
deleted file mode 100644
index e7bb9b3d7..000000000
--- a/nsprpub/pr/src/md/beos/bseg.c
+++ /dev/null
@@ -1,22 +0,0 @@
-/* -*- Mode: C++; c-basic-offset: 4 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "primpl.h"
-
-PR_IMPLEMENT(void)
- _MD_init_segs (void)
-{
-}
-
-PR_IMPLEMENT(PRStatus)
- _MD_alloc_segment (PRSegment *seg, PRUint32 size, void *vaddr)
-{
- return PR_NOT_IMPLEMENTED_ERROR;
-}
-
-PR_IMPLEMENT(void)
- _MD_free_segment (PRSegment *seg)
-{
-}
diff --git a/nsprpub/pr/src/md/beos/bsrcs.mk b/nsprpub/pr/src/md/beos/bsrcs.mk
deleted file mode 100644
index 94424537f..000000000
--- a/nsprpub/pr/src/md/beos/bsrcs.mk
+++ /dev/null
@@ -1,22 +0,0 @@
-#
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-
-# this file lists the source files to be compiled (used in Makefile) and
-# then enumerated as object files (in objs.mk) for inclusion in the NSPR
-# shared library
-
-MDCSRCS = \
- beos.c \
- beos_errors.c \
- bfile.c \
- bmisc.c \
- bnet.c \
- bproc.c \
- brng.c \
- bseg.c \
- btime.c \
- bmmap.c \
- $(NULL)
diff --git a/nsprpub/pr/src/md/beos/btime.c b/nsprpub/pr/src/md/beos/btime.c
deleted file mode 100644
index b6e02fc7d..000000000
--- a/nsprpub/pr/src/md/beos/btime.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/* -*- Mode: C++; c-basic-offset: 4 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "primpl.h"
-#include <kernel/OS.h>
-
-static bigtime_t start;
-
-PRTime
-_MD_now (void)
-{
- return (PRTime)real_time_clock_usecs();
-}
-
-void
-_MD_interval_init (void)
-{
- /* grab the base interval time */
- start = real_time_clock_usecs();
-}
-
-PRIntervalTime
-_MD_get_interval (void)
-{
- return( (PRIntervalTime) real_time_clock_usecs() / 10 );
-
-#if 0
- /* return the number of tens of microseconds that have elapsed since
- we were initialized */
- bigtime_t now = real_time_clock_usecs();
- now -= start;
- now /= 10;
- return (PRIntervalTime)now;
-#endif
-}
-
-PRIntervalTime
-_MD_interval_per_sec (void)
-{
- return 100000L;
-}
diff --git a/nsprpub/pr/src/md/beos/objs.mk b/nsprpub/pr/src/md/beos/objs.mk
deleted file mode 100644
index 8727ee0e6..000000000
--- a/nsprpub/pr/src/md/beos/objs.mk
+++ /dev/null
@@ -1,11 +0,0 @@
-#
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-# This makefile appends to the variable OBJS the platform-dependent
-# object modules that will be part of the nspr20 library.
-
-include $(srcdir)/md/beos/bsrcs.mk
-
-OBJS += $(MDCSRCS:%.c=md/beos/$(OBJDIR)/%.$(OBJ_SUFFIX))
diff --git a/nsprpub/pr/src/md/os2/os2_errors.c b/nsprpub/pr/src/md/os2/os2_errors.c
index 98f5cde59..dfcca6108 100644
--- a/nsprpub/pr/src/md/os2/os2_errors.c
+++ b/nsprpub/pr/src/md/os2/os2_errors.c
@@ -8,152 +8,152 @@
void _MD_os2_map_default_error(PRInt32 err)
{
- switch (err) {
- case EWOULDBLOCK:
- PR_SetError(PR_WOULD_BLOCK_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
- case EMSGSIZE:
- case EINVAL:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case ENOBUFS:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case ECONNREFUSED:
- PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
- break;
- case EISCONN:
- PR_SetError(PR_IS_CONNECTED_ERROR, err);
- break;
+ switch (err) {
+ case EWOULDBLOCK:
+ PR_SetError(PR_WOULD_BLOCK_ERROR, err);
+ break;
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
+ case EMSGSIZE:
+ case EINVAL:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
+ break;
+ case ENOBUFS:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ case ECONNREFUSED:
+ PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
+ break;
+ case EISCONN:
+ PR_SetError(PR_IS_CONNECTED_ERROR, err);
+ break;
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- case ERROR_NETNAME_DELETED:
- PR_SetError(PR_CONNECT_RESET_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ case ERROR_NETNAME_DELETED:
+ PR_SetError(PR_CONNECT_RESET_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_opendir_error(PRInt32 err)
{
- switch (err) {
- case ERROR_FILE_NOT_FOUND:
- case ERROR_PATH_NOT_FOUND:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ERROR_ACCESS_DENIED:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ERROR_INVALID_ADDRESS:
- case ERROR_INVALID_ACCESS:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ERROR_INVALID_NAME:
- case ERROR_INVALID_PARAMETER:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case ERROR_TOO_MANY_OPEN_FILES:
- case ERROR_NOT_DOS_DISK:
- case ERROR_NOT_READY:
- case ERROR_OPEN_FAILED:
- case ERROR_PATH_BUSY:
- case ERROR_CANNOT_MAKE:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ERROR_DRIVE_LOCKED:
- case ERROR_DEVICE_IN_USE:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- case ERROR_FILENAME_EXCED_RANGE:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_SHARING_BUFFER_EXCEEDED:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case ERROR_FILE_NOT_FOUND:
+ case ERROR_PATH_NOT_FOUND:
+ PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
+ break;
+ case ERROR_ACCESS_DENIED:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case ERROR_INVALID_ADDRESS:
+ case ERROR_INVALID_ACCESS:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
+ case ERROR_INVALID_NAME:
+ case ERROR_INVALID_PARAMETER:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
+ break;
+ case ERROR_TOO_MANY_OPEN_FILES:
+ case ERROR_NOT_DOS_DISK:
+ case ERROR_NOT_READY:
+ case ERROR_OPEN_FAILED:
+ case ERROR_PATH_BUSY:
+ case ERROR_CANNOT_MAKE:
+ PR_SetError(PR_IO_ERROR, err);
+ break;
+ case ERROR_DRIVE_LOCKED:
+ case ERROR_DEVICE_IN_USE:
+ PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
+ break;
+ case ERROR_FILENAME_EXCED_RANGE:
+ PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_SHARING_BUFFER_EXCEEDED:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_closedir_error(PRInt32 err)
{
- switch (err) {
- case ERROR_FILE_NOT_FOUND:
- case ERROR_ACCESS_DENIED:
- case ERROR_INVALID_HANDLE:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case ERROR_FILE_NOT_FOUND:
+ case ERROR_ACCESS_DENIED:
+ case ERROR_INVALID_HANDLE:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_readdir_error(PRInt32 err)
{
- switch (err) {
- case ERROR_NO_MORE_FILES:
- PR_SetError(PR_NO_MORE_FILES_ERROR, err);
- break;
- case ERROR_FILE_NOT_FOUND:
- case ERROR_INVALID_HANDLE:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ERROR_INVALID_ADDRESS:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ERROR_NOT_DOS_DISK:
- case ERROR_LOCK_VIOLATION:
- case ERROR_BROKEN_PIPE:
- case ERROR_NOT_READY:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_MORE_DATA:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case ERROR_NO_MORE_FILES:
+ PR_SetError(PR_NO_MORE_FILES_ERROR, err);
+ break;
+ case ERROR_FILE_NOT_FOUND:
+ case ERROR_INVALID_HANDLE:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ERROR_INVALID_ADDRESS:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
+ case ERROR_NOT_DOS_DISK:
+ case ERROR_LOCK_VIOLATION:
+ case ERROR_BROKEN_PIPE:
+ case ERROR_NOT_READY:
+ PR_SetError(PR_IO_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_MORE_DATA:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_delete_error(PRInt32 err)
{
- switch (err) {
- case ERROR_FILE_NOT_FOUND:
- case ERROR_PATH_NOT_FOUND:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ERROR_ACCESS_DENIED:
- case ERROR_WRITE_PROTECT:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ERROR_INVALID_ADDRESS:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ERROR_DRIVE_LOCKED:
- case ERROR_LOCKED:
- case ERROR_SHARING_VIOLATION:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case ERROR_FILE_NOT_FOUND:
+ case ERROR_PATH_NOT_FOUND:
+ PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
+ break;
+ case ERROR_ACCESS_DENIED:
+ case ERROR_WRITE_PROTECT:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case ERROR_INVALID_ADDRESS:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
+ case ERROR_DRIVE_LOCKED:
+ case ERROR_LOCKED:
+ case ERROR_SHARING_VIOLATION:
+ PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
/* The error code for stat() is in errno. */
@@ -173,72 +173,72 @@ void _MD_os2_map_stat_error(PRInt32 err)
void _MD_os2_map_fstat_error(PRInt32 err)
{
- switch (err) {
- case ERROR_ACCESS_DENIED:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ERROR_INVALID_HANDLE:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ERROR_INVALID_ADDRESS:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ERROR_NOT_READY:
- case ERROR_PATH_BUSY:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_MORE_DATA:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case ERROR_DRIVE_LOCKED:
- case ERROR_LOCKED:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case ERROR_ACCESS_DENIED:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case ERROR_INVALID_HANDLE:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ERROR_INVALID_ADDRESS:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
+ case ERROR_NOT_READY:
+ case ERROR_PATH_BUSY:
+ PR_SetError(PR_IO_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_MORE_DATA:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ case ERROR_DRIVE_LOCKED:
+ case ERROR_LOCKED:
+ PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_rename_error(PRInt32 err)
{
- switch (err) {
- case ERROR_FILE_NOT_FOUND:
- case ERROR_PATH_NOT_FOUND:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ERROR_ACCESS_DENIED:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ERROR_INVALID_ADDRESS:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ERROR_INVALID_NAME:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case ERROR_NOT_READY:
- case ERROR_PATH_BUSY:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ERROR_DRIVE_LOCKED:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- case ERROR_FILENAME_EXCED_RANGE:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_MORE_DATA:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case ERROR_ALREADY_EXISTS:
- case ERROR_FILE_EXISTS:
- PR_SetError(PR_FILE_EXISTS_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case ERROR_FILE_NOT_FOUND:
+ case ERROR_PATH_NOT_FOUND:
+ PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
+ break;
+ case ERROR_ACCESS_DENIED:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case ERROR_INVALID_ADDRESS:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
+ case ERROR_INVALID_NAME:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
+ break;
+ case ERROR_NOT_READY:
+ case ERROR_PATH_BUSY:
+ PR_SetError(PR_IO_ERROR, err);
+ break;
+ case ERROR_DRIVE_LOCKED:
+ PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
+ break;
+ case ERROR_FILENAME_EXCED_RANGE:
+ PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_MORE_DATA:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ case ERROR_ALREADY_EXISTS:
+ case ERROR_FILE_EXISTS:
+ PR_SetError(PR_FILE_EXISTS_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
/* The error code for access() is in errno. */
@@ -258,458 +258,458 @@ void _MD_os2_map_access_error(PRInt32 err)
void _MD_os2_map_mkdir_error(PRInt32 err)
{
- switch (err) {
- case ERROR_ALREADY_EXISTS:
- case ERROR_FILE_EXISTS:
- PR_SetError(PR_FILE_EXISTS_ERROR, err);
- break;
- case ERROR_FILE_NOT_FOUND:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ERROR_ACCESS_DENIED:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ERROR_INVALID_ADDRESS:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ERROR_INVALID_NAME:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case ERROR_NOT_READY:
- case ERROR_PATH_BUSY:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ERROR_DRIVE_LOCKED:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- case ERROR_FILENAME_EXCED_RANGE:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case ERROR_TOO_MANY_OPEN_FILES:
- PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
- break;
- case ERROR_PATH_NOT_FOUND:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_MORE_DATA:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case ERROR_DISK_FULL:
- case ERROR_HANDLE_DISK_FULL:
- PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
- break;
- case ERROR_WRITE_PROTECT:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case ERROR_ALREADY_EXISTS:
+ case ERROR_FILE_EXISTS:
+ PR_SetError(PR_FILE_EXISTS_ERROR, err);
+ break;
+ case ERROR_FILE_NOT_FOUND:
+ PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
+ break;
+ case ERROR_ACCESS_DENIED:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case ERROR_INVALID_ADDRESS:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
+ case ERROR_INVALID_NAME:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
+ break;
+ case ERROR_NOT_READY:
+ case ERROR_PATH_BUSY:
+ PR_SetError(PR_IO_ERROR, err);
+ break;
+ case ERROR_DRIVE_LOCKED:
+ PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
+ break;
+ case ERROR_FILENAME_EXCED_RANGE:
+ PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
+ break;
+ case ERROR_TOO_MANY_OPEN_FILES:
+ PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
+ break;
+ case ERROR_PATH_NOT_FOUND:
+ PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_MORE_DATA:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ case ERROR_DISK_FULL:
+ case ERROR_HANDLE_DISK_FULL:
+ PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
+ break;
+ case ERROR_WRITE_PROTECT:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_rmdir_error(PRInt32 err)
{
- switch (err) {
- case ERROR_FILE_NOT_FOUND:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ERROR_ACCESS_DENIED:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ERROR_INVALID_ADDRESS:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ERROR_INVALID_NAME:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case ERROR_NOT_READY:
- case ERROR_PATH_BUSY:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ERROR_DRIVE_LOCKED:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- case ERROR_FILENAME_EXCED_RANGE:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case ERROR_TOO_MANY_OPEN_FILES:
- PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
- break;
- case ERROR_PATH_NOT_FOUND:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_MORE_DATA:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case ERROR_WRITE_PROTECT:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case ERROR_FILE_NOT_FOUND:
+ PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
+ break;
+ case ERROR_ACCESS_DENIED:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case ERROR_INVALID_ADDRESS:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
+ case ERROR_INVALID_NAME:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
+ break;
+ case ERROR_NOT_READY:
+ case ERROR_PATH_BUSY:
+ PR_SetError(PR_IO_ERROR, err);
+ break;
+ case ERROR_DRIVE_LOCKED:
+ PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
+ break;
+ case ERROR_FILENAME_EXCED_RANGE:
+ PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
+ break;
+ case ERROR_TOO_MANY_OPEN_FILES:
+ PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
+ break;
+ case ERROR_PATH_NOT_FOUND:
+ PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_MORE_DATA:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ case ERROR_WRITE_PROTECT:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_read_error(PRInt32 err)
{
- switch (err) {
- case ERROR_ACCESS_DENIED:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ERROR_INVALID_HANDLE:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ERROR_INVALID_ADDRESS:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ERROR_NOT_READY:
- case ERROR_PATH_BUSY:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_MORE_DATA:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case ERROR_DRIVE_LOCKED:
- case ERROR_LOCKED:
- case ERROR_SHARING_VIOLATION:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- case ERROR_NETNAME_DELETED:
- PR_SetError(PR_CONNECT_RESET_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
+ switch (err) {
+ case ERROR_ACCESS_DENIED:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case ERROR_INVALID_HANDLE:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ERROR_INVALID_ADDRESS:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
+ case ERROR_NOT_READY:
+ case ERROR_PATH_BUSY:
+ PR_SetError(PR_IO_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_MORE_DATA:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ case ERROR_DRIVE_LOCKED:
+ case ERROR_LOCKED:
+ case ERROR_SHARING_VIOLATION:
+ PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
+ break;
+ case ERROR_NETNAME_DELETED:
+ PR_SetError(PR_CONNECT_RESET_ERROR, err);
+ break;
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_transmitfile_error(PRInt32 err)
{
- switch (err) {
- case ERROR_ACCESS_DENIED:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ERROR_INVALID_HANDLE:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ERROR_INVALID_ADDRESS:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ERROR_NOT_READY:
- case ERROR_PATH_BUSY:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_MORE_DATA:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case ERROR_DRIVE_LOCKED:
- case ERROR_LOCKED:
- case ERROR_SHARING_VIOLATION:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- case ERROR_FILENAME_EXCED_RANGE:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case ERROR_TOO_MANY_OPEN_FILES:
- PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
- break;
- case ERROR_PATH_NOT_FOUND:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
+ switch (err) {
+ case ERROR_ACCESS_DENIED:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case ERROR_INVALID_HANDLE:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ERROR_INVALID_ADDRESS:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
+ case ERROR_NOT_READY:
+ case ERROR_PATH_BUSY:
+ PR_SetError(PR_IO_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_MORE_DATA:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ case ERROR_DRIVE_LOCKED:
+ case ERROR_LOCKED:
+ case ERROR_SHARING_VIOLATION:
+ PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
+ break;
+ case ERROR_FILENAME_EXCED_RANGE:
+ PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
+ break;
+ case ERROR_TOO_MANY_OPEN_FILES:
+ PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
+ break;
+ case ERROR_PATH_NOT_FOUND:
+ PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
+ break;
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_write_error(PRInt32 err)
{
- switch (err) {
- case ERROR_ACCESS_DENIED:
- case ERROR_WRITE_PROTECT:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ERROR_INVALID_HANDLE:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ERROR_INVALID_ADDRESS:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ERROR_NOT_READY:
- case ERROR_PATH_BUSY:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ERROR_DRIVE_LOCKED:
- case ERROR_LOCKED:
- case ERROR_SHARING_VIOLATION:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_MORE_DATA:
- case ERROR_DISK_FULL:
- case ERROR_HANDLE_DISK_FULL:
- case ENOSPC:
- PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
- break;
- case ERROR_NETNAME_DELETED:
- PR_SetError(PR_CONNECT_RESET_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
- case EMSGSIZE:
- case EINVAL:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case ENOBUFS:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case ECONNREFUSED:
- PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
- break;
- case EISCONN:
- PR_SetError(PR_IS_CONNECTED_ERROR, err);
- break;
+ switch (err) {
+ case ERROR_ACCESS_DENIED:
+ case ERROR_WRITE_PROTECT:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case ERROR_INVALID_HANDLE:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ERROR_INVALID_ADDRESS:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
+ case ERROR_NOT_READY:
+ case ERROR_PATH_BUSY:
+ PR_SetError(PR_IO_ERROR, err);
+ break;
+ case ERROR_DRIVE_LOCKED:
+ case ERROR_LOCKED:
+ case ERROR_SHARING_VIOLATION:
+ PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_MORE_DATA:
+ case ERROR_DISK_FULL:
+ case ERROR_HANDLE_DISK_FULL:
+ case ENOSPC:
+ PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
+ break;
+ case ERROR_NETNAME_DELETED:
+ PR_SetError(PR_CONNECT_RESET_ERROR, err);
+ break;
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
+ case EMSGSIZE:
+ case EINVAL:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
+ break;
+ case ENOBUFS:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ case ECONNREFUSED:
+ PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
+ break;
+ case EISCONN:
+ PR_SetError(PR_IS_CONNECTED_ERROR, err);
+ break;
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_lseek_error(PRInt32 err)
{
- switch (err) {
- case ERROR_INVALID_HANDLE:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ERROR_SEEK_ON_DEVICE:
- PR_SetError(PR_IO_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case ERROR_INVALID_HANDLE:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ERROR_SEEK_ON_DEVICE:
+ PR_SetError(PR_IO_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_fsync_error(PRInt32 err)
{
- switch (err) {
- case ERROR_ACCESS_DENIED:
- case ERROR_WRITE_PROTECT:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ERROR_INVALID_HANDLE:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_MORE_DATA:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case ERROR_DISK_FULL:
- case ERROR_HANDLE_DISK_FULL:
- PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case ERROR_ACCESS_DENIED:
+ case ERROR_WRITE_PROTECT:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case ERROR_INVALID_HANDLE:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_MORE_DATA:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ case ERROR_DISK_FULL:
+ case ERROR_HANDLE_DISK_FULL:
+ PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_close_error(PRInt32 err)
{
- switch (err) {
- case ERROR_INVALID_HANDLE:
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ERROR_NOT_READY:
- case ERROR_PATH_BUSY:
- PR_SetError(PR_IO_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case ERROR_INVALID_HANDLE:
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ERROR_NOT_READY:
+ case ERROR_PATH_BUSY:
+ PR_SetError(PR_IO_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_socket_error(PRInt32 err)
{
- switch (err) {
- case EPROTONOSUPPORT:
- PR_SetError(PR_PROTOCOL_NOT_SUPPORTED_ERROR, err);
- break;
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_MORE_DATA:
- case ENOBUFS:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case EPROTONOSUPPORT:
+ PR_SetError(PR_PROTOCOL_NOT_SUPPORTED_ERROR, err);
+ break;
+ case EACCES:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_MORE_DATA:
+ case ENOBUFS:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_recv_error(PRInt32 err)
{
- switch (err) {
- case EWOULDBLOCK:
- PR_SetError(PR_WOULD_BLOCK_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
+ switch (err) {
+ case EWOULDBLOCK:
+ PR_SetError(PR_WOULD_BLOCK_ERROR, err);
+ break;
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- case ERROR_NETNAME_DELETED:
- PR_SetError(PR_CONNECT_RESET_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ case ERROR_NETNAME_DELETED:
+ PR_SetError(PR_CONNECT_RESET_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_recvfrom_error(PRInt32 err)
{
- switch (err) {
- case EWOULDBLOCK:
- PR_SetError(PR_WOULD_BLOCK_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
+ switch (err) {
+ case EWOULDBLOCK:
+ PR_SetError(PR_WOULD_BLOCK_ERROR, err);
+ break;
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- case ERROR_NETNAME_DELETED:
- PR_SetError(PR_CONNECT_RESET_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ case ERROR_NETNAME_DELETED:
+ PR_SetError(PR_CONNECT_RESET_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_send_error(PRInt32 err)
{
- switch (err) {
- case EWOULDBLOCK:
- PR_SetError(PR_WOULD_BLOCK_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
- case EMSGSIZE:
- case EINVAL:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case ENOBUFS:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case ECONNREFUSED:
- PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
- break;
- case EISCONN:
- PR_SetError(PR_IS_CONNECTED_ERROR, err);
- break;
+ switch (err) {
+ case EWOULDBLOCK:
+ PR_SetError(PR_WOULD_BLOCK_ERROR, err);
+ break;
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
+ case EMSGSIZE:
+ case EINVAL:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
+ break;
+ case ENOBUFS:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ case ECONNREFUSED:
+ PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
+ break;
+ case EISCONN:
+ PR_SetError(PR_IS_CONNECTED_ERROR, err);
+ break;
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- case ERROR_NETNAME_DELETED:
- PR_SetError(PR_CONNECT_RESET_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ case ERROR_NETNAME_DELETED:
+ PR_SetError(PR_CONNECT_RESET_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_sendto_error(PRInt32 err)
{
- _MD_os2_map_default_error(err);
+ _MD_os2_map_default_error(err);
}
void _MD_os2_map_writev_error(int err)
{
- _MD_os2_map_default_error(err);
+ _MD_os2_map_default_error(err);
}
void _MD_os2_map_accept_error(PRInt32 err)
{
- _MD_os2_map_default_error(err);
+ _MD_os2_map_default_error(err);
}
void _MD_os2_map_acceptex_error(PRInt32 err)
{
- switch (err) {
- case ERROR_INVALID_HANDLE:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ERROR_INVALID_ADDRESS:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_MORE_DATA:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case ERROR_INVALID_HANDLE:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ERROR_INVALID_ADDRESS:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_MORE_DATA:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
/*
@@ -729,315 +729,315 @@ int _MD_os2_get_nonblocking_connect_error(int osfd)
void _MD_os2_map_connect_error(PRInt32 err)
{
- switch (err) {
- case EWOULDBLOCK:
- PR_SetError(PR_WOULD_BLOCK_ERROR, err);
- break;
+ switch (err) {
+ case EWOULDBLOCK:
+ PR_SetError(PR_WOULD_BLOCK_ERROR, err);
+ break;
case EINPROGRESS:
- PR_SetError(PR_IN_PROGRESS_ERROR, err);
- break;
- case EALREADY:
- case EINVAL:
- PR_SetError(PR_ALREADY_INITIATED_ERROR, err);
- break;
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case EADDRNOTAVAIL:
- PR_SetError(PR_ADDRESS_NOT_AVAILABLE_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
- case EAFNOSUPPORT:
- PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
- break;
- case ETIMEDOUT:
- PR_SetError(PR_IO_TIMEOUT_ERROR, err);
- break;
- case ECONNREFUSED:
- PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
- break;
- case ENETUNREACH:
- PR_SetError(PR_NETWORK_UNREACHABLE_ERROR, err);
- break;
- case EADDRINUSE:
- PR_SetError(PR_ADDRESS_IN_USE_ERROR, err);
- break;
- case EISCONN:
- PR_SetError(PR_IS_CONNECTED_ERROR, err);
- break;
+ PR_SetError(PR_IN_PROGRESS_ERROR, err);
+ break;
+ case EALREADY:
+ case EINVAL:
+ PR_SetError(PR_ALREADY_INITIATED_ERROR, err);
+ break;
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case EADDRNOTAVAIL:
+ PR_SetError(PR_ADDRESS_NOT_AVAILABLE_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
+ case EAFNOSUPPORT:
+ PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
+ break;
+ case ETIMEDOUT:
+ PR_SetError(PR_IO_TIMEOUT_ERROR, err);
+ break;
+ case ECONNREFUSED:
+ PR_SetError(PR_CONNECT_REFUSED_ERROR, err);
+ break;
+ case ENETUNREACH:
+ PR_SetError(PR_NETWORK_UNREACHABLE_ERROR, err);
+ break;
+ case EADDRINUSE:
+ PR_SetError(PR_ADDRESS_IN_USE_ERROR, err);
+ break;
+ case EISCONN:
+ PR_SetError(PR_IS_CONNECTED_ERROR, err);
+ break;
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_bind_error(PRInt32 err)
{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
+ switch (err) {
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- case EADDRNOTAVAIL:
- PR_SetError(PR_ADDRESS_NOT_AVAILABLE_ERROR, err);
- break;
- case EADDRINUSE:
- PR_SetError(PR_ADDRESS_IN_USE_ERROR, err);
- break;
- case EACCES:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case EINVAL:
- PR_SetError(PR_SOCKET_ADDRESS_IS_BOUND_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ case EADDRNOTAVAIL:
+ PR_SetError(PR_ADDRESS_NOT_AVAILABLE_ERROR, err);
+ break;
+ case EADDRINUSE:
+ PR_SetError(PR_ADDRESS_IN_USE_ERROR, err);
+ break;
+ case EACCES:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case EINVAL:
+ PR_SetError(PR_SOCKET_ADDRESS_IS_BOUND_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_listen_error(PRInt32 err)
{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
- case EOPNOTSUPP:
- PR_SetError(PR_NOT_TCP_SOCKET_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
+ case EOPNOTSUPP:
+ PR_SetError(PR_NOT_TCP_SOCKET_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_shutdown_error(PRInt32 err)
{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
- case ENOTCONN:
- PR_SetError(PR_NOT_CONNECTED_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
+ case ENOTCONN:
+ PR_SetError(PR_NOT_CONNECTED_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_socketpair_error(PRInt32 err)
{
- switch (err) {
- case ENOMEM:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case EAFNOSUPPORT:
- PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
- break;
- case EPROTONOSUPPORT:
- PR_SetError(PR_PROTOCOL_NOT_SUPPORTED_ERROR, err);
- break;
- case EOPNOTSUPP:
- PR_SetError(PR_NOT_TCP_SOCKET_ERROR, err);
- break;
- case EPROTOTYPE:
- PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
- break;
- default:
- _MD_os2_map_default_error(err);
- return;
- }
+ switch (err) {
+ case ENOMEM:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ case EAFNOSUPPORT:
+ PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
+ break;
+ case EPROTONOSUPPORT:
+ PR_SetError(PR_PROTOCOL_NOT_SUPPORTED_ERROR, err);
+ break;
+ case EOPNOTSUPP:
+ PR_SetError(PR_NOT_TCP_SOCKET_ERROR, err);
+ break;
+ case EPROTOTYPE:
+ PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, err);
+ break;
+ default:
+ _MD_os2_map_default_error(err);
+ return;
+ }
}
void _MD_os2_map_getsockname_error(PRInt32 err)
{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
+ switch (err) {
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- case ENOBUFS:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ case ENOBUFS:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_getpeername_error(PRInt32 err)
{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
- case ENOTCONN:
- PR_SetError(PR_NOT_CONNECTED_ERROR, err);
- break;
+ switch (err) {
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
+ case ENOTCONN:
+ PR_SetError(PR_NOT_CONNECTED_ERROR, err);
+ break;
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- case ENOBUFS:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ case ENOBUFS:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_getsockopt_error(PRInt32 err)
{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
- case ENOPROTOOPT:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
+ switch (err) {
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
+ case ENOPROTOOPT:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
+ break;
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- case EINVAL:
- PR_SetError(PR_BUFFER_OVERFLOW_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ case EINVAL:
+ PR_SetError(PR_BUFFER_OVERFLOW_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_setsockopt_error(PRInt32 err)
{
- switch (err) {
- case EBADF:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ENOTSOCK:
- PR_SetError(PR_NOT_SOCKET_ERROR, err);
- break;
- case ENOPROTOOPT:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
+ switch (err) {
+ case EBADF:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ENOTSOCK:
+ PR_SetError(PR_NOT_SOCKET_ERROR, err);
+ break;
+ case ENOPROTOOPT:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
+ break;
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- case EINVAL:
- PR_SetError(PR_BUFFER_OVERFLOW_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ case EINVAL:
+ PR_SetError(PR_BUFFER_OVERFLOW_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_open_error(PRInt32 err)
{
- switch (err) {
- case ERROR_ALREADY_EXISTS:
- case ERROR_FILE_EXISTS:
- PR_SetError(PR_FILE_EXISTS_ERROR, err);
- break;
- case ERROR_FILE_NOT_FOUND:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ERROR_ACCESS_DENIED:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ERROR_INVALID_ADDRESS:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ERROR_INVALID_NAME:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
- break;
- case ERROR_NOT_READY:
- case ERROR_OPEN_FAILED:
- case ERROR_PATH_BUSY:
- PR_SetError(PR_IO_ERROR, err);
- break;
- case ERROR_DRIVE_LOCKED:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- case ERROR_FILENAME_EXCED_RANGE:
- PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
- break;
- case ERROR_TOO_MANY_OPEN_FILES:
- PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
- break;
- case ERROR_PATH_NOT_FOUND:
- PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_MORE_DATA:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- case ERROR_DISK_FULL:
- case ERROR_HANDLE_DISK_FULL:
- PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
- break;
- case ERROR_WRITE_PROTECT:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
- }
+ switch (err) {
+ case ERROR_ALREADY_EXISTS:
+ case ERROR_FILE_EXISTS:
+ PR_SetError(PR_FILE_EXISTS_ERROR, err);
+ break;
+ case ERROR_FILE_NOT_FOUND:
+ PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
+ break;
+ case ERROR_ACCESS_DENIED:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case ERROR_INVALID_ADDRESS:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
+ case ERROR_INVALID_NAME:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, err);
+ break;
+ case ERROR_NOT_READY:
+ case ERROR_OPEN_FAILED:
+ case ERROR_PATH_BUSY:
+ PR_SetError(PR_IO_ERROR, err);
+ break;
+ case ERROR_DRIVE_LOCKED:
+ PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
+ break;
+ case ERROR_FILENAME_EXCED_RANGE:
+ PR_SetError(PR_NAME_TOO_LONG_ERROR, err);
+ break;
+ case ERROR_TOO_MANY_OPEN_FILES:
+ PR_SetError(PR_SYS_DESC_TABLE_FULL_ERROR, err);
+ break;
+ case ERROR_PATH_NOT_FOUND:
+ PR_SetError(PR_FILE_NOT_FOUND_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_MORE_DATA:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ case ERROR_DISK_FULL:
+ case ERROR_HANDLE_DISK_FULL:
+ PR_SetError(PR_NO_DEVICE_SPACE_ERROR, err);
+ break;
+ case ERROR_WRITE_PROTECT:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
+ }
}
void _MD_os2_map_gethostname_error(PRInt32 err)
{
switch (err) {
#ifdef SOCEFAULT
- case SOCEFAULT:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
+ case SOCEFAULT:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
#endif
- case ENETDOWN:
- case EINPROGRESS:
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
+ case ENETDOWN:
+ case EINPROGRESS:
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
}
}
@@ -1070,26 +1070,26 @@ void _MD_os2_map_select_error(PRInt32 err)
void _MD_os2_map_lockf_error(PRInt32 err)
{
switch (err) {
- case ERROR_ACCESS_DENIED:
- PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
- break;
- case ERROR_INVALID_HANDLE:
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
- break;
- case ERROR_INVALID_ADDRESS:
- PR_SetError(PR_ACCESS_FAULT_ERROR, err);
- break;
- case ERROR_DRIVE_LOCKED:
- case ERROR_LOCKED:
- case ERROR_SHARING_VIOLATION:
- PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
- break;
- case ERROR_NOT_ENOUGH_MEMORY:
- case ERROR_MORE_DATA:
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
- break;
- default:
- PR_SetError(PR_UNKNOWN_ERROR, err);
- break;
+ case ERROR_ACCESS_DENIED:
+ PR_SetError(PR_NO_ACCESS_RIGHTS_ERROR, err);
+ break;
+ case ERROR_INVALID_HANDLE:
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, err);
+ break;
+ case ERROR_INVALID_ADDRESS:
+ PR_SetError(PR_ACCESS_FAULT_ERROR, err);
+ break;
+ case ERROR_DRIVE_LOCKED:
+ case ERROR_LOCKED:
+ case ERROR_SHARING_VIOLATION:
+ PR_SetError(PR_FILE_IS_LOCKED_ERROR, err);
+ break;
+ case ERROR_NOT_ENOUGH_MEMORY:
+ case ERROR_MORE_DATA:
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, err);
+ break;
+ default:
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ break;
}
}
diff --git a/nsprpub/pr/src/md/os2/os2cv.c b/nsprpub/pr/src/md/os2/os2cv.c
index 2c424c50b..91e85c0eb 100644
--- a/nsprpub/pr/src/md/os2/os2cv.c
+++ b/nsprpub/pr/src/md/os2/os2cv.c
@@ -16,7 +16,7 @@
* until right after we unlock the lock. This way the awakened threads
* have a better chance to reaquire the lock.
*/
-
+
#include "primpl.h"
/*
@@ -30,7 +30,7 @@ static void
AddThreadToCVWaitQueueInternal(PRThread *thred, struct _MDCVar *cv)
{
PR_ASSERT((cv->waitTail != NULL && cv->waitHead != NULL)
- || (cv->waitTail == NULL && cv->waitHead == NULL));
+ || (cv->waitTail == NULL && cv->waitHead == NULL));
cv->nwait += 1;
thred->md.inCVWaitQueue = PR_TRUE;
thred->md.next = NULL;
@@ -78,7 +78,7 @@ md_UnlockAndPostNotifies(
lock->notified.link = NULL;
#endif
- /*
+ /*
* Figure out how many threads we need to wake up.
*/
notified = &post; /* this is where we start */
@@ -87,7 +87,7 @@ md_UnlockAndPostNotifies(
_MDCVar *cv = notified->cv[index].cv;
PRThread *thred;
int i;
-
+
/* Fast special case: no waiting threads */
if (cv->waitHead == NULL) {
notified->cv[index].notifyHead = NULL;
@@ -155,7 +155,9 @@ md_UnlockAndPostNotifies(
}
prev = notified;
notified = notified->link;
- if (&post != prev) PR_DELETE(prev);
+ if (&post != prev) {
+ PR_DELETE(prev);
+ }
} while (NULL != notified);
}
@@ -165,7 +167,7 @@ md_UnlockAndPostNotifies(
* MP systems don't contend for a lock that they can't have.
*/
static void md_PostNotifyToCvar(_MDCVar *cvar, _MDLock *lock,
- PRBool broadcast)
+ PRBool broadcast)
{
PRIntn index = 0;
_MDNotified *notified = &lock->notified;
@@ -182,7 +184,9 @@ static void md_PostNotifyToCvar(_MDCVar *cvar, _MDLock *lock,
}
}
/* if not full, enter new CV in this array */
- if (notified->length < _MD_CV_NOTIFIED_LENGTH) break;
+ if (notified->length < _MD_CV_NOTIFIED_LENGTH) {
+ break;
+ }
/* if there's no link, create an empty array and link it */
if (NULL == notified->link) {
@@ -215,7 +219,7 @@ _PR_MD_NEW_CV(_MDCVar *cv)
* when the PRCondVar structure is created.
*/
return 0;
-}
+}
void _PR_MD_FREE_CV(_MDCVar *cv)
{
@@ -232,7 +236,7 @@ _PR_MD_WAIT_CV(_MDCVar *cv, _MDLock *lock, PRIntervalTime timeout )
PRThread *thred = _PR_MD_CURRENT_THREAD();
ULONG rv, count;
ULONG msecs = (timeout == PR_INTERVAL_NO_TIMEOUT) ?
- SEM_INDEFINITE_WAIT : PR_IntervalToMilliseconds(timeout);
+ SEM_INDEFINITE_WAIT : PR_IntervalToMilliseconds(timeout);
/*
* If we have pending notifies, post them now.
@@ -241,7 +245,7 @@ _PR_MD_WAIT_CV(_MDCVar *cv, _MDLock *lock, PRIntervalTime timeout )
md_UnlockAndPostNotifies(lock, thred, cv);
} else {
AddThreadToCVWaitQueueInternal(thred, cv);
- DosReleaseMutexSem(lock->mutex);
+ DosReleaseMutexSem(lock->mutex);
}
/* Wait for notification or timeout; don't really care which */
@@ -256,42 +260,42 @@ _PR_MD_WAIT_CV(_MDCVar *cv, _MDLock *lock, PRIntervalTime timeout )
if(rv == ERROR_TIMEOUT)
{
- if (thred->md.inCVWaitQueue) {
- PR_ASSERT((cv->waitTail != NULL && cv->waitHead != NULL)
- || (cv->waitTail == NULL && cv->waitHead == NULL));
- cv->nwait -= 1;
- thred->md.inCVWaitQueue = PR_FALSE;
- if (cv->waitHead == thred) {
- cv->waitHead = thred->md.next;
- if (cv->waitHead == NULL) {
- cv->waitTail = NULL;
- } else {
- cv->waitHead->md.prev = NULL;
- }
- } else {
- PR_ASSERT(thred->md.prev != NULL);
- thred->md.prev->md.next = thred->md.next;
- if (thred->md.next != NULL) {
- thred->md.next->md.prev = thred->md.prev;
- } else {
- PR_ASSERT(cv->waitTail == thred);
- cv->waitTail = thred->md.prev;
- }
- }
- thred->md.next = thred->md.prev = NULL;
- } else {
- /*
- * This thread must have been notified, but the
- * SemRelease call happens after SemRequest
- * times out. Wait on the semaphore again to make it
- * non-signaled. We assume this wait won't take long.
- */
- rv = DosWaitEventSem(thred->md.blocked_sema, SEM_INDEFINITE_WAIT);
- if (rv == NO_ERROR) {
- DosResetEventSem(thred->md.blocked_sema, &count);
- }
- PR_ASSERT(rv == NO_ERROR);
- }
+ if (thred->md.inCVWaitQueue) {
+ PR_ASSERT((cv->waitTail != NULL && cv->waitHead != NULL)
+ || (cv->waitTail == NULL && cv->waitHead == NULL));
+ cv->nwait -= 1;
+ thred->md.inCVWaitQueue = PR_FALSE;
+ if (cv->waitHead == thred) {
+ cv->waitHead = thred->md.next;
+ if (cv->waitHead == NULL) {
+ cv->waitTail = NULL;
+ } else {
+ cv->waitHead->md.prev = NULL;
+ }
+ } else {
+ PR_ASSERT(thred->md.prev != NULL);
+ thred->md.prev->md.next = thred->md.next;
+ if (thred->md.next != NULL) {
+ thred->md.next->md.prev = thred->md.prev;
+ } else {
+ PR_ASSERT(cv->waitTail == thred);
+ cv->waitTail = thred->md.prev;
+ }
+ }
+ thred->md.next = thred->md.prev = NULL;
+ } else {
+ /*
+ * This thread must have been notified, but the
+ * SemRelease call happens after SemRequest
+ * times out. Wait on the semaphore again to make it
+ * non-signaled. We assume this wait won't take long.
+ */
+ rv = DosWaitEventSem(thred->md.blocked_sema, SEM_INDEFINITE_WAIT);
+ if (rv == NO_ERROR) {
+ DosResetEventSem(thred->md.blocked_sema, &count);
+ }
+ PR_ASSERT(rv == NO_ERROR);
+ }
}
PR_ASSERT(thred->md.inCVWaitQueue == PR_FALSE);
return;
diff --git a/nsprpub/pr/src/md/os2/os2gc.c b/nsprpub/pr/src/md/os2/os2gc.c
index 2bcbf7852..79b6de573 100644
--- a/nsprpub/pr/src/md/os2/os2gc.c
+++ b/nsprpub/pr/src/md/os2/os2gc.c
@@ -9,7 +9,7 @@
*/
#include "primpl.h"
-PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
+PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
CONTEXTRECORD context;
context.ContextFlags = CONTEXT_INTEGER;
@@ -34,7 +34,7 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
}
/* This function is not used right now, but is left as a reference.
- * If you ever need to get the fiberID from the currently running fiber,
+ * If you ever need to get the fiberID from the currently running fiber,
* this is it.
*/
void *
@@ -43,8 +43,8 @@ GetMyFiberID()
void *fiberData = 0;
/* A pointer to our tib entry is found at FS:[18]
- * At offset 10h is the fiberData pointer. The context of the
- * fiber is stored in there.
+ * At offset 10h is the fiberData pointer. The context of the
+ * fiber is stored in there.
*/
#ifdef HAVE_ASM
__asm {
@@ -53,6 +53,6 @@ GetMyFiberID()
mov [fiberData], EAX
}
#endif
-
+
return fiberData;
}
diff --git a/nsprpub/pr/src/md/os2/os2inrval.c b/nsprpub/pr/src/md/os2/os2inrval.c
index aff99e2ec..bd283f06d 100644
--- a/nsprpub/pr/src/md/os2/os2inrval.c
+++ b/nsprpub/pr/src/md/os2/os2inrval.c
@@ -14,7 +14,7 @@ static PRBool useHighResTimer = PR_FALSE;
PRIntervalTime _os2_ticksPerSec = -1;
PRIntn _os2_bitShift = 0;
PRInt32 _os2_highMask = 0;
-
+
void
_PR_MD_INTERVAL_INIT()
{
@@ -23,8 +23,9 @@ _PR_MD_INTERVAL_INIT()
APIRET rc;
if ((envp = getenv("NSPR_OS2_NO_HIRES_TIMER")) != NULL) {
- if (atoi(envp) == 1)
- return;
+ if (atoi(envp) == 1) {
+ return;
+ }
}
timerFreq = 0; /* OS/2 high-resolution timer frequency in Hz */
@@ -59,8 +60,8 @@ _PR_MD_GET_INTERVAL()
*/
top = timestamp.ulHi & _os2_highMask;
top = top << (32 - _os2_bitShift);
- timestamp.ulLo = timestamp.ulLo >> _os2_bitShift;
- timestamp.ulLo = timestamp.ulLo + top;
+ timestamp.ulLo = timestamp.ulLo >> _os2_bitShift;
+ timestamp.ulLo = timestamp.ulLo + top;
return (PRUint32)timestamp.ulLo;
} else {
ULONG msCount = -1;
diff --git a/nsprpub/pr/src/md/os2/os2io.c b/nsprpub/pr/src/md/os2/os2io.c
index 3c81ae346..639a0d388 100644
--- a/nsprpub/pr/src/md/os2/os2io.c
+++ b/nsprpub/pr/src/md/os2/os2io.c
@@ -23,16 +23,16 @@ struct _MDLock _pr_ioq_lock;
static PRBool isWSEB = PR_FALSE; /* whether we are using an OS/2 kernel that supports large files */
typedef APIRET (*DosOpenLType)(PSZ pszFileName, PHFILE pHf, PULONG pulAction,
- LONGLONG cbFile, ULONG ulAttribute,
- ULONG fsOpenFlags, ULONG fsOpenMode,
- PEAOP2 peaop2);
+ LONGLONG cbFile, ULONG ulAttribute,
+ ULONG fsOpenFlags, ULONG fsOpenMode,
+ PEAOP2 peaop2);
typedef APIRET (*DosSetFileLocksLType)(HFILE hFile, PFILELOCKL pflUnlock,
- PFILELOCKL pflLock, ULONG timeout,
- ULONG flags);
+ PFILELOCKL pflLock, ULONG timeout,
+ ULONG flags);
typedef APIRET (*DosSetFilePtrLType)(HFILE hFile, LONGLONG ib, ULONG method,
- PLONGLONG ibActual);
+ PLONGLONG ibActual);
DosOpenLType myDosOpenL;
DosSetFileLocksLType myDosSetFileLocksL;
@@ -45,7 +45,7 @@ _PR_MD_INIT_IO()
HMODULE module;
sock_init();
-
+
rc = DosLoadModule(NULL, 0, "DOSCALL1", &module);
if (rc != NO_ERROR)
{
@@ -76,10 +76,10 @@ _PR_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
ULONG count;
PRUint32 msecs = (ticks == PR_INTERVAL_NO_TIMEOUT) ?
- SEM_INDEFINITE_WAIT : PR_IntervalToMilliseconds(ticks);
+ SEM_INDEFINITE_WAIT : PR_IntervalToMilliseconds(ticks);
rv = DosWaitEventSem(thread->md.blocked_sema, msecs);
- DosResetEventSem(thread->md.blocked_sema, &count);
- switch(rv)
+ DosResetEventSem(thread->md.blocked_sema, &count);
+ switch(rv)
{
case NO_ERROR:
return PR_SUCCESS;
@@ -87,7 +87,7 @@ _PR_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
case ERROR_TIMEOUT:
_PR_THREAD_LOCK(thread);
if (thread->state == _PR_IO_WAIT) {
- ;
+ ;
} else {
if (thread->wait.cvar != NULL) {
thread->wait.cvar = NULL;
@@ -99,7 +99,7 @@ _PR_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
*/
_PR_THREAD_UNLOCK(thread);
rv = DosWaitEventSem(thread->md.blocked_sema, 0);
- DosResetEventSem(thread->md.blocked_sema, &count);
+ DosResetEventSem(thread->md.blocked_sema, &count);
PR_ASSERT(rv == NO_ERROR);
}
}
@@ -113,13 +113,15 @@ _PR_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
PRStatus
_PR_MD_WAKEUP_WAITER(PRThread *thread)
{
- if ( _PR_IS_NATIVE_THREAD(thread) )
+ if ( _PR_IS_NATIVE_THREAD(thread) )
{
- if (DosPostEventSem(thread->md.blocked_sema) != NO_ERROR)
+ if (DosPostEventSem(thread->md.blocked_sema) != NO_ERROR) {
return PR_FAILURE;
- else
- return PR_SUCCESS;
- }
+ }
+ else {
+ return PR_SUCCESS;
+ }
+ }
}
@@ -132,7 +134,7 @@ _PR_MD_WAKEUP_WAITER(PRThread *thread)
* The NSPR open flags (osflags) are translated into flags for OS/2
*
* Mode seems to be passed in as a unix style file permissions argument
- * as in 0666, in the case of opening the logFile.
+ * as in 0666, in the case of opening the logFile.
*
*/
PRInt32
@@ -149,7 +151,7 @@ _PR_MD_OPEN(const char *name, PRIntn osflags, int mode)
* All the pointer arguments (&file, &actionTaken and name) have to be in
* low memory for DosOpen to use them.
* The following moves name to low memory.
- */
+ */
if ((ULONG)name >= 0x20000000)
{
size_t len = strlen(name) + 1;
@@ -159,14 +161,19 @@ _PR_MD_OPEN(const char *name, PRIntn osflags, int mode)
}
#endif
- if (osflags & PR_SYNC) access |= OPEN_FLAGS_WRITE_THROUGH;
+ if (osflags & PR_SYNC) {
+ access |= OPEN_FLAGS_WRITE_THROUGH;
+ }
- if (osflags & PR_RDONLY)
+ if (osflags & PR_RDONLY) {
access |= OPEN_ACCESS_READONLY;
- else if (osflags & PR_WRONLY)
+ }
+ else if (osflags & PR_WRONLY) {
access |= OPEN_ACCESS_WRITEONLY;
- else if(osflags & PR_RDWR)
+ }
+ else if(osflags & PR_RDWR) {
access |= OPEN_ACCESS_READWRITE;
+ }
if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL )
{
@@ -174,41 +181,45 @@ _PR_MD_OPEN(const char *name, PRIntn osflags, int mode)
}
else if (osflags & PR_CREATE_FILE)
{
- if (osflags & PR_TRUNCATE)
+ if (osflags & PR_TRUNCATE) {
flags = OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_REPLACE_IF_EXISTS;
- else
+ }
+ else {
flags = OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS;
- }
+ }
+ }
else
{
- if (osflags & PR_TRUNCATE)
+ if (osflags & PR_TRUNCATE) {
flags = OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_REPLACE_IF_EXISTS;
- else
+ }
+ else {
flags = OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS;
+ }
}
do {
if (isWSEB)
{
- rc = myDosOpenL((char*)name,
- &file, /* file handle if successful */
- &actionTaken, /* reason for failure */
- 0, /* initial size of new file */
- FILE_NORMAL, /* file system attributes */
- flags, /* Open flags */
- access, /* Open mode and rights */
- 0); /* OS/2 Extended Attributes */
+ rc = myDosOpenL((char*)name,
+ &file, /* file handle if successful */
+ &actionTaken, /* reason for failure */
+ 0, /* initial size of new file */
+ FILE_NORMAL, /* file system attributes */
+ flags, /* Open flags */
+ access, /* Open mode and rights */
+ 0); /* OS/2 Extended Attributes */
}
else
{
- rc = DosOpen((char*)name,
- &file, /* file handle if successful */
- &actionTaken, /* reason for failure */
- 0, /* initial size of new file */
- FILE_NORMAL, /* file system attributes */
- flags, /* Open flags */
- access, /* Open mode and rights */
- 0); /* OS/2 Extended Attributes */
+ rc = DosOpen((char*)name,
+ &file, /* file handle if successful */
+ &actionTaken, /* reason for failure */
+ 0, /* initial size of new file */
+ FILE_NORMAL, /* file system attributes */
+ flags, /* Open flags */
+ access, /* Open mode and rights */
+ 0); /* OS/2 Extended Attributes */
};
if (rc == ERROR_TOO_MANY_OPEN_FILES) {
ULONG CurMaxFH = 0;
@@ -223,7 +234,7 @@ _PR_MD_OPEN(const char *name, PRIntn osflags, int mode)
if (rc != NO_ERROR) {
_PR_MD_MAP_OPEN_ERROR(rc);
- return -1;
+ return -1;
}
return (PRInt32)file;
@@ -239,17 +250,18 @@ _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
(PVOID)buf,
len,
&bytes);
-
- if (rv != NO_ERROR)
+
+ if (rv != NO_ERROR)
{
/* ERROR_HANDLE_EOF can only be returned by async io */
PR_ASSERT(rv != ERROR_HANDLE_EOF);
- if (rv == ERROR_BROKEN_PIPE)
+ if (rv == ERROR_BROKEN_PIPE) {
return 0;
- else {
- _PR_MD_MAP_READ_ERROR(rv);
- return -1;
- }
+ }
+ else {
+ _PR_MD_MAP_READ_ERROR(rv);
+ return -1;
+ }
}
return (PRInt32)bytes;
}
@@ -258,14 +270,14 @@ PRInt32
_PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 len)
{
PRInt32 bytes;
- int rv;
+ int rv;
rv = DosWrite((HFILE)fd->secret->md.osfd,
(PVOID)buf,
len,
(PULONG)&bytes);
- if (rv != NO_ERROR)
+ if (rv != NO_ERROR)
{
_PR_MD_MAP_WRITE_ERROR(rv);
return -1;
@@ -288,11 +300,12 @@ _PR_MD_LSEEK(PRFileDesc *fd, PRInt32 offset, PRSeekWhence whence)
rv = DosSetFilePtr((HFILE)fd->secret->md.osfd, offset, whence, &newLocation);
- if (rv != NO_ERROR) {
- _PR_MD_MAP_LSEEK_ERROR(rv);
- return -1;
- } else
- return newLocation;
+ if (rv != NO_ERROR) {
+ _PR_MD_MAP_LSEEK_ERROR(rv);
+ return -1;
+ } else {
+ return newLocation;
+ }
}
PRInt64
@@ -306,14 +319,14 @@ _PR_MD_LSEEK64(PRFileDesc *fd, PRInt64 offset, PRSeekWhence whence)
rv = DosSetFilePtr((HFILE)fd->secret->md.osfd, low, whence, &newLocation);
rv = DosSetFilePtr((HFILE)fd->secret->md.osfd, hi, FILE_CURRENT, &newLocation);
- if (rv != NO_ERROR) {
- _PR_MD_MAP_LSEEK_ERROR(rv);
- hi = newLocation = -1;
- }
+ if (rv != NO_ERROR) {
+ _PR_MD_MAP_LSEEK_ERROR(rv);
+ hi = newLocation = -1;
+ }
result.lo = newLocation;
result.hi = hi;
- return result;
+ return result;
#else
PRInt32 where, rc, lo = (PRInt32)offset, hi = (PRInt32)(offset >> 32);
@@ -322,19 +335,19 @@ _PR_MD_LSEEK64(PRFileDesc *fd, PRInt64 offset, PRSeekWhence whence)
PRUint64 newLocationL;
switch (whence)
- {
- case PR_SEEK_SET:
- where = FILE_BEGIN;
- break;
- case PR_SEEK_CUR:
- where = FILE_CURRENT;
- break;
- case PR_SEEK_END:
- where = FILE_END;
- break;
- default:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
- return -1;
+ {
+ case PR_SEEK_SET:
+ where = FILE_BEGIN;
+ break;
+ case PR_SEEK_CUR:
+ where = FILE_CURRENT;
+ break;
+ case PR_SEEK_END:
+ where = FILE_END;
+ break;
+ default:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+ return -1;
}
if (isWSEB)
{
@@ -344,12 +357,12 @@ _PR_MD_LSEEK64(PRFileDesc *fd, PRInt64 offset, PRSeekWhence whence)
{
rc = DosSetFilePtr((HFILE)fd->secret->md.osfd, lo, where, (PULONG)&newLocation);
}
-
+
if (rc != NO_ERROR) {
- _PR_MD_MAP_LSEEK_ERROR(rc);
- return -1;
+ _PR_MD_MAP_LSEEK_ERROR(rc);
+ return -1;
}
-
+
if (isWSEB)
{
return newLocationL;
@@ -373,10 +386,10 @@ _PR_MD_FSYNC(PRFileDesc *fd)
PRInt32 rc = DosResetBuffer((HFILE)fd->secret->md.osfd);
if (rc != NO_ERROR) {
- if (rc != ERROR_ACCESS_DENIED) {
- _PR_MD_MAP_FSYNC_ERROR(rc);
- return -1;
- }
+ if (rc != ERROR_ACCESS_DENIED) {
+ _PR_MD_MAP_FSYNC_ERROR(rc);
+ return -1;
+ }
}
return 0;
}
@@ -385,10 +398,11 @@ PRInt32
_MD_CloseFile(PRInt32 osfd)
{
PRInt32 rv;
-
+
rv = DosClose((HFILE)osfd);
- if (rv != NO_ERROR)
- _PR_MD_MAP_CLOSE_ERROR(rv);
+ if (rv != NO_ERROR) {
+ _PR_MD_MAP_CLOSE_ERROR(rv);
+ }
return rv;
}
@@ -400,10 +414,10 @@ _MD_CloseFile(PRInt32 osfd)
void FlipSlashes(char *cp, int len)
{
while (--len >= 0) {
- if (cp[0] == '/') {
- cp[0] = PR_DIRECTORY_SEPARATOR;
- }
- cp++;
+ if (cp[0] == '/') {
+ cp[0] = PR_DIRECTORY_SEPARATOR;
+ }
+ cp++;
}
}
@@ -417,17 +431,17 @@ void FlipSlashes(char *cp, int len)
PRInt32
_PR_MD_CLOSE_DIR(_MDDir *d)
{
- PRInt32 rc;
+ PRInt32 rc;
if ( d ) {
- rc = DosFindClose(d->d_hdl);
- if(rc == NO_ERROR){
- d->magic = (PRUint32)-1;
- return PR_SUCCESS;
- } else {
- _PR_MD_MAP_CLOSEDIR_ERROR(rc);
- return PR_FAILURE;
- }
+ rc = DosFindClose(d->d_hdl);
+ if(rc == NO_ERROR) {
+ d->magic = (PRUint32)-1;
+ return PR_SUCCESS;
+ } else {
+ _PR_MD_MAP_CLOSEDIR_ERROR(rc);
+ return PR_FAILURE;
+ }
}
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return PR_FAILURE;
@@ -469,7 +483,7 @@ _PR_MD_OPEN_DIR(_MDDir *d, const char *name)
FIL_STANDARD);
}
if ( rc != NO_ERROR ) {
- _PR_MD_MAP_OPENDIR_ERROR(rc);
+ _PR_MD_MAP_OPENDIR_ERROR(rc);
return PR_FAILURE;
}
d->firstEntry = PR_TRUE;
@@ -486,42 +500,46 @@ _PR_MD_READ_DIR(_MDDir *d, PRIntn flags)
USHORT fileAttr;
if ( d ) {
- while (1) {
- if (d->firstEntry) {
- d->firstEntry = PR_FALSE;
- rv = NO_ERROR;
- } else {
- rv = DosFindNext(d->d_hdl,
- &(d->d_entry),
- sizeof(d->d_entry),
- &numFiles);
- }
- if (rv != NO_ERROR) {
- break;
- }
- fileName = GetFileFromDIR(d);
- fileAttr = GetFileAttr(d);
- if ( (flags & PR_SKIP_DOT) &&
- (fileName[0] == '.') && (fileName[1] == '\0'))
+ while (1) {
+ if (d->firstEntry) {
+ d->firstEntry = PR_FALSE;
+ rv = NO_ERROR;
+ } else {
+ rv = DosFindNext(d->d_hdl,
+ &(d->d_entry),
+ sizeof(d->d_entry),
+ &numFiles);
+ }
+ if (rv != NO_ERROR) {
+ break;
+ }
+ fileName = GetFileFromDIR(d);
+ fileAttr = GetFileAttr(d);
+ if ( (flags & PR_SKIP_DOT) &&
+ (fileName[0] == '.') && (fileName[1] == '\0')) {
continue;
- if ( (flags & PR_SKIP_DOT_DOT) &&
- (fileName[0] == '.') && (fileName[1] == '.') &&
- (fileName[2] == '\0'))
+ }
+ if ( (flags & PR_SKIP_DOT_DOT) &&
+ (fileName[0] == '.') && (fileName[1] == '.') &&
+ (fileName[2] == '\0')) {
continue;
- /*
- * XXX
- * Is this the correct definition of a hidden file on OS/2?
- */
- if ((flags & PR_SKIP_NONE) && (fileAttr & FILE_HIDDEN))
+ }
+ /*
+ * XXX
+ * Is this the correct definition of a hidden file on OS/2?
+ */
+ if ((flags & PR_SKIP_NONE) && (fileAttr & FILE_HIDDEN)) {
return fileName;
- else if ((flags & PR_SKIP_HIDDEN) && (fileAttr & FILE_HIDDEN))
+ }
+ else if ((flags & PR_SKIP_HIDDEN) && (fileAttr & FILE_HIDDEN)) {
continue;
- return fileName;
+ }
+ return fileName;
}
PR_ASSERT(NO_ERROR != rv);
- _PR_MD_MAP_READDIR_ERROR(rv);
+ _PR_MD_MAP_READDIR_ERROR(rv);
return NULL;
- }
+ }
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return NULL;
}
@@ -533,7 +551,7 @@ _PR_MD_DELETE(const char *name)
if(rc == NO_ERROR) {
return 0;
} else {
- _PR_MD_MAP_DELETE_ERROR(rc);
+ _PR_MD_MAP_DELETE_ERROR(rc);
return -1;
}
}
@@ -558,7 +576,7 @@ _PR_MD_STAT(const char *fn, struct stat *info)
* can be handled by _stat() on NT but not on Win95.
*
* We remove the backslash or slash at the end and
- * try again.
+ * try again.
*
* Not sure if this happens on OS/2 or not,
* but it doesn't hurt to be careful.
@@ -566,7 +584,7 @@ _PR_MD_STAT(const char *fn, struct stat *info)
int len = strlen(fn);
if (len > 0 && len <= _MAX_PATH
- && (fn[len - 1] == '\\' || fn[len - 1] == '/')) {
+ && (fn[len - 1] == '\\' || fn[len - 1] == '/')) {
char newfn[_MAX_PATH + 1];
strcpy(newfn, fn);
@@ -587,15 +605,18 @@ _PR_MD_GETFILEINFO(const char *fn, PRFileInfo *info)
struct stat sb;
PRInt32 rv;
PRInt64 s, s2us;
-
+
if ( (rv = _PR_MD_STAT(fn, &sb)) == 0 ) {
if (info) {
- if (S_IFREG & sb.st_mode)
+ if (S_IFREG & sb.st_mode) {
info->type = PR_FILE_FILE ;
- else if (S_IFDIR & sb.st_mode)
+ }
+ else if (S_IFDIR & sb.st_mode) {
info->type = PR_FILE_DIRECTORY;
- else
+ }
+ else {
info->type = PR_FILE_OTHER;
+ }
info->size = sb.st_size;
LL_I2L(s2us, PR_USEC_PER_SEC);
LL_I2L(s, sb.st_mtime);
@@ -622,7 +643,7 @@ _PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info)
LL_UI2L(info->size,info32.size);
info->modifyTime = info32.modifyTime;
info->creationTime = info32.creationTime;
-
+
if (isWSEB)
{
APIRET rc ;
@@ -648,33 +669,35 @@ _PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info)
PRInt32
_PR_MD_GETOPENFILEINFO(const PRFileDesc *fd, PRFileInfo *info)
{
- /* For once, the VAC compiler/library did a nice thing.
- * The file handle used by the C runtime is the same one
- * returned by the OS when you call DosOpen(). This means
- * that you can take an OS HFILE and use it with C file
- * functions. The only caveat is that you have to call
- * _setmode() first to initialize some junk. This is
- * immensely useful because I did not have a clue how to
- * implement this function otherwise. The windows folks
- * took the source from the Microsoft C library source, but
- * IBM wasn't kind enough to ship the source with VAC.
- * On second thought, the needed function could probably
- * be gotten from the OS/2 GNU library source, but the
- * point is now moot.
- */
- struct stat hinfo;
+ /* For once, the VAC compiler/library did a nice thing.
+ * The file handle used by the C runtime is the same one
+ * returned by the OS when you call DosOpen(). This means
+ * that you can take an OS HFILE and use it with C file
+ * functions. The only caveat is that you have to call
+ * _setmode() first to initialize some junk. This is
+ * immensely useful because I did not have a clue how to
+ * implement this function otherwise. The windows folks
+ * took the source from the Microsoft C library source, but
+ * IBM wasn't kind enough to ship the source with VAC.
+ * On second thought, the needed function could probably
+ * be gotten from the OS/2 GNU library source, but the
+ * point is now moot.
+ */
+ struct stat hinfo;
PRInt64 s, s2us;
_setmode(fd->secret->md.osfd, O_BINARY);
if(fstat((int)fd->secret->md.osfd, &hinfo) != NO_ERROR) {
- _PR_MD_MAP_FSTAT_ERROR(errno);
+ _PR_MD_MAP_FSTAT_ERROR(errno);
return -1;
- }
+ }
- if (hinfo.st_mode & S_IFDIR)
+ if (hinfo.st_mode & S_IFDIR) {
info->type = PR_FILE_DIRECTORY;
- else
+ }
+ else {
info->type = PR_FILE_FILE;
+ }
info->size = hinfo.st_size;
LL_I2L(s2us, PR_USEC_PER_SEC);
@@ -695,13 +718,13 @@ _PR_MD_GETOPENFILEINFO64(const PRFileDesc *fd, PRFileInfo64 *info)
PRInt32 rv = _PR_MD_GETOPENFILEINFO(fd, &info32);
if (0 == rv)
{
- info->type = info32.type;
- LL_UI2L(info->size,info32.size);
-
- info->modifyTime = info32.modifyTime;
- info->creationTime = info32.creationTime;
+ info->type = info32.type;
+ LL_UI2L(info->size,info32.size);
+
+ info->modifyTime = info32.modifyTime;
+ info->creationTime = info32.creationTime;
}
-
+
if (isWSEB)
{
APIRET rc ;
@@ -728,12 +751,12 @@ _PR_MD_GETOPENFILEINFO64(const PRFileDesc *fd, PRFileInfo64 *info)
PRInt32
_PR_MD_RENAME(const char *from, const char *to)
{
- PRInt32 rc;
+ PRInt32 rc;
/* Does this work with dot-relative pathnames? */
if ( (rc = DosMove((char *)from, (char *)to)) == NO_ERROR) {
return 0;
} else {
- _PR_MD_MAP_RENAME_ERROR(rc);
+ _PR_MD_MAP_RENAME_ERROR(rc);
return -1;
}
}
@@ -741,35 +764,36 @@ _PR_MD_RENAME(const char *from, const char *to)
PRInt32
_PR_MD_ACCESS(const char *name, PRAccessHow how)
{
- PRInt32 rv;
+ PRInt32 rv;
switch (how) {
- case PR_ACCESS_WRITE_OK:
- rv = access(name, 02);
- break;
- case PR_ACCESS_READ_OK:
- rv = access(name, 04);
- break;
- case PR_ACCESS_EXISTS:
- return access(name, 00);
- break;
- default:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
- return -1;
- }
- if (rv < 0)
- _PR_MD_MAP_ACCESS_ERROR(errno);
+ case PR_ACCESS_WRITE_OK:
+ rv = access(name, 02);
+ break;
+ case PR_ACCESS_READ_OK:
+ rv = access(name, 04);
+ break;
+ case PR_ACCESS_EXISTS:
+ return access(name, 00);
+ break;
+ default:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+ return -1;
+ }
+ if (rv < 0) {
+ _PR_MD_MAP_ACCESS_ERROR(errno);
+ }
return rv;
}
PRInt32
_PR_MD_MKDIR(const char *name, PRIntn mode)
{
- PRInt32 rc;
+ PRInt32 rc;
/* XXXMB - how to translate the "mode"??? */
if ((rc = DosCreateDir((char *)name, NULL))== NO_ERROR) {
return 0;
} else {
- _PR_MD_MAP_MKDIR_ERROR(rc);
+ _PR_MD_MAP_MKDIR_ERROR(rc);
return -1;
}
}
@@ -777,11 +801,11 @@ _PR_MD_MKDIR(const char *name, PRIntn mode)
PRInt32
_PR_MD_RMDIR(const char *name)
{
- PRInt32 rc;
+ PRInt32 rc;
if ( (rc = DosDeleteDir((char *)name)) == NO_ERROR) {
return 0;
} else {
- _PR_MD_MAP_RMDIR_ERROR(rc);
+ _PR_MD_MAP_RMDIR_ERROR(rc);
return -1;
}
}
@@ -792,7 +816,7 @@ _PR_MD_LOCKFILE(PRInt32 f)
PRInt32 rv;
FILELOCK lock, unlock;
FILELOCKL lockL, unlockL;
-
+
lock.lOffset = 0;
lockL.lOffset = 0;
lock.lRange = 0xffffffff;
@@ -811,20 +835,20 @@ _PR_MD_LOCKFILE(PRInt32 f)
{
if (isWSEB)
{
- rv = myDosSetFileLocksL( (HFILE) f,
- &unlockL, &lockL,
- 0, 0);
+ rv = myDosSetFileLocksL( (HFILE) f,
+ &unlockL, &lockL,
+ 0, 0);
}
else
{
- rv = DosSetFileLocks( (HFILE) f,
- &unlock, &lock,
- 0, 0);
+ rv = DosSetFileLocks( (HFILE) f,
+ &unlock, &lock,
+ 0, 0);
}
- if ( rv != NO_ERROR )
+ if ( rv != NO_ERROR )
{
DosSleep( 50 ); /* Sleep() a few milisecs and try again. */
- }
+ }
} /* end for() */
return PR_SUCCESS;
} /* end _PR_MD_LOCKFILE() */
@@ -842,7 +866,7 @@ _PR_MD_UNLOCKFILE(PRInt32 f)
PRInt32 rv;
FILELOCK lock, unlock;
FILELOCKL lockL, unlockL;
-
+
lock.lOffset = 0;
lockL.lOffset = 0;
lock.lRange = 0;
@@ -851,20 +875,20 @@ _PR_MD_UNLOCKFILE(PRInt32 f)
unlockL.lOffset = 0;
unlock.lRange = 0xffffffff;
unlockL.lRange = 0xffffffffffffffff;
-
+
if (isWSEB)
{
rv = myDosSetFileLocksL( (HFILE) f,
- &unlockL, &lockL,
- 0, 0);
+ &unlockL, &lockL,
+ 0, 0);
}
else
{
rv = DosSetFileLocks( (HFILE) f,
- &unlock, &lock,
- 0, 0);
+ &unlock, &lock,
+ 0, 0);
}
-
+
if ( rv != NO_ERROR )
{
return PR_SUCCESS;
@@ -890,10 +914,12 @@ _PR_MD_SET_FD_INHERITABLE(PRFileDesc *fd, PRBool inheritable)
return PR_FAILURE;
}
- if (inheritable)
- flags &= ~OPEN_FLAGS_NOINHERIT;
- else
- flags |= OPEN_FLAGS_NOINHERIT;
+ if (inheritable) {
+ flags &= ~OPEN_FLAGS_NOINHERIT;
+ }
+ else {
+ flags |= OPEN_FLAGS_NOINHERIT;
+ }
/* Mask off flags DosSetFHState don't want. */
flags &= (OPEN_FLAGS_WRITE_THROUGH | OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NO_CACHE | OPEN_FLAGS_NOINHERIT);
diff --git a/nsprpub/pr/src/md/os2/os2misc.c b/nsprpub/pr/src/md/os2/os2misc.c
index f0e3ceeaf..240f0905c 100644
--- a/nsprpub/pr/src/md/os2/os2misc.c
+++ b/nsprpub/pr/src/md/os2/os2misc.c
@@ -73,7 +73,7 @@ PR_Now(void)
LL_MUL(ms, ms, ms2us);
LL_MUL(s, s, s2us);
LL_ADD(s, s, ms);
- return s;
+ return s;
}
@@ -120,7 +120,7 @@ static int assembleCmdLine(char *const *argv, char **cmdLine)
strcat(*cmdLine, " ");
}
strcat(*cmdLine, *arg);
- }
+ }
return 0;
}
@@ -150,15 +150,16 @@ static int assembleEnvBlock(char **envp, char **envBlock)
return 0;
}
- if(DosGetInfoBlocks(&ptib, &ppib) != NO_ERROR)
- return -1;
+ if(DosGetInfoBlocks(&ptib, &ppib) != NO_ERROR) {
+ return -1;
+ }
curEnv = ppib->pib_pchenv;
cwdStart = curEnv;
while (*cwdStart) {
if (cwdStart[0] == '=' && cwdStart[1] != '\0'
- && cwdStart[2] == ':' && cwdStart[3] == '=') {
+ && cwdStart[2] == ':' && cwdStart[3] == '=') {
break;
}
cwdStart += strlen(cwdStart) + 1;
@@ -168,7 +169,7 @@ static int assembleEnvBlock(char **envp, char **envBlock)
cwdEnd += strlen(cwdEnd) + 1;
while (*cwdEnd) {
if (cwdEnd[0] != '=' || cwdEnd[1] == '\0'
- || cwdEnd[2] != ':' || cwdEnd[3] != '=') {
+ || cwdEnd[2] != ':' || cwdEnd[3] != '=') {
break;
}
cwdEnd += strlen(cwdEnd) + 1;
@@ -221,7 +222,7 @@ PRProcess * _PR_CreateOS2Process(
char *cmdLine = NULL;
char **newEnvp = NULL;
char *envBlock = NULL;
-
+
STARTDATA startData = {0};
APIRET rc;
ULONG ulAppType = 0;
@@ -250,7 +251,7 @@ PRProcess * _PR_CreateOS2Process(
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
goto errorExit;
}
-
+
if (assembleCmdLine(argv, &cmdLine) == -1) {
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
goto errorExit;
@@ -260,7 +261,7 @@ PRProcess * _PR_CreateOS2Process(
/*
* DosQueryAppType() fails if path (the char* in the first argument) is in
* high memory. If that is the case, the following moves it to low memory.
- */
+ */
if ((ULONG)path >= 0x20000000) {
size_t len = strlen(path) + 1;
char *copy = (char *)alloca(len);
@@ -268,7 +269,7 @@ PRProcess * _PR_CreateOS2Process(
path = copy;
}
#endif
-
+
if (envp == NULL) {
newEnvp = NULL;
} else {
@@ -287,27 +288,27 @@ PRProcess * _PR_CreateOS2Process(
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
goto errorExit;
}
-
+
rc = DosQueryAppType(path, &ulAppType);
if (rc != NO_ERROR) {
- char *pszDot = strrchr(path, '.');
- if (pszDot) {
- /* If it is a CMD file, launch the users command processor */
- if (!stricmp(pszDot, ".cmd")) {
- rc = DosScanEnv("COMSPEC", (PSZ *)&pszComSpec);
- if (!rc) {
- strcpy(pszFormatString, "/C %s %s");
- strcpy(pszEXEName, pszComSpec);
- ulAppType = FAPPTYP_WINDOWCOMPAT;
- }
- }
- }
+ char *pszDot = strrchr(path, '.');
+ if (pszDot) {
+ /* If it is a CMD file, launch the users command processor */
+ if (!stricmp(pszDot, ".cmd")) {
+ rc = DosScanEnv("COMSPEC", (PSZ *)&pszComSpec);
+ if (!rc) {
+ strcpy(pszFormatString, "/C %s %s");
+ strcpy(pszEXEName, pszComSpec);
+ ulAppType = FAPPTYP_WINDOWCOMPAT;
+ }
+ }
+ }
}
if (ulAppType == 0) {
- PR_SetError(PR_UNKNOWN_ERROR, 0);
- goto errorExit;
+ PR_SetError(PR_UNKNOWN_ERROR, 0);
+ goto errorExit;
}
-
+
if ((ulAppType & FAPPTYP_WINDOWAPI) == FAPPTYP_WINDOWAPI) {
startData.SessionType = SSF_TYPE_PM;
}
@@ -317,16 +318,16 @@ PRProcess * _PR_CreateOS2Process(
else {
startData.SessionType = SSF_TYPE_DEFAULT;
}
-
+
if (ulAppType & (FAPPTYP_WINDOWSPROT31 | FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSREAL))
{
strcpy(pszEXEName, "WINOS2.COM");
startData.SessionType = PROG_31_STDSEAMLESSVDM;
strcpy(pszFormatString, "/3 %s %s");
}
-
+
startData.InheritOpt = SSF_INHERTOPT_SHELL;
-
+
if (pszEXEName[0]) {
pszFormatResult = PR_MALLOC(strlen(pszFormatString)+strlen(path)+strlen(cmdLine));
sprintf(pszFormatResult, pszFormatString, path, cmdLine);
@@ -336,13 +337,13 @@ PRProcess * _PR_CreateOS2Process(
startData.PgmInputs = cmdLine;
}
startData.PgmName = pszEXEName;
-
+
startData.Length = sizeof(startData);
startData.Related = SSF_RELATED_INDEPENDENT;
startData.ObjectBuffer = pszObjectBuffer;
startData.ObjectBuffLen = CCHMAXPATH;
startData.Environment = envBlock;
-
+
if (attr) {
/* On OS/2, there is really no way to pass file handles for stdin,
* stdout, and stderr to a new process. Instead, we can make it
@@ -407,7 +408,7 @@ PRProcess * _PR_CreateOS2Process(
}
proc->md.pid = procInfo.codeTerminate;
- } else {
+ } else {
/*
* If no STDIN/STDOUT redirection is not needed, use DosStartSession
* to create a new, independent session
@@ -418,7 +419,7 @@ PRProcess * _PR_CreateOS2Process(
PR_SetError(PR_UNKNOWN_ERROR, rc);
goto errorExit;
}
-
+
proc->md.pid = pid;
}
@@ -453,7 +454,7 @@ errorExit:
PRStatus _PR_DetachOS2Process(PRProcess *process)
{
- /* On OS/2, a process is either created as a child or not.
+ /* On OS/2, a process is either created as a child or not.
* You can't 'detach' it later on.
*/
PR_DELETE(process);
@@ -464,18 +465,18 @@ PRStatus _PR_DetachOS2Process(PRProcess *process)
* XXX: This will currently only work on a child process.
*/
PRStatus _PR_WaitOS2Process(PRProcess *process,
- PRInt32 *exitCode)
+ PRInt32 *exitCode)
{
ULONG ulRetVal;
RESULTCODES results;
PID pidEnded = 0;
- ulRetVal = DosWaitChild(DCWA_PROCESS, DCWW_WAIT,
+ ulRetVal = DosWaitChild(DCWA_PROCESS, DCWW_WAIT,
&results,
&pidEnded, process->md.pid);
if (ulRetVal != NO_ERROR) {
- printf("\nDosWaitChild rc = %lu\n", ulRetVal);
+ printf("\nDosWaitChild rc = %lu\n", ulRetVal);
PR_SetError(PR_UNKNOWN_ERROR, ulRetVal);
return PR_FAILURE;
}
@@ -485,9 +486,9 @@ PRStatus _PR_WaitOS2Process(PRProcess *process,
PRStatus _PR_KillOS2Process(PRProcess *process)
{
- ULONG ulRetVal;
+ ULONG ulRetVal;
if ((ulRetVal = DosKillProcess(DKP_PROCESS, process->md.pid)) == NO_ERROR) {
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
PR_SetError(PR_UNKNOWN_ERROR, ulRetVal);
return PR_FAILURE;
@@ -501,7 +502,7 @@ PRStatus _MD_OS2GetHostName(char *name, PRUint32 namelen)
if (0 == rv) {
return PR_SUCCESS;
}
- _PR_MD_MAP_GETHOSTNAME_ERROR(sock_errno());
+ _PR_MD_MAP_GETHOSTNAME_ERROR(sock_errno());
return PR_FAILURE;
}
@@ -509,7 +510,7 @@ void
_PR_MD_WAKEUP_CPUS( void )
{
return;
-}
+}
/*
**********************************************************************
diff --git a/nsprpub/pr/src/md/os2/os2poll.c b/nsprpub/pr/src/md/os2/os2poll.c
index 9a0a00956..47d971045 100644
--- a/nsprpub/pr/src/md/os2/os2poll.c
+++ b/nsprpub/pr/src/md/os2/os2poll.c
@@ -16,16 +16,17 @@
PRBool IsSocketSet( PRInt32 osfd, int* socks, int start, int count )
{
- int i;
- PRBool isSet = PR_FALSE;
+ int i;
+ PRBool isSet = PR_FALSE;
- for( i = start; i < start+count; i++ )
- {
- if( socks[i] == osfd )
- isSet = PR_TRUE;
- }
-
- return isSet;
+ for( i = start; i < start+count; i++ )
+ {
+ if( socks[i] == osfd ) {
+ isSet = PR_TRUE;
+ }
+ }
+
+ return isSet;
}
#endif
@@ -55,7 +56,7 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
wt = 0;
ex = 0;
socks = (int) PR_MALLOC( npds * 3 * sizeof(int) );
-
+
if (!socks)
{
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
@@ -74,12 +75,12 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
if (pd->in_flags & PR_POLL_READ)
{
in_flags_read = (pd->fd->methods->poll)(
- pd->fd, pd->in_flags & ~PR_POLL_WRITE, &out_flags_read);
+ pd->fd, pd->in_flags & ~PR_POLL_WRITE, &out_flags_read);
}
if (pd->in_flags & PR_POLL_WRITE)
{
in_flags_write = (pd->fd->methods->poll)(
- pd->fd, pd->in_flags & ~PR_POLL_READ, &out_flags_write);
+ pd->fd, pd->in_flags & ~PR_POLL_READ, &out_flags_write);
}
if ((0 != (in_flags_read & out_flags_read)) ||
(0 != (in_flags_write & out_flags_write)))
@@ -115,8 +116,9 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
if (0 == ready)
{
PRInt32 osfd = bottom->secret->md.osfd;
- if (osfd > maxfd)
+ if (osfd > maxfd) {
maxfd = osfd;
+ }
if (in_flags_read & PR_POLL_READ)
{
pd->out_flags |= _PR_POLL_READ_SYS_READ;
@@ -124,7 +126,7 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
FD_SET(osfd, &rd);
#else
socks[rd] = osfd;
- rd++;
+ rd++;
#endif
}
if (in_flags_read & PR_POLL_WRITE)
@@ -134,7 +136,7 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
FD_SET(osfd, &wt);
#else
socks[npds+wt] = osfd;
- wt++;
+ wt++;
#endif
}
if (in_flags_write & PR_POLL_READ)
@@ -144,7 +146,7 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
FD_SET(osfd, &rd);
#else
socks[rd] = osfd;
- rd++;
+ rd++;
#endif
}
if (in_flags_write & PR_POLL_WRITE)
@@ -154,7 +156,7 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
FD_SET(osfd, &wt);
#else
socks[npds+wt] = osfd;
- wt++;
+ wt++;
#endif
}
if (pd->in_flags & PR_POLL_EXCEPT)
@@ -224,24 +226,28 @@ retry:
msecs = PR_IntervalToMilliseconds(remaining);
}
- /* compact array */
- for( i = rd, j = npds; j < npds+wt; i++,j++ )
+ /* compact array */
+ for( i = rd, j = npds; j < npds+wt; i++,j++ ) {
socks[i] = socks[j];
- for( i = rd+wt, j = npds*2; j < npds*2+ex; i++,j++ )
+ }
+ for( i = rd+wt, j = npds*2; j < npds*2+ex; i++,j++ ) {
socks[i] = socks[j];
-
+ }
+
ready = os2_select(socks, rd, wt, ex, msecs);
#endif
if (ready == -1 && errno == EINTR)
{
- if (timeout == PR_INTERVAL_NO_TIMEOUT)
+ if (timeout == PR_INTERVAL_NO_TIMEOUT) {
goto retry;
+ }
else
{
elapsed = (PRIntervalTime) (PR_IntervalNow() - start);
- if (elapsed > timeout)
- ready = 0; /* timed out */
+ if (elapsed > timeout) {
+ ready = 0; /* timed out */
+ }
else
{
remaining = timeout - elapsed;
@@ -272,38 +278,44 @@ retry:
#ifdef BSD_SELECT
if (FD_ISSET(osfd, &rd))
#else
- if( IsSocketSet(osfd, socks, 0, rd) )
+ if( IsSocketSet(osfd, socks, 0, rd) )
#endif
{
- if (pd->out_flags & _PR_POLL_READ_SYS_READ)
+ if (pd->out_flags & _PR_POLL_READ_SYS_READ) {
out_flags |= PR_POLL_READ;
- if (pd->out_flags & _PR_POLL_WRITE_SYS_READ)
+ }
+ if (pd->out_flags & _PR_POLL_WRITE_SYS_READ) {
out_flags |= PR_POLL_WRITE;
- }
+ }
+ }
#ifdef BSD_SELECT
if (FD_ISSET(osfd, &wt))
#else
- if( IsSocketSet(osfd, socks, rd, wt) )
+ if( IsSocketSet(osfd, socks, rd, wt) )
#endif
{
- if (pd->out_flags & _PR_POLL_READ_SYS_WRITE)
+ if (pd->out_flags & _PR_POLL_READ_SYS_WRITE) {
out_flags |= PR_POLL_READ;
- if (pd->out_flags & _PR_POLL_WRITE_SYS_WRITE)
+ }
+ if (pd->out_flags & _PR_POLL_WRITE_SYS_WRITE) {
out_flags |= PR_POLL_WRITE;
- }
+ }
+ }
#ifdef BSD_SELECT
if (FD_ISSET(osfd, &ex))
#else
- if( IsSocketSet(osfd, socks, rd+wt, ex) )
+ if( IsSocketSet(osfd, socks, rd+wt, ex) )
#endif
{
out_flags |= PR_POLL_EXCEPT;
}
}
pd->out_flags = out_flags;
- if (out_flags) ready++;
+ if (out_flags) {
+ ready++;
+ }
}
PR_ASSERT(ready > 0);
}
@@ -323,7 +335,7 @@ retry:
{
bottom = PR_GetIdentitiesLayer(pd->fd, PR_NSPR_IO_LAYER);
if (getsockopt(bottom->secret->md.osfd, SOL_SOCKET,
- SO_TYPE, (char *) &optval, &optlen) == -1)
+ SO_TYPE, (char *) &optval, &optlen) == -1)
{
PR_ASSERT(sock_errno() == ENOTSOCK);
if (sock_errno() == ENOTSOCK)
@@ -336,8 +348,9 @@ retry:
}
PR_ASSERT(ready > 0);
}
- else
+ else {
_PR_MD_MAP_SELECT_ERROR(err);
+ }
}
#ifndef BSD_SELECT
diff --git a/nsprpub/pr/src/md/os2/os2rng.c b/nsprpub/pr/src/md/os2/os2rng.c
index 72f7357fa..aaa969381 100644
--- a/nsprpub/pr/src/md/os2/os2rng.c
+++ b/nsprpub/pr/src/md/os2/os2rng.c
@@ -17,8 +17,9 @@ static BOOL clockTickTime(unsigned long *phigh, unsigned long *plow)
QWORD qword = {0,0};
rc = DosTmrQueryTime(&qword);
- if (rc != NO_ERROR)
- return FALSE;
+ if (rc != NO_ERROR) {
+ return FALSE;
+ }
*phigh = qword.ulHi;
*plow = qword.ulLo;
@@ -35,8 +36,9 @@ extern PRSize _PR_MD_GetRandomNoise(void *buf, PRSize size )
int nBytes = 0;
time_t sTime;
- if (size <= 0)
- return 0;
+ if (size <= 0) {
+ return 0;
+ }
clockTickTime(&high, &low);
@@ -46,16 +48,18 @@ extern PRSize _PR_MD_GetRandomNoise(void *buf, PRSize size )
n += nBytes;
size -= nBytes;
- if (size <= 0)
- return n;
+ if (size <= 0) {
+ return n;
+ }
nBytes = sizeof(high) > size ? size : sizeof(high);
memcpy(((char *)buf) + n, &high, nBytes);
n += nBytes;
size -= nBytes;
- if (size <= 0)
- return n;
+ if (size <= 0) {
+ return n;
+ }
/* get the number of milliseconds that have elapsed since application started */
val = clock();
@@ -65,8 +69,9 @@ extern PRSize _PR_MD_GetRandomNoise(void *buf, PRSize size )
n += nBytes;
size -= nBytes;
- if (size <= 0)
- return n;
+ if (size <= 0) {
+ return n;
+ }
/* get the time in seconds since midnight Jan 1, 1970 */
time(&sTime);
diff --git a/nsprpub/pr/src/md/os2/os2sem.c b/nsprpub/pr/src/md/os2/os2sem.c
index b60f35a74..a0dd88e4b 100644
--- a/nsprpub/pr/src/md/os2/os2sem.c
+++ b/nsprpub/pr/src/md/os2/os2sem.c
@@ -14,7 +14,7 @@
void
_PR_MD_NEW_SEM(_MDSemaphore *md, PRUintn value)
{
- int rv;
+ int rv;
/* Our Sems don't support a value > 1 */
PR_ASSERT(value <= 1);
@@ -26,9 +26,9 @@ _PR_MD_NEW_SEM(_MDSemaphore *md, PRUintn value)
void
_PR_MD_DESTROY_SEM(_MDSemaphore *md)
{
- int rv;
- rv = DosCloseEventSem(md->sem);
- PR_ASSERT(rv == NO_ERROR);
+ int rv;
+ rv = DosCloseEventSem(md->sem);
+ PR_ASSERT(rv == NO_ERROR);
}
@@ -38,10 +38,12 @@ _PR_MD_TIMED_WAIT_SEM(_MDSemaphore *md, PRIntervalTime ticks)
int rv;
rv = DosWaitEventSem(md->sem, PR_IntervalToMilliseconds(ticks));
- if (rv == NO_ERROR)
+ if (rv == NO_ERROR) {
return PR_SUCCESS;
- else
+ }
+ else {
return PR_FAILURE;
+ }
}
PRStatus
@@ -53,9 +55,9 @@ _PR_MD_WAIT_SEM(_MDSemaphore *md)
void
_PR_MD_POST_SEM(_MDSemaphore *md)
{
- int rv;
- rv = DosPostEventSem(md->sem);
- PR_ASSERT(rv == NO_ERROR);
+ int rv;
+ rv = DosPostEventSem(md->sem);
+ PR_ASSERT(rv == NO_ERROR);
}
diff --git a/nsprpub/pr/src/md/os2/os2sock.c b/nsprpub/pr/src/md/os2/os2sock.c
index b32794f39..c6b3ea3a5 100644
--- a/nsprpub/pr/src/md/os2/os2sock.c
+++ b/nsprpub/pr/src/md/os2/os2sock.c
@@ -12,7 +12,7 @@
/*There is standard BSD (which is kind of slow) and a new flavor of select() that takes */
/*an integer list of sockets, the number of read sockets, write sockets, except sockets, and */
/*a millisecond count for timeout. In the interest of performance I have choosen the OS/2 */
-/*specific version of select(). See OS/2 TCP/IP Programmer's Toolkit for more info. */
+/*specific version of select(). See OS/2 TCP/IP Programmer's Toolkit for more info. */
#include "primpl.h"
@@ -32,7 +32,7 @@ _PR_MD_SOCKET(int domain, int type, int flags)
osfd = socket(domain, type, flags);
- if (osfd == -1)
+ if (osfd == -1)
{
err = sock_errno();
_PR_MD_MAP_SOCKET_ERROR(err);
@@ -101,19 +101,23 @@ socket_io_wait( PRInt32 osfd, PRInt32 fd_type, PRIntervalTime timeout )
FD_ZERO(&rd_wr);
do {
FD_SET(osfd, &rd_wr);
- if (fd_type == READ_FD)
+ if (fd_type == READ_FD) {
rv = bsdselect(osfd + 1, &rd_wr, NULL, NULL, &tv);
- else
+ }
+ else {
rv = bsdselect(osfd + 1, NULL, &rd_wr, NULL, &tv);
+ }
#else
- lTimeout = _PR_INTERRUPT_CHECK_INTERVAL_SECS * 1000;
+ lTimeout = _PR_INTERRUPT_CHECK_INTERVAL_SECS * 1000;
do {
socks[0] = osfd;
- if (fd_type == READ_FD)
+ if (fd_type == READ_FD) {
rv = os2_select(socks, 1, 0, 0, lTimeout);
- else
+ }
+ else {
rv = os2_select(socks, 0, 1, 0, lTimeout);
-#endif
+ }
+#endif
if (rv == -1 && (syserror = sock_errno()) != EINTR) {
_PR_MD_MAP_SELECT_ERROR(syserror);
break;
@@ -148,14 +152,16 @@ socket_io_wait( PRInt32 osfd, PRInt32 fd_type, PRIntervalTime timeout )
tv.tv_usec = 0;
} else {
tv.tv_usec = PR_IntervalToMicroseconds(
- remaining -
- PR_SecondsToInterval(tv.tv_sec));
+ remaining -
+ PR_SecondsToInterval(tv.tv_sec));
}
FD_SET(osfd, &rd_wr);
- if (fd_type == READ_FD)
+ if (fd_type == READ_FD) {
rv = bsdselect(osfd + 1, &rd_wr, NULL, NULL, &tv);
- else
+ }
+ else {
rv = bsdselect(osfd + 1, NULL, &rd_wr, NULL, &tv);
+ }
#else
wait_for_remaining = PR_TRUE;
lTimeout = PR_IntervalToMilliseconds(remaining);
@@ -164,10 +170,12 @@ socket_io_wait( PRInt32 osfd, PRInt32 fd_type, PRIntervalTime timeout )
lTimeout = _PR_INTERRUPT_CHECK_INTERVAL_SECS * 1000;
}
socks[0] = osfd;
- if (fd_type == READ_FD)
+ if (fd_type == READ_FD) {
rv = os2_select(socks, 1, 0, 0, lTimeout);
- else
+ }
+ else {
rv = os2_select(socks, 0, 1, 0, lTimeout);
+ }
#endif
/*
* we don't consider EINTR a real error
@@ -198,7 +206,7 @@ socket_io_wait( PRInt32 osfd, PRInt32 fd_type, PRIntervalTime timeout )
} else {
#ifdef BSD_SELECT
now += PR_SecondsToInterval(tv.tv_sec)
- + PR_MicrosecondsToInterval(tv.tv_usec);
+ + PR_MicrosecondsToInterval(tv.tv_usec);
#else
now += PR_MillisecondsToInterval(lTimeout);
#endif
@@ -217,7 +225,7 @@ socket_io_wait( PRInt32 osfd, PRInt32 fd_type, PRIntervalTime timeout )
}
} while (rv == 0 || (rv == -1 && syserror == EINTR));
break;
- }
+ }
return(rv);
}
@@ -237,9 +245,10 @@ _MD_Accept(PRFileDesc *fd, PRNetAddr *addr,
if (fd->secret->nonblocking) {
break;
}
- if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0)
- goto done;
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0) {
+ goto done;
+ }
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -253,7 +262,7 @@ done:
}
PRInt32
-_PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,
+_PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,
PRIntervalTime timeout)
{
PRInt32 rv, err;
@@ -263,17 +272,17 @@ _PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,
* modifies the sockaddr structure.
* See Bugzilla bug 100776. */
- /*
- * We initiate the connection setup by making a nonblocking connect()
- * call. If the connect() call fails, there are two cases we handle
- * specially:
- * 1. The connect() call was interrupted by a signal. In this case
- * we simply retry connect().
- * 2. The NSPR socket is nonblocking and connect() fails with
- * EINPROGRESS. We first wait until the socket becomes writable.
- * Then we try to find out whether the connection setup succeeded
- * or failed.
- */
+ /*
+ * We initiate the connection setup by making a nonblocking connect()
+ * call. If the connect() call fails, there are two cases we handle
+ * specially:
+ * 1. The connect() call was interrupted by a signal. In this case
+ * we simply retry connect().
+ * 2. The NSPR socket is nonblocking and connect() fails with
+ * EINPROGRESS. We first wait until the socket becomes writable.
+ * Then we try to find out whether the connection setup succeeded
+ * or failed.
+ */
retry:
if ((rv = connect(osfd, (struct sockaddr *)&addrCopy, addrlen)) == -1)
@@ -313,7 +322,7 @@ retry:
}
return 0;
}
-
+
_PR_MD_MAP_CONNECT_ERROR(err);
}
@@ -347,7 +356,7 @@ _PR_MD_LISTEN(PRFileDesc *fd, PRIntn backlog)
PRInt32
-_PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
+_PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
PRIntervalTime timeout)
{
PRInt32 osfd = fd->secret->md.osfd;
@@ -361,9 +370,10 @@ _PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
if (fd->secret->nonblocking) {
break;
}
- if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0)
+ if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0) {
goto done;
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ }
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -391,20 +401,21 @@ _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
if (fd->secret->nonblocking) {
break;
}
- if ((rv = socket_io_wait(osfd, WRITE_FD, timeout)) < 0)
+ if ((rv = socket_io_wait(osfd, WRITE_FD, timeout)) < 0) {
goto done;
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ }
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
}
}
- /*
- * optimization; if bytes sent is less than "amount" call
- * select before returning. This is because it is likely that
- * the next send() call will return EWOULDBLOCK.
- */
+ /*
+ * optimization; if bytes sent is less than "amount" call
+ * select before returning. This is because it is likely that
+ * the next send() call will return EWOULDBLOCK.
+ */
if ((!fd->secret->nonblocking) && (rv > 0) && (rv < amount)
&& (timeout != PR_INTERVAL_NO_WAIT))
{
@@ -428,7 +439,7 @@ _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
PRInt32 rv, err;
PRThread *me = _PR_MD_CURRENT_THREAD();
while ((rv = sendto(osfd, buf, amount, flags,
- (struct sockaddr *) addr, addrlen)) == -1)
+ (struct sockaddr *) addr, addrlen)) == -1)
{
err = sock_errno();
if ((err == EWOULDBLOCK))
@@ -436,9 +447,10 @@ _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
if (fd->secret->nonblocking) {
break;
}
- if ((rv = socket_io_wait(osfd, WRITE_FD, timeout)) < 0)
+ if ((rv = socket_io_wait(osfd, WRITE_FD, timeout)) < 0) {
goto done;
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ }
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -461,16 +473,17 @@ _PR_MD_RECVFROM(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
while( (*addrlen = PR_NETADDR_SIZE(addr)),
((rv = recvfrom(osfd, buf, amount, flags,
- (struct sockaddr *) addr, (int *)addrlen)) == -1))
+ (struct sockaddr *) addr, (int *)addrlen)) == -1))
{
err = sock_errno();
if ((err == EWOULDBLOCK)) {
if (fd->secret->nonblocking) {
break;
}
- if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0)
+ if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0) {
goto done;
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ }
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -506,13 +519,13 @@ _PR_MD_WRITEV(PRFileDesc *fd, const PRIOVec *iov, PRInt32 iov_size,
osiov[index].iov_len = iov[index].iov_len;
}
- /*
- * Calculate the total number of bytes to be sent; needed for
- * optimization later.
- * We could avoid this if this number was passed in; but it is
- * probably not a big deal because iov_size is usually small (less than
- * 3)
- */
+ /*
+ * Calculate the total number of bytes to be sent; needed for
+ * optimization later.
+ * We could avoid this if this number was passed in; but it is
+ * probably not a big deal because iov_size is usually small (less than
+ * 3)
+ */
if (!fd->secret->nonblocking) {
for (index=0; index<iov_size; index++) {
amount += iov[index].iov_len;
@@ -525,22 +538,23 @@ _PR_MD_WRITEV(PRFileDesc *fd, const PRIOVec *iov, PRInt32 iov_size,
if (fd->secret->nonblocking) {
break;
}
- if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))<0)
+ if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))<0) {
goto done;
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ }
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
}
}
- /*
- * optimization; if bytes sent is less than "amount" call
- * select before returning. This is because it is likely that
- * the next writev() call will return EWOULDBLOCK.
- */
+ /*
+ * optimization; if bytes sent is less than "amount" call
+ * select before returning. This is because it is likely that
+ * the next writev() call will return EWOULDBLOCK.
+ */
if ((!fd->secret->nonblocking) && (rv > 0) && (rv < amount)
- && (timeout != PR_INTERVAL_NO_WAIT)) {
+ && (timeout != PR_INTERVAL_NO_WAIT)) {
if (socket_io_wait(osfd, WRITE_FD, timeout) < 0) {
rv = -1;
goto done;
@@ -559,8 +573,9 @@ _PR_MD_SHUTDOWN(PRFileDesc *fd, PRIntn how)
PRInt32 rv;
rv = shutdown(fd->secret->md.osfd, how);
- if (rv < 0)
+ if (rv < 0) {
_PR_MD_MAP_SHUTDOWN_ERROR(sock_errno());
+ }
return rv;
}
@@ -639,7 +654,7 @@ _MD_MakeNonblock(PRFileDesc *fd)
PRInt32 osfd = fd->secret->md.osfd;
PRInt32 err;
PRUint32 one = 1;
-
+
if (osfd <= 2) {
/* Don't mess around with stdin, stdout or stderr */
return;
diff --git a/nsprpub/pr/src/md/os2/os2thred.c b/nsprpub/pr/src/md/os2/os2thred.c
index edb9f5f0c..aa929a1a2 100644
--- a/nsprpub/pr/src/md/os2/os2thred.c
+++ b/nsprpub/pr/src/md/os2/os2thred.c
@@ -16,37 +16,37 @@ APIRET (* APIENTRY QueryThreadContext)(TID, ULONG, PCONTEXTRECORD);
void
_PR_MD_ENSURE_TLS(void)
{
- if(!pThreadLocalStorage)
- {
- /* Allocate thread local storage (TLS). Note, that only 32 bytes can
- * be allocated at a time.
- */
- int rc = DosAllocThreadLocalMemory(sizeof(_NSPR_TLS) / 4, (PULONG*)&pThreadLocalStorage);
- PR_ASSERT(rc == NO_ERROR);
- memset(pThreadLocalStorage, 0, sizeof(_NSPR_TLS));
- }
+ if(!pThreadLocalStorage)
+ {
+ /* Allocate thread local storage (TLS). Note, that only 32 bytes can
+ * be allocated at a time.
+ */
+ int rc = DosAllocThreadLocalMemory(sizeof(_NSPR_TLS) / 4, (PULONG*)&pThreadLocalStorage);
+ PR_ASSERT(rc == NO_ERROR);
+ memset(pThreadLocalStorage, 0, sizeof(_NSPR_TLS));
+ }
}
void
_PR_MD_EARLY_INIT()
{
- HMODULE hmod;
+ HMODULE hmod;
- if (DosLoadModule(NULL, 0, "DOSCALL1", &hmod) == 0)
- DosQueryProcAddr(hmod, 877, "DOSQUERYTHREADCONTEXT",
- (PFN *)&QueryThreadContext);
+ if (DosLoadModule(NULL, 0, "DOSCALL1", &hmod) == 0)
+ DosQueryProcAddr(hmod, 877, "DOSQUERYTHREADCONTEXT",
+ (PFN *)&QueryThreadContext);
}
static void
_pr_SetThreadMDHandle(PRThread *thread)
{
- PTIB ptib;
- PPIB ppib;
- PRUword rc;
+ PTIB ptib;
+ PPIB ppib;
+ PRUword rc;
- rc = DosGetInfoBlocks(&ptib, &ppib);
+ rc = DosGetInfoBlocks(&ptib, &ppib);
- thread->md.handle = ptib->tib_ptib2->tib2_ultid;
+ thread->md.handle = ptib->tib_ptib2->tib2_ultid;
}
/* On OS/2, some system function calls seem to change the FPU control word,
@@ -134,15 +134,15 @@ PR_OS2_UnsetFloatExcpHandler(EXCEPTIONREGISTRATIONRECORD* excpreg)
PRStatus
_PR_MD_INIT_THREAD(PRThread *thread)
{
- APIRET rv;
+ APIRET rv;
- if (thread->flags & (_PR_PRIMORDIAL | _PR_ATTACHED)) {
- _pr_SetThreadMDHandle(thread);
- }
+ if (thread->flags & (_PR_PRIMORDIAL | _PR_ATTACHED)) {
+ _pr_SetThreadMDHandle(thread);
+ }
- /* Create the blocking IO semaphore */
- rv = DosCreateEventSem(NULL, &(thread->md.blocked_sema), 0, 0);
- return (rv == NO_ERROR) ? PR_SUCCESS : PR_FAILURE;
+ /* Create the blocking IO semaphore */
+ rv = DosCreateEventSem(NULL, &(thread->md.blocked_sema), 0, 0);
+ return (rv == NO_ERROR) ? PR_SUCCESS : PR_FAILURE;
}
typedef struct param_store
@@ -169,20 +169,20 @@ ExcpStartFunc(void* arg)
}
PRStatus
-_PR_MD_CREATE_THREAD(PRThread *thread,
- void (*start)(void *),
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize)
+_PR_MD_CREATE_THREAD(PRThread *thread,
+ void (*start)(void *),
+ PRThreadPriority priority,
+ PRThreadScope scope,
+ PRThreadState state,
+ PRUint32 stackSize)
{
PARAMSTORE* params = PR_Malloc(sizeof(PARAMSTORE));
params->start = start;
params->thread = thread;
thread->md.handle = thread->id = (TID) _beginthread(ExcpStartFunc,
- NULL,
- thread->stack->stackSize,
- params);
+ NULL,
+ thread->stack->stackSize,
+ params);
if(thread->md.handle == -1) {
return PR_FAILURE;
}
@@ -232,7 +232,7 @@ _PR_MD_SET_PRIORITY(_MDThread *thread, PRThreadPriority newPri)
PR_ASSERT(rv == NO_ERROR);
if (rv != NO_ERROR) {
PR_LOG(_pr_thread_lm, PR_LOG_MIN,
- ("PR_SetThreadPriority: can't set thread priority\n"));
+ ("PR_SetThreadPriority: can't set thread priority\n"));
}
return;
}
@@ -268,41 +268,41 @@ _PR_MD_EXIT(PRIntn status)
}
#ifdef HAVE_THREAD_AFFINITY
-PR_EXTERN(PRInt32)
+PR_EXTERN(PRInt32)
_PR_MD_SETTHREADAFFINITYMASK(PRThread *thread, PRUint32 mask )
{
- /* Can we do this on OS/2? Only on SMP versions? */
- PR_NOT_REACHED("Not implemented");
- return 0;
+ /* Can we do this on OS/2? Only on SMP versions? */
+ PR_NOT_REACHED("Not implemented");
+ return 0;
- /* This is what windows does:
- int rv;
+ /* This is what windows does:
+ int rv;
- rv = SetThreadAffinityMask(thread->md.handle, mask);
+ rv = SetThreadAffinityMask(thread->md.handle, mask);
- return rv?0:-1;
- */
+ return rv?0:-1;
+ */
}
PR_EXTERN(PRInt32)
_PR_MD_GETTHREADAFFINITYMASK(PRThread *thread, PRUint32 *mask)
{
- /* Can we do this on OS/2? Only on SMP versions? */
- PR_NOT_REACHED("Not implemented");
- return 0;
+ /* Can we do this on OS/2? Only on SMP versions? */
+ PR_NOT_REACHED("Not implemented");
+ return 0;
- /* This is what windows does:
- PRInt32 rv, system_mask;
+ /* This is what windows does:
+ PRInt32 rv, system_mask;
- rv = GetProcessAffinityMask(GetCurrentProcess(), mask, &system_mask);
-
- return rv?0:-1;
- */
+ rv = GetProcessAffinityMask(GetCurrentProcess(), mask, &system_mask);
+
+ return rv?0:-1;
+ */
}
#endif /* HAVE_THREAD_AFFINITY */
void
-_PR_MD_SUSPEND_CPU(_PRCPU *cpu)
+_PR_MD_SUSPEND_CPU(_PRCPU *cpu)
{
_PR_MD_SUSPEND_THREAD(cpu->thread);
}
@@ -317,13 +317,13 @@ void
_PR_MD_SUSPEND_THREAD(PRThread *thread)
{
if (_PR_IS_NATIVE_THREAD(thread)) {
- APIRET rc;
+ APIRET rc;
/* XXXMB - DosSuspendThread() is not a blocking call; how do we
* know when the thread is *REALLY* suspended?
*/
- rc = DosSuspendThread(thread->md.handle);
- PR_ASSERT(rc == NO_ERROR);
+ rc = DosSuspendThread(thread->md.handle);
+ PR_ASSERT(rc == NO_ERROR);
}
}
diff --git a/nsprpub/pr/src/md/prosdep.c b/nsprpub/pr/src/md/prosdep.c
index 137ffaecc..0b1f3e597 100644
--- a/nsprpub/pr/src/md/prosdep.c
+++ b/nsprpub/pr/src/md/prosdep.c
@@ -11,9 +11,6 @@
#endif
#ifdef _WIN32
#include <windows.h>
-#endif
-#ifdef XP_BEOS
-#include <OS.h>
#endif
PRInt32 _pr_pageShift;
@@ -24,14 +21,14 @@ PRInt32 _pr_pageSize;
*/
static void GetPageSize(void)
{
- PRInt32 pageSize;
+ PRInt32 pageSize;
/* Get page size */
#ifdef XP_UNIX
#if defined BSDI || defined AIX \
|| defined LINUX || defined __GNU__ || defined __GLIBC__ \
|| defined FREEBSD || defined NETBSD || defined OPENBSD \
- || defined DARWIN || defined SYMBIAN
+ || defined DARWIN
_pr_pageSize = getpagesize();
#elif defined(HPUX)
/* I have no idea. Don't get me started. --Rob */
@@ -41,10 +38,6 @@ static void GetPageSize(void)
#endif
#endif /* XP_UNIX */
-#ifdef XP_BEOS
- _pr_pageSize = B_PAGE_SIZE;
-#endif
-
#ifdef XP_PC
#ifdef _WIN32
SYSTEM_INFO info;
@@ -55,14 +48,14 @@ static void GetPageSize(void)
#endif
#endif /* XP_PC */
- pageSize = _pr_pageSize;
- PR_CEILING_LOG2(_pr_pageShift, pageSize);
+ pageSize = _pr_pageSize;
+ PR_CEILING_LOG2(_pr_pageShift, pageSize);
}
PR_IMPLEMENT(PRInt32) PR_GetPageShift(void)
{
if (!_pr_pageSize) {
- GetPageSize();
+ GetPageSize();
}
return _pr_pageShift;
}
@@ -70,7 +63,7 @@ PR_IMPLEMENT(PRInt32) PR_GetPageShift(void)
PR_IMPLEMENT(PRInt32) PR_GetPageSize(void)
{
if (!_pr_pageSize) {
- GetPageSize();
+ GetPageSize();
}
return _pr_pageSize;
}
diff --git a/nsprpub/pr/src/md/unix/aix.c b/nsprpub/pr/src/md/unix/aix.c
index 43f0d58de..c632c5790 100644
--- a/nsprpub/pr/src/md/unix/aix.c
+++ b/nsprpub/pr/src/md/unix/aix.c
@@ -73,7 +73,7 @@ int _pr_aix_send_file_use_disabled = 0;
void _MD_EarlyInit(void)
{
void *main_app_handle;
- char *evp;
+ char *evp;
main_app_handle = dlopen(NULL, RTLD_NOW);
PR_ASSERT(NULL != main_app_handle);
@@ -85,10 +85,11 @@ void _MD_EarlyInit(void)
}
dlclose(main_app_handle);
- if (evp = getenv("NSPR_AIX_SEND_FILE_USE_DISABLED")) {
- if (1 == atoi(evp))
- _pr_aix_send_file_use_disabled = 1;
- }
+ if (evp = getenv("NSPR_AIX_SEND_FILE_USE_DISABLED")) {
+ if (1 == atoi(evp)) {
+ _pr_aix_send_file_use_disabled = 1;
+ }
+ }
#if defined(AIX_TIMERS)
_MD_AixIntervalInit();
@@ -110,13 +111,13 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
#ifndef _PR_PTHREADS
if (isCurrent) {
- (void) setjmp(CONTEXT(t));
+ (void) setjmp(CONTEXT(t));
}
*np = sizeof(CONTEXT(t)) / sizeof(PRWord);
return (PRWord *) CONTEXT(t);
#else
- *np = 0;
- return NULL;
+ *np = 0;
+ return NULL;
#endif
}
@@ -130,7 +131,7 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri)
PR_IMPLEMENT(PRStatus)
_MD_InitializeThread(PRThread *thread)
{
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
PR_IMPLEMENT(PRStatus)
@@ -145,7 +146,7 @@ PR_IMPLEMENT(PRStatus)
_MD_WAKEUP_WAITER(PRThread *thread)
{
if (thread) {
- PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
+ PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
}
return PR_SUCCESS;
}
@@ -193,17 +194,17 @@ int _MD_SELECT(int width, fd_set *r, fd_set *w, fd_set *e, struct timeval *t)
if (!aix_select_fcn) {
void *aix_handle;
- aix_handle = dlopen("/unix", RTLD_NOW);
- if (!aix_handle) {
- PR_SetError(PR_UNKNOWN_ERROR, 0);
- return -1;
- }
- aix_select_fcn = (int(*)())dlsym(aix_handle,"select");
+ aix_handle = dlopen("/unix", RTLD_NOW);
+ if (!aix_handle) {
+ PR_SetError(PR_UNKNOWN_ERROR, 0);
+ return -1;
+ }
+ aix_select_fcn = (int(*)())dlsym(aix_handle,"select");
dlclose(aix_handle);
- if (!aix_select_fcn) {
- PR_SetError(PR_UNKNOWN_ERROR, 0);
- return -1;
- }
+ if (!aix_select_fcn) {
+ PR_SetError(PR_UNKNOWN_ERROR, 0);
+ return -1;
+ }
}
rv = (*aix_select_fcn)(width, r, w, e, t);
return rv;
@@ -216,17 +217,17 @@ int _MD_POLL(void *listptr, unsigned long nfds, long timeout)
if (!aix_poll_fcn) {
void *aix_handle;
- aix_handle = dlopen("/unix", RTLD_NOW);
- if (!aix_handle) {
- PR_SetError(PR_UNKNOWN_ERROR, 0);
- return -1;
- }
- aix_poll_fcn = (int(*)())dlsym(aix_handle,"poll");
+ aix_handle = dlopen("/unix", RTLD_NOW);
+ if (!aix_handle) {
+ PR_SetError(PR_UNKNOWN_ERROR, 0);
+ return -1;
+ }
+ aix_poll_fcn = (int(*)())dlsym(aix_handle,"poll");
dlclose(aix_handle);
- if (!aix_poll_fcn) {
- PR_SetError(PR_UNKNOWN_ERROR, 0);
- return -1;
- }
+ if (!aix_poll_fcn) {
+ PR_SetError(PR_UNKNOWN_ERROR, 0);
+ return -1;
+ }
}
rv = (*aix_poll_fcn)(listptr, nfds, timeout);
return rv;
@@ -251,51 +252,51 @@ void _pr_aix_dummy()
#include "pratom.h"
-#define _PR_AIX_ATOMIC_LOCK -1
+#define _PR_AIX_ATOMIC_LOCK -1
PR_IMPLEMENT(void)
PR_StackPush(PRStack *stack, PRStackElem *stack_elem)
{
-PRStackElem *addr;
-boolean_t locked = TRUE;
-
- /* Is it safe to cast a pointer to an int? */
- PR_ASSERT(sizeof(int) == sizeof(PRStackElem *));
- do {
- while ((addr = stack->prstk_head.prstk_elem_next) ==
- (PRStackElem *)_PR_AIX_ATOMIC_LOCK)
- ;
- locked = _check_lock((atomic_p) &stack->prstk_head.prstk_elem_next,
- (int) addr, _PR_AIX_ATOMIC_LOCK);
- } while (locked == TRUE);
- stack_elem->prstk_elem_next = addr;
- _clear_lock((atomic_p)&stack->prstk_head.prstk_elem_next, (int)stack_elem);
+ PRStackElem *addr;
+ boolean_t locked = TRUE;
+
+ /* Is it safe to cast a pointer to an int? */
+ PR_ASSERT(sizeof(int) == sizeof(PRStackElem *));
+ do {
+ while ((addr = stack->prstk_head.prstk_elem_next) ==
+ (PRStackElem *)_PR_AIX_ATOMIC_LOCK)
+ ;
+ locked = _check_lock((atomic_p) &stack->prstk_head.prstk_elem_next,
+ (int) addr, _PR_AIX_ATOMIC_LOCK);
+ } while (locked == TRUE);
+ stack_elem->prstk_elem_next = addr;
+ _clear_lock((atomic_p)&stack->prstk_head.prstk_elem_next, (int)stack_elem);
return;
}
PR_IMPLEMENT(PRStackElem *)
PR_StackPop(PRStack *stack)
{
-PRStackElem *element;
-boolean_t locked = TRUE;
-
- /* Is it safe to cast a pointer to an int? */
- PR_ASSERT(sizeof(int) == sizeof(PRStackElem *));
- do {
- while ((element = stack->prstk_head.prstk_elem_next) ==
- (PRStackElem *) _PR_AIX_ATOMIC_LOCK)
- ;
- locked = _check_lock((atomic_p) &stack->prstk_head.prstk_elem_next,
- (int)element, _PR_AIX_ATOMIC_LOCK);
- } while (locked == TRUE);
-
- if (element == NULL) {
- _clear_lock((atomic_p) &stack->prstk_head.prstk_elem_next, NULL);
- } else {
- _clear_lock((atomic_p) &stack->prstk_head.prstk_elem_next,
- (int) element->prstk_elem_next);
- }
- return element;
+ PRStackElem *element;
+ boolean_t locked = TRUE;
+
+ /* Is it safe to cast a pointer to an int? */
+ PR_ASSERT(sizeof(int) == sizeof(PRStackElem *));
+ do {
+ while ((element = stack->prstk_head.prstk_elem_next) ==
+ (PRStackElem *) _PR_AIX_ATOMIC_LOCK)
+ ;
+ locked = _check_lock((atomic_p) &stack->prstk_head.prstk_elem_next,
+ (int)element, _PR_AIX_ATOMIC_LOCK);
+ } while (locked == TRUE);
+
+ if (element == NULL) {
+ _clear_lock((atomic_p) &stack->prstk_head.prstk_elem_next, NULL);
+ } else {
+ _clear_lock((atomic_p) &stack->prstk_head.prstk_elem_next,
+ (int) element->prstk_elem_next);
+ }
+ return element;
}
-#endif /* _PR_HAVE_ATOMIC_CAS */
+#endif /* _PR_HAVE_ATOMIC_CAS */
diff --git a/nsprpub/pr/src/md/unix/aixwrap.c b/nsprpub/pr/src/md/unix/aixwrap.c
index cb5b413f1..853825196 100644
--- a/nsprpub/pr/src/md/unix/aixwrap.c
+++ b/nsprpub/pr/src/md/unix/aixwrap.c
@@ -4,7 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
- * File: aixwrap.c
+ * File: aixwrap.c
* Description:
* This file contains a single function, _MD_SELECT(), which simply
* invokes the select() function. This file is used in an ugly
diff --git a/nsprpub/pr/src/md/unix/bsdi.c b/nsprpub/pr/src/md/unix/bsdi.c
index 095547ed5..e625003f7 100644
--- a/nsprpub/pr/src/md/unix/bsdi.c
+++ b/nsprpub/pr/src/md/unix/bsdi.c
@@ -25,7 +25,7 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
#ifndef _PR_PTHREADS
if (isCurrent) {
- (void) setjmp(CONTEXT(t));
+ (void) setjmp(CONTEXT(t));
}
*np = sizeof(CONTEXT(t)) / sizeof(PRWord);
return (PRWord *) CONTEXT(t);
@@ -45,7 +45,7 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri)
PRStatus
_MD_InitializeThread(PRThread *thread)
{
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
PRStatus
@@ -60,7 +60,7 @@ PRStatus
_MD_WAKEUP_WAITER(PRThread *thread)
{
if (thread) {
- PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
+ PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
}
return PR_SUCCESS;
}
@@ -82,6 +82,6 @@ _MD_CREATE_THREAD(
PRUint32 stackSize)
{
PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for BSDI.");
- return PR_FAILURE;
+ return PR_FAILURE;
}
#endif /* ! _PR_PTHREADS */
diff --git a/nsprpub/pr/src/md/unix/darwin.c b/nsprpub/pr/src/md/unix/darwin.c
index 719fc30f2..6135e082f 100644
--- a/nsprpub/pr/src/md/unix/darwin.c
+++ b/nsprpub/pr/src/md/unix/darwin.c
@@ -48,13 +48,13 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
#if !defined(_PR_PTHREADS)
if (isCurrent) {
- (void) setjmp(CONTEXT(t));
+ (void) setjmp(CONTEXT(t));
}
*np = sizeof(CONTEXT(t)) / sizeof(PRWord);
return (PRWord *) CONTEXT(t);
#else
- *np = 0;
- return NULL;
+ *np = 0;
+ return NULL;
#endif
}
@@ -68,7 +68,7 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri)
PRStatus
_MD_InitializeThread(PRThread *thread)
{
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
PRStatus
@@ -83,7 +83,7 @@ PRStatus
_MD_WAKEUP_WAITER(PRThread *thread)
{
if (thread) {
- PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
+ PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
}
return PR_SUCCESS;
}
@@ -105,7 +105,7 @@ _MD_CREATE_THREAD(
PRUint32 stackSize)
{
PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for Darwin.");
- return PR_FAILURE;
+ return PR_FAILURE;
}
#endif /* ! _PR_PTHREADS */
diff --git a/nsprpub/pr/src/md/unix/freebsd.c b/nsprpub/pr/src/md/unix/freebsd.c
index a66a81284..19af17a44 100644
--- a/nsprpub/pr/src/md/unix/freebsd.c
+++ b/nsprpub/pr/src/md/unix/freebsd.c
@@ -25,13 +25,13 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
#ifndef _PR_PTHREADS
if (isCurrent) {
- (void) sigsetjmp(CONTEXT(t), 1);
+ (void) sigsetjmp(CONTEXT(t), 1);
}
*np = sizeof(CONTEXT(t)) / sizeof(PRWord);
return (PRWord *) CONTEXT(t);
#else
- *np = 0;
- return NULL;
+ *np = 0;
+ return NULL;
#endif
}
@@ -45,7 +45,7 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri)
PRStatus
_MD_InitializeThread(PRThread *thread)
{
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
PRStatus
@@ -60,7 +60,7 @@ PRStatus
_MD_WAKEUP_WAITER(PRThread *thread)
{
if (thread) {
- PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
+ PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
}
return PR_SUCCESS;
}
@@ -82,6 +82,6 @@ _MD_CREATE_THREAD(
PRUint32 stackSize)
{
PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for FreeBSD.");
- return PR_FAILURE;
+ return PR_FAILURE;
}
#endif /* ! _PR_PTHREADS */
diff --git a/nsprpub/pr/src/md/unix/hpux.c b/nsprpub/pr/src/md/unix/hpux.c
index 56fddba29..bf72567fd 100644
--- a/nsprpub/pr/src/md/unix/hpux.c
+++ b/nsprpub/pr/src/md/unix/hpux.c
@@ -84,7 +84,7 @@ void _MD_EarlyInit(void)
if(!setjmp(jb)) {
newstack = (char *) PR_MALLOC(PIDOOMA_STACK_SIZE);
- oldstack = (char *) (*(((int *) jb) + 1) - BACKTRACE_SIZE);
+ oldstack = (char *) (*(((int *) jb) + 1) - BACKTRACE_SIZE);
memcpy(newstack, oldstack, BACKTRACE_SIZE);
*(((int *) jb) + 1) = (int) (newstack + BACKTRACE_SIZE);
longjmp(jb, 1);
@@ -98,13 +98,13 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
#ifndef _PR_PTHREADS
if (isCurrent) {
- (void) setjmp(CONTEXT(t));
+ (void) setjmp(CONTEXT(t));
}
*np = sizeof(CONTEXT(t)) / sizeof(PRWord);
return (PRWord *) CONTEXT(t);
#else
- *np = 0;
- return NULL;
+ *np = 0;
+ return NULL;
#endif
}
@@ -118,7 +118,7 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri)
PRStatus
_MD_InitializeThread(PRThread *thread)
{
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
PRStatus
@@ -133,7 +133,7 @@ PRStatus
_MD_WAKEUP_WAITER(PRThread *thread)
{
if (thread) {
- PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
+ PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
}
return PR_SUCCESS;
}
@@ -208,7 +208,7 @@ strchr(const char *s, int c)
* A.09.07, and B.10.10) dumps core if called with:
* 1. First operand with address = 1(mod 4).
* 2. Size = 1(mod 4)
- * 3. Last byte of the second operand is the last byte of the page and
+ * 3. Last byte of the second operand is the last byte of the page and
* next page is not accessible(not mapped or protected)
* Thus, using the following naive version (tons of optimizations are
* possible;^)
@@ -217,13 +217,15 @@ strchr(const char *s, int c)
int memcmp(const void *s1, const void *s2, size_t n)
{
register unsigned char *p1 = (unsigned char *) s1,
- *p2 = (unsigned char *) s2;
+ *p2 = (unsigned char *) s2;
while (n-- > 0) {
- register int r = ((int) ((unsigned int) *p1))
- - ((int) ((unsigned int) *p2));
- if (r) return r;
+ register int r = ((int) ((unsigned int) *p1))
+ - ((int) ((unsigned int) *p2));
+ if (r) {
+ return r;
+ }
p1++; p2++;
}
- return 0;
+ return 0;
}
diff --git a/nsprpub/pr/src/md/unix/irix.c b/nsprpub/pr/src/md/unix/irix.c
deleted file mode 100644
index c57a07b33..000000000
--- a/nsprpub/pr/src/md/unix/irix.c
+++ /dev/null
@@ -1,1648 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "primpl.h"
-
-#include <signal.h>
-
-#include <sys/types.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/mman.h>
-#include <sys/syssgi.h>
-#include <sys/time.h>
-#include <sys/immu.h>
-#include <sys/utsname.h>
-#include <sys/sysmp.h>
-#include <sys/pda.h>
-#include <sys/prctl.h>
-#include <sys/wait.h>
-#include <sys/resource.h>
-#include <sys/procfs.h>
-#include <task.h>
-#include <dlfcn.h>
-
-static void _MD_IrixIntervalInit(void);
-
-#if defined(_PR_PTHREADS)
-/*
- * for compatibility with classic nspr
- */
-void _PR_IRIX_CHILD_PROCESS()
-{
-}
-#else /* defined(_PR_PTHREADS) */
-
-static void irix_detach_sproc(void);
-char *_nspr_sproc_private; /* ptr. to private region in every sproc */
-
-extern PRUintn _pr_numCPU;
-
-typedef struct nspr_arena {
- PRCList links;
- usptr_t *usarena;
-} nspr_arena;
-
-#define ARENA_PTR(qp) \
- ((nspr_arena *) ((char*) (qp) - offsetof(nspr_arena , links)))
-
-static usptr_t *alloc_new_arena(void);
-
-PRCList arena_list = PR_INIT_STATIC_CLIST(&arena_list);
-ulock_t arena_list_lock;
-nspr_arena first_arena;
-int _nspr_irix_arena_cnt = 1;
-
-PRCList sproc_list = PR_INIT_STATIC_CLIST(&sproc_list);
-ulock_t sproc_list_lock;
-
-typedef struct sproc_data {
- void (*entry) (void *, size_t);
- unsigned inh;
- void *arg;
- caddr_t sp;
- size_t len;
- int *pid;
- int creator_pid;
-} sproc_data;
-
-typedef struct sproc_params {
- PRCList links;
- sproc_data sd;
-} sproc_params;
-
-#define SPROC_PARAMS_PTR(qp) \
- ((sproc_params *) ((char*) (qp) - offsetof(sproc_params , links)))
-
-long _nspr_irix_lock_cnt = 0;
-long _nspr_irix_sem_cnt = 0;
-long _nspr_irix_pollsem_cnt = 0;
-
-usptr_t *_pr_usArena;
-ulock_t _pr_heapLock;
-
-usema_t *_pr_irix_exit_sem;
-PRInt32 _pr_irix_exit_now = 0;
-PRInt32 _pr_irix_process_exit_code = 0; /* exit code for PR_ProcessExit */
-PRInt32 _pr_irix_process_exit = 0; /* process exiting due to call to
- PR_ProcessExit */
-
-int _pr_irix_primoridal_cpu_fd[2] = { -1, -1 };
-static void (*libc_exit)(int) = NULL;
-static void *libc_handle = NULL;
-
-#define _NSPR_DEF_INITUSERS 100 /* default value of CONF_INITUSERS */
-#define _NSPR_DEF_INITSIZE (4 * 1024 * 1024) /* 4 MB */
-
-int _irix_initusers = _NSPR_DEF_INITUSERS;
-int _irix_initsize = _NSPR_DEF_INITSIZE;
-
-PRIntn _pr_io_in_progress, _pr_clock_in_progress;
-
-PRInt32 _pr_md_irix_sprocs_created, _pr_md_irix_sprocs_failed;
-PRInt32 _pr_md_irix_sprocs = 1;
-PRCList _pr_md_irix_sproc_list =
-PR_INIT_STATIC_CLIST(&_pr_md_irix_sproc_list);
-
-sigset_t ints_off;
-extern sigset_t timer_set;
-
-#if !defined(PR_SETABORTSIG)
-#define PR_SETABORTSIG 18
-#endif
-/*
- * terminate the entire application if any sproc exits abnormally
- */
-PRBool _nspr_terminate_on_error = PR_TRUE;
-
-/*
- * exported interface to set the shared arena parameters
- */
-void _PR_Irix_Set_Arena_Params(PRInt32 initusers, PRInt32 initsize)
-{
- _irix_initusers = initusers;
- _irix_initsize = initsize;
-}
-
-static usptr_t *alloc_new_arena()
-{
- return(usinit("/dev/zero"));
-}
-
-static PRStatus new_poll_sem(struct _MDThread *mdthr, int val)
-{
-PRIntn _is;
-PRStatus rv = PR_SUCCESS;
-usema_t *sem = NULL;
-PRCList *qp;
-nspr_arena *arena;
-usptr_t *irix_arena;
-PRThread *me = _MD_GET_ATTACHED_THREAD();
-
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(_is);
- _PR_LOCK(arena_list_lock);
- for (qp = arena_list.next; qp != &arena_list; qp = qp->next) {
- arena = ARENA_PTR(qp);
- sem = usnewpollsema(arena->usarena, val);
- if (sem != NULL) {
- mdthr->cvar_pollsem = sem;
- mdthr->pollsem_arena = arena->usarena;
- break;
- }
- }
- if (sem == NULL) {
- /*
- * If no space left in the arena allocate a new one.
- */
- if (errno == ENOMEM) {
- arena = PR_NEWZAP(nspr_arena);
- if (arena != NULL) {
- irix_arena = alloc_new_arena();
- if (irix_arena) {
- PR_APPEND_LINK(&arena->links, &arena_list);
- _nspr_irix_arena_cnt++;
- arena->usarena = irix_arena;
- sem = usnewpollsema(arena->usarena, val);
- if (sem != NULL) {
- mdthr->cvar_pollsem = sem;
- mdthr->pollsem_arena = arena->usarena;
- } else
- rv = PR_FAILURE;
- } else {
- PR_DELETE(arena);
- rv = PR_FAILURE;
- }
-
- } else
- rv = PR_FAILURE;
- } else
- rv = PR_FAILURE;
- }
- _PR_UNLOCK(arena_list_lock);
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(_is);
- if (rv == PR_SUCCESS)
- _MD_ATOMIC_INCREMENT(&_nspr_irix_pollsem_cnt);
- return rv;
-}
-
-static void free_poll_sem(struct _MDThread *mdthr)
-{
-PRIntn _is;
-PRThread *me = _MD_GET_ATTACHED_THREAD();
-
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(_is);
- usfreepollsema(mdthr->cvar_pollsem, mdthr->pollsem_arena);
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(_is);
- _MD_ATOMIC_DECREMENT(&_nspr_irix_pollsem_cnt);
-}
-
-static PRStatus new_lock(struct _MDLock *lockp)
-{
-PRIntn _is;
-PRStatus rv = PR_SUCCESS;
-ulock_t lock = NULL;
-PRCList *qp;
-nspr_arena *arena;
-usptr_t *irix_arena;
-PRThread *me = _MD_GET_ATTACHED_THREAD();
-
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(_is);
- _PR_LOCK(arena_list_lock);
- for (qp = arena_list.next; qp != &arena_list; qp = qp->next) {
- arena = ARENA_PTR(qp);
- lock = usnewlock(arena->usarena);
- if (lock != NULL) {
- lockp->lock = lock;
- lockp->arena = arena->usarena;
- break;
- }
- }
- if (lock == NULL) {
- /*
- * If no space left in the arena allocate a new one.
- */
- if (errno == ENOMEM) {
- arena = PR_NEWZAP(nspr_arena);
- if (arena != NULL) {
- irix_arena = alloc_new_arena();
- if (irix_arena) {
- PR_APPEND_LINK(&arena->links, &arena_list);
- _nspr_irix_arena_cnt++;
- arena->usarena = irix_arena;
- lock = usnewlock(irix_arena);
- if (lock != NULL) {
- lockp->lock = lock;
- lockp->arena = arena->usarena;
- } else
- rv = PR_FAILURE;
- } else {
- PR_DELETE(arena);
- rv = PR_FAILURE;
- }
-
- } else
- rv = PR_FAILURE;
- } else
- rv = PR_FAILURE;
- }
- _PR_UNLOCK(arena_list_lock);
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(_is);
- if (rv == PR_SUCCESS)
- _MD_ATOMIC_INCREMENT(&_nspr_irix_lock_cnt);
- return rv;
-}
-
-static void free_lock(struct _MDLock *lockp)
-{
-PRIntn _is;
-PRThread *me = _MD_GET_ATTACHED_THREAD();
-
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(_is);
- usfreelock(lockp->lock, lockp->arena);
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(_is);
- _MD_ATOMIC_DECREMENT(&_nspr_irix_lock_cnt);
-}
-
-void _MD_FREE_LOCK(struct _MDLock *lockp)
-{
- PRIntn _is;
- PRThread *me = _MD_GET_ATTACHED_THREAD();
-
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(_is);
- free_lock(lockp);
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(_is);
-}
-
-/*
- * _MD_get_attached_thread
- * Return the thread pointer of the current thread if it is attached.
- *
- * This function is needed for Irix because the thread-local-storage is
- * implemented by mmapin'g a page with the MAP_LOCAL flag. This causes the
- * sproc-private page to inherit contents of the page of the caller of sproc().
- */
-PRThread *_MD_get_attached_thread(void)
-{
-
- if (_MD_GET_SPROC_PID() == get_pid())
- return _MD_THIS_THREAD();
- else
- return 0;
-}
-
-/*
- * _MD_get_current_thread
- * Return the thread pointer of the current thread (attaching it if
- * necessary)
- */
-PRThread *_MD_get_current_thread(void)
-{
-PRThread *me;
-
- me = _MD_GET_ATTACHED_THREAD();
- if (NULL == me) {
- me = _PRI_AttachThread(
- PR_USER_THREAD, PR_PRIORITY_NORMAL, NULL, 0);
- }
- PR_ASSERT(me != NULL);
- return(me);
-}
-
-/*
- * irix_detach_sproc
- * auto-detach a sproc when it exits
- */
-void irix_detach_sproc(void)
-{
-PRThread *me;
-
- me = _MD_GET_ATTACHED_THREAD();
- if ((me != NULL) && (me->flags & _PR_ATTACHED)) {
- _PRI_DetachThread();
- }
-}
-
-
-PRStatus _MD_NEW_LOCK(struct _MDLock *lockp)
-{
- PRStatus rv;
- PRIntn is;
- PRThread *me = _MD_GET_ATTACHED_THREAD();
-
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
- rv = new_lock(lockp);
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
- return rv;
-}
-
-static void
-sigchld_handler(int sig)
-{
- pid_t pid;
- int status;
-
- /*
- * If an sproc exited abnormally send a SIGKILL signal to all the
- * sprocs in the process to terminate the application
- */
- while ((pid = waitpid(0, &status, WNOHANG)) > 0) {
- if (WIFSIGNALED(status) && ((WTERMSIG(status) == SIGSEGV) ||
- (WTERMSIG(status) == SIGBUS) ||
- (WTERMSIG(status) == SIGABRT) ||
- (WTERMSIG(status) == SIGILL))) {
-
- prctl(PR_SETEXITSIG, SIGKILL);
- _exit(status);
- }
- }
-}
-
-static void save_context_and_block(int sig)
-{
-PRThread *me = _PR_MD_CURRENT_THREAD();
-_PRCPU *cpu = _PR_MD_CURRENT_CPU();
-
- /*
- * save context
- */
- (void) setjmp(me->md.jb);
- /*
- * unblock the suspending thread
- */
- if (me->cpu) {
- /*
- * I am a cpu thread, not a user-created GLOBAL thread
- */
- unblockproc(cpu->md.suspending_id);
- } else {
- unblockproc(me->md.suspending_id);
- }
- /*
- * now, block current thread
- */
- blockproc(getpid());
-}
-
-/*
-** The irix kernel has a bug in it which causes async connect's which are
-** interrupted by a signal to fail terribly (EADDRINUSE is returned).
-** We work around the bug by blocking signals during the async connect
-** attempt.
-*/
-PRInt32 _MD_irix_connect(
- PRInt32 osfd, const PRNetAddr *addr, PRInt32 addrlen, PRIntervalTime timeout)
-{
- PRInt32 rv;
- sigset_t oldset;
-
- sigprocmask(SIG_BLOCK, &ints_off, &oldset);
- rv = connect(osfd, addr, addrlen);
- sigprocmask(SIG_SETMASK, &oldset, 0);
-
- return(rv);
-}
-
-#include "prprf.h"
-
-/********************************************************************/
-/********************************************************************/
-/*************** Various thread like things for IRIX ****************/
-/********************************************************************/
-/********************************************************************/
-
-void *_MD_GetSP(PRThread *t)
-{
- PRThread *me = _PR_MD_CURRENT_THREAD();
- void *sp;
-
- if (me == t)
- (void) setjmp(t->md.jb);
-
- sp = (void *)(t->md.jb[JB_SP]);
- PR_ASSERT((sp >= (void *) t->stack->stackBottom) &&
- (sp <= (void *) (t->stack->stackBottom + t->stack->stackSize)));
- return(sp);
-}
-
-void _MD_InitLocks()
-{
- char buf[200];
- char *init_users, *init_size;
-
- PR_snprintf(buf, sizeof(buf), "/dev/zero");
-
- if (init_users = getenv("_NSPR_IRIX_INITUSERS"))
- _irix_initusers = atoi(init_users);
-
- if (init_size = getenv("_NSPR_IRIX_INITSIZE"))
- _irix_initsize = atoi(init_size);
-
- usconfig(CONF_INITUSERS, _irix_initusers);
- usconfig(CONF_INITSIZE, _irix_initsize);
- usconfig(CONF_AUTOGROW, 1);
- usconfig(CONF_AUTORESV, 1);
- if (usconfig(CONF_ARENATYPE, US_SHAREDONLY) < 0) {
- perror("PR_Init: unable to config mutex arena");
- exit(-1);
- }
-
- _pr_usArena = usinit(buf);
- if (!_pr_usArena) {
- fprintf(stderr,
- "PR_Init: Error - unable to create lock/monitor arena\n");
- exit(-1);
- }
- _pr_heapLock = usnewlock(_pr_usArena);
- _nspr_irix_lock_cnt++;
-
- arena_list_lock = usnewlock(_pr_usArena);
- _nspr_irix_lock_cnt++;
-
- sproc_list_lock = usnewlock(_pr_usArena);
- _nspr_irix_lock_cnt++;
-
- _pr_irix_exit_sem = usnewsema(_pr_usArena, 0);
- _nspr_irix_sem_cnt = 1;
-
- first_arena.usarena = _pr_usArena;
- PR_INIT_CLIST(&first_arena.links);
- PR_APPEND_LINK(&first_arena.links, &arena_list);
-}
-
-/* _PR_IRIX_CHILD_PROCESS is a private API for Server group */
-void _PR_IRIX_CHILD_PROCESS()
-{
-extern PRUint32 _pr_global_threads;
-
- PR_ASSERT(_PR_MD_CURRENT_CPU() == _pr_primordialCPU);
- PR_ASSERT(_pr_numCPU == 1);
- PR_ASSERT(_pr_global_threads == 0);
- /*
- * save the new pid
- */
- _pr_primordialCPU->md.id = getpid();
- _MD_SET_SPROC_PID(getpid());
-}
-
-static PRStatus pr_cvar_wait_sem(PRThread *thread, PRIntervalTime timeout)
-{
- int rv;
-
-#ifdef _PR_USE_POLL
- struct pollfd pfd;
- int msecs;
-
- if (timeout == PR_INTERVAL_NO_TIMEOUT)
- msecs = -1;
- else
- msecs = PR_IntervalToMilliseconds(timeout);
-#else
- struct timeval tv, *tvp;
- fd_set rd;
-
- if(timeout == PR_INTERVAL_NO_TIMEOUT)
- tvp = NULL;
- else {
- tv.tv_sec = PR_IntervalToSeconds(timeout);
- tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
- tvp = &tv;
- }
- FD_ZERO(&rd);
- FD_SET(thread->md.cvar_pollsemfd, &rd);
-#endif
-
- /*
- * call uspsema only if a previous select call on this semaphore
- * did not timeout
- */
- if (!thread->md.cvar_pollsem_select) {
- rv = _PR_WAIT_SEM(thread->md.cvar_pollsem);
- PR_ASSERT(rv >= 0);
- } else
- rv = 0;
-again:
- if(!rv) {
-#ifdef _PR_USE_POLL
- pfd.events = POLLIN;
- pfd.fd = thread->md.cvar_pollsemfd;
- rv = _MD_POLL(&pfd, 1, msecs);
-#else
- rv = _MD_SELECT(thread->md.cvar_pollsemfd + 1, &rd, NULL,NULL,tvp);
-#endif
- if ((rv == -1) && (errno == EINTR)) {
- rv = 0;
- goto again;
- }
- PR_ASSERT(rv >= 0);
- }
-
- if (rv > 0) {
- /*
- * acquired the semaphore, call uspsema next time
- */
- thread->md.cvar_pollsem_select = 0;
- return PR_SUCCESS;
- } else {
- /*
- * select timed out; must call select, not uspsema, when trying
- * to acquire the semaphore the next time
- */
- thread->md.cvar_pollsem_select = 1;
- return PR_FAILURE;
- }
-}
-
-PRStatus _MD_wait(PRThread *thread, PRIntervalTime ticks)
-{
- if ( thread->flags & _PR_GLOBAL_SCOPE ) {
- _MD_CHECK_FOR_EXIT();
- if (pr_cvar_wait_sem(thread, ticks) == PR_FAILURE) {
- _MD_CHECK_FOR_EXIT();
- /*
- * wait timed out
- */
- _PR_THREAD_LOCK(thread);
- if (thread->wait.cvar) {
- /*
- * The thread will remove itself from the waitQ
- * of the cvar in _PR_WaitCondVar
- */
- thread->wait.cvar = NULL;
- thread->state = _PR_RUNNING;
- _PR_THREAD_UNLOCK(thread);
- } else {
- _PR_THREAD_UNLOCK(thread);
- /*
- * This thread was woken up by a notifying thread
- * at the same time as a timeout; so, consume the
- * extra post operation on the semaphore
- */
- _MD_CHECK_FOR_EXIT();
- pr_cvar_wait_sem(thread, PR_INTERVAL_NO_TIMEOUT);
- }
- _MD_CHECK_FOR_EXIT();
- }
- } else {
- _PR_MD_SWITCH_CONTEXT(thread);
- }
- return PR_SUCCESS;
-}
-
-PRStatus _MD_WakeupWaiter(PRThread *thread)
-{
- PRThread *me = _PR_MD_CURRENT_THREAD();
- PRIntn is;
-
- PR_ASSERT(_pr_md_idle_cpus >= 0);
- if (thread == NULL) {
- if (_pr_md_idle_cpus)
- _MD_Wakeup_CPUs();
- } else if (!_PR_IS_NATIVE_THREAD(thread)) {
- if (_pr_md_idle_cpus)
- _MD_Wakeup_CPUs();
- } else {
- PR_ASSERT(_PR_IS_NATIVE_THREAD(thread));
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
- _MD_CVAR_POST_SEM(thread);
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
- }
- return PR_SUCCESS;
-}
-
-void create_sproc (void (*entry) (void *, size_t), unsigned inh,
- void *arg, caddr_t sp, size_t len, int *pid)
-{
-sproc_params sparams;
-char data;
-int rv;
-PRThread *me = _PR_MD_CURRENT_THREAD();
-
- if (!_PR_IS_NATIVE_THREAD(me) && (_PR_MD_CURRENT_CPU()->id == 0)) {
- *pid = sprocsp(entry, /* startup func */
- inh, /* attribute flags */
- arg, /* thread param */
- sp, /* stack address */
- len); /* stack size */
- } else {
- sparams.sd.entry = entry;
- sparams.sd.inh = inh;
- sparams.sd.arg = arg;
- sparams.sd.sp = sp;
- sparams.sd.len = len;
- sparams.sd.pid = pid;
- sparams.sd.creator_pid = getpid();
- _PR_LOCK(sproc_list_lock);
- PR_APPEND_LINK(&sparams.links, &sproc_list);
- rv = write(_pr_irix_primoridal_cpu_fd[1], &data, 1);
- PR_ASSERT(rv == 1);
- _PR_UNLOCK(sproc_list_lock);
- blockproc(getpid());
- }
-}
-
-/*
- * _PR_MD_WAKEUP_PRIMORDIAL_CPU
- *
- * wakeup cpu 0
- */
-
-void _PR_MD_WAKEUP_PRIMORDIAL_CPU()
-{
-char data = '0';
-int rv;
-
- rv = write(_pr_irix_primoridal_cpu_fd[1], &data, 1);
- PR_ASSERT(rv == 1);
-}
-
-/*
- * _PR_MD_primordial_cpu
- *
- * process events that need to executed by the primordial cpu on each
- * iteration through the idle loop
- */
-
-void _PR_MD_primordial_cpu()
-{
-PRCList *qp;
-sproc_params *sp;
-int pid;
-
- _PR_LOCK(sproc_list_lock);
- while ((qp = sproc_list.next) != &sproc_list) {
- sp = SPROC_PARAMS_PTR(qp);
- PR_REMOVE_LINK(&sp->links);
- pid = sp->sd.creator_pid;
- (*(sp->sd.pid)) = sprocsp(sp->sd.entry, /* startup func */
- sp->sd.inh, /* attribute flags */
- sp->sd.arg, /* thread param */
- sp->sd.sp, /* stack address */
- sp->sd.len); /* stack size */
- unblockproc(pid);
- }
- _PR_UNLOCK(sproc_list_lock);
-}
-
-PRStatus _MD_CreateThread(PRThread *thread,
-void (*start)(void *),
-PRThreadPriority priority,
-PRThreadScope scope,
-PRThreadState state,
-PRUint32 stackSize)
-{
- typedef void (*SprocEntry) (void *, size_t);
- SprocEntry spentry = (SprocEntry)start;
- PRIntn is;
- PRThread *me = _PR_MD_CURRENT_THREAD();
- PRInt32 pid;
- PRStatus rv;
-
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
- thread->md.cvar_pollsem_select = 0;
- thread->flags |= _PR_GLOBAL_SCOPE;
-
- thread->md.cvar_pollsemfd = -1;
- if (new_poll_sem(&thread->md,0) == PR_FAILURE) {
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
- return PR_FAILURE;
- }
- thread->md.cvar_pollsemfd =
- _PR_OPEN_POLL_SEM(thread->md.cvar_pollsem);
- if ((thread->md.cvar_pollsemfd < 0)) {
- free_poll_sem(&thread->md);
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
- return PR_FAILURE;
- }
-
- create_sproc(spentry, /* startup func */
- PR_SALL, /* attribute flags */
- (void *)thread, /* thread param */
- NULL, /* stack address */
- stackSize, &pid); /* stack size */
- if (pid > 0) {
- _MD_ATOMIC_INCREMENT(&_pr_md_irix_sprocs_created);
- _MD_ATOMIC_INCREMENT(&_pr_md_irix_sprocs);
- rv = PR_SUCCESS;
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
- return rv;
- } else {
- close(thread->md.cvar_pollsemfd);
- thread->md.cvar_pollsemfd = -1;
- free_poll_sem(&thread->md);
- thread->md.cvar_pollsem = NULL;
- _MD_ATOMIC_INCREMENT(&_pr_md_irix_sprocs_failed);
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
- return PR_FAILURE;
- }
-}
-
-void _MD_CleanThread(PRThread *thread)
-{
- if (thread->flags & _PR_GLOBAL_SCOPE) {
- close(thread->md.cvar_pollsemfd);
- thread->md.cvar_pollsemfd = -1;
- free_poll_sem(&thread->md);
- thread->md.cvar_pollsem = NULL;
- }
-}
-
-void _MD_SetPriority(_MDThread *thread, PRThreadPriority newPri)
-{
- return;
-}
-
-extern void _MD_unix_terminate_waitpid_daemon(void);
-
-void
-_MD_CleanupBeforeExit(void)
-{
- extern PRInt32 _pr_cpus_exit;
-
- _MD_unix_terminate_waitpid_daemon();
-
- _pr_irix_exit_now = 1;
- if (_pr_numCPU > 1) {
- /*
- * Set a global flag, and wakeup all cpus which will notice the flag
- * and exit.
- */
- _pr_cpus_exit = getpid();
- _MD_Wakeup_CPUs();
- while(_pr_numCPU > 1) {
- _PR_WAIT_SEM(_pr_irix_exit_sem);
- _pr_numCPU--;
- }
- }
- /*
- * cause global threads on the recycle list to exit
- */
- _PR_DEADQ_LOCK;
- if (_PR_NUM_DEADNATIVE != 0) {
- PRThread *thread;
- PRCList *ptr;
-
- ptr = _PR_DEADNATIVEQ.next;
- while( ptr != &_PR_DEADNATIVEQ ) {
- thread = _PR_THREAD_PTR(ptr);
- _MD_CVAR_POST_SEM(thread);
- ptr = ptr->next;
- }
- }
- _PR_DEADQ_UNLOCK;
- while(_PR_NUM_DEADNATIVE > 1) {
- _PR_WAIT_SEM(_pr_irix_exit_sem);
- _PR_DEC_DEADNATIVE;
- }
-}
-
-#ifdef _PR_HAVE_SGI_PRDA_PROCMASK
-extern void __sgi_prda_procmask(int);
-#endif
-
-PRStatus
-_MD_InitAttachedThread(PRThread *thread, PRBool wakeup_parent)
-{
- PRStatus rv = PR_SUCCESS;
-
- if (thread->flags & _PR_GLOBAL_SCOPE) {
- if (new_poll_sem(&thread->md,0) == PR_FAILURE) {
- return PR_FAILURE;
- }
- thread->md.cvar_pollsemfd =
- _PR_OPEN_POLL_SEM(thread->md.cvar_pollsem);
- if ((thread->md.cvar_pollsemfd < 0)) {
- free_poll_sem(&thread->md);
- return PR_FAILURE;
- }
- if (_MD_InitThread(thread, PR_FALSE) == PR_FAILURE) {
- close(thread->md.cvar_pollsemfd);
- thread->md.cvar_pollsemfd = -1;
- free_poll_sem(&thread->md);
- thread->md.cvar_pollsem = NULL;
- return PR_FAILURE;
- }
- }
- return rv;
-}
-
-PRStatus
-_MD_InitThread(PRThread *thread, PRBool wakeup_parent)
-{
- struct sigaction sigact;
- PRStatus rv = PR_SUCCESS;
-
- if (thread->flags & _PR_GLOBAL_SCOPE) {
- thread->md.id = getpid();
- setblockproccnt(thread->md.id, 0);
- _MD_SET_SPROC_PID(getpid());
-#ifdef _PR_HAVE_SGI_PRDA_PROCMASK
- /*
- * enable user-level processing of sigprocmask(); this is an
- * undocumented feature available in Irix 6.2, 6.3, 6.4 and 6.5
- */
- __sgi_prda_procmask(USER_LEVEL);
-#endif
- /*
- * set up SIGUSR1 handler; this is used to save state
- */
- sigact.sa_handler = save_context_and_block;
- sigact.sa_flags = SA_RESTART;
- /*
- * Must mask clock interrupts
- */
- sigact.sa_mask = timer_set;
- sigaction(SIGUSR1, &sigact, 0);
-
-
- /*
- * PR_SETABORTSIG is a new command implemented in a patch to
- * Irix 6.2, 6.3 and 6.4. This causes a signal to be sent to all
- * sprocs in the process when one of them terminates abnormally
- *
- */
- if (prctl(PR_SETABORTSIG, SIGKILL) < 0) {
- /*
- * if (errno == EINVAL)
- *
- * PR_SETABORTSIG not supported under this OS.
- * You may want to get a recent kernel rollup patch that
- * supports this feature.
- */
- }
- /*
- * SIGCLD handler for detecting abormally-terminating
- * sprocs and for reaping sprocs
- */
- sigact.sa_handler = sigchld_handler;
- sigact.sa_flags = SA_RESTART;
- sigact.sa_mask = ints_off;
- sigaction(SIGCLD, &sigact, NULL);
- }
- return rv;
-}
-
-/*
- * PR_Cleanup should be executed on the primordial sproc; migrate the thread
- * to the primordial cpu
- */
-
-void _PR_MD_PRE_CLEANUP(PRThread *me)
-{
-PRIntn is;
-_PRCPU *cpu = _pr_primordialCPU;
-
- PR_ASSERT(cpu);
-
- me->flags |= _PR_BOUND_THREAD;
-
- if (me->cpu->id != 0) {
- _PR_INTSOFF(is);
- _PR_RUNQ_LOCK(cpu);
- me->cpu = cpu;
- me->state = _PR_RUNNABLE;
- _PR_ADD_RUNQ(me, cpu, me->priority);
- _PR_RUNQ_UNLOCK(cpu);
- _MD_Wakeup_CPUs();
-
- _PR_MD_SWITCH_CONTEXT(me);
-
- _PR_FAST_INTSON(is);
- PR_ASSERT(me->cpu->id == 0);
- }
-}
-
-/*
- * process exiting
- */
-PR_EXTERN(void ) _MD_exit(PRIntn status)
-{
-PRThread *me = _PR_MD_CURRENT_THREAD();
-
- /*
- * the exit code of the process is the exit code of the primordial
- * sproc
- */
- if (!_PR_IS_NATIVE_THREAD(me) && (_PR_MD_CURRENT_CPU()->id == 0)) {
- /*
- * primordial sproc case: call _exit directly
- * Cause SIGKILL to be sent to other sprocs
- */
- prctl(PR_SETEXITSIG, SIGKILL);
- _exit(status);
- } else {
- int rv;
- char data;
- sigset_t set;
-
- /*
- * non-primordial sproc case: cause the primordial sproc, cpu 0,
- * to wakeup and call _exit
- */
- _pr_irix_process_exit = 1;
- _pr_irix_process_exit_code = status;
- rv = write(_pr_irix_primoridal_cpu_fd[1], &data, 1);
- PR_ASSERT(rv == 1);
- /*
- * block all signals and wait for SIGKILL to terminate this sproc
- */
- sigfillset(&set);
- sigsuspend(&set);
- /*
- * this code doesn't (shouldn't) execute
- */
- prctl(PR_SETEXITSIG, SIGKILL);
- _exit(status);
- }
-}
-
-/*
- * Override the exit() function in libc to cause the process to exit
- * when the primodial/main nspr thread calls exit. Calls to exit by any
- * other thread simply result in a call to the exit function in libc.
- * The exit code of the process is the exit code of the primordial
- * sproc.
- */
-
-void exit(int status)
-{
-PRThread *me, *thr;
-PRCList *qp;
-
- if (!_pr_initialized) {
- if (!libc_exit) {
-
- if (!libc_handle)
- libc_handle = dlopen("libc.so",RTLD_NOW);
- if (libc_handle)
- libc_exit = (void (*)(int)) dlsym(libc_handle, "exit");
- }
- if (libc_exit)
- (*libc_exit)(status);
- else
- _exit(status);
- }
-
- me = _PR_MD_CURRENT_THREAD();
-
- if (me == NULL) /* detached thread */
- (*libc_exit)(status);
-
- PR_ASSERT(_PR_IS_NATIVE_THREAD(me) ||
- (_PR_MD_CURRENT_CPU())->id == me->cpu->id);
-
- if (me->flags & _PR_PRIMORDIAL) {
-
- me->flags |= _PR_BOUND_THREAD;
-
- PR_ASSERT((_PR_MD_CURRENT_CPU())->id == me->cpu->id);
- if (me->cpu->id != 0) {
- _PRCPU *cpu = _pr_primordialCPU;
- PRIntn is;
-
- _PR_INTSOFF(is);
- _PR_RUNQ_LOCK(cpu);
- me->cpu = cpu;
- me->state = _PR_RUNNABLE;
- _PR_ADD_RUNQ(me, cpu, me->priority);
- _PR_RUNQ_UNLOCK(cpu);
- _MD_Wakeup_CPUs();
-
- _PR_MD_SWITCH_CONTEXT(me);
-
- _PR_FAST_INTSON(is);
- }
-
- PR_ASSERT((_PR_MD_CURRENT_CPU())->id == 0);
-
- if (prctl(PR_GETNSHARE) > 1) {
-#define SPROC_EXIT_WAIT_TIME 5
- int sleep_cnt = SPROC_EXIT_WAIT_TIME;
-
- /*
- * sprocs still running; caue cpus and recycled global threads
- * to exit
- */
- _pr_irix_exit_now = 1;
- if (_pr_numCPU > 1) {
- _MD_Wakeup_CPUs();
- }
- _PR_DEADQ_LOCK;
- if (_PR_NUM_DEADNATIVE != 0) {
- PRThread *thread;
- PRCList *ptr;
-
- ptr = _PR_DEADNATIVEQ.next;
- while( ptr != &_PR_DEADNATIVEQ ) {
- thread = _PR_THREAD_PTR(ptr);
- _MD_CVAR_POST_SEM(thread);
- ptr = ptr->next;
- }
- }
-
- while (sleep_cnt-- > 0) {
- if (waitpid(0, NULL, WNOHANG) >= 0)
- sleep(1);
- else
- break;
- }
- prctl(PR_SETEXITSIG, SIGKILL);
- }
- (*libc_exit)(status);
- } else {
- /*
- * non-primordial thread; simply call exit in libc.
- */
- (*libc_exit)(status);
- }
-}
-
-
-void
-_MD_InitRunningCPU(_PRCPU *cpu)
-{
- extern int _pr_md_pipefd[2];
-
- _MD_unix_init_running_cpu(cpu);
- cpu->md.id = getpid();
- _MD_SET_SPROC_PID(getpid());
- if (_pr_md_pipefd[0] >= 0) {
- _PR_IOQ_MAX_OSFD(cpu) = _pr_md_pipefd[0];
-#ifndef _PR_USE_POLL
- FD_SET(_pr_md_pipefd[0], &_PR_FD_READ_SET(cpu));
-#endif
- }
-}
-
-void
-_MD_ExitThread(PRThread *thread)
-{
- if (thread->flags & _PR_GLOBAL_SCOPE) {
- _MD_ATOMIC_DECREMENT(&_pr_md_irix_sprocs);
- _MD_CLEAN_THREAD(thread);
- _MD_SET_CURRENT_THREAD(NULL);
- }
-}
-
-void
-_MD_SuspendCPU(_PRCPU *cpu)
-{
- PRInt32 rv;
-
- cpu->md.suspending_id = getpid();
- rv = kill(cpu->md.id, SIGUSR1);
- PR_ASSERT(rv == 0);
- /*
- * now, block the current thread/cpu until woken up by the suspended
- * thread from it's SIGUSR1 signal handler
- */
- blockproc(getpid());
-
-}
-
-void
-_MD_ResumeCPU(_PRCPU *cpu)
-{
- unblockproc(cpu->md.id);
-}
-
-#if 0
-/*
- * save the register context of a suspended sproc
- */
-void get_context(PRThread *thr)
-{
- int len, fd;
- char pidstr[24];
- char path[24];
-
- /*
- * open the file corresponding to this process in procfs
- */
- sprintf(path,"/proc/%s","00000");
- len = strlen(path);
- sprintf(pidstr,"%d",thr->md.id);
- len -= strlen(pidstr);
- sprintf(path + len,"%s",pidstr);
- fd = open(path,O_RDONLY);
- if (fd >= 0) {
- (void) ioctl(fd, PIOCGREG, thr->md.gregs);
- close(fd);
- }
- return;
-}
-#endif /* 0 */
-
-void
-_MD_SuspendThread(PRThread *thread)
-{
- PRInt32 rv;
-
- PR_ASSERT((thread->flags & _PR_GLOBAL_SCOPE) &&
- _PR_IS_GCABLE_THREAD(thread));
-
- thread->md.suspending_id = getpid();
- rv = kill(thread->md.id, SIGUSR1);
- PR_ASSERT(rv == 0);
- /*
- * now, block the current thread/cpu until woken up by the suspended
- * thread from it's SIGUSR1 signal handler
- */
- blockproc(getpid());
-}
-
-void
-_MD_ResumeThread(PRThread *thread)
-{
- PR_ASSERT((thread->flags & _PR_GLOBAL_SCOPE) &&
- _PR_IS_GCABLE_THREAD(thread));
- (void)unblockproc(thread->md.id);
-}
-
-/*
- * return the set of processors available for scheduling procs in the
- * "mask" argument
- */
-PRInt32 _MD_GetThreadAffinityMask(PRThread *unused, PRUint32 *mask)
-{
- PRInt32 nprocs, rv;
- struct pda_stat *pstat;
-#define MAX_PROCESSORS 32
-
- nprocs = sysmp(MP_NPROCS);
- if (nprocs < 0)
- return(-1);
- pstat = (struct pda_stat*)PR_MALLOC(sizeof(struct pda_stat) * nprocs);
- if (pstat == NULL)
- return(-1);
- rv = sysmp(MP_STAT, pstat);
- if (rv < 0) {
- PR_DELETE(pstat);
- return(-1);
- }
- /*
- * look at the first 32 cpus
- */
- nprocs = (nprocs > MAX_PROCESSORS) ? MAX_PROCESSORS : nprocs;
- *mask = 0;
- while (nprocs) {
- if ((pstat->p_flags & PDAF_ENABLED) &&
- !(pstat->p_flags & PDAF_ISOLATED)) {
- *mask |= (1 << pstat->p_cpuid);
- }
- nprocs--;
- pstat++;
- }
- return 0;
-}
-
-static char *_thr_state[] = {
- "UNBORN",
- "RUNNABLE",
- "RUNNING",
- "LOCK_WAIT",
- "COND_WAIT",
- "JOIN_WAIT",
- "IO_WAIT",
- "SUSPENDED",
- "DEAD"
-};
-
-void _PR_List_Threads()
-{
- PRThread *thr;
- void *handle;
- struct _PRCPU *cpu;
- PRCList *qp;
- int len, fd;
- char pidstr[24];
- char path[24];
- prpsinfo_t pinfo;
-
-
- printf("\n%s %-s\n"," ","LOCAL Threads");
- printf("%s %-s\n"," ","----- -------");
- printf("%s %-14s %-10s %-12s %-3s %-10s %-10s %-12s\n\n"," ",
- "Thread", "State", "Wait-Handle",
- "Cpu","Stk-Base","Stk-Sz","SP");
- for (qp = _PR_ACTIVE_LOCAL_THREADQ().next;
- qp != &_PR_ACTIVE_LOCAL_THREADQ(); qp = qp->next) {
- thr = _PR_ACTIVE_THREAD_PTR(qp);
- printf("%s 0x%-12x %-10s "," ",thr,_thr_state[thr->state]);
- if (thr->state == _PR_LOCK_WAIT)
- handle = thr->wait.lock;
- else if (thr->state == _PR_COND_WAIT)
- handle = thr->wait.cvar;
- else
- handle = NULL;
- if (handle)
- printf("0x%-10x ",handle);
- else
- printf("%-12s "," ");
- printf("%-3d ",thr->cpu->id);
- printf("0x%-8x ",thr->stack->stackBottom);
- printf("0x%-8x ",thr->stack->stackSize);
- printf("0x%-10x\n",thr->md.jb[JB_SP]);
- }
-
- printf("\n%s %-s\n"," ","GLOBAL Threads");
- printf("%s %-s\n"," ","------ -------");
- printf("%s %-14s %-6s %-12s %-12s %-12s %-12s\n\n"," ","Thread",
- "Pid","State","Wait-Handle",
- "Stk-Base","Stk-Sz");
-
- for (qp = _PR_ACTIVE_GLOBAL_THREADQ().next;
- qp != &_PR_ACTIVE_GLOBAL_THREADQ(); qp = qp->next) {
- thr = _PR_ACTIVE_THREAD_PTR(qp);
- if (thr->cpu != NULL)
- continue; /* it is a cpu thread */
- printf("%s 0x%-12x %-6d "," ",thr,thr->md.id);
- /*
- * check if the sproc is still running
- * first call prctl(PR_GETSHMASK,pid) to check if
- * the process is part of the share group (the pid
- * could have been recycled by the OS)
- */
- if (prctl(PR_GETSHMASK,thr->md.id) < 0) {
- printf("%-12s\n","TERMINATED");
- continue;
- }
- /*
- * Now, check if the sproc terminated and is in zombie
- * state
- */
- sprintf(path,"/proc/pinfo/%s","00000");
- len = strlen(path);
- sprintf(pidstr,"%d",thr->md.id);
- len -= strlen(pidstr);
- sprintf(path + len,"%s",pidstr);
- fd = open(path,O_RDONLY);
- if (fd >= 0) {
- if (ioctl(fd, PIOCPSINFO, &pinfo) < 0)
- printf("%-12s ","TERMINATED");
- else if (pinfo.pr_zomb)
- printf("%-12s ","TERMINATED");
- else
- printf("%-12s ",_thr_state[thr->state]);
- close(fd);
- } else {
- printf("%-12s ","TERMINATED");
- }
-
- if (thr->state == _PR_LOCK_WAIT)
- handle = thr->wait.lock;
- else if (thr->state == _PR_COND_WAIT)
- handle = thr->wait.cvar;
- else
- handle = NULL;
- if (handle)
- printf("%-12x ",handle);
- else
- printf("%-12s "," ");
- printf("0x%-10x ",thr->stack->stackBottom);
- printf("0x%-10x\n",thr->stack->stackSize);
- }
-
- printf("\n%s %-s\n"," ","CPUs");
- printf("%s %-s\n"," ","----");
- printf("%s %-14s %-6s %-12s \n\n"," ","Id","Pid","State");
-
-
- for (qp = _PR_CPUQ().next; qp != &_PR_CPUQ(); qp = qp->next) {
- cpu = _PR_CPU_PTR(qp);
- printf("%s %-14d %-6d "," ",cpu->id,cpu->md.id);
- /*
- * check if the sproc is still running
- * first call prctl(PR_GETSHMASK,pid) to check if
- * the process is part of the share group (the pid
- * could have been recycled by the OS)
- */
- if (prctl(PR_GETSHMASK,cpu->md.id) < 0) {
- printf("%-12s\n","TERMINATED");
- continue;
- }
- /*
- * Now, check if the sproc terminated and is in zombie
- * state
- */
- sprintf(path,"/proc/pinfo/%s","00000");
- len = strlen(path);
- sprintf(pidstr,"%d",cpu->md.id);
- len -= strlen(pidstr);
- sprintf(path + len,"%s",pidstr);
- fd = open(path,O_RDONLY);
- if (fd >= 0) {
- if (ioctl(fd, PIOCPSINFO, &pinfo) < 0)
- printf("%-12s\n","TERMINATED");
- else if (pinfo.pr_zomb)
- printf("%-12s\n","TERMINATED");
- else
- printf("%-12s\n","RUNNING");
- close(fd);
- } else {
- printf("%-12s\n","TERMINATED");
- }
-
- }
- fflush(stdout);
-}
-#endif /* defined(_PR_PTHREADS) */
-
-PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
-{
-#if !defined(_PR_PTHREADS)
- if (isCurrent) {
- (void) setjmp(t->md.jb);
- }
- *np = sizeof(t->md.jb) / sizeof(PRWord);
- return (PRWord *) (t->md.jb);
-#else
- *np = 0;
- return NULL;
-#endif
-}
-
-void _MD_EarlyInit(void)
-{
-#if !defined(_PR_PTHREADS)
- char *eval;
- int fd;
- extern int __ateachexit(void (*func)(void));
-
- sigemptyset(&ints_off);
- sigaddset(&ints_off, SIGALRM);
- sigaddset(&ints_off, SIGIO);
- sigaddset(&ints_off, SIGCLD);
-
- if (eval = getenv("_NSPR_TERMINATE_ON_ERROR"))
- _nspr_terminate_on_error = (0 == atoi(eval) == 0) ? PR_FALSE : PR_TRUE;
-
- fd = open("/dev/zero",O_RDWR , 0);
- if (fd < 0) {
- perror("open /dev/zero failed");
- exit(1);
- }
- /*
- * Set up the sproc private data area.
- * This region exists at the same address, _nspr_sproc_private, for
- * every sproc, but each sproc gets a private copy of the region.
- */
- _nspr_sproc_private = (char*)mmap(0, _pr_pageSize, PROT_READ | PROT_WRITE,
- MAP_PRIVATE| MAP_LOCAL, fd, 0);
- if (_nspr_sproc_private == (void*)-1) {
- perror("mmap /dev/zero failed");
- exit(1);
- }
- _MD_SET_SPROC_PID(getpid());
- close(fd);
- __ateachexit(irix_detach_sproc);
-#endif
- _MD_IrixIntervalInit();
-} /* _MD_EarlyInit */
-
-void _MD_IrixInit(void)
-{
-#if !defined(_PR_PTHREADS)
- struct sigaction sigact;
- PRThread *me = _PR_MD_CURRENT_THREAD();
- int rv;
-
-#ifdef _PR_HAVE_SGI_PRDA_PROCMASK
- /*
- * enable user-level processing of sigprocmask(); this is an undocumented
- * feature available in Irix 6.2, 6.3, 6.4 and 6.5
- */
- __sgi_prda_procmask(USER_LEVEL);
-#endif
-
- /*
- * set up SIGUSR1 handler; this is used to save state
- * during PR_SuspendAll
- */
- sigact.sa_handler = save_context_and_block;
- sigact.sa_flags = SA_RESTART;
- sigact.sa_mask = ints_off;
- sigaction(SIGUSR1, &sigact, 0);
-
- /*
- * Change the name of the core file from core to core.pid,
- * This is inherited by the sprocs created by this process
- */
-#ifdef PR_COREPID
- prctl(PR_COREPID, 0, 1);
-#endif
- /*
- * Irix-specific terminate on error processing
- */
- /*
- * PR_SETABORTSIG is a new command implemented in a patch to
- * Irix 6.2, 6.3 and 6.4. This causes a signal to be sent to all
- * sprocs in the process when one of them terminates abnormally
- *
- */
- if (prctl(PR_SETABORTSIG, SIGKILL) < 0) {
- /*
- * if (errno == EINVAL)
- *
- * PR_SETABORTSIG not supported under this OS.
- * You may want to get a recent kernel rollup patch that
- * supports this feature.
- *
- */
- }
- /*
- * PR_SETEXITSIG - send the SIGCLD signal to the parent
- * sproc when any sproc terminates
- *
- * This is used to cause the entire application to
- * terminate when any sproc terminates abnormally by
- * receipt of a SIGSEGV, SIGBUS or SIGABRT signal.
- * If this is not done, the application may seem
- * "hung" to the user because the other sprocs may be
- * waiting for resources held by the
- * abnormally-terminating sproc.
- */
- prctl(PR_SETEXITSIG, 0);
-
- sigact.sa_handler = sigchld_handler;
- sigact.sa_flags = SA_RESTART;
- sigact.sa_mask = ints_off;
- sigaction(SIGCLD, &sigact, NULL);
-
- /*
- * setup stack fields for the primordial thread
- */
- me->stack->stackSize = prctl(PR_GETSTACKSIZE);
- me->stack->stackBottom = me->stack->stackTop - me->stack->stackSize;
-
- rv = pipe(_pr_irix_primoridal_cpu_fd);
- PR_ASSERT(rv == 0);
-#ifndef _PR_USE_POLL
- _PR_IOQ_MAX_OSFD(me->cpu) = _pr_irix_primoridal_cpu_fd[0];
- FD_SET(_pr_irix_primoridal_cpu_fd[0], &_PR_FD_READ_SET(me->cpu));
-#endif
-
- libc_handle = dlopen("libc.so",RTLD_NOW);
- PR_ASSERT(libc_handle != NULL);
- libc_exit = (void (*)(int)) dlsym(libc_handle, "exit");
- PR_ASSERT(libc_exit != NULL);
- /* dlclose(libc_handle); */
-
-#endif /* _PR_PTHREADS */
-
- _PR_UnixInit();
-}
-
-/**************************************************************************/
-/************** code and such for NSPR 2.0's interval times ***************/
-/**************************************************************************/
-
-#define PR_PSEC_PER_SEC 1000000000000ULL /* 10^12 */
-
-#ifndef SGI_CYCLECNTR_SIZE
-#define SGI_CYCLECNTR_SIZE 165 /* Size user needs to use to read CC */
-#endif
-
-static PRIntn mmem_fd = -1;
-static PRIntn clock_width = 0;
-static void *iotimer_addr = NULL;
-static PRUint32 pr_clock_mask = 0;
-static PRUint32 pr_clock_shift = 0;
-static PRIntervalTime pr_ticks = 0;
-static PRUint32 pr_clock_granularity = 1;
-static PRUint32 pr_previous = 0, pr_residual = 0;
-static PRUint32 pr_ticks_per_second = 0;
-
-extern PRIntervalTime _PR_UNIX_GetInterval(void);
-extern PRIntervalTime _PR_UNIX_TicksPerSecond(void);
-
-static void _MD_IrixIntervalInit(void)
-{
- /*
- * As much as I would like, the service available through this
- * interface on R3000's (aka, IP12) just isn't going to make it.
- * The register is only 24 bits wide, and rolls over at a verocious
- * rate.
- */
- PRUint32 one_tick = 0;
- struct utsname utsinfo;
- uname(&utsinfo);
- if ((strncmp("IP12", utsinfo.machine, 4) != 0)
- && ((mmem_fd = open("/dev/mmem", O_RDONLY)) != -1))
- {
- int poffmask = getpagesize() - 1;
- __psunsigned_t phys_addr, raddr, cycleval;
-
- phys_addr = syssgi(SGI_QUERY_CYCLECNTR, &cycleval);
- raddr = phys_addr & ~poffmask;
- iotimer_addr = mmap(
- 0, poffmask, PROT_READ, MAP_PRIVATE, mmem_fd, (__psint_t)raddr);
-
- clock_width = syssgi(SGI_CYCLECNTR_SIZE);
- if (clock_width < 0)
- {
- /*
- * We must be executing on a 6.0 or earlier system, since the
- * SGI_CYCLECNTR_SIZE call is not supported.
- *
- * The only pre-6.1 platforms with 64-bit counters are
- * IP19 and IP21 (Challenge, PowerChallenge, Onyx).
- */
- if (!strncmp(utsinfo.machine, "IP19", 4) ||
- !strncmp(utsinfo.machine, "IP21", 4))
- clock_width = 64;
- else
- clock_width = 32;
- }
-
- /*
- * 'cycleval' is picoseconds / increment of the counter.
- * I'm pushing for a tick to be 100 microseconds, 10^(-4).
- * That leaves 10^(-8) left over, or 10^8 / cycleval.
- * Did I do that right?
- */
-
- one_tick = 100000000UL / cycleval ; /* 100 microseconds */
-
- while (0 != one_tick)
- {
- pr_clock_shift += 1;
- one_tick = one_tick >> 1;
- pr_clock_granularity = pr_clock_granularity << 1;
- }
- pr_clock_mask = pr_clock_granularity - 1; /* to make a mask out of it */
- pr_ticks_per_second = PR_PSEC_PER_SEC
- / ((PRUint64)pr_clock_granularity * (PRUint64)cycleval);
-
- iotimer_addr = (void*)
- ((__psunsigned_t)iotimer_addr + (phys_addr & poffmask));
- }
- else
- {
- pr_ticks_per_second = _PR_UNIX_TicksPerSecond();
- }
-} /* _MD_IrixIntervalInit */
-
-PRIntervalTime _MD_IrixIntervalPerSec(void)
-{
- return pr_ticks_per_second;
-}
-
-PRIntervalTime _MD_IrixGetInterval(void)
-{
- if (mmem_fd != -1)
- {
- if (64 == clock_width)
- {
- PRUint64 temp = *(PRUint64*)iotimer_addr;
- pr_ticks = (PRIntervalTime)(temp >> pr_clock_shift);
- }
- else
- {
- PRIntervalTime ticks = pr_ticks;
- PRUint32 now = *(PRUint32*)iotimer_addr, temp;
- PRUint32 residual = pr_residual, previous = pr_previous;
-
- temp = now - previous + residual;
- residual = temp & pr_clock_mask;
- ticks += temp >> pr_clock_shift;
-
- pr_previous = now;
- pr_residual = residual;
- pr_ticks = ticks;
- }
- }
- else
- {
- /*
- * No fast access. Use the time of day clock. This isn't the
- * right answer since this clock can get set back, tick at odd
- * rates, and it's expensive to acqurie.
- */
- pr_ticks = _PR_UNIX_GetInterval();
- }
- return pr_ticks;
-} /* _MD_IrixGetInterval */
-
diff --git a/nsprpub/pr/src/md/unix/linux.c b/nsprpub/pr/src/md/unix/linux.c
index 1b485a024..6bfc7a802 100644
--- a/nsprpub/pr/src/md/unix/linux.c
+++ b/nsprpub/pr/src/md/unix/linux.c
@@ -13,13 +13,13 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
#ifndef _PR_PTHREADS
if (isCurrent) {
- (void) setjmp(CONTEXT(t));
+ (void) setjmp(CONTEXT(t));
}
*np = sizeof(CONTEXT(t)) / sizeof(PRWord);
return (PRWord *) CONTEXT(t);
#else
- *np = 0;
- return NULL;
+ *np = 0;
+ return NULL;
#endif
}
@@ -43,13 +43,13 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri)
PRStatus
_MD_InitializeThread(PRThread *thread)
{
- /*
- * set the pointers to the stack-pointer and frame-pointer words in the
- * context structure; this is for debugging use.
- */
- thread->md.sp = _MD_GET_SP_PTR(thread);
- thread->md.fp = _MD_GET_FP_PTR(thread);
- return PR_SUCCESS;
+ /*
+ * set the pointers to the stack-pointer and frame-pointer words in the
+ * context structure; this is for debugging use.
+ */
+ thread->md.sp = _MD_GET_SP_PTR(thread);
+ thread->md.fp = _MD_GET_FP_PTR(thread);
+ return PR_SUCCESS;
}
PRStatus
@@ -64,7 +64,7 @@ PRStatus
_MD_WAKEUP_WAITER(PRThread *thread)
{
if (thread) {
- PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
+ PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
}
return PR_SUCCESS;
}
@@ -86,6 +86,6 @@ _MD_CREATE_THREAD(
PRUint32 stackSize)
{
PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for Linux.");
- return PR_FAILURE;
+ return PR_FAILURE;
}
#endif /* ! _PR_PTHREADS */
diff --git a/nsprpub/pr/src/md/unix/nto.c b/nsprpub/pr/src/md/unix/nto.c
index e41d665ca..8ab8b1eab 100644
--- a/nsprpub/pr/src/md/unix/nto.c
+++ b/nsprpub/pr/src/md/unix/nto.c
@@ -10,8 +10,8 @@
/* Fake this out */
int socketpair (int foo, int foo2, int foo3, int sv[2])
{
- printf("error in socketpair\n");
- exit (-1);
+ printf("error in socketpair\n");
+ exit (-1);
}
void _MD_EarlyInit(void)
@@ -22,13 +22,13 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
#ifndef _PR_PTHREADS
if (isCurrent) {
- (void) setjmp(CONTEXT(t));
+ (void) setjmp(CONTEXT(t));
}
*np = sizeof(CONTEXT(t)) / sizeof(PRWord);
return (PRWord *) CONTEXT(t);
#else
- *np = 0;
- return NULL;
+ *np = 0;
+ return NULL;
#endif
}
diff --git a/nsprpub/pr/src/md/unix/os_Irix.s b/nsprpub/pr/src/md/unix/os_Irix.s
deleted file mode 100644
index ab1cb0b30..000000000
--- a/nsprpub/pr/src/md/unix/os_Irix.s
+++ /dev/null
@@ -1,134 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/*
- * Atomically add a new element to the top of the stack
- *
- * usage : PR_StackPush(listp, elementp);
- * -----------------------
- */
-
-#include "md/_irix.h"
-#ifdef _PR_HAVE_ATOMIC_CAS
-
-#include <sys/asm.h>
-#include <sys/regdef.h>
-
-LEAF(PR_StackPush)
-
-retry_push:
-.set noreorder
- lw v0,0(a0)
- li t1,1
- beq v0,t1,retry_push
- move t0,a1
-
- ll v0,0(a0)
- beq v0,t1,retry_push
- nop
- sc t1,0(a0)
- beq t1,0,retry_push
- nop
- sw v0,0(a1)
- sync
- sw t0,0(a0)
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- jr ra
- nop
-
-END(PR_StackPush)
-
-/*
- *
- * Atomically remove the element at the top of the stack
- *
- * usage : elemep = PR_StackPop(listp);
- *
- */
-
-LEAF(PR_StackPop)
-retry_pop:
-.set noreorder
-
-
- lw v0,0(a0)
- li t1,1
- beq v0,0,done
- nop
- beq v0,t1,retry_pop
- nop
-
- ll v0,0(a0)
- beq v0,0,done
- nop
- beq v0,t1,retry_pop
- nop
- sc t1,0(a0)
- beq t1,0,retry_pop
- nop
- lw t0,0(v0)
- sw t0,0(a0)
-done:
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- nop
- jr ra
- nop
-
-END(PR_StackPop)
-
-#endif /* _PR_HAVE_ATOMIC_CAS */
diff --git a/nsprpub/pr/src/md/unix/osf1.c b/nsprpub/pr/src/md/unix/osf1.c
deleted file mode 100644
index a9a1c67d0..000000000
--- a/nsprpub/pr/src/md/unix/osf1.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "primpl.h"
-
-void _MD_EarlyInit(void)
-{
-}
-
-PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
-{
-#ifndef _PR_PTHREADS
- if (isCurrent) {
- (void) setjmp(CONTEXT(t));
- }
- *np = sizeof(CONTEXT(t)) / sizeof(PRWord);
- return (PRWord *) CONTEXT(t);
-#else
- *np = 0;
- return NULL;
-#endif
-}
-
-#ifndef _PR_PTHREADS
-void
-_MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri)
-{
- return;
-}
-
-PRStatus
-_MD_InitializeThread(PRThread *thread)
-{
- return PR_SUCCESS;
-}
-
-PRStatus
-_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
-{
- PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
- _PR_MD_SWITCH_CONTEXT(thread);
- return PR_SUCCESS;
-}
-
-PRStatus
-_MD_WAKEUP_WAITER(PRThread *thread)
-{
- if (thread) {
- PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
- }
- return PR_SUCCESS;
-}
-
-/* These functions should not be called for OSF1 */
-void
-_MD_YIELD(void)
-{
- PR_NOT_REACHED("_MD_YIELD should not be called for OSF1.");
-}
-
-PRStatus
-_MD_CREATE_THREAD(
- PRThread *thread,
- void (*start) (void *),
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize)
-{
- PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for OSF1.");
- return PR_FAILURE;
-}
-#endif /* ! _PR_PTHREADS */
diff --git a/nsprpub/pr/src/md/unix/pthreads_user.c b/nsprpub/pr/src/md/unix/pthreads_user.c
index bb64b9f44..525c1576f 100644
--- a/nsprpub/pr/src/md/unix/pthreads_user.c
+++ b/nsprpub/pr/src/md/unix/pthreads_user.c
@@ -11,7 +11,7 @@
sigset_t ints_off;
-pthread_mutex_t _pr_heapLock;
+pthread_mutex_t _pr_heapLock;
pthread_key_t current_thread_key;
pthread_key_t current_cpu_key;
pthread_key_t last_thread_key;
@@ -23,55 +23,57 @@ PRInt32 _pr_md_pthreads = 1;
void _MD_EarlyInit(void)
{
-extern PRInt32 _nspr_noclock;
-
- if (pthread_key_create(&current_thread_key, NULL) != 0) {
- perror("pthread_key_create failed");
- exit(1);
- }
- if (pthread_key_create(&current_cpu_key, NULL) != 0) {
- perror("pthread_key_create failed");
- exit(1);
- }
- if (pthread_key_create(&last_thread_key, NULL) != 0) {
- perror("pthread_key_create failed");
- exit(1);
- }
- if (pthread_key_create(&intsoff_key, NULL) != 0) {
- perror("pthread_key_create failed");
- exit(1);
- }
-
- sigemptyset(&ints_off);
- sigaddset(&ints_off, SIGALRM);
- sigaddset(&ints_off, SIGIO);
- sigaddset(&ints_off, SIGCLD);
-
- /*
- * disable clock interrupts
- */
- _nspr_noclock = 1;
+ extern PRInt32 _nspr_noclock;
+
+ if (pthread_key_create(&current_thread_key, NULL) != 0) {
+ perror("pthread_key_create failed");
+ exit(1);
+ }
+ if (pthread_key_create(&current_cpu_key, NULL) != 0) {
+ perror("pthread_key_create failed");
+ exit(1);
+ }
+ if (pthread_key_create(&last_thread_key, NULL) != 0) {
+ perror("pthread_key_create failed");
+ exit(1);
+ }
+ if (pthread_key_create(&intsoff_key, NULL) != 0) {
+ perror("pthread_key_create failed");
+ exit(1);
+ }
+
+ sigemptyset(&ints_off);
+ sigaddset(&ints_off, SIGALRM);
+ sigaddset(&ints_off, SIGIO);
+ sigaddset(&ints_off, SIGCLD);
+
+ /*
+ * disable clock interrupts
+ */
+ _nspr_noclock = 1;
}
void _MD_InitLocks()
{
- if (pthread_mutex_init(&_pr_heapLock, NULL) != 0) {
- perror("pthread_mutex_init failed");
- exit(1);
- }
+ if (pthread_mutex_init(&_pr_heapLock, NULL) != 0) {
+ perror("pthread_mutex_init failed");
+ exit(1);
+ }
}
PR_IMPLEMENT(void) _MD_FREE_LOCK(struct _MDLock *lockp)
{
- PRIntn _is;
- PRThread *me = _PR_MD_CURRENT_THREAD();
-
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(_is);
- pthread_mutex_destroy(&lockp->mutex);
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(_is);
+ PRIntn _is;
+ PRThread *me = _PR_MD_CURRENT_THREAD();
+
+ if (me && !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(_is);
+ }
+ pthread_mutex_destroy(&lockp->mutex);
+ if (me && !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_FAST_INTSON(_is);
+ }
}
@@ -80,21 +82,23 @@ PR_IMPLEMENT(PRStatus) _MD_NEW_LOCK(struct _MDLock *lockp)
{
PRStatus rv;
PRIntn is;
- PRThread *me = _PR_MD_CURRENT_THREAD();
-
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
- rv = pthread_mutex_init(&lockp->mutex, NULL);
- if (me && !_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
- return (rv == 0) ? PR_SUCCESS : PR_FAILURE;
+ PRThread *me = _PR_MD_CURRENT_THREAD();
+
+ if (me && !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
+ rv = pthread_mutex_init(&lockp->mutex, NULL);
+ if (me && !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_FAST_INTSON(is);
+ }
+ return (rv == 0) ? PR_SUCCESS : PR_FAILURE;
}
PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
if (isCurrent) {
- (void) setjmp(CONTEXT(t));
+ (void) setjmp(CONTEXT(t));
}
*np = sizeof(CONTEXT(t)) / sizeof(PRWord);
return (PRWord *) CONTEXT(t);
@@ -103,9 +107,9 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
PR_IMPLEMENT(void)
_MD_SetPriority(_MDThread *thread, PRThreadPriority newPri)
{
- /*
- * XXX - to be implemented
- */
+ /*
+ * XXX - to be implemented
+ */
return;
}
@@ -116,17 +120,17 @@ PR_IMPLEMENT(PRStatus) _MD_InitThread(struct PRThread *thread)
if (thread->flags & _PR_GLOBAL_SCOPE) {
thread->md.pthread = pthread_self();
#if 0
- /*
- * set up SIGUSR1 handler; this is used to save state
- * during PR_SuspendAll
- */
- sigact.sa_handler = save_context_and_block;
- sigact.sa_flags = SA_RESTART;
- /*
- * Must mask clock interrupts
- */
- sigact.sa_mask = timer_set;
- sigaction(SIGUSR1, &sigact, 0);
+ /*
+ * set up SIGUSR1 handler; this is used to save state
+ * during PR_SuspendAll
+ */
+ sigact.sa_handler = save_context_and_block;
+ sigact.sa_flags = SA_RESTART;
+ /*
+ * Must mask clock interrupts
+ */
+ sigact.sa_mask = timer_set;
+ sigaction(SIGUSR1, &sigact, 0);
#endif
}
@@ -144,8 +148,8 @@ PR_IMPLEMENT(void) _MD_ExitThread(struct PRThread *thread)
PR_IMPLEMENT(void) _MD_CleanThread(struct PRThread *thread)
{
if (thread->flags & _PR_GLOBAL_SCOPE) {
- pthread_mutex_destroy(&thread->md.pthread_mutex);
- pthread_cond_destroy(&thread->md.pthread_cond);
+ pthread_mutex_destroy(&thread->md.pthread_mutex);
+ pthread_cond_destroy(&thread->md.pthread_cond);
}
}
@@ -154,16 +158,16 @@ PR_IMPLEMENT(void) _MD_SuspendThread(struct PRThread *thread)
PRInt32 rv;
PR_ASSERT((thread->flags & _PR_GLOBAL_SCOPE) &&
- _PR_IS_GCABLE_THREAD(thread));
+ _PR_IS_GCABLE_THREAD(thread));
#if 0
- thread->md.suspending_id = getpid();
- rv = kill(thread->md.id, SIGUSR1);
- PR_ASSERT(rv == 0);
- /*
- * now, block the current thread/cpu until woken up by the suspended
- * thread from it's SIGUSR1 signal handler
- */
- blockproc(getpid());
+ thread->md.suspending_id = getpid();
+ rv = kill(thread->md.id, SIGUSR1);
+ PR_ASSERT(rv == 0);
+ /*
+ * now, block the current thread/cpu until woken up by the suspended
+ * thread from it's SIGUSR1 signal handler
+ */
+ blockproc(getpid());
#endif
}
@@ -172,7 +176,7 @@ PR_IMPLEMENT(void) _MD_ResumeThread(struct PRThread *thread)
PRInt32 rv;
PR_ASSERT((thread->flags & _PR_GLOBAL_SCOPE) &&
- _PR_IS_GCABLE_THREAD(thread));
+ _PR_IS_GCABLE_THREAD(thread));
#if 0
rv = unblockproc(thread->md.id);
#endif
@@ -183,21 +187,21 @@ PR_IMPLEMENT(void) _MD_SuspendCPU(struct _PRCPU *thread)
PRInt32 rv;
#if 0
- cpu->md.suspending_id = getpid();
- rv = kill(cpu->md.id, SIGUSR1);
- PR_ASSERT(rv == 0);
- /*
- * now, block the current thread/cpu until woken up by the suspended
- * thread from it's SIGUSR1 signal handler
- */
- blockproc(getpid());
+ cpu->md.suspending_id = getpid();
+ rv = kill(cpu->md.id, SIGUSR1);
+ PR_ASSERT(rv == 0);
+ /*
+ * now, block the current thread/cpu until woken up by the suspended
+ * thread from it's SIGUSR1 signal handler
+ */
+ blockproc(getpid());
#endif
}
PR_IMPLEMENT(void) _MD_ResumeCPU(struct _PRCPU *thread)
{
#if 0
- unblockproc(cpu->md.id);
+ unblockproc(cpu->md.id);
#endif
}
@@ -208,54 +212,55 @@ PR_IMPLEMENT(void) _MD_ResumeCPU(struct _PRCPU *thread)
PR_IMPLEMENT(PRStatus)
_pt_wait(PRThread *thread, PRIntervalTime timeout)
{
-int rv;
-struct timeval now;
-struct timespec tmo;
-PRUint32 ticks = PR_TicksPerSecond();
-
-
- if (timeout != PR_INTERVAL_NO_TIMEOUT) {
- tmo.tv_sec = timeout / ticks;
- tmo.tv_nsec = timeout - (tmo.tv_sec * ticks);
- tmo.tv_nsec = PR_IntervalToMicroseconds(PT_NANOPERMICRO *
- tmo.tv_nsec);
-
- /* pthreads wants this in absolute time, off we go ... */
- (void)GETTIMEOFDAY(&now);
- /* that one's usecs, this one's nsecs - grrrr! */
- tmo.tv_sec += now.tv_sec;
- tmo.tv_nsec += (PT_NANOPERMICRO * now.tv_usec);
- tmo.tv_sec += tmo.tv_nsec / PT_BILLION;
- tmo.tv_nsec %= PT_BILLION;
- }
-
- pthread_mutex_lock(&thread->md.pthread_mutex);
- thread->md.wait--;
- if (thread->md.wait < 0) {
- if (timeout != PR_INTERVAL_NO_TIMEOUT) {
- rv = pthread_cond_timedwait(&thread->md.pthread_cond,
- &thread->md.pthread_mutex, &tmo);
+ int rv;
+ struct timeval now;
+ struct timespec tmo;
+ PRUint32 ticks = PR_TicksPerSecond();
+
+
+ if (timeout != PR_INTERVAL_NO_TIMEOUT) {
+ tmo.tv_sec = timeout / ticks;
+ tmo.tv_nsec = timeout - (tmo.tv_sec * ticks);
+ tmo.tv_nsec = PR_IntervalToMicroseconds(PT_NANOPERMICRO *
+ tmo.tv_nsec);
+
+ /* pthreads wants this in absolute time, off we go ... */
+ (void)GETTIMEOFDAY(&now);
+ /* that one's usecs, this one's nsecs - grrrr! */
+ tmo.tv_sec += now.tv_sec;
+ tmo.tv_nsec += (PT_NANOPERMICRO * now.tv_usec);
+ tmo.tv_sec += tmo.tv_nsec / PT_BILLION;
+ tmo.tv_nsec %= PT_BILLION;
+ }
+
+ pthread_mutex_lock(&thread->md.pthread_mutex);
+ thread->md.wait--;
+ if (thread->md.wait < 0) {
+ if (timeout != PR_INTERVAL_NO_TIMEOUT) {
+ rv = pthread_cond_timedwait(&thread->md.pthread_cond,
+ &thread->md.pthread_mutex, &tmo);
+ }
+ else
+ rv = pthread_cond_wait(&thread->md.pthread_cond,
+ &thread->md.pthread_mutex);
+ if (rv != 0) {
+ thread->md.wait++;
}
- else
- rv = pthread_cond_wait(&thread->md.pthread_cond,
- &thread->md.pthread_mutex);
- if (rv != 0) {
- thread->md.wait++;
- }
- } else
- rv = 0;
- pthread_mutex_unlock(&thread->md.pthread_mutex);
-
- return (rv == 0) ? PR_SUCCESS : PR_FAILURE;
+ } else {
+ rv = 0;
+ }
+ pthread_mutex_unlock(&thread->md.pthread_mutex);
+
+ return (rv == 0) ? PR_SUCCESS : PR_FAILURE;
}
PR_IMPLEMENT(PRStatus)
_MD_wait(PRThread *thread, PRIntervalTime ticks)
{
if ( thread->flags & _PR_GLOBAL_SCOPE ) {
- _MD_CHECK_FOR_EXIT();
+ _MD_CHECK_FOR_EXIT();
if (_pt_wait(thread, ticks) == PR_FAILURE) {
- _MD_CHECK_FOR_EXIT();
+ _MD_CHECK_FOR_EXIT();
/*
* wait timed out
*/
@@ -269,12 +274,12 @@ _MD_wait(PRThread *thread, PRIntervalTime ticks)
thread->state = _PR_RUNNING;
_PR_THREAD_UNLOCK(thread);
} else {
- _pt_wait(thread, PR_INTERVAL_NO_TIMEOUT);
+ _pt_wait(thread, PR_INTERVAL_NO_TIMEOUT);
_PR_THREAD_UNLOCK(thread);
}
}
} else {
- _PR_MD_SWITCH_CONTEXT(thread);
+ _PR_MD_SWITCH_CONTEXT(thread);
}
return PR_SUCCESS;
}
@@ -286,38 +291,43 @@ _MD_WakeupWaiter(PRThread *thread)
PRInt32 pid, rv;
PRIntn is;
- PR_ASSERT(_pr_md_idle_cpus >= 0);
+ PR_ASSERT(_pr_md_idle_cpus >= 0);
if (thread == NULL) {
- if (_pr_md_idle_cpus)
- _MD_Wakeup_CPUs();
+ if (_pr_md_idle_cpus) {
+ _MD_Wakeup_CPUs();
+ }
} else if (!_PR_IS_NATIVE_THREAD(thread)) {
- /*
- * If the thread is on my cpu's runq there is no need to
- * wakeup any cpus
- */
- if (!_PR_IS_NATIVE_THREAD(me)) {
- if (me->cpu != thread->cpu) {
- if (_pr_md_idle_cpus)
- _MD_Wakeup_CPUs();
- }
- } else {
- if (_pr_md_idle_cpus)
- _MD_Wakeup_CPUs();
- }
+ /*
+ * If the thread is on my cpu's runq there is no need to
+ * wakeup any cpus
+ */
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ if (me->cpu != thread->cpu) {
+ if (_pr_md_idle_cpus) {
+ _MD_Wakeup_CPUs();
+ }
+ }
+ } else {
+ if (_pr_md_idle_cpus) {
+ _MD_Wakeup_CPUs();
+ }
+ }
} else {
- PR_ASSERT(_PR_IS_NATIVE_THREAD(thread));
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
-
- pthread_mutex_lock(&thread->md.pthread_mutex);
- thread->md.wait++;
- rv = pthread_cond_signal(&thread->md.pthread_cond);
- PR_ASSERT(rv == 0);
- pthread_mutex_unlock(&thread->md.pthread_mutex);
-
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
- }
+ PR_ASSERT(_PR_IS_NATIVE_THREAD(thread));
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
+
+ pthread_mutex_lock(&thread->md.pthread_mutex);
+ thread->md.wait++;
+ rv = pthread_cond_signal(&thread->md.pthread_cond);
+ PR_ASSERT(rv == 0);
+ pthread_mutex_unlock(&thread->md.pthread_mutex);
+
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_FAST_INTSON(is);
+ }
+ }
return PR_SUCCESS;
}
@@ -339,51 +349,57 @@ _MD_CreateThread(
{
PRIntn is;
int rv;
- PRThread *me = _PR_MD_CURRENT_THREAD();
- pthread_attr_t attr;
+ PRThread *me = _PR_MD_CURRENT_THREAD();
+ pthread_attr_t attr;
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
- if (pthread_mutex_init(&thread->md.pthread_mutex, NULL) != 0) {
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
+ if (pthread_mutex_init(&thread->md.pthread_mutex, NULL) != 0) {
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_FAST_INTSON(is);
+ }
return PR_FAILURE;
- }
+ }
- if (pthread_cond_init(&thread->md.pthread_cond, NULL) != 0) {
- pthread_mutex_destroy(&thread->md.pthread_mutex);
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
+ if (pthread_cond_init(&thread->md.pthread_cond, NULL) != 0) {
+ pthread_mutex_destroy(&thread->md.pthread_mutex);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_FAST_INTSON(is);
+ }
return PR_FAILURE;
- }
+ }
thread->flags |= _PR_GLOBAL_SCOPE;
- pthread_attr_init(&attr); /* initialize attr with default attributes */
- if (pthread_attr_setstacksize(&attr, (size_t) stackSize) != 0) {
- pthread_mutex_destroy(&thread->md.pthread_mutex);
- pthread_cond_destroy(&thread->md.pthread_cond);
- pthread_attr_destroy(&attr);
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
+ pthread_attr_init(&attr); /* initialize attr with default attributes */
+ if (pthread_attr_setstacksize(&attr, (size_t) stackSize) != 0) {
+ pthread_mutex_destroy(&thread->md.pthread_mutex);
+ pthread_cond_destroy(&thread->md.pthread_cond);
+ pthread_attr_destroy(&attr);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_FAST_INTSON(is);
+ }
return PR_FAILURE;
- }
+ }
- thread->md.wait = 0;
+ thread->md.wait = 0;
rv = pthread_create(&thread->md.pthread, &attr, start, (void *)thread);
if (0 == rv) {
_MD_ATOMIC_INCREMENT(&_pr_md_pthreads_created);
_MD_ATOMIC_INCREMENT(&_pr_md_pthreads);
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_FAST_INTSON(is);
+ }
return PR_SUCCESS;
} else {
- pthread_mutex_destroy(&thread->md.pthread_mutex);
- pthread_cond_destroy(&thread->md.pthread_cond);
- pthread_attr_destroy(&attr);
+ pthread_mutex_destroy(&thread->md.pthread_mutex);
+ pthread_cond_destroy(&thread->md.pthread_cond);
+ pthread_attr_destroy(&attr);
_MD_ATOMIC_INCREMENT(&_pr_md_pthreads_failed);
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_FAST_INTSON(is);
+ }
PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, rv);
return PR_FAILURE;
}
@@ -396,12 +412,12 @@ _MD_InitRunningCPU(struct _PRCPU *cpu)
_MD_unix_init_running_cpu(cpu);
cpu->md.pthread = pthread_self();
- if (_pr_md_pipefd[0] >= 0) {
- _PR_IOQ_MAX_OSFD(cpu) = _pr_md_pipefd[0];
+ if (_pr_md_pipefd[0] >= 0) {
+ _PR_IOQ_MAX_OSFD(cpu) = _pr_md_pipefd[0];
#ifndef _PR_USE_POLL
- FD_SET(_pr_md_pipefd[0], &_PR_FD_READ_SET(cpu));
+ FD_SET(_pr_md_pipefd[0], &_PR_FD_READ_SET(cpu));
#endif
- }
+ }
}
@@ -411,7 +427,7 @@ _MD_CleanupBeforeExit(void)
#if 0
extern PRInt32 _pr_cpus_exit;
- _pr_irix_exit_now = 1;
+ _pr_irix_exit_now = 1;
if (_pr_numCPU > 1) {
/*
* Set a global flag, and wakeup all cpus which will notice the flag
@@ -427,22 +443,22 @@ _MD_CleanupBeforeExit(void)
/*
* cause global threads on the recycle list to exit
*/
- _PR_DEADQ_LOCK;
- if (_PR_NUM_DEADNATIVE != 0) {
- PRThread *thread;
- PRCList *ptr;
+ _PR_DEADQ_LOCK;
+ if (_PR_NUM_DEADNATIVE != 0) {
+ PRThread *thread;
+ PRCList *ptr;
ptr = _PR_DEADNATIVEQ.next;
while( ptr != &_PR_DEADNATIVEQ ) {
- thread = _PR_THREAD_PTR(ptr);
- _MD_CVAR_POST_SEM(thread);
- ptr = ptr->next;
- }
- }
- _PR_DEADQ_UNLOCK;
- while(_PR_NUM_DEADNATIVE > 1) {
- _PR_WAIT_SEM(_pr_irix_exit_sem);
- _PR_DEC_DEADNATIVE;
- }
+ thread = _PR_THREAD_PTR(ptr);
+ _MD_CVAR_POST_SEM(thread);
+ ptr = ptr->next;
+ }
+ }
+ _PR_DEADQ_UNLOCK;
+ while(_PR_NUM_DEADNATIVE > 1) {
+ _PR_WAIT_SEM(_pr_irix_exit_sem);
+ _PR_DEC_DEADNATIVE;
+ }
#endif
}
diff --git a/nsprpub/pr/src/md/unix/qnx.c b/nsprpub/pr/src/md/unix/qnx.c
index 259e29cdc..aef97a25a 100644
--- a/nsprpub/pr/src/md/unix/qnx.c
+++ b/nsprpub/pr/src/md/unix/qnx.c
@@ -14,7 +14,7 @@ void _MD_EarlyInit(void)
PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
if (isCurrent) {
- (void) setjmp(CONTEXT(t));
+ (void) setjmp(CONTEXT(t));
}
*np = sizeof(CONTEXT(t)) / sizeof(PRWord);
return (PRWord *) CONTEXT(t);
@@ -29,7 +29,7 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri)
PRStatus
_MD_InitializeThread(PRThread *thread)
{
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
PRStatus
@@ -44,7 +44,7 @@ PRStatus
_MD_WAKEUP_WAITER(PRThread *thread)
{
if (thread) {
- PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
+ PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
}
return PR_SUCCESS;
}
diff --git a/nsprpub/pr/src/md/unix/riscos.c b/nsprpub/pr/src/md/unix/riscos.c
index 318903acb..a04118875 100644
--- a/nsprpub/pr/src/md/unix/riscos.c
+++ b/nsprpub/pr/src/md/unix/riscos.c
@@ -13,13 +13,13 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
#ifndef _PR_PTHREADS
if (isCurrent) {
- (void) setjmp(CONTEXT(t));
+ (void) setjmp(CONTEXT(t));
}
*np = sizeof(CONTEXT(t)) / sizeof(PRWord);
return (PRWord *) CONTEXT(t);
#else
- *np = 0;
- return NULL;
+ *np = 0;
+ return NULL;
#endif
}
@@ -40,13 +40,13 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri)
PRStatus
_MD_InitializeThread(PRThread *thread)
{
- /*
- * set the pointers to the stack-pointer and frame-pointer words in the
- * context structure; this is for debugging use.
- */
- thread->md.sp = _MD_GET_SP_PTR(thread);
- thread->md.fp = _MD_GET_FP_PTR(thread);
- return PR_SUCCESS;
+ /*
+ * set the pointers to the stack-pointer and frame-pointer words in the
+ * context structure; this is for debugging use.
+ */
+ thread->md.sp = _MD_GET_SP_PTR(thread);
+ thread->md.fp = _MD_GET_FP_PTR(thread);
+ return PR_SUCCESS;
}
PRStatus
@@ -61,7 +61,7 @@ PRStatus
_MD_WAKEUP_WAITER(PRThread *thread)
{
if (thread) {
- PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
+ PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
}
return PR_SUCCESS;
}
@@ -83,6 +83,6 @@ _MD_CREATE_THREAD(
PRUint32 stackSize)
{
PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for RISC OS.");
- return PR_FAILURE;
+ return PR_FAILURE;
}
#endif /* ! _PR_PTHREADS */
diff --git a/nsprpub/pr/src/md/unix/scoos.c b/nsprpub/pr/src/md/unix/scoos.c
index b727a53ae..43b256d82 100644
--- a/nsprpub/pr/src/md/unix/scoos.c
+++ b/nsprpub/pr/src/md/unix/scoos.c
@@ -17,7 +17,7 @@ void _MD_EarlyInit(void)
PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
if (isCurrent) {
- (void) setjmp(CONTEXT(t));
+ (void) setjmp(CONTEXT(t));
}
*np = sizeof(CONTEXT(t)) / sizeof(PRWord);
return (PRWord *) CONTEXT(t);
@@ -26,7 +26,7 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
#ifdef ALARMS_BREAK_TCP /* I don't think they do */
PRInt32 _MD_connect(PRInt32 osfd, PRNetAddr *addr, PRInt32 addrlen,
- PRIntervalTime timeout)
+ PRIntervalTime timeout)
{
PRInt32 rv;
@@ -36,7 +36,7 @@ PRInt32 _MD_connect(PRInt32 osfd, PRNetAddr *addr, PRInt32 addrlen,
}
PRInt32 _MD_accept(PRInt32 osfd, PRNetAddr *addr, PRInt32 addrlen,
- PRIntervalTime timeout)
+ PRIntervalTime timeout)
{
PRInt32 rv;
@@ -61,8 +61,9 @@ void
_MD_INIT_ATOMIC(void)
{
/* Sigh. Sure wish SYSV semaphores weren't such a pain to use */
- if ((_uw_semf = tmpfile()) == NULL)
+ if ((_uw_semf = tmpfile()) == NULL) {
PR_ASSERT(0);
+ }
return;
}
@@ -109,7 +110,7 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri)
PRStatus
_MD_InitializeThread(PRThread *thread)
{
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
PRStatus
@@ -124,7 +125,7 @@ PRStatus
_MD_WAKEUP_WAITER(PRThread *thread)
{
if (thread) {
- PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
+ PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
}
return PR_SUCCESS;
}
diff --git a/nsprpub/pr/src/md/unix/solaris.c b/nsprpub/pr/src/md/unix/solaris.c
index 4fe2043b1..383f49d04 100644
--- a/nsprpub/pr/src/md/unix/solaris.c
+++ b/nsprpub/pr/src/md/unix/solaris.c
@@ -25,8 +25,8 @@ PRIntervalTime _MD_Solaris_TicksPerSecond(void)
PRIntervalTime _MD_Solaris_GetInterval(void)
{
union {
- hrtime_t hrt; /* hrtime_t is a 64-bit (long long) integer */
- PRInt64 pr64;
+ hrtime_t hrt; /* hrtime_t is a 64-bit (long long) integer */
+ PRInt64 pr64;
} time;
PRInt64 resolution;
PRIntervalTime ticks;
@@ -49,8 +49,8 @@ void _MD_EarlyInit(void)
PRWord *_MD_HomeGCRegisters(PRThread *t, PRIntn isCurrent, PRIntn *np)
{
- *np = 0;
- return NULL;
+ *np = 0;
+ return NULL;
}
#endif /* _PR_PTHREADS */
@@ -74,7 +74,7 @@ _MD_SET_PRIORITY(_MDThread *thread, PRThreadPriority newPri)
PRStatus
_MD_InitializeThread(PRThread *thread)
{
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
PRStatus
@@ -88,7 +88,7 @@ _MD_WAIT(PRThread *thread, PRIntervalTime ticks)
PRStatus
_MD_WAKEUP_WAITER(PRThread *thread)
{
- PR_ASSERT((thread == NULL) || (!(thread->flags & _PR_GLOBAL_SCOPE)));
+ PR_ASSERT((thread == NULL) || (!(thread->flags & _PR_GLOBAL_SCOPE)));
return PR_SUCCESS;
}
@@ -109,14 +109,14 @@ _MD_CREATE_THREAD(
PRUint32 stackSize)
{
PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for Solaris");
- return(PR_FAILURE);
+ return(PR_FAILURE);
}
#ifdef USE_SETJMP
PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
if (isCurrent) {
- (void) setjmp(CONTEXT(t));
+ (void) setjmp(CONTEXT(t));
}
*np = sizeof(CONTEXT(t)) / sizeof(PRWord);
return (PRWord *) CONTEXT(t);
@@ -125,7 +125,7 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
PRWord *_MD_HomeGCRegisters(PRThread *t, PRIntn isCurrent, PRIntn *np)
{
if (isCurrent) {
- (void) getcontext(CONTEXT(t));
+ (void) getcontext(CONTEXT(t));
}
*np = NGREG;
return (PRWord*) &t->md.context.uc_mcontext.gregs[0];
@@ -136,7 +136,7 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, PRIntn isCurrent, PRIntn *np)
#ifndef _PR_PTHREADS
#if defined(i386) && defined(SOLARIS2_4)
-/*
+/*
* Because clock_gettime() on Solaris/x86 2.4 always generates a
* segmentation fault, we use an emulated version _pr_solx86_clock_gettime(),
* which is implemented using gettimeofday().
@@ -148,8 +148,8 @@ _pr_solx86_clock_gettime(clockid_t clock_id, struct timespec *tp)
struct timeval tv;
if (clock_id != CLOCK_REALTIME) {
- errno = EINVAL;
- return -1;
+ errno = EINVAL;
+ return -1;
}
gettimeofday(&tv, NULL);
diff --git a/nsprpub/pr/src/md/unix/symbian.c b/nsprpub/pr/src/md/unix/symbian.c
deleted file mode 100644
index c797d8687..000000000
--- a/nsprpub/pr/src/md/unix/symbian.c
+++ /dev/null
@@ -1,16 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "primpl.h"
-
-void _MD_EarlyInit(void)
-{
-}
-
-PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
-{
- *np = 0;
- return NULL;
-}
diff --git a/nsprpub/pr/src/md/unix/unix.c b/nsprpub/pr/src/md/unix/unix.c
index 7c90b5075..a8862a4ce 100644
--- a/nsprpub/pr/src/md/unix/unix.c
+++ b/nsprpub/pr/src/md/unix/unix.c
@@ -41,7 +41,7 @@
#if defined(HAVE_SOCKLEN_T) \
|| (defined(__GLIBC__) && __GLIBC__ >= 2)
#define _PRSockLen_t socklen_t
-#elif defined(IRIX) || defined(HPUX) || defined(OSF1) || defined(SOLARIS) \
+#elif defined(HPUX) || defined(SOLARIS) \
|| defined(AIX4_1) || defined(LINUX) \
|| defined(BSDI) || defined(SCO) \
|| defined(DARWIN) \
@@ -49,7 +49,7 @@
#define _PRSockLen_t int
#elif (defined(AIX) && !defined(AIX4_1)) || defined(FREEBSD) \
|| defined(NETBSD) || defined(OPENBSD) || defined(UNIXWARE) \
- || defined(DGUX) || defined(NTO) || defined(RISCOS)
+ || defined(NTO) || defined(RISCOS)
#define _PRSockLen_t size_t
#else
#error "Cannot determine architecture"
@@ -59,7 +59,7 @@
** Global lock variable used to bracket calls into rusty libraries that
** aren't thread safe (like libc, libX, etc).
*/
-static PRLock *_pr_rename_lock = NULL;
+static PRLock *_pr_unix_rename_lock = NULL;
static PRMonitor *_pr_Xfe_mon = NULL;
static PRInt64 minus_one;
@@ -84,10 +84,6 @@ static sigset_t empty_set;
*/
int _nspr_noclock = 1;
-#ifdef IRIX
-extern PRInt32 _nspr_terminate_on_error;
-#endif
-
/*
* There is an assertion in this code that NSPR's definition of PRIOVec
* is bit compatible with UNIX' definition of a struct iovec. This is
@@ -98,13 +94,15 @@ extern PRInt32 _nspr_terminate_on_error;
int _pr_md_pipefd[2] = { -1, -1 };
static char _pr_md_pipebuf[PIPE_BUF];
static PRInt32 local_io_wait(PRInt32 osfd, PRInt32 wait_flag,
- PRIntervalTime timeout);
+ PRIntervalTime timeout);
_PRInterruptTable _pr_interruptTable[] = {
- {
- "clock", _PR_MISSED_CLOCK, _PR_ClockInterrupt, },
- {
- 0 }
+ {
+ "clock", _PR_MISSED_CLOCK, _PR_ClockInterrupt,
+ },
+ {
+ 0
+ }
};
void _MD_unix_init_running_cpu(_PRCPU *cpu)
@@ -116,7 +114,7 @@ void _MD_unix_init_running_cpu(_PRCPU *cpu)
PRStatus _MD_open_dir(_MDDir *d, const char *name)
{
-int err;
+ int err;
d->d = opendir(name);
if (!d->d) {
@@ -129,13 +127,13 @@ int err;
PRInt32 _MD_close_dir(_MDDir *d)
{
-int rv = 0, err;
+ int rv = 0, err;
if (d->d) {
rv = closedir(d->d);
if (rv == -1) {
- err = _MD_ERRNO();
- _PR_MD_MAP_CLOSEDIR_ERROR(err);
+ err = _MD_ERRNO();
+ _PR_MD_MAP_CLOSEDIR_ERROR(err);
}
}
return rv;
@@ -143,8 +141,8 @@ int rv = 0, err;
char * _MD_read_dir(_MDDir *d, PRIntn flags)
{
-struct dirent *de;
-int err;
+ struct dirent *de;
+ int err;
for (;;) {
/*
@@ -157,16 +155,19 @@ int err;
err = _MD_ERRNO();
_PR_MD_MAP_READDIR_ERROR(err);
return 0;
- }
+ }
if ((flags & PR_SKIP_DOT) &&
- (de->d_name[0] == '.') && (de->d_name[1] == 0))
+ (de->d_name[0] == '.') && (de->d_name[1] == 0)) {
continue;
+ }
if ((flags & PR_SKIP_DOT_DOT) &&
(de->d_name[0] == '.') && (de->d_name[1] == '.') &&
- (de->d_name[2] == 0))
+ (de->d_name[2] == 0)) {
continue;
- if ((flags & PR_SKIP_HIDDEN) && (de->d_name[0] == '.'))
+ }
+ if ((flags & PR_SKIP_HIDDEN) && (de->d_name[0] == '.')) {
continue;
+ }
break;
}
return de->d_name;
@@ -174,7 +175,7 @@ int err;
PRInt32 _MD_delete(const char *name)
{
-PRInt32 rv, err;
+ PRInt32 rv, err;
#ifdef UNIXWARE
sigset_t set, oset;
#endif
@@ -188,8 +189,8 @@ PRInt32 rv, err;
sigprocmask(SIG_SETMASK, &oset, NULL);
#endif
if (rv == -1) {
- err = _MD_ERRNO();
- _PR_MD_MAP_UNLINK_ERROR(err);
+ err = _MD_ERRNO();
+ _PR_MD_MAP_UNLINK_ERROR(err);
}
return(rv);
}
@@ -204,10 +205,12 @@ PRInt32 _MD_rename(const char *from, const char *to)
** of an existing file. Holding a lock across these two function
** and the open function is known to be a bad idea, but ....
*/
- if (NULL != _pr_rename_lock)
- PR_Lock(_pr_rename_lock);
- if (0 == access(to, F_OK))
+ if (NULL != _pr_unix_rename_lock) {
+ PR_Lock(_pr_unix_rename_lock);
+ }
+ if (0 == access(to, F_OK)) {
PR_SetError(PR_FILE_EXISTS_ERROR, 0);
+ }
else
{
rv = rename(from, to);
@@ -216,15 +219,16 @@ PRInt32 _MD_rename(const char *from, const char *to)
_PR_MD_MAP_RENAME_ERROR(err);
}
}
- if (NULL != _pr_rename_lock)
- PR_Unlock(_pr_rename_lock);
+ if (NULL != _pr_unix_rename_lock) {
+ PR_Unlock(_pr_unix_rename_lock);
+ }
return rv;
}
PRInt32 _MD_access(const char *name, PRAccessHow how)
{
-PRInt32 rv, err;
-int amode;
+ PRInt32 rv, err;
+ int amode;
switch (how) {
case PR_ACCESS_WRITE_OK:
@@ -254,46 +258,48 @@ done:
PRInt32 _MD_mkdir(const char *name, PRIntn mode)
{
-int rv, err;
+ int rv, err;
/*
** This lock is used to enforce rename semantics as described
** in PR_Rename. Look there for more fun details.
*/
- if (NULL !=_pr_rename_lock)
- PR_Lock(_pr_rename_lock);
+ if (NULL !=_pr_unix_rename_lock) {
+ PR_Lock(_pr_unix_rename_lock);
+ }
rv = mkdir(name, mode);
if (rv < 0) {
err = _MD_ERRNO();
_PR_MD_MAP_MKDIR_ERROR(err);
}
- if (NULL !=_pr_rename_lock)
- PR_Unlock(_pr_rename_lock);
+ if (NULL !=_pr_unix_rename_lock) {
+ PR_Unlock(_pr_unix_rename_lock);
+ }
return rv;
}
PRInt32 _MD_rmdir(const char *name)
{
-int rv, err;
+ int rv, err;
rv = rmdir(name);
if (rv == -1) {
- err = _MD_ERRNO();
- _PR_MD_MAP_RMDIR_ERROR(err);
+ err = _MD_ERRNO();
+ _PR_MD_MAP_RMDIR_ERROR(err);
}
return rv;
}
PRInt32 _MD_read(PRFileDesc *fd, void *buf, PRInt32 amount)
{
-PRThread *me = _PR_MD_CURRENT_THREAD();
-PRInt32 rv, err;
+ PRThread *me = _PR_MD_CURRENT_THREAD();
+ PRInt32 rv, err;
#ifndef _PR_USE_POLL
-fd_set rd;
+ fd_set rd;
#else
-struct pollfd pfd;
+ struct pollfd pfd;
#endif /* _PR_USE_POLL */
-PRInt32 osfd = fd->secret->md.osfd;
+ PRInt32 osfd = fd->secret->md.osfd;
#ifndef _PR_USE_POLL
FD_ZERO(&rd);
@@ -310,17 +316,18 @@ PRInt32 osfd = fd->secret->md.osfd;
}
if (!_PR_IS_NATIVE_THREAD(me)) {
if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_READ,
- PR_INTERVAL_NO_TIMEOUT)) < 0)
- goto done;
+ PR_INTERVAL_NO_TIMEOUT)) < 0) {
+ goto done;
+ }
} else {
#ifndef _PR_USE_POLL
while ((rv = _MD_SELECT(osfd + 1, &rd, NULL, NULL, NULL))
- == -1 && (err = _MD_ERRNO()) == EINTR) {
+ == -1 && (err = _MD_ERRNO()) == EINTR) {
/* retry _MD_SELECT() if it is interrupted */
}
#else /* _PR_USE_POLL */
while ((rv = _MD_POLL(&pfd, 1, -1))
- == -1 && (err = _MD_ERRNO()) == EINTR) {
+ == -1 && (err = _MD_ERRNO()) == EINTR) {
/* retry _MD_POLL() if it is interrupted */
}
#endif /* _PR_USE_POLL */
@@ -328,9 +335,10 @@ PRInt32 osfd = fd->secret->md.osfd;
break;
}
}
- if (_PR_PENDING_INTERRUPT(me))
+ if (_PR_PENDING_INTERRUPT(me)) {
break;
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ }
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -350,14 +358,14 @@ done:
PRInt32 _MD_write(PRFileDesc *fd, const void *buf, PRInt32 amount)
{
-PRThread *me = _PR_MD_CURRENT_THREAD();
-PRInt32 rv, err;
+ PRThread *me = _PR_MD_CURRENT_THREAD();
+ PRInt32 rv, err;
#ifndef _PR_USE_POLL
-fd_set wd;
+ fd_set wd;
#else
-struct pollfd pfd;
+ struct pollfd pfd;
#endif /* _PR_USE_POLL */
-PRInt32 osfd = fd->secret->md.osfd;
+ PRInt32 osfd = fd->secret->md.osfd;
#ifndef _PR_USE_POLL
FD_ZERO(&wd);
@@ -374,17 +382,18 @@ PRInt32 osfd = fd->secret->md.osfd;
}
if (!_PR_IS_NATIVE_THREAD(me)) {
if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE,
- PR_INTERVAL_NO_TIMEOUT)) < 0)
+ PR_INTERVAL_NO_TIMEOUT)) < 0) {
goto done;
+ }
} else {
#ifndef _PR_USE_POLL
while ((rv = _MD_SELECT(osfd + 1, NULL, &wd, NULL, NULL))
- == -1 && (err = _MD_ERRNO()) == EINTR) {
+ == -1 && (err = _MD_ERRNO()) == EINTR) {
/* retry _MD_SELECT() if it is interrupted */
}
#else /* _PR_USE_POLL */
while ((rv = _MD_POLL(&pfd, 1, -1))
- == -1 && (err = _MD_ERRNO()) == EINTR) {
+ == -1 && (err = _MD_ERRNO()) == EINTR) {
/* retry _MD_POLL() if it is interrupted */
}
#endif /* _PR_USE_POLL */
@@ -392,9 +401,10 @@ PRInt32 osfd = fd->secret->md.osfd;
break;
}
}
- if (_PR_PENDING_INTERRUPT(me))
+ if (_PR_PENDING_INTERRUPT(me)) {
break;
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ }
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -414,7 +424,7 @@ done:
PRInt32 _MD_fsync(PRFileDesc *fd)
{
-PRInt32 rv, err;
+ PRInt32 rv, err;
rv = fsync(fd->secret->md.osfd);
if (rv == -1) {
@@ -426,7 +436,7 @@ PRInt32 rv, err;
PRInt32 _MD_close(PRInt32 osfd)
{
-PRInt32 rv, err;
+ PRInt32 rv, err;
rv = close(osfd);
if (rv == -1) {
@@ -484,7 +494,7 @@ PRInt64 _MD_socketavailable64(PRFileDesc *fd)
#ifndef _PR_USE_POLL
static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type,
- PRIntervalTime timeout)
+ PRIntervalTime timeout)
{
PRInt32 rv = -1;
struct timeval tv;
@@ -508,10 +518,12 @@ static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type,
FD_ZERO(&rd_wr);
do {
FD_SET(osfd, &rd_wr);
- if (fd_type == READ_FD)
+ if (fd_type == READ_FD) {
rv = _MD_SELECT(osfd + 1, &rd_wr, NULL, NULL, &tv);
- else
+ }
+ else {
rv = _MD_SELECT(osfd + 1, NULL, &rd_wr, NULL, &tv);
+ }
if (rv == -1 && (syserror = _MD_ERRNO()) != EINTR) {
_PR_MD_MAP_SELECT_ERROR(syserror);
break;
@@ -543,14 +555,16 @@ static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type,
tv.tv_usec = 0;
} else {
tv.tv_usec = PR_IntervalToMicroseconds(
- remaining -
- PR_SecondsToInterval(tv.tv_sec));
+ remaining -
+ PR_SecondsToInterval(tv.tv_sec));
}
FD_SET(osfd, &rd_wr);
- if (fd_type == READ_FD)
+ if (fd_type == READ_FD) {
rv = _MD_SELECT(osfd + 1, &rd_wr, NULL, NULL, &tv);
- else
+ }
+ else {
rv = _MD_SELECT(osfd + 1, NULL, &rd_wr, NULL, &tv);
+ }
/*
* we don't consider EINTR a real error
*/
@@ -579,7 +593,7 @@ static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type,
now += remaining;
} else {
now += PR_SecondsToInterval(tv.tv_sec)
- + PR_MicrosecondsToInterval(tv.tv_usec);
+ + PR_MicrosecondsToInterval(tv.tv_usec);
}
} else {
now = PR_IntervalNow();
@@ -602,7 +616,7 @@ static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type,
#else /* _PR_USE_POLL */
static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type,
- PRIntervalTime timeout)
+ PRIntervalTime timeout)
{
PRInt32 rv = -1;
int msecs;
@@ -634,11 +648,11 @@ static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type,
_PR_MD_MAP_POLL_ERROR(syserror);
break;
}
- /*
- * If POLLERR is set, don't process it; retry the operation
- */
+ /*
+ * If POLLERR is set, don't process it; retry the operation
+ */
if ((rv == 1) && (pfd.revents & (POLLHUP | POLLNVAL))) {
- rv = -1;
+ rv = -1;
_PR_MD_MAP_POLL_REVENTS_ERROR(pfd.revents);
break;
}
@@ -686,11 +700,11 @@ static PRInt32 socket_io_wait(PRInt32 osfd, PRInt32 fd_type,
rv = -1;
break;
}
- /*
- * If POLLERR is set, don't process it; retry the operation
- */
+ /*
+ * If POLLERR is set, don't process it; retry the operation
+ */
if ((rv == 1) && (pfd.revents & (POLLHUP | POLLNVAL))) {
- rv = -1;
+ rv = -1;
_PR_MD_MAP_POLL_REVENTS_ERROR(pfd.revents);
break;
}
@@ -739,11 +753,13 @@ static PRInt32 local_io_wait(
PRInt32 rv;
PR_LOG(_pr_io_lm, PR_LOG_MIN,
- ("waiting to %s on osfd=%d",
- (wait_flag == _PR_UNIX_POLL_READ) ? "read" : "write",
- osfd));
+ ("waiting to %s on osfd=%d",
+ (wait_flag == _PR_UNIX_POLL_READ) ? "read" : "write",
+ osfd));
- if (timeout == PR_INTERVAL_NO_WAIT) return 0;
+ if (timeout == PR_INTERVAL_NO_WAIT) {
+ return 0;
+ }
pd.osfd = osfd;
pd.in_flags = wait_flag;
@@ -760,17 +776,17 @@ static PRInt32 local_io_wait(
PRInt32 _MD_recv(PRFileDesc *fd, void *buf, PRInt32 amount,
- PRInt32 flags, PRIntervalTime timeout)
+ PRInt32 flags, PRIntervalTime timeout)
{
PRInt32 osfd = fd->secret->md.osfd;
PRInt32 rv, err;
PRThread *me = _PR_MD_CURRENT_THREAD();
-/*
- * Many OS's (Solaris, Unixware) have a broken recv which won't read
- * from socketpairs. As long as we don't use flags on socketpairs, this
- * is a decent fix. - mikep
- */
+ /*
+ * Many OS's (Solaris, Unixware) have a broken recv which won't read
+ * from socketpairs. As long as we don't use flags on socketpairs, this
+ * is a decent fix. - mikep
+ */
#if defined(UNIXWARE) || defined(SOLARIS)
while ((rv = read(osfd,buf,amount)) == -1) {
#else
@@ -782,13 +798,15 @@ PRInt32 _MD_recv(PRFileDesc *fd, void *buf, PRInt32 amount,
break;
}
if (!_PR_IS_NATIVE_THREAD(me)) {
- if ((rv = local_io_wait(osfd,_PR_UNIX_POLL_READ,timeout)) < 0)
- goto done;
+ if ((rv = local_io_wait(osfd,_PR_UNIX_POLL_READ,timeout)) < 0) {
+ goto done;
+ }
} else {
- if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0)
+ if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0) {
goto done;
+ }
}
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -802,29 +820,31 @@ done:
}
PRInt32 _MD_recvfrom(PRFileDesc *fd, void *buf, PRInt32 amount,
- PRIntn flags, PRNetAddr *addr, PRUint32 *addrlen,
- PRIntervalTime timeout)
+ PRIntn flags, PRNetAddr *addr, PRUint32 *addrlen,
+ PRIntervalTime timeout)
{
PRInt32 osfd = fd->secret->md.osfd;
PRInt32 rv, err;
PRThread *me = _PR_MD_CURRENT_THREAD();
while ((*addrlen = PR_NETADDR_SIZE(addr)),
- ((rv = recvfrom(osfd, buf, amount, flags,
- (struct sockaddr *) addr, (_PRSockLen_t *)addrlen)) == -1)) {
+ ((rv = recvfrom(osfd, buf, amount, flags,
+ (struct sockaddr *) addr, (_PRSockLen_t *)addrlen)) == -1)) {
err = _MD_ERRNO();
if ((err == EAGAIN) || (err == EWOULDBLOCK)) {
if (fd->secret->nonblocking) {
break;
}
if (!_PR_IS_NATIVE_THREAD(me)) {
- if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_READ, timeout)) < 0)
+ if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_READ, timeout)) < 0) {
goto done;
+ }
} else {
- if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0)
+ if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0) {
goto done;
+ }
}
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -846,13 +866,13 @@ done:
}
PRInt32 _MD_send(PRFileDesc *fd, const void *buf, PRInt32 amount,
- PRInt32 flags, PRIntervalTime timeout)
+ PRInt32 flags, PRIntervalTime timeout)
{
PRInt32 osfd = fd->secret->md.osfd;
PRInt32 rv, err;
PRThread *me = _PR_MD_CURRENT_THREAD();
#if defined(SOLARIS)
- PRInt32 tmp_amount = amount;
+ PRInt32 tmp_amount = amount;
#endif
/*
@@ -872,48 +892,50 @@ PRInt32 _MD_send(PRFileDesc *fd, const void *buf, PRInt32 amount,
break;
}
if (!_PR_IS_NATIVE_THREAD(me)) {
- if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0)
+ if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0) {
goto done;
+ }
} else {
- if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))< 0)
+ if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))< 0) {
goto done;
+ }
}
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
#if defined(SOLARIS)
- /*
- * The write system call has been reported to return the ERANGE
- * error on occasion. Try to write in smaller chunks to workaround
- * this bug.
- */
- if (err == ERANGE) {
- if (tmp_amount > 1) {
- tmp_amount = tmp_amount/2; /* half the bytes */
- continue;
- }
- }
+ /*
+ * The write system call has been reported to return the ERANGE
+ * error on occasion. Try to write in smaller chunks to workaround
+ * this bug.
+ */
+ if (err == ERANGE) {
+ if (tmp_amount > 1) {
+ tmp_amount = tmp_amount/2; /* half the bytes */
+ continue;
+ }
+ }
#endif
break;
}
}
- /*
- * optimization; if bytes sent is less than "amount" call
- * select before returning. This is because it is likely that
- * the next send() call will return EWOULDBLOCK.
- */
+ /*
+ * optimization; if bytes sent is less than "amount" call
+ * select before returning. This is because it is likely that
+ * the next send() call will return EWOULDBLOCK.
+ */
if ((!fd->secret->nonblocking) && (rv > 0) && (rv < amount)
- && (timeout != PR_INTERVAL_NO_WAIT)) {
+ && (timeout != PR_INTERVAL_NO_WAIT)) {
if (_PR_IS_NATIVE_THREAD(me)) {
- if (socket_io_wait(osfd, WRITE_FD, timeout)< 0) {
- rv = -1;
- goto done;
- }
+ if (socket_io_wait(osfd, WRITE_FD, timeout)< 0) {
+ rv = -1;
+ goto done;
+ }
} else {
- if (local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout) < 0) {
- rv = -1;
- goto done;
- }
+ if (local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout) < 0) {
+ rv = -1;
+ goto done;
+ }
}
}
if (rv < 0) {
@@ -938,10 +960,10 @@ PRInt32 _MD_sendto(
((struct sockaddr *) &addrCopy)->sa_family = addr->raw.family;
while ((rv = sendto(osfd, buf, amount, flags,
- (struct sockaddr *) &addrCopy, addrlen)) == -1) {
+ (struct sockaddr *) &addrCopy, addrlen)) == -1) {
#else
while ((rv = sendto(osfd, buf, amount, flags,
- (struct sockaddr *) addr, addrlen)) == -1) {
+ (struct sockaddr *) addr, addrlen)) == -1) {
#endif
err = _MD_ERRNO();
if ((err == EAGAIN) || (err == EWOULDBLOCK)) {
@@ -949,13 +971,15 @@ PRInt32 _MD_sendto(
break;
}
if (!_PR_IS_NATIVE_THREAD(me)) {
- if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0)
- goto done;
+ if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0) {
+ goto done;
+ }
} else {
- if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))< 0)
+ if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))< 0) {
goto done;
+ }
}
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -997,13 +1021,15 @@ PRInt32 _MD_writev(
break;
}
if (!_PR_IS_NATIVE_THREAD(me)) {
- if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0)
- goto done;
+ if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0) {
+ goto done;
+ }
} else {
- if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))<0)
+ if ((rv = socket_io_wait(osfd, WRITE_FD, timeout))<0) {
goto done;
+ }
}
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -1015,17 +1041,17 @@ PRInt32 _MD_writev(
* the next writev() call will return EWOULDBLOCK.
*/
if ((!fd->secret->nonblocking) && (rv > 0) && (rv < amount)
- && (timeout != PR_INTERVAL_NO_WAIT)) {
+ && (timeout != PR_INTERVAL_NO_WAIT)) {
if (_PR_IS_NATIVE_THREAD(me)) {
if (socket_io_wait(osfd, WRITE_FD, timeout) < 0) {
- rv = -1;
+ rv = -1;
goto done;
- }
+ }
} else {
- if (local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout) < 0) {
- rv = -1;
- goto done;
- }
+ if (local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout) < 0) {
+ rv = -1;
+ goto done;
+ }
}
}
if (rv < 0) {
@@ -1036,27 +1062,29 @@ done:
}
PRInt32 _MD_accept(PRFileDesc *fd, PRNetAddr *addr,
- PRUint32 *addrlen, PRIntervalTime timeout)
+ PRUint32 *addrlen, PRIntervalTime timeout)
{
PRInt32 osfd = fd->secret->md.osfd;
PRInt32 rv, err;
PRThread *me = _PR_MD_CURRENT_THREAD();
while ((rv = accept(osfd, (struct sockaddr *) addr,
- (_PRSockLen_t *)addrlen)) == -1) {
+ (_PRSockLen_t *)addrlen)) == -1) {
err = _MD_ERRNO();
if ((err == EAGAIN) || (err == EWOULDBLOCK) || (err == ECONNABORTED)) {
if (fd->secret->nonblocking) {
break;
}
if (!_PR_IS_NATIVE_THREAD(me)) {
- if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_READ, timeout)) < 0)
- goto done;
+ if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_READ, timeout)) < 0) {
+ goto done;
+ }
} else {
- if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0)
+ if ((rv = socket_io_wait(osfd, READ_FD, timeout)) < 0) {
goto done;
+ }
}
- } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))){
+ } else if ((err == EINTR) && (!_PR_PENDING_INTERRUPT(me))) {
continue;
} else {
break;
@@ -1084,10 +1112,6 @@ PRInt32 _MD_connect(
PRInt32 rv, err;
PRThread *me = _PR_MD_CURRENT_THREAD();
PRInt32 osfd = fd->secret->md.osfd;
-#ifdef IRIX
-extern PRInt32 _MD_irix_connect(
- PRInt32 osfd, const PRNetAddr *addr, PRInt32 addrlen, PRIntervalTime timeout);
-#endif
#ifdef _PR_HAVE_SOCKADDR_LEN
PRNetAddr addrCopy;
@@ -1109,15 +1133,11 @@ extern PRInt32 _MD_irix_connect(
*/
retry:
-#ifdef IRIX
- if ((rv = _MD_irix_connect(osfd, addr, addrlen, timeout)) == -1) {
-#else
#ifdef _PR_HAVE_SOCKADDR_LEN
if ((rv = connect(osfd, (struct sockaddr *)&addrCopy, addrlen)) == -1) {
#else
if ((rv = connect(osfd, (struct sockaddr *)addr, addrlen)) == -1) {
#endif
-#endif
err = _MD_ERRNO();
if (err == EINTR) {
@@ -1132,8 +1152,9 @@ retry:
if (!fd->secret->nonblocking && (err == EINPROGRESS)) {
if (!_PR_IS_NATIVE_THREAD(me)) {
- if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0)
+ if ((rv = local_io_wait(osfd, _PR_UNIX_POLL_WRITE, timeout)) < 0) {
return -1;
+ }
} else {
/*
* socket_io_wait() may return -1 or 1.
@@ -1210,7 +1231,7 @@ PRInt32 _MD_shutdown(PRFileDesc *fd, PRIntn how)
}
PRInt32 _MD_socketpair(int af, int type, int flags,
- PRInt32 *osfd)
+ PRInt32 *osfd)
{
PRInt32 rv, err;
@@ -1223,12 +1244,12 @@ PRInt32 _MD_socketpair(int af, int type, int flags,
}
PRStatus _MD_getsockname(PRFileDesc *fd, PRNetAddr *addr,
- PRUint32 *addrlen)
+ PRUint32 *addrlen)
{
PRInt32 rv, err;
rv = getsockname(fd->secret->md.osfd,
- (struct sockaddr *) addr, (_PRSockLen_t *)addrlen);
+ (struct sockaddr *) addr, (_PRSockLen_t *)addrlen);
#ifdef _PR_HAVE_SOCKADDR_LEN
if (rv == 0) {
/* ignore the sa_len field of struct sockaddr */
@@ -1245,12 +1266,12 @@ PRStatus _MD_getsockname(PRFileDesc *fd, PRNetAddr *addr,
}
PRStatus _MD_getpeername(PRFileDesc *fd, PRNetAddr *addr,
- PRUint32 *addrlen)
+ PRUint32 *addrlen)
{
PRInt32 rv, err;
rv = getpeername(fd->secret->md.osfd,
- (struct sockaddr *) addr, (_PRSockLen_t *)addrlen);
+ (struct sockaddr *) addr, (_PRSockLen_t *)addrlen);
#ifdef _PR_HAVE_SOCKADDR_LEN
if (rv == 0) {
/* ignore the sa_len field of struct sockaddr */
@@ -1279,8 +1300,8 @@ PRStatus _MD_getsockopt(PRFileDesc *fd, PRInt32 level,
return rv==0?PR_SUCCESS:PR_FAILURE;
}
-PRStatus _MD_setsockopt(PRFileDesc *fd, PRInt32 level,
- PRInt32 optname, const char* optval, PRInt32 optlen)
+PRStatus _MD_setsockopt(PRFileDesc *fd, PRInt32 level,
+ PRInt32 optname, const char* optval, PRInt32 optlen)
{
PRInt32 rv, err;
@@ -1354,7 +1375,7 @@ static void FindBadFDs(void)
if (fcntl(osfd, F_GETFL, 0) == -1) {
/* Found a bad descriptor, remove it from the fd_sets. */
PR_LOG(_pr_io_lm, PR_LOG_MAX,
- ("file descriptor %d is bad", osfd));
+ ("file descriptor %d is bad", osfd));
pds->out_flags = _PR_UNIX_POLL_NVAL;
notify = PR_TRUE;
}
@@ -1369,26 +1390,29 @@ static void FindBadFDs(void)
pq->on_ioq = PR_FALSE;
/*
- * Decrement the count of descriptors for each desciptor/event
- * because this I/O request is being removed from the
- * ioq
- */
+ * Decrement the count of descriptors for each desciptor/event
+ * because this I/O request is being removed from the
+ * ioq
+ */
pds = pq->pds;
for (; pds < epds; pds++) {
PRInt32 osfd = pds->osfd;
PRInt16 in_flags = pds->in_flags;
PR_ASSERT(osfd >= 0 || in_flags == 0);
if (in_flags & _PR_UNIX_POLL_READ) {
- if (--(_PR_FD_READ_CNT(me->cpu))[osfd] == 0)
+ if (--(_PR_FD_READ_CNT(me->cpu))[osfd] == 0) {
FD_CLR(osfd, &_PR_FD_READ_SET(me->cpu));
+ }
}
if (in_flags & _PR_UNIX_POLL_WRITE) {
- if (--(_PR_FD_WRITE_CNT(me->cpu))[osfd] == 0)
+ if (--(_PR_FD_WRITE_CNT(me->cpu))[osfd] == 0) {
FD_CLR(osfd, &_PR_FD_WRITE_SET(me->cpu));
+ }
}
if (in_flags & _PR_UNIX_POLL_EXCEPT) {
- if (--(_PR_FD_EXCEPTION_CNT(me->cpu))[osfd] == 0)
+ if (--(_PR_FD_EXCEPTION_CNT(me->cpu))[osfd] == 0) {
FD_CLR(osfd, &_PR_FD_EXCEPTION_SET(me->cpu));
+ }
}
}
@@ -1399,36 +1423,39 @@ static void FindBadFDs(void)
_PR_DEL_SLEEPQ(pq->thr, PR_TRUE);
_PR_SLEEPQ_UNLOCK(pq->thr->cpu);
- if (pq->thr->flags & _PR_SUSPENDING) {
- /*
- * set thread state to SUSPENDED;
- * a Resume operation on the thread
- * will move it to the runQ
- */
- pq->thr->state = _PR_SUSPENDED;
- _PR_MISCQ_LOCK(pq->thr->cpu);
- _PR_ADD_SUSPENDQ(pq->thr, pq->thr->cpu);
- _PR_MISCQ_UNLOCK(pq->thr->cpu);
- } else {
- pri = pq->thr->priority;
- pq->thr->state = _PR_RUNNABLE;
-
- _PR_RUNQ_LOCK(cpu);
- _PR_ADD_RUNQ(pq->thr, cpu, pri);
- _PR_RUNQ_UNLOCK(cpu);
- }
+ if (pq->thr->flags & _PR_SUSPENDING) {
+ /*
+ * set thread state to SUSPENDED;
+ * a Resume operation on the thread
+ * will move it to the runQ
+ */
+ pq->thr->state = _PR_SUSPENDED;
+ _PR_MISCQ_LOCK(pq->thr->cpu);
+ _PR_ADD_SUSPENDQ(pq->thr, pq->thr->cpu);
+ _PR_MISCQ_UNLOCK(pq->thr->cpu);
+ } else {
+ pri = pq->thr->priority;
+ pq->thr->state = _PR_RUNNABLE;
+
+ _PR_RUNQ_LOCK(cpu);
+ _PR_ADD_RUNQ(pq->thr, cpu, pri);
+ _PR_RUNQ_UNLOCK(cpu);
+ }
}
_PR_THREAD_UNLOCK(pq->thr);
} else {
- if (pq->timeout < _PR_IOQ_TIMEOUT(me->cpu))
+ if (pq->timeout < _PR_IOQ_TIMEOUT(me->cpu)) {
_PR_IOQ_TIMEOUT(me->cpu) = pq->timeout;
- if (_PR_IOQ_MAX_OSFD(me->cpu) < pq_max_osfd)
+ }
+ if (_PR_IOQ_MAX_OSFD(me->cpu) < pq_max_osfd) {
_PR_IOQ_MAX_OSFD(me->cpu) = pq_max_osfd;
+ }
}
}
if (_PR_IS_NATIVE_THREAD_SUPPORTED()) {
- if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_md_pipefd[0])
+ if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_md_pipefd[0]) {
_PR_IOQ_MAX_OSFD(me->cpu) = _pr_md_pipefd[0];
+ }
}
}
#endif /* !defined(_PR_USE_POLL) */
@@ -1466,9 +1493,6 @@ void _MD_PauseCPU(PRIntervalTime ticks)
PRCList *q;
PRUint32 min_timeout;
sigset_t oldset;
-#ifdef IRIX
-extern sigset_t ints_off;
-#endif
PR_ASSERT(_PR_MD_GET_INTSOFF() != 0);
@@ -1487,24 +1511,15 @@ extern sigset_t ints_off;
*/
if (_PR_IS_NATIVE_THREAD_SUPPORTED()) {
npollfds++;
-#ifdef IRIX
- /*
- * On Irix, a second pipe is used to cause the primordial cpu to
- * wakeup and exit, when the process is exiting because of a call
- * to exit/PR_ProcessExit.
- */
- if (me->cpu->id == 0) {
- npollfds++;
- }
-#endif
- }
+ }
/*
* if the cpu's pollfd array is not big enough, release it and allocate a new one
*/
if (npollfds > _PR_IOQ_POLLFDS_SIZE(me->cpu)) {
- if (_PR_IOQ_POLLFDS(me->cpu) != NULL)
+ if (_PR_IOQ_POLLFDS(me->cpu) != NULL) {
PR_DELETE(_PR_IOQ_POLLFDS(me->cpu));
+ }
pollfds_size = PR_MAX(_PR_IOQ_MIN_POLLFDS_SIZE(me->cpu), npollfds);
pollfds = (struct pollfd *) PR_MALLOC(pollfds_size * sizeof(struct pollfd));
_PR_IOQ_POLLFDS(me->cpu) = pollfds;
@@ -1522,16 +1537,6 @@ extern sigset_t ints_off;
pollfdPtr->fd = _pr_md_pipefd[0];
pollfdPtr->events = POLLIN;
pollfdPtr++;
-#ifdef IRIX
- /*
- * On Irix, the second element is the exit pipe
- */
- if (me->cpu->id == 0) {
- pollfdPtr->fd = _pr_irix_primoridal_cpu_fd[0];
- pollfdPtr->events = POLLIN;
- pollfdPtr++;
- }
-#endif
}
min_timeout = PR_INTERVAL_NO_TIMEOUT;
@@ -1545,9 +1550,9 @@ extern sigset_t ints_off;
}
for (; pds < epds; pds++, pollfdPtr++) {
/*
- * Assert that the pollfdPtr pointer does not go
- * beyond the end of the pollfds array
- */
+ * Assert that the pollfdPtr pointer does not go
+ * beyond the end of the pollfds array
+ */
PR_ASSERT(pollfdPtr < pollfds + npollfds);
pollfdPtr->fd = pds->osfd;
/* direct copy of poll flags */
@@ -1589,17 +1594,19 @@ extern sigset_t ints_off;
}
#ifdef _PR_USE_POLL
- if (min_timeout == PR_INTERVAL_NO_TIMEOUT)
+ if (min_timeout == PR_INTERVAL_NO_TIMEOUT) {
timeout = -1;
- else
+ }
+ else {
timeout = PR_IntervalToMilliseconds(min_timeout);
+ }
#else
if (min_timeout == PR_INTERVAL_NO_TIMEOUT) {
tvp = NULL;
} else {
timeout.tv_sec = PR_IntervalToSeconds(min_timeout);
timeout.tv_usec = PR_IntervalToMicroseconds(min_timeout)
- % PR_USEC_PER_SEC;
+ % PR_USEC_PER_SEC;
tvp = &timeout;
}
#endif /* _PR_USE_POLL */
@@ -1615,22 +1622,10 @@ extern sigset_t ints_off;
* are enabled. Otherwise, when the select/poll calls are interrupted, the
* timer value starts ticking from zero again when the system call is restarted.
*/
-#ifdef IRIX
- /*
- * SIGCHLD signal is used on Irix to detect he termination of an
- * sproc by SIGSEGV, SIGBUS or SIGABRT signals when
- * _nspr_terminate_on_error is set.
- */
- if ((!_nspr_noclock) || (_nspr_terminate_on_error))
-#else
- if (!_nspr_noclock)
-#endif /* IRIX */
-#ifdef IRIX
- sigprocmask(SIG_BLOCK, &ints_off, &oldset);
-#else
- PR_ASSERT(sigismember(&timer_set, SIGALRM));
+ if (!_nspr_noclock) {
+ PR_ASSERT(sigismember(&timer_set, SIGALRM));
+ }
sigprocmask(SIG_BLOCK, &timer_set, &oldset);
-#endif /* IRIX */
#endif /* !_PR_NO_CLOCK_TIMER */
#ifndef _PR_USE_POLL
@@ -1641,19 +1636,14 @@ extern sigset_t ints_off;
#endif /* !_PR_USE_POLL */
#ifndef _PR_NO_CLOCK_TIMER
-#ifdef IRIX
- if ((!_nspr_noclock) || (_nspr_terminate_on_error))
-#else
- if (!_nspr_noclock)
-#endif /* IRIX */
- sigprocmask(SIG_SETMASK, &oldset, 0);
+ if (!_nspr_noclock) {
+ sigprocmask(SIG_SETMASK, &oldset, 0);
+ }
#endif /* !_PR_NO_CLOCK_TIMER */
_MD_CHECK_FOR_EXIT();
-#ifdef IRIX
- _PR_MD_primordial_cpu();
-#endif
+ _PR_MD_primordial_cpu();
_PR_MD_IOQ_LOCK();
/*
@@ -1664,45 +1654,21 @@ extern sigset_t ints_off;
pollfdPtr = pollfds;
if (_PR_IS_NATIVE_THREAD_SUPPORTED()) {
/*
- * Assert that the pipe is the first element in the
- * pollfds array.
- */
+ * Assert that the pipe is the first element in the
+ * pollfds array.
+ */
PR_ASSERT(pollfds[0].fd == _pr_md_pipefd[0]);
if ((pollfds[0].revents & POLLIN) && (nfd == 1)) {
/*
- * woken up by another thread; read all the data
- * in the pipe to empty the pipe
- */
+ * woken up by another thread; read all the data
+ * in the pipe to empty the pipe
+ */
while ((rv = read(_pr_md_pipefd[0], _pr_md_pipebuf,
- PIPE_BUF)) == PIPE_BUF){
+ PIPE_BUF)) == PIPE_BUF) {
}
PR_ASSERT((rv > 0) || ((rv == -1) && (errno == EAGAIN)));
}
pollfdPtr++;
-#ifdef IRIX
- /*
- * On Irix, check to see if the primordial cpu needs to exit
- * to cause the process to terminate
- */
- if (me->cpu->id == 0) {
- PR_ASSERT(pollfds[1].fd == _pr_irix_primoridal_cpu_fd[0]);
- if (pollfdPtr->revents & POLLIN) {
- if (_pr_irix_process_exit) {
- /*
- * process exit due to a call to PR_ProcessExit
- */
- prctl(PR_SETEXITSIG, SIGKILL);
- _exit(_pr_irix_process_exit_code);
- } else {
- while ((rv = read(_pr_irix_primoridal_cpu_fd[0],
- _pr_md_pipebuf, PIPE_BUF)) == PIPE_BUF) {
- }
- PR_ASSERT(rv > 0);
- }
- }
- pollfdPtr++;
- }
-#endif
}
for (q = _PR_IOQ(me->cpu).next; q != &_PR_IOQ(me->cpu); q = q->next) {
PRPollQueue *pq = _PR_POLLQUEUE_PTR(q);
@@ -1744,26 +1710,27 @@ extern sigset_t ints_off;
_PR_DEL_SLEEPQ(pq->thr, PR_TRUE);
_PR_SLEEPQ_UNLOCK(pq->thr->cpu);
- if (pq->thr->flags & _PR_SUSPENDING) {
- /*
- * set thread state to SUSPENDED;
- * a Resume operation on the thread
- * will move it to the runQ
- */
- pq->thr->state = _PR_SUSPENDED;
- _PR_MISCQ_LOCK(pq->thr->cpu);
- _PR_ADD_SUSPENDQ(pq->thr, pq->thr->cpu);
- _PR_MISCQ_UNLOCK(pq->thr->cpu);
- } else {
- pri = pq->thr->priority;
- pq->thr->state = _PR_RUNNABLE;
-
- _PR_RUNQ_LOCK(cpu);
- _PR_ADD_RUNQ(pq->thr, cpu, pri);
- _PR_RUNQ_UNLOCK(cpu);
- if (_pr_md_idle_cpus > 1)
- _PR_MD_WAKEUP_WAITER(thred);
- }
+ if (pq->thr->flags & _PR_SUSPENDING) {
+ /*
+ * set thread state to SUSPENDED;
+ * a Resume operation on the thread
+ * will move it to the runQ
+ */
+ pq->thr->state = _PR_SUSPENDED;
+ _PR_MISCQ_LOCK(pq->thr->cpu);
+ _PR_ADD_SUSPENDQ(pq->thr, pq->thr->cpu);
+ _PR_MISCQ_UNLOCK(pq->thr->cpu);
+ } else {
+ pri = pq->thr->priority;
+ pq->thr->state = _PR_RUNNABLE;
+
+ _PR_RUNQ_LOCK(cpu);
+ _PR_ADD_RUNQ(pq->thr, cpu, pri);
+ _PR_RUNQ_UNLOCK(cpu);
+ if (_pr_md_idle_cpus > 1) {
+ _PR_MD_WAKEUP_WAITER(thred);
+ }
+ }
}
_PR_THREAD_UNLOCK(thred);
_PR_IOQ_OSFD_CNT(me->cpu) -= pq->npds;
@@ -1827,16 +1794,19 @@ extern sigset_t ints_off;
PRInt16 in_flags = pds->in_flags;
PR_ASSERT(osfd >= 0 || in_flags == 0);
if (in_flags & _PR_UNIX_POLL_READ) {
- if (--(_PR_FD_READ_CNT(me->cpu))[osfd] == 0)
+ if (--(_PR_FD_READ_CNT(me->cpu))[osfd] == 0) {
FD_CLR(osfd, &_PR_FD_READ_SET(me->cpu));
+ }
}
if (in_flags & _PR_UNIX_POLL_WRITE) {
- if (--(_PR_FD_WRITE_CNT(me->cpu))[osfd] == 0)
+ if (--(_PR_FD_WRITE_CNT(me->cpu))[osfd] == 0) {
FD_CLR(osfd, &_PR_FD_WRITE_SET(me->cpu));
+ }
}
if (in_flags & _PR_UNIX_POLL_EXCEPT) {
- if (--(_PR_FD_EXCEPTION_CNT(me->cpu))[osfd] == 0)
+ if (--(_PR_FD_EXCEPTION_CNT(me->cpu))[osfd] == 0) {
FD_CLR(osfd, &_PR_FD_EXCEPTION_SET(me->cpu));
+ }
}
}
@@ -1845,7 +1815,7 @@ extern sigset_t ints_off;
* after being added to the run queue, do not dereference
* pq
*/
- thred = pq->thr;
+ thred = pq->thr;
_PR_THREAD_LOCK(thred);
if (pq->thr->flags & (_PR_ON_PAUSEQ|_PR_ON_SLEEPQ)) {
_PRCPU *cpu = thred->cpu;
@@ -1853,79 +1823,62 @@ extern sigset_t ints_off;
_PR_DEL_SLEEPQ(pq->thr, PR_TRUE);
_PR_SLEEPQ_UNLOCK(pq->thr->cpu);
- if (pq->thr->flags & _PR_SUSPENDING) {
- /*
- * set thread state to SUSPENDED;
- * a Resume operation on the thread
- * will move it to the runQ
- */
- pq->thr->state = _PR_SUSPENDED;
- _PR_MISCQ_LOCK(pq->thr->cpu);
- _PR_ADD_SUSPENDQ(pq->thr, pq->thr->cpu);
- _PR_MISCQ_UNLOCK(pq->thr->cpu);
- } else {
- pri = pq->thr->priority;
- pq->thr->state = _PR_RUNNABLE;
-
- pq->thr->cpu = cpu;
- _PR_RUNQ_LOCK(cpu);
- _PR_ADD_RUNQ(pq->thr, cpu, pri);
- _PR_RUNQ_UNLOCK(cpu);
- if (_pr_md_idle_cpus > 1)
- _PR_MD_WAKEUP_WAITER(thred);
- }
+ if (pq->thr->flags & _PR_SUSPENDING) {
+ /*
+ * set thread state to SUSPENDED;
+ * a Resume operation on the thread
+ * will move it to the runQ
+ */
+ pq->thr->state = _PR_SUSPENDED;
+ _PR_MISCQ_LOCK(pq->thr->cpu);
+ _PR_ADD_SUSPENDQ(pq->thr, pq->thr->cpu);
+ _PR_MISCQ_UNLOCK(pq->thr->cpu);
+ } else {
+ pri = pq->thr->priority;
+ pq->thr->state = _PR_RUNNABLE;
+
+ pq->thr->cpu = cpu;
+ _PR_RUNQ_LOCK(cpu);
+ _PR_ADD_RUNQ(pq->thr, cpu, pri);
+ _PR_RUNQ_UNLOCK(cpu);
+ if (_pr_md_idle_cpus > 1) {
+ _PR_MD_WAKEUP_WAITER(thred);
+ }
+ }
}
_PR_THREAD_UNLOCK(thred);
} else {
- if (pq->timeout < _PR_IOQ_TIMEOUT(me->cpu))
+ if (pq->timeout < _PR_IOQ_TIMEOUT(me->cpu)) {
_PR_IOQ_TIMEOUT(me->cpu) = pq->timeout;
- if (_PR_IOQ_MAX_OSFD(me->cpu) < pq_max_osfd)
+ }
+ if (_PR_IOQ_MAX_OSFD(me->cpu) < pq_max_osfd) {
_PR_IOQ_MAX_OSFD(me->cpu) = pq_max_osfd;
+ }
}
}
if (_PR_IS_NATIVE_THREAD_SUPPORTED()) {
if ((FD_ISSET(_pr_md_pipefd[0], rp)) && (nfd == 1)) {
/*
- * woken up by another thread; read all the data
- * in the pipe to empty the pipe
- */
+ * woken up by another thread; read all the data
+ * in the pipe to empty the pipe
+ */
while ((rv =
- read(_pr_md_pipefd[0], _pr_md_pipebuf, PIPE_BUF))
- == PIPE_BUF){
+ read(_pr_md_pipefd[0], _pr_md_pipebuf, PIPE_BUF))
+ == PIPE_BUF) {
}
PR_ASSERT((rv > 0) ||
- ((rv == -1) && (errno == EAGAIN)));
+ ((rv == -1) && (errno == EAGAIN)));
}
- if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_md_pipefd[0])
+ if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_md_pipefd[0]) {
_PR_IOQ_MAX_OSFD(me->cpu) = _pr_md_pipefd[0];
-#ifdef IRIX
- if ((me->cpu->id == 0) &&
- (FD_ISSET(_pr_irix_primoridal_cpu_fd[0], rp))) {
- if (_pr_irix_process_exit) {
- /*
- * process exit due to a call to PR_ProcessExit
- */
- prctl(PR_SETEXITSIG, SIGKILL);
- _exit(_pr_irix_process_exit_code);
- } else {
- while ((rv = read(_pr_irix_primoridal_cpu_fd[0],
- _pr_md_pipebuf, PIPE_BUF)) == PIPE_BUF) {
- }
- PR_ASSERT(rv > 0);
- }
- }
- if (me->cpu->id == 0) {
- if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_irix_primoridal_cpu_fd[0])
- _PR_IOQ_MAX_OSFD(me->cpu) = _pr_irix_primoridal_cpu_fd[0];
- }
-#endif
+ }
}
} else if (nfd < 0) {
if (errno == EBADF) {
FindBadFDs();
} else {
PR_LOG(_pr_io_lm, PR_LOG_MAX, ("select() failed with errno %d",
- errno));
+ errno));
}
} else {
PR_ASSERT(nfd == 0);
@@ -1947,14 +1900,17 @@ extern sigset_t ints_off;
pq_max_osfd = pds->osfd;
}
}
- if (pq->timeout < _PR_IOQ_TIMEOUT(me->cpu))
+ if (pq->timeout < _PR_IOQ_TIMEOUT(me->cpu)) {
_PR_IOQ_TIMEOUT(me->cpu) = pq->timeout;
- if (_PR_IOQ_MAX_OSFD(me->cpu) < pq_max_osfd)
+ }
+ if (_PR_IOQ_MAX_OSFD(me->cpu) < pq_max_osfd) {
_PR_IOQ_MAX_OSFD(me->cpu) = pq_max_osfd;
+ }
}
if (_PR_IS_NATIVE_THREAD_SUPPORTED()) {
- if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_md_pipefd[0])
+ if (_PR_IOQ_MAX_OSFD(me->cpu) < _pr_md_pipefd[0]) {
_PR_IOQ_MAX_OSFD(me->cpu) = _pr_md_pipefd[0];
+ }
}
}
#endif /* _PR_USE_POLL */
@@ -1973,11 +1929,11 @@ void _MD_Wakeup_CPUs()
* pipe full, read all data in pipe to empty it
*/
while ((rv =
- read(_pr_md_pipefd[0], _pr_md_pipebuf, PIPE_BUF))
- == PIPE_BUF) {
+ read(_pr_md_pipefd[0], _pr_md_pipebuf, PIPE_BUF))
+ == PIPE_BUF) {
}
PR_ASSERT((rv > 0) ||
- ((rv == -1) && (errno == EAGAIN)));
+ ((rv == -1) && (errno == EAGAIN)));
rv = write(_pr_md_pipefd[1], &data, 1);
}
}
@@ -2041,10 +1997,10 @@ static void ClockInterruptHandler()
}
#else /* _PR_NO_PREEMPT */
/*
- ** Re-enable unix interrupts (so that we can use
- ** setjmp/longjmp for context switching without having to
- ** worry about the signal state)
- */
+ ** Re-enable unix interrupts (so that we can use
+ ** setjmp/longjmp for context switching without having to
+ ** worry about the signal state)
+ */
sigprocmask(SIG_SETMASK, &empty_set, 0);
PR_LOG(_pr_sched_lm, PR_LOG_MIN, ("clock caused context switch"));
@@ -2056,8 +2012,9 @@ static void ClockInterruptHandler()
_PR_ADD_RUNQ(me, cpu, pri);
_PR_RUNQ_UNLOCK(cpu);
_PR_THREAD_UNLOCK(me);
- } else
+ } else {
me->state = _PR_RUNNABLE;
+ }
_MD_SWITCH_CONTEXT(me);
PR_LOG(_pr_sched_lm, PR_LOG_MIN, ("clock back from context switch"));
#endif /* _PR_NO_PREEMPT */
@@ -2096,10 +2053,12 @@ void _MD_StartInterrupts()
char *eval;
if ((eval = getenv("NSPR_NOCLOCK")) != NULL) {
- if (atoi(eval) == 0)
+ if (atoi(eval) == 0) {
_nspr_noclock = 0;
- else
+ }
+ else {
_nspr_noclock = 1;
+ }
}
#ifndef _PR_NO_CLOCK_TIMER
@@ -2135,10 +2094,10 @@ void _MD_EnableClockInterrupts()
#endif /* HPUX9 */
PR_ASSERT(_pr_numCPU == 1);
- itval.it_interval.tv_sec = 0;
- itval.it_interval.tv_usec = MSEC_PER_TICK * PR_USEC_PER_MSEC;
- itval.it_value = itval.it_interval;
- setitimer(ITIMER_REAL, &itval, 0);
+ itval.it_interval.tv_sec = 0;
+ itval.it_interval.tv_usec = MSEC_PER_TICK * PR_USEC_PER_MSEC;
+ itval.it_value = itval.it_interval;
+ setitimer(ITIMER_REAL, &itval, 0);
}
void _MD_DisableClockInterrupts()
@@ -2147,10 +2106,10 @@ void _MD_DisableClockInterrupts()
extern PRUintn _pr_numCPU;
PR_ASSERT(_pr_numCPU == 1);
- itval.it_interval.tv_sec = 0;
- itval.it_interval.tv_usec = 0;
- itval.it_value = itval.it_interval;
- setitimer(ITIMER_REAL, &itval, 0);
+ itval.it_interval.tv_sec = 0;
+ itval.it_interval.tv_usec = 0;
+ itval.it_value = itval.it_interval;
+ setitimer(ITIMER_REAL, &itval, 0);
}
void _MD_BlockClockInterrupts()
@@ -2181,7 +2140,7 @@ void _MD_MakeNonblock(PRFileDesc *fd)
*/
fcntl(osfd, F_SETFL, flags | O_NONBLOCK);
- }
+}
PRInt32 _MD_open(const char *name, PRIntn flags, PRIntn mode)
{
@@ -2196,12 +2155,15 @@ PRInt32 _MD_open(const char *name, PRIntn flags, PRIntn mode)
osflags = O_RDONLY;
}
- if (flags & PR_EXCL)
+ if (flags & PR_EXCL) {
osflags |= O_EXCL;
- if (flags & PR_APPEND)
+ }
+ if (flags & PR_APPEND) {
osflags |= O_APPEND;
- if (flags & PR_TRUNCATE)
+ }
+ if (flags & PR_TRUNCATE) {
osflags |= O_TRUNC;
+ }
if (flags & PR_SYNC) {
#if defined(O_SYNC)
osflags |= O_SYNC;
@@ -2219,8 +2181,9 @@ PRInt32 _MD_open(const char *name, PRIntn flags, PRIntn mode)
if (flags & PR_CREATE_FILE)
{
osflags |= O_CREAT;
- if (NULL !=_pr_rename_lock)
- PR_Lock(_pr_rename_lock);
+ if (NULL !=_pr_unix_rename_lock) {
+ PR_Lock(_pr_unix_rename_lock);
+ }
}
#if defined(ANDROID)
@@ -2234,14 +2197,15 @@ PRInt32 _MD_open(const char *name, PRIntn flags, PRIntn mode)
_PR_MD_MAP_OPEN_ERROR(err);
}
- if ((flags & PR_CREATE_FILE) && (NULL !=_pr_rename_lock))
- PR_Unlock(_pr_rename_lock);
+ if ((flags & PR_CREATE_FILE) && (NULL !=_pr_unix_rename_lock)) {
+ PR_Unlock(_pr_unix_rename_lock);
+ }
return rv;
}
PRIntervalTime intr_timeout_ticks;
-#if defined(SOLARIS) || defined(IRIX)
+#if defined(SOLARIS)
static void sigsegvhandler() {
fprintf(stderr,"Received SIGSEGV\n");
fflush(stderr);
@@ -2259,7 +2223,7 @@ static void sigbushandler() {
fflush(stderr);
pause();
}
-#endif /* SOLARIS, IRIX */
+#endif /* SOLARIS */
#endif /* !defined(_PR_PTHREADS) */
@@ -2271,7 +2235,7 @@ void _MD_query_fd_inheritable(PRFileDesc *fd)
flags = fcntl(fd->secret->md.osfd, F_GETFD, 0);
PR_ASSERT(-1 != flags);
fd->secret->inheritable = (flags & FD_CLOEXEC) ?
- _PR_TRI_FALSE : _PR_TRI_TRUE;
+ _PR_TRI_FALSE : _PR_TRI_TRUE;
}
PROffset32 _MD_lseek(PRFileDesc *fd, PROffset32 offset, PRSeekWhence whence)
@@ -2537,12 +2501,15 @@ static int _MD_convert_stat_to_fileinfo(
const struct stat *sb,
PRFileInfo *info)
{
- if (S_IFREG & sb->st_mode)
+ if (S_IFREG & sb->st_mode) {
info->type = PR_FILE_FILE;
- else if (S_IFDIR & sb->st_mode)
+ }
+ else if (S_IFDIR & sb->st_mode) {
info->type = PR_FILE_DIRECTORY;
- else
+ }
+ else {
info->type = PR_FILE_OTHER;
+ }
#if defined(_PR_HAVE_LARGE_OFF_T)
if (0x7fffffffL < sb->st_size)
@@ -2561,12 +2528,15 @@ static int _MD_convert_stat64_to_fileinfo64(
const _MDStat64 *sb,
PRFileInfo64 *info)
{
- if (S_IFREG & sb->st_mode)
+ if (S_IFREG & sb->st_mode) {
info->type = PR_FILE_FILE;
- else if (S_IFDIR & sb->st_mode)
+ }
+ else if (S_IFDIR & sb->st_mode) {
info->type = PR_FILE_DIRECTORY;
- else
+ }
+ else {
info->type = PR_FILE_OTHER;
+ }
LL_I2L(info->size, sb->st_size);
@@ -2580,10 +2550,12 @@ PRInt32 _MD_getfileinfo(const char *fn, PRFileInfo *info)
struct stat sb;
rv = stat(fn, &sb);
- if (rv < 0)
+ if (rv < 0) {
_PR_MD_MAP_STAT_ERROR(_MD_ERRNO());
- else if (NULL != info)
+ }
+ else if (NULL != info) {
rv = _MD_convert_stat_to_fileinfo(&sb, info);
+ }
return rv;
}
@@ -2591,10 +2563,12 @@ PRInt32 _MD_getfileinfo64(const char *fn, PRFileInfo64 *info)
{
_MDStat64 sb;
PRInt32 rv = _md_iovector._stat64(fn, &sb);
- if (rv < 0)
+ if (rv < 0) {
_PR_MD_MAP_STAT_ERROR(_MD_ERRNO());
- else if (NULL != info)
+ }
+ else if (NULL != info) {
rv = _MD_convert_stat64_to_fileinfo64(&sb, info);
+ }
return rv;
}
@@ -2602,10 +2576,12 @@ PRInt32 _MD_getopenfileinfo(const PRFileDesc *fd, PRFileInfo *info)
{
struct stat sb;
PRInt32 rv = fstat(fd->secret->md.osfd, &sb);
- if (rv < 0)
+ if (rv < 0) {
_PR_MD_MAP_FSTAT_ERROR(_MD_ERRNO());
- else if (NULL != info)
+ }
+ else if (NULL != info) {
rv = _MD_convert_stat_to_fileinfo(&sb, info);
+ }
return rv;
}
@@ -2613,10 +2589,12 @@ PRInt32 _MD_getopenfileinfo64(const PRFileDesc *fd, PRFileInfo64 *info)
{
_MDStat64 sb;
PRInt32 rv = _md_iovector._fstat64(fd->secret->md.osfd, &sb);
- if (rv < 0)
+ if (rv < 0) {
_PR_MD_MAP_FSTAT_ERROR(_MD_ERRNO());
- else if (NULL != info)
+ }
+ else if (NULL != info) {
rv = _MD_convert_stat64_to_fileinfo64(&sb, info);
+ }
return rv;
}
@@ -2626,11 +2604,7 @@ PRInt32 _MD_getopenfileinfo64(const PRFileDesc *fd, PRFileInfo64 *info)
* initialized by _PR_MD_FINAL_INIT. This means the log file cannot be a
* large file on some platforms.
*/
-#ifdef SYMBIAN
-struct _MD_IOVector _md_iovector; /* Will crash if NSPR_LOG_FILE is set. */
-#else
struct _MD_IOVector _md_iovector = { open };
-#endif
/*
** These implementations are to emulate large file routines on systems that
@@ -2700,7 +2674,9 @@ static PROffset64 _MD_Unix_lseek64(PRIntn osfd, PROffset64 offset, PRIntn whence
LL_L2I(off, offset);
LL_I2L(rv, lseek(osfd, off, whence));
}
- else errno = EFBIG; /* we can't go there */
+ else {
+ errno = EFBIG; /* we can't go there */
+ }
return rv;
} /* _MD_Unix_lseek64 */
@@ -2735,28 +2711,6 @@ mmap64(void *addr, size_t len, int prot, int flags, int fd, loff_t offset)
}
#endif
-#if defined(OSF1) && defined(__GNUC__)
-
-/*
- * On OSF1 V5.0A, <sys/stat.h> defines stat and fstat as
- * macros when compiled under gcc, so it is rather tricky to
- * take the addresses of the real functions the macros expend
- * to. A simple solution is to define forwarder functions
- * and take the addresses of the forwarder functions instead.
- */
-
-static int stat_forwarder(const char *path, struct stat *buffer)
-{
- return stat(path, buffer);
-}
-
-static int fstat_forwarder(int filedes, struct stat *buffer)
-{
- return fstat(filedes, buffer);
-}
-
-#endif
-
static void _PR_InitIOV(void)
{
#if defined(SOLARIS2_5)
@@ -2789,7 +2743,7 @@ static void _PR_InitIOV(void)
_md_iovector._stat64 = stat;
_md_iovector._lseek64 = _MD_Unix_lseek64;
#elif defined(_PR_HAVE_OFF64_T)
-#if defined(IRIX5_3) || (defined(ANDROID) && __ANDROID_API__ < 21)
+#if (defined(ANDROID) && __ANDROID_API__ < 21)
/*
* Android < 21 doesn't have open64. We pass the O_LARGEFILE flag to open
* in _MD_open.
@@ -2811,13 +2765,8 @@ static void _PR_InitIOV(void)
#elif defined(_PR_HAVE_LARGE_OFF_T)
_md_iovector._open64 = open;
_md_iovector._mmap64 = mmap;
-#if defined(OSF1) && defined(__GNUC__)
- _md_iovector._fstat64 = fstat_forwarder;
- _md_iovector._stat64 = stat_forwarder;
-#else
_md_iovector._fstat64 = fstat;
_md_iovector._stat64 = stat;
-#endif
_md_iovector._lseek64 = lseek;
#else
#error "I don't know yet"
@@ -2837,9 +2786,9 @@ void _PR_UnixInit(void)
sigaddset(&timer_set, SIGALRM);
sigemptyset(&empty_set);
intr_timeout_ticks =
- PR_SecondsToInterval(_PR_INTERRUPT_CHECK_INTERVAL_SECS);
+ PR_SecondsToInterval(_PR_INTERRUPT_CHECK_INTERVAL_SECS);
-#if defined(SOLARIS) || defined(IRIX)
+#if defined(SOLARIS)
if (getenv("NSPR_SIGSEGV_HANDLE")) {
sigact.sa_handler = sigsegvhandler;
@@ -2871,8 +2820,8 @@ void _PR_UnixInit(void)
rv = sigaction(SIGPIPE, &sigact, 0);
PR_ASSERT(0 == rv);
- _pr_rename_lock = PR_NewLock();
- PR_ASSERT(NULL != _pr_rename_lock);
+ _pr_unix_rename_lock = PR_NewLock();
+ PR_ASSERT(NULL != _pr_unix_rename_lock);
_pr_Xfe_mon = PR_NewMonitor();
PR_ASSERT(NULL != _pr_Xfe_mon);
@@ -2881,9 +2830,9 @@ void _PR_UnixInit(void)
void _PR_UnixCleanup(void)
{
- if (_pr_rename_lock) {
- PR_DestroyLock(_pr_rename_lock);
- _pr_rename_lock = NULL;
+ if (_pr_unix_rename_lock) {
+ PR_DestroyLock(_pr_unix_rename_lock);
+ _pr_unix_rename_lock = NULL;
}
if (_pr_Xfe_mon) {
PR_DestroyMonitor(_pr_Xfe_mon);
@@ -2917,7 +2866,7 @@ void _MD_InitSegs(void)
return;
}
#endif
- _pr_zero_fd = open("/dev/zero",O_RDWR , 0);
+ _pr_zero_fd = open("/dev/zero",O_RDWR, 0);
/* Prevent the fd from being inherited by child processes */
fcntl(_pr_zero_fd, F_SETFD, FD_CLOEXEC);
_pr_md_lock = PR_NewLock();
@@ -2956,8 +2905,8 @@ from_heap:
prot |= PROT_EXEC;
#endif
rv = mmap((vaddr != 0) ? vaddr : lastaddr, size, prot,
- _MD_MMAP_FLAGS,
- _pr_zero_fd, 0);
+ _MD_MMAP_FLAGS,
+ _pr_zero_fd, 0);
if (rv == (void*)-1) {
goto from_heap;
}
@@ -2973,10 +2922,12 @@ exit:
void _MD_FreeSegment(PRSegment *seg)
{
- if (seg->flags & _PR_SEG_VM)
+ if (seg->flags & _PR_SEG_VM) {
(void) munmap(seg->vaddr, seg->size);
- else
+ }
+ else {
PR_DELETE(seg->vaddr);
+ }
}
#endif /* _PR_PTHREADS */
@@ -3123,7 +3074,7 @@ PRInt32 _PR_WaitForMultipleFDs(
}
_PR_IOQ_OSFD_CNT(me->cpu) += pdcnt;
-
+
_PR_SLEEPQ_LOCK(me->cpu);
_PR_ADD_SLEEPQ(me, timeout);
me->state = _PR_IO_WAIT;
@@ -3139,7 +3090,7 @@ PRInt32 _PR_WaitForMultipleFDs(
me->io_suspended = PR_FALSE;
/*
- * This thread should run on the same cpu on which it was blocked; when
+ * This thread should run on the same cpu on which it was blocked; when
* the IO request times out the fd sets and fd counts for the
* cpu are updated below.
*/
@@ -3163,16 +3114,19 @@ PRInt32 _PR_WaitForMultipleFDs(
PRInt16 in_flags = unixpd->in_flags;
if (in_flags & _PR_UNIX_POLL_READ) {
- if (--(_PR_FD_READ_CNT(me->cpu))[osfd] == 0)
+ if (--(_PR_FD_READ_CNT(me->cpu))[osfd] == 0) {
FD_CLR(osfd, &_PR_FD_READ_SET(me->cpu));
+ }
}
if (in_flags & _PR_UNIX_POLL_WRITE) {
- if (--(_PR_FD_WRITE_CNT(me->cpu))[osfd] == 0)
+ if (--(_PR_FD_WRITE_CNT(me->cpu))[osfd] == 0) {
FD_CLR(osfd, &_PR_FD_WRITE_SET(me->cpu));
+ }
}
if (in_flags & _PR_UNIX_POLL_EXCEPT) {
- if (--(_PR_FD_EXCEPTION_CNT(me->cpu))[osfd] == 0)
+ if (--(_PR_FD_EXCEPTION_CNT(me->cpu))[osfd] == 0) {
FD_CLR(osfd, &_PR_FD_EXCEPTION_SET(me->cpu));
+ }
}
}
#endif /* _PR_USE_POLL */
@@ -3220,12 +3174,12 @@ void _PR_Unblock_IO_Wait(PRThread *thr)
{
int pri = thr->priority;
_PRCPU *cpu = thr->cpu;
-
+
/*
* GLOBAL threads wakeup periodically to check for interrupt
*/
if (_PR_IS_NATIVE_THREAD(thr)) {
- _PR_THREAD_UNLOCK(thr);
+ _PR_THREAD_UNLOCK(thr);
return;
}
@@ -3267,7 +3221,7 @@ int _MD_unix_get_nonblocking_connect_error(int osfd)
if (strcmp(superblock.f_basetype, "ttcpip") == 0) {
/* Using the Tiny Stack! */
rv = getpeername(osfd, (struct sockaddr *) &addr,
- (_PRSockLen_t *) &addrlen);
+ (_PRSockLen_t *) &addrlen);
if (rv == -1) {
int errno_copy = errno; /* make a copy so I don't
* accidentally reset */
@@ -3306,7 +3260,7 @@ int _MD_unix_get_nonblocking_connect_error(int osfd)
_PRSockLen_t optlen = sizeof(err);
if (getsockopt(osfd, SOL_SOCKET, SO_ERROR,
- (char *) &err, &optlen) == -1) {
+ (char *) &err, &optlen) == -1) {
return errno;
} else {
return err;
@@ -3325,16 +3279,16 @@ int _MD_unix_get_nonblocking_connect_error(int osfd)
rv = getmsg(osfd, NULL, NULL, &flags);
PR_ASSERT(-1 == rv || 0 == rv);
if (-1 == rv && errno != EAGAIN && errno != EWOULDBLOCK) {
- return errno;
+ return errno;
}
return 0; /* no error */
#else
- int err;
- _PRSockLen_t optlen = sizeof(err);
- if (getsockopt(osfd, SOL_SOCKET, SO_ERROR, (char*)&err, &optlen) == -1) {
- return errno;
- }
- return err;
+ int err;
+ _PRSockLen_t optlen = sizeof(err);
+ if (getsockopt(osfd, SOL_SOCKET, SO_ERROR, (char*)&err, &optlen) == -1) {
+ return errno;
+ }
+ return err;
#endif
}
@@ -3390,8 +3344,9 @@ _MD_LockFile(PRInt32 f)
arg.l_start = 0;
arg.l_len = 0; /* until EOF */
rv = fcntl(f, F_SETLKW, &arg);
- if (rv == 0)
+ if (rv == 0) {
return PR_SUCCESS;
+ }
_PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
return PR_FAILURE;
}
@@ -3407,8 +3362,9 @@ _MD_TLockFile(PRInt32 f)
arg.l_start = 0;
arg.l_len = 0; /* until EOF */
rv = fcntl(f, F_SETLK, &arg);
- if (rv == 0)
+ if (rv == 0) {
return PR_SUCCESS;
+ }
_PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
return PR_FAILURE;
}
@@ -3424,8 +3380,9 @@ _MD_UnlockFile(PRInt32 f)
arg.l_start = 0;
arg.l_len = 0; /* until EOF */
rv = fcntl(f, F_SETLK, &arg);
- if (rv == 0)
+ if (rv == 0) {
return PR_SUCCESS;
+ }
_PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
return PR_FAILURE;
}
@@ -3439,8 +3396,9 @@ _MD_LockFile(PRInt32 f)
{
PRInt32 rv;
rv = flock(f, LOCK_EX);
- if (rv == 0)
+ if (rv == 0) {
return PR_SUCCESS;
+ }
_PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
return PR_FAILURE;
}
@@ -3450,8 +3408,9 @@ _MD_TLockFile(PRInt32 f)
{
PRInt32 rv;
rv = flock(f, LOCK_EX|LOCK_NB);
- if (rv == 0)
+ if (rv == 0) {
return PR_SUCCESS;
+ }
_PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
return PR_FAILURE;
}
@@ -3461,8 +3420,9 @@ _MD_UnlockFile(PRInt32 f)
{
PRInt32 rv;
rv = flock(f, LOCK_UN);
- if (rv == 0)
+ if (rv == 0) {
return PR_SUCCESS;
+ }
_PR_MD_MAP_FLOCK_ERROR(_MD_ERRNO());
return PR_FAILURE;
}
@@ -3473,8 +3433,9 @@ _MD_LockFile(PRInt32 f)
{
PRInt32 rv;
rv = lockf(f, F_LOCK, 0);
- if (rv == 0)
+ if (rv == 0) {
return PR_SUCCESS;
+ }
_PR_MD_MAP_LOCKF_ERROR(_MD_ERRNO());
return PR_FAILURE;
}
@@ -3484,8 +3445,9 @@ _MD_TLockFile(PRInt32 f)
{
PRInt32 rv;
rv = lockf(f, F_TLOCK, 0);
- if (rv == 0)
+ if (rv == 0) {
return PR_SUCCESS;
+ }
_PR_MD_MAP_LOCKF_ERROR(_MD_ERRNO());
return PR_FAILURE;
}
@@ -3495,8 +3457,9 @@ _MD_UnlockFile(PRInt32 f)
{
PRInt32 rv;
rv = lockf(f, F_ULOCK, 0);
- if (rv == 0)
+ if (rv == 0) {
return PR_SUCCESS;
+ }
_PR_MD_MAP_LOCKF_ERROR(_MD_ERRNO());
return PR_FAILURE;
}
@@ -3516,20 +3479,23 @@ PRStatus _MD_gethostname(char *name, PRUint32 namelen)
PRStatus _MD_getsysinfo(PRSysInfo cmd, char *name, PRUint32 namelen)
{
- struct utsname info;
+ struct utsname info;
- PR_ASSERT((cmd == PR_SI_SYSNAME) || (cmd == PR_SI_RELEASE));
+ PR_ASSERT((cmd == PR_SI_SYSNAME) || (cmd == PR_SI_RELEASE));
- if (uname(&info) == -1) {
- _PR_MD_MAP_DEFAULT_ERROR(errno);
- return PR_FAILURE;
- }
- if (PR_SI_SYSNAME == cmd)
- (void)PR_snprintf(name, namelen, info.sysname);
- else if (PR_SI_RELEASE == cmd)
- (void)PR_snprintf(name, namelen, info.release);
- else
- return PR_FAILURE;
+ if (uname(&info) == -1) {
+ _PR_MD_MAP_DEFAULT_ERROR(errno);
+ return PR_FAILURE;
+ }
+ if (PR_SI_SYSNAME == cmd) {
+ (void)PR_snprintf(name, namelen, info.sysname);
+ }
+ else if (PR_SI_RELEASE == cmd) {
+ (void)PR_snprintf(name, namelen, info.release);
+ }
+ else {
+ return PR_FAILURE;
+ }
return PR_SUCCESS;
}
@@ -3569,12 +3535,15 @@ PRStatus _MD_CreateFileMap(PRFileMap *fmap, PRInt64 size)
}
if (fmap->prot == PR_PROT_READONLY) {
fmap->md.prot = PROT_READ;
-#ifdef OSF1V4_MAP_PRIVATE_BUG
+#if defined(DARWIN) || defined(ANDROID)
/*
- * Use MAP_SHARED to work around a bug in OSF1 V4.0D
- * (QAR 70220 in the OSF_QAR database) that results in
- * corrupted data in the memory-mapped region. This
- * bug is fixed in V5.0.
+ * This is needed on OS X because its implementation of
+ * POSIX shared memory returns an error for MAP_PRIVATE, even
+ * when the mapping is read-only.
+ *
+ * And this is needed on Android, because mapping ashmem with
+ * MAP_PRIVATE creates a mapping of zeroed memory instead of
+ * the shm contents.
*/
fmap->md.flags = MAP_SHARED;
#else
@@ -3601,8 +3570,8 @@ void * _MD_MemMap(
LL_L2I(off, offset);
if ((addr = mmap(0, len, fmap->md.prot, fmap->md.flags,
- fmap->fd->secret->md.osfd, off)) == (void *) -1) {
- _PR_MD_MAP_MMAP_ERROR(_MD_ERRNO());
+ fmap->fd->secret->md.osfd, off)) == (void *) -1) {
+ _PR_MD_MAP_MMAP_ERROR(_MD_ERRNO());
addr = NULL;
}
return addr;
@@ -3623,7 +3592,7 @@ PRStatus _MD_CloseFileMap(PRFileMap *fmap)
PRStatus rc = PR_Close( fmap->fd );
if ( PR_FAILURE == rc ) {
PR_LOG( _pr_io_lm, PR_LOG_DEBUG,
- ("_MD_CloseFileMap(): error closing anonymnous file map osfd"));
+ ("_MD_CloseFileMap(): error closing anonymnous file map osfd"));
return PR_FAILURE;
}
}
diff --git a/nsprpub/pr/src/md/unix/unix_errors.c b/nsprpub/pr/src/md/unix/unix_errors.c
index bcea0993f..1d8765969 100644
--- a/nsprpub/pr/src/md/unix/unix_errors.c
+++ b/nsprpub/pr/src/md/unix/unix_errors.c
@@ -29,9 +29,9 @@ void _MD_unix_map_default_error(int err)
case EAGAIN:
prError = PR_WOULD_BLOCK_ERROR;
break;
- /*
- * On QNX and Neutrino, EALREADY is defined as EBUSY.
- */
+ /*
+ * On QNX and Neutrino, EALREADY is defined as EBUSY.
+ */
#if EALREADY != EBUSY
case EALREADY:
prError = PR_ALREADY_INITIATED_ERROR;
@@ -127,9 +127,9 @@ void _MD_unix_map_default_error(int err)
case ENFILE:
prError = PR_SYS_DESC_TABLE_FULL_ERROR;
break;
- /*
- * On SCO OpenServer 5, ENOBUFS is defined as ENOSR.
- */
+ /*
+ * On SCO OpenServer 5, ENOBUFS is defined as ENOSR.
+ */
#if defined(ENOBUFS) && (ENOBUFS != ENOSR)
case ENOBUFS:
prError = PR_INSUFFICIENT_RESOURCES_ERROR;
@@ -144,7 +144,7 @@ void _MD_unix_map_default_error(int err)
case ENOLCK:
prError = PR_FILE_IS_LOCKED_ERROR;
break;
-#ifdef ENOLINK
+#ifdef ENOLINK
case ENOLINK:
prError = PR_REMOTE_FILE_ERROR;
break;
@@ -362,9 +362,9 @@ void _MD_unix_map_rmdir_error(int err)
PRErrorCode prError;
switch (err) {
- /*
- * On AIX 4.3, ENOTEMPTY is defined as EEXIST.
- */
+ /*
+ * On AIX 4.3, ENOTEMPTY is defined as EEXIST.
+ */
#if ENOTEMPTY != EEXIST
case ENOTEMPTY:
prError = PR_DIRECTORY_NOT_EMPTY_ERROR;
@@ -530,8 +530,8 @@ void _MD_unix_map_connect_error(int err)
switch (err) {
#if defined(UNIXWARE)
/*
- * On some platforms, if we connect to a port on the local host
- * (the loopback address) that no process is listening on, we get
+ * On some platforms, if we connect to a port on the local host
+ * (the loopback address) that no process is listening on, we get
* EIO instead of ECONNREFUSED.
*/
case EIO:
@@ -738,14 +738,18 @@ void _MD_unix_map_poll_error(int err)
void _MD_unix_map_poll_revents_error(int err)
{
- if (err & POLLNVAL)
+ if (err & POLLNVAL) {
PR_SetError(PR_BAD_DESCRIPTOR_ERROR, EBADF);
- else if (err & POLLHUP)
+ }
+ else if (err & POLLHUP) {
PR_SetError(PR_CONNECT_RESET_ERROR, EPIPE);
- else if (err & POLLERR)
+ }
+ else if (err & POLLERR) {
PR_SetError(PR_IO_ERROR, EIO);
- else
+ }
+ else {
PR_SetError(PR_UNKNOWN_ERROR, err);
+ }
}
#endif /* _PR_POLL_AVAILABLE || _PR_NEED_FAKE_POLL */
diff --git a/nsprpub/pr/src/md/unix/unixware.c b/nsprpub/pr/src/md/unix/unixware.c
index 638af5f2e..d6958558b 100644
--- a/nsprpub/pr/src/md/unix/unixware.c
+++ b/nsprpub/pr/src/md/unix/unixware.c
@@ -20,7 +20,7 @@ void _MD_EarlyInit(void)
PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
if (isCurrent) {
- (void) setjmp(CONTEXT(t));
+ (void) setjmp(CONTEXT(t));
}
*np = sizeof(CONTEXT(t)) / sizeof(PRWord);
return (PRWord *) CONTEXT(t);
@@ -29,7 +29,7 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
#ifdef ALARMS_BREAK_TCP /* I don't think they do */
PRInt32 _MD_connect(PRInt32 osfd, const PRNetAddr *addr, PRInt32 addrlen,
- PRIntervalTime timeout)
+ PRIntervalTime timeout)
{
PRInt32 rv;
@@ -39,7 +39,7 @@ PRInt32 _MD_connect(PRInt32 osfd, const PRNetAddr *addr, PRInt32 addrlen,
}
PRInt32 _MD_accept(PRInt32 osfd, PRNetAddr *addr, PRInt32 addrlen,
- PRIntervalTime timeout)
+ PRIntervalTime timeout)
{
PRInt32 rv;
@@ -64,8 +64,9 @@ void
_MD_INIT_ATOMIC(void)
{
/* Sigh. Sure wish SYSV semaphores weren't such a pain to use */
- if ((_uw_semf = tmpfile()) == NULL)
+ if ((_uw_semf = tmpfile()) == NULL) {
PR_ASSERT(0);
+ }
return;
}
@@ -112,7 +113,7 @@ _MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri)
PRStatus
_MD_InitializeThread(PRThread *thread)
{
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
PRStatus
@@ -127,7 +128,7 @@ PRStatus
_MD_WAKEUP_WAITER(PRThread *thread)
{
if (thread) {
- PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
+ PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
}
return PR_SUCCESS;
}
@@ -230,30 +231,31 @@ void _MD_EarlyInit(void)
sigaddset(&set, SIGALRM);
}
-PRStatus _MD_CREATE_THREAD(PRThread *thread,
- void (*start)(void *),
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize)
+PRStatus _MD_CREATE_THREAD(PRThread *thread,
+ void (*start)(void *),
+ PRThreadPriority priority,
+ PRThreadScope scope,
+ PRThreadState state,
+ PRUint32 stackSize)
{
- long flags;
-
+ long flags;
+
/* mask out SIGALRM for native thread creation */
- thr_sigsetmask(SIG_BLOCK, &set, &oldset);
+ thr_sigsetmask(SIG_BLOCK, &set, &oldset);
- flags = (state == PR_JOINABLE_THREAD ? THR_SUSPENDED/*|THR_NEW_LWP*/
- : THR_SUSPENDED|THR_DETACHED/*|THR_NEW_LWP*/);
- if (_PR_IS_GCABLE_THREAD(thread) ||
- (scope == PR_GLOBAL_BOUND_THREAD))
- flags |= THR_BOUND;
+ flags = (state == PR_JOINABLE_THREAD ? THR_SUSPENDED/*|THR_NEW_LWP*/
+ : THR_SUSPENDED|THR_DETACHED/*|THR_NEW_LWP*/);
+ if (_PR_IS_GCABLE_THREAD(thread) ||
+ (scope == PR_GLOBAL_BOUND_THREAD)) {
+ flags |= THR_BOUND;
+ }
if (thr_create(NULL, thread->stack->stackSize,
- (void *(*)(void *)) start, (void *) thread,
- flags,
- &thread->md.handle)) {
- thr_sigsetmask(SIG_SETMASK, &oldset, NULL);
- return PR_FAILURE;
+ (void *(*)(void *)) start, (void *) thread,
+ flags,
+ &thread->md.handle)) {
+ thr_sigsetmask(SIG_SETMASK, &oldset, NULL);
+ return PR_FAILURE;
}
@@ -262,34 +264,34 @@ PRStatus _MD_CREATE_THREAD(PRThread *thread,
* its register state is initialized properly for GC */
thread->md.lwpid = -1;
- thr_sigsetmask(SIG_SETMASK, &oldset, NULL);
+ thr_sigsetmask(SIG_SETMASK, &oldset, NULL);
_MD_NEW_SEM(&thread->md.waiter_sem, 0);
- if ((scope == PR_GLOBAL_THREAD) || (scope == PR_GLOBAL_BOUND_THREAD)) {
- thread->flags |= _PR_GLOBAL_SCOPE;
+ if ((scope == PR_GLOBAL_THREAD) || (scope == PR_GLOBAL_BOUND_THREAD)) {
+ thread->flags |= _PR_GLOBAL_SCOPE;
}
- /*
- ** Set the thread priority. This will also place the thread on
+ /*
+ ** Set the thread priority. This will also place the thread on
** the runQ.
**
** Force PR_SetThreadPriority to set the priority by
** setting thread->priority to 100.
*/
{
- int pri;
- pri = thread->priority;
- thread->priority = 100;
- PR_SetThreadPriority( thread, pri );
-
- PR_LOG(_pr_thread_lm, PR_LOG_MIN,
- ("(0X%x)[Start]: on to runq at priority %d",
- thread, thread->priority));
+ int pri;
+ pri = thread->priority;
+ thread->priority = 100;
+ PR_SetThreadPriority( thread, pri );
+
+ PR_LOG(_pr_thread_lm, PR_LOG_MIN,
+ ("(0X%x)[Start]: on to runq at priority %d",
+ thread, thread->priority));
}
/* Activate the thread */
if (thr_continue( thread->md.handle ) ) {
- return PR_FAILURE;
+ return PR_FAILURE;
}
return PR_SUCCESS;
}
@@ -301,7 +303,7 @@ void _MD_cleanup_thread(PRThread *thread)
hdl = thread->md.handle;
- /*
+ /*
** First, suspend the thread (unless it's the active one)
** Because we suspend it first, we don't have to use LOCK_SCHEDULER to
** prevent both of us modifying the thread structure at the same time.
@@ -310,17 +312,17 @@ void _MD_cleanup_thread(PRThread *thread)
thr_suspend(hdl);
}
PR_LOG(_pr_thread_lm, PR_LOG_MIN,
- ("(0X%x)[DestroyThread]\n", thread));
+ ("(0X%x)[DestroyThread]\n", thread));
_MD_DESTROY_SEM(&thread->md.waiter_sem);
}
void _MD_SET_PRIORITY(_MDThread *md_thread, PRUintn newPri)
{
- if(thr_setprio((thread_t)md_thread->handle, newPri)) {
- PR_LOG(_pr_thread_lm, PR_LOG_MIN,
- ("_PR_SetThreadPriority: can't set thread priority\n"));
- }
+ if(thr_setprio((thread_t)md_thread->handle, newPri)) {
+ PR_LOG(_pr_thread_lm, PR_LOG_MIN,
+ ("_PR_SetThreadPriority: can't set thread priority\n"));
+ }
}
void _MD_WAIT_CV(
@@ -373,18 +375,18 @@ PRThread *_pr_current_thread_tls()
PRStatus
_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
{
- _MD_WAIT_SEM(&thread->md.waiter_sem);
- return PR_SUCCESS;
+ _MD_WAIT_SEM(&thread->md.waiter_sem);
+ return PR_SUCCESS;
}
PRStatus
_MD_WAKEUP_WAITER(PRThread *thread)
{
- if (thread == NULL) {
- return PR_SUCCESS;
- }
- _MD_POST_SEM(&thread->md.waiter_sem);
- return PR_SUCCESS;
+ if (thread == NULL) {
+ return PR_SUCCESS;
+ }
+ _MD_POST_SEM(&thread->md.waiter_sem);
+ return PR_SUCCESS;
}
_PRCPU *_pr_current_cpu_tls()
@@ -412,39 +414,40 @@ void _MD_INIT_IO (void)
PRStatus _MD_InitializeThread(PRThread *thread)
{
- if (!_PR_IS_NATIVE_THREAD(thread))
+ if (!_PR_IS_NATIVE_THREAD(thread)) {
return;
- /* prime the sp; substract 4 so we don't hit the assert that
- * curr sp > base_stack
- */
+ }
+ /* prime the sp; substract 4 so we don't hit the assert that
+ * curr sp > base_stack
+ */
thread->md.sp = (uint_t) thread->stack->allocBase - sizeof(long);
thread->md.lwpid = _lwp_self();
thread->md.handle = THR_SELF();
- /* all threads on Solaris are global threads from NSPR's perspective
- * since all of them are mapped to Solaris threads.
- */
+ /* all threads on Solaris are global threads from NSPR's perspective
+ * since all of them are mapped to Solaris threads.
+ */
thread->flags |= _PR_GLOBAL_SCOPE;
- /* For primordial/attached thread, we don't create an underlying native thread.
- * So, _MD_CREATE_THREAD() does not get called. We need to do initialization
- * like allocating thread's synchronization variables and set the underlying
- * native thread's priority.
- */
- if (thread->flags & (_PR_PRIMORDIAL | _PR_ATTACHED)) {
- _MD_NEW_SEM(&thread->md.waiter_sem, 0);
- _MD_SET_PRIORITY(&(thread->md), thread->priority);
- }
- return PR_SUCCESS;
-}
-
-static sigset_t old_mask; /* store away original gc thread sigmask */
-static int gcprio; /* store away original gc thread priority */
-static lwpid_t *all_lwps=NULL; /* list of lwps that we suspended */
+ /* For primordial/attached thread, we don't create an underlying native thread.
+ * So, _MD_CREATE_THREAD() does not get called. We need to do initialization
+ * like allocating thread's synchronization variables and set the underlying
+ * native thread's priority.
+ */
+ if (thread->flags & (_PR_PRIMORDIAL | _PR_ATTACHED)) {
+ _MD_NEW_SEM(&thread->md.waiter_sem, 0);
+ _MD_SET_PRIORITY(&(thread->md), thread->priority);
+ }
+ return PR_SUCCESS;
+}
+
+static sigset_t old_mask; /* store away original gc thread sigmask */
+static int gcprio; /* store away original gc thread priority */
+static lwpid_t *all_lwps=NULL; /* list of lwps that we suspended */
static int num_lwps ;
static int suspendAllOn = 0;
-#define VALID_SP(sp, bottom, top) \
+#define VALID_SP(sp, bottom, top) \
(((uint_t)(sp)) > ((uint_t)(bottom)) && ((uint_t)(sp)) < ((uint_t)(top)))
void unixware_preempt_off()
@@ -456,7 +459,7 @@ void unixware_preempt_off()
void unixware_preempt_on()
{
- sigprocmask (SIG_SETMASK, &old_mask, NULL);
+ sigprocmask (SIG_SETMASK, &old_mask, NULL);
}
void _MD_Begin_SuspendAll()
@@ -466,7 +469,7 @@ void _MD_Begin_SuspendAll()
PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS, ("Begin_SuspendAll\n"));
/* run at highest prio so I cannot be preempted */
thr_getprio(thr_self(), &gcprio);
- thr_setprio(thr_self(), 0x7fffffff);
+ thr_setprio(thr_self(), 0x7fffffff);
suspendAllOn = 1;
}
@@ -484,55 +487,60 @@ void _MD_End_ResumeAll()
void _MD_Suspend(PRThread *thr)
{
- int lwp_fd, result;
- int lwp_main_proc_fd = 0;
+ int lwp_fd, result;
+ int lwp_main_proc_fd = 0;
thr_suspend(thr->md.handle);
- if (!_PR_IS_GCABLE_THREAD(thr))
- return;
+ if (!_PR_IS_GCABLE_THREAD(thr)) {
+ return;
+ }
/* XXX Primordial thread can't be bound to an lwp, hence there is no
* way we can assume that we can get the lwp status for primordial
* thread reliably. Hence we skip this for primordial thread, hoping
- * that the SP is saved during lock and cond. wait.
+ * that the SP is saved during lock and cond. wait.
* XXX - Again this is concern only for java interpreter, not for the
* server, 'cause primordial thread in the server does not do java work
*/
- if (thr->flags & _PR_PRIMORDIAL)
- return;
+ if (thr->flags & _PR_PRIMORDIAL) {
+ return;
+ }
/* if the thread is not started yet then don't do anything */
- if (!suspendAllOn || thr->md.lwpid == -1)
- return;
+ if (!suspendAllOn || thr->md.lwpid == -1) {
+ return;
+ }
}
void _MD_Resume(PRThread *thr)
{
- if (!_PR_IS_GCABLE_THREAD(thr) || !suspendAllOn){
- /*XXX When the suspendAllOn is set, we will be trying to do lwp_suspend
- * during that time we can't call any thread lib or libc calls. Hence
- * make sure that no resume is requested for Non gcable thread
- * during suspendAllOn */
- PR_ASSERT(!suspendAllOn);
- thr_continue(thr->md.handle);
- return;
- }
- if (thr->md.lwpid == -1)
- return;
-
- if ( _lwp_continue(thr->md.lwpid) < 0) {
- PR_ASSERT(0); /* ARGH, we are hosed! */
- }
+ if (!_PR_IS_GCABLE_THREAD(thr) || !suspendAllOn) {
+ /*XXX When the suspendAllOn is set, we will be trying to do lwp_suspend
+ * during that time we can't call any thread lib or libc calls. Hence
+ * make sure that no resume is requested for Non gcable thread
+ * during suspendAllOn */
+ PR_ASSERT(!suspendAllOn);
+ thr_continue(thr->md.handle);
+ return;
+ }
+ if (thr->md.lwpid == -1) {
+ return;
+ }
+
+ if ( _lwp_continue(thr->md.lwpid) < 0) {
+ PR_ASSERT(0); /* ARGH, we are hosed! */
+ }
}
PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
if (isCurrent) {
- (void) getcontext(CONTEXT(t)); /* XXX tune me: set md_IRIX.c */
+ (void) getcontext(CONTEXT(t)); /* XXX tune me: set md_IRIX.c */
}
*np = NGREG;
- if (t->md.lwpid == -1)
- memset(&t->md.context.uc_mcontext.gregs[0], 0, NGREG * sizeof(PRWord));
+ if (t->md.lwpid == -1) {
+ memset(&t->md.context.uc_mcontext.gregs[0], 0, NGREG * sizeof(PRWord));
+ }
return (PRWord*) &t->md.context.uc_mcontext.gregs[0];
}
@@ -540,7 +548,7 @@ int
_pr_unixware_clock_gettime (struct timespec *tp)
{
struct timeval tv;
-
+
gettimeofday(&tv, NULL);
tp->tv_sec = tv.tv_sec;
tp->tv_nsec = tv.tv_usec * 1000;
diff --git a/nsprpub/pr/src/md/unix/uxpoll.c b/nsprpub/pr/src/md/unix/uxpoll.c
index 8a618ed80..d01121cbf 100644
--- a/nsprpub/pr/src/md/unix/uxpoll.c
+++ b/nsprpub/pr/src/md/unix/uxpoll.c
@@ -52,19 +52,19 @@ static PRInt32 NativeThreadPoll(
if (pds[index].in_flags & PR_POLL_READ)
{
in_flags_read = (pds[index].fd->methods->poll)(
- pds[index].fd,
- pds[index].in_flags & ~PR_POLL_WRITE,
- &out_flags_read);
+ pds[index].fd,
+ pds[index].in_flags & ~PR_POLL_WRITE,
+ &out_flags_read);
}
if (pds[index].in_flags & PR_POLL_WRITE)
{
in_flags_write = (pds[index].fd->methods->poll)(
- pds[index].fd,
- pds[index].in_flags & ~PR_POLL_READ,
- &out_flags_write);
+ pds[index].fd,
+ pds[index].in_flags & ~PR_POLL_READ,
+ &out_flags_write);
}
if ((0 != (in_flags_read & out_flags_read))
- || (0 != (in_flags_write & out_flags_write)))
+ || (0 != (in_flags_write & out_flags_write)))
{
/* this one is ready right now */
if (0 == ready)
@@ -91,7 +91,7 @@ static PRInt32 NativeThreadPoll(
bottom = PR_GetIdentitiesLayer(pds[index].fd, PR_NSPR_IO_LAYER);
PR_ASSERT(NULL != bottom); /* what to do about that? */
if ((NULL != bottom)
- && (_PR_FILEDESC_OPEN == bottom->secret->state))
+ && (_PR_FILEDESC_OPEN == bottom->secret->state))
{
if (0 == ready)
{
@@ -121,8 +121,9 @@ static PRInt32 NativeThreadPoll(
_PR_POLL_WRITE_SYS_WRITE;
syspoll[index].events |= POLLOUT;
}
- if (pds[index].in_flags & PR_POLL_EXCEPT)
+ if (pds[index].in_flags & PR_POLL_EXCEPT) {
syspoll[index].events |= POLLPRI;
+ }
}
}
else
@@ -168,12 +169,18 @@ retry:
if (EINTR == oserror)
{
- if (timeout == PR_INTERVAL_NO_TIMEOUT) goto retry;
- else if (timeout == PR_INTERVAL_NO_WAIT) ready = 0;
+ if (timeout == PR_INTERVAL_NO_TIMEOUT) {
+ goto retry;
+ }
+ else if (timeout == PR_INTERVAL_NO_WAIT) {
+ ready = 0;
+ }
else
{
elapsed = (PRIntervalTime)(PR_IntervalNow() - start);
- if (elapsed > timeout) ready = 0; /* timed out */
+ if (elapsed > timeout) {
+ ready = 0; /* timed out */
+ }
else
{
remaining = timeout - elapsed;
@@ -182,7 +189,9 @@ retry:
}
}
}
- else _PR_MD_MAP_POLL_ERROR(oserror);
+ else {
+ _PR_MD_MAP_POLL_ERROR(oserror);
+ }
}
else if (ready > 0)
{
@@ -203,12 +212,12 @@ retry:
if (syspoll[index].revents & POLLIN)
{
if (pds[index].out_flags
- & _PR_POLL_READ_SYS_READ)
+ & _PR_POLL_READ_SYS_READ)
{
out_flags |= PR_POLL_READ;
}
if (pds[index].out_flags
- & _PR_POLL_WRITE_SYS_READ)
+ & _PR_POLL_WRITE_SYS_READ)
{
out_flags |= PR_POLL_WRITE;
}
@@ -216,24 +225,28 @@ retry:
if (syspoll[index].revents & POLLOUT)
{
if (pds[index].out_flags
- & _PR_POLL_READ_SYS_WRITE)
+ & _PR_POLL_READ_SYS_WRITE)
{
out_flags |= PR_POLL_READ;
}
if (pds[index].out_flags
- & _PR_POLL_WRITE_SYS_WRITE)
+ & _PR_POLL_WRITE_SYS_WRITE)
{
out_flags |= PR_POLL_WRITE;
}
}
- if (syspoll[index].revents & POLLPRI)
+ if (syspoll[index].revents & POLLPRI) {
out_flags |= PR_POLL_EXCEPT;
- if (syspoll[index].revents & POLLERR)
+ }
+ if (syspoll[index].revents & POLLERR) {
out_flags |= PR_POLL_ERR;
- if (syspoll[index].revents & POLLNVAL)
+ }
+ if (syspoll[index].revents & POLLNVAL) {
out_flags |= PR_POLL_NVAL;
- if (syspoll[index].revents & POLLHUP)
+ }
+ if (syspoll[index].revents & POLLHUP) {
out_flags |= PR_POLL_HUP;
+ }
}
}
pds[index].out_flags = out_flags;
@@ -277,15 +290,15 @@ static PRInt32 NativeThreadSelect(
if (pd->in_flags & PR_POLL_READ)
{
in_flags_read = (pd->fd->methods->poll)(
- pd->fd, pd->in_flags & ~PR_POLL_WRITE, &out_flags_read);
+ pd->fd, pd->in_flags & ~PR_POLL_WRITE, &out_flags_read);
}
if (pd->in_flags & PR_POLL_WRITE)
{
in_flags_write = (pd->fd->methods->poll)(
- pd->fd, pd->in_flags & ~PR_POLL_READ, &out_flags_write);
+ pd->fd, pd->in_flags & ~PR_POLL_READ, &out_flags_write);
}
if ((0 != (in_flags_read & out_flags_read))
- || (0 != (in_flags_write & out_flags_write)))
+ || (0 != (in_flags_write & out_flags_write)))
{
/* this one's ready right now */
if (0 == ready)
@@ -313,12 +326,14 @@ static PRInt32 NativeThreadSelect(
bottom = PR_GetIdentitiesLayer(pd->fd, PR_NSPR_IO_LAYER);
PR_ASSERT(NULL != bottom); /* what to do about that? */
if ((NULL != bottom)
- && (_PR_FILEDESC_OPEN == bottom->secret->state))
+ && (_PR_FILEDESC_OPEN == bottom->secret->state))
{
if (0 == ready)
{
PRInt32 osfd = bottom->secret->md.osfd;
- if (osfd > maxfd) maxfd = osfd;
+ if (osfd > maxfd) {
+ maxfd = osfd;
+ }
if (in_flags_read & PR_POLL_READ)
{
pd->out_flags |= _PR_POLL_READ_SYS_READ;
@@ -339,7 +354,9 @@ static PRInt32 NativeThreadSelect(
pd->out_flags |= _PR_POLL_WRITE_SYS_WRITE;
FD_SET(osfd, &wt);
}
- if (pd->in_flags & PR_POLL_EXCEPT) FD_SET(osfd, &ex);
+ if (pd->in_flags & PR_POLL_EXCEPT) {
+ FD_SET(osfd, &ex);
+ }
}
}
else
@@ -363,7 +380,9 @@ static PRInt32 NativeThreadSelect(
}
}
- if (0 != ready) return ready; /* no need to block */
+ if (0 != ready) {
+ return ready; /* no need to block */
+ }
remaining = timeout;
start = PR_IntervalNow();
@@ -381,11 +400,15 @@ retry:
if (ready == -1 && errno == EINTR)
{
- if (timeout == PR_INTERVAL_NO_TIMEOUT) goto retry;
+ if (timeout == PR_INTERVAL_NO_TIMEOUT) {
+ goto retry;
+ }
else
{
elapsed = (PRIntervalTime) (PR_IntervalNow() - start);
- if (elapsed > timeout) ready = 0; /* timed out */
+ if (elapsed > timeout) {
+ ready = 0; /* timed out */
+ }
else
{
remaining = timeout - elapsed;
@@ -415,22 +438,30 @@ retry:
if (FD_ISSET(osfd, &rd))
{
- if (pd->out_flags & _PR_POLL_READ_SYS_READ)
+ if (pd->out_flags & _PR_POLL_READ_SYS_READ) {
out_flags |= PR_POLL_READ;
- if (pd->out_flags & _PR_POLL_WRITE_SYS_READ)
+ }
+ if (pd->out_flags & _PR_POLL_WRITE_SYS_READ) {
out_flags |= PR_POLL_WRITE;
- }
+ }
+ }
if (FD_ISSET(osfd, &wt))
{
- if (pd->out_flags & _PR_POLL_READ_SYS_WRITE)
+ if (pd->out_flags & _PR_POLL_READ_SYS_WRITE) {
out_flags |= PR_POLL_READ;
- if (pd->out_flags & _PR_POLL_WRITE_SYS_WRITE)
+ }
+ if (pd->out_flags & _PR_POLL_WRITE_SYS_WRITE) {
out_flags |= PR_POLL_WRITE;
- }
- if (FD_ISSET(osfd, &ex)) out_flags |= PR_POLL_EXCEPT;
+ }
+ }
+ if (FD_ISSET(osfd, &ex)) {
+ out_flags |= PR_POLL_EXCEPT;
+ }
}
pd->out_flags = out_flags;
- if (out_flags) ready++;
+ if (out_flags) {
+ ready++;
+ }
}
PR_ASSERT(ready > 0);
}
@@ -456,7 +487,9 @@ retry:
}
PR_ASSERT(ready > 0);
}
- else _PR_MD_MAP_SELECT_ERROR(err);
+ else {
+ _PR_MD_MAP_SELECT_ERROR(err);
+ }
}
return ready;
@@ -484,7 +517,7 @@ static PRInt32 LocalThreads(
*/
unixpd = unixpds = (_PRUnixPollDesc*)
- PR_MALLOC(npds * sizeof(_PRUnixPollDesc));
+ PR_MALLOC(npds * sizeof(_PRUnixPollDesc));
if (NULL == unixpds)
{
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
@@ -503,15 +536,15 @@ static PRInt32 LocalThreads(
if (pd->in_flags & PR_POLL_READ)
{
in_flags_read = (pd->fd->methods->poll)(
- pd->fd, pd->in_flags & ~PR_POLL_WRITE, &out_flags_read);
+ pd->fd, pd->in_flags & ~PR_POLL_WRITE, &out_flags_read);
}
if (pd->in_flags & PR_POLL_WRITE)
{
in_flags_write = (pd->fd->methods->poll)(
- pd->fd, pd->in_flags & ~PR_POLL_READ, &out_flags_write);
+ pd->fd, pd->in_flags & ~PR_POLL_READ, &out_flags_write);
}
if ((0 != (in_flags_read & out_flags_read))
- || (0 != (in_flags_write & out_flags_write)))
+ || (0 != (in_flags_write & out_flags_write)))
{
/* this one's ready right now */
if (0 == ready)
@@ -537,7 +570,7 @@ static PRInt32 LocalThreads(
bottom = PR_GetIdentitiesLayer(pd->fd, PR_NSPR_IO_LAYER);
PR_ASSERT(NULL != bottom); /* what to do about that? */
if ((NULL != bottom)
- && (_PR_FILEDESC_OPEN == bottom->secret->state))
+ && (_PR_FILEDESC_OPEN == bottom->secret->state))
{
if (0 == ready)
{
@@ -614,26 +647,34 @@ static PRInt32 LocalThreads(
{
if (unixpd->out_flags & _PR_UNIX_POLL_READ)
{
- if (pd->out_flags & _PR_POLL_READ_SYS_READ)
+ if (pd->out_flags & _PR_POLL_READ_SYS_READ) {
out_flags |= PR_POLL_READ;
- if (pd->out_flags & _PR_POLL_WRITE_SYS_READ)
+ }
+ if (pd->out_flags & _PR_POLL_WRITE_SYS_READ) {
out_flags |= PR_POLL_WRITE;
+ }
}
if (unixpd->out_flags & _PR_UNIX_POLL_WRITE)
{
- if (pd->out_flags & _PR_POLL_READ_SYS_WRITE)
+ if (pd->out_flags & _PR_POLL_READ_SYS_WRITE) {
out_flags |= PR_POLL_READ;
- if (pd->out_flags & _PR_POLL_WRITE_SYS_WRITE)
+ }
+ if (pd->out_flags & _PR_POLL_WRITE_SYS_WRITE) {
out_flags |= PR_POLL_WRITE;
+ }
}
- if (unixpd->out_flags & _PR_UNIX_POLL_EXCEPT)
+ if (unixpd->out_flags & _PR_UNIX_POLL_EXCEPT) {
out_flags |= PR_POLL_EXCEPT;
- if (unixpd->out_flags & _PR_UNIX_POLL_ERR)
+ }
+ if (unixpd->out_flags & _PR_UNIX_POLL_ERR) {
out_flags |= PR_POLL_ERR;
- if (unixpd->out_flags & _PR_UNIX_POLL_NVAL)
+ }
+ if (unixpd->out_flags & _PR_UNIX_POLL_NVAL) {
out_flags |= PR_POLL_NVAL;
- if (unixpd->out_flags & _PR_UNIX_POLL_HUP)
+ }
+ if (unixpd->out_flags & _PR_UNIX_POLL_HUP) {
out_flags |= PR_POLL_HUP;
+ }
}
unixpd++;
}
@@ -662,15 +703,20 @@ PRInt32 _MD_pr_poll(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
return -1;
}
- if (0 == npds) PR_Sleep(timeout);
- else if (_PR_IS_NATIVE_THREAD(me))
+ if (0 == npds) {
+ PR_Sleep(timeout);
+ }
+ else if (_PR_IS_NATIVE_THREAD(me)) {
rv = NativeThreads(pds, npds, timeout);
- else rv = LocalThreads(pds, npds, timeout);
+ }
+ else {
+ rv = LocalThreads(pds, npds, timeout);
+ }
return rv;
} /* _MD_pr_poll */
-#endif /* defined(_PR_PTHREADS) */
+#endif /* defined(_PR_PTHREADS) */
/* uxpoll.c */
diff --git a/nsprpub/pr/src/md/unix/uxproces.c b/nsprpub/pr/src/md/unix/uxproces.c
index 18f23fde8..4216c0442 100644
--- a/nsprpub/pr/src/md/unix/uxproces.c
+++ b/nsprpub/pr/src/md/unix/uxproces.c
@@ -55,11 +55,10 @@ typedef struct pr_PidRecord {
} pr_PidRecord;
/*
- * Irix sprocs and LinuxThreads are actually a kind of processes
+ * LinuxThreads are actually a kind of processes
* that can share the virtual address space and file descriptors.
*/
-#if (defined(IRIX) && !defined(_PR_PTHREADS)) \
- || ((defined(LINUX) || defined(__GNU__) || defined(__GLIBC__)) \
+#if ((defined(LINUX) || defined(__GNU__) || defined(__GLIBC__)) \
&& defined(_PR_PTHREADS))
#define _PR_SHARE_CLONES
#endif
@@ -74,8 +73,8 @@ typedef struct pr_PidRecord {
*/
#if defined(_PR_GLOBAL_THREADS_ONLY) \
- || (defined(_PR_PTHREADS) \
- && !defined(LINUX) && !defined(__GNU__) && !defined(__GLIBC__))
+ || (defined(_PR_PTHREADS) \
+ && !defined(LINUX) && !defined(__GNU__) && !defined(__GLIBC__))
#define _PR_NATIVE_THREADS
#endif
@@ -192,7 +191,7 @@ ForkAndExec(
#ifdef AIX
process->md.pid = (*pr_wp.forkptr)();
-#elif defined(NTO) || defined(SYMBIAN)
+#elif defined(NTO)
/*
* fork() & exec() does not work in a multithreaded process.
* Use spawn() instead.
@@ -204,38 +203,39 @@ ForkAndExec(
if (attr->stdinFd && attr->stdinFd->secret->md.osfd != 0) {
fd_map[0] = dup(attr->stdinFd->secret->md.osfd);
flags = fcntl(fd_map[0], F_GETFL, 0);
- if (flags & O_NONBLOCK)
+ if (flags & O_NONBLOCK) {
fcntl(fd_map[0], F_SETFL, flags & ~O_NONBLOCK);
+ }
}
if (attr->stdoutFd && attr->stdoutFd->secret->md.osfd != 1) {
fd_map[1] = dup(attr->stdoutFd->secret->md.osfd);
flags = fcntl(fd_map[1], F_GETFL, 0);
- if (flags & O_NONBLOCK)
+ if (flags & O_NONBLOCK) {
fcntl(fd_map[1], F_SETFL, flags & ~O_NONBLOCK);
+ }
}
if (attr->stderrFd && attr->stderrFd->secret->md.osfd != 2) {
fd_map[2] = dup(attr->stderrFd->secret->md.osfd);
flags = fcntl(fd_map[2], F_GETFL, 0);
- if (flags & O_NONBLOCK)
+ if (flags & O_NONBLOCK) {
fcntl(fd_map[2], F_SETFL, flags & ~O_NONBLOCK);
+ }
}
PR_ASSERT(attr->currentDirectory == NULL); /* not implemented */
}
-#ifdef SYMBIAN
- /* In Symbian OS, we use posix_spawn instead of fork() and exec() */
- posix_spawn(&(process->md.pid), path, NULL, NULL, argv, childEnvp);
-#else
process->md.pid = spawn(path, 3, fd_map, NULL, argv, childEnvp);
-#endif
- if (fd_map[0] != 0)
+ if (fd_map[0] != 0) {
close(fd_map[0]);
- if (fd_map[1] != 1)
+ }
+ if (fd_map[1] != 1) {
close(fd_map[1]);
- if (fd_map[2] != 2)
+ }
+ if (fd_map[2] != 2) {
close(fd_map[2]);
+ }
}
#else
process->md.pid = fork();
@@ -249,20 +249,20 @@ ForkAndExec(
return NULL;
}
if (0 == process->md.pid) { /* the child process */
- /*
- * If the child process needs to exit, it must call _exit().
- * Do not call exit(), because exit() will flush and close
- * the standard I/O file descriptors, and hence corrupt
- * the parent process's standard I/O data structures.
- */
-
-#if !defined(NTO) && !defined(SYMBIAN)
+ /*
+ * If the child process needs to exit, it must call _exit().
+ * Do not call exit(), because exit() will flush and close
+ * the standard I/O file descriptors, and hence corrupt
+ * the parent process's standard I/O data structures.
+ */
+
+#if !defined(NTO)
if (attr) {
/* the osfd's to redirect stdin, stdout, and stderr to */
int in_osfd = -1, out_osfd = -1, err_osfd = -1;
if (attr->stdinFd
- && attr->stdinFd->secret->md.osfd != 0) {
+ && attr->stdinFd->secret->md.osfd != 0) {
in_osfd = attr->stdinFd->secret->md.osfd;
if (dup2(in_osfd, 0) != 0) {
_exit(1); /* failed */
@@ -273,7 +273,7 @@ ForkAndExec(
}
}
if (attr->stdoutFd
- && attr->stdoutFd->secret->md.osfd != 1) {
+ && attr->stdoutFd->secret->md.osfd != 1) {
out_osfd = attr->stdoutFd->secret->md.osfd;
if (dup2(out_osfd, 1) != 1) {
_exit(1); /* failed */
@@ -284,7 +284,7 @@ ForkAndExec(
}
}
if (attr->stderrFd
- && attr->stderrFd->secret->md.osfd != 2) {
+ && attr->stderrFd->secret->md.osfd != 2) {
err_osfd = attr->stderrFd->secret->md.osfd;
if (dup2(err_osfd, 2) != 2) {
_exit(1); /* failed */
@@ -301,7 +301,7 @@ ForkAndExec(
close(out_osfd);
}
if (err_osfd != -1 && err_osfd != in_osfd
- && err_osfd != out_osfd) {
+ && err_osfd != out_osfd) {
close(err_osfd);
}
if (attr->currentDirectory) {
@@ -363,13 +363,13 @@ _MD_CreateUnixProcess(
int rv;
if (PR_CallOnce(&pr_wp.once, _MD_InitProcesses) == PR_FAILURE) {
- return NULL;
+ return NULL;
}
op = PR_NEW(struct pr_CreateProcOp);
if (NULL == op) {
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
- return NULL;
+ PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+ return NULL;
}
op->path = path;
op->argv = argv;
@@ -378,19 +378,19 @@ _MD_CreateUnixProcess(
op->done = PR_FALSE;
op->doneCV = PR_NewCondVar(pr_wp.ml);
if (NULL == op->doneCV) {
- PR_DELETE(op);
- return NULL;
+ PR_DELETE(op);
+ return NULL;
}
PR_Lock(pr_wp.ml);
/* add to the tail of op queue */
op->next = NULL;
if (pr_wp.opTail) {
- pr_wp.opTail->next = op;
- pr_wp.opTail = op;
+ pr_wp.opTail->next = op;
+ pr_wp.opTail = op;
} else {
- PR_ASSERT(NULL == pr_wp.opHead);
- pr_wp.opHead = pr_wp.opTail = op;
+ PR_ASSERT(NULL == pr_wp.opHead);
+ pr_wp.opHead = pr_wp.opTail = op;
}
/* wake up the daemon thread */
@@ -399,13 +399,13 @@ _MD_CreateUnixProcess(
} while (-1 == rv && EINTR == errno);
while (op->done == PR_FALSE) {
- PR_WaitCondVar(op->doneCV, PR_INTERVAL_NO_TIMEOUT);
+ PR_WaitCondVar(op->doneCV, PR_INTERVAL_NO_TIMEOUT);
}
PR_Unlock(pr_wp.ml);
PR_DestroyCondVar(op->doneCV);
proc = op->process;
if (!proc) {
- PR_SetError(op->prerror, op->oserror);
+ PR_SetError(op->prerror, op->oserror);
}
PR_DELETE(op);
return proc;
@@ -421,7 +421,7 @@ _MD_CreateUnixProcess(
const PRProcessAttr *attr)
{
if (PR_CallOnce(&pr_wp.once, _MD_InitProcesses) == PR_FAILURE) {
- return NULL;
+ return NULL;
}
return ForkAndExec(path, argv, envp, attr);
} /* _MD_CreateUnixProcess */
@@ -445,10 +445,10 @@ FindPidTable(pid_t pid)
pRec = pr_wp.pidTable[keyHash];
while (pRec) {
- if (pRec->pid == pid) {
- break;
- }
- pRec = pRec->next;
+ if (pRec->pid == pid) {
+ break;
+ }
+ pRec = pRec->next;
}
return pRec;
}
@@ -468,21 +468,21 @@ DeletePidTable(pr_PidRecord *pRec)
int keyHash = (int) (pRec->pid & PID_HASH_MASK);
if (pr_wp.pidTable[keyHash] == pRec) {
- pr_wp.pidTable[keyHash] = pRec->next;
+ pr_wp.pidTable[keyHash] = pRec->next;
} else {
- pr_PidRecord *pred, *cur; /* predecessor and current */
-
- pred = pr_wp.pidTable[keyHash];
- cur = pred->next;
- while (cur) {
- if (cur == pRec) {
- pred->next = cur->next;
- break;
+ pr_PidRecord *pred, *cur; /* predecessor and current */
+
+ pred = pr_wp.pidTable[keyHash];
+ cur = pred->next;
+ while (cur) {
+ if (cur == pRec) {
+ pred->next = cur->next;
+ break;
}
- pred = cur;
- cur = cur->next;
+ pred = cur;
+ cur = cur->next;
}
- PR_ASSERT(cur != NULL);
+ PR_ASSERT(cur != NULL);
}
}
@@ -498,10 +498,10 @@ ExtractExitStatus(int rawExitStatus)
PR_ASSERT(!WIFCONTINUED(rawExitStatus));
#endif
if (WIFEXITED(rawExitStatus)) {
- return WEXITSTATUS(rawExitStatus);
+ return WEXITSTATUS(rawExitStatus);
}
- PR_ASSERT(WIFSIGNALED(rawExitStatus));
- return _PR_SIGNALED_EXITSTATUS;
+ PR_ASSERT(WIFSIGNALED(rawExitStatus));
+ return _PR_SIGNALED_EXITSTATUS;
}
static void
@@ -553,16 +553,16 @@ static void WaitPidDaemonThread(void *unused)
}
PR_Unlock(pr_wp.ml);
- while (1) {
- do {
- pid = waitpid((pid_t) -1, &status, 0);
- } while ((pid_t) -1 == pid && EINTR == errno);
+ while (1) {
+ do {
+ pid = waitpid((pid_t) -1, &status, 0);
+ } while ((pid_t) -1 == pid && EINTR == errno);
/*
* waitpid() cannot return 0 because we did not invoke it
* with the WNOHANG option.
- */
- PR_ASSERT(0 != pid);
+ */
+ PR_ASSERT(0 != pid);
/*
* The only possible error code is ECHILD. But if we do
@@ -570,18 +570,18 @@ static void WaitPidDaemonThread(void *unused)
* when there is a child process to wait for.
*/
PR_ASSERT((pid_t) -1 != pid);
- if ((pid_t) -1 == pid) {
+ if ((pid_t) -1 == pid) {
break;
}
- PR_Lock(pr_wp.ml);
+ PR_Lock(pr_wp.ml);
ProcessReapedChildInternal(pid, status);
pr_wp.numProcs--;
while (0 == pr_wp.numProcs) {
PR_WaitCondVar(pr_wp.cv, PR_INTERVAL_NO_TIMEOUT);
}
- PR_Unlock(pr_wp.ml);
- }
+ PR_Unlock(pr_wp.ml);
+ }
}
}
@@ -616,48 +616,50 @@ static void WaitPidDaemonThread(void *unused)
if (pr_waitpid_daemon_exit) {
return;
}
- PR_Lock(pr_wp.ml);
+ PR_Lock(pr_wp.ml);
#endif
-
+
do {
rv = read(pr_wp.pipefd[0], buf, sizeof(buf));
} while (sizeof(buf) == rv || (-1 == rv && EINTR == errno));
#ifdef _PR_SHARE_CLONES
- while ((op = pr_wp.opHead) != NULL) {
- PR_Unlock(pr_wp.ml);
- op->process = ForkAndExec(op->path, op->argv,
- op->envp, op->attr);
- if (NULL == op->process) {
- op->prerror = PR_GetError();
- op->oserror = PR_GetOSError();
- }
- PR_Lock(pr_wp.ml);
- pr_wp.opHead = op->next;
- if (NULL == pr_wp.opHead) {
- pr_wp.opTail = NULL;
- }
- op->done = PR_TRUE;
- PR_NotifyCondVar(op->doneCV);
- }
- PR_Unlock(pr_wp.ml);
+ while ((op = pr_wp.opHead) != NULL) {
+ PR_Unlock(pr_wp.ml);
+ op->process = ForkAndExec(op->path, op->argv,
+ op->envp, op->attr);
+ if (NULL == op->process) {
+ op->prerror = PR_GetError();
+ op->oserror = PR_GetOSError();
+ }
+ PR_Lock(pr_wp.ml);
+ pr_wp.opHead = op->next;
+ if (NULL == pr_wp.opHead) {
+ pr_wp.opTail = NULL;
+ }
+ op->done = PR_TRUE;
+ PR_NotifyCondVar(op->doneCV);
+ }
+ PR_Unlock(pr_wp.ml);
#endif
- while (1) {
- do {
- pid = waitpid((pid_t) -1, &status, WNOHANG);
- } while ((pid_t) -1 == pid && EINTR == errno);
- if (0 == pid) break;
- if ((pid_t) -1 == pid) {
- /* must be because we have no child processes */
- PR_ASSERT(ECHILD == errno);
- break;
+ while (1) {
+ do {
+ pid = waitpid((pid_t) -1, &status, WNOHANG);
+ } while ((pid_t) -1 == pid && EINTR == errno);
+ if (0 == pid) {
+ break;
+ }
+ if ((pid_t) -1 == pid) {
+ /* must be because we have no child processes */
+ PR_ASSERT(ECHILD == errno);
+ break;
}
- PR_Lock(pr_wp.ml);
+ PR_Lock(pr_wp.ml);
ProcessReapedChildInternal(pid, status);
- PR_Unlock(pr_wp.ml);
- }
+ PR_Unlock(pr_wp.ml);
+ }
}
}
@@ -740,13 +742,13 @@ static PRStatus _MD_InitProcesses(void)
#endif /* !_PR_NATIVE_THREADS */
pr_wp.thread = PR_CreateThread(PR_SYSTEM_THREAD,
- WaitPidDaemonThread, NULL, PR_PRIORITY_NORMAL,
+ WaitPidDaemonThread, NULL, PR_PRIORITY_NORMAL,
#ifdef _PR_SHARE_CLONES
- PR_GLOBAL_THREAD,
+ PR_GLOBAL_THREAD,
#else
- PR_LOCAL_THREAD,
+ PR_LOCAL_THREAD,
#endif
- PR_JOINABLE_THREAD, 0);
+ PR_JOINABLE_THREAD, 0);
PR_ASSERT(NULL != pr_wp.thread);
pr_wp.pidTable = (pr_PidRecord**)PR_CALLOC(NBUCKETS * sizeof(pr_PidRecord *));
@@ -762,26 +764,26 @@ PRStatus _MD_DetachUnixProcess(PRProcess *process)
PR_Lock(pr_wp.ml);
pRec = FindPidTable(process->md.pid);
if (NULL == pRec) {
- pRec = PR_NEW(pr_PidRecord);
- if (NULL == pRec) {
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
- retVal = PR_FAILURE;
- goto done;
- }
- pRec->pid = process->md.pid;
- pRec->state = _PR_PID_DETACHED;
- pRec->reapedCV = NULL;
- InsertPidTable(pRec);
+ pRec = PR_NEW(pr_PidRecord);
+ if (NULL == pRec) {
+ PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+ retVal = PR_FAILURE;
+ goto done;
+ }
+ pRec->pid = process->md.pid;
+ pRec->state = _PR_PID_DETACHED;
+ pRec->reapedCV = NULL;
+ InsertPidTable(pRec);
} else {
- PR_ASSERT(_PR_PID_REAPED == pRec->state);
- if (_PR_PID_REAPED != pRec->state) {
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
- retVal = PR_FAILURE;
- } else {
- DeletePidTable(pRec);
- PR_ASSERT(NULL == pRec->reapedCV);
- PR_DELETE(pRec);
- }
+ PR_ASSERT(_PR_PID_REAPED == pRec->state);
+ if (_PR_PID_REAPED != pRec->state) {
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+ retVal = PR_FAILURE;
+ } else {
+ DeletePidTable(pRec);
+ PR_ASSERT(NULL == pRec->reapedCV);
+ PR_DELETE(pRec);
+ }
}
PR_DELETE(process);
@@ -801,47 +803,47 @@ PRStatus _MD_WaitUnixProcess(
PR_Lock(pr_wp.ml);
pRec = FindPidTable(process->md.pid);
if (NULL == pRec) {
- pRec = PR_NEW(pr_PidRecord);
- if (NULL == pRec) {
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
- retVal = PR_FAILURE;
- goto done;
- }
- pRec->pid = process->md.pid;
- pRec->state = _PR_PID_WAITING;
- pRec->reapedCV = PR_NewCondVar(pr_wp.ml);
- if (NULL == pRec->reapedCV) {
- PR_DELETE(pRec);
- retVal = PR_FAILURE;
- goto done;
- }
- InsertPidTable(pRec);
- while (!interrupted && _PR_PID_REAPED != pRec->state) {
- if (PR_WaitCondVar(pRec->reapedCV,
- PR_INTERVAL_NO_TIMEOUT) == PR_FAILURE
- && PR_GetError() == PR_PENDING_INTERRUPT_ERROR) {
- interrupted = PR_TRUE;
+ pRec = PR_NEW(pr_PidRecord);
+ if (NULL == pRec) {
+ PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+ retVal = PR_FAILURE;
+ goto done;
+ }
+ pRec->pid = process->md.pid;
+ pRec->state = _PR_PID_WAITING;
+ pRec->reapedCV = PR_NewCondVar(pr_wp.ml);
+ if (NULL == pRec->reapedCV) {
+ PR_DELETE(pRec);
+ retVal = PR_FAILURE;
+ goto done;
+ }
+ InsertPidTable(pRec);
+ while (!interrupted && _PR_PID_REAPED != pRec->state) {
+ if (PR_WaitCondVar(pRec->reapedCV,
+ PR_INTERVAL_NO_TIMEOUT) == PR_FAILURE
+ && PR_GetError() == PR_PENDING_INTERRUPT_ERROR) {
+ interrupted = PR_TRUE;
}
- }
- if (_PR_PID_REAPED == pRec->state) {
+ }
+ if (_PR_PID_REAPED == pRec->state) {
if (exitCode) {
*exitCode = pRec->exitStatus;
}
- } else {
- PR_ASSERT(interrupted);
- retVal = PR_FAILURE;
- }
- DeletePidTable(pRec);
- PR_DestroyCondVar(pRec->reapedCV);
- PR_DELETE(pRec);
+ } else {
+ PR_ASSERT(interrupted);
+ retVal = PR_FAILURE;
+ }
+ DeletePidTable(pRec);
+ PR_DestroyCondVar(pRec->reapedCV);
+ PR_DELETE(pRec);
} else {
- PR_ASSERT(_PR_PID_REAPED == pRec->state);
- PR_ASSERT(NULL == pRec->reapedCV);
- DeletePidTable(pRec);
+ PR_ASSERT(_PR_PID_REAPED == pRec->state);
+ PR_ASSERT(NULL == pRec->reapedCV);
+ DeletePidTable(pRec);
if (exitCode) {
*exitCode = pRec->exitStatus;
}
- PR_DELETE(pRec);
+ PR_DELETE(pRec);
}
PR_DELETE(process);
@@ -855,27 +857,21 @@ PRStatus _MD_KillUnixProcess(PRProcess *process)
PRErrorCode prerror;
PRInt32 oserror;
-#ifdef SYMBIAN
- /* In Symbian OS, we can not kill other process with Open C */
- PR_SetError(PR_OPERATION_NOT_SUPPORTED_ERROR, oserror);
- return PR_FAILURE;
-#else
if (kill(process->md.pid, SIGKILL) == 0) {
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
oserror = errno;
switch (oserror) {
case EPERM:
- prerror = PR_NO_ACCESS_RIGHTS_ERROR;
- break;
+ prerror = PR_NO_ACCESS_RIGHTS_ERROR;
+ break;
case ESRCH:
- prerror = PR_INVALID_ARGUMENT_ERROR;
- break;
+ prerror = PR_INVALID_ARGUMENT_ERROR;
+ break;
default:
- prerror = PR_UNKNOWN_ERROR;
- break;
+ prerror = PR_UNKNOWN_ERROR;
+ break;
}
PR_SetError(prerror, oserror);
return PR_FAILURE;
-#endif
} /* _MD_KillUnixProcess */
diff --git a/nsprpub/pr/src/md/unix/uxrng.c b/nsprpub/pr/src/md/unix/uxrng.c
index da2f7e9fe..479859000 100644
--- a/nsprpub/pr/src/md/unix/uxrng.c
+++ b/nsprpub/pr/src/md/unix/uxrng.c
@@ -20,7 +20,7 @@ GetHighResClock(void *buf, size_t maxbytes)
hrtime_t t;
t = gethrtime();
if (t) {
- return _pr_CopyLowBits(buf, maxbytes, &t, sizeof(t));
+ return _pr_CopyLowBits(buf, maxbytes, &t, sizeof(t));
}
return 0;
}
@@ -54,28 +54,6 @@ GetHighResClock(void *buf, size_t maxbytes)
}
#endif
-#elif defined(OSF1)
-
-#include <c_asm.h>
-
-/*
- * Use the "get the cycle counter" instruction on the alpha.
- * The low 32 bits completely turn over in less than a minute.
- * The high 32 bits are some non-counter gunk that changes sometimes.
- */
-static size_t
-GetHighResClock(void *buf, size_t maxbytes)
-{
- unsigned long t;
-
-#ifdef __GNUC__
- __asm__("rpcc %0" : "=r" (t));
-#else
- t = asm("rpcc %v0");
-#endif
- return _pr_CopyLowBits(buf, maxbytes, &t, sizeof(t));
-}
-
#elif defined(AIX)
static size_t
@@ -86,7 +64,7 @@ GetHighResClock(void *buf, size_t maxbytes)
#elif (defined(LINUX) || defined(FREEBSD) || defined(__FreeBSD_kernel__) \
|| defined(NETBSD) || defined(__NetBSD_kernel__) || defined(OPENBSD) \
- || defined(SYMBIAN) || defined(__GNU__))
+ || defined(__GNU__))
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -122,91 +100,8 @@ static size_t GetDevURandom( void *buf, size_t size )
static size_t
GetHighResClock(void *buf, size_t maxbytes)
-{
- return(GetDevURandom( buf, maxbytes ));
-}
-
-#elif defined(IRIX)
-#include <fcntl.h>
-#undef PRIVATE
-#include <sys/mman.h>
-#include <sys/syssgi.h>
-#include <sys/immu.h>
-#include <sys/systeminfo.h>
-#include <sys/utsname.h>
-
-static size_t GetHighResClock(void *buf, size_t maxbuf)
{
- unsigned phys_addr, raddr, cycleval;
- static volatile unsigned *iotimer_addr = NULL;
- static int tries = 0;
- static int cntr_size;
- int mfd;
- unsigned s0[2];
-
-#ifndef SGI_CYCLECNTR_SIZE
-#define SGI_CYCLECNTR_SIZE 165 /* Size user needs to use to read CC */
-#endif
-
- if (iotimer_addr == NULL) {
- if (tries++ > 1) {
- /* Don't keep trying if it didn't work */
- return 0;
- }
-
- /*
- ** For SGI machines we can use the cycle counter, if it has one,
- ** to generate some truly random numbers
- */
- phys_addr = syssgi(SGI_QUERY_CYCLECNTR, &cycleval);
- if (phys_addr) {
- int pgsz = getpagesize();
- int pgoffmask = pgsz - 1;
-
- raddr = phys_addr & ~pgoffmask;
- mfd = open("/dev/mmem", O_RDONLY);
- if (mfd < 0) {
- return 0;
- }
- iotimer_addr = (unsigned *)
- mmap(0, pgoffmask, PROT_READ, MAP_PRIVATE, mfd, (int)raddr);
- if (iotimer_addr == (unsigned*)-1) {
- close(mfd);
- iotimer_addr = NULL;
- return 0;
- }
- iotimer_addr = (unsigned*)
- ((__psint_t)iotimer_addr | (phys_addr & pgoffmask));
- /*
- * The file 'mfd' is purposefully not closed.
- */
- cntr_size = syssgi(SGI_CYCLECNTR_SIZE);
- if (cntr_size < 0) {
- struct utsname utsinfo;
-
- /*
- * We must be executing on a 6.0 or earlier system, since the
- * SGI_CYCLECNTR_SIZE call is not supported.
- *
- * The only pre-6.1 platforms with 64-bit counters are
- * IP19 and IP21 (Challenge, PowerChallenge, Onyx).
- */
- uname(&utsinfo);
- if (!strncmp(utsinfo.machine, "IP19", 4) ||
- !strncmp(utsinfo.machine, "IP21", 4))
- cntr_size = 64;
- else
- cntr_size = 32;
- }
- cntr_size /= 8; /* Convert from bits to bytes */
- }
- }
-
- s0[0] = *iotimer_addr;
- if (cntr_size > 4)
- s0[1] = *(iotimer_addr + 1);
- memcpy(buf, (char *)&s0[0], cntr_size);
- return _pr_CopyLowBits(buf, maxbuf, &s0, cntr_size);
+ return(GetDevURandom( buf, maxbytes ));
}
#elif defined(SCO) || defined(UNIXWARE) || defined(BSDI) || defined(NTO) \
diff --git a/nsprpub/pr/src/md/unix/uxshm.c b/nsprpub/pr/src/md/unix/uxshm.c
index 54e68191c..29a6030f4 100644
--- a/nsprpub/pr/src/md/unix/uxshm.c
+++ b/nsprpub/pr/src/md/unix/uxshm.c
@@ -14,7 +14,7 @@
#include <prshm.h>
#include <prerr.h>
#include <prmem.h>
-#include "primpl.h"
+#include "primpl.h"
#include <fcntl.h>
extern PRLogModuleInfo *_pr_shm_lm;
@@ -36,7 +36,7 @@ extern PRLogModuleInfo *_pr_shm_lm;
#define _MD_CLOSE_SHARED_MEMORY _MD_CloseSharedMemory
#define _MD_DELETE_SHARED_MEMORY _MD_DeleteSharedMemory
-extern PRSharedMemory * _MD_OpenSharedMemory(
+extern PRSharedMemory * _MD_OpenSharedMemory(
const char *name,
PRSize size,
PRIntn flags,
@@ -52,16 +52,16 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
if ( PR_FAILURE == rc )
{
_PR_MD_MAP_DEFAULT_ERROR( errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name ));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name ));
return( NULL );
}
shm = PR_NEWZAP( PRSharedMemory );
- if ( NULL == shm )
+ if ( NULL == shm )
{
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0 );
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New PRSharedMemory out of memory"));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New PRSharedMemory out of memory"));
return( NULL );
}
@@ -69,7 +69,7 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
if ( NULL == shm->ipcname )
{
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0 );
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New shm->ipcname out of memory"));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New shm->ipcname out of memory"));
PR_DELETE( shm );
return( NULL );
}
@@ -89,7 +89,7 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
PR_FREEIF( shm->ipcname );
PR_DELETE( shm );
return( NULL );
- }
+ }
if ( close(osfd) == -1 ) {
_PR_MD_MAP_CLOSE_ERROR( errno );
PR_FREEIF( shm->ipcname );
@@ -104,8 +104,8 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
{
rc = PR_FAILURE;
_PR_MD_MAP_DEFAULT_ERROR( errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_OpenSharedMemory(): ftok() failed on name: %s", shm->ipcname));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_OpenSharedMemory(): ftok() failed on name: %s", shm->ipcname));
PR_FREEIF( shm->ipcname );
PR_DELETE( shm );
return( NULL );
@@ -119,19 +119,19 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
}
if ((errno == EEXIST) && (flags & PR_SHM_EXCL)) {
PR_SetError( PR_FILE_EXISTS_ERROR, errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_OpenSharedMemory(): shmget() exclusive failed, errno: %d", errno));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_OpenSharedMemory(): shmget() exclusive failed, errno: %d", errno));
PR_FREEIF(shm->ipcname);
PR_DELETE(shm);
return(NULL);
}
- }
+ }
shm->id = shmget( key, shm->size, shm->mode );
if ( -1 == shm->id ) {
_PR_MD_MAP_DEFAULT_ERROR( errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_OpenSharedMemory(): shmget() failed, errno: %d", errno));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_OpenSharedMemory(): shmget() failed, errno: %d", errno));
PR_FREEIF(shm->ipcname);
PR_DELETE(shm);
return(NULL);
@@ -153,14 +153,14 @@ extern void * _MD_AttachSharedMemory( PRSharedMemory *shm, PRIntn flags )
if ( (void*)-1 == addr )
{
_PR_MD_MAP_DEFAULT_ERROR( errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_AttachSharedMemory(): shmat() failed on name: %s, OsError: %d",
- shm->ipcname, PR_GetOSError() ));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_AttachSharedMemory(): shmat() failed on name: %s, OsError: %d",
+ shm->ipcname, PR_GetOSError() ));
addr = NULL;
}
return addr;
-}
+}
extern PRStatus _MD_DetachSharedMemory( PRSharedMemory *shm, void *addr )
{
@@ -174,12 +174,12 @@ extern PRStatus _MD_DetachSharedMemory( PRSharedMemory *shm, void *addr )
{
rc = PR_FAILURE;
_PR_MD_MAP_DEFAULT_ERROR( errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_DetachSharedMemory(): shmdt() failed on name: %s", shm->ipcname ));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_DetachSharedMemory(): shmdt() failed on name: %s", shm->ipcname ));
}
return rc;
-}
+}
extern PRStatus _MD_CloseSharedMemory( PRSharedMemory *shm )
{
@@ -189,7 +189,7 @@ extern PRStatus _MD_CloseSharedMemory( PRSharedMemory *shm )
PR_DELETE(shm);
return PR_SUCCESS;
-}
+}
extern PRStatus _MD_DeleteSharedMemory( const char *name )
{
@@ -202,19 +202,19 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name )
rc = _PR_MakeNativeIPCName( name, ipcname, PR_IPC_NAME_SIZE, _PRIPCShm );
if ( PR_FAILURE == rc )
{
- PR_SetError( PR_UNKNOWN_ERROR , errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_DeleteSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name ));
+ PR_SetError( PR_UNKNOWN_ERROR, errno );
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_DeleteSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name ));
return(PR_FAILURE);
}
- /* create the file first */
+ /* create the file first */
{
int osfd = open( ipcname, (O_RDWR | O_CREAT), 0666 );
if ( -1 == osfd ) {
_PR_MD_MAP_OPEN_ERROR( errno );
return( PR_FAILURE );
- }
+ }
if ( close(osfd) == -1 ) {
_PR_MD_MAP_CLOSE_ERROR( errno );
return( PR_FAILURE );
@@ -227,20 +227,15 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name )
{
rc = PR_FAILURE;
_PR_MD_MAP_DEFAULT_ERROR( errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_DeleteSharedMemory(): ftok() failed on name: %s", ipcname));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_DeleteSharedMemory(): ftok() failed on name: %s", ipcname));
}
-#ifdef SYMBIAN
- /* In Symbian OS the system imposed minimum is 1 byte, instead of ZERO */
- id = shmget( key, 1, 0 );
-#else
id = shmget( key, 0, 0 );
-#endif
if ( -1 == id ) {
_PR_MD_MAP_DEFAULT_ERROR( errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_DeleteSharedMemory(): shmget() failed, errno: %d", errno));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_DeleteSharedMemory(): shmget() failed, errno: %d", errno));
return(PR_FAILURE);
}
@@ -248,16 +243,16 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name )
if ( -1 == urc )
{
_PR_MD_MAP_DEFAULT_ERROR( errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_DeleteSharedMemory(): shmctl() failed on name: %s", ipcname ));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_DeleteSharedMemory(): shmctl() failed on name: %s", ipcname ));
return(PR_FAILURE);
}
urc = unlink( ipcname );
if ( -1 == urc ) {
_PR_MD_MAP_UNLINK_ERROR( errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_DeleteSharedMemory(): unlink() failed: %s", ipcname ));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_DeleteSharedMemory(): unlink() failed: %s", ipcname ));
return(PR_FAILURE);
}
@@ -280,7 +275,7 @@ struct _MDSharedMemory {
int handle;
};
-extern PRSharedMemory * _MD_OpenSharedMemory(
+extern PRSharedMemory * _MD_OpenSharedMemory(
const char *name,
PRSize size,
PRIntn flags,
@@ -295,17 +290,17 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
rc = _PR_MakeNativeIPCName( name, ipcname, PR_IPC_NAME_SIZE, _PRIPCShm );
if ( PR_FAILURE == rc )
{
- PR_SetError( PR_UNKNOWN_ERROR , errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name ));
+ PR_SetError( PR_UNKNOWN_ERROR, errno );
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name ));
return( NULL );
}
shm = PR_NEWZAP( PRSharedMemory );
- if ( NULL == shm )
+ if ( NULL == shm )
{
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0 );
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New PRSharedMemory out of memory"));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New PRSharedMemory out of memory"));
return( NULL );
}
@@ -313,13 +308,13 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
if ( NULL == shm->ipcname )
{
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0 );
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New shm->ipcname out of memory"));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New shm->ipcname out of memory"));
return( NULL );
}
/* copy args to struct */
strcpy( shm->ipcname, ipcname );
- shm->size = size;
+ shm->size = size;
shm->mode = mode;
shm->flags = flags;
shm->ident = _PR_SHM_IDENT;
@@ -329,9 +324,10 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
*/
if ( flags & PR_SHM_CREATE ) {
int oflag = (O_CREAT | O_RDWR);
-
- if ( flags & PR_SHM_EXCL )
+
+ if ( flags & PR_SHM_EXCL ) {
oflag |= O_EXCL;
+ }
shm->id = shm_open( shm->ipcname, oflag, shm->mode );
} else {
shm->id = shm_open( shm->ipcname, O_RDWR, shm->mode );
@@ -339,9 +335,9 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
if ( -1 == shm->id ) {
_PR_MD_MAP_DEFAULT_ERROR( errno );
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_OpenSharedMemory(): shm_open failed: %s, OSError: %d",
- shm->ipcname, PR_GetOSError()));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_OpenSharedMemory(): shm_open failed: %s, OSError: %d",
+ shm->ipcname, PR_GetOSError()));
PR_DELETE( shm->ipcname );
PR_DELETE( shm );
return(NULL);
@@ -350,8 +346,8 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
end = ftruncate( shm->id, shm->size );
if ( -1 == end ) {
_PR_MD_MAP_DEFAULT_ERROR( errno );
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_OpenSharedMemory(): ftruncate failed, OSError: %d",
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_OpenSharedMemory(): ftruncate failed, OSError: %d",
PR_GetOSError()));
PR_DELETE( shm->ipcname );
PR_DELETE( shm );
@@ -368,24 +364,25 @@ extern void * _MD_AttachSharedMemory( PRSharedMemory *shm, PRIntn flags )
PR_ASSERT( shm->ident == _PR_SHM_IDENT );
- if ( PR_SHM_READONLY == flags)
+ if ( PR_SHM_READONLY == flags) {
prot ^= PROT_WRITE;
+ }
addr = mmap( (void*)0, shm->size, prot, MAP_SHARED, shm->id, 0 );
if ((void*)-1 == addr )
{
_PR_MD_MAP_DEFAULT_ERROR( errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_AttachSharedMemory(): mmap failed: %s, errno: %d",
- shm->ipcname, PR_GetOSError()));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_AttachSharedMemory(): mmap failed: %s, errno: %d",
+ shm->ipcname, PR_GetOSError()));
addr = NULL;
} else {
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_AttachSharedMemory(): name: %s, attached at: %p", shm->ipcname, addr));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_AttachSharedMemory(): name: %s, attached at: %p", shm->ipcname, addr));
}
-
+
return addr;
-}
+}
extern PRStatus _MD_DetachSharedMemory( PRSharedMemory *shm, void *addr )
{
@@ -399,30 +396,30 @@ extern PRStatus _MD_DetachSharedMemory( PRSharedMemory *shm, void *addr )
{
rc = PR_FAILURE;
_PR_MD_MAP_DEFAULT_ERROR( errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_DetachSharedMemory(): munmap failed: %s, errno: %d",
- shm->ipcname, PR_GetOSError()));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_DetachSharedMemory(): munmap failed: %s, errno: %d",
+ shm->ipcname, PR_GetOSError()));
}
return rc;
-}
+}
extern PRStatus _MD_CloseSharedMemory( PRSharedMemory *shm )
{
int urc;
-
+
PR_ASSERT( shm->ident == _PR_SHM_IDENT );
urc = close( shm->id );
if ( -1 == urc ) {
_PR_MD_MAP_CLOSE_ERROR( errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_CloseSharedMemory(): close() failed, error: %d", PR_GetOSError()));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_CloseSharedMemory(): close() failed, error: %d", PR_GetOSError()));
return(PR_FAILURE);
}
PR_DELETE( shm->ipcname );
PR_DELETE( shm );
return PR_SUCCESS;
-}
+}
extern PRStatus _MD_DeleteSharedMemory( const char *name )
{
@@ -433,9 +430,9 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name )
rc = _PR_MakeNativeIPCName( name, ipcname, PR_IPC_NAME_SIZE, _PRIPCShm );
if ( PR_FAILURE == rc )
{
- PR_SetError( PR_UNKNOWN_ERROR , errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name ));
+ PR_SetError( PR_UNKNOWN_ERROR, errno );
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name ));
return rc;
}
@@ -443,12 +440,12 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name )
if ( -1 == urc ) {
rc = PR_FAILURE;
_PR_MD_MAP_DEFAULT_ERROR( errno );
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_DeleteSharedMemory(): shm_unlink failed: %s, errno: %d",
- ipcname, PR_GetOSError()));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_DeleteSharedMemory(): shm_unlink failed: %s, errno: %d",
+ ipcname, PR_GetOSError()));
} else {
- PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_DeleteSharedMemory(): %s, success", ipcname));
+ PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
+ ("_MD_DeleteSharedMemory(): %s, success", ipcname));
}
return rc;
@@ -464,7 +461,7 @@ extern PRLogModuleInfo *_pr_shma_lm;
#include <unistd.h>
-extern PRFileMap* _md_OpenAnonFileMap(
+extern PRFileMap* _md_OpenAnonFileMap(
const char *dirName,
PRSize size,
PRFileMapProtect prot
@@ -488,100 +485,90 @@ extern PRFileMap* _md_OpenAnonFileMap(
** make maxTries number of attempts at uniqueness in the filename
*/
for ( incr = 0; incr < maxTries ; incr++ ) {
-#if defined(SYMBIAN)
-#define NSPR_AFM_FILENAME "%s\\NSPR-AFM-%d-%p.%d"
-#else
#define NSPR_AFM_FILENAME "%s/.NSPR-AFM-%d-%p.%d"
-#endif
genName = PR_smprintf( NSPR_AFM_FILENAME,
- dirName, (int) pid, tid, incr );
+ dirName, (int) pid, tid, incr );
if ( NULL == genName ) {
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_OpenAnonFileMap(): PR_snprintf(): failed, generating filename"));
+ ("_md_OpenAnonFileMap(): PR_snprintf(): failed, generating filename"));
goto Finished;
}
/* create the file */
osfd = open(genName, (O_CREAT | O_EXCL | O_RDWR), mode);
if (-1 == osfd) {
- if (EEXIST == errno) {
+ if (EEXIST == errno) {
+ PR_smprintf_free(genName);
+ continue; /* name exists, try again */
+ }
+ _PR_MD_MAP_OPEN_ERROR(errno);
+ PR_LOG(
+ _pr_shma_lm,
+ PR_LOG_DEBUG,
+ ("_md_OpenAnonFileMap(): open(): failed, filename: %s, errno: %d",
+ genName,
+ PR_GetOSError()));
PR_smprintf_free(genName);
- continue; /* name exists, try again */
- }
- _PR_MD_MAP_OPEN_ERROR(errno);
- PR_LOG(
- _pr_shma_lm,
- PR_LOG_DEBUG,
- ("_md_OpenAnonFileMap(): open(): failed, filename: %s, errno: %d",
- genName,
- PR_GetOSError()));
- PR_smprintf_free(genName);
- goto Finished;
+ goto Finished;
}
break; /* name generation and open successful, break; */
} /* end for() */
if (incr == maxTries) {
- PR_ASSERT(-1 == osfd);
- PR_ASSERT(EEXIST == errno);
- _PR_MD_MAP_OPEN_ERROR(errno);
- goto Finished;
+ PR_ASSERT(-1 == osfd);
+ PR_ASSERT(EEXIST == errno);
+ _PR_MD_MAP_OPEN_ERROR(errno);
+ goto Finished;
}
urc = unlink( genName );
-#if defined(SYMBIAN) && defined(__WINS__)
- /* If it is being used by the system or another process, Symbian OS
- * Emulator(WINS) considers this an error. */
- if ( -1 == urc && EACCES != errno ) {
-#else
if ( -1 == urc ) {
-#endif
_PR_MD_MAP_UNLINK_ERROR( errno );
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_OpenAnonFileMap(): failed on unlink(), errno: %d", errno));
+ ("_md_OpenAnonFileMap(): failed on unlink(), errno: %d", errno));
PR_smprintf_free( genName );
close( osfd );
- goto Finished;
+ goto Finished;
}
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_OpenAnonFileMap(): unlink(): %s", genName ));
+ ("_md_OpenAnonFileMap(): unlink(): %s", genName ));
PR_smprintf_free( genName );
fd = PR_ImportFile( osfd );
if ( NULL == fd ) {
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_OpenAnonFileMap(): PR_ImportFile(): failed"));
- goto Finished;
+ ("_md_OpenAnonFileMap(): PR_ImportFile(): failed"));
+ goto Finished;
}
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_OpenAnonFileMap(): fd: %p", fd ));
+ ("_md_OpenAnonFileMap(): fd: %p", fd ));
urc = ftruncate( fd->secret->md.osfd, size );
if ( -1 == urc ) {
_PR_MD_MAP_DEFAULT_ERROR( errno );
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_OpenAnonFileMap(): failed on ftruncate(), errno: %d", errno));
+ ("_md_OpenAnonFileMap(): failed on ftruncate(), errno: %d", errno));
PR_Close( fd );
- goto Finished;
+ goto Finished;
}
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_OpenAnonFileMap(): ftruncate(): size: %d", size ));
+ ("_md_OpenAnonFileMap(): ftruncate(): size: %d", size ));
LL_UI2L(size64, size); /* PRSize (size_t) is unsigned */
fm = PR_CreateFileMap( fd, size64, prot );
if ( NULL == fm ) {
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("PR_OpenAnonFileMap(): failed"));
+ ("PR_OpenAnonFileMap(): failed"));
PR_Close( fd );
- goto Finished;
+ goto Finished;
}
fm->md.isAnonFM = PR_TRUE; /* set fd close */
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_OpenAnonFileMap(): PR_CreateFileMap(): fm: %p", fm ));
+ ("_md_OpenAnonFileMap(): PR_CreateFileMap(): fm: %p", fm ));
-Finished:
+Finished:
return(fm);
} /* end md_OpenAnonFileMap() */
@@ -598,10 +585,10 @@ extern PRStatus _md_ExportFileMapAsString(
{
PRIntn written;
PRIntn prot = (PRIntn)fm->prot;
-
+
written = PR_snprintf( buf, bufSize, "%ld:%d",
- fm->fd->secret->md.osfd, prot );
-
+ fm->fd->secret->md.osfd, prot );
+
return((written == -1)? PR_FAILURE : PR_SUCCESS);
} /* end _md_ExportFileMapAsString() */
@@ -623,21 +610,21 @@ extern PRFileMap * _md_ImportFileMapFromString(
fd = PR_ImportFile( osfd );
if ( NULL == fd ) {
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_ImportFileMapFromString(): PR_ImportFile() failed"));
+ ("_md_ImportFileMapFromString(): PR_ImportFile() failed"));
goto Finished;
}
rc = PR_GetOpenFileInfo64( fd, &info );
if ( PR_FAILURE == rc ) {
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_ImportFileMapFromString(): PR_GetOpenFileInfo64() failed"));
+ ("_md_ImportFileMapFromString(): PR_GetOpenFileInfo64() failed"));
goto Finished;
}
fm = PR_CreateFileMap( fd, info.size, (PRFileMapProtect)prot );
if ( NULL == fm ) {
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_ImportFileMapFromString(): PR_CreateFileMap() failed"));
+ ("_md_ImportFileMapFromString(): PR_CreateFileMap() failed"));
}
Finished:
diff --git a/nsprpub/pr/src/md/unix/uxwrap.c b/nsprpub/pr/src/md/unix/uxwrap.c
index 3f8e149ef..d6f6d0621 100644
--- a/nsprpub/pr/src/md/unix/uxwrap.c
+++ b/nsprpub/pr/src/md/unix/uxwrap.c
@@ -18,30 +18,25 @@
/* Do not wrap select() and poll(). */
#else /* defined(_PR_PTHREADS) || defined(_PR_GLOBAL_THREADS_ONLY) */
/* The include files for select() */
-#ifdef IRIX
-#include <unistd.h>
-#include <bstring.h>
-#endif
-
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>
-#define ZAP_SET(_to, _width) \
- PR_BEGIN_MACRO \
- memset(_to, 0, \
- ((_width + 8*sizeof(int)-1) / (8*sizeof(int))) \
- * sizeof(int) \
- ); \
+#define ZAP_SET(_to, _width) \
+ PR_BEGIN_MACRO \
+ memset(_to, 0, \
+ ((_width + 8*sizeof(int)-1) / (8*sizeof(int))) \
+ * sizeof(int) \
+ ); \
PR_END_MACRO
/* see comments in ns/cmd/xfe/mozilla.c (look for "PR_XGetXtHackFD") */
static int _pr_xt_hack_fd = -1;
-
+
int PR_XGetXtHackFD(void)
{
int fds[2];
-
+
if (_pr_xt_hack_fd == -1) {
if (!pipe(fds)) {
_pr_xt_hack_fd = fds[0];
@@ -54,7 +49,7 @@ static int (*_pr_xt_hack_okayToReleaseXLock)(void) = 0;
void PR_SetXtHackOkayToReleaseXLockFn(int (*fn)(void))
{
- _pr_xt_hack_okayToReleaseXLock = fn;
+ _pr_xt_hack_okayToReleaseXLock = fn;
}
@@ -72,10 +67,10 @@ void PR_SetXtHackOkayToReleaseXLockFn(int (*fn)(void))
int select(size_t width, int *rl, int *wl, int *el, const struct timeval *tv)
#elif defined(AIX_RENAME_SELECT)
int wrap_select(unsigned long width, void *rl, void *wl, void *el,
- struct timeval *tv)
+ struct timeval *tv)
#elif defined(_PR_SELECT_CONST_TIMEVAL)
int select(int width, fd_set *rd, fd_set *wr, fd_set *ex,
- const struct timeval *tv)
+ const struct timeval *tv)
#else
int select(int width, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *tv)
#endif
@@ -108,10 +103,10 @@ int select(int width, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *tv)
if (!_pr_initialized) {
_PR_ImplicitInitialization();
}
-
+
#ifndef _PR_LOCAL_THREADS_ONLY
if (_PR_IS_NATIVE_THREAD(_PR_MD_CURRENT_THREAD())) {
- return _MD_SELECT(width, rd, wr, ex, tv);
+ return _MD_SELECT(width, rd, wr, ex, tv);
}
#endif
@@ -127,7 +122,7 @@ int select(int width, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *tv)
* from the select() man pages.
*/
if (tv->tv_sec < 0 || tv->tv_sec > 100000000
- || tv->tv_usec < 0 || tv->tv_usec >= 1000000) {
+ || tv->tv_usec < 0 || tv->tv_usec >= 1000000) {
errno = EINVAL;
return -1;
}
@@ -187,31 +182,37 @@ int select(int width, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *tv)
* see comments in mozilla/cmd/xfe/mozilla.c (look for
* "PR_XGetXtHackFD")
*/
- {
- int needToLockXAgain;
-
- needToLockXAgain = 0;
- if (rd && (_pr_xt_hack_fd != -1)
- && FD_ISSET(_pr_xt_hack_fd, rd) && PR_XIsLocked()
- && (!_pr_xt_hack_okayToReleaseXLock
- || _pr_xt_hack_okayToReleaseXLock())) {
- PR_XUnlock();
- needToLockXAgain = 1;
- }
-
- /* This is the potentially blocking step */
- retVal = _PR_WaitForMultipleFDs(unixpds, pdcnt, timeout);
-
- if (needToLockXAgain) {
- PR_XLock();
- }
- }
+ {
+ int needToLockXAgain;
+
+ needToLockXAgain = 0;
+ if (rd && (_pr_xt_hack_fd != -1)
+ && FD_ISSET(_pr_xt_hack_fd, rd) && PR_XIsLocked()
+ && (!_pr_xt_hack_okayToReleaseXLock
+ || _pr_xt_hack_okayToReleaseXLock())) {
+ PR_XUnlock();
+ needToLockXAgain = 1;
+ }
+
+ /* This is the potentially blocking step */
+ retVal = _PR_WaitForMultipleFDs(unixpds, pdcnt, timeout);
+
+ if (needToLockXAgain) {
+ PR_XLock();
+ }
+ }
if (retVal > 0) {
/* Compute select results */
- if (rd) ZAP_SET(rd, width);
- if (wr) ZAP_SET(wr, width);
- if (ex) ZAP_SET(ex, width);
+ if (rd) {
+ ZAP_SET(rd, width);
+ }
+ if (wr) {
+ ZAP_SET(wr, width);
+ }
+ if (ex) {
+ ZAP_SET(ex, width);
+ }
/*
* The return value can be either the number of ready file
@@ -226,7 +227,7 @@ int select(int width, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *tv)
if (unixpd->out_flags & _PR_UNIX_POLL_NVAL) {
errno = EBADF;
PR_LOG(_pr_io_lm, PR_LOG_ERROR,
- ("select returns EBADF for %d", unixpd->osfd));
+ ("select returns EBADF for %d", unixpd->osfd));
retVal = -1;
break;
}
@@ -238,27 +239,25 @@ int select(int width, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *tv)
* it has a hangup condition.
*/
if (rd && (unixpd->in_flags & _PR_UNIX_POLL_READ)
- && (unixpd->out_flags & (_PR_UNIX_POLL_READ
- | _PR_UNIX_POLL_ERR | _PR_UNIX_POLL_HUP))) {
+ && (unixpd->out_flags & (_PR_UNIX_POLL_READ
+ | _PR_UNIX_POLL_ERR | _PR_UNIX_POLL_HUP))) {
FD_SET(unixpd->osfd, rd);
nbits++;
}
if (wr && (unixpd->in_flags & _PR_UNIX_POLL_WRITE)
- && (unixpd->out_flags & (_PR_UNIX_POLL_WRITE
- | _PR_UNIX_POLL_ERR))) {
+ && (unixpd->out_flags & (_PR_UNIX_POLL_WRITE
+ | _PR_UNIX_POLL_ERR))) {
FD_SET(unixpd->osfd, wr);
nbits++;
}
if (ex && (unixpd->in_flags & _PR_UNIX_POLL_WRITE)
- && (unixpd->out_flags & PR_POLL_EXCEPT)) {
+ && (unixpd->out_flags & PR_POLL_EXCEPT)) {
FD_SET(unixpd->osfd, ex);
nbits++;
}
PR_ASSERT(nbits > 0);
-#if defined(HPUX) || defined(SOLARIS) || defined(OSF1) || defined(AIX)
+#if defined(HPUX) || defined(SOLARIS) || defined(AIX)
retVal += nbits;
-#else /* IRIX */
- retVal += 1;
#endif
}
}
@@ -288,7 +287,7 @@ int select(int width, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *tv)
*-----------------------------------------------------------------------
* poll() --
*
- * RETURN VALUES:
+ * RETURN VALUES:
* -1: fails, errno indicates the error.
* 0: timed out, the revents bitmasks are not set.
* positive value: the number of file descriptors for which poll()
@@ -303,7 +302,7 @@ int select(int width, fd_set *rd, fd_set *wr, fd_set *ex, struct timeval *tv)
int wrap_poll(void *listptr, unsigned long nfds, long timeout)
#elif (defined(AIX) && !defined(AIX_RENAME_SELECT))
int poll(void *listptr, unsigned long nfds, long timeout)
-#elif defined(OSF1) || (defined(HPUX) && !defined(HPUX9))
+#elif defined(HPUX) && !defined(HPUX9)
int poll(struct pollfd filedes[], unsigned int nfds, int timeout)
#elif defined(HPUX9)
int poll(struct pollfd filedes[], int nfds, int timeout)
@@ -344,7 +343,7 @@ int poll(struct pollfd *filedes, unsigned long nfds, int timeout)
#ifndef _PR_LOCAL_THREADS_ONLY
if (_PR_IS_NATIVE_THREAD(_PR_MD_CURRENT_THREAD())) {
- return _MD_POLL(filedes, nfds, timeout);
+ return _MD_POLL(filedes, nfds, timeout);
}
#endif
@@ -372,7 +371,7 @@ int poll(struct pollfd *filedes, unsigned long nfds, int timeout)
}
unixpds = (_PRUnixPollDesc *)
- PR_MALLOC(nfds * sizeof(_PRUnixPollDesc));
+ PR_MALLOC(nfds * sizeof(_PRUnixPollDesc));
if (NULL == unixpds) {
errno = EAGAIN;
return -1;
@@ -405,23 +404,23 @@ int poll(struct pollfd *filedes, unsigned long nfds, int timeout)
unixpd->in_flags = 0;
if (pfd->events & (POLLIN
#ifdef POLLRDNORM
- | POLLRDNORM
+ | POLLRDNORM
#endif
- )) {
+ )) {
unixpd->in_flags |= _PR_UNIX_POLL_READ;
}
if (pfd->events & (POLLOUT
#ifdef POLLWRNORM
- | POLLWRNORM
+ | POLLWRNORM
#endif
- )) {
+ )) {
unixpd->in_flags |= _PR_UNIX_POLL_WRITE;
}
if (pfd->events & (POLLPRI
#ifdef POLLRDBAND
- | POLLRDBAND
+ | POLLRDBAND
#endif
- )) {
+ )) {
unixpd->in_flags |= PR_POLL_EXCEPT;
}
#endif /* _PR_USE_POLL */
diff --git a/nsprpub/pr/src/md/windows/ntdllmn.c b/nsprpub/pr/src/md/windows/ntdllmn.c
index 7dec0517d..e64b312d0 100644
--- a/nsprpub/pr/src/md/windows/ntdllmn.c
+++ b/nsprpub/pr/src/md/windows/ntdllmn.c
@@ -26,7 +26,7 @@ BOOL WINAPI DllMain(
DWORD fdwReason,
LPVOID lpvReserved)
{
-PRThread *me;
+ PRThread *me;
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
@@ -45,8 +45,9 @@ PRThread *me;
case DLL_THREAD_DETACH:
if (_pr_initialized) {
me = _MD_GET_ATTACHED_THREAD();
- if ((me != NULL) && (me->flags & _PR_ATTACHED))
+ if ((me != NULL) && (me->flags & _PR_ATTACHED)) {
_PRI_DetachThread();
+ }
}
break;
case DLL_PROCESS_DETACH:
diff --git a/nsprpub/pr/src/md/windows/ntgc.c b/nsprpub/pr/src/md/windows/ntgc.c
index 55ac92fb0..20ad8a81e 100644
--- a/nsprpub/pr/src/md/windows/ntgc.c
+++ b/nsprpub/pr/src/md/windows/ntgc.c
@@ -10,7 +10,7 @@
#include <windows.h>
#include "primpl.h"
-PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
+PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
{
#if defined(_X86_)
CONTEXT context;
@@ -34,8 +34,8 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
} else {
/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING
*
- * This code is extremely machine dependant and completely
- * undocumented by MS. Its only known to work experimentally.
+ * This code is extremely machine dependant and completely
+ * undocumented by MS. Its only known to work experimentally.
* Ready for a walk on the wild * side?
*
* WARNING WARNING WARNING WARNING WARNING WARNING WARNING */
@@ -47,7 +47,7 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
* Are your palms sweating yet?
*/
- /*
+ /*
** EAX is on the stack (ESP+0)
** EDX is on the stack (ESP+4)
** ECX is on the stack (ESP+8)
@@ -71,7 +71,7 @@ PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
}
/* This function is not used right now, but is left as a reference.
- * If you ever need to get the fiberID from the currently running fiber,
+ * If you ever need to get the fiberID from the currently running fiber,
* this is it.
*/
void *
@@ -81,15 +81,15 @@ GetMyFiberID()
void *fiberData;
/* A pointer to our tib entry is found at FS:[18]
- * At offset 10h is the fiberData pointer. The context of the
- * fiber is stored in there.
+ * At offset 10h is the fiberData pointer. The context of the
+ * fiber is stored in there.
*/
__asm {
mov EDX, FS:[18h]
mov EAX, DWORD PTR [EDX+10h]
mov [fiberData], EAX
}
-
+
return fiberData;
#else
PR_NOT_REACHED("not implemented");
diff --git a/nsprpub/pr/src/md/windows/ntinrval.c b/nsprpub/pr/src/md/windows/ntinrval.c
index 10aca11ba..a44780455 100644
--- a/nsprpub/pr/src/md/windows/ntinrval.c
+++ b/nsprpub/pr/src/md/windows/ntinrval.c
@@ -26,14 +26,14 @@ _PR_MD_INTERVAL_INIT()
HMODULE mmtimerlib = LoadLibraryW(L"mmtimer.dll"); /* XXX leaked! */
if (mmtimerlib) {
intervalFunc = (IntervalFuncType)GetProcAddress(mmtimerlib,
- "timeGetTime");
+ "timeGetTime");
} else {
intervalFunc = &GetTickCount;
}
#endif
}
-PRIntervalTime
+PRIntervalTime
_PR_MD_GET_INTERVAL()
{
/* milliseconds since system start */
@@ -44,7 +44,7 @@ _PR_MD_GET_INTERVAL()
#endif
}
-PRIntervalTime
+PRIntervalTime
_PR_MD_INTERVAL_PER_SEC()
{
return 1000;
diff --git a/nsprpub/pr/src/md/windows/ntio.c b/nsprpub/pr/src/md/windows/ntio.c
index aba53dc85..040bbd310 100644
--- a/nsprpub/pr/src/md/windows/ntio.c
+++ b/nsprpub/pr/src/md/windows/ntio.c
@@ -9,7 +9,7 @@
* For LOCAL_SCOPE threads, we're using NT fibers. For GLOBAL_SCOPE threads
* we're using NT-native threads.
*
- * When doing IO, we want to use completion ports for optimal performance
+ * When doing IO, we want to use completion ports for optimal performance
* with fibers. But if we use completion ports for all IO, it is difficult
* to project a blocking model with GLOBAL_SCOPE threads. To handle this
* we create an extra thread for completing IO for GLOBAL_SCOPE threads.
@@ -32,9 +32,9 @@ static PRThread *_pr_io_completion_thread;
#define RECYCLE_SIZE 512
static struct _MDLock _pr_recycle_lock;
static PRInt32 _pr_recycle_INET_array[RECYCLE_SIZE];
-static PRInt32 _pr_recycle_INET_tail = 0;
+static PRInt32 _pr_recycle_INET_tail = 0;
static PRInt32 _pr_recycle_INET6_array[RECYCLE_SIZE];
-static PRInt32 _pr_recycle_INET6_tail = 0;
+static PRInt32 _pr_recycle_INET6_tail = 0;
__declspec(thread) PRThread *_pr_io_restarted_io = NULL;
DWORD _pr_io_restartedIOIndex; /* The thread local storage slot for each
@@ -97,14 +97,14 @@ static PRInt32 _nt_nonblock_recvfrom(PRFileDesc *, char *, int, struct sockaddr
* An inheritable fd cannot be associated with an I/O completion port
* because the completion notification of async I/O initiated by the
* child process is still posted to the I/O completion port in the
- * parent process.
+ * parent process.
*/
#define _NT_USE_NB_IO(fd) \
((fd)->secret->nonblocking || (fd)->secret->inheritable == _PR_TRI_TRUE)
/*
* UDP support
- *
+ *
* UDP is supported on NT by the continuation thread mechanism.
* The code is borrowed from ptio.c in pthreads nspr, hence the
* PT and pt prefixes. This mechanism is in fact general and
@@ -134,12 +134,22 @@ struct pt_Continuation
/* The building of the continuation operation */
ContinuationFn function; /* what function to continue */
- union { SOCKET osfd; } arg1; /* #1 - the op's fd */
- union { void* buffer; } arg2; /* #2 - primary transfer buffer */
- union { PRIntn amount; } arg3; /* #3 - size of 'buffer' */
- union { PRIntn flags; } arg4; /* #4 - read/write flags */
- union { PRNetAddr *addr; } arg5; /* #5 - send/recv address */
-
+ union {
+ SOCKET osfd;
+ } arg1; /* #1 - the op's fd */
+ union {
+ void* buffer;
+ } arg2; /* #2 - primary transfer buffer */
+ union {
+ PRIntn amount;
+ } arg3; /* #3 - size of 'buffer' */
+ union {
+ PRIntn flags;
+ } arg4; /* #4 - read/write flags */
+ union {
+ PRNetAddr *addr;
+ } arg5; /* #5 - send/recv address */
+
PRIntervalTime timeout; /* representation of the timeout */
PRIntn event; /* flags for select()'s events */
@@ -149,7 +159,10 @@ struct pt_Continuation
** These function can either return an int return code or a pointer to
** some object.
*/
- union { PRIntn code; void *object; } result;
+ union {
+ PRIntn code;
+ void *object;
+ } result;
PRIntn syserrno; /* in case it failed, why (errno) */
pr_ContuationStatus status; /* the status of the operation */
@@ -184,7 +197,7 @@ static PRInt32 pt_SendTo(
PRInt32 amount, PRInt32 flags, const PRNetAddr *addr,
PRIntn addrlen, PRIntervalTime timeout);
static PRInt32 pt_RecvFrom(SOCKET osfd, void *buf, PRInt32 amount,
- PRInt32 flags, PRNetAddr *addr, PRIntn *addr_len, PRIntervalTime timeout);
+ PRInt32 flags, PRNetAddr *addr, PRIntn *addr_len, PRIntervalTime timeout);
/* The key returned from GetQueuedCompletionStatus() is used to determine what
@@ -215,10 +228,10 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
PR_ASSERT(deadThread->state == _PR_DEAD_STATE);
/* XXXMB - cleanup to do here? */
- if ( !_PR_IS_NATIVE_THREAD(deadThread) ){
+ if ( !_PR_IS_NATIVE_THREAD(deadThread) ) {
/* Spinlock while user thread is still running.
* There is no way to use a condition variable here. The thread
- * is dead, and we have to wait until we switch off the dead
+ * is dead, and we have to wait until we switch off the dead
* thread before we can kill the fiber completely.
*/
while ( deadThread->no_sched)
@@ -227,8 +240,9 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
DeleteFiber(deadThread->md.fiber_id);
}
memset(deadThread, 0xa, sizeof(PRThread)); /* debugging */
- if (!deadThread->threadAllocatedOnStack)
+ if (!deadThread->threadAllocatedOnStack) {
PR_DELETE(deadThread);
+ }
_nt_idleCount--;
}
_MD_UNLOCK(&_nt_idleLock);
@@ -238,18 +252,19 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
#if 0
timeout = INFINITE;
#else
- /*
- * temporary hack to poll the runq every 5 seconds because of bug in
- * native threads creating user threads and not poking the right cpu.
- *
- * A local thread that was interrupted is bound to its current
- * cpu but there is no easy way for the interrupter to poke the
- * right cpu. This is a hack to poll the runq every 5 seconds.
- */
+ /*
+ * temporary hack to poll the runq every 5 seconds because of bug in
+ * native threads creating user threads and not poking the right cpu.
+ *
+ * A local thread that was interrupted is bound to its current
+ * cpu but there is no easy way for the interrupter to poke the
+ * right cpu. This is a hack to poll the runq every 5 seconds.
+ */
timeout = 5000;
#endif
- else
+ else {
timeout = PR_IntervalToMilliseconds(ticks);
+ }
/*
* The idea of looping here is to complete as many IOs as possible before
@@ -257,11 +272,11 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
*/
while(1) {
rv = GetQueuedCompletionStatus(
- _pr_completion_port,
- &bytes,
- &key,
- &olp,
- timeout);
+ _pr_completion_port,
+ &bytes,
+ &key,
+ &olp,
+ timeout);
if (rv == 0 && olp == NULL) {
/* Error in GetQueuedCompetionStatus */
if (GetLastError() != WAIT_TIMEOUT) {
@@ -273,8 +288,9 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
}
}
- if (olp == NULL)
+ if (olp == NULL) {
return 0;
+ }
mdOlp = (_MDOverlapped *)olp;
@@ -288,8 +304,8 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
PR_ASSERT(desc != NULL);
mwstatus = rv ? PR_MW_SUCCESS : PR_MW_FAILURE;
if (InterlockedCompareExchange((PVOID *)&desc->outcome,
- (PVOID)mwstatus, (PVOID)PR_MW_PENDING)
- == (PVOID)PR_MW_PENDING) {
+ (PVOID)mwstatus, (PVOID)PR_MW_PENDING)
+ == (PVOID)PR_MW_PENDING) {
if (mwstatus == PR_MW_SUCCESS) {
desc->bytesRecv = bytes;
} else {
@@ -344,8 +360,9 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
PR_ASSERT(mdOlp->ioModel == _MD_BlockingIO);
completed_io = _PR_THREAD_MD_TO_PTR(mdOlp->data.mdThread);
completed_io->md.blocked_io_status = rv;
- if (rv == 0)
+ if (rv == 0) {
completed_io->md.blocked_io_error = GetLastError();
+ }
completed_io->md.blocked_io_bytes = bytes;
if ( !_PR_IS_NATIVE_THREAD(completed_io) ) {
@@ -354,7 +371,7 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
/* The KEY_CVAR notification only occurs when a native thread
* is notifying a user thread. For user-user notifications
- * the wakeup occurs by having the notifier place the thread
+ * the wakeup occurs by having the notifier place the thread
* on the runq directly; for native-native notifications the
* wakeup occurs by calling ReleaseSemaphore.
*/
@@ -391,16 +408,17 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
_PR_THREAD_UNLOCK(completed_io);
- /*
- * If an I/O operation is suspended, the thread
- * must be running on the same cpu on which the
- * I/O operation was issued.
- */
- PR_ASSERT(!completed_io->md.thr_bound_cpu ||
- (completed_io->cpu == completed_io->md.thr_bound_cpu));
-
- if (!completed_io->md.thr_bound_cpu)
- completed_io->cpu = lockedCPU;
+ /*
+ * If an I/O operation is suspended, the thread
+ * must be running on the same cpu on which the
+ * I/O operation was issued.
+ */
+ PR_ASSERT(!completed_io->md.thr_bound_cpu ||
+ (completed_io->cpu == completed_io->md.thr_bound_cpu));
+
+ if (!completed_io->md.thr_bound_cpu) {
+ completed_io->cpu = lockedCPU;
+ }
completed_io->state = _PR_RUNNABLE;
_PR_RUNQ_LOCK(completed_io->cpu);
_PR_ADD_RUNQ(completed_io, completed_io->cpu, pri);
@@ -423,7 +441,7 @@ _PR_MD_PAUSE_CPU(PRIntervalTime ticks)
completed_io->state = _PR_RUNNABLE;
_PR_THREAD_UNLOCK(completed_io);
rv = ReleaseSemaphore(completed_io->md.blocked_sema,
- 1, NULL);
+ 1, NULL);
PR_ASSERT(0 != rv);
} else {
_PR_THREAD_UNLOCK(completed_io);
@@ -443,41 +461,41 @@ static PRStatus
_native_thread_md_wait(PRThread *thread, PRIntervalTime ticks)
{
DWORD rv;
- PRUint32 msecs = (ticks == PR_INTERVAL_NO_TIMEOUT) ?
- INFINITE : PR_IntervalToMilliseconds(ticks);
-
- /*
- * thread waiting for a cvar or a joining thread
- */
- rv = WaitForSingleObject(thread->md.blocked_sema, msecs);
- switch(rv) {
- case WAIT_OBJECT_0:
- return PR_SUCCESS;
- break;
- case WAIT_TIMEOUT:
- _PR_THREAD_LOCK(thread);
- PR_ASSERT (thread->state != _PR_IO_WAIT);
- if (thread->wait.cvar != NULL) {
- PR_ASSERT(thread->state == _PR_COND_WAIT);
- thread->wait.cvar = NULL;
- thread->state = _PR_RUNNING;
- _PR_THREAD_UNLOCK(thread);
- } else {
- /* The CVAR was notified just as the timeout
- * occurred. This left the semaphore in the
- * signaled state. Call WaitForSingleObject()
- * to clear the semaphore.
- */
- _PR_THREAD_UNLOCK(thread);
- rv = WaitForSingleObject(thread->md.blocked_sema, INFINITE);
- PR_ASSERT(rv == WAIT_OBJECT_0);
- }
- return PR_SUCCESS;
- break;
- default:
- return PR_FAILURE;
- break;
- }
+ PRUint32 msecs = (ticks == PR_INTERVAL_NO_TIMEOUT) ?
+ INFINITE : PR_IntervalToMilliseconds(ticks);
+
+ /*
+ * thread waiting for a cvar or a joining thread
+ */
+ rv = WaitForSingleObject(thread->md.blocked_sema, msecs);
+ switch(rv) {
+ case WAIT_OBJECT_0:
+ return PR_SUCCESS;
+ break;
+ case WAIT_TIMEOUT:
+ _PR_THREAD_LOCK(thread);
+ PR_ASSERT (thread->state != _PR_IO_WAIT);
+ if (thread->wait.cvar != NULL) {
+ PR_ASSERT(thread->state == _PR_COND_WAIT);
+ thread->wait.cvar = NULL;
+ thread->state = _PR_RUNNING;
+ _PR_THREAD_UNLOCK(thread);
+ } else {
+ /* The CVAR was notified just as the timeout
+ * occurred. This left the semaphore in the
+ * signaled state. Call WaitForSingleObject()
+ * to clear the semaphore.
+ */
+ _PR_THREAD_UNLOCK(thread);
+ rv = WaitForSingleObject(thread->md.blocked_sema, INFINITE);
+ PR_ASSERT(rv == WAIT_OBJECT_0);
+ }
+ return PR_SUCCESS;
+ break;
+ default:
+ return PR_FAILURE;
+ break;
+ }
return PR_SUCCESS;
}
@@ -487,12 +505,12 @@ _PR_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
{
DWORD rv;
- if (_native_threads_only) {
- return(_native_thread_md_wait(thread, ticks));
- }
+ if (_native_threads_only) {
+ return(_native_thread_md_wait(thread, ticks));
+ }
if ( thread->flags & _PR_GLOBAL_SCOPE ) {
PRUint32 msecs = (ticks == PR_INTERVAL_NO_TIMEOUT) ?
- INFINITE : PR_IntervalToMilliseconds(ticks);
+ INFINITE : PR_IntervalToMilliseconds(ticks);
rv = WaitForSingleObject(thread->md.blocked_sema, msecs);
switch(rv) {
case WAIT_OBJECT_0:
@@ -589,96 +607,96 @@ static PRStatus
_native_thread_io_wait(PRThread *thread, PRIntervalTime ticks)
{
DWORD rv, bytes;
-#define _NATIVE_IO_WAIT_HANDLES 2
-#define _NATIVE_WAKEUP_EVENT_INDEX 0
-#define _NATIVE_IO_EVENT_INDEX 1
+#define _NATIVE_IO_WAIT_HANDLES 2
+#define _NATIVE_WAKEUP_EVENT_INDEX 0
+#define _NATIVE_IO_EVENT_INDEX 1
- HANDLE wait_handles[_NATIVE_IO_WAIT_HANDLES];
+ HANDLE wait_handles[_NATIVE_IO_WAIT_HANDLES];
- PRUint32 msecs = (ticks == PR_INTERVAL_NO_TIMEOUT) ?
- INFINITE : PR_IntervalToMilliseconds(ticks);
+ PRUint32 msecs = (ticks == PR_INTERVAL_NO_TIMEOUT) ?
+ INFINITE : PR_IntervalToMilliseconds(ticks);
PR_ASSERT(thread->flags & _PR_GLOBAL_SCOPE);
- wait_handles[0] = thread->md.blocked_sema;
- wait_handles[1] = thread->md.thr_event;
- rv = WaitForMultipleObjects(_NATIVE_IO_WAIT_HANDLES, wait_handles,
- FALSE, msecs);
-
- switch(rv) {
- case WAIT_OBJECT_0 + _NATIVE_IO_EVENT_INDEX:
- /*
- * I/O op completed
- */
- _PR_THREAD_LOCK(thread);
- if (thread->state == _PR_IO_WAIT) {
-
- PR_ASSERT(thread->io_suspended == PR_FALSE);
- PR_ASSERT(thread->io_pending == PR_TRUE);
- thread->state = _PR_RUNNING;
- thread->io_pending = PR_FALSE;
- _PR_THREAD_UNLOCK(thread);
- } else {
- /* The IO completed just at the same time the
- * thread was interrupted. This led to us being
- * notified twice. Call WaitForSingleObject()
- * to clear the semaphore.
- */
- PR_ASSERT(thread->io_suspended == PR_TRUE);
- PR_ASSERT(thread->io_pending == PR_TRUE);
- thread->io_pending = PR_FALSE;
- _PR_THREAD_UNLOCK(thread);
- rv = WaitForSingleObject(thread->md.blocked_sema,
- INFINITE);
- PR_ASSERT(rv == WAIT_OBJECT_0);
- }
-
- rv = GetOverlappedResult((HANDLE) thread->io_fd,
- &thread->md.overlapped.overlapped, &bytes, FALSE);
-
- thread->md.blocked_io_status = rv;
- if (rv != 0) {
- thread->md.blocked_io_bytes = bytes;
- } else {
- thread->md.blocked_io_error = GetLastError();
- PR_ASSERT(ERROR_IO_PENDING != thread->md.blocked_io_error);
- }
- rv = ResetEvent(thread->md.thr_event);
- PR_ASSERT(rv != 0);
- break;
- case WAIT_OBJECT_0 + _NATIVE_WAKEUP_EVENT_INDEX:
- /*
- * I/O interrupted;
- */
+ wait_handles[0] = thread->md.blocked_sema;
+ wait_handles[1] = thread->md.thr_event;
+ rv = WaitForMultipleObjects(_NATIVE_IO_WAIT_HANDLES, wait_handles,
+ FALSE, msecs);
+
+ switch(rv) {
+ case WAIT_OBJECT_0 + _NATIVE_IO_EVENT_INDEX:
+ /*
+ * I/O op completed
+ */
+ _PR_THREAD_LOCK(thread);
+ if (thread->state == _PR_IO_WAIT) {
+
+ PR_ASSERT(thread->io_suspended == PR_FALSE);
+ PR_ASSERT(thread->io_pending == PR_TRUE);
+ thread->state = _PR_RUNNING;
+ thread->io_pending = PR_FALSE;
+ _PR_THREAD_UNLOCK(thread);
+ } else {
+ /* The IO completed just at the same time the
+ * thread was interrupted. This led to us being
+ * notified twice. Call WaitForSingleObject()
+ * to clear the semaphore.
+ */
+ PR_ASSERT(thread->io_suspended == PR_TRUE);
+ PR_ASSERT(thread->io_pending == PR_TRUE);
+ thread->io_pending = PR_FALSE;
+ _PR_THREAD_UNLOCK(thread);
+ rv = WaitForSingleObject(thread->md.blocked_sema,
+ INFINITE);
+ PR_ASSERT(rv == WAIT_OBJECT_0);
+ }
+
+ rv = GetOverlappedResult((HANDLE) thread->io_fd,
+ &thread->md.overlapped.overlapped, &bytes, FALSE);
+
+ thread->md.blocked_io_status = rv;
+ if (rv != 0) {
+ thread->md.blocked_io_bytes = bytes;
+ } else {
+ thread->md.blocked_io_error = GetLastError();
+ PR_ASSERT(ERROR_IO_PENDING != thread->md.blocked_io_error);
+ }
+ rv = ResetEvent(thread->md.thr_event);
+ PR_ASSERT(rv != 0);
+ break;
+ case WAIT_OBJECT_0 + _NATIVE_WAKEUP_EVENT_INDEX:
+ /*
+ * I/O interrupted;
+ */
#ifdef DEBUG
- _PR_THREAD_LOCK(thread);
- PR_ASSERT(thread->io_suspended == PR_TRUE);
- _PR_THREAD_UNLOCK(thread);
+ _PR_THREAD_LOCK(thread);
+ PR_ASSERT(thread->io_suspended == PR_TRUE);
+ _PR_THREAD_UNLOCK(thread);
#endif
- break;
- case WAIT_TIMEOUT:
- _PR_THREAD_LOCK(thread);
- if (thread->state == _PR_IO_WAIT) {
- thread->state = _PR_RUNNING;
- thread->io_suspended = PR_TRUE;
- _PR_THREAD_UNLOCK(thread);
- } else {
- /*
- * The thread was interrupted just as the timeout
- * occurred. This left the semaphore in the signaled
- * state. Call WaitForSingleObject() to clear the
- * semaphore.
- */
- PR_ASSERT(thread->io_suspended == PR_TRUE);
- _PR_THREAD_UNLOCK(thread);
- rv = WaitForSingleObject(thread->md.blocked_sema, INFINITE);
- PR_ASSERT(rv == WAIT_OBJECT_0);
- }
- break;
- default:
- return PR_FAILURE;
- break;
- }
+ break;
+ case WAIT_TIMEOUT:
+ _PR_THREAD_LOCK(thread);
+ if (thread->state == _PR_IO_WAIT) {
+ thread->state = _PR_RUNNING;
+ thread->io_suspended = PR_TRUE;
+ _PR_THREAD_UNLOCK(thread);
+ } else {
+ /*
+ * The thread was interrupted just as the timeout
+ * occurred. This left the semaphore in the signaled
+ * state. Call WaitForSingleObject() to clear the
+ * semaphore.
+ */
+ PR_ASSERT(thread->io_suspended == PR_TRUE);
+ _PR_THREAD_UNLOCK(thread);
+ rv = WaitForSingleObject(thread->md.blocked_sema, INFINITE);
+ PR_ASSERT(rv == WAIT_OBJECT_0);
+ }
+ break;
+ default:
+ return PR_FAILURE;
+ break;
+ }
return PR_SUCCESS;
}
@@ -689,28 +707,31 @@ _NT_IO_WAIT(PRThread *thread, PRIntervalTime timeout)
{
PRBool fWait = PR_TRUE;
- if (_native_threads_only) {
- return(_native_thread_io_wait(thread, timeout));
- }
+ if (_native_threads_only) {
+ return(_native_thread_io_wait(thread, timeout));
+ }
if (!_PR_IS_NATIVE_THREAD(thread)) {
_PR_THREAD_LOCK(thread);
- /* The IO may have already completed; if so, don't add to sleepQ,
+ /* The IO may have already completed; if so, don't add to sleepQ,
* since we are already on the runQ!
*/
if (thread->io_pending == PR_TRUE) {
_PR_SLEEPQ_LOCK(thread->cpu);
_PR_ADD_SLEEPQ(thread, timeout);
_PR_SLEEPQ_UNLOCK(thread->cpu);
- } else
+ } else {
fWait = PR_FALSE;
+ }
_PR_THREAD_UNLOCK(thread);
}
- if (fWait)
+ if (fWait) {
return _PR_MD_WAIT(thread, timeout);
- else
+ }
+ else {
return PR_SUCCESS;
+ }
}
/*
@@ -724,18 +745,18 @@ void _PR_Unblock_IO_Wait(PRThread *thr)
{
PRStatus rv;
_PRCPU *cpu = thr->cpu;
-
+
PR_ASSERT(thr->state == _PR_IO_WAIT);
- /*
- * A thread for which an I/O timed out or was interrupted cannot be
- * in an IO_WAIT state except as a result of calling PR_Close or
- * PR_NT_CancelIo for the FD. For these two cases, _PR_IO_WAIT state
- * is not interruptible
- */
- if (thr->md.interrupt_disabled == PR_TRUE) {
- _PR_THREAD_UNLOCK(thr);
- return;
- }
+ /*
+ * A thread for which an I/O timed out or was interrupted cannot be
+ * in an IO_WAIT state except as a result of calling PR_Close or
+ * PR_NT_CancelIo for the FD. For these two cases, _PR_IO_WAIT state
+ * is not interruptible
+ */
+ if (thr->md.interrupt_disabled == PR_TRUE) {
+ _PR_THREAD_UNLOCK(thr);
+ return;
+ }
thr->io_suspended = PR_TRUE;
thr->state = _PR_RUNNABLE;
@@ -745,11 +766,11 @@ void _PR_Unblock_IO_Wait(PRThread *thr)
_PR_SLEEPQ_LOCK(cpu);
_PR_DEL_SLEEPQ(thr, PR_TRUE);
_PR_SLEEPQ_UNLOCK(cpu);
- /*
- * this thread will continue to run on the same cpu until the
- * I/O is aborted by closing the FD or calling CancelIO
- */
- thr->md.thr_bound_cpu = cpu;
+ /*
+ * this thread will continue to run on the same cpu until the
+ * I/O is aborted by closing the FD or calling CancelIO
+ */
+ thr->md.thr_bound_cpu = cpu;
PR_ASSERT(!(thr->flags & _PR_IDLE_THREAD));
_PR_AddThreadToRunQ(me, thr);
@@ -773,13 +794,14 @@ _NT_ResumeIO(PRThread *thread, PRIntervalTime ticks)
}
} else {
_PR_THREAD_LOCK(thread);
- if (!thread->io_pending)
+ if (!thread->io_pending) {
fWait = PR_FALSE;
+ }
thread->io_suspended = PR_FALSE;
-
+
_PR_THREAD_UNLOCK(thread);
}
- /* We don't put ourselves back on the sleepQ yet; until we
+ /* We don't put ourselves back on the sleepQ yet; until we
* set the suspended bit to false, we can't do that. Just save
* the sleep time here, and then continue. The restarted_io handler
* will add us to the sleepQ if needed.
@@ -787,10 +809,12 @@ _NT_ResumeIO(PRThread *thread, PRIntervalTime ticks)
thread->sleep = ticks;
if (fWait) {
- if (!_PR_IS_NATIVE_THREAD(thread))
+ if (!_PR_IS_NATIVE_THREAD(thread)) {
return _PR_MD_WAIT(thread, ticks);
- else
+ }
+ else {
return _NT_IO_WAIT(thread, ticks);
+ }
}
return PR_SUCCESS;
}
@@ -800,36 +824,40 @@ _PR_MD_WAKEUP_WAITER(PRThread *thread)
{
if (thread == NULL) {
/* If thread is NULL, we aren't waking a thread, we're just poking
- * idle thread
+ * idle thread
*/
- if ( PostQueuedCompletionStatus(_pr_completion_port, 0,
- KEY_CVAR, NULL) == FALSE)
+ if ( PostQueuedCompletionStatus(_pr_completion_port, 0,
+ KEY_CVAR, NULL) == FALSE) {
return PR_FAILURE;
+ }
return PR_SUCCESS;
}
if ( _PR_IS_NATIVE_THREAD(thread) ) {
- if (ReleaseSemaphore(thread->md.blocked_sema, 1, NULL) == FALSE)
+ if (ReleaseSemaphore(thread->md.blocked_sema, 1, NULL) == FALSE) {
return PR_FAILURE;
- else
+ }
+ else {
return PR_SUCCESS;
+ }
} else {
PRThread *me = _PR_MD_CURRENT_THREAD();
/* When a Native thread has to awaken a user thread, it has to poke
* the completion port because all user threads might be idle, and
- * thus the CPUs are just waiting for a completion.
+ * thus the CPUs are just waiting for a completion.
*
- * XXXMB - can we know when we are truely idle (and not checking
+ * XXXMB - can we know when we are truely idle (and not checking
* the runq)?
*/
if ((_PR_IS_NATIVE_THREAD(me) || (thread->cpu != me->cpu)) &&
- (!thread->md.thr_bound_cpu)) {
+ (!thread->md.thr_bound_cpu)) {
/* The thread should not be in any queue */
PR_ASSERT(thread->queueCount == 0);
- if ( PostQueuedCompletionStatus(_pr_completion_port, 0,
- KEY_CVAR, &(thread->md.overlapped.overlapped)) == FALSE)
+ if ( PostQueuedCompletionStatus(_pr_completion_port, 0,
+ KEY_CVAR, &(thread->md.overlapped.overlapped)) == FALSE) {
return PR_FAILURE;
+ }
}
return PR_SUCCESS;
}
@@ -845,12 +873,12 @@ _PR_MD_INIT_IO()
err = WSAStartup( WSAVersion, &WSAData );
PR_ASSERT(0 == err);
-
- _pr_completion_port = CreateIoCompletionPort(INVALID_HANDLE_VALUE,
- NULL,
- 0,
- 0);
-
+
+ _pr_completion_port = CreateIoCompletionPort(INVALID_HANDLE_VALUE,
+ NULL,
+ 0,
+ 0);
+
_MD_NEW_LOCK(&_pr_recycle_lock);
_MD_NEW_LOCK(&_pr_ioq_lock);
@@ -860,8 +888,9 @@ _PR_MD_INIT_IO()
if (OSversion.dwMajorVersion >= 4) {
_nt_version_gets_lockfile_completion = PR_TRUE;
}
- } else
+ } else {
PR_ASSERT(0);
+ }
#ifdef _NEED_351_FILE_LOCKING_HACK
IsFileLocalInit();
@@ -882,8 +911,8 @@ _PR_MD_INIT_IO()
#endif
pt_tq.thread = PR_CreateThread(
- PR_SYSTEM_THREAD, ContinuationThread, NULL,
- PR_PRIORITY_URGENT, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_SYSTEM_THREAD, ContinuationThread, NULL,
+ PR_PRIORITY_URGENT, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
PR_ASSERT(NULL != pt_tq.thread);
@@ -892,8 +921,8 @@ _PR_MD_INIT_IO()
{
SYSTEMTIME systime;
union {
- PRTime prt;
- FILETIME ft;
+ PRTime prt;
+ FILETIME ft;
} filetime;
BOOL rv;
@@ -972,7 +1001,7 @@ _md_put_recycled_socket(SOCKET newsock, int af)
_MD_UNLOCK(&_pr_recycle_lock);
closesocket(newsock);
}
-
+
return;
}
@@ -985,17 +1014,17 @@ _md_Associate(HANDLE file)
{
HANDLE port;
- if (!_native_threads_only) {
- port = CreateIoCompletionPort((HANDLE)file,
- _pr_completion_port,
- KEY_IO,
- 0);
-
- /* XXX should map error codes on failures */
- return (port == _pr_completion_port);
- } else {
- return 1;
- }
+ if (!_native_threads_only) {
+ port = CreateIoCompletionPort((HANDLE)file,
+ _pr_completion_port,
+ KEY_IO,
+ 0);
+
+ /* XXX should map error codes on failures */
+ return (port == _pr_completion_port);
+ } else {
+ return 1;
+ }
}
/*
@@ -1026,7 +1055,7 @@ _NT_IO_ABORT(PROsfd sock)
int loop_count;
/* This is a clumsy way to abort the IO, but it is all we can do.
- * It looks a bit racy, but we handle all the cases.
+ * It looks a bit racy, but we handle all the cases.
* case 1: IO completes before calling closesocket
* case 1a: fWait is set to PR_FALSE
* This should e the most likely case. We'll properly
@@ -1139,15 +1168,16 @@ _PR_MD_connect_thread(void *cdata)
cd->status = connect(cd->osfd, cd->addr, cd->addrlen);
- if (cd->status == SOCKET_ERROR)
+ if (cd->status == SOCKET_ERROR) {
cd->error = WSAGetLastError();
+ }
return;
}
PRInt32
-_PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,
+_PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,
PRIntervalTime timeout)
{
PROsfd osfd = fd->secret->md.osfd;
@@ -1207,7 +1237,7 @@ _PR_MD_BIND(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen)
#if 0
/* Disable nagle- so far unknown if this is good or not...
*/
- rv = setsockopt(fd->secret->md.osfd,
+ rv = setsockopt(fd->secret->md.osfd,
SOL_SOCKET,
TCP_NODELAY,
(const char *)&one,
@@ -1221,19 +1251,19 @@ _PR_MD_BIND(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen)
void _PR_MD_UPDATE_ACCEPT_CONTEXT(PROsfd accept_sock, PROsfd listen_sock)
{
/* Sockets accept()'d with AcceptEx need to call this setsockopt before
- * calling anything other than ReadFile(), WriteFile(), send(), recv(),
- * Transmitfile(), and closesocket(). In order to call any other
+ * calling anything other than ReadFile(), WriteFile(), send(), recv(),
+ * Transmitfile(), and closesocket(). In order to call any other
* winsock functions, we have to make this setsockopt call.
*
* XXXMB - For the server, we *NEVER* need this in
* the "normal" code path. But now we have to call it. This is a waste
- * of a system call. We'd like to only call it before calling the
+ * of a system call. We'd like to only call it before calling the
* obscure socket calls, but since we don't know at that point what the
* original socket was (or even if it is still alive) we can't do it
- * at that point...
+ * at that point...
*/
- setsockopt((SOCKET)accept_sock,
- SOL_SOCKET,
+ setsockopt((SOCKET)accept_sock,
+ SOL_SOCKET,
SO_UPDATE_ACCEPT_CONTEXT,
(char *)&listen_sock,
sizeof(listen_sock));
@@ -1243,8 +1273,8 @@ void _PR_MD_UPDATE_ACCEPT_CONTEXT(PROsfd accept_sock, PROsfd listen_sock)
#define INET_ADDR_PADDED (sizeof(PRNetAddr) + 16)
PROsfd
_PR_MD_FAST_ACCEPT(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
- PRIntervalTime timeout, PRBool fast,
- _PR_AcceptTimeoutCallback callback, void *callbackArg)
+ PRIntervalTime timeout, PRBool fast,
+ _PR_AcceptTimeoutCallback callback, void *callbackArg)
{
PROsfd osfd = fd->secret->md.osfd;
PRThread *me = _PR_MD_CURRENT_THREAD();
@@ -1296,21 +1326,23 @@ _PR_MD_FAST_ACCEPT(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
}
accept_sock = _md_get_recycled_socket(fd->secret->af);
- if (accept_sock == INVALID_SOCKET)
+ if (accept_sock == INVALID_SOCKET) {
return -1;
+ }
memset(&(me->md.overlapped.overlapped), 0, sizeof(OVERLAPPED));
- if (_native_threads_only)
- me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ if (_native_threads_only) {
+ me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ }
_PR_THREAD_LOCK(me);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- closesocket(accept_sock);
- return -1;
- }
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ closesocket(accept_sock);
+ return -1;
+ }
me->io_pending = PR_TRUE;
me->state = _PR_IO_WAIT;
_PR_THREAD_UNLOCK(me);
@@ -1327,19 +1359,19 @@ _PR_MD_FAST_ACCEPT(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
if ( (rv == 0) && ((err = WSAGetLastError()) != ERROR_IO_PENDING)) {
/* Argh! The IO failed */
- closesocket(accept_sock);
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
- _PR_THREAD_UNLOCK(me);
-
- _PR_MD_MAP_ACCEPTEX_ERROR(err);
+ closesocket(accept_sock);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
+ _PR_THREAD_UNLOCK(me);
+
+ _PR_MD_MAP_ACCEPTEX_ERROR(err);
return -1;
}
@@ -1365,27 +1397,29 @@ _PR_MD_FAST_ACCEPT(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
}
if (me->md.blocked_io_status == 0) {
- closesocket(accept_sock);
- _PR_MD_MAP_ACCEPTEX_ERROR(me->md.blocked_io_error);
+ closesocket(accept_sock);
+ _PR_MD_MAP_ACCEPTEX_ERROR(me->md.blocked_io_error);
return -1;
}
- if (!fast)
+ if (!fast) {
_PR_MD_UPDATE_ACCEPT_CONTEXT((SOCKET)accept_sock, (SOCKET)osfd);
+ }
/* IO is done */
GetAcceptExSockaddrs(
- me->md.acceptex_buf,
- 0,
- INET_ADDR_PADDED,
- INET_ADDR_PADDED,
- (LPSOCKADDR *)&(Laddr),
- &llen,
- (LPSOCKADDR *)&(Raddr),
- (unsigned int *)rlen);
-
- if (raddr != NULL)
+ me->md.acceptex_buf,
+ 0,
+ INET_ADDR_PADDED,
+ INET_ADDR_PADDED,
+ (LPSOCKADDR *)&(Laddr),
+ &llen,
+ (LPSOCKADDR *)&(Raddr),
+ (unsigned int *)rlen);
+
+ if (raddr != NULL) {
memcpy((char *)raddr, (char *)&Raddr->inet, *rlen);
+ }
PR_ASSERT(me->io_pending == PR_FALSE);
@@ -1393,10 +1427,10 @@ _PR_MD_FAST_ACCEPT(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
}
PRInt32
-_PR_MD_FAST_ACCEPT_READ(PRFileDesc *sd, PROsfd *newSock, PRNetAddr **raddr,
- void *buf, PRInt32 amount, PRIntervalTime timeout,
- PRBool fast, _PR_AcceptTimeoutCallback callback,
- void *callbackArg)
+_PR_MD_FAST_ACCEPT_READ(PRFileDesc *sd, PROsfd *newSock, PRNetAddr **raddr,
+ void *buf, PRInt32 amount, PRIntervalTime timeout,
+ PRBool fast, _PR_AcceptTimeoutCallback callback,
+ void *callbackArg)
{
PROsfd sock = sd->secret->md.osfd;
PRThread *me = _PR_MD_CURRENT_THREAD();
@@ -1419,21 +1453,23 @@ _PR_MD_FAST_ACCEPT_READ(PRFileDesc *sd, PROsfd *newSock, PRNetAddr **raddr,
}
*newSock = _md_get_recycled_socket(sd->secret->af);
- if (*newSock == INVALID_SOCKET)
+ if (*newSock == INVALID_SOCKET) {
return -1;
+ }
memset(&(me->md.overlapped.overlapped), 0, sizeof(OVERLAPPED));
- if (_native_threads_only)
- me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ if (_native_threads_only) {
+ me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ }
_PR_THREAD_LOCK(me);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- closesocket(*newSock);
- return -1;
- }
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ closesocket(*newSock);
+ return -1;
+ }
me->io_pending = PR_TRUE;
me->state = _PR_IO_WAIT;
_PR_THREAD_UNLOCK(me);
@@ -1449,19 +1485,19 @@ _PR_MD_FAST_ACCEPT_READ(PRFileDesc *sd, PROsfd *newSock, PRNetAddr **raddr,
&(me->md.overlapped.overlapped));
if ( (rv == 0) && ((err = GetLastError()) != ERROR_IO_PENDING)) {
- closesocket(*newSock);
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
- _PR_THREAD_UNLOCK(me);
-
- _PR_MD_MAP_ACCEPTEX_ERROR(err);
+ closesocket(*newSock);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
+ _PR_THREAD_UNLOCK(me);
+
+ _PR_MD_MAP_ACCEPTEX_ERROR(err);
return -1;
}
@@ -1481,7 +1517,7 @@ retry:
PR_ASSERT(timeout != PR_INTERVAL_NO_TIMEOUT);
- err = getsockopt(*newSock,
+ err = getsockopt(*newSock,
SOL_SOCKET,
SO_CONNECT_TIME,
(char *)&seconds,
@@ -1489,14 +1525,17 @@ retry:
if ( err == NO_ERROR ) {
PRIntervalTime elapsed = PR_SecondsToInterval(seconds);
- if (seconds == 0xffffffff)
+ if (seconds == 0xffffffff) {
isConnected = PR_FALSE;
- else
+ }
+ else {
isConnected = PR_TRUE;
+ }
if (!isConnected) {
- if (madeCallback == PR_FALSE && callback)
+ if (madeCallback == PR_FALSE && callback) {
callback(callbackArg);
+ }
madeCallback = PR_TRUE;
me->state = _PR_IO_WAIT;
if (_NT_ResumeIO(me, timeout) == PR_FAILURE) {
@@ -1527,9 +1566,9 @@ retry:
PR_ASSERT(me->io_pending == PR_FALSE);
PR_ASSERT(me->io_suspended == PR_FALSE);
PR_ASSERT(me->md.thr_bound_cpu == NULL);
- /* If the IO is still suspended, it means we didn't get any
+ /* If the IO is still suspended, it means we didn't get any
* completion from NT_IO_WAIT. This is not disasterous, I hope,
- * but it may mean we still have an IO outstanding... Try to
+ * but it may mean we still have an IO outstanding... Try to
* recover by just allowing ourselves to continue.
*/
me->io_suspended = PR_FALSE;
@@ -1549,31 +1588,32 @@ retry:
PR_ASSERT(me->md.thr_bound_cpu == NULL);
if (me->md.blocked_io_status == 0) {
- _PR_MD_MAP_ACCEPTEX_ERROR(me->md.blocked_io_error);
+ _PR_MD_MAP_ACCEPTEX_ERROR(me->md.blocked_io_error);
closesocket(*newSock);
return -1;
}
- if (!fast)
+ if (!fast) {
_PR_MD_UPDATE_ACCEPT_CONTEXT((SOCKET)*newSock, (SOCKET)sock);
+ }
/* IO is done */
GetAcceptExSockaddrs(
- buf,
- amount,
- INET_ADDR_PADDED,
- INET_ADDR_PADDED,
- (LPSOCKADDR *)&(Laddr),
- &llen,
- (LPSOCKADDR *)(raddr),
- (unsigned int *)&rlen);
+ buf,
+ amount,
+ INET_ADDR_PADDED,
+ INET_ADDR_PADDED,
+ (LPSOCKADDR *)&(Laddr),
+ &llen,
+ (LPSOCKADDR *)(raddr),
+ (unsigned int *)&rlen);
return me->md.blocked_io_bytes;
}
PRInt32
_PR_MD_SENDFILE(PRFileDesc *sock, PRSendFileData *sfd,
- PRInt32 flags, PRIntervalTime timeout)
+ PRInt32 flags, PRIntervalTime timeout)
{
PRThread *me = _PR_MD_CURRENT_THREAD();
PRInt32 tflags;
@@ -1603,20 +1643,22 @@ _PR_MD_SENDFILE(PRFileDesc *sock, PRSendFileData *sfd,
memset(&(me->md.overlapped.overlapped), 0, sizeof(OVERLAPPED));
me->md.overlapped.overlapped.Offset = sfd->file_offset;
- if (_native_threads_only)
- me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ if (_native_threads_only) {
+ me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ }
tflags = 0;
- if (flags & PR_TRANSMITFILE_CLOSE_SOCKET)
+ if (flags & PR_TRANSMITFILE_CLOSE_SOCKET) {
tflags = TF_DISCONNECT | TF_REUSE_SOCKET;
+ }
_PR_THREAD_LOCK(me);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
me->io_pending = PR_TRUE;
me->state = _PR_IO_WAIT;
_PR_THREAD_UNLOCK(me);
@@ -1630,18 +1672,18 @@ _PR_MD_SENDFILE(PRFileDesc *sock, PRSendFileData *sfd,
(TRANSMIT_FILE_BUFFERS *)me->md.xmit_bufs,
(DWORD)tflags);
if ( (rv == 0) && ((err = GetLastError()) != ERROR_IO_PENDING) ) {
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
- _PR_THREAD_UNLOCK(me);
-
- _PR_MD_MAP_TRANSMITFILE_ERROR(err);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
+ _PR_THREAD_UNLOCK(me);
+
+ _PR_MD_MAP_TRANSMITFILE_ERROR(err);
return -1;
}
@@ -1663,7 +1705,7 @@ _PR_MD_SENDFILE(PRFileDesc *sock, PRSendFileData *sfd,
}
if (me->md.blocked_io_status == 0) {
- _PR_MD_MAP_TRANSMITFILE_ERROR(me->md.blocked_io_error);
+ _PR_MD_MAP_TRANSMITFILE_ERROR(me->md.blocked_io_error);
return -1;
}
@@ -1677,7 +1719,7 @@ _PR_MD_SENDFILE(PRFileDesc *sock, PRSendFileData *sfd,
}
PRInt32
-_PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
+_PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
PRIntervalTime timeout)
{
PROsfd osfd = fd->secret->md.osfd;
@@ -1706,41 +1748,43 @@ _PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
}
memset(&(me->md.overlapped.overlapped), 0, sizeof(OVERLAPPED));
- if (_native_threads_only)
- me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ if (_native_threads_only) {
+ me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ }
_PR_THREAD_LOCK(me);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
me->io_pending = PR_TRUE;
me->state = _PR_IO_WAIT;
_PR_THREAD_UNLOCK(me);
me->io_fd = osfd;
rv = ReadFile((HANDLE)osfd,
- buf,
+ buf,
amount,
&bytes,
&(me->md.overlapped.overlapped));
if ( (rv == 0) && (GetLastError() != ERROR_IO_PENDING) ) {
- _PR_THREAD_LOCK(me);
+ _PR_THREAD_LOCK(me);
me->io_pending = PR_FALSE;
me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
- _PR_THREAD_UNLOCK(me);
-
- if ((err = GetLastError()) == ERROR_HANDLE_EOF)
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
+ _PR_THREAD_UNLOCK(me);
+
+ if ((err = GetLastError()) == ERROR_HANDLE_EOF) {
return 0;
- _PR_MD_MAP_READ_ERROR(err);
+ }
+ _PR_MD_MAP_READ_ERROR(err);
return -1;
}
@@ -1764,9 +1808,10 @@ _PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
}
if (me->md.blocked_io_status == 0) {
- if (me->md.blocked_io_error == ERROR_HANDLE_EOF)
+ if (me->md.blocked_io_error == ERROR_HANDLE_EOF) {
return 0;
- _PR_MD_MAP_READ_ERROR(me->md.blocked_io_error);
+ }
+ _PR_MD_MAP_READ_ERROR(me->md.blocked_io_error);
return -1;
}
@@ -1805,39 +1850,40 @@ _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
}
memset(&(me->md.overlapped.overlapped), 0, sizeof(OVERLAPPED));
- if (_native_threads_only)
- me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ if (_native_threads_only) {
+ me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ }
_PR_THREAD_LOCK(me);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
me->io_pending = PR_TRUE;
me->state = _PR_IO_WAIT;
_PR_THREAD_UNLOCK(me);
me->io_fd = osfd;
rv = WriteFile((HANDLE)osfd,
- buf,
+ buf,
amount,
&bytes,
&(me->md.overlapped.overlapped));
if ( (rv == 0) && ((err = GetLastError()) != ERROR_IO_PENDING) ) {
- _PR_THREAD_LOCK(me);
+ _PR_THREAD_LOCK(me);
me->io_pending = PR_FALSE;
me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
- _PR_THREAD_UNLOCK(me);
-
- _PR_MD_MAP_WRITE_ERROR(err);
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
+ _PR_THREAD_UNLOCK(me);
+
+ _PR_MD_MAP_WRITE_ERROR(err);
return -1;
}
@@ -1861,7 +1907,7 @@ _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
}
if (me->md.blocked_io_status == 0) {
- _PR_MD_MAP_WRITE_ERROR(me->md.blocked_io_error);
+ _PR_MD_MAP_WRITE_ERROR(me->md.blocked_io_error);
return -1;
}
@@ -1882,10 +1928,12 @@ _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
PR_ASSERT(0 != rv);
fd->secret->md.io_model_committed = PR_TRUE;
}
- if (_NT_USE_NB_IO(fd))
+ if (_NT_USE_NB_IO(fd)) {
return _nt_nonblock_sendto(fd, buf, amount, (struct sockaddr *)addr, addrlen, timeout);
- else
+ }
+ else {
return pt_SendTo(osfd, buf, amount, flags, addr, addrlen, timeout);
+ }
}
PRInt32
@@ -1900,10 +1948,12 @@ _PR_MD_RECVFROM(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
PR_ASSERT(0 != rv);
fd->secret->md.io_model_committed = PR_TRUE;
}
- if (_NT_USE_NB_IO(fd))
+ if (_NT_USE_NB_IO(fd)) {
return _nt_nonblock_recvfrom(fd, buf, amount, (struct sockaddr *)addr, addrlen, timeout);
- else
+ }
+ else {
return pt_RecvFrom(osfd, buf, amount, flags, addr, addrlen, timeout);
+ }
}
/* XXXMB - for now this is a sockets call only */
@@ -1926,12 +1976,14 @@ _PR_MD_WRITEV(PRFileDesc *fd, const PRIOVec *iov, PRInt32 iov_size, PRIntervalTi
for (index=0; index<iov_size; index++) {
rv = _PR_MD_SEND(fd, iov[index].iov_base, iov[index].iov_len, 0,
- timeout);
- if (rv > 0)
+ timeout);
+ if (rv > 0) {
sent += rv;
+ }
if ( rv != iov[index].iov_len ) {
- if (sent <= 0)
+ if (sent <= 0) {
return -1;
+ }
return -1;
}
}
@@ -1945,9 +1997,10 @@ _PR_MD_LISTEN(PRFileDesc *fd, PRIntn backlog)
PRInt32 rv;
rv = listen(fd->secret->md.osfd, backlog);
- if (rv < 0)
- _PR_MD_MAP_LISTEN_ERROR(WSAGetLastError());
- return(rv);
+ if (rv < 0) {
+ _PR_MD_MAP_LISTEN_ERROR(WSAGetLastError());
+ }
+ return(rv);
}
PRInt32
@@ -1956,9 +2009,10 @@ _PR_MD_SHUTDOWN(PRFileDesc *fd, PRIntn how)
PRInt32 rv;
rv = shutdown(fd->secret->md.osfd, how);
- if (rv < 0)
- _PR_MD_MAP_SHUTDOWN_ERROR(WSAGetLastError());
- return(rv);
+ if (rv < 0) {
+ _PR_MD_MAP_SHUTDOWN_ERROR(WSAGetLastError());
+ }
+ return(rv);
}
PRStatus
@@ -1967,12 +2021,13 @@ _PR_MD_GETSOCKNAME(PRFileDesc *fd, PRNetAddr *addr, PRUint32 *len)
PRInt32 rv;
rv = getsockname((SOCKET)fd->secret->md.osfd, (struct sockaddr *)addr, len);
- if (rv==0)
- return PR_SUCCESS;
- else {
- _PR_MD_MAP_GETSOCKNAME_ERROR(WSAGetLastError());
- return PR_FAILURE;
- }
+ if (rv==0) {
+ return PR_SUCCESS;
+ }
+ else {
+ _PR_MD_MAP_GETSOCKNAME_ERROR(WSAGetLastError());
+ return PR_FAILURE;
+ }
}
PRStatus
@@ -1996,7 +2051,7 @@ _PR_MD_GETPEERNAME(PRFileDesc *fd, PRNetAddr *addr, PRUint32 *len)
* Determine if the socket is connected.
*/
- rv = getsockopt(fd->secret->md.osfd,
+ rv = getsockopt(fd->secret->md.osfd,
SOL_SOCKET,
SO_CONNECT_TIME,
(char *) &seconds,
@@ -2013,7 +2068,7 @@ _PR_MD_GETPEERNAME(PRFileDesc *fd, PRNetAddr *addr, PRUint32 *len)
_PR_MD_MAP_GETSOCKOPT_ERROR(WSAGetLastError());
return PR_FAILURE;
}
- } else {
+ } else {
rv = getpeername((SOCKET)fd->secret->md.osfd,
(struct sockaddr *) addr, len);
if (rv == 0) {
@@ -2031,12 +2086,13 @@ _PR_MD_GETSOCKOPT(PRFileDesc *fd, PRInt32 level, PRInt32 optname, char* optval,
PRInt32 rv;
rv = getsockopt((SOCKET)fd->secret->md.osfd, level, optname, optval, optlen);
- if (rv==0)
- return PR_SUCCESS;
- else {
- _PR_MD_MAP_GETSOCKOPT_ERROR(WSAGetLastError());
- return PR_FAILURE;
- }
+ if (rv==0) {
+ return PR_SUCCESS;
+ }
+ else {
+ _PR_MD_MAP_GETSOCKOPT_ERROR(WSAGetLastError());
+ return PR_FAILURE;
+ }
}
PRStatus
@@ -2045,12 +2101,13 @@ _PR_MD_SETSOCKOPT(PRFileDesc *fd, PRInt32 level, PRInt32 optname, const char* op
PRInt32 rv;
rv = setsockopt((SOCKET)fd->secret->md.osfd, level, optname, optval, optlen);
- if (rv==0)
- return PR_SUCCESS;
- else {
- _PR_MD_MAP_SETSOCKOPT_ERROR(WSAGetLastError());
- return PR_FAILURE;
- }
+ if (rv==0) {
+ return PR_SUCCESS;
+ }
+ else {
+ _PR_MD_MAP_SETSOCKOPT_ERROR(WSAGetLastError());
+ return PR_FAILURE;
+ }
}
/* --- FILE IO ----------------------------------------------------------- */
@@ -2062,27 +2119,39 @@ _PR_MD_OPEN(const char *name, PRIntn osflags, PRIntn mode)
PRInt32 access = 0;
PRInt32 flags = 0;
PRInt32 flag6 = 0;
-
- if (osflags & PR_SYNC) flag6 = FILE_FLAG_WRITE_THROUGH;
-
- if (osflags & PR_RDONLY || osflags & PR_RDWR) access |= GENERIC_READ;
- if (osflags & PR_WRONLY || osflags & PR_RDWR) access |= GENERIC_WRITE;
- if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL )
+ if (osflags & PR_SYNC) {
+ flag6 = FILE_FLAG_WRITE_THROUGH;
+ }
+
+ if (osflags & PR_RDONLY || osflags & PR_RDWR) {
+ access |= GENERIC_READ;
+ }
+ if (osflags & PR_WRONLY || osflags & PR_RDWR) {
+ access |= GENERIC_WRITE;
+ }
+
+ if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL ) {
flags = CREATE_NEW;
- else if (osflags & PR_CREATE_FILE)
+ }
+ else if (osflags & PR_CREATE_FILE) {
flags = (0 != (osflags & PR_TRUNCATE)) ? CREATE_ALWAYS : OPEN_ALWAYS;
- else if (osflags & PR_TRUNCATE) flags = TRUNCATE_EXISTING;
- else flags = OPEN_EXISTING;
+ }
+ else if (osflags & PR_TRUNCATE) {
+ flags = TRUNCATE_EXISTING;
+ }
+ else {
+ flags = OPEN_EXISTING;
+ }
flag6 |= FILE_FLAG_OVERLAPPED;
- file = CreateFile(name,
- access,
+ file = CreateFile(name,
+ access,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
- flags,
+ flags,
flag6,
NULL);
if (file == INVALID_HANDLE_VALUE) {
@@ -2113,35 +2182,47 @@ _PR_MD_OPEN_FILE(const char *name, PRIntn osflags, PRIntn mode)
PSECURITY_DESCRIPTOR pSD = NULL;
PACL pACL = NULL;
- if (osflags & PR_SYNC) flag6 = FILE_FLAG_WRITE_THROUGH;
-
- if (osflags & PR_RDONLY || osflags & PR_RDWR) access |= GENERIC_READ;
- if (osflags & PR_WRONLY || osflags & PR_RDWR) access |= GENERIC_WRITE;
+ if (osflags & PR_SYNC) {
+ flag6 = FILE_FLAG_WRITE_THROUGH;
+ }
+
+ if (osflags & PR_RDONLY || osflags & PR_RDWR) {
+ access |= GENERIC_READ;
+ }
+ if (osflags & PR_WRONLY || osflags & PR_RDWR) {
+ access |= GENERIC_WRITE;
+ }
- if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL )
+ if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL ) {
flags = CREATE_NEW;
- else if (osflags & PR_CREATE_FILE)
+ }
+ else if (osflags & PR_CREATE_FILE) {
flags = (0 != (osflags & PR_TRUNCATE)) ? CREATE_ALWAYS : OPEN_ALWAYS;
- else if (osflags & PR_TRUNCATE) flags = TRUNCATE_EXISTING;
- else flags = OPEN_EXISTING;
+ }
+ else if (osflags & PR_TRUNCATE) {
+ flags = TRUNCATE_EXISTING;
+ }
+ else {
+ flags = OPEN_EXISTING;
+ }
flag6 |= FILE_FLAG_OVERLAPPED;
if (osflags & PR_CREATE_FILE) {
if (_PR_NT_MakeSecurityDescriptorACL(mode, fileAccessTable,
- &pSD, &pACL) == PR_SUCCESS) {
+ &pSD, &pACL) == PR_SUCCESS) {
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = FALSE;
lpSA = &sa;
}
}
- file = CreateFile(name,
- access,
+ file = CreateFile(name,
+ access,
FILE_SHARE_READ|FILE_SHARE_WRITE,
lpSA,
- flags,
+ flags,
flag6,
NULL);
if (lpSA != NULL) {
@@ -2163,7 +2244,7 @@ _PR_MD_OPEN_FILE(const char *name, PRIntn osflags, PRIntn mode)
return (PROsfd)file;
}
-PRInt32
+PRInt32
_PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
{
PROsfd f = fd->secret->md.osfd;
@@ -2186,10 +2267,10 @@ _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
PR_ASSERT((me->md.overlapped.overlapped.Offset != 0xffffffff) || (GetLastError() == NO_ERROR));
if (fd->secret->inheritable == _PR_TRI_TRUE) {
- rv = ReadFile((HANDLE)f,
- (LPVOID)buf,
- len,
- &bytes,
+ rv = ReadFile((HANDLE)f,
+ (LPVOID)buf,
+ len,
+ &bytes,
&me->md.overlapped.overlapped);
if (rv != 0) {
loOffset = SetFilePointer((HANDLE)f, bytes, &hiOffset, FILE_CURRENT);
@@ -2199,7 +2280,7 @@ _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
err = GetLastError();
if (err == ERROR_IO_PENDING) {
rv = GetOverlappedResult((HANDLE)f,
- &me->md.overlapped.overlapped, &bytes, TRUE);
+ &me->md.overlapped.overlapped, &bytes, TRUE);
if (rv != 0) {
loOffset = SetFilePointer((HANDLE)f, bytes, &hiOffset, FILE_CURRENT);
PR_ASSERT((loOffset != 0xffffffff) || (GetLastError() == NO_ERROR));
@@ -2220,37 +2301,38 @@ _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
fd->secret->md.io_model_committed = PR_TRUE;
}
- if (_native_threads_only)
- me->md.overlapped.overlapped.hEvent = me->md.thr_event;
-
- _PR_THREAD_LOCK(me);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
- me->io_pending = PR_TRUE;
- me->state = _PR_IO_WAIT;
- _PR_THREAD_UNLOCK(me);
- me->io_fd = f;
-
- rv = ReadFile((HANDLE)f,
- (LPVOID)buf,
- len,
- &bytes,
+ if (_native_threads_only) {
+ me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ }
+
+ _PR_THREAD_LOCK(me);
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
+ me->io_pending = PR_TRUE;
+ me->state = _PR_IO_WAIT;
+ _PR_THREAD_UNLOCK(me);
+ me->io_fd = f;
+
+ rv = ReadFile((HANDLE)f,
+ (LPVOID)buf,
+ len,
+ &bytes,
&me->md.overlapped.overlapped);
if ( (rv == 0) && ((err = GetLastError()) != ERROR_IO_PENDING) ) {
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
- _PR_THREAD_UNLOCK(me);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
+ _PR_THREAD_UNLOCK(me);
if (err == ERROR_HANDLE_EOF) {
return 0;
@@ -2287,7 +2369,7 @@ _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
}
SetFilePointer((HANDLE)f, me->md.blocked_io_bytes, 0, FILE_CURRENT);
-
+
PR_ASSERT(me->io_pending == PR_FALSE);
return me->md.blocked_io_bytes;
@@ -2304,7 +2386,7 @@ _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
/* ERROR_HANDLE_EOF can only be returned by async io */
PR_ASSERT(err != ERROR_HANDLE_EOF);
if (err == ERROR_BROKEN_PIPE) {
- /* The write end of the pipe has been closed. */
+ /* The write end of the pipe has been closed. */
return 0;
}
_PR_MD_MAP_READ_ERROR(err);
@@ -2338,11 +2420,11 @@ _PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 len)
PR_ASSERT((me->md.overlapped.overlapped.Offset != 0xffffffff) || (GetLastError() == NO_ERROR));
if (fd->secret->inheritable == _PR_TRI_TRUE) {
- rv = WriteFile((HANDLE)f,
- (LPVOID)buf,
- len,
- &bytes,
- &me->md.overlapped.overlapped);
+ rv = WriteFile((HANDLE)f,
+ (LPVOID)buf,
+ len,
+ &bytes,
+ &me->md.overlapped.overlapped);
if (rv != 0) {
loOffset = SetFilePointer((HANDLE)f, bytes, &hiOffset, FILE_CURRENT);
PR_ASSERT((loOffset != 0xffffffff) || (GetLastError() == NO_ERROR));
@@ -2351,7 +2433,7 @@ _PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 len)
err = GetLastError();
if (err == ERROR_IO_PENDING) {
rv = GetOverlappedResult((HANDLE)f,
- &me->md.overlapped.overlapped, &bytes, TRUE);
+ &me->md.overlapped.overlapped, &bytes, TRUE);
if (rv != 0) {
loOffset = SetFilePointer((HANDLE)f, bytes, &hiOffset, FILE_CURRENT);
PR_ASSERT((loOffset != 0xffffffff) || (GetLastError() == NO_ERROR));
@@ -2367,37 +2449,38 @@ _PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 len)
PR_ASSERT(rv != 0);
fd->secret->md.io_model_committed = PR_TRUE;
}
- if (_native_threads_only)
- me->md.overlapped.overlapped.hEvent = me->md.thr_event;
-
- _PR_THREAD_LOCK(me);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
- me->io_pending = PR_TRUE;
- me->state = _PR_IO_WAIT;
- _PR_THREAD_UNLOCK(me);
- me->io_fd = f;
-
- rv = WriteFile((HANDLE)f,
- buf,
- len,
- &bytes,
+ if (_native_threads_only) {
+ me->md.overlapped.overlapped.hEvent = me->md.thr_event;
+ }
+
+ _PR_THREAD_LOCK(me);
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
+ me->io_pending = PR_TRUE;
+ me->state = _PR_IO_WAIT;
+ _PR_THREAD_UNLOCK(me);
+ me->io_fd = f;
+
+ rv = WriteFile((HANDLE)f,
+ buf,
+ len,
+ &bytes,
&(me->md.overlapped.overlapped));
if ( (rv == 0) && ((err = GetLastError()) != ERROR_IO_PENDING) ) {
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
- _PR_THREAD_UNLOCK(me);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
+ _PR_THREAD_UNLOCK(me);
_PR_MD_MAP_WRITE_ERROR(err);
return -1;
@@ -2439,7 +2522,7 @@ _PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 len)
offset.QuadPart += me->md.blocked_io_bytes;
SetFilePointer((HANDLE)f, offset.LowPart, &offset.HighPart, FILE_BEGIN);
-
+
PR_ASSERT(me->io_pending == PR_FALSE);
return me->md.blocked_io_bytes;
@@ -2464,7 +2547,7 @@ _PR_MD_SOCKETAVAILABLE(PRFileDesc *fd)
PRInt32 result;
if (ioctlsocket(fd->secret->md.osfd, FIONREAD, &result) < 0) {
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, WSAGetLastError());
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, WSAGetLastError());
return -1;
}
return result;
@@ -2473,10 +2556,12 @@ _PR_MD_SOCKETAVAILABLE(PRFileDesc *fd)
PRInt32
_PR_MD_PIPEAVAILABLE(PRFileDesc *fd)
{
- if (NULL == fd)
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
- else
- PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+ if (NULL == fd) {
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
+ }
+ else {
+ PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+ }
return -1;
}
@@ -2537,7 +2622,7 @@ _PR_MD_LSEEK64(PRFileDesc *fd, PROffset64 offset, PRSeekWhence whence)
li.QuadPart = offset;
li.LowPart = SetFilePointer((HANDLE)fd->secret->md.osfd,
- li.LowPart, &li.HighPart, moveMethod);
+ li.LowPart, &li.HighPart, moveMethod);
if (0xffffffff == li.LowPart && (err = GetLastError()) != NO_ERROR) {
_PR_MD_MAP_LSEEK_ERROR(err);
@@ -2558,10 +2643,10 @@ _PR_MD_FSYNC(PRFileDesc *fd)
/*
* From the documentation:
*
- * On Windows NT, the function FlushFileBuffers fails if hFile
- * is a handle to console output. That is because console
- * output is not buffered. The function returns FALSE, and
- * GetLastError returns ERROR_INVALID_HANDLE.
+ * On Windows NT, the function FlushFileBuffers fails if hFile
+ * is a handle to console output. That is because console
+ * output is not buffered. The function returns FALSE, and
+ * GetLastError returns ERROR_INVALID_HANDLE.
*
* On the other hand, on Win95, it returns without error. I cannot
* assume that 0, 1, and 2 are console, because if someone closes
@@ -2575,12 +2660,12 @@ _PR_MD_FSYNC(PRFileDesc *fd)
BOOL ok = FlushFileBuffers((HANDLE)fd->secret->md.osfd);
if (!ok) {
- DWORD err = GetLastError();
+ DWORD err = GetLastError();
- if (err != ERROR_ACCESS_DENIED) { /* from winerror.h */
- _PR_MD_MAP_FSYNC_ERROR(err);
- return -1;
- }
+ if (err != ERROR_ACCESS_DENIED) { /* from winerror.h */
+ _PR_MD_MAP_FSYNC_ERROR(err);
+ return -1;
+ }
}
return 0;
}
@@ -2593,12 +2678,14 @@ _PR_MD_CLOSE(PROsfd osfd, PRBool socket)
if (socket) {
rv = closesocket((SOCKET)osfd);
- if (rv < 0)
+ if (rv < 0) {
_PR_MD_MAP_CLOSE_ERROR(WSAGetLastError());
+ }
} else {
rv = CloseHandle((HANDLE)osfd)?0:-1;
- if (rv < 0)
+ if (rv < 0) {
_PR_MD_MAP_CLOSE_ERROR(GetLastError());
+ }
}
if (rv == 0 && me->io_suspended) {
@@ -2608,7 +2695,7 @@ _PR_MD_CLOSE(PROsfd osfd, PRBool socket)
_PR_THREAD_LOCK(me);
me->state = _PR_IO_WAIT;
/* The IO could have completed on another thread just after
- * calling closesocket while the io_suspended flag was true.
+ * calling closesocket while the io_suspended flag was true.
* So we now grab the lock to do a safe check on io_pending to
* see if we need to wait or not.
*/
@@ -2617,8 +2704,9 @@ _PR_MD_CLOSE(PROsfd osfd, PRBool socket)
me->md.interrupt_disabled = PR_TRUE;
_PR_THREAD_UNLOCK(me);
- if (fWait)
+ if (fWait) {
_NT_IO_WAIT(me, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_ASSERT(me->io_suspended == PR_FALSE);
PR_ASSERT(me->io_pending == PR_FALSE);
/*
@@ -2647,15 +2735,15 @@ _PR_MD_SET_FD_INHERITABLE(PRFileDesc *fd, PRBool inheritable)
return PR_FAILURE;
}
rv = SetHandleInformation(
- (HANDLE)fd->secret->md.osfd,
- HANDLE_FLAG_INHERIT,
- inheritable ? HANDLE_FLAG_INHERIT : 0);
+ (HANDLE)fd->secret->md.osfd,
+ HANDLE_FLAG_INHERIT,
+ inheritable ? HANDLE_FLAG_INHERIT : 0);
if (0 == rv) {
_PR_MD_MAP_DEFAULT_ERROR(GetLastError());
return PR_FAILURE;
}
return PR_SUCCESS;
-}
+}
void
_PR_MD_INIT_FD_INHERITABLE(PRFileDesc *fd, PRBool imported)
@@ -2750,7 +2838,7 @@ _PR_MD_OPEN_DIR(_MDDir *d, const char *name)
d->d_hdl = FindFirstFile( filename, &(d->d_entry) );
if ( d->d_hdl == INVALID_HANDLE_VALUE ) {
- _PR_MD_MAP_OPENDIR_ERROR(GetLastError());
+ _PR_MD_MAP_OPENDIR_ERROR(GetLastError());
return PR_FAILURE;
}
d->firstEntry = PR_TRUE;
@@ -2778,21 +2866,24 @@ _PR_MD_READ_DIR(_MDDir *d, PRIntn flags)
}
fileName = GetFileFromDIR(d);
if ( (flags & PR_SKIP_DOT) &&
- (fileName[0] == '.') && (fileName[1] == '\0'))
- continue;
+ (fileName[0] == '.') && (fileName[1] == '\0')) {
+ continue;
+ }
if ( (flags & PR_SKIP_DOT_DOT) &&
(fileName[0] == '.') && (fileName[1] == '.') &&
- (fileName[2] == '\0'))
- continue;
- if ( (flags & PR_SKIP_HIDDEN) && FileIsHidden(d))
- continue;
+ (fileName[2] == '\0')) {
+ continue;
+ }
+ if ( (flags & PR_SKIP_HIDDEN) && FileIsHidden(d)) {
+ continue;
+ }
return fileName;
}
- err = GetLastError();
- PR_ASSERT(NO_ERROR != err);
- _PR_MD_MAP_READDIR_ERROR(err);
- return NULL;
- }
+ err = GetLastError();
+ PR_ASSERT(NO_ERROR != err);
+ _PR_MD_MAP_READDIR_ERROR(err);
+ return NULL;
+ }
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return NULL;
}
@@ -2801,11 +2892,11 @@ PRInt32
_PR_MD_DELETE(const char *name)
{
if (DeleteFile(name)) {
- return 0;
- } else {
- _PR_MD_MAP_DELETE_ERROR(GetLastError());
- return -1;
- }
+ return 0;
+ } else {
+ _PR_MD_MAP_DELETE_ERROR(GetLastError());
+ return -1;
+ }
}
void
@@ -2880,7 +2971,7 @@ _PR_MD_STAT(const char *fn, struct stat *info)
int len = strlen(fn);
if (len > 0 && len <= _MAX_PATH
- && IsPrevCharSlash(fn, fn + len)) {
+ && IsPrevCharSlash(fn, fn + len)) {
char newfn[_MAX_PATH + 1];
strcpy(newfn, fn);
@@ -2902,8 +2993,9 @@ IsPrevCharSlash(const char *str, const char *current)
{
const char *prev;
- if (str >= current)
+ if (str >= current) {
return PR_FALSE;
+ }
prev = _mbsdec(str, current);
return (prev == current - 1) && _PR_IS_SLASH(*prev);
}
@@ -2938,7 +3030,7 @@ IsRootDirectory(char *fn, size_t buflen)
}
if (isalpha(fn[0]) && fn[1] == ':' && _PR_IS_SLASH(fn[2])
- && fn[3] == '\0') {
+ && fn[3] == '\0') {
rv = GetDriveType(fn) > 1 ? PR_TRUE : PR_FALSE;
return rv;
}
@@ -3000,7 +3092,7 @@ PRInt32
_PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info)
{
WIN32_FILE_ATTRIBUTE_DATA findFileData;
-
+
if (NULL == fn || '\0' == *fn) {
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return -1;
@@ -3023,11 +3115,11 @@ _PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info)
_PR_FileTimeToPRTime(&findFileData.ftLastWriteTime, &info->modifyTime);
if (0 == findFileData.ftCreationTime.dwLowDateTime &&
- 0 == findFileData.ftCreationTime.dwHighDateTime) {
+ 0 == findFileData.ftCreationTime.dwHighDateTime) {
info->creationTime = info->modifyTime;
} else {
_PR_FileTimeToPRTime(&findFileData.ftCreationTime,
- &info->creationTime);
+ &info->creationTime);
}
return 0;
@@ -3057,14 +3149,16 @@ _PR_MD_GETOPENFILEINFO64(const PRFileDesc *fd, PRFileInfo64 *info)
rv = GetFileInformationByHandle((HANDLE)fd->secret->md.osfd, &hinfo);
if (rv == FALSE) {
- _PR_MD_MAP_FSTAT_ERROR(GetLastError());
+ _PR_MD_MAP_FSTAT_ERROR(GetLastError());
return -1;
- }
+ }
- if (hinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ if (hinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
info->type = PR_FILE_DIRECTORY;
- else
+ }
+ else {
info->type = PR_FILE_FILE;
+ }
info->size = hinfo.nFileSizeHigh;
info->size = (info->size << 32) + hinfo.nFileSizeLow;
@@ -3084,14 +3178,16 @@ _PR_MD_GETOPENFILEINFO(const PRFileDesc *fd, PRFileInfo *info)
rv = GetFileInformationByHandle((HANDLE)fd->secret->md.osfd, &hinfo);
if (rv == FALSE) {
- _PR_MD_MAP_FSTAT_ERROR(GetLastError());
+ _PR_MD_MAP_FSTAT_ERROR(GetLastError());
return -1;
- }
+ }
- if (hinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ if (hinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
info->type = PR_FILE_DIRECTORY;
- else
+ }
+ else {
info->type = PR_FILE_FILE;
+ }
info->size = hinfo.nFileSizeLow;
@@ -3106,11 +3202,11 @@ _PR_MD_RENAME(const char *from, const char *to)
{
/* Does this work with dot-relative pathnames? */
if (MoveFile(from, to)) {
- return 0;
- } else {
- _PR_MD_MAP_RENAME_ERROR(GetLastError());
- return -1;
- }
+ return 0;
+ } else {
+ _PR_MD_MAP_RENAME_ERROR(GetLastError());
+ return -1;
+ }
}
PRInt32
@@ -3119,21 +3215,21 @@ _PR_MD_ACCESS(const char *name, PRAccessHow how)
PRInt32 rv;
switch (how) {
- case PR_ACCESS_WRITE_OK:
- rv = _access(name, 02);
- break;
- case PR_ACCESS_READ_OK:
- rv = _access(name, 04);
- break;
- case PR_ACCESS_EXISTS:
- rv = _access(name, 00);
- break;
- default:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
- return -1;
- }
- if (rv < 0) {
- _PR_MD_MAP_ACCESS_ERROR(errno);
+ case PR_ACCESS_WRITE_OK:
+ rv = _access(name, 02);
+ break;
+ case PR_ACCESS_READ_OK:
+ rv = _access(name, 04);
+ break;
+ case PR_ACCESS_EXISTS:
+ rv = _access(name, 00);
+ break;
+ default:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+ return -1;
+ }
+ if (rv < 0) {
+ _PR_MD_MAP_ACCESS_ERROR(errno);
}
return rv;
}
@@ -3160,7 +3256,7 @@ _PR_MD_MAKE_DIR(const char *name, PRIntn mode)
PACL pACL = NULL;
if (_PR_NT_MakeSecurityDescriptorACL(mode, dirAccessTable,
- &pSD, &pACL) == PR_SUCCESS) {
+ &pSD, &pACL) == PR_SUCCESS) {
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = FALSE;
@@ -3203,17 +3299,17 @@ _PR_MD_LOCKFILE(PROsfd f)
memset(&(me->md.overlapped.overlapped), 0, sizeof(OVERLAPPED));
_PR_THREAD_LOCK(me);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
me->io_pending = PR_TRUE;
me->state = _PR_IO_WAIT;
_PR_THREAD_UNLOCK(me);
- rv = LockFileEx((HANDLE)f,
+ rv = LockFileEx((HANDLE)f,
LOCKFILE_EXCLUSIVE_LOCK,
0,
0x7fffffff,
@@ -3221,16 +3317,16 @@ _PR_MD_LOCKFILE(PROsfd f)
&me->md.overlapped.overlapped);
if (_native_threads_only) {
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return PR_FAILURE;
- }
- _PR_THREAD_UNLOCK(me);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return PR_FAILURE;
+ }
+ _PR_THREAD_UNLOCK(me);
if (rv == FALSE) {
err = GetLastError();
@@ -3249,7 +3345,7 @@ _PR_MD_LOCKFILE(PROsfd f)
*
* If we pretend we won't get a completion, NSPR gets confused later
* when the unexpected completion arrives. If we assume we do get
- * a completion, we hang on 3.51. Worse, Microsoft informs me that the
+ * a completion, we hang on 3.51. Worse, Microsoft informs me that the
* behavior varies on 3.51 depending on if you are using a network
* file system or a local disk!
*
@@ -3257,51 +3353,51 @@ _PR_MD_LOCKFILE(PROsfd f)
* depending on whether or not this system is EITHER
* - running NT 4.0
* - running NT 3.51 with a service pack greater than 5.
- *
+ *
* In the meantime, this code may not work on network file systems.
*
*/
if ( rv == FALSE && ((err = GetLastError()) != ERROR_IO_PENDING)) {
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return PR_FAILURE;
- }
- _PR_THREAD_UNLOCK(me);
-
- _PR_MD_MAP_LOCKF_ERROR(err);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return PR_FAILURE;
+ }
+ _PR_THREAD_UNLOCK(me);
+
+ _PR_MD_MAP_LOCKF_ERROR(err);
return PR_FAILURE;
}
#ifdef _NEED_351_FILE_LOCKING_HACK
else if (rv) {
- /* If this is NT 3.51 and the file is local, then we won't get a
+ /* If this is NT 3.51 and the file is local, then we won't get a
* completion back from LockFile when it succeeded.
*/
if (_nt_version_gets_lockfile_completion == PR_FALSE) {
if ( IsFileLocal((HANDLE)f) == _PR_LOCAL_FILE) {
me->io_pending = PR_FALSE;
me->state = _PR_RUNNING;
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
}
}
#endif /* _NEED_351_FILE_LOCKING_HACK */
if (_NT_IO_WAIT(me, PR_INTERVAL_NO_TIMEOUT) == PR_FAILURE) {
- _PR_THREAD_LOCK(me);
+ _PR_THREAD_LOCK(me);
me->io_pending = PR_FALSE;
me->state = _PR_RUNNING;
- _PR_THREAD_UNLOCK(me);
+ _PR_THREAD_UNLOCK(me);
return PR_FAILURE;
}
if (me->md.blocked_io_status == 0) {
- _PR_MD_MAP_LOCKF_ERROR(me->md.blocked_io_error);
+ _PR_MD_MAP_LOCKF_ERROR(me->md.blocked_io_error);
return PR_FAILURE;
}
@@ -3322,33 +3418,33 @@ _PR_MD_TLOCKFILE(PROsfd f)
memset(&(me->md.overlapped.overlapped), 0, sizeof(OVERLAPPED));
_PR_THREAD_LOCK(me);
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return -1;
- }
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return -1;
+ }
me->io_pending = PR_TRUE;
me->state = _PR_IO_WAIT;
_PR_THREAD_UNLOCK(me);
- rv = LockFileEx((HANDLE)f,
+ rv = LockFileEx((HANDLE)f,
LOCKFILE_FAIL_IMMEDIATELY|LOCKFILE_EXCLUSIVE_LOCK,
0,
0x7fffffff,
0,
&me->md.overlapped.overlapped);
if (_native_threads_only) {
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return PR_FAILURE;
- }
- _PR_THREAD_UNLOCK(me);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return PR_FAILURE;
+ }
+ _PR_THREAD_UNLOCK(me);
if (rv == FALSE) {
err = GetLastError();
@@ -3359,61 +3455,61 @@ _PR_MD_TLOCKFILE(PROsfd f)
return PR_SUCCESS;
}
if ( rv == FALSE && ((err = GetLastError()) != ERROR_IO_PENDING)) {
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return PR_FAILURE;
- }
- _PR_THREAD_UNLOCK(me);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return PR_FAILURE;
+ }
+ _PR_THREAD_UNLOCK(me);
_PR_MD_MAP_LOCKF_ERROR(err);
return PR_FAILURE;
}
#ifdef _NEED_351_FILE_LOCKING_HACK
else if (rv) {
- /* If this is NT 3.51 and the file is local, then we won't get a
+ /* If this is NT 3.51 and the file is local, then we won't get a
* completion back from LockFile when it succeeded.
*/
if (_nt_version_gets_lockfile_completion == PR_FALSE) {
if ( IsFileLocal((HANDLE)f) == _PR_LOCAL_FILE) {
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return PR_FAILURE;
- }
- _PR_THREAD_UNLOCK(me);
-
- return PR_SUCCESS;
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return PR_FAILURE;
+ }
+ _PR_THREAD_UNLOCK(me);
+
+ return PR_SUCCESS;
}
}
}
#endif /* _NEED_351_FILE_LOCKING_HACK */
if (_NT_IO_WAIT(me, PR_INTERVAL_NO_TIMEOUT) == PR_FAILURE) {
- _PR_THREAD_LOCK(me);
- me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- if (_PR_PENDING_INTERRUPT(me)) {
- me->flags &= ~_PR_INTERRUPT;
- PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
- _PR_THREAD_UNLOCK(me);
- return PR_FAILURE;
- }
- _PR_THREAD_UNLOCK(me);
+ _PR_THREAD_LOCK(me);
+ me->io_pending = PR_FALSE;
+ me->state = _PR_RUNNING;
+ if (_PR_PENDING_INTERRUPT(me)) {
+ me->flags &= ~_PR_INTERRUPT;
+ PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
+ _PR_THREAD_UNLOCK(me);
+ return PR_FAILURE;
+ }
+ _PR_THREAD_UNLOCK(me);
return PR_FAILURE;
}
if (me->md.blocked_io_status == 0) {
- _PR_MD_MAP_LOCKF_ERROR(me->md.blocked_io_error);
+ _PR_MD_MAP_LOCKF_ERROR(me->md.blocked_io_error);
return PR_FAILURE;
}
@@ -3440,11 +3536,12 @@ _PR_MD_UNLOCKFILE(PROsfd f)
0,
&me->md.overlapped.overlapped);
- if (rv)
+ if (rv) {
return PR_SUCCESS;
+ }
else {
int err = GetLastError();
- _PR_MD_MAP_LOCKF_ERROR(err);
+ _PR_MD_MAP_LOCKF_ERROR(err);
return PR_FAILURE;
}
}
@@ -3465,17 +3562,17 @@ _PR_MD_MAKE_NONBLOCK(PRFileDesc *f)
#ifdef _NEED_351_FILE_LOCKING_HACK
/***************
-**
+**
** Lockfile hacks
**
** The following code is a hack to work around a microsoft bug with lockfile.
** The problem is that on NT 3.51, if LockFileEx() succeeds, you never
** get a completion back for files that are on local disks. So, we need to
-** know if a file is local or remote so we can tell if we should expect
+** know if a file is local or remote so we can tell if we should expect
** a completion.
**
** The only way to check if a file is local or remote based on the handle is
-** to get the serial number for the volume it is mounted on and then to
+** to get the serial number for the volume it is mounted on and then to
** compare that with mounted drives. This code caches the volume numbers of
** fixed disks and does a relatively quick check.
**
@@ -3499,222 +3596,228 @@ DWORD dwRemoveableDrivesToCheck = 0; /* bitmask for removeable drives */
PRBool IsFileLocalInit()
{
- TCHAR lpBuffer[_PR_MAX_DRIVES*5];
- DWORD nBufferLength = _PR_MAX_DRIVES*5;
- DWORD nBufferNeeded = GetLogicalDriveStrings(0, NULL);
- DWORD dwIndex = 0;
- DWORD dwDriveType;
- DWORD dwVolumeSerialNumber;
- DWORD dwDriveIndex = 0;
- DWORD oldmode = (DWORD) -1;
-
- _MD_NEW_LOCK(&cachedVolumeLock);
-
- nBufferNeeded = GetLogicalDriveStrings(nBufferLength, lpBuffer);
- if (nBufferNeeded == 0 || nBufferNeeded > nBufferLength)
- return PR_FALSE;
-
- // Calling GetVolumeInformation on a removeable drive where the
- // disk is currently removed will cause a dialog box to the
- // console. This is not good.
- // Temporarily disable the SEM_FAILCRITICALERRORS to avoid the
- // damn dialog.
-
- dwCachedVolumeSerialNumbers[dwDriveIndex] = 0;
- oldmode = SetErrorMode(SEM_FAILCRITICALERRORS);
-
- // now loop through the logical drives
- while(lpBuffer[dwIndex] != TEXT('\0'))
- {
- // skip the floppy drives. This is *SLOW*
- if ((lpBuffer[dwIndex] == TEXT('A')) || (lpBuffer[dwIndex] == TEXT('B')))
- /* Skip over floppies */;
- else
- {
- dwDriveIndex = (lpBuffer[dwIndex] - TEXT('A'));
-
- dwDriveType = GetDriveType(&lpBuffer[dwIndex]);
-
- switch(dwDriveType)
- {
- // Ignore these drive types
- case 0:
- case 1:
- case DRIVE_REMOTE:
- default: // If the drive type is unknown, ignore it.
- break;
-
- // Removable media drives can have different serial numbers
- // at different times, so cache the current serial number
- // but keep track of them so they can be rechecked if necessary.
- case DRIVE_REMOVABLE:
-
- // CDROM is a removable media
- case DRIVE_CDROM:
-
- // no idea if ramdisks can change serial numbers or not
- // but it doesn't hurt to treat them as removable.
-
- case DRIVE_RAMDISK:
-
-
- // Here is where we keep track of removable drives.
- dwRemoveableDrivesToCheck |= 1 << dwDriveIndex;
-
- // removable drives fall through to fixed drives and get cached.
-
- case DRIVE_FIXED:
-
- // cache volume serial numbers.
- if (GetVolumeInformation(
- &lpBuffer[dwIndex],
- NULL, 0,
- &dwVolumeSerialNumber,
- NULL, NULL, NULL, 0)
- )
- {
- if (dwLastCachedDrive < dwDriveIndex)
- dwLastCachedDrive = dwDriveIndex;
- dwCachedVolumeSerialNumbers[dwDriveIndex] = dwVolumeSerialNumber;
- }
-
- break;
- }
- }
-
- dwIndex += lstrlen(&lpBuffer[dwIndex]) +1;
- }
-
- if (oldmode != (DWORD) -1) {
- SetErrorMode(oldmode);
- oldmode = (DWORD) -1;
- }
-
- return PR_TRUE;
+ TCHAR lpBuffer[_PR_MAX_DRIVES*5];
+ DWORD nBufferLength = _PR_MAX_DRIVES*5;
+ DWORD nBufferNeeded = GetLogicalDriveStrings(0, NULL);
+ DWORD dwIndex = 0;
+ DWORD dwDriveType;
+ DWORD dwVolumeSerialNumber;
+ DWORD dwDriveIndex = 0;
+ DWORD oldmode = (DWORD) -1;
+
+ _MD_NEW_LOCK(&cachedVolumeLock);
+
+ nBufferNeeded = GetLogicalDriveStrings(nBufferLength, lpBuffer);
+ if (nBufferNeeded == 0 || nBufferNeeded > nBufferLength) {
+ return PR_FALSE;
+ }
+
+ // Calling GetVolumeInformation on a removeable drive where the
+ // disk is currently removed will cause a dialog box to the
+ // console. This is not good.
+ // Temporarily disable the SEM_FAILCRITICALERRORS to avoid the
+ // damn dialog.
+
+ dwCachedVolumeSerialNumbers[dwDriveIndex] = 0;
+ oldmode = SetErrorMode(SEM_FAILCRITICALERRORS);
+
+ // now loop through the logical drives
+ while(lpBuffer[dwIndex] != TEXT('\0'))
+ {
+ // skip the floppy drives. This is *SLOW*
+ if ((lpBuffer[dwIndex] == TEXT('A')) || (lpBuffer[dwIndex] == TEXT('B')))
+ /* Skip over floppies */;
+ else
+ {
+ dwDriveIndex = (lpBuffer[dwIndex] - TEXT('A'));
+
+ dwDriveType = GetDriveType(&lpBuffer[dwIndex]);
+
+ switch(dwDriveType)
+ {
+ // Ignore these drive types
+ case 0:
+ case 1:
+ case DRIVE_REMOTE:
+ default: // If the drive type is unknown, ignore it.
+ break;
+
+ // Removable media drives can have different serial numbers
+ // at different times, so cache the current serial number
+ // but keep track of them so they can be rechecked if necessary.
+ case DRIVE_REMOVABLE:
+
+ // CDROM is a removable media
+ case DRIVE_CDROM:
+
+ // no idea if ramdisks can change serial numbers or not
+ // but it doesn't hurt to treat them as removable.
+
+ case DRIVE_RAMDISK:
+
+
+ // Here is where we keep track of removable drives.
+ dwRemoveableDrivesToCheck |= 1 << dwDriveIndex;
+
+ // removable drives fall through to fixed drives and get cached.
+
+ case DRIVE_FIXED:
+
+ // cache volume serial numbers.
+ if (GetVolumeInformation(
+ &lpBuffer[dwIndex],
+ NULL, 0,
+ &dwVolumeSerialNumber,
+ NULL, NULL, NULL, 0)
+ )
+ {
+ if (dwLastCachedDrive < dwDriveIndex) {
+ dwLastCachedDrive = dwDriveIndex;
+ }
+ dwCachedVolumeSerialNumbers[dwDriveIndex] = dwVolumeSerialNumber;
+ }
+
+ break;
+ }
+ }
+
+ dwIndex += lstrlen(&lpBuffer[dwIndex]) +1;
+ }
+
+ if (oldmode != (DWORD) -1) {
+ SetErrorMode(oldmode);
+ oldmode = (DWORD) -1;
+ }
+
+ return PR_TRUE;
}
PRInt32 IsFileLocal(HANDLE hFile)
{
- DWORD dwIndex = 0, dwMask;
- BY_HANDLE_FILE_INFORMATION Info;
- TCHAR szDrive[4] = TEXT("C:\\");
- DWORD dwVolumeSerialNumber;
- DWORD oldmode = (DWORD) -1;
- int rv = _PR_REMOTE_FILE;
-
- if (!GetFileInformationByHandle(hFile, &Info))
- return -1;
-
- // look to see if the volume serial number has been cached.
- _MD_LOCK(&cachedVolumeLock);
- while(dwIndex <= dwLastCachedDrive)
- if (dwCachedVolumeSerialNumbers[dwIndex++] == Info.dwVolumeSerialNumber)
- {
- _MD_UNLOCK(&cachedVolumeLock);
- return _PR_LOCAL_FILE;
- }
- _MD_UNLOCK(&cachedVolumeLock);
-
- // volume serial number not found in the cache. Check removable files.
- // removable drives are noted as a bitmask. If the bit associated with
- // a specific drive is set, then we should query its volume serial number
- // as its possible it has changed.
- dwMask = dwRemoveableDrivesToCheck;
- dwIndex = 0;
-
- while(dwMask)
- {
- while(!(dwMask & 1))
- {
- dwIndex++;
- dwMask = dwMask >> 1;
- }
-
- szDrive[0] = TEXT('A')+ (TCHAR) dwIndex;
-
- // Calling GetVolumeInformation on a removeable drive where the
- // disk is currently removed will cause a dialog box to the
- // console. This is not good.
- // Temporarily disable the SEM_FAILCRITICALERRORS to avoid the
- // dialog.
-
- oldmode = SetErrorMode(SEM_FAILCRITICALERRORS);
-
- if (GetVolumeInformation(
- szDrive,
- NULL, 0,
- &dwVolumeSerialNumber,
- NULL, NULL, NULL, 0)
- )
- {
- if (dwVolumeSerialNumber == Info.dwVolumeSerialNumber)
- {
- _MD_LOCK(&cachedVolumeLock);
- if (dwLastCachedDrive < dwIndex)
- dwLastCachedDrive = dwIndex;
- dwCachedVolumeSerialNumbers[dwIndex] = dwVolumeSerialNumber;
+ DWORD dwIndex = 0, dwMask;
+ BY_HANDLE_FILE_INFORMATION Info;
+ TCHAR szDrive[4] = TEXT("C:\\");
+ DWORD dwVolumeSerialNumber;
+ DWORD oldmode = (DWORD) -1;
+ int rv = _PR_REMOTE_FILE;
+
+ if (!GetFileInformationByHandle(hFile, &Info)) {
+ return -1;
+ }
+
+ // look to see if the volume serial number has been cached.
+ _MD_LOCK(&cachedVolumeLock);
+ while(dwIndex <= dwLastCachedDrive)
+ if (dwCachedVolumeSerialNumbers[dwIndex++] == Info.dwVolumeSerialNumber)
+ {
_MD_UNLOCK(&cachedVolumeLock);
- rv = _PR_LOCAL_FILE;
- }
- }
- if (oldmode != (DWORD) -1) {
- SetErrorMode(oldmode);
- oldmode = (DWORD) -1;
- }
-
- if (rv == _PR_LOCAL_FILE)
- return _PR_LOCAL_FILE;
-
- dwIndex++;
- dwMask = dwMask >> 1;
- }
-
- return _PR_REMOTE_FILE;
+ return _PR_LOCAL_FILE;
+ }
+ _MD_UNLOCK(&cachedVolumeLock);
+
+ // volume serial number not found in the cache. Check removable files.
+ // removable drives are noted as a bitmask. If the bit associated with
+ // a specific drive is set, then we should query its volume serial number
+ // as its possible it has changed.
+ dwMask = dwRemoveableDrivesToCheck;
+ dwIndex = 0;
+
+ while(dwMask)
+ {
+ while(!(dwMask & 1))
+ {
+ dwIndex++;
+ dwMask = dwMask >> 1;
+ }
+
+ szDrive[0] = TEXT('A')+ (TCHAR) dwIndex;
+
+ // Calling GetVolumeInformation on a removeable drive where the
+ // disk is currently removed will cause a dialog box to the
+ // console. This is not good.
+ // Temporarily disable the SEM_FAILCRITICALERRORS to avoid the
+ // dialog.
+
+ oldmode = SetErrorMode(SEM_FAILCRITICALERRORS);
+
+ if (GetVolumeInformation(
+ szDrive,
+ NULL, 0,
+ &dwVolumeSerialNumber,
+ NULL, NULL, NULL, 0)
+ )
+ {
+ if (dwVolumeSerialNumber == Info.dwVolumeSerialNumber)
+ {
+ _MD_LOCK(&cachedVolumeLock);
+ if (dwLastCachedDrive < dwIndex) {
+ dwLastCachedDrive = dwIndex;
+ }
+ dwCachedVolumeSerialNumbers[dwIndex] = dwVolumeSerialNumber;
+ _MD_UNLOCK(&cachedVolumeLock);
+ rv = _PR_LOCAL_FILE;
+ }
+ }
+ if (oldmode != (DWORD) -1) {
+ SetErrorMode(oldmode);
+ oldmode = (DWORD) -1;
+ }
+
+ if (rv == _PR_LOCAL_FILE) {
+ return _PR_LOCAL_FILE;
+ }
+
+ dwIndex++;
+ dwMask = dwMask >> 1;
+ }
+
+ return _PR_REMOTE_FILE;
}
#endif /* _NEED_351_FILE_LOCKING_HACK */
PR_IMPLEMENT(PRStatus) PR_NT_CancelIo(PRFileDesc *fd)
{
PRThread *me = _PR_MD_CURRENT_THREAD();
- PRBool fWait;
- PRFileDesc *bottom;
+ PRBool fWait;
+ PRFileDesc *bottom;
- bottom = PR_GetIdentitiesLayer(fd, PR_NSPR_IO_LAYER);
+ bottom = PR_GetIdentitiesLayer(fd, PR_NSPR_IO_LAYER);
if (!me->io_suspended || (NULL == bottom) ||
- (me->io_fd != bottom->secret->md.osfd)) {
+ (me->io_fd != bottom->secret->md.osfd)) {
PR_SetError(PR_INVALID_STATE_ERROR, 0);
return PR_FAILURE;
}
- /*
- * The CancelIO operation has to be issued by the same NT thread that
- * issued the I/O operation
- */
- PR_ASSERT(_PR_IS_NATIVE_THREAD(me) || (me->cpu == me->md.thr_bound_cpu));
- if (me->io_pending) {
- if (!CancelIo((HANDLE)bottom->secret->md.osfd)) {
- PR_SetError(PR_INVALID_STATE_ERROR, GetLastError());
- return PR_FAILURE;
- }
- }
- _PR_THREAD_LOCK(me);
- fWait = me->io_pending;
- me->io_suspended = PR_FALSE;
- me->state = _PR_IO_WAIT;
- me->md.interrupt_disabled = PR_TRUE;
- _PR_THREAD_UNLOCK(me);
- if (fWait)
- _NT_IO_WAIT(me, PR_INTERVAL_NO_TIMEOUT);
- PR_ASSERT(me->io_suspended == PR_FALSE);
- PR_ASSERT(me->io_pending == PR_FALSE);
-
- _PR_THREAD_LOCK(me);
- me->md.interrupt_disabled = PR_FALSE;
- me->md.thr_bound_cpu = NULL;
+ /*
+ * The CancelIO operation has to be issued by the same NT thread that
+ * issued the I/O operation
+ */
+ PR_ASSERT(_PR_IS_NATIVE_THREAD(me) || (me->cpu == me->md.thr_bound_cpu));
+ if (me->io_pending) {
+ if (!CancelIo((HANDLE)bottom->secret->md.osfd)) {
+ PR_SetError(PR_INVALID_STATE_ERROR, GetLastError());
+ return PR_FAILURE;
+ }
+ }
+ _PR_THREAD_LOCK(me);
+ fWait = me->io_pending;
+ me->io_suspended = PR_FALSE;
+ me->state = _PR_IO_WAIT;
+ me->md.interrupt_disabled = PR_TRUE;
+ _PR_THREAD_UNLOCK(me);
+ if (fWait) {
+ _NT_IO_WAIT(me, PR_INTERVAL_NO_TIMEOUT);
+ }
+ PR_ASSERT(me->io_suspended == PR_FALSE);
+ PR_ASSERT(me->io_pending == PR_FALSE);
+
+ _PR_THREAD_LOCK(me);
+ me->md.interrupt_disabled = PR_FALSE;
+ me->md.thr_bound_cpu = NULL;
me->io_suspended = PR_FALSE;
me->io_pending = PR_FALSE;
- me->state = _PR_RUNNING;
- _PR_THREAD_UNLOCK(me);
- return PR_SUCCESS;
+ me->state = _PR_RUNNING;
+ _PR_THREAD_UNLOCK(me);
+ return PR_SUCCESS;
}
static PROsfd _nt_nonblock_accept(PRFileDesc *fd, struct sockaddr *addr, int *addrlen, PRIntervalTime timeout)
@@ -3730,9 +3833,9 @@ static PROsfd _nt_nonblock_accept(PRFileDesc *fd, struct sockaddr *addr, int *ad
if (timeout == PR_INTERVAL_NO_TIMEOUT) {
while ((sock = accept(osfd, addr, addrlen)) == -1) {
if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
- && (!fd->secret->nonblocking)) {
+ && (!fd->secret->nonblocking)) {
if ((rv = _PR_NTFiberSafeSelect(0, &rd, NULL, NULL,
- NULL)) == -1) {
+ NULL)) == -1) {
_PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
break;
}
@@ -3744,7 +3847,7 @@ static PROsfd _nt_nonblock_accept(PRFileDesc *fd, struct sockaddr *addr, int *ad
} else if (timeout == PR_INTERVAL_NO_WAIT) {
if ((sock = accept(osfd, addr, addrlen)) == -1) {
if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
- && (!fd->secret->nonblocking)) {
+ && (!fd->secret->nonblocking)) {
PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
} else {
_PR_MD_MAP_ACCEPT_ERROR(err);
@@ -3754,10 +3857,10 @@ static PROsfd _nt_nonblock_accept(PRFileDesc *fd, struct sockaddr *addr, int *ad
retry:
if ((sock = accept(osfd, addr, addrlen)) == -1) {
if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
- && (!fd->secret->nonblocking)) {
+ && (!fd->secret->nonblocking)) {
tv.tv_sec = PR_IntervalToSeconds(timeout);
tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
+ timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
rv = _PR_NTFiberSafeSelect(0, &rd, NULL, NULL, tvp);
@@ -3792,7 +3895,7 @@ static PRInt32 _nt_nonblock_connect(PRFileDesc *fd, struct sockaddr *addr, int a
} else {
tv.tv_sec = PR_IntervalToSeconds(timeout);
tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
+ timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
}
FD_ZERO(&wr);
@@ -3800,7 +3903,7 @@ static PRInt32 _nt_nonblock_connect(PRFileDesc *fd, struct sockaddr *addr, int a
FD_SET((SOCKET)osfd, &wr);
FD_SET((SOCKET)osfd, &ex);
if ((rv = _PR_NTFiberSafeSelect(0, NULL, &wr, &ex,
- tvp)) == -1) {
+ tvp)) == -1) {
_PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
return rv;
}
@@ -3813,13 +3916,13 @@ static PRInt32 _nt_nonblock_connect(PRFileDesc *fd, struct sockaddr *addr, int a
if (FD_ISSET((SOCKET)osfd, &ex)) {
len = sizeof(err);
if (getsockopt(osfd, SOL_SOCKET, SO_ERROR,
- (char *) &err, &len) == SOCKET_ERROR) {
+ (char *) &err, &len) == SOCKET_ERROR) {
_PR_MD_MAP_GETSOCKOPT_ERROR(WSAGetLastError());
return -1;
}
_PR_MD_MAP_CONNECT_ERROR(err);
return -1;
- }
+ }
PR_ASSERT(FD_ISSET((SOCKET)osfd, &wr));
rv = 0;
} else {
@@ -3845,7 +3948,7 @@ static PRInt32 _nt_nonblock_recv(PRFileDesc *fd, char *buf, int len, int flags,
}
while ((rv = recv(osfd,buf,len,osflags)) == -1) {
if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
- && (!fd->secret->nonblocking)) {
+ && (!fd->secret->nonblocking)) {
FD_ZERO(&rd);
FD_SET((SOCKET)osfd, &rd);
if (timeout == PR_INTERVAL_NO_TIMEOUT) {
@@ -3853,11 +3956,11 @@ static PRInt32 _nt_nonblock_recv(PRFileDesc *fd, char *buf, int len, int flags,
} else {
tv.tv_sec = PR_IntervalToSeconds(timeout);
tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
+ timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
}
if ((rv = _PR_NTFiberSafeSelect(0, &rd, NULL, NULL,
- tvp)) == -1) {
+ tvp)) == -1) {
_PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
break;
} else if (rv == 0) {
@@ -3884,19 +3987,19 @@ static PRInt32 _nt_nonblock_send(PRFileDesc *fd, char *buf, int len, PRIntervalT
while(bytesSent < len) {
while ((rv = send(osfd,buf,len,0)) == -1) {
if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
- && (!fd->secret->nonblocking)) {
+ && (!fd->secret->nonblocking)) {
if ( timeout == PR_INTERVAL_NO_TIMEOUT ) {
tvp = NULL;
} else {
tv.tv_sec = PR_IntervalToSeconds(timeout);
tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
+ timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
}
FD_ZERO(&wd);
FD_SET((SOCKET)osfd, &wd);
if ((rv = _PR_NTFiberSafeSelect(0, NULL, &wd, NULL,
- tvp)) == -1) {
+ tvp)) == -1) {
_PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
return -1;
}
@@ -3919,13 +4022,13 @@ static PRInt32 _nt_nonblock_send(PRFileDesc *fd, char *buf, int len, PRIntervalT
} else {
tv.tv_sec = PR_IntervalToSeconds(timeout);
tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
+ timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
}
FD_ZERO(&wd);
FD_SET((SOCKET)osfd, &wd);
if ((rv = _PR_NTFiberSafeSelect(0, NULL, &wd, NULL,
- tvp)) == -1) {
+ tvp)) == -1) {
_PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
return -1;
}
@@ -3946,13 +4049,14 @@ static PRInt32 _nt_nonblock_writev(PRFileDesc *fd, const PRIOVec *iov, int size,
for (index=0; index<size; index++) {
rv = _nt_nonblock_send(fd, iov[index].iov_base, iov[index].iov_len, timeout);
- if (rv > 0)
+ if (rv > 0) {
sent += rv;
+ }
if ( rv != iov[index].iov_len ) {
if (rv < 0) {
if (fd->secret->nonblocking
- && (PR_GetError() == PR_WOULD_BLOCK_ERROR)
- && (sent > 0)) {
+ && (PR_GetError() == PR_WOULD_BLOCK_ERROR)
+ && (sent > 0)) {
return sent;
} else {
return -1;
@@ -3980,19 +4084,19 @@ static PRInt32 _nt_nonblock_sendto(
while(bytesSent < len) {
while ((rv = sendto(osfd,buf,len,0, addr, addrlen)) == -1) {
if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
- && (!fd->secret->nonblocking)) {
+ && (!fd->secret->nonblocking)) {
if ( timeout == PR_INTERVAL_NO_TIMEOUT ) {
tvp = NULL;
} else {
tv.tv_sec = PR_IntervalToSeconds(timeout);
tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
+ timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
}
FD_ZERO(&wd);
FD_SET((SOCKET)osfd, &wd);
if ((rv = _PR_NTFiberSafeSelect(0, NULL, &wd, NULL,
- tvp)) == -1) {
+ tvp)) == -1) {
_PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
return -1;
}
@@ -4015,13 +4119,13 @@ static PRInt32 _nt_nonblock_sendto(
} else {
tv.tv_sec = PR_IntervalToSeconds(timeout);
tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
+ timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
}
FD_ZERO(&wd);
FD_SET((SOCKET)osfd, &wd);
if ((rv = _PR_NTFiberSafeSelect(0, NULL, &wd, NULL,
- tvp)) == -1) {
+ tvp)) == -1) {
_PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
return -1;
}
@@ -4043,19 +4147,19 @@ static PRInt32 _nt_nonblock_recvfrom(PRFileDesc *fd, char *buf, int len, struct
while ((rv = recvfrom(osfd,buf,len,0,addr, addrlen)) == -1) {
if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
- && (!fd->secret->nonblocking)) {
+ && (!fd->secret->nonblocking)) {
if (timeout == PR_INTERVAL_NO_TIMEOUT) {
tvp = NULL;
} else {
tv.tv_sec = PR_IntervalToSeconds(timeout);
tv.tv_usec = PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
+ timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
}
FD_ZERO(&rd);
FD_SET((SOCKET)osfd, &rd);
if ((rv = _PR_NTFiberSafeSelect(0, &rd, NULL, NULL,
- tvp)) == -1) {
+ tvp)) == -1) {
_PR_MD_MAP_SELECT_ERROR(WSAGetLastError());
break;
} else if (rv == 0) {
@@ -4110,7 +4214,7 @@ static void pt_InsertTimedInternal(pt_Continuation *op)
* Subsequently earlier timeouts are computed based on the latter
* knowledge by subracting the timeout deltas that are stored in
* the operation list. There are operation[n]->timeout ticks
- * between the expiration of operation[n-1] and operation[n].e e
+ * between the expiration of operation[n-1] and operation[n].e e
*
* Therefore, the operation[n-1] will expire operation[n]->timeout
* ticks prior to operation[n].
@@ -4145,7 +4249,9 @@ static void pt_InsertTimedInternal(pt_Continuation *op)
qd_tmo -= t_op->timeout; /* previous operaton expiration */
t_op = t_op->prev; /* point to previous operation */
- if (NULL != t_op) qd_tmo += t_op->timeout;
+ if (NULL != t_op) {
+ qd_tmo += t_op->timeout;
+ }
} while (NULL != t_op);
/*
@@ -4170,19 +4276,26 @@ done:
op->prev = NULL;
op->next = pt_tq.head;
pt_tq.head = op;
- if (NULL == pt_tq.tail) pt_tq.tail = op;
- else op->next->prev = op;
+ if (NULL == pt_tq.tail) {
+ pt_tq.tail = op;
+ }
+ else {
+ op->next->prev = op;
+ }
}
else
{
op->prev = t_op;
op->next = t_op->next;
- if (NULL != op->prev)
+ if (NULL != op->prev) {
op->prev->next = op;
- if (NULL != op->next)
+ }
+ if (NULL != op->next) {
op->next->prev = op;
- if (t_op == pt_tq.tail)
+ }
+ if (t_op == pt_tq.tail) {
pt_tq.tail = op;
+ }
}
/*
@@ -4193,7 +4306,7 @@ done:
if (PR_INTERVAL_NO_TIMEOUT != op->timeout)
{
if ((NULL == pt_tq.op) /* we're the one and only */
- || (t_op == pt_tq.op)) /* we're replacing */
+ || (t_op == pt_tq.op)) /* we're replacing */
{
pt_tq.op = op;
pt_tq.epoch = now;
@@ -4217,13 +4330,23 @@ static pt_Continuation *pt_FinishTimedInternal(pt_Continuation *op)
pt_Continuation *next;
/* remove this one from the list */
- if (NULL == op->prev) pt_tq.head = op->next;
- else op->prev->next = op->next;
- if (NULL == op->next) pt_tq.tail = op->prev;
- else op->next->prev = op->prev;
+ if (NULL == op->prev) {
+ pt_tq.head = op->next;
+ }
+ else {
+ op->prev->next = op->next;
+ }
+ if (NULL == op->next) {
+ pt_tq.tail = op->prev;
+ }
+ else {
+ op->next->prev = op->prev;
+ }
/* did we happen to hit the timed op? */
- if (op == pt_tq.op) pt_tq.op = op->prev;
+ if (op == pt_tq.op) {
+ pt_tq.op = op->prev;
+ }
next = op->next;
op->next = op->prev = NULL;
@@ -4264,20 +4387,24 @@ static void ContinuationThread(void *arg)
{
status = PR_WaitCondVar(pt_tq.new_op, PR_INTERVAL_NO_TIMEOUT);
if ((PR_FAILURE == status)
- && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) break;
+ && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) {
+ break;
+ }
}
pollingListNeeded = pt_tq.op_count;
PR_Unlock(pt_tq.ml);
/* Okay. We're history */
if ((PR_FAILURE == status)
- && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) break;
+ && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) {
+ break;
+ }
- /*
- * We are not holding the pt_tq.ml lock now, so more items may
- * get added to pt_tq during this window of time. We hope
- * that 10 more spaces in the polling list should be enough.
- */
+ /*
+ * We are not holding the pt_tq.ml lock now, so more items may
+ * get added to pt_tq during this window of time. We hope
+ * that 10 more spaces in the polling list should be enough.
+ */
FD_ZERO(&readSet);
FD_ZERO(&writeSet);
@@ -4285,15 +4412,18 @@ static void ContinuationThread(void *arg)
pollingListNeeded += 10;
if (pollingListNeeded > pollingSlotsAllocated)
{
- if (NULL != pollingList) PR_DELETE(pollingList);
+ if (NULL != pollingList) {
+ PR_DELETE(pollingList);
+ }
pollingList = PR_MALLOC(pollingListNeeded * sizeof(PRPollDesc));
PR_ASSERT(NULL != pollingList);
pollingSlotsAllocated = pollingListNeeded;
}
#if defined(DEBUG)
- if (pollingListNeeded > pt_debug.pollingListMax)
+ if (pollingListNeeded > pt_debug.pollingListMax) {
pt_debug.pollingListMax = pollingListUsed;
+ }
#endif
/*
@@ -4328,7 +4458,9 @@ static void ContinuationThread(void *arg)
}
pollingList[pollingListUsed] = op->arg1.osfd;
pollingListUsed += 1;
- if (pollingListUsed == pollingSlotsAllocated) break;
+ if (pollingListUsed == pollingSlotsAllocated) {
+ break;
+ }
op = op->next;
}
}
@@ -4351,7 +4483,9 @@ static void ContinuationThread(void *arg)
}
/* there's a chance that all ops got blown away */
- if (NULL == pt_tq.head) continue;
+ if (NULL == pt_tq.head) {
+ continue;
+ }
/* if not, we know this is the shortest timeout */
timeout = pt_tq.head->timeout;
@@ -4362,10 +4496,13 @@ static void ContinuationThread(void *arg)
* should persist forever. But they may be aborted. That's
* what this anxiety is all about.
*/
- if (timeout > mx_select_ticks) timeout = mx_select_ticks;
+ if (timeout > mx_select_ticks) {
+ timeout = mx_select_ticks;
+ }
- if (PR_INTERVAL_NO_TIMEOUT != pt_tq.head->timeout)
+ if (PR_INTERVAL_NO_TIMEOUT != pt_tq.head->timeout) {
pt_tq.head->timeout -= timeout;
+ }
tv.tv_sec = PR_IntervalToSeconds(timeout);
tv.tv_usec = PR_IntervalToMicroseconds(timeout) % PR_USEC_PER_SEC;
@@ -4375,7 +4512,7 @@ static void ContinuationThread(void *arg)
{
if (0 == pt_tq.head->timeout)
{
- /*
+ /*
* The leading element of the timed queue has timed
* out. Get rid of it. In any case go around the
* loop again, computing the polling list, checking
@@ -4394,7 +4531,7 @@ static void ContinuationThread(void *arg)
}
if (-1 == rv && (WSAGetLastError() == WSAEINTR
- || WSAGetLastError() == WSAEINPROGRESS))
+ || WSAGetLastError() == WSAEINPROGRESS))
{
continue; /* go around the loop again */
}
@@ -4463,7 +4600,9 @@ static void ContinuationThread(void *arg)
}
}
}
- if (NULL != pollingList) PR_DELETE(pollingList);
+ if (NULL != pollingList) {
+ PR_DELETE(pollingList);
+ }
} /* ContinuationThread */
static int pt_Continue(pt_Continuation *op)
@@ -4493,8 +4632,9 @@ static int pt_Continue(pt_Continuation *op)
* anyhow and should notice the request in there.
*/
if ((PR_FAILURE == rv)
- && (PR_PENDING_INTERRUPT_ERROR == PR_GetError()))
- op->status = pt_continuation_abort; /* our status */
+ && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) {
+ op->status = pt_continuation_abort; /* our status */
+ }
}
PR_Unlock(pt_tq.ml); /* we provide the locking */
@@ -4507,8 +4647,8 @@ static int pt_Continue(pt_Continuation *op)
static PRBool pt_sendto_cont(pt_Continuation *op, PRInt16 revents)
{
PRIntn bytes = sendto(
- op->arg1.osfd, op->arg2.buffer, op->arg3.amount, op->arg4.flags,
- (struct sockaddr*)op->arg5.addr, sizeof(*(op->arg5.addr)));
+ op->arg1.osfd, op->arg2.buffer, op->arg3.amount, op->arg4.flags,
+ (struct sockaddr*)op->arg5.addr, sizeof(*(op->arg5.addr)));
op->syserrno = WSAGetLastError();
if (bytes > 0) /* this is progress */
{
@@ -4520,18 +4660,18 @@ static PRBool pt_sendto_cont(pt_Continuation *op, PRInt16 revents)
return (0 == op->arg3.amount) ? PR_TRUE : PR_FALSE;
}
else return ((-1 == bytes) && (WSAEWOULDBLOCK == op->syserrno)) ?
- PR_FALSE : PR_TRUE;
+ PR_FALSE : PR_TRUE;
} /* pt_sendto_cont */
static PRBool pt_recvfrom_cont(pt_Continuation *op, PRInt16 revents)
{
PRIntn addr_len = sizeof(*(op->arg5.addr));
op->result.code = recvfrom(
- op->arg1.osfd, op->arg2.buffer, op->arg3.amount,
- op->arg4.flags, (struct sockaddr*)op->arg5.addr, &addr_len);
+ op->arg1.osfd, op->arg2.buffer, op->arg3.amount,
+ op->arg4.flags, (struct sockaddr*)op->arg5.addr, &addr_len);
op->syserrno = WSAGetLastError();
return ((-1 == op->result.code) && (WSAEWOULDBLOCK == op->syserrno)) ?
- PR_FALSE : PR_TRUE;
+ PR_FALSE : PR_TRUE;
} /* pt_recvfrom_cont */
static PRInt32 pt_SendTo(
@@ -4543,13 +4683,15 @@ static PRInt32 pt_SendTo(
PRBool fNeedContinue = PR_FALSE;
bytes = sendto(
- osfd, buf, amount, flags,
- (struct sockaddr*)addr, PR_NETADDR_SIZE(addr));
+ osfd, buf, amount, flags,
+ (struct sockaddr*)addr, PR_NETADDR_SIZE(addr));
if (bytes == -1) {
- if ((err = WSAGetLastError()) == WSAEWOULDBLOCK)
- fNeedContinue = PR_TRUE;
- else
- _PR_MD_MAP_SENDTO_ERROR(err);
+ if ((err = WSAGetLastError()) == WSAEWOULDBLOCK) {
+ fNeedContinue = PR_TRUE;
+ }
+ else {
+ _PR_MD_MAP_SENDTO_ERROR(err);
+ }
}
if (fNeedContinue == PR_TRUE)
{
@@ -4566,26 +4708,28 @@ static PRInt32 pt_SendTo(
bytes = pt_Continue(&op);
if (bytes < 0) {
WSASetLastError(op.syserrno);
- _PR_MD_MAP_SENDTO_ERROR(op.syserrno);
+ _PR_MD_MAP_SENDTO_ERROR(op.syserrno);
}
}
return bytes;
} /* pt_SendTo */
static PRInt32 pt_RecvFrom(SOCKET osfd, void *buf, PRInt32 amount,
- PRInt32 flags, PRNetAddr *addr, PRIntn *addr_len, PRIntervalTime timeout)
+ PRInt32 flags, PRNetAddr *addr, PRIntn *addr_len, PRIntervalTime timeout)
{
PRInt32 bytes = -1, err;
PRBool fNeedContinue = PR_FALSE;
bytes = recvfrom(
- osfd, buf, amount, flags,
- (struct sockaddr*)addr, addr_len);
+ osfd, buf, amount, flags,
+ (struct sockaddr*)addr, addr_len);
if (bytes == -1) {
- if ((err = WSAGetLastError()) == WSAEWOULDBLOCK)
- fNeedContinue = PR_TRUE;
- else
- _PR_MD_MAP_RECVFROM_ERROR(err);
+ if ((err = WSAGetLastError()) == WSAEWOULDBLOCK) {
+ fNeedContinue = PR_TRUE;
+ }
+ else {
+ _PR_MD_MAP_RECVFROM_ERROR(err);
+ }
}
if (fNeedContinue == PR_TRUE)
@@ -4602,7 +4746,7 @@ static PRInt32 pt_RecvFrom(SOCKET osfd, void *buf, PRInt32 amount,
bytes = pt_Continue(&op);
if (bytes < 0) {
WSASetLastError(op.syserrno);
- _PR_MD_MAP_RECVFROM_ERROR(op.syserrno);
+ _PR_MD_MAP_RECVFROM_ERROR(op.syserrno);
}
}
return bytes;
diff --git a/nsprpub/pr/src/md/windows/ntmisc.c b/nsprpub/pr/src/md/windows/ntmisc.c
index 12f8c1df7..1ec6c2a5e 100644
--- a/nsprpub/pr/src/md/windows/ntmisc.c
+++ b/nsprpub/pr/src/md/windows/ntmisc.c
@@ -88,43 +88,43 @@ NowCalibrate(void)
LARGE_INTEGER liFreq, now;
if (calibration.freq == 0.0) {
- if(!QueryPerformanceFrequency(&liFreq)) {
- /* High-performance timer is unavailable */
- calibration.freq = -1.0;
- } else {
- calibration.freq = (long double) liFreq.QuadPart;
- }
+ if(!QueryPerformanceFrequency(&liFreq)) {
+ /* High-performance timer is unavailable */
+ calibration.freq = -1.0;
+ } else {
+ calibration.freq = (long double) liFreq.QuadPart;
+ }
}
if (calibration.freq > 0.0) {
- PRInt64 calibrationDelta = 0;
- /*
- * By wrapping a timeBegin/EndPeriod pair of calls around this loop,
- * the loop seems to take much less time (1 ms vs 15ms) on Vista.
- */
- timeBeginPeriod(1);
- LowResTime(&ftStart);
- do {
- LowResTime(&ft);
- } while (memcmp(&ftStart,&ft, sizeof(ft)) == 0);
- timeEndPeriod(1);
-
- calibration.granularity =
- (FILETIME_TO_INT64(ft) - FILETIME_TO_INT64(ftStart))/10;
-
- QueryPerformanceCounter(&now);
-
- calibration.offset = (long double) FILETIME_TO_INT64(ft);
- calibration.timer_offset = (long double) now.QuadPart;
- /*
- * The windows epoch is around 1600. The unix epoch is around 1970.
- * _pr_filetime_offset is the difference (in windows time units which
- * are 10 times more highres than the JS time unit)
- */
- calibration.offset -= _pr_filetime_offset;
- calibration.offset *= 0.1;
- calibration.last = 0;
-
- calibration.calibrated = PR_TRUE;
+ PRInt64 calibrationDelta = 0;
+ /*
+ * By wrapping a timeBegin/EndPeriod pair of calls around this loop,
+ * the loop seems to take much less time (1 ms vs 15ms) on Vista.
+ */
+ timeBeginPeriod(1);
+ LowResTime(&ftStart);
+ do {
+ LowResTime(&ft);
+ } while (memcmp(&ftStart,&ft, sizeof(ft)) == 0);
+ timeEndPeriod(1);
+
+ calibration.granularity =
+ (FILETIME_TO_INT64(ft) - FILETIME_TO_INT64(ftStart))/10;
+
+ QueryPerformanceCounter(&now);
+
+ calibration.offset = (long double) FILETIME_TO_INT64(ft);
+ calibration.timer_offset = (long double) now.QuadPart;
+ /*
+ * The windows epoch is around 1600. The unix epoch is around 1970.
+ * _pr_filetime_offset is the difference (in windows time units which
+ * are 10 times more highres than the JS time unit)
+ */
+ calibration.offset -= _pr_filetime_offset;
+ calibration.offset *= 0.1;
+ calibration.last = 0;
+
+ calibration.calibrated = PR_TRUE;
}
}
@@ -138,7 +138,7 @@ _MD_InitTime(void)
/* try for CE6 GetSystemTimeAsFileTime first */
HANDLE h = GetModuleHandleW(L"coredll.dll");
ce6_GetSystemTimeAsFileTime = (GetSystemTimeAsFileTimeFcn)
- GetProcAddressA(h, "GetSystemTimeAsFileTime");
+ GetProcAddressA(h, "GetSystemTimeAsFileTime");
/* otherwise go the slow route */
if (ce6_GetSystemTimeAsFileTime == NULL) {
@@ -199,113 +199,113 @@ PR_Now(void)
* a constant, and the entire expression is faster to execute.
*/
return currentTime.prt/_pr_filetime_divisor -
- _pr_filetime_offset/_pr_filetime_divisor;
+ _pr_filetime_offset/_pr_filetime_divisor;
}
do {
- if (!calibration.calibrated || needsCalibration) {
- EnterCriticalSection(&calibration.calibration_lock);
- EnterCriticalSection(&calibration.data_lock);
-
- /* Recalibrate only if no one else did before us */
- if (calibration.offset == cachedOffset) {
- /*
- * Since calibration can take a while, make any other
- * threads immediately wait
- */
- MUTEX_SETSPINCOUNT(&calibration.data_lock, 0);
-
- NowCalibrate();
-
- calibrated = PR_TRUE;
-
- /* Restore spin count */
- MUTEX_SETSPINCOUNT(&calibration.data_lock, DATALOCK_SPINCOUNT);
- }
- LeaveCriticalSection(&calibration.data_lock);
- LeaveCriticalSection(&calibration.calibration_lock);
- }
-
- /* Calculate a low resolution time */
- LowResTime(&ft);
- lowresTime =
+ if (!calibration.calibrated || needsCalibration) {
+ EnterCriticalSection(&calibration.calibration_lock);
+ EnterCriticalSection(&calibration.data_lock);
+
+ /* Recalibrate only if no one else did before us */
+ if (calibration.offset == cachedOffset) {
+ /*
+ * Since calibration can take a while, make any other
+ * threads immediately wait
+ */
+ MUTEX_SETSPINCOUNT(&calibration.data_lock, 0);
+
+ NowCalibrate();
+
+ calibrated = PR_TRUE;
+
+ /* Restore spin count */
+ MUTEX_SETSPINCOUNT(&calibration.data_lock, DATALOCK_SPINCOUNT);
+ }
+ LeaveCriticalSection(&calibration.data_lock);
+ LeaveCriticalSection(&calibration.calibration_lock);
+ }
+
+ /* Calculate a low resolution time */
+ LowResTime(&ft);
+ lowresTime =
((long double)(FILETIME_TO_INT64(ft) - _pr_filetime_offset)) * 0.1;
- if (calibration.freq > 0.0) {
- long double highresTime, diff;
- DWORD timeAdjustment, timeIncrement;
- BOOL timeAdjustmentDisabled;
-
- /* Default to 15.625 ms if the syscall fails */
- long double skewThreshold = 15625.25;
-
- /* Grab high resolution time */
- QueryPerformanceCounter(&now);
- highresTimerValue = (long double)now.QuadPart;
-
- EnterCriticalSection(&calibration.data_lock);
- highresTime = calibration.offset + 1000000L *
- (highresTimerValue-calibration.timer_offset)/calibration.freq;
- cachedOffset = calibration.offset;
-
- /*
- * On some dual processor/core systems, we might get an earlier
- * time so we cache the last time that we returned.
- */
- calibration.last = PR_MAX(calibration.last,(PRInt64)highresTime);
- returnedTime = calibration.last;
- LeaveCriticalSection(&calibration.data_lock);
-
- /* Get an estimate of clock ticks per second from our own test */
- skewThreshold = calibration.granularity;
- /* Check for clock skew */
- diff = lowresTime - highresTime;
-
- /*
- * For some reason that I have not determined, the skew can be
- * up to twice a kernel tick. This does not seem to happen by
- * itself, but I have only seen it triggered by another program
- * doing some kind of file I/O. The symptoms are a negative diff
- * followed by an equally large positive diff.
- */
- if (fabs(diff) > 2*skewThreshold) {
- if (calibrated) {
- /*
- * If we already calibrated once this instance, and the
- * clock is still skewed, then either the processor(s) are
- * wildly changing clockspeed or the system is so busy that
- * we get switched out for long periods of time. In either
- * case, it would be infeasible to make use of high
- * resolution results for anything, so let's resort to old
- * behavior for this call. It's possible that in the
- * future, the user will want the high resolution timer, so
- * we don't disable it entirely.
- */
- returnedTime = (PRInt64)lowresTime;
- needsCalibration = PR_FALSE;
- } else {
- /*
- * It is possible that when we recalibrate, we will return
- * a value less than what we have returned before; this is
- * unavoidable. We cannot tell the different between a
- * faulty QueryPerformanceCounter implementation and user
- * changes to the operating system time. Since we must
- * respect user changes to the operating system time, we
- * cannot maintain the invariant that Date.now() never
- * decreases; the old implementation has this behavior as
- * well.
- */
- needsCalibration = PR_TRUE;
- }
- } else {
- /* No detectable clock skew */
- returnedTime = (PRInt64)highresTime;
- needsCalibration = PR_FALSE;
- }
- } else {
- /* No high resolution timer is available, so fall back */
- returnedTime = (PRInt64)lowresTime;
- }
+ if (calibration.freq > 0.0) {
+ long double highresTime, diff;
+ DWORD timeAdjustment, timeIncrement;
+ BOOL timeAdjustmentDisabled;
+
+ /* Default to 15.625 ms if the syscall fails */
+ long double skewThreshold = 15625.25;
+
+ /* Grab high resolution time */
+ QueryPerformanceCounter(&now);
+ highresTimerValue = (long double)now.QuadPart;
+
+ EnterCriticalSection(&calibration.data_lock);
+ highresTime = calibration.offset + 1000000L *
+ (highresTimerValue-calibration.timer_offset)/calibration.freq;
+ cachedOffset = calibration.offset;
+
+ /*
+ * On some dual processor/core systems, we might get an earlier
+ * time so we cache the last time that we returned.
+ */
+ calibration.last = PR_MAX(calibration.last,(PRInt64)highresTime);
+ returnedTime = calibration.last;
+ LeaveCriticalSection(&calibration.data_lock);
+
+ /* Get an estimate of clock ticks per second from our own test */
+ skewThreshold = calibration.granularity;
+ /* Check for clock skew */
+ diff = lowresTime - highresTime;
+
+ /*
+ * For some reason that I have not determined, the skew can be
+ * up to twice a kernel tick. This does not seem to happen by
+ * itself, but I have only seen it triggered by another program
+ * doing some kind of file I/O. The symptoms are a negative diff
+ * followed by an equally large positive diff.
+ */
+ if (fabs(diff) > 2*skewThreshold) {
+ if (calibrated) {
+ /*
+ * If we already calibrated once this instance, and the
+ * clock is still skewed, then either the processor(s) are
+ * wildly changing clockspeed or the system is so busy that
+ * we get switched out for long periods of time. In either
+ * case, it would be infeasible to make use of high
+ * resolution results for anything, so let's resort to old
+ * behavior for this call. It's possible that in the
+ * future, the user will want the high resolution timer, so
+ * we don't disable it entirely.
+ */
+ returnedTime = (PRInt64)lowresTime;
+ needsCalibration = PR_FALSE;
+ } else {
+ /*
+ * It is possible that when we recalibrate, we will return
+ * a value less than what we have returned before; this is
+ * unavoidable. We cannot tell the different between a
+ * faulty QueryPerformanceCounter implementation and user
+ * changes to the operating system time. Since we must
+ * respect user changes to the operating system time, we
+ * cannot maintain the invariant that Date.now() never
+ * decreases; the old implementation has this behavior as
+ * well.
+ */
+ needsCalibration = PR_TRUE;
+ }
+ } else {
+ /* No detectable clock skew */
+ returnedTime = (PRInt64)highresTime;
+ needsCalibration = PR_FALSE;
+ }
+ } else {
+ /* No high resolution timer is available, so fall back */
+ returnedTime = (PRInt64)lowresTime;
+ }
} while (needsCalibration);
return returnedTime;
@@ -323,7 +323,7 @@ PR_Now(void)
GetSystemTime(&st);
SystemTimeToFileTime(&st, &ft);
_PR_FileTimeToPRTime(&ft, &prt);
- return prt;
+ return prt;
}
#endif
@@ -365,8 +365,8 @@ static int assembleCmdLine(char *const *argv, char **cmdLine)
* a null byte at the end of command line.
*/
cmdLineSize += 2 * strlen(*arg) /* \ and " need to be escaped */
- + 2 /* we quote every argument */
- + 1; /* space in between, or final null */
+ + 2 /* we quote every argument */
+ + 1; /* space in between, or final null */
}
p = *cmdLine = PR_MALLOC((PRUint32) cmdLineSize);
if (p == NULL) {
@@ -376,7 +376,7 @@ static int assembleCmdLine(char *const *argv, char **cmdLine)
for (arg = argv; *arg; arg++) {
/* Add a space to separates the arguments */
if (arg != argv) {
- *p++ = ' ';
+ *p++ = ' ';
}
q = *arg;
numBackslashes = 0;
@@ -442,7 +442,7 @@ static int assembleCmdLine(char *const *argv, char **cmdLine)
if (argNeedQuotes) {
*p++ = '"';
}
- }
+ }
*p = '\0';
return 0;
@@ -488,7 +488,7 @@ static int assembleEnvBlock(char **envp, char **envBlock)
cwdStart = curEnv;
while (*cwdStart) {
if (cwdStart[0] == '=' && cwdStart[1] != '\0'
- && cwdStart[2] == ':' && cwdStart[3] == '=') {
+ && cwdStart[2] == ':' && cwdStart[3] == '=') {
break;
}
cwdStart += strlen(cwdStart) + 1;
@@ -498,7 +498,7 @@ static int assembleEnvBlock(char **envp, char **envBlock)
cwdEnd += strlen(cwdEnd) + 1;
while (*cwdEnd) {
if (cwdEnd[0] != '=' || cwdEnd[1] == '\0'
- || cwdEnd[2] != ':' || cwdEnd[3] != '=') {
+ || cwdEnd[2] != ':' || cwdEnd[3] != '=') {
break;
}
cwdEnd += strlen(cwdEnd) + 1;
@@ -609,7 +609,7 @@ PRProcess * _PR_CreateWindowsProcess(
for (idx = 0; idx < numEnv; idx++) {
newEnvp[idx] = envp[idx];
if (hasFdInheritBuffer && !found
- && !strncmp(newEnvp[idx], "NSPR_INHERIT_FDS=", 17)) {
+ && !strncmp(newEnvp[idx], "NSPR_INHERIT_FDS=", 17)) {
newEnvp[idx] = attr->fdInheritBuffer;
found = PR_TRUE;
}
@@ -759,7 +759,7 @@ PRStatus _PR_DetachWindowsProcess(PRProcess *process)
* It can be called by native threads only (not by fibers).
*/
PRStatus _PR_WaitWindowsProcess(PRProcess *process,
- PRInt32 *exitCode)
+ PRInt32 *exitCode)
{
DWORD dwRetVal;
@@ -770,7 +770,7 @@ PRStatus _PR_WaitWindowsProcess(PRProcess *process,
}
PR_ASSERT(dwRetVal == WAIT_OBJECT_0);
if (exitCode != NULL &&
- GetExitCodeProcess(process->md.handle, exitCode) == FALSE) {
+ GetExitCodeProcess(process->md.handle, exitCode) == FALSE) {
PR_SetError(PR_UNKNOWN_ERROR, GetLastError());
return PR_FAILURE;
}
@@ -787,7 +787,7 @@ PRStatus _PR_KillWindowsProcess(PRProcess *process)
* 256 to indicate that the process is killed.
*/
if (TerminateProcess(process->md.handle, 256)) {
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
PR_SetError(PR_UNKNOWN_ERROR, GetLastError());
return PR_FAILURE;
@@ -804,86 +804,92 @@ PRStatus _MD_WindowsGetHostName(char *name, PRUint32 namelen)
}
syserror = WSAGetLastError();
PR_ASSERT(WSANOTINITIALISED != syserror);
- _PR_MD_MAP_GETHOSTNAME_ERROR(syserror);
+ _PR_MD_MAP_GETHOSTNAME_ERROR(syserror);
return PR_FAILURE;
}
PRStatus _MD_WindowsGetSysInfo(PRSysInfo cmd, char *name, PRUint32 namelen)
{
- OSVERSIONINFO osvi;
-
- PR_ASSERT((cmd == PR_SI_SYSNAME) || (cmd == PR_SI_RELEASE));
-
- ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-
- if (! GetVersionEx (&osvi) ) {
- _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
- return PR_FAILURE;
- }
-
- switch (osvi.dwPlatformId) {
- case VER_PLATFORM_WIN32_NT:
- if (PR_SI_SYSNAME == cmd)
- (void)PR_snprintf(name, namelen, "Windows_NT");
- else if (PR_SI_RELEASE == cmd)
- (void)PR_snprintf(name, namelen, "%d.%d",osvi.dwMajorVersion,
- osvi.dwMinorVersion);
- break;
- case VER_PLATFORM_WIN32_WINDOWS:
- if (PR_SI_SYSNAME == cmd) {
- if ((osvi.dwMajorVersion > 4) ||
- ((osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion > 0)))
- (void)PR_snprintf(name, namelen, "Windows_98");
- else
- (void)PR_snprintf(name, namelen, "Windows_95");
- } else if (PR_SI_RELEASE == cmd) {
- (void)PR_snprintf(name, namelen, "%d.%d",osvi.dwMajorVersion,
- osvi.dwMinorVersion);
- }
- break;
+ OSVERSIONINFO osvi;
+
+ PR_ASSERT((cmd == PR_SI_SYSNAME) || (cmd == PR_SI_RELEASE));
+
+ ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+
+ if (! GetVersionEx (&osvi) ) {
+ _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
+ return PR_FAILURE;
+ }
+
+ switch (osvi.dwPlatformId) {
+ case VER_PLATFORM_WIN32_NT:
+ if (PR_SI_SYSNAME == cmd) {
+ (void)PR_snprintf(name, namelen, "Windows_NT");
+ }
+ else if (PR_SI_RELEASE == cmd)
+ (void)PR_snprintf(name, namelen, "%d.%d",osvi.dwMajorVersion,
+ osvi.dwMinorVersion);
+ break;
+ case VER_PLATFORM_WIN32_WINDOWS:
+ if (PR_SI_SYSNAME == cmd) {
+ if ((osvi.dwMajorVersion > 4) ||
+ ((osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion > 0))) {
+ (void)PR_snprintf(name, namelen, "Windows_98");
+ }
+ else {
+ (void)PR_snprintf(name, namelen, "Windows_95");
+ }
+ } else if (PR_SI_RELEASE == cmd) {
+ (void)PR_snprintf(name, namelen, "%d.%d",osvi.dwMajorVersion,
+ osvi.dwMinorVersion);
+ }
+ break;
#ifdef VER_PLATFORM_WIN32_CE
- case VER_PLATFORM_WIN32_CE:
- if (PR_SI_SYSNAME == cmd)
- (void)PR_snprintf(name, namelen, "Windows_CE");
- else if (PR_SI_RELEASE == cmd)
- (void)PR_snprintf(name, namelen, "%d.%d",osvi.dwMajorVersion,
- osvi.dwMinorVersion);
- break;
+ case VER_PLATFORM_WIN32_CE:
+ if (PR_SI_SYSNAME == cmd) {
+ (void)PR_snprintf(name, namelen, "Windows_CE");
+ }
+ else if (PR_SI_RELEASE == cmd)
+ (void)PR_snprintf(name, namelen, "%d.%d",osvi.dwMajorVersion,
+ osvi.dwMinorVersion);
+ break;
#endif
- default:
- if (PR_SI_SYSNAME == cmd)
- (void)PR_snprintf(name, namelen, "Windows_Unknown");
- else if (PR_SI_RELEASE == cmd)
- (void)PR_snprintf(name, namelen, "%d.%d",0,0);
- break;
- }
- return PR_SUCCESS;
+ default:
+ if (PR_SI_SYSNAME == cmd) {
+ (void)PR_snprintf(name, namelen, "Windows_Unknown");
+ }
+ else if (PR_SI_RELEASE == cmd) {
+ (void)PR_snprintf(name, namelen, "%d.%d",0,0);
+ }
+ break;
+ }
+ return PR_SUCCESS;
}
PRStatus _MD_WindowsGetReleaseName(char *name, PRUint32 namelen)
{
- OSVERSIONINFO osvi;
-
- ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-
- if (! GetVersionEx (&osvi) ) {
- _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
- return PR_FAILURE;
- }
-
- switch (osvi.dwPlatformId) {
- case VER_PLATFORM_WIN32_NT:
- case VER_PLATFORM_WIN32_WINDOWS:
- (void)PR_snprintf(name, namelen, "%d.%d",osvi.dwMajorVersion,
- osvi.dwMinorVersion);
- break;
- default:
- (void)PR_snprintf(name, namelen, "%d.%d",0,0);
- break;
- }
- return PR_SUCCESS;
+ OSVERSIONINFO osvi;
+
+ ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+
+ if (! GetVersionEx (&osvi) ) {
+ _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
+ return PR_FAILURE;
+ }
+
+ switch (osvi.dwPlatformId) {
+ case VER_PLATFORM_WIN32_NT:
+ case VER_PLATFORM_WIN32_WINDOWS:
+ (void)PR_snprintf(name, namelen, "%d.%d",osvi.dwMajorVersion,
+ osvi.dwMinorVersion);
+ break;
+ default:
+ (void)PR_snprintf(name, namelen, "%d.%d",0,0);
+ break;
+ }
+ return PR_SUCCESS;
}
/*
@@ -924,12 +930,12 @@ PRStatus _MD_CreateFileMap(PRFileMap *fmap, PRInt64 size)
}
fmap->md.hFileMap = CreateFileMapping(
- (HANDLE) osfd,
- NULL,
- flProtect,
- dwHi,
- dwLo,
- NULL);
+ (HANDLE) osfd,
+ NULL,
+ flProtect,
+ dwHi,
+ dwLo,
+ NULL);
if (fmap->md.hFileMap == NULL) {
PR_SetError(PR_UNKNOWN_ERROR, GetLastError());
@@ -958,18 +964,18 @@ void * _MD_MemMap(
dwLo = (DWORD) (offset & 0xffffffff);
dwHi = (DWORD) (((PRUint64) offset >> 32) & 0xffffffff);
if ((addr = MapViewOfFile(fmap->md.hFileMap, fmap->md.dwAccess,
- dwHi, dwLo, len)) == NULL) {
+ dwHi, dwLo, len)) == NULL) {
{
- LPVOID lpMsgBuf;
-
- FormatMessage(
+ LPVOID lpMsgBuf;
+
+ FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
- NULL
+ NULL
);
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, ("md_memmap(): %s", lpMsgBuf ));
}
@@ -1035,13 +1041,13 @@ PRStatus _MD_SyncMemMap(
#pragma warning(disable: 4035)
PRInt32 _PR_MD_ATOMIC_INCREMENT(PRInt32 *val)
-{
+{
#if defined(__GNUC__)
- PRInt32 result;
- asm volatile ("lock ; xadd %0, %1"
- : "=r"(result), "=m"(*val)
- : "0"(1), "m"(*val));
- return result + 1;
+ PRInt32 result;
+ asm volatile ("lock ; xadd %0, %1"
+ : "=r"(result), "=m"(*val)
+ : "0"(1), "m"(*val));
+ return result + 1;
#else
__asm
{
@@ -1058,12 +1064,12 @@ PRInt32 _PR_MD_ATOMIC_INCREMENT(PRInt32 *val)
PRInt32 _PR_MD_ATOMIC_DECREMENT(PRInt32 *val)
{
#if defined(__GNUC__)
- PRInt32 result;
- asm volatile ("lock ; xadd %0, %1"
- : "=r"(result), "=m"(*val)
- : "0"(-1), "m"(*val));
- //asm volatile("lock ; xadd %0, %1" : "=m" (val), "=a" (result) : "-1" (1));
- return result - 1;
+ PRInt32 result;
+ asm volatile ("lock ; xadd %0, %1"
+ : "=r"(result), "=m"(*val)
+ : "0"(-1), "m"(*val));
+ //asm volatile("lock ; xadd %0, %1" : "=m" (val), "=a" (result) : "-1" (1));
+ return result - 1;
#else
__asm
{
@@ -1080,12 +1086,12 @@ PRInt32 _PR_MD_ATOMIC_DECREMENT(PRInt32 *val)
PRInt32 _PR_MD_ATOMIC_ADD(PRInt32 *intp, PRInt32 val)
{
#if defined(__GNUC__)
- PRInt32 result;
- //asm volatile("lock ; xadd %1, %0" : "=m" (intp), "=a" (result) : "1" (val));
- asm volatile ("lock ; xadd %0, %1"
- : "=r"(result), "=m"(*intp)
- : "0"(val), "m"(*intp));
- return result + val;
+ PRInt32 result;
+ //asm volatile("lock ; xadd %1, %0" : "=m" (intp), "=a" (result) : "1" (val));
+ asm volatile ("lock ; xadd %0, %1"
+ : "=r"(result), "=m"(*intp)
+ : "0"(val), "m"(*intp));
+ return result + val;
#else
__asm
{
@@ -1102,96 +1108,101 @@ PRInt32 _PR_MD_ATOMIC_ADD(PRInt32 *intp, PRInt32 val)
#ifdef _PR_HAVE_ATOMIC_CAS
#pragma warning(disable: 4035)
-void
+void
PR_StackPush(PRStack *stack, PRStackElem *stack_elem)
{
#if defined(__GNUC__)
- void **tos = (void **) stack;
- void *tmp;
-
- retry:
- if (*tos == (void *) -1)
- goto retry;
-
- __asm__("xchg %0,%1"
- : "=r" (tmp), "=m"(*tos)
- : "0" (-1), "m"(*tos));
-
- if (tmp == (void *) -1)
- goto retry;
-
- *(void **)stack_elem = tmp;
- __asm__("" : : : "memory");
- *tos = stack_elem;
+ void **tos = (void **) stack;
+ void *tmp;
+
+retry:
+ if (*tos == (void *) -1) {
+ goto retry;
+ }
+
+ __asm__("xchg %0,%1"
+ : "=r" (tmp), "=m"(*tos)
+ : "0" (-1), "m"(*tos));
+
+ if (tmp == (void *) -1) {
+ goto retry;
+ }
+
+ *(void **)stack_elem = tmp;
+ __asm__("" : : : "memory");
+ *tos = stack_elem;
#else
__asm
{
- mov ebx, stack
- mov ecx, stack_elem
-retry: mov eax,[ebx]
- cmp eax,-1
- je retry
- mov eax,-1
- xchg dword ptr [ebx], eax
- cmp eax,-1
- je retry
- mov [ecx],eax
- mov [ebx],ecx
+ mov ebx, stack
+ mov ecx, stack_elem
+ retry: mov eax,[ebx]
+ cmp eax,-1
+ je retry
+ mov eax,-1
+ xchg dword ptr [ebx], eax
+ cmp eax,-1
+ je retry
+ mov [ecx],eax
+ mov [ebx],ecx
}
#endif /* __GNUC__ */
}
#pragma warning(default: 4035)
#pragma warning(disable: 4035)
-PRStackElem *
+PRStackElem *
PR_StackPop(PRStack *stack)
{
#if defined(__GNUC__)
- void **tos = (void **) stack;
- void *tmp;
-
- retry:
- if (*tos == (void *) -1)
- goto retry;
-
- __asm__("xchg %0,%1"
- : "=r" (tmp), "=m"(*tos)
- : "0" (-1), "m"(*tos));
-
- if (tmp == (void *) -1)
- goto retry;
-
- if (tmp != (void *) 0)
+ void **tos = (void **) stack;
+ void *tmp;
+
+retry:
+ if (*tos == (void *) -1) {
+ goto retry;
+ }
+
+ __asm__("xchg %0,%1"
+ : "=r" (tmp), "=m"(*tos)
+ : "0" (-1), "m"(*tos));
+
+ if (tmp == (void *) -1) {
+ goto retry;
+ }
+
+ if (tmp != (void *) 0)
{
- void *next = *(void **)tmp;
- *tos = next;
- *(void **)tmp = 0;
+ void *next = *(void **)tmp;
+ *tos = next;
+ *(void **)tmp = 0;
+ }
+ else {
+ *tos = tmp;
}
- else
- *tos = tmp;
-
- return tmp;
+
+ return tmp;
#else
__asm
{
- mov ebx, stack
-retry: mov eax,[ebx]
- cmp eax,-1
- je retry
- mov eax,-1
- xchg dword ptr [ebx], eax
- cmp eax,-1
- je retry
- cmp eax,0
- je empty
- mov ecx,[eax]
- mov [ebx],ecx
- mov [eax],0
- jmp done
-empty:
- mov [ebx],eax
-done:
- }
+ mov ebx, stack
+ retry: mov eax,[ebx]
+ cmp eax,-1
+ je retry
+ mov eax,-1
+ xchg dword ptr [ebx], eax
+ cmp eax,-1
+ je retry
+ cmp eax,0
+ je empty
+ mov ecx,[eax]
+ mov [ebx],ecx
+ mov [eax],0
+ jmp done
+ empty:
+ mov [ebx],eax
+ done:
+ }
#endif /* __GNUC__ */
}
#pragma warning(default: 4035)
diff --git a/nsprpub/pr/src/md/windows/ntsec.c b/nsprpub/pr/src/md/windows/ntsec.c
index c0682e454..0006e8399 100644
--- a/nsprpub/pr/src/md/windows/ntsec.c
+++ b/nsprpub/pr/src/md/windows/ntsec.c
@@ -47,7 +47,7 @@ void _PR_NT_InitSids(void)
* to force proper alignment */
PTOKEN_OWNER pTokenOwner = (PTOKEN_OWNER) infoBuffer;
PTOKEN_PRIMARY_GROUP pTokenPrimaryGroup
- = (PTOKEN_PRIMARY_GROUP) infoBuffer;
+ = (PTOKEN_PRIMARY_GROUP) infoBuffer;
DWORD dwLength;
BOOL rv;
@@ -67,13 +67,13 @@ void _PR_NT_InitSids(void)
* with the error code ERROR_ACCESS_DENIED.
*/
PR_LOG(_pr_io_lm, PR_LOG_DEBUG,
- ("_PR_NT_InitSids: OpenProcessToken() failed. Error: %d",
+ ("_PR_NT_InitSids: OpenProcessToken() failed. Error: %d",
GetLastError()));
return;
}
rv = GetTokenInformation(hToken, TokenOwner, infoBuffer,
- sizeof(infoBuffer), &dwLength);
+ sizeof(infoBuffer), &dwLength);
PR_ASSERT(rv != 0);
dwLength = GetLengthSid(pTokenOwner->Owner);
_pr_nt_sids.owner = (PSID) PR_Malloc(dwLength);
@@ -82,13 +82,13 @@ void _PR_NT_InitSids(void)
PR_ASSERT(rv != 0);
rv = GetTokenInformation(hToken, TokenPrimaryGroup, infoBuffer,
- sizeof(infoBuffer), &dwLength);
+ sizeof(infoBuffer), &dwLength);
PR_ASSERT(rv != 0);
dwLength = GetLengthSid(pTokenPrimaryGroup->PrimaryGroup);
_pr_nt_sids.group = (PSID) PR_Malloc(dwLength);
PR_ASSERT(_pr_nt_sids.group != NULL);
rv = CopySid(dwLength, _pr_nt_sids.group,
- pTokenPrimaryGroup->PrimaryGroup);
+ pTokenPrimaryGroup->PrimaryGroup);
PR_ASSERT(rv != 0);
rv = CloseHandle(hToken);
@@ -96,9 +96,9 @@ void _PR_NT_InitSids(void)
/* Create a well-known SID for the Everyone group. */
rv = AllocateAndInitializeSid(&SIDAuthWorld, 1,
- SECURITY_WORLD_RID,
- 0, 0, 0, 0, 0, 0, 0,
- &_pr_nt_sids.everyone);
+ SECURITY_WORLD_RID,
+ 0, 0, 0, 0, 0, 0, 0,
+ &_pr_nt_sids.everyone);
PR_ASSERT(rv != 0);
#endif
}
@@ -184,10 +184,10 @@ _PR_NT_MakeSecurityDescriptorACL(
*/
cbACL = sizeof(ACL)
- + 3 * (sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD))
- + GetLengthSid(_pr_nt_sids.owner)
- + GetLengthSid(_pr_nt_sids.group)
- + GetLengthSid(_pr_nt_sids.everyone);
+ + 3 * (sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD))
+ + GetLengthSid(_pr_nt_sids.owner)
+ + GetLengthSid(_pr_nt_sids.group)
+ + GetLengthSid(_pr_nt_sids.everyone);
pACL = (PACL) PR_Malloc(cbACL);
if (pACL == NULL) {
_PR_MD_MAP_DEFAULT_ERROR(GetLastError());
@@ -198,29 +198,47 @@ _PR_NT_MakeSecurityDescriptorACL(
goto failed;
}
accessMask = 0;
- if (mode & 00400) accessMask |= accessTable[0];
- if (mode & 00200) accessMask |= accessTable[1];
- if (mode & 00100) accessMask |= accessTable[2];
+ if (mode & 00400) {
+ accessMask |= accessTable[0];
+ }
+ if (mode & 00200) {
+ accessMask |= accessTable[1];
+ }
+ if (mode & 00100) {
+ accessMask |= accessTable[2];
+ }
if (accessMask && !AddAccessAllowedAce(pACL, ACL_REVISION, accessMask,
- _pr_nt_sids.owner)) {
+ _pr_nt_sids.owner)) {
_PR_MD_MAP_DEFAULT_ERROR(GetLastError());
goto failed;
}
accessMask = 0;
- if (mode & 00040) accessMask |= accessTable[0];
- if (mode & 00020) accessMask |= accessTable[1];
- if (mode & 00010) accessMask |= accessTable[2];
+ if (mode & 00040) {
+ accessMask |= accessTable[0];
+ }
+ if (mode & 00020) {
+ accessMask |= accessTable[1];
+ }
+ if (mode & 00010) {
+ accessMask |= accessTable[2];
+ }
if (accessMask && !AddAccessAllowedAce(pACL, ACL_REVISION, accessMask,
- _pr_nt_sids.group)) {
+ _pr_nt_sids.group)) {
_PR_MD_MAP_DEFAULT_ERROR(GetLastError());
goto failed;
}
accessMask = 0;
- if (mode & 00004) accessMask |= accessTable[0];
- if (mode & 00002) accessMask |= accessTable[1];
- if (mode & 00001) accessMask |= accessTable[2];
+ if (mode & 00004) {
+ accessMask |= accessTable[0];
+ }
+ if (mode & 00002) {
+ accessMask |= accessTable[1];
+ }
+ if (mode & 00001) {
+ accessMask |= accessTable[2];
+ }
if (accessMask && !AddAccessAllowedAce(pACL, ACL_REVISION, accessMask,
- _pr_nt_sids.everyone)) {
+ _pr_nt_sids.everyone)) {
_PR_MD_MAP_DEFAULT_ERROR(GetLastError());
goto failed;
}
diff --git a/nsprpub/pr/src/md/windows/ntsem.c b/nsprpub/pr/src/md/windows/ntsem.c
index f36a145a9..757bc839e 100644
--- a/nsprpub/pr/src/md/windows/ntsem.c
+++ b/nsprpub/pr/src/md/windows/ntsem.c
@@ -12,38 +12,40 @@
#include "primpl.h"
-void
+void
_PR_MD_NEW_SEM(_MDSemaphore *md, PRUintn value)
{
md->sem = CreateSemaphore(NULL, value, 0x7fffffff, NULL);
}
-void
+void
_PR_MD_DESTROY_SEM(_MDSemaphore *md)
{
CloseHandle(md->sem);
}
-PRStatus
+PRStatus
_PR_MD_TIMED_WAIT_SEM(_MDSemaphore *md, PRIntervalTime ticks)
{
int rv;
rv = WaitForSingleObject(md->sem, PR_IntervalToMilliseconds(ticks));
- if (rv == WAIT_OBJECT_0)
+ if (rv == WAIT_OBJECT_0) {
return PR_SUCCESS;
- else
+ }
+ else {
return PR_FAILURE;
+ }
}
-PRStatus
+PRStatus
_PR_MD_WAIT_SEM(_MDSemaphore *md)
{
return _PR_MD_TIMED_WAIT_SEM(md, PR_INTERVAL_NO_TIMEOUT);
}
-void
+void
_PR_MD_POST_SEM(_MDSemaphore *md)
{
ReleaseSemaphore(md->sem, 1, NULL);
diff --git a/nsprpub/pr/src/md/windows/ntthread.c b/nsprpub/pr/src/md/windows/ntthread.c
index 1fdf0e93b..395a80dcc 100644
--- a/nsprpub/pr/src/md/windows/ntthread.c
+++ b/nsprpub/pr/src/md/windows/ntthread.c
@@ -109,8 +109,8 @@ _PR_MD_EARLY_INIT()
if (hModule) {
sSetThreadDescription =
(SETTHREADDESCRIPTION) GetProcAddress(
- hModule,
- "SetThreadDescription");
+ hModule,
+ "SetThreadDescription");
}
}
@@ -147,13 +147,13 @@ _PR_MD_INIT_THREAD(PRThread *thread)
** the pseudo handle via DuplicateHandle(...)
*/
DuplicateHandle(
- GetCurrentProcess(), /* Process of source handle */
- GetCurrentThread(), /* Pseudo Handle to dup */
- GetCurrentProcess(), /* Process of handle */
- &(thread->md.handle), /* resulting handle */
- 0L, /* access flags */
- FALSE, /* Inheritable */
- DUPLICATE_SAME_ACCESS); /* Options */
+ GetCurrentProcess(), /* Process of source handle */
+ GetCurrentThread(), /* Pseudo Handle to dup */
+ GetCurrentProcess(), /* Process of handle */
+ &(thread->md.handle), /* resulting handle */
+ 0L, /* access flags */
+ FALSE, /* Inheritable */
+ DUPLICATE_SAME_ACCESS); /* Options */
}
/* Create the blocking IO semaphore */
@@ -161,13 +161,13 @@ _PR_MD_INIT_THREAD(PRThread *thread)
if (thread->md.blocked_sema == NULL) {
return PR_FAILURE;
}
- if (_native_threads_only) {
- /* Create the blocking IO semaphore */
- thread->md.thr_event = CreateEvent(NULL, TRUE, FALSE, NULL);
- if (thread->md.thr_event == NULL) {
- return PR_FAILURE;
- }
- }
+ if (_native_threads_only) {
+ /* Create the blocking IO semaphore */
+ thread->md.thr_event = CreateEvent(NULL, TRUE, FALSE, NULL);
+ if (thread->md.thr_event == NULL) {
+ return PR_FAILURE;
+ }
+ }
}
return PR_SUCCESS;
@@ -181,23 +181,23 @@ pr_root(void *arg)
return 0;
}
-PRStatus
-_PR_MD_CREATE_THREAD(PRThread *thread,
- void (*start)(void *),
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize)
+PRStatus
+_PR_MD_CREATE_THREAD(PRThread *thread,
+ void (*start)(void *),
+ PRThreadPriority priority,
+ PRThreadScope scope,
+ PRThreadState state,
+ PRUint32 stackSize)
{
thread->md.start = start;
thread->md.handle = (HANDLE) _beginthreadex(
- NULL,
- thread->stack->stackSize,
- pr_root,
- (void *)thread,
- CREATE_SUSPENDED | STACK_SIZE_PARAM_IS_A_RESERVATION,
- &(thread->id));
+ NULL,
+ thread->stack->stackSize,
+ pr_root,
+ (void *)thread,
+ CREATE_SUSPENDED | STACK_SIZE_PARAM_IS_A_RESERVATION,
+ &(thread->id));
if(!thread->md.handle) {
PRErrorCode prerror;
thread->md.fiber_last_error = GetLastError();
@@ -228,8 +228,9 @@ _PR_MD_CREATE_THREAD(PRThread *thread,
}
/* Activate the thread */
- if ( ResumeThread( thread->md.handle ) != -1)
+ if ( ResumeThread( thread->md.handle ) != -1) {
return PR_SUCCESS;
+ }
PR_SetError(PR_UNKNOWN_ERROR, GetLastError());
return PR_FAILURE;
@@ -250,14 +251,14 @@ _PR_MD_END_THREAD(void)
_endthreadex(0);
}
-void
+void
_PR_MD_YIELD(void)
{
/* Can NT really yield at all? */
Sleep(0);
}
-void
+void
_PR_MD_SET_PRIORITY(_MDThread *thread, PRThreadPriority newPri)
{
int nativePri;
@@ -284,8 +285,8 @@ _PR_MD_SET_PRIORITY(_MDThread *thread, PRThreadPriority newPri)
rv = SetThreadPriority(thread->handle, nativePri);
PR_ASSERT(rv);
if (!rv) {
- PR_LOG(_pr_thread_lm, PR_LOG_MIN,
- ("PR_SetThreadPriority: can't set thread priority\n"));
+ PR_LOG(_pr_thread_lm, PR_LOG_MIN,
+ ("PR_SetThreadPriority: can't set thread priority\n"));
}
return;
}
@@ -295,10 +296,10 @@ const DWORD MS_VC_EXCEPTION = 0x406D1388;
#pragma pack(push,8)
typedef struct tagTHREADNAME_INFO
{
- DWORD dwType; // Must be 0x1000.
- LPCSTR szName; // Pointer to name (in user addr space).
- DWORD dwThreadID; // Thread ID (-1=caller thread).
- DWORD dwFlags; // Reserved for future use, must be zero.
+ DWORD dwType; // Must be 0x1000.
+ LPCSTR szName; // Pointer to name (in user addr space).
+ DWORD dwThreadID; // Thread ID (-1=caller thread).
+ DWORD dwFlags; // Reserved for future use, must be zero.
} THREADNAME_INFO;
#pragma pack(pop)
@@ -306,32 +307,33 @@ void
_PR_MD_SET_CURRENT_THREAD_NAME(const char *name)
{
#ifdef _MSC_VER
- THREADNAME_INFO info;
+ THREADNAME_INFO info;
#endif
- if (sSetThreadDescription) {
- WCHAR wideName[MAX_PATH];
- if (MultiByteToWideChar(CP_ACP, 0, name, -1, wideName, MAX_PATH)) {
- sSetThreadDescription(GetCurrentThread(), wideName);
- }
- }
+ if (sSetThreadDescription) {
+ WCHAR wideName[MAX_PATH];
+ if (MultiByteToWideChar(CP_ACP, 0, name, -1, wideName, MAX_PATH)) {
+ sSetThreadDescription(GetCurrentThread(), wideName);
+ }
+ }
#ifdef _MSC_VER
- if (!IsDebuggerPresent())
- return;
-
- info.dwType = 0x1000;
- info.szName = (char*) name;
- info.dwThreadID = -1;
- info.dwFlags = 0;
-
- __try {
- RaiseException(MS_VC_EXCEPTION,
- 0,
- sizeof(info) / sizeof(ULONG_PTR),
- (ULONG_PTR*)&info);
- } __except(EXCEPTION_CONTINUE_EXECUTION) {
- }
+ if (!IsDebuggerPresent()) {
+ return;
+ }
+
+ info.dwType = 0x1000;
+ info.szName = (char*) name;
+ info.dwThreadID = -1;
+ info.dwFlags = 0;
+
+ __try {
+ RaiseException(MS_VC_EXCEPTION,
+ 0,
+ sizeof(info) / sizeof(ULONG_PTR),
+ (ULONG_PTR*)&info);
+ } __except(EXCEPTION_CONTINUE_EXECUTION) {
+ }
#endif
}
@@ -353,13 +355,13 @@ _PR_MD_CLEAN_THREAD(PRThread *thread)
PR_ASSERT(rv);
thread->md.blocked_sema = 0;
}
- if (_native_threads_only) {
- if (thread->md.thr_event) {
- rv = CloseHandle(thread->md.thr_event);
- PR_ASSERT(rv);
- thread->md.thr_event = 0;
- }
- }
+ if (_native_threads_only) {
+ if (thread->md.thr_event) {
+ rv = CloseHandle(thread->md.thr_event);
+ PR_ASSERT(rv);
+ thread->md.thr_event = 0;
+ }
+ }
if (thread->md.handle) {
rv = CloseHandle(thread->md.handle);
@@ -399,13 +401,13 @@ _PR_MD_EXIT_THREAD(PRThread *thread)
thread->md.blocked_sema = 0;
}
- if (_native_threads_only) {
- if (thread->md.thr_event) {
- rv = CloseHandle(thread->md.thr_event);
- PR_ASSERT(rv);
- thread->md.thr_event = 0;
- }
- }
+ if (_native_threads_only) {
+ if (thread->md.thr_event) {
+ rv = CloseHandle(thread->md.thr_event);
+ PR_ASSERT(rv);
+ thread->md.thr_event = 0;
+ }
+ }
if (thread->md.handle) {
rv = CloseHandle(thread->md.handle);
@@ -428,7 +430,7 @@ _PR_MD_EXIT(PRIntn status)
#ifdef HAVE_FIBERS
void
-_pr_fiber_mainline(void *unused)
+_pr_fiber_mainline(void *unused)
{
PRThread *fiber = _PR_MD_CURRENT_THREAD();
@@ -445,7 +447,7 @@ PRThread *_PR_MD_CREATE_USER_THREAD(
if ( (thread = PR_NEW(PRThread)) == NULL ) {
return NULL;
}
-
+
memset(thread, 0, sizeof(PRThread));
thread->md.fiber_fn = start;
thread->md.fiber_arg = arg;
@@ -468,10 +470,11 @@ void
_PR_MD_INIT_CONTEXT(PRThread *thread, char *top, void (*start) (void), PRBool *status)
{
thread->md.fiber_fn = (void (*)(void *))start;
- thread->md.fiber_id = CreateFiber(thread->md.fiber_stacksize,
- (LPFIBER_START_ROUTINE)_pr_fiber_mainline, NULL);
- if (thread->md.fiber_id != 0)
+ thread->md.fiber_id = CreateFiber(thread->md.fiber_stacksize,
+ (LPFIBER_START_ROUTINE)_pr_fiber_mainline, NULL);
+ if (thread->md.fiber_id != 0) {
*status = PR_TRUE;
+ }
else {
DWORD oserror = GetLastError();
PRErrorCode prerror;
@@ -502,7 +505,7 @@ _PR_MD_RESTORE_CONTEXT(PRThread *thread)
PR_ASSERT( !_PR_IS_NATIVE_THREAD(thread) );
/* The user-level code for yielding will happily add ourselves to the runq
- * and then switch to ourselves; the NT fibers can't handle switching to
+ * and then switch to ourselves; the NT fibers can't handle switching to
* ourselves.
*/
if (thread != me) {
@@ -532,12 +535,12 @@ PRInt32 _PR_MD_GETTHREADAFFINITYMASK(PRThread *thread, PRUint32 *mask)
PRInt32 rv, system_mask;
rv = GetProcessAffinityMask(GetCurrentProcess(), mask, &system_mask);
-
+
return rv?0:-1;
}
-void
-_PR_MD_SUSPEND_CPU(_PRCPU *cpu)
+void
+_PR_MD_SUSPEND_CPU(_PRCPU *cpu)
{
_PR_MD_SUSPEND_THREAD(cpu->thread);
}
@@ -573,15 +576,15 @@ _PR_MD_RESUME_THREAD(PRThread *thread)
PRThread*
_MD_CURRENT_THREAD(void)
{
-PRThread *thread;
+ PRThread *thread;
- thread = _MD_GET_ATTACHED_THREAD();
+ thread = _MD_GET_ATTACHED_THREAD();
- if (NULL == thread) {
- thread = _PRI_AttachThread(
- PR_USER_THREAD, PR_PRIORITY_NORMAL, NULL, 0);
- }
- PR_ASSERT(thread != NULL);
- return thread;
+ if (NULL == thread) {
+ thread = _PRI_AttachThread(
+ PR_USER_THREAD, PR_PRIORITY_NORMAL, NULL, 0);
+ }
+ PR_ASSERT(thread != NULL);
+ return thread;
}
diff --git a/nsprpub/pr/src/md/windows/w32ipcsem.c b/nsprpub/pr/src/md/windows/w32ipcsem.c
index 954591002..500009352 100644
--- a/nsprpub/pr/src/md/windows/w32ipcsem.c
+++ b/nsprpub/pr/src/md/windows/w32ipcsem.c
@@ -18,17 +18,19 @@ static HANDLE OpenSemaphore(DWORD inDesiredAccess,
HANDLE retval = NULL;
HANDLE semaphore = NULL;
PRUnichar wideName[MAX_PATH]; /* name size is limited to MAX_PATH */
-
+
MultiByteToWideChar(CP_ACP, 0, inName, -1, wideName, MAX_PATH);
/* 0x7fffffff is the max count for our semaphore */
semaphore = CreateSemaphoreW(NULL, 0, 0x7fffffff, wideName);
if (NULL != semaphore) {
DWORD lastErr = GetLastError();
-
- if (ERROR_ALREADY_EXISTS != lastErr)
+
+ if (ERROR_ALREADY_EXISTS != lastErr) {
CloseHandle(semaphore);
- else
+ }
+ else {
retval = semaphore;
+ }
}
return retval;
}
@@ -97,8 +99,8 @@ static DWORD FiberSafeWaitForSingleObject(
warg.handle = hHandle;
warg.timeout = dwMilliseconds;
waitThread = PR_CreateThread(
- PR_USER_THREAD, WaitSingleThread, &warg,
- PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, WaitSingleThread, &warg,
+ PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
if (waitThread == NULL) {
return WAIT_FAILED;
}
@@ -133,7 +135,7 @@ PRSem *_PR_MD_OPEN_SEMAPHORE(
}
if (flags & PR_SEM_CREATE) {
if (_PR_NT_MakeSecurityDescriptorACL(mode, semAccessTable,
- &pSD, &pACL) == PR_SUCCESS) {
+ &pSD, &pACL) == PR_SUCCESS) {
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = FALSE;
@@ -142,7 +144,7 @@ PRSem *_PR_MD_OPEN_SEMAPHORE(
#ifdef WINCE
{
/* The size of a sem's name is limited to MAX_PATH. */
- PRUnichar wosname[MAX_PATH];
+ PRUnichar wosname[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, osname, -1, wosname, MAX_PATH);
sem->sem = CreateSemaphoreW(lpSA, value, 0x7fffffff, wosname);
}
@@ -165,7 +167,7 @@ PRSem *_PR_MD_OPEN_SEMAPHORE(
}
} else {
sem->sem = OpenSemaphore(
- SEMAPHORE_MODIFY_STATE|SYNCHRONIZE, FALSE, osname);
+ SEMAPHORE_MODIFY_STATE|SYNCHRONIZE, FALSE, osname);
if (sem->sem == NULL) {
DWORD err = GetLastError();
diff --git a/nsprpub/pr/src/md/windows/w32poll.c b/nsprpub/pr/src/md/windows/w32poll.c
index daf14dfe0..241c7e3e4 100644
--- a/nsprpub/pr/src/md/windows/w32poll.c
+++ b/nsprpub/pr/src/md/windows/w32poll.c
@@ -62,13 +62,17 @@ int _PR_NTFiberSafeSelect(
data.tv = timeout;
selectThread = PR_CreateThread(
- PR_USER_THREAD, _PR_MD_select_thread, &data,
- PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
- if (selectThread == NULL) return -1;
+ PR_USER_THREAD, _PR_MD_select_thread, &data,
+ PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
+ if (selectThread == NULL) {
+ return -1;
+ }
PR_JoinThread(selectThread);
ready = data.status;
- if (ready == SOCKET_ERROR) WSASetLastError(data.error);
+ if (ready == SOCKET_ERROR) {
+ WSASetLastError(data.error);
+ }
}
return ready;
}
@@ -120,17 +124,17 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
if (pd->in_flags & PR_POLL_READ)
{
in_flags_read = (pd->fd->methods->poll)(
- pd->fd, (PRInt16)(pd->in_flags & ~PR_POLL_WRITE),
- &out_flags_read);
+ pd->fd, (PRInt16)(pd->in_flags & ~PR_POLL_WRITE),
+ &out_flags_read);
}
if (pd->in_flags & PR_POLL_WRITE)
{
in_flags_write = (pd->fd->methods->poll)(
- pd->fd, (PRInt16)(pd->in_flags & ~PR_POLL_READ),
- &out_flags_write);
+ pd->fd, (PRInt16)(pd->in_flags & ~PR_POLL_READ),
+ &out_flags_write);
}
if ((0 != (in_flags_read & out_flags_read))
- || (0 != (in_flags_write & out_flags_write)))
+ || (0 != (in_flags_write & out_flags_write)))
{
/* this one's ready right now (buffered input) */
if (0 == ready)
@@ -158,7 +162,7 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
/* ignore a socket without PR_NSPR_IO_LAYER available */
if ((NULL != bottom)
- && (_PR_FILEDESC_OPEN == bottom->secret->state))
+ && (_PR_FILEDESC_OPEN == bottom->secret->state))
{
if (0 == ready)
{
@@ -214,7 +218,9 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
}
}
- if (0 != ready) return ready; /* no need to block */
+ if (0 != ready) {
+ return ready; /* no need to block */
+ }
/*
* FD_SET does nothing if the fd_set's internal fd_array is full. If
@@ -271,22 +277,30 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
if (FD_ISSET(osfd, &rd))
{
- if (pd->out_flags & _PR_POLL_READ_SYS_READ)
+ if (pd->out_flags & _PR_POLL_READ_SYS_READ) {
out_flags |= PR_POLL_READ;
- if (pd->out_flags & _PR_POLL_WRITE_SYS_READ)
+ }
+ if (pd->out_flags & _PR_POLL_WRITE_SYS_READ) {
out_flags |= PR_POLL_WRITE;
- }
+ }
+ }
if (FD_ISSET(osfd, &wt))
{
- if (pd->out_flags & _PR_POLL_READ_SYS_WRITE)
+ if (pd->out_flags & _PR_POLL_READ_SYS_WRITE) {
out_flags |= PR_POLL_READ;
- if (pd->out_flags & _PR_POLL_WRITE_SYS_WRITE)
+ }
+ if (pd->out_flags & _PR_POLL_WRITE_SYS_WRITE) {
out_flags |= PR_POLL_WRITE;
- }
- if (FD_ISSET(osfd, &ex)) out_flags |= PR_POLL_EXCEPT;
+ }
+ }
+ if (FD_ISSET(osfd, &ex)) {
+ out_flags |= PR_POLL_EXCEPT;
+ }
}
pd->out_flags = out_flags;
- if (out_flags) ready++;
+ if (out_flags) {
+ ready++;
+ }
}
PR_ASSERT(ready > 0);
}
@@ -306,7 +320,7 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
{
bottom = PR_GetIdentitiesLayer(pd->fd, PR_NSPR_IO_LAYER);
if (getsockopt(bottom->secret->md.osfd, SOL_SOCKET,
- SO_TYPE, (char *) &optval, &optlen) == -1)
+ SO_TYPE, (char *) &optval, &optlen) == -1)
{
PR_ASSERT(WSAGetLastError() == WSAENOTSOCK);
if (WSAGetLastError() == WSAENOTSOCK)
@@ -319,7 +333,9 @@ PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
}
PR_ASSERT(ready > 0);
}
- else _PR_MD_MAP_SELECT_ERROR(err);
+ else {
+ _PR_MD_MAP_SELECT_ERROR(err);
+ }
}
return ready;
diff --git a/nsprpub/pr/src/md/windows/w32rng.c b/nsprpub/pr/src/md/windows/w32rng.c
index 633ae0da5..c07625ecc 100644
--- a/nsprpub/pr/src/md/windows/w32rng.c
+++ b/nsprpub/pr/src/md/windows/w32rng.c
@@ -16,8 +16,9 @@ CurrentClockTickTime(LPDWORD lpdwHigh, LPDWORD lpdwLow)
{
LARGE_INTEGER liCount;
- if (!QueryPerformanceCounter(&liCount))
+ if (!QueryPerformanceCounter(&liCount)) {
return FALSE;
+ }
*lpdwHigh = liCount.u.HighPart;
*lpdwLow = liCount.u.LowPart;
@@ -31,8 +32,9 @@ extern PRSize _PR_MD_GetRandomNoise( void *buf, PRSize size )
size_t nBytes;
time_t sTime;
- if (size <= 0)
+ if (size <= 0) {
return 0;
+ }
CurrentClockTickTime(&dwHigh, &dwLow);
@@ -42,16 +44,18 @@ extern PRSize _PR_MD_GetRandomNoise( void *buf, PRSize size )
n += nBytes;
size -= nBytes;
- if (size <= 0)
+ if (size <= 0) {
return n;
+ }
nBytes = sizeof(dwHigh) > size ? size : sizeof(dwHigh);
memcpy(((char *)buf) + n, &dwHigh, nBytes);
n += nBytes;
size -= nBytes;
- if (size <= 0)
+ if (size <= 0) {
return n;
+ }
// get the number of milliseconds that have elapsed since Windows started
dwVal = GetTickCount();
@@ -61,8 +65,9 @@ extern PRSize _PR_MD_GetRandomNoise( void *buf, PRSize size )
n += nBytes;
size -= nBytes;
- if (size <= 0)
+ if (size <= 0) {
return n;
+ }
// get the time in seconds since midnight Jan 1, 1970
time(&sTime);
diff --git a/nsprpub/pr/src/md/windows/w32shm.c b/nsprpub/pr/src/md/windows/w32shm.c
index 8e8b1d684..b0d38b9d7 100644
--- a/nsprpub/pr/src/md/windows/w32shm.c
+++ b/nsprpub/pr/src/md/windows/w32shm.c
@@ -3,7 +3,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#include <private/primpl.h>
+#include <private/primpl.h>
#include <string.h>
#include <prshm.h>
#include <prerr.h>
@@ -23,15 +23,15 @@ extern PRLogModuleInfo *_pr_shm_lm;
*/
static DWORD filemapAccessTable[] = {
FILE_MAP_ALL_ACCESS & ~FILE_MAP_WRITE, /* read */
- FILE_MAP_ALL_ACCESS & ~FILE_MAP_READ, /* write */
+ FILE_MAP_ALL_ACCESS & ~FILE_MAP_READ, /* write */
0 /* execute */
};
-extern PRSharedMemory * _MD_OpenSharedMemory(
- const char *name,
- PRSize size,
- PRIntn flags,
- PRIntn mode
+extern PRSharedMemory * _MD_OpenSharedMemory(
+ const char *name,
+ PRSize size,
+ PRIntn flags,
+ PRIntn mode
)
{
char ipcname[PR_IPC_NAME_SIZE];
@@ -48,15 +48,15 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
if ( PR_FAILURE == rc )
{
PR_SetError(PR_UNKNOWN_ERROR, 0 );
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: name is invalid"));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: name is invalid"));
return(NULL);
}
shm = PR_NEWZAP( PRSharedMemory );
- if ( NULL == shm )
+ if ( NULL == shm )
{
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0 );
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New PRSharedMemory out of memory"));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New PRSharedMemory out of memory"));
return(NULL);
}
@@ -64,14 +64,14 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
if ( NULL == shm->ipcname )
{
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0 );
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New shm->ipcname out of memory"));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG, ( "PR_OpenSharedMemory: New shm->ipcname out of memory"));
PR_DELETE(shm);
return(NULL);
}
/* copy args to struct */
strcpy( shm->ipcname, ipcname );
- shm->size = size;
+ shm->size = size;
shm->mode = mode;
shm->flags = flags;
shm->ident = _PR_SHM_IDENT;
@@ -81,7 +81,7 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
dwLo = (DWORD) (shm->size & 0xffffffff);
if (_PR_NT_MakeSecurityDescriptorACL(mode, filemapAccessTable,
- &pSD, &pACL) == PR_SUCCESS) {
+ &pSD, &pACL) == PR_SUCCESS) {
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = FALSE;
@@ -97,48 +97,48 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
MultiByteToWideChar(CP_ACP, 0, shm->ipcname, -1,
wideIpcName, MAX_PATH);
shm->handle = CreateFileMappingW(
- (HANDLE)-1 ,
- lpSA,
- flProtect,
- dwHi,
- dwLo,
- wideIpcName);
+ (HANDLE)-1,
+ lpSA,
+ flProtect,
+ dwHi,
+ dwLo,
+ wideIpcName);
}
#else
shm->handle = CreateFileMappingA(
- (HANDLE)-1 ,
- lpSA,
- flProtect,
- dwHi,
- dwLo,
- shm->ipcname);
+ (HANDLE)-1,
+ lpSA,
+ flProtect,
+ dwHi,
+ dwLo,
+ shm->ipcname);
#endif
if (lpSA != NULL) {
_PR_NT_FreeSecurityDescriptorACL(pSD, pACL);
}
if ( NULL == shm->handle ) {
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
- ( "PR_OpenSharedMemory: CreateFileMapping() failed: %s",
- shm->ipcname ));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
+ ( "PR_OpenSharedMemory: CreateFileMapping() failed: %s",
+ shm->ipcname ));
_PR_MD_MAP_DEFAULT_ERROR( GetLastError());
PR_FREEIF( shm->ipcname )
PR_DELETE( shm );
return(NULL);
} else {
if (( flags & PR_SHM_EXCL) && ( GetLastError() == ERROR_ALREADY_EXISTS )) {
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
- ( "PR_OpenSharedMemory: Request exclusive & already exists",
- shm->ipcname ));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
+ ( "PR_OpenSharedMemory: Request exclusive & already exists",
+ shm->ipcname ));
PR_SetError( PR_FILE_EXISTS_ERROR, ERROR_ALREADY_EXISTS );
CloseHandle( shm->handle );
PR_FREEIF( shm->ipcname )
PR_DELETE( shm );
return(NULL);
} else {
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
- ( "PR_OpenSharedMemory: CreateFileMapping() success: %s, handle: %d",
- shm->ipcname, shm->handle ));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
+ ( "PR_OpenSharedMemory: CreateFileMapping() success: %s, handle: %d",
+ shm->ipcname, shm->handle ));
return(shm);
}
}
@@ -151,17 +151,17 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
#endif
if ( NULL == shm->handle ) {
_PR_MD_MAP_DEFAULT_ERROR( GetLastError());
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
- ( "PR_OpenSharedMemory: OpenFileMapping() failed: %s, error: %d",
- shm->ipcname, PR_GetOSError()));
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
+ ( "PR_OpenSharedMemory: OpenFileMapping() failed: %s, error: %d",
+ shm->ipcname, PR_GetOSError()));
PR_FREEIF( shm->ipcname );
PR_DELETE( shm );
return(NULL);
} else {
- PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
- ( "PR_OpenSharedMemory: OpenFileMapping() success: %s, handle: %d",
- shm->ipcname, shm->handle ));
- return(shm);
+ PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
+ ( "PR_OpenSharedMemory: OpenFileMapping() success: %s, handle: %d",
+ shm->ipcname, shm->handle ));
+ return(shm);
}
}
/* returns from separate paths */
@@ -174,18 +174,19 @@ extern void * _MD_AttachSharedMemory( PRSharedMemory *shm, PRIntn flags )
PR_ASSERT( shm->ident == _PR_SHM_IDENT );
- if ( PR_SHM_READONLY & flags )
+ if ( PR_SHM_READONLY & flags ) {
access = FILE_MAP_READ;
+ }
addr = MapViewOfFile( shm->handle,
- access,
- 0, 0,
- shm->size );
+ access,
+ 0, 0,
+ shm->size );
if ( NULL == addr ) {
_PR_MD_MAP_DEFAULT_ERROR( GetLastError());
- PR_LOG( _pr_shm_lm, PR_LOG_ERROR,
- ("_MD_AttachSharedMemory: MapViewOfFile() failed. OSerror: %d", PR_GetOSError()));
+ PR_LOG( _pr_shm_lm, PR_LOG_ERROR,
+ ("_MD_AttachSharedMemory: MapViewOfFile() failed. OSerror: %d", PR_GetOSError()));
}
return( addr );
@@ -200,11 +201,11 @@ extern PRStatus _MD_DetachSharedMemory( PRSharedMemory *shm, void *addr )
PR_ASSERT( shm->ident == _PR_SHM_IDENT );
wrc = UnmapViewOfFile( addr );
- if ( FALSE == wrc )
+ if ( FALSE == wrc )
{
_PR_MD_MAP_DEFAULT_ERROR( GetLastError());
- PR_LOG( _pr_shm_lm, PR_LOG_ERROR,
- ("_MD_DetachSharedMemory: UnmapViewOfFile() failed. OSerror: %d", PR_GetOSError()));
+ PR_LOG( _pr_shm_lm, PR_LOG_ERROR,
+ ("_MD_DetachSharedMemory: UnmapViewOfFile() failed. OSerror: %d", PR_GetOSError()));
rc = PR_FAILURE;
}
@@ -223,8 +224,8 @@ extern PRStatus _MD_CloseSharedMemory( PRSharedMemory *shm )
if ( FALSE == wrc )
{
_PR_MD_MAP_DEFAULT_ERROR( GetLastError());
- PR_LOG( _pr_shm_lm, PR_LOG_ERROR,
- ("_MD_CloseSharedMemory: CloseHandle() failed. OSerror: %d", PR_GetOSError()));
+ PR_LOG( _pr_shm_lm, PR_LOG_ERROR,
+ ("_MD_CloseSharedMemory: CloseHandle() failed. OSerror: %d", PR_GetOSError()));
rc = PR_FAILURE;
}
PR_FREEIF( shm->ipcname );
@@ -236,7 +237,7 @@ extern PRStatus _MD_CloseSharedMemory( PRSharedMemory *shm )
extern PRStatus _MD_DeleteSharedMemory( const char *name )
{
return( PR_SUCCESS );
-}
+}
/*
@@ -244,7 +245,7 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name )
*/
extern PRLogModuleInfo *_pr_shma_lm;
-extern PRFileMap* _md_OpenAnonFileMap(
+extern PRFileMap* _md_OpenAnonFileMap(
const char *dirName,
PRSize size,
PRFileMapProtect prot
@@ -256,7 +257,7 @@ extern PRFileMap* _md_OpenAnonFileMap(
fm = PR_CreateFileMap( (PRFileDesc*)-1, size, prot );
if ( NULL == fm ) {
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_OpenAnonFileMap(): PR_CreateFileMap(): failed"));
+ ("_md_OpenAnonFileMap(): PR_CreateFileMap(): failed"));
goto Finished;
}
@@ -267,12 +268,12 @@ extern PRFileMap* _md_OpenAnonFileMap(
** ERROR_CALL_NOT_IMPLEMENTED on Win95.
*/
if (DuplicateHandle(GetCurrentProcess(), fm->md.hFileMap,
- GetCurrentProcess(), &hFileMap,
- 0, TRUE /* inheritable */,
- DUPLICATE_SAME_ACCESS) == FALSE) {
+ GetCurrentProcess(), &hFileMap,
+ 0, TRUE /* inheritable */,
+ DUPLICATE_SAME_ACCESS) == FALSE) {
PR_SetError( PR_UNKNOWN_ERROR, GetLastError() );
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_OpenAnonFileMap(): DuplicateHandle(): failed"));
+ ("_md_OpenAnonFileMap(): DuplicateHandle(): failed"));
PR_CloseFileMap( fm );
fm = NULL;
goto Finished;
@@ -280,7 +281,7 @@ extern PRFileMap* _md_OpenAnonFileMap(
CloseHandle(fm->md.hFileMap);
fm->md.hFileMap = hFileMap;
-Finished:
+Finished:
return(fm);
} /* end md_OpenAnonFileMap() */
@@ -297,12 +298,12 @@ extern PRStatus _md_ExportFileMapAsString(
PRIntn written;
written = PR_snprintf( buf, (PRUint32) bufSize, "%d:%" PR_PRIdOSFD ":%ld",
- (PRIntn)fm->prot, (PROsfd)fm->md.hFileMap, (PRInt32)fm->md.dwAccess );
+ (PRIntn)fm->prot, (PROsfd)fm->md.hFileMap, (PRInt32)fm->md.dwAccess );
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_ExportFileMapAsString(): prot: %x, hFileMap: %x, dwAccess: %x",
- fm->prot, fm->md.hFileMap, fm->md.dwAccess ));
-
+ ("_md_ExportFileMapAsString(): prot: %x, hFileMap: %x, dwAccess: %x",
+ fm->prot, fm->md.hFileMap, fm->md.dwAccess ));
+
return((written == -1)? PR_FAILURE : PR_SUCCESS);
} /* end _md_ExportFileMapAsString() */
@@ -321,12 +322,12 @@ extern PRFileMap * _md_ImportFileMapFromString(
PRFileMap *fm = NULL;
PR_sscanf( fmstring, "%d:%" PR_SCNdOSFD ":%ld",
- &prot, &hFileMap, &dwAccess );
+ &prot, &hFileMap, &dwAccess );
fm = PR_NEWZAP(PRFileMap);
if ( NULL == fm ) {
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_ImportFileMapFromString(): PR_NEWZAP(): Failed"));
+ ("_md_ImportFileMapFromString(): PR_NEWZAP(): Failed"));
return(fm);
}
@@ -336,12 +337,12 @@ extern PRFileMap * _md_ImportFileMapFromString(
fm->fd = (PRFileDesc*)-1;
PR_LOG( _pr_shma_lm, PR_LOG_DEBUG,
- ("_md_ImportFileMapFromString(): fm: %p, prot: %d, hFileMap: %8.8x, dwAccess: %8.8x, fd: %x",
- fm, prot, fm->md.hFileMap, fm->md.dwAccess, fm->fd));
+ ("_md_ImportFileMapFromString(): fm: %p, prot: %d, hFileMap: %8.8x, dwAccess: %8.8x, fd: %x",
+ fm, prot, fm->md.hFileMap, fm->md.dwAccess, fm->fd));
return(fm);
} /* end _md_ImportFileMapFromString() */
#else
-Error! Why is PR_HAVE_WIN32_NAMED_SHARED_MEMORY not defined?
+Error! Why is PR_HAVE_WIN32_NAMED_SHARED_MEMORY not defined?
#endif /* PR_HAVE_WIN32_NAMED_SHARED_MEMORY */
/* --- end w32shm.c --- */
diff --git a/nsprpub/pr/src/md/windows/w95cv.c b/nsprpub/pr/src/md/windows/w95cv.c
index 27b34e691..5cf2966ff 100644
--- a/nsprpub/pr/src/md/windows/w95cv.c
+++ b/nsprpub/pr/src/md/windows/w95cv.c
@@ -16,7 +16,7 @@
* until right after we unlock the lock. This way the awakened threads
* have a better chance to reaquire the lock.
*/
-
+
#include "primpl.h"
/*
@@ -30,7 +30,7 @@ static void
AddThreadToCVWaitQueueInternal(PRThread *thred, struct _MDCVar *cv)
{
PR_ASSERT((cv->waitTail != NULL && cv->waitHead != NULL)
- || (cv->waitTail == NULL && cv->waitHead == NULL));
+ || (cv->waitTail == NULL && cv->waitHead == NULL));
cv->nwait += 1;
thred->md.inCVWaitQueue = PR_TRUE;
thred->md.next = NULL;
@@ -78,7 +78,7 @@ md_UnlockAndPostNotifies(
lock->notified.link = NULL;
#endif
- /*
+ /*
* Figure out how many threads we need to wake up.
*/
notified = &post; /* this is where we start */
@@ -87,7 +87,7 @@ md_UnlockAndPostNotifies(
_MDCVar *cv = notified->cv[index].cv;
PRThread *thred;
int i;
-
+
/* Fast special case: no waiting threads */
if (cv->waitHead == NULL) {
notified->cv[index].notifyHead = NULL;
@@ -134,7 +134,7 @@ md_UnlockAndPostNotifies(
}
/* Release the lock before notifying */
- LeaveCriticalSection(&lock->mutex);
+ LeaveCriticalSection(&lock->mutex);
notified = &post; /* this is where we start */
do {
@@ -156,7 +156,9 @@ md_UnlockAndPostNotifies(
}
prev = notified;
notified = notified->link;
- if (&post != prev) PR_DELETE(prev);
+ if (&post != prev) {
+ PR_DELETE(prev);
+ }
} while (NULL != notified);
}
@@ -166,7 +168,7 @@ md_UnlockAndPostNotifies(
* MP systems don't contend for a lock that they can't have.
*/
static void md_PostNotifyToCvar(_MDCVar *cvar, _MDLock *lock,
- PRBool broadcast)
+ PRBool broadcast)
{
PRIntn index = 0;
_MDNotified *notified = &lock->notified;
@@ -183,7 +185,9 @@ static void md_PostNotifyToCvar(_MDCVar *cvar, _MDLock *lock,
}
}
/* if not full, enter new CV in this array */
- if (notified->length < _MD_CV_NOTIFIED_LENGTH) break;
+ if (notified->length < _MD_CV_NOTIFIED_LENGTH) {
+ break;
+ }
/* if there's no link, create an empty array and link it */
if (NULL == notified->link) {
@@ -207,7 +211,7 @@ static void md_PostNotifyToCvar(_MDCVar *cvar, _MDLock *lock,
* 0 when it succeeds.
*
*/
-PRInt32
+PRInt32
_PR_MD_NEW_CV(_MDCVar *cv)
{
cv->magic = _MD_MAGIC_CV;
@@ -216,7 +220,7 @@ _PR_MD_NEW_CV(_MDCVar *cv)
* when the PRCondVar structure is created.
*/
return 0;
-}
+}
void _PR_MD_FREE_CV(_MDCVar *cv)
{
@@ -232,7 +236,7 @@ void _PR_MD_WAIT_CV(_MDCVar *cv, _MDLock *lock, PRIntervalTime timeout )
PRThread *thred = _PR_MD_CURRENT_THREAD();
DWORD rv;
DWORD msecs = (timeout == PR_INTERVAL_NO_TIMEOUT) ?
- INFINITE : PR_IntervalToMilliseconds(timeout);
+ INFINITE : PR_IntervalToMilliseconds(timeout);
/*
* If we have pending notifies, post them now.
@@ -256,7 +260,7 @@ void _PR_MD_WAIT_CV(_MDCVar *cv, _MDLock *lock, PRIntervalTime timeout )
if (rv == WAIT_TIMEOUT) {
if (thred->md.inCVWaitQueue) {
PR_ASSERT((cv->waitTail != NULL && cv->waitHead != NULL)
- || (cv->waitTail == NULL && cv->waitHead == NULL));
+ || (cv->waitTail == NULL && cv->waitHead == NULL));
cv->nwait -= 1;
thred->md.inCVWaitQueue = PR_FALSE;
if (cv->waitHead == thred) {
@@ -325,7 +329,7 @@ void _PR_MD_INIT_LOCKS(void)
PR_ASSERT(hKernel32);
PR_ASSERT(!sInitializeCriticalSectionEx);
sInitializeCriticalSectionEx = (INITIALIZECRITICALSECTIONEX)
- GetProcAddress(hKernel32, "InitializeCriticalSectionEx");
+ GetProcAddress(hKernel32, "InitializeCriticalSectionEx");
}
/*
diff --git a/nsprpub/pr/src/md/windows/w95dllmain.c b/nsprpub/pr/src/md/windows/w95dllmain.c
index 73707a6e1..c9ab87aec 100644
--- a/nsprpub/pr/src/md/windows/w95dllmain.c
+++ b/nsprpub/pr/src/md/windows/w95dllmain.c
@@ -18,7 +18,7 @@ BOOL WINAPI DllMain(
DWORD fdwReason,
LPVOID lpvReserved)
{
-PRThread *me;
+ PRThread *me;
switch (fdwReason) {
case DLL_PROCESS_ATTACH:
@@ -28,8 +28,9 @@ PRThread *me;
case DLL_THREAD_DETACH:
if (_pr_initialized) {
me = _MD_GET_ATTACHED_THREAD();
- if ((me != NULL) && (me->flags & _PR_ATTACHED))
+ if ((me != NULL) && (me->flags & _PR_ATTACHED)) {
_PRI_DetachThread();
+ }
}
break;
case DLL_PROCESS_DETACH:
diff --git a/nsprpub/pr/src/md/windows/w95io.c b/nsprpub/pr/src/md/windows/w95io.c
index 9bae6f8df..2ad52e19b 100644
--- a/nsprpub/pr/src/md/windows/w95io.c
+++ b/nsprpub/pr/src/md/windows/w95io.c
@@ -53,8 +53,8 @@ _PR_MD_INIT_IO()
{
SYSTEMTIME systime;
union {
- PRTime prt;
- FILETIME ft;
+ PRTime prt;
+ FILETIME ft;
} filetime;
BOOL rv;
@@ -84,16 +84,16 @@ _PR_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
DWORD rv;
PRUint32 msecs = (ticks == PR_INTERVAL_NO_TIMEOUT) ?
- INFINITE : PR_IntervalToMilliseconds(ticks);
+ INFINITE : PR_IntervalToMilliseconds(ticks);
rv = WaitForSingleObject(thread->md.blocked_sema, msecs);
- switch(rv)
+ switch(rv)
{
case WAIT_OBJECT_0:
return PR_SUCCESS;
case WAIT_TIMEOUT:
_PR_THREAD_LOCK(thread);
if (thread->state == _PR_IO_WAIT) {
- ;
+ ;
} else {
if (thread->wait.cvar != NULL) {
thread->wait.cvar = NULL;
@@ -116,13 +116,15 @@ _PR_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
PRStatus
_PR_MD_WAKEUP_WAITER(PRThread *thread)
{
- if ( _PR_IS_NATIVE_THREAD(thread) )
+ if ( _PR_IS_NATIVE_THREAD(thread) )
{
- if (ReleaseSemaphore(thread->md.blocked_sema, 1, NULL) == FALSE)
+ if (ReleaseSemaphore(thread->md.blocked_sema, 1, NULL) == FALSE) {
return PR_FAILURE;
- else
- return PR_SUCCESS;
- }
+ }
+ else {
+ return PR_SUCCESS;
+ }
+ }
}
@@ -135,7 +137,7 @@ _PR_MD_WAKEUP_WAITER(PRThread *thread)
* The NSPR open flags (osflags) are translated into flags for Win95
*
* Mode seems to be passed in as a unix style file permissions argument
- * as in 0666, in the case of opening the logFile.
+ * as in 0666, in the case of opening the logFile.
*
*/
PROsfd
@@ -145,26 +147,35 @@ _PR_MD_OPEN(const char *name, PRIntn osflags, int mode)
PRInt32 access = 0;
PRInt32 flags = 0;
PRInt32 flag6 = 0;
-
- if (osflags & PR_SYNC) flag6 = FILE_FLAG_WRITE_THROUGH;
-
- if (osflags & PR_RDONLY || osflags & PR_RDWR)
+
+ if (osflags & PR_SYNC) {
+ flag6 = FILE_FLAG_WRITE_THROUGH;
+ }
+
+ if (osflags & PR_RDONLY || osflags & PR_RDWR) {
access |= GENERIC_READ;
- if (osflags & PR_WRONLY || osflags & PR_RDWR)
+ }
+ if (osflags & PR_WRONLY || osflags & PR_RDWR) {
access |= GENERIC_WRITE;
+ }
- if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL )
+ if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL ) {
flags = CREATE_NEW;
+ }
else if (osflags & PR_CREATE_FILE) {
- if (osflags & PR_TRUNCATE)
+ if (osflags & PR_TRUNCATE) {
flags = CREATE_ALWAYS;
- else
+ }
+ else {
flags = OPEN_ALWAYS;
+ }
} else {
- if (osflags & PR_TRUNCATE)
+ if (osflags & PR_TRUNCATE) {
flags = TRUNCATE_EXISTING;
- else
+ }
+ else {
flags = OPEN_EXISTING;
+ }
}
file = CreateFileA(name,
@@ -175,9 +186,9 @@ _PR_MD_OPEN(const char *name, PRIntn osflags, int mode)
flag6,
NULL);
if (file == INVALID_HANDLE_VALUE) {
- _PR_MD_MAP_OPEN_ERROR(GetLastError());
- return -1;
- }
+ _PR_MD_MAP_OPEN_ERROR(GetLastError());
+ return -1;
+ }
return (PROsfd)file;
}
@@ -196,33 +207,42 @@ _PR_MD_OPEN_FILE(const char *name, PRIntn osflags, int mode)
if (osflags & PR_CREATE_FILE) {
if (_PR_NT_MakeSecurityDescriptorACL(mode, fileAccessTable,
- &pSD, &pACL) == PR_SUCCESS) {
+ &pSD, &pACL) == PR_SUCCESS) {
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = FALSE;
lpSA = &sa;
}
}
-
- if (osflags & PR_SYNC) flag6 = FILE_FLAG_WRITE_THROUGH;
-
- if (osflags & PR_RDONLY || osflags & PR_RDWR)
+
+ if (osflags & PR_SYNC) {
+ flag6 = FILE_FLAG_WRITE_THROUGH;
+ }
+
+ if (osflags & PR_RDONLY || osflags & PR_RDWR) {
access |= GENERIC_READ;
- if (osflags & PR_WRONLY || osflags & PR_RDWR)
+ }
+ if (osflags & PR_WRONLY || osflags & PR_RDWR) {
access |= GENERIC_WRITE;
+ }
- if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL )
+ if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL ) {
flags = CREATE_NEW;
+ }
else if (osflags & PR_CREATE_FILE) {
- if (osflags & PR_TRUNCATE)
+ if (osflags & PR_TRUNCATE) {
flags = CREATE_ALWAYS;
- else
+ }
+ else {
flags = OPEN_ALWAYS;
+ }
} else {
- if (osflags & PR_TRUNCATE)
+ if (osflags & PR_TRUNCATE) {
flags = TRUNCATE_EXISTING;
- else
+ }
+ else {
flags = OPEN_EXISTING;
+ }
}
file = CreateFileA(name,
@@ -236,9 +256,9 @@ _PR_MD_OPEN_FILE(const char *name, PRIntn osflags, int mode)
_PR_NT_FreeSecurityDescriptorACL(pSD, pACL);
}
if (file == INVALID_HANDLE_VALUE) {
- _PR_MD_MAP_OPEN_ERROR(GetLastError());
- return -1;
- }
+ _PR_MD_MAP_OPEN_ERROR(GetLastError());
+ return -1;
+ }
return (PROsfd)file;
}
@@ -250,22 +270,23 @@ _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
int rv, err;
rv = ReadFile((HANDLE)fd->secret->md.osfd,
- (LPVOID)buf,
- len,
- &bytes,
- NULL);
-
- if (rv == 0)
+ (LPVOID)buf,
+ len,
+ &bytes,
+ NULL);
+
+ if (rv == 0)
{
err = GetLastError();
/* ERROR_HANDLE_EOF can only be returned by async io */
PR_ASSERT(err != ERROR_HANDLE_EOF);
- if (err == ERROR_BROKEN_PIPE)
+ if (err == ERROR_BROKEN_PIPE) {
return 0;
- else {
- _PR_MD_MAP_READ_ERROR(err);
- return -1;
- }
+ }
+ else {
+ _PR_MD_MAP_READ_ERROR(err);
+ return -1;
+ }
}
return bytes;
}
@@ -276,16 +297,16 @@ _PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 len)
PROsfd f = fd->secret->md.osfd;
PRInt32 bytes;
int rv;
-
+
rv = WriteFile((HANDLE)f,
- buf,
- len,
- &bytes,
- NULL );
-
- if (rv == 0)
+ buf,
+ len,
+ &bytes,
+ NULL );
+
+ if (rv == 0)
{
- _PR_MD_MAP_WRITE_ERROR(GetLastError());
+ _PR_MD_MAP_WRITE_ERROR(GetLastError());
return -1;
}
return bytes;
@@ -348,7 +369,7 @@ _PR_MD_LSEEK64(PRFileDesc *fd, PROffset64 offset, PRSeekWhence whence)
li.QuadPart = offset;
li.LowPart = SetFilePointer((HANDLE)fd->secret->md.osfd,
- li.LowPart, &li.HighPart, moveMethod);
+ li.LowPart, &li.HighPart, moveMethod);
if (0xffffffff == li.LowPart && (err = GetLastError()) != NO_ERROR) {
_PR_MD_MAP_LSEEK_ERROR(err);
@@ -369,10 +390,10 @@ _PR_MD_FSYNC(PRFileDesc *fd)
/*
* From the documentation:
*
- * On Windows NT, the function FlushFileBuffers fails if hFile
- * is a handle to console output. That is because console
- * output is not buffered. The function returns FALSE, and
- * GetLastError returns ERROR_INVALID_HANDLE.
+ * On Windows NT, the function FlushFileBuffers fails if hFile
+ * is a handle to console output. That is because console
+ * output is not buffered. The function returns FALSE, and
+ * GetLastError returns ERROR_INVALID_HANDLE.
*
* On the other hand, on Win95, it returns without error. I cannot
* assume that 0, 1, and 2 are console, because if someone closes
@@ -386,11 +407,11 @@ _PR_MD_FSYNC(PRFileDesc *fd)
BOOL ok = FlushFileBuffers((HANDLE)fd->secret->md.osfd);
if (!ok) {
- DWORD err = GetLastError();
- if (err != ERROR_ACCESS_DENIED) { // from winerror.h
- _PR_MD_MAP_FSYNC_ERROR(err);
- return -1;
- }
+ DWORD err = GetLastError();
+ if (err != ERROR_ACCESS_DENIED) { // from winerror.h
+ _PR_MD_MAP_FSYNC_ERROR(err);
+ return -1;
+ }
}
return 0;
}
@@ -399,17 +420,18 @@ PRInt32
_MD_CloseFile(PROsfd osfd)
{
PRInt32 rv;
-
+
rv = (CloseHandle((HANDLE)osfd))?0:-1;
- if (rv == -1)
- _PR_MD_MAP_CLOSE_ERROR(GetLastError());
+ if (rv == -1) {
+ _PR_MD_MAP_CLOSE_ERROR(GetLastError());
+ }
return rv;
}
/* --- DIR IO ------------------------------------------------------------ */
#define GetFileFromDIR(d) (d)->d_entry.cFileName
-#define FileIsHidden(d) ((d)->d_entry.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
+#define FileIsHidden(d) ((d)->d_entry.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
static void FlipSlashes(char *cp, size_t len)
{
@@ -434,12 +456,12 @@ _PR_MD_CLOSE_DIR(_MDDir *d)
{
if ( d ) {
if (FindClose(d->d_hdl)) {
- d->magic = (PRUint32)-1;
- return 0;
- } else {
- _PR_MD_MAP_CLOSEDIR_ERROR(GetLastError());
- return -1;
- }
+ d->magic = (PRUint32)-1;
+ return 0;
+ } else {
+ _PR_MD_MAP_CLOSEDIR_ERROR(GetLastError());
+ return -1;
+ }
}
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return -1;
@@ -472,7 +494,7 @@ _PR_MD_OPEN_DIR(_MDDir *d, const char *name)
d->d_hdl = FindFirstFileA( filename, &(d->d_entry) );
if ( d->d_hdl == INVALID_HANDLE_VALUE ) {
- _PR_MD_MAP_OPENDIR_ERROR(GetLastError());
+ _PR_MD_MAP_OPENDIR_ERROR(GetLastError());
return PR_FAILURE;
}
d->firstEntry = PR_TRUE;
@@ -500,21 +522,24 @@ _PR_MD_READ_DIR(_MDDir *d, PRIntn flags)
}
fileName = GetFileFromDIR(d);
if ( (flags & PR_SKIP_DOT) &&
- (fileName[0] == '.') && (fileName[1] == '\0'))
- continue;
+ (fileName[0] == '.') && (fileName[1] == '\0')) {
+ continue;
+ }
if ( (flags & PR_SKIP_DOT_DOT) &&
(fileName[0] == '.') && (fileName[1] == '.') &&
- (fileName[2] == '\0'))
- continue;
- if ( (flags & PR_SKIP_HIDDEN) && FileIsHidden(d))
- continue;
+ (fileName[2] == '\0')) {
+ continue;
+ }
+ if ( (flags & PR_SKIP_HIDDEN) && FileIsHidden(d)) {
+ continue;
+ }
return fileName;
}
err = GetLastError();
PR_ASSERT(NO_ERROR != err);
- _PR_MD_MAP_READDIR_ERROR(err);
+ _PR_MD_MAP_READDIR_ERROR(err);
return NULL;
- }
+ }
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return NULL;
}
@@ -525,7 +550,7 @@ _PR_MD_DELETE(const char *name)
if (DeleteFileA(name)) {
return 0;
} else {
- _PR_MD_MAP_DELETE_ERROR(GetLastError());
+ _PR_MD_MAP_DELETE_ERROR(GetLastError());
return -1;
}
}
@@ -602,7 +627,7 @@ _PR_MD_STAT(const char *fn, struct stat *info)
size_t len = strlen(fn);
if (len > 0 && len <= _MAX_PATH
- && IsPrevCharSlash(fn, fn + len)) {
+ && IsPrevCharSlash(fn, fn + len)) {
char newfn[_MAX_PATH + 1];
strcpy(newfn, fn);
@@ -624,8 +649,9 @@ IsPrevCharSlash(const char *str, const char *current)
{
const char *prev;
- if (str >= current)
+ if (str >= current) {
return PR_FALSE;
+ }
prev = _mbsdec(str, current);
return (prev == current - 1) && _PR_IS_SLASH(*prev);
}
@@ -660,7 +686,7 @@ IsRootDirectory(char *fn, size_t buflen)
}
if (isalpha(fn[0]) && fn[1] == ':' && _PR_IS_SLASH(fn[2])
- && fn[3] == '\0') {
+ && fn[3] == '\0') {
rv = GetDriveType(fn) > 1 ? PR_TRUE : PR_FALSE;
return rv;
}
@@ -723,7 +749,7 @@ _PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info)
{
WIN32_FILE_ATTRIBUTE_DATA findFileData;
BOOL rv;
-
+
if (NULL == fn || '\0' == *fn) {
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return -1;
@@ -747,11 +773,11 @@ _PR_MD_GETFILEINFO64(const char *fn, PRFileInfo64 *info)
_PR_FileTimeToPRTime(&findFileData.ftLastWriteTime, &info->modifyTime);
if (0 == findFileData.ftCreationTime.dwLowDateTime &&
- 0 == findFileData.ftCreationTime.dwHighDateTime) {
+ 0 == findFileData.ftCreationTime.dwHighDateTime) {
info->creationTime = info->modifyTime;
} else {
_PR_FileTimeToPRTime(&findFileData.ftCreationTime,
- &info->creationTime);
+ &info->creationTime);
}
return 0;
@@ -781,14 +807,16 @@ _PR_MD_GETOPENFILEINFO64(const PRFileDesc *fd, PRFileInfo64 *info)
rv = GetFileInformationByHandle((HANDLE)fd->secret->md.osfd, &hinfo);
if (rv == FALSE) {
- _PR_MD_MAP_FSTAT_ERROR(GetLastError());
+ _PR_MD_MAP_FSTAT_ERROR(GetLastError());
return -1;
- }
+ }
- if (hinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ if (hinfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
info->type = PR_FILE_DIRECTORY;
- else
+ }
+ else {
info->type = PR_FILE_FILE;
+ }
info->size = hinfo.nFileSizeHigh;
info->size = (info->size << 32) + hinfo.nFileSizeLow;
@@ -824,15 +852,15 @@ _PR_MD_SET_FD_INHERITABLE(PRFileDesc *fd, PRBool inheritable)
* ERROR_CALL_NOT_IMPLEMENTED error on Win95.
*/
rv = SetHandleInformation(
- (HANDLE)fd->secret->md.osfd,
- HANDLE_FLAG_INHERIT,
- inheritable ? HANDLE_FLAG_INHERIT : 0);
+ (HANDLE)fd->secret->md.osfd,
+ HANDLE_FLAG_INHERIT,
+ inheritable ? HANDLE_FLAG_INHERIT : 0);
if (0 == rv) {
_PR_MD_MAP_DEFAULT_ERROR(GetLastError());
return PR_FAILURE;
}
return PR_SUCCESS;
-}
+}
void
_PR_MD_INIT_FD_INHERITABLE(PRFileDesc *fd, PRBool imported)
@@ -866,7 +894,7 @@ _PR_MD_RENAME(const char *from, const char *to)
if (MoveFileA(from, to)) {
return 0;
} else {
- _PR_MD_MAP_RENAME_ERROR(GetLastError());
+ _PR_MD_MAP_RENAME_ERROR(GetLastError());
return -1;
}
}
@@ -874,23 +902,24 @@ _PR_MD_RENAME(const char *from, const char *to)
PRInt32
_PR_MD_ACCESS(const char *name, PRAccessHow how)
{
-PRInt32 rv;
+ PRInt32 rv;
switch (how) {
- case PR_ACCESS_WRITE_OK:
- rv = _access(name, 02);
- break;
- case PR_ACCESS_READ_OK:
- rv = _access(name, 04);
- break;
- case PR_ACCESS_EXISTS:
- return _access(name, 00);
- break;
- default:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
- return -1;
- }
- if (rv < 0)
- _PR_MD_MAP_ACCESS_ERROR(errno);
+ case PR_ACCESS_WRITE_OK:
+ rv = _access(name, 02);
+ break;
+ case PR_ACCESS_READ_OK:
+ rv = _access(name, 04);
+ break;
+ case PR_ACCESS_EXISTS:
+ return _access(name, 00);
+ break;
+ default:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+ return -1;
+ }
+ if (rv < 0) {
+ _PR_MD_MAP_ACCESS_ERROR(errno);
+ }
return rv;
}
@@ -901,7 +930,7 @@ _PR_MD_MKDIR(const char *name, PRIntn mode)
if (CreateDirectoryA(name, NULL)) {
return 0;
} else {
- _PR_MD_MAP_MKDIR_ERROR(GetLastError());
+ _PR_MD_MAP_MKDIR_ERROR(GetLastError());
return -1;
}
}
@@ -916,7 +945,7 @@ _PR_MD_MAKE_DIR(const char *name, PRIntn mode)
PACL pACL = NULL;
if (_PR_NT_MakeSecurityDescriptorACL(mode, dirAccessTable,
- &pSD, &pACL) == PR_SUCCESS) {
+ &pSD, &pACL) == PR_SUCCESS) {
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = FALSE;
@@ -940,7 +969,7 @@ _PR_MD_RMDIR(const char *name)
if (RemoveDirectoryA(name)) {
return 0;
} else {
- _PR_MD_MAP_RMDIR_ERROR(GetLastError());
+ _PR_MD_MAP_RMDIR_ERROR(GetLastError());
return -1;
}
}
@@ -949,16 +978,16 @@ PRStatus
_PR_MD_LOCKFILE(PROsfd f)
{
PRStatus rc = PR_SUCCESS;
- DWORD rv;
+ DWORD rv;
- rv = LockFile( (HANDLE)f,
- 0l, 0l,
- 0x0l, 0xffffffffl );
- if ( rv == 0 ) {
+ rv = LockFile( (HANDLE)f,
+ 0l, 0l,
+ 0x0l, 0xffffffffl );
+ if ( rv == 0 ) {
DWORD err = GetLastError();
_PR_MD_MAP_DEFAULT_ERROR(err);
PR_LOG( _pr_io_lm, PR_LOG_ERROR,
- ("_PR_MD_LOCKFILE() failed. Error: %d", err ));
+ ("_PR_MD_LOCKFILE() failed. Error: %d", err ));
rc = PR_FAILURE;
}
@@ -976,30 +1005,32 @@ _PR_MD_TLOCKFILE(PROsfd f)
PRStatus
_PR_MD_UNLOCKFILE(PROsfd f)
{
- PRInt32 rv;
-
+ PRInt32 rv;
+
rv = UnlockFile( (HANDLE) f,
- 0l, 0l,
- 0x0l, 0xffffffffl );
-
+ 0l, 0l,
+ 0x0l, 0xffffffffl );
+
if ( rv )
{
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
else
{
- _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
- return PR_FAILURE;
+ _PR_MD_MAP_DEFAULT_ERROR(GetLastError());
+ return PR_FAILURE;
}
} /* end _PR_MD_UNLOCKFILE() */
PRInt32
_PR_MD_PIPEAVAILABLE(PRFileDesc *fd)
{
- if (NULL == fd)
- PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
- else
- PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+ if (NULL == fd) {
+ PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
+ }
+ else {
+ PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+ }
return -1;
}
@@ -1045,7 +1076,7 @@ _PR_MD_OPEN_FILE_UTF16(const PRUnichar *name, PRIntn osflags, int mode)
if (osflags & PR_CREATE_FILE) {
if (_PR_NT_MakeSecurityDescriptorACL(mode, fileAccessTable,
- &pSD, &pACL) == PR_SUCCESS) {
+ &pSD, &pACL) == PR_SUCCESS) {
sa.nLength = sizeof(sa);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = FALSE;
@@ -1053,25 +1084,34 @@ _PR_MD_OPEN_FILE_UTF16(const PRUnichar *name, PRIntn osflags, int mode)
}
}
- if (osflags & PR_SYNC) flag6 = FILE_FLAG_WRITE_THROUGH;
+ if (osflags & PR_SYNC) {
+ flag6 = FILE_FLAG_WRITE_THROUGH;
+ }
- if (osflags & PR_RDONLY || osflags & PR_RDWR)
+ if (osflags & PR_RDONLY || osflags & PR_RDWR) {
access |= GENERIC_READ;
- if (osflags & PR_WRONLY || osflags & PR_RDWR)
+ }
+ if (osflags & PR_WRONLY || osflags & PR_RDWR) {
access |= GENERIC_WRITE;
-
- if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL )
+ }
+
+ if ( osflags & PR_CREATE_FILE && osflags & PR_EXCL ) {
flags = CREATE_NEW;
+ }
else if (osflags & PR_CREATE_FILE) {
- if (osflags & PR_TRUNCATE)
+ if (osflags & PR_TRUNCATE) {
flags = CREATE_ALWAYS;
- else
+ }
+ else {
flags = OPEN_ALWAYS;
+ }
} else {
- if (osflags & PR_TRUNCATE)
+ if (osflags & PR_TRUNCATE) {
flags = TRUNCATE_EXISTING;
- else
+ }
+ else {
flags = OPEN_EXISTING;
+ }
}
file = createFileW(name,
@@ -1088,10 +1128,10 @@ _PR_MD_OPEN_FILE_UTF16(const PRUnichar *name, PRIntn osflags, int mode)
_PR_MD_MAP_OPEN_ERROR(GetLastError());
return -1;
}
-
+
return (PROsfd)file;
}
-
+
PRStatus
_PR_MD_OPEN_DIR_UTF16(_MDDirUTF16 *d, const PRUnichar *name)
{
@@ -1146,14 +1186,17 @@ _PR_MD_READ_DIR_UTF16(_MDDirUTF16 *d, PRIntn flags)
}
fileName = GetFileFromDIR(d);
if ( (flags & PR_SKIP_DOT) &&
- (fileName[0] == L'.') && (fileName[1] == L'\0'))
+ (fileName[0] == L'.') && (fileName[1] == L'\0')) {
continue;
+ }
if ( (flags & PR_SKIP_DOT_DOT) &&
(fileName[0] == L'.') && (fileName[1] == L'.') &&
- (fileName[2] == L'\0'))
+ (fileName[2] == L'\0')) {
continue;
- if ( (flags & PR_SKIP_HIDDEN) && FileIsHidden(d))
+ }
+ if ( (flags & PR_SKIP_HIDDEN) && FileIsHidden(d)) {
continue;
+ }
return fileName;
}
err = GetLastError();
@@ -1164,7 +1207,7 @@ _PR_MD_READ_DIR_UTF16(_MDDirUTF16 *d, PRIntn flags)
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return NULL;
}
-
+
PRInt32
_PR_MD_CLOSE_DIR_UTF16(_MDDirUTF16 *d)
{
@@ -1213,7 +1256,7 @@ IsRootDirectoryW(PRUnichar *fn, size_t buflen)
}
if (iswalpha(fn[0]) && fn[1] == L':' && _PR_IS_W_SLASH(fn[2])
- && fn[3] == L'\0') {
+ && fn[3] == L'\0') {
rv = getDriveTypeW(fn) > 1 ? PR_TRUE : PR_FALSE;
return rv;
}
@@ -1312,9 +1355,9 @@ _PR_MD_GETFILEINFO64_UTF16(const PRUnichar *fn, PRFileInfo64 *info)
if (NULL == wcspbrk(fn, L".\\/")) {
_PR_MD_MAP_OPENDIR_ERROR(GetLastError());
return -1;
- }
+ }
len = getFullPathNameW(fn, sizeof(pathbuf)/sizeof(pathbuf[0]), pathbuf,
- &filePart);
+ &filePart);
if (0 == len) {
_PR_MD_MAP_OPENDIR_ERROR(GetLastError());
return -1;
@@ -1360,11 +1403,11 @@ _PR_MD_GETFILEINFO64_UTF16(const PRUnichar *fn, PRFileInfo64 *info)
_PR_FileTimeToPRTime(&findFileData.ftLastWriteTime, &info->modifyTime);
if (0 == findFileData.ftCreationTime.dwLowDateTime &&
- 0 == findFileData.ftCreationTime.dwHighDateTime) {
+ 0 == findFileData.ftCreationTime.dwHighDateTime) {
info->creationTime = info->modifyTime;
} else {
_PR_FileTimeToPRTime(&findFileData.ftCreationTime,
- &info->creationTime);
+ &info->creationTime);
}
return 0;
diff --git a/nsprpub/pr/src/md/windows/w95sock.c b/nsprpub/pr/src/md/windows/w95sock.c
index c6a3ec111..7d7362c60 100644
--- a/nsprpub/pr/src/md/windows/w95sock.c
+++ b/nsprpub/pr/src/md/windows/w95sock.c
@@ -14,7 +14,7 @@
#define CONNECT_FD 3
static PRInt32 socket_io_wait(
- PROsfd osfd,
+ PROsfd osfd,
PRInt32 fd_type,
PRIntervalTime timeout);
@@ -51,7 +51,7 @@ _PR_MD_SOCKET(int af, int type, int flags)
sock = socket(af, type, flags);
- if (sock == INVALID_SOCKET )
+ if (sock == INVALID_SOCKET )
{
_PR_MD_MAP_SOCKET_ERROR(WSAGetLastError());
return (PROsfd)sock;
@@ -101,8 +101,9 @@ _MD_CloseSocket(PROsfd osfd)
PRInt32 rv;
rv = closesocket((SOCKET) osfd );
- if (rv < 0)
+ if (rv < 0) {
_PR_MD_MAP_CLOSE_ERROR(WSAGetLastError());
+ }
return rv;
}
@@ -120,8 +121,8 @@ _MD_SocketAvailable(PRFileDesc *fd)
}
PROsfd _MD_Accept(
- PRFileDesc *fd,
- PRNetAddr *raddr,
+ PRFileDesc *fd,
+ PRNetAddr *raddr,
PRUint32 *rlen,
PRIntervalTime timeout )
{
@@ -129,7 +130,7 @@ PROsfd _MD_Accept(
SOCKET sock;
PRInt32 rv, err;
- while ((sock = accept(osfd, (struct sockaddr *) raddr, rlen)) == -1)
+ while ((sock = accept(osfd, (struct sockaddr *) raddr, rlen)) == -1)
{
err = WSAGetLastError();
if ((err == WSAEWOULDBLOCK) && (!fd->secret->nonblocking))
@@ -149,14 +150,14 @@ PROsfd _MD_Accept(
} /* end _MD_accept() */
PRInt32
-_PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,
+_PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,
PRIntervalTime timeout)
{
PROsfd osfd = fd->secret->md.osfd;
PRInt32 rv;
int err;
- if ((rv = connect(osfd, (struct sockaddr *) addr, addrlen)) == -1)
+ if ((rv = connect(osfd, (struct sockaddr *) addr, addrlen)) == -1)
{
err = WSAGetLastError();
if ((!fd->secret->nonblocking) && (err == WSAEWOULDBLOCK))
@@ -171,7 +172,7 @@ _PR_MD_CONNECT(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen,
PR_ASSERT(rv > 0);
/* it's connected */
return(0);
- }
+ }
}
_PR_MD_MAP_CONNECT_ERROR(err);
}
@@ -209,7 +210,7 @@ _PR_MD_LISTEN(PRFileDesc *fd, PRIntn backlog)
}
PRInt32
-_PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
+_PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
PRIntervalTime timeout)
{
PROsfd osfd = fd->secret->md.osfd;
@@ -222,18 +223,18 @@ _PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
PR_ASSERT(PR_MSG_PEEK == flags);
osflags = MSG_PEEK;
}
- while ((rv = recv( osfd, buf, amount, osflags)) == -1)
+ while ((rv = recv( osfd, buf, amount, osflags)) == -1)
{
- if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
+ if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
&& (!fd->secret->nonblocking))
{
rv = socket_io_wait(osfd, READ_FD, timeout);
if ( rv < 0 )
{
return -1;
- }
- }
- else
+ }
+ }
+ else
{
_PR_MD_MAP_RECV_ERROR(err);
break;
@@ -250,11 +251,11 @@ _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
PRInt32 rv, err;
PRInt32 bytesSent = 0;
- while(bytesSent < amount )
+ while(bytesSent < amount )
{
- while ((rv = send( osfd, buf, amount, 0 )) == -1)
+ while ((rv = send( osfd, buf, amount, 0 )) == -1)
{
- if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
+ if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
&& (!fd->secret->nonblocking))
{
rv = socket_io_wait(osfd, WRITE_FD, timeout);
@@ -262,8 +263,8 @@ _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
{
return -1;
}
- }
- else
+ }
+ else
{
_PR_MD_MAP_SEND_ERROR(err);
return -1;
@@ -274,7 +275,7 @@ _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
{
break;
}
- if (bytesSent < amount)
+ if (bytesSent < amount)
{
rv = socket_io_wait(osfd, WRITE_FD, timeout);
if ( rv < 0 )
@@ -296,9 +297,9 @@ _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
do {
while ((rv = sendto( osfd, buf, amount, 0, (struct sockaddr *) addr,
- addrlen)) == -1)
+ addrlen)) == -1)
{
- if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
+ if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
&& (!fd->secret->nonblocking))
{
rv = socket_io_wait(osfd, WRITE_FD, timeout);
@@ -306,8 +307,8 @@ _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
{
return -1;
}
- }
- else
+ }
+ else
{
_PR_MD_MAP_SENDTO_ERROR(err);
return -1;
@@ -318,10 +319,10 @@ _PR_MD_SENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
{
break;
}
- if (bytesSent < amount)
+ if (bytesSent < amount)
{
rv = socket_io_wait(osfd, WRITE_FD, timeout);
- if (rv < 0)
+ if (rv < 0)
{
return -1;
}
@@ -361,8 +362,9 @@ static PRStatus PR_CALLBACK _pr_set_connectex(void)
/* Dummy socket needed for WSAIoctl */
sock = socket(AF_INET, SOCK_STREAM, 0);
- if (sock == INVALID_SOCKET)
+ if (sock == INVALID_SOCKET) {
return PR_SUCCESS;
+ }
GUID guid = WSAID_CONNECTEX;
rc = WSAIoctl(sock, SIO_GET_EXTENSION_FUNCTION_POINTER,
@@ -446,7 +448,7 @@ _PR_MD_TCPSENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
if (rv != 0) {
err = WSAGetLastError();
PR_LOG(_pr_io_lm, PR_LOG_MIN,
- ("_PR_MD_TCPSENDTO setting SO_UPDATE_CONNECT_CONTEXT failed %d\n", err));
+ ("_PR_MD_TCPSENDTO setting SO_UPDATE_CONNECT_CONTEXT failed %d\n", err));
_PR_MD_MAP_SETSOCKOPT_ERROR(err);
return -1;
}
@@ -472,7 +474,7 @@ _PR_MD_TCPSENDTO(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
* them during Fast Open or after connect. Therefore we can assumed
* this data already send. */
if (amount > 0) {
- return amount;
+ return amount;
}
_PR_MD_MAP_CONNECT_ERROR(WSAEWOULDBLOCK);
@@ -510,18 +512,18 @@ _PR_MD_RECVFROM(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
PRInt32 rv, err;
while ((rv = recvfrom( osfd, buf, amount, 0, (struct sockaddr *) addr,
- addrlen)) == -1)
+ addrlen)) == -1)
{
- if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
+ if (((err = WSAGetLastError()) == WSAEWOULDBLOCK)
&& (!fd->secret->nonblocking))
{
rv = socket_io_wait(osfd, READ_FD, timeout);
if ( rv < 0)
{
return -1;
- }
- }
- else
+ }
+ }
+ else
{
_PR_MD_MAP_RECVFROM_ERROR(err);
break;
@@ -537,12 +539,13 @@ _PR_MD_WRITEV(PRFileDesc *fd, const PRIOVec *iov, PRInt32 iov_size, PRIntervalTi
int sent = 0;
int rv;
- for (index=0; index < iov_size; index++)
+ for (index=0; index < iov_size; index++)
{
rv = _PR_MD_SEND(fd, iov[index].iov_base, iov[index].iov_len, 0, timeout);
- if (rv > 0)
+ if (rv > 0) {
sent += rv;
- if ( rv != iov[index].iov_len )
+ }
+ if ( rv != iov[index].iov_len )
{
if (rv < 0)
{
@@ -568,11 +571,12 @@ _PR_MD_WRITEV(PRFileDesc *fd, const PRIOVec *iov, PRInt32 iov_size, PRIntervalTi
PRInt32
_PR_MD_SHUTDOWN(PRFileDesc *fd, PRIntn how)
{
-PRInt32 rv;
+ PRInt32 rv;
rv = shutdown(fd->secret->md.osfd, how);
- if (rv < 0)
+ if (rv < 0) {
_PR_MD_MAP_SHUTDOWN_ERROR(WSAGetLastError());
+ }
return rv;
}
@@ -651,7 +655,7 @@ _MD_MakeNonblock(PRFileDesc *f)
#define _PR_INTERRUPT_CHECK_INTERVAL_SECS 5
static PRInt32 socket_io_wait(
- PROsfd osfd,
+ PROsfd osfd,
PRInt32 fd_type,
PRIntervalTime timeout)
{
@@ -709,15 +713,17 @@ static PRInt32 socket_io_wait(
{
len = sizeof(err);
if (getsockopt(osfd, SOL_SOCKET, SO_ERROR,
- (char *) &err, &len) == SOCKET_ERROR)
- {
+ (char *) &err, &len) == SOCKET_ERROR)
+ {
_PR_MD_MAP_GETSOCKOPT_ERROR(WSAGetLastError());
return -1;
}
- if (err != 0)
+ if (err != 0) {
_PR_MD_MAP_CONNECT_ERROR(err);
- else
+ }
+ else {
PR_SetError(PR_UNKNOWN_ERROR, 0);
+ }
return -1;
}
if (FD_ISSET((SOCKET)osfd, &rd_wr))
@@ -754,8 +760,8 @@ static PRInt32 socket_io_wait(
tv.tv_usec = 0;
} else {
tv.tv_usec = PR_IntervalToMicroseconds(
- remaining -
- PR_SecondsToInterval(tv.tv_sec));
+ remaining -
+ PR_SecondsToInterval(tv.tv_sec));
}
FD_SET(osfd, &rd_wr);
FD_SET(osfd, &ex);
@@ -789,15 +795,17 @@ static PRInt32 socket_io_wait(
{
len = sizeof(err);
if (getsockopt(osfd, SOL_SOCKET, SO_ERROR,
- (char *) &err, &len) == SOCKET_ERROR)
- {
+ (char *) &err, &len) == SOCKET_ERROR)
+ {
_PR_MD_MAP_GETSOCKOPT_ERROR(WSAGetLastError());
return -1;
}
- if (err != 0)
+ if (err != 0) {
_PR_MD_MAP_CONNECT_ERROR(err);
- else
+ }
+ else {
PR_SetError(PR_UNKNOWN_ERROR, 0);
+ }
return -1;
}
if (FD_ISSET((SOCKET)osfd, &rd_wr))
@@ -822,8 +830,8 @@ static PRInt32 socket_io_wait(
if (wait_for_remaining) {
elapsed = remaining;
} else {
- elapsed = PR_SecondsToInterval(tv.tv_sec)
- + PR_MicrosecondsToInterval(tv.tv_usec);
+ elapsed = PR_SecondsToInterval(tv.tv_sec)
+ + PR_MicrosecondsToInterval(tv.tv_usec);
}
if (elapsed >= remaining) {
PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
diff --git a/nsprpub/pr/src/md/windows/w95thred.c b/nsprpub/pr/src/md/windows/w95thred.c
index a365411f5..fb9c457d7 100644
--- a/nsprpub/pr/src/md/windows/w95thred.c
+++ b/nsprpub/pr/src/md/windows/w95thred.c
@@ -25,7 +25,7 @@ DWORD _pr_currentThreadIndex;
DWORD _pr_lastThreadIndex;
DWORD _pr_currentCPUIndex;
#endif
-int _pr_intsOff = 0;
+int _pr_intsOff = 0;
_PRInterruptTable _pr_interruptTable[] = { { 0 } };
typedef HRESULT (WINAPI *SETTHREADDESCRIPTION)(HANDLE, PCWSTR);
@@ -51,8 +51,8 @@ _PR_MD_EARLY_INIT()
if (hModule) {
sSetThreadDescription =
(SETTHREADDESCRIPTION) GetProcAddress(
- hModule,
- "SetThreadDescription");
+ hModule,
+ "SetThreadDescription");
}
}
@@ -108,13 +108,13 @@ _PR_MD_INIT_THREAD(PRThread *thread)
** the pseudo handle via DuplicateHandle(...)
*/
BOOL ok = DuplicateHandle(
- GetCurrentProcess(), /* Process of source handle */
- GetCurrentThread(), /* Pseudo Handle to dup */
- GetCurrentProcess(), /* Process of handle */
- &(thread->md.handle), /* resulting handle */
- 0L, /* access flags */
- FALSE, /* Inheritable */
- DUPLICATE_SAME_ACCESS); /* Options */
+ GetCurrentProcess(), /* Process of source handle */
+ GetCurrentThread(), /* Pseudo Handle to dup */
+ GetCurrentProcess(), /* Process of handle */
+ &(thread->md.handle), /* resulting handle */
+ 0L, /* access flags */
+ FALSE, /* Inheritable */
+ DUPLICATE_SAME_ACCESS); /* Options */
if (!ok) {
return PR_FAILURE;
}
@@ -124,10 +124,12 @@ _PR_MD_INIT_THREAD(PRThread *thread)
/* Create the blocking IO semaphore */
thread->md.blocked_sema = CreateSemaphore(NULL, 0, 1, NULL);
- if (thread->md.blocked_sema == NULL)
+ if (thread->md.blocked_sema == NULL) {
return PR_FAILURE;
- else
- return PR_SUCCESS;
+ }
+ else {
+ return PR_SUCCESS;
+ }
}
static unsigned __stdcall
@@ -138,23 +140,23 @@ pr_root(void *arg)
return 0;
}
-PRStatus
-_PR_MD_CREATE_THREAD(PRThread *thread,
- void (*start)(void *),
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize)
+PRStatus
+_PR_MD_CREATE_THREAD(PRThread *thread,
+ void (*start)(void *),
+ PRThreadPriority priority,
+ PRThreadScope scope,
+ PRThreadState state,
+ PRUint32 stackSize)
{
thread->md.start = start;
thread->md.handle = (HANDLE) _beginthreadex(
- NULL,
- thread->stack->stackSize,
- pr_root,
- (void *)thread,
- CREATE_SUSPENDED | STACK_SIZE_PARAM_IS_A_RESERVATION,
- &(thread->id));
+ NULL,
+ thread->stack->stackSize,
+ pr_root,
+ (void *)thread,
+ CREATE_SUSPENDED | STACK_SIZE_PARAM_IS_A_RESERVATION,
+ &(thread->id));
if(!thread->md.handle) {
return PR_FAILURE;
}
@@ -169,20 +171,21 @@ _PR_MD_CREATE_THREAD(PRThread *thread,
}
/* Activate the thread */
- if ( ResumeThread( thread->md.handle ) != -1)
+ if ( ResumeThread( thread->md.handle ) != -1) {
return PR_SUCCESS;
+ }
return PR_FAILURE;
}
-void
+void
_PR_MD_YIELD(void)
{
/* Can NT really yield at all? */
Sleep(0);
}
-void
+void
_PR_MD_SET_PRIORITY(_MDThread *thread, PRThreadPriority newPri)
{
int nativePri;
@@ -209,8 +212,8 @@ _PR_MD_SET_PRIORITY(_MDThread *thread, PRThreadPriority newPri)
rv = SetThreadPriority(thread->handle, nativePri);
PR_ASSERT(rv);
if (!rv) {
- PR_LOG(_pr_thread_lm, PR_LOG_MIN,
- ("PR_SetThreadPriority: can't set thread priority\n"));
+ PR_LOG(_pr_thread_lm, PR_LOG_MIN,
+ ("PR_SetThreadPriority: can't set thread priority\n"));
}
return;
}
@@ -220,10 +223,10 @@ const DWORD MS_VC_EXCEPTION = 0x406D1388;
#pragma pack(push,8)
typedef struct tagTHREADNAME_INFO
{
- DWORD dwType; // Must be 0x1000.
- LPCSTR szName; // Pointer to name (in user addr space).
- DWORD dwThreadID; // Thread ID (-1=caller thread).
- DWORD dwFlags; // Reserved for future use, must be zero.
+ DWORD dwType; // Must be 0x1000.
+ LPCSTR szName; // Pointer to name (in user addr space).
+ DWORD dwThreadID; // Thread ID (-1=caller thread).
+ DWORD dwFlags; // Reserved for future use, must be zero.
} THREADNAME_INFO;
#pragma pack(pop)
@@ -231,32 +234,33 @@ void
_PR_MD_SET_CURRENT_THREAD_NAME(const char *name)
{
#ifdef _MSC_VER
- THREADNAME_INFO info;
+ THREADNAME_INFO info;
#endif
- if (sSetThreadDescription) {
- WCHAR wideName[MAX_PATH];
- if (MultiByteToWideChar(CP_ACP, 0, name, -1, wideName, MAX_PATH)) {
- sSetThreadDescription(GetCurrentThread(), wideName);
- }
- }
+ if (sSetThreadDescription) {
+ WCHAR wideName[MAX_PATH];
+ if (MultiByteToWideChar(CP_ACP, 0, name, -1, wideName, MAX_PATH)) {
+ sSetThreadDescription(GetCurrentThread(), wideName);
+ }
+ }
#ifdef _MSC_VER
- if (!IsDebuggerPresent())
- return;
-
- info.dwType = 0x1000;
- info.szName = (char*) name;
- info.dwThreadID = -1;
- info.dwFlags = 0;
-
- __try {
- RaiseException(MS_VC_EXCEPTION,
- 0,
- sizeof(info) / sizeof(ULONG_PTR),
- (ULONG_PTR*)&info);
- } __except(EXCEPTION_CONTINUE_EXECUTION) {
- }
+ if (!IsDebuggerPresent()) {
+ return;
+ }
+
+ info.dwType = 0x1000;
+ info.szName = (char*) name;
+ info.dwThreadID = -1;
+ info.dwFlags = 0;
+
+ __try {
+ RaiseException(MS_VC_EXCEPTION,
+ 0,
+ sizeof(info) / sizeof(ULONG_PTR),
+ (ULONG_PTR*)&info);
+ } __except(EXCEPTION_CONTINUE_EXECUTION) {
+ }
#endif
}
@@ -317,16 +321,17 @@ PRInt32 _PR_MD_GETTHREADAFFINITYMASK(PRThread *thread, PRUint32 *mask)
DWORD_PTR system_mask;
rv = GetProcessAffinityMask(GetCurrentProcess(),
- &process_mask, &system_mask);
- if (rv)
+ &process_mask, &system_mask);
+ if (rv) {
*mask = (PRUint32)process_mask;
+ }
return rv?0:-1;
#endif
}
-void
-_PR_MD_SUSPEND_CPU(_PRCPU *cpu)
+void
+_PR_MD_SUSPEND_CPU(_PRCPU *cpu)
{
_PR_MD_SUSPEND_THREAD(cpu->thread);
}
@@ -363,14 +368,14 @@ _PR_MD_RESUME_THREAD(PRThread *thread)
PRThread*
_MD_CURRENT_THREAD(void)
{
-PRThread *thread;
+ PRThread *thread;
- thread = _MD_GET_ATTACHED_THREAD();
+ thread = _MD_GET_ATTACHED_THREAD();
- if (NULL == thread) {
- thread = _PRI_AttachThread(
- PR_USER_THREAD, PR_PRIORITY_NORMAL, NULL, 0);
- }
- PR_ASSERT(thread != NULL);
- return thread;
+ if (NULL == thread) {
+ thread = _PRI_AttachThread(
+ PR_USER_THREAD, PR_PRIORITY_NORMAL, NULL, 0);
+ }
+ PR_ASSERT(thread != NULL);
+ return thread;
}
diff --git a/nsprpub/pr/src/md/windows/win32_errors.c b/nsprpub/pr/src/md/windows/win32_errors.c
index 275792187..b0118146b 100644
--- a/nsprpub/pr/src/md/windows/win32_errors.c
+++ b/nsprpub/pr/src/md/windows/win32_errors.c
@@ -13,7 +13,7 @@
* - GetLastError(): for Win32 functions
* - WSAGetLastError(): for Winsock functions
* - errno: for standard C library functions
- *
+ *
* GetLastError() and WSAGetLastError() return error codes in
* non-overlapping ranges, so their error codes (ERROR_* and
* WSAE*) can be mapped by the same function. On the other hand,
@@ -61,7 +61,7 @@ void _MD_win32_map_default_error(PRInt32 err)
prError = PR_NOT_IMPLEMENTED_ERROR;
break;
case ERROR_DISK_CORRUPT:
- prError = PR_IO_ERROR;
+ prError = PR_IO_ERROR;
break;
case ERROR_DISK_FULL:
prError = PR_NO_DEVICE_SPACE_ERROR;
@@ -518,7 +518,7 @@ void _MD_win32_map_gethostname_error(PRInt32 err)
}
/* Win32 select() only works on sockets. So in this
-** context, WSAENOTSOCK is equivalent to EBADF on Unix.
+** context, WSAENOTSOCK is equivalent to EBADF on Unix.
*/
void _MD_win32_map_select_error(PRInt32 err)
{
diff --git a/nsprpub/pr/src/memory/prseg.c b/nsprpub/pr/src/memory/prseg.c
index ecad1d0ca..0b70f2d4e 100644
--- a/nsprpub/pr/src/memory/prseg.c
+++ b/nsprpub/pr/src/memory/prseg.c
@@ -18,7 +18,7 @@ void _PR_InitSegs(void)
void _PR_InitSegs(void)
{
- _PR_MD_INIT_SEGS();
+ _PR_MD_INIT_SEGS();
}
/*
@@ -31,20 +31,20 @@ PRSegment* _PR_NewSegment(PRUint32 size, void *vaddr)
{
PRSegment *seg;
- /* calloc the data structure for the segment */
+ /* calloc the data structure for the segment */
seg = PR_NEWZAP(PRSegment);
if (seg) {
- size = ((size + _pr_pageSize - 1) >> _pr_pageShift) << _pr_pageShift;
- /*
- ** Now, allocate the actual segment memory (or map under some OS)
- ** The OS specific code decides from where or how to allocate memory.
- */
- if (_PR_MD_ALLOC_SEGMENT(seg, size, vaddr) != PR_SUCCESS) {
- PR_DELETE(seg);
- return NULL;
- }
- }
+ size = ((size + _pr_pageSize - 1) >> _pr_pageShift) << _pr_pageShift;
+ /*
+ ** Now, allocate the actual segment memory (or map under some OS)
+ ** The OS specific code decides from where or how to allocate memory.
+ */
+ if (_PR_MD_ALLOC_SEGMENT(seg, size, vaddr) != PR_SUCCESS) {
+ PR_DELETE(seg);
+ return NULL;
+ }
+ }
return seg;
}
@@ -54,7 +54,7 @@ PRSegment* _PR_NewSegment(PRUint32 size, void *vaddr)
*/
void _PR_DestroySegment(PRSegment *seg)
{
- _PR_MD_FREE_SEGMENT(seg);
+ _PR_MD_FREE_SEGMENT(seg);
PR_DELETE(seg);
}
diff --git a/nsprpub/pr/src/memory/prshm.c b/nsprpub/pr/src/memory/prshm.c
index 59237e6e7..7a587cd5d 100644
--- a/nsprpub/pr/src/memory/prshm.c
+++ b/nsprpub/pr/src/memory/prshm.c
@@ -20,39 +20,39 @@ extern PRLogModuleInfo *_pr_shm_lm;
/* Posix implementation is in pr/src/md/unix/uxshm.c */
#elif defined PR_HAVE_WIN32_NAMED_SHARED_MEMORY
/* Win32 implementation is in pr/src/md/windows/w32shm.c */
-#else
-/*
-** there is no named_shared_memory
+#else
+/*
+** there is no named_shared_memory
*/
extern PRSharedMemory* _MD_OpenSharedMemory( const char *name, PRSize size, PRIntn flags, PRIntn mode )
{
PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
return NULL;
-}
+}
extern void * _MD_AttachSharedMemory( PRSharedMemory *shm, PRIntn flags )
{
PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
return NULL;
-}
+}
extern PRStatus _MD_DetachSharedMemory( PRSharedMemory *shm, void *addr )
{
PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
return PR_FAILURE;
-}
+}
extern PRStatus _MD_CloseSharedMemory( PRSharedMemory *shm )
{
PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
return PR_FAILURE;
-}
+}
extern PRStatus _MD_DeleteSharedMemory( const char *name )
{
PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
return PR_FAILURE;
-}
+}
#endif /* HAVE_SYSV_NAMED_SHARED_MEMORY */
/*
@@ -60,14 +60,16 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name )
**
*/
PR_IMPLEMENT( PRSharedMemory * )
- PR_OpenSharedMemory(
- const char *name,
- PRSize size,
- PRIntn flags,
- PRIntn mode
+PR_OpenSharedMemory(
+ const char *name,
+ PRSize size,
+ PRIntn flags,
+ PRIntn mode
)
{
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
return( _PR_MD_OPEN_SHARED_MEMORY( name, size, flags, mode ));
} /* end PR_OpenSharedMemory() */
@@ -76,9 +78,9 @@ PR_IMPLEMENT( PRSharedMemory * )
**
*/
PR_IMPLEMENT( void * )
- PR_AttachSharedMemory(
- PRSharedMemory *shm,
- PRIntn flags
+PR_AttachSharedMemory(
+ PRSharedMemory *shm,
+ PRIntn flags
)
{
return( _PR_MD_ATTACH_SHARED_MEMORY( shm, flags ));
@@ -89,9 +91,9 @@ PR_IMPLEMENT( void * )
**
*/
PR_IMPLEMENT( PRStatus )
- PR_DetachSharedMemory(
- PRSharedMemory *shm,
- void *addr
+PR_DetachSharedMemory(
+ PRSharedMemory *shm,
+ void *addr
)
{
return( _PR_MD_DETACH_SHARED_MEMORY( shm, addr ));
@@ -102,8 +104,8 @@ PR_IMPLEMENT( PRStatus )
**
*/
PR_IMPLEMENT( PRStatus )
- PR_CloseSharedMemory(
- PRSharedMemory *shm
+PR_CloseSharedMemory(
+ PRSharedMemory *shm
)
{
return( _PR_MD_CLOSE_SHARED_MEMORY( shm ));
@@ -114,11 +116,13 @@ PR_IMPLEMENT( PRStatus )
**
*/
PR_EXTERN( PRStatus )
- PR_DeleteSharedMemory(
- const char *name
+PR_DeleteSharedMemory(
+ const char *name
)
{
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
return(_PR_MD_DELETE_SHARED_MEMORY( name ));
} /* end PR_DestroySharedMemory() */
/* end prshm.c */
diff --git a/nsprpub/pr/src/memory/prshma.c b/nsprpub/pr/src/memory/prshma.c
index c73d7ec16..830b6df51 100644
--- a/nsprpub/pr/src/memory/prshma.c
+++ b/nsprpub/pr/src/memory/prshma.c
@@ -6,7 +6,7 @@
/*
** prshma.h -- NSPR Anonymous Shared Memory
**
-**
+**
*/
#include "primpl.h"
@@ -42,7 +42,7 @@ extern PRFileMap * _PR_MD_IMPORT_FILE_MAP_FROM_STRING(const char *fmstring)
PR_IMPLEMENT(PRFileMap*)
PR_OpenAnonFileMap(
const char *dirName,
- PRSize size,
+ PRSize size,
PRFileMapProtect prot
)
{
@@ -50,21 +50,21 @@ PR_OpenAnonFileMap(
} /* end PR_OpenAnonFileMap() */
/*
-** PR_ProcessAttrSetInheritableFileMap() -- Prepare FileMap for export
+** PR_ProcessAttrSetInheritableFileMap() -- Prepare FileMap for export
** to my children processes via PR_CreateProcess()
**
**
*/
-PR_IMPLEMENT( PRStatus)
-PR_ProcessAttrSetInheritableFileMap(
+PR_IMPLEMENT( PRStatus)
+PR_ProcessAttrSetInheritableFileMap(
PRProcessAttr *attr,
- PRFileMap *fm,
+ PRFileMap *fm,
const char *shmname
)
{
PR_SetError( PR_NOT_IMPLEMENTED_ERROR, 0 );
return( PR_FAILURE);
-} /* end PR_ProcessAttrSetInheritableFileMap() */
+} /* end PR_ProcessAttrSetInheritableFileMap() */
/*
** PR_GetInheritedFileMap() -- Import a PRFileMap previously exported
@@ -72,8 +72,8 @@ PR_ProcessAttrSetInheritableFileMap(
**
*/
PR_IMPLEMENT( PRFileMap *)
-PR_GetInheritedFileMap(
- const char *shmname
+PR_GetInheritedFileMap(
+ const char *shmname
)
{
PRFileMap *fm = NULL;
@@ -86,7 +86,7 @@ PR_GetInheritedFileMap(
**
*/
PR_IMPLEMENT( PRStatus )
-PR_ExportFileMapAsString(
+PR_ExportFileMapAsString(
PRFileMap *fm,
PRSize bufSize,
char *buf
@@ -101,7 +101,7 @@ PR_ExportFileMapAsString(
**
*/
PR_IMPLEMENT( PRFileMap * )
-PR_ImportFileMapFromString(
+PR_ImportFileMapFromString(
const char *fmstring
)
{
diff --git a/nsprpub/pr/src/misc/dtoa.c b/nsprpub/pr/src/misc/dtoa.c
index c39e8925e..43883aba2 100644
--- a/nsprpub/pr/src/misc/dtoa.c
+++ b/nsprpub/pr/src/misc/dtoa.c
@@ -18,13 +18,13 @@
***************************************************************/
/* Please send bug reports to David M. Gay (dmg at acm dot org,
- * with " at " changed at "@" and " dot " changed to "."). */
+ * with " at " changed at "@" and " dot " changed to "."). */
/* On a machine with IEEE extended-precision registers, it is
* necessary to specify double-precision (53-bit) rounding precision
* before invoking strtod or dtoa. If the machine uses (the equivalent
* of) Intel 80x87 arithmetic, the call
- * _control87(PC_53, MCW_PC);
+ * _control87(PC_53, MCW_PC);
* does this with many compilers. Whether this or another call is
* appropriate depends on the compiler; for this to work, it may be
* necessary to #include "float.h" or another system-dependent header
@@ -43,146 +43,146 @@
*
* Modifications:
*
- * 1. We only require IEEE, IBM, or VAX double-precision
- * arithmetic (not IEEE double-extended).
- * 2. We get by with floating-point arithmetic in a case that
- * Clinger missed -- when we're computing d * 10^n
- * for a small integer d and the integer n is not too
- * much larger than 22 (the maximum integer k for which
- * we can represent 10^k exactly), we may be able to
- * compute (d*10^k) * 10^(e-k) with just one roundoff.
- * 3. Rather than a bit-at-a-time adjustment of the binary
- * result in the hard case, we use floating-point
- * arithmetic to determine the adjustment to within
- * one bit; only in really hard cases do we need to
- * compute a second residual.
- * 4. Because of 3., we don't need a large table of powers of 10
- * for ten-to-e (just some small tables, e.g. of 10^k
- * for 0 <= k <= 22).
+ * 1. We only require IEEE, IBM, or VAX double-precision
+ * arithmetic (not IEEE double-extended).
+ * 2. We get by with floating-point arithmetic in a case that
+ * Clinger missed -- when we're computing d * 10^n
+ * for a small integer d and the integer n is not too
+ * much larger than 22 (the maximum integer k for which
+ * we can represent 10^k exactly), we may be able to
+ * compute (d*10^k) * 10^(e-k) with just one roundoff.
+ * 3. Rather than a bit-at-a-time adjustment of the binary
+ * result in the hard case, we use floating-point
+ * arithmetic to determine the adjustment to within
+ * one bit; only in really hard cases do we need to
+ * compute a second residual.
+ * 4. Because of 3., we don't need a large table of powers of 10
+ * for ten-to-e (just some small tables, e.g. of 10^k
+ * for 0 <= k <= 22).
*/
/*
* #define IEEE_8087 for IEEE-arithmetic machines where the least
- * significant byte has the lowest address.
+ * significant byte has the lowest address.
* #define IEEE_MC68k for IEEE-arithmetic machines where the most
- * significant byte has the lowest address.
+ * significant byte has the lowest address.
* #define Long int on machines with 32-bit ints and 64-bit longs.
* #define IBM for IBM mainframe-style floating-point arithmetic.
* #define VAX for VAX-style floating-point arithmetic (D_floating).
* #define No_leftright to omit left-right logic in fast floating-point
- * computation of dtoa. This will cause dtoa modes 4 and 5 to be
- * treated the same as modes 2 and 3 for some inputs.
+ * computation of dtoa. This will cause dtoa modes 4 and 5 to be
+ * treated the same as modes 2 and 3 for some inputs.
* #define Honor_FLT_ROUNDS if FLT_ROUNDS can assume the values 2 or 3
- * and strtod and dtoa should round accordingly. Unless Trust_FLT_ROUNDS
- * is also #defined, fegetround() will be queried for the rounding mode.
- * Note that both FLT_ROUNDS and fegetround() are specified by the C99
- * standard (and are specified to be consistent, with fesetround()
- * affecting the value of FLT_ROUNDS), but that some (Linux) systems
- * do not work correctly in this regard, so using fegetround() is more
- * portable than using FLT_ROUNDS directly.
+ * and strtod and dtoa should round accordingly. Unless Trust_FLT_ROUNDS
+ * is also #defined, fegetround() will be queried for the rounding mode.
+ * Note that both FLT_ROUNDS and fegetround() are specified by the C99
+ * standard (and are specified to be consistent, with fesetround()
+ * affecting the value of FLT_ROUNDS), but that some (Linux) systems
+ * do not work correctly in this regard, so using fegetround() is more
+ * portable than using FLT_ROUNDS directly.
* #define Check_FLT_ROUNDS if FLT_ROUNDS can assume the values 2 or 3
- * and Honor_FLT_ROUNDS is not #defined.
+ * and Honor_FLT_ROUNDS is not #defined.
* #define RND_PRODQUOT to use rnd_prod and rnd_quot (assembly routines
- * that use extended-precision instructions to compute rounded
- * products and quotients) with IBM.
+ * that use extended-precision instructions to compute rounded
+ * products and quotients) with IBM.
* #define ROUND_BIASED for IEEE-format with biased rounding and arithmetic
- * that rounds toward +Infinity.
+ * that rounds toward +Infinity.
* #define ROUND_BIASED_without_Round_Up for IEEE-format with biased
- * rounding when the underlying floating-point arithmetic uses
- * unbiased rounding. This prevent using ordinary floating-point
- * arithmetic when the result could be computed with one rounding error.
+ * rounding when the underlying floating-point arithmetic uses
+ * unbiased rounding. This prevent using ordinary floating-point
+ * arithmetic when the result could be computed with one rounding error.
* #define Inaccurate_Divide for IEEE-format with correctly rounded
- * products but inaccurate quotients, e.g., for Intel i860.
+ * products but inaccurate quotients, e.g., for Intel i860.
* #define NO_LONG_LONG on machines that do not have a "long long"
- * integer type (of >= 64 bits). On such machines, you can
- * #define Just_16 to store 16 bits per 32-bit Long when doing
- * high-precision integer arithmetic. Whether this speeds things
- * up or slows things down depends on the machine and the number
- * being converted. If long long is available and the name is
- * something other than "long long", #define Llong to be the name,
- * and if "unsigned Llong" does not work as an unsigned version of
- * Llong, #define #ULLong to be the corresponding unsigned type.
+ * integer type (of >= 64 bits). On such machines, you can
+ * #define Just_16 to store 16 bits per 32-bit Long when doing
+ * high-precision integer arithmetic. Whether this speeds things
+ * up or slows things down depends on the machine and the number
+ * being converted. If long long is available and the name is
+ * something other than "long long", #define Llong to be the name,
+ * and if "unsigned Llong" does not work as an unsigned version of
+ * Llong, #define #ULLong to be the corresponding unsigned type.
* #define KR_headers for old-style C function headers.
* #define Bad_float_h if your system lacks a float.h or if it does not
- * define some or all of DBL_DIG, DBL_MAX_10_EXP, DBL_MAX_EXP,
- * FLT_RADIX, FLT_ROUNDS, and DBL_MAX.
+ * define some or all of DBL_DIG, DBL_MAX_10_EXP, DBL_MAX_EXP,
+ * FLT_RADIX, FLT_ROUNDS, and DBL_MAX.
* #define MALLOC your_malloc, where your_malloc(n) acts like malloc(n)
- * if memory is available and otherwise does something you deem
- * appropriate. If MALLOC is undefined, malloc will be invoked
- * directly -- and assumed always to succeed. Similarly, if you
- * want something other than the system's free() to be called to
- * recycle memory acquired from MALLOC, #define FREE to be the
- * name of the alternate routine. (FREE or free is only called in
- * pathological cases, e.g., in a dtoa call after a dtoa return in
- * mode 3 with thousands of digits requested.)
+ * if memory is available and otherwise does something you deem
+ * appropriate. If MALLOC is undefined, malloc will be invoked
+ * directly -- and assumed always to succeed. Similarly, if you
+ * want something other than the system's free() to be called to
+ * recycle memory acquired from MALLOC, #define FREE to be the
+ * name of the alternate routine. (FREE or free is only called in
+ * pathological cases, e.g., in a dtoa call after a dtoa return in
+ * mode 3 with thousands of digits requested.)
* #define Omit_Private_Memory to omit logic (added Jan. 1998) for making
- * memory allocations from a private pool of memory when possible.
- * When used, the private pool is PRIVATE_MEM bytes long: 2304 bytes,
- * unless #defined to be a different length. This default length
- * suffices to get rid of MALLOC calls except for unusual cases,
- * such as decimal-to-binary conversion of a very long string of
- * digits. The longest string dtoa can return is about 751 bytes
- * long. For conversions by strtod of strings of 800 digits and
- * all dtoa conversions in single-threaded executions with 8-byte
- * pointers, PRIVATE_MEM >= 7400 appears to suffice; with 4-byte
- * pointers, PRIVATE_MEM >= 7112 appears adequate.
+ * memory allocations from a private pool of memory when possible.
+ * When used, the private pool is PRIVATE_MEM bytes long: 2304 bytes,
+ * unless #defined to be a different length. This default length
+ * suffices to get rid of MALLOC calls except for unusual cases,
+ * such as decimal-to-binary conversion of a very long string of
+ * digits. The longest string dtoa can return is about 751 bytes
+ * long. For conversions by strtod of strings of 800 digits and
+ * all dtoa conversions in single-threaded executions with 8-byte
+ * pointers, PRIVATE_MEM >= 7400 appears to suffice; with 4-byte
+ * pointers, PRIVATE_MEM >= 7112 appears adequate.
* #define NO_INFNAN_CHECK if you do not wish to have INFNAN_CHECK
- * #defined automatically on IEEE systems. On such systems,
- * when INFNAN_CHECK is #defined, strtod checks
- * for Infinity and NaN (case insensitively). On some systems
- * (e.g., some HP systems), it may be necessary to #define NAN_WORD0
- * appropriately -- to the most significant word of a quiet NaN.
- * (On HP Series 700/800 machines, -DNAN_WORD0=0x7ff40000 works.)
- * When INFNAN_CHECK is #defined and No_Hex_NaN is not #defined,
- * strtod also accepts (case insensitively) strings of the form
- * NaN(x), where x is a string of hexadecimal digits and spaces;
- * if there is only one string of hexadecimal digits, it is taken
- * for the 52 fraction bits of the resulting NaN; if there are two
- * or more strings of hex digits, the first is for the high 20 bits,
- * the second and subsequent for the low 32 bits, with intervening
- * white space ignored; but if this results in none of the 52
- * fraction bits being on (an IEEE Infinity symbol), then NAN_WORD0
- * and NAN_WORD1 are used instead.
+ * #defined automatically on IEEE systems. On such systems,
+ * when INFNAN_CHECK is #defined, strtod checks
+ * for Infinity and NaN (case insensitively). On some systems
+ * (e.g., some HP systems), it may be necessary to #define NAN_WORD0
+ * appropriately -- to the most significant word of a quiet NaN.
+ * (On HP Series 700/800 machines, -DNAN_WORD0=0x7ff40000 works.)
+ * When INFNAN_CHECK is #defined and No_Hex_NaN is not #defined,
+ * strtod also accepts (case insensitively) strings of the form
+ * NaN(x), where x is a string of hexadecimal digits and spaces;
+ * if there is only one string of hexadecimal digits, it is taken
+ * for the 52 fraction bits of the resulting NaN; if there are two
+ * or more strings of hex digits, the first is for the high 20 bits,
+ * the second and subsequent for the low 32 bits, with intervening
+ * white space ignored; but if this results in none of the 52
+ * fraction bits being on (an IEEE Infinity symbol), then NAN_WORD0
+ * and NAN_WORD1 are used instead.
* #define MULTIPLE_THREADS if the system offers preemptively scheduled
- * multiple threads. In this case, you must provide (or suitably
- * #define) two locks, acquired by ACQUIRE_DTOA_LOCK(n) and freed
- * by FREE_DTOA_LOCK(n) for n = 0 or 1. (The second lock, accessed
- * in pow5mult, ensures lazy evaluation of only one copy of high
- * powers of 5; omitting this lock would introduce a small
- * probability of wasting memory, but would otherwise be harmless.)
- * You must also invoke freedtoa(s) to free the value s returned by
- * dtoa. You may do so whether or not MULTIPLE_THREADS is #defined.
+ * multiple threads. In this case, you must provide (or suitably
+ * #define) two locks, acquired by ACQUIRE_DTOA_LOCK(n) and freed
+ * by FREE_DTOA_LOCK(n) for n = 0 or 1. (The second lock, accessed
+ * in pow5mult, ensures lazy evaluation of only one copy of high
+ * powers of 5; omitting this lock would introduce a small
+ * probability of wasting memory, but would otherwise be harmless.)
+ * You must also invoke freedtoa(s) to free the value s returned by
+ * dtoa. You may do so whether or not MULTIPLE_THREADS is #defined.
* #define NO_IEEE_Scale to disable new (Feb. 1997) logic in strtod that
- * avoids underflows on inputs whose result does not underflow.
- * If you #define NO_IEEE_Scale on a machine that uses IEEE-format
- * floating-point numbers and flushes underflows to zero rather
- * than implementing gradual underflow, then you must also #define
- * Sudden_Underflow.
+ * avoids underflows on inputs whose result does not underflow.
+ * If you #define NO_IEEE_Scale on a machine that uses IEEE-format
+ * floating-point numbers and flushes underflows to zero rather
+ * than implementing gradual underflow, then you must also #define
+ * Sudden_Underflow.
* #define USE_LOCALE to use the current locale's decimal_point value.
* #define SET_INEXACT if IEEE arithmetic is being used and extra
- * computation should be done to set the inexact flag when the
- * result is inexact and avoid setting inexact when the result
- * is exact. In this case, dtoa.c must be compiled in
- * an environment, perhaps provided by #include "dtoa.c" in a
- * suitable wrapper, that defines two functions,
- * int get_inexact(void);
- * void clear_inexact(void);
- * such that get_inexact() returns a nonzero value if the
- * inexact bit is already set, and clear_inexact() sets the
- * inexact bit to 0. When SET_INEXACT is #defined, strtod
- * also does extra computations to set the underflow and overflow
- * flags when appropriate (i.e., when the result is tiny and
- * inexact or when it is a numeric value rounded to +-infinity).
+ * computation should be done to set the inexact flag when the
+ * result is inexact and avoid setting inexact when the result
+ * is exact. In this case, dtoa.c must be compiled in
+ * an environment, perhaps provided by #include "dtoa.c" in a
+ * suitable wrapper, that defines two functions,
+ * int get_inexact(void);
+ * void clear_inexact(void);
+ * such that get_inexact() returns a nonzero value if the
+ * inexact bit is already set, and clear_inexact() sets the
+ * inexact bit to 0. When SET_INEXACT is #defined, strtod
+ * also does extra computations to set the underflow and overflow
+ * flags when appropriate (i.e., when the result is tiny and
+ * inexact or when it is a numeric value rounded to +-infinity).
* #define NO_ERRNO if strtod should not assign errno = ERANGE when
- * the result overflows to +-Infinity or underflows to 0.
+ * the result overflows to +-Infinity or underflows to 0.
* #define NO_HEX_FP to omit recognition of hexadecimal floating-point
- * values by strtod.
+ * values by strtod.
* #define NO_STRTOD_BIGCOMP (on IEEE-arithmetic systems only for now)
- * to disable logic for "fast" testing of very long input strings
- * to strtod. This testing proceeds by initially truncating the
- * input string, then if necessary comparing the whole string with
- * a decimal expansion to decide close cases. This logic is only
- * used for input more than STRTOD_DIGLIM digits long (default 40).
+ * to disable logic for "fast" testing of very long input strings
+ * to strtod. This testing proceeds by initially truncating the
+ * input string, then if necessary comparing the whole string with
+ * a decimal expansion to decide close cases. This logic is only
+ * used for input more than STRTOD_DIGLIM digits long (default 40).
*/
#ifndef Long
@@ -302,7 +302,10 @@ extern "C" {
Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined.
#endif
-typedef union { double d; ULong L[2]; } U;
+typedef union {
+ double d;
+ ULong L[2];
+} U;
#ifdef IEEE_8087
#define word0(x) (x)->L[1]
@@ -370,7 +373,7 @@ extern int strtod_diglim;
#define Int_max 14
#ifndef NO_IEEE_Scale
#define Avoid_Underflow
-#ifdef Flush_Denorm /* debugging option */
+#ifdef Flush_Denorm /* debugging option */
#undef Sudden_Underflow
#endif
#endif
@@ -411,7 +414,7 @@ extern int strtod_diglim;
#define Emin (-260)
#define Exp_1 0x41000000
#define Exp_11 0x41000000
-#define Ebits 8 /* exponent has 7 bits, but 8 is the right value in b2d */
+#define Ebits 8 /* exponent has 7 bits, but 8 is the right value in b2d */
#define Frac_mask 0xffffff
#define Frac_mask1 0xffffff
#define Bletch 4
@@ -487,8 +490,10 @@ extern double rnd_prod(double, double), rnd_quot(double, double);
#endif
typedef struct BCinfo BCinfo;
- struct
-BCinfo { int dp0, dp1, dplen, dsign, e0, inexact, nd, nd0, rounding, scale, uflchk; };
+struct
+ BCinfo {
+ int dp0, dp1, dplen, dsign, e0, inexact, nd, nd0, rounding, scale, uflchk;
+};
#ifdef KR_headers
#define FFFFFFFF ((((unsigned long)0xffff)<<16)|(unsigned long)0xffff)
@@ -506,7 +511,7 @@ BCinfo { int dp0, dp1, dplen, dsign, e0, inexact, nd, nd0, rounding, scale, uflc
* slower. Hence the default is now to store 32 bits per Long.
*/
#endif
-#else /* long long available */
+#else /* long long available */
#ifndef Llong
#define Llong long long
#endif
@@ -516,8 +521,8 @@ BCinfo { int dp0, dp1, dplen, dsign, e0, inexact, nd, nd0, rounding, scale, uflc
#endif /* NO_LONG_LONG */
#ifndef MULTIPLE_THREADS
-#define ACQUIRE_DTOA_LOCK(n) /*nothing*/
-#define FREE_DTOA_LOCK(n) /*nothing*/
+#define ACQUIRE_DTOA_LOCK(n) /*nothing*/
+#define FREE_DTOA_LOCK(n) /*nothing*/
#endif
#define Kmax 7
@@ -525,946 +530,981 @@ BCinfo { int dp0, dp1, dplen, dsign, e0, inexact, nd, nd0, rounding, scale, uflc
#ifdef __cplusplus
extern "C" double strtod(const char *s00, char **se);
extern "C" char *dtoa(double d, int mode, int ndigits,
- int *decpt, int *sign, char **rve);
+ int *decpt, int *sign, char **rve);
#endif
- struct
-Bigint {
- struct Bigint *next;
- int k, maxwds, sign, wds;
- ULong x[1];
- };
+struct
+ Bigint {
+ struct Bigint *next;
+ int k, maxwds, sign, wds;
+ ULong x[1];
+};
- typedef struct Bigint Bigint;
+typedef struct Bigint Bigint;
- static Bigint *freelist[Kmax+1];
+static Bigint *freelist[Kmax+1];
- static Bigint *
+static Bigint *
Balloc
#ifdef KR_headers
- (k) int k;
+(k) int k;
#else
- (int k)
+(int k)
#endif
{
- int x;
- Bigint *rv;
+ int x;
+ Bigint *rv;
#ifndef Omit_Private_Memory
- unsigned int len;
+ unsigned int len;
#endif
- ACQUIRE_DTOA_LOCK(0);
- /* The k > Kmax case does not need ACQUIRE_DTOA_LOCK(0), */
- /* but this case seems very unlikely. */
- if (k <= Kmax && (rv = freelist[k]))
- freelist[k] = rv->next;
- else {
- x = 1 << k;
+ ACQUIRE_DTOA_LOCK(0);
+ /* The k > Kmax case does not need ACQUIRE_DTOA_LOCK(0), */
+ /* but this case seems very unlikely. */
+ if (k <= Kmax && (rv = freelist[k])) {
+ freelist[k] = rv->next;
+ }
+ else {
+ x = 1 << k;
#ifdef Omit_Private_Memory
- rv = (Bigint *)MALLOC(sizeof(Bigint) + (x-1)*sizeof(ULong));
+ rv = (Bigint *)MALLOC(sizeof(Bigint) + (x-1)*sizeof(ULong));
#else
- len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1)
- /sizeof(double);
- if (k <= Kmax && pmem_next - private_mem + len <= PRIVATE_mem) {
- rv = (Bigint*)pmem_next;
- pmem_next += len;
- }
- else
- rv = (Bigint*)MALLOC(len*sizeof(double));
-#endif
- rv->k = k;
- rv->maxwds = x;
- }
- FREE_DTOA_LOCK(0);
- rv->sign = rv->wds = 0;
- return rv;
- }
-
- static void
+ len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1)
+ /sizeof(double);
+ if (k <= Kmax && pmem_next - private_mem + len <= PRIVATE_mem) {
+ rv = (Bigint*)pmem_next;
+ pmem_next += len;
+ }
+ else {
+ rv = (Bigint*)MALLOC(len*sizeof(double));
+ }
+#endif
+ rv->k = k;
+ rv->maxwds = x;
+ }
+ FREE_DTOA_LOCK(0);
+ rv->sign = rv->wds = 0;
+ return rv;
+}
+
+static void
Bfree
#ifdef KR_headers
- (v) Bigint *v;
+(v) Bigint *v;
#else
- (Bigint *v)
+(Bigint *v)
#endif
{
- if (v) {
- if (v->k > Kmax)
+ if (v) {
+ if (v->k > Kmax)
#ifdef FREE
- FREE((void*)v);
+ FREE((void*)v);
#else
- free((void*)v);
-#endif
- else {
- ACQUIRE_DTOA_LOCK(0);
- v->next = freelist[v->k];
- freelist[v->k] = v;
- FREE_DTOA_LOCK(0);
- }
- }
- }
+ free((void*)v);
+#endif
+ else {
+ ACQUIRE_DTOA_LOCK(0);
+ v->next = freelist[v->k];
+ freelist[v->k] = v;
+ FREE_DTOA_LOCK(0);
+ }
+ }
+}
#define Bcopy(x,y) memcpy((char *)&x->sign, (char *)&y->sign, \
y->wds*sizeof(Long) + 2*sizeof(int))
- static Bigint *
+static Bigint *
multadd
#ifdef KR_headers
- (b, m, a) Bigint *b; int m, a;
+(b, m, a) Bigint *b; int m, a;
#else
- (Bigint *b, int m, int a) /* multiply by m and add a */
+(Bigint *b, int m, int a) /* multiply by m and add a */
#endif
{
- int i, wds;
+ int i, wds;
#ifdef ULLong
- ULong *x;
- ULLong carry, y;
+ ULong *x;
+ ULLong carry, y;
#else
- ULong carry, *x, y;
+ ULong carry, *x, y;
#ifdef Pack_32
- ULong xi, z;
+ ULong xi, z;
#endif
#endif
- Bigint *b1;
+ Bigint *b1;
- wds = b->wds;
- x = b->x;
- i = 0;
- carry = a;
- do {
+ wds = b->wds;
+ x = b->x;
+ i = 0;
+ carry = a;
+ do {
#ifdef ULLong
- y = *x * (ULLong)m + carry;
- carry = y >> 32;
- *x++ = y & FFFFFFFF;
+ y = *x * (ULLong)m + carry;
+ carry = y >> 32;
+ *x++ = y & FFFFFFFF;
#else
#ifdef Pack_32
- xi = *x;
- y = (xi & 0xffff) * m + carry;
- z = (xi >> 16) * m + (y >> 16);
- carry = z >> 16;
- *x++ = (z << 16) + (y & 0xffff);
+ xi = *x;
+ y = (xi & 0xffff) * m + carry;
+ z = (xi >> 16) * m + (y >> 16);
+ carry = z >> 16;
+ *x++ = (z << 16) + (y & 0xffff);
#else
- y = *x * m + carry;
- carry = y >> 16;
- *x++ = y & 0xffff;
-#endif
-#endif
- }
- while(++i < wds);
- if (carry) {
- if (wds >= b->maxwds) {
- b1 = Balloc(b->k+1);
- Bcopy(b1, b);
- Bfree(b);
- b = b1;
- }
- b->x[wds++] = carry;
- b->wds = wds;
- }
- return b;
- }
-
- static Bigint *
+ y = *x * m + carry;
+ carry = y >> 16;
+ *x++ = y & 0xffff;
+#endif
+#endif
+ }
+ while(++i < wds);
+ if (carry) {
+ if (wds >= b->maxwds) {
+ b1 = Balloc(b->k+1);
+ Bcopy(b1, b);
+ Bfree(b);
+ b = b1;
+ }
+ b->x[wds++] = carry;
+ b->wds = wds;
+ }
+ return b;
+}
+
+static Bigint *
s2b
#ifdef KR_headers
- (s, nd0, nd, y9, dplen) CONST char *s; int nd0, nd, dplen; ULong y9;
+(s, nd0, nd, y9, dplen) CONST char *s; int nd0, nd, dplen; ULong y9;
#else
- (const char *s, int nd0, int nd, ULong y9, int dplen)
+(const char *s, int nd0, int nd, ULong y9, int dplen)
#endif
{
- Bigint *b;
- int i, k;
- Long x, y;
+ Bigint *b;
+ int i, k;
+ Long x, y;
- x = (nd + 8) / 9;
- for(k = 0, y = 1; x > y; y <<= 1, k++) ;
+ x = (nd + 8) / 9;
+ for(k = 0, y = 1; x > y; y <<= 1, k++) ;
#ifdef Pack_32
- b = Balloc(k);
- b->x[0] = y9;
- b->wds = 1;
+ b = Balloc(k);
+ b->x[0] = y9;
+ b->wds = 1;
#else
- b = Balloc(k+1);
- b->x[0] = y9 & 0xffff;
- b->wds = (b->x[1] = y9 >> 16) ? 2 : 1;
-#endif
-
- i = 9;
- if (9 < nd0) {
- s += 9;
- do b = multadd(b, 10, *s++ - '0');
- while(++i < nd0);
- s += dplen;
- }
- else
- s += dplen + 9;
- for(; i < nd; i++)
- b = multadd(b, 10, *s++ - '0');
- return b;
- }
-
- static int
+ b = Balloc(k+1);
+ b->x[0] = y9 & 0xffff;
+ b->wds = (b->x[1] = y9 >> 16) ? 2 : 1;
+#endif
+
+ i = 9;
+ if (9 < nd0) {
+ s += 9;
+ do {
+ b = multadd(b, 10, *s++ - '0');
+ }
+ while(++i < nd0);
+ s += dplen;
+ }
+ else {
+ s += dplen + 9;
+ }
+ for(; i < nd; i++) {
+ b = multadd(b, 10, *s++ - '0');
+ }
+ return b;
+}
+
+static int
hi0bits
#ifdef KR_headers
- (x) ULong x;
+(x) ULong x;
#else
- (ULong x)
+(ULong x)
#endif
{
- int k = 0;
-
- if (!(x & 0xffff0000)) {
- k = 16;
- x <<= 16;
- }
- if (!(x & 0xff000000)) {
- k += 8;
- x <<= 8;
- }
- if (!(x & 0xf0000000)) {
- k += 4;
- x <<= 4;
- }
- if (!(x & 0xc0000000)) {
- k += 2;
- x <<= 2;
- }
- if (!(x & 0x80000000)) {
- k++;
- if (!(x & 0x40000000))
- return 32;
- }
- return k;
- }
-
- static int
+ int k = 0;
+
+ if (!(x & 0xffff0000)) {
+ k = 16;
+ x <<= 16;
+ }
+ if (!(x & 0xff000000)) {
+ k += 8;
+ x <<= 8;
+ }
+ if (!(x & 0xf0000000)) {
+ k += 4;
+ x <<= 4;
+ }
+ if (!(x & 0xc0000000)) {
+ k += 2;
+ x <<= 2;
+ }
+ if (!(x & 0x80000000)) {
+ k++;
+ if (!(x & 0x40000000)) {
+ return 32;
+ }
+ }
+ return k;
+}
+
+static int
lo0bits
#ifdef KR_headers
- (y) ULong *y;
+(y) ULong *y;
#else
- (ULong *y)
+(ULong *y)
#endif
{
- int k;
- ULong x = *y;
-
- if (x & 7) {
- if (x & 1)
- return 0;
- if (x & 2) {
- *y = x >> 1;
- return 1;
- }
- *y = x >> 2;
- return 2;
- }
- k = 0;
- if (!(x & 0xffff)) {
- k = 16;
- x >>= 16;
- }
- if (!(x & 0xff)) {
- k += 8;
- x >>= 8;
- }
- if (!(x & 0xf)) {
- k += 4;
- x >>= 4;
- }
- if (!(x & 0x3)) {
- k += 2;
- x >>= 2;
- }
- if (!(x & 1)) {
- k++;
- x >>= 1;
- if (!x)
- return 32;
- }
- *y = x;
- return k;
- }
-
- static Bigint *
+ int k;
+ ULong x = *y;
+
+ if (x & 7) {
+ if (x & 1) {
+ return 0;
+ }
+ if (x & 2) {
+ *y = x >> 1;
+ return 1;
+ }
+ *y = x >> 2;
+ return 2;
+ }
+ k = 0;
+ if (!(x & 0xffff)) {
+ k = 16;
+ x >>= 16;
+ }
+ if (!(x & 0xff)) {
+ k += 8;
+ x >>= 8;
+ }
+ if (!(x & 0xf)) {
+ k += 4;
+ x >>= 4;
+ }
+ if (!(x & 0x3)) {
+ k += 2;
+ x >>= 2;
+ }
+ if (!(x & 1)) {
+ k++;
+ x >>= 1;
+ if (!x) {
+ return 32;
+ }
+ }
+ *y = x;
+ return k;
+}
+
+static Bigint *
i2b
#ifdef KR_headers
- (i) int i;
+(i) int i;
#else
- (int i)
+(int i)
#endif
{
- Bigint *b;
+ Bigint *b;
- b = Balloc(1);
- b->x[0] = i;
- b->wds = 1;
- return b;
- }
+ b = Balloc(1);
+ b->x[0] = i;
+ b->wds = 1;
+ return b;
+}
- static Bigint *
+static Bigint *
mult
#ifdef KR_headers
- (a, b) Bigint *a, *b;
+(a, b) Bigint *a, *b;
#else
- (Bigint *a, Bigint *b)
+(Bigint *a, Bigint *b)
#endif
{
- Bigint *c;
- int k, wa, wb, wc;
- ULong *x, *xa, *xae, *xb, *xbe, *xc, *xc0;
- ULong y;
+ Bigint *c;
+ int k, wa, wb, wc;
+ ULong *x, *xa, *xae, *xb, *xbe, *xc, *xc0;
+ ULong y;
#ifdef ULLong
- ULLong carry, z;
+ ULLong carry, z;
#else
- ULong carry, z;
+ ULong carry, z;
#ifdef Pack_32
- ULong z2;
-#endif
-#endif
-
- if (a->wds < b->wds) {
- c = a;
- a = b;
- b = c;
- }
- k = a->k;
- wa = a->wds;
- wb = b->wds;
- wc = wa + wb;
- if (wc > a->maxwds)
- k++;
- c = Balloc(k);
- for(x = c->x, xa = x + wc; x < xa; x++)
- *x = 0;
- xa = a->x;
- xae = xa + wa;
- xb = b->x;
- xbe = xb + wb;
- xc0 = c->x;
+ ULong z2;
+#endif
+#endif
+
+ if (a->wds < b->wds) {
+ c = a;
+ a = b;
+ b = c;
+ }
+ k = a->k;
+ wa = a->wds;
+ wb = b->wds;
+ wc = wa + wb;
+ if (wc > a->maxwds) {
+ k++;
+ }
+ c = Balloc(k);
+ for(x = c->x, xa = x + wc; x < xa; x++) {
+ *x = 0;
+ }
+ xa = a->x;
+ xae = xa + wa;
+ xb = b->x;
+ xbe = xb + wb;
+ xc0 = c->x;
#ifdef ULLong
- for(; xb < xbe; xc0++) {
- if ((y = *xb++)) {
- x = xa;
- xc = xc0;
- carry = 0;
- do {
- z = *x++ * (ULLong)y + *xc + carry;
- carry = z >> 32;
- *xc++ = z & FFFFFFFF;
- }
- while(x < xae);
- *xc = carry;
- }
- }
+ for(; xb < xbe; xc0++) {
+ if ((y = *xb++)) {
+ x = xa;
+ xc = xc0;
+ carry = 0;
+ do {
+ z = *x++ * (ULLong)y + *xc + carry;
+ carry = z >> 32;
+ *xc++ = z & FFFFFFFF;
+ }
+ while(x < xae);
+ *xc = carry;
+ }
+ }
#else
#ifdef Pack_32
- for(; xb < xbe; xb++, xc0++) {
- if (y = *xb & 0xffff) {
- x = xa;
- xc = xc0;
- carry = 0;
- do {
- z = (*x & 0xffff) * y + (*xc & 0xffff) + carry;
- carry = z >> 16;
- z2 = (*x++ >> 16) * y + (*xc >> 16) + carry;
- carry = z2 >> 16;
- Storeinc(xc, z2, z);
- }
- while(x < xae);
- *xc = carry;
- }
- if (y = *xb >> 16) {
- x = xa;
- xc = xc0;
- carry = 0;
- z2 = *xc;
- do {
- z = (*x & 0xffff) * y + (*xc >> 16) + carry;
- carry = z >> 16;
- Storeinc(xc, z, z2);
- z2 = (*x++ >> 16) * y + (*xc & 0xffff) + carry;
- carry = z2 >> 16;
- }
- while(x < xae);
- *xc = z2;
- }
- }
+ for(; xb < xbe; xb++, xc0++) {
+ if (y = *xb & 0xffff) {
+ x = xa;
+ xc = xc0;
+ carry = 0;
+ do {
+ z = (*x & 0xffff) * y + (*xc & 0xffff) + carry;
+ carry = z >> 16;
+ z2 = (*x++ >> 16) * y + (*xc >> 16) + carry;
+ carry = z2 >> 16;
+ Storeinc(xc, z2, z);
+ }
+ while(x < xae);
+ *xc = carry;
+ }
+ if (y = *xb >> 16) {
+ x = xa;
+ xc = xc0;
+ carry = 0;
+ z2 = *xc;
+ do {
+ z = (*x & 0xffff) * y + (*xc >> 16) + carry;
+ carry = z >> 16;
+ Storeinc(xc, z, z2);
+ z2 = (*x++ >> 16) * y + (*xc & 0xffff) + carry;
+ carry = z2 >> 16;
+ }
+ while(x < xae);
+ *xc = z2;
+ }
+ }
#else
- for(; xb < xbe; xc0++) {
- if (y = *xb++) {
- x = xa;
- xc = xc0;
- carry = 0;
- do {
- z = *x++ * y + *xc + carry;
- carry = z >> 16;
- *xc++ = z & 0xffff;
- }
- while(x < xae);
- *xc = carry;
- }
- }
-#endif
-#endif
- for(xc0 = c->x, xc = xc0 + wc; wc > 0 && !*--xc; --wc) ;
- c->wds = wc;
- return c;
- }
-
- static Bigint *p5s;
-
- static Bigint *
+ for(; xb < xbe; xc0++) {
+ if (y = *xb++) {
+ x = xa;
+ xc = xc0;
+ carry = 0;
+ do {
+ z = *x++ * y + *xc + carry;
+ carry = z >> 16;
+ *xc++ = z & 0xffff;
+ }
+ while(x < xae);
+ *xc = carry;
+ }
+ }
+#endif
+#endif
+ for(xc0 = c->x, xc = xc0 + wc; wc > 0 && !*--xc; --wc) ;
+ c->wds = wc;
+ return c;
+}
+
+static Bigint *p5s;
+
+static Bigint *
pow5mult
#ifdef KR_headers
- (b, k) Bigint *b; int k;
+(b, k) Bigint *b; int k;
#else
- (Bigint *b, int k)
+(Bigint *b, int k)
#endif
{
- Bigint *b1, *p5, *p51;
- int i;
- static int p05[3] = { 5, 25, 125 };
-
- if ((i = k & 3))
- b = multadd(b, p05[i-1], 0);
-
- if (!(k >>= 2))
- return b;
- if (!(p5 = p5s)) {
- /* first time */
+ Bigint *b1, *p5, *p51;
+ int i;
+ static int p05[3] = { 5, 25, 125 };
+
+ if ((i = k & 3)) {
+ b = multadd(b, p05[i-1], 0);
+ }
+
+ if (!(k >>= 2)) {
+ return b;
+ }
+ if (!(p5 = p5s)) {
+ /* first time */
#ifdef MULTIPLE_THREADS
- ACQUIRE_DTOA_LOCK(1);
- if (!(p5 = p5s)) {
- p5 = p5s = i2b(625);
- p5->next = 0;
- }
- FREE_DTOA_LOCK(1);
+ ACQUIRE_DTOA_LOCK(1);
+ if (!(p5 = p5s)) {
+ p5 = p5s = i2b(625);
+ p5->next = 0;
+ }
+ FREE_DTOA_LOCK(1);
#else
- p5 = p5s = i2b(625);
- p5->next = 0;
-#endif
- }
- for(;;) {
- if (k & 1) {
- b1 = mult(b, p5);
- Bfree(b);
- b = b1;
- }
- if (!(k >>= 1))
- break;
- if (!(p51 = p5->next)) {
+ p5 = p5s = i2b(625);
+ p5->next = 0;
+#endif
+ }
+ for(;;) {
+ if (k & 1) {
+ b1 = mult(b, p5);
+ Bfree(b);
+ b = b1;
+ }
+ if (!(k >>= 1)) {
+ break;
+ }
+ if (!(p51 = p5->next)) {
#ifdef MULTIPLE_THREADS
- ACQUIRE_DTOA_LOCK(1);
- if (!(p51 = p5->next)) {
- p51 = p5->next = mult(p5,p5);
- p51->next = 0;
- }
- FREE_DTOA_LOCK(1);
+ ACQUIRE_DTOA_LOCK(1);
+ if (!(p51 = p5->next)) {
+ p51 = p5->next = mult(p5,p5);
+ p51->next = 0;
+ }
+ FREE_DTOA_LOCK(1);
#else
- p51 = p5->next = mult(p5,p5);
- p51->next = 0;
+ p51 = p5->next = mult(p5,p5);
+ p51->next = 0;
#endif
- }
- p5 = p51;
- }
- return b;
- }
+ }
+ p5 = p51;
+ }
+ return b;
+}
- static Bigint *
+static Bigint *
lshift
#ifdef KR_headers
- (b, k) Bigint *b; int k;
+(b, k) Bigint *b; int k;
#else
- (Bigint *b, int k)
+(Bigint *b, int k)
#endif
{
- int i, k1, n, n1;
- Bigint *b1;
- ULong *x, *x1, *xe, z;
+ int i, k1, n, n1;
+ Bigint *b1;
+ ULong *x, *x1, *xe, z;
#ifdef Pack_32
- n = k >> 5;
+ n = k >> 5;
#else
- n = k >> 4;
-#endif
- k1 = b->k;
- n1 = n + b->wds + 1;
- for(i = b->maxwds; n1 > i; i <<= 1)
- k1++;
- b1 = Balloc(k1);
- x1 = b1->x;
- for(i = 0; i < n; i++)
- *x1++ = 0;
- x = b->x;
- xe = x + b->wds;
+ n = k >> 4;
+#endif
+ k1 = b->k;
+ n1 = n + b->wds + 1;
+ for(i = b->maxwds; n1 > i; i <<= 1) {
+ k1++;
+ }
+ b1 = Balloc(k1);
+ x1 = b1->x;
+ for(i = 0; i < n; i++) {
+ *x1++ = 0;
+ }
+ x = b->x;
+ xe = x + b->wds;
#ifdef Pack_32
- if (k &= 0x1f) {
- k1 = 32 - k;
- z = 0;
- do {
- *x1++ = *x << k | z;
- z = *x++ >> k1;
- }
- while(x < xe);
- if ((*x1 = z))
- ++n1;
- }
+ if (k &= 0x1f) {
+ k1 = 32 - k;
+ z = 0;
+ do {
+ *x1++ = *x << k | z;
+ z = *x++ >> k1;
+ }
+ while(x < xe);
+ if ((*x1 = z)) {
+ ++n1;
+ }
+ }
#else
- if (k &= 0xf) {
- k1 = 16 - k;
- z = 0;
- do {
- *x1++ = *x << k & 0xffff | z;
- z = *x++ >> k1;
- }
- while(x < xe);
- if (*x1 = z)
- ++n1;
- }
-#endif
- else do
- *x1++ = *x++;
- while(x < xe);
- b1->wds = n1 - 1;
- Bfree(b);
- return b1;
- }
-
- static int
+ if (k &= 0xf) {
+ k1 = 16 - k;
+ z = 0;
+ do {
+ *x1++ = *x << k & 0xffff | z;
+ z = *x++ >> k1;
+ }
+ while(x < xe);
+ if (*x1 = z) {
+ ++n1;
+ }
+ }
+#endif
+ else do {
+ *x1++ = *x++;
+ }
+ while(x < xe);
+ b1->wds = n1 - 1;
+ Bfree(b);
+ return b1;
+}
+
+static int
cmp
#ifdef KR_headers
- (a, b) Bigint *a, *b;
+(a, b) Bigint *a, *b;
#else
- (Bigint *a, Bigint *b)
+(Bigint *a, Bigint *b)
#endif
{
- ULong *xa, *xa0, *xb, *xb0;
- int i, j;
+ ULong *xa, *xa0, *xb, *xb0;
+ int i, j;
- i = a->wds;
- j = b->wds;
+ i = a->wds;
+ j = b->wds;
#ifdef DEBUG
- if (i > 1 && !a->x[i-1])
- Bug("cmp called with a->x[a->wds-1] == 0");
- if (j > 1 && !b->x[j-1])
- Bug("cmp called with b->x[b->wds-1] == 0");
-#endif
- if (i -= j)
- return i;
- xa0 = a->x;
- xa = xa0 + j;
- xb0 = b->x;
- xb = xb0 + j;
- for(;;) {
- if (*--xa != *--xb)
- return *xa < *xb ? -1 : 1;
- if (xa <= xa0)
- break;
- }
- return 0;
- }
-
- static Bigint *
+ if (i > 1 && !a->x[i-1]) {
+ Bug("cmp called with a->x[a->wds-1] == 0");
+ }
+ if (j > 1 && !b->x[j-1]) {
+ Bug("cmp called with b->x[b->wds-1] == 0");
+ }
+#endif
+ if (i -= j) {
+ return i;
+ }
+ xa0 = a->x;
+ xa = xa0 + j;
+ xb0 = b->x;
+ xb = xb0 + j;
+ for(;;) {
+ if (*--xa != *--xb) {
+ return *xa < *xb ? -1 : 1;
+ }
+ if (xa <= xa0) {
+ break;
+ }
+ }
+ return 0;
+}
+
+static Bigint *
diff
#ifdef KR_headers
- (a, b) Bigint *a, *b;
+(a, b) Bigint *a, *b;
#else
- (Bigint *a, Bigint *b)
+(Bigint *a, Bigint *b)
#endif
{
- Bigint *c;
- int i, wa, wb;
- ULong *xa, *xae, *xb, *xbe, *xc;
+ Bigint *c;
+ int i, wa, wb;
+ ULong *xa, *xae, *xb, *xbe, *xc;
#ifdef ULLong
- ULLong borrow, y;
+ ULLong borrow, y;
#else
- ULong borrow, y;
+ ULong borrow, y;
#ifdef Pack_32
- ULong z;
-#endif
-#endif
-
- i = cmp(a,b);
- if (!i) {
- c = Balloc(0);
- c->wds = 1;
- c->x[0] = 0;
- return c;
- }
- if (i < 0) {
- c = a;
- a = b;
- b = c;
- i = 1;
- }
- else
- i = 0;
- c = Balloc(a->k);
- c->sign = i;
- wa = a->wds;
- xa = a->x;
- xae = xa + wa;
- wb = b->wds;
- xb = b->x;
- xbe = xb + wb;
- xc = c->x;
- borrow = 0;
+ ULong z;
+#endif
+#endif
+
+ i = cmp(a,b);
+ if (!i) {
+ c = Balloc(0);
+ c->wds = 1;
+ c->x[0] = 0;
+ return c;
+ }
+ if (i < 0) {
+ c = a;
+ a = b;
+ b = c;
+ i = 1;
+ }
+ else {
+ i = 0;
+ }
+ c = Balloc(a->k);
+ c->sign = i;
+ wa = a->wds;
+ xa = a->x;
+ xae = xa + wa;
+ wb = b->wds;
+ xb = b->x;
+ xbe = xb + wb;
+ xc = c->x;
+ borrow = 0;
#ifdef ULLong
- do {
- y = (ULLong)*xa++ - *xb++ - borrow;
- borrow = y >> 32 & (ULong)1;
- *xc++ = y & FFFFFFFF;
- }
- while(xb < xbe);
- while(xa < xae) {
- y = *xa++ - borrow;
- borrow = y >> 32 & (ULong)1;
- *xc++ = y & FFFFFFFF;
- }
+ do {
+ y = (ULLong)*xa++ - *xb++ - borrow;
+ borrow = y >> 32 & (ULong)1;
+ *xc++ = y & FFFFFFFF;
+ }
+ while(xb < xbe);
+ while(xa < xae) {
+ y = *xa++ - borrow;
+ borrow = y >> 32 & (ULong)1;
+ *xc++ = y & FFFFFFFF;
+ }
#else
#ifdef Pack_32
- do {
- y = (*xa & 0xffff) - (*xb & 0xffff) - borrow;
- borrow = (y & 0x10000) >> 16;
- z = (*xa++ >> 16) - (*xb++ >> 16) - borrow;
- borrow = (z & 0x10000) >> 16;
- Storeinc(xc, z, y);
- }
- while(xb < xbe);
- while(xa < xae) {
- y = (*xa & 0xffff) - borrow;
- borrow = (y & 0x10000) >> 16;
- z = (*xa++ >> 16) - borrow;
- borrow = (z & 0x10000) >> 16;
- Storeinc(xc, z, y);
- }
+ do {
+ y = (*xa & 0xffff) - (*xb & 0xffff) - borrow;
+ borrow = (y & 0x10000) >> 16;
+ z = (*xa++ >> 16) - (*xb++ >> 16) - borrow;
+ borrow = (z & 0x10000) >> 16;
+ Storeinc(xc, z, y);
+ }
+ while(xb < xbe);
+ while(xa < xae) {
+ y = (*xa & 0xffff) - borrow;
+ borrow = (y & 0x10000) >> 16;
+ z = (*xa++ >> 16) - borrow;
+ borrow = (z & 0x10000) >> 16;
+ Storeinc(xc, z, y);
+ }
#else
- do {
- y = *xa++ - *xb++ - borrow;
- borrow = (y & 0x10000) >> 16;
- *xc++ = y & 0xffff;
- }
- while(xb < xbe);
- while(xa < xae) {
- y = *xa++ - borrow;
- borrow = (y & 0x10000) >> 16;
- *xc++ = y & 0xffff;
- }
-#endif
-#endif
- while(!*--xc)
- wa--;
- c->wds = wa;
- return c;
- }
-
- static double
+ do {
+ y = *xa++ - *xb++ - borrow;
+ borrow = (y & 0x10000) >> 16;
+ *xc++ = y & 0xffff;
+ }
+ while(xb < xbe);
+ while(xa < xae) {
+ y = *xa++ - borrow;
+ borrow = (y & 0x10000) >> 16;
+ *xc++ = y & 0xffff;
+ }
+#endif
+#endif
+ while(!*--xc) {
+ wa--;
+ }
+ c->wds = wa;
+ return c;
+}
+
+static double
ulp
#ifdef KR_headers
- (x) U *x;
+(x) U *x;
#else
- (U *x)
+(U *x)
#endif
{
- Long L;
- U u;
+ Long L;
+ U u;
- L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1;
+ L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1;
#ifndef Avoid_Underflow
#ifndef Sudden_Underflow
- if (L > 0) {
+ if (L > 0) {
#endif
#endif
#ifdef IBM
- L |= Exp_msk1 >> 4;
+ L |= Exp_msk1 >> 4;
#endif
- word0(&u) = L;
- word1(&u) = 0;
+ word0(&u) = L;
+ word1(&u) = 0;
#ifndef Avoid_Underflow
#ifndef Sudden_Underflow
- }
- else {
- L = -L >> Exp_shift;
- if (L < Exp_shift) {
- word0(&u) = 0x80000 >> L;
- word1(&u) = 0;
- }
- else {
- word0(&u) = 0;
- L -= Exp_shift;
- word1(&u) = L >= 31 ? 1 : 1 << 31 - L;
- }
- }
-#endif
-#endif
- return dval(&u);
- }
-
- static double
+ }
+ else {
+ L = -L >> Exp_shift;
+ if (L < Exp_shift) {
+ word0(&u) = 0x80000 >> L;
+ word1(&u) = 0;
+ }
+ else {
+ word0(&u) = 0;
+ L -= Exp_shift;
+ word1(&u) = L >= 31 ? 1 : 1 << 31 - L;
+ }
+ }
+#endif
+#endif
+ return dval(&u);
+}
+
+static double
b2d
#ifdef KR_headers
- (a, e) Bigint *a; int *e;
+(a, e) Bigint *a; int *e;
#else
- (Bigint *a, int *e)
+(Bigint *a, int *e)
#endif
{
- ULong *xa, *xa0, w, y, z;
- int k;
- U d;
+ ULong *xa, *xa0, w, y, z;
+ int k;
+ U d;
#ifdef VAX
- ULong d0, d1;
+ ULong d0, d1;
#else
#define d0 word0(&d)
#define d1 word1(&d)
#endif
- xa0 = a->x;
- xa = xa0 + a->wds;
- y = *--xa;
+ xa0 = a->x;
+ xa = xa0 + a->wds;
+ y = *--xa;
#ifdef DEBUG
- if (!y) Bug("zero y in b2d");
+ if (!y) {
+ Bug("zero y in b2d");
+ }
#endif
- k = hi0bits(y);
- *e = 32 - k;
+ k = hi0bits(y);
+ *e = 32 - k;
#ifdef Pack_32
- if (k < Ebits) {
- d0 = Exp_1 | y >> (Ebits - k);
- w = xa > xa0 ? *--xa : 0;
- d1 = y << ((32-Ebits) + k) | w >> (Ebits - k);
- goto ret_d;
- }
- z = xa > xa0 ? *--xa : 0;
- if (k -= Ebits) {
- d0 = Exp_1 | y << k | z >> (32 - k);
- y = xa > xa0 ? *--xa : 0;
- d1 = z << k | y >> (32 - k);
- }
- else {
- d0 = Exp_1 | y;
- d1 = z;
- }
+ if (k < Ebits) {
+ d0 = Exp_1 | y >> (Ebits - k);
+ w = xa > xa0 ? *--xa : 0;
+ d1 = y << ((32-Ebits) + k) | w >> (Ebits - k);
+ goto ret_d;
+ }
+ z = xa > xa0 ? *--xa : 0;
+ if (k -= Ebits) {
+ d0 = Exp_1 | y << k | z >> (32 - k);
+ y = xa > xa0 ? *--xa : 0;
+ d1 = z << k | y >> (32 - k);
+ }
+ else {
+ d0 = Exp_1 | y;
+ d1 = z;
+ }
#else
- if (k < Ebits + 16) {
- z = xa > xa0 ? *--xa : 0;
- d0 = Exp_1 | y << k - Ebits | z >> Ebits + 16 - k;
- w = xa > xa0 ? *--xa : 0;
- y = xa > xa0 ? *--xa : 0;
- d1 = z << k + 16 - Ebits | w << k - Ebits | y >> 16 + Ebits - k;
- goto ret_d;
- }
- z = xa > xa0 ? *--xa : 0;
- w = xa > xa0 ? *--xa : 0;
- k -= Ebits + 16;
- d0 = Exp_1 | y << k + 16 | z << k | w >> 16 - k;
- y = xa > xa0 ? *--xa : 0;
- d1 = w << k + 16 | y << k;
-#endif
- ret_d:
+ if (k < Ebits + 16) {
+ z = xa > xa0 ? *--xa : 0;
+ d0 = Exp_1 | y << k - Ebits | z >> Ebits + 16 - k;
+ w = xa > xa0 ? *--xa : 0;
+ y = xa > xa0 ? *--xa : 0;
+ d1 = z << k + 16 - Ebits | w << k - Ebits | y >> 16 + Ebits - k;
+ goto ret_d;
+ }
+ z = xa > xa0 ? *--xa : 0;
+ w = xa > xa0 ? *--xa : 0;
+ k -= Ebits + 16;
+ d0 = Exp_1 | y << k + 16 | z << k | w >> 16 - k;
+ y = xa > xa0 ? *--xa : 0;
+ d1 = w << k + 16 | y << k;
+#endif
+ret_d:
#ifdef VAX
- word0(&d) = d0 >> 16 | d0 << 16;
- word1(&d) = d1 >> 16 | d1 << 16;
+ word0(&d) = d0 >> 16 | d0 << 16;
+ word1(&d) = d1 >> 16 | d1 << 16;
#else
#undef d0
#undef d1
#endif
- return dval(&d);
- }
+ return dval(&d);
+}
- static Bigint *
+static Bigint *
d2b
#ifdef KR_headers
- (d, e, bits) U *d; int *e, *bits;
+(d, e, bits) U *d; int *e, *bits;
#else
- (U *d, int *e, int *bits)
+(U *d, int *e, int *bits)
#endif
{
- Bigint *b;
- int de, k;
- ULong *x, y, z;
+ Bigint *b;
+ int de, k;
+ ULong *x, y, z;
#ifndef Sudden_Underflow
- int i;
+ int i;
#endif
#ifdef VAX
- ULong d0, d1;
- d0 = word0(d) >> 16 | word0(d) << 16;
- d1 = word1(d) >> 16 | word1(d) << 16;
+ ULong d0, d1;
+ d0 = word0(d) >> 16 | word0(d) << 16;
+ d1 = word1(d) >> 16 | word1(d) << 16;
#else
#define d0 word0(d)
#define d1 word1(d)
#endif
#ifdef Pack_32
- b = Balloc(1);
+ b = Balloc(1);
#else
- b = Balloc(2);
+ b = Balloc(2);
#endif
- x = b->x;
+ x = b->x;
- z = d0 & Frac_mask;
- d0 &= 0x7fffffff; /* clear sign bit, which we ignore */
+ z = d0 & Frac_mask;
+ d0 &= 0x7fffffff; /* clear sign bit, which we ignore */
#ifdef Sudden_Underflow
- de = (int)(d0 >> Exp_shift);
+ de = (int)(d0 >> Exp_shift);
#ifndef IBM
- z |= Exp_msk11;
+ z |= Exp_msk11;
#endif
#else
- if ((de = (int)(d0 >> Exp_shift)))
- z |= Exp_msk1;
+ if ((de = (int)(d0 >> Exp_shift))) {
+ z |= Exp_msk1;
+ }
#endif
#ifdef Pack_32
- if ((y = d1)) {
- if ((k = lo0bits(&y))) {
- x[0] = y | z << (32 - k);
- z >>= k;
- }
- else
- x[0] = y;
+ if ((y = d1)) {
+ if ((k = lo0bits(&y))) {
+ x[0] = y | z << (32 - k);
+ z >>= k;
+ }
+ else {
+ x[0] = y;
+ }
#ifndef Sudden_Underflow
- i =
+ i =
#endif
- b->wds = (x[1] = z) ? 2 : 1;
- }
- else {
- k = lo0bits(&z);
- x[0] = z;
+ b->wds = (x[1] = z) ? 2 : 1;
+ }
+ else {
+ k = lo0bits(&z);
+ x[0] = z;
#ifndef Sudden_Underflow
- i =
+ i =
#endif
- b->wds = 1;
- k += 32;
- }
+ b->wds = 1;
+ k += 32;
+ }
#else
- if (y = d1) {
- if (k = lo0bits(&y))
- if (k >= 16) {
- x[0] = y | z << 32 - k & 0xffff;
- x[1] = z >> k - 16 & 0xffff;
- x[2] = z >> k;
- i = 2;
- }
- else {
- x[0] = y & 0xffff;
- x[1] = y >> 16 | z << 16 - k & 0xffff;
- x[2] = z >> k & 0xffff;
- x[3] = z >> k+16;
- i = 3;
- }
- else {
- x[0] = y & 0xffff;
- x[1] = y >> 16;
- x[2] = z & 0xffff;
- x[3] = z >> 16;
- i = 3;
- }
- }
- else {
+ if (y = d1) {
+ if (k = lo0bits(&y))
+ if (k >= 16) {
+ x[0] = y | z << 32 - k & 0xffff;
+ x[1] = z >> k - 16 & 0xffff;
+ x[2] = z >> k;
+ i = 2;
+ }
+ else {
+ x[0] = y & 0xffff;
+ x[1] = y >> 16 | z << 16 - k & 0xffff;
+ x[2] = z >> k & 0xffff;
+ x[3] = z >> k+16;
+ i = 3;
+ }
+ else {
+ x[0] = y & 0xffff;
+ x[1] = y >> 16;
+ x[2] = z & 0xffff;
+ x[3] = z >> 16;
+ i = 3;
+ }
+ }
+ else {
#ifdef DEBUG
- if (!z)
- Bug("Zero passed to d2b");
-#endif
- k = lo0bits(&z);
- if (k >= 16) {
- x[0] = z;
- i = 0;
- }
- else {
- x[0] = z & 0xffff;
- x[1] = z >> 16;
- i = 1;
- }
- k += 32;
- }
- while(!x[i])
- --i;
- b->wds = i + 1;
+ if (!z) {
+ Bug("Zero passed to d2b");
+ }
+#endif
+ k = lo0bits(&z);
+ if (k >= 16) {
+ x[0] = z;
+ i = 0;
+ }
+ else {
+ x[0] = z & 0xffff;
+ x[1] = z >> 16;
+ i = 1;
+ }
+ k += 32;
+ }
+ while(!x[i]) {
+ --i;
+ }
+ b->wds = i + 1;
#endif
#ifndef Sudden_Underflow
- if (de) {
+ if (de) {
#endif
#ifdef IBM
- *e = (de - Bias - (P-1) << 2) + k;
- *bits = 4*P + 8 - k - hi0bits(word0(d) & Frac_mask);
+ *e = (de - Bias - (P-1) << 2) + k;
+ *bits = 4*P + 8 - k - hi0bits(word0(d) & Frac_mask);
#else
- *e = de - Bias - (P-1) + k;
- *bits = P - k;
+ *e = de - Bias - (P-1) + k;
+ *bits = P - k;
#endif
#ifndef Sudden_Underflow
- }
- else {
- *e = de - Bias - (P-1) + 1 + k;
+ }
+ else {
+ *e = de - Bias - (P-1) + 1 + k;
#ifdef Pack_32
- *bits = 32*i - hi0bits(x[i-1]);
+ *bits = 32*i - hi0bits(x[i-1]);
#else
- *bits = (i+2)*16 - hi0bits(x[i]);
+ *bits = (i+2)*16 - hi0bits(x[i]);
#endif
- }
+ }
#endif
- return b;
- }
+ return b;
+}
#undef d0
#undef d1
- static double
+static double
ratio
#ifdef KR_headers
- (a, b) Bigint *a, *b;
+(a, b) Bigint *a, *b;
#else
- (Bigint *a, Bigint *b)
+(Bigint *a, Bigint *b)
#endif
{
- U da, db;
- int k, ka, kb;
+ U da, db;
+ int k, ka, kb;
- dval(&da) = b2d(a, &ka);
- dval(&db) = b2d(b, &kb);
+ dval(&da) = b2d(a, &ka);
+ dval(&db) = b2d(b, &kb);
#ifdef Pack_32
- k = ka - kb + 32*(a->wds - b->wds);
+ k = ka - kb + 32*(a->wds - b->wds);
#else
- k = ka - kb + 16*(a->wds - b->wds);
+ k = ka - kb + 16*(a->wds - b->wds);
#endif
#ifdef IBM
- if (k > 0) {
- word0(&da) += (k >> 2)*Exp_msk1;
- if (k &= 3)
- dval(&da) *= 1 << k;
- }
- else {
- k = -k;
- word0(&db) += (k >> 2)*Exp_msk1;
- if (k &= 3)
- dval(&db) *= 1 << k;
- }
+ if (k > 0) {
+ word0(&da) += (k >> 2)*Exp_msk1;
+ if (k &= 3) {
+ dval(&da) *= 1 << k;
+ }
+ }
+ else {
+ k = -k;
+ word0(&db) += (k >> 2)*Exp_msk1;
+ if (k &= 3) {
+ dval(&db) *= 1 << k;
+ }
+ }
#else
- if (k > 0)
- word0(&da) += k*Exp_msk1;
- else {
- k = -k;
- word0(&db) += k*Exp_msk1;
- }
-#endif
- return dval(&da) / dval(&db);
- }
+ if (k > 0) {
+ word0(&da) += k*Exp_msk1;
+ }
+ else {
+ k = -k;
+ word0(&db) += k*Exp_msk1;
+ }
+#endif
+ return dval(&da) / dval(&db);
+}
- static CONST double
+static CONST double
tens[] = {
- 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,
- 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,
- 1e20, 1e21, 1e22
+ 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,
+ 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,
+ 1e20, 1e21, 1e22
#ifdef VAX
- , 1e23, 1e24
+ , 1e23, 1e24
#endif
- };
+};
- static CONST double
+static CONST double
#ifdef IEEE_Arith
bigtens[] = { 1e16, 1e32, 1e64, 1e128, 1e256 };
static CONST double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128,
#ifdef Avoid_Underflow
- 9007199254740992.*9007199254740992.e-256
- /* = 2^106 * 1e-256 */
+ 9007199254740992.*9007199254740992.e-256
+ /* = 2^106 * 1e-256 */
#else
- 1e-256
+ 1e-256
#endif
- };
+ };
/* The factor of 2^53 in tinytens[4] helps us avoid setting the underflow */
/* flag unnecessarily. It leads to a song and dance at the end of strtod. */
#define Scale_Bit 0x10
@@ -1497,19 +1537,20 @@ static CONST double tinytens[] = { 1e-16, 1e-32 };
#ifdef Need_Hexdig /*{*/
static unsigned char hexdig[256];
- static void
+static void
#ifdef KR_headers
htinit(h, s, inc) unsigned char *h; unsigned char *s; int inc;
#else
htinit(unsigned char *h, unsigned char *s, int inc)
#endif
{
- int i, j;
- for(i = 0; (j = s[i]) !=0; i++)
- h[j] = i + inc;
- }
+ int i, j;
+ for(i = 0; (j = s[i]) !=0; i++) {
+ h[j] = i + inc;
+ }
+}
- static void
+static void
#ifdef KR_headers
hexdig_init()
#else
@@ -1517,10 +1558,10 @@ hexdig_init(void)
#endif
{
#define USC (unsigned char *)
- htinit(hexdig, USC "0123456789", 0x10);
- htinit(hexdig, USC "abcdef", 0x10 + 10);
- htinit(hexdig, USC "ABCDEF", 0x10 + 10);
- }
+ htinit(hexdig, USC "0123456789", 0x10);
+ htinit(hexdig, USC "abcdef", 0x10 + 10);
+ htinit(hexdig, USC "ABCDEF", 0x10 + 10);
+}
#endif /* } Need_Hexdig */
#ifdef INFNAN_CHECK
@@ -1533,94 +1574,102 @@ hexdig_init(void)
#define NAN_WORD1 0
#endif
- static int
+static int
match
#ifdef KR_headers
- (sp, t) char **sp, *t;
+(sp, t) char **sp, *t;
#else
- (const char **sp, const char *t)
+(const char **sp, const char *t)
#endif
{
- int c, d;
- CONST char *s = *sp;
-
- while((d = *t++)) {
- if ((c = *++s) >= 'A' && c <= 'Z')
- c += 'a' - 'A';
- if (c != d)
- return 0;
- }
- *sp = s + 1;
- return 1;
- }
+ int c, d;
+ CONST char *s = *sp;
+
+ while((d = *t++)) {
+ if ((c = *++s) >= 'A' && c <= 'Z') {
+ c += 'a' - 'A';
+ }
+ if (c != d) {
+ return 0;
+ }
+ }
+ *sp = s + 1;
+ return 1;
+}
#ifndef No_Hex_NaN
- static void
+static void
hexnan
#ifdef KR_headers
- (rvp, sp) U *rvp; CONST char **sp;
+(rvp, sp) U *rvp; CONST char **sp;
#else
- (U *rvp, const char **sp)
+(U *rvp, const char **sp)
#endif
{
- ULong c, x[2];
- CONST char *s;
- int c1, havedig, udx0, xshift;
-
- if (!hexdig['0'])
- hexdig_init();
- x[0] = x[1] = 0;
- havedig = xshift = 0;
- udx0 = 1;
- s = *sp;
- /* allow optional initial 0x or 0X */
- while((c = *(CONST unsigned char*)(s+1)) && c <= ' ')
- ++s;
- if (s[1] == '0' && (s[2] == 'x' || s[2] == 'X'))
- s += 2;
- while((c = *(CONST unsigned char*)++s)) {
- if ((c1 = hexdig[c]))
- c = c1 & 0xf;
- else if (c <= ' ') {
- if (udx0 && havedig) {
- udx0 = 0;
- xshift = 1;
- }
- continue;
- }
+ ULong c, x[2];
+ CONST char *s;
+ int c1, havedig, udx0, xshift;
+
+ if (!hexdig['0']) {
+ hexdig_init();
+ }
+ x[0] = x[1] = 0;
+ havedig = xshift = 0;
+ udx0 = 1;
+ s = *sp;
+ /* allow optional initial 0x or 0X */
+ while((c = *(CONST unsigned char*)(s+1)) && c <= ' ') {
+ ++s;
+ }
+ if (s[1] == '0' && (s[2] == 'x' || s[2] == 'X')) {
+ s += 2;
+ }
+ while((c = *(CONST unsigned char*)++s)) {
+ if ((c1 = hexdig[c])) {
+ c = c1 & 0xf;
+ }
+ else if (c <= ' ') {
+ if (udx0 && havedig) {
+ udx0 = 0;
+ xshift = 1;
+ }
+ continue;
+ }
#ifdef GDTOA_NON_PEDANTIC_NANCHECK
- else if (/*(*/ c == ')' && havedig) {
- *sp = s + 1;
- break;
- }
- else
- return; /* invalid form: don't change *sp */
+ else if (/*(*/ c == ')' && havedig) {
+ *sp = s + 1;
+ break;
+ }
+ else {
+ return; /* invalid form: don't change *sp */
+ }
#else
- else {
- do {
- if (/*(*/ c == ')') {
- *sp = s + 1;
- break;
- }
- } while((c = *++s));
- break;
- }
-#endif
- havedig = 1;
- if (xshift) {
- xshift = 0;
- x[0] = x[1];
- x[1] = 0;
- }
- if (udx0)
- x[0] = (x[0] << 4) | (x[1] >> 28);
- x[1] = (x[1] << 4) | c;
- }
- if ((x[0] &= 0xfffff) || x[1]) {
- word0(rvp) = Exp_mask | x[0];
- word1(rvp) = x[1];
- }
- }
+ else {
+ do {
+ if (/*(*/ c == ')') {
+ *sp = s + 1;
+ break;
+ }
+ } while((c = *++s));
+ break;
+ }
+#endif
+ havedig = 1;
+ if (xshift) {
+ xshift = 0;
+ x[0] = x[1];
+ x[1] = 0;
+ }
+ if (udx0) {
+ x[0] = (x[0] << 4) | (x[1] >> 28);
+ }
+ x[1] = (x[1] << 4) | c;
+ }
+ if ((x[0] &= 0xfffff) || x[1]) {
+ word0(rvp) = Exp_mask | x[0];
+ word1(rvp) = x[1];
+ }
+}
#endif /*No_Hex_NaN*/
#endif /* INFNAN_CHECK */
@@ -1635,1956 +1684,2122 @@ hexnan
#endif
#if !defined(NO_HEX_FP) || defined(Honor_FLT_ROUNDS) /*{*/
- static Bigint *
+static Bigint *
#ifdef KR_headers
increment(b) Bigint *b;
#else
increment(Bigint *b)
#endif
{
- ULong *x, *xe;
- Bigint *b1;
-
- x = b->x;
- xe = x + b->wds;
- do {
- if (*x < (ULong)0xffffffffL) {
- ++*x;
- return b;
- }
- *x++ = 0;
- } while(x < xe);
- {
- if (b->wds >= b->maxwds) {
- b1 = Balloc(b->k+1);
- Bcopy(b1,b);
- Bfree(b);
- b = b1;
- }
- b->x[b->wds++] = 1;
- }
- return b;
- }
+ ULong *x, *xe;
+ Bigint *b1;
+
+ x = b->x;
+ xe = x + b->wds;
+ do {
+ if (*x < (ULong)0xffffffffL) {
+ ++*x;
+ return b;
+ }
+ *x++ = 0;
+ } while(x < xe);
+ {
+ if (b->wds >= b->maxwds) {
+ b1 = Balloc(b->k+1);
+ Bcopy(b1,b);
+ Bfree(b);
+ b = b1;
+ }
+ b->x[b->wds++] = 1;
+ }
+ return b;
+}
#endif /*}*/
#ifndef NO_HEX_FP /*{*/
- static void
+static void
#ifdef KR_headers
rshift(b, k) Bigint *b; int k;
#else
rshift(Bigint *b, int k)
#endif
{
- ULong *x, *x1, *xe, y;
- int n;
-
- x = x1 = b->x;
- n = k >> kshift;
- if (n < b->wds) {
- xe = x + b->wds;
- x += n;
- if (k &= kmask) {
- n = 32 - k;
- y = *x++ >> k;
- while(x < xe) {
- *x1++ = (y | (*x << n)) & 0xffffffff;
- y = *x++ >> k;
- }
- if ((*x1 = y) !=0)
- x1++;
- }
- else
- while(x < xe)
- *x1++ = *x++;
- }
- if ((b->wds = x1 - b->x) == 0)
- b->x[0] = 0;
- }
-
- static ULong
+ ULong *x, *x1, *xe, y;
+ int n;
+
+ x = x1 = b->x;
+ n = k >> kshift;
+ if (n < b->wds) {
+ xe = x + b->wds;
+ x += n;
+ if (k &= kmask) {
+ n = 32 - k;
+ y = *x++ >> k;
+ while(x < xe) {
+ *x1++ = (y | (*x << n)) & 0xffffffff;
+ y = *x++ >> k;
+ }
+ if ((*x1 = y) !=0) {
+ x1++;
+ }
+ }
+ else
+ while(x < xe) {
+ *x1++ = *x++;
+ }
+ }
+ if ((b->wds = x1 - b->x) == 0) {
+ b->x[0] = 0;
+ }
+}
+
+static ULong
#ifdef KR_headers
any_on(b, k) Bigint *b; int k;
#else
any_on(Bigint *b, int k)
#endif
{
- int n, nwds;
- ULong *x, *x0, x1, x2;
-
- x = b->x;
- nwds = b->wds;
- n = k >> kshift;
- if (n > nwds)
- n = nwds;
- else if (n < nwds && (k &= kmask)) {
- x1 = x2 = x[n];
- x1 >>= k;
- x1 <<= k;
- if (x1 != x2)
- return 1;
- }
- x0 = x;
- x += n;
- while(x > x0)
- if (*--x)
- return 1;
- return 0;
- }
-
-enum { /* rounding values: same as FLT_ROUNDS */
- Round_zero = 0,
- Round_near = 1,
- Round_up = 2,
- Round_down = 3
- };
-
- void
+ int n, nwds;
+ ULong *x, *x0, x1, x2;
+
+ x = b->x;
+ nwds = b->wds;
+ n = k >> kshift;
+ if (n > nwds) {
+ n = nwds;
+ }
+ else if (n < nwds && (k &= kmask)) {
+ x1 = x2 = x[n];
+ x1 >>= k;
+ x1 <<= k;
+ if (x1 != x2) {
+ return 1;
+ }
+ }
+ x0 = x;
+ x += n;
+ while(x > x0)
+ if (*--x) {
+ return 1;
+ }
+ return 0;
+}
+
+enum { /* rounding values: same as FLT_ROUNDS */
+ Round_zero = 0,
+ Round_near = 1,
+ Round_up = 2,
+ Round_down = 3
+};
+
+void
#ifdef KR_headers
gethex(sp, rvp, rounding, sign)
- CONST char **sp; U *rvp; int rounding, sign;
+CONST char **sp; U *rvp; int rounding, sign;
#else
gethex( CONST char **sp, U *rvp, int rounding, int sign)
#endif
{
- Bigint *b;
- CONST unsigned char *decpt, *s0, *s, *s1;
- Long e, e1;
- ULong L, lostbits, *x;
- int big, denorm, esign, havedig, k, n, nbits, up, zret;
+ Bigint *b;
+ CONST unsigned char *decpt, *s0, *s, *s1;
+ Long e, e1;
+ ULong L, lostbits, *x;
+ int big, denorm, esign, havedig, k, n, nbits, up, zret;
#ifdef IBM
- int j;
+ int j;
#endif
- enum {
+ enum {
#ifdef IEEE_Arith /*{{*/
- emax = 0x7fe - Bias - P + 1,
- emin = Emin - P + 1
+ emax = 0x7fe - Bias - P + 1,
+ emin = Emin - P + 1
#else /*}{*/
- emin = Emin - P,
+ emin = Emin - P,
#ifdef VAX
- emax = 0x7ff - Bias - P + 1
+ emax = 0x7ff - Bias - P + 1
#endif
#ifdef IBM
- emax = 0x7f - Bias - P
+ emax = 0x7f - Bias - P
#endif
#endif /*}}*/
- };
+ };
#ifdef USE_LOCALE
- int i;
+ int i;
#ifdef NO_LOCALE_CACHE
- const unsigned char *decimalpoint = (unsigned char*)
- localeconv()->decimal_point;
+ const unsigned char *decimalpoint = (unsigned char*)
+ localeconv()->decimal_point;
#else
- const unsigned char *decimalpoint;
- static unsigned char *decimalpoint_cache;
- if (!(s0 = decimalpoint_cache)) {
- s0 = (unsigned char*)localeconv()->decimal_point;
- if ((decimalpoint_cache = (unsigned char*)
- MALLOC(strlen((CONST char*)s0) + 1))) {
- strcpy((char*)decimalpoint_cache, (CONST char*)s0);
- s0 = decimalpoint_cache;
- }
- }
- decimalpoint = s0;
-#endif
-#endif
-
- if (!hexdig['0'])
- hexdig_init();
- havedig = 0;
- s0 = *(CONST unsigned char **)sp + 2;
- while(s0[havedig] == '0')
- havedig++;
- s0 += havedig;
- s = s0;
- decpt = 0;
- zret = 0;
- e = 0;
- if (hexdig[*s])
- havedig++;
- else {
- zret = 1;
+ const unsigned char *decimalpoint;
+ static unsigned char *decimalpoint_cache;
+ if (!(s0 = decimalpoint_cache)) {
+ s0 = (unsigned char*)localeconv()->decimal_point;
+ if ((decimalpoint_cache = (unsigned char*)
+ MALLOC(strlen((CONST char*)s0) + 1))) {
+ strcpy((char*)decimalpoint_cache, (CONST char*)s0);
+ s0 = decimalpoint_cache;
+ }
+ }
+ decimalpoint = s0;
+#endif
+#endif
+
+ if (!hexdig['0']) {
+ hexdig_init();
+ }
+ havedig = 0;
+ s0 = *(CONST unsigned char **)sp + 2;
+ while(s0[havedig] == '0') {
+ havedig++;
+ }
+ s0 += havedig;
+ s = s0;
+ decpt = 0;
+ zret = 0;
+ e = 0;
+ if (hexdig[*s]) {
+ havedig++;
+ }
+ else {
+ zret = 1;
#ifdef USE_LOCALE
- for(i = 0; decimalpoint[i]; ++i) {
- if (s[i] != decimalpoint[i])
- goto pcheck;
- }
- decpt = s += i;
+ for(i = 0; decimalpoint[i]; ++i) {
+ if (s[i] != decimalpoint[i]) {
+ goto pcheck;
+ }
+ }
+ decpt = s += i;
#else
- if (*s != '.')
- goto pcheck;
- decpt = ++s;
-#endif
- if (!hexdig[*s])
- goto pcheck;
- while(*s == '0')
- s++;
- if (hexdig[*s])
- zret = 0;
- havedig = 1;
- s0 = s;
- }
- while(hexdig[*s])
- s++;
+ if (*s != '.') {
+ goto pcheck;
+ }
+ decpt = ++s;
+#endif
+ if (!hexdig[*s]) {
+ goto pcheck;
+ }
+ while(*s == '0') {
+ s++;
+ }
+ if (hexdig[*s]) {
+ zret = 0;
+ }
+ havedig = 1;
+ s0 = s;
+ }
+ while(hexdig[*s]) {
+ s++;
+ }
#ifdef USE_LOCALE
- if (*s == *decimalpoint && !decpt) {
- for(i = 1; decimalpoint[i]; ++i) {
- if (s[i] != decimalpoint[i])
- goto pcheck;
- }
- decpt = s += i;
+ if (*s == *decimalpoint && !decpt) {
+ for(i = 1; decimalpoint[i]; ++i) {
+ if (s[i] != decimalpoint[i]) {
+ goto pcheck;
+ }
+ }
+ decpt = s += i;
#else
- if (*s == '.' && !decpt) {
- decpt = ++s;
-#endif
- while(hexdig[*s])
- s++;
- }/*}*/
- if (decpt)
- e = -(((Long)(s-decpt)) << 2);
- pcheck:
- s1 = s;
- big = esign = 0;
- switch(*s) {
- case 'p':
- case 'P':
- switch(*++s) {
- case '-':
- esign = 1;
- /* no break */
- case '+':
- s++;
- }
- if ((n = hexdig[*s]) == 0 || n > 0x19) {
- s = s1;
- break;
- }
- e1 = n - 0x10;
- while((n = hexdig[*++s]) !=0 && n <= 0x19) {
- if (e1 & 0xf8000000)
- big = 1;
- e1 = 10*e1 + n - 0x10;
- }
- if (esign)
- e1 = -e1;
- e += e1;
- }
- *sp = (char*)s;
- if (!havedig)
- *sp = (char*)s0 - 1;
- if (zret)
- goto retz1;
- if (big) {
- if (esign) {
+ if (*s == '.' && !decpt) {
+ decpt = ++s;
+#endif
+ while(hexdig[*s]) {
+ s++;
+ }
+ }/*}*/
+ if (decpt) {
+ e = -(((Long)(s-decpt)) << 2);
+ }
+pcheck:
+ s1 = s;
+ big = esign = 0;
+ switch(*s) {
+ case 'p':
+ case 'P':
+ switch(*++s) {
+ case '-':
+ esign = 1;
+ /* no break */
+ case '+':
+ s++;
+ }
+ if ((n = hexdig[*s]) == 0 || n > 0x19) {
+ s = s1;
+ break;
+ }
+ e1 = n - 0x10;
+ while((n = hexdig[*++s]) !=0 && n <= 0x19) {
+ if (e1 & 0xf8000000) {
+ big = 1;
+ }
+ e1 = 10*e1 + n - 0x10;
+ }
+ if (esign) {
+ e1 = -e1;
+ }
+ e += e1;
+ }
+ *sp = (char*)s;
+ if (!havedig) {
+ *sp = (char*)s0 - 1;
+ }
+ if (zret) {
+ goto retz1;
+ }
+ if (big) {
+ if (esign) {
#ifdef IEEE_Arith
- switch(rounding) {
- case Round_up:
- if (sign)
- break;
- goto ret_tiny;
- case Round_down:
- if (!sign)
- break;
- goto ret_tiny;
- }
-#endif
- goto retz;
+ switch(rounding) {
+ case Round_up:
+ if (sign) {
+ break;
+ }
+ goto ret_tiny;
+ case Round_down:
+ if (!sign) {
+ break;
+ }
+ goto ret_tiny;
+ }
+#endif
+ goto retz;
#ifdef IEEE_Arith
- ret_tiny:
+ret_tiny:
#ifndef NO_ERRNO
- errno = ERANGE;
+ errno = ERANGE;
#endif
- word0(rvp) = 0;
- word1(rvp) = 1;
- return;
+ word0(rvp) = 0;
+ word1(rvp) = 1;
+ return;
#endif /* IEEE_Arith */
- }
- switch(rounding) {
- case Round_near:
- goto ovfl1;
- case Round_up:
- if (!sign)
- goto ovfl1;
- goto ret_big;
- case Round_down:
- if (sign)
- goto ovfl1;
- goto ret_big;
- }
- ret_big:
- word0(rvp) = Big0;
- word1(rvp) = Big1;
- return;
- }
- n = s1 - s0 - 1;
- for(k = 0; n > (1 << (kshift-2)) - 1; n >>= 1)
- k++;
- b = Balloc(k);
- x = b->x;
- n = 0;
- L = 0;
+ }
+ switch(rounding) {
+ case Round_near:
+ goto ovfl1;
+ case Round_up:
+ if (!sign) {
+ goto ovfl1;
+ }
+ goto ret_big;
+ case Round_down:
+ if (sign) {
+ goto ovfl1;
+ }
+ goto ret_big;
+ }
+ret_big:
+ word0(rvp) = Big0;
+ word1(rvp) = Big1;
+ return;
+ }
+ n = s1 - s0 - 1;
+ for(k = 0; n > (1 << (kshift-2)) - 1; n >>= 1) {
+ k++;
+ }
+ b = Balloc(k);
+ x = b->x;
+ n = 0;
+ L = 0;
#ifdef USE_LOCALE
- for(i = 0; decimalpoint[i+1]; ++i);
+ for(i = 0; decimalpoint[i+1]; ++i);
#endif
- while(s1 > s0) {
+ while(s1 > s0) {
#ifdef USE_LOCALE
- if (*--s1 == decimalpoint[i]) {
- s1 -= i;
- continue;
- }
+ if (*--s1 == decimalpoint[i]) {
+ s1 -= i;
+ continue;
+ }
#else
- if (*--s1 == '.')
- continue;
-#endif
- if (n == ULbits) {
- *x++ = L;
- L = 0;
- n = 0;
- }
- L |= (hexdig[*s1] & 0x0f) << n;
- n += 4;
- }
- *x++ = L;
- b->wds = n = x - b->x;
- n = ULbits*n - hi0bits(L);
- nbits = Nbits;
- lostbits = 0;
- x = b->x;
- if (n > nbits) {
- n -= nbits;
- if (any_on(b,n)) {
- lostbits = 1;
- k = n - 1;
- if (x[k>>kshift] & 1 << (k & kmask)) {
- lostbits = 2;
- if (k > 0 && any_on(b,k))
- lostbits = 3;
- }
- }
- rshift(b, n);
- e += n;
- }
- else if (n < nbits) {
- n = nbits - n;
- b = lshift(b, n);
- e -= n;
- x = b->x;
- }
- if (e > Emax) {
- ovfl:
- Bfree(b);
- ovfl1:
+ if (*--s1 == '.') {
+ continue;
+ }
+#endif
+ if (n == ULbits) {
+ *x++ = L;
+ L = 0;
+ n = 0;
+ }
+ L |= (hexdig[*s1] & 0x0f) << n;
+ n += 4;
+ }
+ *x++ = L;
+ b->wds = n = x - b->x;
+ n = ULbits*n - hi0bits(L);
+ nbits = Nbits;
+ lostbits = 0;
+ x = b->x;
+ if (n > nbits) {
+ n -= nbits;
+ if (any_on(b,n)) {
+ lostbits = 1;
+ k = n - 1;
+ if (x[k>>kshift] & 1 << (k & kmask)) {
+ lostbits = 2;
+ if (k > 0 && any_on(b,k)) {
+ lostbits = 3;
+ }
+ }
+ }
+ rshift(b, n);
+ e += n;
+ }
+ else if (n < nbits) {
+ n = nbits - n;
+ b = lshift(b, n);
+ e -= n;
+ x = b->x;
+ }
+ if (e > Emax) {
+ovfl:
+ Bfree(b);
+ovfl1:
#ifndef NO_ERRNO
- errno = ERANGE;
-#endif
- word0(rvp) = Exp_mask;
- word1(rvp) = 0;
- return;
- }
- denorm = 0;
- if (e < emin) {
- denorm = 1;
- n = emin - e;
- if (n >= nbits) {
+ errno = ERANGE;
+#endif
+ word0(rvp) = Exp_mask;
+ word1(rvp) = 0;
+ return;
+ }
+ denorm = 0;
+ if (e < emin) {
+ denorm = 1;
+ n = emin - e;
+ if (n >= nbits) {
#ifdef IEEE_Arith /*{*/
- switch (rounding) {
- case Round_near:
- if (n == nbits && (n < 2 || any_on(b,n-1)))
- goto ret_tiny;
- break;
- case Round_up:
- if (!sign)
- goto ret_tiny;
- break;
- case Round_down:
- if (sign)
- goto ret_tiny;
- }
+ switch (rounding) {
+ case Round_near:
+ if (n == nbits && (n < 2 || any_on(b,n-1))) {
+ goto ret_tiny;
+ }
+ break;
+ case Round_up:
+ if (!sign) {
+ goto ret_tiny;
+ }
+ break;
+ case Round_down:
+ if (sign) {
+ goto ret_tiny;
+ }
+ }
#endif /* } IEEE_Arith */
- Bfree(b);
- retz:
+ Bfree(b);
+retz:
#ifndef NO_ERRNO
- errno = ERANGE;
-#endif
- retz1:
- rvp->d = 0.;
- return;
- }
- k = n - 1;
- if (lostbits)
- lostbits = 1;
- else if (k > 0)
- lostbits = any_on(b,k);
- if (x[k>>kshift] & 1 << (k & kmask))
- lostbits |= 2;
- nbits -= n;
- rshift(b,n);
- e = emin;
- }
- if (lostbits) {
- up = 0;
- switch(rounding) {
- case Round_zero:
- break;
- case Round_near:
- if (lostbits & 2
- && (lostbits & 1) | (x[0] & 1))
- up = 1;
- break;
- case Round_up:
- up = 1 - sign;
- break;
- case Round_down:
- up = sign;
- }
- if (up) {
- k = b->wds;
- b = increment(b);
- x = b->x;
- if (denorm) {
+ errno = ERANGE;
+#endif
+retz1:
+ rvp->d = 0.;
+ return;
+ }
+ k = n - 1;
+ if (lostbits) {
+ lostbits = 1;
+ }
+ else if (k > 0) {
+ lostbits = any_on(b,k);
+ }
+ if (x[k>>kshift] & 1 << (k & kmask)) {
+ lostbits |= 2;
+ }
+ nbits -= n;
+ rshift(b,n);
+ e = emin;
+ }
+ if (lostbits) {
+ up = 0;
+ switch(rounding) {
+ case Round_zero:
+ break;
+ case Round_near:
+ if (lostbits & 2
+ && (lostbits & 1) | (x[0] & 1)) {
+ up = 1;
+ }
+ break;
+ case Round_up:
+ up = 1 - sign;
+ break;
+ case Round_down:
+ up = sign;
+ }
+ if (up) {
+ k = b->wds;
+ b = increment(b);
+ x = b->x;
+ if (denorm) {
#if 0
- if (nbits == Nbits - 1
- && x[nbits >> kshift] & 1 << (nbits & kmask))
- denorm = 0; /* not currently used */
-#endif
- }
- else if (b->wds > k
- || ((n = nbits & kmask) !=0
- && hi0bits(x[k-1]) < 32-n)) {
- rshift(b,1);
- if (++e > Emax)
- goto ovfl;
- }
- }
- }
+ if (nbits == Nbits - 1
+ && x[nbits >> kshift] & 1 << (nbits & kmask)) {
+ denorm = 0; /* not currently used */
+ }
+#endif
+ }
+ else if (b->wds > k
+ || ((n = nbits & kmask) !=0
+ && hi0bits(x[k-1]) < 32-n)) {
+ rshift(b,1);
+ if (++e > Emax) {
+ goto ovfl;
+ }
+ }
+ }
+ }
#ifdef IEEE_Arith
- if (denorm)
- word0(rvp) = b->wds > 1 ? b->x[1] & ~0x100000 : 0;
- else
- word0(rvp) = (b->x[1] & ~0x100000) | ((e + 0x3ff + 52) << 20);
- word1(rvp) = b->x[0];
+ if (denorm) {
+ word0(rvp) = b->wds > 1 ? b->x[1] & ~0x100000 : 0;
+ }
+ else {
+ word0(rvp) = (b->x[1] & ~0x100000) | ((e + 0x3ff + 52) << 20);
+ }
+ word1(rvp) = b->x[0];
#endif
#ifdef IBM
- if ((j = e & 3)) {
- k = b->x[0] & ((1 << j) - 1);
- rshift(b,j);
- if (k) {
- switch(rounding) {
- case Round_up:
- if (!sign)
- increment(b);
- break;
- case Round_down:
- if (sign)
- increment(b);
- break;
- case Round_near:
- j = 1 << (j-1);
- if (k & j && ((k & (j-1)) | lostbits))
- increment(b);
- }
- }
- }
- e >>= 2;
- word0(rvp) = b->x[1] | ((e + 65 + 13) << 24);
- word1(rvp) = b->x[0];
+ if ((j = e & 3)) {
+ k = b->x[0] & ((1 << j) - 1);
+ rshift(b,j);
+ if (k) {
+ switch(rounding) {
+ case Round_up:
+ if (!sign) {
+ increment(b);
+ }
+ break;
+ case Round_down:
+ if (sign) {
+ increment(b);
+ }
+ break;
+ case Round_near:
+ j = 1 << (j-1);
+ if (k & j && ((k & (j-1)) | lostbits)) {
+ increment(b);
+ }
+ }
+ }
+ }
+ e >>= 2;
+ word0(rvp) = b->x[1] | ((e + 65 + 13) << 24);
+ word1(rvp) = b->x[0];
#endif
#ifdef VAX
- /* The next two lines ignore swap of low- and high-order 2 bytes. */
- /* word0(rvp) = (b->x[1] & ~0x800000) | ((e + 129 + 55) << 23); */
- /* word1(rvp) = b->x[0]; */
- word0(rvp) = ((b->x[1] & ~0x800000) >> 16) | ((e + 129 + 55) << 7) | (b->x[1] << 16);
- word1(rvp) = (b->x[0] >> 16) | (b->x[0] << 16);
-#endif
- Bfree(b);
- }
+ /* The next two lines ignore swap of low- and high-order 2 bytes. */
+ /* word0(rvp) = (b->x[1] & ~0x800000) | ((e + 129 + 55) << 23); */
+ /* word1(rvp) = b->x[0]; */
+ word0(rvp) = ((b->x[1] & ~0x800000) >> 16) | ((e + 129 + 55) << 7) | (b->x[1] << 16);
+ word1(rvp) = (b->x[0] >> 16) | (b->x[0] << 16);
+#endif
+ Bfree(b);
+}
#endif /*!NO_HEX_FP}*/
- static int
+static int
#ifdef KR_headers
dshift(b, p2) Bigint *b; int p2;
#else
dshift(Bigint *b, int p2)
#endif
{
- int rv = hi0bits(b->x[b->wds-1]) - 4;
- if (p2 > 0)
- rv -= p2;
- return rv & kmask;
- }
+ int rv = hi0bits(b->x[b->wds-1]) - 4;
+ if (p2 > 0) {
+ rv -= p2;
+ }
+ return rv & kmask;
+}
- static int
+static int
quorem
#ifdef KR_headers
- (b, S) Bigint *b, *S;
+(b, S) Bigint *b, *S;
#else
- (Bigint *b, Bigint *S)
+(Bigint *b, Bigint *S)
#endif
{
- int n;
- ULong *bx, *bxe, q, *sx, *sxe;
+ int n;
+ ULong *bx, *bxe, q, *sx, *sxe;
#ifdef ULLong
- ULLong borrow, carry, y, ys;
+ ULLong borrow, carry, y, ys;
#else
- ULong borrow, carry, y, ys;
+ ULong borrow, carry, y, ys;
#ifdef Pack_32
- ULong si, z, zs;
+ ULong si, z, zs;
#endif
#endif
- n = S->wds;
+ n = S->wds;
#ifdef DEBUG
- /*debug*/ if (b->wds > n)
- /*debug*/ Bug("oversize b in quorem");
-#endif
- if (b->wds < n)
- return 0;
- sx = S->x;
- sxe = sx + --n;
- bx = b->x;
- bxe = bx + n;
- q = *bxe / (*sxe + 1); /* ensure q <= true quotient */
+ /*debug*/ if (b->wds > n)
+ /*debug*/{
+ Bug("oversize b in quorem");
+ }
+#endif
+ if (b->wds < n) {
+ return 0;
+ }
+ sx = S->x;
+ sxe = sx + --n;
+ bx = b->x;
+ bxe = bx + n;
+ q = *bxe / (*sxe + 1); /* ensure q <= true quotient */
#ifdef DEBUG
#ifdef NO_STRTOD_BIGCOMP
- /*debug*/ if (q > 9)
+ /*debug*/ if (q > 9)
#else
- /* An oversized q is possible when quorem is called from bigcomp and */
- /* the input is near, e.g., twice the smallest denormalized number. */
- /*debug*/ if (q > 15)
+ /* An oversized q is possible when quorem is called from bigcomp and */
+ /* the input is near, e.g., twice the smallest denormalized number. */
+ /*debug*/ if (q > 15)
#endif
- /*debug*/ Bug("oversized quotient in quorem");
+ /*debug*/ Bug("oversized quotient in quorem");
#endif
- if (q) {
- borrow = 0;
- carry = 0;
- do {
+ if (q) {
+ borrow = 0;
+ carry = 0;
+ do {
#ifdef ULLong
- ys = *sx++ * (ULLong)q + carry;
- carry = ys >> 32;
- y = *bx - (ys & FFFFFFFF) - borrow;
- borrow = y >> 32 & (ULong)1;
- *bx++ = y & FFFFFFFF;
+ ys = *sx++ * (ULLong)q + carry;
+ carry = ys >> 32;
+ y = *bx - (ys & FFFFFFFF) - borrow;
+ borrow = y >> 32 & (ULong)1;
+ *bx++ = y & FFFFFFFF;
#else
#ifdef Pack_32
- si = *sx++;
- ys = (si & 0xffff) * q + carry;
- zs = (si >> 16) * q + (ys >> 16);
- carry = zs >> 16;
- y = (*bx & 0xffff) - (ys & 0xffff) - borrow;
- borrow = (y & 0x10000) >> 16;
- z = (*bx >> 16) - (zs & 0xffff) - borrow;
- borrow = (z & 0x10000) >> 16;
- Storeinc(bx, z, y);
+ si = *sx++;
+ ys = (si & 0xffff) * q + carry;
+ zs = (si >> 16) * q + (ys >> 16);
+ carry = zs >> 16;
+ y = (*bx & 0xffff) - (ys & 0xffff) - borrow;
+ borrow = (y & 0x10000) >> 16;
+ z = (*bx >> 16) - (zs & 0xffff) - borrow;
+ borrow = (z & 0x10000) >> 16;
+ Storeinc(bx, z, y);
#else
- ys = *sx++ * q + carry;
- carry = ys >> 16;
- y = *bx - (ys & 0xffff) - borrow;
- borrow = (y & 0x10000) >> 16;
- *bx++ = y & 0xffff;
-#endif
-#endif
- }
- while(sx <= sxe);
- if (!*bxe) {
- bx = b->x;
- while(--bxe > bx && !*bxe)
- --n;
- b->wds = n;
- }
- }
- if (cmp(b, S) >= 0) {
- q++;
- borrow = 0;
- carry = 0;
- bx = b->x;
- sx = S->x;
- do {
+ ys = *sx++ * q + carry;
+ carry = ys >> 16;
+ y = *bx - (ys & 0xffff) - borrow;
+ borrow = (y & 0x10000) >> 16;
+ *bx++ = y & 0xffff;
+#endif
+#endif
+ }
+ while(sx <= sxe);
+ if (!*bxe) {
+ bx = b->x;
+ while(--bxe > bx && !*bxe) {
+ --n;
+ }
+ b->wds = n;
+ }
+ }
+ if (cmp(b, S) >= 0) {
+ q++;
+ borrow = 0;
+ carry = 0;
+ bx = b->x;
+ sx = S->x;
+ do {
#ifdef ULLong
- ys = *sx++ + carry;
- carry = ys >> 32;
- y = *bx - (ys & FFFFFFFF) - borrow;
- borrow = y >> 32 & (ULong)1;
- *bx++ = y & FFFFFFFF;
+ ys = *sx++ + carry;
+ carry = ys >> 32;
+ y = *bx - (ys & FFFFFFFF) - borrow;
+ borrow = y >> 32 & (ULong)1;
+ *bx++ = y & FFFFFFFF;
#else
#ifdef Pack_32
- si = *sx++;
- ys = (si & 0xffff) + carry;
- zs = (si >> 16) + (ys >> 16);
- carry = zs >> 16;
- y = (*bx & 0xffff) - (ys & 0xffff) - borrow;
- borrow = (y & 0x10000) >> 16;
- z = (*bx >> 16) - (zs & 0xffff) - borrow;
- borrow = (z & 0x10000) >> 16;
- Storeinc(bx, z, y);
+ si = *sx++;
+ ys = (si & 0xffff) + carry;
+ zs = (si >> 16) + (ys >> 16);
+ carry = zs >> 16;
+ y = (*bx & 0xffff) - (ys & 0xffff) - borrow;
+ borrow = (y & 0x10000) >> 16;
+ z = (*bx >> 16) - (zs & 0xffff) - borrow;
+ borrow = (z & 0x10000) >> 16;
+ Storeinc(bx, z, y);
#else
- ys = *sx++ + carry;
- carry = ys >> 16;
- y = *bx - (ys & 0xffff) - borrow;
- borrow = (y & 0x10000) >> 16;
- *bx++ = y & 0xffff;
-#endif
-#endif
- }
- while(sx <= sxe);
- bx = b->x;
- bxe = bx + n;
- if (!*bxe) {
- while(--bxe > bx && !*bxe)
- --n;
- b->wds = n;
- }
- }
- return q;
- }
+ ys = *sx++ + carry;
+ carry = ys >> 16;
+ y = *bx - (ys & 0xffff) - borrow;
+ borrow = (y & 0x10000) >> 16;
+ *bx++ = y & 0xffff;
+#endif
+#endif
+ }
+ while(sx <= sxe);
+ bx = b->x;
+ bxe = bx + n;
+ if (!*bxe) {
+ while(--bxe > bx && !*bxe) {
+ --n;
+ }
+ b->wds = n;
+ }
+ }
+ return q;
+}
#if defined(Avoid_Underflow) || !defined(NO_STRTOD_BIGCOMP) /*{*/
- static double
+static double
sulp
#ifdef KR_headers
- (x, bc) U *x; BCinfo *bc;
+(x, bc) U *x; BCinfo *bc;
#else
- (U *x, BCinfo *bc)
+(U *x, BCinfo *bc)
#endif
{
- U u;
- double rv;
- int i;
-
- rv = ulp(x);
- if (!bc->scale || (i = 2*P + 1 - ((word0(x) & Exp_mask) >> Exp_shift)) <= 0)
- return rv; /* Is there an example where i <= 0 ? */
- word0(&u) = Exp_1 + (i << Exp_shift);
- word1(&u) = 0;
- return rv * u.d;
- }
+ U u;
+ double rv;
+ int i;
+
+ rv = ulp(x);
+ if (!bc->scale || (i = 2*P + 1 - ((word0(x) & Exp_mask) >> Exp_shift)) <= 0) {
+ return rv; /* Is there an example where i <= 0 ? */
+ }
+ word0(&u) = Exp_1 + (i << Exp_shift);
+ word1(&u) = 0;
+ return rv * u.d;
+}
#endif /*}*/
#ifndef NO_STRTOD_BIGCOMP
- static void
+static void
bigcomp
#ifdef KR_headers
- (rv, s0, bc)
- U *rv; CONST char *s0; BCinfo *bc;
+(rv, s0, bc)
+U *rv; CONST char *s0; BCinfo *bc;
#else
- (U *rv, const char *s0, BCinfo *bc)
+(U *rv, const char *s0, BCinfo *bc)
#endif
{
- Bigint *b, *d;
- int b2, bbits, d2, dd, dig, dsign, i, j, nd, nd0, p2, p5, speccase;
-
- dsign = bc->dsign;
- nd = bc->nd;
- nd0 = bc->nd0;
- p5 = nd + bc->e0 - 1;
- speccase = 0;
+ Bigint *b, *d;
+ int b2, bbits, d2, dd, dig, dsign, i, j, nd, nd0, p2, p5, speccase;
+
+ dsign = bc->dsign;
+ nd = bc->nd;
+ nd0 = bc->nd0;
+ p5 = nd + bc->e0 - 1;
+ speccase = 0;
#ifndef Sudden_Underflow
- if (rv->d == 0.) { /* special case: value near underflow-to-zero */
- /* threshold was rounded to zero */
- b = i2b(1);
- p2 = Emin - P + 1;
- bbits = 1;
+ if (rv->d == 0.) { /* special case: value near underflow-to-zero */
+ /* threshold was rounded to zero */
+ b = i2b(1);
+ p2 = Emin - P + 1;
+ bbits = 1;
#ifdef Avoid_Underflow
- word0(rv) = (P+2) << Exp_shift;
+ word0(rv) = (P+2) << Exp_shift;
#else
- word1(rv) = 1;
+ word1(rv) = 1;
#endif
- i = 0;
+ i = 0;
#ifdef Honor_FLT_ROUNDS
- if (bc->rounding == 1)
-#endif
- {
- speccase = 1;
- --p2;
- dsign = 0;
- goto have_i;
- }
- }
- else
-#endif
- b = d2b(rv, &p2, &bbits);
+ if (bc->rounding == 1)
+#endif
+ {
+ speccase = 1;
+ --p2;
+ dsign = 0;
+ goto have_i;
+ }
+ }
+ else
+#endif
+ b = d2b(rv, &p2, &bbits);
#ifdef Avoid_Underflow
- p2 -= bc->scale;
+ p2 -= bc->scale;
#endif
- /* floor(log2(rv)) == bbits - 1 + p2 */
- /* Check for denormal case. */
- i = P - bbits;
- if (i > (j = P - Emin - 1 + p2)) {
+ /* floor(log2(rv)) == bbits - 1 + p2 */
+ /* Check for denormal case. */
+ i = P - bbits;
+ if (i > (j = P - Emin - 1 + p2)) {
#ifdef Sudden_Underflow
- Bfree(b);
- b = i2b(1);
- p2 = Emin;
- i = P - 1;
+ Bfree(b);
+ b = i2b(1);
+ p2 = Emin;
+ i = P - 1;
#ifdef Avoid_Underflow
- word0(rv) = (1 + bc->scale) << Exp_shift;
+ word0(rv) = (1 + bc->scale) << Exp_shift;
#else
- word0(rv) = Exp_msk1;
+ word0(rv) = Exp_msk1;
#endif
- word1(rv) = 0;
+ word1(rv) = 0;
#else
- i = j;
+ i = j;
#endif
- }
+ }
#ifdef Honor_FLT_ROUNDS
- if (bc->rounding != 1) {
- if (i > 0)
- b = lshift(b, i);
- if (dsign)
- b = increment(b);
- }
- else
-#endif
- {
- b = lshift(b, ++i);
- b->x[0] |= 1;
- }
+ if (bc->rounding != 1) {
+ if (i > 0) {
+ b = lshift(b, i);
+ }
+ if (dsign) {
+ b = increment(b);
+ }
+ }
+ else
+#endif
+ {
+ b = lshift(b, ++i);
+ b->x[0] |= 1;
+ }
#ifndef Sudden_Underflow
- have_i:
-#endif
- p2 -= p5 + i;
- d = i2b(1);
- /* Arrange for convenient computation of quotients:
- * shift left if necessary so divisor has 4 leading 0 bits.
- */
- if (p5 > 0)
- d = pow5mult(d, p5);
- else if (p5 < 0)
- b = pow5mult(b, -p5);
- if (p2 > 0) {
- b2 = p2;
- d2 = 0;
- }
- else {
- b2 = 0;
- d2 = -p2;
- }
- i = dshift(d, d2);
- if ((b2 += i) > 0)
- b = lshift(b, b2);
- if ((d2 += i) > 0)
- d = lshift(d, d2);
-
- /* Now b/d = exactly half-way between the two floating-point values */
- /* on either side of the input string. Compute first digit of b/d. */
-
- if (!(dig = quorem(b,d))) {
- b = multadd(b, 10, 0); /* very unlikely */
- dig = quorem(b,d);
- }
-
- /* Compare b/d with s0 */
-
- for(i = 0; i < nd0; ) {
- if ((dd = s0[i++] - '0' - dig))
- goto ret;
- if (!b->x[0] && b->wds == 1) {
- if (i < nd)
- dd = 1;
- goto ret;
- }
- b = multadd(b, 10, 0);
- dig = quorem(b,d);
- }
- for(j = bc->dp1; i++ < nd;) {
- if ((dd = s0[j++] - '0' - dig))
- goto ret;
- if (!b->x[0] && b->wds == 1) {
- if (i < nd)
- dd = 1;
- goto ret;
- }
- b = multadd(b, 10, 0);
- dig = quorem(b,d);
- }
- if (b->x[0] || b->wds > 1 || dig > 0)
- dd = -1;
- ret:
- Bfree(b);
- Bfree(d);
+have_i:
+#endif
+ p2 -= p5 + i;
+ d = i2b(1);
+ /* Arrange for convenient computation of quotients:
+ * shift left if necessary so divisor has 4 leading 0 bits.
+ */
+ if (p5 > 0) {
+ d = pow5mult(d, p5);
+ }
+ else if (p5 < 0) {
+ b = pow5mult(b, -p5);
+ }
+ if (p2 > 0) {
+ b2 = p2;
+ d2 = 0;
+ }
+ else {
+ b2 = 0;
+ d2 = -p2;
+ }
+ i = dshift(d, d2);
+ if ((b2 += i) > 0) {
+ b = lshift(b, b2);
+ }
+ if ((d2 += i) > 0) {
+ d = lshift(d, d2);
+ }
+
+ /* Now b/d = exactly half-way between the two floating-point values */
+ /* on either side of the input string. Compute first digit of b/d. */
+
+ if (!(dig = quorem(b,d))) {
+ b = multadd(b, 10, 0); /* very unlikely */
+ dig = quorem(b,d);
+ }
+
+ /* Compare b/d with s0 */
+
+ for(i = 0; i < nd0; ) {
+ if ((dd = s0[i++] - '0' - dig)) {
+ goto ret;
+ }
+ if (!b->x[0] && b->wds == 1) {
+ if (i < nd) {
+ dd = 1;
+ }
+ goto ret;
+ }
+ b = multadd(b, 10, 0);
+ dig = quorem(b,d);
+ }
+ for(j = bc->dp1; i++ < nd;) {
+ if ((dd = s0[j++] - '0' - dig)) {
+ goto ret;
+ }
+ if (!b->x[0] && b->wds == 1) {
+ if (i < nd) {
+ dd = 1;
+ }
+ goto ret;
+ }
+ b = multadd(b, 10, 0);
+ dig = quorem(b,d);
+ }
+ if (b->x[0] || b->wds > 1 || dig > 0) {
+ dd = -1;
+ }
+ret:
+ Bfree(b);
+ Bfree(d);
#ifdef Honor_FLT_ROUNDS
- if (bc->rounding != 1) {
- if (dd < 0) {
- if (bc->rounding == 0) {
- if (!dsign)
- goto retlow1;
- }
- else if (dsign)
- goto rethi1;
- }
- else if (dd > 0) {
- if (bc->rounding == 0) {
- if (dsign)
- goto rethi1;
- goto ret1;
- }
- if (!dsign)
- goto rethi1;
- dval(rv) += 2.*sulp(rv,bc);
- }
- else {
- bc->inexact = 0;
- if (dsign)
- goto rethi1;
- }
- }
- else
-#endif
- if (speccase) {
- if (dd <= 0)
- rv->d = 0.;
- }
- else if (dd < 0) {
- if (!dsign) /* does not happen for round-near */
+ if (bc->rounding != 1) {
+ if (dd < 0) {
+ if (bc->rounding == 0) {
+ if (!dsign) {
+ goto retlow1;
+ }
+ }
+ else if (dsign) {
+ goto rethi1;
+ }
+ }
+ else if (dd > 0) {
+ if (bc->rounding == 0) {
+ if (dsign) {
+ goto rethi1;
+ }
+ goto ret1;
+ }
+ if (!dsign) {
+ goto rethi1;
+ }
+ dval(rv) += 2.*sulp(rv,bc);
+ }
+ else {
+ bc->inexact = 0;
+ if (dsign) {
+ goto rethi1;
+ }
+ }
+ }
+ else
+#endif
+ if (speccase) {
+ if (dd <= 0) {
+ rv->d = 0.;
+ }
+ }
+ else if (dd < 0) {
+ if (!dsign) /* does not happen for round-near */
retlow1:
- dval(rv) -= sulp(rv,bc);
- }
- else if (dd > 0) {
- if (dsign) {
- rethi1:
- dval(rv) += sulp(rv,bc);
- }
- }
- else {
- /* Exact half-way case: apply round-even rule. */
- if ((j = ((word0(rv) & Exp_mask) >> Exp_shift) - bc->scale) <= 0) {
- i = 1 - j;
- if (i <= 31) {
- if (word1(rv) & (0x1 << i))
- goto odd;
- }
- else if (word0(rv) & (0x1 << (i-32)))
- goto odd;
- }
- else if (word1(rv) & 1) {
- odd:
- if (dsign)
- goto rethi1;
- goto retlow1;
- }
- }
+ dval(rv) -= sulp(rv,bc);
+ }
+ else if (dd > 0) {
+ if (dsign) {
+rethi1:
+ dval(rv) += sulp(rv,bc);
+ }
+ }
+ else {
+ /* Exact half-way case: apply round-even rule. */
+ if ((j = ((word0(rv) & Exp_mask) >> Exp_shift) - bc->scale) <= 0) {
+ i = 1 - j;
+ if (i <= 31) {
+ if (word1(rv) & (0x1 << i)) {
+ goto odd;
+ }
+ }
+ else if (word0(rv) & (0x1 << (i-32))) {
+ goto odd;
+ }
+ }
+ else if (word1(rv) & 1) {
+odd:
+ if (dsign) {
+ goto rethi1;
+ }
+ goto retlow1;
+ }
+ }
#ifdef Honor_FLT_ROUNDS
- ret1:
+ret1:
#endif
- return;
- }
+ return;
+}
#endif /* NO_STRTOD_BIGCOMP */
- double
+double
strtod
#ifdef KR_headers
- (s00, se) CONST char *s00; char **se;
+(s00, se) CONST char *s00; char **se;
#else
- (const char *s00, char **se)
+(const char *s00, char **se)
#endif
{
- int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, e, e1;
- int esign, i, j, k, nd, nd0, nf, nz, nz0, nz1, sign;
- CONST char *s, *s0, *s1;
- double aadj, aadj1;
- Long L;
- U aadj2, adj, rv, rv0;
- ULong y, z;
- BCinfo bc;
- Bigint *bb, *bb1, *bd, *bd0, *bs, *delta;
+ int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, e, e1;
+ int esign, i, j, k, nd, nd0, nf, nz, nz0, nz1, sign;
+ CONST char *s, *s0, *s1;
+ double aadj, aadj1;
+ Long L;
+ U aadj2, adj, rv, rv0;
+ ULong y, z;
+ BCinfo bc;
+ Bigint *bb, *bb1, *bd, *bd0, *bs, *delta;
#ifdef Avoid_Underflow
- ULong Lsb, Lsb1;
+ ULong Lsb, Lsb1;
#endif
#ifdef SET_INEXACT
- int oldinexact;
+ int oldinexact;
#endif
#ifndef NO_STRTOD_BIGCOMP
- int req_bigcomp = 0;
+ int req_bigcomp = 0;
#endif
#ifdef Honor_FLT_ROUNDS /*{*/
#ifdef Trust_FLT_ROUNDS /*{{ only define this if FLT_ROUNDS really works! */
- bc.rounding = Flt_Rounds;
+ bc.rounding = Flt_Rounds;
#else /*}{*/
- bc.rounding = 1;
- switch(fegetround()) {
- case FE_TOWARDZERO: bc.rounding = 0; break;
- case FE_UPWARD: bc.rounding = 2; break;
- case FE_DOWNWARD: bc.rounding = 3;
- }
+ bc.rounding = 1;
+ switch(fegetround()) {
+ case FE_TOWARDZERO: bc.rounding = 0; break;
+ case FE_UPWARD: bc.rounding = 2; break;
+ case FE_DOWNWARD: bc.rounding = 3;
+ }
#endif /*}}*/
#endif /*}*/
#ifdef USE_LOCALE
- CONST char *s2;
-#endif
-
- sign = nz0 = nz1 = nz = bc.dplen = bc.uflchk = 0;
- dval(&rv) = 0.;
- for(s = s00;;s++) switch(*s) {
- case '-':
- sign = 1;
- /* no break */
- case '+':
- if (*++s)
- goto break2;
- /* no break */
- case 0:
- goto ret0;
- case '\t':
- case '\n':
- case '\v':
- case '\f':
- case '\r':
- case ' ':
- continue;
- default:
- goto break2;
- }
- break2:
- if (*s == '0') {
+ CONST char *s2;
+#endif
+
+ sign = nz0 = nz1 = nz = bc.dplen = bc.uflchk = 0;
+ dval(&rv) = 0.;
+ for(s = s00;; s++) switch(*s) {
+ case '-':
+ sign = 1;
+ /* no break */
+ case '+':
+ if (*++s) {
+ goto break2;
+ }
+ /* no break */
+ case 0:
+ goto ret0;
+ case '\t':
+ case '\n':
+ case '\v':
+ case '\f':
+ case '\r':
+ case ' ':
+ continue;
+ default:
+ goto break2;
+ }
+break2:
+ if (*s == '0') {
#ifndef NO_HEX_FP /*{*/
- switch(s[1]) {
- case 'x':
- case 'X':
+ switch(s[1]) {
+ case 'x':
+ case 'X':
#ifdef Honor_FLT_ROUNDS
- gethex(&s, &rv, bc.rounding, sign);
+ gethex(&s, &rv, bc.rounding, sign);
#else
- gethex(&s, &rv, 1, sign);
+ gethex(&s, &rv, 1, sign);
#endif
- goto ret;
- }
+ goto ret;
+ }
#endif /*}*/
- nz0 = 1;
- while(*++s == '0') ;
- if (!*s)
- goto ret;
- }
- s0 = s;
- y = z = 0;
- for(nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++)
- if (nd < 9)
- y = 10*y + c - '0';
- else if (nd < 16)
- z = 10*z + c - '0';
- nd0 = nd;
- bc.dp0 = bc.dp1 = s - s0;
- for(s1 = s; s1 > s0 && *--s1 == '0'; )
- ++nz1;
+ nz0 = 1;
+ while(*++s == '0') ;
+ if (!*s) {
+ goto ret;
+ }
+ }
+ s0 = s;
+ y = z = 0;
+ for(nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++)
+ if (nd < 9) {
+ y = 10*y + c - '0';
+ }
+ else if (nd < 16) {
+ z = 10*z + c - '0';
+ }
+ nd0 = nd;
+ bc.dp0 = bc.dp1 = s - s0;
+ for(s1 = s; s1 > s0 && *--s1 == '0'; ) {
+ ++nz1;
+ }
#ifdef USE_LOCALE
- s1 = localeconv()->decimal_point;
- if (c == *s1) {
- c = '.';
- if (*++s1) {
- s2 = s;
- for(;;) {
- if (*++s2 != *s1) {
- c = 0;
- break;
- }
- if (!*++s1) {
- s = s2;
- break;
- }
- }
- }
- }
-#endif
- if (c == '.') {
- c = *++s;
- bc.dp1 = s - s0;
- bc.dplen = bc.dp1 - bc.dp0;
- if (!nd) {
- for(; c == '0'; c = *++s)
- nz++;
- if (c > '0' && c <= '9') {
- bc.dp0 = s0 - s;
- bc.dp1 = bc.dp0 + bc.dplen;
- s0 = s;
- nf += nz;
- nz = 0;
- goto have_dig;
- }
- goto dig_done;
- }
- for(; c >= '0' && c <= '9'; c = *++s) {
- have_dig:
- nz++;
- if (c -= '0') {
- nf += nz;
- for(i = 1; i < nz; i++)
- if (nd++ < 9)
- y *= 10;
- else if (nd <= DBL_DIG + 1)
- z *= 10;
- if (nd++ < 9)
- y = 10*y + c;
- else if (nd <= DBL_DIG + 1)
- z = 10*z + c;
- nz = nz1 = 0;
- }
- }
- }
- dig_done:
- e = 0;
- if (c == 'e' || c == 'E') {
- if (!nd && !nz && !nz0) {
- goto ret0;
- }
- s00 = s;
- esign = 0;
- switch(c = *++s) {
- case '-':
- esign = 1;
- case '+':
- c = *++s;
- }
- if (c >= '0' && c <= '9') {
- while(c == '0')
- c = *++s;
- if (c > '0' && c <= '9') {
- L = c - '0';
- s1 = s;
- while((c = *++s) >= '0' && c <= '9')
- L = 10*L + c - '0';
- if (s - s1 > 8 || L > 19999)
- /* Avoid confusion from exponents
- * so large that e might overflow.
- */
- e = 19999; /* safe for 16 bit ints */
- else
- e = (int)L;
- if (esign)
- e = -e;
- }
- else
- e = 0;
- }
- else
- s = s00;
- }
- if (!nd) {
- if (!nz && !nz0) {
+ s1 = localeconv()->decimal_point;
+ if (c == *s1) {
+ c = '.';
+ if (*++s1) {
+ s2 = s;
+ for(;;) {
+ if (*++s2 != *s1) {
+ c = 0;
+ break;
+ }
+ if (!*++s1) {
+ s = s2;
+ break;
+ }
+ }
+ }
+ }
+#endif
+ if (c == '.') {
+ c = *++s;
+ bc.dp1 = s - s0;
+ bc.dplen = bc.dp1 - bc.dp0;
+ if (!nd) {
+ for(; c == '0'; c = *++s) {
+ nz++;
+ }
+ if (c > '0' && c <= '9') {
+ bc.dp0 = s0 - s;
+ bc.dp1 = bc.dp0 + bc.dplen;
+ s0 = s;
+ nf += nz;
+ nz = 0;
+ goto have_dig;
+ }
+ goto dig_done;
+ }
+ for(; c >= '0' && c <= '9'; c = *++s) {
+have_dig:
+ nz++;
+ if (c -= '0') {
+ nf += nz;
+ for(i = 1; i < nz; i++)
+ if (nd++ < 9) {
+ y *= 10;
+ }
+ else if (nd <= DBL_DIG + 1) {
+ z *= 10;
+ }
+ if (nd++ < 9) {
+ y = 10*y + c;
+ }
+ else if (nd <= DBL_DIG + 1) {
+ z = 10*z + c;
+ }
+ nz = nz1 = 0;
+ }
+ }
+ }
+dig_done:
+ e = 0;
+ if (c == 'e' || c == 'E') {
+ if (!nd && !nz && !nz0) {
+ goto ret0;
+ }
+ s00 = s;
+ esign = 0;
+ switch(c = *++s) {
+ case '-':
+ esign = 1;
+ case '+':
+ c = *++s;
+ }
+ if (c >= '0' && c <= '9') {
+ while(c == '0') {
+ c = *++s;
+ }
+ if (c > '0' && c <= '9') {
+ L = c - '0';
+ s1 = s;
+ while((c = *++s) >= '0' && c <= '9') {
+ L = 10*L + c - '0';
+ }
+ if (s - s1 > 8 || L > 19999)
+ /* Avoid confusion from exponents
+ * so large that e might overflow.
+ */
+ {
+ e = 19999; /* safe for 16 bit ints */
+ }
+ else {
+ e = (int)L;
+ }
+ if (esign) {
+ e = -e;
+ }
+ }
+ else {
+ e = 0;
+ }
+ }
+ else {
+ s = s00;
+ }
+ }
+ if (!nd) {
+ if (!nz && !nz0) {
#ifdef INFNAN_CHECK
- /* Check for Nan and Infinity */
- if (!bc.dplen)
- switch(c) {
- case 'i':
- case 'I':
- if (match(&s,"nf")) {
- --s;
- if (!match(&s,"inity"))
- ++s;
- word0(&rv) = 0x7ff00000;
- word1(&rv) = 0;
- goto ret;
- }
- break;
- case 'n':
- case 'N':
- if (match(&s, "an")) {
- word0(&rv) = NAN_WORD0;
- word1(&rv) = NAN_WORD1;
+ /* Check for Nan and Infinity */
+ if (!bc.dplen)
+ switch(c) {
+ case 'i':
+ case 'I':
+ if (match(&s,"nf")) {
+ --s;
+ if (!match(&s,"inity")) {
+ ++s;
+ }
+ word0(&rv) = 0x7ff00000;
+ word1(&rv) = 0;
+ goto ret;
+ }
+ break;
+ case 'n':
+ case 'N':
+ if (match(&s, "an")) {
+ word0(&rv) = NAN_WORD0;
+ word1(&rv) = NAN_WORD1;
#ifndef No_Hex_NaN
- if (*s == '(') /*)*/
- hexnan(&rv, &s);
+ if (*s == '(') { /*)*/
+ hexnan(&rv, &s);
+ }
#endif
- goto ret;
- }
- }
+ goto ret;
+ }
+ }
#endif /* INFNAN_CHECK */
- ret0:
- s = s00;
- sign = 0;
- }
- goto ret;
- }
- bc.e0 = e1 = e -= nf;
-
- /* Now we have nd0 digits, starting at s0, followed by a
- * decimal point, followed by nd-nd0 digits. The number we're
- * after is the integer represented by those digits times
- * 10**e */
-
- if (!nd0)
- nd0 = nd;
- k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1;
- dval(&rv) = y;
- if (k > 9) {
+ret0:
+ s = s00;
+ sign = 0;
+ }
+ goto ret;
+ }
+ bc.e0 = e1 = e -= nf;
+
+ /* Now we have nd0 digits, starting at s0, followed by a
+ * decimal point, followed by nd-nd0 digits. The number we're
+ * after is the integer represented by those digits times
+ * 10**e */
+
+ if (!nd0) {
+ nd0 = nd;
+ }
+ k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1;
+ dval(&rv) = y;
+ if (k > 9) {
#ifdef SET_INEXACT
- if (k > DBL_DIG)
- oldinexact = get_inexact();
-#endif
- dval(&rv) = tens[k - 9] * dval(&rv) + z;
- }
- bd0 = 0;
- if (nd <= DBL_DIG
+ if (k > DBL_DIG) {
+ oldinexact = get_inexact();
+ }
+#endif
+ dval(&rv) = tens[k - 9] * dval(&rv) + z;
+ }
+ bd0 = 0;
+ if (nd <= DBL_DIG
#ifndef RND_PRODQUOT
#ifndef Honor_FLT_ROUNDS
- && Flt_Rounds == 1
+ && Flt_Rounds == 1
#endif
#endif
- ) {
- if (!e)
- goto ret;
+ ) {
+ if (!e) {
+ goto ret;
+ }
#ifndef ROUND_BIASED_without_Round_Up
- if (e > 0) {
- if (e <= Ten_pmax) {
+ if (e > 0) {
+ if (e <= Ten_pmax) {
#ifdef VAX
- goto vax_ovfl_check;
+ goto vax_ovfl_check;
#else
#ifdef Honor_FLT_ROUNDS
- /* round correctly FLT_ROUNDS = 2 or 3 */
- if (sign) {
- rv.d = -rv.d;
- sign = 0;
- }
-#endif
- /* rv = */ rounded_product(dval(&rv), tens[e]);
- goto ret;
-#endif
- }
- i = DBL_DIG - nd;
- if (e <= Ten_pmax + i) {
- /* A fancier test would sometimes let us do
- * this for larger i values.
- */
+ /* round correctly FLT_ROUNDS = 2 or 3 */
+ if (sign) {
+ rv.d = -rv.d;
+ sign = 0;
+ }
+#endif
+ /* rv = */ rounded_product(dval(&rv), tens[e]);
+ goto ret;
+#endif
+ }
+ i = DBL_DIG - nd;
+ if (e <= Ten_pmax + i) {
+ /* A fancier test would sometimes let us do
+ * this for larger i values.
+ */
#ifdef Honor_FLT_ROUNDS
- /* round correctly FLT_ROUNDS = 2 or 3 */
- if (sign) {
- rv.d = -rv.d;
- sign = 0;
- }
-#endif
- e -= i;
- dval(&rv) *= tens[i];
+ /* round correctly FLT_ROUNDS = 2 or 3 */
+ if (sign) {
+ rv.d = -rv.d;
+ sign = 0;
+ }
+#endif
+ e -= i;
+ dval(&rv) *= tens[i];
#ifdef VAX
- /* VAX exponent range is so narrow we must
- * worry about overflow here...
- */
- vax_ovfl_check:
- word0(&rv) -= P*Exp_msk1;
- /* rv = */ rounded_product(dval(&rv), tens[e]);
- if ((word0(&rv) & Exp_mask)
- > Exp_msk1*(DBL_MAX_EXP+Bias-1-P))
- goto ovfl;
- word0(&rv) += P*Exp_msk1;
+ /* VAX exponent range is so narrow we must
+ * worry about overflow here...
+ */
+vax_ovfl_check:
+ word0(&rv) -= P*Exp_msk1;
+ /* rv = */ rounded_product(dval(&rv), tens[e]);
+ if ((word0(&rv) & Exp_mask)
+ > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) {
+ goto ovfl;
+ }
+ word0(&rv) += P*Exp_msk1;
#else
- /* rv = */ rounded_product(dval(&rv), tens[e]);
+ /* rv = */ rounded_product(dval(&rv), tens[e]);
#endif
- goto ret;
- }
- }
+ goto ret;
+ }
+ }
#ifndef Inaccurate_Divide
- else if (e >= -Ten_pmax) {
+ else if (e >= -Ten_pmax) {
#ifdef Honor_FLT_ROUNDS
- /* round correctly FLT_ROUNDS = 2 or 3 */
- if (sign) {
- rv.d = -rv.d;
- sign = 0;
- }
+ /* round correctly FLT_ROUNDS = 2 or 3 */
+ if (sign) {
+ rv.d = -rv.d;
+ sign = 0;
+ }
#endif
- /* rv = */ rounded_quotient(dval(&rv), tens[-e]);
- goto ret;
- }
+ /* rv = */ rounded_quotient(dval(&rv), tens[-e]);
+ goto ret;
+ }
#endif
#endif /* ROUND_BIASED_without_Round_Up */
- }
- e1 += nd - k;
+ }
+ e1 += nd - k;
#ifdef IEEE_Arith
#ifdef SET_INEXACT
- bc.inexact = 1;
- if (k <= DBL_DIG)
- oldinexact = get_inexact();
+ bc.inexact = 1;
+ if (k <= DBL_DIG) {
+ oldinexact = get_inexact();
+ }
#endif
#ifdef Avoid_Underflow
- bc.scale = 0;
+ bc.scale = 0;
#endif
#ifdef Honor_FLT_ROUNDS
- if (bc.rounding >= 2) {
- if (sign)
- bc.rounding = bc.rounding == 2 ? 0 : 2;
- else
- if (bc.rounding != 2)
- bc.rounding = 0;
- }
+ if (bc.rounding >= 2) {
+ if (sign) {
+ bc.rounding = bc.rounding == 2 ? 0 : 2;
+ }
+ else if (bc.rounding != 2) {
+ bc.rounding = 0;
+ }
+ }
#endif
#endif /*IEEE_Arith*/
- /* Get starting approximation = rv * 10**e1 */
+ /* Get starting approximation = rv * 10**e1 */
- if (e1 > 0) {
- if ((i = e1 & 15))
- dval(&rv) *= tens[i];
- if (e1 &= ~15) {
- if (e1 > DBL_MAX_10_EXP) {
- ovfl:
- /* Can't trust HUGE_VAL */
+ if (e1 > 0) {
+ if ((i = e1 & 15)) {
+ dval(&rv) *= tens[i];
+ }
+ if (e1 &= ~15) {
+ if (e1 > DBL_MAX_10_EXP) {
+ovfl:
+ /* Can't trust HUGE_VAL */
#ifdef IEEE_Arith
#ifdef Honor_FLT_ROUNDS
- switch(bc.rounding) {
- case 0: /* toward 0 */
- case 3: /* toward -infinity */
- word0(&rv) = Big0;
- word1(&rv) = Big1;
- break;
- default:
- word0(&rv) = Exp_mask;
- word1(&rv) = 0;
- }
+ switch(bc.rounding) {
+ case 0: /* toward 0 */
+ case 3: /* toward -infinity */
+ word0(&rv) = Big0;
+ word1(&rv) = Big1;
+ break;
+ default:
+ word0(&rv) = Exp_mask;
+ word1(&rv) = 0;
+ }
#else /*Honor_FLT_ROUNDS*/
- word0(&rv) = Exp_mask;
- word1(&rv) = 0;
+ word0(&rv) = Exp_mask;
+ word1(&rv) = 0;
#endif /*Honor_FLT_ROUNDS*/
#ifdef SET_INEXACT
- /* set overflow bit */
- dval(&rv0) = 1e300;
- dval(&rv0) *= dval(&rv0);
+ /* set overflow bit */
+ dval(&rv0) = 1e300;
+ dval(&rv0) *= dval(&rv0);
#endif
#else /*IEEE_Arith*/
- word0(&rv) = Big0;
- word1(&rv) = Big1;
+ word0(&rv) = Big0;
+ word1(&rv) = Big1;
#endif /*IEEE_Arith*/
- range_err:
- if (bd0) {
- Bfree(bb);
- Bfree(bd);
- Bfree(bs);
- Bfree(bd0);
- Bfree(delta);
- }
+range_err:
+ if (bd0) {
+ Bfree(bb);
+ Bfree(bd);
+ Bfree(bs);
+ Bfree(bd0);
+ Bfree(delta);
+ }
#ifndef NO_ERRNO
- errno = ERANGE;
-#endif
- goto ret;
- }
- e1 >>= 4;
- for(j = 0; e1 > 1; j++, e1 >>= 1)
- if (e1 & 1)
- dval(&rv) *= bigtens[j];
- /* The last multiplication could overflow. */
- word0(&rv) -= P*Exp_msk1;
- dval(&rv) *= bigtens[j];
- if ((z = word0(&rv) & Exp_mask)
- > Exp_msk1*(DBL_MAX_EXP+Bias-P))
- goto ovfl;
- if (z > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) {
- /* set to largest number */
- /* (Can't trust DBL_MAX) */
- word0(&rv) = Big0;
- word1(&rv) = Big1;
- }
- else
- word0(&rv) += P*Exp_msk1;
- }
- }
- else if (e1 < 0) {
- e1 = -e1;
- if ((i = e1 & 15))
- dval(&rv) /= tens[i];
- if (e1 >>= 4) {
- if (e1 >= 1 << n_bigtens)
- goto undfl;
+ errno = ERANGE;
+#endif
+ goto ret;
+ }
+ e1 >>= 4;
+ for(j = 0; e1 > 1; j++, e1 >>= 1)
+ if (e1 & 1) {
+ dval(&rv) *= bigtens[j];
+ }
+ /* The last multiplication could overflow. */
+ word0(&rv) -= P*Exp_msk1;
+ dval(&rv) *= bigtens[j];
+ if ((z = word0(&rv) & Exp_mask)
+ > Exp_msk1*(DBL_MAX_EXP+Bias-P)) {
+ goto ovfl;
+ }
+ if (z > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) {
+ /* set to largest number */
+ /* (Can't trust DBL_MAX) */
+ word0(&rv) = Big0;
+ word1(&rv) = Big1;
+ }
+ else {
+ word0(&rv) += P*Exp_msk1;
+ }
+ }
+ }
+ else if (e1 < 0) {
+ e1 = -e1;
+ if ((i = e1 & 15)) {
+ dval(&rv) /= tens[i];
+ }
+ if (e1 >>= 4) {
+ if (e1 >= 1 << n_bigtens) {
+ goto undfl;
+ }
#ifdef Avoid_Underflow
- if (e1 & Scale_Bit)
- bc.scale = 2*P;
- for(j = 0; e1 > 0; j++, e1 >>= 1)
- if (e1 & 1)
- dval(&rv) *= tinytens[j];
- if (bc.scale && (j = 2*P + 1 - ((word0(&rv) & Exp_mask)
- >> Exp_shift)) > 0) {
- /* scaled rv is denormal; clear j low bits */
- if (j >= 32) {
- if (j > 54)
- goto undfl;
- word1(&rv) = 0;
- if (j >= 53)
- word0(&rv) = (P+2)*Exp_msk1;
- else
- word0(&rv) &= 0xffffffff << (j-32);
- }
- else
- word1(&rv) &= 0xffffffff << j;
- }
+ if (e1 & Scale_Bit) {
+ bc.scale = 2*P;
+ }
+ for(j = 0; e1 > 0; j++, e1 >>= 1)
+ if (e1 & 1) {
+ dval(&rv) *= tinytens[j];
+ }
+ if (bc.scale && (j = 2*P + 1 - ((word0(&rv) & Exp_mask)
+ >> Exp_shift)) > 0) {
+ /* scaled rv is denormal; clear j low bits */
+ if (j >= 32) {
+ if (j > 54) {
+ goto undfl;
+ }
+ word1(&rv) = 0;
+ if (j >= 53) {
+ word0(&rv) = (P+2)*Exp_msk1;
+ }
+ else {
+ word0(&rv) &= 0xffffffff << (j-32);
+ }
+ }
+ else {
+ word1(&rv) &= 0xffffffff << j;
+ }
+ }
#else
- for(j = 0; e1 > 1; j++, e1 >>= 1)
- if (e1 & 1)
- dval(&rv) *= tinytens[j];
- /* The last multiplication could underflow. */
- dval(&rv0) = dval(&rv);
- dval(&rv) *= tinytens[j];
- if (!dval(&rv)) {
- dval(&rv) = 2.*dval(&rv0);
- dval(&rv) *= tinytens[j];
-#endif
- if (!dval(&rv)) {
- undfl:
- dval(&rv) = 0.;
- goto range_err;
- }
+ for(j = 0; e1 > 1; j++, e1 >>= 1)
+ if (e1 & 1) {
+ dval(&rv) *= tinytens[j];
+ }
+ /* The last multiplication could underflow. */
+ dval(&rv0) = dval(&rv);
+ dval(&rv) *= tinytens[j];
+ if (!dval(&rv)) {
+ dval(&rv) = 2.*dval(&rv0);
+ dval(&rv) *= tinytens[j];
+#endif
+ if (!dval(&rv)) {
+undfl:
+ dval(&rv) = 0.;
+ goto range_err;
+ }
#ifndef Avoid_Underflow
- word0(&rv) = Tiny0;
- word1(&rv) = Tiny1;
- /* The refinement below will clean
- * this approximation up.
- */
- }
-#endif
- }
- }
+ word0(&rv) = Tiny0;
+ word1(&rv) = Tiny1;
+ /* The refinement below will clean
+ * this approximation up.
+ */
+ }
+#endif
+ }
+}
- /* Now the hard part -- adjusting rv to the correct value.*/
+/* Now the hard part -- adjusting rv to the correct value.*/
- /* Put digits into bd: true value = bd * 10^e */
+/* Put digits into bd: true value = bd * 10^e */
- bc.nd = nd - nz1;
+bc.nd = nd - nz1;
#ifndef NO_STRTOD_BIGCOMP
- bc.nd0 = nd0; /* Only needed if nd > strtod_diglim, but done here */
- /* to silence an erroneous warning about bc.nd0 */
- /* possibly not being initialized. */
- if (nd > strtod_diglim) {
- /* ASSERT(strtod_diglim >= 18); 18 == one more than the */
- /* minimum number of decimal digits to distinguish double values */
- /* in IEEE arithmetic. */
- i = j = 18;
- if (i > nd0)
- j += bc.dplen;
- for(;;) {
- if (--j < bc.dp1 && j >= bc.dp0)
- j = bc.dp0 - 1;
- if (s0[j] != '0')
- break;
- --i;
- }
- e += nd - i;
- nd = i;
- if (nd0 > nd)
- nd0 = nd;
- if (nd < 9) { /* must recompute y */
- y = 0;
- for(i = 0; i < nd0; ++i)
- y = 10*y + s0[i] - '0';
- for(j = bc.dp1; i < nd; ++i)
- y = 10*y + s0[j++] - '0';
- }
- }
-#endif
- bd0 = s2b(s0, nd0, nd, y, bc.dplen);
-
- for(;;) {
- bd = Balloc(bd0->k);
- Bcopy(bd, bd0);
- bb = d2b(&rv, &bbe, &bbbits); /* rv = bb * 2^bbe */
- bs = i2b(1);
-
- if (e >= 0) {
- bb2 = bb5 = 0;
- bd2 = bd5 = e;
- }
- else {
- bb2 = bb5 = -e;
- bd2 = bd5 = 0;
- }
- if (bbe >= 0)
- bb2 += bbe;
- else
- bd2 -= bbe;
- bs2 = bb2;
+bc.nd0 = nd0; /* Only needed if nd > strtod_diglim, but done here */
+/* to silence an erroneous warning about bc.nd0 */
+/* possibly not being initialized. */
+if (nd > strtod_diglim) {
+ /* ASSERT(strtod_diglim >= 18); 18 == one more than the */
+ /* minimum number of decimal digits to distinguish double values */
+ /* in IEEE arithmetic. */
+ i = j = 18;
+ if (i > nd0) {
+ j += bc.dplen;
+ }
+ for(;;) {
+ if (--j < bc.dp1 && j >= bc.dp0) {
+ j = bc.dp0 - 1;
+ }
+ if (s0[j] != '0') {
+ break;
+ }
+ --i;
+ }
+ e += nd - i;
+ nd = i;
+ if (nd0 > nd) {
+ nd0 = nd;
+ }
+ if (nd < 9) { /* must recompute y */
+ y = 0;
+ for(i = 0; i < nd0; ++i) {
+ y = 10*y + s0[i] - '0';
+ }
+ for(j = bc.dp1; i < nd; ++i) {
+ y = 10*y + s0[j++] - '0';
+ }
+ }
+}
+#endif
+bd0 = s2b(s0, nd0, nd, y, bc.dplen);
+
+for(;;) {
+ bd = Balloc(bd0->k);
+ Bcopy(bd, bd0);
+ bb = d2b(&rv, &bbe, &bbbits); /* rv = bb * 2^bbe */
+ bs = i2b(1);
+
+ if (e >= 0) {
+ bb2 = bb5 = 0;
+ bd2 = bd5 = e;
+ }
+ else {
+ bb2 = bb5 = -e;
+ bd2 = bd5 = 0;
+ }
+ if (bbe >= 0) {
+ bb2 += bbe;
+ }
+ else {
+ bd2 -= bbe;
+ }
+ bs2 = bb2;
#ifdef Honor_FLT_ROUNDS
- if (bc.rounding != 1)
- bs2++;
+ if (bc.rounding != 1) {
+ bs2++;
+ }
#endif
#ifdef Avoid_Underflow
- Lsb = LSB;
- Lsb1 = 0;
- j = bbe - bc.scale;
- i = j + bbbits - 1; /* logb(rv) */
- j = P + 1 - bbbits;
- if (i < Emin) { /* denormal */
- i = Emin - i;
- j -= i;
- if (i < 32)
- Lsb <<= i;
- else if (i < 52)
- Lsb1 = Lsb << (i-32);
- else
- Lsb1 = Exp_mask;
- }
+ Lsb = LSB;
+ Lsb1 = 0;
+ j = bbe - bc.scale;
+ i = j + bbbits - 1; /* logb(rv) */
+ j = P + 1 - bbbits;
+ if (i < Emin) { /* denormal */
+ i = Emin - i;
+ j -= i;
+ if (i < 32) {
+ Lsb <<= i;
+ }
+ else if (i < 52) {
+ Lsb1 = Lsb << (i-32);
+ }
+ else {
+ Lsb1 = Exp_mask;
+ }
+ }
#else /*Avoid_Underflow*/
#ifdef Sudden_Underflow
#ifdef IBM
- j = 1 + 4*P - 3 - bbbits + ((bbe + bbbits - 1) & 3);
+ j = 1 + 4*P - 3 - bbbits + ((bbe + bbbits - 1) & 3);
#else
- j = P + 1 - bbbits;
+ j = P + 1 - bbbits;
#endif
#else /*Sudden_Underflow*/
- j = bbe;
- i = j + bbbits - 1; /* logb(rv) */
- if (i < Emin) /* denormal */
- j += P - Emin;
- else
- j = P + 1 - bbbits;
+ j = bbe;
+ i = j + bbbits - 1; /* logb(rv) */
+ if (i < Emin) { /* denormal */
+ j += P - Emin;
+ }
+ else {
+ j = P + 1 - bbbits;
+ }
#endif /*Sudden_Underflow*/
#endif /*Avoid_Underflow*/
- bb2 += j;
- bd2 += j;
+ bb2 += j;
+ bd2 += j;
#ifdef Avoid_Underflow
- bd2 += bc.scale;
-#endif
- i = bb2 < bd2 ? bb2 : bd2;
- if (i > bs2)
- i = bs2;
- if (i > 0) {
- bb2 -= i;
- bd2 -= i;
- bs2 -= i;
- }
- if (bb5 > 0) {
- bs = pow5mult(bs, bb5);
- bb1 = mult(bs, bb);
- Bfree(bb);
- bb = bb1;
- }
- if (bb2 > 0)
- bb = lshift(bb, bb2);
- if (bd5 > 0)
- bd = pow5mult(bd, bd5);
- if (bd2 > 0)
- bd = lshift(bd, bd2);
- if (bs2 > 0)
- bs = lshift(bs, bs2);
- delta = diff(bb, bd);
- bc.dsign = delta->sign;
- delta->sign = 0;
- i = cmp(delta, bs);
+ bd2 += bc.scale;
+#endif
+ i = bb2 < bd2 ? bb2 : bd2;
+ if (i > bs2) {
+ i = bs2;
+ }
+ if (i > 0) {
+ bb2 -= i;
+ bd2 -= i;
+ bs2 -= i;
+ }
+ if (bb5 > 0) {
+ bs = pow5mult(bs, bb5);
+ bb1 = mult(bs, bb);
+ Bfree(bb);
+ bb = bb1;
+ }
+ if (bb2 > 0) {
+ bb = lshift(bb, bb2);
+ }
+ if (bd5 > 0) {
+ bd = pow5mult(bd, bd5);
+ }
+ if (bd2 > 0) {
+ bd = lshift(bd, bd2);
+ }
+ if (bs2 > 0) {
+ bs = lshift(bs, bs2);
+ }
+ delta = diff(bb, bd);
+ bc.dsign = delta->sign;
+ delta->sign = 0;
+ i = cmp(delta, bs);
#ifndef NO_STRTOD_BIGCOMP /*{*/
- if (bc.nd > nd && i <= 0) {
- if (bc.dsign) {
- /* Must use bigcomp(). */
- req_bigcomp = 1;
- break;
- }
+ if (bc.nd > nd && i <= 0) {
+ if (bc.dsign) {
+ /* Must use bigcomp(). */
+ req_bigcomp = 1;
+ break;
+ }
#ifdef Honor_FLT_ROUNDS
- if (bc.rounding != 1) {
- if (i < 0) {
- req_bigcomp = 1;
- break;
- }
- }
- else
-#endif
- i = -1; /* Discarded digits make delta smaller. */
- }
+ if (bc.rounding != 1) {
+ if (i < 0) {
+ req_bigcomp = 1;
+ break;
+ }
+ }
+ else
+#endif
+ i = -1; /* Discarded digits make delta smaller. */
+ }
#endif /*}*/
#ifdef Honor_FLT_ROUNDS /*{*/
- if (bc.rounding != 1) {
- if (i < 0) {
- /* Error is less than an ulp */
- if (!delta->x[0] && delta->wds <= 1) {
- /* exact */
+ if (bc.rounding != 1) {
+ if (i < 0) {
+ /* Error is less than an ulp */
+ if (!delta->x[0] && delta->wds <= 1) {
+ /* exact */
#ifdef SET_INEXACT
- bc.inexact = 0;
-#endif
- break;
- }
- if (bc.rounding) {
- if (bc.dsign) {
- adj.d = 1.;
- goto apply_adj;
- }
- }
- else if (!bc.dsign) {
- adj.d = -1.;
- if (!word1(&rv)
- && !(word0(&rv) & Frac_mask)) {
- y = word0(&rv) & Exp_mask;
+ bc.inexact = 0;
+#endif
+ break;
+ }
+ if (bc.rounding) {
+ if (bc.dsign) {
+ adj.d = 1.;
+ goto apply_adj;
+ }
+ }
+ else if (!bc.dsign) {
+ adj.d = -1.;
+ if (!word1(&rv)
+ && !(word0(&rv) & Frac_mask)) {
+ y = word0(&rv) & Exp_mask;
#ifdef Avoid_Underflow
- if (!bc.scale || y > 2*P*Exp_msk1)
+ if (!bc.scale || y > 2*P*Exp_msk1)
#else
- if (y)
-#endif
- {
- delta = lshift(delta,Log2P);
- if (cmp(delta, bs) <= 0)
- adj.d = -0.5;
- }
- }
- apply_adj:
+ if (y)
+#endif
+ {
+ delta = lshift(delta,Log2P);
+ if (cmp(delta, bs) <= 0) {
+ adj.d = -0.5;
+ }
+ }
+ }
+apply_adj:
#ifdef Avoid_Underflow /*{*/
- if (bc.scale && (y = word0(&rv) & Exp_mask)
- <= 2*P*Exp_msk1)
- word0(&adj) += (2*P+1)*Exp_msk1 - y;
+ if (bc.scale && (y = word0(&rv) & Exp_mask)
+ <= 2*P*Exp_msk1) {
+ word0(&adj) += (2*P+1)*Exp_msk1 - y;
+ }
#else
#ifdef Sudden_Underflow
- if ((word0(&rv) & Exp_mask) <=
- P*Exp_msk1) {
- word0(&rv) += P*Exp_msk1;
- dval(&rv) += adj.d*ulp(dval(&rv));
- word0(&rv) -= P*Exp_msk1;
- }
- else
+ if ((word0(&rv) & Exp_mask) <=
+ P*Exp_msk1) {
+ word0(&rv) += P*Exp_msk1;
+ dval(&rv) += adj.d*ulp(dval(&rv));
+ word0(&rv) -= P*Exp_msk1;
+ }
+ else
#endif /*Sudden_Underflow*/
#endif /*Avoid_Underflow}*/
- dval(&rv) += adj.d*ulp(&rv);
- }
- break;
- }
- adj.d = ratio(delta, bs);
- if (adj.d < 1.)
- adj.d = 1.;
- if (adj.d <= 0x7ffffffe) {
- /* adj = rounding ? ceil(adj) : floor(adj); */
- y = adj.d;
- if (y != adj.d) {
- if (!((bc.rounding>>1) ^ bc.dsign))
- y++;
- adj.d = y;
- }
- }
+ dval(&rv) += adj.d*ulp(&rv);
+ }
+ break;
+ }
+ adj.d = ratio(delta, bs);
+ if (adj.d < 1.) {
+ adj.d = 1.;
+ }
+ if (adj.d <= 0x7ffffffe) {
+ /* adj = rounding ? ceil(adj) : floor(adj); */
+ y = adj.d;
+ if (y != adj.d) {
+ if (!((bc.rounding>>1) ^ bc.dsign)) {
+ y++;
+ }
+ adj.d = y;
+ }
+ }
#ifdef Avoid_Underflow /*{*/
- if (bc.scale && (y = word0(&rv) & Exp_mask) <= 2*P*Exp_msk1)
- word0(&adj) += (2*P+1)*Exp_msk1 - y;
+ if (bc.scale && (y = word0(&rv) & Exp_mask) <= 2*P*Exp_msk1) {
+ word0(&adj) += (2*P+1)*Exp_msk1 - y;
+ }
#else
#ifdef Sudden_Underflow
- if ((word0(&rv) & Exp_mask) <= P*Exp_msk1) {
- word0(&rv) += P*Exp_msk1;
- adj.d *= ulp(dval(&rv));
- if (bc.dsign)
- dval(&rv) += adj.d;
- else
- dval(&rv) -= adj.d;
- word0(&rv) -= P*Exp_msk1;
- goto cont;
- }
+ if ((word0(&rv) & Exp_mask) <= P*Exp_msk1) {
+ word0(&rv) += P*Exp_msk1;
+ adj.d *= ulp(dval(&rv));
+ if (bc.dsign) {
+ dval(&rv) += adj.d;
+ }
+ else {
+ dval(&rv) -= adj.d;
+ }
+ word0(&rv) -= P*Exp_msk1;
+ goto cont;
+ }
#endif /*Sudden_Underflow*/
#endif /*Avoid_Underflow}*/
- adj.d *= ulp(&rv);
- if (bc.dsign) {
- if (word0(&rv) == Big0 && word1(&rv) == Big1)
- goto ovfl;
- dval(&rv) += adj.d;
- }
- else
- dval(&rv) -= adj.d;
- goto cont;
- }
+ adj.d *= ulp(&rv);
+ if (bc.dsign) {
+ if (word0(&rv) == Big0 && word1(&rv) == Big1) {
+ goto ovfl;
+ }
+ dval(&rv) += adj.d;
+ }
+ else {
+ dval(&rv) -= adj.d;
+ }
+ goto cont;
+ }
#endif /*}Honor_FLT_ROUNDS*/
- if (i < 0) {
- /* Error is less than half an ulp -- check for
- * special case of mantissa a power of two.
- */
- if (bc.dsign || word1(&rv) || word0(&rv) & Bndry_mask
+ if (i < 0) {
+ /* Error is less than half an ulp -- check for
+ * special case of mantissa a power of two.
+ */
+ if (bc.dsign || word1(&rv) || word0(&rv) & Bndry_mask
#ifdef IEEE_Arith /*{*/
#ifdef Avoid_Underflow
- || (word0(&rv) & Exp_mask) <= (2*P+1)*Exp_msk1
+ || (word0(&rv) & Exp_mask) <= (2*P+1)*Exp_msk1
#else
- || (word0(&rv) & Exp_mask) <= Exp_msk1
+ || (word0(&rv) & Exp_mask) <= Exp_msk1
#endif
#endif /*}*/
- ) {
+ ) {
#ifdef SET_INEXACT
- if (!delta->x[0] && delta->wds <= 1)
- bc.inexact = 0;
-#endif
- break;
- }
- if (!delta->x[0] && delta->wds <= 1) {
- /* exact result */
+ if (!delta->x[0] && delta->wds <= 1) {
+ bc.inexact = 0;
+ }
+#endif
+ break;
+ }
+ if (!delta->x[0] && delta->wds <= 1) {
+ /* exact result */
#ifdef SET_INEXACT
- bc.inexact = 0;
-#endif
- break;
- }
- delta = lshift(delta,Log2P);
- if (cmp(delta, bs) > 0)
- goto drop_down;
- break;
- }
- if (i == 0) {
- /* exactly half-way between */
- if (bc.dsign) {
- if ((word0(&rv) & Bndry_mask1) == Bndry_mask1
- && word1(&rv) == (
+ bc.inexact = 0;
+#endif
+ break;
+ }
+ delta = lshift(delta,Log2P);
+ if (cmp(delta, bs) > 0) {
+ goto drop_down;
+ }
+ break;
+ }
+ if (i == 0) {
+ /* exactly half-way between */
+ if (bc.dsign) {
+ if ((word0(&rv) & Bndry_mask1) == Bndry_mask1
+ && word1(&rv) == (
#ifdef Avoid_Underflow
- (bc.scale && (y = word0(&rv) & Exp_mask) <= 2*P*Exp_msk1)
- ? (0xffffffff & (0xffffffff << (2*P+1-(y>>Exp_shift)))) :
-#endif
- 0xffffffff)) {
- /*boundary case -- increment exponent*/
- if (word0(&rv) == Big0 && word1(&rv) == Big1)
- goto ovfl;
- word0(&rv) = (word0(&rv) & Exp_mask)
- + Exp_msk1
+ (bc.scale && (y = word0(&rv) & Exp_mask) <= 2*P*Exp_msk1)
+ ? (0xffffffff & (0xffffffff << (2*P+1-(y>>Exp_shift)))) :
+#endif
+ 0xffffffff)) {
+ /*boundary case -- increment exponent*/
+ if (word0(&rv) == Big0 && word1(&rv) == Big1) {
+ goto ovfl;
+ }
+ word0(&rv) = (word0(&rv) & Exp_mask)
+ + Exp_msk1
#ifdef IBM
- | Exp_msk1 >> 4
+ | Exp_msk1 >> 4
#endif
- ;
- word1(&rv) = 0;
+ ;
+ word1(&rv) = 0;
#ifdef Avoid_Underflow
- bc.dsign = 0;
-#endif
- break;
- }
- }
- else if (!(word0(&rv) & Bndry_mask) && !word1(&rv)) {
- drop_down:
- /* boundary case -- decrement exponent */
+ bc.dsign = 0;
+#endif
+ break;
+ }
+ }
+ else if (!(word0(&rv) & Bndry_mask) && !word1(&rv)) {
+drop_down:
+ /* boundary case -- decrement exponent */
#ifdef Sudden_Underflow /*{{*/
- L = word0(&rv) & Exp_mask;
+ L = word0(&rv) & Exp_mask;
#ifdef IBM
- if (L < Exp_msk1)
+ if (L < Exp_msk1)
#else
#ifdef Avoid_Underflow
- if (L <= (bc.scale ? (2*P+1)*Exp_msk1 : Exp_msk1))
+ if (L <= (bc.scale ? (2*P+1)*Exp_msk1 : Exp_msk1))
#else
- if (L <= Exp_msk1)
+ if (L <= Exp_msk1)
#endif /*Avoid_Underflow*/
#endif /*IBM*/
- {
- if (bc.nd >nd) {
- bc.uflchk = 1;
- break;
- }
- goto undfl;
- }
- L -= Exp_msk1;
+ {
+ if (bc.nd >nd) {
+ bc.uflchk = 1;
+ break;
+ }
+ goto undfl;
+ }
+ L -= Exp_msk1;
#else /*Sudden_Underflow}{*/
#ifdef Avoid_Underflow
- if (bc.scale) {
- L = word0(&rv) & Exp_mask;
- if (L <= (2*P+1)*Exp_msk1) {
- if (L > (P+2)*Exp_msk1)
- /* round even ==> */
- /* accept rv */
- break;
- /* rv = smallest denormal */
- if (bc.nd >nd) {
- bc.uflchk = 1;
- break;
- }
- goto undfl;
- }
- }
+ if (bc.scale) {
+ L = word0(&rv) & Exp_mask;
+ if (L <= (2*P+1)*Exp_msk1) {
+ if (L > (P+2)*Exp_msk1)
+ /* round even ==> */
+ /* accept rv */
+ {
+ break;
+ }
+ /* rv = smallest denormal */
+ if (bc.nd >nd) {
+ bc.uflchk = 1;
+ break;
+ }
+ goto undfl;
+ }
+ }
#endif /*Avoid_Underflow*/
- L = (word0(&rv) & Exp_mask) - Exp_msk1;
+ L = (word0(&rv) & Exp_mask) - Exp_msk1;
#endif /*Sudden_Underflow}}*/
- word0(&rv) = L | Bndry_mask1;
- word1(&rv) = 0xffffffff;
+ word0(&rv) = L | Bndry_mask1;
+ word1(&rv) = 0xffffffff;
#ifdef IBM
- goto cont;
+ goto cont;
#else
#ifndef NO_STRTOD_BIGCOMP
- if (bc.nd > nd)
- goto cont;
+ if (bc.nd > nd) {
+ goto cont;
+ }
#endif
- break;
+ break;
#endif
- }
+ }
#ifndef ROUND_BIASED
#ifdef Avoid_Underflow
- if (Lsb1) {
- if (!(word0(&rv) & Lsb1))
- break;
- }
- else if (!(word1(&rv) & Lsb))
- break;
+ if (Lsb1) {
+ if (!(word0(&rv) & Lsb1)) {
+ break;
+ }
+ }
+ else if (!(word1(&rv) & Lsb)) {
+ break;
+ }
#else
- if (!(word1(&rv) & LSB))
- break;
+ if (!(word1(&rv) & LSB)) {
+ break;
+ }
#endif
#endif
- if (bc.dsign)
+ if (bc.dsign)
#ifdef Avoid_Underflow
- dval(&rv) += sulp(&rv, &bc);
+ dval(&rv) += sulp(&rv, &bc);
#else
- dval(&rv) += ulp(&rv);
+ dval(&rv) += ulp(&rv);
#endif
#ifndef ROUND_BIASED
- else {
+ else {
#ifdef Avoid_Underflow
- dval(&rv) -= sulp(&rv, &bc);
+ dval(&rv) -= sulp(&rv, &bc);
#else
- dval(&rv) -= ulp(&rv);
+ dval(&rv) -= ulp(&rv);
#endif
#ifndef Sudden_Underflow
- if (!dval(&rv)) {
- if (bc.nd >nd) {
- bc.uflchk = 1;
- break;
- }
- goto undfl;
- }
-#endif
- }
+ if (!dval(&rv)) {
+ if (bc.nd >nd) {
+ bc.uflchk = 1;
+ break;
+ }
+ goto undfl;
+ }
+#endif
+ }
#ifdef Avoid_Underflow
- bc.dsign = 1 - bc.dsign;
+ bc.dsign = 1 - bc.dsign;
#endif
#endif
- break;
- }
- if ((aadj = ratio(delta, bs)) <= 2.) {
- if (bc.dsign)
- aadj = aadj1 = 1.;
- else if (word1(&rv) || word0(&rv) & Bndry_mask) {
+ break;
+ }
+ if ((aadj = ratio(delta, bs)) <= 2.) {
+ if (bc.dsign) {
+ aadj = aadj1 = 1.;
+ }
+ else if (word1(&rv) || word0(&rv) & Bndry_mask) {
#ifndef Sudden_Underflow
- if (word1(&rv) == Tiny1 && !word0(&rv)) {
- if (bc.nd >nd) {
- bc.uflchk = 1;
- break;
- }
- goto undfl;
- }
-#endif
- aadj = 1.;
- aadj1 = -1.;
- }
- else {
- /* special case -- power of FLT_RADIX to be */
- /* rounded down... */
-
- if (aadj < 2./FLT_RADIX)
- aadj = 1./FLT_RADIX;
- else
- aadj *= 0.5;
- aadj1 = -aadj;
- }
- }
- else {
- aadj *= 0.5;
- aadj1 = bc.dsign ? aadj : -aadj;
+ if (word1(&rv) == Tiny1 && !word0(&rv)) {
+ if (bc.nd >nd) {
+ bc.uflchk = 1;
+ break;
+ }
+ goto undfl;
+ }
+#endif
+ aadj = 1.;
+ aadj1 = -1.;
+ }
+ else {
+ /* special case -- power of FLT_RADIX to be */
+ /* rounded down... */
+
+ if (aadj < 2./FLT_RADIX) {
+ aadj = 1./FLT_RADIX;
+ }
+ else {
+ aadj *= 0.5;
+ }
+ aadj1 = -aadj;
+ }
+ }
+ else {
+ aadj *= 0.5;
+ aadj1 = bc.dsign ? aadj : -aadj;
#ifdef Check_FLT_ROUNDS
- switch(bc.rounding) {
- case 2: /* towards +infinity */
- aadj1 -= 0.5;
- break;
- case 0: /* towards 0 */
- case 3: /* towards -infinity */
- aadj1 += 0.5;
- }
+ switch(bc.rounding) {
+ case 2: /* towards +infinity */
+ aadj1 -= 0.5;
+ break;
+ case 0: /* towards 0 */
+ case 3: /* towards -infinity */
+ aadj1 += 0.5;
+ }
#else
- if (Flt_Rounds == 0)
- aadj1 += 0.5;
+ if (Flt_Rounds == 0) {
+ aadj1 += 0.5;
+ }
#endif /*Check_FLT_ROUNDS*/
- }
- y = word0(&rv) & Exp_mask;
-
- /* Check for overflow */
-
- if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) {
- dval(&rv0) = dval(&rv);
- word0(&rv) -= P*Exp_msk1;
- adj.d = aadj1 * ulp(&rv);
- dval(&rv) += adj.d;
- if ((word0(&rv) & Exp_mask) >=
- Exp_msk1*(DBL_MAX_EXP+Bias-P)) {
- if (word0(&rv0) == Big0 && word1(&rv0) == Big1)
- goto ovfl;
- word0(&rv) = Big0;
- word1(&rv) = Big1;
- goto cont;
- }
- else
- word0(&rv) += P*Exp_msk1;
- }
- else {
+ }
+ y = word0(&rv) & Exp_mask;
+
+ /* Check for overflow */
+
+ if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) {
+ dval(&rv0) = dval(&rv);
+ word0(&rv) -= P*Exp_msk1;
+ adj.d = aadj1 * ulp(&rv);
+ dval(&rv) += adj.d;
+ if ((word0(&rv) & Exp_mask) >=
+ Exp_msk1*(DBL_MAX_EXP+Bias-P)) {
+ if (word0(&rv0) == Big0 && word1(&rv0) == Big1) {
+ goto ovfl;
+ }
+ word0(&rv) = Big0;
+ word1(&rv) = Big1;
+ goto cont;
+ }
+ else {
+ word0(&rv) += P*Exp_msk1;
+ }
+ }
+ else {
#ifdef Avoid_Underflow
- if (bc.scale && y <= 2*P*Exp_msk1) {
- if (aadj <= 0x7fffffff) {
- if ((z = aadj) <= 0)
- z = 1;
- aadj = z;
- aadj1 = bc.dsign ? aadj : -aadj;
- }
- dval(&aadj2) = aadj1;
- word0(&aadj2) += (2*P+1)*Exp_msk1 - y;
- aadj1 = dval(&aadj2);
- adj.d = aadj1 * ulp(&rv);
- dval(&rv) += adj.d;
- if (rv.d == 0.)
+ if (bc.scale && y <= 2*P*Exp_msk1) {
+ if (aadj <= 0x7fffffff) {
+ if ((z = aadj) <= 0) {
+ z = 1;
+ }
+ aadj = z;
+ aadj1 = bc.dsign ? aadj : -aadj;
+ }
+ dval(&aadj2) = aadj1;
+ word0(&aadj2) += (2*P+1)*Exp_msk1 - y;
+ aadj1 = dval(&aadj2);
+ adj.d = aadj1 * ulp(&rv);
+ dval(&rv) += adj.d;
+ if (rv.d == 0.)
#ifdef NO_STRTOD_BIGCOMP
- goto undfl;
+ goto undfl;
#else
- {
- if (bc.nd > nd)
- bc.dsign = 1;
- break;
- }
-#endif
- }
- else {
- adj.d = aadj1 * ulp(&rv);
- dval(&rv) += adj.d;
- }
+ {
+ if (bc.nd > nd) {
+ bc.dsign = 1;
+ }
+ break;
+ }
+#endif
+ }
+ else {
+ adj.d = aadj1 * ulp(&rv);
+ dval(&rv) += adj.d;
+ }
#else
#ifdef Sudden_Underflow
- if ((word0(&rv) & Exp_mask) <= P*Exp_msk1) {
- dval(&rv0) = dval(&rv);
- word0(&rv) += P*Exp_msk1;
- adj.d = aadj1 * ulp(&rv);
- dval(&rv) += adj.d;
+ if ((word0(&rv) & Exp_mask) <= P*Exp_msk1) {
+ dval(&rv0) = dval(&rv);
+ word0(&rv) += P*Exp_msk1;
+ adj.d = aadj1 * ulp(&rv);
+ dval(&rv) += adj.d;
#ifdef IBM
- if ((word0(&rv) & Exp_mask) < P*Exp_msk1)
+ if ((word0(&rv) & Exp_mask) < P*Exp_msk1)
#else
- if ((word0(&rv) & Exp_mask) <= P*Exp_msk1)
-#endif
- {
- if (word0(&rv0) == Tiny0
- && word1(&rv0) == Tiny1) {
- if (bc.nd >nd) {
- bc.uflchk = 1;
- break;
- }
- goto undfl;
- }
- word0(&rv) = Tiny0;
- word1(&rv) = Tiny1;
- goto cont;
- }
- else
- word0(&rv) -= P*Exp_msk1;
- }
- else {
- adj.d = aadj1 * ulp(&rv);
- dval(&rv) += adj.d;
- }
+ if ((word0(&rv) & Exp_mask) <= P*Exp_msk1)
+#endif
+ {
+ if (word0(&rv0) == Tiny0
+ && word1(&rv0) == Tiny1) {
+ if (bc.nd >nd) {
+ bc.uflchk = 1;
+ break;
+ }
+ goto undfl;
+ }
+ word0(&rv) = Tiny0;
+ word1(&rv) = Tiny1;
+ goto cont;
+ }
+ else {
+ word0(&rv) -= P*Exp_msk1;
+ }
+ }
+ else {
+ adj.d = aadj1 * ulp(&rv);
+ dval(&rv) += adj.d;
+ }
#else /*Sudden_Underflow*/
- /* Compute adj so that the IEEE rounding rules will
- * correctly round rv + adj in some half-way cases.
- * If rv * ulp(rv) is denormalized (i.e.,
- * y <= (P-1)*Exp_msk1), we must adjust aadj to avoid
- * trouble from bits lost to denormalization;
- * example: 1.2e-307 .
- */
- if (y <= (P-1)*Exp_msk1 && aadj > 1.) {
- aadj1 = (double)(int)(aadj + 0.5);
- if (!bc.dsign)
- aadj1 = -aadj1;
- }
- adj.d = aadj1 * ulp(&rv);
- dval(&rv) += adj.d;
+ /* Compute adj so that the IEEE rounding rules will
+ * correctly round rv + adj in some half-way cases.
+ * If rv * ulp(rv) is denormalized (i.e.,
+ * y <= (P-1)*Exp_msk1), we must adjust aadj to avoid
+ * trouble from bits lost to denormalization;
+ * example: 1.2e-307 .
+ */
+ if (y <= (P-1)*Exp_msk1 && aadj > 1.) {
+ aadj1 = (double)(int)(aadj + 0.5);
+ if (!bc.dsign) {
+ aadj1 = -aadj1;
+ }
+ }
+ adj.d = aadj1 * ulp(&rv);
+ dval(&rv) += adj.d;
#endif /*Sudden_Underflow*/
#endif /*Avoid_Underflow*/
- }
- z = word0(&rv) & Exp_mask;
+ }
+ z = word0(&rv) & Exp_mask;
#ifndef SET_INEXACT
- if (bc.nd == nd) {
+ if (bc.nd == nd) {
#ifdef Avoid_Underflow
- if (!bc.scale)
-#endif
- if (y == z) {
- /* Can we stop now? */
- L = (Long)aadj;
- aadj -= L;
- /* The tolerances below are conservative. */
- if (bc.dsign || word1(&rv) || word0(&rv) & Bndry_mask) {
- if (aadj < .4999999 || aadj > .5000001)
- break;
- }
- else if (aadj < .4999999/FLT_RADIX)
- break;
- }
- }
-#endif
- cont:
- Bfree(bb);
- Bfree(bd);
- Bfree(bs);
- Bfree(delta);
- }
- Bfree(bb);
- Bfree(bd);
- Bfree(bs);
- Bfree(bd0);
- Bfree(delta);
+ if (!bc.scale)
+#endif
+ if (y == z) {
+ /* Can we stop now? */
+ L = (Long)aadj;
+ aadj -= L;
+ /* The tolerances below are conservative. */
+ if (bc.dsign || word1(&rv) || word0(&rv) & Bndry_mask) {
+ if (aadj < .4999999 || aadj > .5000001) {
+ break;
+ }
+ }
+ else if (aadj < .4999999/FLT_RADIX) {
+ break;
+ }
+ }
+ }
+#endif
+cont:
+ Bfree(bb);
+ Bfree(bd);
+ Bfree(bs);
+ Bfree(delta);
+}
+Bfree(bb);
+Bfree(bd);
+Bfree(bs);
+Bfree(bd0);
+Bfree(delta);
#ifndef NO_STRTOD_BIGCOMP
- if (req_bigcomp) {
- bd0 = 0;
- bc.e0 += nz1;
- bigcomp(&rv, s0, &bc);
- y = word0(&rv) & Exp_mask;
- if (y == Exp_mask)
- goto ovfl;
- if (y == 0 && rv.d == 0.)
- goto undfl;
- }
+if (req_bigcomp) {
+ bd0 = 0;
+ bc.e0 += nz1;
+ bigcomp(&rv, s0, &bc);
+ y = word0(&rv) & Exp_mask;
+ if (y == Exp_mask) {
+ goto ovfl;
+ }
+ if (y == 0 && rv.d == 0.) {
+ goto undfl;
+ }
+}
#endif
#ifdef SET_INEXACT
- if (bc.inexact) {
- if (!oldinexact) {
- word0(&rv0) = Exp_1 + (70 << Exp_shift);
- word1(&rv0) = 0;
- dval(&rv0) += 1.;
- }
- }
- else if (!oldinexact)
- clear_inexact();
+if (bc.inexact) {
+ if (!oldinexact) {
+ word0(&rv0) = Exp_1 + (70 << Exp_shift);
+ word1(&rv0) = 0;
+ dval(&rv0) += 1.;
+ }
+}
+else if (!oldinexact) {
+ clear_inexact();
+}
#endif
#ifdef Avoid_Underflow
- if (bc.scale) {
- word0(&rv0) = Exp_1 - 2*P*Exp_msk1;
- word1(&rv0) = 0;
- dval(&rv) *= dval(&rv0);
+if (bc.scale) {
+ word0(&rv0) = Exp_1 - 2*P*Exp_msk1;
+ word1(&rv0) = 0;
+ dval(&rv) *= dval(&rv0);
#ifndef NO_ERRNO
- /* try to avoid the bug of testing an 8087 register value */
+ /* try to avoid the bug of testing an 8087 register value */
#ifdef IEEE_Arith
- if (!(word0(&rv) & Exp_mask))
+ if (!(word0(&rv) & Exp_mask))
#else
- if (word0(&rv) == 0 && word1(&rv) == 0)
+ if (word0(&rv) == 0 && word1(&rv) == 0)
#endif
- errno = ERANGE;
+ errno = ERANGE;
#endif
- }
+}
#endif /* Avoid_Underflow */
#ifdef SET_INEXACT
- if (bc.inexact && !(word0(&rv) & Exp_mask)) {
- /* set underflow bit */
- dval(&rv0) = 1e-300;
- dval(&rv0) *= dval(&rv0);
- }
-#endif
- ret:
- if (se)
- *se = (char *)s;
- return sign ? -dval(&rv) : dval(&rv);
- }
+if (bc.inexact && !(word0(&rv) & Exp_mask)) {
+ /* set underflow bit */
+ dval(&rv0) = 1e-300;
+ dval(&rv0) *= dval(&rv0);
+}
+#endif
+ret:
+if (se) {
+ *se = (char *)s;
+}
+return sign ? -dval(&rv) : dval(&rv);
+}
#ifndef MULTIPLE_THREADS
- static char *dtoa_result;
+static char *dtoa_result;
#endif
- static char *
+static char *
#ifdef KR_headers
rv_alloc(i) int i;
#else
rv_alloc(int i)
#endif
{
- int j, k, *r;
-
- j = sizeof(ULong);
- for(k = 0;
- sizeof(Bigint) - sizeof(ULong) - sizeof(int) + j <= i;
- j <<= 1)
- k++;
- r = (int*)Balloc(k);
- *r = k;
- return
+ int j, k, *r;
+
+ j = sizeof(ULong);
+ for(k = 0;
+ sizeof(Bigint) - sizeof(ULong) - sizeof(int) + j <= i;
+ j <<= 1) {
+ k++;
+ }
+ r = (int*)Balloc(k);
+ *r = k;
+ return
#ifndef MULTIPLE_THREADS
- dtoa_result =
+ dtoa_result =
#endif
- (char *)(r+1);
- }
+ (char *)(r+1);
+}
- static char *
+static char *
#ifdef KR_headers
nrv_alloc(s, rve, n) char *s, **rve; int n;
#else
nrv_alloc(const char *s, char **rve, int n)
#endif
{
- char *rv, *t;
-
- t = rv = rv_alloc(n);
- while((*t = *s++)) t++;
- if (rve)
- *rve = t;
- return rv;
- }
+ char *rv, *t;
+
+ t = rv = rv_alloc(n);
+ while((*t = *s++)) {
+ t++;
+ }
+ if (rve) {
+ *rve = t;
+ }
+ return rv;
+}
/* freedtoa(s) must be used to free values s returned by dtoa
* when MULTIPLE_THREADS is #defined. It should be used in all cases,
@@ -3592,21 +3807,22 @@ nrv_alloc(const char *s, char **rve, int n)
* when MULTIPLE_THREADS is not defined.
*/
- void
+void
#ifdef KR_headers
freedtoa(s) char *s;
#else
freedtoa(char *s)
#endif
{
- Bigint *b = (Bigint *)((int *)s - 1);
- b->maxwds = 1 << (b->k = *(int*)b);
- Bfree(b);
+ Bigint *b = (Bigint *)((int *)s - 1);
+ b->maxwds = 1 << (b->k = *(int*)b);
+ Bfree(b);
#ifndef MULTIPLE_THREADS
- if (s == dtoa_result)
- dtoa_result = 0;
+ if (s == dtoa_result) {
+ dtoa_result = 0;
+ }
#endif
- }
+}
/* dtoa for IEEE arithmetic (dmg): convert double to ASCII string.
*
@@ -3614,743 +3830,781 @@ freedtoa(char *s)
* Guy L. Steele, Jr. and Jon L. White [Proc. ACM SIGPLAN '90, pp. 112-126].
*
* Modifications:
- * 1. Rather than iterating, we use a simple numeric overestimate
- * to determine k = floor(log10(d)). We scale relevant
- * quantities using O(log2(k)) rather than O(k) multiplications.
- * 2. For some modes > 2 (corresponding to ecvt and fcvt), we don't
- * try to generate digits strictly left to right. Instead, we
- * compute with fewer bits and propagate the carry if necessary
- * when rounding the final digit up. This is often faster.
- * 3. Under the assumption that input will be rounded nearest,
- * mode 0 renders 1e23 as 1e23 rather than 9.999999999999999e22.
- * That is, we allow equality in stopping tests when the
- * round-nearest rule will give the same floating-point value
- * as would satisfaction of the stopping test with strict
- * inequality.
- * 4. We remove common factors of powers of 2 from relevant
- * quantities.
- * 5. When converting floating-point integers less than 1e16,
- * we use floating-point arithmetic rather than resorting
- * to multiple-precision integers.
- * 6. When asked to produce fewer than 15 digits, we first try
- * to get by with floating-point arithmetic; we resort to
- * multiple-precision integer arithmetic only if we cannot
- * guarantee that the floating-point calculation has given
- * the correctly rounded result. For k requested digits and
- * "uniformly" distributed input, the probability is
- * something like 10^(k-15) that we must resort to the Long
- * calculation.
+ * 1. Rather than iterating, we use a simple numeric overestimate
+ * to determine k = floor(log10(d)). We scale relevant
+ * quantities using O(log2(k)) rather than O(k) multiplications.
+ * 2. For some modes > 2 (corresponding to ecvt and fcvt), we don't
+ * try to generate digits strictly left to right. Instead, we
+ * compute with fewer bits and propagate the carry if necessary
+ * when rounding the final digit up. This is often faster.
+ * 3. Under the assumption that input will be rounded nearest,
+ * mode 0 renders 1e23 as 1e23 rather than 9.999999999999999e22.
+ * That is, we allow equality in stopping tests when the
+ * round-nearest rule will give the same floating-point value
+ * as would satisfaction of the stopping test with strict
+ * inequality.
+ * 4. We remove common factors of powers of 2 from relevant
+ * quantities.
+ * 5. When converting floating-point integers less than 1e16,
+ * we use floating-point arithmetic rather than resorting
+ * to multiple-precision integers.
+ * 6. When asked to produce fewer than 15 digits, we first try
+ * to get by with floating-point arithmetic; we resort to
+ * multiple-precision integer arithmetic only if we cannot
+ * guarantee that the floating-point calculation has given
+ * the correctly rounded result. For k requested digits and
+ * "uniformly" distributed input, the probability is
+ * something like 10^(k-15) that we must resort to the Long
+ * calculation.
*/
- char *
+char *
dtoa
#ifdef KR_headers
- (dd, mode, ndigits, decpt, sign, rve)
- double dd; int mode, ndigits, *decpt, *sign; char **rve;
+(dd, mode, ndigits, decpt, sign, rve)
+double dd; int mode, ndigits, *decpt, *sign; char **rve;
#else
- (double dd, int mode, int ndigits, int *decpt, int *sign, char **rve)
+(double dd, int mode, int ndigits, int *decpt, int *sign, char **rve)
#endif
{
- /* Arguments ndigits, decpt, sign are similar to those
- of ecvt and fcvt; trailing zeros are suppressed from
- the returned string. If not null, *rve is set to point
- to the end of the return value. If d is +-Infinity or NaN,
- then *decpt is set to 9999.
-
- mode:
- 0 ==> shortest string that yields d when read in
- and rounded to nearest.
- 1 ==> like 0, but with Steele & White stopping rule;
- e.g. with IEEE P754 arithmetic , mode 0 gives
- 1e23 whereas mode 1 gives 9.999999999999999e22.
- 2 ==> max(1,ndigits) significant digits. This gives a
- return value similar to that of ecvt, except
- that trailing zeros are suppressed.
- 3 ==> through ndigits past the decimal point. This
- gives a return value similar to that from fcvt,
- except that trailing zeros are suppressed, and
- ndigits can be negative.
- 4,5 ==> similar to 2 and 3, respectively, but (in
- round-nearest mode) with the tests of mode 0 to
- possibly return a shorter string that rounds to d.
- With IEEE arithmetic and compilation with
- -DHonor_FLT_ROUNDS, modes 4 and 5 behave the same
- as modes 2 and 3 when FLT_ROUNDS != 1.
- 6-9 ==> Debugging modes similar to mode - 4: don't try
- fast floating-point estimate (if applicable).
-
- Values of mode other than 0-9 are treated as mode 0.
-
- Sufficient space is allocated to the return value
- to hold the suppressed trailing zeros.
- */
-
- int bbits, b2, b5, be, dig, i, ieps, ilim, ilim0, ilim1,
- j, j1, k, k0, k_check, leftright, m2, m5, s2, s5,
- spec_case, try_quick;
- Long L;
+ /* Arguments ndigits, decpt, sign are similar to those
+ of ecvt and fcvt; trailing zeros are suppressed from
+ the returned string. If not null, *rve is set to point
+ to the end of the return value. If d is +-Infinity or NaN,
+ then *decpt is set to 9999.
+
+ mode:
+ 0 ==> shortest string that yields d when read in
+ and rounded to nearest.
+ 1 ==> like 0, but with Steele & White stopping rule;
+ e.g. with IEEE P754 arithmetic , mode 0 gives
+ 1e23 whereas mode 1 gives 9.999999999999999e22.
+ 2 ==> max(1,ndigits) significant digits. This gives a
+ return value similar to that of ecvt, except
+ that trailing zeros are suppressed.
+ 3 ==> through ndigits past the decimal point. This
+ gives a return value similar to that from fcvt,
+ except that trailing zeros are suppressed, and
+ ndigits can be negative.
+ 4,5 ==> similar to 2 and 3, respectively, but (in
+ round-nearest mode) with the tests of mode 0 to
+ possibly return a shorter string that rounds to d.
+ With IEEE arithmetic and compilation with
+ -DHonor_FLT_ROUNDS, modes 4 and 5 behave the same
+ as modes 2 and 3 when FLT_ROUNDS != 1.
+ 6-9 ==> Debugging modes similar to mode - 4: don't try
+ fast floating-point estimate (if applicable).
+
+ Values of mode other than 0-9 are treated as mode 0.
+
+ Sufficient space is allocated to the return value
+ to hold the suppressed trailing zeros.
+ */
+
+ int bbits, b2, b5, be, dig, i, ieps, ilim, ilim0, ilim1,
+ j, j1, k, k0, k_check, leftright, m2, m5, s2, s5,
+ spec_case, try_quick;
+ Long L;
#ifndef Sudden_Underflow
- int denorm;
- ULong x;
+ int denorm;
+ ULong x;
#endif
- Bigint *b, *b1, *delta, *mlo, *mhi, *S;
- U d2, eps, u;
- double ds;
- char *s, *s0;
+ Bigint *b, *b1, *delta, *mlo, *mhi, *S;
+ U d2, eps, u;
+ double ds;
+ char *s, *s0;
#ifndef No_leftright
#ifdef IEEE_Arith
- U eps1;
+ U eps1;
#endif
#endif
#ifdef SET_INEXACT
- int inexact, oldinexact;
+ int inexact, oldinexact;
#endif
#ifdef Honor_FLT_ROUNDS /*{*/
- int Rounding;
+ int Rounding;
#ifdef Trust_FLT_ROUNDS /*{{ only define this if FLT_ROUNDS really works! */
- Rounding = Flt_Rounds;
+ Rounding = Flt_Rounds;
#else /*}{*/
- Rounding = 1;
- switch(fegetround()) {
- case FE_TOWARDZERO: Rounding = 0; break;
- case FE_UPWARD: Rounding = 2; break;
- case FE_DOWNWARD: Rounding = 3;
- }
+ Rounding = 1;
+ switch(fegetround()) {
+ case FE_TOWARDZERO: Rounding = 0; break;
+ case FE_UPWARD: Rounding = 2; break;
+ case FE_DOWNWARD: Rounding = 3;
+ }
#endif /*}}*/
#endif /*}*/
#ifndef MULTIPLE_THREADS
- if (dtoa_result) {
- freedtoa(dtoa_result);
- dtoa_result = 0;
- }
-#endif
-
- u.d = dd;
- if (word0(&u) & Sign_bit) {
- /* set sign for everything, including 0's and NaNs */
- *sign = 1;
- word0(&u) &= ~Sign_bit; /* clear sign bit */
- }
- else
- *sign = 0;
+ if (dtoa_result) {
+ freedtoa(dtoa_result);
+ dtoa_result = 0;
+ }
+#endif
+
+ u.d = dd;
+ if (word0(&u) & Sign_bit) {
+ /* set sign for everything, including 0's and NaNs */
+ *sign = 1;
+ word0(&u) &= ~Sign_bit; /* clear sign bit */
+ }
+ else {
+ *sign = 0;
+ }
#if defined(IEEE_Arith) + defined(VAX)
#ifdef IEEE_Arith
- if ((word0(&u) & Exp_mask) == Exp_mask)
+ if ((word0(&u) & Exp_mask) == Exp_mask)
#else
- if (word0(&u) == 0x8000)
+ if (word0(&u) == 0x8000)
#endif
- {
- /* Infinity or NaN */
- *decpt = 9999;
+ {
+ /* Infinity or NaN */
+ *decpt = 9999;
#ifdef IEEE_Arith
- if (!word1(&u) && !(word0(&u) & 0xfffff))
- return nrv_alloc("Infinity", rve, 8);
+ if (!word1(&u) && !(word0(&u) & 0xfffff)) {
+ return nrv_alloc("Infinity", rve, 8);
+ }
#endif
- return nrv_alloc("NaN", rve, 3);
- }
+ return nrv_alloc("NaN", rve, 3);
+ }
#endif
#ifdef IBM
- dval(&u) += 0; /* normalize */
+ dval(&u) += 0; /* normalize */
#endif
- if (!dval(&u)) {
- *decpt = 1;
- return nrv_alloc("0", rve, 1);
- }
+ if (!dval(&u)) {
+ *decpt = 1;
+ return nrv_alloc("0", rve, 1);
+ }
#ifdef SET_INEXACT
- try_quick = oldinexact = get_inexact();
- inexact = 1;
+ try_quick = oldinexact = get_inexact();
+ inexact = 1;
#endif
#ifdef Honor_FLT_ROUNDS
- if (Rounding >= 2) {
- if (*sign)
- Rounding = Rounding == 2 ? 0 : 2;
- else
- if (Rounding != 2)
- Rounding = 0;
- }
+ if (Rounding >= 2) {
+ if (*sign) {
+ Rounding = Rounding == 2 ? 0 : 2;
+ }
+ else if (Rounding != 2) {
+ Rounding = 0;
+ }
+ }
#endif
- b = d2b(&u, &be, &bbits);
+ b = d2b(&u, &be, &bbits);
#ifdef Sudden_Underflow
- i = (int)(word0(&u) >> Exp_shift1 & (Exp_mask>>Exp_shift1));
+ i = (int)(word0(&u) >> Exp_shift1 & (Exp_mask>>Exp_shift1));
#else
- if ((i = (int)(word0(&u) >> Exp_shift1 & (Exp_mask>>Exp_shift1)))) {
+ if ((i = (int)(word0(&u) >> Exp_shift1 & (Exp_mask>>Exp_shift1)))) {
#endif
- dval(&d2) = dval(&u);
- word0(&d2) &= Frac_mask1;
- word0(&d2) |= Exp_11;
+ dval(&d2) = dval(&u);
+ word0(&d2) &= Frac_mask1;
+ word0(&d2) |= Exp_11;
#ifdef IBM
- if (j = 11 - hi0bits(word0(&d2) & Frac_mask))
- dval(&d2) /= 1 << j;
-#endif
-
- /* log(x) ~=~ log(1.5) + (x-1.5)/1.5
- * log10(x) = log(x) / log(10)
- * ~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10))
- * log10(d) = (i-Bias)*log(2)/log(10) + log10(d2)
- *
- * This suggests computing an approximation k to log10(d) by
- *
- * k = (i - Bias)*0.301029995663981
- * + ( (d2-1.5)*0.289529654602168 + 0.176091259055681 );
- *
- * We want k to be too large rather than too small.
- * The error in the first-order Taylor series approximation
- * is in our favor, so we just round up the constant enough
- * to compensate for any error in the multiplication of
- * (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077,
- * and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14,
- * adding 1e-13 to the constant term more than suffices.
- * Hence we adjust the constant term to 0.1760912590558.
- * (We could get a more accurate k by invoking log10,
- * but this is probably not worthwhile.)
- */
-
- i -= Bias;
+ if (j = 11 - hi0bits(word0(&d2) & Frac_mask)) {
+ dval(&d2) /= 1 << j;
+ }
+#endif
+
+ /* log(x) ~=~ log(1.5) + (x-1.5)/1.5
+ * log10(x) = log(x) / log(10)
+ * ~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10))
+ * log10(d) = (i-Bias)*log(2)/log(10) + log10(d2)
+ *
+ * This suggests computing an approximation k to log10(d) by
+ *
+ * k = (i - Bias)*0.301029995663981
+ * + ( (d2-1.5)*0.289529654602168 + 0.176091259055681 );
+ *
+ * We want k to be too large rather than too small.
+ * The error in the first-order Taylor series approximation
+ * is in our favor, so we just round up the constant enough
+ * to compensate for any error in the multiplication of
+ * (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077,
+ * and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14,
+ * adding 1e-13 to the constant term more than suffices.
+ * Hence we adjust the constant term to 0.1760912590558.
+ * (We could get a more accurate k by invoking log10,
+ * but this is probably not worthwhile.)
+ */
+
+ i -= Bias;
#ifdef IBM
- i <<= 2;
- i += j;
+ i <<= 2;
+ i += j;
#endif
#ifndef Sudden_Underflow
- denorm = 0;
- }
- else {
- /* d is denormalized */
-
- i = bbits + be + (Bias + (P-1) - 1);
- x = i > 32 ? word0(&u) << (64 - i) | word1(&u) >> (i - 32)
- : word1(&u) << (32 - i);
- dval(&d2) = x;
- word0(&d2) -= 31*Exp_msk1; /* adjust exponent */
- i -= (Bias + (P-1) - 1) + 1;
- denorm = 1;
- }
-#endif
- ds = (dval(&d2)-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981;
- k = (int)ds;
- if (ds < 0. && ds != k)
- k--; /* want k = floor(ds) */
- k_check = 1;
- if (k >= 0 && k <= Ten_pmax) {
- if (dval(&u) < tens[k])
- k--;
- k_check = 0;
- }
- j = bbits - i - 1;
- if (j >= 0) {
- b2 = 0;
- s2 = j;
- }
- else {
- b2 = -j;
- s2 = 0;
- }
- if (k >= 0) {
- b5 = 0;
- s5 = k;
- s2 += k;
- }
- else {
- b2 -= k;
- b5 = -k;
- s5 = 0;
- }
- if (mode < 0 || mode > 9)
- mode = 0;
+ denorm = 0;
+}
+else {
+ /* d is denormalized */
+
+ i = bbits + be + (Bias + (P-1) - 1);
+ x = i > 32 ? word0(&u) << (64 - i) | word1(&u) >> (i - 32)
+ : word1(&u) << (32 - i);
+ dval(&d2) = x;
+ word0(&d2) -= 31*Exp_msk1; /* adjust exponent */
+ i -= (Bias + (P-1) - 1) + 1;
+ denorm = 1;
+}
+#endif
+ds = (dval(&d2)-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981;
+k = (int)ds;
+if (ds < 0. && ds != k) {
+ k--; /* want k = floor(ds) */
+}
+k_check = 1;
+if (k >= 0 && k <= Ten_pmax) {
+ if (dval(&u) < tens[k]) {
+ k--;
+ }
+ k_check = 0;
+}
+j = bbits - i - 1;
+if (j >= 0) {
+ b2 = 0;
+ s2 = j;
+}
+else {
+ b2 = -j;
+ s2 = 0;
+}
+if (k >= 0) {
+ b5 = 0;
+ s5 = k;
+ s2 += k;
+}
+else {
+ b2 -= k;
+ b5 = -k;
+ s5 = 0;
+}
+if (mode < 0 || mode > 9) {
+ mode = 0;
+}
#ifndef SET_INEXACT
#ifdef Check_FLT_ROUNDS
- try_quick = Rounding == 1;
+try_quick = Rounding == 1;
#else
- try_quick = 1;
+try_quick = 1;
#endif
#endif /*SET_INEXACT*/
- if (mode > 5) {
- mode -= 4;
- try_quick = 0;
- }
- leftright = 1;
- ilim = ilim1 = -1; /* Values for cases 0 and 1; done here to */
- /* silence erroneous "gcc -Wall" warning. */
- switch(mode) {
- case 0:
- case 1:
- i = 18;
- ndigits = 0;
- break;
- case 2:
- leftright = 0;
- /* no break */
- case 4:
- if (ndigits <= 0)
- ndigits = 1;
- ilim = ilim1 = i = ndigits;
- break;
- case 3:
- leftright = 0;
- /* no break */
- case 5:
- i = ndigits + k + 1;
- ilim = i;
- ilim1 = i - 1;
- if (i <= 0)
- i = 1;
- }
- s = s0 = rv_alloc(i);
+if (mode > 5) {
+ mode -= 4;
+ try_quick = 0;
+}
+leftright = 1;
+ilim = ilim1 = -1; /* Values for cases 0 and 1; done here to */
+/* silence erroneous "gcc -Wall" warning. */
+switch(mode) {
+case 0:
+case 1:
+ i = 18;
+ ndigits = 0;
+ break;
+case 2:
+ leftright = 0;
+/* no break */
+case 4:
+ if (ndigits <= 0) {
+ ndigits = 1;
+ }
+ ilim = ilim1 = i = ndigits;
+ break;
+case 3:
+ leftright = 0;
+/* no break */
+case 5:
+ i = ndigits + k + 1;
+ ilim = i;
+ ilim1 = i - 1;
+ if (i <= 0) {
+ i = 1;
+ }
+}
+s = s0 = rv_alloc(i);
#ifdef Honor_FLT_ROUNDS
- if (mode > 1 && Rounding != 1)
- leftright = 0;
-#endif
-
- if (ilim >= 0 && ilim <= Quick_max && try_quick) {
-
- /* Try to get by with floating-point arithmetic. */
-
- i = 0;
- dval(&d2) = dval(&u);
- k0 = k;
- ilim0 = ilim;
- ieps = 2; /* conservative */
- if (k > 0) {
- ds = tens[k&0xf];
- j = k >> 4;
- if (j & Bletch) {
- /* prevent overflows */
- j &= Bletch - 1;
- dval(&u) /= bigtens[n_bigtens-1];
- ieps++;
- }
- for(; j; j >>= 1, i++)
- if (j & 1) {
- ieps++;
- ds *= bigtens[i];
- }
- dval(&u) /= ds;
- }
- else if ((j1 = -k)) {
- dval(&u) *= tens[j1 & 0xf];
- for(j = j1 >> 4; j; j >>= 1, i++)
- if (j & 1) {
- ieps++;
- dval(&u) *= bigtens[i];
- }
- }
- if (k_check && dval(&u) < 1. && ilim > 0) {
- if (ilim1 <= 0)
- goto fast_failed;
- ilim = ilim1;
- k--;
- dval(&u) *= 10.;
- ieps++;
- }
- dval(&eps) = ieps*dval(&u) + 7.;
- word0(&eps) -= (P-1)*Exp_msk1;
- if (ilim == 0) {
- S = mhi = 0;
- dval(&u) -= 5.;
- if (dval(&u) > dval(&eps))
- goto one_digit;
- if (dval(&u) < -dval(&eps))
- goto no_digits;
- goto fast_failed;
- }
+if (mode > 1 && Rounding != 1) {
+ leftright = 0;
+}
+#endif
+
+if (ilim >= 0 && ilim <= Quick_max && try_quick) {
+
+ /* Try to get by with floating-point arithmetic. */
+
+ i = 0;
+ dval(&d2) = dval(&u);
+ k0 = k;
+ ilim0 = ilim;
+ ieps = 2; /* conservative */
+ if (k > 0) {
+ ds = tens[k&0xf];
+ j = k >> 4;
+ if (j & Bletch) {
+ /* prevent overflows */
+ j &= Bletch - 1;
+ dval(&u) /= bigtens[n_bigtens-1];
+ ieps++;
+ }
+ for(; j; j >>= 1, i++)
+ if (j & 1) {
+ ieps++;
+ ds *= bigtens[i];
+ }
+ dval(&u) /= ds;
+ }
+ else if ((j1 = -k)) {
+ dval(&u) *= tens[j1 & 0xf];
+ for(j = j1 >> 4; j; j >>= 1, i++)
+ if (j & 1) {
+ ieps++;
+ dval(&u) *= bigtens[i];
+ }
+ }
+ if (k_check && dval(&u) < 1. && ilim > 0) {
+ if (ilim1 <= 0) {
+ goto fast_failed;
+ }
+ ilim = ilim1;
+ k--;
+ dval(&u) *= 10.;
+ ieps++;
+ }
+ dval(&eps) = ieps*dval(&u) + 7.;
+ word0(&eps) -= (P-1)*Exp_msk1;
+ if (ilim == 0) {
+ S = mhi = 0;
+ dval(&u) -= 5.;
+ if (dval(&u) > dval(&eps)) {
+ goto one_digit;
+ }
+ if (dval(&u) < -dval(&eps)) {
+ goto no_digits;
+ }
+ goto fast_failed;
+ }
#ifndef No_leftright
- if (leftright) {
- /* Use Steele & White method of only
- * generating digits needed.
- */
- dval(&eps) = 0.5/tens[ilim-1] - dval(&eps);
+ if (leftright) {
+ /* Use Steele & White method of only
+ * generating digits needed.
+ */
+ dval(&eps) = 0.5/tens[ilim-1] - dval(&eps);
#ifdef IEEE_Arith
- if (k0 < 0 && j1 >= 307) {
- eps1.d = 1.01e256; /* 1.01 allows roundoff in the next few lines */
- word0(&eps1) -= Exp_msk1 * (Bias+P-1);
- dval(&eps1) *= tens[j1 & 0xf];
- for(i = 0, j = (j1-256) >> 4; j; j >>= 1, i++)
- if (j & 1)
- dval(&eps1) *= bigtens[i];
- if (eps.d < eps1.d)
- eps.d = eps1.d;
- }
-#endif
- for(i = 0;;) {
- L = dval(&u);
- dval(&u) -= L;
- *s++ = '0' + (int)L;
- if (1. - dval(&u) < dval(&eps))
- goto bump_up;
- if (dval(&u) < dval(&eps))
- goto ret1;
- if (++i >= ilim)
- break;
- dval(&eps) *= 10.;
- dval(&u) *= 10.;
- }
- }
- else {
-#endif
- /* Generate ilim digits, then fix them up. */
- dval(&eps) *= tens[ilim-1];
- for(i = 1;; i++, dval(&u) *= 10.) {
- L = (Long)(dval(&u));
- if (!(dval(&u) -= L))
- ilim = i;
- *s++ = '0' + (int)L;
- if (i == ilim) {
- if (dval(&u) > 0.5 + dval(&eps))
- goto bump_up;
- else if (dval(&u) < 0.5 - dval(&eps)) {
- while(*--s == '0');
- s++;
- goto ret1;
- }
- break;
- }
- }
+ if (k0 < 0 && j1 >= 307) {
+ eps1.d = 1.01e256; /* 1.01 allows roundoff in the next few lines */
+ word0(&eps1) -= Exp_msk1 * (Bias+P-1);
+ dval(&eps1) *= tens[j1 & 0xf];
+ for(i = 0, j = (j1-256) >> 4; j; j >>= 1, i++)
+ if (j & 1) {
+ dval(&eps1) *= bigtens[i];
+ }
+ if (eps.d < eps1.d) {
+ eps.d = eps1.d;
+ }
+ }
+#endif
+ for(i = 0;;) {
+ L = dval(&u);
+ dval(&u) -= L;
+ *s++ = '0' + (int)L;
+ if (1. - dval(&u) < dval(&eps)) {
+ goto bump_up;
+ }
+ if (dval(&u) < dval(&eps)) {
+ goto ret1;
+ }
+ if (++i >= ilim) {
+ break;
+ }
+ dval(&eps) *= 10.;
+ dval(&u) *= 10.;
+ }
+ }
+ else {
+#endif
+ /* Generate ilim digits, then fix them up. */
+ dval(&eps) *= tens[ilim-1];
+ for(i = 1;; i++, dval(&u) *= 10.) {
+ L = (Long)(dval(&u));
+ if (!(dval(&u) -= L)) {
+ ilim = i;
+ }
+ *s++ = '0' + (int)L;
+ if (i == ilim) {
+ if (dval(&u) > 0.5 + dval(&eps)) {
+ goto bump_up;
+ }
+ else if (dval(&u) < 0.5 - dval(&eps)) {
+ while(*--s == '0');
+ s++;
+ goto ret1;
+ }
+ break;
+ }
+ }
#ifndef No_leftright
- }
-#endif
- fast_failed:
- s = s0;
- dval(&u) = dval(&d2);
- k = k0;
- ilim = ilim0;
- }
-
- /* Do we have a "small" integer? */
-
- if (be >= 0 && k <= Int_max) {
- /* Yes. */
- ds = tens[k];
- if (ndigits < 0 && ilim <= 0) {
- S = mhi = 0;
- if (ilim < 0 || dval(&u) <= 5*ds)
- goto no_digits;
- goto one_digit;
- }
- for(i = 1;; i++, dval(&u) *= 10.) {
- L = (Long)(dval(&u) / ds);
- dval(&u) -= L*ds;
+ }
+#endif
+fast_failed:
+ s = s0;
+ dval(&u) = dval(&d2);
+ k = k0;
+ ilim = ilim0;
+}
+
+/* Do we have a "small" integer? */
+
+if (be >= 0 && k <= Int_max) {
+ /* Yes. */
+ ds = tens[k];
+ if (ndigits < 0 && ilim <= 0) {
+ S = mhi = 0;
+ if (ilim < 0 || dval(&u) <= 5*ds) {
+ goto no_digits;
+ }
+ goto one_digit;
+ }
+ for(i = 1;; i++, dval(&u) *= 10.) {
+ L = (Long)(dval(&u) / ds);
+ dval(&u) -= L*ds;
#ifdef Check_FLT_ROUNDS
- /* If FLT_ROUNDS == 2, L will usually be high by 1 */
- if (dval(&u) < 0) {
- L--;
- dval(&u) += ds;
- }
-#endif
- *s++ = '0' + (int)L;
- if (!dval(&u)) {
+ /* If FLT_ROUNDS == 2, L will usually be high by 1 */
+ if (dval(&u) < 0) {
+ L--;
+ dval(&u) += ds;
+ }
+#endif
+ *s++ = '0' + (int)L;
+ if (!dval(&u)) {
#ifdef SET_INEXACT
- inexact = 0;
+ inexact = 0;
#endif
- break;
- }
- if (i == ilim) {
+ break;
+ }
+ if (i == ilim) {
#ifdef Honor_FLT_ROUNDS
- if (mode > 1)
- switch(Rounding) {
- case 0: goto ret1;
- case 2: goto bump_up;
- }
+ if (mode > 1)
+ switch(Rounding) {
+ case 0: goto ret1;
+ case 2: goto bump_up;
+ }
#endif
- dval(&u) += dval(&u);
+ dval(&u) += dval(&u);
#ifdef ROUND_BIASED
- if (dval(&u) >= ds)
+ if (dval(&u) >= ds)
#else
- if (dval(&u) > ds || (dval(&u) == ds && L & 1))
-#endif
- {
- bump_up:
- while(*--s == '9')
- if (s == s0) {
- k++;
- *s = '0';
- break;
- }
- ++*s++;
- }
- break;
- }
- }
- goto ret1;
- }
-
- m2 = b2;
- m5 = b5;
- mhi = mlo = 0;
- if (leftright) {
- i =
+ if (dval(&u) > ds || (dval(&u) == ds && L & 1))
+#endif
+ {
+bump_up:
+ while(*--s == '9')
+ if (s == s0) {
+ k++;
+ *s = '0';
+ break;
+ }
+ ++*s++;
+ }
+ break;
+ }
+ }
+ goto ret1;
+}
+
+m2 = b2;
+m5 = b5;
+mhi = mlo = 0;
+if (leftright) {
+ i =
#ifndef Sudden_Underflow
- denorm ? be + (Bias + (P-1) - 1 + 1) :
+ denorm ? be + (Bias + (P-1) - 1 + 1) :
#endif
#ifdef IBM
- 1 + 4*P - 3 - bbits + ((bbits + be - 1) & 3);
+ 1 + 4*P - 3 - bbits + ((bbits + be - 1) & 3);
#else
- 1 + P - bbits;
-#endif
- b2 += i;
- s2 += i;
- mhi = i2b(1);
- }
- if (m2 > 0 && s2 > 0) {
- i = m2 < s2 ? m2 : s2;
- b2 -= i;
- m2 -= i;
- s2 -= i;
- }
- if (b5 > 0) {
- if (leftright) {
- if (m5 > 0) {
- mhi = pow5mult(mhi, m5);
- b1 = mult(mhi, b);
- Bfree(b);
- b = b1;
- }
- if ((j = b5 - m5))
- b = pow5mult(b, j);
- }
- else
- b = pow5mult(b, b5);
- }
- S = i2b(1);
- if (s5 > 0)
- S = pow5mult(S, s5);
-
- /* Check for special case that d is a normalized power of 2. */
-
- spec_case = 0;
- if ((mode < 2 || leftright)
+ 1 + P - bbits;
+#endif
+ b2 += i;
+ s2 += i;
+ mhi = i2b(1);
+}
+if (m2 > 0 && s2 > 0) {
+ i = m2 < s2 ? m2 : s2;
+ b2 -= i;
+ m2 -= i;
+ s2 -= i;
+}
+if (b5 > 0) {
+ if (leftright) {
+ if (m5 > 0) {
+ mhi = pow5mult(mhi, m5);
+ b1 = mult(mhi, b);
+ Bfree(b);
+ b = b1;
+ }
+ if ((j = b5 - m5)) {
+ b = pow5mult(b, j);
+ }
+ }
+ else {
+ b = pow5mult(b, b5);
+ }
+}
+S = i2b(1);
+if (s5 > 0) {
+ S = pow5mult(S, s5);
+}
+
+/* Check for special case that d is a normalized power of 2. */
+
+spec_case = 0;
+if ((mode < 2 || leftright)
#ifdef Honor_FLT_ROUNDS
- && Rounding == 1
+ && Rounding == 1
#endif
- ) {
- if (!word1(&u) && !(word0(&u) & Bndry_mask)
+ ) {
+ if (!word1(&u) && !(word0(&u) & Bndry_mask)
#ifndef Sudden_Underflow
- && word0(&u) & (Exp_mask & ~Exp_msk1)
-#endif
- ) {
- /* The special case */
- b2 += Log2P;
- s2 += Log2P;
- spec_case = 1;
- }
- }
-
- /* Arrange for convenient computation of quotients:
- * shift left if necessary so divisor has 4 leading 0 bits.
- *
- * Perhaps we should just compute leading 28 bits of S once
- * and for all and pass them and a shift to quorem, so it
- * can do shifts and ors to compute the numerator for q.
- */
- i = dshift(S, s2);
- b2 += i;
- m2 += i;
- s2 += i;
- if (b2 > 0)
- b = lshift(b, b2);
- if (s2 > 0)
- S = lshift(S, s2);
- if (k_check) {
- if (cmp(b,S) < 0) {
- k--;
- b = multadd(b, 10, 0); /* we botched the k estimate */
- if (leftright)
- mhi = multadd(mhi, 10, 0);
- ilim = ilim1;
- }
- }
- if (ilim <= 0 && (mode == 3 || mode == 5)) {
- if (ilim < 0 || cmp(b,S = multadd(S,5,0)) <= 0) {
- /* no digits, fcvt style */
- no_digits:
- k = -1 - ndigits;
- goto ret;
- }
- one_digit:
- *s++ = '1';
- k++;
- goto ret;
- }
- if (leftright) {
- if (m2 > 0)
- mhi = lshift(mhi, m2);
-
- /* Compute mlo -- check for special case
- * that d is a normalized power of 2.
- */
-
- mlo = mhi;
- if (spec_case) {
- mhi = Balloc(mhi->k);
- Bcopy(mhi, mlo);
- mhi = lshift(mhi, Log2P);
- }
-
- for(i = 1;;i++) {
- dig = quorem(b,S) + '0';
- /* Do we yet have the shortest decimal string
- * that will round to d?
- */
- j = cmp(b, mlo);
- delta = diff(S, mhi);
- j1 = delta->sign ? 1 : cmp(b, delta);
- Bfree(delta);
+ && word0(&u) & (Exp_mask & ~Exp_msk1)
+#endif
+ ) {
+ /* The special case */
+ b2 += Log2P;
+ s2 += Log2P;
+ spec_case = 1;
+ }
+}
+
+/* Arrange for convenient computation of quotients:
+ * shift left if necessary so divisor has 4 leading 0 bits.
+ *
+ * Perhaps we should just compute leading 28 bits of S once
+ * and for all and pass them and a shift to quorem, so it
+ * can do shifts and ors to compute the numerator for q.
+ */
+i = dshift(S, s2);
+b2 += i;
+m2 += i;
+s2 += i;
+if (b2 > 0) {
+ b = lshift(b, b2);
+}
+if (s2 > 0) {
+ S = lshift(S, s2);
+}
+if (k_check) {
+ if (cmp(b,S) < 0) {
+ k--;
+ b = multadd(b, 10, 0); /* we botched the k estimate */
+ if (leftright) {
+ mhi = multadd(mhi, 10, 0);
+ }
+ ilim = ilim1;
+ }
+}
+if (ilim <= 0 && (mode == 3 || mode == 5)) {
+ if (ilim < 0 || cmp(b,S = multadd(S,5,0)) <= 0) {
+ /* no digits, fcvt style */
+no_digits:
+ k = -1 - ndigits;
+ goto ret;
+ }
+one_digit:
+ *s++ = '1';
+ k++;
+ goto ret;
+}
+if (leftright) {
+ if (m2 > 0) {
+ mhi = lshift(mhi, m2);
+ }
+
+ /* Compute mlo -- check for special case
+ * that d is a normalized power of 2.
+ */
+
+ mlo = mhi;
+ if (spec_case) {
+ mhi = Balloc(mhi->k);
+ Bcopy(mhi, mlo);
+ mhi = lshift(mhi, Log2P);
+ }
+
+ for(i = 1;; i++) {
+ dig = quorem(b,S) + '0';
+ /* Do we yet have the shortest decimal string
+ * that will round to d?
+ */
+ j = cmp(b, mlo);
+ delta = diff(S, mhi);
+ j1 = delta->sign ? 1 : cmp(b, delta);
+ Bfree(delta);
#ifndef ROUND_BIASED
- if (j1 == 0 && mode != 1 && !(word1(&u) & 1)
+ if (j1 == 0 && mode != 1 && !(word1(&u) & 1)
#ifdef Honor_FLT_ROUNDS
- && Rounding >= 1
-#endif
- ) {
- if (dig == '9')
- goto round_9_up;
- if (j > 0)
- dig++;
+ && Rounding >= 1
+#endif
+ ) {
+ if (dig == '9') {
+ goto round_9_up;
+ }
+ if (j > 0) {
+ dig++;
+ }
#ifdef SET_INEXACT
- else if (!b->x[0] && b->wds <= 1)
- inexact = 0;
+ else if (!b->x[0] && b->wds <= 1) {
+ inexact = 0;
+ }
#endif
- *s++ = dig;
- goto ret;
- }
+ *s++ = dig;
+ goto ret;
+ }
#endif
- if (j < 0 || (j == 0 && mode != 1
+ if (j < 0 || (j == 0 && mode != 1
#ifndef ROUND_BIASED
- && !(word1(&u) & 1)
+ && !(word1(&u) & 1)
#endif
- )) {
- if (!b->x[0] && b->wds <= 1) {
+ )) {
+ if (!b->x[0] && b->wds <= 1) {
#ifdef SET_INEXACT
- inexact = 0;
+ inexact = 0;
#endif
- goto accept_dig;
- }
+ goto accept_dig;
+ }
#ifdef Honor_FLT_ROUNDS
- if (mode > 1)
- switch(Rounding) {
- case 0: goto accept_dig;
- case 2: goto keep_dig;
- }
+ if (mode > 1)
+ switch(Rounding) {
+ case 0: goto accept_dig;
+ case 2: goto keep_dig;
+ }
#endif /*Honor_FLT_ROUNDS*/
- if (j1 > 0) {
- b = lshift(b, 1);
- j1 = cmp(b, S);
+ if (j1 > 0) {
+ b = lshift(b, 1);
+ j1 = cmp(b, S);
#ifdef ROUND_BIASED
- if (j1 >= 0 /*)*/
+ if (j1 >= 0 /*)*/
#else
- if ((j1 > 0 || (j1 == 0 && dig & 1))
-#endif
- && dig++ == '9')
- goto round_9_up;
- }
- accept_dig:
- *s++ = dig;
- goto ret;
- }
- if (j1 > 0) {
+ if ((j1 > 0 || (j1 == 0 && dig & 1))
+#endif
+ && dig++ == '9')
+ goto round_9_up;
+ }
+accept_dig:
+ *s++ = dig;
+ goto ret;
+ }
+ if (j1 > 0) {
#ifdef Honor_FLT_ROUNDS
- if (!Rounding)
- goto accept_dig;
-#endif
- if (dig == '9') { /* possible if i == 1 */
- round_9_up:
- *s++ = '9';
- goto roundoff;
- }
- *s++ = dig + 1;
- goto ret;
- }
+ if (!Rounding) {
+ goto accept_dig;
+ }
+#endif
+ if (dig == '9') { /* possible if i == 1 */
+round_9_up:
+ *s++ = '9';
+ goto roundoff;
+ }
+ *s++ = dig + 1;
+ goto ret;
+ }
#ifdef Honor_FLT_ROUNDS
- keep_dig:
-#endif
- *s++ = dig;
- if (i == ilim)
- break;
- b = multadd(b, 10, 0);
- if (mlo == mhi)
- mlo = mhi = multadd(mhi, 10, 0);
- else {
- mlo = multadd(mlo, 10, 0);
- mhi = multadd(mhi, 10, 0);
- }
- }
- }
- else
- for(i = 1;; i++) {
- *s++ = dig = quorem(b,S) + '0';
- if (!b->x[0] && b->wds <= 1) {
+keep_dig:
+#endif
+ *s++ = dig;
+ if (i == ilim) {
+ break;
+ }
+ b = multadd(b, 10, 0);
+ if (mlo == mhi) {
+ mlo = mhi = multadd(mhi, 10, 0);
+ }
+ else {
+ mlo = multadd(mlo, 10, 0);
+ mhi = multadd(mhi, 10, 0);
+ }
+ }
+}
+else
+ for(i = 1;; i++) {
+ *s++ = dig = quorem(b,S) + '0';
+ if (!b->x[0] && b->wds <= 1) {
#ifdef SET_INEXACT
- inexact = 0;
+ inexact = 0;
#endif
- goto ret;
- }
- if (i >= ilim)
- break;
- b = multadd(b, 10, 0);
- }
+ goto ret;
+ }
+ if (i >= ilim) {
+ break;
+ }
+ b = multadd(b, 10, 0);
+ }
- /* Round off last digit */
+/* Round off last digit */
#ifdef Honor_FLT_ROUNDS
- switch(Rounding) {
- case 0: goto trimzeros;
- case 2: goto roundoff;
- }
+switch(Rounding) {
+case 0: goto trimzeros;
+case 2: goto roundoff;
+}
#endif
- b = lshift(b, 1);
- j = cmp(b, S);
+b = lshift(b, 1);
+j = cmp(b, S);
#ifdef ROUND_BIASED
- if (j >= 0)
+if (j >= 0)
#else
- if (j > 0 || (j == 0 && dig & 1))
-#endif
- {
- roundoff:
- while(*--s == '9')
- if (s == s0) {
- k++;
- *s++ = '1';
- goto ret;
- }
- ++*s++;
- }
- else {
+if (j > 0 || (j == 0 && dig & 1))
+#endif
+{
+roundoff:
+ while(*--s == '9')
+ if (s == s0) {
+ k++;
+ *s++ = '1';
+ goto ret;
+ }
+ ++*s++;
+}
+else {
#ifdef Honor_FLT_ROUNDS
- trimzeros:
-#endif
- while(*--s == '0');
- s++;
- }
- ret:
- Bfree(S);
- if (mhi) {
- if (mlo && mlo != mhi)
- Bfree(mlo);
- Bfree(mhi);
- }
- ret1:
+trimzeros:
+#endif
+ while(*--s == '0');
+ s++;
+}
+ret:
+Bfree(S);
+if (mhi) {
+ if (mlo && mlo != mhi) {
+ Bfree(mlo);
+ }
+ Bfree(mhi);
+}
+ret1:
#ifdef SET_INEXACT
- if (inexact) {
- if (!oldinexact) {
- word0(&u) = Exp_1 + (70 << Exp_shift);
- word1(&u) = 0;
- dval(&u) += 1.;
- }
- }
- else if (!oldinexact)
- clear_inexact();
-#endif
- Bfree(b);
- *s = 0;
- *decpt = k + 1;
- if (rve)
- *rve = s;
- return s0;
- }
+if (inexact) {
+ if (!oldinexact) {
+ word0(&u) = Exp_1 + (70 << Exp_shift);
+ word1(&u) = 0;
+ dval(&u) += 1.;
+ }
+}
+else if (!oldinexact) {
+ clear_inexact();
+}
+#endif
+Bfree(b);
+*s = 0;
+*decpt = k + 1;
+if (rve) {
+ *rve = s;
+}
+return s0;
+}
#ifdef __cplusplus
}
#endif
diff --git a/nsprpub/pr/src/misc/pralarm.c b/nsprpub/pr/src/misc/pralarm.c
index 8f642bb16..8130215c2 100644
--- a/nsprpub/pr/src/misc/pralarm.c
+++ b/nsprpub/pr/src/misc/pralarm.c
@@ -38,21 +38,21 @@ struct PRAlarm { /* typedef'd in pralarm.h */
static PRAlarmID *pr_getNextAlarm(PRAlarm *alarm, PRAlarmID *id)
{
-/*
- * Puts 'id' back into the sorted list iff it's not NULL.
- * Removes the first element from the list and returns it (or NULL).
- * List is "assumed" to be short.
- *
- * NB: Caller is providing locking
- */
+ /*
+ * Puts 'id' back into the sorted list iff it's not NULL.
+ * Removes the first element from the list and returns it (or NULL).
+ * List is "assumed" to be short.
+ *
+ * NB: Caller is providing locking
+ */
PRCList *timer;
PRAlarmID *result = id;
PRIntervalTime now = PR_IntervalNow();
if (!PR_CLIST_IS_EMPTY(&alarm->timers))
- {
+ {
if (id != NULL) /* have to put this id back in */
- {
+ {
PRIntervalTime idDelta = now - id->nextNotify;
timer = alarm->timers.next;
do
@@ -107,12 +107,15 @@ static void PR_CALLBACK pr_alarmNotifier(void *arg)
while (why == scan)
{
alarm->current = NULL; /* reset current id */
- if (alarm->state == alarm_inactive) why = abort; /* we're toast */
+ if (alarm->state == alarm_inactive) {
+ why = abort; /* we're toast */
+ }
else if (why == scan) /* the dominant case */
{
id = pr_getNextAlarm(alarm, id); /* even if it's the same */
- if (id == NULL) /* there are no alarms set */
+ if (id == NULL) { /* there are no alarms set */
(void)PR_WaitCondVar(alarm->cond, PR_INTERVAL_NO_TIMEOUT);
+ }
else
{
pause = id->nextNotify - (PR_IntervalNow() - id->epoch);
@@ -121,8 +124,9 @@ static void PR_CALLBACK pr_alarmNotifier(void *arg)
why = notify; /* set up to do our thing */
alarm->current = id; /* id we're about to schedule */
}
- else
- (void)PR_WaitCondVar(alarm->cond, pause); /* dally */
+ else {
+ (void)PR_WaitCondVar(alarm->cond, pause); /* dally */
+ }
}
}
}
@@ -152,21 +156,31 @@ PR_IMPLEMENT(PRAlarm*) PR_CreateAlarm(void)
PRAlarm *alarm = PR_NEWZAP(PRAlarm);
if (alarm != NULL)
{
- if ((alarm->lock = PR_NewLock()) == NULL) goto done;
- if ((alarm->cond = PR_NewCondVar(alarm->lock)) == NULL) goto done;
+ if ((alarm->lock = PR_NewLock()) == NULL) {
+ goto done;
+ }
+ if ((alarm->cond = PR_NewCondVar(alarm->lock)) == NULL) {
+ goto done;
+ }
alarm->state = alarm_active;
PR_INIT_CLIST(&alarm->timers);
alarm->notifier = PR_CreateThread(
- PR_USER_THREAD, pr_alarmNotifier, alarm,
- PR_GetThreadPriority(PR_GetCurrentThread()),
- PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
- if (alarm->notifier == NULL) goto done;
+ PR_USER_THREAD, pr_alarmNotifier, alarm,
+ PR_GetThreadPriority(PR_GetCurrentThread()),
+ PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
+ if (alarm->notifier == NULL) {
+ goto done;
+ }
}
return alarm;
done:
- if (alarm->cond != NULL) PR_DestroyCondVar(alarm->cond);
- if (alarm->lock != NULL) PR_DestroyLock(alarm->lock);
+ if (alarm->cond != NULL) {
+ PR_DestroyCondVar(alarm->cond);
+ }
+ if (alarm->lock != NULL) {
+ PR_DestroyLock(alarm->lock);
+ }
PR_DELETE(alarm);
return NULL;
} /* CreateAlarm */
@@ -180,8 +194,9 @@ PR_IMPLEMENT(PRStatus) PR_DestroyAlarm(PRAlarm *alarm)
rv = PR_NotifyCondVar(alarm->cond);
PR_Unlock(alarm->lock);
- if (rv == PR_SUCCESS)
+ if (rv == PR_SUCCESS) {
rv = PR_JoinThread(alarm->notifier);
+ }
if (rv == PR_SUCCESS)
{
PR_DestroyCondVar(alarm->cond);
@@ -204,8 +219,9 @@ PR_IMPLEMENT(PRAlarmID*) PR_SetAlarm(
PRAlarmID *id = PR_NEWZAP(PRAlarmID);
- if (!id)
+ if (!id) {
return NULL;
+ }
id->alarm = alarm;
PR_INIT_CLIST(&id->list);
@@ -232,8 +248,9 @@ PR_IMPLEMENT(PRStatus) PR_ResetAlarm(
* need locking because it can only be called from within the
* notify routine.
*/
- if (id != id->alarm->current)
+ if (id != id->alarm->current) {
return PR_FAILURE;
+ }
id->period = period;
id->rate = rate;
id->accumulator = 1;
diff --git a/nsprpub/pr/src/misc/pratom.c b/nsprpub/pr/src/misc/pratom.c
index 65e6f3cd8..4f0e3da30 100644
--- a/nsprpub/pr/src/misc/pratom.c
+++ b/nsprpub/pr/src/misc/pratom.c
@@ -43,91 +43,94 @@
/*
* lock counts should be a power of 2
*/
-#define DEFAULT_ATOMIC_LOCKS 16 /* should be in sync with the number of initializers
- below */
-#define MAX_ATOMIC_LOCKS (4 * 1024)
+#define DEFAULT_ATOMIC_LOCKS 16 /* should be in sync with the number of initializers
+ below */
+#define MAX_ATOMIC_LOCKS (4 * 1024)
static pthread_mutex_t static_atomic_locks[DEFAULT_ATOMIC_LOCKS] = {
- PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER,
- PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER,
- PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER,
- PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER,
- PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER,
- PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER,
- PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER,
- PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER };
+ PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER,
+ PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER,
+ PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER,
+ PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER,
+ PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER,
+ PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER,
+ PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER,
+ PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER
+};
#ifdef DEBUG
static PRInt32 static_hash_lock_counts[DEFAULT_ATOMIC_LOCKS];
static PRInt32 *hash_lock_counts = static_hash_lock_counts;
#endif
-static PRUint32 num_atomic_locks = DEFAULT_ATOMIC_LOCKS;
+static PRUint32 num_atomic_locks = DEFAULT_ATOMIC_LOCKS;
static pthread_mutex_t *atomic_locks = static_atomic_locks;
static PRUint32 atomic_hash_mask = DEFAULT_ATOMIC_LOCKS - 1;
-#define _PR_HASH_FOR_LOCK(ptr) \
- ((PRUint32) (((PRUptrdiff) (ptr) >> 2) ^ \
- ((PRUptrdiff) (ptr) >> 8)) & \
- atomic_hash_mask)
+#define _PR_HASH_FOR_LOCK(ptr) \
+ ((PRUint32) (((PRUptrdiff) (ptr) >> 2) ^ \
+ ((PRUptrdiff) (ptr) >> 8)) & \
+ atomic_hash_mask)
void _PR_MD_INIT_ATOMIC()
{
-char *eval;
-int index;
-
-
- PR_ASSERT(PR_FloorLog2(MAX_ATOMIC_LOCKS) ==
- PR_CeilingLog2(MAX_ATOMIC_LOCKS));
-
- PR_ASSERT(PR_FloorLog2(DEFAULT_ATOMIC_LOCKS) ==
- PR_CeilingLog2(DEFAULT_ATOMIC_LOCKS));
-
- if (((eval = getenv("NSPR_ATOMIC_HASH_LOCKS")) != NULL) &&
- ((num_atomic_locks = atoi(eval)) != DEFAULT_ATOMIC_LOCKS)) {
-
- if (num_atomic_locks > MAX_ATOMIC_LOCKS)
- num_atomic_locks = MAX_ATOMIC_LOCKS;
- else if (num_atomic_locks < 1)
- num_atomic_locks = 1;
- else {
- num_atomic_locks = PR_FloorLog2(num_atomic_locks);
- num_atomic_locks = 1L << num_atomic_locks;
- }
- atomic_locks = (pthread_mutex_t *) PR_Malloc(sizeof(pthread_mutex_t) *
- num_atomic_locks);
- if (atomic_locks) {
- for (index = 0; index < num_atomic_locks; index++) {
- if (pthread_mutex_init(&atomic_locks[index], NULL)) {
- PR_DELETE(atomic_locks);
- atomic_locks = NULL;
- break;
- }
- }
- }
+ char *eval;
+ int index;
+
+
+ PR_ASSERT(PR_FloorLog2(MAX_ATOMIC_LOCKS) ==
+ PR_CeilingLog2(MAX_ATOMIC_LOCKS));
+
+ PR_ASSERT(PR_FloorLog2(DEFAULT_ATOMIC_LOCKS) ==
+ PR_CeilingLog2(DEFAULT_ATOMIC_LOCKS));
+
+ if (((eval = getenv("NSPR_ATOMIC_HASH_LOCKS")) != NULL) &&
+ ((num_atomic_locks = atoi(eval)) != DEFAULT_ATOMIC_LOCKS)) {
+
+ if (num_atomic_locks > MAX_ATOMIC_LOCKS) {
+ num_atomic_locks = MAX_ATOMIC_LOCKS;
+ }
+ else if (num_atomic_locks < 1) {
+ num_atomic_locks = 1;
+ }
+ else {
+ num_atomic_locks = PR_FloorLog2(num_atomic_locks);
+ num_atomic_locks = 1L << num_atomic_locks;
+ }
+ atomic_locks = (pthread_mutex_t *) PR_Malloc(sizeof(pthread_mutex_t) *
+ num_atomic_locks);
+ if (atomic_locks) {
+ for (index = 0; index < num_atomic_locks; index++) {
+ if (pthread_mutex_init(&atomic_locks[index], NULL)) {
+ PR_DELETE(atomic_locks);
+ atomic_locks = NULL;
+ break;
+ }
+ }
+ }
#ifdef DEBUG
- if (atomic_locks) {
- hash_lock_counts = PR_CALLOC(num_atomic_locks * sizeof(PRInt32));
- if (hash_lock_counts == NULL) {
- PR_DELETE(atomic_locks);
- atomic_locks = NULL;
- }
- }
+ if (atomic_locks) {
+ hash_lock_counts = PR_CALLOC(num_atomic_locks * sizeof(PRInt32));
+ if (hash_lock_counts == NULL) {
+ PR_DELETE(atomic_locks);
+ atomic_locks = NULL;
+ }
+ }
#endif
- if (atomic_locks == NULL) {
- /*
- * Use statically allocated locks
- */
- atomic_locks = static_atomic_locks;
- num_atomic_locks = DEFAULT_ATOMIC_LOCKS;
- #ifdef DEBUG
- hash_lock_counts = static_hash_lock_counts;
- #endif
- }
- atomic_hash_mask = num_atomic_locks - 1;
- }
- PR_ASSERT(PR_FloorLog2(num_atomic_locks) ==
- PR_CeilingLog2(num_atomic_locks));
+ if (atomic_locks == NULL) {
+ /*
+ * Use statically allocated locks
+ */
+ atomic_locks = static_atomic_locks;
+ num_atomic_locks = DEFAULT_ATOMIC_LOCKS;
+#ifdef DEBUG
+ hash_lock_counts = static_hash_lock_counts;
+#endif
+ }
+ atomic_hash_mask = num_atomic_locks - 1;
+ }
+ PR_ASSERT(PR_FloorLog2(num_atomic_locks) ==
+ PR_CeilingLog2(num_atomic_locks));
}
PRInt32
@@ -299,55 +302,57 @@ PR_AtomicAdd(PRInt32 *ptr, PRInt32 val)
PR_IMPLEMENT(PRStack *)
PR_CreateStack(const char *stack_name)
{
-PRStack *stack;
+ PRStack *stack;
if (!_pr_initialized) {
_PR_ImplicitInitialization();
}
if ((stack = PR_NEW(PRStack)) == NULL) {
- return NULL;
- }
- if (stack_name) {
- stack->prstk_name = (char *) PR_Malloc(strlen(stack_name) + 1);
- if (stack->prstk_name == NULL) {
- PR_DELETE(stack);
- return NULL;
- }
- strcpy(stack->prstk_name, stack_name);
- } else
- stack->prstk_name = NULL;
+ return NULL;
+ }
+ if (stack_name) {
+ stack->prstk_name = (char *) PR_Malloc(strlen(stack_name) + 1);
+ if (stack->prstk_name == NULL) {
+ PR_DELETE(stack);
+ return NULL;
+ }
+ strcpy(stack->prstk_name, stack_name);
+ } else {
+ stack->prstk_name = NULL;
+ }
#ifndef _PR_HAVE_ATOMIC_CAS
stack->prstk_lock = PR_NewLock();
- if (stack->prstk_lock == NULL) {
- PR_Free(stack->prstk_name);
- PR_DELETE(stack);
- return NULL;
- }
+ if (stack->prstk_lock == NULL) {
+ PR_Free(stack->prstk_name);
+ PR_DELETE(stack);
+ return NULL;
+ }
#endif /* !_PR_HAVE_ATOMIC_CAS */
- stack->prstk_head.prstk_elem_next = NULL;
-
+ stack->prstk_head.prstk_elem_next = NULL;
+
return stack;
}
PR_IMPLEMENT(PRStatus)
PR_DestroyStack(PRStack *stack)
{
- if (stack->prstk_head.prstk_elem_next != NULL) {
- PR_SetError(PR_INVALID_STATE_ERROR, 0);
- return PR_FAILURE;
- }
+ if (stack->prstk_head.prstk_elem_next != NULL) {
+ PR_SetError(PR_INVALID_STATE_ERROR, 0);
+ return PR_FAILURE;
+ }
- if (stack->prstk_name)
- PR_Free(stack->prstk_name);
+ if (stack->prstk_name) {
+ PR_Free(stack->prstk_name);
+ }
#ifndef _PR_HAVE_ATOMIC_CAS
- PR_DestroyLock(stack->prstk_lock);
+ PR_DestroyLock(stack->prstk_lock);
#endif /* !_PR_HAVE_ATOMIC_CAS */
- PR_DELETE(stack);
+ PR_DELETE(stack);
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
#ifndef _PR_HAVE_ATOMIC_CAS
@@ -356,8 +361,8 @@ PR_IMPLEMENT(void)
PR_StackPush(PRStack *stack, PRStackElem *stack_elem)
{
PR_Lock(stack->prstk_lock);
- stack_elem->prstk_elem_next = stack->prstk_head.prstk_elem_next;
- stack->prstk_head.prstk_elem_next = stack_elem;
+ stack_elem->prstk_elem_next = stack->prstk_head.prstk_elem_next;
+ stack->prstk_head.prstk_elem_next = stack_elem;
PR_Unlock(stack->prstk_lock);
return;
}
@@ -365,14 +370,14 @@ PR_StackPush(PRStack *stack, PRStackElem *stack_elem)
PR_IMPLEMENT(PRStackElem *)
PR_StackPop(PRStack *stack)
{
-PRStackElem *element;
+ PRStackElem *element;
PR_Lock(stack->prstk_lock);
- element = stack->prstk_head.prstk_elem_next;
- if (element != NULL) {
- stack->prstk_head.prstk_elem_next = element->prstk_elem_next;
- element->prstk_elem_next = NULL; /* debugging aid */
- }
+ element = stack->prstk_head.prstk_elem_next;
+ if (element != NULL) {
+ stack->prstk_head.prstk_elem_next = element->prstk_elem_next;
+ element->prstk_elem_next = NULL; /* debugging aid */
+ }
PR_Unlock(stack->prstk_lock);
return element;
}
diff --git a/nsprpub/pr/src/misc/praton.c b/nsprpub/pr/src/misc/praton.c
index 80c0628cc..3e729f587 100644
--- a/nsprpub/pr/src/misc/praton.c
+++ b/nsprpub/pr/src/misc/praton.c
@@ -10,7 +10,7 @@
/*
* Copyright (c) 1983, 1990, 1993
* The Regents of the University of California. All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -22,7 +22,7 @@
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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
@@ -38,14 +38,14 @@
/*
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
- *
+ *
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies, and that
* the name of Digital Equipment Corporation not be used in advertising or
* publicity pertaining to distribution of the document or software without
* specific, written prior permission.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
@@ -78,7 +78,7 @@ static const unsigned char index_hex[256] = {
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,XX,XX, XX,XX,XX,XX,
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,XX,XX, XX,XX,XX,XX,
XX,10,11,12, 13,14,15,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,10,11,12, 13,14,15,XX, XX,XX,XX,XX, XX,XX,XX,XX,
@@ -93,9 +93,15 @@ static const unsigned char index_hex[256] = {
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
};
-static PRBool _isdigit(char c) { return c >= '0' && c <= '9'; }
-static PRBool _isxdigit(char c) { return index_hex[(unsigned char) c] != XX; }
-static PRBool _isspace(char c) { return c == ' ' || (c >= '\t' && c <= '\r'); }
+static PRBool _isdigit(char c) {
+ return c >= '0' && c <= '9';
+}
+static PRBool _isxdigit(char c) {
+ return index_hex[(unsigned char) c] != XX;
+}
+static PRBool _isspace(char c) {
+ return c == ' ' || (c >= '\t' && c <= '\r');
+}
#undef XX
int
@@ -115,13 +121,15 @@ pr_inet_aton(const char *cp, PRUint32 *addr)
* Values are specified as for C:
* 0x=hex, 0=octal, isdigit=decimal.
*/
- if (!_isdigit(c))
+ if (!_isdigit(c)) {
return (0);
+ }
val = 0; base = 10; digit = 0;
if (c == '0') {
c = *++cp;
- if (c == 'x' || c == 'X')
+ if (c == 'x' || c == 'X') {
base = 16, c = *++cp;
+ }
else {
base = 8;
digit = 1;
@@ -129,8 +137,9 @@ pr_inet_aton(const char *cp, PRUint32 *addr)
}
for (;;) {
if (_isdigit(c)) {
- if (base == 8 && (c == '8' || c == '9'))
+ if (base == 8 && (c == '8' || c == '9')) {
return (0);
+ }
val = (val * base) + (c - '0');
c = *++cp;
digit = 1;
@@ -138,8 +147,9 @@ pr_inet_aton(const char *cp, PRUint32 *addr)
val = (val << 4) + index_hex[(unsigned char) c];
c = *++cp;
digit = 1;
- } else
+ } else {
break;
+ }
}
if (c == '.') {
/*
@@ -148,51 +158,58 @@ pr_inet_aton(const char *cp, PRUint32 *addr)
* a.b.c (with c treated as 16 bits)
* a.b (with b treated as 24 bits)
*/
- if (pp >= parts + 3 || val > 0xffU)
+ if (pp >= parts + 3 || val > 0xffU) {
return (0);
+ }
*pp++ = val;
c = *++cp;
- } else
+ } else {
break;
+ }
}
/*
* Check for trailing characters.
*/
- if (c != '\0' && !_isspace(c))
+ if (c != '\0' && !_isspace(c)) {
return (0);
+ }
/*
* Did we get a valid digit?
*/
- if (!digit)
+ if (!digit) {
return (0);
+ }
/*
* Concoct the address according to
* the number of parts specified.
*/
n = pp - parts + 1;
switch (n) {
- case 1: /*%< a -- 32 bits */
- break;
+ case 1: /*%< a -- 32 bits */
+ break;
- case 2: /*%< a.b -- 8.24 bits */
- if (val > 0xffffffU)
- return (0);
- val |= (unsigned int)parts[0] << 24;
- break;
+ case 2: /*%< a.b -- 8.24 bits */
+ if (val > 0xffffffU) {
+ return (0);
+ }
+ val |= (unsigned int)parts[0] << 24;
+ break;
- case 3: /*%< a.b.c -- 8.8.16 bits */
- if (val > 0xffffU)
- return (0);
- val |= ((unsigned int)parts[0] << 24) | ((unsigned int)parts[1] << 16);
- break;
+ case 3: /*%< a.b.c -- 8.8.16 bits */
+ if (val > 0xffffU) {
+ return (0);
+ }
+ val |= ((unsigned int)parts[0] << 24) | ((unsigned int)parts[1] << 16);
+ break;
- case 4: /*%< a.b.c.d -- 8.8.8.8 bits */
- if (val > 0xffU)
- return (0);
- val |= ((unsigned int)parts[0] << 24) |
- ((unsigned int)parts[1] << 16) |
- ((unsigned int)parts[2] << 8);
- break;
+ case 4: /*%< a.b.c.d -- 8.8.8.8 bits */
+ if (val > 0xffU) {
+ return (0);
+ }
+ val |= ((unsigned int)parts[0] << 24) |
+ ((unsigned int)parts[1] << 16) |
+ ((unsigned int)parts[2] << 8);
+ break;
}
*addr = PR_htonl(val);
return (1);
diff --git a/nsprpub/pr/src/misc/prcountr.c b/nsprpub/pr/src/misc/prcountr.c
index 0f126ad08..29d7d4ccb 100644
--- a/nsprpub/pr/src/misc/prcountr.c
+++ b/nsprpub/pr/src/misc/prcountr.c
@@ -10,16 +10,16 @@
**
** Design Notes:
**
-** The Counter Facility (CF) has a single anchor: qNameList.
+** The Counter Facility (CF) has a single anchor: qNameList.
** The anchor is a PRCList. qNameList is a list of links in QName
** structures. From qNameList any QName structure and its
-** associated RName structure can be located.
-**
+** associated RName structure can be located.
+**
** For each QName, a list of RName structures is anchored at
** rnLink in the QName structure.
-**
+**
** The counter itself is embedded in the RName structure.
-**
+**
** For manipulating the counter database, single lock is used to
** protect the entire list: counterLock.
**
@@ -29,7 +29,7 @@
** "overloaded" for traversing the QName structures; only the
** function PR_FindNextQnameHandle() uses this overloading.
**
-**
+**
** ToDo (lth): decide on how to lock or atomically update
** individual counters. Candidates are: the global lock; a lock
** per RName structure; Atomic operations (Note that there are
@@ -64,9 +64,9 @@ typedef struct RName
PRCList link;
QName *qName;
PRLock *lock;
- volatile PRUint32 counter;
- char name[PRCOUNTER_NAME_MAX+1];
- char desc[PRCOUNTER_DESC_MAX+1];
+ volatile PRUint32 counter;
+ char name[PRCOUNTER_NAME_MAX+1];
+ char desc[PRCOUNTER_DESC_MAX+1];
} RName;
@@ -87,7 +87,7 @@ static void _PR_CounterInitialize( void )
** This function should be called only once
*/
PR_ASSERT( counterLock == NULL );
-
+
counterLock = PR_NewLock();
PR_INIT_CLIST( &qNameList );
lm = PR_NewLogModule("counters");
@@ -111,20 +111,21 @@ static void _PR_CounterInitialize( void )
** Unlock
**
*/
-PR_IMPLEMENT(PRCounterHandle)
- PR_CreateCounter(
- const char *qName,
- const char *rName,
- const char *description
-)
+PR_IMPLEMENT(PRCounterHandle)
+PR_CreateCounter(
+ const char *qName,
+ const char *rName,
+ const char *description
+)
{
QName *qnp;
RName *rnp;
PRBool matchQname = PR_FALSE;
/* Self initialize, if necessary */
- if ( counterLock == NULL )
+ if ( counterLock == NULL ) {
_PR_CounterInitialize();
+ }
/* Validate input arguments */
PR_ASSERT( strlen(qName) <= PRCOUNTER_NAME_MAX );
@@ -157,10 +158,10 @@ PR_IMPLEMENT(PRCounterHandle)
{
qnp = PR_NEWZAP( QName );
PR_ASSERT( qnp != NULL );
- PR_INIT_CLIST( &qnp->link );
- PR_INIT_CLIST( &qnp->rNameList );
+ PR_INIT_CLIST( &qnp->link );
+ PR_INIT_CLIST( &qnp->rNameList );
strcpy( qnp->name, qName );
- PR_APPEND_LINK( &qnp->link, &qNameList );
+ PR_APPEND_LINK( &qnp->link, &qNameList );
}
/* Do we already have a matching RName? */
@@ -189,31 +190,31 @@ PR_IMPLEMENT(PRCounterHandle)
PR_ASSERT(0);
}
- PR_APPEND_LINK( &rnp->link, &qnp->rNameList ); /* add RName to QName's rnList */
+ PR_APPEND_LINK( &rnp->link, &qnp->rNameList ); /* add RName to QName's rnList */
rnp->qName = qnp; /* point the RName to the QName */
/* Unlock the Facility */
PR_Unlock( counterLock );
PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: Create: QName: %s %p, RName: %s %p\n\t",
- qName, qnp, rName, rnp ));
+ qName, qnp, rName, rnp ));
return((PRCounterHandle)rnp);
} /* end PR_CreateCounter() */
-
+
/*
**
*/
-PR_IMPLEMENT(void)
- PR_DestroyCounter(
- PRCounterHandle handle
+PR_IMPLEMENT(void)
+PR_DestroyCounter(
+ PRCounterHandle handle
)
{
RName *rnp = (RName *)handle;
QName *qnp = rnp->qName;
- PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: Deleting: QName: %s, RName: %s",
- qnp->name, rnp->name));
+ PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: Deleting: QName: %s, RName: %s",
+ qnp->name, rnp->name));
/* Lock the Facility */
PR_Lock( counterLock );
@@ -222,8 +223,8 @@ PR_IMPLEMENT(void)
** Remove RName from the list of RNames in QName
** and free RName
*/
- PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: Deleting RName: %s, %p",
- rnp->name, rnp));
+ PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: Deleting RName: %s, %p",
+ rnp->name, rnp));
PR_REMOVE_LINK( &rnp->link );
PR_Free( rnp->lock );
PR_DELETE( rnp );
@@ -234,11 +235,11 @@ PR_IMPLEMENT(void)
*/
if ( PR_CLIST_IS_EMPTY( &qnp->rNameList ) )
{
- PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: Deleting unused QName: %s, %p",
- qnp->name, qnp));
+ PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: Deleting unused QName: %s, %p",
+ qnp->name, qnp));
PR_REMOVE_LINK( &qnp->link );
PR_DELETE( qnp );
- }
+ }
/* Unlock the Facility */
PR_Unlock( counterLock );
@@ -248,10 +249,10 @@ PR_IMPLEMENT(void)
/*
**
*/
-PR_IMPLEMENT(PRCounterHandle)
- PR_GetCounterHandleFromName(
- const char *qName,
- const char *rName
+PR_IMPLEMENT(PRCounterHandle)
+PR_GetCounterHandleFromName(
+ const char *qName,
+ const char *rName
)
{
const char *qn, *rn, *desc;
@@ -259,7 +260,7 @@ PR_IMPLEMENT(PRCounterHandle)
RName *rnp = NULL;
PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: GetCounterHandleFromName:\n\t"
- "QName: %s, RName: %s", qName, rName ));
+ "QName: %s, RName: %s", qName, rName ));
qh = PR_FindNextCounterQname( NULL );
while (qh != NULL)
@@ -269,7 +270,7 @@ PR_IMPLEMENT(PRCounterHandle)
{
PR_GetCounterNameFromHandle( rh, &qn, &rn, &desc );
if ( (strcmp( qName, qn ) == 0)
- && (strcmp( rName, rn ) == 0 ))
+ && (strcmp( rName, rn ) == 0 ))
{
rnp = (RName *)rh;
goto foundIt;
@@ -287,12 +288,12 @@ foundIt:
/*
**
*/
-PR_IMPLEMENT(void)
- PR_GetCounterNameFromHandle(
- PRCounterHandle handle,
- const char **qName,
- const char **rName,
- const char **description
+PR_IMPLEMENT(void)
+PR_GetCounterNameFromHandle(
+ PRCounterHandle handle,
+ const char **qName,
+ const char **rName,
+ const char **description
)
{
RName *rnp = (RName *)handle;
@@ -303,8 +304,8 @@ PR_IMPLEMENT(void)
*description = rnp->desc;
PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: GetConterNameFromHandle: "
- "QNp: %p, RNp: %p,\n\tQName: %s, RName: %s, Desc: %s",
- qnp, rnp, qnp->name, rnp->name, rnp->desc ));
+ "QNp: %p, RNp: %p,\n\tQName: %s, RName: %s, Desc: %s",
+ qnp, rnp, qnp->name, rnp->name, rnp->desc ));
return;
} /* end PR_GetCounterNameFromHandle() */
@@ -313,17 +314,17 @@ PR_IMPLEMENT(void)
/*
**
*/
-PR_IMPLEMENT(void)
- PR_IncrementCounter(
- PRCounterHandle handle
+PR_IMPLEMENT(void)
+PR_IncrementCounter(
+ PRCounterHandle handle
)
{
PR_Lock(((RName *)handle)->lock);
((RName *)handle)->counter++;
PR_Unlock(((RName *)handle)->lock);
- PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: Increment: %p, %ld",
- handle, ((RName *)handle)->counter ));
+ PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: Increment: %p, %ld",
+ handle, ((RName *)handle)->counter ));
return;
} /* end PR_IncrementCounter() */
@@ -333,17 +334,17 @@ PR_IMPLEMENT(void)
/*
**
*/
-PR_IMPLEMENT(void)
- PR_DecrementCounter(
- PRCounterHandle handle
+PR_IMPLEMENT(void)
+PR_DecrementCounter(
+ PRCounterHandle handle
)
{
PR_Lock(((RName *)handle)->lock);
((RName *)handle)->counter--;
PR_Unlock(((RName *)handle)->lock);
- PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: Decrement: %p, %ld",
- handle, ((RName *)handle)->counter ));
+ PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: Decrement: %p, %ld",
+ handle, ((RName *)handle)->counter ));
return;
} /* end PR_DecrementCounter() */
@@ -352,18 +353,18 @@ PR_IMPLEMENT(void)
/*
**
*/
-PR_IMPLEMENT(void)
- PR_AddToCounter(
- PRCounterHandle handle,
- PRUint32 value
+PR_IMPLEMENT(void)
+PR_AddToCounter(
+ PRCounterHandle handle,
+ PRUint32 value
)
{
PR_Lock(((RName *)handle)->lock);
((RName *)handle)->counter += value;
PR_Unlock(((RName *)handle)->lock);
- PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: AddToCounter: %p, %ld",
- handle, ((RName *)handle)->counter ));
+ PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: AddToCounter: %p, %ld",
+ handle, ((RName *)handle)->counter ));
return;
} /* end PR_AddToCounter() */
@@ -372,18 +373,18 @@ PR_IMPLEMENT(void)
/*
**
*/
-PR_IMPLEMENT(void)
- PR_SubtractFromCounter(
- PRCounterHandle handle,
- PRUint32 value
+PR_IMPLEMENT(void)
+PR_SubtractFromCounter(
+ PRCounterHandle handle,
+ PRUint32 value
)
{
PR_Lock(((RName *)handle)->lock);
((RName *)handle)->counter -= value;
PR_Unlock(((RName *)handle)->lock);
-
- PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: SubtractFromCounter: %p, %ld",
- handle, ((RName *)handle)->counter ));
+
+ PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: SubtractFromCounter: %p, %ld",
+ handle, ((RName *)handle)->counter ));
return;
} /* end PR_SubtractFromCounter() */
@@ -391,13 +392,13 @@ PR_IMPLEMENT(void)
/*
**
*/
-PR_IMPLEMENT(PRUint32)
- PR_GetCounter(
- PRCounterHandle handle
+PR_IMPLEMENT(PRUint32)
+PR_GetCounter(
+ PRCounterHandle handle
)
{
- PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: GetCounter: %p, %ld",
- handle, ((RName *)handle)->counter ));
+ PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: GetCounter: %p, %ld",
+ handle, ((RName *)handle)->counter ));
return(((RName *)handle)->counter);
} /* end PR_GetCounter() */
@@ -405,16 +406,16 @@ PR_IMPLEMENT(PRUint32)
/*
**
*/
-PR_IMPLEMENT(void)
- PR_SetCounter(
- PRCounterHandle handle,
- PRUint32 value
+PR_IMPLEMENT(void)
+PR_SetCounter(
+ PRCounterHandle handle,
+ PRUint32 value
)
{
((RName *)handle)->counter = value;
- PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: SetCounter: %p, %ld",
- handle, ((RName *)handle)->counter ));
+ PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: SetCounter: %p, %ld",
+ handle, ((RName *)handle)->counter ));
return;
} /* end PR_SetCounter() */
@@ -422,24 +423,28 @@ PR_IMPLEMENT(void)
/*
**
*/
-PR_IMPLEMENT(PRCounterHandle)
- PR_FindNextCounterQname(
- PRCounterHandle handle
+PR_IMPLEMENT(PRCounterHandle)
+PR_FindNextCounterQname(
+ PRCounterHandle handle
)
{
QName *qnp = (QName *)handle;
- if ( PR_CLIST_IS_EMPTY( &qNameList ))
- qnp = NULL;
- else if ( qnp == NULL )
+ if ( PR_CLIST_IS_EMPTY( &qNameList )) {
+ qnp = NULL;
+ }
+ else if ( qnp == NULL ) {
qnp = (QName *)PR_LIST_HEAD( &qNameList );
- else if ( PR_NEXT_LINK( &qnp->link ) == &qNameList )
+ }
+ else if ( PR_NEXT_LINK( &qnp->link ) == &qNameList ) {
qnp = NULL;
- else
+ }
+ else {
qnp = (QName *)PR_NEXT_LINK( &qnp->link );
+ }
- PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: FindNextQname: Handle: %p, Returns: %p",
- handle, qnp ));
+ PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: FindNextQname: Handle: %p, Returns: %p",
+ handle, qnp ));
return((PRCounterHandle)qnp);
} /* end PR_FindNextCounterQname() */
@@ -448,27 +453,31 @@ PR_IMPLEMENT(PRCounterHandle)
/*
**
*/
-PR_IMPLEMENT(PRCounterHandle)
- PR_FindNextCounterRname(
- PRCounterHandle rhandle,
- PRCounterHandle qhandle
+PR_IMPLEMENT(PRCounterHandle)
+PR_FindNextCounterRname(
+ PRCounterHandle rhandle,
+ PRCounterHandle qhandle
)
{
RName *rnp = (RName *)rhandle;
QName *qnp = (QName *)qhandle;
- if ( PR_CLIST_IS_EMPTY( &qnp->rNameList ))
+ if ( PR_CLIST_IS_EMPTY( &qnp->rNameList )) {
rnp = NULL;
- else if ( rnp == NULL )
+ }
+ else if ( rnp == NULL ) {
rnp = (RName *)PR_LIST_HEAD( &qnp->rNameList );
- else if ( PR_NEXT_LINK( &rnp->link ) == &qnp->rNameList )
+ }
+ else if ( PR_NEXT_LINK( &rnp->link ) == &qnp->rNameList ) {
rnp = NULL;
- else
+ }
+ else {
rnp = (RName *)PR_NEXT_LINK( &rnp->link );
+ }
- PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: FindNextRname: Rhandle: %p, QHandle: %p, Returns: %p",
- rhandle, qhandle, rnp ));
+ PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: FindNextRname: Rhandle: %p, QHandle: %p, Returns: %p",
+ rhandle, qhandle, rnp ));
return((PRCounterHandle)rnp);
} /* end PR_FindNextCounterRname() */
diff --git a/nsprpub/pr/src/misc/prdtoa.c b/nsprpub/pr/src/misc/prdtoa.c
index 227692613..f0963370f 100644
--- a/nsprpub/pr/src/misc/prdtoa.c
+++ b/nsprpub/pr/src/misc/prdtoa.c
@@ -17,8 +17,8 @@
#include "prbit.h"
#define MULTIPLE_THREADS
-#define ACQUIRE_DTOA_LOCK(n) PR_Lock(dtoa_lock[n])
-#define FREE_DTOA_LOCK(n) PR_Unlock(dtoa_lock[n])
+#define ACQUIRE_DTOA_LOCK(n) PR_Lock(dtoa_lock[n])
+#define FREE_DTOA_LOCK(n) PR_Unlock(dtoa_lock[n])
static PRLock *dtoa_lock[2];
@@ -74,13 +74,13 @@ void _PR_CleanupDtoa(void)
***************************************************************/
/* Please send bug reports to David M. Gay (dmg at acm dot org,
- * with " at " changed at "@" and " dot " changed to "."). */
+ * with " at " changed at "@" and " dot " changed to "."). */
/* On a machine with IEEE extended-precision registers, it is
* necessary to specify double-precision (53-bit) rounding precision
* before invoking strtod or dtoa. If the machine uses (the equivalent
* of) Intel 80x87 arithmetic, the call
- * _control87(PC_53, MCW_PC);
+ * _control87(PC_53, MCW_PC);
* does this with many compilers. Whether this or another call is
* appropriate depends on the compiler; for this to work, it may be
* necessary to #include "float.h" or another system-dependent header
@@ -99,127 +99,127 @@ void _PR_CleanupDtoa(void)
*
* Modifications:
*
- * 1. We only require IEEE, IBM, or VAX double-precision
- * arithmetic (not IEEE double-extended).
- * 2. We get by with floating-point arithmetic in a case that
- * Clinger missed -- when we're computing d * 10^n
- * for a small integer d and the integer n is not too
- * much larger than 22 (the maximum integer k for which
- * we can represent 10^k exactly), we may be able to
- * compute (d*10^k) * 10^(e-k) with just one roundoff.
- * 3. Rather than a bit-at-a-time adjustment of the binary
- * result in the hard case, we use floating-point
- * arithmetic to determine the adjustment to within
- * one bit; only in really hard cases do we need to
- * compute a second residual.
- * 4. Because of 3., we don't need a large table of powers of 10
- * for ten-to-e (just some small tables, e.g. of 10^k
- * for 0 <= k <= 22).
+ * 1. We only require IEEE, IBM, or VAX double-precision
+ * arithmetic (not IEEE double-extended).
+ * 2. We get by with floating-point arithmetic in a case that
+ * Clinger missed -- when we're computing d * 10^n
+ * for a small integer d and the integer n is not too
+ * much larger than 22 (the maximum integer k for which
+ * we can represent 10^k exactly), we may be able to
+ * compute (d*10^k) * 10^(e-k) with just one roundoff.
+ * 3. Rather than a bit-at-a-time adjustment of the binary
+ * result in the hard case, we use floating-point
+ * arithmetic to determine the adjustment to within
+ * one bit; only in really hard cases do we need to
+ * compute a second residual.
+ * 4. Because of 3., we don't need a large table of powers of 10
+ * for ten-to-e (just some small tables, e.g. of 10^k
+ * for 0 <= k <= 22).
*/
/*
* #define IEEE_8087 for IEEE-arithmetic machines where the least
- * significant byte has the lowest address.
+ * significant byte has the lowest address.
* #define IEEE_MC68k for IEEE-arithmetic machines where the most
- * significant byte has the lowest address.
+ * significant byte has the lowest address.
* #define IEEE_ARM for IEEE-arithmetic machines where the two words
- * in a double are stored in big endian order but the two shorts
- * in a word are still stored in little endian order.
+ * in a double are stored in big endian order but the two shorts
+ * in a word are still stored in little endian order.
* #define Long int on machines with 32-bit ints and 64-bit longs.
* #define IBM for IBM mainframe-style floating-point arithmetic.
* #define VAX for VAX-style floating-point arithmetic (D_floating).
* #define No_leftright to omit left-right logic in fast floating-point
- * computation of dtoa.
+ * computation of dtoa.
* #define Honor_FLT_ROUNDS if FLT_ROUNDS can assume the values 2 or 3
- * and strtod and dtoa should round accordingly.
+ * and strtod and dtoa should round accordingly.
* #define Check_FLT_ROUNDS if FLT_ROUNDS can assume the values 2 or 3
- * and Honor_FLT_ROUNDS is not #defined.
+ * and Honor_FLT_ROUNDS is not #defined.
* #define RND_PRODQUOT to use rnd_prod and rnd_quot (assembly routines
- * that use extended-precision instructions to compute rounded
- * products and quotients) with IBM.
+ * that use extended-precision instructions to compute rounded
+ * products and quotients) with IBM.
* #define ROUND_BIASED for IEEE-format with biased rounding.
* #define Inaccurate_Divide for IEEE-format with correctly rounded
- * products but inaccurate quotients, e.g., for Intel i860.
+ * products but inaccurate quotients, e.g., for Intel i860.
* #define NO_LONG_LONG on machines that do not have a "long long"
- * integer type (of >= 64 bits). On such machines, you can
- * #define Just_16 to store 16 bits per 32-bit Long when doing
- * high-precision integer arithmetic. Whether this speeds things
- * up or slows things down depends on the machine and the number
- * being converted. If long long is available and the name is
- * something other than "long long", #define Llong to be the name,
- * and if "unsigned Llong" does not work as an unsigned version of
- * Llong, #define #ULLong to be the corresponding unsigned type.
+ * integer type (of >= 64 bits). On such machines, you can
+ * #define Just_16 to store 16 bits per 32-bit Long when doing
+ * high-precision integer arithmetic. Whether this speeds things
+ * up or slows things down depends on the machine and the number
+ * being converted. If long long is available and the name is
+ * something other than "long long", #define Llong to be the name,
+ * and if "unsigned Llong" does not work as an unsigned version of
+ * Llong, #define #ULLong to be the corresponding unsigned type.
* #define KR_headers for old-style C function headers.
* #define Bad_float_h if your system lacks a float.h or if it does not
- * define some or all of DBL_DIG, DBL_MAX_10_EXP, DBL_MAX_EXP,
- * FLT_RADIX, FLT_ROUNDS, and DBL_MAX.
+ * define some or all of DBL_DIG, DBL_MAX_10_EXP, DBL_MAX_EXP,
+ * FLT_RADIX, FLT_ROUNDS, and DBL_MAX.
* #define MALLOC your_malloc, where your_malloc(n) acts like malloc(n)
- * if memory is available and otherwise does something you deem
- * appropriate. If MALLOC is undefined, malloc will be invoked
- * directly -- and assumed always to succeed. Similarly, if you
- * want something other than the system's free() to be called to
- * recycle memory acquired from MALLOC, #define FREE to be the
- * name of the alternate routine. (FREE or free is only called in
- * pathological cases, e.g., in a dtoa call after a dtoa return in
- * mode 3 with thousands of digits requested.)
+ * if memory is available and otherwise does something you deem
+ * appropriate. If MALLOC is undefined, malloc will be invoked
+ * directly -- and assumed always to succeed. Similarly, if you
+ * want something other than the system's free() to be called to
+ * recycle memory acquired from MALLOC, #define FREE to be the
+ * name of the alternate routine. (FREE or free is only called in
+ * pathological cases, e.g., in a dtoa call after a dtoa return in
+ * mode 3 with thousands of digits requested.)
* #define Omit_Private_Memory to omit logic (added Jan. 1998) for making
- * memory allocations from a private pool of memory when possible.
- * When used, the private pool is PRIVATE_MEM bytes long: 2304 bytes,
- * unless #defined to be a different length. This default length
- * suffices to get rid of MALLOC calls except for unusual cases,
- * such as decimal-to-binary conversion of a very long string of
- * digits. The longest string dtoa can return is about 751 bytes
- * long. For conversions by strtod of strings of 800 digits and
- * all dtoa conversions in single-threaded executions with 8-byte
- * pointers, PRIVATE_MEM >= 7400 appears to suffice; with 4-byte
- * pointers, PRIVATE_MEM >= 7112 appears adequate.
+ * memory allocations from a private pool of memory when possible.
+ * When used, the private pool is PRIVATE_MEM bytes long: 2304 bytes,
+ * unless #defined to be a different length. This default length
+ * suffices to get rid of MALLOC calls except for unusual cases,
+ * such as decimal-to-binary conversion of a very long string of
+ * digits. The longest string dtoa can return is about 751 bytes
+ * long. For conversions by strtod of strings of 800 digits and
+ * all dtoa conversions in single-threaded executions with 8-byte
+ * pointers, PRIVATE_MEM >= 7400 appears to suffice; with 4-byte
+ * pointers, PRIVATE_MEM >= 7112 appears adequate.
* #define INFNAN_CHECK on IEEE systems to cause strtod to check for
- * Infinity and NaN (case insensitively). On some systems (e.g.,
- * some HP systems), it may be necessary to #define NAN_WORD0
- * appropriately -- to the most significant word of a quiet NaN.
- * (On HP Series 700/800 machines, -DNAN_WORD0=0x7ff40000 works.)
- * When INFNAN_CHECK is #defined and No_Hex_NaN is not #defined,
- * strtod also accepts (case insensitively) strings of the form
- * NaN(x), where x is a string of hexadecimal digits and spaces;
- * if there is only one string of hexadecimal digits, it is taken
- * for the 52 fraction bits of the resulting NaN; if there are two
- * or more strings of hex digits, the first is for the high 20 bits,
- * the second and subsequent for the low 32 bits, with intervening
- * white space ignored; but if this results in none of the 52
- * fraction bits being on (an IEEE Infinity symbol), then NAN_WORD0
- * and NAN_WORD1 are used instead.
+ * Infinity and NaN (case insensitively). On some systems (e.g.,
+ * some HP systems), it may be necessary to #define NAN_WORD0
+ * appropriately -- to the most significant word of a quiet NaN.
+ * (On HP Series 700/800 machines, -DNAN_WORD0=0x7ff40000 works.)
+ * When INFNAN_CHECK is #defined and No_Hex_NaN is not #defined,
+ * strtod also accepts (case insensitively) strings of the form
+ * NaN(x), where x is a string of hexadecimal digits and spaces;
+ * if there is only one string of hexadecimal digits, it is taken
+ * for the 52 fraction bits of the resulting NaN; if there are two
+ * or more strings of hex digits, the first is for the high 20 bits,
+ * the second and subsequent for the low 32 bits, with intervening
+ * white space ignored; but if this results in none of the 52
+ * fraction bits being on (an IEEE Infinity symbol), then NAN_WORD0
+ * and NAN_WORD1 are used instead.
* #define MULTIPLE_THREADS if the system offers preemptively scheduled
- * multiple threads. In this case, you must provide (or suitably
- * #define) two locks, acquired by ACQUIRE_DTOA_LOCK(n) and freed
- * by FREE_DTOA_LOCK(n) for n = 0 or 1. (The second lock, accessed
- * in pow5mult, ensures lazy evaluation of only one copy of high
- * powers of 5; omitting this lock would introduce a small
- * probability of wasting memory, but would otherwise be harmless.)
- * You must also invoke freedtoa(s) to free the value s returned by
- * dtoa. You may do so whether or not MULTIPLE_THREADS is #defined.
+ * multiple threads. In this case, you must provide (or suitably
+ * #define) two locks, acquired by ACQUIRE_DTOA_LOCK(n) and freed
+ * by FREE_DTOA_LOCK(n) for n = 0 or 1. (The second lock, accessed
+ * in pow5mult, ensures lazy evaluation of only one copy of high
+ * powers of 5; omitting this lock would introduce a small
+ * probability of wasting memory, but would otherwise be harmless.)
+ * You must also invoke freedtoa(s) to free the value s returned by
+ * dtoa. You may do so whether or not MULTIPLE_THREADS is #defined.
* #define NO_IEEE_Scale to disable new (Feb. 1997) logic in strtod that
- * avoids underflows on inputs whose result does not underflow.
- * If you #define NO_IEEE_Scale on a machine that uses IEEE-format
- * floating-point numbers and flushes underflows to zero rather
- * than implementing gradual underflow, then you must also #define
- * Sudden_Underflow.
+ * avoids underflows on inputs whose result does not underflow.
+ * If you #define NO_IEEE_Scale on a machine that uses IEEE-format
+ * floating-point numbers and flushes underflows to zero rather
+ * than implementing gradual underflow, then you must also #define
+ * Sudden_Underflow.
* #define USE_LOCALE to use the current locale's decimal_point value.
* #define SET_INEXACT if IEEE arithmetic is being used and extra
- * computation should be done to set the inexact flag when the
- * result is inexact and avoid setting inexact when the result
- * is exact. In this case, dtoa.c must be compiled in
- * an environment, perhaps provided by #include "dtoa.c" in a
- * suitable wrapper, that defines two functions,
- * int get_inexact(void);
- * void clear_inexact(void);
- * such that get_inexact() returns a nonzero value if the
- * inexact bit is already set, and clear_inexact() sets the
- * inexact bit to 0. When SET_INEXACT is #defined, strtod
- * also does extra computations to set the underflow and overflow
- * flags when appropriate (i.e., when the result is tiny and
- * inexact or when it is a numeric value rounded to +-infinity).
+ * computation should be done to set the inexact flag when the
+ * result is inexact and avoid setting inexact when the result
+ * is exact. In this case, dtoa.c must be compiled in
+ * an environment, perhaps provided by #include "dtoa.c" in a
+ * suitable wrapper, that defines two functions,
+ * int get_inexact(void);
+ * void clear_inexact(void);
+ * such that get_inexact() returns a nonzero value if the
+ * inexact bit is already set, and clear_inexact() sets the
+ * inexact bit to 0. When SET_INEXACT is #defined, strtod
+ * also does extra computations to set the underflow and overflow
+ * flags when appropriate (i.e., when the result is tiny and
+ * inexact or when it is a numeric value rounded to +-infinity).
* #define NO_ERRNO if strtod should not assign errno = ERANGE when
- * the result overflows to +-Infinity or underflows to 0.
+ * the result overflows to +-Infinity or underflows to 0.
*/
#ifndef Long
@@ -337,7 +337,10 @@ extern "C" {
Exactly one of IEEE_8087, IEEE_MC68k, IEEE_ARM, VAX, or IBM should be defined.
#endif
-typedef union { double d; ULong L[2]; } U;
+typedef union {
+ double d;
+ ULong L[2];
+} U;
#define dval(x) (x).d
#ifdef IEEE_8087
@@ -393,7 +396,7 @@ typedef union { double d; ULong L[2]; } U;
#define Int_max 14
#ifndef NO_IEEE_Scale
#define Avoid_Underflow
-#ifdef Flush_Denorm /* debugging option */
+#ifdef Flush_Denorm /* debugging option */
#undef Sudden_Underflow
#endif
#endif
@@ -432,7 +435,7 @@ typedef union { double d; ULong L[2]; } U;
#define Bias 65
#define Exp_1 0x41000000
#define Exp_11 0x41000000
-#define Ebits 8 /* exponent has 7 bits, but 8 is the right value in b2d */
+#define Ebits 8 /* exponent has 7 bits, but 8 is the right value in b2d */
#define Frac_mask 0xffffff
#define Frac_mask1 0xffffff
#define Bletch 4
@@ -515,7 +518,7 @@ extern double rnd_prod(double, double), rnd_quot(double, double);
* slower. Hence the default is now to store 32 bits per Long.
*/
#endif
-#else /* long long available */
+#else /* long long available */
#ifndef Llong
#define Llong long long
#endif
@@ -525,969 +528,1006 @@ extern double rnd_prod(double, double), rnd_quot(double, double);
#endif /* NO_LONG_LONG */
#ifndef MULTIPLE_THREADS
-#define ACQUIRE_DTOA_LOCK(n) /*nothing*/
-#define FREE_DTOA_LOCK(n) /*nothing*/
+#define ACQUIRE_DTOA_LOCK(n) /*nothing*/
+#define FREE_DTOA_LOCK(n) /*nothing*/
#endif
#define Kmax 7
- struct
-Bigint {
- struct Bigint *next;
- int k, maxwds, sign, wds;
- ULong x[1];
- };
+struct
+ Bigint {
+ struct Bigint *next;
+ int k, maxwds, sign, wds;
+ ULong x[1];
+};
- typedef struct Bigint Bigint;
+typedef struct Bigint Bigint;
- static Bigint *freelist[Kmax+1];
+static Bigint *freelist[Kmax+1];
- static Bigint *
+static Bigint *
Balloc
#ifdef KR_headers
- (k) int k;
+(k) int k;
#else
- (int k)
+(int k)
#endif
{
- int x;
- Bigint *rv;
+ int x;
+ Bigint *rv;
#ifndef Omit_Private_Memory
- unsigned int len;
+ unsigned int len;
#endif
- ACQUIRE_DTOA_LOCK(0);
- /* The k > Kmax case does not need ACQUIRE_DTOA_LOCK(0), */
- /* but this case seems very unlikely. */
- if (k <= Kmax && (rv = freelist[k]))
- freelist[k] = rv->next;
- else {
- x = 1 << k;
+ ACQUIRE_DTOA_LOCK(0);
+ /* The k > Kmax case does not need ACQUIRE_DTOA_LOCK(0), */
+ /* but this case seems very unlikely. */
+ if (k <= Kmax && (rv = freelist[k])) {
+ freelist[k] = rv->next;
+ }
+ else {
+ x = 1 << k;
#ifdef Omit_Private_Memory
- rv = (Bigint *)MALLOC(sizeof(Bigint) + (x-1)*sizeof(ULong));
-#else
- len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1)
- /sizeof(double);
- if (k <= Kmax && pmem_next - private_mem + len <= PRIVATE_mem) {
- rv = (Bigint*)pmem_next;
- pmem_next += len;
- }
- else
- rv = (Bigint*)MALLOC(len*sizeof(double));
-#endif
- rv->k = k;
- rv->maxwds = x;
- }
- FREE_DTOA_LOCK(0);
- rv->sign = rv->wds = 0;
- return rv;
- }
-
- static void
+ rv = (Bigint *)MALLOC(sizeof(Bigint) + (x-1)*sizeof(ULong));
+#else
+ len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1)
+ /sizeof(double);
+ if (k <= Kmax && pmem_next - private_mem + len <= PRIVATE_mem) {
+ rv = (Bigint*)pmem_next;
+ pmem_next += len;
+ }
+ else {
+ rv = (Bigint*)MALLOC(len*sizeof(double));
+ }
+#endif
+ rv->k = k;
+ rv->maxwds = x;
+ }
+ FREE_DTOA_LOCK(0);
+ rv->sign = rv->wds = 0;
+ return rv;
+}
+
+static void
Bfree
#ifdef KR_headers
- (v) Bigint *v;
+(v) Bigint *v;
#else
- (Bigint *v)
+(Bigint *v)
#endif
{
- if (v) {
- if (v->k > Kmax)
+ if (v) {
+ if (v->k > Kmax)
#ifdef FREE
- FREE((void*)v);
+ FREE((void*)v);
#else
- free((void*)v);
+ free((void*)v);
#endif
- else {
- ACQUIRE_DTOA_LOCK(0);
- v->next = freelist[v->k];
- freelist[v->k] = v;
- FREE_DTOA_LOCK(0);
- }
- }
- }
+ else {
+ ACQUIRE_DTOA_LOCK(0);
+ v->next = freelist[v->k];
+ freelist[v->k] = v;
+ FREE_DTOA_LOCK(0);
+ }
+ }
+}
#define Bcopy(x,y) memcpy((char *)&x->sign, (char *)&y->sign, \
y->wds*sizeof(Long) + 2*sizeof(int))
- static Bigint *
+static Bigint *
multadd
#ifdef KR_headers
- (b, m, a) Bigint *b; int m, a;
+(b, m, a) Bigint *b; int m, a;
#else
- (Bigint *b, int m, int a) /* multiply by m and add a */
+(Bigint *b, int m, int a) /* multiply by m and add a */
#endif
{
- int i, wds;
+ int i, wds;
#ifdef ULLong
- ULong *x;
- ULLong carry, y;
+ ULong *x;
+ ULLong carry, y;
#else
- ULong carry, *x, y;
+ ULong carry, *x, y;
#ifdef Pack_32
- ULong xi, z;
+ ULong xi, z;
#endif
#endif
- Bigint *b1;
+ Bigint *b1;
- wds = b->wds;
- x = b->x;
- i = 0;
- carry = a;
- do {
+ wds = b->wds;
+ x = b->x;
+ i = 0;
+ carry = a;
+ do {
#ifdef ULLong
- y = *x * (ULLong)m + carry;
- carry = y >> 32;
- *x++ = y & FFFFFFFF;
+ y = *x * (ULLong)m + carry;
+ carry = y >> 32;
+ *x++ = y & FFFFFFFF;
#else
#ifdef Pack_32
- xi = *x;
- y = (xi & 0xffff) * m + carry;
- z = (xi >> 16) * m + (y >> 16);
- carry = z >> 16;
- *x++ = (z << 16) + (y & 0xffff);
-#else
- y = *x * m + carry;
- carry = y >> 16;
- *x++ = y & 0xffff;
-#endif
-#endif
- }
- while(++i < wds);
- if (carry) {
- if (wds >= b->maxwds) {
- b1 = Balloc(b->k+1);
- Bcopy(b1, b);
- Bfree(b);
- b = b1;
- }
- b->x[wds++] = carry;
- b->wds = wds;
- }
- return b;
- }
-
- static Bigint *
+ xi = *x;
+ y = (xi & 0xffff) * m + carry;
+ z = (xi >> 16) * m + (y >> 16);
+ carry = z >> 16;
+ *x++ = (z << 16) + (y & 0xffff);
+#else
+ y = *x * m + carry;
+ carry = y >> 16;
+ *x++ = y & 0xffff;
+#endif
+#endif
+ }
+ while(++i < wds);
+ if (carry) {
+ if (wds >= b->maxwds) {
+ b1 = Balloc(b->k+1);
+ Bcopy(b1, b);
+ Bfree(b);
+ b = b1;
+ }
+ b->x[wds++] = carry;
+ b->wds = wds;
+ }
+ return b;
+}
+
+static Bigint *
s2b
#ifdef KR_headers
- (s, nd0, nd, y9) CONST char *s; int nd0, nd; ULong y9;
+(s, nd0, nd, y9) CONST char *s; int nd0, nd; ULong y9;
#else
- (CONST char *s, int nd0, int nd, ULong y9)
+(CONST char *s, int nd0, int nd, ULong y9)
#endif
{
- Bigint *b;
- int i, k;
- Long x, y;
+ Bigint *b;
+ int i, k;
+ Long x, y;
- x = (nd + 8) / 9;
- for(k = 0, y = 1; x > y; y <<= 1, k++) ;
+ x = (nd + 8) / 9;
+ for(k = 0, y = 1; x > y; y <<= 1, k++) ;
#ifdef Pack_32
- b = Balloc(k);
- b->x[0] = y9;
- b->wds = 1;
-#else
- b = Balloc(k+1);
- b->x[0] = y9 & 0xffff;
- b->wds = (b->x[1] = y9 >> 16) ? 2 : 1;
-#endif
-
- i = 9;
- if (9 < nd0) {
- s += 9;
- do b = multadd(b, 10, *s++ - '0');
- while(++i < nd0);
- s++;
- }
- else
- s += 10;
- for(; i < nd; i++)
- b = multadd(b, 10, *s++ - '0');
- return b;
- }
-
- static int
+ b = Balloc(k);
+ b->x[0] = y9;
+ b->wds = 1;
+#else
+ b = Balloc(k+1);
+ b->x[0] = y9 & 0xffff;
+ b->wds = (b->x[1] = y9 >> 16) ? 2 : 1;
+#endif
+
+ i = 9;
+ if (9 < nd0) {
+ s += 9;
+ do {
+ b = multadd(b, 10, *s++ - '0');
+ }
+ while(++i < nd0);
+ s++;
+ }
+ else {
+ s += 10;
+ }
+ for(; i < nd; i++) {
+ b = multadd(b, 10, *s++ - '0');
+ }
+ return b;
+}
+
+static int
hi0bits
#ifdef KR_headers
- (x) register ULong x;
+(x) register ULong x;
#else
- (register ULong x)
+(register ULong x)
#endif
{
#ifdef PR_HAVE_BUILTIN_BITSCAN32
- return( (!x) ? 32 : pr_bitscan_clz32(x) );
-#else
- register int k = 0;
-
- if (!(x & 0xffff0000)) {
- k = 16;
- x <<= 16;
- }
- if (!(x & 0xff000000)) {
- k += 8;
- x <<= 8;
- }
- if (!(x & 0xf0000000)) {
- k += 4;
- x <<= 4;
- }
- if (!(x & 0xc0000000)) {
- k += 2;
- x <<= 2;
- }
- if (!(x & 0x80000000)) {
- k++;
- if (!(x & 0x40000000))
- return 32;
- }
- return k;
+ return( (!x) ? 32 : pr_bitscan_clz32(x) );
+#else
+ register int k = 0;
+
+ if (!(x & 0xffff0000)) {
+ k = 16;
+ x <<= 16;
+ }
+ if (!(x & 0xff000000)) {
+ k += 8;
+ x <<= 8;
+ }
+ if (!(x & 0xf0000000)) {
+ k += 4;
+ x <<= 4;
+ }
+ if (!(x & 0xc0000000)) {
+ k += 2;
+ x <<= 2;
+ }
+ if (!(x & 0x80000000)) {
+ k++;
+ if (!(x & 0x40000000)) {
+ return 32;
+ }
+ }
+ return k;
#endif /* PR_HAVE_BUILTIN_BITSCAN32 */
- }
+}
- static int
+static int
lo0bits
#ifdef KR_headers
- (y) ULong *y;
+(y) ULong *y;
#else
- (ULong *y)
+(ULong *y)
#endif
{
#ifdef PR_HAVE_BUILTIN_BITSCAN32
- int k;
- ULong x = *y;
-
- if (x>1)
- *y = ( x >> (k = pr_bitscan_ctz32(x)) );
- else
- k = ((x ^ 1) << 5);
-#else
- register int k;
- register ULong x = *y;
-
- if (x & 7) {
- if (x & 1)
- return 0;
- if (x & 2) {
- *y = x >> 1;
- return 1;
- }
- *y = x >> 2;
- return 2;
- }
- k = 0;
- if (!(x & 0xffff)) {
- k = 16;
- x >>= 16;
- }
- if (!(x & 0xff)) {
- k += 8;
- x >>= 8;
- }
- if (!(x & 0xf)) {
- k += 4;
- x >>= 4;
- }
- if (!(x & 0x3)) {
- k += 2;
- x >>= 2;
- }
- if (!(x & 1)) {
- k++;
- x >>= 1;
- if (!x)
- return 32;
- }
- *y = x;
+ int k;
+ ULong x = *y;
+
+ if (x>1) {
+ *y = ( x >> (k = pr_bitscan_ctz32(x)) );
+ }
+ else {
+ k = ((x ^ 1) << 5);
+ }
+#else
+ register int k;
+ register ULong x = *y;
+
+ if (x & 7) {
+ if (x & 1) {
+ return 0;
+ }
+ if (x & 2) {
+ *y = x >> 1;
+ return 1;
+ }
+ *y = x >> 2;
+ return 2;
+ }
+ k = 0;
+ if (!(x & 0xffff)) {
+ k = 16;
+ x >>= 16;
+ }
+ if (!(x & 0xff)) {
+ k += 8;
+ x >>= 8;
+ }
+ if (!(x & 0xf)) {
+ k += 4;
+ x >>= 4;
+ }
+ if (!(x & 0x3)) {
+ k += 2;
+ x >>= 2;
+ }
+ if (!(x & 1)) {
+ k++;
+ x >>= 1;
+ if (!x) {
+ return 32;
+ }
+ }
+ *y = x;
#endif /* PR_HAVE_BUILTIN_BITSCAN32 */
- return k;
- }
+ return k;
+}
- static Bigint *
+static Bigint *
i2b
#ifdef KR_headers
- (i) int i;
+(i) int i;
#else
- (int i)
+(int i)
#endif
{
- Bigint *b;
+ Bigint *b;
- b = Balloc(1);
- b->x[0] = i;
- b->wds = 1;
- return b;
- }
+ b = Balloc(1);
+ b->x[0] = i;
+ b->wds = 1;
+ return b;
+}
- static Bigint *
+static Bigint *
mult
#ifdef KR_headers
- (a, b) Bigint *a, *b;
+(a, b) Bigint *a, *b;
#else
- (Bigint *a, Bigint *b)
+(Bigint *a, Bigint *b)
#endif
{
- Bigint *c;
- int k, wa, wb, wc;
- ULong *x, *xa, *xae, *xb, *xbe, *xc, *xc0;
- ULong y;
+ Bigint *c;
+ int k, wa, wb, wc;
+ ULong *x, *xa, *xae, *xb, *xbe, *xc, *xc0;
+ ULong y;
#ifdef ULLong
- ULLong carry, z;
+ ULLong carry, z;
#else
- ULong carry, z;
+ ULong carry, z;
#ifdef Pack_32
- ULong z2;
-#endif
-#endif
-
- if (a->wds < b->wds) {
- c = a;
- a = b;
- b = c;
- }
- k = a->k;
- wa = a->wds;
- wb = b->wds;
- wc = wa + wb;
- if (wc > a->maxwds)
- k++;
- c = Balloc(k);
- for(x = c->x, xa = x + wc; x < xa; x++)
- *x = 0;
- xa = a->x;
- xae = xa + wa;
- xb = b->x;
- xbe = xb + wb;
- xc0 = c->x;
+ ULong z2;
+#endif
+#endif
+
+ if (a->wds < b->wds) {
+ c = a;
+ a = b;
+ b = c;
+ }
+ k = a->k;
+ wa = a->wds;
+ wb = b->wds;
+ wc = wa + wb;
+ if (wc > a->maxwds) {
+ k++;
+ }
+ c = Balloc(k);
+ for(x = c->x, xa = x + wc; x < xa; x++) {
+ *x = 0;
+ }
+ xa = a->x;
+ xae = xa + wa;
+ xb = b->x;
+ xbe = xb + wb;
+ xc0 = c->x;
#ifdef ULLong
- for(; xb < xbe; xc0++) {
- if (y = *xb++) {
- x = xa;
- xc = xc0;
- carry = 0;
- do {
- z = *x++ * (ULLong)y + *xc + carry;
- carry = z >> 32;
- *xc++ = z & FFFFFFFF;
- }
- while(x < xae);
- *xc = carry;
- }
- }
+ for(; xb < xbe; xc0++) {
+ if (y = *xb++) {
+ x = xa;
+ xc = xc0;
+ carry = 0;
+ do {
+ z = *x++ * (ULLong)y + *xc + carry;
+ carry = z >> 32;
+ *xc++ = z & FFFFFFFF;
+ }
+ while(x < xae);
+ *xc = carry;
+ }
+ }
#else
#ifdef Pack_32
- for(; xb < xbe; xb++, xc0++) {
- if (y = *xb & 0xffff) {
- x = xa;
- xc = xc0;
- carry = 0;
- do {
- z = (*x & 0xffff) * y + (*xc & 0xffff) + carry;
- carry = z >> 16;
- z2 = (*x++ >> 16) * y + (*xc >> 16) + carry;
- carry = z2 >> 16;
- Storeinc(xc, z2, z);
- }
- while(x < xae);
- *xc = carry;
- }
- if (y = *xb >> 16) {
- x = xa;
- xc = xc0;
- carry = 0;
- z2 = *xc;
- do {
- z = (*x & 0xffff) * y + (*xc >> 16) + carry;
- carry = z >> 16;
- Storeinc(xc, z, z2);
- z2 = (*x++ >> 16) * y + (*xc & 0xffff) + carry;
- carry = z2 >> 16;
- }
- while(x < xae);
- *xc = z2;
- }
- }
-#else
- for(; xb < xbe; xc0++) {
- if (y = *xb++) {
- x = xa;
- xc = xc0;
- carry = 0;
- do {
- z = *x++ * y + *xc + carry;
- carry = z >> 16;
- *xc++ = z & 0xffff;
- }
- while(x < xae);
- *xc = carry;
- }
- }
-#endif
-#endif
- for(xc0 = c->x, xc = xc0 + wc; wc > 0 && !*--xc; --wc) ;
- c->wds = wc;
- return c;
- }
-
- static Bigint *p5s;
-
- static Bigint *
+ for(; xb < xbe; xb++, xc0++) {
+ if (y = *xb & 0xffff) {
+ x = xa;
+ xc = xc0;
+ carry = 0;
+ do {
+ z = (*x & 0xffff) * y + (*xc & 0xffff) + carry;
+ carry = z >> 16;
+ z2 = (*x++ >> 16) * y + (*xc >> 16) + carry;
+ carry = z2 >> 16;
+ Storeinc(xc, z2, z);
+ }
+ while(x < xae);
+ *xc = carry;
+ }
+ if (y = *xb >> 16) {
+ x = xa;
+ xc = xc0;
+ carry = 0;
+ z2 = *xc;
+ do {
+ z = (*x & 0xffff) * y + (*xc >> 16) + carry;
+ carry = z >> 16;
+ Storeinc(xc, z, z2);
+ z2 = (*x++ >> 16) * y + (*xc & 0xffff) + carry;
+ carry = z2 >> 16;
+ }
+ while(x < xae);
+ *xc = z2;
+ }
+ }
+#else
+ for(; xb < xbe; xc0++) {
+ if (y = *xb++) {
+ x = xa;
+ xc = xc0;
+ carry = 0;
+ do {
+ z = *x++ * y + *xc + carry;
+ carry = z >> 16;
+ *xc++ = z & 0xffff;
+ }
+ while(x < xae);
+ *xc = carry;
+ }
+ }
+#endif
+#endif
+ for(xc0 = c->x, xc = xc0 + wc; wc > 0 && !*--xc; --wc) ;
+ c->wds = wc;
+ return c;
+}
+
+static Bigint *p5s;
+
+static Bigint *
pow5mult
#ifdef KR_headers
- (b, k) Bigint *b; int k;
+(b, k) Bigint *b; int k;
#else
- (Bigint *b, int k)
+(Bigint *b, int k)
#endif
{
- Bigint *b1, *p5, *p51;
- int i;
- static int p05[3] = { 5, 25, 125 };
+ Bigint *b1, *p5, *p51;
+ int i;
+ static int p05[3] = { 5, 25, 125 };
- if (i = k & 3)
- b = multadd(b, p05[i-1], 0);
+ if (i = k & 3) {
+ b = multadd(b, p05[i-1], 0);
+ }
- if (!(k >>= 2))
- return b;
- if (!(p5 = p5s)) {
- /* first time */
+ if (!(k >>= 2)) {
+ return b;
+ }
+ if (!(p5 = p5s)) {
+ /* first time */
#ifdef MULTIPLE_THREADS
- ACQUIRE_DTOA_LOCK(1);
- if (!(p5 = p5s)) {
- p5 = p5s = i2b(625);
- p5->next = 0;
- }
- FREE_DTOA_LOCK(1);
-#else
- p5 = p5s = i2b(625);
- p5->next = 0;
-#endif
- }
- for(;;) {
- if (k & 1) {
- b1 = mult(b, p5);
- Bfree(b);
- b = b1;
- }
- if (!(k >>= 1))
- break;
- if (!(p51 = p5->next)) {
+ ACQUIRE_DTOA_LOCK(1);
+ if (!(p5 = p5s)) {
+ p5 = p5s = i2b(625);
+ p5->next = 0;
+ }
+ FREE_DTOA_LOCK(1);
+#else
+ p5 = p5s = i2b(625);
+ p5->next = 0;
+#endif
+ }
+ for(;;) {
+ if (k & 1) {
+ b1 = mult(b, p5);
+ Bfree(b);
+ b = b1;
+ }
+ if (!(k >>= 1)) {
+ break;
+ }
+ if (!(p51 = p5->next)) {
#ifdef MULTIPLE_THREADS
- ACQUIRE_DTOA_LOCK(1);
- if (!(p51 = p5->next)) {
- p51 = p5->next = mult(p5,p5);
- p51->next = 0;
- }
- FREE_DTOA_LOCK(1);
-#else
- p51 = p5->next = mult(p5,p5);
- p51->next = 0;
-#endif
- }
- p5 = p51;
- }
- return b;
- }
-
- static Bigint *
+ ACQUIRE_DTOA_LOCK(1);
+ if (!(p51 = p5->next)) {
+ p51 = p5->next = mult(p5,p5);
+ p51->next = 0;
+ }
+ FREE_DTOA_LOCK(1);
+#else
+ p51 = p5->next = mult(p5,p5);
+ p51->next = 0;
+#endif
+ }
+ p5 = p51;
+ }
+ return b;
+}
+
+static Bigint *
lshift
#ifdef KR_headers
- (b, k) Bigint *b; int k;
+(b, k) Bigint *b; int k;
#else
- (Bigint *b, int k)
+(Bigint *b, int k)
#endif
{
- int i, k1, n, n1;
- Bigint *b1;
- ULong *x, *x1, *xe, z;
+ int i, k1, n, n1;
+ Bigint *b1;
+ ULong *x, *x1, *xe, z;
#ifdef Pack_32
- n = k >> 5;
-#else
- n = k >> 4;
-#endif
- k1 = b->k;
- n1 = n + b->wds + 1;
- for(i = b->maxwds; n1 > i; i <<= 1)
- k1++;
- b1 = Balloc(k1);
- x1 = b1->x;
- for(i = 0; i < n; i++)
- *x1++ = 0;
- x = b->x;
- xe = x + b->wds;
+ n = k >> 5;
+#else
+ n = k >> 4;
+#endif
+ k1 = b->k;
+ n1 = n + b->wds + 1;
+ for(i = b->maxwds; n1 > i; i <<= 1) {
+ k1++;
+ }
+ b1 = Balloc(k1);
+ x1 = b1->x;
+ for(i = 0; i < n; i++) {
+ *x1++ = 0;
+ }
+ x = b->x;
+ xe = x + b->wds;
#ifdef Pack_32
- if (k &= 0x1f) {
- k1 = 32 - k;
- z = 0;
- do {
- *x1++ = *x << k | z;
- z = *x++ >> k1;
- }
- while(x < xe);
- if (*x1 = z)
- ++n1;
- }
-#else
- if (k &= 0xf) {
- k1 = 16 - k;
- z = 0;
- do {
- *x1++ = *x << k & 0xffff | z;
- z = *x++ >> k1;
- }
- while(x < xe);
- if (*x1 = z)
- ++n1;
- }
-#endif
- else do
- *x1++ = *x++;
- while(x < xe);
- b1->wds = n1 - 1;
- Bfree(b);
- return b1;
- }
-
- static int
+ if (k &= 0x1f) {
+ k1 = 32 - k;
+ z = 0;
+ do {
+ *x1++ = *x << k | z;
+ z = *x++ >> k1;
+ }
+ while(x < xe);
+ if (*x1 = z) {
+ ++n1;
+ }
+ }
+#else
+ if (k &= 0xf) {
+ k1 = 16 - k;
+ z = 0;
+ do {
+ *x1++ = *x << k & 0xffff | z;
+ z = *x++ >> k1;
+ }
+ while(x < xe);
+ if (*x1 = z) {
+ ++n1;
+ }
+ }
+#endif
+ else do {
+ *x1++ = *x++;
+ }
+ while(x < xe);
+ b1->wds = n1 - 1;
+ Bfree(b);
+ return b1;
+}
+
+static int
cmp
#ifdef KR_headers
- (a, b) Bigint *a, *b;
+(a, b) Bigint *a, *b;
#else
- (Bigint *a, Bigint *b)
+(Bigint *a, Bigint *b)
#endif
{
- ULong *xa, *xa0, *xb, *xb0;
- int i, j;
+ ULong *xa, *xa0, *xb, *xb0;
+ int i, j;
- i = a->wds;
- j = b->wds;
+ i = a->wds;
+ j = b->wds;
#ifdef DEBUG
- if (i > 1 && !a->x[i-1])
- Bug("cmp called with a->x[a->wds-1] == 0");
- if (j > 1 && !b->x[j-1])
- Bug("cmp called with b->x[b->wds-1] == 0");
-#endif
- if (i -= j)
- return i;
- xa0 = a->x;
- xa = xa0 + j;
- xb0 = b->x;
- xb = xb0 + j;
- for(;;) {
- if (*--xa != *--xb)
- return *xa < *xb ? -1 : 1;
- if (xa <= xa0)
- break;
- }
- return 0;
- }
-
- static Bigint *
+ if (i > 1 && !a->x[i-1]) {
+ Bug("cmp called with a->x[a->wds-1] == 0");
+ }
+ if (j > 1 && !b->x[j-1]) {
+ Bug("cmp called with b->x[b->wds-1] == 0");
+ }
+#endif
+ if (i -= j) {
+ return i;
+ }
+ xa0 = a->x;
+ xa = xa0 + j;
+ xb0 = b->x;
+ xb = xb0 + j;
+ for(;;) {
+ if (*--xa != *--xb) {
+ return *xa < *xb ? -1 : 1;
+ }
+ if (xa <= xa0) {
+ break;
+ }
+ }
+ return 0;
+}
+
+static Bigint *
diff
#ifdef KR_headers
- (a, b) Bigint *a, *b;
+(a, b) Bigint *a, *b;
#else
- (Bigint *a, Bigint *b)
+(Bigint *a, Bigint *b)
#endif
{
- Bigint *c;
- int i, wa, wb;
- ULong *xa, *xae, *xb, *xbe, *xc;
+ Bigint *c;
+ int i, wa, wb;
+ ULong *xa, *xae, *xb, *xbe, *xc;
#ifdef ULLong
- ULLong borrow, y;
+ ULLong borrow, y;
#else
- ULong borrow, y;
+ ULong borrow, y;
#ifdef Pack_32
- ULong z;
-#endif
-#endif
-
- i = cmp(a,b);
- if (!i) {
- c = Balloc(0);
- c->wds = 1;
- c->x[0] = 0;
- return c;
- }
- if (i < 0) {
- c = a;
- a = b;
- b = c;
- i = 1;
- }
- else
- i = 0;
- c = Balloc(a->k);
- c->sign = i;
- wa = a->wds;
- xa = a->x;
- xae = xa + wa;
- wb = b->wds;
- xb = b->x;
- xbe = xb + wb;
- xc = c->x;
- borrow = 0;
+ ULong z;
+#endif
+#endif
+
+ i = cmp(a,b);
+ if (!i) {
+ c = Balloc(0);
+ c->wds = 1;
+ c->x[0] = 0;
+ return c;
+ }
+ if (i < 0) {
+ c = a;
+ a = b;
+ b = c;
+ i = 1;
+ }
+ else {
+ i = 0;
+ }
+ c = Balloc(a->k);
+ c->sign = i;
+ wa = a->wds;
+ xa = a->x;
+ xae = xa + wa;
+ wb = b->wds;
+ xb = b->x;
+ xbe = xb + wb;
+ xc = c->x;
+ borrow = 0;
#ifdef ULLong
- do {
- y = (ULLong)*xa++ - *xb++ - borrow;
- borrow = y >> 32 & (ULong)1;
- *xc++ = y & FFFFFFFF;
- }
- while(xb < xbe);
- while(xa < xae) {
- y = *xa++ - borrow;
- borrow = y >> 32 & (ULong)1;
- *xc++ = y & FFFFFFFF;
- }
+ do {
+ y = (ULLong)*xa++ - *xb++ - borrow;
+ borrow = y >> 32 & (ULong)1;
+ *xc++ = y & FFFFFFFF;
+ }
+ while(xb < xbe);
+ while(xa < xae) {
+ y = *xa++ - borrow;
+ borrow = y >> 32 & (ULong)1;
+ *xc++ = y & FFFFFFFF;
+ }
#else
#ifdef Pack_32
- do {
- y = (*xa & 0xffff) - (*xb & 0xffff) - borrow;
- borrow = (y & 0x10000) >> 16;
- z = (*xa++ >> 16) - (*xb++ >> 16) - borrow;
- borrow = (z & 0x10000) >> 16;
- Storeinc(xc, z, y);
- }
- while(xb < xbe);
- while(xa < xae) {
- y = (*xa & 0xffff) - borrow;
- borrow = (y & 0x10000) >> 16;
- z = (*xa++ >> 16) - borrow;
- borrow = (z & 0x10000) >> 16;
- Storeinc(xc, z, y);
- }
-#else
- do {
- y = *xa++ - *xb++ - borrow;
- borrow = (y & 0x10000) >> 16;
- *xc++ = y & 0xffff;
- }
- while(xb < xbe);
- while(xa < xae) {
- y = *xa++ - borrow;
- borrow = (y & 0x10000) >> 16;
- *xc++ = y & 0xffff;
- }
-#endif
-#endif
- while(!*--xc)
- wa--;
- c->wds = wa;
- return c;
- }
-
- static double
+ do {
+ y = (*xa & 0xffff) - (*xb & 0xffff) - borrow;
+ borrow = (y & 0x10000) >> 16;
+ z = (*xa++ >> 16) - (*xb++ >> 16) - borrow;
+ borrow = (z & 0x10000) >> 16;
+ Storeinc(xc, z, y);
+ }
+ while(xb < xbe);
+ while(xa < xae) {
+ y = (*xa & 0xffff) - borrow;
+ borrow = (y & 0x10000) >> 16;
+ z = (*xa++ >> 16) - borrow;
+ borrow = (z & 0x10000) >> 16;
+ Storeinc(xc, z, y);
+ }
+#else
+ do {
+ y = *xa++ - *xb++ - borrow;
+ borrow = (y & 0x10000) >> 16;
+ *xc++ = y & 0xffff;
+ }
+ while(xb < xbe);
+ while(xa < xae) {
+ y = *xa++ - borrow;
+ borrow = (y & 0x10000) >> 16;
+ *xc++ = y & 0xffff;
+ }
+#endif
+#endif
+ while(!*--xc) {
+ wa--;
+ }
+ c->wds = wa;
+ return c;
+}
+
+static double
ulp
#ifdef KR_headers
- (dx) double dx;
+(dx) double dx;
#else
- (double dx)
+(double dx)
#endif
{
- register Long L;
- U x, a;
+ register Long L;
+ U x, a;
- dval(x) = dx;
- L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1;
+ dval(x) = dx;
+ L = (word0(x) & Exp_mask) - (P-1)*Exp_msk1;
#ifndef Avoid_Underflow
#ifndef Sudden_Underflow
- if (L > 0) {
+ if (L > 0) {
#endif
#endif
#ifdef IBM
- L |= Exp_msk1 >> 4;
+ L |= Exp_msk1 >> 4;
#endif
- word0(a) = L;
- word1(a) = 0;
+ word0(a) = L;
+ word1(a) = 0;
#ifndef Avoid_Underflow
#ifndef Sudden_Underflow
- }
- else {
- L = -L >> Exp_shift;
- if (L < Exp_shift) {
- word0(a) = 0x80000 >> L;
- word1(a) = 0;
- }
- else {
- word0(a) = 0;
- L -= Exp_shift;
- word1(a) = L >= 31 ? 1 : 1 << 31 - L;
- }
- }
-#endif
-#endif
- return dval(a);
- }
-
- static double
+ }
+ else {
+ L = -L >> Exp_shift;
+ if (L < Exp_shift) {
+ word0(a) = 0x80000 >> L;
+ word1(a) = 0;
+ }
+ else {
+ word0(a) = 0;
+ L -= Exp_shift;
+ word1(a) = L >= 31 ? 1 : 1 << 31 - L;
+ }
+ }
+#endif
+#endif
+ return dval(a);
+}
+
+static double
b2d
#ifdef KR_headers
- (a, e) Bigint *a; int *e;
+(a, e) Bigint *a; int *e;
#else
- (Bigint *a, int *e)
+(Bigint *a, int *e)
#endif
{
- ULong *xa, *xa0, w, y, z;
- int k;
- U d;
+ ULong *xa, *xa0, w, y, z;
+ int k;
+ U d;
#ifdef VAX
- ULong d0, d1;
+ ULong d0, d1;
#else
#define d0 word0(d)
#define d1 word1(d)
#endif
- xa0 = a->x;
- xa = xa0 + a->wds;
- y = *--xa;
+ xa0 = a->x;
+ xa = xa0 + a->wds;
+ y = *--xa;
#ifdef DEBUG
- if (!y) Bug("zero y in b2d");
+ if (!y) {
+ Bug("zero y in b2d");
+ }
#endif
- k = hi0bits(y);
- *e = 32 - k;
+ k = hi0bits(y);
+ *e = 32 - k;
#ifdef Pack_32
- if (k < Ebits) {
- d0 = Exp_1 | y >> Ebits - k;
- w = xa > xa0 ? *--xa : 0;
- d1 = y << (32-Ebits) + k | w >> Ebits - k;
- goto ret_d;
- }
- z = xa > xa0 ? *--xa : 0;
- if (k -= Ebits) {
- d0 = Exp_1 | y << k | z >> 32 - k;
- y = xa > xa0 ? *--xa : 0;
- d1 = z << k | y >> 32 - k;
- }
- else {
- d0 = Exp_1 | y;
- d1 = z;
- }
-#else
- if (k < Ebits + 16) {
- z = xa > xa0 ? *--xa : 0;
- d0 = Exp_1 | y << k - Ebits | z >> Ebits + 16 - k;
- w = xa > xa0 ? *--xa : 0;
- y = xa > xa0 ? *--xa : 0;
- d1 = z << k + 16 - Ebits | w << k - Ebits | y >> 16 + Ebits - k;
- goto ret_d;
- }
- z = xa > xa0 ? *--xa : 0;
- w = xa > xa0 ? *--xa : 0;
- k -= Ebits + 16;
- d0 = Exp_1 | y << k + 16 | z << k | w >> 16 - k;
- y = xa > xa0 ? *--xa : 0;
- d1 = w << k + 16 | y << k;
-#endif
- ret_d:
+ if (k < Ebits) {
+ d0 = Exp_1 | y >> Ebits - k;
+ w = xa > xa0 ? *--xa : 0;
+ d1 = y << (32-Ebits) + k | w >> Ebits - k;
+ goto ret_d;
+ }
+ z = xa > xa0 ? *--xa : 0;
+ if (k -= Ebits) {
+ d0 = Exp_1 | y << k | z >> 32 - k;
+ y = xa > xa0 ? *--xa : 0;
+ d1 = z << k | y >> 32 - k;
+ }
+ else {
+ d0 = Exp_1 | y;
+ d1 = z;
+ }
+#else
+ if (k < Ebits + 16) {
+ z = xa > xa0 ? *--xa : 0;
+ d0 = Exp_1 | y << k - Ebits | z >> Ebits + 16 - k;
+ w = xa > xa0 ? *--xa : 0;
+ y = xa > xa0 ? *--xa : 0;
+ d1 = z << k + 16 - Ebits | w << k - Ebits | y >> 16 + Ebits - k;
+ goto ret_d;
+ }
+ z = xa > xa0 ? *--xa : 0;
+ w = xa > xa0 ? *--xa : 0;
+ k -= Ebits + 16;
+ d0 = Exp_1 | y << k + 16 | z << k | w >> 16 - k;
+ y = xa > xa0 ? *--xa : 0;
+ d1 = w << k + 16 | y << k;
+#endif
+ret_d:
#ifdef VAX
- word0(d) = d0 >> 16 | d0 << 16;
- word1(d) = d1 >> 16 | d1 << 16;
+ word0(d) = d0 >> 16 | d0 << 16;
+ word1(d) = d1 >> 16 | d1 << 16;
#else
#undef d0
#undef d1
#endif
- return dval(d);
- }
+ return dval(d);
+}
- static Bigint *
+static Bigint *
d2b
#ifdef KR_headers
- (dd, e, bits) double dd; int *e, *bits;
+(dd, e, bits) double dd; int *e, *bits;
#else
- (double dd, int *e, int *bits)
+(double dd, int *e, int *bits)
#endif
{
- U d;
- Bigint *b;
- int de, k;
- ULong *x, y, z;
+ U d;
+ Bigint *b;
+ int de, k;
+ ULong *x, y, z;
#ifndef Sudden_Underflow
- int i;
+ int i;
#endif
#ifdef VAX
- ULong d0, d1;
+ ULong d0, d1;
#endif
- dval(d) = dd;
+ dval(d) = dd;
#ifdef VAX
- d0 = word0(d) >> 16 | word0(d) << 16;
- d1 = word1(d) >> 16 | word1(d) << 16;
+ d0 = word0(d) >> 16 | word0(d) << 16;
+ d1 = word1(d) >> 16 | word1(d) << 16;
#else
#define d0 word0(d)
#define d1 word1(d)
#endif
#ifdef Pack_32
- b = Balloc(1);
+ b = Balloc(1);
#else
- b = Balloc(2);
+ b = Balloc(2);
#endif
- x = b->x;
+ x = b->x;
- z = d0 & Frac_mask;
- d0 &= 0x7fffffff; /* clear sign bit, which we ignore */
+ z = d0 & Frac_mask;
+ d0 &= 0x7fffffff; /* clear sign bit, which we ignore */
#ifdef Sudden_Underflow
- de = (int)(d0 >> Exp_shift);
+ de = (int)(d0 >> Exp_shift);
#ifndef IBM
- z |= Exp_msk11;
+ z |= Exp_msk11;
#endif
#else
- if (de = (int)(d0 >> Exp_shift))
- z |= Exp_msk1;
+ if (de = (int)(d0 >> Exp_shift)) {
+ z |= Exp_msk1;
+ }
#endif
#ifdef Pack_32
- if (y = d1) {
- if (k = lo0bits(&y)) {
- x[0] = y | z << 32 - k;
- z >>= k;
- }
- else
- x[0] = y;
+ if (y = d1) {
+ if (k = lo0bits(&y)) {
+ x[0] = y | z << 32 - k;
+ z >>= k;
+ }
+ else {
+ x[0] = y;
+ }
#ifndef Sudden_Underflow
- i =
+ i =
#endif
- b->wds = (x[1] = z) ? 2 : 1;
- }
- else {
- k = lo0bits(&z);
- x[0] = z;
+ b->wds = (x[1] = z) ? 2 : 1;
+ }
+ else {
+ k = lo0bits(&z);
+ x[0] = z;
#ifndef Sudden_Underflow
- i =
-#endif
- b->wds = 1;
- k += 32;
- }
-#else
- if (y = d1) {
- if (k = lo0bits(&y))
- if (k >= 16) {
- x[0] = y | z << 32 - k & 0xffff;
- x[1] = z >> k - 16 & 0xffff;
- x[2] = z >> k;
- i = 2;
- }
- else {
- x[0] = y & 0xffff;
- x[1] = y >> 16 | z << 16 - k & 0xffff;
- x[2] = z >> k & 0xffff;
- x[3] = z >> k+16;
- i = 3;
- }
- else {
- x[0] = y & 0xffff;
- x[1] = y >> 16;
- x[2] = z & 0xffff;
- x[3] = z >> 16;
- i = 3;
- }
- }
- else {
+ i =
+#endif
+ b->wds = 1;
+ k += 32;
+ }
+#else
+ if (y = d1) {
+ if (k = lo0bits(&y))
+ if (k >= 16) {
+ x[0] = y | z << 32 - k & 0xffff;
+ x[1] = z >> k - 16 & 0xffff;
+ x[2] = z >> k;
+ i = 2;
+ }
+ else {
+ x[0] = y & 0xffff;
+ x[1] = y >> 16 | z << 16 - k & 0xffff;
+ x[2] = z >> k & 0xffff;
+ x[3] = z >> k+16;
+ i = 3;
+ }
+ else {
+ x[0] = y & 0xffff;
+ x[1] = y >> 16;
+ x[2] = z & 0xffff;
+ x[3] = z >> 16;
+ i = 3;
+ }
+ }
+ else {
#ifdef DEBUG
- if (!z)
- Bug("Zero passed to d2b");
-#endif
- k = lo0bits(&z);
- if (k >= 16) {
- x[0] = z;
- i = 0;
- }
- else {
- x[0] = z & 0xffff;
- x[1] = z >> 16;
- i = 1;
- }
- k += 32;
- }
- while(!x[i])
- --i;
- b->wds = i + 1;
+ if (!z) {
+ Bug("Zero passed to d2b");
+ }
+#endif
+ k = lo0bits(&z);
+ if (k >= 16) {
+ x[0] = z;
+ i = 0;
+ }
+ else {
+ x[0] = z & 0xffff;
+ x[1] = z >> 16;
+ i = 1;
+ }
+ k += 32;
+ }
+ while(!x[i]) {
+ --i;
+ }
+ b->wds = i + 1;
#endif
#ifndef Sudden_Underflow
- if (de) {
+ if (de) {
#endif
#ifdef IBM
- *e = (de - Bias - (P-1) << 2) + k;
- *bits = 4*P + 8 - k - hi0bits(word0(d) & Frac_mask);
+ *e = (de - Bias - (P-1) << 2) + k;
+ *bits = 4*P + 8 - k - hi0bits(word0(d) & Frac_mask);
#else
- *e = de - Bias - (P-1) + k;
- *bits = P - k;
+ *e = de - Bias - (P-1) + k;
+ *bits = P - k;
#endif
#ifndef Sudden_Underflow
- }
- else {
- *e = de - Bias - (P-1) + 1 + k;
+ }
+ else {
+ *e = de - Bias - (P-1) + 1 + k;
#ifdef Pack_32
- *bits = 32*i - hi0bits(x[i-1]);
+ *bits = 32*i - hi0bits(x[i-1]);
#else
- *bits = (i+2)*16 - hi0bits(x[i]);
+ *bits = (i+2)*16 - hi0bits(x[i]);
#endif
- }
+ }
#endif
- return b;
- }
+ return b;
+}
#undef d0
#undef d1
- static double
+static double
ratio
#ifdef KR_headers
- (a, b) Bigint *a, *b;
+(a, b) Bigint *a, *b;
#else
- (Bigint *a, Bigint *b)
+(Bigint *a, Bigint *b)
#endif
{
- U da, db;
- int k, ka, kb;
+ U da, db;
+ int k, ka, kb;
- dval(da) = b2d(a, &ka);
- dval(db) = b2d(b, &kb);
+ dval(da) = b2d(a, &ka);
+ dval(db) = b2d(b, &kb);
#ifdef Pack_32
- k = ka - kb + 32*(a->wds - b->wds);
+ k = ka - kb + 32*(a->wds - b->wds);
#else
- k = ka - kb + 16*(a->wds - b->wds);
+ k = ka - kb + 16*(a->wds - b->wds);
#endif
#ifdef IBM
- if (k > 0) {
- word0(da) += (k >> 2)*Exp_msk1;
- if (k &= 3)
- dval(da) *= 1 << k;
- }
- else {
- k = -k;
- word0(db) += (k >> 2)*Exp_msk1;
- if (k &= 3)
- dval(db) *= 1 << k;
- }
-#else
- if (k > 0)
- word0(da) += k*Exp_msk1;
- else {
- k = -k;
- word0(db) += k*Exp_msk1;
- }
-#endif
- return dval(da) / dval(db);
- }
-
- static CONST double
+ if (k > 0) {
+ word0(da) += (k >> 2)*Exp_msk1;
+ if (k &= 3) {
+ dval(da) *= 1 << k;
+ }
+ }
+ else {
+ k = -k;
+ word0(db) += (k >> 2)*Exp_msk1;
+ if (k &= 3) {
+ dval(db) *= 1 << k;
+ }
+ }
+#else
+ if (k > 0) {
+ word0(da) += k*Exp_msk1;
+ }
+ else {
+ k = -k;
+ word0(db) += k*Exp_msk1;
+ }
+#endif
+ return dval(da) / dval(db);
+}
+
+static CONST double
tens[] = {
- 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,
- 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,
- 1e20, 1e21, 1e22
+ 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9,
+ 1e10, 1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19,
+ 1e20, 1e21, 1e22
#ifdef VAX
- , 1e23, 1e24
+ , 1e23, 1e24
#endif
- };
+};
- static CONST double
+static CONST double
#ifdef IEEE_Arith
bigtens[] = { 1e16, 1e32, 1e64, 1e128, 1e256 };
static CONST double tinytens[] = { 1e-16, 1e-32, 1e-64, 1e-128,
#ifdef Avoid_Underflow
- 9007199254740992.*9007199254740992.e-256
- /* = 2^106 * 1e-53 */
+ 9007199254740992.*9007199254740992.e-256
+ /* = 2^106 * 1e-53 */
#else
- 1e-256
+ 1e-256
#endif
- };
+ };
/* The factor of 2^53 in tinytens[4] helps us avoid setting the underflow */
/* flag unnecessarily. It leads to a song and dance at the end of strtod. */
#define Scale_Bit 0x10
@@ -1518,1139 +1558,1243 @@ static CONST double tinytens[] = { 1e-16, 1e-32 };
#define NAN_WORD1 0
#endif
- static int
+static int
match
#ifdef KR_headers
- (sp, t) char **sp, *t;
+(sp, t) char **sp, *t;
#else
- (CONST char **sp, char *t)
+(CONST char **sp, char *t)
#endif
{
- int c, d;
- CONST char *s = *sp;
-
- while(d = *t++) {
- if ((c = *++s) >= 'A' && c <= 'Z')
- c += 'a' - 'A';
- if (c != d)
- return 0;
- }
- *sp = s + 1;
- return 1;
- }
+ int c, d;
+ CONST char *s = *sp;
+
+ while(d = *t++) {
+ if ((c = *++s) >= 'A' && c <= 'Z') {
+ c += 'a' - 'A';
+ }
+ if (c != d) {
+ return 0;
+ }
+ }
+ *sp = s + 1;
+ return 1;
+}
#ifndef No_Hex_NaN
- static void
+static void
hexnan
#ifdef KR_headers
- (rvp, sp) double *rvp; CONST char **sp;
+(rvp, sp) double *rvp; CONST char **sp;
#else
- (double *rvp, CONST char **sp)
+(double *rvp, CONST char **sp)
#endif
{
- ULong c, x[2];
- CONST char *s;
- int havedig, udx0, xshift;
-
- x[0] = x[1] = 0;
- havedig = xshift = 0;
- udx0 = 1;
- s = *sp;
- while(c = *(CONST unsigned char*)++s) {
- if (c >= '0' && c <= '9')
- c -= '0';
- else if (c >= 'a' && c <= 'f')
- c += 10 - 'a';
- else if (c >= 'A' && c <= 'F')
- c += 10 - 'A';
- else if (c <= ' ') {
- if (udx0 && havedig) {
- udx0 = 0;
- xshift = 1;
- }
- continue;
- }
- else if (/*(*/ c == ')' && havedig) {
- *sp = s + 1;
- break;
- }
- else
- return; /* invalid form: don't change *sp */
- havedig = 1;
- if (xshift) {
- xshift = 0;
- x[0] = x[1];
- x[1] = 0;
- }
- if (udx0)
- x[0] = (x[0] << 4) | (x[1] >> 28);
- x[1] = (x[1] << 4) | c;
- }
- if ((x[0] &= 0xfffff) || x[1]) {
- word0(*rvp) = Exp_mask | x[0];
- word1(*rvp) = x[1];
- }
- }
+ ULong c, x[2];
+ CONST char *s;
+ int havedig, udx0, xshift;
+
+ x[0] = x[1] = 0;
+ havedig = xshift = 0;
+ udx0 = 1;
+ s = *sp;
+ while(c = *(CONST unsigned char*)++s) {
+ if (c >= '0' && c <= '9') {
+ c -= '0';
+ }
+ else if (c >= 'a' && c <= 'f') {
+ c += 10 - 'a';
+ }
+ else if (c >= 'A' && c <= 'F') {
+ c += 10 - 'A';
+ }
+ else if (c <= ' ') {
+ if (udx0 && havedig) {
+ udx0 = 0;
+ xshift = 1;
+ }
+ continue;
+ }
+ else if (/*(*/ c == ')' && havedig) {
+ *sp = s + 1;
+ break;
+ }
+ else {
+ return; /* invalid form: don't change *sp */
+ }
+ havedig = 1;
+ if (xshift) {
+ xshift = 0;
+ x[0] = x[1];
+ x[1] = 0;
+ }
+ if (udx0) {
+ x[0] = (x[0] << 4) | (x[1] >> 28);
+ }
+ x[1] = (x[1] << 4) | c;
+ }
+ if ((x[0] &= 0xfffff) || x[1]) {
+ word0(*rvp) = Exp_mask | x[0];
+ word1(*rvp) = x[1];
+ }
+}
#endif /*No_Hex_NaN*/
#endif /* INFNAN_CHECK */
- PR_IMPLEMENT(double)
+PR_IMPLEMENT(double)
PR_strtod
#ifdef KR_headers
- (s00, se) CONST char *s00; char **se;
+(s00, se) CONST char *s00; char **se;
#else
- (CONST char *s00, char **se)
+(CONST char *s00, char **se)
#endif
{
#ifdef Avoid_Underflow
- int scale;
-#endif
- int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign,
- e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign;
- CONST char *s, *s0, *s1;
- double aadj, aadj1, adj;
- U aadj2, rv, rv0;
- Long L;
- ULong y, z;
- Bigint *bb, *bb1, *bd, *bd0, *bs, *delta;
+ int scale;
+#endif
+ int bb2, bb5, bbe, bd2, bd5, bbbits, bs2, c, dsign,
+ e, e1, esign, i, j, k, nd, nd0, nf, nz, nz0, sign;
+ CONST char *s, *s0, *s1;
+ double aadj, aadj1, adj;
+ U aadj2, rv, rv0;
+ Long L;
+ ULong y, z;
+ Bigint *bb, *bb1, *bd, *bd0, *bs, *delta;
#ifdef SET_INEXACT
- int inexact, oldinexact;
+ int inexact, oldinexact;
#endif
#ifdef Honor_FLT_ROUNDS
- int rounding;
+ int rounding;
#endif
#ifdef USE_LOCALE
- CONST char *s2;
-#endif
-
- if (!_pr_initialized) _PR_ImplicitInitialization();
-
- sign = nz0 = nz = 0;
- dval(rv) = 0.;
- for(s = s00;;s++) switch(*s) {
- case '-':
- sign = 1;
- /* no break */
- case '+':
- if (*++s)
- goto break2;
- /* no break */
- case 0:
- goto ret0;
- case '\t':
- case '\n':
- case '\v':
- case '\f':
- case '\r':
- case ' ':
- continue;
- default:
- goto break2;
- }
- break2:
- if (*s == '0') {
- nz0 = 1;
- while(*++s == '0') ;
- if (!*s)
- goto ret;
- }
- s0 = s;
- y = z = 0;
- for(nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++)
- if (nd < 9)
- y = 10*y + c - '0';
- else if (nd < 16)
- z = 10*z + c - '0';
- nd0 = nd;
+ CONST char *s2;
+#endif
+
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
+
+ sign = nz0 = nz = 0;
+ dval(rv) = 0.;
+ for(s = s00;; s++) switch(*s) {
+ case '-':
+ sign = 1;
+ /* no break */
+ case '+':
+ if (*++s) {
+ goto break2;
+ }
+ /* no break */
+ case 0:
+ goto ret0;
+ case '\t':
+ case '\n':
+ case '\v':
+ case '\f':
+ case '\r':
+ case ' ':
+ continue;
+ default:
+ goto break2;
+ }
+break2:
+ if (*s == '0') {
+ nz0 = 1;
+ while(*++s == '0') ;
+ if (!*s) {
+ goto ret;
+ }
+ }
+ s0 = s;
+ y = z = 0;
+ for(nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++)
+ if (nd < 9) {
+ y = 10*y + c - '0';
+ }
+ else if (nd < 16) {
+ z = 10*z + c - '0';
+ }
+ nd0 = nd;
#ifdef USE_LOCALE
- s1 = localeconv()->decimal_point;
- if (c == *s1) {
- c = '.';
- if (*++s1) {
- s2 = s;
- for(;;) {
- if (*++s2 != *s1) {
- c = 0;
- break;
- }
- if (!*++s1) {
- s = s2;
- break;
- }
- }
- }
- }
-#endif
- if (c == '.') {
- c = *++s;
- if (!nd) {
- for(; c == '0'; c = *++s)
- nz++;
- if (c > '0' && c <= '9') {
- s0 = s;
- nf += nz;
- nz = 0;
- goto have_dig;
- }
- goto dig_done;
- }
- for(; c >= '0' && c <= '9'; c = *++s) {
- have_dig:
- nz++;
- if (c -= '0') {
- nf += nz;
- for(i = 1; i < nz; i++)
- if (nd++ < 9)
- y *= 10;
- else if (nd <= DBL_DIG + 1)
- z *= 10;
- if (nd++ < 9)
- y = 10*y + c;
- else if (nd <= DBL_DIG + 1)
- z = 10*z + c;
- nz = 0;
- }
- }
- }
- dig_done:
- if (nd > 64 * 1024)
- goto ret0;
- e = 0;
- if (c == 'e' || c == 'E') {
- if (!nd && !nz && !nz0) {
- goto ret0;
- }
- s00 = s;
- esign = 0;
- switch(c = *++s) {
- case '-':
- esign = 1;
- case '+':
- c = *++s;
- }
- if (c >= '0' && c <= '9') {
- while(c == '0')
- c = *++s;
- if (c > '0' && c <= '9') {
- L = c - '0';
- s1 = s;
- while((c = *++s) >= '0' && c <= '9')
- L = 10*L + c - '0';
- if (s - s1 > 8 || L > 19999)
- /* Avoid confusion from exponents
- * so large that e might overflow.
- */
- e = 19999; /* safe for 16 bit ints */
- else
- e = (int)L;
- if (esign)
- e = -e;
- }
- else
- e = 0;
- }
- else
- s = s00;
- }
- if (!nd) {
- if (!nz && !nz0) {
+ s1 = localeconv()->decimal_point;
+ if (c == *s1) {
+ c = '.';
+ if (*++s1) {
+ s2 = s;
+ for(;;) {
+ if (*++s2 != *s1) {
+ c = 0;
+ break;
+ }
+ if (!*++s1) {
+ s = s2;
+ break;
+ }
+ }
+ }
+ }
+#endif
+ if (c == '.') {
+ c = *++s;
+ if (!nd) {
+ for(; c == '0'; c = *++s) {
+ nz++;
+ }
+ if (c > '0' && c <= '9') {
+ s0 = s;
+ nf += nz;
+ nz = 0;
+ goto have_dig;
+ }
+ goto dig_done;
+ }
+ for(; c >= '0' && c <= '9'; c = *++s) {
+have_dig:
+ nz++;
+ if (c -= '0') {
+ nf += nz;
+ for(i = 1; i < nz; i++)
+ if (nd++ < 9) {
+ y *= 10;
+ }
+ else if (nd <= DBL_DIG + 1) {
+ z *= 10;
+ }
+ if (nd++ < 9) {
+ y = 10*y + c;
+ }
+ else if (nd <= DBL_DIG + 1) {
+ z = 10*z + c;
+ }
+ nz = 0;
+ }
+ }
+ }
+dig_done:
+ if (nd > 64 * 1024) {
+ goto ret0;
+ }
+ e = 0;
+ if (c == 'e' || c == 'E') {
+ if (!nd && !nz && !nz0) {
+ goto ret0;
+ }
+ s00 = s;
+ esign = 0;
+ switch(c = *++s) {
+ case '-':
+ esign = 1;
+ case '+':
+ c = *++s;
+ }
+ if (c >= '0' && c <= '9') {
+ while(c == '0') {
+ c = *++s;
+ }
+ if (c > '0' && c <= '9') {
+ L = c - '0';
+ s1 = s;
+ while((c = *++s) >= '0' && c <= '9') {
+ L = 10*L + c - '0';
+ }
+ if (s - s1 > 8 || L > 19999)
+ /* Avoid confusion from exponents
+ * so large that e might overflow.
+ */
+ {
+ e = 19999; /* safe for 16 bit ints */
+ }
+ else {
+ e = (int)L;
+ }
+ if (esign) {
+ e = -e;
+ }
+ }
+ else {
+ e = 0;
+ }
+ }
+ else {
+ s = s00;
+ }
+ }
+ if (!nd) {
+ if (!nz && !nz0) {
#ifdef INFNAN_CHECK
- /* Check for Nan and Infinity */
- switch(c) {
- case 'i':
- case 'I':
- if (match(&s,"nf")) {
- --s;
- if (!match(&s,"inity"))
- ++s;
- word0(rv) = 0x7ff00000;
- word1(rv) = 0;
- goto ret;
- }
- break;
- case 'n':
- case 'N':
- if (match(&s, "an")) {
- word0(rv) = NAN_WORD0;
- word1(rv) = NAN_WORD1;
+ /* Check for Nan and Infinity */
+ switch(c) {
+ case 'i':
+ case 'I':
+ if (match(&s,"nf")) {
+ --s;
+ if (!match(&s,"inity")) {
+ ++s;
+ }
+ word0(rv) = 0x7ff00000;
+ word1(rv) = 0;
+ goto ret;
+ }
+ break;
+ case 'n':
+ case 'N':
+ if (match(&s, "an")) {
+ word0(rv) = NAN_WORD0;
+ word1(rv) = NAN_WORD1;
#ifndef No_Hex_NaN
- if (*s == '(') /*)*/
- hexnan(&rv, &s);
+ if (*s == '(') { /*)*/
+ hexnan(&rv, &s);
+ }
#endif
- goto ret;
- }
- }
+ goto ret;
+ }
+ }
#endif /* INFNAN_CHECK */
- ret0:
- s = s00;
- sign = 0;
- }
- goto ret;
- }
- e1 = e -= nf;
-
- /* Now we have nd0 digits, starting at s0, followed by a
- * decimal point, followed by nd-nd0 digits. The number we're
- * after is the integer represented by those digits times
- * 10**e */
-
- if (!nd0)
- nd0 = nd;
- k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1;
- dval(rv) = y;
- if (k > 9) {
+ret0:
+ s = s00;
+ sign = 0;
+ }
+ goto ret;
+ }
+ e1 = e -= nf;
+
+ /* Now we have nd0 digits, starting at s0, followed by a
+ * decimal point, followed by nd-nd0 digits. The number we're
+ * after is the integer represented by those digits times
+ * 10**e */
+
+ if (!nd0) {
+ nd0 = nd;
+ }
+ k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1;
+ dval(rv) = y;
+ if (k > 9) {
#ifdef SET_INEXACT
- if (k > DBL_DIG)
- oldinexact = get_inexact();
+ if (k > DBL_DIG) {
+ oldinexact = get_inexact();
+ }
#endif
- dval(rv) = tens[k - 9] * dval(rv) + z;
- }
- bd0 = 0;
- if (nd <= DBL_DIG
+ dval(rv) = tens[k - 9] * dval(rv) + z;
+ }
+ bd0 = 0;
+ if (nd <= DBL_DIG
#ifndef RND_PRODQUOT
#ifndef Honor_FLT_ROUNDS
- && Flt_Rounds == 1
+ && Flt_Rounds == 1
#endif
#endif
- ) {
- if (!e)
- goto ret;
- if (e > 0) {
- if (e <= Ten_pmax) {
+ ) {
+ if (!e) {
+ goto ret;
+ }
+ if (e > 0) {
+ if (e <= Ten_pmax) {
#ifdef VAX
- goto vax_ovfl_check;
+ goto vax_ovfl_check;
#else
#ifdef Honor_FLT_ROUNDS
- /* round correctly FLT_ROUNDS = 2 or 3 */
- if (sign) {
- rv = -rv;
- sign = 0;
- }
-#endif
- /* rv = */ rounded_product(dval(rv), tens[e]);
- goto ret;
-#endif
- }
- i = DBL_DIG - nd;
- if (e <= Ten_pmax + i) {
- /* A fancier test would sometimes let us do
- * this for larger i values.
- */
+ /* round correctly FLT_ROUNDS = 2 or 3 */
+ if (sign) {
+ rv = -rv;
+ sign = 0;
+ }
+#endif
+ /* rv = */ rounded_product(dval(rv), tens[e]);
+ goto ret;
+#endif
+ }
+ i = DBL_DIG - nd;
+ if (e <= Ten_pmax + i) {
+ /* A fancier test would sometimes let us do
+ * this for larger i values.
+ */
#ifdef Honor_FLT_ROUNDS
- /* round correctly FLT_ROUNDS = 2 or 3 */
- if (sign) {
- rv = -rv;
- sign = 0;
- }
-#endif
- e -= i;
- dval(rv) *= tens[i];
+ /* round correctly FLT_ROUNDS = 2 or 3 */
+ if (sign) {
+ rv = -rv;
+ sign = 0;
+ }
+#endif
+ e -= i;
+ dval(rv) *= tens[i];
#ifdef VAX
- /* VAX exponent range is so narrow we must
- * worry about overflow here...
- */
- vax_ovfl_check:
- word0(rv) -= P*Exp_msk1;
- /* rv = */ rounded_product(dval(rv), tens[e]);
- if ((word0(rv) & Exp_mask)
- > Exp_msk1*(DBL_MAX_EXP+Bias-1-P))
- goto ovfl;
- word0(rv) += P*Exp_msk1;
-#else
- /* rv = */ rounded_product(dval(rv), tens[e]);
-#endif
- goto ret;
- }
- }
+ /* VAX exponent range is so narrow we must
+ * worry about overflow here...
+ */
+vax_ovfl_check:
+ word0(rv) -= P*Exp_msk1;
+ /* rv = */ rounded_product(dval(rv), tens[e]);
+ if ((word0(rv) & Exp_mask)
+ > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) {
+ goto ovfl;
+ }
+ word0(rv) += P*Exp_msk1;
+#else
+ /* rv = */ rounded_product(dval(rv), tens[e]);
+#endif
+ goto ret;
+ }
+ }
#ifndef Inaccurate_Divide
- else if (e >= -Ten_pmax) {
+ else if (e >= -Ten_pmax) {
#ifdef Honor_FLT_ROUNDS
- /* round correctly FLT_ROUNDS = 2 or 3 */
- if (sign) {
- rv = -rv;
- sign = 0;
- }
+ /* round correctly FLT_ROUNDS = 2 or 3 */
+ if (sign) {
+ rv = -rv;
+ sign = 0;
+ }
#endif
- /* rv = */ rounded_quotient(dval(rv), tens[-e]);
- goto ret;
- }
+ /* rv = */ rounded_quotient(dval(rv), tens[-e]);
+ goto ret;
+ }
#endif
- }
- e1 += nd - k;
+ }
+ e1 += nd - k;
#ifdef IEEE_Arith
#ifdef SET_INEXACT
- inexact = 1;
- if (k <= DBL_DIG)
- oldinexact = get_inexact();
+ inexact = 1;
+ if (k <= DBL_DIG) {
+ oldinexact = get_inexact();
+ }
#endif
#ifdef Avoid_Underflow
- scale = 0;
+ scale = 0;
#endif
#ifdef Honor_FLT_ROUNDS
- if ((rounding = Flt_Rounds) >= 2) {
- if (sign)
- rounding = rounding == 2 ? 0 : 2;
- else
- if (rounding != 2)
- rounding = 0;
- }
+ if ((rounding = Flt_Rounds) >= 2) {
+ if (sign) {
+ rounding = rounding == 2 ? 0 : 2;
+ }
+ else if (rounding != 2) {
+ rounding = 0;
+ }
+ }
#endif
#endif /*IEEE_Arith*/
- /* Get starting approximation = rv * 10**e1 */
+ /* Get starting approximation = rv * 10**e1 */
- if (e1 > 0) {
- if (i = e1 & 15)
- dval(rv) *= tens[i];
- if (e1 &= ~15) {
- if (e1 > DBL_MAX_10_EXP) {
- ovfl:
+ if (e1 > 0) {
+ if (i = e1 & 15) {
+ dval(rv) *= tens[i];
+ }
+ if (e1 &= ~15) {
+ if (e1 > DBL_MAX_10_EXP) {
+ovfl:
#ifndef NO_ERRNO
- PR_SetError(PR_RANGE_ERROR, 0);
+ PR_SetError(PR_RANGE_ERROR, 0);
#endif
- /* Can't trust HUGE_VAL */
+ /* Can't trust HUGE_VAL */
#ifdef IEEE_Arith
#ifdef Honor_FLT_ROUNDS
- switch(rounding) {
- case 0: /* toward 0 */
- case 3: /* toward -infinity */
- word0(rv) = Big0;
- word1(rv) = Big1;
- break;
- default:
- word0(rv) = Exp_mask;
- word1(rv) = 0;
- }
+ switch(rounding) {
+ case 0: /* toward 0 */
+ case 3: /* toward -infinity */
+ word0(rv) = Big0;
+ word1(rv) = Big1;
+ break;
+ default:
+ word0(rv) = Exp_mask;
+ word1(rv) = 0;
+ }
#else /*Honor_FLT_ROUNDS*/
- word0(rv) = Exp_mask;
- word1(rv) = 0;
+ word0(rv) = Exp_mask;
+ word1(rv) = 0;
#endif /*Honor_FLT_ROUNDS*/
#ifdef SET_INEXACT
- /* set overflow bit */
- dval(rv0) = 1e300;
- dval(rv0) *= dval(rv0);
+ /* set overflow bit */
+ dval(rv0) = 1e300;
+ dval(rv0) *= dval(rv0);
#endif
#else /*IEEE_Arith*/
- word0(rv) = Big0;
- word1(rv) = Big1;
+ word0(rv) = Big0;
+ word1(rv) = Big1;
#endif /*IEEE_Arith*/
- if (bd0)
- goto retfree;
- goto ret;
- }
- e1 >>= 4;
- for(j = 0; e1 > 1; j++, e1 >>= 1)
- if (e1 & 1)
- dval(rv) *= bigtens[j];
- /* The last multiplication could overflow. */
- word0(rv) -= P*Exp_msk1;
- dval(rv) *= bigtens[j];
- if ((z = word0(rv) & Exp_mask)
- > Exp_msk1*(DBL_MAX_EXP+Bias-P))
- goto ovfl;
- if (z > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) {
- /* set to largest number */
- /* (Can't trust DBL_MAX) */
- word0(rv) = Big0;
- word1(rv) = Big1;
- }
- else
- word0(rv) += P*Exp_msk1;
- }
- }
- else if (e1 < 0) {
- e1 = -e1;
- if (i = e1 & 15)
- dval(rv) /= tens[i];
- if (e1 >>= 4) {
- if (e1 >= 1 << n_bigtens)
- goto undfl;
+ if (bd0) {
+ goto retfree;
+ }
+ goto ret;
+ }
+ e1 >>= 4;
+ for(j = 0; e1 > 1; j++, e1 >>= 1)
+ if (e1 & 1) {
+ dval(rv) *= bigtens[j];
+ }
+ /* The last multiplication could overflow. */
+ word0(rv) -= P*Exp_msk1;
+ dval(rv) *= bigtens[j];
+ if ((z = word0(rv) & Exp_mask)
+ > Exp_msk1*(DBL_MAX_EXP+Bias-P)) {
+ goto ovfl;
+ }
+ if (z > Exp_msk1*(DBL_MAX_EXP+Bias-1-P)) {
+ /* set to largest number */
+ /* (Can't trust DBL_MAX) */
+ word0(rv) = Big0;
+ word1(rv) = Big1;
+ }
+ else {
+ word0(rv) += P*Exp_msk1;
+ }
+ }
+ }
+ else if (e1 < 0) {
+ e1 = -e1;
+ if (i = e1 & 15) {
+ dval(rv) /= tens[i];
+ }
+ if (e1 >>= 4) {
+ if (e1 >= 1 << n_bigtens) {
+ goto undfl;
+ }
#ifdef Avoid_Underflow
- if (e1 & Scale_Bit)
- scale = 2*P;
- for(j = 0; e1 > 0; j++, e1 >>= 1)
- if (e1 & 1)
- dval(rv) *= tinytens[j];
- if (scale && (j = 2*P + 1 - ((word0(rv) & Exp_mask)
- >> Exp_shift)) > 0) {
- /* scaled rv is denormal; zap j low bits */
- if (j >= 32) {
- word1(rv) = 0;
- if (j >= 53)
- word0(rv) = (P+2)*Exp_msk1;
- else
- word0(rv) &= 0xffffffff << j-32;
- }
- else
- word1(rv) &= 0xffffffff << j;
- }
-#else
- for(j = 0; e1 > 1; j++, e1 >>= 1)
- if (e1 & 1)
- dval(rv) *= tinytens[j];
- /* The last multiplication could underflow. */
- dval(rv0) = dval(rv);
- dval(rv) *= tinytens[j];
- if (!dval(rv)) {
- dval(rv) = 2.*dval(rv0);
- dval(rv) *= tinytens[j];
-#endif
- if (!dval(rv)) {
- undfl:
- dval(rv) = 0.;
+ if (e1 & Scale_Bit) {
+ scale = 2*P;
+ }
+ for(j = 0; e1 > 0; j++, e1 >>= 1)
+ if (e1 & 1) {
+ dval(rv) *= tinytens[j];
+ }
+ if (scale && (j = 2*P + 1 - ((word0(rv) & Exp_mask)
+ >> Exp_shift)) > 0) {
+ /* scaled rv is denormal; zap j low bits */
+ if (j >= 32) {
+ word1(rv) = 0;
+ if (j >= 53) {
+ word0(rv) = (P+2)*Exp_msk1;
+ }
+ else {
+ word0(rv) &= 0xffffffff << j-32;
+ }
+ }
+ else {
+ word1(rv) &= 0xffffffff << j;
+ }
+ }
+#else
+ for(j = 0; e1 > 1; j++, e1 >>= 1)
+ if (e1 & 1) {
+ dval(rv) *= tinytens[j];
+ }
+ /* The last multiplication could underflow. */
+ dval(rv0) = dval(rv);
+ dval(rv) *= tinytens[j];
+ if (!dval(rv)) {
+ dval(rv) = 2.*dval(rv0);
+ dval(rv) *= tinytens[j];
+#endif
+ if (!dval(rv)) {
+undfl:
+ dval(rv) = 0.;
#ifndef NO_ERRNO
- PR_SetError(PR_RANGE_ERROR, 0);
+ PR_SetError(PR_RANGE_ERROR, 0);
#endif
- if (bd0)
- goto retfree;
- goto ret;
- }
+ if (bd0) {
+ goto retfree;
+ }
+ goto ret;
+ }
#ifndef Avoid_Underflow
- word0(rv) = Tiny0;
- word1(rv) = Tiny1;
- /* The refinement below will clean
- * this approximation up.
- */
- }
-#endif
- }
- }
-
- /* Now the hard part -- adjusting rv to the correct value.*/
-
- /* Put digits into bd: true value = bd * 10^e */
-
- bd0 = s2b(s0, nd0, nd, y);
-
- for(;;) {
- bd = Balloc(bd0->k);
- Bcopy(bd, bd0);
- bb = d2b(dval(rv), &bbe, &bbbits); /* rv = bb * 2^bbe */
- bs = i2b(1);
-
- if (e >= 0) {
- bb2 = bb5 = 0;
- bd2 = bd5 = e;
- }
- else {
- bb2 = bb5 = -e;
- bd2 = bd5 = 0;
- }
- if (bbe >= 0)
- bb2 += bbe;
- else
- bd2 -= bbe;
- bs2 = bb2;
+ word0(rv) = Tiny0;
+ word1(rv) = Tiny1;
+ /* The refinement below will clean
+ * this approximation up.
+ */
+ }
+#endif
+ }
+}
+
+/* Now the hard part -- adjusting rv to the correct value.*/
+
+/* Put digits into bd: true value = bd * 10^e */
+
+bd0 = s2b(s0, nd0, nd, y);
+
+for(;;) {
+ bd = Balloc(bd0->k);
+ Bcopy(bd, bd0);
+ bb = d2b(dval(rv), &bbe, &bbbits); /* rv = bb * 2^bbe */
+ bs = i2b(1);
+
+ if (e >= 0) {
+ bb2 = bb5 = 0;
+ bd2 = bd5 = e;
+ }
+ else {
+ bb2 = bb5 = -e;
+ bd2 = bd5 = 0;
+ }
+ if (bbe >= 0) {
+ bb2 += bbe;
+ }
+ else {
+ bd2 -= bbe;
+ }
+ bs2 = bb2;
#ifdef Honor_FLT_ROUNDS
- if (rounding != 1)
- bs2++;
+ if (rounding != 1) {
+ bs2++;
+ }
#endif
#ifdef Avoid_Underflow
- j = bbe - scale;
- i = j + bbbits - 1; /* logb(rv) */
- if (i < Emin) /* denormal */
- j += P - Emin;
- else
- j = P + 1 - bbbits;
+ j = bbe - scale;
+ i = j + bbbits - 1; /* logb(rv) */
+ if (i < Emin) { /* denormal */
+ j += P - Emin;
+ }
+ else {
+ j = P + 1 - bbbits;
+ }
#else /*Avoid_Underflow*/
#ifdef Sudden_Underflow
#ifdef IBM
- j = 1 + 4*P - 3 - bbbits + ((bbe + bbbits - 1) & 3);
+ j = 1 + 4*P - 3 - bbbits + ((bbe + bbbits - 1) & 3);
#else
- j = P + 1 - bbbits;
+ j = P + 1 - bbbits;
#endif
#else /*Sudden_Underflow*/
- j = bbe;
- i = j + bbbits - 1; /* logb(rv) */
- if (i < Emin) /* denormal */
- j += P - Emin;
- else
- j = P + 1 - bbbits;
+ j = bbe;
+ i = j + bbbits - 1; /* logb(rv) */
+ if (i < Emin) { /* denormal */
+ j += P - Emin;
+ }
+ else {
+ j = P + 1 - bbbits;
+ }
#endif /*Sudden_Underflow*/
#endif /*Avoid_Underflow*/
- bb2 += j;
- bd2 += j;
+ bb2 += j;
+ bd2 += j;
#ifdef Avoid_Underflow
- bd2 += scale;
-#endif
- i = bb2 < bd2 ? bb2 : bd2;
- if (i > bs2)
- i = bs2;
- if (i > 0) {
- bb2 -= i;
- bd2 -= i;
- bs2 -= i;
- }
- if (bb5 > 0) {
- bs = pow5mult(bs, bb5);
- bb1 = mult(bs, bb);
- Bfree(bb);
- bb = bb1;
- }
- if (bb2 > 0)
- bb = lshift(bb, bb2);
- if (bd5 > 0)
- bd = pow5mult(bd, bd5);
- if (bd2 > 0)
- bd = lshift(bd, bd2);
- if (bs2 > 0)
- bs = lshift(bs, bs2);
- delta = diff(bb, bd);
- dsign = delta->sign;
- delta->sign = 0;
- i = cmp(delta, bs);
+ bd2 += scale;
+#endif
+ i = bb2 < bd2 ? bb2 : bd2;
+ if (i > bs2) {
+ i = bs2;
+ }
+ if (i > 0) {
+ bb2 -= i;
+ bd2 -= i;
+ bs2 -= i;
+ }
+ if (bb5 > 0) {
+ bs = pow5mult(bs, bb5);
+ bb1 = mult(bs, bb);
+ Bfree(bb);
+ bb = bb1;
+ }
+ if (bb2 > 0) {
+ bb = lshift(bb, bb2);
+ }
+ if (bd5 > 0) {
+ bd = pow5mult(bd, bd5);
+ }
+ if (bd2 > 0) {
+ bd = lshift(bd, bd2);
+ }
+ if (bs2 > 0) {
+ bs = lshift(bs, bs2);
+ }
+ delta = diff(bb, bd);
+ dsign = delta->sign;
+ delta->sign = 0;
+ i = cmp(delta, bs);
#ifdef Honor_FLT_ROUNDS
- if (rounding != 1) {
- if (i < 0) {
- /* Error is less than an ulp */
- if (!delta->x[0] && delta->wds <= 1) {
- /* exact */
+ if (rounding != 1) {
+ if (i < 0) {
+ /* Error is less than an ulp */
+ if (!delta->x[0] && delta->wds <= 1) {
+ /* exact */
#ifdef SET_INEXACT
- inexact = 0;
-#endif
- break;
- }
- if (rounding) {
- if (dsign) {
- adj = 1.;
- goto apply_adj;
- }
- }
- else if (!dsign) {
- adj = -1.;
- if (!word1(rv)
- && !(word0(rv) & Frac_mask)) {
- y = word0(rv) & Exp_mask;
+ inexact = 0;
+#endif
+ break;
+ }
+ if (rounding) {
+ if (dsign) {
+ adj = 1.;
+ goto apply_adj;
+ }
+ }
+ else if (!dsign) {
+ adj = -1.;
+ if (!word1(rv)
+ && !(word0(rv) & Frac_mask)) {
+ y = word0(rv) & Exp_mask;
#ifdef Avoid_Underflow
- if (!scale || y > 2*P*Exp_msk1)
+ if (!scale || y > 2*P*Exp_msk1)
#else
- if (y)
+ if (y)
#endif
- {
- delta = lshift(delta,Log2P);
- if (cmp(delta, bs) <= 0)
- adj = -0.5;
- }
- }
- apply_adj:
+ {
+ delta = lshift(delta,Log2P);
+ if (cmp(delta, bs) <= 0) {
+ adj = -0.5;
+ }
+ }
+ }
+apply_adj:
#ifdef Avoid_Underflow
- if (scale && (y = word0(rv) & Exp_mask)
- <= 2*P*Exp_msk1)
- word0(adj) += (2*P+1)*Exp_msk1 - y;
+ if (scale && (y = word0(rv) & Exp_mask)
+ <= 2*P*Exp_msk1) {
+ word0(adj) += (2*P+1)*Exp_msk1 - y;
+ }
#else
#ifdef Sudden_Underflow
- if ((word0(rv) & Exp_mask) <=
- P*Exp_msk1) {
- word0(rv) += P*Exp_msk1;
- dval(rv) += adj*ulp(dval(rv));
- word0(rv) -= P*Exp_msk1;
- }
- else
+ if ((word0(rv) & Exp_mask) <=
+ P*Exp_msk1) {
+ word0(rv) += P*Exp_msk1;
+ dval(rv) += adj*ulp(dval(rv));
+ word0(rv) -= P*Exp_msk1;
+ }
+ else
#endif /*Sudden_Underflow*/
#endif /*Avoid_Underflow*/
- dval(rv) += adj*ulp(dval(rv));
- }
- break;
- }
- adj = ratio(delta, bs);
- if (adj < 1.)
- adj = 1.;
- if (adj <= 0x7ffffffe) {
- /* adj = rounding ? ceil(adj) : floor(adj); */
- y = adj;
- if (y != adj) {
- if (!((rounding>>1) ^ dsign))
- y++;
- adj = y;
- }
- }
+ dval(rv) += adj*ulp(dval(rv));
+ }
+ break;
+ }
+ adj = ratio(delta, bs);
+ if (adj < 1.) {
+ adj = 1.;
+ }
+ if (adj <= 0x7ffffffe) {
+ /* adj = rounding ? ceil(adj) : floor(adj); */
+ y = adj;
+ if (y != adj) {
+ if (!((rounding>>1) ^ dsign)) {
+ y++;
+ }
+ adj = y;
+ }
+ }
#ifdef Avoid_Underflow
- if (scale && (y = word0(rv) & Exp_mask) <= 2*P*Exp_msk1)
- word0(adj) += (2*P+1)*Exp_msk1 - y;
+ if (scale && (y = word0(rv) & Exp_mask) <= 2*P*Exp_msk1) {
+ word0(adj) += (2*P+1)*Exp_msk1 - y;
+ }
#else
#ifdef Sudden_Underflow
- if ((word0(rv) & Exp_mask) <= P*Exp_msk1) {
- word0(rv) += P*Exp_msk1;
- adj *= ulp(dval(rv));
- if (dsign)
- dval(rv) += adj;
- else
- dval(rv) -= adj;
- word0(rv) -= P*Exp_msk1;
- goto cont;
- }
+ if ((word0(rv) & Exp_mask) <= P*Exp_msk1) {
+ word0(rv) += P*Exp_msk1;
+ adj *= ulp(dval(rv));
+ if (dsign) {
+ dval(rv) += adj;
+ }
+ else {
+ dval(rv) -= adj;
+ }
+ word0(rv) -= P*Exp_msk1;
+ goto cont;
+ }
#endif /*Sudden_Underflow*/
#endif /*Avoid_Underflow*/
- adj *= ulp(dval(rv));
- if (dsign)
- dval(rv) += adj;
- else
- dval(rv) -= adj;
- goto cont;
- }
+ adj *= ulp(dval(rv));
+ if (dsign) {
+ dval(rv) += adj;
+ }
+ else {
+ dval(rv) -= adj;
+ }
+ goto cont;
+ }
#endif /*Honor_FLT_ROUNDS*/
- if (i < 0) {
- /* Error is less than half an ulp -- check for
- * special case of mantissa a power of two.
- */
- if (dsign || word1(rv) || word0(rv) & Bndry_mask
+ if (i < 0) {
+ /* Error is less than half an ulp -- check for
+ * special case of mantissa a power of two.
+ */
+ if (dsign || word1(rv) || word0(rv) & Bndry_mask
#ifdef IEEE_Arith
#ifdef Avoid_Underflow
- || (word0(rv) & Exp_mask) <= (2*P+1)*Exp_msk1
+ || (word0(rv) & Exp_mask) <= (2*P+1)*Exp_msk1
#else
- || (word0(rv) & Exp_mask) <= Exp_msk1
+ || (word0(rv) & Exp_mask) <= Exp_msk1
#endif
#endif
- ) {
+ ) {
#ifdef SET_INEXACT
- if (!delta->x[0] && delta->wds <= 1)
- inexact = 0;
+ if (!delta->x[0] && delta->wds <= 1) {
+ inexact = 0;
+ }
#endif
- break;
- }
- if (!delta->x[0] && delta->wds <= 1) {
- /* exact result */
+ break;
+ }
+ if (!delta->x[0] && delta->wds <= 1) {
+ /* exact result */
#ifdef SET_INEXACT
- inexact = 0;
-#endif
- break;
- }
- delta = lshift(delta,Log2P);
- if (cmp(delta, bs) > 0)
- goto drop_down;
- break;
- }
- if (i == 0) {
- /* exactly half-way between */
- if (dsign) {
- if ((word0(rv) & Bndry_mask1) == Bndry_mask1
- && word1(rv) == (
+ inexact = 0;
+#endif
+ break;
+ }
+ delta = lshift(delta,Log2P);
+ if (cmp(delta, bs) > 0) {
+ goto drop_down;
+ }
+ break;
+ }
+ if (i == 0) {
+ /* exactly half-way between */
+ if (dsign) {
+ if ((word0(rv) & Bndry_mask1) == Bndry_mask1
+ && word1(rv) == (
#ifdef Avoid_Underflow
- (scale && (y = word0(rv) & Exp_mask) <= 2*P*Exp_msk1)
- ? (0xffffffff & (0xffffffff << (2*P+1-(y>>Exp_shift)))) :
+ (scale && (y = word0(rv) & Exp_mask) <= 2*P*Exp_msk1)
+ ? (0xffffffff & (0xffffffff << (2*P+1-(y>>Exp_shift)))) :
#endif
- 0xffffffff)) {
- /*boundary case -- increment exponent*/
- word0(rv) = (word0(rv) & Exp_mask)
- + Exp_msk1
+ 0xffffffff)) {
+ /*boundary case -- increment exponent*/
+ word0(rv) = (word0(rv) & Exp_mask)
+ + Exp_msk1
#ifdef IBM
- | Exp_msk1 >> 4
+ | Exp_msk1 >> 4
#endif
- ;
- word1(rv) = 0;
+ ;
+ word1(rv) = 0;
#ifdef Avoid_Underflow
- dsign = 0;
-#endif
- break;
- }
- }
- else if (!(word0(rv) & Bndry_mask) && !word1(rv)) {
- drop_down:
- /* boundary case -- decrement exponent */
+ dsign = 0;
+#endif
+ break;
+ }
+ }
+ else if (!(word0(rv) & Bndry_mask) && !word1(rv)) {
+drop_down:
+ /* boundary case -- decrement exponent */
#ifdef Sudden_Underflow /*{{*/
- L = word0(rv) & Exp_mask;
+ L = word0(rv) & Exp_mask;
#ifdef IBM
- if (L < Exp_msk1)
+ if (L < Exp_msk1)
#else
#ifdef Avoid_Underflow
- if (L <= (scale ? (2*P+1)*Exp_msk1 : Exp_msk1))
+ if (L <= (scale ? (2*P+1)*Exp_msk1 : Exp_msk1))
#else
- if (L <= Exp_msk1)
+ if (L <= Exp_msk1)
#endif /*Avoid_Underflow*/
#endif /*IBM*/
- goto undfl;
- L -= Exp_msk1;
+ goto undfl;
+ L -= Exp_msk1;
#else /*Sudden_Underflow}{*/
#ifdef Avoid_Underflow
- if (scale) {
- L = word0(rv) & Exp_mask;
- if (L <= (2*P+1)*Exp_msk1) {
- if (L > (P+2)*Exp_msk1)
- /* round even ==> */
- /* accept rv */
- break;
- /* rv = smallest denormal */
- goto undfl;
- }
- }
+ if (scale) {
+ L = word0(rv) & Exp_mask;
+ if (L <= (2*P+1)*Exp_msk1) {
+ if (L > (P+2)*Exp_msk1)
+ /* round even ==> */
+ /* accept rv */
+ {
+ break;
+ }
+ /* rv = smallest denormal */
+ goto undfl;
+ }
+ }
#endif /*Avoid_Underflow*/
- L = (word0(rv) & Exp_mask) - Exp_msk1;
+ L = (word0(rv) & Exp_mask) - Exp_msk1;
#endif /*Sudden_Underflow}}*/
- word0(rv) = L | Bndry_mask1;
- word1(rv) = 0xffffffff;
+ word0(rv) = L | Bndry_mask1;
+ word1(rv) = 0xffffffff;
#ifdef IBM
- goto cont;
+ goto cont;
#else
- break;
+ break;
#endif
- }
+ }
#ifndef ROUND_BIASED
- if (!(word1(rv) & LSB))
- break;
+ if (!(word1(rv) & LSB)) {
+ break;
+ }
#endif
- if (dsign)
- dval(rv) += ulp(dval(rv));
+ if (dsign) {
+ dval(rv) += ulp(dval(rv));
+ }
#ifndef ROUND_BIASED
- else {
- dval(rv) -= ulp(dval(rv));
+ else {
+ dval(rv) -= ulp(dval(rv));
#ifndef Sudden_Underflow
- if (!dval(rv))
- goto undfl;
+ if (!dval(rv)) {
+ goto undfl;
+ }
#endif
- }
+ }
#ifdef Avoid_Underflow
- dsign = 1 - dsign;
+ dsign = 1 - dsign;
#endif
#endif
- break;
- }
- if ((aadj = ratio(delta, bs)) <= 2.) {
- if (dsign)
- aadj = aadj1 = 1.;
- else if (word1(rv) || word0(rv) & Bndry_mask) {
+ break;
+ }
+ if ((aadj = ratio(delta, bs)) <= 2.) {
+ if (dsign) {
+ aadj = aadj1 = 1.;
+ }
+ else if (word1(rv) || word0(rv) & Bndry_mask) {
#ifndef Sudden_Underflow
- if (word1(rv) == Tiny1 && !word0(rv))
- goto undfl;
-#endif
- aadj = 1.;
- aadj1 = -1.;
- }
- else {
- /* special case -- power of FLT_RADIX to be */
- /* rounded down... */
-
- if (aadj < 2./FLT_RADIX)
- aadj = 1./FLT_RADIX;
- else
- aadj *= 0.5;
- aadj1 = -aadj;
- }
- }
- else {
- aadj *= 0.5;
- aadj1 = dsign ? aadj : -aadj;
+ if (word1(rv) == Tiny1 && !word0(rv)) {
+ goto undfl;
+ }
+#endif
+ aadj = 1.;
+ aadj1 = -1.;
+ }
+ else {
+ /* special case -- power of FLT_RADIX to be */
+ /* rounded down... */
+
+ if (aadj < 2./FLT_RADIX) {
+ aadj = 1./FLT_RADIX;
+ }
+ else {
+ aadj *= 0.5;
+ }
+ aadj1 = -aadj;
+ }
+ }
+ else {
+ aadj *= 0.5;
+ aadj1 = dsign ? aadj : -aadj;
#ifdef Check_FLT_ROUNDS
- switch(Rounding) {
- case 2: /* towards +infinity */
- aadj1 -= 0.5;
- break;
- case 0: /* towards 0 */
- case 3: /* towards -infinity */
- aadj1 += 0.5;
- }
-#else
- if (Flt_Rounds == 0)
- aadj1 += 0.5;
+ switch(Rounding) {
+ case 2: /* towards +infinity */
+ aadj1 -= 0.5;
+ break;
+ case 0: /* towards 0 */
+ case 3: /* towards -infinity */
+ aadj1 += 0.5;
+ }
+#else
+ if (Flt_Rounds == 0) {
+ aadj1 += 0.5;
+ }
#endif /*Check_FLT_ROUNDS*/
- }
- y = word0(rv) & Exp_mask;
-
- /* Check for overflow */
-
- if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) {
- dval(rv0) = dval(rv);
- word0(rv) -= P*Exp_msk1;
- adj = aadj1 * ulp(dval(rv));
- dval(rv) += adj;
- if ((word0(rv) & Exp_mask) >=
- Exp_msk1*(DBL_MAX_EXP+Bias-P)) {
- if (word0(rv0) == Big0 && word1(rv0) == Big1)
- goto ovfl;
- word0(rv) = Big0;
- word1(rv) = Big1;
- goto cont;
- }
- else
- word0(rv) += P*Exp_msk1;
- }
- else {
+ }
+ y = word0(rv) & Exp_mask;
+
+ /* Check for overflow */
+
+ if (y == Exp_msk1*(DBL_MAX_EXP+Bias-1)) {
+ dval(rv0) = dval(rv);
+ word0(rv) -= P*Exp_msk1;
+ adj = aadj1 * ulp(dval(rv));
+ dval(rv) += adj;
+ if ((word0(rv) & Exp_mask) >=
+ Exp_msk1*(DBL_MAX_EXP+Bias-P)) {
+ if (word0(rv0) == Big0 && word1(rv0) == Big1) {
+ goto ovfl;
+ }
+ word0(rv) = Big0;
+ word1(rv) = Big1;
+ goto cont;
+ }
+ else {
+ word0(rv) += P*Exp_msk1;
+ }
+ }
+ else {
#ifdef Avoid_Underflow
- if (scale && y <= 2*P*Exp_msk1) {
- if (aadj <= 0x7fffffff) {
- if ((z = aadj) <= 0)
- z = 1;
- aadj = z;
- aadj1 = dsign ? aadj : -aadj;
- }
- dval(aadj2) = aadj1;
- word0(aadj2) += (2*P+1)*Exp_msk1 - y;
- aadj1 = dval(aadj2);
- }
- adj = aadj1 * ulp(dval(rv));
- dval(rv) += adj;
+ if (scale && y <= 2*P*Exp_msk1) {
+ if (aadj <= 0x7fffffff) {
+ if ((z = aadj) <= 0) {
+ z = 1;
+ }
+ aadj = z;
+ aadj1 = dsign ? aadj : -aadj;
+ }
+ dval(aadj2) = aadj1;
+ word0(aadj2) += (2*P+1)*Exp_msk1 - y;
+ aadj1 = dval(aadj2);
+ }
+ adj = aadj1 * ulp(dval(rv));
+ dval(rv) += adj;
#else
#ifdef Sudden_Underflow
- if ((word0(rv) & Exp_mask) <= P*Exp_msk1) {
- dval(rv0) = dval(rv);
- word0(rv) += P*Exp_msk1;
- adj = aadj1 * ulp(dval(rv));
- dval(rv) += adj;
+ if ((word0(rv) & Exp_mask) <= P*Exp_msk1) {
+ dval(rv0) = dval(rv);
+ word0(rv) += P*Exp_msk1;
+ adj = aadj1 * ulp(dval(rv));
+ dval(rv) += adj;
#ifdef IBM
- if ((word0(rv) & Exp_mask) < P*Exp_msk1)
-#else
- if ((word0(rv) & Exp_mask) <= P*Exp_msk1)
-#endif
- {
- if (word0(rv0) == Tiny0
- && word1(rv0) == Tiny1)
- goto undfl;
- word0(rv) = Tiny0;
- word1(rv) = Tiny1;
- goto cont;
- }
- else
- word0(rv) -= P*Exp_msk1;
- }
- else {
- adj = aadj1 * ulp(dval(rv));
- dval(rv) += adj;
- }
+ if ((word0(rv) & Exp_mask) < P*Exp_msk1)
+#else
+ if ((word0(rv) & Exp_mask) <= P*Exp_msk1)
+#endif
+ {
+ if (word0(rv0) == Tiny0
+ && word1(rv0) == Tiny1) {
+ goto undfl;
+ }
+ word0(rv) = Tiny0;
+ word1(rv) = Tiny1;
+ goto cont;
+ }
+ else {
+ word0(rv) -= P*Exp_msk1;
+ }
+ }
+ else {
+ adj = aadj1 * ulp(dval(rv));
+ dval(rv) += adj;
+ }
#else /*Sudden_Underflow*/
- /* Compute adj so that the IEEE rounding rules will
- * correctly round rv + adj in some half-way cases.
- * If rv * ulp(rv) is denormalized (i.e.,
- * y <= (P-1)*Exp_msk1), we must adjust aadj to avoid
- * trouble from bits lost to denormalization;
- * example: 1.2e-307 .
- */
- if (y <= (P-1)*Exp_msk1 && aadj > 1.) {
- aadj1 = (double)(int)(aadj + 0.5);
- if (!dsign)
- aadj1 = -aadj1;
- }
- adj = aadj1 * ulp(dval(rv));
- dval(rv) += adj;
+ /* Compute adj so that the IEEE rounding rules will
+ * correctly round rv + adj in some half-way cases.
+ * If rv * ulp(rv) is denormalized (i.e.,
+ * y <= (P-1)*Exp_msk1), we must adjust aadj to avoid
+ * trouble from bits lost to denormalization;
+ * example: 1.2e-307 .
+ */
+ if (y <= (P-1)*Exp_msk1 && aadj > 1.) {
+ aadj1 = (double)(int)(aadj + 0.5);
+ if (!dsign) {
+ aadj1 = -aadj1;
+ }
+ }
+ adj = aadj1 * ulp(dval(rv));
+ dval(rv) += adj;
#endif /*Sudden_Underflow*/
#endif /*Avoid_Underflow*/
- }
- z = word0(rv) & Exp_mask;
+ }
+ z = word0(rv) & Exp_mask;
#ifndef SET_INEXACT
#ifdef Avoid_Underflow
- if (!scale)
-#endif
- if (y == z) {
- /* Can we stop now? */
- L = (Long)aadj;
- aadj -= L;
- /* The tolerances below are conservative. */
- if (dsign || word1(rv) || word0(rv) & Bndry_mask) {
- if (aadj < .4999999 || aadj > .5000001)
- break;
- }
- else if (aadj < .4999999/FLT_RADIX)
- break;
- }
-#endif
- cont:
- Bfree(bb);
- Bfree(bd);
- Bfree(bs);
- Bfree(delta);
- }
+ if (!scale)
+#endif
+ if (y == z) {
+ /* Can we stop now? */
+ L = (Long)aadj;
+ aadj -= L;
+ /* The tolerances below are conservative. */
+ if (dsign || word1(rv) || word0(rv) & Bndry_mask) {
+ if (aadj < .4999999 || aadj > .5000001) {
+ break;
+ }
+ }
+ else if (aadj < .4999999/FLT_RADIX) {
+ break;
+ }
+ }
+#endif
+cont:
+ Bfree(bb);
+ Bfree(bd);
+ Bfree(bs);
+ Bfree(delta);
+}
#ifdef SET_INEXACT
- if (inexact) {
- if (!oldinexact) {
- word0(rv0) = Exp_1 + (70 << Exp_shift);
- word1(rv0) = 0;
- dval(rv0) += 1.;
- }
- }
- else if (!oldinexact)
- clear_inexact();
+if (inexact) {
+ if (!oldinexact) {
+ word0(rv0) = Exp_1 + (70 << Exp_shift);
+ word1(rv0) = 0;
+ dval(rv0) += 1.;
+ }
+}
+else if (!oldinexact) {
+ clear_inexact();
+}
#endif
#ifdef Avoid_Underflow
- if (scale) {
- word0(rv0) = Exp_1 - 2*P*Exp_msk1;
- word1(rv0) = 0;
- dval(rv) *= dval(rv0);
+if (scale) {
+ word0(rv0) = Exp_1 - 2*P*Exp_msk1;
+ word1(rv0) = 0;
+ dval(rv) *= dval(rv0);
#ifndef NO_ERRNO
- /* try to avoid the bug of testing an 8087 register value */
- if (word0(rv) == 0 && word1(rv) == 0)
- PR_SetError(PR_RANGE_ERROR, 0);
+ /* try to avoid the bug of testing an 8087 register value */
+ if (word0(rv) == 0 && word1(rv) == 0) {
+ PR_SetError(PR_RANGE_ERROR, 0);
+ }
#endif
- }
+}
#endif /* Avoid_Underflow */
#ifdef SET_INEXACT
- if (inexact && !(word0(rv) & Exp_mask)) {
- /* set underflow bit */
- dval(rv0) = 1e-300;
- dval(rv0) *= dval(rv0);
- }
-#endif
- retfree:
- Bfree(bb);
- Bfree(bd);
- Bfree(bs);
- Bfree(bd0);
- Bfree(delta);
- ret:
- if (se)
- *se = (char *)s;
- return sign ? -dval(rv) : dval(rv);
- }
-
- static int
+if (inexact && !(word0(rv) & Exp_mask)) {
+ /* set underflow bit */
+ dval(rv0) = 1e-300;
+ dval(rv0) *= dval(rv0);
+}
+#endif
+retfree:
+Bfree(bb);
+Bfree(bd);
+Bfree(bs);
+Bfree(bd0);
+Bfree(delta);
+ret:
+if (se) {
+ *se = (char *)s;
+}
+return sign ? -dval(rv) : dval(rv);
+}
+
+static int
quorem
#ifdef KR_headers
- (b, S) Bigint *b, *S;
+(b, S) Bigint *b, *S;
#else
- (Bigint *b, Bigint *S)
+(Bigint *b, Bigint *S)
#endif
{
- int n;
- ULong *bx, *bxe, q, *sx, *sxe;
+ int n;
+ ULong *bx, *bxe, q, *sx, *sxe;
#ifdef ULLong
- ULLong borrow, carry, y, ys;
+ ULLong borrow, carry, y, ys;
#else
- ULong borrow, carry, y, ys;
+ ULong borrow, carry, y, ys;
#ifdef Pack_32
- ULong si, z, zs;
+ ULong si, z, zs;
#endif
#endif
- n = S->wds;
+ n = S->wds;
#ifdef DEBUG
- /*debug*/ if (b->wds > n)
- /*debug*/ Bug("oversize b in quorem");
-#endif
- if (b->wds < n)
- return 0;
- sx = S->x;
- sxe = sx + --n;
- bx = b->x;
- bxe = bx + n;
- q = *bxe / (*sxe + 1); /* ensure q <= true quotient */
+ /*debug*/ if (b->wds > n)
+ /*debug*/{
+ Bug("oversize b in quorem");
+ }
+#endif
+ if (b->wds < n) {
+ return 0;
+ }
+ sx = S->x;
+ sxe = sx + --n;
+ bx = b->x;
+ bxe = bx + n;
+ q = *bxe / (*sxe + 1); /* ensure q <= true quotient */
#ifdef DEBUG
- /*debug*/ if (q > 9)
- /*debug*/ Bug("oversized quotient in quorem");
+ /*debug*/ if (q > 9)
+ /*debug*/{
+ Bug("oversized quotient in quorem");
+ }
#endif
- if (q) {
- borrow = 0;
- carry = 0;
- do {
+ if (q) {
+ borrow = 0;
+ carry = 0;
+ do {
#ifdef ULLong
- ys = *sx++ * (ULLong)q + carry;
- carry = ys >> 32;
- y = *bx - (ys & FFFFFFFF) - borrow;
- borrow = y >> 32 & (ULong)1;
- *bx++ = y & FFFFFFFF;
+ ys = *sx++ * (ULLong)q + carry;
+ carry = ys >> 32;
+ y = *bx - (ys & FFFFFFFF) - borrow;
+ borrow = y >> 32 & (ULong)1;
+ *bx++ = y & FFFFFFFF;
#else
#ifdef Pack_32
- si = *sx++;
- ys = (si & 0xffff) * q + carry;
- zs = (si >> 16) * q + (ys >> 16);
- carry = zs >> 16;
- y = (*bx & 0xffff) - (ys & 0xffff) - borrow;
- borrow = (y & 0x10000) >> 16;
- z = (*bx >> 16) - (zs & 0xffff) - borrow;
- borrow = (z & 0x10000) >> 16;
- Storeinc(bx, z, y);
-#else
- ys = *sx++ * q + carry;
- carry = ys >> 16;
- y = *bx - (ys & 0xffff) - borrow;
- borrow = (y & 0x10000) >> 16;
- *bx++ = y & 0xffff;
-#endif
-#endif
- }
- while(sx <= sxe);
- if (!*bxe) {
- bx = b->x;
- while(--bxe > bx && !*bxe)
- --n;
- b->wds = n;
- }
- }
- if (cmp(b, S) >= 0) {
- q++;
- borrow = 0;
- carry = 0;
- bx = b->x;
- sx = S->x;
- do {
+ si = *sx++;
+ ys = (si & 0xffff) * q + carry;
+ zs = (si >> 16) * q + (ys >> 16);
+ carry = zs >> 16;
+ y = (*bx & 0xffff) - (ys & 0xffff) - borrow;
+ borrow = (y & 0x10000) >> 16;
+ z = (*bx >> 16) - (zs & 0xffff) - borrow;
+ borrow = (z & 0x10000) >> 16;
+ Storeinc(bx, z, y);
+#else
+ ys = *sx++ * q + carry;
+ carry = ys >> 16;
+ y = *bx - (ys & 0xffff) - borrow;
+ borrow = (y & 0x10000) >> 16;
+ *bx++ = y & 0xffff;
+#endif
+#endif
+ }
+ while(sx <= sxe);
+ if (!*bxe) {
+ bx = b->x;
+ while(--bxe > bx && !*bxe) {
+ --n;
+ }
+ b->wds = n;
+ }
+ }
+ if (cmp(b, S) >= 0) {
+ q++;
+ borrow = 0;
+ carry = 0;
+ bx = b->x;
+ sx = S->x;
+ do {
#ifdef ULLong
- ys = *sx++ + carry;
- carry = ys >> 32;
- y = *bx - (ys & FFFFFFFF) - borrow;
- borrow = y >> 32 & (ULong)1;
- *bx++ = y & FFFFFFFF;
+ ys = *sx++ + carry;
+ carry = ys >> 32;
+ y = *bx - (ys & FFFFFFFF) - borrow;
+ borrow = y >> 32 & (ULong)1;
+ *bx++ = y & FFFFFFFF;
#else
#ifdef Pack_32
- si = *sx++;
- ys = (si & 0xffff) + carry;
- zs = (si >> 16) + (ys >> 16);
- carry = zs >> 16;
- y = (*bx & 0xffff) - (ys & 0xffff) - borrow;
- borrow = (y & 0x10000) >> 16;
- z = (*bx >> 16) - (zs & 0xffff) - borrow;
- borrow = (z & 0x10000) >> 16;
- Storeinc(bx, z, y);
-#else
- ys = *sx++ + carry;
- carry = ys >> 16;
- y = *bx - (ys & 0xffff) - borrow;
- borrow = (y & 0x10000) >> 16;
- *bx++ = y & 0xffff;
-#endif
-#endif
- }
- while(sx <= sxe);
- bx = b->x;
- bxe = bx + n;
- if (!*bxe) {
- while(--bxe > bx && !*bxe)
- --n;
- b->wds = n;
- }
- }
- return q;
- }
+ si = *sx++;
+ ys = (si & 0xffff) + carry;
+ zs = (si >> 16) + (ys >> 16);
+ carry = zs >> 16;
+ y = (*bx & 0xffff) - (ys & 0xffff) - borrow;
+ borrow = (y & 0x10000) >> 16;
+ z = (*bx >> 16) - (zs & 0xffff) - borrow;
+ borrow = (z & 0x10000) >> 16;
+ Storeinc(bx, z, y);
+#else
+ ys = *sx++ + carry;
+ carry = ys >> 16;
+ y = *bx - (ys & 0xffff) - borrow;
+ borrow = (y & 0x10000) >> 16;
+ *bx++ = y & 0xffff;
+#endif
+#endif
+ }
+ while(sx <= sxe);
+ bx = b->x;
+ bxe = bx + n;
+ if (!*bxe) {
+ while(--bxe > bx && !*bxe) {
+ --n;
+ }
+ b->wds = n;
+ }
+ }
+ return q;
+}
#ifndef MULTIPLE_THREADS
- static char *dtoa_result;
+static char *dtoa_result;
#endif
- static char *
+static char *
#ifdef KR_headers
rv_alloc(i) int i;
#else
rv_alloc(int i)
#endif
{
- int j, k, *r;
-
- j = sizeof(ULong);
- for(k = 0;
- sizeof(Bigint) - sizeof(ULong) - sizeof(int) + j <= i;
- j <<= 1)
- k++;
- r = (int*)Balloc(k);
- *r = k;
- return
+ int j, k, *r;
+
+ j = sizeof(ULong);
+ for(k = 0;
+ sizeof(Bigint) - sizeof(ULong) - sizeof(int) + j <= i;
+ j <<= 1) {
+ k++;
+ }
+ r = (int*)Balloc(k);
+ *r = k;
+ return
#ifndef MULTIPLE_THREADS
- dtoa_result =
+ dtoa_result =
#endif
- (char *)(r+1);
- }
+ (char *)(r+1);
+}
- static char *
+static char *
#ifdef KR_headers
nrv_alloc(s, rve, n) char *s, **rve; int n;
#else
nrv_alloc(char *s, char **rve, int n)
#endif
{
- char *rv, *t;
+ char *rv, *t;
- t = rv = rv_alloc(n);
- while(*t = *s++) t++;
- if (rve)
- *rve = t;
- return rv;
- }
+ t = rv = rv_alloc(n);
+ while(*t = *s++) {
+ t++;
+ }
+ if (rve) {
+ *rve = t;
+ }
+ return rv;
+}
/* freedtoa(s) must be used to free values s returned by dtoa
* when MULTIPLE_THREADS is #defined. It should be used in all cases,
@@ -2658,21 +2802,22 @@ nrv_alloc(char *s, char **rve, int n)
* when MULTIPLE_THREADS is not defined.
*/
- static void
+static void
#ifdef KR_headers
freedtoa(s) char *s;
#else
freedtoa(char *s)
#endif
{
- Bigint *b = (Bigint *)((int *)s - 1);
- b->maxwds = 1 << (b->k = *(int*)b);
- Bfree(b);
+ Bigint *b = (Bigint *)((int *)s - 1);
+ b->maxwds = 1 << (b->k = *(int*)b);
+ Bfree(b);
#ifndef MULTIPLE_THREADS
- if (s == dtoa_result)
- dtoa_result = 0;
+ if (s == dtoa_result) {
+ dtoa_result = 0;
+ }
#endif
- }
+}
/* dtoa for IEEE arithmetic (dmg): convert double to ASCII string.
*
@@ -2680,729 +2825,770 @@ freedtoa(char *s)
* Guy L. Steele, Jr. and Jon L. White [Proc. ACM SIGPLAN '90, pp. 112-126].
*
* Modifications:
- * 1. Rather than iterating, we use a simple numeric overestimate
- * to determine k = floor(log10(d)). We scale relevant
- * quantities using O(log2(k)) rather than O(k) multiplications.
- * 2. For some modes > 2 (corresponding to ecvt and fcvt), we don't
- * try to generate digits strictly left to right. Instead, we
- * compute with fewer bits and propagate the carry if necessary
- * when rounding the final digit up. This is often faster.
- * 3. Under the assumption that input will be rounded nearest,
- * mode 0 renders 1e23 as 1e23 rather than 9.999999999999999e22.
- * That is, we allow equality in stopping tests when the
- * round-nearest rule will give the same floating-point value
- * as would satisfaction of the stopping test with strict
- * inequality.
- * 4. We remove common factors of powers of 2 from relevant
- * quantities.
- * 5. When converting floating-point integers less than 1e16,
- * we use floating-point arithmetic rather than resorting
- * to multiple-precision integers.
- * 6. When asked to produce fewer than 15 digits, we first try
- * to get by with floating-point arithmetic; we resort to
- * multiple-precision integer arithmetic only if we cannot
- * guarantee that the floating-point calculation has given
- * the correctly rounded result. For k requested digits and
- * "uniformly" distributed input, the probability is
- * something like 10^(k-15) that we must resort to the Long
- * calculation.
+ * 1. Rather than iterating, we use a simple numeric overestimate
+ * to determine k = floor(log10(d)). We scale relevant
+ * quantities using O(log2(k)) rather than O(k) multiplications.
+ * 2. For some modes > 2 (corresponding to ecvt and fcvt), we don't
+ * try to generate digits strictly left to right. Instead, we
+ * compute with fewer bits and propagate the carry if necessary
+ * when rounding the final digit up. This is often faster.
+ * 3. Under the assumption that input will be rounded nearest,
+ * mode 0 renders 1e23 as 1e23 rather than 9.999999999999999e22.
+ * That is, we allow equality in stopping tests when the
+ * round-nearest rule will give the same floating-point value
+ * as would satisfaction of the stopping test with strict
+ * inequality.
+ * 4. We remove common factors of powers of 2 from relevant
+ * quantities.
+ * 5. When converting floating-point integers less than 1e16,
+ * we use floating-point arithmetic rather than resorting
+ * to multiple-precision integers.
+ * 6. When asked to produce fewer than 15 digits, we first try
+ * to get by with floating-point arithmetic; we resort to
+ * multiple-precision integer arithmetic only if we cannot
+ * guarantee that the floating-point calculation has given
+ * the correctly rounded result. For k requested digits and
+ * "uniformly" distributed input, the probability is
+ * something like 10^(k-15) that we must resort to the Long
+ * calculation.
*/
- static char *
+static char *
dtoa
#ifdef KR_headers
- (dd, mode, ndigits, decpt, sign, rve)
- double dd; int mode, ndigits, *decpt, *sign; char **rve;
+(dd, mode, ndigits, decpt, sign, rve)
+double dd; int mode, ndigits, *decpt, *sign; char **rve;
#else
- (double dd, int mode, int ndigits, int *decpt, int *sign, char **rve)
+(double dd, int mode, int ndigits, int *decpt, int *sign, char **rve)
#endif
{
- /* Arguments ndigits, decpt, sign are similar to those
- of ecvt and fcvt; trailing zeros are suppressed from
- the returned string. If not null, *rve is set to point
- to the end of the return value. If d is +-Infinity or NaN,
- then *decpt is set to 9999.
-
- mode:
- 0 ==> shortest string that yields d when read in
- and rounded to nearest.
- 1 ==> like 0, but with Steele & White stopping rule;
- e.g. with IEEE P754 arithmetic , mode 0 gives
- 1e23 whereas mode 1 gives 9.999999999999999e22.
- 2 ==> max(1,ndigits) significant digits. This gives a
- return value similar to that of ecvt, except
- that trailing zeros are suppressed.
- 3 ==> through ndigits past the decimal point. This
- gives a return value similar to that from fcvt,
- except that trailing zeros are suppressed, and
- ndigits can be negative.
- 4,5 ==> similar to 2 and 3, respectively, but (in
- round-nearest mode) with the tests of mode 0 to
- possibly return a shorter string that rounds to d.
- With IEEE arithmetic and compilation with
- -DHonor_FLT_ROUNDS, modes 4 and 5 behave the same
- as modes 2 and 3 when FLT_ROUNDS != 1.
- 6-9 ==> Debugging modes similar to mode - 4: don't try
- fast floating-point estimate (if applicable).
-
- Values of mode other than 0-9 are treated as mode 0.
-
- Sufficient space is allocated to the return value
- to hold the suppressed trailing zeros.
- */
-
- int bbits, b2, b5, be, dig, i, ieps, ilim, ilim0, ilim1,
- j, j1, k, k0, k_check, leftright, m2, m5, s2, s5,
- spec_case, try_quick;
- Long L;
+ /* Arguments ndigits, decpt, sign are similar to those
+ of ecvt and fcvt; trailing zeros are suppressed from
+ the returned string. If not null, *rve is set to point
+ to the end of the return value. If d is +-Infinity or NaN,
+ then *decpt is set to 9999.
+
+ mode:
+ 0 ==> shortest string that yields d when read in
+ and rounded to nearest.
+ 1 ==> like 0, but with Steele & White stopping rule;
+ e.g. with IEEE P754 arithmetic , mode 0 gives
+ 1e23 whereas mode 1 gives 9.999999999999999e22.
+ 2 ==> max(1,ndigits) significant digits. This gives a
+ return value similar to that of ecvt, except
+ that trailing zeros are suppressed.
+ 3 ==> through ndigits past the decimal point. This
+ gives a return value similar to that from fcvt,
+ except that trailing zeros are suppressed, and
+ ndigits can be negative.
+ 4,5 ==> similar to 2 and 3, respectively, but (in
+ round-nearest mode) with the tests of mode 0 to
+ possibly return a shorter string that rounds to d.
+ With IEEE arithmetic and compilation with
+ -DHonor_FLT_ROUNDS, modes 4 and 5 behave the same
+ as modes 2 and 3 when FLT_ROUNDS != 1.
+ 6-9 ==> Debugging modes similar to mode - 4: don't try
+ fast floating-point estimate (if applicable).
+
+ Values of mode other than 0-9 are treated as mode 0.
+
+ Sufficient space is allocated to the return value
+ to hold the suppressed trailing zeros.
+ */
+
+ int bbits, b2, b5, be, dig, i, ieps, ilim, ilim0, ilim1,
+ j, j1, k, k0, k_check, leftright, m2, m5, s2, s5,
+ spec_case, try_quick;
+ Long L;
#ifndef Sudden_Underflow
- int denorm;
- ULong x;
+ int denorm;
+ ULong x;
#endif
- Bigint *b, *b1, *delta, *mlo, *mhi, *S;
- U d, d2, eps;
- double ds;
- char *s, *s0;
+ Bigint *b, *b1, *delta, *mlo, *mhi, *S;
+ U d, d2, eps;
+ double ds;
+ char *s, *s0;
#ifdef Honor_FLT_ROUNDS
- int rounding;
+ int rounding;
#endif
#ifdef SET_INEXACT
- int inexact, oldinexact;
+ int inexact, oldinexact;
#endif
#ifndef MULTIPLE_THREADS
- if (dtoa_result) {
- freedtoa(dtoa_result);
- dtoa_result = 0;
- }
+ if (dtoa_result) {
+ freedtoa(dtoa_result);
+ dtoa_result = 0;
+ }
#endif
- dval(d) = dd;
- if (word0(d) & Sign_bit) {
- /* set sign for everything, including 0's and NaNs */
- *sign = 1;
- word0(d) &= ~Sign_bit; /* clear sign bit */
- }
- else
- *sign = 0;
+ dval(d) = dd;
+ if (word0(d) & Sign_bit) {
+ /* set sign for everything, including 0's and NaNs */
+ *sign = 1;
+ word0(d) &= ~Sign_bit; /* clear sign bit */
+ }
+ else {
+ *sign = 0;
+ }
#if defined(IEEE_Arith) + defined(VAX)
#ifdef IEEE_Arith
- if ((word0(d) & Exp_mask) == Exp_mask)
+ if ((word0(d) & Exp_mask) == Exp_mask)
#else
- if (word0(d) == 0x8000)
+ if (word0(d) == 0x8000)
#endif
- {
- /* Infinity or NaN */
- *decpt = 9999;
+ {
+ /* Infinity or NaN */
+ *decpt = 9999;
#ifdef IEEE_Arith
- if (!word1(d) && !(word0(d) & 0xfffff))
- return nrv_alloc("Infinity", rve, 8);
+ if (!word1(d) && !(word0(d) & 0xfffff)) {
+ return nrv_alloc("Infinity", rve, 8);
+ }
#endif
- return nrv_alloc("NaN", rve, 3);
- }
+ return nrv_alloc("NaN", rve, 3);
+ }
#endif
#ifdef IBM
- dval(d) += 0; /* normalize */
+ dval(d) += 0; /* normalize */
#endif
- if (!dval(d)) {
- *decpt = 1;
- return nrv_alloc("0", rve, 1);
- }
+ if (!dval(d)) {
+ *decpt = 1;
+ return nrv_alloc("0", rve, 1);
+ }
#ifdef SET_INEXACT
- try_quick = oldinexact = get_inexact();
- inexact = 1;
+ try_quick = oldinexact = get_inexact();
+ inexact = 1;
#endif
#ifdef Honor_FLT_ROUNDS
- if ((rounding = Flt_Rounds) >= 2) {
- if (*sign)
- rounding = rounding == 2 ? 0 : 2;
- else
- if (rounding != 2)
- rounding = 0;
- }
+ if ((rounding = Flt_Rounds) >= 2) {
+ if (*sign) {
+ rounding = rounding == 2 ? 0 : 2;
+ }
+ else if (rounding != 2) {
+ rounding = 0;
+ }
+ }
#endif
- b = d2b(dval(d), &be, &bbits);
+ b = d2b(dval(d), &be, &bbits);
#ifdef Sudden_Underflow
- i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1));
+ i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1));
#else
- if (i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1))) {
+ if (i = (int)(word0(d) >> Exp_shift1 & (Exp_mask>>Exp_shift1))) {
#endif
- dval(d2) = dval(d);
- word0(d2) &= Frac_mask1;
- word0(d2) |= Exp_11;
+ dval(d2) = dval(d);
+ word0(d2) &= Frac_mask1;
+ word0(d2) |= Exp_11;
#ifdef IBM
- if (j = 11 - hi0bits(word0(d2) & Frac_mask))
- dval(d2) /= 1 << j;
-#endif
-
- /* log(x) ~=~ log(1.5) + (x-1.5)/1.5
- * log10(x) = log(x) / log(10)
- * ~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10))
- * log10(d) = (i-Bias)*log(2)/log(10) + log10(d2)
- *
- * This suggests computing an approximation k to log10(d) by
- *
- * k = (i - Bias)*0.301029995663981
- * + ( (d2-1.5)*0.289529654602168 + 0.176091259055681 );
- *
- * We want k to be too large rather than too small.
- * The error in the first-order Taylor series approximation
- * is in our favor, so we just round up the constant enough
- * to compensate for any error in the multiplication of
- * (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077,
- * and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14,
- * adding 1e-13 to the constant term more than suffices.
- * Hence we adjust the constant term to 0.1760912590558.
- * (We could get a more accurate k by invoking log10,
- * but this is probably not worthwhile.)
- */
-
- i -= Bias;
+ if (j = 11 - hi0bits(word0(d2) & Frac_mask)) {
+ dval(d2) /= 1 << j;
+ }
+#endif
+
+ /* log(x) ~=~ log(1.5) + (x-1.5)/1.5
+ * log10(x) = log(x) / log(10)
+ * ~=~ log(1.5)/log(10) + (x-1.5)/(1.5*log(10))
+ * log10(d) = (i-Bias)*log(2)/log(10) + log10(d2)
+ *
+ * This suggests computing an approximation k to log10(d) by
+ *
+ * k = (i - Bias)*0.301029995663981
+ * + ( (d2-1.5)*0.289529654602168 + 0.176091259055681 );
+ *
+ * We want k to be too large rather than too small.
+ * The error in the first-order Taylor series approximation
+ * is in our favor, so we just round up the constant enough
+ * to compensate for any error in the multiplication of
+ * (i - Bias) by 0.301029995663981; since |i - Bias| <= 1077,
+ * and 1077 * 0.30103 * 2^-52 ~=~ 7.2e-14,
+ * adding 1e-13 to the constant term more than suffices.
+ * Hence we adjust the constant term to 0.1760912590558.
+ * (We could get a more accurate k by invoking log10,
+ * but this is probably not worthwhile.)
+ */
+
+ i -= Bias;
#ifdef IBM
- i <<= 2;
- i += j;
+ i <<= 2;
+ i += j;
#endif
#ifndef Sudden_Underflow
- denorm = 0;
- }
- else {
- /* d is denormalized */
-
- i = bbits + be + (Bias + (P-1) - 1);
- x = i > 32 ? word0(d) << 64 - i | word1(d) >> i - 32
- : word1(d) << 32 - i;
- dval(d2) = x;
- word0(d2) -= 31*Exp_msk1; /* adjust exponent */
- i -= (Bias + (P-1) - 1) + 1;
- denorm = 1;
- }
-#endif
- ds = (dval(d2)-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981;
- k = (int)ds;
- if (ds < 0. && ds != k)
- k--; /* want k = floor(ds) */
- k_check = 1;
- if (k >= 0 && k <= Ten_pmax) {
- if (dval(d) < tens[k])
- k--;
- k_check = 0;
- }
- j = bbits - i - 1;
- if (j >= 0) {
- b2 = 0;
- s2 = j;
- }
- else {
- b2 = -j;
- s2 = 0;
- }
- if (k >= 0) {
- b5 = 0;
- s5 = k;
- s2 += k;
- }
- else {
- b2 -= k;
- b5 = -k;
- s5 = 0;
- }
- if (mode < 0 || mode > 9)
- mode = 0;
+ denorm = 0;
+}
+else {
+ /* d is denormalized */
+
+ i = bbits + be + (Bias + (P-1) - 1);
+ x = i > 32 ? word0(d) << 64 - i | word1(d) >> i - 32
+ : word1(d) << 32 - i;
+ dval(d2) = x;
+ word0(d2) -= 31*Exp_msk1; /* adjust exponent */
+ i -= (Bias + (P-1) - 1) + 1;
+ denorm = 1;
+}
+#endif
+ds = (dval(d2)-1.5)*0.289529654602168 + 0.1760912590558 + i*0.301029995663981;
+k = (int)ds;
+if (ds < 0. && ds != k) {
+ k--; /* want k = floor(ds) */
+}
+k_check = 1;
+if (k >= 0 && k <= Ten_pmax) {
+ if (dval(d) < tens[k]) {
+ k--;
+ }
+ k_check = 0;
+}
+j = bbits - i - 1;
+if (j >= 0) {
+ b2 = 0;
+ s2 = j;
+}
+else {
+ b2 = -j;
+ s2 = 0;
+}
+if (k >= 0) {
+ b5 = 0;
+ s5 = k;
+ s2 += k;
+}
+else {
+ b2 -= k;
+ b5 = -k;
+ s5 = 0;
+}
+if (mode < 0 || mode > 9) {
+ mode = 0;
+}
#ifndef SET_INEXACT
#ifdef Check_FLT_ROUNDS
- try_quick = Rounding == 1;
+try_quick = Rounding == 1;
#else
- try_quick = 1;
+try_quick = 1;
#endif
#endif /*SET_INEXACT*/
- if (mode > 5) {
- mode -= 4;
- try_quick = 0;
- }
- leftright = 1;
- switch(mode) {
- case 0:
- case 1:
- ilim = ilim1 = -1;
- i = 18;
- ndigits = 0;
- break;
- case 2:
- leftright = 0;
- /* no break */
- case 4:
- if (ndigits <= 0)
- ndigits = 1;
- ilim = ilim1 = i = ndigits;
- break;
- case 3:
- leftright = 0;
- /* no break */
- case 5:
- i = ndigits + k + 1;
- ilim = i;
- ilim1 = i - 1;
- if (i <= 0)
- i = 1;
- }
- s = s0 = rv_alloc(i);
+if (mode > 5) {
+ mode -= 4;
+ try_quick = 0;
+}
+leftright = 1;
+switch(mode) {
+case 0:
+case 1:
+ ilim = ilim1 = -1;
+ i = 18;
+ ndigits = 0;
+ break;
+case 2:
+ leftright = 0;
+/* no break */
+case 4:
+ if (ndigits <= 0) {
+ ndigits = 1;
+ }
+ ilim = ilim1 = i = ndigits;
+ break;
+case 3:
+ leftright = 0;
+/* no break */
+case 5:
+ i = ndigits + k + 1;
+ ilim = i;
+ ilim1 = i - 1;
+ if (i <= 0) {
+ i = 1;
+ }
+}
+s = s0 = rv_alloc(i);
#ifdef Honor_FLT_ROUNDS
- if (mode > 1 && rounding != 1)
- leftright = 0;
-#endif
-
- if (ilim >= 0 && ilim <= Quick_max && try_quick) {
-
- /* Try to get by with floating-point arithmetic. */
-
- i = 0;
- dval(d2) = dval(d);
- k0 = k;
- ilim0 = ilim;
- ieps = 2; /* conservative */
- if (k > 0) {
- ds = tens[k&0xf];
- j = k >> 4;
- if (j & Bletch) {
- /* prevent overflows */
- j &= Bletch - 1;
- dval(d) /= bigtens[n_bigtens-1];
- ieps++;
- }
- for(; j; j >>= 1, i++)
- if (j & 1) {
- ieps++;
- ds *= bigtens[i];
- }
- dval(d) /= ds;
- }
- else if (j1 = -k) {
- dval(d) *= tens[j1 & 0xf];
- for(j = j1 >> 4; j; j >>= 1, i++)
- if (j & 1) {
- ieps++;
- dval(d) *= bigtens[i];
- }
- }
- if (k_check && dval(d) < 1. && ilim > 0) {
- if (ilim1 <= 0)
- goto fast_failed;
- ilim = ilim1;
- k--;
- dval(d) *= 10.;
- ieps++;
- }
- dval(eps) = ieps*dval(d) + 7.;
- word0(eps) -= (P-1)*Exp_msk1;
- if (ilim == 0) {
- S = mhi = 0;
- dval(d) -= 5.;
- if (dval(d) > dval(eps))
- goto one_digit;
- if (dval(d) < -dval(eps))
- goto no_digits;
- goto fast_failed;
- }
+if (mode > 1 && rounding != 1) {
+ leftright = 0;
+}
+#endif
+
+if (ilim >= 0 && ilim <= Quick_max && try_quick) {
+
+ /* Try to get by with floating-point arithmetic. */
+
+ i = 0;
+ dval(d2) = dval(d);
+ k0 = k;
+ ilim0 = ilim;
+ ieps = 2; /* conservative */
+ if (k > 0) {
+ ds = tens[k&0xf];
+ j = k >> 4;
+ if (j & Bletch) {
+ /* prevent overflows */
+ j &= Bletch - 1;
+ dval(d) /= bigtens[n_bigtens-1];
+ ieps++;
+ }
+ for(; j; j >>= 1, i++)
+ if (j & 1) {
+ ieps++;
+ ds *= bigtens[i];
+ }
+ dval(d) /= ds;
+ }
+ else if (j1 = -k) {
+ dval(d) *= tens[j1 & 0xf];
+ for(j = j1 >> 4; j; j >>= 1, i++)
+ if (j & 1) {
+ ieps++;
+ dval(d) *= bigtens[i];
+ }
+ }
+ if (k_check && dval(d) < 1. && ilim > 0) {
+ if (ilim1 <= 0) {
+ goto fast_failed;
+ }
+ ilim = ilim1;
+ k--;
+ dval(d) *= 10.;
+ ieps++;
+ }
+ dval(eps) = ieps*dval(d) + 7.;
+ word0(eps) -= (P-1)*Exp_msk1;
+ if (ilim == 0) {
+ S = mhi = 0;
+ dval(d) -= 5.;
+ if (dval(d) > dval(eps)) {
+ goto one_digit;
+ }
+ if (dval(d) < -dval(eps)) {
+ goto no_digits;
+ }
+ goto fast_failed;
+ }
#ifndef No_leftright
- if (leftright) {
- /* Use Steele & White method of only
- * generating digits needed.
- */
- dval(eps) = 0.5/tens[ilim-1] - dval(eps);
- for(i = 0;;) {
- L = dval(d);
- dval(d) -= L;
- *s++ = '0' + (int)L;
- if (dval(d) < dval(eps))
- goto ret1;
- if (1. - dval(d) < dval(eps))
- goto bump_up;
- if (++i >= ilim)
- break;
- dval(eps) *= 10.;
- dval(d) *= 10.;
- }
- }
- else {
-#endif
- /* Generate ilim digits, then fix them up. */
- dval(eps) *= tens[ilim-1];
- for(i = 1;; i++, dval(d) *= 10.) {
- L = (Long)(dval(d));
- if (!(dval(d) -= L))
- ilim = i;
- *s++ = '0' + (int)L;
- if (i == ilim) {
- if (dval(d) > 0.5 + dval(eps))
- goto bump_up;
- else if (dval(d) < 0.5 - dval(eps)) {
- while(*--s == '0');
- s++;
- goto ret1;
- }
- break;
- }
- }
+ if (leftright) {
+ /* Use Steele & White method of only
+ * generating digits needed.
+ */
+ dval(eps) = 0.5/tens[ilim-1] - dval(eps);
+ for(i = 0;;) {
+ L = dval(d);
+ dval(d) -= L;
+ *s++ = '0' + (int)L;
+ if (dval(d) < dval(eps)) {
+ goto ret1;
+ }
+ if (1. - dval(d) < dval(eps)) {
+ goto bump_up;
+ }
+ if (++i >= ilim) {
+ break;
+ }
+ dval(eps) *= 10.;
+ dval(d) *= 10.;
+ }
+ }
+ else {
+#endif
+ /* Generate ilim digits, then fix them up. */
+ dval(eps) *= tens[ilim-1];
+ for(i = 1;; i++, dval(d) *= 10.) {
+ L = (Long)(dval(d));
+ if (!(dval(d) -= L)) {
+ ilim = i;
+ }
+ *s++ = '0' + (int)L;
+ if (i == ilim) {
+ if (dval(d) > 0.5 + dval(eps)) {
+ goto bump_up;
+ }
+ else if (dval(d) < 0.5 - dval(eps)) {
+ while(*--s == '0');
+ s++;
+ goto ret1;
+ }
+ break;
+ }
+ }
#ifndef No_leftright
- }
-#endif
- fast_failed:
- s = s0;
- dval(d) = dval(d2);
- k = k0;
- ilim = ilim0;
- }
-
- /* Do we have a "small" integer? */
-
- if (be >= 0 && k <= Int_max) {
- /* Yes. */
- ds = tens[k];
- if (ndigits < 0 && ilim <= 0) {
- S = mhi = 0;
- if (ilim < 0 || dval(d) <= 5*ds)
- goto no_digits;
- goto one_digit;
- }
- for(i = 1; i <= k+1; i++, dval(d) *= 10.) {
- L = (Long)(dval(d) / ds);
- dval(d) -= L*ds;
+ }
+#endif
+fast_failed:
+ s = s0;
+ dval(d) = dval(d2);
+ k = k0;
+ ilim = ilim0;
+}
+
+/* Do we have a "small" integer? */
+
+if (be >= 0 && k <= Int_max) {
+ /* Yes. */
+ ds = tens[k];
+ if (ndigits < 0 && ilim <= 0) {
+ S = mhi = 0;
+ if (ilim < 0 || dval(d) <= 5*ds) {
+ goto no_digits;
+ }
+ goto one_digit;
+ }
+ for(i = 1; i <= k+1; i++, dval(d) *= 10.) {
+ L = (Long)(dval(d) / ds);
+ dval(d) -= L*ds;
#ifdef Check_FLT_ROUNDS
- /* If FLT_ROUNDS == 2, L will usually be high by 1 */
- if (dval(d) < 0) {
- L--;
- dval(d) += ds;
- }
-#endif
- *s++ = '0' + (int)L;
- if (!dval(d)) {
+ /* If FLT_ROUNDS == 2, L will usually be high by 1 */
+ if (dval(d) < 0) {
+ L--;
+ dval(d) += ds;
+ }
+#endif
+ *s++ = '0' + (int)L;
+ if (!dval(d)) {
#ifdef SET_INEXACT
- inexact = 0;
+ inexact = 0;
#endif
- break;
- }
- if (i == ilim) {
+ break;
+ }
+ if (i == ilim) {
#ifdef Honor_FLT_ROUNDS
- if (mode > 1)
- switch(rounding) {
- case 0: goto ret1;
- case 2: goto bump_up;
- }
-#endif
- dval(d) += dval(d);
- if (dval(d) > ds || dval(d) == ds && L & 1) {
- bump_up:
- while(*--s == '9')
- if (s == s0) {
- k++;
- *s = '0';
- break;
- }
- ++*s++;
- }
- break;
- }
- }
- goto ret1;
- }
-
- m2 = b2;
- m5 = b5;
- mhi = mlo = 0;
- if (leftright) {
- i =
+ if (mode > 1)
+ switch(rounding) {
+ case 0: goto ret1;
+ case 2: goto bump_up;
+ }
+#endif
+ dval(d) += dval(d);
+ if (dval(d) > ds || dval(d) == ds && L & 1) {
+bump_up:
+ while(*--s == '9')
+ if (s == s0) {
+ k++;
+ *s = '0';
+ break;
+ }
+ ++*s++;
+ }
+ break;
+ }
+ }
+ goto ret1;
+}
+
+m2 = b2;
+m5 = b5;
+mhi = mlo = 0;
+if (leftright) {
+ i =
#ifndef Sudden_Underflow
- denorm ? be + (Bias + (P-1) - 1 + 1) :
+ denorm ? be + (Bias + (P-1) - 1 + 1) :
#endif
#ifdef IBM
- 1 + 4*P - 3 - bbits + ((bbits + be - 1) & 3);
-#else
- 1 + P - bbits;
-#endif
- b2 += i;
- s2 += i;
- mhi = i2b(1);
- }
- if (m2 > 0 && s2 > 0) {
- i = m2 < s2 ? m2 : s2;
- b2 -= i;
- m2 -= i;
- s2 -= i;
- }
- if (b5 > 0) {
- if (leftright) {
- if (m5 > 0) {
- mhi = pow5mult(mhi, m5);
- b1 = mult(mhi, b);
- Bfree(b);
- b = b1;
- }
- if (j = b5 - m5)
- b = pow5mult(b, j);
- }
- else
- b = pow5mult(b, b5);
- }
- S = i2b(1);
- if (s5 > 0)
- S = pow5mult(S, s5);
-
- /* Check for special case that d is a normalized power of 2. */
-
- spec_case = 0;
- if ((mode < 2 || leftright)
+ 1 + 4*P - 3 - bbits + ((bbits + be - 1) & 3);
+#else
+ 1 + P - bbits;
+#endif
+ b2 += i;
+ s2 += i;
+ mhi = i2b(1);
+}
+if (m2 > 0 && s2 > 0) {
+ i = m2 < s2 ? m2 : s2;
+ b2 -= i;
+ m2 -= i;
+ s2 -= i;
+}
+if (b5 > 0) {
+ if (leftright) {
+ if (m5 > 0) {
+ mhi = pow5mult(mhi, m5);
+ b1 = mult(mhi, b);
+ Bfree(b);
+ b = b1;
+ }
+ if (j = b5 - m5) {
+ b = pow5mult(b, j);
+ }
+ }
+ else {
+ b = pow5mult(b, b5);
+ }
+}
+S = i2b(1);
+if (s5 > 0) {
+ S = pow5mult(S, s5);
+}
+
+/* Check for special case that d is a normalized power of 2. */
+
+spec_case = 0;
+if ((mode < 2 || leftright)
#ifdef Honor_FLT_ROUNDS
- && rounding == 1
+ && rounding == 1
#endif
- ) {
- if (!word1(d) && !(word0(d) & Bndry_mask)
+ ) {
+ if (!word1(d) && !(word0(d) & Bndry_mask)
#ifndef Sudden_Underflow
- && word0(d) & (Exp_mask & ~Exp_msk1)
-#endif
- ) {
- /* The special case */
- b2 += Log2P;
- s2 += Log2P;
- spec_case = 1;
- }
- }
-
- /* Arrange for convenient computation of quotients:
- * shift left if necessary so divisor has 4 leading 0 bits.
- *
- * Perhaps we should just compute leading 28 bits of S once
- * and for all and pass them and a shift to quorem, so it
- * can do shifts and ors to compute the numerator for q.
- */
+ && word0(d) & (Exp_mask & ~Exp_msk1)
+#endif
+ ) {
+ /* The special case */
+ b2 += Log2P;
+ s2 += Log2P;
+ spec_case = 1;
+ }
+}
+
+/* Arrange for convenient computation of quotients:
+ * shift left if necessary so divisor has 4 leading 0 bits.
+ *
+ * Perhaps we should just compute leading 28 bits of S once
+ * and for all and pass them and a shift to quorem, so it
+ * can do shifts and ors to compute the numerator for q.
+ */
#ifdef Pack_32
- if (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0x1f)
- i = 32 - i;
-#else
- if (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0xf)
- i = 16 - i;
-#endif
- if (i > 4) {
- i -= 4;
- b2 += i;
- m2 += i;
- s2 += i;
- }
- else if (i < 4) {
- i += 28;
- b2 += i;
- m2 += i;
- s2 += i;
- }
- if (b2 > 0)
- b = lshift(b, b2);
- if (s2 > 0)
- S = lshift(S, s2);
- if (k_check) {
- if (cmp(b,S) < 0) {
- k--;
- b = multadd(b, 10, 0); /* we botched the k estimate */
- if (leftright)
- mhi = multadd(mhi, 10, 0);
- ilim = ilim1;
- }
- }
- if (ilim <= 0 && (mode == 3 || mode == 5)) {
- if (ilim < 0 || cmp(b,S = multadd(S,5,0)) <= 0) {
- /* no digits, fcvt style */
- no_digits:
- k = -1 - ndigits;
- goto ret;
- }
- one_digit:
- *s++ = '1';
- k++;
- goto ret;
- }
- if (leftright) {
- if (m2 > 0)
- mhi = lshift(mhi, m2);
-
- /* Compute mlo -- check for special case
- * that d is a normalized power of 2.
- */
-
- mlo = mhi;
- if (spec_case) {
- mhi = Balloc(mhi->k);
- Bcopy(mhi, mlo);
- mhi = lshift(mhi, Log2P);
- }
-
- for(i = 1;;i++) {
- dig = quorem(b,S) + '0';
- /* Do we yet have the shortest decimal string
- * that will round to d?
- */
- j = cmp(b, mlo);
- delta = diff(S, mhi);
- j1 = delta->sign ? 1 : cmp(b, delta);
- Bfree(delta);
+if (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0x1f) {
+ i = 32 - i;
+}
+#else
+if (i = ((s5 ? 32 - hi0bits(S->x[S->wds-1]) : 1) + s2) & 0xf) {
+ i = 16 - i;
+}
+#endif
+if (i > 4) {
+ i -= 4;
+ b2 += i;
+ m2 += i;
+ s2 += i;
+}
+else if (i < 4) {
+ i += 28;
+ b2 += i;
+ m2 += i;
+ s2 += i;
+}
+if (b2 > 0) {
+ b = lshift(b, b2);
+}
+if (s2 > 0) {
+ S = lshift(S, s2);
+}
+if (k_check) {
+ if (cmp(b,S) < 0) {
+ k--;
+ b = multadd(b, 10, 0); /* we botched the k estimate */
+ if (leftright) {
+ mhi = multadd(mhi, 10, 0);
+ }
+ ilim = ilim1;
+ }
+}
+if (ilim <= 0 && (mode == 3 || mode == 5)) {
+ if (ilim < 0 || cmp(b,S = multadd(S,5,0)) <= 0) {
+ /* no digits, fcvt style */
+no_digits:
+ k = -1 - ndigits;
+ goto ret;
+ }
+one_digit:
+ *s++ = '1';
+ k++;
+ goto ret;
+}
+if (leftright) {
+ if (m2 > 0) {
+ mhi = lshift(mhi, m2);
+ }
+
+ /* Compute mlo -- check for special case
+ * that d is a normalized power of 2.
+ */
+
+ mlo = mhi;
+ if (spec_case) {
+ mhi = Balloc(mhi->k);
+ Bcopy(mhi, mlo);
+ mhi = lshift(mhi, Log2P);
+ }
+
+ for(i = 1;; i++) {
+ dig = quorem(b,S) + '0';
+ /* Do we yet have the shortest decimal string
+ * that will round to d?
+ */
+ j = cmp(b, mlo);
+ delta = diff(S, mhi);
+ j1 = delta->sign ? 1 : cmp(b, delta);
+ Bfree(delta);
#ifndef ROUND_BIASED
- if (j1 == 0 && mode != 1 && !(word1(d) & 1)
+ if (j1 == 0 && mode != 1 && !(word1(d) & 1)
#ifdef Honor_FLT_ROUNDS
- && rounding >= 1
+ && rounding >= 1
#endif
- ) {
- if (dig == '9')
- goto round_9_up;
- if (j > 0)
- dig++;
+ ) {
+ if (dig == '9') {
+ goto round_9_up;
+ }
+ if (j > 0) {
+ dig++;
+ }
#ifdef SET_INEXACT
- else if (!b->x[0] && b->wds <= 1)
- inexact = 0;
+ else if (!b->x[0] && b->wds <= 1) {
+ inexact = 0;
+ }
#endif
- *s++ = dig;
- goto ret;
- }
+ *s++ = dig;
+ goto ret;
+ }
#endif
- if (j < 0 || j == 0 && mode != 1
+ if (j < 0 || j == 0 && mode != 1
#ifndef ROUND_BIASED
- && !(word1(d) & 1)
+ && !(word1(d) & 1)
#endif
- ) {
- if (!b->x[0] && b->wds <= 1) {
+ ) {
+ if (!b->x[0] && b->wds <= 1) {
#ifdef SET_INEXACT
- inexact = 0;
+ inexact = 0;
#endif
- goto accept_dig;
- }
+ goto accept_dig;
+ }
#ifdef Honor_FLT_ROUNDS
- if (mode > 1)
- switch(rounding) {
- case 0: goto accept_dig;
- case 2: goto keep_dig;
- }
+ if (mode > 1)
+ switch(rounding) {
+ case 0: goto accept_dig;
+ case 2: goto keep_dig;
+ }
#endif /*Honor_FLT_ROUNDS*/
- if (j1 > 0) {
- b = lshift(b, 1);
- j1 = cmp(b, S);
- if ((j1 > 0 || j1 == 0 && dig & 1)
- && dig++ == '9')
- goto round_9_up;
- }
- accept_dig:
- *s++ = dig;
- goto ret;
- }
- if (j1 > 0) {
+ if (j1 > 0) {
+ b = lshift(b, 1);
+ j1 = cmp(b, S);
+ if ((j1 > 0 || j1 == 0 && dig & 1)
+ && dig++ == '9') {
+ goto round_9_up;
+ }
+ }
+accept_dig:
+ *s++ = dig;
+ goto ret;
+ }
+ if (j1 > 0) {
#ifdef Honor_FLT_ROUNDS
- if (!rounding)
- goto accept_dig;
-#endif
- if (dig == '9') { /* possible if i == 1 */
- round_9_up:
- *s++ = '9';
- goto roundoff;
- }
- *s++ = dig + 1;
- goto ret;
- }
+ if (!rounding) {
+ goto accept_dig;
+ }
+#endif
+ if (dig == '9') { /* possible if i == 1 */
+round_9_up:
+ *s++ = '9';
+ goto roundoff;
+ }
+ *s++ = dig + 1;
+ goto ret;
+ }
#ifdef Honor_FLT_ROUNDS
- keep_dig:
-#endif
- *s++ = dig;
- if (i == ilim)
- break;
- b = multadd(b, 10, 0);
- if (mlo == mhi)
- mlo = mhi = multadd(mhi, 10, 0);
- else {
- mlo = multadd(mlo, 10, 0);
- mhi = multadd(mhi, 10, 0);
- }
- }
- }
- else
- for(i = 1;; i++) {
- *s++ = dig = quorem(b,S) + '0';
- if (!b->x[0] && b->wds <= 1) {
+keep_dig:
+#endif
+ *s++ = dig;
+ if (i == ilim) {
+ break;
+ }
+ b = multadd(b, 10, 0);
+ if (mlo == mhi) {
+ mlo = mhi = multadd(mhi, 10, 0);
+ }
+ else {
+ mlo = multadd(mlo, 10, 0);
+ mhi = multadd(mhi, 10, 0);
+ }
+ }
+}
+else
+ for(i = 1;; i++) {
+ *s++ = dig = quorem(b,S) + '0';
+ if (!b->x[0] && b->wds <= 1) {
#ifdef SET_INEXACT
- inexact = 0;
+ inexact = 0;
#endif
- goto ret;
- }
- if (i >= ilim)
- break;
- b = multadd(b, 10, 0);
- }
+ goto ret;
+ }
+ if (i >= ilim) {
+ break;
+ }
+ b = multadd(b, 10, 0);
+ }
- /* Round off last digit */
+/* Round off last digit */
#ifdef Honor_FLT_ROUNDS
- switch(rounding) {
- case 0: goto trimzeros;
- case 2: goto roundoff;
- }
-#endif
- b = lshift(b, 1);
- j = cmp(b, S);
- if (j > 0 || j == 0 && dig & 1) {
- roundoff:
- while(*--s == '9')
- if (s == s0) {
- k++;
- *s++ = '1';
- goto ret;
- }
- ++*s++;
- }
- else {
+switch(rounding) {
+case 0: goto trimzeros;
+case 2: goto roundoff;
+}
+#endif
+b = lshift(b, 1);
+j = cmp(b, S);
+if (j > 0 || j == 0 && dig & 1) {
+roundoff:
+ while(*--s == '9')
+ if (s == s0) {
+ k++;
+ *s++ = '1';
+ goto ret;
+ }
+ ++*s++;
+}
+else {
#ifdef Honor_FLT_ROUNDS
- trimzeros:
-#endif
- while(*--s == '0');
- s++;
- }
- ret:
- Bfree(S);
- if (mhi) {
- if (mlo && mlo != mhi)
- Bfree(mlo);
- Bfree(mhi);
- }
- ret1:
+trimzeros:
+#endif
+ while(*--s == '0');
+ s++;
+}
+ret:
+Bfree(S);
+if (mhi) {
+ if (mlo && mlo != mhi) {
+ Bfree(mlo);
+ }
+ Bfree(mhi);
+}
+ret1:
#ifdef SET_INEXACT
- if (inexact) {
- if (!oldinexact) {
- word0(d) = Exp_1 + (70 << Exp_shift);
- word1(d) = 0;
- dval(d) += 1.;
- }
- }
- else if (!oldinexact)
- clear_inexact();
-#endif
- Bfree(b);
- *s = 0;
- *decpt = k + 1;
- if (rve)
- *rve = s;
- return s0;
- }
+if (inexact) {
+ if (!oldinexact) {
+ word0(d) = Exp_1 + (70 << Exp_shift);
+ word1(d) = 0;
+ dval(d) += 1.;
+ }
+}
+else if (!oldinexact) {
+ clear_inexact();
+}
+#endif
+Bfree(b);
+*s = 0;
+*decpt = k + 1;
+if (rve) {
+ *rve = s;
+}
+return s0;
+}
#ifdef __cplusplus
}
#endif
PR_IMPLEMENT(PRStatus)
PR_dtoa(PRFloat64 d, PRIntn mode, PRIntn ndigits,
- PRIntn *decpt, PRIntn *sign, char **rve, char *buf, PRSize bufsize)
+ PRIntn *decpt, PRIntn *sign, char **rve, char *buf, PRSize bufsize)
{
char *result;
PRSize resultlen;
PRStatus rv = PR_FAILURE;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
if (mode < 0 || mode > 3) {
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
@@ -3424,7 +3610,7 @@ PR_dtoa(PRFloat64 d, PRIntn mode, PRIntn ndigits,
rv = PR_SUCCESS;
}
freedtoa(result);
- return rv;
+ return rv;
}
/*
@@ -3432,7 +3618,7 @@ PR_dtoa(PRFloat64 d, PRIntn mode, PRIntn ndigits,
** prcsn - number of digits of precision to generate floating
** point value.
** This should be reparameterized so that you can send in a
-** prcn for the positive and negative ranges. For now,
+** prcn for the positive and negative ranges. For now,
** conform to the ECMA JavaScript spec which says numbers
** less than 1e-6 are in scientific notation.
** Also, the ECMA spec says that there should always be a
@@ -3456,7 +3642,7 @@ PR_cnvtf(char *buf, int bufsz, int prcsn, double dfval)
}
/* XXX Why use mode 1? */
if (PR_dtoa(dval(fval),1,prcsn,&decpt,&sign,&endnum,num,bufsz)
- == PR_FAILURE) {
+ == PR_FAILURE) {
buf[0] = '\0';
goto done;
}
diff --git a/nsprpub/pr/src/misc/prenv.c b/nsprpub/pr/src/misc/prenv.c
index cc2e198b9..b057a1c89 100644
--- a/nsprpub/pr/src/misc/prenv.c
+++ b/nsprpub/pr/src/misc/prenv.c
@@ -50,7 +50,7 @@ static PRLock *_pr_envLock = NULL;
void _PR_InitEnv(void)
{
- _PR_NEW_LOCK_ENV();
+ _PR_NEW_LOCK_ENV();
}
void _PR_CleanupEnv(void)
@@ -62,7 +62,9 @@ PR_IMPLEMENT(char*) PR_GetEnv(const char *var)
{
char *ev;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
_PR_LOCK_ENV();
ev = _PR_MD_GET_ENV(var);
@@ -73,28 +75,30 @@ PR_IMPLEMENT(char*) PR_GetEnv(const char *var)
PR_IMPLEMENT(char*) PR_GetEnvSecure(const char *var)
{
#ifdef HAVE_SECURE_GETENV
- char *ev;
+ char *ev;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
- _PR_LOCK_ENV();
- ev = secure_getenv(var);
- _PR_UNLOCK_ENV();
+ _PR_LOCK_ENV();
+ ev = secure_getenv(var);
+ _PR_UNLOCK_ENV();
- return ev;
+ return ev;
#else
#ifdef XP_UNIX
- /*
- ** Fall back to checking uids and gids. This won't detect any other
- ** privilege-granting mechanisms the platform may have. This also
- ** can't detect the case where the process already called
- ** setuid(geteuid()) and/or setgid(getegid()).
- */
- if (getuid() != geteuid() || getgid() != getegid()) {
- return NULL;
- }
+ /*
+ ** Fall back to checking uids and gids. This won't detect any other
+ ** privilege-granting mechanisms the platform may have. This also
+ ** can't detect the case where the process already called
+ ** setuid(geteuid()) and/or setgid(getegid()).
+ */
+ if (getuid() != geteuid() || getgid() != getegid()) {
+ return NULL;
+ }
#endif /* XP_UNIX */
- return PR_GetEnv(var);
+ return PR_GetEnv(var);
#endif /* HAVE_SECURE_GETENV */
}
@@ -102,9 +106,13 @@ PR_IMPLEMENT(PRStatus) PR_SetEnv(const char *string)
{
PRIntn result;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
- if (!strchr(string, '=')) return(PR_FAILURE);
+ if (!strchr(string, '=')) {
+ return(PR_FAILURE);
+ }
_PR_LOCK_ENV();
result = _PR_MD_PUT_ENV((char*)string);
@@ -135,21 +143,21 @@ PR_IMPLEMENT(char **) PR_DuplicateEnvironment(void)
len = strlen(*src) + 1;
*dst = PR_Malloc(len);
if (*dst == NULL) {
- /* Allocation failed. Must clean up the half-copied env. */
- char **to_delete;
-
- for (to_delete = result; to_delete != dst; to_delete++) {
- PR_Free(*to_delete);
- }
- PR_Free(result);
- result = NULL;
- goto out;
+ /* Allocation failed. Must clean up the half-copied env. */
+ char **to_delete;
+
+ for (to_delete = result; to_delete != dst; to_delete++) {
+ PR_Free(*to_delete);
+ }
+ PR_Free(result);
+ result = NULL;
+ goto out;
}
memcpy(*dst, *src, len);
}
*dst = NULL;
}
- out:
+out:
_PR_UNLOCK_ENV();
return result;
}
diff --git a/nsprpub/pr/src/misc/prerr.c b/nsprpub/pr/src/misc/prerr.c
index bc78c8fbf..99cf39f8c 100644
--- a/nsprpub/pr/src/misc/prerr.c
+++ b/nsprpub/pr/src/misc/prerr.c
@@ -10,84 +10,84 @@
*/
#include "prerror.h"
static const struct PRErrorMessage text[] = {
- {"PR_OUT_OF_MEMORY_ERROR", "Memory allocation attempt failed"},
- {"PR_BAD_DESCRIPTOR_ERROR", "Invalid file descriptor"},
- {"PR_WOULD_BLOCK_ERROR", "The operation would have blocked"},
- {"PR_ACCESS_FAULT_ERROR", "Invalid memory address argument"},
- {"PR_INVALID_METHOD_ERROR", "Invalid function for file type"},
- {"PR_ILLEGAL_ACCESS_ERROR", "Invalid memory address argument"},
- {"PR_UNKNOWN_ERROR", "Some unknown error has occurred"},
- {"PR_PENDING_INTERRUPT_ERROR", "Operation interrupted by another thread"},
- {"PR_NOT_IMPLEMENTED_ERROR", "function not implemented"},
- {"PR_IO_ERROR", "I/O function error"},
- {"PR_IO_TIMEOUT_ERROR", "I/O operation timed out"},
- {"PR_IO_PENDING_ERROR", "I/O operation on busy file descriptor"},
- {"PR_DIRECTORY_OPEN_ERROR", "The directory could not be opened"},
- {"PR_INVALID_ARGUMENT_ERROR", "Invalid function argument"},
- {"PR_ADDRESS_NOT_AVAILABLE_ERROR", "Network address not available (in use?)"},
- {"PR_ADDRESS_NOT_SUPPORTED_ERROR", "Network address type not supported"},
- {"PR_IS_CONNECTED_ERROR", "Already connected"},
- {"PR_BAD_ADDRESS_ERROR", "Network address is invalid"},
- {"PR_ADDRESS_IN_USE_ERROR", "Local Network address is in use"},
- {"PR_CONNECT_REFUSED_ERROR", "Connection refused by peer"},
- {"PR_NETWORK_UNREACHABLE_ERROR", "Network address is presently unreachable"},
- {"PR_CONNECT_TIMEOUT_ERROR", "Connection attempt timed out"},
- {"PR_NOT_CONNECTED_ERROR", "Network file descriptor is not connected"},
- {"PR_LOAD_LIBRARY_ERROR", "Failure to load dynamic library"},
- {"PR_UNLOAD_LIBRARY_ERROR", "Failure to unload dynamic library"},
- {"PR_FIND_SYMBOL_ERROR", "Symbol not found in any of the loaded dynamic libraries"},
- {"PR_INSUFFICIENT_RESOURCES_ERROR", "Insufficient system resources"},
- {"PR_DIRECTORY_LOOKUP_ERROR", "A directory lookup on a network address has failed"},
- {"PR_TPD_RANGE_ERROR", "Attempt to access a TPD key that is out of range"},
- {"PR_PROC_DESC_TABLE_FULL_ERROR", "Process open FD table is full"},
- {"PR_SYS_DESC_TABLE_FULL_ERROR", "System open FD table is full"},
- {"PR_NOT_SOCKET_ERROR", "Network operation attempted on non-network file descriptor"},
- {"PR_NOT_TCP_SOCKET_ERROR", "TCP-specific function attempted on a non-TCP file descriptor"},
- {"PR_SOCKET_ADDRESS_IS_BOUND_ERROR", "TCP file descriptor is already bound"},
- {"PR_NO_ACCESS_RIGHTS_ERROR", "Access Denied"},
- {"PR_OPERATION_NOT_SUPPORTED_ERROR", "The requested operation is not supported by the platform"},
- {"PR_PROTOCOL_NOT_SUPPORTED_ERROR", "The host operating system does not support the protocol requested"},
- {"PR_REMOTE_FILE_ERROR", "Access to the remote file has been severed"},
- {"PR_BUFFER_OVERFLOW_ERROR", "The value requested is too large to be stored in the data buffer provided"},
- {"PR_CONNECT_RESET_ERROR", "TCP connection reset by peer"},
- {"PR_RANGE_ERROR", "Unused"},
- {"PR_DEADLOCK_ERROR", "The operation would have deadlocked"},
- {"PR_FILE_IS_LOCKED_ERROR", "The file is already locked"},
- {"PR_FILE_TOO_BIG_ERROR", "Write would result in file larger than the system allows"},
- {"PR_NO_DEVICE_SPACE_ERROR", "The device for storing the file is full"},
- {"PR_PIPE_ERROR", "Unused"},
- {"PR_NO_SEEK_DEVICE_ERROR", "Unused"},
- {"PR_IS_DIRECTORY_ERROR", "Cannot perform a normal file operation on a directory"},
- {"PR_LOOP_ERROR", "Symbolic link loop"},
- {"PR_NAME_TOO_LONG_ERROR", "File name is too long"},
- {"PR_FILE_NOT_FOUND_ERROR", "File not found"},
- {"PR_NOT_DIRECTORY_ERROR", "Cannot perform directory operation on a normal file"},
- {"PR_READ_ONLY_FILESYSTEM_ERROR", "Cannot write to a read-only file system"},
- {"PR_DIRECTORY_NOT_EMPTY_ERROR", "Cannot delete a directory that is not empty"},
- {"PR_FILESYSTEM_MOUNTED_ERROR", "Cannot delete or rename a file object while the file system is busy"},
- {"PR_NOT_SAME_DEVICE_ERROR", "Cannot rename a file to a file system on another device"},
- {"PR_DIRECTORY_CORRUPTED_ERROR", "The directory object in the file system is corrupted"},
- {"PR_FILE_EXISTS_ERROR", "Cannot create or rename a filename that already exists"},
- {"PR_MAX_DIRECTORY_ENTRIES_ERROR", "Directory is full. No additional filenames may be added"},
- {"PR_INVALID_DEVICE_STATE_ERROR", "The required device was in an invalid state"},
- {"PR_DEVICE_IS_LOCKED_ERROR", "The device is locked"},
- {"PR_NO_MORE_FILES_ERROR", "No more entries in the directory"},
- {"PR_END_OF_FILE_ERROR", "Encountered end of file"},
- {"PR_FILE_SEEK_ERROR", "Seek error"},
- {"PR_FILE_IS_BUSY_ERROR", "The file is busy"},
- {"PR_OPERATION_ABORTED_ERROR", "The I/O operation was aborted"},
- {"PR_IN_PROGRESS_ERROR", "Operation is still in progress (probably a non-blocking connect)"},
- {"PR_ALREADY_INITIATED_ERROR", "Operation has already been initiated (probably a non-blocking connect)"},
- {"PR_GROUP_EMPTY_ERROR", "The wait group is empty"},
- {"PR_INVALID_STATE_ERROR", "Object state improper for request"},
- {"PR_NETWORK_DOWN_ERROR", "Network is down"},
- {"PR_SOCKET_SHUTDOWN_ERROR", "Socket shutdown"},
- {"PR_CONNECT_ABORTED_ERROR", "Connection aborted"},
- {"PR_HOST_UNREACHABLE_ERROR", "Host is unreachable"},
- {"PR_LIBRARY_NOT_LOADED_ERROR", "The library is not loaded"},
- {"PR_CALL_ONCE_ERROR", "The one-time function was previously called and failed. Its error code is no longer available"},
- {"PR_MAX_ERROR", "Placeholder for the end of the list"},
- {0, 0}
+ {"PR_OUT_OF_MEMORY_ERROR", "Memory allocation attempt failed"},
+ {"PR_BAD_DESCRIPTOR_ERROR", "Invalid file descriptor"},
+ {"PR_WOULD_BLOCK_ERROR", "The operation would have blocked"},
+ {"PR_ACCESS_FAULT_ERROR", "Invalid memory address argument"},
+ {"PR_INVALID_METHOD_ERROR", "Invalid function for file type"},
+ {"PR_ILLEGAL_ACCESS_ERROR", "Invalid memory address argument"},
+ {"PR_UNKNOWN_ERROR", "Some unknown error has occurred"},
+ {"PR_PENDING_INTERRUPT_ERROR", "Operation interrupted by another thread"},
+ {"PR_NOT_IMPLEMENTED_ERROR", "function not implemented"},
+ {"PR_IO_ERROR", "I/O function error"},
+ {"PR_IO_TIMEOUT_ERROR", "I/O operation timed out"},
+ {"PR_IO_PENDING_ERROR", "I/O operation on busy file descriptor"},
+ {"PR_DIRECTORY_OPEN_ERROR", "The directory could not be opened"},
+ {"PR_INVALID_ARGUMENT_ERROR", "Invalid function argument"},
+ {"PR_ADDRESS_NOT_AVAILABLE_ERROR", "Network address not available (in use?)"},
+ {"PR_ADDRESS_NOT_SUPPORTED_ERROR", "Network address type not supported"},
+ {"PR_IS_CONNECTED_ERROR", "Already connected"},
+ {"PR_BAD_ADDRESS_ERROR", "Network address is invalid"},
+ {"PR_ADDRESS_IN_USE_ERROR", "Local Network address is in use"},
+ {"PR_CONNECT_REFUSED_ERROR", "Connection refused by peer"},
+ {"PR_NETWORK_UNREACHABLE_ERROR", "Network address is presently unreachable"},
+ {"PR_CONNECT_TIMEOUT_ERROR", "Connection attempt timed out"},
+ {"PR_NOT_CONNECTED_ERROR", "Network file descriptor is not connected"},
+ {"PR_LOAD_LIBRARY_ERROR", "Failure to load dynamic library"},
+ {"PR_UNLOAD_LIBRARY_ERROR", "Failure to unload dynamic library"},
+ {"PR_FIND_SYMBOL_ERROR", "Symbol not found in any of the loaded dynamic libraries"},
+ {"PR_INSUFFICIENT_RESOURCES_ERROR", "Insufficient system resources"},
+ {"PR_DIRECTORY_LOOKUP_ERROR", "A directory lookup on a network address has failed"},
+ {"PR_TPD_RANGE_ERROR", "Attempt to access a TPD key that is out of range"},
+ {"PR_PROC_DESC_TABLE_FULL_ERROR", "Process open FD table is full"},
+ {"PR_SYS_DESC_TABLE_FULL_ERROR", "System open FD table is full"},
+ {"PR_NOT_SOCKET_ERROR", "Network operation attempted on non-network file descriptor"},
+ {"PR_NOT_TCP_SOCKET_ERROR", "TCP-specific function attempted on a non-TCP file descriptor"},
+ {"PR_SOCKET_ADDRESS_IS_BOUND_ERROR", "TCP file descriptor is already bound"},
+ {"PR_NO_ACCESS_RIGHTS_ERROR", "Access Denied"},
+ {"PR_OPERATION_NOT_SUPPORTED_ERROR", "The requested operation is not supported by the platform"},
+ {"PR_PROTOCOL_NOT_SUPPORTED_ERROR", "The host operating system does not support the protocol requested"},
+ {"PR_REMOTE_FILE_ERROR", "Access to the remote file has been severed"},
+ {"PR_BUFFER_OVERFLOW_ERROR", "The value requested is too large to be stored in the data buffer provided"},
+ {"PR_CONNECT_RESET_ERROR", "TCP connection reset by peer"},
+ {"PR_RANGE_ERROR", "Unused"},
+ {"PR_DEADLOCK_ERROR", "The operation would have deadlocked"},
+ {"PR_FILE_IS_LOCKED_ERROR", "The file is already locked"},
+ {"PR_FILE_TOO_BIG_ERROR", "Write would result in file larger than the system allows"},
+ {"PR_NO_DEVICE_SPACE_ERROR", "The device for storing the file is full"},
+ {"PR_PIPE_ERROR", "Unused"},
+ {"PR_NO_SEEK_DEVICE_ERROR", "Unused"},
+ {"PR_IS_DIRECTORY_ERROR", "Cannot perform a normal file operation on a directory"},
+ {"PR_LOOP_ERROR", "Symbolic link loop"},
+ {"PR_NAME_TOO_LONG_ERROR", "File name is too long"},
+ {"PR_FILE_NOT_FOUND_ERROR", "File not found"},
+ {"PR_NOT_DIRECTORY_ERROR", "Cannot perform directory operation on a normal file"},
+ {"PR_READ_ONLY_FILESYSTEM_ERROR", "Cannot write to a read-only file system"},
+ {"PR_DIRECTORY_NOT_EMPTY_ERROR", "Cannot delete a directory that is not empty"},
+ {"PR_FILESYSTEM_MOUNTED_ERROR", "Cannot delete or rename a file object while the file system is busy"},
+ {"PR_NOT_SAME_DEVICE_ERROR", "Cannot rename a file to a file system on another device"},
+ {"PR_DIRECTORY_CORRUPTED_ERROR", "The directory object in the file system is corrupted"},
+ {"PR_FILE_EXISTS_ERROR", "Cannot create or rename a filename that already exists"},
+ {"PR_MAX_DIRECTORY_ENTRIES_ERROR", "Directory is full. No additional filenames may be added"},
+ {"PR_INVALID_DEVICE_STATE_ERROR", "The required device was in an invalid state"},
+ {"PR_DEVICE_IS_LOCKED_ERROR", "The device is locked"},
+ {"PR_NO_MORE_FILES_ERROR", "No more entries in the directory"},
+ {"PR_END_OF_FILE_ERROR", "Encountered end of file"},
+ {"PR_FILE_SEEK_ERROR", "Seek error"},
+ {"PR_FILE_IS_BUSY_ERROR", "The file is busy"},
+ {"PR_OPERATION_ABORTED_ERROR", "The I/O operation was aborted"},
+ {"PR_IN_PROGRESS_ERROR", "Operation is still in progress (probably a non-blocking connect)"},
+ {"PR_ALREADY_INITIATED_ERROR", "Operation has already been initiated (probably a non-blocking connect)"},
+ {"PR_GROUP_EMPTY_ERROR", "The wait group is empty"},
+ {"PR_INVALID_STATE_ERROR", "Object state improper for request"},
+ {"PR_NETWORK_DOWN_ERROR", "Network is down"},
+ {"PR_SOCKET_SHUTDOWN_ERROR", "Socket shutdown"},
+ {"PR_CONNECT_ABORTED_ERROR", "Connection aborted"},
+ {"PR_HOST_UNREACHABLE_ERROR", "Host is unreachable"},
+ {"PR_LIBRARY_NOT_LOADED_ERROR", "The library is not loaded"},
+ {"PR_CALL_ONCE_ERROR", "The one-time function was previously called and failed. Its error code is no longer available"},
+ {"PR_MAX_ERROR", "Placeholder for the end of the list"},
+ {0, 0}
};
static const struct PRErrorTable et = { text, "prerr", -6000L, 77 };
diff --git a/nsprpub/pr/src/misc/prerror.c b/nsprpub/pr/src/misc/prerror.c
index 19f7794b4..a06b78ddb 100644
--- a/nsprpub/pr/src/misc/prerror.c
+++ b/nsprpub/pr/src/misc/prerror.c
@@ -34,25 +34,27 @@ PR_IMPLEMENT(void) PR_SetErrorText(PRIntn textLength, const char *text)
if (0 == textLength)
{
- if (NULL != thread->errorString)
- PR_DELETE(thread->errorString);
- thread->errorStringSize = 0;
+ if (NULL != thread->errorString) {
+ PR_DELETE(thread->errorString);
+ }
+ thread->errorStringSize = 0;
}
else
{
- PRIntn size = textLength + 31; /* actual length to allocate. Plus a little extra */
+ PRIntn size = textLength + 31; /* actual length to allocate. Plus a little extra */
if (thread->errorStringSize < textLength+1) /* do we have room? */
{
- if (NULL != thread->errorString)
- PR_DELETE(thread->errorString);
- thread->errorString = (char*)PR_MALLOC(size);
+ if (NULL != thread->errorString) {
+ PR_DELETE(thread->errorString);
+ }
+ thread->errorString = (char*)PR_MALLOC(size);
if ( NULL == thread->errorString ) {
thread->errorStringSize = 0;
thread->errorStringLength = 0;
return;
}
thread->errorStringSize = size;
- }
+ }
memcpy(thread->errorString, text, textLength+1 );
}
thread->errorStringLength = textLength;
@@ -67,8 +69,9 @@ PR_IMPLEMENT(PRInt32) PR_GetErrorTextLength(void)
PR_IMPLEMENT(PRInt32) PR_GetErrorText(char *text)
{
PRThread *thread = PR_GetCurrentThread();
- if (0 != thread->errorStringLength)
+ if (0 != thread->errorStringLength) {
memcpy(text, thread->errorString, thread->errorStringLength+1);
+ }
return thread->errorStringLength;
} /* PR_GetErrorText */
diff --git a/nsprpub/pr/src/misc/prerrortable.c b/nsprpub/pr/src/misc/prerrortable.c
index 285fde977..a7ff4f0eb 100644
--- a/nsprpub/pr/src/misc/prerrortable.c
+++ b/nsprpub/pr/src/misc/prerrortable.c
@@ -8,7 +8,7 @@
/*
Copyright 1987, 1988 by the Student Information Processing Board
- of the Massachusetts Institute of Technology
+ of the Massachusetts Institute of Technology
Permission to use, copy, modify, and distribute this software
and its documentation for any purpose and without fee is
@@ -30,8 +30,8 @@ provided "as is" without express or implied warranty.
#include "prmem.h"
#include "prerror.h"
-#define ERRCODE_RANGE 8 /* # of bits to shift table number */
-#define BITS_PER_CHAR 6 /* # bits to shift per character in name */
+#define ERRCODE_RANGE 8 /* # of bits to shift table number */
+#define BITS_PER_CHAR 6 /* # bits to shift per character in name */
#ifdef NEED_SYS_ERRLIST
extern char const * const sys_errlist[];
@@ -57,12 +57,12 @@ static PRErrorCallbackNewTableFn *callback_newtable = 0;
static const char char_set[] =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
static const char *
error_table_name (PRErrorCode num)
{
- static char buf[6]; /* only used if internal code problems exist */
+ static char buf[6]; /* only used if internal code problems exist */
long ch;
int i;
@@ -75,9 +75,10 @@ error_table_name (PRErrorCode num)
num &= 077777777;
/* num = 00 000 000 aaa aaa bbb bbb ccc ccc ddd ddd */
for (i = 4; i >= 0; i--) {
- ch = (num >> BITS_PER_CHAR * i) & ((1 << BITS_PER_CHAR) - 1);
- if (ch != 0)
- *p++ = char_set[ch-1];
+ ch = (num >> BITS_PER_CHAR * i) & ((1 << BITS_PER_CHAR) - 1);
+ if (ch != 0) {
+ *p++ = char_set[ch-1];
+ }
}
*p = '\0';
return(buf);
@@ -99,40 +100,42 @@ PR_ErrorToString(PRErrorCode code, PRLanguageCode language)
char *cp;
for (et = Table_List; et; et = et->next) {
- if (et->table->base <= code &&
- et->table->base + et->table->n_msgs > code) {
- /* This is the right table */
- if (callback_lookup) {
- msg = callback_lookup(code, language, et->table,
- callback_private, et->table_private);
- if (msg) return msg;
- }
-
- return(et->table->msgs[code - et->table->base].en_text);
- }
+ if (et->table->base <= code &&
+ et->table->base + et->table->n_msgs > code) {
+ /* This is the right table */
+ if (callback_lookup) {
+ msg = callback_lookup(code, language, et->table,
+ callback_private, et->table_private);
+ if (msg) {
+ return msg;
+ }
+ }
+
+ return(et->table->msgs[code - et->table->base].en_text);
+ }
}
if (code >= 0 && code < 256) {
- return strerror(code);
+ return strerror(code);
}
offset = (int) (code & ((1<<ERRCODE_RANGE)-1));
table_num = code - offset;
strcpy (buffer, "Unknown code ");
if (table_num) {
- strcat(buffer, error_table_name (table_num));
- strcat(buffer, " ");
+ strcat(buffer, error_table_name (table_num));
+ strcat(buffer, " ");
}
for (cp = buffer; *cp; cp++)
- ;
+ ;
if (offset >= 100) {
- *cp++ = (char)('0' + offset / 100);
- offset %= 100;
- started++;
+ *cp++ = (char)('0' + offset / 100);
+ offset %= 100;
+ started++;
}
if (started || offset >= 10) {
- *cp++ = (char)('0' + offset / 10);
- offset %= 10;
+ *cp++ = (char)('0' + offset / 10);
+ offset %= 10;
}
*cp++ = (char)('0' + offset);
*cp = '\0';
@@ -145,11 +148,11 @@ PR_ErrorToName(PRErrorCode code)
struct PRErrorTableList *et;
for (et = Table_List; et; et = et->next) {
- if (et->table->base <= code &&
- et->table->base + et->table->n_msgs > code) {
- /* This is the right table */
- return(et->table->msgs[code - et->table->base].name);
- }
+ if (et->table->base <= code &&
+ et->table->base + et->table->n_msgs > code) {
+ /* This is the right table */
+ return(et->table->msgs[code - et->table->base].name);
+ }
}
return 0;
@@ -167,14 +170,15 @@ PR_ErrorInstallTable(const struct PRErrorTable *table)
struct PRErrorTableList * new_et;
new_et = (struct PRErrorTableList *)
- PR_Malloc(sizeof(struct PRErrorTableList));
- if (!new_et)
- return errno; /* oops */
+ PR_Malloc(sizeof(struct PRErrorTableList));
+ if (!new_et) {
+ return errno; /* oops */
+ }
new_et->table = table;
if (callback_newtable) {
- new_et->table_private = callback_newtable(table, callback_private);
+ new_et->table_private = callback_newtable(table, callback_private);
} else {
- new_et->table_private = 0;
+ new_et->table_private = 0;
}
new_et->next = Table_List;
Table_List = new_et;
@@ -183,23 +187,23 @@ PR_ErrorInstallTable(const struct PRErrorTable *table)
PR_IMPLEMENT(void)
PR_ErrorInstallCallback(const char * const * languages,
- PRErrorCallbackLookupFn *lookup,
- PRErrorCallbackNewTableFn *newtable,
- struct PRErrorCallbackPrivate *cb_private)
+ PRErrorCallbackLookupFn *lookup,
+ PRErrorCallbackNewTableFn *newtable,
+ struct PRErrorCallbackPrivate *cb_private)
{
struct PRErrorTableList *et;
assert(strcmp(languages[0], "i-default") == 0);
assert(strcmp(languages[1], "en") == 0);
-
+
callback_languages = languages;
callback_lookup = lookup;
callback_newtable = newtable;
callback_private = cb_private;
if (callback_newtable) {
- for (et = Table_List; et; et = et->next) {
- et->table_private = callback_newtable(et->table, callback_private);
- }
+ for (et = Table_List; et; et = et->next) {
+ et->table_private = callback_newtable(et->table, callback_private);
+ }
}
}
diff --git a/nsprpub/pr/src/misc/prinit.c b/nsprpub/pr/src/misc/prinit.c
index 43048a0d2..5ac99fe58 100644
--- a/nsprpub/pr/src/misc/prinit.c
+++ b/nsprpub/pr/src/misc/prinit.c
@@ -26,9 +26,9 @@ PRFileDesc *_pr_stderr;
#if !defined(_PR_PTHREADS) && !defined(_PR_BTHREADS)
PRCList _pr_active_local_threadQ =
- PR_INIT_STATIC_CLIST(&_pr_active_local_threadQ);
+ PR_INIT_STATIC_CLIST(&_pr_active_local_threadQ);
PRCList _pr_active_global_threadQ =
- PR_INIT_STATIC_CLIST(&_pr_active_global_threadQ);
+ PR_INIT_STATIC_CLIST(&_pr_active_global_threadQ);
_MDLock _pr_cpuLock; /* lock for the CPU Q */
PRCList _pr_cpuQ = PR_INIT_STATIC_CLIST(&_pr_cpuQ);
@@ -41,10 +41,10 @@ PRUintn _pr_maxPTDs;
#ifdef _PR_LOCAL_THREADS_ONLY
-struct _PRCPU *_pr_currentCPU;
-PRThread *_pr_currentThread;
-PRThread *_pr_lastThread;
-PRInt32 _pr_intsOff;
+struct _PRCPU *_pr_currentCPU;
+PRThread *_pr_currentThread;
+PRThread *_pr_lastThread;
+PRInt32 _pr_intsOff;
#endif /* _PR_LOCAL_THREADS_ONLY */
@@ -138,7 +138,9 @@ static void _pr_SetNativeThreadsOnlyMode(void)
static void _PR_InitStuff(void)
{
- if (_pr_initialized) return;
+ if (_pr_initialized) {
+ return;
+ }
_pr_initialized = PR_TRUE;
#ifdef _PR_ZONE_ALLOCATOR
_PR_InitZones();
@@ -150,26 +152,26 @@ static void _PR_InitStuff(void)
(void) PR_GetPageSize();
- _pr_clock_lm = PR_NewLogModule("clock");
- _pr_cmon_lm = PR_NewLogModule("cmon");
- _pr_io_lm = PR_NewLogModule("io");
- _pr_mon_lm = PR_NewLogModule("mon");
- _pr_linker_lm = PR_NewLogModule("linker");
- _pr_cvar_lm = PR_NewLogModule("cvar");
- _pr_sched_lm = PR_NewLogModule("sched");
- _pr_thread_lm = PR_NewLogModule("thread");
- _pr_gc_lm = PR_NewLogModule("gc");
- _pr_shm_lm = PR_NewLogModule("shm");
- _pr_shma_lm = PR_NewLogModule("shma");
-
- /* NOTE: These init's cannot depend on _PR_MD_CURRENT_THREAD() */
+ _pr_clock_lm = PR_NewLogModule("clock");
+ _pr_cmon_lm = PR_NewLogModule("cmon");
+ _pr_io_lm = PR_NewLogModule("io");
+ _pr_mon_lm = PR_NewLogModule("mon");
+ _pr_linker_lm = PR_NewLogModule("linker");
+ _pr_cvar_lm = PR_NewLogModule("cvar");
+ _pr_sched_lm = PR_NewLogModule("sched");
+ _pr_thread_lm = PR_NewLogModule("thread");
+ _pr_gc_lm = PR_NewLogModule("gc");
+ _pr_shm_lm = PR_NewLogModule("shm");
+ _pr_shma_lm = PR_NewLogModule("shma");
+
+ /* NOTE: These init's cannot depend on _PR_MD_CURRENT_THREAD() */
_PR_MD_EARLY_INIT();
_PR_InitLocks();
_PR_InitAtomic();
_PR_InitSegs();
_PR_InitStacks();
- _PR_InitTPD();
+ _PR_InitTPD();
_PR_InitEnv();
_PR_InitLayerCache();
_PR_InitClock();
@@ -178,22 +180,22 @@ static void _PR_InitStuff(void)
PR_ASSERT(NULL != _pr_sleeplock);
_PR_InitThreads(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
-
+
#ifdef WIN16
- {
- PRInt32 top; /* artificial top of stack, win16 */
- _pr_top_of_task_stack = (char *) &top;
- }
-#endif
+ {
+ PRInt32 top; /* artificial top of stack, win16 */
+ _pr_top_of_task_stack = (char *) &top;
+ }
+#endif
#ifndef _PR_GLOBAL_THREADS_ONLY
- _PR_InitCPUs();
+ _PR_InitCPUs();
#endif
-/*
- * XXX: call _PR_InitMem only on those platforms for which nspr implements
- * malloc, for now.
- */
+ /*
+ * XXX: call _PR_InitMem only on those platforms for which nspr implements
+ * malloc, for now.
+ */
#ifdef _PR_OVERRIDE_MALLOC
_PR_InitMem();
#endif
@@ -216,7 +218,7 @@ static void _PR_InitStuff(void)
void _PR_ImplicitInitialization(void)
{
- _PR_InitStuff();
+ _PR_InitStuff();
/* Enable interrupts */
#if !defined(_PR_PTHREADS) && !defined(_PR_GLOBAL_THREADS_ONLY)
@@ -228,20 +230,20 @@ void _PR_ImplicitInitialization(void)
PR_IMPLEMENT(void) PR_DisableClockInterrupts(void)
{
#if !defined(_PR_PTHREADS) && !defined(_PR_BTHREADS)
- if (!_pr_initialized) {
- _PR_InitStuff();
- } else {
- _PR_MD_DISABLE_CLOCK_INTERRUPTS();
- }
+ if (!_pr_initialized) {
+ _PR_InitStuff();
+ } else {
+ _PR_MD_DISABLE_CLOCK_INTERRUPTS();
+ }
#endif
}
PR_IMPLEMENT(void) PR_EnableClockInterrupts(void)
{
#if !defined(_PR_PTHREADS) && !defined(_PR_BTHREADS)
- if (!_pr_initialized) {
- _PR_InitStuff();
- }
+ if (!_pr_initialized) {
+ _PR_InitStuff();
+ }
_PR_MD_ENABLE_CLOCK_INTERRUPTS();
#endif
}
@@ -249,14 +251,14 @@ PR_IMPLEMENT(void) PR_EnableClockInterrupts(void)
PR_IMPLEMENT(void) PR_BlockClockInterrupts(void)
{
#if !defined(_PR_PTHREADS) && !defined(_PR_BTHREADS)
- _PR_MD_BLOCK_CLOCK_INTERRUPTS();
+ _PR_MD_BLOCK_CLOCK_INTERRUPTS();
#endif
}
PR_IMPLEMENT(void) PR_UnblockClockInterrupts(void)
{
#if !defined(_PR_PTHREADS) && !defined(_PR_BTHREADS)
- _PR_MD_UNBLOCK_CLOCK_INTERRUPTS();
+ _PR_MD_UNBLOCK_CLOCK_INTERRUPTS();
#endif
}
@@ -272,7 +274,7 @@ PR_IMPLEMENT(PRIntn) PR_Initialize(
PRIntn rv;
_PR_ImplicitInitialization();
rv = prmain(argc, argv);
- PR_Cleanup();
+ PR_Cleanup();
return rv;
} /* PR_Initialize */
@@ -281,7 +283,7 @@ PR_IMPLEMENT(PRIntn) PR_Initialize(
*
* _PR_CleanupBeforeExit --
*
- * Perform the cleanup work before exiting the process.
+ * Perform the cleanup work before exiting the process.
* We first do the cleanup generic to all platforms. Then
* we call _PR_MD_CLEANUP_BEFORE_EXIT(), where platform-dependent
* cleanup is done. This function is used by PR_Cleanup().
@@ -291,23 +293,25 @@ PR_IMPLEMENT(PRIntn) PR_Initialize(
*-----------------------------------------------------------------------
*/
#if defined(_PR_PTHREADS) || defined(_PR_BTHREADS)
- /* see ptthread.c */
+/* see ptthread.c */
#else
static void
_PR_CleanupBeforeExit(void)
{
-/*
-Do not make any calls here other than to destroy resources. For example,
-do not make any calls that eventually may end up in PR_Lock. Because the
-thread is destroyed, can not access current thread any more.
-*/
+ /*
+ Do not make any calls here other than to destroy resources. For example,
+ do not make any calls that eventually may end up in PR_Lock. Because the
+ thread is destroyed, can not access current thread any more.
+ */
_PR_CleanupTPD();
if (_pr_terminationCVLock)
- /*
- * In light of the comment above, this looks real suspicious.
- * I'd go so far as to say it's just a problem waiting to happen.
- */
+ /*
+ * In light of the comment above, this looks real suspicious.
+ * I'd go so far as to say it's just a problem waiting to happen.
+ */
+ {
PR_DestroyLock(_pr_terminationCVLock);
+ }
_PR_MD_CLEANUP_BEFORE_EXIT();
}
@@ -329,7 +333,7 @@ thread is destroyed, can not access current thread any more.
* Then it performs cleanup in preparation for exiting the process.
* PR_Cleanup() does not exit the primordial thread (which would
* in turn exit the process).
- *
+ *
* PR_Cleanup() only responds when it is called by the primordial
* thread. Calls by any other thread are silently ignored.
*
@@ -338,7 +342,7 @@ thread is destroyed, can not access current thread any more.
*----------------------------------------------------------------------
*/
#if defined(_PR_PTHREADS) || defined(_PR_BTHREADS)
- /* see ptthread.c */
+/* see ptthread.c */
#else
PR_IMPLEMENT(PRStatus) PR_Cleanup()
@@ -369,21 +373,13 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup()
}
PR_Unlock(_pr_activeLock);
-#ifdef IRIX
- _PR_MD_PRE_CLEANUP(me);
- /*
- * The primordial thread must now be running on the primordial cpu
- */
- PR_ASSERT((_PR_IS_NATIVE_THREAD(me)) || (me->cpu->id == 0));
-#endif
-
_PR_MD_EARLY_CLEANUP();
_PR_CleanupMW();
_PR_CleanupTime();
_PR_CleanupDtoa();
_PR_CleanupCallOnce();
- _PR_ShutdownLinker();
+ _PR_ShutdownLinker();
_PR_CleanupNet();
_PR_CleanupIO();
/* Release the primordial thread's private data, etc. */
@@ -391,9 +387,9 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup()
_PR_MD_STOP_INTERRUPTS();
- PR_LOG(_pr_thread_lm, PR_LOG_MIN,
- ("PR_Cleanup: clean up before destroying thread"));
- _PR_LogCleanup();
+ PR_LOG(_pr_thread_lm, PR_LOG_MIN,
+ ("PR_Cleanup: clean up before destroying thread"));
+ _PR_LogCleanup();
/*
* This part should look like the end of _PR_NativeRunThread
@@ -436,18 +432,18 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup()
/*
*------------------------------------------------------------------------
* PR_ProcessExit --
- *
+ *
* Cause an immediate, nongraceful, forced termination of the process.
* It takes a PRIntn argument, which is the exit status code of the
* process.
- *
+ *
* See also: PR_Cleanup()
*
*------------------------------------------------------------------------
*/
#if defined(_PR_PTHREADS) || defined(_PR_BTHREADS)
- /* see ptthread.c */
+/* see ptthread.c */
#else
PR_IMPLEMENT(void) PR_ProcessExit(PRIntn status)
{
@@ -518,7 +514,7 @@ PR_SetStdioRedirect(
static PRBool warn = PR_TRUE;
if (warn) {
warn = _PR_Obsolete("PR_SetStdioRedirect()",
- "PR_ProcessAttrSetStdioRedirect()");
+ "PR_ProcessAttrSetStdioRedirect()");
}
#endif
PR_ProcessAttrSetStdioRedirect(attr, stdioFd, redirectFd);
@@ -583,11 +579,11 @@ PR_ProcessAttrSetInheritableFD(
if (NULL == attr->fdInheritBuffer) {
/* The first time, we print "NSPR_INHERIT_FDS=<name>:<type>:<val>" */
newSize = NSPR_INHERIT_FDS_STRLEN + strlen(name)
- + FD_TYPE_STRLEN + OSFD_STRLEN + 2 + 1;
+ + FD_TYPE_STRLEN + OSFD_STRLEN + 2 + 1;
} else {
/* At other times, we print ":<name>:<type>:<val>" */
newSize = attr->fdInheritBufferUsed + strlen(name)
- + FD_TYPE_STRLEN + OSFD_STRLEN + 3 + 1;
+ + FD_TYPE_STRLEN + OSFD_STRLEN + 3 + 1;
}
if (newSize > attr->fdInheritBufferSize) {
/* Make newSize a multiple of FD_INHERIT_BUFFER_INCR */
@@ -611,13 +607,13 @@ PR_ProcessAttrSetInheritableFD(
freeSize = attr->fdInheritBufferSize - attr->fdInheritBufferUsed;
if (0 == attr->fdInheritBufferUsed) {
nwritten = PR_snprintf(cur, freeSize,
- "NSPR_INHERIT_FDS=%s:%d:0x%" PR_PRIxOSFD,
- name, (PRIntn)fd->methods->file_type, fd->secret->md.osfd);
+ "NSPR_INHERIT_FDS=%s:%d:0x%" PR_PRIxOSFD,
+ name, (PRIntn)fd->methods->file_type, fd->secret->md.osfd);
} else {
nwritten = PR_snprintf(cur, freeSize, ":%s:%d:0x%" PR_PRIxOSFD,
- name, (PRIntn)fd->methods->file_type, fd->secret->md.osfd);
+ name, (PRIntn)fd->methods->file_type, fd->secret->md.osfd);
}
- attr->fdInheritBufferUsed += nwritten;
+ attr->fdInheritBufferUsed += nwritten;
return PR_SUCCESS;
}
@@ -713,13 +709,13 @@ PR_IMPLEMENT(PRStatus) PR_CreateProcessDetached(
process = PR_CreateProcess(path, argv, envp, attr);
if (NULL == process) {
- return PR_FAILURE;
+ return PR_FAILURE;
}
rv = PR_DetachProcess(process);
PR_ASSERT(PR_SUCCESS == rv);
if (rv == PR_FAILURE) {
- PR_DELETE(process);
- return PR_FAILURE;
+ PR_DELETE(process);
+ return PR_FAILURE;
}
return PR_SUCCESS;
}
@@ -771,22 +767,24 @@ PR_IMPLEMENT(PRStatus) PR_CallOnce(
PRCallOnceType *once,
PRCallOnceFN func)
{
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
if (!once->initialized) {
- if (PR_ATOMIC_SET(&once->inProgress, 1) == 0) {
- once->status = (*func)();
- PR_Lock(mod_init.ml);
- once->initialized = 1;
- PR_NotifyAllCondVar(mod_init.cv);
- PR_Unlock(mod_init.ml);
- } else {
- PR_Lock(mod_init.ml);
- while (!once->initialized) {
- PR_WaitCondVar(mod_init.cv, PR_INTERVAL_NO_TIMEOUT);
+ if (PR_ATOMIC_SET(&once->inProgress, 1) == 0) {
+ once->status = (*func)();
+ PR_Lock(mod_init.ml);
+ once->initialized = 1;
+ PR_NotifyAllCondVar(mod_init.cv);
+ PR_Unlock(mod_init.ml);
+ } else {
+ PR_Lock(mod_init.ml);
+ while (!once->initialized) {
+ PR_WaitCondVar(mod_init.cv, PR_INTERVAL_NO_TIMEOUT);
}
- PR_Unlock(mod_init.ml);
- }
+ PR_Unlock(mod_init.ml);
+ }
} else {
if (PR_SUCCESS != once->status) {
PR_SetError(PR_CALL_ONCE_ERROR, 0);
@@ -800,22 +798,24 @@ PR_IMPLEMENT(PRStatus) PR_CallOnceWithArg(
PRCallOnceWithArgFN func,
void *arg)
{
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
if (!once->initialized) {
- if (PR_ATOMIC_SET(&once->inProgress, 1) == 0) {
- once->status = (*func)(arg);
- PR_Lock(mod_init.ml);
- once->initialized = 1;
- PR_NotifyAllCondVar(mod_init.cv);
- PR_Unlock(mod_init.ml);
- } else {
- PR_Lock(mod_init.ml);
- while (!once->initialized) {
- PR_WaitCondVar(mod_init.cv, PR_INTERVAL_NO_TIMEOUT);
+ if (PR_ATOMIC_SET(&once->inProgress, 1) == 0) {
+ once->status = (*func)(arg);
+ PR_Lock(mod_init.ml);
+ once->initialized = 1;
+ PR_NotifyAllCondVar(mod_init.cv);
+ PR_Unlock(mod_init.ml);
+ } else {
+ PR_Lock(mod_init.ml);
+ while (!once->initialized) {
+ PR_WaitCondVar(mod_init.cv, PR_INTERVAL_NO_TIMEOUT);
}
- PR_Unlock(mod_init.ml);
- }
+ PR_Unlock(mod_init.ml);
+ }
} else {
if (PR_SUCCESS != once->status) {
PR_SetError(PR_CALL_ONCE_ERROR, 0);
diff --git a/nsprpub/pr/src/misc/prinrval.c b/nsprpub/pr/src/misc/prinrval.c
index 50a938b52..79ff2cbca 100644
--- a/nsprpub/pr/src/misc/prinrval.c
+++ b/nsprpub/pr/src/misc/prinrval.c
@@ -4,8 +4,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
- * file: prinrval.c
- * description: implementation for the kernel interval timing functions
+ * file: prinrval.c
+ * description: implementation for the kernel interval timing functions
*/
#include "primpl.h"
@@ -34,13 +34,17 @@ void _PR_InitClock(void)
PR_IMPLEMENT(PRIntervalTime) PR_IntervalNow(void)
{
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
return _PR_MD_GET_INTERVAL();
} /* PR_IntervalNow */
PR_EXTERN(PRUint32) PR_TicksPerSecond(void)
{
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
return _PR_MD_INTERVAL_PER_SEC();
} /* PR_TicksPerSecond */
diff --git a/nsprpub/pr/src/misc/pripc.c b/nsprpub/pr/src/misc/pripc.c
index e41a2afcf..64415dd63 100644
--- a/nsprpub/pr/src/misc/pripc.c
+++ b/nsprpub/pr/src/misc/pripc.c
@@ -17,7 +17,7 @@
* A POSIX IPC name must begin with a '/'.
* A POSIX IPC name on Solaris cannot contain any '/' except
* the required leading '/'.
- * A POSIX IPC name on HP-UX and OSF1 must be a valid pathname
+ * A POSIX IPC name on HP-UX must be a valid pathname
* in the file system.
*
* The ftok() function for System V IPC requires a valid pathname
diff --git a/nsprpub/pr/src/misc/pripcsem.c b/nsprpub/pr/src/misc/pripcsem.c
index a17689788..49b051b74 100644
--- a/nsprpub/pr/src/misc/pripcsem.c
+++ b/nsprpub/pr/src/misc/pripcsem.c
@@ -60,9 +60,11 @@ PR_IMPLEMENT(PRSem *) PR_OpenSemaphore(
{
char osname[PR_IPC_NAME_SIZE];
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
if (_PR_MakeNativeIPCName(name, osname, sizeof(osname), _PRIPCSem)
- == PR_FAILURE) {
+ == PR_FAILURE) {
return NULL;
}
return _PR_MD_OPEN_SEMAPHORE(osname, flags, mode, value);
@@ -87,9 +89,11 @@ PR_IMPLEMENT(PRStatus) PR_DeleteSemaphore(const char *name)
{
char osname[PR_IPC_NAME_SIZE];
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
if (_PR_MakeNativeIPCName(name, osname, sizeof(osname), _PRIPCSem)
- == PR_FAILURE) {
+ == PR_FAILURE) {
return PR_FAILURE;
}
return _PR_MD_DELETE_SEMAPHORE(osname);
diff --git a/nsprpub/pr/src/misc/prlong.c b/nsprpub/pr/src/misc/prlong.c
index 185fa5cd4..9c5abf06b 100644
--- a/nsprpub/pr/src/misc/prlong.c
+++ b/nsprpub/pr/src/misc/prlong.c
@@ -10,10 +10,18 @@ static PRInt64 ll_maxint = PR_INT64(0x7fffffffffffffff);
static PRInt64 ll_minint = PR_INT64(0x8000000000000000);
static PRUint64 ll_maxuint = PR_UINT64(0xffffffffffffffff);
-PR_IMPLEMENT(PRInt64) LL_Zero(void) { return ll_zero; }
-PR_IMPLEMENT(PRInt64) LL_MaxInt(void) { return ll_maxint; }
-PR_IMPLEMENT(PRInt64) LL_MinInt(void) { return ll_minint; }
-PR_IMPLEMENT(PRUint64) LL_MaxUint(void) { return ll_maxuint; }
+PR_IMPLEMENT(PRInt64) LL_Zero(void) {
+ return ll_zero;
+}
+PR_IMPLEMENT(PRInt64) LL_MaxInt(void) {
+ return ll_maxint;
+}
+PR_IMPLEMENT(PRInt64) LL_MinInt(void) {
+ return ll_minint;
+}
+PR_IMPLEMENT(PRUint64) LL_MaxUint(void) {
+ return ll_maxuint;
+}
#ifndef HAVE_LONG_LONG
/*
@@ -32,10 +40,10 @@ static void norm_udivmod32(PRUint32 *qp, PRUint32 *rp, PRUint64 a, PRUint32 b)
r1 = (r1 << 16) | _hi16(a.lo);
if (r1 < m) {
q1--, r1 += b;
- if (r1 >= b /* i.e., we didn't get a carry when adding to r1 */
- && r1 < m) {
- q1--, r1 += b;
- }
+ if (r1 >= b /* i.e., we didn't get a carry when adding to r1 */
+ && r1 < m) {
+ q1--, r1 += b;
+ }
}
r1 -= m;
r0 = r1 % d1;
@@ -45,9 +53,9 @@ static void norm_udivmod32(PRUint32 *qp, PRUint32 *rp, PRUint64 a, PRUint32 b)
if (r0 < m) {
q0--, r0 += b;
if (r0 >= b
- && r0 < m) {
- q0--, r0 += b;
- }
+ && r0 < m) {
+ q0--, r0 += b;
+ }
}
*qp = (q1 << 16) | q0;
*rp = r0 - m;
@@ -58,18 +66,24 @@ static PRUint32 CountLeadingZeros(PRUint32 a)
PRUint32 t;
PRUint32 r = 32;
- if ((t = a >> 16) != 0)
- r -= 16, a = t;
- if ((t = a >> 8) != 0)
- r -= 8, a = t;
- if ((t = a >> 4) != 0)
- r -= 4, a = t;
- if ((t = a >> 2) != 0)
- r -= 2, a = t;
- if ((t = a >> 1) != 0)
- r -= 1, a = t;
- if (a & 1)
- r--;
+ if ((t = a >> 16) != 0) {
+ r -= 16, a = t;
+ }
+ if ((t = a >> 8) != 0) {
+ r -= 8, a = t;
+ }
+ if ((t = a >> 4) != 0) {
+ r -= 4, a = t;
+ }
+ if ((t = a >> 2) != 0) {
+ r -= 2, a = t;
+ }
+ if ((t = a >> 1) != 0) {
+ r -= 1, a = t;
+ }
+ if (a & 1) {
+ r--;
+ }
return r;
}
@@ -83,157 +97,158 @@ PR_IMPLEMENT(void) ll_udivmod(PRUint64 *qp, PRUint64 *rp, PRUint64 a, PRUint64 b
n1 = a.hi;
if (b.hi == 0) {
- if (b.lo > n1) {
- /* (0 q0) = (n1 n0) / (0 D0) */
-
- lsh = CountLeadingZeros(b.lo);
-
- if (lsh) {
- /*
- * Normalize, i.e. make the most significant bit of the
- * denominator be set.
- */
- b.lo = b.lo << lsh;
- n1 = (n1 << lsh) | (n0 >> (32 - lsh));
- n0 = n0 << lsh;
- }
-
- a.lo = n0, a.hi = n1;
- norm_udivmod32(&q0, &n0, a, b.lo);
- q1 = 0;
-
- /* remainder is in n0 >> lsh */
- } else {
- /* (q1 q0) = (n1 n0) / (0 d0) */
-
- if (b.lo == 0) /* user wants to divide by zero! */
- b.lo = 1 / b.lo; /* so go ahead and crash */
-
- lsh = CountLeadingZeros(b.lo);
-
- if (lsh == 0) {
- /*
- * From (n1 >= b.lo)
- * && (the most significant bit of b.lo is set),
- * conclude that
- * (the most significant bit of n1 is set)
- * && (the leading quotient digit q1 = 1).
- *
- * This special case is necessary, not an optimization
- * (Shifts counts of 32 are undefined).
- */
- n1 -= b.lo;
- q1 = 1;
- } else {
- /*
- * Normalize.
- */
- rsh = 32 - lsh;
-
- b.lo = b.lo << lsh;
- n2 = n1 >> rsh;
- n1 = (n1 << lsh) | (n0 >> rsh);
- n0 = n0 << lsh;
-
- a.lo = n1, a.hi = n2;
- norm_udivmod32(&q1, &n1, a, b.lo);
- }
-
- /* n1 != b.lo... */
-
- a.lo = n0, a.hi = n1;
- norm_udivmod32(&q0, &n0, a, b.lo);
-
- /* remainder in n0 >> lsh */
- }
-
- if (rp) {
- rp->lo = n0 >> lsh;
- rp->hi = 0;
- }
+ if (b.lo > n1) {
+ /* (0 q0) = (n1 n0) / (0 D0) */
+
+ lsh = CountLeadingZeros(b.lo);
+
+ if (lsh) {
+ /*
+ * Normalize, i.e. make the most significant bit of the
+ * denominator be set.
+ */
+ b.lo = b.lo << lsh;
+ n1 = (n1 << lsh) | (n0 >> (32 - lsh));
+ n0 = n0 << lsh;
+ }
+
+ a.lo = n0, a.hi = n1;
+ norm_udivmod32(&q0, &n0, a, b.lo);
+ q1 = 0;
+
+ /* remainder is in n0 >> lsh */
+ } else {
+ /* (q1 q0) = (n1 n0) / (0 d0) */
+
+ if (b.lo == 0) { /* user wants to divide by zero! */
+ b.lo = 1 / b.lo; /* so go ahead and crash */
+ }
+
+ lsh = CountLeadingZeros(b.lo);
+
+ if (lsh == 0) {
+ /*
+ * From (n1 >= b.lo)
+ * && (the most significant bit of b.lo is set),
+ * conclude that
+ * (the most significant bit of n1 is set)
+ * && (the leading quotient digit q1 = 1).
+ *
+ * This special case is necessary, not an optimization
+ * (Shifts counts of 32 are undefined).
+ */
+ n1 -= b.lo;
+ q1 = 1;
+ } else {
+ /*
+ * Normalize.
+ */
+ rsh = 32 - lsh;
+
+ b.lo = b.lo << lsh;
+ n2 = n1 >> rsh;
+ n1 = (n1 << lsh) | (n0 >> rsh);
+ n0 = n0 << lsh;
+
+ a.lo = n1, a.hi = n2;
+ norm_udivmod32(&q1, &n1, a, b.lo);
+ }
+
+ /* n1 != b.lo... */
+
+ a.lo = n0, a.hi = n1;
+ norm_udivmod32(&q0, &n0, a, b.lo);
+
+ /* remainder in n0 >> lsh */
+ }
+
+ if (rp) {
+ rp->lo = n0 >> lsh;
+ rp->hi = 0;
+ }
} else {
- if (b.hi > n1) {
- /* (0 0) = (n1 n0) / (D1 d0) */
-
- q0 = 0;
- q1 = 0;
-
- /* remainder in (n1 n0) */
- if (rp) {
- rp->lo = n0;
- rp->hi = n1;
- }
- } else {
- /* (0 q0) = (n1 n0) / (d1 d0) */
-
- lsh = CountLeadingZeros(b.hi);
- if (lsh == 0) {
- /*
- * From (n1 >= b.hi)
- * && (the most significant bit of b.hi is set),
- * conclude that
- * (the most significant bit of n1 is set)
- * && (the quotient digit q0 = 0 or 1).
- *
- * This special case is necessary, not an optimization.
- */
-
- /*
- * The condition on the next line takes advantage of that
- * n1 >= b.hi (true due to control flow).
- */
- if (n1 > b.hi || n0 >= b.lo) {
- q0 = 1;
- a.lo = n0, a.hi = n1;
- LL_SUB(a, a, b);
- } else {
- q0 = 0;
- }
- q1 = 0;
-
- if (rp) {
- rp->lo = n0;
- rp->hi = n1;
- }
- } else {
- PRInt64 m;
-
- /*
- * Normalize.
- */
- rsh = 32 - lsh;
-
- b.hi = (b.hi << lsh) | (b.lo >> rsh);
- b.lo = b.lo << lsh;
- n2 = n1 >> rsh;
- n1 = (n1 << lsh) | (n0 >> rsh);
- n0 = n0 << lsh;
-
- a.lo = n1, a.hi = n2;
- norm_udivmod32(&q0, &n1, a, b.hi);
- LL_MUL32(m, q0, b.lo);
-
- if ((m.hi > n1) || ((m.hi == n1) && (m.lo > n0))) {
- q0--;
- LL_SUB(m, m, b);
- }
-
- q1 = 0;
-
- /* Remainder is ((n1 n0) - (m1 m0)) >> lsh */
- if (rp) {
- a.lo = n0, a.hi = n1;
- LL_SUB(a, a, m);
- rp->lo = (a.hi << rsh) | (a.lo >> lsh);
- rp->hi = a.hi >> lsh;
- }
- }
- }
+ if (b.hi > n1) {
+ /* (0 0) = (n1 n0) / (D1 d0) */
+
+ q0 = 0;
+ q1 = 0;
+
+ /* remainder in (n1 n0) */
+ if (rp) {
+ rp->lo = n0;
+ rp->hi = n1;
+ }
+ } else {
+ /* (0 q0) = (n1 n0) / (d1 d0) */
+
+ lsh = CountLeadingZeros(b.hi);
+ if (lsh == 0) {
+ /*
+ * From (n1 >= b.hi)
+ * && (the most significant bit of b.hi is set),
+ * conclude that
+ * (the most significant bit of n1 is set)
+ * && (the quotient digit q0 = 0 or 1).
+ *
+ * This special case is necessary, not an optimization.
+ */
+
+ /*
+ * The condition on the next line takes advantage of that
+ * n1 >= b.hi (true due to control flow).
+ */
+ if (n1 > b.hi || n0 >= b.lo) {
+ q0 = 1;
+ a.lo = n0, a.hi = n1;
+ LL_SUB(a, a, b);
+ } else {
+ q0 = 0;
+ }
+ q1 = 0;
+
+ if (rp) {
+ rp->lo = n0;
+ rp->hi = n1;
+ }
+ } else {
+ PRInt64 m;
+
+ /*
+ * Normalize.
+ */
+ rsh = 32 - lsh;
+
+ b.hi = (b.hi << lsh) | (b.lo >> rsh);
+ b.lo = b.lo << lsh;
+ n2 = n1 >> rsh;
+ n1 = (n1 << lsh) | (n0 >> rsh);
+ n0 = n0 << lsh;
+
+ a.lo = n1, a.hi = n2;
+ norm_udivmod32(&q0, &n1, a, b.hi);
+ LL_MUL32(m, q0, b.lo);
+
+ if ((m.hi > n1) || ((m.hi == n1) && (m.lo > n0))) {
+ q0--;
+ LL_SUB(m, m, b);
+ }
+
+ q1 = 0;
+
+ /* Remainder is ((n1 n0) - (m1 m0)) >> lsh */
+ if (rp) {
+ a.lo = n0, a.hi = n1;
+ LL_SUB(a, a, m);
+ rp->lo = (a.hi << rsh) | (a.lo >> lsh);
+ rp->hi = a.hi >> lsh;
+ }
+ }
+ }
}
if (qp) {
- qp->lo = q0;
- qp->hi = q1;
+ qp->lo = q0;
+ qp->hi = q1;
}
}
#endif /* !HAVE_LONG_LONG */
diff --git a/nsprpub/pr/src/misc/prnetdb.c b/nsprpub/pr/src/misc/prnetdb.c
index c482e8e4a..6ad0242d6 100644
--- a/nsprpub/pr/src/misc/prnetdb.c
+++ b/nsprpub/pr/src/misc/prnetdb.c
@@ -29,14 +29,13 @@ extern int h_errno;
* The meaning of the macros related to gethostbyname, gethostbyaddr,
* and gethostbyname2 is defined below.
* - _PR_HAVE_THREADSAFE_GETHOST: the gethostbyXXX functions return
- * the result in thread specific storage. For example, AIX, HP-UX,
- * and OSF1.
+ * the result in thread specific storage. For example, AIX, HP-UX.
* - _PR_HAVE_GETHOST_R: have the gethostbyXXX_r functions. See next
* two macros.
* - _PR_HAVE_GETHOST_R_INT: the gethostbyXXX_r functions return an
* int. For example, Linux glibc.
* - _PR_HAVE_GETHOST_R_POINTER: the gethostbyXXX_r functions return
- * a struct hostent* pointer. For example, Solaris and IRIX.
+ * a struct hostent* pointer. For example, Solaris.
*/
#if defined(_PR_NO_PREEMPT) || defined(_PR_HAVE_GETHOST_R) \
|| defined(_PR_HAVE_THREADSAFE_GETHOST)
@@ -58,23 +57,16 @@ PRLock *_pr_dnsLock = NULL;
* Some return a pointer to struct protoent, others return
* an int, and glibc's flavor takes five arguments.
*/
-#if defined(XP_BEOS) && defined(BONE_VERSION)
-#include <arpa/inet.h> /* pick up define for inet_addr */
-#include <sys/socket.h>
-#define _PR_HAVE_GETPROTO_R
-#define _PR_HAVE_GETPROTO_R_POINTER
-#endif
#if defined(SOLARIS) || (defined(BSDI) && defined(_REENTRANT)) \
- || (defined(LINUX) && defined(_REENTRANT) \
+ || (defined(LINUX) && defined(_REENTRANT) \
&& defined(__GLIBC__) && __GLIBC__ < 2)
#define _PR_HAVE_GETPROTO_R
#define _PR_HAVE_GETPROTO_R_POINTER
#endif
-#if defined(OSF1) \
- || defined(AIX4_3_PLUS) || (defined(AIX) && defined(_THREAD_SAFE)) \
- || (defined(HPUX10_10) && defined(_REENTRANT)) \
+#if defined(AIX4_3_PLUS) || (defined(AIX) && defined(_THREAD_SAFE)) \
+ || (defined(HPUX10_10) && defined(_REENTRANT)) \
|| (defined(HPUX10_20) && defined(_REENTRANT)) \
|| defined(OPENBSD)
#define _PR_HAVE_GETPROTO_R
@@ -87,7 +79,7 @@ PRLock *_pr_dnsLock = NULL;
#endif
/* BeOS has glibc but not the glibc-style getprotobyxxx_r functions. */
-#if (defined(__GLIBC__) && __GLIBC__ >= 2 && !defined(XP_BEOS))
+#if (defined(__GLIBC__) && __GLIBC__ >= 2)
#define _PR_HAVE_GETPROTO_R
#define _PR_HAVE_5_ARG_GETPROTO_R
#endif
@@ -100,48 +92,56 @@ PRLock* _getproto_lock = NULL;
extern PRBool _pr_ipv6_is_present(void);
#endif
-#define _PR_IN6_IS_ADDR_UNSPECIFIED(a) \
- (((a)->pr_s6_addr32[0] == 0) && \
- ((a)->pr_s6_addr32[1] == 0) && \
- ((a)->pr_s6_addr32[2] == 0) && \
- ((a)->pr_s6_addr32[3] == 0))
-
-#define _PR_IN6_IS_ADDR_LOOPBACK(a) \
- (((a)->pr_s6_addr32[0] == 0) && \
- ((a)->pr_s6_addr32[1] == 0) && \
- ((a)->pr_s6_addr32[2] == 0) && \
- ((a)->pr_s6_addr[12] == 0) && \
- ((a)->pr_s6_addr[13] == 0) && \
- ((a)->pr_s6_addr[14] == 0) && \
+#define _PR_IN6_IS_ADDR_UNSPECIFIED(a) \
+ (((a)->pr_s6_addr32[0] == 0) && \
+ ((a)->pr_s6_addr32[1] == 0) && \
+ ((a)->pr_s6_addr32[2] == 0) && \
+ ((a)->pr_s6_addr32[3] == 0))
+
+#define _PR_IN6_IS_ADDR_LOOPBACK(a) \
+ (((a)->pr_s6_addr32[0] == 0) && \
+ ((a)->pr_s6_addr32[1] == 0) && \
+ ((a)->pr_s6_addr32[2] == 0) && \
+ ((a)->pr_s6_addr[12] == 0) && \
+ ((a)->pr_s6_addr[13] == 0) && \
+ ((a)->pr_s6_addr[14] == 0) && \
((a)->pr_s6_addr[15] == 0x1U))
-
-const PRIPv6Addr _pr_in6addr_any = {{{ 0, 0, 0, 0,
- 0, 0, 0, 0,
- 0, 0, 0, 0,
- 0, 0, 0, 0 }}};
-
-const PRIPv6Addr _pr_in6addr_loopback = {{{ 0, 0, 0, 0,
- 0, 0, 0, 0,
- 0, 0, 0, 0,
- 0, 0, 0, 0x1U }}};
+
+const PRIPv6Addr _pr_in6addr_any = {{{
+ 0, 0, 0, 0,
+ 0, 0, 0, 0,
+ 0, 0, 0, 0,
+ 0, 0, 0, 0
+ }
+ }
+};
+
+const PRIPv6Addr _pr_in6addr_loopback = {{{
+ 0, 0, 0, 0,
+ 0, 0, 0, 0,
+ 0, 0, 0, 0,
+ 0, 0, 0, 0x1U
+ }
+ }
+};
/*
* The values at bytes 10 and 11 are compared using pointers to
* 8-bit fields, and not 32-bit fields, to make the comparison work on
* both big-endian and little-endian systems
*/
-#define _PR_IN6_IS_ADDR_V4MAPPED(a) \
- (((a)->pr_s6_addr32[0] == 0) && \
- ((a)->pr_s6_addr32[1] == 0) && \
- ((a)->pr_s6_addr[8] == 0) && \
- ((a)->pr_s6_addr[9] == 0) && \
- ((a)->pr_s6_addr[10] == 0xff) && \
- ((a)->pr_s6_addr[11] == 0xff))
+#define _PR_IN6_IS_ADDR_V4MAPPED(a) \
+ (((a)->pr_s6_addr32[0] == 0) && \
+ ((a)->pr_s6_addr32[1] == 0) && \
+ ((a)->pr_s6_addr[8] == 0) && \
+ ((a)->pr_s6_addr[9] == 0) && \
+ ((a)->pr_s6_addr[10] == 0xff) && \
+ ((a)->pr_s6_addr[11] == 0xff))
-#define _PR_IN6_IS_ADDR_V4COMPAT(a) \
- (((a)->pr_s6_addr32[0] == 0) && \
- ((a)->pr_s6_addr32[1] == 0) && \
- ((a)->pr_s6_addr32[2] == 0))
+#define _PR_IN6_IS_ADDR_V4COMPAT(a) \
+ (((a)->pr_s6_addr32[0] == 0) && \
+ ((a)->pr_s6_addr32[1] == 0) && \
+ ((a)->pr_s6_addr32[2] == 0))
#define _PR_IN6_V4MAPPED_TO_IPADDR(a) ((a)->pr_s6_addr32[3])
@@ -247,8 +247,9 @@ _pr_QueryNetIfs(void)
return;
}
} else {
- if (ifc.ifc_len == lastlen)
- break; /* success, len has not changed */
+ if (ifc.ifc_len == lastlen) {
+ break; /* success, len has not changed */
+ }
lastlen = ifc.ifc_len;
}
len += 10 * sizeof(struct ifreq); /* increment */
@@ -271,13 +272,13 @@ _pr_QueryNetIfs(void)
struct sockaddr_in *sin = (struct sockaddr_in *) sa;
if (sin->sin_addr.s_addr != htonl(INADDR_LOOPBACK)) {
_pr_have_inet_if = PR_TRUE;
- }
+ }
} else if (sa->sa_family == AF_INET6) {
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sa;
if (!IN6_IS_ADDR_LOOPBACK(&sin6->sin6_addr)
- && !IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
+ && !IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
_pr_have_inet6_if = PR_TRUE;
- }
+ }
}
#ifdef _PR_HAVE_SOCKADDR_LEN
@@ -285,16 +286,16 @@ _pr_QueryNetIfs(void)
#else
switch (sa->sa_family) {
#ifdef AF_LINK
- case AF_LINK:
- sa_len = sizeof(struct sockaddr_dl);
- break;
-#endif
- case AF_INET6:
- sa_len = sizeof(struct sockaddr_in6);
- break;
- default:
- sa_len = sizeof(struct sockaddr);
- break;
+ case AF_LINK:
+ sa_len = sizeof(struct sockaddr_dl);
+ break;
+#endif
+ case AF_INET6:
+ sa_len = sizeof(struct sockaddr_in6);
+ break;
+ default:
+ sa_len = sizeof(struct sockaddr);
+ break;
}
#endif
ifr = (struct ifreq *)(((char *)sa) + sa_len);
@@ -360,15 +361,15 @@ _pr_QueryNetIfs(void)
struct sockaddr_in *sin = (struct sockaddr_in *) sa;
if (sin->sin_addr.s_addr != htonl(INADDR_LOOPBACK)) {
_pr_have_inet_if = 1;
- }
+ }
} else if (sa->sa_family == AF_INET6) {
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *) sa;
if (!IN6_IS_ADDR_LOOPBACK(&sin6->sin6_addr)
- && !IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
+ && !IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
_pr_have_inet6_if = 1;
- }
+ }
}
- }
+ }
freeifaddrs(ifp);
}
@@ -393,21 +394,21 @@ void _PR_InitNet(void)
{
#if defined(XP_UNIX)
#ifdef HAVE_NETCONFIG
- /*
- * This one-liner prevents the endless re-open's and re-read's of
- * /etc/netconfig on EACH and EVERY call to accept(), connect(), etc.
- */
- (void)setnetconfig();
+ /*
+ * This one-liner prevents the endless re-open's and re-read's of
+ * /etc/netconfig on EACH and EVERY call to accept(), connect(), etc.
+ */
+ (void)setnetconfig();
#endif
#endif
#if !defined(_PR_NO_DNS_LOCK)
- _pr_dnsLock = PR_NewLock();
+ _pr_dnsLock = PR_NewLock();
#endif
#if !defined(_PR_HAVE_GETPROTO_R)
- _getproto_lock = PR_NewLock();
+ _getproto_lock = PR_NewLock();
#endif
#if defined(_PR_INET6) && defined(_PR_HAVE_GETHOSTBYNAME2)
- _pr_query_ifs_lock = PR_NewLock();
+ _pr_query_ifs_lock = PR_NewLock();
#endif
}
@@ -439,23 +440,23 @@ void _PR_CleanupNet(void)
*/
static char *Alloc(PRIntn amount, char **bufp, PRIntn *buflenp, PRIntn align)
{
- char *buf = *bufp;
- PRIntn buflen = *buflenp;
-
- if (align && ((long)buf & (align - 1))) {
- PRIntn skip = align - ((ptrdiff_t)buf & (align - 1));
- if (buflen < skip) {
- return 0;
- }
- buf += skip;
- buflen -= skip;
- }
- if (buflen < amount) {
- return 0;
- }
- *bufp = buf + amount;
- *buflenp = buflen - amount;
- return buf;
+ char *buf = *bufp;
+ PRIntn buflen = *buflenp;
+
+ if (align && ((long)buf & (align - 1))) {
+ PRIntn skip = align - ((ptrdiff_t)buf & (align - 1));
+ if (buflen < skip) {
+ return 0;
+ }
+ buf += skip;
+ buflen -= skip;
+ }
+ if (buflen < amount) {
+ return 0;
+ }
+ *bufp = buf + amount;
+ *buflenp = buflen - amount;
+ return buf;
}
typedef enum _PRIPAddrConversion {
@@ -494,98 +495,92 @@ static PRStatus CopyHostent(
_PRIPAddrConversion conversion,
PRHostEnt *to)
{
- PRIntn len, na;
- char **ap;
-
- if (conversion != _PRIPAddrNoConversion
- && from->h_addrtype == AF_INET) {
- PR_ASSERT(from->h_length == 4);
- to->h_addrtype = PR_AF_INET6;
- to->h_length = 16;
- } else {
-#if defined(_PR_INET6) || defined(_PR_INET6_PROBE)
- if (AF_INET6 == from->h_addrtype)
- to->h_addrtype = PR_AF_INET6;
- else
-#endif
- to->h_addrtype = from->h_addrtype;
- to->h_length = from->h_length;
- }
-
- /* Copy the official name */
- if (!from->h_name) return PR_FAILURE;
- len = strlen(from->h_name) + 1;
- to->h_name = Alloc(len, buf, bufsize, 0);
- if (!to->h_name) return PR_FAILURE;
- memcpy(to->h_name, from->h_name, len);
-
- /* Count the aliases, then allocate storage for the pointers */
- if (!from->h_aliases) {
- na = 1;
- } else {
- for (na = 1, ap = from->h_aliases; *ap != 0; na++, ap++){;} /* nothing to execute */
- }
- to->h_aliases = (char**)Alloc(
- na * sizeof(char*), buf, bufsize, sizeof(char**));
- if (!to->h_aliases) return PR_FAILURE;
-
- /* Copy the aliases, one at a time */
- if (!from->h_aliases) {
- to->h_aliases[0] = 0;
- } else {
- for (na = 0, ap = from->h_aliases; *ap != 0; na++, ap++) {
- len = strlen(*ap) + 1;
- to->h_aliases[na] = Alloc(len, buf, bufsize, 0);
- if (!to->h_aliases[na]) return PR_FAILURE;
- memcpy(to->h_aliases[na], *ap, len);
- }
- to->h_aliases[na] = 0;
- }
-
- /* Count the addresses, then allocate storage for the pointers */
- for (na = 1, ap = from->h_addr_list; *ap != 0; na++, ap++){;} /* nothing to execute */
- to->h_addr_list = (char**)Alloc(
- na * sizeof(char*), buf, bufsize, sizeof(char**));
- if (!to->h_addr_list) return PR_FAILURE;
-
- /* Copy the addresses, one at a time */
- for (na = 0, ap = from->h_addr_list; *ap != 0; na++, ap++) {
- to->h_addr_list[na] = Alloc(to->h_length, buf, bufsize, 0);
- if (!to->h_addr_list[na]) return PR_FAILURE;
- if (conversion != _PRIPAddrNoConversion
- && from->h_addrtype == AF_INET) {
- if (conversion == _PRIPAddrIPv4Mapped) {
- MakeIPv4MappedAddr(*ap, to->h_addr_list[na]);
- } else {
- PR_ASSERT(conversion == _PRIPAddrIPv4Compat);
- MakeIPv4CompatAddr(*ap, to->h_addr_list[na]);
- }
- } else {
- memcpy(to->h_addr_list[na], *ap, to->h_length);
- }
- }
- to->h_addr_list[na] = 0;
- return PR_SUCCESS;
-}
+ PRIntn len, na;
+ char **ap;
-#ifdef SYMBIAN
-/* Set p_aliases by hand because Symbian's getprotobyname() returns NULL. */
-static void AssignAliases(struct protoent *Protoent, char** aliases)
-{
- if (NULL == Protoent->p_aliases) {
- if (0 == strcmp(Protoent->p_name, "ip"))
- aliases[0] = "IP";
- else if (0 == strcmp(Protoent->p_name, "tcp"))
- aliases[0] = "TCP";
- else if (0 == strcmp(Protoent->p_name, "udp"))
- aliases[0] = "UDP";
+ if (conversion != _PRIPAddrNoConversion
+ && from->h_addrtype == AF_INET) {
+ PR_ASSERT(from->h_length == 4);
+ to->h_addrtype = PR_AF_INET6;
+ to->h_length = 16;
+ } else {
+#if defined(_PR_INET6) || defined(_PR_INET6_PROBE)
+ if (AF_INET6 == from->h_addrtype) {
+ to->h_addrtype = PR_AF_INET6;
+ }
else
- aliases[0] = "UNKNOWN";
- aliases[1] = NULL;
- Protoent->p_aliases = aliases;
+#endif
+ to->h_addrtype = from->h_addrtype;
+ to->h_length = from->h_length;
}
+
+ /* Copy the official name */
+ if (!from->h_name) {
+ return PR_FAILURE;
+ }
+ len = strlen(from->h_name) + 1;
+ to->h_name = Alloc(len, buf, bufsize, 0);
+ if (!to->h_name) {
+ return PR_FAILURE;
+ }
+ memcpy(to->h_name, from->h_name, len);
+
+ /* Count the aliases, then allocate storage for the pointers */
+ if (!from->h_aliases) {
+ na = 1;
+ } else {
+ for (na = 1, ap = from->h_aliases; *ap != 0; na++, ap++) {;} /* nothing to execute */
+ }
+ to->h_aliases = (char**)Alloc(
+ na * sizeof(char*), buf, bufsize, sizeof(char**));
+ if (!to->h_aliases) {
+ return PR_FAILURE;
+ }
+
+ /* Copy the aliases, one at a time */
+ if (!from->h_aliases) {
+ to->h_aliases[0] = 0;
+ } else {
+ for (na = 0, ap = from->h_aliases; *ap != 0; na++, ap++) {
+ len = strlen(*ap) + 1;
+ to->h_aliases[na] = Alloc(len, buf, bufsize, 0);
+ if (!to->h_aliases[na]) {
+ return PR_FAILURE;
+ }
+ memcpy(to->h_aliases[na], *ap, len);
+ }
+ to->h_aliases[na] = 0;
+ }
+
+ /* Count the addresses, then allocate storage for the pointers */
+ for (na = 1, ap = from->h_addr_list; *ap != 0; na++, ap++) {;} /* nothing to execute */
+ to->h_addr_list = (char**)Alloc(
+ na * sizeof(char*), buf, bufsize, sizeof(char**));
+ if (!to->h_addr_list) {
+ return PR_FAILURE;
+ }
+
+ /* Copy the addresses, one at a time */
+ for (na = 0, ap = from->h_addr_list; *ap != 0; na++, ap++) {
+ to->h_addr_list[na] = Alloc(to->h_length, buf, bufsize, 0);
+ if (!to->h_addr_list[na]) {
+ return PR_FAILURE;
+ }
+ if (conversion != _PRIPAddrNoConversion
+ && from->h_addrtype == AF_INET) {
+ if (conversion == _PRIPAddrIPv4Mapped) {
+ MakeIPv4MappedAddr(*ap, to->h_addr_list[na]);
+ } else {
+ PR_ASSERT(conversion == _PRIPAddrIPv4Compat);
+ MakeIPv4CompatAddr(*ap, to->h_addr_list[na]);
+ }
+ } else {
+ memcpy(to->h_addr_list[na], *ap, to->h_length);
+ }
+ }
+ to->h_addr_list[na] = 0;
+ return PR_SUCCESS;
}
-#endif
#if !defined(_PR_HAVE_GETPROTO_R)
/*
@@ -595,35 +590,43 @@ static void AssignAliases(struct protoent *Protoent, char** aliases)
static PRStatus CopyProtoent(
struct protoent *from, char *buf, PRIntn bufsize, PRProtoEnt *to)
{
- PRIntn len, na;
- char **ap;
-
- /* Do the easy stuff */
- to->p_num = from->p_proto;
-
- /* Copy the official name */
- if (!from->p_name) return PR_FAILURE;
- len = strlen(from->p_name) + 1;
- to->p_name = Alloc(len, &buf, &bufsize, 0);
- if (!to->p_name) return PR_FAILURE;
- memcpy(to->p_name, from->p_name, len);
-
- /* Count the aliases, then allocate storage for the pointers */
- for (na = 1, ap = from->p_aliases; *ap != 0; na++, ap++){;} /* nothing to execute */
- to->p_aliases = (char**)Alloc(
- na * sizeof(char*), &buf, &bufsize, sizeof(char**));
- if (!to->p_aliases) return PR_FAILURE;
-
- /* Copy the aliases, one at a time */
- for (na = 0, ap = from->p_aliases; *ap != 0; na++, ap++) {
- len = strlen(*ap) + 1;
- to->p_aliases[na] = Alloc(len, &buf, &bufsize, 0);
- if (!to->p_aliases[na]) return PR_FAILURE;
- memcpy(to->p_aliases[na], *ap, len);
- }
- to->p_aliases[na] = 0;
-
- return PR_SUCCESS;
+ PRIntn len, na;
+ char **ap;
+
+ /* Do the easy stuff */
+ to->p_num = from->p_proto;
+
+ /* Copy the official name */
+ if (!from->p_name) {
+ return PR_FAILURE;
+ }
+ len = strlen(from->p_name) + 1;
+ to->p_name = Alloc(len, &buf, &bufsize, 0);
+ if (!to->p_name) {
+ return PR_FAILURE;
+ }
+ memcpy(to->p_name, from->p_name, len);
+
+ /* Count the aliases, then allocate storage for the pointers */
+ for (na = 1, ap = from->p_aliases; *ap != 0; na++, ap++) {;} /* nothing to execute */
+ to->p_aliases = (char**)Alloc(
+ na * sizeof(char*), &buf, &bufsize, sizeof(char**));
+ if (!to->p_aliases) {
+ return PR_FAILURE;
+ }
+
+ /* Copy the aliases, one at a time */
+ for (na = 0, ap = from->p_aliases; *ap != 0; na++, ap++) {
+ len = strlen(*ap) + 1;
+ to->p_aliases[na] = Alloc(len, &buf, &bufsize, 0);
+ if (!to->p_aliases[na]) {
+ return PR_FAILURE;
+ }
+ memcpy(to->p_aliases[na], *ap, len);
+ }
+ to->p_aliases[na] = 0;
+
+ return PR_SUCCESS;
}
#endif /* !defined(_PR_HAVE_GETPROTO_R) */
@@ -631,7 +634,7 @@ static PRStatus CopyProtoent(
* #################################################################
* NOTE: tmphe, tmpbuf, bufsize, h, and h_err are local variables
* or arguments of PR_GetHostByName, PR_GetIPNodeByName, and
- * PR_GetHostByAddr. DO NOT CHANGE THE NAMES OF THESE LOCAL
+ * PR_GetHostByAddr. DO NOT CHANGE THE NAMES OF THESE LOCAL
* VARIABLES OR ARGUMENTS.
* #################################################################
*/
@@ -665,8 +668,8 @@ static PRStatus CopyProtoent(
PR_IMPLEMENT(PRStatus) PR_GetHostByName(
const char *name, char *buf, PRIntn bufsize, PRHostEnt *hp)
{
- struct hostent *h;
- PRStatus rv = PR_FAILURE;
+ struct hostent *h;
+ PRStatus rv = PR_FAILURE;
#if defined(_PR_HAVE_GETHOST_R)
char localbuf[PR_NETDB_BUF_SIZE];
char *tmpbuf;
@@ -674,7 +677,9 @@ PR_IMPLEMENT(PRStatus) PR_GetHostByName(
int h_err;
#endif
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
#if defined(_PR_HAVE_GETHOST_R)
tmpbuf = localbuf;
@@ -689,35 +694,37 @@ PR_IMPLEMENT(PRStatus) PR_GetHostByName(
}
#endif
- LOCK_DNS();
+ LOCK_DNS();
- h = GETHOSTBYNAME(name);
-
- if (NULL == h)
- {
- PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_GETHOST_ERRNO());
- }
- else
- {
- _PRIPAddrConversion conversion = _PRIPAddrNoConversion;
- rv = CopyHostent(h, &buf, &bufsize, conversion, hp);
- if (PR_SUCCESS != rv)
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
- }
- UNLOCK_DNS();
+ h = GETHOSTBYNAME(name);
+
+ if (NULL == h)
+ {
+ PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_GETHOST_ERRNO());
+ }
+ else
+ {
+ _PRIPAddrConversion conversion = _PRIPAddrNoConversion;
+ rv = CopyHostent(h, &buf, &bufsize, conversion, hp);
+ if (PR_SUCCESS != rv) {
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
+ }
+ }
+ UNLOCK_DNS();
#if defined(_PR_HAVE_GETHOST_R)
- if (tmpbuf != localbuf)
+ if (tmpbuf != localbuf) {
PR_Free(tmpbuf);
+ }
#endif
- return rv;
+ return rv;
}
#if !defined(_PR_INET6) && \
defined(_PR_INET6_PROBE) && defined(_PR_HAVE_GETIPNODEBYNAME)
typedef struct hostent * (*_pr_getipnodebyname_t)(const char *, int,
- int, int *);
+ int, int *);
typedef struct hostent * (*_pr_getipnodebyaddr_t)(const void *, size_t,
- int, int *);
+ int, int *);
typedef void (*_pr_freehostent_t)(struct hostent *);
static void * _pr_getipnodebyname_fp;
static void * _pr_getipnodebyaddr_fp;
@@ -730,7 +737,7 @@ static void * _pr_freehostent_fp;
PRStatus
_pr_find_getipnodebyname(void)
{
- PRLibrary *lib;
+ PRLibrary *lib;
PRStatus rv;
#define GETIPNODEBYNAME "getipnodebyname"
#define GETIPNODEBYADDR "getipnodebyaddr"
@@ -741,15 +748,19 @@ _pr_find_getipnodebyname(void)
_pr_freehostent_fp = PR_FindSymbol(lib, FREEHOSTENT);
if (NULL != _pr_freehostent_fp) {
_pr_getipnodebyaddr_fp = PR_FindSymbol(lib, GETIPNODEBYADDR);
- if (NULL != _pr_getipnodebyaddr_fp)
+ if (NULL != _pr_getipnodebyaddr_fp) {
rv = PR_SUCCESS;
- else
+ }
+ else {
rv = PR_FAILURE;
- } else
+ }
+ } else {
rv = PR_FAILURE;
+ }
(void)PR_UnloadLibrary(lib);
- } else
+ } else {
rv = PR_FAILURE;
+ }
return rv;
}
#endif
@@ -767,15 +778,17 @@ static PRStatus AppendV4AddrsToHostent(
PRIntn na, na_old;
char **ap;
char **new_addr_list;
-
+
/* Count the addresses, then grow storage for the pointers */
for (na_old = 0, ap = to->h_addr_list; *ap != 0; na_old++, ap++)
- {;} /* nothing to execute */
+ {;} /* nothing to execute */
for (na = na_old + 1, ap = from->h_addr_list; *ap != 0; na++, ap++)
- {;} /* nothing to execute */
+ {;} /* nothing to execute */
new_addr_list = (char**)Alloc(
- na * sizeof(char*), buf, bufsize, sizeof(char**));
- if (!new_addr_list) return PR_FAILURE;
+ na * sizeof(char*), buf, bufsize, sizeof(char**));
+ if (!new_addr_list) {
+ return PR_FAILURE;
+ }
/* Copy the V6 addresses, one at a time */
for (na = 0, ap = to->h_addr_list; *ap != 0; na++, ap++) {
@@ -786,7 +799,9 @@ static PRStatus AppendV4AddrsToHostent(
/* Copy the V4 addresses, one at a time */
for (ap = from->h_addr_list; *ap != 0; na++, ap++) {
to->h_addr_list[na] = Alloc(to->h_length, buf, bufsize, 0);
- if (!to->h_addr_list[na]) return PR_FAILURE;
+ if (!to->h_addr_list[na]) {
+ return PR_FAILURE;
+ }
MakeIPv4MappedAddr(*ap, to->h_addr_list[na]);
}
to->h_addr_list[na] = 0;
@@ -798,8 +813,8 @@ PR_IMPLEMENT(PRStatus) PR_GetIPNodeByName(
const char *name, PRUint16 af, PRIntn flags,
char *buf, PRIntn bufsize, PRHostEnt *hp)
{
- struct hostent *h = 0;
- PRStatus rv = PR_FAILURE;
+ struct hostent *h = 0;
+ PRStatus rv = PR_FAILURE;
#if defined(_PR_HAVE_GETHOST_R)
char localbuf[PR_NETDB_BUF_SIZE];
char *tmpbuf;
@@ -807,15 +822,17 @@ PR_IMPLEMENT(PRStatus) PR_GetIPNodeByName(
int h_err;
#endif
#if defined(_PR_HAVE_GETIPNODEBYNAME)
- PRUint16 md_af = af;
- int error_num;
- int tmp_flags = 0;
+ PRUint16 md_af = af;
+ int error_num;
+ int tmp_flags = 0;
#endif
#if defined(_PR_HAVE_GETHOSTBYNAME2)
PRBool did_af_inet = PR_FALSE;
#endif
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
if (af != PR_AF_INET && af != PR_AF_INET6) {
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
@@ -830,28 +847,35 @@ PR_IMPLEMENT(PRStatus) PR_GetIPNodeByName(
* machine going from offline to online.
*/
if (!_pr_have_inet_if && !_pr_have_inet6_if) {
- _pr_QueryNetIfs();
+ _pr_QueryNetIfs();
#ifdef DEBUG_QUERY_IFS
- if (_pr_have_inet_if)
- printf("Have IPv4 source address\n");
- if (_pr_have_inet6_if)
- printf("Have IPv6 source address\n");
+ if (_pr_have_inet_if) {
+ printf("Have IPv4 source address\n");
+ }
+ if (_pr_have_inet6_if) {
+ printf("Have IPv6 source address\n");
+ }
#endif
}
PR_Unlock(_pr_query_ifs_lock);
#endif
#if defined(_PR_HAVE_GETIPNODEBYNAME)
- if (flags & PR_AI_V4MAPPED)
- tmp_flags |= AI_V4MAPPED;
- if (flags & PR_AI_ADDRCONFIG)
- tmp_flags |= AI_ADDRCONFIG;
- if (flags & PR_AI_ALL)
- tmp_flags |= AI_ALL;
- if (af == PR_AF_INET6)
- md_af = AF_INET6;
- else
- md_af = af;
+ if (flags & PR_AI_V4MAPPED) {
+ tmp_flags |= AI_V4MAPPED;
+ }
+ if (flags & PR_AI_ADDRCONFIG) {
+ tmp_flags |= AI_ADDRCONFIG;
+ }
+ if (flags & PR_AI_ALL) {
+ tmp_flags |= AI_ALL;
+ }
+ if (af == PR_AF_INET6) {
+ md_af = AF_INET6;
+ }
+ else {
+ md_af = af;
+ }
#endif
#if defined(_PR_HAVE_GETHOST_R)
@@ -876,12 +900,12 @@ PR_IMPLEMENT(PRStatus) PR_GetIPNodeByName(
if ((flags & PR_AI_ADDRCONFIG) == 0 || _pr_have_inet6_if)
{
#ifdef _PR_INET6_PROBE
- if (_pr_ipv6_is_present())
+ if (_pr_ipv6_is_present())
#endif
- h = GETHOSTBYNAME2(name, AF_INET6);
+ h = GETHOSTBYNAME2(name, AF_INET6);
}
if ((NULL == h) && (flags & PR_AI_V4MAPPED)
- && ((flags & PR_AI_ADDRCONFIG) == 0 || _pr_have_inet_if))
+ && ((flags & PR_AI_ADDRCONFIG) == 0 || _pr_have_inet_if))
{
did_af_inet = PR_TRUE;
h = GETHOSTBYNAME2(name, AF_INET);
@@ -899,97 +923,106 @@ PR_IMPLEMENT(PRStatus) PR_GetIPNodeByName(
h = getipnodebyname(name, md_af, tmp_flags, &error_num);
#else
#error "Unknown name-to-address translation function"
-#endif /* _PR_HAVE_GETHOSTBYNAME2 */
+#endif /* _PR_HAVE_GETHOSTBYNAME2 */
#elif defined(_PR_INET6_PROBE) && defined(_PR_HAVE_GETIPNODEBYNAME)
if (_pr_ipv6_is_present())
{
#ifdef PR_GETIPNODE_NOT_THREADSAFE
LOCK_DNS();
#endif
- h = (*((_pr_getipnodebyname_t)_pr_getipnodebyname_fp))(name, md_af, tmp_flags, &error_num);
+ h = (*((_pr_getipnodebyname_t)_pr_getipnodebyname_fp))(name, md_af, tmp_flags, &error_num);
}
else
{
LOCK_DNS();
- h = GETHOSTBYNAME(name);
+ h = GETHOSTBYNAME(name);
}
#else /* _PR_INET6 */
LOCK_DNS();
h = GETHOSTBYNAME(name);
#endif /* _PR_INET6 */
-
- if (NULL == h)
- {
+
+ if (NULL == h)
+ {
#if defined(_PR_INET6) && defined(_PR_HAVE_GETIPNODEBYNAME)
- PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, error_num);
+ PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, error_num);
#elif defined(_PR_INET6_PROBE) && defined(_PR_HAVE_GETIPNODEBYNAME)
- if (_pr_ipv6_is_present())
- PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, error_num);
- else
- PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_GETHOST_ERRNO());
+ if (_pr_ipv6_is_present()) {
+ PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, error_num);
+ }
+ else {
+ PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_GETHOST_ERRNO());
+ }
#else
- PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_GETHOST_ERRNO());
+ PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_GETHOST_ERRNO());
#endif
- }
- else
- {
- _PRIPAddrConversion conversion = _PRIPAddrNoConversion;
+ }
+ else
+ {
+ _PRIPAddrConversion conversion = _PRIPAddrNoConversion;
- if (af == PR_AF_INET6) conversion = _PRIPAddrIPv4Mapped;
- rv = CopyHostent(h, &buf, &bufsize, conversion, hp);
- if (PR_SUCCESS != rv)
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
+ if (af == PR_AF_INET6) {
+ conversion = _PRIPAddrIPv4Mapped;
+ }
+ rv = CopyHostent(h, &buf, &bufsize, conversion, hp);
+ if (PR_SUCCESS != rv) {
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
+ }
#if defined(_PR_INET6) && defined(_PR_HAVE_GETIPNODEBYNAME)
- freehostent(h);
+ freehostent(h);
#elif defined(_PR_INET6_PROBE) && defined(_PR_HAVE_GETIPNODEBYNAME)
- if (_pr_ipv6_is_present())
- (*((_pr_freehostent_t)_pr_freehostent_fp))(h);
+ if (_pr_ipv6_is_present()) {
+ (*((_pr_freehostent_t)_pr_freehostent_fp))(h);
+ }
#endif
#if defined(_PR_INET6) && defined(_PR_HAVE_GETHOSTBYNAME2)
- if ((PR_SUCCESS == rv) && (flags & PR_AI_V4MAPPED)
- && ((flags & PR_AI_ALL)
- || ((flags & PR_AI_ADDRCONFIG) && _pr_have_inet_if))
- && !did_af_inet && (h = GETHOSTBYNAME2(name, AF_INET)) != 0) {
- rv = AppendV4AddrsToHostent(h, &buf, &bufsize, hp);
- if (PR_SUCCESS != rv)
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
- }
+ if ((PR_SUCCESS == rv) && (flags & PR_AI_V4MAPPED)
+ && ((flags & PR_AI_ALL)
+ || ((flags & PR_AI_ADDRCONFIG) && _pr_have_inet_if))
+ && !did_af_inet && (h = GETHOSTBYNAME2(name, AF_INET)) != 0) {
+ rv = AppendV4AddrsToHostent(h, &buf, &bufsize, hp);
+ if (PR_SUCCESS != rv) {
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
+ }
+ }
#endif
- }
+ }
/* Must match the convoluted logic above for LOCK_DNS() */
#ifdef _PR_INET6
#ifdef _PR_HAVE_GETHOSTBYNAME2
UNLOCK_DNS();
-#endif /* _PR_HAVE_GETHOSTBYNAME2 */
+#endif /* _PR_HAVE_GETHOSTBYNAME2 */
#elif defined(_PR_INET6_PROBE) && defined(_PR_HAVE_GETIPNODEBYNAME)
#ifdef PR_GETIPNODE_NOT_THREADSAFE
UNLOCK_DNS();
#else
- if (!_pr_ipv6_is_present())
+ if (!_pr_ipv6_is_present()) {
UNLOCK_DNS();
+ }
#endif
#else /* _PR_INET6 */
UNLOCK_DNS();
#endif /* _PR_INET6 */
#if defined(_PR_HAVE_GETHOST_R)
- if (tmpbuf != localbuf)
+ if (tmpbuf != localbuf) {
PR_Free(tmpbuf);
+ }
#endif
- return rv;
+ return rv;
}
PR_IMPLEMENT(PRStatus) PR_GetHostByAddr(
const PRNetAddr *hostaddr, char *buf, PRIntn bufsize, PRHostEnt *hostentry)
{
- struct hostent *h;
- PRStatus rv = PR_FAILURE;
- const void *addr;
- PRUint32 tmp_ip;
- int addrlen;
- PRInt32 af;
+ struct hostent *h;
+ PRStatus rv = PR_FAILURE;
+ const void *addr;
+ PRUint32 tmp_ip;
+ int addrlen;
+ PRInt32 af;
#if defined(_PR_HAVE_GETHOST_R)
char localbuf[PR_NETDB_BUF_SIZE];
char *tmpbuf;
@@ -997,55 +1030,58 @@ PR_IMPLEMENT(PRStatus) PR_GetHostByAddr(
int h_err;
#endif
#if defined(_PR_HAVE_GETIPNODEBYADDR)
- int error_num;
+ int error_num;
#endif
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
- if (hostaddr->raw.family == PR_AF_INET6)
- {
+ if (hostaddr->raw.family == PR_AF_INET6)
+ {
#if defined(_PR_INET6_PROBE)
- af = _pr_ipv6_is_present() ? AF_INET6 : AF_INET;
+ af = _pr_ipv6_is_present() ? AF_INET6 : AF_INET;
#elif defined(_PR_INET6)
- af = AF_INET6;
+ af = AF_INET6;
#else
- af = AF_INET;
+ af = AF_INET;
#endif
#if defined(_PR_GHBA_DISALLOW_V4MAPPED)
- if (_PR_IN6_IS_ADDR_V4MAPPED(&hostaddr->ipv6.ip))
- af = AF_INET;
-#endif
- }
- else
- {
- PR_ASSERT(hostaddr->raw.family == AF_INET);
- af = AF_INET;
- }
- if (hostaddr->raw.family == PR_AF_INET6) {
+ if (_PR_IN6_IS_ADDR_V4MAPPED(&hostaddr->ipv6.ip)) {
+ af = AF_INET;
+ }
+#endif
+ }
+ else
+ {
+ PR_ASSERT(hostaddr->raw.family == AF_INET);
+ af = AF_INET;
+ }
+ if (hostaddr->raw.family == PR_AF_INET6) {
#if defined(_PR_INET6) || defined(_PR_INET6_PROBE)
- if (af == AF_INET6) {
- addr = &hostaddr->ipv6.ip;
- addrlen = sizeof(hostaddr->ipv6.ip);
- }
- else
-#endif
- {
- PR_ASSERT(af == AF_INET);
- if (!_PR_IN6_IS_ADDR_V4MAPPED(&hostaddr->ipv6.ip)) {
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
- return rv;
- }
- tmp_ip = _PR_IN6_V4MAPPED_TO_IPADDR((PRIPv6Addr *)
- &hostaddr->ipv6.ip);
- addr = &tmp_ip;
- addrlen = sizeof(tmp_ip);
- }
- } else {
- PR_ASSERT(hostaddr->raw.family == AF_INET);
- PR_ASSERT(af == AF_INET);
- addr = &hostaddr->inet.ip;
- addrlen = sizeof(hostaddr->inet.ip);
- }
+ if (af == AF_INET6) {
+ addr = &hostaddr->ipv6.ip;
+ addrlen = sizeof(hostaddr->ipv6.ip);
+ }
+ else
+#endif
+ {
+ PR_ASSERT(af == AF_INET);
+ if (!_PR_IN6_IS_ADDR_V4MAPPED(&hostaddr->ipv6.ip)) {
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+ return rv;
+ }
+ tmp_ip = _PR_IN6_V4MAPPED_TO_IPADDR((PRIPv6Addr *)
+ &hostaddr->ipv6.ip);
+ addr = &tmp_ip;
+ addrlen = sizeof(tmp_ip);
+ }
+ } else {
+ PR_ASSERT(hostaddr->raw.family == AF_INET);
+ PR_ASSERT(af == AF_INET);
+ addr = &hostaddr->inet.ip;
+ addrlen = sizeof(hostaddr->inet.ip);
+ }
#if defined(_PR_HAVE_GETHOST_R)
tmpbuf = localbuf;
@@ -1062,63 +1098,66 @@ PR_IMPLEMENT(PRStatus) PR_GetHostByAddr(
/* Do not need to lock the DNS lock if getipnodebyaddr() is called */
#if defined(_PR_HAVE_GETIPNODEBYADDR) && defined(_PR_INET6)
- h = getipnodebyaddr(addr, addrlen, af, &error_num);
+ h = getipnodebyaddr(addr, addrlen, af, &error_num);
#elif defined(_PR_HAVE_GETIPNODEBYADDR) && defined(_PR_INET6_PROBE)
if (_pr_ipv6_is_present())
{
#ifdef PR_GETIPNODE_NOT_THREADSAFE
LOCK_DNS();
#endif
- h = (*((_pr_getipnodebyaddr_t)_pr_getipnodebyaddr_fp))(addr, addrlen,
- af, &error_num);
+ h = (*((_pr_getipnodebyaddr_t)_pr_getipnodebyaddr_fp))(addr, addrlen,
+ af, &error_num);
}
- else
+ else
{
LOCK_DNS();
- h = GETHOSTBYADDR(addr, addrlen, af);
+ h = GETHOSTBYADDR(addr, addrlen, af);
}
-#else /* _PR_HAVE_GETIPNODEBYADDR */
+#else /* _PR_HAVE_GETIPNODEBYADDR */
LOCK_DNS();
- h = GETHOSTBYADDR(addr, addrlen, af);
+ h = GETHOSTBYADDR(addr, addrlen, af);
#endif /* _PR_HAVE_GETIPNODEBYADDR */
- if (NULL == h)
- {
+ if (NULL == h)
+ {
#if defined(_PR_INET6) && defined(_PR_HAVE_GETIPNODEBYADDR)
- PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, error_num);
+ PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, error_num);
#elif defined(_PR_INET6_PROBE) && defined(_PR_HAVE_GETIPNODEBYADDR)
- if (_pr_ipv6_is_present())
- PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, error_num);
- else
- PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_GETHOST_ERRNO());
+ if (_pr_ipv6_is_present()) {
+ PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, error_num);
+ }
+ else {
+ PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_GETHOST_ERRNO());
+ }
#else
- PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_GETHOST_ERRNO());
-#endif
- }
- else
- {
- _PRIPAddrConversion conversion = _PRIPAddrNoConversion;
- if (hostaddr->raw.family == PR_AF_INET6) {
- if (af == AF_INET) {
- if (_PR_IN6_IS_ADDR_V4MAPPED((PRIPv6Addr*)
- &hostaddr->ipv6.ip)) {
- conversion = _PRIPAddrIPv4Mapped;
- } else if (_PR_IN6_IS_ADDR_V4COMPAT((PRIPv6Addr *)
- &hostaddr->ipv6.ip)) {
- conversion = _PRIPAddrIPv4Compat;
- }
- }
- }
- rv = CopyHostent(h, &buf, &bufsize, conversion, hostentry);
- if (PR_SUCCESS != rv) {
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
- }
+ PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_GETHOST_ERRNO());
+#endif
+ }
+ else
+ {
+ _PRIPAddrConversion conversion = _PRIPAddrNoConversion;
+ if (hostaddr->raw.family == PR_AF_INET6) {
+ if (af == AF_INET) {
+ if (_PR_IN6_IS_ADDR_V4MAPPED((PRIPv6Addr*)
+ &hostaddr->ipv6.ip)) {
+ conversion = _PRIPAddrIPv4Mapped;
+ } else if (_PR_IN6_IS_ADDR_V4COMPAT((PRIPv6Addr *)
+ &hostaddr->ipv6.ip)) {
+ conversion = _PRIPAddrIPv4Compat;
+ }
+ }
+ }
+ rv = CopyHostent(h, &buf, &bufsize, conversion, hostentry);
+ if (PR_SUCCESS != rv) {
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
+ }
#if defined(_PR_INET6) && defined(_PR_HAVE_GETIPNODEBYADDR)
- freehostent(h);
+ freehostent(h);
#elif defined(_PR_INET6_PROBE) && defined(_PR_HAVE_GETIPNODEBYADDR)
- if (_pr_ipv6_is_present())
- (*((_pr_freehostent_t)_pr_freehostent_fp))(h);
+ if (_pr_ipv6_is_present()) {
+ (*((_pr_freehostent_t)_pr_freehostent_fp))(h);
+ }
#endif
- }
+ }
/* Must match the convoluted logic above for LOCK_DNS() */
#if defined(_PR_HAVE_GETIPNODEBYADDR) && defined(_PR_INET6)
@@ -1126,19 +1165,21 @@ PR_IMPLEMENT(PRStatus) PR_GetHostByAddr(
#ifdef PR_GETIPNODE_NOT_THREADSAFE
UNLOCK_DNS();
#else
- if (!_pr_ipv6_is_present())
+ if (!_pr_ipv6_is_present()) {
UNLOCK_DNS();
+ }
#endif
-#else /* _PR_HAVE_GETIPNODEBYADDR */
+#else /* _PR_HAVE_GETIPNODEBYADDR */
UNLOCK_DNS();
#endif /* _PR_HAVE_GETIPNODEBYADDR */
#if defined(_PR_HAVE_GETHOST_R)
- if (tmpbuf != localbuf)
+ if (tmpbuf != localbuf) {
PR_Free(tmpbuf);
+ }
#endif
- return rv;
+ return rv;
}
/******************************************************************************/
@@ -1169,12 +1210,12 @@ PR_IMPLEMENT(PRStatus) PR_GetHostByAddr(
static struct protoent *getprotobyname_r(const char* name)
{
- return getprotobyname(name);
+ return getprotobyname(name);
} /* getprotobyname_r */
static struct protoent *getprotobynumber_r(PRInt32 number)
{
- return getprotobynumber(number);
+ return getprotobynumber(number);
} /* getprotobynumber_r */
#endif /* !defined(_PR_HAVE_GETPROTO_R) */
@@ -1182,12 +1223,14 @@ static struct protoent *getprotobynumber_r(PRInt32 number)
PR_IMPLEMENT(PRStatus) PR_GetProtoByName(
const char* name, char* buffer, PRInt32 buflen, PRProtoEnt* result)
{
- PRStatus rv = PR_SUCCESS;
+ PRStatus rv = PR_SUCCESS;
#if defined(_PR_HAVE_GETPROTO_R)
- struct protoent* res = (struct protoent*)result;
+ struct protoent* res = (struct protoent*)result;
#endif
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
#if defined(_PR_HAVE_GETPROTO_R_INT)
{
@@ -1225,7 +1268,7 @@ PR_IMPLEMENT(PRStatus) PR_GetProtoByName(
** at least the size of a struct protoent_data.
*/
memset(buffer, 0, buflen);
- if (-1 == getprotobyname_r(name, res, (struct protoent_data*)buffer))
+ if (-1 == getprotobyname_r(name, res, (struct protoent_data*)buffer))
{
PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_ERRNO());
return PR_FAILURE;
@@ -1238,27 +1281,24 @@ PR_IMPLEMENT(PRStatus) PR_GetProtoByName(
return PR_FAILURE;
}
#else /* do it the hard way */
- {
- struct protoent *staticBuf;
- PR_Lock(_getproto_lock);
- staticBuf = getprotobyname_r(name);
- if (NULL == staticBuf)
- {
- rv = PR_FAILURE;
- PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_ERRNO());
- }
- else
- {
-#if defined(SYMBIAN)
- char* aliases[2];
- AssignAliases(staticBuf, aliases);
-#endif
- rv = CopyProtoent(staticBuf, buffer, buflen, result);
- if (PR_FAILURE == rv)
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
- }
- PR_Unlock(_getproto_lock);
- }
+ {
+ struct protoent *staticBuf;
+ PR_Lock(_getproto_lock);
+ staticBuf = getprotobyname_r(name);
+ if (NULL == staticBuf)
+ {
+ rv = PR_FAILURE;
+ PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_ERRNO());
+ }
+ else
+ {
+ rv = CopyProtoent(staticBuf, buffer, buflen, result);
+ if (PR_FAILURE == rv) {
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
+ }
+ }
+ PR_Unlock(_getproto_lock);
+ }
#endif /* all that */
return rv;
}
@@ -1266,12 +1306,14 @@ PR_IMPLEMENT(PRStatus) PR_GetProtoByName(
PR_IMPLEMENT(PRStatus) PR_GetProtoByNumber(
PRInt32 number, char* buffer, PRInt32 buflen, PRProtoEnt* result)
{
- PRStatus rv = PR_SUCCESS;
+ PRStatus rv = PR_SUCCESS;
#if defined(_PR_HAVE_GETPROTO_R)
- struct protoent* res = (struct protoent*)result;
+ struct protoent* res = (struct protoent*)result;
#endif
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
#if defined(_PR_HAVE_GETPROTO_R_INT)
{
@@ -1309,7 +1351,7 @@ PR_IMPLEMENT(PRStatus) PR_GetProtoByNumber(
** The buffer needs to be zero'd for these OS's.
*/
memset(buffer, 0, buflen);
- if (-1 == getprotobynumber_r(number, res, (struct protoent_data*)buffer))
+ if (-1 == getprotobynumber_r(number, res, (struct protoent_data*)buffer))
{
PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_ERRNO());
return PR_FAILURE;
@@ -1322,27 +1364,24 @@ PR_IMPLEMENT(PRStatus) PR_GetProtoByNumber(
return PR_FAILURE;
}
#else /* do it the hard way */
- {
- struct protoent *staticBuf;
- PR_Lock(_getproto_lock);
- staticBuf = getprotobynumber_r(number);
- if (NULL == staticBuf)
- {
- rv = PR_FAILURE;
- PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_ERRNO());
- }
- else
- {
-#if defined(SYMBIAN)
- char* aliases[2];
- AssignAliases(staticBuf, aliases);
-#endif
- rv = CopyProtoent(staticBuf, buffer, buflen, result);
- if (PR_FAILURE == rv)
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
- }
- PR_Unlock(_getproto_lock);
- }
+ {
+ struct protoent *staticBuf;
+ PR_Lock(_getproto_lock);
+ staticBuf = getprotobynumber_r(number);
+ if (NULL == staticBuf)
+ {
+ rv = PR_FAILURE;
+ PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, _MD_ERRNO());
+ }
+ else
+ {
+ rv = CopyProtoent(staticBuf, buffer, buflen, result);
+ if (PR_FAILURE == rv) {
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
+ }
+ }
+ PR_Unlock(_getproto_lock);
+ }
#endif /* all that crap */
return rv;
@@ -1360,8 +1399,9 @@ PRUintn _PR_NetAddrSize(const PRNetAddr* addr)
* we take the size of struct sockaddr_in6 instead of
* addr->ipv6.
*/
- if (AF_INET == addr->raw.family)
+ if (AF_INET == addr->raw.family) {
addrsize = sizeof(addr->inet);
+ }
else if (PR_AF_INET6 == addr->raw.family)
#if defined(_PR_INET6)
addrsize = sizeof(struct sockaddr_in6);
@@ -1382,7 +1422,9 @@ PRUintn _PR_NetAddrSize(const PRNetAddr* addr)
addrsize = sizeof(addr->local);
}
#endif
- else addrsize = 0;
+ else {
+ addrsize = 0;
+ }
return addrsize;
} /* _PR_NetAddrSize */
@@ -1392,15 +1434,17 @@ PR_IMPLEMENT(PRIntn) PR_EnumerateHostEnt(
{
void *addr = hostEnt->h_addr_list[enumIndex++];
memset(address, 0, sizeof(PRNetAddr));
- if (NULL == addr) enumIndex = 0;
+ if (NULL == addr) {
+ enumIndex = 0;
+ }
else
{
address->raw.family = hostEnt->h_addrtype;
if (PR_AF_INET6 == hostEnt->h_addrtype)
{
address->ipv6.port = htons(port);
- address->ipv6.flowinfo = 0;
- address->ipv6.scope_id = 0;
+ address->ipv6.flowinfo = 0;
+ address->ipv6.scope_id = 0;
memcpy(&address->ipv6.ip, addr, hostEnt->h_length);
}
else
@@ -1417,25 +1461,29 @@ PR_IMPLEMENT(PRStatus) PR_InitializeNetAddr(
PRNetAddrValue val, PRUint16 port, PRNetAddr *addr)
{
PRStatus rv = PR_SUCCESS;
- if (!_pr_initialized) _PR_ImplicitInitialization();
-
- if (val != PR_IpAddrNull) memset(addr, 0, sizeof(*addr));
- addr->inet.family = AF_INET;
- addr->inet.port = htons(port);
- switch (val)
- {
- case PR_IpAddrNull:
- break; /* don't overwrite the address */
- case PR_IpAddrAny:
- addr->inet.ip = htonl(INADDR_ANY);
- break;
- case PR_IpAddrLoopback:
- addr->inet.ip = htonl(INADDR_LOOPBACK);
- break;
- default:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
- rv = PR_FAILURE;
- }
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
+
+ if (val != PR_IpAddrNull) {
+ memset(addr, 0, sizeof(*addr));
+ }
+ addr->inet.family = AF_INET;
+ addr->inet.port = htons(port);
+ switch (val)
+ {
+ case PR_IpAddrNull:
+ break; /* don't overwrite the address */
+ case PR_IpAddrAny:
+ addr->inet.ip = htonl(INADDR_ANY);
+ break;
+ case PR_IpAddrLoopback:
+ addr->inet.ip = htonl(INADDR_LOOPBACK);
+ break;
+ default:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+ rv = PR_FAILURE;
+ }
return rv;
} /* PR_InitializeNetAddr */
@@ -1443,48 +1491,54 @@ PR_IMPLEMENT(PRStatus) PR_SetNetAddr(
PRNetAddrValue val, PRUint16 af, PRUint16 port, PRNetAddr *addr)
{
PRStatus rv = PR_SUCCESS;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
if (af == PR_AF_INET6)
{
- if (val != PR_IpAddrNull) memset(addr, 0, sizeof(addr->ipv6));
+ if (val != PR_IpAddrNull) {
+ memset(addr, 0, sizeof(addr->ipv6));
+ }
addr->ipv6.family = af;
addr->ipv6.port = htons(port);
addr->ipv6.flowinfo = 0;
addr->ipv6.scope_id = 0;
switch (val)
{
- case PR_IpAddrNull:
- break; /* don't overwrite the address */
- case PR_IpAddrAny:
- addr->ipv6.ip = _pr_in6addr_any;
- break;
- case PR_IpAddrLoopback:
- addr->ipv6.ip = _pr_in6addr_loopback;
- break;
- default:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
- rv = PR_FAILURE;
+ case PR_IpAddrNull:
+ break; /* don't overwrite the address */
+ case PR_IpAddrAny:
+ addr->ipv6.ip = _pr_in6addr_any;
+ break;
+ case PR_IpAddrLoopback:
+ addr->ipv6.ip = _pr_in6addr_loopback;
+ break;
+ default:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+ rv = PR_FAILURE;
}
}
else
{
- if (val != PR_IpAddrNull) memset(addr, 0, sizeof(addr->inet));
+ if (val != PR_IpAddrNull) {
+ memset(addr, 0, sizeof(addr->inet));
+ }
addr->inet.family = af;
addr->inet.port = htons(port);
switch (val)
{
- case PR_IpAddrNull:
- break; /* don't overwrite the address */
- case PR_IpAddrAny:
- addr->inet.ip = htonl(INADDR_ANY);
- break;
- case PR_IpAddrLoopback:
- addr->inet.ip = htonl(INADDR_LOOPBACK);
- break;
- default:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
- rv = PR_FAILURE;
+ case PR_IpAddrNull:
+ break; /* don't overwrite the address */
+ case PR_IpAddrAny:
+ addr->inet.ip = htonl(INADDR_ANY);
+ break;
+ case PR_IpAddrLoopback:
+ addr->inet.ip = htonl(INADDR_LOOPBACK);
+ break;
+ default:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+ rv = PR_FAILURE;
}
}
return rv;
@@ -1495,25 +1549,25 @@ PR_IsNetAddrType(const PRNetAddr *addr, PRNetAddrValue val)
{
if (addr->raw.family == PR_AF_INET6) {
if (val == PR_IpAddrAny) {
- if (_PR_IN6_IS_ADDR_UNSPECIFIED((PRIPv6Addr *)&addr->ipv6.ip)) {
- return PR_TRUE;
- }
+ if (_PR_IN6_IS_ADDR_UNSPECIFIED((PRIPv6Addr *)&addr->ipv6.ip)) {
+ return PR_TRUE;
+ }
if (_PR_IN6_IS_ADDR_V4MAPPED((PRIPv6Addr *)&addr->ipv6.ip)
&& _PR_IN6_V4MAPPED_TO_IPADDR((PRIPv6Addr *)&addr->ipv6.ip)
== htonl(INADDR_ANY)) {
return PR_TRUE;
- }
+ }
} else if (val == PR_IpAddrLoopback) {
if (_PR_IN6_IS_ADDR_LOOPBACK((PRIPv6Addr *)&addr->ipv6.ip)) {
- return PR_TRUE;
- }
+ return PR_TRUE;
+ }
if (_PR_IN6_IS_ADDR_V4MAPPED((PRIPv6Addr *)&addr->ipv6.ip)
&& _PR_IN6_V4MAPPED_TO_IPADDR((PRIPv6Addr *)&addr->ipv6.ip)
== htonl(INADDR_LOOPBACK)) {
return PR_TRUE;
- }
+ }
} else if (val == PR_IpAddrV4Mapped
- && _PR_IN6_IS_ADDR_V4MAPPED((PRIPv6Addr *)&addr->ipv6.ip)) {
+ && _PR_IN6_IS_ADDR_V4MAPPED((PRIPv6Addr *)&addr->ipv6.ip)) {
return PR_TRUE;
}
} else {
@@ -1537,7 +1591,7 @@ static const unsigned char index_hex[256] = {
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,XX,XX, XX,XX,XX,XX,
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,XX,XX, XX,XX,XX,XX,
XX,10,11,12, 13,14,15,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX, XX,XX,XX,XX,
XX,10,11,12, 13,14,15,XX, XX,XX,XX,XX, XX,XX,XX,XX,
@@ -1570,16 +1624,22 @@ static int StringToV6Addr(const char *string, PRIPv6Addr *addr)
/* Handle initial (double) colon */
if (*s == ':') {
- if (s[1] != ':') return 0;
+ if (s[1] != ':') {
+ return 0;
+ }
s += 2;
addr->pr_s6_addr16[0] = 0;
section = double_colon = 1;
}
while (*s) {
- if (section == 8) return 0; /* too long */
+ if (section == 8) {
+ return 0; /* too long */
+ }
if (*s == ':') {
- if (double_colon != -1) return 0; /* two double colons */
+ if (double_colon != -1) {
+ return 0; /* two double colons */
+ }
addr->pr_s6_addr16[section++] = 0;
double_colon = section;
s++;
@@ -1589,70 +1649,96 @@ static int StringToV6Addr(const char *string, PRIPv6Addr *addr)
val = (val << 4) + index_hex[*s++];
}
if (*s == '.') {
- if (len == 0) return 0; /* nothing between : and . */
+ if (len == 0) {
+ return 0; /* nothing between : and . */
+ }
break;
}
if (*s == ':') {
s++;
- if (!*s) return 0; /* cannot end with single colon */
+ if (!*s) {
+ return 0; /* cannot end with single colon */
+ }
} else if (*s) {
return 0; /* bad character */
}
addr->pr_s6_addr16[section++] = htons((unsigned short)val);
}
-
+
if (*s == '.') {
/* Have a trailing v4 format address */
- if (section > 6) return 0; /* not enough room */
+ if (section > 6) {
+ return 0; /* not enough room */
+ }
/*
* The number before the '.' is decimal, but we parsed it
* as hex. That means it is in BCD. Check it for validity
* and convert it to binary.
*/
- if (val > 0x0255 || (val & 0xf0) > 0x90 || (val & 0xf) > 9) return 0;
+ if (val > 0x0255 || (val & 0xf0) > 0x90 || (val & 0xf) > 9) {
+ return 0;
+ }
val = (val >> 8) * 100 + ((val >> 4) & 0xf) * 10 + (val & 0xf);
addr->pr_s6_addr[2 * section] = val;
s++;
val = index_hex[*s++];
- if (val > 9) return 0;
+ if (val > 9) {
+ return 0;
+ }
while (*s >= '0' && *s <= '9') {
val = val * 10 + *s++ - '0';
- if (val > 255) return 0;
+ if (val > 255) {
+ return 0;
+ }
+ }
+ if (*s != '.') {
+ return 0; /* must have exactly 4 decimal numbers */
}
- if (*s != '.') return 0; /* must have exactly 4 decimal numbers */
addr->pr_s6_addr[2 * section + 1] = val;
section++;
s++;
val = index_hex[*s++];
- if (val > 9) return 0;
+ if (val > 9) {
+ return 0;
+ }
while (*s >= '0' && *s <= '9') {
val = val * 10 + *s++ - '0';
- if (val > 255) return 0;
+ if (val > 255) {
+ return 0;
+ }
+ }
+ if (*s != '.') {
+ return 0; /* must have exactly 4 decimal numbers */
}
- if (*s != '.') return 0; /* must have exactly 4 decimal numbers */
addr->pr_s6_addr[2 * section] = val;
s++;
val = index_hex[*s++];
- if (val > 9) return 0;
+ if (val > 9) {
+ return 0;
+ }
while (*s >= '0' && *s <= '9') {
val = val * 10 + *s++ - '0';
- if (val > 255) return 0;
+ if (val > 255) {
+ return 0;
+ }
+ }
+ if (*s) {
+ return 0; /* must have exactly 4 decimal numbers */
}
- if (*s) return 0; /* must have exactly 4 decimal numbers */
addr->pr_s6_addr[2 * section + 1] = val;
section++;
}
-
+
if (double_colon != -1) {
/* Stretch the double colon */
int tosection;
int ncopy = section - double_colon;
for (tosection = 7; ncopy--; tosection--) {
- addr->pr_s6_addr16[tosection] =
+ addr->pr_s6_addr16[tosection] =
addr->pr_s6_addr16[double_colon + ncopy];
}
while (tosection >= double_colon) {
@@ -1726,20 +1812,36 @@ static const char *V6AddrToString(
STUFF('f');
STUFF(':');
}
- if (addr->pr_s6_addr[12] > 99) STUFF(addr->pr_s6_addr[12]/100 + '0');
- if (addr->pr_s6_addr[12] > 9) STUFF((addr->pr_s6_addr[12]%100)/10 + '0');
+ if (addr->pr_s6_addr[12] > 99) {
+ STUFF(addr->pr_s6_addr[12]/100 + '0');
+ }
+ if (addr->pr_s6_addr[12] > 9) {
+ STUFF((addr->pr_s6_addr[12]%100)/10 + '0');
+ }
STUFF(addr->pr_s6_addr[12]%10 + '0');
STUFF('.');
- if (addr->pr_s6_addr[13] > 99) STUFF(addr->pr_s6_addr[13]/100 + '0');
- if (addr->pr_s6_addr[13] > 9) STUFF((addr->pr_s6_addr[13]%100)/10 + '0');
+ if (addr->pr_s6_addr[13] > 99) {
+ STUFF(addr->pr_s6_addr[13]/100 + '0');
+ }
+ if (addr->pr_s6_addr[13] > 9) {
+ STUFF((addr->pr_s6_addr[13]%100)/10 + '0');
+ }
STUFF(addr->pr_s6_addr[13]%10 + '0');
STUFF('.');
- if (addr->pr_s6_addr[14] > 99) STUFF(addr->pr_s6_addr[14]/100 + '0');
- if (addr->pr_s6_addr[14] > 9) STUFF((addr->pr_s6_addr[14]%100)/10 + '0');
+ if (addr->pr_s6_addr[14] > 99) {
+ STUFF(addr->pr_s6_addr[14]/100 + '0');
+ }
+ if (addr->pr_s6_addr[14] > 9) {
+ STUFF((addr->pr_s6_addr[14]%100)/10 + '0');
+ }
STUFF(addr->pr_s6_addr[14]%10 + '0');
STUFF('.');
- if (addr->pr_s6_addr[15] > 99) STUFF(addr->pr_s6_addr[15]/100 + '0');
- if (addr->pr_s6_addr[15] > 9) STUFF((addr->pr_s6_addr[15]%100)/10 + '0');
+ if (addr->pr_s6_addr[15] > 99) {
+ STUFF(addr->pr_s6_addr[15]/100 + '0');
+ }
+ if (addr->pr_s6_addr[15] > 9) {
+ STUFF((addr->pr_s6_addr[15]%100)/10 + '0');
+ }
STUFF(addr->pr_s6_addr[15]%10 + '0');
STUFF('\0');
return bufcopy;
@@ -1765,11 +1867,13 @@ static const char *V6AddrToString(
}
STUFF(basis_hex[val & 0xf]);
section++;
- if (section < 8 && section != double_colon) STUFF(':');
+ if (section < 8 && section != double_colon) {
+ STUFF(':');
+ }
}
STUFF('\0');
return bufcopy;
-#undef STUFF
+#undef STUFF
}
#endif /* !_PR_HAVE_INET_NTOP */
@@ -1785,10 +1889,18 @@ PR_IMPLEMENT(void) PR_ConvertIPv4AddrToIPv6(PRUint32 v4addr, PRIPv6Addr *v6addr)
memcpy(dstp + 12,(char *) &v4addr, 4);
}
-PR_IMPLEMENT(PRUint16) PR_ntohs(PRUint16 n) { return ntohs(n); }
-PR_IMPLEMENT(PRUint32) PR_ntohl(PRUint32 n) { return ntohl(n); }
-PR_IMPLEMENT(PRUint16) PR_htons(PRUint16 n) { return htons(n); }
-PR_IMPLEMENT(PRUint32) PR_htonl(PRUint32 n) { return htonl(n); }
+PR_IMPLEMENT(PRUint16) PR_ntohs(PRUint16 n) {
+ return ntohs(n);
+}
+PR_IMPLEMENT(PRUint32) PR_ntohl(PRUint32 n) {
+ return ntohl(n);
+}
+PR_IMPLEMENT(PRUint16) PR_htons(PRUint16 n) {
+ return htons(n);
+}
+PR_IMPLEMENT(PRUint32) PR_htonl(PRUint32 n) {
+ return htonl(n);
+}
PR_IMPLEMENT(PRUint64) PR_ntohll(PRUint64 n)
{
#ifdef IS_BIG_ENDIAN
@@ -1849,23 +1961,23 @@ typedef struct addrinfo PRADDRINFO;
typedef struct addrinfo PRADDRINFO;
-/* getaddrinfo/freeaddrinfo/getnameinfo prototypes */
+/* getaddrinfo/freeaddrinfo/getnameinfo prototypes */
#if defined(WIN32)
#define FUNC_MODIFIER __stdcall
#else
#define FUNC_MODIFIER
#endif
typedef int (FUNC_MODIFIER * FN_GETADDRINFO)
- (const char *nodename,
- const char *servname,
- const PRADDRINFO *hints,
- PRADDRINFO **res);
+(const char *nodename,
+ const char *servname,
+ const PRADDRINFO *hints,
+ PRADDRINFO **res);
typedef int (FUNC_MODIFIER * FN_FREEADDRINFO)
- (PRADDRINFO *ai);
+(PRADDRINFO *ai);
typedef int (FUNC_MODIFIER * FN_GETNAMEINFO)
- (const struct sockaddr *addr, int addrlen,
- char *host, int hostlen,
- char *serv, int servlen, int flags);
+(const struct sockaddr *addr, int addrlen,
+ char *host, int hostlen,
+ char *serv, int servlen, int flags);
/* global state */
static FN_GETADDRINFO _pr_getaddrinfo = NULL;
@@ -1896,15 +2008,15 @@ _pr_find_getaddrinfo(void)
continue;
}
_pr_getaddrinfo = (FN_GETADDRINFO)
- PR_FindFunctionSymbol(lib, GETADDRINFO_SYMBOL);
+ PR_FindFunctionSymbol(lib, GETADDRINFO_SYMBOL);
if (!_pr_getaddrinfo) {
PR_UnloadLibrary(lib);
continue;
}
_pr_freeaddrinfo = (FN_FREEADDRINFO)
- PR_FindFunctionSymbol(lib, FREEADDRINFO_SYMBOL);
+ PR_FindFunctionSymbol(lib, FREEADDRINFO_SYMBOL);
_pr_getnameinfo = (FN_GETNAMEINFO)
- PR_FindFunctionSymbol(lib, GETNAMEINFO_SYMBOL);
+ PR_FindFunctionSymbol(lib, GETNAMEINFO_SYMBOL);
if (!_pr_freeaddrinfo || !_pr_getnameinfo) {
PR_UnloadLibrary(lib);
continue;
@@ -1919,14 +2031,14 @@ _pr_find_getaddrinfo(void)
* search library containing getaddrinfo for freeaddrinfo.
*/
_pr_getaddrinfo = (FN_GETADDRINFO)
- PR_FindFunctionSymbolAndLibrary(GETADDRINFO_SYMBOL, &lib);
+ PR_FindFunctionSymbolAndLibrary(GETADDRINFO_SYMBOL, &lib);
if (!_pr_getaddrinfo) {
return PR_FAILURE;
}
_pr_freeaddrinfo = (FN_FREEADDRINFO)
- PR_FindFunctionSymbol(lib, FREEADDRINFO_SYMBOL);
+ PR_FindFunctionSymbol(lib, FREEADDRINFO_SYMBOL);
_pr_getnameinfo = (FN_GETNAMEINFO)
- PR_FindFunctionSymbol(lib, GETNAMEINFO_SYMBOL);
+ PR_FindFunctionSymbol(lib, GETNAMEINFO_SYMBOL);
PR_UnloadLibrary(lib);
if (!_pr_freeaddrinfo || !_pr_getnameinfo) {
return PR_FAILURE;
@@ -1946,7 +2058,7 @@ _pr_find_getaddrinfo(void)
#if !defined(_PR_HAVE_GETADDRINFO) || defined(_PR_INET6_PROBE)
/*
* If getaddrinfo does not exist, then we will fall back on
- * PR_GetHostByName, which requires that we allocate a buffer for the
+ * PR_GetHostByName, which requires that we allocate a buffer for the
* PRHostEnt data structure and its members.
*/
typedef struct PRAddrInfoFB {
@@ -1980,8 +2092,8 @@ pr_GetAddrInfoByNameFB(const char *hostname,
#endif /* !_PR_HAVE_GETADDRINFO || _PR_INET6_PROBE */
PR_IMPLEMENT(PRAddrInfo *) PR_GetAddrInfoByName(const char *hostname,
- PRUint16 af,
- PRIntn flags)
+ PRUint16 af,
+ PRIntn flags)
{
/* restrict input to supported values */
if ((af != PR_AF_INET && af != PR_AF_UNSPEC) ||
@@ -1990,7 +2102,9 @@ PR_IMPLEMENT(PRAddrInfo *) PR_GetAddrInfoByName(const char *hostname,
return NULL;
}
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
#if !defined(_PR_HAVE_GETADDRINFO)
return pr_GetAddrInfoByNameFB(hostname, af, flags);
@@ -2011,14 +2125,15 @@ PR_IMPLEMENT(PRAddrInfo *) PR_GetAddrInfoByName(const char *hostname,
*/
memset(&hints, 0, sizeof(hints));
- if (!(flags & PR_AI_NOCANONNAME))
+ if (!(flags & PR_AI_NOCANONNAME)) {
hints.ai_flags |= AI_CANONNAME;
+ }
#ifdef AI_ADDRCONFIG
- /*
+ /*
* Propagate AI_ADDRCONFIG to the GETADDRINFO call if PR_AI_ADDRCONFIG
* is set.
- *
- * Need a workaround for loopback host addresses:
+ *
+ * Need a workaround for loopback host addresses:
* The problem is that in glibc and Windows, AI_ADDRCONFIG applies the
* existence of an outgoing network interface to IP addresses of the
* loopback interface, due to a strict interpretation of the
@@ -2055,8 +2170,9 @@ PR_IMPLEMENT(PRAddrInfo *) PR_GetAddrInfoByName(const char *hostname,
rv = GETADDRINFO(hostname, NULL, &hints, &res);
}
#endif
- if (rv == 0)
+ if (rv == 0) {
return (PRAddrInfo *) res;
+ }
PR_SetError(PR_DIRECTORY_LOOKUP_ERROR, rv);
}
@@ -2068,8 +2184,9 @@ PR_IMPLEMENT(void) PR_FreeAddrInfo(PRAddrInfo *ai)
{
#if defined(_PR_HAVE_GETADDRINFO)
#if defined(_PR_INET6_PROBE)
- if (!_pr_ipv6_is_present())
+ if (!_pr_ipv6_is_present()) {
PR_Free((PRAddrInfoFB *) ai);
+ }
else
#endif
FREEADDRINFO((PRADDRINFO *) ai);
@@ -2079,9 +2196,9 @@ PR_IMPLEMENT(void) PR_FreeAddrInfo(PRAddrInfo *ai)
}
PR_IMPLEMENT(void *) PR_EnumerateAddrInfo(void *iterPtr,
- const PRAddrInfo *base,
- PRUint16 port,
- PRNetAddr *result)
+ const PRAddrInfo *base,
+ PRUint16 port,
+ PRNetAddr *result)
{
#if defined(_PR_HAVE_GETADDRINFO)
PRADDRINFO *ai;
@@ -2090,35 +2207,43 @@ PR_IMPLEMENT(void *) PR_EnumerateAddrInfo(void *iterPtr,
/* using PRAddrInfoFB */
PRIntn iter = (PRIntn)(PRPtrdiff) iterPtr;
iter = PR_EnumerateHostEnt(iter, &((PRAddrInfoFB *) base)->hostent, port, result);
- if (iter < 0)
+ if (iter < 0) {
iter = 0;
+ }
return (void *)(PRPtrdiff) iter;
}
#endif
- if (iterPtr)
+ if (iterPtr) {
ai = ((PRADDRINFO *) iterPtr)->ai_next;
- else
+ }
+ else {
ai = (PRADDRINFO *) base;
+ }
- while (ai && ai->ai_addrlen > sizeof(PRNetAddr))
+ while (ai && ai->ai_addrlen > sizeof(PRNetAddr)) {
ai = ai->ai_next;
+ }
if (ai) {
/* copy sockaddr to PRNetAddr */
memcpy(result, ai->ai_addr, ai->ai_addrlen);
result->raw.family = ai->ai_addr->sa_family;
#ifdef _PR_INET6
- if (AF_INET6 == result->raw.family)
+ if (AF_INET6 == result->raw.family) {
result->raw.family = PR_AF_INET6;
+ }
#endif
- if (ai->ai_addrlen < sizeof(PRNetAddr))
+ if (ai->ai_addrlen < sizeof(PRNetAddr)) {
memset(((char*)result)+ai->ai_addrlen, 0, sizeof(PRNetAddr) - ai->ai_addrlen);
+ }
- if (result->raw.family == PR_AF_INET)
+ if (result->raw.family == PR_AF_INET) {
result->inet.port = htons(port);
- else
+ }
+ else {
result->ipv6.port = htons(port);
+ }
}
return ai;
@@ -2126,8 +2251,9 @@ PR_IMPLEMENT(void *) PR_EnumerateAddrInfo(void *iterPtr,
/* using PRAddrInfoFB */
PRIntn iter = (PRIntn) iterPtr;
iter = PR_EnumerateHostEnt(iter, &((PRAddrInfoFB *) base)->hostent, port, result);
- if (iter < 0)
+ if (iter < 0) {
iter = 0;
+ }
return (void *) iter;
#endif
}
@@ -2139,7 +2265,7 @@ PR_IMPLEMENT(const char *) PR_GetCanonNameFromAddrInfo(const PRAddrInfo *ai)
if (!_pr_ipv6_is_present()) {
const PRAddrInfoFB *fb = (const PRAddrInfoFB *) ai;
return fb->has_cname ? fb->hostent.h_name : NULL;
- }
+ }
#endif
return ((const PRADDRINFO *) ai)->ai_canonname;
#else
@@ -2221,7 +2347,9 @@ static PRStatus pr_StringToNetAddrFB(const char *string, PRNetAddr *addr)
PR_IMPLEMENT(PRStatus) PR_StringToNetAddr(const char *string, PRNetAddr *addr)
{
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
if (!addr || !string || !*string)
{
@@ -2238,12 +2366,14 @@ PR_IMPLEMENT(PRStatus) PR_StringToNetAddr(const char *string, PRNetAddr *addr)
* and most likely others. So we only use it to convert literal IP addresses
* that contain IPv6 scope IDs, which pr_inet_aton cannot convert.
*/
- if (!strchr(string, '%'))
+ if (!strchr(string, '%')) {
return pr_StringToNetAddrFB(string, addr);
+ }
#if defined(_PR_INET6_PROBE)
- if (!_pr_ipv6_is_present())
+ if (!_pr_ipv6_is_present()) {
return pr_StringToNetAddrFB(string, addr);
+ }
#endif
return pr_StringToNetAddrGAI(string, addr);
@@ -2282,7 +2412,7 @@ static PRStatus pr_NetAddrToStringGNI(
addrp = &addrcopy;
#endif
rv = GETNAMEINFO((const struct sockaddr *)addrp, addrlen,
- string, size, NULL, 0, NI_NUMERICHOST);
+ string, size, NULL, 0, NI_NUMERICHOST);
if (rv != 0)
{
PR_SetError(PR_INVALID_ARGUMENT_ERROR, rv);
@@ -2311,13 +2441,17 @@ static PRStatus pr_NetAddrToStringFB(
}
else
{
- if (size < 16) goto failed;
- if (AF_INET != addr->raw.family) goto failed;
+ if (size < 16) {
+ goto failed;
+ }
+ if (AF_INET != addr->raw.family) {
+ goto failed;
+ }
else
{
unsigned char *byte = (unsigned char*)&addr->inet.ip;
PR_snprintf(string, size, "%u.%u.%u.%u",
- byte[0], byte[1], byte[2], byte[3]);
+ byte[0], byte[1], byte[2], byte[3]);
}
}
@@ -2333,14 +2467,17 @@ failed:
PR_IMPLEMENT(PRStatus) PR_NetAddrToString(
const PRNetAddr *addr, char *string, PRUint32 size)
{
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
#if !defined(_PR_HAVE_GETADDRINFO)
return pr_NetAddrToStringFB(addr, string, size);
#else
#if defined(_PR_INET6_PROBE)
- if (!_pr_ipv6_is_present())
+ if (!_pr_ipv6_is_present()) {
return pr_NetAddrToStringFB(addr, string, size);
+ }
#endif
return pr_NetAddrToStringGNI(addr, string, size);
#endif
diff --git a/nsprpub/pr/src/misc/prolock.c b/nsprpub/pr/src/misc/prolock.c
index 38b778789..77a26bb2f 100644
--- a/nsprpub/pr/src/misc/prolock.c
+++ b/nsprpub/pr/src/misc/prolock.c
@@ -5,18 +5,18 @@
/*
** prolock.c -- NSPR Ordered Lock
-**
+**
** Implement the API defined in prolock.h
-**
+**
*/
#include "prolock.h"
#include "prlog.h"
#include "prerror.h"
-PR_IMPLEMENT(PROrderedLock *)
- PR_CreateOrderedLock(
- PRInt32 order,
- const char *name
+PR_IMPLEMENT(PROrderedLock *)
+PR_CreateOrderedLock(
+ PRInt32 order,
+ const char *name
)
{
PR_NOT_REACHED("Not implemented"); /* Not implemented yet */
@@ -25,9 +25,9 @@ PR_IMPLEMENT(PROrderedLock *)
} /* end PR_CreateOrderedLock() */
-PR_IMPLEMENT(void)
- PR_DestroyOrderedLock(
- PROrderedLock *lock
+PR_IMPLEMENT(void)
+PR_DestroyOrderedLock(
+ PROrderedLock *lock
)
{
PR_NOT_REACHED("Not implemented"); /* Not implemented yet */
@@ -35,9 +35,9 @@ PR_IMPLEMENT(void)
} /* end PR_DestroyOrderedLock() */
-PR_IMPLEMENT(void)
- PR_LockOrderedLock(
- PROrderedLock *lock
+PR_IMPLEMENT(void)
+PR_LockOrderedLock(
+ PROrderedLock *lock
)
{
PR_NOT_REACHED("Not implemented"); /* Not implemented yet */
@@ -45,9 +45,9 @@ PR_IMPLEMENT(void)
} /* end PR_LockOrderedLock() */
-PR_IMPLEMENT(PRStatus)
- PR_UnlockOrderedLock(
- PROrderedLock *lock
+PR_IMPLEMENT(PRStatus)
+PR_UnlockOrderedLock(
+ PROrderedLock *lock
)
{
PR_NOT_REACHED("Not implemented"); /* Not implemented yet */
diff --git a/nsprpub/pr/src/misc/prrng.c b/nsprpub/pr/src/misc/prrng.c
index b5c38f82d..b3e3d4878 100644
--- a/nsprpub/pr/src/misc/prrng.c
+++ b/nsprpub/pr/src/misc/prrng.c
@@ -16,15 +16,15 @@
#include <string.h>
#endif
-PRSize _pr_CopyLowBits(
- void *dst,
- PRSize dstlen,
- void *src,
+PRSize _pr_CopyLowBits(
+ void *dst,
+ PRSize dstlen,
+ void *src,
PRSize srclen )
{
if (srclen <= dstlen) {
- memcpy(dst, src, srclen);
- return srclen;
+ memcpy(dst, src, srclen);
+ return srclen;
}
#if defined IS_BIG_ENDIAN
memcpy(dst, (char*)src + (srclen - dstlen), dstlen);
@@ -32,9 +32,9 @@ PRSize _pr_CopyLowBits(
memcpy(dst, src, dstlen);
#endif
return dstlen;
-}
+}
-PR_IMPLEMENT(PRSize) PR_GetRandomNoise(
+PR_IMPLEMENT(PRSize) PR_GetRandomNoise(
void *buf,
PRSize size
)
diff --git a/nsprpub/pr/src/misc/prsystem.c b/nsprpub/pr/src/misc/prsystem.c
index eba85fb0b..825d3be0f 100644
--- a/nsprpub/pr/src/misc/prsystem.c
+++ b/nsprpub/pr/src/misc/prsystem.c
@@ -8,10 +8,6 @@
#include "prprf.h"
#include "prlong.h"
-#if defined(BEOS)
-#include <kernel/OS.h>
-#endif
-
#if defined(OS2)
#define INCL_DOS
#define INCL_DOSMISC
@@ -71,7 +67,7 @@ PR_IMPLEMENT(char) PR_GetDirectorySepartor(void)
static PRBool warn = PR_TRUE;
if (warn) {
warn = _PR_Obsolete("PR_GetDirectorySepartor()",
- "PR_GetDirectorySeparator()");
+ "PR_GetDirectorySeparator()");
}
#endif
return PR_GetDirectorySeparator();
@@ -86,84 +82,90 @@ PR_IMPLEMENT(PRStatus) PR_GetSystemInfo(PRSysInfo cmd, char *buf, PRUint32 bufle
{
PRUintn len = 0;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
switch(cmd)
{
- case PR_SI_HOSTNAME:
- case PR_SI_HOSTNAME_UNTRUNCATED:
- if (PR_FAILURE == _PR_MD_GETHOSTNAME(buf, (PRUintn)buflen))
- return PR_FAILURE;
+ case PR_SI_HOSTNAME:
+ case PR_SI_HOSTNAME_UNTRUNCATED:
+ if (PR_FAILURE == _PR_MD_GETHOSTNAME(buf, (PRUintn)buflen)) {
+ return PR_FAILURE;
+ }
- if (cmd == PR_SI_HOSTNAME_UNTRUNCATED)
- break;
- /*
- * On some platforms a system does not have a hostname and
- * its IP address is returned instead. The following code
- * should be skipped on those platforms.
- */
+ if (cmd == PR_SI_HOSTNAME_UNTRUNCATED) {
+ break;
+ }
+ /*
+ * On some platforms a system does not have a hostname and
+ * its IP address is returned instead. The following code
+ * should be skipped on those platforms.
+ */
#ifndef _PR_GET_HOST_ADDR_AS_NAME
- /* Return the unqualified hostname */
+ /* Return the unqualified hostname */
while (buf[len] && (len < buflen)) {
if (buf[len] == '.') {
buf[len] = '\0';
break;
}
len += 1;
- }
+ }
#endif
- break;
+ break;
- case PR_SI_SYSNAME:
- /* Return the operating system name */
+ case PR_SI_SYSNAME:
+ /* Return the operating system name */
#if defined(XP_UNIX) || defined(WIN32)
- if (PR_FAILURE == _PR_MD_GETSYSINFO(cmd, buf, (PRUintn)buflen))
- return PR_FAILURE;
+ if (PR_FAILURE == _PR_MD_GETSYSINFO(cmd, buf, (PRUintn)buflen)) {
+ return PR_FAILURE;
+ }
#else
- (void)PR_snprintf(buf, buflen, _PR_SI_SYSNAME);
+ (void)PR_snprintf(buf, buflen, _PR_SI_SYSNAME);
#endif
- break;
+ break;
- case PR_SI_RELEASE:
- /* Return the version of the operating system */
+ case PR_SI_RELEASE:
+ /* Return the version of the operating system */
#if defined(XP_UNIX) || defined(WIN32)
- if (PR_FAILURE == _PR_MD_GETSYSINFO(cmd, buf, (PRUintn)buflen))
- return PR_FAILURE;
+ if (PR_FAILURE == _PR_MD_GETSYSINFO(cmd, buf, (PRUintn)buflen)) {
+ return PR_FAILURE;
+ }
#endif
#if defined(XP_OS2)
- {
- ULONG os2ver[2] = {0};
- DosQuerySysInfo(QSV_VERSION_MINOR, QSV_VERSION_REVISION,
- &os2ver, sizeof(os2ver));
- /* Formatting for normal usage (2.11, 3.0, 4.0, 4.5); officially,
- Warp 4 is version 2.40.00, WSeB 2.45.00 */
- if (os2ver[0] < 30)
- (void)PR_snprintf(buf, buflen, "%s%lu",
- "2.", os2ver[0]);
- else if (os2ver[0] < 45)
- (void)PR_snprintf(buf, buflen, "%lu%s%lu",
- os2ver[0]/10, ".", os2ver[1]);
- else
- (void)PR_snprintf(buf, buflen, "%.1f",
- os2ver[0]/10.0);
- }
+ {
+ ULONG os2ver[2] = {0};
+ DosQuerySysInfo(QSV_VERSION_MINOR, QSV_VERSION_REVISION,
+ &os2ver, sizeof(os2ver));
+ /* Formatting for normal usage (2.11, 3.0, 4.0, 4.5); officially,
+ Warp 4 is version 2.40.00, WSeB 2.45.00 */
+ if (os2ver[0] < 30)
+ (void)PR_snprintf(buf, buflen, "%s%lu",
+ "2.", os2ver[0]);
+ else if (os2ver[0] < 45)
+ (void)PR_snprintf(buf, buflen, "%lu%s%lu",
+ os2ver[0]/10, ".", os2ver[1]);
+ else
+ (void)PR_snprintf(buf, buflen, "%.1f",
+ os2ver[0]/10.0);
+ }
#endif /* OS2 */
- break;
-
- case PR_SI_ARCHITECTURE:
- /* Return the architecture of the machine (ie. x86, mips, alpha, ...)*/
- (void)PR_snprintf(buf, buflen, _PR_SI_ARCHITECTURE);
- break;
- default:
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
- return PR_FAILURE;
+ break;
+
+ case PR_SI_ARCHITECTURE:
+ /* Return the architecture of the machine (ie. x86, mips, alpha, ...)*/
+ (void)PR_snprintf(buf, buflen, _PR_SI_ARCHITECTURE);
+ break;
+ default:
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+ return PR_FAILURE;
}
return PR_SUCCESS;
}
/*
** PR_GetNumberOfProcessors()
-**
+**
** Implementation notes:
** Every platform does it a bit different.
** numCpus is the returned value.
@@ -173,7 +175,7 @@ PR_IMPLEMENT(PRStatus) PR_GetSystemInfo(PRSysInfo cmd, char *buf, PRUint32 bufle
** order of the if defined()s may be important,
** especially for unix variants. Do platform
** specific implementations before XP_UNIX.
-**
+**
*/
PR_IMPLEMENT(PRInt32) PR_GetNumberOfProcessors( void )
{
@@ -183,11 +185,6 @@ PR_IMPLEMENT(PRInt32) PR_GetNumberOfProcessors( void )
GetSystemInfo( &info );
numCpus = info.dwNumberOfProcessors;
-#elif defined(BEOS)
- system_info sysInfo;
-
- get_system_info(&sysInfo);
- numCpus = sysInfo.cpu_count;
#elif defined(OS2)
DosQuerySysInfo( QSV_NUMPROCESSORS, QSV_NUMPROCESSORS, &numCpus, sizeof(numCpus));
#elif defined(_PR_HAVE_SYSCTL)
@@ -208,9 +205,7 @@ PR_IMPLEMENT(PRInt32) PR_GetNumberOfProcessors( void )
numCpus = -1; /* set to -1 for return value on error */
_PR_MD_MAP_DEFAULT_ERROR( _MD_ERRNO() );
}
-#elif defined(IRIX)
- numCpus = sysconf( _SC_NPROC_ONLN );
-#elif defined(RISCOS) || defined(SYMBIAN)
+#elif defined(RISCOS)
numCpus = 1;
#elif defined(LINUX)
/* for the benefit of devices with advanced power-saving, that
@@ -255,14 +250,14 @@ PR_IMPLEMENT(PRInt32) PR_GetNumberOfProcessors( void )
/*
** PR_GetPhysicalMemorySize()
-**
+**
** Implementation notes:
** Every platform does it a bit different.
** bytes is the returned value.
** for each platform's "if defined" section
** declare your local variable
** do your thing, assign to bytes.
-**
+**
*/
PR_IMPLEMENT(PRUint64) PR_GetPhysicalMemorySize(void)
{
@@ -272,8 +267,9 @@ PR_IMPLEMENT(PRUint64) PR_GetPhysicalMemorySize(void)
long pageSize = sysconf(_SC_PAGESIZE);
long pageCount = sysconf(_SC_PHYS_PAGES);
- if (pageSize >= 0 && pageCount >= 0)
+ if (pageSize >= 0 && pageCount >= 0) {
bytes = (PRUint64) pageSize * pageCount;
+ }
#elif defined(NETBSD) || defined(OPENBSD) \
|| defined(FREEBSD) || defined(DRAGONFLY)
@@ -302,8 +298,9 @@ PR_IMPLEMENT(PRUint64) PR_GetPhysicalMemorySize(void)
struct pst_static info;
int result = pstat_getstatic(&info, sizeof(info), 1, 0);
- if (result == 1)
+ if (result == 1) {
bytes = (PRUint64) info.physical_memory * info.page_size;
+ }
#elif defined(DARWIN)
@@ -316,15 +313,17 @@ PR_IMPLEMENT(PRUint64) PR_GetPhysicalMemorySize(void)
(host_info_t) &hInfo,
&count);
mach_port_deallocate(mach_task_self(), mach_host);
- if (result == KERN_SUCCESS)
+ if (result == KERN_SUCCESS) {
bytes = hInfo.max_mem;
+ }
#elif defined(WIN32)
MEMORYSTATUSEX memStat;
memStat.dwLength = sizeof(memStat);
- if (GlobalMemoryStatusEx(&memStat))
+ if (GlobalMemoryStatusEx(&memStat)) {
bytes = memStat.ullTotalPhys;
+ }
#elif defined(OS2)
diff --git a/nsprpub/pr/src/misc/prthinfo.c b/nsprpub/pr/src/misc/prthinfo.c
index 2477899c3..14602df0b 100644
--- a/nsprpub/pr/src/misc/prthinfo.c
+++ b/nsprpub/pr/src/misc/prthinfo.c
@@ -32,8 +32,9 @@ PR_ThreadScanStackPointers(PRThread* t,
*/
p0 = _MD_HomeGCRegisters(t, t == current, &n);
status = scanFun(t, (void**)p0, n, scanClosure);
- if (status != PR_SUCCESS)
+ if (status != PR_SUCCESS) {
return status;
+ }
/* Scan the C stack for pointers into the GC heap */
#if defined(XP_PC) && defined(WIN16)
@@ -86,7 +87,7 @@ PR_ThreadScanStackPointers(PRThread* t,
{
prword_t scan;
prword_t limit;
-
+
scan = (prword_t) sp;
limit = (prword_t) esp;
while (scan < limit) {
@@ -94,16 +95,18 @@ PR_ThreadScanStackPointers(PRThread* t,
test = *((prword_t **)scan);
status = scanFun(t, (void**)&test, 1, scanClosure);
- if (status != PR_SUCCESS)
+ if (status != PR_SUCCESS) {
return status;
+ }
scan += sizeof(char);
}
}
#else
if (sp < esp) {
status = scanFun(t, (void**)sp, esp - sp, scanClosure);
- if (status != PR_SUCCESS)
+ if (status != PR_SUCCESS) {
return status;
+ }
}
#endif
@@ -114,17 +117,19 @@ PR_ThreadScanStackPointers(PRThread* t,
** will be collected
*/
status = scanFun(t, (void**)&t->environment, 1, scanClosure);
- if (status != PR_SUCCESS)
+ if (status != PR_SUCCESS) {
return status;
+ }
/* if thread is not allocated on stack, this is redundant. */
ptd = t->privateData;
for (index = 0; index < t->tpdLength; index++, ptd++) {
status = scanFun(t, (void**)ptd, 1, scanClosure);
- if (status != PR_SUCCESS)
+ if (status != PR_SUCCESS) {
return status;
+ }
}
-
+
return PR_SUCCESS;
}
@@ -173,9 +178,9 @@ PR_GetStackSpaceLeft(PRThread* t)
sp = (PRWord*) PR_GetSP(t);
esp = (PRWord*) t->stack->stackTop;
- PR_ASSERT((t->stack->stackSize == 0) ||
- ((sp > (PRWord*)t->stack->stackBottom) &&
- (sp <= (PRWord*)t->stack->stackTop)));
+ PR_ASSERT((t->stack->stackSize == 0) ||
+ ((sp > (PRWord*)t->stack->stackBottom) &&
+ (sp <= (PRWord*)t->stack->stackTop)));
}
#else /* ! WIN16 */
#ifdef HAVE_STACK_GROWING_UP
@@ -197,8 +202,8 @@ PR_GetStackSpaceLeft(PRThread* t)
}
esp = (PRWord*) t->stack->stackTop;
if (t->stack->stackSize) {
- PR_ASSERT((sp > (PRWord*)t->stack->stackBottom) &&
- (sp < (PRWord*)t->stack->stackTop));
+ PR_ASSERT((sp > (PRWord*)t->stack->stackBottom) &&
+ (sp < (PRWord*)t->stack->stackTop));
}
#endif /* ! HAVE_STACK_GROWING_UP */
#endif /* ! WIN16 */
diff --git a/nsprpub/pr/src/misc/prtime.c b/nsprpub/pr/src/misc/prtime.c
index f03786096..6d711a6b8 100644
--- a/nsprpub/pr/src/misc/prtime.c
+++ b/nsprpub/pr/src/misc/prtime.c
@@ -21,7 +21,7 @@
#include <errno.h> /* for EINVAL */
#include <time.h>
-/*
+/*
* The COUNT_LEAPS macro counts the number of leap years passed by
* till the start of the given year Y. At the start of the year 4
* A.D. the number of leap years passed by is 0, while at the start of
@@ -204,14 +204,14 @@ ComputeGMT(PRTime time, PRExplodedTime *gmt)
PR_IMPLEMENT(void)
PR_ExplodeTime(
- PRTime usecs,
- PRTimeParamFn params,
- PRExplodedTime *exploded)
+ PRTime usecs,
+ PRTimeParamFn params,
+ PRExplodedTime *exploded)
{
ComputeGMT(usecs, exploded);
exploded->tm_params = params(exploded);
ApplySecOffset(exploded, exploded->tm_params.tp_gmt_offset
- + exploded->tm_params.tp_dst_offset);
+ + exploded->tm_params.tp_dst_offset);
}
@@ -241,9 +241,9 @@ PR_ImplodeTime(const PRExplodedTime *exploded)
PR_NormalizeTime(&copy, PR_GMTParameters);
numDays = DAYS_BETWEEN_YEARS(1970, copy.tm_year);
-
+
numSecs = copy.tm_yday * 86400 + copy.tm_hour * 3600
- + copy.tm_min * 60 + copy.tm_sec;
+ + copy.tm_min * 60 + copy.tm_sec;
LL_I2L(temp, numDays);
LL_I2L(secPerDay, 86400);
@@ -277,8 +277,9 @@ PR_ImplodeTime(const PRExplodedTime *exploded)
static int IsLeapYear(PRInt16 year)
{
- if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
+ if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
return 1;
+ }
return 0;
}
@@ -321,23 +322,26 @@ ApplySecOffset(PRExplodedTime *time, PRInt32 secOffset)
if (time->tm_month < 0) {
time->tm_month = 11;
time->tm_year--;
- if (IsLeapYear(time->tm_year))
+ if (IsLeapYear(time->tm_year)) {
time->tm_yday = 365;
- else
+ }
+ else {
time->tm_yday = 364;
+ }
}
time->tm_mday = nDays[IsLeapYear(time->tm_year)][time->tm_month];
}
time->tm_wday--;
- if (time->tm_wday < 0)
+ if (time->tm_wday < 0) {
time->tm_wday = 6;
+ }
} else if (time->tm_hour > 23) {
/* Increment mday, yday, and wday */
time->tm_hour -= 24;
time->tm_mday++;
time->tm_yday++;
if (time->tm_mday >
- nDays[IsLeapYear(time->tm_year)][time->tm_month]) {
+ nDays[IsLeapYear(time->tm_year)][time->tm_month]) {
time->tm_mday = 1;
time->tm_month++;
if (time->tm_month > 11) {
@@ -347,8 +351,9 @@ ApplySecOffset(PRExplodedTime *time, PRInt32 secOffset)
}
}
time->tm_wday++;
- if (time->tm_wday > 6)
+ if (time->tm_wday > 6) {
time->tm_wday = 0;
+ }
}
}
@@ -360,7 +365,7 @@ PR_NormalizeTime(PRExplodedTime *time, PRTimeParamFn params)
/* Get back to GMT */
time->tm_sec -= time->tm_params.tp_gmt_offset
- + time->tm_params.tp_dst_offset;
+ + time->tm_params.tp_dst_offset;
time->tm_params.tp_gmt_offset = 0;
time->tm_params.tp_dst_offset = 0;
@@ -442,8 +447,8 @@ PR_NormalizeTime(PRExplodedTime *time, PRTimeParamFn params)
/* Recompute yday and wday */
time->tm_yday = time->tm_mday +
- lastDayOfMonth[IsLeapYear(time->tm_year)][time->tm_month];
-
+ lastDayOfMonth[IsLeapYear(time->tm_year)][time->tm_month];
+
numDays = DAYS_BETWEEN_YEARS(1970, time->tm_year) + time->tm_yday;
time->tm_wday = (numDays + 4) % 7;
if (time->tm_wday < 0) {
@@ -455,7 +460,7 @@ PR_NormalizeTime(PRExplodedTime *time, PRTimeParamFn params)
time->tm_params = params(time);
ApplySecOffset(time, time->tm_params.tp_gmt_offset
- + time->tm_params.tp_dst_offset);
+ + time->tm_params.tp_dst_offset);
}
@@ -463,7 +468,7 @@ PR_NormalizeTime(PRExplodedTime *time, PRTimeParamFn params)
*-------------------------------------------------------------------------
*
* PR_LocalTimeParameters --
- *
+ *
* returns the time parameters for the local time zone
*
* The following uses localtime() from the standard C library.
@@ -480,7 +485,7 @@ PR_NormalizeTime(PRExplodedTime *time, PRTimeParamFn params)
* In this case we could define the macro as
* #define MT_safe_localtime(timer, result) \
* (localtime_r(timer, result) == 0 ? result : NULL)
- * I chose to compare the return value of localtime_r with -1 so
+ * I chose to compare the return value of localtime_r with -1 so
* that I can catch the cases where localtime_r returns a pointer
* to struct tm. The macro definition above would not be able to
* detect such mistakes because it is legal to compare a pointer
@@ -521,7 +526,9 @@ static struct tm *MT_safe_localtime(const time_t *clock, struct tm *result)
* against NSPR threads only when the
* NSPR thread system is activated. */
- if (needLock) PR_Lock(monitor);
+ if (needLock) {
+ PR_Lock(monitor);
+ }
/*
* Microsoft (all flavors) localtime() returns a NULL pointer if 'clock'
@@ -538,15 +545,17 @@ static struct tm *MT_safe_localtime(const time_t *clock, struct tm *result)
* clock plus ULONG_MAX. So we also have to check for the invalid
* structs returned for timezones west of Greenwich when clock == 0.
*/
-
+
tmPtr = localtime(clock);
#if defined(WIN16) || defined(XP_OS2)
if ( (PRInt32) *clock < 0 ||
- ( (PRInt32) *clock == 0 && tmPtr->tm_year != 70))
+ ( (PRInt32) *clock == 0 && tmPtr->tm_year != 70)) {
result = NULL;
- else
+ }
+ else {
*result = *tmPtr;
+ }
#else
if (tmPtr) {
*result = *tmPtr;
@@ -555,7 +564,9 @@ static struct tm *MT_safe_localtime(const time_t *clock, struct tm *result)
}
#endif /* WIN16 */
- if (needLock) PR_Unlock(monitor);
+ if (needLock) {
+ PR_Unlock(monitor);
+ }
return result;
}
@@ -585,7 +596,7 @@ void _PR_CleanupTime(void)
#endif
}
-#if defined(XP_UNIX) || defined(XP_PC) || defined(XP_BEOS)
+#if defined(XP_UNIX) || defined(XP_PC)
PR_IMPLEMENT(PRTimeParameters)
PR_LocalTimeParameters(const PRExplodedTime *gmt)
@@ -629,10 +640,10 @@ PR_LocalTimeParameters(const PRExplodedTime *gmt)
/* GMT is 00:00:00, 2nd of Jan. */
- offset2Jan1970 = (PRInt32)localTime.tm_sec
- + 60L * (PRInt32)localTime.tm_min
- + 3600L * (PRInt32)localTime.tm_hour
- + 86400L * (PRInt32)((PRInt32)localTime.tm_mday - 2L);
+ offset2Jan1970 = (PRInt32)localTime.tm_sec
+ + 60L * (PRInt32)localTime.tm_min
+ + 3600L * (PRInt32)localTime.tm_hour
+ + 86400L * (PRInt32)((PRInt32)localTime.tm_mday - 2L);
isdst2Jan1970 = localTime.tm_isdst;
@@ -683,7 +694,7 @@ PR_LocalTimeParameters(const PRExplodedTime *gmt)
}
/*
- * dayOffset is the offset between local time and GMT in
+ * dayOffset is the offset between local time and GMT in
* the day component, which can only be -1, 0, or 1. We
* use the day of the week to compute dayOffset.
*/
@@ -704,9 +715,9 @@ PR_LocalTimeParameters(const PRExplodedTime *gmt)
}
offsetNew = (PRInt32)localTime.tm_sec - gmt->tm_sec
- + 60L * ((PRInt32)localTime.tm_min - gmt->tm_min)
- + 3600L * ((PRInt32)localTime.tm_hour - gmt->tm_hour)
- + 86400L * (PRInt32)dayOffset;
+ + 60L * ((PRInt32)localTime.tm_min - gmt->tm_min)
+ + 3600L * ((PRInt32)localTime.tm_hour - gmt->tm_hour)
+ + 86400L * (PRInt32)dayOffset;
if (localTime.tm_isdst <= 0) {
/* DST is not in effect */
@@ -732,11 +743,11 @@ PR_LocalTimeParameters(const PRExplodedTime *gmt)
retVal.tp_dst_offset = 3600;
}
}
-
+
return retVal;
}
-#endif /* defined(XP_UNIX) || defined(XP_PC) || defined(XP_BEOS) */
+#endif /* defined(XP_UNIX) || defined(XP_PC) */
/*
*------------------------------------------------------------------------
@@ -751,27 +762,28 @@ PR_LocalTimeParameters(const PRExplodedTime *gmt)
/*
* Returns the mday of the first sunday of the month, where
* mday and wday are for a given day in the month.
- * mdays start with 1 (e.g. 1..31).
+ * mdays start with 1 (e.g. 1..31).
* wdays start with 0 and are in the range 0..6. 0 = Sunday.
*/
#define firstSunday(mday, wday) (((mday - wday + 7 - 1) % 7) + 1)
/*
- * Returns the mday for the N'th Sunday of the month, where
+ * Returns the mday for the N'th Sunday of the month, where
* mday and wday are for a given day in the month.
- * mdays start with 1 (e.g. 1..31).
+ * mdays start with 1 (e.g. 1..31).
* wdays start with 0 and are in the range 0..6. 0 = Sunday.
* N has the following values: 0 = first, 1 = second (etc), -1 = last.
- * ndays is the number of days in that month, the same value as the
+ * ndays is the number of days in that month, the same value as the
* mday of the last day of the month.
*/
-static PRInt32
-NthSunday(PRInt32 mday, PRInt32 wday, PRInt32 N, PRInt32 ndays)
+static PRInt32
+NthSunday(PRInt32 mday, PRInt32 wday, PRInt32 N, PRInt32 ndays)
{
PRInt32 firstSun = firstSunday(mday, wday);
- if (N < 0)
+ if (N < 0) {
N = (ndays - firstSun) / 7;
+ }
return firstSun + (7 * N);
}
@@ -825,9 +837,9 @@ PR_USPacificTimeParameters(const PRExplodedTime *gmt)
ApplySecOffset(&st, retVal.tp_gmt_offset);
if (st.tm_year < 2007) { /* first April Sunday - Last October Sunday */
- dst = &dstParams[0];
+ dst = &dstParams[0];
} else { /* Second March Sunday - First November Sunday */
- dst = &dstParams[1];
+ dst = &dstParams[1];
}
/*
@@ -837,38 +849,38 @@ PR_USPacificTimeParameters(const PRExplodedTime *gmt)
if (st.tm_month < dst->dst_start_month) {
retVal.tp_dst_offset = 0L;
} else if (st.tm_month == dst->dst_start_month) {
- int NthSun = NthSunday(st.tm_mday, st.tm_wday,
- dst->dst_start_Nth_Sunday,
- dst->dst_start_month_ndays);
- if (st.tm_mday < NthSun) { /* Before starting Sunday */
- retVal.tp_dst_offset = 0L;
+ int NthSun = NthSunday(st.tm_mday, st.tm_wday,
+ dst->dst_start_Nth_Sunday,
+ dst->dst_start_month_ndays);
+ if (st.tm_mday < NthSun) { /* Before starting Sunday */
+ retVal.tp_dst_offset = 0L;
} else if (st.tm_mday == NthSun) { /* Starting Sunday */
- /* 01:59:59 PST -> 03:00:00 PDT */
- if (st.tm_hour < 2) {
- retVal.tp_dst_offset = 0L;
- } else {
- retVal.tp_dst_offset = 3600L;
- }
- } else { /* After starting Sunday */
- retVal.tp_dst_offset = 3600L;
+ /* 01:59:59 PST -> 03:00:00 PDT */
+ if (st.tm_hour < 2) {
+ retVal.tp_dst_offset = 0L;
+ } else {
+ retVal.tp_dst_offset = 3600L;
+ }
+ } else { /* After starting Sunday */
+ retVal.tp_dst_offset = 3600L;
}
} else if (st.tm_month < dst->dst_end_month) {
retVal.tp_dst_offset = 3600L;
} else if (st.tm_month == dst->dst_end_month) {
- int NthSun = NthSunday(st.tm_mday, st.tm_wday,
- dst->dst_end_Nth_Sunday,
- dst->dst_end_month_ndays);
- if (st.tm_mday < NthSun) { /* Before ending Sunday */
- retVal.tp_dst_offset = 3600L;
+ int NthSun = NthSunday(st.tm_mday, st.tm_wday,
+ dst->dst_end_Nth_Sunday,
+ dst->dst_end_month_ndays);
+ if (st.tm_mday < NthSun) { /* Before ending Sunday */
+ retVal.tp_dst_offset = 3600L;
} else if (st.tm_mday == NthSun) { /* Ending Sunday */
- /* 01:59:59 PDT -> 01:00:00 PST */
- if (st.tm_hour < 1) {
- retVal.tp_dst_offset = 3600L;
- } else {
- retVal.tp_dst_offset = 0L;
- }
- } else { /* After ending Sunday */
- retVal.tp_dst_offset = 0L;
+ /* 01:59:59 PDT -> 01:00:00 PST */
+ if (st.tm_hour < 1) {
+ retVal.tp_dst_offset = 3600L;
+ } else {
+ retVal.tp_dst_offset = 0L;
+ }
+ } else { /* After ending Sunday */
+ retVal.tp_dst_offset = 0L;
}
} else {
retVal.tp_dst_offset = 0L;
@@ -918,15 +930,15 @@ PR_GMTParameters(const PRExplodedTime *gmt)
typedef enum
{
- TT_UNKNOWN,
+ TT_UNKNOWN,
- TT_SUN, TT_MON, TT_TUE, TT_WED, TT_THU, TT_FRI, TT_SAT,
+ TT_SUN, TT_MON, TT_TUE, TT_WED, TT_THU, TT_FRI, TT_SAT,
- TT_JAN, TT_FEB, TT_MAR, TT_APR, TT_MAY, TT_JUN,
- TT_JUL, TT_AUG, TT_SEP, TT_OCT, TT_NOV, TT_DEC,
+ TT_JAN, TT_FEB, TT_MAR, TT_APR, TT_MAY, TT_JUN,
+ TT_JUL, TT_AUG, TT_SEP, TT_OCT, TT_NOV, TT_DEC,
- TT_PST, TT_PDT, TT_MST, TT_MDT, TT_CST, TT_CDT, TT_EST, TT_EDT,
- TT_AST, TT_NST, TT_GMT, TT_BST, TT_MET, TT_EET, TT_JST
+ TT_PST, TT_PDT, TT_MST, TT_MDT, TT_CST, TT_CDT, TT_EST, TT_EDT,
+ TT_AST, TT_NST, TT_GMT, TT_BST, TT_MET, TT_EET, TT_JST
} TIME_TOKEN;
/*
@@ -962,716 +974,819 @@ typedef enum
PR_IMPLEMENT(PRStatus)
PR_ParseTimeStringToExplodedTime(
- const char *string,
- PRBool default_to_gmt,
- PRExplodedTime *result)
+ const char *string,
+ PRBool default_to_gmt,
+ PRExplodedTime *result)
{
- TIME_TOKEN dotw = TT_UNKNOWN;
- TIME_TOKEN month = TT_UNKNOWN;
- TIME_TOKEN zone = TT_UNKNOWN;
- int zone_offset = -1;
- int dst_offset = 0;
- int date = -1;
- PRInt32 year = -1;
- int hour = -1;
- int min = -1;
- int sec = -1;
- struct tm *localTimeResult;
-
- const char *rest = string;
-
- int iterations = 0;
-
- PR_ASSERT(string && result);
- if (!string || !result) return PR_FAILURE;
-
- while (*rest)
+ TIME_TOKEN dotw = TT_UNKNOWN;
+ TIME_TOKEN month = TT_UNKNOWN;
+ TIME_TOKEN zone = TT_UNKNOWN;
+ int zone_offset = -1;
+ int dst_offset = 0;
+ int date = -1;
+ PRInt32 year = -1;
+ int hour = -1;
+ int min = -1;
+ int sec = -1;
+ struct tm *localTimeResult;
+
+ const char *rest = string;
+
+ int iterations = 0;
+
+ PR_ASSERT(string && result);
+ if (!string || !result) {
+ return PR_FAILURE;
+ }
+
+ while (*rest)
+ {
+
+ if (iterations++ > 1000)
+ {
+ return PR_FAILURE;
+ }
+
+ switch (*rest)
{
+ case 'a': case 'A':
+ if (month == TT_UNKNOWN &&
+ (rest[1] == 'p' || rest[1] == 'P') &&
+ (rest[2] == 'r' || rest[2] == 'R')) {
+ month = TT_APR;
+ }
+ else if (zone == TT_UNKNOWN &&
+ (rest[1] == 's' || rest[1] == 'S') &&
+ (rest[2] == 't' || rest[2] == 'T')) {
+ zone = TT_AST;
+ }
+ else if (month == TT_UNKNOWN &&
+ (rest[1] == 'u' || rest[1] == 'U') &&
+ (rest[2] == 'g' || rest[2] == 'G')) {
+ month = TT_AUG;
+ }
+ break;
+ case 'b': case 'B':
+ if (zone == TT_UNKNOWN &&
+ (rest[1] == 's' || rest[1] == 'S') &&
+ (rest[2] == 't' || rest[2] == 'T')) {
+ zone = TT_BST;
+ }
+ break;
+ case 'c': case 'C':
+ if (zone == TT_UNKNOWN &&
+ (rest[1] == 'd' || rest[1] == 'D') &&
+ (rest[2] == 't' || rest[2] == 'T')) {
+ zone = TT_CDT;
+ }
+ else if (zone == TT_UNKNOWN &&
+ (rest[1] == 's' || rest[1] == 'S') &&
+ (rest[2] == 't' || rest[2] == 'T')) {
+ zone = TT_CST;
+ }
+ break;
+ case 'd': case 'D':
+ if (month == TT_UNKNOWN &&
+ (rest[1] == 'e' || rest[1] == 'E') &&
+ (rest[2] == 'c' || rest[2] == 'C')) {
+ month = TT_DEC;
+ }
+ break;
+ case 'e': case 'E':
+ if (zone == TT_UNKNOWN &&
+ (rest[1] == 'd' || rest[1] == 'D') &&
+ (rest[2] == 't' || rest[2] == 'T')) {
+ zone = TT_EDT;
+ }
+ else if (zone == TT_UNKNOWN &&
+ (rest[1] == 'e' || rest[1] == 'E') &&
+ (rest[2] == 't' || rest[2] == 'T')) {
+ zone = TT_EET;
+ }
+ else if (zone == TT_UNKNOWN &&
+ (rest[1] == 's' || rest[1] == 'S') &&
+ (rest[2] == 't' || rest[2] == 'T')) {
+ zone = TT_EST;
+ }
+ break;
+ case 'f': case 'F':
+ if (month == TT_UNKNOWN &&
+ (rest[1] == 'e' || rest[1] == 'E') &&
+ (rest[2] == 'b' || rest[2] == 'B')) {
+ month = TT_FEB;
+ }
+ else if (dotw == TT_UNKNOWN &&
+ (rest[1] == 'r' || rest[1] == 'R') &&
+ (rest[2] == 'i' || rest[2] == 'I')) {
+ dotw = TT_FRI;
+ }
+ break;
+ case 'g': case 'G':
+ if (zone == TT_UNKNOWN &&
+ (rest[1] == 'm' || rest[1] == 'M') &&
+ (rest[2] == 't' || rest[2] == 'T')) {
+ zone = TT_GMT;
+ }
+ break;
+ case 'j': case 'J':
+ if (month == TT_UNKNOWN &&
+ (rest[1] == 'a' || rest[1] == 'A') &&
+ (rest[2] == 'n' || rest[2] == 'N')) {
+ month = TT_JAN;
+ }
+ else if (zone == TT_UNKNOWN &&
+ (rest[1] == 's' || rest[1] == 'S') &&
+ (rest[2] == 't' || rest[2] == 'T')) {
+ zone = TT_JST;
+ }
+ else if (month == TT_UNKNOWN &&
+ (rest[1] == 'u' || rest[1] == 'U') &&
+ (rest[2] == 'l' || rest[2] == 'L')) {
+ month = TT_JUL;
+ }
+ else if (month == TT_UNKNOWN &&
+ (rest[1] == 'u' || rest[1] == 'U') &&
+ (rest[2] == 'n' || rest[2] == 'N')) {
+ month = TT_JUN;
+ }
+ break;
+ case 'm': case 'M':
+ if (month == TT_UNKNOWN &&
+ (rest[1] == 'a' || rest[1] == 'A') &&
+ (rest[2] == 'r' || rest[2] == 'R')) {
+ month = TT_MAR;
+ }
+ else if (month == TT_UNKNOWN &&
+ (rest[1] == 'a' || rest[1] == 'A') &&
+ (rest[2] == 'y' || rest[2] == 'Y')) {
+ month = TT_MAY;
+ }
+ else if (zone == TT_UNKNOWN &&
+ (rest[1] == 'd' || rest[1] == 'D') &&
+ (rest[2] == 't' || rest[2] == 'T')) {
+ zone = TT_MDT;
+ }
+ else if (zone == TT_UNKNOWN &&
+ (rest[1] == 'e' || rest[1] == 'E') &&
+ (rest[2] == 't' || rest[2] == 'T')) {
+ zone = TT_MET;
+ }
+ else if (dotw == TT_UNKNOWN &&
+ (rest[1] == 'o' || rest[1] == 'O') &&
+ (rest[2] == 'n' || rest[2] == 'N')) {
+ dotw = TT_MON;
+ }
+ else if (zone == TT_UNKNOWN &&
+ (rest[1] == 's' || rest[1] == 'S') &&
+ (rest[2] == 't' || rest[2] == 'T')) {
+ zone = TT_MST;
+ }
+ break;
+ case 'n': case 'N':
+ if (month == TT_UNKNOWN &&
+ (rest[1] == 'o' || rest[1] == 'O') &&
+ (rest[2] == 'v' || rest[2] == 'V')) {
+ month = TT_NOV;
+ }
+ else if (zone == TT_UNKNOWN &&
+ (rest[1] == 's' || rest[1] == 'S') &&
+ (rest[2] == 't' || rest[2] == 'T')) {
+ zone = TT_NST;
+ }
+ break;
+ case 'o': case 'O':
+ if (month == TT_UNKNOWN &&
+ (rest[1] == 'c' || rest[1] == 'C') &&
+ (rest[2] == 't' || rest[2] == 'T')) {
+ month = TT_OCT;
+ }
+ break;
+ case 'p': case 'P':
+ if (zone == TT_UNKNOWN &&
+ (rest[1] == 'd' || rest[1] == 'D') &&
+ (rest[2] == 't' || rest[2] == 'T')) {
+ zone = TT_PDT;
+ }
+ else if (zone == TT_UNKNOWN &&
+ (rest[1] == 's' || rest[1] == 'S') &&
+ (rest[2] == 't' || rest[2] == 'T')) {
+ zone = TT_PST;
+ }
+ break;
+ case 's': case 'S':
+ if (dotw == TT_UNKNOWN &&
+ (rest[1] == 'a' || rest[1] == 'A') &&
+ (rest[2] == 't' || rest[2] == 'T')) {
+ dotw = TT_SAT;
+ }
+ else if (month == TT_UNKNOWN &&
+ (rest[1] == 'e' || rest[1] == 'E') &&
+ (rest[2] == 'p' || rest[2] == 'P')) {
+ month = TT_SEP;
+ }
+ else if (dotw == TT_UNKNOWN &&
+ (rest[1] == 'u' || rest[1] == 'U') &&
+ (rest[2] == 'n' || rest[2] == 'N')) {
+ dotw = TT_SUN;
+ }
+ break;
+ case 't': case 'T':
+ if (dotw == TT_UNKNOWN &&
+ (rest[1] == 'h' || rest[1] == 'H') &&
+ (rest[2] == 'u' || rest[2] == 'U')) {
+ dotw = TT_THU;
+ }
+ else if (dotw == TT_UNKNOWN &&
+ (rest[1] == 'u' || rest[1] == 'U') &&
+ (rest[2] == 'e' || rest[2] == 'E')) {
+ dotw = TT_TUE;
+ }
+ break;
+ case 'u': case 'U':
+ if (zone == TT_UNKNOWN &&
+ (rest[1] == 't' || rest[1] == 'T') &&
+ !(rest[2] >= 'A' && rest[2] <= 'Z') &&
+ !(rest[2] >= 'a' && rest[2] <= 'z'))
+ /* UT is the same as GMT but UTx is not. */
+ {
+ zone = TT_GMT;
+ }
+ break;
+ case 'w': case 'W':
+ if (dotw == TT_UNKNOWN &&
+ (rest[1] == 'e' || rest[1] == 'E') &&
+ (rest[2] == 'd' || rest[2] == 'D')) {
+ dotw = TT_WED;
+ }
+ break;
+
+ case '+': case '-':
+ {
+ const char *end;
+ int sign;
+ if (zone_offset != -1)
+ {
+ /* already got one... */
+ rest++;
+ break;
+ }
+ if (zone != TT_UNKNOWN && zone != TT_GMT)
+ {
+ /* GMT+0300 is legal, but PST+0300 is not. */
+ rest++;
+ break;
+ }
- if (iterations++ > 1000)
+ sign = ((*rest == '+') ? 1 : -1);
+ rest++; /* move over sign */
+ end = rest;
+ while (*end >= '0' && *end <= '9') {
+ end++;
+ }
+ if (rest == end) { /* no digits here */
+ break;
+ }
+
+ if ((end - rest) == 4)
+ /* offset in HHMM */
+ zone_offset = (((((rest[0]-'0')*10) + (rest[1]-'0')) * 60) +
+ (((rest[2]-'0')*10) + (rest[3]-'0')));
+ else if ((end - rest) == 2)
+ /* offset in hours */
+ {
+ zone_offset = (((rest[0]-'0')*10) + (rest[1]-'0')) * 60;
+ }
+ else if ((end - rest) == 1)
+ /* offset in hours */
+ {
+ zone_offset = (rest[0]-'0') * 60;
+ }
+ else
+ /* 3 or >4 */
{
- return PR_FAILURE;
+ break;
}
- switch (*rest)
+ zone_offset *= sign;
+ zone = TT_GMT;
+ break;
+ }
+
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ {
+ int tmp_hour = -1;
+ int tmp_min = -1;
+ int tmp_sec = -1;
+ const char *end = rest + 1;
+ while (*end >= '0' && *end <= '9') {
+ end++;
+ }
+
+ /* end is now the first character after a range of digits. */
+
+ if (*end == ':')
{
- case 'a': case 'A':
- if (month == TT_UNKNOWN &&
- (rest[1] == 'p' || rest[1] == 'P') &&
- (rest[2] == 'r' || rest[2] == 'R'))
- month = TT_APR;
- else if (zone == TT_UNKNOWN &&
- (rest[1] == 's' || rest[1] == 'S') &&
- (rest[2] == 't' || rest[2] == 'T'))
- zone = TT_AST;
- else if (month == TT_UNKNOWN &&
- (rest[1] == 'u' || rest[1] == 'U') &&
- (rest[2] == 'g' || rest[2] == 'G'))
- month = TT_AUG;
- break;
- case 'b': case 'B':
- if (zone == TT_UNKNOWN &&
- (rest[1] == 's' || rest[1] == 'S') &&
- (rest[2] == 't' || rest[2] == 'T'))
- zone = TT_BST;
- break;
- case 'c': case 'C':
- if (zone == TT_UNKNOWN &&
- (rest[1] == 'd' || rest[1] == 'D') &&
- (rest[2] == 't' || rest[2] == 'T'))
- zone = TT_CDT;
- else if (zone == TT_UNKNOWN &&
- (rest[1] == 's' || rest[1] == 'S') &&
- (rest[2] == 't' || rest[2] == 'T'))
- zone = TT_CST;
- break;
- case 'd': case 'D':
- if (month == TT_UNKNOWN &&
- (rest[1] == 'e' || rest[1] == 'E') &&
- (rest[2] == 'c' || rest[2] == 'C'))
- month = TT_DEC;
- break;
- case 'e': case 'E':
- if (zone == TT_UNKNOWN &&
- (rest[1] == 'd' || rest[1] == 'D') &&
- (rest[2] == 't' || rest[2] == 'T'))
- zone = TT_EDT;
- else if (zone == TT_UNKNOWN &&
- (rest[1] == 'e' || rest[1] == 'E') &&
- (rest[2] == 't' || rest[2] == 'T'))
- zone = TT_EET;
- else if (zone == TT_UNKNOWN &&
- (rest[1] == 's' || rest[1] == 'S') &&
- (rest[2] == 't' || rest[2] == 'T'))
- zone = TT_EST;
- break;
- case 'f': case 'F':
- if (month == TT_UNKNOWN &&
- (rest[1] == 'e' || rest[1] == 'E') &&
- (rest[2] == 'b' || rest[2] == 'B'))
- month = TT_FEB;
- else if (dotw == TT_UNKNOWN &&
- (rest[1] == 'r' || rest[1] == 'R') &&
- (rest[2] == 'i' || rest[2] == 'I'))
- dotw = TT_FRI;
- break;
- case 'g': case 'G':
- if (zone == TT_UNKNOWN &&
- (rest[1] == 'm' || rest[1] == 'M') &&
- (rest[2] == 't' || rest[2] == 'T'))
- zone = TT_GMT;
- break;
- case 'j': case 'J':
- if (month == TT_UNKNOWN &&
- (rest[1] == 'a' || rest[1] == 'A') &&
- (rest[2] == 'n' || rest[2] == 'N'))
- month = TT_JAN;
- else if (zone == TT_UNKNOWN &&
- (rest[1] == 's' || rest[1] == 'S') &&
- (rest[2] == 't' || rest[2] == 'T'))
- zone = TT_JST;
- else if (month == TT_UNKNOWN &&
- (rest[1] == 'u' || rest[1] == 'U') &&
- (rest[2] == 'l' || rest[2] == 'L'))
- month = TT_JUL;
- else if (month == TT_UNKNOWN &&
- (rest[1] == 'u' || rest[1] == 'U') &&
- (rest[2] == 'n' || rest[2] == 'N'))
- month = TT_JUN;
- break;
- case 'm': case 'M':
- if (month == TT_UNKNOWN &&
- (rest[1] == 'a' || rest[1] == 'A') &&
- (rest[2] == 'r' || rest[2] == 'R'))
- month = TT_MAR;
- else if (month == TT_UNKNOWN &&
- (rest[1] == 'a' || rest[1] == 'A') &&
- (rest[2] == 'y' || rest[2] == 'Y'))
- month = TT_MAY;
- else if (zone == TT_UNKNOWN &&
- (rest[1] == 'd' || rest[1] == 'D') &&
- (rest[2] == 't' || rest[2] == 'T'))
- zone = TT_MDT;
- else if (zone == TT_UNKNOWN &&
- (rest[1] == 'e' || rest[1] == 'E') &&
- (rest[2] == 't' || rest[2] == 'T'))
- zone = TT_MET;
- else if (dotw == TT_UNKNOWN &&
- (rest[1] == 'o' || rest[1] == 'O') &&
- (rest[2] == 'n' || rest[2] == 'N'))
- dotw = TT_MON;
- else if (zone == TT_UNKNOWN &&
- (rest[1] == 's' || rest[1] == 'S') &&
- (rest[2] == 't' || rest[2] == 'T'))
- zone = TT_MST;
- break;
- case 'n': case 'N':
- if (month == TT_UNKNOWN &&
- (rest[1] == 'o' || rest[1] == 'O') &&
- (rest[2] == 'v' || rest[2] == 'V'))
- month = TT_NOV;
- else if (zone == TT_UNKNOWN &&
- (rest[1] == 's' || rest[1] == 'S') &&
- (rest[2] == 't' || rest[2] == 'T'))
- zone = TT_NST;
- break;
- case 'o': case 'O':
- if (month == TT_UNKNOWN &&
- (rest[1] == 'c' || rest[1] == 'C') &&
- (rest[2] == 't' || rest[2] == 'T'))
- month = TT_OCT;
- break;
- case 'p': case 'P':
- if (zone == TT_UNKNOWN &&
- (rest[1] == 'd' || rest[1] == 'D') &&
- (rest[2] == 't' || rest[2] == 'T'))
- zone = TT_PDT;
- else if (zone == TT_UNKNOWN &&
- (rest[1] == 's' || rest[1] == 'S') &&
- (rest[2] == 't' || rest[2] == 'T'))
- zone = TT_PST;
- break;
- case 's': case 'S':
- if (dotw == TT_UNKNOWN &&
- (rest[1] == 'a' || rest[1] == 'A') &&
- (rest[2] == 't' || rest[2] == 'T'))
- dotw = TT_SAT;
- else if (month == TT_UNKNOWN &&
- (rest[1] == 'e' || rest[1] == 'E') &&
- (rest[2] == 'p' || rest[2] == 'P'))
- month = TT_SEP;
- else if (dotw == TT_UNKNOWN &&
- (rest[1] == 'u' || rest[1] == 'U') &&
- (rest[2] == 'n' || rest[2] == 'N'))
- dotw = TT_SUN;
- break;
- case 't': case 'T':
- if (dotw == TT_UNKNOWN &&
- (rest[1] == 'h' || rest[1] == 'H') &&
- (rest[2] == 'u' || rest[2] == 'U'))
- dotw = TT_THU;
- else if (dotw == TT_UNKNOWN &&
- (rest[1] == 'u' || rest[1] == 'U') &&
- (rest[2] == 'e' || rest[2] == 'E'))
- dotw = TT_TUE;
- break;
- case 'u': case 'U':
- if (zone == TT_UNKNOWN &&
- (rest[1] == 't' || rest[1] == 'T') &&
- !(rest[2] >= 'A' && rest[2] <= 'Z') &&
- !(rest[2] >= 'a' && rest[2] <= 'z'))
- /* UT is the same as GMT but UTx is not. */
- zone = TT_GMT;
- break;
- case 'w': case 'W':
- if (dotw == TT_UNKNOWN &&
- (rest[1] == 'e' || rest[1] == 'E') &&
- (rest[2] == 'd' || rest[2] == 'D'))
- dotw = TT_WED;
- break;
-
- case '+': case '-':
- {
- const char *end;
- int sign;
- if (zone_offset != -1)
- {
- /* already got one... */
- rest++;
- break;
- }
- if (zone != TT_UNKNOWN && zone != TT_GMT)
- {
- /* GMT+0300 is legal, but PST+0300 is not. */
- rest++;
- break;
- }
-
- sign = ((*rest == '+') ? 1 : -1);
- rest++; /* move over sign */
- end = rest;
- while (*end >= '0' && *end <= '9')
- end++;
- if (rest == end) /* no digits here */
- break;
-
- if ((end - rest) == 4)
- /* offset in HHMM */
- zone_offset = (((((rest[0]-'0')*10) + (rest[1]-'0')) * 60) +
- (((rest[2]-'0')*10) + (rest[3]-'0')));
- else if ((end - rest) == 2)
- /* offset in hours */
- zone_offset = (((rest[0]-'0')*10) + (rest[1]-'0')) * 60;
- else if ((end - rest) == 1)
- /* offset in hours */
- zone_offset = (rest[0]-'0') * 60;
- else
- /* 3 or >4 */
- break;
-
- zone_offset *= sign;
- zone = TT_GMT;
+ if (hour >= 0 && min >= 0) { /* already got it */
+ break;
+ }
+
+ /* We have seen "[0-9]+:", so this is probably HH:MM[:SS] */
+ if ((end - rest) > 2)
+ /* it is [0-9][0-9][0-9]+: */
+ {
+ break;
+ }
+ if ((end - rest) == 2)
+ tmp_hour = ((rest[0]-'0')*10 +
+ (rest[1]-'0'));
+ else {
+ tmp_hour = (rest[0]-'0');
+ }
+
+ /* move over the colon, and parse minutes */
+
+ rest = ++end;
+ while (*end >= '0' && *end <= '9') {
+ end++;
+ }
+
+ if (end == rest)
+ /* no digits after first colon? */
+ {
+ break;
+ }
+ if ((end - rest) > 2)
+ /* it is [0-9][0-9][0-9]+: */
+ {
break;
- }
-
- case '0': case '1': case '2': case '3': case '4':
- case '5': case '6': case '7': case '8': case '9':
- {
- int tmp_hour = -1;
- int tmp_min = -1;
- int tmp_sec = -1;
- const char *end = rest + 1;
- while (*end >= '0' && *end <= '9')
- end++;
-
- /* end is now the first character after a range of digits. */
-
- if (*end == ':')
- {
- if (hour >= 0 && min >= 0) /* already got it */
- break;
-
- /* We have seen "[0-9]+:", so this is probably HH:MM[:SS] */
- if ((end - rest) > 2)
- /* it is [0-9][0-9][0-9]+: */
- break;
- if ((end - rest) == 2)
- tmp_hour = ((rest[0]-'0')*10 +
- (rest[1]-'0'));
- else
- tmp_hour = (rest[0]-'0');
-
- /* move over the colon, and parse minutes */
-
- rest = ++end;
- while (*end >= '0' && *end <= '9')
- end++;
-
- if (end == rest)
- /* no digits after first colon? */
- break;
- if ((end - rest) > 2)
- /* it is [0-9][0-9][0-9]+: */
- break;
- if ((end - rest) == 2)
- tmp_min = ((rest[0]-'0')*10 +
- (rest[1]-'0'));
- else
- tmp_min = (rest[0]-'0');
-
- /* now go for seconds */
- rest = end;
- if (*rest == ':')
- rest++;
- end = rest;
- while (*end >= '0' && *end <= '9')
- end++;
-
- if (end == rest)
- /* no digits after second colon - that's ok. */
- ;
- else if ((end - rest) > 2)
- /* it is [0-9][0-9][0-9]+: */
- break;
- if ((end - rest) == 2)
- tmp_sec = ((rest[0]-'0')*10 +
- (rest[1]-'0'));
- else
- tmp_sec = (rest[0]-'0');
-
- /* If we made it here, we've parsed hour and min,
- and possibly sec, so it worked as a unit. */
-
- /* skip over whitespace and see if there's an AM or PM
- directly following the time.
- */
- if (tmp_hour <= 12)
- {
- const char *s = end;
- while (*s && (*s == ' ' || *s == '\t'))
- s++;
- if ((s[0] == 'p' || s[0] == 'P') &&
- (s[1] == 'm' || s[1] == 'M'))
- /* 10:05pm == 22:05, and 12:05pm == 12:05 */
- tmp_hour = (tmp_hour == 12 ? 12 : tmp_hour + 12);
- else if (tmp_hour == 12 &&
- (s[0] == 'a' || s[0] == 'A') &&
- (s[1] == 'm' || s[1] == 'M'))
- /* 12:05am == 00:05 */
- tmp_hour = 0;
- }
-
- hour = tmp_hour;
- min = tmp_min;
- sec = tmp_sec;
- rest = end;
- break;
- }
- if ((*end == '/' || *end == '-') &&
- end[1] >= '0' && end[1] <= '9')
- {
- /* Perhaps this is 6/16/95, 16/6/95, 6-16-95, or 16-6-95
- or even 95-06-05...
- #### But it doesn't handle 1995-06-22.
- */
- int n1, n2, n3;
- const char *s;
-
- if (month != TT_UNKNOWN)
- /* if we saw a month name, this can't be. */
- break;
-
- s = rest;
-
- n1 = (*s++ - '0'); /* first 1 or 2 digits */
- if (*s >= '0' && *s <= '9')
- n1 = n1*10 + (*s++ - '0');
-
- if (*s != '/' && *s != '-') /* slash */
- break;
- s++;
-
- if (*s < '0' || *s > '9') /* second 1 or 2 digits */
- break;
- n2 = (*s++ - '0');
- if (*s >= '0' && *s <= '9')
- n2 = n2*10 + (*s++ - '0');
-
- if (*s != '/' && *s != '-') /* slash */
- break;
- s++;
-
- if (*s < '0' || *s > '9') /* third 1, 2, 4, or 5 digits */
- break;
- n3 = (*s++ - '0');
- if (*s >= '0' && *s <= '9')
- n3 = n3*10 + (*s++ - '0');
-
- if (*s >= '0' && *s <= '9') /* optional digits 3, 4, and 5 */
- {
- n3 = n3*10 + (*s++ - '0');
- if (*s < '0' || *s > '9')
- break;
- n3 = n3*10 + (*s++ - '0');
- if (*s >= '0' && *s <= '9')
- n3 = n3*10 + (*s++ - '0');
- }
-
- if ((*s >= '0' && *s <= '9') || /* followed by non-alphanum */
- (*s >= 'A' && *s <= 'Z') ||
- (*s >= 'a' && *s <= 'z'))
- break;
-
- /* Ok, we parsed three 1-2 digit numbers, with / or -
- between them. Now decide what the hell they are
- (DD/MM/YY or MM/DD/YY or YY/MM/DD.)
- */
-
- if (n1 > 31 || n1 == 0) /* must be YY/MM/DD */
- {
- if (n2 > 12) break;
- if (n3 > 31) break;
- year = n1;
- if (year < 70)
- year += 2000;
- else if (year < 100)
- year += 1900;
- month = (TIME_TOKEN)(n2 + ((int)TT_JAN) - 1);
- date = n3;
- rest = s;
- break;
- }
-
- if (n1 > 12 && n2 > 12) /* illegal */
- {
- rest = s;
- break;
- }
-
- if (n3 < 70)
- n3 += 2000;
- else if (n3 < 100)
- n3 += 1900;
-
- if (n1 > 12) /* must be DD/MM/YY */
- {
- date = n1;
- month = (TIME_TOKEN)(n2 + ((int)TT_JAN) - 1);
- year = n3;
- }
- else /* assume MM/DD/YY */
- {
- /* #### In the ambiguous case, should we consult the
- locale to find out the local default? */
- month = (TIME_TOKEN)(n1 + ((int)TT_JAN) - 1);
- date = n2;
- year = n3;
- }
- rest = s;
- }
- else if ((*end >= 'A' && *end <= 'Z') ||
- (*end >= 'a' && *end <= 'z'))
- /* Digits followed by non-punctuation - what's that? */
- ;
- else if ((end - rest) == 5) /* five digits is a year */
- year = (year < 0
- ? ((rest[0]-'0')*10000L +
- (rest[1]-'0')*1000L +
- (rest[2]-'0')*100L +
- (rest[3]-'0')*10L +
- (rest[4]-'0'))
- : year);
- else if ((end - rest) == 4) /* four digits is a year */
- year = (year < 0
- ? ((rest[0]-'0')*1000L +
- (rest[1]-'0')*100L +
- (rest[2]-'0')*10L +
- (rest[3]-'0'))
- : year);
- else if ((end - rest) == 2) /* two digits - date or year */
- {
- int n = ((rest[0]-'0')*10 +
- (rest[1]-'0'));
- /* If we don't have a date (day of the month) and we see a number
- less than 32, then assume that is the date.
-
- Otherwise, if we have a date and not a year, assume this is the
- year. If it is less than 70, then assume it refers to the 21st
- century. If it is two digits (>= 70), assume it refers to this
- century. Otherwise, assume it refers to an unambiguous year.
-
- The world will surely end soon.
- */
- if (date < 0 && n < 32)
- date = n;
- else if (year < 0)
- {
- if (n < 70)
- year = 2000 + n;
- else if (n < 100)
- year = 1900 + n;
- else
- year = n;
- }
- /* else what the hell is this. */
- }
- else if ((end - rest) == 1) /* one digit - date */
- date = (date < 0 ? (rest[0]-'0') : date);
- /* else, three or more than five digits - what's that? */
+ }
+ if ((end - rest) == 2)
+ tmp_min = ((rest[0]-'0')*10 +
+ (rest[1]-'0'));
+ else {
+ tmp_min = (rest[0]-'0');
+ }
+ /* now go for seconds */
+ rest = end;
+ if (*rest == ':') {
+ rest++;
+ }
+ end = rest;
+ while (*end >= '0' && *end <= '9') {
+ end++;
+ }
+
+ if (end == rest)
+ /* no digits after second colon - that's ok. */
+ ;
+ else if ((end - rest) > 2)
+ /* it is [0-9][0-9][0-9]+: */
+ {
break;
- }
+ }
+ if ((end - rest) == 2)
+ tmp_sec = ((rest[0]-'0')*10 +
+ (rest[1]-'0'));
+ else {
+ tmp_sec = (rest[0]-'0');
+ }
+
+ /* If we made it here, we've parsed hour and min,
+ and possibly sec, so it worked as a unit. */
+
+ /* skip over whitespace and see if there's an AM or PM
+ directly following the time.
+ */
+ if (tmp_hour <= 12)
+ {
+ const char *s = end;
+ while (*s && (*s == ' ' || *s == '\t')) {
+ s++;
+ }
+ if ((s[0] == 'p' || s[0] == 'P') &&
+ (s[1] == 'm' || s[1] == 'M'))
+ /* 10:05pm == 22:05, and 12:05pm == 12:05 */
+ {
+ tmp_hour = (tmp_hour == 12 ? 12 : tmp_hour + 12);
+ }
+ else if (tmp_hour == 12 &&
+ (s[0] == 'a' || s[0] == 'A') &&
+ (s[1] == 'm' || s[1] == 'M'))
+ /* 12:05am == 00:05 */
+ {
+ tmp_hour = 0;
+ }
+ }
+
+ hour = tmp_hour;
+ min = tmp_min;
+ sec = tmp_sec;
+ rest = end;
+ break;
}
+ if ((*end == '/' || *end == '-') &&
+ end[1] >= '0' && end[1] <= '9')
+ {
+ /* Perhaps this is 6/16/95, 16/6/95, 6-16-95, or 16-6-95
+ or even 95-06-05...
+ #### But it doesn't handle 1995-06-22.
+ */
+ int n1, n2, n3;
+ const char *s;
+
+ if (month != TT_UNKNOWN)
+ /* if we saw a month name, this can't be. */
+ {
+ break;
+ }
+
+ s = rest;
+
+ n1 = (*s++ - '0'); /* first 1 or 2 digits */
+ if (*s >= '0' && *s <= '9') {
+ n1 = n1*10 + (*s++ - '0');
+ }
+
+ if (*s != '/' && *s != '-') { /* slash */
+ break;
+ }
+ s++;
+
+ if (*s < '0' || *s > '9') { /* second 1 or 2 digits */
+ break;
+ }
+ n2 = (*s++ - '0');
+ if (*s >= '0' && *s <= '9') {
+ n2 = n2*10 + (*s++ - '0');
+ }
+
+ if (*s != '/' && *s != '-') { /* slash */
+ break;
+ }
+ s++;
+
+ if (*s < '0' || *s > '9') { /* third 1, 2, 4, or 5 digits */
+ break;
+ }
+ n3 = (*s++ - '0');
+ if (*s >= '0' && *s <= '9') {
+ n3 = n3*10 + (*s++ - '0');
+ }
+
+ if (*s >= '0' && *s <= '9') /* optional digits 3, 4, and 5 */
+ {
+ n3 = n3*10 + (*s++ - '0');
+ if (*s < '0' || *s > '9') {
+ break;
+ }
+ n3 = n3*10 + (*s++ - '0');
+ if (*s >= '0' && *s <= '9') {
+ n3 = n3*10 + (*s++ - '0');
+ }
+ }
+
+ if ((*s >= '0' && *s <= '9') || /* followed by non-alphanum */
+ (*s >= 'A' && *s <= 'Z') ||
+ (*s >= 'a' && *s <= 'z')) {
+ break;
+ }
+
+ /* Ok, we parsed three 1-2 digit numbers, with / or -
+ between them. Now decide what the hell they are
+ (DD/MM/YY or MM/DD/YY or YY/MM/DD.)
+ */
+
+ if (n1 > 31 || n1 == 0) /* must be YY/MM/DD */
+ {
+ if (n2 > 12) {
+ break;
+ }
+ if (n3 > 31) {
+ break;
+ }
+ year = n1;
+ if (year < 70) {
+ year += 2000;
+ }
+ else if (year < 100) {
+ year += 1900;
+ }
+ month = (TIME_TOKEN)(n2 + ((int)TT_JAN) - 1);
+ date = n3;
+ rest = s;
+ break;
+ }
+
+ if (n1 > 12 && n2 > 12) /* illegal */
+ {
+ rest = s;
+ break;
+ }
- /* Skip to the end of this token, whether we parsed it or not.
- Tokens are delimited by whitespace, or ,;-/
- But explicitly not :+-.
- */
- while (*rest &&
- *rest != ' ' && *rest != '\t' &&
- *rest != ',' && *rest != ';' &&
- *rest != '-' && *rest != '+' &&
- *rest != '/' &&
- *rest != '(' && *rest != ')' && *rest != '[' && *rest != ']')
- rest++;
- /* skip over uninteresting chars. */
- SKIP_MORE:
- while (*rest &&
- (*rest == ' ' || *rest == '\t' ||
- *rest == ',' || *rest == ';' || *rest == '/' ||
- *rest == '(' || *rest == ')' || *rest == '[' || *rest == ']'))
- rest++;
-
- /* "-" is ignored at the beginning of a token if we have not yet
- parsed a year (e.g., the second "-" in "30-AUG-1966"), or if
- the character after the dash is not a digit. */
- if (*rest == '-' && ((rest > string &&
- isalpha((unsigned char)rest[-1]) && year < 0) ||
- rest[1] < '0' || rest[1] > '9'))
+ if (n3 < 70) {
+ n3 += 2000;
+ }
+ else if (n3 < 100) {
+ n3 += 1900;
+ }
+
+ if (n1 > 12) /* must be DD/MM/YY */
+ {
+ date = n1;
+ month = (TIME_TOKEN)(n2 + ((int)TT_JAN) - 1);
+ year = n3;
+ }
+ else /* assume MM/DD/YY */
+ {
+ /* #### In the ambiguous case, should we consult the
+ locale to find out the local default? */
+ month = (TIME_TOKEN)(n1 + ((int)TT_JAN) - 1);
+ date = n2;
+ year = n3;
+ }
+ rest = s;
+ }
+ else if ((*end >= 'A' && *end <= 'Z') ||
+ (*end >= 'a' && *end <= 'z'))
+ /* Digits followed by non-punctuation - what's that? */
+ ;
+ else if ((end - rest) == 5) /* five digits is a year */
+ year = (year < 0
+ ? ((rest[0]-'0')*10000L +
+ (rest[1]-'0')*1000L +
+ (rest[2]-'0')*100L +
+ (rest[3]-'0')*10L +
+ (rest[4]-'0'))
+ : year);
+ else if ((end - rest) == 4) /* four digits is a year */
+ year = (year < 0
+ ? ((rest[0]-'0')*1000L +
+ (rest[1]-'0')*100L +
+ (rest[2]-'0')*10L +
+ (rest[3]-'0'))
+ : year);
+ else if ((end - rest) == 2) /* two digits - date or year */
{
- rest++;
- goto SKIP_MORE;
+ int n = ((rest[0]-'0')*10 +
+ (rest[1]-'0'));
+ /* If we don't have a date (day of the month) and we see a number
+ less than 32, then assume that is the date.
+
+ Otherwise, if we have a date and not a year, assume this is the
+ year. If it is less than 70, then assume it refers to the 21st
+ century. If it is two digits (>= 70), assume it refers to this
+ century. Otherwise, assume it refers to an unambiguous year.
+
+ The world will surely end soon.
+ */
+ if (date < 0 && n < 32) {
+ date = n;
+ }
+ else if (year < 0)
+ {
+ if (n < 70) {
+ year = 2000 + n;
+ }
+ else if (n < 100) {
+ year = 1900 + n;
+ }
+ else {
+ year = n;
+ }
+ }
+ /* else what the hell is this. */
}
+ else if ((end - rest) == 1) { /* one digit - date */
+ date = (date < 0 ? (rest[0]-'0') : date);
+ }
+ /* else, three or more than five digits - what's that? */
+
+ break;
+ }
+ }
+ /* Skip to the end of this token, whether we parsed it or not.
+ Tokens are delimited by whitespace, or ,;-/
+ But explicitly not :+-.
+ */
+ while (*rest &&
+ *rest != ' ' && *rest != '\t' &&
+ *rest != ',' && *rest != ';' &&
+ *rest != '-' && *rest != '+' &&
+ *rest != '/' &&
+ *rest != '(' && *rest != ')' && *rest != '[' && *rest != ']') {
+ rest++;
+ }
+ /* skip over uninteresting chars. */
+SKIP_MORE:
+ while (*rest &&
+ (*rest == ' ' || *rest == '\t' ||
+ *rest == ',' || *rest == ';' || *rest == '/' ||
+ *rest == '(' || *rest == ')' || *rest == '[' || *rest == ']')) {
+ rest++;
}
- if (zone != TT_UNKNOWN && zone_offset == -1)
+ /* "-" is ignored at the beginning of a token if we have not yet
+ parsed a year (e.g., the second "-" in "30-AUG-1966"), or if
+ the character after the dash is not a digit. */
+ if (*rest == '-' && ((rest > string &&
+ isalpha((unsigned char)rest[-1]) && year < 0) ||
+ rest[1] < '0' || rest[1] > '9'))
{
- switch (zone)
- {
- case TT_PST: zone_offset = -8 * 60; break;
- case TT_PDT: zone_offset = -8 * 60; dst_offset = 1 * 60; break;
- case TT_MST: zone_offset = -7 * 60; break;
- case TT_MDT: zone_offset = -7 * 60; dst_offset = 1 * 60; break;
- case TT_CST: zone_offset = -6 * 60; break;
- case TT_CDT: zone_offset = -6 * 60; dst_offset = 1 * 60; break;
- case TT_EST: zone_offset = -5 * 60; break;
- case TT_EDT: zone_offset = -5 * 60; dst_offset = 1 * 60; break;
- case TT_AST: zone_offset = -4 * 60; break;
- case TT_NST: zone_offset = -3 * 60 - 30; break;
- case TT_GMT: zone_offset = 0 * 60; break;
- case TT_BST: zone_offset = 0 * 60; dst_offset = 1 * 60; break;
- case TT_MET: zone_offset = 1 * 60; break;
- case TT_EET: zone_offset = 2 * 60; break;
- case TT_JST: zone_offset = 9 * 60; break;
- default:
- PR_ASSERT (0);
- break;
- }
+ rest++;
+ goto SKIP_MORE;
+ }
+
+ }
+
+ if (zone != TT_UNKNOWN && zone_offset == -1)
+ {
+ switch (zone)
+ {
+ case TT_PST: zone_offset = -8 * 60; break;
+ case TT_PDT: zone_offset = -8 * 60; dst_offset = 1 * 60; break;
+ case TT_MST: zone_offset = -7 * 60; break;
+ case TT_MDT: zone_offset = -7 * 60; dst_offset = 1 * 60; break;
+ case TT_CST: zone_offset = -6 * 60; break;
+ case TT_CDT: zone_offset = -6 * 60; dst_offset = 1 * 60; break;
+ case TT_EST: zone_offset = -5 * 60; break;
+ case TT_EDT: zone_offset = -5 * 60; dst_offset = 1 * 60; break;
+ case TT_AST: zone_offset = -4 * 60; break;
+ case TT_NST: zone_offset = -3 * 60 - 30; break;
+ case TT_GMT: zone_offset = 0 * 60; break;
+ case TT_BST: zone_offset = 0 * 60; dst_offset = 1 * 60; break;
+ case TT_MET: zone_offset = 1 * 60; break;
+ case TT_EET: zone_offset = 2 * 60; break;
+ case TT_JST: zone_offset = 9 * 60; break;
+ default:
+ PR_ASSERT (0);
+ break;
}
+ }
- /* If we didn't find a year, month, or day-of-the-month, we can't
- possibly parse this, and in fact, mktime() will do something random
- (I'm seeing it return "Tue Feb 5 06:28:16 2036", which is no doubt
- a numerologically significant date... */
- if (month == TT_UNKNOWN || date == -1 || year == -1 || year > PR_INT16_MAX)
- return PR_FAILURE;
+ /* If we didn't find a year, month, or day-of-the-month, we can't
+ possibly parse this, and in fact, mktime() will do something random
+ (I'm seeing it return "Tue Feb 5 06:28:16 2036", which is no doubt
+ a numerologically significant date... */
+ if (month == TT_UNKNOWN || date == -1 || year == -1 || year > PR_INT16_MAX) {
+ return PR_FAILURE;
+ }
- memset(result, 0, sizeof(*result));
- if (sec != -1)
+ memset(result, 0, sizeof(*result));
+ if (sec != -1) {
result->tm_sec = sec;
- if (min != -1)
+ }
+ if (min != -1) {
result->tm_min = min;
- if (hour != -1)
+ }
+ if (hour != -1) {
result->tm_hour = hour;
- if (date != -1)
+ }
+ if (date != -1) {
result->tm_mday = date;
- if (month != TT_UNKNOWN)
+ }
+ if (month != TT_UNKNOWN) {
result->tm_month = (((int)month) - ((int)TT_JAN));
- if (year != -1)
+ }
+ if (year != -1) {
result->tm_year = year;
- if (dotw != TT_UNKNOWN)
+ }
+ if (dotw != TT_UNKNOWN) {
result->tm_wday = (((int)dotw) - ((int)TT_SUN));
- /*
- * Mainly to compute wday and yday, but normalized time is also required
- * by the check below that works around a Visual C++ 2005 mktime problem.
- */
- PR_NormalizeTime(result, PR_GMTParameters);
- /* The remaining work is to set the gmt and dst offsets in tm_params. */
-
- if (zone == TT_UNKNOWN && default_to_gmt)
- {
- /* No zone was specified, so pretend the zone was GMT. */
- zone = TT_GMT;
- zone_offset = 0;
- }
+ }
+ /*
+ * Mainly to compute wday and yday, but normalized time is also required
+ * by the check below that works around a Visual C++ 2005 mktime problem.
+ */
+ PR_NormalizeTime(result, PR_GMTParameters);
+ /* The remaining work is to set the gmt and dst offsets in tm_params. */
+
+ if (zone == TT_UNKNOWN && default_to_gmt)
+ {
+ /* No zone was specified, so pretend the zone was GMT. */
+ zone = TT_GMT;
+ zone_offset = 0;
+ }
- if (zone_offset == -1)
- {
- /* no zone was specified, and we're to assume that everything
- is local. */
- struct tm localTime;
- time_t secs;
+ if (zone_offset == -1)
+ {
+ /* no zone was specified, and we're to assume that everything
+ is local. */
+ struct tm localTime;
+ time_t secs;
- PR_ASSERT(result->tm_month > -1 &&
- result->tm_mday > 0 &&
- result->tm_hour > -1 &&
- result->tm_min > -1 &&
- result->tm_sec > -1);
+ PR_ASSERT(result->tm_month > -1 &&
+ result->tm_mday > 0 &&
+ result->tm_hour > -1 &&
+ result->tm_min > -1 &&
+ result->tm_sec > -1);
- /*
- * To obtain time_t from a tm structure representing the local
- * time, we call mktime(). However, we need to see if we are
- * on 1-Jan-1970 or before. If we are, we can't call mktime()
- * because mktime() will crash on win16. In that case, we
- * calculate zone_offset based on the zone offset at
- * 00:00:00, 2 Jan 1970 GMT, and subtract zone_offset from the
- * date we are parsing to transform the date to GMT. We also
- * do so if mktime() returns (time_t) -1 (time out of range).
- */
-
- /* month, day, hours, mins and secs are always non-negative
- so we dont need to worry about them. */
- if(result->tm_year >= 1970)
- {
- PRInt64 usec_per_sec;
-
- localTime.tm_sec = result->tm_sec;
- localTime.tm_min = result->tm_min;
- localTime.tm_hour = result->tm_hour;
- localTime.tm_mday = result->tm_mday;
- localTime.tm_mon = result->tm_month;
- localTime.tm_year = result->tm_year - 1900;
- /* Set this to -1 to tell mktime "I don't care". If you set
- it to 0 or 1, you are making assertions about whether the
- date you are handing it is in daylight savings mode or not;
- and if you're wrong, it will "fix" it for you. */
- localTime.tm_isdst = -1;
+ /*
+ * To obtain time_t from a tm structure representing the local
+ * time, we call mktime(). However, we need to see if we are
+ * on 1-Jan-1970 or before. If we are, we can't call mktime()
+ * because mktime() will crash on win16. In that case, we
+ * calculate zone_offset based on the zone offset at
+ * 00:00:00, 2 Jan 1970 GMT, and subtract zone_offset from the
+ * date we are parsing to transform the date to GMT. We also
+ * do so if mktime() returns (time_t) -1 (time out of range).
+ */
+
+ /* month, day, hours, mins and secs are always non-negative
+ so we dont need to worry about them. */
+ if(result->tm_year >= 1970)
+ {
+ PRInt64 usec_per_sec;
+
+ localTime.tm_sec = result->tm_sec;
+ localTime.tm_min = result->tm_min;
+ localTime.tm_hour = result->tm_hour;
+ localTime.tm_mday = result->tm_mday;
+ localTime.tm_mon = result->tm_month;
+ localTime.tm_year = result->tm_year - 1900;
+ /* Set this to -1 to tell mktime "I don't care". If you set
+ it to 0 or 1, you are making assertions about whether the
+ date you are handing it is in daylight savings mode or not;
+ and if you're wrong, it will "fix" it for you. */
+ localTime.tm_isdst = -1;
#if _MSC_VER == 1400 /* 1400 = Visual C++ 2005 (8.0) */
- /*
- * mktime will return (time_t) -1 if the input is a date
- * after 23:59:59, December 31, 3000, US Pacific Time (not
- * UTC as documented):
- * http://msdn.microsoft.com/en-us/library/d1y53h2a(VS.80).aspx
- * But if the year is 3001, mktime also invokes the invalid
- * parameter handler, causing the application to crash. This
- * problem has been reported in
- * http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=266036.
- * We avoid this crash by not calling mktime if the date is
- * out of range. To use a simple test that works in any time
- * zone, we consider year 3000 out of range as well. (See
- * bug 480740.)
- */
- if (result->tm_year >= 3000) {
- /* Emulate what mktime would have done. */
- errno = EINVAL;
- secs = (time_t) -1;
- } else {
- secs = mktime(&localTime);
- }
+ /*
+ * mktime will return (time_t) -1 if the input is a date
+ * after 23:59:59, December 31, 3000, US Pacific Time (not
+ * UTC as documented):
+ * http://msdn.microsoft.com/en-us/library/d1y53h2a(VS.80).aspx
+ * But if the year is 3001, mktime also invokes the invalid
+ * parameter handler, causing the application to crash. This
+ * problem has been reported in
+ * http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=266036.
+ * We avoid this crash by not calling mktime if the date is
+ * out of range. To use a simple test that works in any time
+ * zone, we consider year 3000 out of range as well. (See
+ * bug 480740.)
+ */
+ if (result->tm_year >= 3000) {
+ /* Emulate what mktime would have done. */
+ errno = EINVAL;
+ secs = (time_t) -1;
+ } else {
+ secs = mktime(&localTime);
+ }
#else
- secs = mktime(&localTime);
+ secs = mktime(&localTime);
#endif
- if (secs != (time_t) -1)
- {
- PRTime usecs64;
- LL_I2L(usecs64, secs);
- LL_I2L(usec_per_sec, PR_USEC_PER_SEC);
- LL_MUL(usecs64, usecs64, usec_per_sec);
- PR_ExplodeTime(usecs64, PR_LocalTimeParameters, result);
- return PR_SUCCESS;
- }
- }
-
- /* So mktime() can't handle this case. We assume the
- zone_offset for the date we are parsing is the same as
- the zone offset on 00:00:00 2 Jan 1970 GMT. */
- secs = 86400;
- localTimeResult = MT_safe_localtime(&secs, &localTime);
- PR_ASSERT(localTimeResult != NULL);
- if (localTimeResult == NULL) {
- return PR_FAILURE;
- }
- zone_offset = localTime.tm_min
- + 60 * localTime.tm_hour
- + 1440 * (localTime.tm_mday - 2);
+ if (secs != (time_t) -1)
+ {
+ PRTime usecs64;
+ LL_I2L(usecs64, secs);
+ LL_I2L(usec_per_sec, PR_USEC_PER_SEC);
+ LL_MUL(usecs64, usecs64, usec_per_sec);
+ PR_ExplodeTime(usecs64, PR_LocalTimeParameters, result);
+ return PR_SUCCESS;
+ }
}
- result->tm_params.tp_gmt_offset = zone_offset * 60;
- result->tm_params.tp_dst_offset = dst_offset * 60;
+ /* So mktime() can't handle this case. We assume the
+ zone_offset for the date we are parsing is the same as
+ the zone offset on 00:00:00 2 Jan 1970 GMT. */
+ secs = 86400;
+ localTimeResult = MT_safe_localtime(&secs, &localTime);
+ PR_ASSERT(localTimeResult != NULL);
+ if (localTimeResult == NULL) {
+ return PR_FAILURE;
+ }
+ zone_offset = localTime.tm_min
+ + 60 * localTime.tm_hour
+ + 1440 * (localTime.tm_mday - 2);
+ }
- return PR_SUCCESS;
+ result->tm_params.tp_gmt_offset = zone_offset * 60;
+ result->tm_params.tp_dst_offset = dst_offset * 60;
+
+ return PR_SUCCESS;
}
PR_IMPLEMENT(PRStatus)
PR_ParseTimeString(
- const char *string,
- PRBool default_to_gmt,
- PRTime *result)
+ const char *string,
+ PRBool default_to_gmt,
+ PRTime *result)
{
- PRExplodedTime tm;
- PRStatus rv;
+ PRExplodedTime tm;
+ PRStatus rv;
- rv = PR_ParseTimeStringToExplodedTime(string,
- default_to_gmt,
- &tm);
- if (rv != PR_SUCCESS)
+ rv = PR_ParseTimeStringToExplodedTime(string,
+ default_to_gmt,
+ &tm);
+ if (rv != PR_SUCCESS) {
return rv;
+ }
- *result = PR_ImplodeTime(&tm);
+ *result = PR_ImplodeTime(&tm);
- return PR_SUCCESS;
+ return PR_SUCCESS;
}
/*
@@ -1720,9 +1835,9 @@ PR_FormatTime(char *buf, int buflen, const char *fmt,
* additional fields: tm_zone and tm_gmtoff.
*/
-#if (__GLIBC__ >= 2) || defined(XP_BEOS) \
- || defined(NETBSD) || defined(OPENBSD) || defined(FREEBSD) \
- || defined(DARWIN) || defined(SYMBIAN) || defined(ANDROID)
+#if (__GLIBC__ >= 2) || defined(NETBSD) \
+ || defined(OPENBSD) || defined(FREEBSD) \
+ || defined(DARWIN) || defined(ANDROID)
a.tm_zone = NULL;
a.tm_gmtoff = time->tm_params.tp_gmt_offset +
time->tm_params.tp_dst_offset;
@@ -1750,22 +1865,22 @@ PR_FormatTime(char *buf, int buflen, const char *fmt,
static const char* abbrevDays[] =
{
- "Sun","Mon","Tue","Wed","Thu","Fri","Sat"
+ "Sun","Mon","Tue","Wed","Thu","Fri","Sat"
};
static const char* days[] =
{
- "Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"
+ "Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"
};
static const char* abbrevMonths[] =
{
- "Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
static const char* months[] =
-{
+{
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
};
@@ -1813,7 +1928,7 @@ while(0)
/* Needed by PR_FormatTimeUSEnglish() */
static unsigned int pr_WeekOfYear(const PRExplodedTime* time,
- unsigned int firstDayOfWeek);
+ unsigned int firstDayOfWeek);
/***********************************************************************************
@@ -1824,169 +1939,169 @@ static unsigned int pr_WeekOfYear(const PRExplodedTime* time,
* needed to write things like MIME headers which must always be in US English.
*
**********************************************************************************/
-
+
PR_IMPLEMENT(PRUint32)
PR_FormatTimeUSEnglish( char* buf, PRUint32 bufSize,
const char* format, const PRExplodedTime* time )
{
- char* bufPtr = buf;
- const char* fmtPtr;
- char tmpBuf[ 40 ];
- const int tmpBufSize = sizeof( tmpBuf );
-
-
- for( fmtPtr=format; *fmtPtr != '\0'; fmtPtr++ )
- {
- if( *fmtPtr != '%' )
- {
- ADDCHAR( bufPtr, bufSize, *fmtPtr );
- }
- else
- {
- switch( *(++fmtPtr) )
- {
- case '%':
- /* escaped '%' character */
- ADDCHAR( bufPtr, bufSize, '%' );
- break;
-
- case 'a':
- /* abbreviated weekday name */
- ADDSTR( bufPtr, bufSize, abbrevDays[ time->tm_wday ] );
- break;
-
- case 'A':
- /* full weekday name */
- ADDSTR( bufPtr, bufSize, days[ time->tm_wday ] );
- break;
-
- case 'b':
- /* abbreviated month name */
- ADDSTR( bufPtr, bufSize, abbrevMonths[ time->tm_month ] );
- break;
-
- case 'B':
- /* full month name */
- ADDSTR(bufPtr, bufSize, months[ time->tm_month ] );
- break;
-
- case 'c':
- /* Date and time. */
- PR_FormatTimeUSEnglish( tmpBuf, tmpBufSize, "%a %b %d %H:%M:%S %Y", time );
- ADDSTR( bufPtr, bufSize, tmpBuf );
- break;
-
- case 'd':
- /* day of month ( 01 - 31 ) */
- PR_snprintf(tmpBuf,tmpBufSize,"%.2ld",time->tm_mday );
- ADDSTR( bufPtr, bufSize, tmpBuf );
- break;
-
- case 'H':
- /* hour ( 00 - 23 ) */
- PR_snprintf(tmpBuf,tmpBufSize,"%.2ld",time->tm_hour );
- ADDSTR( bufPtr, bufSize, tmpBuf );
- break;
-
- case 'I':
- /* hour ( 01 - 12 ) */
- PR_snprintf(tmpBuf,tmpBufSize,"%.2ld",
- (time->tm_hour%12) ? time->tm_hour%12 : (PRInt32) 12 );
- ADDSTR( bufPtr, bufSize, tmpBuf );
- break;
-
- case 'j':
- /* day number of year ( 001 - 366 ) */
- PR_snprintf(tmpBuf,tmpBufSize,"%.3d",time->tm_yday + 1);
- ADDSTR( bufPtr, bufSize, tmpBuf );
- break;
-
- case 'm':
- /* month number ( 01 - 12 ) */
- PR_snprintf(tmpBuf,tmpBufSize,"%.2ld",time->tm_month+1);
- ADDSTR( bufPtr, bufSize, tmpBuf );
- break;
-
- case 'M':
- /* minute ( 00 - 59 ) */
- PR_snprintf(tmpBuf,tmpBufSize,"%.2ld",time->tm_min );
- ADDSTR( bufPtr, bufSize, tmpBuf );
- break;
-
- case 'p':
- /* locale's equivalent of either AM or PM */
- ADDSTR( bufPtr, bufSize, (time->tm_hour<12)?"AM":"PM" );
- break;
-
- case 'S':
- /* seconds ( 00 - 61 ), allows for leap seconds */
- PR_snprintf(tmpBuf,tmpBufSize,"%.2ld",time->tm_sec );
- ADDSTR( bufPtr, bufSize, tmpBuf );
- break;
-
- case 'U':
- /* week number of year ( 00 - 53 ), Sunday is the first day of week 1 */
- PR_snprintf(tmpBuf,tmpBufSize,"%.2d", pr_WeekOfYear( time, 0 ) );
- ADDSTR( bufPtr, bufSize, tmpBuf );
- break;
-
- case 'w':
- /* weekday number ( 0 - 6 ), Sunday = 0 */
- PR_snprintf(tmpBuf,tmpBufSize,"%d",time->tm_wday );
- ADDSTR( bufPtr, bufSize, tmpBuf );
- break;
-
- case 'W':
- /* Week number of year ( 00 - 53 ), Monday is the first day of week 1 */
- PR_snprintf(tmpBuf,tmpBufSize,"%.2d", pr_WeekOfYear( time, 1 ) );
- ADDSTR( bufPtr, bufSize, tmpBuf );
- break;
-
- case 'x':
- /* Date representation */
- PR_FormatTimeUSEnglish( tmpBuf, tmpBufSize, "%m/%d/%y", time );
- ADDSTR( bufPtr, bufSize, tmpBuf );
- break;
-
- case 'X':
- /* Time representation. */
- PR_FormatTimeUSEnglish( tmpBuf, tmpBufSize, "%H:%M:%S", time );
- ADDSTR( bufPtr, bufSize, tmpBuf );
- break;
-
- case 'y':
- /* year within century ( 00 - 99 ) */
- PR_snprintf(tmpBuf,tmpBufSize,"%.2d",time->tm_year % 100 );
- ADDSTR( bufPtr, bufSize, tmpBuf );
- break;
-
- case 'Y':
- /* year as ccyy ( for example 1986 ) */
- PR_snprintf(tmpBuf,tmpBufSize,"%.4d",time->tm_year );
- ADDSTR( bufPtr, bufSize, tmpBuf );
- break;
-
- case 'Z':
- /* Time zone name or no characters if no time zone exists.
- * Since time zone name is supposed to be independant of locale, we
- * defer to PR_FormatTime() for this option.
- */
- PR_FormatTime( tmpBuf, tmpBufSize, "%Z", time );
- ADDSTR( bufPtr, bufSize, tmpBuf );
- break;
+ char* bufPtr = buf;
+ const char* fmtPtr;
+ char tmpBuf[ 40 ];
+ const int tmpBufSize = sizeof( tmpBuf );
- default:
- /* Unknown format. Simply copy format into output buffer. */
- ADDCHAR( bufPtr, bufSize, '%' );
+
+ for( fmtPtr=format; *fmtPtr != '\0'; fmtPtr++ )
+ {
+ if( *fmtPtr != '%' )
+ {
ADDCHAR( bufPtr, bufSize, *fmtPtr );
- break;
-
- }
- }
- }
-
- ADDCHAR( bufPtr, bufSize, '\0' );
- return (PRUint32)(bufPtr - buf - 1);
+ }
+ else
+ {
+ switch( *(++fmtPtr) )
+ {
+ case '%':
+ /* escaped '%' character */
+ ADDCHAR( bufPtr, bufSize, '%' );
+ break;
+
+ case 'a':
+ /* abbreviated weekday name */
+ ADDSTR( bufPtr, bufSize, abbrevDays[ time->tm_wday ] );
+ break;
+
+ case 'A':
+ /* full weekday name */
+ ADDSTR( bufPtr, bufSize, days[ time->tm_wday ] );
+ break;
+
+ case 'b':
+ /* abbreviated month name */
+ ADDSTR( bufPtr, bufSize, abbrevMonths[ time->tm_month ] );
+ break;
+
+ case 'B':
+ /* full month name */
+ ADDSTR(bufPtr, bufSize, months[ time->tm_month ] );
+ break;
+
+ case 'c':
+ /* Date and time. */
+ PR_FormatTimeUSEnglish( tmpBuf, tmpBufSize, "%a %b %d %H:%M:%S %Y", time );
+ ADDSTR( bufPtr, bufSize, tmpBuf );
+ break;
+
+ case 'd':
+ /* day of month ( 01 - 31 ) */
+ PR_snprintf(tmpBuf,tmpBufSize,"%.2ld",time->tm_mday );
+ ADDSTR( bufPtr, bufSize, tmpBuf );
+ break;
+
+ case 'H':
+ /* hour ( 00 - 23 ) */
+ PR_snprintf(tmpBuf,tmpBufSize,"%.2ld",time->tm_hour );
+ ADDSTR( bufPtr, bufSize, tmpBuf );
+ break;
+
+ case 'I':
+ /* hour ( 01 - 12 ) */
+ PR_snprintf(tmpBuf,tmpBufSize,"%.2ld",
+ (time->tm_hour%12) ? time->tm_hour%12 : (PRInt32) 12 );
+ ADDSTR( bufPtr, bufSize, tmpBuf );
+ break;
+
+ case 'j':
+ /* day number of year ( 001 - 366 ) */
+ PR_snprintf(tmpBuf,tmpBufSize,"%.3d",time->tm_yday + 1);
+ ADDSTR( bufPtr, bufSize, tmpBuf );
+ break;
+
+ case 'm':
+ /* month number ( 01 - 12 ) */
+ PR_snprintf(tmpBuf,tmpBufSize,"%.2ld",time->tm_month+1);
+ ADDSTR( bufPtr, bufSize, tmpBuf );
+ break;
+
+ case 'M':
+ /* minute ( 00 - 59 ) */
+ PR_snprintf(tmpBuf,tmpBufSize,"%.2ld",time->tm_min );
+ ADDSTR( bufPtr, bufSize, tmpBuf );
+ break;
+
+ case 'p':
+ /* locale's equivalent of either AM or PM */
+ ADDSTR( bufPtr, bufSize, (time->tm_hour<12)?"AM":"PM" );
+ break;
+
+ case 'S':
+ /* seconds ( 00 - 61 ), allows for leap seconds */
+ PR_snprintf(tmpBuf,tmpBufSize,"%.2ld",time->tm_sec );
+ ADDSTR( bufPtr, bufSize, tmpBuf );
+ break;
+
+ case 'U':
+ /* week number of year ( 00 - 53 ), Sunday is the first day of week 1 */
+ PR_snprintf(tmpBuf,tmpBufSize,"%.2d", pr_WeekOfYear( time, 0 ) );
+ ADDSTR( bufPtr, bufSize, tmpBuf );
+ break;
+
+ case 'w':
+ /* weekday number ( 0 - 6 ), Sunday = 0 */
+ PR_snprintf(tmpBuf,tmpBufSize,"%d",time->tm_wday );
+ ADDSTR( bufPtr, bufSize, tmpBuf );
+ break;
+
+ case 'W':
+ /* Week number of year ( 00 - 53 ), Monday is the first day of week 1 */
+ PR_snprintf(tmpBuf,tmpBufSize,"%.2d", pr_WeekOfYear( time, 1 ) );
+ ADDSTR( bufPtr, bufSize, tmpBuf );
+ break;
+
+ case 'x':
+ /* Date representation */
+ PR_FormatTimeUSEnglish( tmpBuf, tmpBufSize, "%m/%d/%y", time );
+ ADDSTR( bufPtr, bufSize, tmpBuf );
+ break;
+
+ case 'X':
+ /* Time representation. */
+ PR_FormatTimeUSEnglish( tmpBuf, tmpBufSize, "%H:%M:%S", time );
+ ADDSTR( bufPtr, bufSize, tmpBuf );
+ break;
+
+ case 'y':
+ /* year within century ( 00 - 99 ) */
+ PR_snprintf(tmpBuf,tmpBufSize,"%.2d",time->tm_year % 100 );
+ ADDSTR( bufPtr, bufSize, tmpBuf );
+ break;
+
+ case 'Y':
+ /* year as ccyy ( for example 1986 ) */
+ PR_snprintf(tmpBuf,tmpBufSize,"%.4d",time->tm_year );
+ ADDSTR( bufPtr, bufSize, tmpBuf );
+ break;
+
+ case 'Z':
+ /* Time zone name or no characters if no time zone exists.
+ * Since time zone name is supposed to be independant of locale, we
+ * defer to PR_FormatTime() for this option.
+ */
+ PR_FormatTime( tmpBuf, tmpBufSize, "%Z", time );
+ ADDSTR( bufPtr, bufSize, tmpBuf );
+ break;
+
+ default:
+ /* Unknown format. Simply copy format into output buffer. */
+ ADDCHAR( bufPtr, bufSize, '%' );
+ ADDCHAR( bufPtr, bufSize, *fmtPtr );
+ break;
+
+ }
+ }
+ }
+
+ ADDCHAR( bufPtr, bufSize, '\0' );
+ return (PRUint32)(bufPtr - buf - 1);
}
@@ -1997,38 +2112,39 @@ PR_FormatTimeUSEnglish( char* buf, PRUint32 bufSize,
* Returns the week number of the year (0-53) for the given time. firstDayOfWeek
* is the day on which the week is considered to start (0=Sun, 1=Mon, ...).
* Week 1 starts the first time firstDayOfWeek occurs in the year. In other words,
- * a partial week at the start of the year is considered week 0.
+ * a partial week at the start of the year is considered week 0.
*
**********************************************************************************/
static unsigned int
pr_WeekOfYear(const PRExplodedTime* time, unsigned int firstDayOfWeek)
{
- int dayOfWeek;
- int dayOfYear;
-
- /* Get the day of the year for the given time then adjust it to represent the
- * first day of the week containing the given time.
- */
- dayOfWeek = time->tm_wday - firstDayOfWeek;
- if (dayOfWeek < 0)
- dayOfWeek += 7;
-
- dayOfYear = time->tm_yday - dayOfWeek;
-
- if( dayOfYear <= 0 )
- {
- /* If dayOfYear is <= 0, it is in the first partial week of the year. */
- return 0;
- }
-
- /* Count the number of full weeks ( dayOfYear / 7 ) then add a week if there
- * are any days left over ( dayOfYear % 7 ). Because we are only counting to
- * the first day of the week containing the given time, rather than to the
- * actual day representing the given time, any days in week 0 will be "absorbed"
- * as extra days in the given week.
- */
- return (dayOfYear / 7) + ( (dayOfYear % 7) == 0 ? 0 : 1 );
+ int dayOfWeek;
+ int dayOfYear;
+
+ /* Get the day of the year for the given time then adjust it to represent the
+ * first day of the week containing the given time.
+ */
+ dayOfWeek = time->tm_wday - firstDayOfWeek;
+ if (dayOfWeek < 0) {
+ dayOfWeek += 7;
+ }
+
+ dayOfYear = time->tm_yday - dayOfWeek;
+
+ if( dayOfYear <= 0 )
+ {
+ /* If dayOfYear is <= 0, it is in the first partial week of the year. */
+ return 0;
+ }
+
+ /* Count the number of full weeks ( dayOfYear / 7 ) then add a week if there
+ * are any days left over ( dayOfYear % 7 ). Because we are only counting to
+ * the first day of the week containing the given time, rather than to the
+ * actual day representing the given time, any days in week 0 will be "absorbed"
+ * as extra days in the given week.
+ */
+ return (dayOfYear / 7) + ( (dayOfYear % 7) == 0 ? 0 : 1 );
}
diff --git a/nsprpub/pr/src/misc/prtpool.c b/nsprpub/pr/src/misc/prtpool.c
index c2cc9c803..69f588ef6 100644
--- a/nsprpub/pr/src/misc/prtpool.c
+++ b/nsprpub/pr/src/misc/prtpool.c
@@ -7,8 +7,8 @@
/*
* Thread pools
- * Thread pools create and manage threads to provide support for
- * scheduling jobs onto one or more threads.
+ * Thread pools create and manage threads to provide support for
+ * scheduling jobs onto one or more threads.
*
*/
#ifdef OPT_WINNT
@@ -19,32 +19,32 @@
* worker thread
*/
typedef struct wthread {
- PRCList links;
- PRThread *thread;
+ PRCList links;
+ PRThread *thread;
} wthread;
/*
* queue of timer jobs
*/
typedef struct timer_jobq {
- PRCList list;
- PRLock *lock;
- PRCondVar *cv;
- PRInt32 cnt;
- PRCList wthreads;
+ PRCList list;
+ PRLock *lock;
+ PRCondVar *cv;
+ PRInt32 cnt;
+ PRCList wthreads;
} timer_jobq;
/*
* queue of jobs
*/
typedef struct tp_jobq {
- PRCList list;
- PRInt32 cnt;
- PRLock *lock;
- PRCondVar *cv;
- PRCList wthreads;
+ PRCList list;
+ PRInt32 cnt;
+ PRLock *lock;
+ PRCondVar *cv;
+ PRCList wthreads;
#ifdef OPT_WINNT
- HANDLE nt_completion_port;
+ HANDLE nt_completion_port;
#endif
} tp_jobq;
@@ -52,62 +52,62 @@ typedef struct tp_jobq {
* queue of IO jobs
*/
typedef struct io_jobq {
- PRCList list;
- PRPollDesc *pollfds;
- PRInt32 npollfds;
- PRJob **polljobs;
- PRLock *lock;
- PRInt32 cnt;
- PRFileDesc *notify_fd;
- PRCList wthreads;
+ PRCList list;
+ PRPollDesc *pollfds;
+ PRInt32 npollfds;
+ PRJob **polljobs;
+ PRLock *lock;
+ PRInt32 cnt;
+ PRFileDesc *notify_fd;
+ PRCList wthreads;
} io_jobq;
/*
* Threadpool
*/
struct PRThreadPool {
- PRInt32 init_threads;
- PRInt32 max_threads;
- PRInt32 current_threads;
- PRInt32 idle_threads;
- PRUint32 stacksize;
- tp_jobq jobq;
- io_jobq ioq;
- timer_jobq timerq;
- PRLock *join_lock; /* used with jobp->join_cv */
- PRCondVar *shutdown_cv;
- PRBool shutdown;
+ PRInt32 init_threads;
+ PRInt32 max_threads;
+ PRInt32 current_threads;
+ PRInt32 idle_threads;
+ PRUint32 stacksize;
+ tp_jobq jobq;
+ io_jobq ioq;
+ timer_jobq timerq;
+ PRLock *join_lock; /* used with jobp->join_cv */
+ PRCondVar *shutdown_cv;
+ PRBool shutdown;
};
typedef enum io_op_type
- { JOB_IO_READ, JOB_IO_WRITE, JOB_IO_CONNECT, JOB_IO_ACCEPT } io_op_type;
+{ JOB_IO_READ, JOB_IO_WRITE, JOB_IO_CONNECT, JOB_IO_ACCEPT } io_op_type;
#ifdef OPT_WINNT
typedef struct NT_notifier {
- OVERLAPPED overlapped; /* must be first */
- PRJob *jobp;
+ OVERLAPPED overlapped; /* must be first */
+ PRJob *jobp;
} NT_notifier;
#endif
struct PRJob {
- PRCList links; /* for linking jobs */
- PRBool on_ioq; /* job on ioq */
- PRBool on_timerq; /* job on timerq */
- PRJobFn job_func;
- void *job_arg;
- PRCondVar *join_cv;
- PRBool join_wait; /* == PR_TRUE, when waiting to join */
- PRCondVar *cancel_cv; /* for cancelling IO jobs */
- PRBool cancel_io; /* for cancelling IO jobs */
- PRThreadPool *tpool; /* back pointer to thread pool */
- PRJobIoDesc *iod;
- io_op_type io_op;
- PRInt16 io_poll_flags;
- PRNetAddr *netaddr;
- PRIntervalTime timeout; /* relative value */
- PRIntervalTime absolute;
+ PRCList links; /* for linking jobs */
+ PRBool on_ioq; /* job on ioq */
+ PRBool on_timerq; /* job on timerq */
+ PRJobFn job_func;
+ void *job_arg;
+ PRCondVar *join_cv;
+ PRBool join_wait; /* == PR_TRUE, when waiting to join */
+ PRCondVar *cancel_cv; /* for cancelling IO jobs */
+ PRBool cancel_io; /* for cancelling IO jobs */
+ PRThreadPool *tpool; /* back pointer to thread pool */
+ PRJobIoDesc *iod;
+ io_op_type io_op;
+ PRInt16 io_poll_flags;
+ PRNetAddr *netaddr;
+ PRIntervalTime timeout; /* relative value */
+ PRIntervalTime absolute;
#ifdef OPT_WINNT
- NT_notifier nt_notifier;
+ NT_notifier nt_notifier;
#endif
};
@@ -119,22 +119,22 @@ struct PRJob {
#define JOINABLE_JOB(_jobp) (NULL != (_jobp)->join_cv)
-#define JOIN_NOTIFY(_jobp) \
- PR_BEGIN_MACRO \
- PR_Lock(_jobp->tpool->join_lock); \
- _jobp->join_wait = PR_FALSE; \
- PR_NotifyCondVar(_jobp->join_cv); \
- PR_Unlock(_jobp->tpool->join_lock); \
- PR_END_MACRO
-
-#define CANCEL_IO_JOB(jobp) \
- PR_BEGIN_MACRO \
- jobp->cancel_io = PR_FALSE; \
- jobp->on_ioq = PR_FALSE; \
- PR_REMOVE_AND_INIT_LINK(&jobp->links); \
- tp->ioq.cnt--; \
- PR_NotifyCondVar(jobp->cancel_cv); \
- PR_END_MACRO
+#define JOIN_NOTIFY(_jobp) \
+ PR_BEGIN_MACRO \
+ PR_Lock(_jobp->tpool->join_lock); \
+ _jobp->join_wait = PR_FALSE; \
+ PR_NotifyCondVar(_jobp->join_cv); \
+ PR_Unlock(_jobp->tpool->join_lock); \
+ PR_END_MACRO
+
+#define CANCEL_IO_JOB(jobp) \
+ PR_BEGIN_MACRO \
+ jobp->cancel_io = PR_FALSE; \
+ jobp->on_ioq = PR_FALSE; \
+ PR_REMOVE_AND_INIT_LINK(&jobp->links); \
+ tp->ioq.cnt--; \
+ PR_NotifyCondVar(jobp->cancel_cv); \
+ PR_END_MACRO
static void delete_job(PRJob *jobp);
static PRThreadPool * alloc_threadpool(void);
@@ -145,10 +145,10 @@ static void notify_timerq(PRThreadPool *tp);
/*
* locks are acquired in the following order
*
- * tp->ioq.lock,tp->timerq.lock
- * |
- * V
- * tp->jobq->lock
+ * tp->ioq.lock,tp->timerq.lock
+ * |
+ * V
+ * tp->jobq->lock
*/
/*
@@ -156,65 +156,66 @@ static void notify_timerq(PRThreadPool *tp);
*/
static void wstart(void *arg)
{
-PRThreadPool *tp = (PRThreadPool *) arg;
-PRCList *head;
-
- /*
- * execute jobs until shutdown
- */
- while (!tp->shutdown) {
- PRJob *jobp;
+ PRThreadPool *tp = (PRThreadPool *) arg;
+ PRCList *head;
+
+ /*
+ * execute jobs until shutdown
+ */
+ while (!tp->shutdown) {
+ PRJob *jobp;
#ifdef OPT_WINNT
- BOOL rv;
- DWORD unused, shutdown;
- LPOVERLAPPED olp;
-
- PR_Lock(tp->jobq.lock);
- tp->idle_threads++;
- PR_Unlock(tp->jobq.lock);
- rv = GetQueuedCompletionStatus(tp->jobq.nt_completion_port,
- &unused, &shutdown, &olp, INFINITE);
-
- PR_ASSERT(rv);
- if (shutdown)
- break;
- jobp = ((NT_notifier *) olp)->jobp;
- PR_Lock(tp->jobq.lock);
- tp->idle_threads--;
- tp->jobq.cnt--;
- PR_Unlock(tp->jobq.lock);
+ BOOL rv;
+ DWORD unused, shutdown;
+ LPOVERLAPPED olp;
+
+ PR_Lock(tp->jobq.lock);
+ tp->idle_threads++;
+ PR_Unlock(tp->jobq.lock);
+ rv = GetQueuedCompletionStatus(tp->jobq.nt_completion_port,
+ &unused, &shutdown, &olp, INFINITE);
+
+ PR_ASSERT(rv);
+ if (shutdown) {
+ break;
+ }
+ jobp = ((NT_notifier *) olp)->jobp;
+ PR_Lock(tp->jobq.lock);
+ tp->idle_threads--;
+ tp->jobq.cnt--;
+ PR_Unlock(tp->jobq.lock);
#else
- PR_Lock(tp->jobq.lock);
- while (PR_CLIST_IS_EMPTY(&tp->jobq.list) && (!tp->shutdown)) {
- tp->idle_threads++;
- PR_WaitCondVar(tp->jobq.cv, PR_INTERVAL_NO_TIMEOUT);
- tp->idle_threads--;
- }
- if (tp->shutdown) {
- PR_Unlock(tp->jobq.lock);
- break;
- }
- head = PR_LIST_HEAD(&tp->jobq.list);
- /*
- * remove job from queue
- */
- PR_REMOVE_AND_INIT_LINK(head);
- tp->jobq.cnt--;
- jobp = JOB_LINKS_PTR(head);
- PR_Unlock(tp->jobq.lock);
+ PR_Lock(tp->jobq.lock);
+ while (PR_CLIST_IS_EMPTY(&tp->jobq.list) && (!tp->shutdown)) {
+ tp->idle_threads++;
+ PR_WaitCondVar(tp->jobq.cv, PR_INTERVAL_NO_TIMEOUT);
+ tp->idle_threads--;
+ }
+ if (tp->shutdown) {
+ PR_Unlock(tp->jobq.lock);
+ break;
+ }
+ head = PR_LIST_HEAD(&tp->jobq.list);
+ /*
+ * remove job from queue
+ */
+ PR_REMOVE_AND_INIT_LINK(head);
+ tp->jobq.cnt--;
+ jobp = JOB_LINKS_PTR(head);
+ PR_Unlock(tp->jobq.lock);
#endif
- jobp->job_func(jobp->job_arg);
- if (!JOINABLE_JOB(jobp)) {
- delete_job(jobp);
- } else {
- JOIN_NOTIFY(jobp);
- }
- }
- PR_Lock(tp->jobq.lock);
- tp->current_threads--;
- PR_Unlock(tp->jobq.lock);
+ jobp->job_func(jobp->job_arg);
+ if (!JOINABLE_JOB(jobp)) {
+ delete_job(jobp);
+ } else {
+ JOIN_NOTIFY(jobp);
+ }
+ }
+ PR_Lock(tp->jobq.lock);
+ tp->current_threads--;
+ PR_Unlock(tp->jobq.lock);
}
/*
@@ -223,52 +224,52 @@ PRCList *head;
static void
add_to_jobq(PRThreadPool *tp, PRJob *jobp)
{
- /*
- * add to jobq
- */
+ /*
+ * add to jobq
+ */
#ifdef OPT_WINNT
- PR_Lock(tp->jobq.lock);
- tp->jobq.cnt++;
- PR_Unlock(tp->jobq.lock);
- /*
- * notify worker thread(s)
- */
- PostQueuedCompletionStatus(tp->jobq.nt_completion_port, 0,
- FALSE, &jobp->nt_notifier.overlapped);
+ PR_Lock(tp->jobq.lock);
+ tp->jobq.cnt++;
+ PR_Unlock(tp->jobq.lock);
+ /*
+ * notify worker thread(s)
+ */
+ PostQueuedCompletionStatus(tp->jobq.nt_completion_port, 0,
+ FALSE, &jobp->nt_notifier.overlapped);
#else
- PR_Lock(tp->jobq.lock);
- PR_APPEND_LINK(&jobp->links,&tp->jobq.list);
- tp->jobq.cnt++;
- if ((tp->idle_threads < tp->jobq.cnt) &&
- (tp->current_threads < tp->max_threads)) {
- wthread *wthrp;
- /*
- * increment thread count and unlock the jobq lock
- */
- tp->current_threads++;
- PR_Unlock(tp->jobq.lock);
- /* create new worker thread */
- wthrp = PR_NEWZAP(wthread);
- if (wthrp) {
- wthrp->thread = PR_CreateThread(PR_USER_THREAD, wstart,
- tp, PR_PRIORITY_NORMAL,
- PR_GLOBAL_THREAD,PR_JOINABLE_THREAD,tp->stacksize);
- if (NULL == wthrp->thread) {
- PR_DELETE(wthrp); /* this sets wthrp to NULL */
- }
- }
- PR_Lock(tp->jobq.lock);
- if (NULL == wthrp) {
- tp->current_threads--;
- } else {
- PR_APPEND_LINK(&wthrp->links, &tp->jobq.wthreads);
- }
- }
- /*
- * wakeup a worker thread
- */
- PR_NotifyCondVar(tp->jobq.cv);
- PR_Unlock(tp->jobq.lock);
+ PR_Lock(tp->jobq.lock);
+ PR_APPEND_LINK(&jobp->links,&tp->jobq.list);
+ tp->jobq.cnt++;
+ if ((tp->idle_threads < tp->jobq.cnt) &&
+ (tp->current_threads < tp->max_threads)) {
+ wthread *wthrp;
+ /*
+ * increment thread count and unlock the jobq lock
+ */
+ tp->current_threads++;
+ PR_Unlock(tp->jobq.lock);
+ /* create new worker thread */
+ wthrp = PR_NEWZAP(wthread);
+ if (wthrp) {
+ wthrp->thread = PR_CreateThread(PR_USER_THREAD, wstart,
+ tp, PR_PRIORITY_NORMAL,
+ PR_GLOBAL_THREAD,PR_JOINABLE_THREAD,tp->stacksize);
+ if (NULL == wthrp->thread) {
+ PR_DELETE(wthrp); /* this sets wthrp to NULL */
+ }
+ }
+ PR_Lock(tp->jobq.lock);
+ if (NULL == wthrp) {
+ tp->current_threads--;
+ } else {
+ PR_APPEND_LINK(&wthrp->links, &tp->jobq.wthreads);
+ }
+ }
+ /*
+ * wakeup a worker thread
+ */
+ PR_NotifyCondVar(tp->jobq.cv);
+ PR_Unlock(tp->jobq.lock);
#endif
}
@@ -277,207 +278,220 @@ add_to_jobq(PRThreadPool *tp, PRJob *jobp)
*/
static void io_wstart(void *arg)
{
-PRThreadPool *tp = (PRThreadPool *) arg;
-int pollfd_cnt, pollfds_used;
-int rv;
-PRCList *qp, *nextqp;
-PRPollDesc *pollfds = NULL;
-PRJob **polljobs = NULL;
-int poll_timeout;
-PRIntervalTime now;
-
- /*
- * scan io_jobq
- * construct poll list
- * call PR_Poll
- * for all fds, for which poll returns true, move the job to
- * jobq and wakeup worker thread.
- */
- while (!tp->shutdown) {
- PRJob *jobp;
-
- pollfd_cnt = tp->ioq.cnt + 10;
- if (pollfd_cnt > tp->ioq.npollfds) {
-
- /*
- * re-allocate pollfd array if the current one is not large
- * enough
- */
- if (NULL != tp->ioq.pollfds)
- PR_Free(tp->ioq.pollfds);
- tp->ioq.pollfds = (PRPollDesc *) PR_Malloc(pollfd_cnt *
- (sizeof(PRPollDesc) + sizeof(PRJob *)));
- PR_ASSERT(NULL != tp->ioq.pollfds);
- /*
- * array of pollfds
- */
- pollfds = tp->ioq.pollfds;
- tp->ioq.polljobs = (PRJob **) (&tp->ioq.pollfds[pollfd_cnt]);
- /*
- * parallel array of jobs
- */
- polljobs = tp->ioq.polljobs;
- tp->ioq.npollfds = pollfd_cnt;
- }
-
- pollfds_used = 0;
- /*
- * add the notify fd; used for unblocking io thread(s)
- */
- pollfds[pollfds_used].fd = tp->ioq.notify_fd;
- pollfds[pollfds_used].in_flags = PR_POLL_READ;
- pollfds[pollfds_used].out_flags = 0;
- polljobs[pollfds_used] = NULL;
- pollfds_used++;
- /*
- * fill in the pollfd array
- */
- PR_Lock(tp->ioq.lock);
- for (qp = tp->ioq.list.next; qp != &tp->ioq.list; qp = nextqp) {
- nextqp = qp->next;
- jobp = JOB_LINKS_PTR(qp);
- if (jobp->cancel_io) {
- CANCEL_IO_JOB(jobp);
- continue;
- }
- if (pollfds_used == (pollfd_cnt))
- break;
- pollfds[pollfds_used].fd = jobp->iod->socket;
- pollfds[pollfds_used].in_flags = jobp->io_poll_flags;
- pollfds[pollfds_used].out_flags = 0;
- polljobs[pollfds_used] = jobp;
-
- pollfds_used++;
- }
- if (!PR_CLIST_IS_EMPTY(&tp->ioq.list)) {
- qp = tp->ioq.list.next;
- jobp = JOB_LINKS_PTR(qp);
- if (PR_INTERVAL_NO_TIMEOUT == jobp->timeout)
- poll_timeout = PR_INTERVAL_NO_TIMEOUT;
- else if (PR_INTERVAL_NO_WAIT == jobp->timeout)
- poll_timeout = PR_INTERVAL_NO_WAIT;
- else {
- poll_timeout = jobp->absolute - PR_IntervalNow();
- if (poll_timeout <= 0) /* already timed out */
- poll_timeout = PR_INTERVAL_NO_WAIT;
- }
- } else {
- poll_timeout = PR_INTERVAL_NO_TIMEOUT;
- }
- PR_Unlock(tp->ioq.lock);
-
- /*
- * XXXX
- * should retry if more jobs have been added to the queue?
- *
- */
- PR_ASSERT(pollfds_used <= pollfd_cnt);
- rv = PR_Poll(tp->ioq.pollfds, pollfds_used, poll_timeout);
-
- if (tp->shutdown) {
- break;
- }
-
- if (rv > 0) {
- /*
- * at least one io event is set
- */
- PRStatus rval_status;
- PRInt32 index;
-
- PR_ASSERT(pollfds[0].fd == tp->ioq.notify_fd);
- /*
- * reset the pollable event, if notified
- */
- if (pollfds[0].out_flags & PR_POLL_READ) {
- rval_status = PR_WaitForPollableEvent(tp->ioq.notify_fd);
- PR_ASSERT(PR_SUCCESS == rval_status);
- }
-
- for(index = 1; index < (pollfds_used); index++) {
+ PRThreadPool *tp = (PRThreadPool *) arg;
+ int pollfd_cnt, pollfds_used;
+ int rv;
+ PRCList *qp, *nextqp;
+ PRPollDesc *pollfds = NULL;
+ PRJob **polljobs = NULL;
+ int poll_timeout;
+ PRIntervalTime now;
+
+ /*
+ * scan io_jobq
+ * construct poll list
+ * call PR_Poll
+ * for all fds, for which poll returns true, move the job to
+ * jobq and wakeup worker thread.
+ */
+ while (!tp->shutdown) {
+ PRJob *jobp;
+
+ pollfd_cnt = tp->ioq.cnt + 10;
+ if (pollfd_cnt > tp->ioq.npollfds) {
+
+ /*
+ * re-allocate pollfd array if the current one is not large
+ * enough
+ */
+ if (NULL != tp->ioq.pollfds) {
+ PR_Free(tp->ioq.pollfds);
+ }
+ tp->ioq.pollfds = (PRPollDesc *) PR_Malloc(pollfd_cnt *
+ (sizeof(PRPollDesc) + sizeof(PRJob *)));
+ PR_ASSERT(NULL != tp->ioq.pollfds);
+ /*
+ * array of pollfds
+ */
+ pollfds = tp->ioq.pollfds;
+ tp->ioq.polljobs = (PRJob **) (&tp->ioq.pollfds[pollfd_cnt]);
+ /*
+ * parallel array of jobs
+ */
+ polljobs = tp->ioq.polljobs;
+ tp->ioq.npollfds = pollfd_cnt;
+ }
+
+ pollfds_used = 0;
+ /*
+ * add the notify fd; used for unblocking io thread(s)
+ */
+ pollfds[pollfds_used].fd = tp->ioq.notify_fd;
+ pollfds[pollfds_used].in_flags = PR_POLL_READ;
+ pollfds[pollfds_used].out_flags = 0;
+ polljobs[pollfds_used] = NULL;
+ pollfds_used++;
+ /*
+ * fill in the pollfd array
+ */
+ PR_Lock(tp->ioq.lock);
+ for (qp = tp->ioq.list.next; qp != &tp->ioq.list; qp = nextqp) {
+ nextqp = qp->next;
+ jobp = JOB_LINKS_PTR(qp);
+ if (jobp->cancel_io) {
+ CANCEL_IO_JOB(jobp);
+ continue;
+ }
+ if (pollfds_used == (pollfd_cnt)) {
+ break;
+ }
+ pollfds[pollfds_used].fd = jobp->iod->socket;
+ pollfds[pollfds_used].in_flags = jobp->io_poll_flags;
+ pollfds[pollfds_used].out_flags = 0;
+ polljobs[pollfds_used] = jobp;
+
+ pollfds_used++;
+ }
+ if (!PR_CLIST_IS_EMPTY(&tp->ioq.list)) {
+ qp = tp->ioq.list.next;
+ jobp = JOB_LINKS_PTR(qp);
+ if (PR_INTERVAL_NO_TIMEOUT == jobp->timeout) {
+ poll_timeout = PR_INTERVAL_NO_TIMEOUT;
+ }
+ else if (PR_INTERVAL_NO_WAIT == jobp->timeout) {
+ poll_timeout = PR_INTERVAL_NO_WAIT;
+ }
+ else {
+ poll_timeout = jobp->absolute - PR_IntervalNow();
+ if (poll_timeout <= 0) { /* already timed out */
+ poll_timeout = PR_INTERVAL_NO_WAIT;
+ }
+ }
+ } else {
+ poll_timeout = PR_INTERVAL_NO_TIMEOUT;
+ }
+ PR_Unlock(tp->ioq.lock);
+
+ /*
+ * XXXX
+ * should retry if more jobs have been added to the queue?
+ *
+ */
+ PR_ASSERT(pollfds_used <= pollfd_cnt);
+ rv = PR_Poll(tp->ioq.pollfds, pollfds_used, poll_timeout);
+
+ if (tp->shutdown) {
+ break;
+ }
+
+ if (rv > 0) {
+ /*
+ * at least one io event is set
+ */
+ PRStatus rval_status;
+ PRInt32 index;
+
+ PR_ASSERT(pollfds[0].fd == tp->ioq.notify_fd);
+ /*
+ * reset the pollable event, if notified
+ */
+ if (pollfds[0].out_flags & PR_POLL_READ) {
+ rval_status = PR_WaitForPollableEvent(tp->ioq.notify_fd);
+ PR_ASSERT(PR_SUCCESS == rval_status);
+ }
+
+ for(index = 1; index < (pollfds_used); index++) {
PRInt16 events = pollfds[index].in_flags;
- PRInt16 revents = pollfds[index].out_flags;
- jobp = polljobs[index];
+ PRInt16 revents = pollfds[index].out_flags;
+ jobp = polljobs[index];
if ((revents & PR_POLL_NVAL) || /* busted in all cases */
- (revents & PR_POLL_ERR) ||
- ((events & PR_POLL_WRITE) &&
- (revents & PR_POLL_HUP))) { /* write op & hup */
- PR_Lock(tp->ioq.lock);
- if (jobp->cancel_io) {
- CANCEL_IO_JOB(jobp);
- PR_Unlock(tp->ioq.lock);
- continue;
- }
- PR_REMOVE_AND_INIT_LINK(&jobp->links);
- tp->ioq.cnt--;
- jobp->on_ioq = PR_FALSE;
- PR_Unlock(tp->ioq.lock);
-
- /* set error */
- if (PR_POLL_NVAL & revents)
- jobp->iod->error = PR_BAD_DESCRIPTOR_ERROR;
- else if (PR_POLL_HUP & revents)
- jobp->iod->error = PR_CONNECT_RESET_ERROR;
- else
- jobp->iod->error = PR_IO_ERROR;
-
- /*
- * add to jobq
- */
- add_to_jobq(tp, jobp);
- } else if (revents) {
- /*
- * add to jobq
- */
- PR_Lock(tp->ioq.lock);
- if (jobp->cancel_io) {
- CANCEL_IO_JOB(jobp);
- PR_Unlock(tp->ioq.lock);
- continue;
- }
- PR_REMOVE_AND_INIT_LINK(&jobp->links);
- tp->ioq.cnt--;
- jobp->on_ioq = PR_FALSE;
- PR_Unlock(tp->ioq.lock);
-
- if (jobp->io_op == JOB_IO_CONNECT) {
- if (PR_GetConnectStatus(&pollfds[index]) == PR_SUCCESS)
- jobp->iod->error = 0;
- else
- jobp->iod->error = PR_GetError();
- } else
- jobp->iod->error = 0;
-
- add_to_jobq(tp, jobp);
- }
- }
- }
- /*
- * timeout processing
- */
- now = PR_IntervalNow();
- PR_Lock(tp->ioq.lock);
- for (qp = tp->ioq.list.next; qp != &tp->ioq.list; qp = nextqp) {
- nextqp = qp->next;
- jobp = JOB_LINKS_PTR(qp);
- if (jobp->cancel_io) {
- CANCEL_IO_JOB(jobp);
- continue;
- }
- if (PR_INTERVAL_NO_TIMEOUT == jobp->timeout)
- break;
- if ((PR_INTERVAL_NO_WAIT != jobp->timeout) &&
- ((PRInt32)(jobp->absolute - now) > 0))
- break;
- PR_REMOVE_AND_INIT_LINK(&jobp->links);
- tp->ioq.cnt--;
- jobp->on_ioq = PR_FALSE;
- jobp->iod->error = PR_IO_TIMEOUT_ERROR;
- add_to_jobq(tp, jobp);
- }
- PR_Unlock(tp->ioq.lock);
- }
+ (revents & PR_POLL_ERR) ||
+ ((events & PR_POLL_WRITE) &&
+ (revents & PR_POLL_HUP))) { /* write op & hup */
+ PR_Lock(tp->ioq.lock);
+ if (jobp->cancel_io) {
+ CANCEL_IO_JOB(jobp);
+ PR_Unlock(tp->ioq.lock);
+ continue;
+ }
+ PR_REMOVE_AND_INIT_LINK(&jobp->links);
+ tp->ioq.cnt--;
+ jobp->on_ioq = PR_FALSE;
+ PR_Unlock(tp->ioq.lock);
+
+ /* set error */
+ if (PR_POLL_NVAL & revents) {
+ jobp->iod->error = PR_BAD_DESCRIPTOR_ERROR;
+ }
+ else if (PR_POLL_HUP & revents) {
+ jobp->iod->error = PR_CONNECT_RESET_ERROR;
+ }
+ else {
+ jobp->iod->error = PR_IO_ERROR;
+ }
+
+ /*
+ * add to jobq
+ */
+ add_to_jobq(tp, jobp);
+ } else if (revents) {
+ /*
+ * add to jobq
+ */
+ PR_Lock(tp->ioq.lock);
+ if (jobp->cancel_io) {
+ CANCEL_IO_JOB(jobp);
+ PR_Unlock(tp->ioq.lock);
+ continue;
+ }
+ PR_REMOVE_AND_INIT_LINK(&jobp->links);
+ tp->ioq.cnt--;
+ jobp->on_ioq = PR_FALSE;
+ PR_Unlock(tp->ioq.lock);
+
+ if (jobp->io_op == JOB_IO_CONNECT) {
+ if (PR_GetConnectStatus(&pollfds[index]) == PR_SUCCESS) {
+ jobp->iod->error = 0;
+ }
+ else {
+ jobp->iod->error = PR_GetError();
+ }
+ } else {
+ jobp->iod->error = 0;
+ }
+
+ add_to_jobq(tp, jobp);
+ }
+ }
+ }
+ /*
+ * timeout processing
+ */
+ now = PR_IntervalNow();
+ PR_Lock(tp->ioq.lock);
+ for (qp = tp->ioq.list.next; qp != &tp->ioq.list; qp = nextqp) {
+ nextqp = qp->next;
+ jobp = JOB_LINKS_PTR(qp);
+ if (jobp->cancel_io) {
+ CANCEL_IO_JOB(jobp);
+ continue;
+ }
+ if (PR_INTERVAL_NO_TIMEOUT == jobp->timeout) {
+ break;
+ }
+ if ((PR_INTERVAL_NO_WAIT != jobp->timeout) &&
+ ((PRInt32)(jobp->absolute - now) > 0)) {
+ break;
+ }
+ PR_REMOVE_AND_INIT_LINK(&jobp->links);
+ tp->ioq.cnt--;
+ jobp->on_ioq = PR_FALSE;
+ jobp->iod->error = PR_IO_TIMEOUT_ERROR;
+ add_to_jobq(tp, jobp);
+ }
+ PR_Unlock(tp->ioq.lock);
+ }
}
/*
@@ -485,391 +499,419 @@ PRIntervalTime now;
*/
static void timer_wstart(void *arg)
{
-PRThreadPool *tp = (PRThreadPool *) arg;
-PRCList *qp;
-PRIntervalTime timeout;
-PRIntervalTime now;
-
- /*
- * call PR_WaitCondVar with minimum value of all timeouts
- */
- while (!tp->shutdown) {
- PRJob *jobp;
-
- PR_Lock(tp->timerq.lock);
- if (PR_CLIST_IS_EMPTY(&tp->timerq.list)) {
- timeout = PR_INTERVAL_NO_TIMEOUT;
- } else {
- PRCList *qp;
-
- qp = tp->timerq.list.next;
- jobp = JOB_LINKS_PTR(qp);
-
- timeout = jobp->absolute - PR_IntervalNow();
- if (timeout <= 0)
- timeout = PR_INTERVAL_NO_WAIT; /* already timed out */
- }
- if (PR_INTERVAL_NO_WAIT != timeout)
- PR_WaitCondVar(tp->timerq.cv, timeout);
- if (tp->shutdown) {
- PR_Unlock(tp->timerq.lock);
- break;
- }
- /*
- * move expired-timer jobs to jobq
- */
- now = PR_IntervalNow();
- while (!PR_CLIST_IS_EMPTY(&tp->timerq.list)) {
- qp = tp->timerq.list.next;
- jobp = JOB_LINKS_PTR(qp);
-
- if ((PRInt32)(jobp->absolute - now) > 0) {
- break;
- }
- /*
- * job timed out
- */
- PR_REMOVE_AND_INIT_LINK(&jobp->links);
- tp->timerq.cnt--;
- jobp->on_timerq = PR_FALSE;
- add_to_jobq(tp, jobp);
- }
- PR_Unlock(tp->timerq.lock);
- }
+ PRThreadPool *tp = (PRThreadPool *) arg;
+ PRCList *qp;
+ PRIntervalTime timeout;
+ PRIntervalTime now;
+
+ /*
+ * call PR_WaitCondVar with minimum value of all timeouts
+ */
+ while (!tp->shutdown) {
+ PRJob *jobp;
+
+ PR_Lock(tp->timerq.lock);
+ if (PR_CLIST_IS_EMPTY(&tp->timerq.list)) {
+ timeout = PR_INTERVAL_NO_TIMEOUT;
+ } else {
+ PRCList *qp;
+
+ qp = tp->timerq.list.next;
+ jobp = JOB_LINKS_PTR(qp);
+
+ timeout = jobp->absolute - PR_IntervalNow();
+ if (timeout <= 0) {
+ timeout = PR_INTERVAL_NO_WAIT; /* already timed out */
+ }
+ }
+ if (PR_INTERVAL_NO_WAIT != timeout) {
+ PR_WaitCondVar(tp->timerq.cv, timeout);
+ }
+ if (tp->shutdown) {
+ PR_Unlock(tp->timerq.lock);
+ break;
+ }
+ /*
+ * move expired-timer jobs to jobq
+ */
+ now = PR_IntervalNow();
+ while (!PR_CLIST_IS_EMPTY(&tp->timerq.list)) {
+ qp = tp->timerq.list.next;
+ jobp = JOB_LINKS_PTR(qp);
+
+ if ((PRInt32)(jobp->absolute - now) > 0) {
+ break;
+ }
+ /*
+ * job timed out
+ */
+ PR_REMOVE_AND_INIT_LINK(&jobp->links);
+ tp->timerq.cnt--;
+ jobp->on_timerq = PR_FALSE;
+ add_to_jobq(tp, jobp);
+ }
+ PR_Unlock(tp->timerq.lock);
+ }
}
static void
delete_threadpool(PRThreadPool *tp)
{
- if (NULL != tp) {
- if (NULL != tp->shutdown_cv)
- PR_DestroyCondVar(tp->shutdown_cv);
- if (NULL != tp->jobq.cv)
- PR_DestroyCondVar(tp->jobq.cv);
- if (NULL != tp->jobq.lock)
- PR_DestroyLock(tp->jobq.lock);
- if (NULL != tp->join_lock)
- PR_DestroyLock(tp->join_lock);
+ if (NULL != tp) {
+ if (NULL != tp->shutdown_cv) {
+ PR_DestroyCondVar(tp->shutdown_cv);
+ }
+ if (NULL != tp->jobq.cv) {
+ PR_DestroyCondVar(tp->jobq.cv);
+ }
+ if (NULL != tp->jobq.lock) {
+ PR_DestroyLock(tp->jobq.lock);
+ }
+ if (NULL != tp->join_lock) {
+ PR_DestroyLock(tp->join_lock);
+ }
#ifdef OPT_WINNT
- if (NULL != tp->jobq.nt_completion_port)
- CloseHandle(tp->jobq.nt_completion_port);
+ if (NULL != tp->jobq.nt_completion_port) {
+ CloseHandle(tp->jobq.nt_completion_port);
+ }
#endif
- /* Timer queue */
- if (NULL != tp->timerq.cv)
- PR_DestroyCondVar(tp->timerq.cv);
- if (NULL != tp->timerq.lock)
- PR_DestroyLock(tp->timerq.lock);
-
- if (NULL != tp->ioq.lock)
- PR_DestroyLock(tp->ioq.lock);
- if (NULL != tp->ioq.pollfds)
- PR_Free(tp->ioq.pollfds);
- if (NULL != tp->ioq.notify_fd)
- PR_DestroyPollableEvent(tp->ioq.notify_fd);
- PR_Free(tp);
- }
- return;
+ /* Timer queue */
+ if (NULL != tp->timerq.cv) {
+ PR_DestroyCondVar(tp->timerq.cv);
+ }
+ if (NULL != tp->timerq.lock) {
+ PR_DestroyLock(tp->timerq.lock);
+ }
+
+ if (NULL != tp->ioq.lock) {
+ PR_DestroyLock(tp->ioq.lock);
+ }
+ if (NULL != tp->ioq.pollfds) {
+ PR_Free(tp->ioq.pollfds);
+ }
+ if (NULL != tp->ioq.notify_fd) {
+ PR_DestroyPollableEvent(tp->ioq.notify_fd);
+ }
+ PR_Free(tp);
+ }
+ return;
}
static PRThreadPool *
alloc_threadpool(void)
{
-PRThreadPool *tp;
-
- tp = (PRThreadPool *) PR_CALLOC(sizeof(*tp));
- if (NULL == tp)
- goto failed;
- tp->jobq.lock = PR_NewLock();
- if (NULL == tp->jobq.lock)
- goto failed;
- tp->jobq.cv = PR_NewCondVar(tp->jobq.lock);
- if (NULL == tp->jobq.cv)
- goto failed;
- tp->join_lock = PR_NewLock();
- if (NULL == tp->join_lock)
- goto failed;
+ PRThreadPool *tp;
+
+ tp = (PRThreadPool *) PR_CALLOC(sizeof(*tp));
+ if (NULL == tp) {
+ goto failed;
+ }
+ tp->jobq.lock = PR_NewLock();
+ if (NULL == tp->jobq.lock) {
+ goto failed;
+ }
+ tp->jobq.cv = PR_NewCondVar(tp->jobq.lock);
+ if (NULL == tp->jobq.cv) {
+ goto failed;
+ }
+ tp->join_lock = PR_NewLock();
+ if (NULL == tp->join_lock) {
+ goto failed;
+ }
#ifdef OPT_WINNT
- tp->jobq.nt_completion_port = CreateIoCompletionPort(INVALID_HANDLE_VALUE,
- NULL, 0, 0);
- if (NULL == tp->jobq.nt_completion_port)
- goto failed;
+ tp->jobq.nt_completion_port = CreateIoCompletionPort(INVALID_HANDLE_VALUE,
+ NULL, 0, 0);
+ if (NULL == tp->jobq.nt_completion_port) {
+ goto failed;
+ }
#endif
- tp->ioq.lock = PR_NewLock();
- if (NULL == tp->ioq.lock)
- goto failed;
-
- /* Timer queue */
-
- tp->timerq.lock = PR_NewLock();
- if (NULL == tp->timerq.lock)
- goto failed;
- tp->timerq.cv = PR_NewCondVar(tp->timerq.lock);
- if (NULL == tp->timerq.cv)
- goto failed;
-
- tp->shutdown_cv = PR_NewCondVar(tp->jobq.lock);
- if (NULL == tp->shutdown_cv)
- goto failed;
- tp->ioq.notify_fd = PR_NewPollableEvent();
- if (NULL == tp->ioq.notify_fd)
- goto failed;
- return tp;
+ tp->ioq.lock = PR_NewLock();
+ if (NULL == tp->ioq.lock) {
+ goto failed;
+ }
+
+ /* Timer queue */
+
+ tp->timerq.lock = PR_NewLock();
+ if (NULL == tp->timerq.lock) {
+ goto failed;
+ }
+ tp->timerq.cv = PR_NewCondVar(tp->timerq.lock);
+ if (NULL == tp->timerq.cv) {
+ goto failed;
+ }
+
+ tp->shutdown_cv = PR_NewCondVar(tp->jobq.lock);
+ if (NULL == tp->shutdown_cv) {
+ goto failed;
+ }
+ tp->ioq.notify_fd = PR_NewPollableEvent();
+ if (NULL == tp->ioq.notify_fd) {
+ goto failed;
+ }
+ return tp;
failed:
- delete_threadpool(tp);
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
- return NULL;
+ delete_threadpool(tp);
+ PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+ return NULL;
}
/* Create thread pool */
PR_IMPLEMENT(PRThreadPool *)
PR_CreateThreadPool(PRInt32 initial_threads, PRInt32 max_threads,
- PRUint32 stacksize)
+ PRUint32 stacksize)
{
-PRThreadPool *tp;
-PRThread *thr;
-int i;
-wthread *wthrp;
-
- tp = alloc_threadpool();
- if (NULL == tp)
- return NULL;
-
- tp->init_threads = initial_threads;
- tp->max_threads = max_threads;
- tp->stacksize = stacksize;
- PR_INIT_CLIST(&tp->jobq.list);
- PR_INIT_CLIST(&tp->ioq.list);
- PR_INIT_CLIST(&tp->timerq.list);
- PR_INIT_CLIST(&tp->jobq.wthreads);
- PR_INIT_CLIST(&tp->ioq.wthreads);
- PR_INIT_CLIST(&tp->timerq.wthreads);
- tp->shutdown = PR_FALSE;
-
- PR_Lock(tp->jobq.lock);
- for(i=0; i < initial_threads; ++i) {
-
- thr = PR_CreateThread(PR_USER_THREAD, wstart,
- tp, PR_PRIORITY_NORMAL,
- PR_GLOBAL_THREAD, PR_JOINABLE_THREAD,stacksize);
- PR_ASSERT(thr);
- wthrp = PR_NEWZAP(wthread);
- PR_ASSERT(wthrp);
- wthrp->thread = thr;
- PR_APPEND_LINK(&wthrp->links, &tp->jobq.wthreads);
- }
- tp->current_threads = initial_threads;
-
- thr = PR_CreateThread(PR_USER_THREAD, io_wstart,
- tp, PR_PRIORITY_NORMAL,
- PR_GLOBAL_THREAD,PR_JOINABLE_THREAD,stacksize);
- PR_ASSERT(thr);
- wthrp = PR_NEWZAP(wthread);
- PR_ASSERT(wthrp);
- wthrp->thread = thr;
- PR_APPEND_LINK(&wthrp->links, &tp->ioq.wthreads);
-
- thr = PR_CreateThread(PR_USER_THREAD, timer_wstart,
- tp, PR_PRIORITY_NORMAL,
- PR_GLOBAL_THREAD,PR_JOINABLE_THREAD,stacksize);
- PR_ASSERT(thr);
- wthrp = PR_NEWZAP(wthread);
- PR_ASSERT(wthrp);
- wthrp->thread = thr;
- PR_APPEND_LINK(&wthrp->links, &tp->timerq.wthreads);
-
- PR_Unlock(tp->jobq.lock);
- return tp;
+ PRThreadPool *tp;
+ PRThread *thr;
+ int i;
+ wthread *wthrp;
+
+ tp = alloc_threadpool();
+ if (NULL == tp) {
+ return NULL;
+ }
+
+ tp->init_threads = initial_threads;
+ tp->max_threads = max_threads;
+ tp->stacksize = stacksize;
+ PR_INIT_CLIST(&tp->jobq.list);
+ PR_INIT_CLIST(&tp->ioq.list);
+ PR_INIT_CLIST(&tp->timerq.list);
+ PR_INIT_CLIST(&tp->jobq.wthreads);
+ PR_INIT_CLIST(&tp->ioq.wthreads);
+ PR_INIT_CLIST(&tp->timerq.wthreads);
+ tp->shutdown = PR_FALSE;
+
+ PR_Lock(tp->jobq.lock);
+ for(i=0; i < initial_threads; ++i) {
+
+ thr = PR_CreateThread(PR_USER_THREAD, wstart,
+ tp, PR_PRIORITY_NORMAL,
+ PR_GLOBAL_THREAD, PR_JOINABLE_THREAD,stacksize);
+ PR_ASSERT(thr);
+ wthrp = PR_NEWZAP(wthread);
+ PR_ASSERT(wthrp);
+ wthrp->thread = thr;
+ PR_APPEND_LINK(&wthrp->links, &tp->jobq.wthreads);
+ }
+ tp->current_threads = initial_threads;
+
+ thr = PR_CreateThread(PR_USER_THREAD, io_wstart,
+ tp, PR_PRIORITY_NORMAL,
+ PR_GLOBAL_THREAD,PR_JOINABLE_THREAD,stacksize);
+ PR_ASSERT(thr);
+ wthrp = PR_NEWZAP(wthread);
+ PR_ASSERT(wthrp);
+ wthrp->thread = thr;
+ PR_APPEND_LINK(&wthrp->links, &tp->ioq.wthreads);
+
+ thr = PR_CreateThread(PR_USER_THREAD, timer_wstart,
+ tp, PR_PRIORITY_NORMAL,
+ PR_GLOBAL_THREAD,PR_JOINABLE_THREAD,stacksize);
+ PR_ASSERT(thr);
+ wthrp = PR_NEWZAP(wthread);
+ PR_ASSERT(wthrp);
+ wthrp->thread = thr;
+ PR_APPEND_LINK(&wthrp->links, &tp->timerq.wthreads);
+
+ PR_Unlock(tp->jobq.lock);
+ return tp;
}
static void
delete_job(PRJob *jobp)
{
- if (NULL != jobp) {
- if (NULL != jobp->join_cv) {
- PR_DestroyCondVar(jobp->join_cv);
- jobp->join_cv = NULL;
- }
- if (NULL != jobp->cancel_cv) {
- PR_DestroyCondVar(jobp->cancel_cv);
- jobp->cancel_cv = NULL;
- }
- PR_DELETE(jobp);
- }
+ if (NULL != jobp) {
+ if (NULL != jobp->join_cv) {
+ PR_DestroyCondVar(jobp->join_cv);
+ jobp->join_cv = NULL;
+ }
+ if (NULL != jobp->cancel_cv) {
+ PR_DestroyCondVar(jobp->cancel_cv);
+ jobp->cancel_cv = NULL;
+ }
+ PR_DELETE(jobp);
+ }
}
static PRJob *
alloc_job(PRBool joinable, PRThreadPool *tp)
{
- PRJob *jobp;
-
- jobp = PR_NEWZAP(PRJob);
- if (NULL == jobp)
- goto failed;
- if (joinable) {
- jobp->join_cv = PR_NewCondVar(tp->join_lock);
- jobp->join_wait = PR_TRUE;
- if (NULL == jobp->join_cv)
- goto failed;
- } else {
- jobp->join_cv = NULL;
- }
+ PRJob *jobp;
+
+ jobp = PR_NEWZAP(PRJob);
+ if (NULL == jobp) {
+ goto failed;
+ }
+ if (joinable) {
+ jobp->join_cv = PR_NewCondVar(tp->join_lock);
+ jobp->join_wait = PR_TRUE;
+ if (NULL == jobp->join_cv) {
+ goto failed;
+ }
+ } else {
+ jobp->join_cv = NULL;
+ }
#ifdef OPT_WINNT
- jobp->nt_notifier.jobp = jobp;
+ jobp->nt_notifier.jobp = jobp;
#endif
- return jobp;
+ return jobp;
failed:
- delete_job(jobp);
- PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
- return NULL;
+ delete_job(jobp);
+ PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+ return NULL;
}
/* queue a job */
PR_IMPLEMENT(PRJob *)
PR_QueueJob(PRThreadPool *tpool, PRJobFn fn, void *arg, PRBool joinable)
{
- PRJob *jobp;
+ PRJob *jobp;
- jobp = alloc_job(joinable, tpool);
- if (NULL == jobp)
- return NULL;
+ jobp = alloc_job(joinable, tpool);
+ if (NULL == jobp) {
+ return NULL;
+ }
- jobp->job_func = fn;
- jobp->job_arg = arg;
- jobp->tpool = tpool;
+ jobp->job_func = fn;
+ jobp->job_arg = arg;
+ jobp->tpool = tpool;
- add_to_jobq(tpool, jobp);
- return jobp;
+ add_to_jobq(tpool, jobp);
+ return jobp;
}
/* queue a job, when a socket is readable or writeable */
static PRJob *
queue_io_job(PRThreadPool *tpool, PRJobIoDesc *iod, PRJobFn fn, void * arg,
- PRBool joinable, io_op_type op)
+ PRBool joinable, io_op_type op)
{
- PRJob *jobp;
- PRIntervalTime now;
-
- jobp = alloc_job(joinable, tpool);
- if (NULL == jobp) {
- return NULL;
- }
-
- /*
- * Add a new job to io_jobq
- * wakeup io worker thread
- */
-
- jobp->job_func = fn;
- jobp->job_arg = arg;
- jobp->tpool = tpool;
- jobp->iod = iod;
- if (JOB_IO_READ == op) {
- jobp->io_op = JOB_IO_READ;
- jobp->io_poll_flags = PR_POLL_READ;
- } else if (JOB_IO_WRITE == op) {
- jobp->io_op = JOB_IO_WRITE;
- jobp->io_poll_flags = PR_POLL_WRITE;
- } else if (JOB_IO_ACCEPT == op) {
- jobp->io_op = JOB_IO_ACCEPT;
- jobp->io_poll_flags = PR_POLL_READ;
- } else if (JOB_IO_CONNECT == op) {
- jobp->io_op = JOB_IO_CONNECT;
- jobp->io_poll_flags = PR_POLL_WRITE|PR_POLL_EXCEPT;
- } else {
- delete_job(jobp);
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
- return NULL;
- }
-
- jobp->timeout = iod->timeout;
- if ((PR_INTERVAL_NO_TIMEOUT == iod->timeout) ||
- (PR_INTERVAL_NO_WAIT == iod->timeout)) {
- jobp->absolute = iod->timeout;
- } else {
- now = PR_IntervalNow();
- jobp->absolute = now + iod->timeout;
- }
-
-
- PR_Lock(tpool->ioq.lock);
-
- if (PR_CLIST_IS_EMPTY(&tpool->ioq.list) ||
- (PR_INTERVAL_NO_TIMEOUT == iod->timeout)) {
- PR_APPEND_LINK(&jobp->links,&tpool->ioq.list);
- } else if (PR_INTERVAL_NO_WAIT == iod->timeout) {
- PR_INSERT_LINK(&jobp->links,&tpool->ioq.list);
- } else {
- PRCList *qp;
- PRJob *tmp_jobp;
- /*
- * insert into the timeout-sorted ioq
- */
- for (qp = tpool->ioq.list.prev; qp != &tpool->ioq.list;
- qp = qp->prev) {
- tmp_jobp = JOB_LINKS_PTR(qp);
- if ((PRInt32)(jobp->absolute - tmp_jobp->absolute) >= 0) {
- break;
- }
- }
- PR_INSERT_AFTER(&jobp->links,qp);
- }
-
- jobp->on_ioq = PR_TRUE;
- tpool->ioq.cnt++;
- /*
- * notify io worker thread(s)
- */
- PR_Unlock(tpool->ioq.lock);
- notify_ioq(tpool);
- return jobp;
+ PRJob *jobp;
+ PRIntervalTime now;
+
+ jobp = alloc_job(joinable, tpool);
+ if (NULL == jobp) {
+ return NULL;
+ }
+
+ /*
+ * Add a new job to io_jobq
+ * wakeup io worker thread
+ */
+
+ jobp->job_func = fn;
+ jobp->job_arg = arg;
+ jobp->tpool = tpool;
+ jobp->iod = iod;
+ if (JOB_IO_READ == op) {
+ jobp->io_op = JOB_IO_READ;
+ jobp->io_poll_flags = PR_POLL_READ;
+ } else if (JOB_IO_WRITE == op) {
+ jobp->io_op = JOB_IO_WRITE;
+ jobp->io_poll_flags = PR_POLL_WRITE;
+ } else if (JOB_IO_ACCEPT == op) {
+ jobp->io_op = JOB_IO_ACCEPT;
+ jobp->io_poll_flags = PR_POLL_READ;
+ } else if (JOB_IO_CONNECT == op) {
+ jobp->io_op = JOB_IO_CONNECT;
+ jobp->io_poll_flags = PR_POLL_WRITE|PR_POLL_EXCEPT;
+ } else {
+ delete_job(jobp);
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+ return NULL;
+ }
+
+ jobp->timeout = iod->timeout;
+ if ((PR_INTERVAL_NO_TIMEOUT == iod->timeout) ||
+ (PR_INTERVAL_NO_WAIT == iod->timeout)) {
+ jobp->absolute = iod->timeout;
+ } else {
+ now = PR_IntervalNow();
+ jobp->absolute = now + iod->timeout;
+ }
+
+
+ PR_Lock(tpool->ioq.lock);
+
+ if (PR_CLIST_IS_EMPTY(&tpool->ioq.list) ||
+ (PR_INTERVAL_NO_TIMEOUT == iod->timeout)) {
+ PR_APPEND_LINK(&jobp->links,&tpool->ioq.list);
+ } else if (PR_INTERVAL_NO_WAIT == iod->timeout) {
+ PR_INSERT_LINK(&jobp->links,&tpool->ioq.list);
+ } else {
+ PRCList *qp;
+ PRJob *tmp_jobp;
+ /*
+ * insert into the timeout-sorted ioq
+ */
+ for (qp = tpool->ioq.list.prev; qp != &tpool->ioq.list;
+ qp = qp->prev) {
+ tmp_jobp = JOB_LINKS_PTR(qp);
+ if ((PRInt32)(jobp->absolute - tmp_jobp->absolute) >= 0) {
+ break;
+ }
+ }
+ PR_INSERT_AFTER(&jobp->links,qp);
+ }
+
+ jobp->on_ioq = PR_TRUE;
+ tpool->ioq.cnt++;
+ /*
+ * notify io worker thread(s)
+ */
+ PR_Unlock(tpool->ioq.lock);
+ notify_ioq(tpool);
+ return jobp;
}
/* queue a job, when a socket is readable */
PR_IMPLEMENT(PRJob *)
PR_QueueJob_Read(PRThreadPool *tpool, PRJobIoDesc *iod, PRJobFn fn, void * arg,
- PRBool joinable)
+ PRBool joinable)
{
- return (queue_io_job(tpool, iod, fn, arg, joinable, JOB_IO_READ));
+ return (queue_io_job(tpool, iod, fn, arg, joinable, JOB_IO_READ));
}
/* queue a job, when a socket is writeable */
PR_IMPLEMENT(PRJob *)
PR_QueueJob_Write(PRThreadPool *tpool, PRJobIoDesc *iod, PRJobFn fn,void * arg,
- PRBool joinable)
+ PRBool joinable)
{
- return (queue_io_job(tpool, iod, fn, arg, joinable, JOB_IO_WRITE));
+ return (queue_io_job(tpool, iod, fn, arg, joinable, JOB_IO_WRITE));
}
/* queue a job, when a socket has a pending connection */
PR_IMPLEMENT(PRJob *)
PR_QueueJob_Accept(PRThreadPool *tpool, PRJobIoDesc *iod, PRJobFn fn,
- void * arg, PRBool joinable)
+ void * arg, PRBool joinable)
{
- return (queue_io_job(tpool, iod, fn, arg, joinable, JOB_IO_ACCEPT));
+ return (queue_io_job(tpool, iod, fn, arg, joinable, JOB_IO_ACCEPT));
}
/* queue a job, when a socket can be connected */
PR_IMPLEMENT(PRJob *)
PR_QueueJob_Connect(PRThreadPool *tpool, PRJobIoDesc *iod,
- const PRNetAddr *addr, PRJobFn fn, void * arg, PRBool joinable)
+ const PRNetAddr *addr, PRJobFn fn, void * arg, PRBool joinable)
{
- PRStatus rv;
- PRErrorCode err;
-
- rv = PR_Connect(iod->socket, addr, PR_INTERVAL_NO_WAIT);
- if ((rv == PR_FAILURE) && ((err = PR_GetError()) == PR_IN_PROGRESS_ERROR)){
- /* connection pending */
- return(queue_io_job(tpool, iod, fn, arg, joinable, JOB_IO_CONNECT));
- }
+ PRStatus rv;
+ PRErrorCode err;
+
+ rv = PR_Connect(iod->socket, addr, PR_INTERVAL_NO_WAIT);
+ if ((rv == PR_FAILURE) && ((err = PR_GetError()) == PR_IN_PROGRESS_ERROR)) {
+ /* connection pending */
+ return(queue_io_job(tpool, iod, fn, arg, joinable, JOB_IO_CONNECT));
+ }
/*
* connection succeeded or failed; add to jobq right away
*/
- if (rv == PR_FAILURE)
- iod->error = err;
- else
- iod->error = 0;
+ if (rv == PR_FAILURE) {
+ iod->error = err;
+ }
+ else {
+ iod->error = 0;
+ }
return(PR_QueueJob(tpool, fn, arg, joinable));
}
@@ -877,311 +919,318 @@ PR_QueueJob_Connect(PRThreadPool *tpool, PRJobIoDesc *iod,
/* queue a job, when a timer expires */
PR_IMPLEMENT(PRJob *)
PR_QueueJob_Timer(PRThreadPool *tpool, PRIntervalTime timeout,
- PRJobFn fn, void * arg, PRBool joinable)
+ PRJobFn fn, void * arg, PRBool joinable)
{
- PRIntervalTime now;
- PRJob *jobp;
-
- if (PR_INTERVAL_NO_TIMEOUT == timeout) {
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
- return NULL;
- }
- if (PR_INTERVAL_NO_WAIT == timeout) {
- /*
- * no waiting; add to jobq right away
- */
- return(PR_QueueJob(tpool, fn, arg, joinable));
- }
- jobp = alloc_job(joinable, tpool);
- if (NULL == jobp) {
- return NULL;
- }
-
- /*
- * Add a new job to timer_jobq
- * wakeup timer worker thread
- */
-
- jobp->job_func = fn;
- jobp->job_arg = arg;
- jobp->tpool = tpool;
- jobp->timeout = timeout;
-
- now = PR_IntervalNow();
- jobp->absolute = now + timeout;
-
-
- PR_Lock(tpool->timerq.lock);
- jobp->on_timerq = PR_TRUE;
- if (PR_CLIST_IS_EMPTY(&tpool->timerq.list))
- PR_APPEND_LINK(&jobp->links,&tpool->timerq.list);
- else {
- PRCList *qp;
- PRJob *tmp_jobp;
- /*
- * insert into the sorted timer jobq
- */
- for (qp = tpool->timerq.list.prev; qp != &tpool->timerq.list;
- qp = qp->prev) {
- tmp_jobp = JOB_LINKS_PTR(qp);
- if ((PRInt32)(jobp->absolute - tmp_jobp->absolute) >= 0) {
- break;
- }
- }
- PR_INSERT_AFTER(&jobp->links,qp);
- }
- tpool->timerq.cnt++;
- /*
- * notify timer worker thread(s)
- */
- notify_timerq(tpool);
- PR_Unlock(tpool->timerq.lock);
- return jobp;
+ PRIntervalTime now;
+ PRJob *jobp;
+
+ if (PR_INTERVAL_NO_TIMEOUT == timeout) {
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+ return NULL;
+ }
+ if (PR_INTERVAL_NO_WAIT == timeout) {
+ /*
+ * no waiting; add to jobq right away
+ */
+ return(PR_QueueJob(tpool, fn, arg, joinable));
+ }
+ jobp = alloc_job(joinable, tpool);
+ if (NULL == jobp) {
+ return NULL;
+ }
+
+ /*
+ * Add a new job to timer_jobq
+ * wakeup timer worker thread
+ */
+
+ jobp->job_func = fn;
+ jobp->job_arg = arg;
+ jobp->tpool = tpool;
+ jobp->timeout = timeout;
+
+ now = PR_IntervalNow();
+ jobp->absolute = now + timeout;
+
+
+ PR_Lock(tpool->timerq.lock);
+ jobp->on_timerq = PR_TRUE;
+ if (PR_CLIST_IS_EMPTY(&tpool->timerq.list)) {
+ PR_APPEND_LINK(&jobp->links,&tpool->timerq.list);
+ }
+ else {
+ PRCList *qp;
+ PRJob *tmp_jobp;
+ /*
+ * insert into the sorted timer jobq
+ */
+ for (qp = tpool->timerq.list.prev; qp != &tpool->timerq.list;
+ qp = qp->prev) {
+ tmp_jobp = JOB_LINKS_PTR(qp);
+ if ((PRInt32)(jobp->absolute - tmp_jobp->absolute) >= 0) {
+ break;
+ }
+ }
+ PR_INSERT_AFTER(&jobp->links,qp);
+ }
+ tpool->timerq.cnt++;
+ /*
+ * notify timer worker thread(s)
+ */
+ notify_timerq(tpool);
+ PR_Unlock(tpool->timerq.lock);
+ return jobp;
}
static void
notify_timerq(PRThreadPool *tp)
{
- /*
- * wakeup the timer thread(s)
- */
- PR_NotifyCondVar(tp->timerq.cv);
+ /*
+ * wakeup the timer thread(s)
+ */
+ PR_NotifyCondVar(tp->timerq.cv);
}
static void
notify_ioq(PRThreadPool *tp)
{
-PRStatus rval_status;
+ PRStatus rval_status;
- /*
- * wakeup the io thread(s)
- */
- rval_status = PR_SetPollableEvent(tp->ioq.notify_fd);
- PR_ASSERT(PR_SUCCESS == rval_status);
+ /*
+ * wakeup the io thread(s)
+ */
+ rval_status = PR_SetPollableEvent(tp->ioq.notify_fd);
+ PR_ASSERT(PR_SUCCESS == rval_status);
}
/*
* cancel a job
*
- * XXXX: is this needed? likely to be removed
+ * XXXX: is this needed? likely to be removed
*/
PR_IMPLEMENT(PRStatus)
PR_CancelJob(PRJob *jobp) {
- PRStatus rval = PR_FAILURE;
- PRThreadPool *tp;
-
- if (jobp->on_timerq) {
- /*
- * now, check again while holding the timerq lock
- */
- tp = jobp->tpool;
- PR_Lock(tp->timerq.lock);
- if (jobp->on_timerq) {
- jobp->on_timerq = PR_FALSE;
- PR_REMOVE_AND_INIT_LINK(&jobp->links);
- tp->timerq.cnt--;
- PR_Unlock(tp->timerq.lock);
- if (!JOINABLE_JOB(jobp)) {
- delete_job(jobp);
- } else {
- JOIN_NOTIFY(jobp);
- }
- rval = PR_SUCCESS;
- } else
- PR_Unlock(tp->timerq.lock);
- } else if (jobp->on_ioq) {
- /*
- * now, check again while holding the ioq lock
- */
- tp = jobp->tpool;
- PR_Lock(tp->ioq.lock);
- if (jobp->on_ioq) {
- jobp->cancel_cv = PR_NewCondVar(tp->ioq.lock);
- if (NULL == jobp->cancel_cv) {
- PR_Unlock(tp->ioq.lock);
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
- return PR_FAILURE;
- }
- /*
- * mark job 'cancelled' and notify io thread(s)
- * XXXX:
- * this assumes there is only one io thread; when there
- * are multiple threads, the io thread processing this job
- * must be notified.
- */
- jobp->cancel_io = PR_TRUE;
- PR_Unlock(tp->ioq.lock); /* release, reacquire ioq lock */
- notify_ioq(tp);
- PR_Lock(tp->ioq.lock);
- while (jobp->cancel_io)
- PR_WaitCondVar(jobp->cancel_cv, PR_INTERVAL_NO_TIMEOUT);
- PR_Unlock(tp->ioq.lock);
- PR_ASSERT(!jobp->on_ioq);
- if (!JOINABLE_JOB(jobp)) {
- delete_job(jobp);
- } else {
- JOIN_NOTIFY(jobp);
- }
- rval = PR_SUCCESS;
- } else
- PR_Unlock(tp->ioq.lock);
- }
- if (PR_FAILURE == rval)
- PR_SetError(PR_INVALID_STATE_ERROR, 0);
- return rval;
+ PRStatus rval = PR_FAILURE;
+ PRThreadPool *tp;
+
+ if (jobp->on_timerq) {
+ /*
+ * now, check again while holding the timerq lock
+ */
+ tp = jobp->tpool;
+ PR_Lock(tp->timerq.lock);
+ if (jobp->on_timerq) {
+ jobp->on_timerq = PR_FALSE;
+ PR_REMOVE_AND_INIT_LINK(&jobp->links);
+ tp->timerq.cnt--;
+ PR_Unlock(tp->timerq.lock);
+ if (!JOINABLE_JOB(jobp)) {
+ delete_job(jobp);
+ } else {
+ JOIN_NOTIFY(jobp);
+ }
+ rval = PR_SUCCESS;
+ } else {
+ PR_Unlock(tp->timerq.lock);
+ }
+ } else if (jobp->on_ioq) {
+ /*
+ * now, check again while holding the ioq lock
+ */
+ tp = jobp->tpool;
+ PR_Lock(tp->ioq.lock);
+ if (jobp->on_ioq) {
+ jobp->cancel_cv = PR_NewCondVar(tp->ioq.lock);
+ if (NULL == jobp->cancel_cv) {
+ PR_Unlock(tp->ioq.lock);
+ PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
+ return PR_FAILURE;
+ }
+ /*
+ * mark job 'cancelled' and notify io thread(s)
+ * XXXX:
+ * this assumes there is only one io thread; when there
+ * are multiple threads, the io thread processing this job
+ * must be notified.
+ */
+ jobp->cancel_io = PR_TRUE;
+ PR_Unlock(tp->ioq.lock); /* release, reacquire ioq lock */
+ notify_ioq(tp);
+ PR_Lock(tp->ioq.lock);
+ while (jobp->cancel_io) {
+ PR_WaitCondVar(jobp->cancel_cv, PR_INTERVAL_NO_TIMEOUT);
+ }
+ PR_Unlock(tp->ioq.lock);
+ PR_ASSERT(!jobp->on_ioq);
+ if (!JOINABLE_JOB(jobp)) {
+ delete_job(jobp);
+ } else {
+ JOIN_NOTIFY(jobp);
+ }
+ rval = PR_SUCCESS;
+ } else {
+ PR_Unlock(tp->ioq.lock);
+ }
+ }
+ if (PR_FAILURE == rval) {
+ PR_SetError(PR_INVALID_STATE_ERROR, 0);
+ }
+ return rval;
}
/* join a job, wait until completion */
PR_IMPLEMENT(PRStatus)
PR_JoinJob(PRJob *jobp)
{
- if (!JOINABLE_JOB(jobp)) {
- PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
- return PR_FAILURE;
- }
- PR_Lock(jobp->tpool->join_lock);
- while(jobp->join_wait)
- PR_WaitCondVar(jobp->join_cv, PR_INTERVAL_NO_TIMEOUT);
- PR_Unlock(jobp->tpool->join_lock);
- delete_job(jobp);
- return PR_SUCCESS;
+ if (!JOINABLE_JOB(jobp)) {
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+ return PR_FAILURE;
+ }
+ PR_Lock(jobp->tpool->join_lock);
+ while(jobp->join_wait) {
+ PR_WaitCondVar(jobp->join_cv, PR_INTERVAL_NO_TIMEOUT);
+ }
+ PR_Unlock(jobp->tpool->join_lock);
+ delete_job(jobp);
+ return PR_SUCCESS;
}
/* shutdown threadpool */
PR_IMPLEMENT(PRStatus)
PR_ShutdownThreadPool(PRThreadPool *tpool)
{
-PRStatus rval = PR_SUCCESS;
+ PRStatus rval = PR_SUCCESS;
- PR_Lock(tpool->jobq.lock);
- tpool->shutdown = PR_TRUE;
- PR_NotifyAllCondVar(tpool->shutdown_cv);
- PR_Unlock(tpool->jobq.lock);
+ PR_Lock(tpool->jobq.lock);
+ tpool->shutdown = PR_TRUE;
+ PR_NotifyAllCondVar(tpool->shutdown_cv);
+ PR_Unlock(tpool->jobq.lock);
- return rval;
+ return rval;
}
/*
* join thread pool
- * wait for termination of worker threads
- * reclaim threadpool resources
+ * wait for termination of worker threads
+ * reclaim threadpool resources
*/
PR_IMPLEMENT(PRStatus)
PR_JoinThreadPool(PRThreadPool *tpool)
{
-PRStatus rval = PR_SUCCESS;
-PRCList *head;
-PRStatus rval_status;
+ PRStatus rval = PR_SUCCESS;
+ PRCList *head;
+ PRStatus rval_status;
- PR_Lock(tpool->jobq.lock);
- while (!tpool->shutdown)
- PR_WaitCondVar(tpool->shutdown_cv, PR_INTERVAL_NO_TIMEOUT);
+ PR_Lock(tpool->jobq.lock);
+ while (!tpool->shutdown) {
+ PR_WaitCondVar(tpool->shutdown_cv, PR_INTERVAL_NO_TIMEOUT);
+ }
- /*
- * wakeup worker threads
- */
+ /*
+ * wakeup worker threads
+ */
#ifdef OPT_WINNT
- /*
- * post shutdown notification for all threads
- */
- {
- int i;
- for(i=0; i < tpool->current_threads; i++) {
- PostQueuedCompletionStatus(tpool->jobq.nt_completion_port, 0,
- TRUE, NULL);
- }
- }
+ /*
+ * post shutdown notification for all threads
+ */
+ {
+ int i;
+ for(i=0; i < tpool->current_threads; i++) {
+ PostQueuedCompletionStatus(tpool->jobq.nt_completion_port, 0,
+ TRUE, NULL);
+ }
+ }
#else
- PR_NotifyAllCondVar(tpool->jobq.cv);
+ PR_NotifyAllCondVar(tpool->jobq.cv);
#endif
- /*
- * wakeup io thread(s)
- */
- notify_ioq(tpool);
-
- /*
- * wakeup timer thread(s)
- */
- PR_Lock(tpool->timerq.lock);
- notify_timerq(tpool);
- PR_Unlock(tpool->timerq.lock);
-
- while (!PR_CLIST_IS_EMPTY(&tpool->jobq.wthreads)) {
- wthread *wthrp;
-
- head = PR_LIST_HEAD(&tpool->jobq.wthreads);
- PR_REMOVE_AND_INIT_LINK(head);
- PR_Unlock(tpool->jobq.lock);
- wthrp = WTHREAD_LINKS_PTR(head);
- rval_status = PR_JoinThread(wthrp->thread);
- PR_ASSERT(PR_SUCCESS == rval_status);
- PR_DELETE(wthrp);
- PR_Lock(tpool->jobq.lock);
- }
- PR_Unlock(tpool->jobq.lock);
- while (!PR_CLIST_IS_EMPTY(&tpool->ioq.wthreads)) {
- wthread *wthrp;
-
- head = PR_LIST_HEAD(&tpool->ioq.wthreads);
- PR_REMOVE_AND_INIT_LINK(head);
- wthrp = WTHREAD_LINKS_PTR(head);
- rval_status = PR_JoinThread(wthrp->thread);
- PR_ASSERT(PR_SUCCESS == rval_status);
- PR_DELETE(wthrp);
- }
-
- while (!PR_CLIST_IS_EMPTY(&tpool->timerq.wthreads)) {
- wthread *wthrp;
-
- head = PR_LIST_HEAD(&tpool->timerq.wthreads);
- PR_REMOVE_AND_INIT_LINK(head);
- wthrp = WTHREAD_LINKS_PTR(head);
- rval_status = PR_JoinThread(wthrp->thread);
- PR_ASSERT(PR_SUCCESS == rval_status);
- PR_DELETE(wthrp);
- }
-
- /*
- * Delete queued jobs
- */
- while (!PR_CLIST_IS_EMPTY(&tpool->jobq.list)) {
- PRJob *jobp;
-
- head = PR_LIST_HEAD(&tpool->jobq.list);
- PR_REMOVE_AND_INIT_LINK(head);
- jobp = JOB_LINKS_PTR(head);
- tpool->jobq.cnt--;
- delete_job(jobp);
- }
-
- /* delete io jobs */
- while (!PR_CLIST_IS_EMPTY(&tpool->ioq.list)) {
- PRJob *jobp;
-
- head = PR_LIST_HEAD(&tpool->ioq.list);
- PR_REMOVE_AND_INIT_LINK(head);
- tpool->ioq.cnt--;
- jobp = JOB_LINKS_PTR(head);
- delete_job(jobp);
- }
-
- /* delete timer jobs */
- while (!PR_CLIST_IS_EMPTY(&tpool->timerq.list)) {
- PRJob *jobp;
-
- head = PR_LIST_HEAD(&tpool->timerq.list);
- PR_REMOVE_AND_INIT_LINK(head);
- tpool->timerq.cnt--;
- jobp = JOB_LINKS_PTR(head);
- delete_job(jobp);
- }
-
- PR_ASSERT(0 == tpool->jobq.cnt);
- PR_ASSERT(0 == tpool->ioq.cnt);
- PR_ASSERT(0 == tpool->timerq.cnt);
-
- delete_threadpool(tpool);
- return rval;
+ /*
+ * wakeup io thread(s)
+ */
+ notify_ioq(tpool);
+
+ /*
+ * wakeup timer thread(s)
+ */
+ PR_Lock(tpool->timerq.lock);
+ notify_timerq(tpool);
+ PR_Unlock(tpool->timerq.lock);
+
+ while (!PR_CLIST_IS_EMPTY(&tpool->jobq.wthreads)) {
+ wthread *wthrp;
+
+ head = PR_LIST_HEAD(&tpool->jobq.wthreads);
+ PR_REMOVE_AND_INIT_LINK(head);
+ PR_Unlock(tpool->jobq.lock);
+ wthrp = WTHREAD_LINKS_PTR(head);
+ rval_status = PR_JoinThread(wthrp->thread);
+ PR_ASSERT(PR_SUCCESS == rval_status);
+ PR_DELETE(wthrp);
+ PR_Lock(tpool->jobq.lock);
+ }
+ PR_Unlock(tpool->jobq.lock);
+ while (!PR_CLIST_IS_EMPTY(&tpool->ioq.wthreads)) {
+ wthread *wthrp;
+
+ head = PR_LIST_HEAD(&tpool->ioq.wthreads);
+ PR_REMOVE_AND_INIT_LINK(head);
+ wthrp = WTHREAD_LINKS_PTR(head);
+ rval_status = PR_JoinThread(wthrp->thread);
+ PR_ASSERT(PR_SUCCESS == rval_status);
+ PR_DELETE(wthrp);
+ }
+
+ while (!PR_CLIST_IS_EMPTY(&tpool->timerq.wthreads)) {
+ wthread *wthrp;
+
+ head = PR_LIST_HEAD(&tpool->timerq.wthreads);
+ PR_REMOVE_AND_INIT_LINK(head);
+ wthrp = WTHREAD_LINKS_PTR(head);
+ rval_status = PR_JoinThread(wthrp->thread);
+ PR_ASSERT(PR_SUCCESS == rval_status);
+ PR_DELETE(wthrp);
+ }
+
+ /*
+ * Delete queued jobs
+ */
+ while (!PR_CLIST_IS_EMPTY(&tpool->jobq.list)) {
+ PRJob *jobp;
+
+ head = PR_LIST_HEAD(&tpool->jobq.list);
+ PR_REMOVE_AND_INIT_LINK(head);
+ jobp = JOB_LINKS_PTR(head);
+ tpool->jobq.cnt--;
+ delete_job(jobp);
+ }
+
+ /* delete io jobs */
+ while (!PR_CLIST_IS_EMPTY(&tpool->ioq.list)) {
+ PRJob *jobp;
+
+ head = PR_LIST_HEAD(&tpool->ioq.list);
+ PR_REMOVE_AND_INIT_LINK(head);
+ tpool->ioq.cnt--;
+ jobp = JOB_LINKS_PTR(head);
+ delete_job(jobp);
+ }
+
+ /* delete timer jobs */
+ while (!PR_CLIST_IS_EMPTY(&tpool->timerq.list)) {
+ PRJob *jobp;
+
+ head = PR_LIST_HEAD(&tpool->timerq.list);
+ PR_REMOVE_AND_INIT_LINK(head);
+ tpool->timerq.cnt--;
+ jobp = JOB_LINKS_PTR(head);
+ delete_job(jobp);
+ }
+
+ PR_ASSERT(0 == tpool->jobq.cnt);
+ PR_ASSERT(0 == tpool->ioq.cnt);
+ PR_ASSERT(0 == tpool->timerq.cnt);
+
+ delete_threadpool(tpool);
+ return rval;
}
diff --git a/nsprpub/pr/src/misc/prtrace.c b/nsprpub/pr/src/misc/prtrace.c
index 058f700b5..ef6b65104 100644
--- a/nsprpub/pr/src/misc/prtrace.c
+++ b/nsprpub/pr/src/misc/prtrace.c
@@ -85,18 +85,18 @@ static PRCondVar *logCVar; /* Sync Condidtion Variable */
** Inter-thread state communication.
** Controling thread writes to logOrder under protection of logCVar
** the logging thread reads logOrder and sets logState on Notify.
-**
+**
** logSegments, logCount, logLostData must be read and written under
** protection of logLock, logCVar.
-**
+**
*/
static enum LogState
{
LogNotRunning, /* Initial state */
LogReset, /* Causes logger to re-calc controls */
LogActive, /* Logging in progress, set only by log thread */
- LogSuspend, /* Suspend Logging */
- LogResume, /* Resume Logging => LogActive */
+ LogSuspend, /* Suspend Logging */
+ LogResume, /* Resume Logging => LogActive */
LogStop /* Stop the log thread */
} logOrder, logState, localState; /* controlling state variables */
static PRInt32 logSegments; /* Number of buffer segments */
@@ -129,21 +129,21 @@ static void NewTraceBuffer( PRInt32 size )
logSegSize = logEntriesPerSegment * sizeof(PRTraceEntry);
PR_ASSERT( bufSize != 0);
PR_LOG( lm, PR_LOG_ERROR,
- ("NewTraceBuffer: logSegments: %ld, logEntries: %ld, logEntriesPerSegment: %ld, logSegSize: %ld",
- logSegments, logEntries, logEntriesPerSegment, logSegSize ));
+ ("NewTraceBuffer: logSegments: %ld, logEntries: %ld, logEntriesPerSegment: %ld, logSegSize: %ld",
+ logSegments, logEntries, logEntriesPerSegment, logSegSize ));
tBuf = PR_Malloc( bufSize );
if ( tBuf == NULL )
{
PR_LOG( lm, PR_LOG_ERROR,
- ("PRTrace: Failed to get trace buffer"));
+ ("PRTrace: Failed to get trace buffer"));
PR_ASSERT( 0 );
- }
+ }
else
{
PR_LOG( lm, PR_LOG_NOTICE,
- ("PRTrace: Got trace buffer of size: %ld, at %p", bufSize, tBuf));
+ ("PRTrace: Got trace buffer of size: %ld, at %p", bufSize, tBuf));
}
next = 0;
@@ -166,7 +166,7 @@ static void _PR_InitializeTrace( void )
PR_ASSERT( traceLock != NULL );
PR_Lock( traceLock );
-
+
PR_INIT_CLIST( &qNameList );
lm = PR_NewLogModule("trace");
@@ -179,17 +179,17 @@ static void _PR_InitializeTrace( void )
logCVar = PR_NewCondVar( logLock );
PR_Unlock( traceLock );
- return;
+ return;
} /* end _PR_InitializeTrace() */
/*
** Create a Trace Handle
*/
PR_IMPLEMENT(PRTraceHandle)
- PR_CreateTrace(
- const char *qName, /* QName for this trace handle */
- const char *rName, /* RName for this trace handle */
- const char *description /* description for this trace handle */
+PR_CreateTrace(
+ const char *qName, /* QName for this trace handle */
+ const char *rName, /* RName for this trace handle */
+ const char *description /* description for this trace handle */
)
{
QName *qnp;
@@ -197,8 +197,9 @@ PR_IMPLEMENT(PRTraceHandle)
PRBool matchQname = PR_FALSE;
/* Self initialize, if necessary */
- if ( traceLock == NULL )
+ if ( traceLock == NULL ) {
_PR_InitializeTrace();
+ }
/* Validate input arguments */
PR_ASSERT( strlen(qName) <= PRTRACE_NAME_MAX );
@@ -234,10 +235,10 @@ PR_IMPLEMENT(PRTraceHandle)
{
qnp = PR_NEWZAP( QName );
PR_ASSERT( qnp != NULL );
- PR_INIT_CLIST( &qnp->link );
- PR_INIT_CLIST( &qnp->rNameList );
+ PR_INIT_CLIST( &qnp->link );
+ PR_INIT_CLIST( &qnp->rNameList );
strcpy( qnp->name, qName );
- PR_APPEND_LINK( &qnp->link, &qNameList );
+ PR_APPEND_LINK( &qnp->link, &qNameList );
}
/* Do we already have a matching RName? */
@@ -267,13 +268,13 @@ PR_IMPLEMENT(PRTraceHandle)
PR_ASSERT(0);
}
- PR_APPEND_LINK( &rnp->link, &qnp->rNameList ); /* add RName to QName's rnList */
+ PR_APPEND_LINK( &rnp->link, &qnp->rNameList ); /* add RName to QName's rnList */
rnp->qName = qnp; /* point the RName to the QName */
/* Unlock the Facility */
PR_Unlock( traceLock );
PR_LOG( lm, PR_LOG_DEBUG, ("PRTrace: Create: QName: %s %p, RName: %s %p\n\t",
- qName, qnp, rName, rnp ));
+ qName, qnp, rName, rnp ));
return((PRTraceHandle)rnp);
} /* end PR_CreateTrace() */
@@ -281,16 +282,16 @@ PR_IMPLEMENT(PRTraceHandle)
/*
**
*/
-PR_IMPLEMENT(void)
- PR_DestroyTrace(
- PRTraceHandle handle /* Handle to be destroyed */
+PR_IMPLEMENT(void)
+PR_DestroyTrace(
+ PRTraceHandle handle /* Handle to be destroyed */
)
{
RName *rnp = (RName *)handle;
QName *qnp = rnp->qName;
- PR_LOG( lm, PR_LOG_DEBUG, ("PRTrace: Deleting: QName: %s, RName: %s",
- qnp->name, rnp->name));
+ PR_LOG( lm, PR_LOG_DEBUG, ("PRTrace: Deleting: QName: %s, RName: %s",
+ qnp->name, rnp->name));
/* Lock the Facility */
PR_Lock( traceLock );
@@ -299,8 +300,8 @@ PR_IMPLEMENT(void)
** Remove RName from the list of RNames in QName
** and free RName
*/
- PR_LOG( lm, PR_LOG_DEBUG, ("PRTrace: Deleting RName: %s, %p",
- rnp->name, rnp));
+ PR_LOG( lm, PR_LOG_DEBUG, ("PRTrace: Deleting RName: %s, %p",
+ rnp->name, rnp));
PR_REMOVE_LINK( &rnp->link );
PR_Free( rnp->lock );
PR_DELETE( rnp );
@@ -311,11 +312,11 @@ PR_IMPLEMENT(void)
*/
if ( PR_CLIST_IS_EMPTY( &qnp->rNameList ) )
{
- PR_LOG( lm, PR_LOG_DEBUG, ("PRTrace: Deleting unused QName: %s, %p",
- qnp->name, qnp));
+ PR_LOG( lm, PR_LOG_DEBUG, ("PRTrace: Deleting unused QName: %s, %p",
+ qnp->name, qnp));
PR_REMOVE_LINK( &qnp->link );
PR_DELETE( qnp );
- }
+ }
/* Unlock the Facility */
PR_Unlock( traceLock );
@@ -325,39 +326,42 @@ PR_IMPLEMENT(void)
/*
** Create a TraceEntry in the trace buffer
*/
-PR_IMPLEMENT(void)
- PR_Trace(
- PRTraceHandle handle, /* use this trace handle */
- PRUint32 userData0, /* User supplied data word 0 */
- PRUint32 userData1, /* User supplied data word 1 */
- PRUint32 userData2, /* User supplied data word 2 */
- PRUint32 userData3, /* User supplied data word 3 */
- PRUint32 userData4, /* User supplied data word 4 */
- PRUint32 userData5, /* User supplied data word 5 */
- PRUint32 userData6, /* User supplied data word 6 */
- PRUint32 userData7 /* User supplied data word 7 */
+PR_IMPLEMENT(void)
+PR_Trace(
+ PRTraceHandle handle, /* use this trace handle */
+ PRUint32 userData0, /* User supplied data word 0 */
+ PRUint32 userData1, /* User supplied data word 1 */
+ PRUint32 userData2, /* User supplied data word 2 */
+ PRUint32 userData3, /* User supplied data word 3 */
+ PRUint32 userData4, /* User supplied data word 4 */
+ PRUint32 userData5, /* User supplied data word 5 */
+ PRUint32 userData6, /* User supplied data word 6 */
+ PRUint32 userData7 /* User supplied data word 7 */
)
{
PRTraceEntry *tep;
PRInt32 mark;
- if ( (traceState == Suspended )
- || ( ((RName *)handle)->state == Suspended ))
+ if ( (traceState == Suspended )
+ || ( ((RName *)handle)->state == Suspended )) {
return;
+ }
/*
** Get the next trace entry slot w/ minimum delay
*/
PR_Lock( traceLock );
- tep = &tBuf[next++];
- if ( next > last )
+ tep = &tBuf[next++];
+ if ( next > last ) {
next = 0;
- if ( fetchLostData == PR_FALSE && next == fetchLastSeen )
+ }
+ if ( fetchLostData == PR_FALSE && next == fetchLastSeen ) {
fetchLostData = PR_TRUE;
-
+ }
+
mark = next;
-
+
PR_Unlock( traceLock );
/*
@@ -400,10 +404,10 @@ PR_IMPLEMENT(void)
/*
**
*/
-PR_IMPLEMENT(void)
- PR_SetTraceOption(
- PRTraceOption command, /* One of the enumerated values */
- void *value /* command value or NULL */
+PR_IMPLEMENT(void)
+PR_SetTraceOption(
+ PRTraceOption command, /* One of the enumerated values */
+ void *value /* command value or NULL */
)
{
RName * rnp;
@@ -417,79 +421,80 @@ PR_IMPLEMENT(void)
NewTraceBuffer( bufSize );
PR_Unlock( traceLock );
PR_LOG( lm, PR_LOG_DEBUG,
- ("PRSetTraceOption: PRTraceBufSize: %ld", bufSize));
+ ("PRSetTraceOption: PRTraceBufSize: %ld", bufSize));
break;
-
+
case PRTraceEnable :
rnp = *(RName **)value;
rnp->state = Running;
PR_LOG( lm, PR_LOG_DEBUG,
- ("PRSetTraceOption: PRTraceEnable: %p", rnp));
+ ("PRSetTraceOption: PRTraceEnable: %p", rnp));
break;
-
+
case PRTraceDisable :
rnp = *(RName **)value;
rnp->state = Suspended;
PR_LOG( lm, PR_LOG_DEBUG,
- ("PRSetTraceOption: PRTraceDisable: %p", rnp));
+ ("PRSetTraceOption: PRTraceDisable: %p", rnp));
break;
-
+
case PRTraceSuspend :
traceState = Suspended;
PR_LOG( lm, PR_LOG_DEBUG,
- ("PRSetTraceOption: PRTraceSuspend"));
+ ("PRSetTraceOption: PRTraceSuspend"));
break;
-
+
case PRTraceResume :
traceState = Running;
PR_LOG( lm, PR_LOG_DEBUG,
- ("PRSetTraceOption: PRTraceResume"));
+ ("PRSetTraceOption: PRTraceResume"));
break;
-
+
case PRTraceSuspendRecording :
PR_Lock( logLock );
logOrder = LogSuspend;
PR_NotifyCondVar( logCVar );
PR_Unlock( logLock );
PR_LOG( lm, PR_LOG_DEBUG,
- ("PRSetTraceOption: PRTraceSuspendRecording"));
+ ("PRSetTraceOption: PRTraceSuspendRecording"));
break;
-
+
case PRTraceResumeRecording :
PR_LOG( lm, PR_LOG_DEBUG,
- ("PRSetTraceOption: PRTraceResumeRecording"));
- if ( logState != LogSuspend )
+ ("PRSetTraceOption: PRTraceResumeRecording"));
+ if ( logState != LogSuspend ) {
break;
+ }
PR_Lock( logLock );
logOrder = LogResume;
PR_NotifyCondVar( logCVar );
PR_Unlock( logLock );
break;
-
+
case PRTraceStopRecording :
PR_Lock( logLock );
logOrder = LogStop;
PR_NotifyCondVar( logCVar );
PR_Unlock( logLock );
PR_LOG( lm, PR_LOG_DEBUG,
- ("PRSetTraceOption: PRTraceStopRecording"));
+ ("PRSetTraceOption: PRTraceStopRecording"));
break;
case PRTraceLockHandles :
PR_LOG( lm, PR_LOG_DEBUG,
- ("PRSetTraceOption: PRTraceLockTraceHandles"));
+ ("PRSetTraceOption: PRTraceLockTraceHandles"));
PR_Lock( traceLock );
break;
-
+
case PRTraceUnLockHandles :
PR_LOG( lm, PR_LOG_DEBUG,
- ("PRSetTraceOption: PRTraceUnLockHandles"));
+ ("PRSetTraceOption: PRTraceUnLockHandles"));
PR_Unlock( traceLock );
break;
default:
PR_LOG( lm, PR_LOG_ERROR,
- ("PRSetTraceOption: Invalid command %ld", command ));
+ ("PRSetTraceOption: Invalid command %ld", command ));
PR_ASSERT( 0 );
break;
} /* end switch() */
@@ -499,10 +504,10 @@ PR_IMPLEMENT(void)
/*
**
*/
-PR_IMPLEMENT(void)
- PR_GetTraceOption(
- PRTraceOption command, /* One of the enumerated values */
- void *value /* command value or NULL */
+PR_IMPLEMENT(void)
+PR_GetTraceOption(
+ PRTraceOption command, /* One of the enumerated values */
+ void *value /* command value or NULL */
)
{
switch ( command )
@@ -510,12 +515,12 @@ PR_IMPLEMENT(void)
case PRTraceBufSize :
*((PRInt32 *)value) = bufSize;
PR_LOG( lm, PR_LOG_DEBUG,
- ("PRGetTraceOption: PRTraceBufSize: %ld", bufSize ));
+ ("PRGetTraceOption: PRTraceBufSize: %ld", bufSize ));
break;
-
+
default:
PR_LOG( lm, PR_LOG_ERROR,
- ("PRGetTraceOption: Invalid command %ld", command ));
+ ("PRGetTraceOption: Invalid command %ld", command ));
PR_ASSERT( 0 );
break;
} /* end switch() */
@@ -525,10 +530,10 @@ PR_IMPLEMENT(void)
/*
**
*/
-PR_IMPLEMENT(PRTraceHandle)
- PR_GetTraceHandleFromName(
- const char *qName, /* QName search argument */
- const char *rName /* RName search argument */
+PR_IMPLEMENT(PRTraceHandle)
+PR_GetTraceHandleFromName(
+ const char *qName, /* QName search argument */
+ const char *rName /* RName search argument */
)
{
const char *qn, *rn, *desc;
@@ -536,7 +541,7 @@ PR_IMPLEMENT(PRTraceHandle)
RName *rnp = NULL;
PR_LOG( lm, PR_LOG_DEBUG, ("PRTrace: GetTraceHandleFromName:\n\t"
- "QName: %s, RName: %s", qName, rName ));
+ "QName: %s, RName: %s", qName, rName ));
qh = PR_FindNextTraceQname( NULL );
while (qh != NULL)
@@ -546,7 +551,7 @@ PR_IMPLEMENT(PRTraceHandle)
{
PR_GetTraceNameFromHandle( rh, &qn, &rn, &desc );
if ( (strcmp( qName, qn ) == 0)
- && (strcmp( rName, rn ) == 0 ))
+ && (strcmp( rName, rn ) == 0 ))
{
rnp = (RName *)rh;
goto foundIt;
@@ -564,12 +569,12 @@ foundIt:
/*
**
*/
-PR_IMPLEMENT(void)
- PR_GetTraceNameFromHandle(
- PRTraceHandle handle, /* handle as search argument */
- const char **qName, /* pointer to associated QName */
- const char **rName, /* pointer to associated RName */
- const char **description /* pointer to associated description */
+PR_IMPLEMENT(void)
+PR_GetTraceNameFromHandle(
+ PRTraceHandle handle, /* handle as search argument */
+ const char **qName, /* pointer to associated QName */
+ const char **rName, /* pointer to associated RName */
+ const char **description /* pointer to associated description */
)
{
RName *rnp = (RName *)handle;
@@ -580,8 +585,8 @@ PR_IMPLEMENT(void)
*description = rnp->desc;
PR_LOG( lm, PR_LOG_DEBUG, ("PRTrace: GetConterNameFromHandle: "
- "QNp: %p, RNp: %p,\n\tQName: %s, RName: %s, Desc: %s",
- qnp, rnp, qnp->name, rnp->name, rnp->desc ));
+ "QNp: %p, RNp: %p,\n\tQName: %s, RName: %s, Desc: %s",
+ qnp, rnp, qnp->name, rnp->name, rnp->desc ));
return;
} /* end PR_GetTraceNameFromHandle() */
@@ -589,24 +594,28 @@ PR_IMPLEMENT(void)
/*
**
*/
-PR_IMPLEMENT(PRTraceHandle)
- PR_FindNextTraceQname(
- PRTraceHandle handle
+PR_IMPLEMENT(PRTraceHandle)
+PR_FindNextTraceQname(
+ PRTraceHandle handle
)
{
QName *qnp = (QName *)handle;
- if ( PR_CLIST_IS_EMPTY( &qNameList ))
- qnp = NULL;
- else if ( qnp == NULL )
+ if ( PR_CLIST_IS_EMPTY( &qNameList )) {
+ qnp = NULL;
+ }
+ else if ( qnp == NULL ) {
qnp = (QName *)PR_LIST_HEAD( &qNameList );
- else if ( PR_NEXT_LINK( &qnp->link ) == &qNameList )
+ }
+ else if ( PR_NEXT_LINK( &qnp->link ) == &qNameList ) {
qnp = NULL;
- else
+ }
+ else {
qnp = (QName *)PR_NEXT_LINK( &qnp->link );
+ }
- PR_LOG( lm, PR_LOG_DEBUG, ("PRTrace: FindNextQname: Handle: %p, Returns: %p",
- handle, qnp ));
+ PR_LOG( lm, PR_LOG_DEBUG, ("PRTrace: FindNextQname: Handle: %p, Returns: %p",
+ handle, qnp ));
return((PRTraceHandle)qnp);
} /* end PR_FindNextTraceQname() */
@@ -614,31 +623,35 @@ PR_IMPLEMENT(PRTraceHandle)
/*
**
*/
-PR_IMPLEMENT(PRTraceHandle)
- PR_FindNextTraceRname(
- PRTraceHandle rhandle,
- PRTraceHandle qhandle
+PR_IMPLEMENT(PRTraceHandle)
+PR_FindNextTraceRname(
+ PRTraceHandle rhandle,
+ PRTraceHandle qhandle
)
{
RName *rnp = (RName *)rhandle;
QName *qnp = (QName *)qhandle;
- if ( PR_CLIST_IS_EMPTY( &qnp->rNameList ))
+ if ( PR_CLIST_IS_EMPTY( &qnp->rNameList )) {
rnp = NULL;
- else if ( rnp == NULL )
+ }
+ else if ( rnp == NULL ) {
rnp = (RName *)PR_LIST_HEAD( &qnp->rNameList );
- else if ( PR_NEXT_LINK( &rnp->link ) == &qnp->rNameList )
+ }
+ else if ( PR_NEXT_LINK( &rnp->link ) == &qnp->rNameList ) {
rnp = NULL;
- else
+ }
+ else {
rnp = (RName *)PR_NEXT_LINK( &rnp->link );
+ }
- PR_LOG( lm, PR_LOG_DEBUG, ("PRTrace: FindNextRname: Rhandle: %p, QHandle: %p, Returns: %p",
- rhandle, qhandle, rnp ));
+ PR_LOG( lm, PR_LOG_DEBUG, ("PRTrace: FindNextRname: Rhandle: %p, QHandle: %p, Returns: %p",
+ rhandle, qhandle, rnp ));
return((PRTraceHandle)rnp);
} /* end PR_FindNextTraceRname() */
-
+
/*
**
*/
@@ -648,11 +661,12 @@ static PRFileDesc * InitializeRecording( void )
PRFileDesc *logFile;
/* Self initialize, if necessary */
- if ( traceLock == NULL )
+ if ( traceLock == NULL ) {
_PR_InitializeTrace();
+ }
PR_LOG( lm, PR_LOG_DEBUG,
- ("PR_RecordTraceEntries: begins"));
+ ("PR_RecordTraceEntries: begins"));
logLostData = 0; /* reset at entry */
logState = LogReset;
@@ -662,17 +676,17 @@ static PRFileDesc * InitializeRecording( void )
if ( logFileName == NULL )
{
PR_LOG( lm, PR_LOG_ERROR,
- ("RecordTraceEntries: Environment variable not defined. Exiting"));
+ ("RecordTraceEntries: Environment variable not defined. Exiting"));
return NULL;
}
-
+
/* Open the logfile */
logFile = PR_Open( logFileName, PR_WRONLY | PR_CREATE_FILE, 0666 );
if ( logFile == NULL )
{
PR_LOG( lm, PR_LOG_ERROR,
- ("RecordTraceEntries: Cannot open %s as trace log file. OS error: %ld",
- logFileName, PR_GetOSError()));
+ ("RecordTraceEntries: Cannot open %s as trace log file. OS error: %ld",
+ logFileName, PR_GetOSError()));
return NULL;
}
return logFile;
@@ -685,35 +699,35 @@ static void ProcessOrders( void )
{
switch ( logOrder )
{
- case LogReset :
- logOrder = logState = localState;
- PR_LOG( lm, PR_LOG_DEBUG,
- ("RecordTraceEntries: LogReset"));
- break;
+ case LogReset :
+ logOrder = logState = localState;
+ PR_LOG( lm, PR_LOG_DEBUG,
+ ("RecordTraceEntries: LogReset"));
+ break;
- case LogSuspend :
- localState = logOrder = logState = LogSuspend;
- PR_LOG( lm, PR_LOG_DEBUG,
- ("RecordTraceEntries: LogSuspend"));
- break;
+ case LogSuspend :
+ localState = logOrder = logState = LogSuspend;
+ PR_LOG( lm, PR_LOG_DEBUG,
+ ("RecordTraceEntries: LogSuspend"));
+ break;
- case LogResume :
- localState = logOrder = logState = LogActive;
- PR_LOG( lm, PR_LOG_DEBUG,
- ("RecordTraceEntries: LogResume"));
- break;
+ case LogResume :
+ localState = logOrder = logState = LogActive;
+ PR_LOG( lm, PR_LOG_DEBUG,
+ ("RecordTraceEntries: LogResume"));
+ break;
- case LogStop :
- logOrder = logState = LogStop;
- PR_LOG( lm, PR_LOG_DEBUG,
- ("RecordTraceEntries: LogStop"));
- break;
+ case LogStop :
+ logOrder = logState = LogStop;
+ PR_LOG( lm, PR_LOG_DEBUG,
+ ("RecordTraceEntries: LogStop"));
+ break;
- default :
- PR_LOG( lm, PR_LOG_ERROR,
- ("RecordTraceEntries: Invalid logOrder: %ld", logOrder ));
- PR_ASSERT( 0 );
- break;
+ default :
+ PR_LOG( lm, PR_LOG_ERROR,
+ ("RecordTraceEntries: Invalid logOrder: %ld", logOrder ));
+ PR_ASSERT( 0 );
+ break;
} /* end switch() */
return ;
} /* end ProcessOrders() */
@@ -727,17 +741,17 @@ static void WriteTraceSegment( PRFileDesc *logFile, void *buf, PRInt32 amount )
PR_LOG( lm, PR_LOG_ERROR,
- ("WriteTraceSegment: Buffer: %p, Amount: %ld", buf, amount));
- rc = PR_Write( logFile, buf , amount );
+ ("WriteTraceSegment: Buffer: %p, Amount: %ld", buf, amount));
+ rc = PR_Write( logFile, buf, amount );
if ( rc == -1 )
PR_LOG( lm, PR_LOG_ERROR,
- ("RecordTraceEntries: PR_Write() failed. Error: %ld", PR_GetError() ));
+ ("RecordTraceEntries: PR_Write() failed. Error: %ld", PR_GetError() ));
else if ( rc != amount )
PR_LOG( lm, PR_LOG_ERROR,
- ("RecordTraceEntries: PR_Write() Tried to write: %ld, Wrote: %ld", amount, rc));
- else
+ ("RecordTraceEntries: PR_Write() Tried to write: %ld, Wrote: %ld", amount, rc));
+ else
PR_LOG( lm, PR_LOG_DEBUG,
- ("RecordTraceEntries: PR_Write(): Buffer: %p, bytes: %ld", buf, amount));
+ ("RecordTraceEntries: PR_Write(): Buffer: %p, bytes: %ld", buf, amount));
return;
} /* end WriteTraceSegment() */
@@ -746,8 +760,8 @@ static void WriteTraceSegment( PRFileDesc *logFile, void *buf, PRInt32 amount )
**
*/
PR_IMPLEMENT(void)
- PR_RecordTraceEntries(
- void
+PR_RecordTraceEntries(
+ void
)
{
PRFileDesc *logFile;
@@ -760,7 +774,7 @@ PR_IMPLEMENT(void)
if ( logFile == NULL )
{
PR_LOG( lm, PR_LOG_DEBUG,
- ("PR_RecordTraceEntries: Failed to initialize"));
+ ("PR_RecordTraceEntries: Failed to initialize"));
return;
}
@@ -770,12 +784,14 @@ PR_IMPLEMENT(void)
PR_Lock( logLock );
- while ( (logCount == 0) && ( logOrder == logState ) )
+ while ( (logCount == 0) && ( logOrder == logState ) ) {
PR_WaitCondVar( logCVar, PR_INTERVAL_NO_TIMEOUT );
+ }
/* Handle state transitions */
- if ( logOrder != logState )
+ if ( logOrder != logState ) {
ProcessOrders();
+ }
/* recalculate local controls */
if ( logCount )
@@ -787,7 +803,7 @@ PR_IMPLEMENT(void)
logCount = (logCount % logSegments);
currentSegment = logCount;
PR_LOG( lm, PR_LOG_DEBUG,
- ("PR_RecordTraceEntries: LostData segments: %ld", logLostData));
+ ("PR_RecordTraceEntries: LostData segments: %ld", logLostData));
}
else
{
@@ -795,29 +811,32 @@ PR_IMPLEMENT(void)
}
buf = tBuf + ( logEntriesPerSegment * currentSegment );
- if (++currentSegment >= logSegments )
+ if (++currentSegment >= logSegments ) {
currentSegment = 0;
+ }
doWrite = PR_TRUE;
}
- else
+ else {
doWrite = PR_FALSE;
+ }
PR_Unlock( logLock );
if ( doWrite == PR_TRUE )
{
- if ( localState != LogSuspend )
+ if ( localState != LogSuspend ) {
WriteTraceSegment( logFile, buf, logSegSize );
+ }
else
PR_LOG( lm, PR_LOG_DEBUG,
- ("RecordTraceEntries: PR_Write(): is suspended" ));
+ ("RecordTraceEntries: PR_Write(): is suspended" ));
}
} /* end while(logState...) */
PR_Close( logFile );
PR_LOG( lm, PR_LOG_DEBUG,
- ("RecordTraceEntries: exiting"));
+ ("RecordTraceEntries: exiting"));
return;
} /* end PR_RecordTraceEntries() */
@@ -825,23 +844,23 @@ PR_IMPLEMENT(void)
**
*/
PR_IMPLEMENT(PRIntn)
- PR_GetTraceEntries(
- PRTraceEntry *buffer, /* where to write output */
- PRInt32 count, /* number to get */
- PRInt32 *found /* number you got */
+PR_GetTraceEntries(
+ PRTraceEntry *buffer, /* where to write output */
+ PRInt32 count, /* number to get */
+ PRInt32 *found /* number you got */
)
{
- PRInt32 rc;
+ PRInt32 rc;
PRInt32 copied = 0;
-
+
PR_Lock( traceLock );
-
+
/*
** Depending on where the LastSeen and Next indices are,
- ** copy the trace buffer in one or two pieces.
+ ** copy the trace buffer in one or two pieces.
*/
PR_LOG( lm, PR_LOG_ERROR,
- ("PR_GetTraceEntries: Next: %ld, LastSeen: %ld", next, fetchLastSeen));
+ ("PR_GetTraceEntries: Next: %ld, LastSeen: %ld", next, fetchLastSeen));
if ( fetchLastSeen <= next )
{
@@ -850,7 +869,7 @@ PR_IMPLEMENT(PRIntn)
*(buffer + copied++) = *(tBuf + fetchLastSeen++);
}
PR_LOG( lm, PR_LOG_ERROR,
- ("PR_GetTraceEntries: Copied: %ld, LastSeen: %ld", copied, fetchLastSeen));
+ ("PR_GetTraceEntries: Copied: %ld, LastSeen: %ld", copied, fetchLastSeen));
}
else /* copy in 2 parts */
{
@@ -861,14 +880,14 @@ PR_IMPLEMENT(PRIntn)
fetchLastSeen = 0;
PR_LOG( lm, PR_LOG_ERROR,
- ("PR_GetTraceEntries: Copied: %ld, LastSeen: %ld", copied, fetchLastSeen));
+ ("PR_GetTraceEntries: Copied: %ld, LastSeen: %ld", copied, fetchLastSeen));
while ( count-- > 0 && fetchLastSeen < next )
{
*(buffer + copied++) = *(tBuf + fetchLastSeen++);
}
PR_LOG( lm, PR_LOG_ERROR,
- ("PR_GetTraceEntries: Copied: %ld, LastSeen: %ld", copied, fetchLastSeen));
+ ("PR_GetTraceEntries: Copied: %ld, LastSeen: %ld", copied, fetchLastSeen));
}
*found = copied;
diff --git a/nsprpub/pr/src/prvrsion.c b/nsprpub/pr/src/prvrsion.c
index be43578ca..09dcc6659 100644
--- a/nsprpub/pr/src/prvrsion.c
+++ b/nsprpub/pr/src/prvrsion.c
@@ -54,7 +54,7 @@ PRVersionDescription VERSION_DESC_NAME =
/* filename */ _PRODUCTION, /* the produced library name */
/* description */ "Portable runtime", /* what we are */
/* security */ "N/A", /* not applicable here */
- /* copywrite */ "Copyright (c) 1998 Netscape Communications Corporation. All Rights Reserved",
+ /* copywrite */ "This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.",
/* comment */ "License information: http://www.mozilla.org/MPL/",
/* specialString */ ""
};
@@ -68,9 +68,9 @@ PRVersionDescription VERSION_DESC_NAME =
* must not end in a '$' to prevent rcs keyword substitution.
*/
static char rcsid[] = "$Header: NSPR " PR_VERSION _DEBUG_STRING
- " " _BUILD_STRING " $";
+ " " _BUILD_STRING " $";
static char sccsid[] = "@(#)NSPR " PR_VERSION _DEBUG_STRING
- " " _BUILD_STRING;
+ " " _BUILD_STRING;
#endif /* XP_UNIX */
@@ -84,7 +84,7 @@ PR_IMPLEMENT(const PRVersionDescription*) libVersionPoint(void)
/*
* Add dummy references to rcsid and sccsid to prevent them
* from being optimized away as unused variables.
- */
+ */
const char *dummy;
dummy = rcsid;
diff --git a/nsprpub/pr/src/pthreads/ptio.c b/nsprpub/pr/src/pthreads/ptio.c
index 1549a905f..3ad2d80a8 100644
--- a/nsprpub/pr/src/pthreads/ptio.c
+++ b/nsprpub/pr/src/pthreads/ptio.c
@@ -177,23 +177,23 @@ static PRBool _pr_ipv6_v6only_on_by_default;
#define _PRSelectFdSetArg_t int *
#elif defined(AIX4_1)
#define _PRSelectFdSetArg_t void *
-#elif defined(IRIX) || (defined(AIX) && !defined(AIX4_1)) \
- || defined(OSF1) || defined(SOLARIS) \
+#elif (defined(AIX) && !defined(AIX4_1)) \
+ || defined(SOLARIS) \
|| defined(HPUX10_30) || defined(HPUX11) \
|| defined(LINUX) || defined(__GNU__) || defined(__GLIBC__) \
|| defined(FREEBSD) || defined(NETBSD) || defined(OPENBSD) \
|| defined(BSDI) || defined(NTO) || defined(DARWIN) \
- || defined(UNIXWARE) || defined(RISCOS) || defined(SYMBIAN)
+ || defined(UNIXWARE) || defined(RISCOS)
#define _PRSelectFdSetArg_t fd_set *
#else
#error "Cannot determine architecture"
#endif
-#if defined(SOLARIS)
+#if defined(SOLARIS)
#ifndef PROTO_SDP
/* on solaris, SDP is a new type of protocol */
#define PROTO_SDP 257
-#endif
+#endif
#define _PR_HAVE_SDP
#elif defined(LINUX)
#ifndef AF_INET_SDP
@@ -218,9 +218,9 @@ static PRLock *_pr_rename_lock; /* For PR_Rename() */
PRBool IsValidNetAddr(const PRNetAddr *addr)
{
if ((addr != NULL)
- && (addr->raw.family != AF_UNIX)
- && (addr->raw.family != PR_AF_INET6)
- && (addr->raw.family != AF_INET)) {
+ && (addr->raw.family != AF_UNIX)
+ && (addr->raw.family != PR_AF_INET6)
+ && (addr->raw.family != AF_INET)) {
return PR_FALSE;
}
return PR_TRUE;
@@ -233,8 +233,8 @@ static PRBool IsValidNetAddrLen(const PRNetAddr *addr, PRInt32 addr_len)
* is not uniform, so we don't check it.
*/
if ((addr != NULL)
- && (addr->raw.family != AF_UNIX)
- && (PR_NETADDR_SIZE(addr) != addr_len)) {
+ && (addr->raw.family != AF_UNIX)
+ && (PR_NETADDR_SIZE(addr) != addr_len)) {
#if defined(LINUX) && __GLIBC__ == 2 && __GLIBC_MINOR__ == 1
/*
* In glibc 2.1, struct sockaddr_in6 is 24 bytes. In glibc 2.2
@@ -244,7 +244,7 @@ static PRBool IsValidNetAddrLen(const PRNetAddr *addr, PRInt32 addr_len)
* We need to allow that. (Bugzilla bug #77264)
*/
if ((PR_AF_INET6 == addr->raw.family)
- && (sizeof(addr->ipv6) == addr_len)) {
+ && (sizeof(addr->ipv6) == addr_len)) {
return PR_TRUE;
}
#endif
@@ -266,8 +266,8 @@ static PRBool IsValidNetAddrLen(const PRNetAddr *addr, PRInt32 addr_len)
#define PT_DEFAULT_POLL_MSEC 5000
#if defined(_PR_POLL_WITH_SELECT)
#define PT_DEFAULT_SELECT_SEC (PT_DEFAULT_POLL_MSEC/PR_MSEC_PER_SEC)
-#define PT_DEFAULT_SELECT_USEC \
- ((PT_DEFAULT_POLL_MSEC % PR_MSEC_PER_SEC) * PR_USEC_PER_MSEC)
+#define PT_DEFAULT_SELECT_USEC \
+ ((PT_DEFAULT_POLL_MSEC % PR_MSEC_PER_SEC) * PR_USEC_PER_MSEC)
#endif
/*
@@ -280,7 +280,7 @@ static PRBool IsValidNetAddrLen(const PRNetAddr *addr, PRInt32 addr_len)
#if defined(HAVE_SOCKLEN_T) \
|| (defined(__GLIBC__) && __GLIBC__ >= 2)
typedef socklen_t pt_SockLen;
-#elif (defined(AIX) && !defined(AIX4_1))
+#elif (defined(AIX) && !defined(AIX4_1))
typedef PRSize pt_SockLen;
#else
typedef PRIntn pt_SockLen;
@@ -299,8 +299,12 @@ struct pt_Continuation
{
/* The building of the continuation operation */
ContinuationFn function; /* what function to continue */
- union { PRIntn osfd; } arg1; /* #1 - the op's fd */
- union { void* buffer; } arg2; /* #2 - primary transfer buffer */
+ union {
+ PRIntn osfd;
+ } arg1; /* #1 - the op's fd */
+ union {
+ void* buffer;
+ } arg2; /* #2 - primary transfer buffer */
union {
PRSize amount; /* #3 - size of 'buffer', or */
pt_SockLen *addr_len; /* - length of address */
@@ -308,15 +312,19 @@ struct pt_Continuation
/*
* For sendfile()
*/
- struct file_spec {
- off_t offset; /* offset in file to send */
- size_t nbytes; /* length of file data to send */
- size_t st_size; /* file size */
- } file_spec;
+ struct file_spec {
+ off_t offset; /* offset in file to send */
+ size_t nbytes; /* length of file data to send */
+ size_t st_size; /* file size */
+ } file_spec;
#endif
} arg3;
- union { PRIntn flags; } arg4; /* #4 - read/write flags */
- union { PRNetAddr *addr; } arg5; /* #5 - send/recv address */
+ union {
+ PRIntn flags;
+ } arg4; /* #4 - read/write flags */
+ union {
+ PRNetAddr *addr;
+ } arg5; /* #5 - send/recv address */
#ifdef HPUX11
/*
@@ -325,7 +333,7 @@ struct pt_Continuation
int filedesc; /* descriptor of file to send */
int nbytes_to_send; /* size of header and file */
#endif /* HPUX11 */
-
+
#ifdef SOLARIS
/*
* For sendfilev()
@@ -341,7 +349,7 @@ struct pt_Continuation
off_t offset;
size_t count;
#endif /* LINUX */
-
+
PRIntervalTime timeout; /* client (relative) timeout */
PRInt16 event; /* flags for poll()'s events */
@@ -351,7 +359,10 @@ struct pt_Continuation
** These function can either return an int return code or a pointer to
** some object.
*/
- union { PRSize code; void *object; } result;
+ union {
+ PRSize code;
+ void *object;
+ } result;
PRIntn syserrno; /* in case it failed, why (errno) */
pr_ContuationStatus status; /* the status of the operation */
@@ -374,8 +385,10 @@ PR_IMPLEMENT(void) PT_FPrintStats(PRFileDesc *debug_out, const char *msg)
LL_SUB(elapsed, PR_Now(), stats.timeStarted);
LL_I2L(aMil, 1000000);
LL_DIV(elapsed, elapsed, aMil);
-
- if (NULL != msg) PR_fprintf(debug_out, "%s", msg);
+
+ if (NULL != msg) {
+ PR_fprintf(debug_out, "%s", msg);
+ }
PR_fprintf(
debug_out, "\tstarted: %s[%lld]\n", buffer, elapsed);
PR_fprintf(
@@ -403,7 +416,7 @@ PR_IMPLEMENT(void) PT_FPrintStats(PRFileDesc *debug_out, const char *msg)
#if defined(_PR_POLL_WITH_SELECT)
/*
- * OSF1 and HPUX report the POLLHUP event for a socket when the
+ * HPUX report the POLLHUP event for a socket when the
* shutdown(SHUT_WR) operation is called for the remote end, even though
* the socket is still writeable. Use select(), instead of poll(), to
* workaround this problem.
@@ -411,290 +424,319 @@ PR_IMPLEMENT(void) PT_FPrintStats(PRFileDesc *debug_out, const char *msg)
static void pt_poll_now_with_select(pt_Continuation *op)
{
PRInt32 msecs;
- fd_set rd, wr, *rdp, *wrp;
- struct timeval tv;
- PRIntervalTime epoch, now, elapsed, remaining;
- PRBool wait_for_remaining;
+ fd_set rd, wr, *rdp, *wrp;
+ struct timeval tv;
+ PRIntervalTime epoch, now, elapsed, remaining;
+ PRBool wait_for_remaining;
PRThread *self = PR_GetCurrentThread();
-
- PR_ASSERT(PR_INTERVAL_NO_WAIT != op->timeout);
- PR_ASSERT(op->arg1.osfd < FD_SETSIZE);
+
+ PR_ASSERT(PR_INTERVAL_NO_WAIT != op->timeout);
+ PR_ASSERT(op->arg1.osfd < FD_SETSIZE);
switch (op->timeout) {
case PR_INTERVAL_NO_TIMEOUT:
- tv.tv_sec = PT_DEFAULT_SELECT_SEC;
- tv.tv_usec = PT_DEFAULT_SELECT_USEC;
- do
- {
- PRIntn rv;
-
- if (op->event & POLLIN) {
- FD_ZERO(&rd);
- FD_SET(op->arg1.osfd, &rd);
- rdp = &rd;
- } else
- rdp = NULL;
- if (op->event & POLLOUT) {
- FD_ZERO(&wr);
- FD_SET(op->arg1.osfd, &wr);
- wrp = &wr;
- } else
- wrp = NULL;
-
- rv = select(op->arg1.osfd + 1, rdp, wrp, NULL, &tv);
-
- if (_PT_THREAD_INTERRUPTED(self))
- {
- self->state &= ~PT_THREAD_ABORTED;
- op->result.code = -1;
- op->syserrno = EINTR;
- op->status = pt_continuation_done;
- return;
- }
-
- if ((-1 == rv) && ((errno == EINTR) || (errno == EAGAIN)))
- continue; /* go around the loop again */
-
- if (rv > 0)
- {
- PRInt16 revents = 0;
-
- if ((op->event & POLLIN) && FD_ISSET(op->arg1.osfd, &rd))
- revents |= POLLIN;
- if ((op->event & POLLOUT) && FD_ISSET(op->arg1.osfd, &wr))
- revents |= POLLOUT;
-
- if (op->function(op, revents))
- op->status = pt_continuation_done;
- } else if (rv == -1) {
- op->result.code = -1;
- op->syserrno = errno;
- op->status = pt_continuation_done;
- }
- /* else, select timed out */
- } while (pt_continuation_done != op->status);
- break;
+ tv.tv_sec = PT_DEFAULT_SELECT_SEC;
+ tv.tv_usec = PT_DEFAULT_SELECT_USEC;
+ do
+ {
+ PRIntn rv;
+
+ if (op->event & POLLIN) {
+ FD_ZERO(&rd);
+ FD_SET(op->arg1.osfd, &rd);
+ rdp = &rd;
+ } else {
+ rdp = NULL;
+ }
+ if (op->event & POLLOUT) {
+ FD_ZERO(&wr);
+ FD_SET(op->arg1.osfd, &wr);
+ wrp = &wr;
+ } else {
+ wrp = NULL;
+ }
+
+ rv = select(op->arg1.osfd + 1, rdp, wrp, NULL, &tv);
+
+ if (_PT_THREAD_INTERRUPTED(self))
+ {
+ self->state &= ~PT_THREAD_ABORTED;
+ op->result.code = -1;
+ op->syserrno = EINTR;
+ op->status = pt_continuation_done;
+ return;
+ }
+
+ if ((-1 == rv) && ((errno == EINTR) || (errno == EAGAIN))) {
+ continue; /* go around the loop again */
+ }
+
+ if (rv > 0)
+ {
+ PRInt16 revents = 0;
+
+ if ((op->event & POLLIN) && FD_ISSET(op->arg1.osfd, &rd)) {
+ revents |= POLLIN;
+ }
+ if ((op->event & POLLOUT) && FD_ISSET(op->arg1.osfd, &wr)) {
+ revents |= POLLOUT;
+ }
+
+ if (op->function(op, revents)) {
+ op->status = pt_continuation_done;
+ }
+ } else if (rv == -1) {
+ op->result.code = -1;
+ op->syserrno = errno;
+ op->status = pt_continuation_done;
+ }
+ /* else, select timed out */
+ } while (pt_continuation_done != op->status);
+ break;
default:
now = epoch = PR_IntervalNow();
remaining = op->timeout;
- do
- {
- PRIntn rv;
-
- if (op->event & POLLIN) {
- FD_ZERO(&rd);
- FD_SET(op->arg1.osfd, &rd);
- rdp = &rd;
- } else
- rdp = NULL;
- if (op->event & POLLOUT) {
- FD_ZERO(&wr);
- FD_SET(op->arg1.osfd, &wr);
- wrp = &wr;
- } else
- wrp = NULL;
-
- wait_for_remaining = PR_TRUE;
- msecs = (PRInt32)PR_IntervalToMilliseconds(remaining);
- if (msecs > PT_DEFAULT_POLL_MSEC) {
- wait_for_remaining = PR_FALSE;
- msecs = PT_DEFAULT_POLL_MSEC;
- }
- tv.tv_sec = msecs/PR_MSEC_PER_SEC;
- tv.tv_usec = (msecs % PR_MSEC_PER_SEC) * PR_USEC_PER_MSEC;
- rv = select(op->arg1.osfd + 1, rdp, wrp, NULL, &tv);
-
- if (_PT_THREAD_INTERRUPTED(self))
- {
- self->state &= ~PT_THREAD_ABORTED;
- op->result.code = -1;
- op->syserrno = EINTR;
- op->status = pt_continuation_done;
- return;
- }
-
- if (rv > 0) {
- PRInt16 revents = 0;
-
- if ((op->event & POLLIN) && FD_ISSET(op->arg1.osfd, &rd))
- revents |= POLLIN;
- if ((op->event & POLLOUT) && FD_ISSET(op->arg1.osfd, &wr))
- revents |= POLLOUT;
-
- if (op->function(op, revents))
- op->status = pt_continuation_done;
-
- } else if ((rv == 0) ||
- ((errno == EINTR) || (errno == EAGAIN))) {
- if (rv == 0) { /* select timed out */
- if (wait_for_remaining)
- now += remaining;
- else
- now += PR_MillisecondsToInterval(msecs);
- } else
- now = PR_IntervalNow();
- elapsed = (PRIntervalTime) (now - epoch);
- if (elapsed >= op->timeout) {
- op->result.code = -1;
- op->syserrno = ETIMEDOUT;
- op->status = pt_continuation_done;
- } else
- remaining = op->timeout - elapsed;
- } else {
- op->result.code = -1;
- op->syserrno = errno;
- op->status = pt_continuation_done;
- }
- } while (pt_continuation_done != op->status);
+ do
+ {
+ PRIntn rv;
+
+ if (op->event & POLLIN) {
+ FD_ZERO(&rd);
+ FD_SET(op->arg1.osfd, &rd);
+ rdp = &rd;
+ } else {
+ rdp = NULL;
+ }
+ if (op->event & POLLOUT) {
+ FD_ZERO(&wr);
+ FD_SET(op->arg1.osfd, &wr);
+ wrp = &wr;
+ } else {
+ wrp = NULL;
+ }
+
+ wait_for_remaining = PR_TRUE;
+ msecs = (PRInt32)PR_IntervalToMilliseconds(remaining);
+ if (msecs > PT_DEFAULT_POLL_MSEC) {
+ wait_for_remaining = PR_FALSE;
+ msecs = PT_DEFAULT_POLL_MSEC;
+ }
+ tv.tv_sec = msecs/PR_MSEC_PER_SEC;
+ tv.tv_usec = (msecs % PR_MSEC_PER_SEC) * PR_USEC_PER_MSEC;
+ rv = select(op->arg1.osfd + 1, rdp, wrp, NULL, &tv);
+
+ if (_PT_THREAD_INTERRUPTED(self))
+ {
+ self->state &= ~PT_THREAD_ABORTED;
+ op->result.code = -1;
+ op->syserrno = EINTR;
+ op->status = pt_continuation_done;
+ return;
+ }
+
+ if (rv > 0) {
+ PRInt16 revents = 0;
+
+ if ((op->event & POLLIN) && FD_ISSET(op->arg1.osfd, &rd)) {
+ revents |= POLLIN;
+ }
+ if ((op->event & POLLOUT) && FD_ISSET(op->arg1.osfd, &wr)) {
+ revents |= POLLOUT;
+ }
+
+ if (op->function(op, revents)) {
+ op->status = pt_continuation_done;
+ }
+
+ } else if ((rv == 0) ||
+ ((errno == EINTR) || (errno == EAGAIN))) {
+ if (rv == 0) { /* select timed out */
+ if (wait_for_remaining) {
+ now += remaining;
+ }
+ else {
+ now += PR_MillisecondsToInterval(msecs);
+ }
+ } else {
+ now = PR_IntervalNow();
+ }
+ elapsed = (PRIntervalTime) (now - epoch);
+ if (elapsed >= op->timeout) {
+ op->result.code = -1;
+ op->syserrno = ETIMEDOUT;
+ op->status = pt_continuation_done;
+ } else {
+ remaining = op->timeout - elapsed;
+ }
+ } else {
+ op->result.code = -1;
+ op->syserrno = errno;
+ op->status = pt_continuation_done;
+ }
+ } while (pt_continuation_done != op->status);
break;
}
} /* pt_poll_now_with_select */
-#endif /* _PR_POLL_WITH_SELECT */
+#endif /* _PR_POLL_WITH_SELECT */
static void pt_poll_now(pt_Continuation *op)
{
PRInt32 msecs;
- PRIntervalTime epoch, now, elapsed, remaining;
- PRBool wait_for_remaining;
+ PRIntervalTime epoch, now, elapsed, remaining;
+ PRBool wait_for_remaining;
PRThread *self = PR_GetCurrentThread();
-
- PR_ASSERT(PR_INTERVAL_NO_WAIT != op->timeout);
+
+ PR_ASSERT(PR_INTERVAL_NO_WAIT != op->timeout);
#if defined (_PR_POLL_WITH_SELECT)
- /*
- * If the fd is small enough call the select-based poll operation
- */
- if (op->arg1.osfd < FD_SETSIZE) {
- pt_poll_now_with_select(op);
- return;
- }
+ /*
+ * If the fd is small enough call the select-based poll operation
+ */
+ if (op->arg1.osfd < FD_SETSIZE) {
+ pt_poll_now_with_select(op);
+ return;
+ }
#endif
switch (op->timeout) {
case PR_INTERVAL_NO_TIMEOUT:
- msecs = PT_DEFAULT_POLL_MSEC;
- do
- {
- PRIntn rv;
- struct pollfd tmp_pfd;
-
- tmp_pfd.revents = 0;
- tmp_pfd.fd = op->arg1.osfd;
- tmp_pfd.events = op->event;
-
- rv = poll(&tmp_pfd, 1, msecs);
-
- if (_PT_THREAD_INTERRUPTED(self))
- {
- self->state &= ~PT_THREAD_ABORTED;
- op->result.code = -1;
- op->syserrno = EINTR;
- op->status = pt_continuation_done;
- return;
- }
-
- if ((-1 == rv) && ((errno == EINTR) || (errno == EAGAIN)))
- continue; /* go around the loop again */
-
- if (rv > 0)
- {
- PRInt16 events = tmp_pfd.events;
- PRInt16 revents = tmp_pfd.revents;
-
- if ((revents & POLLNVAL) /* busted in all cases */
- || ((events & POLLOUT) && (revents & POLLHUP)))
- /* write op & hup */
- {
- op->result.code = -1;
- if (POLLNVAL & revents) op->syserrno = EBADF;
- else if (POLLHUP & revents) op->syserrno = EPIPE;
- op->status = pt_continuation_done;
- } else {
- if (op->function(op, revents))
- op->status = pt_continuation_done;
- }
- } else if (rv == -1) {
- op->result.code = -1;
- op->syserrno = errno;
- op->status = pt_continuation_done;
- }
- /* else, poll timed out */
- } while (pt_continuation_done != op->status);
- break;
+ msecs = PT_DEFAULT_POLL_MSEC;
+ do
+ {
+ PRIntn rv;
+ struct pollfd tmp_pfd;
+
+ tmp_pfd.revents = 0;
+ tmp_pfd.fd = op->arg1.osfd;
+ tmp_pfd.events = op->event;
+
+ rv = poll(&tmp_pfd, 1, msecs);
+
+ if (_PT_THREAD_INTERRUPTED(self))
+ {
+ self->state &= ~PT_THREAD_ABORTED;
+ op->result.code = -1;
+ op->syserrno = EINTR;
+ op->status = pt_continuation_done;
+ return;
+ }
+
+ if ((-1 == rv) && ((errno == EINTR) || (errno == EAGAIN))) {
+ continue; /* go around the loop again */
+ }
+
+ if (rv > 0)
+ {
+ PRInt16 events = tmp_pfd.events;
+ PRInt16 revents = tmp_pfd.revents;
+
+ if ((revents & POLLNVAL) /* busted in all cases */
+ || ((events & POLLOUT) && (revents & POLLHUP)))
+ /* write op & hup */
+ {
+ op->result.code = -1;
+ if (POLLNVAL & revents) {
+ op->syserrno = EBADF;
+ }
+ else if (POLLHUP & revents) {
+ op->syserrno = EPIPE;
+ }
+ op->status = pt_continuation_done;
+ } else {
+ if (op->function(op, revents)) {
+ op->status = pt_continuation_done;
+ }
+ }
+ } else if (rv == -1) {
+ op->result.code = -1;
+ op->syserrno = errno;
+ op->status = pt_continuation_done;
+ }
+ /* else, poll timed out */
+ } while (pt_continuation_done != op->status);
+ break;
default:
now = epoch = PR_IntervalNow();
remaining = op->timeout;
- do
- {
- PRIntn rv;
- struct pollfd tmp_pfd;
-
- tmp_pfd.revents = 0;
- tmp_pfd.fd = op->arg1.osfd;
- tmp_pfd.events = op->event;
-
- wait_for_remaining = PR_TRUE;
- msecs = (PRInt32)PR_IntervalToMilliseconds(remaining);
- if (msecs > PT_DEFAULT_POLL_MSEC)
- {
- wait_for_remaining = PR_FALSE;
- msecs = PT_DEFAULT_POLL_MSEC;
- }
- rv = poll(&tmp_pfd, 1, msecs);
-
- if (_PT_THREAD_INTERRUPTED(self))
- {
- self->state &= ~PT_THREAD_ABORTED;
- op->result.code = -1;
- op->syserrno = EINTR;
- op->status = pt_continuation_done;
- return;
- }
-
- if (rv > 0)
- {
- PRInt16 events = tmp_pfd.events;
- PRInt16 revents = tmp_pfd.revents;
-
- if ((revents & POLLNVAL) /* busted in all cases */
- || ((events & POLLOUT) && (revents & POLLHUP)))
- /* write op & hup */
- {
- op->result.code = -1;
- if (POLLNVAL & revents) op->syserrno = EBADF;
- else if (POLLHUP & revents) op->syserrno = EPIPE;
- op->status = pt_continuation_done;
- } else {
- if (op->function(op, revents))
- {
- op->status = pt_continuation_done;
- }
- }
- } else if ((rv == 0) ||
- ((errno == EINTR) || (errno == EAGAIN))) {
- if (rv == 0) /* poll timed out */
- {
- if (wait_for_remaining)
- now += remaining;
- else
- now += PR_MillisecondsToInterval(msecs);
- }
- else
- now = PR_IntervalNow();
- elapsed = (PRIntervalTime) (now - epoch);
- if (elapsed >= op->timeout) {
- op->result.code = -1;
- op->syserrno = ETIMEDOUT;
- op->status = pt_continuation_done;
- } else
- remaining = op->timeout - elapsed;
- } else {
- op->result.code = -1;
- op->syserrno = errno;
- op->status = pt_continuation_done;
- }
- } while (pt_continuation_done != op->status);
+ do
+ {
+ PRIntn rv;
+ struct pollfd tmp_pfd;
+
+ tmp_pfd.revents = 0;
+ tmp_pfd.fd = op->arg1.osfd;
+ tmp_pfd.events = op->event;
+
+ wait_for_remaining = PR_TRUE;
+ msecs = (PRInt32)PR_IntervalToMilliseconds(remaining);
+ if (msecs > PT_DEFAULT_POLL_MSEC)
+ {
+ wait_for_remaining = PR_FALSE;
+ msecs = PT_DEFAULT_POLL_MSEC;
+ }
+ rv = poll(&tmp_pfd, 1, msecs);
+
+ if (_PT_THREAD_INTERRUPTED(self))
+ {
+ self->state &= ~PT_THREAD_ABORTED;
+ op->result.code = -1;
+ op->syserrno = EINTR;
+ op->status = pt_continuation_done;
+ return;
+ }
+
+ if (rv > 0)
+ {
+ PRInt16 events = tmp_pfd.events;
+ PRInt16 revents = tmp_pfd.revents;
+
+ if ((revents & POLLNVAL) /* busted in all cases */
+ || ((events & POLLOUT) && (revents & POLLHUP)))
+ /* write op & hup */
+ {
+ op->result.code = -1;
+ if (POLLNVAL & revents) {
+ op->syserrno = EBADF;
+ }
+ else if (POLLHUP & revents) {
+ op->syserrno = EPIPE;
+ }
+ op->status = pt_continuation_done;
+ } else {
+ if (op->function(op, revents))
+ {
+ op->status = pt_continuation_done;
+ }
+ }
+ } else if ((rv == 0) ||
+ ((errno == EINTR) || (errno == EAGAIN))) {
+ if (rv == 0) /* poll timed out */
+ {
+ if (wait_for_remaining) {
+ now += remaining;
+ }
+ else {
+ now += PR_MillisecondsToInterval(msecs);
+ }
+ }
+ else {
+ now = PR_IntervalNow();
+ }
+ elapsed = (PRIntervalTime) (now - epoch);
+ if (elapsed >= op->timeout) {
+ op->result.code = -1;
+ op->syserrno = ETIMEDOUT;
+ op->status = pt_continuation_done;
+ } else {
+ remaining = op->timeout - elapsed;
+ }
+ } else {
+ op->result.code = -1;
+ op->syserrno = errno;
+ op->status = pt_continuation_done;
+ }
+ } while (pt_continuation_done != op->status);
break;
}
@@ -703,11 +745,11 @@ static void pt_poll_now(pt_Continuation *op)
static PRIntn pt_Continue(pt_Continuation *op)
{
op->status = pt_continuation_pending; /* set default value */
- /*
- * let each thread call poll directly
- */
- pt_poll_now(op);
- PR_ASSERT(pt_continuation_done == op->status);
+ /*
+ * let each thread call poll directly
+ */
+ pt_poll_now(op);
+ PR_ASSERT(pt_continuation_done == op->status);
return op->result.code;
} /* pt_Continue */
@@ -729,12 +771,13 @@ static PRBool pt_accept_cont(pt_Continuation *op, PRInt16 revents)
{
op->syserrno = 0;
op->result.code = accept(
- op->arg1.osfd, op->arg2.buffer, op->arg3.addr_len);
+ op->arg1.osfd, op->arg2.buffer, op->arg3.addr_len);
if (-1 == op->result.code)
{
op->syserrno = errno;
- if (EWOULDBLOCK == errno || EAGAIN == errno || ECONNABORTED == errno)
- return PR_FALSE; /* do nothing - this one ain't finished */
+ if (EWOULDBLOCK == errno || EAGAIN == errno || ECONNABORTED == errno) {
+ return PR_FALSE; /* do nothing - this one ain't finished */
+ }
}
return PR_TRUE;
} /* pt_accept_cont */
@@ -747,11 +790,11 @@ static PRBool pt_read_cont(pt_Continuation *op, PRInt16 revents)
* error we continue is EWOULDBLOCK|EAGAIN.
*/
op->result.code = read(
- op->arg1.osfd, op->arg2.buffer, op->arg3.amount);
+ op->arg1.osfd, op->arg2.buffer, op->arg3.amount);
op->syserrno = errno;
- return ((-1 == op->result.code) &&
+ return ((-1 == op->result.code) &&
(EWOULDBLOCK == op->syserrno || EAGAIN == op->syserrno)) ?
- PR_FALSE : PR_TRUE;
+ PR_FALSE : PR_TRUE;
} /* pt_read_cont */
static PRBool pt_recv_cont(pt_Continuation *op, PRInt16 revents)
@@ -764,18 +807,18 @@ static PRBool pt_recv_cont(pt_Continuation *op, PRInt16 revents)
#if defined(SOLARIS)
if (0 == op->arg4.flags)
op->result.code = read(
- op->arg1.osfd, op->arg2.buffer, op->arg3.amount);
+ op->arg1.osfd, op->arg2.buffer, op->arg3.amount);
else
op->result.code = recv(
- op->arg1.osfd, op->arg2.buffer, op->arg3.amount, op->arg4.flags);
+ op->arg1.osfd, op->arg2.buffer, op->arg3.amount, op->arg4.flags);
#else
op->result.code = recv(
- op->arg1.osfd, op->arg2.buffer, op->arg3.amount, op->arg4.flags);
+ op->arg1.osfd, op->arg2.buffer, op->arg3.amount, op->arg4.flags);
#endif
op->syserrno = errno;
- return ((-1 == op->result.code) &&
+ return ((-1 == op->result.code) &&
(EWOULDBLOCK == op->syserrno || EAGAIN == op->syserrno)) ?
- PR_FALSE : PR_TRUE;
+ PR_FALSE : PR_TRUE;
} /* pt_recv_cont */
static PRBool pt_send_cont(pt_Continuation *op, PRInt16 revents)
@@ -796,7 +839,7 @@ retry:
bytes = write(op->arg1.osfd, op->arg2.buffer, tmp_amount);
#else
bytes = send(
- op->arg1.osfd, op->arg2.buffer, op->arg3.amount, op->arg4.flags);
+ op->arg1.osfd, op->arg2.buffer, op->arg3.amount, op->arg4.flags);
#endif
op->syserrno = errno;
@@ -829,7 +872,9 @@ retry:
op->result.code = -1;
return PR_TRUE;
}
- else return PR_FALSE;
+ else {
+ return PR_FALSE;
+ }
} /* pt_send_cont */
static PRBool pt_write_cont(pt_Continuation *op, PRInt16 revents)
@@ -858,7 +903,9 @@ static PRBool pt_write_cont(pt_Continuation *op, PRInt16 revents)
op->result.code = -1;
return PR_TRUE;
}
- else return PR_FALSE;
+ else {
+ return PR_FALSE;
+ }
} /* pt_write_cont */
static PRBool pt_writev_cont(pt_Continuation *op, PRInt16 revents)
@@ -900,14 +947,16 @@ static PRBool pt_writev_cont(pt_Continuation *op, PRInt16 revents)
op->result.code = -1;
return PR_TRUE;
}
- else return PR_FALSE;
+ else {
+ return PR_FALSE;
+ }
} /* pt_writev_cont */
static PRBool pt_sendto_cont(pt_Continuation *op, PRInt16 revents)
{
PRIntn bytes = sendto(
- op->arg1.osfd, op->arg2.buffer, op->arg3.amount, op->arg4.flags,
- (struct sockaddr*)op->arg5.addr, PR_NETADDR_SIZE(op->arg5.addr));
+ op->arg1.osfd, op->arg2.buffer, op->arg3.amount, op->arg4.flags,
+ (struct sockaddr*)op->arg5.addr, PR_NETADDR_SIZE(op->arg5.addr));
op->syserrno = errno;
if (bytes >= 0) /* this is progress */
{
@@ -923,19 +972,21 @@ static PRBool pt_sendto_cont(pt_Continuation *op, PRInt16 revents)
op->result.code = -1;
return PR_TRUE;
}
- else return PR_FALSE;
+ else {
+ return PR_FALSE;
+ }
} /* pt_sendto_cont */
static PRBool pt_recvfrom_cont(pt_Continuation *op, PRInt16 revents)
{
pt_SockLen addr_len = sizeof(PRNetAddr);
op->result.code = recvfrom(
- op->arg1.osfd, op->arg2.buffer, op->arg3.amount,
- op->arg4.flags, (struct sockaddr*)op->arg5.addr, &addr_len);
+ op->arg1.osfd, op->arg2.buffer, op->arg3.amount,
+ op->arg4.flags, (struct sockaddr*)op->arg5.addr, &addr_len);
op->syserrno = errno;
- return ((-1 == op->result.code) &&
+ return ((-1 == op->result.code) &&
(EWOULDBLOCK == op->syserrno || EAGAIN == op->syserrno)) ?
- PR_FALSE : PR_TRUE;
+ PR_FALSE : PR_TRUE;
} /* pt_recvfrom_cont */
#ifdef AIX
@@ -943,29 +994,30 @@ static PRBool pt_aix_sendfile_cont(pt_Continuation *op, PRInt16 revents)
{
struct sf_parms *sf_struct = (struct sf_parms *) op->arg2.buffer;
ssize_t rv;
- unsigned long long saved_file_offset;
- long long saved_file_bytes;
+ unsigned long long saved_file_offset;
+ long long saved_file_bytes;
- saved_file_offset = sf_struct->file_offset;
- saved_file_bytes = sf_struct->file_bytes;
- sf_struct->bytes_sent = 0;
+ saved_file_offset = sf_struct->file_offset;
+ saved_file_bytes = sf_struct->file_bytes;
+ sf_struct->bytes_sent = 0;
- if ((sf_struct->file_bytes > 0) && (sf_struct->file_size > 0))
- PR_ASSERT((sf_struct->file_bytes + sf_struct->file_offset) <=
- sf_struct->file_size);
+ if ((sf_struct->file_bytes > 0) && (sf_struct->file_size > 0))
+ PR_ASSERT((sf_struct->file_bytes + sf_struct->file_offset) <=
+ sf_struct->file_size);
rv = AIX_SEND_FILE(&op->arg1.osfd, sf_struct, op->arg4.flags);
op->syserrno = errno;
if (rv != -1) {
op->result.code += sf_struct->bytes_sent;
- /*
- * A bug in AIX 4.3.2 prevents the 'file_bytes' field from
- * being updated. So, 'file_bytes' is maintained by NSPR to
- * avoid conflict when this bug is fixed in AIX, in the future.
- */
- if (saved_file_bytes != -1)
- saved_file_bytes -= (sf_struct->file_offset - saved_file_offset);
- sf_struct->file_bytes = saved_file_bytes;
+ /*
+ * A bug in AIX 4.3.2 prevents the 'file_bytes' field from
+ * being updated. So, 'file_bytes' is maintained by NSPR to
+ * avoid conflict when this bug is fixed in AIX, in the future.
+ */
+ if (saved_file_bytes != -1) {
+ saved_file_bytes -= (sf_struct->file_offset - saved_file_offset);
+ }
+ sf_struct->file_bytes = saved_file_bytes;
} else if (op->syserrno != EWOULDBLOCK && op->syserrno != EAGAIN) {
op->result.code = -1;
} else {
@@ -987,7 +1039,7 @@ static PRBool pt_hpux_sendfile_cont(pt_Continuation *op, PRInt16 revents)
int count;
count = sendfile(op->arg1.osfd, op->filedesc, op->arg3.file_spec.offset,
- op->arg3.file_spec.nbytes, hdtrl, op->arg4.flags);
+ op->arg3.file_spec.nbytes, hdtrl, op->arg4.flags);
PR_ASSERT(count <= op->nbytes_to_send);
op->syserrno = errno;
@@ -1000,13 +1052,13 @@ static PRBool pt_hpux_sendfile_cont(pt_Continuation *op, PRInt16 revents)
}
if (count != -1 && count < op->nbytes_to_send) {
if (count < hdtrl[0].iov_len) {
- /* header not sent */
+ /* header not sent */
hdtrl[0].iov_base = ((char *) hdtrl[0].iov_base) + count;
hdtrl[0].iov_len -= count;
} else if (count < (hdtrl[0].iov_len + op->arg3.file_spec.nbytes)) {
- /* header sent, file not sent */
+ /* header sent, file not sent */
PRUint32 file_nbytes_sent = count - hdtrl[0].iov_len;
hdtrl[0].iov_base = NULL;
@@ -1015,24 +1067,24 @@ static PRBool pt_hpux_sendfile_cont(pt_Continuation *op, PRInt16 revents)
op->arg3.file_spec.offset += file_nbytes_sent;
op->arg3.file_spec.nbytes -= file_nbytes_sent;
} else if (count < (hdtrl[0].iov_len + op->arg3.file_spec.nbytes +
- hdtrl[1].iov_len)) {
+ hdtrl[1].iov_len)) {
PRUint32 trailer_nbytes_sent = count - (hdtrl[0].iov_len +
- op->arg3.file_spec.nbytes);
+ op->arg3.file_spec.nbytes);
- /* header sent, file sent, trailer not sent */
+ /* header sent, file sent, trailer not sent */
hdtrl[0].iov_base = NULL;
hdtrl[0].iov_len = 0;
- /*
- * set file offset and len so that no more file data is
- * sent
- */
+ /*
+ * set file offset and len so that no more file data is
+ * sent
+ */
op->arg3.file_spec.offset = op->arg3.file_spec.st_size;
op->arg3.file_spec.nbytes = 0;
hdtrl[1].iov_base =((char *) hdtrl[1].iov_base)+ trailer_nbytes_sent;
hdtrl[1].iov_len -= trailer_nbytes_sent;
- }
+ }
op->nbytes_to_send -= count;
return PR_FALSE;
}
@@ -1041,7 +1093,7 @@ static PRBool pt_hpux_sendfile_cont(pt_Continuation *op, PRInt16 revents)
}
#endif /* HPUX11 */
-#ifdef SOLARIS
+#ifdef SOLARIS
static PRBool pt_solaris_sendfile_cont(pt_Continuation *op, PRInt16 revents)
{
struct sendfilevec *vec = (struct sendfilevec *) op->arg2.buffer;
@@ -1054,13 +1106,13 @@ static PRBool pt_solaris_sendfile_cont(pt_Continuation *op, PRInt16 revents)
if (count == -1) {
if (op->syserrno != EWOULDBLOCK && op->syserrno != EAGAIN
- && op->syserrno != EINTR) {
+ && op->syserrno != EINTR) {
op->result.code = -1;
return PR_TRUE;
}
count = xferred;
} else if (count == 0) {
- /*
+ /*
* We are now at EOF. The file was truncated. Solaris sendfile is
* supposed to return 0 and no error in this case, though some versions
* may return -1 and EINVAL .
@@ -1070,7 +1122,7 @@ static PRBool pt_solaris_sendfile_cont(pt_Continuation *op, PRInt16 revents)
return PR_TRUE;
}
PR_ASSERT(count <= op->nbytes_to_send);
-
+
op->result.code += count;
if (count < op->nbytes_to_send) {
op->nbytes_to_send -= count;
@@ -1094,7 +1146,7 @@ static PRBool pt_solaris_sendfile_cont(pt_Continuation *op, PRInt16 revents)
}
#endif /* SOLARIS */
-#ifdef LINUX
+#ifdef LINUX
static PRBool pt_linux_sendfile_cont(pt_Continuation *op, PRInt16 revents)
{
ssize_t rv;
@@ -1133,9 +1185,9 @@ void _PR_InitIO(void)
_pr_flock_cv = PR_NewCondVar(_pr_flock_lock);
PR_ASSERT(NULL != _pr_flock_cv);
_pr_rename_lock = PR_NewLock();
- PR_ASSERT(NULL != _pr_rename_lock);
+ PR_ASSERT(NULL != _pr_rename_lock);
- _PR_InitFdCache(); /* do that */
+ _PR_InitFdCache(); /* do that */
_pr_stdin = pt_SetMethods(0, PR_DESC_FILE, PR_FALSE, PR_TRUE);
_pr_stdout = pt_SetMethods(1, PR_DESC_FILE, PR_FALSE, PR_TRUE);
@@ -1155,7 +1207,7 @@ void _PR_InitIO(void)
int on;
socklen_t optlen = sizeof(on);
if (getsockopt(osfd, IPPROTO_IPV6, IPV6_V6ONLY,
- &on, &optlen) == 0) {
+ &on, &optlen) == 0) {
_pr_ipv6_v6only_on_by_default = on;
}
close(osfd);
@@ -1170,11 +1222,11 @@ void _PR_CleanupIO(void)
_pr_stdin = NULL;
_PR_Putfd(_pr_stdout);
_pr_stdout = NULL;
- _PR_Putfd(_pr_stderr);
+ _PR_Putfd(_pr_stderr);
_pr_stderr = NULL;
_PR_CleanupFdCache();
-
+
if (_pr_flock_cv)
{
PR_DestroyCondVar(_pr_flock_cv);
@@ -1197,8 +1249,10 @@ PR_IMPLEMENT(PRFileDesc*) PR_GetSpecialFD(PRSpecialFD osfd)
PRFileDesc *result = NULL;
PR_ASSERT(osfd >= PR_StandardInput && osfd <= PR_StandardError);
- if (!_pr_initialized) _PR_ImplicitInitialization();
-
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
+
switch (osfd)
{
case PR_StandardInput: result = _pr_stdin; break;
@@ -1243,37 +1297,21 @@ static PRStatus pt_Close(PRFileDesc *fd)
{
if ((NULL == fd) || (NULL == fd->secret)
|| ((_PR_FILEDESC_OPEN != fd->secret->state)
- && (_PR_FILEDESC_CLOSED != fd->secret->state)))
+ && (_PR_FILEDESC_CLOSED != fd->secret->state)))
{
PR_SetError(PR_BAD_DESCRIPTOR_ERROR, 0);
return PR_FAILURE;
}
- if (pt_TestAbort()) return PR_FAILURE;
+ if (pt_TestAbort()) {
+ return PR_FAILURE;
+ }
if (_PR_FILEDESC_OPEN == fd->secret->state)
{
if (-1 == close(fd->secret->md.osfd))
{
-#ifdef OSF1
- /*
- * Bug 86941: On Tru64 UNIX V5.0A and V5.1, the close()
- * system call, when called to close a TCP socket, may
- * return -1 with errno set to EINVAL but the system call
- * does close the socket successfully. An application
- * may safely ignore the EINVAL error. This bug is fixed
- * on Tru64 UNIX V5.1A and later. The defect tracking
- * number is QAR 81431.
- */
- if (PR_DESC_SOCKET_TCP != fd->methods->file_type
- || EINVAL != errno)
- {
- pt_MapError(_PR_MD_MAP_CLOSE_ERROR, errno);
- return PR_FAILURE;
- }
-#else
pt_MapError(_PR_MD_MAP_CLOSE_ERROR, errno);
return PR_FAILURE;
-#endif
}
fd->secret->state = _PR_FILEDESC_CLOSED;
}
@@ -1285,7 +1323,9 @@ static PRInt32 pt_Read(PRFileDesc *fd, void *buf, PRInt32 amount)
{
PRInt32 syserrno, bytes = -1;
- if (pt_TestAbort()) return bytes;
+ if (pt_TestAbort()) {
+ return bytes;
+ }
bytes = read(fd->secret->md.osfd, buf, amount);
syserrno = errno;
@@ -1303,8 +1343,9 @@ static PRInt32 pt_Read(PRFileDesc *fd, void *buf, PRInt32 amount)
bytes = pt_Continue(&op);
syserrno = op.syserrno;
}
- if (bytes < 0)
+ if (bytes < 0) {
pt_MapError(_PR_MD_MAP_READ_ERROR, syserrno);
+ }
return bytes;
} /* pt_Read */
@@ -1313,7 +1354,9 @@ static PRInt32 pt_Write(PRFileDesc *fd, const void *buf, PRInt32 amount)
PRInt32 syserrno, bytes = -1;
PRBool fNeedContinue = PR_FALSE;
- if (pt_TestAbort()) return bytes;
+ if (pt_TestAbort()) {
+ return bytes;
+ }
bytes = write(fd->secret->md.osfd, buf, amount);
syserrno = errno;
@@ -1325,7 +1368,7 @@ static PRInt32 pt_Write(PRFileDesc *fd, const void *buf, PRInt32 amount)
fNeedContinue = PR_TRUE;
}
if ( (bytes == -1) && (syserrno == EWOULDBLOCK || syserrno == EAGAIN)
- && (!fd->secret->nonblocking) )
+ && (!fd->secret->nonblocking) )
{
bytes = 0;
fNeedContinue = PR_TRUE;
@@ -1344,8 +1387,9 @@ static PRInt32 pt_Write(PRFileDesc *fd, const void *buf, PRInt32 amount)
bytes = pt_Continue(&op);
syserrno = op.syserrno;
}
- if (bytes == -1)
+ if (bytes == -1) {
pt_MapError(_PR_MD_MAP_WRITE_ERROR, syserrno);
+ }
return bytes;
} /* pt_Write */
@@ -1358,7 +1402,9 @@ static PRInt32 pt_Writev(
struct iovec osiov_local[PR_MAX_IOVECTOR_SIZE], *osiov;
int osiov_len;
- if (pt_TestAbort()) return rv;
+ if (pt_TestAbort()) {
+ return rv;
+ }
/* Ensured by PR_Writev */
PR_ASSERT(iov_len <= PR_MAX_IOVECTOR_SIZE);
@@ -1390,7 +1436,7 @@ static PRInt32 pt_Writev(
* we within that array? What are the parameters for
* resumption? Maybe we're done!
*/
- for ( ;osiov_len > 0; osiov++, osiov_len--)
+ for ( ; osiov_len > 0; osiov++, osiov_len--)
{
if (bytes < osiov->iov_len)
{
@@ -1409,12 +1455,16 @@ static PRInt32 pt_Writev(
rv = -1;
syserrno = ETIMEDOUT;
}
- else fNeedContinue = PR_TRUE;
+ else {
+ fNeedContinue = PR_TRUE;
+ }
}
}
else if (syserrno == EWOULDBLOCK || syserrno == EAGAIN)
{
- if (PR_INTERVAL_NO_WAIT == timeout) syserrno = ETIMEDOUT;
+ if (PR_INTERVAL_NO_WAIT == timeout) {
+ syserrno = ETIMEDOUT;
+ }
else
{
rv = 0;
@@ -1437,7 +1487,9 @@ static PRInt32 pt_Writev(
rv = pt_Continue(&op);
syserrno = op.syserrno;
}
- if (rv == -1) pt_MapError(_PR_MD_MAP_WRITEV_ERROR, syserrno);
+ if (rv == -1) {
+ pt_MapError(_PR_MD_MAP_WRITEV_ERROR, syserrno);
+ }
return rv;
} /* pt_Writev */
@@ -1457,8 +1509,9 @@ static PRInt32 pt_Available_f(PRFileDesc *fd)
cur = _PR_MD_LSEEK(fd, 0, PR_SEEK_CUR);
- if (cur >= 0)
+ if (cur >= 0) {
end = _PR_MD_LSEEK(fd, 0, PR_SEEK_END);
+ }
if ((cur < 0) || (end < 0)) {
return -1;
@@ -1478,10 +1531,13 @@ static PRInt64 pt_Available64_f(PRFileDesc *fd)
LL_I2L(minus_one, -1);
cur = _PR_MD_LSEEK64(fd, LL_ZERO, PR_SEEK_CUR);
- if (LL_GE_ZERO(cur))
+ if (LL_GE_ZERO(cur)) {
end = _PR_MD_LSEEK64(fd, LL_ZERO, PR_SEEK_END);
+ }
- if (!LL_GE_ZERO(cur) || !LL_GE_ZERO(end)) return minus_one;
+ if (!LL_GE_ZERO(cur) || !LL_GE_ZERO(end)) {
+ return minus_one;
+ }
LL_SUB(result, end, cur);
(void)_PR_MD_LSEEK64(fd, cur, PR_SEEK_SET);
@@ -1492,12 +1548,15 @@ static PRInt64 pt_Available64_f(PRFileDesc *fd)
static PRInt32 pt_Available_s(PRFileDesc *fd)
{
PRInt32 rv, bytes = -1;
- if (pt_TestAbort()) return bytes;
+ if (pt_TestAbort()) {
+ return bytes;
+ }
rv = ioctl(fd->secret->md.osfd, FIONREAD, &bytes);
- if (rv == -1)
+ if (rv == -1) {
pt_MapError(_PR_MD_MAP_SOCKETAVAILABLE_ERROR, errno);
+ }
return bytes;
} /* pt_Available_s */
@@ -1528,7 +1587,9 @@ static PRStatus pt_Synch(PRFileDesc *fd)
static PRStatus pt_Fsync(PRFileDesc *fd)
{
PRIntn rv = -1;
- if (pt_TestAbort()) return PR_FAILURE;
+ if (pt_TestAbort()) {
+ return PR_FAILURE;
+ }
rv = fsync(fd->secret->md.osfd);
if (rv < 0) {
@@ -1543,7 +1604,7 @@ static PRStatus pt_Connect(
{
PRIntn rv = -1, syserrno;
pt_SockLen addr_len;
- const PRNetAddr *addrp = addr;
+ const PRNetAddr *addrp = addr;
#if defined(_PR_HAVE_SOCKADDR_LEN) || defined(_PR_INET6)
PRNetAddr addrCopy;
#endif
@@ -1551,7 +1612,9 @@ static PRStatus pt_Connect(
PRUint16 md_af = addr->raw.family;
#endif
- if (pt_TestAbort()) return PR_FAILURE;
+ if (pt_TestAbort()) {
+ return PR_FAILURE;
+ }
PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
addr_len = PR_NETADDR_SIZE(addr);
@@ -1577,7 +1640,9 @@ static PRStatus pt_Connect(
syserrno = errno;
if ((-1 == rv) && (EINPROGRESS == syserrno) && (!fd->secret->nonblocking))
{
- if (PR_INTERVAL_NO_WAIT == timeout) syserrno = ETIMEDOUT;
+ if (PR_INTERVAL_NO_WAIT == timeout) {
+ syserrno = ETIMEDOUT;
+ }
else
{
pt_Continuation op;
@@ -1610,7 +1675,7 @@ static PRStatus pt_ConnectContinue(
return PR_FAILURE;
}
if ((out_flags & (PR_POLL_WRITE | PR_POLL_EXCEPT | PR_POLL_ERR
- | PR_POLL_HUP)) == 0)
+ | PR_POLL_HUP)) == 0)
{
PR_ASSERT(out_flags == 0);
PR_SetError(PR_IN_PROGRESS_ERROR, 0);
@@ -1647,17 +1712,10 @@ static PRFileDesc* pt_Accept(
PRFileDesc *newfd = NULL;
PRIntn syserrno, osfd = -1;
pt_SockLen addr_len = sizeof(PRNetAddr);
-#ifdef SYMBIAN
- PRNetAddr dummy_addr;
-#endif
- if (pt_TestAbort()) return newfd;
-
-#ifdef SYMBIAN
- /* On Symbian OS, accept crashes if addr is NULL. */
- if (!addr)
- addr = &dummy_addr;
-#endif
+ if (pt_TestAbort()) {
+ return newfd;
+ }
#ifdef _PR_STRICT_ADDR_LEN
if (addr)
@@ -1676,14 +1734,19 @@ static PRFileDesc* pt_Accept(
if (osfd == -1)
{
- if (fd->secret->nonblocking) goto failed;
+ if (fd->secret->nonblocking) {
+ goto failed;
+ }
if (EWOULDBLOCK != syserrno && EAGAIN != syserrno
- && ECONNABORTED != syserrno)
+ && ECONNABORTED != syserrno) {
goto failed;
+ }
else
{
- if (PR_INTERVAL_NO_WAIT == timeout) syserrno = ETIMEDOUT;
+ if (PR_INTERVAL_NO_WAIT == timeout) {
+ syserrno = ETIMEDOUT;
+ }
else
{
pt_Continuation op;
@@ -1696,7 +1759,9 @@ static PRFileDesc* pt_Accept(
osfd = pt_Continue(&op);
syserrno = op.syserrno;
}
- if (osfd < 0) goto failed;
+ if (osfd < 0) {
+ goto failed;
+ }
}
}
#ifdef _PR_HAVE_SOCKADDR_LEN
@@ -1707,11 +1772,14 @@ static PRFileDesc* pt_Accept(
}
#endif /* _PR_HAVE_SOCKADDR_LEN */
#ifdef _PR_INET6
- if (addr && (AF_INET6 == addr->raw.family))
+ if (addr && (AF_INET6 == addr->raw.family)) {
addr->raw.family = PR_AF_INET6;
+ }
#endif
newfd = pt_SetMethods(osfd, PR_DESC_SOCKET_TCP, PR_TRUE, PR_FALSE);
- if (newfd == NULL) close(osfd); /* $$$ whoops! this doesn't work $$$ */
+ if (newfd == NULL) {
+ close(osfd); /* $$$ whoops! this doesn't work $$$ */
+ }
else
{
PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
@@ -1736,7 +1804,7 @@ static PRStatus pt_Bind(PRFileDesc *fd, const PRNetAddr *addr)
{
PRIntn rv;
pt_SockLen addr_len;
- const PRNetAddr *addrp = addr;
+ const PRNetAddr *addrp = addr;
#if defined(_PR_HAVE_SOCKADDR_LEN) || defined(_PR_INET6)
PRNetAddr addrCopy;
#endif
@@ -1744,7 +1812,9 @@ static PRStatus pt_Bind(PRFileDesc *fd, const PRNetAddr *addr)
PRUint16 md_af = addr->raw.family;
#endif
- if (pt_TestAbort()) return PR_FAILURE;
+ if (pt_TestAbort()) {
+ return PR_FAILURE;
+ }
PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
if (addr->raw.family == AF_UNIX)
@@ -1755,7 +1825,7 @@ static PRStatus pt_Bind(PRFileDesc *fd, const PRNetAddr *addr)
/* Linux has abstract socket address support */
&& addr->local.path[0] != 0
#endif
- )
+ )
{
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
return PR_FAILURE;
@@ -1794,7 +1864,9 @@ static PRStatus pt_Listen(PRFileDesc *fd, PRIntn backlog)
{
PRIntn rv;
- if (pt_TestAbort()) return PR_FAILURE;
+ if (pt_TestAbort()) {
+ return PR_FAILURE;
+ }
rv = listen(fd->secret->md.osfd, backlog);
if (rv == -1) {
@@ -1807,7 +1879,9 @@ static PRStatus pt_Listen(PRFileDesc *fd, PRIntn backlog)
static PRStatus pt_Shutdown(PRFileDesc *fd, PRIntn how)
{
PRIntn rv = -1;
- if (pt_TestAbort()) return PR_FAILURE;
+ if (pt_TestAbort()) {
+ return PR_FAILURE;
+ }
rv = shutdown(fd->secret->md.osfd, how);
@@ -1831,17 +1905,12 @@ static PRInt32 pt_Recv(
PRInt32 syserrno, bytes = -1;
PRIntn osflags;
- if (0 == flags)
+ if (0 == flags) {
osflags = 0;
+ }
else if (PR_MSG_PEEK == flags)
{
-#ifdef SYMBIAN
- /* MSG_PEEK doesn't work as expected. */
- PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
- return bytes;
-#else
osflags = MSG_PEEK;
-#endif
}
else
{
@@ -1849,14 +1918,18 @@ static PRInt32 pt_Recv(
return bytes;
}
- if (pt_TestAbort()) return bytes;
+ if (pt_TestAbort()) {
+ return bytes;
+ }
/* recv() is a much slower call on pre-2.6 Solaris than read(). */
#if defined(SOLARIS)
- if (0 == osflags)
+ if (0 == osflags) {
bytes = read(fd->secret->md.osfd, buf, amount);
- else
+ }
+ else {
bytes = recv(fd->secret->md.osfd, buf, amount, osflags);
+ }
#else
bytes = recv(fd->secret->md.osfd, buf, amount, osflags);
#endif
@@ -1865,7 +1938,9 @@ static PRInt32 pt_Recv(
if ((bytes == -1) && (syserrno == EWOULDBLOCK || syserrno == EAGAIN)
&& (!fd->secret->nonblocking))
{
- if (PR_INTERVAL_NO_WAIT == timeout) syserrno = ETIMEDOUT;
+ if (PR_INTERVAL_NO_WAIT == timeout) {
+ syserrno = ETIMEDOUT;
+ }
else
{
pt_Continuation op;
@@ -1880,8 +1955,9 @@ static PRInt32 pt_Recv(
syserrno = op.syserrno;
}
}
- if (bytes < 0)
+ if (bytes < 0) {
pt_MapError(_PR_MD_MAP_RECV_ERROR, syserrno);
+ }
return bytes;
} /* pt_Recv */
@@ -1897,10 +1973,12 @@ static PRInt32 pt_Send(
PRInt32 syserrno, bytes = -1;
PRBool fNeedContinue = PR_FALSE;
#if defined(SOLARIS)
- PRInt32 tmp_amount = amount;
+ PRInt32 tmp_amount = amount;
#endif
- if (pt_TestAbort()) return bytes;
+ if (pt_TestAbort()) {
+ return bytes;
+ }
/*
* On pre-2.6 Solaris, send() is much slower than write().
@@ -1946,9 +2024,11 @@ retry:
}
}
if ( (bytes == -1) && (syserrno == EWOULDBLOCK || syserrno == EAGAIN)
- && (!fd->secret->nonblocking) )
+ && (!fd->secret->nonblocking) )
{
- if (PR_INTERVAL_NO_WAIT == timeout) syserrno = ETIMEDOUT;
+ if (PR_INTERVAL_NO_WAIT == timeout) {
+ syserrno = ETIMEDOUT;
+ }
else
{
bytes = 0;
@@ -1970,8 +2050,9 @@ retry:
bytes = pt_Continue(&op);
syserrno = op.syserrno;
}
- if (bytes == -1)
+ if (bytes == -1) {
pt_MapError(_PR_MD_MAP_SEND_ERROR, syserrno);
+ }
return bytes;
} /* pt_Send */
@@ -1988,7 +2069,7 @@ static PRInt32 pt_SendTo(
PRInt32 syserrno, bytes = -1;
PRBool fNeedContinue = PR_FALSE;
pt_SockLen addr_len;
- const PRNetAddr *addrp = addr;
+ const PRNetAddr *addrp = addr;
#if defined(_PR_HAVE_SOCKADDR_LEN) || defined(_PR_INET6)
PRNetAddr addrCopy;
#endif
@@ -1996,7 +2077,9 @@ static PRInt32 pt_SendTo(
PRUint16 md_af = addr->raw.family;
#endif
- if (pt_TestAbort()) return bytes;
+ if (pt_TestAbort()) {
+ return bytes;
+ }
PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
#ifdef _PR_INET6
@@ -2019,14 +2102,18 @@ static PRInt32 pt_SendTo(
addrp = &addrCopy;
#endif
bytes = sendto(
- fd->secret->md.osfd, buf, amount, flags,
- (struct sockaddr*)addrp, addr_len);
+ fd->secret->md.osfd, buf, amount, flags,
+ (struct sockaddr*)addrp, addr_len);
syserrno = errno;
if ( (bytes == -1) && (syserrno == EWOULDBLOCK || syserrno == EAGAIN)
- && (!fd->secret->nonblocking) )
+ && (!fd->secret->nonblocking) )
{
- if (PR_INTERVAL_NO_WAIT == timeout) syserrno = ETIMEDOUT;
- else fNeedContinue = PR_TRUE;
+ if (PR_INTERVAL_NO_WAIT == timeout) {
+ syserrno = ETIMEDOUT;
+ }
+ else {
+ fNeedContinue = PR_TRUE;
+ }
}
if (fNeedContinue == PR_TRUE)
{
@@ -2043,8 +2130,9 @@ static PRInt32 pt_SendTo(
bytes = pt_Continue(&op);
syserrno = op.syserrno;
}
- if (bytes < 0)
+ if (bytes < 0) {
pt_MapError(_PR_MD_MAP_SENDTO_ERROR, syserrno);
+ }
return bytes;
} /* pt_SendTo */
@@ -2068,7 +2156,9 @@ static PRInt32 pt_TCP_SendTo(
PRUint16 md_af = addr->raw.family;
#endif
- if (pt_TestAbort()) return bytes;
+ if (pt_TestAbort()) {
+ return bytes;
+ }
PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
addr_len = PR_NETADDR_SIZE(addr);
@@ -2097,8 +2187,8 @@ static PRInt32 pt_TCP_SendTo(
#ifndef HAS_CONNECTX
bytes = sendto(
- fd->secret->md.osfd, buf, amount, MSG_FASTOPEN,
- (struct sockaddr*)addrp, addr_len);
+ fd->secret->md.osfd, buf, amount, MSG_FASTOPEN,
+ (struct sockaddr*)addrp, addr_len);
#else
sa_endpoints_t endpoints;
endpoints.sae_srcif = 0;
@@ -2110,13 +2200,17 @@ static PRInt32 pt_TCP_SendTo(
iov[0].iov_base = buf;
iov[0].iov_len = amount;
PRInt32 rv = connectx(fd->secret->md.osfd, &endpoints, SAE_ASSOCID_ANY,
- CONNECT_DATA_IDEMPOTENT, iov, 1, &bytes, NULL);
+ CONNECT_DATA_IDEMPOTENT, iov, 1, &bytes, NULL);
#endif
syserrno = errno;
if ( (bytes == -1) && (syserrno == EWOULDBLOCK || syserrno == EAGAIN)
- && (!fd->secret->nonblocking) ) {
- if (PR_INTERVAL_NO_WAIT == timeout) syserrno = ETIMEDOUT;
- else fNeedContinue = PR_TRUE;
+ && (!fd->secret->nonblocking) ) {
+ if (PR_INTERVAL_NO_WAIT == timeout) {
+ syserrno = ETIMEDOUT;
+ }
+ else {
+ fNeedContinue = PR_TRUE;
+ }
}
if (fNeedContinue == PR_TRUE) {
pt_Continuation op;
@@ -2144,24 +2238,30 @@ static PRInt32 pt_TCP_SendTo(
#endif /* LINUX || DARWIN */
static PRInt32 pt_RecvFrom(PRFileDesc *fd, void *buf, PRInt32 amount,
- PRIntn flags, PRNetAddr *addr, PRIntervalTime timeout)
+ PRIntn flags, PRNetAddr *addr, PRIntervalTime timeout)
{
PRBool fNeedContinue = PR_FALSE;
PRInt32 syserrno, bytes = -1;
pt_SockLen addr_len = sizeof(PRNetAddr);
- if (pt_TestAbort()) return bytes;
+ if (pt_TestAbort()) {
+ return bytes;
+ }
bytes = recvfrom(
- fd->secret->md.osfd, buf, amount, flags,
- (struct sockaddr*)addr, &addr_len);
+ fd->secret->md.osfd, buf, amount, flags,
+ (struct sockaddr*)addr, &addr_len);
syserrno = errno;
if ( (bytes == -1) && (syserrno == EWOULDBLOCK || syserrno == EAGAIN)
- && (!fd->secret->nonblocking) )
+ && (!fd->secret->nonblocking) )
{
- if (PR_INTERVAL_NO_WAIT == timeout) syserrno = ETIMEDOUT;
- else fNeedContinue = PR_TRUE;
+ if (PR_INTERVAL_NO_WAIT == timeout) {
+ syserrno = ETIMEDOUT;
+ }
+ else {
+ fNeedContinue = PR_TRUE;
+ }
}
if (fNeedContinue == PR_TRUE)
@@ -2188,12 +2288,14 @@ static PRInt32 pt_RecvFrom(PRFileDesc *fd, void *buf, PRInt32 amount,
}
#endif /* _PR_HAVE_SOCKADDR_LEN */
#ifdef _PR_INET6
- if (addr && (AF_INET6 == addr->raw.family))
+ if (addr && (AF_INET6 == addr->raw.family)) {
addr->raw.family = PR_AF_INET6;
+ }
#endif
}
- else
+ else {
pt_MapError(_PR_MD_MAP_RECVFROM_ERROR, syserrno);
+ }
return bytes;
} /* pt_RecvFrom */
@@ -2208,16 +2310,16 @@ static void pt_aix_sendfile_init_routine(void)
dlclose(handle);
}
-/*
+/*
* pt_AIXDispatchSendFile
*/
static PRInt32 pt_AIXDispatchSendFile(PRFileDesc *sd, PRSendFileData *sfd,
- PRTransmitFileFlags flags, PRIntervalTime timeout)
+ PRTransmitFileFlags flags, PRIntervalTime timeout)
{
int rv;
rv = pthread_once(&pt_aix_sendfile_once_block,
- pt_aix_sendfile_init_routine);
+ pt_aix_sendfile_init_routine);
PR_ASSERT(0 == rv);
if (pt_aix_sendfile_fptr) {
return pt_AIXSendFile(sd, sfd, flags, timeout);
@@ -2232,44 +2334,46 @@ static PRInt32 pt_AIXDispatchSendFile(PRFileDesc *sd, PRSendFileData *sfd,
* pt_AIXSendFile
*
* Send file sfd->fd across socket sd. If specified, header and trailer
- * buffers are sent before and after the file, respectively.
+ * buffers are sent before and after the file, respectively.
*
* PR_TRANSMITFILE_CLOSE_SOCKET flag - close socket after sending file
- *
+ *
* return number of bytes sent or -1 on error
*
* This implementation takes advantage of the send_file() system
* call available in AIX 4.3.2.
*/
-static PRInt32 pt_AIXSendFile(PRFileDesc *sd, PRSendFileData *sfd,
- PRTransmitFileFlags flags, PRIntervalTime timeout)
+static PRInt32 pt_AIXSendFile(PRFileDesc *sd, PRSendFileData *sfd,
+ PRTransmitFileFlags flags, PRIntervalTime timeout)
{
struct sf_parms sf_struct;
uint_t send_flags;
ssize_t rv;
int syserrno;
PRInt32 count;
- unsigned long long saved_file_offset;
- long long saved_file_bytes;
+ unsigned long long saved_file_offset;
+ long long saved_file_bytes;
sf_struct.header_data = (void *) sfd->header; /* cast away the 'const' */
sf_struct.header_length = sfd->hlen;
sf_struct.file_descriptor = sfd->fd->secret->md.osfd;
sf_struct.file_size = 0;
sf_struct.file_offset = sfd->file_offset;
- if (sfd->file_nbytes == 0)
- sf_struct.file_bytes = -1;
- else
- sf_struct.file_bytes = sfd->file_nbytes;
+ if (sfd->file_nbytes == 0) {
+ sf_struct.file_bytes = -1;
+ }
+ else {
+ sf_struct.file_bytes = sfd->file_nbytes;
+ }
sf_struct.trailer_data = (void *) sfd->trailer;
sf_struct.trailer_length = sfd->tlen;
sf_struct.bytes_sent = 0;
- saved_file_offset = sf_struct.file_offset;
+ saved_file_offset = sf_struct.file_offset;
saved_file_bytes = sf_struct.file_bytes;
- send_flags = 0; /* flags processed at the end */
+ send_flags = 0; /* flags processed at the end */
/* The first argument to send_file() is int*. */
PR_ASSERT(sizeof(int) == sizeof(sd->secret->md.osfd));
@@ -2285,14 +2389,15 @@ static PRInt32 pt_AIXSendFile(PRFileDesc *sd, PRSendFileData *sfd,
}
} else {
count = sf_struct.bytes_sent;
- /*
- * A bug in AIX 4.3.2 prevents the 'file_bytes' field from
- * being updated. So, 'file_bytes' is maintained by NSPR to
- * avoid conflict when this bug is fixed in AIX, in the future.
- */
- if (saved_file_bytes != -1)
- saved_file_bytes -= (sf_struct.file_offset - saved_file_offset);
- sf_struct.file_bytes = saved_file_bytes;
+ /*
+ * A bug in AIX 4.3.2 prevents the 'file_bytes' field from
+ * being updated. So, 'file_bytes' is maintained by NSPR to
+ * avoid conflict when this bug is fixed in AIX, in the future.
+ */
+ if (saved_file_bytes != -1) {
+ saved_file_bytes -= (sf_struct.file_offset - saved_file_offset);
+ }
+ sf_struct.file_bytes = saved_file_bytes;
}
if ((rv == 1) || ((rv == -1) && (count == 0))) {
@@ -2316,10 +2421,10 @@ static PRInt32 pt_AIXSendFile(PRFileDesc *sd, PRSendFileData *sfd,
if (flags & PR_TRANSMITFILE_CLOSE_SOCKET) {
PR_Close(sd);
}
- PR_ASSERT(count == (sfd->hlen + sfd->tlen +
- ((sfd->file_nbytes == 0) ?
- sf_struct.file_size - sfd->file_offset :
- sfd->file_nbytes)));
+ PR_ASSERT(count == (sfd->hlen + sfd->tlen +
+ ((sfd->file_nbytes == 0) ?
+ sf_struct.file_size - sfd->file_offset :
+ sfd->file_nbytes)));
return count;
}
#endif /* AIX */
@@ -2332,15 +2437,15 @@ static PRInt32 pt_AIXSendFile(PRFileDesc *sd, PRSendFileData *sfd,
* buffers are sent before and after the file, respectively.
*
* PR_TRANSMITFILE_CLOSE_SOCKET flag - close socket after sending file
- *
+ *
* return number of bytes sent or -1 on error
*
* This implementation takes advantage of the sendfile() system
* call available in HP-UX B.11.00.
*/
-static PRInt32 pt_HPUXSendFile(PRFileDesc *sd, PRSendFileData *sfd,
- PRTransmitFileFlags flags, PRIntervalTime timeout)
+static PRInt32 pt_HPUXSendFile(PRFileDesc *sd, PRSendFileData *sfd,
+ PRTransmitFileFlags flags, PRIntervalTime timeout)
{
struct stat statbuf;
size_t nbytes_to_send, file_nbytes_to_send;
@@ -2354,7 +2459,7 @@ static PRInt32 pt_HPUXSendFile(PRFileDesc *sd, PRSendFileData *sfd,
if (fstat(sfd->fd->secret->md.osfd, &statbuf) == -1) {
_PR_MD_MAP_FSTAT_ERROR(errno);
return -1;
- }
+ }
file_nbytes_to_send = statbuf.st_size - sfd->file_offset;
} else {
file_nbytes_to_send = sfd->file_nbytes;
@@ -2375,7 +2480,7 @@ static PRInt32 pt_HPUXSendFile(PRFileDesc *sd, PRSendFileData *sfd,
do {
count = sendfile(sd->secret->md.osfd, sfd->fd->secret->md.osfd,
- sfd->file_offset, file_nbytes_to_send, hdtrl, send_flags);
+ sfd->file_offset, file_nbytes_to_send, hdtrl, send_flags);
} while (count == -1 && (syserrno = errno) == EINTR);
if (count == -1 && (syserrno == EAGAIN || syserrno == EWOULDBLOCK)) {
@@ -2385,14 +2490,14 @@ static PRInt32 pt_HPUXSendFile(PRFileDesc *sd, PRSendFileData *sfd,
pt_Continuation op;
if (count < sfd->hlen) {
- /* header not sent */
+ /* header not sent */
hdtrl[0].iov_base = ((char *) sfd->header) + count;
hdtrl[0].iov_len = sfd->hlen - count;
op.arg3.file_spec.offset = sfd->file_offset;
op.arg3.file_spec.nbytes = file_nbytes_to_send;
} else if (count < (sfd->hlen + file_nbytes_to_send)) {
- /* header sent, file not sent */
+ /* header sent, file not sent */
hdtrl[0].iov_base = NULL;
hdtrl[0].iov_len = 0;
@@ -2400,23 +2505,23 @@ static PRInt32 pt_HPUXSendFile(PRFileDesc *sd, PRSendFileData *sfd,
op.arg3.file_spec.offset = sfd->file_offset + count - sfd->hlen;
op.arg3.file_spec.nbytes = file_nbytes_to_send - (count - sfd->hlen);
} else if (count < (sfd->hlen + file_nbytes_to_send + sfd->tlen)) {
- PRUint32 trailer_nbytes_sent;
+ PRUint32 trailer_nbytes_sent;
- /* header sent, file sent, trailer not sent */
+ /* header sent, file sent, trailer not sent */
hdtrl[0].iov_base = NULL;
hdtrl[0].iov_len = 0;
- /*
- * set file offset and len so that no more file data is
- * sent
- */
+ /*
+ * set file offset and len so that no more file data is
+ * sent
+ */
op.arg3.file_spec.offset = statbuf.st_size;
op.arg3.file_spec.nbytes = 0;
- trailer_nbytes_sent = count - sfd->hlen - file_nbytes_to_send;
+ trailer_nbytes_sent = count - sfd->hlen - file_nbytes_to_send;
hdtrl[1].iov_base = ((char *) sfd->trailer) + trailer_nbytes_sent;
hdtrl[1].iov_len = sfd->tlen - trailer_nbytes_sent;
- }
+ }
op.arg1.osfd = sd->secret->md.osfd;
op.filedesc = sfd->fd->secret->md.osfd;
@@ -2445,7 +2550,7 @@ static PRInt32 pt_HPUXSendFile(PRFileDesc *sd, PRSendFileData *sfd,
#endif /* HPUX11 */
-#ifdef SOLARIS
+#ifdef SOLARIS
/*
* pt_SolarisSendFile
@@ -2462,12 +2567,12 @@ static PRInt32 pt_HPUXSendFile(PRFileDesc *sd, PRSendFileData *sfd,
*/
static PRInt32 pt_SolarisSendFile(PRFileDesc *sd, PRSendFileData *sfd,
- PRTransmitFileFlags flags, PRIntervalTime timeout)
+ PRTransmitFileFlags flags, PRIntervalTime timeout)
{
struct stat statbuf;
- size_t nbytes_to_send, file_nbytes_to_send;
- struct sendfilevec sfv_struct[3];
- int sfvcnt = 0;
+ size_t nbytes_to_send, file_nbytes_to_send;
+ struct sendfilevec sfv_struct[3];
+ int sfvcnt = 0;
size_t xferred;
PRInt32 count;
int syserrno;
@@ -2477,7 +2582,7 @@ static PRInt32 pt_SolarisSendFile(PRFileDesc *sd, PRSendFileData *sfd,
if (fstat(sfd->fd->secret->md.osfd, &statbuf) == -1) {
_PR_MD_MAP_FSTAT_ERROR(errno);
return -1;
- }
+ }
file_nbytes_to_send = statbuf.st_size - sfd->file_offset;
} else {
file_nbytes_to_send = sfd->file_nbytes;
@@ -2488,7 +2593,7 @@ static PRInt32 pt_SolarisSendFile(PRFileDesc *sd, PRSendFileData *sfd,
if (sfd->hlen != 0) {
sfv_struct[sfvcnt].sfv_fd = SFV_FD_SELF;
sfv_struct[sfvcnt].sfv_flag = 0;
- sfv_struct[sfvcnt].sfv_off = (off_t) sfd->header;
+ sfv_struct[sfvcnt].sfv_off = (off_t) sfd->header;
sfv_struct[sfvcnt].sfv_len = sfd->hlen;
sfvcnt++;
}
@@ -2504,7 +2609,7 @@ static PRInt32 pt_SolarisSendFile(PRFileDesc *sd, PRSendFileData *sfd,
if (sfd->tlen != 0) {
sfv_struct[sfvcnt].sfv_fd = SFV_FD_SELF;
sfv_struct[sfvcnt].sfv_flag = 0;
- sfv_struct[sfvcnt].sfv_off = (off_t) sfd->trailer;
+ sfv_struct[sfvcnt].sfv_off = (off_t) sfd->trailer;
sfv_struct[sfvcnt].sfv_len = sfd->tlen;
sfvcnt++;
}
@@ -2513,21 +2618,21 @@ static PRInt32 pt_SolarisSendFile(PRFileDesc *sd, PRSendFileData *sfd,
count = 0;
goto done;
}
-
+
/*
* Strictly speaking, we may have sent some bytes when the
* sendfilev() is interrupted and we should retry it from an
* updated offset. We are not doing that here.
*/
count = SOLARIS_SENDFILEV(sd->secret->md.osfd, sfv_struct,
- sfvcnt, &xferred);
+ sfvcnt, &xferred);
PR_ASSERT((count == -1) || (count == xferred));
if (count == -1) {
syserrno = errno;
if (syserrno == EINTR
- || syserrno == EAGAIN || syserrno == EWOULDBLOCK) {
+ || syserrno == EAGAIN || syserrno == EWOULDBLOCK) {
count = xferred;
}
} else if (count == 0) {
@@ -2588,14 +2693,14 @@ static void pt_solaris_sendfilev_init_routine(void)
{
void *handle;
PRBool close_it = PR_FALSE;
-
+
/*
* We do not want to unload libsendfile.so. This handle is leaked
* intentionally.
*/
handle = dlopen("libsendfile.so", RTLD_LAZY | RTLD_GLOBAL);
PR_LOG(_pr_io_lm, PR_LOG_DEBUG,
- ("dlopen(libsendfile.so) returns %p", handle));
+ ("dlopen(libsendfile.so) returns %p", handle));
if (NULL == handle) {
/*
@@ -2605,28 +2710,28 @@ static void pt_solaris_sendfilev_init_routine(void)
*/
handle = dlopen(0, RTLD_LAZY | RTLD_GLOBAL);
PR_LOG(_pr_io_lm, PR_LOG_DEBUG,
- ("dlopen(0) returns %p", handle));
+ ("dlopen(0) returns %p", handle));
close_it = PR_TRUE;
}
pt_solaris_sendfilev_fptr = (ssize_t (*)()) dlsym(handle, "sendfilev");
PR_LOG(_pr_io_lm, PR_LOG_DEBUG,
- ("dlsym(sendfilev) returns %p", pt_solaris_sendfilev_fptr));
-
+ ("dlsym(sendfilev) returns %p", pt_solaris_sendfilev_fptr));
+
if (close_it) {
dlclose(handle);
}
}
-/*
+/*
* pt_SolarisDispatchSendFile
*/
static PRInt32 pt_SolarisDispatchSendFile(PRFileDesc *sd, PRSendFileData *sfd,
- PRTransmitFileFlags flags, PRIntervalTime timeout)
+ PRTransmitFileFlags flags, PRIntervalTime timeout)
{
int rv;
rv = pthread_once(&pt_solaris_sendfilev_once_block,
- pt_solaris_sendfilev_init_routine);
+ pt_solaris_sendfilev_init_routine);
PR_ASSERT(0 == rv);
if (pt_solaris_sendfilev_fptr) {
return pt_SolarisSendFile(sd, sfd, flags, timeout);
@@ -2646,7 +2751,7 @@ static PRInt32 pt_SolarisDispatchSendFile(PRFileDesc *sd, PRSendFileData *sfd,
* buffers are sent before and after the file, respectively.
*
* PR_TRANSMITFILE_CLOSE_SOCKET flag - close socket after sending file
- *
+ *
* return number of bytes sent or -1 on error
*
* This implementation takes advantage of the sendfile() system
@@ -2654,10 +2759,10 @@ static PRInt32 pt_SolarisDispatchSendFile(PRFileDesc *sd, PRSendFileData *sfd,
*/
static PRInt32 pt_LinuxSendFile(PRFileDesc *sd, PRSendFileData *sfd,
- PRTransmitFileFlags flags, PRIntervalTime timeout)
+ PRTransmitFileFlags flags, PRIntervalTime timeout)
{
struct stat statbuf;
- size_t file_nbytes_to_send;
+ size_t file_nbytes_to_send;
PRInt32 count = 0;
ssize_t rv;
int syserrno;
@@ -2670,17 +2775,17 @@ static PRInt32 pt_LinuxSendFile(PRFileDesc *sd, PRSendFileData *sfd,
if (fstat(sfd->fd->secret->md.osfd, &statbuf) == -1) {
_PR_MD_MAP_FSTAT_ERROR(errno);
return -1;
- }
+ }
file_nbytes_to_send = statbuf.st_size - sfd->file_offset;
} else {
file_nbytes_to_send = sfd->file_nbytes;
}
if ((sfd->hlen != 0 || sfd->tlen != 0)
- && sd->secret->md.tcp_nodelay == 0) {
+ && sd->secret->md.tcp_nodelay == 0) {
tcp_cork = 1;
if (setsockopt(sd->secret->md.osfd, SOL_TCP, TCP_CORK,
- &tcp_cork, sizeof tcp_cork) == 0) {
+ &tcp_cork, sizeof tcp_cork) == 0) {
tcp_cork_enabled = PR_TRUE;
} else {
syserrno = errno;
@@ -2695,8 +2800,8 @@ static PRInt32 pt_LinuxSendFile(PRFileDesc *sd, PRSendFileData *sfd,
* on going.
*/
PR_LOG(_pr_io_lm, PR_LOG_WARNING,
- ("pt_LinuxSendFile: "
- "setsockopt(TCP_CORK) failed with EINVAL\n"));
+ ("pt_LinuxSendFile: "
+ "setsockopt(TCP_CORK) failed with EINVAL\n"));
}
}
@@ -2711,7 +2816,7 @@ static PRInt32 pt_LinuxSendFile(PRFileDesc *sd, PRSendFileData *sfd,
offset = sfd->file_offset;
do {
rv = sendfile(sd->secret->md.osfd, sfd->fd->secret->md.osfd,
- &offset, file_nbytes_to_send);
+ &offset, file_nbytes_to_send);
} while (rv == -1 && (syserrno = errno) == EINTR);
if (rv == -1) {
if (syserrno != EAGAIN && syserrno != EWOULDBLOCK) {
@@ -2757,7 +2862,7 @@ failed:
if (tcp_cork_enabled) {
tcp_cork = 0;
if (setsockopt(sd->secret->md.osfd, SOL_TCP, TCP_CORK,
- &tcp_cork, sizeof tcp_cork) == -1 && count != -1) {
+ &tcp_cork, sizeof tcp_cork) == -1 && count != -1) {
_PR_MD_MAP_SETSOCKOPT_ERROR(errno);
count = -1;
}
@@ -2773,14 +2878,16 @@ failed:
#endif /* LINUX */
#ifdef AIX
-extern int _pr_aix_send_file_use_disabled;
+extern int _pr_aix_send_file_use_disabled;
#endif
static PRInt32 pt_SendFile(
PRFileDesc *sd, PRSendFileData *sfd,
PRTransmitFileFlags flags, PRIntervalTime timeout)
{
- if (pt_TestAbort()) return -1;
+ if (pt_TestAbort()) {
+ return -1;
+ }
/* The socket must be in blocking mode. */
if (sd->secret->nonblocking)
{
@@ -2791,31 +2898,33 @@ static PRInt32 pt_SendFile(
return(pt_HPUXSendFile(sd, sfd, flags, timeout));
#elif defined(AIX)
#ifdef HAVE_SEND_FILE
- /*
- * A bug in AIX 4.3.2 results in corruption of data transferred by
- * send_file(); AIX patch PTF U463956 contains the fix. A user can
- * disable the use of send_file function in NSPR, when this patch is
- * not installed on the system, by setting the envionment variable
- * NSPR_AIX_SEND_FILE_USE_DISABLED to 1.
- */
- if (_pr_aix_send_file_use_disabled)
- return(PR_EmulateSendFile(sd, sfd, flags, timeout));
- else
- return(pt_AIXSendFile(sd, sfd, flags, timeout));
+ /*
+ * A bug in AIX 4.3.2 results in corruption of data transferred by
+ * send_file(); AIX patch PTF U463956 contains the fix. A user can
+ * disable the use of send_file function in NSPR, when this patch is
+ * not installed on the system, by setting the envionment variable
+ * NSPR_AIX_SEND_FILE_USE_DISABLED to 1.
+ */
+ if (_pr_aix_send_file_use_disabled) {
+ return(PR_EmulateSendFile(sd, sfd, flags, timeout));
+ }
+ else {
+ return(pt_AIXSendFile(sd, sfd, flags, timeout));
+ }
#else
- return(PR_EmulateSendFile(sd, sfd, flags, timeout));
+ return(PR_EmulateSendFile(sd, sfd, flags, timeout));
/* return(pt_AIXDispatchSendFile(sd, sfd, flags, timeout));*/
#endif /* HAVE_SEND_FILE */
#elif defined(SOLARIS)
#ifdef HAVE_SENDFILEV
- return(pt_SolarisSendFile(sd, sfd, flags, timeout));
+ return(pt_SolarisSendFile(sd, sfd, flags, timeout));
#else
- return(pt_SolarisDispatchSendFile(sd, sfd, flags, timeout));
+ return(pt_SolarisDispatchSendFile(sd, sfd, flags, timeout));
#endif /* HAVE_SENDFILEV */
#elif defined(LINUX)
- return(pt_LinuxSendFile(sd, sfd, flags, timeout));
+ return(pt_LinuxSendFile(sd, sfd, flags, timeout));
#else
- return(PR_EmulateSendFile(sd, sfd, flags, timeout));
+ return(PR_EmulateSendFile(sd, sfd, flags, timeout));
#endif
}
@@ -2823,17 +2932,17 @@ static PRInt32 pt_TransmitFile(
PRFileDesc *sd, PRFileDesc *fd, const void *headers,
PRInt32 hlen, PRTransmitFileFlags flags, PRIntervalTime timeout)
{
- PRSendFileData sfd;
+ PRSendFileData sfd;
- sfd.fd = fd;
- sfd.file_offset = 0;
- sfd.file_nbytes = 0;
- sfd.header = headers;
- sfd.hlen = hlen;
- sfd.trailer = NULL;
- sfd.tlen = 0;
+ sfd.fd = fd;
+ sfd.file_offset = 0;
+ sfd.file_nbytes = 0;
+ sfd.header = headers;
+ sfd.hlen = hlen;
+ sfd.trailer = NULL;
+ sfd.tlen = 0;
- return(pt_SendFile(sd, &sfd, flags, timeout));
+ return(pt_SendFile(sd, &sfd, flags, timeout));
} /* pt_TransmitFile */
static PRInt32 pt_AcceptRead(
@@ -2842,7 +2951,9 @@ static PRInt32 pt_AcceptRead(
{
PRInt32 rv = -1;
- if (pt_TestAbort()) return rv;
+ if (pt_TestAbort()) {
+ return rv;
+ }
/* The socket must be in blocking mode. */
if (sd->secret->nonblocking)
{
@@ -2859,10 +2970,12 @@ static PRStatus pt_GetSockName(PRFileDesc *fd, PRNetAddr *addr)
PRIntn rv = -1;
pt_SockLen addr_len = sizeof(PRNetAddr);
- if (pt_TestAbort()) return PR_FAILURE;
+ if (pt_TestAbort()) {
+ return PR_FAILURE;
+ }
rv = getsockname(
- fd->secret->md.osfd, (struct sockaddr*)addr, &addr_len);
+ fd->secret->md.osfd, (struct sockaddr*)addr, &addr_len);
if (rv == -1) {
pt_MapError(_PR_MD_MAP_GETSOCKNAME_ERROR, errno);
return PR_FAILURE;
@@ -2875,8 +2988,9 @@ static PRStatus pt_GetSockName(PRFileDesc *fd, PRNetAddr *addr)
}
#endif /* _PR_HAVE_SOCKADDR_LEN */
#ifdef _PR_INET6
- if (AF_INET6 == addr->raw.family)
+ if (AF_INET6 == addr->raw.family) {
addr->raw.family = PR_AF_INET6;
+ }
#endif
PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
PR_ASSERT(IsValidNetAddrLen(addr, addr_len) == PR_TRUE);
@@ -2888,10 +3002,12 @@ static PRStatus pt_GetPeerName(PRFileDesc *fd, PRNetAddr *addr)
PRIntn rv = -1;
pt_SockLen addr_len = sizeof(PRNetAddr);
- if (pt_TestAbort()) return PR_FAILURE;
+ if (pt_TestAbort()) {
+ return PR_FAILURE;
+ }
rv = getpeername(
- fd->secret->md.osfd, (struct sockaddr*)addr, &addr_len);
+ fd->secret->md.osfd, (struct sockaddr*)addr, &addr_len);
if (rv == -1) {
pt_MapError(_PR_MD_MAP_GETPEERNAME_ERROR, errno);
@@ -2905,8 +3021,9 @@ static PRStatus pt_GetPeerName(PRFileDesc *fd, PRNetAddr *addr)
}
#endif /* _PR_HAVE_SOCKADDR_LEN */
#ifdef _PR_INET6
- if (AF_INET6 == addr->raw.family)
+ if (AF_INET6 == addr->raw.family) {
addr->raw.family = PR_AF_INET6;
+ }
#endif
PR_ASSERT(IsValidNetAddr(addr) == PR_TRUE);
PR_ASSERT(IsValidNetAddrLen(addr, addr_len) == PR_TRUE);
@@ -2939,7 +3056,7 @@ static PRStatus pt_GetSocketOption(PRFileDesc *fd, PRSocketOptionData *data)
struct linger linger;
length = sizeof(linger);
rv = getsockopt(
- fd->secret->md.osfd, level, name, (char *) &linger, &length);
+ fd->secret->md.osfd, level, name, (char *) &linger, &length);
PR_ASSERT((-1 == rv) || (sizeof(linger) == length));
data->value.linger.polarity =
(linger.l_onoff) ? PR_TRUE : PR_FALSE;
@@ -2956,7 +3073,7 @@ static PRStatus pt_GetSocketOption(PRFileDesc *fd, PRSocketOptionData *data)
PRIntn value;
length = sizeof(PRIntn);
rv = getsockopt(
- fd->secret->md.osfd, level, name, (char*)&value, &length);
+ fd->secret->md.osfd, level, name, (char*)&value, &length);
PR_ASSERT((-1 == rv) || (sizeof(PRIntn) == length));
data->value.reuse_addr = (0 == value) ? PR_FALSE : PR_TRUE;
break;
@@ -2966,8 +3083,8 @@ static PRStatus pt_GetSocketOption(PRFileDesc *fd, PRSocketOptionData *data)
PRUint8 xbool;
length = sizeof(xbool);
rv = getsockopt(
- fd->secret->md.osfd, level, name,
- (char*)&xbool, &length);
+ fd->secret->md.osfd, level, name,
+ (char*)&xbool, &length);
PR_ASSERT((-1 == rv) || (sizeof(xbool) == length));
data->value.mcast_loopback = (0 == xbool) ? PR_FALSE : PR_TRUE;
break;
@@ -2979,7 +3096,7 @@ static PRStatus pt_GetSocketOption(PRFileDesc *fd, PRSocketOptionData *data)
PRIntn value;
length = sizeof(PRIntn);
rv = getsockopt(
- fd->secret->md.osfd, level, name, (char*)&value, &length);
+ fd->secret->md.osfd, level, name, (char*)&value, &length);
PR_ASSERT((-1 == rv) || (sizeof(PRIntn) == length));
data->value.recv_buffer_size = value;
break;
@@ -2989,8 +3106,8 @@ static PRStatus pt_GetSocketOption(PRFileDesc *fd, PRSocketOptionData *data)
{
length = sizeof(PRUintn);
rv = getsockopt(
- fd->secret->md.osfd, level, name,
- (char*)&data->value.ip_ttl, &length);
+ fd->secret->md.osfd, level, name,
+ (char*)&data->value.ip_ttl, &length);
PR_ASSERT((-1 == rv) || (sizeof(PRIntn) == length));
break;
}
@@ -2999,8 +3116,8 @@ static PRStatus pt_GetSocketOption(PRFileDesc *fd, PRSocketOptionData *data)
PRUint8 ttl;
length = sizeof(ttl);
rv = getsockopt(
- fd->secret->md.osfd, level, name,
- (char*)&ttl, &length);
+ fd->secret->md.osfd, level, name,
+ (char*)&ttl, &length);
PR_ASSERT((-1 == rv) || (sizeof(ttl) == length));
data->value.mcast_ttl = ttl;
break;
@@ -3011,7 +3128,7 @@ static PRStatus pt_GetSocketOption(PRFileDesc *fd, PRSocketOptionData *data)
struct ip_mreq mreq;
length = sizeof(mreq);
rv = getsockopt(
- fd->secret->md.osfd, level, name, (char*)&mreq, &length);
+ fd->secret->md.osfd, level, name, (char*)&mreq, &length);
PR_ASSERT((-1 == rv) || (sizeof(mreq) == length));
data->value.add_member.mcaddr.inet.ip =
mreq.imr_multiaddr.s_addr;
@@ -3023,17 +3140,19 @@ static PRStatus pt_GetSocketOption(PRFileDesc *fd, PRSocketOptionData *data)
{
length = sizeof(data->value.mcast_if.inet.ip);
rv = getsockopt(
- fd->secret->md.osfd, level, name,
- (char*)&data->value.mcast_if.inet.ip, &length);
+ fd->secret->md.osfd, level, name,
+ (char*)&data->value.mcast_if.inet.ip, &length);
PR_ASSERT((-1 == rv)
- || (sizeof(data->value.mcast_if.inet.ip) == length));
+ || (sizeof(data->value.mcast_if.inet.ip) == length));
break;
}
default:
PR_NOT_REACHED("Unknown socket option");
break;
}
- if (-1 == rv) _PR_MD_MAP_GETSOCKOPT_ERROR(errno);
+ if (-1 == rv) {
+ _PR_MD_MAP_GETSOCKOPT_ERROR(errno);
+ }
}
return (-1 == rv) ? PR_FAILURE : PR_SUCCESS;
} /* pt_GetSocketOption */
@@ -3064,7 +3183,7 @@ static PRStatus pt_SetSocketOption(PRFileDesc *fd, const PRSocketOptionData *dat
linger.l_onoff = data->value.linger.polarity;
linger.l_linger = PR_IntervalToSeconds(data->value.linger.linger);
rv = setsockopt(
- fd->secret->md.osfd, level, name, (char*)&linger, sizeof(linger));
+ fd->secret->md.osfd, level, name, (char*)&linger, sizeof(linger));
break;
}
case PR_SockOpt_Reuseaddr:
@@ -3075,8 +3194,8 @@ static PRStatus pt_SetSocketOption(PRFileDesc *fd, const PRSocketOptionData *dat
{
PRIntn value = (data->value.reuse_addr) ? 1 : 0;
rv = setsockopt(
- fd->secret->md.osfd, level, name,
- (char*)&value, sizeof(PRIntn));
+ fd->secret->md.osfd, level, name,
+ (char*)&value, sizeof(PRIntn));
#ifdef LINUX
/* for pt_LinuxSendFile */
if (name == TCP_NODELAY && rv == 0) {
@@ -3089,8 +3208,8 @@ static PRStatus pt_SetSocketOption(PRFileDesc *fd, const PRSocketOptionData *dat
{
PRUint8 xbool = data->value.mcast_loopback ? 1 : 0;
rv = setsockopt(
- fd->secret->md.osfd, level, name,
- (char*)&xbool, sizeof(xbool));
+ fd->secret->md.osfd, level, name,
+ (char*)&xbool, sizeof(xbool));
break;
}
case PR_SockOpt_RecvBufferSize:
@@ -3099,24 +3218,24 @@ static PRStatus pt_SetSocketOption(PRFileDesc *fd, const PRSocketOptionData *dat
{
PRIntn value = data->value.recv_buffer_size;
rv = setsockopt(
- fd->secret->md.osfd, level, name,
- (char*)&value, sizeof(PRIntn));
+ fd->secret->md.osfd, level, name,
+ (char*)&value, sizeof(PRIntn));
break;
}
case PR_SockOpt_IpTimeToLive:
case PR_SockOpt_IpTypeOfService:
{
rv = setsockopt(
- fd->secret->md.osfd, level, name,
- (char*)&data->value.ip_ttl, sizeof(PRUintn));
+ fd->secret->md.osfd, level, name,
+ (char*)&data->value.ip_ttl, sizeof(PRUintn));
break;
}
case PR_SockOpt_McastTimeToLive:
{
PRUint8 ttl = data->value.mcast_ttl;
rv = setsockopt(
- fd->secret->md.osfd, level, name,
- (char*)&ttl, sizeof(ttl));
+ fd->secret->md.osfd, level, name,
+ (char*)&ttl, sizeof(ttl));
break;
}
case PR_SockOpt_AddMember:
@@ -3128,23 +3247,25 @@ static PRStatus pt_SetSocketOption(PRFileDesc *fd, const PRSocketOptionData *dat
mreq.imr_interface.s_addr =
data->value.add_member.ifaddr.inet.ip;
rv = setsockopt(
- fd->secret->md.osfd, level, name,
- (char*)&mreq, sizeof(mreq));
+ fd->secret->md.osfd, level, name,
+ (char*)&mreq, sizeof(mreq));
break;
}
case PR_SockOpt_McastInterface:
{
rv = setsockopt(
- fd->secret->md.osfd, level, name,
- (char*)&data->value.mcast_if.inet.ip,
- sizeof(data->value.mcast_if.inet.ip));
+ fd->secret->md.osfd, level, name,
+ (char*)&data->value.mcast_if.inet.ip,
+ sizeof(data->value.mcast_if.inet.ip));
break;
}
default:
PR_NOT_REACHED("Unknown socket option");
break;
}
- if (-1 == rv) _PR_MD_MAP_SETSOCKOPT_ERROR(errno);
+ if (-1 == rv) {
+ _PR_MD_MAP_SETSOCKOPT_ERROR(errno);
+ }
}
return (-1 == rv) ? PR_FAILURE : PR_SUCCESS;
} /* pt_SetSocketOption */
@@ -3165,30 +3286,30 @@ static PRIOMethods _pr_file_methods = {
pt_Seek64,
pt_FileInfo,
pt_FileInfo64,
- (PRWritevFN)_PR_InvalidInt,
- (PRConnectFN)_PR_InvalidStatus,
- (PRAcceptFN)_PR_InvalidDesc,
- (PRBindFN)_PR_InvalidStatus,
- (PRListenFN)_PR_InvalidStatus,
- (PRShutdownFN)_PR_InvalidStatus,
- (PRRecvFN)_PR_InvalidInt,
- (PRSendFN)_PR_InvalidInt,
- (PRRecvfromFN)_PR_InvalidInt,
- (PRSendtoFN)_PR_InvalidInt,
+ (PRWritevFN)_PR_InvalidInt,
+ (PRConnectFN)_PR_InvalidStatus,
+ (PRAcceptFN)_PR_InvalidDesc,
+ (PRBindFN)_PR_InvalidStatus,
+ (PRListenFN)_PR_InvalidStatus,
+ (PRShutdownFN)_PR_InvalidStatus,
+ (PRRecvFN)_PR_InvalidInt,
+ (PRSendFN)_PR_InvalidInt,
+ (PRRecvfromFN)_PR_InvalidInt,
+ (PRSendtoFN)_PR_InvalidInt,
pt_Poll,
- (PRAcceptreadFN)_PR_InvalidInt,
- (PRTransmitfileFN)_PR_InvalidInt,
- (PRGetsocknameFN)_PR_InvalidStatus,
- (PRGetpeernameFN)_PR_InvalidStatus,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
+ (PRAcceptreadFN)_PR_InvalidInt,
+ (PRTransmitfileFN)_PR_InvalidInt,
+ (PRGetsocknameFN)_PR_InvalidStatus,
+ (PRGetpeernameFN)_PR_InvalidStatus,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
(PRGetsocketoptionFN)_PR_InvalidStatus,
(PRSetsocketoptionFN)_PR_InvalidStatus,
- (PRSendfileFN)_PR_InvalidInt,
- (PRConnectcontinueFN)_PR_InvalidStatus,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
+ (PRSendfileFN)_PR_InvalidInt,
+ (PRConnectcontinueFN)_PR_InvalidStatus,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
(PRReservedFN)_PR_InvalidInt
};
@@ -3204,30 +3325,30 @@ static PRIOMethods _pr_pipe_methods = {
(PRSeek64FN)_PR_InvalidInt64,
(PRFileInfoFN)_PR_InvalidStatus,
(PRFileInfo64FN)_PR_InvalidStatus,
- (PRWritevFN)_PR_InvalidInt,
- (PRConnectFN)_PR_InvalidStatus,
- (PRAcceptFN)_PR_InvalidDesc,
- (PRBindFN)_PR_InvalidStatus,
- (PRListenFN)_PR_InvalidStatus,
- (PRShutdownFN)_PR_InvalidStatus,
- (PRRecvFN)_PR_InvalidInt,
- (PRSendFN)_PR_InvalidInt,
- (PRRecvfromFN)_PR_InvalidInt,
- (PRSendtoFN)_PR_InvalidInt,
+ (PRWritevFN)_PR_InvalidInt,
+ (PRConnectFN)_PR_InvalidStatus,
+ (PRAcceptFN)_PR_InvalidDesc,
+ (PRBindFN)_PR_InvalidStatus,
+ (PRListenFN)_PR_InvalidStatus,
+ (PRShutdownFN)_PR_InvalidStatus,
+ (PRRecvFN)_PR_InvalidInt,
+ (PRSendFN)_PR_InvalidInt,
+ (PRRecvfromFN)_PR_InvalidInt,
+ (PRSendtoFN)_PR_InvalidInt,
pt_Poll,
- (PRAcceptreadFN)_PR_InvalidInt,
- (PRTransmitfileFN)_PR_InvalidInt,
- (PRGetsocknameFN)_PR_InvalidStatus,
- (PRGetpeernameFN)_PR_InvalidStatus,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
+ (PRAcceptreadFN)_PR_InvalidInt,
+ (PRTransmitfileFN)_PR_InvalidInt,
+ (PRGetsocknameFN)_PR_InvalidStatus,
+ (PRGetpeernameFN)_PR_InvalidStatus,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
(PRGetsocketoptionFN)_PR_InvalidStatus,
(PRSetsocketoptionFN)_PR_InvalidStatus,
- (PRSendfileFN)_PR_InvalidInt,
- (PRConnectcontinueFN)_PR_InvalidStatus,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
+ (PRSendfileFN)_PR_InvalidInt,
+ (PRConnectcontinueFN)_PR_InvalidStatus,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
(PRReservedFN)_PR_InvalidInt
};
@@ -3266,11 +3387,11 @@ static PRIOMethods _pr_tcp_methods = {
(PRReservedFN)_PR_InvalidInt,
pt_GetSocketOption,
pt_SetSocketOption,
- pt_SendFile,
+ pt_SendFile,
pt_ConnectContinue,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
(PRReservedFN)_PR_InvalidInt
};
@@ -3305,11 +3426,11 @@ static PRIOMethods _pr_udp_methods = {
(PRReservedFN)_PR_InvalidInt,
pt_GetSocketOption,
pt_SetSocketOption,
- (PRSendfileFN)_PR_InvalidInt,
- (PRConnectcontinueFN)_PR_InvalidStatus,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
+ (PRSendfileFN)_PR_InvalidInt,
+ (PRConnectcontinueFN)_PR_InvalidStatus,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
(PRReservedFN)_PR_InvalidInt
};
@@ -3325,39 +3446,38 @@ static PRIOMethods _pr_socketpollfd_methods = {
(PRSeek64FN)_PR_InvalidInt64,
(PRFileInfoFN)_PR_InvalidStatus,
(PRFileInfo64FN)_PR_InvalidStatus,
- (PRWritevFN)_PR_InvalidInt,
- (PRConnectFN)_PR_InvalidStatus,
- (PRAcceptFN)_PR_InvalidDesc,
- (PRBindFN)_PR_InvalidStatus,
- (PRListenFN)_PR_InvalidStatus,
- (PRShutdownFN)_PR_InvalidStatus,
- (PRRecvFN)_PR_InvalidInt,
- (PRSendFN)_PR_InvalidInt,
- (PRRecvfromFN)_PR_InvalidInt,
- (PRSendtoFN)_PR_InvalidInt,
- pt_Poll,
- (PRAcceptreadFN)_PR_InvalidInt,
- (PRTransmitfileFN)_PR_InvalidInt,
- (PRGetsocknameFN)_PR_InvalidStatus,
- (PRGetpeernameFN)_PR_InvalidStatus,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
+ (PRWritevFN)_PR_InvalidInt,
+ (PRConnectFN)_PR_InvalidStatus,
+ (PRAcceptFN)_PR_InvalidDesc,
+ (PRBindFN)_PR_InvalidStatus,
+ (PRListenFN)_PR_InvalidStatus,
+ (PRShutdownFN)_PR_InvalidStatus,
+ (PRRecvFN)_PR_InvalidInt,
+ (PRSendFN)_PR_InvalidInt,
+ (PRRecvfromFN)_PR_InvalidInt,
+ (PRSendtoFN)_PR_InvalidInt,
+ pt_Poll,
+ (PRAcceptreadFN)_PR_InvalidInt,
+ (PRTransmitfileFN)_PR_InvalidInt,
+ (PRGetsocknameFN)_PR_InvalidStatus,
+ (PRGetpeernameFN)_PR_InvalidStatus,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
(PRGetsocketoptionFN)_PR_InvalidStatus,
(PRSetsocketoptionFN)_PR_InvalidStatus,
- (PRSendfileFN)_PR_InvalidInt,
- (PRConnectcontinueFN)_PR_InvalidStatus,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
- (PRReservedFN)_PR_InvalidInt,
+ (PRSendfileFN)_PR_InvalidInt,
+ (PRConnectcontinueFN)_PR_InvalidStatus,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
(PRReservedFN)_PR_InvalidInt
};
-#if defined(HPUX) || defined(OSF1) || defined(SOLARIS) || defined (IRIX) \
+#if defined(HPUX) || defined(SOLARIS) \
|| defined(LINUX) || defined(__GNU__) || defined(__GLIBC__) \
|| defined(AIX) || defined(FREEBSD) || defined(NETBSD) \
|| defined(OPENBSD) || defined(BSDI) || defined(NTO) \
- || defined(DARWIN) || defined(UNIXWARE) || defined(RISCOS) \
- || defined(SYMBIAN)
+ || defined(DARWIN) || defined(UNIXWARE) || defined(RISCOS)
#define _PR_FCNTL_FLAGS O_NONBLOCK
#else
#error "Can't determine architecture"
@@ -3402,13 +3522,17 @@ static PRFileDesc *pt_SetMethods(
PRIntn osfd, PRDescType type, PRBool isAcceptedSocket, PRBool imported)
{
PRFileDesc *fd = _PR_Getfd();
-
- if (fd == NULL) PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+
+ if (fd == NULL) {
+ PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+ }
else
{
fd->secret->md.osfd = osfd;
fd->secret->state = _PR_FILEDESC_OPEN;
- if (imported) fd->secret->inheritable = _PR_TRI_UNKNOWN;
+ if (imported) {
+ fd->secret->inheritable = _PR_TRI_UNKNOWN;
+ }
else
{
/* By default, a Unix fd is not closed on exec. */
@@ -3427,7 +3551,9 @@ static PRFileDesc *pt_SetMethods(
case PR_DESC_SOCKET_TCP:
fd->methods = PR_GetTCPMethods();
#ifdef _PR_ACCEPT_INHERIT_NONBLOCK
- if (!isAcceptedSocket) pt_MakeSocketNonblock(osfd);
+ if (!isAcceptedSocket) {
+ pt_MakeSocketNonblock(osfd);
+ }
#else
pt_MakeSocketNonblock(osfd);
#endif
@@ -3477,7 +3603,9 @@ PR_IMPLEMENT(PRFileDesc*) PR_AllocFileDesc(
{
PRFileDesc *fd = _PR_Getfd();
- if (NULL == fd) goto failed;
+ if (NULL == fd) {
+ goto failed;
+ }
fd->methods = methods;
fd->secret->md.osfd = osfd;
@@ -3485,13 +3613,17 @@ PR_IMPLEMENT(PRFileDesc*) PR_AllocFileDesc(
if (osfd > 2)
{
/* Don't mess around with stdin, stdout or stderr */
- if (&_pr_tcp_methods == methods) pt_MakeSocketNonblock(osfd);
- else pt_MakeFdNonblock(osfd);
+ if (&_pr_tcp_methods == methods) {
+ pt_MakeSocketNonblock(osfd);
+ }
+ else {
+ pt_MakeFdNonblock(osfd);
+ }
}
fd->secret->state = _PR_FILEDESC_OPEN;
fd->secret->inheritable = _PR_TRI_UNKNOWN;
return fd;
-
+
failed:
PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
return fd;
@@ -3512,8 +3644,9 @@ PR_IMPLEMENT(PRBool) _pr_test_ipv6_socket()
*/
{
struct utsname u;
- if (uname(&u) != 0 || atoi(u.release) < 7)
+ if (uname(&u) != 0 || atoi(u.release) < 7) {
return PR_FALSE;
+ }
}
#endif
@@ -3530,7 +3663,7 @@ PR_IMPLEMENT(PRBool) _pr_test_ipv6_socket()
}
return PR_FALSE;
}
-#endif /* _PR_INET6_PROBE */
+#endif /* _PR_INET6_PROBE */
#endif
PR_IMPLEMENT(PRFileDesc*) PR_Socket(PRInt32 domain, PRInt32 type, PRInt32 proto)
@@ -3542,9 +3675,13 @@ PR_IMPLEMENT(PRFileDesc*) PR_Socket(PRInt32 domain, PRInt32 type, PRInt32 proto)
PRInt32 tmp_domain = domain;
#endif
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
- if (pt_TestAbort()) return NULL;
+ if (pt_TestAbort()) {
+ return NULL;
+ }
if (PF_INET != domain
&& PR_AF_INET6 != domain
@@ -3559,17 +3696,22 @@ PR_IMPLEMENT(PRFileDesc*) PR_Socket(PRInt32 domain, PRInt32 type, PRInt32 proto)
PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, 0);
return fd;
}
- if (type == SOCK_STREAM) ftype = PR_DESC_SOCKET_TCP;
- else if (type == SOCK_DGRAM) ftype = PR_DESC_SOCKET_UDP;
- else
- {
- (void)PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, 0);
- return fd;
- }
+ if (type == SOCK_STREAM) {
+ ftype = PR_DESC_SOCKET_TCP;
+ }
+ else if (type == SOCK_DGRAM) {
+ ftype = PR_DESC_SOCKET_UDP;
+ }
+ else
+ {
+ (void)PR_SetError(PR_ADDRESS_NOT_SUPPORTED_ERROR, 0);
+ return fd;
+ }
#if defined(_PR_HAVE_SDP)
#if defined(LINUX)
- if (PR_AF_INET_SDP == domain)
+ if (PR_AF_INET_SDP == domain) {
domain = AF_INET_SDP;
+ }
#elif defined(SOLARIS)
if (PR_AF_INET_SDP == domain) {
domain = AF_INET;
@@ -3581,18 +3723,23 @@ PR_IMPLEMENT(PRFileDesc*) PR_Socket(PRInt32 domain, PRInt32 type, PRInt32 proto)
#endif /* SOLARIS */
#endif /* _PR_HAVE_SDP */
#if defined(_PR_INET6_PROBE)
- if (PR_AF_INET6 == domain)
- domain = _pr_ipv6_is_present() ? AF_INET6 : AF_INET;
-#elif defined(_PR_INET6)
- if (PR_AF_INET6 == domain)
- domain = AF_INET6;
+ if (PR_AF_INET6 == domain) {
+ domain = _pr_ipv6_is_present() ? AF_INET6 : AF_INET;
+ }
+#elif defined(_PR_INET6)
+ if (PR_AF_INET6 == domain) {
+ domain = AF_INET6;
+ }
#else
- if (PR_AF_INET6 == domain)
- domain = AF_INET;
+ if (PR_AF_INET6 == domain) {
+ domain = AF_INET;
+ }
#endif
osfd = socket(domain, type, proto);
- if (osfd == -1) pt_MapError(_PR_MD_MAP_SOCKET_ERROR, errno);
+ if (osfd == -1) {
+ pt_MapError(_PR_MD_MAP_SOCKET_ERROR, errno);
+ }
else
{
#ifdef _PR_IPV6_V6ONLY_PROBE
@@ -3600,28 +3747,32 @@ PR_IMPLEMENT(PRFileDesc*) PR_Socket(PRInt32 domain, PRInt32 type, PRInt32 proto)
{
int on = 0;
(void)setsockopt(osfd, IPPROTO_IPV6, IPV6_V6ONLY,
- &on, sizeof(on));
+ &on, sizeof(on));
}
#endif
fd = pt_SetMethods(osfd, ftype, PR_FALSE, PR_FALSE);
- if (fd == NULL) close(osfd);
+ if (fd == NULL) {
+ close(osfd);
+ }
}
#ifdef _PR_NEED_SECRET_AF
- if (fd != NULL) fd->secret->af = domain;
+ if (fd != NULL) {
+ fd->secret->af = domain;
+ }
#endif
#if defined(_PR_INET6_PROBE) || !defined(_PR_INET6)
- if (fd != NULL) {
- /*
- * For platforms with no support for IPv6
- * create layered socket for IPv4-mapped IPv6 addresses
- */
- if (PR_AF_INET6 == tmp_domain && PR_AF_INET == domain) {
- if (PR_FAILURE == _pr_push_ipv6toipv4_layer(fd)) {
- PR_Close(fd);
- fd = NULL;
- }
- }
- }
+ if (fd != NULL) {
+ /*
+ * For platforms with no support for IPv6
+ * create layered socket for IPv4-mapped IPv6 addresses
+ */
+ if (PR_AF_INET6 == tmp_domain && PR_AF_INET == domain) {
+ if (PR_FAILURE == _pr_push_ipv6toipv4_layer(fd)) {
+ PR_Close(fd);
+ fd = NULL;
+ }
+ }
+ }
#endif
return fd;
} /* PR_Socket */
@@ -3636,16 +3787,32 @@ PR_IMPLEMENT(PRFileDesc*) PR_OpenFile(
PRFileDesc *fd = NULL;
PRIntn syserrno, osfd = -1, osflags = 0;;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
- if (pt_TestAbort()) return NULL;
+ if (pt_TestAbort()) {
+ return NULL;
+ }
- if (flags & PR_RDONLY) osflags |= O_RDONLY;
- if (flags & PR_WRONLY) osflags |= O_WRONLY;
- if (flags & PR_RDWR) osflags |= O_RDWR;
- if (flags & PR_APPEND) osflags |= O_APPEND;
- if (flags & PR_TRUNCATE) osflags |= O_TRUNC;
- if (flags & PR_EXCL) osflags |= O_EXCL;
+ if (flags & PR_RDONLY) {
+ osflags |= O_RDONLY;
+ }
+ if (flags & PR_WRONLY) {
+ osflags |= O_WRONLY;
+ }
+ if (flags & PR_RDWR) {
+ osflags |= O_RDWR;
+ }
+ if (flags & PR_APPEND) {
+ osflags |= O_APPEND;
+ }
+ if (flags & PR_TRUNCATE) {
+ osflags |= O_TRUNC;
+ }
+ if (flags & PR_EXCL) {
+ osflags |= O_EXCL;
+ }
if (flags & PR_SYNC)
{
#if defined(O_SYNC)
@@ -3665,22 +3832,27 @@ PR_IMPLEMENT(PRFileDesc*) PR_OpenFile(
if (flags & PR_CREATE_FILE)
{
osflags |= O_CREAT;
- if (NULL !=_pr_rename_lock)
+ if (NULL !=_pr_rename_lock) {
PR_Lock(_pr_rename_lock);
+ }
}
osfd = _md_iovector._open64(name, osflags, mode);
syserrno = errno;
- if ((flags & PR_CREATE_FILE) && (NULL !=_pr_rename_lock))
+ if ((flags & PR_CREATE_FILE) && (NULL !=_pr_rename_lock)) {
PR_Unlock(_pr_rename_lock);
+ }
- if (osfd == -1)
+ if (osfd == -1) {
pt_MapError(_PR_MD_MAP_OPEN_ERROR, syserrno);
+ }
else
{
fd = pt_SetMethods(osfd, PR_DESC_FILE, PR_FALSE, PR_FALSE);
- if (fd == NULL) close(osfd); /* $$$ whoops! this is bad $$$ */
+ if (fd == NULL) {
+ close(osfd); /* $$$ whoops! this is bad $$$ */
+ }
}
return fd;
} /* PR_OpenFile */
@@ -3694,9 +3866,13 @@ PR_IMPLEMENT(PRStatus) PR_Delete(const char *name)
{
PRIntn rv = -1;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
- if (pt_TestAbort()) return PR_FAILURE;
+ if (pt_TestAbort()) {
+ return PR_FAILURE;
+ }
rv = unlink(name);
@@ -3711,24 +3887,28 @@ PR_IMPLEMENT(PRStatus) PR_Access(const char *name, PRAccessHow how)
{
PRIntn rv;
- if (pt_TestAbort()) return PR_FAILURE;
+ if (pt_TestAbort()) {
+ return PR_FAILURE;
+ }
switch (how)
{
- case PR_ACCESS_READ_OK:
- rv = access(name, R_OK);
- break;
- case PR_ACCESS_WRITE_OK:
- rv = access(name, W_OK);
- break;
- case PR_ACCESS_EXISTS:
- default:
- rv = access(name, F_OK);
+ case PR_ACCESS_READ_OK:
+ rv = access(name, R_OK);
+ break;
+ case PR_ACCESS_WRITE_OK:
+ rv = access(name, W_OK);
+ break;
+ case PR_ACCESS_EXISTS:
+ default:
+ rv = access(name, F_OK);
+ }
+ if (0 == rv) {
+ return PR_SUCCESS;
}
- if (0 == rv) return PR_SUCCESS;
pt_MapError(_PR_MD_MAP_ACCESS_ERROR, errno);
return PR_FAILURE;
-
+
} /* PR_Access */
PR_IMPLEMENT(PRStatus) PR_GetFileInfo(const char *fn, PRFileInfo *info)
@@ -3741,7 +3921,9 @@ PR_IMPLEMENT(PRStatus) PR_GetFileInfo64(const char *fn, PRFileInfo64 *info)
{
PRInt32 rv;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
rv = _PR_MD_GETFILEINFO64(fn, info);
return (0 == rv) ? PR_SUCCESS : PR_FAILURE;
} /* PR_GetFileInfo64 */
@@ -3750,13 +3932,15 @@ PR_IMPLEMENT(PRStatus) PR_Rename(const char *from, const char *to)
{
PRIntn rv = -1;
- if (pt_TestAbort()) return PR_FAILURE;
+ if (pt_TestAbort()) {
+ return PR_FAILURE;
+ }
/*
** We have to acquire a lock here to stiffle anybody trying to create
** a new file at the same time. And we have to hold that lock while we
** test to see if the file exists and do the rename. The other place
- ** where the lock is held is in PR_Open() when possibly creating a
+ ** where the lock is held is in PR_Open() when possibly creating a
** new file.
*/
@@ -3770,8 +3954,9 @@ PR_IMPLEMENT(PRStatus) PR_Rename(const char *from, const char *to)
else
{
rv = rename(from, to);
- if (rv == -1)
+ if (rv == -1) {
pt_MapError(_PR_MD_MAP_RENAME_ERROR, errno);
+ }
}
PR_Unlock(_pr_rename_lock);
return (-1 == rv) ? PR_FAILURE : PR_SUCCESS;
@@ -3779,7 +3964,9 @@ PR_IMPLEMENT(PRStatus) PR_Rename(const char *from, const char *to)
PR_IMPLEMENT(PRStatus) PR_CloseDir(PRDir *dir)
{
- if (pt_TestAbort()) return PR_FAILURE;
+ if (pt_TestAbort()) {
+ return PR_FAILURE;
+ }
if (NULL != dir->md.d)
{
@@ -3798,19 +3985,24 @@ PR_IMPLEMENT(PRStatus) PR_MakeDir(const char *name, PRIntn mode)
{
PRInt32 rv = -1;
- if (pt_TestAbort()) return PR_FAILURE;
+ if (pt_TestAbort()) {
+ return PR_FAILURE;
+ }
/*
** This lock is used to enforce rename semantics as described
** in PR_Rename.
*/
- if (NULL !=_pr_rename_lock)
+ if (NULL !=_pr_rename_lock) {
PR_Lock(_pr_rename_lock);
+ }
rv = mkdir(name, mode);
- if (-1 == rv)
+ if (-1 == rv) {
pt_MapError(_PR_MD_MAP_MKDIR_ERROR, errno);
- if (NULL !=_pr_rename_lock)
+ }
+ if (NULL !=_pr_rename_lock) {
PR_Unlock(_pr_rename_lock);
+ }
return (-1 == rv) ? PR_FAILURE : PR_SUCCESS;
} /* PR_Makedir */
@@ -3824,7 +4016,9 @@ PR_IMPLEMENT(PRStatus) PR_RmDir(const char *name)
{
PRInt32 rv;
- if (pt_TestAbort()) return PR_FAILURE;
+ if (pt_TestAbort()) {
+ return PR_FAILURE;
+ }
rv = rmdir(name);
if (0 == rv) {
@@ -3840,18 +4034,23 @@ PR_IMPLEMENT(PRDir*) PR_OpenDir(const char *name)
DIR *osdir;
PRDir *dir = NULL;
- if (pt_TestAbort()) return dir;
+ if (pt_TestAbort()) {
+ return dir;
+ }
osdir = opendir(name);
- if (osdir == NULL)
+ if (osdir == NULL) {
pt_MapError(_PR_MD_MAP_OPENDIR_ERROR, errno);
+ }
else
{
dir = PR_NEWZAP(PRDir);
- if (dir)
+ if (dir) {
dir->md.d = osdir;
- else
+ }
+ else {
(void)closedir(osdir);
+ }
}
return dir;
} /* PR_OpenDir */
@@ -3867,9 +4066,13 @@ static PRInt32 _pr_poll_with_poll(
*/
PRIntervalTime start = 0, elapsed, remaining;
- if (pt_TestAbort()) return -1;
+ if (pt_TestAbort()) {
+ return -1;
+ }
- if (0 == npds) PR_Sleep(timeout);
+ if (0 == npds) {
+ PR_Sleep(timeout);
+ }
else
{
#define STACK_POLL_DESC_COUNT 64
@@ -3910,19 +4113,19 @@ static PRInt32 _pr_poll_with_poll(
if (pds[index].in_flags & PR_POLL_READ)
{
in_flags_read = (pds[index].fd->methods->poll)(
- pds[index].fd,
- pds[index].in_flags & ~PR_POLL_WRITE,
- &out_flags_read);
+ pds[index].fd,
+ pds[index].in_flags & ~PR_POLL_WRITE,
+ &out_flags_read);
}
if (pds[index].in_flags & PR_POLL_WRITE)
{
in_flags_write = (pds[index].fd->methods->poll)(
- pds[index].fd,
- pds[index].in_flags & ~PR_POLL_READ,
- &out_flags_write);
+ pds[index].fd,
+ pds[index].in_flags & ~PR_POLL_READ,
+ &out_flags_write);
}
if ((0 != (in_flags_read & out_flags_read))
- || (0 != (in_flags_write & out_flags_write)))
+ || (0 != (in_flags_write & out_flags_write)))
{
/* this one is ready right now */
if (0 == ready)
@@ -3946,12 +4149,12 @@ static PRInt32 _pr_poll_with_poll(
{
/* now locate the NSPR layer at the bottom of the stack */
PRFileDesc *bottom = PR_GetIdentitiesLayer(
- pds[index].fd, PR_NSPR_IO_LAYER);
+ pds[index].fd, PR_NSPR_IO_LAYER);
/* ignore a socket without PR_NSPR_IO_LAYER available */
pds[index].out_flags = 0; /* pre-condition */
if ((NULL != bottom)
- && (_PR_FILEDESC_OPEN == bottom->secret->state))
+ && (_PR_FILEDESC_OPEN == bottom->secret->state))
{
if (0 == ready)
{
@@ -3981,8 +4184,9 @@ static PRInt32 _pr_poll_with_poll(
_PR_POLL_WRITE_SYS_WRITE;
syspoll[index].events |= POLLOUT;
}
- if (pds[index].in_flags & PR_POLL_EXCEPT)
+ if (pds[index].in_flags & PR_POLL_EXCEPT) {
syspoll[index].events |= POLLPRI;
+ }
}
}
else
@@ -4012,11 +4216,11 @@ static PRInt32 _pr_poll_with_poll(
{
switch (timeout)
{
- case PR_INTERVAL_NO_WAIT: msecs = 0; break;
- case PR_INTERVAL_NO_TIMEOUT: msecs = -1; break;
- default:
- msecs = PR_IntervalToMilliseconds(timeout);
- start = PR_IntervalNow();
+ case PR_INTERVAL_NO_WAIT: msecs = 0; break;
+ case PR_INTERVAL_NO_TIMEOUT: msecs = -1; break;
+ default:
+ msecs = PR_IntervalToMilliseconds(timeout);
+ start = PR_IntervalNow();
}
retry:
@@ -4027,16 +4231,19 @@ retry:
if (EINTR == oserror)
{
- if (timeout == PR_INTERVAL_NO_TIMEOUT)
+ if (timeout == PR_INTERVAL_NO_TIMEOUT) {
goto retry;
- else if (timeout == PR_INTERVAL_NO_WAIT)
- ready = 0; /* don't retry, just time out */
+ }
+ else if (timeout == PR_INTERVAL_NO_WAIT) {
+ ready = 0; /* don't retry, just time out */
+ }
else
{
elapsed = (PRIntervalTime) (PR_IntervalNow()
- - start);
- if (elapsed > timeout)
- ready = 0; /* timed out */
+ - start);
+ if (elapsed > timeout) {
+ ready = 0; /* timed out */
+ }
else
{
remaining = timeout - elapsed;
@@ -4062,12 +4269,12 @@ retry:
if (syspoll[index].revents & POLLIN)
{
if (pds[index].out_flags
- & _PR_POLL_READ_SYS_READ)
+ & _PR_POLL_READ_SYS_READ)
{
out_flags |= PR_POLL_READ;
}
if (pds[index].out_flags
- & _PR_POLL_WRITE_SYS_READ)
+ & _PR_POLL_WRITE_SYS_READ)
{
out_flags |= PR_POLL_WRITE;
}
@@ -4075,24 +4282,28 @@ retry:
if (syspoll[index].revents & POLLOUT)
{
if (pds[index].out_flags
- & _PR_POLL_READ_SYS_WRITE)
+ & _PR_POLL_READ_SYS_WRITE)
{
out_flags |= PR_POLL_READ;
}
if (pds[index].out_flags
- & _PR_POLL_WRITE_SYS_WRITE)
+ & _PR_POLL_WRITE_SYS_WRITE)
{
out_flags |= PR_POLL_WRITE;
}
}
- if (syspoll[index].revents & POLLPRI)
+ if (syspoll[index].revents & POLLPRI) {
out_flags |= PR_POLL_EXCEPT;
- if (syspoll[index].revents & POLLERR)
+ }
+ if (syspoll[index].revents & POLLERR) {
out_flags |= PR_POLL_ERR;
- if (syspoll[index].revents & POLLNVAL)
+ }
+ if (syspoll[index].revents & POLLNVAL) {
out_flags |= PR_POLL_NVAL;
- if (syspoll[index].revents & POLLHUP)
+ }
+ if (syspoll[index].revents & POLLHUP) {
out_flags |= PR_POLL_HUP;
+ }
}
}
pds[index].out_flags = out_flags;
@@ -4106,7 +4317,7 @@ retry:
#if defined(_PR_POLL_WITH_SELECT)
/*
- * OSF1 and HPUX report the POLLHUP event for a socket when the
+ * HPUX report the POLLHUP event for a socket when the
* shutdown(SHUT_WR) operation is called for the remote end, even though
* the socket is still writeable. Use select(), instead of poll(), to
* workaround this problem.
@@ -4122,16 +4333,20 @@ static PRInt32 _pr_poll_with_select(
*/
PRIntervalTime start = 0, elapsed, remaining;
- if (pt_TestAbort()) return -1;
+ if (pt_TestAbort()) {
+ return -1;
+ }
- if (0 == npds) PR_Sleep(timeout);
+ if (0 == npds) {
+ PR_Sleep(timeout);
+ }
else
{
#define STACK_POLL_DESC_COUNT 64
int stack_selectfd[STACK_POLL_DESC_COUNT];
int *selectfd;
- fd_set rd, wr, ex, *rdp = NULL, *wrp = NULL, *exp = NULL;
- struct timeval tv, *tvp;
+ fd_set rd, wr, ex, *rdp = NULL, *wrp = NULL, *exp = NULL;
+ struct timeval tv, *tvp;
PRIntn index, msecs, maxfd = 0;
if (npds <= STACK_POLL_DESC_COUNT)
@@ -4155,9 +4370,9 @@ static PRInt32 _pr_poll_with_select(
}
selectfd = me->selectfd_list;
}
- FD_ZERO(&rd);
- FD_ZERO(&wr);
- FD_ZERO(&ex);
+ FD_ZERO(&rd);
+ FD_ZERO(&wr);
+ FD_ZERO(&ex);
for (index = 0; index < npds; ++index)
{
@@ -4169,19 +4384,19 @@ static PRInt32 _pr_poll_with_select(
if (pds[index].in_flags & PR_POLL_READ)
{
in_flags_read = (pds[index].fd->methods->poll)(
- pds[index].fd,
- pds[index].in_flags & ~PR_POLL_WRITE,
- &out_flags_read);
+ pds[index].fd,
+ pds[index].in_flags & ~PR_POLL_WRITE,
+ &out_flags_read);
}
if (pds[index].in_flags & PR_POLL_WRITE)
{
in_flags_write = (pds[index].fd->methods->poll)(
- pds[index].fd,
- pds[index].in_flags & ~PR_POLL_READ,
- &out_flags_write);
+ pds[index].fd,
+ pds[index].in_flags & ~PR_POLL_READ,
+ &out_flags_write);
}
if ((0 != (in_flags_read & out_flags_read))
- || (0 != (in_flags_write & out_flags_write)))
+ || (0 != (in_flags_write & out_flags_write)))
{
/* this one is ready right now */
if (0 == ready)
@@ -4205,12 +4420,12 @@ static PRInt32 _pr_poll_with_select(
{
/* now locate the NSPR layer at the bottom of the stack */
PRFileDesc *bottom = PR_GetIdentitiesLayer(
- pds[index].fd, PR_NSPR_IO_LAYER);
+ pds[index].fd, PR_NSPR_IO_LAYER);
/* ignore a socket without PR_NSPR_IO_LAYER available */
pds[index].out_flags = 0; /* pre-condition */
if ((NULL != bottom)
- && (_PR_FILEDESC_OPEN == bottom->secret->state))
+ && (_PR_FILEDESC_OPEN == bottom->secret->state))
{
if (0 == ready)
{
@@ -4248,15 +4463,16 @@ static PRInt32 _pr_poll_with_select(
add_to_ex = PR_TRUE;
}
if ((selectfd[index] > maxfd) &&
- (add_to_rd || add_to_wr || add_to_ex))
+ (add_to_rd || add_to_wr || add_to_ex))
{
maxfd = selectfd[index];
/*
* If maxfd is too large to be used with
* select, fall back to calling poll.
*/
- if (maxfd >= FD_SETSIZE)
+ if (maxfd >= FD_SETSIZE) {
break;
+ }
}
if (add_to_rd)
{
@@ -4297,30 +4513,30 @@ static PRInt32 _pr_poll_with_select(
}
if (0 == ready)
{
- if (maxfd >= FD_SETSIZE)
- {
- /*
- * maxfd too large to be used with select, fall back to
- * calling poll
- */
- return(_pr_poll_with_poll(pds, npds, timeout));
- }
+ if (maxfd >= FD_SETSIZE)
+ {
+ /*
+ * maxfd too large to be used with select, fall back to
+ * calling poll
+ */
+ return(_pr_poll_with_poll(pds, npds, timeout));
+ }
switch (timeout)
{
- case PR_INTERVAL_NO_WAIT:
- tv.tv_sec = 0;
- tv.tv_usec = 0;
- tvp = &tv;
- break;
- case PR_INTERVAL_NO_TIMEOUT:
- tvp = NULL;
- break;
- default:
- msecs = PR_IntervalToMilliseconds(timeout);
- tv.tv_sec = msecs/PR_MSEC_PER_SEC;
- tv.tv_usec = (msecs % PR_MSEC_PER_SEC) * PR_USEC_PER_MSEC;
- tvp = &tv;
- start = PR_IntervalNow();
+ case PR_INTERVAL_NO_WAIT:
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+ tvp = &tv;
+ break;
+ case PR_INTERVAL_NO_TIMEOUT:
+ tvp = NULL;
+ break;
+ default:
+ msecs = PR_IntervalToMilliseconds(timeout);
+ tv.tv_sec = msecs/PR_MSEC_PER_SEC;
+ tv.tv_usec = (msecs % PR_MSEC_PER_SEC) * PR_USEC_PER_MSEC;
+ tvp = &tv;
+ start = PR_IntervalNow();
}
retry:
@@ -4331,45 +4547,49 @@ retry:
if ((EINTR == oserror) || (EAGAIN == oserror))
{
- if (timeout == PR_INTERVAL_NO_TIMEOUT)
+ if (timeout == PR_INTERVAL_NO_TIMEOUT) {
goto retry;
- else if (timeout == PR_INTERVAL_NO_WAIT)
- ready = 0; /* don't retry, just time out */
+ }
+ else if (timeout == PR_INTERVAL_NO_WAIT) {
+ ready = 0; /* don't retry, just time out */
+ }
else
{
elapsed = (PRIntervalTime) (PR_IntervalNow()
- - start);
- if (elapsed > timeout)
- ready = 0; /* timed out */
+ - start);
+ if (elapsed > timeout) {
+ ready = 0; /* timed out */
+ }
else
{
remaining = timeout - elapsed;
msecs = PR_IntervalToMilliseconds(remaining);
- tv.tv_sec = msecs/PR_MSEC_PER_SEC;
- tv.tv_usec = (msecs % PR_MSEC_PER_SEC) *
- PR_USEC_PER_MSEC;
+ tv.tv_sec = msecs/PR_MSEC_PER_SEC;
+ tv.tv_usec = (msecs % PR_MSEC_PER_SEC) *
+ PR_USEC_PER_MSEC;
goto retry;
}
}
} else if (EBADF == oserror)
{
- /* find all the bad fds */
- ready = 0;
- for (index = 0; index < npds; ++index)
- {
- pds[index].out_flags = 0;
- if ((NULL != pds[index].fd) &&
- (0 != pds[index].in_flags))
- {
- if (fcntl(selectfd[index], F_GETFL, 0) == -1)
- {
- pds[index].out_flags = PR_POLL_NVAL;
- ready++;
- }
- }
- }
- } else
+ /* find all the bad fds */
+ ready = 0;
+ for (index = 0; index < npds; ++index)
+ {
+ pds[index].out_flags = 0;
+ if ((NULL != pds[index].fd) &&
+ (0 != pds[index].in_flags))
+ {
+ if (fcntl(selectfd[index], F_GETFL, 0) == -1)
+ {
+ pds[index].out_flags = PR_POLL_NVAL;
+ ready++;
+ }
+ }
+ }
+ } else {
_PR_MD_MAP_SELECT_ERROR(oserror);
+ }
}
else if (ready > 0)
{
@@ -4378,34 +4598,35 @@ retry:
PRInt16 out_flags = 0;
if ((NULL != pds[index].fd) && (0 != pds[index].in_flags))
{
- if (FD_ISSET(selectfd[index], &rd))
- {
- if (pds[index].out_flags
- & _PR_POLL_READ_SYS_READ)
- {
- out_flags |= PR_POLL_READ;
- }
- if (pds[index].out_flags
- & _PR_POLL_WRITE_SYS_READ)
- {
- out_flags |= PR_POLL_WRITE;
- }
- }
- if (FD_ISSET(selectfd[index], &wr))
- {
- if (pds[index].out_flags
- & _PR_POLL_READ_SYS_WRITE)
- {
- out_flags |= PR_POLL_READ;
- }
- if (pds[index].out_flags
- & _PR_POLL_WRITE_SYS_WRITE)
- {
- out_flags |= PR_POLL_WRITE;
- }
- }
- if (FD_ISSET(selectfd[index], &ex))
- out_flags |= PR_POLL_EXCEPT;
+ if (FD_ISSET(selectfd[index], &rd))
+ {
+ if (pds[index].out_flags
+ & _PR_POLL_READ_SYS_READ)
+ {
+ out_flags |= PR_POLL_READ;
+ }
+ if (pds[index].out_flags
+ & _PR_POLL_WRITE_SYS_READ)
+ {
+ out_flags |= PR_POLL_WRITE;
+ }
+ }
+ if (FD_ISSET(selectfd[index], &wr))
+ {
+ if (pds[index].out_flags
+ & _PR_POLL_READ_SYS_WRITE)
+ {
+ out_flags |= PR_POLL_READ;
+ }
+ if (pds[index].out_flags
+ & _PR_POLL_WRITE_SYS_WRITE)
+ {
+ out_flags |= PR_POLL_WRITE;
+ }
+ }
+ if (FD_ISSET(selectfd[index], &ex)) {
+ out_flags |= PR_POLL_EXCEPT;
+ }
}
pds[index].out_flags = out_flags;
}
@@ -4415,15 +4636,15 @@ retry:
return ready;
} /* _pr_poll_with_select */
-#endif /* _PR_POLL_WITH_SELECT */
+#endif /* _PR_POLL_WITH_SELECT */
PR_IMPLEMENT(PRInt32) PR_Poll(
PRPollDesc *pds, PRIntn npds, PRIntervalTime timeout)
{
#if defined(_PR_POLL_WITH_SELECT)
- return(_pr_poll_with_select(pds, npds, timeout));
+ return(_pr_poll_with_select(pds, npds, timeout));
#else
- return(_pr_poll_with_poll(pds, npds, timeout));
+ return(_pr_poll_with_poll(pds, npds, timeout));
#endif
}
@@ -4431,7 +4652,9 @@ PR_IMPLEMENT(PRDirEntry*) PR_ReadDir(PRDir *dir, PRDirFlags flags)
{
struct dirent *dp;
- if (pt_TestAbort()) return NULL;
+ if (pt_TestAbort()) {
+ return NULL;
+ }
for (;;)
{
@@ -4444,13 +4667,18 @@ PR_IMPLEMENT(PRDirEntry*) PR_ReadDir(PRDir *dir, PRDirFlags flags)
}
if ((flags & PR_SKIP_DOT)
&& ('.' == dp->d_name[0])
- && (0 == dp->d_name[1])) continue;
+ && (0 == dp->d_name[1])) {
+ continue;
+ }
if ((flags & PR_SKIP_DOT_DOT)
&& ('.' == dp->d_name[0])
&& ('.' == dp->d_name[1])
- && (0 == dp->d_name[2])) continue;
- if ((flags & PR_SKIP_HIDDEN) && ('.' == dp->d_name[0]))
+ && (0 == dp->d_name[2])) {
+ continue;
+ }
+ if ((flags & PR_SKIP_HIDDEN) && ('.' == dp->d_name[0])) {
continue;
+ }
break;
}
dir->d.name = dp->d_name;
@@ -4483,87 +4711,11 @@ PR_IMPLEMENT(PRFileDesc*) PR_OpenTCPSocket(PRIntn af)
PR_IMPLEMENT(PRStatus) PR_NewTCPSocketPair(PRFileDesc *fds[2])
{
-#ifdef SYMBIAN
- /*
- * For the platforms that don't have socketpair.
- *
- * Copied from prsocket.c, with the parameter f[] renamed fds[] and the
- * _PR_CONNECT_DOES_NOT_BIND code removed.
- */
- PRFileDesc *listenSock;
- PRNetAddr selfAddr, peerAddr;
- PRUint16 port;
-
- fds[0] = fds[1] = NULL;
- listenSock = PR_NewTCPSocket();
- if (listenSock == NULL) {
- goto failed;
- }
- PR_InitializeNetAddr(PR_IpAddrLoopback, 0, &selfAddr); /* BugZilla: 35408 */
- if (PR_Bind(listenSock, &selfAddr) == PR_FAILURE) {
- goto failed;
- }
- if (PR_GetSockName(listenSock, &selfAddr) == PR_FAILURE) {
- goto failed;
- }
- port = ntohs(selfAddr.inet.port);
- if (PR_Listen(listenSock, 5) == PR_FAILURE) {
- goto failed;
- }
- fds[0] = PR_NewTCPSocket();
- if (fds[0] == NULL) {
- goto failed;
- }
- PR_InitializeNetAddr(PR_IpAddrLoopback, port, &selfAddr);
-
- /*
- * Only a thread is used to do the connect and accept.
- * I am relying on the fact that PR_Connect returns
- * successfully as soon as the connect request is put
- * into the listen queue (but before PR_Accept is called).
- * This is the behavior of the BSD socket code. If
- * connect does not return until accept is called, we
- * will need to create another thread to call connect.
- */
- if (PR_Connect(fds[0], &selfAddr, PR_INTERVAL_NO_TIMEOUT)
- == PR_FAILURE) {
- goto failed;
- }
- /*
- * A malicious local process may connect to the listening
- * socket, so we need to verify that the accepted connection
- * is made from our own socket fds[0].
- */
- if (PR_GetSockName(fds[0], &selfAddr) == PR_FAILURE) {
- goto failed;
- }
- fds[1] = PR_Accept(listenSock, &peerAddr, PR_INTERVAL_NO_TIMEOUT);
- if (fds[1] == NULL) {
- goto failed;
- }
- if (peerAddr.inet.port != selfAddr.inet.port) {
- /* the connection we accepted is not from fds[0] */
- PR_SetError(PR_INSUFFICIENT_RESOURCES_ERROR, 0);
- goto failed;
- }
- PR_Close(listenSock);
- return PR_SUCCESS;
-
-failed:
- if (listenSock) {
- PR_Close(listenSock);
- }
- if (fds[0]) {
- PR_Close(fds[0]);
- }
- if (fds[1]) {
- PR_Close(fds[1]);
- }
- return PR_FAILURE;
-#else
PRInt32 osfd[2];
- if (pt_TestAbort()) return PR_FAILURE;
+ if (pt_TestAbort()) {
+ return PR_FAILURE;
+ }
if (socketpair(AF_UNIX, SOCK_STREAM, 0, osfd) == -1) {
pt_MapError(_PR_MD_MAP_SOCKETPAIR_ERROR, errno);
@@ -4583,7 +4735,6 @@ failed:
return PR_FAILURE;
}
return PR_SUCCESS;
-#endif
} /* PR_NewTCPSocketPair */
PR_IMPLEMENT(PRStatus) PR_CreatePipe(
@@ -4593,11 +4744,13 @@ PR_IMPLEMENT(PRStatus) PR_CreatePipe(
{
int pipefd[2];
- if (pt_TestAbort()) return PR_FAILURE;
+ if (pt_TestAbort()) {
+ return PR_FAILURE;
+ }
if (pipe(pipefd) == -1)
{
- /* XXX map pipe error */
+ /* XXX map pipe error */
PR_SetError(PR_UNKNOWN_ERROR, errno);
return PR_FAILURE;
}
@@ -4637,7 +4790,7 @@ PR_IMPLEMENT(PRStatus) PR_SetFDInheritable(
if (fd->secret->inheritable != inheritable)
{
if (fcntl(fd->secret->md.osfd, F_SETFD,
- inheritable ? 0 : FD_CLOEXEC) == -1)
+ inheritable ? 0 : FD_CLOEXEC) == -1)
{
_PR_MD_MAP_DEFAULT_ERROR(errno);
return PR_FAILURE;
@@ -4655,9 +4808,13 @@ PR_IMPLEMENT(PRFileDesc*) PR_ImportFile(PRInt32 osfd)
{
PRFileDesc *fd;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
fd = pt_SetMethods(osfd, PR_DESC_FILE, PR_FALSE, PR_TRUE);
- if (NULL == fd) close(osfd);
+ if (NULL == fd) {
+ close(osfd);
+ }
return fd;
} /* PR_ImportFile */
@@ -4665,9 +4822,13 @@ PR_IMPLEMENT(PRFileDesc*) PR_ImportPipe(PRInt32 osfd)
{
PRFileDesc *fd;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
fd = pt_SetMethods(osfd, PR_DESC_PIPE, PR_FALSE, PR_TRUE);
- if (NULL == fd) close(osfd);
+ if (NULL == fd) {
+ close(osfd);
+ }
return fd;
} /* PR_ImportPipe */
@@ -4675,11 +4836,17 @@ PR_IMPLEMENT(PRFileDesc*) PR_ImportTCPSocket(PRInt32 osfd)
{
PRFileDesc *fd;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
fd = pt_SetMethods(osfd, PR_DESC_SOCKET_TCP, PR_FALSE, PR_TRUE);
- if (NULL == fd) close(osfd);
+ if (NULL == fd) {
+ close(osfd);
+ }
#ifdef _PR_NEED_SECRET_AF
- if (NULL != fd) fd->secret->af = PF_INET;
+ if (NULL != fd) {
+ fd->secret->af = PF_INET;
+ }
#endif
return fd;
} /* PR_ImportTCPSocket */
@@ -4688,9 +4855,13 @@ PR_IMPLEMENT(PRFileDesc*) PR_ImportUDPSocket(PRInt32 osfd)
{
PRFileDesc *fd;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
fd = pt_SetMethods(osfd, PR_DESC_SOCKET_UDP, PR_FALSE, PR_TRUE);
- if (NULL == fd) close(osfd);
+ if (NULL == fd) {
+ close(osfd);
+ }
return fd;
} /* PR_ImportUDPSocket */
@@ -4698,16 +4869,20 @@ PR_IMPLEMENT(PRFileDesc*) PR_CreateSocketPollFd(PRInt32 osfd)
{
PRFileDesc *fd;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
fd = _PR_Getfd();
- if (fd == NULL) PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+ if (fd == NULL) {
+ PR_SetError(PR_OUT_OF_MEMORY_ERROR, 0);
+ }
else
{
fd->secret->md.osfd = osfd;
fd->secret->inheritable = _PR_TRI_FALSE;
- fd->secret->state = _PR_FILEDESC_OPEN;
+ fd->secret->state = _PR_FILEDESC_OPEN;
fd->methods = PR_GetSocketPollFdMethods();
}
@@ -4730,27 +4905,36 @@ PR_IMPLEMENT(PRInt32) PR_FileDesc2NativeHandle(PRFileDesc *bottom)
{
PRInt32 osfd = -1;
bottom = (NULL == bottom) ?
- NULL : PR_GetIdentitiesLayer(bottom, PR_NSPR_IO_LAYER);
- if (NULL == bottom) PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
- else osfd = bottom->secret->md.osfd;
+ NULL : PR_GetIdentitiesLayer(bottom, PR_NSPR_IO_LAYER);
+ if (NULL == bottom) {
+ PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
+ }
+ else {
+ osfd = bottom->secret->md.osfd;
+ }
return osfd;
} /* PR_FileDesc2NativeHandle */
PR_IMPLEMENT(void) PR_ChangeFileDescNativeHandle(PRFileDesc *fd,
- PRInt32 handle)
+ PRInt32 handle)
{
- if (fd) fd->secret->md.osfd = handle;
+ if (fd) {
+ fd->secret->md.osfd = handle;
+ }
} /* PR_ChangeFileDescNativeHandle*/
PR_IMPLEMENT(PRStatus) PR_LockFile(PRFileDesc *fd)
{
PRStatus status = PR_SUCCESS;
- if (pt_TestAbort()) return PR_FAILURE;
+ if (pt_TestAbort()) {
+ return PR_FAILURE;
+ }
PR_Lock(_pr_flock_lock);
- while (-1 == fd->secret->lockCount)
+ while (-1 == fd->secret->lockCount) {
PR_WaitCondVar(_pr_flock_cv, PR_INTERVAL_NO_TIMEOUT);
+ }
if (0 == fd->secret->lockCount)
{
fd->secret->lockCount = -1;
@@ -4765,7 +4949,7 @@ PR_IMPLEMENT(PRStatus) PR_LockFile(PRFileDesc *fd)
fd->secret->lockCount += 1;
}
PR_Unlock(_pr_flock_lock);
-
+
return status;
} /* PR_LockFile */
@@ -4773,17 +4957,23 @@ PR_IMPLEMENT(PRStatus) PR_TLockFile(PRFileDesc *fd)
{
PRStatus status = PR_SUCCESS;
- if (pt_TestAbort()) return PR_FAILURE;
+ if (pt_TestAbort()) {
+ return PR_FAILURE;
+ }
PR_Lock(_pr_flock_lock);
if (0 == fd->secret->lockCount)
{
status = _PR_MD_TLOCKFILE(fd->secret->md.osfd);
- if (PR_SUCCESS == status) fd->secret->lockCount = 1;
+ if (PR_SUCCESS == status) {
+ fd->secret->lockCount = 1;
+ }
+ }
+ else {
+ fd->secret->lockCount += 1;
}
- else fd->secret->lockCount += 1;
PR_Unlock(_pr_flock_lock);
-
+
return status;
} /* PR_TLockFile */
@@ -4791,15 +4981,21 @@ PR_IMPLEMENT(PRStatus) PR_UnlockFile(PRFileDesc *fd)
{
PRStatus status = PR_SUCCESS;
- if (pt_TestAbort()) return PR_FAILURE;
+ if (pt_TestAbort()) {
+ return PR_FAILURE;
+ }
PR_Lock(_pr_flock_lock);
if (fd->secret->lockCount == 1)
{
status = _PR_MD_UNLOCKFILE(fd->secret->md.osfd);
- if (PR_SUCCESS == status) fd->secret->lockCount = 0;
+ if (PR_SUCCESS == status) {
+ fd->secret->lockCount = 0;
+ }
+ }
+ else {
+ fd->secret->lockCount -= 1;
}
- else fd->secret->lockCount -= 1;
PR_Unlock(_pr_flock_lock);
return status;
@@ -4812,13 +5008,14 @@ PR_IMPLEMENT(PRStatus) PR_UnlockFile(PRFileDesc *fd)
PR_IMPLEMENT(PRInt32) PR_GetSysfdTableMax(void)
{
-#if defined(AIX) || defined(SYMBIAN)
+#if defined(AIX)
return sysconf(_SC_OPEN_MAX);
#else
struct rlimit rlim;
- if ( getrlimit(RLIMIT_NOFILE, &rlim) < 0)
- return -1;
+ if ( getrlimit(RLIMIT_NOFILE, &rlim) < 0) {
+ return -1;
+ }
return rlim.rlim_max;
#endif
@@ -4826,23 +5023,28 @@ PR_IMPLEMENT(PRInt32) PR_GetSysfdTableMax(void)
PR_IMPLEMENT(PRInt32) PR_SetSysfdTableSize(PRIntn table_size)
{
-#if defined(AIX) || defined(SYMBIAN)
+#if defined(AIX)
return -1;
#else
struct rlimit rlim;
PRInt32 tableMax = PR_GetSysfdTableMax();
- if (tableMax < 0) return -1;
+ if (tableMax < 0) {
+ return -1;
+ }
rlim.rlim_max = tableMax;
/* Grow as much as we can; even if too big */
- if ( rlim.rlim_max < table_size )
+ if ( rlim.rlim_max < table_size ) {
rlim.rlim_cur = rlim.rlim_max;
- else
+ }
+ else {
rlim.rlim_cur = table_size;
+ }
- if ( setrlimit(RLIMIT_NOFILE, &rlim) < 0)
+ if ( setrlimit(RLIMIT_NOFILE, &rlim) < 0) {
return -1;
+ }
return rlim.rlim_cur;
#endif
@@ -4857,9 +5059,13 @@ PR_IMPLEMENT(PRInt32) PR_SetSysfdTableSize(PRIntn table_size)
PR_IMPLEMENT(PRInt32) PR_Stat(const char *name, struct stat *buf)
{
static PRBool unwarned = PR_TRUE;
- if (unwarned) unwarned = _PR_Obsolete("PR_Stat", "PR_GetFileInfo");
+ if (unwarned) {
+ unwarned = _PR_Obsolete("PR_Stat", "PR_GetFileInfo");
+ }
- if (pt_TestAbort()) return -1;
+ if (pt_TestAbort()) {
+ return -1;
+ }
if (-1 == stat(name, buf)) {
pt_MapError(_PR_MD_MAP_STAT_ERROR, errno);
@@ -4874,14 +5080,18 @@ PR_IMPLEMENT(PRInt32) PR_Stat(const char *name, struct stat *buf)
PR_IMPLEMENT(void) PR_FD_ZERO(PR_fd_set *set)
{
static PRBool unwarned = PR_TRUE;
- if (unwarned) unwarned = _PR_Obsolete("PR_FD_ZERO (PR_Select)", "PR_Poll");
+ if (unwarned) {
+ unwarned = _PR_Obsolete("PR_FD_ZERO (PR_Select)", "PR_Poll");
+ }
memset(set, 0, sizeof(PR_fd_set));
}
PR_IMPLEMENT(void) PR_FD_SET(PRFileDesc *fh, PR_fd_set *set)
{
static PRBool unwarned = PR_TRUE;
- if (unwarned) unwarned = _PR_Obsolete("PR_FD_SET (PR_Select)", "PR_Poll");
+ if (unwarned) {
+ unwarned = _PR_Obsolete("PR_FD_SET (PR_Select)", "PR_Poll");
+ }
PR_ASSERT( set->hsize < PR_MAX_SELECT_DESC );
set->harray[set->hsize++] = fh;
@@ -4891,34 +5101,40 @@ PR_IMPLEMENT(void) PR_FD_CLR(PRFileDesc *fh, PR_fd_set *set)
{
PRUint32 index, index2;
static PRBool unwarned = PR_TRUE;
- if (unwarned) unwarned = _PR_Obsolete("PR_FD_CLR (PR_Select)", "PR_Poll");
+ if (unwarned) {
+ unwarned = _PR_Obsolete("PR_FD_CLR (PR_Select)", "PR_Poll");
+ }
for (index = 0; index<set->hsize; index++)
- if (set->harray[index] == fh) {
- for (index2=index; index2 < (set->hsize-1); index2++) {
- set->harray[index2] = set->harray[index2+1];
- }
- set->hsize--;
- break;
- }
+ if (set->harray[index] == fh) {
+ for (index2=index; index2 < (set->hsize-1); index2++) {
+ set->harray[index2] = set->harray[index2+1];
+ }
+ set->hsize--;
+ break;
+ }
}
PR_IMPLEMENT(PRInt32) PR_FD_ISSET(PRFileDesc *fh, PR_fd_set *set)
{
PRUint32 index;
static PRBool unwarned = PR_TRUE;
- if (unwarned) unwarned = _PR_Obsolete("PR_FD_ISSET (PR_Select)", "PR_Poll");
+ if (unwarned) {
+ unwarned = _PR_Obsolete("PR_FD_ISSET (PR_Select)", "PR_Poll");
+ }
for (index = 0; index<set->hsize; index++)
- if (set->harray[index] == fh) {
- return 1;
- }
+ if (set->harray[index] == fh) {
+ return 1;
+ }
return 0;
}
PR_IMPLEMENT(void) PR_FD_NSET(PRInt32 fd, PR_fd_set *set)
{
static PRBool unwarned = PR_TRUE;
- if (unwarned) unwarned = _PR_Obsolete("PR_FD_NSET (PR_Select)", "PR_Poll");
+ if (unwarned) {
+ unwarned = _PR_Obsolete("PR_FD_NSET (PR_Select)", "PR_Poll");
+ }
PR_ASSERT( set->nsize < PR_MAX_SELECT_DESC );
set->narray[set->nsize++] = fd;
@@ -4928,27 +5144,31 @@ PR_IMPLEMENT(void) PR_FD_NCLR(PRInt32 fd, PR_fd_set *set)
{
PRUint32 index, index2;
static PRBool unwarned = PR_TRUE;
- if (unwarned) unwarned = _PR_Obsolete("PR_FD_NCLR (PR_Select)", "PR_Poll");
+ if (unwarned) {
+ unwarned = _PR_Obsolete("PR_FD_NCLR (PR_Select)", "PR_Poll");
+ }
for (index = 0; index<set->nsize; index++)
- if (set->narray[index] == fd) {
- for (index2=index; index2 < (set->nsize-1); index2++) {
- set->narray[index2] = set->narray[index2+1];
- }
- set->nsize--;
- break;
- }
+ if (set->narray[index] == fd) {
+ for (index2=index; index2 < (set->nsize-1); index2++) {
+ set->narray[index2] = set->narray[index2+1];
+ }
+ set->nsize--;
+ break;
+ }
}
PR_IMPLEMENT(PRInt32) PR_FD_NISSET(PRInt32 fd, PR_fd_set *set)
{
PRUint32 index;
static PRBool unwarned = PR_TRUE;
- if (unwarned) unwarned = _PR_Obsolete("PR_FD_NISSET (PR_Select)", "PR_Poll");
+ if (unwarned) {
+ unwarned = _PR_Obsolete("PR_FD_NISSET (PR_Select)", "PR_Poll");
+ }
for (index = 0; index<set->nsize; index++)
- if (set->narray[index] == fd) {
- return 1;
- }
+ if (set->narray[index] == fd) {
+ return 1;
+ }
return 0;
}
@@ -4965,22 +5185,25 @@ _PR_getset(PR_fd_set *pr_set, fd_set *set)
PRUint32 index;
PRInt32 max = 0;
- if (!pr_set)
+ if (!pr_set) {
return 0;
-
+ }
+
FD_ZERO(set);
/* First set the pr file handle osfds */
for (index=0; index<pr_set->hsize; index++) {
FD_SET(pr_set->harray[index]->secret->md.osfd, set);
- if (pr_set->harray[index]->secret->md.osfd > max)
+ if (pr_set->harray[index]->secret->md.osfd > max) {
max = pr_set->harray[index]->secret->md.osfd;
+ }
}
/* Second set the native osfds */
for (index=0; index<pr_set->nsize; index++) {
FD_SET(pr_set->narray[index], set);
- if (pr_set->narray[index] > max)
+ if (pr_set->narray[index] > max) {
max = pr_set->narray[index];
+ }
}
return max;
}
@@ -4990,8 +5213,9 @@ _PR_setset(PR_fd_set *pr_set, fd_set *set)
{
PRUint32 index, last_used;
- if (!pr_set)
+ if (!pr_set) {
return;
+ }
for (last_used=0, index=0; index<pr_set->hsize; index++) {
if ( FD_ISSET(pr_set->harray[index]->secret->md.osfd, set) ) {
@@ -5009,7 +5233,7 @@ _PR_setset(PR_fd_set *pr_set, fd_set *set)
}
PR_IMPLEMENT(PRInt32) PR_Select(
- PRInt32 unused, PR_fd_set *pr_rd, PR_fd_set *pr_wr,
+ PRInt32 unused, PR_fd_set *pr_rd, PR_fd_set *pr_wr,
PR_fd_set *pr_ex, PRIntervalTime timeout)
{
fd_set rd, wr, ex;
@@ -5024,7 +5248,9 @@ PR_IMPLEMENT(PRInt32) PR_Select(
PRIntervalTime start = 0, elapsed, remaining;
static PRBool unwarned = PR_TRUE;
- if (unwarned) unwarned = _PR_Obsolete( "PR_Select", "PR_Poll");
+ if (unwarned) {
+ unwarned = _PR_Obsolete( "PR_Select", "PR_Poll");
+ }
FD_ZERO(&rd);
FD_ZERO(&wr);
@@ -5039,14 +5265,14 @@ PR_IMPLEMENT(PRInt32) PR_Select(
} else {
tv.tv_sec = (PRInt32)PR_IntervalToSeconds(timeout);
tv.tv_usec = (PRInt32)PR_IntervalToMicroseconds(
- timeout - PR_SecondsToInterval(tv.tv_sec));
+ timeout - PR_SecondsToInterval(tv.tv_sec));
tvp = &tv;
start = PR_IntervalNow();
}
retry:
rv = select(max_fd + 1, (_PRSelectFdSetArg_t) &rd,
- (_PRSelectFdSetArg_t) &wr, (_PRSelectFdSetArg_t) &ex, tvp);
+ (_PRSelectFdSetArg_t) &wr, (_PRSelectFdSetArg_t) &ex, tvp);
if (rv == -1 && errno == EINTR) {
if (timeout == PR_INTERVAL_NO_TIMEOUT) {
@@ -5059,7 +5285,7 @@ retry:
remaining = timeout - elapsed;
tv.tv_sec = (PRInt32)PR_IntervalToSeconds(remaining);
tv.tv_usec = (PRInt32)PR_IntervalToMicroseconds(
- remaining - PR_SecondsToInterval(tv.tv_sec));
+ remaining - PR_SecondsToInterval(tv.tv_sec));
goto retry;
}
}
@@ -5076,7 +5302,7 @@ retry:
}
#endif /* defined(_PR_PTHREADS) */
-#ifdef MOZ_UNICODE
+#ifdef MOZ_UNICODE
/* ================ UTF16 Interfaces ================================ */
PR_IMPLEMENT(PRFileDesc*) PR_OpenFileUTF16(
const PRUnichar *name, PRIntn flags, PRIntn mode)
diff --git a/nsprpub/pr/src/pthreads/ptmisc.c b/nsprpub/pr/src/pthreads/ptmisc.c
index bbc6d56bc..4069f585a 100644
--- a/nsprpub/pr/src/pthreads/ptmisc.c
+++ b/nsprpub/pr/src/pthreads/ptmisc.c
@@ -19,20 +19,26 @@
#define PT_LOG(f)
-void _PR_InitCPUs(void) {PT_LOG("_PR_InitCPUs")}
-void _PR_InitStacks(void) {PT_LOG("_PR_InitStacks")}
+void _PR_InitCPUs(void) {
+ PT_LOG("_PR_InitCPUs")
+}
+void _PR_InitStacks(void) {
+ PT_LOG("_PR_InitStacks")
+}
-PR_IMPLEMENT(void) PR_SetConcurrency(PRUintn numCPUs)
+PR_IMPLEMENT(void) PR_SetConcurrency(PRUintn numCPUs)
{
#ifdef SOLARIS
- thr_setconcurrency(numCPUs);
+ thr_setconcurrency(numCPUs);
#else
- PT_LOG("PR_SetConcurrency");
+ PT_LOG("PR_SetConcurrency");
#endif
}
PR_IMPLEMENT(void) PR_SetThreadRecycleMode(PRUint32 flag)
- {PT_LOG("PR_SetThreadRecycleMode")}
+{
+ PT_LOG("PR_SetThreadRecycleMode")
+}
#endif /* defined(_PR_PTHREADS) */
diff --git a/nsprpub/pr/src/pthreads/ptsynch.c b/nsprpub/pr/src/pthreads/ptsynch.c
index 126bed670..26f58b2d0 100644
--- a/nsprpub/pr/src/pthreads/ptsynch.c
+++ b/nsprpub/pr/src/pthreads/ptsynch.c
@@ -47,7 +47,7 @@ pt_pthread_mutex_is_locked(pthread_mutex_t *m)
void _PR_InitLocks(void)
{
int rv;
- rv = _PT_PTHREAD_MUTEXATTR_INIT(&_pt_mattr);
+ rv = _PT_PTHREAD_MUTEXATTR_INIT(&_pt_mattr);
PR_ASSERT(0 == rv);
#if (defined(LINUX) && (__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)) || \
@@ -116,13 +116,16 @@ static void pt_PostNotifies(PRLock *lock, PRBool unlock)
PR_DestroyCondVar(cv);
}
#else /* defined(DEBUG) */
- if (0 > PR_ATOMIC_DECREMENT(&cv->notify_pending))
+ if (0 > PR_ATOMIC_DECREMENT(&cv->notify_pending)) {
PR_DestroyCondVar(cv);
+ }
#endif /* defined(DEBUG) */
}
prev = notified;
notified = notified->link;
- if (&post != prev) PR_DELETE(prev);
+ if (&post != prev) {
+ PR_DELETE(prev);
+ }
} while (NULL != notified);
} /* pt_PostNotifies */
@@ -131,12 +134,14 @@ PR_IMPLEMENT(PRLock*) PR_NewLock(void)
PRIntn rv;
PRLock *lock;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
lock = PR_NEWZAP(PRLock);
if (lock != NULL)
{
- rv = _PT_PTHREAD_MUTEX_INIT(lock->mutex, _pt_mattr);
+ rv = _PT_PTHREAD_MUTEX_INIT(lock->mutex, _pt_mattr);
PR_ASSERT(0 == rv);
}
#if defined(DEBUG)
@@ -174,7 +179,7 @@ PR_IMPLEMENT(void) PR_Lock(PRLock *lock)
PR_ASSERT(NULL == lock->notified.link);
PR_ASSERT(PR_FALSE == lock->locked);
/* Nb: the order of the next two statements is not critical to
- * the correctness of PR_AssertCurrentThreadOwnsLock(), but
+ * the correctness of PR_AssertCurrentThreadOwnsLock(), but
* this particular order makes the assertion more likely to
* catch errors. */
lock->owner = pthread_self();
@@ -194,8 +199,9 @@ PR_IMPLEMENT(PRStatus) PR_Unlock(PRLock *lock)
PR_ASSERT(PR_TRUE == lock->locked);
PR_ASSERT(pthread_equal(lock->owner, self));
- if (!lock->locked || !pthread_equal(lock->owner, self))
+ if (!lock->locked || !pthread_equal(lock->owner, self)) {
return PR_FAILURE;
+ }
lock->locked = PR_FALSE;
if (0 == lock->notified.length) /* shortcut */
@@ -203,7 +209,9 @@ PR_IMPLEMENT(PRStatus) PR_Unlock(PRLock *lock)
rv = pthread_mutex_unlock(&lock->mutex);
PR_ASSERT(0 == rv);
}
- else pt_PostNotifies(lock, PR_TRUE);
+ else {
+ pt_PostNotifies(lock, PR_TRUE);
+ }
#if defined(DEBUG)
pt_debug.locks_released += 1;
@@ -213,8 +221,8 @@ PR_IMPLEMENT(PRStatus) PR_Unlock(PRLock *lock)
PR_IMPLEMENT(void) PR_AssertCurrentThreadOwnsLock(PRLock *lock)
{
- /* Nb: the order of the |locked| and |owner==me| checks is not critical
- * to the correctness of PR_AssertCurrentThreadOwnsLock(), but
+ /* Nb: the order of the |locked| and |owner==me| checks is not critical
+ * to the correctness of PR_AssertCurrentThreadOwnsLock(), but
* this particular order makes the assertion more likely to
* catch errors. */
PR_ASSERT(lock->locked && pthread_equal(lock->owner, pthread_self()));
@@ -282,19 +290,24 @@ static void pt_PostNotifyToCvar(PRCondVar *cvar, PRBool broadcast)
{
if (notified->cv[index].cv == cvar)
{
- if (broadcast)
+ if (broadcast) {
notified->cv[index].times = -1;
- else if (-1 != notified->cv[index].times)
+ }
+ else if (-1 != notified->cv[index].times) {
notified->cv[index].times += 1;
+ }
return; /* we're finished */
}
}
/* if not full, enter new CV in this array */
- if (notified->length < PT_CV_NOTIFIED_LENGTH) break;
+ if (notified->length < PT_CV_NOTIFIED_LENGTH) {
+ break;
+ }
/* if there's no link, create an empty array and link it */
- if (NULL == notified->link)
+ if (NULL == notified->link) {
notified->link = PR_NEWZAP(_PT_Notified);
+ }
notified = notified->link;
}
@@ -358,7 +371,9 @@ PR_IMPLEMENT(PRStatus) PR_WaitCondVar(PRCondVar *cvar, PRIntervalTime timeout)
/* and it better be by us */
PR_ASSERT(pthread_equal(cvar->lock->owner, pthread_self()));
- if (_PT_THREAD_INTERRUPTED(thred)) goto aborted;
+ if (_PT_THREAD_INTERRUPTED(thred)) {
+ goto aborted;
+ }
/*
* The thread waiting is used for PR_Interrupt
@@ -373,18 +388,21 @@ PR_IMPLEMENT(PRStatus) PR_WaitCondVar(PRCondVar *cvar, PRIntervalTime timeout)
* that they are going to collide for the lock that we will
* hold until we actually wait.
*/
- if (0 != cvar->lock->notified.length)
+ if (0 != cvar->lock->notified.length) {
pt_PostNotifies(cvar->lock, PR_FALSE);
+ }
/*
* We're surrendering the lock, so clear out the locked field.
*/
cvar->lock->locked = PR_FALSE;
- if (timeout == PR_INTERVAL_NO_TIMEOUT)
+ if (timeout == PR_INTERVAL_NO_TIMEOUT) {
rv = pthread_cond_wait(&cvar->cv, &cvar->lock->mutex);
- else
+ }
+ else {
rv = pt_TimedWait(&cvar->cv, &cvar->lock->mutex, timeout);
+ }
/* We just got the lock back - this better be empty */
PR_ASSERT(PR_FALSE == cvar->lock->locked);
@@ -393,7 +411,9 @@ PR_IMPLEMENT(PRStatus) PR_WaitCondVar(PRCondVar *cvar, PRIntervalTime timeout)
PR_ASSERT(0 == cvar->lock->notified.length);
thred->waiting = NULL; /* and now we're not */
- if (_PT_THREAD_INTERRUPTED(thred)) goto aborted;
+ if (_PT_THREAD_INTERRUPTED(thred)) {
+ goto aborted;
+ }
if (rv != 0)
{
_PR_MD_MAP_DEFAULT_ERROR(rv);
@@ -409,7 +429,7 @@ aborted:
PR_IMPLEMENT(PRStatus) PR_NotifyCondVar(PRCondVar *cvar)
{
- PR_ASSERT(cvar != NULL);
+ PR_ASSERT(cvar != NULL);
pt_PostNotifyToCvar(cvar, PR_FALSE);
return PR_SUCCESS;
} /* PR_NotifyCondVar */
@@ -440,10 +460,12 @@ static void pt_PostNotifyToMonitor(PRMonitor *mon, PRBool broadcast)
/* mon->notifyTimes is protected by the monitor, so we don't need to
* acquire mon->lock.
*/
- if (broadcast)
+ if (broadcast) {
mon->notifyTimes = -1;
- else if (-1 != mon->notifyTimes)
+ }
+ else if (-1 != mon->notifyTimes) {
mon->notifyTimes += 1;
+ }
} /* pt_PostNotifyToMonitor */
static void pt_PostNotifiesFromMonitor(pthread_cond_t *cv, PRIntn times)
@@ -476,7 +498,9 @@ PR_IMPLEMENT(PRMonitor*) PR_NewMonitor(void)
PRMonitor *mon;
int rv;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
mon = PR_NEWZAP(PRMonitor);
if (mon == NULL)
@@ -487,20 +511,23 @@ PR_IMPLEMENT(PRMonitor*) PR_NewMonitor(void)
rv = _PT_PTHREAD_MUTEX_INIT(mon->lock, _pt_mattr);
PR_ASSERT(0 == rv);
- if (0 != rv)
+ if (0 != rv) {
goto error1;
+ }
_PT_PTHREAD_INVALIDATE_THR_HANDLE(mon->owner);
rv = _PT_PTHREAD_COND_INIT(mon->entryCV, _pt_cvar_attr);
PR_ASSERT(0 == rv);
- if (0 != rv)
+ if (0 != rv) {
goto error2;
+ }
rv = _PT_PTHREAD_COND_INIT(mon->waitCV, _pt_cvar_attr);
PR_ASSERT(0 == rv);
- if (0 != rv)
+ if (0 != rv) {
goto error3;
+ }
mon->notifyTimes = 0;
mon->entryCount = 0;
@@ -521,8 +548,9 @@ error1:
PR_IMPLEMENT(PRMonitor*) PR_NewNamedMonitor(const char* name)
{
PRMonitor* mon = PR_NewMonitor();
- if (mon)
+ if (mon) {
mon->name = name;
+ }
return mon;
}
@@ -543,7 +571,7 @@ PR_IMPLEMENT(void) PR_DestroyMonitor(PRMonitor *mon)
}
} /* PR_DestroyMonitor */
-/* The GC uses this; it is quite arguably a bad interface. I'm just
+/* The GC uses this; it is quite arguably a bad interface. I'm just
* duplicating it for now - XXXMB
*/
PR_IMPLEMENT(PRIntn) PR_GetMonitorEntryCount(PRMonitor *mon)
@@ -554,8 +582,9 @@ PR_IMPLEMENT(PRIntn) PR_GetMonitorEntryCount(PRMonitor *mon)
rv = pthread_mutex_lock(&mon->lock);
PR_ASSERT(0 == rv);
- if (pthread_equal(mon->owner, self))
+ if (pthread_equal(mon->owner, self)) {
count = mon->entryCount;
+ }
rv = pthread_mutex_unlock(&mon->lock);
PR_ASSERT(0 == rv);
return count;
@@ -585,8 +614,9 @@ PR_IMPLEMENT(void) PR_EnterMonitor(PRMonitor *mon)
PR_ASSERT(0 == rv);
if (mon->entryCount != 0)
{
- if (pthread_equal(mon->owner, self))
+ if (pthread_equal(mon->owner, self)) {
goto done;
+ }
while (mon->entryCount != 0)
{
rv = pthread_cond_wait(&mon->entryCV, &mon->lock);
@@ -641,8 +671,9 @@ PR_IMPLEMENT(PRStatus) PR_ExitMonitor(PRMonitor *mon)
PR_ASSERT(0 == rv);
if (notifyEntryWaiter)
{
- if (notifyTimes)
+ if (notifyTimes) {
pt_PostNotifiesFromMonitor(&mon->waitCV, notifyTimes);
+ }
rv = pthread_cond_signal(&mon->entryCV);
PR_ASSERT(0 == rv);
/* We are done accessing the members of 'mon'. Release the
@@ -667,7 +698,7 @@ PR_IMPLEMENT(PRStatus) PR_Wait(PRMonitor *mon, PRIntervalTime timeout)
PR_ASSERT(pthread_equal(mon->owner, pthread_self()));
/* tuck these away 'till later */
- saved_entries = mon->entryCount;
+ saved_entries = mon->entryCount;
mon->entryCount = 0;
_PT_PTHREAD_COPY_THR_HANDLE(mon->owner, saved_owner);
_PT_PTHREAD_INVALIDATE_THR_HANDLE(mon->owner);
@@ -687,10 +718,12 @@ PR_IMPLEMENT(PRStatus) PR_Wait(PRMonitor *mon, PRIntervalTime timeout)
rv = pthread_cond_signal(&mon->entryCV);
PR_ASSERT(0 == rv);
- if (timeout == PR_INTERVAL_NO_TIMEOUT)
+ if (timeout == PR_INTERVAL_NO_TIMEOUT) {
rv = pthread_cond_wait(&mon->waitCV, &mon->lock);
- else
+ }
+ else {
rv = pt_TimedWait(&mon->waitCV, &mon->lock, timeout);
+ }
PR_ASSERT(0 == rv);
while (mon->entryCount != 0)
@@ -729,32 +762,35 @@ PR_IMPLEMENT(void) PR_PostSem(PRSemaphore *semaphore)
{
static PRBool unwarned = PR_TRUE;
if (unwarned) unwarned = _PR_Obsolete(
- "PR_PostSem", "locks & condition variables");
- PR_Lock(semaphore->cvar->lock);
- PR_NotifyCondVar(semaphore->cvar);
- semaphore->count += 1;
- PR_Unlock(semaphore->cvar->lock);
+ "PR_PostSem", "locks & condition variables");
+ PR_Lock(semaphore->cvar->lock);
+ PR_NotifyCondVar(semaphore->cvar);
+ semaphore->count += 1;
+ PR_Unlock(semaphore->cvar->lock);
} /* PR_PostSem */
PR_IMPLEMENT(PRStatus) PR_WaitSem(PRSemaphore *semaphore)
{
- PRStatus status = PR_SUCCESS;
+ PRStatus status = PR_SUCCESS;
static PRBool unwarned = PR_TRUE;
if (unwarned) unwarned = _PR_Obsolete(
- "PR_WaitSem", "locks & condition variables");
- PR_Lock(semaphore->cvar->lock);
- while ((semaphore->count == 0) && (PR_SUCCESS == status))
- status = PR_WaitCondVar(semaphore->cvar, PR_INTERVAL_NO_TIMEOUT);
- if (PR_SUCCESS == status) semaphore->count -= 1;
- PR_Unlock(semaphore->cvar->lock);
- return status;
+ "PR_WaitSem", "locks & condition variables");
+ PR_Lock(semaphore->cvar->lock);
+ while ((semaphore->count == 0) && (PR_SUCCESS == status)) {
+ status = PR_WaitCondVar(semaphore->cvar, PR_INTERVAL_NO_TIMEOUT);
+ }
+ if (PR_SUCCESS == status) {
+ semaphore->count -= 1;
+ }
+ PR_Unlock(semaphore->cvar->lock);
+ return status;
} /* PR_WaitSem */
PR_IMPLEMENT(void) PR_DestroySem(PRSemaphore *semaphore)
{
static PRBool unwarned = PR_TRUE;
if (unwarned) unwarned = _PR_Obsolete(
- "PR_DestroySem", "locks & condition variables");
+ "PR_DestroySem", "locks & condition variables");
PR_DestroyLock(semaphore->cvar->lock);
PR_DestroyCondVar(semaphore->cvar);
PR_Free(semaphore);
@@ -764,10 +800,12 @@ PR_IMPLEMENT(PRSemaphore*) PR_NewSem(PRUintn value)
{
PRSemaphore *semaphore;
static PRBool unwarned = PR_TRUE;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
if (unwarned) unwarned = _PR_Obsolete(
- "PR_NewSem", "locks & condition variables");
+ "PR_NewSem", "locks & condition variables");
semaphore = PR_NEWZAP(PRSemaphore);
if (NULL != semaphore)
@@ -825,7 +863,9 @@ PR_IMPLEMENT(PRSem *) PR_OpenSemaphore(
{
int oflag = O_CREAT;
- if (flags & PR_SEM_EXCL) oflag |= O_EXCL;
+ if (flags & PR_SEM_EXCL) {
+ oflag |= O_EXCL;
+ }
sem->sem = sem_open(osname, oflag, mode, value);
}
else
@@ -901,7 +941,7 @@ PR_IMPLEMENT(PRStatus) PR_DeleteSemaphore(const char *name)
}
return PR_SUCCESS;
}
-
+
#elif defined(_PR_HAVE_SYSV_SEMAPHORES)
#include <fcntl.h>
@@ -913,7 +953,7 @@ PR_IMPLEMENT(PRStatus) PR_DeleteSemaphore(const char *name)
#if (defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)) \
|| (defined(FREEBSD) && __FreeBSD_version < 1200059) \
|| defined(OPENBSD) || defined(BSDI) \
- || defined(DARWIN) || defined(SYMBIAN)
+ || defined(DARWIN)
/* union semun is defined by including <sys/sem.h> */
#else
/* according to X/OPEN we have to define it ourselves */
@@ -1026,7 +1066,9 @@ PR_IMPLEMENT(PRSem *) PR_OpenSemaphore(
{
arg.buf = &seminfo;
semctl(sem->semid, 0, IPC_STAT, arg);
- if (seminfo.sem_otime != 0) break;
+ if (seminfo.sem_otime != 0) {
+ break;
+ }
sleep(1);
}
if (i == MAX_TRIES)
@@ -1106,7 +1148,7 @@ PR_IMPLEMENT(PRStatus) PR_DeleteSemaphore(const char *name)
}
unused.val = 0;
if (semctl(semid, 0, IPC_RMID, unused) == -1)
- {
+ {
_PR_MD_MAP_DEFAULT_ERROR(errno);
return PR_FAILURE;
}
@@ -1176,7 +1218,9 @@ PR_IMPLEMENT(PRCondVar*) PRP_NewNakedCondVar(void)
{
PRCondVar *cv;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
cv = PR_NEW(PRCondVar);
if (cv != NULL)
@@ -1202,7 +1246,7 @@ PR_IMPLEMENT(void) PRP_DestroyNakedCondVar(PRCondVar *cvar)
int rv;
rv = pthread_cond_destroy(&cvar->cv); PR_ASSERT(0 == rv);
#if defined(DEBUG)
- memset(cvar, 0xaf, sizeof(PRCondVar));
+ memset(cvar, 0xaf, sizeof(PRCondVar));
#endif
PR_Free(cvar);
} /* PRP_DestroyNakedCondVar */
@@ -1214,10 +1258,12 @@ PR_IMPLEMENT(PRStatus) PRP_NakedWait(
PR_ASSERT(cvar != NULL);
/* XXX do we really want to assert this in a naked wait? */
PR_ASSERT(_PT_PTHREAD_MUTEX_IS_LOCKED(ml->mutex));
- if (timeout == PR_INTERVAL_NO_TIMEOUT)
+ if (timeout == PR_INTERVAL_NO_TIMEOUT) {
rv = pthread_cond_wait(&cvar->cv, &ml->mutex);
- else
+ }
+ else {
rv = pt_TimedWait(&cvar->cv, &ml->mutex, timeout);
+ }
if (rv != 0)
{
_PR_MD_MAP_DEFAULT_ERROR(rv);
diff --git a/nsprpub/pr/src/pthreads/ptthread.c b/nsprpub/pr/src/pthreads/ptthread.c
index e61a4cbde..292c89ebc 100644
--- a/nsprpub/pr/src/pthreads/ptthread.c
+++ b/nsprpub/pr/src/pthreads/ptthread.c
@@ -25,11 +25,8 @@
#include <pthread_np.h>
#endif
-#ifdef SYMBIAN
-/* In Open C sched_get_priority_min/max do not work properly, so we undefine
- * _POSIX_THREAD_PRIORITY_SCHEDULING here.
- */
-#undef _POSIX_THREAD_PRIORITY_SCHEDULING
+#if defined(ANDROID)
+#include <sys/prctl.h>
#endif
#ifdef _PR_NICE_PRIORITY_SCHEDULING
@@ -79,7 +76,7 @@ static PRIntn pt_PriorityMap(PRThreadPriority pri)
return 10;
#else
return pt_book.minPrio +
- pri * (pt_book.maxPrio - pt_book.minPrio) / PR_PRIORITY_LAST;
+ pri * (pt_book.maxPrio - pt_book.minPrio) / PR_PRIORITY_LAST;
#endif
}
#elif defined(_PR_NICE_PRIORITY_SCHEDULING)
@@ -185,15 +182,18 @@ static void *_pt_root(void *arg)
#endif
/* If this is a GCABLE thread, set its state appropriately */
- if (thred->suspend & PT_THREAD_SETGCABLE)
- thred->state |= PT_THREAD_GCABLE;
+ if (thred->suspend & PT_THREAD_SETGCABLE) {
+ thred->state |= PT_THREAD_GCABLE;
+ }
thred->suspend = 0;
thred->prev = pt_book.last;
- if (pt_book.last)
+ if (pt_book.last) {
pt_book.last->next = thred;
- else
+ }
+ else {
pt_book.first = thred;
+ }
thred->next = NULL;
pt_book.last = thred;
PR_Unlock(pt_book.ml);
@@ -209,22 +209,29 @@ static void *_pt_root(void *arg)
*/
if (detached)
{
- while (!thred->okToDelete)
+ while (!thred->okToDelete) {
PR_WaitCondVar(pt_book.cv, PR_INTERVAL_NO_TIMEOUT);
+ }
}
- if (thred->state & PT_THREAD_SYSTEM)
+ if (thred->state & PT_THREAD_SYSTEM) {
pt_book.system -= 1;
- else if (--pt_book.user == pt_book.this_many)
+ }
+ else if (--pt_book.user == pt_book.this_many) {
PR_NotifyAllCondVar(pt_book.cv);
- if (NULL == thred->prev)
+ }
+ if (NULL == thred->prev) {
pt_book.first = thred->next;
- else
+ }
+ else {
thred->prev->next = thred->next;
- if (NULL == thred->next)
+ }
+ if (NULL == thred->next) {
pt_book.last = thred->prev;
- else
+ }
+ else {
thred->next->prev = thred->prev;
+ }
PR_Unlock(pt_book.ml);
/*
@@ -259,7 +266,9 @@ static PRThread* pt_AttachThread(void)
* either (e.g., PR_SetError()) as that will result in infinite
* recursion.
*/
- if (!_pr_initialized) return NULL;
+ if (!_pr_initialized) {
+ return NULL;
+ }
/* PR_NEWZAP must not call PR_GetCurrentThread() */
thred = PR_NEWZAP(PRThread);
@@ -281,10 +290,12 @@ static PRThread* pt_AttachThread(void)
/* then put it into the list */
thred->prev = pt_book.last;
- if (pt_book.last)
+ if (pt_book.last) {
pt_book.last->next = thred;
- else
+ }
+ else {
pt_book.first = thred;
+ }
thred->next = NULL;
pt_book.last = thred;
PR_Unlock(pt_book.ml);
@@ -302,12 +313,16 @@ static PRThread* _PR_CreateThread(
PRThread *thred;
pthread_attr_t tattr;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
- if ((PRIntn)PR_PRIORITY_FIRST > (PRIntn)priority)
+ if ((PRIntn)PR_PRIORITY_FIRST > (PRIntn)priority) {
priority = PR_PRIORITY_FIRST;
- else if ((PRIntn)PR_PRIORITY_LAST < (PRIntn)priority)
+ }
+ else if ((PRIntn)PR_PRIORITY_LAST < (PRIntn)priority) {
priority = PR_PRIORITY_LAST;
+ }
rv = _PT_PTHREAD_ATTR_INIT(&tattr);
PR_ASSERT(0 == rv);
@@ -339,8 +354,8 @@ static PRThread* _PR_CreateThread(
}
rv = pthread_attr_setdetachstate(&tattr,
- ((PR_JOINABLE_THREAD == state) ?
- PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED));
+ ((PR_JOINABLE_THREAD == state) ?
+ PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED));
PR_ASSERT(0 == rv);
/*
@@ -349,8 +364,9 @@ static PRThread* _PR_CreateThread(
if (stackSize)
{
#ifdef _MD_MINIMUM_STACK_SIZE
- if (stackSize < _MD_MINIMUM_STACK_SIZE)
+ if (stackSize < _MD_MINIMUM_STACK_SIZE) {
stackSize = _MD_MINIMUM_STACK_SIZE;
+ }
#endif
rv = pthread_attr_setstacksize(&tattr, stackSize);
PR_ASSERT(0 == rv);
@@ -369,36 +385,42 @@ static PRThread* _PR_CreateThread(
thred->arg = arg;
thred->startFunc = start;
thred->priority = priority;
- if (PR_UNJOINABLE_THREAD == state)
+ if (PR_UNJOINABLE_THREAD == state) {
thred->state |= PT_THREAD_DETACHED;
+ }
+
+ if (PR_LOCAL_THREAD == scope) {
+ scope = PR_GLOBAL_THREAD;
+ }
- if (PR_LOCAL_THREAD == scope)
- scope = PR_GLOBAL_THREAD;
-
if (PR_GLOBAL_BOUND_THREAD == scope) {
#if _POSIX_THREAD_PRIORITY_SCHEDULING > 0
- rv = pthread_attr_setscope(&tattr, PTHREAD_SCOPE_SYSTEM);
- if (rv) {
- /*
- * system scope not supported
- */
- scope = PR_GLOBAL_THREAD;
- /*
- * reset scope
- */
- rv = pthread_attr_setscope(&tattr, PTHREAD_SCOPE_PROCESS);
- PR_ASSERT(0 == rv);
- }
+ rv = pthread_attr_setscope(&tattr, PTHREAD_SCOPE_SYSTEM);
+ if (rv) {
+ /*
+ * system scope not supported
+ */
+ scope = PR_GLOBAL_THREAD;
+ /*
+ * reset scope
+ */
+ rv = pthread_attr_setscope(&tattr, PTHREAD_SCOPE_PROCESS);
+ PR_ASSERT(0 == rv);
+ }
#endif
- }
- if (PR_GLOBAL_THREAD == scope)
+ }
+ if (PR_GLOBAL_THREAD == scope) {
thred->state |= PT_THREAD_GLOBAL;
- else if (PR_GLOBAL_BOUND_THREAD == scope)
+ }
+ else if (PR_GLOBAL_BOUND_THREAD == scope) {
thred->state |= (PT_THREAD_GLOBAL | PT_THREAD_BOUND);
- else /* force it global */
+ }
+ else { /* force it global */
thred->state |= PT_THREAD_GLOBAL;
- if (PR_SYSTEM_THREAD == type)
+ }
+ if (PR_SYSTEM_THREAD == type) {
thred->state |= PT_THREAD_SYSTEM;
+ }
thred->suspend =(isGCAble) ? PT_THREAD_SETGCABLE : 0;
@@ -420,9 +442,12 @@ static PRThread* _PR_CreateThread(
/* make the thread counted to the rest of the runtime */
PR_Lock(pt_book.ml);
- if (PR_SYSTEM_THREAD == type)
+ if (PR_SYSTEM_THREAD == type) {
pt_book.system += 1;
- else pt_book.user += 1;
+ }
+ else {
+ pt_book.user += 1;
+ }
PR_Unlock(pt_book.ml);
/*
@@ -434,27 +459,15 @@ static PRThread* _PR_CreateThread(
if (EPERM == rv)
{
-#if defined(IRIX)
- if (PR_GLOBAL_BOUND_THREAD == scope) {
- /*
- * SCOPE_SYSTEM requires appropriate privilege
- * reset to process scope and try again
- */
- rv = pthread_attr_setscope(&tattr, PTHREAD_SCOPE_PROCESS);
- PR_ASSERT(0 == rv);
- thred->state &= ~PT_THREAD_BOUND;
- }
-#else
/* Remember that we don't have thread scheduling privilege. */
pt_schedpriv = EPERM;
PR_LOG(_pr_thread_lm, PR_LOG_MIN,
- ("_PR_CreateThread: no thread scheduling privilege"));
+ ("_PR_CreateThread: no thread scheduling privilege"));
/* Try creating the thread again without setting priority. */
#if _POSIX_THREAD_PRIORITY_SCHEDULING > 0
rv = pthread_attr_setinheritsched(&tattr, PTHREAD_INHERIT_SCHED);
PR_ASSERT(0 == rv);
#endif
-#endif /* IRIX */
rv = _PT_PTHREAD_CREATE(&id, tattr, _pt_root, thred);
}
@@ -462,10 +475,12 @@ static PRThread* _PR_CreateThread(
{
PRIntn oserr = rv;
PR_Lock(pt_book.ml);
- if (thred->state & PT_THREAD_SYSTEM)
+ if (thred->state & PT_THREAD_SYSTEM) {
pt_book.system -= 1;
- else if (--pt_book.user == pt_book.this_many)
+ }
+ else if (--pt_book.user == pt_book.this_many) {
PR_NotifyAllCondVar(pt_book.cv);
+ }
PR_Unlock(pt_book.ml);
PR_Free(thred->stack);
@@ -516,23 +531,23 @@ PR_IMPLEMENT(PRThread*) PR_CreateThread(
PRThreadState state, PRUint32 stackSize)
{
return _PR_CreateThread(
- type, start, arg, priority, scope, state, stackSize, PR_FALSE);
+ type, start, arg, priority, scope, state, stackSize, PR_FALSE);
} /* PR_CreateThread */
PR_IMPLEMENT(PRThread*) PR_CreateThreadGCAble(
- PRThreadType type, void (*start)(void *arg), void *arg,
+ PRThreadType type, void (*start)(void *arg), void *arg,
PRThreadPriority priority, PRThreadScope scope,
PRThreadState state, PRUint32 stackSize)
{
return _PR_CreateThread(
- type, start, arg, priority, scope, state, stackSize, PR_TRUE);
+ type, start, arg, priority, scope, state, stackSize, PR_TRUE);
} /* PR_CreateThreadGCAble */
PR_IMPLEMENT(void*) GetExecutionEnvironment(PRThread *thred)
{
return thred->environment;
} /* GetExecutionEnvironment */
-
+
PR_IMPLEMENT(void) SetExecutionEnvironment(PRThread *thred, void *env)
{
thred->environment = env;
@@ -552,8 +567,8 @@ PR_IMPLEMENT(PRStatus) PR_JoinThread(PRThread *thred)
PR_ASSERT(thred != NULL);
if ((0xafafafaf == thred->state)
- || (PT_THREAD_DETACHED == (PT_THREAD_DETACHED & thred->state))
- || (PT_THREAD_FOREIGN == (PT_THREAD_FOREIGN & thred->state)))
+ || (PT_THREAD_DETACHED == (PT_THREAD_DETACHED & thred->state))
+ || (PT_THREAD_FOREIGN == (PT_THREAD_FOREIGN & thred->state)))
{
/*
* This might be a bad address, but if it isn't, the state should
@@ -606,7 +621,9 @@ PR_IMPLEMENT(void) PR_DetachThread(void)
int rv;
_PT_PTHREAD_GETSPECIFIC(pt_book.key, thred);
- if (NULL == thred) return;
+ if (NULL == thred) {
+ return;
+ }
_pt_thread_death(thred);
rv = pthread_setspecific(pt_book.key, NULL);
PR_ASSERT(0 == rv);
@@ -616,10 +633,14 @@ PR_IMPLEMENT(PRThread*) PR_GetCurrentThread(void)
{
void *thred;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
_PT_PTHREAD_GETSPECIFIC(pt_book.key, thred);
- if (NULL == thred) thred = pt_AttachThread();
+ if (NULL == thred) {
+ thred = pt_AttachThread();
+ }
PR_ASSERT(NULL != thred);
return (PRThread*)thred;
} /* PR_GetCurrentThread */
@@ -627,19 +648,19 @@ PR_IMPLEMENT(PRThread*) PR_GetCurrentThread(void)
PR_IMPLEMENT(PRThreadScope) PR_GetThreadScope(const PRThread *thred)
{
return (thred->state & PT_THREAD_BOUND) ?
- PR_GLOBAL_BOUND_THREAD : PR_GLOBAL_THREAD;
+ PR_GLOBAL_BOUND_THREAD : PR_GLOBAL_THREAD;
} /* PR_GetThreadScope() */
PR_IMPLEMENT(PRThreadType) PR_GetThreadType(const PRThread *thred)
{
return (thred->state & PT_THREAD_SYSTEM) ?
- PR_SYSTEM_THREAD : PR_USER_THREAD;
+ PR_SYSTEM_THREAD : PR_USER_THREAD;
}
PR_IMPLEMENT(PRThreadState) PR_GetThreadState(const PRThread *thred)
{
return (thred->state & PT_THREAD_DETACHED) ?
- PR_UNJOINABLE_THREAD : PR_JOINABLE_THREAD;
+ PR_UNJOINABLE_THREAD : PR_JOINABLE_THREAD;
} /* PR_GetThreadState */
PR_IMPLEMENT(PRThreadPriority) PR_GetThreadPriority(const PRThread *thred)
@@ -654,10 +675,12 @@ PR_IMPLEMENT(void) PR_SetThreadPriority(PRThread *thred, PRThreadPriority newPri
PR_ASSERT(NULL != thred);
- if ((PRIntn)PR_PRIORITY_FIRST > (PRIntn)newPri)
+ if ((PRIntn)PR_PRIORITY_FIRST > (PRIntn)newPri) {
newPri = PR_PRIORITY_FIRST;
- else if ((PRIntn)PR_PRIORITY_LAST < (PRIntn)newPri)
+ }
+ else if ((PRIntn)PR_PRIORITY_LAST < (PRIntn)newPri) {
newPri = PR_PRIORITY_LAST;
+ }
#if _POSIX_THREAD_PRIORITY_SCHEDULING > 0
if (EPERM != pt_schedpriv)
@@ -667,22 +690,24 @@ PR_IMPLEMENT(void) PR_SetThreadPriority(PRThread *thred, PRThreadPriority newPri
rv = pthread_getschedparam(thred->id, &policy, &schedule);
if(0 == rv) {
- schedule.sched_priority = pt_PriorityMap(newPri);
- rv = pthread_setschedparam(thred->id, policy, &schedule);
- if (EPERM == rv)
- {
- pt_schedpriv = EPERM;
- PR_LOG(_pr_thread_lm, PR_LOG_MIN,
- ("PR_SetThreadPriority: no thread scheduling privilege"));
- }
- }
- if (rv != 0)
- rv = -1;
+ schedule.sched_priority = pt_PriorityMap(newPri);
+ rv = pthread_setschedparam(thred->id, policy, &schedule);
+ if (EPERM == rv)
+ {
+ pt_schedpriv = EPERM;
+ PR_LOG(_pr_thread_lm, PR_LOG_MIN,
+ ("PR_SetThreadPriority: no thread scheduling privilege"));
+ }
+ }
+ if (rv != 0) {
+ rv = -1;
+ }
}
#elif defined(_PR_NICE_PRIORITY_SCHEDULING)
PR_Lock(pt_book.ml);
- while (thred->tid == 0)
+ while (thred->tid == 0) {
PR_WaitCondVar(pt_book.cv, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_Unlock(pt_book.ml);
errno = 0;
@@ -699,8 +724,8 @@ PR_IMPLEMENT(void) PR_SetThreadPriority(PRThread *thred, PRThreadPriority newPri
* because adjusting the nice value might be permitted for certain
* ranges but not for others. */
PR_LOG(_pr_thread_lm, PR_LOG_MIN,
- ("PR_SetThreadPriority: setpriority failed with error %d",
- errno));
+ ("PR_SetThreadPriority: setpriority failed with error %d",
+ errno));
}
}
#else
@@ -733,7 +758,9 @@ PR_IMPLEMENT(PRStatus) PR_Interrupt(PRThread *thred)
*/
PRCondVar *cv;
PR_ASSERT(NULL != thred);
- if (NULL == thred) return PR_FAILURE;
+ if (NULL == thred) {
+ return PR_FAILURE;
+ }
thred->state |= PT_THREAD_ABORTED;
@@ -744,8 +771,9 @@ PR_IMPLEMENT(PRStatus) PR_Interrupt(PRThread *thred)
(void)PR_ATOMIC_INCREMENT(&cv->notify_pending);
rv = pthread_cond_broadcast(&cv->cv);
PR_ASSERT(0 == rv);
- if (0 > PR_ATOMIC_DECREMENT(&cv->notify_pending))
+ if (0 > PR_ATOMIC_DECREMENT(&cv->notify_pending)) {
PR_DestroyCondVar(cv);
+ }
}
return PR_SUCCESS;
} /* PR_Interrupt */
@@ -772,7 +800,7 @@ PR_IMPLEMENT(PRStatus) PR_Yield(void)
{
static PRBool warning = PR_TRUE;
if (warning) warning = _PR_Obsolete(
- "PR_Yield()", "PR_Sleep(PR_INTERVAL_NO_WAIT)");
+ "PR_Yield()", "PR_Sleep(PR_INTERVAL_NO_WAIT)");
return PR_Sleep(PR_INTERVAL_NO_WAIT);
}
@@ -780,7 +808,9 @@ PR_IMPLEMENT(PRStatus) PR_Sleep(PRIntervalTime ticks)
{
PRStatus rv = PR_SUCCESS;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
if (PR_INTERVAL_NO_WAIT == ticks)
{
@@ -799,7 +829,9 @@ PR_IMPLEMENT(PRStatus) PR_Sleep(PRIntervalTime ticks)
{
PRIntervalTime now = PR_IntervalNow();
PRIntervalTime delta = now - timein;
- if (delta > ticks) break;
+ if (delta > ticks) {
+ break;
+ }
rv = PR_WaitCondVar(cv, ticks - delta);
} while (PR_SUCCESS == rv);
PR_Unlock(_pr_sleeplock);
@@ -824,7 +856,7 @@ static void _pt_thread_death(void *arg)
PR_ASSERT(0 == rv);
}
- /* PR_TRUE for: call destructors */
+ /* PR_TRUE for: call destructors */
_pt_thread_death_internal(arg, PR_TRUE);
if (NULL == thred)
@@ -841,29 +873,38 @@ static void _pt_thread_death_internal(void *arg, PRBool callDestructors)
if (thred->state & (PT_THREAD_FOREIGN|PT_THREAD_PRIMORD))
{
PR_Lock(pt_book.ml);
- if (NULL == thred->prev)
+ if (NULL == thred->prev) {
pt_book.first = thred->next;
- else
+ }
+ else {
thred->prev->next = thred->next;
- if (NULL == thred->next)
+ }
+ if (NULL == thred->next) {
pt_book.last = thred->prev;
- else
+ }
+ else {
thred->next->prev = thred->prev;
+ }
PR_Unlock(pt_book.ml);
}
- if (callDestructors)
+ if (callDestructors) {
_PR_DestroyThreadPrivate(thred);
+ }
PR_Free(thred->privateData);
- if (NULL != thred->errorString)
+ if (NULL != thred->errorString) {
PR_Free(thred->errorString);
- if (NULL != thred->name)
+ }
+ if (NULL != thred->name) {
PR_Free(thred->name);
+ }
PR_Free(thred->stack);
- if (NULL != thred->syspoll_list)
+ if (NULL != thred->syspoll_list) {
PR_Free(thred->syspoll_list);
+ }
#if defined(_PR_POLL_WITH_SELECT)
- if (NULL != thred->selectfd_list)
+ if (NULL != thred->selectfd_list) {
PR_Free(thred->selectfd_list);
+ }
#endif
#if defined(DEBUG)
memset(thred, 0xaf, sizeof(PRThread));
@@ -893,17 +934,17 @@ void _PR_InitThreads(
#if _POSIX_THREAD_PRIORITY_SCHEDULING > 0
#if defined(FREEBSD)
{
- pthread_attr_t attr;
- int policy;
- /* get the min and max priorities of the default policy */
- pthread_attr_init(&attr);
- pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
- pthread_attr_getschedpolicy(&attr, &policy);
- pt_book.minPrio = sched_get_priority_min(policy);
- PR_ASSERT(-1 != pt_book.minPrio);
- pt_book.maxPrio = sched_get_priority_max(policy);
- PR_ASSERT(-1 != pt_book.maxPrio);
- pthread_attr_destroy(&attr);
+ pthread_attr_t attr;
+ int policy;
+ /* get the min and max priorities of the default policy */
+ pthread_attr_init(&attr);
+ pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
+ pthread_attr_getschedpolicy(&attr, &policy);
+ pt_book.minPrio = sched_get_priority_min(policy);
+ PR_ASSERT(-1 != pt_book.minPrio);
+ pt_book.maxPrio = sched_get_priority_max(policy);
+ PR_ASSERT(-1 != pt_book.maxPrio);
+ pthread_attr_destroy(&attr);
}
#else
/*
@@ -913,7 +954,7 @@ void _PR_InitThreads(
pt_book.maxPrio = PT_PRIO_MAX;
#endif
#endif
-
+
PR_ASSERT(NULL == pt_book.ml);
pt_book.ml = PR_NewLock();
PR_ASSERT(NULL != pt_book.ml);
@@ -935,12 +976,12 @@ void _PR_InitThreads(
{
thred->state |= PT_THREAD_SYSTEM;
pt_book.system += 1;
- pt_book.this_many = 0;
+ pt_book.this_many = 0;
}
else
{
- pt_book.user += 1;
- pt_book.this_many = 1;
+ pt_book.user += 1;
+ pt_book.this_many = 1;
}
thred->next = thred->prev = NULL;
pt_book.first = pt_book.last = thred;
@@ -949,7 +990,7 @@ void _PR_InitThreads(
PR_ASSERT(thred->stack != NULL);
thred->stack->stackSize = 0;
thred->stack->thr = thred;
- _PR_InitializeStack(thred->stack);
+ _PR_InitializeStack(thred->stack);
/*
* Create a key for our use to store a backpointer in the pthread
@@ -966,8 +1007,9 @@ void _PR_InitThreads(
* nothing.
*/
rv = _PT_PTHREAD_KEY_CREATE(&pt_book.key, _pt_thread_death);
- if (0 != rv)
+ if (0 != rv) {
PR_Assert("0 == rv", __FILE__, __LINE__);
+ }
pt_book.keyCreated = PR_TRUE;
rv = pthread_setspecific(pt_book.key, thred);
PR_ASSERT(0 == rv);
@@ -989,7 +1031,7 @@ static void _PR_Fini(void);
__attribute__ ((constructor))
static void _register_PR_Fini() {
- atexit(_PR_Fini);
+ atexit(_PR_Fini);
}
#else
static void _PR_Fini(void) __attribute__ ((destructor));
@@ -1031,9 +1073,9 @@ void PR_HPUX10xInit(shl_t handle, int loading)
* loading is non-zero at startup and zero at termination.
*/
if (loading) {
- /* ... do some initializations ... */
+ /* ... do some initializations ... */
} else {
- _PR_Fini();
+ _PR_Fini();
}
}
#endif
@@ -1047,7 +1089,7 @@ void _PR_Fini(void)
int rv;
if (!_pr_initialized) {
- /* Either NSPR was never successfully initialized or
+ /* Either NSPR was never successfully initialized or
* PR_Cleanup has been called already. */
if (pt_book.keyCreated)
{
@@ -1062,7 +1104,7 @@ void _PR_Fini(void)
if (NULL != thred)
{
/*
- * PR_FALSE, because it is unsafe to call back to the
+ * PR_FALSE, because it is unsafe to call back to the
* thread private data destructors at final cleanup.
*/
_pt_thread_death_internal(thred, PR_FALSE);
@@ -1085,12 +1127,15 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup(void)
if (me->state & PT_THREAD_PRIMORD)
{
PR_Lock(pt_book.ml);
- while (pt_book.user > pt_book.this_many)
+ while (pt_book.user > pt_book.this_many) {
PR_WaitCondVar(pt_book.cv, PR_INTERVAL_NO_TIMEOUT);
- if (me->state & PT_THREAD_SYSTEM)
+ }
+ if (me->state & PT_THREAD_SYSTEM) {
pt_book.system -= 1;
- else
+ }
+ else {
pt_book.user -= 1;
+ }
PR_Unlock(pt_book.ml);
_PR_MD_EARLY_CLEANUP();
@@ -1168,7 +1213,7 @@ PR_SetThreadDumpProc(PRThread* thread, PRThreadDumpProc dump, void *arg)
thread->dumpArg = arg;
}
-/*
+/*
* Garbage collection support follows.
*/
@@ -1194,15 +1239,14 @@ static void null_signal_handler(PRIntn sig);
*/
static void init_pthread_gc_support(void)
{
-#ifndef SYMBIAN
PRIntn rv;
- {
- struct sigaction sigact_usr2;
+ {
+ struct sigaction sigact_usr2;
- sigact_usr2.sa_handler = suspend_signal_handler;
- sigact_usr2.sa_flags = SA_RESTART;
- sigemptyset (&sigact_usr2.sa_mask);
+ sigact_usr2.sa_handler = suspend_signal_handler;
+ sigact_usr2.sa_flags = SA_RESTART;
+ sigemptyset (&sigact_usr2.sa_mask);
rv = sigaction (SIGUSR2, &sigact_usr2, NULL);
PR_ASSERT(0 == rv);
@@ -1213,31 +1257,30 @@ static void init_pthread_gc_support(void)
#else
sigaddset (&sigwait_set, SIGUSR2);
#endif /* defined(PT_NO_SIGTIMEDWAIT) */
- }
+ }
#if defined(PT_NO_SIGTIMEDWAIT)
- {
- struct sigaction sigact_null;
- sigact_null.sa_handler = null_signal_handler;
- sigact_null.sa_flags = SA_RESTART;
- sigemptyset (&sigact_null.sa_mask);
+ {
+ struct sigaction sigact_null;
+ sigact_null.sa_handler = null_signal_handler;
+ sigact_null.sa_flags = SA_RESTART;
+ sigemptyset (&sigact_null.sa_mask);
rv = sigaction (SIGUSR1, &sigact_null, NULL);
- PR_ASSERT(0 ==rv);
+ PR_ASSERT(0 ==rv);
}
#endif /* defined(PT_NO_SIGTIMEDWAIT) */
-#endif /* SYMBIAN */
}
PR_IMPLEMENT(void) PR_SetThreadGCAble(void)
{
PR_Lock(pt_book.ml);
- PR_GetCurrentThread()->state |= PT_THREAD_GCABLE;
+ PR_GetCurrentThread()->state |= PT_THREAD_GCABLE;
PR_Unlock(pt_book.ml);
}
PR_IMPLEMENT(void) PR_ClearThreadGCAble(void)
{
PR_Lock(pt_book.ml);
- PR_GetCurrentThread()->state &= (~PT_THREAD_GCABLE);
+ PR_GetCurrentThread()->state &= (~PT_THREAD_GCABLE);
PR_Unlock(pt_book.ml);
}
@@ -1284,23 +1327,24 @@ PR_IMPLEMENT(PRStatus) PR_EnumerateThreads(PREnumerator func, void *arg)
if (_PT_IS_GCABLE_THREAD(thred))
{
PR_ASSERT((thred == me) || (thred->suspend & PT_THREAD_SUSPENDED));
- PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS,
- ("In PR_EnumerateThreads callback thread %p thid = %X\n",
+ PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS,
+ ("In PR_EnumerateThreads callback thread %p thid = %X\n",
thred, thred->id));
rv = func(thred, count++, arg);
- if (rv != PR_SUCCESS)
+ if (rv != PR_SUCCESS) {
return rv;
+ }
}
thred = next;
}
- PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS,
- ("End PR_EnumerateThreads count = %d \n", count));
+ PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS,
+ ("End PR_EnumerateThreads count = %d \n", count));
return rv;
} /* PR_EnumerateThreads */
/*
- * PR_SuspendAll and PR_ResumeAll are called during garbage collection. The strategy
+ * PR_SuspendAll and PR_ResumeAll are called during garbage collection. The strategy
* we use is to send a SIGUSR2 signal to every gc able thread that we intend to suspend.
* The signal handler will record the stack pointer and will block until resumed by
* the resume call. Since the signal handler is the last routine called for the
@@ -1313,97 +1357,96 @@ PR_IMPLEMENT(PRStatus) PR_EnumerateThreads(PREnumerator func, void *arg)
/*
* In the signal handler, we can not use condition variable notify or wait.
- * This does not work consistently across all pthread platforms. We also can not
+ * This does not work consistently across all pthread platforms. We also can not
* use locking since that does not seem to work reliably across platforms.
* Only thing we can do is yielding while testing for a global condition
* to change. This does work on pthread supported platforms. We may have
* to play with priortities if there are any problems detected.
*/
- /*
- * In AIX, you cannot use ANY pthread calls in the signal handler except perhaps
- * pthread_yield. But that is horribly inefficient. Hence we use only sigwait, no
- * sigtimedwait is available. We need to use another user signal, SIGUSR1. Actually
- * SIGUSR1 is also used by exec in Java. So our usage here breaks the exec in Java,
- * for AIX. You cannot use pthread_cond_wait or pthread_delay_np in the signal
- * handler as all synchronization mechanisms just break down.
- */
+/*
+ * In AIX, you cannot use ANY pthread calls in the signal handler except perhaps
+ * pthread_yield. But that is horribly inefficient. Hence we use only sigwait, no
+ * sigtimedwait is available. We need to use another user signal, SIGUSR1. Actually
+ * SIGUSR1 is also used by exec in Java. So our usage here breaks the exec in Java,
+ * for AIX. You cannot use pthread_cond_wait or pthread_delay_np in the signal
+ * handler as all synchronization mechanisms just break down.
+ */
#if defined(PT_NO_SIGTIMEDWAIT)
static void null_signal_handler(PRIntn sig)
{
- return;
+ return;
}
#endif
static void suspend_signal_handler(PRIntn sig)
{
- PRThread *me = PR_GetCurrentThread();
+ PRThread *me = PR_GetCurrentThread();
- PR_ASSERT(me != NULL);
- PR_ASSERT(_PT_IS_GCABLE_THREAD(me));
- PR_ASSERT((me->suspend & PT_THREAD_SUSPENDED) == 0);
+ PR_ASSERT(me != NULL);
+ PR_ASSERT(_PT_IS_GCABLE_THREAD(me));
+ PR_ASSERT((me->suspend & PT_THREAD_SUSPENDED) == 0);
- PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS,
- ("Begin suspend_signal_handler thred %p thread id = %X\n",
- me, me->id));
+ PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS,
+ ("Begin suspend_signal_handler thred %p thread id = %X\n",
+ me, me->id));
- /*
- * save stack pointer
- */
- me->sp = &me;
+ /*
+ * save stack pointer
+ */
+ me->sp = &me;
- /*
- At this point, the thread's stack pointer has been saved,
- And it is going to enter a wait loop until it is resumed.
- So it is _really_ suspended
- */
+ /*
+ At this point, the thread's stack pointer has been saved,
+ And it is going to enter a wait loop until it is resumed.
+ So it is _really_ suspended
+ */
- me->suspend |= PT_THREAD_SUSPENDED;
+ me->suspend |= PT_THREAD_SUSPENDED;
- /*
- * now, block current thread
- */
+ /*
+ * now, block current thread
+ */
#if defined(PT_NO_SIGTIMEDWAIT)
- pthread_cond_signal(&me->suspendResumeCV);
- while (me->suspend & PT_THREAD_SUSPENDED)
- {
+ pthread_cond_signal(&me->suspendResumeCV);
+ while (me->suspend & PT_THREAD_SUSPENDED)
+ {
#if !defined(FREEBSD) && !defined(NETBSD) && !defined(OPENBSD) \
&& !defined(BSDI) && !defined(UNIXWARE) \
- && !defined(DARWIN) && !defined(RISCOS) \
- && !defined(SYMBIAN) /*XXX*/
+ && !defined(DARWIN) && !defined(RISCOS)
PRIntn rv;
- sigwait(&sigwait_set, &rv);
+ sigwait(&sigwait_set, &rv);
#endif
- }
- me->suspend |= PT_THREAD_RESUMED;
- pthread_cond_signal(&me->suspendResumeCV);
+ }
+ me->suspend |= PT_THREAD_RESUMED;
+ pthread_cond_signal(&me->suspendResumeCV);
#else /* defined(PT_NO_SIGTIMEDWAIT) */
- while (me->suspend & PT_THREAD_SUSPENDED)
- {
- PRIntn rv = sigtimedwait(&sigwait_set, NULL, &hundredmillisec);
- PR_ASSERT(-1 == rv);
- }
- me->suspend |= PT_THREAD_RESUMED;
+ while (me->suspend & PT_THREAD_SUSPENDED)
+ {
+ PRIntn rv = sigtimedwait(&sigwait_set, NULL, &hundredmillisec);
+ PR_ASSERT(-1 == rv);
+ }
+ me->suspend |= PT_THREAD_RESUMED;
#endif
/*
* At this point, thread has been resumed, so set a global condition.
- * The ResumeAll needs to know that this has really been resumed.
- * So the signal handler sets a flag which PR_ResumeAll will reset.
+ * The ResumeAll needs to know that this has really been resumed.
+ * So the signal handler sets a flag which PR_ResumeAll will reset.
* The PR_ResumeAll must reset this flag ...
*/
- PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS,
- ("End suspend_signal_handler thred = %p tid = %X\n", me, me->id));
+ PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS,
+ ("End suspend_signal_handler thred = %p tid = %X\n", me, me->id));
} /* suspend_signal_handler */
static void pt_SuspendSet(PRThread *thred)
{
PRIntn rv;
- PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS,
- ("pt_SuspendSet thred %p thread id = %X\n", thred, thred->id));
+ PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS,
+ ("pt_SuspendSet thred %p thread id = %X\n", thred, thred->id));
/*
@@ -1412,54 +1455,49 @@ static void pt_SuspendSet(PRThread *thred)
PR_ASSERT((thred->suspend & PT_THREAD_SUSPENDED) == 0);
- PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS,
- ("doing pthread_kill in pt_SuspendSet thred %p tid = %X\n",
- thred, thred->id));
-#if defined(SYMBIAN)
- /* All signal group functions are not implemented in Symbian OS */
- rv = 0;
-#else
+ PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS,
+ ("doing pthread_kill in pt_SuspendSet thred %p tid = %X\n",
+ thred, thred->id));
rv = pthread_kill (thred->id, SIGUSR2);
-#endif
PR_ASSERT(0 == rv);
}
static void pt_SuspendTest(PRThread *thred)
{
- PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS,
- ("Begin pt_SuspendTest thred %p thread id = %X\n", thred, thred->id));
+ PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS,
+ ("Begin pt_SuspendTest thred %p thread id = %X\n", thred, thred->id));
/*
* Wait for the thread to be really suspended. This happens when the
* suspend signal handler stores the stack pointer and sets the state
- * to suspended.
+ * to suspended.
*/
#if defined(PT_NO_SIGTIMEDWAIT)
pthread_mutex_lock(&thred->suspendResumeMutex);
while ((thred->suspend & PT_THREAD_SUSPENDED) == 0)
{
- pthread_cond_timedwait(
- &thred->suspendResumeCV, &thred->suspendResumeMutex, &onemillisec);
- }
- pthread_mutex_unlock(&thred->suspendResumeMutex);
+ pthread_cond_timedwait(
+ &thred->suspendResumeCV, &thred->suspendResumeMutex, &onemillisec);
+ }
+ pthread_mutex_unlock(&thred->suspendResumeMutex);
#else
while ((thred->suspend & PT_THREAD_SUSPENDED) == 0)
{
- PRIntn rv = sigtimedwait(&sigwait_set, NULL, &onemillisec);
- PR_ASSERT(-1 == rv);
- }
+ PRIntn rv = sigtimedwait(&sigwait_set, NULL, &onemillisec);
+ PR_ASSERT(-1 == rv);
+ }
#endif
PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS,
- ("End pt_SuspendTest thred %p tid %X\n", thred, thred->id));
+ ("End pt_SuspendTest thred %p tid %X\n", thred, thred->id));
} /* pt_SuspendTest */
static void pt_ResumeSet(PRThread *thred)
{
- PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS,
- ("pt_ResumeSet thred %p thread id = %X\n", thred, thred->id));
+ PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS,
+ ("pt_ResumeSet thred %p thread id = %X\n", thred, thred->id));
/*
* Clear the global state and set the thread state so that it will
@@ -1472,43 +1510,39 @@ static void pt_ResumeSet(PRThread *thred)
thred->suspend &= ~PT_THREAD_SUSPENDED;
#if defined(PT_NO_SIGTIMEDWAIT)
-#if defined(SYMBIAN)
- /* All signal group functions are not implemented in Symbian OS */
-#else
- pthread_kill(thred->id, SIGUSR1);
-#endif
+ pthread_kill(thred->id, SIGUSR1);
#endif
} /* pt_ResumeSet */
static void pt_ResumeTest(PRThread *thred)
{
- PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS,
- ("Begin pt_ResumeTest thred %p thread id = %X\n", thred, thred->id));
+ PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS,
+ ("Begin pt_ResumeTest thred %p thread id = %X\n", thred, thred->id));
/*
* Wait for the threads resume state to change
- * to indicate it is really resumed
+ * to indicate it is really resumed
*/
#if defined(PT_NO_SIGTIMEDWAIT)
pthread_mutex_lock(&thred->suspendResumeMutex);
while ((thred->suspend & PT_THREAD_RESUMED) == 0)
{
- pthread_cond_timedwait(
- &thred->suspendResumeCV, &thred->suspendResumeMutex, &onemillisec);
+ pthread_cond_timedwait(
+ &thred->suspendResumeCV, &thred->suspendResumeMutex, &onemillisec);
}
pthread_mutex_unlock(&thred->suspendResumeMutex);
#else
while ((thred->suspend & PT_THREAD_RESUMED) == 0) {
- PRIntn rv = sigtimedwait(&sigwait_set, NULL, &onemillisec);
- PR_ASSERT(-1 == rv);
- }
+ PRIntn rv = sigtimedwait(&sigwait_set, NULL, &onemillisec);
+ PR_ASSERT(-1 == rv);
+ }
#endif
thred->suspend &= ~PT_THREAD_RESUMED;
PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS, (
- "End pt_ResumeTest thred %p tid %X\n", thred, thred->id));
+ "End pt_ResumeTest thred %p tid %X\n", thred, thred->id));
} /* pt_ResumeTest */
static pthread_once_t pt_gc_support_control = PTHREAD_ONCE_INIT;
@@ -1535,8 +1569,9 @@ PR_IMPLEMENT(void) PR_SuspendAll(void)
#endif
while (thred != NULL)
{
- if ((thred != me) && _PT_IS_GCABLE_THREAD(thred))
- pt_SuspendSet(thred);
+ if ((thred != me) && _PT_IS_GCABLE_THREAD(thred)) {
+ pt_SuspendSet(thred);
+ }
thred = thred->next;
}
@@ -1544,8 +1579,9 @@ PR_IMPLEMENT(void) PR_SuspendAll(void)
thred = pt_book.first;
while (thred != NULL)
{
- if ((thred != me) && _PT_IS_GCABLE_THREAD(thred))
+ if ((thred != me) && _PT_IS_GCABLE_THREAD(thred)) {
pt_SuspendTest(thred);
+ }
thred = thred->next;
}
@@ -1554,8 +1590,8 @@ PR_IMPLEMENT(void) PR_SuspendAll(void)
#ifdef DEBUG
etime = PR_IntervalNow();
PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS,\
- ("End PR_SuspendAll (time %dms)\n",
- PR_IntervalToMilliseconds(etime - stime)));
+ ("End PR_SuspendAll (time %dms)\n",
+ PR_IntervalToMilliseconds(etime - stime)));
#endif
} /* PR_SuspendAll */
@@ -1577,16 +1613,18 @@ PR_IMPLEMENT(void) PR_ResumeAll(void)
while (thred != NULL)
{
- if ((thred != me) && _PT_IS_GCABLE_THREAD(thred))
- pt_ResumeSet(thred);
+ if ((thred != me) && _PT_IS_GCABLE_THREAD(thred)) {
+ pt_ResumeSet(thred);
+ }
thred = thred->next;
}
thred = pt_book.first;
while (thred != NULL)
{
- if ((thred != me) && _PT_IS_GCABLE_THREAD(thred))
- pt_ResumeTest(thred);
+ if ((thred != me) && _PT_IS_GCABLE_THREAD(thred)) {
+ pt_ResumeTest(thred);
+ }
thred = thred->next;
}
@@ -1595,17 +1633,17 @@ PR_IMPLEMENT(void) PR_ResumeAll(void)
suspendAllOn = PR_FALSE;
etime = PR_IntervalNow();
PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS,
- ("End PR_ResumeAll (time %dms)\n",
- PR_IntervalToMilliseconds(etime - stime)));
+ ("End PR_ResumeAll (time %dms)\n",
+ PR_IntervalToMilliseconds(etime - stime)));
#endif
} /* PR_ResumeAll */
/* Return the stack pointer for the given thread- used by the GC */
PR_IMPLEMENT(void *)PR_GetSP(PRThread *thred)
{
- PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS,
- ("in PR_GetSP thred %p thid = %X, sp = %p\n",
- thred, thred->id, thred->sp));
+ PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS,
+ ("in PR_GetSP thred %p thid = %X, sp = %p\n",
+ thred, thred->id, thred->sp));
return thred->sp;
} /* PR_GetSP */
@@ -1621,18 +1659,22 @@ PR_IMPLEMENT(PRStatus) PR_SetCurrentThreadName(const char *name)
}
thread = PR_GetCurrentThread();
- if (!thread)
+ if (!thread) {
return PR_FAILURE;
+ }
PR_Free(thread->name);
nameLen = strlen(name);
thread->name = (char *)PR_Malloc(nameLen + 1);
- if (!thread->name)
+ if (!thread->name) {
return PR_FAILURE;
+ }
memcpy(thread->name, name, nameLen + 1);
#if defined(OPENBSD) || defined(FREEBSD) || defined(DRAGONFLY)
pthread_set_name_np(thread->id, name);
+#elif defined(ANDROID)
+ prctl(PR_SET_NAME, (unsigned long)(name));
#elif defined(NETBSD)
result = pthread_setname_np(thread->id, "%s", (void *)name);
#else /* not BSD */
@@ -1648,8 +1690,9 @@ PR_IMPLEMENT(PRStatus) PR_SetCurrentThreadName(const char *name)
*(void**)(&dynamic_pthread_setname_np) =
dlsym(RTLD_DEFAULT, "pthread_setname_np");
- if (!dynamic_pthread_setname_np)
+ if (!dynamic_pthread_setname_np) {
return PR_SUCCESS;
+ }
/*
* The 15-character name length limit is an experimentally determined
@@ -1688,8 +1731,9 @@ PR_IMPLEMENT(PRStatus) PR_SetCurrentThreadName(const char *name)
PR_IMPLEMENT(const char *) PR_GetThreadName(const PRThread *thread)
{
- if (!thread)
+ if (!thread) {
return NULL;
+ }
return thread->name;
}
diff --git a/nsprpub/pr/src/threads/combined/prucpu.c b/nsprpub/pr/src/threads/combined/prucpu.c
index 3913dc8de..25ffcce86 100644
--- a/nsprpub/pr/src/threads/combined/prucpu.c
+++ b/nsprpub/pr/src/threads/combined/prucpu.c
@@ -41,8 +41,9 @@ void _PR_InitCPUs()
{
PRThread *me = _PR_MD_CURRENT_THREAD();
- if (_native_threads_only)
+ if (_native_threads_only) {
return;
+ }
_pr_cpuID = 0;
_MD_NEW_LOCK( &_pr_cpuLock);
@@ -119,13 +120,14 @@ static _PRCPUQueue *_PR_CreateCPUQueue(void)
PRInt32 index;
_PRCPUQueue *cpuQueue;
cpuQueue = PR_NEWZAP(_PRCPUQueue);
-
+
_MD_NEW_LOCK( &cpuQueue->runQLock );
_MD_NEW_LOCK( &cpuQueue->sleepQLock );
_MD_NEW_LOCK( &cpuQueue->miscQLock );
- for (index = 0; index < PR_ARRAY_SIZE(cpuQueue->runQ); index++)
+ for (index = 0; index < PR_ARRAY_SIZE(cpuQueue->runQ); index++) {
PR_INIT_CLIST( &(cpuQueue->runQ[index]) );
+ }
PR_INIT_CLIST( &(cpuQueue->sleepQ) );
PR_INIT_CLIST( &(cpuQueue->pauseQ) );
PR_INIT_CLIST( &(cpuQueue->suspendQ) );
@@ -191,7 +193,7 @@ static PRStatus _PR_StartCPU(_PRCPU *cpu, PRThread *thread)
cpu->last_clock = PR_IntervalNow();
/* Before we create any threads on this CPU we have to
- * set the current CPU
+ * set the current CPU
*/
_PR_MD_SET_CURRENT_CPU(cpu);
_PR_MD_INIT_RUNNING_CPU(cpu);
@@ -210,15 +212,16 @@ static PRStatus _PR_StartCPU(_PRCPU *cpu, PRThread *thread)
/* didn't clean up CPU queue XXXMB */
PR_DELETE(cpu);
return PR_FAILURE;
- }
+ }
PR_ASSERT(cpu->idle_thread->cpu == cpu);
cpu->idle_thread->no_sched = 0;
cpu->thread = thread;
- if (_pr_cpu_affinity_mask)
+ if (_pr_cpu_affinity_mask) {
PR_SetThreadAffinityMask(thread, _pr_cpu_affinity_mask);
+ }
/* Created and started a new CPU */
_PR_CPU_LIST_LOCK();
@@ -273,8 +276,10 @@ static void _PR_RunCPU(void *arg)
while(1) {
PRInt32 is;
- if (!_PR_IS_NATIVE_THREAD(me)) _PR_INTSOFF(is);
- _PR_MD_START_INTERRUPTS();
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
+ _PR_MD_START_INTERRUPTS();
_PR_MD_SWITCH_CONTEXT(me);
}
}
@@ -289,13 +294,18 @@ static void PR_CALLBACK _PR_CPU_Idle(void *_cpu)
me->cpu = cpu;
cpu->idle_thread = me;
- if (_MD_LAST_THREAD())
+ if (_MD_LAST_THREAD()) {
_MD_LAST_THREAD()->no_sched = 0;
- if (!_PR_IS_NATIVE_THREAD(me)) _PR_MD_SET_INTSOFF(0);
+ }
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_MD_SET_INTSOFF(0);
+ }
while(1) {
PRInt32 is;
PRIntervalTime timeout;
- if (!_PR_IS_NATIVE_THREAD(me)) _PR_INTSOFF(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
_PR_RUNQ_LOCK(cpu);
#if !defined(_PR_LOCAL_THREADS_ONLY) && !defined(_PR_GLOBAL_THREADS_ONLY)
@@ -345,14 +355,16 @@ static void PR_CALLBACK _PR_CPU_Idle(void *_cpu)
#endif /* _PR_HAVE_ATOMIC_OPS */
#endif
- _PR_ClockInterrupt();
+ _PR_ClockInterrupt();
- /* Now schedule any thread that is on the runq
- * INTS must be OFF when calling PR_Schedule()
- */
- me->state = _PR_RUNNABLE;
- _PR_MD_SWITCH_CONTEXT(me);
- if (!_PR_IS_NATIVE_THREAD(me)) _PR_FAST_INTSON(is);
+ /* Now schedule any thread that is on the runq
+ * INTS must be OFF when calling PR_Schedule()
+ */
+ me->state = _PR_RUNNABLE;
+ _PR_MD_SWITCH_CONTEXT(me);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_FAST_INTSON(is);
+ }
}
}
#endif /* _PR_GLOBAL_THREADS_ONLY */
@@ -370,36 +382,43 @@ PR_IMPLEMENT(void) PR_SetConcurrency(PRUintn numCPUs)
PRThread *thr;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
+
+ if (_native_threads_only) {
+ return;
+ }
- if (_native_threads_only)
- return;
-
_PR_CPU_LIST_LOCK();
if (_pr_numCPU < numCPUs) {
newCPU = numCPUs - _pr_numCPU;
_pr_numCPU = numCPUs;
- } else newCPU = 0;
+ } else {
+ newCPU = 0;
+ }
_PR_CPU_LIST_UNLOCK();
for (; newCPU; newCPU--) {
cpu = _PR_CreateCPU();
thr = _PR_CreateThread(PR_SYSTEM_THREAD,
- _PR_RunCPU,
- cpu,
- PR_PRIORITY_NORMAL,
- PR_GLOBAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0,
- _PR_IDLE_THREAD);
+ _PR_RunCPU,
+ cpu,
+ PR_PRIORITY_NORMAL,
+ PR_GLOBAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0,
+ _PR_IDLE_THREAD);
}
#endif
}
PR_IMPLEMENT(_PRCPU *) _PR_GetPrimordialCPU(void)
{
- if (_pr_primordialCPU)
+ if (_pr_primordialCPU) {
return _pr_primordialCPU;
- else
+ }
+ else {
return _PR_MD_CURRENT_CPU();
+ }
}
diff --git a/nsprpub/pr/src/threads/combined/prucv.c b/nsprpub/pr/src/threads/combined/prucv.c
index d0bf4c422..801d3d2fd 100644
--- a/nsprpub/pr/src/threads/combined/prucv.c
+++ b/nsprpub/pr/src/threads/combined/prucv.c
@@ -10,10 +10,10 @@
#if defined(WIN95)
/*
-** Some local variables report warnings on Win95 because the code paths
+** Some local variables report warnings on Win95 because the code paths
** using them are conditioned on HAVE_CUSTOME_USER_THREADS.
** The pragma suppresses the warning.
-**
+**
*/
#pragma warning(disable : 4101)
#endif
@@ -39,24 +39,25 @@ PRBool _PR_NotifyThread (PRThread *thread, PRThread *me)
/* The notify and timeout can collide; in which case both may
* attempt to delete from the sleepQ; only let one do it.
*/
- if (thread->flags & (_PR_ON_SLEEPQ|_PR_ON_PAUSEQ))
+ if (thread->flags & (_PR_ON_SLEEPQ|_PR_ON_PAUSEQ)) {
_PR_DEL_SLEEPQ(thread, PR_TRUE);
+ }
_PR_SLEEPQ_UNLOCK(thread->cpu);
- if (thread->flags & _PR_SUSPENDING) {
- /*
- * set thread state to SUSPENDED; a Resume operation
- * on the thread will move it to the runQ
- */
- thread->state = _PR_SUSPENDED;
- _PR_MISCQ_LOCK(thread->cpu);
- _PR_ADD_SUSPENDQ(thread, thread->cpu);
- _PR_MISCQ_UNLOCK(thread->cpu);
- _PR_THREAD_UNLOCK(thread);
- } else {
- /* Make thread runnable */
- thread->state = _PR_RUNNABLE;
- _PR_THREAD_UNLOCK(thread);
+ if (thread->flags & _PR_SUSPENDING) {
+ /*
+ * set thread state to SUSPENDED; a Resume operation
+ * on the thread will move it to the runQ
+ */
+ thread->state = _PR_SUSPENDED;
+ _PR_MISCQ_LOCK(thread->cpu);
+ _PR_ADD_SUSPENDQ(thread, thread->cpu);
+ _PR_MISCQ_UNLOCK(thread->cpu);
+ _PR_THREAD_UNLOCK(thread);
+ } else {
+ /* Make thread runnable */
+ thread->state = _PR_RUNNABLE;
+ _PR_THREAD_UNLOCK(thread);
_PR_AddThreadToRunQ(me, thread);
_PR_MD_WAKEUP_WAITER(thread);
@@ -72,29 +73,30 @@ PRBool _PR_NotifyThread (PRThread *thread, PRThread *me)
if (thread->wait.cvar) {
thread->wait.cvar = NULL;
- if (thread->flags & _PR_SUSPENDING) {
- /*
- * set thread state to SUSPENDED; a Resume operation
- * on the thread will enable the thread to run
- */
- thread->state = _PR_SUSPENDED;
- } else
- thread->state = _PR_RUNNING;
+ if (thread->flags & _PR_SUSPENDING) {
+ /*
+ * set thread state to SUSPENDED; a Resume operation
+ * on the thread will enable the thread to run
+ */
+ thread->state = _PR_SUSPENDED;
+ } else {
+ thread->state = _PR_RUNNING;
+ }
_PR_THREAD_UNLOCK(thread);
_PR_MD_WAKEUP_WAITER(thread);
rv = PR_TRUE;
} else {
_PR_THREAD_UNLOCK(thread);
rv = PR_FALSE;
- }
- }
+ }
+ }
return rv;
}
/*
* Notify thread waiting on cvar; called when thread is interrupted
- * The thread lock is held on entry and released before return
+ * The thread lock is held on entry and released before return
*/
void _PR_NotifyLockedThread (PRThread *thread)
{
@@ -102,8 +104,9 @@ void _PR_NotifyLockedThread (PRThread *thread)
PRCondVar *cvar;
PRThreadPriority pri;
- if ( !_PR_IS_NATIVE_THREAD(me))
- PR_ASSERT(_PR_MD_GET_INTSOFF() != 0);
+ if ( !_PR_IS_NATIVE_THREAD(me)) {
+ PR_ASSERT(_PR_MD_GET_INTSOFF() != 0);
+ }
cvar = thread->wait.cvar;
thread->wait.cvar = NULL;
@@ -113,36 +116,38 @@ void _PR_NotifyLockedThread (PRThread *thread)
_PR_THREAD_LOCK(thread);
if (!_PR_IS_NATIVE_THREAD(thread)) {
- _PR_SLEEPQ_LOCK(thread->cpu);
- /* The notify and timeout can collide; in which case both may
- * attempt to delete from the sleepQ; only let one do it.
- */
- if (thread->flags & (_PR_ON_SLEEPQ|_PR_ON_PAUSEQ))
- _PR_DEL_SLEEPQ(thread, PR_TRUE);
- _PR_SLEEPQ_UNLOCK(thread->cpu);
+ _PR_SLEEPQ_LOCK(thread->cpu);
+ /* The notify and timeout can collide; in which case both may
+ * attempt to delete from the sleepQ; only let one do it.
+ */
+ if (thread->flags & (_PR_ON_SLEEPQ|_PR_ON_PAUSEQ)) {
+ _PR_DEL_SLEEPQ(thread, PR_TRUE);
+ }
+ _PR_SLEEPQ_UNLOCK(thread->cpu);
- /* Make thread runnable */
- pri = thread->priority;
- thread->state = _PR_RUNNABLE;
+ /* Make thread runnable */
+ pri = thread->priority;
+ thread->state = _PR_RUNNABLE;
- PR_ASSERT(!(thread->flags & _PR_IDLE_THREAD));
+ PR_ASSERT(!(thread->flags & _PR_IDLE_THREAD));
- _PR_AddThreadToRunQ(me, thread);
- _PR_THREAD_UNLOCK(thread);
+ _PR_AddThreadToRunQ(me, thread);
+ _PR_THREAD_UNLOCK(thread);
- _PR_MD_WAKEUP_WAITER(thread);
+ _PR_MD_WAKEUP_WAITER(thread);
} else {
- if (thread->flags & _PR_SUSPENDING) {
- /*
- * set thread state to SUSPENDED; a Resume operation
- * on the thread will enable the thread to run
- */
- thread->state = _PR_SUSPENDED;
- } else
- thread->state = _PR_RUNNING;
- _PR_THREAD_UNLOCK(thread);
- _PR_MD_WAKEUP_WAITER(thread);
- }
+ if (thread->flags & _PR_SUSPENDING) {
+ /*
+ * set thread state to SUSPENDED; a Resume operation
+ * on the thread will enable the thread to run
+ */
+ thread->state = _PR_SUSPENDED;
+ } else {
+ thread->state = _PR_RUNNING;
+ }
+ _PR_THREAD_UNLOCK(thread);
+ _PR_MD_WAKEUP_WAITER(thread);
+ }
_PR_CVAR_UNLOCK(cvar);
return;
@@ -181,8 +186,9 @@ PRStatus _PR_WaitCondVar(
return PR_SUCCESS;
#else /* _PR_GLOBAL_THREADS_ONLY */
- if ( !_PR_IS_NATIVE_THREAD(thread))
- _PR_INTSOFF(is);
+ if ( !_PR_IS_NATIVE_THREAD(thread)) {
+ _PR_INTSOFF(is);
+ }
_PR_CVAR_LOCK(cvar);
_PR_THREAD_LOCK(thread);
@@ -190,10 +196,11 @@ PRStatus _PR_WaitCondVar(
if (_PR_PENDING_INTERRUPT(thread)) {
PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);
thread->flags &= ~_PR_INTERRUPT;
- _PR_CVAR_UNLOCK(cvar);
- _PR_THREAD_UNLOCK(thread);
- if ( !_PR_IS_NATIVE_THREAD(thread))
- _PR_INTSON(is);
+ _PR_CVAR_UNLOCK(cvar);
+ _PR_THREAD_UNLOCK(thread);
+ if ( !_PR_IS_NATIVE_THREAD(thread)) {
+ _PR_INTSON(is);
+ }
return PR_FAILURE;
}
@@ -216,15 +223,15 @@ PRStatus _PR_WaitCondVar(
}
_PR_CVAR_UNLOCK(cvar);
_PR_THREAD_UNLOCK(thread);
-
- /*
- ** Release lock protecting the condition variable and thereby giving time
+
+ /*
+ ** Release lock protecting the condition variable and thereby giving time
** to the next thread which can potentially notify on the condition variable
*/
PR_Unlock(lock);
PR_LOG(_pr_cvar_lm, PR_LOG_MIN,
- ("PR_Wait: cvar=%p waiting for %d", cvar, timeout));
+ ("PR_Wait: cvar=%p waiting for %d", cvar, timeout));
rv = _PR_MD_WAIT(thread, timeout);
@@ -233,10 +240,11 @@ PRStatus _PR_WaitCondVar(
_PR_CVAR_UNLOCK(cvar);
PR_LOG(_pr_cvar_lm, PR_LOG_MIN,
- ("PR_Wait: cvar=%p done waiting", cvar));
+ ("PR_Wait: cvar=%p done waiting", cvar));
- if ( !_PR_IS_NATIVE_THREAD(thread))
- _PR_INTSON(is);
+ if ( !_PR_IS_NATIVE_THREAD(thread)) {
+ _PR_INTSON(is);
+ }
/* Acquire lock again that we had just relinquished */
PR_Lock(lock);
@@ -260,8 +268,9 @@ void _PR_NotifyCondVar(PRCondVar *cvar, PRThread *me)
PRCList *q;
PRIntn is;
- if ( !_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
+ if ( !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
PR_ASSERT(_PR_IS_NATIVE_THREAD(me) || _PR_MD_GET_INTSOFF() != 0);
_PR_CVAR_LOCK(cvar);
@@ -269,15 +278,17 @@ void _PR_NotifyCondVar(PRCondVar *cvar, PRThread *me)
while (q != &cvar->condQ) {
PR_LOG(_pr_cvar_lm, PR_LOG_MIN, ("_PR_NotifyCondVar: cvar=%p", cvar));
if (_PR_THREAD_CONDQ_PTR(q)->wait.cvar) {
- if (_PR_NotifyThread(_PR_THREAD_CONDQ_PTR(q), me) == PR_TRUE)
+ if (_PR_NotifyThread(_PR_THREAD_CONDQ_PTR(q), me) == PR_TRUE) {
break;
+ }
}
q = q->next;
}
_PR_CVAR_UNLOCK(cvar);
- if ( !_PR_IS_NATIVE_THREAD(me))
- _PR_INTSON(is);
+ if ( !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSON(is);
+ }
#endif /* _PR_GLOBAL_THREADS_ONLY */
}
@@ -290,10 +301,10 @@ PRUint32 _PR_CondVarToString(PRCondVar *cvar, char *buf, PRUint32 buflen)
PRUint32 nb;
if (cvar->lock->owner) {
- nb = PR_snprintf(buf, buflen, "[%p] owner=%ld[%p]",
- cvar, cvar->lock->owner->id, cvar->lock->owner);
+ nb = PR_snprintf(buf, buflen, "[%p] owner=%ld[%p]",
+ cvar, cvar->lock->owner->id, cvar->lock->owner);
} else {
- nb = PR_snprintf(buf, buflen, "[%p]", cvar);
+ nb = PR_snprintf(buf, buflen, "[%p]", cvar);
}
return nb;
}
@@ -307,7 +318,7 @@ void _PR_ClockInterrupt(void)
PRThread *thread, *me = _PR_MD_CURRENT_THREAD();
_PRCPU *cpu = me->cpu;
PRIntervalTime elapsed, now;
-
+
PR_ASSERT(_PR_MD_GET_INTSOFF() != 0);
/* Figure out how much time elapsed since the last clock tick */
now = PR_IntervalNow();
@@ -315,7 +326,7 @@ void _PR_ClockInterrupt(void)
cpu->last_clock = now;
PR_LOG(_pr_clock_lm, PR_LOG_MAX,
- ("ExpireWaits: elapsed=%lld usec", elapsed));
+ ("ExpireWaits: elapsed=%lld usec", elapsed));
while(1) {
_PR_SLEEPQ_LOCK(cpu);
@@ -370,8 +381,8 @@ void _PR_ClockInterrupt(void)
/* Notify the thread waiting on the condition variable */
if (thread->flags & _PR_SUSPENDING) {
- PR_ASSERT((thread->state == _PR_IO_WAIT) ||
- (thread->state == _PR_COND_WAIT));
+ PR_ASSERT((thread->state == _PR_IO_WAIT) ||
+ (thread->state == _PR_COND_WAIT));
/*
** Thread is suspended and its condition timeout
** expired. Transfer thread from sleepQ to suspendQ.
@@ -398,8 +409,9 @@ void _PR_ClockInterrupt(void)
_PR_ADD_RUNQ(thread, cpu, pri);
_PR_RUNQ_UNLOCK(cpu);
- if (pri > me->priority)
+ if (pri > me->priority) {
_PR_SET_RESCHED_FLAG();
+ }
thread->wait.cvar = NULL;
@@ -411,14 +423,14 @@ void _PR_ClockInterrupt(void)
thread->io_suspended = PR_TRUE;
#ifdef WINNT
- /*
- * For NT, record the cpu on which I/O was issued
- * I/O cancellation is done on the same cpu
- */
+ /*
+ * For NT, record the cpu on which I/O was issued
+ * I/O cancellation is done on the same cpu
+ */
thread->md.thr_bound_cpu = cpu;
#endif
- PR_ASSERT(!(thread->flags & _PR_IDLE_THREAD));
+ PR_ASSERT(!(thread->flags & _PR_IDLE_THREAD));
PR_ASSERT(thread->cpu == cpu);
thread->state = _PR_RUNNABLE;
_PR_RUNQ_LOCK(cpu);
@@ -434,7 +446,7 @@ void _PR_ClockInterrupt(void)
/*
** Create a new condition variable.
-** "lock" is the lock to use with the condition variable.
+** "lock" is the lock to use with the condition variable.
**
** Condition variables are synchronization objects that threads can use
** to wait for some condition to occur.
@@ -518,11 +530,13 @@ PR_IMPLEMENT(PRStatus) PR_WaitCondVar(PRCondVar *cvar, PRIntervalTime timeout)
{
PRThread *me = _PR_MD_CURRENT_THREAD();
- PR_ASSERT(cvar->lock->owner == me);
- PR_ASSERT(me != suspendAllThread);
- if (cvar->lock->owner != me) return PR_FAILURE;
+ PR_ASSERT(cvar->lock->owner == me);
+ PR_ASSERT(me != suspendAllThread);
+ if (cvar->lock->owner != me) {
+ return PR_FAILURE;
+ }
- return _PR_WaitCondVar(me, cvar, cvar->lock, timeout);
+ return _PR_WaitCondVar(me, cvar, cvar->lock, timeout);
}
/*
@@ -536,7 +550,9 @@ PR_IMPLEMENT(PRStatus) PR_NotifyCondVar(PRCondVar *cvar)
PR_ASSERT(cvar->lock->owner == me);
PR_ASSERT(me != suspendAllThread);
- if (cvar->lock->owner != me) return PR_FAILURE;
+ if (cvar->lock->owner != me) {
+ return PR_FAILURE;
+ }
_PR_NotifyCondVar(cvar, me);
return PR_SUCCESS;
@@ -554,24 +570,28 @@ PR_IMPLEMENT(PRStatus) PR_NotifyAllCondVar(PRCondVar *cvar)
PRThread *me = _PR_MD_CURRENT_THREAD();
PR_ASSERT(cvar->lock->owner == me);
- if (cvar->lock->owner != me) return PR_FAILURE;
+ if (cvar->lock->owner != me) {
+ return PR_FAILURE;
+ }
#ifdef _PR_GLOBAL_THREADS_ONLY
_PR_MD_NOTIFYALL_CV(&cvar->md, &cvar->lock->ilock);
return PR_SUCCESS;
#else /* _PR_GLOBAL_THREADS_ONLY */
- if ( !_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
+ if ( !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
_PR_CVAR_LOCK(cvar);
q = cvar->condQ.next;
while (q != &cvar->condQ) {
- PR_LOG(_pr_cvar_lm, PR_LOG_MIN, ("PR_NotifyAll: cvar=%p", cvar));
- _PR_NotifyThread(_PR_THREAD_CONDQ_PTR(q), me);
- q = q->next;
+ PR_LOG(_pr_cvar_lm, PR_LOG_MIN, ("PR_NotifyAll: cvar=%p", cvar));
+ _PR_NotifyThread(_PR_THREAD_CONDQ_PTR(q), me);
+ q = q->next;
}
_PR_CVAR_UNLOCK(cvar);
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSON(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSON(is);
+ }
return PR_SUCCESS;
#endif /* _PR_GLOBAL_THREADS_ONLY */
@@ -592,13 +612,13 @@ PR_IMPLEMENT(PRCondVar*) PRP_NewNakedCondVar(void)
{
if (_PR_MD_NEW_LOCK(&(cvar->ilock)) == PR_FAILURE)
{
- PR_DELETE(cvar); cvar = NULL;
- }
- else
- {
- PR_INIT_CLIST(&cvar->condQ);
+ PR_DELETE(cvar); cvar = NULL;
+ }
+ else
+ {
+ PR_INIT_CLIST(&cvar->condQ);
cvar->lock = _PR_NAKED_CV_LOCK;
- }
+ }
}
return cvar;
@@ -610,16 +630,16 @@ PR_IMPLEMENT(void) PRP_DestroyNakedCondVar(PRCondVar *cvar)
PR_ASSERT(_PR_NAKED_CV_LOCK == cvar->lock);
_PR_MD_FREE_LOCK(&(cvar->ilock));
-
+
PR_DELETE(cvar);
}
PR_IMPLEMENT(PRStatus) PRP_NakedWait(
- PRCondVar *cvar, PRLock *lock, PRIntervalTime timeout)
+ PRCondVar *cvar, PRLock *lock, PRIntervalTime timeout)
{
PRThread *me = _PR_MD_CURRENT_THREAD();
PR_ASSERT(_PR_NAKED_CV_LOCK == cvar->lock);
- return _PR_WaitCondVar(me, cvar, lock, timeout);
+ return _PR_WaitCondVar(me, cvar, lock, timeout);
} /* PRP_NakedWait */
PR_IMPLEMENT(PRStatus) PRP_NakedNotify(PRCondVar *cvar)
@@ -639,16 +659,20 @@ PR_IMPLEMENT(PRStatus) PRP_NakedBroadcast(PRCondVar *cvar)
PRThread *me = _PR_MD_CURRENT_THREAD();
PR_ASSERT(_PR_NAKED_CV_LOCK == cvar->lock);
- if ( !_PR_IS_NATIVE_THREAD(me)) _PR_INTSOFF(is);
- _PR_MD_LOCK( &(cvar->ilock) );
+ if ( !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
+ _PR_MD_LOCK( &(cvar->ilock) );
q = cvar->condQ.next;
while (q != &cvar->condQ) {
- PR_LOG(_pr_cvar_lm, PR_LOG_MIN, ("PR_NotifyAll: cvar=%p", cvar));
- _PR_NotifyThread(_PR_THREAD_CONDQ_PTR(q), me);
- q = q->next;
+ PR_LOG(_pr_cvar_lm, PR_LOG_MIN, ("PR_NotifyAll: cvar=%p", cvar));
+ _PR_NotifyThread(_PR_THREAD_CONDQ_PTR(q), me);
+ q = q->next;
+ }
+ _PR_MD_UNLOCK( &(cvar->ilock) );
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSON(is);
}
- _PR_MD_UNLOCK( &(cvar->ilock) );
- if (!_PR_IS_NATIVE_THREAD(me)) _PR_INTSON(is);
return PR_SUCCESS;
} /* PRP_NakedBroadcast */
diff --git a/nsprpub/pr/src/threads/combined/prulock.c b/nsprpub/pr/src/threads/combined/prulock.c
index 8b2f41eec..69c27d149 100644
--- a/nsprpub/pr/src/threads/combined/prulock.c
+++ b/nsprpub/pr/src/threads/combined/prulock.c
@@ -7,10 +7,10 @@
#if defined(WIN95)
/*
-** Some local variables report warnings on Win95 because the code paths
+** Some local variables report warnings on Win95 because the code paths
** using them are conditioned on HAVE_CUSTOME_USER_THREADS.
** The pragma suppresses the warning.
-**
+**
*/
#pragma warning(disable : 4101)
#endif
@@ -18,7 +18,7 @@
void _PR_InitLocks(void)
{
- _PR_MD_INIT_LOCKS();
+ _PR_MD_INIT_LOCKS();
}
/*
@@ -33,7 +33,7 @@ void _PR_IntsOn(_PRCPU *cpu)
PR_ASSERT(cpu); /* Global threads don't have CPUs */
PR_ASSERT(_PR_MD_GET_INTSOFF() > 0);
- me = _PR_MD_CURRENT_THREAD();
+ me = _PR_MD_CURRENT_THREAD();
PR_ASSERT(!(me->flags & _PR_IDLE_THREAD));
/*
@@ -69,15 +69,15 @@ void _PR_IntsOn(_PRCPU *cpu)
if (cpu->u.missed[3] != 0) {
_PRCPU *cpu;
- _PR_THREAD_LOCK(me);
+ _PR_THREAD_LOCK(me);
me->state = _PR_RUNNABLE;
pri = me->priority;
cpu = me->cpu;
- _PR_RUNQ_LOCK(cpu);
+ _PR_RUNQ_LOCK(cpu);
_PR_ADD_RUNQ(me, cpu, pri);
- _PR_RUNQ_UNLOCK(cpu);
- _PR_THREAD_UNLOCK(me);
+ _PR_RUNQ_UNLOCK(cpu);
+ _PR_THREAD_UNLOCK(me);
_PR_MD_SWITCH_CONTEXT(me);
}
}
@@ -99,11 +99,11 @@ void _PR_UnblockLockWaiter(PRLock *lock)
/* Unblock first waiter */
t = _PR_THREAD_CONDQ_PTR(q);
- /*
- ** We are about to change the thread's state to runnable and for local
- ** threads, we are going to assign a cpu to it. So, protect thread's
- ** data structure.
- */
+ /*
+ ** We are about to change the thread's state to runnable and for local
+ ** threads, we are going to assign a cpu to it. So, protect thread's
+ ** data structure.
+ */
_PR_THREAD_LOCK(t);
if (t->flags & _PR_SUSPENDING) {
@@ -113,24 +113,24 @@ void _PR_UnblockLockWaiter(PRLock *lock)
}
/* Found a runnable thread */
- PR_ASSERT(t->state == _PR_LOCK_WAIT);
- PR_ASSERT(t->wait.lock == lock);
+ PR_ASSERT(t->state == _PR_LOCK_WAIT);
+ PR_ASSERT(t->wait.lock == lock);
t->wait.lock = 0;
PR_REMOVE_LINK(&t->waitQLinks); /* take it off lock's waitQ */
- /*
- ** If this is a native thread, nothing else to do except to wake it
- ** up by calling the machine dependent wakeup routine.
- **
- ** If this is a local thread, we need to assign it a cpu and
- ** put the thread on that cpu's run queue. There are two cases to
- ** take care of. If the currently running thread is also a local
- ** thread, we just assign our own cpu to that thread and put it on
- ** the cpu's run queue. If the the currently running thread is a
- ** native thread, we assign the primordial cpu to it (on NT,
- ** MD_WAKEUP handles the cpu assignment).
- */
-
+ /*
+ ** If this is a native thread, nothing else to do except to wake it
+ ** up by calling the machine dependent wakeup routine.
+ **
+ ** If this is a local thread, we need to assign it a cpu and
+ ** put the thread on that cpu's run queue. There are two cases to
+ ** take care of. If the currently running thread is also a local
+ ** thread, we just assign our own cpu to that thread and put it on
+ ** the cpu's run queue. If the the currently running thread is a
+ ** native thread, we assign the primordial cpu to it (on NT,
+ ** MD_WAKEUP handles the cpu assignment).
+ */
+
if ( !_PR_IS_NATIVE_THREAD(t) ) {
t->state = _PR_RUNNABLE;
@@ -156,7 +156,9 @@ PR_IMPLEMENT(PRLock*) PR_NewLock(void)
{
PRLock *lock;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
lock = PR_NEWZAP(PRLock);
if (lock) {
@@ -206,25 +208,26 @@ PR_IMPLEMENT(void) PR_Lock(PRLock *lock)
PRThread *t;
PRCList *q;
- PR_ASSERT(me != suspendAllThread);
+ PR_ASSERT(me != suspendAllThread);
PR_ASSERT(!(me->flags & _PR_IDLE_THREAD));
PR_ASSERT(lock != NULL);
-#ifdef _PR_GLOBAL_THREADS_ONLY
+#ifdef _PR_GLOBAL_THREADS_ONLY
_PR_MD_LOCK(&lock->ilock);
PR_ASSERT(lock->owner == 0);
lock->owner = me;
return;
#else /* _PR_GLOBAL_THREADS_ONLY */
- if (_native_threads_only) {
- _PR_MD_LOCK(&lock->ilock);
- PR_ASSERT(lock->owner == 0);
- lock->owner = me;
- return;
- }
+ if (_native_threads_only) {
+ _PR_MD_LOCK(&lock->ilock);
+ PR_ASSERT(lock->owner == 0);
+ lock->owner = me;
+ return;
+ }
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
PR_ASSERT(_PR_IS_NATIVE_THREAD(me) || _PR_MD_GET_INTSOFF() != 0);
@@ -234,11 +237,12 @@ retry:
/* Just got the lock */
lock->owner = me;
lock->priority = me->priority;
- /* Add the granted lock to this owning thread's lock list */
+ /* Add the granted lock to this owning thread's lock list */
PR_APPEND_LINK(&lock->links, &me->lockList);
_PR_LOCK_UNLOCK(lock);
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_FAST_INTSON(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_FAST_INTSON(is);
+ }
return;
}
@@ -258,39 +262,39 @@ retry:
}
#endif
- /*
+ /*
Add this thread to the asked for lock's list of waiting threads. We
add this thread thread in the right priority order so when the unlock
occurs, the thread with the higher priority will get the lock.
*/
q = lock->waitQ.next;
if (q == &lock->waitQ || _PR_THREAD_CONDQ_PTR(q)->priority ==
- _PR_THREAD_CONDQ_PTR(lock->waitQ.prev)->priority) {
- /*
- * If all the threads in the lock waitQ have the same priority,
- * then avoid scanning the list: insert the element at the end.
- */
- q = &lock->waitQ;
+ _PR_THREAD_CONDQ_PTR(lock->waitQ.prev)->priority) {
+ /*
+ * If all the threads in the lock waitQ have the same priority,
+ * then avoid scanning the list: insert the element at the end.
+ */
+ q = &lock->waitQ;
} else {
- /* Sort thread into lock's waitQ at appropriate point */
- /* Now scan the list for where to insert this entry */
- while (q != &lock->waitQ) {
- t = _PR_THREAD_CONDQ_PTR(lock->waitQ.next);
- if (me->priority > t->priority) {
- /* Found a lower priority thread to insert in front of */
- break;
- }
- q = q->next;
- }
- }
+ /* Sort thread into lock's waitQ at appropriate point */
+ /* Now scan the list for where to insert this entry */
+ while (q != &lock->waitQ) {
+ t = _PR_THREAD_CONDQ_PTR(lock->waitQ.next);
+ if (me->priority > t->priority) {
+ /* Found a lower priority thread to insert in front of */
+ break;
+ }
+ q = q->next;
+ }
+ }
PR_INSERT_BEFORE(&me->waitQLinks, q);
- /*
- Now grab the threadLock since we are about to change the state. We have
- to do this since a PR_Suspend or PR_SetThreadPriority type call that takes
- a PRThread* as an argument could be changing the state of this thread from
- a thread running on a different cpu.
- */
+ /*
+ Now grab the threadLock since we are about to change the state. We have
+ to do this since a PR_Suspend or PR_SetThreadPriority type call that takes
+ a PRThread* as an argument could be changing the state of this thread from
+ a thread running on a different cpu.
+ */
_PR_THREAD_LOCK(me);
me->state = _PR_LOCK_WAIT;
@@ -300,7 +304,7 @@ retry:
_PR_LOCK_UNLOCK(lock);
_PR_MD_WAIT(me, PR_INTERVAL_NO_TIMEOUT);
- goto retry;
+ goto retry;
#endif /* _PR_GLOBAL_THREADS_ONLY */
}
@@ -317,29 +321,30 @@ PR_IMPLEMENT(PRStatus) PR_Unlock(PRLock *lock)
PR_ASSERT(lock != NULL);
PR_ASSERT(lock->owner == me);
- PR_ASSERT(me != suspendAllThread);
+ PR_ASSERT(me != suspendAllThread);
PR_ASSERT(!(me->flags & _PR_IDLE_THREAD));
if (lock->owner != me) {
return PR_FAILURE;
}
-#ifdef _PR_GLOBAL_THREADS_ONLY
+#ifdef _PR_GLOBAL_THREADS_ONLY
lock->owner = 0;
_PR_MD_UNLOCK(&lock->ilock);
return PR_SUCCESS;
#else /* _PR_GLOBAL_THREADS_ONLY */
- if (_native_threads_only) {
- lock->owner = 0;
- _PR_MD_UNLOCK(&lock->ilock);
- return PR_SUCCESS;
- }
+ if (_native_threads_only) {
+ lock->owner = 0;
+ _PR_MD_UNLOCK(&lock->ilock);
+ return PR_SUCCESS;
+ }
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
_PR_LOCK_LOCK(lock);
- /* Remove the lock from the owning thread's lock list */
+ /* Remove the lock from the owning thread's lock list */
PR_REMOVE_LINK(&lock->links);
pri = lock->priority;
boost = lock->boostPriority;
@@ -365,13 +370,15 @@ PR_IMPLEMENT(PRStatus) PR_Unlock(PRLock *lock)
/* Unblock the first waiting thread */
q = lock->waitQ.next;
- if (q != &lock->waitQ)
+ if (q != &lock->waitQ) {
_PR_UnblockLockWaiter(lock);
+ }
lock->boostPriority = PR_PRIORITY_LOW;
lock->owner = 0;
_PR_LOCK_UNLOCK(lock);
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSON(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSON(is);
+ }
return PR_SUCCESS;
#endif /* _PR_GLOBAL_THREADS_ONLY */
}
@@ -397,7 +404,7 @@ PR_IMPLEMENT(PRBool) PR_TestAndLock(PRLock *lock)
PRBool rv = PR_FALSE;
PRIntn is;
-#ifdef _PR_GLOBAL_THREADS_ONLY
+#ifdef _PR_GLOBAL_THREADS_ONLY
is = _PR_MD_TEST_AND_LOCK(&lock->ilock);
if (is == 0) {
lock->owner = me;
@@ -407,32 +414,34 @@ PR_IMPLEMENT(PRBool) PR_TestAndLock(PRLock *lock)
#else /* _PR_GLOBAL_THREADS_ONLY */
#ifndef _PR_LOCAL_THREADS_ONLY
- if (_native_threads_only) {
- is = _PR_MD_TEST_AND_LOCK(&lock->ilock);
- if (is == 0) {
- lock->owner = me;
- return PR_TRUE;
- }
- return PR_FALSE;
- }
+ if (_native_threads_only) {
+ is = _PR_MD_TEST_AND_LOCK(&lock->ilock);
+ if (is == 0) {
+ lock->owner = me;
+ return PR_TRUE;
+ }
+ return PR_FALSE;
+ }
#endif
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
_PR_LOCK_LOCK(lock);
if (lock->owner == 0) {
/* Just got the lock */
lock->owner = me;
lock->priority = me->priority;
- /* Add the granted lock to this owning thread's lock list */
+ /* Add the granted lock to this owning thread's lock list */
PR_APPEND_LINK(&lock->links, &me->lockList);
rv = PR_TRUE;
}
_PR_LOCK_UNLOCK(lock);
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSON(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSON(is);
+ }
return rv;
#endif /* _PR_GLOBAL_THREADS_ONLY */
}
@@ -443,4 +452,6 @@ PR_IMPLEMENT(PRBool) PR_TestAndLock(PRLock *lock)
/************************************************************************/
/************************************************************************/
PR_IMPLEMENT(PRStatus) PRP_TryLock(PRLock *lock)
- { return (PR_TestAndLock(lock)) ? PR_SUCCESS : PR_FAILURE; }
+{
+ return (PR_TestAndLock(lock)) ? PR_SUCCESS : PR_FAILURE;
+}
diff --git a/nsprpub/pr/src/threads/combined/prustack.c b/nsprpub/pr/src/threads/combined/prustack.c
index 59562bac4..3f5452c48 100644
--- a/nsprpub/pr/src/threads/combined/prustack.c
+++ b/nsprpub/pr/src/threads/combined/prustack.c
@@ -19,7 +19,7 @@ PRBool _pr_debugStacks = PR_FALSE;
#endif
/* How much space to leave between the stacks, at each end */
-#define REDZONE (2 << _pr_pageShift)
+#define REDZONE (2 << _pr_pageShift)
#define _PR_THREAD_STACK_PTR(_qp) \
((PRThreadStack*) ((char*) (_qp) - offsetof(PRThreadStack,links)))
@@ -54,22 +54,23 @@ PRThreadStack *_PR_NewStack(PRUint32 stackSize)
PR_Lock(_pr_stackLock);
qp = _pr_freeStacks.prev;
while ((_pr_numFreeStacks > _pr_maxFreeStacks) && (qp != &_pr_freeStacks)) {
- ts = _PR_THREAD_STACK_PTR(qp);
- thr = _PR_THREAD_STACK_TO_PTR(ts);
- qp = qp->prev;
- /*
- * skip stacks which are still being used
- */
- if (thr->no_sched)
- continue;
- PR_REMOVE_LINK(&ts->links);
-
- /* Give platform OS to clear out the stack for debugging */
- _PR_MD_CLEAR_STACK(ts);
-
- _pr_numFreeStacks--;
- _PR_DestroySegment(ts->seg);
- PR_DELETE(ts);
+ ts = _PR_THREAD_STACK_PTR(qp);
+ thr = _PR_THREAD_STACK_TO_PTR(ts);
+ qp = qp->prev;
+ /*
+ * skip stacks which are still being used
+ */
+ if (thr->no_sched) {
+ continue;
+ }
+ PR_REMOVE_LINK(&ts->links);
+
+ /* Give platform OS to clear out the stack for debugging */
+ _PR_MD_CLEAR_STACK(ts);
+
+ _pr_numFreeStacks--;
+ _PR_DestroySegment(ts->seg);
+ PR_DELETE(ts);
}
/*
@@ -79,51 +80,51 @@ PRThreadStack *_PR_NewStack(PRUint32 stackSize)
qp = _pr_freeStacks.next;
ts = 0;
while (qp != &_pr_freeStacks) {
- ts = _PR_THREAD_STACK_PTR(qp);
- thr = _PR_THREAD_STACK_TO_PTR(ts);
- qp = qp->next;
- /*
- * skip stacks which are still being used
- */
- if ((!(thr->no_sched)) && ((ts->allocSize - 2*REDZONE) >= stackSize)) {
- /*
- ** Found a stack that is not in use and is big enough. Change
- ** stackSize to fit it.
- */
- stackSize = ts->allocSize - 2*REDZONE;
- PR_REMOVE_LINK(&ts->links);
- _pr_numFreeStacks--;
- ts->links.next = 0;
- ts->links.prev = 0;
- PR_Unlock(_pr_stackLock);
- goto done;
- }
- ts = 0;
+ ts = _PR_THREAD_STACK_PTR(qp);
+ thr = _PR_THREAD_STACK_TO_PTR(ts);
+ qp = qp->next;
+ /*
+ * skip stacks which are still being used
+ */
+ if ((!(thr->no_sched)) && ((ts->allocSize - 2*REDZONE) >= stackSize)) {
+ /*
+ ** Found a stack that is not in use and is big enough. Change
+ ** stackSize to fit it.
+ */
+ stackSize = ts->allocSize - 2*REDZONE;
+ PR_REMOVE_LINK(&ts->links);
+ _pr_numFreeStacks--;
+ ts->links.next = 0;
+ ts->links.prev = 0;
+ PR_Unlock(_pr_stackLock);
+ goto done;
+ }
+ ts = 0;
}
PR_Unlock(_pr_stackLock);
if (!ts) {
- /* Make a new thread stack object. */
- ts = PR_NEWZAP(PRThreadStack);
- if (!ts) {
- return NULL;
- }
-
- /*
- ** Assign some of the virtual space to the new stack object. We
- ** may not get that piece of VM, but if nothing else we will
- ** advance the pointer so we don't collide (unless the OS screws
- ** up).
- */
- ts->allocSize = stackSize + 2*REDZONE;
- ts->seg = _PR_NewSegment(ts->allocSize, 0);
- if (!ts->seg) {
- PR_DELETE(ts);
- return NULL;
- }
- }
-
- done:
+ /* Make a new thread stack object. */
+ ts = PR_NEWZAP(PRThreadStack);
+ if (!ts) {
+ return NULL;
+ }
+
+ /*
+ ** Assign some of the virtual space to the new stack object. We
+ ** may not get that piece of VM, but if nothing else we will
+ ** advance the pointer so we don't collide (unless the OS screws
+ ** up).
+ */
+ ts->allocSize = stackSize + 2*REDZONE;
+ ts->seg = _PR_NewSegment(ts->allocSize, 0);
+ if (!ts->seg) {
+ PR_DELETE(ts);
+ return NULL;
+ }
+ }
+
+done:
ts->allocBase = (char*)ts->seg->vaddr;
ts->flags = _PR_STACK_MAPPED;
ts->stackSize = stackSize;
@@ -137,11 +138,11 @@ PRThreadStack *_PR_NewStack(PRUint32 stackSize)
#endif
PR_LOG(_pr_thread_lm, PR_LOG_NOTICE,
- ("thread stack: base=0x%x limit=0x%x bottom=0x%x top=0x%x\n",
- ts->allocBase, ts->allocBase + ts->allocSize - 1,
- ts->allocBase + REDZONE,
- ts->allocBase + REDZONE + stackSize - 1));
-
+ ("thread stack: base=0x%x limit=0x%x bottom=0x%x top=0x%x\n",
+ ts->allocBase, ts->allocBase + ts->allocSize - 1,
+ ts->allocBase + REDZONE,
+ ts->allocBase + REDZONE + stackSize - 1));
+
_PR_MD_INIT_STACK(ts,REDZONE);
return ts;
@@ -153,11 +154,11 @@ PRThreadStack *_PR_NewStack(PRUint32 stackSize)
void _PR_FreeStack(PRThreadStack *ts)
{
if (!ts) {
- return;
+ return;
}
if (ts->flags & _PR_STACK_PRIMORDIAL) {
- PR_DELETE(ts);
- return;
+ PR_DELETE(ts);
+ return;
}
/*
diff --git a/nsprpub/pr/src/threads/combined/pruthr.c b/nsprpub/pr/src/threads/combined/pruthr.c
index 4625ab246..44a082007 100644
--- a/nsprpub/pr/src/threads/combined/pruthr.c
+++ b/nsprpub/pr/src/threads/combined/pruthr.c
@@ -7,7 +7,7 @@
#include <signal.h>
#include <string.h>
-#if defined(WIN95)
+#if defined(WIN95)
/*
** Some local variables report warnings on Win95 because the code paths
** using them are conditioned on HAVE_CUSTOME_USER_THREADS.
@@ -15,7 +15,7 @@
**
*/
#pragma warning(disable : 4101)
-#endif
+#endif
/* _pr_activeLock protects the following global variables */
PRLock *_pr_activeLock;
@@ -28,7 +28,7 @@ PRInt32 _pr_primordialExitCount; /* In PR_Cleanup(), the primordial thread
* If the primordial thread is a system
* thread, then _pr_primordialExitCount
* is 0. If the primordial thread is
- * itself a user thread, then
+ * itself a user thread, then
* _pr_primordialThread is 1.
*/
PRCondVar *_pr_primordialExitCVar; /* When _pr_userActive is decremented to
@@ -60,7 +60,7 @@ static void _PR_InitializeRecycledThread(PRThread *thread);
static void _PR_UserRunThread(void);
void _PR_InitThreads(PRThreadType type, PRThreadPriority priority,
- PRUintn maxPTDs)
+ PRUintn maxPTDs)
{
PRThread *thread;
PRThreadStack *stack;
@@ -74,13 +74,13 @@ void _PR_InitThreads(PRThreadType type, PRThreadPriority priority,
stack = PR_NEWZAP(PRThreadStack);
#ifdef HAVE_STACK_GROWING_UP
stack->stackTop = (char*) ((((PRWord)&type) >> _pr_pageShift)
- << _pr_pageShift);
+ << _pr_pageShift);
#else
#if defined(SOLARIS) || defined (UNIXWARE) && defined (USR_SVR4_THREADS)
stack->stackTop = (char*) &thread;
#else
stack->stackTop = (char*) ((((PRWord)&type + _pr_pageSize - 1)
- >> _pr_pageShift) << _pr_pageShift);
+ >> _pr_pageShift) << _pr_pageShift);
#endif
#endif
#else
@@ -104,11 +104,13 @@ void _PR_InitThreads(PRThreadType type, PRThreadPriority priority,
_pr_userActive++;
_pr_primordialExitCount = 1;
}
- thread->no_sched = 1;
- _pr_primordialExitCVar = PR_NewCondVar(_pr_activeLock);
+ thread->no_sched = 1;
+ _pr_primordialExitCVar = PR_NewCondVar(_pr_activeLock);
}
- if (!thread) PR_Abort();
+ if (!thread) {
+ PR_Abort();
+ }
#ifdef _PR_LOCAL_THREADS_ONLY
thread->flags |= _PR_PRIMORDIAL;
#else
@@ -174,13 +176,13 @@ static void _PR_InitializeNativeStack(PRThreadStack *ts)
** Setup stackTop and stackBottom values.
*/
#ifdef HAVE_STACK_GROWING_UP
- ts->allocBase = (char*) ((((PRWord)&ts) >> _pr_pageShift)
- << _pr_pageShift);
+ ts->allocBase = (char*) ((((PRWord)&ts) >> _pr_pageShift)
+ << _pr_pageShift);
ts->stackBottom = ts->allocBase + ts->stackSize;
ts->stackTop = ts->allocBase;
#else
ts->allocBase = (char*) ((((PRWord)&ts + _pr_pageSize - 1)
- >> _pr_pageShift) << _pr_pageShift);
+ >> _pr_pageShift) << _pr_pageShift);
ts->stackTop = ts->allocBase;
ts->stackBottom = ts->allocBase - ts->stackSize;
#endif
@@ -195,7 +197,7 @@ void _PR_NotifyJoinWaiters(PRThread *thread)
** Notify on our "termination" condition variable so that joining
** thread will know about our termination. Switch our context and
** come back later on to continue the cleanup.
- */
+ */
PR_ASSERT(thread == _PR_MD_CURRENT_THREAD());
if (thread->term != NULL) {
PR_Lock(_pr_terminationCVLock);
@@ -251,19 +253,19 @@ static void _PR_InitializeRecycledThread(PRThread *thread)
PRStatus _PR_RecycleThread(PRThread *thread)
{
if ( _PR_IS_NATIVE_THREAD(thread) &&
- _PR_NUM_DEADNATIVE < _pr_recycleThreads) {
+ _PR_NUM_DEADNATIVE < _pr_recycleThreads) {
_PR_DEADQ_LOCK;
PR_APPEND_LINK(&thread->links, &_PR_DEADNATIVEQ);
_PR_INC_DEADNATIVE;
_PR_DEADQ_UNLOCK;
- return (PR_SUCCESS);
+ return (PR_SUCCESS);
} else if ( !_PR_IS_NATIVE_THREAD(thread) &&
_PR_NUM_DEADUSER < _pr_recycleThreads) {
_PR_DEADQ_LOCK;
PR_APPEND_LINK(&thread->links, &_PR_DEADUSERQ);
_PR_INC_DEADUSER;
_PR_DEADQ_UNLOCK;
- return (PR_SUCCESS);
+ return (PR_SUCCESS);
}
return (PR_FAILURE);
}
@@ -433,7 +435,7 @@ void _PR_NativeRunThread(void *arg)
thread->state = _PR_DEAD_STATE;
if (!_pr_recycleThreads || (_PR_RecycleThread(thread) ==
- PR_FAILURE)) {
+ PR_FAILURE)) {
/*
* thread not recycled
* platform-specific thread exit processing
@@ -460,8 +462,9 @@ static void _PR_UserRunThread(void)
PRThread *thread = _PR_MD_CURRENT_THREAD();
PRIntn is;
- if (_MD_LAST_THREAD())
- _MD_LAST_THREAD()->no_sched = 0;
+ if (_MD_LAST_THREAD()) {
+ _MD_LAST_THREAD()->no_sched = 0;
+ }
#ifdef HAVE_CUSTOM_USER_THREADS
if (thread->stack == NULL) {
@@ -472,17 +475,19 @@ static void _PR_UserRunThread(void)
while(1) {
/* Run thread main */
- if ( !_PR_IS_NATIVE_THREAD(thread)) _PR_MD_SET_INTSOFF(0);
+ if ( !_PR_IS_NATIVE_THREAD(thread)) {
+ _PR_MD_SET_INTSOFF(0);
+ }
- /*
- * Add to list of active threads
- */
- if (!(thread->flags & _PR_IDLE_THREAD)) {
- PR_Lock(_pr_activeLock);
- PR_APPEND_LINK(&thread->active, &_PR_ACTIVE_LOCAL_THREADQ());
- _pr_local_threads++;
- PR_Unlock(_pr_activeLock);
- }
+ /*
+ * Add to list of active threads
+ */
+ if (!(thread->flags & _PR_IDLE_THREAD)) {
+ PR_Lock(_pr_activeLock);
+ PR_APPEND_LINK(&thread->active, &_PR_ACTIVE_LOCAL_THREADQ());
+ _pr_local_threads++;
+ PR_Unlock(_pr_activeLock);
+ }
(*thread->startFunc)(thread->arg);
@@ -504,33 +509,33 @@ static void _PR_UserRunThread(void)
PR_ASSERT(thread->io_suspended == PR_FALSE);
PR_Lock(_pr_activeLock);
- /*
- * remove thread from list of active threads
- */
- if (!(thread->flags & _PR_IDLE_THREAD)) {
- PR_REMOVE_LINK(&thread->active);
- _pr_local_threads--;
- }
- PR_Unlock(_pr_activeLock);
+ /*
+ * remove thread from list of active threads
+ */
+ if (!(thread->flags & _PR_IDLE_THREAD)) {
+ PR_REMOVE_LINK(&thread->active);
+ _pr_local_threads--;
+ }
+ PR_Unlock(_pr_activeLock);
PR_LOG(_pr_thread_lm, PR_LOG_MIN, ("thread exiting"));
/* All done, time to go away */
_PR_CleanupThread(thread);
- _PR_INTSOFF(is);
+ _PR_INTSOFF(is);
_PR_NotifyJoinWaiters(thread);
- _PR_DecrActiveThreadCount(thread);
+ _PR_DecrActiveThreadCount(thread);
thread->state = _PR_DEAD_STATE;
if (!_pr_recycleThreads || (_PR_RecycleThread(thread) ==
- PR_FAILURE)) {
+ PR_FAILURE)) {
/*
** Destroy the thread resources
*/
- _PR_UserDestroyThread(thread);
+ _PR_UserDestroyThread(thread);
}
/*
@@ -557,54 +562,58 @@ void _PR_SetThreadPriority(PRThread *thread, PRThreadPriority newPri)
return;
}
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
_PR_THREAD_LOCK(thread);
if (newPri != thread->priority) {
- _PRCPU *cpu = thread->cpu;
+ _PRCPU *cpu = thread->cpu;
- switch (thread->state) {
- case _PR_RUNNING:
- /* Change my priority */
+ switch (thread->state) {
+ case _PR_RUNNING:
+ /* Change my priority */
- _PR_RUNQ_LOCK(cpu);
- thread->priority = newPri;
- if (_PR_RUNQREADYMASK(cpu) >> (newPri + 1)) {
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_SET_RESCHED_FLAG();
- }
- _PR_RUNQ_UNLOCK(cpu);
- break;
+ _PR_RUNQ_LOCK(cpu);
+ thread->priority = newPri;
+ if (_PR_RUNQREADYMASK(cpu) >> (newPri + 1)) {
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_SET_RESCHED_FLAG();
+ }
+ }
+ _PR_RUNQ_UNLOCK(cpu);
+ break;
- case _PR_RUNNABLE:
+ case _PR_RUNNABLE:
- _PR_RUNQ_LOCK(cpu);
- /* Move to different runQ */
- _PR_DEL_RUNQ(thread);
- thread->priority = newPri;
- PR_ASSERT(!(thread->flags & _PR_IDLE_THREAD));
- _PR_ADD_RUNQ(thread, cpu, newPri);
- _PR_RUNQ_UNLOCK(cpu);
+ _PR_RUNQ_LOCK(cpu);
+ /* Move to different runQ */
+ _PR_DEL_RUNQ(thread);
+ thread->priority = newPri;
+ PR_ASSERT(!(thread->flags & _PR_IDLE_THREAD));
+ _PR_ADD_RUNQ(thread, cpu, newPri);
+ _PR_RUNQ_UNLOCK(cpu);
- if (newPri > me->priority) {
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_SET_RESCHED_FLAG();
- }
+ if (newPri > me->priority) {
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_SET_RESCHED_FLAG();
+ }
+ }
- break;
+ break;
- case _PR_LOCK_WAIT:
- case _PR_COND_WAIT:
- case _PR_IO_WAIT:
- case _PR_SUSPENDED:
+ case _PR_LOCK_WAIT:
+ case _PR_COND_WAIT:
+ case _PR_IO_WAIT:
+ case _PR_SUSPENDED:
- thread->priority = newPri;
- break;
- }
+ thread->priority = newPri;
+ break;
+ }
}
_PR_THREAD_UNLOCK(thread);
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSON(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSON(is);
+ }
}
/*
@@ -618,51 +627,53 @@ static void _PR_Suspend(PRThread *thread)
PR_ASSERT(thread != me);
PR_ASSERT(!_PR_IS_NATIVE_THREAD(thread) || (!thread->cpu));
- if (!_PR_IS_NATIVE_THREAD(me))
+ if (!_PR_IS_NATIVE_THREAD(me)) {
_PR_INTSOFF(is);
+ }
_PR_THREAD_LOCK(thread);
switch (thread->state) {
- case _PR_RUNNABLE:
- if (!_PR_IS_NATIVE_THREAD(thread)) {
- _PR_RUNQ_LOCK(thread->cpu);
- _PR_DEL_RUNQ(thread);
- _PR_RUNQ_UNLOCK(thread->cpu);
+ case _PR_RUNNABLE:
+ if (!_PR_IS_NATIVE_THREAD(thread)) {
+ _PR_RUNQ_LOCK(thread->cpu);
+ _PR_DEL_RUNQ(thread);
+ _PR_RUNQ_UNLOCK(thread->cpu);
+
+ _PR_MISCQ_LOCK(thread->cpu);
+ _PR_ADD_SUSPENDQ(thread, thread->cpu);
+ _PR_MISCQ_UNLOCK(thread->cpu);
+ } else {
+ /*
+ * Only LOCAL threads are suspended by _PR_Suspend
+ */
+ PR_ASSERT(0);
+ }
+ thread->state = _PR_SUSPENDED;
+ break;
- _PR_MISCQ_LOCK(thread->cpu);
- _PR_ADD_SUSPENDQ(thread, thread->cpu);
- _PR_MISCQ_UNLOCK(thread->cpu);
- } else {
+ case _PR_RUNNING:
/*
- * Only LOCAL threads are suspended by _PR_Suspend
+ * The thread being suspended should be a LOCAL thread with
+ * _pr_numCPUs == 1. Hence, the thread cannot be in RUNNING state
*/
- PR_ASSERT(0);
- }
- thread->state = _PR_SUSPENDED;
- break;
-
- case _PR_RUNNING:
- /*
- * The thread being suspended should be a LOCAL thread with
- * _pr_numCPUs == 1. Hence, the thread cannot be in RUNNING state
- */
- PR_ASSERT(0);
- break;
+ PR_ASSERT(0);
+ break;
- case _PR_LOCK_WAIT:
- case _PR_IO_WAIT:
- case _PR_COND_WAIT:
- if (_PR_IS_NATIVE_THREAD(thread)) {
- _PR_MD_SUSPEND_THREAD(thread);
- }
- thread->flags |= _PR_SUSPENDING;
- break;
+ case _PR_LOCK_WAIT:
+ case _PR_IO_WAIT:
+ case _PR_COND_WAIT:
+ if (_PR_IS_NATIVE_THREAD(thread)) {
+ _PR_MD_SUSPEND_THREAD(thread);
+ }
+ thread->flags |= _PR_SUSPENDING;
+ break;
- default:
- PR_Abort();
+ default:
+ PR_Abort();
}
_PR_THREAD_UNLOCK(thread);
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSON(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSON(is);
+ }
}
static void _PR_Resume(PRThread *thread)
@@ -671,72 +682,75 @@ static void _PR_Resume(PRThread *thread)
PRIntn is;
PRThread *me = _PR_MD_CURRENT_THREAD();
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
_PR_THREAD_LOCK(thread);
switch (thread->state) {
- case _PR_SUSPENDED:
- thread->state = _PR_RUNNABLE;
- thread->flags &= ~_PR_SUSPENDING;
- if (!_PR_IS_NATIVE_THREAD(thread)) {
- _PR_MISCQ_LOCK(thread->cpu);
- _PR_DEL_SUSPENDQ(thread);
- _PR_MISCQ_UNLOCK(thread->cpu);
+ case _PR_SUSPENDED:
+ thread->state = _PR_RUNNABLE;
+ thread->flags &= ~_PR_SUSPENDING;
+ if (!_PR_IS_NATIVE_THREAD(thread)) {
+ _PR_MISCQ_LOCK(thread->cpu);
+ _PR_DEL_SUSPENDQ(thread);
+ _PR_MISCQ_UNLOCK(thread->cpu);
+
+ pri = thread->priority;
+
+ _PR_RUNQ_LOCK(thread->cpu);
+ _PR_ADD_RUNQ(thread, thread->cpu, pri);
+ _PR_RUNQ_UNLOCK(thread->cpu);
+
+ if (pri > _PR_MD_CURRENT_THREAD()->priority) {
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_SET_RESCHED_FLAG();
+ }
+ }
+ } else {
+ PR_ASSERT(0);
+ }
+ break;
- pri = thread->priority;
+ case _PR_IO_WAIT:
+ case _PR_COND_WAIT:
+ thread->flags &= ~_PR_SUSPENDING;
+ /* PR_ASSERT(thread->wait.monitor->stickyCount == 0); */
+ break;
- _PR_RUNQ_LOCK(thread->cpu);
- _PR_ADD_RUNQ(thread, thread->cpu, pri);
- _PR_RUNQ_UNLOCK(thread->cpu);
+ case _PR_LOCK_WAIT:
+ {
+ PRLock *wLock = thread->wait.lock;
+
+ thread->flags &= ~_PR_SUSPENDING;
- if (pri > _PR_MD_CURRENT_THREAD()->priority) {
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_SET_RESCHED_FLAG();
+ _PR_LOCK_LOCK(wLock);
+ if (thread->wait.lock->owner == 0) {
+ _PR_UnblockLockWaiter(thread->wait.lock);
}
- } else {
- PR_ASSERT(0);
+ _PR_LOCK_UNLOCK(wLock);
+ break;
}
- break;
-
- case _PR_IO_WAIT:
- case _PR_COND_WAIT:
- thread->flags &= ~_PR_SUSPENDING;
-/* PR_ASSERT(thread->wait.monitor->stickyCount == 0); */
- break;
-
- case _PR_LOCK_WAIT:
- {
- PRLock *wLock = thread->wait.lock;
-
- thread->flags &= ~_PR_SUSPENDING;
-
- _PR_LOCK_LOCK(wLock);
- if (thread->wait.lock->owner == 0) {
- _PR_UnblockLockWaiter(thread->wait.lock);
- }
- _PR_LOCK_UNLOCK(wLock);
- break;
- }
- case _PR_RUNNABLE:
- break;
- case _PR_RUNNING:
- /*
- * The thread being suspended should be a LOCAL thread with
- * _pr_numCPUs == 1. Hence, the thread cannot be in RUNNING state
- */
- PR_ASSERT(0);
- break;
+ case _PR_RUNNABLE:
+ break;
+ case _PR_RUNNING:
+ /*
+ * The thread being suspended should be a LOCAL thread with
+ * _pr_numCPUs == 1. Hence, the thread cannot be in RUNNING state
+ */
+ PR_ASSERT(0);
+ break;
- default:
- /*
- * thread should have been in one of the above-listed blocked states
- * (_PR_JOIN_WAIT, _PR_IO_WAIT, _PR_UNBORN, _PR_DEAD_STATE)
- */
- PR_Abort();
+ default:
+ /*
+ * thread should have been in one of the above-listed blocked states
+ * (_PR_JOIN_WAIT, _PR_IO_WAIT, _PR_UNBORN, _PR_DEAD_STATE)
+ */
+ PR_Abort();
}
_PR_THREAD_UNLOCK(thread);
- if (!_PR_IS_NATIVE_THREAD(me))
+ if (!_PR_IS_NATIVE_THREAD(me)) {
_PR_INTSON(is);
+ }
}
@@ -761,8 +775,8 @@ static PRThread *get_thread(_PRCPU *cpu, PRBool *wakeup_cpus)
}
thread = NULL;
for (pri = priMax; pri >= priMin ; pri-- ) {
- if (r & (1 << pri)) {
- for (qp = _PR_RUNQ(cpu)[pri].next;
+ if (r & (1 << pri)) {
+ for (qp = _PR_RUNQ(cpu)[pri].next;
qp != &_PR_RUNQ(cpu)[pri];
qp = qp->next) {
thread = _PR_THREAD_PTR(qp);
@@ -786,9 +800,6 @@ static PRThread *get_thread(_PRCPU *cpu, PRBool *wakeup_cpus)
*/
thread = NULL;
-#ifdef IRIX
- _PR_MD_WAKEUP_PRIMORDIAL_CPU();
-#endif
continue;
} else if (thread->io_pending == PR_TRUE) {
/*
@@ -854,16 +865,16 @@ void _PR_Schedule(void)
* operation, for example
*/
if ((thread = suspendAllThread) != 0) {
- if ((!(thread->no_sched)) && (thread->state == _PR_RUNNABLE)) {
+ if ((!(thread->no_sched)) && (thread->state == _PR_RUNNABLE)) {
/* Pull thread off of its run queue */
_PR_DEL_RUNQ(thread);
_PR_RUNQ_UNLOCK(cpu);
goto found_thread;
- } else {
+ } else {
thread = NULL;
_PR_RUNQ_UNLOCK(cpu);
goto idle_thread;
- }
+ }
}
r = _PR_RUNQREADYMASK(cpu);
if (r==0) {
@@ -876,8 +887,8 @@ void _PR_Schedule(void)
}
thread = NULL;
for (pri = priMax; pri >= priMin ; pri-- ) {
- if (r & (1 << pri)) {
- for (qp = _PR_RUNQ(cpu)[pri].next;
+ if (r & (1 << pri)) {
+ for (qp = _PR_RUNQ(cpu)[pri].next;
qp != &_PR_RUNQ(cpu)[pri];
qp = qp->next) {
thread = _PR_THREAD_PTR(qp);
@@ -885,7 +896,7 @@ void _PR_Schedule(void)
* skip non-schedulable threads
*/
PR_ASSERT(!(thread->flags & _PR_IDLE_THREAD));
- if ((thread->no_sched) && (me != thread)){
+ if ((thread->no_sched) && (me != thread)) {
thread = NULL;
continue;
} else {
@@ -907,48 +918,51 @@ void _PR_Schedule(void)
for (qp = _PR_CPUQ().next; qp != &_PR_CPUQ(); qp = qp->next) {
if (cpu != _PR_CPU_PTR(qp)) {
if ((thread = get_thread(_PR_CPU_PTR(qp), &wakeup_cpus))
- != NULL) {
+ != NULL) {
thread->cpu = cpu;
_PR_CPU_LIST_UNLOCK();
- if (wakeup_cpus == PR_TRUE)
+ if (wakeup_cpus == PR_TRUE) {
_PR_MD_WAKEUP_CPUS();
+ }
goto found_thread;
}
}
}
_PR_CPU_LIST_UNLOCK();
- if (wakeup_cpus == PR_TRUE)
+ if (wakeup_cpus == PR_TRUE) {
_PR_MD_WAKEUP_CPUS();
+ }
#endif /* _PR_LOCAL_THREADS_ONLY */
idle_thread:
- /*
- ** There are no threads to run. Switch to the idle thread
- */
+ /*
+ ** There are no threads to run. Switch to the idle thread
+ */
PR_LOG(_pr_sched_lm, PR_LOG_MAX, ("pausing"));
thread = _PR_MD_CURRENT_CPU()->idle_thread;
found_thread:
PR_ASSERT((me == thread) || ((thread->state == _PR_RUNNABLE) &&
- (!(thread->no_sched))));
+ (!(thread->no_sched))));
/* Resume the thread */
PR_LOG(_pr_sched_lm, PR_LOG_MAX,
- ("switching to %d[%p]", thread->id, thread));
+ ("switching to %d[%p]", thread->id, thread));
PR_ASSERT(thread->state != _PR_RUNNING);
thread->state = _PR_RUNNING;
-
+
/* If we are on the runq, it just means that we went to sleep on some
* resource, and by the time we got here another real native thread had
- * already given us the resource and put us back on the runqueue
+ * already given us the resource and put us back on the runqueue
*/
- PR_ASSERT(thread->cpu == _PR_MD_CURRENT_CPU());
- if (thread != me)
+ PR_ASSERT(thread->cpu == _PR_MD_CURRENT_CPU());
+ if (thread != me) {
_PR_MD_RESTORE_CONTEXT(thread);
+ }
#if 0
- /* XXXMB; with setjmp/longjmp it is impossible to land here, but
- * it is not with fibers... Is this a bad thing? I believe it is
+ /* XXXMB; with setjmp/longjmp it is impossible to land here, but
+ * it is not with fibers... Is this a bad thing? I believe it is
* still safe.
*/
PR_NOT_REACHED("impossible return from schedule");
@@ -956,13 +970,13 @@ found_thread:
}
/*
-** Attaches a thread.
-** Does not set the _PR_MD_CURRENT_THREAD.
+** Attaches a thread.
+** Does not set the _PR_MD_CURRENT_THREAD.
** Does not specify the scope of the thread.
*/
static PRThread *
_PR_AttachThread(PRThreadType type, PRThreadPriority priority,
- PRThreadStack *stack)
+ PRThreadStack *stack)
{
PRThread *thread;
char *mem;
@@ -981,9 +995,9 @@ _PR_AttachThread(PRThreadType type, PRThreadPriority priority,
thread->state = _PR_RUNNING;
PR_INIT_CLIST(&thread->lockList);
if (_PR_MD_NEW_LOCK(&thread->threadLock) == PR_FAILURE) {
- PR_DELETE(thread);
- return 0;
- }
+ PR_DELETE(thread);
+ return 0;
+ }
return thread;
}
@@ -992,15 +1006,15 @@ _PR_AttachThread(PRThreadType type, PRThreadPriority priority,
-PR_IMPLEMENT(PRThread*)
+PR_IMPLEMENT(PRThread*)
_PR_NativeCreateThread(PRThreadType type,
- void (*start)(void *arg),
- void *arg,
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize,
- PRUint32 flags)
+ void (*start)(void *arg),
+ void *arg,
+ PRThreadPriority priority,
+ PRThreadScope scope,
+ PRThreadState state,
+ PRUint32 stackSize,
+ PRUint32 flags)
{
PRThread *thread;
@@ -1028,33 +1042,33 @@ _PR_NativeCreateThread(PRThreadType type,
thread->startFunc = start;
thread->arg = arg;
- /*
+ /*
Set thread flags related to scope and joinable state. If joinable
thread, allocate a "termination" conidition variable.
*/
if (state == PR_JOINABLE_THREAD) {
thread->term = PR_NewCondVar(_pr_terminationCVLock);
- if (thread->term == NULL) {
- PR_DELETE(thread->stack);
- goto done;
- }
+ if (thread->term == NULL) {
+ PR_DELETE(thread->stack);
+ goto done;
+ }
}
- thread->state = _PR_RUNNING;
+ thread->state = _PR_RUNNING;
if (_PR_MD_CREATE_THREAD(thread, _PR_NativeRunThread, priority,
- scope,state,stackSize) == PR_SUCCESS) {
+ scope,state,stackSize) == PR_SUCCESS) {
return thread;
}
if (thread->term) {
PR_DestroyCondVar(thread->term);
thread->term = NULL;
}
- PR_DELETE(thread->stack);
+ PR_DELETE(thread->stack);
}
done:
if (thread) {
- _PR_DecrActiveThreadCount(thread);
+ _PR_DecrActiveThreadCount(thread);
_PR_DestroyThread(thread);
}
return NULL;
@@ -1063,13 +1077,13 @@ done:
/************************************************************************/
PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
- void (*start)(void *arg),
- void *arg,
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize,
- PRUint32 flags)
+ void (*start)(void *arg),
+ void *arg,
+ PRThreadPriority priority,
+ PRThreadScope scope,
+ PRThreadState state,
+ PRUint32 stackSize,
+ PRUint32 flags)
{
PRThread *me;
PRThread *thread = NULL;
@@ -1080,7 +1094,7 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
PRIntn useRecycled = 0;
PRBool status;
- /*
+ /*
First, pin down the priority. Not all compilers catch passing out of
range enum here. If we let bad values thru, priority queues won't work.
*/
@@ -1089,34 +1103,39 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
} else if (priority < PR_PRIORITY_FIRST) {
priority = PR_PRIORITY_FIRST;
}
-
- if (!_pr_initialized) _PR_ImplicitInitialization();
- if (! (flags & _PR_IDLE_THREAD))
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
+
+ if (! (flags & _PR_IDLE_THREAD)) {
me = _PR_MD_CURRENT_THREAD();
+ }
#if defined(_PR_GLOBAL_THREADS_ONLY)
- /*
- * can create global threads only
- */
- if (scope == PR_LOCAL_THREAD)
- scope = PR_GLOBAL_THREAD;
+ /*
+ * can create global threads only
+ */
+ if (scope == PR_LOCAL_THREAD) {
+ scope = PR_GLOBAL_THREAD;
+ }
#endif
- if (_native_threads_only)
- scope = PR_GLOBAL_THREAD;
+ if (_native_threads_only) {
+ scope = PR_GLOBAL_THREAD;
+ }
native = (((scope == PR_GLOBAL_THREAD)|| (scope == PR_GLOBAL_BOUND_THREAD))
- && _PR_IS_NATIVE_THREAD_SUPPORTED());
+ && _PR_IS_NATIVE_THREAD_SUPPORTED());
_PR_ADJUST_STACKSIZE(stackSize);
if (native) {
- /*
- * clear the IDLE_THREAD flag which applies to LOCAL
- * threads only
- */
- flags &= ~_PR_IDLE_THREAD;
+ /*
+ * clear the IDLE_THREAD flag which applies to LOCAL
+ * threads only
+ */
+ flags &= ~_PR_IDLE_THREAD;
flags |= _PR_GLOBAL_SCOPE;
if (_PR_NUM_DEADNATIVE > 0) {
_PR_DEADQ_LOCK;
@@ -1132,35 +1151,38 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
_PR_InitializeRecycledThread(thread);
thread->startFunc = start;
thread->arg = arg;
- thread->flags = (flags | _PR_GLOBAL_SCOPE);
- if (type == PR_SYSTEM_THREAD)
- {
- thread->flags |= _PR_SYSTEM;
- PR_ATOMIC_INCREMENT(&_pr_systemActive);
- }
- else PR_ATOMIC_INCREMENT(&_pr_userActive);
+ thread->flags = (flags | _PR_GLOBAL_SCOPE);
+ if (type == PR_SYSTEM_THREAD)
+ {
+ thread->flags |= _PR_SYSTEM;
+ PR_ATOMIC_INCREMENT(&_pr_systemActive);
+ }
+ else {
+ PR_ATOMIC_INCREMENT(&_pr_userActive);
+ }
- if (state == PR_JOINABLE_THREAD) {
- if (!thread->term)
- thread->term = PR_NewCondVar(_pr_terminationCVLock);
- }
- else {
- if(thread->term) {
- PR_DestroyCondVar(thread->term);
+ if (state == PR_JOINABLE_THREAD) {
+ if (!thread->term) {
+ thread->term = PR_NewCondVar(_pr_terminationCVLock);
+ }
+ }
+ else {
+ if(thread->term) {
+ PR_DestroyCondVar(thread->term);
thread->term = 0;
- }
- }
+ }
+ }
thread->priority = priority;
- _PR_MD_SET_PRIORITY(&(thread->md), priority);
- /* XXX what about stackSize? */
- thread->state = _PR_RUNNING;
+ _PR_MD_SET_PRIORITY(&(thread->md), priority);
+ /* XXX what about stackSize? */
+ thread->state = _PR_RUNNING;
_PR_MD_WAKEUP_WAITER(thread);
- return thread;
+ return thread;
}
}
- thread = _PR_NativeCreateThread(type, start, arg, priority,
- scope, state, stackSize, flags);
+ thread = _PR_NativeCreateThread(type, start, arg, priority,
+ scope, state, stackSize, flags);
} else {
if (_PR_NUM_DEADUSER > 0) {
_PR_DEADQ_LOCK;
@@ -1170,14 +1192,14 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
} else {
PRCList *ptr;
- /* Go down list checking for a recycled thread with a
+ /* Go down list checking for a recycled thread with a
* large enough stack. XXXMB - this has a bad degenerate case.
*/
ptr = _PR_DEADUSERQ.next;
while( ptr != &_PR_DEADUSERQ ) {
thread = _PR_THREAD_PTR(ptr);
if ((thread->stack->stackSize >= stackSize) &&
- (!thread->no_sched)) {
+ (!thread->no_sched)) {
PR_REMOVE_LINK(&thread->links);
_PR_DEC_DEADUSER;
break;
@@ -1185,28 +1207,29 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
ptr = ptr->next;
thread = NULL;
}
- }
+ }
_PR_DEADQ_UNLOCK;
- if (thread) {
+ if (thread) {
_PR_InitializeRecycledThread(thread);
thread->startFunc = start;
thread->arg = arg;
thread->priority = priority;
- if (state == PR_JOINABLE_THREAD) {
- if (!thread->term)
- thread->term = PR_NewCondVar(_pr_terminationCVLock);
- } else {
- if(thread->term) {
- PR_DestroyCondVar(thread->term);
- thread->term = 0;
- }
- }
+ if (state == PR_JOINABLE_THREAD) {
+ if (!thread->term) {
+ thread->term = PR_NewCondVar(_pr_terminationCVLock);
+ }
+ } else {
+ if(thread->term) {
+ PR_DestroyCondVar(thread->term);
+ thread->term = 0;
+ }
+ }
useRecycled++;
}
}
- }
+ }
if (thread == NULL) {
#ifndef HAVE_CUSTOM_USER_THREADS
stack = _PR_NewStack(stackSize);
@@ -1260,8 +1283,9 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
PR_INIT_CLIST(&thread->lockList);
if (_PR_MD_INIT_THREAD(thread) == PR_FAILURE) {
- if (thread->threadAllocatedOnStack == 1)
+ if (thread->threadAllocatedOnStack == 1) {
_PR_FreeStack(thread->stack);
+ }
else {
PR_DELETE(thread);
}
@@ -1270,8 +1294,9 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
}
if (_PR_MD_NEW_LOCK(&thread->threadLock) == PR_FAILURE) {
- if (thread->threadAllocatedOnStack == 1)
+ if (thread->threadAllocatedOnStack == 1) {
_PR_FreeStack(thread->stack);
+ }
else {
PR_DELETE(thread->privateData);
PR_DELETE(thread);
@@ -1284,8 +1309,9 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
if (status == PR_FALSE) {
_PR_MD_FREE_LOCK(&thread->threadLock);
- if (thread->threadAllocatedOnStack == 1)
+ if (thread->threadAllocatedOnStack == 1) {
_PR_FreeStack(thread->stack);
+ }
else {
PR_DELETE(thread->privateData);
PR_DELETE(thread);
@@ -1293,7 +1319,7 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
return NULL;
}
- /*
+ /*
Set thread flags related to scope and joinable state. If joinable
thread, allocate a "termination" condition variable.
*/
@@ -1301,8 +1327,9 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
thread->term = PR_NewCondVar(_pr_terminationCVLock);
if (thread->term == NULL) {
_PR_MD_FREE_LOCK(&thread->threadLock);
- if (thread->threadAllocatedOnStack == 1)
+ if (thread->threadAllocatedOnStack == 1) {
_PR_FreeStack(thread->stack);
+ }
else {
PR_DELETE(thread->privateData);
PR_DELETE(thread);
@@ -1310,9 +1337,9 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
return NULL;
}
}
-
+
}
-
+
/* Update thread type counter */
PR_Lock(_pr_activeLock);
thread->flags = flags;
@@ -1326,15 +1353,17 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
/* Make thread runnable */
thread->state = _PR_RUNNABLE;
- /*
- * Add to list of active threads
- */
+ /*
+ * Add to list of active threads
+ */
PR_Unlock(_pr_activeLock);
- if ((! (thread->flags & _PR_IDLE_THREAD)) && _PR_IS_NATIVE_THREAD(me) )
+ if ((! (thread->flags & _PR_IDLE_THREAD)) && _PR_IS_NATIVE_THREAD(me) ) {
thread->cpu = _PR_GetPrimordialCPU();
- else
+ }
+ else {
thread->cpu = _PR_MD_CURRENT_CPU();
+ }
PR_ASSERT(!_PR_IS_NATIVE_THREAD(thread));
@@ -1350,28 +1379,29 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
** If the creating thread is a kernel thread, we need to
** awaken the user thread idle thread somehow; potentially
** it could be sleeping in its idle loop, and we need to poke
- ** it. To do so, wake the idle thread...
+ ** it. To do so, wake the idle thread...
*/
_PR_MD_WAKEUP_WAITER(NULL);
} else if (_PR_IS_NATIVE_THREAD(me)) {
_PR_MD_WAKEUP_WAITER(thread);
}
- if ((! (thread->flags & _PR_IDLE_THREAD)) && !_PR_IS_NATIVE_THREAD(me) )
+ if ((! (thread->flags & _PR_IDLE_THREAD)) && !_PR_IS_NATIVE_THREAD(me) ) {
_PR_INTSON(is);
+ }
}
return thread;
}
PR_IMPLEMENT(PRThread*) PR_CreateThread(PRThreadType type,
- void (*start)(void *arg),
- void *arg,
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize)
+ void (*start)(void *arg),
+ void *arg,
+ PRThreadPriority priority,
+ PRThreadScope scope,
+ PRThreadState state,
+ PRUint32 stackSize)
{
- return _PR_CreateThread(type, start, arg, priority, scope, state,
+ return _PR_CreateThread(type, start, arg, priority, scope, state,
stackSize, 0);
}
@@ -1388,7 +1418,7 @@ PR_IMPLEMENT(PRThread*) PR_CreateThread(PRThreadType type,
** thread. PR_Init does this automatically for the primordial thread.
*/
PRThread* _PRI_AttachThread(PRThreadType type,
- PRThreadPriority priority, PRThreadStack *stack, PRUint32 flags)
+ PRThreadPriority priority, PRThreadStack *stack, PRUint32 flags)
{
PRThread *thread;
@@ -1419,9 +1449,9 @@ PRThread* _PRI_AttachThread(PRThreadType type,
PR_INIT_CLIST(&thread->links);
if (_PR_MD_INIT_ATTACHED_THREAD(thread) == PR_FAILURE) {
- PR_DELETE(thread->stack);
- _PR_DestroyThread(thread);
- return NULL;
+ PR_DELETE(thread->stack);
+ _PR_DestroyThread(thread);
+ return NULL;
}
_PR_MD_SET_CURRENT_CPU(NULL);
@@ -1445,7 +1475,7 @@ PRThread* _PRI_AttachThread(PRThreadType type,
}
PR_IMPLEMENT(PRThread*) PR_AttachThread(PRThreadType type,
- PRThreadPriority priority, PRThreadStack *stack)
+ PRThreadPriority priority, PRThreadStack *stack)
{
return PR_GetCurrentThread();
}
@@ -1453,16 +1483,17 @@ PR_IMPLEMENT(PRThread*) PR_AttachThread(PRThreadType type,
PR_IMPLEMENT(void) PR_DetachThread(void)
{
/*
- * On IRIX, Solaris, and Windows, foreign threads are detached when
+ * On Solaris, and Windows, foreign threads are detached when
* they terminate.
*/
-#if !defined(IRIX) && !defined(WIN32) \
+#if !defined(WIN32) \
&& !(defined(SOLARIS) && defined(_PR_GLOBAL_THREADS_ONLY))
PRThread *me;
if (_pr_initialized) {
me = _PR_MD_GET_ATTACHED_THREAD();
- if ((me != NULL) && (me->flags & _PR_ATTACHED))
+ if ((me != NULL) && (me->flags & _PR_ATTACHED)) {
_PRI_DetachThread();
+ }
}
#endif
}
@@ -1471,12 +1502,12 @@ void _PRI_DetachThread(void)
{
PRThread *me = _PR_MD_CURRENT_THREAD();
- if (me->flags & _PR_PRIMORDIAL) {
- /*
- * ignore, if primordial thread
- */
- return;
- }
+ if (me->flags & _PR_PRIMORDIAL) {
+ /*
+ * ignore, if primordial thread
+ */
+ return;
+ }
PR_ASSERT(me->flags & _PR_ATTACHED);
PR_ASSERT(_PR_IS_NATIVE_THREAD(me));
_PR_CleanupThread(me);
@@ -1486,17 +1517,18 @@ void _PRI_DetachThread(void)
_PR_MD_CLEAN_THREAD(me);
_PR_MD_SET_CURRENT_THREAD(NULL);
- if (!me->threadAllocatedOnStack)
+ if (!me->threadAllocatedOnStack) {
PR_DELETE(me->stack);
+ }
_PR_MD_FREE_LOCK(&me->threadLock);
PR_DELETE(me);
}
/*
** Wait for thread termination:
-** "thread" is the target thread
+** "thread" is the target thread
**
-** This can return PR_FAILURE if no joinable thread could be found
+** This can return PR_FAILURE if no joinable thread could be found
** corresponding to the specified target thread.
**
** The calling thread is suspended until the target thread completes.
@@ -1511,8 +1543,9 @@ PR_IMPLEMENT(PRStatus) PR_JoinThread(PRThread *thread)
PRCondVar *term;
PRThread *me = _PR_MD_CURRENT_THREAD();
- if (!_PR_IS_NATIVE_THREAD(me))
+ if (!_PR_IS_NATIVE_THREAD(me)) {
_PR_INTSOFF(is);
+ }
term = thread->term;
/* can't join a non-joinable thread */
if (term == NULL) {
@@ -1524,8 +1557,9 @@ PR_IMPLEMENT(PRStatus) PR_JoinThread(PRThread *thread)
if (term->condQ.next != &term->condQ) {
goto ErrorExit;
}
- if (!_PR_IS_NATIVE_THREAD(me))
+ if (!_PR_IS_NATIVE_THREAD(me)) {
_PR_INTSON(is);
+ }
/* wait for the target thread's termination cv invariant */
PR_Lock (_pr_terminationCVLock);
@@ -1533,14 +1567,15 @@ PR_IMPLEMENT(PRStatus) PR_JoinThread(PRThread *thread)
(void) PR_WaitCondVar(term, PR_INTERVAL_NO_TIMEOUT);
}
(void) PR_Unlock (_pr_terminationCVLock);
-
- /*
+
+ /*
Remove target thread from global waiting to join Q; make it runnable
again and put it back on its run Q. When it gets scheduled later in
_PR_RunThread code, it will clean up its stack.
- */
- if (!_PR_IS_NATIVE_THREAD(me))
+ */
+ if (!_PR_IS_NATIVE_THREAD(me)) {
_PR_INTSOFF(is);
+ }
thread->state = _PR_RUNNABLE;
if ( !_PR_IS_NATIVE_THREAD(thread) ) {
_PR_THREAD_LOCK(thread);
@@ -1552,23 +1587,26 @@ PR_IMPLEMENT(PRStatus) PR_JoinThread(PRThread *thread)
_PR_AddThreadToRunQ(me, thread);
_PR_THREAD_UNLOCK(thread);
}
- if (!_PR_IS_NATIVE_THREAD(me))
+ if (!_PR_IS_NATIVE_THREAD(me)) {
_PR_INTSON(is);
+ }
_PR_MD_WAKEUP_WAITER(thread);
return PR_SUCCESS;
ErrorExit:
- if ( !_PR_IS_NATIVE_THREAD(me)) _PR_INTSON(is);
- return PR_FAILURE;
+ if ( !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSON(is);
+ }
+ return PR_FAILURE;
}
PR_IMPLEMENT(void) PR_SetThreadPriority(PRThread *thread,
- PRThreadPriority newPri)
+ PRThreadPriority newPri)
{
- /*
+ /*
First, pin down the priority. Not all compilers catch passing out of
range enum here. If we let bad values thru, priority queues won't work.
*/
@@ -1577,11 +1615,13 @@ PR_IMPLEMENT(void) PR_SetThreadPriority(PRThread *thread,
} else if ((PRIntn)newPri < (PRIntn)PR_PRIORITY_FIRST) {
newPri = PR_PRIORITY_FIRST;
}
-
+
if ( _PR_IS_NATIVE_THREAD(thread) ) {
thread->priority = newPri;
_PR_MD_SET_PRIORITY(&(thread->md), newPri);
- } else _PR_SetThreadPriority(thread, newPri);
+ } else {
+ _PR_SetThreadPriority(thread, newPri);
+ }
}
PR_IMPLEMENT(PRStatus) PR_SetCurrentThreadName(const char *name)
@@ -1595,14 +1635,16 @@ PR_IMPLEMENT(PRStatus) PR_SetCurrentThreadName(const char *name)
}
thread = PR_GetCurrentThread();
- if (!thread)
+ if (!thread) {
return PR_FAILURE;
+ }
PR_Free(thread->name);
nameLen = strlen(name);
thread->name = (char *)PR_Malloc(nameLen + 1);
- if (!thread->name)
+ if (!thread->name) {
return PR_FAILURE;
+ }
memcpy(thread->name, name, nameLen + 1);
_PR_MD_SET_CURRENT_THREAD_NAME(thread->name);
return PR_SUCCESS;
@@ -1610,14 +1652,15 @@ PR_IMPLEMENT(PRStatus) PR_SetCurrentThreadName(const char *name)
PR_IMPLEMENT(const char *) PR_GetThreadName(const PRThread *thread)
{
- if (!thread)
+ if (!thread) {
return NULL;
+ }
return thread->name;
}
/*
-** This routine prevents all other threads from running. This call is needed by
+** This routine prevents all other threads from running. This call is needed by
** the garbage collector.
*/
PR_IMPLEMENT(void) PR_SuspendAll(void)
@@ -1633,25 +1676,27 @@ PR_IMPLEMENT(void) PR_SuspendAll(void)
suspendAllThread = _PR_MD_CURRENT_THREAD();
_PR_MD_BEGIN_SUSPEND_ALL();
for (qp = _PR_ACTIVE_LOCAL_THREADQ().next;
- qp != &_PR_ACTIVE_LOCAL_THREADQ(); qp = qp->next) {
- if ((me != _PR_ACTIVE_THREAD_PTR(qp)) &&
+ qp != &_PR_ACTIVE_LOCAL_THREADQ(); qp = qp->next) {
+ if ((me != _PR_ACTIVE_THREAD_PTR(qp)) &&
_PR_IS_GCABLE_THREAD(_PR_ACTIVE_THREAD_PTR(qp))) {
_PR_Suspend(_PR_ACTIVE_THREAD_PTR(qp));
- PR_ASSERT((_PR_ACTIVE_THREAD_PTR(qp))->state != _PR_RUNNING);
- }
+ PR_ASSERT((_PR_ACTIVE_THREAD_PTR(qp))->state != _PR_RUNNING);
+ }
}
for (qp = _PR_ACTIVE_GLOBAL_THREADQ().next;
- qp != &_PR_ACTIVE_GLOBAL_THREADQ(); qp = qp->next) {
+ qp != &_PR_ACTIVE_GLOBAL_THREADQ(); qp = qp->next) {
if ((me != _PR_ACTIVE_THREAD_PTR(qp)) &&
_PR_IS_GCABLE_THREAD(_PR_ACTIVE_THREAD_PTR(qp)))
/* PR_Suspend(_PR_ACTIVE_THREAD_PTR(qp)); */
- _PR_MD_SUSPEND_THREAD(_PR_ACTIVE_THREAD_PTR(qp));
+ {
+ _PR_MD_SUSPEND_THREAD(_PR_ACTIVE_THREAD_PTR(qp));
+ }
}
_PR_MD_END_SUSPEND_ALL();
}
/*
-** This routine unblocks all other threads that were suspended from running by
+** This routine unblocks all other threads that were suspended from running by
** PR_SuspendAll(). This call is needed by the garbage collector.
*/
PR_IMPLEMENT(void) PR_ResumeAll(void)
@@ -1664,16 +1709,18 @@ PR_IMPLEMENT(void) PR_ResumeAll(void)
*/
_PR_MD_BEGIN_RESUME_ALL();
for (qp = _PR_ACTIVE_LOCAL_THREADQ().next;
- qp != &_PR_ACTIVE_LOCAL_THREADQ(); qp = qp->next) {
- if ((me != _PR_ACTIVE_THREAD_PTR(qp)) &&
- _PR_IS_GCABLE_THREAD(_PR_ACTIVE_THREAD_PTR(qp)))
+ qp != &_PR_ACTIVE_LOCAL_THREADQ(); qp = qp->next) {
+ if ((me != _PR_ACTIVE_THREAD_PTR(qp)) &&
+ _PR_IS_GCABLE_THREAD(_PR_ACTIVE_THREAD_PTR(qp))) {
_PR_Resume(_PR_ACTIVE_THREAD_PTR(qp));
+ }
}
for (qp = _PR_ACTIVE_GLOBAL_THREADQ().next;
- qp != &_PR_ACTIVE_GLOBAL_THREADQ(); qp = qp->next) {
+ qp != &_PR_ACTIVE_GLOBAL_THREADQ(); qp = qp->next) {
if ((me != _PR_ACTIVE_THREAD_PTR(qp)) &&
- _PR_IS_GCABLE_THREAD(_PR_ACTIVE_THREAD_PTR(qp)))
- _PR_MD_RESUME_THREAD(_PR_ACTIVE_THREAD_PTR(qp));
+ _PR_IS_GCABLE_THREAD(_PR_ACTIVE_THREAD_PTR(qp))) {
+ _PR_MD_RESUME_THREAD(_PR_ACTIVE_THREAD_PTR(qp));
+ }
}
_PR_MD_END_RESUME_ALL();
suspendAllThread = NULL;
@@ -1715,8 +1762,9 @@ PR_IMPLEMENT(PRStatus) PR_EnumerateThreads(PREnumerator func, void *arg)
if (_PR_IS_GCABLE_THREAD(t))
{
rv = (*func)(t, i, arg);
- if (rv != PR_SUCCESS)
+ if (rv != PR_SUCCESS) {
return rv;
+ }
i++;
}
}
@@ -1728,8 +1776,9 @@ PR_IMPLEMENT(PRStatus) PR_EnumerateThreads(PREnumerator func, void *arg)
if (_PR_IS_GCABLE_THREAD(t))
{
rv = (*func)(t, i, arg);
- if (rv != PR_SUCCESS)
+ if (rv != PR_SUCCESS) {
return rv;
+ }
i++;
}
}
@@ -1787,7 +1836,7 @@ _PR_AddSleepQ(PRThread *thread, PRIntervalTime timeout)
** must be one) so that they remain relative to us.
*/
PR_ASSERT (thread->links.next != &_PR_SLEEPQ(cpu));
-
+
t = _PR_THREAD_PTR(thread->links.next);
PR_ASSERT(_PR_THREAD_PTR(t->links.prev) == thread);
t->sleep -= sleep;
@@ -1821,24 +1870,28 @@ _PR_DelSleepQ(PRThread *thread, PRBool propogate_time)
if (propogate_time == PR_TRUE) {
PRThread *after = _PR_THREAD_PTR(q);
after->sleep += thread->sleep;
- } else
+ } else {
_PR_SLEEPQMAX(cpu) -= thread->sleep;
+ }
} else {
/* Check if prev is the beggining of the list; if so,
- * we are the only element on the list.
+ * we are the only element on the list.
*/
- if (thread->links.prev != &_PR_SLEEPQ(cpu))
+ if (thread->links.prev != &_PR_SLEEPQ(cpu)) {
_PR_SLEEPQMAX(cpu) -= thread->sleep;
- else
+ }
+ else {
_PR_SLEEPQMAX(cpu) = 0;
+ }
}
thread->flags &= ~_PR_ON_SLEEPQ;
} else {
thread->flags &= ~_PR_ON_PAUSEQ;
}
PR_REMOVE_LINK(&thread->links);
- } else
+ } else {
PR_ASSERT(0);
+ }
}
void
@@ -1861,17 +1914,17 @@ _PR_AddThreadToRunQ(
* "post" the awakened thread to the IO completion port
* for the next idle CPU to execute (this is done in
* _PR_MD_WAKEUP_WAITER).
- * Threads with a suspended I/O operation remain bound to
- * the same cpu until I/O is cancelled
+ * Threads with a suspended I/O operation remain bound to
+ * the same cpu until I/O is cancelled
*
* NOTE: the boolean expression below must be the exact
* opposite of the corresponding boolean expression in
* _PR_MD_WAKEUP_WAITER.
*/
if ((!_PR_IS_NATIVE_THREAD(me) && (cpu == me->cpu)) ||
- (thread->md.thr_bound_cpu)) {
- PR_ASSERT(!thread->md.thr_bound_cpu ||
- (thread->md.thr_bound_cpu == cpu));
+ (thread->md.thr_bound_cpu)) {
+ PR_ASSERT(!thread->md.thr_bound_cpu ||
+ (thread->md.thr_bound_cpu == cpu));
_PR_RUNQ_LOCK(cpu);
_PR_ADD_RUNQ(thread, cpu, pri);
_PR_RUNQ_UNLOCK(cpu);
diff --git a/nsprpub/pr/src/threads/prcmon.c b/nsprpub/pr/src/threads/prcmon.c
index 2a196e9d4..c1d354ced 100644
--- a/nsprpub/pr/src/threads/prcmon.c
+++ b/nsprpub/pr/src/threads/prcmon.c
@@ -100,9 +100,11 @@ static PRStatus ExpandMonitorCache(PRUintn new_size_log2)
** Expand the monitor-cache-entry free list
*/
new_block = (MonitorCacheEntryBlock*)
- PR_CALLOC(sizeof(MonitorCacheEntryBlock)
- + (entries - 1) * sizeof(MonitorCacheEntry));
- if (NULL == new_block) return PR_FAILURE;
+ PR_CALLOC(sizeof(MonitorCacheEntryBlock)
+ + (entries - 1) * sizeof(MonitorCacheEntry));
+ if (NULL == new_block) {
+ return PR_FAILURE;
+ }
/*
** Allocate system monitors for the new monitor cache entries. If we
@@ -110,8 +112,9 @@ static PRStatus ExpandMonitorCache(PRUintn new_size_log2)
*/
for (i = 0, p = new_block->entries; i < entries; i++, p++) {
p->mon = PR_NewMonitor();
- if (!p->mon)
+ if (!p->mon) {
break;
+ }
}
added = i;
if (added != entries) {
@@ -129,10 +132,11 @@ static PRStatus ExpandMonitorCache(PRUintn new_size_log2)
** carry on with the too-large new_block.
*/
realloc_block = (MonitorCacheEntryBlock*)
- PR_REALLOC(new_block, sizeof(MonitorCacheEntryBlock)
- + (added - 1) * sizeof(MonitorCacheEntry));
- if (realloc_block)
+ PR_REALLOC(new_block, sizeof(MonitorCacheEntryBlock)
+ + (added - 1) * sizeof(MonitorCacheEntry));
+ if (realloc_block) {
new_block = realloc_block;
+ }
}
/*
@@ -141,8 +145,9 @@ static PRStatus ExpandMonitorCache(PRUintn new_size_log2)
** the mcache-lock and we aren't calling anyone who might want to use
** it.
*/
- for (i = 0, p = new_block->entries; i < added - 1; i++, p++)
+ for (i = 0, p = new_block->entries; i < added - 1; i++, p++) {
p->next = p + 1;
+ }
p->next = free_entries;
free_entries = new_block->entries;
num_free_entries += added;
@@ -151,7 +156,7 @@ static PRStatus ExpandMonitorCache(PRUintn new_size_log2)
/* Try to expand the hash table */
new_hash_buckets = (MonitorCacheEntry**)
- PR_CALLOC(entries * sizeof(MonitorCacheEntry*));
+ PR_CALLOC(entries * sizeof(MonitorCacheEntry*));
if (NULL == new_hash_buckets) {
/*
** Partial lossage. In this situation we don't get any more hash
@@ -220,8 +225,9 @@ static MonitorCacheEntry **LookupMonitorCacheEntry(void *address)
pp = hash_buckets + hash;
while ((p = *pp) != 0) {
if (p->address == address) {
- if (p->cacheEntryCount > 0)
+ if (p->cacheEntryCount > 0) {
return pp;
+ }
return NULL;
}
pp = &p->next;
@@ -242,7 +248,9 @@ static PRMonitor *CreateMonitor(void *address)
hash = HASH(address);
pp = hash_buckets + hash;
while ((p = *pp) != 0) {
- if (p->address == address) goto gotit;
+ if (p->address == address) {
+ goto gotit;
+ }
pp = &p->next;
}
@@ -261,7 +269,9 @@ static PRMonitor *CreateMonitor(void *address)
expanding = PR_TRUE;
rv = ExpandMonitorCache(num_hash_buckets_log2 + 1);
expanding = PR_FALSE;
- if (PR_FAILURE == rv) return NULL;
+ if (PR_FAILURE == rv) {
+ return NULL;
+ }
/* redo the hash because it'll be different now */
hash = HASH(address);
@@ -278,14 +288,15 @@ static PRMonitor *CreateMonitor(void *address)
p = free_entries;
free_entries = p->next;
num_free_entries--;
- if (OnMonitorRecycle && p->address)
+ if (OnMonitorRecycle && p->address) {
OnMonitorRecycle(p->address);
+ }
p->address = address;
p->next = hash_buckets[hash];
hash_buckets[hash] = p;
PR_ASSERT(p->cacheEntryCount == 0);
- gotit:
+gotit:
p->cacheEntryCount++;
return p->mon;
}
@@ -337,13 +348,17 @@ PR_IMPLEMENT(PRMonitor*) PR_CEnterMonitor(void *address)
{
PRMonitor *mon;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
_PR_LOCK_MCACHE();
mon = CreateMonitor(address);
_PR_UNLOCK_MCACHE();
- if (!mon) return NULL;
+ if (!mon) {
+ return NULL;
+ }
PR_EnterMonitor(mon);
return mon;
@@ -389,8 +404,9 @@ PR_IMPLEMENT(PRStatus) PR_CWait(void *address, PRIntervalTime ticks)
mon = pp ? ((*pp)->mon) : NULL;
_PR_UNLOCK_MCACHE();
- if (mon == NULL)
+ if (mon == NULL) {
return PR_FAILURE;
+ }
return PR_Wait(mon, ticks);
}
@@ -404,8 +420,9 @@ PR_IMPLEMENT(PRStatus) PR_CNotify(void *address)
mon = pp ? ((*pp)->mon) : NULL;
_PR_UNLOCK_MCACHE();
- if (mon == NULL)
+ if (mon == NULL) {
return PR_FAILURE;
+ }
return PR_Notify(mon);
}
@@ -419,8 +436,9 @@ PR_IMPLEMENT(PRStatus) PR_CNotifyAll(void *address)
mon = pp ? ((*pp)->mon) : NULL;
_PR_UNLOCK_MCACHE();
- if (mon == NULL)
+ if (mon == NULL) {
return PR_FAILURE;
+ }
return PR_NotifyAll(mon);
}
diff --git a/nsprpub/pr/src/threads/prcthr.c b/nsprpub/pr/src/threads/prcthr.c
index 268814473..e7044ed53 100644
--- a/nsprpub/pr/src/threads/prcthr.c
+++ b/nsprpub/pr/src/threads/prcthr.c
@@ -7,17 +7,17 @@
#if defined(WIN95)
/*
-** Some local variables report warnings on Win95 because the code paths
+** Some local variables report warnings on Win95 because the code paths
** using them are conditioned on HAVE_CUSTOME_USER_THREADS.
** The pragma suppresses the warning.
-**
+**
*/
#pragma warning(disable : 4101)
#endif
extern PRLock *_pr_sleeplock; /* allocated and initialized in prinit */
-/*
+/*
** Routines common to both native and user threads.
**
**
@@ -46,7 +46,7 @@ PR_IMPLEMENT(PRStatus) PR_Yield()
{
static PRBool warning = PR_TRUE;
if (warning) warning = _PR_Obsolete(
- "PR_Yield()", "PR_Sleep(PR_INTERVAL_NO_WAIT)");
+ "PR_Yield()", "PR_Sleep(PR_INTERVAL_NO_WAIT)");
return (PR_Sleep(PR_INTERVAL_NO_WAIT));
}
@@ -64,7 +64,9 @@ PR_IMPLEMENT(PRStatus) PR_Sleep(PRIntervalTime timeout)
{
PRStatus rv = PR_SUCCESS;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
if (PR_INTERVAL_NO_WAIT == timeout)
{
@@ -76,7 +78,9 @@ PR_IMPLEMENT(PRStatus) PR_Sleep(PRIntervalTime timeout)
PRUintn pri = me->priority;
_PRCPU *cpu = _PR_MD_CURRENT_CPU();
- if ( _PR_IS_NATIVE_THREAD(me) ) _PR_MD_YIELD();
+ if ( _PR_IS_NATIVE_THREAD(me) ) {
+ _PR_MD_YIELD();
+ }
else
{
_PR_INTSOFF(is);
@@ -118,7 +122,9 @@ PR_IMPLEMENT(PRStatus) PR_Sleep(PRIntervalTime timeout)
do
{
PRIntervalTime delta = PR_IntervalNow() - timein;
- if (delta > timeout) break;
+ if (delta > timeout) {
+ break;
+ }
rv = PR_WaitCondVar(cv, timeout - delta);
} while (rv == PR_SUCCESS);
PR_Unlock(_pr_sleeplock);
@@ -139,7 +145,9 @@ PR_IMPLEMENT(PRThreadPriority) PR_GetThreadPriority(const PRThread *thread)
PR_IMPLEMENT(PRThread *) PR_GetCurrentThread()
{
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
return _PR_MD_CURRENT_THREAD();
}
@@ -161,52 +169,60 @@ PR_IMPLEMENT(PRStatus) PR_Interrupt(PRThread *thread)
if ((NULL != victim) && (!(thread->flags & _PR_INTERRUPT_BLOCKED))) {
int haveLock = (victim->lock->owner == _PR_MD_CURRENT_THREAD());
- if (!haveLock) PR_Lock(victim->lock);
+ if (!haveLock) {
+ PR_Lock(victim->lock);
+ }
PR_NotifyAllCondVar(victim);
- if (!haveLock) PR_Unlock(victim->lock);
+ if (!haveLock) {
+ PR_Unlock(victim->lock);
+ }
}
return PR_SUCCESS;
#else /* ! _PR_GLOBAL_THREADS_ONLY */
PRIntn is;
PRThread *me = _PR_MD_CURRENT_THREAD();
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSOFF(is);
-
- _PR_THREAD_LOCK(thread);
- thread->flags |= _PR_INTERRUPT;
- switch (thread->state) {
- case _PR_COND_WAIT:
- /*
- * call is made with thread locked;
- * on return lock is released
- */
- if (!(thread->flags & _PR_INTERRUPT_BLOCKED))
- _PR_NotifyLockedThread(thread);
- break;
- case _PR_IO_WAIT:
- /*
- * Need to hold the thread lock when calling
- * _PR_Unblock_IO_Wait(). On return lock is
- * released.
- */
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
+
+ _PR_THREAD_LOCK(thread);
+ thread->flags |= _PR_INTERRUPT;
+ switch (thread->state) {
+ case _PR_COND_WAIT:
+ /*
+ * call is made with thread locked;
+ * on return lock is released
+ */
+ if (!(thread->flags & _PR_INTERRUPT_BLOCKED)) {
+ _PR_NotifyLockedThread(thread);
+ }
+ break;
+ case _PR_IO_WAIT:
+ /*
+ * Need to hold the thread lock when calling
+ * _PR_Unblock_IO_Wait(). On return lock is
+ * released.
+ */
#if defined(XP_UNIX) || defined(WINNT) || defined(WIN16)
- if (!(thread->flags & _PR_INTERRUPT_BLOCKED))
- _PR_Unblock_IO_Wait(thread);
+ if (!(thread->flags & _PR_INTERRUPT_BLOCKED)) {
+ _PR_Unblock_IO_Wait(thread);
+ }
#else
- _PR_THREAD_UNLOCK(thread);
+ _PR_THREAD_UNLOCK(thread);
#endif
- break;
- case _PR_RUNNING:
- case _PR_RUNNABLE:
- case _PR_LOCK_WAIT:
- default:
- _PR_THREAD_UNLOCK(thread);
- break;
- }
- if (!_PR_IS_NATIVE_THREAD(me))
- _PR_INTSON(is);
- return PR_SUCCESS;
+ break;
+ case _PR_RUNNING:
+ case _PR_RUNNABLE:
+ case _PR_LOCK_WAIT:
+ default:
+ _PR_THREAD_UNLOCK(thread);
+ break;
+ }
+ if (!_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSON(is);
+ }
+ return PR_SUCCESS;
#endif /* _PR_GLOBAL_THREADS_ONLY */
}
@@ -218,11 +234,15 @@ PR_IMPLEMENT(void) PR_ClearInterrupt()
PRIntn is;
PRThread *me = _PR_MD_CURRENT_THREAD();
- if ( !_PR_IS_NATIVE_THREAD(me)) _PR_INTSOFF(is);
+ if ( !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
_PR_THREAD_LOCK(me);
- me->flags &= ~_PR_INTERRUPT;
+ me->flags &= ~_PR_INTERRUPT;
_PR_THREAD_UNLOCK(me);
- if ( !_PR_IS_NATIVE_THREAD(me)) _PR_INTSON(is);
+ if ( !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSON(is);
+ }
}
PR_IMPLEMENT(void) PR_BlockInterrupt()
@@ -230,11 +250,15 @@ PR_IMPLEMENT(void) PR_BlockInterrupt()
PRIntn is;
PRThread *me = _PR_MD_CURRENT_THREAD();
- if ( !_PR_IS_NATIVE_THREAD(me)) _PR_INTSOFF(is);
+ if ( !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
_PR_THREAD_LOCK(me);
_PR_THREAD_BLOCK_INTERRUPT(me);
_PR_THREAD_UNLOCK(me);
- if ( !_PR_IS_NATIVE_THREAD(me)) _PR_INTSON(is);
+ if ( !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSON(is);
+ }
} /* PR_BlockInterrupt */
PR_IMPLEMENT(void) PR_UnblockInterrupt()
@@ -242,11 +266,15 @@ PR_IMPLEMENT(void) PR_UnblockInterrupt()
PRIntn is;
PRThread *me = _PR_MD_CURRENT_THREAD();
- if ( !_PR_IS_NATIVE_THREAD(me)) _PR_INTSOFF(is);
+ if ( !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSOFF(is);
+ }
_PR_THREAD_LOCK(me);
_PR_THREAD_UNBLOCK_INTERRUPT(me);
_PR_THREAD_UNLOCK(me);
- if ( !_PR_IS_NATIVE_THREAD(me)) _PR_INTSON(is);
+ if ( !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSON(is);
+ }
} /* PR_UnblockInterrupt */
/*
@@ -254,17 +282,17 @@ PR_IMPLEMENT(void) PR_UnblockInterrupt()
*/
PR_IMPLEMENT(void *) PR_GetSP(PRThread *thread)
{
- return (void *)_PR_MD_GET_SP(thread);
+ return (void *)_PR_MD_GET_SP(thread);
}
PR_IMPLEMENT(void*) GetExecutionEnvironment(PRThread *thread)
{
- return thread->environment;
+ return thread->environment;
}
PR_IMPLEMENT(void) SetExecutionEnvironment(PRThread *thread, void *env)
{
- thread->environment = env;
+ thread->environment = env;
}
@@ -280,12 +308,8 @@ PR_IMPLEMENT(PRInt32) PR_GetThreadAffinityMask(PRThread *thread, PRUint32 *mask)
PR_IMPLEMENT(PRInt32) PR_SetThreadAffinityMask(PRThread *thread, PRUint32 mask )
{
#ifdef HAVE_THREAD_AFFINITY
-#ifndef IRIX
return _PR_MD_SETTHREADAFFINITYMASK(thread, mask);
#else
- return 0;
-#endif
-#else
return 0;
#endif
}
@@ -298,7 +322,9 @@ PR_IMPLEMENT(PRInt32) PR_SetCPUAffinityMask(PRUint32 mask)
PRCList *qp;
extern PRUint32 _pr_cpu_affinity_mask;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
_pr_cpu_affinity_mask = mask;
@@ -323,27 +349,27 @@ PR_IMPLEMENT(void) PR_SetThreadRecycleMode(PRUint32 count)
}
PR_IMPLEMENT(PRThread*) PR_CreateThreadGCAble(PRThreadType type,
- void (*start)(void *arg),
- void *arg,
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize)
+ void (*start)(void *arg),
+ void *arg,
+ PRThreadPriority priority,
+ PRThreadScope scope,
+ PRThreadState state,
+ PRUint32 stackSize)
{
- return _PR_CreateThread(type, start, arg, priority, scope, state,
+ return _PR_CreateThread(type, start, arg, priority, scope, state,
stackSize, _PR_GCABLE_THREAD);
}
#ifdef SOLARIS
PR_IMPLEMENT(PRThread*) PR_CreateThreadBound(PRThreadType type,
- void (*start)(void *arg),
- void *arg,
- PRUintn priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize)
+ void (*start)(void *arg),
+ void *arg,
+ PRUintn priority,
+ PRThreadScope scope,
+ PRThreadState state,
+ PRUint32 stackSize)
{
- return _PR_CreateThread(type, start, arg, priority, scope, state,
+ return _PR_CreateThread(type, start, arg, priority, scope, state,
stackSize, _PR_BOUND_THREAD);
}
#endif
@@ -359,29 +385,36 @@ PR_IMPLEMENT(PRThread*) PR_AttachThreadGCAble(
PR_IMPLEMENT(void) PR_SetThreadGCAble()
{
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
PR_Lock(_pr_activeLock);
- _PR_MD_CURRENT_THREAD()->flags |= _PR_GCABLE_THREAD;
- PR_Unlock(_pr_activeLock);
+ _PR_MD_CURRENT_THREAD()->flags |= _PR_GCABLE_THREAD;
+ PR_Unlock(_pr_activeLock);
}
PR_IMPLEMENT(void) PR_ClearThreadGCAble()
{
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
PR_Lock(_pr_activeLock);
- _PR_MD_CURRENT_THREAD()->flags &= (~_PR_GCABLE_THREAD);
- PR_Unlock(_pr_activeLock);
+ _PR_MD_CURRENT_THREAD()->flags &= (~_PR_GCABLE_THREAD);
+ PR_Unlock(_pr_activeLock);
}
PR_IMPLEMENT(PRThreadScope) PR_GetThreadScope(const PRThread *thread)
{
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
if (_PR_IS_NATIVE_THREAD(thread)) {
- return (thread->flags & _PR_BOUND_THREAD) ? PR_GLOBAL_BOUND_THREAD :
- PR_GLOBAL_THREAD;
- } else
+ return (thread->flags & _PR_BOUND_THREAD) ? PR_GLOBAL_BOUND_THREAD :
+ PR_GLOBAL_THREAD;
+ } else {
return PR_LOCAL_THREAD;
+ }
}
PR_IMPLEMENT(PRThreadType) PR_GetThreadType(const PRThread *thread)
diff --git a/nsprpub/pr/src/threads/prdump.c b/nsprpub/pr/src/threads/prdump.c
index b40bee30c..04d842047 100644
--- a/nsprpub/pr/src/threads/prdump.c
+++ b/nsprpub/pr/src/threads/prdump.c
@@ -7,10 +7,10 @@
#if defined(WIN95)
/*
-** Some local variables report warnings on Win95 because the code paths
+** Some local variables report warnings on Win95 because the code paths
** using them are conditioned on HAVE_CUSTOME_USER_THREADS.
** The pragma suppresses the warning.
-**
+**
*/
#pragma warning(disable : 4101)
#endif
@@ -40,26 +40,26 @@ void _PR_DumpThread(PRFileDesc *fd, PRThread *thread)
_PR_DumpPrintf(fd, "%05d[%08p] pri=%2d flags=0x%02x",
thread->id, thread, thread->priority, thread->flags);
switch (thread->state) {
- case _PR_RUNNABLE:
- case _PR_RUNNING:
- break;
- case _PR_LOCK_WAIT:
- _PR_DumpPrintf(fd, " lock=%p", thread->wait.lock);
- break;
- case _PR_COND_WAIT:
- _PR_DumpPrintf(fd, " condvar=%p sleep=%lldms",
- thread->wait.cvar, thread->sleep);
- break;
- case _PR_SUSPENDED:
- _PR_DumpPrintf(fd, " suspended");
- break;
+ case _PR_RUNNABLE:
+ case _PR_RUNNING:
+ break;
+ case _PR_LOCK_WAIT:
+ _PR_DumpPrintf(fd, " lock=%p", thread->wait.lock);
+ break;
+ case _PR_COND_WAIT:
+ _PR_DumpPrintf(fd, " condvar=%p sleep=%lldms",
+ thread->wait.cvar, thread->sleep);
+ break;
+ case _PR_SUSPENDED:
+ _PR_DumpPrintf(fd, " suspended");
+ break;
}
PR_Write(fd, "\n", 1);
#endif
/* Now call dump routine */
if (thread->dump) {
- thread->dump(fd, thread, thread->dumpArg);
+ thread->dump(fd, thread, thread->dumpArg);
}
}
@@ -106,11 +106,15 @@ PR_IMPLEMENT(void) PR_ShowStatus(void)
PRIntn is;
if ( _PR_MD_CURRENT_THREAD()
- && !_PR_IS_NATIVE_THREAD(_PR_MD_CURRENT_THREAD())) _PR_INTSOFF(is);
+ && !_PR_IS_NATIVE_THREAD(_PR_MD_CURRENT_THREAD())) {
+ _PR_INTSOFF(is);
+ }
_pr_dumpOut = _pr_stderr;
_PR_DumpThreads(_pr_dumpOut);
if ( _PR_MD_CURRENT_THREAD()
- && !_PR_IS_NATIVE_THREAD(_PR_MD_CURRENT_THREAD())) _PR_FAST_INTSON(is);
+ && !_PR_IS_NATIVE_THREAD(_PR_MD_CURRENT_THREAD())) {
+ _PR_FAST_INTSON(is);
+ }
}
PR_IMPLEMENT(void)
diff --git a/nsprpub/pr/src/threads/prmon.c b/nsprpub/pr/src/threads/prmon.c
index 36be8a941..b7c526eea 100644
--- a/nsprpub/pr/src/threads/prmon.c
+++ b/nsprpub/pr/src/threads/prmon.c
@@ -20,10 +20,12 @@ static void _PR_PostNotifyToMonitor(PRMonitor *mon, PRBool broadcast)
/* mon->notifyTimes is protected by the monitor, so we don't need to
* acquire mon->lock.
*/
- if (broadcast)
+ if (broadcast) {
mon->notifyTimes = -1;
- else if (mon->notifyTimes != -1)
+ }
+ else if (mon->notifyTimes != -1) {
mon->notifyTimes += 1;
+ }
}
static void _PR_PostNotifiesFromMonitor(PRCondVar *cv, PRIntn times)
@@ -55,7 +57,9 @@ PR_IMPLEMENT(PRMonitor*) PR_NewMonitor()
PRMonitor *mon;
PRStatus rv;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
mon = PR_NEWZAP(PRMonitor);
if (mon == NULL) {
@@ -65,20 +69,23 @@ PR_IMPLEMENT(PRMonitor*) PR_NewMonitor()
rv = _PR_InitLock(&mon->lock);
PR_ASSERT(rv == PR_SUCCESS);
- if (rv != PR_SUCCESS)
+ if (rv != PR_SUCCESS) {
goto error1;
+ }
mon->owner = NULL;
rv = _PR_InitCondVar(&mon->entryCV, &mon->lock);
PR_ASSERT(rv == PR_SUCCESS);
- if (rv != PR_SUCCESS)
+ if (rv != PR_SUCCESS) {
goto error2;
+ }
rv = _PR_InitCondVar(&mon->waitCV, &mon->lock);
PR_ASSERT(rv == PR_SUCCESS);
- if (rv != PR_SUCCESS)
+ if (rv != PR_SUCCESS) {
goto error3;
+ }
mon->notifyTimes = 0;
mon->entryCount = 0;
@@ -97,8 +104,9 @@ error1:
PR_IMPLEMENT(PRMonitor*) PR_NewNamedMonitor(const char* name)
{
PRMonitor* mon = PR_NewMonitor();
- if (mon)
+ if (mon) {
mon->name = name;
+ }
return mon;
}
@@ -130,8 +138,9 @@ PR_IMPLEMENT(void) PR_EnterMonitor(PRMonitor *mon)
PR_ASSERT(mon != NULL);
PR_Lock(&mon->lock);
if (mon->entryCount != 0) {
- if (mon->owner == me)
+ if (mon->owner == me) {
goto done;
+ }
while (mon->entryCount != 0) {
rv = PR_WaitCondVar(&mon->entryCV, PR_INTERVAL_NO_TIMEOUT);
PR_ASSERT(rv == PR_SUCCESS);
@@ -161,8 +170,9 @@ PR_IMPLEMENT(PRBool) PR_TestAndEnterMonitor(PRMonitor *mon)
PR_ASSERT(mon != NULL);
PR_Lock(&mon->lock);
if (mon->entryCount != 0) {
- if (mon->owner == me)
+ if (mon->owner == me) {
goto done;
+ }
rv = PR_Unlock(&mon->lock);
PR_ASSERT(rv == PR_SUCCESS);
return PR_FALSE;
@@ -228,8 +238,9 @@ PR_IMPLEMENT(PRIntn) PR_GetMonitorEntryCount(PRMonitor *mon)
PRIntn count = 0;
PR_Lock(&mon->lock);
- if (mon->owner == me)
+ if (mon->owner == me) {
count = mon->entryCount;
+ }
rv = PR_Unlock(&mon->lock);
PR_ASSERT(rv == PR_SUCCESS);
return count;
@@ -337,10 +348,10 @@ PRUint32 _PR_MonitorToString(PRMonitor *mon, char *buf, PRUint32 buflen)
PRUint32 nb;
if (mon->owner) {
- nb = PR_snprintf(buf, buflen, "[%p] owner=%d[%p] count=%ld",
- mon, mon->owner->id, mon->owner, mon->entryCount);
+ nb = PR_snprintf(buf, buflen, "[%p] owner=%d[%p] count=%ld",
+ mon, mon->owner->id, mon->owner, mon->entryCount);
} else {
- nb = PR_snprintf(buf, buflen, "[%p]", mon);
+ nb = PR_snprintf(buf, buflen, "[%p]", mon);
}
return nb;
}
diff --git a/nsprpub/pr/src/threads/prrwlock.c b/nsprpub/pr/src/threads/prrwlock.c
index 1dd9e0a90..0cb51e5bd 100644
--- a/nsprpub/pr/src/threads/prrwlock.c
+++ b/nsprpub/pr/src/threads/prrwlock.c
@@ -36,43 +36,43 @@
* Reader-writer lock
*/
struct PRRWLock {
- char *rw_name; /* lock name */
- PRUint32 rw_rank; /* rank of the lock */
+ char *rw_name; /* lock name */
+ PRUint32 rw_rank; /* rank of the lock */
#if defined(HAVE_UNIX98_RWLOCK) || defined(HAVE_UI_RWLOCK)
- RWLOCK_T rw_lock;
+ RWLOCK_T rw_lock;
#else
- PRLock *rw_lock;
- PRInt32 rw_lock_cnt; /* == 0, if unlocked */
- /* == -1, if write-locked */
- /* > 0 , # of read locks */
- PRUint32 rw_reader_cnt; /* number of waiting readers */
- PRUint32 rw_writer_cnt; /* number of waiting writers */
- PRCondVar *rw_reader_waitq; /* cvar for readers */
- PRCondVar *rw_writer_waitq; /* cvar for writers */
+ PRLock *rw_lock;
+ PRInt32 rw_lock_cnt; /* == 0, if unlocked */
+ /* == -1, if write-locked */
+ /* > 0 , # of read locks */
+ PRUint32 rw_reader_cnt; /* number of waiting readers */
+ PRUint32 rw_writer_cnt; /* number of waiting writers */
+ PRCondVar *rw_reader_waitq; /* cvar for readers */
+ PRCondVar *rw_writer_waitq; /* cvar for writers */
#ifdef DEBUG
- PRThread *rw_owner; /* lock owner for write-lock */
+ PRThread *rw_owner; /* lock owner for write-lock */
#endif
#endif
};
#ifdef DEBUG
-#define _PR_RWLOCK_RANK_ORDER_DEBUG /* enable deadlock detection using
- rank-order for locks
- */
+#define _PR_RWLOCK_RANK_ORDER_DEBUG /* enable deadlock detection using
+ rank-order for locks
+ */
#endif
#ifdef _PR_RWLOCK_RANK_ORDER_DEBUG
-static PRUintn pr_thread_rwlock_key; /* TPD key for lock stack */
-static PRUintn pr_thread_rwlock_alloc_failed;
+static PRUintn pr_thread_rwlock_key; /* TPD key for lock stack */
+static PRUintn pr_thread_rwlock_alloc_failed;
-#define _PR_RWLOCK_RANK_ORDER_LIMIT 10
+#define _PR_RWLOCK_RANK_ORDER_LIMIT 10
typedef struct thread_rwlock_stack {
- PRInt32 trs_index; /* top of stack */
- PRRWLock *trs_stack[_PR_RWLOCK_RANK_ORDER_LIMIT]; /* stack of lock
- pointers */
+ PRInt32 trs_index; /* top of stack */
+ PRRWLock *trs_stack[_PR_RWLOCK_RANK_ORDER_LIMIT]; /* stack of lock
+ pointers */
} thread_rwlock_stack;
@@ -89,8 +89,8 @@ static void _PR_RELEASE_LOCK_STACK(void *lock_stack);
/*
* PR_NewRWLock
- * Create a reader-writer lock, with the given lock rank and lock name
- *
+ * Create a reader-writer lock, with the given lock rank and lock name
+ *
*/
PR_IMPLEMENT(PRRWLock *)
@@ -98,64 +98,67 @@ PR_NewRWLock(PRUint32 lock_rank, const char *lock_name)
{
PRRWLock *rwlock;
#if defined(HAVE_UNIX98_RWLOCK) || defined(HAVE_UI_RWLOCK)
- int err;
+ int err;
#endif
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
rwlock = PR_NEWZAP(PRRWLock);
- if (rwlock == NULL)
- return NULL;
-
- rwlock->rw_rank = lock_rank;
- if (lock_name != NULL) {
- rwlock->rw_name = (char*) PR_Malloc(strlen(lock_name) + 1);
- if (rwlock->rw_name == NULL) {
- PR_DELETE(rwlock);
- return(NULL);
- }
- strcpy(rwlock->rw_name, lock_name);
- } else {
- rwlock->rw_name = NULL;
- }
-
+ if (rwlock == NULL) {
+ return NULL;
+ }
+
+ rwlock->rw_rank = lock_rank;
+ if (lock_name != NULL) {
+ rwlock->rw_name = (char*) PR_Malloc(strlen(lock_name) + 1);
+ if (rwlock->rw_name == NULL) {
+ PR_DELETE(rwlock);
+ return(NULL);
+ }
+ strcpy(rwlock->rw_name, lock_name);
+ } else {
+ rwlock->rw_name = NULL;
+ }
+
#if defined(HAVE_UNIX98_RWLOCK) || defined(HAVE_UI_RWLOCK)
- err = RWLOCK_INIT(&rwlock->rw_lock);
- if (err != 0) {
- PR_SetError(PR_UNKNOWN_ERROR, err);
- PR_Free(rwlock->rw_name);
- PR_DELETE(rwlock);
- return NULL;
- }
- return rwlock;
+ err = RWLOCK_INIT(&rwlock->rw_lock);
+ if (err != 0) {
+ PR_SetError(PR_UNKNOWN_ERROR, err);
+ PR_Free(rwlock->rw_name);
+ PR_DELETE(rwlock);
+ return NULL;
+ }
+ return rwlock;
#else
- rwlock->rw_lock = PR_NewLock();
+ rwlock->rw_lock = PR_NewLock();
if (rwlock->rw_lock == NULL) {
- goto failed;
- }
- rwlock->rw_reader_waitq = PR_NewCondVar(rwlock->rw_lock);
+ goto failed;
+ }
+ rwlock->rw_reader_waitq = PR_NewCondVar(rwlock->rw_lock);
if (rwlock->rw_reader_waitq == NULL) {
- goto failed;
- }
- rwlock->rw_writer_waitq = PR_NewCondVar(rwlock->rw_lock);
+ goto failed;
+ }
+ rwlock->rw_writer_waitq = PR_NewCondVar(rwlock->rw_lock);
if (rwlock->rw_writer_waitq == NULL) {
- goto failed;
- }
- rwlock->rw_reader_cnt = 0;
- rwlock->rw_writer_cnt = 0;
- rwlock->rw_lock_cnt = 0;
- return rwlock;
+ goto failed;
+ }
+ rwlock->rw_reader_cnt = 0;
+ rwlock->rw_writer_cnt = 0;
+ rwlock->rw_lock_cnt = 0;
+ return rwlock;
failed:
- if (rwlock->rw_reader_waitq != NULL) {
- PR_DestroyCondVar(rwlock->rw_reader_waitq);
- }
- if (rwlock->rw_lock != NULL) {
- PR_DestroyLock(rwlock->rw_lock);
- }
- PR_Free(rwlock->rw_name);
- PR_DELETE(rwlock);
- return NULL;
+ if (rwlock->rw_reader_waitq != NULL) {
+ PR_DestroyCondVar(rwlock->rw_reader_waitq);
+ }
+ if (rwlock->rw_lock != NULL) {
+ PR_DestroyLock(rwlock->rw_lock);
+ }
+ PR_Free(rwlock->rw_name);
+ PR_DELETE(rwlock);
+ return NULL;
#endif
}
@@ -166,17 +169,18 @@ PR_IMPLEMENT(void)
PR_DestroyRWLock(PRRWLock *rwlock)
{
#if defined(HAVE_UNIX98_RWLOCK) || defined(HAVE_UI_RWLOCK)
- int err;
- err = RWLOCK_DESTROY(&rwlock->rw_lock);
- PR_ASSERT(err == 0);
+ int err;
+ err = RWLOCK_DESTROY(&rwlock->rw_lock);
+ PR_ASSERT(err == 0);
#else
- PR_ASSERT(rwlock->rw_reader_cnt == 0);
- PR_DestroyCondVar(rwlock->rw_reader_waitq);
- PR_DestroyCondVar(rwlock->rw_writer_waitq);
- PR_DestroyLock(rwlock->rw_lock);
+ PR_ASSERT(rwlock->rw_reader_cnt == 0);
+ PR_DestroyCondVar(rwlock->rw_reader_waitq);
+ PR_DestroyCondVar(rwlock->rw_writer_waitq);
+ PR_DestroyLock(rwlock->rw_lock);
#endif
- if (rwlock->rw_name != NULL)
- PR_Free(rwlock->rw_name);
+ if (rwlock->rw_name != NULL) {
+ PR_Free(rwlock->rw_name);
+ }
PR_DELETE(rwlock);
}
@@ -187,47 +191,48 @@ PR_IMPLEMENT(void)
PR_RWLock_Rlock(PRRWLock *rwlock)
{
#if defined(HAVE_UNIX98_RWLOCK) || defined(HAVE_UI_RWLOCK)
-int err;
+ int err;
#endif
#ifdef _PR_RWLOCK_RANK_ORDER_DEBUG
- /*
- * assert that rank ordering is not violated; the rank of 'rwlock' should
- * be equal to or greater than the highest rank of all the locks held by
- * the thread.
- */
- PR_ASSERT((rwlock->rw_rank == PR_RWLOCK_RANK_NONE) ||
- (rwlock->rw_rank >= _PR_GET_THREAD_RWLOCK_RANK()));
+ /*
+ * assert that rank ordering is not violated; the rank of 'rwlock' should
+ * be equal to or greater than the highest rank of all the locks held by
+ * the thread.
+ */
+ PR_ASSERT((rwlock->rw_rank == PR_RWLOCK_RANK_NONE) ||
+ (rwlock->rw_rank >= _PR_GET_THREAD_RWLOCK_RANK()));
#endif
#if defined(HAVE_UNIX98_RWLOCK) || defined(HAVE_UI_RWLOCK)
- err = RWLOCK_RDLOCK(&rwlock->rw_lock);
- PR_ASSERT(err == 0);
+ err = RWLOCK_RDLOCK(&rwlock->rw_lock);
+ PR_ASSERT(err == 0);
#else
- PR_Lock(rwlock->rw_lock);
- /*
- * wait if write-locked or if a writer is waiting; preference for writers
- */
- while ((rwlock->rw_lock_cnt < 0) ||
- (rwlock->rw_writer_cnt > 0)) {
- rwlock->rw_reader_cnt++;
- PR_WaitCondVar(rwlock->rw_reader_waitq, PR_INTERVAL_NO_TIMEOUT);
- rwlock->rw_reader_cnt--;
- }
- /*
- * Increment read-lock count
- */
- rwlock->rw_lock_cnt++;
-
- PR_Unlock(rwlock->rw_lock);
+ PR_Lock(rwlock->rw_lock);
+ /*
+ * wait if write-locked or if a writer is waiting; preference for writers
+ */
+ while ((rwlock->rw_lock_cnt < 0) ||
+ (rwlock->rw_writer_cnt > 0)) {
+ rwlock->rw_reader_cnt++;
+ PR_WaitCondVar(rwlock->rw_reader_waitq, PR_INTERVAL_NO_TIMEOUT);
+ rwlock->rw_reader_cnt--;
+ }
+ /*
+ * Increment read-lock count
+ */
+ rwlock->rw_lock_cnt++;
+
+ PR_Unlock(rwlock->rw_lock);
#endif
#ifdef _PR_RWLOCK_RANK_ORDER_DEBUG
- /*
- * update thread's lock rank
- */
- if (rwlock->rw_rank != PR_RWLOCK_RANK_NONE)
- _PR_SET_THREAD_RWLOCK_RANK(rwlock);
+ /*
+ * update thread's lock rank
+ */
+ if (rwlock->rw_rank != PR_RWLOCK_RANK_NONE) {
+ _PR_SET_THREAD_RWLOCK_RANK(rwlock);
+ }
#endif
}
@@ -238,53 +243,54 @@ PR_IMPLEMENT(void)
PR_RWLock_Wlock(PRRWLock *rwlock)
{
#if defined(DEBUG)
-PRThread *me = PR_GetCurrentThread();
+ PRThread *me = PR_GetCurrentThread();
#endif
#if defined(HAVE_UNIX98_RWLOCK) || defined(HAVE_UI_RWLOCK)
-int err;
+ int err;
#endif
#ifdef _PR_RWLOCK_RANK_ORDER_DEBUG
- /*
- * assert that rank ordering is not violated; the rank of 'rwlock' should
- * be equal to or greater than the highest rank of all the locks held by
- * the thread.
- */
- PR_ASSERT((rwlock->rw_rank == PR_RWLOCK_RANK_NONE) ||
- (rwlock->rw_rank >= _PR_GET_THREAD_RWLOCK_RANK()));
+ /*
+ * assert that rank ordering is not violated; the rank of 'rwlock' should
+ * be equal to or greater than the highest rank of all the locks held by
+ * the thread.
+ */
+ PR_ASSERT((rwlock->rw_rank == PR_RWLOCK_RANK_NONE) ||
+ (rwlock->rw_rank >= _PR_GET_THREAD_RWLOCK_RANK()));
#endif
#if defined(HAVE_UNIX98_RWLOCK) || defined(HAVE_UI_RWLOCK)
- err = RWLOCK_WRLOCK(&rwlock->rw_lock);
- PR_ASSERT(err == 0);
+ err = RWLOCK_WRLOCK(&rwlock->rw_lock);
+ PR_ASSERT(err == 0);
#else
- PR_Lock(rwlock->rw_lock);
- /*
- * wait if read locked
- */
- while (rwlock->rw_lock_cnt != 0) {
- rwlock->rw_writer_cnt++;
- PR_WaitCondVar(rwlock->rw_writer_waitq, PR_INTERVAL_NO_TIMEOUT);
- rwlock->rw_writer_cnt--;
- }
- /*
- * apply write lock
- */
- rwlock->rw_lock_cnt--;
- PR_ASSERT(rwlock->rw_lock_cnt == -1);
+ PR_Lock(rwlock->rw_lock);
+ /*
+ * wait if read locked
+ */
+ while (rwlock->rw_lock_cnt != 0) {
+ rwlock->rw_writer_cnt++;
+ PR_WaitCondVar(rwlock->rw_writer_waitq, PR_INTERVAL_NO_TIMEOUT);
+ rwlock->rw_writer_cnt--;
+ }
+ /*
+ * apply write lock
+ */
+ rwlock->rw_lock_cnt--;
+ PR_ASSERT(rwlock->rw_lock_cnt == -1);
#ifdef DEBUG
- PR_ASSERT(me != NULL);
- rwlock->rw_owner = me;
+ PR_ASSERT(me != NULL);
+ rwlock->rw_owner = me;
#endif
- PR_Unlock(rwlock->rw_lock);
+ PR_Unlock(rwlock->rw_lock);
#endif
#ifdef _PR_RWLOCK_RANK_ORDER_DEBUG
- /*
- * update thread's lock rank
- */
- if (rwlock->rw_rank != PR_RWLOCK_RANK_NONE)
- _PR_SET_THREAD_RWLOCK_RANK(rwlock);
+ /*
+ * update thread's lock rank
+ */
+ if (rwlock->rw_rank != PR_RWLOCK_RANK_NONE) {
+ _PR_SET_THREAD_RWLOCK_RANK(rwlock);
+ }
#endif
}
@@ -295,64 +301,68 @@ PR_IMPLEMENT(void)
PR_RWLock_Unlock(PRRWLock *rwlock)
{
#if defined(DEBUG)
-PRThread *me = PR_GetCurrentThread();
+ PRThread *me = PR_GetCurrentThread();
#endif
#if defined(HAVE_UNIX98_RWLOCK) || defined(HAVE_UI_RWLOCK)
-int err;
+ int err;
#endif
#if defined(HAVE_UNIX98_RWLOCK) || defined(HAVE_UI_RWLOCK)
- err = RWLOCK_UNLOCK(&rwlock->rw_lock);
- PR_ASSERT(err == 0);
+ err = RWLOCK_UNLOCK(&rwlock->rw_lock);
+ PR_ASSERT(err == 0);
#else
- PR_Lock(rwlock->rw_lock);
- /*
- * lock must be read or write-locked
- */
- PR_ASSERT(rwlock->rw_lock_cnt != 0);
- if (rwlock->rw_lock_cnt > 0) {
-
- /*
- * decrement read-lock count
- */
- rwlock->rw_lock_cnt--;
- if (rwlock->rw_lock_cnt == 0) {
- /*
- * lock is not read-locked anymore; wakeup a waiting writer
- */
- if (rwlock->rw_writer_cnt > 0)
- PR_NotifyCondVar(rwlock->rw_writer_waitq);
- }
- } else {
- PR_ASSERT(rwlock->rw_lock_cnt == -1);
-
- rwlock->rw_lock_cnt = 0;
+ PR_Lock(rwlock->rw_lock);
+ /*
+ * lock must be read or write-locked
+ */
+ PR_ASSERT(rwlock->rw_lock_cnt != 0);
+ if (rwlock->rw_lock_cnt > 0) {
+
+ /*
+ * decrement read-lock count
+ */
+ rwlock->rw_lock_cnt--;
+ if (rwlock->rw_lock_cnt == 0) {
+ /*
+ * lock is not read-locked anymore; wakeup a waiting writer
+ */
+ if (rwlock->rw_writer_cnt > 0) {
+ PR_NotifyCondVar(rwlock->rw_writer_waitq);
+ }
+ }
+ } else {
+ PR_ASSERT(rwlock->rw_lock_cnt == -1);
+
+ rwlock->rw_lock_cnt = 0;
#ifdef DEBUG
- PR_ASSERT(rwlock->rw_owner == me);
- rwlock->rw_owner = NULL;
+ PR_ASSERT(rwlock->rw_owner == me);
+ rwlock->rw_owner = NULL;
#endif
- /*
- * wakeup a writer, if present; preference for writers
- */
- if (rwlock->rw_writer_cnt > 0)
- PR_NotifyCondVar(rwlock->rw_writer_waitq);
- /*
- * else, wakeup all readers, if any
- */
- else if (rwlock->rw_reader_cnt > 0)
- PR_NotifyAllCondVar(rwlock->rw_reader_waitq);
- }
- PR_Unlock(rwlock->rw_lock);
+ /*
+ * wakeup a writer, if present; preference for writers
+ */
+ if (rwlock->rw_writer_cnt > 0) {
+ PR_NotifyCondVar(rwlock->rw_writer_waitq);
+ }
+ /*
+ * else, wakeup all readers, if any
+ */
+ else if (rwlock->rw_reader_cnt > 0) {
+ PR_NotifyAllCondVar(rwlock->rw_reader_waitq);
+ }
+ }
+ PR_Unlock(rwlock->rw_lock);
#endif
#ifdef _PR_RWLOCK_RANK_ORDER_DEBUG
- /*
- * update thread's lock rank
- */
- if (rwlock->rw_rank != PR_RWLOCK_RANK_NONE)
- _PR_UNSET_THREAD_RWLOCK_RANK(rwlock);
+ /*
+ * update thread's lock rank
+ */
+ if (rwlock->rw_rank != PR_RWLOCK_RANK_NONE) {
+ _PR_UNSET_THREAD_RWLOCK_RANK(rwlock);
+ }
#endif
- return;
+ return;
}
#ifndef _PR_RWLOCK_RANK_ORDER_DEBUG
@@ -363,121 +373,126 @@ void _PR_InitRWLocks(void) { }
void _PR_InitRWLocks(void)
{
- /*
- * allocated thread-private-data index for rwlock list
- */
- if (PR_NewThreadPrivateIndex(&pr_thread_rwlock_key,
- _PR_RELEASE_LOCK_STACK) == PR_FAILURE) {
- pr_thread_rwlock_alloc_failed = 1;
- return;
- }
+ /*
+ * allocated thread-private-data index for rwlock list
+ */
+ if (PR_NewThreadPrivateIndex(&pr_thread_rwlock_key,
+ _PR_RELEASE_LOCK_STACK) == PR_FAILURE) {
+ pr_thread_rwlock_alloc_failed = 1;
+ return;
+ }
}
/*
* _PR_SET_THREAD_RWLOCK_RANK
- * Set a thread's lock rank, which is the highest of the ranks of all
- * the locks held by the thread. Pointers to the locks are added to a
- * per-thread list, which is anchored off a thread-private data key.
+ * Set a thread's lock rank, which is the highest of the ranks of all
+ * the locks held by the thread. Pointers to the locks are added to a
+ * per-thread list, which is anchored off a thread-private data key.
*/
static void
_PR_SET_THREAD_RWLOCK_RANK(PRRWLock *rwlock)
{
-thread_rwlock_stack *lock_stack;
-PRStatus rv;
-
- /*
- * allocate a lock stack
- */
- if ((lock_stack = PR_GetThreadPrivate(pr_thread_rwlock_key)) == NULL) {
- lock_stack = (thread_rwlock_stack *)
- PR_CALLOC(1 * sizeof(thread_rwlock_stack));
- if (lock_stack) {
- rv = PR_SetThreadPrivate(pr_thread_rwlock_key, lock_stack);
- if (rv == PR_FAILURE) {
- PR_DELETE(lock_stack);
- pr_thread_rwlock_alloc_failed = 1;
- return;
- }
- } else {
- pr_thread_rwlock_alloc_failed = 1;
- return;
- }
- }
- /*
- * add rwlock to lock stack, if limit is not exceeded
- */
- if (lock_stack) {
- if (lock_stack->trs_index < _PR_RWLOCK_RANK_ORDER_LIMIT)
- lock_stack->trs_stack[lock_stack->trs_index++] = rwlock;
- }
+ thread_rwlock_stack *lock_stack;
+ PRStatus rv;
+
+ /*
+ * allocate a lock stack
+ */
+ if ((lock_stack = PR_GetThreadPrivate(pr_thread_rwlock_key)) == NULL) {
+ lock_stack = (thread_rwlock_stack *)
+ PR_CALLOC(1 * sizeof(thread_rwlock_stack));
+ if (lock_stack) {
+ rv = PR_SetThreadPrivate(pr_thread_rwlock_key, lock_stack);
+ if (rv == PR_FAILURE) {
+ PR_DELETE(lock_stack);
+ pr_thread_rwlock_alloc_failed = 1;
+ return;
+ }
+ } else {
+ pr_thread_rwlock_alloc_failed = 1;
+ return;
+ }
+ }
+ /*
+ * add rwlock to lock stack, if limit is not exceeded
+ */
+ if (lock_stack) {
+ if (lock_stack->trs_index < _PR_RWLOCK_RANK_ORDER_LIMIT) {
+ lock_stack->trs_stack[lock_stack->trs_index++] = rwlock;
+ }
+ }
}
static void
_PR_RELEASE_LOCK_STACK(void *lock_stack)
{
- PR_ASSERT(lock_stack);
- PR_DELETE(lock_stack);
+ PR_ASSERT(lock_stack);
+ PR_DELETE(lock_stack);
}
/*
* _PR_GET_THREAD_RWLOCK_RANK
*
- * return thread's lock rank. If thread-private-data for the lock
- * stack is not allocated, return PR_RWLOCK_RANK_NONE.
+ * return thread's lock rank. If thread-private-data for the lock
+ * stack is not allocated, return PR_RWLOCK_RANK_NONE.
*/
-
+
static PRUint32
_PR_GET_THREAD_RWLOCK_RANK(void)
{
- thread_rwlock_stack *lock_stack;
-
- lock_stack = PR_GetThreadPrivate(pr_thread_rwlock_key);
- if (lock_stack == NULL || lock_stack->trs_index == 0)
- return (PR_RWLOCK_RANK_NONE);
- else
- return(lock_stack->trs_stack[lock_stack->trs_index - 1]->rw_rank);
+ thread_rwlock_stack *lock_stack;
+
+ lock_stack = PR_GetThreadPrivate(pr_thread_rwlock_key);
+ if (lock_stack == NULL || lock_stack->trs_index == 0) {
+ return (PR_RWLOCK_RANK_NONE);
+ }
+ else {
+ return(lock_stack->trs_stack[lock_stack->trs_index - 1]->rw_rank);
+ }
}
/*
* _PR_UNSET_THREAD_RWLOCK_RANK
*
- * remove the rwlock from the lock stack. Since locks may not be
- * unlocked in a FIFO order, the entire lock stack is searched.
+ * remove the rwlock from the lock stack. Since locks may not be
+ * unlocked in a FIFO order, the entire lock stack is searched.
*/
-
+
static void
_PR_UNSET_THREAD_RWLOCK_RANK(PRRWLock *rwlock)
{
- thread_rwlock_stack *lock_stack;
- int new_index = 0, index, done = 0;
-
- lock_stack = PR_GetThreadPrivate(pr_thread_rwlock_key);
-
- PR_ASSERT(lock_stack != NULL);
-
- for (index = lock_stack->trs_index - 1; index >= 0; index--) {
- if (!done && (lock_stack->trs_stack[index] == rwlock)) {
- /*
- * reset the slot for rwlock
- */
- lock_stack->trs_stack[index] = NULL;
- done = 1;
- }
- /*
- * search for the lowest-numbered empty slot, above which there are
- * no non-empty slots
- */
- if (!new_index && (lock_stack->trs_stack[index] != NULL))
- new_index = index + 1;
- if (done && new_index)
- break;
- }
- /*
- * set top of stack to highest numbered empty slot
- */
- lock_stack->trs_index = new_index;
+ thread_rwlock_stack *lock_stack;
+ int new_index = 0, index, done = 0;
+
+ lock_stack = PR_GetThreadPrivate(pr_thread_rwlock_key);
+
+ PR_ASSERT(lock_stack != NULL);
+
+ for (index = lock_stack->trs_index - 1; index >= 0; index--) {
+ if (!done && (lock_stack->trs_stack[index] == rwlock)) {
+ /*
+ * reset the slot for rwlock
+ */
+ lock_stack->trs_stack[index] = NULL;
+ done = 1;
+ }
+ /*
+ * search for the lowest-numbered empty slot, above which there are
+ * no non-empty slots
+ */
+ if (!new_index && (lock_stack->trs_stack[index] != NULL)) {
+ new_index = index + 1;
+ }
+ if (done && new_index) {
+ break;
+ }
+ }
+ /*
+ * set top of stack to highest numbered empty slot
+ */
+ lock_stack->trs_index = new_index;
}
-#endif /* _PR_RWLOCK_RANK_ORDER_DEBUG */
+#endif /* _PR_RWLOCK_RANK_ORDER_DEBUG */
diff --git a/nsprpub/pr/src/threads/prsem.c b/nsprpub/pr/src/threads/prsem.c
index f5f261fe9..120075b0c 100644
--- a/nsprpub/pr/src/threads/prsem.c
+++ b/nsprpub/pr/src/threads/prsem.c
@@ -26,16 +26,16 @@ PR_IMPLEMENT(PRSemaphore*) PR_NewSem(PRUintn value)
if (!lock) {
PR_DELETE(sem);
return NULL;
- }
+ }
cvar = PR_NewCondVar(lock);
if (!cvar) {
PR_DestroyLock(lock);
PR_DELETE(sem);
return NULL;
- }
- sem->cvar = cvar;
- sem->count = value;
+ }
+ sem->cvar = cvar;
+ sem->count = value;
#endif
}
return sem;
@@ -61,56 +61,59 @@ PR_IMPLEMENT(void) PR_DestroySem(PRSemaphore *sem)
/*
** Wait on a Semaphore.
-**
-** This routine allows a calling thread to wait or proceed depending upon the
-** state of the semahore sem. The thread can proceed only if the counter value
-** of the semaphore sem is currently greater than 0. If the value of semaphore
-** sem is positive, it is decremented by one and the routine returns immediately
-** allowing the calling thread to continue. If the value of semaphore sem is 0,
-** the calling thread blocks awaiting the semaphore to be released by another
+**
+** This routine allows a calling thread to wait or proceed depending upon the
+** state of the semahore sem. The thread can proceed only if the counter value
+** of the semaphore sem is currently greater than 0. If the value of semaphore
+** sem is positive, it is decremented by one and the routine returns immediately
+** allowing the calling thread to continue. If the value of semaphore sem is 0,
+** the calling thread blocks awaiting the semaphore to be released by another
** thread.
-**
-** This routine can return PR_PENDING_INTERRUPT if the waiting thread
+**
+** This routine can return PR_PENDING_INTERRUPT if the waiting thread
** has been interrupted.
*/
PR_IMPLEMENT(PRStatus) PR_WaitSem(PRSemaphore *sem)
{
- PRStatus status = PR_SUCCESS;
+ PRStatus status = PR_SUCCESS;
#ifdef HAVE_CVAR_BUILT_ON_SEM
- return _PR_MD_WAIT_SEM(&sem->md);
+ return _PR_MD_WAIT_SEM(&sem->md);
#else
- PR_Lock(sem->cvar->lock);
- while (sem->count == 0) {
- sem->waiters++;
- status = PR_WaitCondVar(sem->cvar, PR_INTERVAL_NO_TIMEOUT);
- sem->waiters--;
- if (status != PR_SUCCESS)
- break;
- }
- if (status == PR_SUCCESS)
- sem->count--;
- PR_Unlock(sem->cvar->lock);
+ PR_Lock(sem->cvar->lock);
+ while (sem->count == 0) {
+ sem->waiters++;
+ status = PR_WaitCondVar(sem->cvar, PR_INTERVAL_NO_TIMEOUT);
+ sem->waiters--;
+ if (status != PR_SUCCESS) {
+ break;
+ }
+ }
+ if (status == PR_SUCCESS) {
+ sem->count--;
+ }
+ PR_Unlock(sem->cvar->lock);
#endif
-
- return (status);
+
+ return (status);
}
/*
-** This routine increments the counter value of the semaphore. If other threads
-** are blocked for the semaphore, then the scheduler will determine which ONE
+** This routine increments the counter value of the semaphore. If other threads
+** are blocked for the semaphore, then the scheduler will determine which ONE
** thread will be unblocked.
*/
PR_IMPLEMENT(void) PR_PostSem(PRSemaphore *sem)
{
#ifdef HAVE_CVAR_BUILT_ON_SEM
- _PR_MD_POST_SEM(&sem->md);
+ _PR_MD_POST_SEM(&sem->md);
#else
- PR_Lock(sem->cvar->lock);
- if (sem->waiters)
- PR_NotifyCondVar(sem->cvar);
- sem->count++;
- PR_Unlock(sem->cvar->lock);
+ PR_Lock(sem->cvar->lock);
+ if (sem->waiters) {
+ PR_NotifyCondVar(sem->cvar);
+ }
+ sem->count++;
+ PR_Unlock(sem->cvar->lock);
#endif
}
@@ -123,16 +126,16 @@ PR_IMPLEMENT(void) PR_PostSem(PRSemaphore *sem)
*/
PR_IMPLEMENT(PRUintn) PR_GetValueSem(PRSemaphore *sem)
{
- PRUintn rv;
+ PRUintn rv;
#ifdef HAVE_CVAR_BUILT_ON_SEM
- rv = _PR_MD_GET_VALUE_SEM(&sem->md);
+ rv = _PR_MD_GET_VALUE_SEM(&sem->md);
#else
- PR_Lock(sem->cvar->lock);
- rv = sem->count;
- PR_Unlock(sem->cvar->lock);
+ PR_Lock(sem->cvar->lock);
+ rv = sem->count;
+ PR_Unlock(sem->cvar->lock);
#endif
-
- return rv;
+
+ return rv;
}
#endif
diff --git a/nsprpub/pr/src/threads/prtpd.c b/nsprpub/pr/src/threads/prtpd.c
index 0eb2a011c..e6385cf70 100644
--- a/nsprpub/pr/src/threads/prtpd.c
+++ b/nsprpub/pr/src/threads/prtpd.c
@@ -32,7 +32,6 @@
** the routines in pr/src/btthreads/
*/
-#ifndef XP_BEOS
#include "primpl.h"
@@ -40,10 +39,10 @@
#if defined(WIN95)
/*
-** Some local variables report warnings on Win95 because the code paths
+** Some local variables report warnings on Win95 because the code paths
** using them are conditioned on HAVE_CUSTOME_USER_THREADS.
** The pragma suppresses the warning.
-**
+**
*/
#pragma warning(disable : 4101)
#endif
@@ -52,9 +51,9 @@
static PRInt32 _pr_tpd_length = 0; /* current length of destructor vector */
static PRInt32 _pr_tpd_highwater = 0; /* next TPD key to be assigned */
static PRThreadPrivateDTOR *_pr_tpd_destructors = NULL;
- /* the destructors are associated with
- the keys, therefore asserting that
- the TPD key depicts the data's 'type' */
+/* the destructors are associated with
+ the keys, therefore asserting that
+ the TPD key depicts the data's 'type' */
/*
** Initialize the thread private data manipulation
@@ -62,7 +61,7 @@ static PRThreadPrivateDTOR *_pr_tpd_destructors = NULL;
void _PR_InitTPD(void)
{
_pr_tpd_destructors = (PRThreadPrivateDTOR*)
- PR_CALLOC(_PR_TPD_LIMIT * sizeof(PRThreadPrivateDTOR*));
+ PR_CALLOC(_PR_TPD_LIMIT * sizeof(PRThreadPrivateDTOR*));
PR_ASSERT(NULL != _pr_tpd_destructors);
_pr_tpd_length = _PR_TPD_LIMIT;
}
@@ -75,22 +74,22 @@ void _PR_CleanupTPD(void)
} /* _PR_CleanupTPD */
/*
-** This routine returns a new index for per-thread-private data table.
-** The index is visible to all threads within a process. This index can
-** be used with the PR_SetThreadPrivate() and PR_GetThreadPrivate() routines
+** This routine returns a new index for per-thread-private data table.
+** The index is visible to all threads within a process. This index can
+** be used with the PR_SetThreadPrivate() and PR_GetThreadPrivate() routines
** to save and retrieve data associated with the index for a thread.
**
-** The index independently maintains specific values for each binding thread.
+** The index independently maintains specific values for each binding thread.
** A thread can only get access to its own thread-specific-data.
**
** Upon a new index return the value associated with the index for all threads
-** is NULL, and upon thread creation the value associated with all indices for
-** that thread is NULL.
+** is NULL, and upon thread creation the value associated with all indices for
+** that thread is NULL.
**
** "dtor" is the destructor function to invoke when the private
** data is set or destroyed
**
-** Returns PR_FAILURE if the total number of indices will exceed the maximun
+** Returns PR_FAILURE if the total number of indices will exceed the maximun
** allowed.
*/
@@ -100,7 +99,9 @@ PR_IMPLEMENT(PRStatus) PR_NewThreadPrivateIndex(
PRStatus rv;
PRInt32 index;
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
PR_ASSERT(NULL != newIndex);
PR_ASSERT(NULL != _pr_tpd_destructors);
@@ -124,7 +125,7 @@ PR_IMPLEMENT(PRStatus) PR_NewThreadPrivateIndex(
/*
** Define some per-thread-private data.
** "index" is an index into the per-thread private data table
-** "priv" is the per-thread-private data
+** "priv" is the per-thread-private data
**
** If the per-thread private data table has a previously registered
** destructor function and a non-NULL per-thread-private data value,
@@ -150,7 +151,7 @@ PR_IMPLEMENT(PRStatus) PR_SetThreadPrivate(PRUintn index, void *priv)
}
PR_ASSERT(((NULL == self->privateData) && (0 == self->tpdLength))
- || ((NULL != self->privateData) && (0 != self->tpdLength)));
+ || ((NULL != self->privateData) && (0 != self->tpdLength)));
/*
** If this thread does not have a sufficient vector for the index
@@ -192,9 +193,9 @@ PR_IMPLEMENT(PRStatus) PR_SetThreadPrivate(PRUintn index, void *priv)
/*
** Recover the per-thread-private data for the current thread. "index" is
-** the index into the per-thread private data table.
+** the index into the per-thread private data table.
**
-** The returned value may be NULL which is indistinguishable from an error
+** The returned value may be NULL which is indistinguishable from an error
** condition.
**
*/
@@ -203,7 +204,7 @@ PR_IMPLEMENT(void*) PR_GetThreadPrivate(PRUintn index)
{
PRThread *self = PR_GetCurrentThread();
void *tpd = ((NULL == self->privateData) || (index >= self->tpdLength)) ?
- NULL : self->privateData[index];
+ NULL : self->privateData[index];
return tpd;
}
@@ -249,4 +250,3 @@ void _PR_DestroyThreadPrivate(PRThread* self)
}
} /* _PR_DestroyThreadPrivate */
-#endif /* !XP_BEOS */