summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Engert <kaie@kuix.de>2019-09-24 00:53:06 +0000
committerKai Engert <kaie@kuix.de>2019-09-24 00:53:06 +0000
commitdaa0011ec91c63a5e9838b47fc4b981317366faa (patch)
tree9186932526405768f9604d36e0ff9a1aaba1d163
parent4771dcb79652d9d2781f01a495ad30c1b2e9170a (diff)
downloadnspr-hg-daa0011ec91c63a5e9838b47fc4b981317366faa.tar.gz
Bug 1581890 - formatted code with artistic style utility. r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D46204
-rw-r--r--config/nsinstall.c528
-rw-r--r--lib/ds/plarena.c45
-rw-r--r--lib/ds/plhash.c44
-rw-r--r--lib/ds/plvrsion.c4
-rw-r--r--lib/libc/include/plgetopt.h14
-rw-r--r--lib/libc/src/plerror.c20
-rw-r--r--lib/libc/src/plgetopt.c13
-rw-r--r--lib/libc/src/plvrsion.c4
-rw-r--r--lib/libc/src/strcase.c80
-rw-r--r--lib/libc/src/strcat.c13
-rw-r--r--lib/libc/src/strchr.c30
-rw-r--r--lib/libc/src/strcmp.c12
-rw-r--r--lib/libc/src/strcpy.c27
-rw-r--r--lib/libc/src/strdup.c14
-rw-r--r--lib/libc/src/strlen.c11
-rw-r--r--lib/libc/src/strpbrk.c25
-rw-r--r--lib/libc/src/strstr.c53
-rw-r--r--lib/libc/src/strtok.c9
-rw-r--r--lib/prstreams/plvrsion.c4
-rw-r--r--lib/prstreams/prstrms.cpp7
-rw-r--r--lib/prstreams/prstrms.h44
-rw-r--r--lib/prstreams/tests/testprstrm/testprstrm.cpp231
-rw-r--r--lib/tests/arena.c194
-rw-r--r--lib/tests/base64t.c3619
-rw-r--r--lib/tests/getopt.c21
-rw-r--r--lib/tests/string.c2662
-rw-r--r--pr/include/gencfg.c96
-rw-r--r--pr/include/md/_aix.h106
-rw-r--r--pr/include/md/_bsdi.h72
-rw-r--r--pr/include/md/_darwin.h56
-rw-r--r--pr/include/md/_freebsd.h54
-rw-r--r--pr/include/md/_hpux.h52
-rw-r--r--pr/include/md/_linux.h48
-rw-r--r--pr/include/md/_netbsd.h52
-rw-r--r--pr/include/md/_nspr_pthread.h164
-rw-r--r--pr/include/md/_nto.h122
-rw-r--r--pr/include/md/_openbsd.h50
-rw-r--r--pr/include/md/_os2.h40
-rw-r--r--pr/include/md/_os2_errors.h76
-rw-r--r--pr/include/md/_pcos.h2
-rw-r--r--pr/include/md/_pth.h36
-rw-r--r--pr/include/md/_qnx.h118
-rw-r--r--pr/include/md/_riscos.h98
-rw-r--r--pr/include/md/_scoos.h102
-rw-r--r--pr/include/md/_solaris.h296
-rw-r--r--pr/include/md/_unix_errors.h78
-rw-r--r--pr/include/md/_unixos.h332
-rw-r--r--pr/include/md/_unixware.h84
-rw-r--r--pr/include/md/_win32_errors.h70
-rw-r--r--pr/include/md/_win95.h36
-rw-r--r--pr/include/md/_winnt.h44
-rw-r--r--pr/include/obsolete/pralarm.h6
-rw-r--r--pr/include/obsolete/protypes.h6
-rw-r--r--pr/include/pratom.h36
-rw-r--r--pr/include/prbit.h38
-rw-r--r--pr/include/prclist.h60
-rw-r--r--pr/include/prcountr.h68
-rw-r--r--pr/include/prcvar.h2
-rw-r--r--pr/include/prdtoa.h2
-rw-r--r--pr/include/prerror.h24
-rw-r--r--pr/include/prinet.h4
-rw-r--r--pr/include/prinit.h8
-rw-r--r--pr/include/prinrval.h4
-rw-r--r--pr/include/prio.h118
-rw-r--r--pr/include/private/pprio.h40
-rw-r--r--pr/include/private/pprthred.h30
-rw-r--r--pr/include/private/primpl.h136
-rw-r--r--pr/include/prlink.h4
-rw-r--r--pr/include/prlock.h6
-rw-r--r--pr/include/prlog.h2
-rw-r--r--pr/include/prmem.h54
-rw-r--r--pr/include/prnetdb.h22
-rw-r--r--pr/include/prolock.h18
-rw-r--r--pr/include/prpdce.h10
-rw-r--r--pr/include/prprf.h26
-rw-r--r--pr/include/prrwlock.h12
-rw-r--r--pr/include/prshm.h30
-rw-r--r--pr/include/prthread.h12
-rw-r--r--pr/include/prtime.h34
-rw-r--r--pr/include/prtpool.h16
-rw-r--r--pr/include/prtrace.h84
-rw-r--r--pr/include/prtypes.h2
-rw-r--r--pr/include/prwin16.h4
-rw-r--r--pr/src/cplus/rcbase.cpp16
-rw-r--r--pr/src/cplus/rcbase.h8
-rw-r--r--pr/src/cplus/rccv.cpp11
-rw-r--r--pr/src/cplus/rccv.h2
-rw-r--r--pr/src/cplus/rcfileio.cpp140
-rw-r--r--pr/src/cplus/rcfileio.h40
-rw-r--r--pr/src/cplus/rcinrval.cpp22
-rw-r--r--pr/src/cplus/rcinrval.h104
-rw-r--r--pr/src/cplus/rcio.h39
-rw-r--r--pr/src/cplus/rclock.cpp4
-rw-r--r--pr/src/cplus/rclock.h14
-rw-r--r--pr/src/cplus/rcnetdb.cpp75
-rw-r--r--pr/src/cplus/rcnetdb.h14
-rw-r--r--pr/src/cplus/rcnetio.cpp124
-rw-r--r--pr/src/cplus/rcnetio.h34
-rw-r--r--[-rwxr-xr-x]pr/src/cplus/rcthread.cpp75
-rw-r--r--pr/src/cplus/rcthread.h6
-rw-r--r--pr/src/cplus/rctime.cpp40
-rw-r--r--pr/src/cplus/rctime.h58
-rw-r--r--pr/src/cplus/tests/ranfile.cpp201
-rw-r--r--pr/src/cplus/tests/switch.cpp168
-rw-r--r--pr/src/cplus/tests/thread.cpp4
-rw-r--r--pr/src/cplus/tests/tpd.cpp47
-rw-r--r--pr/src/io/prdir.c74
-rw-r--r--pr/src/io/prfdcach.c48
-rw-r--r--pr/src/io/prfile.c228
-rw-r--r--pr/src/io/prio.c126
-rw-r--r--pr/src/io/priometh.c103
-rw-r--r--pr/src/io/pripv6.c332
-rw-r--r--pr/src/io/prlayer.c279
-rw-r--r--pr/src/io/prlog.c52
-rw-r--r--pr/src/io/prmapopt.c52
-rw-r--r--pr/src/io/prmmap.c14
-rw-r--r--pr/src/io/prmwait.c245
-rw-r--r--pr/src/io/prpolevt.c6
-rw-r--r--pr/src/io/prprf.c1476
-rw-r--r--pr/src/io/prscanf.c72
-rw-r--r--pr/src/io/prsocket.c1914
-rw-r--r--pr/src/linking/prlink.c368
-rw-r--r--pr/src/malloc/prmalloc.c788
-rw-r--r--pr/src/malloc/prmem.c153
-rw-r--r--pr/src/md/os2/os2_errors.c1684
-rw-r--r--pr/src/md/os2/os2cv.c86
-rw-r--r--pr/src/md/os2/os2inrval.c5
-rw-r--r--pr/src/md/os2/os2io.c386
-rw-r--r--pr/src/md/os2/os2misc.c47
-rw-r--r--pr/src/md/os2/os2poll.c61
-rw-r--r--pr/src/md/os2/os2rng.c25
-rw-r--r--pr/src/md/os2/os2sem.c20
-rw-r--r--pr/src/md/os2/os2sock.c129
-rw-r--r--pr/src/md/os2/os2thred.c106
-rw-r--r--pr/src/md/prosdep.c10
-rw-r--r--pr/src/md/unix/aix.c133
-rw-r--r--pr/src/md/unix/aixwrap.c2
-rw-r--r--pr/src/md/unix/bsdi.c8
-rw-r--r--pr/src/md/unix/darwin.c12
-rw-r--r--pr/src/md/unix/freebsd.c12
-rw-r--r--pr/src/md/unix/hpux.c20
-rw-r--r--pr/src/md/unix/linux.c24
-rw-r--r--pr/src/md/unix/nto.c10
-rw-r--r--pr/src/md/unix/pthreads_user.c416
-rw-r--r--pr/src/md/unix/qnx.c6
-rw-r--r--pr/src/md/unix/riscos.c24
-rw-r--r--pr/src/md/unix/scoos.c13
-rw-r--r--pr/src/md/unix/solaris.c22
-rw-r--r--pr/src/md/unix/unix.c768
-rw-r--r--pr/src/md/unix/unix_errors.c30
-rw-r--r--pr/src/md/unix/unixware.c190
-rw-r--r--pr/src/md/unix/uxpoll.c152
-rw-r--r--pr/src/md/unix/uxproces.c310
-rw-r--r--pr/src/md/unix/uxrng.c2
-rw-r--r--pr/src/md/unix/uxshm.c122
-rw-r--r--pr/src/md/unix/uxwrap.c96
-rw-r--r--pr/src/md/windows/ntdllmn.c5
-rw-r--r--pr/src/md/windows/ntinrval.c2
-rw-r--r--pr/src/md/windows/ntio.c1896
-rw-r--r--pr/src/md/windows/ntmisc.c607
-rw-r--r--pr/src/md/windows/ntsec.c66
-rw-r--r--pr/src/md/windows/ntsem.c6
-rw-r--r--pr/src/md/windows/ntthread.c163
-rw-r--r--pr/src/md/windows/w32ipcsem.c14
-rw-r--r--pr/src/md/windows/w32poll.c54
-rw-r--r--pr/src/md/windows/w32rng.c15
-rw-r--r--pr/src/md/windows/w32shm.c95
-rw-r--r--pr/src/md/windows/w95cv.c20
-rw-r--r--pr/src/md/windows/w95dllmain.c5
-rw-r--r--pr/src/md/windows/w95io.c315
-rw-r--r--pr/src/md/windows/w95sock.c44
-rw-r--r--pr/src/md/windows/w95thred.c129
-rw-r--r--pr/src/memory/prseg.c26
-rw-r--r--pr/src/memory/prshm.c38
-rw-r--r--pr/src/misc/dtoa.c6650
-rw-r--r--pr/src/misc/pralarm.c61
-rw-r--r--pr/src/misc/pratom.c213
-rw-r--r--pr/src/misc/praton.c79
-rw-r--r--pr/src/misc/prcountr.c129
-rw-r--r--pr/src/misc/prdtoa.c5038
-rw-r--r--pr/src/misc/prenv.c68
-rw-r--r--pr/src/misc/prerr.c156
-rw-r--r--pr/src/misc/prerror.c21
-rw-r--r--pr/src/misc/prerrortable.c92
-rw-r--r--pr/src/misc/prinit.c190
-rw-r--r--pr/src/misc/prinrval.c12
-rw-r--r--pr/src/misc/pripcsem.c12
-rw-r--r--pr/src/misc/prlong.c355
-rw-r--r--pr/src/misc/prnetdb.c1216
-rw-r--r--pr/src/misc/prolock.c18
-rw-r--r--pr/src/misc/prrng.c4
-rw-r--r--pr/src/misc/prsystem.c118
-rw-r--r--pr/src/misc/prthinfo.c25
-rw-r--r--pr/src/misc/prtime.c1926
-rw-r--r--pr/src/misc/prtpool.c1917
-rw-r--r--pr/src/misc/prtrace.c279
-rw-r--r--pr/src/prvrsion.c4
-rw-r--r--pr/src/pthreads/ptio.c1931
-rw-r--r--pr/src/pthreads/ptmisc.c16
-rw-r--r--pr/src/pthreads/ptsynch.c142
-rw-r--r--pr/src/pthreads/ptthread.c479
-rw-r--r--pr/src/threads/combined/prucpu.c75
-rw-r--r--pr/src/threads/combined/prucv.c236
-rw-r--r--pr/src/threads/combined/prulock.c183
-rw-r--r--pr/src/threads/combined/prustack.c131
-rw-r--r--pr/src/threads/combined/pruthr.c676
-rw-r--r--pr/src/threads/prcmon.c56
-rw-r--r--pr/src/threads/prcthr.c185
-rw-r--r--pr/src/threads/prdump.c36
-rw-r--r--pr/src/threads/prmon.c37
-rw-r--r--pr/src/threads/prrwlock.c551
-rw-r--r--pr/src/threads/prsem.c63
-rw-r--r--pr/src/threads/prtpd.c16
-rw-r--r--[-rwxr-xr-x]pr/tests/abstract.c244
-rw-r--r--pr/tests/accept.c307
-rw-r--r--pr/tests/acceptread.c63
-rw-r--r--pr/tests/acceptreademu.c65
-rw-r--r--pr/tests/addrstr.c28
-rw-r--r--pr/tests/affinity.c110
-rw-r--r--pr/tests/alarm.c221
-rw-r--r--pr/tests/anonfm.c104
-rw-r--r--pr/tests/append.c68
-rw-r--r--pr/tests/attach.c202
-rw-r--r--pr/tests/bigfile.c195
-rw-r--r--pr/tests/bigfile2.c4
-rw-r--r--pr/tests/bigfile3.c2
-rw-r--r--pr/tests/bug1test.c273
-rw-r--r--pr/tests/cleanup.c68
-rw-r--r--pr/tests/cltsrv.c343
-rw-r--r--pr/tests/concur.c75
-rw-r--r--pr/tests/cvar.c218
-rw-r--r--pr/tests/cvar2.c136
-rw-r--r--pr/tests/dbmalloc.c83
-rw-r--r--pr/tests/dbmalloc1.c46
-rw-r--r--pr/tests/dceemu.c42
-rw-r--r--pr/tests/depend.c31
-rw-r--r--pr/tests/dlltest.c70
-rw-r--r--pr/tests/dtoa.c96
-rw-r--r--pr/tests/env.c198
-rw-r--r--pr/tests/errcodes.c180
-rw-r--r--pr/tests/errset.c176
-rw-r--r--pr/tests/exit.c47
-rw-r--r--pr/tests/fileio.c192
-rw-r--r--pr/tests/foreign.c254
-rw-r--r--pr/tests/forktest.c44
-rw-r--r--pr/tests/formattm.c10
-rw-r--r--pr/tests/freeif.c12
-rw-r--r--pr/tests/fsync.c51
-rw-r--r--pr/tests/getai.c2
-rw-r--r--pr/tests/gethost.c84
-rw-r--r--pr/tests/getproto.c16
-rw-r--r--pr/tests/i2l.c28
-rw-r--r--pr/tests/initclk.c20
-rw-r--r--pr/tests/inrval.c119
-rw-r--r--pr/tests/instrumt.c195
-rw-r--r--pr/tests/intrio.c17
-rw-r--r--pr/tests/intrupt.c163
-rw-r--r--pr/tests/io_timeout.c195
-rw-r--r--pr/tests/io_timeoutk.c114
-rw-r--r--pr/tests/io_timeoutu.c118
-rw-r--r--pr/tests/ioconthr.c6
-rw-r--r--pr/tests/ipv6.c48
-rw-r--r--pr/tests/join.c140
-rw-r--r--pr/tests/joinkk.c176
-rw-r--r--pr/tests/joinku.c178
-rw-r--r--pr/tests/joinuk.c168
-rw-r--r--pr/tests/joinuu.c168
-rw-r--r--pr/tests/layer.c201
-rw-r--r--pr/tests/lazyinit.c7
-rw-r--r--pr/tests/libfilename.c8
-rw-r--r--pr/tests/lltest.c454
-rw-r--r--pr/tests/lock.c159
-rw-r--r--pr/tests/lockfile.c110
-rw-r--r--pr/tests/logger.c18
-rw-r--r--pr/tests/many_cv.c42
-rw-r--r--pr/tests/mbcs.c44
-rw-r--r--pr/tests/multiacc.c10
-rw-r--r--pr/tests/multiwait.c292
-rw-r--r--pr/tests/nameshm1.c190
-rw-r--r--pr/tests/nbconn.c815
-rw-r--r--pr/tests/nblayer.c411
-rw-r--r--pr/tests/nonblock.c102
-rw-r--r--pr/tests/ntioto.c125
-rw-r--r--pr/tests/ntoh.c24
-rw-r--r--pr/tests/op_2long.c52
-rw-r--r--pr/tests/op_excl.c50
-rw-r--r--pr/tests/op_filnf.c36
-rw-r--r--pr/tests/op_filok.c30
-rw-r--r--pr/tests/op_nofil.c38
-rw-r--r--pr/tests/parent.c18
-rw-r--r--pr/tests/parsetm.c26
-rw-r--r--pr/tests/peek.c30
-rw-r--r--pr/tests/perf.c169
-rw-r--r--pr/tests/pipeself.c122
-rw-r--r--[-rwxr-xr-x]pr/tests/poll_er.c144
-rw-r--r--pr/tests/poll_nm.c320
-rw-r--r--pr/tests/poll_to.c154
-rw-r--r--pr/tests/pollable.c26
-rw-r--r--pr/tests/prftest.c24
-rw-r--r--pr/tests/prftest1.c81
-rw-r--r--pr/tests/prftest2.c80
-rw-r--r--pr/tests/primblok.c4
-rw-r--r--pr/tests/priotest.c62
-rw-r--r--pr/tests/provider.c410
-rw-r--r--pr/tests/prpoll.c338
-rw-r--r--pr/tests/prpollml.c20
-rw-r--r--pr/tests/prselect.c334
-rw-r--r--pr/tests/randseed.c40
-rw-r--r--pr/tests/ranfile.c199
-rw-r--r--pr/tests/rmdir.c18
-rw-r--r--pr/tests/rwlockrank.c14
-rw-r--r--pr/tests/rwlocktest.c284
-rw-r--r--pr/tests/sel_spd.c596
-rw-r--r--[-rwxr-xr-x]pr/tests/selct_er.c158
-rw-r--r--pr/tests/selct_nm.c284
-rw-r--r--pr/tests/selct_to.c148
-rw-r--r--pr/tests/select2.c209
-rw-r--r--pr/tests/sem.c239
-rw-r--r--pr/tests/sema.c14
-rw-r--r--pr/tests/semaerr.c4
-rw-r--r--pr/tests/semaerr1.c4
-rw-r--r--pr/tests/semaping.c8
-rw-r--r--pr/tests/semapong.c8
-rw-r--r--pr/tests/sendzlf.c20
-rw-r--r--pr/tests/server_test.c337
-rw-r--r--pr/tests/servr_kk.c319
-rw-r--r--pr/tests/servr_ku.c317
-rw-r--r--pr/tests/servr_uk.c318
-rw-r--r--pr/tests/servr_uu.c317
-rw-r--r--pr/tests/short_thread.c64
-rw-r--r--pr/tests/sigpipe.c2
-rw-r--r--pr/tests/sleep.c54
-rw-r--r--pr/tests/socket.c1055
-rw-r--r--pr/tests/sockopt.c45
-rw-r--r--pr/tests/sprintf.c404
-rw-r--r--pr/tests/stack.c442
-rw-r--r--pr/tests/stat.c10
-rw-r--r--pr/tests/stdio.c12
-rw-r--r--pr/tests/strod.c28
-rw-r--r--pr/tests/suspend.c44
-rw-r--r--pr/tests/switch.c185
-rw-r--r--pr/tests/system.c8
-rw-r--r--pr/tests/testbit.c50
-rw-r--r--pr/tests/testfile.c1505
-rw-r--r--pr/tests/threads.c54
-rw-r--r--pr/tests/thrpool_client.c81
-rw-r--r--pr/tests/thrpool_server.c493
-rw-r--r--pr/tests/thruput.c130
-rw-r--r--pr/tests/time.c68
-rw-r--r--pr/tests/timemac.c73
-rw-r--r--pr/tests/timetest.c1004
-rw-r--r--pr/tests/tmoacc.c148
-rw-r--r--pr/tests/tmocon.c192
-rw-r--r--pr/tests/tpd.c48
-rw-r--r--pr/tests/udpsrv.c142
-rw-r--r--pr/tests/version.c93
-rw-r--r--pr/tests/writev.c101
-rw-r--r--pr/tests/xnotify.c208
-rw-r--r--pr/tests/y2k.c449
-rw-r--r--pr/tests/y2ktmo.c52
-rw-r--r--pr/tests/yield.c15
-rw-r--r--pr/tests/zerolen.c12
-rw-r--r--tools/httpget.c314
-rw-r--r--tools/tail.c164
364 files changed, 39924 insertions, 33806 deletions
diff --git a/config/nsinstall.c b/config/nsinstall.c
index 48041ea2..ee6a1115 100644
--- a/config/nsinstall.c
+++ b/config/nsinstall.c
@@ -45,7 +45,7 @@
#if defined(SCO) || defined(UNIXWARE)
#if !defined(S_ISLNK) && defined(S_IFLNK)
-#define S_ISLNK(a) (((a) & S_IFMT) == S_IFLNK)
+#define S_ISLNK(a) (((a) & S_IFMT) == S_IFLNK)
#endif
#endif
@@ -57,9 +57,9 @@ static void
usage(void)
{
fprintf(stderr,
- "usage: %s [-C cwd] [-L linkprefix] [-m mode] [-o owner] [-g group]\n"
- " %*s [-DdltR] file [file ...] directory\n",
- program, (int)strlen(program), "");
+ "usage: %s [-C cwd] [-L linkprefix] [-m mode] [-o owner] [-g group]\n"
+ " %*s [-DdltR] file [file ...] directory\n",
+ program, (int)strlen(program), "");
exit(2);
}
@@ -70,23 +70,26 @@ mkdirs(char *path, mode_t mode)
struct stat sb;
int res;
- while (*path == '/' && path[1] == '/')
- path++;
+ while (*path == '/' && path[1] == '/') {
+ path++;
+ }
for (cp = strrchr(path, '/'); cp && cp != path && cp[-1] == '/'; cp--)
- ;
+ ;
if (cp && cp != path) {
- *cp = '\0';
- if ((stat(path, &sb) < 0 || !S_ISDIR(sb.st_mode)) &&
- mkdirs(path, mode) < 0) {
- return -1;
- }
- *cp = '/';
+ *cp = '\0';
+ if ((stat(path, &sb) < 0 || !S_ISDIR(sb.st_mode)) &&
+ mkdirs(path, mode) < 0) {
+ return -1;
+ }
+ *cp = '/';
}
res = mkdir(path, mode);
- if ((res != 0) && (errno == EEXIST))
- return 0;
- else
- return res;
+ if ((res != 0) && (errno == EEXIST)) {
+ return 0;
+ }
+ else {
+ return res;
+ }
}
static uid_t
@@ -97,11 +100,13 @@ touid(char *owner)
char *cp;
pw = getpwnam(owner);
- if (pw)
- return pw->pw_uid;
+ if (pw) {
+ return pw->pw_uid;
+ }
uid = strtol(owner, &cp, 0);
- if (uid == 0 && cp == owner)
- fail("cannot find uid for %s", owner);
+ if (uid == 0 && cp == owner) {
+ fail("cannot find uid for %s", owner);
+ }
return uid;
}
@@ -113,11 +118,13 @@ togid(char *group)
char *cp;
gr = getgrnam(group);
- if (gr)
- return gr->gr_gid;
+ if (gr) {
+ return gr->gr_gid;
+ }
gid = strtol(group, &cp, 0);
- if (gid == 0 && cp == group)
- fail("cannot find gid for %s", group);
+ if (gid == 0 && cp == group) {
+ fail("cannot find gid for %s", group);
+ }
return gid;
}
@@ -137,65 +144,68 @@ main(int argc, char **argv)
onlydir = dodir = dolink = dorelsymlink = dotimes = lplen = 0;
while ((opt = getopt(argc, argv, "C:DdlL:Rm:o:g:t")) != EOF) {
- switch (opt) {
- case 'C':
- cwd = optarg;
- break;
- case 'D':
- onlydir = 1;
- break;
- case 'd':
- dodir = 1;
- break;
- case 'l':
- dolink = 1;
- break;
- case 'L':
- linkprefix = optarg;
- lplen = strlen(linkprefix);
- dolink = 1;
- break;
- case 'R':
- dolink = dorelsymlink = 1;
- break;
- case 'm':
- mode = strtoul(optarg, &cp, 8);
- if (mode == 0 && cp == optarg)
- usage();
- break;
- case 'o':
- owner = optarg;
- break;
- case 'g':
- group = optarg;
- break;
- case 't':
- dotimes = 1;
- break;
- default:
- usage();
- }
+ switch (opt) {
+ case 'C':
+ cwd = optarg;
+ break;
+ case 'D':
+ onlydir = 1;
+ break;
+ case 'd':
+ dodir = 1;
+ break;
+ case 'l':
+ dolink = 1;
+ break;
+ case 'L':
+ linkprefix = optarg;
+ lplen = strlen(linkprefix);
+ dolink = 1;
+ break;
+ case 'R':
+ dolink = dorelsymlink = 1;
+ break;
+ case 'm':
+ mode = strtoul(optarg, &cp, 8);
+ if (mode == 0 && cp == optarg) {
+ usage();
+ }
+ break;
+ case 'o':
+ owner = optarg;
+ break;
+ case 'g':
+ group = optarg;
+ break;
+ case 't':
+ dotimes = 1;
+ break;
+ default:
+ usage();
+ }
}
argc -= optind;
argv += optind;
- if (argc < 2 - onlydir)
- usage();
+ if (argc < 2 - onlydir) {
+ usage();
+ }
todir = argv[argc-1];
if ((stat(todir, &sb) < 0 || !S_ISDIR(sb.st_mode)) &&
- mkdirs(todir, 0777) < 0) {
- fail("cannot make directory %s", todir);
+ mkdirs(todir, 0777) < 0) {
+ fail("cannot make directory %s", todir);
+ }
+ if (onlydir) {
+ return 0;
}
- if (onlydir)
- return 0;
if (!cwd) {
#ifdef GETCWD_CAN_MALLOC
- cwd = getcwd(0, PATH_MAX);
+ cwd = getcwd(0, PATH_MAX);
#else
- cwd = malloc(PATH_MAX + 1);
- cwd = getcwd(cwd, PATH_MAX);
+ cwd = malloc(PATH_MAX + 1);
+ cwd = getcwd(cwd, PATH_MAX);
#endif
}
xchdir(todir);
@@ -212,120 +222,134 @@ main(int argc, char **argv)
gid = group ? togid(group) : -1;
while (--argc > 0) {
- name = *argv++;
- len = strlen(name);
- base = xbasename(name);
- bnlen = strlen(base);
- toname = (char*)xmalloc(tdlen + 1 + bnlen + 1);
- sprintf(toname, "%s/%s", todir, base);
- exists = (lstat(toname, &tosb) == 0);
-
- if (dodir) {
- /* -d means create a directory, always */
- if (exists && !S_ISDIR(tosb.st_mode)) {
- (void) unlink(toname);
- exists = 0;
- }
- if (!exists && mkdir(toname, mode) < 0)
- fail("cannot make directory %s", toname);
- if ((owner || group) && chown(toname, uid, gid) < 0)
- fail("cannot change owner of %s", toname);
- } else if (dolink) {
- if (*name == '/') {
- /* source is absolute pathname, link to it directly */
- linkname = 0;
- } else {
- if (linkprefix) {
- /* -L implies -l and prefixes names with a $cwd arg. */
- len += lplen + 1;
- linkname = (char*)xmalloc(len + 1);
- sprintf(linkname, "%s/%s", linkprefix, name);
- } else if (dorelsymlink) {
- /* Symlink the relative path from todir to source name. */
- linkname = (char*)xmalloc(PATH_MAX);
-
- if (*todir == '/') {
- /* todir is absolute: skip over common prefix. */
- lplen = relatepaths(todir, cwd, linkname);
- strcpy(linkname + lplen, name);
- } else {
- /* todir is named by a relative path: reverse it. */
- reversepath(todir, name, len, linkname);
- xchdir(cwd);
- }
-
- len = strlen(linkname);
- }
- name = linkname;
- }
-
- /* Check for a pre-existing symlink with identical content. */
- if (exists &&
- (!S_ISLNK(tosb.st_mode) ||
- readlink(toname, buf, sizeof buf) != len ||
- strncmp(buf, name, len) != 0)) {
- (void) (S_ISDIR(tosb.st_mode) ? rmdir : unlink)(toname);
- exists = 0;
- }
- if (!exists && symlink(name, toname) < 0)
- fail("cannot make symbolic link %s", toname);
+ name = *argv++;
+ len = strlen(name);
+ base = xbasename(name);
+ bnlen = strlen(base);
+ toname = (char*)xmalloc(tdlen + 1 + bnlen + 1);
+ sprintf(toname, "%s/%s", todir, base);
+ exists = (lstat(toname, &tosb) == 0);
+
+ if (dodir) {
+ /* -d means create a directory, always */
+ if (exists && !S_ISDIR(tosb.st_mode)) {
+ (void) unlink(toname);
+ exists = 0;
+ }
+ if (!exists && mkdir(toname, mode) < 0) {
+ fail("cannot make directory %s", toname);
+ }
+ if ((owner || group) && chown(toname, uid, gid) < 0) {
+ fail("cannot change owner of %s", toname);
+ }
+ } else if (dolink) {
+ if (*name == '/') {
+ /* source is absolute pathname, link to it directly */
+ linkname = 0;
+ } else {
+ if (linkprefix) {
+ /* -L implies -l and prefixes names with a $cwd arg. */
+ len += lplen + 1;
+ linkname = (char*)xmalloc(len + 1);
+ sprintf(linkname, "%s/%s", linkprefix, name);
+ } else if (dorelsymlink) {
+ /* Symlink the relative path from todir to source name. */
+ linkname = (char*)xmalloc(PATH_MAX);
+
+ if (*todir == '/') {
+ /* todir is absolute: skip over common prefix. */
+ lplen = relatepaths(todir, cwd, linkname);
+ strcpy(linkname + lplen, name);
+ } else {
+ /* todir is named by a relative path: reverse it. */
+ reversepath(todir, name, len, linkname);
+ xchdir(cwd);
+ }
+
+ len = strlen(linkname);
+ }
+ name = linkname;
+ }
+
+ /* Check for a pre-existing symlink with identical content. */
+ if (exists &&
+ (!S_ISLNK(tosb.st_mode) ||
+ readlink(toname, buf, sizeof buf) != len ||
+ strncmp(buf, name, len) != 0)) {
+ (void) (S_ISDIR(tosb.st_mode) ? rmdir : unlink)(toname);
+ exists = 0;
+ }
+ if (!exists && symlink(name, toname) < 0) {
+ fail("cannot make symbolic link %s", toname);
+ }
#ifdef HAVE_LCHOWN
- if ((owner || group) && lchown(toname, uid, gid) < 0)
- fail("cannot change owner of %s", toname);
+ if ((owner || group) && lchown(toname, uid, gid) < 0) {
+ fail("cannot change owner of %s", toname);
+ }
#endif
- if (linkname) {
- free(linkname);
- linkname = 0;
- }
- } else {
- /* Copy from name to toname, which might be the same file. */
- fromfd = open(name, O_RDONLY);
- if (fromfd < 0 || fstat(fromfd, &sb) < 0)
- fail("cannot access %s", name);
- if (exists && (!S_ISREG(tosb.st_mode) || access(toname, W_OK) < 0))
- (void) (S_ISDIR(tosb.st_mode) ? rmdir : unlink)(toname);
- tofd = open(toname, O_CREAT | O_WRONLY, 0666);
- if (tofd < 0)
- fail("cannot create %s", toname);
-
- bp = buf;
- while ((cc = read(fromfd, bp, sizeof buf)) > 0) {
- while ((wc = write(tofd, bp, cc)) > 0) {
- if ((cc -= wc) == 0)
- break;
- bp += wc;
- }
- if (wc < 0)
- fail("cannot write to %s", toname);
- }
- if (cc < 0)
- fail("cannot read from %s", name);
-
- if (ftruncate(tofd, sb.st_size) < 0)
- fail("cannot truncate %s", toname);
- if (dotimes) {
- utb.actime = sb.st_atime;
- utb.modtime = sb.st_mtime;
- if (utime(toname, &utb) < 0)
- fail("cannot set times of %s", toname);
- }
+ if (linkname) {
+ free(linkname);
+ linkname = 0;
+ }
+ } else {
+ /* Copy from name to toname, which might be the same file. */
+ fromfd = open(name, O_RDONLY);
+ if (fromfd < 0 || fstat(fromfd, &sb) < 0) {
+ fail("cannot access %s", name);
+ }
+ if (exists && (!S_ISREG(tosb.st_mode) || access(toname, W_OK) < 0)) {
+ (void) (S_ISDIR(tosb.st_mode) ? rmdir : unlink)(toname);
+ }
+ tofd = open(toname, O_CREAT | O_WRONLY, 0666);
+ if (tofd < 0) {
+ fail("cannot create %s", toname);
+ }
+
+ bp = buf;
+ while ((cc = read(fromfd, bp, sizeof buf)) > 0) {
+ while ((wc = write(tofd, bp, cc)) > 0) {
+ if ((cc -= wc) == 0) {
+ break;
+ }
+ bp += wc;
+ }
+ if (wc < 0) {
+ fail("cannot write to %s", toname);
+ }
+ }
+ if (cc < 0) {
+ fail("cannot read from %s", name);
+ }
+
+ if (ftruncate(tofd, sb.st_size) < 0) {
+ fail("cannot truncate %s", toname);
+ }
+ if (dotimes) {
+ utb.actime = sb.st_atime;
+ utb.modtime = sb.st_mtime;
+ if (utime(toname, &utb) < 0) {
+ fail("cannot set times of %s", toname);
+ }
+ }
#ifdef HAVE_FCHMOD
- if (fchmod(tofd, mode) < 0)
+ if (fchmod(tofd, mode) < 0)
#else
- if (chmod(toname, mode) < 0)
+ if (chmod(toname, mode) < 0)
#endif
- fail("cannot change mode of %s", toname);
- if ((owner || group) && fchown(tofd, uid, gid) < 0)
- fail("cannot change owner of %s", toname);
-
- /* Must check for delayed (NFS) write errors on close. */
- if (close(tofd) < 0)
- fail("cannot write to %s", toname);
- close(fromfd);
- }
-
- free(toname);
+ fail("cannot change mode of %s", toname);
+ if ((owner || group) && fchown(tofd, uid, gid) < 0) {
+ fail("cannot change owner of %s", toname);
+ }
+
+ /* Must check for delayed (NFS) write errors on close. */
+ if (close(tofd) < 0) {
+ fail("cannot write to %s", toname);
+ }
+ close(fromfd);
+ }
+
+ free(toname);
}
free(cwd);
@@ -359,10 +383,10 @@ fail(char *format, ...)
if (error)
#ifdef USE_REENTRANT_LIBC
- R_STRERROR_R(errno);
- fprintf(stderr, ": %s", r_strerror_r);
+ R_STRERROR_R(errno);
+ fprintf(stderr, ": %s", r_strerror_r);
#else
- fprintf(stderr, ": %s", strerror(errno));
+ fprintf(stderr, ": %s", strerror(errno));
#endif
putc('\n', stderr);
@@ -372,18 +396,20 @@ fail(char *format, ...)
char *
getcomponent(char *path, char *name)
{
- if (*path == '\0')
- return 0;
+ if (*path == '\0') {
+ return 0;
+ }
if (*path == '/') {
- *name++ = '/';
+ *name++ = '/';
} else {
- do {
- *name++ = *path++;
- } while (*path != '/' && *path != '\0');
+ do {
+ *name++ = *path++;
+ } while (*path != '/' && *path != '\0');
}
*name = '\0';
- while (*path == '/')
- path++;
+ while (*path == '/') {
+ path++;
+ }
return path;
}
@@ -391,14 +417,14 @@ getcomponent(char *path, char *name)
/* Sigh. The static buffer in Unixware's readdir is too small. */
struct dirent * readdir(DIR *d)
{
- static struct dirent *buf = NULL;
+ static struct dirent *buf = NULL;
#define MAX_PATH_LEN 1024
- if(buf == NULL)
- buf = (struct dirent *) malloc(sizeof(struct dirent) + MAX_PATH_LEN)
-;
- return(readdir_r(d, buf));
+ if(buf == NULL)
+ buf = (struct dirent *) malloc(sizeof(struct dirent) + MAX_PATH_LEN)
+ ;
+ return(readdir_r(d, buf));
}
#endif
@@ -410,13 +436,16 @@ ino2name(ino_t ino, char *dir)
char *name;
dp = opendir("..");
- if (!dp)
- fail("cannot read parent directory");
+ if (!dp) {
+ fail("cannot read parent directory");
+ }
for (;;) {
- if (!(ep = readdir(dp)))
- fail("cannot find current directory");
- if (ep->d_ino == ino)
- break;
+ if (!(ep = readdir(dp))) {
+ fail("cannot find current directory");
+ }
+ if (ep->d_ino == ino) {
+ break;
+ }
}
name = xstrdup(ep->d_name);
closedir(dp);
@@ -427,8 +456,9 @@ void *
xmalloc(size_t size)
{
void *p = malloc(size);
- if (!p)
- fail("cannot allocate %u bytes", size);
+ if (!p) {
+ fail("cannot allocate %u bytes", size);
+ }
return p;
}
@@ -443,17 +473,21 @@ xbasename(char *path)
{
char *cp;
- while ((cp = strrchr(path, '/')) && cp[1] == '\0')
- *cp = '\0';
- if (!cp) return path;
+ while ((cp = strrchr(path, '/')) && cp[1] == '\0') {
+ *cp = '\0';
+ }
+ if (!cp) {
+ return path;
+ }
return cp + 1;
}
void
xchdir(char *dir)
{
- if (chdir(dir) < 0)
- fail("cannot change directory to %s", dir);
+ if (chdir(dir) < 0) {
+ fail("cannot change directory to %s", dir);
+ }
}
int
@@ -465,27 +499,29 @@ relatepaths(char *from, char *to, char *outpath)
assert(*from == '/' && *to == '/');
for (cp = to, cp2 = from; *cp == *cp2; cp++, cp2++)
- if (*cp == '\0')
- break;
- while (cp[-1] != '/')
- cp--, cp2--;
+ if (*cp == '\0') {
+ break;
+ }
+ while (cp[-1] != '/') {
+ cp--, cp2--;
+ }
if (cp - 1 == to) {
- /* closest common ancestor is /, so use full pathname */
- len = strlen(strcpy(outpath, to));
- if (outpath[len] != '/') {
- outpath[len++] = '/';
- outpath[len] = '\0';
- }
+ /* closest common ancestor is /, so use full pathname */
+ len = strlen(strcpy(outpath, to));
+ if (outpath[len] != '/') {
+ outpath[len++] = '/';
+ outpath[len] = '\0';
+ }
} else {
- len = 0;
- while ((cp2 = getcomponent(cp2, buf)) != 0) {
- strcpy(outpath + len, "../");
- len += 3;
- }
- while ((cp = getcomponent(cp, buf)) != 0) {
- sprintf(outpath + len, "%s/", buf);
- len += strlen(outpath + len);
- }
+ len = 0;
+ while ((cp2 = getcomponent(cp2, buf)) != 0) {
+ strcpy(outpath + len, "../");
+ len += 3;
+ }
+ while ((cp = getcomponent(cp, buf)) != 0) {
+ sprintf(outpath + len, "%s/", buf);
+ len += strlen(outpath + len);
+ }
}
return len;
}
@@ -500,23 +536,25 @@ reversepath(char *inpath, char *name, int len, char *outpath)
cp = strcpy(outpath + PATH_MAX - (len + 1), name);
cp2 = inpath;
while ((cp2 = getcomponent(cp2, buf)) != 0) {
- if (strcmp(buf, ".") == 0)
- continue;
- if (strcmp(buf, "..") == 0) {
- if (stat(".", &sb) < 0)
- fail("cannot stat current directory");
- name = ino2name(sb.st_ino, "..");
- len = strlen(name);
- cp -= len + 1;
- strcpy(cp, name);
- cp[len] = '/';
- free(name);
- xchdir("..");
- } else {
- cp -= 3;
- memcpy(cp, "../", 3);
- xchdir(buf);
- }
+ if (strcmp(buf, ".") == 0) {
+ continue;
+ }
+ if (strcmp(buf, "..") == 0) {
+ if (stat(".", &sb) < 0) {
+ fail("cannot stat current directory");
+ }
+ name = ino2name(sb.st_ino, "..");
+ len = strlen(name);
+ cp -= len + 1;
+ strcpy(cp, name);
+ cp[len] = '/';
+ free(name);
+ xchdir("..");
+ } else {
+ cp -= 3;
+ memcpy(cp, "../", 3);
+ xchdir(buf);
+ }
}
strcpy(outpath, cp);
}
diff --git a/lib/ds/plarena.c b/lib/ds/plarena.c
index 1d54e2ca..3c6df2b7 100644
--- a/lib/ds/plarena.c
+++ b/lib/ds/plarena.c
@@ -35,35 +35,40 @@ PR_IMPLEMENT(void) PL_InitArenaPool(
* align = 1 to 32.
*/
static const PRUint8 pmasks[33] = {
- 0, /* not used */
- 0, 1, 3, 3, 7, 7, 7, 7,15,15,15,15,15,15,15,15, /* 1 ... 16 */
+ 0, /* not used */
+ 0, 1, 3, 3, 7, 7, 7, 7,15,15,15,15,15,15,15,15, /* 1 ... 16 */
31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31 /* 17 ... 32 */
};
- if (align == 0)
+ if (align == 0) {
align = PL_ARENA_DEFAULT_ALIGN;
+ }
- if (align < sizeof(pmasks)/sizeof(pmasks[0]))
+ if (align < sizeof(pmasks)/sizeof(pmasks[0])) {
pool->mask = pmasks[align];
- else
+ }
+ else {
pool->mask = PR_BITMASK(PR_CeilingLog2(align));
+ }
pool->first.next = NULL;
/* Set all three addresses in pool->first to the same dummy value.
* These addresses are only compared with each other, but never
* dereferenced. */
pool->first.base = pool->first.avail = pool->first.limit =
- (PRUword)PL_ARENA_ALIGN(pool, &pool->first + 1);
+ (PRUword)PL_ARENA_ALIGN(pool, &pool->first + 1);
pool->current = &pool->first;
/*
* Compute the net size so that each arena's gross size is |size|.
* sizeof(PLArena) + pool->mask is the header and alignment slop
* that PL_ArenaAllocate adds to the net size.
*/
- if (size > sizeof(PLArena) + pool->mask)
+ if (size > sizeof(PLArena) + pool->mask) {
pool->arenasize = size - (sizeof(PLArena) + pool->mask);
- else
+ }
+ else {
pool->arenasize = size;
+ }
#ifdef PL_ARENAMETER
memset(&pool->stats, 0, sizeof pool->stats);
pool->stats.name = strdup(name);
@@ -102,8 +107,9 @@ PR_IMPLEMENT(void *) PL_ArenaAllocate(PLArenaPool *pool, PRUint32 nb)
nbOld = nb;
nb = (PRUword)PL_ARENA_ALIGN(pool, nb); /* force alignment */
- if (nb < nbOld)
+ if (nb < nbOld) {
return NULL;
+ }
/* attempt to allocate from arenas at pool->current */
{
@@ -139,8 +145,9 @@ PR_IMPLEMENT(void *) PL_ArenaAllocate(PLArenaPool *pool, PRUint32 nb)
a->next = pool->current->next;
pool->current->next = a;
pool->current = a;
- if ( NULL == pool->first.next )
+ if ( NULL == pool->first.next ) {
pool->first.next = a;
+ }
PL_COUNT_ARENA(pool,++);
COUNT(pool, nmallocs);
return(rp);
@@ -156,11 +163,13 @@ PR_IMPLEMENT(void *) PL_ArenaGrow(
{
void *newp;
- if (PR_UINT32_MAX - size < incr)
+ if (PR_UINT32_MAX - size < incr) {
return NULL;
+ }
PL_ARENA_ALLOCATE(newp, pool, size + incr);
- if (newp)
+ if (newp) {
memcpy(newp, p, size);
+ }
return newp;
}
@@ -183,8 +192,9 @@ PR_IMPLEMENT(void) PL_ClearArenaPool(PLArenaPool *pool, PRInt32 pattern)
static void FreeArenaList(PLArenaPool *pool, PLArena *head)
{
PLArena *a = head->next;
- if (!a)
+ if (!a) {
return;
+ }
head->next = NULL;
@@ -225,8 +235,9 @@ PR_IMPLEMENT(void) PL_FinishArenaPool(PLArenaPool *pool)
{
PLArenaStats *stats, **statsp;
- if (pool->stats.name)
+ if (pool->stats.name) {
PR_DELETE(pool->stats.name);
+ }
for (statsp = &arena_stats_list; (stats = *statsp) != 0;
statsp = &stats->next) {
if (stats == &pool->stats) {
@@ -267,8 +278,9 @@ PR_IMPLEMENT(void) PL_ArenaCountAllocation(PLArenaPool *pool, PRUint32 nb)
{
pool->stats.nallocs++;
pool->stats.nbytes += nb;
- if (nb > pool->stats.maxalloc)
+ if (nb > pool->stats.maxalloc) {
pool->stats.maxalloc = nb;
+ }
pool->stats.variance += nb * nb;
}
@@ -285,8 +297,9 @@ PR_IMPLEMENT(void) PL_ArenaCountGrowth(
pool->stats.nbytes += incr;
pool->stats.variance -= size * size;
size += incr;
- if (size > pool->stats.maxalloc)
+ if (size > pool->stats.maxalloc) {
pool->stats.maxalloc = size;
+ }
pool->stats.variance += size * size;
}
diff --git a/lib/ds/plhash.c b/lib/ds/plhash.c
index 0011df33..95497f06 100644
--- a/lib/ds/plhash.c
+++ b/lib/ds/plhash.c
@@ -51,8 +51,9 @@ DefaultAllocEntry(void *pool, const void *key)
static void PR_CALLBACK
DefaultFreeEntry(void *pool, PLHashEntry *he, PRUintn flag)
{
- if (flag == HT_FREE_ENTRY)
+ if (flag == HT_FREE_ENTRY) {
PR_Free(he);
+ }
}
static PLHashAllocOps defaultHashAllocOps = {
@@ -72,15 +73,19 @@ PL_NewHashTable(PRUint32 n, PLHashFunction keyHash,
n = MINBUCKETSLOG2;
} else {
n = PR_CeilingLog2(n);
- if ((PRInt32)n < 0)
+ if ((PRInt32)n < 0) {
return 0;
+ }
}
- if (!allocOps) allocOps = &defaultHashAllocOps;
+ if (!allocOps) {
+ allocOps = &defaultHashAllocOps;
+ }
ht = (PLHashTable*)((*allocOps->allocTable)(allocPriv, sizeof *ht));
- if (!ht)
- return 0;
+ if (!ht) {
+ return 0;
+ }
memset(ht, 0, sizeof *ht);
ht->shift = PL_HASH_BITS - n;
n = 1 << n;
@@ -202,7 +207,7 @@ PL_HashTableRawAdd(PLHashTable *ht, PLHashEntry **hep,
oldbuckets = ht->buckets;
nb = 2 * n * sizeof(PLHashEntry *);
ht->buckets = (PLHashEntry**)
- ((*ht->allocOps->allocTable)(ht->allocPriv, nb));
+ ((*ht->allocOps->allocTable)(ht->allocPriv, nb));
if (!ht->buckets) {
ht->buckets = oldbuckets;
return 0;
@@ -231,8 +236,9 @@ PL_HashTableRawAdd(PLHashTable *ht, PLHashEntry **hep,
/* Make a new key value entry */
he = (*ht->allocOps->allocEntry)(ht->allocPriv, key);
- if (!he)
- return 0;
+ if (!he) {
+ return 0;
+ }
he->keyHash = keyHash;
he->key = key;
he->value = value;
@@ -256,8 +262,9 @@ PL_HashTableAdd(PLHashTable *ht, const void *key, void *value)
/* key,value pair is already present in table */
return he;
}
- if (he->value)
+ if (he->value) {
(*ht->allocOps->freeEntry)(ht->allocPriv, he, HT_FREE_VALUE);
+ }
he->value = value;
return he;
}
@@ -280,7 +287,7 @@ PL_HashTableRawRemove(PLHashTable *ht, PLHashEntry **hep, PLHashEntry *he)
oldbuckets = ht->buckets;
nb = n * sizeof(PLHashEntry*) / 2;
ht->buckets = (PLHashEntry**)(
- (*ht->allocOps->allocTable)(ht->allocPriv, nb));
+ (*ht->allocOps->allocTable)(ht->allocPriv, nb));
if (!ht->buckets) {
ht->buckets = oldbuckets;
return;
@@ -315,8 +322,9 @@ PL_HashTableRemove(PLHashTable *ht, const void *key)
keyHash = (*ht->keyHash)(key);
hep = PL_HashTableRawLookup(ht, keyHash, key);
- if ((he = *hep) == 0)
+ if ((he = *hep) == 0) {
return PR_FALSE;
+ }
/* Hit; remove element */
PL_HashTableRawRemove(ht, hep, he);
@@ -414,11 +422,13 @@ PL_HashTableDumpMeter(PLHashTable *ht, PLHashEnumerator dump, FILE *fp)
nbuckets = NBUCKETS(ht);
for (i = 0; i < nbuckets; i++) {
he = ht->buckets[i];
- if (!he)
+ if (!he) {
continue;
+ }
nchains++;
- for (n = 0; he; he = he->next)
+ for (n = 0; he; he = he->next) {
n++;
+ }
variance += n * n;
if (n > maxChainLen) {
maxChainLen = n;
@@ -434,15 +444,16 @@ PL_HashTableDumpMeter(PLHashTable *ht, PLHashEnumerator dump, FILE *fp)
fprintf(fp, " number of grows: %u\n", ht->ngrows);
fprintf(fp, " number of shrinks: %u\n", ht->nshrinks);
fprintf(fp, " mean steps per hash: %g\n", (double)ht->nsteps
- / ht->nlookups);
+ / ht->nlookups);
fprintf(fp, "mean hash chain length: %g\n", mean);
fprintf(fp, " standard deviation: %g\n", sqrt(variance));
fprintf(fp, " max hash chain length: %u\n", maxChainLen);
fprintf(fp, " max hash chain: [%u]\n", maxChain);
for (he = ht->buckets[maxChain], i = 0; he; he = he->next, i++)
- if ((*dump)(he, i, fp) != HT_ENUMERATE_NEXT)
+ if ((*dump)(he, i, fp) != HT_ENUMERATE_NEXT) {
break;
+ }
}
#endif /* HASHMETER */
@@ -465,8 +476,9 @@ PL_HashString(const void *key)
const PRUint8 *s;
h = 0;
- for (s = (const PRUint8*)key; *s; s++)
+ for (s = (const PRUint8*)key; *s; s++) {
h = PR_ROTATE_LEFT32(h, 4) ^ *s;
+ }
return h;
}
diff --git a/lib/ds/plvrsion.c b/lib/ds/plvrsion.c
index 1af25417..14c1d676 100644
--- a/lib/ds/plvrsion.c
+++ b/lib/ds/plvrsion.c
@@ -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 */
diff --git a/lib/libc/include/plgetopt.h b/lib/libc/include/plgetopt.h
index 87891e85..bd5181b1 100644
--- a/lib/libc/include/plgetopt.h
+++ b/lib/libc/include/plgetopt.h
@@ -20,9 +20,9 @@ typedef struct PLOptionInternal PLOptionInternal;
typedef enum
{
- PL_OPT_OK, /* all's well with the option */
- PL_OPT_EOL, /* end of options list */
- PL_OPT_BAD /* invalid option (and value) */
+ PL_OPT_OK, /* all's well with the option */
+ PL_OPT_EOL, /* end of options list */
+ PL_OPT_BAD /* invalid option (and value) */
} PLOptStatus;
typedef struct PLLongOpt
@@ -30,7 +30,7 @@ typedef struct PLLongOpt
const char * longOptName; /* long option name string */
PRIntn longOption; /* value put in PLOptState for this option. */
PRBool valueRequired; /* If option name not followed by '=', */
- /* value is the next argument from argv. */
+ /* value is the next argument from argv. */
} PLLongOpt;
typedef struct PLOptState
@@ -52,7 +52,7 @@ typedef struct PLOptState
* followed immediately by a ':' character.
*/
PR_EXTERN(PLOptState*) PL_CreateOptState(
- PRIntn argc, char **argv, const char *options);
+ PRIntn argc, char **argv, const char *options);
/*
* PL_CreateLongOptState
@@ -66,8 +66,8 @@ PR_EXTERN(PLOptState*) PL_CreateOptState(
* followed by '=' then the next argument from argv is taken as the value.
*/
PR_EXTERN(PLOptState*) PL_CreateLongOptState(
- PRIntn argc, char **argv, const char *options,
- const PLLongOpt *longOpts);
+ PRIntn argc, char **argv, const char *options,
+ const PLLongOpt *longOpts);
/*
* PL_DestroyOptState
*
diff --git a/lib/libc/src/plerror.c b/lib/libc/src/plerror.c
index bb8e08d2..2a3510f8 100644
--- a/lib/libc/src/plerror.c
+++ b/lib/libc/src/plerror.c
@@ -16,14 +16,16 @@
PR_IMPLEMENT(void) PL_FPrintError(PRFileDesc *fd, const char *msg)
{
-PRErrorCode error = PR_GetError();
-PRInt32 oserror = PR_GetOSError();
-const char *name = PR_ErrorToName(error);
+ PRErrorCode error = PR_GetError();
+ PRInt32 oserror = PR_GetOSError();
+ const char *name = PR_ErrorToName(error);
- if (NULL != msg) PR_fprintf(fd, "%s: ", msg);
+ if (NULL != msg) {
+ PR_fprintf(fd, "%s: ", msg);
+ }
if (NULL == name)
PR_fprintf(
- fd, " (%d)OUT OF RANGE, oserror = %d\n", error, oserror);
+ fd, " (%d)OUT OF RANGE, oserror = %d\n", error, oserror);
else
PR_fprintf(
fd, "%s(%d), oserror = %d\n",
@@ -32,9 +34,11 @@ const char *name = PR_ErrorToName(error);
PR_IMPLEMENT(void) PL_PrintError(const char *msg)
{
- static PRFileDesc *fd = NULL;
- if (NULL == fd) fd = PR_GetSpecialFD(PR_StandardError);
- PL_FPrintError(fd, msg);
+ static PRFileDesc *fd = NULL;
+ if (NULL == fd) {
+ fd = PR_GetSpecialFD(PR_StandardError);
+ }
+ PL_FPrintError(fd, msg);
} /* PL_PrintError */
/* plerror.c */
diff --git a/lib/libc/src/plgetopt.c b/lib/libc/src/plgetopt.c
index 264a88ae..4e37e65f 100644
--- a/lib/libc/src/plgetopt.c
+++ b/lib/libc/src/plgetopt.c
@@ -158,10 +158,12 @@ PR_IMPLEMENT(PLOptStatus) PL_GetNextOpt(PLOptState *opt)
for (; longOpt->longOptName; ++longOpt)
{
- if (strncmp(longOpt->longOptName, internal->xargv, optNameLen))
- continue; /* not a possible match */
- if (strlen(longOpt->longOptName) != optNameLen)
- continue; /* not a match */
+ if (strncmp(longOpt->longOptName, internal->xargv, optNameLen)) {
+ continue; /* not a possible match */
+ }
+ if (strlen(longOpt->longOptName) != optNameLen) {
+ continue; /* not a match */
+ }
/* option name match */
opt->longOptIndex = longOpt - internal->longOpts;
opt->longOption = longOpt->longOption;
@@ -227,8 +229,9 @@ PR_IMPLEMENT(PLOptStatus) PL_GetNextOpt(PLOptState *opt)
internal->xargv = &static_Nul;
internal->minus = 0;
}
- else
+ else {
opt->value = NULL;
+ }
return PL_OPT_OK;
}
}
diff --git a/lib/libc/src/plvrsion.c b/lib/libc/src/plvrsion.c
index 1831f504..ffa2e95d 100644
--- a/lib/libc/src/plvrsion.c
+++ b/lib/libc/src/plvrsion.c
@@ -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 */
diff --git a/lib/libc/src/strcase.c b/lib/libc/src/strcase.c
index ad542587..f1ab038c 100644
--- a/lib/libc/src/strcase.c
+++ b/lib/libc/src/strcase.c
@@ -48,10 +48,12 @@ PL_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 )
+ if( (const char *)0 == a ) {
return ((const char *)0 == b) ? 0 : -1;
- if( (const char *)0 == b )
+ }
+ if( (const char *)0 == b ) {
return 1;
+ }
while( (uc[*ua] == uc[*ub]) && ('\0' != *a) )
{
@@ -69,10 +71,12 @@ PL_strncasecmp(const char *a, const char *b, PRUint32 max)
const unsigned char *ua = (const unsigned char *)a;
const unsigned char *ub = (const unsigned char *)b;
- if( (const char *)0 == a )
+ if( (const char *)0 == a ) {
return ((const char *)0 == b) ? 0 : -1;
- if( (const char *)0 == b )
+ }
+ if( (const char *)0 == b ) {
return 1;
+ }
while( max && (uc[*ua] == uc[*ub]) && ('\0' != *a) )
{
@@ -82,7 +86,9 @@ PL_strncasecmp(const char *a, const char *b, PRUint32 max)
max--;
}
- if( 0 == max ) return (PRIntn)0;
+ if( 0 == max ) {
+ return (PRIntn)0;
+ }
return (PRIntn)(uc[*ua] - uc[*ub]);
}
@@ -92,15 +98,20 @@ PL_strcasestr(const char *big, const char *little)
{
PRUint32 ll;
- if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
- if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
+ if( ((const char *)0 == big) || ((const char *)0 == little) ) {
+ return (char *)0;
+ }
+ if( ((char)0 == *big) || ((char)0 == *little) ) {
+ return (char *)0;
+ }
ll = strlen(little);
for( ; *big; big++ )
/* obvious improvement available here */
- if( 0 == PL_strncasecmp(big, little, ll) )
- return (char *)big;
+ if( 0 == PL_strncasecmp(big, little, ll) ) {
+ return (char *)big;
+ }
return (char *)0;
}
@@ -111,18 +122,25 @@ PL_strcaserstr(const char *big, const char *little)
const char *p;
PRUint32 bl, ll;
- if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
- if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
+ if( ((const char *)0 == big) || ((const char *)0 == little) ) {
+ return (char *)0;
+ }
+ if( ((char)0 == *big) || ((char)0 == *little) ) {
+ return (char *)0;
+ }
bl = strlen(big);
ll = strlen(little);
- if( bl < ll ) return (char *)0;
+ if( bl < ll ) {
+ return (char *)0;
+ }
p = &big[ bl - ll ];
for( ; p >= big; p-- )
/* obvious improvement available here */
- if( 0 == PL_strncasecmp(p, little, ll) )
- return (char *)p;
+ if( 0 == PL_strncasecmp(p, little, ll) ) {
+ return (char *)p;
+ }
return (char *)0;
}
@@ -132,18 +150,25 @@ PL_strncasestr(const char *big, const char *little, PRUint32 max)
{
PRUint32 ll;
- if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
- if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
+ if( ((const char *)0 == big) || ((const char *)0 == little) ) {
+ return (char *)0;
+ }
+ if( ((char)0 == *big) || ((char)0 == *little) ) {
+ return (char *)0;
+ }
ll = strlen(little);
- if( ll > max ) return (char *)0;
+ if( ll > max ) {
+ return (char *)0;
+ }
max -= ll;
max++;
for( ; max && *big; big++, max-- )
/* obvious improvement available here */
- if( 0 == PL_strncasecmp(big, little, ll) )
- return (char *)big;
+ if( 0 == PL_strncasecmp(big, little, ll) ) {
+ return (char *)big;
+ }
return (char *)0;
}
@@ -154,8 +179,12 @@ PL_strncaserstr(const char *big, const char *little, PRUint32 max)
const char *p;
PRUint32 ll;
- if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
- if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
+ if( ((const char *)0 == big) || ((const char *)0 == little) ) {
+ return (char *)0;
+ }
+ if( ((char)0 == *big) || ((char)0 == *little) ) {
+ return (char *)0;
+ }
ll = strlen(little);
@@ -163,12 +192,15 @@ PL_strncaserstr(const char *big, const char *little, PRUint32 max)
;
p -= ll;
- if( p < big ) return (char *)0;
+ if( p < big ) {
+ return (char *)0;
+ }
for( ; p >= big; p-- )
/* obvious improvement available here */
- if( 0 == PL_strncasecmp(p, little, ll) )
- return (char *)p;
+ if( 0 == PL_strncasecmp(p, little, ll) ) {
+ return (char *)p;
+ }
return (char *)0;
}
diff --git a/lib/libc/src/strcat.c b/lib/libc/src/strcat.c
index 05b7b46d..df847d36 100644
--- a/lib/libc/src/strcat.c
+++ b/lib/libc/src/strcat.c
@@ -9,8 +9,9 @@
PR_IMPLEMENT(char *)
PL_strcat(char *dest, const char *src)
{
- if( ((char *)0 == dest) || ((const char *)0 == src) )
+ if( ((char *)0 == dest) || ((const char *)0 == src) ) {
return dest;
+ }
return strcat(dest, src);
}
@@ -20,8 +21,9 @@ PL_strncat(char *dest, const char *src, PRUint32 max)
{
char *rv;
- if( ((char *)0 == dest) || ((const char *)0 == src) || (0 == max) )
+ if( ((char *)0 == dest) || ((const char *)0 == src) || (0 == max) ) {
return dest;
+ }
for( rv = dest; *dest; dest++ )
;
@@ -36,13 +38,16 @@ PL_strcatn(char *dest, PRUint32 max, const char *src)
char *rv;
PRUint32 dl;
- if( ((char *)0 == dest) || ((const char *)0 == src) )
+ if( ((char *)0 == dest) || ((const char *)0 == src) ) {
return dest;
+ }
for( rv = dest, dl = 0; *dest; dest++, dl++ )
;
- if( max <= dl ) return rv;
+ if( max <= dl ) {
+ return rv;
+ }
(void)PL_strncpyz(dest, src, max-dl);
return rv;
diff --git a/lib/libc/src/strchr.c b/lib/libc/src/strchr.c
index 523378b4..7de1887d 100644
--- a/lib/libc/src/strchr.c
+++ b/lib/libc/src/strchr.c
@@ -9,7 +9,9 @@
PR_IMPLEMENT(char *)
PL_strchr(const char *s, char c)
{
- if( (const char *)0 == s ) return (char *)0;
+ if( (const char *)0 == s ) {
+ return (char *)0;
+ }
return strchr(s, c);
}
@@ -17,7 +19,9 @@ PL_strchr(const char *s, char c)
PR_IMPLEMENT(char *)
PL_strrchr(const char *s, char c)
{
- if( (const char *)0 == s ) return (char *)0;
+ if( (const char *)0 == s ) {
+ return (char *)0;
+ }
return strrchr(s, c);
}
@@ -25,13 +29,18 @@ PL_strrchr(const char *s, char c)
PR_IMPLEMENT(char *)
PL_strnchr(const char *s, char c, PRUint32 n)
{
- if( (const char *)0 == s ) return (char *)0;
+ if( (const char *)0 == s ) {
+ return (char *)0;
+ }
for( ; n && *s; s++, n-- )
- if( *s == c )
+ if( *s == c ) {
return (char *)s;
+ }
- if( ((char)0 == c) && (n > 0) && ((char)0 == *s) ) return (char *)s;
+ if( ((char)0 == c) && (n > 0) && ((char)0 == *s) ) {
+ return (char *)s;
+ }
return (char *)0;
}
@@ -41,16 +50,21 @@ PL_strnrchr(const char *s, char c, PRUint32 n)
{
const char *p;
- if( (const char *)0 == s ) return (char *)0;
+ if( (const char *)0 == s ) {
+ return (char *)0;
+ }
for( p = s; n && *p; p++, n-- )
;
- if( ((char)0 == c) && (n > 0) && ((char)0 == *p) ) return (char *)p;
+ if( ((char)0 == c) && (n > 0) && ((char)0 == *p) ) {
+ return (char *)p;
+ }
for( p--; p >= s; p-- )
- if( *p == c )
+ if( *p == c ) {
return (char *)p;
+ }
return (char *)0;
}
diff --git a/lib/libc/src/strcmp.c b/lib/libc/src/strcmp.c
index 296d7163..9b00bbc5 100644
--- a/lib/libc/src/strcmp.c
+++ b/lib/libc/src/strcmp.c
@@ -9,10 +9,12 @@
PR_IMPLEMENT(PRIntn)
PL_strcmp(const char *a, const char *b)
{
- if( (const char *)0 == a )
+ if( (const char *)0 == a ) {
return ((const char *)0 == b) ? 0 : -1;
- if( (const char *)0 == b )
+ }
+ if( (const char *)0 == b ) {
return 1;
+ }
return (PRIntn)strcmp(a, b);
}
@@ -20,10 +22,12 @@ PL_strcmp(const char *a, const char *b)
PR_IMPLEMENT(PRIntn)
PL_strncmp(const char *a, const char *b, PRUint32 max)
{
- if( (const char *)0 == a )
+ if( (const char *)0 == a ) {
return ((const char *)0 == b) ? 0 : -1;
- if( (const char *)0 == b )
+ }
+ if( (const char *)0 == b ) {
return 1;
+ }
return (PRIntn)strncmp(a, b, (size_t)max);
}
diff --git a/lib/libc/src/strcpy.c b/lib/libc/src/strcpy.c
index 62f11a15..f49b3e75 100644
--- a/lib/libc/src/strcpy.c
+++ b/lib/libc/src/strcpy.c
@@ -9,7 +9,9 @@
PR_IMPLEMENT(char *)
PL_strcpy(char *dest, const char *src)
{
- if( ((char *)0 == dest) || ((const char *)0 == src) ) return (char *)0;
+ if( ((char *)0 == dest) || ((const char *)0 == src) ) {
+ return (char *)0;
+ }
return strcpy(dest, src);
}
@@ -19,16 +21,21 @@ PL_strncpy(char *dest, const char *src, PRUint32 max)
{
char *rv;
- if( (char *)0 == dest ) return (char *)0;
- if( (const char *)0 == src ) return (char *)0;
+ if( (char *)0 == dest ) {
+ return (char *)0;
+ }
+ if( (const char *)0 == src ) {
+ return (char *)0;
+ }
for( rv = dest; max && ((*dest = *src) != 0); dest++, src++, max-- )
;
#ifdef JLRU
/* XXX I (wtc) think the -- and ++ operators should be postfix. */
- while( --max )
+ while( --max ) {
*++dest = '\0';
+ }
#endif /* JLRU */
return rv;
@@ -39,9 +46,15 @@ PL_strncpyz(char *dest, const char *src, PRUint32 max)
{
char *rv;
- if( (char *)0 == dest ) return (char *)0;
- if( (const char *)0 == src ) return (char *)0;
- if( 0 == max ) return (char *)0;
+ if( (char *)0 == dest ) {
+ return (char *)0;
+ }
+ if( (const char *)0 == src ) {
+ return (char *)0;
+ }
+ if( 0 == max ) {
+ return (char *)0;
+ }
for( rv = dest, max--; max && ((*dest = *src) != 0); dest++, src++, max-- )
;
diff --git a/lib/libc/src/strdup.c b/lib/libc/src/strdup.c
index c267147c..d2deae43 100644
--- a/lib/libc/src/strdup.c
+++ b/lib/libc/src/strdup.c
@@ -13,13 +13,16 @@ PL_strdup(const char *s)
char *rv;
size_t n;
- if( (const char *)0 == s )
+ if( (const char *)0 == s ) {
s = "";
+ }
n = strlen(s) + 1;
rv = (char *)malloc(n);
- if( (char *)0 == rv ) return rv;
+ if( (char *)0 == rv ) {
+ return rv;
+ }
(void)memcpy(rv, s, n);
@@ -38,13 +41,16 @@ PL_strndup(const char *s, PRUint32 max)
char *rv;
size_t l;
- if( (const char *)0 == s )
+ if( (const char *)0 == s ) {
s = "";
+ }
l = PL_strnlen(s, max);
rv = (char *)malloc(l+1);
- if( (char *)0 == rv ) return rv;
+ if( (char *)0 == rv ) {
+ return rv;
+ }
(void)memcpy(rv, s, l);
rv[l] = '\0';
diff --git a/lib/libc/src/strlen.c b/lib/libc/src/strlen.c
index ffcf5eed..2888175d 100644
--- a/lib/libc/src/strlen.c
+++ b/lib/libc/src/strlen.c
@@ -13,7 +13,9 @@ PL_strlen(const char *str)
{
size_t l;
- if( (const char *)0 == str ) return 0;
+ if( (const char *)0 == str ) {
+ return 0;
+ }
l = strlen(str);
@@ -22,8 +24,9 @@ PL_strlen(const char *str)
*/
if( sizeof(PRUint32) < sizeof(size_t) )
{
- if( l > PR_INT32_MAX )
+ if( l > PR_INT32_MAX ) {
PR_Assert("l <= PR_INT32_MAX", __FILE__, __LINE__);
+ }
}
return (PRUint32)l;
@@ -34,7 +37,9 @@ PL_strnlen(const char *str, PRUint32 max)
{
register const char *s;
- if( (const char *)0 == str ) return 0;
+ if( (const char *)0 == str ) {
+ return 0;
+ }
for( s = str; max && *s; s++, max-- )
;
diff --git a/lib/libc/src/strpbrk.c b/lib/libc/src/strpbrk.c
index 0d2be981..89ccbe69 100644
--- a/lib/libc/src/strpbrk.c
+++ b/lib/libc/src/strpbrk.c
@@ -9,7 +9,9 @@
PR_IMPLEMENT(char *)
PL_strpbrk(const char *s, const char *list)
{
- if( ((const char *)0 == s) || ((const char *)0 == list) ) return (char *)0;
+ if( ((const char *)0 == s) || ((const char *)0 == list) ) {
+ return (char *)0;
+ }
return strpbrk(s, list);
}
@@ -20,15 +22,18 @@ PL_strprbrk(const char *s, const char *list)
const char *p;
const char *r;
- if( ((const char *)0 == s) || ((const char *)0 == list) ) return (char *)0;
+ if( ((const char *)0 == s) || ((const char *)0 == list) ) {
+ return (char *)0;
+ }
for( r = s; *r; r++ )
;
for( r--; r >= s; r-- )
for( p = list; *p; p++ )
- if( *r == *p )
+ if( *r == *p ) {
return (char *)r;
+ }
return (char *)0;
}
@@ -38,12 +43,15 @@ PL_strnpbrk(const char *s, const char *list, PRUint32 max)
{
const char *p;
- if( ((const char *)0 == s) || ((const char *)0 == list) ) return (char *)0;
+ if( ((const char *)0 == s) || ((const char *)0 == list) ) {
+ return (char *)0;
+ }
for( ; max && *s; s++, max-- )
for( p = list; *p; p++ )
- if( *s == *p )
+ if( *s == *p ) {
return (char *)s;
+ }
return (char *)0;
}
@@ -54,15 +62,18 @@ PL_strnprbrk(const char *s, const char *list, PRUint32 max)
const char *p;
const char *r;
- if( ((const char *)0 == s) || ((const char *)0 == list) ) return (char *)0;
+ if( ((const char *)0 == s) || ((const char *)0 == list) ) {
+ return (char *)0;
+ }
for( r = s; max && *r; r++, max-- )
;
for( r--; r >= s; r-- )
for( p = list; *p; p++ )
- if( *r == *p )
+ if( *r == *p ) {
return (char *)r;
+ }
return (char *)0;
}
diff --git a/lib/libc/src/strstr.c b/lib/libc/src/strstr.c
index a90d8226..dd27a23e 100644
--- a/lib/libc/src/strstr.c
+++ b/lib/libc/src/strstr.c
@@ -9,8 +9,12 @@
PR_IMPLEMENT(char *)
PL_strstr(const char *big, const char *little)
{
- if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
- if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
+ if( ((const char *)0 == big) || ((const char *)0 == little) ) {
+ return (char *)0;
+ }
+ if( ((char)0 == *big) || ((char)0 == *little) ) {
+ return (char *)0;
+ }
return strstr(big, little);
}
@@ -22,18 +26,25 @@ PL_strrstr(const char *big, const char *little)
size_t ll;
size_t bl;
- if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
- if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
+ if( ((const char *)0 == big) || ((const char *)0 == little) ) {
+ return (char *)0;
+ }
+ if( ((char)0 == *big) || ((char)0 == *little) ) {
+ return (char *)0;
+ }
ll = strlen(little);
bl = strlen(big);
- if( bl < ll ) return (char *)0;
+ if( bl < ll ) {
+ return (char *)0;
+ }
p = &big[ bl - ll ];
for( ; p >= big; p-- )
if( *little == *p )
- if( 0 == strncmp(p, little, ll) )
+ if( 0 == strncmp(p, little, ll) ) {
return (char *)p;
+ }
return (char *)0;
}
@@ -43,18 +54,25 @@ PL_strnstr(const char *big, const char *little, PRUint32 max)
{
size_t ll;
- if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
- if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
+ if( ((const char *)0 == big) || ((const char *)0 == little) ) {
+ return (char *)0;
+ }
+ if( ((char)0 == *big) || ((char)0 == *little) ) {
+ return (char *)0;
+ }
ll = strlen(little);
- if( ll > (size_t)max ) return (char *)0;
+ if( ll > (size_t)max ) {
+ return (char *)0;
+ }
max -= (PRUint32)ll;
max++;
for( ; max && *big; big++, max-- )
if( *little == *big )
- if( 0 == strncmp(big, little, ll) )
+ if( 0 == strncmp(big, little, ll) ) {
return (char *)big;
+ }
return (char *)0;
}
@@ -65,8 +83,12 @@ PL_strnrstr(const char *big, const char *little, PRUint32 max)
const char *p;
size_t ll;
- if( ((const char *)0 == big) || ((const char *)0 == little) ) return (char *)0;
- if( ((char)0 == *big) || ((char)0 == *little) ) return (char *)0;
+ if( ((const char *)0 == big) || ((const char *)0 == little) ) {
+ return (char *)0;
+ }
+ if( ((char)0 == *big) || ((char)0 == *little) ) {
+ return (char *)0;
+ }
ll = strlen(little);
@@ -74,12 +96,15 @@ PL_strnrstr(const char *big, const char *little, PRUint32 max)
;
p -= ll;
- if( p < big ) return (char *)0;
+ if( p < big ) {
+ return (char *)0;
+ }
for( ; p >= big; p-- )
if( *little == *p )
- if( 0 == strncmp(p, little, ll) )
+ if( 0 == strncmp(p, little, ll) ) {
return (char *)p;
+ }
return (char *)0;
}
diff --git a/lib/libc/src/strtok.c b/lib/libc/src/strtok.c
index b23b2c5c..df404494 100644
--- a/lib/libc/src/strtok.c
+++ b/lib/libc/src/strtok.c
@@ -14,8 +14,9 @@ PL_strtok_r(char *s1, const char *s2, char **lasts)
if( s1 == NULL )
{
- if( *lasts == NULL )
+ if( *lasts == NULL ) {
return NULL;
+ }
s1 = *lasts;
}
@@ -24,11 +25,13 @@ PL_strtok_r(char *s1, const char *s2, char **lasts)
{
for( sepp = s2 ; (sc = *sepp) != 0 ; sepp++ )
{
- if( c == sc )
+ if( c == sc ) {
break;
+ }
}
- if( sc == 0 )
+ if( sc == 0 ) {
break;
+ }
}
if( c == 0 )
diff --git a/lib/prstreams/plvrsion.c b/lib/prstreams/plvrsion.c
index bb32e88d..a8332ff6 100644
--- a/lib/prstreams/plvrsion.c
+++ b/lib/prstreams/plvrsion.c
@@ -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 */
diff --git a/lib/prstreams/prstrms.cpp b/lib/prstreams/prstrms.cpp
index d601fce2..878175df 100644
--- a/lib/prstreams/prstrms.cpp
+++ b/lib/prstreams/prstrms.cpp
@@ -115,7 +115,7 @@ PRfilebuf *PRfilebuf::open(
_opened = true;
if (ate &&
- seekoff(0, ios_base::end, flags) == pos_type(traits_type::eof())) {
+ seekoff(0, ios_base::end, flags) == pos_type(traits_type::eof())) {
close();
return NULL;
}
@@ -138,13 +138,14 @@ PRfilebuf *PRfilebuf::attach(PRFileDesc *fd)
PRfilebuf *PRfilebuf::close()
{
- if (_fd == NULL)
+ if (_fd == NULL) {
return NULL;
+ }
int status = sync();
if (PR_Close(_fd) == PR_FAILURE ||
- traits_type::eq_int_type(status, traits_type::eof())) {
+ traits_type::eq_int_type(status, traits_type::eof())) {
return NULL;
}
diff --git a/lib/prstreams/prstrms.h b/lib/prstreams/prstrms.h
index 319dbf9d..113a4162 100644
--- a/lib/prstreams/prstrms.h
+++ b/lib/prstreams/prstrms.h
@@ -34,24 +34,26 @@ public:
PRfilebuf(PRFileDesc *fd, char_type *ptr, std::streamsize len);
virtual ~PRfilebuf();
- bool is_open() const { return _fd != NULL; }
+ bool is_open() const {
+ return _fd != NULL;
+ }
PRfilebuf *open(
- const char *name,
- std::ios_base::openmode flags,
- PRIntn mode);
+ const char *name,
+ std::ios_base::openmode flags,
+ PRIntn mode);
PRfilebuf *attach(PRFileDesc *fd);
PRfilebuf *close();
protected:
virtual std::streambuf *setbuf(char_type *ptr, std::streamsize len);
virtual pos_type seekoff(
- off_type offset,
- std::ios_base::seekdir dir,
- std::ios_base::openmode flags);
+ off_type offset,
+ std::ios_base::seekdir dir,
+ std::ios_base::openmode flags);
virtual pos_type seekpos(
- pos_type pos,
- std::ios_base::openmode flags) {
+ pos_type pos,
+ std::ios_base::openmode flags) {
return seekoff(pos, std::ios_base::beg, flags);
}
virtual int sync();
@@ -83,8 +85,12 @@ public:
PRifstream(const char *name, openmode flags = in, PRIntn mode = 0);
virtual ~PRifstream();
- PRfilebuf *rdbuf() const { return &_filebuf; }
- bool is_open() const { return _filebuf.is_open(); }
+ PRfilebuf *rdbuf() const {
+ return &_filebuf;
+ }
+ bool is_open() const {
+ return _filebuf.is_open();
+ }
void open(const char *name, openmode flags = in, PRIntn mode = 0);
void attach(PRFileDesc *fd);
@@ -104,8 +110,12 @@ public:
PRofstream(const char *name, openmode flags = out, PRIntn mode = 0);
virtual ~PRofstream();
- PRfilebuf *rdbuf() const { return &_filebuf; }
- bool is_open() const { return _filebuf.is_open(); }
+ PRfilebuf *rdbuf() const {
+ return &_filebuf;
+ }
+ bool is_open() const {
+ return _filebuf.is_open();
+ }
void open(const char *name, openmode flags = out, PRIntn mode = 0);
void attach(PRFileDesc *fd);
@@ -125,8 +135,12 @@ public:
PRfstream(const char *name, openmode flags = in | out, PRIntn mode = 0);
virtual ~PRfstream();
- PRfilebuf *rdbuf() const { return &_filebuf; }
- bool is_open() const { return _filebuf.is_open(); }
+ PRfilebuf *rdbuf() const {
+ return &_filebuf;
+ }
+ bool is_open() const {
+ return _filebuf.is_open();
+ }
void open(const char *name, openmode flags = in | out, PRIntn mode = 0);
void attach(PRFileDesc *fd);
diff --git a/lib/prstreams/tests/testprstrm/testprstrm.cpp b/lib/prstreams/tests/testprstrm/testprstrm.cpp
index 8ab455b5..236e6ac6 100644
--- a/lib/prstreams/tests/testprstrm/testprstrm.cpp
+++ b/lib/prstreams/tests/testprstrm/testprstrm.cpp
@@ -41,131 +41,132 @@ threadmain(void *mytag)
void
threadwork(threadarg *arg)
{
- unsigned int i;
+ unsigned int i;
- char fname1[256];
- char fname2[256];
+ char fname1[256];
+ char fname2[256];
- strcpy(fname1, arg->mytag);
- strcpy(fname2, arg->mytag);
- strcat(fname2, "2");
- PR_Delete(fname1);
- PR_Delete(fname2);
+ strcpy(fname1, arg->mytag);
+ strcpy(fname2, arg->mytag);
+ strcat(fname2, "2");
+ PR_Delete(fname1);
+ PR_Delete(fname2);
- PRfilebuf *fb[MaxCnt];
- PRifstream *ifs[MaxCnt];
- PRofstream *ofs[MaxCnt];
- int mode = 0;
+ PRfilebuf *fb[MaxCnt];
+ PRifstream *ifs[MaxCnt];
+ PRofstream *ofs[MaxCnt];
+ int mode = 0;
#ifdef XP_UNIX
- mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH;
+ mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH;
#endif
- //
- // Allocate a bunch
- cout << "Testing unused filebufs ----------------" << endl;
- for (i=0; i < MaxCnt; i++){
- fb[i] = new PRfilebuf;
- }
- // Delete them
- for (i=0; i < MaxCnt; i++){
- delete fb[i];
- }
- cout << "Unused filebufs complete ---------------" << endl;
-
- //
- // Allocate a bunch
- cout << "Testing unused ifstream -----------------" << endl;
- for (i=0; i < MaxCnt; i++){
- ifs[i] = new PRifstream;
- }
- //
- // Delete them
- for (i=0; i < MaxCnt; i++){
- delete ifs[i];
- }
- cout << "Unused ifstream complete ----------------" << endl;
- //
- // Allocate a bunch
- cout << "Testing unused ofstream -----------------" << endl;
- for (i=0; i < MaxCnt; i++){
- ofs[i] = new PRofstream;
- }
- for (i=0; i < MaxCnt; i++){
- *(ofs[i]) << "A"; // Write a bit
- delete ofs[i]; // Delete it.
- }
- cout << "Unused ofstream complete ----------------" << endl;
-
- cout << "Testing use of ofstream 1 (extra filebuf allocated) ---------" << endl;
- PRofstream *aos = new PRofstream(fname1, ios::out|ios::ate, mode);
- for (i=0; i < MaxCnt; i++){
- for (int j=0; j < 8192; j++)
- *aos << "AaBbCcDdEeFfGg" << endl;
- fb[i] = new PRfilebuf; // Allocate as we go to hack at the heap
- }
- //
- // Delete the extra foo we allocated
- for (i=0; i < MaxCnt; i++){
- delete fb[i];
- }
- aos->flush(); // Explicit flush
- delete aos;
- cout << "Testing use of ofstream 1 complete (extra filebuf deleted) --" << endl;
- cout << "Testing use of ofstream 2 (extra filebuf allocated) ---------" << endl;
- PRofstream *aos2 = new PRofstream(fname2, ios::out, mode);
-
- for (i=0; i < MaxCnt; i++){
- *aos2 << "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz";
- }
- // Force flushing in the dtor
- delete aos2;
- cout << "Testing use of ofstream 2 complete (extra filebuf deleted) --" << endl;
- char line[1024];
- cout << "Testing use of ifstream 1 (stack allocation) -------------" << endl;
- PRifstream ais(fname1);
- for (i=0; i < MaxCnt; i++){
- ais >> line;
- }
- cout << "Testing use of ifstream 1 complete -----------------------" << endl;
- cout << "Testing use of ifstream 2 ----------------------" << endl;
- PRifstream *ais2 = new PRifstream(fname2);
- char achar;
- for (i=0; i < MaxCnt*10; i++){
- *ais2 >> achar;
- }
- delete ais2;
- cout << "Testing use of ifstream 2 complete -------------" << endl;
+ //
+ // Allocate a bunch
+ cout << "Testing unused filebufs ----------------" << endl;
+ for (i=0; i < MaxCnt; i++) {
+ fb[i] = new PRfilebuf;
+ }
+ // Delete them
+ for (i=0; i < MaxCnt; i++) {
+ delete fb[i];
+ }
+ cout << "Unused filebufs complete ---------------" << endl;
+
+ //
+ // Allocate a bunch
+ cout << "Testing unused ifstream -----------------" << endl;
+ for (i=0; i < MaxCnt; i++) {
+ ifs[i] = new PRifstream;
+ }
+ //
+ // Delete them
+ for (i=0; i < MaxCnt; i++) {
+ delete ifs[i];
+ }
+ cout << "Unused ifstream complete ----------------" << endl;
+ //
+ // Allocate a bunch
+ cout << "Testing unused ofstream -----------------" << endl;
+ for (i=0; i < MaxCnt; i++) {
+ ofs[i] = new PRofstream;
+ }
+ for (i=0; i < MaxCnt; i++) {
+ *(ofs[i]) << "A"; // Write a bit
+ delete ofs[i]; // Delete it.
+ }
+ cout << "Unused ofstream complete ----------------" << endl;
+
+ cout << "Testing use of ofstream 1 (extra filebuf allocated) ---------" << endl;
+ PRofstream *aos = new PRofstream(fname1, ios::out|ios::ate, mode);
+ for (i=0; i < MaxCnt; i++) {
+ for (int j=0; j < 8192; j++) {
+ *aos << "AaBbCcDdEeFfGg" << endl;
+ }
+ fb[i] = new PRfilebuf; // Allocate as we go to hack at the heap
+ }
+ //
+ // Delete the extra foo we allocated
+ for (i=0; i < MaxCnt; i++) {
+ delete fb[i];
+ }
+ aos->flush(); // Explicit flush
+ delete aos;
+ cout << "Testing use of ofstream 1 complete (extra filebuf deleted) --" << endl;
+ cout << "Testing use of ofstream 2 (extra filebuf allocated) ---------" << endl;
+ PRofstream *aos2 = new PRofstream(fname2, ios::out, mode);
+
+ for (i=0; i < MaxCnt; i++) {
+ *aos2 << "AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz";
+ }
+ // Force flushing in the dtor
+ delete aos2;
+ cout << "Testing use of ofstream 2 complete (extra filebuf deleted) --" << endl;
+ char line[1024];
+ cout << "Testing use of ifstream 1 (stack allocation) -------------" << endl;
+ PRifstream ais(fname1);
+ for (i=0; i < MaxCnt; i++) {
+ ais >> line;
+ }
+ cout << "Testing use of ifstream 1 complete -----------------------" << endl;
+ cout << "Testing use of ifstream 2 ----------------------" << endl;
+ PRifstream *ais2 = new PRifstream(fname2);
+ char achar;
+ for (i=0; i < MaxCnt*10; i++) {
+ *ais2 >> achar;
+ }
+ delete ais2;
+ cout << "Testing use of ifstream 2 complete -------------" << endl;
}
#define STACKSIZE 1024*1024
int
main()
{
- PR_Init(PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 256);
- threadmain(const_cast<char *>("TestFile"));
- PRThread *thr1 = PR_CreateThread(PR_SYSTEM_THREAD,
- threadmain,
- const_cast<char *>("TestFile1"),
- PR_PRIORITY_NORMAL,
- PR_GLOBAL_THREAD,
- PR_JOINABLE_THREAD,
- STACKSIZE);
- PRThread *thr2 = PR_CreateThread(PR_SYSTEM_THREAD,
- threadmain,
- const_cast<char *>("TestFile2"),
- PR_PRIORITY_NORMAL,
- PR_GLOBAL_THREAD,
- PR_JOINABLE_THREAD,
- STACKSIZE);
- PRThread *thr3 = PR_CreateThread(PR_SYSTEM_THREAD,
- threadmain,
- const_cast<char *>("TestFile3"),
- PR_PRIORITY_NORMAL,
- PR_GLOBAL_THREAD,
- PR_JOINABLE_THREAD,
- STACKSIZE);
- PR_JoinThread(thr1);
- PR_JoinThread(thr2);
- PR_JoinThread(thr3);
- return 0;
+ PR_Init(PR_SYSTEM_THREAD, PR_PRIORITY_NORMAL, 256);
+ threadmain(const_cast<char *>("TestFile"));
+ PRThread *thr1 = PR_CreateThread(PR_SYSTEM_THREAD,
+ threadmain,
+ const_cast<char *>("TestFile1"),
+ PR_PRIORITY_NORMAL,
+ PR_GLOBAL_THREAD,
+ PR_JOINABLE_THREAD,
+ STACKSIZE);
+ PRThread *thr2 = PR_CreateThread(PR_SYSTEM_THREAD,
+ threadmain,
+ const_cast<char *>("TestFile2"),
+ PR_PRIORITY_NORMAL,
+ PR_GLOBAL_THREAD,
+ PR_JOINABLE_THREAD,
+ STACKSIZE);
+ PRThread *thr3 = PR_CreateThread(PR_SYSTEM_THREAD,
+ threadmain,
+ const_cast<char *>("TestFile3"),
+ PR_PRIORITY_NORMAL,
+ PR_GLOBAL_THREAD,
+ PR_JOINABLE_THREAD,
+ STACKSIZE);
+ PR_JoinThread(thr1);
+ PR_JoinThread(thr2);
+ PR_JoinThread(thr3);
+ return 0;
}
diff --git a/lib/tests/arena.c b/lib/tests/arena.c
index b74db893..2be2d5b4 100644
--- a/lib/tests/arena.c
+++ b/lib/tests/arena.c
@@ -33,7 +33,7 @@ PRIntn stressThreads = 4;
void DumpAll( void )
{
- return;
+ return;
}
/*
@@ -43,31 +43,31 @@ static void ArenaAllocate( void )
{
PLArenaPool ap;
void *ptr;
- PRInt32 i;
+ PRInt32 i;
PL_InitArenaPool( &ap, "AllocArena", 2048, sizeof(double));
PR_LOG( tLM, PR_LOG_DEBUG, ("AA, InitPool -- Pool: %p. first: %p, current: %p, size: %d",
- &ap, ap.first, ap.current, ap.arenasize ));
+ &ap, ap.first, ap.current, ap.arenasize ));
- for( i = 0; i < 150; i++ )
- {
- PL_ARENA_ALLOCATE( ptr, &ap, 512 );
+ for( i = 0; i < 150; i++ )
+ {
+ PL_ARENA_ALLOCATE( ptr, &ap, 512 );
PR_LOG( tLM, PR_LOG_DEBUG,("AA, after alloc -- Pool: %p. first: %p, current: %p, size: %d",
- &ap, ap.first, ap.current, ap.arenasize ));
- PR_LOG( tLM, PR_LOG_DEBUG,(
- "AA -- Pool: %p. alloc: %p ", &ap, ptr ));
- }
+ &ap, ap.first, ap.current, ap.arenasize ));
+ PR_LOG( tLM, PR_LOG_DEBUG,(
+ "AA -- Pool: %p. alloc: %p ", &ap, ptr ));
+ }
PL_FreeArenaPool( &ap );
- for( i = 0; i < 221; i++ )
- {
- PL_ARENA_ALLOCATE( ptr, &ap, 512 );
+ for( i = 0; i < 221; i++ )
+ {
+ PL_ARENA_ALLOCATE( ptr, &ap, 512 );
PR_LOG( tLM, PR_LOG_DEBUG,("AA, after alloc -- Pool: %p. first: %p, current: %p, size: %d",
- &ap, ap.first, ap.current, ap.arenasize ));
- PR_LOG( tLM, PR_LOG_DEBUG,(
- "AA -- Pool: %p. alloc: %p ", &ap, ptr ));
- }
+ &ap, ap.first, ap.current, ap.arenasize ));
+ PR_LOG( tLM, PR_LOG_DEBUG,(
+ "AA -- Pool: %p. alloc: %p ", &ap, ptr ));
+ }
PL_FreeArenaPool( &ap );
@@ -80,18 +80,18 @@ static void ArenaGrow( void )
{
PLArenaPool ap;
void *ptr;
- PRInt32 i;
+ PRInt32 i;
PL_InitArenaPool( &ap, "TheArena", 4096, sizeof(double));
PL_ARENA_ALLOCATE( ptr, &ap, 512 );
- PR_LOG( tLM, PR_LOG_DEBUG, ("Before growth -- Pool: %p. alloc: %p ", &ap, ptr ));
+ PR_LOG( tLM, PR_LOG_DEBUG, ("Before growth -- Pool: %p. alloc: %p ", &ap, ptr ));
- for( i = 0; i < 10; i++ )
- {
- PL_ARENA_GROW( ptr, &ap, 512, 7000 );
- PR_LOG( tLM, PR_LOG_DEBUG, ("After growth -- Pool: %p. alloc: %p ", &ap, ptr ));
- }
+ for( i = 0; i < 10; i++ )
+ {
+ PL_ARENA_GROW( ptr, &ap, 512, 7000 );
+ PR_LOG( tLM, PR_LOG_DEBUG, ("After growth -- Pool: %p. alloc: %p ", &ap, ptr ));
+ }
return;
@@ -111,63 +111,63 @@ static void MarkAndRelease( void )
PL_InitArenaPool( &ap, "TheArena", 4096, sizeof(double));
mark0 = PL_ARENA_MARK( &ap );
PR_LOG( tLM, PR_LOG_DEBUG,
- ("mark0. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p, m0: %p",
- &ap, ap.first.next, ap.current, ap.arenasize, ptr, mark0 ));
+ ("mark0. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p, m0: %p",
+ &ap, ap.first.next, ap.current, ap.arenasize, ptr, mark0 ));
- for( i = 0; i < 201; i++ )
- {
- PL_ARENA_ALLOCATE( ptr, &ap, 512 );
+ for( i = 0; i < 201; i++ )
+ {
+ PL_ARENA_ALLOCATE( ptr, &ap, 512 );
PR_LOG( tLM, PR_LOG_DEBUG,
- ("mr. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
- &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
- }
+ ("mr. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
+ &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
+ }
mark1 = PL_ARENA_MARK( &ap );
PR_LOG( tLM, PR_LOG_DEBUG,
- ("mark1. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p, m1: %p",
- &ap, ap.first.next, ap.current, ap.arenasize, ptr, mark1 ));
+ ("mark1. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p, m1: %p",
+ &ap, ap.first.next, ap.current, ap.arenasize, ptr, mark1 ));
- for( i = 0; i < 225; i++ )
- {
- PL_ARENA_ALLOCATE( ptr, &ap, 512 );
+ for( i = 0; i < 225; i++ )
+ {
+ PL_ARENA_ALLOCATE( ptr, &ap, 512 );
PR_LOG( tLM, PR_LOG_DEBUG,
- ("mr. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
- &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
- }
+ ("mr. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
+ &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
+ }
PL_ARENA_RELEASE( &ap, mark1 );
PR_LOG( tLM, PR_LOG_DEBUG,
- ("Release-1: %p -- Pool: %p. first: %p, current: %p, size: %d",
- mark1, &ap, ap.first, ap.current, ap.arenasize ));
+ ("Release-1: %p -- Pool: %p. first: %p, current: %p, size: %d",
+ mark1, &ap, ap.first, ap.current, ap.arenasize ));
- for( i = 0; i < 20; i++ )
- {
- PL_ARENA_ALLOCATE( ptr, &ap, 512 );
+ for( i = 0; i < 20; i++ )
+ {
+ PL_ARENA_ALLOCATE( ptr, &ap, 512 );
PR_LOG( tLM, PR_LOG_DEBUG,
- ("mr. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
- &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
- }
+ ("mr. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
+ &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
+ }
PL_ARENA_RELEASE( &ap, mark1 );
PR_LOG( tLM, PR_LOG_DEBUG,
- ("Release-1. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
- &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
+ ("Release-1. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
+ &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
PL_ARENA_RELEASE( &ap, mark0 );
PR_LOG( tLM, PR_LOG_DEBUG,
- ("Release-0. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
- &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
+ ("Release-0. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
+ &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
PL_FreeArenaPool( &ap );
PR_LOG( tLM, PR_LOG_DEBUG,
- ("Free. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
- &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
+ ("Free. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
+ &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
PL_FinishArenaPool( &ap );
PR_LOG( tLM, PR_LOG_DEBUG,
- ("Finish. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
- &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
+ ("Finish. ap: %p, ap.f: %p, ap.c: %p, ap.siz: %d, alloc: %p",
+ &ap, ap.first.next, ap.current, ap.arenasize, ptr ));
return;
} /* end MarkAndRelease() */
@@ -251,12 +251,12 @@ static void Stress( void )
{
PR_EnterMonitor(tMon);
tt = PR_CreateThread(PR_USER_THREAD,
- StressThread,
- NULL,
- PR_PRIORITY_NORMAL,
- PR_GLOBAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0);
+ StressThread,
+ NULL,
+ PR_PRIORITY_NORMAL,
+ PR_GLOBAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0);
threadCount++;
PR_ExitMonitor(tMon);
}
@@ -268,7 +268,7 @@ static void Stress( void )
PR_Wait(tMon, PR_INTERVAL_NO_TIMEOUT);
}
PR_ExitMonitor(tMon);
- PR_DestroyMonitor(tMon);
+ PR_DestroyMonitor(tMon);
return;
} /* end Stress() */
@@ -313,50 +313,52 @@ void Help( void )
PRIntn main(PRIntn argc, char *argv[])
{
PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "dhp:P:a:A:i:s:t:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ PLOptState *opt = PL_CreateOptState(argc, argv, "dhp:P:a:A:i:s:t:");
+ while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
- if (PL_OPT_BAD == os) continue;
+ if (PL_OPT_BAD == os) {
+ continue;
+ }
switch (opt->option)
{
- case 'a': /* arena Min size */
- arenaMin = atol( opt->value );
- break;
- case 'A': /* arena Max size */
- arenaMax = atol( opt->value );
- break;
- case 'p': /* pool Min size */
- poolMin = atol( opt->value );
- break;
- case 'P': /* pool Max size */
- poolMax = atol( opt->value );
- break;
- case 'i': /* Iterations in stress tests */
- stressIterations = atol( opt->value );
- break;
- case 's': /* storage to get per iteration */
- maxAlloc = atol( opt->value );
- break;
- case 't': /* Number of stress threads to create */
- stressThreads = atol( opt->value );
- break;
- case 'd': /* debug mode */
- debug_mode = 1;
- break;
- case 'h': /* help */
- default:
- Help();
+ case 'a': /* arena Min size */
+ arenaMin = atol( opt->value );
+ break;
+ case 'A': /* arena Max size */
+ arenaMax = atol( opt->value );
+ break;
+ case 'p': /* pool Min size */
+ poolMin = atol( opt->value );
+ break;
+ case 'P': /* pool Max size */
+ poolMax = atol( opt->value );
+ break;
+ case 'i': /* Iterations in stress tests */
+ stressIterations = atol( opt->value );
+ break;
+ case 's': /* storage to get per iteration */
+ maxAlloc = atol( opt->value );
+ break;
+ case 't': /* Number of stress threads to create */
+ stressThreads = atol( opt->value );
+ break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ case 'h': /* help */
+ default:
+ Help();
} /* end switch() */
} /* end while() */
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
srand( (unsigned)time( NULL ) ); /* seed random number generator */
tLM = PR_NewLogModule("testcase");
#if 0
- ArenaAllocate();
- ArenaGrow();
+ ArenaAllocate();
+ ArenaGrow();
#endif
MarkAndRelease();
diff --git a/lib/tests/base64t.c b/lib/tests/base64t.c
index 2a6e3eb2..adbbb813 100644
--- a/lib/tests/base64t.c
+++ b/lib/tests/base64t.c
@@ -163,1628 +163,2003 @@ PRBool test_003(void)
return PR_TRUE;
}
- static struct
- {
- const char *plaintext;
- const char *cyphertext;
- } array[] =
- {
- /* Cyphertexts generated with uuenview 0.5.13 */
- { " ", "IA==" },
- { ".", "Lg==" },
- { "/", "Lw==" },
- { "C", "Qw==" },
- { "H", "SA==" },
- { "S", "Uw==" },
- { "^", "Xg==" },
- { "a", "YQ==" },
- { "o", "bw==" },
- { "t", "dA==" },
-
- { "AB", "QUI=" },
- { "AH", "QUg=" },
- { "AQ", "QVE=" },
- { "BD", "QkQ=" },
- { "CR", "Q1I=" },
- { "CS", "Q1M=" },
- { "DB", "REI=" },
- { "DC", "REM=" },
- { "EK", "RUs=" },
- { "ET", "RVQ=" },
- { "IM", "SU0=" },
- { "JR", "SlI=" },
- { "LO", "TE8=" },
- { "LW", "TFc=" },
- { "ML", "TUw=" },
- { "SB", "U0I=" },
- { "TO", "VE8=" },
- { "VS", "VlM=" },
- { "WP", "V1A=" },
- /* legitimate two-letter words */
- { "ad", "YWQ=" },
- { "ah", "YWg=" },
- { "am", "YW0=" },
- { "an", "YW4=" },
- { "as", "YXM=" },
- { "at", "YXQ=" },
- { "ax", "YXg=" },
- { "be", "YmU=" },
- { "by", "Ynk=" },
- { "do", "ZG8=" },
- { "go", "Z28=" },
- { "he", "aGU=" },
- { "hi", "aGk=" },
- { "if", "aWY=" },
- { "in", "aW4=" },
- { "is", "aXM=" },
- { "it", "aXQ=" },
- { "me", "bWU=" },
- { "my", "bXk=" },
- { "no", "bm8=" },
- { "of", "b2Y=" },
- { "on", "b24=" },
- { "or", "b3I=" },
- { "ox", "b3g=" },
- { "so", "c28=" },
- { "to", "dG8=" },
- { "up", "dXA=" },
- { "us", "dXM=" },
- { "we", "d2U=" },
- /* all three-letter entries in /usr/dict/words */
- { "1st", "MXN0" },
- { "2nd", "Mm5k" },
- { "3rd", "M3Jk" },
- { "4th", "NHRo" },
- { "5th", "NXRo" },
- { "6th", "NnRo" },
- { "7th", "N3Ro" },
- { "8th", "OHRo" },
- { "9th", "OXRo" },
- { "AAA", "QUFB" },
- { "AAU", "QUFV" },
- { "ABA", "QUJB" },
- { "abc", "YWJj" },
- { "Abe", "QWJl" },
- { "Abo", "QWJv" },
- { "ace", "YWNl" },
- { "ACM", "QUNN" },
- { "ACS", "QUNT" },
- { "act", "YWN0" },
- { "Ada", "QWRh" },
- { "add", "YWRk" },
- { "ado", "YWRv" },
- { "aft", "YWZ0" },
- { "age", "YWdl" },
- { "ago", "YWdv" },
- { "aid", "YWlk" },
- { "ail", "YWls" },
- { "aim", "YWlt" },
- { "air", "YWly" },
- { "ala", "YWxh" },
- { "alb", "YWxi" },
- { "ale", "YWxl" },
- { "Ali", "QWxp" },
- { "all", "YWxs" },
- { "alp", "YWxw" },
- { "A&M", "QSZN" },
- { "AMA", "QU1B" },
- { "ami", "YW1p" },
- { "amp", "YW1w" },
- { "Amy", "QW15" },
- { "amy", "YW15" },
- { "ana", "YW5h" },
- { "and", "YW5k" },
- { "ani", "YW5p" },
- { "Ann", "QW5u" },
- { "ant", "YW50" },
- { "any", "YW55" },
- { "A&P", "QSZQ" },
- { "ape", "YXBl" },
- { "Apr", "QXBy" },
- { "APS", "QVBT" },
- { "apt", "YXB0" },
- { "arc", "YXJj" },
- { "are", "YXJl" },
- { "ark", "YXJr" },
- { "arm", "YXJt" },
- { "art", "YXJ0" },
- { "a's", "YSdz" },
- { "ash", "YXNo" },
- { "ask", "YXNr" },
- { "ass", "YXNz" },
- { "ate", "YXRl" },
- { "Aug", "QXVn" },
- { "auk", "YXVr" },
- { "Ave", "QXZl" },
- { "awe", "YXdl" },
- { "awl", "YXds" },
- { "awn", "YXdu" },
- { "axe", "YXhl" },
- { "aye", "YXll" },
- { "bad", "YmFk" },
- { "bag", "YmFn" },
- { "bah", "YmFo" },
- { "bam", "YmFt" },
- { "ban", "YmFu" },
- { "bar", "YmFy" },
- { "bat", "YmF0" },
- { "bay", "YmF5" },
- { "bed", "YmVk" },
- { "bee", "YmVl" },
- { "beg", "YmVn" },
- { "bel", "YmVs" },
- { "Ben", "QmVu" },
- { "bet", "YmV0" },
- { "bey", "YmV5" },
- { "bib", "Ymli" },
- { "bid", "Ymlk" },
- { "big", "Ymln" },
- { "bin", "Ymlu" },
- { "bit", "Yml0" },
- { "biz", "Yml6" },
- { "BMW", "Qk1X" },
- { "boa", "Ym9h" },
- { "bob", "Ym9i" },
- { "bog", "Ym9n" },
- { "bon", "Ym9u" },
- { "boo", "Ym9v" },
- { "bop", "Ym9w" },
- { "bow", "Ym93" },
- { "box", "Ym94" },
- { "boy", "Ym95" },
- { "b's", "Yidz" },
- { "BTL", "QlRM" },
- { "BTU", "QlRV" },
- { "bub", "YnVi" },
- { "bud", "YnVk" },
- { "bug", "YnVn" },
- { "bum", "YnVt" },
- { "bun", "YnVu" },
- { "bus", "YnVz" },
- { "but", "YnV0" },
- { "buy", "YnV5" },
- { "bye", "Ynll" },
- { "cab", "Y2Fi" },
- { "Cal", "Q2Fs" },
- { "cam", "Y2Ft" },
- { "can", "Y2Fu" },
- { "cap", "Y2Fw" },
- { "car", "Y2Fy" },
- { "cat", "Y2F0" },
- { "caw", "Y2F3" },
- { "CBS", "Q0JT" },
- { "CDC", "Q0RD" },
- { "CEQ", "Q0VR" },
- { "chi", "Y2hp" },
- { "CIA", "Q0lB" },
- { "cit", "Y2l0" },
- { "cod", "Y29k" },
- { "cog", "Y29n" },
- { "col", "Y29s" },
- { "con", "Y29u" },
- { "coo", "Y29v" },
- { "cop", "Y29w" },
- { "cos", "Y29z" },
- { "cot", "Y290" },
- { "cow", "Y293" },
- { "cox", "Y294" },
- { "coy", "Y295" },
- { "CPA", "Q1BB" },
- { "cpu", "Y3B1" },
- { "CRT", "Q1JU" },
- { "cry", "Y3J5" },
- { "c's", "Yydz" },
- { "cub", "Y3Vi" },
- { "cud", "Y3Vk" },
- { "cue", "Y3Vl" },
- { "cup", "Y3Vw" },
- { "cur", "Y3Vy" },
- { "cut", "Y3V0" },
- { "dab", "ZGFi" },
- { "dad", "ZGFk" },
- { "dam", "ZGFt" },
- { "Dan", "RGFu" },
- { "Dar", "RGFy" },
- { "day", "ZGF5" },
- { "Dec", "RGVj" },
- { "Dee", "RGVl" },
- { "Del", "RGVs" },
- { "den", "ZGVu" },
- { "Des", "RGVz" },
- { "dew", "ZGV3" },
- { "dey", "ZGV5" },
- { "did", "ZGlk" },
- { "die", "ZGll" },
- { "dig", "ZGln" },
- { "dim", "ZGlt" },
- { "din", "ZGlu" },
- { "dip", "ZGlw" },
- { "Dis", "RGlz" },
- { "DNA", "RE5B" },
- { "DOD", "RE9E" },
- { "doe", "ZG9l" },
- { "dog", "ZG9n" },
- { "don", "ZG9u" },
- { "dot", "ZG90" },
- { "Dow", "RG93" },
- { "dry", "ZHJ5" },
- { "d's", "ZCdz" },
- { "dub", "ZHVi" },
- { "dud", "ZHVk" },
- { "due", "ZHVl" },
- { "dug", "ZHVn" },
- { "dun", "ZHVu" },
- { "dye", "ZHll" },
- { "ear", "ZWFy" },
- { "eat", "ZWF0" },
- { "ebb", "ZWJi" },
- { "EDT", "RURU" },
- { "eel", "ZWVs" },
- { "eft", "ZWZ0" },
- { "e.g", "ZS5n" },
- { "egg", "ZWdn" },
- { "ego", "ZWdv" },
- { "eke", "ZWtl" },
- { "Eli", "RWxp" },
- { "elk", "ZWxr" },
- { "ell", "ZWxs" },
- { "elm", "ZWxt" },
- { "Ely", "RWx5" },
- { "end", "ZW5k" },
- { "Eng", "RW5n" },
- { "EPA", "RVBB" },
- { "era", "ZXJh" },
- { "ere", "ZXJl" },
- { "erg", "ZXJn" },
- { "err", "ZXJy" },
- { "e's", "ZSdz" },
- { "EST", "RVNU" },
- { "eta", "ZXRh" },
- { "etc", "ZXRj" },
- { "Eva", "RXZh" },
- { "eve", "ZXZl" },
- { "ewe", "ZXdl" },
- { "eye", "ZXll" },
- { "FAA", "RkFB" },
- { "fad", "ZmFk" },
- { "fag", "ZmFn" },
- { "fan", "ZmFu" },
- { "far", "ZmFy" },
- { "fat", "ZmF0" },
- { "fay", "ZmF5" },
- { "FBI", "RkJJ" },
- { "FCC", "RkND" },
- { "FDA", "RkRB" },
- { "Feb", "RmVi" },
- { "fed", "ZmVk" },
- { "fee", "ZmVl" },
- { "few", "ZmV3" },
- { "fib", "Zmli" },
- { "fig", "Zmln" },
- { "fin", "Zmlu" },
- { "fir", "Zmly" },
- { "fit", "Zml0" },
- { "fix", "Zml4" },
- { "Flo", "Rmxv" },
- { "flu", "Zmx1" },
- { "fly", "Zmx5" },
- { "FMC", "Rk1D" },
- { "fob", "Zm9i" },
- { "foe", "Zm9l" },
- { "fog", "Zm9n" },
- { "fop", "Zm9w" },
- { "for", "Zm9y" },
- { "fox", "Zm94" },
- { "FPC", "RlBD" },
- { "fro", "ZnJv" },
- { "fry", "ZnJ5" },
- { "f's", "Zidz" },
- { "FTC", "RlRD" },
- { "fum", "ZnVt" },
- { "fun", "ZnVu" },
- { "fur", "ZnVy" },
- { "gab", "Z2Fi" },
- { "gad", "Z2Fk" },
- { "gag", "Z2Fn" },
- { "gal", "Z2Fs" },
- { "gam", "Z2Ft" },
- { "GAO", "R0FP" },
- { "gap", "Z2Fw" },
- { "gar", "Z2Fy" },
- { "gas", "Z2Fz" },
- { "gay", "Z2F5" },
- { "gee", "Z2Vl" },
- { "gel", "Z2Vs" },
- { "gem", "Z2Vt" },
- { "get", "Z2V0" },
- { "gig", "Z2ln" },
- { "Gil", "R2ls" },
- { "gin", "Z2lu" },
- { "GMT", "R01U" },
- { "GNP", "R05Q" },
- { "gnu", "Z251" },
- { "Goa", "R29h" },
- { "gob", "Z29i" },
- { "god", "Z29k" },
- { "gog", "Z29n" },
- { "GOP", "R09Q" },
- { "got", "Z290" },
- { "GPO", "R1BP" },
- { "g's", "Zydz" },
- { "GSA", "R1NB" },
- { "gum", "Z3Vt" },
- { "gun", "Z3Vu" },
- { "Gus", "R3Vz" },
- { "gut", "Z3V0" },
- { "guy", "Z3V5" },
- { "gym", "Z3lt" },
- { "gyp", "Z3lw" },
- { "had", "aGFk" },
- { "Hal", "SGFs" },
- { "ham", "aGFt" },
- { "Han", "SGFu" },
- { "hap", "aGFw" },
- { "hat", "aGF0" },
- { "haw", "aGF3" },
- { "hay", "aGF5" },
- { "hem", "aGVt" },
- { "hen", "aGVu" },
- { "her", "aGVy" },
- { "hew", "aGV3" },
- { "hex", "aGV4" },
- { "hey", "aGV5" },
- { "hid", "aGlk" },
- { "him", "aGlt" },
- { "hip", "aGlw" },
- { "his", "aGlz" },
- { "hit", "aGl0" },
- { "hob", "aG9i" },
- { "hoc", "aG9j" },
- { "hoe", "aG9l" },
- { "hog", "aG9n" },
- { "hoi", "aG9p" },
- { "Hom", "SG9t" },
- { "hop", "aG9w" },
- { "hot", "aG90" },
- { "how", "aG93" },
- { "hoy", "aG95" },
- { "h's", "aCdz" },
- { "hub", "aHVi" },
- { "hue", "aHVl" },
- { "hug", "aHVn" },
- { "huh", "aHVo" },
- { "hum", "aHVt" },
- { "Hun", "SHVu" },
- { "hut", "aHV0" },
- { "Ian", "SWFu" },
- { "IBM", "SUJN" },
- { "Ibn", "SWJu" },
- { "ICC", "SUND" },
- { "ice", "aWNl" },
- { "icy", "aWN5" },
- { "I'd", "SSdk" },
- { "Ida", "SWRh" },
- { "i.e", "aS5l" },
- { "iii", "aWlp" },
- { "Ike", "SWtl" },
- { "ill", "aWxs" },
- { "I'm", "SSdt" },
- { "imp", "aW1w" },
- { "Inc", "SW5j" },
- { "ink", "aW5r" },
- { "inn", "aW5u" },
- { "ion", "aW9u" },
- { "Ira", "SXJh" },
- { "ire", "aXJl" },
- { "irk", "aXJr" },
- { "IRS", "SVJT" },
- { "i's", "aSdz" },
- { "Ito", "SXRv" },
- { "ITT", "SVRU" },
- { "ivy", "aXZ5" },
- { "jab", "amFi" },
- { "jag", "amFn" },
- { "jam", "amFt" },
- { "Jan", "SmFu" },
- { "jar", "amFy" },
- { "jaw", "amF3" },
- { "jay", "amF5" },
- { "Jed", "SmVk" },
- { "jet", "amV0" },
- { "Jew", "SmV3" },
- { "jig", "amln" },
- { "Jim", "Smlt" },
- { "job", "am9i" },
- { "Joe", "Sm9l" },
- { "jog", "am9n" },
- { "Jon", "Sm9u" },
- { "jot", "am90" },
- { "joy", "am95" },
- { "j's", "aidz" },
- { "jug", "anVn" },
- { "jut", "anV0" },
- { "Kay", "S2F5" },
- { "keg", "a2Vn" },
- { "ken", "a2Vu" },
- { "key", "a2V5" },
- { "kid", "a2lk" },
- { "Kim", "S2lt" },
- { "kin", "a2lu" },
- { "kit", "a2l0" },
- { "k's", "aydz" },
- { "lab", "bGFi" },
- { "lac", "bGFj" },
- { "lad", "bGFk" },
- { "lag", "bGFn" },
- { "lam", "bGFt" },
- { "Lao", "TGFv" },
- { "lap", "bGFw" },
- { "law", "bGF3" },
- { "lax", "bGF4" },
- { "lay", "bGF5" },
- { "lea", "bGVh" },
- { "led", "bGVk" },
- { "lee", "bGVl" },
- { "leg", "bGVn" },
- { "Len", "TGVu" },
- { "Leo", "TGVv" },
- { "let", "bGV0" },
- { "Lev", "TGV2" },
- { "Lew", "TGV3" },
- { "lew", "bGV3" },
- { "lid", "bGlk" },
- { "lie", "bGll" },
- { "lim", "bGlt" },
- { "Lin", "TGlu" },
- { "lip", "bGlw" },
- { "lit", "bGl0" },
- { "Liz", "TGl6" },
- { "lob", "bG9i" },
- { "log", "bG9n" },
- { "lop", "bG9w" },
- { "Los", "TG9z" },
- { "lot", "bG90" },
- { "Lou", "TG91" },
- { "low", "bG93" },
- { "loy", "bG95" },
- { "l's", "bCdz" },
- { "LSI", "TFNJ" },
- { "Ltd", "THRk" },
- { "LTV", "TFRW" },
- { "lug", "bHVn" },
- { "lux", "bHV4" },
- { "lye", "bHll" },
- { "Mac", "TWFj" },
- { "mad", "bWFk" },
- { "Mae", "TWFl" },
- { "man", "bWFu" },
- { "Mao", "TWFv" },
- { "map", "bWFw" },
- { "mar", "bWFy" },
- { "mat", "bWF0" },
- { "maw", "bWF3" },
- { "Max", "TWF4" },
- { "max", "bWF4" },
- { "may", "bWF5" },
- { "MBA", "TUJB" },
- { "Meg", "TWVn" },
- { "Mel", "TWVs" },
- { "men", "bWVu" },
- { "met", "bWV0" },
- { "mew", "bWV3" },
- { "mid", "bWlk" },
- { "mig", "bWln" },
- { "min", "bWlu" },
- { "MIT", "TUlU" },
- { "mix", "bWl4" },
- { "mob", "bW9i" },
- { "Moe", "TW9l" },
- { "moo", "bW9v" },
- { "mop", "bW9w" },
- { "mot", "bW90" },
- { "mow", "bW93" },
- { "MPH", "TVBI" },
- { "Mrs", "TXJz" },
- { "m's", "bSdz" },
- { "mud", "bXVk" },
- { "mug", "bXVn" },
- { "mum", "bXVt" },
- { "nab", "bmFi" },
- { "nag", "bmFn" },
- { "Nan", "TmFu" },
- { "nap", "bmFw" },
- { "Nat", "TmF0" },
- { "nay", "bmF5" },
- { "NBC", "TkJD" },
- { "NBS", "TkJT" },
- { "NCO", "TkNP" },
- { "NCR", "TkNS" },
- { "Ned", "TmVk" },
- { "nee", "bmVl" },
- { "net", "bmV0" },
- { "new", "bmV3" },
- { "nib", "bmli" },
- { "NIH", "TklI" },
- { "nil", "bmls" },
- { "nip", "bmlw" },
- { "nit", "bml0" },
- { "NNE", "Tk5F" },
- { "NNW", "Tk5X" },
- { "nob", "bm9i" },
- { "nod", "bm9k" },
- { "non", "bm9u" },
- { "nor", "bm9y" },
- { "not", "bm90" },
- { "Nov", "Tm92" },
- { "now", "bm93" },
- { "NRC", "TlJD" },
- { "n's", "bidz" },
- { "NSF", "TlNG" },
- { "nun", "bnVu" },
- { "nut", "bnV0" },
- { "NYC", "TllD" },
- { "NYU", "TllV" },
- { "oaf", "b2Fm" },
- { "oak", "b2Fr" },
- { "oar", "b2Fy" },
- { "oat", "b2F0" },
- { "Oct", "T2N0" },
- { "odd", "b2Rk" },
- { "ode", "b2Rl" },
- { "off", "b2Zm" },
- { "oft", "b2Z0" },
- { "ohm", "b2ht" },
- { "oil", "b2ls" },
- { "old", "b2xk" },
- { "one", "b25l" },
- { "opt", "b3B0" },
- { "orb", "b3Ji" },
- { "ore", "b3Jl" },
- { "Orr", "T3Jy" },
- { "o's", "bydz" },
- { "Ott", "T3R0" },
- { "our", "b3Vy" },
- { "out", "b3V0" },
- { "ova", "b3Zh" },
- { "owe", "b3dl" },
- { "owl", "b3ds" },
- { "own", "b3du" },
- { "pad", "cGFk" },
- { "pal", "cGFs" },
- { "Pam", "UGFt" },
- { "pan", "cGFu" },
- { "pap", "cGFw" },
- { "par", "cGFy" },
- { "pat", "cGF0" },
- { "paw", "cGF3" },
- { "pax", "cGF4" },
- { "pay", "cGF5" },
- { "Paz", "UGF6" },
- { "PBS", "UEJT" },
- { "PDP", "UERQ" },
- { "pea", "cGVh" },
- { "pee", "cGVl" },
- { "peg", "cGVn" },
- { "pen", "cGVu" },
- { "pep", "cGVw" },
- { "per", "cGVy" },
- { "pet", "cGV0" },
- { "pew", "cGV3" },
- { "PhD", "UGhE" },
- { "phi", "cGhp" },
- { "pie", "cGll" },
- { "pig", "cGln" },
- { "pin", "cGlu" },
- { "pip", "cGlw" },
- { "pit", "cGl0" },
- { "ply", "cGx5" },
- { "pod", "cG9k" },
- { "Poe", "UG9l" },
- { "poi", "cG9p" },
- { "pol", "cG9s" },
- { "pop", "cG9w" },
- { "pot", "cG90" },
- { "pow", "cG93" },
- { "ppm", "cHBt" },
- { "pro", "cHJv" },
- { "pry", "cHJ5" },
- { "p's", "cCdz" },
- { "psi", "cHNp" },
- { "PTA", "UFRB" },
- { "pub", "cHVi" },
- { "PUC", "UFVD" },
- { "pug", "cHVn" },
- { "pun", "cHVu" },
- { "pup", "cHVw" },
- { "pus", "cHVz" },
- { "put", "cHV0" },
- { "PVC", "UFZD" },
- { "QED", "UUVE" },
- { "q's", "cSdz" },
- { "qua", "cXVh" },
- { "quo", "cXVv" },
- { "Rae", "UmFl" },
- { "rag", "cmFn" },
- { "raj", "cmFq" },
- { "ram", "cmFt" },
- { "ran", "cmFu" },
- { "rap", "cmFw" },
- { "rat", "cmF0" },
- { "raw", "cmF3" },
- { "ray", "cmF5" },
- { "RCA", "UkNB" },
- { "R&D", "UiZE" },
- { "reb", "cmVi" },
- { "red", "cmVk" },
- { "rep", "cmVw" },
- { "ret", "cmV0" },
- { "rev", "cmV2" },
- { "Rex", "UmV4" },
- { "rho", "cmhv" },
- { "rib", "cmli" },
- { "rid", "cmlk" },
- { "rig", "cmln" },
- { "rim", "cmlt" },
- { "Rio", "Umlv" },
- { "rip", "cmlw" },
- { "RNA", "Uk5B" },
- { "rob", "cm9i" },
- { "rod", "cm9k" },
- { "roe", "cm9l" },
- { "Ron", "Um9u" },
- { "rot", "cm90" },
- { "row", "cm93" },
- { "Roy", "Um95" },
- { "RPM", "UlBN" },
- { "r's", "cidz" },
- { "rub", "cnVi" },
- { "rue", "cnVl" },
- { "rug", "cnVn" },
- { "rum", "cnVt" },
- { "run", "cnVu" },
- { "rut", "cnV0" },
- { "rye", "cnll" },
- { "sac", "c2Fj" },
- { "sad", "c2Fk" },
- { "sag", "c2Fn" },
- { "Sal", "U2Fs" },
- { "Sam", "U2Ft" },
- { "San", "U2Fu" },
- { "Sao", "U2Fv" },
- { "sap", "c2Fw" },
- { "sat", "c2F0" },
- { "saw", "c2F3" },
- { "sax", "c2F4" },
- { "say", "c2F5" },
- { "Sci", "U2Np" },
- { "SCM", "U0NN" },
- { "sea", "c2Vh" },
- { "sec", "c2Vj" },
- { "see", "c2Vl" },
- { "sen", "c2Vu" },
- { "seq", "c2Vx" },
- { "set", "c2V0" },
- { "sew", "c2V3" },
- { "sex", "c2V4" },
- { "she", "c2hl" },
- { "Shu", "U2h1" },
- { "shy", "c2h5" },
- { "sib", "c2li" },
- { "sic", "c2lj" },
- { "sin", "c2lu" },
- { "sip", "c2lw" },
- { "sir", "c2ly" },
- { "sis", "c2lz" },
- { "sit", "c2l0" },
- { "six", "c2l4" },
- { "ski", "c2tp" },
- { "sky", "c2t5" },
- { "sly", "c2x5" },
- { "sob", "c29i" },
- { "Soc", "U29j" },
- { "sod", "c29k" },
- { "Sol", "U29s" },
- { "son", "c29u" },
- { "sop", "c29w" },
- { "sou", "c291" },
- { "sow", "c293" },
- { "soy", "c295" },
- { "spa", "c3Bh" },
- { "spy", "c3B5" },
- { "Sri", "U3Jp" },
- { "s's", "cydz" },
- { "SSE", "U1NF" },
- { "SST", "U1NU" },
- { "SSW", "U1NX" },
- { "Stu", "U3R1" },
- { "sub", "c3Vi" },
- { "sud", "c3Vk" },
- { "sue", "c3Vl" },
- { "sum", "c3Vt" },
- { "sun", "c3Vu" },
- { "sup", "c3Vw" },
- { "Sus", "U3Vz" },
- { "tab", "dGFi" },
- { "tad", "dGFk" },
- { "tag", "dGFn" },
- { "tam", "dGFt" },
- { "tan", "dGFu" },
- { "tao", "dGFv" },
- { "tap", "dGFw" },
- { "tar", "dGFy" },
- { "tat", "dGF0" },
- { "tau", "dGF1" },
- { "tax", "dGF4" },
- { "tea", "dGVh" },
- { "Ted", "VGVk" },
- { "ted", "dGVk" },
- { "tee", "dGVl" },
- { "Tel", "VGVs" },
- { "ten", "dGVu" },
- { "the", "dGhl" },
- { "thy", "dGh5" },
- { "tic", "dGlj" },
- { "tid", "dGlk" },
- { "tie", "dGll" },
- { "til", "dGls" },
- { "Tim", "VGlt" },
- { "tin", "dGlu" },
- { "tip", "dGlw" },
- { "tit", "dGl0" },
- { "TNT", "VE5U" },
- { "toe", "dG9l" },
- { "tog", "dG9n" },
- { "Tom", "VG9t" },
- { "ton", "dG9u" },
- { "too", "dG9v" },
- { "top", "dG9w" },
- { "tor", "dG9y" },
- { "tot", "dG90" },
- { "tow", "dG93" },
- { "toy", "dG95" },
- { "TRW", "VFJX" },
- { "try", "dHJ5" },
- { "t's", "dCdz" },
- { "TTL", "VFRM" },
- { "TTY", "VFRZ" },
- { "tub", "dHVi" },
- { "tug", "dHVn" },
- { "tum", "dHVt" },
- { "tun", "dHVu" },
- { "TVA", "VFZB" },
- { "TWA", "VFdB" },
- { "two", "dHdv" },
- { "TWX", "VFdY" },
- { "ugh", "dWdo" },
- { "UHF", "VUhG" },
- { "Uri", "VXJp" },
- { "urn", "dXJu" },
- { "U.S", "VS5T" },
- { "u's", "dSdz" },
- { "USA", "VVNB" },
- { "USC", "VVND" },
- { "use", "dXNl" },
- { "USN", "VVNO" },
- { "van", "dmFu" },
- { "vat", "dmF0" },
- { "vee", "dmVl" },
- { "vet", "dmV0" },
- { "vex", "dmV4" },
- { "VHF", "VkhG" },
- { "via", "dmlh" },
- { "vie", "dmll" },
- { "vii", "dmlp" },
- { "vis", "dmlz" },
- { "viz", "dml6" },
- { "von", "dm9u" },
- { "vow", "dm93" },
- { "v's", "didz" },
- { "WAC", "V0FD" },
- { "wad", "d2Fk" },
- { "wag", "d2Fn" },
- { "wah", "d2Fo" },
- { "wan", "d2Fu" },
- { "war", "d2Fy" },
- { "was", "d2Fz" },
- { "wax", "d2F4" },
- { "way", "d2F5" },
- { "web", "d2Vi" },
- { "wed", "d2Vk" },
- { "wee", "d2Vl" },
- { "Wei", "V2Vp" },
- { "wet", "d2V0" },
- { "who", "d2hv" },
- { "why", "d2h5" },
- { "wig", "d2ln" },
- { "win", "d2lu" },
- { "wit", "d2l0" },
- { "woe", "d29l" },
- { "wok", "d29r" },
- { "won", "d29u" },
- { "woo", "d29v" },
- { "wop", "d29w" },
- { "wow", "d293" },
- { "wry", "d3J5" },
- { "w's", "dydz" },
- { "x's", "eCdz" },
- { "yah", "eWFo" },
- { "yak", "eWFr" },
- { "yam", "eWFt" },
- { "yap", "eWFw" },
- { "yaw", "eWF3" },
- { "yea", "eWVh" },
- { "yen", "eWVu" },
- { "yet", "eWV0" },
- { "yin", "eWlu" },
- { "yip", "eWlw" },
- { "yon", "eW9u" },
- { "you", "eW91" },
- { "yow", "eW93" },
- { "y's", "eSdz" },
- { "yuh", "eXVo" },
- { "zag", "emFn" },
- { "Zan", "WmFu" },
- { "zap", "emFw" },
- { "Zen", "WmVu" },
- { "zig", "emln" },
- { "zip", "emlw" },
- { "Zoe", "Wm9l" },
- { "zoo", "em9v" },
- { "z's", "eidz" },
- /* the false rumors file */
- { "\"So when I die, the first thing I will see in heaven is a score list?\"",
- "IlNvIHdoZW4gSSBkaWUsIHRoZSBmaXJzdCB0aGluZyBJIHdpbGwgc2VlIGluIGhlYXZlbiBpcyBhIHNjb3JlIGxpc3Q/Ig==" },
- { "1st Law of Hacking: leaving is much more difficult than entering.",
- "MXN0IExhdyBvZiBIYWNraW5nOiBsZWF2aW5nIGlzIG11Y2ggbW9yZSBkaWZmaWN1bHQgdGhhbiBlbnRlcmluZy4=" },
- { "2nd Law of Hacking: first in, first out.",
- "Mm5kIExhdyBvZiBIYWNraW5nOiBmaXJzdCBpbiwgZmlyc3Qgb3V0Lg==" },
- { "3rd Law of Hacking: the last blow counts most.",
- "M3JkIExhdyBvZiBIYWNraW5nOiB0aGUgbGFzdCBibG93IGNvdW50cyBtb3N0Lg==" },
- { "4th Law of Hacking: you will find the exit at the entrance.",
- "NHRoIExhdyBvZiBIYWNraW5nOiB5b3Ugd2lsbCBmaW5kIHRoZSBleGl0IGF0IHRoZSBlbnRyYW5jZS4=" },
- { "A chameleon imitating a mail daemon often delivers scrolls of fire.",
- "QSBjaGFtZWxlb24gaW1pdGF0aW5nIGEgbWFpbCBkYWVtb24gb2Z0ZW4gZGVsaXZlcnMgc2Nyb2xscyBvZiBmaXJlLg==" },
- { "A cockatrice corpse is guaranteed to be untainted!",
- "QSBjb2NrYXRyaWNlIGNvcnBzZSBpcyBndWFyYW50ZWVkIHRvIGJlIHVudGFpbnRlZCE=" },
- { "A dead cockatrice is just a dead lizard.",
- "QSBkZWFkIGNvY2thdHJpY2UgaXMganVzdCBhIGRlYWQgbGl6YXJkLg==" },
- { "A dragon is just a snake that ate a scroll of fire.",
- "QSBkcmFnb24gaXMganVzdCBhIHNuYWtlIHRoYXQgYXRlIGEgc2Nyb2xsIG9mIGZpcmUu" },
- { "A fading corridor enlightens your insight.",
- "QSBmYWRpbmcgY29ycmlkb3IgZW5saWdodGVucyB5b3VyIGluc2lnaHQu" },
- { "A glowing potion is too hot to drink.",
- "QSBnbG93aW5nIHBvdGlvbiBpcyB0b28gaG90IHRvIGRyaW5rLg==" },
- { "A good amulet may protect you against guards.",
- "QSBnb29kIGFtdWxldCBtYXkgcHJvdGVjdCB5b3UgYWdhaW5zdCBndWFyZHMu" },
- { "A lizard corpse is a good thing to turn undead.",
- "QSBsaXphcmQgY29ycHNlIGlzIGEgZ29vZCB0aGluZyB0byB0dXJuIHVuZGVhZC4=" },
- { "A long worm can be defined recursively. So how should you attack it?",
- "QSBsb25nIHdvcm0gY2FuIGJlIGRlZmluZWQgcmVjdXJzaXZlbHkuIFNvIGhvdyBzaG91bGQgeW91IGF0dGFjayBpdD8=" },
- { "A monstrous mind is a toy forever.",
- "QSBtb25zdHJvdXMgbWluZCBpcyBhIHRveSBmb3JldmVyLg==" },
- { "A nymph will be very pleased if you call her by her real name: Lorelei.",
- "QSBueW1waCB3aWxsIGJlIHZlcnkgcGxlYXNlZCBpZiB5b3UgY2FsbCBoZXIgYnkgaGVyIHJlYWwgbmFtZTogTG9yZWxlaS4=" },
- { "A ring of dungeon master control is a great find.",
- "QSByaW5nIG9mIGR1bmdlb24gbWFzdGVyIGNvbnRyb2wgaXMgYSBncmVhdCBmaW5kLg==" },
- { "A ring of extra ring finger is useless if not enchanted.",
- "QSByaW5nIG9mIGV4dHJhIHJpbmcgZmluZ2VyIGlzIHVzZWxlc3MgaWYgbm90IGVuY2hhbnRlZC4=" },
- { "A rope may form a trail in a maze.",
- "QSByb3BlIG1heSBmb3JtIGEgdHJhaWwgaW4gYSBtYXplLg==" },
- { "A staff may recharge if you drop it for awhile.",
- "QSBzdGFmZiBtYXkgcmVjaGFyZ2UgaWYgeW91IGRyb3AgaXQgZm9yIGF3aGlsZS4=" },
- { "A visit to the Zoo is very educational; you meet interesting animals.",
- "QSB2aXNpdCB0byB0aGUgWm9vIGlzIHZlcnkgZWR1Y2F0aW9uYWw7IHlvdSBtZWV0IGludGVyZXN0aW5nIGFuaW1hbHMu" },
- { "A wand of deaf is a more dangerous weapon than a wand of sheep.",
- "QSB3YW5kIG9mIGRlYWYgaXMgYSBtb3JlIGRhbmdlcm91cyB3ZWFwb24gdGhhbiBhIHdhbmQgb2Ygc2hlZXAu" },
- { "A wand of vibration might bring the whole cave crashing about your ears.",
- "QSB3YW5kIG9mIHZpYnJhdGlvbiBtaWdodCBicmluZyB0aGUgd2hvbGUgY2F2ZSBjcmFzaGluZyBhYm91dCB5b3VyIGVhcnMu" },
- { "A winner never quits. A quitter never wins.",
- "QSB3aW5uZXIgbmV2ZXIgcXVpdHMuIEEgcXVpdHRlciBuZXZlciB3aW5zLg==" },
- { "A wish? Okay, make me a fortune cookie!",
- "QSB3aXNoPyBPa2F5LCBtYWtlIG1lIGEgZm9ydHVuZSBjb29raWUh" },
- { "Afraid of mimics? Try to wear a ring of true seeing.",
- "QWZyYWlkIG9mIG1pbWljcz8gVHJ5IHRvIHdlYXIgYSByaW5nIG9mIHRydWUgc2VlaW5nLg==" },
- { "All monsters are created evil, but some are more evil than others.",
- "QWxsIG1vbnN0ZXJzIGFyZSBjcmVhdGVkIGV2aWwsIGJ1dCBzb21lIGFyZSBtb3JlIGV2aWwgdGhhbiBvdGhlcnMu" },
- { "Always attack a floating eye from behind!",
- "QWx3YXlzIGF0dGFjayBhIGZsb2F0aW5nIGV5ZSBmcm9tIGJlaGluZCE=" },
- { "An elven cloak is always the height of fashion.",
- "QW4gZWx2ZW4gY2xvYWsgaXMgYWx3YXlzIHRoZSBoZWlnaHQgb2YgZmFzaGlvbi4=" },
- { "Any small object that is accidentally dropped will hide under a larger object.",
- "QW55IHNtYWxsIG9iamVjdCB0aGF0IGlzIGFjY2lkZW50YWxseSBkcm9wcGVkIHdpbGwgaGlkZSB1bmRlciBhIGxhcmdlciBvYmplY3Qu" },
- { "Balrogs do not appear above level 20.",
- "QmFscm9ncyBkbyBub3QgYXBwZWFyIGFib3ZlIGxldmVsIDIwLg==" },
- { "Banana peels work especially well against Keystone Kops.",
- "QmFuYW5hIHBlZWxzIHdvcmsgZXNwZWNpYWxseSB3ZWxsIGFnYWluc3QgS2V5c3RvbmUgS29wcy4=" },
- { "Be careful when eating bananas. Monsters might slip on the peels.",
- "QmUgY2FyZWZ1bCB3aGVuIGVhdGluZyBiYW5hbmFzLiBNb25zdGVycyBtaWdodCBzbGlwIG9uIHRoZSBwZWVscy4=" },
- { "Better leave the dungeon; otherwise you might get hurt badly.",
- "QmV0dGVyIGxlYXZlIHRoZSBkdW5nZW9uOyBvdGhlcndpc2UgeW91IG1pZ2h0IGdldCBodXJ0IGJhZGx5Lg==" },
- { "Beware of the potion of nitroglycerin -- it's not for the weak of heart.",
- "QmV3YXJlIG9mIHRoZSBwb3Rpb24gb2Ygbml0cm9nbHljZXJpbiAtLSBpdCdzIG5vdCBmb3IgdGhlIHdlYWsgb2YgaGVhcnQu" },
- { "Beware: there's always a chance that your wand explodes as you try to zap it!",
- "QmV3YXJlOiB0aGVyZSdzIGFsd2F5cyBhIGNoYW5jZSB0aGF0IHlvdXIgd2FuZCBleHBsb2RlcyBhcyB5b3UgdHJ5IHRvIHphcCBpdCE=" },
- { "Beyond the 23rd level lies a happy retirement in a room of your own.",
- "QmV5b25kIHRoZSAyM3JkIGxldmVsIGxpZXMgYSBoYXBweSByZXRpcmVtZW50IGluIGEgcm9vbSBvZiB5b3VyIG93bi4=" },
- { "Changing your suit without dropping your sword? You must be kidding!",
- "Q2hhbmdpbmcgeW91ciBzdWl0IHdpdGhvdXQgZHJvcHBpbmcgeW91ciBzd29yZD8gWW91IG11c3QgYmUga2lkZGluZyE=" },
- { "Cockatrices might turn themselves to stone faced with a mirror.",
- "Q29ja2F0cmljZXMgbWlnaHQgdHVybiB0aGVtc2VsdmVzIHRvIHN0b25lIGZhY2VkIHdpdGggYSBtaXJyb3Iu" },
- { "Consumption of home-made food is strictly forbidden in this dungeon.",
- "Q29uc3VtcHRpb24gb2YgaG9tZS1tYWRlIGZvb2QgaXMgc3RyaWN0bHkgZm9yYmlkZGVuIGluIHRoaXMgZHVuZ2Vvbi4=" },
- { "Dark room? Your chance to develop your photographs!",
- "RGFyayByb29tPyBZb3VyIGNoYW5jZSB0byBkZXZlbG9wIHlvdXIgcGhvdG9ncmFwaHMh" },
- { "Dark rooms are not *completely* dark: just wait and let your eyes adjust...",
- "RGFyayByb29tcyBhcmUgbm90ICpjb21wbGV0ZWx5KiBkYXJrOiBqdXN0IHdhaXQgYW5kIGxldCB5b3VyIGV5ZXMgYWRqdXN0Li4u" },
- { "David London sez, \"Hey guys, *WIELD* a lizard corpse against a cockatrice!\"",
- "RGF2aWQgTG9uZG9uIHNleiwgIkhleSBndXlzLCAqV0lFTEQqIGEgbGl6YXJkIGNvcnBzZSBhZ2FpbnN0IGEgY29ja2F0cmljZSEi" },
- { "Death is just life's way of telling you you've been fired.",
- "RGVhdGggaXMganVzdCBsaWZlJ3Mgd2F5IG9mIHRlbGxpbmcgeW91IHlvdSd2ZSBiZWVuIGZpcmVkLg==" },
- { "Demi-gods don't need any help from the gods.",
- "RGVtaS1nb2RzIGRvbid0IG5lZWQgYW55IGhlbHAgZnJvbSB0aGUgZ29kcy4=" },
- { "Demons *HATE* Priests and Priestesses.",
- "RGVtb25zICpIQVRFKiBQcmllc3RzIGFuZCBQcmllc3Rlc3Nlcy4=" },
- { "Didn't you forget to pay?",
- "RGlkbid0IHlvdSBmb3JnZXQgdG8gcGF5Pw==" },
- { "Didn't your mother tell you not to eat food off the floor?",
- "RGlkbid0IHlvdXIgbW90aGVyIHRlbGwgeW91IG5vdCB0byBlYXQgZm9vZCBvZmYgdGhlIGZsb29yPw==" },
- { "Direct a direct hit on your direct opponent, directing in the right direction.",
- "RGlyZWN0IGEgZGlyZWN0IGhpdCBvbiB5b3VyIGRpcmVjdCBvcHBvbmVudCwgZGlyZWN0aW5nIGluIHRoZSByaWdodCBkaXJlY3Rpb24u" },
- { "Do you want to make more money? Sure, we all do! Join the Fort Ludios guard!",
- "RG8geW91IHdhbnQgdG8gbWFrZSBtb3JlIG1vbmV5PyBTdXJlLCB3ZSBhbGwgZG8hIEpvaW4gdGhlIEZvcnQgTHVkaW9zIGd1YXJkIQ==" },
- { "Don't eat too much: you might start hiccoughing!",
- "RG9uJ3QgZWF0IHRvbyBtdWNoOiB5b3UgbWlnaHQgc3RhcnQgaGljY291Z2hpbmch" },
- { "Don't play hack at your work; your boss might hit you!",
- "RG9uJ3QgcGxheSBoYWNrIGF0IHlvdXIgd29yazsgeW91ciBib3NzIG1pZ2h0IGhpdCB5b3Uh" },
- { "Don't tell a soul you found a secret door, otherwise it isn't a secret anymore.",
- "RG9uJ3QgdGVsbCBhIHNvdWwgeW91IGZvdW5kIGEgc2VjcmV0IGRvb3IsIG90aGVyd2lzZSBpdCBpc24ndCBhIHNlY3JldCBhbnltb3JlLg==" },
- { "Drinking potions of booze may land you in jail if you are under 21.",
- "RHJpbmtpbmcgcG90aW9ucyBvZiBib296ZSBtYXkgbGFuZCB5b3UgaW4gamFpbCBpZiB5b3UgYXJlIHVuZGVyIDIxLg==" },
- { "Drop your vanity and get rid of your jewels! Pickpockets about!",
- "RHJvcCB5b3VyIHZhbml0eSBhbmQgZ2V0IHJpZCBvZiB5b3VyIGpld2VscyEgUGlja3BvY2tldHMgYWJvdXQh" },
- { "Eat 10 cloves of garlic and keep all humans at a two-square distance.",
- "RWF0IDEwIGNsb3ZlcyBvZiBnYXJsaWMgYW5kIGtlZXAgYWxsIGh1bWFucyBhdCBhIHR3by1zcXVhcmUgZGlzdGFuY2Uu" },
- { "Eels hide under mud. Use a unicorn to clear the water and make them visible.",
- "RWVscyBoaWRlIHVuZGVyIG11ZC4gVXNlIGEgdW5pY29ybiB0byBjbGVhciB0aGUgd2F0ZXIgYW5kIG1ha2UgdGhlbSB2aXNpYmxlLg==" },
- { "Engrave your wishes with a wand of wishing.",
- "RW5ncmF2ZSB5b3VyIHdpc2hlcyB3aXRoIGEgd2FuZCBvZiB3aXNoaW5nLg==" },
- { "Eventually you will come to admire the swift elegance of a retreating nymph.",
- "RXZlbnR1YWxseSB5b3Ugd2lsbCBjb21lIHRvIGFkbWlyZSB0aGUgc3dpZnQgZWxlZ2FuY2Ugb2YgYSByZXRyZWF0aW5nIG55bXBoLg==" },
- { "Ever heard hissing outside? I *knew* you hadn't!",
- "RXZlciBoZWFyZCBoaXNzaW5nIG91dHNpZGU/IEkgKmtuZXcqIHlvdSBoYWRuJ3Qh" },
- { "Ever lifted a dragon corpse?",
- "RXZlciBsaWZ0ZWQgYSBkcmFnb24gY29ycHNlPw==" },
- { "Ever seen a leocrotta dancing the tengu?",
- "RXZlciBzZWVuIGEgbGVvY3JvdHRhIGRhbmNpbmcgdGhlIHRlbmd1Pw==" },
- { "Ever seen your weapon glow plaid?",
- "RXZlciBzZWVuIHlvdXIgd2VhcG9uIGdsb3cgcGxhaWQ/" },
- { "Ever tamed a shopkeeper?",
- "RXZlciB0YW1lZCBhIHNob3BrZWVwZXI/" },
- { "Ever tried digging through a Vault Guard?",
- "RXZlciB0cmllZCBkaWdnaW5nIHRocm91Z2ggYSBWYXVsdCBHdWFyZD8=" },
- { "Ever tried enchanting a rope?",
- "RXZlciB0cmllZCBlbmNoYW50aW5nIGEgcm9wZT8=" },
- { "Floating eyes can't stand Hawaiian shirts.",
- "RmxvYXRpbmcgZXllcyBjYW4ndCBzdGFuZCBIYXdhaWlhbiBzaGlydHMu" },
- { "For any remedy there is a misery.",
- "Rm9yIGFueSByZW1lZHkgdGhlcmUgaXMgYSBtaXNlcnku" },
- { "Giant bats turn into giant vampires.",
- "R2lhbnQgYmF0cyB0dXJuIGludG8gZ2lhbnQgdmFtcGlyZXMu" },
- { "Good day for overcoming obstacles. Try a steeplechase.",
- "R29vZCBkYXkgZm9yIG92ZXJjb21pbmcgb2JzdGFjbGVzLiBUcnkgYSBzdGVlcGxlY2hhc2Uu" },
- { "Half Moon tonight. (At least it's better than no Moon at all.)",
- "SGFsZiBNb29uIHRvbmlnaHQuIChBdCBsZWFzdCBpdCdzIGJldHRlciB0aGFuIG5vIE1vb24gYXQgYWxsLik=" },
- { "Help! I'm being held prisoner in a fortune cookie factory!",
- "SGVscCEgSSdtIGJlaW5nIGhlbGQgcHJpc29uZXIgaW4gYSBmb3J0dW5lIGNvb2tpZSBmYWN0b3J5IQ==" },
- { "Housecats have nine lives, kittens only one.",
- "SG91c2VjYXRzIGhhdmUgbmluZSBsaXZlcywga2l0dGVucyBvbmx5IG9uZS4=" },
- { "How long can you tread water?",
- "SG93IGxvbmcgY2FuIHlvdSB0cmVhZCB3YXRlcj8=" },
- { "Hungry? There is an abundance of food on the next level.",
- "SHVuZ3J5PyBUaGVyZSBpcyBhbiBhYnVuZGFuY2Ugb2YgZm9vZCBvbiB0aGUgbmV4dCBsZXZlbC4=" },
- { "I guess you've never hit a mail daemon with the Amulet of Yendor...",
- "SSBndWVzcyB5b3UndmUgbmV2ZXIgaGl0IGEgbWFpbCBkYWVtb24gd2l0aCB0aGUgQW11bGV0IG9mIFllbmRvci4uLg==" },
- { "If you are the shopkeeper, you can take things for free.",
- "SWYgeW91IGFyZSB0aGUgc2hvcGtlZXBlciwgeW91IGNhbiB0YWtlIHRoaW5ncyBmb3IgZnJlZS4=" },
- { "If you can't learn to do it well, learn to enjoy doing it badly.",
- "SWYgeW91IGNhbid0IGxlYXJuIHRvIGRvIGl0IHdlbGwsIGxlYXJuIHRvIGVuam95IGRvaW5nIGl0IGJhZGx5Lg==" },
- { "If you thought the Wizard was bad, just wait till you meet the Warlord!",
- "SWYgeW91IHRob3VnaHQgdGhlIFdpemFyZCB3YXMgYmFkLCBqdXN0IHdhaXQgdGlsbCB5b3UgbWVldCB0aGUgV2FybG9yZCE=" },
- { "If you turn blind, don't expect your dog to be turned into a seeing-eye dog.",
- "SWYgeW91IHR1cm4gYmxpbmQsIGRvbid0IGV4cGVjdCB5b3VyIGRvZyB0byBiZSB0dXJuZWQgaW50byBhIHNlZWluZy1leWUgZG9nLg==" },
- { "If you want to feel great, you must eat something real big.",
- "SWYgeW91IHdhbnQgdG8gZmVlbCBncmVhdCwgeW91IG11c3QgZWF0IHNvbWV0aGluZyByZWFsIGJpZy4=" },
- { "If you want to float, you'd better eat a floating eye.",
- "SWYgeW91IHdhbnQgdG8gZmxvYXQsIHlvdSdkIGJldHRlciBlYXQgYSBmbG9hdGluZyBleWUu" },
- { "If your ghost kills a player, it increases your score.",
- "SWYgeW91ciBnaG9zdCBraWxscyBhIHBsYXllciwgaXQgaW5jcmVhc2VzIHlvdXIgc2NvcmUu" },
- { "Increase mindpower: Tame your own ghost!",
- "SW5jcmVhc2UgbWluZHBvd2VyOiBUYW1lIHlvdXIgb3duIGdob3N0IQ==" },
- { "It furthers one to see the great man.",
- "SXQgZnVydGhlcnMgb25lIHRvIHNlZSB0aGUgZ3JlYXQgbWFuLg==" },
- { "It's easy to overlook a monster in a wood.",
- "SXQncyBlYXN5IHRvIG92ZXJsb29rIGEgbW9uc3RlciBpbiBhIHdvb2Qu" },
- { "Just below any trapdoor there may be another one. Just keep falling!",
- "SnVzdCBiZWxvdyBhbnkgdHJhcGRvb3IgdGhlcmUgbWF5IGJlIGFub3RoZXIgb25lLiBKdXN0IGtlZXAgZmFsbGluZyE=" },
- { "Katanas are very sharp; watch you don't cut yourself.",
- "S2F0YW5hcyBhcmUgdmVyeSBzaGFycDsgd2F0Y2ggeW91IGRvbid0IGN1dCB5b3Vyc2VsZi4=" },
- { "Keep a clear mind: quaff clear potions.",
- "S2VlcCBhIGNsZWFyIG1pbmQ6IHF1YWZmIGNsZWFyIHBvdGlvbnMu" },
- { "Kicking the terminal doesn't hurt the monsters.",
- "S2lja2luZyB0aGUgdGVybWluYWwgZG9lc24ndCBodXJ0IHRoZSBtb25zdGVycy4=" },
- { "Killer bees keep appearing till you kill their queen.",
- "S2lsbGVyIGJlZXMga2VlcCBhcHBlYXJpbmcgdGlsbCB5b3Uga2lsbCB0aGVpciBxdWVlbi4=" },
- { "Killer bunnies can be tamed with carrots only.",
- "S2lsbGVyIGJ1bm5pZXMgY2FuIGJlIHRhbWVkIHdpdGggY2Fycm90cyBvbmx5Lg==" },
- { "Latest news? Put `rec.games.roguelike.nethack' in your .newsrc!",
- "TGF0ZXN0IG5ld3M/IFB1dCBgcmVjLmdhbWVzLnJvZ3VlbGlrZS5uZXRoYWNrJyBpbiB5b3VyIC5uZXdzcmMh" },
- { "Learn how to spell. Play NetHack!",
- "TGVhcm4gaG93IHRvIHNwZWxsLiBQbGF5IE5ldEhhY2sh" },
- { "Leprechauns hide their gold in a secret room.",
- "TGVwcmVjaGF1bnMgaGlkZSB0aGVpciBnb2xkIGluIGEgc2VjcmV0IHJvb20u" },
- { "Let your fingers do the walking on the yulkjhnb keys.",
- "TGV0IHlvdXIgZmluZ2VycyBkbyB0aGUgd2Fsa2luZyBvbiB0aGUgeXVsa2pobmIga2V5cy4=" },
- { "Let's face it: this time you're not going to win.",
- "TGV0J3MgZmFjZSBpdDogdGhpcyB0aW1lIHlvdSdyZSBub3QgZ29pbmcgdG8gd2luLg==" },
- { "Let's have a party, drink a lot of booze.",
- "TGV0J3MgaGF2ZSBhIHBhcnR5LCBkcmluayBhIGxvdCBvZiBib296ZS4=" },
- { "Liquor sellers do not drink; they hate to see you twice.",
- "TGlxdW9yIHNlbGxlcnMgZG8gbm90IGRyaW5rOyB0aGV5IGhhdGUgdG8gc2VlIHlvdSB0d2ljZS4=" },
- { "Lunar eclipse tonight. May as well quit now!",
- "THVuYXIgZWNsaXBzZSB0b25pZ2h0LiBNYXkgYXMgd2VsbCBxdWl0IG5vdyE=" },
- { "Meeting your own ghost decreases your luck considerably!",
- "TWVldGluZyB5b3VyIG93biBnaG9zdCBkZWNyZWFzZXMgeW91ciBsdWNrIGNvbnNpZGVyYWJseSE=" },
- { "Money to invest? Take it to the local branch of the Magic Memory Vault!",
- "TW9uZXkgdG8gaW52ZXN0PyBUYWtlIGl0IHRvIHRoZSBsb2NhbCBicmFuY2ggb2YgdGhlIE1hZ2ljIE1lbW9yeSBWYXVsdCE=" },
- { "Monsters come from nowhere to hit you everywhere.",
- "TW9uc3RlcnMgY29tZSBmcm9tIG5vd2hlcmUgdG8gaGl0IHlvdSBldmVyeXdoZXJlLg==" },
- { "Monsters sleep because you are boring, not because they ever get tired.",
- "TW9uc3RlcnMgc2xlZXAgYmVjYXVzZSB5b3UgYXJlIGJvcmluZywgbm90IGJlY2F1c2UgdGhleSBldmVyIGdldCB0aXJlZC4=" },
- { "Most monsters prefer minced meat. That's why they are hitting you!",
- "TW9zdCBtb25zdGVycyBwcmVmZXIgbWluY2VkIG1lYXQuIFRoYXQncyB3aHkgdGhleSBhcmUgaGl0dGluZyB5b3Uh" },
- { "Most of the bugs in NetHack are on the floor.",
- "TW9zdCBvZiB0aGUgYnVncyBpbiBOZXRIYWNrIGFyZSBvbiB0aGUgZmxvb3Iu" },
- { "Much ado Nothing Happens.",
- "TXVjaCBhZG8gTm90aGluZyBIYXBwZW5zLg==" },
- { "Multi-player NetHack is a myth.",
- "TXVsdGktcGxheWVyIE5ldEhhY2sgaXMgYSBteXRoLg==" },
- { "NetHack is addictive. Too late, you're already hooked.",
- "TmV0SGFjayBpcyBhZGRpY3RpdmUuIFRvbyBsYXRlLCB5b3UncmUgYWxyZWFkeSBob29rZWQu" },
- { "Never ask a shopkeeper for a price list.",
- "TmV2ZXIgYXNrIGEgc2hvcGtlZXBlciBmb3IgYSBwcmljZSBsaXN0Lg==" },
- { "Never burn a tree, unless you like getting whacked with a +5 shovel.",
- "TmV2ZXIgYnVybiBhIHRyZWUsIHVubGVzcyB5b3UgbGlrZSBnZXR0aW5nIHdoYWNrZWQgd2l0aCBhICs1IHNob3ZlbC4=" },
- { "Never eat with glowing hands!",
- "TmV2ZXIgZWF0IHdpdGggZ2xvd2luZyBoYW5kcyE=" },
- { "Never mind the monsters hitting you: they just replace the charwomen.",
- "TmV2ZXIgbWluZCB0aGUgbW9uc3RlcnMgaGl0dGluZyB5b3U6IHRoZXkganVzdCByZXBsYWNlIHRoZSBjaGFyd29tZW4u" },
- { "Never play leapfrog with a unicorn.",
- "TmV2ZXIgcGxheSBsZWFwZnJvZyB3aXRoIGEgdW5pY29ybi4=" },
- { "Never step on a cursed engraving.",
- "TmV2ZXIgc3RlcCBvbiBhIGN1cnNlZCBlbmdyYXZpbmcu" },
- { "Never swim with a camera: there's nothing to take pictures of.",
- "TmV2ZXIgc3dpbSB3aXRoIGEgY2FtZXJhOiB0aGVyZSdzIG5vdGhpbmcgdG8gdGFrZSBwaWN0dXJlcyBvZi4=" },
- { "Never teach your pet rust monster to fetch.",
- "TmV2ZXIgdGVhY2ggeW91ciBwZXQgcnVzdCBtb25zdGVyIHRvIGZldGNoLg==" },
- { "Never trust a random generator in magic fields.",
- "TmV2ZXIgdHJ1c3QgYSByYW5kb20gZ2VuZXJhdG9yIGluIG1hZ2ljIGZpZWxkcy4=" },
- { "Never use a wand of death.",
- "TmV2ZXIgdXNlIGEgd2FuZCBvZiBkZWF0aC4=" },
- { "No level contains two shops. The maze is no level. So...",
- "Tm8gbGV2ZWwgY29udGFpbnMgdHdvIHNob3BzLiBUaGUgbWF6ZSBpcyBubyBsZXZlbC4gU28uLi4=" },
- { "No part of this fortune may be reproduced, stored in a retrieval system, ...",
- "Tm8gcGFydCBvZiB0aGlzIGZvcnR1bmUgbWF5IGJlIHJlcHJvZHVjZWQsIHN0b3JlZCBpbiBhIHJldHJpZXZhbCBzeXN0ZW0sIC4uLg==" },
- { "Not all rumors are as misleading as this one.",
- "Tm90IGFsbCBydW1vcnMgYXJlIGFzIG1pc2xlYWRpbmcgYXMgdGhpcyBvbmUu" },
- { "Nymphs and nurses like beautiful rings.",
- "TnltcGhzIGFuZCBudXJzZXMgbGlrZSBiZWF1dGlmdWwgcmluZ3Mu" },
- { "Nymphs are blondes. Are you a gentleman?",
- "TnltcGhzIGFyZSBibG9uZGVzLiBBcmUgeW91IGEgZ2VudGxlbWFuPw==" },
- { "Offering a unicorn a worthless piece of glass might prove to be fatal!",
- "T2ZmZXJpbmcgYSB1bmljb3JuIGEgd29ydGhsZXNzIHBpZWNlIG9mIGdsYXNzIG1pZ2h0IHByb3ZlIHRvIGJlIGZhdGFsIQ==" },
- { "Old hackers never die: young ones do.",
- "T2xkIGhhY2tlcnMgbmV2ZXIgZGllOiB5b3VuZyBvbmVzIGRvLg==" },
- { "One has to leave shops before closing time.",
- "T25lIGhhcyB0byBsZWF2ZSBzaG9wcyBiZWZvcmUgY2xvc2luZyB0aW1lLg==" },
- { "One homunculus a day keeps the doctor away.",
- "T25lIGhvbXVuY3VsdXMgYSBkYXkga2VlcHMgdGhlIGRvY3RvciBhd2F5Lg==" },
- { "One level further down somebody is getting killed, right now.",
- "T25lIGxldmVsIGZ1cnRoZXIgZG93biBzb21lYm9keSBpcyBnZXR0aW5nIGtpbGxlZCwgcmlnaHQgbm93Lg==" },
- { "Only a wizard can use a magic whistle.",
- "T25seSBhIHdpemFyZCBjYW4gdXNlIGEgbWFnaWMgd2hpc3RsZS4=" },
- { "Only adventurers of evil alignment think of killing their dog.",
- "T25seSBhZHZlbnR1cmVycyBvZiBldmlsIGFsaWdubWVudCB0aGluayBvZiBraWxsaW5nIHRoZWlyIGRvZy4=" },
- { "Only chaotic evils kill sleeping monsters.",
- "T25seSBjaGFvdGljIGV2aWxzIGtpbGwgc2xlZXBpbmcgbW9uc3RlcnMu" },
- { "Only real trappers escape traps.",
- "T25seSByZWFsIHRyYXBwZXJzIGVzY2FwZSB0cmFwcy4=" },
- { "Only real wizards can write scrolls.",
- "T25seSByZWFsIHdpemFyZHMgY2FuIHdyaXRlIHNjcm9sbHMu" },
- { "Operation OVERKILL has started now.",
- "T3BlcmF0aW9uIE9WRVJLSUxMIGhhcyBzdGFydGVkIG5vdy4=" },
- { "PLEASE ignore previous rumor.",
- "UExFQVNFIGlnbm9yZSBwcmV2aW91cyBydW1vci4=" },
- { "Polymorph into an ettin; meet your opponents face to face to face.",
- "UG9seW1vcnBoIGludG8gYW4gZXR0aW47IG1lZXQgeW91ciBvcHBvbmVudHMgZmFjZSB0byBmYWNlIHRvIGZhY2Uu" },
- { "Praying will frighten demons.",
- "UHJheWluZyB3aWxsIGZyaWdodGVuIGRlbW9ucy4=" },
- { "Row (3x) that boat gently down the stream, Charon (4x), death is but a dream.",
- "Um93ICgzeCkgdGhhdCBib2F0IGdlbnRseSBkb3duIHRoZSBzdHJlYW0sIENoYXJvbiAoNHgpLCBkZWF0aCBpcyBidXQgYSBkcmVhbS4=" },
- { "Running is good for your legs.",
- "UnVubmluZyBpcyBnb29kIGZvciB5b3VyIGxlZ3Mu" },
- { "Screw up your courage! You've screwed up everything else.",
- "U2NyZXcgdXAgeW91ciBjb3VyYWdlISBZb3UndmUgc2NyZXdlZCB1cCBldmVyeXRoaW5nIGVsc2Uu" },
- { "Seepage? Leaky pipes? Rising damp? Summon the plumber!",
- "U2VlcGFnZT8gTGVha3kgcGlwZXM/IFJpc2luZyBkYW1wPyBTdW1tb24gdGhlIHBsdW1iZXIh" },
- { "Segmentation fault (core dumped).",
- "U2VnbWVudGF0aW9uIGZhdWx0IChjb3JlIGR1bXBlZCku" },
- { "Shopkeepers sometimes die from old age.",
- "U2hvcGtlZXBlcnMgc29tZXRpbWVzIGRpZSBmcm9tIG9sZCBhZ2Uu" },
- { "Some mazes (especially small ones) have no solutions, says man 6 maze.",
- "U29tZSBtYXplcyAoZXNwZWNpYWxseSBzbWFsbCBvbmVzKSBoYXZlIG5vIHNvbHV0aW9ucywgc2F5cyBtYW4gNiBtYXplLg==" },
- { "Some questions the Sphynx asks just *don't* have any answers.",
- "U29tZSBxdWVzdGlvbnMgdGhlIFNwaHlueCBhc2tzIGp1c3QgKmRvbid0KiBoYXZlIGFueSBhbnN3ZXJzLg==" },
- { "Sometimes \"mu\" is the answer.",
- "U29tZXRpbWVzICJtdSIgaXMgdGhlIGFuc3dlci4=" },
- { "Sorry, no fortune this time. Better luck next cookie!",
- "U29ycnksIG5vIGZvcnR1bmUgdGhpcyB0aW1lLiBCZXR0ZXIgbHVjayBuZXh0IGNvb2tpZSE=" },
- { "Spare your scrolls of make-edible until it's really necessary!",
- "U3BhcmUgeW91ciBzY3JvbGxzIG9mIG1ha2UtZWRpYmxlIHVudGlsIGl0J3MgcmVhbGx5IG5lY2Vzc2FyeSE=" },
- { "Suddenly, the dungeon will collapse...",
- "U3VkZGVubHksIHRoZSBkdW5nZW9uIHdpbGwgY29sbGFwc2UuLi4=" },
- { "Taming a mail daemon may cause a system security violation.",
- "VGFtaW5nIGEgbWFpbCBkYWVtb24gbWF5IGNhdXNlIGEgc3lzdGVtIHNlY3VyaXR5IHZpb2xhdGlvbi4=" },
- { "The crowd was so tough, the Stooges won't play the Dungeon anymore, nyuk nyuk.",
- "VGhlIGNyb3dkIHdhcyBzbyB0b3VnaCwgdGhlIFN0b29nZXMgd29uJ3QgcGxheSB0aGUgRHVuZ2VvbiBhbnltb3JlLCBueXVrIG55dWsu" },
- { "The leprechauns hide their treasure in a small hidden room.",
- "VGhlIGxlcHJlY2hhdW5zIGhpZGUgdGhlaXIgdHJlYXN1cmUgaW4gYSBzbWFsbCBoaWRkZW4gcm9vbS4=" },
- { "The longer the wand the better.",
- "VGhlIGxvbmdlciB0aGUgd2FuZCB0aGUgYmV0dGVyLg==" },
- { "The magic word is \"XYZZY\".",
- "VGhlIG1hZ2ljIHdvcmQgaXMgIlhZWlpZIi4=" },
- { "The meek shall inherit your bones files.",
- "VGhlIG1lZWsgc2hhbGwgaW5oZXJpdCB5b3VyIGJvbmVzIGZpbGVzLg==" },
- { "The mines are dark and deep, and I have levels to go before I sleep.",
- "VGhlIG1pbmVzIGFyZSBkYXJrIGFuZCBkZWVwLCBhbmQgSSBoYXZlIGxldmVscyB0byBnbyBiZWZvcmUgSSBzbGVlcC4=" },
- { "The use of dynamite is dangerous.",
- "VGhlIHVzZSBvZiBkeW5hbWl0ZSBpcyBkYW5nZXJvdXMu" },
- { "There are no worms in the UNIX version.",
- "VGhlcmUgYXJlIG5vIHdvcm1zIGluIHRoZSBVTklYIHZlcnNpb24u" },
- { "There is a trap on this level!",
- "VGhlcmUgaXMgYSB0cmFwIG9uIHRoaXMgbGV2ZWwh" },
- { "They say that Demogorgon, Asmodeus, Orcus, Yeenoghu & Juiblex is no law firm.",
- "VGhleSBzYXkgdGhhdCBEZW1vZ29yZ29uLCBBc21vZGV1cywgT3JjdXMsIFllZW5vZ2h1ICYgSnVpYmxleCBpcyBubyBsYXcgZmlybS4=" },
- { "They say that Geryon has an evil twin, beware!",
- "VGhleSBzYXkgdGhhdCBHZXJ5b24gaGFzIGFuIGV2aWwgdHdpbiwgYmV3YXJlIQ==" },
- { "They say that Medusa would make a terrible pet.",
- "VGhleSBzYXkgdGhhdCBNZWR1c2Egd291bGQgbWFrZSBhIHRlcnJpYmxlIHBldC4=" },
- { "They say that NetHack bugs are Seldon planned.",
- "VGhleSBzYXkgdGhhdCBOZXRIYWNrIGJ1Z3MgYXJlIFNlbGRvbiBwbGFubmVkLg==" },
- { "They say that NetHack comes in 256 flavors.",
- "VGhleSBzYXkgdGhhdCBOZXRIYWNrIGNvbWVzIGluIDI1NiBmbGF2b3JzLg==" },
- { "They say that NetHack is just a computer game.",
- "VGhleSBzYXkgdGhhdCBOZXRIYWNrIGlzIGp1c3QgYSBjb21wdXRlciBnYW1lLg==" },
- { "They say that NetHack is more than just a computer game.",
- "VGhleSBzYXkgdGhhdCBOZXRIYWNrIGlzIG1vcmUgdGhhbiBqdXN0IGEgY29tcHV0ZXIgZ2FtZS4=" },
- { "They say that NetHack is never what it used to be.",
- "VGhleSBzYXkgdGhhdCBOZXRIYWNrIGlzIG5ldmVyIHdoYXQgaXQgdXNlZCB0byBiZS4=" },
- { "They say that a baby dragon is too small to hurt or help you.",
- "VGhleSBzYXkgdGhhdCBhIGJhYnkgZHJhZ29uIGlzIHRvbyBzbWFsbCB0byBodXJ0IG9yIGhlbHAgeW91Lg==" },
- { "They say that a black pudding is simply a brown pudding gone bad.",
- "VGhleSBzYXkgdGhhdCBhIGJsYWNrIHB1ZGRpbmcgaXMgc2ltcGx5IGEgYnJvd24gcHVkZGluZyBnb25lIGJhZC4=" },
- { "They say that a black sheep has 3 bags full of wool.",
- "VGhleSBzYXkgdGhhdCBhIGJsYWNrIHNoZWVwIGhhcyAzIGJhZ3MgZnVsbCBvZiB3b29sLg==" },
- { "They say that a blank scroll is like a blank check.",
- "VGhleSBzYXkgdGhhdCBhIGJsYW5rIHNjcm9sbCBpcyBsaWtlIGEgYmxhbmsgY2hlY2su" },
- { "They say that a cat named Morris has nine lives.",
- "VGhleSBzYXkgdGhhdCBhIGNhdCBuYW1lZCBNb3JyaXMgaGFzIG5pbmUgbGl2ZXMu" },
- { "They say that a desperate shopper might pay any price in a shop.",
- "VGhleSBzYXkgdGhhdCBhIGRlc3BlcmF0ZSBzaG9wcGVyIG1pZ2h0IHBheSBhbnkgcHJpY2UgaW4gYSBzaG9wLg==" },
- { "They say that a diamond dog is everybody's best friend.",
- "VGhleSBzYXkgdGhhdCBhIGRpYW1vbmQgZG9nIGlzIGV2ZXJ5Ym9keSdzIGJlc3QgZnJpZW5kLg==" },
- { "They say that a dwarf lord can carry a pick-axe because his armor is light.",
- "VGhleSBzYXkgdGhhdCBhIGR3YXJmIGxvcmQgY2FuIGNhcnJ5IGEgcGljay1heGUgYmVjYXVzZSBoaXMgYXJtb3IgaXMgbGlnaHQu" },
- { "They say that a floating eye can defeat Medusa.",
- "VGhleSBzYXkgdGhhdCBhIGZsb2F0aW5nIGV5ZSBjYW4gZGVmZWF0IE1lZHVzYS4=" },
- { "They say that a fortune only has 1 line and you can't read between it.",
- "VGhleSBzYXkgdGhhdCBhIGZvcnR1bmUgb25seSBoYXMgMSBsaW5lIGFuZCB5b3UgY2FuJ3QgcmVhZCBiZXR3ZWVuIGl0Lg==" },
- { "They say that a fortune only has 1 line, but you can read between it.",
- "VGhleSBzYXkgdGhhdCBhIGZvcnR1bmUgb25seSBoYXMgMSBsaW5lLCBidXQgeW91IGNhbiByZWFkIGJldHdlZW4gaXQu" },
- { "They say that a fountain looks nothing like a regularly erupting geyser.",
- "VGhleSBzYXkgdGhhdCBhIGZvdW50YWluIGxvb2tzIG5vdGhpbmcgbGlrZSBhIHJlZ3VsYXJseSBlcnVwdGluZyBnZXlzZXIu" },
- { "They say that a gold doubloon is worth more than its weight in gold.",
- "VGhleSBzYXkgdGhhdCBhIGdvbGQgZG91Ymxvb24gaXMgd29ydGggbW9yZSB0aGFuIGl0cyB3ZWlnaHQgaW4gZ29sZC4=" },
- { "They say that a grid bug won't pay a shopkeeper for zapping you in a shop.",
- "VGhleSBzYXkgdGhhdCBhIGdyaWQgYnVnIHdvbid0IHBheSBhIHNob3BrZWVwZXIgZm9yIHphcHBpbmcgeW91IGluIGEgc2hvcC4=" },
- { "They say that a gypsy could tell your fortune for a price.",
- "VGhleSBzYXkgdGhhdCBhIGd5cHN5IGNvdWxkIHRlbGwgeW91ciBmb3J0dW5lIGZvciBhIHByaWNlLg==" },
- { "They say that a hacker named Alice once level teleported by using a mirror.",
- "VGhleSBzYXkgdGhhdCBhIGhhY2tlciBuYW1lZCBBbGljZSBvbmNlIGxldmVsIHRlbGVwb3J0ZWQgYnkgdXNpbmcgYSBtaXJyb3Iu" },
- { "They say that a hacker named David once slew a giant with a sling and a rock.",
- "VGhleSBzYXkgdGhhdCBhIGhhY2tlciBuYW1lZCBEYXZpZCBvbmNlIHNsZXcgYSBnaWFudCB3aXRoIGEgc2xpbmcgYW5kIGEgcm9jay4=" },
- { "They say that a hacker named Dorothy once rode a fog cloud to Oz.",
- "VGhleSBzYXkgdGhhdCBhIGhhY2tlciBuYW1lZCBEb3JvdGh5IG9uY2Ugcm9kZSBhIGZvZyBjbG91ZCB0byBPei4=" },
- { "They say that a hacker named Mary once lost a white sheep in the mazes.",
- "VGhleSBzYXkgdGhhdCBhIGhhY2tlciBuYW1lZCBNYXJ5IG9uY2UgbG9zdCBhIHdoaXRlIHNoZWVwIGluIHRoZSBtYXplcy4=" },
- { "They say that a helm of brilliance is not to be taken lightly.",
- "VGhleSBzYXkgdGhhdCBhIGhlbG0gb2YgYnJpbGxpYW5jZSBpcyBub3QgdG8gYmUgdGFrZW4gbGlnaHRseS4=" },
- { "They say that a hot dog and a hell hound are the same thing.",
- "VGhleSBzYXkgdGhhdCBhIGhvdCBkb2cgYW5kIGEgaGVsbCBob3VuZCBhcmUgdGhlIHNhbWUgdGhpbmcu" },
- { "They say that a lamp named Aladdin's Lamp contains a djinni with 3 wishes.",
- "VGhleSBzYXkgdGhhdCBhIGxhbXAgbmFtZWQgQWxhZGRpbidzIExhbXAgY29udGFpbnMgYSBkamlubmkgd2l0aCAzIHdpc2hlcy4=" },
- { "They say that a large dog named Lassie will lead you to the amulet.",
- "VGhleSBzYXkgdGhhdCBhIGxhcmdlIGRvZyBuYW1lZCBMYXNzaWUgd2lsbCBsZWFkIHlvdSB0byB0aGUgYW11bGV0Lg==" },
- { "They say that a long sword is not a light sword.",
- "VGhleSBzYXkgdGhhdCBhIGxvbmcgc3dvcmQgaXMgbm90IGEgbGlnaHQgc3dvcmQu" },
- { "They say that a manes won't mince words with you.",
- "VGhleSBzYXkgdGhhdCBhIG1hbmVzIHdvbid0IG1pbmNlIHdvcmRzIHdpdGggeW91Lg==" },
- { "They say that a mind is a terrible thing to waste.",
- "VGhleSBzYXkgdGhhdCBhIG1pbmQgaXMgYSB0ZXJyaWJsZSB0aGluZyB0byB3YXN0ZS4=" },
- { "They say that a plain nymph will only wear a wire ring in one ear.",
- "VGhleSBzYXkgdGhhdCBhIHBsYWluIG55bXBoIHdpbGwgb25seSB3ZWFyIGEgd2lyZSByaW5nIGluIG9uZSBlYXIu" },
- { "They say that a plumed hat could be a previously used crested helmet.",
- "VGhleSBzYXkgdGhhdCBhIHBsdW1lZCBoYXQgY291bGQgYmUgYSBwcmV2aW91c2x5IHVzZWQgY3Jlc3RlZCBoZWxtZXQu" },
- { "They say that a potion of oil is difficult to grasp.",
- "VGhleSBzYXkgdGhhdCBhIHBvdGlvbiBvZiBvaWwgaXMgZGlmZmljdWx0IHRvIGdyYXNwLg==" },
- { "They say that a potion of yogurt is a cancelled potion of sickness.",
- "VGhleSBzYXkgdGhhdCBhIHBvdGlvbiBvZiB5b2d1cnQgaXMgYSBjYW5jZWxsZWQgcG90aW9uIG9mIHNpY2tuZXNzLg==" },
- { "They say that a purple worm is not a baby purple dragon.",
- "VGhleSBzYXkgdGhhdCBhIHB1cnBsZSB3b3JtIGlzIG5vdCBhIGJhYnkgcHVycGxlIGRyYWdvbi4=" },
- { "They say that a quivering blob tastes different than a gelatinous cube.",
- "VGhleSBzYXkgdGhhdCBhIHF1aXZlcmluZyBibG9iIHRhc3RlcyBkaWZmZXJlbnQgdGhhbiBhIGdlbGF0aW5vdXMgY3ViZS4=" },
- { "They say that a runed broadsword named Stormbringer attracts vortices.",
- "VGhleSBzYXkgdGhhdCBhIHJ1bmVkIGJyb2Fkc3dvcmQgbmFtZWQgU3Rvcm1icmluZ2VyIGF0dHJhY3RzIHZvcnRpY2VzLg==" },
- { "They say that a scroll of summoning has other names.",
- "VGhleSBzYXkgdGhhdCBhIHNjcm9sbCBvZiBzdW1tb25pbmcgaGFzIG90aGVyIG5hbWVzLg==" },
- { "They say that a shaman can bestow blessings but usually doesn't.",
- "VGhleSBzYXkgdGhhdCBhIHNoYW1hbiBjYW4gYmVzdG93IGJsZXNzaW5ncyBidXQgdXN1YWxseSBkb2Vzbid0Lg==" },
- { "They say that a shaman will bless you for an eye of newt and wing of bat.",
- "VGhleSBzYXkgdGhhdCBhIHNoYW1hbiB3aWxsIGJsZXNzIHlvdSBmb3IgYW4gZXllIG9mIG5ld3QgYW5kIHdpbmcgb2YgYmF0Lg==" },
- { "They say that a shimmering gold shield is not a polished silver shield.",
- "VGhleSBzYXkgdGhhdCBhIHNoaW1tZXJpbmcgZ29sZCBzaGllbGQgaXMgbm90IGEgcG9saXNoZWQgc2lsdmVyIHNoaWVsZC4=" },
- { "They say that a spear will hit a neo-otyugh. (Do YOU know what that is?)",
- "VGhleSBzYXkgdGhhdCBhIHNwZWFyIHdpbGwgaGl0IGEgbmVvLW90eXVnaC4gKERvIFlPVSBrbm93IHdoYXQgdGhhdCBpcz8p" },
- { "They say that a spotted dragon is the ultimate shape changer.",
- "VGhleSBzYXkgdGhhdCBhIHNwb3R0ZWQgZHJhZ29uIGlzIHRoZSB1bHRpbWF0ZSBzaGFwZSBjaGFuZ2VyLg==" },
- { "They say that a stethoscope is no good if you can only hear your heartbeat.",
- "VGhleSBzYXkgdGhhdCBhIHN0ZXRob3Njb3BlIGlzIG5vIGdvb2QgaWYgeW91IGNhbiBvbmx5IGhlYXIgeW91ciBoZWFydGJlYXQu" },
- { "They say that a succubus named Suzy will sometimes warn you of danger.",
- "VGhleSBzYXkgdGhhdCBhIHN1Y2N1YnVzIG5hbWVkIFN1enkgd2lsbCBzb21ldGltZXMgd2FybiB5b3Ugb2YgZGFuZ2VyLg==" },
- { "They say that a wand of cancellation is not like a wand of polymorph.",
- "VGhleSBzYXkgdGhhdCBhIHdhbmQgb2YgY2FuY2VsbGF0aW9uIGlzIG5vdCBsaWtlIGEgd2FuZCBvZiBwb2x5bW9ycGgu" },
- { "They say that a wood golem named Pinocchio would be easy to control.",
- "VGhleSBzYXkgdGhhdCBhIHdvb2QgZ29sZW0gbmFtZWQgUGlub2NjaGlvIHdvdWxkIGJlIGVhc3kgdG8gY29udHJvbC4=" },
- { "They say that after killing a dragon it's time for a change of scenery.",
- "VGhleSBzYXkgdGhhdCBhZnRlciBraWxsaW5nIGEgZHJhZ29uIGl0J3MgdGltZSBmb3IgYSBjaGFuZ2Ugb2Ygc2NlbmVyeS4=" },
- { "They say that an amulet of strangulation is worse than ring around the collar.",
- "VGhleSBzYXkgdGhhdCBhbiBhbXVsZXQgb2Ygc3RyYW5ndWxhdGlvbiBpcyB3b3JzZSB0aGFuIHJpbmcgYXJvdW5kIHRoZSBjb2xsYXIu" },
- { "They say that an attic is the best place to hide your toys.",
- "VGhleSBzYXkgdGhhdCBhbiBhdHRpYyBpcyB0aGUgYmVzdCBwbGFjZSB0byBoaWRlIHlvdXIgdG95cy4=" },
- { "They say that an axe named Cleaver once belonged to a hacker named Beaver.",
- "VGhleSBzYXkgdGhhdCBhbiBheGUgbmFtZWQgQ2xlYXZlciBvbmNlIGJlbG9uZ2VkIHRvIGEgaGFja2VyIG5hbWVkIEJlYXZlci4=" },
- { "They say that an eye of newt and a wing of bat are double the trouble.",
- "VGhleSBzYXkgdGhhdCBhbiBleWUgb2YgbmV3dCBhbmQgYSB3aW5nIG9mIGJhdCBhcmUgZG91YmxlIHRoZSB0cm91YmxlLg==" },
- { "They say that an incubus named Izzy sometimes makes women feel sensitive.",
- "VGhleSBzYXkgdGhhdCBhbiBpbmN1YnVzIG5hbWVkIEl6enkgc29tZXRpbWVzIG1ha2VzIHdvbWVuIGZlZWwgc2Vuc2l0aXZlLg==" },
- { "They say that an opulent throne room is rarely a place to wish you'd be in.",
- "VGhleSBzYXkgdGhhdCBhbiBvcHVsZW50IHRocm9uZSByb29tIGlzIHJhcmVseSBhIHBsYWNlIHRvIHdpc2ggeW91J2QgYmUgaW4u" },
- { "They say that an unlucky hacker once had a nose bleed at an altar and died.",
- "VGhleSBzYXkgdGhhdCBhbiB1bmx1Y2t5IGhhY2tlciBvbmNlIGhhZCBhIG5vc2UgYmxlZWQgYXQgYW4gYWx0YXIgYW5kIGRpZWQu" },
- { "They say that and they say this but they never say never, never!",
- "VGhleSBzYXkgdGhhdCBhbmQgdGhleSBzYXkgdGhpcyBidXQgdGhleSBuZXZlciBzYXkgbmV2ZXIsIG5ldmVyIQ==" },
- { "They say that any quantum mechanic knows that speed kills.",
- "VGhleSBzYXkgdGhhdCBhbnkgcXVhbnR1bSBtZWNoYW5pYyBrbm93cyB0aGF0IHNwZWVkIGtpbGxzLg==" },
- { "They say that applying a unicorn horn means you've missed the point.",
- "VGhleSBzYXkgdGhhdCBhcHBseWluZyBhIHVuaWNvcm4gaG9ybiBtZWFucyB5b3UndmUgbWlzc2VkIHRoZSBwb2ludC4=" },
- { "They say that blue stones are radioactive, beware.",
- "VGhleSBzYXkgdGhhdCBibHVlIHN0b25lcyBhcmUgcmFkaW9hY3RpdmUsIGJld2FyZS4=" },
- { "They say that building a dungeon is a team effort.",
- "VGhleSBzYXkgdGhhdCBidWlsZGluZyBhIGR1bmdlb24gaXMgYSB0ZWFtIGVmZm9ydC4=" },
- { "They say that chaotic characters never get a kick out of altars.",
- "VGhleSBzYXkgdGhhdCBjaGFvdGljIGNoYXJhY3RlcnMgbmV2ZXIgZ2V0IGEga2ljayBvdXQgb2YgYWx0YXJzLg==" },
- { "They say that collapsing a dungeon often creates a panic.",
- "VGhleSBzYXkgdGhhdCBjb2xsYXBzaW5nIGEgZHVuZ2VvbiBvZnRlbiBjcmVhdGVzIGEgcGFuaWMu" },
- { "They say that counting your eggs before they hatch shows that you care.",
- "VGhleSBzYXkgdGhhdCBjb3VudGluZyB5b3VyIGVnZ3MgYmVmb3JlIHRoZXkgaGF0Y2ggc2hvd3MgdGhhdCB5b3UgY2FyZS4=" },
- { "They say that dipping a bag of tricks in a fountain won't make it an icebox.",
- "VGhleSBzYXkgdGhhdCBkaXBwaW5nIGEgYmFnIG9mIHRyaWNrcyBpbiBhIGZvdW50YWluIHdvbid0IG1ha2UgaXQgYW4gaWNlYm94Lg==" },
- { "They say that dipping an eel and brown mold in hot water makes bouillabaisse.",
- "VGhleSBzYXkgdGhhdCBkaXBwaW5nIGFuIGVlbCBhbmQgYnJvd24gbW9sZCBpbiBob3Qgd2F0ZXIgbWFrZXMgYm91aWxsYWJhaXNzZS4=" },
- { "They say that donating a doubloon is extremely pious charity.",
- "VGhleSBzYXkgdGhhdCBkb25hdGluZyBhIGRvdWJsb29uIGlzIGV4dHJlbWVseSBwaW91cyBjaGFyaXR5Lg==" },
- { "They say that eating royal jelly attracts grizzly owlbears.",
- "VGhleSBzYXkgdGhhdCBlYXRpbmcgcm95YWwgamVsbHkgYXR0cmFjdHMgZ3JpenpseSBvd2xiZWFycy4=" },
- { "They say that eggs, pancakes and juice are just a mundane breakfast.",
- "VGhleSBzYXkgdGhhdCBlZ2dzLCBwYW5jYWtlcyBhbmQganVpY2UgYXJlIGp1c3QgYSBtdW5kYW5lIGJyZWFrZmFzdC4=" },
- { "They say that everyone knows why Medusa stands alone in the dark.",
- "VGhleSBzYXkgdGhhdCBldmVyeW9uZSBrbm93cyB3aHkgTWVkdXNhIHN0YW5kcyBhbG9uZSBpbiB0aGUgZGFyay4=" },
- { "They say that everyone wanted rec.games.hack to undergo a name change.",
- "VGhleSBzYXkgdGhhdCBldmVyeW9uZSB3YW50ZWQgcmVjLmdhbWVzLmhhY2sgdG8gdW5kZXJnbyBhIG5hbWUgY2hhbmdlLg==" },
- { "They say that finding a winning strategy is a deliberate move on your part.",
- "VGhleSBzYXkgdGhhdCBmaW5kaW5nIGEgd2lubmluZyBzdHJhdGVneSBpcyBhIGRlbGliZXJhdGUgbW92ZSBvbiB5b3VyIHBhcnQu" },
- { "They say that finding worthless glass is worth something.",
- "VGhleSBzYXkgdGhhdCBmaW5kaW5nIHdvcnRobGVzcyBnbGFzcyBpcyB3b3J0aCBzb21ldGhpbmcu" },
- { "They say that fortune cookies are food for thought.",
- "VGhleSBzYXkgdGhhdCBmb3J0dW5lIGNvb2tpZXMgYXJlIGZvb2QgZm9yIHRob3VnaHQu" },
- { "They say that gold is only wasted on a pet dragon.",
- "VGhleSBzYXkgdGhhdCBnb2xkIGlzIG9ubHkgd2FzdGVkIG9uIGEgcGV0IGRyYWdvbi4=" },
- { "They say that good things come to those that wait.",
- "VGhleSBzYXkgdGhhdCBnb29kIHRoaW5ncyBjb21lIHRvIHRob3NlIHRoYXQgd2FpdC4=" },
- { "They say that greased objects will slip out of monsters' hands.",
- "VGhleSBzYXkgdGhhdCBncmVhc2VkIG9iamVjdHMgd2lsbCBzbGlwIG91dCBvZiBtb25zdGVycycgaGFuZHMu" },
- { "They say that if you can't spell then you'll wish you had a spell book.",
- "VGhleSBzYXkgdGhhdCBpZiB5b3UgY2FuJ3Qgc3BlbGwgdGhlbiB5b3UnbGwgd2lzaCB5b3UgaGFkIGEgc3BlbGwgYm9vay4=" },
- { "They say that if you live by the sword, you'll die by the sword.",
- "VGhleSBzYXkgdGhhdCBpZiB5b3UgbGl2ZSBieSB0aGUgc3dvcmQsIHlvdSdsbCBkaWUgYnkgdGhlIHN3b3JkLg==" },
- { "They say that if you play like a monster you'll have a better game.",
- "VGhleSBzYXkgdGhhdCBpZiB5b3UgcGxheSBsaWtlIGEgbW9uc3RlciB5b3UnbGwgaGF2ZSBhIGJldHRlciBnYW1lLg==" },
- { "They say that if you sleep with a demon you might awake with a headache.",
- "VGhleSBzYXkgdGhhdCBpZiB5b3Ugc2xlZXAgd2l0aCBhIGRlbW9uIHlvdSBtaWdodCBhd2FrZSB3aXRoIGEgaGVhZGFjaGUu" },
- { "They say that if you step on a crack you could break your mother's back.",
- "VGhleSBzYXkgdGhhdCBpZiB5b3Ugc3RlcCBvbiBhIGNyYWNrIHlvdSBjb3VsZCBicmVhayB5b3VyIG1vdGhlcidzIGJhY2su" },
- { "They say that if you're invisible you can still be heard!",
- "VGhleSBzYXkgdGhhdCBpZiB5b3UncmUgaW52aXNpYmxlIHlvdSBjYW4gc3RpbGwgYmUgaGVhcmQh" },
- { "They say that if you're lucky you can feel the runes on a scroll.",
- "VGhleSBzYXkgdGhhdCBpZiB5b3UncmUgbHVja3kgeW91IGNhbiBmZWVsIHRoZSBydW5lcyBvbiBhIHNjcm9sbC4=" },
- { "They say that in the big picture gold is only small change.",
- "VGhleSBzYXkgdGhhdCBpbiB0aGUgYmlnIHBpY3R1cmUgZ29sZCBpcyBvbmx5IHNtYWxsIGNoYW5nZS4=" },
- { "They say that in the dungeon it's not what you know that really matters.",
- "VGhleSBzYXkgdGhhdCBpbiB0aGUgZHVuZ2VvbiBpdCdzIG5vdCB3aGF0IHlvdSBrbm93IHRoYXQgcmVhbGx5IG1hdHRlcnMu" },
- { "They say that in the dungeon moon rocks are really dilithium crystals.",
- "VGhleSBzYXkgdGhhdCBpbiB0aGUgZHVuZ2VvbiBtb29uIHJvY2tzIGFyZSByZWFsbHkgZGlsaXRoaXVtIGNyeXN0YWxzLg==" },
- { "They say that in the dungeon the boorish customer is never right.",
- "VGhleSBzYXkgdGhhdCBpbiB0aGUgZHVuZ2VvbiB0aGUgYm9vcmlzaCBjdXN0b21lciBpcyBuZXZlciByaWdodC4=" },
- { "They say that in the dungeon you don't need a watch to tell time.",
- "VGhleSBzYXkgdGhhdCBpbiB0aGUgZHVuZ2VvbiB5b3UgZG9uJ3QgbmVlZCBhIHdhdGNoIHRvIHRlbGwgdGltZS4=" },
- { "They say that in the dungeon you need something old, new, burrowed and blue.",
- "VGhleSBzYXkgdGhhdCBpbiB0aGUgZHVuZ2VvbiB5b3UgbmVlZCBzb21ldGhpbmcgb2xkLCBuZXcsIGJ1cnJvd2VkIGFuZCBibHVlLg==" },
- { "They say that in the dungeon you should always count your blessings.",
- "VGhleSBzYXkgdGhhdCBpbiB0aGUgZHVuZ2VvbiB5b3Ugc2hvdWxkIGFsd2F5cyBjb3VudCB5b3VyIGJsZXNzaW5ncy4=" },
- { "They say that iron golem plate mail isn't worth wishing for.",
- "VGhleSBzYXkgdGhhdCBpcm9uIGdvbGVtIHBsYXRlIG1haWwgaXNuJ3Qgd29ydGggd2lzaGluZyBmb3Iu" },
- { "They say that it takes four quarterstaffs to make one staff.",
- "VGhleSBzYXkgdGhhdCBpdCB0YWtlcyBmb3VyIHF1YXJ0ZXJzdGFmZnMgdG8gbWFrZSBvbmUgc3RhZmYu" },
- { "They say that it's not over till the fat ladies sing.",
- "VGhleSBzYXkgdGhhdCBpdCdzIG5vdCBvdmVyIHRpbGwgdGhlIGZhdCBsYWRpZXMgc2luZy4=" },
- { "They say that it's not over till the fat lady shouts `Off with its head'.",
- "VGhleSBzYXkgdGhhdCBpdCdzIG5vdCBvdmVyIHRpbGwgdGhlIGZhdCBsYWR5IHNob3V0cyBgT2ZmIHdpdGggaXRzIGhlYWQnLg==" },
- { "They say that kicking a heavy statue is really a dumb move.",
- "VGhleSBzYXkgdGhhdCBraWNraW5nIGEgaGVhdnkgc3RhdHVlIGlzIHJlYWxseSBhIGR1bWIgbW92ZS4=" },
- { "They say that kicking a valuable gem doesn't seem to make sense.",
- "VGhleSBzYXkgdGhhdCBraWNraW5nIGEgdmFsdWFibGUgZ2VtIGRvZXNuJ3Qgc2VlbSB0byBtYWtlIHNlbnNlLg==" },
- { "They say that leprechauns know Latin and you should too.",
- "VGhleSBzYXkgdGhhdCBsZXByZWNoYXVucyBrbm93IExhdGluIGFuZCB5b3Ugc2hvdWxkIHRvby4=" },
- { "They say that minotaurs get lost outside of the mazes.",
- "VGhleSBzYXkgdGhhdCBtaW5vdGF1cnMgZ2V0IGxvc3Qgb3V0c2lkZSBvZiB0aGUgbWF6ZXMu" },
- { "They say that most trolls are born again.",
- "VGhleSBzYXkgdGhhdCBtb3N0IHRyb2xscyBhcmUgYm9ybiBhZ2Fpbi4=" },
- { "They say that naming your cat Garfield will make you more attractive.",
- "VGhleSBzYXkgdGhhdCBuYW1pbmcgeW91ciBjYXQgR2FyZmllbGQgd2lsbCBtYWtlIHlvdSBtb3JlIGF0dHJhY3RpdmUu" },
- { "They say that no one knows everything about everything in the dungeon.",
- "VGhleSBzYXkgdGhhdCBubyBvbmUga25vd3MgZXZlcnl0aGluZyBhYm91dCBldmVyeXRoaW5nIGluIHRoZSBkdW5nZW9uLg==" },
- { "They say that no one plays NetHack just for the fun of it.",
- "VGhleSBzYXkgdGhhdCBubyBvbmUgcGxheXMgTmV0SGFjayBqdXN0IGZvciB0aGUgZnVuIG9mIGl0Lg==" },
- { "They say that no one really subscribes to rec.games.roguelike.nethack.",
- "VGhleSBzYXkgdGhhdCBubyBvbmUgcmVhbGx5IHN1YnNjcmliZXMgdG8gcmVjLmdhbWVzLnJvZ3VlbGlrZS5uZXRoYWNrLg==" },
- { "They say that no one will admit to starting a rumor.",
- "VGhleSBzYXkgdGhhdCBubyBvbmUgd2lsbCBhZG1pdCB0byBzdGFydGluZyBhIHJ1bW9yLg==" },
- { "They say that nurses sometimes carry scalpels and never use them.",
- "VGhleSBzYXkgdGhhdCBudXJzZXMgc29tZXRpbWVzIGNhcnJ5IHNjYWxwZWxzIGFuZCBuZXZlciB1c2UgdGhlbS4=" },
- { "They say that once you've met one wizard you've met them all.",
- "VGhleSBzYXkgdGhhdCBvbmNlIHlvdSd2ZSBtZXQgb25lIHdpemFyZCB5b3UndmUgbWV0IHRoZW0gYWxsLg==" },
- { "They say that one troll is worth 10,000 newts.",
- "VGhleSBzYXkgdGhhdCBvbmUgdHJvbGwgaXMgd29ydGggMTAsMDAwIG5ld3RzLg==" },
- { "They say that only David can find the zoo!",
- "VGhleSBzYXkgdGhhdCBvbmx5IERhdmlkIGNhbiBmaW5kIHRoZSB6b28h" },
- { "They say that only angels play their harps for their pets.",
- "VGhleSBzYXkgdGhhdCBvbmx5IGFuZ2VscyBwbGF5IHRoZWlyIGhhcnBzIGZvciB0aGVpciBwZXRzLg==" },
- { "They say that only big spenders carry gold.",
- "VGhleSBzYXkgdGhhdCBvbmx5IGJpZyBzcGVuZGVycyBjYXJyeSBnb2xkLg==" },
- { "They say that orc shamans are healthy, wealthy and wise.",
- "VGhleSBzYXkgdGhhdCBvcmMgc2hhbWFucyBhcmUgaGVhbHRoeSwgd2VhbHRoeSBhbmQgd2lzZS4=" },
- { "They say that playing NetHack is like walking into a death trap.",
- "VGhleSBzYXkgdGhhdCBwbGF5aW5nIE5ldEhhY2sgaXMgbGlrZSB3YWxraW5nIGludG8gYSBkZWF0aCB0cmFwLg==" },
- { "They say that problem breathing is best treated by a proper diet.",
- "VGhleSBzYXkgdGhhdCBwcm9ibGVtIGJyZWF0aGluZyBpcyBiZXN0IHRyZWF0ZWQgYnkgYSBwcm9wZXIgZGlldC4=" },
- { "They say that quaffing many potions of levitation can give you a headache.",
- "VGhleSBzYXkgdGhhdCBxdWFmZmluZyBtYW55IHBvdGlvbnMgb2YgbGV2aXRhdGlvbiBjYW4gZ2l2ZSB5b3UgYSBoZWFkYWNoZS4=" },
- { "They say that queen bees get that way by eating royal jelly.",
- "VGhleSBzYXkgdGhhdCBxdWVlbiBiZWVzIGdldCB0aGF0IHdheSBieSBlYXRpbmcgcm95YWwgamVsbHku" },
- { "They say that reading a scare monster scroll is the same as saying Elbereth.",
- "VGhleSBzYXkgdGhhdCByZWFkaW5nIGEgc2NhcmUgbW9uc3RlciBzY3JvbGwgaXMgdGhlIHNhbWUgYXMgc2F5aW5nIEVsYmVyZXRoLg==" },
- { "They say that real hackers always are controlled.",
- "VGhleSBzYXkgdGhhdCByZWFsIGhhY2tlcnMgYWx3YXlzIGFyZSBjb250cm9sbGVkLg==" },
- { "They say that real hackers never sleep.",
- "VGhleSBzYXkgdGhhdCByZWFsIGhhY2tlcnMgbmV2ZXIgc2xlZXAu" },
- { "They say that shopkeepers are insured by Croesus himself!",
- "VGhleSBzYXkgdGhhdCBzaG9wa2VlcGVycyBhcmUgaW5zdXJlZCBieSBDcm9lc3VzIGhpbXNlbGYh" },
- { "They say that shopkeepers never carry more than 20 gold pieces, at night.",
- "VGhleSBzYXkgdGhhdCBzaG9wa2VlcGVycyBuZXZlciBjYXJyeSBtb3JlIHRoYW4gMjAgZ29sZCBwaWVjZXMsIGF0IG5pZ2h0Lg==" },
- { "They say that shopkeepers never sell blessed potions of invisibility.",
- "VGhleSBzYXkgdGhhdCBzaG9wa2VlcGVycyBuZXZlciBzZWxsIGJsZXNzZWQgcG90aW9ucyBvZiBpbnZpc2liaWxpdHku" },
- { "They say that soldiers wear kid gloves and silly helmets.",
- "VGhleSBzYXkgdGhhdCBzb2xkaWVycyB3ZWFyIGtpZCBnbG92ZXMgYW5kIHNpbGx5IGhlbG1ldHMu" },
- { "They say that some Kops are on the take.",
- "VGhleSBzYXkgdGhhdCBzb21lIEtvcHMgYXJlIG9uIHRoZSB0YWtlLg==" },
- { "They say that some guards' palms can be greased.",
- "VGhleSBzYXkgdGhhdCBzb21lIGd1YXJkcycgcGFsbXMgY2FuIGJlIGdyZWFzZWQu" },
- { "They say that some monsters may kiss your boots to stop your drum playing.",
- "VGhleSBzYXkgdGhhdCBzb21lIG1vbnN0ZXJzIG1heSBraXNzIHlvdXIgYm9vdHMgdG8gc3RvcCB5b3VyIGRydW0gcGxheWluZy4=" },
- { "They say that sometimes you can be the hit of the party when playing a horn.",
- "VGhleSBzYXkgdGhhdCBzb21ldGltZXMgeW91IGNhbiBiZSB0aGUgaGl0IG9mIHRoZSBwYXJ0eSB3aGVuIHBsYXlpbmcgYSBob3JuLg==" },
- { "They say that the NetHack gods generally welcome your sacrifices.",
- "VGhleSBzYXkgdGhhdCB0aGUgTmV0SGFjayBnb2RzIGdlbmVyYWxseSB3ZWxjb21lIHlvdXIgc2FjcmlmaWNlcy4=" },
- { "They say that the Three Rings are named Vilya, Nenya and Narya.",
- "VGhleSBzYXkgdGhhdCB0aGUgVGhyZWUgUmluZ3MgYXJlIG5hbWVkIFZpbHlhLCBOZW55YSBhbmQgTmFyeWEu" },
- { "They say that the Wizard of Yendor has a death wish.",
- "VGhleSBzYXkgdGhhdCB0aGUgV2l6YXJkIG9mIFllbmRvciBoYXMgYSBkZWF0aCB3aXNoLg==" },
- { "They say that the `hair of the dog' is sometimes an effective remedy.",
- "VGhleSBzYXkgdGhhdCB0aGUgYGhhaXIgb2YgdGhlIGRvZycgaXMgc29tZXRpbWVzIGFuIGVmZmVjdGl2ZSByZW1lZHku" },
- { "They say that the best time to save your game is now before its too late.",
- "VGhleSBzYXkgdGhhdCB0aGUgYmVzdCB0aW1lIHRvIHNhdmUgeW91ciBnYW1lIGlzIG5vdyBiZWZvcmUgaXRzIHRvbyBsYXRlLg==" },
- { "They say that the biggest obstacle in NetHack is your mind.",
- "VGhleSBzYXkgdGhhdCB0aGUgYmlnZ2VzdCBvYnN0YWNsZSBpbiBOZXRIYWNrIGlzIHlvdXIgbWluZC4=" },
- { "They say that the gods are angry when they hit you with objects.",
- "VGhleSBzYXkgdGhhdCB0aGUgZ29kcyBhcmUgYW5ncnkgd2hlbiB0aGV5IGhpdCB5b3Ugd2l0aCBvYmplY3RzLg==" },
- { "They say that the priesthood are specially favored by the gods.",
- "VGhleSBzYXkgdGhhdCB0aGUgcHJpZXN0aG9vZCBhcmUgc3BlY2lhbGx5IGZhdm9yZWQgYnkgdGhlIGdvZHMu" },
- { "They say that the way to make a unicorn happy is to give it what it wants.",
- "VGhleSBzYXkgdGhhdCB0aGUgd2F5IHRvIG1ha2UgYSB1bmljb3JuIGhhcHB5IGlzIHRvIGdpdmUgaXQgd2hhdCBpdCB3YW50cy4=" },
- { "They say that there are no black or white stones, only gray.",
- "VGhleSBzYXkgdGhhdCB0aGVyZSBhcmUgbm8gYmxhY2sgb3Igd2hpdGUgc3RvbmVzLCBvbmx5IGdyYXku" },
- { "They say that there are no skeletons hence there are no skeleton keys.",
- "VGhleSBzYXkgdGhhdCB0aGVyZSBhcmUgbm8gc2tlbGV0b25zIGhlbmNlIHRoZXJlIGFyZSBubyBza2VsZXRvbiBrZXlzLg==" },
- { "They say that there is a clever rogue in every hacker just dying to escape.",
- "VGhleSBzYXkgdGhhdCB0aGVyZSBpcyBhIGNsZXZlciByb2d1ZSBpbiBldmVyeSBoYWNrZXIganVzdCBkeWluZyB0byBlc2NhcGUu" },
- { "They say that there is no such thing as free advice.",
- "VGhleSBzYXkgdGhhdCB0aGVyZSBpcyBubyBzdWNoIHRoaW5nIGFzIGZyZWUgYWR2aWNlLg==" },
- { "They say that there is only one way to win at NetHack.",
- "VGhleSBzYXkgdGhhdCB0aGVyZSBpcyBvbmx5IG9uZSB3YXkgdG8gd2luIGF0IE5ldEhhY2su" },
- { "They say that there once was a fearsome chaotic samurai named Luk No.",
- "VGhleSBzYXkgdGhhdCB0aGVyZSBvbmNlIHdhcyBhIGZlYXJzb21lIGNoYW90aWMgc2FtdXJhaSBuYW1lZCBMdWsgTm8u" },
- { "They say that there was a time when cursed holy water wasn't water.",
- "VGhleSBzYXkgdGhhdCB0aGVyZSB3YXMgYSB0aW1lIHdoZW4gY3Vyc2VkIGhvbHkgd2F0ZXIgd2Fzbid0IHdhdGVyLg==" },
- { "They say that there's no point in crying over a gray ooze.",
- "VGhleSBzYXkgdGhhdCB0aGVyZSdzIG5vIHBvaW50IGluIGNyeWluZyBvdmVyIGEgZ3JheSBvb3plLg==" },
- { "They say that there's only hope left after you've opened Pandora's box.",
- "VGhleSBzYXkgdGhhdCB0aGVyZSdzIG9ubHkgaG9wZSBsZWZ0IGFmdGVyIHlvdSd2ZSBvcGVuZWQgUGFuZG9yYSdzIGJveC4=" },
- { "They say that trapdoors should always be marked `Caution: Trap Door'.",
- "VGhleSBzYXkgdGhhdCB0cmFwZG9vcnMgc2hvdWxkIGFsd2F5cyBiZSBtYXJrZWQgYENhdXRpb246IFRyYXAgRG9vcicu" },
- { "They say that using an amulet of change isn't a difficult operation.",
- "VGhleSBzYXkgdGhhdCB1c2luZyBhbiBhbXVsZXQgb2YgY2hhbmdlIGlzbid0IGEgZGlmZmljdWx0IG9wZXJhdGlvbi4=" },
- { "They say that water walking boots are better if you are fast like Hermes.",
- "VGhleSBzYXkgdGhhdCB3YXRlciB3YWxraW5nIGJvb3RzIGFyZSBiZXR0ZXIgaWYgeW91IGFyZSBmYXN0IGxpa2UgSGVybWVzLg==" },
- { "They say that when you wear a circular amulet you might resemble a troll.",
- "VGhleSBzYXkgdGhhdCB3aGVuIHlvdSB3ZWFyIGEgY2lyY3VsYXIgYW11bGV0IHlvdSBtaWdodCByZXNlbWJsZSBhIHRyb2xsLg==" },
- { "They say that when you're hungry you can get a pizza in 30 moves or it's free.",
- "VGhleSBzYXkgdGhhdCB3aGVuIHlvdSdyZSBodW5ncnkgeW91IGNhbiBnZXQgYSBwaXp6YSBpbiAzMCBtb3ZlcyBvciBpdCdzIGZyZWUu" },
- { "They say that when your god is angry you should try another one.",
- "VGhleSBzYXkgdGhhdCB3aGVuIHlvdXIgZ29kIGlzIGFuZ3J5IHlvdSBzaG91bGQgdHJ5IGFub3RoZXIgb25lLg==" },
- { "They say that wielding a unicorn horn takes strength.",
- "VGhleSBzYXkgdGhhdCB3aWVsZGluZyBhIHVuaWNvcm4gaG9ybiB0YWtlcyBzdHJlbmd0aC4=" },
- { "They say that with speed boots you never worry about hit and run accidents.",
- "VGhleSBzYXkgdGhhdCB3aXRoIHNwZWVkIGJvb3RzIHlvdSBuZXZlciB3b3JyeSBhYm91dCBoaXQgYW5kIHJ1biBhY2NpZGVudHMu" },
- { "They say that you can defeat a killer bee with a unicorn horn.",
- "VGhleSBzYXkgdGhhdCB5b3UgY2FuIGRlZmVhdCBhIGtpbGxlciBiZWUgd2l0aCBhIHVuaWNvcm4gaG9ybi4=" },
- { "They say that you can only cross the River Styx in Charon's boat.",
- "VGhleSBzYXkgdGhhdCB5b3UgY2FuIG9ubHkgY3Jvc3MgdGhlIFJpdmVyIFN0eXggaW4gQ2hhcm9uJ3MgYm9hdC4=" },
- { "They say that you can only kill a lich once and then you'd better be careful.",
- "VGhleSBzYXkgdGhhdCB5b3UgY2FuIG9ubHkga2lsbCBhIGxpY2ggb25jZSBhbmQgdGhlbiB5b3UnZCBiZXR0ZXIgYmUgY2FyZWZ1bC4=" },
- { "They say that you can only wish for things you've already had.",
- "VGhleSBzYXkgdGhhdCB5b3UgY2FuIG9ubHkgd2lzaCBmb3IgdGhpbmdzIHlvdSd2ZSBhbHJlYWR5IGhhZC4=" },
- { "They say that you can train a cat by talking gently to it.",
- "VGhleSBzYXkgdGhhdCB5b3UgY2FuIHRyYWluIGEgY2F0IGJ5IHRhbGtpbmcgZ2VudGx5IHRvIGl0Lg==" },
- { "They say that you can train a dog by talking firmly to it.",
- "VGhleSBzYXkgdGhhdCB5b3UgY2FuIHRyYWluIGEgZG9nIGJ5IHRhbGtpbmcgZmlybWx5IHRvIGl0Lg==" },
- { "They say that you can trust your gold with the king.",
- "VGhleSBzYXkgdGhhdCB5b3UgY2FuIHRydXN0IHlvdXIgZ29sZCB3aXRoIHRoZSBraW5nLg==" },
- { "They say that you can't wipe your greasy bare hands on a blank scroll.",
- "VGhleSBzYXkgdGhhdCB5b3UgY2FuJ3Qgd2lwZSB5b3VyIGdyZWFzeSBiYXJlIGhhbmRzIG9uIGEgYmxhbmsgc2Nyb2xsLg==" },
- { "They say that you cannot trust scrolls of rumor.",
- "VGhleSBzYXkgdGhhdCB5b3UgY2Fubm90IHRydXN0IHNjcm9sbHMgb2YgcnVtb3Iu" },
- { "They say that you could fall head over heels for an energy vortex.",
- "VGhleSBzYXkgdGhhdCB5b3UgY291bGQgZmFsbCBoZWFkIG92ZXIgaGVlbHMgZm9yIGFuIGVuZXJneSB2b3J0ZXgu" },
- { "They say that you need a key in order to open locked doors.",
- "VGhleSBzYXkgdGhhdCB5b3UgbmVlZCBhIGtleSBpbiBvcmRlciB0byBvcGVuIGxvY2tlZCBkb29ycy4=" },
- { "They say that you need a mirror to notice a mimic in an antique shop.",
- "VGhleSBzYXkgdGhhdCB5b3UgbmVlZCBhIG1pcnJvciB0byBub3RpY2UgYSBtaW1pYyBpbiBhbiBhbnRpcXVlIHNob3Au" },
- { "They say that you really can use a pick-axe unless you really can't.",
- "VGhleSBzYXkgdGhhdCB5b3UgcmVhbGx5IGNhbiB1c2UgYSBwaWNrLWF4ZSB1bmxlc3MgeW91IHJlYWxseSBjYW4ndC4=" },
- { "They say that you should always store your tools in the cellar.",
- "VGhleSBzYXkgdGhhdCB5b3Ugc2hvdWxkIGFsd2F5cyBzdG9yZSB5b3VyIHRvb2xzIGluIHRoZSBjZWxsYXIu" },
- { "They say that you should be careful while climbing the ladder to success.",
- "VGhleSBzYXkgdGhhdCB5b3Ugc2hvdWxkIGJlIGNhcmVmdWwgd2hpbGUgY2xpbWJpbmcgdGhlIGxhZGRlciB0byBzdWNjZXNzLg==" },
- { "They say that you should call your armor `rustproof'.",
- "VGhleSBzYXkgdGhhdCB5b3Ugc2hvdWxkIGNhbGwgeW91ciBhcm1vciBgcnVzdHByb29mJy4=" },
- { "They say that you should name your dog Spuds to have a cool pet.",
- "VGhleSBzYXkgdGhhdCB5b3Ugc2hvdWxkIG5hbWUgeW91ciBkb2cgU3B1ZHMgdG8gaGF2ZSBhIGNvb2wgcGV0Lg==" },
- { "They say that you should name your weapon after your first monster kill.",
- "VGhleSBzYXkgdGhhdCB5b3Ugc2hvdWxkIG5hbWUgeW91ciB3ZWFwb24gYWZ0ZXIgeW91ciBmaXJzdCBtb25zdGVyIGtpbGwu" },
- { "They say that you should never introduce a rope golem to a succubus.",
- "VGhleSBzYXkgdGhhdCB5b3Ugc2hvdWxkIG5ldmVyIGludHJvZHVjZSBhIHJvcGUgZ29sZW0gdG8gYSBzdWNjdWJ1cy4=" },
- { "They say that you should never sleep near invisible ring wraiths.",
- "VGhleSBzYXkgdGhhdCB5b3Ugc2hvdWxkIG5ldmVyIHNsZWVwIG5lYXIgaW52aXNpYmxlIHJpbmcgd3JhaXRocy4=" },
- { "They say that you should never try to leave the dungeon with a bag of gems.",
- "VGhleSBzYXkgdGhhdCB5b3Ugc2hvdWxkIG5ldmVyIHRyeSB0byBsZWF2ZSB0aGUgZHVuZ2VvbiB3aXRoIGEgYmFnIG9mIGdlbXMu" },
- { "They say that you should remove your armor before sitting on a throne.",
- "VGhleSBzYXkgdGhhdCB5b3Ugc2hvdWxkIHJlbW92ZSB5b3VyIGFybW9yIGJlZm9yZSBzaXR0aW5nIG9uIGEgdGhyb25lLg==" },
- { "This fortune cookie is copy protected.",
- "VGhpcyBmb3J0dW5lIGNvb2tpZSBpcyBjb3B5IHByb3RlY3RlZC4=" },
- { "This fortune cookie is the property of Fortune Cookies, Inc.",
- "VGhpcyBmb3J0dW5lIGNvb2tpZSBpcyB0aGUgcHJvcGVydHkgb2YgRm9ydHVuZSBDb29raWVzLCBJbmMu" },
- { "Tired? Try a scroll of charging on yourself.",
- "VGlyZWQ/IFRyeSBhIHNjcm9sbCBvZiBjaGFyZ2luZyBvbiB5b3Vyc2VsZi4=" },
- { "To achieve the next higher rating, you need 3 more points.",
- "VG8gYWNoaWV2ZSB0aGUgbmV4dCBoaWdoZXIgcmF0aW5nLCB5b3UgbmVlZCAzIG1vcmUgcG9pbnRzLg==" },
- { "To reach heaven, escape the dungeon while wearing a ring of levitation.",
- "VG8gcmVhY2ggaGVhdmVuLCBlc2NhcGUgdGhlIGR1bmdlb24gd2hpbGUgd2VhcmluZyBhIHJpbmcgb2YgbGV2aXRhdGlvbi4=" },
- { "Tourists wear shirts loud enough to wake the dead.",
- "VG91cmlzdHMgd2VhciBzaGlydHMgbG91ZCBlbm91Z2ggdG8gd2FrZSB0aGUgZGVhZC4=" },
- { "Try calling your katana Moulinette.",
- "VHJ5IGNhbGxpbmcgeW91ciBrYXRhbmEgTW91bGluZXR0ZS4=" },
- { "Ulch! That meat was painted!",
- "VWxjaCEgVGhhdCBtZWF0IHdhcyBwYWludGVkIQ==" },
- { "Unfortunately, this message was left intentionally blank.",
- "VW5mb3J0dW5hdGVseSwgdGhpcyBtZXNzYWdlIHdhcyBsZWZ0IGludGVudGlvbmFsbHkgYmxhbmsu" },
- { "Using a morning star in the evening has no effect.",
- "VXNpbmcgYSBtb3JuaW5nIHN0YXIgaW4gdGhlIGV2ZW5pbmcgaGFzIG5vIGVmZmVjdC4=" },
- { "Want a hint? Zap a wand of make invisible on your weapon!",
- "V2FudCBhIGhpbnQ/IFphcCBhIHdhbmQgb2YgbWFrZSBpbnZpc2libGUgb24geW91ciB3ZWFwb24h" },
- { "Want to ascend in a hurry? Apply at Gizmonic Institute.",
- "V2FudCB0byBhc2NlbmQgaW4gYSBodXJyeT8gQXBwbHkgYXQgR2l6bW9uaWMgSW5zdGl0dXRlLg==" },
- { "Wanted: shopkeepers. Send a scroll of mail to Mage of Yendor/Level 35/Dungeon.",
- "V2FudGVkOiBzaG9wa2VlcGVycy4gU2VuZCBhIHNjcm9sbCBvZiBtYWlsIHRvIE1hZ2Ugb2YgWWVuZG9yL0xldmVsIDM1L0R1bmdlb24u" },
- { "Warning: fortune reading can be hazardous to your health.",
- "V2FybmluZzogZm9ydHVuZSByZWFkaW5nIGNhbiBiZSBoYXphcmRvdXMgdG8geW91ciBoZWFsdGgu" },
- { "We have new ways of detecting treachery...",
- "V2UgaGF2ZSBuZXcgd2F5cyBvZiBkZXRlY3RpbmcgdHJlYWNoZXJ5Li4u" },
- { "Wet towels make great weapons!",
- "V2V0IHRvd2VscyBtYWtlIGdyZWF0IHdlYXBvbnMh" },
- { "What a pity, you cannot read it!",
- "V2hhdCBhIHBpdHksIHlvdSBjYW5ub3QgcmVhZCBpdCE=" },
- { "When a piercer drops in on you, you will be tempted to hit the ceiling!",
- "V2hlbiBhIHBpZXJjZXIgZHJvcHMgaW4gb24geW91LCB5b3Ugd2lsbCBiZSB0ZW1wdGVkIHRvIGhpdCB0aGUgY2VpbGluZyE=" },
- { "When in a maze follow the right wall and you will never get lost.",
- "V2hlbiBpbiBhIG1hemUgZm9sbG93IHRoZSByaWdodCB3YWxsIGFuZCB5b3Ugd2lsbCBuZXZlciBnZXQgbG9zdC4=" },
- { "When you have a key, you don't have to wait for the guard.",
- "V2hlbiB5b3UgaGF2ZSBhIGtleSwgeW91IGRvbid0IGhhdmUgdG8gd2FpdCBmb3IgdGhlIGd1YXJkLg==" },
- { "Why are you wasting time reading fortunes?",
- "V2h5IGFyZSB5b3Ugd2FzdGluZyB0aW1lIHJlYWRpbmcgZm9ydHVuZXM/" },
- { "Wish for a master key and open the Magic Memory Vault!",
- "V2lzaCBmb3IgYSBtYXN0ZXIga2V5IGFuZCBvcGVuIHRoZSBNYWdpYyBNZW1vcnkgVmF1bHQh" },
- { "Wizard expects every monster to do its duty.",
- "V2l6YXJkIGV4cGVjdHMgZXZlcnkgbW9uc3RlciB0byBkbyBpdHMgZHV0eS4=" },
- { "Wow! You could've had a potion of fruit juice!",
- "V293ISBZb3UgY291bGQndmUgaGFkIGEgcG90aW9uIG9mIGZydWl0IGp1aWNlIQ==" },
- { "Yet Another Silly Message (YASM).",
- "WWV0IEFub3RoZXIgU2lsbHkgTWVzc2FnZSAoWUFTTSku" },
- { "You are destined to be misled by a fortune.",
- "WW91IGFyZSBkZXN0aW5lZCB0byBiZSBtaXNsZWQgYnkgYSBmb3J0dW5lLg==" },
- { "You can get a genuine Amulet of Yendor by doing the following: --More--",
- "WW91IGNhbiBnZXQgYSBnZW51aW5lIEFtdWxldCBvZiBZZW5kb3IgYnkgZG9pbmcgdGhlIGZvbGxvd2luZzogLS1Nb3JlLS0=" },
- { "You can protect yourself from black dragons by doing the following: --More--",
- "WW91IGNhbiBwcm90ZWN0IHlvdXJzZWxmIGZyb20gYmxhY2sgZHJhZ29ucyBieSBkb2luZyB0aGUgZm9sbG93aW5nOiAtLU1vcmUtLQ==" },
- { "You can't get by the snake.",
- "WW91IGNhbid0IGdldCBieSB0aGUgc25ha2Uu" },
- { "You feel like someone is pulling your leg.",
- "WW91IGZlZWwgbGlrZSBzb21lb25lIGlzIHB1bGxpbmcgeW91ciBsZWcu" },
- { "You have to outwit the Sphynx or pay her.",
- "WW91IGhhdmUgdG8gb3V0d2l0IHRoZSBTcGh5bnggb3IgcGF5IGhlci4=" },
- { "You hear the fortune cookie's hissing!",
- "WW91IGhlYXIgdGhlIGZvcnR1bmUgY29va2llJ3MgaGlzc2luZyE=" },
- { "You may get rich selling letters, but beware of being blackmailed!",
- "WW91IG1heSBnZXQgcmljaCBzZWxsaW5nIGxldHRlcnMsIGJ1dCBiZXdhcmUgb2YgYmVpbmcgYmxhY2ttYWlsZWQh" },
- { "You offend Shai-Hulud by sheathing your crysknife without having drawn blood.",
- "WW91IG9mZmVuZCBTaGFpLUh1bHVkIGJ5IHNoZWF0aGluZyB5b3VyIGNyeXNrbmlmZSB3aXRob3V0IGhhdmluZyBkcmF3biBibG9vZC4=" },
- { "You swallowed the fortune!",
- "WW91IHN3YWxsb3dlZCB0aGUgZm9ydHVuZSE=" },
- { "You want to regain strength? Two levels ahead is a guesthouse!",
- "WW91IHdhbnQgdG8gcmVnYWluIHN0cmVuZ3RoPyBUd28gbGV2ZWxzIGFoZWFkIGlzIGEgZ3Vlc3Rob3VzZSE=" },
- { "You will encounter a tall, dark, and gruesome creature...",
- "WW91IHdpbGwgZW5jb3VudGVyIGEgdGFsbCwgZGFyaywgYW5kIGdydWVzb21lIGNyZWF0dXJlLi4u" },
-
- { "The End", "VGhlIEVuZA==" }
- };
+static struct
+{
+ const char *plaintext;
+ const char *cyphertext;
+} array[] =
+{
+ /* Cyphertexts generated with uuenview 0.5.13 */
+ { " ", "IA==" },
+ { ".", "Lg==" },
+ { "/", "Lw==" },
+ { "C", "Qw==" },
+ { "H", "SA==" },
+ { "S", "Uw==" },
+ { "^", "Xg==" },
+ { "a", "YQ==" },
+ { "o", "bw==" },
+ { "t", "dA==" },
+
+ { "AB", "QUI=" },
+ { "AH", "QUg=" },
+ { "AQ", "QVE=" },
+ { "BD", "QkQ=" },
+ { "CR", "Q1I=" },
+ { "CS", "Q1M=" },
+ { "DB", "REI=" },
+ { "DC", "REM=" },
+ { "EK", "RUs=" },
+ { "ET", "RVQ=" },
+ { "IM", "SU0=" },
+ { "JR", "SlI=" },
+ { "LO", "TE8=" },
+ { "LW", "TFc=" },
+ { "ML", "TUw=" },
+ { "SB", "U0I=" },
+ { "TO", "VE8=" },
+ { "VS", "VlM=" },
+ { "WP", "V1A=" },
+ /* legitimate two-letter words */
+ { "ad", "YWQ=" },
+ { "ah", "YWg=" },
+ { "am", "YW0=" },
+ { "an", "YW4=" },
+ { "as", "YXM=" },
+ { "at", "YXQ=" },
+ { "ax", "YXg=" },
+ { "be", "YmU=" },
+ { "by", "Ynk=" },
+ { "do", "ZG8=" },
+ { "go", "Z28=" },
+ { "he", "aGU=" },
+ { "hi", "aGk=" },
+ { "if", "aWY=" },
+ { "in", "aW4=" },
+ { "is", "aXM=" },
+ { "it", "aXQ=" },
+ { "me", "bWU=" },
+ { "my", "bXk=" },
+ { "no", "bm8=" },
+ { "of", "b2Y=" },
+ { "on", "b24=" },
+ { "or", "b3I=" },
+ { "ox", "b3g=" },
+ { "so", "c28=" },
+ { "to", "dG8=" },
+ { "up", "dXA=" },
+ { "us", "dXM=" },
+ { "we", "d2U=" },
+ /* all three-letter entries in /usr/dict/words */
+ { "1st", "MXN0" },
+ { "2nd", "Mm5k" },
+ { "3rd", "M3Jk" },
+ { "4th", "NHRo" },
+ { "5th", "NXRo" },
+ { "6th", "NnRo" },
+ { "7th", "N3Ro" },
+ { "8th", "OHRo" },
+ { "9th", "OXRo" },
+ { "AAA", "QUFB" },
+ { "AAU", "QUFV" },
+ { "ABA", "QUJB" },
+ { "abc", "YWJj" },
+ { "Abe", "QWJl" },
+ { "Abo", "QWJv" },
+ { "ace", "YWNl" },
+ { "ACM", "QUNN" },
+ { "ACS", "QUNT" },
+ { "act", "YWN0" },
+ { "Ada", "QWRh" },
+ { "add", "YWRk" },
+ { "ado", "YWRv" },
+ { "aft", "YWZ0" },
+ { "age", "YWdl" },
+ { "ago", "YWdv" },
+ { "aid", "YWlk" },
+ { "ail", "YWls" },
+ { "aim", "YWlt" },
+ { "air", "YWly" },
+ { "ala", "YWxh" },
+ { "alb", "YWxi" },
+ { "ale", "YWxl" },
+ { "Ali", "QWxp" },
+ { "all", "YWxs" },
+ { "alp", "YWxw" },
+ { "A&M", "QSZN" },
+ { "AMA", "QU1B" },
+ { "ami", "YW1p" },
+ { "amp", "YW1w" },
+ { "Amy", "QW15" },
+ { "amy", "YW15" },
+ { "ana", "YW5h" },
+ { "and", "YW5k" },
+ { "ani", "YW5p" },
+ { "Ann", "QW5u" },
+ { "ant", "YW50" },
+ { "any", "YW55" },
+ { "A&P", "QSZQ" },
+ { "ape", "YXBl" },
+ { "Apr", "QXBy" },
+ { "APS", "QVBT" },
+ { "apt", "YXB0" },
+ { "arc", "YXJj" },
+ { "are", "YXJl" },
+ { "ark", "YXJr" },
+ { "arm", "YXJt" },
+ { "art", "YXJ0" },
+ { "a's", "YSdz" },
+ { "ash", "YXNo" },
+ { "ask", "YXNr" },
+ { "ass", "YXNz" },
+ { "ate", "YXRl" },
+ { "Aug", "QXVn" },
+ { "auk", "YXVr" },
+ { "Ave", "QXZl" },
+ { "awe", "YXdl" },
+ { "awl", "YXds" },
+ { "awn", "YXdu" },
+ { "axe", "YXhl" },
+ { "aye", "YXll" },
+ { "bad", "YmFk" },
+ { "bag", "YmFn" },
+ { "bah", "YmFo" },
+ { "bam", "YmFt" },
+ { "ban", "YmFu" },
+ { "bar", "YmFy" },
+ { "bat", "YmF0" },
+ { "bay", "YmF5" },
+ { "bed", "YmVk" },
+ { "bee", "YmVl" },
+ { "beg", "YmVn" },
+ { "bel", "YmVs" },
+ { "Ben", "QmVu" },
+ { "bet", "YmV0" },
+ { "bey", "YmV5" },
+ { "bib", "Ymli" },
+ { "bid", "Ymlk" },
+ { "big", "Ymln" },
+ { "bin", "Ymlu" },
+ { "bit", "Yml0" },
+ { "biz", "Yml6" },
+ { "BMW", "Qk1X" },
+ { "boa", "Ym9h" },
+ { "bob", "Ym9i" },
+ { "bog", "Ym9n" },
+ { "bon", "Ym9u" },
+ { "boo", "Ym9v" },
+ { "bop", "Ym9w" },
+ { "bow", "Ym93" },
+ { "box", "Ym94" },
+ { "boy", "Ym95" },
+ { "b's", "Yidz" },
+ { "BTL", "QlRM" },
+ { "BTU", "QlRV" },
+ { "bub", "YnVi" },
+ { "bud", "YnVk" },
+ { "bug", "YnVn" },
+ { "bum", "YnVt" },
+ { "bun", "YnVu" },
+ { "bus", "YnVz" },
+ { "but", "YnV0" },
+ { "buy", "YnV5" },
+ { "bye", "Ynll" },
+ { "cab", "Y2Fi" },
+ { "Cal", "Q2Fs" },
+ { "cam", "Y2Ft" },
+ { "can", "Y2Fu" },
+ { "cap", "Y2Fw" },
+ { "car", "Y2Fy" },
+ { "cat", "Y2F0" },
+ { "caw", "Y2F3" },
+ { "CBS", "Q0JT" },
+ { "CDC", "Q0RD" },
+ { "CEQ", "Q0VR" },
+ { "chi", "Y2hp" },
+ { "CIA", "Q0lB" },
+ { "cit", "Y2l0" },
+ { "cod", "Y29k" },
+ { "cog", "Y29n" },
+ { "col", "Y29s" },
+ { "con", "Y29u" },
+ { "coo", "Y29v" },
+ { "cop", "Y29w" },
+ { "cos", "Y29z" },
+ { "cot", "Y290" },
+ { "cow", "Y293" },
+ { "cox", "Y294" },
+ { "coy", "Y295" },
+ { "CPA", "Q1BB" },
+ { "cpu", "Y3B1" },
+ { "CRT", "Q1JU" },
+ { "cry", "Y3J5" },
+ { "c's", "Yydz" },
+ { "cub", "Y3Vi" },
+ { "cud", "Y3Vk" },
+ { "cue", "Y3Vl" },
+ { "cup", "Y3Vw" },
+ { "cur", "Y3Vy" },
+ { "cut", "Y3V0" },
+ { "dab", "ZGFi" },
+ { "dad", "ZGFk" },
+ { "dam", "ZGFt" },
+ { "Dan", "RGFu" },
+ { "Dar", "RGFy" },
+ { "day", "ZGF5" },
+ { "Dec", "RGVj" },
+ { "Dee", "RGVl" },
+ { "Del", "RGVs" },
+ { "den", "ZGVu" },
+ { "Des", "RGVz" },
+ { "dew", "ZGV3" },
+ { "dey", "ZGV5" },
+ { "did", "ZGlk" },
+ { "die", "ZGll" },
+ { "dig", "ZGln" },
+ { "dim", "ZGlt" },
+ { "din", "ZGlu" },
+ { "dip", "ZGlw" },
+ { "Dis", "RGlz" },
+ { "DNA", "RE5B" },
+ { "DOD", "RE9E" },
+ { "doe", "ZG9l" },
+ { "dog", "ZG9n" },
+ { "don", "ZG9u" },
+ { "dot", "ZG90" },
+ { "Dow", "RG93" },
+ { "dry", "ZHJ5" },
+ { "d's", "ZCdz" },
+ { "dub", "ZHVi" },
+ { "dud", "ZHVk" },
+ { "due", "ZHVl" },
+ { "dug", "ZHVn" },
+ { "dun", "ZHVu" },
+ { "dye", "ZHll" },
+ { "ear", "ZWFy" },
+ { "eat", "ZWF0" },
+ { "ebb", "ZWJi" },
+ { "EDT", "RURU" },
+ { "eel", "ZWVs" },
+ { "eft", "ZWZ0" },
+ { "e.g", "ZS5n" },
+ { "egg", "ZWdn" },
+ { "ego", "ZWdv" },
+ { "eke", "ZWtl" },
+ { "Eli", "RWxp" },
+ { "elk", "ZWxr" },
+ { "ell", "ZWxs" },
+ { "elm", "ZWxt" },
+ { "Ely", "RWx5" },
+ { "end", "ZW5k" },
+ { "Eng", "RW5n" },
+ { "EPA", "RVBB" },
+ { "era", "ZXJh" },
+ { "ere", "ZXJl" },
+ { "erg", "ZXJn" },
+ { "err", "ZXJy" },
+ { "e's", "ZSdz" },
+ { "EST", "RVNU" },
+ { "eta", "ZXRh" },
+ { "etc", "ZXRj" },
+ { "Eva", "RXZh" },
+ { "eve", "ZXZl" },
+ { "ewe", "ZXdl" },
+ { "eye", "ZXll" },
+ { "FAA", "RkFB" },
+ { "fad", "ZmFk" },
+ { "fag", "ZmFn" },
+ { "fan", "ZmFu" },
+ { "far", "ZmFy" },
+ { "fat", "ZmF0" },
+ { "fay", "ZmF5" },
+ { "FBI", "RkJJ" },
+ { "FCC", "RkND" },
+ { "FDA", "RkRB" },
+ { "Feb", "RmVi" },
+ { "fed", "ZmVk" },
+ { "fee", "ZmVl" },
+ { "few", "ZmV3" },
+ { "fib", "Zmli" },
+ { "fig", "Zmln" },
+ { "fin", "Zmlu" },
+ { "fir", "Zmly" },
+ { "fit", "Zml0" },
+ { "fix", "Zml4" },
+ { "Flo", "Rmxv" },
+ { "flu", "Zmx1" },
+ { "fly", "Zmx5" },
+ { "FMC", "Rk1D" },
+ { "fob", "Zm9i" },
+ { "foe", "Zm9l" },
+ { "fog", "Zm9n" },
+ { "fop", "Zm9w" },
+ { "for", "Zm9y" },
+ { "fox", "Zm94" },
+ { "FPC", "RlBD" },
+ { "fro", "ZnJv" },
+ { "fry", "ZnJ5" },
+ { "f's", "Zidz" },
+ { "FTC", "RlRD" },
+ { "fum", "ZnVt" },
+ { "fun", "ZnVu" },
+ { "fur", "ZnVy" },
+ { "gab", "Z2Fi" },
+ { "gad", "Z2Fk" },
+ { "gag", "Z2Fn" },
+ { "gal", "Z2Fs" },
+ { "gam", "Z2Ft" },
+ { "GAO", "R0FP" },
+ { "gap", "Z2Fw" },
+ { "gar", "Z2Fy" },
+ { "gas", "Z2Fz" },
+ { "gay", "Z2F5" },
+ { "gee", "Z2Vl" },
+ { "gel", "Z2Vs" },
+ { "gem", "Z2Vt" },
+ { "get", "Z2V0" },
+ { "gig", "Z2ln" },
+ { "Gil", "R2ls" },
+ { "gin", "Z2lu" },
+ { "GMT", "R01U" },
+ { "GNP", "R05Q" },
+ { "gnu", "Z251" },
+ { "Goa", "R29h" },
+ { "gob", "Z29i" },
+ { "god", "Z29k" },
+ { "gog", "Z29n" },
+ { "GOP", "R09Q" },
+ { "got", "Z290" },
+ { "GPO", "R1BP" },
+ { "g's", "Zydz" },
+ { "GSA", "R1NB" },
+ { "gum", "Z3Vt" },
+ { "gun", "Z3Vu" },
+ { "Gus", "R3Vz" },
+ { "gut", "Z3V0" },
+ { "guy", "Z3V5" },
+ { "gym", "Z3lt" },
+ { "gyp", "Z3lw" },
+ { "had", "aGFk" },
+ { "Hal", "SGFs" },
+ { "ham", "aGFt" },
+ { "Han", "SGFu" },
+ { "hap", "aGFw" },
+ { "hat", "aGF0" },
+ { "haw", "aGF3" },
+ { "hay", "aGF5" },
+ { "hem", "aGVt" },
+ { "hen", "aGVu" },
+ { "her", "aGVy" },
+ { "hew", "aGV3" },
+ { "hex", "aGV4" },
+ { "hey", "aGV5" },
+ { "hid", "aGlk" },
+ { "him", "aGlt" },
+ { "hip", "aGlw" },
+ { "his", "aGlz" },
+ { "hit", "aGl0" },
+ { "hob", "aG9i" },
+ { "hoc", "aG9j" },
+ { "hoe", "aG9l" },
+ { "hog", "aG9n" },
+ { "hoi", "aG9p" },
+ { "Hom", "SG9t" },
+ { "hop", "aG9w" },
+ { "hot", "aG90" },
+ { "how", "aG93" },
+ { "hoy", "aG95" },
+ { "h's", "aCdz" },
+ { "hub", "aHVi" },
+ { "hue", "aHVl" },
+ { "hug", "aHVn" },
+ { "huh", "aHVo" },
+ { "hum", "aHVt" },
+ { "Hun", "SHVu" },
+ { "hut", "aHV0" },
+ { "Ian", "SWFu" },
+ { "IBM", "SUJN" },
+ { "Ibn", "SWJu" },
+ { "ICC", "SUND" },
+ { "ice", "aWNl" },
+ { "icy", "aWN5" },
+ { "I'd", "SSdk" },
+ { "Ida", "SWRh" },
+ { "i.e", "aS5l" },
+ { "iii", "aWlp" },
+ { "Ike", "SWtl" },
+ { "ill", "aWxs" },
+ { "I'm", "SSdt" },
+ { "imp", "aW1w" },
+ { "Inc", "SW5j" },
+ { "ink", "aW5r" },
+ { "inn", "aW5u" },
+ { "ion", "aW9u" },
+ { "Ira", "SXJh" },
+ { "ire", "aXJl" },
+ { "irk", "aXJr" },
+ { "IRS", "SVJT" },
+ { "i's", "aSdz" },
+ { "Ito", "SXRv" },
+ { "ITT", "SVRU" },
+ { "ivy", "aXZ5" },
+ { "jab", "amFi" },
+ { "jag", "amFn" },
+ { "jam", "amFt" },
+ { "Jan", "SmFu" },
+ { "jar", "amFy" },
+ { "jaw", "amF3" },
+ { "jay", "amF5" },
+ { "Jed", "SmVk" },
+ { "jet", "amV0" },
+ { "Jew", "SmV3" },
+ { "jig", "amln" },
+ { "Jim", "Smlt" },
+ { "job", "am9i" },
+ { "Joe", "Sm9l" },
+ { "jog", "am9n" },
+ { "Jon", "Sm9u" },
+ { "jot", "am90" },
+ { "joy", "am95" },
+ { "j's", "aidz" },
+ { "jug", "anVn" },
+ { "jut", "anV0" },
+ { "Kay", "S2F5" },
+ { "keg", "a2Vn" },
+ { "ken", "a2Vu" },
+ { "key", "a2V5" },
+ { "kid", "a2lk" },
+ { "Kim", "S2lt" },
+ { "kin", "a2lu" },
+ { "kit", "a2l0" },
+ { "k's", "aydz" },
+ { "lab", "bGFi" },
+ { "lac", "bGFj" },
+ { "lad", "bGFk" },
+ { "lag", "bGFn" },
+ { "lam", "bGFt" },
+ { "Lao", "TGFv" },
+ { "lap", "bGFw" },
+ { "law", "bGF3" },
+ { "lax", "bGF4" },
+ { "lay", "bGF5" },
+ { "lea", "bGVh" },
+ { "led", "bGVk" },
+ { "lee", "bGVl" },
+ { "leg", "bGVn" },
+ { "Len", "TGVu" },
+ { "Leo", "TGVv" },
+ { "let", "bGV0" },
+ { "Lev", "TGV2" },
+ { "Lew", "TGV3" },
+ { "lew", "bGV3" },
+ { "lid", "bGlk" },
+ { "lie", "bGll" },
+ { "lim", "bGlt" },
+ { "Lin", "TGlu" },
+ { "lip", "bGlw" },
+ { "lit", "bGl0" },
+ { "Liz", "TGl6" },
+ { "lob", "bG9i" },
+ { "log", "bG9n" },
+ { "lop", "bG9w" },
+ { "Los", "TG9z" },
+ { "lot", "bG90" },
+ { "Lou", "TG91" },
+ { "low", "bG93" },
+ { "loy", "bG95" },
+ { "l's", "bCdz" },
+ { "LSI", "TFNJ" },
+ { "Ltd", "THRk" },
+ { "LTV", "TFRW" },
+ { "lug", "bHVn" },
+ { "lux", "bHV4" },
+ { "lye", "bHll" },
+ { "Mac", "TWFj" },
+ { "mad", "bWFk" },
+ { "Mae", "TWFl" },
+ { "man", "bWFu" },
+ { "Mao", "TWFv" },
+ { "map", "bWFw" },
+ { "mar", "bWFy" },
+ { "mat", "bWF0" },
+ { "maw", "bWF3" },
+ { "Max", "TWF4" },
+ { "max", "bWF4" },
+ { "may", "bWF5" },
+ { "MBA", "TUJB" },
+ { "Meg", "TWVn" },
+ { "Mel", "TWVs" },
+ { "men", "bWVu" },
+ { "met", "bWV0" },
+ { "mew", "bWV3" },
+ { "mid", "bWlk" },
+ { "mig", "bWln" },
+ { "min", "bWlu" },
+ { "MIT", "TUlU" },
+ { "mix", "bWl4" },
+ { "mob", "bW9i" },
+ { "Moe", "TW9l" },
+ { "moo", "bW9v" },
+ { "mop", "bW9w" },
+ { "mot", "bW90" },
+ { "mow", "bW93" },
+ { "MPH", "TVBI" },
+ { "Mrs", "TXJz" },
+ { "m's", "bSdz" },
+ { "mud", "bXVk" },
+ { "mug", "bXVn" },
+ { "mum", "bXVt" },
+ { "nab", "bmFi" },
+ { "nag", "bmFn" },
+ { "Nan", "TmFu" },
+ { "nap", "bmFw" },
+ { "Nat", "TmF0" },
+ { "nay", "bmF5" },
+ { "NBC", "TkJD" },
+ { "NBS", "TkJT" },
+ { "NCO", "TkNP" },
+ { "NCR", "TkNS" },
+ { "Ned", "TmVk" },
+ { "nee", "bmVl" },
+ { "net", "bmV0" },
+ { "new", "bmV3" },
+ { "nib", "bmli" },
+ { "NIH", "TklI" },
+ { "nil", "bmls" },
+ { "nip", "bmlw" },
+ { "nit", "bml0" },
+ { "NNE", "Tk5F" },
+ { "NNW", "Tk5X" },
+ { "nob", "bm9i" },
+ { "nod", "bm9k" },
+ { "non", "bm9u" },
+ { "nor", "bm9y" },
+ { "not", "bm90" },
+ { "Nov", "Tm92" },
+ { "now", "bm93" },
+ { "NRC", "TlJD" },
+ { "n's", "bidz" },
+ { "NSF", "TlNG" },
+ { "nun", "bnVu" },
+ { "nut", "bnV0" },
+ { "NYC", "TllD" },
+ { "NYU", "TllV" },
+ { "oaf", "b2Fm" },
+ { "oak", "b2Fr" },
+ { "oar", "b2Fy" },
+ { "oat", "b2F0" },
+ { "Oct", "T2N0" },
+ { "odd", "b2Rk" },
+ { "ode", "b2Rl" },
+ { "off", "b2Zm" },
+ { "oft", "b2Z0" },
+ { "ohm", "b2ht" },
+ { "oil", "b2ls" },
+ { "old", "b2xk" },
+ { "one", "b25l" },
+ { "opt", "b3B0" },
+ { "orb", "b3Ji" },
+ { "ore", "b3Jl" },
+ { "Orr", "T3Jy" },
+ { "o's", "bydz" },
+ { "Ott", "T3R0" },
+ { "our", "b3Vy" },
+ { "out", "b3V0" },
+ { "ova", "b3Zh" },
+ { "owe", "b3dl" },
+ { "owl", "b3ds" },
+ { "own", "b3du" },
+ { "pad", "cGFk" },
+ { "pal", "cGFs" },
+ { "Pam", "UGFt" },
+ { "pan", "cGFu" },
+ { "pap", "cGFw" },
+ { "par", "cGFy" },
+ { "pat", "cGF0" },
+ { "paw", "cGF3" },
+ { "pax", "cGF4" },
+ { "pay", "cGF5" },
+ { "Paz", "UGF6" },
+ { "PBS", "UEJT" },
+ { "PDP", "UERQ" },
+ { "pea", "cGVh" },
+ { "pee", "cGVl" },
+ { "peg", "cGVn" },
+ { "pen", "cGVu" },
+ { "pep", "cGVw" },
+ { "per", "cGVy" },
+ { "pet", "cGV0" },
+ { "pew", "cGV3" },
+ { "PhD", "UGhE" },
+ { "phi", "cGhp" },
+ { "pie", "cGll" },
+ { "pig", "cGln" },
+ { "pin", "cGlu" },
+ { "pip", "cGlw" },
+ { "pit", "cGl0" },
+ { "ply", "cGx5" },
+ { "pod", "cG9k" },
+ { "Poe", "UG9l" },
+ { "poi", "cG9p" },
+ { "pol", "cG9s" },
+ { "pop", "cG9w" },
+ { "pot", "cG90" },
+ { "pow", "cG93" },
+ { "ppm", "cHBt" },
+ { "pro", "cHJv" },
+ { "pry", "cHJ5" },
+ { "p's", "cCdz" },
+ { "psi", "cHNp" },
+ { "PTA", "UFRB" },
+ { "pub", "cHVi" },
+ { "PUC", "UFVD" },
+ { "pug", "cHVn" },
+ { "pun", "cHVu" },
+ { "pup", "cHVw" },
+ { "pus", "cHVz" },
+ { "put", "cHV0" },
+ { "PVC", "UFZD" },
+ { "QED", "UUVE" },
+ { "q's", "cSdz" },
+ { "qua", "cXVh" },
+ { "quo", "cXVv" },
+ { "Rae", "UmFl" },
+ { "rag", "cmFn" },
+ { "raj", "cmFq" },
+ { "ram", "cmFt" },
+ { "ran", "cmFu" },
+ { "rap", "cmFw" },
+ { "rat", "cmF0" },
+ { "raw", "cmF3" },
+ { "ray", "cmF5" },
+ { "RCA", "UkNB" },
+ { "R&D", "UiZE" },
+ { "reb", "cmVi" },
+ { "red", "cmVk" },
+ { "rep", "cmVw" },
+ { "ret", "cmV0" },
+ { "rev", "cmV2" },
+ { "Rex", "UmV4" },
+ { "rho", "cmhv" },
+ { "rib", "cmli" },
+ { "rid", "cmlk" },
+ { "rig", "cmln" },
+ { "rim", "cmlt" },
+ { "Rio", "Umlv" },
+ { "rip", "cmlw" },
+ { "RNA", "Uk5B" },
+ { "rob", "cm9i" },
+ { "rod", "cm9k" },
+ { "roe", "cm9l" },
+ { "Ron", "Um9u" },
+ { "rot", "cm90" },
+ { "row", "cm93" },
+ { "Roy", "Um95" },
+ { "RPM", "UlBN" },
+ { "r's", "cidz" },
+ { "rub", "cnVi" },
+ { "rue", "cnVl" },
+ { "rug", "cnVn" },
+ { "rum", "cnVt" },
+ { "run", "cnVu" },
+ { "rut", "cnV0" },
+ { "rye", "cnll" },
+ { "sac", "c2Fj" },
+ { "sad", "c2Fk" },
+ { "sag", "c2Fn" },
+ { "Sal", "U2Fs" },
+ { "Sam", "U2Ft" },
+ { "San", "U2Fu" },
+ { "Sao", "U2Fv" },
+ { "sap", "c2Fw" },
+ { "sat", "c2F0" },
+ { "saw", "c2F3" },
+ { "sax", "c2F4" },
+ { "say", "c2F5" },
+ { "Sci", "U2Np" },
+ { "SCM", "U0NN" },
+ { "sea", "c2Vh" },
+ { "sec", "c2Vj" },
+ { "see", "c2Vl" },
+ { "sen", "c2Vu" },
+ { "seq", "c2Vx" },
+ { "set", "c2V0" },
+ { "sew", "c2V3" },
+ { "sex", "c2V4" },
+ { "she", "c2hl" },
+ { "Shu", "U2h1" },
+ { "shy", "c2h5" },
+ { "sib", "c2li" },
+ { "sic", "c2lj" },
+ { "sin", "c2lu" },
+ { "sip", "c2lw" },
+ { "sir", "c2ly" },
+ { "sis", "c2lz" },
+ { "sit", "c2l0" },
+ { "six", "c2l4" },
+ { "ski", "c2tp" },
+ { "sky", "c2t5" },
+ { "sly", "c2x5" },
+ { "sob", "c29i" },
+ { "Soc", "U29j" },
+ { "sod", "c29k" },
+ { "Sol", "U29s" },
+ { "son", "c29u" },
+ { "sop", "c29w" },
+ { "sou", "c291" },
+ { "sow", "c293" },
+ { "soy", "c295" },
+ { "spa", "c3Bh" },
+ { "spy", "c3B5" },
+ { "Sri", "U3Jp" },
+ { "s's", "cydz" },
+ { "SSE", "U1NF" },
+ { "SST", "U1NU" },
+ { "SSW", "U1NX" },
+ { "Stu", "U3R1" },
+ { "sub", "c3Vi" },
+ { "sud", "c3Vk" },
+ { "sue", "c3Vl" },
+ { "sum", "c3Vt" },
+ { "sun", "c3Vu" },
+ { "sup", "c3Vw" },
+ { "Sus", "U3Vz" },
+ { "tab", "dGFi" },
+ { "tad", "dGFk" },
+ { "tag", "dGFn" },
+ { "tam", "dGFt" },
+ { "tan", "dGFu" },
+ { "tao", "dGFv" },
+ { "tap", "dGFw" },
+ { "tar", "dGFy" },
+ { "tat", "dGF0" },
+ { "tau", "dGF1" },
+ { "tax", "dGF4" },
+ { "tea", "dGVh" },
+ { "Ted", "VGVk" },
+ { "ted", "dGVk" },
+ { "tee", "dGVl" },
+ { "Tel", "VGVs" },
+ { "ten", "dGVu" },
+ { "the", "dGhl" },
+ { "thy", "dGh5" },
+ { "tic", "dGlj" },
+ { "tid", "dGlk" },
+ { "tie", "dGll" },
+ { "til", "dGls" },
+ { "Tim", "VGlt" },
+ { "tin", "dGlu" },
+ { "tip", "dGlw" },
+ { "tit", "dGl0" },
+ { "TNT", "VE5U" },
+ { "toe", "dG9l" },
+ { "tog", "dG9n" },
+ { "Tom", "VG9t" },
+ { "ton", "dG9u" },
+ { "too", "dG9v" },
+ { "top", "dG9w" },
+ { "tor", "dG9y" },
+ { "tot", "dG90" },
+ { "tow", "dG93" },
+ { "toy", "dG95" },
+ { "TRW", "VFJX" },
+ { "try", "dHJ5" },
+ { "t's", "dCdz" },
+ { "TTL", "VFRM" },
+ { "TTY", "VFRZ" },
+ { "tub", "dHVi" },
+ { "tug", "dHVn" },
+ { "tum", "dHVt" },
+ { "tun", "dHVu" },
+ { "TVA", "VFZB" },
+ { "TWA", "VFdB" },
+ { "two", "dHdv" },
+ { "TWX", "VFdY" },
+ { "ugh", "dWdo" },
+ { "UHF", "VUhG" },
+ { "Uri", "VXJp" },
+ { "urn", "dXJu" },
+ { "U.S", "VS5T" },
+ { "u's", "dSdz" },
+ { "USA", "VVNB" },
+ { "USC", "VVND" },
+ { "use", "dXNl" },
+ { "USN", "VVNO" },
+ { "van", "dmFu" },
+ { "vat", "dmF0" },
+ { "vee", "dmVl" },
+ { "vet", "dmV0" },
+ { "vex", "dmV4" },
+ { "VHF", "VkhG" },
+ { "via", "dmlh" },
+ { "vie", "dmll" },
+ { "vii", "dmlp" },
+ { "vis", "dmlz" },
+ { "viz", "dml6" },
+ { "von", "dm9u" },
+ { "vow", "dm93" },
+ { "v's", "didz" },
+ { "WAC", "V0FD" },
+ { "wad", "d2Fk" },
+ { "wag", "d2Fn" },
+ { "wah", "d2Fo" },
+ { "wan", "d2Fu" },
+ { "war", "d2Fy" },
+ { "was", "d2Fz" },
+ { "wax", "d2F4" },
+ { "way", "d2F5" },
+ { "web", "d2Vi" },
+ { "wed", "d2Vk" },
+ { "wee", "d2Vl" },
+ { "Wei", "V2Vp" },
+ { "wet", "d2V0" },
+ { "who", "d2hv" },
+ { "why", "d2h5" },
+ { "wig", "d2ln" },
+ { "win", "d2lu" },
+ { "wit", "d2l0" },
+ { "woe", "d29l" },
+ { "wok", "d29r" },
+ { "won", "d29u" },
+ { "woo", "d29v" },
+ { "wop", "d29w" },
+ { "wow", "d293" },
+ { "wry", "d3J5" },
+ { "w's", "dydz" },
+ { "x's", "eCdz" },
+ { "yah", "eWFo" },
+ { "yak", "eWFr" },
+ { "yam", "eWFt" },
+ { "yap", "eWFw" },
+ { "yaw", "eWF3" },
+ { "yea", "eWVh" },
+ { "yen", "eWVu" },
+ { "yet", "eWV0" },
+ { "yin", "eWlu" },
+ { "yip", "eWlw" },
+ { "yon", "eW9u" },
+ { "you", "eW91" },
+ { "yow", "eW93" },
+ { "y's", "eSdz" },
+ { "yuh", "eXVo" },
+ { "zag", "emFn" },
+ { "Zan", "WmFu" },
+ { "zap", "emFw" },
+ { "Zen", "WmVu" },
+ { "zig", "emln" },
+ { "zip", "emlw" },
+ { "Zoe", "Wm9l" },
+ { "zoo", "em9v" },
+ { "z's", "eidz" },
+ /* the false rumors file */
+ { "\"So when I die, the first thing I will see in heaven is a score list?\"",
+ "IlNvIHdoZW4gSSBkaWUsIHRoZSBmaXJzdCB0aGluZyBJIHdpbGwgc2VlIGluIGhlYXZlbiBpcyBhIHNjb3JlIGxpc3Q/Ig=="
+ },
+ { "1st Law of Hacking: leaving is much more difficult than entering.",
+ "MXN0IExhdyBvZiBIYWNraW5nOiBsZWF2aW5nIGlzIG11Y2ggbW9yZSBkaWZmaWN1bHQgdGhhbiBlbnRlcmluZy4="
+ },
+ { "2nd Law of Hacking: first in, first out.",
+ "Mm5kIExhdyBvZiBIYWNraW5nOiBmaXJzdCBpbiwgZmlyc3Qgb3V0Lg=="
+ },
+ { "3rd Law of Hacking: the last blow counts most.",
+ "M3JkIExhdyBvZiBIYWNraW5nOiB0aGUgbGFzdCBibG93IGNvdW50cyBtb3N0Lg=="
+ },
+ { "4th Law of Hacking: you will find the exit at the entrance.",
+ "NHRoIExhdyBvZiBIYWNraW5nOiB5b3Ugd2lsbCBmaW5kIHRoZSBleGl0IGF0IHRoZSBlbnRyYW5jZS4="
+ },
+ { "A chameleon imitating a mail daemon often delivers scrolls of fire.",
+ "QSBjaGFtZWxlb24gaW1pdGF0aW5nIGEgbWFpbCBkYWVtb24gb2Z0ZW4gZGVsaXZlcnMgc2Nyb2xscyBvZiBmaXJlLg=="
+ },
+ { "A cockatrice corpse is guaranteed to be untainted!",
+ "QSBjb2NrYXRyaWNlIGNvcnBzZSBpcyBndWFyYW50ZWVkIHRvIGJlIHVudGFpbnRlZCE="
+ },
+ { "A dead cockatrice is just a dead lizard.",
+ "QSBkZWFkIGNvY2thdHJpY2UgaXMganVzdCBhIGRlYWQgbGl6YXJkLg=="
+ },
+ { "A dragon is just a snake that ate a scroll of fire.",
+ "QSBkcmFnb24gaXMganVzdCBhIHNuYWtlIHRoYXQgYXRlIGEgc2Nyb2xsIG9mIGZpcmUu"
+ },
+ { "A fading corridor enlightens your insight.",
+ "QSBmYWRpbmcgY29ycmlkb3IgZW5saWdodGVucyB5b3VyIGluc2lnaHQu"
+ },
+ { "A glowing potion is too hot to drink.",
+ "QSBnbG93aW5nIHBvdGlvbiBpcyB0b28gaG90IHRvIGRyaW5rLg=="
+ },
+ { "A good amulet may protect you against guards.",
+ "QSBnb29kIGFtdWxldCBtYXkgcHJvdGVjdCB5b3UgYWdhaW5zdCBndWFyZHMu"
+ },
+ { "A lizard corpse is a good thing to turn undead.",
+ "QSBsaXphcmQgY29ycHNlIGlzIGEgZ29vZCB0aGluZyB0byB0dXJuIHVuZGVhZC4="
+ },
+ { "A long worm can be defined recursively. So how should you attack it?",
+ "QSBsb25nIHdvcm0gY2FuIGJlIGRlZmluZWQgcmVjdXJzaXZlbHkuIFNvIGhvdyBzaG91bGQgeW91IGF0dGFjayBpdD8="
+ },
+ { "A monstrous mind is a toy forever.",
+ "QSBtb25zdHJvdXMgbWluZCBpcyBhIHRveSBmb3JldmVyLg=="
+ },
+ { "A nymph will be very pleased if you call her by her real name: Lorelei.",
+ "QSBueW1waCB3aWxsIGJlIHZlcnkgcGxlYXNlZCBpZiB5b3UgY2FsbCBoZXIgYnkgaGVyIHJlYWwgbmFtZTogTG9yZWxlaS4="
+ },
+ { "A ring of dungeon master control is a great find.",
+ "QSByaW5nIG9mIGR1bmdlb24gbWFzdGVyIGNvbnRyb2wgaXMgYSBncmVhdCBmaW5kLg=="
+ },
+ { "A ring of extra ring finger is useless if not enchanted.",
+ "QSByaW5nIG9mIGV4dHJhIHJpbmcgZmluZ2VyIGlzIHVzZWxlc3MgaWYgbm90IGVuY2hhbnRlZC4="
+ },
+ { "A rope may form a trail in a maze.",
+ "QSByb3BlIG1heSBmb3JtIGEgdHJhaWwgaW4gYSBtYXplLg=="
+ },
+ { "A staff may recharge if you drop it for awhile.",
+ "QSBzdGFmZiBtYXkgcmVjaGFyZ2UgaWYgeW91IGRyb3AgaXQgZm9yIGF3aGlsZS4="
+ },
+ { "A visit to the Zoo is very educational; you meet interesting animals.",
+ "QSB2aXNpdCB0byB0aGUgWm9vIGlzIHZlcnkgZWR1Y2F0aW9uYWw7IHlvdSBtZWV0IGludGVyZXN0aW5nIGFuaW1hbHMu"
+ },
+ { "A wand of deaf is a more dangerous weapon than a wand of sheep.",
+ "QSB3YW5kIG9mIGRlYWYgaXMgYSBtb3JlIGRhbmdlcm91cyB3ZWFwb24gdGhhbiBhIHdhbmQgb2Ygc2hlZXAu"
+ },
+ { "A wand of vibration might bring the whole cave crashing about your ears.",
+ "QSB3YW5kIG9mIHZpYnJhdGlvbiBtaWdodCBicmluZyB0aGUgd2hvbGUgY2F2ZSBjcmFzaGluZyBhYm91dCB5b3VyIGVhcnMu"
+ },
+ { "A winner never quits. A quitter never wins.",
+ "QSB3aW5uZXIgbmV2ZXIgcXVpdHMuIEEgcXVpdHRlciBuZXZlciB3aW5zLg=="
+ },
+ { "A wish? Okay, make me a fortune cookie!",
+ "QSB3aXNoPyBPa2F5LCBtYWtlIG1lIGEgZm9ydHVuZSBjb29raWUh"
+ },
+ { "Afraid of mimics? Try to wear a ring of true seeing.",
+ "QWZyYWlkIG9mIG1pbWljcz8gVHJ5IHRvIHdlYXIgYSByaW5nIG9mIHRydWUgc2VlaW5nLg=="
+ },
+ { "All monsters are created evil, but some are more evil than others.",
+ "QWxsIG1vbnN0ZXJzIGFyZSBjcmVhdGVkIGV2aWwsIGJ1dCBzb21lIGFyZSBtb3JlIGV2aWwgdGhhbiBvdGhlcnMu"
+ },
+ { "Always attack a floating eye from behind!",
+ "QWx3YXlzIGF0dGFjayBhIGZsb2F0aW5nIGV5ZSBmcm9tIGJlaGluZCE="
+ },
+ { "An elven cloak is always the height of fashion.",
+ "QW4gZWx2ZW4gY2xvYWsgaXMgYWx3YXlzIHRoZSBoZWlnaHQgb2YgZmFzaGlvbi4="
+ },
+ { "Any small object that is accidentally dropped will hide under a larger object.",
+ "QW55IHNtYWxsIG9iamVjdCB0aGF0IGlzIGFjY2lkZW50YWxseSBkcm9wcGVkIHdpbGwgaGlkZSB1bmRlciBhIGxhcmdlciBvYmplY3Qu"
+ },
+ { "Balrogs do not appear above level 20.",
+ "QmFscm9ncyBkbyBub3QgYXBwZWFyIGFib3ZlIGxldmVsIDIwLg=="
+ },
+ { "Banana peels work especially well against Keystone Kops.",
+ "QmFuYW5hIHBlZWxzIHdvcmsgZXNwZWNpYWxseSB3ZWxsIGFnYWluc3QgS2V5c3RvbmUgS29wcy4="
+ },
+ { "Be careful when eating bananas. Monsters might slip on the peels.",
+ "QmUgY2FyZWZ1bCB3aGVuIGVhdGluZyBiYW5hbmFzLiBNb25zdGVycyBtaWdodCBzbGlwIG9uIHRoZSBwZWVscy4="
+ },
+ { "Better leave the dungeon; otherwise you might get hurt badly.",
+ "QmV0dGVyIGxlYXZlIHRoZSBkdW5nZW9uOyBvdGhlcndpc2UgeW91IG1pZ2h0IGdldCBodXJ0IGJhZGx5Lg=="
+ },
+ { "Beware of the potion of nitroglycerin -- it's not for the weak of heart.",
+ "QmV3YXJlIG9mIHRoZSBwb3Rpb24gb2Ygbml0cm9nbHljZXJpbiAtLSBpdCdzIG5vdCBmb3IgdGhlIHdlYWsgb2YgaGVhcnQu"
+ },
+ { "Beware: there's always a chance that your wand explodes as you try to zap it!",
+ "QmV3YXJlOiB0aGVyZSdzIGFsd2F5cyBhIGNoYW5jZSB0aGF0IHlvdXIgd2FuZCBleHBsb2RlcyBhcyB5b3UgdHJ5IHRvIHphcCBpdCE="
+ },
+ { "Beyond the 23rd level lies a happy retirement in a room of your own.",
+ "QmV5b25kIHRoZSAyM3JkIGxldmVsIGxpZXMgYSBoYXBweSByZXRpcmVtZW50IGluIGEgcm9vbSBvZiB5b3VyIG93bi4="
+ },
+ { "Changing your suit without dropping your sword? You must be kidding!",
+ "Q2hhbmdpbmcgeW91ciBzdWl0IHdpdGhvdXQgZHJvcHBpbmcgeW91ciBzd29yZD8gWW91IG11c3QgYmUga2lkZGluZyE="
+ },
+ { "Cockatrices might turn themselves to stone faced with a mirror.",
+ "Q29ja2F0cmljZXMgbWlnaHQgdHVybiB0aGVtc2VsdmVzIHRvIHN0b25lIGZhY2VkIHdpdGggYSBtaXJyb3Iu"
+ },
+ { "Consumption of home-made food is strictly forbidden in this dungeon.",
+ "Q29uc3VtcHRpb24gb2YgaG9tZS1tYWRlIGZvb2QgaXMgc3RyaWN0bHkgZm9yYmlkZGVuIGluIHRoaXMgZHVuZ2Vvbi4="
+ },
+ { "Dark room? Your chance to develop your photographs!",
+ "RGFyayByb29tPyBZb3VyIGNoYW5jZSB0byBkZXZlbG9wIHlvdXIgcGhvdG9ncmFwaHMh"
+ },
+ { "Dark rooms are not *completely* dark: just wait and let your eyes adjust...",
+ "RGFyayByb29tcyBhcmUgbm90ICpjb21wbGV0ZWx5KiBkYXJrOiBqdXN0IHdhaXQgYW5kIGxldCB5b3VyIGV5ZXMgYWRqdXN0Li4u"
+ },
+ { "David London sez, \"Hey guys, *WIELD* a lizard corpse against a cockatrice!\"",
+ "RGF2aWQgTG9uZG9uIHNleiwgIkhleSBndXlzLCAqV0lFTEQqIGEgbGl6YXJkIGNvcnBzZSBhZ2FpbnN0IGEgY29ja2F0cmljZSEi"
+ },
+ { "Death is just life's way of telling you you've been fired.",
+ "RGVhdGggaXMganVzdCBsaWZlJ3Mgd2F5IG9mIHRlbGxpbmcgeW91IHlvdSd2ZSBiZWVuIGZpcmVkLg=="
+ },
+ { "Demi-gods don't need any help from the gods.",
+ "RGVtaS1nb2RzIGRvbid0IG5lZWQgYW55IGhlbHAgZnJvbSB0aGUgZ29kcy4="
+ },
+ { "Demons *HATE* Priests and Priestesses.",
+ "RGVtb25zICpIQVRFKiBQcmllc3RzIGFuZCBQcmllc3Rlc3Nlcy4="
+ },
+ { "Didn't you forget to pay?",
+ "RGlkbid0IHlvdSBmb3JnZXQgdG8gcGF5Pw=="
+ },
+ { "Didn't your mother tell you not to eat food off the floor?",
+ "RGlkbid0IHlvdXIgbW90aGVyIHRlbGwgeW91IG5vdCB0byBlYXQgZm9vZCBvZmYgdGhlIGZsb29yPw=="
+ },
+ { "Direct a direct hit on your direct opponent, directing in the right direction.",
+ "RGlyZWN0IGEgZGlyZWN0IGhpdCBvbiB5b3VyIGRpcmVjdCBvcHBvbmVudCwgZGlyZWN0aW5nIGluIHRoZSByaWdodCBkaXJlY3Rpb24u"
+ },
+ { "Do you want to make more money? Sure, we all do! Join the Fort Ludios guard!",
+ "RG8geW91IHdhbnQgdG8gbWFrZSBtb3JlIG1vbmV5PyBTdXJlLCB3ZSBhbGwgZG8hIEpvaW4gdGhlIEZvcnQgTHVkaW9zIGd1YXJkIQ=="
+ },
+ { "Don't eat too much: you might start hiccoughing!",
+ "RG9uJ3QgZWF0IHRvbyBtdWNoOiB5b3UgbWlnaHQgc3RhcnQgaGljY291Z2hpbmch"
+ },
+ { "Don't play hack at your work; your boss might hit you!",
+ "RG9uJ3QgcGxheSBoYWNrIGF0IHlvdXIgd29yazsgeW91ciBib3NzIG1pZ2h0IGhpdCB5b3Uh"
+ },
+ { "Don't tell a soul you found a secret door, otherwise it isn't a secret anymore.",
+ "RG9uJ3QgdGVsbCBhIHNvdWwgeW91IGZvdW5kIGEgc2VjcmV0IGRvb3IsIG90aGVyd2lzZSBpdCBpc24ndCBhIHNlY3JldCBhbnltb3JlLg=="
+ },
+ { "Drinking potions of booze may land you in jail if you are under 21.",
+ "RHJpbmtpbmcgcG90aW9ucyBvZiBib296ZSBtYXkgbGFuZCB5b3UgaW4gamFpbCBpZiB5b3UgYXJlIHVuZGVyIDIxLg=="
+ },
+ { "Drop your vanity and get rid of your jewels! Pickpockets about!",
+ "RHJvcCB5b3VyIHZhbml0eSBhbmQgZ2V0IHJpZCBvZiB5b3VyIGpld2VscyEgUGlja3BvY2tldHMgYWJvdXQh"
+ },
+ { "Eat 10 cloves of garlic and keep all humans at a two-square distance.",
+ "RWF0IDEwIGNsb3ZlcyBvZiBnYXJsaWMgYW5kIGtlZXAgYWxsIGh1bWFucyBhdCBhIHR3by1zcXVhcmUgZGlzdGFuY2Uu"
+ },
+ { "Eels hide under mud. Use a unicorn to clear the water and make them visible.",
+ "RWVscyBoaWRlIHVuZGVyIG11ZC4gVXNlIGEgdW5pY29ybiB0byBjbGVhciB0aGUgd2F0ZXIgYW5kIG1ha2UgdGhlbSB2aXNpYmxlLg=="
+ },
+ { "Engrave your wishes with a wand of wishing.",
+ "RW5ncmF2ZSB5b3VyIHdpc2hlcyB3aXRoIGEgd2FuZCBvZiB3aXNoaW5nLg=="
+ },
+ { "Eventually you will come to admire the swift elegance of a retreating nymph.",
+ "RXZlbnR1YWxseSB5b3Ugd2lsbCBjb21lIHRvIGFkbWlyZSB0aGUgc3dpZnQgZWxlZ2FuY2Ugb2YgYSByZXRyZWF0aW5nIG55bXBoLg=="
+ },
+ { "Ever heard hissing outside? I *knew* you hadn't!",
+ "RXZlciBoZWFyZCBoaXNzaW5nIG91dHNpZGU/IEkgKmtuZXcqIHlvdSBoYWRuJ3Qh"
+ },
+ { "Ever lifted a dragon corpse?",
+ "RXZlciBsaWZ0ZWQgYSBkcmFnb24gY29ycHNlPw=="
+ },
+ { "Ever seen a leocrotta dancing the tengu?",
+ "RXZlciBzZWVuIGEgbGVvY3JvdHRhIGRhbmNpbmcgdGhlIHRlbmd1Pw=="
+ },
+ { "Ever seen your weapon glow plaid?",
+ "RXZlciBzZWVuIHlvdXIgd2VhcG9uIGdsb3cgcGxhaWQ/"
+ },
+ { "Ever tamed a shopkeeper?",
+ "RXZlciB0YW1lZCBhIHNob3BrZWVwZXI/"
+ },
+ { "Ever tried digging through a Vault Guard?",
+ "RXZlciB0cmllZCBkaWdnaW5nIHRocm91Z2ggYSBWYXVsdCBHdWFyZD8="
+ },
+ { "Ever tried enchanting a rope?",
+ "RXZlciB0cmllZCBlbmNoYW50aW5nIGEgcm9wZT8="
+ },
+ { "Floating eyes can't stand Hawaiian shirts.",
+ "RmxvYXRpbmcgZXllcyBjYW4ndCBzdGFuZCBIYXdhaWlhbiBzaGlydHMu"
+ },
+ { "For any remedy there is a misery.",
+ "Rm9yIGFueSByZW1lZHkgdGhlcmUgaXMgYSBtaXNlcnku"
+ },
+ { "Giant bats turn into giant vampires.",
+ "R2lhbnQgYmF0cyB0dXJuIGludG8gZ2lhbnQgdmFtcGlyZXMu"
+ },
+ { "Good day for overcoming obstacles. Try a steeplechase.",
+ "R29vZCBkYXkgZm9yIG92ZXJjb21pbmcgb2JzdGFjbGVzLiBUcnkgYSBzdGVlcGxlY2hhc2Uu"
+ },
+ { "Half Moon tonight. (At least it's better than no Moon at all.)",
+ "SGFsZiBNb29uIHRvbmlnaHQuIChBdCBsZWFzdCBpdCdzIGJldHRlciB0aGFuIG5vIE1vb24gYXQgYWxsLik="
+ },
+ { "Help! I'm being held prisoner in a fortune cookie factory!",
+ "SGVscCEgSSdtIGJlaW5nIGhlbGQgcHJpc29uZXIgaW4gYSBmb3J0dW5lIGNvb2tpZSBmYWN0b3J5IQ=="
+ },
+ { "Housecats have nine lives, kittens only one.",
+ "SG91c2VjYXRzIGhhdmUgbmluZSBsaXZlcywga2l0dGVucyBvbmx5IG9uZS4="
+ },
+ { "How long can you tread water?",
+ "SG93IGxvbmcgY2FuIHlvdSB0cmVhZCB3YXRlcj8="
+ },
+ { "Hungry? There is an abundance of food on the next level.",
+ "SHVuZ3J5PyBUaGVyZSBpcyBhbiBhYnVuZGFuY2Ugb2YgZm9vZCBvbiB0aGUgbmV4dCBsZXZlbC4="
+ },
+ { "I guess you've never hit a mail daemon with the Amulet of Yendor...",
+ "SSBndWVzcyB5b3UndmUgbmV2ZXIgaGl0IGEgbWFpbCBkYWVtb24gd2l0aCB0aGUgQW11bGV0IG9mIFllbmRvci4uLg=="
+ },
+ { "If you are the shopkeeper, you can take things for free.",
+ "SWYgeW91IGFyZSB0aGUgc2hvcGtlZXBlciwgeW91IGNhbiB0YWtlIHRoaW5ncyBmb3IgZnJlZS4="
+ },
+ { "If you can't learn to do it well, learn to enjoy doing it badly.",
+ "SWYgeW91IGNhbid0IGxlYXJuIHRvIGRvIGl0IHdlbGwsIGxlYXJuIHRvIGVuam95IGRvaW5nIGl0IGJhZGx5Lg=="
+ },
+ { "If you thought the Wizard was bad, just wait till you meet the Warlord!",
+ "SWYgeW91IHRob3VnaHQgdGhlIFdpemFyZCB3YXMgYmFkLCBqdXN0IHdhaXQgdGlsbCB5b3UgbWVldCB0aGUgV2FybG9yZCE="
+ },
+ { "If you turn blind, don't expect your dog to be turned into a seeing-eye dog.",
+ "SWYgeW91IHR1cm4gYmxpbmQsIGRvbid0IGV4cGVjdCB5b3VyIGRvZyB0byBiZSB0dXJuZWQgaW50byBhIHNlZWluZy1leWUgZG9nLg=="
+ },
+ { "If you want to feel great, you must eat something real big.",
+ "SWYgeW91IHdhbnQgdG8gZmVlbCBncmVhdCwgeW91IG11c3QgZWF0IHNvbWV0aGluZyByZWFsIGJpZy4="
+ },
+ { "If you want to float, you'd better eat a floating eye.",
+ "SWYgeW91IHdhbnQgdG8gZmxvYXQsIHlvdSdkIGJldHRlciBlYXQgYSBmbG9hdGluZyBleWUu"
+ },
+ { "If your ghost kills a player, it increases your score.",
+ "SWYgeW91ciBnaG9zdCBraWxscyBhIHBsYXllciwgaXQgaW5jcmVhc2VzIHlvdXIgc2NvcmUu"
+ },
+ { "Increase mindpower: Tame your own ghost!",
+ "SW5jcmVhc2UgbWluZHBvd2VyOiBUYW1lIHlvdXIgb3duIGdob3N0IQ=="
+ },
+ { "It furthers one to see the great man.",
+ "SXQgZnVydGhlcnMgb25lIHRvIHNlZSB0aGUgZ3JlYXQgbWFuLg=="
+ },
+ { "It's easy to overlook a monster in a wood.",
+ "SXQncyBlYXN5IHRvIG92ZXJsb29rIGEgbW9uc3RlciBpbiBhIHdvb2Qu"
+ },
+ { "Just below any trapdoor there may be another one. Just keep falling!",
+ "SnVzdCBiZWxvdyBhbnkgdHJhcGRvb3IgdGhlcmUgbWF5IGJlIGFub3RoZXIgb25lLiBKdXN0IGtlZXAgZmFsbGluZyE="
+ },
+ { "Katanas are very sharp; watch you don't cut yourself.",
+ "S2F0YW5hcyBhcmUgdmVyeSBzaGFycDsgd2F0Y2ggeW91IGRvbid0IGN1dCB5b3Vyc2VsZi4="
+ },
+ { "Keep a clear mind: quaff clear potions.",
+ "S2VlcCBhIGNsZWFyIG1pbmQ6IHF1YWZmIGNsZWFyIHBvdGlvbnMu"
+ },
+ { "Kicking the terminal doesn't hurt the monsters.",
+ "S2lja2luZyB0aGUgdGVybWluYWwgZG9lc24ndCBodXJ0IHRoZSBtb25zdGVycy4="
+ },
+ { "Killer bees keep appearing till you kill their queen.",
+ "S2lsbGVyIGJlZXMga2VlcCBhcHBlYXJpbmcgdGlsbCB5b3Uga2lsbCB0aGVpciBxdWVlbi4="
+ },
+ { "Killer bunnies can be tamed with carrots only.",
+ "S2lsbGVyIGJ1bm5pZXMgY2FuIGJlIHRhbWVkIHdpdGggY2Fycm90cyBvbmx5Lg=="
+ },
+ { "Latest news? Put `rec.games.roguelike.nethack' in your .newsrc!",
+ "TGF0ZXN0IG5ld3M/IFB1dCBgcmVjLmdhbWVzLnJvZ3VlbGlrZS5uZXRoYWNrJyBpbiB5b3VyIC5uZXdzcmMh"
+ },
+ { "Learn how to spell. Play NetHack!",
+ "TGVhcm4gaG93IHRvIHNwZWxsLiBQbGF5IE5ldEhhY2sh"
+ },
+ { "Leprechauns hide their gold in a secret room.",
+ "TGVwcmVjaGF1bnMgaGlkZSB0aGVpciBnb2xkIGluIGEgc2VjcmV0IHJvb20u"
+ },
+ { "Let your fingers do the walking on the yulkjhnb keys.",
+ "TGV0IHlvdXIgZmluZ2VycyBkbyB0aGUgd2Fsa2luZyBvbiB0aGUgeXVsa2pobmIga2V5cy4="
+ },
+ { "Let's face it: this time you're not going to win.",
+ "TGV0J3MgZmFjZSBpdDogdGhpcyB0aW1lIHlvdSdyZSBub3QgZ29pbmcgdG8gd2luLg=="
+ },
+ { "Let's have a party, drink a lot of booze.",
+ "TGV0J3MgaGF2ZSBhIHBhcnR5LCBkcmluayBhIGxvdCBvZiBib296ZS4="
+ },
+ { "Liquor sellers do not drink; they hate to see you twice.",
+ "TGlxdW9yIHNlbGxlcnMgZG8gbm90IGRyaW5rOyB0aGV5IGhhdGUgdG8gc2VlIHlvdSB0d2ljZS4="
+ },
+ { "Lunar eclipse tonight. May as well quit now!",
+ "THVuYXIgZWNsaXBzZSB0b25pZ2h0LiBNYXkgYXMgd2VsbCBxdWl0IG5vdyE="
+ },
+ { "Meeting your own ghost decreases your luck considerably!",
+ "TWVldGluZyB5b3VyIG93biBnaG9zdCBkZWNyZWFzZXMgeW91ciBsdWNrIGNvbnNpZGVyYWJseSE="
+ },
+ { "Money to invest? Take it to the local branch of the Magic Memory Vault!",
+ "TW9uZXkgdG8gaW52ZXN0PyBUYWtlIGl0IHRvIHRoZSBsb2NhbCBicmFuY2ggb2YgdGhlIE1hZ2ljIE1lbW9yeSBWYXVsdCE="
+ },
+ { "Monsters come from nowhere to hit you everywhere.",
+ "TW9uc3RlcnMgY29tZSBmcm9tIG5vd2hlcmUgdG8gaGl0IHlvdSBldmVyeXdoZXJlLg=="
+ },
+ { "Monsters sleep because you are boring, not because they ever get tired.",
+ "TW9uc3RlcnMgc2xlZXAgYmVjYXVzZSB5b3UgYXJlIGJvcmluZywgbm90IGJlY2F1c2UgdGhleSBldmVyIGdldCB0aXJlZC4="
+ },
+ { "Most monsters prefer minced meat. That's why they are hitting you!",
+ "TW9zdCBtb25zdGVycyBwcmVmZXIgbWluY2VkIG1lYXQuIFRoYXQncyB3aHkgdGhleSBhcmUgaGl0dGluZyB5b3Uh"
+ },
+ { "Most of the bugs in NetHack are on the floor.",
+ "TW9zdCBvZiB0aGUgYnVncyBpbiBOZXRIYWNrIGFyZSBvbiB0aGUgZmxvb3Iu"
+ },
+ { "Much ado Nothing Happens.",
+ "TXVjaCBhZG8gTm90aGluZyBIYXBwZW5zLg=="
+ },
+ { "Multi-player NetHack is a myth.",
+ "TXVsdGktcGxheWVyIE5ldEhhY2sgaXMgYSBteXRoLg=="
+ },
+ { "NetHack is addictive. Too late, you're already hooked.",
+ "TmV0SGFjayBpcyBhZGRpY3RpdmUuIFRvbyBsYXRlLCB5b3UncmUgYWxyZWFkeSBob29rZWQu"
+ },
+ { "Never ask a shopkeeper for a price list.",
+ "TmV2ZXIgYXNrIGEgc2hvcGtlZXBlciBmb3IgYSBwcmljZSBsaXN0Lg=="
+ },
+ { "Never burn a tree, unless you like getting whacked with a +5 shovel.",
+ "TmV2ZXIgYnVybiBhIHRyZWUsIHVubGVzcyB5b3UgbGlrZSBnZXR0aW5nIHdoYWNrZWQgd2l0aCBhICs1IHNob3ZlbC4="
+ },
+ { "Never eat with glowing hands!",
+ "TmV2ZXIgZWF0IHdpdGggZ2xvd2luZyBoYW5kcyE="
+ },
+ { "Never mind the monsters hitting you: they just replace the charwomen.",
+ "TmV2ZXIgbWluZCB0aGUgbW9uc3RlcnMgaGl0dGluZyB5b3U6IHRoZXkganVzdCByZXBsYWNlIHRoZSBjaGFyd29tZW4u"
+ },
+ { "Never play leapfrog with a unicorn.",
+ "TmV2ZXIgcGxheSBsZWFwZnJvZyB3aXRoIGEgdW5pY29ybi4="
+ },
+ { "Never step on a cursed engraving.",
+ "TmV2ZXIgc3RlcCBvbiBhIGN1cnNlZCBlbmdyYXZpbmcu"
+ },
+ { "Never swim with a camera: there's nothing to take pictures of.",
+ "TmV2ZXIgc3dpbSB3aXRoIGEgY2FtZXJhOiB0aGVyZSdzIG5vdGhpbmcgdG8gdGFrZSBwaWN0dXJlcyBvZi4="
+ },
+ { "Never teach your pet rust monster to fetch.",
+ "TmV2ZXIgdGVhY2ggeW91ciBwZXQgcnVzdCBtb25zdGVyIHRvIGZldGNoLg=="
+ },
+ { "Never trust a random generator in magic fields.",
+ "TmV2ZXIgdHJ1c3QgYSByYW5kb20gZ2VuZXJhdG9yIGluIG1hZ2ljIGZpZWxkcy4="
+ },
+ { "Never use a wand of death.",
+ "TmV2ZXIgdXNlIGEgd2FuZCBvZiBkZWF0aC4="
+ },
+ { "No level contains two shops. The maze is no level. So...",
+ "Tm8gbGV2ZWwgY29udGFpbnMgdHdvIHNob3BzLiBUaGUgbWF6ZSBpcyBubyBsZXZlbC4gU28uLi4="
+ },
+ { "No part of this fortune may be reproduced, stored in a retrieval system, ...",
+ "Tm8gcGFydCBvZiB0aGlzIGZvcnR1bmUgbWF5IGJlIHJlcHJvZHVjZWQsIHN0b3JlZCBpbiBhIHJldHJpZXZhbCBzeXN0ZW0sIC4uLg=="
+ },
+ { "Not all rumors are as misleading as this one.",
+ "Tm90IGFsbCBydW1vcnMgYXJlIGFzIG1pc2xlYWRpbmcgYXMgdGhpcyBvbmUu"
+ },
+ { "Nymphs and nurses like beautiful rings.",
+ "TnltcGhzIGFuZCBudXJzZXMgbGlrZSBiZWF1dGlmdWwgcmluZ3Mu"
+ },
+ { "Nymphs are blondes. Are you a gentleman?",
+ "TnltcGhzIGFyZSBibG9uZGVzLiBBcmUgeW91IGEgZ2VudGxlbWFuPw=="
+ },
+ { "Offering a unicorn a worthless piece of glass might prove to be fatal!",
+ "T2ZmZXJpbmcgYSB1bmljb3JuIGEgd29ydGhsZXNzIHBpZWNlIG9mIGdsYXNzIG1pZ2h0IHByb3ZlIHRvIGJlIGZhdGFsIQ=="
+ },
+ { "Old hackers never die: young ones do.",
+ "T2xkIGhhY2tlcnMgbmV2ZXIgZGllOiB5b3VuZyBvbmVzIGRvLg=="
+ },
+ { "One has to leave shops before closing time.",
+ "T25lIGhhcyB0byBsZWF2ZSBzaG9wcyBiZWZvcmUgY2xvc2luZyB0aW1lLg=="
+ },
+ { "One homunculus a day keeps the doctor away.",
+ "T25lIGhvbXVuY3VsdXMgYSBkYXkga2VlcHMgdGhlIGRvY3RvciBhd2F5Lg=="
+ },
+ { "One level further down somebody is getting killed, right now.",
+ "T25lIGxldmVsIGZ1cnRoZXIgZG93biBzb21lYm9keSBpcyBnZXR0aW5nIGtpbGxlZCwgcmlnaHQgbm93Lg=="
+ },
+ { "Only a wizard can use a magic whistle.",
+ "T25seSBhIHdpemFyZCBjYW4gdXNlIGEgbWFnaWMgd2hpc3RsZS4="
+ },
+ { "Only adventurers of evil alignment think of killing their dog.",
+ "T25seSBhZHZlbnR1cmVycyBvZiBldmlsIGFsaWdubWVudCB0aGluayBvZiBraWxsaW5nIHRoZWlyIGRvZy4="
+ },
+ { "Only chaotic evils kill sleeping monsters.",
+ "T25seSBjaGFvdGljIGV2aWxzIGtpbGwgc2xlZXBpbmcgbW9uc3RlcnMu"
+ },
+ { "Only real trappers escape traps.",
+ "T25seSByZWFsIHRyYXBwZXJzIGVzY2FwZSB0cmFwcy4="
+ },
+ { "Only real wizards can write scrolls.",
+ "T25seSByZWFsIHdpemFyZHMgY2FuIHdyaXRlIHNjcm9sbHMu"
+ },
+ { "Operation OVERKILL has started now.",
+ "T3BlcmF0aW9uIE9WRVJLSUxMIGhhcyBzdGFydGVkIG5vdy4="
+ },
+ { "PLEASE ignore previous rumor.",
+ "UExFQVNFIGlnbm9yZSBwcmV2aW91cyBydW1vci4="
+ },
+ { "Polymorph into an ettin; meet your opponents face to face to face.",
+ "UG9seW1vcnBoIGludG8gYW4gZXR0aW47IG1lZXQgeW91ciBvcHBvbmVudHMgZmFjZSB0byBmYWNlIHRvIGZhY2Uu"
+ },
+ { "Praying will frighten demons.",
+ "UHJheWluZyB3aWxsIGZyaWdodGVuIGRlbW9ucy4="
+ },
+ { "Row (3x) that boat gently down the stream, Charon (4x), death is but a dream.",
+ "Um93ICgzeCkgdGhhdCBib2F0IGdlbnRseSBkb3duIHRoZSBzdHJlYW0sIENoYXJvbiAoNHgpLCBkZWF0aCBpcyBidXQgYSBkcmVhbS4="
+ },
+ { "Running is good for your legs.",
+ "UnVubmluZyBpcyBnb29kIGZvciB5b3VyIGxlZ3Mu"
+ },
+ { "Screw up your courage! You've screwed up everything else.",
+ "U2NyZXcgdXAgeW91ciBjb3VyYWdlISBZb3UndmUgc2NyZXdlZCB1cCBldmVyeXRoaW5nIGVsc2Uu"
+ },
+ { "Seepage? Leaky pipes? Rising damp? Summon the plumber!",
+ "U2VlcGFnZT8gTGVha3kgcGlwZXM/IFJpc2luZyBkYW1wPyBTdW1tb24gdGhlIHBsdW1iZXIh"
+ },
+ { "Segmentation fault (core dumped).",
+ "U2VnbWVudGF0aW9uIGZhdWx0IChjb3JlIGR1bXBlZCku"
+ },
+ { "Shopkeepers sometimes die from old age.",
+ "U2hvcGtlZXBlcnMgc29tZXRpbWVzIGRpZSBmcm9tIG9sZCBhZ2Uu"
+ },
+ { "Some mazes (especially small ones) have no solutions, says man 6 maze.",
+ "U29tZSBtYXplcyAoZXNwZWNpYWxseSBzbWFsbCBvbmVzKSBoYXZlIG5vIHNvbHV0aW9ucywgc2F5cyBtYW4gNiBtYXplLg=="
+ },
+ { "Some questions the Sphynx asks just *don't* have any answers.",
+ "U29tZSBxdWVzdGlvbnMgdGhlIFNwaHlueCBhc2tzIGp1c3QgKmRvbid0KiBoYXZlIGFueSBhbnN3ZXJzLg=="
+ },
+ { "Sometimes \"mu\" is the answer.",
+ "U29tZXRpbWVzICJtdSIgaXMgdGhlIGFuc3dlci4="
+ },
+ { "Sorry, no fortune this time. Better luck next cookie!",
+ "U29ycnksIG5vIGZvcnR1bmUgdGhpcyB0aW1lLiBCZXR0ZXIgbHVjayBuZXh0IGNvb2tpZSE="
+ },
+ { "Spare your scrolls of make-edible until it's really necessary!",
+ "U3BhcmUgeW91ciBzY3JvbGxzIG9mIG1ha2UtZWRpYmxlIHVudGlsIGl0J3MgcmVhbGx5IG5lY2Vzc2FyeSE="
+ },
+ { "Suddenly, the dungeon will collapse...",
+ "U3VkZGVubHksIHRoZSBkdW5nZW9uIHdpbGwgY29sbGFwc2UuLi4="
+ },
+ { "Taming a mail daemon may cause a system security violation.",
+ "VGFtaW5nIGEgbWFpbCBkYWVtb24gbWF5IGNhdXNlIGEgc3lzdGVtIHNlY3VyaXR5IHZpb2xhdGlvbi4="
+ },
+ { "The crowd was so tough, the Stooges won't play the Dungeon anymore, nyuk nyuk.",
+ "VGhlIGNyb3dkIHdhcyBzbyB0b3VnaCwgdGhlIFN0b29nZXMgd29uJ3QgcGxheSB0aGUgRHVuZ2VvbiBhbnltb3JlLCBueXVrIG55dWsu"
+ },
+ { "The leprechauns hide their treasure in a small hidden room.",
+ "VGhlIGxlcHJlY2hhdW5zIGhpZGUgdGhlaXIgdHJlYXN1cmUgaW4gYSBzbWFsbCBoaWRkZW4gcm9vbS4="
+ },
+ { "The longer the wand the better.",
+ "VGhlIGxvbmdlciB0aGUgd2FuZCB0aGUgYmV0dGVyLg=="
+ },
+ { "The magic word is \"XYZZY\".",
+ "VGhlIG1hZ2ljIHdvcmQgaXMgIlhZWlpZIi4="
+ },
+ { "The meek shall inherit your bones files.",
+ "VGhlIG1lZWsgc2hhbGwgaW5oZXJpdCB5b3VyIGJvbmVzIGZpbGVzLg=="
+ },
+ { "The mines are dark and deep, and I have levels to go before I sleep.",
+ "VGhlIG1pbmVzIGFyZSBkYXJrIGFuZCBkZWVwLCBhbmQgSSBoYXZlIGxldmVscyB0byBnbyBiZWZvcmUgSSBzbGVlcC4="
+ },
+ { "The use of dynamite is dangerous.",
+ "VGhlIHVzZSBvZiBkeW5hbWl0ZSBpcyBkYW5nZXJvdXMu"
+ },
+ { "There are no worms in the UNIX version.",
+ "VGhlcmUgYXJlIG5vIHdvcm1zIGluIHRoZSBVTklYIHZlcnNpb24u"
+ },
+ { "There is a trap on this level!",
+ "VGhlcmUgaXMgYSB0cmFwIG9uIHRoaXMgbGV2ZWwh"
+ },
+ { "They say that Demogorgon, Asmodeus, Orcus, Yeenoghu & Juiblex is no law firm.",
+ "VGhleSBzYXkgdGhhdCBEZW1vZ29yZ29uLCBBc21vZGV1cywgT3JjdXMsIFllZW5vZ2h1ICYgSnVpYmxleCBpcyBubyBsYXcgZmlybS4="
+ },
+ { "They say that Geryon has an evil twin, beware!",
+ "VGhleSBzYXkgdGhhdCBHZXJ5b24gaGFzIGFuIGV2aWwgdHdpbiwgYmV3YXJlIQ=="
+ },
+ { "They say that Medusa would make a terrible pet.",
+ "VGhleSBzYXkgdGhhdCBNZWR1c2Egd291bGQgbWFrZSBhIHRlcnJpYmxlIHBldC4="
+ },
+ { "They say that NetHack bugs are Seldon planned.",
+ "VGhleSBzYXkgdGhhdCBOZXRIYWNrIGJ1Z3MgYXJlIFNlbGRvbiBwbGFubmVkLg=="
+ },
+ { "They say that NetHack comes in 256 flavors.",
+ "VGhleSBzYXkgdGhhdCBOZXRIYWNrIGNvbWVzIGluIDI1NiBmbGF2b3JzLg=="
+ },
+ { "They say that NetHack is just a computer game.",
+ "VGhleSBzYXkgdGhhdCBOZXRIYWNrIGlzIGp1c3QgYSBjb21wdXRlciBnYW1lLg=="
+ },
+ { "They say that NetHack is more than just a computer game.",
+ "VGhleSBzYXkgdGhhdCBOZXRIYWNrIGlzIG1vcmUgdGhhbiBqdXN0IGEgY29tcHV0ZXIgZ2FtZS4="
+ },
+ { "They say that NetHack is never what it used to be.",
+ "VGhleSBzYXkgdGhhdCBOZXRIYWNrIGlzIG5ldmVyIHdoYXQgaXQgdXNlZCB0byBiZS4="
+ },
+ { "They say that a baby dragon is too small to hurt or help you.",
+ "VGhleSBzYXkgdGhhdCBhIGJhYnkgZHJhZ29uIGlzIHRvbyBzbWFsbCB0byBodXJ0IG9yIGhlbHAgeW91Lg=="
+ },
+ { "They say that a black pudding is simply a brown pudding gone bad.",
+ "VGhleSBzYXkgdGhhdCBhIGJsYWNrIHB1ZGRpbmcgaXMgc2ltcGx5IGEgYnJvd24gcHVkZGluZyBnb25lIGJhZC4="
+ },
+ { "They say that a black sheep has 3 bags full of wool.",
+ "VGhleSBzYXkgdGhhdCBhIGJsYWNrIHNoZWVwIGhhcyAzIGJhZ3MgZnVsbCBvZiB3b29sLg=="
+ },
+ { "They say that a blank scroll is like a blank check.",
+ "VGhleSBzYXkgdGhhdCBhIGJsYW5rIHNjcm9sbCBpcyBsaWtlIGEgYmxhbmsgY2hlY2su"
+ },
+ { "They say that a cat named Morris has nine lives.",
+ "VGhleSBzYXkgdGhhdCBhIGNhdCBuYW1lZCBNb3JyaXMgaGFzIG5pbmUgbGl2ZXMu"
+ },
+ { "They say that a desperate shopper might pay any price in a shop.",
+ "VGhleSBzYXkgdGhhdCBhIGRlc3BlcmF0ZSBzaG9wcGVyIG1pZ2h0IHBheSBhbnkgcHJpY2UgaW4gYSBzaG9wLg=="
+ },
+ { "They say that a diamond dog is everybody's best friend.",
+ "VGhleSBzYXkgdGhhdCBhIGRpYW1vbmQgZG9nIGlzIGV2ZXJ5Ym9keSdzIGJlc3QgZnJpZW5kLg=="
+ },
+ { "They say that a dwarf lord can carry a pick-axe because his armor is light.",
+ "VGhleSBzYXkgdGhhdCBhIGR3YXJmIGxvcmQgY2FuIGNhcnJ5IGEgcGljay1heGUgYmVjYXVzZSBoaXMgYXJtb3IgaXMgbGlnaHQu"
+ },
+ { "They say that a floating eye can defeat Medusa.",
+ "VGhleSBzYXkgdGhhdCBhIGZsb2F0aW5nIGV5ZSBjYW4gZGVmZWF0IE1lZHVzYS4="
+ },
+ { "They say that a fortune only has 1 line and you can't read between it.",
+ "VGhleSBzYXkgdGhhdCBhIGZvcnR1bmUgb25seSBoYXMgMSBsaW5lIGFuZCB5b3UgY2FuJ3QgcmVhZCBiZXR3ZWVuIGl0Lg=="
+ },
+ { "They say that a fortune only has 1 line, but you can read between it.",
+ "VGhleSBzYXkgdGhhdCBhIGZvcnR1bmUgb25seSBoYXMgMSBsaW5lLCBidXQgeW91IGNhbiByZWFkIGJldHdlZW4gaXQu"
+ },
+ { "They say that a fountain looks nothing like a regularly erupting geyser.",
+ "VGhleSBzYXkgdGhhdCBhIGZvdW50YWluIGxvb2tzIG5vdGhpbmcgbGlrZSBhIHJlZ3VsYXJseSBlcnVwdGluZyBnZXlzZXIu"
+ },
+ { "They say that a gold doubloon is worth more than its weight in gold.",
+ "VGhleSBzYXkgdGhhdCBhIGdvbGQgZG91Ymxvb24gaXMgd29ydGggbW9yZSB0aGFuIGl0cyB3ZWlnaHQgaW4gZ29sZC4="
+ },
+ { "They say that a grid bug won't pay a shopkeeper for zapping you in a shop.",
+ "VGhleSBzYXkgdGhhdCBhIGdyaWQgYnVnIHdvbid0IHBheSBhIHNob3BrZWVwZXIgZm9yIHphcHBpbmcgeW91IGluIGEgc2hvcC4="
+ },
+ { "They say that a gypsy could tell your fortune for a price.",
+ "VGhleSBzYXkgdGhhdCBhIGd5cHN5IGNvdWxkIHRlbGwgeW91ciBmb3J0dW5lIGZvciBhIHByaWNlLg=="
+ },
+ { "They say that a hacker named Alice once level teleported by using a mirror.",
+ "VGhleSBzYXkgdGhhdCBhIGhhY2tlciBuYW1lZCBBbGljZSBvbmNlIGxldmVsIHRlbGVwb3J0ZWQgYnkgdXNpbmcgYSBtaXJyb3Iu"
+ },
+ { "They say that a hacker named David once slew a giant with a sling and a rock.",
+ "VGhleSBzYXkgdGhhdCBhIGhhY2tlciBuYW1lZCBEYXZpZCBvbmNlIHNsZXcgYSBnaWFudCB3aXRoIGEgc2xpbmcgYW5kIGEgcm9jay4="
+ },
+ { "They say that a hacker named Dorothy once rode a fog cloud to Oz.",
+ "VGhleSBzYXkgdGhhdCBhIGhhY2tlciBuYW1lZCBEb3JvdGh5IG9uY2Ugcm9kZSBhIGZvZyBjbG91ZCB0byBPei4="
+ },
+ { "They say that a hacker named Mary once lost a white sheep in the mazes.",
+ "VGhleSBzYXkgdGhhdCBhIGhhY2tlciBuYW1lZCBNYXJ5IG9uY2UgbG9zdCBhIHdoaXRlIHNoZWVwIGluIHRoZSBtYXplcy4="
+ },
+ { "They say that a helm of brilliance is not to be taken lightly.",
+ "VGhleSBzYXkgdGhhdCBhIGhlbG0gb2YgYnJpbGxpYW5jZSBpcyBub3QgdG8gYmUgdGFrZW4gbGlnaHRseS4="
+ },
+ { "They say that a hot dog and a hell hound are the same thing.",
+ "VGhleSBzYXkgdGhhdCBhIGhvdCBkb2cgYW5kIGEgaGVsbCBob3VuZCBhcmUgdGhlIHNhbWUgdGhpbmcu"
+ },
+ { "They say that a lamp named Aladdin's Lamp contains a djinni with 3 wishes.",
+ "VGhleSBzYXkgdGhhdCBhIGxhbXAgbmFtZWQgQWxhZGRpbidzIExhbXAgY29udGFpbnMgYSBkamlubmkgd2l0aCAzIHdpc2hlcy4="
+ },
+ { "They say that a large dog named Lassie will lead you to the amulet.",
+ "VGhleSBzYXkgdGhhdCBhIGxhcmdlIGRvZyBuYW1lZCBMYXNzaWUgd2lsbCBsZWFkIHlvdSB0byB0aGUgYW11bGV0Lg=="
+ },
+ { "They say that a long sword is not a light sword.",
+ "VGhleSBzYXkgdGhhdCBhIGxvbmcgc3dvcmQgaXMgbm90IGEgbGlnaHQgc3dvcmQu"
+ },
+ { "They say that a manes won't mince words with you.",
+ "VGhleSBzYXkgdGhhdCBhIG1hbmVzIHdvbid0IG1pbmNlIHdvcmRzIHdpdGggeW91Lg=="
+ },
+ { "They say that a mind is a terrible thing to waste.",
+ "VGhleSBzYXkgdGhhdCBhIG1pbmQgaXMgYSB0ZXJyaWJsZSB0aGluZyB0byB3YXN0ZS4="
+ },
+ { "They say that a plain nymph will only wear a wire ring in one ear.",
+ "VGhleSBzYXkgdGhhdCBhIHBsYWluIG55bXBoIHdpbGwgb25seSB3ZWFyIGEgd2lyZSByaW5nIGluIG9uZSBlYXIu"
+ },
+ { "They say that a plumed hat could be a previously used crested helmet.",
+ "VGhleSBzYXkgdGhhdCBhIHBsdW1lZCBoYXQgY291bGQgYmUgYSBwcmV2aW91c2x5IHVzZWQgY3Jlc3RlZCBoZWxtZXQu"
+ },
+ { "They say that a potion of oil is difficult to grasp.",
+ "VGhleSBzYXkgdGhhdCBhIHBvdGlvbiBvZiBvaWwgaXMgZGlmZmljdWx0IHRvIGdyYXNwLg=="
+ },
+ { "They say that a potion of yogurt is a cancelled potion of sickness.",
+ "VGhleSBzYXkgdGhhdCBhIHBvdGlvbiBvZiB5b2d1cnQgaXMgYSBjYW5jZWxsZWQgcG90aW9uIG9mIHNpY2tuZXNzLg=="
+ },
+ { "They say that a purple worm is not a baby purple dragon.",
+ "VGhleSBzYXkgdGhhdCBhIHB1cnBsZSB3b3JtIGlzIG5vdCBhIGJhYnkgcHVycGxlIGRyYWdvbi4="
+ },
+ { "They say that a quivering blob tastes different than a gelatinous cube.",
+ "VGhleSBzYXkgdGhhdCBhIHF1aXZlcmluZyBibG9iIHRhc3RlcyBkaWZmZXJlbnQgdGhhbiBhIGdlbGF0aW5vdXMgY3ViZS4="
+ },
+ { "They say that a runed broadsword named Stormbringer attracts vortices.",
+ "VGhleSBzYXkgdGhhdCBhIHJ1bmVkIGJyb2Fkc3dvcmQgbmFtZWQgU3Rvcm1icmluZ2VyIGF0dHJhY3RzIHZvcnRpY2VzLg=="
+ },
+ { "They say that a scroll of summoning has other names.",
+ "VGhleSBzYXkgdGhhdCBhIHNjcm9sbCBvZiBzdW1tb25pbmcgaGFzIG90aGVyIG5hbWVzLg=="
+ },
+ { "They say that a shaman can bestow blessings but usually doesn't.",
+ "VGhleSBzYXkgdGhhdCBhIHNoYW1hbiBjYW4gYmVzdG93IGJsZXNzaW5ncyBidXQgdXN1YWxseSBkb2Vzbid0Lg=="
+ },
+ { "They say that a shaman will bless you for an eye of newt and wing of bat.",
+ "VGhleSBzYXkgdGhhdCBhIHNoYW1hbiB3aWxsIGJsZXNzIHlvdSBmb3IgYW4gZXllIG9mIG5ld3QgYW5kIHdpbmcgb2YgYmF0Lg=="
+ },
+ { "They say that a shimmering gold shield is not a polished silver shield.",
+ "VGhleSBzYXkgdGhhdCBhIHNoaW1tZXJpbmcgZ29sZCBzaGllbGQgaXMgbm90IGEgcG9saXNoZWQgc2lsdmVyIHNoaWVsZC4="
+ },
+ { "They say that a spear will hit a neo-otyugh. (Do YOU know what that is?)",
+ "VGhleSBzYXkgdGhhdCBhIHNwZWFyIHdpbGwgaGl0IGEgbmVvLW90eXVnaC4gKERvIFlPVSBrbm93IHdoYXQgdGhhdCBpcz8p"
+ },
+ { "They say that a spotted dragon is the ultimate shape changer.",
+ "VGhleSBzYXkgdGhhdCBhIHNwb3R0ZWQgZHJhZ29uIGlzIHRoZSB1bHRpbWF0ZSBzaGFwZSBjaGFuZ2VyLg=="
+ },
+ { "They say that a stethoscope is no good if you can only hear your heartbeat.",
+ "VGhleSBzYXkgdGhhdCBhIHN0ZXRob3Njb3BlIGlzIG5vIGdvb2QgaWYgeW91IGNhbiBvbmx5IGhlYXIgeW91ciBoZWFydGJlYXQu"
+ },
+ { "They say that a succubus named Suzy will sometimes warn you of danger.",
+ "VGhleSBzYXkgdGhhdCBhIHN1Y2N1YnVzIG5hbWVkIFN1enkgd2lsbCBzb21ldGltZXMgd2FybiB5b3Ugb2YgZGFuZ2VyLg=="
+ },
+ { "They say that a wand of cancellation is not like a wand of polymorph.",
+ "VGhleSBzYXkgdGhhdCBhIHdhbmQgb2YgY2FuY2VsbGF0aW9uIGlzIG5vdCBsaWtlIGEgd2FuZCBvZiBwb2x5bW9ycGgu"
+ },
+ { "They say that a wood golem named Pinocchio would be easy to control.",
+ "VGhleSBzYXkgdGhhdCBhIHdvb2QgZ29sZW0gbmFtZWQgUGlub2NjaGlvIHdvdWxkIGJlIGVhc3kgdG8gY29udHJvbC4="
+ },
+ { "They say that after killing a dragon it's time for a change of scenery.",
+ "VGhleSBzYXkgdGhhdCBhZnRlciBraWxsaW5nIGEgZHJhZ29uIGl0J3MgdGltZSBmb3IgYSBjaGFuZ2Ugb2Ygc2NlbmVyeS4="
+ },
+ { "They say that an amulet of strangulation is worse than ring around the collar.",
+ "VGhleSBzYXkgdGhhdCBhbiBhbXVsZXQgb2Ygc3RyYW5ndWxhdGlvbiBpcyB3b3JzZSB0aGFuIHJpbmcgYXJvdW5kIHRoZSBjb2xsYXIu"
+ },
+ { "They say that an attic is the best place to hide your toys.",
+ "VGhleSBzYXkgdGhhdCBhbiBhdHRpYyBpcyB0aGUgYmVzdCBwbGFjZSB0byBoaWRlIHlvdXIgdG95cy4="
+ },
+ { "They say that an axe named Cleaver once belonged to a hacker named Beaver.",
+ "VGhleSBzYXkgdGhhdCBhbiBheGUgbmFtZWQgQ2xlYXZlciBvbmNlIGJlbG9uZ2VkIHRvIGEgaGFja2VyIG5hbWVkIEJlYXZlci4="
+ },
+ { "They say that an eye of newt and a wing of bat are double the trouble.",
+ "VGhleSBzYXkgdGhhdCBhbiBleWUgb2YgbmV3dCBhbmQgYSB3aW5nIG9mIGJhdCBhcmUgZG91YmxlIHRoZSB0cm91YmxlLg=="
+ },
+ { "They say that an incubus named Izzy sometimes makes women feel sensitive.",
+ "VGhleSBzYXkgdGhhdCBhbiBpbmN1YnVzIG5hbWVkIEl6enkgc29tZXRpbWVzIG1ha2VzIHdvbWVuIGZlZWwgc2Vuc2l0aXZlLg=="
+ },
+ { "They say that an opulent throne room is rarely a place to wish you'd be in.",
+ "VGhleSBzYXkgdGhhdCBhbiBvcHVsZW50IHRocm9uZSByb29tIGlzIHJhcmVseSBhIHBsYWNlIHRvIHdpc2ggeW91J2QgYmUgaW4u"
+ },
+ { "They say that an unlucky hacker once had a nose bleed at an altar and died.",
+ "VGhleSBzYXkgdGhhdCBhbiB1bmx1Y2t5IGhhY2tlciBvbmNlIGhhZCBhIG5vc2UgYmxlZWQgYXQgYW4gYWx0YXIgYW5kIGRpZWQu"
+ },
+ { "They say that and they say this but they never say never, never!",
+ "VGhleSBzYXkgdGhhdCBhbmQgdGhleSBzYXkgdGhpcyBidXQgdGhleSBuZXZlciBzYXkgbmV2ZXIsIG5ldmVyIQ=="
+ },
+ { "They say that any quantum mechanic knows that speed kills.",
+ "VGhleSBzYXkgdGhhdCBhbnkgcXVhbnR1bSBtZWNoYW5pYyBrbm93cyB0aGF0IHNwZWVkIGtpbGxzLg=="
+ },
+ { "They say that applying a unicorn horn means you've missed the point.",
+ "VGhleSBzYXkgdGhhdCBhcHBseWluZyBhIHVuaWNvcm4gaG9ybiBtZWFucyB5b3UndmUgbWlzc2VkIHRoZSBwb2ludC4="
+ },
+ { "They say that blue stones are radioactive, beware.",
+ "VGhleSBzYXkgdGhhdCBibHVlIHN0b25lcyBhcmUgcmFkaW9hY3RpdmUsIGJld2FyZS4="
+ },
+ { "They say that building a dungeon is a team effort.",
+ "VGhleSBzYXkgdGhhdCBidWlsZGluZyBhIGR1bmdlb24gaXMgYSB0ZWFtIGVmZm9ydC4="
+ },
+ { "They say that chaotic characters never get a kick out of altars.",
+ "VGhleSBzYXkgdGhhdCBjaGFvdGljIGNoYXJhY3RlcnMgbmV2ZXIgZ2V0IGEga2ljayBvdXQgb2YgYWx0YXJzLg=="
+ },
+ { "They say that collapsing a dungeon often creates a panic.",
+ "VGhleSBzYXkgdGhhdCBjb2xsYXBzaW5nIGEgZHVuZ2VvbiBvZnRlbiBjcmVhdGVzIGEgcGFuaWMu"
+ },
+ { "They say that counting your eggs before they hatch shows that you care.",
+ "VGhleSBzYXkgdGhhdCBjb3VudGluZyB5b3VyIGVnZ3MgYmVmb3JlIHRoZXkgaGF0Y2ggc2hvd3MgdGhhdCB5b3UgY2FyZS4="
+ },
+ { "They say that dipping a bag of tricks in a fountain won't make it an icebox.",
+ "VGhleSBzYXkgdGhhdCBkaXBwaW5nIGEgYmFnIG9mIHRyaWNrcyBpbiBhIGZvdW50YWluIHdvbid0IG1ha2UgaXQgYW4gaWNlYm94Lg=="
+ },
+ { "They say that dipping an eel and brown mold in hot water makes bouillabaisse.",
+ "VGhleSBzYXkgdGhhdCBkaXBwaW5nIGFuIGVlbCBhbmQgYnJvd24gbW9sZCBpbiBob3Qgd2F0ZXIgbWFrZXMgYm91aWxsYWJhaXNzZS4="
+ },
+ { "They say that donating a doubloon is extremely pious charity.",
+ "VGhleSBzYXkgdGhhdCBkb25hdGluZyBhIGRvdWJsb29uIGlzIGV4dHJlbWVseSBwaW91cyBjaGFyaXR5Lg=="
+ },
+ { "They say that eating royal jelly attracts grizzly owlbears.",
+ "VGhleSBzYXkgdGhhdCBlYXRpbmcgcm95YWwgamVsbHkgYXR0cmFjdHMgZ3JpenpseSBvd2xiZWFycy4="
+ },
+ { "They say that eggs, pancakes and juice are just a mundane breakfast.",
+ "VGhleSBzYXkgdGhhdCBlZ2dzLCBwYW5jYWtlcyBhbmQganVpY2UgYXJlIGp1c3QgYSBtdW5kYW5lIGJyZWFrZmFzdC4="
+ },
+ { "They say that everyone knows why Medusa stands alone in the dark.",
+ "VGhleSBzYXkgdGhhdCBldmVyeW9uZSBrbm93cyB3aHkgTWVkdXNhIHN0YW5kcyBhbG9uZSBpbiB0aGUgZGFyay4="
+ },
+ { "They say that everyone wanted rec.games.hack to undergo a name change.",
+ "VGhleSBzYXkgdGhhdCBldmVyeW9uZSB3YW50ZWQgcmVjLmdhbWVzLmhhY2sgdG8gdW5kZXJnbyBhIG5hbWUgY2hhbmdlLg=="
+ },
+ { "They say that finding a winning strategy is a deliberate move on your part.",
+ "VGhleSBzYXkgdGhhdCBmaW5kaW5nIGEgd2lubmluZyBzdHJhdGVneSBpcyBhIGRlbGliZXJhdGUgbW92ZSBvbiB5b3VyIHBhcnQu"
+ },
+ { "They say that finding worthless glass is worth something.",
+ "VGhleSBzYXkgdGhhdCBmaW5kaW5nIHdvcnRobGVzcyBnbGFzcyBpcyB3b3J0aCBzb21ldGhpbmcu"
+ },
+ { "They say that fortune cookies are food for thought.",
+ "VGhleSBzYXkgdGhhdCBmb3J0dW5lIGNvb2tpZXMgYXJlIGZvb2QgZm9yIHRob3VnaHQu"
+ },
+ { "They say that gold is only wasted on a pet dragon.",
+ "VGhleSBzYXkgdGhhdCBnb2xkIGlzIG9ubHkgd2FzdGVkIG9uIGEgcGV0IGRyYWdvbi4="
+ },
+ { "They say that good things come to those that wait.",
+ "VGhleSBzYXkgdGhhdCBnb29kIHRoaW5ncyBjb21lIHRvIHRob3NlIHRoYXQgd2FpdC4="
+ },
+ { "They say that greased objects will slip out of monsters' hands.",
+ "VGhleSBzYXkgdGhhdCBncmVhc2VkIG9iamVjdHMgd2lsbCBzbGlwIG91dCBvZiBtb25zdGVycycgaGFuZHMu"
+ },
+ { "They say that if you can't spell then you'll wish you had a spell book.",
+ "VGhleSBzYXkgdGhhdCBpZiB5b3UgY2FuJ3Qgc3BlbGwgdGhlbiB5b3UnbGwgd2lzaCB5b3UgaGFkIGEgc3BlbGwgYm9vay4="
+ },
+ { "They say that if you live by the sword, you'll die by the sword.",
+ "VGhleSBzYXkgdGhhdCBpZiB5b3UgbGl2ZSBieSB0aGUgc3dvcmQsIHlvdSdsbCBkaWUgYnkgdGhlIHN3b3JkLg=="
+ },
+ { "They say that if you play like a monster you'll have a better game.",
+ "VGhleSBzYXkgdGhhdCBpZiB5b3UgcGxheSBsaWtlIGEgbW9uc3RlciB5b3UnbGwgaGF2ZSBhIGJldHRlciBnYW1lLg=="
+ },
+ { "They say that if you sleep with a demon you might awake with a headache.",
+ "VGhleSBzYXkgdGhhdCBpZiB5b3Ugc2xlZXAgd2l0aCBhIGRlbW9uIHlvdSBtaWdodCBhd2FrZSB3aXRoIGEgaGVhZGFjaGUu"
+ },
+ { "They say that if you step on a crack you could break your mother's back.",
+ "VGhleSBzYXkgdGhhdCBpZiB5b3Ugc3RlcCBvbiBhIGNyYWNrIHlvdSBjb3VsZCBicmVhayB5b3VyIG1vdGhlcidzIGJhY2su"
+ },
+ { "They say that if you're invisible you can still be heard!",
+ "VGhleSBzYXkgdGhhdCBpZiB5b3UncmUgaW52aXNpYmxlIHlvdSBjYW4gc3RpbGwgYmUgaGVhcmQh"
+ },
+ { "They say that if you're lucky you can feel the runes on a scroll.",
+ "VGhleSBzYXkgdGhhdCBpZiB5b3UncmUgbHVja3kgeW91IGNhbiBmZWVsIHRoZSBydW5lcyBvbiBhIHNjcm9sbC4="
+ },
+ { "They say that in the big picture gold is only small change.",
+ "VGhleSBzYXkgdGhhdCBpbiB0aGUgYmlnIHBpY3R1cmUgZ29sZCBpcyBvbmx5IHNtYWxsIGNoYW5nZS4="
+ },
+ { "They say that in the dungeon it's not what you know that really matters.",
+ "VGhleSBzYXkgdGhhdCBpbiB0aGUgZHVuZ2VvbiBpdCdzIG5vdCB3aGF0IHlvdSBrbm93IHRoYXQgcmVhbGx5IG1hdHRlcnMu"
+ },
+ { "They say that in the dungeon moon rocks are really dilithium crystals.",
+ "VGhleSBzYXkgdGhhdCBpbiB0aGUgZHVuZ2VvbiBtb29uIHJvY2tzIGFyZSByZWFsbHkgZGlsaXRoaXVtIGNyeXN0YWxzLg=="
+ },
+ { "They say that in the dungeon the boorish customer is never right.",
+ "VGhleSBzYXkgdGhhdCBpbiB0aGUgZHVuZ2VvbiB0aGUgYm9vcmlzaCBjdXN0b21lciBpcyBuZXZlciByaWdodC4="
+ },
+ { "They say that in the dungeon you don't need a watch to tell time.",
+ "VGhleSBzYXkgdGhhdCBpbiB0aGUgZHVuZ2VvbiB5b3UgZG9uJ3QgbmVlZCBhIHdhdGNoIHRvIHRlbGwgdGltZS4="
+ },
+ { "They say that in the dungeon you need something old, new, burrowed and blue.",
+ "VGhleSBzYXkgdGhhdCBpbiB0aGUgZHVuZ2VvbiB5b3UgbmVlZCBzb21ldGhpbmcgb2xkLCBuZXcsIGJ1cnJvd2VkIGFuZCBibHVlLg=="
+ },
+ { "They say that in the dungeon you should always count your blessings.",
+ "VGhleSBzYXkgdGhhdCBpbiB0aGUgZHVuZ2VvbiB5b3Ugc2hvdWxkIGFsd2F5cyBjb3VudCB5b3VyIGJsZXNzaW5ncy4="
+ },
+ { "They say that iron golem plate mail isn't worth wishing for.",
+ "VGhleSBzYXkgdGhhdCBpcm9uIGdvbGVtIHBsYXRlIG1haWwgaXNuJ3Qgd29ydGggd2lzaGluZyBmb3Iu"
+ },
+ { "They say that it takes four quarterstaffs to make one staff.",
+ "VGhleSBzYXkgdGhhdCBpdCB0YWtlcyBmb3VyIHF1YXJ0ZXJzdGFmZnMgdG8gbWFrZSBvbmUgc3RhZmYu"
+ },
+ { "They say that it's not over till the fat ladies sing.",
+ "VGhleSBzYXkgdGhhdCBpdCdzIG5vdCBvdmVyIHRpbGwgdGhlIGZhdCBsYWRpZXMgc2luZy4="
+ },
+ { "They say that it's not over till the fat lady shouts `Off with its head'.",
+ "VGhleSBzYXkgdGhhdCBpdCdzIG5vdCBvdmVyIHRpbGwgdGhlIGZhdCBsYWR5IHNob3V0cyBgT2ZmIHdpdGggaXRzIGhlYWQnLg=="
+ },
+ { "They say that kicking a heavy statue is really a dumb move.",
+ "VGhleSBzYXkgdGhhdCBraWNraW5nIGEgaGVhdnkgc3RhdHVlIGlzIHJlYWxseSBhIGR1bWIgbW92ZS4="
+ },
+ { "They say that kicking a valuable gem doesn't seem to make sense.",
+ "VGhleSBzYXkgdGhhdCBraWNraW5nIGEgdmFsdWFibGUgZ2VtIGRvZXNuJ3Qgc2VlbSB0byBtYWtlIHNlbnNlLg=="
+ },
+ { "They say that leprechauns know Latin and you should too.",
+ "VGhleSBzYXkgdGhhdCBsZXByZWNoYXVucyBrbm93IExhdGluIGFuZCB5b3Ugc2hvdWxkIHRvby4="
+ },
+ { "They say that minotaurs get lost outside of the mazes.",
+ "VGhleSBzYXkgdGhhdCBtaW5vdGF1cnMgZ2V0IGxvc3Qgb3V0c2lkZSBvZiB0aGUgbWF6ZXMu"
+ },
+ { "They say that most trolls are born again.",
+ "VGhleSBzYXkgdGhhdCBtb3N0IHRyb2xscyBhcmUgYm9ybiBhZ2Fpbi4="
+ },
+ { "They say that naming your cat Garfield will make you more attractive.",
+ "VGhleSBzYXkgdGhhdCBuYW1pbmcgeW91ciBjYXQgR2FyZmllbGQgd2lsbCBtYWtlIHlvdSBtb3JlIGF0dHJhY3RpdmUu"
+ },
+ { "They say that no one knows everything about everything in the dungeon.",
+ "VGhleSBzYXkgdGhhdCBubyBvbmUga25vd3MgZXZlcnl0aGluZyBhYm91dCBldmVyeXRoaW5nIGluIHRoZSBkdW5nZW9uLg=="
+ },
+ { "They say that no one plays NetHack just for the fun of it.",
+ "VGhleSBzYXkgdGhhdCBubyBvbmUgcGxheXMgTmV0SGFjayBqdXN0IGZvciB0aGUgZnVuIG9mIGl0Lg=="
+ },
+ { "They say that no one really subscribes to rec.games.roguelike.nethack.",
+ "VGhleSBzYXkgdGhhdCBubyBvbmUgcmVhbGx5IHN1YnNjcmliZXMgdG8gcmVjLmdhbWVzLnJvZ3VlbGlrZS5uZXRoYWNrLg=="
+ },
+ { "They say that no one will admit to starting a rumor.",
+ "VGhleSBzYXkgdGhhdCBubyBvbmUgd2lsbCBhZG1pdCB0byBzdGFydGluZyBhIHJ1bW9yLg=="
+ },
+ { "They say that nurses sometimes carry scalpels and never use them.",
+ "VGhleSBzYXkgdGhhdCBudXJzZXMgc29tZXRpbWVzIGNhcnJ5IHNjYWxwZWxzIGFuZCBuZXZlciB1c2UgdGhlbS4="
+ },
+ { "They say that once you've met one wizard you've met them all.",
+ "VGhleSBzYXkgdGhhdCBvbmNlIHlvdSd2ZSBtZXQgb25lIHdpemFyZCB5b3UndmUgbWV0IHRoZW0gYWxsLg=="
+ },
+ { "They say that one troll is worth 10,000 newts.",
+ "VGhleSBzYXkgdGhhdCBvbmUgdHJvbGwgaXMgd29ydGggMTAsMDAwIG5ld3RzLg=="
+ },
+ { "They say that only David can find the zoo!",
+ "VGhleSBzYXkgdGhhdCBvbmx5IERhdmlkIGNhbiBmaW5kIHRoZSB6b28h"
+ },
+ { "They say that only angels play their harps for their pets.",
+ "VGhleSBzYXkgdGhhdCBvbmx5IGFuZ2VscyBwbGF5IHRoZWlyIGhhcnBzIGZvciB0aGVpciBwZXRzLg=="
+ },
+ { "They say that only big spenders carry gold.",
+ "VGhleSBzYXkgdGhhdCBvbmx5IGJpZyBzcGVuZGVycyBjYXJyeSBnb2xkLg=="
+ },
+ { "They say that orc shamans are healthy, wealthy and wise.",
+ "VGhleSBzYXkgdGhhdCBvcmMgc2hhbWFucyBhcmUgaGVhbHRoeSwgd2VhbHRoeSBhbmQgd2lzZS4="
+ },
+ { "They say that playing NetHack is like walking into a death trap.",
+ "VGhleSBzYXkgdGhhdCBwbGF5aW5nIE5ldEhhY2sgaXMgbGlrZSB3YWxraW5nIGludG8gYSBkZWF0aCB0cmFwLg=="
+ },
+ { "They say that problem breathing is best treated by a proper diet.",
+ "VGhleSBzYXkgdGhhdCBwcm9ibGVtIGJyZWF0aGluZyBpcyBiZXN0IHRyZWF0ZWQgYnkgYSBwcm9wZXIgZGlldC4="
+ },
+ { "They say that quaffing many potions of levitation can give you a headache.",
+ "VGhleSBzYXkgdGhhdCBxdWFmZmluZyBtYW55IHBvdGlvbnMgb2YgbGV2aXRhdGlvbiBjYW4gZ2l2ZSB5b3UgYSBoZWFkYWNoZS4="
+ },
+ { "They say that queen bees get that way by eating royal jelly.",
+ "VGhleSBzYXkgdGhhdCBxdWVlbiBiZWVzIGdldCB0aGF0IHdheSBieSBlYXRpbmcgcm95YWwgamVsbHku"
+ },
+ { "They say that reading a scare monster scroll is the same as saying Elbereth.",
+ "VGhleSBzYXkgdGhhdCByZWFkaW5nIGEgc2NhcmUgbW9uc3RlciBzY3JvbGwgaXMgdGhlIHNhbWUgYXMgc2F5aW5nIEVsYmVyZXRoLg=="
+ },
+ { "They say that real hackers always are controlled.",
+ "VGhleSBzYXkgdGhhdCByZWFsIGhhY2tlcnMgYWx3YXlzIGFyZSBjb250cm9sbGVkLg=="
+ },
+ { "They say that real hackers never sleep.",
+ "VGhleSBzYXkgdGhhdCByZWFsIGhhY2tlcnMgbmV2ZXIgc2xlZXAu"
+ },
+ { "They say that shopkeepers are insured by Croesus himself!",
+ "VGhleSBzYXkgdGhhdCBzaG9wa2VlcGVycyBhcmUgaW5zdXJlZCBieSBDcm9lc3VzIGhpbXNlbGYh"
+ },
+ { "They say that shopkeepers never carry more than 20 gold pieces, at night.",
+ "VGhleSBzYXkgdGhhdCBzaG9wa2VlcGVycyBuZXZlciBjYXJyeSBtb3JlIHRoYW4gMjAgZ29sZCBwaWVjZXMsIGF0IG5pZ2h0Lg=="
+ },
+ { "They say that shopkeepers never sell blessed potions of invisibility.",
+ "VGhleSBzYXkgdGhhdCBzaG9wa2VlcGVycyBuZXZlciBzZWxsIGJsZXNzZWQgcG90aW9ucyBvZiBpbnZpc2liaWxpdHku"
+ },
+ { "They say that soldiers wear kid gloves and silly helmets.",
+ "VGhleSBzYXkgdGhhdCBzb2xkaWVycyB3ZWFyIGtpZCBnbG92ZXMgYW5kIHNpbGx5IGhlbG1ldHMu"
+ },
+ { "They say that some Kops are on the take.",
+ "VGhleSBzYXkgdGhhdCBzb21lIEtvcHMgYXJlIG9uIHRoZSB0YWtlLg=="
+ },
+ { "They say that some guards' palms can be greased.",
+ "VGhleSBzYXkgdGhhdCBzb21lIGd1YXJkcycgcGFsbXMgY2FuIGJlIGdyZWFzZWQu"
+ },
+ { "They say that some monsters may kiss your boots to stop your drum playing.",
+ "VGhleSBzYXkgdGhhdCBzb21lIG1vbnN0ZXJzIG1heSBraXNzIHlvdXIgYm9vdHMgdG8gc3RvcCB5b3VyIGRydW0gcGxheWluZy4="
+ },
+ { "They say that sometimes you can be the hit of the party when playing a horn.",
+ "VGhleSBzYXkgdGhhdCBzb21ldGltZXMgeW91IGNhbiBiZSB0aGUgaGl0IG9mIHRoZSBwYXJ0eSB3aGVuIHBsYXlpbmcgYSBob3JuLg=="
+ },
+ { "They say that the NetHack gods generally welcome your sacrifices.",
+ "VGhleSBzYXkgdGhhdCB0aGUgTmV0SGFjayBnb2RzIGdlbmVyYWxseSB3ZWxjb21lIHlvdXIgc2FjcmlmaWNlcy4="
+ },
+ { "They say that the Three Rings are named Vilya, Nenya and Narya.",
+ "VGhleSBzYXkgdGhhdCB0aGUgVGhyZWUgUmluZ3MgYXJlIG5hbWVkIFZpbHlhLCBOZW55YSBhbmQgTmFyeWEu"
+ },
+ { "They say that the Wizard of Yendor has a death wish.",
+ "VGhleSBzYXkgdGhhdCB0aGUgV2l6YXJkIG9mIFllbmRvciBoYXMgYSBkZWF0aCB3aXNoLg=="
+ },
+ { "They say that the `hair of the dog' is sometimes an effective remedy.",
+ "VGhleSBzYXkgdGhhdCB0aGUgYGhhaXIgb2YgdGhlIGRvZycgaXMgc29tZXRpbWVzIGFuIGVmZmVjdGl2ZSByZW1lZHku"
+ },
+ { "They say that the best time to save your game is now before its too late.",
+ "VGhleSBzYXkgdGhhdCB0aGUgYmVzdCB0aW1lIHRvIHNhdmUgeW91ciBnYW1lIGlzIG5vdyBiZWZvcmUgaXRzIHRvbyBsYXRlLg=="
+ },
+ { "They say that the biggest obstacle in NetHack is your mind.",
+ "VGhleSBzYXkgdGhhdCB0aGUgYmlnZ2VzdCBvYnN0YWNsZSBpbiBOZXRIYWNrIGlzIHlvdXIgbWluZC4="
+ },
+ { "They say that the gods are angry when they hit you with objects.",
+ "VGhleSBzYXkgdGhhdCB0aGUgZ29kcyBhcmUgYW5ncnkgd2hlbiB0aGV5IGhpdCB5b3Ugd2l0aCBvYmplY3RzLg=="
+ },
+ { "They say that the priesthood are specially favored by the gods.",
+ "VGhleSBzYXkgdGhhdCB0aGUgcHJpZXN0aG9vZCBhcmUgc3BlY2lhbGx5IGZhdm9yZWQgYnkgdGhlIGdvZHMu"
+ },
+ { "They say that the way to make a unicorn happy is to give it what it wants.",
+ "VGhleSBzYXkgdGhhdCB0aGUgd2F5IHRvIG1ha2UgYSB1bmljb3JuIGhhcHB5IGlzIHRvIGdpdmUgaXQgd2hhdCBpdCB3YW50cy4="
+ },
+ { "They say that there are no black or white stones, only gray.",
+ "VGhleSBzYXkgdGhhdCB0aGVyZSBhcmUgbm8gYmxhY2sgb3Igd2hpdGUgc3RvbmVzLCBvbmx5IGdyYXku"
+ },
+ { "They say that there are no skeletons hence there are no skeleton keys.",
+ "VGhleSBzYXkgdGhhdCB0aGVyZSBhcmUgbm8gc2tlbGV0b25zIGhlbmNlIHRoZXJlIGFyZSBubyBza2VsZXRvbiBrZXlzLg=="
+ },
+ { "They say that there is a clever rogue in every hacker just dying to escape.",
+ "VGhleSBzYXkgdGhhdCB0aGVyZSBpcyBhIGNsZXZlciByb2d1ZSBpbiBldmVyeSBoYWNrZXIganVzdCBkeWluZyB0byBlc2NhcGUu"
+ },
+ { "They say that there is no such thing as free advice.",
+ "VGhleSBzYXkgdGhhdCB0aGVyZSBpcyBubyBzdWNoIHRoaW5nIGFzIGZyZWUgYWR2aWNlLg=="
+ },
+ { "They say that there is only one way to win at NetHack.",
+ "VGhleSBzYXkgdGhhdCB0aGVyZSBpcyBvbmx5IG9uZSB3YXkgdG8gd2luIGF0IE5ldEhhY2su"
+ },
+ { "They say that there once was a fearsome chaotic samurai named Luk No.",
+ "VGhleSBzYXkgdGhhdCB0aGVyZSBvbmNlIHdhcyBhIGZlYXJzb21lIGNoYW90aWMgc2FtdXJhaSBuYW1lZCBMdWsgTm8u"
+ },
+ { "They say that there was a time when cursed holy water wasn't water.",
+ "VGhleSBzYXkgdGhhdCB0aGVyZSB3YXMgYSB0aW1lIHdoZW4gY3Vyc2VkIGhvbHkgd2F0ZXIgd2Fzbid0IHdhdGVyLg=="
+ },
+ { "They say that there's no point in crying over a gray ooze.",
+ "VGhleSBzYXkgdGhhdCB0aGVyZSdzIG5vIHBvaW50IGluIGNyeWluZyBvdmVyIGEgZ3JheSBvb3plLg=="
+ },
+ { "They say that there's only hope left after you've opened Pandora's box.",
+ "VGhleSBzYXkgdGhhdCB0aGVyZSdzIG9ubHkgaG9wZSBsZWZ0IGFmdGVyIHlvdSd2ZSBvcGVuZWQgUGFuZG9yYSdzIGJveC4="
+ },
+ { "They say that trapdoors should always be marked `Caution: Trap Door'.",
+ "VGhleSBzYXkgdGhhdCB0cmFwZG9vcnMgc2hvdWxkIGFsd2F5cyBiZSBtYXJrZWQgYENhdXRpb246IFRyYXAgRG9vcicu"
+ },
+ { "They say that using an amulet of change isn't a difficult operation.",
+ "VGhleSBzYXkgdGhhdCB1c2luZyBhbiBhbXVsZXQgb2YgY2hhbmdlIGlzbid0IGEgZGlmZmljdWx0IG9wZXJhdGlvbi4="
+ },
+ { "They say that water walking boots are better if you are fast like Hermes.",
+ "VGhleSBzYXkgdGhhdCB3YXRlciB3YWxraW5nIGJvb3RzIGFyZSBiZXR0ZXIgaWYgeW91IGFyZSBmYXN0IGxpa2UgSGVybWVzLg=="
+ },
+ { "They say that when you wear a circular amulet you might resemble a troll.",
+ "VGhleSBzYXkgdGhhdCB3aGVuIHlvdSB3ZWFyIGEgY2lyY3VsYXIgYW11bGV0IHlvdSBtaWdodCByZXNlbWJsZSBhIHRyb2xsLg=="
+ },
+ { "They say that when you're hungry you can get a pizza in 30 moves or it's free.",
+ "VGhleSBzYXkgdGhhdCB3aGVuIHlvdSdyZSBodW5ncnkgeW91IGNhbiBnZXQgYSBwaXp6YSBpbiAzMCBtb3ZlcyBvciBpdCdzIGZyZWUu"
+ },
+ { "They say that when your god is angry you should try another one.",
+ "VGhleSBzYXkgdGhhdCB3aGVuIHlvdXIgZ29kIGlzIGFuZ3J5IHlvdSBzaG91bGQgdHJ5IGFub3RoZXIgb25lLg=="
+ },
+ { "They say that wielding a unicorn horn takes strength.",
+ "VGhleSBzYXkgdGhhdCB3aWVsZGluZyBhIHVuaWNvcm4gaG9ybiB0YWtlcyBzdHJlbmd0aC4="
+ },
+ { "They say that with speed boots you never worry about hit and run accidents.",
+ "VGhleSBzYXkgdGhhdCB3aXRoIHNwZWVkIGJvb3RzIHlvdSBuZXZlciB3b3JyeSBhYm91dCBoaXQgYW5kIHJ1biBhY2NpZGVudHMu"
+ },
+ { "They say that you can defeat a killer bee with a unicorn horn.",
+ "VGhleSBzYXkgdGhhdCB5b3UgY2FuIGRlZmVhdCBhIGtpbGxlciBiZWUgd2l0aCBhIHVuaWNvcm4gaG9ybi4="
+ },
+ { "They say that you can only cross the River Styx in Charon's boat.",
+ "VGhleSBzYXkgdGhhdCB5b3UgY2FuIG9ubHkgY3Jvc3MgdGhlIFJpdmVyIFN0eXggaW4gQ2hhcm9uJ3MgYm9hdC4="
+ },
+ { "They say that you can only kill a lich once and then you'd better be careful.",
+ "VGhleSBzYXkgdGhhdCB5b3UgY2FuIG9ubHkga2lsbCBhIGxpY2ggb25jZSBhbmQgdGhlbiB5b3UnZCBiZXR0ZXIgYmUgY2FyZWZ1bC4="
+ },
+ { "They say that you can only wish for things you've already had.",
+ "VGhleSBzYXkgdGhhdCB5b3UgY2FuIG9ubHkgd2lzaCBmb3IgdGhpbmdzIHlvdSd2ZSBhbHJlYWR5IGhhZC4="
+ },
+ { "They say that you can train a cat by talking gently to it.",
+ "VGhleSBzYXkgdGhhdCB5b3UgY2FuIHRyYWluIGEgY2F0IGJ5IHRhbGtpbmcgZ2VudGx5IHRvIGl0Lg=="
+ },
+ { "They say that you can train a dog by talking firmly to it.",
+ "VGhleSBzYXkgdGhhdCB5b3UgY2FuIHRyYWluIGEgZG9nIGJ5IHRhbGtpbmcgZmlybWx5IHRvIGl0Lg=="
+ },
+ { "They say that you can trust your gold with the king.",
+ "VGhleSBzYXkgdGhhdCB5b3UgY2FuIHRydXN0IHlvdXIgZ29sZCB3aXRoIHRoZSBraW5nLg=="
+ },
+ { "They say that you can't wipe your greasy bare hands on a blank scroll.",
+ "VGhleSBzYXkgdGhhdCB5b3UgY2FuJ3Qgd2lwZSB5b3VyIGdyZWFzeSBiYXJlIGhhbmRzIG9uIGEgYmxhbmsgc2Nyb2xsLg=="
+ },
+ { "They say that you cannot trust scrolls of rumor.",
+ "VGhleSBzYXkgdGhhdCB5b3UgY2Fubm90IHRydXN0IHNjcm9sbHMgb2YgcnVtb3Iu"
+ },
+ { "They say that you could fall head over heels for an energy vortex.",
+ "VGhleSBzYXkgdGhhdCB5b3UgY291bGQgZmFsbCBoZWFkIG92ZXIgaGVlbHMgZm9yIGFuIGVuZXJneSB2b3J0ZXgu"
+ },
+ { "They say that you need a key in order to open locked doors.",
+ "VGhleSBzYXkgdGhhdCB5b3UgbmVlZCBhIGtleSBpbiBvcmRlciB0byBvcGVuIGxvY2tlZCBkb29ycy4="
+ },
+ { "They say that you need a mirror to notice a mimic in an antique shop.",
+ "VGhleSBzYXkgdGhhdCB5b3UgbmVlZCBhIG1pcnJvciB0byBub3RpY2UgYSBtaW1pYyBpbiBhbiBhbnRpcXVlIHNob3Au"
+ },
+ { "They say that you really can use a pick-axe unless you really can't.",
+ "VGhleSBzYXkgdGhhdCB5b3UgcmVhbGx5IGNhbiB1c2UgYSBwaWNrLWF4ZSB1bmxlc3MgeW91IHJlYWxseSBjYW4ndC4="
+ },
+ { "They say that you should always store your tools in the cellar.",
+ "VGhleSBzYXkgdGhhdCB5b3Ugc2hvdWxkIGFsd2F5cyBzdG9yZSB5b3VyIHRvb2xzIGluIHRoZSBjZWxsYXIu"
+ },
+ { "They say that you should be careful while climbing the ladder to success.",
+ "VGhleSBzYXkgdGhhdCB5b3Ugc2hvdWxkIGJlIGNhcmVmdWwgd2hpbGUgY2xpbWJpbmcgdGhlIGxhZGRlciB0byBzdWNjZXNzLg=="
+ },
+ { "They say that you should call your armor `rustproof'.",
+ "VGhleSBzYXkgdGhhdCB5b3Ugc2hvdWxkIGNhbGwgeW91ciBhcm1vciBgcnVzdHByb29mJy4="
+ },
+ { "They say that you should name your dog Spuds to have a cool pet.",
+ "VGhleSBzYXkgdGhhdCB5b3Ugc2hvdWxkIG5hbWUgeW91ciBkb2cgU3B1ZHMgdG8gaGF2ZSBhIGNvb2wgcGV0Lg=="
+ },
+ { "They say that you should name your weapon after your first monster kill.",
+ "VGhleSBzYXkgdGhhdCB5b3Ugc2hvdWxkIG5hbWUgeW91ciB3ZWFwb24gYWZ0ZXIgeW91ciBmaXJzdCBtb25zdGVyIGtpbGwu"
+ },
+ { "They say that you should never introduce a rope golem to a succubus.",
+ "VGhleSBzYXkgdGhhdCB5b3Ugc2hvdWxkIG5ldmVyIGludHJvZHVjZSBhIHJvcGUgZ29sZW0gdG8gYSBzdWNjdWJ1cy4="
+ },
+ { "They say that you should never sleep near invisible ring wraiths.",
+ "VGhleSBzYXkgdGhhdCB5b3Ugc2hvdWxkIG5ldmVyIHNsZWVwIG5lYXIgaW52aXNpYmxlIHJpbmcgd3JhaXRocy4="
+ },
+ { "They say that you should never try to leave the dungeon with a bag of gems.",
+ "VGhleSBzYXkgdGhhdCB5b3Ugc2hvdWxkIG5ldmVyIHRyeSB0byBsZWF2ZSB0aGUgZHVuZ2VvbiB3aXRoIGEgYmFnIG9mIGdlbXMu"
+ },
+ { "They say that you should remove your armor before sitting on a throne.",
+ "VGhleSBzYXkgdGhhdCB5b3Ugc2hvdWxkIHJlbW92ZSB5b3VyIGFybW9yIGJlZm9yZSBzaXR0aW5nIG9uIGEgdGhyb25lLg=="
+ },
+ { "This fortune cookie is copy protected.",
+ "VGhpcyBmb3J0dW5lIGNvb2tpZSBpcyBjb3B5IHByb3RlY3RlZC4="
+ },
+ { "This fortune cookie is the property of Fortune Cookies, Inc.",
+ "VGhpcyBmb3J0dW5lIGNvb2tpZSBpcyB0aGUgcHJvcGVydHkgb2YgRm9ydHVuZSBDb29raWVzLCBJbmMu"
+ },
+ { "Tired? Try a scroll of charging on yourself.",
+ "VGlyZWQ/IFRyeSBhIHNjcm9sbCBvZiBjaGFyZ2luZyBvbiB5b3Vyc2VsZi4="
+ },
+ { "To achieve the next higher rating, you need 3 more points.",
+ "VG8gYWNoaWV2ZSB0aGUgbmV4dCBoaWdoZXIgcmF0aW5nLCB5b3UgbmVlZCAzIG1vcmUgcG9pbnRzLg=="
+ },
+ { "To reach heaven, escape the dungeon while wearing a ring of levitation.",
+ "VG8gcmVhY2ggaGVhdmVuLCBlc2NhcGUgdGhlIGR1bmdlb24gd2hpbGUgd2VhcmluZyBhIHJpbmcgb2YgbGV2aXRhdGlvbi4="
+ },
+ { "Tourists wear shirts loud enough to wake the dead.",
+ "VG91cmlzdHMgd2VhciBzaGlydHMgbG91ZCBlbm91Z2ggdG8gd2FrZSB0aGUgZGVhZC4="
+ },
+ { "Try calling your katana Moulinette.",
+ "VHJ5IGNhbGxpbmcgeW91ciBrYXRhbmEgTW91bGluZXR0ZS4="
+ },
+ { "Ulch! That meat was painted!",
+ "VWxjaCEgVGhhdCBtZWF0IHdhcyBwYWludGVkIQ=="
+ },
+ { "Unfortunately, this message was left intentionally blank.",
+ "VW5mb3J0dW5hdGVseSwgdGhpcyBtZXNzYWdlIHdhcyBsZWZ0IGludGVudGlvbmFsbHkgYmxhbmsu"
+ },
+ { "Using a morning star in the evening has no effect.",
+ "VXNpbmcgYSBtb3JuaW5nIHN0YXIgaW4gdGhlIGV2ZW5pbmcgaGFzIG5vIGVmZmVjdC4="
+ },
+ { "Want a hint? Zap a wand of make invisible on your weapon!",
+ "V2FudCBhIGhpbnQ/IFphcCBhIHdhbmQgb2YgbWFrZSBpbnZpc2libGUgb24geW91ciB3ZWFwb24h"
+ },
+ { "Want to ascend in a hurry? Apply at Gizmonic Institute.",
+ "V2FudCB0byBhc2NlbmQgaW4gYSBodXJyeT8gQXBwbHkgYXQgR2l6bW9uaWMgSW5zdGl0dXRlLg=="
+ },
+ { "Wanted: shopkeepers. Send a scroll of mail to Mage of Yendor/Level 35/Dungeon.",
+ "V2FudGVkOiBzaG9wa2VlcGVycy4gU2VuZCBhIHNjcm9sbCBvZiBtYWlsIHRvIE1hZ2Ugb2YgWWVuZG9yL0xldmVsIDM1L0R1bmdlb24u"
+ },
+ { "Warning: fortune reading can be hazardous to your health.",
+ "V2FybmluZzogZm9ydHVuZSByZWFkaW5nIGNhbiBiZSBoYXphcmRvdXMgdG8geW91ciBoZWFsdGgu"
+ },
+ { "We have new ways of detecting treachery...",
+ "V2UgaGF2ZSBuZXcgd2F5cyBvZiBkZXRlY3RpbmcgdHJlYWNoZXJ5Li4u"
+ },
+ { "Wet towels make great weapons!",
+ "V2V0IHRvd2VscyBtYWtlIGdyZWF0IHdlYXBvbnMh"
+ },
+ { "What a pity, you cannot read it!",
+ "V2hhdCBhIHBpdHksIHlvdSBjYW5ub3QgcmVhZCBpdCE="
+ },
+ { "When a piercer drops in on you, you will be tempted to hit the ceiling!",
+ "V2hlbiBhIHBpZXJjZXIgZHJvcHMgaW4gb24geW91LCB5b3Ugd2lsbCBiZSB0ZW1wdGVkIHRvIGhpdCB0aGUgY2VpbGluZyE="
+ },
+ { "When in a maze follow the right wall and you will never get lost.",
+ "V2hlbiBpbiBhIG1hemUgZm9sbG93IHRoZSByaWdodCB3YWxsIGFuZCB5b3Ugd2lsbCBuZXZlciBnZXQgbG9zdC4="
+ },
+ { "When you have a key, you don't have to wait for the guard.",
+ "V2hlbiB5b3UgaGF2ZSBhIGtleSwgeW91IGRvbid0IGhhdmUgdG8gd2FpdCBmb3IgdGhlIGd1YXJkLg=="
+ },
+ { "Why are you wasting time reading fortunes?",
+ "V2h5IGFyZSB5b3Ugd2FzdGluZyB0aW1lIHJlYWRpbmcgZm9ydHVuZXM/"
+ },
+ { "Wish for a master key and open the Magic Memory Vault!",
+ "V2lzaCBmb3IgYSBtYXN0ZXIga2V5IGFuZCBvcGVuIHRoZSBNYWdpYyBNZW1vcnkgVmF1bHQh"
+ },
+ { "Wizard expects every monster to do its duty.",
+ "V2l6YXJkIGV4cGVjdHMgZXZlcnkgbW9uc3RlciB0byBkbyBpdHMgZHV0eS4="
+ },
+ { "Wow! You could've had a potion of fruit juice!",
+ "V293ISBZb3UgY291bGQndmUgaGFkIGEgcG90aW9uIG9mIGZydWl0IGp1aWNlIQ=="
+ },
+ { "Yet Another Silly Message (YASM).",
+ "WWV0IEFub3RoZXIgU2lsbHkgTWVzc2FnZSAoWUFTTSku"
+ },
+ { "You are destined to be misled by a fortune.",
+ "WW91IGFyZSBkZXN0aW5lZCB0byBiZSBtaXNsZWQgYnkgYSBmb3J0dW5lLg=="
+ },
+ { "You can get a genuine Amulet of Yendor by doing the following: --More--",
+ "WW91IGNhbiBnZXQgYSBnZW51aW5lIEFtdWxldCBvZiBZZW5kb3IgYnkgZG9pbmcgdGhlIGZvbGxvd2luZzogLS1Nb3JlLS0="
+ },
+ { "You can protect yourself from black dragons by doing the following: --More--",
+ "WW91IGNhbiBwcm90ZWN0IHlvdXJzZWxmIGZyb20gYmxhY2sgZHJhZ29ucyBieSBkb2luZyB0aGUgZm9sbG93aW5nOiAtLU1vcmUtLQ=="
+ },
+ { "You can't get by the snake.",
+ "WW91IGNhbid0IGdldCBieSB0aGUgc25ha2Uu"
+ },
+ { "You feel like someone is pulling your leg.",
+ "WW91IGZlZWwgbGlrZSBzb21lb25lIGlzIHB1bGxpbmcgeW91ciBsZWcu"
+ },
+ { "You have to outwit the Sphynx or pay her.",
+ "WW91IGhhdmUgdG8gb3V0d2l0IHRoZSBTcGh5bnggb3IgcGF5IGhlci4="
+ },
+ { "You hear the fortune cookie's hissing!",
+ "WW91IGhlYXIgdGhlIGZvcnR1bmUgY29va2llJ3MgaGlzc2luZyE="
+ },
+ { "You may get rich selling letters, but beware of being blackmailed!",
+ "WW91IG1heSBnZXQgcmljaCBzZWxsaW5nIGxldHRlcnMsIGJ1dCBiZXdhcmUgb2YgYmVpbmcgYmxhY2ttYWlsZWQh"
+ },
+ { "You offend Shai-Hulud by sheathing your crysknife without having drawn blood.",
+ "WW91IG9mZmVuZCBTaGFpLUh1bHVkIGJ5IHNoZWF0aGluZyB5b3VyIGNyeXNrbmlmZSB3aXRob3V0IGhhdmluZyBkcmF3biBibG9vZC4="
+ },
+ { "You swallowed the fortune!",
+ "WW91IHN3YWxsb3dlZCB0aGUgZm9ydHVuZSE="
+ },
+ { "You want to regain strength? Two levels ahead is a guesthouse!",
+ "WW91IHdhbnQgdG8gcmVnYWluIHN0cmVuZ3RoPyBUd28gbGV2ZWxzIGFoZWFkIGlzIGEgZ3Vlc3Rob3VzZSE="
+ },
+ { "You will encounter a tall, dark, and gruesome creature...",
+ "WW91IHdpbGwgZW5jb3VudGVyIGEgdGFsbCwgZGFyaywgYW5kIGdydWVzb21lIGNyZWF0dXJlLi4u"
+ },
+
+ { "The End", "VGhlIEVuZA==" }
+};
/* PL_Base64Encode, random strings */
PRBool test_004(void)
diff --git a/lib/tests/getopt.c b/lib/tests/getopt.c
index 6c59ed4e..dc3ea39f 100644
--- a/lib/tests/getopt.c
+++ b/lib/tests/getopt.c
@@ -12,9 +12,9 @@
static const PLLongOpt optArray[] = {
- { "longa", 'a' , PR_TRUE },
- { "longb", 'b' , PR_TRUE },
- { "longc", 'c' , PR_FALSE },
+ { "longa", 'a', PR_TRUE },
+ { "longb", 'b', PR_TRUE },
+ { "longc", 'c', PR_FALSE },
{ "longd", 'd' | 0x100, PR_TRUE },
{ "longe", 'e' | 0x100, PR_FALSE },
{ NULL, }
@@ -29,13 +29,14 @@ main(int argc, char **argv)
opt = PL_CreateLongOptState(argc, argv, "a:b:c", optArray);
while (PL_OPT_OK == (ostat = PL_GetNextOpt(opt))) {
- if (opt->option == 0 && opt->longOptIndex < 0)
- printf("Positional parameter: \"%s\"\n", opt->value);
- else
- printf("%s option: %x (\'%c\', index %d), argument: \"%s\"\n",
- (ostat == PL_OPT_BAD) ? "BAD" : "GOOD",
- opt->longOption, opt->option ? opt->option : ' ',
- opt->longOptIndex, opt->value);
+ if (opt->option == 0 && opt->longOptIndex < 0) {
+ printf("Positional parameter: \"%s\"\n", opt->value);
+ }
+ else
+ printf("%s option: %x (\'%c\', index %d), argument: \"%s\"\n",
+ (ostat == PL_OPT_BAD) ? "BAD" : "GOOD",
+ opt->longOption, opt->option ? opt->option : ' ',
+ opt->longOptIndex, opt->value);
}
printf("last result was %s\n", (ostat == PL_OPT_BAD) ? "BAD" : "EOL");
diff --git a/lib/tests/string.c b/lib/tests/string.c
index 220cc437..7765d12d 100644
--- a/lib/tests/string.c
+++ b/lib/tests/string.c
@@ -16,13 +16,13 @@ PRBool test_001(void)
const char *str;
PRUint32 len;
} array[] =
- {
- { (const char *)0, 0 },
- { "", 0 },
- { "a", 1 },
- { "abcdefg", 7 },
- { "abcdefg\0hijk", 7 }
- };
+ {
+ { (const char *)0, 0 },
+ { "", 0 },
+ { "a", 1 },
+ { "abcdefg", 7 },
+ { "abcdefg\0hijk", 7 }
+ };
int i;
@@ -52,23 +52,23 @@ PRBool test_002(void)
PRUint32 max;
PRUint32 len;
} array[] =
- {
- { (const char *)0, 0, 0 },
- { (const char *)0, 12, 0 },
- { "", 0, 0 },
- { "", 12, 0 },
- { "a", 0, 0 },
- { "a", 1, 1 },
- { "a", 12, 1 },
- { "abcdefg", 0, 0 },
- { "abcdefg", 1, 1 },
- { "abcdefg", 7, 7 },
- { "abcdefg", 12, 7 },
- { "abcdefg\0hijk", 0, 0 },
- { "abcdefg\0hijk", 1, 1 },
- { "abcdefg\0hijk", 7, 7 },
- { "abcdefg\0hijk", 12, 7 },
- };
+ {
+ { (const char *)0, 0, 0 },
+ { (const char *)0, 12, 0 },
+ { "", 0, 0 },
+ { "", 12, 0 },
+ { "a", 0, 0 },
+ { "a", 1, 1 },
+ { "a", 12, 1 },
+ { "abcdefg", 0, 0 },
+ { "abcdefg", 1, 1 },
+ { "abcdefg", 7, 7 },
+ { "abcdefg", 12, 7 },
+ { "abcdefg\0hijk", 0, 0 },
+ { "abcdefg\0hijk", 1, 1 },
+ { "abcdefg\0hijk", 7, 7 },
+ { "abcdefg\0hijk", 12, 7 },
+ };
int i;
@@ -101,18 +101,18 @@ PRBool test_003(void)
char *rv;
PRBool comp;
} array[] =
- {
- { (const char *)0, (char *)0, (char *)0, PR_FALSE },
- { (const char *)0, buffer, (char *)0, PR_FALSE },
- { "", (char *)0, (char *)0, PR_FALSE },
- { "", buffer, buffer, PR_TRUE },
- { "a", (char *)0, (char *)0, PR_FALSE },
- { "a", buffer, buffer, PR_TRUE },
- { "abcdefg", (char *)0, (char *)0, PR_FALSE },
- { "abcdefg", buffer, buffer, PR_TRUE },
- { "wxyz\0abcdefg", (char *)0, (char *)0, PR_FALSE },
- { "wxyz\0abcdefg", buffer, buffer, PR_TRUE }
- };
+ {
+ { (const char *)0, (char *)0, (char *)0, PR_FALSE },
+ { (const char *)0, buffer, (char *)0, PR_FALSE },
+ { "", (char *)0, (char *)0, PR_FALSE },
+ { "", buffer, buffer, PR_TRUE },
+ { "a", (char *)0, (char *)0, PR_FALSE },
+ { "a", buffer, buffer, PR_TRUE },
+ { "abcdefg", (char *)0, (char *)0, PR_FALSE },
+ { "abcdefg", buffer, buffer, PR_TRUE },
+ { "wxyz\0abcdefg", (char *)0, (char *)0, PR_FALSE },
+ { "wxyz\0abcdefg", buffer, buffer, PR_TRUE }
+ };
int i;
@@ -144,7 +144,9 @@ PRBool test_003(void)
return PR_FALSE;
}
- if( (char)0 == *a ) break;
+ if( (char)0 == *a ) {
+ break;
+ }
a++;
b++;
@@ -171,56 +173,56 @@ PRBool test_004(void)
const char *result;
PRBool nulled;
} array[] =
- {
- { (const char *)0, 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
- { (const char *)0, 0, buffer, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
- { (const char *)0, 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
- { (const char *)0, 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
- { (const char *)0, 1, buffer, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
- { (const char *)0, 7, buffer, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
- { "", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
- { "", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
- { "", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
- { "", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
- { "", 1, buffer, buffer, PR_TRUE, "", PR_TRUE },
- { "", 7, buffer, buffer, PR_TRUE, "", PR_TRUE },
- { "a", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
- { "a", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
- { "a", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
- { "a", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
- { "b", 1, buffer, buffer, PR_TRUE, "b", PR_FALSE },
- { "c", 7, buffer, buffer, PR_TRUE, "c", PR_TRUE },
- { "de", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
- { "de", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
- { "de", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
- { "de", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
- { "fg", 1, buffer, buffer, PR_TRUE, "f", PR_FALSE },
- { "hi", 7, buffer, buffer, PR_TRUE, "hi", PR_TRUE },
- { "jklmnopq", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
- { "jklmnopq", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
- { "jklmnopq", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
- { "jklmnopq", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
- { "rstuvwxy", 1, buffer, buffer, PR_TRUE, "r", PR_FALSE },
- { "zABCDEFG", 7, buffer, buffer, PR_TRUE, "zABCDEF", PR_FALSE },
- { "a\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
- { "a\0XXX", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
- { "a\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
- { "a\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
- { "b\0XXX", 1, buffer, buffer, PR_TRUE, "b", PR_FALSE },
- { "c\0XXX", 7, buffer, buffer, PR_TRUE, "c", PR_TRUE },
- { "de\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
- { "de\0XXX", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
- { "de\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
- { "de\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
- { "fg\0XXX", 1, buffer, buffer, PR_TRUE, "f", PR_FALSE },
- { "hi\0XXX", 7, buffer, buffer, PR_TRUE, "hi", PR_TRUE },
- { "jklmnopq\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
- { "jklmnopq\0XXX", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
- { "jklmnopq\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
- { "jklmnopq\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
- { "rstuvwxy\0XXX", 1, buffer, buffer, PR_TRUE, "r", PR_FALSE },
- { "zABCDEFG\0XXX", 7, buffer, buffer, PR_TRUE, "zABCDEF", PR_FALSE },
- };
+ {
+ { (const char *)0, 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+ { (const char *)0, 0, buffer, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+ { (const char *)0, 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+ { (const char *)0, 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+ { (const char *)0, 1, buffer, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+ { (const char *)0, 7, buffer, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+ { "", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+ { "", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
+ { "", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+ { "", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+ { "", 1, buffer, buffer, PR_TRUE, "", PR_TRUE },
+ { "", 7, buffer, buffer, PR_TRUE, "", PR_TRUE },
+ { "a", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+ { "a", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
+ { "a", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+ { "a", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+ { "b", 1, buffer, buffer, PR_TRUE, "b", PR_FALSE },
+ { "c", 7, buffer, buffer, PR_TRUE, "c", PR_TRUE },
+ { "de", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+ { "de", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
+ { "de", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+ { "de", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+ { "fg", 1, buffer, buffer, PR_TRUE, "f", PR_FALSE },
+ { "hi", 7, buffer, buffer, PR_TRUE, "hi", PR_TRUE },
+ { "jklmnopq", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+ { "jklmnopq", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
+ { "jklmnopq", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+ { "jklmnopq", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+ { "rstuvwxy", 1, buffer, buffer, PR_TRUE, "r", PR_FALSE },
+ { "zABCDEFG", 7, buffer, buffer, PR_TRUE, "zABCDEF", PR_FALSE },
+ { "a\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+ { "a\0XXX", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
+ { "a\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+ { "a\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+ { "b\0XXX", 1, buffer, buffer, PR_TRUE, "b", PR_FALSE },
+ { "c\0XXX", 7, buffer, buffer, PR_TRUE, "c", PR_TRUE },
+ { "de\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+ { "de\0XXX", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
+ { "de\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+ { "de\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+ { "fg\0XXX", 1, buffer, buffer, PR_TRUE, "f", PR_FALSE },
+ { "hi\0XXX", 7, buffer, buffer, PR_TRUE, "hi", PR_TRUE },
+ { "jklmnopq\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+ { "jklmnopq\0XXX", 0, buffer, buffer, PR_FALSE, (const char *)0, PR_FALSE },
+ { "jklmnopq\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+ { "jklmnopq\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0, PR_FALSE },
+ { "rstuvwxy\0XXX", 1, buffer, buffer, PR_TRUE, "r", PR_FALSE },
+ { "zABCDEFG\0XXX", 7, buffer, buffer, PR_TRUE, "zABCDEF", PR_FALSE },
+ };
int i;
@@ -231,8 +233,9 @@ PRBool test_004(void)
char *rv;
int j;
- for( j = 0; j < sizeof(buffer); j++ )
+ for( j = 0; j < sizeof(buffer); j++ ) {
buffer[j] = '-';
+ }
rv = PL_strncpy(array[i].dest, array[i].str, array[i].len);
if( array[i].rv != rv )
@@ -297,56 +300,56 @@ PRBool test_005(void)
PRBool comp;
const char *result;
} array[] =
- {
- { (const char *)0, 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
- { (const char *)0, 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
- { (const char *)0, 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
- { (const char *)0, 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
- { (const char *)0, 1, buffer, (char *)0, PR_FALSE, (const char *)0 },
- { (const char *)0, 7, buffer, (char *)0, PR_FALSE, (const char *)0 },
- { "", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
- { "", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
- { "", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
- { "", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
- { "", 1, buffer, buffer, PR_TRUE, "" },
- { "", 7, buffer, buffer, PR_TRUE, "" },
- { "a", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
- { "a", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
- { "a", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
- { "a", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
- { "b", 1, buffer, buffer, PR_TRUE, "" },
- { "c", 7, buffer, buffer, PR_TRUE, "c" },
- { "de", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
- { "de", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
- { "de", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
- { "de", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
- { "fg", 1, buffer, buffer, PR_TRUE, "" },
- { "hi", 7, buffer, buffer, PR_TRUE, "hi" },
- { "jklmnopq", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
- { "jklmnopq", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
- { "jklmnopq", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
- { "jklmnopq", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
- { "rstuvwxy", 1, buffer, buffer, PR_TRUE, "" },
- { "zABCDEFG", 7, buffer, buffer, PR_TRUE, "zABCDE" },
- { "a\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
- { "a\0XXX", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
- { "a\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
- { "a\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
- { "b\0XXX", 1, buffer, buffer, PR_TRUE, "" },
- { "c\0XXX", 7, buffer, buffer, PR_TRUE, "c" },
- { "de\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
- { "de\0XXX", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
- { "de\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
- { "de\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
- { "fg\0XXX", 1, buffer, buffer, PR_TRUE, "" },
- { "hi\0XXX", 7, buffer, buffer, PR_TRUE, "hi" },
- { "jklmnopq\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
- { "jklmnopq\0XXX", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
- { "jklmnopq\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
- { "jklmnopq\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
- { "rstuvwxy\0XXX", 1, buffer, buffer, PR_TRUE, "" },
- { "zABCDEFG\0XXX", 7, buffer, buffer, PR_TRUE, "zABCDE" },
- };
+ {
+ { (const char *)0, 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+ { (const char *)0, 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
+ { (const char *)0, 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+ { (const char *)0, 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+ { (const char *)0, 1, buffer, (char *)0, PR_FALSE, (const char *)0 },
+ { (const char *)0, 7, buffer, (char *)0, PR_FALSE, (const char *)0 },
+ { "", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+ { "", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
+ { "", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+ { "", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+ { "", 1, buffer, buffer, PR_TRUE, "" },
+ { "", 7, buffer, buffer, PR_TRUE, "" },
+ { "a", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+ { "a", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
+ { "a", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+ { "a", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+ { "b", 1, buffer, buffer, PR_TRUE, "" },
+ { "c", 7, buffer, buffer, PR_TRUE, "c" },
+ { "de", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+ { "de", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
+ { "de", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+ { "de", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+ { "fg", 1, buffer, buffer, PR_TRUE, "" },
+ { "hi", 7, buffer, buffer, PR_TRUE, "hi" },
+ { "jklmnopq", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+ { "jklmnopq", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
+ { "jklmnopq", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+ { "jklmnopq", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+ { "rstuvwxy", 1, buffer, buffer, PR_TRUE, "" },
+ { "zABCDEFG", 7, buffer, buffer, PR_TRUE, "zABCDE" },
+ { "a\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+ { "a\0XXX", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
+ { "a\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+ { "a\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+ { "b\0XXX", 1, buffer, buffer, PR_TRUE, "" },
+ { "c\0XXX", 7, buffer, buffer, PR_TRUE, "c" },
+ { "de\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+ { "de\0XXX", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
+ { "de\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+ { "de\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+ { "fg\0XXX", 1, buffer, buffer, PR_TRUE, "" },
+ { "hi\0XXX", 7, buffer, buffer, PR_TRUE, "hi" },
+ { "jklmnopq\0XXX", 0, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+ { "jklmnopq\0XXX", 0, buffer, (char *)0, PR_FALSE, (const char *)0 },
+ { "jklmnopq\0XXX", 1, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+ { "jklmnopq\0XXX", 7, (char *)0, (char *)0, PR_FALSE, (const char *)0 },
+ { "rstuvwxy\0XXX", 1, buffer, buffer, PR_TRUE, "" },
+ { "zABCDEFG\0XXX", 7, buffer, buffer, PR_TRUE, "zABCDE" },
+ };
int i;
@@ -357,8 +360,9 @@ PRBool test_005(void)
char *rv;
int j;
- for( j = 0; j < sizeof(buffer); j++ )
+ for( j = 0; j < sizeof(buffer); j++ ) {
buffer[j] = '-';
+ }
rv = PL_strncpyz(array[i].dest, array[i].str, array[i].len);
if( array[i].rv != rv )
@@ -382,7 +386,9 @@ PRBool test_005(void)
return PR_FALSE;
}
- if( (char)0 == *a ) break;
+ if( (char)0 == *a ) {
+ break;
+ }
a++;
b++;
@@ -440,7 +446,9 @@ PRBool test_006(void)
return PR_FALSE;
}
- if( (char)0 == *a ) break;
+ if( (char)0 == *a ) {
+ break;
+ }
a++;
b++;
@@ -463,29 +471,29 @@ PRBool test_007(void)
PRUint32 len;
const char *result;
} array[] =
- {
- { (const char *)0, 0, "" },
- { (const char *)0, 1, "" },
- { (const char *)0, 7, "" },
- { "", 0, "" },
- { "", 1, "" },
- { "", 7, "" },
- { "a", 0, "" },
- { "a", 1, "a" },
- { "a", 7, "a" },
- { "ab", 0, "" },
- { "ab", 1, "a" },
- { "ab", 7, "ab" },
- { "abcdefg", 0, "" },
- { "abcdefg", 1, "a" },
- { "abcdefg", 7, "abcdefg" },
- { "abcdefghijk", 0, "" },
- { "abcdefghijk", 1, "a" },
- { "abcdefghijk", 7, "abcdefg" },
- { "abcdef\0ghijk", 0, "" },
- { "abcdef\0ghijk", 1, "a" },
- { "abcdef\0ghijk", 7, "abcdef" }
- };
+ {
+ { (const char *)0, 0, "" },
+ { (const char *)0, 1, "" },
+ { (const char *)0, 7, "" },
+ { "", 0, "" },
+ { "", 1, "" },
+ { "", 7, "" },
+ { "a", 0, "" },
+ { "a", 1, "a" },
+ { "a", 7, "a" },
+ { "ab", 0, "" },
+ { "ab", 1, "a" },
+ { "ab", 7, "ab" },
+ { "abcdefg", 0, "" },
+ { "abcdefg", 1, "a" },
+ { "abcdefg", 7, "abcdefg" },
+ { "abcdefghijk", 0, "" },
+ { "abcdefghijk", 1, "a" },
+ { "abcdefghijk", 7, "abcdefg" },
+ { "abcdef\0ghijk", 0, "" },
+ { "abcdef\0ghijk", 1, "a" },
+ { "abcdef\0ghijk", 7, "abcdef" }
+ };
int i;
@@ -515,7 +523,9 @@ PRBool test_007(void)
return PR_FALSE;
}
- if( (char)0 == *a ) break;
+ if( (char)0 == *a ) {
+ break;
+ }
a++;
b++;
@@ -537,19 +547,19 @@ PRBool test_008(void)
const char *second;
const char *result;
} array[] =
- {
- { (const char *)0, (const char *)0, (const char *)0 },
- { (const char *)0, "xyz", (const char *)0 },
- { "", (const char *)0, "" },
- { "", "", "" },
- { "ab", "", "ab" },
- { "cd", "ef", "cdef" },
- { "gh\0X", "", "gh" },
- { "ij\0X", "kl", "ijkl" },
- { "mn\0X", "op\0X", "mnop" },
- { "qr", "st\0X", "qrst" },
- { "uv\0X", "wx\0X", "uvwx" }
- };
+ {
+ { (const char *)0, (const char *)0, (const char *)0 },
+ { (const char *)0, "xyz", (const char *)0 },
+ { "", (const char *)0, "" },
+ { "", "", "" },
+ { "ab", "", "ab" },
+ { "cd", "ef", "cdef" },
+ { "gh\0X", "", "gh" },
+ { "ij\0X", "kl", "ijkl" },
+ { "mn\0X", "op\0X", "mnop" },
+ { "qr", "st\0X", "qrst" },
+ { "uv\0X", "wx\0X", "uvwx" }
+ };
int i;
@@ -561,11 +571,13 @@ PRBool test_008(void)
int j;
char *rv;
- for( j = 0; j < sizeof(buffer); j++ )
+ for( j = 0; j < sizeof(buffer); j++ ) {
buffer[j] = '-';
+ }
- if( (const char *)0 != array[i].first )
+ if( (const char *)0 != array[i].first ) {
(void)PL_strcpy(buffer, array[i].first);
+ }
rv = PL_strcat(((const char *)0 == array[i].first) ? (char *)0 : buffer,
array[i].second);
@@ -607,7 +619,9 @@ PRBool test_008(void)
return PR_FALSE;
}
- if( (char)0 == *a ) break;
+ if( (char)0 == *a ) {
+ break;
+ }
a++;
b++;
@@ -631,35 +645,35 @@ PRBool test_009(void)
PRBool nulled;
const char *result;
} array[] =
- {
- { (const char *)0, (const char *)0, 0, PR_FALSE, (const char *)0 },
- { (const char *)0, (const char *)0, 1, PR_FALSE, (const char *)0 },
- { (const char *)0, (const char *)0, 7, PR_FALSE, (const char *)0 },
- { (const char *)0, "", 0, PR_FALSE, (const char *)0 },
- { (const char *)0, "", 1, PR_FALSE, (const char *)0 },
- { (const char *)0, "", 7, PR_FALSE, (const char *)0 },
- { (const char *)0, "stuff", 0, PR_FALSE, (const char *)0 },
- { (const char *)0, "stuff", 1, PR_FALSE, (const char *)0 },
- { (const char *)0, "stuff", 7, PR_FALSE, (const char *)0 },
- { "", (const char *)0, 0, PR_TRUE, "" },
- { "", (const char *)0, 1, PR_TRUE, "" },
- { "", (const char *)0, 7, PR_TRUE, "" },
- { "", "", 0, PR_TRUE, "" },
- { "", "", 1, PR_TRUE, "" },
- { "", "", 7, PR_TRUE, "" },
- { "", "abcdefgh", 0, PR_TRUE, "" },
- { "", "abcdefgh", 1, PR_FALSE, "a" },
- { "", "abcdefgh", 7, PR_FALSE, "abcdefg" },
- { "xyz", (const char *)0, 0, PR_TRUE, "xyz" },
- { "xyz", (const char *)0, 1, PR_TRUE, "xyz" },
- { "xyz", (const char *)0, 7, PR_TRUE, "xyz" },
- { "xyz", "", 0, PR_TRUE, "xyz" },
- { "xyz", "", 1, PR_TRUE, "xyz" },
- { "xyz", "", 7, PR_TRUE, "xyz" },
- { "xyz", "abcdefgh", 0, PR_TRUE, "xyz" },
- { "xyz", "abcdefgh", 1, PR_FALSE, "xyza" },
- { "xyz", "abcdefgh", 7, PR_FALSE, "xyzabcdefg" }
- };
+ {
+ { (const char *)0, (const char *)0, 0, PR_FALSE, (const char *)0 },
+ { (const char *)0, (const char *)0, 1, PR_FALSE, (const char *)0 },
+ { (const char *)0, (const char *)0, 7, PR_FALSE, (const char *)0 },
+ { (const char *)0, "", 0, PR_FALSE, (const char *)0 },
+ { (const char *)0, "", 1, PR_FALSE, (const char *)0 },
+ { (const char *)0, "", 7, PR_FALSE, (const char *)0 },
+ { (const char *)0, "stuff", 0, PR_FALSE, (const char *)0 },
+ { (const char *)0, "stuff", 1, PR_FALSE, (const char *)0 },
+ { (const char *)0, "stuff", 7, PR_FALSE, (const char *)0 },
+ { "", (const char *)0, 0, PR_TRUE, "" },
+ { "", (const char *)0, 1, PR_TRUE, "" },
+ { "", (const char *)0, 7, PR_TRUE, "" },
+ { "", "", 0, PR_TRUE, "" },
+ { "", "", 1, PR_TRUE, "" },
+ { "", "", 7, PR_TRUE, "" },
+ { "", "abcdefgh", 0, PR_TRUE, "" },
+ { "", "abcdefgh", 1, PR_FALSE, "a" },
+ { "", "abcdefgh", 7, PR_FALSE, "abcdefg" },
+ { "xyz", (const char *)0, 0, PR_TRUE, "xyz" },
+ { "xyz", (const char *)0, 1, PR_TRUE, "xyz" },
+ { "xyz", (const char *)0, 7, PR_TRUE, "xyz" },
+ { "xyz", "", 0, PR_TRUE, "xyz" },
+ { "xyz", "", 1, PR_TRUE, "xyz" },
+ { "xyz", "", 7, PR_TRUE, "xyz" },
+ { "xyz", "abcdefgh", 0, PR_TRUE, "xyz" },
+ { "xyz", "abcdefgh", 1, PR_FALSE, "xyza" },
+ { "xyz", "abcdefgh", 7, PR_FALSE, "xyzabcdefg" }
+ };
int i;
@@ -671,14 +685,16 @@ PRBool test_009(void)
int j;
char *rv;
- for( j = 0; j < sizeof(buffer); j++ )
+ for( j = 0; j < sizeof(buffer); j++ ) {
buffer[j] = '-';
+ }
- if( (const char *)0 != array[i].first )
+ if( (const char *)0 != array[i].first ) {
(void)PL_strcpy(buffer, array[i].first);
+ }
rv = PL_strncat(((const char *)0 == array[i].first) ? (char *)0 : buffer,
- array[i].second, array[i].length);
+ array[i].second, array[i].length);
if( (const char *)0 == array[i].result )
{
@@ -761,35 +777,35 @@ PRBool test_010(void)
PRUint32 length;
const char *result;
} array[] =
- {
- { (const char *)0, (const char *)0, 0, (const char *)0 },
- { (const char *)0, (const char *)0, 1, (const char *)0 },
- { (const char *)0, (const char *)0, 7, (const char *)0 },
- { (const char *)0, "", 0, (const char *)0 },
- { (const char *)0, "", 1, (const char *)0 },
- { (const char *)0, "", 7, (const char *)0 },
- { (const char *)0, "stuff", 0, (const char *)0 },
- { (const char *)0, "stuff", 1, (const char *)0 },
- { (const char *)0, "stuff", 7, (const char *)0 },
- { "", (const char *)0, 0, "" },
- { "", (const char *)0, 1, "" },
- { "", (const char *)0, 7, "" },
- { "", "", 0, "" },
- { "", "", 1, "" },
- { "", "", 7, "" },
- { "", "abcdefgh", 0, "" },
- { "", "abcdefgh", 1, "" },
- { "", "abcdefgh", 7, "abcdef" },
- { "xyz", (const char *)0, 0, "xyz" },
- { "xyz", (const char *)0, 1, "xyz" },
- { "xyz", (const char *)0, 7, "xyz" },
- { "xyz", "", 0, "xyz" },
- { "xyz", "", 1, "xyz" },
- { "xyz", "", 7, "xyz" },
- { "xyz", "abcdefgh", 0, "xyz" },
- { "xyz", "abcdefgh", 1, "xyz" },
- { "xyz", "abcdefgh", 7, "xyzabc" }
- };
+ {
+ { (const char *)0, (const char *)0, 0, (const char *)0 },
+ { (const char *)0, (const char *)0, 1, (const char *)0 },
+ { (const char *)0, (const char *)0, 7, (const char *)0 },
+ { (const char *)0, "", 0, (const char *)0 },
+ { (const char *)0, "", 1, (const char *)0 },
+ { (const char *)0, "", 7, (const char *)0 },
+ { (const char *)0, "stuff", 0, (const char *)0 },
+ { (const char *)0, "stuff", 1, (const char *)0 },
+ { (const char *)0, "stuff", 7, (const char *)0 },
+ { "", (const char *)0, 0, "" },
+ { "", (const char *)0, 1, "" },
+ { "", (const char *)0, 7, "" },
+ { "", "", 0, "" },
+ { "", "", 1, "" },
+ { "", "", 7, "" },
+ { "", "abcdefgh", 0, "" },
+ { "", "abcdefgh", 1, "" },
+ { "", "abcdefgh", 7, "abcdef" },
+ { "xyz", (const char *)0, 0, "xyz" },
+ { "xyz", (const char *)0, 1, "xyz" },
+ { "xyz", (const char *)0, 7, "xyz" },
+ { "xyz", "", 0, "xyz" },
+ { "xyz", "", 1, "xyz" },
+ { "xyz", "", 7, "xyz" },
+ { "xyz", "abcdefgh", 0, "xyz" },
+ { "xyz", "abcdefgh", 1, "xyz" },
+ { "xyz", "abcdefgh", 7, "xyzabc" }
+ };
int i;
@@ -801,11 +817,13 @@ PRBool test_010(void)
int j;
char *rv;
- for( j = 0; j < sizeof(buffer); j++ )
+ for( j = 0; j < sizeof(buffer); j++ ) {
buffer[j] = '-';
+ }
- if( (const char *)0 != array[i].first )
+ if( (const char *)0 != array[i].first ) {
(void)PL_strcpy(buffer, array[i].first);
+ }
rv = PL_strcatn(((const char *)0 == array[i].first) ? (char *)0 : buffer,
array[i].length, array[i].second);
@@ -847,7 +865,9 @@ PRBool test_010(void)
return PR_FALSE;
}
- if( (char)0 == *a ) break;
+ if( (char)0 == *a ) {
+ break;
+ }
a++;
b++;
@@ -869,39 +889,39 @@ PRBool test_011(void)
const char *two;
PRIntn sign;
} array[] =
- {
- { (const char *)0, (const char *)0, 0 },
- { (const char *)0, "word", -1 },
- { "word", (const char *)0, 1 },
- { "word", "word", 0 },
- { "aZYXVUT", "bZYXVUT", -1 },
- { "aZYXVUT", "bAAAAAA", -1 },
- { "a", "aa", -1 },
- { "a", "a", 0 },
- { "a", "A", 1 },
- { "aaaaa", "baaaa", -1 },
- { "aaaaa", "abaaa", -1 },
- { "aaaaa", "aabaa", -1 },
- { "aaaaa", "aaaba", -1 },
- { "aaaaa", "aaaab", -1 },
- { "bZYXVUT", "aZYXVUT", 1 },
- { "bAAAAAA", "aZYXVUT", 1 },
- { "aa", "a", 1 },
- { "A", "a", -1 },
- { "baaaa", "aaaaa", 1 },
- { "abaaa", "aaaaa", 1 },
- { "aabaa", "aaaaa", 1 },
- { "aaaba", "aaaaa", 1 },
- { "aaaab", "aaaaa", 1 },
- { "word", "Word", 1 },
- { "word", "wOrd", 1 },
- { "word", "woRd", 1 },
- { "word", "worD", 1 },
- { "WORD", "wORD", -1 },
- { "WORD", "WoRD", -1 },
- { "WORD", "WOrD", -1 },
- { "WORD", "WORd", -1 }
- };
+ {
+ { (const char *)0, (const char *)0, 0 },
+ { (const char *)0, "word", -1 },
+ { "word", (const char *)0, 1 },
+ { "word", "word", 0 },
+ { "aZYXVUT", "bZYXVUT", -1 },
+ { "aZYXVUT", "bAAAAAA", -1 },
+ { "a", "aa", -1 },
+ { "a", "a", 0 },
+ { "a", "A", 1 },
+ { "aaaaa", "baaaa", -1 },
+ { "aaaaa", "abaaa", -1 },
+ { "aaaaa", "aabaa", -1 },
+ { "aaaaa", "aaaba", -1 },
+ { "aaaaa", "aaaab", -1 },
+ { "bZYXVUT", "aZYXVUT", 1 },
+ { "bAAAAAA", "aZYXVUT", 1 },
+ { "aa", "a", 1 },
+ { "A", "a", -1 },
+ { "baaaa", "aaaaa", 1 },
+ { "abaaa", "aaaaa", 1 },
+ { "aabaa", "aaaaa", 1 },
+ { "aaaba", "aaaaa", 1 },
+ { "aaaab", "aaaaa", 1 },
+ { "word", "Word", 1 },
+ { "word", "wOrd", 1 },
+ { "word", "woRd", 1 },
+ { "word", "worD", 1 },
+ { "WORD", "wORD", -1 },
+ { "WORD", "WoRD", -1 },
+ { "WORD", "WOrD", -1 },
+ { "WORD", "WORd", -1 }
+ };
int i;
@@ -914,13 +934,19 @@ PRBool test_011(void)
switch( array[i].sign )
{
case -1:
- if( rv < 0 ) continue;
+ if( rv < 0 ) {
+ continue;
+ }
break;
case 1:
- if( rv > 0 ) continue;
+ if( rv > 0 ) {
+ continue;
+ }
break;
case 0:
- if( 0 == rv ) continue;
+ if( 0 == rv ) {
+ continue;
+ }
break;
default:
PR_NOT_REACHED("static data inconsistancy");
@@ -948,105 +974,105 @@ PRBool test_012(void)
PRUint32 max;
PRIntn sign;
} array[] =
- {
- { (const char *)0, (const char *)0, 0, 0 },
- { (const char *)0, (const char *)0, 1, 0 },
- { (const char *)0, (const char *)0, 4, 0 },
- { (const char *)0, "word", 0, -1 },
- { (const char *)0, "word", 1, -1 },
- { (const char *)0, "word", 4, -1 },
- { "word", (const char *)0, 0, 1 },
- { "word", (const char *)0, 1, 1 },
- { "word", (const char *)0, 4, 1 },
- { "word", "word", 0, 0 },
- { "word", "word", 1, 0 },
- { "word", "word", 3, 0 },
- { "word", "word", 5, 0 },
- { "aZYXVUT", "bZYXVUT", 0, 0 },
- { "aZYXVUT", "bZYXVUT", 1, -1 },
- { "aZYXVUT", "bZYXVUT", 4, -1 },
- { "aZYXVUT", "bZYXVUT", 9, -1 },
- { "aZYXVUT", "bAAAAAA", 0, 0 },
- { "aZYXVUT", "bAAAAAA", 1, -1 },
- { "aZYXVUT", "bAAAAAA", 4, -1 },
- { "aZYXVUT", "bAAAAAA", 5, -1 },
- { "a", "aa", 0, 0 },
- { "a", "aa", 1, 0 },
- { "a", "aa", 4, -1 },
- { "a", "a", 0, 0 },
- { "a", "a", 1, 0 },
- { "a", "a", 4, 0 },
- { "a", "A", 0, 0 },
- { "a", "A", 1, 1 },
- { "a", "A", 4, 1 },
- { "aaaaa", "baaaa", 0, 0 },
- { "aaaaa", "baaaa", 1, -1 },
- { "aaaaa", "baaaa", 4, -1 },
- { "aaaaa", "abaaa", 0, 0 },
- { "aaaaa", "abaaa", 1, 0 },
- { "aaaaa", "abaaa", 4, -1 },
- { "aaaaa", "aabaa", 0, 0 },
- { "aaaaa", "aabaa", 1, 0 },
- { "aaaaa", "aabaa", 4, -1 },
- { "aaaaa", "aaaba", 0, 0 },
- { "aaaaa", "aaaba", 1, 0 },
- { "aaaaa", "aaaba", 4, -1 },
- { "aaaaa", "aaaab", 0, 0 },
- { "aaaaa", "aaaab", 1, 0 },
- { "aaaaa", "aaaab", 4, 0 },
- { "bZYXVUT", "aZYXVUT", 0, 0 },
- { "bZYXVUT", "aZYXVUT", 1, 1 },
- { "bZYXVUT", "aZYXVUT", 4, 1 },
- { "bAAAAAA", "aZYXVUT", 0, 0 },
- { "bAAAAAA", "aZYXVUT", 1, 1 },
- { "bAAAAAA", "aZYXVUT", 4, 1 },
- { "aa", "a", 0, 0 },
- { "aa", "a", 1, 0 },
- { "aa", "a", 4, 1 },
- { "A", "a", 0, 0 },
- { "A", "a", 1, -1 },
- { "A", "a", 4, -1 },
- { "baaaa", "aaaaa", 0, 0 },
- { "baaaa", "aaaaa", 1, 1 },
- { "baaaa", "aaaaa", 4, 1 },
- { "abaaa", "aaaaa", 0, 0 },
- { "abaaa", "aaaaa", 1, 0 },
- { "abaaa", "aaaaa", 4, 1 },
- { "aabaa", "aaaaa", 0, 0 },
- { "aabaa", "aaaaa", 1, 0 },
- { "aabaa", "aaaaa", 4, 1 },
- { "aaaba", "aaaaa", 0, 0 },
- { "aaaba", "aaaaa", 1, 0 },
- { "aaaba", "aaaaa", 4, 1 },
- { "aaaab", "aaaaa", 0, 0 },
- { "aaaab", "aaaaa", 1, 0 },
- { "aaaab", "aaaaa", 4, 0 },
- { "word", "Word", 0, 0 },
- { "word", "Word", 1, 1 },
- { "word", "Word", 3, 1 },
- { "word", "wOrd", 0, 0 },
- { "word", "wOrd", 1, 0 },
- { "word", "wOrd", 3, 1 },
- { "word", "woRd", 0, 0 },
- { "word", "woRd", 1, 0 },
- { "word", "woRd", 3, 1 },
- { "word", "worD", 0, 0 },
- { "word", "worD", 1, 0 },
- { "word", "worD", 3, 0 },
- { "WORD", "wORD", 0, 0 },
- { "WORD", "wORD", 1, -1 },
- { "WORD", "wORD", 3, -1 },
- { "WORD", "WoRD", 0, 0 },
- { "WORD", "WoRD", 1, 0 },
- { "WORD", "WoRD", 3, -1 },
- { "WORD", "WOrD", 0, 0 },
- { "WORD", "WOrD", 1, 0 },
- { "WORD", "WOrD", 3, -1 },
- { "WORD", "WORd", 0, 0 },
- { "WORD", "WORd", 1, 0 },
- { "WORD", "WORd", 3, 0 }
-
- };
+ {
+ { (const char *)0, (const char *)0, 0, 0 },
+ { (const char *)0, (const char *)0, 1, 0 },
+ { (const char *)0, (const char *)0, 4, 0 },
+ { (const char *)0, "word", 0, -1 },
+ { (const char *)0, "word", 1, -1 },
+ { (const char *)0, "word", 4, -1 },
+ { "word", (const char *)0, 0, 1 },
+ { "word", (const char *)0, 1, 1 },
+ { "word", (const char *)0, 4, 1 },
+ { "word", "word", 0, 0 },
+ { "word", "word", 1, 0 },
+ { "word", "word", 3, 0 },
+ { "word", "word", 5, 0 },
+ { "aZYXVUT", "bZYXVUT", 0, 0 },
+ { "aZYXVUT", "bZYXVUT", 1, -1 },
+ { "aZYXVUT", "bZYXVUT", 4, -1 },
+ { "aZYXVUT", "bZYXVUT", 9, -1 },
+ { "aZYXVUT", "bAAAAAA", 0, 0 },
+ { "aZYXVUT", "bAAAAAA", 1, -1 },
+ { "aZYXVUT", "bAAAAAA", 4, -1 },
+ { "aZYXVUT", "bAAAAAA", 5, -1 },
+ { "a", "aa", 0, 0 },
+ { "a", "aa", 1, 0 },
+ { "a", "aa", 4, -1 },
+ { "a", "a", 0, 0 },
+ { "a", "a", 1, 0 },
+ { "a", "a", 4, 0 },
+ { "a", "A", 0, 0 },
+ { "a", "A", 1, 1 },
+ { "a", "A", 4, 1 },
+ { "aaaaa", "baaaa", 0, 0 },
+ { "aaaaa", "baaaa", 1, -1 },
+ { "aaaaa", "baaaa", 4, -1 },
+ { "aaaaa", "abaaa", 0, 0 },
+ { "aaaaa", "abaaa", 1, 0 },
+ { "aaaaa", "abaaa", 4, -1 },
+ { "aaaaa", "aabaa", 0, 0 },
+ { "aaaaa", "aabaa", 1, 0 },
+ { "aaaaa", "aabaa", 4, -1 },
+ { "aaaaa", "aaaba", 0, 0 },
+ { "aaaaa", "aaaba", 1, 0 },
+ { "aaaaa", "aaaba", 4, -1 },
+ { "aaaaa", "aaaab", 0, 0 },
+ { "aaaaa", "aaaab", 1, 0 },
+ { "aaaaa", "aaaab", 4, 0 },
+ { "bZYXVUT", "aZYXVUT", 0, 0 },
+ { "bZYXVUT", "aZYXVUT", 1, 1 },
+ { "bZYXVUT", "aZYXVUT", 4, 1 },
+ { "bAAAAAA", "aZYXVUT", 0, 0 },
+ { "bAAAAAA", "aZYXVUT", 1, 1 },
+ { "bAAAAAA", "aZYXVUT", 4, 1 },
+ { "aa", "a", 0, 0 },
+ { "aa", "a", 1, 0 },
+ { "aa", "a", 4, 1 },
+ { "A", "a", 0, 0 },
+ { "A", "a", 1, -1 },
+ { "A", "a", 4, -1 },
+ { "baaaa", "aaaaa", 0, 0 },
+ { "baaaa", "aaaaa", 1, 1 },
+ { "baaaa", "aaaaa", 4, 1 },
+ { "abaaa", "aaaaa", 0, 0 },
+ { "abaaa", "aaaaa", 1, 0 },
+ { "abaaa", "aaaaa", 4, 1 },
+ { "aabaa", "aaaaa", 0, 0 },
+ { "aabaa", "aaaaa", 1, 0 },
+ { "aabaa", "aaaaa", 4, 1 },
+ { "aaaba", "aaaaa", 0, 0 },
+ { "aaaba", "aaaaa", 1, 0 },
+ { "aaaba", "aaaaa", 4, 1 },
+ { "aaaab", "aaaaa", 0, 0 },
+ { "aaaab", "aaaaa", 1, 0 },
+ { "aaaab", "aaaaa", 4, 0 },
+ { "word", "Word", 0, 0 },
+ { "word", "Word", 1, 1 },
+ { "word", "Word", 3, 1 },
+ { "word", "wOrd", 0, 0 },
+ { "word", "wOrd", 1, 0 },
+ { "word", "wOrd", 3, 1 },
+ { "word", "woRd", 0, 0 },
+ { "word", "woRd", 1, 0 },
+ { "word", "woRd", 3, 1 },
+ { "word", "worD", 0, 0 },
+ { "word", "worD", 1, 0 },
+ { "word", "worD", 3, 0 },
+ { "WORD", "wORD", 0, 0 },
+ { "WORD", "wORD", 1, -1 },
+ { "WORD", "wORD", 3, -1 },
+ { "WORD", "WoRD", 0, 0 },
+ { "WORD", "WoRD", 1, 0 },
+ { "WORD", "WoRD", 3, -1 },
+ { "WORD", "WOrD", 0, 0 },
+ { "WORD", "WOrD", 1, 0 },
+ { "WORD", "WOrD", 3, -1 },
+ { "WORD", "WORd", 0, 0 },
+ { "WORD", "WORd", 1, 0 },
+ { "WORD", "WORd", 3, 0 }
+
+ };
int i;
@@ -1059,13 +1085,19 @@ PRBool test_012(void)
switch( array[i].sign )
{
case -1:
- if( rv < 0 ) continue;
+ if( rv < 0 ) {
+ continue;
+ }
break;
case 1:
- if( rv > 0 ) continue;
+ if( rv > 0 ) {
+ continue;
+ }
break;
case 0:
- if( 0 == rv ) continue;
+ if( 0 == rv ) {
+ continue;
+ }
break;
default:
PR_NOT_REACHED("static data inconsistancy");
@@ -1092,39 +1124,39 @@ PRBool test_013(void)
const char *two;
PRIntn sign;
} array[] =
- {
- { (const char *)0, (const char *)0, 0 },
- { (const char *)0, "word", -1 },
- { "word", (const char *)0, 1 },
- { "word", "word", 0 },
- { "aZYXVUT", "bZYXVUT", -1 },
- { "aZYXVUT", "bAAAAAA", -1 },
- { "a", "aa", -1 },
- { "a", "a", 0 },
- { "a", "A", 0 },
- { "aaaaa", "baaaa", -1 },
- { "aaaaa", "abaaa", -1 },
- { "aaaaa", "aabaa", -1 },
- { "aaaaa", "aaaba", -1 },
- { "aaaaa", "aaaab", -1 },
- { "bZYXVUT", "aZYXVUT", 1 },
- { "bAAAAAA", "aZYXVUT", 1 },
- { "aa", "a", 1 },
- { "A", "a", 0 },
- { "baaaa", "aaaaa", 1 },
- { "abaaa", "aaaaa", 1 },
- { "aabaa", "aaaaa", 1 },
- { "aaaba", "aaaaa", 1 },
- { "aaaab", "aaaaa", 1 },
- { "word", "Word", 0 },
- { "word", "wOrd", 0 },
- { "word", "woRd", 0 },
- { "word", "worD", 0 },
- { "WORD", "wORD", 0 },
- { "WORD", "WoRD", 0 },
- { "WORD", "WOrD", 0 },
- { "WORD", "WORd", 0 }
- };
+ {
+ { (const char *)0, (const char *)0, 0 },
+ { (const char *)0, "word", -1 },
+ { "word", (const char *)0, 1 },
+ { "word", "word", 0 },
+ { "aZYXVUT", "bZYXVUT", -1 },
+ { "aZYXVUT", "bAAAAAA", -1 },
+ { "a", "aa", -1 },
+ { "a", "a", 0 },
+ { "a", "A", 0 },
+ { "aaaaa", "baaaa", -1 },
+ { "aaaaa", "abaaa", -1 },
+ { "aaaaa", "aabaa", -1 },
+ { "aaaaa", "aaaba", -1 },
+ { "aaaaa", "aaaab", -1 },
+ { "bZYXVUT", "aZYXVUT", 1 },
+ { "bAAAAAA", "aZYXVUT", 1 },
+ { "aa", "a", 1 },
+ { "A", "a", 0 },
+ { "baaaa", "aaaaa", 1 },
+ { "abaaa", "aaaaa", 1 },
+ { "aabaa", "aaaaa", 1 },
+ { "aaaba", "aaaaa", 1 },
+ { "aaaab", "aaaaa", 1 },
+ { "word", "Word", 0 },
+ { "word", "wOrd", 0 },
+ { "word", "woRd", 0 },
+ { "word", "worD", 0 },
+ { "WORD", "wORD", 0 },
+ { "WORD", "WoRD", 0 },
+ { "WORD", "WOrD", 0 },
+ { "WORD", "WORd", 0 }
+ };
int i;
@@ -1137,13 +1169,19 @@ PRBool test_013(void)
switch( array[i].sign )
{
case -1:
- if( rv < 0 ) continue;
+ if( rv < 0 ) {
+ continue;
+ }
break;
case 1:
- if( rv > 0 ) continue;
+ if( rv > 0 ) {
+ continue;
+ }
break;
case 0:
- if( 0 == rv ) continue;
+ if( 0 == rv ) {
+ continue;
+ }
break;
default:
PR_NOT_REACHED("static data inconsistancy");
@@ -1171,104 +1209,104 @@ PRBool test_014(void)
PRUint32 max;
PRIntn sign;
} array[] =
- {
- { (const char *)0, (const char *)0, 0, 0 },
- { (const char *)0, (const char *)0, 1, 0 },
- { (const char *)0, (const char *)0, 4, 0 },
- { (const char *)0, "word", 0, -1 },
- { (const char *)0, "word", 1, -1 },
- { (const char *)0, "word", 4, -1 },
- { "word", (const char *)0, 0, 1 },
- { "word", (const char *)0, 1, 1 },
- { "word", (const char *)0, 4, 1 },
- { "word", "word", 0, 0 },
- { "word", "word", 1, 0 },
- { "word", "word", 3, 0 },
- { "word", "word", 5, 0 },
- { "aZYXVUT", "bZYXVUT", 0, 0 },
- { "aZYXVUT", "bZYXVUT", 1, -1 },
- { "aZYXVUT", "bZYXVUT", 4, -1 },
- { "aZYXVUT", "bZYXVUT", 9, -1 },
- { "aZYXVUT", "bAAAAAA", 0, 0 },
- { "aZYXVUT", "bAAAAAA", 1, -1 },
- { "aZYXVUT", "bAAAAAA", 4, -1 },
- { "aZYXVUT", "bAAAAAA", 5, -1 },
- { "a", "aa", 0, 0 },
- { "a", "aa", 1, 0 },
- { "a", "aa", 4, -1 },
- { "a", "a", 0, 0 },
- { "a", "a", 1, 0 },
- { "a", "a", 4, 0 },
- { "a", "A", 0, 0 },
- { "a", "A", 1, 0 },
- { "a", "A", 4, 0 },
- { "aaaaa", "baaaa", 0, 0 },
- { "aaaaa", "baaaa", 1, -1 },
- { "aaaaa", "baaaa", 4, -1 },
- { "aaaaa", "abaaa", 0, 0 },
- { "aaaaa", "abaaa", 1, 0 },
- { "aaaaa", "abaaa", 4, -1 },
- { "aaaaa", "aabaa", 0, 0 },
- { "aaaaa", "aabaa", 1, 0 },
- { "aaaaa", "aabaa", 4, -1 },
- { "aaaaa", "aaaba", 0, 0 },
- { "aaaaa", "aaaba", 1, 0 },
- { "aaaaa", "aaaba", 4, -1 },
- { "aaaaa", "aaaab", 0, 0 },
- { "aaaaa", "aaaab", 1, 0 },
- { "aaaaa", "aaaab", 4, 0 },
- { "bZYXVUT", "aZYXVUT", 0, 0 },
- { "bZYXVUT", "aZYXVUT", 1, 1 },
- { "bZYXVUT", "aZYXVUT", 4, 1 },
- { "bAAAAAA", "aZYXVUT", 0, 0 },
- { "bAAAAAA", "aZYXVUT", 1, 1 },
- { "bAAAAAA", "aZYXVUT", 4, 1 },
- { "aa", "a", 0, 0 },
- { "aa", "a", 1, 0 },
- { "aa", "a", 4, 1 },
- { "A", "a", 0, 0 },
- { "A", "a", 1, 0 },
- { "A", "a", 4, 0 },
- { "baaaa", "aaaaa", 0, 0 },
- { "baaaa", "aaaaa", 1, 1 },
- { "baaaa", "aaaaa", 4, 1 },
- { "abaaa", "aaaaa", 0, 0 },
- { "abaaa", "aaaaa", 1, 0 },
- { "abaaa", "aaaaa", 4, 1 },
- { "aabaa", "aaaaa", 0, 0 },
- { "aabaa", "aaaaa", 1, 0 },
- { "aabaa", "aaaaa", 4, 1 },
- { "aaaba", "aaaaa", 0, 0 },
- { "aaaba", "aaaaa", 1, 0 },
- { "aaaba", "aaaaa", 4, 1 },
- { "aaaab", "aaaaa", 0, 0 },
- { "aaaab", "aaaaa", 1, 0 },
- { "aaaab", "aaaaa", 4, 0 },
- { "word", "Word", 0, 0 },
- { "word", "Word", 1, 0 },
- { "word", "Word", 3, 0 },
- { "word", "wOrd", 0, 0 },
- { "word", "wOrd", 1, 0 },
- { "word", "wOrd", 3, 0 },
- { "word", "woRd", 0, 0 },
- { "word", "woRd", 1, 0 },
- { "word", "woRd", 3, 0 },
- { "word", "worD", 0, 0 },
- { "word", "worD", 1, 0 },
- { "word", "worD", 3, 0 },
- { "WORD", "wORD", 0, 0 },
- { "WORD", "wORD", 1, 0 },
- { "WORD", "wORD", 3, 0 },
- { "WORD", "WoRD", 0, 0 },
- { "WORD", "WoRD", 1, 0 },
- { "WORD", "WoRD", 3, 0 },
- { "WORD", "WOrD", 0, 0 },
- { "WORD", "WOrD", 1, 0 },
- { "WORD", "WOrD", 3, 0 },
- { "WORD", "WORd", 0, 0 },
- { "WORD", "WORd", 1, 0 },
- { "WORD", "WORd", 3, 0 }
- };
+ {
+ { (const char *)0, (const char *)0, 0, 0 },
+ { (const char *)0, (const char *)0, 1, 0 },
+ { (const char *)0, (const char *)0, 4, 0 },
+ { (const char *)0, "word", 0, -1 },
+ { (const char *)0, "word", 1, -1 },
+ { (const char *)0, "word", 4, -1 },
+ { "word", (const char *)0, 0, 1 },
+ { "word", (const char *)0, 1, 1 },
+ { "word", (const char *)0, 4, 1 },
+ { "word", "word", 0, 0 },
+ { "word", "word", 1, 0 },
+ { "word", "word", 3, 0 },
+ { "word", "word", 5, 0 },
+ { "aZYXVUT", "bZYXVUT", 0, 0 },
+ { "aZYXVUT", "bZYXVUT", 1, -1 },
+ { "aZYXVUT", "bZYXVUT", 4, -1 },
+ { "aZYXVUT", "bZYXVUT", 9, -1 },
+ { "aZYXVUT", "bAAAAAA", 0, 0 },
+ { "aZYXVUT", "bAAAAAA", 1, -1 },
+ { "aZYXVUT", "bAAAAAA", 4, -1 },
+ { "aZYXVUT", "bAAAAAA", 5, -1 },
+ { "a", "aa", 0, 0 },
+ { "a", "aa", 1, 0 },
+ { "a", "aa", 4, -1 },
+ { "a", "a", 0, 0 },
+ { "a", "a", 1, 0 },
+ { "a", "a", 4, 0 },
+ { "a", "A", 0, 0 },
+ { "a", "A", 1, 0 },
+ { "a", "A", 4, 0 },
+ { "aaaaa", "baaaa", 0, 0 },
+ { "aaaaa", "baaaa", 1, -1 },
+ { "aaaaa", "baaaa", 4, -1 },
+ { "aaaaa", "abaaa", 0, 0 },
+ { "aaaaa", "abaaa", 1, 0 },
+ { "aaaaa", "abaaa", 4, -1 },
+ { "aaaaa", "aabaa", 0, 0 },
+ { "aaaaa", "aabaa", 1, 0 },
+ { "aaaaa", "aabaa", 4, -1 },
+ { "aaaaa", "aaaba", 0, 0 },
+ { "aaaaa", "aaaba", 1, 0 },
+ { "aaaaa", "aaaba", 4, -1 },
+ { "aaaaa", "aaaab", 0, 0 },
+ { "aaaaa", "aaaab", 1, 0 },
+ { "aaaaa", "aaaab", 4, 0 },
+ { "bZYXVUT", "aZYXVUT", 0, 0 },
+ { "bZYXVUT", "aZYXVUT", 1, 1 },
+ { "bZYXVUT", "aZYXVUT", 4, 1 },
+ { "bAAAAAA", "aZYXVUT", 0, 0 },
+ { "bAAAAAA", "aZYXVUT", 1, 1 },
+ { "bAAAAAA", "aZYXVUT", 4, 1 },
+ { "aa", "a", 0, 0 },
+ { "aa", "a", 1, 0 },
+ { "aa", "a", 4, 1 },
+ { "A", "a", 0, 0 },
+ { "A", "a", 1, 0 },
+ { "A", "a", 4, 0 },
+ { "baaaa", "aaaaa", 0, 0 },
+ { "baaaa", "aaaaa", 1, 1 },
+ { "baaaa", "aaaaa", 4, 1 },
+ { "abaaa", "aaaaa", 0, 0 },
+ { "abaaa", "aaaaa", 1, 0 },
+ { "abaaa", "aaaaa", 4, 1 },
+ { "aabaa", "aaaaa", 0, 0 },
+ { "aabaa", "aaaaa", 1, 0 },
+ { "aabaa", "aaaaa", 4, 1 },
+ { "aaaba", "aaaaa", 0, 0 },
+ { "aaaba", "aaaaa", 1, 0 },
+ { "aaaba", "aaaaa", 4, 1 },
+ { "aaaab", "aaaaa", 0, 0 },
+ { "aaaab", "aaaaa", 1, 0 },
+ { "aaaab", "aaaaa", 4, 0 },
+ { "word", "Word", 0, 0 },
+ { "word", "Word", 1, 0 },
+ { "word", "Word", 3, 0 },
+ { "word", "wOrd", 0, 0 },
+ { "word", "wOrd", 1, 0 },
+ { "word", "wOrd", 3, 0 },
+ { "word", "woRd", 0, 0 },
+ { "word", "woRd", 1, 0 },
+ { "word", "woRd", 3, 0 },
+ { "word", "worD", 0, 0 },
+ { "word", "worD", 1, 0 },
+ { "word", "worD", 3, 0 },
+ { "WORD", "wORD", 0, 0 },
+ { "WORD", "wORD", 1, 0 },
+ { "WORD", "wORD", 3, 0 },
+ { "WORD", "WoRD", 0, 0 },
+ { "WORD", "WoRD", 1, 0 },
+ { "WORD", "WoRD", 3, 0 },
+ { "WORD", "WOrD", 0, 0 },
+ { "WORD", "WOrD", 1, 0 },
+ { "WORD", "WOrD", 3, 0 },
+ { "WORD", "WORd", 0, 0 },
+ { "WORD", "WORd", 1, 0 },
+ { "WORD", "WORd", 3, 0 }
+ };
int i;
@@ -1281,13 +1319,19 @@ PRBool test_014(void)
switch( array[i].sign )
{
case -1:
- if( rv < 0 ) continue;
+ if( rv < 0 ) {
+ continue;
+ }
break;
case 1:
- if( rv > 0 ) continue;
+ if( rv > 0 ) {
+ continue;
+ }
break;
case 0:
- if( 0 == rv ) continue;
+ if( 0 == rv ) {
+ continue;
+ }
break;
default:
PR_NOT_REACHED("static data inconsistancy");
@@ -1315,36 +1359,36 @@ PRBool test_015(void)
PRBool ret;
PRUint32 off;
} array[] =
- {
- { (const char *)0, 'a', PR_FALSE, 0 },
- { (const char *)0, '\0', PR_FALSE, 0 },
- { "abcdefg", 'a', PR_TRUE, 0 },
- { "abcdefg", 'b', PR_TRUE, 1 },
- { "abcdefg", 'c', PR_TRUE, 2 },
- { "abcdefg", 'd', PR_TRUE, 3 },
- { "abcdefg", 'e', PR_TRUE, 4 },
- { "abcdefg", 'f', PR_TRUE, 5 },
- { "abcdefg", 'g', PR_TRUE, 6 },
- { "abcdefg", 'h', PR_FALSE, 0 },
- { "abcdefg", '\0', PR_TRUE, 7 },
- { "abcdefg", 'A', PR_FALSE, 0 },
- { "abcdefg", 'B', PR_FALSE, 0 },
- { "abcdefg", 'C', PR_FALSE, 0 },
- { "abcdefg", 'D', PR_FALSE, 0 },
- { "abcdefg", 'E', PR_FALSE, 0 },
- { "abcdefg", 'F', PR_FALSE, 0 },
- { "abcdefg", 'G', PR_FALSE, 0 },
- { "abcdefg", 'H', PR_FALSE, 0 },
- { "abcdefgabcdefg", 'a', PR_TRUE, 0 },
- { "abcdefgabcdefg", 'b', PR_TRUE, 1 },
- { "abcdefgabcdefg", 'c', PR_TRUE, 2 },
- { "abcdefgabcdefg", 'd', PR_TRUE, 3 },
- { "abcdefgabcdefg", 'e', PR_TRUE, 4 },
- { "abcdefgabcdefg", 'f', PR_TRUE, 5 },
- { "abcdefgabcdefg", 'g', PR_TRUE, 6 },
- { "abcdefgabcdefg", 'h', PR_FALSE, 0 },
- { "abcdefgabcdefg", '\0', PR_TRUE, 14 }
- };
+ {
+ { (const char *)0, 'a', PR_FALSE, 0 },
+ { (const char *)0, '\0', PR_FALSE, 0 },
+ { "abcdefg", 'a', PR_TRUE, 0 },
+ { "abcdefg", 'b', PR_TRUE, 1 },
+ { "abcdefg", 'c', PR_TRUE, 2 },
+ { "abcdefg", 'd', PR_TRUE, 3 },
+ { "abcdefg", 'e', PR_TRUE, 4 },
+ { "abcdefg", 'f', PR_TRUE, 5 },
+ { "abcdefg", 'g', PR_TRUE, 6 },
+ { "abcdefg", 'h', PR_FALSE, 0 },
+ { "abcdefg", '\0', PR_TRUE, 7 },
+ { "abcdefg", 'A', PR_FALSE, 0 },
+ { "abcdefg", 'B', PR_FALSE, 0 },
+ { "abcdefg", 'C', PR_FALSE, 0 },
+ { "abcdefg", 'D', PR_FALSE, 0 },
+ { "abcdefg", 'E', PR_FALSE, 0 },
+ { "abcdefg", 'F', PR_FALSE, 0 },
+ { "abcdefg", 'G', PR_FALSE, 0 },
+ { "abcdefg", 'H', PR_FALSE, 0 },
+ { "abcdefgabcdefg", 'a', PR_TRUE, 0 },
+ { "abcdefgabcdefg", 'b', PR_TRUE, 1 },
+ { "abcdefgabcdefg", 'c', PR_TRUE, 2 },
+ { "abcdefgabcdefg", 'd', PR_TRUE, 3 },
+ { "abcdefgabcdefg", 'e', PR_TRUE, 4 },
+ { "abcdefgabcdefg", 'f', PR_TRUE, 5 },
+ { "abcdefgabcdefg", 'g', PR_TRUE, 6 },
+ { "abcdefgabcdefg", 'h', PR_FALSE, 0 },
+ { "abcdefgabcdefg", '\0', PR_TRUE, 14 }
+ };
int i;
@@ -1395,36 +1439,36 @@ PRBool test_016(void)
PRBool ret;
PRUint32 off;
} array[] =
- {
- { (const char *)0, 'a', PR_FALSE, 0 },
- { (const char *)0, '\0', PR_FALSE, 0 },
- { "abcdefg", 'a', PR_TRUE, 0 },
- { "abcdefg", 'b', PR_TRUE, 1 },
- { "abcdefg", 'c', PR_TRUE, 2 },
- { "abcdefg", 'd', PR_TRUE, 3 },
- { "abcdefg", 'e', PR_TRUE, 4 },
- { "abcdefg", 'f', PR_TRUE, 5 },
- { "abcdefg", 'g', PR_TRUE, 6 },
- { "abcdefg", 'h', PR_FALSE, 0 },
- { "abcdefg", '\0', PR_TRUE, 7 },
- { "abcdefg", 'A', PR_FALSE, 0 },
- { "abcdefg", 'B', PR_FALSE, 0 },
- { "abcdefg", 'C', PR_FALSE, 0 },
- { "abcdefg", 'D', PR_FALSE, 0 },
- { "abcdefg", 'E', PR_FALSE, 0 },
- { "abcdefg", 'F', PR_FALSE, 0 },
- { "abcdefg", 'G', PR_FALSE, 0 },
- { "abcdefg", 'H', PR_FALSE, 0 },
- { "abcdefgabcdefg", 'a', PR_TRUE, 7 },
- { "abcdefgabcdefg", 'b', PR_TRUE, 8 },
- { "abcdefgabcdefg", 'c', PR_TRUE, 9 },
- { "abcdefgabcdefg", 'd', PR_TRUE, 10 },
- { "abcdefgabcdefg", 'e', PR_TRUE, 11 },
- { "abcdefgabcdefg", 'f', PR_TRUE, 12 },
- { "abcdefgabcdefg", 'g', PR_TRUE, 13 },
- { "abcdefgabcdefg", 'h', PR_FALSE, 0 },
- { "abcdefgabcdefg", '\0', PR_TRUE, 14 }
- };
+ {
+ { (const char *)0, 'a', PR_FALSE, 0 },
+ { (const char *)0, '\0', PR_FALSE, 0 },
+ { "abcdefg", 'a', PR_TRUE, 0 },
+ { "abcdefg", 'b', PR_TRUE, 1 },
+ { "abcdefg", 'c', PR_TRUE, 2 },
+ { "abcdefg", 'd', PR_TRUE, 3 },
+ { "abcdefg", 'e', PR_TRUE, 4 },
+ { "abcdefg", 'f', PR_TRUE, 5 },
+ { "abcdefg", 'g', PR_TRUE, 6 },
+ { "abcdefg", 'h', PR_FALSE, 0 },
+ { "abcdefg", '\0', PR_TRUE, 7 },
+ { "abcdefg", 'A', PR_FALSE, 0 },
+ { "abcdefg", 'B', PR_FALSE, 0 },
+ { "abcdefg", 'C', PR_FALSE, 0 },
+ { "abcdefg", 'D', PR_FALSE, 0 },
+ { "abcdefg", 'E', PR_FALSE, 0 },
+ { "abcdefg", 'F', PR_FALSE, 0 },
+ { "abcdefg", 'G', PR_FALSE, 0 },
+ { "abcdefg", 'H', PR_FALSE, 0 },
+ { "abcdefgabcdefg", 'a', PR_TRUE, 7 },
+ { "abcdefgabcdefg", 'b', PR_TRUE, 8 },
+ { "abcdefgabcdefg", 'c', PR_TRUE, 9 },
+ { "abcdefgabcdefg", 'd', PR_TRUE, 10 },
+ { "abcdefgabcdefg", 'e', PR_TRUE, 11 },
+ { "abcdefgabcdefg", 'f', PR_TRUE, 12 },
+ { "abcdefgabcdefg", 'g', PR_TRUE, 13 },
+ { "abcdefgabcdefg", 'h', PR_FALSE, 0 },
+ { "abcdefgabcdefg", '\0', PR_TRUE, 14 }
+ };
int i;
@@ -1476,39 +1520,39 @@ PRBool test_017(void)
PRBool ret;
PRUint32 off;
} array[] =
- {
- { (const char *)0, 'a', 2, PR_FALSE, 0 },
- { (const char *)0, '\0', 2, PR_FALSE, 0 },
- { "abcdefg", 'a', 5, PR_TRUE, 0 },
- { "abcdefg", 'b', 5, PR_TRUE, 1 },
- { "abcdefg", 'c', 5, PR_TRUE, 2 },
- { "abcdefg", 'd', 5, PR_TRUE, 3 },
- { "abcdefg", 'e', 5, PR_TRUE, 4 },
- { "abcdefg", 'f', 5, PR_FALSE, 0 },
- { "abcdefg", 'g', 5, PR_FALSE, 0 },
- { "abcdefg", 'h', 5, PR_FALSE, 0 },
- { "abcdefg", '\0', 5, PR_FALSE, 0 },
- { "abcdefg", '\0', 15, PR_TRUE, 7 },
- { "abcdefg", 'A', 5, PR_FALSE, 0 },
- { "abcdefg", 'B', 5, PR_FALSE, 0 },
- { "abcdefg", 'C', 5, PR_FALSE, 0 },
- { "abcdefg", 'D', 5, PR_FALSE, 0 },
- { "abcdefg", 'E', 5, PR_FALSE, 0 },
- { "abcdefg", 'F', 5, PR_FALSE, 0 },
- { "abcdefg", 'G', 5, PR_FALSE, 0 },
- { "abcdefg", 'H', 5, PR_FALSE, 0 },
- { "abcdefgabcdefg", 'a', 10, PR_TRUE, 0 },
- { "abcdefgabcdefg", 'b', 10, PR_TRUE, 1 },
- { "abcdefgabcdefg", 'c', 10, PR_TRUE, 2 },
- { "abcdefgabcdefg", 'd', 10, PR_TRUE, 3 },
- { "abcdefgabcdefg", 'e', 10, PR_TRUE, 4 },
- { "abcdefgabcdefg", 'f', 10, PR_TRUE, 5 },
- { "abcdefgabcdefg", 'g', 10, PR_TRUE, 6 },
- { "abcdefgabcdefg", 'h', 10, PR_FALSE, 0 },
- { "abcdefgabcdefg", '\0', 10, PR_FALSE, 0 },
- { "abcdefgabcdefg", '\0', 14, PR_FALSE, 0 },
- { "abcdefgabcdefg", '\0', 15, PR_TRUE, 14 }
- };
+ {
+ { (const char *)0, 'a', 2, PR_FALSE, 0 },
+ { (const char *)0, '\0', 2, PR_FALSE, 0 },
+ { "abcdefg", 'a', 5, PR_TRUE, 0 },
+ { "abcdefg", 'b', 5, PR_TRUE, 1 },
+ { "abcdefg", 'c', 5, PR_TRUE, 2 },
+ { "abcdefg", 'd', 5, PR_TRUE, 3 },
+ { "abcdefg", 'e', 5, PR_TRUE, 4 },
+ { "abcdefg", 'f', 5, PR_FALSE, 0 },
+ { "abcdefg", 'g', 5, PR_FALSE, 0 },
+ { "abcdefg", 'h', 5, PR_FALSE, 0 },
+ { "abcdefg", '\0', 5, PR_FALSE, 0 },
+ { "abcdefg", '\0', 15, PR_TRUE, 7 },
+ { "abcdefg", 'A', 5, PR_FALSE, 0 },
+ { "abcdefg", 'B', 5, PR_FALSE, 0 },
+ { "abcdefg", 'C', 5, PR_FALSE, 0 },
+ { "abcdefg", 'D', 5, PR_FALSE, 0 },
+ { "abcdefg", 'E', 5, PR_FALSE, 0 },
+ { "abcdefg", 'F', 5, PR_FALSE, 0 },
+ { "abcdefg", 'G', 5, PR_FALSE, 0 },
+ { "abcdefg", 'H', 5, PR_FALSE, 0 },
+ { "abcdefgabcdefg", 'a', 10, PR_TRUE, 0 },
+ { "abcdefgabcdefg", 'b', 10, PR_TRUE, 1 },
+ { "abcdefgabcdefg", 'c', 10, PR_TRUE, 2 },
+ { "abcdefgabcdefg", 'd', 10, PR_TRUE, 3 },
+ { "abcdefgabcdefg", 'e', 10, PR_TRUE, 4 },
+ { "abcdefgabcdefg", 'f', 10, PR_TRUE, 5 },
+ { "abcdefgabcdefg", 'g', 10, PR_TRUE, 6 },
+ { "abcdefgabcdefg", 'h', 10, PR_FALSE, 0 },
+ { "abcdefgabcdefg", '\0', 10, PR_FALSE, 0 },
+ { "abcdefgabcdefg", '\0', 14, PR_FALSE, 0 },
+ { "abcdefgabcdefg", '\0', 15, PR_TRUE, 14 }
+ };
int i;
@@ -1560,39 +1604,39 @@ PRBool test_018(void)
PRBool ret;
PRUint32 off;
} array[] =
- {
- { (const char *)0, 'a', 2, PR_FALSE, 0 },
- { (const char *)0, '\0', 2, PR_FALSE, 0 },
- { "abcdefg", 'a', 5, PR_TRUE, 0 },
- { "abcdefg", 'b', 5, PR_TRUE, 1 },
- { "abcdefg", 'c', 5, PR_TRUE, 2 },
- { "abcdefg", 'd', 5, PR_TRUE, 3 },
- { "abcdefg", 'e', 5, PR_TRUE, 4 },
- { "abcdefg", 'f', 5, PR_FALSE, 0 },
- { "abcdefg", 'g', 5, PR_FALSE, 0 },
- { "abcdefg", 'h', 5, PR_FALSE, 0 },
- { "abcdefg", '\0', 5, PR_FALSE, 0 },
- { "abcdefg", '\0', 15, PR_TRUE, 7 },
- { "abcdefg", 'A', 5, PR_FALSE, 0 },
- { "abcdefg", 'B', 5, PR_FALSE, 0 },
- { "abcdefg", 'C', 5, PR_FALSE, 0 },
- { "abcdefg", 'D', 5, PR_FALSE, 0 },
- { "abcdefg", 'E', 5, PR_FALSE, 0 },
- { "abcdefg", 'F', 5, PR_FALSE, 0 },
- { "abcdefg", 'G', 5, PR_FALSE, 0 },
- { "abcdefg", 'H', 5, PR_FALSE, 0 },
- { "abcdefgabcdefg", 'a', 10, PR_TRUE, 7 },
- { "abcdefgabcdefg", 'b', 10, PR_TRUE, 8 },
- { "abcdefgabcdefg", 'c', 10, PR_TRUE, 9 },
- { "abcdefgabcdefg", 'd', 10, PR_TRUE, 3 },
- { "abcdefgabcdefg", 'e', 10, PR_TRUE, 4 },
- { "abcdefgabcdefg", 'f', 10, PR_TRUE, 5 },
- { "abcdefgabcdefg", 'g', 10, PR_TRUE, 6 },
- { "abcdefgabcdefg", 'h', 10, PR_FALSE, 0 },
- { "abcdefgabcdefg", '\0', 10, PR_FALSE, 0 },
- { "abcdefgabcdefg", '\0', 14, PR_FALSE, 0 },
- { "abcdefgabcdefg", '\0', 15, PR_TRUE, 14 }
- };
+ {
+ { (const char *)0, 'a', 2, PR_FALSE, 0 },
+ { (const char *)0, '\0', 2, PR_FALSE, 0 },
+ { "abcdefg", 'a', 5, PR_TRUE, 0 },
+ { "abcdefg", 'b', 5, PR_TRUE, 1 },
+ { "abcdefg", 'c', 5, PR_TRUE, 2 },
+ { "abcdefg", 'd', 5, PR_TRUE, 3 },
+ { "abcdefg", 'e', 5, PR_TRUE, 4 },
+ { "abcdefg", 'f', 5, PR_FALSE, 0 },
+ { "abcdefg", 'g', 5, PR_FALSE, 0 },
+ { "abcdefg", 'h', 5, PR_FALSE, 0 },
+ { "abcdefg", '\0', 5, PR_FALSE, 0 },
+ { "abcdefg", '\0', 15, PR_TRUE, 7 },
+ { "abcdefg", 'A', 5, PR_FALSE, 0 },
+ { "abcdefg", 'B', 5, PR_FALSE, 0 },
+ { "abcdefg", 'C', 5, PR_FALSE, 0 },
+ { "abcdefg", 'D', 5, PR_FALSE, 0 },
+ { "abcdefg", 'E', 5, PR_FALSE, 0 },
+ { "abcdefg", 'F', 5, PR_FALSE, 0 },
+ { "abcdefg", 'G', 5, PR_FALSE, 0 },
+ { "abcdefg", 'H', 5, PR_FALSE, 0 },
+ { "abcdefgabcdefg", 'a', 10, PR_TRUE, 7 },
+ { "abcdefgabcdefg", 'b', 10, PR_TRUE, 8 },
+ { "abcdefgabcdefg", 'c', 10, PR_TRUE, 9 },
+ { "abcdefgabcdefg", 'd', 10, PR_TRUE, 3 },
+ { "abcdefgabcdefg", 'e', 10, PR_TRUE, 4 },
+ { "abcdefgabcdefg", 'f', 10, PR_TRUE, 5 },
+ { "abcdefgabcdefg", 'g', 10, PR_TRUE, 6 },
+ { "abcdefgabcdefg", 'h', 10, PR_FALSE, 0 },
+ { "abcdefgabcdefg", '\0', 10, PR_FALSE, 0 },
+ { "abcdefgabcdefg", '\0', 14, PR_FALSE, 0 },
+ { "abcdefgabcdefg", '\0', 15, PR_TRUE, 14 }
+ };
int i;
@@ -1643,41 +1687,41 @@ PRBool test_019(void)
PRBool ret;
PRUint32 off;
} array[] =
- {
- { (const char *)0, (const char *)0, PR_FALSE, 0 },
- { (const char *)0, "abc", PR_FALSE, 0 },
- { "abc", (const char *)0, PR_FALSE, 0 },
- { "abcdefg", "", PR_FALSE, 0 },
- { "", "aeiou", PR_FALSE, 0 },
- { "abcdefg", "ae", PR_TRUE, 0 },
- { "abcdefg", "ei", PR_TRUE, 4 },
- { "abcdefg", "io", PR_FALSE, 0 },
- { "abcdefg", "bcd", PR_TRUE, 1 },
- { "abcdefg", "cbd", PR_TRUE, 1 },
- { "abcdefg", "dbc", PR_TRUE, 1 },
- { "abcdefg", "ghi", PR_TRUE, 6 },
- { "abcdefg", "AE", PR_FALSE, 0 },
- { "abcdefg", "EI", PR_FALSE, 0 },
- { "abcdefg", "IO", PR_FALSE, 0 },
- { "abcdefg", "BCD", PR_FALSE, 0 },
- { "abcdefg", "CBD", PR_FALSE, 0 },
- { "abcdefg", "DBC", PR_FALSE, 0 },
- { "abcdefg", "GHI", PR_FALSE, 0 },
- { "abcdefgabcdefg", "ae", PR_TRUE, 0 },
- { "abcdefgabcdefg", "ei", PR_TRUE, 4 },
- { "abcdefgabcdefg", "io", PR_FALSE, 0 },
- { "abcdefgabcdefg", "bcd", PR_TRUE, 1 },
- { "abcdefgabcdefg", "cbd", PR_TRUE, 1 },
- { "abcdefgabcdefg", "dbc", PR_TRUE, 1 },
- { "abcdefgabcdefg", "ghi", PR_TRUE, 6 },
- { "abcdefgabcdefg", "AE", PR_FALSE, 0 },
- { "abcdefgabcdefg", "EI", PR_FALSE, 0 },
- { "abcdefgabcdefg", "IO", PR_FALSE, 0 },
- { "abcdefgabcdefg", "BCD", PR_FALSE, 0 },
- { "abcdefgabcdefg", "CBD", PR_FALSE, 0 },
- { "abcdefgabcdefg", "DBC", PR_FALSE, 0 },
- { "abcdefgabcdefg", "GHI", PR_FALSE, 0 }
- };
+ {
+ { (const char *)0, (const char *)0, PR_FALSE, 0 },
+ { (const char *)0, "abc", PR_FALSE, 0 },
+ { "abc", (const char *)0, PR_FALSE, 0 },
+ { "abcdefg", "", PR_FALSE, 0 },
+ { "", "aeiou", PR_FALSE, 0 },
+ { "abcdefg", "ae", PR_TRUE, 0 },
+ { "abcdefg", "ei", PR_TRUE, 4 },
+ { "abcdefg", "io", PR_FALSE, 0 },
+ { "abcdefg", "bcd", PR_TRUE, 1 },
+ { "abcdefg", "cbd", PR_TRUE, 1 },
+ { "abcdefg", "dbc", PR_TRUE, 1 },
+ { "abcdefg", "ghi", PR_TRUE, 6 },
+ { "abcdefg", "AE", PR_FALSE, 0 },
+ { "abcdefg", "EI", PR_FALSE, 0 },
+ { "abcdefg", "IO", PR_FALSE, 0 },
+ { "abcdefg", "BCD", PR_FALSE, 0 },
+ { "abcdefg", "CBD", PR_FALSE, 0 },
+ { "abcdefg", "DBC", PR_FALSE, 0 },
+ { "abcdefg", "GHI", PR_FALSE, 0 },
+ { "abcdefgabcdefg", "ae", PR_TRUE, 0 },
+ { "abcdefgabcdefg", "ei", PR_TRUE, 4 },
+ { "abcdefgabcdefg", "io", PR_FALSE, 0 },
+ { "abcdefgabcdefg", "bcd", PR_TRUE, 1 },
+ { "abcdefgabcdefg", "cbd", PR_TRUE, 1 },
+ { "abcdefgabcdefg", "dbc", PR_TRUE, 1 },
+ { "abcdefgabcdefg", "ghi", PR_TRUE, 6 },
+ { "abcdefgabcdefg", "AE", PR_FALSE, 0 },
+ { "abcdefgabcdefg", "EI", PR_FALSE, 0 },
+ { "abcdefgabcdefg", "IO", PR_FALSE, 0 },
+ { "abcdefgabcdefg", "BCD", PR_FALSE, 0 },
+ { "abcdefgabcdefg", "CBD", PR_FALSE, 0 },
+ { "abcdefgabcdefg", "DBC", PR_FALSE, 0 },
+ { "abcdefgabcdefg", "GHI", PR_FALSE, 0 }
+ };
int i;
@@ -1734,41 +1778,41 @@ PRBool test_020(void)
PRBool ret;
PRUint32 off;
} array[] =
- {
- { (const char *)0, (const char *)0, PR_FALSE, 0 },
- { (const char *)0, "abc", PR_FALSE, 0 },
- { "abc", (const char *)0, PR_FALSE, 0 },
- { "abcdefg", "", PR_FALSE, 0 },
- { "", "aeiou", PR_FALSE, 0 },
- { "abcdefg", "ae", PR_TRUE, 4 },
- { "abcdefg", "ei", PR_TRUE, 4 },
- { "abcdefg", "io", PR_FALSE, 0 },
- { "abcdefg", "bcd", PR_TRUE, 3 },
- { "abcdefg", "cbd", PR_TRUE, 3 },
- { "abcdefg", "dbc", PR_TRUE, 3 },
- { "abcdefg", "ghi", PR_TRUE, 6 },
- { "abcdefg", "AE", PR_FALSE, 0 },
- { "abcdefg", "EI", PR_FALSE, 0 },
- { "abcdefg", "IO", PR_FALSE, 0 },
- { "abcdefg", "BCD", PR_FALSE, 0 },
- { "abcdefg", "CBD", PR_FALSE, 0 },
- { "abcdefg", "DBC", PR_FALSE, 0 },
- { "abcdefg", "GHI", PR_FALSE, 0 },
- { "abcdefgabcdefg", "ae", PR_TRUE, 11 },
- { "abcdefgabcdefg", "ei", PR_TRUE, 11 },
- { "abcdefgabcdefg", "io", PR_FALSE, 0 },
- { "abcdefgabcdefg", "bcd", PR_TRUE, 10 },
- { "abcdefgabcdefg", "cbd", PR_TRUE, 10 },
- { "abcdefgabcdefg", "dbc", PR_TRUE, 10 },
- { "abcdefgabcdefg", "ghi", PR_TRUE, 13 },
- { "abcdefgabcdefg", "AE", PR_FALSE, 0 },
- { "abcdefgabcdefg", "EI", PR_FALSE, 0 },
- { "abcdefgabcdefg", "IO", PR_FALSE, 0 },
- { "abcdefgabcdefg", "BCD", PR_FALSE, 0 },
- { "abcdefgabcdefg", "CBD", PR_FALSE, 0 },
- { "abcdefgabcdefg", "DBC", PR_FALSE, 0 },
- { "abcdefgabcdefg", "GHI", PR_FALSE, 0 }
- };
+ {
+ { (const char *)0, (const char *)0, PR_FALSE, 0 },
+ { (const char *)0, "abc", PR_FALSE, 0 },
+ { "abc", (const char *)0, PR_FALSE, 0 },
+ { "abcdefg", "", PR_FALSE, 0 },
+ { "", "aeiou", PR_FALSE, 0 },
+ { "abcdefg", "ae", PR_TRUE, 4 },
+ { "abcdefg", "ei", PR_TRUE, 4 },
+ { "abcdefg", "io", PR_FALSE, 0 },
+ { "abcdefg", "bcd", PR_TRUE, 3 },
+ { "abcdefg", "cbd", PR_TRUE, 3 },
+ { "abcdefg", "dbc", PR_TRUE, 3 },
+ { "abcdefg", "ghi", PR_TRUE, 6 },
+ { "abcdefg", "AE", PR_FALSE, 0 },
+ { "abcdefg", "EI", PR_FALSE, 0 },
+ { "abcdefg", "IO", PR_FALSE, 0 },
+ { "abcdefg", "BCD", PR_FALSE, 0 },
+ { "abcdefg", "CBD", PR_FALSE, 0 },
+ { "abcdefg", "DBC", PR_FALSE, 0 },
+ { "abcdefg", "GHI", PR_FALSE, 0 },
+ { "abcdefgabcdefg", "ae", PR_TRUE, 11 },
+ { "abcdefgabcdefg", "ei", PR_TRUE, 11 },
+ { "abcdefgabcdefg", "io", PR_FALSE, 0 },
+ { "abcdefgabcdefg", "bcd", PR_TRUE, 10 },
+ { "abcdefgabcdefg", "cbd", PR_TRUE, 10 },
+ { "abcdefgabcdefg", "dbc", PR_TRUE, 10 },
+ { "abcdefgabcdefg", "ghi", PR_TRUE, 13 },
+ { "abcdefgabcdefg", "AE", PR_FALSE, 0 },
+ { "abcdefgabcdefg", "EI", PR_FALSE, 0 },
+ { "abcdefgabcdefg", "IO", PR_FALSE, 0 },
+ { "abcdefgabcdefg", "BCD", PR_FALSE, 0 },
+ { "abcdefgabcdefg", "CBD", PR_FALSE, 0 },
+ { "abcdefgabcdefg", "DBC", PR_FALSE, 0 },
+ { "abcdefgabcdefg", "GHI", PR_FALSE, 0 }
+ };
int i;
@@ -1826,46 +1870,46 @@ PRBool test_021(void)
PRBool ret;
PRUint32 off;
} array[] =
- {
- { (const char *)0, (const char *)0, 3, PR_FALSE, 0 },
- { (const char *)0, "abc", 3, PR_FALSE, 0 },
- { "abc", (const char *)0, 3, PR_FALSE, 0 },
- { "abcdefg", "", 3, PR_FALSE, 0 },
- { "", "aeiou", 3, PR_FALSE, 0 },
- { "abcdefg", "ae", 0, PR_FALSE, 0 },
- { "abcdefg", "ae", 1, PR_TRUE, 0 },
- { "abcdefg", "ae", 4, PR_TRUE, 0 },
- { "abcdefg", "ae", 5, PR_TRUE, 0 },
- { "abcdefg", "ae", 6, PR_TRUE, 0 },
- { "abcdefg", "ei", 4, PR_FALSE, 0 },
- { "abcdefg", "io", 10, PR_FALSE, 0 },
- { "abcdefg", "bcd", 2, PR_TRUE, 1 },
- { "abcdefg", "cbd", 2, PR_TRUE, 1 },
- { "abcdefg", "dbc", 2, PR_TRUE, 1 },
- { "abcdefg", "ghi", 6, PR_FALSE, 0 },
- { "abcdefg", "ghi", 7, PR_TRUE, 6 },
- { "abcdefg", "AE", 9, PR_FALSE, 0 },
- { "abcdefg", "EI", 9, PR_FALSE, 0 },
- { "abcdefg", "IO", 9, PR_FALSE, 0 },
- { "abcdefg", "BCD", 9, PR_FALSE, 0 },
- { "abcdefg", "CBD", 9, PR_FALSE, 0 },
- { "abcdefg", "DBC", 9, PR_FALSE, 0 },
- { "abcdefg", "GHI", 9, PR_FALSE, 0 },
- { "abcdefgabcdefg", "ae", 10, PR_TRUE, 0 },
- { "abcdefgabcdefg", "ei", 10, PR_TRUE, 4 },
- { "abcdefgabcdefg", "io", 10, PR_FALSE, 0 },
- { "abcdefgabcdefg", "bcd", 10, PR_TRUE, 1 },
- { "abcdefgabcdefg", "cbd", 10, PR_TRUE, 1 },
- { "abcdefgabcdefg", "dbc", 10, PR_TRUE, 1 },
- { "abcdefgabcdefg", "ghi", 10, PR_TRUE, 6 },
- { "abcdefgabcdefg", "AE", 10, PR_FALSE, 0 },
- { "abcdefgabcdefg", "EI", 10, PR_FALSE, 0 },
- { "abcdefgabcdefg", "IO", 10, PR_FALSE, 0 },
- { "abcdefgabcdefg", "BCD", 10, PR_FALSE, 0 },
- { "abcdefgabcdefg", "CBD", 10, PR_FALSE, 0 },
- { "abcdefgabcdefg", "DBC", 10, PR_FALSE, 0 },
- { "abcdefgabcdefg", "GHI", 10, PR_FALSE, 0 }
- };
+ {
+ { (const char *)0, (const char *)0, 3, PR_FALSE, 0 },
+ { (const char *)0, "abc", 3, PR_FALSE, 0 },
+ { "abc", (const char *)0, 3, PR_FALSE, 0 },
+ { "abcdefg", "", 3, PR_FALSE, 0 },
+ { "", "aeiou", 3, PR_FALSE, 0 },
+ { "abcdefg", "ae", 0, PR_FALSE, 0 },
+ { "abcdefg", "ae", 1, PR_TRUE, 0 },
+ { "abcdefg", "ae", 4, PR_TRUE, 0 },
+ { "abcdefg", "ae", 5, PR_TRUE, 0 },
+ { "abcdefg", "ae", 6, PR_TRUE, 0 },
+ { "abcdefg", "ei", 4, PR_FALSE, 0 },
+ { "abcdefg", "io", 10, PR_FALSE, 0 },
+ { "abcdefg", "bcd", 2, PR_TRUE, 1 },
+ { "abcdefg", "cbd", 2, PR_TRUE, 1 },
+ { "abcdefg", "dbc", 2, PR_TRUE, 1 },
+ { "abcdefg", "ghi", 6, PR_FALSE, 0 },
+ { "abcdefg", "ghi", 7, PR_TRUE, 6 },
+ { "abcdefg", "AE", 9, PR_FALSE, 0 },
+ { "abcdefg", "EI", 9, PR_FALSE, 0 },
+ { "abcdefg", "IO", 9, PR_FALSE, 0 },
+ { "abcdefg", "BCD", 9, PR_FALSE, 0 },
+ { "abcdefg", "CBD", 9, PR_FALSE, 0 },
+ { "abcdefg", "DBC", 9, PR_FALSE, 0 },
+ { "abcdefg", "GHI", 9, PR_FALSE, 0 },
+ { "abcdefgabcdefg", "ae", 10, PR_TRUE, 0 },
+ { "abcdefgabcdefg", "ei", 10, PR_TRUE, 4 },
+ { "abcdefgabcdefg", "io", 10, PR_FALSE, 0 },
+ { "abcdefgabcdefg", "bcd", 10, PR_TRUE, 1 },
+ { "abcdefgabcdefg", "cbd", 10, PR_TRUE, 1 },
+ { "abcdefgabcdefg", "dbc", 10, PR_TRUE, 1 },
+ { "abcdefgabcdefg", "ghi", 10, PR_TRUE, 6 },
+ { "abcdefgabcdefg", "AE", 10, PR_FALSE, 0 },
+ { "abcdefgabcdefg", "EI", 10, PR_FALSE, 0 },
+ { "abcdefgabcdefg", "IO", 10, PR_FALSE, 0 },
+ { "abcdefgabcdefg", "BCD", 10, PR_FALSE, 0 },
+ { "abcdefgabcdefg", "CBD", 10, PR_FALSE, 0 },
+ { "abcdefgabcdefg", "DBC", 10, PR_FALSE, 0 },
+ { "abcdefgabcdefg", "GHI", 10, PR_FALSE, 0 }
+ };
int i;
@@ -1923,55 +1967,55 @@ PRBool test_022(void)
PRBool ret;
PRUint32 off;
} array[] =
- {
- { (const char *)0, (const char *)0, 3, PR_FALSE, 0 },
- { (const char *)0, "abc", 3, PR_FALSE, 0 },
- { "abc", (const char *)0, 3, PR_FALSE, 0 },
- { "abcdefg", "", 3, PR_FALSE, 0 },
- { "", "aeiou", 3, PR_FALSE, 0 },
- { "abcdefg", "ae", 0, PR_FALSE, 0 },
- { "abcdefg", "ae", 1, PR_TRUE, 0 },
- { "abcdefg", "ae", 4, PR_TRUE, 0 },
- { "abcdefg", "ae", 5, PR_TRUE, 4 },
- { "abcdefg", "ae", 6, PR_TRUE, 4 },
- { "abcdefg", "ei", 4, PR_FALSE, 0 },
- { "abcdefg", "io", 10, PR_FALSE, 0 },
- { "abcdefg", "bcd", 2, PR_TRUE, 1 },
- { "abcdefg", "cbd", 2, PR_TRUE, 1 },
- { "abcdefg", "dbc", 2, PR_TRUE, 1 },
- { "abcdefg", "bcd", 3, PR_TRUE, 2 },
- { "abcdefg", "cbd", 3, PR_TRUE, 2 },
- { "abcdefg", "dbc", 3, PR_TRUE, 2 },
- { "abcdefg", "bcd", 5, PR_TRUE, 3 },
- { "abcdefg", "cbd", 5, PR_TRUE, 3 },
- { "abcdefg", "dbc", 5, PR_TRUE, 3 },
- { "abcdefg", "bcd", 15, PR_TRUE, 3 },
- { "abcdefg", "cbd", 15, PR_TRUE, 3 },
- { "abcdefg", "dbc", 15, PR_TRUE, 3 },
- { "abcdefg", "ghi", 6, PR_FALSE, 0 },
- { "abcdefg", "ghi", 7, PR_TRUE, 6 },
- { "abcdefg", "AE", 9, PR_FALSE, 0 },
- { "abcdefg", "EI", 9, PR_FALSE, 0 },
- { "abcdefg", "IO", 9, PR_FALSE, 0 },
- { "abcdefg", "BCD", 9, PR_FALSE, 0 },
- { "abcdefg", "CBD", 9, PR_FALSE, 0 },
- { "abcdefg", "DBC", 9, PR_FALSE, 0 },
- { "abcdefg", "GHI", 9, PR_FALSE, 0 },
- { "abcdefgabcdefg", "ae", 10, PR_TRUE, 7 },
- { "abcdefgabcdefg", "ei", 10, PR_TRUE, 4 },
- { "abcdefgabcdefg", "io", 10, PR_FALSE, 0 },
- { "abcdefgabcdefg", "bcd", 10, PR_TRUE, 9 },
- { "abcdefgabcdefg", "cbd", 10, PR_TRUE, 9 },
- { "abcdefgabcdefg", "dbc", 10, PR_TRUE, 9 },
- { "abcdefgabcdefg", "ghi", 10, PR_TRUE, 6 },
- { "abcdefgabcdefg", "AE", 10, PR_FALSE, 0 },
- { "abcdefgabcdefg", "EI", 10, PR_FALSE, 0 },
- { "abcdefgabcdefg", "IO", 10, PR_FALSE, 0 },
- { "abcdefgabcdefg", "BCD", 10, PR_FALSE, 0 },
- { "abcdefgabcdefg", "CBD", 10, PR_FALSE, 0 },
- { "abcdefgabcdefg", "DBC", 10, PR_FALSE, 0 },
- { "abcdefgabcdefg", "GHI", 10, PR_FALSE, 0 }
- };
+ {
+ { (const char *)0, (const char *)0, 3, PR_FALSE, 0 },
+ { (const char *)0, "abc", 3, PR_FALSE, 0 },
+ { "abc", (const char *)0, 3, PR_FALSE, 0 },
+ { "abcdefg", "", 3, PR_FALSE, 0 },
+ { "", "aeiou", 3, PR_FALSE, 0 },
+ { "abcdefg", "ae", 0, PR_FALSE, 0 },
+ { "abcdefg", "ae", 1, PR_TRUE, 0 },
+ { "abcdefg", "ae", 4, PR_TRUE, 0 },
+ { "abcdefg", "ae", 5, PR_TRUE, 4 },
+ { "abcdefg", "ae", 6, PR_TRUE, 4 },
+ { "abcdefg", "ei", 4, PR_FALSE, 0 },
+ { "abcdefg", "io", 10, PR_FALSE, 0 },
+ { "abcdefg", "bcd", 2, PR_TRUE, 1 },
+ { "abcdefg", "cbd", 2, PR_TRUE, 1 },
+ { "abcdefg", "dbc", 2, PR_TRUE, 1 },
+ { "abcdefg", "bcd", 3, PR_TRUE, 2 },
+ { "abcdefg", "cbd", 3, PR_TRUE, 2 },
+ { "abcdefg", "dbc", 3, PR_TRUE, 2 },
+ { "abcdefg", "bcd", 5, PR_TRUE, 3 },
+ { "abcdefg", "cbd", 5, PR_TRUE, 3 },
+ { "abcdefg", "dbc", 5, PR_TRUE, 3 },
+ { "abcdefg", "bcd", 15, PR_TRUE, 3 },
+ { "abcdefg", "cbd", 15, PR_TRUE, 3 },
+ { "abcdefg", "dbc", 15, PR_TRUE, 3 },
+ { "abcdefg", "ghi", 6, PR_FALSE, 0 },
+ { "abcdefg", "ghi", 7, PR_TRUE, 6 },
+ { "abcdefg", "AE", 9, PR_FALSE, 0 },
+ { "abcdefg", "EI", 9, PR_FALSE, 0 },
+ { "abcdefg", "IO", 9, PR_FALSE, 0 },
+ { "abcdefg", "BCD", 9, PR_FALSE, 0 },
+ { "abcdefg", "CBD", 9, PR_FALSE, 0 },
+ { "abcdefg", "DBC", 9, PR_FALSE, 0 },
+ { "abcdefg", "GHI", 9, PR_FALSE, 0 },
+ { "abcdefgabcdefg", "ae", 10, PR_TRUE, 7 },
+ { "abcdefgabcdefg", "ei", 10, PR_TRUE, 4 },
+ { "abcdefgabcdefg", "io", 10, PR_FALSE, 0 },
+ { "abcdefgabcdefg", "bcd", 10, PR_TRUE, 9 },
+ { "abcdefgabcdefg", "cbd", 10, PR_TRUE, 9 },
+ { "abcdefgabcdefg", "dbc", 10, PR_TRUE, 9 },
+ { "abcdefgabcdefg", "ghi", 10, PR_TRUE, 6 },
+ { "abcdefgabcdefg", "AE", 10, PR_FALSE, 0 },
+ { "abcdefgabcdefg", "EI", 10, PR_FALSE, 0 },
+ { "abcdefgabcdefg", "IO", 10, PR_FALSE, 0 },
+ { "abcdefgabcdefg", "BCD", 10, PR_FALSE, 0 },
+ { "abcdefgabcdefg", "CBD", 10, PR_FALSE, 0 },
+ { "abcdefgabcdefg", "DBC", 10, PR_FALSE, 0 },
+ { "abcdefgabcdefg", "GHI", 10, PR_FALSE, 0 }
+ };
int i;
@@ -2028,58 +2072,58 @@ PRBool test_023(void)
PRBool ret;
PRUint32 off;
} array[] =
- {
- { (const char *)0, (const char *)0, PR_FALSE, 0 },
- { (const char *)0, "blah", PR_FALSE, 0 },
- { "blah-de-blah", (const char *)0, PR_FALSE, 0 },
- { "blah-de-blah", "blah", PR_TRUE, 0 },
- { "", "blah", PR_FALSE, 0 },
- { "blah-de-blah", "", PR_FALSE, 0 },
- { "abcdefg", "a", PR_TRUE, 0 },
- { "abcdefg", "c", PR_TRUE, 2 },
- { "abcdefg", "e", PR_TRUE, 4 },
- { "abcdefg", "g", PR_TRUE, 6 },
- { "abcdefg", "i", PR_FALSE, 0 },
- { "abcdefg", "ab", PR_TRUE, 0 },
- { "abcdefg", "cd", PR_TRUE, 2 },
- { "abcdefg", "ef", PR_TRUE, 4 },
- { "abcdefg", "gh", PR_FALSE, 0 },
- { "abcdabc", "bc", PR_TRUE, 1 },
- { "abcdefg", "abcdefg", PR_TRUE, 0 },
- { "abcdefgabcdefg", "a", PR_TRUE, 0 },
- { "abcdefgabcdefg", "c", PR_TRUE, 2 },
- { "abcdefgabcdefg", "e", PR_TRUE, 4 },
- { "abcdefgabcdefg", "g", PR_TRUE, 6 },
- { "abcdefgabcdefg", "i", PR_FALSE, 0 },
- { "abcdefgabcdefg", "ab", PR_TRUE, 0 },
- { "abcdefgabcdefg", "cd", PR_TRUE, 2 },
- { "abcdefgabcdefg", "ef", PR_TRUE, 4 },
- { "abcdefgabcdefg", "gh", PR_FALSE, 0 },
- { "abcdabcabcdabc", "bc", PR_TRUE, 1 },
- { "abcdefgabcdefg", "abcdefg", PR_TRUE, 0 },
- { "ABCDEFG", "a", PR_FALSE, 0 },
- { "ABCDEFG", "c", PR_FALSE, 0 },
- { "ABCDEFG", "e", PR_FALSE, 0 },
- { "ABCDEFG", "g", PR_FALSE, 0 },
- { "ABCDEFG", "i", PR_FALSE, 0 },
- { "ABCDEFG", "ab", PR_FALSE, 0 },
- { "ABCDEFG", "cd", PR_FALSE, 0 },
- { "ABCDEFG", "ef", PR_FALSE, 0 },
- { "ABCDEFG", "gh", PR_FALSE, 0 },
- { "ABCDABC", "bc", PR_FALSE, 0 },
- { "ABCDEFG", "abcdefg", PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "a", PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "c", PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "e", PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "g", PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "ab", PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "cd", PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "ef", PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 },
- { "ABCDABCABCDABC", "bc", PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "abcdefg", PR_FALSE, 0 }
- };
+ {
+ { (const char *)0, (const char *)0, PR_FALSE, 0 },
+ { (const char *)0, "blah", PR_FALSE, 0 },
+ { "blah-de-blah", (const char *)0, PR_FALSE, 0 },
+ { "blah-de-blah", "blah", PR_TRUE, 0 },
+ { "", "blah", PR_FALSE, 0 },
+ { "blah-de-blah", "", PR_FALSE, 0 },
+ { "abcdefg", "a", PR_TRUE, 0 },
+ { "abcdefg", "c", PR_TRUE, 2 },
+ { "abcdefg", "e", PR_TRUE, 4 },
+ { "abcdefg", "g", PR_TRUE, 6 },
+ { "abcdefg", "i", PR_FALSE, 0 },
+ { "abcdefg", "ab", PR_TRUE, 0 },
+ { "abcdefg", "cd", PR_TRUE, 2 },
+ { "abcdefg", "ef", PR_TRUE, 4 },
+ { "abcdefg", "gh", PR_FALSE, 0 },
+ { "abcdabc", "bc", PR_TRUE, 1 },
+ { "abcdefg", "abcdefg", PR_TRUE, 0 },
+ { "abcdefgabcdefg", "a", PR_TRUE, 0 },
+ { "abcdefgabcdefg", "c", PR_TRUE, 2 },
+ { "abcdefgabcdefg", "e", PR_TRUE, 4 },
+ { "abcdefgabcdefg", "g", PR_TRUE, 6 },
+ { "abcdefgabcdefg", "i", PR_FALSE, 0 },
+ { "abcdefgabcdefg", "ab", PR_TRUE, 0 },
+ { "abcdefgabcdefg", "cd", PR_TRUE, 2 },
+ { "abcdefgabcdefg", "ef", PR_TRUE, 4 },
+ { "abcdefgabcdefg", "gh", PR_FALSE, 0 },
+ { "abcdabcabcdabc", "bc", PR_TRUE, 1 },
+ { "abcdefgabcdefg", "abcdefg", PR_TRUE, 0 },
+ { "ABCDEFG", "a", PR_FALSE, 0 },
+ { "ABCDEFG", "c", PR_FALSE, 0 },
+ { "ABCDEFG", "e", PR_FALSE, 0 },
+ { "ABCDEFG", "g", PR_FALSE, 0 },
+ { "ABCDEFG", "i", PR_FALSE, 0 },
+ { "ABCDEFG", "ab", PR_FALSE, 0 },
+ { "ABCDEFG", "cd", PR_FALSE, 0 },
+ { "ABCDEFG", "ef", PR_FALSE, 0 },
+ { "ABCDEFG", "gh", PR_FALSE, 0 },
+ { "ABCDABC", "bc", PR_FALSE, 0 },
+ { "ABCDEFG", "abcdefg", PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "a", PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "c", PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "e", PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "g", PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "ab", PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "cd", PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "ef", PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 },
+ { "ABCDABCABCDABC", "bc", PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "abcdefg", PR_FALSE, 0 }
+ };
int i;
@@ -2136,58 +2180,58 @@ PRBool test_024(void)
PRBool ret;
PRUint32 off;
} array[] =
- {
- { (const char *)0, (const char *)0, PR_FALSE, 0 },
- { (const char *)0, "blah", PR_FALSE, 0 },
- { "blah-de-blah", (const char *)0, PR_FALSE, 0 },
- { "blah-de-blah", "blah", PR_TRUE, 8 },
- { "", "blah", PR_FALSE, 0 },
- { "blah-de-blah", "", PR_FALSE, 0 },
- { "abcdefg", "a", PR_TRUE, 0 },
- { "abcdefg", "c", PR_TRUE, 2 },
- { "abcdefg", "e", PR_TRUE, 4 },
- { "abcdefg", "g", PR_TRUE, 6 },
- { "abcdefg", "i", PR_FALSE, 0 },
- { "abcdefg", "ab", PR_TRUE, 0 },
- { "abcdefg", "cd", PR_TRUE, 2 },
- { "abcdefg", "ef", PR_TRUE, 4 },
- { "abcdefg", "gh", PR_FALSE, 0 },
- { "abcdabc", "bc", PR_TRUE, 5 },
- { "abcdefg", "abcdefg", PR_TRUE, 0 },
- { "abcdefgabcdefg", "a", PR_TRUE, 7 },
- { "abcdefgabcdefg", "c", PR_TRUE, 9 },
- { "abcdefgabcdefg", "e", PR_TRUE, 11 },
- { "abcdefgabcdefg", "g", PR_TRUE, 13 },
- { "abcdefgabcdefg", "i", PR_FALSE, 0 },
- { "abcdefgabcdefg", "ab", PR_TRUE, 7 },
- { "abcdefgabcdefg", "cd", PR_TRUE, 9 },
- { "abcdefgabcdefg", "ef", PR_TRUE, 11 },
- { "abcdefgabcdefg", "gh", PR_FALSE, 0 },
- { "abcdabcabcdabc", "bc", PR_TRUE, 12 },
- { "abcdefgabcdefg", "abcdefg", PR_TRUE, 7 },
- { "ABCDEFG", "a", PR_FALSE, 0 },
- { "ABCDEFG", "c", PR_FALSE, 0 },
- { "ABCDEFG", "e", PR_FALSE, 0 },
- { "ABCDEFG", "g", PR_FALSE, 0 },
- { "ABCDEFG", "i", PR_FALSE, 0 },
- { "ABCDEFG", "ab", PR_FALSE, 0 },
- { "ABCDEFG", "cd", PR_FALSE, 0 },
- { "ABCDEFG", "ef", PR_FALSE, 0 },
- { "ABCDEFG", "gh", PR_FALSE, 0 },
- { "ABCDABC", "bc", PR_FALSE, 0 },
- { "ABCDEFG", "abcdefg", PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "a", PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "c", PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "e", PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "g", PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "ab", PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "cd", PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "ef", PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 },
- { "ABCDABCABCDABC", "bc", PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "abcdefg", PR_FALSE, 0 }
- };
+ {
+ { (const char *)0, (const char *)0, PR_FALSE, 0 },
+ { (const char *)0, "blah", PR_FALSE, 0 },
+ { "blah-de-blah", (const char *)0, PR_FALSE, 0 },
+ { "blah-de-blah", "blah", PR_TRUE, 8 },
+ { "", "blah", PR_FALSE, 0 },
+ { "blah-de-blah", "", PR_FALSE, 0 },
+ { "abcdefg", "a", PR_TRUE, 0 },
+ { "abcdefg", "c", PR_TRUE, 2 },
+ { "abcdefg", "e", PR_TRUE, 4 },
+ { "abcdefg", "g", PR_TRUE, 6 },
+ { "abcdefg", "i", PR_FALSE, 0 },
+ { "abcdefg", "ab", PR_TRUE, 0 },
+ { "abcdefg", "cd", PR_TRUE, 2 },
+ { "abcdefg", "ef", PR_TRUE, 4 },
+ { "abcdefg", "gh", PR_FALSE, 0 },
+ { "abcdabc", "bc", PR_TRUE, 5 },
+ { "abcdefg", "abcdefg", PR_TRUE, 0 },
+ { "abcdefgabcdefg", "a", PR_TRUE, 7 },
+ { "abcdefgabcdefg", "c", PR_TRUE, 9 },
+ { "abcdefgabcdefg", "e", PR_TRUE, 11 },
+ { "abcdefgabcdefg", "g", PR_TRUE, 13 },
+ { "abcdefgabcdefg", "i", PR_FALSE, 0 },
+ { "abcdefgabcdefg", "ab", PR_TRUE, 7 },
+ { "abcdefgabcdefg", "cd", PR_TRUE, 9 },
+ { "abcdefgabcdefg", "ef", PR_TRUE, 11 },
+ { "abcdefgabcdefg", "gh", PR_FALSE, 0 },
+ { "abcdabcabcdabc", "bc", PR_TRUE, 12 },
+ { "abcdefgabcdefg", "abcdefg", PR_TRUE, 7 },
+ { "ABCDEFG", "a", PR_FALSE, 0 },
+ { "ABCDEFG", "c", PR_FALSE, 0 },
+ { "ABCDEFG", "e", PR_FALSE, 0 },
+ { "ABCDEFG", "g", PR_FALSE, 0 },
+ { "ABCDEFG", "i", PR_FALSE, 0 },
+ { "ABCDEFG", "ab", PR_FALSE, 0 },
+ { "ABCDEFG", "cd", PR_FALSE, 0 },
+ { "ABCDEFG", "ef", PR_FALSE, 0 },
+ { "ABCDEFG", "gh", PR_FALSE, 0 },
+ { "ABCDABC", "bc", PR_FALSE, 0 },
+ { "ABCDEFG", "abcdefg", PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "a", PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "c", PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "e", PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "g", PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "ab", PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "cd", PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "ef", PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 },
+ { "ABCDABCABCDABC", "bc", PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "abcdefg", PR_FALSE, 0 }
+ };
int i;
@@ -2245,79 +2289,79 @@ PRBool test_025(void)
PRBool ret;
PRUint32 off;
} array[] =
- {
- { (const char *)0, (const char *)0, 12, PR_FALSE, 0 },
- { (const char *)0, "blah", 12, PR_FALSE, 0 },
- { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 },
- { "blah-de-blah", "blah", 0, PR_FALSE, 0 },
- { "blah-de-blah", "blah", 2, PR_FALSE, 0 },
- { "blah-de-blah", "blah", 3, PR_FALSE, 0 },
- { "blah-de-blah", "blah", 4, PR_TRUE, 0 },
- { "blah-de-blah", "blah", 5, PR_TRUE, 0 },
- { "blah-de-blah", "blah", 12, PR_TRUE, 0 },
- { "", "blah", 12, PR_FALSE, 0 },
- { "blah-de-blah", "", 12, PR_FALSE, 0 },
- { "abcdefg", "a", 5, PR_TRUE, 0 },
- { "abcdefg", "c", 5, PR_TRUE, 2 },
- { "abcdefg", "e", 5, PR_TRUE, 4 },
- { "abcdefg", "g", 5, PR_FALSE, 0 },
- { "abcdefg", "i", 5, PR_FALSE, 0 },
- { "abcdefg", "ab", 5, PR_TRUE, 0 },
- { "abcdefg", "cd", 5, PR_TRUE, 2 },
- { "abcdefg", "ef", 5, PR_FALSE, 0 },
- { "abcdefg", "gh", 5, PR_FALSE, 0 },
- { "abcdabc", "bc", 5, PR_TRUE, 1 },
- { "abcdabc", "bc", 6, PR_TRUE, 1 },
- { "abcdabc", "bc", 7, PR_TRUE, 1 },
- { "abcdefg", "abcdefg", 6, PR_FALSE, 0 },
- { "abcdefg", "abcdefg", 7, PR_TRUE, 0 },
- { "abcdefg", "abcdefg", 8, PR_TRUE, 0 },
- { "abcdefgabcdefg", "a", 12, PR_TRUE, 0 },
- { "abcdefgabcdefg", "c", 12, PR_TRUE, 2 },
- { "abcdefgabcdefg", "e", 12, PR_TRUE, 4 },
- { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 },
- { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 },
- { "abcdefgabcdefg", "ab", 12, PR_TRUE, 0 },
- { "abcdefgabcdefg", "cd", 12, PR_TRUE, 2 },
- { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 },
- { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 },
- { "abcdabcabcdabc", "bc", 5, PR_TRUE, 1 },
- { "abcdabcabcdabc", "bc", 6, PR_TRUE, 1 },
- { "abcdabcabcdabc", "bc", 7, PR_TRUE, 1 },
- { "abcdefgabcdefg", "abcdefg", 6, PR_FALSE, 0 },
- { "abcdefgabcdefg", "abcdefg", 7, PR_TRUE, 0 },
- { "abcdefgabcdefg", "abcdefg", 8, PR_TRUE, 0 },
- { "ABCDEFG", "a", 5, PR_FALSE, 0 },
- { "ABCDEFG", "c", 5, PR_FALSE, 0 },
- { "ABCDEFG", "e", 5, PR_FALSE, 0 },
- { "ABCDEFG", "g", 5, PR_FALSE, 0 },
- { "ABCDEFG", "i", 5, PR_FALSE, 0 },
- { "ABCDEFG", "ab", 5, PR_FALSE, 0 },
- { "ABCDEFG", "cd", 5, PR_FALSE, 0 },
- { "ABCDEFG", "ef", 5, PR_FALSE, 0 },
- { "ABCDEFG", "gh", 5, PR_FALSE, 0 },
- { "ABCDABC", "bc", 5, PR_FALSE, 0 },
- { "ABCDABC", "bc", 6, PR_FALSE, 0 },
- { "ABCDABC", "bc", 7, PR_FALSE, 0 },
- { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
- { "ABCDEFG", "abcdefg", 7, PR_FALSE, 0 },
- { "ABCDEFG", "abcdefg", 8, PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "a", 12, PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "c", 12, PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "e", 12, PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "g", 12, PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "ab", 12, PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "cd", 12, PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "ef", 12, PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 },
- { "ABCDABCABCDABC", "bc", 5, PR_FALSE, 0 },
- { "ABCDABCABCDABC", "bc", 6, PR_FALSE, 0 },
- { "ABCDABCABCDABC", "bc", 7, PR_FALSE, },
- { "ABCDEFGABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "abcdefg", 7, PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "abcdefg", 8, PR_FALSE, 0 }
- };
+ {
+ { (const char *)0, (const char *)0, 12, PR_FALSE, 0 },
+ { (const char *)0, "blah", 12, PR_FALSE, 0 },
+ { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 },
+ { "blah-de-blah", "blah", 0, PR_FALSE, 0 },
+ { "blah-de-blah", "blah", 2, PR_FALSE, 0 },
+ { "blah-de-blah", "blah", 3, PR_FALSE, 0 },
+ { "blah-de-blah", "blah", 4, PR_TRUE, 0 },
+ { "blah-de-blah", "blah", 5, PR_TRUE, 0 },
+ { "blah-de-blah", "blah", 12, PR_TRUE, 0 },
+ { "", "blah", 12, PR_FALSE, 0 },
+ { "blah-de-blah", "", 12, PR_FALSE, 0 },
+ { "abcdefg", "a", 5, PR_TRUE, 0 },
+ { "abcdefg", "c", 5, PR_TRUE, 2 },
+ { "abcdefg", "e", 5, PR_TRUE, 4 },
+ { "abcdefg", "g", 5, PR_FALSE, 0 },
+ { "abcdefg", "i", 5, PR_FALSE, 0 },
+ { "abcdefg", "ab", 5, PR_TRUE, 0 },
+ { "abcdefg", "cd", 5, PR_TRUE, 2 },
+ { "abcdefg", "ef", 5, PR_FALSE, 0 },
+ { "abcdefg", "gh", 5, PR_FALSE, 0 },
+ { "abcdabc", "bc", 5, PR_TRUE, 1 },
+ { "abcdabc", "bc", 6, PR_TRUE, 1 },
+ { "abcdabc", "bc", 7, PR_TRUE, 1 },
+ { "abcdefg", "abcdefg", 6, PR_FALSE, 0 },
+ { "abcdefg", "abcdefg", 7, PR_TRUE, 0 },
+ { "abcdefg", "abcdefg", 8, PR_TRUE, 0 },
+ { "abcdefgabcdefg", "a", 12, PR_TRUE, 0 },
+ { "abcdefgabcdefg", "c", 12, PR_TRUE, 2 },
+ { "abcdefgabcdefg", "e", 12, PR_TRUE, 4 },
+ { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 },
+ { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 },
+ { "abcdefgabcdefg", "ab", 12, PR_TRUE, 0 },
+ { "abcdefgabcdefg", "cd", 12, PR_TRUE, 2 },
+ { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 },
+ { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 },
+ { "abcdabcabcdabc", "bc", 5, PR_TRUE, 1 },
+ { "abcdabcabcdabc", "bc", 6, PR_TRUE, 1 },
+ { "abcdabcabcdabc", "bc", 7, PR_TRUE, 1 },
+ { "abcdefgabcdefg", "abcdefg", 6, PR_FALSE, 0 },
+ { "abcdefgabcdefg", "abcdefg", 7, PR_TRUE, 0 },
+ { "abcdefgabcdefg", "abcdefg", 8, PR_TRUE, 0 },
+ { "ABCDEFG", "a", 5, PR_FALSE, 0 },
+ { "ABCDEFG", "c", 5, PR_FALSE, 0 },
+ { "ABCDEFG", "e", 5, PR_FALSE, 0 },
+ { "ABCDEFG", "g", 5, PR_FALSE, 0 },
+ { "ABCDEFG", "i", 5, PR_FALSE, 0 },
+ { "ABCDEFG", "ab", 5, PR_FALSE, 0 },
+ { "ABCDEFG", "cd", 5, PR_FALSE, 0 },
+ { "ABCDEFG", "ef", 5, PR_FALSE, 0 },
+ { "ABCDEFG", "gh", 5, PR_FALSE, 0 },
+ { "ABCDABC", "bc", 5, PR_FALSE, 0 },
+ { "ABCDABC", "bc", 6, PR_FALSE, 0 },
+ { "ABCDABC", "bc", 7, PR_FALSE, 0 },
+ { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
+ { "ABCDEFG", "abcdefg", 7, PR_FALSE, 0 },
+ { "ABCDEFG", "abcdefg", 8, PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "a", 12, PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "c", 12, PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "e", 12, PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "g", 12, PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "ab", 12, PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "cd", 12, PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "ef", 12, PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 },
+ { "ABCDABCABCDABC", "bc", 5, PR_FALSE, 0 },
+ { "ABCDABCABCDABC", "bc", 6, PR_FALSE, 0 },
+ { "ABCDABCABCDABC", "bc", 7, PR_FALSE, },
+ { "ABCDEFGABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "abcdefg", 7, PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "abcdefg", 8, PR_FALSE, 0 }
+ };
int i;
@@ -2375,81 +2419,81 @@ PRBool test_026(void)
PRBool ret;
PRUint32 off;
} array[] =
- {
- { (const char *)0, (const char *)0, 12, PR_FALSE, 0 },
- { (const char *)0, "blah", 12, PR_FALSE, 0 },
- { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 },
- { "blah-de-blah", "blah", 0, PR_FALSE, 0 },
- { "blah-de-blah", "blah", 2, PR_FALSE, 0 },
- { "blah-de-blah", "blah", 3, PR_FALSE, 0 },
- { "blah-de-blah", "blah", 4, PR_TRUE, 0 },
- { "blah-de-blah", "blah", 5, PR_TRUE, 0 },
- { "blah-de-blah", "blah", 11, PR_TRUE, 0 },
- { "blah-de-blah", "blah", 12, PR_TRUE, 8 },
- { "blah-de-blah", "blah", 13, PR_TRUE, 8 },
- { "", "blah", 12, PR_FALSE, 0 },
- { "blah-de-blah", "", 12, PR_FALSE, 0 },
- { "abcdefg", "a", 5, PR_TRUE, 0 },
- { "abcdefg", "c", 5, PR_TRUE, 2 },
- { "abcdefg", "e", 5, PR_TRUE, 4 },
- { "abcdefg", "g", 5, PR_FALSE, 0 },
- { "abcdefg", "i", 5, PR_FALSE, 0 },
- { "abcdefg", "ab", 5, PR_TRUE, 0 },
- { "abcdefg", "cd", 5, PR_TRUE, 2 },
- { "abcdefg", "ef", 5, PR_FALSE, 0 },
- { "abcdefg", "gh", 5, PR_FALSE, 0 },
- { "abcdabc", "bc", 5, PR_TRUE, 1 },
- { "abcdabc", "bc", 6, PR_TRUE, 1 },
- { "abcdabc", "bc", 7, PR_TRUE, 5 },
- { "abcdefg", "abcdefg", 6, PR_FALSE, 0 },
- { "abcdefg", "abcdefg", 7, PR_TRUE, 0 },
- { "abcdefg", "abcdefg", 8, PR_TRUE, 0 },
- { "abcdefgabcdefg", "a", 12, PR_TRUE, 7 },
- { "abcdefgabcdefg", "c", 12, PR_TRUE, 9 },
- { "abcdefgabcdefg", "e", 12, PR_TRUE, 11 },
- { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 },
- { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 },
- { "abcdefgabcdefg", "ab", 12, PR_TRUE, 7 },
- { "abcdefgabcdefg", "cd", 12, PR_TRUE, 9 },
- { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 },
- { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 },
- { "abcdabcabcdabc", "bc", 12, PR_TRUE, 8 },
- { "abcdabcabcdabc", "bc", 13, PR_TRUE, 8 },
- { "abcdabcabcdabc", "bc", 14, PR_TRUE, 12 },
- { "abcdefgabcdefg", "abcdefg", 13, PR_TRUE, 0 },
- { "abcdefgabcdefg", "abcdefg", 14, PR_TRUE, 7 },
- { "abcdefgabcdefg", "abcdefg", 15, PR_TRUE, 7 },
- { "ABCDEFG", "a", 5, PR_FALSE, 0 },
- { "ABCDEFG", "c", 5, PR_FALSE, 0 },
- { "ABCDEFG", "e", 5, PR_FALSE, 0 },
- { "ABCDEFG", "g", 5, PR_FALSE, 0 },
- { "ABCDEFG", "i", 5, PR_FALSE, 0 },
- { "ABCDEFG", "ab", 5, PR_FALSE, 0 },
- { "ABCDEFG", "cd", 5, PR_FALSE, 0 },
- { "ABCDEFG", "ef", 5, PR_FALSE, 0 },
- { "ABCDEFG", "gh", 5, PR_FALSE, 0 },
- { "ABCDABC", "bc", 5, PR_FALSE, 0 },
- { "ABCDABC", "bc", 6, PR_FALSE, 0 },
- { "ABCDABC", "bc", 7, PR_FALSE, 0 },
- { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
- { "ABCDEFG", "abcdefg", 7, PR_FALSE, 0 },
- { "ABCDEFG", "abcdefg", 8, PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "a", 12, PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "c", 12, PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "e", 12, PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "g", 12, PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "ab", 12, PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "cd", 12, PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "ef", 12, PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 },
- { "ABCDABCABCDABC", "bc", 12, PR_FALSE, 0 },
- { "ABCDABCABCDABC", "bc", 13, PR_FALSE, 0 },
- { "ABCDABCABCDABC", "bc", 14, PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "abcdefg", 13, PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "abcdefg", 14, PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "abcdefg", 15, PR_FALSE, 0 }
- };
+ {
+ { (const char *)0, (const char *)0, 12, PR_FALSE, 0 },
+ { (const char *)0, "blah", 12, PR_FALSE, 0 },
+ { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 },
+ { "blah-de-blah", "blah", 0, PR_FALSE, 0 },
+ { "blah-de-blah", "blah", 2, PR_FALSE, 0 },
+ { "blah-de-blah", "blah", 3, PR_FALSE, 0 },
+ { "blah-de-blah", "blah", 4, PR_TRUE, 0 },
+ { "blah-de-blah", "blah", 5, PR_TRUE, 0 },
+ { "blah-de-blah", "blah", 11, PR_TRUE, 0 },
+ { "blah-de-blah", "blah", 12, PR_TRUE, 8 },
+ { "blah-de-blah", "blah", 13, PR_TRUE, 8 },
+ { "", "blah", 12, PR_FALSE, 0 },
+ { "blah-de-blah", "", 12, PR_FALSE, 0 },
+ { "abcdefg", "a", 5, PR_TRUE, 0 },
+ { "abcdefg", "c", 5, PR_TRUE, 2 },
+ { "abcdefg", "e", 5, PR_TRUE, 4 },
+ { "abcdefg", "g", 5, PR_FALSE, 0 },
+ { "abcdefg", "i", 5, PR_FALSE, 0 },
+ { "abcdefg", "ab", 5, PR_TRUE, 0 },
+ { "abcdefg", "cd", 5, PR_TRUE, 2 },
+ { "abcdefg", "ef", 5, PR_FALSE, 0 },
+ { "abcdefg", "gh", 5, PR_FALSE, 0 },
+ { "abcdabc", "bc", 5, PR_TRUE, 1 },
+ { "abcdabc", "bc", 6, PR_TRUE, 1 },
+ { "abcdabc", "bc", 7, PR_TRUE, 5 },
+ { "abcdefg", "abcdefg", 6, PR_FALSE, 0 },
+ { "abcdefg", "abcdefg", 7, PR_TRUE, 0 },
+ { "abcdefg", "abcdefg", 8, PR_TRUE, 0 },
+ { "abcdefgabcdefg", "a", 12, PR_TRUE, 7 },
+ { "abcdefgabcdefg", "c", 12, PR_TRUE, 9 },
+ { "abcdefgabcdefg", "e", 12, PR_TRUE, 11 },
+ { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 },
+ { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 },
+ { "abcdefgabcdefg", "ab", 12, PR_TRUE, 7 },
+ { "abcdefgabcdefg", "cd", 12, PR_TRUE, 9 },
+ { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 },
+ { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 },
+ { "abcdabcabcdabc", "bc", 12, PR_TRUE, 8 },
+ { "abcdabcabcdabc", "bc", 13, PR_TRUE, 8 },
+ { "abcdabcabcdabc", "bc", 14, PR_TRUE, 12 },
+ { "abcdefgabcdefg", "abcdefg", 13, PR_TRUE, 0 },
+ { "abcdefgabcdefg", "abcdefg", 14, PR_TRUE, 7 },
+ { "abcdefgabcdefg", "abcdefg", 15, PR_TRUE, 7 },
+ { "ABCDEFG", "a", 5, PR_FALSE, 0 },
+ { "ABCDEFG", "c", 5, PR_FALSE, 0 },
+ { "ABCDEFG", "e", 5, PR_FALSE, 0 },
+ { "ABCDEFG", "g", 5, PR_FALSE, 0 },
+ { "ABCDEFG", "i", 5, PR_FALSE, 0 },
+ { "ABCDEFG", "ab", 5, PR_FALSE, 0 },
+ { "ABCDEFG", "cd", 5, PR_FALSE, 0 },
+ { "ABCDEFG", "ef", 5, PR_FALSE, 0 },
+ { "ABCDEFG", "gh", 5, PR_FALSE, 0 },
+ { "ABCDABC", "bc", 5, PR_FALSE, 0 },
+ { "ABCDABC", "bc", 6, PR_FALSE, 0 },
+ { "ABCDABC", "bc", 7, PR_FALSE, 0 },
+ { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
+ { "ABCDEFG", "abcdefg", 7, PR_FALSE, 0 },
+ { "ABCDEFG", "abcdefg", 8, PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "a", 12, PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "c", 12, PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "e", 12, PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "g", 12, PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "ab", 12, PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "cd", 12, PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "ef", 12, PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 },
+ { "ABCDABCABCDABC", "bc", 12, PR_FALSE, 0 },
+ { "ABCDABCABCDABC", "bc", 13, PR_FALSE, 0 },
+ { "ABCDABCABCDABC", "bc", 14, PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "abcdefg", 13, PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "abcdefg", 14, PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "abcdefg", 15, PR_FALSE, 0 }
+ };
int i;
@@ -2506,58 +2550,58 @@ PRBool test_027(void)
PRBool ret;
PRUint32 off;
} array[] =
- {
- { (const char *)0, (const char *)0, PR_FALSE, 0 },
- { (const char *)0, "blah", PR_FALSE, 0 },
- { "blah-de-blah", (const char *)0, PR_FALSE, 0 },
- { "blah-de-blah", "blah", PR_TRUE, 0 },
- { "", "blah", PR_FALSE, 0 },
- { "blah-de-blah", "", PR_FALSE, 0 },
- { "abcdefg", "a", PR_TRUE, 0 },
- { "abcdefg", "c", PR_TRUE, 2 },
- { "abcdefg", "e", PR_TRUE, 4 },
- { "abcdefg", "g", PR_TRUE, 6 },
- { "abcdefg", "i", PR_FALSE, 0 },
- { "abcdefg", "ab", PR_TRUE, 0 },
- { "abcdefg", "cd", PR_TRUE, 2 },
- { "abcdefg", "ef", PR_TRUE, 4 },
- { "abcdefg", "gh", PR_FALSE, 0 },
- { "abcdabc", "bc", PR_TRUE, 1 },
- { "abcdefg", "abcdefg", PR_TRUE, 0 },
- { "abcdefgabcdefg", "a", PR_TRUE, 0 },
- { "abcdefgabcdefg", "c", PR_TRUE, 2 },
- { "abcdefgabcdefg", "e", PR_TRUE, 4 },
- { "abcdefgabcdefg", "g", PR_TRUE, 6 },
- { "abcdefgabcdefg", "i", PR_FALSE, 0 },
- { "abcdefgabcdefg", "ab", PR_TRUE, 0 },
- { "abcdefgabcdefg", "cd", PR_TRUE, 2 },
- { "abcdefgabcdefg", "ef", PR_TRUE, 4 },
- { "abcdefgabcdefg", "gh", PR_FALSE, 0 },
- { "abcdabcabcdabc", "bc", PR_TRUE, 1 },
- { "abcdefgabcdefg", "abcdefg", PR_TRUE, 0 },
- { "ABCDEFG", "a", PR_TRUE, 0 },
- { "ABCDEFG", "c", PR_TRUE, 2 },
- { "ABCDEFG", "e", PR_TRUE, 4 },
- { "ABCDEFG", "g", PR_TRUE, 6 },
- { "ABCDEFG", "i", PR_FALSE, 0 },
- { "ABCDEFG", "ab", PR_TRUE, 0 },
- { "ABCDEFG", "cd", PR_TRUE, 2 },
- { "ABCDEFG", "ef", PR_TRUE, 4 },
- { "ABCDEFG", "gh", PR_FALSE, 0 },
- { "ABCDABC", "bc", PR_TRUE, 1 },
- { "ABCDEFG", "abcdefg", PR_TRUE, 0 },
- { "ABCDEFGABCDEFG", "a", PR_TRUE, 0 },
- { "ABCDEFGABCDEFG", "c", PR_TRUE, 2 },
- { "ABCDEFGABCDEFG", "e", PR_TRUE, 4 },
- { "ABCDEFGABCDEFG", "g", PR_TRUE, 6 },
- { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "ab", PR_TRUE, 0 },
- { "ABCDEFGABCDEFG", "cd", PR_TRUE, 2 },
- { "ABCDEFGABCDEFG", "ef", PR_TRUE, 4 },
- { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 },
- { "ABCDABCABCDABC", "bc", PR_TRUE, 1 },
- { "ABCDEFGABCDEFG", "abcdefg", PR_TRUE, 0 }
- };
+ {
+ { (const char *)0, (const char *)0, PR_FALSE, 0 },
+ { (const char *)0, "blah", PR_FALSE, 0 },
+ { "blah-de-blah", (const char *)0, PR_FALSE, 0 },
+ { "blah-de-blah", "blah", PR_TRUE, 0 },
+ { "", "blah", PR_FALSE, 0 },
+ { "blah-de-blah", "", PR_FALSE, 0 },
+ { "abcdefg", "a", PR_TRUE, 0 },
+ { "abcdefg", "c", PR_TRUE, 2 },
+ { "abcdefg", "e", PR_TRUE, 4 },
+ { "abcdefg", "g", PR_TRUE, 6 },
+ { "abcdefg", "i", PR_FALSE, 0 },
+ { "abcdefg", "ab", PR_TRUE, 0 },
+ { "abcdefg", "cd", PR_TRUE, 2 },
+ { "abcdefg", "ef", PR_TRUE, 4 },
+ { "abcdefg", "gh", PR_FALSE, 0 },
+ { "abcdabc", "bc", PR_TRUE, 1 },
+ { "abcdefg", "abcdefg", PR_TRUE, 0 },
+ { "abcdefgabcdefg", "a", PR_TRUE, 0 },
+ { "abcdefgabcdefg", "c", PR_TRUE, 2 },
+ { "abcdefgabcdefg", "e", PR_TRUE, 4 },
+ { "abcdefgabcdefg", "g", PR_TRUE, 6 },
+ { "abcdefgabcdefg", "i", PR_FALSE, 0 },
+ { "abcdefgabcdefg", "ab", PR_TRUE, 0 },
+ { "abcdefgabcdefg", "cd", PR_TRUE, 2 },
+ { "abcdefgabcdefg", "ef", PR_TRUE, 4 },
+ { "abcdefgabcdefg", "gh", PR_FALSE, 0 },
+ { "abcdabcabcdabc", "bc", PR_TRUE, 1 },
+ { "abcdefgabcdefg", "abcdefg", PR_TRUE, 0 },
+ { "ABCDEFG", "a", PR_TRUE, 0 },
+ { "ABCDEFG", "c", PR_TRUE, 2 },
+ { "ABCDEFG", "e", PR_TRUE, 4 },
+ { "ABCDEFG", "g", PR_TRUE, 6 },
+ { "ABCDEFG", "i", PR_FALSE, 0 },
+ { "ABCDEFG", "ab", PR_TRUE, 0 },
+ { "ABCDEFG", "cd", PR_TRUE, 2 },
+ { "ABCDEFG", "ef", PR_TRUE, 4 },
+ { "ABCDEFG", "gh", PR_FALSE, 0 },
+ { "ABCDABC", "bc", PR_TRUE, 1 },
+ { "ABCDEFG", "abcdefg", PR_TRUE, 0 },
+ { "ABCDEFGABCDEFG", "a", PR_TRUE, 0 },
+ { "ABCDEFGABCDEFG", "c", PR_TRUE, 2 },
+ { "ABCDEFGABCDEFG", "e", PR_TRUE, 4 },
+ { "ABCDEFGABCDEFG", "g", PR_TRUE, 6 },
+ { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "ab", PR_TRUE, 0 },
+ { "ABCDEFGABCDEFG", "cd", PR_TRUE, 2 },
+ { "ABCDEFGABCDEFG", "ef", PR_TRUE, 4 },
+ { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 },
+ { "ABCDABCABCDABC", "bc", PR_TRUE, 1 },
+ { "ABCDEFGABCDEFG", "abcdefg", PR_TRUE, 0 }
+ };
int i;
@@ -2614,58 +2658,58 @@ PRBool test_028(void)
PRBool ret;
PRUint32 off;
} array[] =
- {
- { (const char *)0, (const char *)0, PR_FALSE, 0 },
- { (const char *)0, "blah", PR_FALSE, 0 },
- { "blah-de-blah", (const char *)0, PR_FALSE, 0 },
- { "blah-de-blah", "blah", PR_TRUE, 8 },
- { "", "blah", PR_FALSE, 0 },
- { "blah-de-blah", "", PR_FALSE, 0 },
- { "abcdefg", "a", PR_TRUE, 0 },
- { "abcdefg", "c", PR_TRUE, 2 },
- { "abcdefg", "e", PR_TRUE, 4 },
- { "abcdefg", "g", PR_TRUE, 6 },
- { "abcdefg", "i", PR_FALSE, 0 },
- { "abcdefg", "ab", PR_TRUE, 0 },
- { "abcdefg", "cd", PR_TRUE, 2 },
- { "abcdefg", "ef", PR_TRUE, 4 },
- { "abcdefg", "gh", PR_FALSE, 0 },
- { "abcdabc", "bc", PR_TRUE, 5 },
- { "abcdefg", "abcdefg", PR_TRUE, 0 },
- { "abcdefgabcdefg", "a", PR_TRUE, 7 },
- { "abcdefgabcdefg", "c", PR_TRUE, 9 },
- { "abcdefgabcdefg", "e", PR_TRUE, 11 },
- { "abcdefgabcdefg", "g", PR_TRUE, 13 },
- { "abcdefgabcdefg", "i", PR_FALSE, 0 },
- { "abcdefgabcdefg", "ab", PR_TRUE, 7 },
- { "abcdefgabcdefg", "cd", PR_TRUE, 9 },
- { "abcdefgabcdefg", "ef", PR_TRUE, 11 },
- { "abcdefgabcdefg", "gh", PR_FALSE, 0 },
- { "abcdabcabcdabc", "bc", PR_TRUE, 12 },
- { "abcdefgabcdefg", "abcdefg", PR_TRUE, 7 },
- { "ABCDEFG", "a", PR_TRUE, 0 },
- { "ABCDEFG", "c", PR_TRUE, 2 },
- { "ABCDEFG", "e", PR_TRUE, 4 },
- { "ABCDEFG", "g", PR_TRUE, 6 },
- { "ABCDEFG", "i", PR_FALSE, 0 },
- { "ABCDEFG", "ab", PR_TRUE, 0 },
- { "ABCDEFG", "cd", PR_TRUE, 2 },
- { "ABCDEFG", "ef", PR_TRUE, 4 },
- { "ABCDEFG", "gh", PR_FALSE, 0 },
- { "ABCDABC", "bc", PR_TRUE, 5 },
- { "ABCDEFG", "abcdefg", PR_TRUE, 0 },
- { "ABCDEFGABCDEFG", "a", PR_TRUE, 7 },
- { "ABCDEFGABCDEFG", "c", PR_TRUE, 9 },
- { "ABCDEFGABCDEFG", "e", PR_TRUE, 11 },
- { "ABCDEFGABCDEFG", "g", PR_TRUE, 13 },
- { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "ab", PR_TRUE, 7 },
- { "ABCDEFGABCDEFG", "cd", PR_TRUE, 9 },
- { "ABCDEFGABCDEFG", "ef", PR_TRUE, 11 },
- { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 },
- { "ABCDABCABCDABC", "bc", PR_TRUE, 12 },
- { "ABCDEFGABCDEFG", "abcdefg", PR_TRUE, 7 }
- };
+ {
+ { (const char *)0, (const char *)0, PR_FALSE, 0 },
+ { (const char *)0, "blah", PR_FALSE, 0 },
+ { "blah-de-blah", (const char *)0, PR_FALSE, 0 },
+ { "blah-de-blah", "blah", PR_TRUE, 8 },
+ { "", "blah", PR_FALSE, 0 },
+ { "blah-de-blah", "", PR_FALSE, 0 },
+ { "abcdefg", "a", PR_TRUE, 0 },
+ { "abcdefg", "c", PR_TRUE, 2 },
+ { "abcdefg", "e", PR_TRUE, 4 },
+ { "abcdefg", "g", PR_TRUE, 6 },
+ { "abcdefg", "i", PR_FALSE, 0 },
+ { "abcdefg", "ab", PR_TRUE, 0 },
+ { "abcdefg", "cd", PR_TRUE, 2 },
+ { "abcdefg", "ef", PR_TRUE, 4 },
+ { "abcdefg", "gh", PR_FALSE, 0 },
+ { "abcdabc", "bc", PR_TRUE, 5 },
+ { "abcdefg", "abcdefg", PR_TRUE, 0 },
+ { "abcdefgabcdefg", "a", PR_TRUE, 7 },
+ { "abcdefgabcdefg", "c", PR_TRUE, 9 },
+ { "abcdefgabcdefg", "e", PR_TRUE, 11 },
+ { "abcdefgabcdefg", "g", PR_TRUE, 13 },
+ { "abcdefgabcdefg", "i", PR_FALSE, 0 },
+ { "abcdefgabcdefg", "ab", PR_TRUE, 7 },
+ { "abcdefgabcdefg", "cd", PR_TRUE, 9 },
+ { "abcdefgabcdefg", "ef", PR_TRUE, 11 },
+ { "abcdefgabcdefg", "gh", PR_FALSE, 0 },
+ { "abcdabcabcdabc", "bc", PR_TRUE, 12 },
+ { "abcdefgabcdefg", "abcdefg", PR_TRUE, 7 },
+ { "ABCDEFG", "a", PR_TRUE, 0 },
+ { "ABCDEFG", "c", PR_TRUE, 2 },
+ { "ABCDEFG", "e", PR_TRUE, 4 },
+ { "ABCDEFG", "g", PR_TRUE, 6 },
+ { "ABCDEFG", "i", PR_FALSE, 0 },
+ { "ABCDEFG", "ab", PR_TRUE, 0 },
+ { "ABCDEFG", "cd", PR_TRUE, 2 },
+ { "ABCDEFG", "ef", PR_TRUE, 4 },
+ { "ABCDEFG", "gh", PR_FALSE, 0 },
+ { "ABCDABC", "bc", PR_TRUE, 5 },
+ { "ABCDEFG", "abcdefg", PR_TRUE, 0 },
+ { "ABCDEFGABCDEFG", "a", PR_TRUE, 7 },
+ { "ABCDEFGABCDEFG", "c", PR_TRUE, 9 },
+ { "ABCDEFGABCDEFG", "e", PR_TRUE, 11 },
+ { "ABCDEFGABCDEFG", "g", PR_TRUE, 13 },
+ { "ABCDEFGABCDEFG", "i", PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "ab", PR_TRUE, 7 },
+ { "ABCDEFGABCDEFG", "cd", PR_TRUE, 9 },
+ { "ABCDEFGABCDEFG", "ef", PR_TRUE, 11 },
+ { "ABCDEFGABCDEFG", "gh", PR_FALSE, 0 },
+ { "ABCDABCABCDABC", "bc", PR_TRUE, 12 },
+ { "ABCDEFGABCDEFG", "abcdefg", PR_TRUE, 7 }
+ };
int i;
@@ -2723,79 +2767,79 @@ PRBool test_029(void)
PRBool ret;
PRUint32 off;
} array[] =
- {
- { (const char *)0, (const char *)0, 12, PR_FALSE, 0 },
- { (const char *)0, "blah", 12, PR_FALSE, 0 },
- { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 },
- { "blah-de-blah", "blah", 0, PR_FALSE, 0 },
- { "blah-de-blah", "blah", 2, PR_FALSE, 0 },
- { "blah-de-blah", "blah", 3, PR_FALSE, 0 },
- { "blah-de-blah", "blah", 4, PR_TRUE, 0 },
- { "blah-de-blah", "blah", 5, PR_TRUE, 0 },
- { "blah-de-blah", "blah", 12, PR_TRUE, 0 },
- { "", "blah", 12, PR_FALSE, 0 },
- { "blah-de-blah", "", 12, PR_FALSE, 0 },
- { "abcdefg", "a", 5, PR_TRUE, 0 },
- { "abcdefg", "c", 5, PR_TRUE, 2 },
- { "abcdefg", "e", 5, PR_TRUE, 4 },
- { "abcdefg", "g", 5, PR_FALSE, 0 },
- { "abcdefg", "i", 5, PR_FALSE, 0 },
- { "abcdefg", "ab", 5, PR_TRUE, 0 },
- { "abcdefg", "cd", 5, PR_TRUE, 2 },
- { "abcdefg", "ef", 5, PR_FALSE, 0 },
- { "abcdefg", "gh", 5, PR_FALSE, 0 },
- { "abcdabc", "bc", 5, PR_TRUE, 1 },
- { "abcdabc", "bc", 6, PR_TRUE, 1 },
- { "abcdabc", "bc", 7, PR_TRUE, 1 },
- { "abcdefg", "abcdefg", 6, PR_FALSE, 0 },
- { "abcdefg", "abcdefg", 7, PR_TRUE, 0 },
- { "abcdefg", "abcdefg", 8, PR_TRUE, 0 },
- { "abcdefgabcdefg", "a", 12, PR_TRUE, 0 },
- { "abcdefgabcdefg", "c", 12, PR_TRUE, 2 },
- { "abcdefgabcdefg", "e", 12, PR_TRUE, 4 },
- { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 },
- { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 },
- { "abcdefgabcdefg", "ab", 12, PR_TRUE, 0 },
- { "abcdefgabcdefg", "cd", 12, PR_TRUE, 2 },
- { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 },
- { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 },
- { "abcdabcabcdabc", "bc", 5, PR_TRUE, 1 },
- { "abcdabcabcdabc", "bc", 6, PR_TRUE, 1 },
- { "abcdabcabcdabc", "bc", 7, PR_TRUE, 1 },
- { "abcdefgabcdefg", "abcdefg", 6, PR_FALSE, 0 },
- { "abcdefgabcdefg", "abcdefg", 7, PR_TRUE, 0 },
- { "abcdefgabcdefg", "abcdefg", 8, PR_TRUE, 0 },
- { "ABCDEFG", "a", 5, PR_TRUE, 0 },
- { "ABCDEFG", "c", 5, PR_TRUE, 2 },
- { "ABCDEFG", "e", 5, PR_TRUE, 4 },
- { "ABCDEFG", "g", 5, PR_FALSE, 0 },
- { "ABCDEFG", "i", 5, PR_FALSE, 0 },
- { "ABCDEFG", "ab", 5, PR_TRUE, 0 },
- { "ABCDEFG", "cd", 5, PR_TRUE, 2 },
- { "ABCDEFG", "ef", 5, PR_FALSE, 0 },
- { "ABCDEFG", "gh", 5, PR_FALSE, 0 },
- { "ABCDABC", "bc", 5, PR_TRUE, 1 },
- { "ABCDABC", "bc", 6, PR_TRUE, 1 },
- { "ABCDABC", "bc", 7, PR_TRUE, 1 },
- { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
- { "ABCDEFG", "abcdefg", 7, PR_TRUE, 0 },
- { "ABCDEFG", "abcdefg", 8, PR_TRUE, 0 },
- { "ABCDEFGABCDEFG", "a", 12, PR_TRUE, 0 },
- { "ABCDEFGABCDEFG", "c", 12, PR_TRUE, 2 },
- { "ABCDEFGABCDEFG", "e", 12, PR_TRUE, 4 },
- { "ABCDEFGABCDEFG", "g", 12, PR_TRUE, 6 },
- { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "ab", 12, PR_TRUE, 0 },
- { "ABCDEFGABCDEFG", "cd", 12, PR_TRUE, 2 },
- { "ABCDEFGABCDEFG", "ef", 12, PR_TRUE, 4 },
- { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 },
- { "ABCDABCABCDABC", "bc", 5, PR_TRUE, 1 },
- { "ABCDABCABCDABC", "bc", 6, PR_TRUE, 1 },
- { "ABCDABCABCDABC", "bc", 7, PR_TRUE, 1 },
- { "ABCDEFGABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "abcdefg", 7, PR_TRUE, 0 },
- { "ABCDEFGABCDEFG", "abcdefg", 8, PR_TRUE, 0 }
- };
+ {
+ { (const char *)0, (const char *)0, 12, PR_FALSE, 0 },
+ { (const char *)0, "blah", 12, PR_FALSE, 0 },
+ { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 },
+ { "blah-de-blah", "blah", 0, PR_FALSE, 0 },
+ { "blah-de-blah", "blah", 2, PR_FALSE, 0 },
+ { "blah-de-blah", "blah", 3, PR_FALSE, 0 },
+ { "blah-de-blah", "blah", 4, PR_TRUE, 0 },
+ { "blah-de-blah", "blah", 5, PR_TRUE, 0 },
+ { "blah-de-blah", "blah", 12, PR_TRUE, 0 },
+ { "", "blah", 12, PR_FALSE, 0 },
+ { "blah-de-blah", "", 12, PR_FALSE, 0 },
+ { "abcdefg", "a", 5, PR_TRUE, 0 },
+ { "abcdefg", "c", 5, PR_TRUE, 2 },
+ { "abcdefg", "e", 5, PR_TRUE, 4 },
+ { "abcdefg", "g", 5, PR_FALSE, 0 },
+ { "abcdefg", "i", 5, PR_FALSE, 0 },
+ { "abcdefg", "ab", 5, PR_TRUE, 0 },
+ { "abcdefg", "cd", 5, PR_TRUE, 2 },
+ { "abcdefg", "ef", 5, PR_FALSE, 0 },
+ { "abcdefg", "gh", 5, PR_FALSE, 0 },
+ { "abcdabc", "bc", 5, PR_TRUE, 1 },
+ { "abcdabc", "bc", 6, PR_TRUE, 1 },
+ { "abcdabc", "bc", 7, PR_TRUE, 1 },
+ { "abcdefg", "abcdefg", 6, PR_FALSE, 0 },
+ { "abcdefg", "abcdefg", 7, PR_TRUE, 0 },
+ { "abcdefg", "abcdefg", 8, PR_TRUE, 0 },
+ { "abcdefgabcdefg", "a", 12, PR_TRUE, 0 },
+ { "abcdefgabcdefg", "c", 12, PR_TRUE, 2 },
+ { "abcdefgabcdefg", "e", 12, PR_TRUE, 4 },
+ { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 },
+ { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 },
+ { "abcdefgabcdefg", "ab", 12, PR_TRUE, 0 },
+ { "abcdefgabcdefg", "cd", 12, PR_TRUE, 2 },
+ { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 },
+ { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 },
+ { "abcdabcabcdabc", "bc", 5, PR_TRUE, 1 },
+ { "abcdabcabcdabc", "bc", 6, PR_TRUE, 1 },
+ { "abcdabcabcdabc", "bc", 7, PR_TRUE, 1 },
+ { "abcdefgabcdefg", "abcdefg", 6, PR_FALSE, 0 },
+ { "abcdefgabcdefg", "abcdefg", 7, PR_TRUE, 0 },
+ { "abcdefgabcdefg", "abcdefg", 8, PR_TRUE, 0 },
+ { "ABCDEFG", "a", 5, PR_TRUE, 0 },
+ { "ABCDEFG", "c", 5, PR_TRUE, 2 },
+ { "ABCDEFG", "e", 5, PR_TRUE, 4 },
+ { "ABCDEFG", "g", 5, PR_FALSE, 0 },
+ { "ABCDEFG", "i", 5, PR_FALSE, 0 },
+ { "ABCDEFG", "ab", 5, PR_TRUE, 0 },
+ { "ABCDEFG", "cd", 5, PR_TRUE, 2 },
+ { "ABCDEFG", "ef", 5, PR_FALSE, 0 },
+ { "ABCDEFG", "gh", 5, PR_FALSE, 0 },
+ { "ABCDABC", "bc", 5, PR_TRUE, 1 },
+ { "ABCDABC", "bc", 6, PR_TRUE, 1 },
+ { "ABCDABC", "bc", 7, PR_TRUE, 1 },
+ { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
+ { "ABCDEFG", "abcdefg", 7, PR_TRUE, 0 },
+ { "ABCDEFG", "abcdefg", 8, PR_TRUE, 0 },
+ { "ABCDEFGABCDEFG", "a", 12, PR_TRUE, 0 },
+ { "ABCDEFGABCDEFG", "c", 12, PR_TRUE, 2 },
+ { "ABCDEFGABCDEFG", "e", 12, PR_TRUE, 4 },
+ { "ABCDEFGABCDEFG", "g", 12, PR_TRUE, 6 },
+ { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "ab", 12, PR_TRUE, 0 },
+ { "ABCDEFGABCDEFG", "cd", 12, PR_TRUE, 2 },
+ { "ABCDEFGABCDEFG", "ef", 12, PR_TRUE, 4 },
+ { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 },
+ { "ABCDABCABCDABC", "bc", 5, PR_TRUE, 1 },
+ { "ABCDABCABCDABC", "bc", 6, PR_TRUE, 1 },
+ { "ABCDABCABCDABC", "bc", 7, PR_TRUE, 1 },
+ { "ABCDEFGABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "abcdefg", 7, PR_TRUE, 0 },
+ { "ABCDEFGABCDEFG", "abcdefg", 8, PR_TRUE, 0 }
+ };
int i;
@@ -2853,81 +2897,81 @@ PRBool test_030(void)
PRBool ret;
PRUint32 off;
} array[] =
- {
- { (const char *)0, (const char *)0, 12, PR_FALSE, 0 },
- { (const char *)0, "blah", 12, PR_FALSE, 0 },
- { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 },
- { "blah-de-blah", "blah", 0, PR_FALSE, 0 },
- { "blah-de-blah", "blah", 2, PR_FALSE, 0 },
- { "blah-de-blah", "blah", 3, PR_FALSE, 0 },
- { "blah-de-blah", "blah", 4, PR_TRUE, 0 },
- { "blah-de-blah", "blah", 5, PR_TRUE, 0 },
- { "blah-de-blah", "blah", 11, PR_TRUE, 0 },
- { "blah-de-blah", "blah", 12, PR_TRUE, 8 },
- { "blah-de-blah", "blah", 13, PR_TRUE, 8 },
- { "", "blah", 12, PR_FALSE, 0 },
- { "blah-de-blah", "", 12, PR_FALSE, 0 },
- { "abcdefg", "a", 5, PR_TRUE, 0 },
- { "abcdefg", "c", 5, PR_TRUE, 2 },
- { "abcdefg", "e", 5, PR_TRUE, 4 },
- { "abcdefg", "g", 5, PR_FALSE, 0 },
- { "abcdefg", "i", 5, PR_FALSE, 0 },
- { "abcdefg", "ab", 5, PR_TRUE, 0 },
- { "abcdefg", "cd", 5, PR_TRUE, 2 },
- { "abcdefg", "ef", 5, PR_FALSE, 0 },
- { "abcdefg", "gh", 5, PR_FALSE, 0 },
- { "abcdabc", "bc", 5, PR_TRUE, 1 },
- { "abcdabc", "bc", 6, PR_TRUE, 1 },
- { "abcdabc", "bc", 7, PR_TRUE, 5 },
- { "abcdefg", "abcdefg", 6, PR_FALSE, 0 },
- { "abcdefg", "abcdefg", 7, PR_TRUE, 0 },
- { "abcdefg", "abcdefg", 8, PR_TRUE, 0 },
- { "abcdefgabcdefg", "a", 12, PR_TRUE, 7 },
- { "abcdefgabcdefg", "c", 12, PR_TRUE, 9 },
- { "abcdefgabcdefg", "e", 12, PR_TRUE, 11 },
- { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 },
- { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 },
- { "abcdefgabcdefg", "ab", 12, PR_TRUE, 7 },
- { "abcdefgabcdefg", "cd", 12, PR_TRUE, 9 },
- { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 },
- { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 },
- { "abcdabcabcdabc", "bc", 12, PR_TRUE, 8 },
- { "abcdabcabcdabc", "bc", 13, PR_TRUE, 8 },
- { "abcdabcabcdabc", "bc", 14, PR_TRUE, 12 },
- { "abcdefgabcdefg", "abcdefg", 13, PR_TRUE, 0 },
- { "abcdefgabcdefg", "abcdefg", 14, PR_TRUE, 7 },
- { "abcdefgabcdefg", "abcdefg", 15, PR_TRUE, 7 },
- { "ABCDEFG", "a", 5, PR_TRUE, 0 },
- { "ABCDEFG", "c", 5, PR_TRUE, 2 },
- { "ABCDEFG", "e", 5, PR_TRUE, 4 },
- { "ABCDEFG", "g", 5, PR_FALSE, 0 },
- { "ABCDEFG", "i", 5, PR_FALSE, 0 },
- { "ABCDEFG", "ab", 5, PR_TRUE, 0 },
- { "ABCDEFG", "cd", 5, PR_TRUE, 2 },
- { "ABCDEFG", "ef", 5, PR_FALSE, 0 },
- { "ABCDEFG", "gh", 5, PR_FALSE, 0 },
- { "ABCDABC", "bc", 5, PR_TRUE, 1 },
- { "ABCDABC", "bc", 6, PR_TRUE, 1 },
- { "ABCDABC", "bc", 7, PR_TRUE, 5 },
- { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
- { "ABCDEFG", "abcdefg", 7, PR_TRUE, 0 },
- { "ABCDEFG", "abcdefg", 8, PR_TRUE, 0 },
- { "ABCDEFGABCDEFG", "a", 12, PR_TRUE, 7 },
- { "ABCDEFGABCDEFG", "c", 12, PR_TRUE, 9 },
- { "ABCDEFGABCDEFG", "e", 12, PR_TRUE, 11 },
- { "ABCDEFGABCDEFG", "g", 12, PR_TRUE, 6 },
- { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 },
- { "ABCDEFGABCDEFG", "ab", 12, PR_TRUE, 7 },
- { "ABCDEFGABCDEFG", "cd", 12, PR_TRUE, 9 },
- { "ABCDEFGABCDEFG", "ef", 12, PR_TRUE, 4 },
- { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 },
- { "ABCDABCABCDABC", "bc", 12, PR_TRUE, 8 },
- { "ABCDABCABCDABC", "bc", 13, PR_TRUE, 8 },
- { "ABCDABCABCDABC", "bc", 14, PR_TRUE, 12 },
- { "ABCDEFGABCDEFG", "abcdefg", 13, PR_TRUE, 0 },
- { "ABCDEFGABCDEFG", "abcdefg", 14, PR_TRUE, 7 },
- { "ABCDEFGABCDEFG", "abcdefg", 15, PR_TRUE, 7 }
- };
+ {
+ { (const char *)0, (const char *)0, 12, PR_FALSE, 0 },
+ { (const char *)0, "blah", 12, PR_FALSE, 0 },
+ { "blah-de-blah", (const char *)0, 12, PR_FALSE, 0 },
+ { "blah-de-blah", "blah", 0, PR_FALSE, 0 },
+ { "blah-de-blah", "blah", 2, PR_FALSE, 0 },
+ { "blah-de-blah", "blah", 3, PR_FALSE, 0 },
+ { "blah-de-blah", "blah", 4, PR_TRUE, 0 },
+ { "blah-de-blah", "blah", 5, PR_TRUE, 0 },
+ { "blah-de-blah", "blah", 11, PR_TRUE, 0 },
+ { "blah-de-blah", "blah", 12, PR_TRUE, 8 },
+ { "blah-de-blah", "blah", 13, PR_TRUE, 8 },
+ { "", "blah", 12, PR_FALSE, 0 },
+ { "blah-de-blah", "", 12, PR_FALSE, 0 },
+ { "abcdefg", "a", 5, PR_TRUE, 0 },
+ { "abcdefg", "c", 5, PR_TRUE, 2 },
+ { "abcdefg", "e", 5, PR_TRUE, 4 },
+ { "abcdefg", "g", 5, PR_FALSE, 0 },
+ { "abcdefg", "i", 5, PR_FALSE, 0 },
+ { "abcdefg", "ab", 5, PR_TRUE, 0 },
+ { "abcdefg", "cd", 5, PR_TRUE, 2 },
+ { "abcdefg", "ef", 5, PR_FALSE, 0 },
+ { "abcdefg", "gh", 5, PR_FALSE, 0 },
+ { "abcdabc", "bc", 5, PR_TRUE, 1 },
+ { "abcdabc", "bc", 6, PR_TRUE, 1 },
+ { "abcdabc", "bc", 7, PR_TRUE, 5 },
+ { "abcdefg", "abcdefg", 6, PR_FALSE, 0 },
+ { "abcdefg", "abcdefg", 7, PR_TRUE, 0 },
+ { "abcdefg", "abcdefg", 8, PR_TRUE, 0 },
+ { "abcdefgabcdefg", "a", 12, PR_TRUE, 7 },
+ { "abcdefgabcdefg", "c", 12, PR_TRUE, 9 },
+ { "abcdefgabcdefg", "e", 12, PR_TRUE, 11 },
+ { "abcdefgabcdefg", "g", 12, PR_TRUE, 6 },
+ { "abcdefgabcdefg", "i", 12, PR_FALSE, 0 },
+ { "abcdefgabcdefg", "ab", 12, PR_TRUE, 7 },
+ { "abcdefgabcdefg", "cd", 12, PR_TRUE, 9 },
+ { "abcdefgabcdefg", "ef", 12, PR_TRUE, 4 },
+ { "abcdefgabcdefg", "gh", 12, PR_FALSE, 0 },
+ { "abcdabcabcdabc", "bc", 12, PR_TRUE, 8 },
+ { "abcdabcabcdabc", "bc", 13, PR_TRUE, 8 },
+ { "abcdabcabcdabc", "bc", 14, PR_TRUE, 12 },
+ { "abcdefgabcdefg", "abcdefg", 13, PR_TRUE, 0 },
+ { "abcdefgabcdefg", "abcdefg", 14, PR_TRUE, 7 },
+ { "abcdefgabcdefg", "abcdefg", 15, PR_TRUE, 7 },
+ { "ABCDEFG", "a", 5, PR_TRUE, 0 },
+ { "ABCDEFG", "c", 5, PR_TRUE, 2 },
+ { "ABCDEFG", "e", 5, PR_TRUE, 4 },
+ { "ABCDEFG", "g", 5, PR_FALSE, 0 },
+ { "ABCDEFG", "i", 5, PR_FALSE, 0 },
+ { "ABCDEFG", "ab", 5, PR_TRUE, 0 },
+ { "ABCDEFG", "cd", 5, PR_TRUE, 2 },
+ { "ABCDEFG", "ef", 5, PR_FALSE, 0 },
+ { "ABCDEFG", "gh", 5, PR_FALSE, 0 },
+ { "ABCDABC", "bc", 5, PR_TRUE, 1 },
+ { "ABCDABC", "bc", 6, PR_TRUE, 1 },
+ { "ABCDABC", "bc", 7, PR_TRUE, 5 },
+ { "ABCDEFG", "abcdefg", 6, PR_FALSE, 0 },
+ { "ABCDEFG", "abcdefg", 7, PR_TRUE, 0 },
+ { "ABCDEFG", "abcdefg", 8, PR_TRUE, 0 },
+ { "ABCDEFGABCDEFG", "a", 12, PR_TRUE, 7 },
+ { "ABCDEFGABCDEFG", "c", 12, PR_TRUE, 9 },
+ { "ABCDEFGABCDEFG", "e", 12, PR_TRUE, 11 },
+ { "ABCDEFGABCDEFG", "g", 12, PR_TRUE, 6 },
+ { "ABCDEFGABCDEFG", "i", 12, PR_FALSE, 0 },
+ { "ABCDEFGABCDEFG", "ab", 12, PR_TRUE, 7 },
+ { "ABCDEFGABCDEFG", "cd", 12, PR_TRUE, 9 },
+ { "ABCDEFGABCDEFG", "ef", 12, PR_TRUE, 4 },
+ { "ABCDEFGABCDEFG", "gh", 12, PR_FALSE, 0 },
+ { "ABCDABCABCDABC", "bc", 12, PR_TRUE, 8 },
+ { "ABCDABCABCDABC", "bc", 13, PR_TRUE, 8 },
+ { "ABCDABCABCDABC", "bc", 14, PR_TRUE, 12 },
+ { "ABCDEFGABCDEFG", "abcdefg", 13, PR_TRUE, 0 },
+ { "ABCDEFGABCDEFG", "abcdefg", 14, PR_TRUE, 7 },
+ { "ABCDEFGABCDEFG", "abcdefg", 15, PR_TRUE, 7 }
+ };
int i;
diff --git a/pr/include/gencfg.c b/pr/include/gencfg.c
index d4da2b7b..3a67e911 100644
--- a/pr/include/gencfg.c
+++ b/pr/include/gencfg.c
@@ -7,54 +7,54 @@
#if defined(__sun)
#ifndef SOLARIS
- error - SOLARIS is not defined
+error - SOLARIS is not defined
#endif
#endif
#if defined(__hpux)
#ifndef HPUX
- error - HPUX is not defined
+error - HPUX is not defined
#endif
#endif
#if defined(__alpha)
#if !(defined(_WIN32)) && !(defined(__linux)) && !(defined(__FreeBSD__))
- error - None of _WIN32, __linux, or __FreeBSD__ is defined
+error - None of _WIN32, __linux, or __FreeBSD__ is defined
#endif
#endif
#if defined(_IBMR2)
#ifndef AIX
- error - AIX is not defined
+error - AIX is not defined
#endif
#endif
#if defined(linux)
#ifndef LINUX
- error - LINUX is not defined
+error - LINUX is not defined
#endif
#endif
#if defined(bsdi)
#ifndef BSDI
- error - BSDI is not defined
+error - BSDI is not defined
#endif
#endif
#if defined(M_UNIX)
#ifndef SCO
- error - SCO is not defined
+error - SCO is not defined
#endif
#endif
#if !defined(M_UNIX) && defined(_USLC_)
#ifndef UNIXWARE
- error - UNIXWARE is not defined
+error - UNIXWARE is not defined
#endif
#endif
#if defined(__APPLE__)
#ifndef DARWIN
- error - DARWIN is not defined
+error - DARWIN is not defined
#endif
#endif
@@ -64,15 +64,15 @@
#ifdef XP_PC
#ifdef WIN32
-#define INT64 _PRInt64
+#define INT64 _PRInt64
#else
-#define INT64 long
+#define INT64 long
#endif
#else
#if defined(HPUX) || defined(SCO) || defined(UNIXWARE)
-#define INT64 long
+#define INT64 long
#else
-#define INT64 long long
+#define INT64 long long
#endif
#endif
@@ -95,7 +95,7 @@ struct align_PRInt64 {
struct align_fakelonglong {
char c;
struct {
- long hi, lo;
+ long hi, lo;
} a;
};
struct align_float {
@@ -123,18 +123,24 @@ static int Log2(int n)
{
int log2 = 0;
- if (n & (n-1))
- log2++;
- if (n >> 16)
- log2 += 16, n >>= 16;
- if (n >> 8)
- log2 += 8, n >>= 8;
- if (n >> 4)
- log2 += 4, n >>= 4;
- if (n >> 2)
- log2 += 2, n >>= 2;
- if (n >> 1)
- log2++;
+ if (n & (n-1)) {
+ log2++;
+ }
+ if (n >> 16) {
+ log2 += 16, n >>= 16;
+ }
+ if (n >> 8) {
+ log2 += 8, n >>= 8;
+ }
+ if (n >> 4) {
+ log2 += 4, n >>= 4;
+ }
+ if (n >> 2) {
+ log2 += 2, n >>= 2;
+ }
+ if (n >> 1) {
+ log2++;
+ }
return log2;
}
@@ -142,34 +148,34 @@ static int Log2(int n)
static void do64(void)
{
union {
- int i;
- char c[4];
+ int i;
+ char c[4];
} u;
u.i = 0x01020304;
if (u.c[0] == 0x01) {
- fprintf(stream, "#undef IS_LITTLE_ENDIAN\n");
- fprintf(stream, "#define IS_BIG_ENDIAN 1\n\n");
+ fprintf(stream, "#undef IS_LITTLE_ENDIAN\n");
+ fprintf(stream, "#define IS_BIG_ENDIAN 1\n\n");
} else {
- fprintf(stream, "#define IS_LITTLE_ENDIAN 1\n");
- fprintf(stream, "#undef IS_BIG_ENDIAN\n\n");
+ fprintf(stream, "#define IS_LITTLE_ENDIAN 1\n");
+ fprintf(stream, "#undef IS_BIG_ENDIAN\n\n");
}
}
static void do32(void)
{
union {
- long i;
- char c[4];
+ long i;
+ char c[4];
} u;
u.i = 0x01020304;
if (u.c[0] == 0x01) {
- fprintf(stream, "#undef IS_LITTLE_ENDIAN\n");
- fprintf(stream, "#define IS_BIG_ENDIAN 1\n\n");
+ fprintf(stream, "#undef IS_LITTLE_ENDIAN\n");
+ fprintf(stream, "#define IS_BIG_ENDIAN 1\n\n");
} else {
- fprintf(stream, "#define IS_LITTLE_ENDIAN 1\n");
- fprintf(stream, "#undef IS_BIG_ENDIAN\n\n");
+ fprintf(stream, "#define IS_LITTLE_ENDIAN 1\n");
+ fprintf(stream, "#undef IS_BIG_ENDIAN\n\n");
}
}
@@ -195,8 +201,8 @@ int main(int argc, char **argv)
return 1;
}
} else {
- stream = stdout;
- }
+ stream = stdout;
+ }
fprintf(stream, "#ifndef nspr_cpucfg___\n");
fprintf(stream, "#define nspr_cpucfg___\n\n");
@@ -204,9 +210,9 @@ int main(int argc, char **argv)
fprintf(stream, "/* AUTOMATICALLY GENERATED - DO NOT EDIT */\n\n");
if (sizeof(long) == 8) {
- do64();
+ do64();
} else {
- do32();
+ do32();
}
fprintf(stream, "#define PR_BYTES_PER_BYTE %d\n", sizeof(char));
fprintf(stream, "#define PR_BYTES_PER_SHORT %d\n", sizeof(short));
@@ -242,11 +248,11 @@ int main(int argc, char **argv)
fprintf(stream, "#define PR_ALIGN_OF_INT %d\n", ALIGN_OF(int));
fprintf(stream, "#define PR_ALIGN_OF_LONG %d\n", ALIGN_OF(long));
if (sizeof(INT64) < 8) {
- /* this machine doesn't actually support PRInt64's */
- fprintf(stream, "#define PR_ALIGN_OF_INT64 %d\n",
+ /* this machine doesn't actually support PRInt64's */
+ fprintf(stream, "#define PR_ALIGN_OF_INT64 %d\n",
ALIGN_OF(fakelonglong));
} else {
- fprintf(stream, "#define PR_ALIGN_OF_INT64 %d\n", ALIGN_OF(PRInt64));
+ fprintf(stream, "#define PR_ALIGN_OF_INT64 %d\n", ALIGN_OF(PRInt64));
}
fprintf(stream, "#define PR_ALIGN_OF_FLOAT %d\n", ALIGN_OF(float));
fprintf(stream, "#define PR_ALIGN_OF_DOUBLE %d\n", ALIGN_OF(double));
diff --git a/pr/include/md/_aix.h b/pr/include/md/_aix.h
index 3daf14fa..c2794d33 100644
--- a/pr/include/md/_aix.h
+++ b/pr/include/md/_aix.h
@@ -22,22 +22,22 @@
*/
#define PR_LINKER_ARCH "aix"
-#define _PR_SI_SYSNAME "AIX"
-#define _PR_SI_ARCHITECTURE "rs6000"
-#define PR_DLL_SUFFIX ".so"
+#define _PR_SI_SYSNAME "AIX"
+#define _PR_SI_ARCHITECTURE "rs6000"
+#define PR_DLL_SUFFIX ".so"
-#define _PR_VMBASE 0x30000000
-#define _PR_STACK_VMBASE 0x50000000
-#define _MD_DEFAULT_STACK_SIZE (2*65536L)
-#define _MD_MINIMUM_STACK_SIZE (2*65536L)
-#define _MD_MMAP_FLAGS MAP_PRIVATE
+#define _PR_VMBASE 0x30000000
+#define _PR_STACK_VMBASE 0x50000000
+#define _MD_DEFAULT_STACK_SIZE (2*65536L)
+#define _MD_MINIMUM_STACK_SIZE (2*65536L)
+#define _MD_MMAP_FLAGS MAP_PRIVATE
#define NEED_TIME_R
#undef HAVE_STACK_GROWING_UP
-#undef HAVE_WEAK_IO_SYMBOLS
-#undef HAVE_WEAK_MALLOC_SYMBOLS
-#define HAVE_DLL
-#define USE_DLFCN
+#undef HAVE_WEAK_IO_SYMBOLS
+#undef HAVE_WEAK_MALLOC_SYMBOLS
+#define HAVE_DLL
+#define USE_DLFCN
#define _PR_HAVE_SOCKADDR_LEN
#define _PR_POLL_AVAILABLE
#define _PR_USE_POLL
@@ -85,13 +85,13 @@ extern PRIntervalTime _MD_AixIntervalPerSec(void);
#include <setjmp.h>
-#define _MD_GET_SP(_t) (_t)->md.jb[3]
-#define _MD_SET_THR_SP(_t, _sp) ((_t)->md.jb[3] = (int) (_sp - 2 * 64))
-#define PR_NUM_GCREGS _JBLEN
+#define _MD_GET_SP(_t) (_t)->md.jb[3]
+#define _MD_SET_THR_SP(_t, _sp) ((_t)->md.jb[3] = (int) (_sp - 2 * 64))
+#define PR_NUM_GCREGS _JBLEN
-#define CONTEXT(_th) ((_th)->md.jb)
-#define SAVE_CONTEXT(_th) _setjmp(CONTEXT(_th))
-#define GOTO_CONTEXT(_th) _longjmp(CONTEXT(_th), 1)
+#define CONTEXT(_th) ((_th)->md.jb)
+#define SAVE_CONTEXT(_th) _setjmp(CONTEXT(_th))
+#define GOTO_CONTEXT(_th) _longjmp(CONTEXT(_th), 1)
#ifdef PTHREADS_USER
#include "_nspr_pthread.h"
@@ -100,26 +100,26 @@ extern PRIntervalTime _MD_AixIntervalPerSec(void);
/*
** Initialize the thread context preparing it to execute _main.
*/
-#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
- PR_BEGIN_MACRO \
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
+ PR_BEGIN_MACRO \
*status = PR_TRUE; \
- if (setjmp(CONTEXT(_thread))) { \
- (*_main)(); \
- } \
- _MD_GET_SP(_thread) = (int) (_sp - 2 * 64); \
+ if (setjmp(CONTEXT(_thread))) { \
+ (*_main)(); \
+ } \
+ _MD_GET_SP(_thread) = (int) (_sp - 2 * 64); \
PR_END_MACRO
#define _MD_SWITCH_CONTEXT(_thread) \
if (!setjmp(CONTEXT(_thread))) { \
- (_thread)->md.errcode = errno; \
- _PR_Schedule(); \
+ (_thread)->md.errcode = errno; \
+ _PR_Schedule(); \
}
/*
** Restore a thread context, saved by _MD_SWITCH_CONTEXT
*/
#define _MD_RESTORE_CONTEXT(_thread) \
-{ \
+{ \
errno = (_thread)->md.errcode; \
_MD_SET_CURRENT_THREAD(_thread); \
longjmp(CONTEXT(_thread), 1); \
@@ -166,28 +166,28 @@ struct _MDCPU_Unix {
#ifndef _PR_USE_POLL
fd_set fd_read_set, fd_write_set, fd_exception_set;
PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
- fd_exception_cnt[_PR_MD_MAX_OSFD];
+ fd_exception_cnt[_PR_MD_MAX_OSFD];
#else
- struct pollfd *ioq_pollfds;
- int ioq_pollfds_size;
-#endif /* _PR_USE_POLL */
+ struct pollfd *ioq_pollfds;
+ int ioq_pollfds_size;
+#endif /* _PR_USE_POLL */
};
-#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
+#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
-#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
-#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
-#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
-#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
-#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
-#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
-#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
-#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
-#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
-#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
-#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
-
-#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
+#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
struct _MDCPU {
struct _MDCPU_Unix md_unix;
@@ -205,19 +205,19 @@ struct _MDCPU {
#define _MD_IOQ_LOCK()
#define _MD_IOQ_UNLOCK()
-#define _MD_EARLY_INIT _MD_EarlyInit
-#define _MD_FINAL_INIT _PR_UnixInit
-#define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
-#define _MD_INIT_THREAD _MD_InitializeThread
+#define _MD_EARLY_INIT _MD_EarlyInit
+#define _MD_FINAL_INIT _PR_UnixInit
+#define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
+#define _MD_INIT_THREAD _MD_InitializeThread
#define _MD_EXIT_THREAD(thread)
-#define _MD_SUSPEND_THREAD(thread)
-#define _MD_RESUME_THREAD(thread)
+#define _MD_SUSPEND_THREAD(thread)
+#define _MD_RESUME_THREAD(thread)
#define _MD_CLEAN_THREAD(_thread)
#endif /* PTHREADS_USER */
#ifdef AIX_RENAME_SELECT
-#define _MD_SELECT select
-#define _MD_POLL poll
+#define _MD_SELECT select
+#define _MD_POLL poll
#endif
extern void _MD_aix_map_sendfile_error(int err);
diff --git a/pr/include/md/_bsdi.h b/pr/include/md/_bsdi.h
index f5ab14a9..99655dc3 100644
--- a/pr/include/md/_bsdi.h
+++ b/pr/include/md/_bsdi.h
@@ -10,9 +10,9 @@
* Internal configuration macros
*/
-#include <sys/param.h> /* for _BSDI_VERSION */
+#include <sys/param.h> /* for _BSDI_VERSION */
-#define PR_LINKER_ARCH "bsdi"
+#define PR_LINKER_ARCH "bsdi"
#define _PR_SI_SYSNAME "BSDI"
#if defined(__i386__)
#define _PR_SI_ARCHITECTURE "x86"
@@ -21,10 +21,10 @@
#else
#error "Unknown CPU architecture"
#endif
-#define PR_DLL_SUFFIX ".so"
+#define PR_DLL_SUFFIX ".so"
-#define _PR_STACK_VMBASE 0x50000000
-#define _MD_DEFAULT_STACK_SIZE 65536L
+#define _PR_STACK_VMBASE 0x50000000
+#define _MD_DEFAULT_STACK_SIZE 65536L
#define _MD_MMAP_FLAGS MAP_PRIVATE
#define HAVE_BSD_FLOCK
@@ -56,32 +56,32 @@
#error "Unknown BSDI jmp_buf type"
#endif
-#define PR_NUM_GCREGS _JBLEN
-#define PR_CONTEXT_TYPE jmp_buf
+#define PR_NUM_GCREGS _JBLEN
+#define PR_CONTEXT_TYPE jmp_buf
#define CONTEXT(_th) ((_th)->md.context)
-#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
-{ \
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
+{ \
*status = PR_TRUE; \
- if (setjmp(CONTEXT(_thread))) { \
- _main(); \
- } \
+ if (setjmp(CONTEXT(_thread))) { \
+ _main(); \
+ } \
_MD_GET_SP(_thread) = (int) (_sp - 64); \
}
#define _MD_SWITCH_CONTEXT(_thread) \
if (!setjmp(CONTEXT(_thread))) { \
- (_thread)->md.errcode = errno; \
- _PR_Schedule(); \
+ (_thread)->md.errcode = errno; \
+ _PR_Schedule(); \
}
/*
** Restore a thread context, saved by _MD_SWITCH_CONTEXT
*/
#define _MD_RESTORE_CONTEXT(_thread) \
-{ \
- errno = (_thread)->md.errcode; \
+{ \
+ errno = (_thread)->md.errcode; \
_MD_SET_CURRENT_THREAD(_thread); \
longjmp(CONTEXT(_thread), 1); \
}
@@ -127,31 +127,31 @@ struct _MDCPU_Unix {
#ifndef _PR_USE_POLL
fd_set fd_read_set, fd_write_set, fd_exception_set;
PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
- fd_exception_cnt[_PR_MD_MAX_OSFD];
+ fd_exception_cnt[_PR_MD_MAX_OSFD];
#else
- struct pollfd *ioq_pollfds;
- int ioq_pollfds_size;
-#endif /* _PR_USE_POLL */
+ struct pollfd *ioq_pollfds;
+ int ioq_pollfds_size;
+#endif /* _PR_USE_POLL */
};
-#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
+#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
-#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
-#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
-#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
-#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
-#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
-#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
-#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
-#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
-#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
-#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
-#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
-
-#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
+#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
struct _MDCPU {
- struct _MDCPU_Unix md_unix;
+ struct _MDCPU_Unix md_unix;
};
#define _MD_INIT_LOCKS()
@@ -171,7 +171,7 @@ struct _MDCPU {
#endif /* ! _PR_PTHREADS */
#define _MD_EARLY_INIT _MD_EarlyInit
-#define _MD_FINAL_INIT _PR_UnixInit
+#define _MD_FINAL_INIT _PR_UnixInit
#include <sys/syscall.h>
#define _MD_SELECT(nfds,r,w,e,tv) syscall(SYS_select,nfds,r,w,e,tv)
diff --git a/pr/include/md/_darwin.h b/pr/include/md/_darwin.h
index fcfc1bbc..1d79d3d8 100644
--- a/pr/include/md/_darwin.h
+++ b/pr/include/md/_darwin.h
@@ -16,7 +16,7 @@
#include <TargetConditionals.h>
#endif
-#define PR_LINKER_ARCH "darwin"
+#define PR_LINKER_ARCH "darwin"
#define _PR_SI_SYSNAME "DARWIN"
#ifdef __i386__
#define _PR_SI_ARCHITECTURE "x86"
@@ -31,11 +31,11 @@
#else
#error "Unknown CPU architecture"
#endif
-#define PR_DLL_SUFFIX ".dylib"
+#define PR_DLL_SUFFIX ".dylib"
#define _PR_VMBASE 0x30000000
-#define _PR_STACK_VMBASE 0x50000000
-#define _MD_DEFAULT_STACK_SIZE 65536L
+#define _PR_STACK_VMBASE 0x50000000
+#define _MD_DEFAULT_STACK_SIZE 65536L
#define _MD_MMAP_FLAGS MAP_PRIVATE
#undef HAVE_STACK_GROWING_UP
@@ -146,11 +146,11 @@ static inline PRInt32 _MD_ATOMIC_SET(PRInt32 *val, PRInt32 newval)
#include <setjmp.h>
-#define PR_CONTEXT_TYPE jmp_buf
+#define PR_CONTEXT_TYPE jmp_buf
#define CONTEXT(_th) ((_th)->md.context)
#define _MD_GET_SP(_th) (((struct sigcontext *) (_th)->md.context)->sc_onstack)
-#define PR_NUM_GCREGS _JBLEN
+#define PR_NUM_GCREGS _JBLEN
/*
** Initialize a thread context to run "_main()" when started
@@ -166,8 +166,8 @@ static inline PRInt32 _MD_ATOMIC_SET(PRInt32 *val, PRInt32 newval)
#define _MD_SWITCH_CONTEXT(_thread) \
if (!setjmp(CONTEXT(_thread))) { \
- (_thread)->md.errcode = errno; \
- _PR_Schedule(); \
+ (_thread)->md.errcode = errno; \
+ _PR_Schedule(); \
}
/*
@@ -221,31 +221,31 @@ struct _MDCPU_Unix {
#ifndef _PR_USE_POLL
fd_set fd_read_set, fd_write_set, fd_exception_set;
PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
- fd_exception_cnt[_PR_MD_MAX_OSFD];
+ fd_exception_cnt[_PR_MD_MAX_OSFD];
#else
- struct pollfd *ioq_pollfds;
- int ioq_pollfds_size;
-#endif /* _PR_USE_POLL */
+ struct pollfd *ioq_pollfds;
+ int ioq_pollfds_size;
+#endif /* _PR_USE_POLL */
};
-#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
+#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
-#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
-#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
-#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
-#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
-#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
-#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
-#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
-#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
-#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
-#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
-#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
-
-#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
+#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
struct _MDCPU {
- struct _MDCPU_Unix md_unix;
+ struct _MDCPU_Unix md_unix;
};
#define _MD_INIT_LOCKS()
@@ -281,7 +281,7 @@ extern void _MD_YIELD(void);
#endif /* ! _PR_PTHREADS */
#define _MD_EARLY_INIT _MD_EarlyInit
-#define _MD_FINAL_INIT _PR_UnixInit
+#define _MD_FINAL_INIT _PR_UnixInit
#define _MD_INTERVAL_INIT _PR_Mach_IntervalInit
#define _MD_GET_INTERVAL _PR_Mach_GetInterval
#define _MD_INTERVAL_PER_SEC _PR_Mach_TicksPerSecond
diff --git a/pr/include/md/_freebsd.h b/pr/include/md/_freebsd.h
index 9a179bcb..118cb9f9 100644
--- a/pr/include/md/_freebsd.h
+++ b/pr/include/md/_freebsd.h
@@ -13,7 +13,7 @@
#endif
#include <sys/syscall.h>
-#define PR_LINKER_ARCH "freebsd"
+#define PR_LINKER_ARCH "freebsd"
#define _PR_SI_SYSNAME "FREEBSD"
#if defined(__i386__)
#define _PR_SI_ARCHITECTURE "x86"
@@ -47,8 +47,8 @@
#endif
#define _PR_VMBASE 0x30000000
-#define _PR_STACK_VMBASE 0x50000000
-#define _MD_DEFAULT_STACK_SIZE 65536L
+#define _PR_STACK_VMBASE 0x50000000
+#define _MD_DEFAULT_STACK_SIZE 65536L
#define _MD_MMAP_FLAGS MAP_PRIVATE
#undef HAVE_STACK_GROWING_UP
@@ -91,12 +91,12 @@
#ifndef _PR_PTHREADS
#include <setjmp.h>
-#define PR_CONTEXT_TYPE sigjmp_buf
+#define PR_CONTEXT_TYPE sigjmp_buf
#define CONTEXT(_th) ((_th)->md.context)
#define _MD_GET_SP(_th) (_th)->md.context[0]._sjb[2]
-#define PR_NUM_GCREGS _JBLEN
+#define PR_NUM_GCREGS _JBLEN
/*
** Initialize a thread context to run "_main()" when started
@@ -112,8 +112,8 @@
#define _MD_SWITCH_CONTEXT(_thread) \
if (!sigsetjmp(CONTEXT(_thread), 1)) { \
- (_thread)->md.errcode = errno; \
- _PR_Schedule(); \
+ (_thread)->md.errcode = errno; \
+ _PR_Schedule(); \
}
/*
@@ -167,31 +167,31 @@ struct _MDCPU_Unix {
#ifndef _PR_USE_POLL
fd_set fd_read_set, fd_write_set, fd_exception_set;
PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
- fd_exception_cnt[_PR_MD_MAX_OSFD];
+ fd_exception_cnt[_PR_MD_MAX_OSFD];
#else
- struct pollfd *ioq_pollfds;
- int ioq_pollfds_size;
-#endif /* _PR_USE_POLL */
+ struct pollfd *ioq_pollfds;
+ int ioq_pollfds_size;
+#endif /* _PR_USE_POLL */
};
-#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
+#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
-#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
-#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
-#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
-#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
-#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
-#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
-#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
-#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
-#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
-#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
-#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
-
-#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
+#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
struct _MDCPU {
- struct _MDCPU_Unix md_unix;
+ struct _MDCPU_Unix md_unix;
};
#define _MD_INIT_LOCKS()
@@ -229,7 +229,7 @@ extern void _MD_YIELD(void);
extern void _MD_EarlyInit(void);
#define _MD_EARLY_INIT _MD_EarlyInit
-#define _MD_FINAL_INIT _PR_UnixInit
+#define _MD_FINAL_INIT _PR_UnixInit
#define _PR_HAVE_CLOCK_MONOTONIC
/*
diff --git a/pr/include/md/_hpux.h b/pr/include/md/_hpux.h
index adb9264a..2d8017e9 100644
--- a/pr/include/md/_hpux.h
+++ b/pr/include/md/_hpux.h
@@ -40,9 +40,9 @@
#define NEED_TIME_R
#define HAVE_STACK_GROWING_UP
-#undef HAVE_WEAK_IO_SYMBOLS
-#undef HAVE_WEAK_MALLOC_SYMBOLS
-#define HAVE_DLL
+#undef HAVE_WEAK_IO_SYMBOLS
+#undef HAVE_WEAK_MALLOC_SYMBOLS
+#define HAVE_DLL
#ifdef IS_64
#define USE_DLFCN
#else
@@ -134,7 +134,7 @@ struct _md_sockaddr_in6 {
/* Caveat: This makes jmp_buf full of doubles. */
#define CONTEXT(_th) ((_th)->md.jb)
- /* Stack needs two frames (64 bytes) at the bottom */ \
+/* Stack needs two frames (64 bytes) at the bottom */ \
#define _MD_SET_THR_SP(_t, _sp) ((_MD_GET_SP(_t)) = (int) (_sp + 64 *2))
#define SAVE_CONTEXT(_th) _setjmp(CONTEXT(_th))
#define GOTO_CONTEXT(_th) _longjmp(CONTEXT(_th), 1)
@@ -206,28 +206,28 @@ struct _MDCPU_Unix {
#ifndef _PR_USE_POLL
fd_set fd_read_set, fd_write_set, fd_exception_set;
PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
- fd_exception_cnt[_PR_MD_MAX_OSFD];
+ fd_exception_cnt[_PR_MD_MAX_OSFD];
#else
- struct pollfd *ioq_pollfds;
- int ioq_pollfds_size;
-#endif /* _PR_USE_POLL */
+ struct pollfd *ioq_pollfds;
+ int ioq_pollfds_size;
+#endif /* _PR_USE_POLL */
};
-#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
+#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
-#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
-#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
-#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
-#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
-#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
-#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
-#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
-#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
-#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
-#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
-#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
-
-#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
+#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
struct _MDCPU {
struct _MDCPU_Unix md_unix;
@@ -249,17 +249,17 @@ struct _MDCPU {
#define _MD_RESUME_THREAD(thread) _MD_resume_thread
#define _MD_CLEAN_THREAD(_thread)
-#else /* PTHREADS_USER */
+#else /* PTHREADS_USER */
#include "_nspr_pthread.h"
-#endif /* PTHREADS_USER */
+#endif /* PTHREADS_USER */
#endif /* !defined(_PR_PTHREADS) */
#if !defined(PTHREADS_USER)
-#define _MD_EARLY_INIT _MD_EarlyInit
-#define _MD_FINAL_INIT _PR_UnixInit
+#define _MD_EARLY_INIT _MD_EarlyInit
+#define _MD_FINAL_INIT _PR_UnixInit
#endif
#if defined(HPUX_LW_TIMER)
diff --git a/pr/include/md/_linux.h b/pr/include/md/_linux.h
index 80822e7f..6b54d097 100644
--- a/pr/include/md/_linux.h
+++ b/pr/include/md/_linux.h
@@ -17,7 +17,7 @@
* Internal configuration macros
*/
-#define PR_LINKER_ARCH "linux"
+#define PR_LINKER_ARCH "linux"
#define _PR_SI_SYSNAME "LINUX"
#ifdef __powerpc64__
#define _PR_SI_ARCHITECTURE "ppc64"
@@ -66,18 +66,18 @@
#else
#error "Unknown CPU architecture"
#endif
-#define PR_DLL_SUFFIX ".so"
+#define PR_DLL_SUFFIX ".so"
#define _PR_VMBASE 0x30000000
-#define _PR_STACK_VMBASE 0x50000000
-#define _MD_DEFAULT_STACK_SIZE 65536L
+#define _PR_STACK_VMBASE 0x50000000
+#define _MD_DEFAULT_STACK_SIZE 65536L
#define _MD_MMAP_FLAGS MAP_PRIVATE
#if defined(__aarch64__) || defined(__mips__)
#define _MD_MINIMUM_STACK_SIZE 0x20000
#endif
-#undef HAVE_STACK_GROWING_UP
+#undef HAVE_STACK_GROWING_UP
/*
* Elf linux supports dl* functions
@@ -331,7 +331,7 @@ extern void _MD_CleanupBeforeExit(void);
#include <setjmp.h>
-#define PR_CONTEXT_TYPE sigjmp_buf
+#define PR_CONTEXT_TYPE sigjmp_buf
#define CONTEXT(_th) ((_th)->md.context)
@@ -556,8 +556,8 @@ extern void _MD_CleanupBeforeExit(void);
#define _MD_SWITCH_CONTEXT(_thread) \
if (!sigsetjmp(CONTEXT(_thread), 1)) { \
- (_thread)->md.errcode = errno; \
- _PR_Schedule(); \
+ (_thread)->md.errcode = errno; \
+ _PR_Schedule(); \
}
/*
@@ -618,24 +618,24 @@ struct _MDCPU_Unix {
#else
struct pollfd *ioq_pollfds;
int ioq_pollfds_size;
-#endif /* _PR_USE_POLL */
+#endif /* _PR_USE_POLL */
};
-#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
+#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
-#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
-#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
-#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
-#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
-#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
-#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
-#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
-#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
-#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
-#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
-#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
-
-#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
+#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
struct _MDCPU {
struct _MDCPU_Unix md_unix;
@@ -688,7 +688,7 @@ extern void _MD_EarlyInit(void);
#ifdef _PR_POLL_AVAILABLE
#include <sys/poll.h>
extern int __syscall_poll(struct pollfd *ufds, unsigned long int nfds,
- int timeout);
+ int timeout);
#define _MD_POLL __syscall_poll
#endif
diff --git a/pr/include/md/_netbsd.h b/pr/include/md/_netbsd.h
index 945d94ff..1ec0fe6e 100644
--- a/pr/include/md/_netbsd.h
+++ b/pr/include/md/_netbsd.h
@@ -9,7 +9,7 @@
#include <sys/syscall.h>
#include <sys/param.h> /* for __NetBSD_Version__ */
-#define PR_LINKER_ARCH "netbsd"
+#define PR_LINKER_ARCH "netbsd"
#define _PR_SI_SYSNAME "NetBSD"
#if defined(__i386__)
#define _PR_SI_ARCHITECTURE "x86"
@@ -33,14 +33,14 @@
#endif
#if defined(__ELF__)
-#define PR_DLL_SUFFIX ".so"
+#define PR_DLL_SUFFIX ".so"
#else
-#define PR_DLL_SUFFIX ".so.1.0"
+#define PR_DLL_SUFFIX ".so.1.0"
#endif
#define _PR_VMBASE 0x30000000
-#define _PR_STACK_VMBASE 0x50000000
-#define _MD_DEFAULT_STACK_SIZE 65536L
+#define _PR_STACK_VMBASE 0x50000000
+#define _MD_DEFAULT_STACK_SIZE 65536L
#define _MD_MMAP_FLAGS MAP_PRIVATE
#undef HAVE_STACK_GROWING_UP
@@ -67,7 +67,7 @@
#ifndef _PR_PTHREADS
#include <setjmp.h>
-#define PR_CONTEXT_TYPE sigjmp_buf
+#define PR_CONTEXT_TYPE sigjmp_buf
#define CONTEXT(_th) ((_th)->md.context)
@@ -91,7 +91,7 @@
#endif
#define _MD_GET_SP(_th) (_th)->md.context[JB_SP_INDEX]
-#define PR_NUM_GCREGS _JBLEN
+#define PR_NUM_GCREGS _JBLEN
/*
** Initialize a thread context to run "_main()" when started
@@ -162,28 +162,28 @@ struct _MDCPU_Unix {
#ifndef _PR_USE_POLL
fd_set fd_read_set, fd_write_set, fd_exception_set;
PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
- fd_exception_cnt[_PR_MD_MAX_OSFD];
+ fd_exception_cnt[_PR_MD_MAX_OSFD];
#else
- struct pollfd *ioq_pollfds;
- int ioq_pollfds_size;
-#endif /* _PR_USE_POLL */
+ struct pollfd *ioq_pollfds;
+ int ioq_pollfds_size;
+#endif /* _PR_USE_POLL */
};
-#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
+#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
-#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
-#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
-#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
-#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
-#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
-#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
-#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
-#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
-#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
-#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
-#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
-
-#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
+#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
struct _MDCPU {
struct _MDCPU_Unix md_unix;
@@ -210,7 +210,7 @@ struct _MDCPU {
extern void _MD_EarlyInit(void);
#define _MD_EARLY_INIT _MD_EarlyInit
-#define _MD_FINAL_INIT _PR_UnixInit
+#define _MD_FINAL_INIT _PR_UnixInit
#define _PR_HAVE_CLOCK_MONOTONIC
/*
diff --git a/pr/include/md/_nspr_pthread.h b/pr/include/md/_nspr_pthread.h
index 8ca38362..01796e77 100644
--- a/pr/include/md/_nspr_pthread.h
+++ b/pr/include/md/_nspr_pthread.h
@@ -18,72 +18,72 @@ extern pthread_key_t current_cpu_key;
extern pthread_key_t last_thread_key;
extern pthread_key_t intsoff_key;
-#define _MD_CURRENT_THREAD() \
- ((struct PRThread *) pthread_getspecific(current_thread_key))
-#define _MD_CURRENT_CPU() \
- ((struct _PRCPU *) pthread_getspecific(current_cpu_key))
-#define _MD_LAST_THREAD() \
- ((struct PRThread *) pthread_getspecific(last_thread_key))
+#define _MD_CURRENT_THREAD() \
+ ((struct PRThread *) pthread_getspecific(current_thread_key))
+#define _MD_CURRENT_CPU() \
+ ((struct _PRCPU *) pthread_getspecific(current_cpu_key))
+#define _MD_LAST_THREAD() \
+ ((struct PRThread *) pthread_getspecific(last_thread_key))
-#define _MD_SET_CURRENT_THREAD(newval) \
- pthread_setspecific(current_thread_key, (void *)newval)
+#define _MD_SET_CURRENT_THREAD(newval) \
+ pthread_setspecific(current_thread_key, (void *)newval)
-#define _MD_SET_CURRENT_CPU(newval) \
- pthread_setspecific(current_cpu_key, (void *)newval)
+#define _MD_SET_CURRENT_CPU(newval) \
+ pthread_setspecific(current_cpu_key, (void *)newval)
-#define _MD_SET_LAST_THREAD(newval) \
- pthread_setspecific(last_thread_key, (void *)newval)
+#define _MD_SET_LAST_THREAD(newval) \
+ pthread_setspecific(last_thread_key, (void *)newval)
#define _MD_SET_INTSOFF(_val)
-#define _MD_GET_INTSOFF() 1
+#define _MD_GET_INTSOFF() 1
/*
** Initialize the thread context preparing it to execute _main.
*/
-#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
- PR_BEGIN_MACRO \
- *status = PR_TRUE; \
- if (SAVE_CONTEXT(_thread)) { \
- (*_main)(); \
- } \
- _MD_SET_THR_SP(_thread, _sp); \
- _thread->no_sched = 0; \
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
+ PR_BEGIN_MACRO \
+ *status = PR_TRUE; \
+ if (SAVE_CONTEXT(_thread)) { \
+ (*_main)(); \
+ } \
+ _MD_SET_THR_SP(_thread, _sp); \
+ _thread->no_sched = 0; \
PR_END_MACRO
-#define _MD_SWITCH_CONTEXT(_thread) \
- PR_BEGIN_MACRO \
- PR_ASSERT(_thread->no_sched); \
- if (!SAVE_CONTEXT(_thread)) { \
- (_thread)->md.errcode = errno; \
- _MD_SET_LAST_THREAD(_thread); \
- _PR_Schedule(); \
- } else { \
- (_MD_LAST_THREAD())->no_sched = 0; \
- } \
+#define _MD_SWITCH_CONTEXT(_thread) \
+ PR_BEGIN_MACRO \
+ PR_ASSERT(_thread->no_sched); \
+ if (!SAVE_CONTEXT(_thread)) { \
+ (_thread)->md.errcode = errno; \
+ _MD_SET_LAST_THREAD(_thread); \
+ _PR_Schedule(); \
+ } else { \
+ (_MD_LAST_THREAD())->no_sched = 0; \
+ } \
PR_END_MACRO
/*
** Restore a thread context, saved by _MD_SWITCH_CONTEXT
*/
-#define _MD_RESTORE_CONTEXT(_thread) \
- PR_BEGIN_MACRO \
- errno = (_thread)->md.errcode; \
- _MD_SET_CURRENT_THREAD(_thread); \
- _thread->no_sched = 1; \
- GOTO_CONTEXT(_thread); \
+#define _MD_RESTORE_CONTEXT(_thread) \
+ PR_BEGIN_MACRO \
+ errno = (_thread)->md.errcode; \
+ _MD_SET_CURRENT_THREAD(_thread); \
+ _thread->no_sched = 1; \
+ GOTO_CONTEXT(_thread); \
PR_END_MACRO
/* Machine-dependent (MD) data structures */
struct _MDThread {
- jmp_buf jb;
- int id;
- int errcode;
- pthread_t pthread;
- pthread_mutex_t pthread_mutex;
- pthread_cond_t pthread_cond;
- int wait;
+ jmp_buf jb;
+ int id;
+ int errcode;
+ pthread_t pthread;
+ pthread_mutex_t pthread_mutex;
+ pthread_cond_t pthread_cond;
+ int wait;
};
struct _MDThreadStack {
@@ -91,7 +91,7 @@ struct _MDThreadStack {
};
struct _MDLock {
- pthread_mutex_t mutex;
+ pthread_mutex_t mutex;
};
struct _MDSemaphore {
@@ -99,7 +99,7 @@ struct _MDSemaphore {
};
struct _MDCVar {
- pthread_mutex_t mutex;
+ pthread_mutex_t mutex;
};
struct _MDSegment {
@@ -119,33 +119,33 @@ struct _MDCPU_Unix {
#ifndef _PR_USE_POLL
fd_set fd_read_set, fd_write_set, fd_exception_set;
PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
- fd_exception_cnt[_PR_MD_MAX_OSFD];
+ fd_exception_cnt[_PR_MD_MAX_OSFD];
#else
- struct pollfd *ioq_pollfds;
- int ioq_pollfds_size;
-#endif /* _PR_USE_POLL */
+ struct pollfd *ioq_pollfds;
+ int ioq_pollfds_size;
+#endif /* _PR_USE_POLL */
};
-#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
+#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
-#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
-#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
-#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
-#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
-#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
-#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
-#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
-#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
-#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
-#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
-#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
-
-#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
+#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
struct _MDCPU {
- jmp_buf jb;
- pthread_t pthread;
- struct _MDCPU_Unix md_unix;
+ jmp_buf jb;
+ pthread_t pthread;
+ struct _MDCPU_Unix md_unix;
};
/*
@@ -162,15 +162,15 @@ extern pthread_mutex_t _pr_heapLock;
#define _PR_UNLOCK(lock) pthread_mutex_unlock(lock)
-#define _PR_LOCK_HEAP() { \
- if (_pr_primordialCPU) { \
- _PR_LOCK(_pr_heapLock); \
- }
+#define _PR_LOCK_HEAP() { \
+ if (_pr_primordialCPU) { \
+ _PR_LOCK(_pr_heapLock); \
+ }
-#define _PR_UNLOCK_HEAP() if (_pr_primordialCPU) { \
- _PR_UNLOCK(_pr_heapLock); \
- } \
- }
+#define _PR_UNLOCK_HEAP() if (_pr_primordialCPU) { \
+ _PR_UNLOCK(_pr_heapLock); \
+ } \
+ }
NSPR_API(PRStatus) _MD_NEW_LOCK(struct _MDLock *md);
NSPR_API(void) _MD_FREE_LOCK(struct _MDLock *lockp);
@@ -219,12 +219,12 @@ NSPR_API(void) _MD_CleanThread(struct PRThread *thread);
#define _MD_CLEAN_THREAD _MD_CleanThread
NSPR_API(PRStatus) _MD_CreateThread(
- struct PRThread *thread,
- void (*start) (void *),
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize);
+ struct PRThread *thread,
+ void (*start) (void *),
+ PRThreadPriority priority,
+ PRThreadScope scope,
+ PRThreadState state,
+ PRUint32 stackSize);
#define _MD_CREATE_THREAD _MD_CreateThread
extern void _MD_CleanupBeforeExit(void);
@@ -243,7 +243,7 @@ NSPR_API(PRStatus) _MD_WakeupWaiter(struct PRThread *);
#define _MD_WAKEUP_WAITER _MD_WakeupWaiter
NSPR_API(void) _MD_SetPriority(struct _MDThread *thread,
- PRThreadPriority newPri);
+ PRThreadPriority newPri);
#define _MD_SET_PRIORITY _MD_SetPriority
#endif /* PTHREADS_USER */
diff --git a/pr/include/md/_nto.h b/pr/include/md/_nto.h
index 95309756..1094dd18 100644
--- a/pr/include/md/_nto.h
+++ b/pr/include/md/_nto.h
@@ -9,19 +9,19 @@
/*
** Internal configuration macros
*/
-#define PR_LINKER_ARCH "nto"
-#define _PR_SI_SYSNAME "NTO"
-#define _PR_SI_ARCHITECTURE "x86"
-#define PR_DLL_SUFFIX ".so"
-
-#define _PR_VMBASE 0x30000000
-#define _PR_STACK_VMBASE 0x50000000
-#define _MD_DEFAULT_STACK_SIZE 65536L
-#define _MD_MINIMUM_STACK_SIZE 131072L
-#define _MD_MMAP_FLAGS MAP_PRIVATE
-
-#ifndef HAVE_WEAK_IO_SYMBOLS
-#define HAVE_WEAK_IO_SYMBOLS
+#define PR_LINKER_ARCH "nto"
+#define _PR_SI_SYSNAME "NTO"
+#define _PR_SI_ARCHITECTURE "x86"
+#define PR_DLL_SUFFIX ".so"
+
+#define _PR_VMBASE 0x30000000
+#define _PR_STACK_VMBASE 0x50000000
+#define _MD_DEFAULT_STACK_SIZE 65536L
+#define _MD_MINIMUM_STACK_SIZE 131072L
+#define _MD_MMAP_FLAGS MAP_PRIVATE
+
+#ifndef HAVE_WEAK_IO_SYMBOLS
+#define HAVE_WEAK_IO_SYMBOLS
#endif
#undef _PR_POLL_AVAILABLE
@@ -35,14 +35,14 @@
#define _PR_HAVE_POSIX_SEMAPHORES
#undef FD_SETSIZE
-#define FD_SETSIZE 4096
+#define FD_SETSIZE 4096
#include <sys/time.h>
#include <sys/types.h>
#include <sys/select.h>
#undef HAVE_STACK_GROWING_UP
-#define HAVE_DLL
-#define USE_DLFCN
+#define HAVE_DLL
+#define USE_DLFCN
#define NEED_STRFTIME_LOCK
#define NEED_TIME_R
#define _PR_NEED_STRCASECMP
@@ -55,39 +55,39 @@
#include <setjmp.h>
-#define _SETJMP setjmp
-#define _LONGJMP longjmp
-#define _PR_CONTEXT_TYPE jmp_buf
-#define _PR_NUM_GCREGS _JBLEN
-#define _MD_GET_SP(_t) (_t)->md.context[7]
+#define _SETJMP setjmp
+#define _LONGJMP longjmp
+#define _PR_CONTEXT_TYPE jmp_buf
+#define _PR_NUM_GCREGS _JBLEN
+#define _MD_GET_SP(_t) (_t)->md.context[7]
-#define CONTEXT(_th) ((_th)->md.context)
+#define CONTEXT(_th) ((_th)->md.context)
/*
** Initialize the thread context preparing it to execute _main.
*/
-#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
-{ \
- *status = PR_TRUE; \
- if(_SETJMP(CONTEXT(_thread))) (*_main)(); \
- _MD_GET_SP(_thread) = (int) ((_sp) - 128); \
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
+{ \
+ *status = PR_TRUE; \
+ if(_SETJMP(CONTEXT(_thread))) (*_main)(); \
+ _MD_GET_SP(_thread) = (int) ((_sp) - 128); \
}
-#define _MD_SWITCH_CONTEXT(_thread) \
- if (!_SETJMP(CONTEXT(_thread))) { \
- (_thread)->md.errcode = errno; \
- _PR_Schedule(); \
+#define _MD_SWITCH_CONTEXT(_thread) \
+ if (!_SETJMP(CONTEXT(_thread))) { \
+ (_thread)->md.errcode = errno; \
+ _PR_Schedule(); \
}
/*
** Restore a thread context, saved by _MD_SWITCH_CONTEXT
*/
-#define _MD_RESTORE_CONTEXT(_thread) \
-{ \
- errno = (_thread)->md.errcode; \
- _MD_SET_CURRENT_THREAD(_thread); \
- _LONGJMP(CONTEXT(_thread), 1); \
+#define _MD_RESTORE_CONTEXT(_thread) \
+{ \
+ errno = (_thread)->md.errcode; \
+ _MD_SET_CURRENT_THREAD(_thread); \
+ _LONGJMP(CONTEXT(_thread), 1); \
}
/*
@@ -122,7 +122,7 @@ struct _MDSegment {
/*
** md-specific cpu structure field
*/
-#define _PR_MD_MAX_OSFD FD_SETSIZE
+#define _PR_MD_MAX_OSFD FD_SETSIZE
struct _MDCPU_Unix {
PRCList ioQ;
@@ -138,28 +138,28 @@ struct _MDCPU_Unix {
#endif
};
-#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
-#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
-#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
-#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
-#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
-#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
-#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
-#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
-#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
-#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
-#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
-#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
-#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
-
-#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
+#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
struct _MDCPU {
- struct _MDCPU_Unix md_unix;
+ struct _MDCPU_Unix md_unix;
};
#define _MD_INIT_LOCKS()
-#define _MD_NEW_LOCK(lock) PR_SUCCESS
+#define _MD_NEW_LOCK(lock) PR_SUCCESS
#define _MD_FREE_LOCK(lock)
#define _MD_LOCK(lock)
#define _MD_UNLOCK(lock)
@@ -168,20 +168,20 @@ struct _MDCPU {
#define _MD_IOQ_UNLOCK()
#define _MD_INTERVAL_USE_GTOD
-#define _MD_EARLY_INIT _MD_EarlyInit
-#define _MD_FINAL_INIT _PR_UnixInit
-#define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
-#define _MD_INIT_THREAD _MD_InitializeThread
+#define _MD_EARLY_INIT _MD_EarlyInit
+#define _MD_FINAL_INIT _PR_UnixInit
+#define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
+#define _MD_INIT_THREAD _MD_InitializeThread
#define _MD_EXIT_THREAD(thread)
-#define _MD_SUSPEND_THREAD(thread)
-#define _MD_RESUME_THREAD(thread)
+#define _MD_SUSPEND_THREAD(thread)
+#define _MD_RESUME_THREAD(thread)
#define _MD_CLEAN_THREAD(_thread)
/*
** We wrapped the select() call. _MD_SELECT refers to the built-in,
** unwrapped version.
*/
-#define _MD_SELECT select
+#define _MD_SELECT select
#define SA_RESTART 0
diff --git a/pr/include/md/_openbsd.h b/pr/include/md/_openbsd.h
index 666c177e..43fed38a 100644
--- a/pr/include/md/_openbsd.h
+++ b/pr/include/md/_openbsd.h
@@ -8,7 +8,7 @@
#include <sys/syscall.h>
-#define PR_LINKER_ARCH "openbsd"
+#define PR_LINKER_ARCH "openbsd"
#define _PR_SI_SYSNAME "OPENBSD"
#if defined(__i386__)
#define _PR_SI_ARCHITECTURE "x86"
@@ -26,11 +26,11 @@
#define _PR_SI_ARCHITECTURE "arm"
#endif
-#define PR_DLL_SUFFIX ".so"
+#define PR_DLL_SUFFIX ".so"
#define _PR_VMBASE 0x30000000
-#define _PR_STACK_VMBASE 0x50000000
-#define _MD_DEFAULT_STACK_SIZE 65536L
+#define _PR_STACK_VMBASE 0x50000000
+#define _MD_DEFAULT_STACK_SIZE 65536L
#define _MD_MMAP_FLAGS MAP_PRIVATE
#undef HAVE_STACK_GROWING_UP
@@ -55,7 +55,7 @@
#ifndef _PR_PTHREADS
#include <setjmp.h>
-#define PR_CONTEXT_TYPE sigjmp_buf
+#define PR_CONTEXT_TYPE sigjmp_buf
#define CONTEXT(_th) ((_th)->md.context)
@@ -74,7 +74,7 @@
#endif
#define _MD_GET_SP(_th) (_th)->md.context[JB_SP_INDEX]
-#define PR_NUM_GCREGS _JBLEN
+#define PR_NUM_GCREGS _JBLEN
/*
** Initialize a thread context to run "_main()" when started
@@ -145,28 +145,28 @@ struct _MDCPU_Unix {
#ifndef _PR_USE_POLL
fd_set fd_read_set, fd_write_set, fd_exception_set;
PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
- fd_exception_cnt[_PR_MD_MAX_OSFD];
+ fd_exception_cnt[_PR_MD_MAX_OSFD];
#else
- struct pollfd *ioq_pollfds;
- int ioq_pollfds_size;
-#endif /* _PR_USE_POLL */
+ struct pollfd *ioq_pollfds;
+ int ioq_pollfds_size;
+#endif /* _PR_USE_POLL */
};
-#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
+#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
-#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
-#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
-#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
-#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
-#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
-#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
-#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
-#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
-#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
-#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
-#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
-
-#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
+#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
struct _MDCPU {
struct _MDCPU_Unix md_unix;
@@ -191,7 +191,7 @@ struct _MDCPU {
#endif /* ! _PR_PTHREADS */
#define _MD_EARLY_INIT _MD_EarlyInit
-#define _MD_FINAL_INIT _PR_UnixInit
+#define _MD_FINAL_INIT _PR_UnixInit
#define _PR_HAVE_CLOCK_MONOTONIC
/*
diff --git a/pr/include/md/_os2.h b/pr/include/md/_os2.h
index 414663b0..2c3165a1 100644
--- a/pr/include/md/_os2.h
+++ b/pr/include/md/_os2.h
@@ -48,19 +48,19 @@ extern struct PRLock *_pr_schedLock;
typedef void (*FiberFunc)(void *);
#define PR_NUM_GCREGS 8
-typedef PRInt32 PR_CONTEXT_TYPE[PR_NUM_GCREGS];
+typedef PRInt32 PR_CONTEXT_TYPE[PR_NUM_GCREGS];
#define GC_VMBASE 0x40000000
#define GC_VMLIMIT 0x00FFFFFF
typedef int (*FARPROC)();
-#define _MD_MAGIC_THREAD 0x22222222
-#define _MD_MAGIC_THREADSTACK 0x33333333
-#define _MD_MAGIC_SEGMENT 0x44444444
-#define _MD_MAGIC_DIR 0x55555555
+#define _MD_MAGIC_THREAD 0x22222222
+#define _MD_MAGIC_THREADSTACK 0x33333333
+#define _MD_MAGIC_SEGMENT 0x44444444
+#define _MD_MAGIC_DIR 0x55555555
#define _MD_MAGIC_CV 0x66666666
struct _MDSemaphore {
- HEV sem;
+ HEV sem;
};
struct _MDCPU {
@@ -154,7 +154,7 @@ struct _MDFileDesc {
};
struct _MDProcess {
- PID pid;
+ PID pid;
};
/* --- Misc stuff --- */
@@ -251,7 +251,7 @@ extern PRInt32 _MD_SocketAvailable(PRFileDesc *fd);
#define _MD_PIPEAVAILABLE _MD_SocketAvailable
#define _MD_CONNECT (_PR_MD_CONNECT)
extern PRInt32 _MD_Accept(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
- PRIntervalTime timeout);
+ PRIntervalTime timeout);
#define _MD_ACCEPT _MD_Accept
#define _MD_BIND (_PR_MD_BIND)
#define _MD_RECV (_PR_MD_RECV)
@@ -264,8 +264,8 @@ extern PRInt32 _MD_Accept(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
/* --- DIR stuff --- */
#define PR_DIRECTORY_SEPARATOR '\\'
#define PR_DIRECTORY_SEPARATOR_STR "\\"
-#define PR_PATH_SEPARATOR ';'
-#define PR_PATH_SEPARATOR_STR ";"
+#define PR_PATH_SEPARATOR ';'
+#define PR_PATH_SEPARATOR_STR ";"
#define _MD_ERRNO() errno
#define _MD_OPEN_DIR (_PR_MD_OPEN_DIR)
#define _MD_CLOSE_DIR (_PR_MD_CLOSE_DIR)
@@ -303,7 +303,7 @@ extern PRInt32 _MD_Accept(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
/* --- Lock stuff --- */
#define _PR_LOCK _MD_LOCK
-#define _PR_UNLOCK _MD_UNLOCK
+#define _PR_UNLOCK _MD_UNLOCK
#define _MD_NEW_LOCK (_PR_MD_NEW_LOCK)
#define _MD_FREE_LOCK(lock) (DosCloseMutexSem((lock)->mutex))
@@ -316,13 +316,13 @@ extern PRInt32 _MD_Accept(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
#define _MD_WAKEUP_WAITER (_PR_MD_WAKEUP_WAITER)
/* --- CVar ------------------- */
-#define _MD_WAIT_CV (_PR_MD_WAIT_CV)
-#define _MD_NEW_CV (_PR_MD_NEW_CV)
-#define _MD_FREE_CV (_PR_MD_FREE_CV)
-#define _MD_NOTIFY_CV (_PR_MD_NOTIFY_CV )
-#define _MD_NOTIFYALL_CV (_PR_MD_NOTIFYALL_CV)
+#define _MD_WAIT_CV (_PR_MD_WAIT_CV)
+#define _MD_NEW_CV (_PR_MD_NEW_CV)
+#define _MD_FREE_CV (_PR_MD_FREE_CV)
+#define _MD_NOTIFY_CV (_PR_MD_NOTIFY_CV )
+#define _MD_NOTIFYALL_CV (_PR_MD_NOTIFYALL_CV)
- /* XXXMB- the IOQ stuff is certainly not working correctly yet. */
+/* XXXMB- the IOQ stuff is certainly not working correctly yet. */
/* extern struct _MDLock _pr_ioq_lock; */
#define _MD_IOQ_LOCK()
#define _MD_IOQ_UNLOCK()
@@ -358,7 +358,7 @@ extern PRStatus _PR_DetachOS2Process(struct PRProcess *process);
/* --- Wait for a child process to terminate --- */
#define _MD_WAIT_PROCESS _PR_WaitOS2Process
extern PRStatus _PR_WaitOS2Process(struct PRProcess *process,
- PRInt32 *exitCode);
+ PRInt32 *exitCode);
#define _MD_KILL_PROCESS _PR_KillOS2Process
extern PRStatus _PR_KillOS2Process(struct PRProcess *process);
@@ -409,7 +409,7 @@ extern struct PRThread * _MD_CURRENT_THREAD(void);
/* --- Scheduler stuff --- */
#define LOCK_SCHEDULER() 0
#define UNLOCK_SCHEDULER() 0
-#define _PR_LockSched() 0
+#define _PR_LockSched() 0
#define _PR_UnlockSched() 0
/* --- Initialization stuff --- */
@@ -434,7 +434,7 @@ extern PRInt32 _MD_GetMemMapAlignment(void);
#define _MD_GET_MEM_MAP_ALIGNMENT _MD_GetMemMapAlignment
extern void * _MD_MemMap(struct PRFileMap *fmap, PRInt64 offset,
- PRUint32 len);
+ PRUint32 len);
#define _MD_MEM_MAP _MD_MemMap
extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size);
diff --git a/pr/include/md/_os2_errors.h b/pr/include/md/_os2_errors.h
index 2ba9b7a1..556a9ae8 100644
--- a/pr/include/md/_os2_errors.h
+++ b/pr/include/md/_os2_errors.h
@@ -8,119 +8,119 @@
#include "md/_os2.h"
#ifndef assert
- #include <assert.h>
+#include <assert.h>
#endif
NSPR_API(void) _MD_os2_map_default_error(PRInt32 err);
-#define _PR_MD_MAP_DEFAULT_ERROR _MD_os2_map_default_error
+#define _PR_MD_MAP_DEFAULT_ERROR _MD_os2_map_default_error
NSPR_API(void) _MD_os2_map_opendir_error(PRInt32 err);
-#define _PR_MD_MAP_OPENDIR_ERROR _MD_os2_map_opendir_error
+#define _PR_MD_MAP_OPENDIR_ERROR _MD_os2_map_opendir_error
NSPR_API(void) _MD_os2_map_closedir_error(PRInt32 err);
-#define _PR_MD_MAP_CLOSEDIR_ERROR _MD_os2_map_closedir_error
+#define _PR_MD_MAP_CLOSEDIR_ERROR _MD_os2_map_closedir_error
NSPR_API(void) _MD_os2_readdir_error(PRInt32 err);
-#define _PR_MD_MAP_READDIR_ERROR _MD_os2_readdir_error
+#define _PR_MD_MAP_READDIR_ERROR _MD_os2_readdir_error
NSPR_API(void) _MD_os2_map_delete_error(PRInt32 err);
-#define _PR_MD_MAP_DELETE_ERROR _MD_os2_map_delete_error
+#define _PR_MD_MAP_DELETE_ERROR _MD_os2_map_delete_error
NSPR_API(void) _MD_os2_map_stat_error(PRInt32 err);
-#define _PR_MD_MAP_STAT_ERROR _MD_os2_map_stat_error
+#define _PR_MD_MAP_STAT_ERROR _MD_os2_map_stat_error
NSPR_API(void) _MD_os2_map_fstat_error(PRInt32 err);
-#define _PR_MD_MAP_FSTAT_ERROR _MD_os2_map_fstat_error
+#define _PR_MD_MAP_FSTAT_ERROR _MD_os2_map_fstat_error
NSPR_API(void) _MD_os2_map_rename_error(PRInt32 err);
-#define _PR_MD_MAP_RENAME_ERROR _MD_os2_map_rename_error
+#define _PR_MD_MAP_RENAME_ERROR _MD_os2_map_rename_error
NSPR_API(void) _MD_os2_map_access_error(PRInt32 err);
-#define _PR_MD_MAP_ACCESS_ERROR _MD_os2_map_access_error
+#define _PR_MD_MAP_ACCESS_ERROR _MD_os2_map_access_error
NSPR_API(void) _MD_os2_map_mkdir_error(PRInt32 err);
-#define _PR_MD_MAP_MKDIR_ERROR _MD_os2_map_mkdir_error
+#define _PR_MD_MAP_MKDIR_ERROR _MD_os2_map_mkdir_error
NSPR_API(void) _MD_os2_map_rmdir_error(PRInt32 err);
-#define _PR_MD_MAP_RMDIR_ERROR _MD_os2_map_rmdir_error
+#define _PR_MD_MAP_RMDIR_ERROR _MD_os2_map_rmdir_error
NSPR_API(void) _MD_os2_map_read_error(PRInt32 err);
-#define _PR_MD_MAP_READ_ERROR _MD_os2_map_read_error
+#define _PR_MD_MAP_READ_ERROR _MD_os2_map_read_error
NSPR_API(void) _MD_os2_map_transmitfile_error(PRInt32 err);
-#define _PR_MD_MAP_TRANSMITFILE_ERROR _MD_os2_map_transmitfile_error
+#define _PR_MD_MAP_TRANSMITFILE_ERROR _MD_os2_map_transmitfile_error
NSPR_API(void) _MD_os2_map_write_error(PRInt32 err);
-#define _PR_MD_MAP_WRITE_ERROR _MD_os2_map_write_error
+#define _PR_MD_MAP_WRITE_ERROR _MD_os2_map_write_error
NSPR_API(void) _MD_os2_map_lseek_error(PRInt32 err);
-#define _PR_MD_MAP_LSEEK_ERROR _MD_os2_map_lseek_error
+#define _PR_MD_MAP_LSEEK_ERROR _MD_os2_map_lseek_error
NSPR_API(void) _MD_os2_map_fsync_error(PRInt32 err);
-#define _PR_MD_MAP_FSYNC_ERROR _MD_os2_map_fsync_error
+#define _PR_MD_MAP_FSYNC_ERROR _MD_os2_map_fsync_error
NSPR_API(void) _MD_os2_map_close_error(PRInt32 err);
-#define _PR_MD_MAP_CLOSE_ERROR _MD_os2_map_close_error
+#define _PR_MD_MAP_CLOSE_ERROR _MD_os2_map_close_error
NSPR_API(void) _MD_os2_map_socket_error(PRInt32 err);
-#define _PR_MD_MAP_SOCKET_ERROR _MD_os2_map_socket_error
+#define _PR_MD_MAP_SOCKET_ERROR _MD_os2_map_socket_error
NSPR_API(void) _MD_os2_map_recv_error(PRInt32 err);
-#define _PR_MD_MAP_RECV_ERROR _MD_os2_map_recv_error
+#define _PR_MD_MAP_RECV_ERROR _MD_os2_map_recv_error
NSPR_API(void) _MD_os2_map_recvfrom_error(PRInt32 err);
-#define _PR_MD_MAP_RECVFROM_ERROR _MD_os2_map_recvfrom_error
+#define _PR_MD_MAP_RECVFROM_ERROR _MD_os2_map_recvfrom_error
NSPR_API(void) _MD_os2_map_send_error(PRInt32 err);
-#define _PR_MD_MAP_SEND_ERROR _MD_os2_map_send_error
+#define _PR_MD_MAP_SEND_ERROR _MD_os2_map_send_error
NSPR_API(void) _MD_os2_map_sendto_error(PRInt32 err);
-#define _PR_MD_MAP_SENDTO_ERROR _MD_os2_map_sendto_error
+#define _PR_MD_MAP_SENDTO_ERROR _MD_os2_map_sendto_error
NSPR_API(void) _MD_os2_map_writev_error(int err);
-#define _PR_MD_MAP_WRITEV_ERROR _MD_os2_map_writev_error
+#define _PR_MD_MAP_WRITEV_ERROR _MD_os2_map_writev_error
NSPR_API(void) _MD_os2_map_accept_error(PRInt32 err);
-#define _PR_MD_MAP_ACCEPT_ERROR _MD_os2_map_accept_error
+#define _PR_MD_MAP_ACCEPT_ERROR _MD_os2_map_accept_error
NSPR_API(void) _MD_os2_map_acceptex_error(PRInt32 err);
-#define _PR_MD_MAP_ACCEPTEX_ERROR _MD_os2_map_acceptex_error
+#define _PR_MD_MAP_ACCEPTEX_ERROR _MD_os2_map_acceptex_error
NSPR_API(void) _MD_os2_map_connect_error(PRInt32 err);
-#define _PR_MD_MAP_CONNECT_ERROR _MD_os2_map_connect_error
+#define _PR_MD_MAP_CONNECT_ERROR _MD_os2_map_connect_error
NSPR_API(void) _MD_os2_map_bind_error(PRInt32 err);
-#define _PR_MD_MAP_BIND_ERROR _MD_os2_map_bind_error
+#define _PR_MD_MAP_BIND_ERROR _MD_os2_map_bind_error
NSPR_API(void) _MD_os2_map_listen_error(PRInt32 err);
-#define _PR_MD_MAP_LISTEN_ERROR _MD_os2_map_listen_error
+#define _PR_MD_MAP_LISTEN_ERROR _MD_os2_map_listen_error
NSPR_API(void) _MD_os2_map_shutdown_error(PRInt32 err);
-#define _PR_MD_MAP_SHUTDOWN_ERROR _MD_os2_map_shutdown_error
+#define _PR_MD_MAP_SHUTDOWN_ERROR _MD_os2_map_shutdown_error
NSPR_API(void) _MD_os2_map_socketpair_error(int err);
-#define _PR_MD_MAP_SOCKETPAIR_ERROR _MD_os2_map_socketpair_error
+#define _PR_MD_MAP_SOCKETPAIR_ERROR _MD_os2_map_socketpair_error
NSPR_API(void) _MD_os2_map_getsockname_error(PRInt32 err);
-#define _PR_MD_MAP_GETSOCKNAME_ERROR _MD_os2_map_getsockname_error
+#define _PR_MD_MAP_GETSOCKNAME_ERROR _MD_os2_map_getsockname_error
NSPR_API(void) _MD_os2_map_getpeername_error(PRInt32 err);
-#define _PR_MD_MAP_GETPEERNAME_ERROR _MD_os2_map_getpeername_error
+#define _PR_MD_MAP_GETPEERNAME_ERROR _MD_os2_map_getpeername_error
NSPR_API(void) _MD_os2_map_getsockopt_error(PRInt32 err);
-#define _PR_MD_MAP_GETSOCKOPT_ERROR _MD_os2_map_getsockopt_error
+#define _PR_MD_MAP_GETSOCKOPT_ERROR _MD_os2_map_getsockopt_error
NSPR_API(void) _MD_os2_map_setsockopt_error(PRInt32 err);
-#define _PR_MD_MAP_SETSOCKOPT_ERROR _MD_os2_map_setsockopt_error
+#define _PR_MD_MAP_SETSOCKOPT_ERROR _MD_os2_map_setsockopt_error
NSPR_API(void) _MD_os2_map_open_error(PRInt32 err);
-#define _PR_MD_MAP_OPEN_ERROR _MD_os2_map_open_error
+#define _PR_MD_MAP_OPEN_ERROR _MD_os2_map_open_error
NSPR_API(void) _MD_os2_map_gethostname_error(PRInt32 err);
-#define _PR_MD_MAP_GETHOSTNAME_ERROR _MD_os2_map_gethostname_error
+#define _PR_MD_MAP_GETHOSTNAME_ERROR _MD_os2_map_gethostname_error
NSPR_API(void) _MD_os2_map_select_error(PRInt32 err);
-#define _PR_MD_MAP_SELECT_ERROR _MD_os2_map_select_error
+#define _PR_MD_MAP_SELECT_ERROR _MD_os2_map_select_error
NSPR_API(void) _MD_os2_map_lockf_error(int err);
#define _PR_MD_MAP_LOCKF_ERROR _MD_os2_map_lockf_error
diff --git a/pr/include/md/_pcos.h b/pr/include/md/_pcos.h
index 3b4f2054..679fe19b 100644
--- a/pr/include/md/_pcos.h
+++ b/pr/include/md/_pcos.h
@@ -6,7 +6,7 @@
#ifndef prpcos_h___
#define prpcos_h___
-#define PR_DLL_SUFFIX ".dll"
+#define PR_DLL_SUFFIX ".dll"
#include <stdlib.h>
diff --git a/pr/include/md/_pth.h b/pr/include/md/_pth.h
index 9c9012a1..37d26e70 100644
--- a/pr/include/md/_pth.h
+++ b/pr/include/md/_pth.h
@@ -85,11 +85,11 @@
* recursion ensues.
*/
#if defined(AIX) || defined(SOLARIS) \
- || defined(LINUX) || defined(__GNU__) || defined(__GLIBC__) \
- || defined(HPUX) || defined(FREEBSD) \
- || defined(NETBSD) || defined(OPENBSD) || defined(BSDI) \
- || defined(NTO) || defined(DARWIN) \
- || defined(UNIXWARE) || defined(RISCOS)
+ || defined(LINUX) || defined(__GNU__) || defined(__GLIBC__) \
+ || defined(HPUX) || defined(FREEBSD) \
+ || defined(NETBSD) || defined(OPENBSD) || defined(BSDI) \
+ || defined(NTO) || defined(DARWIN) \
+ || defined(UNIXWARE) || defined(RISCOS)
#define _PT_PTHREAD_INVALIDATE_THR_HANDLE(t) (t) = 0
#define _PT_PTHREAD_THR_HANDLE_IS_INVALID(t) (t) == 0
#define _PT_PTHREAD_COPY_THR_HANDLE(st, dt) (dt) = (st)
@@ -113,10 +113,10 @@
* These platforms don't have sigtimedwait()
*/
#if (defined(AIX) && !defined(AIX4_3_PLUS)) \
- || defined(LINUX) || defined(__GNU__)|| defined(__GLIBC__) \
- || defined(FREEBSD) || defined(NETBSD) || defined(OPENBSD) \
- || defined(BSDI) || defined(UNIXWARE) \
- || defined(DARWIN)
+ || defined(LINUX) || defined(__GNU__)|| defined(__GLIBC__) \
+ || defined(FREEBSD) || defined(NETBSD) || defined(OPENBSD) \
+ || defined(BSDI) || defined(UNIXWARE) \
+ || defined(DARWIN)
#define PT_NO_SIGTIMEDWAIT
#endif
@@ -133,7 +133,7 @@
#define PT_PRIO_MIN sched_get_priority_min(SCHED_OTHER)
#define PT_PRIO_MAX sched_get_priority_max(SCHED_OTHER)
#elif defined(LINUX) || defined(__GNU__) || defined(__GLIBC__) \
- || defined(FREEBSD)
+ || defined(FREEBSD)
#define PT_PRIO_MIN sched_get_priority_min(SCHED_OTHER)
#define PT_PRIO_MAX sched_get_priority_max(SCHED_OTHER)
#elif defined(NTO)
@@ -157,8 +157,8 @@
#define PT_PRIO_MIN 0
#define PT_PRIO_MAX 31
#elif defined(NETBSD) \
- || defined(BSDI) || defined(DARWIN) || defined(UNIXWARE) \
- || defined(RISCOS) /* XXX */
+ || defined(BSDI) || defined(DARWIN) || defined(UNIXWARE) \
+ || defined(RISCOS) /* XXX */
#define PT_PRIO_MIN 0
#define PT_PRIO_MAX 126
#else
@@ -172,13 +172,13 @@
*/
#if defined(AIX)
extern int (*_PT_aix_yield_fcn)();
-#define _PT_PTHREAD_YIELD() (*_PT_aix_yield_fcn)()
+#define _PT_PTHREAD_YIELD() (*_PT_aix_yield_fcn)()
#elif defined(HPUX) || defined(SOLARIS) \
- || defined(LINUX) || defined(__GNU__) || defined(__GLIBC__) \
- || defined(FREEBSD) || defined(NETBSD) || defined(OPENBSD) \
- || defined(BSDI) || defined(NTO) || defined(DARWIN) \
- || defined(UNIXWARE) || defined(RISCOS)
-#define _PT_PTHREAD_YIELD() sched_yield()
+ || defined(LINUX) || defined(__GNU__) || defined(__GLIBC__) \
+ || defined(FREEBSD) || defined(NETBSD) || defined(OPENBSD) \
+ || defined(BSDI) || defined(NTO) || defined(DARWIN) \
+ || defined(UNIXWARE) || defined(RISCOS)
+#define _PT_PTHREAD_YIELD() sched_yield()
#else
#error "Need to define _PT_PTHREAD_YIELD for this platform"
#endif
diff --git a/pr/include/md/_qnx.h b/pr/include/md/_qnx.h
index d3bba6d0..923e1743 100644
--- a/pr/include/md/_qnx.h
+++ b/pr/include/md/_qnx.h
@@ -9,18 +9,18 @@
/*
** Internal configuration macros
*/
-#define PR_LINKER_ARCH "qnx"
-#define _PR_SI_SYSNAME "QNX"
-#define _PR_SI_ARCHITECTURE "x86"
-#define PR_DLL_SUFFIX ".so"
-
-#define _PR_VMBASE 0x30000000
-#define _PR_STACK_VMBASE 0x50000000
-#define _MD_DEFAULT_STACK_SIZE 65536L
-#define _MD_MMAP_FLAGS MAP_PRIVATE
-
-#ifndef HAVE_WEAK_IO_SYMBOLS
-#define HAVE_WEAK_IO_SYMBOLS
+#define PR_LINKER_ARCH "qnx"
+#define _PR_SI_SYSNAME "QNX"
+#define _PR_SI_ARCHITECTURE "x86"
+#define PR_DLL_SUFFIX ".so"
+
+#define _PR_VMBASE 0x30000000
+#define _PR_STACK_VMBASE 0x50000000
+#define _MD_DEFAULT_STACK_SIZE 65536L
+#define _MD_MMAP_FLAGS MAP_PRIVATE
+
+#ifndef HAVE_WEAK_IO_SYMBOLS
+#define HAVE_WEAK_IO_SYMBOLS
#endif
#undef _PR_POLL_AVAILABLE
@@ -33,8 +33,8 @@
#include <sys/select.h>
#undef HAVE_STACK_GROWING_UP
-#undef HAVE_DLL
-#undef USE_DLFCN
+#undef HAVE_DLL
+#undef USE_DLFCN
#define NEED_STRFTIME_LOCK
#define NEED_TIME_R
#define _PR_NEED_STRCASECMP
@@ -47,38 +47,38 @@
#include <setjmp.h>
-#define _SETJMP setjmp
-#define _LONGJMP longjmp
-#define _PR_CONTEXT_TYPE jmp_buf
-#define _PR_NUM_GCREGS _JBLEN
-#define _MD_GET_SP(_t) (_t)->md.context[7]
+#define _SETJMP setjmp
+#define _LONGJMP longjmp
+#define _PR_CONTEXT_TYPE jmp_buf
+#define _PR_NUM_GCREGS _JBLEN
+#define _MD_GET_SP(_t) (_t)->md.context[7]
-#define CONTEXT(_th) ((_th)->md.context)
+#define CONTEXT(_th) ((_th)->md.context)
/*
** Initialize the thread context preparing it to execute _main.
*/
-#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
-{ \
- *status = PR_TRUE; \
- if(_SETJMP(CONTEXT(_thread))) (*_main)(); \
- _MD_GET_SP(_thread) = (int) ((_sp) - 128); \
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
+{ \
+ *status = PR_TRUE; \
+ if(_SETJMP(CONTEXT(_thread))) (*_main)(); \
+ _MD_GET_SP(_thread) = (int) ((_sp) - 128); \
}
-#define _MD_SWITCH_CONTEXT(_thread) \
- if (!_SETJMP(CONTEXT(_thread))) { \
- (_thread)->md.errcode = errno; \
- _PR_Schedule(); \
+#define _MD_SWITCH_CONTEXT(_thread) \
+ if (!_SETJMP(CONTEXT(_thread))) { \
+ (_thread)->md.errcode = errno; \
+ _PR_Schedule(); \
}
/*
** Restore a thread context, saved by _MD_SWITCH_CONTEXT
*/
-#define _MD_RESTORE_CONTEXT(_thread) \
-{ \
- errno = (_thread)->md.errcode; \
- _MD_SET_CURRENT_THREAD(_thread); \
- _LONGJMP(CONTEXT(_thread), 1); \
+#define _MD_RESTORE_CONTEXT(_thread) \
+{ \
+ errno = (_thread)->md.errcode; \
+ _MD_SET_CURRENT_THREAD(_thread); \
+ _LONGJMP(CONTEXT(_thread), 1); \
}
/*
@@ -113,7 +113,7 @@ struct _MDSegment {
/*
** md-specific cpu structure field
*/
-#define _PR_MD_MAX_OSFD FD_SETSIZE
+#define _PR_MD_MAX_OSFD FD_SETSIZE
struct _MDCPU_Unix {
PRCList ioQ;
@@ -129,28 +129,28 @@ struct _MDCPU_Unix {
#endif
};
-#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
-#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
-#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
-#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
-#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
-#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
-#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
-#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
-#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
-#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
-#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
-#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
-#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
-
-#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
+#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
struct _MDCPU {
- struct _MDCPU_Unix md_unix;
+ struct _MDCPU_Unix md_unix;
};
#define _MD_INIT_LOCKS()
-#define _MD_NEW_LOCK(lock) PR_SUCCESS
+#define _MD_NEW_LOCK(lock) PR_SUCCESS
#define _MD_FREE_LOCK(lock)
#define _MD_LOCK(lock)
#define _MD_UNLOCK(lock)
@@ -159,13 +159,13 @@ struct _MDCPU {
#define _MD_IOQ_UNLOCK()
#define _MD_INTERVAL_USE_GTOD
-#define _MD_EARLY_INIT _MD_EarlyInit
-#define _MD_FINAL_INIT _PR_UnixInit
-#define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
-#define _MD_INIT_THREAD _MD_InitializeThread
+#define _MD_EARLY_INIT _MD_EarlyInit
+#define _MD_FINAL_INIT _PR_UnixInit
+#define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
+#define _MD_INIT_THREAD _MD_InitializeThread
#define _MD_EXIT_THREAD(thread)
-#define _MD_SUSPEND_THREAD(thread)
-#define _MD_RESUME_THREAD(thread)
+#define _MD_SUSPEND_THREAD(thread)
+#define _MD_RESUME_THREAD(thread)
#define _MD_CLEAN_THREAD(_thread)
/*
@@ -175,7 +175,7 @@ struct _MDCPU {
#include <sys/time.h>
#include <sys/types.h>
#include <sys/select.h>
-#define _MD_SELECT select
+#define _MD_SELECT select
#define SA_RESTART 0
diff --git a/pr/include/md/_riscos.h b/pr/include/md/_riscos.h
index f62d668d..ec03dcbd 100644
--- a/pr/include/md/_riscos.h
+++ b/pr/include/md/_riscos.h
@@ -9,10 +9,10 @@
/*
** Internal configuration macros
*/
-#define PR_LINKER_ARCH "riscos"
-#define _PR_SI_SYSNAME "RISCOS"
-#define _PR_SI_ARCHITECTURE "arm"
-#define PR_DLL_SUFFIX ".so"
+#define PR_LINKER_ARCH "riscos"
+#define _PR_SI_SYSNAME "RISCOS"
+#define _PR_SI_ARCHITECTURE "arm"
+#define PR_DLL_SUFFIX ".so"
#define _PR_POLL_AVAILABLE
#define _PR_USE_POLL
@@ -42,39 +42,39 @@
#include <setjmp.h>
-#define _SETJMP setjmp
-#define _LONGJMP longjmp
-#define _PR_CONTEXT_TYPE jmp_buf
-#define _PR_NUM_GCREGS _JBLEN
-#define _MD_GET_SP(_t) (_t)->md.context[7]
+#define _SETJMP setjmp
+#define _LONGJMP longjmp
+#define _PR_CONTEXT_TYPE jmp_buf
+#define _PR_NUM_GCREGS _JBLEN
+#define _MD_GET_SP(_t) (_t)->md.context[7]
-#define CONTEXT(_th) ((_th)->md.context)
+#define CONTEXT(_th) ((_th)->md.context)
/*
** Initialize the thread context preparing it to execute _main.
*/
-#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
-{ \
- *status = PR_TRUE; \
- if(_SETJMP(CONTEXT(_thread))) (*_main)(); \
- _MD_GET_SP(_thread) = (int) ((_sp) - 128); \
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
+{ \
+ *status = PR_TRUE; \
+ if(_SETJMP(CONTEXT(_thread))) (*_main)(); \
+ _MD_GET_SP(_thread) = (int) ((_sp) - 128); \
}
-#define _MD_SWITCH_CONTEXT(_thread) \
- if (!_SETJMP(CONTEXT(_thread))) { \
- (_thread)->md.errcode = errno; \
- _PR_Schedule(); \
+#define _MD_SWITCH_CONTEXT(_thread) \
+ if (!_SETJMP(CONTEXT(_thread))) { \
+ (_thread)->md.errcode = errno; \
+ _PR_Schedule(); \
}
/*
** Restore a thread context, saved by _MD_SWITCH_CONTEXT
*/
-#define _MD_RESTORE_CONTEXT(_thread) \
-{ \
- errno = (_thread)->md.errcode; \
- _MD_SET_CURRENT_THREAD(_thread); \
- _LONGJMP(CONTEXT(_thread), 1); \
+#define _MD_RESTORE_CONTEXT(_thread) \
+{ \
+ errno = (_thread)->md.errcode; \
+ _MD_SET_CURRENT_THREAD(_thread); \
+ _LONGJMP(CONTEXT(_thread), 1); \
}
/*
@@ -109,7 +109,7 @@ struct _MDSegment {
/*
** md-specific cpu structure field
*/
-#define _PR_MD_MAX_OSFD FD_SETSIZE
+#define _PR_MD_MAX_OSFD FD_SETSIZE
struct _MDCPU_Unix {
PRCList ioQ;
@@ -125,28 +125,28 @@ struct _MDCPU_Unix {
#endif
};
-#define _PR_IOQ(_cpu) /* */ ((_cpu)->md.md_unix.ioQ)
-#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
-#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
-#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
-#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
-#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
-#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
-#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
-#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
-#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
-#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
-#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
-#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
-
-#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
+#define _PR_IOQ(_cpu) /* */ ((_cpu)->md.md_unix.ioQ)
+#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
+#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
struct _MDCPU {
- struct _MDCPU_Unix md_unix;
+ struct _MDCPU_Unix md_unix;
};
#define _MD_INIT_LOCKS()
-#define _MD_NEW_LOCK(lock) PR_SUCCESS
+#define _MD_NEW_LOCK(lock) PR_SUCCESS
#define _MD_FREE_LOCK(lock)
#define _MD_LOCK(lock)
#define _MD_UNLOCK(lock)
@@ -155,13 +155,13 @@ struct _MDCPU {
#define _MD_IOQ_UNLOCK()
#define _MD_INTERVAL_USE_GTOD
-#define _MD_EARLY_INIT _MD_EarlyInit
-#define _MD_FINAL_INIT _PR_UnixInit
-#define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
-#define _MD_INIT_THREAD _MD_InitializeThread
+#define _MD_EARLY_INIT _MD_EarlyInit
+#define _MD_FINAL_INIT _PR_UnixInit
+#define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
+#define _MD_INIT_THREAD _MD_InitializeThread
#define _MD_EXIT_THREAD(thread)
-#define _MD_SUSPEND_THREAD(thread)
-#define _MD_RESUME_THREAD(thread)
+#define _MD_SUSPEND_THREAD(thread)
+#define _MD_RESUME_THREAD(thread)
#define _MD_CLEAN_THREAD(_thread)
/*
@@ -171,6 +171,6 @@ struct _MDCPU {
#include <sys/time.h>
#include <sys/types.h>
#include <sys/select.h>
-#define _MD_SELECT select
+#define _MD_SELECT select
#endif /* nspr_riscos_defs_h___ */
diff --git a/pr/include/md/_scoos.h b/pr/include/md/_scoos.h
index c444dcd9..1f6dda15 100644
--- a/pr/include/md/_scoos.h
+++ b/pr/include/md/_scoos.h
@@ -10,26 +10,26 @@
* Internal configuration macros
*/
-#define PR_LINKER_ARCH "scoos5"
-#define PR_DLL_SUFFIX ".so"
+#define PR_LINKER_ARCH "scoos5"
+#define PR_DLL_SUFFIX ".so"
#define _PR_SI_SYSNAME "SCO"
#define _PR_SI_ARCHITECTURE "x86"
#define _PR_STACK_VMBASE 0x50000000
-#define _MD_DEFAULT_STACK_SIZE 65536L
+#define _MD_DEFAULT_STACK_SIZE 65536L
#define _MD_MMAP_FLAGS MAP_PRIVATE
#undef HAVE_STACK_GROWING_UP
-#define HAVE_DLL
-#define USE_DLFCN
+#define HAVE_DLL
+#define USE_DLFCN
#if !defined (HAVE_STRERROR)
#define HAVE_STRERROR
#endif
-#ifndef HAVE_WEAK_IO_SYMBOLS
-#define HAVE_WEAK_IO_SYMBOLS
+#ifndef HAVE_WEAK_IO_SYMBOLS
+#define HAVE_WEAK_IO_SYMBOLS
#endif
#define _PR_POLL_AVAILABLE
@@ -47,34 +47,34 @@
#include <setjmp.h>
#define _MD_GET_SP(_t) (_t)->md.jb[4]
-#define PR_NUM_GCREGS _SIGJBLEN
-#define PR_CONTEXT_TYPE sigjmp_buf
+#define PR_NUM_GCREGS _SIGJBLEN
+#define PR_CONTEXT_TYPE sigjmp_buf
#define CONTEXT(_th) ((_th)->md.jb)
-#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
-{ \
- *status = PR_TRUE; \
- if (sigsetjmp(CONTEXT(_thread),1)) { \
- (*_main)(); \
- } \
- _MD_GET_SP(_thread) = (int) ((_sp) - 64); \
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
+{ \
+ *status = PR_TRUE; \
+ if (sigsetjmp(CONTEXT(_thread),1)) { \
+ (*_main)(); \
+ } \
+ _MD_GET_SP(_thread) = (int) ((_sp) - 64); \
}
-#define _MD_SWITCH_CONTEXT(_thread) \
- if (!sigsetjmp(CONTEXT(_thread), 1)) { \
- (_thread)->md.errcode = errno; \
- _PR_Schedule(); \
+#define _MD_SWITCH_CONTEXT(_thread) \
+ if (!sigsetjmp(CONTEXT(_thread), 1)) { \
+ (_thread)->md.errcode = errno; \
+ _PR_Schedule(); \
}
/*
** Restore a thread context, saved by _MD_SWITCH_CONTEXT
*/
-#define _MD_RESTORE_CONTEXT(_thread) \
-{ \
- errno = (_thread)->osErrorCode; \
- _MD_SET_CURRENT_THREAD(_thread); \
- siglongjmp(CONTEXT(_thread), 1); \
+#define _MD_RESTORE_CONTEXT(_thread) \
+{ \
+ errno = (_thread)->osErrorCode; \
+ _MD_SET_CURRENT_THREAD(_thread); \
+ siglongjmp(CONTEXT(_thread), 1); \
}
#endif /* _PR_LOCAL_THREADS_ONLY */
@@ -118,28 +118,28 @@ struct _MDCPU_Unix {
#ifndef _PR_USE_POLL
fd_set fd_read_set, fd_write_set, fd_exception_set;
PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
- fd_exception_cnt[_PR_MD_MAX_OSFD];
+ fd_exception_cnt[_PR_MD_MAX_OSFD];
#else
- struct pollfd *ioq_pollfds;
- int ioq_pollfds_size;
-#endif /* _PR_USE_POLL */
+ struct pollfd *ioq_pollfds;
+ int ioq_pollfds_size;
+#endif /* _PR_USE_POLL */
};
-#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
+#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
-#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
-#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
-#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
-#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
-#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
-#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
-#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
-#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
-#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
-#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
-#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
-
-#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
+#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
struct _MDCPU {
struct _MDCPU_Unix md_unix;
@@ -154,18 +154,18 @@ struct _MDCPU {
#define _MD_IOQ_LOCK()
#define _MD_IOQ_UNLOCK()
-#define _MD_EARLY_INIT _MD_EarlyInit
-#define _MD_FINAL_INIT _PR_UnixInit
-#define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
-#define _MD_INIT_THREAD _MD_InitializeThread
+#define _MD_EARLY_INIT _MD_EarlyInit
+#define _MD_FINAL_INIT _PR_UnixInit
+#define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
+#define _MD_INIT_THREAD _MD_InitializeThread
#define _MD_EXIT_THREAD(thread)
-#define _MD_SUSPEND_THREAD(thread)
-#define _MD_RESUME_THREAD(thread)
+#define _MD_SUSPEND_THREAD(thread)
+#define _MD_RESUME_THREAD(thread)
#define _MD_CLEAN_THREAD(_thread)
#define _MD_INTERVAL_USE_GTOD
-#define _MD_SELECT _select
-#define _MD_POLL _poll
+#define _MD_SELECT _select
+#define _MD_POLL _poll
#endif /* nspr_scoos5_defs_h___ */
diff --git a/pr/include/md/_solaris.h b/pr/include/md/_solaris.h
index 9da60ebb..4ebf77fd 100644
--- a/pr/include/md/_solaris.h
+++ b/pr/include/md/_solaris.h
@@ -10,33 +10,33 @@
* Internal configuration macros
*/
-#define PR_LINKER_ARCH "solaris"
-#define _PR_SI_SYSNAME "SOLARIS"
+#define PR_LINKER_ARCH "solaris"
+#define _PR_SI_SYSNAME "SOLARIS"
#ifdef sparc
-#define _PR_SI_ARCHITECTURE "sparc"
+#define _PR_SI_ARCHITECTURE "sparc"
#elif defined(__x86_64)
-#define _PR_SI_ARCHITECTURE "x86-64"
+#define _PR_SI_ARCHITECTURE "x86-64"
#elif defined(i386)
-#define _PR_SI_ARCHITECTURE "x86"
+#define _PR_SI_ARCHITECTURE "x86"
#else
#error unknown processor
#endif
-#define PR_DLL_SUFFIX ".so"
+#define PR_DLL_SUFFIX ".so"
-#define _PR_VMBASE 0x30000000
-#define _PR_STACK_VMBASE 0x50000000
-#define _MD_DEFAULT_STACK_SIZE (2*65536L)
+#define _PR_VMBASE 0x30000000
+#define _PR_STACK_VMBASE 0x50000000
+#define _MD_DEFAULT_STACK_SIZE (2*65536L)
#define _MD_MMAP_FLAGS MAP_SHARED
#undef HAVE_STACK_GROWING_UP
#ifndef HAVE_WEAK_IO_SYMBOLS
-#define HAVE_WEAK_IO_SYMBOLS
+#define HAVE_WEAK_IO_SYMBOLS
#endif
-#undef HAVE_WEAK_MALLOC_SYMBOLS
-#define HAVE_DLL
-#define USE_DLFCN
+#undef HAVE_WEAK_MALLOC_SYMBOLS
+#define HAVE_DLL
+#define USE_DLFCN
#define NEED_STRFTIME_LOCK
/*
@@ -137,10 +137,10 @@ NSPR_API(PRInt32) _MD_AtomicSet(PRInt32 *val, PRInt32 newval);
#if defined(_PR_PTHREADS)
-NSPR_API(void) _MD_EarlyInit(void);
+NSPR_API(void) _MD_EarlyInit(void);
-#define _MD_EARLY_INIT _MD_EarlyInit
-#define _MD_FINAL_INIT _PR_UnixInit
+#define _MD_EARLY_INIT _MD_EarlyInit
+#define _MD_FINAL_INIT _PR_UnixInit
#else /* _PR_PTHREADS */
@@ -159,46 +159,46 @@ NSPR_API(void) _MD_EarlyInit(void);
** Initialization Related definitions
*/
-NSPR_API(void) _MD_EarlyInit(void);
-NSPR_API(void) _MD_SolarisInit();
-#define _MD_EARLY_INIT _MD_EarlyInit
-#define _MD_FINAL_INIT _MD_SolarisInit
-#define _MD_INIT_THREAD _MD_InitializeThread
+NSPR_API(void) _MD_EarlyInit(void);
+NSPR_API(void) _MD_SolarisInit();
+#define _MD_EARLY_INIT _MD_EarlyInit
+#define _MD_FINAL_INIT _MD_SolarisInit
+#define _MD_INIT_THREAD _MD_InitializeThread
#ifdef USE_SETJMP
#include <setjmp.h>
-#define _PR_CONTEXT_TYPE jmp_buf
+#define _PR_CONTEXT_TYPE jmp_buf
#ifdef sparc
-#define _MD_GET_SP(_t) (_t)->md.context[2]
+#define _MD_GET_SP(_t) (_t)->md.context[2]
#else
-#define _MD_GET_SP(_t) (_t)->md.context[4]
+#define _MD_GET_SP(_t) (_t)->md.context[4]
#endif
-#define PR_NUM_GCREGS _JBLEN
-#define CONTEXT(_thread) (_thread)->md.context
+#define PR_NUM_GCREGS _JBLEN
+#define CONTEXT(_thread) (_thread)->md.context
#else /* ! USE_SETJMP */
#ifdef sparc
-#define _PR_CONTEXT_TYPE ucontext_t
-#define _MD_GET_SP(_t) (_t)->md.context.uc_mcontext.gregs[REG_SP]
+#define _PR_CONTEXT_TYPE ucontext_t
+#define _MD_GET_SP(_t) (_t)->md.context.uc_mcontext.gregs[REG_SP]
/*
** Sparc's use register windows. the _MD_GetRegisters for the sparc's
** doesn't actually store anything into the argument buffer; instead the
** register windows are homed to the stack. I assume that the stack
** always has room for the registers to spill to...
*/
-#define PR_NUM_GCREGS 0
+#define PR_NUM_GCREGS 0
#else
-#define _PR_CONTEXT_TYPE unsigned int edi; sigset_t oldMask, blockMask; ucontext_t
-#define _MD_GET_SP(_t) (_t)->md.context.uc_mcontext.gregs[USP]
-#define PR_NUM_GCREGS _JBLEN
+#define _PR_CONTEXT_TYPE unsigned int edi; sigset_t oldMask, blockMask; ucontext_t
+#define _MD_GET_SP(_t) (_t)->md.context.uc_mcontext.gregs[USP]
+#define PR_NUM_GCREGS _JBLEN
#endif
-#define CONTEXT(_thread) (&(_thread)->md.context)
+#define CONTEXT(_thread) (&(_thread)->md.context)
#endif /* ! USE_SETJMP */
@@ -214,35 +214,35 @@ NSPR_API(void) _MD_SolarisInit();
#define GETTIME(tt) clock_gettime(CLOCK_REALTIME, (tt))
#endif /* i386 */
-#define _MD_SAVE_ERRNO(_thread) (_thread)->md.errcode = errno;
-#define _MD_RESTORE_ERRNO(_thread) errno = (_thread)->md.errcode;
+#define _MD_SAVE_ERRNO(_thread) (_thread)->md.errcode = errno;
+#define _MD_RESTORE_ERRNO(_thread) errno = (_thread)->md.errcode;
#ifdef sparc
#ifdef USE_SETJMP
-#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
- PR_BEGIN_MACRO \
- int *context = (_thread)->md.context; \
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
+ PR_BEGIN_MACRO \
+ int *context = (_thread)->md.context; \
*status = PR_TRUE; \
- (void) setjmp(context); \
- (_thread)->md.context[1] = (int) ((_sp) - 64); \
- (_thread)->md.context[2] = (int) _main; \
- (_thread)->md.context[3] = (int) _main + 4; \
+ (void) setjmp(context); \
+ (_thread)->md.context[1] = (int) ((_sp) - 64); \
+ (_thread)->md.context[2] = (int) _main; \
+ (_thread)->md.context[3] = (int) _main + 4; \
_thread->no_sched = 0; \
PR_END_MACRO
#define _MD_SWITCH_CONTEXT(_thread) \
if (!setjmp(CONTEXT(_thread))) { \
- _MD_SAVE_ERRNO(_thread) \
- _MD_SET_LAST_THREAD(_thread); \
- _MD_SET_CURRENT_THREAD(_thread); \
- _PR_Schedule(); \
+ _MD_SAVE_ERRNO(_thread) \
+ _MD_SET_LAST_THREAD(_thread); \
+ _MD_SET_CURRENT_THREAD(_thread); \
+ _PR_Schedule(); \
}
-#define _MD_RESTORE_CONTEXT(_newThread) \
-{ \
- _MD_RESTORE_ERRNO(_newThread) \
- _MD_SET_CURRENT_THREAD(_newThread); \
+#define _MD_RESTORE_CONTEXT(_newThread) \
+{ \
+ _MD_RESTORE_ERRNO(_newThread) \
+ _MD_SET_CURRENT_THREAD(_newThread); \
longjmp(CONTEXT(_newThread), 1); \
}
@@ -250,19 +250,19 @@ NSPR_API(void) _MD_SolarisInit();
/*
** Initialize the thread context preparing it to execute _main.
*/
-#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
- PR_BEGIN_MACRO \
- ucontext_t *uc = CONTEXT(_thread); \
- *status = PR_TRUE; \
- getcontext(uc); \
- uc->uc_stack.ss_sp = (char *) ((unsigned long)(_sp - WINDOWSIZE - SA(MINFRAME)) & 0xfffffff8); \
- uc->uc_stack.ss_size = _thread->stack->stackSize; \
- uc->uc_stack.ss_flags = 0; /* ? */ \
- uc->uc_mcontext.gregs[REG_SP] = (unsigned int) uc->uc_stack.ss_sp; \
- uc->uc_mcontext.gregs[REG_PC] = (unsigned int) _main; \
- uc->uc_mcontext.gregs[REG_nPC] = (unsigned int) ((char*)_main)+4; \
- uc->uc_flags = UC_ALL; \
- _thread->no_sched = 0; \
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
+ PR_BEGIN_MACRO \
+ ucontext_t *uc = CONTEXT(_thread); \
+ *status = PR_TRUE; \
+ getcontext(uc); \
+ uc->uc_stack.ss_sp = (char *) ((unsigned long)(_sp - WINDOWSIZE - SA(MINFRAME)) & 0xfffffff8); \
+ uc->uc_stack.ss_size = _thread->stack->stackSize; \
+ uc->uc_stack.ss_flags = 0; /* ? */ \
+ uc->uc_mcontext.gregs[REG_SP] = (unsigned int) uc->uc_stack.ss_sp; \
+ uc->uc_mcontext.gregs[REG_PC] = (unsigned int) _main; \
+ uc->uc_mcontext.gregs[REG_nPC] = (unsigned int) ((char*)_main)+4; \
+ uc->uc_flags = UC_ALL; \
+ _thread->no_sched = 0; \
PR_END_MACRO
/*
@@ -270,26 +270,26 @@ NSPR_API(void) _MD_SolarisInit();
** calling the thread scheduler. Reload cpu when we come back from the
** context switch because it might have changed.
*/
-#define _MD_SWITCH_CONTEXT(_thread) \
- PR_BEGIN_MACRO \
- if (!getcontext(CONTEXT(_thread))) { \
- _MD_SAVE_ERRNO(_thread); \
- _MD_SET_LAST_THREAD(_thread); \
- _PR_Schedule(); \
- } \
+#define _MD_SWITCH_CONTEXT(_thread) \
+ PR_BEGIN_MACRO \
+ if (!getcontext(CONTEXT(_thread))) { \
+ _MD_SAVE_ERRNO(_thread); \
+ _MD_SET_LAST_THREAD(_thread); \
+ _PR_Schedule(); \
+ } \
PR_END_MACRO
/*
** Restore a thread context that was saved by _MD_SWITCH_CONTEXT or
** initialized by _MD_INIT_CONTEXT.
*/
-#define _MD_RESTORE_CONTEXT(_newThread) \
- PR_BEGIN_MACRO \
- ucontext_t *uc = CONTEXT(_newThread); \
- uc->uc_mcontext.gregs[11] = 1; \
- _MD_RESTORE_ERRNO(_newThread); \
- _MD_SET_CURRENT_THREAD(_newThread); \
- setcontext(uc); \
+#define _MD_RESTORE_CONTEXT(_newThread) \
+ PR_BEGIN_MACRO \
+ ucontext_t *uc = CONTEXT(_newThread); \
+ uc->uc_mcontext.gregs[11] = 1; \
+ _MD_RESTORE_ERRNO(_newThread); \
+ _MD_SET_CURRENT_THREAD(_newThread); \
+ setcontext(uc); \
PR_END_MACRO
#endif
@@ -307,7 +307,7 @@ NSPR_API(void) _MD_SolarisInit();
#define _MD_SWITCH_CONTEXT(_thread) \
if (!setjmp(CONTEXT(_thread))) { \
_MD_SAVE_ERRNO(_thread) \
- _PR_Schedule(); \
+ _PR_Schedule(); \
}
#define _MD_RESTORE_CONTEXT(_newThread) \
@@ -319,71 +319,71 @@ NSPR_API(void) _MD_SolarisInit();
#else /* USE_SETJMP */
-#define WINDOWSIZE 0
+#define WINDOWSIZE 0
int getedi(void);
void setedi(int);
-#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
- PR_BEGIN_MACRO \
- ucontext_t *uc = CONTEXT(_thread); \
+#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
+ PR_BEGIN_MACRO \
+ ucontext_t *uc = CONTEXT(_thread); \
*status = PR_TRUE; \
- getcontext(uc); \
- /* Force sp to be double aligned! */ \
- uc->uc_mcontext.gregs[USP] = (int) ((unsigned long)(_sp - WINDOWSIZE - SA(MINFRAME)) & 0xfffffff8); \
- uc->uc_mcontext.gregs[PC] = (int) _main; \
- (_thread)->no_sched = 0; \
- PR_END_MACRO
+ getcontext(uc); \
+ /* Force sp to be double aligned! */ \
+ uc->uc_mcontext.gregs[USP] = (int) ((unsigned long)(_sp - WINDOWSIZE - SA(MINFRAME)) & 0xfffffff8); \
+ uc->uc_mcontext.gregs[PC] = (int) _main; \
+ (_thread)->no_sched = 0; \
+ PR_END_MACRO
/* getcontext() may return 1, contrary to what the man page says */
-#define _MD_SWITCH_CONTEXT(_thread) \
- PR_BEGIN_MACRO \
- ucontext_t *uc = CONTEXT(_thread); \
- PR_ASSERT(_thread->no_sched); \
- sigfillset(&((_thread)->md.blockMask)); \
- sigprocmask(SIG_BLOCK, &((_thread)->md.blockMask), \
- &((_thread)->md.oldMask)); \
- (_thread)->md.edi = getedi(); \
- if (! getcontext(uc)) { \
- sigprocmask(SIG_SETMASK, &((_thread)->md.oldMask), NULL); \
- uc->uc_mcontext.gregs[EDI] = (_thread)->md.edi; \
- _MD_SAVE_ERRNO(_thread) \
- _MD_SET_LAST_THREAD(_thread); \
- _PR_Schedule(); \
- } else { \
- sigprocmask(SIG_SETMASK, &((_thread)->md.oldMask), NULL); \
- setedi((_thread)->md.edi); \
- PR_ASSERT(_MD_LAST_THREAD() !=_MD_CURRENT_THREAD()); \
- _MD_LAST_THREAD()->no_sched = 0; \
- } \
- PR_END_MACRO
+#define _MD_SWITCH_CONTEXT(_thread) \
+ PR_BEGIN_MACRO \
+ ucontext_t *uc = CONTEXT(_thread); \
+ PR_ASSERT(_thread->no_sched); \
+ sigfillset(&((_thread)->md.blockMask)); \
+ sigprocmask(SIG_BLOCK, &((_thread)->md.blockMask), \
+ &((_thread)->md.oldMask)); \
+ (_thread)->md.edi = getedi(); \
+ if (! getcontext(uc)) { \
+ sigprocmask(SIG_SETMASK, &((_thread)->md.oldMask), NULL); \
+ uc->uc_mcontext.gregs[EDI] = (_thread)->md.edi; \
+ _MD_SAVE_ERRNO(_thread) \
+ _MD_SET_LAST_THREAD(_thread); \
+ _PR_Schedule(); \
+ } else { \
+ sigprocmask(SIG_SETMASK, &((_thread)->md.oldMask), NULL); \
+ setedi((_thread)->md.edi); \
+ PR_ASSERT(_MD_LAST_THREAD() !=_MD_CURRENT_THREAD()); \
+ _MD_LAST_THREAD()->no_sched = 0; \
+ } \
+ PR_END_MACRO
/*
** Restore a thread context, saved by _PR_SWITCH_CONTEXT
*/
-#define _MD_RESTORE_CONTEXT(_newthread) \
- PR_BEGIN_MACRO \
- ucontext_t *uc = CONTEXT(_newthread); \
- uc->uc_mcontext.gregs[EAX] = 1; \
- _MD_RESTORE_ERRNO(_newthread) \
- _MD_SET_CURRENT_THREAD(_newthread); \
- (_newthread)->no_sched = 1; \
- setcontext(uc); \
- PR_END_MACRO
+#define _MD_RESTORE_CONTEXT(_newthread) \
+ PR_BEGIN_MACRO \
+ ucontext_t *uc = CONTEXT(_newthread); \
+ uc->uc_mcontext.gregs[EAX] = 1; \
+ _MD_RESTORE_ERRNO(_newthread) \
+ _MD_SET_CURRENT_THREAD(_newthread); \
+ (_newthread)->no_sched = 1; \
+ setcontext(uc); \
+ PR_END_MACRO
#endif /* USE_SETJMP */
#endif /* sparc */
struct _MDLock {
- PRInt8 notused;
+ PRInt8 notused;
};
struct _MDCVar {
- PRInt8 notused;
+ PRInt8 notused;
};
struct _MDSemaphore {
- PRInt8 notused;
+ PRInt8 notused;
};
struct _MDThread {
@@ -413,35 +413,35 @@ struct _MDCPU_Unix {
#ifndef _PR_USE_POLL
fd_set fd_read_set, fd_write_set, fd_exception_set;
PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
- fd_exception_cnt[_PR_MD_MAX_OSFD];
+ fd_exception_cnt[_PR_MD_MAX_OSFD];
#else
- struct pollfd *ioq_pollfds;
- int ioq_pollfds_size;
-#endif /* _PR_USE_POLL */
+ struct pollfd *ioq_pollfds;
+ int ioq_pollfds_size;
+#endif /* _PR_USE_POLL */
};
-#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
+#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
-#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
-#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
-#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
-#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
-#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
-#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
-#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
-#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
-#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
-#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
-#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
-
-#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
+#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
struct _MDCPU {
- struct _MDCPU_Unix md_unix;
+ struct _MDCPU_Unix md_unix;
};
#define _MD_INIT_LOCKS()
-#define _MD_NEW_LOCK(lock) PR_SUCCESS
+#define _MD_NEW_LOCK(lock) PR_SUCCESS
#define _MD_FREE_LOCK(lock)
#define _MD_LOCK(lock)
#define _MD_UNLOCK(lock)
@@ -449,8 +449,8 @@ struct _MDCPU {
#define _MD_IOQ_LOCK()
#define _MD_IOQ_UNLOCK()
-#define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
-#define _MD_INIT_THREAD _MD_InitializeThread
+#define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
+#define _MD_INIT_THREAD _MD_InitializeThread
#define _MD_EXIT_THREAD(thread)
#define _MD_SUSPEND_THREAD(thread)
#define _MD_RESUME_THREAD(thread)
@@ -461,15 +461,15 @@ extern PRStatus _MD_WAKEUP_WAITER(struct PRThread *);
extern void _MD_YIELD(void);
extern PRStatus _MD_InitializeThread(PRThread *thread);
extern void _MD_SET_PRIORITY(struct _MDThread *thread,
- PRThreadPriority newPri);
+ PRThreadPriority newPri);
extern PRStatus _MD_CREATE_THREAD(PRThread *thread, void (*start) (void *),
- PRThreadPriority priority, PRThreadScope scope, PRThreadState state,
- PRUint32 stackSize);
+ PRThreadPriority priority, PRThreadScope scope, PRThreadState state,
+ PRUint32 stackSize);
/* The following defines the unwrapped versions of select() and poll(). */
extern int _select(int nfds, fd_set *readfds, fd_set *writefds,
- fd_set *exceptfds, struct timeval *timeout);
-#define _MD_SELECT _select
+ fd_set *exceptfds, struct timeval *timeout);
+#define _MD_SELECT _select
#include <stropts.h>
#include <poll.h>
diff --git a/pr/include/md/_unix_errors.h b/pr/include/md/_unix_errors.h
index 96d72db0..0578fd02 100644
--- a/pr/include/md/_unix_errors.h
+++ b/pr/include/md/_unix_errors.h
@@ -12,115 +12,115 @@
PR_BEGIN_EXTERN_C
extern void _MD_unix_map_default_error(int err);
-#define _PR_MD_MAP_DEFAULT_ERROR _MD_unix_map_default_error
+#define _PR_MD_MAP_DEFAULT_ERROR _MD_unix_map_default_error
extern void _MD_unix_map_opendir_error(int err);
-#define _PR_MD_MAP_OPENDIR_ERROR _MD_unix_map_opendir_error
+#define _PR_MD_MAP_OPENDIR_ERROR _MD_unix_map_opendir_error
extern void _MD_unix_map_closedir_error(int err);
-#define _PR_MD_MAP_CLOSEDIR_ERROR _MD_unix_map_closedir_error
+#define _PR_MD_MAP_CLOSEDIR_ERROR _MD_unix_map_closedir_error
extern void _MD_unix_readdir_error(int err);
-#define _PR_MD_MAP_READDIR_ERROR _MD_unix_readdir_error
+#define _PR_MD_MAP_READDIR_ERROR _MD_unix_readdir_error
extern void _MD_unix_map_unlink_error(int err);
-#define _PR_MD_MAP_UNLINK_ERROR _MD_unix_map_unlink_error
+#define _PR_MD_MAP_UNLINK_ERROR _MD_unix_map_unlink_error
extern void _MD_unix_map_stat_error(int err);
-#define _PR_MD_MAP_STAT_ERROR _MD_unix_map_stat_error
+#define _PR_MD_MAP_STAT_ERROR _MD_unix_map_stat_error
extern void _MD_unix_map_fstat_error(int err);
-#define _PR_MD_MAP_FSTAT_ERROR _MD_unix_map_fstat_error
+#define _PR_MD_MAP_FSTAT_ERROR _MD_unix_map_fstat_error
extern void _MD_unix_map_rename_error(int err);
-#define _PR_MD_MAP_RENAME_ERROR _MD_unix_map_rename_error
+#define _PR_MD_MAP_RENAME_ERROR _MD_unix_map_rename_error
extern void _MD_unix_map_access_error(int err);
-#define _PR_MD_MAP_ACCESS_ERROR _MD_unix_map_access_error
+#define _PR_MD_MAP_ACCESS_ERROR _MD_unix_map_access_error
extern void _MD_unix_map_mkdir_error(int err);
-#define _PR_MD_MAP_MKDIR_ERROR _MD_unix_map_mkdir_error
+#define _PR_MD_MAP_MKDIR_ERROR _MD_unix_map_mkdir_error
extern void _MD_unix_map_rmdir_error(int err);
-#define _PR_MD_MAP_RMDIR_ERROR _MD_unix_map_rmdir_error
+#define _PR_MD_MAP_RMDIR_ERROR _MD_unix_map_rmdir_error
extern void _MD_unix_map_read_error(int err);
-#define _PR_MD_MAP_READ_ERROR _MD_unix_map_read_error
+#define _PR_MD_MAP_READ_ERROR _MD_unix_map_read_error
extern void _MD_unix_map_write_error(int err);
-#define _PR_MD_MAP_WRITE_ERROR _MD_unix_map_write_error
+#define _PR_MD_MAP_WRITE_ERROR _MD_unix_map_write_error
extern void _MD_unix_map_lseek_error(int err);
-#define _PR_MD_MAP_LSEEK_ERROR _MD_unix_map_lseek_error
+#define _PR_MD_MAP_LSEEK_ERROR _MD_unix_map_lseek_error
extern void _MD_unix_map_fsync_error(int err);
-#define _PR_MD_MAP_FSYNC_ERROR _MD_unix_map_fsync_error
+#define _PR_MD_MAP_FSYNC_ERROR _MD_unix_map_fsync_error
extern void _MD_unix_map_close_error(int err);
-#define _PR_MD_MAP_CLOSE_ERROR _MD_unix_map_close_error
+#define _PR_MD_MAP_CLOSE_ERROR _MD_unix_map_close_error
extern void _MD_unix_map_socket_error(int err);
-#define _PR_MD_MAP_SOCKET_ERROR _MD_unix_map_socket_error
+#define _PR_MD_MAP_SOCKET_ERROR _MD_unix_map_socket_error
extern void _MD_unix_map_socketavailable_error(int err);
-#define _PR_MD_MAP_SOCKETAVAILABLE_ERROR _MD_unix_map_socketavailable_error
+#define _PR_MD_MAP_SOCKETAVAILABLE_ERROR _MD_unix_map_socketavailable_error
extern void _MD_unix_map_recv_error(int err);
-#define _PR_MD_MAP_RECV_ERROR _MD_unix_map_recv_error
+#define _PR_MD_MAP_RECV_ERROR _MD_unix_map_recv_error
extern void _MD_unix_map_recvfrom_error(int err);
-#define _PR_MD_MAP_RECVFROM_ERROR _MD_unix_map_recvfrom_error
+#define _PR_MD_MAP_RECVFROM_ERROR _MD_unix_map_recvfrom_error
extern void _MD_unix_map_send_error(int err);
-#define _PR_MD_MAP_SEND_ERROR _MD_unix_map_send_error
+#define _PR_MD_MAP_SEND_ERROR _MD_unix_map_send_error
extern void _MD_unix_map_sendto_error(int err);
-#define _PR_MD_MAP_SENDTO_ERROR _MD_unix_map_sendto_error
+#define _PR_MD_MAP_SENDTO_ERROR _MD_unix_map_sendto_error
extern void _MD_unix_map_writev_error(int err);
-#define _PR_MD_MAP_WRITEV_ERROR _MD_unix_map_writev_error
+#define _PR_MD_MAP_WRITEV_ERROR _MD_unix_map_writev_error
extern void _MD_unix_map_accept_error(int err);
-#define _PR_MD_MAP_ACCEPT_ERROR _MD_unix_map_accept_error
+#define _PR_MD_MAP_ACCEPT_ERROR _MD_unix_map_accept_error
extern void _MD_unix_map_connect_error(int err);
-#define _PR_MD_MAP_CONNECT_ERROR _MD_unix_map_connect_error
+#define _PR_MD_MAP_CONNECT_ERROR _MD_unix_map_connect_error
extern void _MD_unix_map_bind_error(int err);
-#define _PR_MD_MAP_BIND_ERROR _MD_unix_map_bind_error
+#define _PR_MD_MAP_BIND_ERROR _MD_unix_map_bind_error
extern void _MD_unix_map_listen_error(int err);
-#define _PR_MD_MAP_LISTEN_ERROR _MD_unix_map_listen_error
+#define _PR_MD_MAP_LISTEN_ERROR _MD_unix_map_listen_error
extern void _MD_unix_map_shutdown_error(int err);
-#define _PR_MD_MAP_SHUTDOWN_ERROR _MD_unix_map_shutdown_error
+#define _PR_MD_MAP_SHUTDOWN_ERROR _MD_unix_map_shutdown_error
extern void _MD_unix_map_socketpair_error(int err);
-#define _PR_MD_MAP_SOCKETPAIR_ERROR _MD_unix_map_socketpair_error
+#define _PR_MD_MAP_SOCKETPAIR_ERROR _MD_unix_map_socketpair_error
extern void _MD_unix_map_getsockname_error(int err);
-#define _PR_MD_MAP_GETSOCKNAME_ERROR _MD_unix_map_getsockname_error
+#define _PR_MD_MAP_GETSOCKNAME_ERROR _MD_unix_map_getsockname_error
extern void _MD_unix_map_getpeername_error(int err);
-#define _PR_MD_MAP_GETPEERNAME_ERROR _MD_unix_map_getpeername_error
+#define _PR_MD_MAP_GETPEERNAME_ERROR _MD_unix_map_getpeername_error
extern void _MD_unix_map_getsockopt_error(int err);
-#define _PR_MD_MAP_GETSOCKOPT_ERROR _MD_unix_map_getsockopt_error
+#define _PR_MD_MAP_GETSOCKOPT_ERROR _MD_unix_map_getsockopt_error
extern void _MD_unix_map_setsockopt_error(int err);
-#define _PR_MD_MAP_SETSOCKOPT_ERROR _MD_unix_map_setsockopt_error
+#define _PR_MD_MAP_SETSOCKOPT_ERROR _MD_unix_map_setsockopt_error
extern void _MD_unix_map_open_error(int err);
-#define _PR_MD_MAP_OPEN_ERROR _MD_unix_map_open_error
+#define _PR_MD_MAP_OPEN_ERROR _MD_unix_map_open_error
extern void _MD_unix_map_mmap_error(int err);
-#define _PR_MD_MAP_MMAP_ERROR _MD_unix_map_mmap_error
+#define _PR_MD_MAP_MMAP_ERROR _MD_unix_map_mmap_error
extern void _MD_unix_map_gethostname_error(int err);
-#define _PR_MD_MAP_GETHOSTNAME_ERROR _MD_unix_map_gethostname_error
+#define _PR_MD_MAP_GETHOSTNAME_ERROR _MD_unix_map_gethostname_error
extern void _MD_unix_map_select_error(int err);
-#define _PR_MD_MAP_SELECT_ERROR _MD_unix_map_select_error
+#define _PR_MD_MAP_SELECT_ERROR _MD_unix_map_select_error
extern void _MD_unix_map_poll_error(int err);
#define _PR_MD_MAP_POLL_ERROR _MD_unix_map_poll_error
@@ -129,10 +129,10 @@ extern void _MD_unix_map_poll_revents_error(int err);
#define _PR_MD_MAP_POLL_REVENTS_ERROR _MD_unix_map_poll_revents_error
extern void _MD_unix_map_flock_error(int err);
-#define _PR_MD_MAP_FLOCK_ERROR _MD_unix_map_flock_error
+#define _PR_MD_MAP_FLOCK_ERROR _MD_unix_map_flock_error
extern void _MD_unix_map_lockf_error(int err);
-#define _PR_MD_MAP_LOCKF_ERROR _MD_unix_map_lockf_error
+#define _PR_MD_MAP_LOCKF_ERROR _MD_unix_map_lockf_error
PR_END_EXTERN_C
diff --git a/pr/include/md/_unixos.h b/pr/include/md/_unixos.h
index e0e5db11..7d444cda 100644
--- a/pr/include/md/_unixos.h
+++ b/pr/include/md/_unixos.h
@@ -54,10 +54,10 @@
#define _PR_HAVE_O_APPEND
-#define PR_DIRECTORY_SEPARATOR '/'
-#define PR_DIRECTORY_SEPARATOR_STR "/"
-#define PR_PATH_SEPARATOR ':'
-#define PR_PATH_SEPARATOR_STR ":"
+#define PR_DIRECTORY_SEPARATOR '/'
+#define PR_DIRECTORY_SEPARATOR_STR "/"
+#define PR_PATH_SEPARATOR ':'
+#define PR_PATH_SEPARATOR_STR ":"
typedef int (*FARPROC)();
/*
@@ -87,9 +87,9 @@ extern PRIntervalTime intr_timeout_ticks;
#endif /* _PR_USE_POLL */
typedef struct _PRUnixPollDesc {
- PRInt32 osfd;
- PRInt16 in_flags;
- PRInt16 out_flags;
+ PRInt32 osfd;
+ PRInt16 in_flags;
+ PRInt16 out_flags;
} _PRUnixPollDesc;
typedef struct PRPollQueue {
@@ -128,7 +128,7 @@ struct _MDFileDesc {
};
struct _MDDir {
- DIR *d;
+ DIR *d;
};
struct _PRCPU;
@@ -148,48 +148,48 @@ extern void _MD_unix_init_running_cpu(struct _PRCPU *cpu);
#if defined(DEBUG) && !defined(DARWIN)
#if !defined(SOLARIS)
#include <string.h> /* for memset() */
-#define _MD_INIT_STACK(ts,REDZONE) \
- PR_BEGIN_MACRO \
- (void) mprotect((void*)ts->seg->vaddr, REDZONE, PROT_NONE); \
- (void) mprotect((void*) ((char*)ts->seg->vaddr + REDZONE + ts->stackSize),\
- REDZONE, PROT_NONE); \
- /* \
- ** Fill stack memory with something that turns into an illegal \
- ** pointer value. This will sometimes find runtime references to \
- ** uninitialized pointers. We don't do this for solaris because we \
- ** can use purify instead. \
- */ \
- if (_pr_debugStacks) { \
- memset(ts->allocBase + REDZONE, 0xf7, ts->stackSize); \
- } \
+#define _MD_INIT_STACK(ts,REDZONE) \
+ PR_BEGIN_MACRO \
+ (void) mprotect((void*)ts->seg->vaddr, REDZONE, PROT_NONE); \
+ (void) mprotect((void*) ((char*)ts->seg->vaddr + REDZONE + ts->stackSize),\
+ REDZONE, PROT_NONE); \
+ /* \
+ ** Fill stack memory with something that turns into an illegal \
+ ** pointer value. This will sometimes find runtime references to \
+ ** uninitialized pointers. We don't do this for solaris because we \
+ ** can use purify instead. \
+ */ \
+ if (_pr_debugStacks) { \
+ memset(ts->allocBase + REDZONE, 0xf7, ts->stackSize); \
+ } \
PR_END_MACRO
-#else /* !SOLARIS */
-#define _MD_INIT_STACK(ts,REDZONE) \
- PR_BEGIN_MACRO \
- (void) mprotect((void*)ts->seg->vaddr, REDZONE, PROT_NONE); \
- (void) mprotect((void*) ((char*)ts->seg->vaddr + REDZONE + ts->stackSize),\
- REDZONE, PROT_NONE); \
+#else /* !SOLARIS */
+#define _MD_INIT_STACK(ts,REDZONE) \
+ PR_BEGIN_MACRO \
+ (void) mprotect((void*)ts->seg->vaddr, REDZONE, PROT_NONE); \
+ (void) mprotect((void*) ((char*)ts->seg->vaddr + REDZONE + ts->stackSize),\
+ REDZONE, PROT_NONE); \
PR_END_MACRO
-#endif /* !SOLARIS */
+#endif /* !SOLARIS */
/*
* _MD_CLEAR_STACK
- * Allow access to the redzone pages; the access was turned off in
- * _MD_INIT_STACK.
+ * Allow access to the redzone pages; the access was turned off in
+ * _MD_INIT_STACK.
*/
-#define _MD_CLEAR_STACK(ts) \
- PR_BEGIN_MACRO \
- (void) mprotect((void*)ts->seg->vaddr, REDZONE, PROT_READ|PROT_WRITE);\
- (void) mprotect((void*) ((char*)ts->seg->vaddr + REDZONE + ts->stackSize),\
- REDZONE, PROT_READ|PROT_WRITE); \
+#define _MD_CLEAR_STACK(ts) \
+ PR_BEGIN_MACRO \
+ (void) mprotect((void*)ts->seg->vaddr, REDZONE, PROT_READ|PROT_WRITE);\
+ (void) mprotect((void*) ((char*)ts->seg->vaddr + REDZONE + ts->stackSize),\
+ REDZONE, PROT_READ|PROT_WRITE); \
PR_END_MACRO
-#else /* DEBUG */
+#else /* DEBUG */
#define _MD_INIT_STACK(ts,REDZONE)
#define _MD_CLEAR_STACK(ts)
-#endif /* DEBUG */
+#endif /* DEBUG */
#if !defined(SOLARIS)
@@ -228,7 +228,7 @@ extern PRStatus _MD_DetachUnixProcess(struct PRProcess *process);
/* Wait for a child process to terminate */
#define _MD_WAIT_PROCESS _MD_WaitUnixProcess
extern PRStatus _MD_WaitUnixProcess(struct PRProcess *process,
- PRInt32 *exitCode);
+ PRInt32 *exitCode);
#define _MD_KILL_PROCESS _MD_KillUnixProcess
extern PRStatus _MD_KillUnixProcess(struct PRProcess *process);
@@ -238,53 +238,53 @@ extern PRStatus _MD_KillUnixProcess(struct PRProcess *process);
extern void _MD_EnableClockInterrupts(void);
extern void _MD_DisableClockInterrupts(void);
-#define _MD_START_INTERRUPTS _MD_StartInterrupts
-#define _MD_STOP_INTERRUPTS _MD_StopInterrupts
-#define _MD_DISABLE_CLOCK_INTERRUPTS _MD_DisableClockInterrupts
-#define _MD_ENABLE_CLOCK_INTERRUPTS _MD_EnableClockInterrupts
-#define _MD_BLOCK_CLOCK_INTERRUPTS _MD_BlockClockInterrupts
-#define _MD_UNBLOCK_CLOCK_INTERRUPTS _MD_UnblockClockInterrupts
+#define _MD_START_INTERRUPTS _MD_StartInterrupts
+#define _MD_STOP_INTERRUPTS _MD_StopInterrupts
+#define _MD_DISABLE_CLOCK_INTERRUPTS _MD_DisableClockInterrupts
+#define _MD_ENABLE_CLOCK_INTERRUPTS _MD_EnableClockInterrupts
+#define _MD_BLOCK_CLOCK_INTERRUPTS _MD_BlockClockInterrupts
+#define _MD_UNBLOCK_CLOCK_INTERRUPTS _MD_UnblockClockInterrupts
/************************************************************************/
-extern void _MD_InitCPUS(void);
+extern void _MD_InitCPUS(void);
#define _MD_INIT_CPUS _MD_InitCPUS
-extern void _MD_Wakeup_CPUs(void);
+extern void _MD_Wakeup_CPUs(void);
#define _MD_WAKEUP_CPUS _MD_Wakeup_CPUs
-#define _MD_PAUSE_CPU _MD_PauseCPU
+#define _MD_PAUSE_CPU _MD_PauseCPU
#if defined(_PR_LOCAL_THREADS_ONLY) || defined(_PR_GLOBAL_THREADS_ONLY)
#define _MD_CLEANUP_BEFORE_EXIT()
#endif
-#define _MD_EXIT(status) _exit(status)
+#define _MD_EXIT(status) _exit(status)
/************************************************************************/
-#define _MD_GET_ENV getenv
-#define _MD_PUT_ENV putenv
+#define _MD_GET_ENV getenv
+#define _MD_PUT_ENV putenv
/************************************************************************/
#define _MD_INIT_FILEDESC(fd)
-extern void _MD_MakeNonblock(PRFileDesc *fd);
-#define _MD_MAKE_NONBLOCK _MD_MakeNonblock
+extern void _MD_MakeNonblock(PRFileDesc *fd);
+#define _MD_MAKE_NONBLOCK _MD_MakeNonblock
/************************************************************************/
#if !defined(_PR_PTHREADS)
-extern void _MD_InitSegs(void);
-extern PRStatus _MD_AllocSegment(PRSegment *seg, PRUint32 size,
- void *vaddr);
-extern void _MD_FreeSegment(PRSegment *seg);
+extern void _MD_InitSegs(void);
+extern PRStatus _MD_AllocSegment(PRSegment *seg, PRUint32 size,
+ void *vaddr);
+extern void _MD_FreeSegment(PRSegment *seg);
-#define _MD_INIT_SEGS _MD_InitSegs
-#define _MD_ALLOC_SEGMENT _MD_AllocSegment
-#define _MD_FREE_SEGMENT _MD_FreeSegment
+#define _MD_INIT_SEGS _MD_InitSegs
+#define _MD_ALLOC_SEGMENT _MD_AllocSegment
+#define _MD_FREE_SEGMENT _MD_FreeSegment
#endif /* !defined(_PR_PTHREADS) */
@@ -294,25 +294,25 @@ extern void _MD_FreeSegment(PRSegment *seg);
extern PRIntervalTime _PR_UNIX_GetInterval(void);
extern PRIntervalTime _PR_UNIX_TicksPerSecond(void);
#define _MD_INTERVAL_INIT()
-#define _MD_GET_INTERVAL _PR_UNIX_GetInterval
-#define _MD_INTERVAL_PER_SEC _PR_UNIX_TicksPerSecond
+#define _MD_GET_INTERVAL _PR_UNIX_GetInterval
+#define _MD_INTERVAL_PER_SEC _PR_UNIX_TicksPerSecond
#endif
#ifdef _PR_HAVE_CLOCK_MONOTONIC
extern PRIntervalTime _PR_UNIX_GetInterval2(void);
extern PRIntervalTime _PR_UNIX_TicksPerSecond2(void);
#define _MD_INTERVAL_INIT()
-#define _MD_GET_INTERVAL _PR_UNIX_GetInterval2
-#define _MD_INTERVAL_PER_SEC _PR_UNIX_TicksPerSecond2
+#define _MD_GET_INTERVAL _PR_UNIX_GetInterval2
+#define _MD_INTERVAL_PER_SEC _PR_UNIX_TicksPerSecond2
#endif
-#define _MD_INTERVAL_PER_MILLISEC() (_PR_MD_INTERVAL_PER_SEC() / 1000)
-#define _MD_INTERVAL_PER_MICROSEC() (_PR_MD_INTERVAL_PER_SEC() / 1000000)
+#define _MD_INTERVAL_PER_MILLISEC() (_PR_MD_INTERVAL_PER_SEC() / 1000)
+#define _MD_INTERVAL_PER_MICROSEC() (_PR_MD_INTERVAL_PER_SEC() / 1000000)
/************************************************************************/
-#define _MD_ERRNO() (errno)
-#define _MD_GET_SOCKET_ERROR() (errno)
+#define _MD_ERRNO() (errno)
+#define _MD_GET_SOCKET_ERROR() (errno)
/************************************************************************/
@@ -329,125 +329,125 @@ extern PRStatus _MD_open_dir(struct _MDDir *, const char *);
extern PRInt32 _MD_close_dir(struct _MDDir *);
extern char * _MD_read_dir(struct _MDDir *, PRIntn);
extern PRInt32 _MD_open(const char *name, PRIntn osflags, PRIntn mode);
-extern PRInt32 _MD_delete(const char *name);
-extern PRInt32 _MD_getfileinfo(const char *fn, PRFileInfo *info);
+extern PRInt32 _MD_delete(const char *name);
+extern PRInt32 _MD_getfileinfo(const char *fn, PRFileInfo *info);
extern PRInt32 _MD_getfileinfo64(const char *fn, PRFileInfo64 *info);
extern PRInt32 _MD_getopenfileinfo(const PRFileDesc *fd, PRFileInfo *info);
extern PRInt32 _MD_getopenfileinfo64(const PRFileDesc *fd, PRFileInfo64 *info);
-extern PRInt32 _MD_rename(const char *from, const char *to);
-extern PRInt32 _MD_access(const char *name, PRAccessHow how);
-extern PRInt32 _MD_mkdir(const char *name, PRIntn mode);
-extern PRInt32 _MD_rmdir(const char *name);
-extern PRInt32 _MD_accept_read(PRInt32 sock, PRInt32 *newSock,
- PRNetAddr **raddr, void *buf, PRInt32 amount);
-extern PRInt32 _PR_UnixSendFile(PRFileDesc *sd, PRSendFileData *sfd,
- PRTransmitFileFlags flags, PRIntervalTime timeout);
+extern PRInt32 _MD_rename(const char *from, const char *to);
+extern PRInt32 _MD_access(const char *name, PRAccessHow how);
+extern PRInt32 _MD_mkdir(const char *name, PRIntn mode);
+extern PRInt32 _MD_rmdir(const char *name);
+extern PRInt32 _MD_accept_read(PRInt32 sock, PRInt32 *newSock,
+ PRNetAddr **raddr, void *buf, PRInt32 amount);
+extern PRInt32 _PR_UnixSendFile(PRFileDesc *sd, PRSendFileData *sfd,
+ PRTransmitFileFlags flags, PRIntervalTime timeout);
extern PRStatus _MD_LockFile(PRInt32 osfd);
extern PRStatus _MD_TLockFile(PRInt32 osfd);
extern PRStatus _MD_UnlockFile(PRInt32 osfd);
-#define _MD_OPEN_DIR(dir, name) _MD_open_dir(dir, name)
-#define _MD_CLOSE_DIR(dir) _MD_close_dir(dir)
-#define _MD_READ_DIR(dir, flags) _MD_read_dir(dir, flags)
-#define _MD_OPEN(name, osflags, mode) _MD_open(name, osflags, mode)
-#define _MD_OPEN_FILE(name, osflags, mode) _MD_open(name, osflags, mode)
+#define _MD_OPEN_DIR(dir, name) _MD_open_dir(dir, name)
+#define _MD_CLOSE_DIR(dir) _MD_close_dir(dir)
+#define _MD_READ_DIR(dir, flags) _MD_read_dir(dir, flags)
+#define _MD_OPEN(name, osflags, mode) _MD_open(name, osflags, mode)
+#define _MD_OPEN_FILE(name, osflags, mode) _MD_open(name, osflags, mode)
extern PRInt32 _MD_read(PRFileDesc *fd, void *buf, PRInt32 amount);
-#define _MD_READ(fd,buf,amount) _MD_read(fd,buf,amount)
+#define _MD_READ(fd,buf,amount) _MD_read(fd,buf,amount)
extern PRInt32 _MD_write(PRFileDesc *fd, const void *buf, PRInt32 amount);
-#define _MD_WRITE(fd,buf,amount) _MD_write(fd,buf,amount)
-#define _MD_DELETE(name) _MD_delete(name)
-#define _MD_GETFILEINFO(fn, info) _MD_getfileinfo(fn, info)
-#define _MD_GETFILEINFO64(fn, info) _MD_getfileinfo64(fn, info)
-#define _MD_GETOPENFILEINFO(fd, info) _MD_getopenfileinfo(fd, info)
-#define _MD_GETOPENFILEINFO64(fd, info) _MD_getopenfileinfo64(fd, info)
-#define _MD_RENAME(from, to) _MD_rename(from, to)
-#define _MD_ACCESS(name, how) _MD_access(name, how)
-#define _MD_MKDIR(name, mode) _MD_mkdir(name, mode)
-#define _MD_MAKE_DIR(name, mode) _MD_mkdir(name, mode)
-#define _MD_RMDIR(name) _MD_rmdir(name)
-#define _MD_ACCEPT_READ(sock, newSock, raddr, buf, amount) _MD_accept_read(sock, newSock, raddr, buf, amount)
+#define _MD_WRITE(fd,buf,amount) _MD_write(fd,buf,amount)
+#define _MD_DELETE(name) _MD_delete(name)
+#define _MD_GETFILEINFO(fn, info) _MD_getfileinfo(fn, info)
+#define _MD_GETFILEINFO64(fn, info) _MD_getfileinfo64(fn, info)
+#define _MD_GETOPENFILEINFO(fd, info) _MD_getopenfileinfo(fd, info)
+#define _MD_GETOPENFILEINFO64(fd, info) _MD_getopenfileinfo64(fd, info)
+#define _MD_RENAME(from, to) _MD_rename(from, to)
+#define _MD_ACCESS(name, how) _MD_access(name, how)
+#define _MD_MKDIR(name, mode) _MD_mkdir(name, mode)
+#define _MD_MAKE_DIR(name, mode) _MD_mkdir(name, mode)
+#define _MD_RMDIR(name) _MD_rmdir(name)
+#define _MD_ACCEPT_READ(sock, newSock, raddr, buf, amount) _MD_accept_read(sock, newSock, raddr, buf, amount)
#define _MD_LOCKFILE _MD_LockFile
#define _MD_TLOCKFILE _MD_TLockFile
#define _MD_UNLOCKFILE _MD_UnlockFile
-extern PRInt32 _MD_socket(int af, int type, int flags);
-#define _MD_SOCKET _MD_socket
-extern PRInt32 _MD_connect(PRFileDesc *fd, const PRNetAddr *addr,
- PRUint32 addrlen, PRIntervalTime timeout);
-#define _MD_CONNECT _MD_connect
-extern PRInt32 _MD_accept(PRFileDesc *fd, PRNetAddr *addr, PRUint32 *addrlen,
- PRIntervalTime timeout);
-#define _MD_ACCEPT _MD_accept
-extern PRInt32 _MD_bind(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen);
-#define _MD_BIND _MD_bind
-extern PRInt32 _MD_listen(PRFileDesc *fd, PRIntn backlog);
-#define _MD_LISTEN _MD_listen
-extern PRInt32 _MD_shutdown(PRFileDesc *fd, PRIntn how);
-#define _MD_SHUTDOWN _MD_shutdown
-
-extern PRInt32 _MD_recv(PRFileDesc *fd, void *buf, PRInt32 amount,
- PRIntn flags, PRIntervalTime timeout);
-#define _MD_RECV _MD_recv
-extern PRInt32 _MD_send(PRFileDesc *fd, const void *buf, PRInt32 amount,
- PRIntn flags, PRIntervalTime timeout);
-#define _MD_SEND _MD_send
-extern PRInt32 _MD_recvfrom(PRFileDesc *fd, void *buf, PRInt32 amount,
- PRIntn flags, PRNetAddr *addr, PRUint32 *addrlen,
- PRIntervalTime timeout);
-#define _MD_RECVFROM _MD_recvfrom
+extern PRInt32 _MD_socket(int af, int type, int flags);
+#define _MD_SOCKET _MD_socket
+extern PRInt32 _MD_connect(PRFileDesc *fd, const PRNetAddr *addr,
+ PRUint32 addrlen, PRIntervalTime timeout);
+#define _MD_CONNECT _MD_connect
+extern PRInt32 _MD_accept(PRFileDesc *fd, PRNetAddr *addr, PRUint32 *addrlen,
+ PRIntervalTime timeout);
+#define _MD_ACCEPT _MD_accept
+extern PRInt32 _MD_bind(PRFileDesc *fd, const PRNetAddr *addr, PRUint32 addrlen);
+#define _MD_BIND _MD_bind
+extern PRInt32 _MD_listen(PRFileDesc *fd, PRIntn backlog);
+#define _MD_LISTEN _MD_listen
+extern PRInt32 _MD_shutdown(PRFileDesc *fd, PRIntn how);
+#define _MD_SHUTDOWN _MD_shutdown
+
+extern PRInt32 _MD_recv(PRFileDesc *fd, void *buf, PRInt32 amount,
+ PRIntn flags, PRIntervalTime timeout);
+#define _MD_RECV _MD_recv
+extern PRInt32 _MD_send(PRFileDesc *fd, const void *buf, PRInt32 amount,
+ PRIntn flags, PRIntervalTime timeout);
+#define _MD_SEND _MD_send
+extern PRInt32 _MD_recvfrom(PRFileDesc *fd, void *buf, PRInt32 amount,
+ PRIntn flags, PRNetAddr *addr, PRUint32 *addrlen,
+ PRIntervalTime timeout);
+#define _MD_RECVFROM _MD_recvfrom
extern PRInt32 _MD_sendto(PRFileDesc *fd, const void *buf, PRInt32 amount,
- PRIntn flags, const PRNetAddr *addr, PRUint32 addrlen,
- PRIntervalTime timeout);
-#define _MD_SENDTO _MD_sendto
-extern PRInt32 _MD_writev(PRFileDesc *fd, const struct PRIOVec *iov,
- PRInt32 iov_size, PRIntervalTime timeout);
-#define _MD_WRITEV _MD_writev
+ PRIntn flags, const PRNetAddr *addr, PRUint32 addrlen,
+ PRIntervalTime timeout);
+#define _MD_SENDTO _MD_sendto
+extern PRInt32 _MD_writev(PRFileDesc *fd, const struct PRIOVec *iov,
+ PRInt32 iov_size, PRIntervalTime timeout);
+#define _MD_WRITEV _MD_writev
-extern PRInt32 _MD_socketavailable(PRFileDesc *fd);
-#define _MD_SOCKETAVAILABLE _MD_socketavailable
-extern PRInt64 _MD_socketavailable64(PRFileDesc *fd);
-#define _MD_SOCKETAVAILABLE64 _MD_socketavailable64
+extern PRInt32 _MD_socketavailable(PRFileDesc *fd);
+#define _MD_SOCKETAVAILABLE _MD_socketavailable
+extern PRInt64 _MD_socketavailable64(PRFileDesc *fd);
+#define _MD_SOCKETAVAILABLE64 _MD_socketavailable64
-#define _MD_PIPEAVAILABLE _MD_socketavailable
+#define _MD_PIPEAVAILABLE _MD_socketavailable
extern PRInt32 _MD_pr_poll(PRPollDesc *pds, PRIntn npds,
- PRIntervalTime timeout);
-#define _MD_PR_POLL _MD_pr_poll
-
-extern PRInt32 _MD_close(PRInt32 osfd);
-#define _MD_CLOSE_FILE _MD_close
-extern PRInt32 _MD_lseek(PRFileDesc*, PRInt32, PRSeekWhence);
-#define _MD_LSEEK _MD_lseek
-extern PRInt64 _MD_lseek64(PRFileDesc*, PRInt64, PRSeekWhence);
-#define _MD_LSEEK64 _MD_lseek64
-extern PRInt32 _MD_fsync(PRFileDesc *fd);
-#define _MD_FSYNC _MD_fsync
+ PRIntervalTime timeout);
+#define _MD_PR_POLL _MD_pr_poll
+
+extern PRInt32 _MD_close(PRInt32 osfd);
+#define _MD_CLOSE_FILE _MD_close
+extern PRInt32 _MD_lseek(PRFileDesc*, PRInt32, PRSeekWhence);
+#define _MD_LSEEK _MD_lseek
+extern PRInt64 _MD_lseek64(PRFileDesc*, PRInt64, PRSeekWhence);
+#define _MD_LSEEK64 _MD_lseek64
+extern PRInt32 _MD_fsync(PRFileDesc *fd);
+#define _MD_FSYNC _MD_fsync
extern PRInt32 _MD_socketpair(int af, int type, int flags, PRInt32 *osfd);
-#define _MD_SOCKETPAIR _MD_socketpair
+#define _MD_SOCKETPAIR _MD_socketpair
-#define _MD_CLOSE_SOCKET _MD_close
+#define _MD_CLOSE_SOCKET _MD_close
#ifndef NO_NSPR_10_SUPPORT
-#define _MD_STAT stat
+#define _MD_STAT stat
#endif
extern PRStatus _MD_getpeername(PRFileDesc *fd, PRNetAddr *addr,
- PRUint32 *addrlen);
+ PRUint32 *addrlen);
#define _MD_GETPEERNAME _MD_getpeername
extern PRStatus _MD_getsockname(PRFileDesc *fd, PRNetAddr *addr,
- PRUint32 *addrlen);
+ PRUint32 *addrlen);
#define _MD_GETSOCKNAME _MD_getsockname
extern PRStatus _MD_getsockopt(PRFileDesc *fd, PRInt32 level,
- PRInt32 optname, char* optval, PRInt32* optlen);
-#define _MD_GETSOCKOPT _MD_getsockopt
+ PRInt32 optname, char* optval, PRInt32* optlen);
+#define _MD_GETSOCKOPT _MD_getsockopt
extern PRStatus _MD_setsockopt(PRFileDesc *fd, PRInt32 level,
- PRInt32 optname, const char* optval, PRInt32 optlen);
-#define _MD_SETSOCKOPT _MD_setsockopt
+ PRInt32 optname, const char* optval, PRInt32 optlen);
+#define _MD_SETSOCKOPT _MD_setsockopt
extern PRStatus _MD_set_fd_inheritable(PRFileDesc *fd, PRBool inheritable);
#define _MD_SET_FD_INHERITABLE _MD_set_fd_inheritable
@@ -459,10 +459,10 @@ extern void _MD_query_fd_inheritable(PRFileDesc *fd);
#define _MD_QUERY_FD_INHERITABLE _MD_query_fd_inheritable
extern PRStatus _MD_gethostname(char *name, PRUint32 namelen);
-#define _MD_GETHOSTNAME _MD_gethostname
+#define _MD_GETHOSTNAME _MD_gethostname
extern PRStatus _MD_getsysinfo(PRSysInfo cmd, char *name, PRUint32 namelen);
-#define _MD_GETSYSINFO _MD_getsysinfo
+#define _MD_GETSYSINFO _MD_getsysinfo
extern int _MD_unix_get_nonblocking_connect_error(int osfd);
@@ -480,7 +480,7 @@ extern PRStatus _MD_CreateFileMap(struct PRFileMap *fmap, PRInt64 size);
#define _MD_GET_MEM_MAP_ALIGNMENT() PR_GetPageSize()
extern void * _MD_MemMap(struct PRFileMap *fmap, PRInt64 offset,
- PRUint32 len);
+ PRUint32 len);
#define _MD_MEM_MAP _MD_MemMap
extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size);
@@ -527,19 +527,19 @@ struct pollfd {
/* poll events */
-#define POLLIN 0x0001 /* fd is readable */
-#define POLLPRI 0x0002 /* high priority info at fd */
-#define POLLOUT 0x0004 /* fd is writeable (won't block) */
-#define POLLRDNORM 0x0040 /* normal data is readable */
-#define POLLWRNORM POLLOUT
-#define POLLRDBAND 0x0080 /* out-of-band data is readable */
-#define POLLWRBAND 0x0100 /* out-of-band data is writeable */
+#define POLLIN 0x0001 /* fd is readable */
+#define POLLPRI 0x0002 /* high priority info at fd */
+#define POLLOUT 0x0004 /* fd is writeable (won't block) */
+#define POLLRDNORM 0x0040 /* normal data is readable */
+#define POLLWRNORM POLLOUT
+#define POLLRDBAND 0x0080 /* out-of-band data is readable */
+#define POLLWRBAND 0x0100 /* out-of-band data is writeable */
-#define POLLNORM POLLRDNORM
+#define POLLNORM POLLRDNORM
-#define POLLERR 0x0008 /* fd has error condition */
-#define POLLHUP 0x0010 /* fd has been hung up on */
-#define POLLNVAL 0x0020 /* invalid pollfd entry */
+#define POLLERR 0x0008 /* fd has error condition */
+#define POLLHUP 0x0010 /* fd has been hung up on */
+#define POLLNVAL 0x0020 /* invalid pollfd entry */
extern int poll(struct pollfd *, unsigned long, int);
diff --git a/pr/include/md/_unixware.h b/pr/include/md/_unixware.h
index bebcd811..06667b29 100644
--- a/pr/include/md/_unixware.h
+++ b/pr/include/md/_unixware.h
@@ -10,18 +10,18 @@
* Internal configuration macros
*/
-#define PR_LINKER_ARCH "unixware"
-#define _PR_SI_SYSNAME "UnixWare"
-#define _PR_SI_ARCHITECTURE "x86"
-#define PR_DLL_SUFFIX ".so"
-
-#define _PR_VMBASE 0x30000000
-#define _PR_STACK_VMBASE 0x50000000
-#define _MD_DEFAULT_STACK_SIZE 65536L
+#define PR_LINKER_ARCH "unixware"
+#define _PR_SI_SYSNAME "UnixWare"
+#define _PR_SI_ARCHITECTURE "x86"
+#define PR_DLL_SUFFIX ".so"
+
+#define _PR_VMBASE 0x30000000
+#define _PR_STACK_VMBASE 0x50000000
+#define _MD_DEFAULT_STACK_SIZE 65536L
#define _MD_MMAP_FLAGS MAP_PRIVATE
-#ifndef HAVE_WEAK_IO_SYMBOLS
-#define HAVE_WEAK_IO_SYMBOLS
+#ifndef HAVE_WEAK_IO_SYMBOLS
+#define HAVE_WEAK_IO_SYMBOLS
#endif
#define _PR_POLL_AVAILABLE
#define _PR_USE_POLL
@@ -29,8 +29,8 @@
#undef HAVE_STACK_GROWING_UP
#define HAVE_NETCONFIG
-#define HAVE_DLL
-#define USE_DLFCN
+#define HAVE_DLL
+#define USE_DLFCN
#define HAVE_STRERROR
#define NEED_STRFTIME_LOCK
#define NEED_TIME_R
@@ -44,7 +44,7 @@
#define _LONGJMP longjmp
#define _PR_CONTEXT_TYPE jmp_buf
#define _MD_GET_SP(_t) (_t)->md.context[4]
-#define _PR_NUM_GCREGS _JBLEN
+#define _PR_NUM_GCREGS _JBLEN
#define CONTEXT(_th) ((_th)->md.context)
@@ -52,7 +52,7 @@
** Initialize the thread context preparing it to execute _main.
*/
#define _MD_INIT_CONTEXT(_thread, _sp, _main, status) \
-{ \
+{ \
*status = PR_TRUE; \
if(_SETJMP(CONTEXT(_thread))) (*_main)(); \
_MD_GET_SP(_thread) = (int) ((_sp) - 128); \
@@ -60,16 +60,16 @@
#define _MD_SWITCH_CONTEXT(_thread) \
if (!_SETJMP(CONTEXT(_thread))) { \
- (_thread)->md.errcode = errno; \
- _PR_Schedule(); \
+ (_thread)->md.errcode = errno; \
+ _PR_Schedule(); \
}
/*
** Restore a thread context, saved by _MD_SWITCH_CONTEXT
*/
#define _MD_RESTORE_CONTEXT(_thread) \
-{ \
- errno = (_thread)->md.errcode; \
+{ \
+ errno = (_thread)->md.errcode; \
_MD_SET_CURRENT_THREAD(_thread); \
_LONGJMP(CONTEXT(_thread), 1); \
}
@@ -117,31 +117,31 @@ struct _MDCPU_Unix {
#ifndef _PR_USE_POLL
fd_set fd_read_set, fd_write_set, fd_exception_set;
PRInt16 fd_read_cnt[_PR_MD_MAX_OSFD],fd_write_cnt[_PR_MD_MAX_OSFD],
- fd_exception_cnt[_PR_MD_MAX_OSFD];
+ fd_exception_cnt[_PR_MD_MAX_OSFD];
#else
- struct pollfd *ioq_pollfds;
- int ioq_pollfds_size;
-#endif /* _PR_USE_POLL */
+ struct pollfd *ioq_pollfds;
+ int ioq_pollfds_size;
+#endif /* _PR_USE_POLL */
};
-#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
+#define _PR_IOQ(_cpu) ((_cpu)->md.md_unix.ioQ)
#define _PR_ADD_TO_IOQ(_pq, _cpu) PR_APPEND_LINK(&_pq.links, &_PR_IOQ(_cpu))
-#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
-#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
-#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
-#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
-#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
-#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
-#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
-#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
-#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
-#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
-#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
-
-#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
+#define _PR_FD_READ_SET(_cpu) ((_cpu)->md.md_unix.fd_read_set)
+#define _PR_FD_READ_CNT(_cpu) ((_cpu)->md.md_unix.fd_read_cnt)
+#define _PR_FD_WRITE_SET(_cpu) ((_cpu)->md.md_unix.fd_write_set)
+#define _PR_FD_WRITE_CNT(_cpu) ((_cpu)->md.md_unix.fd_write_cnt)
+#define _PR_FD_EXCEPTION_SET(_cpu) ((_cpu)->md.md_unix.fd_exception_set)
+#define _PR_FD_EXCEPTION_CNT(_cpu) ((_cpu)->md.md_unix.fd_exception_cnt)
+#define _PR_IOQ_TIMEOUT(_cpu) ((_cpu)->md.md_unix.ioq_timeout)
+#define _PR_IOQ_MAX_OSFD(_cpu) ((_cpu)->md.md_unix.ioq_max_osfd)
+#define _PR_IOQ_OSFD_CNT(_cpu) ((_cpu)->md.md_unix.ioq_osfd_cnt)
+#define _PR_IOQ_POLLFDS(_cpu) ((_cpu)->md.md_unix.ioq_pollfds)
+#define _PR_IOQ_POLLFDS_SIZE(_cpu) ((_cpu)->md.md_unix.ioq_pollfds_size)
+
+#define _PR_IOQ_MIN_POLLFDS_SIZE(_cpu) 32
struct _MDCPU {
- struct _MDCPU_Unix md_unix;
+ struct _MDCPU_Unix md_unix;
};
#define _MD_INIT_LOCKS()
@@ -160,13 +160,13 @@ struct _MDCPU {
*/
#define _MD_INTERVAL_USE_GTOD
-#define _MD_EARLY_INIT _MD_EarlyInit
-#define _MD_FINAL_INIT _PR_UnixInit
+#define _MD_EARLY_INIT _MD_EarlyInit
+#define _MD_FINAL_INIT _PR_UnixInit
#define _MD_INIT_RUNNING_CPU(cpu) _MD_unix_init_running_cpu(cpu)
#define _MD_INIT_THREAD _MD_InitializeThread
#define _MD_EXIT_THREAD(thread)
-#define _MD_SUSPEND_THREAD(thread)
-#define _MD_RESUME_THREAD(thread)
+#define _MD_SUSPEND_THREAD(thread)
+#define _MD_RESUME_THREAD(thread)
#define _MD_CLEAN_THREAD(_thread)
/*
@@ -177,7 +177,7 @@ struct _MDCPU {
#include <sys/types.h>
#include <sys/select.h>
extern int _select(int nfds, fd_set *readfds, fd_set *writefds,
- fd_set *execptfds, struct timeval *timeout);
+ fd_set *execptfds, struct timeval *timeout);
#define _MD_SELECT _select
#define _MD_POLL _poll
diff --git a/pr/include/md/_win32_errors.h b/pr/include/md/_win32_errors.h
index 173f6b39..d267d8a2 100644
--- a/pr/include/md/_win32_errors.h
+++ b/pr/include/md/_win32_errors.h
@@ -12,109 +12,109 @@
extern void _MD_win32_map_default_error(PRInt32 err);
-#define _PR_MD_MAP_DEFAULT_ERROR _MD_win32_map_default_error
+#define _PR_MD_MAP_DEFAULT_ERROR _MD_win32_map_default_error
extern void _MD_win32_map_opendir_error(PRInt32 err);
-#define _PR_MD_MAP_OPENDIR_ERROR _MD_win32_map_opendir_error
+#define _PR_MD_MAP_OPENDIR_ERROR _MD_win32_map_opendir_error
extern void _MD_win32_map_closedir_error(PRInt32 err);
-#define _PR_MD_MAP_CLOSEDIR_ERROR _MD_win32_map_closedir_error
+#define _PR_MD_MAP_CLOSEDIR_ERROR _MD_win32_map_closedir_error
extern void _MD_unix_readdir_error(PRInt32 err);
-#define _PR_MD_MAP_READDIR_ERROR _MD_unix_readdir_error
+#define _PR_MD_MAP_READDIR_ERROR _MD_unix_readdir_error
extern void _MD_win32_map_delete_error(PRInt32 err);
-#define _PR_MD_MAP_DELETE_ERROR _MD_win32_map_delete_error
+#define _PR_MD_MAP_DELETE_ERROR _MD_win32_map_delete_error
extern void _MD_win32_map_stat_error(PRInt32 err);
-#define _PR_MD_MAP_STAT_ERROR _MD_win32_map_stat_error
+#define _PR_MD_MAP_STAT_ERROR _MD_win32_map_stat_error
extern void _MD_win32_map_fstat_error(PRInt32 err);
-#define _PR_MD_MAP_FSTAT_ERROR _MD_win32_map_fstat_error
+#define _PR_MD_MAP_FSTAT_ERROR _MD_win32_map_fstat_error
extern void _MD_win32_map_rename_error(PRInt32 err);
-#define _PR_MD_MAP_RENAME_ERROR _MD_win32_map_rename_error
+#define _PR_MD_MAP_RENAME_ERROR _MD_win32_map_rename_error
extern void _MD_win32_map_access_error(PRInt32 err);
-#define _PR_MD_MAP_ACCESS_ERROR _MD_win32_map_access_error
+#define _PR_MD_MAP_ACCESS_ERROR _MD_win32_map_access_error
extern void _MD_win32_map_mkdir_error(PRInt32 err);
-#define _PR_MD_MAP_MKDIR_ERROR _MD_win32_map_mkdir_error
+#define _PR_MD_MAP_MKDIR_ERROR _MD_win32_map_mkdir_error
extern void _MD_win32_map_rmdir_error(PRInt32 err);
-#define _PR_MD_MAP_RMDIR_ERROR _MD_win32_map_rmdir_error
+#define _PR_MD_MAP_RMDIR_ERROR _MD_win32_map_rmdir_error
extern void _MD_win32_map_read_error(PRInt32 err);
-#define _PR_MD_MAP_READ_ERROR _MD_win32_map_read_error
+#define _PR_MD_MAP_READ_ERROR _MD_win32_map_read_error
extern void _MD_win32_map_transmitfile_error(PRInt32 err);
-#define _PR_MD_MAP_TRANSMITFILE_ERROR _MD_win32_map_transmitfile_error
+#define _PR_MD_MAP_TRANSMITFILE_ERROR _MD_win32_map_transmitfile_error
extern void _MD_win32_map_write_error(PRInt32 err);
-#define _PR_MD_MAP_WRITE_ERROR _MD_win32_map_write_error
+#define _PR_MD_MAP_WRITE_ERROR _MD_win32_map_write_error
extern void _MD_win32_map_lseek_error(PRInt32 err);
-#define _PR_MD_MAP_LSEEK_ERROR _MD_win32_map_lseek_error
+#define _PR_MD_MAP_LSEEK_ERROR _MD_win32_map_lseek_error
extern void _MD_win32_map_fsync_error(PRInt32 err);
-#define _PR_MD_MAP_FSYNC_ERROR _MD_win32_map_fsync_error
+#define _PR_MD_MAP_FSYNC_ERROR _MD_win32_map_fsync_error
extern void _MD_win32_map_close_error(PRInt32 err);
-#define _PR_MD_MAP_CLOSE_ERROR _MD_win32_map_close_error
+#define _PR_MD_MAP_CLOSE_ERROR _MD_win32_map_close_error
extern void _MD_win32_map_socket_error(PRInt32 err);
-#define _PR_MD_MAP_SOCKET_ERROR _MD_win32_map_socket_error
+#define _PR_MD_MAP_SOCKET_ERROR _MD_win32_map_socket_error
extern void _MD_win32_map_recv_error(PRInt32 err);
-#define _PR_MD_MAP_RECV_ERROR _MD_win32_map_recv_error
+#define _PR_MD_MAP_RECV_ERROR _MD_win32_map_recv_error
extern void _MD_win32_map_recvfrom_error(PRInt32 err);
-#define _PR_MD_MAP_RECVFROM_ERROR _MD_win32_map_recvfrom_error
+#define _PR_MD_MAP_RECVFROM_ERROR _MD_win32_map_recvfrom_error
extern void _MD_win32_map_send_error(PRInt32 err);
-#define _PR_MD_MAP_SEND_ERROR _MD_win32_map_send_error
+#define _PR_MD_MAP_SEND_ERROR _MD_win32_map_send_error
extern void _MD_win32_map_sendto_error(PRInt32 err);
-#define _PR_MD_MAP_SENDTO_ERROR _MD_win32_map_sendto_error
+#define _PR_MD_MAP_SENDTO_ERROR _MD_win32_map_sendto_error
extern void _MD_win32_map_accept_error(PRInt32 err);
-#define _PR_MD_MAP_ACCEPT_ERROR _MD_win32_map_accept_error
+#define _PR_MD_MAP_ACCEPT_ERROR _MD_win32_map_accept_error
extern void _MD_win32_map_acceptex_error(PRInt32 err);
-#define _PR_MD_MAP_ACCEPTEX_ERROR _MD_win32_map_acceptex_error
+#define _PR_MD_MAP_ACCEPTEX_ERROR _MD_win32_map_acceptex_error
extern void _MD_win32_map_connect_error(PRInt32 err);
-#define _PR_MD_MAP_CONNECT_ERROR _MD_win32_map_connect_error
+#define _PR_MD_MAP_CONNECT_ERROR _MD_win32_map_connect_error
extern void _MD_win32_map_bind_error(PRInt32 err);
-#define _PR_MD_MAP_BIND_ERROR _MD_win32_map_bind_error
+#define _PR_MD_MAP_BIND_ERROR _MD_win32_map_bind_error
extern void _MD_win32_map_listen_error(PRInt32 err);
-#define _PR_MD_MAP_LISTEN_ERROR _MD_win32_map_listen_error
+#define _PR_MD_MAP_LISTEN_ERROR _MD_win32_map_listen_error
extern void _MD_win32_map_shutdown_error(PRInt32 err);
-#define _PR_MD_MAP_SHUTDOWN_ERROR _MD_win32_map_shutdown_error
+#define _PR_MD_MAP_SHUTDOWN_ERROR _MD_win32_map_shutdown_error
extern void _MD_win32_map_getsockname_error(PRInt32 err);
-#define _PR_MD_MAP_GETSOCKNAME_ERROR _MD_win32_map_getsockname_error
+#define _PR_MD_MAP_GETSOCKNAME_ERROR _MD_win32_map_getsockname_error
extern void _MD_win32_map_getpeername_error(PRInt32 err);
-#define _PR_MD_MAP_GETPEERNAME_ERROR _MD_win32_map_getpeername_error
+#define _PR_MD_MAP_GETPEERNAME_ERROR _MD_win32_map_getpeername_error
extern void _MD_win32_map_getsockopt_error(PRInt32 err);
-#define _PR_MD_MAP_GETSOCKOPT_ERROR _MD_win32_map_getsockopt_error
+#define _PR_MD_MAP_GETSOCKOPT_ERROR _MD_win32_map_getsockopt_error
extern void _MD_win32_map_setsockopt_error(PRInt32 err);
-#define _PR_MD_MAP_SETSOCKOPT_ERROR _MD_win32_map_setsockopt_error
+#define _PR_MD_MAP_SETSOCKOPT_ERROR _MD_win32_map_setsockopt_error
extern void _MD_win32_map_open_error(PRInt32 err);
-#define _PR_MD_MAP_OPEN_ERROR _MD_win32_map_open_error
+#define _PR_MD_MAP_OPEN_ERROR _MD_win32_map_open_error
extern void _MD_win32_map_gethostname_error(PRInt32 err);
-#define _PR_MD_MAP_GETHOSTNAME_ERROR _MD_win32_map_gethostname_error
+#define _PR_MD_MAP_GETHOSTNAME_ERROR _MD_win32_map_gethostname_error
extern void _MD_win32_map_select_error(PRInt32 err);
-#define _PR_MD_MAP_SELECT_ERROR _MD_win32_map_select_error
+#define _PR_MD_MAP_SELECT_ERROR _MD_win32_map_select_error
extern void _MD_win32_map_lockf_error(int err);
#define _PR_MD_MAP_LOCKF_ERROR _MD_win32_map_lockf_error
diff --git a/pr/include/md/_win95.h b/pr/include/md/_win95.h
index a4cb03a2..281cd6f0 100644
--- a/pr/include/md/_win95.h
+++ b/pr/include/md/_win95.h
@@ -84,14 +84,14 @@ extern struct PRLock *_pr_schedLock;
typedef void (*FiberFunc)(void *);
#define PR_NUM_GCREGS 8
-typedef PRInt32 PR_CONTEXT_TYPE[PR_NUM_GCREGS];
+typedef PRInt32 PR_CONTEXT_TYPE[PR_NUM_GCREGS];
#define GC_VMBASE 0x40000000
#define GC_VMLIMIT 0x00FFFFFF
-#define _MD_MAGIC_THREAD 0x22222222
-#define _MD_MAGIC_THREADSTACK 0x33333333
-#define _MD_MAGIC_SEGMENT 0x44444444
-#define _MD_MAGIC_DIR 0x55555555
+#define _MD_MAGIC_THREAD 0x22222222
+#define _MD_MAGIC_THREADSTACK 0x33333333
+#define _MD_MAGIC_SEGMENT 0x44444444
+#define _MD_MAGIC_DIR 0x55555555
#define _MD_MAGIC_CV 0x66666666
struct _MDCPU {
@@ -310,7 +310,7 @@ extern PRInt32 _MD_CloseSocket(PROsfd osfd);
#define _MD_INIT_ATOMIC()
#if defined(_M_IX86) || defined(_X86_)
#define _MD_ATOMIC_INCREMENT _PR_MD_ATOMIC_INCREMENT
-#define _MD_ATOMIC_ADD _PR_MD_ATOMIC_ADD
+#define _MD_ATOMIC_ADD _PR_MD_ATOMIC_ADD
#define _MD_ATOMIC_DECREMENT _PR_MD_ATOMIC_DECREMENT
#else /* non-x86 processors */
#define _MD_ATOMIC_INCREMENT(x) InterlockedIncrement((PLONG)x)
@@ -329,7 +329,7 @@ extern PRInt32 _MD_SocketAvailable(PRFileDesc *fd);
#define _MD_PIPEAVAILABLE _PR_MD_PIPEAVAILABLE
#define _MD_CONNECT _PR_MD_CONNECT
extern PROsfd _MD_Accept(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
- PRIntervalTime timeout);
+ PRIntervalTime timeout);
#define _MD_ACCEPT _MD_Accept
#define _MD_BIND _PR_MD_BIND
#define _MD_RECV _PR_MD_RECV
@@ -343,8 +343,8 @@ extern PROsfd _MD_Accept(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
/* --- DIR stuff --- */
#define PR_DIRECTORY_SEPARATOR '\\'
#define PR_DIRECTORY_SEPARATOR_STR "\\"
-#define PR_PATH_SEPARATOR ';'
-#define PR_PATH_SEPARATOR_STR ";"
+#define PR_PATH_SEPARATOR ';'
+#define PR_PATH_SEPARATOR_STR ";"
#define _MD_ERRNO() GetLastError()
#define _MD_OPEN_DIR _PR_MD_OPEN_DIR
#define _MD_CLOSE_DIR _PR_MD_CLOSE_DIR
@@ -396,13 +396,13 @@ extern PROsfd _MD_Accept(PRFileDesc *fd, PRNetAddr *raddr, PRUint32 *rlen,
#define _MD_WAKEUP_WAITER _PR_MD_WAKEUP_WAITER
/* --- CVar ------------------- */
-#define _MD_WAIT_CV _PR_MD_WAIT_CV
-#define _MD_NEW_CV _PR_MD_NEW_CV
-#define _MD_FREE_CV _PR_MD_FREE_CV
-#define _MD_NOTIFY_CV _PR_MD_NOTIFY_CV
-#define _MD_NOTIFYALL_CV _PR_MD_NOTIFYALL_CV
+#define _MD_WAIT_CV _PR_MD_WAIT_CV
+#define _MD_NEW_CV _PR_MD_NEW_CV
+#define _MD_FREE_CV _PR_MD_FREE_CV
+#define _MD_NOTIFY_CV _PR_MD_NOTIFY_CV
+#define _MD_NOTIFYALL_CV _PR_MD_NOTIFYALL_CV
- /* XXXMB- the IOQ stuff is certainly not working correctly yet. */
+/* XXXMB- the IOQ stuff is certainly not working correctly yet. */
// extern struct _MDLock _pr_ioq_lock;
#define _MD_IOQ_LOCK()
#define _MD_IOQ_UNLOCK()
@@ -438,7 +438,7 @@ extern PRStatus _PR_DetachWindowsProcess(struct PRProcess *process);
/* --- Wait for a child process to terminate --- */
#define _MD_WAIT_PROCESS _PR_WaitWindowsProcess
extern PRStatus _PR_WaitWindowsProcess(struct PRProcess *process,
- PRInt32 *exitCode);
+ PRInt32 *exitCode);
#define _MD_KILL_PROCESS _PR_KillWindowsProcess
extern PRStatus _PR_KillWindowsProcess(struct PRProcess *process);
@@ -499,7 +499,7 @@ extern DWORD _pr_currentCPUIndex;
/* --- Scheduler stuff --- */
#define LOCK_SCHEDULER() 0
#define UNLOCK_SCHEDULER() 0
-#define _PR_LockSched() 0
+#define _PR_LockSched() 0
#define _PR_UnlockSched() 0
/* --- Initialization stuff --- */
@@ -523,7 +523,7 @@ extern PRInt32 _MD_GetMemMapAlignment(void);
#define _MD_GET_MEM_MAP_ALIGNMENT _MD_GetMemMapAlignment
extern void * _MD_MemMap(struct PRFileMap *fmap, PRInt64 offset,
- PRUint32 len);
+ PRUint32 len);
#define _MD_MEM_MAP _MD_MemMap
extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size);
diff --git a/pr/include/md/_winnt.h b/pr/include/md/_winnt.h
index 5946ef7f..faed03ec 100644
--- a/pr/include/md/_winnt.h
+++ b/pr/include/md/_winnt.h
@@ -10,10 +10,10 @@
** setting _WIN32_WINNT to NT 4.0 for winsock.h, winbase.h, winnt.h.
*/
#ifndef _WIN32_WINNT
- #define _WIN32_WINNT 0x0400
+#define _WIN32_WINNT 0x0400
#elif (_WIN32_WINNT < 0x0400)
- #undef _WIN32_WINNT
- #define _WIN32_WINNT 0x0400
+#undef _WIN32_WINNT
+#define _WIN32_WINNT 0x0400
#endif /* _WIN32_WINNT */
#include <windows.h>
@@ -103,14 +103,14 @@ extern struct PRLock *_pr_schedLock;
typedef void (*FiberFunc)(void *);
#define PR_NUM_GCREGS 8
-typedef PRInt32 PR_CONTEXT_TYPE[PR_NUM_GCREGS];
+typedef PRInt32 PR_CONTEXT_TYPE[PR_NUM_GCREGS];
#define GC_VMBASE 0x40000000
#define GC_VMLIMIT 0x00FFFFFF
-#define _MD_MAGIC_THREAD 0x22222222
-#define _MD_MAGIC_THREADSTACK 0x33333333
-#define _MD_MAGIC_SEGMENT 0x44444444
-#define _MD_MAGIC_DIR 0x55555555
+#define _MD_MAGIC_THREAD 0x22222222
+#define _MD_MAGIC_THREADSTACK 0x33333333
+#define _MD_MAGIC_SEGMENT 0x44444444
+#define _MD_MAGIC_DIR 0x55555555
struct _MDCPU {
int unused;
@@ -146,7 +146,7 @@ typedef struct _MDOverlapped {
} _MDOverlapped;
struct _MDThread {
- /* The overlapped structure must be first! */
+ /* The overlapped structure must be first! */
struct _MDOverlapped overlapped; /* Used for async IO for this thread */
void *acceptex_buf; /* Used for AcceptEx() */
TRANSMIT_FILE_BUFFERS *xmit_bufs; /* Used for TransmitFile() */
@@ -161,10 +161,10 @@ struct _MDThread {
void *sp; /* only valid when suspended */
PRUint32 magic; /* for debugging */
PR_CONTEXT_TYPE gcContext; /* Thread context for GC */
- struct _PRCPU *thr_bound_cpu; /* thread bound to cpu */
- PRBool interrupt_disabled;/* thread cannot be interrupted */
- HANDLE thr_event; /* For native-threads-only support,
- thread blocks on this event */
+ struct _PRCPU *thr_bound_cpu; /* thread bound to cpu */
+ PRBool interrupt_disabled;/* thread cannot be interrupted */
+ HANDLE thr_event; /* For native-threads-only support,
+ thread blocks on this event */
/* The following are used only if this is a fiber */
void *fiber_id; /* flag whether or not this is a fiber*/
@@ -307,7 +307,7 @@ extern PRInt32 _PR_MD_CLOSE(PROsfd osfd, PRBool socket);
#define _MD_SETSOCKOPT _PR_MD_SETSOCKOPT
#define _MD_SELECT select
extern int _PR_NTFiberSafeSelect(int, fd_set *, fd_set *, fd_set *,
- const struct timeval *);
+ const struct timeval *);
#define _MD_FSYNC _PR_MD_FSYNC
#define _MD_SOCKETAVAILABLE _PR_MD_SOCKETAVAILABLE
#define _MD_PIPEAVAILABLE _PR_MD_PIPEAVAILABLE
@@ -316,7 +316,7 @@ extern int _PR_NTFiberSafeSelect(int, fd_set *, fd_set *, fd_set *,
#define _MD_INIT_ATOMIC()
#if defined(_M_IX86) || defined(_X86_)
#define _MD_ATOMIC_INCREMENT _PR_MD_ATOMIC_INCREMENT
-#define _MD_ATOMIC_ADD _PR_MD_ATOMIC_ADD
+#define _MD_ATOMIC_ADD _PR_MD_ATOMIC_ADD
#define _MD_ATOMIC_DECREMENT _PR_MD_ATOMIC_DECREMENT
#else /* non-x86 processors */
#define _MD_ATOMIC_INCREMENT(x) InterlockedIncrement((PLONG)x)
@@ -342,7 +342,7 @@ extern int _PR_NTFiberSafeSelect(int, fd_set *, fd_set *, fd_set *,
#define _MD_BIND _PR_MD_BIND
#define _MD_RECV _PR_MD_RECV
#define _MD_SEND _PR_MD_SEND
-#define _MD_SENDFILE _PR_MD_SENDFILE
+#define _MD_SENDFILE _PR_MD_SENDFILE
#define _MD_PR_POLL _PR_MD_PR_POLL
/* --- Scheduler stuff --- */
@@ -351,8 +351,8 @@ extern int _PR_NTFiberSafeSelect(int, fd_set *, fd_set *, fd_set *,
/* --- DIR stuff --- */
#define PR_DIRECTORY_SEPARATOR '\\'
#define PR_DIRECTORY_SEPARATOR_STR "\\"
-#define PR_PATH_SEPARATOR ';'
-#define PR_PATH_SEPARATOR_STR ";"
+#define PR_PATH_SEPARATOR ';'
+#define PR_PATH_SEPARATOR_STR ";"
#define _MD_ERRNO() GetLastError()
#define _MD_OPEN_DIR _PR_MD_OPEN_DIR
#define _MD_CLOSE_DIR _PR_MD_CLOSE_DIR
@@ -414,13 +414,13 @@ extern void _PR_Unblock_IO_Wait(PRThread *thr);
#define _MD_UNLOCK(lock) LeaveCriticalSection(&((lock)->mutex))
#endif
#define _PR_LOCK _MD_LOCK
-#define _PR_UNLOCK _MD_UNLOCK
+#define _PR_UNLOCK _MD_UNLOCK
/* --- lock and cv waiting --- */
#define _MD_WAIT _PR_MD_WAIT
#define _MD_WAKEUP_WAITER _PR_MD_WAKEUP_WAITER
- /* XXXMB- the IOQ stuff is certainly not working correctly yet. */
+/* XXXMB- the IOQ stuff is certainly not working correctly yet. */
extern struct _MDLock _pr_ioq_lock;
#define _MD_IOQ_LOCK() _MD_LOCK(&_pr_ioq_lock)
#define _MD_IOQ_UNLOCK() _MD_UNLOCK(&_pr_ioq_lock)
@@ -457,7 +457,7 @@ extern PRStatus _PR_DetachWindowsProcess(struct PRProcess *process);
/* --- Wait for a child process to terminate --- */
#define _MD_WAIT_PROCESS _PR_WaitWindowsProcess
extern PRStatus _PR_WaitWindowsProcess(struct PRProcess *process,
- PRInt32 *exitCode);
+ PRInt32 *exitCode);
#define _MD_KILL_PROCESS _PR_KillWindowsProcess
extern PRStatus _PR_KillWindowsProcess(struct PRProcess *process);
@@ -573,7 +573,7 @@ extern PRInt32 _MD_GetMemMapAlignment(void);
#define _MD_GET_MEM_MAP_ALIGNMENT _MD_GetMemMapAlignment
extern void * _MD_MemMap(struct PRFileMap *fmap, PRInt64 offset,
- PRUint32 len);
+ PRUint32 len);
#define _MD_MEM_MAP _MD_MemMap
extern PRStatus _MD_MemUnmap(void *addr, PRUint32 size);
diff --git a/pr/include/obsolete/pralarm.h b/pr/include/obsolete/pralarm.h
index f6b6035f..9ae3a4bc 100644
--- a/pr/include/obsolete/pralarm.h
+++ b/pr/include/obsolete/pralarm.h
@@ -4,8 +4,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
-** File: pralarm.h
-** Description: API to periodic alarms.
+** File: pralarm.h
+** Description: API to periodic alarms.
**
**
** Alarms are defined to invoke some client specified function at
@@ -153,7 +153,7 @@ NSPR_API(PRAlarmID*) PR_SetAlarm(
** ALGORITHM: See PR_SetAlarm().
***********************************************************************/
NSPR_API(PRStatus) PR_ResetAlarm(
- PRAlarmID *id, PRIntervalTime period, PRUint32 rate);
+ PRAlarmID *id, PRIntervalTime period, PRUint32 rate);
PR_END_EXTERN_C
diff --git a/pr/include/obsolete/protypes.h b/pr/include/obsolete/protypes.h
index 06791e13..5400afb2 100644
--- a/pr/include/obsolete/protypes.h
+++ b/pr/include/obsolete/protypes.h
@@ -126,9 +126,9 @@ typedef PRWord prword_t;
/* Re: prbit.h */
-#define TEST_BIT PR_TEST_BIT
-#define SET_BIT PR_SET_BIT
-#define CLEAR_BIT PR_CLEAR_BIT
+#define TEST_BIT PR_TEST_BIT
+#define SET_BIT PR_SET_BIT
+#define CLEAR_BIT PR_CLEAR_BIT
/* Re: prarena.h->plarena.h */
#define PRArena PLArena
diff --git a/pr/include/pratom.h b/pr/include/pratom.h
index dff9d6c0..11a8aaed 100644
--- a/pr/include/pratom.h
+++ b/pr/include/pratom.h
@@ -25,7 +25,7 @@ PR_BEGIN_EXTERN_C
** RETURN:
** the returned value is the result of the increment
*/
-NSPR_API(PRInt32) PR_AtomicIncrement(PRInt32 *val);
+NSPR_API(PRInt32) PR_AtomicIncrement(PRInt32 *val);
/*
** FUNCTION: PR_AtomicDecrement
@@ -36,7 +36,7 @@ NSPR_API(PRInt32) PR_AtomicIncrement(PRInt32 *val);
** RETURN:
** the returned value is the result of the decrement
*/
-NSPR_API(PRInt32) PR_AtomicDecrement(PRInt32 *val);
+NSPR_API(PRInt32) PR_AtomicDecrement(PRInt32 *val);
/*
** FUNCTION: PR_AtomicSet
@@ -56,11 +56,11 @@ NSPR_API(PRInt32) PR_AtomicSet(PRInt32 *val, PRInt32 newval);
** Atomically add a 32 bit value.
** INPUTS:
** ptr: a pointer to the value to increment
-** val: value to be added
+** val: value to be added
** RETURN:
** the returned value is the result of the addition
*/
-NSPR_API(PRInt32) PR_AtomicAdd(PRInt32 *ptr, PRInt32 val);
+NSPR_API(PRInt32) PR_AtomicAdd(PRInt32 *ptr, PRInt32 val);
/*
** MACRO: PR_ATOMIC_INCREMENT
@@ -137,8 +137,8 @@ NSPR_API(PRInt32) PR_AtomicAdd(PRInt32 *ptr, PRInt32 val);
typedef struct PRStackElemStr PRStackElem;
struct PRStackElemStr {
- PRStackElem *prstk_elem_next; /* next pointer MUST be at offset 0;
- assembly language code relies on this */
+ PRStackElem *prstk_elem_next; /* next pointer MUST be at offset 0;
+ assembly language code relies on this */
};
typedef struct PRStackStr PRStack;
@@ -152,46 +152,46 @@ typedef struct PRStackStr PRStack;
** RETURN:
** A pointer to the created stack, if successful, else NULL.
*/
-NSPR_API(PRStack *) PR_CreateStack(const char *stack_name);
+NSPR_API(PRStack *) PR_CreateStack(const char *stack_name);
/*
** FUNCTION: PR_StackPush
** DESCRIPTION:
** Push an element on the top of the stack
** INPUTS:
-** stack: pointer to the stack
-** stack_elem: pointer to the stack element
+** stack: pointer to the stack
+** stack_elem: pointer to the stack element
** RETURN:
** None
*/
-NSPR_API(void) PR_StackPush(PRStack *stack, PRStackElem *stack_elem);
+NSPR_API(void) PR_StackPush(PRStack *stack, PRStackElem *stack_elem);
/*
** FUNCTION: PR_StackPop
** DESCRIPTION:
** Remove the element on the top of the stack
** INPUTS:
-** stack: pointer to the stack
+** stack: pointer to the stack
** RETURN:
** A pointer to the stack element removed from the top of the stack,
-** if non-empty,
+** if non-empty,
** else NULL
*/
-NSPR_API(PRStackElem *) PR_StackPop(PRStack *stack);
+NSPR_API(PRStackElem *) PR_StackPop(PRStack *stack);
/*
** FUNCTION: PR_DestroyStack
** DESCRIPTION:
** Destroy the stack
** INPUTS:
-** stack: pointer to the stack
+** stack: pointer to the stack
** RETURN:
** PR_SUCCESS - if successfully deleted
-** PR_FAILURE - if the stack is not empty
-** PR_GetError will return
-** PR_INVALID_STATE_ERROR - stack is not empty
+** PR_FAILURE - if the stack is not empty
+** PR_GetError will return
+** PR_INVALID_STATE_ERROR - stack is not empty
*/
-NSPR_API(PRStatus) PR_DestroyStack(PRStack *stack);
+NSPR_API(PRStatus) PR_DestroyStack(PRStack *stack);
PR_END_EXTERN_C
diff --git a/pr/include/prbit.h b/pr/include/prbit.h
index 8a9f53cf..50c65923 100644
--- a/pr/include/prbit.h
+++ b/pr/include/prbit.h
@@ -18,18 +18,18 @@ PR_BEGIN_EXTERN_C
defined(_M_ARM64))
# include <intrin.h>
# pragma intrinsic(_BitScanForward,_BitScanReverse)
- __forceinline static int __prBitScanForward32(unsigned int val)
- {
+__forceinline static int __prBitScanForward32(unsigned int val)
+{
unsigned long idx;
_BitScanForward(&idx, (unsigned long)val);
return( (int)idx );
- }
- __forceinline static int __prBitScanReverse32(unsigned int val)
- {
+}
+__forceinline static int __prBitScanReverse32(unsigned int val)
+{
unsigned long idx;
_BitScanReverse(&idx, (unsigned long)val);
return( (int)(31-idx) );
- }
+}
# define pr_bitscan_ctz32(val) __prBitScanForward32(val)
# define pr_bitscan_clz32(val) __prBitScanReverse32(val)
# define PR_HAVE_BUILTIN_BITSCAN32
@@ -76,20 +76,20 @@ NSPR_API(PRIntn) PR_FloorLog2(PRUint32 i);
#else
#define PR_CEILING_LOG2(_log2,_n) \
PR_BEGIN_MACRO \
- PRUint32 j_ = (PRUint32)(_n); \
+ PRUint32 j_ = (PRUint32)(_n); \
(_log2) = 0; \
if ((j_) & ((j_)-1)) \
- (_log2) += 1; \
+ (_log2) += 1; \
if ((j_) >> 16) \
- (_log2) += 16, (j_) >>= 16; \
+ (_log2) += 16, (j_) >>= 16; \
if ((j_) >> 8) \
- (_log2) += 8, (j_) >>= 8; \
+ (_log2) += 8, (j_) >>= 8; \
if ((j_) >> 4) \
- (_log2) += 4, (j_) >>= 4; \
+ (_log2) += 4, (j_) >>= 4; \
if ((j_) >> 2) \
- (_log2) += 2, (j_) >>= 2; \
+ (_log2) += 2, (j_) >>= 2; \
if ((j_) >> 1) \
- (_log2) += 1; \
+ (_log2) += 1; \
PR_END_MACRO
#endif /* PR_HAVE_BUILTIN_BITSCAN32 */
@@ -108,18 +108,18 @@ NSPR_API(PRIntn) PR_FloorLog2(PRUint32 i);
#else
#define PR_FLOOR_LOG2(_log2,_n) \
PR_BEGIN_MACRO \
- PRUint32 j_ = (PRUint32)(_n); \
+ PRUint32 j_ = (PRUint32)(_n); \
(_log2) = 0; \
if ((j_) >> 16) \
- (_log2) += 16, (j_) >>= 16; \
+ (_log2) += 16, (j_) >>= 16; \
if ((j_) >> 8) \
- (_log2) += 8, (j_) >>= 8; \
+ (_log2) += 8, (j_) >>= 8; \
if ((j_) >> 4) \
- (_log2) += 4, (j_) >>= 4; \
+ (_log2) += 4, (j_) >>= 4; \
if ((j_) >> 2) \
- (_log2) += 2, (j_) >>= 2; \
+ (_log2) += 2, (j_) >>= 2; \
if ((j_) >> 1) \
- (_log2) += 1; \
+ (_log2) += 1; \
PR_END_MACRO
#endif /* PR_HAVE_BUILTIN_BITSCAN32 */
diff --git a/pr/include/prclist.h b/pr/include/prclist.h
index 23247228..a0691760 100644
--- a/pr/include/prclist.h
+++ b/pr/include/prclist.h
@@ -14,42 +14,42 @@ typedef struct PRCListStr PRCList;
** Circular linked list
*/
struct PRCListStr {
- PRCList *next;
- PRCList *prev;
+ PRCList *next;
+ PRCList *prev;
};
/*
** Insert element "_e" into the list, before "_l".
*/
-#define PR_INSERT_BEFORE(_e,_l) \
- PR_BEGIN_MACRO \
- (_e)->next = (_l); \
- (_e)->prev = (_l)->prev; \
- (_l)->prev->next = (_e); \
- (_l)->prev = (_e); \
+#define PR_INSERT_BEFORE(_e,_l) \
+ PR_BEGIN_MACRO \
+ (_e)->next = (_l); \
+ (_e)->prev = (_l)->prev; \
+ (_l)->prev->next = (_e); \
+ (_l)->prev = (_e); \
PR_END_MACRO
/*
** Insert element "_e" into the list, after "_l".
*/
-#define PR_INSERT_AFTER(_e,_l) \
- PR_BEGIN_MACRO \
- (_e)->next = (_l)->next; \
- (_e)->prev = (_l); \
- (_l)->next->prev = (_e); \
- (_l)->next = (_e); \
+#define PR_INSERT_AFTER(_e,_l) \
+ PR_BEGIN_MACRO \
+ (_e)->next = (_l)->next; \
+ (_e)->prev = (_l); \
+ (_l)->next->prev = (_e); \
+ (_l)->next = (_e); \
PR_END_MACRO
/*
** Return the element following element "_e"
*/
-#define PR_NEXT_LINK(_e) \
- ((_e)->next)
+#define PR_NEXT_LINK(_e) \
+ ((_e)->next)
/*
** Return the element preceding element "_e"
*/
-#define PR_PREV_LINK(_e) \
- ((_e)->prev)
+#define PR_PREV_LINK(_e) \
+ ((_e)->prev)
/*
** Append an element "_e" to the end of the list "_l"
@@ -68,10 +68,10 @@ struct PRCListStr {
/*
** Remove the element "_e" from it's circular list.
*/
-#define PR_REMOVE_LINK(_e) \
- PR_BEGIN_MACRO \
- (_e)->prev->next = (_e)->next; \
- (_e)->next->prev = (_e)->prev; \
+#define PR_REMOVE_LINK(_e) \
+ PR_BEGIN_MACRO \
+ (_e)->prev->next = (_e)->next; \
+ (_e)->next->prev = (_e)->prev; \
PR_END_MACRO
/*
@@ -79,11 +79,11 @@ struct PRCListStr {
** linkage.
*/
#define PR_REMOVE_AND_INIT_LINK(_e) \
- PR_BEGIN_MACRO \
- (_e)->prev->next = (_e)->next; \
- (_e)->next->prev = (_e)->prev; \
- (_e)->next = (_e); \
- (_e)->prev = (_e); \
+ PR_BEGIN_MACRO \
+ (_e)->prev->next = (_e)->next; \
+ (_e)->next->prev = (_e)->prev; \
+ (_e)->next = (_e); \
+ (_e)->prev = (_e); \
PR_END_MACRO
/*
@@ -97,9 +97,9 @@ struct PRCListStr {
** Initialize a circular list
*/
#define PR_INIT_CLIST(_l) \
- PR_BEGIN_MACRO \
- (_l)->next = (_l); \
- (_l)->prev = (_l); \
+ PR_BEGIN_MACRO \
+ (_l)->next = (_l); \
+ (_l)->prev = (_l); \
PR_END_MACRO
#define PR_INIT_STATIC_CLIST(_l) \
diff --git a/pr/include/prcountr.h b/pr/include/prcountr.h
index 5a134903..1503d06d 100644
--- a/pr/include/prcountr.h
+++ b/pr/include/prcountr.h
@@ -149,10 +149,10 @@ typedef void * PRCounterHandle;
#endif
NSPR_API(PRCounterHandle)
- PR_CreateCounter(
- const char *qName,
- const char *rName,
- const char *description
+PR_CreateCounter(
+ const char *qName,
+ const char *rName,
+ const char *description
);
/* -----------------------------------------------------------------------
@@ -179,8 +179,8 @@ NSPR_API(PRCounterHandle)
#endif
NSPR_API(void)
- PR_DestroyCounter(
- PRCounterHandle handle
+PR_DestroyCounter(
+ PRCounterHandle handle
);
@@ -212,9 +212,9 @@ NSPR_API(void)
#endif
NSPR_API(PRCounterHandle)
- PR_GetCounterHandleFromName(
- const char *qName,
- const char *rName
+PR_GetCounterHandleFromName(
+ const char *qName,
+ const char *rName
);
/* -----------------------------------------------------------------------
@@ -245,11 +245,11 @@ NSPR_API(PRCounterHandle)
#endif
NSPR_API(void)
- PR_GetCounterNameFromHandle(
- PRCounterHandle handle,
- const char **qName,
- const char **rName,
- const char **description
+PR_GetCounterNameFromHandle(
+ PRCounterHandle handle,
+ const char **qName,
+ const char **rName,
+ const char **description
);
@@ -276,8 +276,8 @@ NSPR_API(void)
#endif
NSPR_API(void)
- PR_IncrementCounter(
- PRCounterHandle handle
+PR_IncrementCounter(
+ PRCounterHandle handle
);
@@ -305,8 +305,8 @@ NSPR_API(void)
#endif
NSPR_API(void)
- PR_DecrementCounter(
- PRCounterHandle handle
+PR_DecrementCounter(
+ PRCounterHandle handle
);
/* -----------------------------------------------------------------------
@@ -334,9 +334,9 @@ NSPR_API(void)
#endif
NSPR_API(void)
- PR_AddToCounter(
- PRCounterHandle handle,
- PRUint32 value
+PR_AddToCounter(
+ PRCounterHandle handle,
+ PRUint32 value
);
@@ -368,9 +368,9 @@ NSPR_API(void)
#endif
NSPR_API(void)
- PR_SubtractFromCounter(
- PRCounterHandle handle,
- PRUint32 value
+PR_SubtractFromCounter(
+ PRCounterHandle handle,
+ PRUint32 value
);
@@ -398,8 +398,8 @@ NSPR_API(void)
#endif
NSPR_API(PRUint32)
- PR_GetCounter(
- PRCounterHandle handle
+PR_GetCounter(
+ PRCounterHandle handle
);
/* -----------------------------------------------------------------------
@@ -429,9 +429,9 @@ NSPR_API(PRUint32)
#endif
NSPR_API(void)
- PR_SetCounter(
- PRCounterHandle handle,
- PRUint32 value
+PR_SetCounter(
+ PRCounterHandle handle,
+ PRUint32 value
);
@@ -472,8 +472,8 @@ NSPR_API(void)
#endif
NSPR_API(PRCounterHandle)
- PR_FindNextCounterQname(
- PRCounterHandle handle
+PR_FindNextCounterQname(
+ PRCounterHandle handle
);
/* -----------------------------------------------------------------------
@@ -515,9 +515,9 @@ NSPR_API(PRCounterHandle)
#endif
NSPR_API(PRCounterHandle)
- PR_FindNextCounterRname(
- PRCounterHandle rhandle,
- PRCounterHandle qhandle
+PR_FindNextCounterRname(
+ PRCounterHandle rhandle,
+ PRCounterHandle qhandle
);
PR_END_EXTERN_C
diff --git a/pr/include/prcvar.h b/pr/include/prcvar.h
index 03ce2106..413a3646 100644
--- a/pr/include/prcvar.h
+++ b/pr/include/prcvar.h
@@ -16,7 +16,7 @@ typedef struct PRCondVar PRCondVar;
/*
** Create a new condition variable.
**
-** "lock" is the lock used to protect the 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.
diff --git a/pr/include/prdtoa.h b/pr/include/prdtoa.h
index 191b6c75..312a9d60 100644
--- a/pr/include/prdtoa.h
+++ b/pr/include/prdtoa.h
@@ -44,7 +44,7 @@ NSPR_API(void) PR_cnvtf(char *buf, PRIntn bufsz, PRIntn prcsn, PRFloat64 fval);
** and rounded to nearest.
*/
NSPR_API(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);
PR_END_EXTERN_C
diff --git a/pr/include/prerror.h b/pr/include/prerror.h
index bb3398d6..f445aa90 100644
--- a/pr/include/prerror.h
+++ b/pr/include/prerror.h
@@ -80,13 +80,13 @@ purpose. It is provided "as is" without express or implied warranty.
/*
* NOTE:
- * The interfaces for error-code-translation described in the rest of
- * this file are preliminary in the 3.1 release of nspr and are subject
- * to change in future releases.
+ * The interfaces for error-code-translation described in the rest of
+ * this file are preliminary in the 3.1 release of nspr and are subject
+ * to change in future releases.
*/
/*
-** Description: Localizable error code to string function.
+** Description: Localizable error code to string function.
**
**
** NSPR provides a mechanism for converting an error code to a
@@ -195,9 +195,9 @@ struct PRErrorCallbackTablePrivate;
*/
typedef const char *
PRErrorCallbackLookupFn(PRErrorCode code, PRLanguageCode language,
- const struct PRErrorTable *table,
- struct PRErrorCallbackPrivate *cb_private,
- struct PRErrorCallbackTablePrivate *table_private);
+ const struct PRErrorTable *table,
+ struct PRErrorCallbackPrivate *cb_private,
+ struct PRErrorCallbackTablePrivate *table_private);
/*
* PRErrorCallbackNewTableFn --
@@ -211,7 +211,7 @@ PRErrorCallbackLookupFn(PRErrorCode code, PRLanguageCode language,
*/
typedef struct PRErrorCallbackTablePrivate *
PRErrorCallbackNewTableFn(const struct PRErrorTable *table,
- struct PRErrorCallbackPrivate *cb_private);
+ struct PRErrorCallbackPrivate *cb_private);
/**********************************************************************/
/****************************** FUNCTIONS *****************************/
@@ -228,7 +228,7 @@ PRErrorCallbackNewTableFn(const struct PRErrorTable *table,
**
***********************************************************************/
NSPR_API(const char *) PR_ErrorToString(PRErrorCode code,
- PRLanguageCode language);
+ PRLanguageCode language);
/***********************************************************************
@@ -285,9 +285,9 @@ NSPR_API(PRErrorCode) PR_ErrorInstallTable(const struct PRErrorTable *table);
**
***********************************************************************/
NSPR_API(void) PR_ErrorInstallCallback(const char * const * languages,
- PRErrorCallbackLookupFn *lookup,
- PRErrorCallbackNewTableFn *newtable,
- struct PRErrorCallbackPrivate *cb_private);
+ PRErrorCallbackLookupFn *lookup,
+ PRErrorCallbackNewTableFn *newtable,
+ struct PRErrorCallbackPrivate *cb_private);
PR_END_EXTERN_C
diff --git a/pr/include/prinet.h b/pr/include/prinet.h
index 6ba5829f..b743ef63 100644
--- a/pr/include/prinet.h
+++ b/pr/include/prinet.h
@@ -4,7 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
- * File: prinet.h
+ * File: prinet.h
* Description:
* Header file used to find the system header files for socket support[1].
* This file serves the following purposes:
@@ -34,7 +34,7 @@
#if defined(XP_UNIX) || defined(XP_OS2)
#include <sys/types.h>
-#include <sys/socket.h> /* AF_INET */
+#include <sys/socket.h> /* AF_INET */
#include <netinet/in.h> /* INADDR_ANY, ..., ntohl(), ... */
#ifdef XP_OS2
#include <sys/ioctl.h>
diff --git a/pr/include/prinit.h b/pr/include/prinit.h
index d33c1011..a9327bc3 100644
--- a/pr/include/prinit.h
+++ b/pr/include/prinit.h
@@ -132,25 +132,25 @@ NSPR_API(PRStatus) PR_Cleanup(void);
/*
** Disable Interrupts
-** Disables timer signals used for pre-emptive scheduling.
+** Disables timer signals used for pre-emptive scheduling.
*/
NSPR_API(void) PR_DisableClockInterrupts(void);
/*
** Enables Interrupts
-** Enables timer signals used for pre-emptive scheduling.
+** Enables timer signals used for pre-emptive scheduling.
*/
NSPR_API(void) PR_EnableClockInterrupts(void);
/*
** Block Interrupts
-** Blocks the timer signal used for pre-emptive scheduling
+** Blocks the timer signal used for pre-emptive scheduling
*/
NSPR_API(void) PR_BlockClockInterrupts(void);
/*
** Unblock Interrupts
-** Unblocks the timer signal used for pre-emptive scheduling
+** Unblocks the timer signal used for pre-emptive scheduling
*/
NSPR_API(void) PR_UnblockClockInterrupts(void);
diff --git a/pr/include/prinrval.h b/pr/include/prinrval.h
index be22b838..7797291d 100644
--- a/pr/include/prinrval.h
+++ b/pr/include/prinrval.h
@@ -4,8 +4,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
-** File: prinrval.h
-** Description: API to interval timing functions of NSPR.
+** File: prinrval.h
+** Description: API to interval timing functions of NSPR.
**
**
** NSPR provides interval times that are independent of network time
diff --git a/pr/include/prio.h b/pr/include/prio.h
index 48694aad..d5cff257 100644
--- a/pr/include/prio.h
+++ b/pr/include/prio.h
@@ -54,7 +54,7 @@ struct PRFileDesc {
PRFilePrivate *secret; /* layer dependent data */
PRFileDesc *lower, *higher; /* pointers to adjacent layers */
void (PR_CALLBACK *dtor)(PRFileDesc *fd);
- /* A destructor function for layer */
+ /* A destructor function for layer */
PRDescIdentity identity; /* Identity of this particular layer */
};
@@ -128,17 +128,17 @@ typedef enum PRTransmitFileFlags {
*************************************************************************/
struct PRIPv6Addr {
- union {
- PRUint8 _S6_u8[16];
- PRUint16 _S6_u16[8];
- PRUint32 _S6_u32[4];
- PRUint64 _S6_u64[2];
- } _S6_un;
+ union {
+ PRUint8 _S6_u8[16];
+ PRUint16 _S6_u16[8];
+ PRUint32 _S6_u32[4];
+ PRUint64 _S6_u64[2];
+ } _S6_un;
};
-#define pr_s6_addr _S6_un._S6_u8
-#define pr_s6_addr16 _S6_un._S6_u16
-#define pr_s6_addr32 _S6_un._S6_u32
-#define pr_s6_addr64 _S6_un._S6_u64
+#define pr_s6_addr _S6_un._S6_u8
+#define pr_s6_addr16 _S6_un._S6_u16
+#define pr_s6_addr32 _S6_un._S6_u32
+#define pr_s6_addr64 _S6_un._S6_u64
typedef struct PRIPv6Addr PRIPv6Addr;
@@ -165,7 +165,7 @@ union PRNetAddr {
PRUint16 family; /* address family (AF_UNIX) */
#ifdef XP_OS2
char path[108]; /* null-terminated pathname */
- /* bind fails if size is not 108. */
+ /* bind fails if size is not 108. */
#else
char path[104]; /* null-terminated pathname */
#endif
@@ -209,13 +209,13 @@ typedef enum PRSockOption
} PRSockOption;
typedef struct PRLinger {
- PRBool polarity; /* Polarity of the option's setting */
- PRIntervalTime linger; /* Time to linger before closing */
+ PRBool polarity; /* Polarity of the option's setting */
+ PRIntervalTime linger; /* Time to linger before closing */
} PRLinger;
typedef struct PRMcastRequest {
- PRNetAddr mcaddr; /* IP multicast address of group */
- PRNetAddr ifaddr; /* local IP address of interface */
+ PRNetAddr mcaddr; /* IP multicast address of group */
+ PRNetAddr ifaddr; /* local IP address of interface */
} PRMcastRequest;
typedef struct PRSocketOptionData
@@ -333,8 +333,8 @@ typedef PRInt32 (PR_CALLBACK *PRAcceptreadFN)(
PRFileDesc *sd, PRFileDesc **nd, PRNetAddr **raddr,
void *buf, PRInt32 amount, PRIntervalTime t);
typedef PRInt32 (PR_CALLBACK *PRTransmitfileFN)(
- PRFileDesc *sd, PRFileDesc *fd, const void *headers,
- PRInt32 hlen, PRTransmitFileFlags flags, PRIntervalTime t);
+ PRFileDesc *sd, PRFileDesc *fd, const void *headers,
+ PRInt32 hlen, PRTransmitFileFlags flags, PRIntervalTime t);
typedef PRStatus (PR_CALLBACK *PRGetsocknameFN)(PRFileDesc *fd, PRNetAddr *addr);
typedef PRStatus (PR_CALLBACK *PRGetpeernameFN)(PRFileDesc *fd, PRNetAddr *addr);
typedef PRStatus (PR_CALLBACK *PRGetsocketoptionFN)(
@@ -342,8 +342,8 @@ typedef PRStatus (PR_CALLBACK *PRGetsocketoptionFN)(
typedef PRStatus (PR_CALLBACK *PRSetsocketoptionFN)(
PRFileDesc *fd, const PRSocketOptionData *data);
typedef PRInt32 (PR_CALLBACK *PRSendfileFN)(
- PRFileDesc *networkSocket, PRSendFileData *sendData,
- PRTransmitFileFlags flags, PRIntervalTime timeout);
+ PRFileDesc *networkSocket, PRSendFileData *sendData,
+ PRTransmitFileFlags flags, PRIntervalTime timeout);
typedef PRStatus (PR_CALLBACK *PRConnectcontinueFN)(
PRFileDesc *fd, PRInt16 out_flags);
typedef PRIntn (PR_CALLBACK *PRReservedFN)(PRFileDesc *fd);
@@ -378,16 +378,16 @@ struct PRIOMethods {
PRReservedFN reserved_fn_6; /* reserved for future use */
PRReservedFN reserved_fn_5; /* reserved for future use */
PRGetsocketoptionFN getsocketoption;
- /* Get current setting of specified option */
+ /* Get current setting of specified option */
PRSetsocketoptionFN setsocketoption;
- /* Set value of specified option */
- PRSendfileFN sendfile; /* Send a (partial) file with header/trailer*/
+ /* Set value of specified option */
+ PRSendfileFN sendfile; /* Send a (partial) file with header/trailer*/
PRConnectcontinueFN connectcontinue;
- /* Continue a nonblocking connect */
- PRReservedFN reserved_fn_3; /* reserved for future use */
- PRReservedFN reserved_fn_2; /* reserved for future use */
- PRReservedFN reserved_fn_1; /* reserved for future use */
- PRReservedFN reserved_fn_0; /* reserved for future use */
+ /* Continue a nonblocking connect */
+ PRReservedFN reserved_fn_3; /* reserved for future use */
+ PRReservedFN reserved_fn_2; /* reserved for future use */
+ PRReservedFN reserved_fn_1; /* reserved for future use */
+ PRReservedFN reserved_fn_0; /* reserved for future use */
};
/*
@@ -418,9 +418,9 @@ typedef enum PRSpecialFD
NSPR_API(PRFileDesc*) PR_GetSpecialFD(PRSpecialFD id);
-#define PR_STDIN PR_GetSpecialFD(PR_StandardInput)
-#define PR_STDOUT PR_GetSpecialFD(PR_StandardOutput)
-#define PR_STDERR PR_GetSpecialFD(PR_StandardError)
+#define PR_STDIN PR_GetSpecialFD(PR_StandardInput)
+#define PR_STDOUT PR_GetSpecialFD(PR_StandardOutput)
+#define PR_STDERR PR_GetSpecialFD(PR_StandardError)
/*
**************************************************************************
@@ -543,16 +543,16 @@ NSPR_API(PRFileDesc*) PR_PopIOLayer(PRFileDesc *fd_stack, PRDescIdentity id);
* The file status flags.
* It is a bitwise OR of the following bit flags (only one of
* the first three flags below may be used):
- * PR_RDONLY Open for reading only.
- * PR_WRONLY Open for writing only.
- * PR_RDWR Open for reading and writing.
- * PR_CREATE_FILE If the file does not exist, the file is created
+ * PR_RDONLY Open for reading only.
+ * PR_WRONLY Open for writing only.
+ * PR_RDWR Open for reading and writing.
+ * PR_CREATE_FILE If the file does not exist, the file is created
* If the file exists, this flag has no effect.
* PR_SYNC If set, each write will wait for both the file data
* and file status to be physically updated.
- * PR_APPEND The file pointer is set to the end of
+ * PR_APPEND The file pointer is set to the end of
* the file prior to each write.
- * PR_TRUNCATE If the file exists, its length is truncated to 0.
+ * PR_TRUNCATE If the file exists, its length is truncated to 0.
* PR_EXCL With PR_CREATE_FILE, if the file does not exist,
* the file is created. If the file already
* exists, no action and NULL is returned
@@ -974,7 +974,7 @@ NSPR_API(PRInt64) PR_Available64(PRFileDesc *fd);
************************************************************************
*/
-NSPR_API(PRStatus) PR_Sync(PRFileDesc *fd);
+NSPR_API(PRStatus) PR_Sync(PRFileDesc *fd);
/************************************************************************/
@@ -990,7 +990,7 @@ struct PRDirEntryUTF16 {
#endif /* MOZ_UNICODE */
#if !defined(NO_NSPR_10_SUPPORT)
-#define PR_DirName(dirEntry) (dirEntry->name)
+#define PR_DirName(dirEntry) (dirEntry->name)
#endif
/*
@@ -1444,7 +1444,7 @@ NSPR_API(PRStatus) PR_Shutdown(PRFileDesc *fd, PRShutdownHow how);
#define PR_MSG_PEEK 0x2
NSPR_API(PRInt32) PR_Recv(PRFileDesc *fd, void *buf, PRInt32 amount,
- PRIntn flags, PRIntervalTime timeout);
+ PRIntn flags, PRIntervalTime timeout);
/*
*************************************************************************
@@ -1475,7 +1475,7 @@ NSPR_API(PRInt32) PR_Recv(PRFileDesc *fd, void *buf, PRInt32 amount,
*/
NSPR_API(PRInt32) PR_Send(PRFileDesc *fd, const void *buf, PRInt32 amount,
- PRIntn flags, PRIntervalTime timeout);
+ PRIntn flags, PRIntervalTime timeout);
/*
*************************************************************************
@@ -1593,9 +1593,9 @@ NSPR_API(PRInt32) PR_TransmitFile(
** DESCRIPTION:
** PR_SendFile sends data from a file (sendData->fd) across a socket
** (networkSocket). If specified, a header and/or trailer buffer are sent
-** before and after the file, respectively. The file offset, number of bytes
-** of file data to send, the header and trailer buffers are specified in the
-** sendData argument.
+** before and after the file, respectively. The file offset, number of bytes
+** of file data to send, the header and trailer buffers are specified in the
+** sendData argument.
**
** Optionally, if the PR_TRANSMITFILE_CLOSE_SOCKET flag is passed, the
** socket is closed after successfully sending the data.
@@ -1605,7 +1605,7 @@ NSPR_API(PRInt32) PR_TransmitFile(
** The socket to send data over
** PRSendFileData *sendData
** Contains the FD, file offset and length, header and trailer
-** buffer specifications.
+** buffer specifications.
** PRTransmitFileFlags flags
** If the flags indicate that the connection should be closed,
** it will be done immediately after transferring the file, unless
@@ -1622,21 +1622,21 @@ NSPR_API(PRInt32) PR_TransmitFile(
*/
struct PRSendFileData {
- PRFileDesc *fd; /* file to send */
- PRUint32 file_offset; /* file offset */
- PRSize file_nbytes; /* number of bytes of file data to send */
- /* if 0, send data from file_offset to */
- /* end-of-file. */
- const void *header; /* header buffer */
- PRInt32 hlen; /* header len */
- const void *trailer; /* trailer buffer */
- PRInt32 tlen; /* trailer len */
+ PRFileDesc *fd; /* file to send */
+ PRUint32 file_offset; /* file offset */
+ PRSize file_nbytes; /* number of bytes of file data to send */
+ /* if 0, send data from file_offset to */
+ /* end-of-file. */
+ const void *header; /* header buffer */
+ PRInt32 hlen; /* header len */
+ const void *trailer; /* trailer buffer */
+ PRInt32 tlen; /* trailer len */
};
NSPR_API(PRInt32) PR_SendFile(
PRFileDesc *networkSocket, PRSendFileData *sendData,
- PRTransmitFileFlags flags, PRIntervalTime timeout);
+ PRTransmitFileFlags flags, PRIntervalTime timeout);
/*
*************************************************************************
@@ -1732,7 +1732,7 @@ NSPR_API(PRStatus) PR_NewTCPSocketPair(PRFileDesc *fds[2]);
** be obtained by calling PR_GetError().
**************************************************************************
**/
-NSPR_API(PRStatus) PR_GetSockName(PRFileDesc *fd, PRNetAddr *addr);
+NSPR_API(PRStatus) PR_GetSockName(PRFileDesc *fd, PRNetAddr *addr);
/*
*************************************************************************
@@ -1754,12 +1754,12 @@ NSPR_API(PRStatus) PR_GetSockName(PRFileDesc *fd, PRNetAddr *addr);
** be obtained by calling PR_GetError().
**************************************************************************
**/
-NSPR_API(PRStatus) PR_GetPeerName(PRFileDesc *fd, PRNetAddr *addr);
+NSPR_API(PRStatus) PR_GetPeerName(PRFileDesc *fd, PRNetAddr *addr);
-NSPR_API(PRStatus) PR_GetSocketOption(
+NSPR_API(PRStatus) PR_GetSocketOption(
PRFileDesc *fd, PRSocketOptionData *data);
-NSPR_API(PRStatus) PR_SetSocketOption(
+NSPR_API(PRStatus) PR_SetSocketOption(
PRFileDesc *fd, const PRSocketOptionData *data);
/*
diff --git a/pr/include/private/pprio.h b/pr/include/private/pprio.h
index d3e342cb..be8252b8 100644
--- a/pr/include/private/pprio.h
+++ b/pr/include/private/pprio.h
@@ -4,9 +4,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
-** File: pprio.h
+** File: pprio.h
**
-** Description: Private definitions for I/O related structures
+** Description: Private definitions for I/O related structures
*/
#ifndef pprio_h___
@@ -51,7 +51,7 @@ NSPR_API(const PRIOMethods*) PR_GetPipeMethods(void);
NSPR_API(PROsfd) PR_FileDesc2NativeHandle(PRFileDesc *);
NSPR_API(void) PR_ChangeFileDescNativeHandle(PRFileDesc *, PROsfd);
NSPR_API(PRFileDesc*) PR_AllocFileDesc(PROsfd osfd,
- const PRIOMethods *methods);
+ const PRIOMethods *methods);
NSPR_API(void) PR_FreeFileDesc(PRFileDesc *fd);
/*
** Import an existing OS file to NSPR.
@@ -67,7 +67,7 @@ NSPR_API(PRFileDesc*) PR_ImportUDPSocket(PROsfd osfd);
* FUNCTION: PR_CreateSocketPollFd
* DESCRIPTION:
* Create a PRFileDesc wrapper for a native socket handle, for use with
- * PR_Poll only
+ * PR_Poll only
* INPUTS:
* None
* OUTPUTS:
@@ -80,7 +80,7 @@ NSPR_API(PRFileDesc*) PR_ImportUDPSocket(PROsfd osfd);
**************************************************************************
*/
-NSPR_API(PRFileDesc*) PR_CreateSocketPollFd(PROsfd osfd);
+NSPR_API(PRFileDesc*) PR_CreateSocketPollFd(PROsfd osfd);
/*
*************************************************************************
@@ -93,7 +93,7 @@ NSPR_API(PRFileDesc*) PR_CreateSocketPollFd(PROsfd osfd);
* None
* RETURN: PRFileDesc*
* Upon successful completion, PR_DestroySocketPollFd returns
- * PR_SUCCESS, else PR_FAILURE
+ * PR_SUCCESS, else PR_FAILURE
*
**************************************************************************
*/
@@ -122,7 +122,7 @@ NSPR_API(PRStatus) PR_DestroySocketPollFd(PRFileDesc *fd);
/*
** Create a new Socket; this function is obsolete.
*/
-NSPR_API(PRFileDesc*) PR_Socket(PRInt32 domain, PRInt32 type, PRInt32 proto);
+NSPR_API(PRFileDesc*) PR_Socket(PRInt32 domain, PRInt32 type, PRInt32 proto);
/* FUNCTION: PR_LockFile
** DESCRIPTION:
@@ -157,7 +157,7 @@ NSPR_API(PRStatus) PR_UnlockFile(PRFileDesc *fd);
** Emulate acceptread by accept and recv.
*/
NSPR_API(PRInt32) PR_EmulateAcceptRead(PRFileDesc *sd, PRFileDesc **nd,
- PRNetAddr **raddr, void *buf, PRInt32 amount, PRIntervalTime timeout);
+ PRNetAddr **raddr, void *buf, PRInt32 amount, PRIntervalTime timeout);
/*
** Emulate sendfile by reading from the file and writing to the socket.
@@ -177,7 +177,7 @@ NSPR_API(PRInt32) PR_EmulateSendFile(
** updates the accept context. This version does not.
**/
NSPR_API(PRInt32) PR_NTFast_AcceptRead(PRFileDesc *sd, PRFileDesc **nd,
- PRNetAddr **raddr, void *buf, PRInt32 amount, PRIntervalTime t);
+ PRNetAddr **raddr, void *buf, PRInt32 amount, PRIntervalTime t);
typedef void (*_PR_AcceptTimeoutCallback)(void *);
@@ -196,14 +196,14 @@ typedef void (*_PR_AcceptTimeoutCallback)(void *);
** close the connection and return error.
*/
NSPR_API(PRInt32) PR_NTFast_AcceptRead_WithTimeoutCallback(
- PRFileDesc *sd,
- PRFileDesc **nd,
- PRNetAddr **raddr,
- void *buf,
- PRInt32 amount,
- PRIntervalTime t,
- _PR_AcceptTimeoutCallback callback,
- void *callback_arg);
+ PRFileDesc *sd,
+ PRFileDesc **nd,
+ PRNetAddr **raddr,
+ void *buf,
+ PRInt32 amount,
+ PRIntervalTime t,
+ _PR_AcceptTimeoutCallback callback,
+ void *callback_arg);
/* FUNCTION: PR_NTFast_Accept
** DESCRIPTION:
@@ -213,8 +213,8 @@ NSPR_API(PRInt32) PR_NTFast_AcceptRead_WithTimeoutCallback(
** the acceptcontext. The generic version of PR_Accept always
** updates the accept context. This version does not.
**/
-NSPR_API(PRFileDesc*) PR_NTFast_Accept(PRFileDesc *fd, PRNetAddr *addr,
- PRIntervalTime timeout);
+NSPR_API(PRFileDesc*) PR_NTFast_Accept(PRFileDesc *fd, PRNetAddr *addr,
+ PRIntervalTime timeout);
/* FUNCTION: PR_NTFast_Update
** DESCRIPTION:
@@ -225,7 +225,7 @@ NSPR_API(PRFileDesc*) PR_NTFast_Accept(PRFileDesc *fd, PRNetAddr *addr,
** Are PR_Read, PR_Write, PR_Transmitfile, and PR_Close.
*/
NSPR_API(void) PR_NTFast_UpdateAcceptContext(PRFileDesc *acceptSock,
- PRFileDesc *listenSock);
+ PRFileDesc *listenSock);
/* FUNCTION: PR_NT_CancelIo
diff --git a/pr/include/private/pprthred.h b/pr/include/private/pprthred.h
index 4b74faaf..e566d8ad 100644
--- a/pr/include/private/pprthred.h
+++ b/pr/include/private/pprthred.h
@@ -27,9 +27,9 @@ PR_BEGIN_EXTERN_C
/*
** Associate a thread object with an existing native thread.
-** "type" is the type of thread object to attach
-** "priority" is the priority to assign to the thread
-** "stack" defines the shape of the threads stack
+** "type" is the type of thread object to attach
+** "priority" is the priority to assign to the thread
+** "stack" defines the shape of the threads stack
**
** This can return NULL if some kind of error occurs, or if memory is
** tight. This call invokes "start(obj,arg)" and returns when the
@@ -39,8 +39,8 @@ PR_BEGIN_EXTERN_C
** thread. PR_Init does this automatically for the primordial thread.
*/
NSPR_API(PRThread*) PR_AttachThread(PRThreadType type,
- PRThreadPriority priority,
- PRThreadStack *stack);
+ PRThreadPriority priority,
+ PRThreadStack *stack);
/*
** Detach the nspr thread from the currently executing native thread.
@@ -120,20 +120,20 @@ NSPR_API(void) PR_SetThreadRecycleMode(PRUint32 flag);
** collectible.
*/
NSPR_API(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);
/*
** Same as PR_AttachThread except that the thread being attached is marked as
** garbage collectible.
*/
NSPR_API(PRThread*) PR_AttachThreadGCAble(PRThreadType type,
- PRThreadPriority priority,
- PRThreadStack *stack);
+ PRThreadPriority priority,
+ PRThreadStack *stack);
/*
** Mark the thread as garbage collectible.
@@ -206,7 +206,7 @@ NSPR_API(PRStatus) PR_EnumerateThreads(PREnumerator func, void *arg);
*/
typedef PRStatus
(PR_CALLBACK *PRScanStackFun)(PRThread* t,
- void** baseAddr, PRUword count, void* closure);
+ void** baseAddr, PRUword count, void* closure);
/*
** Applies scanFun to all contiguous groups of potential pointers
@@ -294,7 +294,7 @@ NSPR_API(void) PR_OS2_UnsetFloatExcpHandler(EXCEPTIONREGISTRATIONRECORD* e);
#endif /* XP_OS2 */
/* I think PR_GetMonitorEntryCount is useless. All you really want is this... */
-#define PR_InMonitor(m) (PR_GetMonitorEntryCount(m) > 0)
+#define PR_InMonitor(m) (PR_GetMonitorEntryCount(m) > 0)
/*---------------------------------------------------------------------------
** Special X-Lock hack for client
diff --git a/pr/include/private/primpl.h b/pr/include/private/primpl.h
index 3edd00e7..3f5a1504 100644
--- a/pr/include/private/primpl.h
+++ b/pr/include/private/primpl.h
@@ -145,12 +145,12 @@ struct _PT_Notified
#define PT_THREAD_FOREIGN 0x80 /* thread is not one of ours */
#define PT_THREAD_BOUND 0x100 /* a bound-global thread */
-#define _PT_THREAD_INTERRUPTED(thr) \
- (!(thr->interrupt_blocked) && (thr->state & PT_THREAD_ABORTED))
-#define _PT_THREAD_BLOCK_INTERRUPT(thr) \
- (thr->interrupt_blocked = 1)
-#define _PT_THREAD_UNBLOCK_INTERRUPT(thr) \
- (thr->interrupt_blocked = 0)
+#define _PT_THREAD_INTERRUPTED(thr) \
+ (!(thr->interrupt_blocked) && (thr->state & PT_THREAD_ABORTED))
+#define _PT_THREAD_BLOCK_INTERRUPT(thr) \
+ (thr->interrupt_blocked = 1)
+#define _PT_THREAD_UNBLOCK_INTERRUPT(thr) \
+ (thr->interrupt_blocked = 0)
#define _PT_IS_GCABLE_THREAD(thr) ((thr)->state & PT_THREAD_GCABLE)
@@ -561,7 +561,7 @@ NSPR_API(void) _PR_Notify(PRMonitor *mon, PRBool all, PRBool sticky);
#define _PR_IDLE_THREAD 0x200 /* this is an idle thread */
#define _PR_GCABLE_THREAD 0x400 /* this is a collectable thread */
#define _PR_BOUND_THREAD 0x800 /* a bound thread */
-#define _PR_INTERRUPT_BLOCKED 0x1000 /* interrupts blocked */
+#define _PR_INTERRUPT_BLOCKED 0x1000 /* interrupts blocked */
/* PRThread.state */
#define _PR_UNBORN 0
@@ -587,7 +587,7 @@ NSPR_API(void) _PR_Notify(PRMonitor *mon, PRBool all, PRBool sticky);
*/
#ifndef _MD_MINIMUM_STACK_SIZE
-#define _MD_MINIMUM_STACK_SIZE 0
+#define _MD_MINIMUM_STACK_SIZE 0
#endif
#if (!defined(HAVE_CUSTOM_USER_THREADS))
@@ -606,12 +606,12 @@ NSPR_API(void) _PR_Notify(PRMonitor *mon, PRBool all, PRBool sticky);
#define _PR_IS_GCABLE_THREAD(thr) ((thr)->flags & _PR_GCABLE_THREAD)
-#define _PR_PENDING_INTERRUPT(thr) \
- (!((thr)->flags & _PR_INTERRUPT_BLOCKED) && ((thr)->flags & _PR_INTERRUPT))
-#define _PR_THREAD_BLOCK_INTERRUPT(thr) \
- (thr->flags |= _PR_INTERRUPT_BLOCKED)
-#define _PR_THREAD_UNBLOCK_INTERRUPT(thr) \
- (thr->flags &= ~_PR_INTERRUPT_BLOCKED)
+#define _PR_PENDING_INTERRUPT(thr) \
+ (!((thr)->flags & _PR_INTERRUPT_BLOCKED) && ((thr)->flags & _PR_INTERRUPT))
+#define _PR_THREAD_BLOCK_INTERRUPT(thr) \
+ (thr->flags |= _PR_INTERRUPT_BLOCKED)
+#define _PR_THREAD_UNBLOCK_INTERRUPT(thr) \
+ (thr->flags &= ~_PR_INTERRUPT_BLOCKED)
#define _PR_THREAD_PTR(_qp) \
((PRThread*) ((char*) (_qp) - offsetof(PRThread,links)))
@@ -693,28 +693,28 @@ extern void _PR_SetThreadPriority(
PRThread* thread, PRThreadPriority priority);
/***********************************************************************
-** FUNCTION: _PR_NewSegment()
+** FUNCTION: _PR_NewSegment()
** DESCRIPTION:
** Allocate a memory segment. The "size" value is rounded up to the
** native system page size and a page aligned portion of memory is
** returned. This memory is not part of the malloc heap. If "vaddr" is
** not NULL then PR tries to allocate the segment at the desired virtual
** address.
-** INPUTS: size: size of the desired memory segment
+** INPUTS: size: size of the desired memory segment
** vaddr: address at which the newly aquired segment is to be
** mapped into memory.
-** OUTPUTS: a memory segment is allocated, a PRSegment is allocated
-** RETURN: pointer to PRSegment
+** OUTPUTS: a memory segment is allocated, a PRSegment is allocated
+** RETURN: pointer to PRSegment
***********************************************************************/
extern PRSegment* _PR_NewSegment(PRUint32 size, void *vaddr);
/***********************************************************************
-** FUNCTION: _PR_DestroySegment()
+** FUNCTION: _PR_DestroySegment()
** DESCRIPTION:
** The memory segment and the PRSegment are freed
-** INPUTS: seg: pointer to PRSegment to be freed
-** OUTPUTS: the the PRSegment and its associated memory segment are freed
-** RETURN: void
+** INPUTS: seg: pointer to PRSegment to be freed
+** OUTPUTS: the the PRSegment and its associated memory segment are freed
+** RETURN: void
***********************************************************************/
extern void _PR_DestroySegment(PRSegment *seg);
@@ -735,7 +735,7 @@ NSPR_API(PRThread*) _PR_CreateThread(PRThreadType type,
PRThreadScope scope,
PRThreadState state,
PRUint32 stackSize,
- PRUint32 flags);
+ PRUint32 flags);
extern void _PR_NativeDestroyThread(PRThread *thread);
extern void _PR_UserDestroyThread(PRThread *thread);
@@ -954,19 +954,19 @@ extern void _PR_MD_CREATE_PRIMORDIAL_USER_THREAD(PRThread *);
#define _PR_MD_CREATE_PRIMORDIAL_USER_THREAD _MD_CREATE_PRIMORDIAL_USER_THREAD
extern PRThread* _PR_MD_CREATE_USER_THREAD(
- PRUint32 stacksize,
- void (*start)(void *),
- void *arg);
+ PRUint32 stacksize,
+ void (*start)(void *),
+ void *arg);
#define _PR_MD_CREATE_USER_THREAD _MD_CREATE_USER_THREAD
#endif
extern PRStatus _PR_MD_CREATE_THREAD(
- PRThread *thread,
- void (*start) (void *),
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize);
+ PRThread *thread,
+ void (*start) (void *),
+ PRThreadPriority priority,
+ PRThreadScope scope,
+ PRThreadState state,
+ PRUint32 stackSize);
#define _PR_MD_CREATE_THREAD _MD_CREATE_THREAD
extern void _PR_MD_JOIN_THREAD(_MDThread *md);
@@ -1134,7 +1134,7 @@ extern PRInt32 _PR_MD_SHUTDOWN(PRFileDesc *fd, PRIntn how);
#define _PR_MD_SHUTDOWN _MD_SHUTDOWN
extern PRInt32 _PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount,
- PRIntn flags, PRIntervalTime timeout);
+ PRIntn flags, PRIntervalTime timeout);
#define _PR_MD_RECV _MD_RECV
extern PRInt32 _PR_MD_SEND(
@@ -1143,22 +1143,22 @@ extern PRInt32 _PR_MD_SEND(
#define _PR_MD_SEND _MD_SEND
extern PRInt32 _PR_MD_ACCEPT_READ(PRFileDesc *sd, PROsfd *newSock,
- PRNetAddr **raddr, void *buf, PRInt32 amount,
- PRIntervalTime timeout);
+ PRNetAddr **raddr, void *buf, PRInt32 amount,
+ PRIntervalTime timeout);
#define _PR_MD_ACCEPT_READ _MD_ACCEPT_READ
#ifdef WIN32
extern PROsfd _PR_MD_FAST_ACCEPT(PRFileDesc *fd, PRNetAddr *addr,
- PRUint32 *addrlen, PRIntervalTime timeout,
- PRBool fast,
- _PR_AcceptTimeoutCallback callback,
- void *callbackArg);
+ PRUint32 *addrlen, PRIntervalTime timeout,
+ PRBool fast,
+ _PR_AcceptTimeoutCallback callback,
+ void *callbackArg);
extern 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);
+ PRNetAddr **raddr, void *buf, PRInt32 amount,
+ PRIntervalTime timeout, PRBool fast,
+ _PR_AcceptTimeoutCallback callback,
+ void *callbackArg);
extern void _PR_MD_UPDATE_ACCEPT_CONTEXT(PROsfd s, PROsfd ls);
#define _PR_MD_UPDATE_ACCEPT_CONTEXT _MD_UPDATE_ACCEPT_CONTEXT
@@ -1173,7 +1173,7 @@ extern const PRTime _pr_filetime_offset;
extern PRInt32 _PR_MD_SENDFILE(
PRFileDesc *sock, PRSendFileData *sfd,
- PRInt32 flags, PRIntervalTime timeout);
+ PRInt32 flags, PRIntervalTime timeout);
#define _PR_MD_SENDFILE _MD_SENDFILE
extern PRStatus _PR_MD_GETSOCKNAME(
@@ -1229,7 +1229,7 @@ extern PRInt32 _PR_MD_PIPEAVAILABLE(PRFileDesc *fd);
#define _PR_MD_PIPEAVAILABLE _MD_PIPEAVAILABLE
extern PRInt32 _PR_MD_PR_POLL(PRPollDesc *pds, PRIntn npds,
- PRIntervalTime timeout);
+ PRIntervalTime timeout);
#define _PR_MD_PR_POLL _MD_PR_POLL
/*
@@ -1360,32 +1360,32 @@ extern PRUintn _PR_NetAddrSize(const PRNetAddr* addr);
*/
#if defined(XP_UNIX) || defined(XP_OS2)
-#define PR_NETADDR_SIZE(_addr) \
- ((_addr)->raw.family == PR_AF_INET \
- ? sizeof((_addr)->inet) \
- : ((_addr)->raw.family == PR_AF_INET6 \
- ? sizeof(struct _md_sockaddr_in6) \
+#define PR_NETADDR_SIZE(_addr) \
+ ((_addr)->raw.family == PR_AF_INET \
+ ? sizeof((_addr)->inet) \
+ : ((_addr)->raw.family == PR_AF_INET6 \
+ ? sizeof(struct _md_sockaddr_in6) \
: sizeof((_addr)->local)))
#else
-#define PR_NETADDR_SIZE(_addr) \
- ((_addr)->raw.family == PR_AF_INET \
- ? sizeof((_addr)->inet) \
+#define PR_NETADDR_SIZE(_addr) \
+ ((_addr)->raw.family == PR_AF_INET \
+ ? sizeof((_addr)->inet) \
: sizeof(struct _md_sockaddr_in6))
#endif /* defined(XP_UNIX) */
#else
#if defined(XP_UNIX) || defined(XP_OS2)
-#define PR_NETADDR_SIZE(_addr) \
- ((_addr)->raw.family == PR_AF_INET \
- ? sizeof((_addr)->inet) \
- : ((_addr)->raw.family == PR_AF_INET6 \
- ? sizeof((_addr)->ipv6) \
+#define PR_NETADDR_SIZE(_addr) \
+ ((_addr)->raw.family == PR_AF_INET \
+ ? sizeof((_addr)->inet) \
+ : ((_addr)->raw.family == PR_AF_INET6 \
+ ? sizeof((_addr)->ipv6) \
: sizeof((_addr)->local)))
#else
-#define PR_NETADDR_SIZE(_addr) \
- ((_addr)->raw.family == PR_AF_INET \
- ? sizeof((_addr)->inet) \
+#define PR_NETADDR_SIZE(_addr) \
+ ((_addr)->raw.family == PR_AF_INET \
+ ? sizeof((_addr)->inet) \
: sizeof((_addr)->ipv6))
#endif /* defined(XP_UNIX) */
@@ -1403,9 +1403,9 @@ struct PRLock {
PRBool locked; /* whether the mutex is locked */
pthread_t owner; /* if locked, current lock owner */
#elif defined(_PR_BTHREADS)
- sem_id semaphoreID; /* the underlying lock */
- int32 benaphoreCount; /* number of people in lock */
- thread_id owner; /* current lock owner */
+ sem_id semaphoreID; /* the underlying lock */
+ int32 benaphoreCount; /* number of people in lock */
+ thread_id owner; /* current lock owner */
#else /* not pthreads or Be threads */
PRCList links; /* linkage for PRThread.lockList */
struct PRThread *owner; /* current lock owner */
@@ -1533,7 +1533,7 @@ struct PRThreadStack {
PRUint32 stackSize; /* size of usable portion of the stack */
PRSegment *seg;
- PRThread* thr; /* back pointer to thread owning this stack */
+ PRThread* thr; /* back pointer to thread owning this stack */
#if defined(_PR_PTHREADS)
#else /* defined(_PR_PTHREADS) */
@@ -1736,7 +1736,7 @@ struct PRFilePrivate {
#ifdef _PR_NEED_SECRET_AF
PRUint16 af; /* If the platform's implementation of accept()
* requires knowing the address family of the
- * socket, we save the address family here. */
+ * socket, we save the address family here. */
#endif
#if defined(_WIN64)
@@ -2134,8 +2134,8 @@ extern PRSize _pr_CopyLowBits( void *dest, PRSize dstlen, void *src, PRSize srcl
#if defined(_WIN64) && defined(WIN95)
typedef struct _PRFileDescList {
- PRFileDesc *fd;
- struct _PRFileDescList *next;
+ PRFileDesc *fd;
+ struct _PRFileDescList *next;
} PRFileDescList;
extern PRLock *_fd_waiting_for_overlapped_done_lock;
diff --git a/pr/include/prlink.h b/pr/include/prlink.h
index e9134d13..0e38effa 100644
--- a/pr/include/prlink.h
+++ b/pr/include/prlink.h
@@ -190,7 +190,7 @@ NSPR_API(PRFuncPtr) PR_FindFunctionSymbol(PRLibrary *lib, const char *name);
** This increments the reference count of the library.
*/
NSPR_API(void*) PR_FindSymbolAndLibrary(const char *name,
- PRLibrary* *lib);
+ PRLibrary* *lib);
/*
** Similar to PR_FindSymbolAndLibrary, except that the return value is
@@ -201,7 +201,7 @@ NSPR_API(void*) PR_FindSymbolAndLibrary(const char *name,
** This increments the reference count of the library.
*/
NSPR_API(PRFuncPtr) PR_FindFunctionSymbolAndLibrary(const char *name,
- PRLibrary* *lib);
+ PRLibrary* *lib);
/*
** Register a static link table with the runtime under the name
diff --git a/pr/include/prlock.h b/pr/include/prlock.h
index 64f0125b..9b7fdaa1 100644
--- a/pr/include/prlock.h
+++ b/pr/include/prlock.h
@@ -4,8 +4,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
-** File: prlock.h
-** Description: API to basic locking functions of NSPR.
+** File: prlock.h
+** Description: API to basic locking functions of NSPR.
**
**
** NSPR provides basic locking mechanisms for thread synchronization. Locks
@@ -28,7 +28,7 @@ PR_BEGIN_EXTERN_C
* PRLock --
*
* NSPR represents the lock as an opaque entity to the client of the
- * API. All routines operate on a pointer to this opaque entity.
+ * API. All routines operate on a pointer to this opaque entity.
*/
typedef struct PRLock PRLock;
diff --git a/pr/include/prlog.h b/pr/include/prlog.h
index abfea214..a1f57e4d 100644
--- a/pr/include/prlog.h
+++ b/pr/include/prlog.h
@@ -158,7 +158,7 @@ NSPR_API(void) PR_LogPrint(const char *fmt, ...);
NSPR_API(void) PR_LogFlush(void);
NSPR_API(void) PR_Assert(const char *s, const char *file, PRIntn ln)
- PR_PRETEND_NORETURN;
+PR_PRETEND_NORETURN;
#if defined(DEBUG) || defined(FORCE_PR_LOG)
#define PR_LOGGING 1
diff --git a/pr/include/prmem.h b/pr/include/prmem.h
index c7cb5fbf..ed9a4289 100644
--- a/pr/include/prmem.h
+++ b/pr/include/prmem.h
@@ -45,81 +45,81 @@ NSPR_API(void) PR_Free(void *ptr);
*/
/***********************************************************************
-** FUNCTION: PR_MALLOC()
+** FUNCTION: PR_MALLOC()
** DESCRIPTION:
** PR_NEW() allocates an untyped item of size _size from the heap.
** INPUTS: _size: size in bytes of item to be allocated
-** OUTPUTS: untyped pointer to the node allocated
-** RETURN: pointer to node or error returned from malloc().
+** OUTPUTS: untyped pointer to the node allocated
+** RETURN: pointer to node or error returned from malloc().
***********************************************************************/
#define PR_MALLOC(_bytes) (PR_Malloc((_bytes)))
/***********************************************************************
-** FUNCTION: PR_NEW()
+** FUNCTION: PR_NEW()
** DESCRIPTION:
** PR_NEW() allocates an item of type _struct from the heap.
** INPUTS: _struct: a data type
-** OUTPUTS: pointer to _struct
-** RETURN: pointer to _struct or error returns from malloc().
+** OUTPUTS: pointer to _struct
+** RETURN: pointer to _struct or error returns from malloc().
***********************************************************************/
#define PR_NEW(_struct) ((_struct *) PR_MALLOC(sizeof(_struct)))
/***********************************************************************
-** FUNCTION: PR_REALLOC()
+** FUNCTION: PR_REALLOC()
** DESCRIPTION:
** PR_REALLOC() re-allocates _ptr bytes from the heap as a _size
** untyped item.
-** INPUTS: _ptr: pointer to node to reallocate
+** INPUTS: _ptr: pointer to node to reallocate
** _size: size of node to allocate
-** OUTPUTS: pointer to node allocated
-** RETURN: pointer to node allocated
+** OUTPUTS: pointer to node allocated
+** RETURN: pointer to node allocated
***********************************************************************/
#define PR_REALLOC(_ptr, _size) (PR_Realloc((_ptr), (_size)))
/***********************************************************************
-** FUNCTION: PR_CALLOC()
+** FUNCTION: PR_CALLOC()
** DESCRIPTION:
** PR_CALLOC() allocates a _size bytes untyped item from the heap
** and sets the allocated memory to all 0x00.
-** INPUTS: _size: size of node to allocate
-** OUTPUTS: pointer to node allocated
-** RETURN: pointer to node allocated
+** INPUTS: _size: size of node to allocate
+** OUTPUTS: pointer to node allocated
+** RETURN: pointer to node allocated
***********************************************************************/
#define PR_CALLOC(_size) (PR_Calloc(1, (_size)))
/***********************************************************************
-** FUNCTION: PR_NEWZAP()
+** FUNCTION: PR_NEWZAP()
** DESCRIPTION:
** PR_NEWZAP() allocates an item of type _struct from the heap
** and sets the allocated memory to all 0x00.
-** INPUTS: _struct: a data type
-** OUTPUTS: pointer to _struct
-** RETURN: pointer to _struct
+** INPUTS: _struct: a data type
+** OUTPUTS: pointer to _struct
+** RETURN: pointer to _struct
***********************************************************************/
#define PR_NEWZAP(_struct) ((_struct*)PR_Calloc(1, sizeof(_struct)))
/***********************************************************************
-** FUNCTION: PR_DELETE()
+** FUNCTION: PR_DELETE()
** DESCRIPTION:
** PR_DELETE() unallocates an object previosly allocated via PR_NEW()
** or PR_NEWZAP() to the heap.
-** INPUTS: pointer to previously allocated object
-** OUTPUTS: the referenced object is returned to the heap
-** RETURN: void
+** INPUTS: pointer to previously allocated object
+** OUTPUTS: the referenced object is returned to the heap
+** RETURN: void
***********************************************************************/
#define PR_DELETE(_ptr) { PR_Free(_ptr); (_ptr) = NULL; }
/***********************************************************************
-** FUNCTION: PR_FREEIF()
+** FUNCTION: PR_FREEIF()
** DESCRIPTION:
** PR_FREEIF() conditionally unallocates an object previously allocated
** vial PR_NEW() or PR_NEWZAP(). If the pointer to the object is
** equal to zero (0), the object is not released.
-** INPUTS: pointer to previously allocated object
-** OUTPUTS: the referenced object is conditionally returned to the heap
-** RETURN: void
+** INPUTS: pointer to previously allocated object
+** OUTPUTS: the referenced object is conditionally returned to the heap
+** RETURN: void
***********************************************************************/
-#define PR_FREEIF(_ptr) if (_ptr) PR_DELETE(_ptr)
+#define PR_FREEIF(_ptr) if (_ptr) PR_DELETE(_ptr)
PR_END_EXTERN_C
diff --git a/pr/include/prnetdb.h b/pr/include/prnetdb.h
index c7a476aa..7a7ea863 100644
--- a/pr/include/prnetdb.h
+++ b/pr/include/prnetdb.h
@@ -55,7 +55,7 @@ typedef struct PRHostEnt {
/***********************************************************************
** FUNCTION:
-** DESCRIPTION: PR_GetHostByName()
+** DESCRIPTION: PR_GetHostByName()
** Lookup a host by name.
**
** INPUTS:
@@ -79,7 +79,7 @@ NSPR_API(PRStatus) PR_GetHostByName(
/***********************************************************************
** FUNCTION:
-** DESCRIPTION: PR_GetIPNodeByName()
+** DESCRIPTION: PR_GetIPNodeByName()
** Lookup a host by name. Equivalent to getipnodebyname(AI_DEFAULT)
** of RFC 2553.
**
@@ -121,7 +121,7 @@ NSPR_API(PRStatus) PR_GetIPNodeByName(
/***********************************************************************
** FUNCTION:
-** DESCRIPTION: PR_GetHostByAddr()
+** DESCRIPTION: PR_GetHostByAddr()
** Lookup a host entry by its network address.
**
** INPUTS:
@@ -144,7 +144,7 @@ NSPR_API(PRStatus) PR_GetHostByAddr(
const PRNetAddr *hostaddr, char *buf, PRIntn bufsize, PRHostEnt *hostentry);
/***********************************************************************
-** FUNCTION: PR_EnumerateHostEnt()
+** FUNCTION: PR_EnumerateHostEnt()
** DESCRIPTION:
** A stateless enumerator over a PRHostEnt structure acquired from
** PR_GetHostByName() PR_GetHostByAddr() to evaluate the possible
@@ -240,7 +240,7 @@ NSPR_API(PRStatus) PR_SetNetAddr(
/***********************************************************************
** FUNCTION:
-** DESCRIPTION: PR_IsNetAddrType()
+** DESCRIPTION: PR_IsNetAddrType()
** Determine if the network address is of the specified type.
**
** INPUTS:
@@ -255,11 +255,11 @@ NSPR_API(PRBool) PR_IsNetAddrType(const PRNetAddr *addr, PRNetAddrValue val);
/***********************************************************************
** FUNCTION:
-** DESCRIPTION: PR_ConvertIPv4AddrToIPv6()
+** DESCRIPTION: PR_ConvertIPv4AddrToIPv6()
** Convert an IPv4 addr to an (IPv4-mapped) IPv6 addr
**
** INPUTS:
-** PRUint32 v4addr IPv4 address
+** PRUint32 v4addr IPv4 address
**
** OUTPUTS:
** PRIPv6Addr *v6addr The converted IPv6 address
@@ -272,7 +272,7 @@ NSPR_API(void) PR_ConvertIPv4AddrToIPv6(PRUint32 v4addr, PRIPv6Addr *v6addr);
/***********************************************************************
** MACRO:
-** DESCRIPTION: PR_NetAddrFamily()
+** DESCRIPTION: PR_NetAddrFamily()
** Get the 'family' field of a PRNetAddr union.
**
** INPUTS:
@@ -285,7 +285,7 @@ NSPR_API(void) PR_ConvertIPv4AddrToIPv6(PRUint32 v4addr, PRIPv6Addr *v6addr);
/***********************************************************************
** MACRO:
-** DESCRIPTION: PR_NetAddrInetPort()
+** DESCRIPTION: PR_NetAddrInetPort()
** Get the 'port' field of a PRNetAddr union.
**
** INPUTS:
@@ -299,7 +299,7 @@ NSPR_API(void) PR_ConvertIPv4AddrToIPv6(PRUint32 v4addr, PRIPv6Addr *v6addr);
/***********************************************************************
** FUNCTION:
-** DESCRIPTION: PR_GetProtoByName()
+** DESCRIPTION: PR_GetProtoByName()
** Lookup a protocol entry based on protocol's name
**
** INPUTS:
@@ -334,7 +334,7 @@ NSPR_API(PRStatus) PR_GetProtoByName(
/***********************************************************************
** FUNCTION:
-** DESCRIPTION: PR_GetProtoByNumber()
+** DESCRIPTION: PR_GetProtoByNumber()
** Lookup a protocol entry based on protocol's number
**
** INPUTS:
diff --git a/pr/include/prolock.h b/pr/include/prolock.h
index 089b3e37..7b57b3c7 100644
--- a/pr/include/prolock.h
+++ b/pr/include/prolock.h
@@ -86,9 +86,9 @@ typedef PRLock PROrderedLock;
#endif
NSPR_API(PROrderedLock *)
- PR_CreateOrderedLock(
- PRInt32 order,
- const char *name
+PR_CreateOrderedLock(
+ PRInt32 order,
+ const char *name
);
/* -----------------------------------------------------------------------
@@ -113,8 +113,8 @@ NSPR_API(PROrderedLock *)
#endif
NSPR_API(void)
- PR_DestroyOrderedLock(
- PROrderedLock *lock
+PR_DestroyOrderedLock(
+ PROrderedLock *lock
);
/* -----------------------------------------------------------------------
@@ -141,8 +141,8 @@ NSPR_API(void)
#endif
NSPR_API(void)
- PR_LockOrderedLock(
- PROrderedLock *lock
+PR_LockOrderedLock(
+ PROrderedLock *lock
);
/* -----------------------------------------------------------------------
@@ -169,8 +169,8 @@ NSPR_API(void)
#endif
NSPR_API(PRStatus)
- PR_UnlockOrderedLock(
- PROrderedLock *lock
+PR_UnlockOrderedLock(
+ PROrderedLock *lock
);
PR_END_EXTERN_C
diff --git a/pr/include/prpdce.h b/pr/include/prpdce.h
index b681795f..bf9ea9e2 100644
--- a/pr/include/prpdce.h
+++ b/pr/include/prpdce.h
@@ -4,10 +4,10 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
- * File: prpdce.h
- * Description: This file is the API defined to allow for DCE (aka POSIX)
- * thread emulation in an NSPR environment. It is not the
- * intent that this be a fully supported API.
+ * File: prpdce.h
+ * Description: This file is the API defined to allow for DCE (aka POSIX)
+ * thread emulation in an NSPR environment. It is not the
+ * intent that this be a fully supported API.
*/
#if !defined(PRPDCE_H)
@@ -61,7 +61,7 @@ NSPR_API(void) PRP_DestroyNakedCondVar(PRCondVar *cvar);
** NB: The CV ('cvar') must be one created using PR_NewNakedCondVar.
*/
NSPR_API(PRStatus) PRP_NakedWait(
- PRCondVar *cvar, PRLock *lock, PRIntervalTime timeout);
+ PRCondVar *cvar, PRLock *lock, PRIntervalTime timeout);
/*
** Notify a thread waiting on a condition
diff --git a/pr/include/prprf.h b/pr/include/prprf.h
index 440be888..759ef405 100644
--- a/pr/include/prprf.h
+++ b/pr/include/prprf.h
@@ -8,19 +8,19 @@
/*
** API for PR printf like routines. Supports the following formats
-** %d - decimal
-** %u - unsigned decimal
-** %x - unsigned hex
-** %X - unsigned uppercase hex
-** %o - unsigned octal
-** %hd, %hu, %hx, %hX, %ho - 16-bit versions of above
-** %ld, %lu, %lx, %lX, %lo - 32-bit versions of above
-** %lld, %llu, %llx, %llX, %llo - 64 bit versions of above
-** %s - string
-** %c - character
-** %p - pointer (deals with machine dependent pointer size)
-** %f - float
-** %g - float
+** %d - decimal
+** %u - unsigned decimal
+** %x - unsigned hex
+** %X - unsigned uppercase hex
+** %o - unsigned octal
+** %hd, %hu, %hx, %hX, %ho - 16-bit versions of above
+** %ld, %lu, %lx, %lX, %lo - 32-bit versions of above
+** %lld, %llu, %llx, %llX, %llo - 64 bit versions of above
+** %s - string
+** %c - character
+** %p - pointer (deals with machine dependent pointer size)
+** %f - float
+** %g - float
*/
#include "prtypes.h"
#include "prio.h"
diff --git a/pr/include/prrwlock.h b/pr/include/prrwlock.h
index cbaecdda..ab47b53f 100644
--- a/pr/include/prrwlock.h
+++ b/pr/include/prrwlock.h
@@ -4,8 +4,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
-** File: prrwlock.h
-** Description: API to basic reader-writer lock functions of NSPR.
+** File: prrwlock.h
+** Description: API to basic reader-writer lock functions of NSPR.
**
**/
@@ -19,14 +19,14 @@ PR_BEGIN_EXTERN_C
/*
* PRRWLock --
*
- * The reader writer lock, PRRWLock, is an opaque object to the clients
- * of NSPR. All routines operate on a pointer to this opaque entity.
+ * The reader writer lock, PRRWLock, is an opaque object to the clients
+ * of NSPR. All routines operate on a pointer to this opaque entity.
*/
typedef struct PRRWLock PRRWLock;
-#define PR_RWLOCK_RANK_NONE 0
+#define PR_RWLOCK_RANK_NONE 0
/***********************************************************************
@@ -34,7 +34,7 @@ typedef struct PRRWLock PRRWLock;
** DESCRIPTION:
** Returns a pointer to a newly created reader-writer lock object.
** INPUTS: Lock rank
-** Lock name
+** Lock name
** OUTPUTS: void
** RETURN: PRRWLock*
** If the lock cannot be created because of resource constraints, NULL
diff --git a/pr/include/prshm.h b/pr/include/prshm.h
index 916a56c9..3588aed4 100644
--- a/pr/include/prshm.h
+++ b/pr/include/prshm.h
@@ -145,11 +145,11 @@ typedef struct PRSharedMemory PRSharedMemory;
**
*/
NSPR_API( PRSharedMemory * )
- PR_OpenSharedMemory(
- const char *name,
- PRSize size,
- PRIntn flags,
- PRIntn mode
+PR_OpenSharedMemory(
+ const char *name,
+ PRSize size,
+ PRIntn flags,
+ PRIntn mode
);
/* Define values for PR_OpenShareMemory(...,create) */
#define PR_SHM_CREATE 0x1 /* create if not exist */
@@ -179,9 +179,9 @@ NSPR_API( PRSharedMemory * )
**
*/
NSPR_API( void * )
- PR_AttachSharedMemory(
- PRSharedMemory *shm,
- PRIntn flags
+PR_AttachSharedMemory(
+ PRSharedMemory *shm,
+ PRIntn flags
);
/* Define values for PR_AttachSharedMemory(...,flags) */
#define PR_SHM_READONLY 0x01
@@ -205,9 +205,9 @@ NSPR_API( void * )
**
*/
NSPR_API( PRStatus )
- PR_DetachSharedMemory(
- PRSharedMemory *shm,
- void *addr
+PR_DetachSharedMemory(
+ PRSharedMemory *shm,
+ void *addr
);
/*
@@ -227,8 +227,8 @@ NSPR_API( PRStatus )
**
*/
NSPR_API( PRStatus )
- PR_CloseSharedMemory(
- PRSharedMemory *shm
+PR_CloseSharedMemory(
+ PRSharedMemory *shm
);
/*
@@ -248,8 +248,8 @@ NSPR_API( PRStatus )
**
*/
NSPR_API( PRStatus )
- PR_DeleteSharedMemory(
- const char *name
+PR_DeleteSharedMemory(
+ const char *name
);
PR_END_EXTERN_C
diff --git a/pr/include/prthread.h b/pr/include/prthread.h
index 98f8a6df..cacd3891 100644
--- a/pr/include/prthread.h
+++ b/pr/include/prthread.h
@@ -103,12 +103,12 @@ typedef enum PRThreadPriority
** PR_USER_THREAD to exit then the process exits.
*/
NSPR_API(PRThread*) PR_CreateThread(PRThreadType type,
- void (PR_CALLBACK *start)(void *arg),
- void *arg,
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize);
+ void (PR_CALLBACK *start)(void *arg),
+ void *arg,
+ PRThreadPriority priority,
+ PRThreadScope scope,
+ PRThreadState state,
+ PRUint32 stackSize);
/*
** Wait for thread termination:
diff --git a/pr/include/prtime.h b/pr/include/prtime.h
index caaee14f..917a1615 100644
--- a/pr/include/prtime.h
+++ b/pr/include/prtime.h
@@ -24,11 +24,11 @@ PR_BEGIN_EXTERN_C
/************************* TYPES AND CONSTANTS ************************/
/**********************************************************************/
-#define PR_MSEC_PER_SEC 1000L
-#define PR_USEC_PER_SEC 1000000L
-#define PR_NSEC_PER_SEC 1000000000L
-#define PR_USEC_PER_MSEC 1000L
-#define PR_NSEC_PER_MSEC 1000000L
+#define PR_MSEC_PER_SEC 1000L
+#define PR_USEC_PER_SEC 1000000L
+#define PR_NSEC_PER_SEC 1000000000L
+#define PR_USEC_PER_MSEC 1000L
+#define PR_NSEC_PER_MSEC 1000000L
/*
* PRTime --
@@ -81,21 +81,21 @@ typedef struct PRTimeParameters {
*/
typedef struct PRExplodedTime {
- PRInt32 tm_usec; /* microseconds past tm_sec (0-99999) */
+ PRInt32 tm_usec; /* microseconds past tm_sec (0-99999) */
PRInt32 tm_sec; /* seconds past tm_min (0-61, accomodating
up to two leap seconds) */
PRInt32 tm_min; /* minutes past tm_hour (0-59) */
PRInt32 tm_hour; /* hours past tm_day (0-23) */
PRInt32 tm_mday; /* days past tm_mon (1-31, note that it
- starts from 1) */
+ starts from 1) */
PRInt32 tm_month; /* months past tm_year (0-11, Jan = 0) */
PRInt16 tm_year; /* absolute year, AD (note that we do not
- count from 1900) */
+ count from 1900) */
- PRInt8 tm_wday; /* calculated day of the week
- (0-6, Sun = 0) */
+ PRInt8 tm_wday; /* calculated day of the week
+ (0-6, Sun = 0) */
PRInt16 tm_yday; /* calculated day of the year
- (0-365, Jan 1 = 0) */
+ (0-365, Jan 1 = 0) */
PRTimeParameters tm_params; /* time parameters used by conversion */
} PRExplodedTime;
@@ -229,9 +229,9 @@ NSPR_API(PRTimeParameters) PR_USPacificTimeParameters(const PRExplodedTime *gmt)
*/
NSPR_API(PRStatus) PR_ParseTimeStringToExplodedTime (
- const char *string,
- PRBool default_to_gmt,
- PRExplodedTime *result);
+ const char *string,
+ PRBool default_to_gmt,
+ PRExplodedTime *result);
/*
* This uses PR_ParseTimeStringToExplodedTime to parse
@@ -242,9 +242,9 @@ NSPR_API(PRStatus) PR_ParseTimeStringToExplodedTime (
*/
NSPR_API(PRStatus) PR_ParseTimeString (
- const char *string,
- PRBool default_to_gmt,
- PRTime *result);
+ const char *string,
+ PRBool default_to_gmt,
+ PRTime *result);
/* Format a time value into a buffer. Same semantics as strftime() */
NSPR_API(PRUint32) PR_FormatTime(char *buf, int buflen, const char *fmt,
diff --git a/pr/include/prtpool.h b/pr/include/prtpool.h
index 6a434dd1..b4d18d41 100644
--- a/pr/include/prtpool.h
+++ b/pr/include/prtpool.h
@@ -13,8 +13,8 @@
/*
* NOTE:
- * THIS API IS A PRELIMINARY VERSION IN NSPR 4.0 AND IS SUBJECT TO
- * CHANGE
+ * THIS API IS A PRELIMINARY VERSION IN NSPR 4.0 AND IS SUBJECT TO
+ * CHANGE
*/
PR_BEGIN_EXTERN_C
@@ -32,7 +32,7 @@ typedef void (PR_CALLBACK *PRJobFn) (void *arg);
/* Create thread pool */
NSPR_API(PRThreadPool *)
PR_CreateThreadPool(PRInt32 initial_threads, PRInt32 max_threads,
- PRUint32 stacksize);
+ PRUint32 stacksize);
/* queue a job */
NSPR_API(PRJob *)
@@ -41,27 +41,27 @@ PR_QueueJob(PRThreadPool *tpool, PRJobFn fn, void *arg, PRBool joinable);
/* queue a job, when a socket is readable */
NSPR_API(PRJob *)
PR_QueueJob_Read(PRThreadPool *tpool, PRJobIoDesc *iod,
- PRJobFn fn, void * arg, PRBool joinable);
+ PRJobFn fn, void * arg, PRBool joinable);
/* queue a job, when a socket is writeable */
NSPR_API(PRJob *)
PR_QueueJob_Write(PRThreadPool *tpool, PRJobIoDesc *iod,
- PRJobFn fn, void * arg, PRBool joinable);
+ PRJobFn fn, void * arg, PRBool joinable);
/* queue a job, when a socket has a pending connection */
NSPR_API(PRJob *)
PR_QueueJob_Accept(PRThreadPool *tpool, PRJobIoDesc *iod,
- PRJobFn fn, void * arg, PRBool joinable);
+ PRJobFn fn, void * arg, PRBool joinable);
/* queue a job, when the socket connection to addr succeeds or fails */
NSPR_API(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);
/* queue a job, when a timer exipres */
NSPR_API(PRJob *)
PR_QueueJob_Timer(PRThreadPool *tpool, PRIntervalTime timeout,
- PRJobFn fn, void * arg, PRBool joinable);
+ PRJobFn fn, void * arg, PRBool joinable);
/* cancel a job */
NSPR_API(PRStatus)
PR_CancelJob(PRJob *job);
diff --git a/pr/include/prtrace.h b/pr/include/prtrace.h
index aa16a830..49bd3edb 100644
--- a/pr/include/prtrace.h
+++ b/pr/include/prtrace.h
@@ -174,10 +174,10 @@ typedef enum PRTraceOption
#endif
NSPR_API(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 */
);
@@ -208,8 +208,8 @@ NSPR_API(PRTraceHandle)
#endif
NSPR_API(void)
- PR_DestroyTrace(
- PRTraceHandle handle /* Handle to be destroyed */
+PR_DestroyTrace(
+ PRTraceHandle handle /* Handle to be destroyed */
);
@@ -249,16 +249,16 @@ NSPR_API(void)
#endif
NSPR_API(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_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 */
);
/* -----------------------------------------------------------------------
@@ -336,9 +336,9 @@ NSPR_API(void)
#endif
NSPR_API(void)
- PR_SetTraceOption(
- PRTraceOption command, /* One of the enumerated values */
- void *value /* command value or NULL */
+PR_SetTraceOption(
+ PRTraceOption command, /* One of the enumerated values */
+ void *value /* command value or NULL */
);
@@ -374,9 +374,9 @@ NSPR_API(void)
#endif
NSPR_API(void)
- PR_GetTraceOption(
- PRTraceOption command, /* One of the enumerated values */
- void *value /* command value or NULL */
+PR_GetTraceOption(
+ PRTraceOption command, /* One of the enumerated values */
+ void *value /* command value or NULL */
);
/* -----------------------------------------------------------------------
@@ -410,9 +410,9 @@ NSPR_API(void)
#endif
NSPR_API(PRTraceHandle)
- PR_GetTraceHandleFromName(
- const char *qName, /* QName search argument */
- const char *rName /* RName search argument */
+PR_GetTraceHandleFromName(
+ const char *qName, /* QName search argument */
+ const char *rName /* RName search argument */
);
/* -----------------------------------------------------------------------
@@ -442,11 +442,11 @@ NSPR_API(PRTraceHandle)
#endif
NSPR_API(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_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 */
);
/* -----------------------------------------------------------------------
@@ -484,8 +484,8 @@ NSPR_API(void)
#endif
NSPR_API(PRTraceHandle)
- PR_FindNextTraceQname(
- PRTraceHandle handle
+PR_FindNextTraceQname(
+ PRTraceHandle handle
);
@@ -526,9 +526,9 @@ NSPR_API(PRTraceHandle)
#endif
NSPR_API(PRTraceHandle)
- PR_FindNextTraceRname(
- PRTraceHandle rhandle,
- PRTraceHandle qhandle
+PR_FindNextTraceRname(
+ PRTraceHandle rhandle,
+ PRTraceHandle qhandle
);
/* -----------------------------------------------------------------------
@@ -576,14 +576,14 @@ NSPR_API(PRTraceHandle)
*/
#if defined (DEBUG) || defined (FORCE_NSPR_TRACE)
#define PR_RECORD_TRACE_ENTRIES()\
- PR_RecordTraceEntries()
+ PR_RecordTraceEntries()
#else
#define PR_RECORD_TRACE_ENTRIES()
#endif
NSPR_API(void)
- PR_RecordTraceEntries(
- void
+PR_RecordTraceEntries(
+ void
);
/* -----------------------------------------------------------------------
@@ -634,10 +634,10 @@ NSPR_API(void)
#endif
NSPR_API(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 */
);
PR_END_EXTERN_C
diff --git a/pr/include/prtypes.h b/pr/include/prtypes.h
index 74419ea2..7400367f 100644
--- a/pr/include/prtypes.h
+++ b/pr/include/prtypes.h
@@ -515,7 +515,7 @@ typedef unsigned long PRUword;
** Fundamental NSPR macros, used nearly everywhere.
*/
-#define PR_PUBLIC_API PR_IMPLEMENT
+#define PR_PUBLIC_API PR_IMPLEMENT
/*
** Macro body brackets so that macros with compound statement definitions
diff --git a/pr/include/prwin16.h b/pr/include/prwin16.h
index 636a89b8..b545f04a 100644
--- a/pr/include/prwin16.h
+++ b/pr/include/prwin16.h
@@ -54,7 +54,7 @@ PR_MD_RegisterW16StdioCallbacks(
PRStdinRead inReadf, /* i: function pointer for stdin read */
PRStdoutWrite outWritef, /* i: function pointer for stdout write */
PRStderrWrite errWritef /* i: function pointer for stderr write */
- );
+);
NSPR_API(PRInt32)
_PL_W16StdioWrite( void *buf, PRInt32 amount );
@@ -79,7 +79,7 @@ struct PRMethodCallbackStr {
void (PR_CALLBACK *free)( void *ptr );
void * (PR_CALLBACK *getenv)( const char *name);
int (PR_CALLBACK *putenv)( const char *assoc);
-/* void * (PR_CALLBACK *perror)( const char *prefix ); */
+ /* void * (PR_CALLBACK *perror)( const char *prefix ); */
};
NSPR_API(void) PR_MDRegisterCallbacks(struct PRMethodCallbackStr *);
diff --git a/pr/src/cplus/rcbase.cpp b/pr/src/cplus/rcbase.cpp
index c258081d..7c12e6d3 100644
--- a/pr/src/cplus/rcbase.cpp
+++ b/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/pr/src/cplus/rcbase.h b/pr/src/cplus/rcbase.h
index 58df43c1..3cc91f80 100644
--- a/pr/src/cplus/rcbase.h
+++ b/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/pr/src/cplus/rccv.cpp b/pr/src/cplus/rccv.cpp
index 32b84b1c..f1243853 100644
--- a/pr/src/cplus/rccv.cpp
+++ b/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/pr/src/cplus/rccv.h b/pr/src/cplus/rccv.h
index e5c89135..afeec616 100644
--- a/pr/src/cplus/rccv.h
+++ b/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/pr/src/cplus/rcfileio.cpp b/pr/src/cplus/rcfileio.cpp
index cdf6318a..91c5fde6 100644
--- a/pr/src/cplus/rcfileio.cpp
+++ b/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/pr/src/cplus/rcfileio.h b/pr/src/cplus/rcfileio.h
index d9c82582..9e28b36a 100644
--- a/pr/src/cplus/rcfileio.h
+++ b/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/pr/src/cplus/rcinrval.cpp b/pr/src/cplus/rcinrval.cpp
index cda5f8df..3805a576 100644
--- a/pr/src/cplus/rcinrval.cpp
+++ b/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/pr/src/cplus/rcinrval.h b/pr/src/cplus/rcinrval.h
index 4ff26dc5..333209e6 100644
--- a/pr/src/cplus/rcinrval.h
+++ b/pr/src/cplus/rcinrval.h
@@ -73,64 +73,118 @@ private:
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/pr/src/cplus/rcio.h b/pr/src/cplus/rcio.h
index a4278d2a..1bd3ac41 100644
--- a/pr/src/cplus/rcio.h
+++ b/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/pr/src/cplus/rclock.cpp b/pr/src/cplus/rclock.cpp
index 60d13b88..8c106de0 100644
--- a/pr/src/cplus/rclock.cpp
+++ b/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/pr/src/cplus/rclock.h b/pr/src/cplus/rclock.h
index 511b6fa4..c86c2f17 100644
--- a/pr/src/cplus/rclock.h
+++ b/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/pr/src/cplus/rcnetdb.cpp b/pr/src/cplus/rcnetdb.cpp
index 042943bc..19eb6654 100644
--- a/pr/src/cplus/rcnetdb.cpp
+++ b/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/pr/src/cplus/rcnetdb.h b/pr/src/cplus/rcnetdb.h
index 8096113b..14e96ecd 100644
--- a/pr/src/cplus/rcnetdb.h
+++ b/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/pr/src/cplus/rcnetio.cpp b/pr/src/cplus/rcnetio.cpp
index cbbadcfe..e351345e 100644
--- a/pr/src/cplus/rcnetio.cpp
+++ b/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 */
@@ -46,31 +54,44 @@ PRInt32 RCNetStreamIO::AcceptRead(
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/pr/src/cplus/rcnetio.h b/pr/src/cplus/rcnetio.h
index 44b8bf07..7f6b669d 100644
--- a/pr/src/cplus/rcnetio.h
+++ b/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/pr/src/cplus/rcthread.cpp b/pr/src/cplus/rcthread.cpp
index d2f84cf3..471e580a 100755..100644
--- a/pr/src/cplus/rcthread.cpp
+++ b/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,26 +96,40 @@ 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)
{
@@ -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 */
@@ -169,7 +200,9 @@ void RCPrimordialThread::RootFunction()
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/pr/src/cplus/rcthread.h b/pr/src/cplus/rcthread.h
index c8b303ff..b7716d4b 100644
--- a/pr/src/cplus/rcthread.h
+++ b/pr/src/cplus/rcthread.h
@@ -157,7 +157,7 @@ private:
public:
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/pr/src/cplus/rctime.cpp b/pr/src/cplus/rctime.cpp
index d6551040..2c9823e1 100644
--- a/pr/src/cplus/rctime.cpp
+++ b/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/pr/src/cplus/rctime.h b/pr/src/cplus/rctime.h
index 17af3c2d..3752a3d5 100644
--- a/pr/src/cplus/rctime.h
+++ b/pr/src/cplus/rctime.h
@@ -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::operator=(PRTime his) { gmt = his; }
-inline void RCTime::operator=(const RCTime& his) { gmt = his.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 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/pr/src/cplus/tests/ranfile.cpp b/pr/src/cplus/tests/ranfile.cpp
index 7cedc341..0fb4c5d2 100644
--- a/pr/src/cplus/tests/ranfile.cpp
+++ b/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/pr/src/cplus/tests/switch.cpp b/pr/src/cplus/tests/switch.cpp
index d8b4e936..00de8e30 100644
--- a/pr/src/cplus/tests/switch.cpp
+++ b/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/pr/src/cplus/tests/thread.cpp b/pr/src/cplus/tests/thread.cpp
index e2c318d4..ff01402d 100644
--- a/pr/src/cplus/tests/thread.cpp
+++ b/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()
{
diff --git a/pr/src/cplus/tests/tpd.cpp b/pr/src/cplus/tests/tpd.cpp
index 56ac9677..2a18c9cb 100644
--- a/pr/src/cplus/tests/tpd.cpp
+++ b/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,7 +106,8 @@ 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;
@@ -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= */
/*
@@ -257,7 +273,8 @@ void MyThread::RootFunction()
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)
diff --git a/pr/src/io/prdir.c b/pr/src/io/prdir.c
index e1e19625..365afefd 100644
--- a/pr/src/io/prdir.c
+++ b/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
@@ -120,10 +126,12 @@ PR_IMPLEMENT(PRStatus) PR_CloseDirUTF16(PRDirUTF16 *dir)
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/pr/src/io/prfdcach.c b/pr/src/io/prfdcach.c
index 255f4632..ecfe3d39 100644
--- a/pr/src/io/prfdcach.c
+++ b/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,9 +167,13 @@ 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;
@@ -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/pr/src/io/prfile.c b/pr/src/io/prfile.c
index d31e446b..4b07baf4 100644
--- a/pr/src/io/prfile.c
+++ b/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;
@@ -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;
@@ -399,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() */
@@ -422,12 +441,14 @@ 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) \
@@ -441,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;
@@ -476,24 +501,26 @@ 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;
+ }
}
/*
@@ -503,7 +530,9 @@ 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 ) {
@@ -522,7 +551,9 @@ 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 ) {
@@ -571,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) */
@@ -591,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);
@@ -625,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++;
}
@@ -642,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--;
}
@@ -661,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);
@@ -696,7 +732,9 @@ PR_IMPLEMENT(PRStatus) PR_CreatePipe(
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) {
@@ -741,7 +779,9 @@ PR_IMPLEMENT(PRFileDesc*) PR_OpenFileUTF16(
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);
@@ -763,7 +803,9 @@ PR_IMPLEMENT(PRStatus) PR_GetFileInfo64UTF16(const PRUnichar *fn, PRFileInfo64 *
{
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/pr/src/io/prio.c b/pr/src/io/prio.c
index ffc66f1a..745d7721 100644
--- a/pr/src/io/prio.c
+++ b/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,7 +88,9 @@ 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)
{
@@ -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));
}
/*
diff --git a/pr/src/io/priometh.c b/pr/src/io/priometh.c
index 6ec5045f..508719a8 100644
--- a/pr/src/io/priometh.c
+++ b/pr/src/io/priometh.c
@@ -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)
@@ -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/pr/src/io/pripv6.c b/pr/src/io/pripv6.c
index 9f94ff4e..1c299652 100644
--- a/pr/src/io/pripv6.c
+++ b/pr/src/io/pripv6.c
@@ -23,110 +23,110 @@ 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,47 +204,47 @@ 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)
@@ -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/pr/src/io/prlayer.c b/pr/src/io/prlayer.c
index 26fc82ff..1e63b7b7 100644
--- a/pr/src/io/prlayer.c
+++ b/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/pr/src/io/prlog.c b/pr/src/io/prlog.c
index b4fe8f11..52bd6abc 100644
--- a/pr/src/io/prlog.c
+++ b/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/pr/src/io/prmapopt.c b/pr/src/io/prmapopt.c
index 262b00bb..b6653e4b 100644
--- a/pr/src/io/prmapopt.c
+++ b/pr/src/io/prmapopt.c
@@ -65,7 +65,7 @@ PRStatus PR_CALLBACK _PR_SocketGetSocketOption(PRFileDesc *fd, PRSocketOptionDat
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);
@@ -89,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:
@@ -103,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:
@@ -115,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:
@@ -126,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:
@@ -138,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
@@ -150,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 =
@@ -166,8 +170,8 @@ 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:
@@ -191,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))
{
@@ -220,7 +224,7 @@ PRStatus PR_CALLBACK _PR_SocketSetSocketOption(PRFileDesc *fd, const PRSocketOpt
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;
}
case PR_SockOpt_Reuseaddr:
@@ -236,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:
@@ -248,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:
@@ -257,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:
@@ -265,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:
@@ -277,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
@@ -290,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 */
@@ -298,8 +302,8 @@ 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:
@@ -431,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/pr/src/io/prmmap.c b/pr/src/io/prmmap.c
index 64f7ed4e..b0adf886 100644
--- a/pr/src/io/prmmap.c
+++ b/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/pr/src/io/prmwait.c b/pr/src/io/prmwait.c
index 22ded763..62e35ab6 100644
--- a/pr/src/io/prmwait.c
+++ b/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)
@@ -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:
@@ -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;
@@ -412,7 +419,9 @@ static PRRecvWait **_MW_LookupInternal(PRWaitGroup *group, PRFileDesc *fd)
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;
@@ -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
@@ -638,7 +661,7 @@ static void NT_TimeProc(void *arg)
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);
@@ -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);
@@ -843,8 +873,12 @@ PR_IMPLEMENT(PRRecvWait*) PR_WaitRecvReady(PRWaitGroup *group)
_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
{
@@ -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;
}
@@ -969,10 +1008,12 @@ PR_IMPLEMENT(PRRecvWait*) PR_WaitRecvReady(PRWaitGroup *group)
*/
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;
@@ -1400,7 +1470,9 @@ PR_IMPLEMENT(PRRecvWait*) PR_EnumerateWaitGroup(
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/pr/src/io/prpolevt.c b/pr/src/io/prpolevt.c
index 352ca153..1b664ba2 100644
--- a/pr/src/io/prpolevt.c
+++ b/pr/src/io/prpolevt.c
@@ -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/pr/src/io/prprf.c b/pr/src/io/prprf.c
index 82639d87..9b6072e2 100644
--- a/pr/src/io/prprf.c
+++ b/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
*/
@@ -394,58 +395,60 @@ static struct NumArg* BuildArgArray( const char *fmt, va_list ap, int* rv, struc
/*
- ** 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, ...)
+ const char *fmt, ...)
{
va_list ap;
PRUint32 rv;
@@ -1088,7 +1113,7 @@ PR_IMPLEMENT(PRUint32) PR_sxprintf(PRStuffFunc func, void *arg,
}
PR_IMPLEMENT(PRUint32) PR_vsxprintf(PRStuffFunc func, void *arg,
- const char *fmt, va_list ap)
+ 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/pr/src/io/prscanf.c b/pr/src/io/prscanf.c
index ebb33242..9923ea27 100644
--- a/pr/src/io/prscanf.c
+++ b/pr/src/io/prscanf.c
@@ -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);
@@ -478,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/pr/src/io/prsocket.c b/pr/src/io/prsocket.c
index e2ffb1d6..79419306 100644
--- a/pr/src/io/prsocket.c
+++ b/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) {
- 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;
+ 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;
}
/************************************************************************/
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;
@@ -401,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.
- */
+ /*
+ * 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);
+ _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)
@@ -809,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)
@@ -916,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)
+ 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)
+ 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 */
@@ -1111,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 */
@@ -1120,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)
+ 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(
@@ -1226,40 +1250,40 @@ 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,
+ SocketPoll,
+ SocketAcceptRead,
+ SocketTransmitFile,
+ SocketGetName,
+ SocketGetPeerName,
+ (PRReservedFN)_PR_InvalidInt,
+ (PRReservedFN)_PR_InvalidInt,
+ _PR_SocketGetSocketOption,
+ _PR_SocketSetSocketOption,
SocketSendFile,
SocketConnectContinue,
(PRReservedFN)_PR_InvalidInt,
@@ -1269,36 +1293,36 @@ static PRIOMethods tcpMethods = {
};
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,
+ 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,
@@ -1330,7 +1354,7 @@ static PRIOMethods socketpollfdMethods = {
(PRSendFN)_PR_InvalidInt,
(PRRecvfromFN)_PR_InvalidInt,
(PRSendtoFN)_PR_InvalidInt,
- SocketPoll,
+ SocketPoll,
(PRAcceptreadFN)_PR_InvalidInt,
(PRTransmitfileFN)_PR_InvalidInt,
(PRGetsocknameFN)_PR_InvalidStatus,
@@ -1349,12 +1373,12 @@ static PRIOMethods socketpollfdMethods = {
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()
@@ -1371,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,
@@ -1517,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);
@@ -1529,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) {
@@ -1555,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;
}
/*
@@ -1564,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);
@@ -1658,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;
}
/*
@@ -1711,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;
+ }
}
/*
@@ -1722,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;
}
@@ -1799,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 */
@@ -1827,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];
@@ -1856,13 +1899,15 @@ 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 */
@@ -1884,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)
{
@@ -1902,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)
{
@@ -1923,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)
@@ -1935,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);
diff --git a/pr/src/linking/prlink.c b/pr/src/linking/prlink.c
index 56eddf41..1f343071 100644
--- a/pr/src/linking/prlink.c
+++ b/pr/src/linking/prlink.c
@@ -120,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)
@@ -162,7 +163,7 @@ void _PR_InitLinker(void)
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 */
}
@@ -189,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);
@@ -221,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);
@@ -230,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;
@@ -248,7 +251,9 @@ 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;
@@ -259,7 +264,7 @@ PR_GetLibraryPath(void)
#ifdef XP_PC
ev = getenv("LD_LIBRARY_PATH");
if (!ev) {
- ev = ".;\\lib";
+ ev = ".;\\lib";
}
ev = strdup(ev);
#endif
@@ -267,21 +272,21 @@ PR_GetLibraryPath(void)
#if defined(XP_UNIX)
#if defined(USE_DLFCN) || defined(USE_MACH_DYLD)
{
- char *p=NULL;
- int len;
+ char *p=NULL;
+ int len;
- ev = getenv("LD_LIBRARY_PATH");
- if (!ev) {
- ev = "/usr/lib:/lib";
- }
- 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
@@ -295,7 +300,7 @@ PR_GetLibraryPath(void)
*/
_pr_currentLibPath = ev;
- exit:
+exit:
if (_pr_currentLibPath) {
copy = strdup(_pr_currentLibPath);
}
@@ -365,25 +370,25 @@ pr_UnlockedFindLibrary(const char *name)
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;
}
@@ -430,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) {
@@ -522,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,
@@ -550,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;
}
@@ -574,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);
@@ -635,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);
@@ -646,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();
@@ -655,8 +668,9 @@ 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)) {
@@ -670,7 +684,9 @@ pr_LoadLibraryByPathname(const char *name, PRIntn flags)
result = pr_UnlockedFindLibrary(name);
#endif
- if (result != NULL) goto unlock;
+ if (result != NULL) {
+ goto unlock;
+ }
lm = PR_NEWZAP(PRLibrary);
if (lm == NULL) {
@@ -685,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
@@ -750,73 +767,73 @@ 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;
+ 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) */
@@ -826,16 +843,18 @@ pr_LoadLibraryByPathname(const char *name, PRIntn flags)
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;
@@ -864,10 +883,10 @@ 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_UNIX
@@ -877,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
@@ -893,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;
@@ -931,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;
@@ -991,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);
@@ -1018,17 +1042,21 @@ pr_FindSymbolInLib(PRLibrary *lm, const char *name)
}
#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 */
@@ -1045,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 */
@@ -1121,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.
*/
@@ -1148,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;
}
@@ -1177,7 +1209,9 @@ 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);
@@ -1192,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;
@@ -1204,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;
}
@@ -1326,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/pr/src/malloc/prmalloc.c b/pr/src/malloc/prmalloc.c
index c55a4fab..c03b7d11 100644
--- a/pr/src/malloc/prmalloc.c
+++ b/pr/src/malloc/prmalloc.c
@@ -64,8 +64,8 @@ static int malloc_event;
#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
*/
-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
@@ -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,8 +442,9 @@ 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
@@ -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");
+ != 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++;
- }
+ 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;
- }
+ 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/pr/src/malloc/prmem.c b/pr/src/malloc/prmem.c
index c8ea939e..08a700f7 100644
--- a/pr/src/malloc/prmem.c
+++ b/pr/src/malloc/prmem.c
@@ -58,8 +58,9 @@ _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++) {
@@ -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,8 +160,9 @@ _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 (i = 0; i < MEM_ZONES; 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
@@ -371,12 +377,15 @@ pr_ZoneRealloc(void *oldptr, PRUint32 bytes)
}
}
- 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) */
@@ -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,59 +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;
-#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); \
- } \
- }
+#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);
diff --git a/pr/src/md/os2/os2_errors.c b/pr/src/md/os2/os2_errors.c
index 169253f7..dfcca610 100644
--- a/pr/src/md/os2/os2_errors.c
+++ b/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/pr/src/md/os2/os2cv.c b/pr/src/md/os2/os2cv.c
index 089e7396..91e85c0e 100644
--- a/pr/src/md/os2/os2cv.c
+++ b/pr/src/md/os2/os2cv.c
@@ -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;
@@ -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) {
@@ -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.
@@ -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/pr/src/md/os2/os2inrval.c b/pr/src/md/os2/os2inrval.c
index 4164cdf2..bd283f06 100644
--- a/pr/src/md/os2/os2inrval.c
+++ b/pr/src/md/os2/os2inrval.c
@@ -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 */
diff --git a/pr/src/md/os2/os2io.c b/pr/src/md/os2/os2io.c
index ad7d921f..639a0d38 100644
--- a/pr/src/md/os2/os2io.c
+++ b/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;
@@ -76,7 +76,7 @@ _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)
@@ -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;
@@ -115,11 +115,13 @@ _PR_MD_WAKEUP_WAITER(PRThread *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;
+ }
+ }
}
@@ -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;
@@ -244,12 +255,13 @@ _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 len)
{
/* 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;
}
@@ -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)
{
@@ -346,8 +359,8 @@ _PR_MD_LSEEK64(PRFileDesc *fd, PRInt64 offset, PRSeekWhence whence)
}
if (rc != NO_ERROR) {
- _PR_MD_MAP_LSEEK_ERROR(rc);
- return -1;
+ _PR_MD_MAP_LSEEK_ERROR(rc);
+ return -1;
}
if (isWSEB)
@@ -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;
}
@@ -387,8 +400,9 @@ _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;
}
}
@@ -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);
@@ -590,12 +608,15 @@ _PR_MD_GETFILEINFO(const char *fn, PRFileInfo *info)
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);
@@ -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,11 +718,11 @@ _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->type = info32.type;
+ LL_UI2L(info->size,info32.size);
- info->modifyTime = info32.modifyTime;
- info->creationTime = info32.creationTime;
+ info->modifyTime = info32.modifyTime;
+ info->creationTime = info32.creationTime;
}
if (isWSEB)
@@ -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;
}
}
@@ -811,17 +835,17 @@ _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. */
}
@@ -855,14 +879,14 @@ _PR_MD_UNLOCKFILE(PRInt32 f)
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 )
@@ -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/pr/src/md/os2/os2misc.c b/pr/src/md/os2/os2misc.c
index 8e44ca01..240f0905 100644
--- a/pr/src/md/os2/os2misc.c
+++ b/pr/src/md/os2/os2misc.c
@@ -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;
@@ -290,22 +291,22 @@ PRProcess * _PR_CreateOS2Process(
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) {
@@ -464,7 +465,7 @@ 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;
@@ -475,7 +476,7 @@ PRStatus _PR_WaitOS2Process(PRProcess *process,
&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;
}
diff --git a/pr/src/md/os2/os2poll.c b/pr/src/md/os2/os2poll.c
index 91101d43..47d97104 100644
--- a/pr/src/md/os2/os2poll.c
+++ b/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;
- }
+ for( i = start; i < start+count; i++ )
+ {
+ if( socks[i] == osfd ) {
+ isSet = PR_TRUE;
+ }
+ }
- return isSet;
+ return isSet;
}
#endif
@@ -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;
@@ -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;
@@ -275,10 +281,12 @@ retry:
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
@@ -287,10 +295,12 @@ retry:
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
@@ -303,7 +313,9 @@ retry:
}
}
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/pr/src/md/os2/os2rng.c b/pr/src/md/os2/os2rng.c
index 72f7357f..aaa96938 100644
--- a/pr/src/md/os2/os2rng.c
+++ b/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/pr/src/md/os2/os2sem.c b/pr/src/md/os2/os2sem.c
index 9c7d05cf..a0dd88e4 100644
--- a/pr/src/md/os2/os2sem.c
+++ b/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/pr/src/md/os2/os2sock.c b/pr/src/md/os2/os2sock.c
index 490c4af6..c6b3ea3a 100644
--- a/pr/src/md/os2/os2sock.c
+++ b/pr/src/md/os2/os2sock.c
@@ -101,18 +101,22 @@ 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;
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
if (rv == -1 && (syserror = sock_errno()) != EINTR) {
_PR_MD_MAP_SELECT_ERROR(syserror);
@@ -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;
@@ -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)
@@ -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;
}
diff --git a/pr/src/md/os2/os2thred.c b/pr/src/md/os2/os2thred.c
index ab26f181..aa929a1a 100644
--- a/pr/src/md/os2/os2thred.c
+++ b/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
@@ -170,19 +170,19 @@ ExcpStartFunc(void* arg)
PRStatus
_PR_MD_CREATE_THREAD(PRThread *thread,
- void (*start)(void *),
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize)
+ 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;
}
@@ -271,33 +271,33 @@ _PR_MD_EXIT(PRIntn status)
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);
+ rv = GetProcessAffinityMask(GetCurrentProcess(), mask, &system_mask);
- return rv?0:-1;
- */
+ return rv?0:-1;
+ */
}
#endif /* HAVE_THREAD_AFFINITY */
@@ -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/pr/src/md/prosdep.c b/pr/src/md/prosdep.c
index 17441718..0b1f3e59 100644
--- a/pr/src/md/prosdep.c
+++ b/pr/src/md/prosdep.c
@@ -21,7 +21,7 @@ PRInt32 _pr_pageSize;
*/
static void GetPageSize(void)
{
- PRInt32 pageSize;
+ PRInt32 pageSize;
/* Get page size */
#ifdef XP_UNIX
@@ -48,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;
}
@@ -63,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/pr/src/md/unix/aix.c b/pr/src/md/unix/aix.c
index 43f0d58d..c632c579 100644
--- a/pr/src/md/unix/aix.c
+++ b/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/pr/src/md/unix/aixwrap.c b/pr/src/md/unix/aixwrap.c
index cb5b413f..85382519 100644
--- a/pr/src/md/unix/aixwrap.c
+++ b/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/pr/src/md/unix/bsdi.c b/pr/src/md/unix/bsdi.c
index 095547ed..e625003f 100644
--- a/pr/src/md/unix/bsdi.c
+++ b/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/pr/src/md/unix/darwin.c b/pr/src/md/unix/darwin.c
index 719fc30f..6135e082 100644
--- a/pr/src/md/unix/darwin.c
+++ b/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/pr/src/md/unix/freebsd.c b/pr/src/md/unix/freebsd.c
index a66a8128..19af17a4 100644
--- a/pr/src/md/unix/freebsd.c
+++ b/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/pr/src/md/unix/hpux.c b/pr/src/md/unix/hpux.c
index 4f5435b9..bf72567f 100644
--- a/pr/src/md/unix/hpux.c
+++ b/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;
}
@@ -217,12 +217,14 @@ 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;
+ - ((int) ((unsigned int) *p2));
+ if (r) {
+ return r;
+ }
p1++; p2++;
}
return 0;
diff --git a/pr/src/md/unix/linux.c b/pr/src/md/unix/linux.c
index 1b485a02..6bfc7a80 100644
--- a/pr/src/md/unix/linux.c
+++ b/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/pr/src/md/unix/nto.c b/pr/src/md/unix/nto.c
index e41d665c..8ab8b1ea 100644
--- a/pr/src/md/unix/nto.c
+++ b/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/pr/src/md/unix/pthreads_user.c b/pr/src/md/unix/pthreads_user.c
index 69061205..525c1576 100644
--- a/pr/src/md/unix/pthreads_user.c
+++ b/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);
+ }
}
@@ -82,19 +84,21 @@ PR_IMPLEMENT(PRStatus) _MD_NEW_LOCK(struct _MDLock *lockp)
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;
+ 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,37 +291,42 @@ _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;
+ 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;
- }
+ }
+ _PR_DEADQ_UNLOCK;
+ while(_PR_NUM_DEADNATIVE > 1) {
+ _PR_WAIT_SEM(_pr_irix_exit_sem);
+ _PR_DEC_DEADNATIVE;
+ }
#endif
}
diff --git a/pr/src/md/unix/qnx.c b/pr/src/md/unix/qnx.c
index 259e29cd..aef97a25 100644
--- a/pr/src/md/unix/qnx.c
+++ b/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/pr/src/md/unix/riscos.c b/pr/src/md/unix/riscos.c
index 318903ac..a0411887 100644
--- a/pr/src/md/unix/riscos.c
+++ b/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/pr/src/md/unix/scoos.c b/pr/src/md/unix/scoos.c
index b727a53a..43b256d8 100644
--- a/pr/src/md/unix/scoos.c
+++ b/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/pr/src/md/unix/solaris.c b/pr/src/md/unix/solaris.c
index 3b7d1280..383f49d0 100644
--- a/pr/src/md/unix/solaris.c
+++ b/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];
@@ -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/pr/src/md/unix/unix.c b/pr/src/md/unix/unix.c
index 61be5229..a8862a4c 100644
--- a/pr/src/md/unix/unix.c
+++ b/pr/src/md/unix/unix.c
@@ -94,13 +94,15 @@ int _nspr_noclock = 1;
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, },
+ "clock", _PR_MISSED_CLOCK, _PR_ClockInterrupt,
+ },
{
- 0 }
+ 0
+ }
};
void _MD_unix_init_running_cpu(_PRCPU *cpu)
@@ -112,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) {
@@ -125,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;
@@ -139,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 (;;) {
/*
@@ -155,14 +157,17 @@ int 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;
@@ -170,7 +175,7 @@ int err;
PRInt32 _MD_delete(const char *name)
{
-PRInt32 rv, err;
+ PRInt32 rv, err;
#ifdef UNIXWARE
sigset_t set, oset;
#endif
@@ -184,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);
}
@@ -200,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_unix_rename_lock)
+ if (NULL != _pr_unix_rename_lock) {
PR_Lock(_pr_unix_rename_lock);
- if (0 == access(to, F_OK))
+ }
+ if (0 == access(to, F_OK)) {
PR_SetError(PR_FILE_EXISTS_ERROR, 0);
+ }
else
{
rv = rename(from, to);
@@ -212,15 +219,16 @@ PRInt32 _MD_rename(const char *from, const char *to)
_PR_MD_MAP_RENAME_ERROR(err);
}
}
- if (NULL != _pr_unix_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:
@@ -250,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_unix_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_unix_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);
@@ -306,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 */
@@ -324,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;
@@ -346,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);
@@ -370,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 */
@@ -388,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;
@@ -410,7 +424,7 @@ done:
PRInt32 _MD_fsync(PRFileDesc *fd)
{
-PRInt32 rv, err;
+ PRInt32 rv, err;
rv = fsync(fd->secret->md.osfd);
if (rv == -1) {
@@ -422,7 +436,7 @@ PRInt32 rv, err;
PRInt32 _MD_close(PRInt32 osfd)
{
-PRInt32 rv, err;
+ PRInt32 rv, err;
rv = close(osfd);
if (rv == -1) {
@@ -480,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;
@@ -504,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;
@@ -539,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
*/
@@ -575,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();
@@ -598,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;
@@ -630,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;
}
@@ -682,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;
}
@@ -735,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;
@@ -756,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
@@ -778,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;
@@ -798,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;
@@ -842,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
/*
@@ -868,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) {
@@ -934,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)) {
@@ -945,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;
@@ -993,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;
@@ -1011,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) {
@@ -1032,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;
@@ -1120,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.
@@ -1198,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;
@@ -1211,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 */
@@ -1233,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 */
@@ -1268,7 +1301,7 @@ PRStatus _MD_getsockopt(PRFileDesc *fd, PRInt32 level,
}
PRStatus _MD_setsockopt(PRFileDesc *fd, PRInt32 level,
- PRInt32 optname, const char* optval, PRInt32 optlen)
+ PRInt32 optname, const char* optval, PRInt32 optlen)
{
PRInt32 rv, err;
@@ -1342,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;
}
@@ -1357,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));
+ }
}
}
@@ -1387,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) */
@@ -1472,14 +1511,15 @@ void _MD_PauseCPU(PRIntervalTime ticks)
*/
if (_PR_IS_NATIVE_THREAD_SUPPORTED()) {
npollfds++;
- }
+ }
/*
* 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;
@@ -1510,9 +1550,9 @@ void _MD_PauseCPU(PRIntervalTime ticks)
}
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 */
@@ -1554,17 +1594,19 @@ void _MD_PauseCPU(PRIntervalTime ticks)
}
#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 */
@@ -1580,8 +1622,9 @@ void _MD_PauseCPU(PRIntervalTime ticks)
* are enabled. Otherwise, when the select/poll calls are interrupted, the
* timer value starts ticking from zero again when the system call is restarted.
*/
- if (!_nspr_noclock)
- PR_ASSERT(sigismember(&timer_set, SIGALRM));
+ if (!_nspr_noclock) {
+ PR_ASSERT(sigismember(&timer_set, SIGALRM));
+ }
sigprocmask(SIG_BLOCK, &timer_set, &oldset);
#endif /* !_PR_NO_CLOCK_TIMER */
@@ -1593,13 +1636,14 @@ void _MD_PauseCPU(PRIntervalTime ticks)
#endif /* !_PR_USE_POLL */
#ifndef _PR_NO_CLOCK_TIMER
- if (!_nspr_noclock)
- sigprocmask(SIG_SETMASK, &oldset, 0);
+ if (!_nspr_noclock) {
+ sigprocmask(SIG_SETMASK, &oldset, 0);
+ }
#endif /* !_PR_NO_CLOCK_TIMER */
_MD_CHECK_FOR_EXIT();
- _PR_MD_primordial_cpu();
+ _PR_MD_primordial_cpu();
_PR_MD_IOQ_LOCK();
/*
@@ -1610,17 +1654,17 @@ void _MD_PauseCPU(PRIntervalTime ticks)
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)));
}
@@ -1666,26 +1710,27 @@ void _MD_PauseCPU(PRIntervalTime ticks)
_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;
@@ -1749,16 +1794,19 @@ void _MD_PauseCPU(PRIntervalTime ticks)
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));
+ }
}
}
@@ -1767,7 +1815,7 @@ void _MD_PauseCPU(PRIntervalTime ticks)
* 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;
@@ -1775,58 +1823,62 @@ void _MD_PauseCPU(PRIntervalTime ticks)
_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];
+ }
}
} 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);
@@ -1848,14 +1900,17 @@ void _MD_PauseCPU(PRIntervalTime ticks)
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 */
@@ -1874,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);
}
}
@@ -1942,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"));
@@ -1957,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 */
@@ -1997,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
@@ -2036,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()
@@ -2048,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()
@@ -2082,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)
{
@@ -2097,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;
@@ -2120,8 +2181,9 @@ PRInt32 _MD_open(const char *name, PRIntn flags, PRIntn mode)
if (flags & PR_CREATE_FILE)
{
osflags |= O_CREAT;
- if (NULL !=_pr_unix_rename_lock)
+ if (NULL !=_pr_unix_rename_lock) {
PR_Lock(_pr_unix_rename_lock);
+ }
}
#if defined(ANDROID)
@@ -2135,8 +2197,9 @@ PRInt32 _MD_open(const char *name, PRIntn flags, PRIntn mode)
_PR_MD_MAP_OPEN_ERROR(err);
}
- if ((flags & PR_CREATE_FILE) && (NULL !=_pr_unix_rename_lock))
+ if ((flags & PR_CREATE_FILE) && (NULL !=_pr_unix_rename_lock)) {
PR_Unlock(_pr_unix_rename_lock);
+ }
return rv;
}
@@ -2172,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)
@@ -2438,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)
@@ -2462,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);
@@ -2481,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;
}
@@ -2492,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;
}
@@ -2503,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;
}
@@ -2514,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;
}
@@ -2597,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 */
@@ -2707,7 +2786,7 @@ 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)
@@ -2787,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();
@@ -2826,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;
}
@@ -2843,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 */
@@ -3033,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 */
@@ -3137,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 */
@@ -3176,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;
@@ -3195,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
}
@@ -3260,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;
}
@@ -3277,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;
}
@@ -3294,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;
}
@@ -3309,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;
}
@@ -3320,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;
}
@@ -3331,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;
}
@@ -3343,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;
}
@@ -3354,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;
}
@@ -3365,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;
}
@@ -3386,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;
}
@@ -3474,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;
@@ -3496,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/pr/src/md/unix/unix_errors.c b/pr/src/md/unix/unix_errors.c
index fcc8320f..1d876596 100644
--- a/pr/src/md/unix/unix_errors.c
+++ b/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;
@@ -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;
@@ -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/pr/src/md/unix/unixware.c b/pr/src/md/unix/unixware.c
index 4ddb23d6..d6958558 100644
--- a/pr/src/md/unix/unixware.c
+++ b/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;
}
@@ -231,29 +232,30 @@ void _MD_EarlyInit(void)
}
PRStatus _MD_CREATE_THREAD(PRThread *thread,
- void (*start)(void *),
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize)
+ 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);
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;
+ : 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)) {
+ (void *(*)(void *)) start, (void *) thread,
+ flags,
+ &thread->md.handle)) {
thr_sigsetmask(SIG_SETMASK, &oldset, NULL);
- return PR_FAILURE;
+ return PR_FAILURE;
}
@@ -265,8 +267,8 @@ PRStatus _MD_CREATE_THREAD(PRThread *thread,
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;
}
/*
@@ -277,19 +279,19 @@ PRStatus _MD_CREATE_THREAD(PRThread *thread,
** 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;
}
@@ -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()
@@ -484,12 +487,13 @@ 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
@@ -497,42 +501,46 @@ void _MD_Suspend(PRThread *thr)
* 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 (!_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 ( _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];
}
diff --git a/pr/src/md/unix/uxpoll.c b/pr/src/md/unix/uxpoll.c
index 101ff3f8..d01121cb 100644
--- a/pr/src/md/unix/uxpoll.c
+++ b/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,10 +703,15 @@ 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 */
diff --git a/pr/src/md/unix/uxproces.c b/pr/src/md/unix/uxproces.c
index 8665992f..4216c044 100644
--- a/pr/src/md/unix/uxproces.c
+++ b/pr/src/md/unix/uxproces.c
@@ -73,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
@@ -203,20 +203,23 @@ 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 */
@@ -224,12 +227,15 @@ ForkAndExec(
process->md.pid = spawn(path, 3, fd_map, NULL, argv, childEnvp);
- 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();
@@ -243,12 +249,12 @@ 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 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) {
@@ -256,7 +262,7 @@ ForkAndExec(
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 */
@@ -267,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 */
@@ -278,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 */
@@ -295,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) {
@@ -357,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;
@@ -372,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 */
@@ -393,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;
@@ -415,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 */
@@ -439,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;
}
@@ -462,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);
}
}
@@ -492,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
@@ -547,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
@@ -564,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);
+ }
}
}
@@ -610,7 +616,7 @@ static void WaitPidDaemonThread(void *unused)
if (pr_waitpid_daemon_exit) {
return;
}
- PR_Lock(pr_wp.ml);
+ PR_Lock(pr_wp.ml);
#endif
do {
@@ -618,40 +624,42 @@ static void WaitPidDaemonThread(void *unused)
} 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);
+ }
}
}
@@ -734,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 *));
@@ -756,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);
@@ -795,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);
@@ -850,19 +858,19 @@ PRStatus _MD_KillUnixProcess(PRProcess *process)
PRInt32 oserror;
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;
diff --git a/pr/src/md/unix/uxrng.c b/pr/src/md/unix/uxrng.c
index 36638f8e..47985900 100644
--- a/pr/src/md/unix/uxrng.c
+++ b/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;
}
diff --git a/pr/src/md/unix/uxshm.c b/pr/src/md/unix/uxshm.c
index 92bd5b9f..29a6030f 100644
--- a/pr/src/md/unix/uxshm.c
+++ b/pr/src/md/unix/uxshm.c
@@ -53,7 +53,7 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
{
_PR_MD_MAP_DEFAULT_ERROR( errno );
PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name ));
+ ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name ));
return( NULL );
}
@@ -105,7 +105,7 @@ 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));
+ ("_MD_OpenSharedMemory(): ftok() failed on name: %s", shm->ipcname));
PR_FREEIF( shm->ipcname );
PR_DELETE( shm );
return( NULL );
@@ -120,7 +120,7 @@ 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));
+ ("_MD_OpenSharedMemory(): shmget() exclusive failed, errno: %d", errno));
PR_FREEIF(shm->ipcname);
PR_DELETE(shm);
return(NULL);
@@ -131,7 +131,7 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
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));
+ ("_MD_OpenSharedMemory(): shmget() failed, errno: %d", errno));
PR_FREEIF(shm->ipcname);
PR_DELETE(shm);
return(NULL);
@@ -154,8 +154,8 @@ extern void * _MD_AttachSharedMemory( PRSharedMemory *shm, PRIntn flags )
{
_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() ));
+ ("_MD_AttachSharedMemory(): shmat() failed on name: %s, OsError: %d",
+ shm->ipcname, PR_GetOSError() ));
addr = NULL;
}
@@ -175,7 +175,7 @@ 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 ));
+ ("_MD_DetachSharedMemory(): shmdt() failed on name: %s", shm->ipcname ));
}
return rc;
@@ -202,9 +202,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_SetError( PR_UNKNOWN_ERROR, errno );
PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_DeleteSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name ));
+ ("_MD_DeleteSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name ));
return(PR_FAILURE);
}
@@ -228,14 +228,14 @@ 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));
+ ("_MD_DeleteSharedMemory(): ftok() failed on name: %s", ipcname));
}
id = shmget( key, 0, 0 );
if ( -1 == id ) {
_PR_MD_MAP_DEFAULT_ERROR( errno );
PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_DeleteSharedMemory(): shmget() failed, errno: %d", errno));
+ ("_MD_DeleteSharedMemory(): shmget() failed, errno: %d", errno));
return(PR_FAILURE);
}
@@ -244,7 +244,7 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name )
{
_PR_MD_MAP_DEFAULT_ERROR( errno );
PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_DeleteSharedMemory(): shmctl() failed on name: %s", ipcname ));
+ ("_MD_DeleteSharedMemory(): shmctl() failed on name: %s", ipcname ));
return(PR_FAILURE);
}
@@ -252,7 +252,7 @@ extern PRStatus _MD_DeleteSharedMemory( const char *name )
if ( -1 == urc ) {
_PR_MD_MAP_UNLINK_ERROR( errno );
PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_DeleteSharedMemory(): unlink() failed: %s", ipcname ));
+ ("_MD_DeleteSharedMemory(): unlink() failed: %s", ipcname ));
return(PR_FAILURE);
}
@@ -290,9 +290,9 @@ 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_SetError( PR_UNKNOWN_ERROR, errno );
PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name ));
+ ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name ));
return( NULL );
}
@@ -325,8 +325,9 @@ 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 );
@@ -335,7 +336,7 @@ 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",
+ ("_MD_OpenSharedMemory(): shm_open failed: %s, OSError: %d",
shm->ipcname, PR_GetOSError()));
PR_DELETE( shm->ipcname );
PR_DELETE( shm );
@@ -346,7 +347,7 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
if ( -1 == end ) {
_PR_MD_MAP_DEFAULT_ERROR( errno );
PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_OpenSharedMemory(): ftruncate failed, OSError: %d",
+ ("_MD_OpenSharedMemory(): ftruncate failed, OSError: %d",
PR_GetOSError()));
PR_DELETE( shm->ipcname );
PR_DELETE( shm );
@@ -363,20 +364,21 @@ 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()));
+ ("_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));
+ ("_MD_AttachSharedMemory(): name: %s, attached at: %p", shm->ipcname, addr));
}
return addr;
@@ -395,8 +397,8 @@ 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()));
+ ("_MD_DetachSharedMemory(): munmap failed: %s, errno: %d",
+ shm->ipcname, PR_GetOSError()));
}
return rc;
}
@@ -411,7 +413,7 @@ extern PRStatus _MD_CloseSharedMemory( PRSharedMemory *shm )
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()));
+ ("_MD_CloseSharedMemory(): close() failed, error: %d", PR_GetOSError()));
return(PR_FAILURE);
}
PR_DELETE( shm->ipcname );
@@ -428,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_SetError( PR_UNKNOWN_ERROR, errno );
PR_LOG( _pr_shm_lm, PR_LOG_DEBUG,
- ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name ));
+ ("_MD_OpenSharedMemory(): _PR_MakeNativeIPCName() failed: %s", name ));
return rc;
}
@@ -439,11 +441,11 @@ 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(): shm_unlink failed: %s, errno: %d",
- ipcname, PR_GetOSError()));
+ ("_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));
+ ("_MD_DeleteSharedMemory(): %s, success", ipcname));
}
return rc;
@@ -485,86 +487,86 @@ extern PRFileMap* _md_OpenAnonFileMap(
for ( incr = 0; incr < maxTries ; incr++ ) {
#define NSPR_AFM_FILENAME "%s/.NSPR-AFM-%d-%p.%d"
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 ( -1 == urc ) {
_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;
}
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"));
+ ("_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;
}
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;
}
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:
return(fm);
@@ -585,7 +587,7 @@ extern PRStatus _md_ExportFileMapAsString(
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() */
@@ -608,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/pr/src/md/unix/uxwrap.c b/pr/src/md/unix/uxwrap.c
index 70569229..d6f6d062 100644
--- a/pr/src/md/unix/uxwrap.c
+++ b/pr/src/md/unix/uxwrap.c
@@ -22,12 +22,12 @@
#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") */
@@ -67,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
@@ -122,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;
}
@@ -182,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
@@ -221,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;
}
@@ -233,19 +239,19 @@ 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++;
}
@@ -337,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
@@ -365,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;
@@ -398,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/pr/src/md/windows/ntdllmn.c b/pr/src/md/windows/ntdllmn.c
index 7dec0517..e64b312d 100644
--- a/pr/src/md/windows/ntdllmn.c
+++ b/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/pr/src/md/windows/ntinrval.c b/pr/src/md/windows/ntinrval.c
index 1e99c4c8..a4478045 100644
--- a/pr/src/md/windows/ntinrval.c
+++ b/pr/src/md/windows/ntinrval.c
@@ -26,7 +26,7 @@ _PR_MD_INTERVAL_INIT()
HMODULE mmtimerlib = LoadLibraryW(L"mmtimer.dll"); /* XXX leaked! */
if (mmtimerlib) {
intervalFunc = (IntervalFuncType)GetProcAddress(mmtimerlib,
- "timeGetTime");
+ "timeGetTime");
} else {
intervalFunc = &GetTickCount;
}
diff --git a/pr/src/md/windows/ntio.c b/pr/src/md/windows/ntio.c
index 105fdecb..040bbd31 100644
--- a/pr/src/md/windows/ntio.c
+++ b/pr/src/md/windows/ntio.c
@@ -134,11 +134,21 @@ 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 */
@@ -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,7 +228,7 @@ _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
@@ -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) ) {
@@ -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,9 +707,9 @@ _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);
@@ -703,14 +721,17 @@ _NT_IO_WAIT(PRThread *thread, PRIntervalTime timeout)
_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;
+ }
}
/*
@@ -726,16 +747,16 @@ void _PR_Unblock_IO_Wait(PRThread *thr)
_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,8 +794,9 @@ _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);
@@ -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;
}
@@ -803,16 +827,19 @@ _PR_MD_WAKEUP_WAITER(PRThread *thread)
* idle thread
*/
if ( PostQueuedCompletionStatus(_pr_completion_port, 0,
- KEY_CVAR, NULL) == FALSE)
+ 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();
@@ -824,12 +851,13 @@ _PR_MD_WAKEUP_WAITER(PRThread *thread)
* 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)
+ KEY_CVAR, &(thread->md.overlapped.overlapped)) == FALSE) {
return PR_FAILURE;
+ }
}
return PR_SUCCESS;
}
@@ -847,9 +875,9 @@ _PR_MD_INIT_IO()
PR_ASSERT(0 == err);
_pr_completion_port = CreateIoCompletionPort(INVALID_HANDLE_VALUE,
- NULL,
- 0,
- 0);
+ 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;
@@ -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;
+ }
}
/*
@@ -1139,8 +1168,9 @@ _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;
}
@@ -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);
@@ -1394,9 +1428,9 @@ _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)
+ 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;
}
@@ -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) {
@@ -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;
}
@@ -1706,16 +1748,17 @@ _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);
@@ -1727,20 +1770,21 @@ _PR_MD_RECV(PRFileDesc *fd, void *buf, PRInt32 amount, PRIntn flags,
&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,16 +1850,17 @@ _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);
@@ -1826,18 +1872,18 @@ _PR_MD_SEND(PRFileDesc *fd, const void *buf, PRInt32 amount, PRIntn flags,
&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
@@ -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 ----------------------------------------------------------- */
@@ -2063,17 +2120,29 @@ _PR_MD_OPEN(const char *name, PRIntn osflags, PRIntn mode)
PRInt32 flags = 0;
PRInt32 flag6 = 0;
- 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) access |= GENERIC_READ;
- if (osflags & PR_WRONLY || osflags & PR_RDWR) access |= GENERIC_WRITE;
+ 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;
@@ -2113,24 +2182,36 @@ _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_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_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;
@@ -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,20 +2301,21 @@ _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;
+ 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,
@@ -2241,16 +2323,16 @@ _PR_MD_READ(PRFileDesc *fd, void *buf, PRInt32 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;
@@ -2339,10 +2421,10 @@ _PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 len)
if (fd->secret->inheritable == _PR_TRI_TRUE) {
rv = WriteFile((HANDLE)f,
- (LPVOID)buf,
- len,
- &bytes,
- &me->md.overlapped.overlapped);
+ (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,20 +2449,21 @@ _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;
+ 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,
@@ -2388,16 +2471,16 @@ _PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 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;
@@ -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) {
@@ -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,9 +2735,9 @@ _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;
@@ -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;
}
@@ -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,12 +3299,12 @@ _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);
@@ -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();
@@ -3263,18 +3359,18 @@ _PR_MD_LOCKFILE(PROsfd f)
*/
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
@@ -3293,15 +3389,15 @@ _PR_MD_LOCKFILE(PROsfd f)
#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,12 +3418,12 @@ _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);
@@ -3339,16 +3435,16 @@ _PR_MD_TLOCKFILE(PROsfd f)
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,16 +3455,16 @@ _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;
@@ -3380,16 +3476,16 @@ _PR_MD_TLOCKFILE(PROsfd f)
*/
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);
+ _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;
}
@@ -3398,22 +3494,22 @@ _PR_MD_TLOCKFILE(PROsfd f)
#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;
}
}
@@ -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,7 +3916,7 @@ 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;
}
@@ -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) {
@@ -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;
@@ -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/pr/src/md/windows/ntmisc.c b/pr/src/md/windows/ntmisc.c
index 2413e27b..1ec6c2a5 100644
--- a/pr/src/md/windows/ntmisc.c
+++ b/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;
@@ -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) {
@@ -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,7 +964,7 @@ 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;
@@ -1037,11 +1043,11 @@ PRStatus _MD_SyncMemMap(
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
{
@@ -1106,37 +1112,39 @@ void
PR_StackPush(PRStack *stack, PRStackElem *stack_elem)
{
#if defined(__GNUC__)
- void **tos = (void **) stack;
- void *tmp;
+ void **tos = (void **) stack;
+ void *tmp;
- retry:
- if (*tos == (void *) -1)
- goto retry;
+retry:
+ if (*tos == (void *) -1) {
+ goto retry;
+ }
- __asm__("xchg %0,%1"
- : "=r" (tmp), "=m"(*tos)
- : "0" (-1), "m"(*tos));
+ __asm__("xchg %0,%1"
+ : "=r" (tmp), "=m"(*tos)
+ : "0" (-1), "m"(*tos));
- if (tmp == (void *) -1)
- goto retry;
+ if (tmp == (void *) -1) {
+ goto retry;
+ }
- *(void **)stack_elem = tmp;
- __asm__("" : : : "memory");
- *tos = stack_elem;
+ *(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__ */
}
@@ -1147,51 +1155,54 @@ PRStackElem *
PR_StackPop(PRStack *stack)
{
#if defined(__GNUC__)
- void **tos = (void **) stack;
- void *tmp;
+ void **tos = (void **) stack;
+ void *tmp;
- retry:
- if (*tos == (void *) -1)
- goto retry;
+retry:
+ if (*tos == (void *) -1) {
+ goto retry;
+ }
- __asm__("xchg %0,%1"
- : "=r" (tmp), "=m"(*tos)
- : "0" (-1), "m"(*tos));
+ __asm__("xchg %0,%1"
+ : "=r" (tmp), "=m"(*tos)
+ : "0" (-1), "m"(*tos));
- if (tmp == (void *) -1)
- goto retry;
+ if (tmp == (void *) -1) {
+ goto retry;
+ }
- if (tmp != (void *) 0)
+ 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/pr/src/md/windows/ntsec.c b/pr/src/md/windows/ntsec.c
index c0682e45..0006e839 100644
--- a/pr/src/md/windows/ntsec.c
+++ b/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/pr/src/md/windows/ntsem.c b/pr/src/md/windows/ntsem.c
index 716e6ef3..757bc839 100644
--- a/pr/src/md/windows/ntsem.c
+++ b/pr/src/md/windows/ntsem.c
@@ -31,10 +31,12 @@ _PR_MD_TIMED_WAIT_SEM(_MDSemaphore *md, PRIntervalTime ticks)
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
diff --git a/pr/src/md/windows/ntthread.c b/pr/src/md/windows/ntthread.c
index 6dd01fb9..395a80dc 100644
--- a/pr/src/md/windows/ntthread.c
+++ b/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;
@@ -183,21 +183,21 @@ pr_root(void *arg)
PRStatus
_PR_MD_CREATE_THREAD(PRThread *thread,
- void (*start)(void *),
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize)
+ 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;
@@ -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);
@@ -469,9 +471,10 @@ _PR_MD_INIT_CONTEXT(PRThread *thread, char *top, void (*start) (void), PRBool *s
{
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)
+ (LPFIBER_START_ROUTINE)_pr_fiber_mainline, NULL);
+ if (thread->md.fiber_id != 0) {
*status = PR_TRUE;
+ }
else {
DWORD oserror = GetLastError();
PRErrorCode prerror;
@@ -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/pr/src/md/windows/w32ipcsem.c b/pr/src/md/windows/w32ipcsem.c
index 5719ce3f..50000935 100644
--- a/pr/src/md/windows/w32ipcsem.c
+++ b/pr/src/md/windows/w32ipcsem.c
@@ -25,10 +25,12 @@ static HANDLE OpenSemaphore(DWORD inDesiredAccess,
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;
@@ -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/pr/src/md/windows/w32poll.c b/pr/src/md/windows/w32poll.c
index 8a4b5157..241c7e3e 100644
--- a/pr/src/md/windows/w32poll.c
+++ b/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/pr/src/md/windows/w32rng.c b/pr/src/md/windows/w32rng.c
index 633ae0da..c07625ec 100644
--- a/pr/src/md/windows/w32rng.c
+++ b/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/pr/src/md/windows/w32shm.c b/pr/src/md/windows/w32shm.c
index 748a9860..b0d38b9d 100644
--- a/pr/src/md/windows/w32shm.c
+++ b/pr/src/md/windows/w32shm.c
@@ -28,10 +28,10 @@ static DWORD filemapAccessTable[] = {
};
extern PRSharedMemory * _MD_OpenSharedMemory(
- const char *name,
- PRSize size,
- PRIntn flags,
- PRIntn mode
+ const char *name,
+ PRSize size,
+ PRIntn flags,
+ PRIntn mode
)
{
char ipcname[PR_IPC_NAME_SIZE];
@@ -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,21 +97,21 @@ 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);
@@ -119,8 +119,8 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
if ( NULL == shm->handle ) {
PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
- ( "PR_OpenSharedMemory: CreateFileMapping() failed: %s",
- shm->ipcname ));
+ ( "PR_OpenSharedMemory: CreateFileMapping() failed: %s",
+ shm->ipcname ));
_PR_MD_MAP_DEFAULT_ERROR( GetLastError());
PR_FREEIF( shm->ipcname )
PR_DELETE( shm );
@@ -128,8 +128,8 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
} 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_OpenSharedMemory: Request exclusive & already exists",
+ shm->ipcname ));
PR_SetError( PR_FILE_EXISTS_ERROR, ERROR_ALREADY_EXISTS );
CloseHandle( shm->handle );
PR_FREEIF( shm->ipcname )
@@ -137,8 +137,8 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
return(NULL);
} else {
PR_LOG(_pr_shm_lm, PR_LOG_DEBUG,
- ( "PR_OpenSharedMemory: CreateFileMapping() success: %s, handle: %d",
- shm->ipcname, shm->handle ));
+ ( "PR_OpenSharedMemory: CreateFileMapping() success: %s, handle: %d",
+ shm->ipcname, shm->handle ));
return(shm);
}
}
@@ -152,16 +152,16 @@ extern PRSharedMemory * _MD_OpenSharedMemory(
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_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_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()));
+ ("_MD_AttachSharedMemory: MapViewOfFile() failed. OSerror: %d", PR_GetOSError()));
}
return( addr );
@@ -204,7 +205,7 @@ extern PRStatus _MD_DetachSharedMemory( PRSharedMemory *shm, void *addr )
{
_PR_MD_MAP_DEFAULT_ERROR( GetLastError());
PR_LOG( _pr_shm_lm, PR_LOG_ERROR,
- ("_MD_DetachSharedMemory: UnmapViewOfFile() failed. OSerror: %d", PR_GetOSError()));
+ ("_MD_DetachSharedMemory: UnmapViewOfFile() failed. OSerror: %d", PR_GetOSError()));
rc = PR_FAILURE;
}
@@ -224,7 +225,7 @@ extern PRStatus _MD_CloseSharedMemory( PRSharedMemory *shm )
{
_PR_MD_MAP_DEFAULT_ERROR( GetLastError());
PR_LOG( _pr_shm_lm, PR_LOG_ERROR,
- ("_MD_CloseSharedMemory: CloseHandle() failed. OSerror: %d", PR_GetOSError()));
+ ("_MD_CloseSharedMemory: CloseHandle() failed. OSerror: %d", PR_GetOSError()));
rc = PR_FAILURE;
}
PR_FREEIF( shm->ipcname );
@@ -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;
@@ -297,11 +298,11 @@ 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,8 +337,8 @@ 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() */
diff --git a/pr/src/md/windows/w95cv.c b/pr/src/md/windows/w95cv.c
index 42a43ae5..5cf2966f 100644
--- a/pr/src/md/windows/w95cv.c
+++ b/pr/src/md/windows/w95cv.c
@@ -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;
@@ -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) {
@@ -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/pr/src/md/windows/w95dllmain.c b/pr/src/md/windows/w95dllmain.c
index 73707a6e..c9ab87ae 100644
--- a/pr/src/md/windows/w95dllmain.c
+++ b/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/pr/src/md/windows/w95io.c b/pr/src/md/windows/w95io.c
index 07a19458..2ad52e19 100644
--- a/pr/src/md/windows/w95io.c
+++ b/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,7 +84,7 @@ _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)
{
@@ -93,7 +93,7 @@ _PR_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
case WAIT_TIMEOUT:
_PR_THREAD_LOCK(thread);
if (thread->state == _PR_IO_WAIT) {
- ;
+ ;
} else {
if (thread->wait.cvar != NULL) {
thread->wait.cvar = NULL;
@@ -118,11 +118,13 @@ _PR_MD_WAKEUP_WAITER(PRThread *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;
+ }
+ }
}
@@ -146,25 +148,34 @@ _PR_MD_OPEN(const char *name, PRIntn osflags, int mode)
PRInt32 flags = 0;
PRInt32 flag6 = 0;
- 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 = 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());
+ _PR_MD_MAP_OPEN_ERROR(GetLastError());
return -1;
- }
+ }
return (PROsfd)file;
}
@@ -196,7 +207,7 @@ _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;
@@ -204,25 +215,34 @@ _PR_MD_OPEN_FILE(const char *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 = 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());
+ _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);
+ (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;
}
@@ -278,14 +299,14 @@ _PR_MD_WRITE(PRFileDesc *fd, const void *buf, PRInt32 len)
int rv;
rv = WriteFile((HANDLE)f,
- buf,
- len,
- &bytes,
- NULL );
+ 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;
}
@@ -401,15 +422,16 @@ _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;
}
@@ -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,9 +852,9 @@ _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;
@@ -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,
@@ -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();
@@ -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;
}
@@ -1314,7 +1357,7 @@ _PR_MD_GETFILEINFO64_UTF16(const PRUnichar *fn, PRFileInfo64 *info)
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/pr/src/md/windows/w95sock.c b/pr/src/md/windows/w95sock.c
index 10423e98..7d7362c6 100644
--- a/pr/src/md/windows/w95sock.c
+++ b/pr/src/md/windows/w95sock.c
@@ -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;
}
@@ -296,7 +297,7 @@ _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)
&& (!fd->secret->nonblocking))
@@ -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,7 +512,7 @@ _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)
&& (!fd->secret->nonblocking))
@@ -540,8 +542,9 @@ _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)
+ if (rv > 0) {
sent += rv;
+ }
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;
}
@@ -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))
@@ -823,7 +831,7 @@ static PRInt32 socket_io_wait(
elapsed = remaining;
} else {
elapsed = PR_SecondsToInterval(tv.tv_sec)
- + PR_MicrosecondsToInterval(tv.tv_usec);
+ + PR_MicrosecondsToInterval(tv.tv_usec);
}
if (elapsed >= remaining) {
PR_SetError(PR_IO_TIMEOUT_ERROR, 0);
diff --git a/pr/src/md/windows/w95thred.c b/pr/src/md/windows/w95thred.c
index 5b5a5a89..fb9c457d 100644
--- a/pr/src/md/windows/w95thred.c
+++ b/pr/src/md/windows/w95thred.c
@@ -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
@@ -140,21 +142,21 @@ pr_root(void *arg)
PRStatus
_PR_MD_CREATE_THREAD(PRThread *thread,
- void (*start)(void *),
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize)
+ 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,8 +171,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;
+ }
return PR_FAILURE;
}
@@ -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,9 +321,10 @@ 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
@@ -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/pr/src/memory/prseg.c b/pr/src/memory/prseg.c
index ecad1d0c..0b70f2d4 100644
--- a/pr/src/memory/prseg.c
+++ b/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/pr/src/memory/prshm.c b/pr/src/memory/prshm.c
index cce64d2a..7a587cd5 100644
--- a/pr/src/memory/prshm.c
+++ b/pr/src/memory/prshm.c
@@ -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/pr/src/misc/dtoa.c b/pr/src/misc/dtoa.c
index c39e8925..43883aba 100644
--- a/pr/src/misc/dtoa.c
+++ b/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/pr/src/misc/pralarm.c b/pr/src/misc/pralarm.c
index 907277ef..8130215c 100644
--- a/pr/src/misc/pralarm.c
+++ b/pr/src/misc/pralarm.c
@@ -38,13 +38,13 @@ 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();
@@ -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/pr/src/misc/pratom.c b/pr/src/misc/pratom.c
index 7662ef36..4f0e3da3 100644
--- a/pr/src/misc/pratom.c
+++ b/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,35 +302,36 @@ 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;
}
@@ -335,19 +339,20 @@ PRStack *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/pr/src/misc/praton.c b/pr/src/misc/praton.c
index c9668700..3e729f58 100644
--- a/pr/src/misc/praton.c
+++ b/pr/src/misc/praton.c
@@ -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/pr/src/misc/prcountr.c b/pr/src/misc/prcountr.c
index edd57122..29d7d4cc 100644
--- a/pr/src/misc/prcountr.c
+++ b/pr/src/misc/prcountr.c
@@ -112,10 +112,10 @@ static void _PR_CounterInitialize( void )
**
*/
PR_IMPLEMENT(PRCounterHandle)
- PR_CreateCounter(
- const char *qName,
- const char *rName,
- const char *description
+PR_CreateCounter(
+ const char *qName,
+ const char *rName,
+ const char *description
)
{
QName *qnp;
@@ -123,8 +123,9 @@ PR_IMPLEMENT(PRCounterHandle)
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 );
@@ -195,7 +196,7 @@ PR_IMPLEMENT(PRCounterHandle)
/* 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() */
@@ -205,15 +206,15 @@ PR_IMPLEMENT(PRCounterHandle)
**
*/
PR_IMPLEMENT(void)
- PR_DestroyCounter(
- PRCounterHandle handle
+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));
+ qnp->name, rnp->name));
/* Lock the Facility */
PR_Lock( counterLock );
@@ -223,7 +224,7 @@ PR_IMPLEMENT(void)
** and free RName
*/
PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: Deleting RName: %s, %p",
- rnp->name, rnp));
+ rnp->name, rnp));
PR_REMOVE_LINK( &rnp->link );
PR_Free( rnp->lock );
PR_DELETE( rnp );
@@ -235,7 +236,7 @@ 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));
+ qnp->name, qnp));
PR_REMOVE_LINK( &qnp->link );
PR_DELETE( qnp );
}
@@ -249,9 +250,9 @@ PR_IMPLEMENT(void)
**
*/
PR_IMPLEMENT(PRCounterHandle)
- PR_GetCounterHandleFromName(
- const char *qName,
- const char *rName
+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;
@@ -288,11 +289,11 @@ foundIt:
**
*/
PR_IMPLEMENT(void)
- PR_GetCounterNameFromHandle(
- PRCounterHandle handle,
- const char **qName,
- const char **rName,
- const char **description
+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() */
@@ -314,8 +315,8 @@ PR_IMPLEMENT(void)
**
*/
PR_IMPLEMENT(void)
- PR_IncrementCounter(
- PRCounterHandle handle
+PR_IncrementCounter(
+ PRCounterHandle handle
)
{
PR_Lock(((RName *)handle)->lock);
@@ -323,7 +324,7 @@ PR_IMPLEMENT(void)
PR_Unlock(((RName *)handle)->lock);
PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: Increment: %p, %ld",
- handle, ((RName *)handle)->counter ));
+ handle, ((RName *)handle)->counter ));
return;
} /* end PR_IncrementCounter() */
@@ -334,8 +335,8 @@ PR_IMPLEMENT(void)
**
*/
PR_IMPLEMENT(void)
- PR_DecrementCounter(
- PRCounterHandle handle
+PR_DecrementCounter(
+ PRCounterHandle handle
)
{
PR_Lock(((RName *)handle)->lock);
@@ -343,7 +344,7 @@ PR_IMPLEMENT(void)
PR_Unlock(((RName *)handle)->lock);
PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: Decrement: %p, %ld",
- handle, ((RName *)handle)->counter ));
+ handle, ((RName *)handle)->counter ));
return;
} /* end PR_DecrementCounter() */
@@ -353,9 +354,9 @@ PR_IMPLEMENT(void)
**
*/
PR_IMPLEMENT(void)
- PR_AddToCounter(
- PRCounterHandle handle,
- PRUint32 value
+PR_AddToCounter(
+ PRCounterHandle handle,
+ PRUint32 value
)
{
PR_Lock(((RName *)handle)->lock);
@@ -363,7 +364,7 @@ PR_IMPLEMENT(void)
PR_Unlock(((RName *)handle)->lock);
PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: AddToCounter: %p, %ld",
- handle, ((RName *)handle)->counter ));
+ handle, ((RName *)handle)->counter ));
return;
} /* end PR_AddToCounter() */
@@ -373,9 +374,9 @@ PR_IMPLEMENT(void)
**
*/
PR_IMPLEMENT(void)
- PR_SubtractFromCounter(
- PRCounterHandle handle,
- PRUint32 value
+PR_SubtractFromCounter(
+ PRCounterHandle handle,
+ PRUint32 value
)
{
PR_Lock(((RName *)handle)->lock);
@@ -383,7 +384,7 @@ PR_IMPLEMENT(void)
PR_Unlock(((RName *)handle)->lock);
PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: SubtractFromCounter: %p, %ld",
- handle, ((RName *)handle)->counter ));
+ handle, ((RName *)handle)->counter ));
return;
} /* end PR_SubtractFromCounter() */
@@ -392,12 +393,12 @@ PR_IMPLEMENT(void)
**
*/
PR_IMPLEMENT(PRUint32)
- PR_GetCounter(
- PRCounterHandle handle
+PR_GetCounter(
+ PRCounterHandle handle
)
{
PR_LOG( lm, PR_LOG_DEBUG, ("PR_Counter: GetCounter: %p, %ld",
- handle, ((RName *)handle)->counter ));
+ handle, ((RName *)handle)->counter ));
return(((RName *)handle)->counter);
} /* end PR_GetCounter() */
@@ -406,15 +407,15 @@ PR_IMPLEMENT(PRUint32)
**
*/
PR_IMPLEMENT(void)
- PR_SetCounter(
- PRCounterHandle handle,
- PRUint32 value
+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 ));
+ handle, ((RName *)handle)->counter ));
return;
} /* end PR_SetCounter() */
@@ -423,23 +424,27 @@ PR_IMPLEMENT(void)
**
*/
PR_IMPLEMENT(PRCounterHandle)
- PR_FindNextCounterQname(
- PRCounterHandle handle
+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 ));
+ handle, qnp ));
return((PRCounterHandle)qnp);
} /* end PR_FindNextCounterQname() */
@@ -449,26 +454,30 @@ PR_IMPLEMENT(PRCounterHandle)
**
*/
PR_IMPLEMENT(PRCounterHandle)
- PR_FindNextCounterRname(
- PRCounterHandle rhandle,
- PRCounterHandle qhandle
+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 ));
+ rhandle, qhandle, rnp ));
return((PRCounterHandle)rnp);
} /* end PR_FindNextCounterRname() */
diff --git a/pr/src/misc/prdtoa.c b/pr/src/misc/prdtoa.c
index c3423286..f0963370 100644
--- a/pr/src/misc/prdtoa.c
+++ b/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);
@@ -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/pr/src/misc/prenv.c b/pr/src/misc/prenv.c
index cc2e198b..b057a1c8 100644
--- a/pr/src/misc/prenv.c
+++ b/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/pr/src/misc/prerr.c b/pr/src/misc/prerr.c
index bc78c8fb..99cf39f8 100644
--- a/pr/src/misc/prerr.c
+++ b/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/pr/src/misc/prerror.c b/pr/src/misc/prerror.c
index 19f7794b..a06b78dd 100644
--- a/pr/src/misc/prerror.c
+++ b/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/pr/src/misc/prerrortable.c b/pr/src/misc/prerrortable.c
index 7ce11d81..a7ff4f0e 100644
--- a/pr/src/misc/prerrortable.c
+++ b/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,9 +187,9 @@ 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;
@@ -198,8 +202,8 @@ PR_ErrorInstallCallback(const char * const * languages,
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/pr/src/misc/prinit.c b/pr/src/misc/prinit.c
index 61cb63bd..5ac99fe5 100644
--- a/pr/src/misc/prinit.c
+++ b/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,17 +152,17 @@ 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");
+ _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();
@@ -169,7 +171,7 @@ static void _PR_InitStuff(void)
_PR_InitAtomic();
_PR_InitSegs();
_PR_InitStacks();
- _PR_InitTPD();
+ _PR_InitTPD();
_PR_InitEnv();
_PR_InitLayerCache();
_PR_InitClock();
@@ -180,20 +182,20 @@ static void _PR_InitStuff(void)
_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;
- }
+ {
+ 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 */
@@ -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();
}
@@ -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()
@@ -375,7 +379,7 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup()
_PR_CleanupTime();
_PR_CleanupDtoa();
_PR_CleanupCallOnce();
- _PR_ShutdownLinker();
+ _PR_ShutdownLinker();
_PR_CleanupNet();
_PR_CleanupIO();
/* Release the primordial thread's private data, etc. */
@@ -383,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
@@ -439,7 +443,7 @@ PR_IMPLEMENT(PRStatus) PR_Cleanup()
*/
#if defined(_PR_PTHREADS) || defined(_PR_BTHREADS)
- /* see ptthread.c */
+/* see ptthread.c */
#else
PR_IMPLEMENT(void) PR_ProcessExit(PRIntn status)
{
@@ -510,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);
@@ -575,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 */
@@ -603,11 +607,11 @@ 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;
return PR_SUCCESS;
@@ -705,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;
}
@@ -763,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);
@@ -792,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/pr/src/misc/prinrval.c b/pr/src/misc/prinrval.c
index 50a938b5..79ff2cbc 100644
--- a/pr/src/misc/prinrval.c
+++ b/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/pr/src/misc/pripcsem.c b/pr/src/misc/pripcsem.c
index a1768978..49b051b7 100644
--- a/pr/src/misc/pripcsem.c
+++ b/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/pr/src/misc/prlong.c b/pr/src/misc/prlong.c
index 185fa5cd..9c5abf06 100644
--- a/pr/src/misc/prlong.c
+++ b/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/pr/src/misc/prnetdb.c b/pr/src/misc/prnetdb.c
index 923e75f9..6ad0242d 100644
--- a/pr/src/misc/prnetdb.c
+++ b/pr/src/misc/prnetdb.c
@@ -59,14 +59,14 @@ PRLock *_pr_dnsLock = NULL;
*/
#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(AIX4_3_PLUS) || (defined(AIX) && defined(_THREAD_SAFE)) \
- || (defined(HPUX10_10) && defined(_REENTRANT)) \
+ || (defined(HPUX10_10) && defined(_REENTRANT)) \
|| (defined(HPUX10_20) && defined(_REENTRANT)) \
|| defined(OPENBSD)
#define _PR_HAVE_GETPROTO_R
@@ -92,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_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_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_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_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])
@@ -239,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 */
@@ -267,7 +276,7 @@ _pr_QueryNetIfs(void)
} 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;
}
}
@@ -277,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);
@@ -356,7 +365,7 @@ _pr_QueryNetIfs(void)
} 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;
}
}
@@ -385,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
}
@@ -431,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 {
@@ -486,78 +495,91 @@ 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 {
+ 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;
+ 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;
}
#if !defined(_PR_HAVE_GETPROTO_R)
@@ -568,35 +590,43 @@ static PRStatus CopyHostent(
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) */
@@ -638,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;
@@ -647,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;
@@ -662,35 +694,37 @@ PR_IMPLEMENT(PRStatus) PR_GetHostByName(
}
#endif
- LOCK_DNS();
+ LOCK_DNS();
- h = GETHOSTBYNAME(name);
+ 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 (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;
@@ -714,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
@@ -743,12 +781,14 @@ static PRStatus AppendV4AddrsToHostent(
/* 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++) {
@@ -759,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;
@@ -771,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;
@@ -780,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);
@@ -803,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)
@@ -849,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);
@@ -872,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;
@@ -970,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;
@@ -1035,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)
@@ -1099,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;
}
/******************************************************************************/
@@ -1142,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) */
@@ -1155,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)
{
@@ -1198,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;
@@ -1211,23 +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
- {
- 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;
}
@@ -1235,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)
{
@@ -1278,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;
@@ -1291,23 +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
- {
- 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;
@@ -1325,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);
@@ -1347,7 +1422,9 @@ PRUintn _PR_NetAddrSize(const PRNetAddr* addr)
addrsize = sizeof(addr->local);
}
#endif
- else addrsize = 0;
+ else {
+ addrsize = 0;
+ }
return addrsize;
} /* _PR_NetAddrSize */
@@ -1357,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
@@ -1382,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 */
@@ -1408,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;
@@ -1460,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 {
@@ -1502,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,
@@ -1535,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++;
@@ -1554,12 +1649,16 @@ 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 */
}
@@ -1568,46 +1667,68 @@ static int StringToV6Addr(const char *string, PRIPv6Addr *addr)
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++;
}
@@ -1691,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;
@@ -1730,7 +1867,9 @@ 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;
@@ -1750,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
@@ -1821,16 +1968,16 @@ typedef struct addrinfo PRADDRINFO;
#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;
@@ -1861,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;
@@ -1884,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;
@@ -1945,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) ||
@@ -1955,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);
@@ -1976,8 +2125,9 @@ 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
@@ -2020,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);
}
@@ -2033,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);
@@ -2044,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;
@@ -2055,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;
@@ -2091,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
}
@@ -2186,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)
{
@@ -2203,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);
@@ -2247,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);
@@ -2276,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]);
}
}
@@ -2298,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/pr/src/misc/prolock.c b/pr/src/misc/prolock.c
index a8115460..77a26bb2 100644
--- a/pr/src/misc/prolock.c
+++ b/pr/src/misc/prolock.c
@@ -14,9 +14,9 @@
#include "prerror.h"
PR_IMPLEMENT(PROrderedLock *)
- PR_CreateOrderedLock(
- PRInt32 order,
- const char *name
+PR_CreateOrderedLock(
+ PRInt32 order,
+ const char *name
)
{
PR_NOT_REACHED("Not implemented"); /* Not implemented yet */
@@ -26,8 +26,8 @@ PR_IMPLEMENT(PROrderedLock *)
PR_IMPLEMENT(void)
- PR_DestroyOrderedLock(
- PROrderedLock *lock
+PR_DestroyOrderedLock(
+ PROrderedLock *lock
)
{
PR_NOT_REACHED("Not implemented"); /* Not implemented yet */
@@ -36,8 +36,8 @@ PR_IMPLEMENT(void)
PR_IMPLEMENT(void)
- PR_LockOrderedLock(
- PROrderedLock *lock
+PR_LockOrderedLock(
+ PROrderedLock *lock
)
{
PR_NOT_REACHED("Not implemented"); /* Not implemented yet */
@@ -46,8 +46,8 @@ PR_IMPLEMENT(void)
PR_IMPLEMENT(PRStatus)
- PR_UnlockOrderedLock(
- PROrderedLock *lock
+PR_UnlockOrderedLock(
+ PROrderedLock *lock
)
{
PR_NOT_REACHED("Not implemented"); /* Not implemented yet */
diff --git a/pr/src/misc/prrng.c b/pr/src/misc/prrng.c
index 1597293c..b3e3d487 100644
--- a/pr/src/misc/prrng.c
+++ b/pr/src/misc/prrng.c
@@ -23,8 +23,8 @@ PRSize _pr_CopyLowBits(
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);
diff --git a/pr/src/misc/prsystem.c b/pr/src/misc/prsystem.c
index fe424491..825d3be0 100644
--- a/pr/src/misc/prsystem.c
+++ b/pr/src/misc/prsystem.c
@@ -67,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();
@@ -82,24 +82,28 @@ 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';
@@ -108,51 +112,53 @@ PR_IMPLEMENT(PRStatus) PR_GetSystemInfo(PRSysInfo cmd, char *buf, PRUint32 bufle
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;
}
@@ -261,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)
@@ -291,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)
@@ -305,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/pr/src/misc/prthinfo.c b/pr/src/misc/prthinfo.c
index cdc24276..14602df0 100644
--- a/pr/src/misc/prthinfo.c
+++ b/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)
@@ -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,15 +117,17 @@ 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/pr/src/misc/prtime.c b/pr/src/misc/prtime.c
index 8b9f4a91..6d711a6b 100644
--- a/pr/src/misc/prtime.c
+++ b/pr/src/misc/prtime.c
@@ -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);
}
@@ -243,7 +243,7 @@ PR_ImplodeTime(const PRExplodedTime *exploded)
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,7 +447,7 @@ 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;
@@ -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);
}
@@ -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'
@@ -543,10 +550,12 @@ static struct tm *MT_safe_localtime(const time_t *clock, struct tm *result)
#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;
}
@@ -630,9 +641,9 @@ 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);
+ + 60L * (PRInt32)localTime.tm_min
+ + 3600L * (PRInt32)localTime.tm_hour
+ + 86400L * (PRInt32)((PRInt32)localTime.tm_mday - 2L);
isdst2Jan1970 = localTime.tm_isdst;
@@ -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 */
@@ -770,8 +781,9 @@ 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;
+ }
- if (iterations++ > 1000)
+ 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)
{
- return PR_FAILURE;
+ /* GMT+0300 is legal, but PST+0300 is not. */
+ rest++;
+ break;
}
- switch (*rest)
+ 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 */
{
- 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;
+ 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;
+ 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;
- }
-
- 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? */
+ }
+ /* 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++;
- /* 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 (*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 */
{
- 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;
+ }
}
- if (zone != TT_UNKNOWN && zone_offset == -1)
+ /* 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'))
{
- 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 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 (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;
+ }
- 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;
- }
- }
+ 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);
+ /* 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);
+ }
- result->tm_params.tp_gmt_offset = zone_offset * 60;
- result->tm_params.tp_dst_offset = dst_offset * 60;
+ result->tm_params.tp_gmt_offset = zone_offset * 60;
+ result->tm_params.tp_dst_offset = dst_offset * 60;
- return PR_SUCCESS;
+ 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;
}
/*
@@ -1750,18 +1865,18 @@ 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[] =
@@ -1813,7 +1928,7 @@ while(0)
/* Needed by PR_FormatTimeUSEnglish() */
static unsigned int pr_WeekOfYear(const PRExplodedTime* time,
- unsigned int firstDayOfWeek);
+ unsigned int firstDayOfWeek);
/***********************************************************************************
@@ -1829,164 +1944,164 @@ 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;
+ }
+ 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);
+ }
+ }
+ }
+
+ ADDCHAR( bufPtr, bufSize, '\0' );
+ return (PRUint32)(bufPtr - buf - 1);
}
@@ -2004,31 +2119,32 @@ PR_FormatTimeUSEnglish( char* buf, PRUint32 bufSize,
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/pr/src/misc/prtpool.c b/pr/src/misc/prtpool.c
index 05867ea7..69f588ef 100644
--- a/pr/src/misc/prtpool.c
+++ b/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];
+ 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/pr/src/misc/prtrace.c b/pr/src/misc/prtrace.c
index 0b916902..ef6b6510 100644
--- a/pr/src/misc/prtrace.c
+++ b/pr/src/misc/prtrace.c
@@ -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;
@@ -186,10 +186,10 @@ static void _PR_InitializeTrace( void )
** 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 );
@@ -273,7 +274,7 @@ PR_IMPLEMENT(PRTraceHandle)
/* 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() */
@@ -282,15 +283,15 @@ PR_IMPLEMENT(PRTraceHandle)
**
*/
PR_IMPLEMENT(void)
- PR_DestroyTrace(
- PRTraceHandle handle /* Handle to be destroyed */
+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));
+ qnp->name, rnp->name));
/* Lock the Facility */
PR_Lock( traceLock );
@@ -300,7 +301,7 @@ PR_IMPLEMENT(void)
** and free RName
*/
PR_LOG( lm, PR_LOG_DEBUG, ("PRTrace: Deleting RName: %s, %p",
- rnp->name, rnp));
+ rnp->name, rnp));
PR_REMOVE_LINK( &rnp->link );
PR_Free( rnp->lock );
PR_DELETE( rnp );
@@ -312,7 +313,7 @@ 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));
+ qnp->name, qnp));
PR_REMOVE_LINK( &qnp->link );
PR_DELETE( qnp );
}
@@ -326,24 +327,25 @@ 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_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 ))
+ || ( ((RName *)handle)->state == Suspended )) {
return;
+ }
/*
** Get the next trace entry slot w/ minimum delay
@@ -351,10 +353,12 @@ PR_IMPLEMENT(void)
PR_Lock( traceLock );
tep = &tBuf[next++];
- if ( next > last )
+ if ( next > last ) {
next = 0;
- if ( fetchLostData == PR_FALSE && next == fetchLastSeen )
+ }
+ if ( fetchLostData == PR_FALSE && next == fetchLastSeen ) {
fetchLostData = PR_TRUE;
+ }
mark = next;
@@ -401,9 +405,9 @@ PR_IMPLEMENT(void)
**
*/
PR_IMPLEMENT(void)
- PR_SetTraceOption(
- PRTraceOption command, /* One of the enumerated values */
- void *value /* command value or NULL */
+PR_SetTraceOption(
+ PRTraceOption command, /* One of the enumerated values */
+ void *value /* command value or NULL */
)
{
RName * rnp;
@@ -417,33 +421,33 @@ 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 :
@@ -452,14 +456,15 @@ PR_IMPLEMENT(void)
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 );
@@ -472,24 +477,24 @@ PR_IMPLEMENT(void)
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() */
@@ -500,9 +505,9 @@ PR_IMPLEMENT(void)
**
*/
PR_IMPLEMENT(void)
- PR_GetTraceOption(
- PRTraceOption command, /* One of the enumerated values */
- void *value /* command value or NULL */
+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() */
@@ -526,9 +531,9 @@ PR_IMPLEMENT(void)
**
*/
PR_IMPLEMENT(PRTraceHandle)
- PR_GetTraceHandleFromName(
- const char *qName, /* QName search argument */
- const char *rName /* RName search argument */
+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;
@@ -565,11 +570,11 @@ 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_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() */
@@ -590,23 +595,27 @@ PR_IMPLEMENT(void)
**
*/
PR_IMPLEMENT(PRTraceHandle)
- PR_FindNextTraceQname(
- PRTraceHandle handle
+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 ));
+ handle, qnp ));
return((PRTraceHandle)qnp);
} /* end PR_FindNextTraceQname() */
@@ -615,26 +624,30 @@ PR_IMPLEMENT(PRTraceHandle)
**
*/
PR_IMPLEMENT(PRTraceHandle)
- PR_FindNextTraceRname(
- PRTraceHandle rhandle,
- PRTraceHandle qhandle
+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 ));
+ 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,7 +676,7 @@ 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;
}
@@ -671,8 +685,8 @@ static PRFileDesc * InitializeRecording( void )
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));
+ ("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,10 +844,10 @@ 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;
@@ -841,7 +860,7 @@ PR_IMPLEMENT(PRIntn)
** 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/pr/src/prvrsion.c b/pr/src/prvrsion.c
index 8f42266c..09dcc665 100644
--- a/pr/src/prvrsion.c
+++ b/pr/src/prvrsion.c
@@ -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 */
diff --git a/pr/src/pthreads/ptio.c b/pr/src/pthreads/ptio.c
index ea1cccf3..3ad2d80a 100644
--- a/pr/src/pthreads/ptio.c
+++ b/pr/src/pthreads/ptio.c
@@ -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
/*
@@ -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
/*
@@ -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 */
@@ -375,7 +386,9 @@ PR_IMPLEMENT(void) PT_FPrintStats(PRFileDesc *debug_out, const char *msg)
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(
@@ -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) &&
(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) &&
(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) &&
(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;
}
@@ -1054,7 +1106,7 @@ 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;
}
@@ -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);
@@ -1197,7 +1249,9 @@ 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)
{
@@ -1243,12 +1297,14 @@ 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)
{
@@ -1267,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;
@@ -1285,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 */
@@ -1295,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;
@@ -1307,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;
@@ -1326,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 */
@@ -1340,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);
@@ -1372,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)
{
@@ -1391,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;
@@ -1419,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 */
@@ -1439,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;
@@ -1460,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);
@@ -1474,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 */
@@ -1510,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) {
@@ -1525,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
@@ -1533,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);
@@ -1559,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;
@@ -1592,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);
@@ -1630,7 +1713,9 @@ static PRFileDesc* pt_Accept(
PRIntn syserrno, osfd = -1;
pt_SockLen addr_len = sizeof(PRNetAddr);
- if (pt_TestAbort()) return newfd;
+ if (pt_TestAbort()) {
+ return newfd;
+ }
#ifdef _PR_STRICT_ADDR_LEN
if (addr)
@@ -1649,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;
@@ -1669,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
@@ -1680,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);
@@ -1709,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
@@ -1717,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)
@@ -1728,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;
@@ -1767,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) {
@@ -1780,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);
@@ -1804,8 +1905,9 @@ static PRInt32 pt_Recv(
PRInt32 syserrno, bytes = -1;
PRIntn osflags;
- if (0 == flags)
+ if (0 == flags) {
osflags = 0;
+ }
else if (PR_MSG_PEEK == flags)
{
osflags = MSG_PEEK;
@@ -1816,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
@@ -1832,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;
@@ -1847,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 */
@@ -1864,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().
@@ -1913,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;
@@ -1937,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 */
@@ -1955,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
@@ -1963,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
@@ -1986,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)
{
@@ -2010,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 */
@@ -2035,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);
@@ -2064,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;
@@ -2077,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;
@@ -2111,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)
@@ -2155,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 */
@@ -2179,12 +2314,12 @@ static void pt_aix_sendfile_init_routine(void)
* 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);
@@ -2210,33 +2345,35 @@ static PRInt32 pt_AIXDispatchSendFile(PRFileDesc *sd, PRSendFileData *sfd,
*/
static PRInt32 pt_AIXSendFile(PRFileDesc *sd, PRSendFileData *sfd,
- PRTransmitFileFlags flags, PRIntervalTime timeout)
+ 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));
@@ -2252,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))) {
@@ -2283,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 */
@@ -2307,7 +2445,7 @@ static PRInt32 pt_AIXSendFile(PRFileDesc *sd, PRSendFileData *sfd,
*/
static PRInt32 pt_HPUXSendFile(PRFileDesc *sd, PRSendFileData *sfd,
- PRTransmitFileFlags flags, PRIntervalTime timeout)
+ PRTransmitFileFlags flags, PRIntervalTime timeout)
{
struct stat statbuf;
size_t nbytes_to_send, file_nbytes_to_send;
@@ -2342,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)) {
@@ -2352,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;
@@ -2367,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;
@@ -2429,7 +2567,7 @@ 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;
@@ -2487,14 +2625,14 @@ static PRInt32 pt_SolarisSendFile(PRFileDesc *sd, PRSendFileData *sfd,
* 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) {
@@ -2562,7 +2700,7 @@ static void pt_solaris_sendfilev_init_routine(void)
*/
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) {
/*
@@ -2572,12 +2710,12 @@ 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);
@@ -2588,12 +2726,12 @@ static void pt_solaris_sendfilev_init_routine(void)
* 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);
@@ -2621,7 +2759,7 @@ 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;
@@ -2644,10 +2782,10 @@ static PRInt32 pt_LinuxSendFile(PRFileDesc *sd, PRSendFileData *sfd,
}
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;
@@ -2662,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"));
}
}
@@ -2678,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) {
@@ -2724,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;
}
@@ -2740,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)
{
@@ -2758,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
}
@@ -2790,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(
@@ -2809,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)
{
@@ -2826,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;
@@ -2842,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);
@@ -2855,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);
@@ -2872,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);
@@ -2906,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;
@@ -2923,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;
@@ -2933,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;
@@ -2946,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;
@@ -2956,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;
}
@@ -2966,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;
@@ -2978,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;
@@ -2990,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 */
@@ -3031,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:
@@ -3042,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) {
@@ -3056,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:
@@ -3066,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:
@@ -3095,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 */
@@ -3302,7 +3456,7 @@ static PRIOMethods _pr_socketpollfd_methods = {
(PRSendFN)_PR_InvalidInt,
(PRRecvfromFN)_PR_InvalidInt,
(PRSendtoFN)_PR_InvalidInt,
- pt_Poll,
+ pt_Poll,
(PRAcceptreadFN)_PR_InvalidInt,
(PRTransmitfileFN)_PR_InvalidInt,
(PRGetsocknameFN)_PR_InvalidStatus,
@@ -3369,12 +3523,16 @@ static PRFileDesc *pt_SetMethods(
{
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. */
@@ -3393,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
@@ -3443,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;
@@ -3451,8 +3613,12 @@ 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;
@@ -3478,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
@@ -3496,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)
@@ -3508,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
@@ -3525,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;
@@ -3547,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;
+ 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;
+ 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
@@ -3566,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 */
@@ -3602,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)
@@ -3631,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 */
@@ -3660,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);
@@ -3677,21 +3887,25 @@ 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;
@@ -3707,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 */
@@ -3716,7 +3932,9 @@ 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
@@ -3736,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;
@@ -3745,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)
{
@@ -3764,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 */
@@ -3790,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) {
@@ -3806,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 */
@@ -3833,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
@@ -3876,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)
@@ -3912,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)
{
@@ -3947,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
@@ -3978,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:
@@ -3993,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;
@@ -4028,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;
}
@@ -4041,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;
@@ -4088,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)
@@ -4121,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)
{
@@ -4135,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)
@@ -4171,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)
{
@@ -4214,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)
{
@@ -4263,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:
@@ -4297,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)
{
@@ -4344,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;
}
@@ -4381,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
}
@@ -4397,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 (;;)
{
@@ -4410,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;
@@ -4451,7 +4713,9 @@ PR_IMPLEMENT(PRStatus) PR_NewTCPSocketPair(PRFileDesc *fds[2])
{
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);
@@ -4480,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;
}
@@ -4524,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;
@@ -4542,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 */
@@ -4552,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 */
@@ -4562,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 */
@@ -4575,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 */
@@ -4585,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();
}
@@ -4617,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;
@@ -4660,15 +4957,21 @@ 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;
@@ -4678,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;
@@ -4704,8 +5013,9 @@ PR_IMPLEMENT(PRInt32) PR_GetSysfdTableMax(void)
#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
@@ -4719,17 +5029,22 @@ PR_IMPLEMENT(PRInt32) PR_SetSysfdTableSize(PRIntn table_size)
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
@@ -4744,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);
@@ -4761,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;
@@ -4778,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;
@@ -4815,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;
}
@@ -4852,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;
}
@@ -4877,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) ) {
@@ -4911,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);
@@ -4926,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) {
@@ -4946,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;
}
}
diff --git a/pr/src/pthreads/ptmisc.c b/pr/src/pthreads/ptmisc.c
index 9750c251..4069f585 100644
--- a/pr/src/pthreads/ptmisc.c
+++ b/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)
{
#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/pr/src/pthreads/ptsynch.c b/pr/src/pthreads/ptsynch.c
index 86bc6dae..26f58b2d 100644
--- a/pr/src/pthreads/ptsynch.c
+++ b/pr/src/pthreads/ptsynch.c
@@ -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,7 +134,9 @@ 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)
@@ -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;
@@ -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);
@@ -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;
}
@@ -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
@@ -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
@@ -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)
@@ -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/pr/src/pthreads/ptthread.c b/pr/src/pthreads/ptthread.c
index 681380d7..292c89eb 100644
--- a/pr/src/pthreads/ptthread.c
+++ b/pr/src/pthreads/ptthread.c
@@ -76,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)
@@ -182,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);
@@ -206,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);
/*
@@ -256,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);
@@ -278,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);
@@ -299,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);
@@ -336,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);
/*
@@ -346,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);
@@ -366,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;
@@ -417,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,7 +462,7 @@ static PRThread* _PR_CreateThread(
/* 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);
@@ -447,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);
@@ -501,7 +531,7 @@ 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(
@@ -510,7 +540,7 @@ PR_IMPLEMENT(PRThread*) PR_CreateThreadGCAble(
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)
@@ -537,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
@@ -591,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);
@@ -601,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 */
@@ -612,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)
@@ -639,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)
@@ -652,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;
@@ -684,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
@@ -718,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;
@@ -729,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 */
@@ -757,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);
}
@@ -765,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)
{
@@ -784,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);
@@ -826,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));
@@ -878,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
/*
@@ -920,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;
@@ -934,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
@@ -951,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);
@@ -974,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));
@@ -1016,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
@@ -1070,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();
@@ -1181,12 +1241,12 @@ static void init_pthread_gc_support(void)
{
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);
@@ -1197,15 +1257,15 @@ 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) */
}
@@ -1213,14 +1273,14 @@ static void init_pthread_gc_support(void)
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);
}
@@ -1272,13 +1332,14 @@ PR_IMPLEMENT(PRStatus) PR_EnumerateThreads(PREnumerator func, void *arg)
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));
+ ("End PR_EnumerateThreads count = %d \n", count));
return rv;
} /* PR_EnumerateThreads */
@@ -1303,70 +1364,70 @@ PR_IMPLEMENT(PRStatus) PR_EnumerateThreads(PREnumerator func, void *arg)
* 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)
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
/*
@@ -1377,7 +1438,7 @@ static void suspend_signal_handler(PRIntn sig)
*/
PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS,
- ("End suspend_signal_handler thred = %p tid = %X\n", me, me->id));
+ ("End suspend_signal_handler thred = %p tid = %X\n", me, me->id));
} /* suspend_signal_handler */
static void pt_SuspendSet(PRThread *thred)
@@ -1385,7 +1446,7 @@ 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));
+ ("pt_SuspendSet thred %p thread id = %X\n", thred, thred->id));
/*
@@ -1395,8 +1456,8 @@ 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));
+ ("doing pthread_kill in pt_SuspendSet thred %p tid = %X\n",
+ thred, thred->id));
rv = pthread_kill (thred->id, SIGUSR2);
PR_ASSERT(0 == rv);
}
@@ -1404,7 +1465,7 @@ static void pt_SuspendSet(PRThread *thred)
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));
+ ("Begin pt_SuspendTest thred %p thread id = %X\n", thred, thred->id));
/*
@@ -1417,26 +1478,26 @@ static void pt_SuspendTest(PRThread *thred)
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));
+ ("pt_ResumeSet thred %p thread id = %X\n", thred, thred->id));
/*
* Clear the global state and set the thread state so that it will
@@ -1449,7 +1510,7 @@ static void pt_ResumeSet(PRThread *thred)
thred->suspend &= ~PT_THREAD_SUSPENDED;
#if defined(PT_NO_SIGTIMEDWAIT)
- pthread_kill(thred->id, SIGUSR1);
+ pthread_kill(thred->id, SIGUSR1);
#endif
} /* pt_ResumeSet */
@@ -1457,7 +1518,7 @@ static void pt_ResumeSet(PRThread *thred)
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));
+ ("Begin pt_ResumeTest thred %p thread id = %X\n", thred, thred->id));
/*
* Wait for the threads resume state to change
@@ -1467,21 +1528,21 @@ static void pt_ResumeTest(PRThread *thred)
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;
@@ -1508,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;
}
@@ -1517,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;
}
@@ -1527,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 */
@@ -1550,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;
}
@@ -1568,8 +1633,8 @@ 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 */
@@ -1577,8 +1642,8 @@ PR_IMPLEMENT(void) PR_ResumeAll(void)
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));
+ ("in PR_GetSP thred %p thid = %X, sp = %p\n",
+ thred, thred->id, thred->sp));
return thred->sp;
} /* PR_GetSP */
@@ -1594,14 +1659,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);
#if defined(OPENBSD) || defined(FREEBSD) || defined(DRAGONFLY)
@@ -1623,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
@@ -1663,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/pr/src/threads/combined/prucpu.c b/pr/src/threads/combined/prucpu.c
index c1b37aaf..25ffcce8 100644
--- a/pr/src/threads/combined/prucpu.c
+++ b/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);
@@ -124,8 +125,9 @@ static _PRCPUQueue *_PR_CreateCPUQueue(void)
_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) );
@@ -217,8 +219,9 @@ static PRStatus _PR_StartCPU(_PRCPU *cpu, PRThread *thread)
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/pr/src/threads/combined/prucv.c b/pr/src/threads/combined/prucv.c
index 97c596fb..801d3d2f 100644
--- a/pr/src/threads/combined/prucv.c
+++ b/pr/src/threads/combined/prucv.c
@@ -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,14 +73,15 @@ 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;
@@ -94,7 +96,7 @@ PRBool _PR_NotifyThread (PRThread *thread, PRThread *me)
/*
* 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,35 +116,37 @@ 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);
@@ -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;
}
@@ -224,7 +231,7 @@ PRStatus _PR_WaitCondVar(
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;
}
@@ -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;
@@ -615,11 +635,11 @@ PR_IMPLEMENT(void) PRP_DestroyNakedCondVar(PRCondVar *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/pr/src/threads/combined/prulock.c b/pr/src/threads/combined/prulock.c
index 3d459dd5..69c27d14 100644
--- a/pr/src/threads/combined/prulock.c
+++ b/pr/src/threads/combined/prulock.c
@@ -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,23 +113,23 @@ 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) ) {
@@ -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) {
@@ -216,15 +218,16 @@ PR_IMPLEMENT(void) PR_Lock(PRLock *lock)
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;
}
@@ -265,32 +269,32 @@ retry:
*/
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 */
}
@@ -329,17 +333,18 @@ PR_IMPLEMENT(PRStatus) PR_Unlock(PRLock *lock)
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 */
}
@@ -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/pr/src/threads/combined/prustack.c b/pr/src/threads/combined/prustack.c
index f4b760dc..3f5452c4 100644
--- a/pr/src/threads/combined/prustack.c
+++ b/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,10 +138,10 @@ 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);
@@ -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/pr/src/threads/combined/pruthr.c b/pr/src/threads/combined/pruthr.c
index fe0c4293..44a08200 100644
--- a/pr/src/threads/combined/pruthr.c
+++ b/pr/src/threads/combined/pruthr.c
@@ -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
@@ -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,14 +509,14 @@ 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 */
@@ -521,16 +526,16 @@ static void _PR_UserRunThread(void)
_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);
-
- 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();
+ 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);
}
- } else {
- PR_ASSERT(0);
- }
- break;
+ break;
- case _PR_IO_WAIT:
- case _PR_COND_WAIT:
- thread->flags &= ~_PR_SUSPENDING;
-/* PR_ASSERT(thread->wait.monitor->stickyCount == 0); */
- 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;
+ case _PR_LOCK_WAIT:
+ {
+ PRLock *wLock = thread->wait.lock;
- thread->flags &= ~_PR_SUSPENDING;
+ thread->flags &= ~_PR_SUSPENDING;
- _PR_LOCK_LOCK(wLock);
- if (thread->wait.lock->owner == 0) {
- _PR_UnblockLockWaiter(thread->wait.lock);
+ _PR_LOCK_LOCK(wLock);
+ if (thread->wait.lock->owner == 0) {
+ _PR_UnblockLockWaiter(thread->wait.lock);
+ }
+ _PR_LOCK_UNLOCK(wLock);
+ break;
}
- _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,7 +775,7 @@ static PRThread *get_thread(_PRCPU *cpu, PRBool *wakeup_cpus)
}
thread = NULL;
for (pri = priMax; pri >= priMin ; pri-- ) {
- if (r & (1 << pri)) {
+ if (r & (1 << pri)) {
for (qp = _PR_RUNQ(cpu)[pri].next;
qp != &_PR_RUNQ(cpu)[pri];
qp = qp->next) {
@@ -851,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) {
@@ -873,7 +887,7 @@ void _PR_Schedule(void)
}
thread = NULL;
for (pri = priMax; pri >= priMin ; pri-- ) {
- if (r & (1 << pri)) {
+ if (r & (1 << pri)) {
for (qp = _PR_RUNQ(cpu)[pri].next;
qp != &_PR_RUNQ(cpu)[pri];
qp = qp->next) {
@@ -882,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 {
@@ -904,35 +918,37 @@ 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;
@@ -940,9 +956,10 @@ found_thread:
* 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
*/
- 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
@@ -959,7 +976,7 @@ found_thread:
*/
static PRThread *
_PR_AttachThread(PRThreadType type, PRThreadPriority priority,
- PRThreadStack *stack)
+ PRThreadStack *stack)
{
PRThread *thread;
char *mem;
@@ -978,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;
}
@@ -991,13 +1008,13 @@ _PR_AttachThread(PRThreadType type, PRThreadPriority priority,
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;
@@ -1031,27 +1048,27 @@ _PR_NativeCreateThread(PRThreadType type,
*/
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;
@@ -1060,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;
@@ -1087,33 +1104,38 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
priority = PR_PRIORITY_FIRST;
}
- if (!_pr_initialized) _PR_ImplicitInitialization();
+ if (!_pr_initialized) {
+ _PR_ImplicitInitialization();
+ }
- if (! (flags & _PR_IDLE_THREAD))
+ 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;
@@ -1129,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);
+ scope, state, stackSize, flags);
} else {
if (_PR_NUM_DEADUSER > 0) {
_PR_DEADQ_LOCK;
@@ -1174,7 +1199,7 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
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;
@@ -1186,20 +1211,21 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
_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++;
}
}
@@ -1257,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);
}
@@ -1267,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);
@@ -1281,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);
@@ -1298,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);
@@ -1323,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));
@@ -1353,20 +1385,21 @@ PR_IMPLEMENT(PRThread*) _PR_CreateThread(PRThreadType type,
} 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,
stackSize, 0);
@@ -1385,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;
@@ -1416,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);
@@ -1442,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();
}
@@ -1458,8 +1491,9 @@ PR_IMPLEMENT(void) PR_DetachThread(void)
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
}
@@ -1468,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);
@@ -1483,8 +1517,9 @@ 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);
}
@@ -1508,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) {
@@ -1521,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);
@@ -1536,8 +1573,9 @@ PR_IMPLEMENT(PRStatus) PR_JoinThread(PRThread *thread)
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);
@@ -1549,20 +1587,23 @@ 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);
+ if ( !_PR_IS_NATIVE_THREAD(me)) {
+ _PR_INTSON(is);
+ }
return PR_FAILURE;
}
PR_IMPLEMENT(void) PR_SetThreadPriority(PRThread *thread,
- PRThreadPriority newPri)
+ PRThreadPriority newPri)
{
/*
@@ -1578,7 +1619,9 @@ PR_IMPLEMENT(void) PR_SetThreadPriority(PRThread *thread,
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)
@@ -1592,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;
@@ -1607,8 +1652,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;
}
@@ -1630,19 +1676,21 @@ 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) {
+ 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();
}
@@ -1661,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) {
+ 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_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;
@@ -1712,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++;
}
}
@@ -1725,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++;
}
}
@@ -1818,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.
*/
- 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
@@ -1858,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/pr/src/threads/prcmon.c b/pr/src/threads/prcmon.c
index 2a196e9d..c1d354ce 100644
--- a/pr/src/threads/prcmon.c
+++ b/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/pr/src/threads/prcthr.c b/pr/src/threads/prcthr.c
index 78401b9d..e7044ed5 100644
--- a/pr/src/threads/prcthr.c
+++ b/pr/src/threads/prcthr.c
@@ -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;
}
@@ -294,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;
@@ -319,12 +349,12 @@ 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,
stackSize, _PR_GCABLE_THREAD);
@@ -332,12 +362,12 @@ PR_IMPLEMENT(PRThread*) PR_CreateThreadGCAble(PRThreadType type,
#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,
stackSize, _PR_BOUND_THREAD);
@@ -355,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/pr/src/threads/prdump.c b/pr/src/threads/prdump.c
index 6c74eeaf..04d84204 100644
--- a/pr/src/threads/prdump.c
+++ b/pr/src/threads/prdump.c
@@ -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/pr/src/threads/prmon.c b/pr/src/threads/prmon.c
index 36be8a94..b7c526ee 100644
--- a/pr/src/threads/prmon.c
+++ b/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/pr/src/threads/prrwlock.c b/pr/src/threads/prrwlock.c
index baa8cb21..0cb51e5b 100644
--- a/pr/src/threads/prrwlock.c
+++ b/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,7 +89,7 @@ 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
*
*/
@@ -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/pr/src/threads/prsem.c b/pr/src/threads/prsem.c
index 4b1617ca..120075b0 100644
--- a/pr/src/threads/prsem.c
+++ b/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;
@@ -75,25 +75,27 @@ PR_IMPLEMENT(void) PR_DestroySem(PRSemaphore *sem)
*/
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);
}
/*
@@ -104,13 +106,14 @@ PR_IMPLEMENT(PRStatus) PR_WaitSem(PRSemaphore *sem)
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/pr/src/threads/prtpd.c b/pr/src/threads/prtpd.c
index 650da675..e6385cf7 100644
--- a/pr/src/threads/prtpd.c
+++ b/pr/src/threads/prtpd.c
@@ -51,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
@@ -61,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;
}
@@ -99,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);
@@ -149,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
@@ -202,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;
}
diff --git a/pr/tests/abstract.c b/pr/tests/abstract.c
index 47c4637a..3d255c1c 100755..100644
--- a/pr/tests/abstract.c
+++ b/pr/tests/abstract.c
@@ -15,143 +15,143 @@ static const char abstractSocketName[] = "\0testsocket";
static void
ClientThread(void* aArg)
{
- PRFileDesc* socket;
- PRNetAddr addr;
- PRUint8 buf[1024];
- PRInt32 len;
- PRInt32 total;
-
- addr.local.family = PR_AF_LOCAL;
- memcpy(addr.local.path, abstractSocketName, sizeof(abstractSocketName));
-
- socket = PR_OpenTCPSocket(addr.raw.family);
- if (!socket) {
- fprintf(stderr, "PR_OpenTCPSokcet failed\n");
- exit(1);
- }
-
- if (PR_Connect(socket, &addr, PR_INTERVAL_NO_TIMEOUT) == PR_FAILURE) {
- fprintf(stderr, "PR_Connect failed\n");
- exit(1);
- }
-
- total = 0;
- while (total < sizeof(buf)) {
- len = PR_Recv(socket, buf + total, sizeof(buf) - total, 0,
- PR_INTERVAL_NO_TIMEOUT);
- if (len < 1) {
- fprintf(stderr, "PR_Recv failed\n");
- exit(1);
+ PRFileDesc* socket;
+ PRNetAddr addr;
+ PRUint8 buf[1024];
+ PRInt32 len;
+ PRInt32 total;
+
+ addr.local.family = PR_AF_LOCAL;
+ memcpy(addr.local.path, abstractSocketName, sizeof(abstractSocketName));
+
+ socket = PR_OpenTCPSocket(addr.raw.family);
+ if (!socket) {
+ fprintf(stderr, "PR_OpenTCPSokcet failed\n");
+ exit(1);
}
- total += len;
- }
-
- total = 0;
- while (total < sizeof(buf)) {
- len = PR_Send(socket, buf + total, sizeof(buf) - total, 0,
- PR_INTERVAL_NO_TIMEOUT);
- if (len < 1) {
- fprintf(stderr, "PR_Send failed\n");
- exit(1);
+
+ if (PR_Connect(socket, &addr, PR_INTERVAL_NO_TIMEOUT) == PR_FAILURE) {
+ fprintf(stderr, "PR_Connect failed\n");
+ exit(1);
+ }
+
+ total = 0;
+ while (total < sizeof(buf)) {
+ len = PR_Recv(socket, buf + total, sizeof(buf) - total, 0,
+ PR_INTERVAL_NO_TIMEOUT);
+ if (len < 1) {
+ fprintf(stderr, "PR_Recv failed\n");
+ exit(1);
+ }
+ total += len;
}
- total += len;
- }
- if (PR_Close(socket) == PR_FAILURE) {
- fprintf(stderr, "PR_Close failed\n");
- exit(1);
- }
+ total = 0;
+ while (total < sizeof(buf)) {
+ len = PR_Send(socket, buf + total, sizeof(buf) - total, 0,
+ PR_INTERVAL_NO_TIMEOUT);
+ if (len < 1) {
+ fprintf(stderr, "PR_Send failed\n");
+ exit(1);
+ }
+ total += len;
+ }
+
+ if (PR_Close(socket) == PR_FAILURE) {
+ fprintf(stderr, "PR_Close failed\n");
+ exit(1);
+ }
}
int
main()
{
- PRFileDesc* socket;
- PRFileDesc* acceptSocket;
- PRThread* thread;
- PRNetAddr addr;
- PRUint8 buf[1024];
- PRInt32 len;
- PRInt32 total;
-
- addr.local.family = PR_AF_LOCAL;
- memcpy(addr.local.path, abstractSocketName, sizeof(abstractSocketName));
-
- socket = PR_OpenTCPSocket(addr.raw.family);
- if (!socket) {
- fprintf(stderr, "PR_OpenTCPSocket failed\n");
- exit(1);
- }
- if (PR_Bind(socket, &addr) == PR_FAILURE) {
- fprintf(stderr, "PR_Bind failed\n");
- exit(1);
- }
-
- if (PR_Listen(socket, 5) == PR_FAILURE) {
- fprintf(stderr, "PR_Listen failed\n");
- exit(1);
- }
-
- thread = PR_CreateThread(PR_USER_THREAD, ClientThread, 0, PR_PRIORITY_NORMAL,
- PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
- if (!thread) {
- fprintf(stderr, "PR_CreateThread failed");
- exit(1);
- }
-
- acceptSocket = PR_Accept(socket, NULL, PR_INTERVAL_NO_TIMEOUT);
- if (!acceptSocket) {
- fprintf(stderr, "PR_Accept failed\n");
- exit(1);
- }
-
- memset(buf, 'A', sizeof(buf));
-
- total = 0;
- while (total < sizeof(buf)) {
- len = PR_Send(acceptSocket, buf + total, sizeof(buf) - total, 0,
- PR_INTERVAL_NO_TIMEOUT);
- if (len < 1) {
- fprintf(stderr, "PR_Send failed\n");
- exit(1);
+ PRFileDesc* socket;
+ PRFileDesc* acceptSocket;
+ PRThread* thread;
+ PRNetAddr addr;
+ PRUint8 buf[1024];
+ PRInt32 len;
+ PRInt32 total;
+
+ addr.local.family = PR_AF_LOCAL;
+ memcpy(addr.local.path, abstractSocketName, sizeof(abstractSocketName));
+
+ socket = PR_OpenTCPSocket(addr.raw.family);
+ if (!socket) {
+ fprintf(stderr, "PR_OpenTCPSocket failed\n");
+ exit(1);
+ }
+ if (PR_Bind(socket, &addr) == PR_FAILURE) {
+ fprintf(stderr, "PR_Bind failed\n");
+ exit(1);
+ }
+
+ if (PR_Listen(socket, 5) == PR_FAILURE) {
+ fprintf(stderr, "PR_Listen failed\n");
+ exit(1);
+ }
+
+ thread = PR_CreateThread(PR_USER_THREAD, ClientThread, 0, PR_PRIORITY_NORMAL,
+ PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
+ if (!thread) {
+ fprintf(stderr, "PR_CreateThread failed");
+ exit(1);
}
- total += len;
- }
-
- total = 0;
- while (total < sizeof(buf)) {
- len = PR_Recv(acceptSocket, buf + total, sizeof(buf) - total, 0,
- PR_INTERVAL_NO_TIMEOUT);
- if (len < 1) {
- fprintf(stderr, "PR_Recv failed\n");
- exit(1);
+
+ acceptSocket = PR_Accept(socket, NULL, PR_INTERVAL_NO_TIMEOUT);
+ if (!acceptSocket) {
+ fprintf(stderr, "PR_Accept failed\n");
+ exit(1);
+ }
+
+ memset(buf, 'A', sizeof(buf));
+
+ total = 0;
+ while (total < sizeof(buf)) {
+ len = PR_Send(acceptSocket, buf + total, sizeof(buf) - total, 0,
+ PR_INTERVAL_NO_TIMEOUT);
+ if (len < 1) {
+ fprintf(stderr, "PR_Send failed\n");
+ exit(1);
+ }
+ total += len;
+ }
+
+ total = 0;
+ while (total < sizeof(buf)) {
+ len = PR_Recv(acceptSocket, buf + total, sizeof(buf) - total, 0,
+ PR_INTERVAL_NO_TIMEOUT);
+ if (len < 1) {
+ fprintf(stderr, "PR_Recv failed\n");
+ exit(1);
+ }
+ total += len;
+ }
+
+ if (PR_Close(acceptSocket) == PR_FAILURE) {
+ fprintf(stderr, "PR_Close failed\n");
+ exit(1);
+ }
+
+ if (PR_JoinThread(thread) == PR_FAILURE) {
+ fprintf(stderr, "PR_JoinThread failed\n");
+ exit(1);
+ }
+
+ if (PR_Close(socket) == PR_FAILURE) {
+ fprintf(stderr, "PR_Close failed\n");
+ exit(1);
}
- total += len;
- }
-
- if (PR_Close(acceptSocket) == PR_FAILURE) {
- fprintf(stderr, "PR_Close failed\n");
- exit(1);
- }
-
- if (PR_JoinThread(thread) == PR_FAILURE) {
- fprintf(stderr, "PR_JoinThread failed\n");
- exit(1);
- }
-
- if (PR_Close(socket) == PR_FAILURE) {
- fprintf(stderr, "PR_Close failed\n");
- exit(1);
- }
- printf("PASS\n");
- return 0;
+ printf("PASS\n");
+ return 0;
}
#else
int
main()
{
- printf("PASS\n");
- return 0;
+ printf("PASS\n");
+ return 0;
}
#endif
diff --git a/pr/tests/accept.c b/pr/tests/accept.c
index 0b26ccdb..3e3850b6 100644
--- a/pr/tests/accept.c
+++ b/pr/tests/accept.c
@@ -96,8 +96,9 @@ void Test_Assert(const char *msg, const char *file, PRIntn line)
void timeout_callback(void *magic)
{
TEST_ASSERT(magic == (void *)CALLBACK_MAGIC);
- if (debug_mode)
+ if (debug_mode) {
PR_fprintf(output, "timeout callback called okay\n");
+ }
}
#endif
@@ -120,37 +121,40 @@ ClientThread(void *_action)
memset(buf, 0xaf, sizeof(buf)); /* initialize with arbitrary data */
sock = PR_NewTCPSocket();
if (!sock) {
- if (!debug_mode)
+ if (!debug_mode) {
failed_already=1;
- else
+ }
+ else {
PR_fprintf(output, "client: unable to create socket\n");
+ }
return;
}
if (action != CLIENT_TIMEOUT_ACCEPT) {
if ((rv = PR_Connect(sock, &serverAddr,
- timeoutTime)) < 0) {
- if (!debug_mode)
+ timeoutTime)) < 0) {
+ if (!debug_mode) {
failed_already=1;
+ }
else
PR_fprintf(output,
- "client: unable to connect to server (%ld, %ld, %ld, %ld)\n",
- iterations, rv, PR_GetError(), PR_GetOSError());
+ "client: unable to connect to server (%ld, %ld, %ld, %ld)\n",
+ iterations, rv, PR_GetError(), PR_GetOSError());
goto ErrorExit;
}
if (action != CLIENT_TIMEOUT_SEND) {
if ((rv = PR_Send(sock, buf, CLIENT_DATA,
- 0, timeoutTime))< 0) {
+ 0, timeoutTime))< 0) {
if (!debug_mode) {
failed_already=1;
} else {
PR_fprintf(output,
- "client: unable to send to server (%d, %ld, %ld)\n",
- CLIENT_DATA, rv, PR_GetError());
+ "client: unable to send to server (%d, %ld, %ld)\n",
+ CLIENT_DATA, rv, PR_GetError());
}
- goto ErrorExit;
+ goto ErrorExit;
}
} else {
PR_Sleep(PR_SecondsToInterval(TIMEOUTSECS + 1));
@@ -158,34 +162,38 @@ ClientThread(void *_action)
} else {
PR_Sleep(PR_SecondsToInterval(TIMEOUTSECS + 1));
}
- if (debug_mode)
+ if (debug_mode) {
PR_fprintf(output, ".");
+ }
PR_Close(sock);
- sock = NULL;
+ sock = NULL;
}
- if (debug_mode)
+ if (debug_mode) {
PR_fprintf(output, "\n");
+ }
ErrorExit:
- if (sock != NULL)
+ if (sock != NULL) {
PR_Close(sock);
+ }
}
static void
RunTest(PRInt32 acceptType, PRInt32 clientAction)
{
-int i;
+ int i;
/* First bind to the socket */
listenSock = PR_NewTCPSocket();
if (!listenSock) {
failed_already=1;
- if (debug_mode)
+ if (debug_mode) {
PR_fprintf(output, "unable to create listen socket\n");
+ }
return;
}
- memset(&listenAddr, 0 , sizeof(listenAddr));
+ memset(&listenAddr, 0, sizeof(listenAddr));
listenAddr.inet.family = PR_AF_INET;
listenAddr.inet.port = PR_htons(BASE_PORT);
listenAddr.inet.ip = PR_htonl(PR_INADDR_ANY);
@@ -197,148 +205,153 @@ int i;
while (PR_Bind(listenSock, &listenAddr) == PR_FAILURE) {
if (PR_GetError() == PR_ADDRESS_IN_USE_ERROR) {
listenAddr.inet.port += 2;
- if (i++ < SERVER_MAX_BIND_COUNT)
+ if (i++ < SERVER_MAX_BIND_COUNT) {
continue;
+ }
}
failed_already=1;
if (debug_mode) {
- PR_fprintf(output,"accept: ERROR - PR_Bind failed\n");
+ PR_fprintf(output,"accept: ERROR - PR_Bind failed\n");
}
- return;
+ return;
}
rv = PR_Listen(listenSock, 100);
if (rv == PR_FAILURE) {
failed_already=1;
- if (debug_mode)
+ if (debug_mode) {
PR_fprintf(output, "unable to listen\n");
+ }
return;
}
clientCommand = clientAction;
clientThread = PR_CreateThread(PR_USER_THREAD, ClientThread,
- (void *)&clientCommand, PR_PRIORITY_NORMAL, thread_scope,
- PR_JOINABLE_THREAD, 0);
+ (void *)&clientCommand, PR_PRIORITY_NORMAL, thread_scope,
+ PR_JOINABLE_THREAD, 0);
if (!clientThread) {
failed_already=1;
- if (debug_mode)
+ if (debug_mode) {
PR_fprintf(output, "error creating client thread\n");
+ }
return;
}
iterations = count;
- for (;iterations--;) {
+ for (; iterations--;) {
switch (acceptType) {
- case ACCEPT_NORMAL:
- clientSock = PR_Accept(listenSock, &clientAddr,
- timeoutTime);
- switch(clientAction) {
- case CLIENT_TIMEOUT_ACCEPT:
- TEST_ASSERT(clientSock == 0);
- TEST_ASSERT(PR_GetError() == PR_IO_TIMEOUT_ERROR);
- break;
- case CLIENT_NORMAL:
- TEST_ASSERT(clientSock);
- bytesRead = PR_Recv(clientSock,
- buf, CLIENT_DATA, 0, timeoutTime);
- TEST_ASSERT(bytesRead == CLIENT_DATA);
- break;
- case CLIENT_TIMEOUT_SEND:
- TEST_ASSERT(clientSock);
- bytesRead = PR_Recv(clientSock,
- buf, CLIENT_DATA, 0, timeoutTime);
- TEST_ASSERT(bytesRead == -1);
- TEST_ASSERT(PR_GetError() == PR_IO_TIMEOUT_ERROR);
- break;
- }
- break;
- case ACCEPT_READ:
- status = PR_AcceptRead(listenSock, &clientSock,
- &raddr, buf, CLIENT_DATA, timeoutTime);
- switch(clientAction) {
- case CLIENT_TIMEOUT_ACCEPT:
- /* Invalid test case */
- TEST_ASSERT(0);
- break;
- case CLIENT_NORMAL:
- TEST_ASSERT(clientSock);
- TEST_ASSERT(status == CLIENT_DATA);
+ case ACCEPT_NORMAL:
+ clientSock = PR_Accept(listenSock, &clientAddr,
+ timeoutTime);
+ switch(clientAction) {
+ case CLIENT_TIMEOUT_ACCEPT:
+ TEST_ASSERT(clientSock == 0);
+ TEST_ASSERT(PR_GetError() == PR_IO_TIMEOUT_ERROR);
+ break;
+ case CLIENT_NORMAL:
+ TEST_ASSERT(clientSock);
+ bytesRead = PR_Recv(clientSock,
+ buf, CLIENT_DATA, 0, timeoutTime);
+ TEST_ASSERT(bytesRead == CLIENT_DATA);
+ break;
+ case CLIENT_TIMEOUT_SEND:
+ TEST_ASSERT(clientSock);
+ bytesRead = PR_Recv(clientSock,
+ buf, CLIENT_DATA, 0, timeoutTime);
+ TEST_ASSERT(bytesRead == -1);
+ TEST_ASSERT(PR_GetError() == PR_IO_TIMEOUT_ERROR);
+ break;
+ }
break;
- case CLIENT_TIMEOUT_SEND:
- TEST_ASSERT(status == -1);
- TEST_ASSERT(PR_GetError() == PR_IO_TIMEOUT_ERROR);
+ case ACCEPT_READ:
+ status = PR_AcceptRead(listenSock, &clientSock,
+ &raddr, buf, CLIENT_DATA, timeoutTime);
+ switch(clientAction) {
+ case CLIENT_TIMEOUT_ACCEPT:
+ /* Invalid test case */
+ TEST_ASSERT(0);
+ break;
+ case CLIENT_NORMAL:
+ TEST_ASSERT(clientSock);
+ TEST_ASSERT(status == CLIENT_DATA);
+ break;
+ case CLIENT_TIMEOUT_SEND:
+ TEST_ASSERT(status == -1);
+ TEST_ASSERT(PR_GetError() == PR_IO_TIMEOUT_ERROR);
+ break;
+ }
break;
- }
- break;
#ifdef WINNT
- case ACCEPT_FAST:
- clientSock = PR_NTFast_Accept(listenSock,
- &clientAddr, timeoutTime);
- switch(clientAction) {
- case CLIENT_TIMEOUT_ACCEPT:
- TEST_ASSERT(clientSock == 0);
- if (debug_mode)
- PR_fprintf(output, "PR_GetError is %ld\n", PR_GetError());
- TEST_ASSERT(PR_GetError() == PR_IO_TIMEOUT_ERROR);
- break;
- case CLIENT_NORMAL:
- TEST_ASSERT(clientSock);
- bytesRead = PR_Recv(clientSock,
- buf, CLIENT_DATA, 0, timeoutTime);
- TEST_ASSERT(bytesRead == CLIENT_DATA);
- break;
- case CLIENT_TIMEOUT_SEND:
- TEST_ASSERT(clientSock);
- bytesRead = PR_Recv(clientSock,
- buf, CLIENT_DATA, 0, timeoutTime);
- TEST_ASSERT(bytesRead == -1);
- TEST_ASSERT(PR_GetError() == PR_IO_TIMEOUT_ERROR);
- break;
- }
- break;
- break;
- case ACCEPT_READ_FAST:
- status = PR_NTFast_AcceptRead(listenSock,
- &clientSock, &raddr, buf, 4096, timeoutTime);
- switch(clientAction) {
- case CLIENT_TIMEOUT_ACCEPT:
- /* Invalid test case */
- TEST_ASSERT(0);
- break;
- case CLIENT_NORMAL:
- TEST_ASSERT(clientSock);
- TEST_ASSERT(status == CLIENT_DATA);
- break;
- case CLIENT_TIMEOUT_SEND:
- TEST_ASSERT(clientSock == NULL);
- TEST_ASSERT(status == -1);
- TEST_ASSERT(PR_GetError() == PR_IO_TIMEOUT_ERROR);
+ case ACCEPT_FAST:
+ clientSock = PR_NTFast_Accept(listenSock,
+ &clientAddr, timeoutTime);
+ switch(clientAction) {
+ case CLIENT_TIMEOUT_ACCEPT:
+ TEST_ASSERT(clientSock == 0);
+ if (debug_mode) {
+ PR_fprintf(output, "PR_GetError is %ld\n", PR_GetError());
+ }
+ TEST_ASSERT(PR_GetError() == PR_IO_TIMEOUT_ERROR);
+ break;
+ case CLIENT_NORMAL:
+ TEST_ASSERT(clientSock);
+ bytesRead = PR_Recv(clientSock,
+ buf, CLIENT_DATA, 0, timeoutTime);
+ TEST_ASSERT(bytesRead == CLIENT_DATA);
+ break;
+ case CLIENT_TIMEOUT_SEND:
+ TEST_ASSERT(clientSock);
+ bytesRead = PR_Recv(clientSock,
+ buf, CLIENT_DATA, 0, timeoutTime);
+ TEST_ASSERT(bytesRead == -1);
+ TEST_ASSERT(PR_GetError() == PR_IO_TIMEOUT_ERROR);
+ break;
+ }
break;
- }
- break;
- case ACCEPT_READ_FAST_CB:
- status = PR_NTFast_AcceptRead_WithTimeoutCallback(
- listenSock, &clientSock, &raddr, buf, 4096,
- timeoutTime, timeout_callback, (void *)CALLBACK_MAGIC);
- switch(clientAction) {
- case CLIENT_TIMEOUT_ACCEPT:
- /* Invalid test case */
- TEST_ASSERT(0);
break;
- case CLIENT_NORMAL:
- TEST_ASSERT(clientSock);
- TEST_ASSERT(status == CLIENT_DATA);
+ case ACCEPT_READ_FAST:
+ status = PR_NTFast_AcceptRead(listenSock,
+ &clientSock, &raddr, buf, 4096, timeoutTime);
+ switch(clientAction) {
+ case CLIENT_TIMEOUT_ACCEPT:
+ /* Invalid test case */
+ TEST_ASSERT(0);
+ break;
+ case CLIENT_NORMAL:
+ TEST_ASSERT(clientSock);
+ TEST_ASSERT(status == CLIENT_DATA);
+ break;
+ case CLIENT_TIMEOUT_SEND:
+ TEST_ASSERT(clientSock == NULL);
+ TEST_ASSERT(status == -1);
+ TEST_ASSERT(PR_GetError() == PR_IO_TIMEOUT_ERROR);
+ break;
+ }
break;
- case CLIENT_TIMEOUT_SEND:
- if (debug_mode)
- PR_fprintf(output, "clientSock = 0x%8.8lx\n", clientSock);
- TEST_ASSERT(clientSock == NULL);
- TEST_ASSERT(status == -1);
- TEST_ASSERT(PR_GetError() == PR_IO_TIMEOUT_ERROR);
+ case ACCEPT_READ_FAST_CB:
+ status = PR_NTFast_AcceptRead_WithTimeoutCallback(
+ listenSock, &clientSock, &raddr, buf, 4096,
+ timeoutTime, timeout_callback, (void *)CALLBACK_MAGIC);
+ switch(clientAction) {
+ case CLIENT_TIMEOUT_ACCEPT:
+ /* Invalid test case */
+ TEST_ASSERT(0);
+ break;
+ case CLIENT_NORMAL:
+ TEST_ASSERT(clientSock);
+ TEST_ASSERT(status == CLIENT_DATA);
+ break;
+ case CLIENT_TIMEOUT_SEND:
+ if (debug_mode) {
+ PR_fprintf(output, "clientSock = 0x%8.8lx\n", clientSock);
+ }
+ TEST_ASSERT(clientSock == NULL);
+ TEST_ASSERT(status == -1);
+ TEST_ASSERT(PR_GetError() == PR_IO_TIMEOUT_ERROR);
+ break;
+ }
break;
- }
- break;
#endif
}
if (clientSock != NULL) {
@@ -419,8 +432,9 @@ static void Measure(void (*func)(void), const char *msg)
stop = PR_IntervalNow();
d = (double)PR_IntervalToMicroseconds(stop - start);
- if (debug_mode)
+ if (debug_mode) {
PR_fprintf(output, "%40s: %6.2f usec\n", msg, d / count);
+ }
}
@@ -437,20 +451,22 @@ int main(int argc, char **argv)
PLOptState *opt = PL_CreateOptState(argc, argv, "Gdc:");
while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
- if (PL_OPT_BAD == os) continue;
+ if (PL_OPT_BAD == os) {
+ continue;
+ }
switch (opt->option)
{
- case 'G': /* global threads */
- thread_scope = PR_GLOBAL_THREAD;
- break;
- case 'd': /* debug mode */
- debug_mode = 1;
- break;
- case 'c': /* loop counter */
- count = atoi(opt->value);
- break;
- default:
- break;
+ case 'G': /* global threads */
+ thread_scope = PR_GLOBAL_THREAD;
+ break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ case 'c': /* loop counter */
+ count = atoi(opt->value);
+ break;
+ default:
+ break;
}
}
PL_DestroyOptState(opt);
@@ -460,8 +476,9 @@ int main(int argc, char **argv)
PR_STDIO_INIT();
timeoutTime = PR_SecondsToInterval(TIMEOUTSECS);
- if (debug_mode)
+ if (debug_mode) {
PR_fprintf(output, "\nRun accept() sucessful connection tests\n");
+ }
Measure(AcceptUpdatedTest, "PR_Accept()");
Measure(AcceptReadTest, "PR_AcceptRead()");
@@ -470,14 +487,16 @@ int main(int argc, char **argv)
Measure(AcceptReadNotUpdatedTest, "PR_NTFast_AcceptRead()");
Measure(AcceptReadCallbackTest, "PR_NTFast_AcceptRead_WithTimeoutCallback()");
#endif
- if (debug_mode)
+ if (debug_mode) {
PR_fprintf(output, "\nRun accept() timeout in the accept tests\n");
+ }
#ifdef WINNT
Measure(TimeoutReadReadCallbackTest, "PR_NTFast_AcceptRead_WithTimeoutCallback()");
#endif
Measure(TimeoutReadUpdatedTest, "PR_Accept()");
- if (debug_mode)
+ if (debug_mode) {
PR_fprintf(output, "\nRun accept() timeout in the read tests\n");
+ }
Measure(TimeoutReadReadTest, "PR_AcceptRead()");
#ifdef WINNT
Measure(TimeoutReadNotUpdatedTest, "PR_NTFast_Accept()");
diff --git a/pr/tests/acceptread.c b/pr/tests/acceptread.c
index 1d3dab6e..d7fe079c 100644
--- a/pr/tests/acceptread.c
+++ b/pr/tests/acceptread.c
@@ -23,10 +23,12 @@ static PRStatus PrintAddress(const PRNetAddr* address)
{
char buffer[100];
PRStatus rv = PR_NetAddrToString(address, buffer, sizeof(buffer));
- if (PR_FAILURE == rv) PL_FPrintError(err_out, "PR_NetAddrToString");
+ if (PR_FAILURE == rv) {
+ PL_FPrintError(err_out, "PR_NetAddrToString");
+ }
else PR_fprintf(
- std_out, "Accepted connection from (0x%p)%s:%d\n",
- address, buffer, address->inet.port);
+ std_out, "Accepted connection from (0x%p)%s:%d\n",
+ address, buffer, address->inet.port);
return rv;
} /* PrintAddress */
@@ -66,10 +68,14 @@ static void ConnectingThread(void *arg)
PR_Sleep(write_dally);
nbytes = PR_Send(sock, GET, sizeof(GET), 0, PR_INTERVAL_NO_TIMEOUT);
- if (nbytes == -1) PL_FPrintError(err_out, "PR_Send (client) failed");
+ if (nbytes == -1) {
+ PL_FPrintError(err_out, "PR_Send (client) failed");
+ }
nbytes = PR_Recv(sock, buf, sizeof(buf), 0, PR_INTERVAL_NO_TIMEOUT);
- if (nbytes == -1) PL_FPrintError(err_out, "PR_Recv (client) failed");
+ if (nbytes == -1) {
+ PL_FPrintError(err_out, "PR_Recv (client) failed");
+ }
else
{
PR_fprintf(std_out, "PR_Recv (client) succeeded: %d bytes\n", nbytes);
@@ -77,11 +83,13 @@ static void ConnectingThread(void *arg)
PR_fprintf(std_out, "%s\n", buf);
}
- if (PR_FAILURE == PR_Shutdown(sock, PR_SHUTDOWN_BOTH))
+ if (PR_FAILURE == PR_Shutdown(sock, PR_SHUTDOWN_BOTH)) {
PL_FPrintError(err_out, "PR_Shutdown (client) failed");
+ }
- if (PR_FAILURE == PR_Close(sock))
+ if (PR_FAILURE == PR_Close(sock)) {
PL_FPrintError(err_out, "PR_Close (client) failed");
+ }
return;
} /* ConnectingThread */
@@ -123,9 +131,11 @@ static void AcceptingThread(void *arg)
PR_ProcessExit(1);
}
bytes = PR_AcceptRead(
- listen_sock, &accept_sock, &accept_addr, buf, buf_size, accept_timeout);
+ listen_sock, &accept_sock, &accept_addr, buf, buf_size, accept_timeout);
- if (-1 == bytes) PL_FPrintError(err_out, "PR_AcceptRead (server) failed");
+ if (-1 == bytes) {
+ PL_FPrintError(err_out, "PR_AcceptRead (server) failed");
+ }
else
{
PrintAddress(accept_addr);
@@ -134,20 +144,23 @@ static void AcceptingThread(void *arg)
buf, &buf[BUF_SIZE], buf);
bytes = PR_Write(accept_sock, buf, bytes);
rv = PR_Shutdown(accept_sock, PR_SHUTDOWN_BOTH);
- if (PR_FAILURE == rv)
+ if (PR_FAILURE == rv) {
PL_FPrintError(err_out, "PR_Shutdown (server) failed");
+ }
}
if (-1 != bytes)
{
rv = PR_Close(accept_sock);
- if (PR_FAILURE == rv)
+ if (PR_FAILURE == rv) {
PL_FPrintError(err_out, "PR_Close (server) failed");
+ }
}
rv = PR_Close(listen_sock);
- if (PR_FAILURE == rv)
+ if (PR_FAILURE == rv) {
PL_FPrintError(err_out, "PR_Close (server) failed");
+ }
} /* AcceptingThread */
int main(int argc, char **argv)
@@ -165,8 +178,12 @@ int main(int argc, char **argv)
std_out = PR_STDOUT;
accept_timeout = PR_SecondsToInterval(2);
- if (argc != 2 && argc != 3) port_number = DEFAULT_PORT;
- else port_number = (PRUint16)atoi(argv[(argc == 2) ? 1 : 2]);
+ if (argc != 2 && argc != 3) {
+ port_number = DEFAULT_PORT;
+ }
+ else {
+ port_number = (PRUint16)atoi(argv[(argc == 2) ? 1 : 2]);
+ }
status = PR_InitializeNetAddr(PR_IpAddrAny, port_number, &server_addr);
if (PR_SUCCESS != status)
@@ -177,7 +194,7 @@ int main(int argc, char **argv)
if (argc < 3)
{
status = PR_InitializeNetAddr(
- PR_IpAddrLoopback, port_number, &client_addr);
+ PR_IpAddrLoopback, port_number, &client_addr);
if (PR_SUCCESS != status)
{
PL_FPrintError(err_out, "PR_InitializeNetAddr failed");
@@ -187,7 +204,7 @@ int main(int argc, char **argv)
else
{
status = PR_GetHostByName(
- argv[1], netdb_buf, sizeof(netdb_buf), &he);
+ argv[1], netdb_buf, sizeof(netdb_buf), &he);
if (status == PR_FAILURE)
{
PL_FPrintError(err_out, "PR_GetHostByName failed");
@@ -210,8 +227,8 @@ int main(int argc, char **argv)
std_out, "Testing w/ write_dally = %d msec\n",
PR_IntervalToMilliseconds(write_dally));
server_thread = PR_CreateThread(
- PR_USER_THREAD, AcceptingThread, &server_addr,
- PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, AcceptingThread, &server_addr,
+ PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
if (server_thread == NULL)
{
PL_FPrintError(err_out, "PR_CreateThread (server) failed");
@@ -221,19 +238,21 @@ int main(int argc, char **argv)
PR_Sleep(delta); /* let the server pot thicken */
client_thread = PR_CreateThread(
- PR_USER_THREAD, ConnectingThread, &client_addr,
- PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, ConnectingThread, &client_addr,
+ PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
if (client_thread == NULL)
{
PL_FPrintError(err_out, "PR_CreateThread (client) failed");
PR_ProcessExit(1);
}
- if (PR_JoinThread(client_thread) == PR_FAILURE)
+ if (PR_JoinThread(client_thread) == PR_FAILURE) {
PL_FPrintError(err_out, "PR_JoinThread (client) failed");
+ }
- if (PR_JoinThread(server_thread) == PR_FAILURE)
+ if (PR_JoinThread(server_thread) == PR_FAILURE) {
PL_FPrintError(err_out, "PR_JoinThread (server) failed");
+ }
}
return 0;
diff --git a/pr/tests/acceptreademu.c b/pr/tests/acceptreademu.c
index bc5f6daf..75140c02 100644
--- a/pr/tests/acceptreademu.c
+++ b/pr/tests/acceptreademu.c
@@ -29,7 +29,7 @@ static PRIOMethods emu_layer_methods;
/* the acceptread method in emu_layer_methods */
static PRInt32 PR_CALLBACK emu_AcceptRead(PRFileDesc *sd, PRFileDesc **nd,
- PRNetAddr **raddr, void *buf, PRInt32 amount, PRIntervalTime timeout)
+ PRNetAddr **raddr, void *buf, PRInt32 amount, PRIntervalTime timeout)
{
return PR_EmulateAcceptRead(sd, nd, raddr, buf, amount, timeout);
}
@@ -38,10 +38,12 @@ static PRStatus PrintAddress(const PRNetAddr* address)
{
char buffer[100];
PRStatus rv = PR_NetAddrToString(address, buffer, sizeof(buffer));
- if (PR_FAILURE == rv) PL_FPrintError(err_out, "PR_NetAddrToString");
+ if (PR_FAILURE == rv) {
+ PL_FPrintError(err_out, "PR_NetAddrToString");
+ }
else PR_fprintf(
- std_out, "Accepted connection from (0x%p)%s:%d\n",
- address, buffer, address->inet.port);
+ std_out, "Accepted connection from (0x%p)%s:%d\n",
+ address, buffer, address->inet.port);
return rv;
} /* PrintAddress */
@@ -81,10 +83,14 @@ static void ConnectingThread(void *arg)
PR_Sleep(write_dally);
nbytes = PR_Send(sock, GET, sizeof(GET), 0, PR_INTERVAL_NO_TIMEOUT);
- if (nbytes == -1) PL_FPrintError(err_out, "PR_Send (client) failed");
+ if (nbytes == -1) {
+ PL_FPrintError(err_out, "PR_Send (client) failed");
+ }
nbytes = PR_Recv(sock, buf, sizeof(buf), 0, PR_INTERVAL_NO_TIMEOUT);
- if (nbytes == -1) PL_FPrintError(err_out, "PR_Recv (client) failed");
+ if (nbytes == -1) {
+ PL_FPrintError(err_out, "PR_Recv (client) failed");
+ }
else
{
PR_fprintf(std_out, "PR_Recv (client) succeeded: %d bytes\n", nbytes);
@@ -92,11 +98,13 @@ static void ConnectingThread(void *arg)
PR_fprintf(std_out, "%s\n", buf);
}
- if (PR_FAILURE == PR_Shutdown(sock, PR_SHUTDOWN_BOTH))
+ if (PR_FAILURE == PR_Shutdown(sock, PR_SHUTDOWN_BOTH)) {
PL_FPrintError(err_out, "PR_Shutdown (client) failed");
+ }
- if (PR_FAILURE == PR_Close(sock))
+ if (PR_FAILURE == PR_Close(sock)) {
PL_FPrintError(err_out, "PR_Close (client) failed");
+ }
return;
} /* ConnectingThread */
@@ -150,9 +158,11 @@ static void AcceptingThread(void *arg)
PR_ProcessExit(1);
}
bytes = PR_AcceptRead(
- listen_sock, &accept_sock, &accept_addr, buf, buf_size, accept_timeout);
+ listen_sock, &accept_sock, &accept_addr, buf, buf_size, accept_timeout);
- if (-1 == bytes) PL_FPrintError(err_out, "PR_AcceptRead (server) failed");
+ if (-1 == bytes) {
+ PL_FPrintError(err_out, "PR_AcceptRead (server) failed");
+ }
else
{
PrintAddress(accept_addr);
@@ -161,20 +171,23 @@ static void AcceptingThread(void *arg)
buf, &buf[BUF_SIZE], buf);
bytes = PR_Write(accept_sock, buf, bytes);
rv = PR_Shutdown(accept_sock, PR_SHUTDOWN_BOTH);
- if (PR_FAILURE == rv)
+ if (PR_FAILURE == rv) {
PL_FPrintError(err_out, "PR_Shutdown (server) failed");
+ }
}
if (-1 != bytes)
{
rv = PR_Close(accept_sock);
- if (PR_FAILURE == rv)
+ if (PR_FAILURE == rv) {
PL_FPrintError(err_out, "PR_Close (server) failed");
+ }
}
rv = PR_Close(listen_sock);
- if (PR_FAILURE == rv)
+ if (PR_FAILURE == rv) {
PL_FPrintError(err_out, "PR_Close (server) failed");
+ }
} /* AcceptingThread */
int main(int argc, char **argv)
@@ -195,8 +208,12 @@ int main(int argc, char **argv)
emu_layer_methods = *PR_GetDefaultIOMethods();
emu_layer_methods.acceptread = emu_AcceptRead;
- if (argc != 2 && argc != 3) port_number = DEFAULT_PORT;
- else port_number = (PRUint16)atoi(argv[(argc == 2) ? 1 : 2]);
+ if (argc != 2 && argc != 3) {
+ port_number = DEFAULT_PORT;
+ }
+ else {
+ port_number = (PRUint16)atoi(argv[(argc == 2) ? 1 : 2]);
+ }
status = PR_InitializeNetAddr(PR_IpAddrAny, port_number, &server_addr);
if (PR_SUCCESS != status)
@@ -207,7 +224,7 @@ int main(int argc, char **argv)
if (argc < 3)
{
status = PR_InitializeNetAddr(
- PR_IpAddrLoopback, port_number, &client_addr);
+ PR_IpAddrLoopback, port_number, &client_addr);
if (PR_SUCCESS != status)
{
PL_FPrintError(err_out, "PR_InitializeNetAddr failed");
@@ -217,7 +234,7 @@ int main(int argc, char **argv)
else
{
status = PR_GetHostByName(
- argv[1], netdb_buf, sizeof(netdb_buf), &he);
+ argv[1], netdb_buf, sizeof(netdb_buf), &he);
if (status == PR_FAILURE)
{
PL_FPrintError(err_out, "PR_GetHostByName failed");
@@ -240,8 +257,8 @@ int main(int argc, char **argv)
std_out, "Testing w/ write_dally = %d msec\n",
PR_IntervalToMilliseconds(write_dally));
server_thread = PR_CreateThread(
- PR_USER_THREAD, AcceptingThread, &server_addr,
- PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, AcceptingThread, &server_addr,
+ PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
if (server_thread == NULL)
{
PL_FPrintError(err_out, "PR_CreateThread (server) failed");
@@ -251,19 +268,21 @@ int main(int argc, char **argv)
PR_Sleep(delta); /* let the server pot thicken */
client_thread = PR_CreateThread(
- PR_USER_THREAD, ConnectingThread, &client_addr,
- PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, ConnectingThread, &client_addr,
+ PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
if (client_thread == NULL)
{
PL_FPrintError(err_out, "PR_CreateThread (client) failed");
PR_ProcessExit(1);
}
- if (PR_JoinThread(client_thread) == PR_FAILURE)
+ if (PR_JoinThread(client_thread) == PR_FAILURE) {
PL_FPrintError(err_out, "PR_JoinThread (client) failed");
+ }
- if (PR_JoinThread(server_thread) == PR_FAILURE)
+ if (PR_JoinThread(server_thread) == PR_FAILURE) {
PL_FPrintError(err_out, "PR_JoinThread (server) failed");
+ }
}
return 0;
diff --git a/pr/tests/addrstr.c b/pr/tests/addrstr.c
index 6c84b55f..b6736a74 100644
--- a/pr/tests/addrstr.c
+++ b/pr/tests/addrstr.c
@@ -49,23 +49,23 @@ int main(int argc, char **argv)
PRStatus rv;
while ((in = *nexttestaddr++) != 0) {
- expected_out = *nexttestaddr++;
- rv = PR_StringToNetAddr(in, &addr);
- if (rv) {
- printf("cannot convert %s to addr: %d\n", in, rv);
+ expected_out = *nexttestaddr++;
+ rv = PR_StringToNetAddr(in, &addr);
+ if (rv) {
+ printf("cannot convert %s to addr: %d\n", in, rv);
failed_already = 1;
- continue;
- }
- rv = PR_NetAddrToString(&addr, buf, sizeof(buf));
- if (rv) {
- printf("cannot convert %s back to string: %d\n", in, rv);
+ continue;
+ }
+ rv = PR_NetAddrToString(&addr, buf, sizeof(buf));
+ if (rv) {
+ printf("cannot convert %s back to string: %d\n", in, rv);
failed_already = 1;
- continue;
- }
- if (strcmp(buf, expected_out)) {
+ continue;
+ }
+ if (strcmp(buf, expected_out)) {
/* This is not necessarily an error */
- printf("%s expected %s got %s\n", in, expected_out, buf);
- }
+ printf("%s expected %s got %s\n", in, expected_out, buf);
+ }
}
while ((in = *nextbadaddr++) != 0) {
if (PR_StringToNetAddr(in, &addr) == PR_SUCCESS) {
diff --git a/pr/tests/affinity.c b/pr/tests/affinity.c
index 52a9b28f..14d08efc 100644
--- a/pr/tests/affinity.c
+++ b/pr/tests/affinity.c
@@ -14,69 +14,71 @@
/*
* Test PR_GetThreadAffinityMask
- * The function is called by each of local, global and global bound threads
- * The test should be run on both single and multi-cpu systems
+ * The function is called by each of local, global and global bound threads
+ * The test should be run on both single and multi-cpu systems
*/
static void PR_CALLBACK thread_start(void *arg)
{
-PRUint32 mask = 0;
+ PRUint32 mask = 0;
- if (PR_GetThreadAffinityMask(PR_GetCurrentThread(), &mask))
- printf("\tthread_start: PR_GetCurrentThreadAffinityMask failed\n");
- else
- printf("\tthread_start: AffinityMask = 0x%x\n",mask);
+ if (PR_GetThreadAffinityMask(PR_GetCurrentThread(), &mask)) {
+ printf("\tthread_start: PR_GetCurrentThreadAffinityMask failed\n");
+ }
+ else {
+ printf("\tthread_start: AffinityMask = 0x%x\n",mask);
+ }
}
int main(int argc, char **argv)
{
- PRThread *t;
-
- printf("main: creating local thread\n");
-
- t = PR_CreateThread(PR_USER_THREAD,
- thread_start, 0,
- PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD,
- PR_JOINABLE_THREAD,
- 0);
-
- if (NULL == t) {
- printf("main: cannot create local thread\n");
- exit(1);
- }
-
- PR_JoinThread(t);
-
- printf("main: creating global thread\n");
- t = PR_CreateThread(PR_USER_THREAD,
- thread_start, 0,
- PR_PRIORITY_NORMAL,
- PR_GLOBAL_THREAD,
- PR_JOINABLE_THREAD,
- 0);
-
- if (NULL == t) {
- printf("main: cannot create global thread\n");
- exit(1);
- }
-
- PR_JoinThread(t);
-
- printf("main: creating global bound thread\n");
- t = PR_CreateThread(PR_USER_THREAD,
- thread_start, 0,
- PR_PRIORITY_NORMAL,
- PR_GLOBAL_BOUND_THREAD,
- PR_JOINABLE_THREAD,
- 0);
-
- if (NULL == t) {
- printf("main: cannot create global bound thread\n");
- exit(1);
- }
-
- PR_JoinThread(t);
+ PRThread *t;
+
+ printf("main: creating local thread\n");
+
+ t = PR_CreateThread(PR_USER_THREAD,
+ thread_start, 0,
+ PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD,
+ PR_JOINABLE_THREAD,
+ 0);
+
+ if (NULL == t) {
+ printf("main: cannot create local thread\n");
+ exit(1);
+ }
+
+ PR_JoinThread(t);
+
+ printf("main: creating global thread\n");
+ t = PR_CreateThread(PR_USER_THREAD,
+ thread_start, 0,
+ PR_PRIORITY_NORMAL,
+ PR_GLOBAL_THREAD,
+ PR_JOINABLE_THREAD,
+ 0);
+
+ if (NULL == t) {
+ printf("main: cannot create global thread\n");
+ exit(1);
+ }
+
+ PR_JoinThread(t);
+
+ printf("main: creating global bound thread\n");
+ t = PR_CreateThread(PR_USER_THREAD,
+ thread_start, 0,
+ PR_PRIORITY_NORMAL,
+ PR_GLOBAL_BOUND_THREAD,
+ PR_JOINABLE_THREAD,
+ 0);
+
+ if (NULL == t) {
+ printf("main: cannot create global bound thread\n");
+ exit(1);
+ }
+
+ PR_JoinThread(t);
return 0;
}
diff --git a/pr/tests/alarm.c b/pr/tests/alarm.c
index 3a2ff35e..10a148e4 100644
--- a/pr/tests/alarm.c
+++ b/pr/tests/alarm.c
@@ -12,12 +12,12 @@
**
** Modification History:
** 13-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.
***********************************************************************/
/***********************************************************************
@@ -60,8 +60,9 @@ static void Notifier(void *arg)
PR_Lock(notifyData->ml);
while (notifyData->counter > 0)
{
- while (!notifyData->pending)
+ while (!notifyData->pending) {
PR_WaitCondVar(notifyData->child, PR_INTERVAL_NO_TIMEOUT);
+ }
notifyData->counter -= 1;
notifyData->pending = PR_FALSE;
PR_NotifyCondVar(notifyData->parent);
@@ -98,9 +99,9 @@ static PRIntervalTime ConditionNotify(PRUint32 loops)
notifyData.child = PR_NewCondVar(notifyData.ml);
notifyData.parent = PR_NewCondVar(notifyData.ml);
thread = PR_CreateThread(
- PR_USER_THREAD, Notifier, &notifyData,
- PR_GetThreadPriority(PR_GetCurrentThread()),
- thread_scope, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, Notifier, &notifyData,
+ PR_GetThreadPriority(PR_GetCurrentThread()),
+ thread_scope, PR_JOINABLE_THREAD, 0);
overhead = PR_IntervalNow() - timein; /* elapsed so far */
@@ -109,8 +110,9 @@ static PRIntervalTime ConditionNotify(PRUint32 loops)
{
notifyData.pending = PR_TRUE;
PR_NotifyCondVar(notifyData.child);
- while (notifyData.pending)
+ while (notifyData.pending) {
PR_WaitCondVar(notifyData.parent, PR_INTERVAL_NO_TIMEOUT);
+ }
}
PR_Unlock(notifyData.ml);
@@ -171,9 +173,10 @@ static PRBool AlarmFn1(PRAlarmID *id, void *clientData, PRUint32 late)
ad->late += late;
ad->times += 1;
keepGoing = ((PRIntervalTime)(now - ad->timein) < ad->duration) ?
- PR_TRUE : PR_FALSE;
- if (!keepGoing)
+ PR_TRUE : PR_FALSE;
+ if (!keepGoing) {
rv = PR_NotifyCondVar(ad->cv);
+ }
resetAlarm = ((ad->times % 31) == 0) ? PR_TRUE : PR_FALSE;
interval = (ad->period + ad->rate - 1) / ad->rate;
@@ -187,11 +190,14 @@ static PRBool AlarmFn1(PRAlarmID *id, void *clientData, PRUint32 late)
if (rv != PR_SUCCESS)
{
- if (!debug_mode) failed_already=1;
- else
- printf("AlarmFn: notify status: FAIL\n");
+ if (!debug_mode) {
+ failed_already=1;
+ }
+ else {
+ printf("AlarmFn: notify status: FAIL\n");
+ }
- }
+ }
if (resetAlarm)
{
@@ -199,10 +205,12 @@ static PRBool AlarmFn1(PRAlarmID *id, void *clientData, PRUint32 late)
ad->late = ad->times = 0;
if (PR_ResetAlarm(id, ad->period, ad->rate) != PR_SUCCESS)
{
- if (!debug_mode)
- failed_already=1;
- else
- printf("AlarmFn: Resetting alarm status: FAIL\n");
+ if (!debug_mode) {
+ failed_already=1;
+ }
+ else {
+ printf("AlarmFn: Resetting alarm status: FAIL\n");
+ }
keepGoing = PR_FALSE;
}
@@ -239,8 +247,9 @@ static PRIntervalTime Alarms1(PRUint32 loops)
overhead = PR_IntervalNow() - timein;
PR_Lock(ml);
- while ((PRIntervalTime)(PR_IntervalNow() - ad.timein) < duration)
+ while ((PRIntervalTime)(PR_IntervalNow() - ad.timein) < duration) {
PR_WaitCondVar(cv, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_Unlock(ml);
timein = PR_IntervalNow();
@@ -262,7 +271,7 @@ static PRBool AlarmFn2(PRAlarmID *id, void *clientData, PRUint32 late)
PR_Lock(ad->ml);
ad->times += 1;
keepGoing = ((PRIntervalTime)(now - ad->timein) < ad->duration) ?
- PR_TRUE : PR_FALSE;
+ PR_TRUE : PR_FALSE;
interval = (ad->period + ad->rate - 1) / ad->rate;
if (!late && (interval > 10))
@@ -271,13 +280,16 @@ static PRBool AlarmFn2(PRAlarmID *id, void *clientData, PRUint32 late)
PR_WaitCondVar(ad->cv, interval);
}
- if (!keepGoing) rv = PR_NotifyCondVar(ad->cv);
+ if (!keepGoing) {
+ rv = PR_NotifyCondVar(ad->cv);
+ }
PR_Unlock(ad->ml);
- if (rv != PR_SUCCESS)
- failed_already=1;;
+ if (rv != PR_SUCCESS) {
+ failed_already=1;
+ };
return keepGoing;
} /* AlarmFn2 */
@@ -310,8 +322,9 @@ static PRIntervalTime Alarms2(PRUint32 loops)
overhead = PR_IntervalNow() - timein;
PR_Lock(ml);
- while ((PRIntervalTime)(PR_IntervalNow() - ad.timein) < duration)
+ while ((PRIntervalTime)(PR_IntervalNow() - ad.timein) < duration) {
PR_WaitCondVar(cv, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_Unlock(ml);
timein = PR_IntervalNow();
@@ -319,10 +332,12 @@ static PRIntervalTime Alarms2(PRUint32 loops)
rv = PR_DestroyAlarm(alarm);
if (rv != PR_SUCCESS)
{
- if (!debug_mode)
- failed_already=1;
- else
- printf("***Destroying alarm status: FAIL\n");
+ if (!debug_mode) {
+ failed_already=1;
+ }
+ else {
+ printf("***Destroying alarm status: FAIL\n");
+ }
}
@@ -376,26 +391,29 @@ static PRIntervalTime Alarms3(PRUint32 loops)
PR_Lock(ml);
for (i = 0; i < 3; ++i)
{
- while ((PRIntervalTime)(PR_IntervalNow() - ad[i].timein) < duration)
+ while ((PRIntervalTime)(PR_IntervalNow() - ad[i].timein) < duration) {
PR_WaitCondVar(cv, PR_INTERVAL_NO_TIMEOUT);
+ }
}
PR_Unlock(ml);
timein = PR_IntervalNow();
- if (debug_mode)
- printf
+ if (debug_mode)
+ printf
("Alarms3 finished at %u, %u, %u\n",
- ad[0].timein, ad[1].timein, ad[2].timein);
+ ad[0].timein, ad[1].timein, ad[2].timein);
rv = PR_DestroyAlarm(alarm);
if (rv != PR_SUCCESS)
{
- if (!debug_mode)
- failed_already=1;
- else
- printf("***Destroying alarm status: FAIL\n");
- }
+ if (!debug_mode) {
+ failed_already=1;
+ }
+ else {
+ printf("***Destroying alarm status: FAIL\n");
+ }
+ }
PR_DestroyCondVar(cv);
PR_DestroyLock(ml);
@@ -411,15 +429,17 @@ static PRUint32 TimeThis(
PRUint32 overhead, usecs;
PRIntervalTime predicted, timein, timeout, ticks;
- if (debug_mode)
- printf("Testing %s ...", msg);
+ if (debug_mode) {
+ printf("Testing %s ...", msg);
+ }
timein = PR_IntervalNow();
predicted = func(loops);
timeout = PR_IntervalNow();
- if (debug_mode)
- printf(" done\n");
+ if (debug_mode) {
+ printf(" done\n");
+ }
ticks = timeout - timein;
usecs = PR_IntervalToMicroseconds(ticks);
@@ -427,18 +447,18 @@ static PRUint32 TimeThis(
if(ticks < predicted)
{
- if (debug_mode) {
- printf("\tFinished in negative time\n");
- printf("\tpredicted overhead was %d usecs\n", overhead);
- printf("\ttest completed in %d usecs\n\n", usecs);
- }
+ if (debug_mode) {
+ printf("\tFinished in negative time\n");
+ printf("\tpredicted overhead was %d usecs\n", overhead);
+ printf("\ttest completed in %d usecs\n\n", usecs);
+ }
}
else
{
- if (debug_mode)
- printf(
- "\ttotal: %d usecs\n\toverhead: %d usecs\n\tcost: %6.3f usecs\n\n",
- usecs, overhead, ((double)(usecs - overhead) / (double)loops));
+ if (debug_mode)
+ printf(
+ "\ttotal: %d usecs\n\toverhead: %d usecs\n\tcost: %6.3f usecs\n\n",
+ usecs, overhead, ((double)(usecs - overhead) / (double)loops));
}
return overhead;
@@ -448,70 +468,83 @@ int prmain(int argc, char** argv)
{
PRUint32 cpu, cpus = 0, loops = 0;
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name [-d]
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "Gdl:c:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name [-d]
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "Gdl:c:");
+ while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
- if (PL_OPT_BAD == os) continue;
+ if (PL_OPT_BAD == os) {
+ continue;
+ }
switch (opt->option)
{
- case 'G': /* GLOBAL threads */
- thread_scope = PR_GLOBAL_THREAD;
- break;
- case 'd': /* debug mode */
- debug_mode = 1;
- break;
- case 'l': /* loop count */
- loops = atoi(opt->value);
- break;
- case 'c': /* concurrency limit */
- cpus = atoi(opt->value);
- break;
- default:
- break;
+ case 'G': /* GLOBAL threads */
+ thread_scope = PR_GLOBAL_THREAD;
+ break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ case 'l': /* loop count */
+ loops = atoi(opt->value);
+ break;
+ case 'c': /* concurrency limit */
+ cpus = atoi(opt->value);
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- if (cpus == 0) cpus = 1;
- if (loops == 0) loops = 4;
+ if (cpus == 0) {
+ cpus = 1;
+ }
+ if (loops == 0) {
+ loops = 4;
+ }
- if (debug_mode)
- printf("Alarm: Using %d loops\n", loops);
+ if (debug_mode) {
+ printf("Alarm: Using %d loops\n", loops);
+ }
- if (debug_mode)
+ if (debug_mode) {
printf("Alarm: Using %d cpu(s)\n", cpus);
+ }
for (cpu = 1; cpu <= cpus; ++cpu)
{
- if (debug_mode)
- printf("\nAlarm: Using %d CPU(s)\n", cpu);
+ if (debug_mode) {
+ printf("\nAlarm: Using %d CPU(s)\n", cpu);
+ }
- PR_SetConcurrency(cpu);
+ PR_SetConcurrency(cpu);
- /* some basic time test */
- (void)TimeThis("ConditionNotify", ConditionNotify, loops);
- (void)TimeThis("ConditionTimeout", ConditionTimeout, loops);
- (void)TimeThis("Alarms1", Alarms1, loops);
- (void)TimeThis("Alarms2", Alarms2, loops);
- (void)TimeThis("Alarms3", Alarms3, loops);
+ /* some basic time test */
+ (void)TimeThis("ConditionNotify", ConditionNotify, loops);
+ (void)TimeThis("ConditionTimeout", ConditionTimeout, loops);
+ (void)TimeThis("Alarms1", Alarms1, loops);
+ (void)TimeThis("Alarms2", Alarms2, loops);
+ (void)TimeThis("Alarms3", Alarms3, loops);
}
return 0;
}
int main(int argc, char** argv)
{
- PR_Initialize(prmain, argc, argv, 0);
- PR_STDIO_INIT();
- if (failed_already) return 1;
- else return 0;
+ PR_Initialize(prmain, argc, argv, 0);
+ PR_STDIO_INIT();
+ if (failed_already) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
} /* main */
diff --git a/pr/tests/anonfm.c b/pr/tests/anonfm.c
index 1c3468f3..529be6fa 100644
--- a/pr/tests/anonfm.c
+++ b/pr/tests/anonfm.c
@@ -73,37 +73,37 @@ static void ClientOne( void )
PRStatus rc;
PR_LOG(lm, msgLevel,
- ("ClientOne() starting"));
+ ("ClientOne() starting"));
fmString = PR_GetEnv( fmEnvName );
if ( NULL == fmString ) {
failed_already = 1;
PR_LOG(lm, msgLevel,
- ("ClientOne(): PR_Getenv() failed"));
+ ("ClientOne(): PR_Getenv() failed"));
return;
}
PR_LOG(lm, msgLevel,
- ("ClientOne(): PR_Getenv(): found: %s", fmString));
+ ("ClientOne(): PR_Getenv(): found: %s", fmString));
fm = PR_ImportFileMapFromString( fmString );
if ( NULL == fm ) {
failed_already = 1;
PR_LOG(lm, msgLevel,
- ("ClientOne(): PR_ImportFileMapFromString() failed"));
+ ("ClientOne(): PR_ImportFileMapFromString() failed"));
return;
}
PR_LOG(lm, msgLevel,
- ("ClientOne(): PR_ImportFileMapFromString(): fm: %p", fm ));
+ ("ClientOne(): PR_ImportFileMapFromString(): fm: %p", fm ));
addr = PR_MemMap( fm, LL_ZERO, fmSize );
if ( NULL == addr ) {
failed_already = 1;
PR_LOG(lm, msgLevel,
- ("ClientOne(): PR_MemMap() failed, OSError: %d", PR_GetOSError() ));
+ ("ClientOne(): PR_MemMap() failed, OSError: %d", PR_GetOSError() ));
return;
}
PR_LOG(lm, msgLevel,
- ("ClientOne(): PR_MemMap(): addr: %p", addr ));
+ ("ClientOne(): PR_MemMap(): addr: %p", addr ));
/* write to memory map to release server */
*addr = 1;
@@ -111,17 +111,17 @@ static void ClientOne( void )
rc = PR_MemUnmap( addr, fmSize );
PR_ASSERT( rc == PR_SUCCESS );
PR_LOG(lm, msgLevel,
- ("ClientOne(): PR_MemUnap(): success" ));
+ ("ClientOne(): PR_MemUnap(): success" ));
rc = PR_CloseFileMap( fm );
if ( PR_FAILURE == rc ) {
failed_already = 1;
PR_LOG(lm, msgLevel,
- ("ClientOne(): PR_MemUnap() failed, OSError: %d", PR_GetOSError() ));
+ ("ClientOne(): PR_MemUnap() failed, OSError: %d", PR_GetOSError() ));
return;
}
PR_LOG(lm, msgLevel,
- ("ClientOne(): PR_CloseFileMap(): success" ));
+ ("ClientOne(): PR_CloseFileMap(): success" ));
return;
} /* end ClientOne() */
@@ -150,23 +150,23 @@ static void ServerOne( void )
PRInt32 exit_status;
PR_LOG(lm, msgLevel,
- ("ServerOne() starting"));
+ ("ServerOne() starting"));
fm = PR_OpenAnonFileMap( dirName, fmSize, fmProt );
if ( NULL == fm ) {
failed_already = 1;
PR_LOG(lm, msgLevel,
- ("PR_OpenAnonFileMap() failed"));
+ ("PR_OpenAnonFileMap() failed"));
return;
}
PR_LOG(lm, msgLevel,
- ("ServerOne(): FileMap: %p", fm ));
+ ("ServerOne(): FileMap: %p", fm ));
rc = PR_ExportFileMapAsString( fm, sizeof(fmString), fmString );
if ( PR_FAILURE == rc ) {
failed_already = 1;
PR_LOG(lm, msgLevel,
- ("PR_ExportFileMap() failed"));
+ ("PR_ExportFileMap() failed"));
return;
}
@@ -180,16 +180,17 @@ static void ServerOne( void )
if ( NULL == addr ) {
failed_already = 1;
PR_LOG(lm, msgLevel,
- ("PR_MemMap() failed"));
+ ("PR_MemMap() failed"));
return;
}
/* set initial value for client */
- for (i = 0; i < (PRIntn)fmSize ; i++ )
+ for (i = 0; i < (PRIntn)fmSize ; i++ ) {
*(addr+i) = 0x00;
+ }
PR_LOG(lm, msgLevel,
- ("ServerOne(): PR_MemMap(): addr: %p", addr ));
+ ("ServerOne(): PR_MemMap(): addr: %p", addr ));
/*
** set arguments for child process
@@ -202,22 +203,24 @@ static void ServerOne( void )
proc = PR_CreateProcess(child_argv[0], child_argv, NULL, NULL);
PR_ASSERT( proc );
PR_LOG(lm, msgLevel,
- ("ServerOne(): PR_CreateProcess(): proc: %x", proc ));
+ ("ServerOne(): PR_CreateProcess(): proc: %x", proc ));
/*
** ClientOne() will set the memory to 1
*/
PR_LOG(lm, msgLevel,
- ("ServerOne(): waiting on Client, *addr: %x", *addr ));
+ ("ServerOne(): waiting on Client, *addr: %x", *addr ));
while( *addr == 0x00 ) {
- if ( debug )
+ if ( debug ) {
fprintf(stderr, ".");
+ }
PR_Sleep(PR_MillisecondsToInterval(300));
}
- if ( debug )
+ if ( debug ) {
fprintf(stderr, "\n");
+ }
PR_LOG(lm, msgLevel,
- ("ServerOne(): Client responded" ));
+ ("ServerOne(): Client responded" ));
rc = PR_WaitProcess( proc, &exit_status );
PR_ASSERT( PR_FAILURE != rc );
@@ -226,21 +229,21 @@ static void ServerOne( void )
if ( PR_FAILURE == rc ) {
failed_already = 1;
PR_LOG(lm, msgLevel,
- ("PR_MemUnmap() failed"));
+ ("PR_MemUnmap() failed"));
return;
}
PR_LOG(lm, msgLevel,
- ("ServerOne(): PR_MemUnmap(): success" ));
+ ("ServerOne(): PR_MemUnmap(): success" ));
rc = PR_CloseFileMap(fm);
if ( PR_FAILURE == rc ) {
failed_already = 1;
PR_LOG(lm, msgLevel,
- ("PR_CloseFileMap() failed"));
+ ("PR_CloseFileMap() failed"));
return;
}
PR_LOG(lm, msgLevel,
- ("ServerOne(): PR_CloseFileMap() success" ));
+ ("ServerOne(): PR_CloseFileMap() success" ));
return;
} /* end ServerOne() */
@@ -251,7 +254,7 @@ static void ServerOne( void )
static void ServerTwo( void )
{
PR_LOG(lm, msgLevel,
- ("ServerTwo(): Not implemented yet" ));
+ ("ServerTwo(): Not implemented yet" ));
} /* end ServerTwo() */
@@ -264,30 +267,32 @@ int main(int argc, char **argv)
PLOptStatus os;
PLOptState *opt = PL_CreateOptState(argc, argv, "hdC:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
- if (PL_OPT_BAD == os) continue;
+ if (PL_OPT_BAD == os) {
+ continue;
+ }
switch (opt->option)
{
- case 'C': /* Client style */
- client = atol(opt->value);
- break;
- case 's': /* file size */
- fmSize = atol( opt->value ) * 1024;
- break;
- case 'd': /* debug */
- debug = 1;
- msgLevel = PR_LOG_DEBUG;
- break;
- case 'h': /* help message */
- Help();
- break;
- default:
- strcpy(dirName, opt->value);
- break;
+ case 'C': /* Client style */
+ client = atol(opt->value);
+ break;
+ case 's': /* file size */
+ fmSize = atol( opt->value ) * 1024;
+ break;
+ case 'd': /* debug */
+ debug = 1;
+ msgLevel = PR_LOG_DEBUG;
+ break;
+ case 'h': /* help message */
+ Help();
+ break;
+ default:
+ strcpy(dirName, opt->value);
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
}
lm = PR_NewLogModule("Test"); /* Initialize logging */
@@ -298,13 +303,16 @@ int main(int argc, char **argv)
ClientTwo();
} else {
ServerOne();
- if ( failed_already ) goto Finished;
+ if ( failed_already ) {
+ goto Finished;
+ }
ServerTwo();
}
Finished:
- if ( debug )
+ if ( debug ) {
printf("%s\n", (failed_already)? "FAIL" : "PASS");
+ }
return( (failed_already == PR_TRUE )? 1 : 0 );
} /* main() */
/* end anonfm.c */
diff --git a/pr/tests/append.c b/pr/tests/append.c
index 53439d5f..9d688a4f 100644
--- a/pr/tests/append.c
+++ b/pr/tests/append.c
@@ -42,27 +42,31 @@ int main(int argc, char **argv)
PLOptStatus os;
PLOptState *opt = PL_CreateOptState(argc, argv, "vd");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ 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 */
- debug = 1;
- break;
- case 'v': /* verbose */
- verbose = 1;
- break;
- default:
- break;
+ case 'd': /* debug */
+ debug = 1;
+ break;
+ case 'v': /* verbose */
+ verbose = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
} /* end block "Get command line options" */
-/* ---------------------------------------------------------------------- */
+ /* ---------------------------------------------------------------------- */
fd = PR_Open( "/tmp/nsprAppend", (PR_APPEND | PR_CREATE_FILE | PR_TRUNCATE | PR_WRONLY), 0666 );
if ( NULL == fd ) {
- if (debug) printf("PR_Open() failed for writing: %d\n", PR_GetError());
+ if (debug) {
+ printf("PR_Open() failed for writing: %d\n", PR_GetError());
+ }
failedAlready = PR_TRUE;
goto Finished;
}
@@ -70,27 +74,35 @@ int main(int argc, char **argv)
for ( i = 0; i < addedBytes ; i++ ) {
rv = PR_Write( fd, &buf, sizeof(buf));
if ( sizeof(buf) != rv ) {
- if (debug) printf("PR_Write() failed: %d\n", PR_GetError());
+ if (debug) {
+ printf("PR_Write() failed: %d\n", PR_GetError());
+ }
failedAlready = PR_TRUE;
goto Finished;
}
- rv = PR_Seek( fd, 0 , PR_SEEK_SET );
+ rv = PR_Seek( fd, 0, PR_SEEK_SET );
if ( -1 == rv ) {
- if (debug) printf("PR_Seek() failed: %d\n", PR_GetError());
+ if (debug) {
+ printf("PR_Seek() failed: %d\n", PR_GetError());
+ }
failedAlready = PR_TRUE;
goto Finished;
}
}
rc = PR_Close( fd );
if ( PR_FAILURE == rc ) {
- if (debug) printf("PR_Close() failed after writing: %d\n", PR_GetError());
+ if (debug) {
+ printf("PR_Close() failed after writing: %d\n", PR_GetError());
+ }
failedAlready = PR_TRUE;
goto Finished;
}
-/* ---------------------------------------------------------------------- */
+ /* ---------------------------------------------------------------------- */
fd = PR_Open( "/tmp/nsprAppend", PR_RDONLY, 0 );
if ( NULL == fd ) {
- if (debug) printf("PR_Open() failed for reading: %d\n", PR_GetError());
+ if (debug) {
+ printf("PR_Open() failed for reading: %d\n", PR_GetError());
+ }
failedAlready = PR_TRUE;
goto Finished;
}
@@ -98,7 +110,9 @@ int main(int argc, char **argv)
for ( i = 0; i < addedBytes ; i++ ) {
rv = PR_Read( fd, &inBuf, sizeof(inBuf));
if ( sizeof(inBuf) != rv) {
- if (debug) printf("PR_Write() failed: %d\n", PR_GetError());
+ if (debug) {
+ printf("PR_Write() failed: %d\n", PR_GetError());
+ }
failedAlready = PR_TRUE;
goto Finished;
}
@@ -107,19 +121,25 @@ int main(int argc, char **argv)
rc = PR_Close( fd );
if ( PR_FAILURE == rc ) {
- if (debug) printf("PR_Close() failed after reading: %d\n", PR_GetError());
+ if (debug) {
+ printf("PR_Close() failed after reading: %d\n", PR_GetError());
+ }
failedAlready = PR_TRUE;
goto Finished;
}
if ( sum != addedBytes ) {
- if (debug) printf("Uh Oh! addedBytes: %d. Sum: %d\n", addedBytes, sum);
+ if (debug) {
+ printf("Uh Oh! addedBytes: %d. Sum: %d\n", addedBytes, sum);
+ }
failedAlready = PR_TRUE;
goto Finished;
}
-/* ---------------------------------------------------------------------- */
+ /* ---------------------------------------------------------------------- */
Finished:
- if (debug || verbose) printf("%s\n", (failedAlready)? "FAILED" : "PASSED" );
+ if (debug || verbose) {
+ printf("%s\n", (failedAlready)? "FAILED" : "PASSED" );
+ }
return( (failedAlready)? 1 : 0 );
} /* main() */
diff --git a/pr/tests/attach.c b/pr/tests/attach.c
index 5d09680f..2c1ac997 100644
--- a/pr/tests/attach.c
+++ b/pr/tests/attach.c
@@ -14,12 +14,12 @@
**
** Modification History:
** 13-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.
** 12-June-97 Revert to return code 0 and 1.
***********************************************************************/
@@ -63,16 +63,16 @@ AttachDetach(void)
PRThread *me;
PRInt32 index;
- for (index=0;index<count; index++) {
+ for (index=0; index<count; index++) {
me = PR_AttachThread(PR_USER_THREAD,
PR_PRIORITY_NORMAL,
NULL);
if (!me) {
fprintf(stderr, "Error attaching thread %d: PR_AttachThread failed\n",
- count);
- failed_already = 1;
- return;
+ count);
+ failed_already = 1;
+ return;
}
PR_DetachThread();
}
@@ -90,8 +90,9 @@ static void Measure(void (*func)(void), const char *msg)
stop = PR_IntervalNow();
d = (double)PR_IntervalToMicroseconds(stop - start);
- if (debug_mode)
- printf("%40s: %6.2f usec\n", msg, d / count);
+ if (debug_mode) {
+ printf("%40s: %6.2f usec\n", msg, d / count);
+ }
}
#ifdef WIN32
@@ -123,37 +124,41 @@ int main(int argc, char **argv)
TID threadID;
#endif
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name [-d] [-c n]
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "dc:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name [-d] [-c n]
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "dc:");
+ 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_mode = 1;
- break;
- case 'c': /* loop count */
- count = atoi(opt->value);
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ case 'c': /* loop count */
+ count = atoi(opt->value);
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
#if defined(WIN16)
printf("attach: This test is not valid for Win16\n");
goto exit_now;
#endif
- if(0 == count) count = DEFAULT_COUNT;
+ if(0 == count) {
+ count = DEFAULT_COUNT;
+ }
/*
* To force the implicit initialization of nspr20
@@ -170,82 +175,96 @@ int main(int argc, char **argv)
#ifdef _PR_PTHREADS
rv = _PT_PTHREAD_ATTR_INIT(&attr);
- if (debug_mode) PR_ASSERT(0 == rv);
- else if (0 != rv) {
- failed_already=1;
- goto exit_now;
- }
+ if (debug_mode) {
+ PR_ASSERT(0 == rv);
+ }
+ else if (0 != rv) {
+ failed_already=1;
+ goto exit_now;
+ }
rv = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
- if (debug_mode) PR_ASSERT(0 == rv);
- else if (0 != rv) {
- failed_already=1;
- goto exit_now;
- }
+ if (debug_mode) {
+ PR_ASSERT(0 == rv);
+ }
+ else if (0 != rv) {
+ failed_already=1;
+ goto exit_now;
+ }
rv = _PT_PTHREAD_CREATE(&threadID, attr, threadStartFunc, NULL);
if (rv != 0) {
- fprintf(stderr, "thread creation failed: error code %d\n", rv);
- failed_already=1;
- goto exit_now;
- }
- else {
- if (debug_mode)
- printf ("thread creation succeeded \n");
-
- }
+ fprintf(stderr, "thread creation failed: error code %d\n", rv);
+ failed_already=1;
+ goto exit_now;
+ }
+ else {
+ if (debug_mode) {
+ printf ("thread creation succeeded \n");
+ }
+
+ }
rv = _PT_PTHREAD_ATTR_DESTROY(&attr);
- if (debug_mode) PR_ASSERT(0 == rv);
- else if (0 != rv) {
- failed_already=1;
- goto exit_now;
- }
+ if (debug_mode) {
+ PR_ASSERT(0 == rv);
+ }
+ else if (0 != rv) {
+ failed_already=1;
+ goto exit_now;
+ }
rv = pthread_join(threadID, NULL);
- if (debug_mode) PR_ASSERT(0 == rv);
- else if (0 != rv) {
- failed_already=1;
- goto exit_now;
- }
+ if (debug_mode) {
+ PR_ASSERT(0 == rv);
+ }
+ else if (0 != rv) {
+ failed_already=1;
+ goto exit_now;
+ }
#elif defined(SOLARIS)
rv = thr_create(NULL, 0, threadStartFunc, NULL, 0, &threadID);
if (rv != 0) {
- if(!debug_mode) {
- failed_already=1;
- goto exit_now;
- } else
- fprintf(stderr, "thread creation failed: error code %d\n", rv);
+ if(!debug_mode) {
+ failed_already=1;
+ goto exit_now;
+ } else {
+ fprintf(stderr, "thread creation failed: error code %d\n", rv);
+ }
}
rv = thr_join(threadID, NULL, NULL);
- if (debug_mode) PR_ASSERT(0 == rv);
- else if (0 != rv)
- {
- failed_already=1;
- goto exit_now;
- }
+ if (debug_mode) {
+ PR_ASSERT(0 == rv);
+ }
+ else if (0 != rv)
+ {
+ failed_already=1;
+ goto exit_now;
+ }
#elif defined(WIN32)
hThread = (HANDLE) _beginthreadex(NULL, 0, threadStartFunc, NULL,
- STACK_SIZE_PARAM_IS_A_RESERVATION, &threadID);
+ STACK_SIZE_PARAM_IS_A_RESERVATION, &threadID);
if (hThread == 0) {
fprintf(stderr, "thread creation failed: error code %d\n",
GetLastError());
- failed_already=1;
- goto exit_now;
+ failed_already=1;
+ goto exit_now;
}
rv = WaitForSingleObject(hThread, INFINITE);
- if (debug_mode)PR_ASSERT(rv != WAIT_FAILED);
- else if (rv == WAIT_FAILED) {
- failed_already=1;
- goto exit_now;
- }
+ if (debug_mode) {
+ PR_ASSERT(rv != WAIT_FAILED);
+ }
+ else if (rv == WAIT_FAILED) {
+ failed_already=1;
+ goto exit_now;
+ }
#elif defined(OS2)
threadID = (TID) _beginthread((void *)threadStartFunc, NULL,
- 32768, NULL);
+ 32768, NULL);
if (threadID == -1) {
fprintf(stderr, "thread creation failed: error code %d\n", errno);
failed_already=1;
@@ -260,18 +279,21 @@ int main(int argc, char **argv)
}
#else
- if (!debug_mode)
- failed_already=1;
- else
- printf("The attach test does not apply to this platform because\n"
- "either this platform does not have native threads or the\n"
- "test needs to be written for this platform.\n");
- goto exit_now;
+ if (!debug_mode) {
+ failed_already=1;
+ }
+ else
+ printf("The attach test does not apply to this platform because\n"
+ "either this platform does not have native threads or the\n"
+ "test needs to be written for this platform.\n");
+ goto exit_now;
#endif
exit_now:
- if(failed_already)
- return 1;
- else
- return 0;
+ if(failed_already) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
}
diff --git a/pr/tests/bigfile.c b/pr/tests/bigfile.c
index 6780d64f..e17a767e 100644
--- a/pr/tests/bigfile.c
+++ b/pr/tests/bigfile.c
@@ -48,11 +48,16 @@ static PRStatus DeleteIfFound(const char *filename)
{
VERBOSE(v_shout, "Deleting existing file");
rv = PR_Delete(filename);
- if (PR_FAILURE == rv) VERBOSE(v_shout, "Cannot delete big file");
+ if (PR_FAILURE == rv) {
+ VERBOSE(v_shout, "Cannot delete big file");
+ }
}
- else if (PR_FILE_NOT_FOUND_ERROR != PR_GetError())
+ else if (PR_FILE_NOT_FOUND_ERROR != PR_GetError()) {
VERBOSE(v_shout, "Cannot access big file");
- else rv = PR_SUCCESS;
+ }
+ else {
+ rv = PR_SUCCESS;
+ }
return rv;
} /* DeleteIfFound */
@@ -61,19 +66,26 @@ static PRIntn Error(const char *msg, const char *filename)
PRInt32 error = PR_GetError();
if (NULL != msg)
{
- if (0 == error) PR_fprintf(output, msg);
- else PL_FPrintError(output, msg);
+ if (0 == error) {
+ PR_fprintf(output, msg);
+ }
+ else {
+ PL_FPrintError(output, msg);
+ }
}
(void)DeleteIfFound(filename);
- if (v_shout == verbose) PR_Abort();
+ if (v_shout == verbose) {
+ PR_Abort();
+ }
return 1;
} /* Error */
static void Verbose(
Verbosity level, const char *msg, const char *file, PRIntn line)
{
- if (level <= verbose)
+ if (level <= verbose) {
PR_fprintf(output, "[%s : %d]: %s\n", file, line, msg);
+ }
} /* Verbose */
static void PrintInfo(PRFileInfo64 *info, const char *filename)
@@ -119,44 +131,58 @@ int main(int argc, char **argv)
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:
- filename = opt->value;
- break;
- case 'd': /* debug mode */
- verbose = v_shout;
- break;
- case 'k': /* keep file */
- keep = PR_TRUE;
- break;
- case 'v': /* verbosity */
- if (v_shout > verbose) verbose += 1;
- break;
- case 'c': /* loop counter */
- count = atoi(opt->value);
- break;
- case 's': /* filesize */
- filesize = atoi(opt->value);
- break;
- case 'h': /* confused */
- default:
- return Usage();
+ case 0:
+ filename = opt->value;
+ break;
+ case 'd': /* debug mode */
+ verbose = v_shout;
+ break;
+ case 'k': /* keep file */
+ keep = PR_TRUE;
+ break;
+ case 'v': /* verbosity */
+ if (v_shout > verbose) {
+ verbose += 1;
+ }
+ break;
+ case 'c': /* loop counter */
+ count = atoi(opt->value);
+ break;
+ case 's': /* filesize */
+ filesize = atoi(opt->value);
+ break;
+ case 'h': /* confused */
+ default:
+ return Usage();
}
}
PL_DestroyOptState(opt);
- if (0 == count) count = DEFAULT_COUNT;
- if (0 == filesize) filesize = DEFAULT_FILESIZE;
+ if (0 == count) {
+ count = DEFAULT_COUNT;
+ }
+ if (0 == filesize) {
+ filesize = DEFAULT_FILESIZE;
+ }
if (NULL == filename)
{
#define FILE_NAME "bigfile.dat"
- if (DEFAULT_FILESIZE != filesize) return Usage();
- else filename = FILE_NAME;
+ if (DEFAULT_FILESIZE != filesize) {
+ return Usage();
+ }
+ else {
+ filename = FILE_NAME;
+ }
}
- if (PR_FAILURE == DeleteIfFound(filename)) return 1;
+ if (PR_FAILURE == DeleteIfFound(filename)) {
+ return 1;
+ }
test_result = 0;
@@ -167,33 +193,49 @@ int main(int argc, char **argv)
LL_I2L(big_fragment, BUFFER_SIZE);
LL_MUL(filesize64, filesize64, one_meg);
- for (loop = 0; loop < BUFFER_SIZE; ++loop) buffer[loop] = (char)loop;
+ for (loop = 0; loop < BUFFER_SIZE; ++loop) {
+ buffer[loop] = (char)loop;
+ }
VERBOSE(v_whisper, "Creating big file");
file = PR_Open(filename, PR_CREATE_FILE | PR_WRONLY, 0666);
- if (NULL == file) return Error("PR_Open()", filename);
+ if (NULL == file) {
+ return Error("PR_Open()", filename);
+ }
VERBOSE(v_whisper, "Testing available space in empty file");
big_answer = file->methods->available64(file);
- if (!LL_IS_ZERO(big_answer)) return Error("empty available64()", filename);
+ if (!LL_IS_ZERO(big_answer)) {
+ return Error("empty available64()", filename);
+ }
- LL_SUB(big_size, filesize64, one_meg);
+ LL_SUB(big_size, filesize64, one_meg);
VERBOSE(v_whisper, "Creating sparse big file by seeking to end");
- big_answer = file->methods->seek64(file, big_size, PR_SEEK_SET);
- if (!LL_EQ(big_answer, big_size)) return Error("seek", filename);
+ big_answer = file->methods->seek64(file, big_size, PR_SEEK_SET);
+ if (!LL_EQ(big_answer, big_size)) {
+ return Error("seek", filename);
+ }
VERBOSE(v_whisper, "Writing block at end of sparse file");
- bytes = file->methods->write(file, buffer, BUFFER_SIZE);
- if (bytes != BUFFER_SIZE) return Error("write", filename);
+ bytes = file->methods->write(file, buffer, BUFFER_SIZE);
+ if (bytes != BUFFER_SIZE) {
+ return Error("write", filename);
+ }
VERBOSE(v_whisper, "Testing available space at end of sparse file");
big_answer = file->methods->available64(file);
- if (!LL_IS_ZERO(big_answer)) return Error("eof available64()", filename);
+ if (!LL_IS_ZERO(big_answer)) {
+ return Error("eof available64()", filename);
+ }
VERBOSE(v_whisper, "Getting big info on sparse big file");
rv = file->methods->fileInfo64(file, &big_info);
- if (PR_FAILURE == rv) return Error("fileInfo64()", filename);
- if (v_shout <= verbose) PrintInfo(&big_info, filename);
+ if (PR_FAILURE == rv) {
+ return Error("fileInfo64()", filename);
+ }
+ if (v_shout <= verbose) {
+ PrintInfo(&big_info, filename);
+ }
VERBOSE(v_whisper, "Getting small info on sparse big file");
rv = file->methods->fileInfo(file, &small_info);
@@ -210,75 +252,104 @@ int main(int argc, char **argv)
VERBOSE(v_whisper, "Rewinding big file");
big_answer = file->methods->seek64(file, zero_meg, PR_SEEK_SET);
- if (!LL_IS_ZERO(big_answer)) return Error("rewind seek64()", filename);
+ if (!LL_IS_ZERO(big_answer)) {
+ return Error("rewind seek64()", filename);
+ }
VERBOSE(v_whisper, "Establishing available space in rewound file");
big_answer = file->methods->available64(file);
- if (LL_NE(filesize64, big_answer))
+ if (LL_NE(filesize64, big_answer)) {
return Error("bof available64()", filename);
+ }
VERBOSE(v_whisper, "Closing big file");
rv = file->methods->close(file);
- if (PR_FAILURE == rv) return Error("close()", filename);
+ if (PR_FAILURE == rv) {
+ return Error("close()", filename);
+ }
VERBOSE(v_whisper, "Reopening big file");
file = PR_Open(filename, PR_RDWR, 0666);
- if (NULL == file) return Error("open failed", filename);
+ if (NULL == file) {
+ return Error("open failed", filename);
+ }
VERBOSE(v_whisper, "Checking available data in reopened file");
big_answer = file->methods->available64(file);
- if (LL_NE(filesize64, big_answer))
+ if (LL_NE(filesize64, big_answer)) {
return Error("reopened available64()", filename);
+ }
big_answer = zero_meg;
VERBOSE(v_whisper, "Rewriting every byte of big file data");
do
{
bytes = file->methods->write(file, buffer, BUFFER_SIZE);
- if (bytes != BUFFER_SIZE)
+ if (bytes != BUFFER_SIZE) {
return Error("write", filename);
+ }
LL_ADD(big_answer, big_answer, big_fragment);
} while (LL_CMP(big_answer, <, filesize64));
VERBOSE(v_whisper, "Checking position at eof");
big_answer = file->methods->seek64(file, zero_meg, PR_SEEK_CUR);
- if (LL_NE(big_answer, filesize64))
+ if (LL_NE(big_answer, filesize64)) {
return Error("file size error", filename);
+ }
VERBOSE(v_whisper, "Testing available space at eof");
big_answer = file->methods->available64(file);
- if (!LL_IS_ZERO(big_answer))
+ if (!LL_IS_ZERO(big_answer)) {
return Error("eof available64()", filename);
+ }
VERBOSE(v_whisper, "Rewinding full file");
big_answer = file->methods->seek64(file, zero_meg, PR_SEEK_SET);
- if (!LL_IS_ZERO(big_answer)) return Error("bof seek64()", filename);
+ if (!LL_IS_ZERO(big_answer)) {
+ return Error("bof seek64()", filename);
+ }
VERBOSE(v_whisper, "Testing available space in rewound file");
big_answer = file->methods->available64(file);
- if (LL_NE(big_answer, filesize64)) return Error("bof available64()", filename);
+ if (LL_NE(big_answer, filesize64)) {
+ return Error("bof available64()", filename);
+ }
VERBOSE(v_whisper, "Seeking to end of big file");
big_answer = file->methods->seek64(file, filesize64, PR_SEEK_SET);
- if (LL_NE(big_answer, filesize64)) return Error("eof seek64()", filename);
+ if (LL_NE(big_answer, filesize64)) {
+ return Error("eof seek64()", filename);
+ }
VERBOSE(v_whisper, "Getting info on big file while it's open");
rv = file->methods->fileInfo64(file, &big_info);
- if (PR_FAILURE == rv) return Error("fileInfo64()", filename);
- if (v_shout <= verbose) PrintInfo(&big_info, filename);
+ if (PR_FAILURE == rv) {
+ return Error("fileInfo64()", filename);
+ }
+ if (v_shout <= verbose) {
+ PrintInfo(&big_info, filename);
+ }
VERBOSE(v_whisper, "Closing big file");
rv = file->methods->close(file);
- if (PR_FAILURE == rv) return Error("close()", filename);
+ if (PR_FAILURE == rv) {
+ return Error("close()", filename);
+ }
VERBOSE(v_whisper, "Getting info on big file after it's closed");
rv = PR_GetFileInfo64(filename, &big_info);
- if (PR_FAILURE == rv) return Error("fileInfo64()", filename);
- if (v_shout <= verbose) PrintInfo(&big_info, filename);
+ if (PR_FAILURE == rv) {
+ return Error("fileInfo64()", filename);
+ }
+ if (v_shout <= verbose) {
+ PrintInfo(&big_info, filename);
+ }
VERBOSE(v_whisper, "Deleting big file");
rv = PR_Delete(filename);
- if (PR_FAILURE == rv) return Error("PR_Delete()", filename);
+ if (PR_FAILURE == rv) {
+ return Error("PR_Delete()", filename);
+ }
PR_DELETE(buffer);
return test_result;
diff --git a/pr/tests/bigfile2.c b/pr/tests/bigfile2.c
index a41841c5..1a7d45b0 100644
--- a/pr/tests/bigfile2.c
+++ b/pr/tests/bigfile2.c
@@ -37,7 +37,7 @@ int main(int argc, char **argv)
LL_SHL(offset, offset, 32);
fd = PR_Open(TEST_FILE_NAME,
- PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0666);
+ PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0666);
if (fd == NULL) {
fprintf(stderr, "PR_Open failed\n");
exit(1);
@@ -63,7 +63,7 @@ int main(int argc, char **argv)
#ifdef _WIN32
hFile = CreateFile(TEST_FILE_NAME_FOR_CREATEFILE, GENERIC_READ, 0, NULL,
- OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE) {
fprintf(stderr, "CreateFile failed\n");
exit(1);
diff --git a/pr/tests/bigfile3.c b/pr/tests/bigfile3.c
index 6afbfc93..aeb4d65e 100644
--- a/pr/tests/bigfile3.c
+++ b/pr/tests/bigfile3.c
@@ -38,7 +38,7 @@ int main(int argc, char **argv)
#ifdef _WIN32
hFile = CreateFile(TEST_FILE_NAME_FOR_CREATEFILE, GENERIC_WRITE, 0, NULL,
- CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+ CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE) {
fprintf(stderr, "CreateFile failed\n");
exit(1);
diff --git a/pr/tests/bug1test.c b/pr/tests/bug1test.c
index f26c0b89..62ca90d4 100644
--- a/pr/tests/bug1test.c
+++ b/pr/tests/bug1test.c
@@ -17,7 +17,7 @@ before leaving the critical section in _PR_CondWait in hwmon.c).
typedef struct Arg_s
{
- PRInt32 a, b;
+ PRInt32 a, b;
} Arg_t;
PRMonitor* gMonitor; // the monitor
@@ -27,7 +27,7 @@ PRInt32 gReadWaiting; // number of threads waiting for read lock
PRInt32 gCounter; // a counter
- // stats
+// stats
PRInt32 gReads; // number of successful reads
PRInt32 gMaxReads; // max number of simultaneous reads
PRInt32 gMaxWriteWaits; // max number of writes that waited for read
@@ -36,189 +36,194 @@ PRInt32 gMaxReadWaits; // max number of reads that waited for write wait
void spin (PRInt32 aDelay)
{
- PRInt32 index;
- PRInt32 delay = aDelay * 1000;
+ PRInt32 index;
+ PRInt32 delay = aDelay * 1000;
- PR_Sleep(0);
+ PR_Sleep(0);
- // randomize delay a bit
- delay = (delay / 2) + (PRInt32)((float)delay *
- ((float)rand () / (float)RAND_MAX));
+ // randomize delay a bit
+ delay = (delay / 2) + (PRInt32)((float)delay *
+ ((float)rand () / (float)RAND_MAX));
- for (index = 0; index < delay * 10; index++)
- // consume a bunch of cpu cycles
- ;
- PR_Sleep(0);
+ for (index = 0; index < delay * 10; index++)
+ // consume a bunch of cpu cycles
+ ;
+ PR_Sleep(0);
}
void doWriteThread (void* arg)
{
- PRInt32 last;
- Arg_t *args = (Arg_t*)arg;
- PRInt32 aWorkDelay = args->a, aWaitDelay = args->b;
- PR_Sleep(0);
+ PRInt32 last;
+ Arg_t *args = (Arg_t*)arg;
+ PRInt32 aWorkDelay = args->a, aWaitDelay = args->b;
+ PR_Sleep(0);
- while (1)
- {
- // -- enter write lock
- PR_EnterMonitor (gMonitor);
-
- if (0 < gReading) // wait for read locks to go away
+ while (1)
{
- PRIntervalTime fiveSecs = PR_SecondsToInterval(5);
-
- gWriteWaiting++;
- if (gWriteWaiting > gMaxWriteWaits) // stats
- gMaxWriteWaits = gWriteWaiting;
- while (0 < gReading)
- PR_Wait (gMonitor, fiveSecs);
- gWriteWaiting--;
- }
- // -- write lock entered
+ // -- enter write lock
+ PR_EnterMonitor (gMonitor);
+
+ if (0 < gReading) // wait for read locks to go away
+ {
+ PRIntervalTime fiveSecs = PR_SecondsToInterval(5);
- last = gCounter;
- gCounter++;
+ gWriteWaiting++;
+ if (gWriteWaiting > gMaxWriteWaits) { // stats
+ gMaxWriteWaits = gWriteWaiting;
+ }
+ while (0 < gReading) {
+ PR_Wait (gMonitor, fiveSecs);
+ }
+ gWriteWaiting--;
+ }
+ // -- write lock entered
- spin (aWorkDelay);
+ last = gCounter;
+ gCounter++;
- PR_ASSERT (gCounter == (last + 1)); // test invariance
+ spin (aWorkDelay);
- // -- exit write lock
+ PR_ASSERT (gCounter == (last + 1)); // test invariance
+
+ // -- exit write lock
// if (0 < gReadWaiting) // notify waiting reads (do it anyway to show off the CondWait bug)
- PR_NotifyAll (gMonitor);
+ PR_NotifyAll (gMonitor);
- PR_ExitMonitor (gMonitor);
- // -- write lock exited
+ PR_ExitMonitor (gMonitor);
+ // -- write lock exited
- spin (aWaitDelay);
- }
+ spin (aWaitDelay);
+ }
}
void doReadThread (void* arg)
{
- PRInt32 last;
- Arg_t *args = (Arg_t*)arg;
- PRInt32 aWorkDelay = args->a, aWaitDelay = args->b;
- PR_Sleep(0);
-
- while (1)
- {
- // -- enter read lock
- PR_EnterMonitor (gMonitor);
+ PRInt32 last;
+ Arg_t *args = (Arg_t*)arg;
+ PRInt32 aWorkDelay = args->a, aWaitDelay = args->b;
+ PR_Sleep(0);
- if (0 < gWriteWaiting) // give up the monitor to waiting writes
+ while (1)
{
- PRIntervalTime fiveSecs = PR_SecondsToInterval(5);
-
- gReadWaiting++;
- if (gReadWaiting > gMaxReadWaits) // stats
- gMaxReadWaits = gReadWaiting;
- while (0 < gWriteWaiting)
- PR_Wait (gMonitor, fiveSecs);
- gReadWaiting--;
- }
+ // -- enter read lock
+ PR_EnterMonitor (gMonitor);
+
+ if (0 < gWriteWaiting) // give up the monitor to waiting writes
+ {
+ PRIntervalTime fiveSecs = PR_SecondsToInterval(5);
+
+ gReadWaiting++;
+ if (gReadWaiting > gMaxReadWaits) { // stats
+ gMaxReadWaits = gReadWaiting;
+ }
+ while (0 < gWriteWaiting) {
+ PR_Wait (gMonitor, fiveSecs);
+ }
+ gReadWaiting--;
+ }
- gReading++;
+ gReading++;
- gReads++; // stats
- if (gReading > gMaxReads) // stats
- gMaxReads = gReading;
+ gReads++; // stats
+ if (gReading > gMaxReads) { // stats
+ gMaxReads = gReading;
+ }
- PR_ExitMonitor (gMonitor);
- // -- read lock entered
+ PR_ExitMonitor (gMonitor);
+ // -- read lock entered
- last = gCounter;
+ last = gCounter;
- spin (aWorkDelay);
+ spin (aWorkDelay);
- PR_ASSERT (gCounter == last); // test invariance
+ PR_ASSERT (gCounter == last); // test invariance
- // -- exit read lock
- PR_EnterMonitor (gMonitor); // read unlock
- gReading--;
+ // -- exit read lock
+ PR_EnterMonitor (gMonitor); // read unlock
+ gReading--;
// if ((0 == gReading) && (0 < gWriteWaiting)) // notify waiting writes (do it anyway to show off the CondWait bug)
- PR_NotifyAll (gMonitor);
- PR_ExitMonitor (gMonitor);
- // -- read lock exited
+ PR_NotifyAll (gMonitor);
+ PR_ExitMonitor (gMonitor);
+ // -- read lock exited
- spin (aWaitDelay);
- }
+ spin (aWaitDelay);
+ }
}
void fireThread (
char* aName, void (*aProc)(void *arg), Arg_t *aArg)
{
- PRThread *thread = PR_CreateThread(
- PR_USER_THREAD, aProc, aArg, PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD, PR_UNJOINABLE_THREAD, 0);
+ PRThread *thread = PR_CreateThread(
+ PR_USER_THREAD, aProc, aArg, PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD, PR_UNJOINABLE_THREAD, 0);
}
int pseudoMain (int argc, char** argv, char *pad)
{
- PRInt32 lastWriteCount = gCounter;
- PRInt32 lastReadCount = gReads;
- Arg_t a1 = {500, 250};
- Arg_t a2 = {500, 500};
- Arg_t a3 = {250, 500};
- Arg_t a4 = {750, 250};
- Arg_t a5 = {100, 750};
- Arg_t a6 = {100, 500};
- Arg_t a7 = {100, 750};
-
- gMonitor = PR_NewMonitor ();
-
- fireThread ("R1", doReadThread, &a1);
- fireThread ("R2", doReadThread, &a2);
- fireThread ("R3", doReadThread, &a3);
- fireThread ("R4", doReadThread, &a4);
-
- fireThread ("W1", doWriteThread, &a5);
- fireThread ("W2", doWriteThread, &a6);
- fireThread ("W3", doWriteThread, &a7);
-
- fireThread ("R5", doReadThread, &a1);
- fireThread ("R6", doReadThread, &a2);
- fireThread ("R7", doReadThread, &a3);
- fireThread ("R8", doReadThread, &a4);
-
- fireThread ("W4", doWriteThread, &a5);
- fireThread ("W5", doWriteThread, &a6);
- fireThread ("W6", doWriteThread, &a7);
-
- while (1)
- {
- PRInt32 writeCount, readCount;
- PRIntervalTime fiveSecs = PR_SecondsToInterval(5);
- PR_Sleep (fiveSecs); // get out of the way
-
- // print some stats, not threadsafe, informative only
- writeCount = gCounter;
- readCount = gReads;
- printf ("\ntick %d writes (+%d), %d reads (+%d) [max %d, %d, %d]",
- writeCount, writeCount - lastWriteCount,
- readCount, readCount - lastReadCount,
- gMaxReads, gMaxWriteWaits, gMaxReadWaits);
- lastWriteCount = writeCount;
- lastReadCount = readCount;
- gMaxReads = gMaxWriteWaits = gMaxReadWaits = 0;
- }
- return 0;
+ PRInt32 lastWriteCount = gCounter;
+ PRInt32 lastReadCount = gReads;
+ Arg_t a1 = {500, 250};
+ Arg_t a2 = {500, 500};
+ Arg_t a3 = {250, 500};
+ Arg_t a4 = {750, 250};
+ Arg_t a5 = {100, 750};
+ Arg_t a6 = {100, 500};
+ Arg_t a7 = {100, 750};
+
+ gMonitor = PR_NewMonitor ();
+
+ fireThread ("R1", doReadThread, &a1);
+ fireThread ("R2", doReadThread, &a2);
+ fireThread ("R3", doReadThread, &a3);
+ fireThread ("R4", doReadThread, &a4);
+
+ fireThread ("W1", doWriteThread, &a5);
+ fireThread ("W2", doWriteThread, &a6);
+ fireThread ("W3", doWriteThread, &a7);
+
+ fireThread ("R5", doReadThread, &a1);
+ fireThread ("R6", doReadThread, &a2);
+ fireThread ("R7", doReadThread, &a3);
+ fireThread ("R8", doReadThread, &a4);
+
+ fireThread ("W4", doWriteThread, &a5);
+ fireThread ("W5", doWriteThread, &a6);
+ fireThread ("W6", doWriteThread, &a7);
+
+ while (1)
+ {
+ PRInt32 writeCount, readCount;
+ PRIntervalTime fiveSecs = PR_SecondsToInterval(5);
+ PR_Sleep (fiveSecs); // get out of the way
+
+ // print some stats, not threadsafe, informative only
+ writeCount = gCounter;
+ readCount = gReads;
+ printf ("\ntick %d writes (+%d), %d reads (+%d) [max %d, %d, %d]",
+ writeCount, writeCount - lastWriteCount,
+ readCount, readCount - lastReadCount,
+ gMaxReads, gMaxWriteWaits, gMaxReadWaits);
+ lastWriteCount = writeCount;
+ lastReadCount = readCount;
+ gMaxReads = gMaxWriteWaits = gMaxReadWaits = 0;
+ }
+ return 0;
}
static void padStack (int argc, char** argv)
{
- char pad[512]; /* Work around bug in nspr on windoze */
- pseudoMain (argc, argv, pad);
+ char pad[512]; /* Work around bug in nspr on windoze */
+ pseudoMain (argc, argv, pad);
}
int main(int argc, char **argv)
{
- PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
- PR_STDIO_INIT();
- padStack (argc, argv);
+ PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
+ PR_STDIO_INIT();
+ padStack (argc, argv);
}
diff --git a/pr/tests/cleanup.c b/pr/tests/cleanup.c
index d5803a52..679fe59c 100644
--- a/pr/tests/cleanup.c
+++ b/pr/tests/cleanup.c
@@ -36,7 +36,7 @@ int main(int argc, char **argv)
{
PLOptStatus os;
PRBool cleanup = PR_FALSE;
- PRThreadScope type = PR_LOCAL_THREAD;
+ PRThreadScope type = PR_LOCAL_THREAD;
PRFileDesc *err = PR_GetSpecialFD(PR_StandardError);
PLOptState *opt = PL_CreateOptState(argc, argv, "Ghs:S:t:cC:");
PRIntn concurrency = 1, child_sleep = 10, main_sleep = 5, threads = 1;
@@ -44,40 +44,42 @@ int main(int argc, char **argv)
PR_STDIO_INIT();
while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
- if (PL_OPT_BAD == os) continue;
+ if (PL_OPT_BAD == os) {
+ continue;
+ }
switch (opt->option)
{
- case 'c': /* call PR_Cleanup() before exiting */
- cleanup = PR_TRUE;
- break;
- case 'G': /* local vs global threads */
- type = PR_GLOBAL_THREAD;
- break;
- case 's': /* time to sleep */
- child_sleep = atoi(opt->value);
- break;
- case 'S': /* time to sleep */
- main_sleep = atoi(opt->value);
- break;
- case 'C': /* number of cpus to create */
- concurrency = atoi(opt->value);
- break;
- case 't': /* number of threads to create */
- threads = atoi(opt->value);
- break;
- case 'h': /* user wants some guidance */
- Help(); /* so give him an earful */
- return 2; /* but not a lot else */
- break;
- default:
- break;
+ case 'c': /* call PR_Cleanup() before exiting */
+ cleanup = PR_TRUE;
+ break;
+ case 'G': /* local vs global threads */
+ type = PR_GLOBAL_THREAD;
+ break;
+ case 's': /* time to sleep */
+ child_sleep = atoi(opt->value);
+ break;
+ case 'S': /* time to sleep */
+ main_sleep = atoi(opt->value);
+ break;
+ case 'C': /* number of cpus to create */
+ concurrency = atoi(opt->value);
+ break;
+ case 't': /* number of threads to create */
+ threads = atoi(opt->value);
+ break;
+ case 'h': /* user wants some guidance */
+ Help(); /* so give him an earful */
+ return 2; /* but not a lot else */
+ break;
+ default:
+ break;
}
}
PL_DestroyOptState(opt);
PR_fprintf(err, "Cleanup settings\n");
PR_fprintf(err, "\tThread type: %s\n",
- (PR_LOCAL_THREAD == type) ? "LOCAL" : "GLOBAL");
+ (PR_LOCAL_THREAD == type) ? "LOCAL" : "GLOBAL");
PR_fprintf(err, "\tConcurrency: %d\n", concurrency);
PR_fprintf(err, "\tNumber of threads: %d\n", threads);
PR_fprintf(err, "\tThread sleep: %d\n", child_sleep);
@@ -86,13 +88,15 @@ int main(int argc, char **argv)
PR_SetConcurrency(concurrency);
- while (threads-- > 0)
- (void)PR_CreateThread(
- PR_USER_THREAD, Thread, (void*)child_sleep, PR_PRIORITY_NORMAL,
- type, PR_UNJOINABLE_THREAD, 0);
+ while (threads-- > 0)
+ (void)PR_CreateThread(
+ PR_USER_THREAD, Thread, (void*)child_sleep, PR_PRIORITY_NORMAL,
+ type, PR_UNJOINABLE_THREAD, 0);
PR_Sleep(PR_SecondsToInterval(main_sleep));
- if (cleanup) PR_Cleanup();
+ if (cleanup) {
+ PR_Cleanup();
+ }
PR_fprintf(err, "main() exiting\n");
return 0;
diff --git a/pr/tests/cltsrv.c b/pr/tests/cltsrv.c
index 17ca7caa..caf1ad4d 100644
--- a/pr/tests/cltsrv.c
+++ b/pr/tests/cltsrv.c
@@ -182,7 +182,7 @@ static void _MY_Assert(const char *s, const char *file, PRIntn ln)
static PRBool Aborted(PRStatus rv)
{
return ((PR_FAILURE == rv) && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) ?
- PR_TRUE : PR_FALSE;
+ PR_TRUE : PR_FALSE;
}
static void TimeOfDayMessage(const char *msg, PRThread* me)
@@ -211,8 +211,9 @@ static void PR_CALLBACK Client(void *arg)
PRIntervalTime timeout = PR_MillisecondsToInterval(DEFAULT_CLIENT_TIMEOUT);
- for (index = 0; index < sizeof(buffer); ++index)
+ for (index = 0; index < sizeof(buffer); ++index) {
buffer[index] = (char)index;
+ }
client->started = PR_IntervalNow();
@@ -229,7 +230,7 @@ static void PR_CALLBACK Client(void *arg)
(void)PR_NetAddrToString(&client->serverAddress, buffer, sizeof(buffer));
TEST_LOG(cltsrv_log_file, TEST_LOG_INFO,
- ("\tClient(0x%p): connecting to server at %s\n", me, buffer));
+ ("\tClient(0x%p): connecting to server at %s\n", me, buffer));
fd = PR_Socket(domain, SOCK_STREAM, protocol);
TEST_ASSERT(NULL != fd);
@@ -239,7 +240,7 @@ static void PR_CALLBACK Client(void *arg)
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
("\tClient(0x%p): conection failed (%d, %d)\n",
- me, PR_GetError(), PR_GetOSError()));
+ me, PR_GetError(), PR_GetOSError()));
goto aborted;
}
@@ -252,10 +253,12 @@ static void PR_CALLBACK Client(void *arg)
cltsrv_log_file, TEST_LOG_VERBOSE,
("\tClient(0x%p): sending descriptor for %u bytes\n", me, descbytes));
bytes = PR_Send(
- fd, descriptor, sizeof(*descriptor), SEND_FLAGS, timeout);
+ fd, descriptor, sizeof(*descriptor), SEND_FLAGS, timeout);
if (sizeof(CSDescriptor_t) != bytes)
{
- if (Aborted(PR_FAILURE)) goto aborted;
+ if (Aborted(PR_FAILURE)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -270,15 +273,18 @@ static void PR_CALLBACK Client(void *arg)
while (netbytes < descbytes)
{
filebytes = sizeof(buffer);
- if ((descbytes - netbytes) < filebytes)
+ if ((descbytes - netbytes) < filebytes) {
filebytes = descbytes - netbytes;
+ }
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("\tClient(0x%p): sending %d bytes\n", me, filebytes));
bytes = PR_Send(fd, buffer, filebytes, SEND_FLAGS, timeout);
if (filebytes != bytes)
{
- if (Aborted(PR_FAILURE)) goto aborted;
+ if (Aborted(PR_FAILURE)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -294,8 +300,9 @@ static void PR_CALLBACK Client(void *arg)
while (filebytes < descbytes)
{
netbytes = sizeof(buffer);
- if ((descbytes - filebytes) < netbytes)
+ if ((descbytes - filebytes) < netbytes) {
netbytes = descbytes - filebytes;
+ }
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("\tClient(0x%p): receiving %d bytes\n", me, netbytes));
@@ -313,26 +320,28 @@ static void PR_CALLBACK Client(void *arg)
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
("\tClient(0x%p): receive data timeout\n", me));
- else
+ else
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
("\tClient(0x%p): receive error (%d, %d)\n",
- me, PR_GetError(), PR_GetOSError()));
+ me, PR_GetError(), PR_GetOSError()));
goto retry;
- }
+ }
if (0 == bytes)
{
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
("\t\tClient(0x%p): unexpected end of stream\n",
- PR_GetCurrentThread()));
+ PR_GetCurrentThread()));
break;
}
filebytes += bytes;
}
rv = PR_Shutdown(fd, PR_SHUTDOWN_BOTH);
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
TEST_ASSERT(PR_SUCCESS == rv);
retry:
(void)PR_Close(fd); fd = NULL;
@@ -345,14 +354,18 @@ retry:
client->bytesTransferred += 2 * descbytes;
rv = PR_WaitCondVar(client->stateChange, rand() % clipping);
PR_Unlock(client->ml);
- if (Aborted(rv)) break;
+ if (Aborted(rv)) {
+ break;
+ }
}
aborted:
client->stopped = PR_IntervalNow();
PR_ClearInterrupt();
- if (NULL != fd) rv = PR_Close(fd);
+ if (NULL != fd) {
+ rv = PR_Close(fd);
+ }
PR_Lock(client->ml);
client->state = cs_exit;
@@ -362,7 +375,7 @@ aborted:
TEST_LOG(
cltsrv_log_file, TEST_LOG_ALWAYS,
("\tClient(0x%p): stopped after %u operations and %u bytes\n",
- PR_GetCurrentThread(), client->operations, client->bytesTransferred));
+ PR_GetCurrentThread(), client->operations, client->bytesTransferred));
} /* Client */
@@ -380,11 +393,13 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
cltsrv_log_file, TEST_LOG_VERBOSE,
("\tProcessRequest(0x%p): receiving desciptor\n", me));
bytes = PR_Recv(
- fd, descriptor, sizeof(*descriptor), RECV_FLAGS, timeout);
+ fd, descriptor, sizeof(*descriptor), RECV_FLAGS, timeout);
if (-1 == bytes)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto exit;
+ if (Aborted(rv)) {
+ goto exit;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -407,14 +422,16 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("\t\tProcessRequest(0x%p): read descriptor {%d, %s}\n",
- me, descbytes, descriptor->filename));
+ me, descbytes, descriptor->filename));
file = PR_Open(
- descriptor->filename, (PR_CREATE_FILE | PR_WRONLY), 0666);
+ descriptor->filename, (PR_CREATE_FILE | PR_WRONLY), 0666);
if (NULL == file)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -429,8 +446,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
while (filebytes < descbytes)
{
netbytes = sizeof(buffer);
- if ((descbytes - filebytes) < netbytes)
+ if ((descbytes - filebytes) < netbytes) {
netbytes = descbytes - filebytes;
+ }
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("\tProcessRequest(0x%p): receive %d bytes\n", me, netbytes));
@@ -438,7 +456,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
if (-1 == bytes)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -454,7 +474,7 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
TEST_LOG(
cltsrv_log_file, TEST_LOG_WARNING,
("\t\tProcessRequest(0x%p): unexpected error (%d, %d)\n",
- me, PR_GetError(), PR_GetOSError()));
+ me, PR_GetError(), PR_GetOSError()));
goto aborted;
}
if(0 == bytes)
@@ -476,7 +496,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
if (netbytes != bytes)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -494,7 +516,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
PR_Unlock(server->ml);
rv = PR_Close(file);
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
TEST_ASSERT(PR_SUCCESS == rv);
file = NULL;
@@ -505,19 +529,21 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
if (NULL == file)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
("\t\tProcessRequest(0x%p): open file timeout\n",
- PR_GetCurrentThread()));
+ PR_GetCurrentThread()));
goto aborted;
}
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
("\t\tProcessRequest(0x%p): other file open error (%u, %u)\n",
- me, PR_GetError(), PR_GetOSError()));
+ me, PR_GetError(), PR_GetOSError()));
goto aborted;
}
TEST_ASSERT(NULL != file);
@@ -526,8 +552,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
while (netbytes < descbytes)
{
filebytes = sizeof(buffer);
- if ((descbytes - netbytes) < filebytes)
+ if ((descbytes - netbytes) < filebytes) {
filebytes = descbytes - netbytes;
+ }
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("\tProcessRequest(0x%p): read %d bytes from file\n", me, filebytes));
@@ -535,7 +562,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
if (filebytes != bytes)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
@@ -544,7 +573,7 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
("\t\tProcessRequest(0x%p): other file error (%d, %d)\n",
- me, PR_GetError(), PR_GetOSError()));
+ me, PR_GetError(), PR_GetOSError()));
goto aborted;
}
TEST_ASSERT(bytes > 0);
@@ -557,7 +586,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
if (filebytes != bytes)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -567,7 +598,7 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
}
break;
}
- TEST_ASSERT(bytes > 0);
+ TEST_ASSERT(bytes > 0);
}
PR_Lock(server->ml);
@@ -575,16 +606,22 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
PR_Unlock(server->ml);
rv = PR_Shutdown(fd, PR_SHUTDOWN_BOTH);
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
rv = PR_Close(file);
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
TEST_ASSERT(PR_SUCCESS == rv);
file = NULL;
aborted:
PR_ClearInterrupt();
- if (NULL != file) PR_Close(file);
+ if (NULL != file) {
+ PR_Close(file);
+ }
drv = PR_Delete(descriptor->filename);
TEST_ASSERT(PR_SUCCESS == drv);
exit:
@@ -606,9 +643,9 @@ static PRStatus CreateWorker(CSServer_t *server, CSPool_t *pool)
worker->server = server;
PR_INIT_CLIST(&worker->element);
worker->thread = PR_CreateThread(
- PR_USER_THREAD, Worker, worker,
- DEFAULT_SERVER_PRIORITY, thread_scope,
- PR_UNJOINABLE_THREAD, 0);
+ PR_USER_THREAD, Worker, worker,
+ DEFAULT_SERVER_PRIORITY, thread_scope,
+ PR_UNJOINABLE_THREAD, 0);
if (NULL == worker->thread)
{
PR_DELETE(worker);
@@ -616,8 +653,8 @@ static PRStatus CreateWorker(CSServer_t *server, CSPool_t *pool)
}
TEST_LOG(cltsrv_log_file, TEST_LOG_STATUS,
- ("\tCreateWorker(0x%p): create new worker (0x%p)\n",
- PR_GetCurrentThread(), worker->thread));
+ ("\tCreateWorker(0x%p): create new worker (0x%p)\n",
+ PR_GetCurrentThread(), worker->thread));
return PR_SUCCESS;
} /* CreateWorker */
@@ -647,14 +684,14 @@ static void PR_CALLBACK Worker(void *arg)
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("\t\tWorker(0x%p): waiting for accept slot[%d]\n",
- me, pool->accepting));
+ me, pool->accepting));
rv = PR_WaitCondVar(pool->acceptComplete, PR_INTERVAL_NO_TIMEOUT);
if (Aborted(rv) || (cs_run != server->state))
{
TEST_LOG(
cltsrv_log_file, TEST_LOG_NOTICE,
("\tWorker(0x%p): has been %s\n",
- me, (Aborted(rv) ? "interrupted" : "stopped")));
+ me, (Aborted(rv) ? "interrupted" : "stopped")));
goto exit;
}
}
@@ -692,13 +729,15 @@ static void PR_CALLBACK Worker(void *arg)
*/
PRBool another =
((pool->workers < server->workers.minimum) ||
- ((0 == pool->accepting)
- && (pool->workers < server->workers.maximum))) ?
- PR_TRUE : PR_FALSE;
+ ((0 == pool->accepting)
+ && (pool->workers < server->workers.maximum))) ?
+ PR_TRUE : PR_FALSE;
pool->active += 1;
PR_Unlock(server->ml);
- if (another) (void)CreateWorker(server, pool);
+ if (another) {
+ (void)CreateWorker(server, pool);
+ }
rv = ProcessRequest(fd, server);
if (PR_SUCCESS != rv)
@@ -752,11 +791,12 @@ static void PR_CALLBACK Server(void *arg)
TEST_ASSERT(PR_SUCCESS == rv);
memset(&serverAddress, 0, sizeof(serverAddress));
- if (PR_AF_INET6 != domain)
- rv = PR_InitializeNetAddr(PR_IpAddrAny, DEFAULT_PORT, &serverAddress);
- else
- rv = PR_SetNetAddr(PR_IpAddrAny, PR_AF_INET6, DEFAULT_PORT,
- &serverAddress);
+ if (PR_AF_INET6 != domain) {
+ rv = PR_InitializeNetAddr(PR_IpAddrAny, DEFAULT_PORT, &serverAddress);
+ }
+ else
+ rv = PR_SetNetAddr(PR_IpAddrAny, PR_AF_INET6, DEFAULT_PORT,
+ &serverAddress);
rv = PR_Bind(server->listener, &serverAddress);
TEST_ASSERT(PR_SUCCESS == rv);
@@ -827,7 +867,7 @@ static void PR_CALLBACK Server(void *arg)
TEST_LOG(
cltsrv_log_file, TEST_LOG_NOTICE,
("\tServer(0x%p): waiting for %u workers to exit\n",
- me, server->pool.workers));
+ me, server->pool.workers));
(void)PR_WaitCondVar(server->pool.exiting, PR_INTERVAL_NO_TIMEOUT);
}
@@ -838,9 +878,11 @@ static void PR_CALLBACK Server(void *arg)
TEST_LOG(
cltsrv_log_file, TEST_LOG_ALWAYS,
("\tServer(0x%p): stopped after %u operations and %u bytes\n",
- me, server->operations, server->bytesTransferred));
+ me, server->operations, server->bytesTransferred));
- if (NULL != server->listener) PR_Close(server->listener);
+ if (NULL != server->listener) {
+ PR_Close(server->listener);
+ }
server->stopped = PR_IntervalNow();
} /* Server */
@@ -851,7 +893,9 @@ static void WaitForCompletion(PRIntn execution)
{
PRIntn dally = (execution > 30) ? 30 : execution;
PR_Sleep(PR_SecondsToInterval(dally));
- if (pthread_stats) PT_FPrintStats(debug_out, "\nPThread Statistics\n");
+ if (pthread_stats) {
+ PT_FPrintStats(debug_out, "\nPThread Statistics\n");
+ }
execution -= dally;
}
} /* WaitForCompletion */
@@ -922,70 +966,86 @@ int main(int argc, char** argv)
while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
- if (PL_OPT_BAD == os) continue;
+ if (PL_OPT_BAD == os) {
+ continue;
+ }
switch (opt->option)
{
- case 'G': /* use global threads */
- thread_scope = PR_GLOBAL_THREAD;
- break;
- case 'X': /* use XTP as transport */
- protocol = 36;
- break;
- case '6': /* Use IPv6 */
- domain = PR_AF_INET6;
- break;
- case 'a': /* the value for accepting */
- accepting = atoi(opt->value);
- break;
- case 'b': /* the value for backlock */
- backlog = atoi(opt->value);
- break;
- case 'c': /* number of client threads */
- clients = atoi(opt->value);
- break;
- case 'f': /* low water fd cache */
- low = atoi(opt->value);
- break;
- case 'F': /* low water fd cache */
- high = atoi(opt->value);
- break;
- case 'w': /* minimum server worker threads */
- workersMin = atoi(opt->value);
- break;
- case 'W': /* maximum server worker threads */
- workersMax = atoi(opt->value);
- break;
- case 'e': /* program execution time in seconds */
- execution = atoi(opt->value);
- break;
- case 's': /* server's address */
- serverName = opt->value;
- break;
- case 'v': /* verbosity */
- verbosity = IncrementVerbosity();
- break;
- case 'd': /* debug mode */
- debug_mode = PR_TRUE;
- break;
- case 'p': /* pthread mode */
- pthread_stats = PR_TRUE;
- break;
- case 'h':
- default:
- Help();
- return 2;
+ case 'G': /* use global threads */
+ thread_scope = PR_GLOBAL_THREAD;
+ break;
+ case 'X': /* use XTP as transport */
+ protocol = 36;
+ break;
+ case '6': /* Use IPv6 */
+ domain = PR_AF_INET6;
+ break;
+ case 'a': /* the value for accepting */
+ accepting = atoi(opt->value);
+ break;
+ case 'b': /* the value for backlock */
+ backlog = atoi(opt->value);
+ break;
+ case 'c': /* number of client threads */
+ clients = atoi(opt->value);
+ break;
+ case 'f': /* low water fd cache */
+ low = atoi(opt->value);
+ break;
+ case 'F': /* low water fd cache */
+ high = atoi(opt->value);
+ break;
+ case 'w': /* minimum server worker threads */
+ workersMin = atoi(opt->value);
+ break;
+ case 'W': /* maximum server worker threads */
+ workersMax = atoi(opt->value);
+ break;
+ case 'e': /* program execution time in seconds */
+ execution = atoi(opt->value);
+ break;
+ case 's': /* server's address */
+ serverName = opt->value;
+ break;
+ case 'v': /* verbosity */
+ verbosity = IncrementVerbosity();
+ break;
+ case 'd': /* debug mode */
+ debug_mode = PR_TRUE;
+ break;
+ case 'p': /* pthread mode */
+ pthread_stats = PR_TRUE;
+ break;
+ case 'h':
+ default:
+ Help();
+ return 2;
}
}
PL_DestroyOptState(opt);
- if (0 != PL_strcmp(serverName, DEFAULT_SERVER)) serverIsLocal = PR_FALSE;
- if (0 == execution) execution = DEFAULT_EXECUTION_TIME;
- if (0 == workersMax) workersMax = DEFAULT_WORKERS_MAX;
- if (0 == workersMin) workersMin = DEFAULT_WORKERS_MIN;
- if (0 == accepting) accepting = ALLOWED_IN_ACCEPT;
- if (0 == backlog) backlog = DEFAULT_BACKLOG;
+ if (0 != PL_strcmp(serverName, DEFAULT_SERVER)) {
+ serverIsLocal = PR_FALSE;
+ }
+ if (0 == execution) {
+ execution = DEFAULT_EXECUTION_TIME;
+ }
+ if (0 == workersMax) {
+ workersMax = DEFAULT_WORKERS_MAX;
+ }
+ if (0 == workersMin) {
+ workersMin = DEFAULT_WORKERS_MIN;
+ }
+ if (0 == accepting) {
+ accepting = ALLOWED_IN_ACCEPT;
+ }
+ if (0 == backlog) {
+ backlog = DEFAULT_BACKLOG;
+ }
- if (workersMin > accepting) accepting = workersMin;
+ if (workersMin > accepting) {
+ accepting = workersMin;
+ }
PR_STDIO_INIT();
TimeOfDayMessage("Client/Server started at", PR_GetCurrentThread());
@@ -1023,8 +1083,8 @@ int main(int argc, char** argv)
("main(0x%p): creating server thread\n", PR_GetCurrentThread()));
server->thread = PR_CreateThread(
- PR_USER_THREAD, Server, server, PR_PRIORITY_HIGH,
- thread_scope, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, Server, server, PR_PRIORITY_HIGH,
+ thread_scope, PR_JOINABLE_THREAD, 0);
TEST_ASSERT(NULL != server->thread);
TEST_LOG(
@@ -1032,14 +1092,15 @@ int main(int argc, char** argv)
("main(0x%p): waiting for server init\n", PR_GetCurrentThread()));
PR_Lock(server->ml);
- while (server->state == cs_init)
+ while (server->state == cs_init) {
PR_WaitCondVar(server->stateChange, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_Unlock(server->ml);
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("main(0x%p): server init complete (port #%d)\n",
- PR_GetCurrentThread(), server->port));
+ PR_GetCurrentThread(), server->port));
}
if (clients != 0)
@@ -1052,7 +1113,7 @@ int main(int argc, char** argv)
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("main(0x%p): creating %d client threads\n",
- PR_GetCurrentThread(), clients));
+ PR_GetCurrentThread(), clients));
if (!serverIsLocal)
{
@@ -1070,13 +1131,13 @@ int main(int argc, char** argv)
client[index].ml = PR_NewLock();
if (serverIsLocal)
{
- if (PR_AF_INET6 != domain)
- (void)PR_InitializeNetAddr(
- PR_IpAddrLoopback, DEFAULT_PORT,
- &client[index].serverAddress);
- else
- rv = PR_SetNetAddr(PR_IpAddrLoopback, PR_AF_INET6,
- DEFAULT_PORT, &client[index].serverAddress);
+ if (PR_AF_INET6 != domain)
+ (void)PR_InitializeNetAddr(
+ PR_IpAddrLoopback, DEFAULT_PORT,
+ &client[index].serverAddress);
+ else
+ rv = PR_SetNetAddr(PR_IpAddrLoopback, PR_AF_INET6,
+ DEFAULT_PORT, &client[index].serverAddress);
}
else
{
@@ -1088,12 +1149,13 @@ int main(int argc, char** argv)
cltsrv_log_file, TEST_LOG_INFO,
("main(0x%p): creating client threads\n", PR_GetCurrentThread()));
client[index].thread = PR_CreateThread(
- PR_USER_THREAD, Client, &client[index], PR_PRIORITY_NORMAL,
- thread_scope, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, Client, &client[index], PR_PRIORITY_NORMAL,
+ thread_scope, PR_JOINABLE_THREAD, 0);
TEST_ASSERT(NULL != client[index].thread);
PR_Lock(client[index].ml);
- while (cs_init == client[index].state)
+ while (cs_init == client[index].state) {
PR_WaitCondVar(client[index].stateChange, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_Unlock(client[index].ml);
}
}
@@ -1102,7 +1164,7 @@ int main(int argc, char** argv)
TEST_LOG(
cltsrv_log_file, TEST_LOG_ALWAYS,
("main(0x%p): waiting for execution interval (%d seconds)\n",
- PR_GetCurrentThread(), execution));
+ PR_GetCurrentThread(), execution));
WaitForCompletion(execution);
@@ -1113,8 +1175,8 @@ int main(int argc, char** argv)
for (index = 0; index < clients; ++index)
{
TEST_LOG(cltsrv_log_file, TEST_LOG_STATUS,
- ("main(0x%p): notifying client(0x%p) to stop\n",
- PR_GetCurrentThread(), client[index].thread));
+ ("main(0x%p): notifying client(0x%p) to stop\n",
+ PR_GetCurrentThread(), client[index].thread));
PR_Lock(client[index].ml);
if (cs_run == client[index].state)
@@ -1128,11 +1190,11 @@ int main(int argc, char** argv)
PR_Unlock(client[index].ml);
TEST_LOG(cltsrv_log_file, TEST_LOG_VERBOSE,
- ("main(0x%p): joining client(0x%p)\n",
- PR_GetCurrentThread(), client[index].thread));
+ ("main(0x%p): joining client(0x%p)\n",
+ PR_GetCurrentThread(), client[index].thread));
- joinStatus = PR_JoinThread(client[index].thread);
- TEST_ASSERT(PR_SUCCESS == joinStatus);
+ joinStatus = PR_JoinThread(client[index].thread);
+ TEST_ASSERT(PR_SUCCESS == joinStatus);
PR_DestroyCondVar(client[index].stateChange);
PR_DestroyLock(client[index].ml);
}
@@ -1145,19 +1207,20 @@ int main(int argc, char** argv)
TEST_LOG(
cltsrv_log_file, TEST_LOG_NOTICE,
("main(0x%p): notifying server(0x%p) to stop\n",
- PR_GetCurrentThread(), server->thread));
+ PR_GetCurrentThread(), server->thread));
PR_Lock(server->ml);
server->state = cs_stop;
PR_Interrupt(server->thread);
- while (cs_exit != server->state)
+ while (cs_exit != server->state) {
PR_WaitCondVar(server->stateChange, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_Unlock(server->ml);
TEST_LOG(
cltsrv_log_file, TEST_LOG_NOTICE,
("main(0x%p): joining server(0x%p)\n",
- PR_GetCurrentThread(), server->thread));
+ PR_GetCurrentThread(), server->thread));
joinStatus = PR_JoinThread(server->thread);
TEST_ASSERT(PR_SUCCESS == joinStatus);
diff --git a/pr/tests/concur.c b/pr/tests/concur.c
index 1b8f001b..59402902 100644
--- a/pr/tests/concur.c
+++ b/pr/tests/concur.c
@@ -46,8 +46,9 @@ static void PR_CALLBACK Dull(void *arg)
Context *context = (Context*)arg;
PR_Lock(context->ml);
context->have += 1;
- while (context->want >= context->have)
+ while (context->want >= context->have) {
PR_WaitCondVar(context->cv, PR_INTERVAL_NO_TIMEOUT);
+ }
context->have -= 1;
PR_Unlock(context->ml);
} /* Dull */
@@ -55,40 +56,46 @@ static void PR_CALLBACK Dull(void *arg)
PRIntn PR_CALLBACK Concur(PRIntn argc, char **argv)
{
PRUintn cpus;
- PLOptStatus os;
- PRThread **threads;
+ PLOptStatus os;
+ PRThread **threads;
PRBool debug = PR_FALSE;
PRUintn range = DEFAULT_RANGE;
- PRStatus rc;
+ PRStatus rc;
PRUintn cnt;
PRUintn loops = DEFAULT_LOOPS;
- PRIntervalTime hundredMills = PR_MillisecondsToInterval(100);
- PLOptState *opt = PL_CreateOptState(argc, argv, "Gdl:r:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ PRIntervalTime hundredMills = PR_MillisecondsToInterval(100);
+ PLOptState *opt = PL_CreateOptState(argc, argv, "Gdl:r:");
+ while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
- if (PL_OPT_BAD == os) continue;
+ if (PL_OPT_BAD == os) {
+ continue;
+ }
switch (opt->option)
{
- case 'G': /* GLOBAL threads */
- thread_scope = PR_GLOBAL_THREAD;
- break;
- case 'd': /* debug mode */
- debug = PR_TRUE;
- break;
- case 'r': /* range limit */
- range = atoi(opt->value);
- break;
- case 'l': /* loop counter */
- loops = atoi(opt->value);
- break;
- default:
- break;
+ case 'G': /* GLOBAL threads */
+ thread_scope = PR_GLOBAL_THREAD;
+ break;
+ case 'd': /* debug mode */
+ debug = PR_TRUE;
+ break;
+ case 'r': /* range limit */
+ range = atoi(opt->value);
+ break;
+ case 'l': /* loop counter */
+ loops = atoi(opt->value);
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- if (0 == range) range = DEFAULT_RANGE;
- if (0 == loops) loops = DEFAULT_LOOPS;
+ if (0 == range) {
+ range = DEFAULT_RANGE;
+ }
+ if (0 == loops) {
+ loops = DEFAULT_LOOPS;
+ }
context.ml = PR_NewLock();
context.cv = PR_NewCondVar(context.ml);
@@ -97,7 +104,7 @@ PRIntn PR_CALLBACK Concur(PRIntn argc, char **argv)
PR_fprintf(
PR_STDERR, "Testing with %d CPUs and %d interations\n", range, loops);
- threads = (PRThread**) PR_CALLOC(sizeof(PRThread*) * range);
+ threads = (PRThread**) PR_CALLOC(sizeof(PRThread*) * range);
while (--loops > 0)
{
for (cpus = 1; cpus <= range; ++cpus)
@@ -106,8 +113,8 @@ PRIntn PR_CALLBACK Concur(PRIntn argc, char **argv)
context.want = cpus;
threads[cpus - 1] = PR_CreateThread(
- PR_USER_THREAD, Dull, &context, PR_PRIORITY_NORMAL,
- thread_scope, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, Dull, &context, PR_PRIORITY_NORMAL,
+ thread_scope, PR_JOINABLE_THREAD, 0);
}
PR_Sleep(hundredMills);
@@ -121,10 +128,10 @@ PRIntn PR_CALLBACK Concur(PRIntn argc, char **argv)
PR_NotifyCondVar(context.cv);
PR_Unlock(context.ml);
}
- for(cnt = 0; cnt < range; cnt++) {
- rc = PR_JoinThread(threads[cnt]);
- PR_ASSERT(rc == PR_SUCCESS);
- }
+ for(cnt = 0; cnt < range; cnt++) {
+ rc = PR_JoinThread(threads[cnt]);
+ PR_ASSERT(rc == PR_SUCCESS);
+ }
}
@@ -132,7 +139,9 @@ PRIntn PR_CALLBACK Concur(PRIntn argc, char **argv)
PR_fprintf(
PR_STDERR, "Waiting for %d thread(s) to exit\n", context.have);
- while (context.have > 0) PR_Sleep(hundredMills);
+ while (context.have > 0) {
+ PR_Sleep(hundredMills);
+ }
if (debug)
PR_fprintf(
diff --git a/pr/tests/cvar.c b/pr/tests/cvar.c
index bbb94225..4dc891d3 100644
--- a/pr/tests/cvar.c
+++ b/pr/tests/cvar.c
@@ -12,12 +12,12 @@
**
** Modification History:
** 13-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.
** 12-June-97 Revert to return code 0 and 1.
***********************************************************************/
@@ -39,15 +39,15 @@ PRMonitor *mon;
PRInt32 count = 0;
PRIntn debug_mode;
-#define kQSIZE 1
+#define kQSIZE 1
typedef struct {
- PRLock *bufLock;
- int startIdx;
- int numFull;
- PRCondVar *notFull;
- PRCondVar *notEmpty;
- void *data[kQSIZE];
+ PRLock *bufLock;
+ int startIdx;
+ int numFull;
+ PRCondVar *notFull;
+ PRCondVar *notEmpty;
+ void *data[kQSIZE];
} CircBuf;
static PRBool failed = PR_FALSE;
@@ -57,19 +57,20 @@ static PRBool failed = PR_FALSE;
*/
static CircBuf* NewCB(void)
{
- CircBuf *cbp;
+ CircBuf *cbp;
- cbp = PR_NEW(CircBuf);
- if (cbp == NULL)
- return (NULL);
+ cbp = PR_NEW(CircBuf);
+ if (cbp == NULL) {
+ return (NULL);
+ }
- cbp->bufLock = PR_NewLock();
- cbp->startIdx = 0;
- cbp->numFull = 0;
- cbp->notFull = PR_NewCondVar(cbp->bufLock);
- cbp->notEmpty = PR_NewCondVar(cbp->bufLock);
+ cbp->bufLock = PR_NewLock();
+ cbp->startIdx = 0;
+ cbp->numFull = 0;
+ cbp->notFull = PR_NewCondVar(cbp->bufLock);
+ cbp->notEmpty = PR_NewCondVar(cbp->bufLock);
- return (cbp);
+ return (cbp);
}
/*
@@ -77,10 +78,10 @@ static CircBuf* NewCB(void)
*/
static void DeleteCB(CircBuf *cbp)
{
- PR_DestroyLock(cbp->bufLock);
- PR_DestroyCondVar(cbp->notFull);
- PR_DestroyCondVar(cbp->notEmpty);
- PR_DELETE(cbp);
+ PR_DestroyLock(cbp->bufLock);
+ PR_DestroyCondVar(cbp->notFull);
+ PR_DestroyCondVar(cbp->notEmpty);
+ PR_DELETE(cbp);
}
@@ -90,16 +91,17 @@ static void DeleteCB(CircBuf *cbp)
*/
static void PutCBData(CircBuf *cbp, void *data)
{
- PR_Lock(cbp->bufLock);
- /* wait while the buffer is full */
- while (cbp->numFull == kQSIZE)
- PR_WaitCondVar(cbp->notFull,PR_INTERVAL_NO_TIMEOUT);
- cbp->data[(cbp->startIdx + cbp->numFull) % kQSIZE] = data;
- cbp->numFull += 1;
+ PR_Lock(cbp->bufLock);
+ /* wait while the buffer is full */
+ while (cbp->numFull == kQSIZE) {
+ PR_WaitCondVar(cbp->notFull,PR_INTERVAL_NO_TIMEOUT);
+ }
+ cbp->data[(cbp->startIdx + cbp->numFull) % kQSIZE] = data;
+ cbp->numFull += 1;
- /* let a waiting reader know that there is data */
- PR_NotifyCondVar(cbp->notEmpty);
- PR_Unlock(cbp->bufLock);
+ /* let a waiting reader know that there is data */
+ PR_NotifyCondVar(cbp->notEmpty);
+ PR_Unlock(cbp->bufLock);
}
@@ -110,21 +112,22 @@ static void PutCBData(CircBuf *cbp, void *data)
*/
static void* GetCBData(CircBuf *cbp)
{
- void *data;
+ void *data;
- PR_Lock(cbp->bufLock);
- /* wait while the buffer is empty */
- while (cbp->numFull == 0)
- PR_WaitCondVar(cbp->notEmpty,PR_INTERVAL_NO_TIMEOUT);
- data = cbp->data[cbp->startIdx];
- cbp->startIdx =(cbp->startIdx + 1) % kQSIZE;
- cbp->numFull -= 1;
+ PR_Lock(cbp->bufLock);
+ /* wait while the buffer is empty */
+ while (cbp->numFull == 0) {
+ PR_WaitCondVar(cbp->notEmpty,PR_INTERVAL_NO_TIMEOUT);
+ }
+ data = cbp->data[cbp->startIdx];
+ cbp->startIdx =(cbp->startIdx + 1) % kQSIZE;
+ cbp->numFull -= 1;
- /* let a waiting writer know that there is room */
- PR_NotifyCondVar(cbp->notFull);
- PR_Unlock(cbp->bufLock);
+ /* let a waiting writer know that there is room */
+ PR_NotifyCondVar(cbp->notFull);
+ PR_Unlock(cbp->bufLock);
- return (data);
+ return (data);
}
@@ -134,15 +137,17 @@ static int alive;
static void PR_CALLBACK CXReader(void *arg)
{
- CircBuf *cbp = (CircBuf *)arg;
+ CircBuf *cbp = (CircBuf *)arg;
PRInt32 i, n;
void *data;
n = count / 2;
for (i = 0; i < n; i++) {
- data = GetCBData(cbp);
- if ((int)data != i)
- if (debug_mode) printf("data mismatch at for i = %d usec\n", i);
+ data = GetCBData(cbp);
+ if ((int)data != i)
+ if (debug_mode) {
+ printf("data mismatch at for i = %d usec\n", i);
+ }
}
PR_EnterMonitor(mon);
@@ -153,12 +158,13 @@ static void PR_CALLBACK CXReader(void *arg)
static void PR_CALLBACK CXWriter(void *arg)
{
- CircBuf *cbp = (CircBuf *)arg;
+ CircBuf *cbp = (CircBuf *)arg;
PRInt32 i, n;
n = count / 2;
- for (i = 0; i < n; i++)
- PutCBData(cbp, (void *)i);
+ for (i = 0; i < n; i++) {
+ PutCBData(cbp, (void *)i);
+ }
PR_EnterMonitor(mon);
--alive;
@@ -169,35 +175,35 @@ static void PR_CALLBACK CXWriter(void *arg)
static void CondWaitContextSwitch(PRThreadScope scope1, PRThreadScope scope2)
{
PRThread *t1, *t2;
- CircBuf *cbp;
+ CircBuf *cbp;
PR_EnterMonitor(mon);
alive = 2;
- cbp = NewCB();
-
- t1 = PR_CreateThread(PR_USER_THREAD,
- CXReader, cbp,
- PR_PRIORITY_NORMAL,
- scope1,
- PR_UNJOINABLE_THREAD,
- 0);
- PR_ASSERT(t1);
- t2 = PR_CreateThread(PR_USER_THREAD,
- CXWriter, cbp,
- PR_PRIORITY_NORMAL,
- scope2,
- PR_UNJOINABLE_THREAD,
- 0);
- PR_ASSERT(t2);
+ cbp = NewCB();
+
+ t1 = PR_CreateThread(PR_USER_THREAD,
+ CXReader, cbp,
+ PR_PRIORITY_NORMAL,
+ scope1,
+ PR_UNJOINABLE_THREAD,
+ 0);
+ PR_ASSERT(t1);
+ t2 = PR_CreateThread(PR_USER_THREAD,
+ CXWriter, cbp,
+ PR_PRIORITY_NORMAL,
+ scope2,
+ PR_UNJOINABLE_THREAD,
+ 0);
+ PR_ASSERT(t2);
/* Wait for both of the threads to exit */
while (alive) {
- PR_Wait(mon, PR_INTERVAL_NO_TIMEOUT);
+ PR_Wait(mon, PR_INTERVAL_NO_TIMEOUT);
}
- DeleteCB(cbp);
+ DeleteCB(cbp);
PR_ExitMonitor(mon);
}
@@ -230,39 +236,47 @@ static void Measure(void (*func)(void), const char *msg)
d = (double)PR_IntervalToMicroseconds(stop - start);
- if (debug_mode) printf("%40s: %6.2f usec\n", msg, d / count);
+ if (debug_mode) {
+ printf("%40s: %6.2f usec\n", msg, d / count);
+ }
- if (0 == d) failed = PR_TRUE;
+ if (0 == d) {
+ failed = PR_TRUE;
+ }
}
static PRIntn PR_CALLBACK RealMain(int argc, char **argv)
{
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name [-d] [-c n]
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "dc:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name [-d] [-c n]
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "dc:");
+ 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_mode = 1;
- break;
- case 'c': /* loop count */
- count = atoi(opt->value);
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ case 'c': /* loop count */
+ count = atoi(opt->value);
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- if (0 == count) count = DEFAULT_COUNT;
+ if (0 == count) {
+ count = DEFAULT_COUNT;
+ }
mon = PR_NewMonitor();
@@ -270,14 +284,18 @@ static PRIntn PR_CALLBACK RealMain(int argc, char **argv)
Measure(CondWaitContextSwitchUK, "cond var wait context switch- user/kernel");
Measure(CondWaitContextSwitchKK, "cond var wait context switch- kernel/kernel");
- PR_DestroyMonitor(mon);
+ PR_DestroyMonitor(mon);
- if (debug_mode) printf("%s\n", (failed) ? "FAILED" : "PASSED");
+ if (debug_mode) {
+ printf("%s\n", (failed) ? "FAILED" : "PASSED");
+ }
- if(failed)
- return 1;
- else
- return 0;
+ if(failed) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
}
diff --git a/pr/tests/cvar2.c b/pr/tests/cvar2.c
index c2efbe85..c9f57d5c 100644
--- a/pr/tests/cvar2.c
+++ b/pr/tests/cvar2.c
@@ -11,14 +11,14 @@
** Description: Simple test creates several local and global threads;
** half use a single,shared condvar, and the
** other half have their own condvar. The main thread then loops
-** notifying them to wakeup.
+** notifying them to wakeup.
**
** Modification History:
** 14-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.
***********************************************************************/
#include "nspr.h"
@@ -67,8 +67,9 @@ SharedCondVarThread(void *_info)
for (index=0; index<info->loops; index++) {
PR_Lock(info->lock);
- if (*info->tcount == 0)
+ if (*info->tcount == 0) {
PR_WaitCondVar(info->cvar, info->timeout);
+ }
#if 0
printf("shared thread %ld notified in loop %ld\n", info->id, index);
#endif
@@ -95,10 +96,10 @@ PrivateCondVarThread(void *_info)
for (index=0; index<info->loops; index++) {
PR_Lock(info->lock);
if (*info->tcount == 0) {
- DPRINTF(("PrivateCondVarThread: thread 0x%lx waiting on cvar = 0x%lx\n",
- PR_GetCurrentThread(), info->cvar));
+ DPRINTF(("PrivateCondVarThread: thread 0x%lx waiting on cvar = 0x%lx\n",
+ PR_GetCurrentThread(), info->cvar));
PR_WaitCondVar(info->cvar, info->timeout);
- }
+ }
#if 0
printf("solo thread %ld notified in loop %ld\n", info->id, index);
#endif
@@ -108,8 +109,8 @@ PrivateCondVarThread(void *_info)
PR_Lock(info->exitlock);
(*info->exitcount)++;
PR_NotifyCondVar(info->exitcvar);
-DPRINTF(("PrivateCondVarThread: thread 0x%lx notified exitcvar = 0x%lx cnt = %ld\n",
- PR_GetCurrentThread(), info->exitcvar,(*info->exitcount)));
+ DPRINTF(("PrivateCondVarThread: thread 0x%lx notified exitcvar = 0x%lx cnt = %ld\n",
+ PR_GetCurrentThread(), info->exitcvar,(*info->exitcount)));
PR_Unlock(info->exitlock);
}
#if 0
@@ -142,15 +143,16 @@ CreateTestThread(threadinfo *info,
info->exitcvar = exitcvar;
info->exitcount = exitcount;
info->thread = PR_CreateThread(
- PR_USER_THREAD,
- shared?SharedCondVarThread:PrivateCondVarThread,
- info,
- PR_PRIORITY_NORMAL,
- scope,
- PR_JOINABLE_THREAD,
- 0);
- if (!info->thread)
+ PR_USER_THREAD,
+ shared?SharedCondVarThread:PrivateCondVarThread,
+ info,
+ PR_PRIORITY_NORMAL,
+ scope,
+ PR_JOINABLE_THREAD,
+ 0);
+ if (!info->thread) {
PL_PrintError("error creating thread\n");
+ }
}
@@ -189,7 +191,7 @@ CondVarTestSUU(void *_arg)
PR_TRUE,
PR_LOCAL_THREAD);
index++;
- DPRINTF(("CondVarTestSUU: created thread 0x%lx\n",list[index].thread));
+ DPRINTF(("CondVarTestSUU: created thread 0x%lx\n",list[index].thread));
}
for (loops = 0; loops < count; loops++) {
@@ -199,22 +201,24 @@ CondVarTestSUU(void *_arg)
(*list[index].tcount)++;
PR_NotifyCondVar(list[index].cvar);
PR_Unlock(list[index].lock);
- DPRINTF(("PrivateCondVarThread: thread 0x%lx notified cvar = 0x%lx\n",
- PR_GetCurrentThread(), list[index].cvar));
+ DPRINTF(("PrivateCondVarThread: thread 0x%lx notified cvar = 0x%lx\n",
+ PR_GetCurrentThread(), list[index].cvar));
}
/* Wait for threads to finish */
PR_Lock(exitlock);
- while(exitcount < arg)
+ while(exitcount < arg) {
PR_WaitCondVar(exitcvar, PR_SecondsToInterval(60));
+ }
PR_ASSERT(exitcount >= arg);
exitcount -= arg;
PR_Unlock(exitlock);
}
/* Join all the threads */
- for(index=0; index<(arg); index++)
+ for(index=0; index<(arg); index++) {
PR_JoinThread(list[index].thread);
+ }
PR_DestroyCondVar(sharedcvar);
PR_DestroyLock(sharedlock);
@@ -276,8 +280,9 @@ CondVarTestSUK(void *_arg)
#endif
/* Wait for threads to finish */
PR_Lock(exitlock);
- while(exitcount < arg)
+ while(exitcount < arg) {
PR_WaitCondVar(exitcvar, PR_SecondsToInterval(60));
+ }
PR_ASSERT(exitcount >= arg);
exitcount -= arg;
PR_Unlock(exitlock);
@@ -287,8 +292,9 @@ CondVarTestSUK(void *_arg)
}
/* Join all the threads */
- for(index=0; index<(arg); index++)
+ for(index=0; index<(arg); index++) {
PR_JoinThread(list[index].thread);
+ }
PR_DestroyCondVar(sharedcvar);
PR_DestroyLock(sharedlock);
@@ -336,9 +342,9 @@ CondVarTestPUU(void *_arg)
PR_FALSE,
PR_LOCAL_THREAD);
- DPRINTF(("CondVarTestPUU: created thread 0x%lx\n",list[index].thread));
+ DPRINTF(("CondVarTestPUU: created thread 0x%lx\n",list[index].thread));
index++;
- tcount++;
+ tcount++;
}
for (loops = 0; loops < count; loops++) {
@@ -351,13 +357,13 @@ CondVarTestPUU(void *_arg)
PR_Unlock(list[index].lock);
}
- PR_Lock(exitlock);
+ PR_Lock(exitlock);
/* Wait for threads to finish */
while(exitcount < arg) {
-DPRINTF(("CondVarTestPUU: thread 0x%lx waiting on exitcvar = 0x%lx cnt = %ld\n",
- PR_GetCurrentThread(), exitcvar, exitcount));
- PR_WaitCondVar(exitcvar, PR_SecondsToInterval(60));
- }
+ DPRINTF(("CondVarTestPUU: thread 0x%lx waiting on exitcvar = 0x%lx cnt = %ld\n",
+ PR_GetCurrentThread(), exitcvar, exitcount));
+ PR_WaitCondVar(exitcvar, PR_SecondsToInterval(60));
+ }
PR_ASSERT(exitcount >= arg);
exitcount -= arg;
PR_Unlock(exitlock);
@@ -365,7 +371,7 @@ DPRINTF(("CondVarTestPUU: thread 0x%lx waiting on exitcvar = 0x%lx cnt = %ld\n",
/* Join all the threads */
for(index=0; index<(arg); index++) {
- DPRINTF(("CondVarTestPUU: joining thread 0x%lx\n",list[index].thread));
+ DPRINTF(("CondVarTestPUU: joining thread 0x%lx\n",list[index].thread));
PR_JoinThread(list[index].thread);
if (list[index].internal) {
PR_Lock(list[index].lock);
@@ -438,8 +444,9 @@ CondVarTestPUK(void *_arg)
/* Wait for threads to finish */
PR_Lock(exitlock);
- while(exitcount < arg)
+ while(exitcount < arg) {
PR_WaitCondVar(exitcvar, PR_SecondsToInterval(60));
+ }
PR_ASSERT(exitcount >= arg);
exitcount -= arg;
PR_Unlock(exitlock);
@@ -532,7 +539,7 @@ CondVarTest(void *_arg)
PR_FALSE,
PR_LOCAL_THREAD);
index++;
- ptcount++;
+ ptcount++;
list[index].lock = PR_NewLock();
list[index].cvar = PR_NewCondVar(list[index].lock);
CreateTestThread(&list[index],
@@ -549,7 +556,7 @@ CondVarTest(void *_arg)
PR_GLOBAL_THREAD);
index++;
- ptcount++;
+ ptcount++;
}
for (loops = 0; loops < count; loops++) {
@@ -568,8 +575,9 @@ CondVarTest(void *_arg)
/* Wait for threads to finish */
PR_Lock(exitlock);
- while(exitcount < arg*4)
+ while(exitcount < arg*4) {
PR_WaitCondVar(exitcvar, PR_SecondsToInterval(60));
+ }
PR_ASSERT(exitcount >= arg*4);
exitcount -= arg*4;
PR_Unlock(exitlock);
@@ -682,8 +690,9 @@ CondVarTimeoutTest(void *_arg)
/* Wait for threads to finish */
PR_Lock(exitlock);
- while(exitcount < arg*4)
+ while(exitcount < arg*4) {
PR_WaitCondVar(exitcvar, PR_SecondsToInterval(60));
+ }
PR_ASSERT(exitcount >= arg*4);
exitcount -= arg*4;
PR_Unlock(exitlock);
@@ -774,7 +783,7 @@ CondVarMixedTest(void *_arg)
PR_FALSE,
PR_LOCAL_THREAD);
index++;
- ptcount++;
+ ptcount++;
list[index].lock = PR_NewLock();
list[index].cvar = PR_NewCondVar(list[index].lock);
@@ -791,7 +800,7 @@ CondVarMixedTest(void *_arg)
PR_FALSE,
PR_GLOBAL_THREAD);
index++;
- ptcount++;
+ ptcount++;
}
@@ -809,8 +818,9 @@ CondVarMixedTest(void *_arg)
}
/* Wait for threads to finish */
PR_Lock(exitlock);
- while(exitcount < arg*4)
+ while(exitcount < arg*4) {
PR_WaitCondVar(exitcvar, PR_SecondsToInterval(60));
+ }
PR_ASSERT(exitcount >= arg*4);
exitcount -= arg*4;
PR_Unlock(exitlock);
@@ -884,30 +894,36 @@ static void Measure(void (*func)(void *), PRInt32 arg, const char *msg)
static PRIntn PR_CALLBACK RealMain(int argc, char **argv)
{
PRInt32 threads, default_threads = DEFAULT_THREADS;
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "vc:t:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "vc:t:");
+ 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': /* debug mode */
- _debug_on = 1;
- break;
- case 'c': /* loop counter */
- count = atoi(opt->value);
- break;
- case 't': /* number of threads involved */
- default_threads = atoi(opt->value);
- break;
- default:
- break;
+ case 'v': /* debug mode */
+ _debug_on = 1;
+ break;
+ case 'c': /* loop counter */
+ count = atoi(opt->value);
+ break;
+ case 't': /* number of threads involved */
+ default_threads = atoi(opt->value);
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- if (0 == count) count = DEFAULT_COUNT;
- if (0 == default_threads) default_threads = DEFAULT_THREADS;
+ if (0 == count) {
+ count = DEFAULT_COUNT;
+ }
+ if (0 == default_threads) {
+ default_threads = DEFAULT_THREADS;
+ }
printf("\n\
CondVar Test: \n\
@@ -927,7 +943,7 @@ Lastly, the combined test creates a thread for each of the above three \n\
cases and they all run simultaneously. \n\
\n\
This test is run with %d, %d, %d, and %d threads of each type.\n\n",
-default_threads, default_threads*2, default_threads*3, default_threads*4);
+ default_threads, default_threads*2, default_threads*3, default_threads*4);
PR_SetConcurrency(2);
diff --git a/pr/tests/dbmalloc.c b/pr/tests/dbmalloc.c
index fa96c964..2a7ad4fa 100644
--- a/pr/tests/dbmalloc.c
+++ b/pr/tests/dbmalloc.c
@@ -11,10 +11,10 @@
**
** Modification History:
** 14-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.
***********************************************************************/
#include <stdio.h>
#include <stdlib.h>
@@ -38,15 +38,17 @@ typedef struct node_struct
int line;
char value[4];
}
- node_t,
- *node_pt;
+node_t,
+*node_pt;
node_pt get_node(const char *line)
{
node_pt rv;
int l = strlen(line);
rv = (node_pt)PR_MALLOC(sizeof(node_t) + l + 1 - 4);
- if( (node_pt)0 == rv ) return (node_pt)0;
+ if( (node_pt)0 == rv ) {
+ return (node_pt)0;
+ }
memcpy(&rv->value[0], line, l+1);
rv->next = rv->prev = (node_pt)0;
return rv;
@@ -61,10 +63,18 @@ dump
int debug
)
{
- if( (node_pt)0 != node->prev ) dump(name, node->prev, mf, debug);
- if( 0 != debug ) printf("[%s]: %6d: %s", name, node->line, node->value);
- if( node->line == mf ) fprintf(stderr, "[%s]: Line %d was allocated!\n", name, node->line);
- if( (node_pt)0 != node->next ) dump(name, node->next, mf, debug);
+ if( (node_pt)0 != node->prev ) {
+ dump(name, node->prev, mf, debug);
+ }
+ if( 0 != debug ) {
+ printf("[%s]: %6d: %s", name, node->line, node->value);
+ }
+ if( node->line == mf ) {
+ fprintf(stderr, "[%s]: Line %d was allocated!\n", name, node->line);
+ }
+ if( (node_pt)0 != node->next ) {
+ dump(name, node->next, mf, debug);
+ }
return;
}
@@ -74,8 +84,12 @@ release
node_pt node
)
{
- if( (node_pt)0 != node->prev ) release(node->prev);
- if( (node_pt)0 != node->next ) release(node->next);
+ if( (node_pt)0 != node->prev ) {
+ release(node->prev);
+ }
+ if( (node_pt)0 != node->next ) {
+ release(node->next);
+ }
PR_DELETE(node);
}
@@ -129,8 +143,9 @@ t2
node_pt n;
node_pt *w = &head;
- if( (strlen(buffer) == (BUFSIZ-1)) && (buffer[BUFSIZ-2] != '\n') )
+ if( (strlen(buffer) == (BUFSIZ-1)) && (buffer[BUFSIZ-2] != '\n') ) {
buffer[BUFSIZ-2] == '\n';
+ }
l++;
@@ -154,8 +169,12 @@ t2
}
comp = strcmp((*w)->value, n->value);
- if( comp < 0 ) w = &(*w)->next;
- else w = &(*w)->prev;
+ if( comp < 0 ) {
+ w = &(*w)->next;
+ }
+ else {
+ w = &(*w)->prev;
+ }
}
}
@@ -186,16 +205,24 @@ test
printf("[%s]: starting test 0\n", name);
n = t2(name, 0, debug);
- if( -1 == n ) return;
+ if( -1 == n ) {
+ return;
+ }
printf("[%s]: test 0 had %ld allocations.\n", name, n);
- if( 0 >= n ) return;
+ if( 0 >= n ) {
+ return;
+ }
for( i = 0; i < nf; i++ )
{
int which = rand() % n;
- if( 0 == which ) printf("[%s]: starting test %d -- no allocation should fail\n", name, i+1);
- else printf("[%s]: starting test %d -- allocation %d should fail\n", name, i+1, which);
+ if( 0 == which ) {
+ printf("[%s]: starting test %d -- no allocation should fail\n", name, i+1);
+ }
+ else {
+ printf("[%s]: starting test %d -- allocation %d should fail\n", name, i+1, which);
+ }
(void)t2(name, which, debug);
printf("[%s]: test %d done.\n", name, i+1);
}
@@ -213,7 +240,7 @@ int main(int argc, char **argv)
struct threadlist *next;
PRThread *thread;
}
- *threadhead = (struct threadlist *)0;
+ *threadhead = (struct threadlist *)0;
extern int nf, debug;
@@ -296,14 +323,16 @@ int main(int argc, char **argv)
}
}
- if( okay == 0 ) usage();
- else while( (struct threadlist *)0 != threadhead )
- {
- struct threadlist *x = threadhead->next;
- (void)PR_JoinThread(threadhead->thread);
- PR_DELETE(threadhead);
- threadhead = x;
+ if( okay == 0 ) {
+ usage();
}
+ else while( (struct threadlist *)0 != threadhead )
+ {
+ struct threadlist *x = threadhead->next;
+ (void)PR_JoinThread(threadhead->thread);
+ PR_DELETE(threadhead);
+ threadhead = x;
+ }
return 0;
}
diff --git a/pr/tests/dbmalloc1.c b/pr/tests/dbmalloc1.c
index cb13ecf7..a7e995c4 100644
--- a/pr/tests/dbmalloc1.c
+++ b/pr/tests/dbmalloc1.c
@@ -11,12 +11,12 @@
**
** Modification History:
** 14-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.
**
** 12-June-97 AGarcia Revert to return code 0 and 1, remove debug option (obsolete).
***********************************************************************/
@@ -44,18 +44,22 @@ r1
)
{
int i;
- actually_failed=0;
+ actually_failed=0;
for( i = 0; i < 5; i++ )
{
void *x = PR_MALLOC(128);
if( (void *)0 == x ) {
- if (debug_mode) printf("\tMalloc %d failed.\n", i+1);
- actually_failed = 1;
- }
+ if (debug_mode) {
+ printf("\tMalloc %d failed.\n", i+1);
+ }
+ actually_failed = 1;
+ }
PR_DELETE(x);
}
- if (((should_fail != actually_failed) & (!debug_mode))) failed_already=1;
+ if (((should_fail != actually_failed) & (!debug_mode))) {
+ failed_already=1;
+ }
return;
@@ -71,14 +75,18 @@ r2
for( i = 0; i <= 5; i++ )
{
- should_fail =0;
+ should_fail =0;
if( 0 == i ) {
- if (debug_mode) printf("No malloc should fail:\n");
- }
+ if (debug_mode) {
+ printf("No malloc should fail:\n");
+ }
+ }
else {
- if (debug_mode) printf("Malloc %d should fail:\n", i);
- should_fail = 1;
- }
+ if (debug_mode) {
+ printf("Malloc %d should fail:\n", i);
+ }
+ should_fail = 1;
+ }
PR_SetMallocCountdown(i);
r1();
PR_ClearMallocCountdown();
@@ -88,16 +96,18 @@ r2
int main(int argc, char **argv)
{
- /* main test */
+ /* main test */
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
PR_STDIO_INIT();
r2();
- if(failed_already)
+ if(failed_already) {
return 1;
- else
+ }
+ else {
return 0;
+ }
}
diff --git a/pr/tests/dceemu.c b/pr/tests/dceemu.c
index 5a1eb78d..2b1d0901 100644
--- a/pr/tests/dceemu.c
+++ b/pr/tests/dceemu.c
@@ -9,8 +9,8 @@
**
** Modification History:
** 14-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.
** 04-June-97 AGarcia removed the Test_Result function. Regress tool has been updated to
@@ -41,38 +41,54 @@ static PRIntn prmain(PRIntn argc, char **argv)
rv = PRP_TryLock(ml);
PR_ASSERT(PR_SUCCESS == rv);
- if ((rv != PR_SUCCESS) & (!debug_mode)) failed_already=1;
+ if ((rv != PR_SUCCESS) & (!debug_mode)) {
+ failed_already=1;
+ }
rv = PRP_TryLock(ml);
PR_ASSERT(PR_FAILURE == rv);
- if ((rv != PR_FAILURE) & (!debug_mode)) failed_already=1;
+ if ((rv != PR_FAILURE) & (!debug_mode)) {
+ failed_already=1;
+ }
rv = PRP_NakedNotify(cv);
PR_ASSERT(PR_SUCCESS == rv);
- if ((rv != PR_SUCCESS) & (!debug_mode)) failed_already=1;
+ if ((rv != PR_SUCCESS) & (!debug_mode)) {
+ failed_already=1;
+ }
rv = PRP_NakedBroadcast(cv);
PR_ASSERT(PR_SUCCESS == rv);
- if ((rv != PR_SUCCESS) & (!debug_mode)) failed_already=1;
+ if ((rv != PR_SUCCESS) & (!debug_mode)) {
+ failed_already=1;
+ }
rv = PRP_NakedWait(cv, ml, tenmsecs);
PR_ASSERT(PR_SUCCESS == rv);
- if ((rv != PR_SUCCESS) & (!debug_mode)) failed_already=1;
+ if ((rv != PR_SUCCESS) & (!debug_mode)) {
+ failed_already=1;
+ }
PR_Unlock(ml);
rv = PRP_NakedNotify(cv);
PR_ASSERT(PR_SUCCESS == rv);
- if ((rv != PR_SUCCESS) & (!debug_mode)) failed_already=1;
+ if ((rv != PR_SUCCESS) & (!debug_mode)) {
+ failed_already=1;
+ }
rv = PRP_NakedBroadcast(cv);
PR_ASSERT(PR_SUCCESS == rv);
- if ((rv != PR_SUCCESS) & (!debug_mode)) failed_already=1;
+ if ((rv != PR_SUCCESS) & (!debug_mode)) {
+ failed_already=1;
+ }
PRP_DestroyNakedCondVar(cv);
PR_DestroyLock(ml);
- if (debug_mode) printf("Test succeeded\n");
+ if (debug_mode) {
+ printf("Test succeeded\n");
+ }
return 0;
@@ -81,10 +97,12 @@ static PRIntn prmain(PRIntn argc, char **argv)
int main(int argc, char **argv)
{
PR_Initialize(prmain, argc, argv, 0);
- if(failed_already)
+ if(failed_already) {
return 1;
- else
+ }
+ else {
return 0;
+ }
} /* main */
diff --git a/pr/tests/depend.c b/pr/tests/depend.c
index 98ce245e..f3689bc4 100644
--- a/pr/tests/depend.c
+++ b/pr/tests/depend.c
@@ -7,15 +7,15 @@
** 1996 - Netscape Communications Corporation
**
**
-** Name: depend.c
+** Name: depend.c
** Description: Test to enumerate the dependencies
*
** Modification History:
** 14-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.
***********************************************************************/
#include "prinit.h"
@@ -35,13 +35,16 @@ static void PrintVersion(
static const char *tabs = {" "};
tab *= 2;
- if (tab > len) tab = len;
+ if (tab > len) {
+ tab = len;
+ }
printf("%s", &tabs[len - tab]);
printf("%s ", msg);
printf("%s ", info->id);
printf("%d.%d", info->major, info->minor);
- if (0 != info->patch)
+ if (0 != info->patch) {
printf(".p%d", info->patch);
+ }
printf("\n");
} /* PrintDependency */
@@ -77,9 +80,15 @@ static const PRVersionInfo *HackExportInfo(void)
static const PRDependencyInfo *DummyImports(
const PRDependencyInfo *previous)
{
- if (NULL == previous) return &dummy_imports[0];
- else if (&dummy_imports[0] == previous) return &dummy_imports[1];
- else if (&dummy_imports[1] == previous) return NULL;
+ if (NULL == previous) {
+ return &dummy_imports[0];
+ }
+ else if (&dummy_imports[0] == previous) {
+ return &dummy_imports[1];
+ }
+ else if (&dummy_imports[1] == previous) {
+ return NULL;
+ }
} /* DummyImports */
static const PRVersionInfo *DummyLibVersion(void)
@@ -113,7 +122,9 @@ int main(int argc, char **argv)
printf("Depend.c build time is %s %s\n", buildDate, buildTime);
- if (NULL != info) ChaseDependents(info, tab);
+ if (NULL != info) {
+ ChaseDependents(info, tab);
+ }
return 0;
} /* main */
diff --git a/pr/tests/dlltest.c b/pr/tests/dlltest.c
index aec632ff..d6873228 100644
--- a/pr/tests/dlltest.c
+++ b/pr/tests/dlltest.c
@@ -11,12 +11,12 @@
**
** Modification History:
** 14-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.
** 12-June-97 Revert to return code 0 and 1.
***********************************************************************/
@@ -61,7 +61,9 @@ int main(int argc, char** argv)
*/
libName = PR_GetLibraryName("dll", "my");
- if (debug_mode) printf("Loading library %s\n", libName);
+ if (debug_mode) {
+ printf("Loading library %s\n", libName);
+ }
lib = PR_LoadLibrary(libName);
PR_FreeLibraryName(libName);
if (lib == NULL) {
@@ -72,7 +74,9 @@ int main(int argc, char** argv)
fprintf(
stderr, "PR_LoadLibrary failed (%d, %d, %s)\n",
PR_GetError(), PR_GetOSError(), text);
- if (!debug_mode) failed_already=1;
+ if (!debug_mode) {
+ failed_already=1;
+ }
}
getFcn = (GetFcnType) PR_FindSymbol(lib, "My_GetValue");
setFcn = (SetFcnType) PR_FindFunctionSymbol(lib, "My_SetValue");
@@ -80,9 +84,13 @@ int main(int argc, char** argv)
value = (*getFcn)();
if (value != 888) {
fprintf(stderr, "Test 1 failed: set value to 888, but got %d\n", value);
- if (!debug_mode) failed_already=1;
+ if (!debug_mode) {
+ failed_already=1;
+ }
+ }
+ if (debug_mode) {
+ printf("Test 1 passed\n");
}
- if (debug_mode) printf("Test 1 passed\n");
/*
* Test 2: get a second handle to the same library (this should increment
@@ -93,24 +101,32 @@ int main(int argc, char** argv)
getFcn = (GetFcnType) PR_FindSymbolAndLibrary("My_GetValue", &lib2);
if (NULL == getFcn || lib != lib2) {
fprintf(stderr, "Test 2 failed: handles for the same library are not "
- "equal: handle 1: %p, handle 2: %p\n", lib, lib2);
- if (!debug_mode) failed_already=1;
+ "equal: handle 1: %p, handle 2: %p\n", lib, lib2);
+ if (!debug_mode) {
+ failed_already=1;
+ }
}
setFcn = (SetFcnType) PR_FindSymbol(lib2, "My_SetValue");
value = (*getFcn)();
if (value != 888) {
fprintf(stderr, "Test 2 failed: value should be 888, but got %d\n",
- value);
- if (!debug_mode) failed_already=1;
+ value);
+ if (!debug_mode) {
+ failed_already=1;
+ }
}
(*setFcn)(777);
value = (*getFcn)();
if (value != 777) {
fprintf(stderr, "Test 2 failed: set value to 777, but got %d\n", value);
- if (!debug_mode) failed_already=1;
+ if (!debug_mode) {
+ failed_already=1;
+ }
goto exit_now;
}
- if (debug_mode) printf("Test 2 passed\n");
+ if (debug_mode) {
+ printf("Test 2 passed\n");
+ }
/*
* Test 3: unload the library. The library should still be accessible
@@ -120,8 +136,10 @@ int main(int argc, char** argv)
status = PR_UnloadLibrary(lib);
if (PR_FAILURE == status) {
fprintf(stderr, "Test 3 failed: cannot unload library: (%d, %d)\n",
- PR_GetError(), PR_GetOSError());
- if (!debug_mode) failed_already=1;
+ PR_GetError(), PR_GetOSError());
+ if (!debug_mode) {
+ failed_already=1;
+ }
goto exit_now;
}
getFcn = (GetFcnType) PR_FindFunctionSymbol(lib2, "My_GetValue");
@@ -130,10 +148,14 @@ int main(int argc, char** argv)
value = (*getFcn)();
if (value != 666) {
fprintf(stderr, "Test 3 failed: set value to 666, but got %d\n", value);
- if (!debug_mode) failed_already=1;
+ if (!debug_mode) {
+ failed_already=1;
+ }
goto exit_now;
}
- if (debug_mode) printf("Test 3 passed\n");
+ if (debug_mode) {
+ printf("Test 3 passed\n");
+ }
/*
* Test 4: unload the library, testing the reference count mechanism.
@@ -142,15 +164,19 @@ int main(int argc, char** argv)
status = PR_UnloadLibrary(lib2);
if (PR_FAILURE == status) {
fprintf(stderr, "Test 4 failed: cannot unload library: (%d, %d)\n",
- PR_GetError(), PR_GetOSError());
- if (!debug_mode) failed_already=1;
+ PR_GetError(), PR_GetOSError());
+ if (!debug_mode) {
+ failed_already=1;
+ }
goto exit_now;
}
getFcn = (GetFcnType) PR_FindFunctionSymbolAndLibrary("My_GetValue", &lib2);
if (NULL != getFcn) {
fprintf(stderr, "Test 4 failed: how can we find a symbol "
- "in an already unloaded library?\n");
- if (!debug_mode) failed_already=1;
+ "in an already unloaded library?\n");
+ if (!debug_mode) {
+ failed_already=1;
+ }
goto exit_now;
}
if (debug_mode) {
diff --git a/pr/tests/dtoa.c b/pr/tests/dtoa.c
index a33c5c56..ef2e4dc4 100644
--- a/pr/tests/dtoa.c
+++ b/pr/tests/dtoa.c
@@ -34,104 +34,104 @@ int main(int argc, char **argv)
num = 1e24;
num1 = PR_strtod("1e24",NULL);
- if(num1 != num){
- fprintf(stderr,"Failed to convert numeric value %s\n","1e24");
+ if(num1 != num) {
+ fprintf(stderr,"Failed to convert numeric value %s\n","1e24");
failed_already = 1;
}
PR_cnvtf(cnvt,sizeof(cnvt),20,num);
- if(strcmp("1e+24",cnvt) != 0){
- fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
+ if(strcmp("1e+24",cnvt) != 0) {
+ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
failed_already = 1;
}
num = 0.001e7;
num1 = PR_strtod("0.001e7",NULL);
- if(num1 != num){
- fprintf(stderr,"Failed to convert numeric value %s\n","0.001e7");
+ if(num1 != num) {
+ fprintf(stderr,"Failed to convert numeric value %s\n","0.001e7");
failed_already = 1;
}
PR_cnvtf(cnvt,sizeof(cnvt),20,num);
- if(strcmp("10000",cnvt) != 0){
- fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
+ if(strcmp("10000",cnvt) != 0) {
+ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
failed_already = 1;
}
num = 0.0000000000000753;
num1 = PR_strtod("0.0000000000000753",NULL);
- if(num1 != num){
- fprintf(stderr,"Failed to convert numeric value %s\n",
- "0.0000000000000753");
+ if(num1 != num) {
+ fprintf(stderr,"Failed to convert numeric value %s\n",
+ "0.0000000000000753");
failed_already = 1;
}
PR_cnvtf(cnvt,sizeof(cnvt),20,num);
- if(strcmp("7.53e-14",cnvt) != 0){
- fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
+ if(strcmp("7.53e-14",cnvt) != 0) {
+ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
failed_already = 1;
}
num = 1.867e73;
num1 = PR_strtod("1.867e73",NULL);
- if(num1 != num){
- fprintf(stderr,"Failed to convert numeric value %s\n","1.867e73");
+ if(num1 != num) {
+ fprintf(stderr,"Failed to convert numeric value %s\n","1.867e73");
failed_already = 1;
}
PR_cnvtf(cnvt,sizeof(cnvt),20,num);
- if(strcmp("1.867e+73",cnvt) != 0){
- fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
+ if(strcmp("1.867e+73",cnvt) != 0) {
+ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
failed_already = 1;
}
num = -1.867e73;
num1 = PR_strtod("-1.867e73",NULL);
- if(num1 != num){
- fprintf(stderr,"Failed to convert numeric value %s\n","-1.867e73");
+ if(num1 != num) {
+ fprintf(stderr,"Failed to convert numeric value %s\n","-1.867e73");
failed_already = 1;
}
PR_cnvtf(cnvt,sizeof(cnvt),20,num);
- if(strcmp("-1.867e+73",cnvt) != 0){
- fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
+ if(strcmp("-1.867e+73",cnvt) != 0) {
+ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
failed_already = 1;
}
num = -1.867e-73;
num1 = PR_strtod("-1.867e-73",NULL);
- if(num1 != num){
- fprintf(stderr,"Failed to convert numeric value %s\n","-1.867e-73");
+ if(num1 != num) {
+ fprintf(stderr,"Failed to convert numeric value %s\n","-1.867e-73");
failed_already = 1;
}
PR_cnvtf(cnvt,sizeof(cnvt),20,num);
- if(strcmp("-1.867e-73",cnvt) != 0){
- fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
+ if(strcmp("-1.867e-73",cnvt) != 0) {
+ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
failed_already = 1;
}
/* Testing for infinity */
num = 1.0 / zero;
num1 = PR_strtod("1.867e765",NULL);
- if(num1 != num){
- fprintf(stderr,"Failed to convert numeric value %s\n","1.867e765");
+ if(num1 != num) {
+ fprintf(stderr,"Failed to convert numeric value %s\n","1.867e765");
failed_already = 1;
}
PR_cnvtf(cnvt,sizeof(cnvt),20,num);
- if(strcmp("Infinity",cnvt) != 0){
- fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
+ if(strcmp("Infinity",cnvt) != 0) {
+ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
failed_already = 1;
}
num = -1.0 / zero;
num1 = PR_strtod("-1.867e765",NULL);
- if(num1 != num){
- fprintf(stderr,"Failed to convert numeric value %s\n","-1.867e765");
+ if(num1 != num) {
+ fprintf(stderr,"Failed to convert numeric value %s\n","-1.867e765");
failed_already = 1;
}
PR_cnvtf(cnvt,sizeof(cnvt),20,num);
- if(strcmp("-Infinity",cnvt) != 0){
- fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
+ if(strcmp("-Infinity",cnvt) != 0) {
+ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
failed_already = 1;
}
@@ -139,42 +139,42 @@ int main(int argc, char **argv)
num = zero / zero;
PR_cnvtf(cnvt,sizeof(cnvt),20,num);
- if(strcmp("NaN",cnvt) != 0){
- fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
+ if(strcmp("NaN",cnvt) != 0) {
+ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
failed_already = 1;
}
num = - zero / zero;
PR_cnvtf(cnvt,sizeof(cnvt),20,num);
- if(strcmp("NaN",cnvt) != 0){
- fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
+ if(strcmp("NaN",cnvt) != 0) {
+ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
failed_already = 1;
}
num = 1.0000000001e21;
num1 = PR_strtod("1.0000000001e21",NULL);
- if(num1 != num){
- fprintf(stderr,"Failed to convert numeric value %s\n",
- "1.0000000001e21");
+ if(num1 != num) {
+ fprintf(stderr,"Failed to convert numeric value %s\n",
+ "1.0000000001e21");
failed_already = 1;
}
PR_cnvtf(cnvt,sizeof(cnvt),20,num);
- if(strcmp("1.0000000001e+21",cnvt) != 0){
- fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
+ if(strcmp("1.0000000001e+21",cnvt) != 0) {
+ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
failed_already = 1;
}
num = -1.0000000001e-21;
num1 = PR_strtod("-1.0000000001e-21",NULL);
- if(num1 != num){
- fprintf(stderr,"Failed to convert numeric value %s\n",
- "-1.0000000001e-21");
+ if(num1 != num) {
+ fprintf(stderr,"Failed to convert numeric value %s\n",
+ "-1.0000000001e-21");
failed_already = 1;
}
PR_cnvtf(cnvt,sizeof(cnvt),20,num);
- if(strcmp("-1.0000000001e-21",cnvt) != 0){
- fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
+ if(strcmp("-1.0000000001e-21",cnvt) != 0) {
+ fprintf(stderr,"Failed to convert numeric value %lf %s\n",num,cnvt);
failed_already = 1;
}
@@ -198,7 +198,7 @@ int main(int argc, char **argv)
num = 0;
num1 = PR_strtod(thousands,NULL);
free(thousands);
- if(num1 != num){
+ if(num1 != num) {
fprintf(stderr,"Failed to convert numeric value %s\n",
"0.1111111111111111...");
failed_already = 1;
diff --git a/pr/tests/env.c b/pr/tests/env.c
index 5da05b60..17b0eeb9 100644
--- a/pr/tests/env.c
+++ b/pr/tests/env.c
@@ -46,31 +46,33 @@ int main(int argc, char **argv)
PLOptStatus os;
PLOptState *opt = PL_CreateOptState(argc, argv, "vds");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ 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 */
- debug = 1;
- break;
- case 'v': /* verbose */
- verbose = 1;
- break;
- case 's': /* secure / set[ug]id */
- /*
- ** To test PR_GetEnvSecure, make this executable (or a
- ** copy of it) setuid / setgid / otherwise inherently
- ** privileged (e.g., file capabilities) and run it
- ** with this flag.
- */
- secure = 1;
- break;
- default:
- break;
+ case 'd': /* debug */
+ debug = 1;
+ break;
+ case 'v': /* verbose */
+ verbose = 1;
+ break;
+ case 's': /* secure / set[ug]id */
+ /*
+ ** To test PR_GetEnvSecure, make this executable (or a
+ ** copy of it) setuid / setgid / otherwise inherently
+ ** privileged (e.g., file capabilities) and run it
+ ** with this flag.
+ */
+ secure = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
} /* end block "Get command line options" */
#if 0
@@ -83,24 +85,36 @@ int main(int argc, char **argv)
DWORD size;
rv = SetEnvironmentVariable( ENVNAME, ENVVALUE );
if ( rv == 0 ) {
- if (debug) printf("env: Shit! SetEnvironmentVariable() failed\n");
+ if (debug) {
+ printf("env: Shit! SetEnvironmentVariable() failed\n");
+ }
failedAlready = PR_TRUE;
}
- if (verbose) printf("env: SetEnvironmentVariable() worked\n");
+ if (verbose) {
+ printf("env: SetEnvironmentVariable() worked\n");
+ }
size = GetEnvironmentVariable( ENVNAME, envBuf, ENVBUFSIZE );
if ( size == 0 ) {
- if (debug) printf("env: Shit! GetEnvironmentVariable() failed. Found: %s\n", envBuf );
+ if (debug) {
+ printf("env: Shit! GetEnvironmentVariable() failed. Found: %s\n", envBuf );
+ }
failedAlready = PR_TRUE;
}
- if (verbose) printf("env: GetEnvironmentVariable() worked. Found: %s\n", envBuf);
+ if (verbose) {
+ printf("env: GetEnvironmentVariable() worked. Found: %s\n", envBuf);
+ }
value = PR_GetEnv( ENVNAME );
if ( (NULL == value ) || (strcmp( value, ENVVALUE))) {
- if (debug) printf( "env: PR_GetEnv() failed retrieving WinNative. Found: %s\n", value);
+ if (debug) {
+ printf( "env: PR_GetEnv() failed retrieving WinNative. Found: %s\n", value);
+ }
failedAlready = PR_TRUE;
}
- if (verbose) printf("env: PR_GetEnv() worked. Found: %s\n", value);
+ if (verbose) {
+ printf("env: PR_GetEnv() worked. Found: %s\n", value);
+ }
}
#endif
@@ -109,18 +123,26 @@ int main(int argc, char **argv)
sprintf( envBuf, ENVNAME "=" ENVVALUE );
rc = PR_SetEnv( envBuf );
if ( PR_FAILURE == rc ) {
- if (debug) printf( "env: PR_SetEnv() failed setting\n");
+ if (debug) {
+ printf( "env: PR_SetEnv() failed setting\n");
+ }
failedAlready = PR_TRUE;
} else {
- if (verbose) printf("env: PR_SetEnv() worked.\n");
+ if (verbose) {
+ printf("env: PR_SetEnv() worked.\n");
+ }
}
value = PR_GetEnv( ENVNAME );
if ( (NULL == value ) || (strcmp( value, ENVVALUE))) {
- if (debug) printf( "env: PR_GetEnv() Failed after setting\n" );
+ if (debug) {
+ printf( "env: PR_GetEnv() Failed after setting\n" );
+ }
failedAlready = PR_TRUE;
} else {
- if (verbose) printf("env: PR_GetEnv() worked after setting it. Found: %s\n", value );
+ if (verbose) {
+ printf("env: PR_GetEnv() worked after setting it. Found: %s\n", value );
+ }
}
if ( secure ) {
@@ -130,10 +152,14 @@ int main(int argc, char **argv)
*/
value = PR_GetEnvSecure( ENVNAME );
if ( NULL != value ) {
- if (debug) printf( "env: PR_GetEnvSecure() failed; expected NULL, found \"%s\"\n", value );
+ if (debug) {
+ printf( "env: PR_GetEnvSecure() failed; expected NULL, found \"%s\"\n", value );
+ }
failedAlready = PR_TRUE;
} else {
- if (verbose) printf("env: PR_GetEnvSecure() worked\n" );
+ if (verbose) {
+ printf("env: PR_GetEnvSecure() worked\n" );
+ }
}
} else {
/*
@@ -142,14 +168,18 @@ int main(int argc, char **argv)
*/
value = PR_GetEnvSecure( ENVNAME );
if ( (NULL == value ) || (strcmp( value, ENVVALUE))) {
- if (debug) printf( "env: PR_GetEnvSecure() Failed after setting\n" );
+ if (debug) {
+ printf( "env: PR_GetEnvSecure() Failed after setting\n" );
+ }
failedAlready = PR_TRUE;
} else {
- if (verbose) printf("env: PR_GetEnvSecure() worked after setting it. Found: %s\n", value );
+ if (verbose) {
+ printf("env: PR_GetEnvSecure() worked after setting it. Found: %s\n", value );
+ }
}
}
-/* ---------------------------------------------------------------------- */
+ /* ---------------------------------------------------------------------- */
/* check that PR_DuplicateEnvironment() agrees with PR_GetEnv() */
{
#if defined(XP_UNIX) && (!defined(DARWIN) || defined(HAVE_CRT_EXTERNS_H))
@@ -163,9 +193,11 @@ int main(int argc, char **argv)
if ( NULL == dupenv ) {
if (expect_failure) {
if (verbose) printf("env: PR_DuplicateEnvironment failed, "
- "as expected on this platform.\n");
+ "as expected on this platform.\n");
} else {
- if (debug) printf("env: PR_DuplicateEnvironment() failed.\n");
+ if (debug) {
+ printf("env: PR_DuplicateEnvironment() failed.\n");
+ }
failedAlready = PR_TRUE;
}
} else {
@@ -173,17 +205,19 @@ int main(int argc, char **argv)
if (expect_failure) {
if (debug) printf("env: PR_DuplicateEnvironment() succeeded, "
- "but failure is expected on this platform.\n");
+ "but failure is expected on this platform.\n");
failedAlready = PR_TRUE;
} else {
- if (verbose) printf("env: PR_DuplicateEnvironment() succeeded.\n");
+ if (verbose) {
+ printf("env: PR_DuplicateEnvironment() succeeded.\n");
+ }
}
for (i = dupenv; *i; i++) {
char *equals = strchr(*i, '=');
if ( equals == NULL ) {
if (debug) printf("env: PR_DuplicateEnvironment() returned a string"
- " with no '=': %s\n", *i);
+ " with no '=': %s\n", *i);
failedAlready = PR_TRUE;
} else {
/* We own this string, so we can temporarily alter it */
@@ -193,23 +227,23 @@ int main(int argc, char **argv)
if ( strcmp(*i, ENVNAME) == 0) {
found++;
if (verbose) printf("env: PR_DuplicateEnvironment() found " ENVNAME
- " (%u so far).\n", found);
+ " (%u so far).\n", found);
}
/* Multiple values for the same name can't happen, according to POSIX. */
value = PR_GetEnv(*i);
if ( value == NULL ) {
if (debug) printf("env: PR_DuplicateEnvironment() returned a name"
- " which PR_GetEnv() failed to find: %s\n", *i);
+ " which PR_GetEnv() failed to find: %s\n", *i);
failedAlready = PR_TRUE;
} else if ( strcmp(equals + 1, value) != 0) {
if (debug) printf("env: PR_DuplicateEnvironment() returned the wrong"
- " value for %s: expected %s; found %s\n",
- *i, value, equals + 1);
+ " value for %s: expected %s; found %s\n",
+ *i, value, equals + 1);
failedAlready = PR_TRUE;
} else {
if (verbose) printf("env: PR_DuplicateEnvironment() agreed with"
- " PR_GetEnv() about %s\n", *i);
+ " PR_GetEnv() about %s\n", *i);
}
}
PR_Free(*i);
@@ -218,44 +252,58 @@ int main(int argc, char **argv)
if (found != 1) {
if (debug) printf("env: PR_DuplicateEnvironment() found %u entries for " ENVNAME
- " (expected 1)\n", found);
+ " (expected 1)\n", found);
failedAlready = PR_TRUE;
} else {
- if (verbose) printf("env: PR_DuplicateEnvironment() found 1 entry for " ENVNAME "\n");
+ if (verbose) {
+ printf("env: PR_DuplicateEnvironment() found 1 entry for " ENVNAME "\n");
+ }
}
}
}
-/* ---------------------------------------------------------------------- */
+ /* ---------------------------------------------------------------------- */
/* un-set the variable, using RAW name... should not work */
envBuf = NewBuffer( ENVBUFSIZE );
sprintf( envBuf, ENVNAME );
rc = PR_SetEnv( envBuf );
if ( PR_FAILURE == rc ) {
- if (verbose) printf( "env: PR_SetEnv() not un-set using RAW name. Good!\n");
+ if (verbose) {
+ printf( "env: PR_SetEnv() not un-set using RAW name. Good!\n");
+ }
} else {
- if (debug) printf("env: PR_SetEnv() un-set using RAW name. Bad!\n" );
+ if (debug) {
+ printf("env: PR_SetEnv() un-set using RAW name. Bad!\n" );
+ }
failedAlready = PR_TRUE;
}
value = PR_GetEnv( ENVNAME );
if ( NULL == value ) {
- if (debug) printf("env: PR_GetEnv() after un-set using RAW name. Bad!\n" );
+ if (debug) {
+ printf("env: PR_GetEnv() after un-set using RAW name. Bad!\n" );
+ }
failedAlready = PR_TRUE;
} else {
- if (verbose) printf( "env: PR_GetEnv() after RAW un-set found: %s\n", value );
+ if (verbose) {
+ printf( "env: PR_GetEnv() after RAW un-set found: %s\n", value );
+ }
}
-/* ---------------------------------------------------------------------- */
+ /* ---------------------------------------------------------------------- */
/* set it again ... */
envBuf = NewBuffer( ENVBUFSIZE );
sprintf( envBuf, ENVNAME "=" ENVVALUE );
rc = PR_SetEnv( envBuf );
if ( PR_FAILURE == rc ) {
- if (debug) printf( "env: PR_SetEnv() failed setting the second time.\n");
+ if (debug) {
+ printf( "env: PR_SetEnv() failed setting the second time.\n");
+ }
failedAlready = PR_TRUE;
} else {
- if (verbose) printf("env: PR_SetEnv() worked.\n");
+ if (verbose) {
+ printf("env: PR_SetEnv() worked.\n");
+ }
}
/* un-set the variable using the form name= */
@@ -263,41 +311,59 @@ int main(int argc, char **argv)
sprintf( envBuf, ENVNAME "=" );
rc = PR_SetEnv( envBuf );
if ( PR_FAILURE == rc ) {
- if (debug) printf( "env: PR_SetEnv() failed un-setting using name=\n");
+ if (debug) {
+ printf( "env: PR_SetEnv() failed un-setting using name=\n");
+ }
failedAlready = PR_TRUE;
} else {
- if (verbose) printf("env: PR_SetEnv() un-set using name= worked\n" );
+ if (verbose) {
+ printf("env: PR_SetEnv() un-set using name= worked\n" );
+ }
}
value = PR_GetEnv( ENVNAME );
if (( NULL == value ) || ( 0x00 == *value )) {
- if (verbose) printf("env: PR_GetEnv() after un-set using name= worked\n" );
+ if (verbose) {
+ printf("env: PR_GetEnv() after un-set using name= worked\n" );
+ }
} else {
- if (debug) printf( "env: PR_GetEnv() after un-set using name=. Found: %s\n", value );
+ if (debug) {
+ printf( "env: PR_GetEnv() after un-set using name=. Found: %s\n", value );
+ }
failedAlready = PR_TRUE;
}
-/* ---------------------------------------------------------------------- */
+ /* ---------------------------------------------------------------------- */
/* un-set the variable using the form name= */
envBuf = NewBuffer( ENVBUFSIZE );
sprintf( envBuf, ENVNAME "999=" );
rc = PR_SetEnv( envBuf );
if ( PR_FAILURE == rc ) {
- if (debug) printf( "env: PR_SetEnv() failed un-setting using name=\n");
+ if (debug) {
+ printf( "env: PR_SetEnv() failed un-setting using name=\n");
+ }
failedAlready = PR_TRUE;
} else {
- if (verbose) printf("env: PR_SetEnv() un-set using name= worked\n" );
+ if (verbose) {
+ printf("env: PR_SetEnv() un-set using name= worked\n" );
+ }
}
value = PR_GetEnv( ENVNAME "999" );
if (( NULL == value ) || ( 0x00 == *value )) {
- if (verbose) printf("env: PR_GetEnv() after un-set using name= worked\n" );
+ if (verbose) {
+ printf("env: PR_GetEnv() after un-set using name= worked\n" );
+ }
} else {
- if (debug) printf( "env: PR_GetEnv() after un-set using name=. Found: %s\n", value );
+ if (debug) {
+ printf( "env: PR_GetEnv() after un-set using name=. Found: %s\n", value );
+ }
failedAlready = PR_TRUE;
}
-/* ---------------------------------------------------------------------- */
- if (debug || verbose) printf("\n%s\n", (failedAlready)? "FAILED" : "PASSED" );
+ /* ---------------------------------------------------------------------- */
+ if (debug || verbose) {
+ printf("\n%s\n", (failedAlready)? "FAILED" : "PASSED" );
+ }
return( (failedAlready)? 1 : 0 );
} /* main() */
diff --git a/pr/tests/errcodes.c b/pr/tests/errcodes.c
index 2ef00b24..591b630b 100644
--- a/pr/tests/errcodes.c
+++ b/pr/tests/errcodes.c
@@ -18,90 +18,90 @@
static int _debug_on = 0;
struct errinfo {
- PRErrorCode errcode;
- char *errname;
+ PRErrorCode errcode;
+ char *errname;
};
struct errinfo errcodes[] = {
-{PR_OUT_OF_MEMORY_ERROR, "PR_OUT_OF_MEMORY_ERROR"},
-{PR_BAD_DESCRIPTOR_ERROR, "PR_BAD_DESCRIPTOR_ERROR"},
-{PR_WOULD_BLOCK_ERROR, "PR_WOULD_BLOCK_ERROR"},
-{PR_ACCESS_FAULT_ERROR, "PR_ACCESS_FAULT_ERROR"},
-{PR_INVALID_METHOD_ERROR, "PR_INVALID_METHOD_ERROR"},
-{PR_ILLEGAL_ACCESS_ERROR, "PR_ILLEGAL_ACCESS_ERROR"},
-{PR_UNKNOWN_ERROR, "PR_UNKNOWN_ERROR"},
-{PR_PENDING_INTERRUPT_ERROR, "PR_PENDING_INTERRUPT_ERROR"},
-{PR_NOT_IMPLEMENTED_ERROR, "PR_NOT_IMPLEMENTED_ERROR"},
-{PR_IO_ERROR, "PR_IO_ERROR"},
-{PR_IO_TIMEOUT_ERROR, "PR_IO_TIMEOUT_ERROR"},
-{PR_IO_PENDING_ERROR, "PR_IO_PENDING_ERROR"},
-{PR_DIRECTORY_OPEN_ERROR, "PR_DIRECTORY_OPEN_ERROR"},
-{PR_INVALID_ARGUMENT_ERROR, "PR_INVALID_ARGUMENT_ERROR"},
-{PR_ADDRESS_NOT_AVAILABLE_ERROR, "PR_ADDRESS_NOT_AVAILABLE_ERROR"},
-{PR_ADDRESS_NOT_SUPPORTED_ERROR, "PR_ADDRESS_NOT_SUPPORTED_ERROR"},
-{PR_IS_CONNECTED_ERROR, "PR_IS_CONNECTED_ERROR"},
-{PR_BAD_ADDRESS_ERROR, "PR_BAD_ADDRESS_ERROR"},
-{PR_ADDRESS_IN_USE_ERROR, "PR_ADDRESS_IN_USE_ERROR"},
-{PR_CONNECT_REFUSED_ERROR, "PR_CONNECT_REFUSED_ERROR"},
-{PR_NETWORK_UNREACHABLE_ERROR, "PR_NETWORK_UNREACHABLE_ERROR"},
-{PR_CONNECT_TIMEOUT_ERROR, "PR_CONNECT_TIMEOUT_ERROR"},
-{PR_NOT_CONNECTED_ERROR, "PR_NOT_CONNECTED_ERROR"},
-{PR_LOAD_LIBRARY_ERROR, "PR_LOAD_LIBRARY_ERROR"},
-{PR_UNLOAD_LIBRARY_ERROR, "PR_UNLOAD_LIBRARY_ERROR"},
-{PR_FIND_SYMBOL_ERROR, "PR_FIND_SYMBOL_ERROR"},
-{PR_INSUFFICIENT_RESOURCES_ERROR, "PR_INSUFFICIENT_RESOURCES_ERROR"},
-{PR_DIRECTORY_LOOKUP_ERROR, "PR_DIRECTORY_LOOKUP_ERROR"},
-{PR_TPD_RANGE_ERROR, "PR_TPD_RANGE_ERROR"},
-{PR_PROC_DESC_TABLE_FULL_ERROR, "PR_PROC_DESC_TABLE_FULL_ERROR"},
-{PR_SYS_DESC_TABLE_FULL_ERROR, "PR_SYS_DESC_TABLE_FULL_ERROR"},
-{PR_NOT_SOCKET_ERROR, "PR_NOT_SOCKET_ERROR"},
-{PR_NOT_TCP_SOCKET_ERROR, "PR_NOT_TCP_SOCKET_ERROR"},
-{PR_SOCKET_ADDRESS_IS_BOUND_ERROR, "PR_SOCKET_ADDRESS_IS_BOUND_ERROR"},
-{PR_NO_ACCESS_RIGHTS_ERROR, "PR_NO_ACCESS_RIGHTS_ERROR"},
-{PR_OPERATION_NOT_SUPPORTED_ERROR, "PR_OPERATION_NOT_SUPPORTED_ERROR"},
-{PR_PROTOCOL_NOT_SUPPORTED_ERROR, "PR_PROTOCOL_NOT_SUPPORTED_ERROR"},
-{PR_REMOTE_FILE_ERROR, "PR_REMOTE_FILE_ERROR"},
-{PR_BUFFER_OVERFLOW_ERROR, "PR_BUFFER_OVERFLOW_ERROR"},
-{PR_CONNECT_RESET_ERROR, "PR_CONNECT_RESET_ERROR"},
-{PR_RANGE_ERROR, "PR_RANGE_ERROR"},
-{PR_DEADLOCK_ERROR, "PR_DEADLOCK_ERROR"},
-{PR_FILE_IS_LOCKED_ERROR, "PR_FILE_IS_LOCKED_ERROR"},
-{PR_FILE_TOO_BIG_ERROR, "PR_FILE_TOO_BIG_ERROR"},
-{PR_NO_DEVICE_SPACE_ERROR, "PR_NO_DEVICE_SPACE_ERROR"},
-{PR_PIPE_ERROR, "PR_PIPE_ERROR"},
-{PR_NO_SEEK_DEVICE_ERROR, "PR_NO_SEEK_DEVICE_ERROR"},
-{PR_IS_DIRECTORY_ERROR, "PR_IS_DIRECTORY_ERROR"},
-{PR_LOOP_ERROR, "PR_LOOP_ERROR"},
-{PR_NAME_TOO_LONG_ERROR, "PR_NAME_TOO_LONG_ERROR"},
-{PR_FILE_NOT_FOUND_ERROR, "PR_FILE_NOT_FOUND_ERROR"},
-{PR_NOT_DIRECTORY_ERROR, "PR_NOT_DIRECTORY_ERROR"},
-{PR_READ_ONLY_FILESYSTEM_ERROR, "PR_READ_ONLY_FILESYSTEM_ERROR"},
-{PR_DIRECTORY_NOT_EMPTY_ERROR, "PR_DIRECTORY_NOT_EMPTY_ERROR"},
-{PR_FILESYSTEM_MOUNTED_ERROR, "PR_FILESYSTEM_MOUNTED_ERROR"},
-{PR_NOT_SAME_DEVICE_ERROR, "PR_NOT_SAME_DEVICE_ERROR"},
-{PR_DIRECTORY_CORRUPTED_ERROR, "PR_DIRECTORY_CORRUPTED_ERROR"},
-{PR_FILE_EXISTS_ERROR, "PR_FILE_EXISTS_ERROR"},
-{PR_MAX_DIRECTORY_ENTRIES_ERROR, "PR_MAX_DIRECTORY_ENTRIES_ERROR"},
-{PR_INVALID_DEVICE_STATE_ERROR, "PR_INVALID_DEVICE_STATE_ERROR"},
-{PR_DEVICE_IS_LOCKED_ERROR, "PR_DEVICE_IS_LOCKED_ERROR"},
-{PR_NO_MORE_FILES_ERROR, "PR_NO_MORE_FILES_ERROR"},
-{PR_END_OF_FILE_ERROR, "PR_END_OF_FILE_ERROR"},
-{PR_FILE_SEEK_ERROR, "PR_FILE_SEEK_ERROR"},
-{PR_FILE_IS_BUSY_ERROR, "PR_FILE_IS_BUSY_ERROR"},
-{PR_IN_PROGRESS_ERROR, "PR_IN_PROGRESS_ERROR"},
-{PR_ALREADY_INITIATED_ERROR, "PR_ALREADY_INITIATED_ERROR"},
-{PR_GROUP_EMPTY_ERROR, "PR_GROUP_EMPTY_ERROR"},
-{PR_INVALID_STATE_ERROR, "PR_INVALID_STATE_ERROR"},
-{PR_NETWORK_DOWN_ERROR, "PR_NETWORK_DOWN_ERROR"},
-{PR_SOCKET_SHUTDOWN_ERROR, "PR_SOCKET_SHUTDOWN_ERROR"},
-{PR_CONNECT_ABORTED_ERROR, "PR_CONNECT_ABORTED_ERROR"},
-{PR_HOST_UNREACHABLE_ERROR, "PR_HOST_UNREACHABLE_ERROR"}
+ {PR_OUT_OF_MEMORY_ERROR, "PR_OUT_OF_MEMORY_ERROR"},
+ {PR_BAD_DESCRIPTOR_ERROR, "PR_BAD_DESCRIPTOR_ERROR"},
+ {PR_WOULD_BLOCK_ERROR, "PR_WOULD_BLOCK_ERROR"},
+ {PR_ACCESS_FAULT_ERROR, "PR_ACCESS_FAULT_ERROR"},
+ {PR_INVALID_METHOD_ERROR, "PR_INVALID_METHOD_ERROR"},
+ {PR_ILLEGAL_ACCESS_ERROR, "PR_ILLEGAL_ACCESS_ERROR"},
+ {PR_UNKNOWN_ERROR, "PR_UNKNOWN_ERROR"},
+ {PR_PENDING_INTERRUPT_ERROR, "PR_PENDING_INTERRUPT_ERROR"},
+ {PR_NOT_IMPLEMENTED_ERROR, "PR_NOT_IMPLEMENTED_ERROR"},
+ {PR_IO_ERROR, "PR_IO_ERROR"},
+ {PR_IO_TIMEOUT_ERROR, "PR_IO_TIMEOUT_ERROR"},
+ {PR_IO_PENDING_ERROR, "PR_IO_PENDING_ERROR"},
+ {PR_DIRECTORY_OPEN_ERROR, "PR_DIRECTORY_OPEN_ERROR"},
+ {PR_INVALID_ARGUMENT_ERROR, "PR_INVALID_ARGUMENT_ERROR"},
+ {PR_ADDRESS_NOT_AVAILABLE_ERROR, "PR_ADDRESS_NOT_AVAILABLE_ERROR"},
+ {PR_ADDRESS_NOT_SUPPORTED_ERROR, "PR_ADDRESS_NOT_SUPPORTED_ERROR"},
+ {PR_IS_CONNECTED_ERROR, "PR_IS_CONNECTED_ERROR"},
+ {PR_BAD_ADDRESS_ERROR, "PR_BAD_ADDRESS_ERROR"},
+ {PR_ADDRESS_IN_USE_ERROR, "PR_ADDRESS_IN_USE_ERROR"},
+ {PR_CONNECT_REFUSED_ERROR, "PR_CONNECT_REFUSED_ERROR"},
+ {PR_NETWORK_UNREACHABLE_ERROR, "PR_NETWORK_UNREACHABLE_ERROR"},
+ {PR_CONNECT_TIMEOUT_ERROR, "PR_CONNECT_TIMEOUT_ERROR"},
+ {PR_NOT_CONNECTED_ERROR, "PR_NOT_CONNECTED_ERROR"},
+ {PR_LOAD_LIBRARY_ERROR, "PR_LOAD_LIBRARY_ERROR"},
+ {PR_UNLOAD_LIBRARY_ERROR, "PR_UNLOAD_LIBRARY_ERROR"},
+ {PR_FIND_SYMBOL_ERROR, "PR_FIND_SYMBOL_ERROR"},
+ {PR_INSUFFICIENT_RESOURCES_ERROR, "PR_INSUFFICIENT_RESOURCES_ERROR"},
+ {PR_DIRECTORY_LOOKUP_ERROR, "PR_DIRECTORY_LOOKUP_ERROR"},
+ {PR_TPD_RANGE_ERROR, "PR_TPD_RANGE_ERROR"},
+ {PR_PROC_DESC_TABLE_FULL_ERROR, "PR_PROC_DESC_TABLE_FULL_ERROR"},
+ {PR_SYS_DESC_TABLE_FULL_ERROR, "PR_SYS_DESC_TABLE_FULL_ERROR"},
+ {PR_NOT_SOCKET_ERROR, "PR_NOT_SOCKET_ERROR"},
+ {PR_NOT_TCP_SOCKET_ERROR, "PR_NOT_TCP_SOCKET_ERROR"},
+ {PR_SOCKET_ADDRESS_IS_BOUND_ERROR, "PR_SOCKET_ADDRESS_IS_BOUND_ERROR"},
+ {PR_NO_ACCESS_RIGHTS_ERROR, "PR_NO_ACCESS_RIGHTS_ERROR"},
+ {PR_OPERATION_NOT_SUPPORTED_ERROR, "PR_OPERATION_NOT_SUPPORTED_ERROR"},
+ {PR_PROTOCOL_NOT_SUPPORTED_ERROR, "PR_PROTOCOL_NOT_SUPPORTED_ERROR"},
+ {PR_REMOTE_FILE_ERROR, "PR_REMOTE_FILE_ERROR"},
+ {PR_BUFFER_OVERFLOW_ERROR, "PR_BUFFER_OVERFLOW_ERROR"},
+ {PR_CONNECT_RESET_ERROR, "PR_CONNECT_RESET_ERROR"},
+ {PR_RANGE_ERROR, "PR_RANGE_ERROR"},
+ {PR_DEADLOCK_ERROR, "PR_DEADLOCK_ERROR"},
+ {PR_FILE_IS_LOCKED_ERROR, "PR_FILE_IS_LOCKED_ERROR"},
+ {PR_FILE_TOO_BIG_ERROR, "PR_FILE_TOO_BIG_ERROR"},
+ {PR_NO_DEVICE_SPACE_ERROR, "PR_NO_DEVICE_SPACE_ERROR"},
+ {PR_PIPE_ERROR, "PR_PIPE_ERROR"},
+ {PR_NO_SEEK_DEVICE_ERROR, "PR_NO_SEEK_DEVICE_ERROR"},
+ {PR_IS_DIRECTORY_ERROR, "PR_IS_DIRECTORY_ERROR"},
+ {PR_LOOP_ERROR, "PR_LOOP_ERROR"},
+ {PR_NAME_TOO_LONG_ERROR, "PR_NAME_TOO_LONG_ERROR"},
+ {PR_FILE_NOT_FOUND_ERROR, "PR_FILE_NOT_FOUND_ERROR"},
+ {PR_NOT_DIRECTORY_ERROR, "PR_NOT_DIRECTORY_ERROR"},
+ {PR_READ_ONLY_FILESYSTEM_ERROR, "PR_READ_ONLY_FILESYSTEM_ERROR"},
+ {PR_DIRECTORY_NOT_EMPTY_ERROR, "PR_DIRECTORY_NOT_EMPTY_ERROR"},
+ {PR_FILESYSTEM_MOUNTED_ERROR, "PR_FILESYSTEM_MOUNTED_ERROR"},
+ {PR_NOT_SAME_DEVICE_ERROR, "PR_NOT_SAME_DEVICE_ERROR"},
+ {PR_DIRECTORY_CORRUPTED_ERROR, "PR_DIRECTORY_CORRUPTED_ERROR"},
+ {PR_FILE_EXISTS_ERROR, "PR_FILE_EXISTS_ERROR"},
+ {PR_MAX_DIRECTORY_ENTRIES_ERROR, "PR_MAX_DIRECTORY_ENTRIES_ERROR"},
+ {PR_INVALID_DEVICE_STATE_ERROR, "PR_INVALID_DEVICE_STATE_ERROR"},
+ {PR_DEVICE_IS_LOCKED_ERROR, "PR_DEVICE_IS_LOCKED_ERROR"},
+ {PR_NO_MORE_FILES_ERROR, "PR_NO_MORE_FILES_ERROR"},
+ {PR_END_OF_FILE_ERROR, "PR_END_OF_FILE_ERROR"},
+ {PR_FILE_SEEK_ERROR, "PR_FILE_SEEK_ERROR"},
+ {PR_FILE_IS_BUSY_ERROR, "PR_FILE_IS_BUSY_ERROR"},
+ {PR_IN_PROGRESS_ERROR, "PR_IN_PROGRESS_ERROR"},
+ {PR_ALREADY_INITIATED_ERROR, "PR_ALREADY_INITIATED_ERROR"},
+ {PR_GROUP_EMPTY_ERROR, "PR_GROUP_EMPTY_ERROR"},
+ {PR_INVALID_STATE_ERROR, "PR_INVALID_STATE_ERROR"},
+ {PR_NETWORK_DOWN_ERROR, "PR_NETWORK_DOWN_ERROR"},
+ {PR_SOCKET_SHUTDOWN_ERROR, "PR_SOCKET_SHUTDOWN_ERROR"},
+ {PR_CONNECT_ABORTED_ERROR, "PR_CONNECT_ABORTED_ERROR"},
+ {PR_HOST_UNREACHABLE_ERROR, "PR_HOST_UNREACHABLE_ERROR"}
};
int main(int argc, char **argv)
{
- int count, errnum;
+ int count, errnum;
/*
* -d debug mode
@@ -111,24 +111,26 @@ int main(int argc, char **argv)
PLOptState *opt = PL_CreateOptState(argc, argv, "d");
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_on = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ _debug_on = 1;
+ break;
+ default:
+ break;
}
}
PL_DestroyOptState(opt);
- count = sizeof(errcodes)/sizeof(errcodes[0]);
- printf("\nNumber of error codes = %d\n\n",count);
- for (errnum = 0; errnum < count; errnum++) {
- printf("%-40s = %d\n",errcodes[errnum].errname,
- errcodes[errnum].errcode);
- }
+ count = sizeof(errcodes)/sizeof(errcodes[0]);
+ printf("\nNumber of error codes = %d\n\n",count);
+ for (errnum = 0; errnum < count; errnum++) {
+ printf("%-40s = %d\n",errcodes[errnum].errname,
+ errcodes[errnum].errcode);
+ }
- return 0;
+ return 0;
}
diff --git a/pr/tests/errset.c b/pr/tests/errset.c
index b0e92487..fb76a6fa 100644
--- a/pr/tests/errset.c
+++ b/pr/tests/errset.c
@@ -25,91 +25,91 @@
static int _debug_on = 0;
struct errinfo {
- PRErrorCode errcode;
- char *errname;
+ PRErrorCode errcode;
+ char *errname;
};
struct errinfo errcodes[] = {
-{PR_OUT_OF_MEMORY_ERROR, "PR_OUT_OF_MEMORY_ERROR"},
-{PR_UNKNOWN_ERROR, "An intentionally long error message text intended to force a delete of the current errorString buffer and get another one."},
-{PR_BAD_DESCRIPTOR_ERROR, "PR_BAD_DESCRIPTOR_ERROR"},
-{PR_WOULD_BLOCK_ERROR, "PR_WOULD_BLOCK_ERROR"},
-{PR_ACCESS_FAULT_ERROR, "PR_ACCESS_FAULT_ERROR"},
-{PR_INVALID_METHOD_ERROR, "PR_INVALID_METHOD_ERROR"},
-{PR_ILLEGAL_ACCESS_ERROR, "PR_ILLEGAL_ACCESS_ERROR"},
-{PR_UNKNOWN_ERROR, "PR_UNKNOWN_ERROR"},
-{PR_PENDING_INTERRUPT_ERROR, "PR_PENDING_INTERRUPT_ERROR"},
-{PR_NOT_IMPLEMENTED_ERROR, "PR_NOT_IMPLEMENTED_ERROR"},
-{PR_IO_ERROR, "PR_IO_ERROR"},
-{PR_IO_TIMEOUT_ERROR, "PR_IO_TIMEOUT_ERROR"},
-{PR_IO_PENDING_ERROR, "PR_IO_PENDING_ERROR"},
-{PR_DIRECTORY_OPEN_ERROR, "PR_DIRECTORY_OPEN_ERROR"},
-{PR_INVALID_ARGUMENT_ERROR, "PR_INVALID_ARGUMENT_ERROR"},
-{PR_ADDRESS_NOT_AVAILABLE_ERROR, "PR_ADDRESS_NOT_AVAILABLE_ERROR"},
-{PR_ADDRESS_NOT_SUPPORTED_ERROR, "PR_ADDRESS_NOT_SUPPORTED_ERROR"},
-{PR_IS_CONNECTED_ERROR, "PR_IS_CONNECTED_ERROR"},
-{PR_BAD_ADDRESS_ERROR, "PR_BAD_ADDRESS_ERROR"},
-{PR_ADDRESS_IN_USE_ERROR, "PR_ADDRESS_IN_USE_ERROR"},
-{PR_CONNECT_REFUSED_ERROR, "PR_CONNECT_REFUSED_ERROR"},
-{PR_NETWORK_UNREACHABLE_ERROR, "PR_NETWORK_UNREACHABLE_ERROR"},
-{PR_CONNECT_TIMEOUT_ERROR, "PR_CONNECT_TIMEOUT_ERROR"},
-{PR_NOT_CONNECTED_ERROR, "PR_NOT_CONNECTED_ERROR"},
-{PR_LOAD_LIBRARY_ERROR, "PR_LOAD_LIBRARY_ERROR"},
-{PR_UNLOAD_LIBRARY_ERROR, "PR_UNLOAD_LIBRARY_ERROR"},
-{PR_FIND_SYMBOL_ERROR, "PR_FIND_SYMBOL_ERROR"},
-{PR_INSUFFICIENT_RESOURCES_ERROR, "PR_INSUFFICIENT_RESOURCES_ERROR"},
-{PR_DIRECTORY_LOOKUP_ERROR, "PR_DIRECTORY_LOOKUP_ERROR"},
-{PR_TPD_RANGE_ERROR, "PR_TPD_RANGE_ERROR"},
-{PR_PROC_DESC_TABLE_FULL_ERROR, "PR_PROC_DESC_TABLE_FULL_ERROR"},
-{PR_SYS_DESC_TABLE_FULL_ERROR, "PR_SYS_DESC_TABLE_FULL_ERROR"},
-{PR_NOT_SOCKET_ERROR, "PR_NOT_SOCKET_ERROR"},
-{PR_NOT_TCP_SOCKET_ERROR, "PR_NOT_TCP_SOCKET_ERROR"},
-{PR_SOCKET_ADDRESS_IS_BOUND_ERROR, "PR_SOCKET_ADDRESS_IS_BOUND_ERROR"},
-{PR_NO_ACCESS_RIGHTS_ERROR, "PR_NO_ACCESS_RIGHTS_ERROR"},
-{PR_OPERATION_NOT_SUPPORTED_ERROR, "PR_OPERATION_NOT_SUPPORTED_ERROR"},
-{PR_PROTOCOL_NOT_SUPPORTED_ERROR, "PR_PROTOCOL_NOT_SUPPORTED_ERROR"},
-{PR_REMOTE_FILE_ERROR, "PR_REMOTE_FILE_ERROR"},
-{PR_BUFFER_OVERFLOW_ERROR, "PR_BUFFER_OVERFLOW_ERROR"},
-{PR_CONNECT_RESET_ERROR, "PR_CONNECT_RESET_ERROR"},
-{PR_RANGE_ERROR, "PR_RANGE_ERROR"},
-{PR_DEADLOCK_ERROR, "PR_DEADLOCK_ERROR"},
-{PR_FILE_IS_LOCKED_ERROR, "PR_FILE_IS_LOCKED_ERROR"},
-{PR_FILE_TOO_BIG_ERROR, "PR_FILE_TOO_BIG_ERROR"},
-{PR_NO_DEVICE_SPACE_ERROR, "PR_NO_DEVICE_SPACE_ERROR"},
-{PR_PIPE_ERROR, "PR_PIPE_ERROR"},
-{PR_NO_SEEK_DEVICE_ERROR, "PR_NO_SEEK_DEVICE_ERROR"},
-{PR_IS_DIRECTORY_ERROR, "PR_IS_DIRECTORY_ERROR"},
-{PR_LOOP_ERROR, "PR_LOOP_ERROR"},
-{PR_NAME_TOO_LONG_ERROR, "PR_NAME_TOO_LONG_ERROR"},
-{PR_FILE_NOT_FOUND_ERROR, "PR_FILE_NOT_FOUND_ERROR"},
-{PR_NOT_DIRECTORY_ERROR, "PR_NOT_DIRECTORY_ERROR"},
-{PR_READ_ONLY_FILESYSTEM_ERROR, "PR_READ_ONLY_FILESYSTEM_ERROR"},
-{PR_DIRECTORY_NOT_EMPTY_ERROR, "PR_DIRECTORY_NOT_EMPTY_ERROR"},
-{PR_FILESYSTEM_MOUNTED_ERROR, "PR_FILESYSTEM_MOUNTED_ERROR"},
-{PR_NOT_SAME_DEVICE_ERROR, "PR_NOT_SAME_DEVICE_ERROR"},
-{PR_DIRECTORY_CORRUPTED_ERROR, "PR_DIRECTORY_CORRUPTED_ERROR"},
-{PR_FILE_EXISTS_ERROR, "PR_FILE_EXISTS_ERROR"},
-{PR_MAX_DIRECTORY_ENTRIES_ERROR, "PR_MAX_DIRECTORY_ENTRIES_ERROR"},
-{PR_INVALID_DEVICE_STATE_ERROR, "PR_INVALID_DEVICE_STATE_ERROR"},
-{PR_DEVICE_IS_LOCKED_ERROR, "PR_DEVICE_IS_LOCKED_ERROR"},
-{PR_NO_MORE_FILES_ERROR, "PR_NO_MORE_FILES_ERROR"},
-{PR_END_OF_FILE_ERROR, "PR_END_OF_FILE_ERROR"},
-{PR_FILE_SEEK_ERROR, "PR_FILE_SEEK_ERROR"},
-{PR_FILE_IS_BUSY_ERROR, "PR_FILE_IS_BUSY_ERROR"},
-{PR_IN_PROGRESS_ERROR, "PR_IN_PROGRESS_ERROR"},
-{PR_ALREADY_INITIATED_ERROR, "PR_ALREADY_INITIATED_ERROR"},
-{PR_GROUP_EMPTY_ERROR, "PR_GROUP_EMPTY_ERROR"},
-{PR_INVALID_STATE_ERROR, "PR_INVALID_STATE_ERROR"},
-{PR_NETWORK_DOWN_ERROR, "PR_NETWORK_DOWN_ERROR"},
-{PR_SOCKET_SHUTDOWN_ERROR, "PR_SOCKET_SHUTDOWN_ERROR"},
-{PR_CONNECT_ABORTED_ERROR, "PR_CONNECT_ABORTED_ERROR"},
-{PR_HOST_UNREACHABLE_ERROR, "PR_HOST_UNREACHABLE_ERROR"}
+ {PR_OUT_OF_MEMORY_ERROR, "PR_OUT_OF_MEMORY_ERROR"},
+ {PR_UNKNOWN_ERROR, "An intentionally long error message text intended to force a delete of the current errorString buffer and get another one."},
+ {PR_BAD_DESCRIPTOR_ERROR, "PR_BAD_DESCRIPTOR_ERROR"},
+ {PR_WOULD_BLOCK_ERROR, "PR_WOULD_BLOCK_ERROR"},
+ {PR_ACCESS_FAULT_ERROR, "PR_ACCESS_FAULT_ERROR"},
+ {PR_INVALID_METHOD_ERROR, "PR_INVALID_METHOD_ERROR"},
+ {PR_ILLEGAL_ACCESS_ERROR, "PR_ILLEGAL_ACCESS_ERROR"},
+ {PR_UNKNOWN_ERROR, "PR_UNKNOWN_ERROR"},
+ {PR_PENDING_INTERRUPT_ERROR, "PR_PENDING_INTERRUPT_ERROR"},
+ {PR_NOT_IMPLEMENTED_ERROR, "PR_NOT_IMPLEMENTED_ERROR"},
+ {PR_IO_ERROR, "PR_IO_ERROR"},
+ {PR_IO_TIMEOUT_ERROR, "PR_IO_TIMEOUT_ERROR"},
+ {PR_IO_PENDING_ERROR, "PR_IO_PENDING_ERROR"},
+ {PR_DIRECTORY_OPEN_ERROR, "PR_DIRECTORY_OPEN_ERROR"},
+ {PR_INVALID_ARGUMENT_ERROR, "PR_INVALID_ARGUMENT_ERROR"},
+ {PR_ADDRESS_NOT_AVAILABLE_ERROR, "PR_ADDRESS_NOT_AVAILABLE_ERROR"},
+ {PR_ADDRESS_NOT_SUPPORTED_ERROR, "PR_ADDRESS_NOT_SUPPORTED_ERROR"},
+ {PR_IS_CONNECTED_ERROR, "PR_IS_CONNECTED_ERROR"},
+ {PR_BAD_ADDRESS_ERROR, "PR_BAD_ADDRESS_ERROR"},
+ {PR_ADDRESS_IN_USE_ERROR, "PR_ADDRESS_IN_USE_ERROR"},
+ {PR_CONNECT_REFUSED_ERROR, "PR_CONNECT_REFUSED_ERROR"},
+ {PR_NETWORK_UNREACHABLE_ERROR, "PR_NETWORK_UNREACHABLE_ERROR"},
+ {PR_CONNECT_TIMEOUT_ERROR, "PR_CONNECT_TIMEOUT_ERROR"},
+ {PR_NOT_CONNECTED_ERROR, "PR_NOT_CONNECTED_ERROR"},
+ {PR_LOAD_LIBRARY_ERROR, "PR_LOAD_LIBRARY_ERROR"},
+ {PR_UNLOAD_LIBRARY_ERROR, "PR_UNLOAD_LIBRARY_ERROR"},
+ {PR_FIND_SYMBOL_ERROR, "PR_FIND_SYMBOL_ERROR"},
+ {PR_INSUFFICIENT_RESOURCES_ERROR, "PR_INSUFFICIENT_RESOURCES_ERROR"},
+ {PR_DIRECTORY_LOOKUP_ERROR, "PR_DIRECTORY_LOOKUP_ERROR"},
+ {PR_TPD_RANGE_ERROR, "PR_TPD_RANGE_ERROR"},
+ {PR_PROC_DESC_TABLE_FULL_ERROR, "PR_PROC_DESC_TABLE_FULL_ERROR"},
+ {PR_SYS_DESC_TABLE_FULL_ERROR, "PR_SYS_DESC_TABLE_FULL_ERROR"},
+ {PR_NOT_SOCKET_ERROR, "PR_NOT_SOCKET_ERROR"},
+ {PR_NOT_TCP_SOCKET_ERROR, "PR_NOT_TCP_SOCKET_ERROR"},
+ {PR_SOCKET_ADDRESS_IS_BOUND_ERROR, "PR_SOCKET_ADDRESS_IS_BOUND_ERROR"},
+ {PR_NO_ACCESS_RIGHTS_ERROR, "PR_NO_ACCESS_RIGHTS_ERROR"},
+ {PR_OPERATION_NOT_SUPPORTED_ERROR, "PR_OPERATION_NOT_SUPPORTED_ERROR"},
+ {PR_PROTOCOL_NOT_SUPPORTED_ERROR, "PR_PROTOCOL_NOT_SUPPORTED_ERROR"},
+ {PR_REMOTE_FILE_ERROR, "PR_REMOTE_FILE_ERROR"},
+ {PR_BUFFER_OVERFLOW_ERROR, "PR_BUFFER_OVERFLOW_ERROR"},
+ {PR_CONNECT_RESET_ERROR, "PR_CONNECT_RESET_ERROR"},
+ {PR_RANGE_ERROR, "PR_RANGE_ERROR"},
+ {PR_DEADLOCK_ERROR, "PR_DEADLOCK_ERROR"},
+ {PR_FILE_IS_LOCKED_ERROR, "PR_FILE_IS_LOCKED_ERROR"},
+ {PR_FILE_TOO_BIG_ERROR, "PR_FILE_TOO_BIG_ERROR"},
+ {PR_NO_DEVICE_SPACE_ERROR, "PR_NO_DEVICE_SPACE_ERROR"},
+ {PR_PIPE_ERROR, "PR_PIPE_ERROR"},
+ {PR_NO_SEEK_DEVICE_ERROR, "PR_NO_SEEK_DEVICE_ERROR"},
+ {PR_IS_DIRECTORY_ERROR, "PR_IS_DIRECTORY_ERROR"},
+ {PR_LOOP_ERROR, "PR_LOOP_ERROR"},
+ {PR_NAME_TOO_LONG_ERROR, "PR_NAME_TOO_LONG_ERROR"},
+ {PR_FILE_NOT_FOUND_ERROR, "PR_FILE_NOT_FOUND_ERROR"},
+ {PR_NOT_DIRECTORY_ERROR, "PR_NOT_DIRECTORY_ERROR"},
+ {PR_READ_ONLY_FILESYSTEM_ERROR, "PR_READ_ONLY_FILESYSTEM_ERROR"},
+ {PR_DIRECTORY_NOT_EMPTY_ERROR, "PR_DIRECTORY_NOT_EMPTY_ERROR"},
+ {PR_FILESYSTEM_MOUNTED_ERROR, "PR_FILESYSTEM_MOUNTED_ERROR"},
+ {PR_NOT_SAME_DEVICE_ERROR, "PR_NOT_SAME_DEVICE_ERROR"},
+ {PR_DIRECTORY_CORRUPTED_ERROR, "PR_DIRECTORY_CORRUPTED_ERROR"},
+ {PR_FILE_EXISTS_ERROR, "PR_FILE_EXISTS_ERROR"},
+ {PR_MAX_DIRECTORY_ENTRIES_ERROR, "PR_MAX_DIRECTORY_ENTRIES_ERROR"},
+ {PR_INVALID_DEVICE_STATE_ERROR, "PR_INVALID_DEVICE_STATE_ERROR"},
+ {PR_DEVICE_IS_LOCKED_ERROR, "PR_DEVICE_IS_LOCKED_ERROR"},
+ {PR_NO_MORE_FILES_ERROR, "PR_NO_MORE_FILES_ERROR"},
+ {PR_END_OF_FILE_ERROR, "PR_END_OF_FILE_ERROR"},
+ {PR_FILE_SEEK_ERROR, "PR_FILE_SEEK_ERROR"},
+ {PR_FILE_IS_BUSY_ERROR, "PR_FILE_IS_BUSY_ERROR"},
+ {PR_IN_PROGRESS_ERROR, "PR_IN_PROGRESS_ERROR"},
+ {PR_ALREADY_INITIATED_ERROR, "PR_ALREADY_INITIATED_ERROR"},
+ {PR_GROUP_EMPTY_ERROR, "PR_GROUP_EMPTY_ERROR"},
+ {PR_INVALID_STATE_ERROR, "PR_INVALID_STATE_ERROR"},
+ {PR_NETWORK_DOWN_ERROR, "PR_NETWORK_DOWN_ERROR"},
+ {PR_SOCKET_SHUTDOWN_ERROR, "PR_SOCKET_SHUTDOWN_ERROR"},
+ {PR_CONNECT_ABORTED_ERROR, "PR_CONNECT_ABORTED_ERROR"},
+ {PR_HOST_UNREACHABLE_ERROR, "PR_HOST_UNREACHABLE_ERROR"}
};
int main(int argc, char **argv)
{
- int count, errnum;
+ int count, errnum;
/*
* -d debug mode
@@ -119,21 +119,23 @@ int main(int argc, char **argv)
PLOptState *opt = PL_CreateOptState(argc, argv, "d");
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_on = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ _debug_on = 1;
+ break;
+ default:
+ break;
}
}
PL_DestroyOptState(opt);
- count = sizeof(errcodes)/sizeof(errcodes[0]);
- printf("\nNumber of error codes = %d\n\n",count);
- for (errnum = 0; errnum < count; errnum++) {
+ count = sizeof(errcodes)/sizeof(errcodes[0]);
+ printf("\nNumber of error codes = %d\n\n",count);
+ for (errnum = 0; errnum < count; errnum++) {
PRInt32 len1, len2, err;
char msg[256];
@@ -149,5 +151,5 @@ int main(int argc, char **argv)
printf("%5.5d -- %s\n", errnum, msg );
}
- return 0;
+ return 0;
}
diff --git a/pr/tests/exit.c b/pr/tests/exit.c
index fe6fc31e..dd3d4442 100644
--- a/pr/tests/exit.c
+++ b/pr/tests/exit.c
@@ -30,8 +30,9 @@ static void Help(void)
static void Dull(void *arg)
{
PR_Sleep(PR_SecondsToInterval(dally));
- if (verbose && force)
+ if (verbose && force) {
PR_fprintf(err, "If you see this, the test failed\n");
+ }
} /* Dull */
static PRIntn PR_CALLBACK RealMain(PRIntn argc, char **argv)
@@ -43,38 +44,42 @@ static PRIntn PR_CALLBACK RealMain(PRIntn argc, char **argv)
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': /* verbosity */
- verbose = PR_TRUE;
- break;
- case 'x': /* force exit */
- force = PR_TRUE;
- break;
- case 't': /* seconds to dally in child */
- dally = atoi(opt->value);
- break;
- case 'h': /* user wants some guidance */
- default:
- Help(); /* so give him an earful */
- return 2; /* but not a lot else */
+ case 'd': /* verbosity */
+ verbose = PR_TRUE;
+ break;
+ case 'x': /* force exit */
+ force = PR_TRUE;
+ break;
+ case 't': /* seconds to dally in child */
+ dally = atoi(opt->value);
+ break;
+ case 'h': /* user wants some guidance */
+ default:
+ Help(); /* so give him an earful */
+ return 2; /* but not a lot else */
}
}
PL_DestroyOptState(opt);
- if (0 == dally) dally = 10;
+ if (0 == dally) {
+ dally = 10;
+ }
- /*
- * Create LOCAL and GLOBAL threads
- */
+ /*
+ * Create LOCAL and GLOBAL threads
+ */
(void)PR_CreateThread(
PR_USER_THREAD, Dull, NULL, PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD, PR_UNJOINABLE_THREAD, 0);
+ PR_LOCAL_THREAD, PR_UNJOINABLE_THREAD, 0);
(void)PR_CreateThread(
PR_USER_THREAD, Dull, NULL, PR_PRIORITY_NORMAL,
- PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0);
+ PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0);
if (verbose)
PR_fprintf(
diff --git a/pr/tests/fileio.c b/pr/tests/fileio.c
index ac1fdb1a..a0be3bb1 100644
--- a/pr/tests/fileio.c
+++ b/pr/tests/fileio.c
@@ -11,12 +11,12 @@
**
** Modification History:
** 14-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.
** 12-June-97 Revert to return code 0 and 1, remove debug option (obsolete).
***********************************************************************/
@@ -47,137 +47,145 @@ PRIntn failed_already=0;
PRIntn debug_mode;
static void InitialSetup(void)
{
- PRUintn i;
- PRInt32 nWritten, rv;
+ PRUintn i;
+ PRInt32 nWritten, rv;
- t1 = PR_Open("t1.tmp", PR_CREATE_FILE | PR_RDWR, 0);
- PR_ASSERT(t1 != NULL);
+ t1 = PR_Open("t1.tmp", PR_CREATE_FILE | PR_RDWR, 0);
+ PR_ASSERT(t1 != NULL);
- for (i=0; i<TBSIZE; i++)
- tbuf[i] = i;
+ for (i=0; i<TBSIZE; i++) {
+ tbuf[i] = i;
+ }
- nWritten = PR_Write((PRFileDesc*)t1, tbuf, TBSIZE);
- PR_ASSERT(nWritten == TBSIZE);
+ nWritten = PR_Write((PRFileDesc*)t1, tbuf, TBSIZE);
+ PR_ASSERT(nWritten == TBSIZE);
- rv = PR_Seek(t1,0,PR_SEEK_SET);
- PR_ASSERT(rv == 0);
+ rv = PR_Seek(t1,0,PR_SEEK_SET);
+ PR_ASSERT(rv == 0);
- t2 = PR_Open("t2.tmp", PR_CREATE_FILE | PR_RDWR, 0);
- PR_ASSERT(t2 != NULL);
+ t2 = PR_Open("t2.tmp", PR_CREATE_FILE | PR_RDWR, 0);
+ PR_ASSERT(t2 != NULL);
}
static void VerifyAndCleanup(void)
{
- PRUintn i;
- PRInt32 nRead, rv;
-
- for (i=0; i<TBSIZE; i++)
- tbuf[i] = 0;
-
- rv = PR_Seek(t2,0,PR_SEEK_SET);
- PR_ASSERT(rv == 0);
-
- nRead = PR_Read((PRFileDesc*)t2, tbuf, TBSIZE);
- PR_ASSERT(nRead == TBSIZE);
+ PRUintn i;
+ PRInt32 nRead, rv;
- for (i=0; i<TBSIZE; i++)
- if (tbuf[i] != (PRUint8)i) {
- if (debug_mode) printf("data mismatch for index= %d \n", i);
- else failed_already=1;
- }
- PR_Close(t1);
- PR_Close(t2);
-
- PR_Delete("t1.tmp");
- PR_Delete("t2.tmp");
+ for (i=0; i<TBSIZE; i++) {
+ tbuf[i] = 0;
+ }
- if (debug_mode) printf("fileio test passed\n");
+ rv = PR_Seek(t2,0,PR_SEEK_SET);
+ PR_ASSERT(rv == 0);
+
+ nRead = PR_Read((PRFileDesc*)t2, tbuf, TBSIZE);
+ PR_ASSERT(nRead == TBSIZE);
+
+ for (i=0; i<TBSIZE; i++)
+ if (tbuf[i] != (PRUint8)i) {
+ if (debug_mode) {
+ printf("data mismatch for index= %d \n", i);
+ }
+ else {
+ failed_already=1;
+ }
+ }
+ PR_Close(t1);
+ PR_Close(t2);
+
+ PR_Delete("t1.tmp");
+ PR_Delete("t2.tmp");
+
+ if (debug_mode) {
+ printf("fileio test passed\n");
+ }
}
/*------------------ Following is the real test program ---------*/
/*
- Program to copy one file to another. Two temporary files get
- created. First one gets written in one write call. Then,
- a reader thread reads from this file into a double buffer.
- The writer thread writes from double buffer into the other
- temporary file. The second temporary file gets verified
- for accurate data.
+ Program to copy one file to another. Two temporary files get
+ created. First one gets written in one write call. Then,
+ a reader thread reads from this file into a double buffer.
+ The writer thread writes from double buffer into the other
+ temporary file. The second temporary file gets verified
+ for accurate data.
*/
-PRSemaphore *emptyBufs; /* number of empty buffers */
-PRSemaphore *fullBufs; /* number of buffers that are full */
+PRSemaphore *emptyBufs; /* number of empty buffers */
+PRSemaphore *fullBufs; /* number of buffers that are full */
-#define BSIZE 100
+#define BSIZE 100
struct {
- char data[BSIZE];
- PRUintn nbytes; /* number of bytes in this buffer */
+ char data[BSIZE];
+ PRUintn nbytes; /* number of bytes in this buffer */
} buf[2];
static void PR_CALLBACK reader(void *arg)
{
- PRUintn i = 0;
- PRInt32 nbytes;
-
- do {
- (void) PR_WaitSem(emptyBufs);
- nbytes = PR_Read((PRFileDesc*)arg, buf[i].data, BSIZE);
- if (nbytes >= 0) {
- buf[i].nbytes = nbytes;
- PR_PostSem(fullBufs);
- i = (i + 1) % 2;
- }
- } while (nbytes > 0);
+ PRUintn i = 0;
+ PRInt32 nbytes;
+
+ do {
+ (void) PR_WaitSem(emptyBufs);
+ nbytes = PR_Read((PRFileDesc*)arg, buf[i].data, BSIZE);
+ if (nbytes >= 0) {
+ buf[i].nbytes = nbytes;
+ PR_PostSem(fullBufs);
+ i = (i + 1) % 2;
+ }
+ } while (nbytes > 0);
}
static void PR_CALLBACK writer(void *arg)
{
- PRUintn i = 0;
- PRInt32 nbytes;
-
- do {
- (void) PR_WaitSem(fullBufs);
- nbytes = buf[i].nbytes;
- if (nbytes > 0) {
- nbytes = PR_Write((PRFileDesc*)arg, buf[i].data, nbytes);
- PR_PostSem(emptyBufs);
- i = (i + 1) % 2;
- }
- } while (nbytes > 0);
+ PRUintn i = 0;
+ PRInt32 nbytes;
+
+ do {
+ (void) PR_WaitSem(fullBufs);
+ nbytes = buf[i].nbytes;
+ if (nbytes > 0) {
+ nbytes = PR_Write((PRFileDesc*)arg, buf[i].data, nbytes);
+ PR_PostSem(emptyBufs);
+ i = (i + 1) % 2;
+ }
+ } while (nbytes > 0);
}
int main(int argc, char **argv)
{
- PRThread *r, *w;
+ PRThread *r, *w;
- PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
+ PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
PR_STDIO_INIT();
- emptyBufs = PR_NewSem(2); /* two empty buffers */
+ emptyBufs = PR_NewSem(2); /* two empty buffers */
- fullBufs = PR_NewSem(0); /* zero full buffers */
+ fullBufs = PR_NewSem(0); /* zero full buffers */
- /* Create initial temp file setup */
- InitialSetup();
+ /* Create initial temp file setup */
+ InitialSetup();
- /* create the reader thread */
+ /* create the reader thread */
- r = PR_CreateThread(PR_USER_THREAD,
- reader, t1,
- PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD,
- PR_JOINABLE_THREAD,
- 0);
+ r = PR_CreateThread(PR_USER_THREAD,
+ reader, t1,
+ PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD,
+ PR_JOINABLE_THREAD,
+ 0);
- w = PR_CreateThread(PR_USER_THREAD,
- writer, t2,
- PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD,
- PR_JOINABLE_THREAD,
- 0);
+ w = PR_CreateThread(PR_USER_THREAD,
+ writer, t2,
+ PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD,
+ PR_JOINABLE_THREAD,
+ 0);
/* Do the joining for both threads */
(void) PR_JoinThread(r);
diff --git a/pr/tests/foreign.c b/pr/tests/foreign.c
index 6c682f30..a711b758 100644
--- a/pr/tests/foreign.c
+++ b/pr/tests/foreign.c
@@ -48,9 +48,9 @@ static PRFileDesc *output;
static int _debug_on = 0;
-#define DEFAULT_THREAD_COUNT 10
+#define DEFAULT_THREAD_COUNT 10
-#define DPRINTF(arg) if (_debug_on) PR_fprintf arg
+#define DPRINTF(arg) if (_debug_on) PR_fprintf arg
#if defined(_PR_PTHREADS)
#include <pthread.h>
@@ -86,16 +86,16 @@ static PRStatus NSPRPUB_TESTS_CreateThread(StartFn start, void *arg)
switch (thread_provider)
{
- case thread_nspr:
+ case thread_nspr:
{
PRThread *thread = PR_CreateThread(
- PR_USER_THREAD, start, arg,
- PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
- PR_UNJOINABLE_THREAD, 0);
+ PR_USER_THREAD, start, arg,
+ PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
+ PR_UNJOINABLE_THREAD, 0);
rv = (NULL == thread) ? PR_FAILURE : PR_SUCCESS;
}
break;
- case thread_pthread:
+ case thread_pthread:
#if defined(_PR_PTHREADS)
{
int rv;
@@ -126,11 +126,11 @@ static PRStatus NSPRPUB_TESTS_CreateThread(StartFn start, void *arg)
break;
#endif /* defined(_PR_PTHREADS) */
- case thread_sproc:
- PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
- rv = PR_FAILURE;
- break;
- case thread_win32:
+ case thread_sproc:
+ PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+ rv = PR_FAILURE;
+ break;
+ case thread_win32:
#if defined(WIN32)
{
void *th;
@@ -141,12 +141,12 @@ static PRStatus NSPRPUB_TESTS_CreateThread(StartFn start, void *arg)
start_object->start = start;
start_object->arg = arg;
th = (void*)_beginthreadex(
- NULL, /* LPSECURITY_ATTRIBUTES - pointer to thread security attributes */
- 0U, /* DWORD - initial thread stack size, in bytes */
- windows_start, /* LPTHREAD_START_ROUTINE - pointer to thread function */
- start_object, /* LPVOID - argument for new thread */
- STACK_SIZE_PARAM_IS_A_RESERVATION, /*DWORD dwCreationFlags - creation flags */
- &id /* LPDWORD - pointer to returned thread identifier */ );
+ NULL, /* LPSECURITY_ATTRIBUTES - pointer to thread security attributes */
+ 0U, /* DWORD - initial thread stack size, in bytes */
+ windows_start, /* LPTHREAD_START_ROUTINE - pointer to thread function */
+ start_object, /* LPVOID - argument for new thread */
+ STACK_SIZE_PARAM_IS_A_RESERVATION, /*DWORD dwCreationFlags - creation flags */
+ &id /* LPDWORD - pointer to returned thread identifier */ );
rv = (NULL == th) ? PR_FAILURE : PR_SUCCESS;
}
@@ -155,9 +155,9 @@ static PRStatus NSPRPUB_TESTS_CreateThread(StartFn start, void *arg)
rv = PR_FAILURE;
#endif
break;
- default:
- PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
- rv = PR_FAILURE;
+ default:
+ PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+ rv = PR_FAILURE;
}
return rv;
} /* NSPRPUB_TESTS_CreateThread */
@@ -177,133 +177,135 @@ static void OneShot(void *arg)
PRFileDesc *pair[2];
PRIntn test = (PRIntn)arg;
- for (test = 0; test < 12; ++test) {
-
- switch (test)
- {
- case 0:
- lock = PR_NewLock();
- DPRINTF((output,"Thread[0x%x] called PR_NewLock\n",
- PR_GetCurrentThread()));
- PR_DestroyLock(lock);
- break;
-
- case 1:
- (void)PR_SecondsToInterval(1);
- DPRINTF((output,"Thread[0x%x] called PR_SecondsToInterval\n",
- PR_GetCurrentThread()));
- break;
-
- case 2: (void)PR_CreateThread(
- PR_USER_THREAD, lazyEntry, NULL, PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD, PR_UNJOINABLE_THREAD, 0);
- DPRINTF((output,"Thread[0x%x] called PR_CreateThread\n",
- PR_GetCurrentThread()));
- break;
-
- case 3:
- fd = PR_Open("foreign.tmp", PR_CREATE_FILE | PR_RDWR, 0666);
- DPRINTF((output,"Thread[0x%x] called PR_Open\n",
- PR_GetCurrentThread()));
- PR_Close(fd);
- break;
-
- case 4:
- fd = PR_NewUDPSocket();
- DPRINTF((output,"Thread[0x%x] called PR_NewUDPSocket\n",
- PR_GetCurrentThread()));
- PR_Close(fd);
- break;
-
- case 5:
- fd = PR_NewTCPSocket();
- DPRINTF((output,"Thread[0x%x] called PR_NewTCPSocket\n",
- PR_GetCurrentThread()));
- PR_Close(fd);
- break;
+ for (test = 0; test < 12; ++test) {
- case 6:
+ switch (test)
+ {
+ case 0:
+ lock = PR_NewLock();
+ DPRINTF((output,"Thread[0x%x] called PR_NewLock\n",
+ PR_GetCurrentThread()));
+ PR_DestroyLock(lock);
+ break;
+
+ case 1:
+ (void)PR_SecondsToInterval(1);
+ DPRINTF((output,"Thread[0x%x] called PR_SecondsToInterval\n",
+ PR_GetCurrentThread()));
+ break;
+
+ case 2: (void)PR_CreateThread(
+ PR_USER_THREAD, lazyEntry, NULL, PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD, PR_UNJOINABLE_THREAD, 0);
+ DPRINTF((output,"Thread[0x%x] called PR_CreateThread\n",
+ PR_GetCurrentThread()));
+ break;
+
+ case 3:
+ fd = PR_Open("foreign.tmp", PR_CREATE_FILE | PR_RDWR, 0666);
+ DPRINTF((output,"Thread[0x%x] called PR_Open\n",
+ PR_GetCurrentThread()));
+ PR_Close(fd);
+ break;
+
+ case 4:
+ fd = PR_NewUDPSocket();
+ DPRINTF((output,"Thread[0x%x] called PR_NewUDPSocket\n",
+ PR_GetCurrentThread()));
+ PR_Close(fd);
+ break;
+
+ case 5:
+ fd = PR_NewTCPSocket();
+ DPRINTF((output,"Thread[0x%x] called PR_NewTCPSocket\n",
+ PR_GetCurrentThread()));
+ PR_Close(fd);
+ break;
+
+ case 6:
#define TEMP_DIR "/tmp/"
- dir = PR_OpenDir(TEMP_DIR);
- DPRINTF((output,"Thread[0x%x] called PR_OpenDir\n",
- PR_GetCurrentThread()));
- PR_CloseDir(dir);
- break;
-
- case 7:
- (void)PR_NewThreadPrivateIndex(&pdkey, NULL);
- DPRINTF((output,"Thread[0x%x] called PR_NewThreadPrivateIndex\n",
- PR_GetCurrentThread()));
- break;
-
- case 8:
- (void)PR_GetEnv("PATH");
- DPRINTF((output,"Thread[0x%x] called PR_GetEnv\n",
- PR_GetCurrentThread()));
- break;
-
- case 9:
- (void)PR_NewTCPSocketPair(pair);
- DPRINTF((output,"Thread[0x%x] called PR_NewTCPSocketPair\n",
- PR_GetCurrentThread()));
- PR_Close(pair[0]);
- PR_Close(pair[1]);
- break;
-
- case 10:
- PR_SetConcurrency(2);
- DPRINTF((output,"Thread[0x%x] called PR_SetConcurrency\n",
- PR_GetCurrentThread()));
- break;
-
- case 11:
- PR_SetThreadPriority(PR_GetCurrentThread(), PR_PRIORITY_HIGH);
- DPRINTF((output,"Thread[0x%x] called PR_SetThreadPriority\n",
- PR_GetCurrentThread()));
- break;
-
- default:
- break;
- } /* switch() */
- }
+ dir = PR_OpenDir(TEMP_DIR);
+ DPRINTF((output,"Thread[0x%x] called PR_OpenDir\n",
+ PR_GetCurrentThread()));
+ PR_CloseDir(dir);
+ break;
+
+ case 7:
+ (void)PR_NewThreadPrivateIndex(&pdkey, NULL);
+ DPRINTF((output,"Thread[0x%x] called PR_NewThreadPrivateIndex\n",
+ PR_GetCurrentThread()));
+ break;
+
+ case 8:
+ (void)PR_GetEnv("PATH");
+ DPRINTF((output,"Thread[0x%x] called PR_GetEnv\n",
+ PR_GetCurrentThread()));
+ break;
+
+ case 9:
+ (void)PR_NewTCPSocketPair(pair);
+ DPRINTF((output,"Thread[0x%x] called PR_NewTCPSocketPair\n",
+ PR_GetCurrentThread()));
+ PR_Close(pair[0]);
+ PR_Close(pair[1]);
+ break;
+
+ case 10:
+ PR_SetConcurrency(2);
+ DPRINTF((output,"Thread[0x%x] called PR_SetConcurrency\n",
+ PR_GetCurrentThread()));
+ break;
+
+ case 11:
+ PR_SetThreadPriority(PR_GetCurrentThread(), PR_PRIORITY_HIGH);
+ DPRINTF((output,"Thread[0x%x] called PR_SetThreadPriority\n",
+ PR_GetCurrentThread()));
+ break;
+
+ default:
+ break;
+ } /* switch() */
+ }
} /* OneShot */
int main(int argc, char **argv)
{
PRStatus rv;
- PRInt32 thread_cnt = DEFAULT_THREAD_COUNT;
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "dt:");
+ PRInt32 thread_cnt = DEFAULT_THREAD_COUNT;
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "dt:");
#if defined(WIN32)
- thread_provider = thread_win32;
+ thread_provider = thread_win32;
#elif defined(_PR_PTHREADS)
- thread_provider = thread_pthread;
+ thread_provider = thread_pthread;
#else
thread_provider = thread_nspr;
#endif
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ 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_on = 1;
- break;
- case 't': /* thread count */
- thread_cnt = atoi(opt->value);
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ _debug_on = 1;
+ break;
+ case 't': /* thread count */
+ thread_cnt = atoi(opt->value);
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- PR_SetConcurrency(2);
+ PR_SetConcurrency(2);
- output = PR_GetSpecialFD(PR_StandardOutput);
+ output = PR_GetSpecialFD(PR_StandardOutput);
while (thread_cnt-- > 0)
{
diff --git a/pr/tests/forktest.c b/pr/tests/forktest.c
index a7385baf..7de18524 100644
--- a/pr/tests/forktest.c
+++ b/pr/tests/forktest.c
@@ -62,13 +62,13 @@ ClientThreadFunc(void *arg)
addr.inet.port = 0;
if ((sock = PR_NewTCPSocket()) == NULL) {
fprintf(stderr, "failed to create TCP socket: error code %d\n",
- PR_GetError());
+ PR_GetError());
failed_already = 1;
goto finish;
}
if (PR_Bind(sock, &addr) != PR_SUCCESS) {
fprintf(stderr, "PR_Bind failed: error code %d\n",
- PR_GetError());
+ PR_GetError());
failed_already = 1;
goto finish;
}
@@ -79,7 +79,7 @@ ClientThreadFunc(void *arg)
if (PR_Connect(sock, &addr, PR_SecondsToInterval(5)) !=
PR_SUCCESS) {
fprintf(stderr, "PR_Connect failed: error code %d\n",
- PR_GetError());
+ PR_GetError());
failed_already = 1;
goto finish;
}
@@ -88,7 +88,7 @@ ClientThreadFunc(void *arg)
if (PR_Send(sock, message, strlen(message) + 1, 0, PR_INTERVAL_NO_TIMEOUT) ==
-1) {
fprintf(stderr, "PR_Send failed: error code %d\n",
- PR_GetError());
+ PR_GetError());
failed_already = 1;
goto finish;
}
@@ -117,7 +117,7 @@ DoIO(void)
listenSock = PR_NewTCPSocket();
if (!listenSock) {
fprintf(stderr, "failed to create a TCP socket: error code %d\n",
- PR_GetError());
+ PR_GetError());
failed_already = 1;
goto finish;
}
@@ -126,28 +126,28 @@ DoIO(void)
addr.inet.port = 0;
if (PR_Bind(listenSock, &addr) == PR_FAILURE) {
fprintf(stderr, "failed to bind socket: error code %d\n",
- PR_GetError());
+ PR_GetError());
failed_already = 1;
goto finish;
}
if (PR_GetSockName(listenSock, &addr) == PR_FAILURE) {
fprintf(stderr, "failed to get socket port number: error code %d\n",
- PR_GetError());
+ PR_GetError());
failed_already = 1;
goto finish;
}
if (PR_Listen(listenSock, 5) == PR_FAILURE) {
fprintf(stderr, "PR_Listen failed: error code %d\n",
- PR_GetError());
+ PR_GetError());
failed_already = 1;
goto finish;
}
clientThread = PR_CreateThread( PR_USER_THREAD, ClientThreadFunc,
- (void *) PR_ntohs(addr.inet.port), PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
- PR_JOINABLE_THREAD, 0);
+ (void *) PR_ntohs(addr.inet.port), PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
+ PR_JOINABLE_THREAD, 0);
if (clientThread == NULL) {
fprintf(stderr, "Cannot create client thread: (%d, %d)\n",
- PR_GetError(), PR_GetOSError());
+ PR_GetError(), PR_GetOSError());
failed_already = 1;
goto finish;
}
@@ -156,14 +156,14 @@ DoIO(void)
sock = PR_Accept(listenSock, &addr, PR_SecondsToInterval(5));
if (!sock) {
fprintf(stderr, "PR_Accept failed: error code %d\n",
- PR_GetError());
+ PR_GetError());
failed_already = 1;
goto finish;
}
nBytes = PR_Recv(sock, buf, sizeof(buf), 0, PR_INTERVAL_NO_TIMEOUT);
if (nBytes == -1) {
fprintf(stderr, "PR_Recv failed: error code %d\n",
- PR_GetError());
+ PR_GetError());
failed_already = 1;
goto finish;
}
@@ -182,7 +182,7 @@ DoIO(void)
fflush(stdout);
} else {
fprintf(stderr, "The message should be \"%s\"\n",
- message);
+ message);
failed_already = 1;
}
@@ -199,7 +199,7 @@ finish:
int main(int argc, char **argv)
{
pid_t pid;
- int rv;
+ int rv;
/* main test program */
@@ -217,12 +217,12 @@ int main(int argc, char **argv)
printf("Fork succeeded. Parent process continues.\n");
DoIO();
if ((rv = waitpid(pid, &childStatus, 0)) != pid) {
- {
- fprintf(stderr, "waitpid failed: %d\n", errno);
- failed_already = 1;
- }
+ {
+ fprintf(stderr, "waitpid failed: %d\n", errno);
+ failed_already = 1;
+ }
} else if (!WIFEXITED(childStatus)
- || WEXITSTATUS(childStatus) != 0) {
+ || WEXITSTATUS(childStatus) != 0) {
failed_already = 1;
}
printf("Parent process exits.\n");
@@ -243,8 +243,8 @@ int main(int argc, char **argv)
#else /* XP_UNIX */
int main( int argc,
-char *argv[]
-)
+ char *argv[]
+ )
{
printf("The fork test is applicable to Unix only.\n");
diff --git a/pr/tests/formattm.c b/pr/tests/formattm.c
index 88b9fdf2..63355b28 100644
--- a/pr/tests/formattm.c
+++ b/pr/tests/formattm.c
@@ -20,7 +20,7 @@ int main(int argc, char **argv)
PR_ExplodeTime(now, PR_LocalTimeParameters, &tod);
if (PR_FormatTime(buffer, sizeof(buffer),
- "%a %b %d %H:%M:%S %Z %Y", &tod) != 0) {
+ "%a %b %d %H:%M:%S %Z %Y", &tod) != 0) {
printf("%s\n", buffer);
} else {
fprintf(stderr, "PR_FormatTime(buffer) failed\n");
@@ -29,21 +29,21 @@ int main(int argc, char **argv)
small_buffer[0] = '?';
if (PR_FormatTime(small_buffer, sizeof(small_buffer),
- "%a %b %d %H:%M:%S %Z %Y", &tod) == 0) {
+ "%a %b %d %H:%M:%S %Z %Y", &tod) == 0) {
if (small_buffer[0] != '\0') {
fprintf(stderr, "PR_FormatTime(small_buffer) did not output "
- "an empty string on failure\n");
+ "an empty string on failure\n");
return 1;
}
printf("%s\n", small_buffer);
} else {
fprintf(stderr, "PR_FormatTime(small_buffer) succeeded "
- "unexpectedly\n");
+ "unexpectedly\n");
return 1;
}
(void)PR_FormatTimeUSEnglish(buffer, sizeof(buffer),
- "%a %b %d %H:%M:%S %Z %Y", &tod);
+ "%a %b %d %H:%M:%S %Z %Y", &tod);
printf("%s\n", buffer);
return 0;
diff --git a/pr/tests/freeif.c b/pr/tests/freeif.c
index edf005e4..1d38d0e3 100644
--- a/pr/tests/freeif.c
+++ b/pr/tests/freeif.c
@@ -27,16 +27,20 @@ int main(int argc, char **argv)
char *ptr = NULL;
/* this fails to compile with the old definition of PR_DELETE */
- if (foo)
+ if (foo) {
PR_DELETE(ptr);
- else
+ }
+ else {
Noop();
+ }
/* this nests incorrectly with the old definition of PR_FREEIF */
- if (foo)
+ if (foo) {
PR_FREEIF(ptr);
- else
+ }
+ else {
Fail();
+ }
printf("PASS\n");
return 0;
diff --git a/pr/tests/fsync.c b/pr/tests/fsync.c
index 01c71c4c..ee2eeff7 100644
--- a/pr/tests/fsync.c
+++ b/pr/tests/fsync.c
@@ -39,25 +39,27 @@ int main(int argc, char **argv)
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: /* Name of file to create */
- filename = opt->value;
- break;
- case 'S': /* Use sych option on file */
- flags |= PR_SYNC;
- break;
- case 'K': /* Size of file to write */
- filesize = atoi(opt->value);
- break;
- case 'c': /* Number of iterations */
- iterations = atoi(opt->value);
- break;
- case 'h': /* user wants some guidance */
- default: /* user needs some guidance */
- Help(); /* so give him an earful */
- return 2; /* but not a lot else */
+ case 0: /* Name of file to create */
+ filename = opt->value;
+ break;
+ case 'S': /* Use sych option on file */
+ flags |= PR_SYNC;
+ break;
+ case 'K': /* Size of file to write */
+ filesize = atoi(opt->value);
+ break;
+ case 'c': /* Number of iterations */
+ iterations = atoi(opt->value);
+ break;
+ case 'h': /* user wants some guidance */
+ default: /* user needs some guidance */
+ Help(); /* so give him an earful */
+ return 2; /* but not a lot else */
}
}
PL_DestroyOptState(opt);
@@ -76,8 +78,9 @@ int main(int argc, char **argv)
return 1;
}
- for (index = 0; index < sizeof(buffer); ++index)
+ for (index = 0; index < sizeof(buffer); ++index) {
buffer[index] = (PRUint8)index;
+ }
for (loops = 0; loops < iterations; ++loops)
{
@@ -89,12 +92,16 @@ int main(int argc, char **argv)
time = (PR_IntervalNow() - time);
total += time;
- if (time < shortest) shortest = time;
- else if (time > longest) longest = time;
+ if (time < shortest) {
+ shortest = time;
+ }
+ else if (time > longest) {
+ longest = time;
+ }
if (0 != PR_Seek(file, 0, PR_SEEK_SET))
{
- PL_FPrintError(err, "Rewinding file");
- return 1;
+ PL_FPrintError(err, "Rewinding file");
+ return 1;
}
}
diff --git a/pr/tests/getai.c b/pr/tests/getai.c
index f398ca3b..d759ed82 100644
--- a/pr/tests/getai.c
+++ b/pr/tests/getai.c
@@ -17,7 +17,7 @@ int main(int argc, char **argv)
ai = PR_GetAddrInfoByName(argv[1], PR_AF_UNSPEC, PR_AI_ADDRCONFIG);
if (ai == NULL) {
fprintf(stderr, "PR_GetAddrInfoByName failed: (%d, %d)\n",
- PR_GetError(), PR_GetOSError());
+ PR_GetError(), PR_GetOSError());
exit(1);
}
printf("%s\n", PR_GetCanonNameFromAddrInfo(ai));
diff --git a/pr/tests/gethost.c b/pr/tests/gethost.c
index e2226416..8a15cb61 100644
--- a/pr/tests/gethost.c
+++ b/pr/tests/gethost.c
@@ -45,7 +45,9 @@ void PrintHostent(const PRHostEnt *he)
for (i = 0; he->h_addr_list[i]; i++) {
printf("h_addr_list[%d]: ", i);
for (j = 0; j < he->h_length; j++) {
- if (j != 0) printf(".");
+ if (j != 0) {
+ printf(".");
+ }
printf("%u", (unsigned char)he->h_addr_list[i][j]);
}
printf("\n");
@@ -64,7 +66,9 @@ int main(int argc, char **argv)
PLOptState *opt = PL_CreateOptState(argc, argv, "h");
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: /* naked */
hostName = opt->value;
@@ -89,10 +93,12 @@ int main(int argc, char **argv)
fprintf(stderr, "PR_EnumerateHostEnt failed\n");
exit(1);
}
- if (idx == 0) break; /* normal loop termination */
+ if (idx == 0) {
+ break; /* normal loop termination */
+ }
printf("reverse lookup\n");
if (PR_GetHostByAddr(&addr, reversebuf, sizeof(reversebuf),
- &reversehe) == PR_FAILURE) {
+ &reversehe) == PR_FAILURE) {
fprintf(stderr, "PR_GetHostByAddr failed\n");
exit(1);
}
@@ -101,14 +107,14 @@ int main(int argc, char **argv)
printf("PR_GetIPNodeByName with PR_AF_INET\n");
if (PR_GetIPNodeByName(hostName, PR_AF_INET, PR_AI_DEFAULT,
- buf, sizeof(buf), &he) == PR_FAILURE) {
+ buf, sizeof(buf), &he) == PR_FAILURE) {
fprintf(stderr, "PR_GetIPNodeByName failed\n");
exit(1);
}
PrintHostent(&he);
printf("PR_GetIPNodeByName with PR_AF_INET6\n");
if (PR_GetIPNodeByName(hostName, PR_AF_INET6, PR_AI_DEFAULT,
- buf, sizeof(buf), &he) == PR_FAILURE) {
+ buf, sizeof(buf), &he) == PR_FAILURE) {
fprintf(stderr, "PR_GetIPNodeByName failed\n");
exit(1);
}
@@ -121,10 +127,12 @@ int main(int argc, char **argv)
fprintf(stderr, "PR_EnumerateHostEnt failed\n");
exit(1);
}
- if (idx == 0) break; /* normal loop termination */
+ if (idx == 0) {
+ break; /* normal loop termination */
+ }
printf("reverse lookup\n");
if (PR_GetHostByAddr(&addr, reversebuf, sizeof(reversebuf),
- &reversehe) == PR_FAILURE) {
+ &reversehe) == PR_FAILURE) {
fprintf(stderr, "PR_GetHostByAddr failed\n");
exit(1);
}
@@ -198,11 +206,11 @@ int main(int argc, char **argv)
fprintf(stderr, "addr should be unspecified address\n");
exit(1);
}
- {
- char buf[256];
- PR_NetAddrToString(&addr, buf, 256);
- printf("IPv4 INADDRANY: %s\n", buf);
- }
+ {
+ char buf[256];
+ PR_NetAddrToString(&addr, buf, 256);
+ printf("IPv4 INADDRANY: %s\n", buf);
+ }
addr.inet.family = PR_AF_INET;
addr.inet.port = 0;
addr.inet.ip = PR_htonl(PR_INADDR_LOOPBACK);
@@ -210,11 +218,11 @@ int main(int argc, char **argv)
fprintf(stderr, "addr should be loopback address\n");
exit(1);
}
- {
- char buf[256];
- PR_NetAddrToString(&addr, buf, 256);
- printf("IPv4 LOOPBACK: %s\n", buf);
- }
+ {
+ char buf[256];
+ PR_NetAddrToString(&addr, buf, 256);
+ printf("IPv4 LOOPBACK: %s\n", buf);
+ }
if (PR_SetNetAddr(PR_IpAddrAny, PR_AF_INET6, 0, &addr) == PR_FAILURE) {
fprintf(stderr, "PR_SetNetAddr failed\n");
@@ -224,11 +232,11 @@ int main(int argc, char **argv)
fprintf(stderr, "addr should be unspecified address\n");
exit(1);
}
- {
- char buf[256];
- PR_NetAddrToString(&addr, buf, 256);
- printf("IPv6 INADDRANY: %s\n", buf);
- }
+ {
+ char buf[256];
+ PR_NetAddrToString(&addr, buf, 256);
+ printf("IPv6 INADDRANY: %s\n", buf);
+ }
if (PR_SetNetAddr(PR_IpAddrLoopback, PR_AF_INET6, 0, &addr) == PR_FAILURE) {
fprintf(stderr, "PR_SetNetAddr failed\n");
exit(1);
@@ -237,23 +245,23 @@ int main(int argc, char **argv)
fprintf(stderr, "addr should be loopback address\n");
exit(1);
}
- {
- char buf[256];
- PR_NetAddrToString(&addr, buf, 256);
- printf("IPv6 LOOPBACK: %s\n", buf);
- }
- {
- PRIPv6Addr v6addr;
- char tmp_buf[256];
+ {
+ char buf[256];
+ PR_NetAddrToString(&addr, buf, 256);
+ printf("IPv6 LOOPBACK: %s\n", buf);
+ }
+ {
+ PRIPv6Addr v6addr;
+ char tmp_buf[256];
- PR_SetNetAddr(PR_IpAddrLoopback, PR_AF_INET, 0, &addr);
+ PR_SetNetAddr(PR_IpAddrLoopback, PR_AF_INET, 0, &addr);
- PR_ConvertIPv4AddrToIPv6(addr.inet.ip, &v6addr);
- PR_SetNetAddr(PR_IpAddrAny, PR_AF_INET6, 0, &addr);
- addr.ipv6.ip = v6addr;
- PR_NetAddrToString(&addr, tmp_buf, 256);
- printf("IPv4-mapped IPv6 LOOPBACK: %s\n", tmp_buf);
- }
+ PR_ConvertIPv4AddrToIPv6(addr.inet.ip, &v6addr);
+ PR_SetNetAddr(PR_IpAddrAny, PR_AF_INET6, 0, &addr);
+ addr.ipv6.ip = v6addr;
+ PR_NetAddrToString(&addr, tmp_buf, 256);
+ printf("IPv4-mapped IPv6 LOOPBACK: %s\n", tmp_buf);
+ }
printf("PASS\n");
return 0;
}
diff --git a/pr/tests/getproto.c b/pr/tests/getproto.c
index f63a4dfd..1a33b1f2 100644
--- a/pr/tests/getproto.c
+++ b/pr/tests/getproto.c
@@ -39,7 +39,9 @@ int main(int argc, char **argv)
prstderr,"tcp is usually 6, but is %d on this machine\n",
proto.p_num);
}
- else PR_fprintf(prstderr, "tcp is protocol number %d\n", proto.p_num);
+ else {
+ PR_fprintf(prstderr, "tcp is protocol number %d\n", proto.p_num);
+ }
rv = PR_GetProtoByName("udp", buf, sizeof(buf), &proto);
if (PR_FAILURE == rv) {
@@ -51,7 +53,9 @@ int main(int argc, char **argv)
prstderr, "udp is usually 17, but is %d on this machine\n",
proto.p_num);
}
- else PR_fprintf(prstderr, "udp is protocol number %d\n", proto.p_num);
+ else {
+ PR_fprintf(prstderr, "udp is protocol number %d\n", proto.p_num);
+ }
rv = PR_GetProtoByNumber(6, buf, sizeof(buf), &proto);
if (PR_FAILURE == rv) {
@@ -63,7 +67,9 @@ int main(int argc, char **argv)
prstderr, "Protocol number 6 is usually tcp, but is %s"
" on this platform\n", proto.p_name);
}
- else PR_fprintf(prstderr, "Protocol number 6 is %s\n", proto.p_name);
+ else {
+ PR_fprintf(prstderr, "Protocol number 6 is %s\n", proto.p_name);
+ }
rv = PR_GetProtoByNumber(17, buf, sizeof(buf), &proto);
if (PR_FAILURE == rv) {
@@ -75,7 +81,9 @@ int main(int argc, char **argv)
prstderr, "Protocol number 17 is usually udp, but is %s"
" on this platform\n", proto.p_name);
}
- else PR_fprintf(prstderr, "Protocol number 17 is %s\n", proto.p_name);
+ else {
+ PR_fprintf(prstderr, "Protocol number 17 is %s\n", proto.p_name);
+ }
PR_fprintf(prstderr, (failed) ? "FAILED\n" : "PASSED\n");
return (failed) ? 1 : 0;
diff --git a/pr/tests/i2l.c b/pr/tests/i2l.c
index 8f41fa34..a28cd16a 100644
--- a/pr/tests/i2l.c
+++ b/pr/tests/i2l.c
@@ -46,21 +46,23 @@ static PRIntn PR_CALLBACK RealMain(PRIntn argc, char **argv)
while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
- if (PL_OPT_BAD == os) continue;
+ if (PL_OPT_BAD == os) {
+ continue;
+ }
switch (opt->option)
{
- case 'i': /* signed integer */
- si.i = (PRInt32)atoi(opt->value);
- bsi = PR_TRUE;
- break;
- case 'u': /* unsigned */
- ui.i = (PRUint32)atoi(opt->value);
- bui = PR_TRUE;
- break;
- case 'h': /* user wants some guidance */
- default:
- Help(); /* so give him an earful */
- return 2; /* but not a lot else */
+ case 'i': /* signed integer */
+ si.i = (PRInt32)atoi(opt->value);
+ bsi = PR_TRUE;
+ break;
+ case 'u': /* unsigned */
+ ui.i = (PRUint32)atoi(opt->value);
+ bui = PR_TRUE;
+ break;
+ case 'h': /* user wants some guidance */
+ default:
+ Help(); /* so give him an earful */
+ return 2; /* but not a lot else */
}
}
PL_DestroyOptState(opt);
diff --git a/pr/tests/initclk.c b/pr/tests/initclk.c
index 37e4c050..65d8b17e 100644
--- a/pr/tests/initclk.c
+++ b/pr/tests/initclk.c
@@ -49,13 +49,13 @@ int main(int argc, char **argv)
PR_ASSERT(NULL != cv2);
start = PR_IntervalNow();
thread = PR_CreateThread(
- PR_USER_THREAD,
- ThreadFunc,
- NULL,
- PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD,
- PR_JOINABLE_THREAD,
- 0);
+ PR_USER_THREAD,
+ ThreadFunc,
+ NULL,
+ PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD,
+ PR_JOINABLE_THREAD,
+ 0);
PR_ASSERT(NULL != thread);
PR_Lock(lock2);
PR_WaitCondVar(cv2, PR_MillisecondsToInterval(LONG_TIMEOUT));
@@ -66,12 +66,12 @@ int main(int argc, char **argv)
/* Allow 100ms imprecision */
if (elapsed_ms < LONG_TIMEOUT - 100 || elapsed_ms > LONG_TIMEOUT + 100) {
printf("Elapsed time should be %u ms but is %u ms\n",
- LONG_TIMEOUT, elapsed_ms);
+ LONG_TIMEOUT, elapsed_ms);
printf("FAIL\n");
exit(1);
}
- printf("Elapsed time: %u ms, expected time: %u ms\n",
- LONG_TIMEOUT, elapsed_ms);
+ printf("Elapsed time: %u ms, expected time: %u ms\n",
+ LONG_TIMEOUT, elapsed_ms);
printf("PASS\n");
return 0;
}
diff --git a/pr/tests/inrval.c b/pr/tests/inrval.c
index c9192221..52f7b71d 100644
--- a/pr/tests/inrval.c
+++ b/pr/tests/inrval.c
@@ -8,12 +8,12 @@
** description: Interval conversion test.
** Modification History:
** 15-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.
**/
/***********************************************************************
** Includes
@@ -45,25 +45,25 @@ static void TestConversions(void)
{
PRIntervalTime ticks = PR_TicksPerSecond();
- if (debug_mode) {
- PR_fprintf(output, "PR_TicksPerSecond: %ld\n\n", ticks);
- PR_fprintf(output, "PR_SecondsToInterval(1): %ld\n", PR_SecondsToInterval(1));
- PR_fprintf(output, "PR_MillisecondsToInterval(1000): %ld\n", PR_MillisecondsToInterval(1000));
- PR_fprintf(output, "PR_MicrosecondsToInterval(1000000): %ld\n\n", PR_MicrosecondsToInterval(1000000));
-
- PR_fprintf(output, "PR_SecondsToInterval(3): %ld\n", PR_SecondsToInterval(3));
- PR_fprintf(output, "PR_MillisecondsToInterval(3000): %ld\n", PR_MillisecondsToInterval(3000));
- PR_fprintf(output, "PR_MicrosecondsToInterval(3000000): %ld\n\n", PR_MicrosecondsToInterval(3000000));
-
- PR_fprintf(output, "PR_IntervalToSeconds(%ld): %ld\n", ticks, PR_IntervalToSeconds(ticks));
- PR_fprintf(output, "PR_IntervalToMilliseconds(%ld): %ld\n", ticks, PR_IntervalToMilliseconds(ticks));
- PR_fprintf(output, "PR_IntervalToMicroseconds(%ld): %ld\n\n", ticks, PR_IntervalToMicroseconds(ticks));
-
- ticks *= 3;
- PR_fprintf(output, "PR_IntervalToSeconds(%ld): %ld\n", ticks, PR_IntervalToSeconds(ticks));
- PR_fprintf(output, "PR_IntervalToMilliseconds(%ld): %ld\n", ticks, PR_IntervalToMilliseconds(ticks));
- PR_fprintf(output, "PR_IntervalToMicroseconds(%ld): %ld\n\n", ticks, PR_IntervalToMicroseconds(ticks));
- } /*end debug mode */
+ if (debug_mode) {
+ PR_fprintf(output, "PR_TicksPerSecond: %ld\n\n", ticks);
+ PR_fprintf(output, "PR_SecondsToInterval(1): %ld\n", PR_SecondsToInterval(1));
+ PR_fprintf(output, "PR_MillisecondsToInterval(1000): %ld\n", PR_MillisecondsToInterval(1000));
+ PR_fprintf(output, "PR_MicrosecondsToInterval(1000000): %ld\n\n", PR_MicrosecondsToInterval(1000000));
+
+ PR_fprintf(output, "PR_SecondsToInterval(3): %ld\n", PR_SecondsToInterval(3));
+ PR_fprintf(output, "PR_MillisecondsToInterval(3000): %ld\n", PR_MillisecondsToInterval(3000));
+ PR_fprintf(output, "PR_MicrosecondsToInterval(3000000): %ld\n\n", PR_MicrosecondsToInterval(3000000));
+
+ PR_fprintf(output, "PR_IntervalToSeconds(%ld): %ld\n", ticks, PR_IntervalToSeconds(ticks));
+ PR_fprintf(output, "PR_IntervalToMilliseconds(%ld): %ld\n", ticks, PR_IntervalToMilliseconds(ticks));
+ PR_fprintf(output, "PR_IntervalToMicroseconds(%ld): %ld\n\n", ticks, PR_IntervalToMicroseconds(ticks));
+
+ ticks *= 3;
+ PR_fprintf(output, "PR_IntervalToSeconds(%ld): %ld\n", ticks, PR_IntervalToSeconds(ticks));
+ PR_fprintf(output, "PR_IntervalToMilliseconds(%ld): %ld\n", ticks, PR_IntervalToMilliseconds(ticks));
+ PR_fprintf(output, "PR_IntervalToMicroseconds(%ld): %ld\n\n", ticks, PR_IntervalToMicroseconds(ticks));
+ } /*end debug mode */
} /* TestConversions */
static void TestIntervalOverhead(void)
@@ -72,8 +72,9 @@ static void TestIntervalOverhead(void)
PRUint32 elapsed, per_call, loops = 1000000;
PRIntervalTime timeout, timein = PR_IntervalNow();
- while (--loops > 0)
+ while (--loops > 0) {
timeout = PR_IntervalNow();
+ }
elapsed = 1000U * PR_IntervalToMicroseconds(timeout - timein);
per_call = elapsed / 1000000U;
@@ -91,8 +92,9 @@ static void TestNowOverhead(void)
LL_I2L(ten26th, 1000000);
timein = PR_Now();
- while (--loops > 0)
+ while (--loops > 0) {
timeout = PR_Now();
+ }
LL_SUB(elapsed, timeout, timein);
LL_MUL(elapsed, elapsed, ten23rd);
@@ -124,54 +126,62 @@ static void TestIntervals(void)
LL_DIV(elapsed, elapsed, thousand);
LL_L2UI(delta, elapsed);
if (debug_mode) PR_fprintf(output,
- "TestIntervals: %swaiting %ld seconds took %ld msecs\n",
- ((rv == PR_SUCCESS) ? "" : "FAILED "), seconds, delta);
+ "TestIntervals: %swaiting %ld seconds took %ld msecs\n",
+ ((rv == PR_SUCCESS) ? "" : "FAILED "), seconds, delta);
}
PR_DestroyCondVar(cv);
PR_DestroyLock(ml);
- if (debug_mode) PR_fprintf(output, "\n");
+ if (debug_mode) {
+ PR_fprintf(output, "\n");
+ }
} /* TestIntervals */
static PRIntn PR_CALLBACK RealMain(int argc, char** argv)
{
PRUint32 vcpu, cpus = 0, loops = 1000;
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
- /* main test */
+ /* main test */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "dl:c:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "dl:c:");
+ 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_mode = 1;
- break;
- case 'c': /* concurrency counter */
- cpus = atoi(opt->value);
- break;
- case 'l': /* loop counter */
- loops = atoi(opt->value);
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ case 'c': /* concurrency counter */
+ cpus = atoi(opt->value);
+ break;
+ case 'l': /* loop counter */
+ loops = atoi(opt->value);
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
output = PR_GetSpecialFD(PR_StandardOutput);
PR_fprintf(output, "inrval: Examine stdout to determine results.\n");
- if (cpus == 0) cpus = 8;
- if (loops == 0) loops = 1000;
+ if (cpus == 0) {
+ cpus = 8;
+ }
+ if (loops == 0) {
+ loops = 1000;
+ }
if (debug_mode > 0)
{
@@ -181,8 +191,9 @@ static PRIntn PR_CALLBACK RealMain(int argc, char** argv)
for (vcpu = 1; vcpu <= cpus; vcpu += cpus - 1)
{
- if (debug_mode)
+ if (debug_mode) {
PR_fprintf(output, "\nInrval: Using %d CPU(s)\n\n", vcpu);
+ }
PR_SetConcurrency(vcpu);
TestNowOverhead();
diff --git a/pr/tests/instrumt.c b/pr/tests/instrumt.c
index f8e42e9b..e1ca94d0 100644
--- a/pr/tests/instrumt.c
+++ b/pr/tests/instrumt.c
@@ -95,8 +95,8 @@ static void ListCounters(void)
PR_GET_COUNTER_NAME_FROM_HANDLE( rh, qname, rname, desc );
PR_GET_COUNTER(tCtr, rh);
PR_LOG( lm, msgLevel,
- ( "QName: %s RName: %s Desc: %s Value: %ld\n",
- qn, rn, dn, tCtr ));
+ ( "QName: %s RName: %s Desc: %s Value: %ld\n",
+ qn, rn, dn, tCtr ));
PR_FIND_NEXT_COUNTER_RNAME(rh, rh, qh );
}
PR_FIND_NEXT_COUNTER_QNAME(qh, qh);
@@ -121,8 +121,8 @@ static void ListTraces(void)
{
PR_GET_TRACE_NAME_FROM_HANDLE( rh, qname, rname, desc );
PR_LOG( lm, msgLevel,
- ( "QName: %s RName: %s Desc: %s",
- qn, rn, dn ));
+ ( "QName: %s RName: %s Desc: %s",
+ qn, rn, dn ));
PR_FIND_NEXT_TRACE_RNAME(rh, rh, qh );
}
PR_FIND_NEXT_TRACE_QNAME(qh, qh);
@@ -145,33 +145,33 @@ static void PR_CALLBACK CountSomething( void *arg )
PRInt32 i;
PR_LOG( lm, msgLevel,
- ("CountSomething: begin thread %ld", switchVar ));
+ ("CountSomething: begin thread %ld", switchVar ));
for ( i = 0; i < COUNT_LIMIT ; i++)
{
switch ( switchVar )
{
- case 1 :
- PR_INCREMENT_COUNTER( hCounter );
- break;
- case 2 :
- PR_DECREMENT_COUNTER( hCounter );
- break;
- case 3 :
- PR_ADD_TO_COUNTER( hCounter, 1 );
- break;
- case 4 :
- PR_SUBTRACT_FROM_COUNTER( hCounter, 1 );
- break;
- default :
- PR_ASSERT( 0 );
- break;
+ case 1 :
+ PR_INCREMENT_COUNTER( hCounter );
+ break;
+ case 2 :
+ PR_DECREMENT_COUNTER( hCounter );
+ break;
+ case 3 :
+ PR_ADD_TO_COUNTER( hCounter, 1 );
+ break;
+ case 4 :
+ PR_SUBTRACT_FROM_COUNTER( hCounter, 1 );
+ break;
+ default :
+ PR_ASSERT( 0 );
+ break;
}
PR_TRACE( hTrace, CountLoop, switchVar, i, 0, 0, 0, 0, 0 );
} /* end for() */
PR_LOG( lm, msgLevel,
- ("CounterSomething: end thread %ld", switchVar ));
+ ("CounterSomething: end thread %ld", switchVar ));
PR_EnterMonitor(mon);
--activeThreads;
@@ -192,7 +192,7 @@ static void CounterTest( void )
PR_DEFINE_COUNTER( zCounter );
PR_LOG( lm, msgLevel,
- ("Begin CounterTest"));
+ ("Begin CounterTest"));
/*
** Test Get and Set of a counter.
@@ -205,7 +205,7 @@ static void CounterTest( void )
{
failed = PR_TRUE;
PR_LOG( lm, msgLevel,
- ("Counter set/get failed"));
+ ("Counter set/get failed"));
}
activeThreads += 4;
@@ -214,40 +214,40 @@ static void CounterTest( void )
PR_GET_COUNTER_HANDLE_FROM_NAME( tc, "Atomic", "SMP Tests" );
PR_ASSERT( tc == hCounter );
- t1 = PR_CreateThread(PR_USER_THREAD,
- CountSomething, &one,
- PR_PRIORITY_NORMAL,
- PR_GLOBAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0);
- PR_ASSERT(t1);
-
- t2 = PR_CreateThread(PR_USER_THREAD,
- CountSomething, &two,
- PR_PRIORITY_NORMAL,
- PR_GLOBAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0);
- PR_ASSERT(t2);
-
- t3 = PR_CreateThread(PR_USER_THREAD,
- CountSomething, &three,
- PR_PRIORITY_NORMAL,
- PR_GLOBAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0);
- PR_ASSERT(t3);
-
- t4 = PR_CreateThread(PR_USER_THREAD,
- CountSomething, &four,
- PR_PRIORITY_NORMAL,
- PR_GLOBAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0);
- PR_ASSERT(t4);
+ t1 = PR_CreateThread(PR_USER_THREAD,
+ CountSomething, &one,
+ PR_PRIORITY_NORMAL,
+ PR_GLOBAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0);
+ PR_ASSERT(t1);
+
+ t2 = PR_CreateThread(PR_USER_THREAD,
+ CountSomething, &two,
+ PR_PRIORITY_NORMAL,
+ PR_GLOBAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0);
+ PR_ASSERT(t2);
+
+ t3 = PR_CreateThread(PR_USER_THREAD,
+ CountSomething, &three,
+ PR_PRIORITY_NORMAL,
+ PR_GLOBAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0);
+ PR_ASSERT(t3);
+
+ t4 = PR_CreateThread(PR_USER_THREAD,
+ CountSomething, &four,
+ PR_PRIORITY_NORMAL,
+ PR_GLOBAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0);
+ PR_ASSERT(t4);
PR_LOG( lm, msgLevel,
- ("Counter Threads started"));
+ ("Counter Threads started"));
ListCounters();
return;
@@ -288,19 +288,19 @@ static void PR_CALLBACK SampleTrace( void *arg )
{
rc = PR_GetTraceEntries( foundEntries, NUM_TRACE_RECORDS, &found);
PR_LOG( lm, msgLevel,
- ("SampleTrace: Lost Data: %ld found: %ld", rc, found ));
+ ("SampleTrace: Lost Data: %ld found: %ld", rc, found ));
if ( found != 0)
{
for ( i = 0 ; i < found; i++ )
{
PR_LOG( lm, msgLevel,
- ("SampleTrace, detail: Thread: %p, Time: %llX, UD0: %ld, UD1: %ld, UD2: %8.8ld",
- (foundEntries +i)->thread,
- (foundEntries +i)->time,
- (foundEntries +i)->userData[0],
- (foundEntries +i)->userData[1],
- (foundEntries +i)->userData[2] ));
+ ("SampleTrace, detail: Thread: %p, Time: %llX, UD0: %ld, UD1: %ld, UD2: %8.8ld",
+ (foundEntries +i)->thread,
+ (foundEntries +i)->time,
+ (foundEntries +i)->userData[0],
+ (foundEntries +i)->userData[1],
+ (foundEntries +i)->userData[2] ));
}
}
PR_Sleep(PR_MillisecondsToInterval(50));
@@ -315,7 +315,7 @@ static void PR_CALLBACK SampleTrace( void *arg )
PR_ExitMonitor(mon);
PR_LOG( lm, msgLevel,
- ("SampleTrace(): exiting"));
+ ("SampleTrace(): exiting"));
#endif
return;
@@ -332,7 +332,7 @@ static void TraceTest( void )
PRThread *t1, *t2;
PR_LOG( lm, msgLevel,
- ("Begin TraceTest"));
+ ("Begin TraceTest"));
size = SMALL_TRACE_BUFSIZE;
PR_SET_TRACE_OPTION( PRTraceBufSize, &size );
@@ -361,21 +361,21 @@ static void TraceTest( void )
activeThreads += 2;
- t1 = PR_CreateThread(PR_USER_THREAD,
- RecordTrace, NULL,
- PR_PRIORITY_NORMAL,
- PR_GLOBAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0);
- PR_ASSERT(t1);
-
- t2 = PR_CreateThread(PR_USER_THREAD,
- SampleTrace, 0,
- PR_PRIORITY_NORMAL,
- PR_GLOBAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0);
- PR_ASSERT(t2);
+ t1 = PR_CreateThread(PR_USER_THREAD,
+ RecordTrace, NULL,
+ PR_PRIORITY_NORMAL,
+ PR_GLOBAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0);
+ PR_ASSERT(t1);
+
+ t2 = PR_CreateThread(PR_USER_THREAD,
+ SampleTrace, 0,
+ PR_PRIORITY_NORMAL,
+ PR_GLOBAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0);
+ PR_ASSERT(t2);
ListTraces();
@@ -383,7 +383,7 @@ static void TraceTest( void )
PR_ASSERT( th == hTrace );
PR_LOG( lm, msgLevel,
- ("End TraceTest"));
+ ("End TraceTest"));
return;
} /* end TraceTest() */
@@ -394,7 +394,7 @@ static void TraceTest( void )
static void OrderedLockTest( void )
{
PR_LOG( lm, msgLevel,
- ("Begin OrderedLockTest"));
+ ("Begin OrderedLockTest"));
} /* end OrderedLockTest() */
@@ -408,23 +408,25 @@ int main(int argc, char **argv)
PLOptState *opt = PL_CreateOptState(argc, argv, "hdv:");
lm = PR_NewLogModule("Test");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ 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 */
- msgLevel = (PRLogModuleLevel)atol( opt->value);
- break;
- case 'h': /* help message */
- Help();
- help = PR_TRUE;
- break;
- default:
- break;
+ case 'v': /* verbose mode */
+ msgLevel = (PRLogModuleLevel)atol( opt->value);
+ break;
+ case 'h': /* help message */
+ Help();
+ help = PR_TRUE;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
PR_CREATE_TRACE( hTrace, "TraceTest", "tt1", "A description for the trace test" );
mon = PR_NewMonitor();
@@ -436,9 +438,10 @@ int main(int argc, char **argv)
/* Wait for all threads to exit */
while ( activeThreads > 0 ) {
- if ( activeThreads == 1 )
+ if ( activeThreads == 1 ) {
PR_SET_TRACE_OPTION( PRTraceStopRecording, NULL );
- PR_Wait(mon, PR_INTERVAL_NO_TIMEOUT);
+ }
+ PR_Wait(mon, PR_INTERVAL_NO_TIMEOUT);
PR_GET_COUNTER( counter, hCounter );
}
PR_ExitMonitor( mon );
@@ -451,7 +454,7 @@ int main(int argc, char **argv)
{
failed = PR_TRUE;
PR_LOG( lm, msgLevel,
- ("Expected counter == 0, found: %ld", counter));
+ ("Expected counter == 0, found: %ld", counter));
printf("FAIL\n");
}
else
diff --git a/pr/tests/intrio.c b/pr/tests/intrio.c
index 691ed815..23d834d6 100644
--- a/pr/tests/intrio.c
+++ b/pr/tests/intrio.c
@@ -62,7 +62,7 @@ static void PR_CALLBACK IOThread(void *arg)
}
if (PR_GetError() != PR_PENDING_INTERRUPT_ERROR) {
fprintf(stderr, "PR_Accept failed (%d, %d)\n",
- PR_GetError(), PR_GetOSError());
+ PR_GetError(), PR_GetOSError());
exit(1);
}
printf("PR_Accept() is interrupted as expected\n");
@@ -77,23 +77,24 @@ static void Test(PRThreadScope scope1, PRThreadScope scope2)
PRThread *iothread, *abortio;
printf("A %s thread will be interrupted by a %s thread\n",
- (scope1 == PR_LOCAL_THREAD ? "local" : "global"),
- (scope2 == PR_LOCAL_THREAD ? "local" : "global"));
+ (scope1 == PR_LOCAL_THREAD ? "local" : "global"),
+ (scope2 == PR_LOCAL_THREAD ? "local" : "global"));
iothread_ready = PR_FALSE;
iothread = PR_CreateThread(
- PR_USER_THREAD, IOThread, NULL, PR_PRIORITY_NORMAL,
- scope1, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, IOThread, NULL, PR_PRIORITY_NORMAL,
+ scope1, PR_JOINABLE_THREAD, 0);
if (iothread == NULL) {
fprintf(stderr, "cannot create thread\n");
exit(1);
}
PR_Lock(lock);
- while (!iothread_ready)
+ while (!iothread_ready) {
PR_WaitCondVar(cvar, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_Unlock(lock);
abortio = PR_CreateThread(
- PR_USER_THREAD, AbortIO, iothread, PR_PRIORITY_NORMAL,
- scope2, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, AbortIO, iothread, PR_PRIORITY_NORMAL,
+ scope2, PR_JOINABLE_THREAD, 0);
if (abortio == NULL) {
fprintf(stderr, "cannot create thread\n");
exit(1);
diff --git a/pr/tests/intrupt.c b/pr/tests/intrupt.c
index ce5e06d7..950d30d4 100644
--- a/pr/tests/intrupt.c
+++ b/pr/tests/intrupt.c
@@ -40,22 +40,30 @@ static void PR_CALLBACK AbortCV(void *arg)
/* some other thread (main) is doing the interrupt */
PR_Lock(ml);
rv = PR_WaitCondVar(cv, PR_INTERVAL_NO_TIMEOUT);
- if (debug_mode) printf( "Expected interrupt on wait CV and ");
+ if (debug_mode) {
+ printf( "Expected interrupt on wait CV and ");
+ }
if (PR_FAILURE == rv)
{
if (PR_PENDING_INTERRUPT_ERROR == PR_GetError())
{
- if (debug_mode) printf("got it\n");
+ if (debug_mode) {
+ printf("got it\n");
+ }
}
else
{
- if (debug_mode) printf("got random error\n");
+ if (debug_mode) {
+ printf("got random error\n");
+ }
passed = PR_FALSE;
}
}
else
{
- if (debug_mode) printf("got a successful completion\n");
+ if (debug_mode) {
+ printf("got a successful completion\n");
+ }
passed = PR_FALSE;
}
@@ -88,22 +96,30 @@ static void PR_CALLBACK AbortCV(void *arg)
/* set, then wait - interrupt - then wait again */
PR_Interrupt(me);
rv = PR_WaitCondVar(cv, 10);
- if (debug_mode) printf( "Expected interrupt on wait CV and ");
+ if (debug_mode) {
+ printf( "Expected interrupt on wait CV and ");
+ }
if (PR_FAILURE == rv)
{
if (PR_PENDING_INTERRUPT_ERROR == PR_GetError())
{
- if (debug_mode) printf("got it\n");
+ if (debug_mode) {
+ printf("got it\n");
+ }
}
else
{
- if (debug_mode) printf("failed\n");
+ if (debug_mode) {
+ printf("failed\n");
+ }
passed = PR_FALSE;
}
}
else
{
- if (debug_mode) printf("got a successful completion\n");
+ if (debug_mode) {
+ printf("got a successful completion\n");
+ }
passed = PR_FALSE;
}
@@ -152,11 +168,13 @@ static void setup_listen_socket(PRFileDesc **listner, PRNetAddr *netaddr)
rv = PR_Listen(*listner, 5);
- if (PR_GetSockName(*listner, netaddr) < 0) {
- if (debug_mode) printf("intrupt: ERROR - PR_GetSockName failed\n");
- passed = PR_FALSE;
- return;
- }
+ if (PR_GetSockName(*listner, netaddr) < 0) {
+ if (debug_mode) {
+ printf("intrupt: ERROR - PR_GetSockName failed\n");
+ }
+ passed = PR_FALSE;
+ return;
+ }
}
@@ -167,11 +185,11 @@ static void PR_CALLBACK IntrBlock(void *arg)
PRFileDesc *listner;
/* some other thread (main) is doing the interrupt */
- /* block the interrupt */
- PR_BlockInterrupt();
+ /* block the interrupt */
+ PR_BlockInterrupt();
PR_Lock(ml);
rv = PR_WaitCondVar(cv, PR_SecondsToInterval(4));
- PR_Unlock(ml);
+ PR_Unlock(ml);
if (debug_mode)
{
printf("Expected success on wait CV and ");
@@ -180,30 +198,39 @@ static void PR_CALLBACK IntrBlock(void *arg)
printf(
"%s\n", (PR_PENDING_INTERRUPT_ERROR == PR_GetError()) ?
"got interrupted" : "got a random failure");
- } else
- printf("got it\n");
+ } else {
+ printf("got it\n");
+ }
}
passed = ((PR_TRUE == passed) && (PR_SUCCESS == rv)) ? PR_TRUE : PR_FALSE;
- setup_listen_socket(&listner, &netaddr);
- PR_UnblockInterrupt();
+ setup_listen_socket(&listner, &netaddr);
+ PR_UnblockInterrupt();
if (PR_Accept(listner, &netaddr, PR_INTERVAL_NO_TIMEOUT) == NULL)
{
PRInt32 error = PR_GetError();
- if (debug_mode) printf("Expected interrupt on PR_Accept() and ");
+ if (debug_mode) {
+ printf("Expected interrupt on PR_Accept() and ");
+ }
if (PR_PENDING_INTERRUPT_ERROR == error)
{
- if (debug_mode) printf("got it\n");
+ if (debug_mode) {
+ printf("got it\n");
+ }
}
else
{
- if (debug_mode) printf("failed\n");
+ if (debug_mode) {
+ printf("failed\n");
+ }
passed = PR_FALSE;
}
}
else
{
- if (debug_mode) printf("Failed to interrupt PR_Accept()\n");
+ if (debug_mode) {
+ printf("Failed to interrupt PR_Accept()\n");
+ }
passed = PR_FALSE;
}
@@ -221,10 +248,12 @@ void PR_CALLBACK Intrupt(void *arg)
cv = PR_NewCondVar(ml);
/* Part I */
- if (debug_mode) printf("Part I\n");
+ if (debug_mode) {
+ printf("Part I\n");
+ }
abortCV = PR_CreateThread(
- PR_USER_THREAD, AbortCV, 0, PR_PRIORITY_NORMAL,
- thread_scope, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, AbortCV, 0, PR_PRIORITY_NORMAL,
+ thread_scope, PR_JOINABLE_THREAD, 0);
PR_Sleep(PR_SecondsToInterval(2));
rv = PR_Interrupt(abortCV);
@@ -233,42 +262,58 @@ void PR_CALLBACK Intrupt(void *arg)
PR_ASSERT(PR_SUCCESS == rv);
/* Part II */
- if (debug_mode) printf("Part II\n");
+ if (debug_mode) {
+ printf("Part II\n");
+ }
abortJoin = PR_CreateThread(
- PR_USER_THREAD, AbortJoin, 0, PR_PRIORITY_NORMAL,
- thread_scope, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, AbortJoin, 0, PR_PRIORITY_NORMAL,
+ thread_scope, PR_JOINABLE_THREAD, 0);
PR_Sleep(PR_SecondsToInterval(2));
- if (debug_mode) printf("Expecting to interrupt an exited thread ");
+ if (debug_mode) {
+ printf("Expecting to interrupt an exited thread ");
+ }
rv = PR_Interrupt(abortJoin);
PR_ASSERT(PR_SUCCESS == rv);
rv = PR_JoinThread(abortJoin);
PR_ASSERT(PR_SUCCESS == rv);
- if (debug_mode) printf("and succeeded\n");
+ if (debug_mode) {
+ printf("and succeeded\n");
+ }
/* Part III */
- if (debug_mode) printf("Part III\n");
- setup_listen_socket(&listner, &netaddr);
+ if (debug_mode) {
+ printf("Part III\n");
+ }
+ setup_listen_socket(&listner, &netaddr);
abortIO = PR_CreateThread(
- PR_USER_THREAD, AbortIO, PR_GetCurrentThread(), PR_PRIORITY_NORMAL,
- thread_scope, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, AbortIO, PR_GetCurrentThread(), PR_PRIORITY_NORMAL,
+ thread_scope, PR_JOINABLE_THREAD, 0);
if (PR_Accept(listner, &netaddr, PR_INTERVAL_NO_TIMEOUT) == NULL)
{
PRInt32 error = PR_GetError();
- if (debug_mode) printf("Expected interrupt on PR_Accept() and ");
+ if (debug_mode) {
+ printf("Expected interrupt on PR_Accept() and ");
+ }
if (PR_PENDING_INTERRUPT_ERROR == error)
{
- if (debug_mode) printf("got it\n");
+ if (debug_mode) {
+ printf("got it\n");
+ }
}
else
{
- if (debug_mode) printf("failed\n");
+ if (debug_mode) {
+ printf("failed\n");
+ }
passed = PR_FALSE;
}
}
else
{
- if (debug_mode) printf("Failed to interrupt PR_Accept()\n");
+ if (debug_mode) {
+ printf("Failed to interrupt PR_Accept()\n");
+ }
passed = PR_FALSE;
}
@@ -277,10 +322,12 @@ void PR_CALLBACK Intrupt(void *arg)
rv = PR_JoinThread(abortIO);
PR_ASSERT(PR_SUCCESS == rv);
/* Part VI */
- if (debug_mode) printf("Part VI\n");
+ if (debug_mode) {
+ printf("Part VI\n");
+ }
intrBlock = PR_CreateThread(
- PR_USER_THREAD, IntrBlock, 0, PR_PRIORITY_NORMAL,
- thread_scope, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, IntrBlock, 0, PR_PRIORITY_NORMAL,
+ thread_scope, PR_JOINABLE_THREAD, 0);
PR_Sleep(PR_SecondsToInterval(2));
rv = PR_Interrupt(intrBlock);
@@ -295,26 +342,28 @@ void PR_CALLBACK Intrupt(void *arg)
int main(int argc, char **argv)
{
PRThread *intrupt;
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "dG");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "dG");
+ 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_mode = PR_TRUE;
- break;
- case 'G': /* use global threads */
- thread_scope = PR_GLOBAL_THREAD;
- break;
+ case 'd': /* debug mode */
+ debug_mode = PR_TRUE;
+ break;
+ case 'G': /* use global threads */
+ thread_scope = PR_GLOBAL_THREAD;
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
PR_STDIO_INIT();
intrupt = PR_CreateThread(
- PR_USER_THREAD, Intrupt, NULL, PR_PRIORITY_NORMAL,
- thread_scope, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, Intrupt, NULL, PR_PRIORITY_NORMAL,
+ thread_scope, PR_JOINABLE_THREAD, 0);
if (intrupt == NULL) {
fprintf(stderr, "cannot create thread\n");
passed = PR_FALSE;
@@ -324,7 +373,7 @@ int main(int argc, char **argv)
PR_ASSERT(rv == PR_SUCCESS);
}
printf("%s\n", ((passed) ? "PASSED" : "FAILED"));
- return ((passed) ? 0 : 1);
+ return ((passed) ? 0 : 1);
} /* main */
/* intrupt.c */
diff --git a/pr/tests/io_timeout.c b/pr/tests/io_timeout.c
index 0ac4eef6..19d3daec 100644
--- a/pr/tests/io_timeout.c
+++ b/pr/tests/io_timeout.c
@@ -11,10 +11,10 @@
**
** Modification History:
** 14-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.
***********************************************************************/
/***********************************************************************
** Includes
@@ -40,9 +40,9 @@ typedef struct threadInfo {
PRIntn failed_already = 0;
PRIntn debug_mode = 0;
-#define LOCAL_SCOPE_STRING "LOCAL scope"
-#define GLOBAL_SCOPE_STRING "GLOBAL scope"
-#define GLOBAL_BOUND_SCOPE_STRING "GLOBAL_BOUND scope"
+#define LOCAL_SCOPE_STRING "LOCAL scope"
+#define GLOBAL_SCOPE_STRING "GLOBAL scope"
+#define GLOBAL_BOUND_SCOPE_STRING "GLOBAL_BOUND scope"
void
thread_main(void *_info)
@@ -53,35 +53,37 @@ thread_main(void *_info)
PRFileDesc *listenSock = NULL;
PRFileDesc *clientSock;
PRStatus rv;
- PRThreadScope tscope;
- char *scope_str;
-
-
- if (debug_mode)
- printf("thread %d is alive\n", info->id);
- tscope = PR_GetThreadScope(PR_GetCurrentThread());
-
- switch(tscope) {
- case PR_LOCAL_THREAD:
- scope_str = LOCAL_SCOPE_STRING;
- break;
- case PR_GLOBAL_THREAD:
- scope_str = GLOBAL_SCOPE_STRING;
- break;
- case PR_GLOBAL_BOUND_THREAD:
- scope_str = GLOBAL_BOUND_SCOPE_STRING;
- break;
- default:
- PR_NOT_REACHED("Invalid thread scope");
- break;
- }
- printf("thread id %d, scope %s\n", info->id, scope_str);
+ PRThreadScope tscope;
+ char *scope_str;
+
+
+ if (debug_mode) {
+ printf("thread %d is alive\n", info->id);
+ }
+ tscope = PR_GetThreadScope(PR_GetCurrentThread());
+
+ switch(tscope) {
+ case PR_LOCAL_THREAD:
+ scope_str = LOCAL_SCOPE_STRING;
+ break;
+ case PR_GLOBAL_THREAD:
+ scope_str = GLOBAL_SCOPE_STRING;
+ break;
+ case PR_GLOBAL_BOUND_THREAD:
+ scope_str = GLOBAL_BOUND_SCOPE_STRING;
+ break;
+ default:
+ PR_NOT_REACHED("Invalid thread scope");
+ break;
+ }
+ printf("thread id %d, scope %s\n", info->id, scope_str);
listenSock = PR_NewTCPSocket();
if (!listenSock) {
- if (debug_mode)
- printf("unable to create listen socket\n");
- failed_already=1;
+ if (debug_mode) {
+ printf("unable to create listen socket\n");
+ }
+ failed_already=1;
goto dead;
}
@@ -90,57 +92,61 @@ thread_main(void *_info)
listenAddr.inet.ip = PR_htonl(PR_INADDR_ANY);
rv = PR_Bind(listenSock, &listenAddr);
if (rv == PR_FAILURE) {
- if (debug_mode)
- printf("unable to bind\n");
- failed_already=1;
+ if (debug_mode) {
+ printf("unable to bind\n");
+ }
+ failed_already=1;
goto dead;
}
rv = PR_Listen(listenSock, 4);
if (rv == PR_FAILURE) {
- if (debug_mode)
- printf("unable to listen\n");
- failed_already=1;
+ if (debug_mode) {
+ printf("unable to listen\n");
+ }
+ failed_already=1;
goto dead;
}
- if (debug_mode)
- printf("thread %d going into accept for %d seconds\n",
- info->id, info->accept_timeout + info->id);
+ if (debug_mode)
+ printf("thread %d going into accept for %d seconds\n",
+ info->id, info->accept_timeout + info->id);
clientSock = PR_Accept(listenSock, &clientAddr, PR_SecondsToInterval(info->accept_timeout +info->id));
if (clientSock == NULL) {
if (PR_GetError() == PR_IO_TIMEOUT_ERROR) {
- if (debug_mode) {
- printf("PR_Accept() timeout worked!\n");
- printf("TEST PASSED! PR_Accept() returned error %d\n",
- PR_IO_TIMEOUT_ERROR);
- }
- } else {
- if (debug_mode)
- printf("TEST FAILED! PR_Accept() returned error %d\n",
- PR_GetError());
- failed_already=1;
- }
+ if (debug_mode) {
+ printf("PR_Accept() timeout worked!\n");
+ printf("TEST PASSED! PR_Accept() returned error %d\n",
+ PR_IO_TIMEOUT_ERROR);
+ }
+ } else {
+ if (debug_mode)
+ printf("TEST FAILED! PR_Accept() returned error %d\n",
+ PR_GetError());
+ failed_already=1;
+ }
} else {
- if (debug_mode)
- printf ("TEST FAILED! PR_Accept() succeeded?\n");
- failed_already=1;
- PR_Close(clientSock);
+ if (debug_mode) {
+ printf ("TEST FAILED! PR_Accept() succeeded?\n");
+ }
+ failed_already=1;
+ PR_Close(clientSock);
}
dead:
if (listenSock) {
- PR_Close(listenSock);
+ PR_Close(listenSock);
}
PR_Lock(info->dead_lock);
(*info->alive)--;
PR_NotifyCondVar(info->dead_cv);
PR_Unlock(info->dead_lock);
- if (debug_mode)
- printf("thread %d is dead\n", info->id);
+ if (debug_mode) {
+ printf("thread %d is dead\n", info->id);
+ }
PR_Free(info);
}
@@ -154,8 +160,9 @@ thread_test(PRThreadScope scope, PRInt32 num_threads)
PRCondVar *dead_cv;
PRInt32 alive;
- if (debug_mode)
- printf("IO Timeout test started with %d threads\n", num_threads);
+ if (debug_mode) {
+ printf("IO Timeout test started with %d threads\n", num_threads);
+ }
dead_lock = PR_NewLock();
dead_cv = PR_NewCondVar(dead_lock);
@@ -179,9 +186,9 @@ thread_test(PRThreadScope scope, PRInt32 num_threads)
0);
if (!thr) {
- printf("Failed to create thread, error = %d(%d)\n",
- PR_GetError(), PR_GetOSError());
- failed_already=1;
+ printf("Failed to create thread, error = %d(%d)\n",
+ PR_GetError(), PR_GetOSError());
+ failed_already=1;
PR_Lock(dead_lock);
alive--;
@@ -191,8 +198,9 @@ thread_test(PRThreadScope scope, PRInt32 num_threads)
PR_Lock(dead_lock);
while(alive) {
- if (debug_mode)
- printf("main loop awake; alive = %d\n", alive);
+ if (debug_mode) {
+ printf("main loop awake; alive = %d\n", alive);
+ }
PR_WaitCondVar(dead_cv, PR_INTERVAL_NO_TIMEOUT);
}
PR_Unlock(dead_lock);
@@ -205,35 +213,38 @@ int main(int argc, char **argv)
{
PRInt32 num_threads = 0;
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name [-d] [-t <threads>]
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "dt:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name [-d] [-t <threads>]
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "dt:");
+ 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_mode = 1;
- break;
- case 't': /* threads to involve */
- num_threads = atoi(opt->value);
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ case 't': /* threads to involve */
+ num_threads = atoi(opt->value);
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- /* main test */
+ /* main test */
- if (0 == num_threads)
+ if (0 == num_threads) {
num_threads = NUM_THREADS;
+ }
PR_Init(PR_USER_THREAD, PR_PRIORITY_LOW, 0);
PR_STDIO_INIT();
@@ -249,8 +260,10 @@ int main(int argc, char **argv)
PR_Cleanup();
- if (failed_already)
- return 1;
- else
- return 0;
+ if (failed_already) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
}
diff --git a/pr/tests/io_timeoutk.c b/pr/tests/io_timeoutk.c
index 0d22a03b..a058655f 100644
--- a/pr/tests/io_timeoutk.c
+++ b/pr/tests/io_timeoutk.c
@@ -9,12 +9,12 @@
**
** Modification History:
** 19-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.
***********************************************************************/
/***********************************************************************
** Includes
@@ -51,11 +51,15 @@ thread_main(void *_info)
PRFileDesc *clientSock;
PRStatus rv;
- if (debug_mode) printf("thread %d is alive\n", info->id);
+ if (debug_mode) {
+ printf("thread %d is alive\n", info->id);
+ }
listenSock = PR_NewTCPSocket();
if (!listenSock) {
- if (debug_mode) printf("unable to create listen socket\n");
+ if (debug_mode) {
+ printf("unable to create listen socket\n");
+ }
goto dead;
}
@@ -64,45 +68,57 @@ thread_main(void *_info)
listenAddr.inet.ip = PR_htonl(INADDR_ANY);
rv = PR_Bind(listenSock, &listenAddr);
if (rv == PR_FAILURE) {
- if (debug_mode) printf("unable to bind\n");
+ if (debug_mode) {
+ printf("unable to bind\n");
+ }
goto dead;
}
rv = PR_Listen(listenSock, 4);
if (rv == PR_FAILURE) {
- if (debug_mode) printf("unable to listen\n");
+ if (debug_mode) {
+ printf("unable to listen\n");
+ }
goto dead;
}
if (debug_mode) printf("thread %d going into accept for %d seconds\n",
- info->id, info->accept_timeout + info->id);
+ info->id, info->accept_timeout + info->id);
clientSock = PR_Accept(listenSock, &clientAddr, PR_SecondsToInterval(info->accept_timeout +info->id));
if (clientSock == NULL) {
if (PR_GetError() == PR_IO_TIMEOUT_ERROR)
if (debug_mode) {
- printf("PR_Accept() timeout worked!\n");
+ printf("PR_Accept() timeout worked!\n");
printf("TEST FAILED! PR_Accept() returned error %d\n",
- PR_GetError());
- }
- else failed_already=1;
+ PR_GetError());
+ }
+ else {
+ failed_already=1;
+ }
} else {
- if (debug_mode) printf ("TEST FAILED! PR_Accept() succeeded?\n");
- else failed_already=1;
- PR_Close(clientSock);
+ if (debug_mode) {
+ printf ("TEST FAILED! PR_Accept() succeeded?\n");
+ }
+ else {
+ failed_already=1;
+ }
+ PR_Close(clientSock);
}
dead:
if (listenSock) {
- PR_Close(listenSock);
+ PR_Close(listenSock);
}
PR_Lock(info->dead_lock);
(*info->alive)--;
PR_NotifyCondVar(info->dead_cv);
PR_Unlock(info->dead_lock);
- if (debug_mode) printf("thread %d is dead\n", info->id);
+ if (debug_mode) {
+ printf("thread %d is dead\n", info->id);
+ }
}
void
@@ -114,7 +130,9 @@ thread_test(PRInt32 scope, PRInt32 num_threads)
PRCondVar *dead_cv;
PRInt32 alive;
- if (debug_mode) printf("IO Timeout test started with %d threads\n", num_threads);
+ if (debug_mode) {
+ printf("IO Timeout test started with %d threads\n", num_threads);
+ }
dead_lock = PR_NewLock();
dead_cv = PR_NewCondVar(dead_lock);
@@ -146,7 +164,9 @@ thread_test(PRInt32 scope, PRInt32 num_threads)
PR_Lock(dead_lock);
while(alive) {
- if (debug_mode) printf("main loop awake; alive = %d\n", alive);
+ if (debug_mode) {
+ printf("main loop awake; alive = %d\n", alive);
+ }
PR_WaitCondVar(dead_cv, PR_INTERVAL_NO_TIMEOUT);
}
PR_Unlock(dead_lock);
@@ -156,46 +176,54 @@ int main(int argc, char **argv)
{
PRInt32 num_threads;
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
+ 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_mode = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- /* main test */
+ /* main test */
- if (argc > 2)
+ if (argc > 2) {
num_threads = atoi(argv[2]);
- else
+ }
+ else {
num_threads = NUM_THREADS;
+ }
PR_Init(PR_USER_THREAD, PR_PRIORITY_LOW, 0);
PR_STDIO_INIT();
- if (debug_mode) printf("kernel level test\n");
+ if (debug_mode) {
+ printf("kernel level test\n");
+ }
thread_test(PR_GLOBAL_THREAD, num_threads);
- PR_Cleanup();
+ PR_Cleanup();
- if(failed_already)
+ if(failed_already) {
return 1;
- else
+ }
+ else {
return 0;
+ }
}
diff --git a/pr/tests/io_timeoutu.c b/pr/tests/io_timeoutu.c
index 9a24457a..b6d9ccfa 100644
--- a/pr/tests/io_timeoutu.c
+++ b/pr/tests/io_timeoutu.c
@@ -10,12 +10,12 @@
**
** Modification History:
** 19-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.
***********************************************************************/
/***********************************************************************
** Includes
@@ -50,11 +50,15 @@ thread_main(void *_info)
PRFileDesc *clientSock;
PRStatus rv;
- if (debug_mode) printf("thread %d is alive\n", info->id);
+ if (debug_mode) {
+ printf("thread %d is alive\n", info->id);
+ }
listenSock = PR_NewTCPSocket();
if (!listenSock) {
- if (debug_mode) printf("unable to create listen socket\n");
+ if (debug_mode) {
+ printf("unable to create listen socket\n");
+ }
goto dead;
}
@@ -63,47 +67,59 @@ thread_main(void *_info)
listenAddr.inet.ip = PR_htonl(INADDR_ANY);
rv = PR_Bind(listenSock, &listenAddr);
if (rv == PR_FAILURE) {
- if (debug_mode) printf("unable to bind\n");
+ if (debug_mode) {
+ printf("unable to bind\n");
+ }
goto dead;
}
rv = PR_Listen(listenSock, 4);
if (rv == PR_FAILURE) {
- if (debug_mode) printf("unable to listen\n");
+ if (debug_mode) {
+ printf("unable to listen\n");
+ }
goto dead;
}
if (debug_mode) printf("thread %d going into accept for %d seconds\n",
- info->id, info->accept_timeout + info->id);
+ info->id, info->accept_timeout + info->id);
clientSock = PR_Accept(
- listenSock, &clientAddr, PR_SecondsToInterval(
- info->accept_timeout + info->id));
+ listenSock, &clientAddr, PR_SecondsToInterval(
+ info->accept_timeout + info->id));
if (clientSock == NULL) {
if (PR_GetError() == PR_IO_TIMEOUT_ERROR)
if (debug_mode) {
- printf("PR_Accept() timeout worked!\n");
+ printf("PR_Accept() timeout worked!\n");
printf("TEST FAILED! PR_Accept() returned error %d\n",
- }
- PR_GetError());
- else failed_already=1;
+ }
+ PR_GetError());
+ else {
+ failed_already=1;
+ }
} else {
- if (debug_mode) printf ("TEST FAILED! PR_Accept() succeeded?\n");
- else failed_already=1;
- PR_Close(clientSock);
+ if (debug_mode) {
+ printf ("TEST FAILED! PR_Accept() succeeded?\n");
+ }
+ else {
+ failed_already=1;
+ }
+ PR_Close(clientSock);
}
dead:
if (listenSock) {
- PR_Close(listenSock);
+ PR_Close(listenSock);
}
PR_Lock(info->dead_lock);
(*info->alive)--;
PR_NotifyCondVar(info->dead_cv);
PR_Unlock(info->dead_lock);
- if (debug_mode) printf("thread %d is dead\n", info->id);
+ if (debug_mode) {
+ printf("thread %d is dead\n", info->id);
+ }
}
void
@@ -115,7 +131,9 @@ thread_test(PRInt32 scope, PRInt32 num_threads)
PRCondVar *dead_cv;
PRInt32 alive;
- if (debug_mode) printf("IO Timeout test started with %d threads\n", num_threads);
+ if (debug_mode) {
+ printf("IO Timeout test started with %d threads\n", num_threads);
+ }
dead_lock = PR_NewLock();
dead_cv = PR_NewCondVar(dead_lock);
@@ -147,7 +165,9 @@ thread_test(PRInt32 scope, PRInt32 num_threads)
PR_Lock(dead_lock);
while(alive) {
- if (debug_mode) printf("main loop awake; alive = %d\n", alive);
+ if (debug_mode) {
+ printf("main loop awake; alive = %d\n", alive);
+ }
PR_WaitCondVar(dead_cv, PR_INTERVAL_NO_TIMEOUT);
}
PR_Unlock(dead_lock);
@@ -157,46 +177,54 @@ int main(int argc, char **argv)
{
PRInt32 num_threads;
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
+ 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_mode = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- /* main test */
+ /* main test */
- if (argc > 2)
+ if (argc > 2) {
num_threads = atoi(argv[2]);
- else
+ }
+ else {
num_threads = NUM_THREADS;
+ }
PR_Init(PR_USER_THREAD, PR_PRIORITY_LOW, 0);
PR_STDIO_INIT();
- if (debug_mode) printf("user level test\n");
+ if (debug_mode) {
+ printf("user level test\n");
+ }
thread_test(PR_LOCAL_THREAD, num_threads);
- PR_Cleanup();
- if(failed_already)
+ PR_Cleanup();
+ if(failed_already) {
return 1;
- else
+ }
+ else {
return 0;
+ }
}
diff --git a/pr/tests/ioconthr.c b/pr/tests/ioconthr.c
index 6b6a5523..3f5adcd5 100644
--- a/pr/tests/ioconthr.c
+++ b/pr/tests/ioconthr.c
@@ -62,8 +62,8 @@ int main(int argc, char **argv)
PR_ProcessExit(1);
}
threads[index] = PR_CreateThread(
- PR_USER_THREAD, ThreadFunc, fds[2 * index],
- PR_PRIORITY_NORMAL, thread_scope, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, ThreadFunc, fds[2 * index],
+ PR_PRIORITY_NORMAL, thread_scope, PR_JOINABLE_THREAD, 0);
if (NULL == threads[index]) {
fprintf(stderr, "PR_CreateThread failed\n");
PR_ProcessExit(1);
@@ -90,7 +90,7 @@ int main(int argc, char **argv)
}
elapsed = (PRIntervalTime)(PR_IntervalNow() - start);
printf("Threads terminated in %d milliseconds\n",
- PR_IntervalToMilliseconds(elapsed));
+ PR_IntervalToMilliseconds(elapsed));
fflush(stdout);
/* We are being very generous and allow 10 seconds. */
diff --git a/pr/tests/ipv6.c b/pr/tests/ipv6.c
index af27d03c..cc323e1e 100644
--- a/pr/tests/ipv6.c
+++ b/pr/tests/ipv6.c
@@ -55,13 +55,17 @@ static PRStatus PrintAddress(const PRNetAddr* address)
PRNetAddr translation;
char buffer[ADDR_BUFFER];
PRStatus rv = PR_NetAddrToString(address, buffer, sizeof(buffer));
- if (PR_FAILURE == rv) PL_FPrintError(err, "PR_NetAddrToString");
+ if (PR_FAILURE == rv) {
+ PL_FPrintError(err, "PR_NetAddrToString");
+ }
else
{
PR_fprintf(err, "\t%s\n", buffer);
memset(&translation, 0, sizeof(translation));
rv = PR_StringToNetAddr(buffer, &translation);
- if (PR_FAILURE == rv) PL_FPrintError(err, "PR_StringToNetAddr");
+ if (PR_FAILURE == rv) {
+ PL_FPrintError(err, "PR_StringToNetAddr");
+ }
else
{
PRSize addr_len = NETADDR_SIZE(address);
@@ -91,19 +95,21 @@ int main(int argc, char **argv)
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: /* Name of host to lookup */
- name = opt->value;
- break;
- case 'V': /* Do version discovery */
- version = PR_TRUE;
- break;
- case 'h': /* user wants some guidance */
- default:
- Help(); /* so give him an earful */
- return 2; /* but not a lot else */
+ case 0: /* Name of host to lookup */
+ name = opt->value;
+ break;
+ case 'V': /* Do version discovery */
+ version = PR_TRUE;
+ break;
+ case 'h': /* user wants some guidance */
+ default:
+ Help(); /* so give him an earful */
+ return 2; /* but not a lot else */
}
}
PL_DestroyOptState(opt);
@@ -119,14 +125,16 @@ int main(int argc, char **argv)
char *nspr_path = PR_GetEnv("LD_LIBRARY_PATH");
char *nspr_name = PR_GetLibraryName(nspr_path, NSPR_LIB);
PRLibrary *runtime = PR_LoadLibrary(nspr_name);
- if (NULL == runtime)
+ if (NULL == runtime) {
PL_FPrintError(err, "PR_LoadLibrary");
+ }
else
{
versionEntryPointType versionPoint = (versionEntryPointType)
- PR_FindSymbol(runtime, "libVersionPoint");
- if (NULL == versionPoint)
+ PR_FindSymbol(runtime, "libVersionPoint");
+ if (NULL == versionPoint) {
PL_FPrintError(err, "PR_FindSymbol");
+ }
else
{
char buffer[100];
@@ -155,7 +163,9 @@ int main(int argc, char **argv)
(void)PR_fprintf(err, " comment: %s\n", version_info->comment);
}
}
- if (NULL != nspr_name) PR_FreeLibraryName(nspr_name);
+ if (NULL != nspr_name) {
+ PR_FreeLibraryName(nspr_name);
+ }
}
{
@@ -192,7 +202,9 @@ int main(int argc, char **argv)
do
{
index = PR_EnumerateHostEnt(index, &host, 0, &address);
- if (index > 0) PrintAddress(&address);
+ if (index > 0) {
+ PrintAddress(&address);
+ }
else if (-1 == index)
{
failed = PR_TRUE;
diff --git a/pr/tests/join.c b/pr/tests/join.c
index bd399017..24238e6e 100644
--- a/pr/tests/join.c
+++ b/pr/tests/join.c
@@ -12,11 +12,11 @@
** Modification History:
**
** 19-May-97 AGarcia - separate the four join tests into different unit test modules.
-** AGarcia- Converted the test to accomodate the debug_mode flag.
+** 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 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.
***********************************************************************/
/***********************************************************************
@@ -35,7 +35,7 @@
/***********************************************************************
** PRIVATE FUNCTION: Test_Result
** DESCRIPTION: Used in conjunction with the regress tool, prints out the
-** status of the test case.
+** status of the test case.
** INPUTS: PASS/FAIL
** OUTPUTS: None
** RETURN: None
@@ -51,10 +51,12 @@
static void Test_Result (int result)
{
- if (result == PASS)
+ if (result == PASS) {
printf ("PASS\n");
- else
+ }
+ else {
printf ("FAIL\n");
+ }
exit (1);
}
@@ -86,43 +88,63 @@ void runTest(PRThreadScope scope1, PRThreadScope scope2)
/* create the low and high priority threads */
low = PR_CreateThread(PR_USER_THREAD,
- lowPriority, 0,
- PR_PRIORITY_LOW,
- scope1,
- PR_JOINABLE_THREAD,
- 0);
+ lowPriority, 0,
+ PR_PRIORITY_LOW,
+ scope1,
+ PR_JOINABLE_THREAD,
+ 0);
if (!low) {
- if (debug_mode) printf("\tcannot create low priority thread\n");
- else Test_Result(FAIL);
+ if (debug_mode) {
+ printf("\tcannot create low priority thread\n");
+ }
+ else {
+ Test_Result(FAIL);
+ }
return;
}
high = PR_CreateThread(PR_USER_THREAD,
- highPriority, 0,
- PR_PRIORITY_HIGH,
- scope2,
- PR_JOINABLE_THREAD,
- 0);
+ highPriority, 0,
+ PR_PRIORITY_HIGH,
+ scope2,
+ PR_JOINABLE_THREAD,
+ 0);
if (!high) {
- if (debug_mode) printf("\tcannot create high priority thread\n");
- else Test_Result(FAIL);
+ if (debug_mode) {
+ printf("\tcannot create high priority thread\n");
+ }
+ else {
+ Test_Result(FAIL);
+ }
return;
}
/* Do the joining for both threads */
if (PR_JoinThread(low) == PR_FAILURE) {
- if (debug_mode) printf("\tcannot join low priority thread\n");
- else Test_Result (FAIL);
+ if (debug_mode) {
+ printf("\tcannot join low priority thread\n");
+ }
+ else {
+ Test_Result (FAIL);
+ }
return;
} else {
- if (debug_mode) printf("\tjoined low priority thread\n");
+ if (debug_mode) {
+ printf("\tjoined low priority thread\n");
+ }
}
if (PR_JoinThread(high) == PR_FAILURE) {
- if (debug_mode) printf("\tcannot join high priority thread\n");
- else Test_Result(FAIL);
+ if (debug_mode) {
+ printf("\tcannot join high priority thread\n");
+ }
+ else {
+ Test_Result(FAIL);
+ }
return;
} else {
- if (debug_mode) printf("\tjoined high priority thread\n");
+ if (debug_mode) {
+ printf("\tjoined high priority thread\n");
+ }
}
}
@@ -133,35 +155,55 @@ void joinWithUnjoinable(void)
/* create the unjoinable thread */
thread = PR_CreateThread(PR_USER_THREAD,
- unjoinable, 0,
- PR_PRIORITY_NORMAL,
- PR_GLOBAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0);
+ unjoinable, 0,
+ PR_PRIORITY_NORMAL,
+ PR_GLOBAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0);
if (!thread) {
- if (debug_mode) printf("\tcannot create unjoinable thread\n");
- else Test_Result(FAIL);
+ if (debug_mode) {
+ printf("\tcannot create unjoinable thread\n");
+ }
+ else {
+ Test_Result(FAIL);
+ }
return;
}
if (PR_JoinThread(thread) == PR_SUCCESS) {
- if (debug_mode) printf("\tsuccessfully joined with unjoinable thread?!\n");
- else Test_Result(FAIL);
+ if (debug_mode) {
+ printf("\tsuccessfully joined with unjoinable thread?!\n");
+ }
+ else {
+ Test_Result(FAIL);
+ }
return;
} else {
- if (debug_mode) printf("\tcannot join with unjoinable thread, as expected\n");
+ if (debug_mode) {
+ printf("\tcannot join with unjoinable thread, as expected\n");
+ }
if (PR_GetError() != PR_INVALID_ARGUMENT_ERROR) {
- if (debug_mode) printf("\tWrong error code\n");
- else Test_Result(FAIL);
+ if (debug_mode) {
+ printf("\tWrong error code\n");
+ }
+ else {
+ Test_Result(FAIL);
+ }
return;
}
}
if (PR_Interrupt(thread) == PR_FAILURE) {
- if (debug_mode) printf("\tcannot interrupt unjoinable thread\n");
- else Test_Result(FAIL);
+ if (debug_mode) {
+ printf("\tcannot interrupt unjoinable thread\n");
+ }
+ else {
+ Test_Result(FAIL);
+ }
return;
} else {
- if (debug_mode) printf("\tinterrupted unjoinable thread\n");
+ if (debug_mode) {
+ printf("\tinterrupted unjoinable thread\n");
+ }
}
}
@@ -178,19 +220,21 @@ static PRIntn PR_CALLBACK RealMain(int argc, char **argv)
PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
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_mode = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ default:
+ break;
}
}
PL_DestroyOptState(opt);
- /* main test */
+ /* main test */
printf("User-User test\n");
runTest(PR_LOCAL_THREAD, PR_LOCAL_THREAD);
printf("User-Kernel test\n");
diff --git a/pr/tests/joinkk.c b/pr/tests/joinkk.c
index 433fc48e..4e7b2b5e 100644
--- a/pr/tests/joinkk.c
+++ b/pr/tests/joinkk.c
@@ -12,13 +12,13 @@
** Modification History:
**
** 19-May-97 AGarcia - separate the four join tests into different unit test modules.
-** 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
+** 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 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.
***********************************************************************/
/***********************************************************************
@@ -36,9 +36,9 @@
PRIntn failed_already=0;
PRIntn debug_mode;
/*
- Program to test joining of threads. Two threads are created. One
- to be waited upon until it has started. The other to join after it has
- completed.
+ Program to test joining of threads. Two threads are created. One
+ to be waited upon until it has started. The other to join after it has
+ completed.
*/
@@ -52,91 +52,115 @@ static void highPriority(void *arg)
void runTest(PRThreadScope scope1, PRThreadScope scope2)
{
- PRThread *low,*high;
-
- /* create the low and high priority threads */
-
- low = PR_CreateThread(PR_USER_THREAD,
- lowPriority, 0,
- PR_PRIORITY_LOW,
- scope1,
- PR_JOINABLE_THREAD,
- 0);
- if (!low) {
- if (debug_mode) printf("\tcannot create low priority thread\n");
- else failed_already=1;
- return;
- }
-
- high = PR_CreateThread(PR_USER_THREAD,
- highPriority, 0,
- PR_PRIORITY_HIGH,
- scope2,
- PR_JOINABLE_THREAD,
- 0);
- if (!high) {
- if (debug_mode) printf("\tcannot create high priority thread\n");
- else failed_already=1;
- return;
- }
-
- /* Do the joining for both threads */
- if (PR_JoinThread(low) == PR_FAILURE) {
- if (debug_mode) printf("\tcannot join low priority thread\n");
- else failed_already=1;
- return;
- } else {
- if (debug_mode) printf("\tjoined low priority thread\n");
+ PRThread *low,*high;
+
+ /* create the low and high priority threads */
+
+ low = PR_CreateThread(PR_USER_THREAD,
+ lowPriority, 0,
+ PR_PRIORITY_LOW,
+ scope1,
+ PR_JOINABLE_THREAD,
+ 0);
+ if (!low) {
+ if (debug_mode) {
+ printf("\tcannot create low priority thread\n");
+ }
+ else {
+ failed_already=1;
+ }
+ return;
+ }
+
+ high = PR_CreateThread(PR_USER_THREAD,
+ highPriority, 0,
+ PR_PRIORITY_HIGH,
+ scope2,
+ PR_JOINABLE_THREAD,
+ 0);
+ if (!high) {
+ if (debug_mode) {
+ printf("\tcannot create high priority thread\n");
+ }
+ else {
+ failed_already=1;
+ }
+ return;
+ }
+
+ /* Do the joining for both threads */
+ if (PR_JoinThread(low) == PR_FAILURE) {
+ if (debug_mode) {
+ printf("\tcannot join low priority thread\n");
+ }
+ else {
+ failed_already=1;
+ }
+ return;
+ } else {
+ if (debug_mode) {
+ printf("\tjoined low priority thread\n");
+ }
}
- if (PR_JoinThread(high) == PR_FAILURE) {
- if (debug_mode) printf("\tcannot join high priority thread\n");
- else failed_already=1;
- return;
- } else {
- if (debug_mode) printf("\tjoined high priority thread\n");
+ if (PR_JoinThread(high) == PR_FAILURE) {
+ if (debug_mode) {
+ printf("\tcannot join high priority thread\n");
+ }
+ else {
+ failed_already=1;
+ }
+ return;
+ } else {
+ if (debug_mode) {
+ printf("\tjoined high priority thread\n");
+ }
}
}
static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
{
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
-
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
+ 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_mode = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- /* main test */
+ /* main test */
- if (debug_mode) printf("Kernel-Kernel test\n");
+ if (debug_mode) {
+ printf("Kernel-Kernel test\n");
+ }
runTest(PR_GLOBAL_THREAD, PR_GLOBAL_THREAD);
- if(failed_already)
- {
+ if(failed_already)
+ {
printf("FAIL\n");
- return 1;
- }
- else
- {
+ return 1;
+ }
+ else
+ {
printf("PASS\n");
- return 0;
- }
+ return 0;
+ }
}
diff --git a/pr/tests/joinku.c b/pr/tests/joinku.c
index 8278303b..cd83b6cb 100644
--- a/pr/tests/joinku.c
+++ b/pr/tests/joinku.c
@@ -12,13 +12,13 @@
** Modification History:
**
** 19-May-97 AGarcia - separate the four join tests into different unit test modules.
-** 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
+** 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 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.
***********************************************************************/
/***********************************************************************
@@ -38,9 +38,9 @@ PRIntn debug_mode;
/*
- Program to test joining of threads. Two threads are created. One
- to be waited upon until it has started. The other to join after it has
- completed.
+ Program to test joining of threads. Two threads are created. One
+ to be waited upon until it has started. The other to join after it has
+ completed.
*/
@@ -54,95 +54,119 @@ static void highPriority(void *arg)
void runTest(PRThreadScope scope1, PRThreadScope scope2)
{
- PRThread *low,*high;
-
- /* create the low and high priority threads */
-
- low = PR_CreateThread(PR_USER_THREAD,
- lowPriority, 0,
- PR_PRIORITY_LOW,
- scope1,
- PR_JOINABLE_THREAD,
- 0);
- if (!low) {
- if (debug_mode) printf("\tcannot create low priority thread\n");
- else failed_already=1;
- return;
- }
-
- high = PR_CreateThread(PR_USER_THREAD,
- highPriority, 0,
- PR_PRIORITY_HIGH,
- scope2,
- PR_JOINABLE_THREAD,
- 0);
- if (!high) {
- if (debug_mode) printf("\tcannot create high priority thread\n");
- else failed_already=1;
- return;
- }
-
- /* Do the joining for both threads */
- if (PR_JoinThread(low) == PR_FAILURE) {
- if (debug_mode) printf("\tcannot join low priority thread\n");
- else failed_already=1;
- return;
- } else {
- if (debug_mode) printf("\tjoined low priority thread\n");
+ PRThread *low,*high;
+
+ /* create the low and high priority threads */
+
+ low = PR_CreateThread(PR_USER_THREAD,
+ lowPriority, 0,
+ PR_PRIORITY_LOW,
+ scope1,
+ PR_JOINABLE_THREAD,
+ 0);
+ if (!low) {
+ if (debug_mode) {
+ printf("\tcannot create low priority thread\n");
+ }
+ else {
+ failed_already=1;
+ }
+ return;
+ }
+
+ high = PR_CreateThread(PR_USER_THREAD,
+ highPriority, 0,
+ PR_PRIORITY_HIGH,
+ scope2,
+ PR_JOINABLE_THREAD,
+ 0);
+ if (!high) {
+ if (debug_mode) {
+ printf("\tcannot create high priority thread\n");
+ }
+ else {
+ failed_already=1;
+ }
+ return;
}
- if (PR_JoinThread(high) == PR_FAILURE) {
- if (debug_mode) printf("\tcannot join high priority thread\n");
- else failed_already=1;
- return;
- } else {
- if (debug_mode) printf("\tjoined high priority thread\n");
+
+ /* Do the joining for both threads */
+ if (PR_JoinThread(low) == PR_FAILURE) {
+ if (debug_mode) {
+ printf("\tcannot join low priority thread\n");
+ }
+ else {
+ failed_already=1;
+ }
+ return;
+ } else {
+ if (debug_mode) {
+ printf("\tjoined low priority thread\n");
+ }
+ }
+ if (PR_JoinThread(high) == PR_FAILURE) {
+ if (debug_mode) {
+ printf("\tcannot join high priority thread\n");
+ }
+ else {
+ failed_already=1;
+ }
+ return;
+ } else {
+ if (debug_mode) {
+ printf("\tjoined high priority thread\n");
+ }
}
}
static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
{
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
-
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
+ 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_mode = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
PR_STDIO_INIT();
- /* main test */
+ /* main test */
- if (debug_mode) printf("Kernel-User test\n");
+ if (debug_mode) {
+ printf("Kernel-User test\n");
+ }
runTest(PR_GLOBAL_THREAD, PR_LOCAL_THREAD);
- if(failed_already)
+ if(failed_already)
+ {
+ printf("FAIL\n");
+ return 1;
+ }
+ else
{
- printf("FAIL\n");
- return 1;
- }
- else
- {
- printf("PASS\n");
- return 0;
- }
+ printf("PASS\n");
+ return 0;
+ }
}
diff --git a/pr/tests/joinuk.c b/pr/tests/joinuk.c
index 1b6fe9b2..418c5e0e 100644
--- a/pr/tests/joinuk.c
+++ b/pr/tests/joinuk.c
@@ -12,13 +12,13 @@
** Modification History:
**
** 19-May-97 AGarcia - separate the four join tests into different unit test modules.
-** 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
+** 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 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.
***********************************************************************/
/***********************************************************************
@@ -36,9 +36,9 @@
PRIntn failed_already=0;
PRIntn debug_mode;
/*
- Program to test joining of threads. Two threads are created. One
- to be waited upon until it has started. The other to join after it has
- completed.
+ Program to test joining of threads. Two threads are created. One
+ to be waited upon until it has started. The other to join after it has
+ completed.
*/
@@ -52,93 +52,117 @@ static void highPriority(void *arg)
void runTest(PRThreadScope scope1, PRThreadScope scope2)
{
- PRThread *low,*high;
-
- /* create the low and high priority threads */
-
- low = PR_CreateThread(PR_USER_THREAD,
- lowPriority, 0,
- PR_PRIORITY_LOW,
- scope1,
- PR_JOINABLE_THREAD,
- 0);
- if (!low) {
- if (debug_mode) printf("\tcannot create low priority thread\n");
- else failed_already=1;
- return;
- }
-
- high = PR_CreateThread(PR_USER_THREAD,
- highPriority, 0,
- PR_PRIORITY_HIGH,
- scope2,
- PR_JOINABLE_THREAD,
- 0);
- if (!high) {
- if (debug_mode) printf("\tcannot create high priority thread\n");
- else failed_already=1;
- return;
- }
-
- /* Do the joining for both threads */
- if (PR_JoinThread(low) == PR_FAILURE) {
- if (debug_mode) printf("\tcannot join low priority thread\n");
- else failed_already=1;
- return;
- } else {
- if (debug_mode) printf("\tjoined low priority thread\n");
+ PRThread *low,*high;
+
+ /* create the low and high priority threads */
+
+ low = PR_CreateThread(PR_USER_THREAD,
+ lowPriority, 0,
+ PR_PRIORITY_LOW,
+ scope1,
+ PR_JOINABLE_THREAD,
+ 0);
+ if (!low) {
+ if (debug_mode) {
+ printf("\tcannot create low priority thread\n");
+ }
+ else {
+ failed_already=1;
+ }
+ return;
}
- if (PR_JoinThread(high) == PR_FAILURE) {
- if (debug_mode) printf("\tcannot join high priority thread\n");
- else failed_already=1;
- return;
- } else {
- if (debug_mode) printf("\tjoined high priority thread\n");
+
+ high = PR_CreateThread(PR_USER_THREAD,
+ highPriority, 0,
+ PR_PRIORITY_HIGH,
+ scope2,
+ PR_JOINABLE_THREAD,
+ 0);
+ if (!high) {
+ if (debug_mode) {
+ printf("\tcannot create high priority thread\n");
+ }
+ else {
+ failed_already=1;
+ }
+ return;
+ }
+
+ /* Do the joining for both threads */
+ if (PR_JoinThread(low) == PR_FAILURE) {
+ if (debug_mode) {
+ printf("\tcannot join low priority thread\n");
+ }
+ else {
+ failed_already=1;
+ }
+ return;
+ } else {
+ if (debug_mode) {
+ printf("\tjoined low priority thread\n");
+ }
+ }
+ if (PR_JoinThread(high) == PR_FAILURE) {
+ if (debug_mode) {
+ printf("\tcannot join high priority thread\n");
+ }
+ else {
+ failed_already=1;
+ }
+ return;
+ } else {
+ if (debug_mode) {
+ printf("\tjoined high priority thread\n");
+ }
}
}
static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
{
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
-
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
+ 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_mode = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
PR_STDIO_INIT();
- /* main test */
+ /* main test */
- if (debug_mode) printf("User-Kernel test\n");
+ if (debug_mode) {
+ printf("User-Kernel test\n");
+ }
runTest(PR_LOCAL_THREAD, PR_GLOBAL_THREAD);
- if(failed_already)
- {
+ if(failed_already)
+ {
printf("FAIL\n");
- return 1;
+ return 1;
} else
{
printf("PASS\n");
- return 0;
+ return 0;
}
}
diff --git a/pr/tests/joinuu.c b/pr/tests/joinuu.c
index b03b6fff..4d30bfa7 100644
--- a/pr/tests/joinuu.c
+++ b/pr/tests/joinuu.c
@@ -12,13 +12,13 @@
** Modification History:
**
** 19-May-97 AGarcia - separate the four join tests into different unit test modules.
-** 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
+** 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 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.
***********************************************************************/
/***********************************************************************
@@ -38,9 +38,9 @@ PRIntn debug_mode;
/*
- Program to test joining of threads. Two threads are created. One
- to be waited upon until it has started. The other to join after it has
- completed.
+ Program to test joining of threads. Two threads are created. One
+ to be waited upon until it has started. The other to join after it has
+ completed.
*/
@@ -54,91 +54,115 @@ static void highPriority(void *arg)
void runTest(PRThreadScope scope1, PRThreadScope scope2)
{
- PRThread *low,*high;
-
- /* create the low and high priority threads */
-
- low = PR_CreateThread(PR_USER_THREAD,
- lowPriority, 0,
- PR_PRIORITY_LOW,
- scope1,
- PR_JOINABLE_THREAD,
- 0);
- if (!low) {
- if (debug_mode) printf("\tcannot create low priority thread\n");
- else failed_already=1;
- return;
- }
-
- high = PR_CreateThread(PR_USER_THREAD,
- highPriority, 0,
- PR_PRIORITY_HIGH,
- scope2,
- PR_JOINABLE_THREAD,
- 0);
- if (!high) {
- if (debug_mode) printf("\tcannot create high priority thread\n");
- else failed_already=1;
- return;
- }
-
- /* Do the joining for both threads */
- if (PR_JoinThread(low) == PR_FAILURE) {
- if (debug_mode) printf("\tcannot join low priority thread\n");
- else failed_already=1;
- return;
- } else {
- if (debug_mode) printf("\tjoined low priority thread\n");
+ PRThread *low,*high;
+
+ /* create the low and high priority threads */
+
+ low = PR_CreateThread(PR_USER_THREAD,
+ lowPriority, 0,
+ PR_PRIORITY_LOW,
+ scope1,
+ PR_JOINABLE_THREAD,
+ 0);
+ if (!low) {
+ if (debug_mode) {
+ printf("\tcannot create low priority thread\n");
+ }
+ else {
+ failed_already=1;
+ }
+ return;
}
- if (PR_JoinThread(high) == PR_FAILURE) {
- if (debug_mode) printf("\tcannot join high priority thread\n");
- else failed_already=1;
- return;
- } else {
- if (debug_mode) printf("\tjoined high priority thread\n");
+
+ high = PR_CreateThread(PR_USER_THREAD,
+ highPriority, 0,
+ PR_PRIORITY_HIGH,
+ scope2,
+ PR_JOINABLE_THREAD,
+ 0);
+ if (!high) {
+ if (debug_mode) {
+ printf("\tcannot create high priority thread\n");
+ }
+ else {
+ failed_already=1;
+ }
+ return;
+ }
+
+ /* Do the joining for both threads */
+ if (PR_JoinThread(low) == PR_FAILURE) {
+ if (debug_mode) {
+ printf("\tcannot join low priority thread\n");
+ }
+ else {
+ failed_already=1;
+ }
+ return;
+ } else {
+ if (debug_mode) {
+ printf("\tjoined low priority thread\n");
+ }
+ }
+ if (PR_JoinThread(high) == PR_FAILURE) {
+ if (debug_mode) {
+ printf("\tcannot join high priority thread\n");
+ }
+ else {
+ failed_already=1;
+ }
+ return;
+ } else {
+ if (debug_mode) {
+ printf("\tjoined high priority thread\n");
+ }
}
}
static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
{
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
-
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
+ 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_mode = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
PR_STDIO_INIT();
- /* main test */
- if (debug_mode) printf("User-User test\n");
+ /* main test */
+ if (debug_mode) {
+ printf("User-User test\n");
+ }
runTest(PR_LOCAL_THREAD, PR_LOCAL_THREAD);
- if(failed_already)
- {
+ if(failed_already)
+ {
printf("FAIL\n");
- return 1;
+ return 1;
} else
{
printf("PASS\n");
- return 0;
+ return 0;
}
diff --git a/pr/tests/layer.c b/pr/tests/layer.c
index 0272f0ea..8579394d 100644
--- a/pr/tests/layer.c
+++ b/pr/tests/layer.c
@@ -46,42 +46,43 @@ static PRFileDesc *PushLayer(PRFileDesc *stack)
{
PRFileDesc *layer = PR_CreateIOLayerStub(identity, &myMethods);
PRStatus rv = PR_PushIOLayer(stack, PR_GetLayersIdentity(stack), layer);
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(logFile, "Pushed layer(0x%x) onto stack(0x%x)\n", layer, stack);
+ }
PR_ASSERT(PR_SUCCESS == rv);
return stack;
} /* PushLayer */
static PRFileDesc *PushNewLayers(PRFileDesc *stack)
{
- PRDescIdentity tmp_identity;
+ PRDescIdentity tmp_identity;
PRFileDesc *layer;
PRStatus rv;
- /* push a dummy layer */
+ /* push a dummy layer */
tmp_identity = PR_GetUniqueIdentity("Dummy 1");
layer = PR_CreateIOLayerStub(tmp_identity, PR_GetDefaultIOMethods());
rv = PR_PushIOLayer(stack, PR_GetLayersIdentity(stack), layer);
if (verbosity > quiet)
PR_fprintf(logFile, "Pushed layer(0x%x) onto stack(0x%x)\n", layer,
- stack);
+ stack);
PR_ASSERT(PR_SUCCESS == rv);
- /* push a data processing layer */
+ /* push a data processing layer */
layer = PR_CreateIOLayerStub(identity, &myMethods);
rv = PR_PushIOLayer(stack, PR_GetLayersIdentity(stack), layer);
if (verbosity > quiet)
PR_fprintf(logFile, "Pushed layer(0x%x) onto stack(0x%x)\n", layer,
- stack);
+ stack);
PR_ASSERT(PR_SUCCESS == rv);
- /* push another dummy layer */
+ /* push another dummy layer */
tmp_identity = PR_GetUniqueIdentity("Dummy 2");
layer = PR_CreateIOLayerStub(tmp_identity, PR_GetDefaultIOMethods());
rv = PR_PushIOLayer(stack, PR_GetLayersIdentity(stack), layer);
if (verbosity > quiet)
PR_fprintf(logFile, "Pushed layer(0x%x) onto stack(0x%x)\n", layer,
- stack);
+ stack);
PR_ASSERT(PR_SUCCESS == rv);
return stack;
} /* PushLayer */
@@ -90,8 +91,9 @@ static PRFileDesc *PushNewLayers(PRFileDesc *stack)
static PRFileDesc *PopLayer(PRFileDesc *stack)
{
PRFileDesc *popped = PR_PopIOLayer(stack, identity);
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(logFile, "Popped layer(0x%x) from stack(0x%x)\n", popped, stack);
+ }
popped->dtor(popped);
return stack;
@@ -114,19 +116,22 @@ static void PR_CALLBACK Client(void *arg)
while (minor_iterations-- > 0)
{
bytes_sent = PR_Send(
- stack, buffer, sizeof(buffer), empty_flags, PR_INTERVAL_NO_TIMEOUT);
+ stack, buffer, sizeof(buffer), empty_flags, PR_INTERVAL_NO_TIMEOUT);
PR_ASSERT(sizeof(buffer) == bytes_sent);
- if (verbosity > chatty)
+ if (verbosity > chatty) {
PR_fprintf(logFile, "Client sending %d bytes\n", bytes_sent);
+ }
bytes_read = PR_Recv(
- stack, buffer, bytes_sent, empty_flags, PR_INTERVAL_NO_TIMEOUT);
- if (verbosity > chatty)
+ stack, buffer, bytes_sent, empty_flags, PR_INTERVAL_NO_TIMEOUT);
+ if (verbosity > chatty) {
PR_fprintf(logFile, "Client receiving %d bytes\n", bytes_read);
+ }
PR_ASSERT(bytes_read == bytes_sent);
}
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(logFile, "Client shutting down stack\n");
+ }
rv = PR_Shutdown(stack, PR_SHUTDOWN_BOTH); PR_ASSERT(PR_SUCCESS == rv);
} /* Client */
@@ -142,29 +147,33 @@ static void PR_CALLBACK Server(void *arg)
PRNetAddr client_address;
service = PR_Accept(stack, &client_address, PR_INTERVAL_NO_TIMEOUT);
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(logFile, "Server accepting connection\n");
+ }
do
{
bytes_read = PR_Recv(
- service, buffer, sizeof(buffer), empty_flags, PR_INTERVAL_NO_TIMEOUT);
+ service, buffer, sizeof(buffer), empty_flags, PR_INTERVAL_NO_TIMEOUT);
if (0 != bytes_read)
{
- if (verbosity > chatty)
+ if (verbosity > chatty) {
PR_fprintf(logFile, "Server receiving %d bytes\n", bytes_read);
+ }
PR_ASSERT(bytes_read > 0);
bytes_sent = PR_Send(
- service, buffer, bytes_read, empty_flags, PR_INTERVAL_NO_TIMEOUT);
- if (verbosity > chatty)
+ service, buffer, bytes_read, empty_flags, PR_INTERVAL_NO_TIMEOUT);
+ if (verbosity > chatty) {
PR_fprintf(logFile, "Server sending %d bytes\n", bytes_sent);
+ }
PR_ASSERT(bytes_read == bytes_sent);
}
} while (0 != bytes_read);
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(logFile, "Server shutting down and closing stack\n");
+ }
rv = PR_Shutdown(service, PR_SHUTDOWN_BOTH); PR_ASSERT(PR_SUCCESS == rv);
rv = PR_Close(service); PR_ASSERT(PR_SUCCESS == rv);
@@ -179,24 +188,26 @@ static PRInt32 PR_CALLBACK MyRecv(
PRInt32 rv, readin = 0, request = 0;
rv = lo->methods->recv(lo, &request, sizeof(request), flags, timeout);
if (verbosity > chatty) PR_fprintf(
- logFile, "MyRecv sending permission for %d bytes\n", request);
+ logFile, "MyRecv sending permission for %d bytes\n", request);
if (0 < rv)
{
if (verbosity > chatty) PR_fprintf(
- logFile, "MyRecv received permission request for %d bytes\n", request);
+ logFile, "MyRecv received permission request for %d bytes\n", request);
rv = lo->methods->send(
- lo, &request, sizeof(request), flags, timeout);
+ lo, &request, sizeof(request), flags, timeout);
if (0 < rv)
{
if (verbosity > chatty) PR_fprintf(
- logFile, "MyRecv sending permission for %d bytes\n", request);
+ logFile, "MyRecv sending permission for %d bytes\n", request);
while (readin < request)
{
rv = lo->methods->recv(
- lo, b + readin, amount - readin, flags, timeout);
- if (rv <= 0) break;
+ lo, b + readin, amount - readin, flags, timeout);
+ if (rv <= 0) {
+ break;
+ }
if (verbosity > chatty) PR_fprintf(
- logFile, "MyRecv received %d bytes\n", rv);
+ logFile, "MyRecv received %d bytes\n", rv);
readin += rv;
}
rv = readin;
@@ -213,24 +224,26 @@ static PRInt32 PR_CALLBACK MySend(
const char *b = (const char*)buf;
PRInt32 rv, wroteout = 0, request;
if (verbosity > chatty) PR_fprintf(
- logFile, "MySend asking permission to send %d bytes\n", amount);
+ logFile, "MySend asking permission to send %d bytes\n", amount);
rv = lo->methods->send(lo, &amount, sizeof(amount), flags, timeout);
if (0 < rv)
{
rv = lo->methods->recv(
- lo, &request, sizeof(request), flags, timeout);
+ lo, &request, sizeof(request), flags, timeout);
if (0 < rv)
{
PR_ASSERT(request == amount);
if (verbosity > chatty) PR_fprintf(
- logFile, "MySend got permission to send %d bytes\n", request);
+ logFile, "MySend got permission to send %d bytes\n", request);
while (wroteout < request)
{
rv = lo->methods->send(
- lo, b + wroteout, request - wroteout, flags, timeout);
- if (rv <= 0) break;
+ lo, b + wroteout, request - wroteout, flags, timeout);
+ if (rv <= 0) {
+ break;
+ }
if (verbosity > chatty) PR_fprintf(
- logFile, "MySend wrote %d bytes\n", rv);
+ logFile, "MySend wrote %d bytes\n", rv);
wroteout += rv;
}
rv = amount;
@@ -242,8 +255,12 @@ static PRInt32 PR_CALLBACK MySend(
static Verbosity ChangeVerbosity(Verbosity verbosity, PRIntn delta)
{
PRIntn verbage = (PRIntn)verbosity + delta;
- if (verbage < (PRIntn)silent) verbage = (PRIntn)silent;
- else if (verbage > (PRIntn)noisy) verbage = (PRIntn)noisy;
+ if (verbage < (PRIntn)silent) {
+ verbage = (PRIntn)silent;
+ }
+ else if (verbage > (PRIntn)noisy) {
+ verbage = (PRIntn)noisy;
+ }
return (Verbosity)verbage;
} /* ChangeVerbosity */
@@ -262,34 +279,38 @@ int main(int argc, char **argv)
PLOptState *opt = PL_CreateOptState(argc, argv, "dqGC:c:p:");
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:
- server_name = opt->value;
- break;
- case 'd': /* debug mode */
- if (verbosity < noisy)
- verbosity = ChangeVerbosity(verbosity, 1);
- break;
- case 'q': /* debug mode */
- if (verbosity > silent)
- verbosity = ChangeVerbosity(verbosity, -1);
- break;
- case 'G': /* use global threads */
- thread_scope = PR_GLOBAL_THREAD;
- break;
- case 'C': /* number of threads waiting */
- major_iterations = atoi(opt->value);
- break;
- case 'c': /* number of client threads */
- minor_iterations = atoi(opt->value);
- break;
- case 'p': /* default port */
- default_port = atoi(opt->value);
- break;
- default:
- break;
+ case 0:
+ server_name = opt->value;
+ break;
+ case 'd': /* debug mode */
+ if (verbosity < noisy) {
+ verbosity = ChangeVerbosity(verbosity, 1);
+ }
+ break;
+ case 'q': /* debug mode */
+ if (verbosity > silent) {
+ verbosity = ChangeVerbosity(verbosity, -1);
+ }
+ break;
+ case 'G': /* use global threads */
+ thread_scope = PR_GLOBAL_THREAD;
+ break;
+ case 'C': /* number of threads waiting */
+ major_iterations = atoi(opt->value);
+ break;
+ case 'c': /* number of client threads */
+ minor_iterations = atoi(opt->value);
+ break;
+ case 'p': /* default port */
+ default_port = atoi(opt->value);
+ break;
+ default:
+ break;
}
}
PL_DestroyOptState(opt);
@@ -311,13 +332,13 @@ int main(int argc, char **argv)
if (NULL == server_name)
rv = PR_InitializeNetAddr(
- PR_IpAddrLoopback, default_port, &server_address);
+ PR_IpAddrLoopback, default_port, &server_address);
else
{
rv = PR_StringToNetAddr(server_name, &server_address);
PR_ASSERT(PR_SUCCESS == rv);
rv = PR_InitializeNetAddr(
- PR_IpAddrNull, default_port, &server_address);
+ PR_IpAddrNull, default_port, &server_address);
}
PR_ASSERT(PR_SUCCESS == rv);
@@ -326,8 +347,9 @@ int main(int argc, char **argv)
mits = minor_iterations;
while (major_iterations-- > 0)
{
- if (verbosity > silent)
+ if (verbosity > silent) {
PR_fprintf(logFile, "Beginning non-layered test\n");
+ }
client = PR_NewTCPSocket(); PR_ASSERT(NULL != client);
service = PR_NewTCPSocket(); PR_ASSERT(NULL != service);
rv = PR_InitializeNetAddr(PR_IpAddrAny, default_port, &any_address);
@@ -337,15 +359,15 @@ int main(int argc, char **argv)
minor_iterations = mits;
server_thread = PR_CreateThread(
- PR_USER_THREAD, Server, service,
- PR_PRIORITY_HIGH, thread_scope,
- PR_JOINABLE_THREAD, 16 * 1024);
+ PR_USER_THREAD, Server, service,
+ PR_PRIORITY_HIGH, thread_scope,
+ PR_JOINABLE_THREAD, 16 * 1024);
PR_ASSERT(NULL != server_thread);
client_thread = PR_CreateThread(
- PR_USER_THREAD, Client, client,
- PR_PRIORITY_NORMAL, thread_scope,
- PR_JOINABLE_THREAD, 16 * 1024);
+ PR_USER_THREAD, Client, client,
+ PR_PRIORITY_NORMAL, thread_scope,
+ PR_JOINABLE_THREAD, 16 * 1024);
PR_ASSERT(NULL != client_thread);
rv = PR_JoinThread(client_thread);
@@ -355,12 +377,14 @@ int main(int argc, char **argv)
rv = PR_Close(client); PR_ASSERT(PR_SUCCESS == rv);
rv = PR_Close(service); PR_ASSERT(PR_SUCCESS == rv);
- if (verbosity > silent)
+ if (verbosity > silent) {
PR_fprintf(logFile, "Ending non-layered test\n");
+ }
/* with layering */
- if (verbosity > silent)
+ if (verbosity > silent) {
PR_fprintf(logFile, "Beginning layered test\n");
+ }
client = PR_NewTCPSocket(); PR_ASSERT(NULL != client);
PushLayer(client);
service = PR_NewTCPSocket(); PR_ASSERT(NULL != service);
@@ -372,15 +396,15 @@ int main(int argc, char **argv)
minor_iterations = mits;
server_thread = PR_CreateThread(
- PR_USER_THREAD, Server, service,
- PR_PRIORITY_HIGH, thread_scope,
- PR_JOINABLE_THREAD, 16 * 1024);
+ PR_USER_THREAD, Server, service,
+ PR_PRIORITY_HIGH, thread_scope,
+ PR_JOINABLE_THREAD, 16 * 1024);
PR_ASSERT(NULL != server_thread);
client_thread = PR_CreateThread(
- PR_USER_THREAD, Client, client,
- PR_PRIORITY_NORMAL, thread_scope,
- PR_JOINABLE_THREAD, 16 * 1024);
+ PR_USER_THREAD, Client, client,
+ PR_PRIORITY_NORMAL, thread_scope,
+ PR_JOINABLE_THREAD, 16 * 1024);
PR_ASSERT(NULL != client_thread);
rv = PR_JoinThread(client_thread);
@@ -393,12 +417,12 @@ int main(int argc, char **argv)
/* with layering, using new style stack */
if (verbosity > silent)
PR_fprintf(logFile,
- "Beginning layered test with new style stack\n");
+ "Beginning layered test with new style stack\n");
client = PR_NewTCPSocket(); PR_ASSERT(NULL != client);
- client_stack = PR_CreateIOLayer(client);
+ client_stack = PR_CreateIOLayer(client);
PushNewLayers(client_stack);
service = PR_NewTCPSocket(); PR_ASSERT(NULL != service);
- service_stack = PR_CreateIOLayer(service);
+ service_stack = PR_CreateIOLayer(service);
PushNewLayers(service_stack);
rv = PR_InitializeNetAddr(PR_IpAddrAny, default_port, &any_address);
PR_ASSERT(PR_SUCCESS == rv);
@@ -407,15 +431,15 @@ int main(int argc, char **argv)
minor_iterations = mits;
server_thread = PR_CreateThread(
- PR_USER_THREAD, Server, service_stack,
- PR_PRIORITY_HIGH, thread_scope,
- PR_JOINABLE_THREAD, 16 * 1024);
+ PR_USER_THREAD, Server, service_stack,
+ PR_PRIORITY_HIGH, thread_scope,
+ PR_JOINABLE_THREAD, 16 * 1024);
PR_ASSERT(NULL != server_thread);
client_thread = PR_CreateThread(
- PR_USER_THREAD, Client, client_stack,
- PR_PRIORITY_NORMAL, thread_scope,
- PR_JOINABLE_THREAD, 16 * 1024);
+ PR_USER_THREAD, Client, client_stack,
+ PR_PRIORITY_NORMAL, thread_scope,
+ PR_JOINABLE_THREAD, 16 * 1024);
PR_ASSERT(NULL != client_thread);
rv = PR_JoinThread(client_thread);
@@ -425,8 +449,9 @@ int main(int argc, char **argv)
rv = PR_Close(client_stack); PR_ASSERT(PR_SUCCESS == rv);
rv = PR_Close(service_stack); PR_ASSERT(PR_SUCCESS == rv);
- if (verbosity > silent)
+ if (verbosity > silent) {
PR_fprintf(logFile, "Ending layered test\n");
+ }
}
return 0;
} /* main */
diff --git a/pr/tests/lazyinit.c b/pr/tests/lazyinit.c
index 35b8a3a8..5ec1c957 100644
--- a/pr/tests/lazyinit.c
+++ b/pr/tests/lazyinit.c
@@ -53,8 +53,9 @@ int main(int argc, char **argv)
{
test = 0;
}
- else
+ else {
test = atoi(argv[1]);
+ }
switch (test)
{
@@ -65,8 +66,8 @@ int main(int argc, char **argv)
break;
case 2: thread = PR_CreateThread(
- PR_USER_THREAD, lazyEntry, NULL, PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, lazyEntry, NULL, PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
break;
case 3: file = PR_Open("/usr/tmp/", PR_RDONLY, 0);
diff --git a/pr/tests/libfilename.c b/pr/tests/libfilename.c
index 66bb45c8..09d0980d 100644
--- a/pr/tests/libfilename.c
+++ b/pr/tests/libfilename.c
@@ -34,7 +34,9 @@ static PRStatus RunTest(const char *name, PRFuncPtr addr)
return PR_FAILURE;
}
- if (debug_mode) printf("Pathname is %s\n", pathname);
+ if (debug_mode) {
+ printf("Pathname is %s\n", pathname);
+ }
fd = PR_OpenFile(pathname, PR_RDONLY, 0);
if (fd == NULL) {
fprintf(stderr, "PR_Open failed: %d\n", (int)PR_GetError());
@@ -74,7 +76,9 @@ int main(int argc, char **argv)
/* Next test a library that is dynamically loaded. */
name = PR_GetLibraryName("dll", "my");
- if (debug_mode) printf("Loading library %s\n", name);
+ if (debug_mode) {
+ printf("Loading library %s\n", name);
+ }
lib = PR_LoadLibrary(name);
if (!lib) {
fprintf(stderr, "PR_LoadLibrary failed\n");
diff --git a/pr/tests/lltest.c b/pr/tests/lltest.c
index 36e67984..26f7d8ea 100644
--- a/pr/tests/lltest.c
+++ b/pr/tests/lltest.c
@@ -93,8 +93,9 @@ static void
SetFailed( char *what, char *how )
{
failedAlready = 1;
- if ( debugMode )
+ if ( debugMode ) {
PR_fprintf(output, "%s: failed: %s\n", what, how );
+ }
return;
}
@@ -118,10 +119,12 @@ static void TestAssignment( void )
PRInt64 zero = LL_Zero();
PRInt64 min = LL_MinInt();
PRInt64 max = LL_MaxInt();
- if (!LL_EQ(zero, bigZero))
+ if (!LL_EQ(zero, bigZero)) {
SetFailed("LL_EQ(zero, bigZero)", "!=");
- if (!LL_CMP(max, >, min))
+ }
+ if (!LL_CMP(max, >, min)) {
SetFailed("LL_CMP(max, >, min)", "!>");
+ }
}
/*
@@ -133,226 +136,296 @@ TestComparisons( void )
ReportProgress("Testing Comparisons Operations\n");
/* test for zero */
- if ( !LL_IS_ZERO( bigZero ))
+ if ( !LL_IS_ZERO( bigZero )) {
SetFailed( "LL_IS_ZERO", "Zero is not zero" );
+ }
- if ( LL_IS_ZERO( bigOne ))
+ if ( LL_IS_ZERO( bigOne )) {
SetFailed( "LL_IS_ZERO", "One tests as zero" );
+ }
- if ( LL_IS_ZERO( bigMinusOne ))
+ if ( LL_IS_ZERO( bigMinusOne )) {
SetFailed( "LL_IS_ZERO", "Minus One tests as zero" );
+ }
/* test equal */
- if ( !LL_EQ( bigZero, bigZero ))
+ if ( !LL_EQ( bigZero, bigZero )) {
SetFailed( "LL_EQ", "zero EQ zero");
+ }
- if ( !LL_EQ( bigOne, bigOne ))
+ if ( !LL_EQ( bigOne, bigOne )) {
SetFailed( "LL_EQ", "one EQ one" );
+ }
- if ( !LL_EQ( bigNumber, bigNumber ))
+ if ( !LL_EQ( bigNumber, bigNumber )) {
SetFailed( "LL_EQ", "bigNumber EQ bigNumber" );
+ }
- if ( !LL_EQ( bigMinusOne, bigMinusOne ))
+ if ( !LL_EQ( bigMinusOne, bigMinusOne )) {
SetFailed( "LL_EQ", "minus one EQ minus one");
+ }
- if ( LL_EQ( bigZero, bigOne ))
+ if ( LL_EQ( bigZero, bigOne )) {
SetFailed( "LL_EQ", "zero EQ one");
+ }
- if ( LL_EQ( bigOne, bigZero ))
+ if ( LL_EQ( bigOne, bigZero )) {
SetFailed( "LL_EQ", "one EQ zero" );
+ }
- if ( LL_EQ( bigMinusOne, bigOne ))
+ if ( LL_EQ( bigMinusOne, bigOne )) {
SetFailed( "LL_EQ", "minus one EQ one");
+ }
- if ( LL_EQ( bigNumber, bigOne ))
+ if ( LL_EQ( bigNumber, bigOne )) {
SetFailed( "LL_EQ", "bigNumber EQ one");
+ }
/* test not equal */
- if ( LL_NE( bigZero, bigZero ))
+ if ( LL_NE( bigZero, bigZero )) {
SetFailed( "LL_NE", "0 NE 0");
+ }
- if ( LL_NE( bigOne, bigOne ))
+ if ( LL_NE( bigOne, bigOne )) {
SetFailed( "LL_NE", "1 NE 1");
+ }
- if ( LL_NE( bigMinusOne, bigMinusOne ))
+ if ( LL_NE( bigMinusOne, bigMinusOne )) {
SetFailed( "LL_NE", "-1 NE -1");
+ }
- if ( LL_NE( bigNumber, bigNumber ))
+ if ( LL_NE( bigNumber, bigNumber )) {
SetFailed( "LL_NE", "n NE n");
+ }
- if ( LL_NE( bigMinusNumber, bigMinusNumber ))
+ if ( LL_NE( bigMinusNumber, bigMinusNumber )) {
SetFailed( "LL_NE", "-n NE -n");
+ }
- if ( !LL_NE( bigZero, bigOne))
+ if ( !LL_NE( bigZero, bigOne)) {
SetFailed( "LL_NE", "0 NE 1");
+ }
- if ( !LL_NE( bigOne, bigMinusNumber))
+ if ( !LL_NE( bigOne, bigMinusNumber)) {
SetFailed( "LL_NE", "1 NE -n");
+ }
/* Greater than or equal to zero */
- if ( !LL_GE_ZERO( bigZero ))
+ if ( !LL_GE_ZERO( bigZero )) {
SetFailed( "LL_GE_ZERO", "0");
+ }
- if ( !LL_GE_ZERO( bigOne ))
+ if ( !LL_GE_ZERO( bigOne )) {
SetFailed( "LL_GE_ZERO", "1");
+ }
- if ( !LL_GE_ZERO( bigNumber ))
+ if ( !LL_GE_ZERO( bigNumber )) {
SetFailed( "LL_GE_ZERO", "n");
+ }
- if ( LL_GE_ZERO( bigMinusOne ))
+ if ( LL_GE_ZERO( bigMinusOne )) {
SetFailed( "LL_GE_ZERO", "-1");
+ }
- if ( LL_GE_ZERO( bigMinusNumber ))
+ if ( LL_GE_ZERO( bigMinusNumber )) {
SetFailed( "LL_GE_ZERO", "-n");
+ }
/* Algebraic Compare two values */
- if ( !LL_CMP( bigZero, ==, bigZero ))
+ if ( !LL_CMP( bigZero, ==, bigZero )) {
SetFailed( "LL_CMP", "0 == 0");
+ }
- if ( LL_CMP( bigZero, >, bigZero ))
+ if ( LL_CMP( bigZero, >, bigZero )) {
SetFailed( "LL_CMP", "0 > 0");
+ }
- if ( LL_CMP( bigZero, <, bigZero ))
+ if ( LL_CMP( bigZero, <, bigZero )) {
SetFailed( "LL_CMP", "0 < 0");
+ }
- if ( LL_CMP( bigNumber, <, bigOne ))
+ if ( LL_CMP( bigNumber, <, bigOne )) {
SetFailed( "LL_CMP", "n < 1");
+ }
- if ( !LL_CMP( bigNumber, >, bigOne ))
+ if ( !LL_CMP( bigNumber, >, bigOne )) {
SetFailed( "LL_CMP", "n <= 1");
+ }
- if ( LL_CMP( bigOne, >, bigNumber ))
+ if ( LL_CMP( bigOne, >, bigNumber )) {
SetFailed( "LL_CMP", "1 > n");
+ }
- if ( LL_CMP( bigMinusNumber, >, bigNumber ))
+ if ( LL_CMP( bigMinusNumber, >, bigNumber )) {
SetFailed( "LL_CMP", "-n > n");
+ }
- if ( LL_CMP( bigNumber, !=, bigNumber))
+ if ( LL_CMP( bigNumber, !=, bigNumber)) {
SetFailed( "LL_CMP", "n != n");
+ }
- if ( !LL_CMP( bigMinusOne, >, bigMinusTwo ))
+ if ( !LL_CMP( bigMinusOne, >, bigMinusTwo )) {
SetFailed( "LL_CMP", "-1 <= -2");
+ }
- if ( !LL_CMP( bigMaxInt32, <, big2To31 ))
+ if ( !LL_CMP( bigMaxInt32, <, big2To31 )) {
SetFailed( "LL_CMP", "Max 32-bit signed int >= 2^31");
+ }
/* Two positive numbers */
- if ( !LL_CMP( bigInt0, <=, bigInt0 ))
+ if ( !LL_CMP( bigInt0, <=, bigInt0 )) {
SetFailed( "LL_CMP", "LL_CMP(<=) failed");
+ }
- if ( !LL_CMP( bigInt0, <=, bigInt1 ))
+ if ( !LL_CMP( bigInt0, <=, bigInt1 )) {
SetFailed( "LL_CMP", "LL_CMP(<=) failed");
+ }
- if ( LL_CMP( bigInt0, <=, bigInt2 ))
+ if ( LL_CMP( bigInt0, <=, bigInt2 )) {
SetFailed( "LL_CMP", "LL_CMP(<=) failed");
+ }
- if ( !LL_CMP( bigInt0, <=, bigInt3 ))
+ if ( !LL_CMP( bigInt0, <=, bigInt3 )) {
SetFailed( "LL_CMP", "LL_CMP(<=) failed");
+ }
- if ( !LL_CMP( bigInt0, <=, bigInt4 ))
+ if ( !LL_CMP( bigInt0, <=, bigInt4 )) {
SetFailed( "LL_CMP", "LL_CMP(<=) failed");
+ }
- if ( !LL_CMP( bigInt0, <=, bigInt5 ))
+ if ( !LL_CMP( bigInt0, <=, bigInt5 )) {
SetFailed( "LL_CMP", "LL_CMP(<=) failed");
+ }
/* Two negative numbers */
- if ( !LL_CMP( bigInt6, <=, bigInt6 ))
+ if ( !LL_CMP( bigInt6, <=, bigInt6 )) {
SetFailed( "LL_CMP", "LL_CMP(<=) failed");
+ }
- if ( !LL_CMP( bigInt6, <=, bigInt7 ))
+ if ( !LL_CMP( bigInt6, <=, bigInt7 )) {
SetFailed( "LL_CMP", "LL_CMP(<=) failed");
+ }
- if ( LL_CMP( bigInt6, <=, bigInt8 ))
+ if ( LL_CMP( bigInt6, <=, bigInt8 )) {
SetFailed( "LL_CMP", "LL_CMP(<=) failed");
+ }
- if ( !LL_CMP( bigInt6, <=, bigInt9 ))
+ if ( !LL_CMP( bigInt6, <=, bigInt9 )) {
SetFailed( "LL_CMP", "LL_CMP(<=) failed");
+ }
- if ( !LL_CMP( bigInt6, <=, bigInt10 ))
+ if ( !LL_CMP( bigInt6, <=, bigInt10 )) {
SetFailed( "LL_CMP", "LL_CMP(<=) failed");
+ }
- if ( !LL_CMP( bigInt6, <=, bigInt11 ))
+ if ( !LL_CMP( bigInt6, <=, bigInt11 )) {
SetFailed( "LL_CMP", "LL_CMP(<=) failed");
+ }
/* One positive, one negative */
- if ( LL_CMP( bigInt0, <=, bigInt6 ))
+ if ( LL_CMP( bigInt0, <=, bigInt6 )) {
SetFailed( "LL_CMP", "LL_CMP(<=) failed");
+ }
- if ( LL_CMP( bigInt0, <=, bigInt7 ))
+ if ( LL_CMP( bigInt0, <=, bigInt7 )) {
SetFailed( "LL_CMP", "LL_CMP(<=) failed");
+ }
- if ( LL_CMP( bigInt0, <=, bigInt8 ))
+ if ( LL_CMP( bigInt0, <=, bigInt8 )) {
SetFailed( "LL_CMP", "LL_CMP(<=) failed");
+ }
/* Bitwise Compare two numbers */
- if ( !LL_UCMP( bigZero, ==, bigZero ))
+ if ( !LL_UCMP( bigZero, ==, bigZero )) {
SetFailed( "LL_UCMP", "0 == 0");
+ }
- if ( LL_UCMP( bigZero, >, bigZero ))
+ if ( LL_UCMP( bigZero, >, bigZero )) {
SetFailed( "LL_UCMP", "0 > 0");
+ }
- if ( LL_UCMP( bigZero, <, bigZero ))
+ if ( LL_UCMP( bigZero, <, bigZero )) {
SetFailed( "LL_UCMP", "0 < 0");
+ }
- if ( LL_UCMP( bigNumber, <, bigOne ))
+ if ( LL_UCMP( bigNumber, <, bigOne )) {
SetFailed( "LL_UCMP", "n < 1");
+ }
- if ( !LL_UCMP( bigNumber, >, bigOne ))
+ if ( !LL_UCMP( bigNumber, >, bigOne )) {
SetFailed( "LL_UCMP", "n < 1");
+ }
- if ( LL_UCMP( bigOne, >, bigNumber ))
+ if ( LL_UCMP( bigOne, >, bigNumber )) {
SetFailed( "LL_UCMP", "1 > n");
+ }
- if ( LL_UCMP( bigMinusNumber, <, bigNumber ))
+ if ( LL_UCMP( bigMinusNumber, <, bigNumber )) {
SetFailed( "LL_UCMP", "-n < n");
+ }
/* Two positive numbers */
- if ( !LL_UCMP( bigInt0, <=, bigInt0 ))
+ if ( !LL_UCMP( bigInt0, <=, bigInt0 )) {
SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
+ }
- if ( !LL_UCMP( bigInt0, <=, bigInt1 ))
+ if ( !LL_UCMP( bigInt0, <=, bigInt1 )) {
SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
+ }
- if ( LL_UCMP( bigInt0, <=, bigInt2 ))
+ if ( LL_UCMP( bigInt0, <=, bigInt2 )) {
SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
+ }
- if ( !LL_UCMP( bigInt0, <=, bigInt3 ))
+ if ( !LL_UCMP( bigInt0, <=, bigInt3 )) {
SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
+ }
- if ( !LL_UCMP( bigInt0, <=, bigInt4 ))
+ if ( !LL_UCMP( bigInt0, <=, bigInt4 )) {
SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
+ }
- if ( !LL_UCMP( bigInt0, <=, bigInt5 ))
+ if ( !LL_UCMP( bigInt0, <=, bigInt5 )) {
SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
+ }
/* Two negative numbers */
- if ( !LL_UCMP( bigInt6, <=, bigInt6 ))
+ if ( !LL_UCMP( bigInt6, <=, bigInt6 )) {
SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
+ }
- if ( !LL_UCMP( bigInt6, <=, bigInt7 ))
+ if ( !LL_UCMP( bigInt6, <=, bigInt7 )) {
SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
+ }
- if ( LL_UCMP( bigInt6, <=, bigInt8 ))
+ if ( LL_UCMP( bigInt6, <=, bigInt8 )) {
SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
+ }
- if ( !LL_UCMP( bigInt6, <=, bigInt9 ))
+ if ( !LL_UCMP( bigInt6, <=, bigInt9 )) {
SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
+ }
- if ( !LL_UCMP( bigInt6, <=, bigInt10 ))
+ if ( !LL_UCMP( bigInt6, <=, bigInt10 )) {
SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
+ }
- if ( !LL_UCMP( bigInt6, <=, bigInt11 ))
+ if ( !LL_UCMP( bigInt6, <=, bigInt11 )) {
SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
+ }
/* One positive, one negative */
- if ( !LL_UCMP( bigInt0, <=, bigInt6 ))
+ if ( !LL_UCMP( bigInt0, <=, bigInt6 )) {
SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
+ }
- if ( !LL_UCMP( bigInt0, <=, bigInt7 ))
+ if ( !LL_UCMP( bigInt0, <=, bigInt7 )) {
SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
+ }
- if ( !LL_UCMP( bigInt0, <=, bigInt8 ))
+ if ( !LL_UCMP( bigInt0, <=, bigInt8 )) {
SetFailed( "LL_UCMP", "LL_UCMP(<=) failed");
+ }
return;
}
@@ -370,82 +443,99 @@ TestLogicalOperations( void )
/* Test AND */
LL_AND( result, bigZero, bigZero );
- if ( !LL_IS_ZERO( result ))
+ if ( !LL_IS_ZERO( result )) {
ResultFailed( "LL_AND", "0 & 0", bigZero, result );
+ }
LL_AND( result, bigOne, bigOne );
- if ( LL_IS_ZERO( result ))
+ if ( LL_IS_ZERO( result )) {
ResultFailed( "LL_AND", "1 & 1", bigOne, result );
+ }
LL_AND( result, bigZero, bigOne );
- if ( !LL_IS_ZERO( result ))
+ if ( !LL_IS_ZERO( result )) {
ResultFailed( "LL_AND", "1 & 1", bigZero, result );
+ }
LL_AND( result, bigMinusOne, bigMinusOne );
- if ( !LL_UCMP( result, ==, bigMinusOne ))
+ if ( !LL_UCMP( result, ==, bigMinusOne )) {
ResultFailed( "LL_AND", "-1 & -1", bigMinusOne, result );
+ }
/* test OR */
LL_OR( result, bigZero, bigZero );
- if ( !LL_IS_ZERO( result ))
+ if ( !LL_IS_ZERO( result )) {
ResultFailed( "LL_OR", "0 | 1", bigZero, result);
+ }
LL_OR( result, bigZero, bigOne );
- if ( LL_IS_ZERO( result ))
+ if ( LL_IS_ZERO( result )) {
ResultFailed( "LL_OR", "0 | 1", bigOne, result );
+ }
LL_OR( result, bigZero, bigMinusNumber );
- if ( !LL_UCMP( result, ==, bigMinusNumber ))
+ if ( !LL_UCMP( result, ==, bigMinusNumber )) {
ResultFailed( "LL_OR", "0 | -n", bigMinusNumber, result);
+ }
LL_OR( result, bigMinusNumber, bigZero );
- if ( !LL_UCMP( result, ==, bigMinusNumber ))
+ if ( !LL_UCMP( result, ==, bigMinusNumber )) {
ResultFailed( "LL_OR", "-n | 0", bigMinusNumber, result );
+ }
/* test XOR */
LL_XOR( result, bigZero, bigZero );
- if ( LL_UCMP( result, !=, bigZero ))
+ if ( LL_UCMP( result, !=, bigZero )) {
ResultFailed( "LL_XOR", "0 ^ 0", bigZero, result);
+ }
LL_XOR( result, bigOne, bigZero );
- if ( LL_UCMP( result, !=, bigOne ))
+ if ( LL_UCMP( result, !=, bigOne )) {
ResultFailed( "LL_XOR", "1 ^ 0", bigZero, result );
+ }
LL_XOR( result, bigMinusNumber, bigZero );
- if ( LL_UCMP( result, !=, bigMinusNumber ))
+ if ( LL_UCMP( result, !=, bigMinusNumber )) {
ResultFailed( "LL_XOR", "-n ^ 0", bigMinusNumber, result );
+ }
LL_XOR( result, bigMinusNumber, bigMinusNumber );
- if ( LL_UCMP( result, !=, bigZero ))
+ if ( LL_UCMP( result, !=, bigZero )) {
ResultFailed( "LL_XOR", "-n ^ -n", bigMinusNumber, result);
+ }
/* test OR2. */
result = bigZero;
LL_OR2( result, bigOne );
- if ( LL_UCMP( result, !=, bigOne ))
+ if ( LL_UCMP( result, !=, bigOne )) {
ResultFailed( "LL_OR2", "(r=0) |= 1", bigOne, result);
+ }
result = bigOne;
LL_OR2( result, bigNumber );
- if ( LL_UCMP( result, !=, bigNumber ))
+ if ( LL_UCMP( result, !=, bigNumber )) {
ResultFailed( "LL_OR2", "(r=1) |= n", bigNumber, result);
+ }
result = bigMinusNumber;
LL_OR2( result, bigMinusNumber );
- if ( LL_UCMP( result, !=, bigMinusNumber ))
+ if ( LL_UCMP( result, !=, bigMinusNumber )) {
ResultFailed( "LL_OR2", "(r=-n) |= -n", bigMinusNumber, result);
+ }
/* test NOT */
LL_NOT( result, bigMinusNumber);
LL_NOT( result2, result);
- if ( LL_UCMP( result2, !=, bigMinusNumber ))
+ if ( LL_UCMP( result2, !=, bigMinusNumber )) {
ResultFailed( "LL_NOT", "r != ~(~-n)", bigMinusNumber, result);
+ }
/* test Negation */
LL_NEG( result, bigMinusNumber );
LL_NEG( result2, result );
- if ( LL_CMP( result2, !=, bigMinusNumber ))
+ if ( LL_CMP( result2, !=, bigMinusNumber )) {
ResultFailed( "LL_NEG", "r != -(-(-n))", bigMinusNumber, result);
+ }
return;
}
@@ -470,77 +560,93 @@ TestConversion( void )
/* LL_L2I -- Convert to signed 32bit */
LL_L2I(result32, bigOne );
- if ( result32 != one )
+ if ( result32 != one ) {
SetFailed( "LL_L2I", "r != 1");
+ }
LL_L2I(result32, bigMinusOne );
- if ( result32 != minusOne )
+ if ( result32 != minusOne ) {
SetFailed( "LL_L2I", "r != -1");
+ }
/* LL_L2UI -- Convert 64bit to unsigned 32bit */
LL_L2UI( resultU32, bigMinusOne );
- if ( resultU32 != (PRUint32) minusOne )
+ if ( resultU32 != (PRUint32) minusOne ) {
SetFailed( "LL_L2UI", "r != -1");
+ }
LL_L2UI( resultU32, bigOne );
- if ( resultU32 != (PRUint32) one )
+ if ( resultU32 != (PRUint32) one ) {
SetFailed( "LL_L2UI", "r != 1");
+ }
/* LL_L2F -- Convert to 32bit floating point */
LL_L2F( resultF, bigOne );
- if ( resultF != 1.0 )
+ if ( resultF != 1.0 ) {
SetFailed( "LL_L2F", "r != 1.0");
+ }
LL_L2F( resultF, bigMinusOne );
- if ( resultF != -1.0 )
+ if ( resultF != -1.0 ) {
SetFailed( "LL_L2F", "r != 1.0");
+ }
/* LL_L2D -- Convert to 64bit floating point */
LL_L2D( resultD, bigOne );
- if ( resultD != 1.0L )
+ if ( resultD != 1.0L ) {
SetFailed( "LL_L2D", "r != 1.0");
+ }
LL_L2D( resultD, bigMinusOne );
- if ( resultD != -1.0L )
+ if ( resultD != -1.0L ) {
SetFailed( "LL_L2D", "r != -1.0");
+ }
/* LL_I2L -- Convert 32bit signed to 64bit signed */
LL_I2L( result, one );
- if ( LL_CMP(result, !=, bigOne ))
+ if ( LL_CMP(result, !=, bigOne )) {
SetFailed( "LL_I2L", "r != 1");
+ }
LL_I2L( result, minusOne );
- if ( LL_CMP(result, !=, bigMinusOne ))
+ if ( LL_CMP(result, !=, bigMinusOne )) {
SetFailed( "LL_I2L", "r != -1");
+ }
/* LL_UI2L -- Convert 32bit unsigned to 64bit unsigned */
LL_UI2L( resultU, (PRUint32) one );
- if ( LL_CMP(resultU, !=, bigOne ))
+ if ( LL_CMP(resultU, !=, bigOne )) {
SetFailed( "LL_UI2L", "r != 1");
+ }
/* [lth.] This did not behave as expected, but it is correct
*/
LL_UI2L( resultU, (PRUint32) minusOne );
- if ( LL_CMP(resultU, !=, bigZeroFox ))
+ if ( LL_CMP(resultU, !=, bigZeroFox )) {
ResultFailed( "LL_UI2L", "r != -1", bigZeroFox, resultU);
+ }
/* LL_F2L -- Convert 32bit float to 64bit signed */
LL_F2L( result, 1.0 );
- if ( LL_CMP(result, !=, bigOne ))
+ if ( LL_CMP(result, !=, bigOne )) {
SetFailed( "LL_F2L", "r != 1");
+ }
LL_F2L( result, -1.0 );
- if ( LL_CMP(result, !=, bigMinusOne ))
+ if ( LL_CMP(result, !=, bigMinusOne )) {
SetFailed( "LL_F2L", "r != -1");
+ }
/* LL_D2L -- Convert 64bit Float to 64bit signed */
LL_D2L( result, 1.0L );
- if ( LL_CMP(result, !=, bigOne ))
+ if ( LL_CMP(result, !=, bigOne )) {
SetFailed( "LL_D2L", "r != 1");
+ }
LL_D2L( result, -1.0L );
- if ( LL_CMP(result, !=, bigMinusOne ))
+ if ( LL_CMP(result, !=, bigMinusOne )) {
SetFailed( "LL_D2L", "r != -1");
+ }
return;
}
@@ -578,47 +684,57 @@ TestShift( void )
/* LL_SHL -- Shift left algebraic */
LL_SHL( result, bigOne, one );
- if ( LL_CMP( result, !=, bigTwo ))
+ if ( LL_CMP( result, !=, bigTwo )) {
ResultFailed( "LL_SHL", "r != 2", bigOne, result );
+ }
LL_SHL( result, bigTwo, thirtyTwo );
- if ( LL_CMP( result, !=, largeTwoZero ))
+ if ( LL_CMP( result, !=, largeTwoZero )) {
ResultFailed( "LL_SHL", "r != twoZero", largeTwoZero, result);
+ }
/* LL_SHR -- Shift right algebraic */
LL_SHR( result, bigFoxZero, thirtyTwo );
- if ( LL_CMP( result, !=, bigMinusOne ))
+ if ( LL_CMP( result, !=, bigMinusOne )) {
ResultFailed( "LL_SHR", "r != -1", bigMinusOne, result);
+ }
LL_SHR( result, bigTwo, one );
- if ( LL_CMP( result, !=, bigOne ))
+ if ( LL_CMP( result, !=, bigOne )) {
ResultFailed( "LL_SHR", "r != 1", bigOne, result);
+ }
LL_SHR( result, bigFoxFox, thirtyTwo );
- if ( LL_CMP( result, !=, bigMinusOne ))
+ if ( LL_CMP( result, !=, bigMinusOne )) {
ResultFailed( "LL_SHR", "r != -1 (was ff,ff)", bigMinusOne, result);
+ }
/* LL_USHR -- Logical shift right */
LL_USHR( resultU, bigZeroFox, thirtyTwo );
- if ( LL_UCMP( resultU, !=, bigZero ))
+ if ( LL_UCMP( resultU, !=, bigZero )) {
ResultFailed( "LL_USHR", "r != 0 ", bigZero, result);
+ }
LL_USHR( resultU, bigFoxFox, thirtyTwo );
- if ( LL_UCMP( resultU, !=, bigZeroFox ))
+ if ( LL_UCMP( resultU, !=, bigZeroFox )) {
ResultFailed( "LL_USHR", "r != 0 ", bigZeroFox, result);
+ }
/* LL_ISHL -- Shift a 32bit integer into a 64bit result */
LL_ISHL( resultU, minusOne, thirtyTwo );
- if ( LL_UCMP( resultU, !=, bigFoxZero ))
+ if ( LL_UCMP( resultU, !=, bigFoxZero )) {
ResultFailed( "LL_ISHL", "r != ff,00 ", bigFoxZero, result);
+ }
LL_ISHL( resultU, one, sixtyThree );
- if ( LL_UCMP( resultU, !=, bigEightZero ))
+ if ( LL_UCMP( resultU, !=, bigEightZero )) {
ResultFailed( "LL_ISHL", "r != 80,00 ", bigEightZero, result);
+ }
LL_ISHL( resultU, one, sixteen );
- if ( LL_UCMP( resultU, !=, big64K ))
+ if ( LL_UCMP( resultU, !=, big64K )) {
ResultFailed( "LL_ISHL", "r != 64K ", big64K, resultU);
+ }
return;
}
@@ -642,104 +758,124 @@ TestArithmetic( void )
/* Addition */
LL_ADD( result, bigOne, bigOne );
- if ( LL_CMP( result, !=, bigTwo ))
+ if ( LL_CMP( result, !=, bigTwo )) {
ResultFailed( "LL_ADD", "r != 1 + 1", bigTwo, result);
+ }
LL_ADD( result, bigMinusOne, bigOne );
- if ( LL_CMP( result, !=, bigZero ))
+ if ( LL_CMP( result, !=, bigZero )) {
ResultFailed( "LL_ADD", "r != -1 + 1", bigOne, result);
+ }
LL_ADD( result, largeVal, bigOne );
- if ( LL_CMP( result, !=, largeValPlusOne ))
+ if ( LL_CMP( result, !=, largeValPlusOne )) {
ResultFailed( "LL_ADD", "lVP1 != lV + 1", largeValPlusOne, result);
+ }
/* Subtraction */
LL_SUB( result, bigOne, bigOne );
- if ( LL_CMP( result, !=, bigZero ))
+ if ( LL_CMP( result, !=, bigZero )) {
ResultFailed( "LL_SUB", "r != 1 - 1", bigZero, result);
+ }
LL_SUB( result, bigTwo, bigOne );
- if ( LL_CMP( result, !=, bigOne ))
+ if ( LL_CMP( result, !=, bigOne )) {
ResultFailed( "LL_SUB", "r != 2 - 1", bigOne, result);
+ }
LL_SUB( result, largeValPlusOne, bigOne );
- if ( LL_CMP( result, !=, largeVal ))
+ if ( LL_CMP( result, !=, largeVal )) {
ResultFailed( "LL_SUB", "r != lVP1 - 1", largeVal, result);
+ }
/* Multiply */
LL_MUL( result, largeVal, bigTwo );
- if ( LL_CMP( result, !=, largeValTimesTwo ))
+ if ( LL_CMP( result, !=, largeValTimesTwo )) {
ResultFailed( "LL_MUL", "r != lV*2", largeValTimesTwo, result);
+ }
LL_MUL( result, largeMultCand, big64K );
- if ( LL_CMP( result, !=, largeMultCandx64K ))
+ if ( LL_CMP( result, !=, largeMultCandx64K )) {
ResultFailed( "LL_MUL", "r != lV*64K", largeMultCandx64K, result);
+ }
LL_NEG( result2, largeMultCand );
LL_MUL( result, largeMultCand, bigMinusOne );
- if ( LL_CMP( result, !=, result2 ))
+ if ( LL_CMP( result, !=, result2 )) {
ResultFailed( "LL_MUL", "r != -lMC", result2, result);
+ }
LL_SHL( result2, bigZeroFox, 5);
LL_MUL( result, bigZeroFox, bigThirtyTwo );
- if ( LL_CMP( result, !=, largeNumSHL5 ))
+ if ( LL_CMP( result, !=, largeNumSHL5 )) {
ResultFailed( "LL_MUL", "r != 0f<<5", largeNumSHL5, result );
+ }
/* LL_DIV() Division */
LL_DIV( result, bigOne, bigOne);
- if ( LL_CMP( result, !=, bigOne ))
+ if ( LL_CMP( result, !=, bigOne )) {
ResultFailed( "LL_DIV", "1 != 1", bigOne, result);
+ }
LL_DIV( result, bigNumber, bigOne );
- if ( LL_CMP( result, !=, bigNumber ))
+ if ( LL_CMP( result, !=, bigNumber )) {
ResultFailed( "LL_DIV", "r != n / 1", bigNumber, result);
+ }
LL_DIV( result, bigNumber, bigMinusOne );
- if ( LL_CMP( result, !=, bigMinusNumber ))
+ if ( LL_CMP( result, !=, bigMinusNumber )) {
ResultFailed( "LL_DIV", "r != n / -1", bigMinusNumber, result);
+ }
LL_DIV( result, bigMinusNumber, bigMinusOne );
- if ( LL_CMP( result, !=, bigNumber ))
+ if ( LL_CMP( result, !=, bigNumber )) {
ResultFailed( "LL_DIV", "r != -n / -1", bigNumber, result);
+ }
LL_SHL( result2, bigZeroFox, 5 );
LL_DIV( result, result2, bigOne );
- if ( LL_CMP( result, !=, result2 ))
+ if ( LL_CMP( result, !=, result2 )) {
ResultFailed( "LL_DIV", "0f<<5 != 0f<<5", result2, result);
+ }
LL_SHL( result2, bigZeroFox, 5 );
LL_NEG( result2, result2 );
LL_DIV( result, result2, bigOne );
- if ( LL_CMP( result, !=, result2 ))
+ if ( LL_CMP( result, !=, result2 )) {
ResultFailed( "LL_DIV", "-0f<<5 != -0f<<5", result2, result);
+ }
LL_SHL( result2, bigZeroFox, 17 );
LL_DIV( result, result2, bigMinusOne );
LL_NEG( result2, result2 );
- if ( LL_CMP( result, !=, result2 ))
+ if ( LL_CMP( result, !=, result2 )) {
ResultFailed( "LL_DIV", "-0f<<17 != -0f<<17", result2, result);
+ }
/* LL_MOD() Modulo Division */
LL_ADD( result2, bigThirtyTwo, bigOne );
LL_MOD( result, result2, bigSixTeen );
- if ( LL_CMP( result, !=, bigOne ))
+ if ( LL_CMP( result, !=, bigOne )) {
ResultFailed( "LL_MOD", "r != 1", bigSixTeen, result);
+ }
LL_MUL( result2, bigZeroFox, bigThirtyTwo );
LL_ADD( result2, result2, bigSixTeen);
LL_MOD( result, result2, bigThirtyTwo );
- if ( LL_CMP( result, !=, bigSixTeen ))
+ if ( LL_CMP( result, !=, bigSixTeen )) {
ResultFailed( "LL_MOD", "r != 16", bigSixTeen, result);
+ }
/* LL_UDIVMOD */
LL_DIV( result, bigOne, bigOne);
- if ( LL_CMP( result, !=, bigOne ))
+ if ( LL_CMP( result, !=, bigOne )) {
ResultFailed( "LL_DIV", "r != 16", bigSixTeen, result);
+ }
return;
@@ -749,12 +885,15 @@ static void TestWellknowns(void)
{
PRInt64 max = LL_MAXINT, min = LL_MININT, zero = LL_ZERO;
PRInt64 mmax = LL_MaxInt(), mmin = LL_MinInt(), mzero = LL_Zero();
- if (LL_NE(max, mmax))
+ if (LL_NE(max, mmax)) {
ResultFailed( "max, mmax", "max != mmax", max, mmax);
- if (LL_NE(min, mmin))
+ }
+ if (LL_NE(min, mmin)) {
ResultFailed( "min, mmin", "min != mmin", max, mmin);
- if (LL_NE(zero, mzero))
+ }
+ if (LL_NE(zero, mzero)) {
ResultFailed( "zero, mzero", "zero != mzero", zero, mzero);
+ }
} /* TestWellknowns */
/*
@@ -774,22 +913,24 @@ Initialize( PRIntn argc, char **argv )
*/
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': /* set debug mode */
- debugMode = PR_TRUE;
- break;
-
- case 'v': /* set verbose mode */
- verboseMode = PR_TRUE;
- debugMode = PR_TRUE;
- break;
-
- case 'h': /* user wants some guidance */
- default:
- PR_fprintf(output, "You get help.\n");
- return(1);
+ case 'd': /* set debug mode */
+ debugMode = PR_TRUE;
+ break;
+
+ case 'v': /* set verbose mode */
+ verboseMode = PR_TRUE;
+ debugMode = PR_TRUE;
+ break;
+
+ case 'h': /* user wants some guidance */
+ default:
+ PR_fprintf(output, "You get help.\n");
+ return(1);
}
}
PL_DestroyOptState(opt);
@@ -801,8 +942,9 @@ int main(int argc, char **argv)
PR_STDIO_INIT();
output = PR_GetSpecialFD(PR_StandardError);
- if ( Initialize( argc, argv ))
+ if ( Initialize( argc, argv )) {
return(1);
+ }
TestAssignment();
TestComparisons();
@@ -817,11 +959,11 @@ int main(int argc, char **argv)
*/
if ( failedAlready )
{
- PR_fprintf(output, "FAIL\n");\
+ PR_fprintf(output, "FAIL\n"); \
}
else
{
- PR_fprintf(output, "PASS\n");\
+ PR_fprintf(output, "PASS\n"); \
}
return failedAlready;
} /* end main() */
diff --git a/pr/tests/lock.c b/pr/tests/lock.c
index f10f80fd..83a4f418 100644
--- a/pr/tests/lock.c
+++ b/pr/tests/lock.c
@@ -9,12 +9,12 @@
**
** Modification History:
** 14-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.
**
** 11-Aug-97 LarryH. Win16 port of NSPR.
** - Added "PASS", "FAIL" messages on completion.
@@ -149,8 +149,8 @@ static PRIntervalTime ContentiousLock(PRUint32 loops)
contention->ml = PR_NewLock();
contention->interval = contention_interval;
thread = PR_CreateThread(
- PR_USER_THREAD, LockContender, contention,
- PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, LockContender, contention,
+ PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
PR_ASSERT(thread != NULL);
overhead = PR_IntervalNow() - timein;
@@ -211,12 +211,18 @@ static PRIntervalTime NonContentiousMonitor(PRUint32 loops)
static void PR_CALLBACK TryEntry(void *arg)
{
PRMonitor *ml = (PRMonitor*)arg;
- if (debug_mode) PR_fprintf(std_err, "Reentrant thread created\n");
+ if (debug_mode) {
+ PR_fprintf(std_err, "Reentrant thread created\n");
+ }
PR_EnterMonitor(ml);
PR_ASSERT_CURRENT_THREAD_IN_MONITOR(ml);
- if (debug_mode) PR_fprintf(std_err, "Reentrant thread acquired monitor\n");
+ if (debug_mode) {
+ PR_fprintf(std_err, "Reentrant thread acquired monitor\n");
+ }
PR_ExitMonitor(ml);
- if (debug_mode) PR_fprintf(std_err, "Reentrant thread released monitor\n");
+ if (debug_mode) {
+ PR_fprintf(std_err, "Reentrant thread released monitor\n");
+ }
} /* TryEntry */
static PRIntervalTime ReentrantMonitor(PRUint32 loops)
@@ -224,32 +230,40 @@ static PRIntervalTime ReentrantMonitor(PRUint32 loops)
PRStatus status;
PRThread *thread;
PRMonitor *ml = PR_NewMonitor();
- if (debug_mode) PR_fprintf(std_err, "\nMonitor created for reentrant test\n");
+ if (debug_mode) {
+ PR_fprintf(std_err, "\nMonitor created for reentrant test\n");
+ }
PR_EnterMonitor(ml);
PR_ASSERT_CURRENT_THREAD_IN_MONITOR(ml);
PR_EnterMonitor(ml);
PR_ASSERT_CURRENT_THREAD_IN_MONITOR(ml);
- if (debug_mode) PR_fprintf(std_err, "Monitor acquired twice\n");
+ if (debug_mode) {
+ PR_fprintf(std_err, "Monitor acquired twice\n");
+ }
thread = PR_CreateThread(
- PR_USER_THREAD, TryEntry, ml,
- PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, TryEntry, ml,
+ PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
PR_ASSERT(thread != NULL);
PR_Sleep(PR_SecondsToInterval(1));
PR_ASSERT_CURRENT_THREAD_IN_MONITOR(ml);
PR_ExitMonitor(ml);
PR_ASSERT_CURRENT_THREAD_IN_MONITOR(ml);
- if (debug_mode) PR_fprintf(std_err, "Monitor released first time\n");
+ if (debug_mode) {
+ PR_fprintf(std_err, "Monitor released first time\n");
+ }
PR_ExitMonitor(ml);
- if (debug_mode) PR_fprintf(std_err, "Monitor released second time\n");
+ if (debug_mode) {
+ PR_fprintf(std_err, "Monitor released second time\n");
+ }
status = PR_JoinThread(thread);
if (debug_mode) PR_fprintf(std_err,
- "Reentrant thread joined %s\n",
- (status == PR_SUCCESS) ? "successfully" : "in error");
+ "Reentrant thread joined %s\n",
+ (status == PR_SUCCESS) ? "successfully" : "in error");
PR_DestroyMonitor(ml);
return 0;
@@ -283,8 +297,8 @@ static PRUint32 ContentiousMonitor(PRUint32 loops)
contention->ml = PR_NewMonitor();
contention->interval = contention_interval;
thread = PR_CreateThread(
- PR_USER_THREAD, MonitorContender, contention,
- PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, MonitorContender, contention,
+ PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
PR_ASSERT(thread != NULL);
overhead = PR_IntervalNow() - timein;
@@ -352,8 +366,8 @@ static PRIntervalTime ContentiousCMonitor(PRUint32 loops)
contention->loops = loops;
contention->interval = contention_interval;
thread = PR_CreateThread(
- PR_USER_THREAD, Contender, contention,
- PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, Contender, contention,
+ PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
PR_ASSERT(thread != NULL);
overhead = PR_IntervalNow() - timein;
@@ -405,11 +419,15 @@ static PRIntervalTime Test(
accountable -= overhead;
elapsed = (PRFloat64)PR_IntervalToMicroseconds(accountable);
PR_fprintf(PR_STDOUT, "%s:", msg);
- while (spaces++ < 50) PR_fprintf(PR_STDOUT, " ");
- if ((PRInt32)accountable < 0)
+ while (spaces++ < 50) {
+ PR_fprintf(PR_STDOUT, " ");
+ }
+ if ((PRInt32)accountable < 0) {
PR_fprintf(PR_STDOUT, "*****.** usecs/iteration\n");
- else
+ }
+ else {
PR_fprintf(PR_STDOUT, "%8.2f usecs/iteration\n", elapsed/loops);
+ }
}
return duration;
} /* Test */
@@ -424,58 +442,68 @@ int main(int argc, char **argv)
PR_STDIO_INIT();
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
{
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
Command line argument -l <num> sets the number of loops.
Command line argument -c <num> sets the number of cpus.
Usage: lock [-d] [-l <num>] [-c <num>]
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "dvl:c:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "dvl:c:");
+ 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_mode = PR_TRUE;
- break;
- case 'v': /* debug mode */
- verbosity = PR_TRUE;
- break;
- case 'l': /* number of loops */
- loops = atoi(opt->value);
- break;
- case 'c': /* number of cpus */
- cpus = atoi(opt->value);
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = PR_TRUE;
+ break;
+ case 'v': /* debug mode */
+ verbosity = PR_TRUE;
+ break;
+ case 'l': /* number of loops */
+ loops = atoi(opt->value);
+ break;
+ case 'c': /* number of cpus */
+ cpus = atoi(opt->value);
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
}
- /* main test */
+ /* main test */
PR_SetConcurrency(8);
- if (loops == 0) loops = 100;
+ if (loops == 0) {
+ loops = 100;
+ }
if (debug_mode)
{
std_err = PR_STDERR;
PR_fprintf(std_err, "Lock: Using %d loops\n", loops);
}
- if (cpus == 0) cpus = 2;
- if (debug_mode) PR_fprintf(std_err, "Lock: Using %d cpu(s)\n", cpus);
+ if (cpus == 0) {
+ cpus = 2;
+ }
+ if (debug_mode) {
+ PR_fprintf(std_err, "Lock: Using %d cpu(s)\n", cpus);
+ }
(void)Sleeper(10); /* try filling in the caches */
for (cpu = 1; cpu <= cpus; ++cpu)
{
- if (debug_mode) PR_fprintf(std_err, "\nLock: Using %d CPU(s)\n", cpu);
+ if (debug_mode) {
+ PR_fprintf(std_err, "\nLock: Using %d CPU(s)\n", cpu);
+ }
PR_SetConcurrency(cpu);
duration = Test("Overhead of PR_Sleep", Sleeper, loops, 0);
@@ -498,20 +526,21 @@ int main(int argc, char **argv)
PR_fprintf(
std_err, "%s: test %s\n", "Lock(mutex) test",
((rv) ? "passed" : "failed"));
- else {
- if (!rv)
- failed_already=1;
- }
-
- if(failed_already)
- {
- PR_fprintf(PR_STDOUT, "FAIL\n");
- return 1;
+ else {
+ if (!rv) {
+ failed_already=1;
+ }
+ }
+
+ if(failed_already)
+ {
+ PR_fprintf(PR_STDOUT, "FAIL\n");
+ return 1;
}
- else
+ else
{
- PR_fprintf(PR_STDOUT, "PASS\n");
- return 0;
+ PR_fprintf(PR_STDOUT, "PASS\n");
+ return 0;
}
} /* main */
diff --git a/pr/tests/lockfile.c b/pr/tests/lockfile.c
index 903b5035..883ef0d6 100644
--- a/pr/tests/lockfile.c
+++ b/pr/tests/lockfile.c
@@ -11,12 +11,12 @@
**
** Modification History:
** 19-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.
***********************************************************************/
/***********************************************************************
** Includes
@@ -64,8 +64,8 @@ static PRIntervalTime NonContentiousLock(PRInt32 loops)
_lockfile = PR_Open(LOCKFILE, PR_CREATE_FILE|PR_RDWR, 0666);
if (!_lockfile) {
if (debug_mode) printf(
- "could not create lockfile: %d [%d]\n",
- PR_GetError(), PR_GetOSError());
+ "could not create lockfile: %d [%d]\n",
+ PR_GetError(), PR_GetOSError());
return PR_INTERVAL_NO_TIMEOUT;
}
PR_LockFile(_lockfile);
@@ -84,8 +84,8 @@ static void PR_CALLBACK LockContender(void *arg)
_lockfile = PR_Open(LOCKFILE, PR_CREATE_FILE|PR_RDWR, 0666);
if (!_lockfile) {
if (debug_mode) printf(
- "could not create lockfile: %d [%d]\n",
- PR_GetError(), PR_GetOSError());
+ "could not create lockfile: %d [%d]\n",
+ PR_GetError(), PR_GetOSError());
break;
}
PR_LockFile(_lockfile);
@@ -112,8 +112,8 @@ static PRIntervalTime ContentiousLock(PRInt32 loops)
contention.ml = PR_NewLock();
contention.interval = contention_interval;
thread = PR_CreateThread(
- PR_USER_THREAD, LockContender, &contention,
- PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, LockContender, &contention,
+ PR_PRIORITY_LOW, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
PR_ASSERT(thread != NULL);
overhead = PR_IntervalNow() - timein;
@@ -155,12 +155,20 @@ static PRIntervalTime Test(
accountable = duration - predicted;
accountable -= overhead;
elapsed = (PRFloat64)PR_IntervalToMicroseconds(accountable);
- if (debug_mode) printf("%s:", msg);
- while (spaces++ < 50) if (debug_mode) printf(" ");
+ if (debug_mode) {
+ printf("%s:", msg);
+ }
+ while (spaces++ < 50) if (debug_mode) {
+ printf(" ");
+ }
if ((PRInt32)accountable < 0) {
- if (debug_mode) printf("*****.** usecs/iteration\n");
+ if (debug_mode) {
+ printf("*****.** usecs/iteration\n");
+ }
} else {
- if (debug_mode) printf("%8.2f usecs/iteration\n", elapsed/loops);
+ if (debug_mode) {
+ printf("%8.2f usecs/iteration\n", elapsed/loops);
+ }
}
return duration;
} /* Test */
@@ -172,45 +180,59 @@ int main(int argc, char **argv)
PRInt32 loops = 100;
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
+ 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_mode = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- /* main test */
+ /* main test */
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
PR_STDIO_INIT();
- if (argc > 1) loops = atoi(argv[1]);
- if (loops == 0) loops = 100;
- if (debug_mode) printf("Lock: Using %d loops\n", loops);
+ if (argc > 1) {
+ loops = atoi(argv[1]);
+ }
+ if (loops == 0) {
+ loops = 100;
+ }
+ if (debug_mode) {
+ printf("Lock: Using %d loops\n", loops);
+ }
cpus = (argc < 3) ? 2 : atoi(argv[2]);
- if (cpus == 0) cpus = 2;
- if (debug_mode) printf("Lock: Using %d cpu(s)\n", cpus);
+ if (cpus == 0) {
+ cpus = 2;
+ }
+ if (debug_mode) {
+ printf("Lock: Using %d cpu(s)\n", cpus);
+ }
for (cpu = 1; cpu <= cpus; ++cpu)
{
- if (debug_mode) printf("\nLockFile: Using %d CPU(s)\n", cpu);
+ if (debug_mode) {
+ printf("\nLockFile: Using %d CPU(s)\n", cpu);
+ }
PR_SetConcurrency(cpu);
duration = Test("LockFile non-contentious locking/unlocking", NonContentiousLock, loops, 0);
@@ -219,11 +241,15 @@ int main(int argc, char **argv)
PR_Delete(LOCKFILE); /* try to get rid of evidence */
- if (debug_mode) printf("%s: test %s\n", "Lock(mutex) test", ((failed_already) ? "failed" : "passed"));
- if(failed_already)
- return 1;
- else
- return 0;
+ if (debug_mode) {
+ printf("%s: test %s\n", "Lock(mutex) test", ((failed_already) ? "failed" : "passed"));
+ }
+ if(failed_already) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
} /* main */
/* testlock.c */
diff --git a/pr/tests/logger.c b/pr/tests/logger.c
index 2ba0b394..ee28d41d 100644
--- a/pr/tests/logger.c
+++ b/pr/tests/logger.c
@@ -38,8 +38,8 @@ static void Error(const char* msg)
static void PR_CALLBACK forked(void *arg)
{
PRIntn i;
- PRLock *ml;
- PRCondVar *cv;
+ PRLock *ml;
+ PRCondVar *cv;
PR_LogPrint("%s logging creating mutex\n", (const char*)arg);
ml = PR_NewLock();
@@ -68,18 +68,18 @@ static void UserLogStuff( void )
myLM = PR_NewLogModule( "userStuff" );
if (! myLM )
- {
+ {
printf("UserLogStuff(): can't create new log module\n" );
return;
- }
+ }
PR_LOG( myLM, PR_LOG_NOTICE, ("Log a Notice %d\n", 1 ));
for (i = 0; i < 10 ; i++ )
- {
+ {
PR_LOG( myLM, PR_LOG_DEBUG, ("Log Debug number: %d\n", i));
PR_Sleep( 300 );
- }
+ }
} /* end UserLogStuff() */
@@ -108,9 +108,9 @@ int main(int argc, char **argv)
** Now change buffering.
*/
PR_SetLogBuffering( 65500 );
- thread = PR_CreateThread(
- PR_USER_THREAD, forked, (void*)argv[0], PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
+ thread = PR_CreateThread(
+ PR_USER_THREAD, forked, (void*)argv[0], PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
PR_LogPrint("%s joining thread\n", argv[0]);
UserLogStuff();
diff --git a/pr/tests/many_cv.c b/pr/tests/many_cv.c
index 1a408596..8444c995 100644
--- a/pr/tests/many_cv.c
+++ b/pr/tests/many_cv.c
@@ -45,22 +45,24 @@ static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
- if (PL_OPT_BAD == os) continue;
+ if (PL_OPT_BAD == os) {
+ continue;
+ }
switch (opt->option)
{
- case 's': /* number of CVs to association with lock */
- stats = PR_TRUE;
- break;
- case 'c': /* number of CVs to association with lock */
- cvs = atoi(opt->value);
- break;
- case 'l': /* number of times to run the tests */
- loops = atoi(opt->value);
- break;
- case 'h': /* user wants some guidance */
- default:
- Help(); /* so give him an earful */
- return 2; /* but not a lot else */
+ case 's': /* number of CVs to association with lock */
+ stats = PR_TRUE;
+ break;
+ case 'c': /* number of CVs to association with lock */
+ cvs = atoi(opt->value);
+ break;
+ case 'l': /* number of times to run the tests */
+ loops = atoi(opt->value);
+ break;
+ case 'h': /* user wants some guidance */
+ default:
+ Help(); /* so give him an earful */
+ return 2; /* but not a lot else */
}
}
PL_DestroyOptState(opt);
@@ -87,15 +89,19 @@ static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
for (nl = 0; nl < cvs; ++nl)
{
PRInt32 ran = RandomNum() % 8;
- if (0 == ran) PR_NotifyAllCondVar(cv[nl]);
- else for (nc = 0; nc < ran; ++nc)
- PR_NotifyCondVar(cv[nl]);
+ if (0 == ran) {
+ PR_NotifyAllCondVar(cv[nl]);
+ }
+ else for (nc = 0; nc < ran; ++nc) {
+ PR_NotifyCondVar(cv[nl]);
+ }
}
PR_Unlock(ml);
}
- for (index = 0; index < cvs; ++index)
+ for (index = 0; index < cvs; ++index) {
PR_DestroyCondVar(cv[index]);
+ }
PR_DELETE(cv);
diff --git a/pr/tests/mbcs.c b/pr/tests/mbcs.c
index c5760939..1a0d08f8 100644
--- a/pr/tests/mbcs.c
+++ b/pr/tests/mbcs.c
@@ -69,7 +69,7 @@ static void TraverseDirectory( unsigned char *dir )
cwd = PR_OpenDir( dir );
if ( NULL == cwd ) {
printf("PR_OpenDir() failed on directory: %s, with error: %d, %d\n",
- dir, PR_GetError(), PR_GetOSError());
+ dir, PR_GetError(), PR_GetOSError());
exit(1);
}
while( NULL != (dirEntry = PR_ReadDir( cwd, PR_SKIP_BOTH | PR_SKIP_HIDDEN ))) {
@@ -77,7 +77,7 @@ static void TraverseDirectory( unsigned char *dir )
rc = PR_GetFileInfo( file, &info );
if ( PR_FAILURE == rc ) {
printf("PR_GetFileInfo() failed on file: %s, with error: %d, %d\n",
- dirEntry->name, PR_GetError(), PR_GetOSError());
+ dirEntry->name, PR_GetError(), PR_GetOSError());
exit(1);
}
if ( PR_FILE_FILE == info.type ) {
@@ -85,12 +85,12 @@ static void TraverseDirectory( unsigned char *dir )
fd = PR_Open( file, PR_RDONLY, 0 );
if ( NULL == fd ) {
printf("PR_Open() failed. Error: %ld, OSError: %ld\n",
- PR_GetError(), PR_GetOSError());
+ PR_GetError(), PR_GetOSError());
}
rc = PR_Close( fd );
if ( PR_FAILURE == rc ) {
printf("PR_Close() failed. Error: %ld, OSError: %ld\n",
- PR_GetError(), PR_GetOSError());
+ PR_GetError(), PR_GetOSError());
}
} else if ( PR_FILE_DIRECTORY == info.type ) {
sprintf( nextDir, "%s/%s", dir, dirEntry->name );
@@ -105,38 +105,40 @@ static void TraverseDirectory( unsigned char *dir )
rc = PR_CloseDir( cwd );
if ( PR_FAILURE == rc ) {
printf("PR_CloseDir() failed on directory: %s, with error: %d, %d\n",
- dir, PR_GetError(), PR_GetOSError());
+ dir, PR_GetError(), PR_GetOSError());
}
} /* end TraverseDirectory() */
int main(int argc, char **argv)
{
- { /* get command line options */
+ { /* get command line options */
/*
** Get command line options
*/
PLOptStatus os;
PLOptState *opt = PL_CreateOptState(argc, argv, "dv");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ 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 */
- debug = 1;
- msgLevel = PR_LOG_ERROR;
- break;
- case 'v': /* verbose mode */
- msgLevel = PR_LOG_DEBUG;
- break;
- default:
- dirName = strdup(opt->value);
- break;
+ case 'd': /* debug */
+ debug = 1;
+ msgLevel = PR_LOG_ERROR;
+ break;
+ case 'v': /* verbose mode */
+ msgLevel = PR_LOG_DEBUG;
+ break;
+ default:
+ dirName = strdup(opt->value);
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
} /* end get command line options */
lm = PR_NewLogModule("Test"); /* Initialize logging */
@@ -149,7 +151,9 @@ int main(int argc, char **argv)
TraverseDirectory( dirName );
- if (debug) printf("%s\n", (failed_already)? "FAIL" : "PASS");
+ if (debug) {
+ printf("%s\n", (failed_already)? "FAIL" : "PASS");
+ }
return( (failed_already == PR_TRUE )? 1 : 0 );
} /* main() */
/* end template.c */
diff --git a/pr/tests/multiacc.c b/pr/tests/multiacc.c
index 9382c4f6..ff8452d3 100644
--- a/pr/tests/multiacc.c
+++ b/pr/tests/multiacc.c
@@ -65,7 +65,7 @@ int main(int argc, char **argv)
char buf[1024];
serverThreads = (PRThread **)
- PR_Malloc(num_server_threads * sizeof(PRThread *));
+ PR_Malloc(num_server_threads * sizeof(PRThread *));
if (NULL == serverThreads) {
fprintf(stderr, "PR_Malloc failed\n");
exit(1);
@@ -132,8 +132,8 @@ int main(int argc, char **argv)
printf("creating dummy thread\n");
fflush(stdout);
dummyThread = PR_CreateThread(PR_USER_THREAD,
- ServerThreadFunc, dummySock, PR_PRIORITY_NORMAL,
- thread_scope, PR_JOINABLE_THREAD, 0);
+ ServerThreadFunc, dummySock, PR_PRIORITY_NORMAL,
+ thread_scope, PR_JOINABLE_THREAD, 0);
if (NULL == dummyThread) {
fprintf(stderr, "PR_CreateThread failed\n");
exit(1);
@@ -143,8 +143,8 @@ int main(int argc, char **argv)
PR_Sleep(PR_SecondsToInterval(1));
for (idx = 0; idx < num_server_threads; idx++) {
serverThreads[idx] = PR_CreateThread(PR_USER_THREAD,
- ServerThreadFunc, listenSock, PR_PRIORITY_NORMAL,
- thread_scope, PR_JOINABLE_THREAD, 0);
+ ServerThreadFunc, listenSock, PR_PRIORITY_NORMAL,
+ thread_scope, PR_JOINABLE_THREAD, 0);
if (NULL == serverThreads[idx]) {
fprintf(stderr, "PR_CreateThread failed\n");
exit(1);
diff --git a/pr/tests/multiwait.c b/pr/tests/multiwait.c
index 61b08df1..71e5ebdd 100644
--- a/pr/tests/multiwait.c
+++ b/pr/tests/multiwait.c
@@ -45,7 +45,9 @@ static PRIntn client_threads = 20, worker_threads = 2, wait_objects = 50;
((_expr)?((void)0):_MW_Assert(# _expr,__FILE__,__LINE__))
static void _MW_Assert(const char *s, const char *file, PRIntn ln)
{
- if (NULL != debug) PL_FPrintError(debug, NULL);
+ if (NULL != debug) {
+ PL_FPrintError(debug, NULL);
+ }
PR_Assert(s, file, ln);
} /* _MW_Assert */
#else
@@ -56,7 +58,8 @@ static void PrintRecvDesc(PRRecvWait *desc, const char *msg)
{
const char *tag[] = {
"PR_MW_INTERRUPT", "PR_MW_TIMEOUT",
- "PR_MW_FAILURE", "PR_MW_SUCCESS", "PR_MW_PENDING"};
+ "PR_MW_FAILURE", "PR_MW_SUCCESS", "PR_MW_PENDING"
+ };
PR_fprintf(
debug, "%s: PRRecvWait(@0x%x): {fd: 0x%x, outcome: %s, tmo: %u}\n",
msg, desc, desc->fd, tag[desc->outcome + 3], desc->timeout);
@@ -75,8 +78,9 @@ static Shared *MakeShared(const char *title)
static void DestroyShared(Shared *shared)
{
PRStatus rv;
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(debug, "%s: destroying group\n", shared->title);
+ }
rv = PR_DestroyWaitGroup(shared->group);
MW_ASSERT(PR_SUCCESS == rv);
PR_DestroyLock(shared->list_lock);
@@ -96,18 +100,21 @@ static PRRecvWait *CreateRecvWait(PRFileDesc *fd, PRIntervalTime timeout)
PR_AtomicIncrement(&desc_allocated);
- if (verbosity > chatty)
+ if (verbosity > chatty) {
PrintRecvDesc(desc_out, "Allocated");
+ }
return desc_out;
} /* CreateRecvWait */
static void DestroyRecvWait(PRRecvWait *desc_out)
{
- if (verbosity > chatty)
+ if (verbosity > chatty) {
PrintRecvDesc(desc_out, "Destroying");
+ }
PR_Close(desc_out->fd);
- if (NULL != desc_out->buffer.start)
+ if (NULL != desc_out->buffer.start) {
PR_DELETE(desc_out->buffer.start);
+ }
PR_Free(desc_out);
(void)PR_AtomicDecrement(&desc_allocated);
} /* DestroyRecvWait */
@@ -116,13 +123,16 @@ static void CancelGroup(Shared *shared)
{
PRRecvWait *desc_out;
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(debug, "%s Reclaiming wait descriptors\n", shared->title);
+ }
do
{
desc_out = PR_CancelWaitGroup(shared->group);
- if (NULL != desc_out) DestroyRecvWait(desc_out);
+ if (NULL != desc_out) {
+ DestroyRecvWait(desc_out);
+ }
} while (NULL != desc_out);
MW_ASSERT(0 == desc_allocated);
@@ -139,11 +149,14 @@ static void PR_CALLBACK ClientThread(void* arg)
Shared *shared = (Shared*)arg;
PRFileDesc *server = PR_NewTCPSocket();
if ((NULL == server)
- && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) return;
+ && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) {
+ return;
+ }
MW_ASSERT(NULL != server);
- if (verbosity > chatty)
+ if (verbosity > chatty) {
PR_fprintf(debug, "%s: Server socket @0x%x\n", shared->title, server);
+ }
/* Initialize the buffer so that Purify won't complain */
memset(buffer, 0, sizeof(buffer));
@@ -151,33 +164,40 @@ static void PR_CALLBACK ClientThread(void* arg)
rv = PR_InitializeNetAddr(PR_IpAddrLoopback, default_port, &server_address);
MW_ASSERT(PR_SUCCESS == rv);
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(debug, "%s: Client opening connection\n", shared->title);
+ }
rv = PR_Connect(server, &server_address, PR_INTERVAL_NO_TIMEOUT);
if (PR_FAILURE == rv)
{
- if (verbosity > silent) PL_FPrintError(debug, "Client connect failed");
+ if (verbosity > silent) {
+ PL_FPrintError(debug, "Client connect failed");
+ }
return;
}
while (ops_done < ops_required)
{
bytes = PR_Send(
- server, buffer, sizeof(buffer), empty_flags, PR_INTERVAL_NO_TIMEOUT);
- if ((-1 == bytes) && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) break;
+ server, buffer, sizeof(buffer), empty_flags, PR_INTERVAL_NO_TIMEOUT);
+ if ((-1 == bytes) && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) {
+ break;
+ }
MW_ASSERT(sizeof(buffer) == bytes);
if (verbosity > chatty)
PR_fprintf(
debug, "%s: Client sent %d bytes\n",
shared->title, sizeof(buffer));
bytes = PR_Recv(
- server, buffer, sizeof(buffer), empty_flags, PR_INTERVAL_NO_TIMEOUT);
+ server, buffer, sizeof(buffer), empty_flags, PR_INTERVAL_NO_TIMEOUT);
if (verbosity > chatty)
PR_fprintf(
debug, "%s: Client received %d bytes\n",
shared->title, sizeof(buffer));
- if ((-1 == bytes) && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) break;
+ if ((-1 == bytes) && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) {
+ break;
+ }
MW_ASSERT(sizeof(buffer) == bytes);
PR_Sleep(shared->timeout);
}
@@ -196,12 +216,16 @@ static void OneInThenCancelled(Shared *shared)
desc_in->fd = PR_NewTCPSocket();
desc_in->timeout = shared->timeout;
- if (verbosity > chatty) PrintRecvDesc(desc_in, "Adding desc");
+ if (verbosity > chatty) {
+ PrintRecvDesc(desc_in, "Adding desc");
+ }
rv = PR_AddWaitFileDesc(shared->group, desc_in);
MW_ASSERT(PR_SUCCESS == rv);
- if (verbosity > chatty) PrintRecvDesc(desc_in, "Cancelling");
+ if (verbosity > chatty) {
+ PrintRecvDesc(desc_in, "Cancelling");
+ }
rv = PR_CancelWaitFileDesc(shared->group, desc_in);
MW_ASSERT(PR_SUCCESS == rv);
@@ -209,13 +233,16 @@ static void OneInThenCancelled(Shared *shared)
MW_ASSERT(desc_out == desc_in);
MW_ASSERT(PR_MW_INTERRUPT == desc_out->outcome);
MW_ASSERT(PR_PENDING_INTERRUPT_ERROR == PR_GetError());
- if (verbosity > chatty) PrintRecvDesc(desc_out, "Ready");
+ if (verbosity > chatty) {
+ PrintRecvDesc(desc_out, "Ready");
+ }
rv = PR_Close(desc_in->fd);
MW_ASSERT(PR_SUCCESS == rv);
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(debug, "%s: destroying group\n", shared->title);
+ }
PR_DELETE(desc_in);
} /* OneInThenCancelled */
@@ -228,7 +255,9 @@ static void OneOpOneThread(Shared *shared)
desc_in->fd = PR_NewTCPSocket();
desc_in->timeout = shared->timeout;
- if (verbosity > chatty) PrintRecvDesc(desc_in, "Adding desc");
+ if (verbosity > chatty) {
+ PrintRecvDesc(desc_in, "Adding desc");
+ }
rv = PR_AddWaitFileDesc(shared->group, desc_in);
MW_ASSERT(PR_SUCCESS == rv);
@@ -236,7 +265,9 @@ static void OneOpOneThread(Shared *shared)
MW_ASSERT(desc_out == desc_in);
MW_ASSERT(PR_MW_TIMEOUT == desc_out->outcome);
MW_ASSERT(PR_IO_TIMEOUT_ERROR == PR_GetError());
- if (verbosity > chatty) PrintRecvDesc(desc_out, "Ready");
+ if (verbosity > chatty) {
+ PrintRecvDesc(desc_out, "Ready");
+ }
rv = PR_Close(desc_in->fd);
MW_ASSERT(PR_SUCCESS == rv);
@@ -251,8 +282,9 @@ static void ManyOpOneThread(Shared *shared)
PRRecvWait *desc_in;
PRRecvWait *desc_out;
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(debug, "%s: adding %d descs\n", shared->title, wait_objects);
+ }
for (index = 0; index < wait_objects; ++index)
{
@@ -267,7 +299,9 @@ static void ManyOpOneThread(Shared *shared)
desc_out = PR_WaitRecvReady(shared->group);
MW_ASSERT(PR_MW_TIMEOUT == desc_out->outcome);
MW_ASSERT(PR_IO_TIMEOUT_ERROR == PR_GetError());
- if (verbosity > chatty) PrintRecvDesc(desc_out, "Ready/readding");
+ if (verbosity > chatty) {
+ PrintRecvDesc(desc_out, "Ready/readding");
+ }
rv = PR_AddWaitFileDesc(shared->group, desc_out);
MW_ASSERT(PR_SUCCESS == rv);
(void)PR_AtomicIncrement(&ops_done);
@@ -287,18 +321,26 @@ static void PR_CALLBACK SomeOpsThread(void *arg)
if (NULL == desc_out)
{
MW_ASSERT(PR_PENDING_INTERRUPT_ERROR == PR_GetError());
- if (verbosity > quiet) PR_fprintf(debug, "Aborted\n");
+ if (verbosity > quiet) {
+ PR_fprintf(debug, "Aborted\n");
+ }
break;
}
MW_ASSERT(PR_MW_TIMEOUT == desc_out->outcome);
MW_ASSERT(PR_IO_TIMEOUT_ERROR == PR_GetError());
- if (verbosity > chatty) PrintRecvDesc(desc_out, "Ready");
+ if (verbosity > chatty) {
+ PrintRecvDesc(desc_out, "Ready");
+ }
- if (verbosity > chatty) PrintRecvDesc(desc_out, "Re-Adding");
+ if (verbosity > chatty) {
+ PrintRecvDesc(desc_out, "Re-Adding");
+ }
desc_out->timeout = shared->timeout;
rv = PR_AddWaitFileDesc(shared->group, desc_out);
PR_AtomicIncrement(&ops_done);
- if (ops_done > ops_required) break;
+ if (ops_done > ops_required) {
+ break;
+ }
} while (PR_SUCCESS == rv);
MW_ASSERT(PR_SUCCESS == rv);
} /* SomeOpsThread */
@@ -314,19 +356,21 @@ static void SomeOpsSomeThreads(Shared *shared)
/* Create some threads */
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(debug, "%s: creating threads\n", shared->title);
+ }
for (index = 0; index < worker_threads; ++index)
{
thread[index] = PR_CreateThread(
- PR_USER_THREAD, SomeOpsThread, shared,
- PR_PRIORITY_HIGH, thread_scope,
- PR_JOINABLE_THREAD, 16 * 1024);
+ PR_USER_THREAD, SomeOpsThread, shared,
+ PR_PRIORITY_HIGH, thread_scope,
+ PR_JOINABLE_THREAD, 16 * 1024);
}
/* then create some operations */
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(debug, "%s: creating desc\n", shared->title);
+ }
for (index = 0; index < wait_objects; ++index)
{
desc_in = CreateRecvWait(PR_NewTCPSocket(), shared->timeout);
@@ -334,12 +378,16 @@ static void SomeOpsSomeThreads(Shared *shared)
MW_ASSERT(PR_SUCCESS == rv);
}
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(debug, "%s: sleeping\n", shared->title);
- while (ops_done < ops_required) PR_Sleep(shared->timeout);
+ }
+ while (ops_done < ops_required) {
+ PR_Sleep(shared->timeout);
+ }
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(debug, "%s: interrupting/joining threads\n", shared->title);
+ }
for (index = 0; index < worker_threads; ++index)
{
rv = PR_Interrupt(thread[index]);
@@ -361,19 +409,25 @@ static PRStatus ServiceRequest(Shared *shared, PRRecvWait *desc)
debug, "%s: Service received %d bytes\n",
shared->title, desc->bytesRecv);
- if (0 == desc->bytesRecv) goto quitting;
+ if (0 == desc->bytesRecv) {
+ goto quitting;
+ }
if ((-1 == desc->bytesRecv)
- && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) goto aborted;
+ && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) {
+ goto aborted;
+ }
bytes_out = PR_Send(
- desc->fd, desc->buffer.start, desc->bytesRecv, 0, shared->timeout);
+ desc->fd, desc->buffer.start, desc->bytesRecv, 0, shared->timeout);
if (verbosity > chatty)
PR_fprintf(
debug, "%s: Service sent %d bytes\n",
shared->title, bytes_out);
if ((-1 == bytes_out)
- && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) goto aborted;
+ && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) {
+ goto aborted;
+ }
MW_ASSERT(bytes_out == desc->bytesRecv);
return PR_SUCCESS;
@@ -393,8 +447,9 @@ static void PR_CALLBACK ServiceThread(void *arg)
if (NULL != desc_out)
{
desc_out->timeout = PR_INTERVAL_NO_TIMEOUT;
- if (verbosity > chatty)
+ if (verbosity > chatty) {
PrintRecvDesc(desc_out, "Service re-adding");
+ }
rv = PR_AddWaitFileDesc(shared->group, desc_out);
MW_ASSERT(PR_SUCCESS == rv);
}
@@ -411,8 +466,9 @@ static void PR_CALLBACK ServiceThread(void *arg)
case PR_MW_SUCCESS:
{
PR_AtomicIncrement(&ops_done);
- if (verbosity > chatty)
+ if (verbosity > chatty) {
PrintRecvDesc(desc_out, "Service ready");
+ }
rv = ServiceRequest(shared, desc_out);
break;
}
@@ -423,15 +479,18 @@ static void PR_CALLBACK ServiceThread(void *arg)
case PR_MW_TIMEOUT:
MW_ASSERT(PR_IO_TIMEOUT_ERROR == PR_GetError());
case PR_MW_FAILURE:
- if (verbosity > silent)
+ if (verbosity > silent) {
PL_FPrintError(debug, "RecvReady failure");
+ }
break;
default:
break;
}
} while (PR_SUCCESS == rv);
- if (NULL != desc_out) DestroyRecvWait(desc_out);
+ if (NULL != desc_out) {
+ DestroyRecvWait(desc_out);
+ }
} /* ServiceThread */
@@ -451,12 +510,14 @@ static void PR_CALLBACK EnumerationThread(void *arg)
desc = NULL;
while (NULL != (desc = PR_EnumerateWaitGroup(enumerator, desc)))
{
- if (verbosity > chatty) PrintRecvDesc(desc, shared->title);
+ if (verbosity > chatty) {
+ PrintRecvDesc(desc, shared->title);
+ }
count += 1;
}
if (verbosity > silent)
PR_fprintf(debug,
- "%s Enumerated %d objects\n", shared->title, count);
+ "%s Enumerated %d objects\n", shared->title, count);
}
MW_ASSERT(PR_PENDING_INTERRUPT_ERROR == PR_GetError());
@@ -477,14 +538,15 @@ static void PR_CALLBACK ServerThread(void *arg)
PRNetAddr server_address, client_address;
worker_thread = (PRThread**)PR_CALLOC(sizeof(PRThread*) * worker_threads);
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(debug, "%s: Server creating worker_threads\n", shared->title);
+ }
for (index = 0; index < worker_threads; ++index)
{
worker_thread[index] = PR_CreateThread(
- PR_USER_THREAD, ServiceThread, shared,
- PR_PRIORITY_HIGH, thread_scope,
- PR_JOINABLE_THREAD, 16 * 1024);
+ PR_USER_THREAD, ServiceThread, shared,
+ PR_PRIORITY_HIGH, thread_scope,
+ PR_JOINABLE_THREAD, 16 * 1024);
}
rv = PR_InitializeNetAddr(PR_IpAddrAny, default_port, &server_address);
@@ -499,12 +561,15 @@ static void PR_CALLBACK ServerThread(void *arg)
rv = PR_Listen(listener, 10); MW_ASSERT(PR_SUCCESS == rv);
while (ops_done < ops_required)
{
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(debug, "%s: Server accepting connection\n", shared->title);
+ }
service = PR_Accept(listener, &client_address, PR_INTERVAL_NO_TIMEOUT);
if (NULL == service)
{
- if (PR_PENDING_INTERRUPT_ERROR == PR_GetError()) break;
+ if (PR_PENDING_INTERRUPT_ERROR == PR_GetError()) {
+ break;
+ }
PL_PrintError("Accept failed");
MW_ASSERT(PR_FALSE && "Accept failed");
}
@@ -512,15 +577,17 @@ static void PR_CALLBACK ServerThread(void *arg)
{
desc_in = CreateRecvWait(service, shared->timeout);
desc_in->timeout = PR_INTERVAL_NO_TIMEOUT;
- if (verbosity > chatty)
+ if (verbosity > chatty) {
PrintRecvDesc(desc_in, "Service adding");
+ }
rv = PR_AddWaitFileDesc(shared->group, desc_in);
MW_ASSERT(PR_SUCCESS == rv);
}
}
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(debug, "%s: Server interrupting worker_threads\n", shared->title);
+ }
for (index = 0; index < worker_threads; ++index)
{
rv = PR_Interrupt(worker_thread[index]);
@@ -552,41 +619,48 @@ static void RealOneGroupIO(Shared *shared)
PRIntn index;
PRThread *server_thread, *enumeration_thread, **client_thread;
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(debug, "%s: creating server_thread\n", shared->title);
+ }
server_thread = PR_CreateThread(
- PR_USER_THREAD, ServerThread, shared,
- PR_PRIORITY_HIGH, thread_scope,
- PR_JOINABLE_THREAD, 16 * 1024);
+ PR_USER_THREAD, ServerThread, shared,
+ PR_PRIORITY_HIGH, thread_scope,
+ PR_JOINABLE_THREAD, 16 * 1024);
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(debug, "%s: creating enumeration_thread\n", shared->title);
+ }
enumeration_thread = PR_CreateThread(
- PR_USER_THREAD, EnumerationThread, shared,
- PR_PRIORITY_HIGH, thread_scope,
- PR_JOINABLE_THREAD, 16 * 1024);
+ PR_USER_THREAD, EnumerationThread, shared,
+ PR_PRIORITY_HIGH, thread_scope,
+ PR_JOINABLE_THREAD, 16 * 1024);
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(debug, "%s: snoozing before creating clients\n", shared->title);
+ }
PR_Sleep(5 * shared->timeout);
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(debug, "%s: creating client_threads\n", shared->title);
+ }
client_thread = (PRThread**)PR_CALLOC(sizeof(PRThread*) * client_threads);
for (index = 0; index < client_threads; ++index)
{
client_thread[index] = PR_CreateThread(
- PR_USER_THREAD, ClientThread, shared,
- PR_PRIORITY_NORMAL, thread_scope,
- PR_JOINABLE_THREAD, 16 * 1024);
+ PR_USER_THREAD, ClientThread, shared,
+ PR_PRIORITY_NORMAL, thread_scope,
+ PR_JOINABLE_THREAD, 16 * 1024);
}
- while (ops_done < ops_required) PR_Sleep(shared->timeout);
+ while (ops_done < ops_required) {
+ PR_Sleep(shared->timeout);
+ }
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(debug, "%s: interrupting/joining client_threads\n", shared->title);
+ }
for (index = 0; index < client_threads; ++index)
{
rv = PR_Interrupt(client_thread[index]);
@@ -596,15 +670,17 @@ static void RealOneGroupIO(Shared *shared)
}
PR_DELETE(client_thread);
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(debug, "%s: interrupting/joining enumeration_thread\n", shared->title);
+ }
rv = PR_Interrupt(enumeration_thread);
MW_ASSERT(PR_SUCCESS == rv);
rv = PR_JoinThread(enumeration_thread);
MW_ASSERT(PR_SUCCESS == rv);
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(debug, "%s: interrupting/joining server_thread\n", shared->title);
+ }
rv = PR_Interrupt(server_thread);
MW_ASSERT(PR_SUCCESS == rv);
rv = PR_JoinThread(server_thread);
@@ -617,8 +693,9 @@ static void RunThisOne(
Shared *shared;
if ((NULL == test_name) || (0 == PL_strcmp(name, test_name)))
{
- if (verbosity > silent)
+ if (verbosity > silent) {
PR_fprintf(debug, "%s()\n", name);
+ }
shared = MakeShared(name);
ops_done = 0;
func(shared); /* run the test */
@@ -641,46 +718,51 @@ int main(int argc, char **argv)
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:
- test_name = opt->value;
- break;
- case 'd': /* debug mode */
- if (verbosity < noisy)
- verbosity = ChangeVerbosity(verbosity, 1);
- break;
- case 'q': /* debug mode */
- if (verbosity > silent)
- verbosity = ChangeVerbosity(verbosity, -1);
- break;
- case 'G': /* use global threads */
- thread_scope = PR_GLOBAL_THREAD;
- break;
- case 'c': /* number of client threads */
- client_threads = atoi(opt->value);
- break;
- case 'o': /* operations to compelete */
- ops_required = atoi(opt->value);
- break;
- case 'p': /* default port */
- default_port = atoi(opt->value);
- break;
- case 't': /* number of threads waiting */
- worker_threads = atoi(opt->value);
- break;
- case 'w': /* number of wait objects */
- wait_objects = atoi(opt->value);
- break;
- default:
- break;
+ case 0:
+ test_name = opt->value;
+ break;
+ case 'd': /* debug mode */
+ if (verbosity < noisy) {
+ verbosity = ChangeVerbosity(verbosity, 1);
+ }
+ break;
+ case 'q': /* debug mode */
+ if (verbosity > silent) {
+ verbosity = ChangeVerbosity(verbosity, -1);
+ }
+ break;
+ case 'G': /* use global threads */
+ thread_scope = PR_GLOBAL_THREAD;
+ break;
+ case 'c': /* number of client threads */
+ client_threads = atoi(opt->value);
+ break;
+ case 'o': /* operations to compelete */
+ ops_required = atoi(opt->value);
+ break;
+ case 'p': /* default port */
+ default_port = atoi(opt->value);
+ break;
+ case 't': /* number of threads waiting */
+ worker_threads = atoi(opt->value);
+ break;
+ case 'w': /* number of wait objects */
+ wait_objects = atoi(opt->value);
+ break;
+ default:
+ break;
}
}
PL_DestroyOptState(opt);
- if (verbosity > 0)
+ if (verbosity > 0) {
debug = PR_GetSpecialFD(PR_StandardError);
+ }
RunThisOne(OneInThenCancelled, "OneInThenCancelled", test_name);
RunThisOne(OneOpOneThread, "OneOpOneThread", test_name);
diff --git a/pr/tests/nameshm1.c b/pr/tests/nameshm1.c
index beadb98d..3f7137e2 100644
--- a/pr/tests/nameshm1.c
+++ b/pr/tests/nameshm1.c
@@ -112,76 +112,76 @@ static void BasicTest( void )
PRInt32 rc;
PR_LOG( lm, msgLevel,
- ( "nameshm1: Begin BasicTest" ));
+ ( "nameshm1: Begin BasicTest" ));
if ( PR_FAILURE == PR_DeleteSharedMemory( optName )) {
PR_LOG( lm, msgLevel,
- ("nameshm1: Initial PR_DeleteSharedMemory() failed. No problem"));
+ ("nameshm1: Initial PR_DeleteSharedMemory() failed. No problem"));
} else
PR_LOG( lm, msgLevel,
- ("nameshm1: Initial PR_DeleteSharedMemory() success"));
+ ("nameshm1: Initial PR_DeleteSharedMemory() success"));
shm = PR_OpenSharedMemory( optName, optSize, (PR_SHM_CREATE | PR_SHM_EXCL), SHM_MODE );
if ( NULL == shm )
{
PR_LOG( lm, msgLevel,
- ( "nameshm1: RW Create: Error: %ld. OSError: %ld", PR_GetError(), PR_GetOSError()));
+ ( "nameshm1: RW Create: Error: %ld. OSError: %ld", PR_GetError(), PR_GetOSError()));
failed_already = 1;
return;
}
PR_LOG( lm, msgLevel,
- ( "nameshm1: RW Create: success: %p", shm ));
+ ( "nameshm1: RW Create: success: %p", shm ));
- addr = PR_AttachSharedMemory( shm , 0 );
+ addr = PR_AttachSharedMemory( shm, 0 );
if ( NULL == addr )
{
PR_LOG( lm, msgLevel,
- ( "nameshm1: RW Attach: Error: %ld. OSError: %ld", PR_GetError(), PR_GetOSError()));
+ ( "nameshm1: RW Attach: Error: %ld. OSError: %ld", PR_GetError(), PR_GetOSError()));
failed_already = 1;
return;
}
PR_LOG( lm, msgLevel,
- ( "nameshm1: RW Attach: success: %p", addr ));
+ ( "nameshm1: RW Attach: success: %p", addr ));
/* fill memory with i */
for ( i = 0; i < optSize ; i++ )
{
- *(addr + i) = i;
+ *(addr + i) = i;
}
rc = PR_DetachSharedMemory( shm, addr );
if ( PR_FAILURE == rc )
{
PR_LOG( lm, msgLevel,
- ( "nameshm1: RW Detach: Error: %ld. OSError: %ld", PR_GetError(), PR_GetOSError()));
+ ( "nameshm1: RW Detach: Error: %ld. OSError: %ld", PR_GetError(), PR_GetOSError()));
failed_already = 1;
return;
}
PR_LOG( lm, msgLevel,
- ( "nameshm1: RW Detach: success: " ));
+ ( "nameshm1: RW Detach: success: " ));
rc = PR_CloseSharedMemory( shm );
if ( PR_FAILURE == rc )
{
PR_LOG( lm, msgLevel,
- ( "nameshm1: RW Close: Error: %ld. OSError: %ld", PR_GetError(), PR_GetOSError()));
+ ( "nameshm1: RW Close: Error: %ld. OSError: %ld", PR_GetError(), PR_GetOSError()));
failed_already = 1;
return;
}
PR_LOG( lm, msgLevel,
- ( "nameshm1: RW Close: success: " ));
+ ( "nameshm1: RW Close: success: " ));
rc = PR_DeleteSharedMemory( optName );
if ( PR_FAILURE == rc )
{
PR_LOG( lm, msgLevel,
- ( "nameshm1: RW Delete: Error: %ld. OSError: %ld", PR_GetError(), PR_GetOSError()));
+ ( "nameshm1: RW Delete: Error: %ld. OSError: %ld", PR_GetError(), PR_GetOSError()));
failed_already = 1;
return;
}
PR_LOG( lm, msgLevel,
- ( "nameshm1: RW Delete: success: " ));
+ ( "nameshm1: RW Delete: success: " ));
PR_LOG( lm, msgLevel,
("nameshm1: BasicTest(): Passed"));
@@ -196,30 +196,30 @@ static void ReadOnlyTest( void )
PRInt32 rc;
PR_LOG( lm, msgLevel,
- ( "nameshm1: Begin ReadOnlyTest" ));
+ ( "nameshm1: Begin ReadOnlyTest" ));
shm = PR_OpenSharedMemory( optName, optSize, (PR_SHM_CREATE | PR_SHM_EXCL), SHM_MODE);
if ( NULL == shm )
{
PR_LOG( lm, msgLevel,
- ( "nameshm1: RO Create: Error: %ld. OSError: %ld", PR_GetError(), PR_GetOSError()));
+ ( "nameshm1: RO Create: Error: %ld. OSError: %ld", PR_GetError(), PR_GetOSError()));
failed_already = 1;
return;
}
PR_LOG( lm, msgLevel,
- ( "nameshm1: RO Create: success: %p", shm ));
+ ( "nameshm1: RO Create: success: %p", shm ));
- roAddr = PR_AttachSharedMemory( shm , PR_SHM_READONLY );
+ roAddr = PR_AttachSharedMemory( shm, PR_SHM_READONLY );
if ( NULL == roAddr )
{
PR_LOG( lm, msgLevel,
- ( "nameshm1: RO Attach: Error: %ld. OSError: %ld", PR_GetError(), PR_GetOSError()));
+ ( "nameshm1: RO Attach: Error: %ld. OSError: %ld", PR_GetError(), PR_GetOSError()));
failed_already = 1;
return;
}
PR_LOG( lm, msgLevel,
- ( "nameshm1: RO Attach: success: %p", roAddr ));
+ ( "nameshm1: RO Attach: success: %p", roAddr ));
if ( optWriteRO )
{
@@ -233,37 +233,37 @@ static void ReadOnlyTest( void )
if ( PR_FAILURE == rc )
{
PR_LOG( lm, msgLevel,
- ( "nameshm1: RO Detach: Error: %ld. OSError: %ld", PR_GetError(), PR_GetOSError()));
+ ( "nameshm1: RO Detach: Error: %ld. OSError: %ld", PR_GetError(), PR_GetOSError()));
failed_already = 1;
return;
}
PR_LOG( lm, msgLevel,
- ( "nameshm1: RO Detach: success: " ));
+ ( "nameshm1: RO Detach: success: " ));
rc = PR_CloseSharedMemory( shm );
if ( PR_FAILURE == rc )
{
PR_LOG( lm, msgLevel,
- ( "nameshm1: RO Close: Error: %ld. OSError: %ld", PR_GetError(), PR_GetOSError()));
+ ( "nameshm1: RO Close: Error: %ld. OSError: %ld", PR_GetError(), PR_GetOSError()));
failed_already = 1;
return;
}
PR_LOG( lm, msgLevel,
- ( "nameshm1: RO Close: success: " ));
+ ( "nameshm1: RO Close: success: " ));
rc = PR_DeleteSharedMemory( optName );
if ( PR_FAILURE == rc )
{
PR_LOG( lm, msgLevel,
- ( "nameshm1: RO Destroy: Error: %ld. OSError: %ld", PR_GetError(), PR_GetOSError()));
+ ( "nameshm1: RO Destroy: Error: %ld. OSError: %ld", PR_GetError(), PR_GetOSError()));
failed_already = 1;
return;
}
PR_LOG( lm, msgLevel,
- ( "nameshm1: RO Destroy: success: " ));
+ ( "nameshm1: RO Destroy: success: " ));
PR_LOG( lm, msgLevel,
- ("nameshm1: ReadOnlyTest(): Passed"));
+ ("nameshm1: ReadOnlyTest(): Passed"));
return;
} /* end ReadOnlyTest() */
@@ -289,28 +289,28 @@ static void DoClient( void )
if ( NULL == shm )
{
PR_LOG( lm, msgLevel,
- ( "nameshm1: DoClient(): Create: Error: %ld. OSError: %ld",
- PR_GetError(), PR_GetOSError()));
+ ( "nameshm1: DoClient(): Create: Error: %ld. OSError: %ld",
+ PR_GetError(), PR_GetOSError()));
failed_already = 1;
return;
}
PR_LOG( lm, msgLevel,
- ( "nameshm1: DoClient(): Create: success: %p", shm ));
+ ( "nameshm1: DoClient(): Create: success: %p", shm ));
- addr = PR_AttachSharedMemory( shm , 0 );
+ addr = PR_AttachSharedMemory( shm, 0 );
if ( NULL == addr )
{
PR_LOG( lm, msgLevel,
- ( "nameshm1: DoClient(): Attach: Error: %ld. OSError: %ld",
- PR_GetError(), PR_GetOSError()));
+ ( "nameshm1: DoClient(): Attach: Error: %ld. OSError: %ld",
+ PR_GetError(), PR_GetOSError()));
failed_already = 1;
return;
}
PR_LOG( lm, msgLevel,
- ( "nameshm1: DoClient(): Attach: success: %p", addr ));
+ ( "nameshm1: DoClient(): Attach: success: %p", addr ));
PR_LOG( lm, msgLevel,
- ( "Client found: %s", addr));
+ ( "Client found: %s", addr));
PR_Sleep(PR_SecondsToInterval(4));
for ( i = 0 ; i < optPing ; i++ )
@@ -322,7 +322,7 @@ static void DoClient( void )
PR_ASSERT( (*addr % 2) == 0 );
if ( optVerbose )
PR_LOG( lm, msgLevel,
- ( "nameshm1: Client ping: %d, i: %d", *addr, i));
+ ( "nameshm1: Client ping: %d, i: %d", *addr, i));
rc = PR_PostSemaphore( sem1 );
PR_ASSERT( PR_FAILURE != rc );
@@ -338,25 +338,25 @@ static void DoClient( void )
if ( PR_FAILURE == rc )
{
PR_LOG( lm, msgLevel,
- ( "nameshm1: DoClient(): Detach: Error: %ld. OSError: %ld",
- PR_GetError(), PR_GetOSError()));
+ ( "nameshm1: DoClient(): Detach: Error: %ld. OSError: %ld",
+ PR_GetError(), PR_GetOSError()));
failed_already = 1;
return;
}
PR_LOG( lm, msgLevel,
- ( "nameshm1: DoClient(): Detach: success: " ));
+ ( "nameshm1: DoClient(): Detach: success: " ));
rc = PR_CloseSharedMemory( shm );
if ( PR_FAILURE == rc )
{
PR_LOG( lm, msgLevel,
- ( "nameshm1: DoClient(): Close: Error: %ld. OSError: %ld",
- PR_GetError(), PR_GetOSError()));
+ ( "nameshm1: DoClient(): Close: Error: %ld. OSError: %ld",
+ PR_GetError(), PR_GetOSError()));
failed_already = 1;
return;
}
PR_LOG( lm, msgLevel,
- ( "nameshm1: DoClient(): Close: success: " ));
+ ( "nameshm1: DoClient(): Close: success: " ));
return;
} /* end DoClient() */
@@ -374,39 +374,39 @@ static void ClientServerTest( void )
char buf[24];
PR_LOG( lm, msgLevel,
- ( "nameshm1: Begin ClientServerTest" ));
+ ( "nameshm1: Begin ClientServerTest" ));
rc = PR_DeleteSharedMemory( optName );
if ( PR_FAILURE == rc )
{
PR_LOG( lm, msgLevel,
- ( "nameshm1: Server: Destroy: failed. No problem"));
+ ( "nameshm1: Server: Destroy: failed. No problem"));
} else
PR_LOG( lm, msgLevel,
- ( "nameshm1: Server: Destroy: success" ));
+ ( "nameshm1: Server: Destroy: success" ));
shm = PR_OpenSharedMemory( optName, optSize, (PR_SHM_CREATE | PR_SHM_EXCL), SHM_MODE);
if ( NULL == shm )
{
PR_LOG( lm, msgLevel,
- ( "nameshm1: Server: Create: Error: %ld. OSError: %ld", PR_GetError(), PR_GetOSError()));
+ ( "nameshm1: Server: Create: Error: %ld. OSError: %ld", PR_GetError(), PR_GetOSError()));
failed_already = 1;
return;
}
PR_LOG( lm, msgLevel,
- ( "nameshm1: Server: Create: success: %p", shm ));
+ ( "nameshm1: Server: Create: success: %p", shm ));
- addr = PR_AttachSharedMemory( shm , 0 );
+ addr = PR_AttachSharedMemory( shm, 0 );
if ( NULL == addr )
{
PR_LOG( lm, msgLevel,
- ( "nameshm1: Server: Attach: Error: %ld. OSError: %ld", PR_GetError(), PR_GetOSError()));
+ ( "nameshm1: Server: Attach: Error: %ld. OSError: %ld", PR_GetError(), PR_GetOSError()));
failed_already = 1;
return;
}
PR_LOG( lm, msgLevel,
- ( "nameshm1: Server: Attach: success: %p", addr ));
+ ( "nameshm1: Server: Attach: success: %p", addr ));
sem1 = PR_OpenSemaphore( SEM_NAME1, PR_SEM_CREATE, SEM_MODE, 0 );
PR_ASSERT( sem1 );
@@ -439,7 +439,7 @@ static void ClientServerTest( void )
PR_ASSERT( (*addr % 2) == 1 );
if ( optVerbose )
PR_LOG( lm, msgLevel,
- ( "nameshm1: Server pong: %d, i: %d", *addr, i));
+ ( "nameshm1: Server pong: %d, i: %d", *addr, i));
rc = PR_PostSemaphore( sem2 );
@@ -465,37 +465,37 @@ static void ClientServerTest( void )
if ( PR_FAILURE == rc )
{
PR_LOG( lm, msgLevel,
- ( "nameshm1: Server: Detach: Error: %ld. OSError: %ld",
- PR_GetError(), PR_GetOSError()));
+ ( "nameshm1: Server: Detach: Error: %ld. OSError: %ld",
+ PR_GetError(), PR_GetOSError()));
failed_already = 1;
return;
}
PR_LOG( lm, msgLevel,
- ( "nameshm1: Server: Detach: success: " ));
+ ( "nameshm1: Server: Detach: success: " ));
rc = PR_CloseSharedMemory( shm );
if ( PR_FAILURE == rc )
{
PR_LOG( lm, msgLevel,
- ( "nameshm1: Server: Close: Error: %ld. OSError: %ld",
- PR_GetError(), PR_GetOSError()));
+ ( "nameshm1: Server: Close: Error: %ld. OSError: %ld",
+ PR_GetError(), PR_GetOSError()));
failed_already = 1;
return;
}
PR_LOG( lm, msgLevel,
- ( "nameshm1: Server: Close: success: " ));
+ ( "nameshm1: Server: Close: success: " ));
rc = PR_DeleteSharedMemory( optName );
if ( PR_FAILURE == rc )
{
PR_LOG( lm, msgLevel,
- ( "nameshm1: Server: Destroy: Error: %ld. OSError: %ld",
- PR_GetError(), PR_GetOSError()));
+ ( "nameshm1: Server: Destroy: Error: %ld. OSError: %ld",
+ PR_GetError(), PR_GetOSError()));
failed_already = 1;
return;
}
PR_LOG( lm, msgLevel,
- ( "nameshm1: Server: Destroy: success" ));
+ ( "nameshm1: Server: Destroy: success" ));
return;
} /* end ClientServerTest() */
@@ -509,61 +509,67 @@ int main(int argc, char **argv)
PLOptStatus os;
PLOptState *opt = PL_CreateOptState(argc, argv, "Cdvw:s:p:i:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ 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': /* debug mode */
- optVerbose = 1;
+ case 'v': /* debug mode */
+ optVerbose = 1;
/* no break! fall into debug option */
- case 'd': /* debug mode */
- debug = 1;
- msgLevel = PR_LOG_DEBUG;
- break;
- case 'w': /* try writing to memory mapped read-only */
- optWriteRO = 1;
- break;
- case 'C':
- optClient = 1;
- break;
- case 's':
- optSize = atol(opt->value) * 1024;
- break;
- case 'p':
- optPing = atol(opt->value);
- break;
- case 'i':
- optClientIterations = atol(opt->value);
- break;
- default:
- strcpy( optName, opt->value );
- break;
+ case 'd': /* debug mode */
+ debug = 1;
+ msgLevel = PR_LOG_DEBUG;
+ break;
+ case 'w': /* try writing to memory mapped read-only */
+ optWriteRO = 1;
+ break;
+ case 'C':
+ optClient = 1;
+ break;
+ case 's':
+ optSize = atol(opt->value) * 1024;
+ break;
+ case 'p':
+ optPing = atol(opt->value);
+ break;
+ case 'i':
+ optClientIterations = atol(opt->value);
+ break;
+ default:
+ strcpy( optName, opt->value );
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
}
lm = PR_NewLogModule("Test"); /* Initialize logging */
PR_LOG( lm, msgLevel,
- ( "nameshm1: Starting" ));
+ ( "nameshm1: Starting" ));
if ( optClient )
{
DoClient();
} else {
BasicTest();
- if ( failed_already != 0 )
+ if ( failed_already != 0 ) {
goto Finished;
+ }
ReadOnlyTest();
- if ( failed_already != 0 )
+ if ( failed_already != 0 ) {
goto Finished;
+ }
ClientServerTest();
}
Finished:
- if ( debug ) printf("%s\n", (failed_already)? "FAIL" : "PASS" );
+ if ( debug ) {
+ printf("%s\n", (failed_already)? "FAIL" : "PASS" );
+ }
return( (failed_already)? 1 : 0 );
} /* main() */
/* end instrumt.c */
diff --git a/pr/tests/nbconn.c b/pr/tests/nbconn.c
index 8ff01efa..d1dd67c0 100644
--- a/pr/tests/nbconn.c
+++ b/pr/tests/nbconn.c
@@ -30,12 +30,12 @@
#include <string.h>
#define SERVER_MAX_BIND_COUNT 100
-#define DATA_BUF_SIZE 256
+#define DATA_BUF_SIZE 256
#define TCP_SERVER_PORT 10000
#define TCP_UNUSED_PORT 211
typedef struct Server_Param {
- PRFileDesc *sp_fd; /* server port */
+ PRFileDesc *sp_fd; /* server port */
} Server_Param;
static void PR_CALLBACK TCP_Server(void *arg);
@@ -53,9 +53,9 @@ int main(int argc, char **argv)
PRPollDesc pd;
PRStatus rv;
PRSocketOptionData optData;
- const char *hostname = NULL;
+ const char *hostname = NULL;
PRIntn default_case, n, bytes_read, bytes_sent;
- PRInt32 failed_already = 0;
+ PRInt32 failed_already = 0;
/*
* -d debug mode
@@ -65,112 +65,117 @@ int main(int argc, char **argv)
PLOptState *opt = PL_CreateOptState(argc, argv, "d");
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: /* debug mode */
- hostname = opt->value;
- break;
- case 'd': /* debug mode */
- _debug_on = 1;
- break;
- default:
- break;
+ case 0: /* debug mode */
+ hostname = opt->value;
+ break;
+ case 'd': /* debug mode */
+ _debug_on = 1;
+ break;
+ default:
+ break;
}
}
PL_DestroyOptState(opt);
PR_STDIO_INIT();
- if (hostname)
- default_case = 0;
- else
- default_case = 1;
-
- if (default_case) {
-
- /*
- * In the default case the following tests are executed:
- * 1. successful connection: a server thread accepts a connection
- * from the main thread
- * 2. unsuccessful connection: the main thread tries to connect to a
- * nonexistent port and expects to get an error
- */
- rv = connection_success_test();
- if (rv == 0)
- rv = connection_failure_test();
- return rv;
- } else {
- PRFileDesc *sock;
-
- if (PR_GetHostByName(argv[1], buf, sizeof(buf), &he) == PR_FAILURE) {
- printf( "Unknown host: %s\n", argv[1]);
- exit(1);
- } else {
- printf( "host: %s\n", buf);
- }
- PR_EnumerateHostEnt(0, &he, 80, &addr);
-
- sock = PR_NewTCPSocket();
- optData.option = PR_SockOpt_Nonblocking;
- optData.value.non_blocking = PR_TRUE;
- PR_SetSocketOption(sock, &optData);
- rv = PR_Connect(sock, &addr, PR_INTERVAL_NO_TIMEOUT);
- if (rv == PR_FAILURE && PR_GetError() == PR_IN_PROGRESS_ERROR) {
- printf( "Connect in progress\n");
- }
-
- pd.fd = sock;
- pd.in_flags = PR_POLL_WRITE | PR_POLL_EXCEPT;
- n = PR_Poll(&pd, 1, PR_INTERVAL_NO_TIMEOUT);
- if (n == -1) {
- printf( "PR_Poll failed\n");
- exit(1);
- }
- printf( "PR_Poll returns %d\n", n);
- if (pd.out_flags & PR_POLL_READ) {
- printf( "PR_POLL_READ\n");
- }
- if (pd.out_flags & PR_POLL_WRITE) {
- printf( "PR_POLL_WRITE\n");
- }
- if (pd.out_flags & PR_POLL_EXCEPT) {
- printf( "PR_POLL_EXCEPT\n");
- }
- if (pd.out_flags & PR_POLL_ERR) {
- printf( "PR_POLL_ERR\n");
- }
- if (pd.out_flags & PR_POLL_NVAL) {
- printf( "PR_POLL_NVAL\n");
- }
-
- if (PR_GetConnectStatus(&pd) == PR_SUCCESS) {
- printf("PR_GetConnectStatus: connect succeeded\n");
- PR_Write(sock, "GET /\r\n\r\n", 9);
- PR_Shutdown(sock, PR_SHUTDOWN_SEND);
- pd.in_flags = PR_POLL_READ;
- while (1) {
- n = PR_Poll(&pd, 1, PR_INTERVAL_NO_TIMEOUT);
- printf( "poll returns %d\n", n);
- n = PR_Read(sock, buf, sizeof(buf));
- printf( "read returns %d\n", n);
- if (n <= 0) {
- break;
- }
- PR_Write(PR_STDOUT, buf, n);
- }
- } else {
- if (PR_GetError() == PR_IN_PROGRESS_ERROR) {
- printf( "PR_GetConnectStatus: connect still in progress\n");
- exit(1);
- }
- printf( "PR_GetConnectStatus: connect failed: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
- }
- PR_Close(sock);
- printf( "PASS\n");
- return 0;
-
- }
+ if (hostname) {
+ default_case = 0;
+ }
+ else {
+ default_case = 1;
+ }
+
+ if (default_case) {
+
+ /*
+ * In the default case the following tests are executed:
+ * 1. successful connection: a server thread accepts a connection
+ * from the main thread
+ * 2. unsuccessful connection: the main thread tries to connect to a
+ * nonexistent port and expects to get an error
+ */
+ rv = connection_success_test();
+ if (rv == 0) {
+ rv = connection_failure_test();
+ }
+ return rv;
+ } else {
+ PRFileDesc *sock;
+
+ if (PR_GetHostByName(argv[1], buf, sizeof(buf), &he) == PR_FAILURE) {
+ printf( "Unknown host: %s\n", argv[1]);
+ exit(1);
+ } else {
+ printf( "host: %s\n", buf);
+ }
+ PR_EnumerateHostEnt(0, &he, 80, &addr);
+
+ sock = PR_NewTCPSocket();
+ optData.option = PR_SockOpt_Nonblocking;
+ optData.value.non_blocking = PR_TRUE;
+ PR_SetSocketOption(sock, &optData);
+ rv = PR_Connect(sock, &addr, PR_INTERVAL_NO_TIMEOUT);
+ if (rv == PR_FAILURE && PR_GetError() == PR_IN_PROGRESS_ERROR) {
+ printf( "Connect in progress\n");
+ }
+
+ pd.fd = sock;
+ pd.in_flags = PR_POLL_WRITE | PR_POLL_EXCEPT;
+ n = PR_Poll(&pd, 1, PR_INTERVAL_NO_TIMEOUT);
+ if (n == -1) {
+ printf( "PR_Poll failed\n");
+ exit(1);
+ }
+ printf( "PR_Poll returns %d\n", n);
+ if (pd.out_flags & PR_POLL_READ) {
+ printf( "PR_POLL_READ\n");
+ }
+ if (pd.out_flags & PR_POLL_WRITE) {
+ printf( "PR_POLL_WRITE\n");
+ }
+ if (pd.out_flags & PR_POLL_EXCEPT) {
+ printf( "PR_POLL_EXCEPT\n");
+ }
+ if (pd.out_flags & PR_POLL_ERR) {
+ printf( "PR_POLL_ERR\n");
+ }
+ if (pd.out_flags & PR_POLL_NVAL) {
+ printf( "PR_POLL_NVAL\n");
+ }
+
+ if (PR_GetConnectStatus(&pd) == PR_SUCCESS) {
+ printf("PR_GetConnectStatus: connect succeeded\n");
+ PR_Write(sock, "GET /\r\n\r\n", 9);
+ PR_Shutdown(sock, PR_SHUTDOWN_SEND);
+ pd.in_flags = PR_POLL_READ;
+ while (1) {
+ n = PR_Poll(&pd, 1, PR_INTERVAL_NO_TIMEOUT);
+ printf( "poll returns %d\n", n);
+ n = PR_Read(sock, buf, sizeof(buf));
+ printf( "read returns %d\n", n);
+ if (n <= 0) {
+ break;
+ }
+ PR_Write(PR_STDOUT, buf, n);
+ }
+ } else {
+ if (PR_GetError() == PR_IN_PROGRESS_ERROR) {
+ printf( "PR_GetConnectStatus: connect still in progress\n");
+ exit(1);
+ }
+ printf( "PR_GetConnectStatus: connect failed: (%ld, %ld)\n",
+ PR_GetError(), PR_GetOSError());
+ }
+ PR_Close(sock);
+ printf( "PASS\n");
+ return 0;
+
+ }
}
@@ -184,40 +189,40 @@ TCP_Server(void *arg)
{
Server_Param *sp = (Server_Param *) arg;
PRFileDesc *sockfd, *newsockfd;
- char data_buf[DATA_BUF_SIZE];
+ char data_buf[DATA_BUF_SIZE];
PRIntn rv, bytes_read;
- sockfd = sp->sp_fd;
- if ((newsockfd = PR_Accept(sockfd, NULL,
- PR_INTERVAL_NO_TIMEOUT)) == NULL) {
- fprintf(stderr,"ERROR - PR_Accept failed: (%d,%d)\n",
- PR_GetError(), PR_GetOSError());
- return;
- }
- bytes_read = 0;
- while (bytes_read != DATA_BUF_SIZE) {
- rv = PR_Read(newsockfd, data_buf + bytes_read ,
- DATA_BUF_SIZE - bytes_read);
- if (rv < 0) {
- fprintf(stderr,"Error - PR_Read failed: (%d, %d)\n",
- PR_GetError(), PR_GetOSError());
- PR_Close(newsockfd);
- return;
- }
- PR_ASSERT(rv != 0);
- bytes_read += rv;
- }
- DPRINTF(("Bytes read from client - %d\n",bytes_read));
- rv = PR_Write(newsockfd, data_buf,DATA_BUF_SIZE);
- if (rv < 0) {
- fprintf(stderr,"Error - PR_Write failed: (%d, %d)\n",
- PR_GetError(), PR_GetOSError());
- PR_Close(newsockfd);
- return;
- }
- PR_ASSERT(rv == DATA_BUF_SIZE);
- DPRINTF(("Bytes written to client - %d\n",rv));
- PR_Close(newsockfd);
+ sockfd = sp->sp_fd;
+ if ((newsockfd = PR_Accept(sockfd, NULL,
+ PR_INTERVAL_NO_TIMEOUT)) == NULL) {
+ fprintf(stderr,"ERROR - PR_Accept failed: (%d,%d)\n",
+ PR_GetError(), PR_GetOSError());
+ return;
+ }
+ bytes_read = 0;
+ while (bytes_read != DATA_BUF_SIZE) {
+ rv = PR_Read(newsockfd, data_buf + bytes_read,
+ DATA_BUF_SIZE - bytes_read);
+ if (rv < 0) {
+ fprintf(stderr,"Error - PR_Read failed: (%d, %d)\n",
+ PR_GetError(), PR_GetOSError());
+ PR_Close(newsockfd);
+ return;
+ }
+ PR_ASSERT(rv != 0);
+ bytes_read += rv;
+ }
+ DPRINTF(("Bytes read from client - %d\n",bytes_read));
+ rv = PR_Write(newsockfd, data_buf,DATA_BUF_SIZE);
+ if (rv < 0) {
+ fprintf(stderr,"Error - PR_Write failed: (%d, %d)\n",
+ PR_GetError(), PR_GetOSError());
+ PR_Close(newsockfd);
+ return;
+ }
+ PR_ASSERT(rv == DATA_BUF_SIZE);
+ DPRINTF(("Bytes written to client - %d\n",rv));
+ PR_Close(newsockfd);
}
@@ -227,190 +232,193 @@ TCP_Server(void *arg)
static PRIntn
connection_success_test()
{
- PRFileDesc *sockfd = NULL, *conn_fd = NULL;
- PRNetAddr netaddr;
- PRInt32 i, rv;
+ PRFileDesc *sockfd = NULL, *conn_fd = NULL;
+ PRNetAddr netaddr;
+ PRInt32 i, rv;
PRPollDesc pd;
PRSocketOptionData optData;
- PRThread *thr = NULL;
- Server_Param sp;
- char send_buf[DATA_BUF_SIZE], recv_buf[DATA_BUF_SIZE];
+ PRThread *thr = NULL;
+ Server_Param sp;
+ char send_buf[DATA_BUF_SIZE], recv_buf[DATA_BUF_SIZE];
PRIntn default_case, n, bytes_read, bytes_sent;
PRIntn failed_already = 0;
- /*
- * Create a tcp socket
- */
- if ((sockfd = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr,"Error - PR_NewTCPSocket failed\n");
- failed_already=1;
- goto def_exit;
- }
- memset(&netaddr, 0 , sizeof(netaddr));
- netaddr.inet.family = PR_AF_INET;
- netaddr.inet.port = PR_htons(TCP_SERVER_PORT);
- netaddr.inet.ip = PR_htonl(PR_INADDR_ANY);
- /*
- * try a few times to bind server's address, if addresses are in
- * use
- */
- i = 0;
- while (PR_Bind(sockfd, &netaddr) < 0) {
- if (PR_GetError() == PR_ADDRESS_IN_USE_ERROR) {
- netaddr.inet.port += 2;
- if (i++ < SERVER_MAX_BIND_COUNT)
- continue;
- }
- fprintf(stderr,"ERROR - PR_Bind failed: (%d,%d)\n",
- PR_GetError(), PR_GetOSError());
- failed_already=1;
- goto def_exit;
- }
-
- if (PR_Listen(sockfd, 32) < 0) {
- fprintf(stderr,"ERROR - PR_Listen failed: (%d,%d)\n",
- PR_GetError(), PR_GetOSError());
- failed_already=1;
- goto def_exit;
- }
-
- if (PR_GetSockName(sockfd, &netaddr) < 0) {
- fprintf(stderr,"ERROR - PR_GetSockName failed: (%d,%d)\n",
- PR_GetError(), PR_GetOSError());
- failed_already=1;
- goto def_exit;
- }
- if ((conn_fd = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr,"Error - PR_NewTCPSocket failed\n");
- failed_already=1;
- goto def_exit;
- }
- optData.option = PR_SockOpt_Nonblocking;
- optData.value.non_blocking = PR_TRUE;
- PR_SetSocketOption(conn_fd, &optData);
- rv = PR_Connect(conn_fd, &netaddr, PR_INTERVAL_NO_TIMEOUT);
- if (rv == PR_FAILURE) {
- if (PR_GetError() == PR_IN_PROGRESS_ERROR) {
- DPRINTF(("Connect in progress\n"));
- } else {
- fprintf(stderr,"Error - PR_Connect failed: (%d, %d)\n",
- PR_GetError(), PR_GetOSError());
- failed_already=1;
- goto def_exit;
- }
- }
- /*
- * Now create a thread to accept a connection
- */
- sp.sp_fd = sockfd;
- thr = PR_CreateThread(PR_USER_THREAD, TCP_Server, (void *)&sp,
- PR_PRIORITY_NORMAL, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
- if (thr == NULL) {
- fprintf(stderr,"Error - PR_CreateThread failed: (%d,%d)\n",
- PR_GetError(), PR_GetOSError());
- failed_already=1;
- goto def_exit;
- }
- DPRINTF(("Created TCP_Server thread [0x%x]\n",thr));
- pd.fd = conn_fd;
- pd.in_flags = PR_POLL_WRITE | PR_POLL_EXCEPT;
- n = PR_Poll(&pd, 1, PR_INTERVAL_NO_TIMEOUT);
- if (n == -1) {
- fprintf(stderr,"Error - PR_Poll failed: (%d, %d)\n",
- PR_GetError(), PR_GetOSError());
- failed_already=1;
- goto def_exit;
- }
- if (PR_GetConnectStatus(&pd) == PR_SUCCESS) {
- PRInt32 rv;
-
- DPRINTF(("Connection successful\n"));
-
- /*
- * Write some data, read it back and check data integrity to
- * make sure the connection is good
- */
- pd.in_flags = PR_POLL_WRITE;
- bytes_sent = 0;
- memset(send_buf, 'a', DATA_BUF_SIZE);
- while (bytes_sent != DATA_BUF_SIZE) {
- rv = PR_Poll(&pd, 1, PR_INTERVAL_NO_TIMEOUT);
- if (rv < 0) {
- fprintf(stderr,"Error - PR_Poll failed: (%d, %d)\n",
- PR_GetError(), PR_GetOSError());
- failed_already=1;
- goto def_exit;
- }
- PR_ASSERT((rv == 1) && (pd.out_flags == PR_POLL_WRITE));
- rv = PR_Write(conn_fd, send_buf + bytes_sent,
- DATA_BUF_SIZE - bytes_sent);
- if (rv < 0) {
- fprintf(stderr,"Error - PR_Write failed: (%d, %d)\n",
- PR_GetError(), PR_GetOSError());
- failed_already=1;
- goto def_exit;
- }
- PR_ASSERT(rv > 0);
- bytes_sent += rv;
- }
- DPRINTF(("Bytes written to server - %d\n",bytes_sent));
- PR_Shutdown(conn_fd, PR_SHUTDOWN_SEND);
- pd.in_flags = PR_POLL_READ;
- bytes_read = 0;
- memset(recv_buf, 0, DATA_BUF_SIZE);
- while (bytes_read != DATA_BUF_SIZE) {
- rv = PR_Poll(&pd, 1, PR_INTERVAL_NO_TIMEOUT);
- if (rv < 0) {
- fprintf(stderr,"Error - PR_Poll failed: (%d, %d)\n",
- PR_GetError(), PR_GetOSError());
- failed_already=1;
- goto def_exit;
- }
- PR_ASSERT((rv == 1) && (pd.out_flags == PR_POLL_READ));
- rv = PR_Read(conn_fd, recv_buf + bytes_read ,
- DATA_BUF_SIZE - bytes_read);
- if (rv < 0) {
- fprintf(stderr,"Error - PR_Read failed: (%d, %d)\n",
- PR_GetError(), PR_GetOSError());
- failed_already=1;
- goto def_exit;
- }
- PR_ASSERT(rv != 0);
- bytes_read += rv;
- }
- DPRINTF(("Bytes read from server - %d\n",bytes_read));
- /*
- * verify the data read
- */
- if (memcmp(send_buf, recv_buf, DATA_BUF_SIZE) != 0) {
- fprintf(stderr,"ERROR - data corruption\n");
- failed_already=1;
- goto def_exit;
- }
- DPRINTF(("Data integrity verified\n"));
- } else {
- fprintf(stderr,"PR_GetConnectStatus: connect failed: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
- failed_already = 1;
- goto def_exit;
- }
+ /*
+ * Create a tcp socket
+ */
+ if ((sockfd = PR_NewTCPSocket()) == NULL) {
+ fprintf(stderr,"Error - PR_NewTCPSocket failed\n");
+ failed_already=1;
+ goto def_exit;
+ }
+ memset(&netaddr, 0, sizeof(netaddr));
+ netaddr.inet.family = PR_AF_INET;
+ netaddr.inet.port = PR_htons(TCP_SERVER_PORT);
+ netaddr.inet.ip = PR_htonl(PR_INADDR_ANY);
+ /*
+ * try a few times to bind server's address, if addresses are in
+ * use
+ */
+ i = 0;
+ while (PR_Bind(sockfd, &netaddr) < 0) {
+ if (PR_GetError() == PR_ADDRESS_IN_USE_ERROR) {
+ netaddr.inet.port += 2;
+ if (i++ < SERVER_MAX_BIND_COUNT) {
+ continue;
+ }
+ }
+ fprintf(stderr,"ERROR - PR_Bind failed: (%d,%d)\n",
+ PR_GetError(), PR_GetOSError());
+ failed_already=1;
+ goto def_exit;
+ }
+
+ if (PR_Listen(sockfd, 32) < 0) {
+ fprintf(stderr,"ERROR - PR_Listen failed: (%d,%d)\n",
+ PR_GetError(), PR_GetOSError());
+ failed_already=1;
+ goto def_exit;
+ }
+
+ if (PR_GetSockName(sockfd, &netaddr) < 0) {
+ fprintf(stderr,"ERROR - PR_GetSockName failed: (%d,%d)\n",
+ PR_GetError(), PR_GetOSError());
+ failed_already=1;
+ goto def_exit;
+ }
+ if ((conn_fd = PR_NewTCPSocket()) == NULL) {
+ fprintf(stderr,"Error - PR_NewTCPSocket failed\n");
+ failed_already=1;
+ goto def_exit;
+ }
+ optData.option = PR_SockOpt_Nonblocking;
+ optData.value.non_blocking = PR_TRUE;
+ PR_SetSocketOption(conn_fd, &optData);
+ rv = PR_Connect(conn_fd, &netaddr, PR_INTERVAL_NO_TIMEOUT);
+ if (rv == PR_FAILURE) {
+ if (PR_GetError() == PR_IN_PROGRESS_ERROR) {
+ DPRINTF(("Connect in progress\n"));
+ } else {
+ fprintf(stderr,"Error - PR_Connect failed: (%d, %d)\n",
+ PR_GetError(), PR_GetOSError());
+ failed_already=1;
+ goto def_exit;
+ }
+ }
+ /*
+ * Now create a thread to accept a connection
+ */
+ sp.sp_fd = sockfd;
+ thr = PR_CreateThread(PR_USER_THREAD, TCP_Server, (void *)&sp,
+ PR_PRIORITY_NORMAL, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
+ if (thr == NULL) {
+ fprintf(stderr,"Error - PR_CreateThread failed: (%d,%d)\n",
+ PR_GetError(), PR_GetOSError());
+ failed_already=1;
+ goto def_exit;
+ }
+ DPRINTF(("Created TCP_Server thread [0x%x]\n",thr));
+ pd.fd = conn_fd;
+ pd.in_flags = PR_POLL_WRITE | PR_POLL_EXCEPT;
+ n = PR_Poll(&pd, 1, PR_INTERVAL_NO_TIMEOUT);
+ if (n == -1) {
+ fprintf(stderr,"Error - PR_Poll failed: (%d, %d)\n",
+ PR_GetError(), PR_GetOSError());
+ failed_already=1;
+ goto def_exit;
+ }
+ if (PR_GetConnectStatus(&pd) == PR_SUCCESS) {
+ PRInt32 rv;
+
+ DPRINTF(("Connection successful\n"));
+
+ /*
+ * Write some data, read it back and check data integrity to
+ * make sure the connection is good
+ */
+ pd.in_flags = PR_POLL_WRITE;
+ bytes_sent = 0;
+ memset(send_buf, 'a', DATA_BUF_SIZE);
+ while (bytes_sent != DATA_BUF_SIZE) {
+ rv = PR_Poll(&pd, 1, PR_INTERVAL_NO_TIMEOUT);
+ if (rv < 0) {
+ fprintf(stderr,"Error - PR_Poll failed: (%d, %d)\n",
+ PR_GetError(), PR_GetOSError());
+ failed_already=1;
+ goto def_exit;
+ }
+ PR_ASSERT((rv == 1) && (pd.out_flags == PR_POLL_WRITE));
+ rv = PR_Write(conn_fd, send_buf + bytes_sent,
+ DATA_BUF_SIZE - bytes_sent);
+ if (rv < 0) {
+ fprintf(stderr,"Error - PR_Write failed: (%d, %d)\n",
+ PR_GetError(), PR_GetOSError());
+ failed_already=1;
+ goto def_exit;
+ }
+ PR_ASSERT(rv > 0);
+ bytes_sent += rv;
+ }
+ DPRINTF(("Bytes written to server - %d\n",bytes_sent));
+ PR_Shutdown(conn_fd, PR_SHUTDOWN_SEND);
+ pd.in_flags = PR_POLL_READ;
+ bytes_read = 0;
+ memset(recv_buf, 0, DATA_BUF_SIZE);
+ while (bytes_read != DATA_BUF_SIZE) {
+ rv = PR_Poll(&pd, 1, PR_INTERVAL_NO_TIMEOUT);
+ if (rv < 0) {
+ fprintf(stderr,"Error - PR_Poll failed: (%d, %d)\n",
+ PR_GetError(), PR_GetOSError());
+ failed_already=1;
+ goto def_exit;
+ }
+ PR_ASSERT((rv == 1) && (pd.out_flags == PR_POLL_READ));
+ rv = PR_Read(conn_fd, recv_buf + bytes_read,
+ DATA_BUF_SIZE - bytes_read);
+ if (rv < 0) {
+ fprintf(stderr,"Error - PR_Read failed: (%d, %d)\n",
+ PR_GetError(), PR_GetOSError());
+ failed_already=1;
+ goto def_exit;
+ }
+ PR_ASSERT(rv != 0);
+ bytes_read += rv;
+ }
+ DPRINTF(("Bytes read from server - %d\n",bytes_read));
+ /*
+ * verify the data read
+ */
+ if (memcmp(send_buf, recv_buf, DATA_BUF_SIZE) != 0) {
+ fprintf(stderr,"ERROR - data corruption\n");
+ failed_already=1;
+ goto def_exit;
+ }
+ DPRINTF(("Data integrity verified\n"));
+ } else {
+ fprintf(stderr,"PR_GetConnectStatus: connect failed: (%ld, %ld)\n",
+ PR_GetError(), PR_GetOSError());
+ failed_already = 1;
+ goto def_exit;
+ }
def_exit:
- if (thr) {
- PR_JoinThread(thr);
- thr = NULL;
- }
- if (sockfd) {
- PR_Close(sockfd);
- sockfd = NULL;
- }
- if (conn_fd) {
- PR_Close(conn_fd);
- conn_fd = NULL;
- }
- if (failed_already)
- return 1;
- else
- return 0;
+ if (thr) {
+ PR_JoinThread(thr);
+ thr = NULL;
+ }
+ if (sockfd) {
+ PR_Close(sockfd);
+ sockfd = NULL;
+ }
+ if (conn_fd) {
+ PR_Close(conn_fd);
+ conn_fd = NULL;
+ }
+ if (failed_already) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
}
@@ -420,101 +428,104 @@ def_exit:
static PRIntn
connection_failure_test()
{
- PRFileDesc *sockfd = NULL, *conn_fd = NULL;
- PRNetAddr netaddr;
- PRInt32 i, rv;
+ PRFileDesc *sockfd = NULL, *conn_fd = NULL;
+ PRNetAddr netaddr;
+ PRInt32 i, rv;
PRPollDesc pd;
PRSocketOptionData optData;
PRIntn n, failed_already = 0;
- /*
- * Create a tcp socket
- */
- if ((sockfd = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr,"Error - PR_NewTCPSocket failed\n");
- failed_already=1;
- goto def_exit;
- }
- memset(&netaddr, 0 , sizeof(netaddr));
- netaddr.inet.family = PR_AF_INET;
- netaddr.inet.port = PR_htons(TCP_SERVER_PORT);
- netaddr.inet.ip = PR_htonl(PR_INADDR_ANY);
- /*
- * try a few times to bind server's address, if addresses are in
- * use
- */
- i = 0;
- while (PR_Bind(sockfd, &netaddr) < 0) {
- if (PR_GetError() == PR_ADDRESS_IN_USE_ERROR) {
- netaddr.inet.port += 2;
- if (i++ < SERVER_MAX_BIND_COUNT)
- continue;
- }
- fprintf(stderr,"ERROR - PR_Bind failed: (%d,%d)\n",
- PR_GetError(), PR_GetOSError());
- failed_already=1;
- goto def_exit;
- }
-
- if (PR_GetSockName(sockfd, &netaddr) < 0) {
- fprintf(stderr,"ERROR - PR_GetSockName failed: (%d,%d)\n",
- PR_GetError(), PR_GetOSError());
- failed_already=1;
- goto def_exit;
- }
+ /*
+ * Create a tcp socket
+ */
+ if ((sockfd = PR_NewTCPSocket()) == NULL) {
+ fprintf(stderr,"Error - PR_NewTCPSocket failed\n");
+ failed_already=1;
+ goto def_exit;
+ }
+ memset(&netaddr, 0, sizeof(netaddr));
+ netaddr.inet.family = PR_AF_INET;
+ netaddr.inet.port = PR_htons(TCP_SERVER_PORT);
+ netaddr.inet.ip = PR_htonl(PR_INADDR_ANY);
+ /*
+ * try a few times to bind server's address, if addresses are in
+ * use
+ */
+ i = 0;
+ while (PR_Bind(sockfd, &netaddr) < 0) {
+ if (PR_GetError() == PR_ADDRESS_IN_USE_ERROR) {
+ netaddr.inet.port += 2;
+ if (i++ < SERVER_MAX_BIND_COUNT) {
+ continue;
+ }
+ }
+ fprintf(stderr,"ERROR - PR_Bind failed: (%d,%d)\n",
+ PR_GetError(), PR_GetOSError());
+ failed_already=1;
+ goto def_exit;
+ }
+
+ if (PR_GetSockName(sockfd, &netaddr) < 0) {
+ fprintf(stderr,"ERROR - PR_GetSockName failed: (%d,%d)\n",
+ PR_GetError(), PR_GetOSError());
+ failed_already=1;
+ goto def_exit;
+ }
#ifdef AIX
- /*
- * On AIX, set to unused/reserved port
- */
- netaddr.inet.port = PR_htons(TCP_UNUSED_PORT);
+ /*
+ * On AIX, set to unused/reserved port
+ */
+ netaddr.inet.port = PR_htons(TCP_UNUSED_PORT);
#endif
- if ((conn_fd = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr,"Error - PR_NewTCPSocket failed\n");
- failed_already=1;
- goto def_exit;
- }
- optData.option = PR_SockOpt_Nonblocking;
- optData.value.non_blocking = PR_TRUE;
- PR_SetSocketOption(conn_fd, &optData);
- rv = PR_Connect(conn_fd, &netaddr, PR_INTERVAL_NO_TIMEOUT);
- if (rv == PR_FAILURE) {
- DPRINTF(("PR_Connect to a non-listen port failed: (%d, %d)\n",
- PR_GetError(), PR_GetOSError()));
- } else {
- PR_ASSERT(rv == PR_SUCCESS);
- fprintf(stderr,"Error - PR_Connect succeeded, expected to fail\n");
- failed_already=1;
- goto def_exit;
- }
- pd.fd = conn_fd;
- pd.in_flags = PR_POLL_WRITE | PR_POLL_EXCEPT;
- n = PR_Poll(&pd, 1, PR_INTERVAL_NO_TIMEOUT);
- if (n == -1) {
- fprintf(stderr,"Error - PR_Poll failed: (%d, %d)\n",
- PR_GetError(), PR_GetOSError());
- failed_already=1;
- goto def_exit;
- }
- if (PR_GetConnectStatus(&pd) == PR_SUCCESS) {
- PRInt32 rv;
- fprintf(stderr,"PR_GetConnectStatus succeeded, expected to fail\n");
- failed_already = 1;
- goto def_exit;
- }
- rv = PR_GetError();
- DPRINTF(("Connection failed, successfully with PR_Error %d\n",rv));
+ if ((conn_fd = PR_NewTCPSocket()) == NULL) {
+ fprintf(stderr,"Error - PR_NewTCPSocket failed\n");
+ failed_already=1;
+ goto def_exit;
+ }
+ optData.option = PR_SockOpt_Nonblocking;
+ optData.value.non_blocking = PR_TRUE;
+ PR_SetSocketOption(conn_fd, &optData);
+ rv = PR_Connect(conn_fd, &netaddr, PR_INTERVAL_NO_TIMEOUT);
+ if (rv == PR_FAILURE) {
+ DPRINTF(("PR_Connect to a non-listen port failed: (%d, %d)\n",
+ PR_GetError(), PR_GetOSError()));
+ } else {
+ PR_ASSERT(rv == PR_SUCCESS);
+ fprintf(stderr,"Error - PR_Connect succeeded, expected to fail\n");
+ failed_already=1;
+ goto def_exit;
+ }
+ pd.fd = conn_fd;
+ pd.in_flags = PR_POLL_WRITE | PR_POLL_EXCEPT;
+ n = PR_Poll(&pd, 1, PR_INTERVAL_NO_TIMEOUT);
+ if (n == -1) {
+ fprintf(stderr,"Error - PR_Poll failed: (%d, %d)\n",
+ PR_GetError(), PR_GetOSError());
+ failed_already=1;
+ goto def_exit;
+ }
+ if (PR_GetConnectStatus(&pd) == PR_SUCCESS) {
+ PRInt32 rv;
+ fprintf(stderr,"PR_GetConnectStatus succeeded, expected to fail\n");
+ failed_already = 1;
+ goto def_exit;
+ }
+ rv = PR_GetError();
+ DPRINTF(("Connection failed, successfully with PR_Error %d\n",rv));
def_exit:
- if (sockfd) {
- PR_Close(sockfd);
- sockfd = NULL;
- }
- if (conn_fd) {
- PR_Close(conn_fd);
- conn_fd = NULL;
- }
- if (failed_already)
- return 1;
- else
- return 0;
+ if (sockfd) {
+ PR_Close(sockfd);
+ sockfd = NULL;
+ }
+ if (conn_fd) {
+ PR_Close(conn_fd);
+ conn_fd = NULL;
+ }
+ if (failed_already) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
}
diff --git a/pr/tests/nblayer.c b/pr/tests/nblayer.c
index 1b4064bd..c9e6bf24 100644
--- a/pr/tests/nblayer.c
+++ b/pr/tests/nblayer.c
@@ -62,16 +62,18 @@ static PRFileDesc *PushLayer(PRFileDesc *stack)
layer->secret = PR_NEWZAP(PRFilePrivate);
rv = PR_PushIOLayer(stack, PR_GetLayersIdentity(stack), layer);
PR_ASSERT(PR_SUCCESS == rv);
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(logFile, "Pushed layer(0x%x) onto stack(0x%x)\n", layer, stack);
+ }
return stack;
} /* PushLayer */
static PRFileDesc *PopLayer(PRFileDesc *stack)
{
PRFileDesc *popped = PR_PopIOLayer(stack, identity);
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(logFile, "Popped layer(0x%x) from stack(0x%x)\n", popped, stack);
+ }
PR_DELETE(popped->secret);
popped->dtor(popped);
return stack;
@@ -94,8 +96,9 @@ static void PR_CALLBACK Client(void *arg)
rv = PR_Connect(stack, &server_address, PR_INTERVAL_NO_TIMEOUT);
if ((PR_FAILURE == rv) && (PR_IN_PROGRESS_ERROR == PR_GetError()))
{
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(logFile, "Client connect 'in progress'\n");
+ }
do
{
polldesc.fd = stack;
@@ -103,26 +106,33 @@ static void PR_CALLBACK Client(void *arg)
polldesc.in_flags = PR_POLL_WRITE | PR_POLL_EXCEPT;
ready = PR_Poll(&polldesc, 1, PR_INTERVAL_NO_TIMEOUT);
if ((1 != ready) /* if not 1, then we're dead */
- || (0 == (polldesc.in_flags & polldesc.out_flags)))
- { PR_NOT_REACHED("Whoa!"); break; }
+ || (0 == (polldesc.in_flags & polldesc.out_flags)))
+ {
+ PR_NOT_REACHED("Whoa!");
+ break;
+ }
if (verbosity > quiet)
PR_fprintf(
logFile, "Client connect 'in progress' [0x%x]\n",
polldesc.out_flags);
rv = PR_GetConnectStatus(&polldesc);
if ((PR_FAILURE == rv)
- && (PR_IN_PROGRESS_ERROR != PR_GetError())) break;
+ && (PR_IN_PROGRESS_ERROR != PR_GetError())) {
+ break;
+ }
} while (PR_FAILURE == rv);
}
PR_ASSERT(PR_SUCCESS == rv);
- if (verbosity > chatty)
+ if (verbosity > chatty) {
PR_fprintf(logFile, "Client created connection\n");
+ }
for (mits = 0; mits < minor_iterations; ++mits)
{
bytes_sent = 0;
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(logFile, "Client sending %d bytes\n", sizeof(buffer));
+ }
do
{
if (verbosity > chatty)
@@ -130,11 +140,14 @@ static void PR_CALLBACK Client(void *arg)
logFile, "Client sending %d bytes\n",
sizeof(buffer) - bytes_sent);
ready = PR_Send(
- stack, buffer + bytes_sent, sizeof(buffer) - bytes_sent,
- empty_flags, PR_INTERVAL_NO_TIMEOUT);
- if (verbosity > chatty)
+ stack, buffer + bytes_sent, sizeof(buffer) - bytes_sent,
+ empty_flags, PR_INTERVAL_NO_TIMEOUT);
+ if (verbosity > chatty) {
PR_fprintf(logFile, "Client send status [%d]\n", ready);
- if (0 < ready) bytes_sent += ready;
+ }
+ if (0 < ready) {
+ bytes_sent += ready;
+ }
else if ((-1 == ready) && (PR_WOULD_BLOCK_ERROR == PR_GetError()))
{
polldesc.fd = stack;
@@ -142,10 +155,15 @@ static void PR_CALLBACK Client(void *arg)
polldesc.in_flags = PR_POLL_WRITE;
ready = PR_Poll(&polldesc, 1, PR_INTERVAL_NO_TIMEOUT);
if ((1 != ready) /* if not 1, then we're dead */
- || (0 == (polldesc.in_flags & polldesc.out_flags)))
- { PR_NOT_REACHED("Whoa!"); break; }
+ || (0 == (polldesc.in_flags & polldesc.out_flags)))
+ {
+ PR_NOT_REACHED("Whoa!");
+ break;
+ }
+ }
+ else {
+ break;
}
- else break;
} while (bytes_sent < sizeof(buffer));
PR_ASSERT(sizeof(buffer) == bytes_sent);
@@ -157,12 +175,14 @@ static void PR_CALLBACK Client(void *arg)
logFile, "Client receiving %d bytes\n",
bytes_sent - bytes_read);
ready = PR_Recv(
- stack, buffer + bytes_read, bytes_sent - bytes_read,
- empty_flags, PR_INTERVAL_NO_TIMEOUT);
+ stack, buffer + bytes_read, bytes_sent - bytes_read,
+ empty_flags, PR_INTERVAL_NO_TIMEOUT);
if (verbosity > chatty)
PR_fprintf(
logFile, "Client receive status [%d]\n", ready);
- if (0 < ready) bytes_read += ready;
+ if (0 < ready) {
+ bytes_read += ready;
+ }
else if ((-1 == ready) && (PR_WOULD_BLOCK_ERROR == PR_GetError()))
{
polldesc.fd = stack;
@@ -170,18 +190,25 @@ static void PR_CALLBACK Client(void *arg)
polldesc.in_flags = PR_POLL_READ;
ready = PR_Poll(&polldesc, 1, PR_INTERVAL_NO_TIMEOUT);
if ((1 != ready) /* if not 1, then we're dead */
- || (0 == (polldesc.in_flags & polldesc.out_flags)))
- { PR_NOT_REACHED("Whoa!"); break; }
+ || (0 == (polldesc.in_flags & polldesc.out_flags)))
+ {
+ PR_NOT_REACHED("Whoa!");
+ break;
+ }
+ }
+ else {
+ break;
}
- else break;
} while (bytes_read < bytes_sent);
- if (verbosity > chatty)
+ if (verbosity > chatty) {
PR_fprintf(logFile, "Client received %d bytes\n", bytes_read);
+ }
PR_ASSERT(bytes_read == bytes_sent);
}
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(logFile, "Client shutting down stack\n");
+ }
rv = PR_Shutdown(stack, PR_SHUTDOWN_BOTH); PR_ASSERT(PR_SUCCESS == rv);
} /* Client */
@@ -200,11 +227,13 @@ static void PR_CALLBACK Server(void *arg)
do
{
- if (verbosity > chatty)
+ if (verbosity > chatty) {
PR_fprintf(logFile, "Server accepting connection\n");
+ }
service = PR_Accept(stack, &client_address, PR_INTERVAL_NO_TIMEOUT);
- if (verbosity > chatty)
+ if (verbosity > chatty) {
PR_fprintf(logFile, "Server accept status [0x%p]\n", service);
+ }
if ((NULL == service) && (PR_WOULD_BLOCK_ERROR == PR_GetError()))
{
polldesc.fd = stack;
@@ -212,14 +241,18 @@ static void PR_CALLBACK Server(void *arg)
polldesc.in_flags = PR_POLL_READ | PR_POLL_EXCEPT;
ready = PR_Poll(&polldesc, 1, PR_INTERVAL_NO_TIMEOUT);
if ((1 != ready) /* if not 1, then we're dead */
- || (0 == (polldesc.in_flags & polldesc.out_flags)))
- { PR_NOT_REACHED("Whoa!"); break; }
+ || (0 == (polldesc.in_flags & polldesc.out_flags)))
+ {
+ PR_NOT_REACHED("Whoa!");
+ break;
+ }
}
} while (NULL == service);
PR_ASSERT(NULL != service);
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(logFile, "Server accepting connection\n");
+ }
do
{
@@ -231,11 +264,14 @@ static void PR_CALLBACK Server(void *arg)
logFile, "Server receiving %d bytes\n",
sizeof(buffer) - bytes_read);
ready = PR_Recv(
- service, buffer + bytes_read, sizeof(buffer) - bytes_read,
- empty_flags, PR_INTERVAL_NO_TIMEOUT);
- if (verbosity > chatty)
+ service, buffer + bytes_read, sizeof(buffer) - bytes_read,
+ empty_flags, PR_INTERVAL_NO_TIMEOUT);
+ if (verbosity > chatty) {
PR_fprintf(logFile, "Server receive status [%d]\n", ready);
- if (0 < ready) bytes_read += ready;
+ }
+ if (0 < ready) {
+ bytes_read += ready;
+ }
else if ((-1 == ready) && (PR_WOULD_BLOCK_ERROR == PR_GetError()))
{
polldesc.fd = service;
@@ -243,24 +279,30 @@ static void PR_CALLBACK Server(void *arg)
polldesc.in_flags = PR_POLL_READ;
ready = PR_Poll(&polldesc, 1, PR_INTERVAL_NO_TIMEOUT);
if ((1 != ready) /* if not 1, then we're dead */
- || (0 == (polldesc.in_flags & polldesc.out_flags)))
- { PR_NOT_REACHED("Whoa!"); break; }
+ || (0 == (polldesc.in_flags & polldesc.out_flags)))
+ {
+ PR_NOT_REACHED("Whoa!");
+ break;
+ }
+ }
+ else {
+ break;
}
- else break;
} while (bytes_read < sizeof(buffer));
if (0 != bytes_read)
{
- if (verbosity > chatty)
+ if (verbosity > chatty) {
PR_fprintf(logFile, "Server received %d bytes\n", bytes_read);
+ }
PR_ASSERT(bytes_read > 0);
bytes_sent = 0;
do
{
ready = PR_Send(
- service, buffer + bytes_sent, bytes_read - bytes_sent,
- empty_flags, PR_INTERVAL_NO_TIMEOUT);
+ service, buffer + bytes_sent, bytes_read - bytes_sent,
+ empty_flags, PR_INTERVAL_NO_TIMEOUT);
if (0 < ready)
{
bytes_sent += ready;
@@ -272,19 +314,26 @@ static void PR_CALLBACK Server(void *arg)
polldesc.in_flags = PR_POLL_WRITE;
ready = PR_Poll(&polldesc, 1, PR_INTERVAL_NO_TIMEOUT);
if ((1 != ready) /* if not 1, then we're dead */
- || (0 == (polldesc.in_flags & polldesc.out_flags)))
- { PR_NOT_REACHED("Whoa!"); break; }
+ || (0 == (polldesc.in_flags & polldesc.out_flags)))
+ {
+ PR_NOT_REACHED("Whoa!");
+ break;
+ }
+ }
+ else {
+ break;
}
- else break;
} while (bytes_sent < bytes_read);
PR_ASSERT(bytes_read == bytes_sent);
- if (verbosity > chatty)
+ if (verbosity > chatty) {
PR_fprintf(logFile, "Server sent %d bytes\n", bytes_sent);
+ }
}
} while (0 != bytes_read);
- if (verbosity > quiet)
+ if (verbosity > quiet) {
PR_fprintf(logFile, "Server shutting down stack\n");
+ }
rv = PR_Shutdown(service, PR_SHUTDOWN_BOTH); PR_ASSERT(PR_SUCCESS == rv);
rv = PR_Close(service); PR_ASSERT(PR_SUCCESS == rv);
@@ -329,7 +378,9 @@ static PRInt16 PR_CALLBACK MyPoll(
default: break;
}
}
- else PR_NOT_REACHED("How'd I get here?");
+ else {
+ PR_NOT_REACHED("How'd I get here?");
+ }
new_flags = (fd->lower->methods->poll)(fd->lower, my_flags, out_flags);
if (verbosity > chatty)
PR_fprintf(
@@ -393,42 +444,58 @@ static PRInt32 PR_CALLBACK MyRecv(
{
switch (mine->rcvstate)
{
- case rcv_get_debit:
- b = (char*)&mine->rcvreq;
- mine->rcvreq = amount;
- rv = lo->methods->recv(
- lo, b + mine->rcvinprogress,
- sizeof(mine->rcvreq) - mine->rcvinprogress, flags, timeout);
- if (0 == rv) goto closed;
- if ((-1 == rv) && (PR_WOULD_BLOCK_ERROR == PR_GetError())) break;
- mine->rcvinprogress += rv; /* accumulate the read */
- if (mine->rcvinprogress < sizeof(mine->rcvreq)) break; /* loop */
- mine->rcvstate = rcv_send_credit;
- mine->rcvinprogress = 0;
- case rcv_send_credit:
- b = (char*)&mine->rcvreq;
- rv = lo->methods->send(
- lo, b + mine->rcvinprogress,
- sizeof(mine->rcvreq) - mine->rcvinprogress, flags, timeout);
- if ((-1 == rv) && (PR_WOULD_BLOCK_ERROR == PR_GetError())) break;
- mine->rcvinprogress += rv; /* accumulate the read */
- if (mine->rcvinprogress < sizeof(mine->rcvreq)) break; /* loop */
- mine->rcvstate = rcv_data;
- mine->rcvinprogress = 0;
- case rcv_data:
- b = (char*)buf;
- rv = lo->methods->recv(
- lo, b + mine->rcvinprogress,
- mine->rcvreq - mine->rcvinprogress, flags, timeout);
- if (0 == rv) goto closed;
- if ((-1 == rv) && (PR_WOULD_BLOCK_ERROR == PR_GetError())) break;
- mine->rcvinprogress += rv; /* accumulate the read */
- if (mine->rcvinprogress < amount) break; /* loop */
- mine->rcvstate = rcv_get_debit;
- mine->rcvinprogress = 0;
- return mine->rcvreq; /* << -- that's it! */
- default:
- break;
+ case rcv_get_debit:
+ b = (char*)&mine->rcvreq;
+ mine->rcvreq = amount;
+ rv = lo->methods->recv(
+ lo, b + mine->rcvinprogress,
+ sizeof(mine->rcvreq) - mine->rcvinprogress, flags, timeout);
+ if (0 == rv) {
+ goto closed;
+ }
+ if ((-1 == rv) && (PR_WOULD_BLOCK_ERROR == PR_GetError())) {
+ break;
+ }
+ mine->rcvinprogress += rv; /* accumulate the read */
+ if (mine->rcvinprogress < sizeof(mine->rcvreq)) {
+ break; /* loop */
+ }
+ mine->rcvstate = rcv_send_credit;
+ mine->rcvinprogress = 0;
+ case rcv_send_credit:
+ b = (char*)&mine->rcvreq;
+ rv = lo->methods->send(
+ lo, b + mine->rcvinprogress,
+ sizeof(mine->rcvreq) - mine->rcvinprogress, flags, timeout);
+ if ((-1 == rv) && (PR_WOULD_BLOCK_ERROR == PR_GetError())) {
+ break;
+ }
+ mine->rcvinprogress += rv; /* accumulate the read */
+ if (mine->rcvinprogress < sizeof(mine->rcvreq)) {
+ break; /* loop */
+ }
+ mine->rcvstate = rcv_data;
+ mine->rcvinprogress = 0;
+ case rcv_data:
+ b = (char*)buf;
+ rv = lo->methods->recv(
+ lo, b + mine->rcvinprogress,
+ mine->rcvreq - mine->rcvinprogress, flags, timeout);
+ if (0 == rv) {
+ goto closed;
+ }
+ if ((-1 == rv) && (PR_WOULD_BLOCK_ERROR == PR_GetError())) {
+ break;
+ }
+ mine->rcvinprogress += rv; /* accumulate the read */
+ if (mine->rcvinprogress < amount) {
+ break; /* loop */
+ }
+ mine->rcvstate = rcv_get_debit;
+ mine->rcvinprogress = 0;
+ return mine->rcvreq; /* << -- that's it! */
+ default:
+ break;
}
} while (-1 != rv);
return rv;
@@ -451,40 +518,52 @@ static PRInt32 PR_CALLBACK MySend(
{
switch (mine->xmtstate)
{
- case xmt_send_debit:
- b = (char*)&mine->xmtreq;
- mine->xmtreq = amount;
- rv = lo->methods->send(
- lo, b - mine->xmtinprogress,
- sizeof(mine->xmtreq) - mine->xmtinprogress, flags, timeout);
- if ((-1 == rv) && (PR_WOULD_BLOCK_ERROR == PR_GetError())) break;
- mine->xmtinprogress += rv;
- if (mine->xmtinprogress < sizeof(mine->xmtreq)) break;
- mine->xmtstate = xmt_recv_credit;
- mine->xmtinprogress = 0;
- case xmt_recv_credit:
- b = (char*)&mine->xmtreq;
- rv = lo->methods->recv(
- lo, b + mine->xmtinprogress,
- sizeof(mine->xmtreq) - mine->xmtinprogress, flags, timeout);
- if ((-1 == rv) && (PR_WOULD_BLOCK_ERROR == PR_GetError())) break;
- mine->xmtinprogress += rv;
- if (mine->xmtinprogress < sizeof(mine->xmtreq)) break;
- mine->xmtstate = xmt_data;
- mine->xmtinprogress = 0;
- case xmt_data:
- b = (char*)buf;
- rv = lo->methods->send(
- lo, b + mine->xmtinprogress,
- mine->xmtreq - mine->xmtinprogress, flags, timeout);
- if ((-1 == rv) && (PR_WOULD_BLOCK_ERROR == PR_GetError())) break;
- mine->xmtinprogress += rv;
- if (mine->xmtinprogress < amount) break;
- mine->xmtstate = xmt_send_debit;
- mine->xmtinprogress = 0;
- return mine->xmtreq; /* <<-- That's the one! */
- default:
- break;
+ case xmt_send_debit:
+ b = (char*)&mine->xmtreq;
+ mine->xmtreq = amount;
+ rv = lo->methods->send(
+ lo, b - mine->xmtinprogress,
+ sizeof(mine->xmtreq) - mine->xmtinprogress, flags, timeout);
+ if ((-1 == rv) && (PR_WOULD_BLOCK_ERROR == PR_GetError())) {
+ break;
+ }
+ mine->xmtinprogress += rv;
+ if (mine->xmtinprogress < sizeof(mine->xmtreq)) {
+ break;
+ }
+ mine->xmtstate = xmt_recv_credit;
+ mine->xmtinprogress = 0;
+ case xmt_recv_credit:
+ b = (char*)&mine->xmtreq;
+ rv = lo->methods->recv(
+ lo, b + mine->xmtinprogress,
+ sizeof(mine->xmtreq) - mine->xmtinprogress, flags, timeout);
+ if ((-1 == rv) && (PR_WOULD_BLOCK_ERROR == PR_GetError())) {
+ break;
+ }
+ mine->xmtinprogress += rv;
+ if (mine->xmtinprogress < sizeof(mine->xmtreq)) {
+ break;
+ }
+ mine->xmtstate = xmt_data;
+ mine->xmtinprogress = 0;
+ case xmt_data:
+ b = (char*)buf;
+ rv = lo->methods->send(
+ lo, b + mine->xmtinprogress,
+ mine->xmtreq - mine->xmtinprogress, flags, timeout);
+ if ((-1 == rv) && (PR_WOULD_BLOCK_ERROR == PR_GetError())) {
+ break;
+ }
+ mine->xmtinprogress += rv;
+ if (mine->xmtinprogress < amount) {
+ break;
+ }
+ mine->xmtstate = xmt_send_debit;
+ mine->xmtinprogress = 0;
+ return mine->xmtreq; /* <<-- That's the one! */
+ default:
+ break;
}
} while (-1 != rv);
return rv;
@@ -493,8 +572,12 @@ static PRInt32 PR_CALLBACK MySend(
static Verbosity ChangeVerbosity(Verbosity verbosity, PRIntn delta)
{
PRIntn verbage = (PRIntn)verbosity + delta;
- if (verbage < (PRIntn)silent) verbage = (PRIntn)silent;
- else if (verbage > (PRIntn)noisy) verbage = (PRIntn)noisy;
+ if (verbage < (PRIntn)silent) {
+ verbage = (PRIntn)silent;
+ }
+ else if (verbage > (PRIntn)noisy) {
+ verbage = (PRIntn)noisy;
+ }
return (Verbosity)verbage;
} /* ChangeVerbosity */
@@ -512,34 +595,38 @@ int main(int argc, char **argv)
PLOptState *opt = PL_CreateOptState(argc, argv, "dqGC:c:p:");
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:
- server_name = opt->value;
- break;
- case 'd': /* debug mode */
- if (verbosity < noisy)
- verbosity = ChangeVerbosity(verbosity, 1);
- break;
- case 'q': /* debug mode */
- if (verbosity > silent)
- verbosity = ChangeVerbosity(verbosity, -1);
- break;
- case 'G': /* use global threads */
- thread_scope = PR_GLOBAL_THREAD;
- break;
- case 'C': /* number of threads waiting */
- major_iterations = atoi(opt->value);
- break;
- case 'c': /* number of client threads */
- minor_iterations = atoi(opt->value);
- break;
- case 'p': /* default port */
- default_port = atoi(opt->value);
- break;
- default:
- break;
+ case 0:
+ server_name = opt->value;
+ break;
+ case 'd': /* debug mode */
+ if (verbosity < noisy) {
+ verbosity = ChangeVerbosity(verbosity, 1);
+ }
+ break;
+ case 'q': /* debug mode */
+ if (verbosity > silent) {
+ verbosity = ChangeVerbosity(verbosity, -1);
+ }
+ break;
+ case 'G': /* use global threads */
+ thread_scope = PR_GLOBAL_THREAD;
+ break;
+ case 'C': /* number of threads waiting */
+ major_iterations = atoi(opt->value);
+ break;
+ case 'c': /* number of client threads */
+ minor_iterations = atoi(opt->value);
+ break;
+ case 'p': /* default port */
+ default_port = atoi(opt->value);
+ break;
+ default:
+ break;
}
}
PL_DestroyOptState(opt);
@@ -563,13 +650,13 @@ int main(int argc, char **argv)
if (NULL == server_name)
rv = PR_InitializeNetAddr(
- PR_IpAddrLoopback, default_port, &server_address);
+ PR_IpAddrLoopback, default_port, &server_address);
else
{
rv = PR_StringToNetAddr(server_name, &server_address);
PR_ASSERT(PR_SUCCESS == rv);
rv = PR_InitializeNetAddr(
- PR_IpAddrNull, default_port, &server_address);
+ PR_IpAddrNull, default_port, &server_address);
}
PR_ASSERT(PR_SUCCESS == rv);
@@ -582,8 +669,9 @@ int main(int argc, char **argv)
while (major_iterations-- > 0)
{
- if (verbosity > silent)
+ if (verbosity > silent) {
PR_fprintf(logFile, "Beginning non-layered test\n");
+ }
client = PR_NewTCPSocket(); PR_ASSERT(NULL != client);
service = PR_NewTCPSocket(); PR_ASSERT(NULL != service);
@@ -603,15 +691,15 @@ int main(int argc, char **argv)
rv = PR_Listen(service, 10); PR_ASSERT(PR_SUCCESS == rv);
server_thread = PR_CreateThread(
- PR_USER_THREAD, Server, service,
- PR_PRIORITY_HIGH, thread_scope,
- PR_JOINABLE_THREAD, 16 * 1024);
+ PR_USER_THREAD, Server, service,
+ PR_PRIORITY_HIGH, thread_scope,
+ PR_JOINABLE_THREAD, 16 * 1024);
PR_ASSERT(NULL != server_thread);
client_thread = PR_CreateThread(
- PR_USER_THREAD, Client, client,
- PR_PRIORITY_NORMAL, thread_scope,
- PR_JOINABLE_THREAD, 16 * 1024);
+ PR_USER_THREAD, Client, client,
+ PR_PRIORITY_NORMAL, thread_scope,
+ PR_JOINABLE_THREAD, 16 * 1024);
PR_ASSERT(NULL != client_thread);
rv = PR_JoinThread(client_thread);
@@ -621,12 +709,14 @@ int main(int argc, char **argv)
rv = PR_Close(client); PR_ASSERT(PR_SUCCESS == rv);
rv = PR_Close(service); PR_ASSERT(PR_SUCCESS == rv);
- if (verbosity > silent)
+ if (verbosity > silent) {
PR_fprintf(logFile, "Ending non-layered test\n");
+ }
/* with layering */
- if (verbosity > silent)
+ if (verbosity > silent) {
PR_fprintf(logFile, "Beginning layered test\n");
+ }
client = PR_NewTCPSocket(); PR_ASSERT(NULL != client);
service = PR_NewTCPSocket(); PR_ASSERT(NULL != service);
@@ -648,15 +738,15 @@ int main(int argc, char **argv)
rv = PR_Listen(service, 10); PR_ASSERT(PR_SUCCESS == rv);
server_thread = PR_CreateThread(
- PR_USER_THREAD, Server, service,
- PR_PRIORITY_HIGH, thread_scope,
- PR_JOINABLE_THREAD, 16 * 1024);
+ PR_USER_THREAD, Server, service,
+ PR_PRIORITY_HIGH, thread_scope,
+ PR_JOINABLE_THREAD, 16 * 1024);
PR_ASSERT(NULL != server_thread);
client_thread = PR_CreateThread(
- PR_USER_THREAD, Client, client,
- PR_PRIORITY_NORMAL, thread_scope,
- PR_JOINABLE_THREAD, 16 * 1024);
+ PR_USER_THREAD, Client, client,
+ PR_PRIORITY_NORMAL, thread_scope,
+ PR_JOINABLE_THREAD, 16 * 1024);
PR_ASSERT(NULL != client_thread);
rv = PR_JoinThread(client_thread);
@@ -666,8 +756,9 @@ int main(int argc, char **argv)
rv = PR_Close(PopLayer(client)); PR_ASSERT(PR_SUCCESS == rv);
rv = PR_Close(PopLayer(service)); PR_ASSERT(PR_SUCCESS == rv);
- if (verbosity > silent)
+ if (verbosity > silent) {
PR_fprintf(logFile, "Ending layered test\n");
+ }
}
return 0;
} /* main */
diff --git a/pr/tests/nonblock.c b/pr/tests/nonblock.c
index e9d19d18..f24ffb02 100644
--- a/pr/tests/nonblock.c
+++ b/pr/tests/nonblock.c
@@ -64,13 +64,13 @@ clientThreadFunc(void *arg)
retVal = PR_Connect(sock, &addr, PR_INTERVAL_NO_TIMEOUT);
if (retVal == PR_FAILURE && PR_GetError() == PR_IN_PROGRESS_ERROR) {
#if !defined(USE_PR_SELECT)
- PRPollDesc pd;
- PRInt32 n;
- fprintf(stderr, "connect: EWOULDBLOCK, good\n");
- pd.fd = sock;
- pd.in_flags = PR_POLL_WRITE;
- n = PR_Poll(&pd, 1, PR_INTERVAL_NO_TIMEOUT);
- PR_ASSERT(n == 1);
+ PRPollDesc pd;
+ PRInt32 n;
+ fprintf(stderr, "connect: EWOULDBLOCK, good\n");
+ pd.fd = sock;
+ pd.in_flags = PR_POLL_WRITE;
+ n = PR_Poll(&pd, 1, PR_INTERVAL_NO_TIMEOUT);
+ PR_ASSERT(n == 1);
PR_ASSERT(pd.out_flags == PR_POLL_WRITE);
#else
PR_fd_set writeSet;
@@ -89,17 +89,17 @@ clientThreadFunc(void *arg)
/* time 4, 7, 11, etc. */
for (i = 0; i < NUMBER_ROUNDS; i++) {
PR_Sleep(3 * unitTime);
- nBytes = PR_Write(sock, buf, sizeof(buf));
- if (nBytes == -1) {
- if (PR_GetError() == PR_WOULD_BLOCK_ERROR) {
- fprintf(stderr, "write: EWOULDBLOCK\n");
- exit(1);
+ nBytes = PR_Write(sock, buf, sizeof(buf));
+ if (nBytes == -1) {
+ if (PR_GetError() == PR_WOULD_BLOCK_ERROR) {
+ fprintf(stderr, "write: EWOULDBLOCK\n");
+ exit(1);
} else {
- fprintf(stderr, "write: failed\n");
+ fprintf(stderr, "write: failed\n");
}
- }
- printf("client sent %d bytes\n", nBytes);
- fflush(stdout);
+ }
+ printf("client sent %d bytes\n", nBytes);
+ fflush(stdout);
}
PR_Close(sock);
@@ -119,38 +119,38 @@ static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
/* Create a listening socket */
if ((listenSock = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr, "Can't create a new TCP socket\n");
- exit(1);
+ fprintf(stderr, "Can't create a new TCP socket\n");
+ exit(1);
}
addr.inet.family = PR_AF_INET;
addr.inet.ip = PR_htonl(PR_INADDR_ANY);
addr.inet.port = PR_htons(0);
if (PR_Bind(listenSock, &addr) == PR_FAILURE) {
- fprintf(stderr, "Can't bind socket\n");
- exit(1);
+ fprintf(stderr, "Can't bind socket\n");
+ exit(1);
}
if (PR_GetSockName(listenSock, &addr) == PR_FAILURE) {
- fprintf(stderr, "PR_GetSockName failed\n");
- exit(1);
+ fprintf(stderr, "PR_GetSockName failed\n");
+ exit(1);
}
listenPort = PR_ntohs(addr.inet.port);
if (PR_Listen(listenSock, 5) == PR_FAILURE) {
- fprintf(stderr, "Can't listen on a socket\n");
- exit(1);
+ fprintf(stderr, "Can't listen on a socket\n");
+ exit(1);
}
PR_snprintf(buf, sizeof(buf),
- "The server thread is listening on port %hu\n\n",
- listenPort);
+ "The server thread is listening on port %hu\n\n",
+ listenPort);
printf("%s", buf);
clientThread = PR_CreateThread(PR_USER_THREAD,
- clientThreadFunc, (void *) listenPort,
- PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
- PR_UNJOINABLE_THREAD, 0);
+ clientThreadFunc, (void *) listenPort,
+ PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
+ PR_UNJOINABLE_THREAD, 0);
if (clientThread == NULL) {
- fprintf(stderr, "can't create thread\n");
- exit(1);
+ fprintf(stderr, "can't create thread\n");
+ exit(1);
}
printf("client thread created.\n");
@@ -163,7 +163,7 @@ static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
if (sock != NULL || PR_GetError() != PR_WOULD_BLOCK_ERROR) {
PL_PrintError("First Accept\n");
fprintf(stderr, "First PR_Accept() xxx\n" );
- exit(1);
+ exit(1);
}
printf("accept: EWOULDBLOCK, good\n");
fflush(stdout);
@@ -174,7 +174,7 @@ static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
PL_PrintError("Second Accept\n");
fprintf(stderr, "Second PR_Accept() failed: (%d, %d)\n",
PR_GetError(), PR_GetOSError());
- exit(1);
+ exit(1);
}
printf("accept: succeeded, good\n");
fflush(stdout);
@@ -184,26 +184,26 @@ static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
/* time 3, 5, 6, 8, etc. */
for (i = 0; i < NUMBER_ROUNDS; i++) {
- PR_Sleep(unitTime);
- retVal = PR_Recv(sock, buf, sizeof(buf), 0, PR_INTERVAL_NO_TIMEOUT);
- if (retVal != -1 || PR_GetError() != PR_WOULD_BLOCK_ERROR) {
- PL_PrintError("First Receive:\n");
- fprintf(stderr, "First PR_Recv: retVal: %ld, Error: %ld\n",
- retVal, PR_GetError());
- exit(1);
+ PR_Sleep(unitTime);
+ retVal = PR_Recv(sock, buf, sizeof(buf), 0, PR_INTERVAL_NO_TIMEOUT);
+ if (retVal != -1 || PR_GetError() != PR_WOULD_BLOCK_ERROR) {
+ PL_PrintError("First Receive:\n");
+ fprintf(stderr, "First PR_Recv: retVal: %ld, Error: %ld\n",
+ retVal, PR_GetError());
+ exit(1);
}
- printf("read: EWOULDBLOCK, good\n");
- fflush(stdout);
- PR_Sleep(2 * unitTime);
- retVal = PR_Recv(sock, buf, sizeof(buf), 0, PR_INTERVAL_NO_TIMEOUT);
- if (retVal != CHUNK_SIZE) {
- PL_PrintError("Second Receive:\n");
- fprintf(stderr, "Second PR_Recv: retVal: %ld, Error: %ld\n",
- retVal, PR_GetError());
- exit(1);
+ printf("read: EWOULDBLOCK, good\n");
+ fflush(stdout);
+ PR_Sleep(2 * unitTime);
+ retVal = PR_Recv(sock, buf, sizeof(buf), 0, PR_INTERVAL_NO_TIMEOUT);
+ if (retVal != CHUNK_SIZE) {
+ PL_PrintError("Second Receive:\n");
+ fprintf(stderr, "Second PR_Recv: retVal: %ld, Error: %ld\n",
+ retVal, PR_GetError());
+ exit(1);
}
- printf("read: %d bytes, good\n", retVal);
- fflush(stdout);
+ printf("read: %d bytes, good\n", retVal);
+ fflush(stdout);
}
PR_Close(sock);
diff --git a/pr/tests/ntioto.c b/pr/tests/ntioto.c
index 0686241b..5fb01e76 100644
--- a/pr/tests/ntioto.c
+++ b/pr/tests/ntioto.c
@@ -98,27 +98,36 @@ static void AcceptThread(void *arg)
PRNetAddr *arAddr;
bytesRead = PR_AcceptRead( listenSock,
- &arSock,
- &arAddr,
- dataBuf,
- ACCEPT_READ_DATASIZE,
- PR_SecondsToInterval(1));
+ &arSock,
+ &arAddr,
+ dataBuf,
+ ACCEPT_READ_DATASIZE,
+ PR_SecondsToInterval(1));
if ( bytesRead == -1 && PR_GetError() == PR_IO_TIMEOUT_ERROR ) {
- if ( debug ) printf("AcceptRead timed out\n");
+ if ( debug ) {
+ printf("AcceptRead timed out\n");
+ }
} else {
- if ( debug ) printf("Oops! read: %d, error: %d\n", bytesRead, PR_GetError());
+ if ( debug ) {
+ printf("Oops! read: %d, error: %d\n", bytesRead, PR_GetError());
+ }
}
while( state != AllDone ) {
PR_Lock( ml );
- while( state != RunAcceptRead )
+ while( state != RunAcceptRead ) {
PR_WaitCondVar( cv, PR_INTERVAL_NO_TIMEOUT );
- if ( ++iCounter >= jitter )
+ }
+ if ( ++iCounter >= jitter ) {
state = AllDone;
- else
+ }
+ else {
state = RunJitter;
- if ( verbose ) printf(".");
+ }
+ if ( verbose ) {
+ printf(".");
+ }
PR_NotifyCondVar( cv );
PR_Unlock( ml );
PR_Write( file1, ".", 1 );
@@ -131,11 +140,15 @@ static void JitterThread(void *arg)
{
while( state != AllDone ) {
PR_Lock( ml );
- while( state != RunJitter && state != AllDone )
+ while( state != RunJitter && state != AllDone ) {
PR_WaitCondVar( cv, PR_INTERVAL_NO_TIMEOUT );
- if ( state != AllDone)
+ }
+ if ( state != AllDone) {
state = RunAcceptRead;
- if ( verbose ) printf("+");
+ }
+ if ( verbose ) {
+ printf("+");
+ }
PR_NotifyCondVar( cv );
PR_Unlock( ml );
PR_Write( file1, "+", 1 );
@@ -153,7 +166,9 @@ static void ConnectThread( void *arg )
PR_ASSERT(clientSock);
if ( resume ) {
- if ( debug ) printf("pausing 3 seconds before connect\n");
+ if ( debug ) {
+ printf("pausing 3 seconds before connect\n");
+ }
PR_Sleep( PR_SecondsToInterval(3));
}
@@ -161,13 +176,14 @@ static void ConnectThread( void *arg )
rv = PR_InitializeNetAddr(PR_IpAddrLoopback, BASE_PORT, &serverAddress);
PR_ASSERT( PR_SUCCESS == rv );
rv = PR_Connect( clientSock,
- &serverAddress,
- PR_SecondsToInterval(1));
+ &serverAddress,
+ PR_SecondsToInterval(1));
PR_ASSERT( PR_SUCCESS == rv );
/* that's all we do. ... Wait for the acceptread() to timeout */
- while( state != AllDone )
+ while( state != AllDone ) {
PR_Sleep( PR_SecondsToInterval(1));
+ }
return;
} /* end ConnectThread() */
@@ -191,35 +207,38 @@ int main(int argc, char **argv)
PLOptStatus os;
PLOptState *opt = PL_CreateOptState(argc, argv, "hdrvj:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ 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 */
- debug = 1;
- msgLevel = PR_LOG_ERROR;
- break;
- case 'v': /* verbose mode */
- verbose = 1;
- msgLevel = PR_LOG_DEBUG;
- break;
- case 'j':
- jitter = atoi(opt->value);
- if ( jitter == 0)
- jitter = JITTER_DEFAULT;
- break;
- case 'r':
- resume = PR_TRUE;
- break;
- case 'h': /* help message */
- Help();
- break;
- default:
- break;
+ case 'd': /* debug */
+ debug = 1;
+ msgLevel = PR_LOG_ERROR;
+ break;
+ case 'v': /* verbose mode */
+ verbose = 1;
+ msgLevel = PR_LOG_DEBUG;
+ break;
+ case 'j':
+ jitter = atoi(opt->value);
+ if ( jitter == 0) {
+ jitter = JITTER_DEFAULT;
+ }
+ break;
+ case 'r':
+ resume = PR_TRUE;
+ break;
+ case 'h': /* help message */
+ Help();
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
}
lm = PR_NewLogModule("Test"); /* Initialize logging */
@@ -250,23 +269,23 @@ int main(int argc, char **argv)
/* create Connect thread */
tConnect = PR_CreateThread(
- PR_USER_THREAD, ConnectThread, NULL,
- PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
- PR_JOINABLE_THREAD, 0 );
+ PR_USER_THREAD, ConnectThread, NULL,
+ PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
+ PR_JOINABLE_THREAD, 0 );
PR_ASSERT( tConnect );
/* create jitter off thread */
tJitter = PR_CreateThread(
- PR_USER_THREAD, JitterThread, NULL,
- PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
- PR_JOINABLE_THREAD, 0 );
+ PR_USER_THREAD, JitterThread, NULL,
+ PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
+ PR_JOINABLE_THREAD, 0 );
PR_ASSERT( tJitter );
/* create acceptread thread */
tAccept = PR_CreateThread(
- PR_USER_THREAD, AcceptThread, NULL,
- PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
- PR_JOINABLE_THREAD, 0 );
+ PR_USER_THREAD, AcceptThread, NULL,
+ PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
+ PR_JOINABLE_THREAD, 0 );
PR_ASSERT( tAccept );
/* wait for all threads to quit, then terminate gracefully */
@@ -280,7 +299,9 @@ int main(int argc, char **argv)
PR_Delete( "xxxTestFile");
/* test return and exit */
- if (debug) printf("%s\n", (failed_already)? "FAIL" : "PASS");
+ if (debug) {
+ printf("%s\n", (failed_already)? "FAIL" : "PASS");
+ }
return( (failed_already == PR_TRUE )? 1 : 0 );
} /* main() */
/* end ntioto.c */
diff --git a/pr/tests/ntoh.c b/pr/tests/ntoh.c
index b4ddc81e..980a1b49 100644
--- a/pr/tests/ntoh.c
+++ b/pr/tests/ntoh.c
@@ -33,17 +33,17 @@ int main(int argc, char **argv)
un.s = s_h;
printf("%u %u\n",
- un.bytes[0], un.bytes[1]);
+ un.bytes[0], un.bytes[1]);
un.s = PR_htons(un.s);
printf("%u %u\n",
- un.bytes[0], un.bytes[1]);
+ un.bytes[0], un.bytes[1]);
if (memcmp(un.bytes, bytes_n, 2)) {
fprintf(stderr, "PR_htons failed\n");
exit(1);
}
un.s = PR_ntohs(un.s);
printf("%u %u\n",
- un.bytes[0], un.bytes[1]);
+ un.bytes[0], un.bytes[1]);
if (un.s != s_h) {
fprintf(stderr, "PR_ntohs failed\n");
exit(1);
@@ -51,17 +51,17 @@ int main(int argc, char **argv)
un.l = l_h;
printf("%u %u %u %u\n",
- un.bytes[0], un.bytes[1], un.bytes[2], un.bytes[3]);
+ un.bytes[0], un.bytes[1], un.bytes[2], un.bytes[3]);
un.l = PR_htonl(un.l);
printf("%u %u %u %u\n",
- un.bytes[0], un.bytes[1], un.bytes[2], un.bytes[3]);
+ un.bytes[0], un.bytes[1], un.bytes[2], un.bytes[3]);
if (memcmp(un.bytes, bytes_n, 4)) {
fprintf(stderr, "PR_htonl failed\n");
exit(1);
}
un.l = PR_ntohl(un.l);
printf("%u %u %u %u\n",
- un.bytes[0], un.bytes[1], un.bytes[2], un.bytes[3]);
+ un.bytes[0], un.bytes[1], un.bytes[2], un.bytes[3]);
if (un.l != l_h) {
fprintf(stderr, "PR_ntohl failed\n");
exit(1);
@@ -69,20 +69,20 @@ int main(int argc, char **argv)
un.ll = ll_h;
printf("%u %u %u %u %u %u %u %u\n",
- un.bytes[0], un.bytes[1], un.bytes[2], un.bytes[3],
- un.bytes[4], un.bytes[5], un.bytes[6], un.bytes[7]);
+ un.bytes[0], un.bytes[1], un.bytes[2], un.bytes[3],
+ un.bytes[4], un.bytes[5], un.bytes[6], un.bytes[7]);
un.ll = PR_htonll(un.ll);
printf("%u %u %u %u %u %u %u %u\n",
- un.bytes[0], un.bytes[1], un.bytes[2], un.bytes[3],
- un.bytes[4], un.bytes[5], un.bytes[6], un.bytes[7]);
+ un.bytes[0], un.bytes[1], un.bytes[2], un.bytes[3],
+ un.bytes[4], un.bytes[5], un.bytes[6], un.bytes[7]);
if (memcmp(un.bytes, bytes_n, 8)) {
fprintf(stderr, "PR_htonll failed\n");
exit(1);
}
un.ll = PR_ntohll(un.ll);
printf("%u %u %u %u %u %u %u %u\n",
- un.bytes[0], un.bytes[1], un.bytes[2], un.bytes[3],
- un.bytes[4], un.bytes[5], un.bytes[6], un.bytes[7]);
+ un.bytes[0], un.bytes[1], un.bytes[2], un.bytes[3],
+ un.bytes[4], un.bytes[5], un.bytes[6], un.bytes[7]);
if (LL_NE(un.ll, ll_h)) {
fprintf(stderr, "PR_ntohll failed\n");
exit(1);
diff --git a/pr/tests/op_2long.c b/pr/tests/op_2long.c
index 8a6e1c3a..7a6b1312 100644
--- a/pr/tests/op_2long.c
+++ b/pr/tests/op_2long.c
@@ -37,38 +37,38 @@ PRIntn error_code;
int main(int argc, char **argv)
{
- char nameTooLong[TOO_LONG];
- int i;
+ char nameTooLong[TOO_LONG];
+ int i;
- /* Generate a really long pathname */
- for (i = 0; i < TOO_LONG - 1; i++) {
- if (i % 10 == 0) {
- nameTooLong[i] = '/';
- } else {
- nameTooLong[i] = 'a';
- }
- }
- nameTooLong[TOO_LONG - 1] = 0;
+ /* Generate a really long pathname */
+ for (i = 0; i < TOO_LONG - 1; i++) {
+ if (i % 10 == 0) {
+ nameTooLong[i] = '/';
+ } else {
+ nameTooLong[i] = 'a';
+ }
+ }
+ nameTooLong[TOO_LONG - 1] = 0;
PR_STDIO_INIT();
- t1 = PR_Open(nameTooLong, PR_RDWR, 0666);
- if (t1 == NULL) {
- if (PR_GetError() == PR_NAME_TOO_LONG_ERROR) {
+ t1 = PR_Open(nameTooLong, PR_RDWR, 0666);
+ if (t1 == NULL) {
+ if (PR_GetError() == PR_NAME_TOO_LONG_ERROR) {
PL_PrintError("error code is");
- printf ("PASS\n");
- return 0;
- }
- else {
+ printf ("PASS\n");
+ return 0;
+ }
+ else {
PL_PrintError("error code is");
- printf ("FAIL\n");
- return 1;
- }
- }
+ printf ("FAIL\n");
+ return 1;
+ }
+ }
- else {
- printf ("Test passed\n");
- return 0;
- }
+ else {
+ printf ("Test passed\n");
+ return 0;
+ }
diff --git a/pr/tests/op_excl.c b/pr/tests/op_excl.c
index 630b7637..e214af12 100644
--- a/pr/tests/op_excl.c
+++ b/pr/tests/op_excl.c
@@ -55,23 +55,25 @@ int main(int argc, char **argv)
PLOptStatus os;
PLOptState *opt = PL_CreateOptState(argc, argv, "hd");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ 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 */
- debug = 1;
- msgLevel = PR_LOG_ERROR;
- break;
- case 'h': /* help message */
- Help();
- break;
- default:
- break;
+ case 'd': /* debug */
+ debug = 1;
+ msgLevel = PR_LOG_ERROR;
+ break;
+ case 'h': /* help message */
+ Help();
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
}
lm = PR_NewLogModule("Test"); /* Initialize logging */
@@ -81,21 +83,27 @@ int main(int argc, char **argv)
*/
fd = PR_Open( NEW_FILENAME, PR_CREATE_FILE | PR_EXCL | PR_WRONLY, 0666 );
if ( NULL == fd ) {
- if (debug) fprintf( stderr, "Open exclusive. Expected success, got failure\n");
+ if (debug) {
+ fprintf( stderr, "Open exclusive. Expected success, got failure\n");
+ }
failed_already = 1;
goto Finished;
}
written = PR_Write( fd, outBuf, OUT_SIZE );
if ( OUT_SIZE != written ) {
- if (debug) fprintf( stderr, "Write after open exclusive failed\n");
+ if (debug) {
+ fprintf( stderr, "Write after open exclusive failed\n");
+ }
failed_already = 1;
goto Finished;
}
rv = PR_Close(fd);
if ( PR_FAILURE == rv ) {
- if (debug) fprintf( stderr, "Close after open exclusive failed\n");
+ if (debug) {
+ fprintf( stderr, "Close after open exclusive failed\n");
+ }
failed_already = 1;
goto Finished;
}
@@ -105,19 +113,25 @@ int main(int argc, char **argv)
*/
fd = PR_Open( NEW_FILENAME, PR_CREATE_FILE | PR_EXCL | PR_WRONLY, 0666 );
if ( NULL != fd ) {
- if (debug) fprintf( stderr, "Open exclusive. Expected failure, got success\n");
+ if (debug) {
+ fprintf( stderr, "Open exclusive. Expected failure, got success\n");
+ }
failed_already = 1;
PR_Close(fd);
}
rv = PR_Delete( NEW_FILENAME );
if ( PR_FAILURE == rv ) {
- if (debug) fprintf( stderr, "PR_Delete() failed\n");
+ if (debug) {
+ fprintf( stderr, "PR_Delete() failed\n");
+ }
failed_already = 1;
}
Finished:
- if (debug) printf("%s\n", (failed_already)? "FAIL" : "PASS");
+ if (debug) {
+ printf("%s\n", (failed_already)? "FAIL" : "PASS");
+ }
return( (failed_already == PR_TRUE )? 1 : 0 );
} /* main() */
/* end op_excl.c */
diff --git a/pr/tests/op_filnf.c b/pr/tests/op_filnf.c
index 61c4d497..1f1e8eed 100644
--- a/pr/tests/op_filnf.c
+++ b/pr/tests/op_filnf.c
@@ -8,7 +8,7 @@
** Name: op_filnf.c
**
** Description: Test Program to verify the PR_FILE_NOT_FOUND_ERROR
-** This test program also uses the TRUNCATE option
+** This test program also uses the TRUNCATE option
**
** Modification History:
** 03-June-97 AGarcia- Initial version
@@ -31,21 +31,21 @@ PRIntn error_code;
int main(int argc, char **argv)
{
PR_STDIO_INIT();
- t1 = PR_Open("/usr/tmp/ttools/err03.tmp", PR_TRUNCATE | PR_RDWR, 0666);
- if (t1 == NULL) {
- if (PR_GetError() == PR_FILE_NOT_FOUND_ERROR) {
- printf ("error code is %d \n", PR_GetError());
- printf ("PASS\n");
- return 0;
- }
- else {
- printf ("error code is %d \n", PR_GetError());
- printf ("FAIL\n");
- return 1;
- }
- }
- PR_Close(t1);
- printf ("opened a file that should not exist\n");
- printf ("FAIL\n");
- return 1;
+ t1 = PR_Open("/usr/tmp/ttools/err03.tmp", PR_TRUNCATE | PR_RDWR, 0666);
+ if (t1 == NULL) {
+ if (PR_GetError() == PR_FILE_NOT_FOUND_ERROR) {
+ printf ("error code is %d \n", PR_GetError());
+ printf ("PASS\n");
+ return 0;
+ }
+ else {
+ printf ("error code is %d \n", PR_GetError());
+ printf ("FAIL\n");
+ return 1;
+ }
+ }
+ PR_Close(t1);
+ printf ("opened a file that should not exist\n");
+ printf ("FAIL\n");
+ return 1;
}
diff --git a/pr/tests/op_filok.c b/pr/tests/op_filok.c
index f8110cc4..4f8688b7 100644
--- a/pr/tests/op_filok.c
+++ b/pr/tests/op_filok.c
@@ -29,20 +29,20 @@ int main(int argc, char **argv)
{
PR_STDIO_INIT();
- t1 = PR_Open(argv[0], PR_RDONLY, 0666);
+ t1 = PR_Open(argv[0], PR_RDONLY, 0666);
- if (t1 == NULL) {
- printf ("error code is %d \n", PR_GetError());
- printf ("File %s should be found\n", argv[0]);
- return 1;
- } else {
- if (PR_Close(t1) == PR_SUCCESS) {
- printf ("Test passed \n");
- return 0;
- } else {
- printf ("cannot close file\n");
- printf ("error code is %d\n", PR_GetError());
- return 1;
- }
- }
+ if (t1 == NULL) {
+ printf ("error code is %d \n", PR_GetError());
+ printf ("File %s should be found\n", argv[0]);
+ return 1;
+ } else {
+ if (PR_Close(t1) == PR_SUCCESS) {
+ printf ("Test passed \n");
+ return 0;
+ } else {
+ printf ("cannot close file\n");
+ printf ("error code is %d\n", PR_GetError());
+ return 1;
+ }
+ }
}
diff --git a/pr/tests/op_nofil.c b/pr/tests/op_nofil.c
index 2b809672..12d54201 100644
--- a/pr/tests/op_nofil.c
+++ b/pr/tests/op_nofil.c
@@ -34,23 +34,23 @@ static PRFileDesc *t1;
int main(int argc, char **argv)
{
PR_STDIO_INIT();
- t1 = PR_Open(NO_SUCH_FILE, PR_RDONLY, 0666);
- if (t1 == NULL) {
- if (PR_GetError() == PR_FILE_NOT_FOUND_ERROR) {
- printf ("error code is PR_FILE_NOT_FOUND_ERROR, as expected\n");
- printf ("PASS\n");
- return 0;
- } else {
- printf ("error code is %d \n", PR_GetError());
- printf ("FAIL\n");
- return 1;
- }
- }
- printf ("File %s exists on this machine!?\n", NO_SUCH_FILE);
- if (PR_Close(t1) == PR_FAILURE) {
- printf ("cannot close file\n");
- printf ("error code is %d \n", PR_GetError());
- }
- printf ("FAIL\n");
- return 1;
+ t1 = PR_Open(NO_SUCH_FILE, PR_RDONLY, 0666);
+ if (t1 == NULL) {
+ if (PR_GetError() == PR_FILE_NOT_FOUND_ERROR) {
+ printf ("error code is PR_FILE_NOT_FOUND_ERROR, as expected\n");
+ printf ("PASS\n");
+ return 0;
+ } else {
+ printf ("error code is %d \n", PR_GetError());
+ printf ("FAIL\n");
+ return 1;
+ }
+ }
+ printf ("File %s exists on this machine!?\n", NO_SUCH_FILE);
+ if (PR_Close(t1) == PR_FAILURE) {
+ printf ("cannot close file\n");
+ printf ("error code is %d \n", PR_GetError());
+ }
+ printf ("FAIL\n");
+ return 1;
}
diff --git a/pr/tests/parent.c b/pr/tests/parent.c
index f1bfc415..f43ce0c3 100644
--- a/pr/tests/parent.c
+++ b/pr/tests/parent.c
@@ -28,7 +28,7 @@ static char *default_argv[] = {"cvar", "-c", "2000", NULL};
static void PrintUsage(void)
{
PR_fprintf(PR_GetSpecialFD(PR_StandardError),
- "Usage: parent [-d] child [options]\n");
+ "Usage: parent [-d] child [options]\n");
}
int main(int argc, char **argv)
@@ -49,8 +49,9 @@ int main(int argc, char **argv)
argv += 1; /* don't care about our program name */
while (*argv != NULL && argv[0][0] == '-')
{
- if (argv[0][1] == 'd')
+ if (argv[0][1] == 'd') {
debug = PR_GetSpecialFD(PR_StandardError);
+ }
else
{
PrintUsage();
@@ -68,7 +69,9 @@ int main(int argc, char **argv)
}
child->name = *child->argv;
- if (NULL != debug) PR_fprintf(debug, "Forking %s\n", child->name);
+ if (NULL != debug) {
+ PR_fprintf(debug, "Forking %s\n", child->name);
+ }
child->attr = PR_NewProcessAttr();
PR_ProcessAttrSetStdioRedirect(
@@ -80,7 +83,7 @@ int main(int argc, char **argv)
t_start = PR_IntervalNow();
child->process = PR_CreateProcess(
- child->name, child->argv, NULL, child->attr);
+ child->name, child->argv, NULL, child->attr);
t_elapsed = (PRIntervalTime) (PR_IntervalNow() - t_start);
PR_DestroyProcessAttr(child->attr);
@@ -99,7 +102,9 @@ int main(int argc, char **argv)
if (0 == test_status)
{
- if (NULL != debug) PR_fprintf(debug, "Waiting for child to exit\n");
+ if (NULL != debug) {
+ PR_fprintf(debug, "Waiting for child to exit\n");
+ }
rv = PR_WaitProcess(child->process, &test_status);
if (PR_SUCCESS == rv)
{
@@ -111,8 +116,9 @@ int main(int argc, char **argv)
else
{
test_status = 1;
- if (NULL != debug)
+ if (NULL != debug) {
PR_fprintf(debug, "PR_WaitProcess failed\n");
+ }
}
}
PR_DELETE(child);
diff --git a/pr/tests/parsetm.c b/pr/tests/parsetm.c
index d4629dd4..0e25ffe6 100644
--- a/pr/tests/parsetm.c
+++ b/pr/tests/parsetm.c
@@ -19,10 +19,11 @@
PRBool debug_mode = PR_TRUE;
static char *dayOfWeek[] =
- { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???" };
+{ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???" };
static char *month[] =
- { "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 void PrintExplodedTime(const PRExplodedTime *et) {
PRInt32 totalOffset;
@@ -31,27 +32,32 @@ static void PrintExplodedTime(const PRExplodedTime *et) {
/* Print day of the week, month, day, hour, minute, and second */
if (debug_mode) printf("%s %s %ld %02ld:%02ld:%02ld ",
- dayOfWeek[et->tm_wday], month[et->tm_month], et->tm_mday,
- et->tm_hour, et->tm_min, et->tm_sec);
+ dayOfWeek[et->tm_wday], month[et->tm_month], et->tm_mday,
+ et->tm_hour, et->tm_min, et->tm_sec);
/* Print time zone */
totalOffset = et->tm_params.tp_gmt_offset + et->tm_params.tp_dst_offset;
if (totalOffset == 0) {
- if (debug_mode) printf("UTC ");
+ if (debug_mode) {
+ printf("UTC ");
+ }
} else {
sign = "+";
if (totalOffset < 0) {
- totalOffset = -totalOffset;
- sign = "-";
+ totalOffset = -totalOffset;
+ sign = "-";
}
hourOffset = totalOffset / 3600;
minOffset = (totalOffset % 3600) / 60;
- if (debug_mode)
+ if (debug_mode) {
printf("%s%02ld%02ld ", sign, hourOffset, minOffset);
+ }
}
/* Print year */
- if (debug_mode) printf("%hd", et->tm_year);
+ if (debug_mode) {
+ printf("%hd", et->tm_year);
+ }
}
int main(int argc, char **argv)
diff --git a/pr/tests/peek.c b/pr/tests/peek.c
index 5b83692f..4dce8299 100644
--- a/pr/tests/peek.c
+++ b/pr/tests/peek.c
@@ -30,9 +30,11 @@ static int iterations = 10;
* send_amount[i] <= recv_amount[i].
*/
static PRInt32 recv_amount[10] = {
- 16, 128, 256, 1024, 512, 512, 128, 256, 32, 32};
+ 16, 128, 256, 1024, 512, 512, 128, 256, 32, 32
+};
static PRInt32 send_amount[10] = {
- 16, 64, 128, 1024, 512, 256, 128, 64, 16, 32};
+ 16, 64, 128, 1024, 512, 256, 128, 64, 16, 32
+};
/* Blocking I/O */
static void ServerB(void *arg)
@@ -53,7 +55,7 @@ static void ServerB(void *arg)
for (i = 0; i < iterations; i++) {
memset(buf, 0, sizeof(buf));
nbytes = PR_Recv(sock, buf, recv_amount[i],
- PR_MSG_PEEK, PR_INTERVAL_NO_TIMEOUT);
+ PR_MSG_PEEK, PR_INTERVAL_NO_TIMEOUT);
if (-1 == nbytes) {
fprintf(stderr, "PR_Recv failed\n");
exit(1);
@@ -73,7 +75,7 @@ static void ServerB(void *arg)
memset(buf, 0, sizeof(buf));
nbytes = PR_Recv(sock, buf, recv_amount[i],
- PR_MSG_PEEK, PR_INTERVAL_NO_TIMEOUT);
+ PR_MSG_PEEK, PR_INTERVAL_NO_TIMEOUT);
if (-1 == nbytes) {
fprintf(stderr, "PR_Recv failed\n");
exit(1);
@@ -93,7 +95,7 @@ static void ServerB(void *arg)
memset(buf, 0, sizeof(buf));
nbytes = PR_Recv(sock, buf, recv_amount[i],
- 0, PR_INTERVAL_NO_TIMEOUT);
+ 0, PR_INTERVAL_NO_TIMEOUT);
if (-1 == nbytes) {
fprintf(stderr, "PR_Recv failed\n");
exit(1);
@@ -114,7 +116,7 @@ static void ServerB(void *arg)
PR_Sleep(PR_SecondsToInterval(1));
memset(buf, 2*i+1, send_amount[i]);
nbytes = PR_Send(sock, buf, send_amount[i],
- 0, PR_INTERVAL_NO_TIMEOUT);
+ 0, PR_INTERVAL_NO_TIMEOUT);
if (-1 == nbytes) {
fprintf(stderr, "PR_Send failed\n");
exit(1);
@@ -157,7 +159,7 @@ static void ClientNB(void *arg)
}
memset(&addr, 0, sizeof(addr));
if (PR_SetNetAddr(PR_IpAddrLoopback, PR_AF_INET6, port, &addr)
- == PR_FAILURE) {
+ == PR_FAILURE) {
fprintf(stderr, "PR_SetNetAddr failed\n");
exit(1);
}
@@ -187,7 +189,7 @@ static void ClientNB(void *arg)
PR_Sleep(PR_SecondsToInterval(1));
memset(buf, 2*i, send_amount[i]);
while ((nbytes = PR_Send(sock, buf, send_amount[i],
- 0, PR_INTERVAL_NO_TIMEOUT)) == -1) {
+ 0, PR_INTERVAL_NO_TIMEOUT)) == -1) {
if (PR_GetError() != PR_WOULD_BLOCK_ERROR) {
fprintf(stderr, "PR_Send failed\n");
exit(1);
@@ -211,7 +213,7 @@ static void ClientNB(void *arg)
memset(buf, 0, sizeof(buf));
while ((nbytes = PR_Recv(sock, buf, recv_amount[i],
- PR_MSG_PEEK, PR_INTERVAL_NO_TIMEOUT)) == -1) {
+ PR_MSG_PEEK, PR_INTERVAL_NO_TIMEOUT)) == -1) {
if (PR_GetError() != PR_WOULD_BLOCK_ERROR) {
fprintf(stderr, "PR_Recv failed\n");
exit(1);
@@ -243,7 +245,7 @@ static void ClientNB(void *arg)
memset(buf, 0, sizeof(buf));
nbytes = PR_Recv(sock, buf, recv_amount[i],
- PR_MSG_PEEK, PR_INTERVAL_NO_TIMEOUT);
+ PR_MSG_PEEK, PR_INTERVAL_NO_TIMEOUT);
if (-1 == nbytes) {
fprintf(stderr, "PR_Recv failed\n");
exit(1);
@@ -263,7 +265,7 @@ static void ClientNB(void *arg)
memset(buf, 0, sizeof(buf));
nbytes = PR_Recv(sock, buf, recv_amount[i],
- 0, PR_INTERVAL_NO_TIMEOUT);
+ 0, PR_INTERVAL_NO_TIMEOUT);
if (-1 == nbytes) {
fprintf(stderr, "PR_Recv failed\n");
exit(1);
@@ -293,14 +295,14 @@ RunTest(PRThreadScope scope, PRFileDesc *listenSock, PRUint16 port)
PRThread *server, *client;
server = PR_CreateThread(PR_USER_THREAD, ServerB, listenSock,
- PR_PRIORITY_NORMAL, scope, PR_JOINABLE_THREAD, 0);
+ PR_PRIORITY_NORMAL, scope, PR_JOINABLE_THREAD, 0);
if (NULL == server) {
fprintf(stderr, "PR_CreateThread failed\n");
exit(1);
}
client = PR_CreateThread(
- PR_USER_THREAD, ClientNB, (void *) port,
- PR_PRIORITY_NORMAL, scope, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, ClientNB, (void *) port,
+ PR_PRIORITY_NORMAL, scope, PR_JOINABLE_THREAD, 0);
if (NULL == client) {
fprintf(stderr, "PR_CreateThread failed\n");
exit(1);
diff --git a/pr/tests/perf.c b/pr/tests/perf.c
index 8247eaf8..cd8ac143 100644
--- a/pr/tests/perf.c
+++ b/pr/tests/perf.c
@@ -32,18 +32,18 @@ static void LocalProcedureCall(void)
PRInt32 i;
for (i = 0; i < count; i++) {
- nop(i, i, 5);
+ nop(i, i, 5);
}
}
static void DLLProcedureCall(void)
{
PRInt32 i;
- PRThreadState state;
- PRThread *self = PR_GetCurrentThread();
+ PRThreadState state;
+ PRThread *self = PR_GetCurrentThread();
for (i = 0; i < count; i++) {
- state = PR_GetThreadState(self);
+ state = PR_GetThreadState(self);
}
}
@@ -72,8 +72,8 @@ static void IdleLock(void)
PRInt32 i;
for (i = 0; i < count; i++) {
- PR_Lock(lock);
- PR_Unlock(lock);
+ PR_Lock(lock);
+ PR_Unlock(lock);
}
}
@@ -82,8 +82,8 @@ static void IdleMonitor(void)
PRInt32 i;
for (i = 0; i < count; i++) {
- PR_EnterMonitor(mon);
- PR_ExitMonitor(mon);
+ PR_EnterMonitor(mon);
+ PR_ExitMonitor(mon);
}
}
@@ -92,8 +92,8 @@ static void IdleCMonitor(void)
PRInt32 i;
for (i = 0; i < count; i++) {
- PR_CEnterMonitor((void*)7);
- PR_CExitMonitor((void*)7);
+ PR_CEnterMonitor((void*)7);
+ PR_CExitMonitor((void*)7);
}
}
@@ -111,16 +111,17 @@ static void CDThread(void)
/*
* Cannot create too many threads
*/
- if (num_threads > 1000)
- num_threads = 1000;
+ if (num_threads > 1000) {
+ num_threads = 1000;
+ }
for (i = 0; i < num_threads; i++) {
PRThread *t = PR_CreateThread(PR_USER_THREAD,
- dull, 0,
- PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0);
+ dull, 0,
+ PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0);
if (NULL == t) {
fprintf(stderr, "CDThread: cannot create thread %3d\n", i);
} else {
@@ -140,13 +141,13 @@ static void PR_CALLBACK CXReader(void *arg)
PR_EnterMonitor(mon);
n = count / 2;
for (i = 0; i < n; i++) {
- while (cxq == 0) {
+ while (cxq == 0) {
DPRINTF(("CXReader: thread = 0x%lx waiting\n",
- PR_GetCurrentThread()));
- PR_Wait(mon, PR_INTERVAL_NO_TIMEOUT);
- }
- --cxq;
- PR_Notify(mon);
+ PR_GetCurrentThread()));
+ PR_Wait(mon, PR_INTERVAL_NO_TIMEOUT);
+ }
+ --cxq;
+ PR_Notify(mon);
}
PR_ExitMonitor(mon);
@@ -164,13 +165,13 @@ static void PR_CALLBACK CXWriter(void *arg)
PR_EnterMonitor(mon);
n = count / 2;
for (i = 0; i < n; i++) {
- while (cxq == 1) {
+ while (cxq == 1) {
DPRINTF(("CXWriter: thread = 0x%lx waiting\n",
- PR_GetCurrentThread()));
- PR_Wait(mon, PR_INTERVAL_NO_TIMEOUT);
- }
- ++cxq;
- PR_Notify(mon);
+ PR_GetCurrentThread()));
+ PR_Wait(mon, PR_INTERVAL_NO_TIMEOUT);
+ }
+ ++cxq;
+ PR_Notify(mon);
}
PR_ExitMonitor(mon);
@@ -190,37 +191,37 @@ static void ContextSwitch(PRThreadScope scope1, PRThreadScope scope2)
cxq = 0;
t1 = PR_CreateThread(PR_USER_THREAD,
- CXReader, 0,
- PR_PRIORITY_NORMAL,
- scope1,
- PR_UNJOINABLE_THREAD,
- 0);
+ CXReader, 0,
+ PR_PRIORITY_NORMAL,
+ scope1,
+ PR_UNJOINABLE_THREAD,
+ 0);
if (NULL == t1) {
fprintf(stderr, "ContextSwitch: cannot create thread\n");
} else {
DPRINTF(("ContextSwitch: created %s thread = 0x%lx\n",
- (scope1 == PR_GLOBAL_THREAD ?
- "PR_GLOBAL_THREAD" : "PR_LOCAL_THREAD"),
- t1));
+ (scope1 == PR_GLOBAL_THREAD ?
+ "PR_GLOBAL_THREAD" : "PR_LOCAL_THREAD"),
+ t1));
}
t2 = PR_CreateThread(PR_USER_THREAD,
- CXWriter, 0,
- PR_PRIORITY_NORMAL,
- scope2,
- PR_UNJOINABLE_THREAD,
- 0);
+ CXWriter, 0,
+ PR_PRIORITY_NORMAL,
+ scope2,
+ PR_UNJOINABLE_THREAD,
+ 0);
if (NULL == t2) {
fprintf(stderr, "ContextSwitch: cannot create thread\n");
} else {
DPRINTF(("ContextSwitch: created %s thread = 0x%lx\n",
- (scope2 == PR_GLOBAL_THREAD ?
- "PR_GLOBAL_THREAD" : "PR_LOCAL_THREAD"),
- t2));
+ (scope2 == PR_GLOBAL_THREAD ?
+ "PR_GLOBAL_THREAD" : "PR_LOCAL_THREAD"),
+ t2));
}
/* Wait for both of the threads to exit */
while (alive) {
- PR_Wait(mon2, PR_INTERVAL_NO_TIMEOUT);
+ PR_Wait(mon2, PR_INTERVAL_NO_TIMEOUT);
}
PR_ExitMonitor(mon2);
}
@@ -255,10 +256,10 @@ static void PR_CALLBACK SemaThread(void *argSema)
n = count / 2;
for (i = 0; i < n; i++) {
DPRINTF(("SemaThread: thread = 0x%lx waiting on sem = 0x%lx\n",
- PR_GetCurrentThread(), sem[0]));
+ PR_GetCurrentThread(), sem[0]));
PR_WaitSem(sem[0]);
DPRINTF(("SemaThread: thread = 0x%lx posting on sem = 0x%lx\n",
- PR_GetCurrentThread(), sem[1]));
+ PR_GetCurrentThread(), sem[1]));
PR_PostSem(sem[1]);
}
@@ -285,34 +286,34 @@ static void SemaContextSwitch(PRThreadScope scope1, PRThreadScope scope2)
cxq = 0;
t1 = PR_CreateThread(PR_USER_THREAD,
- SemaThread,
- sem_set1,
- PR_PRIORITY_NORMAL,
- scope1,
- PR_UNJOINABLE_THREAD,
- 0);
+ SemaThread,
+ sem_set1,
+ PR_PRIORITY_NORMAL,
+ scope1,
+ PR_UNJOINABLE_THREAD,
+ 0);
if (NULL == t1) {
fprintf(stderr, "SemaContextSwitch: cannot create thread\n");
} else {
DPRINTF(("SemaContextSwitch: created %s thread = 0x%lx\n",
- (scope1 == PR_GLOBAL_THREAD ?
- "PR_GLOBAL_THREAD" : "PR_LOCAL_THREAD"),
- t1));
+ (scope1 == PR_GLOBAL_THREAD ?
+ "PR_GLOBAL_THREAD" : "PR_LOCAL_THREAD"),
+ t1));
}
t2 = PR_CreateThread(PR_USER_THREAD,
- SemaThread,
- sem_set2,
- PR_PRIORITY_NORMAL,
- scope2,
- PR_UNJOINABLE_THREAD,
- 0);
+ SemaThread,
+ sem_set2,
+ PR_PRIORITY_NORMAL,
+ scope2,
+ PR_UNJOINABLE_THREAD,
+ 0);
if (NULL == t2) {
fprintf(stderr, "SemaContextSwitch: cannot create thread\n");
} else {
DPRINTF(("SemaContextSwitch: created %s thread = 0x%lx\n",
- (scope2 == PR_GLOBAL_THREAD ?
- "PR_GLOBAL_THREAD" : "PR_LOCAL_THREAD"),
- t2));
+ (scope2 == PR_GLOBAL_THREAD ?
+ "PR_GLOBAL_THREAD" : "PR_LOCAL_THREAD"),
+ t2));
}
/* Wait for both of the threads to exit */
@@ -363,30 +364,34 @@ static void Measure(void (*func)(void), const char *msg)
int main(int argc, char **argv)
{
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "dc:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "dc:");
+ 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_on = 1;
- break;
- case 'c': /* loop count */
- count = atoi(opt->value);
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ _debug_on = 1;
+ break;
+ case 'c': /* loop count */
+ count = atoi(opt->value);
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- if (0 == count) count = DEFAULT_COUNT;
+ if (0 == count) {
+ count = DEFAULT_COUNT;
+ }
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
- PR_BlockClockInterrupts();
- PR_UnblockClockInterrupts();
+ PR_BlockClockInterrupts();
+ PR_UnblockClockInterrupts();
PR_STDIO_INIT();
lock = PR_NewLock();
diff --git a/pr/tests/pipeself.c b/pr/tests/pipeself.c
index a3acf70b..7066c58d 100644
--- a/pr/tests/pipeself.c
+++ b/pr/tests/pipeself.c
@@ -94,7 +94,7 @@ int main(int argc, char **argv)
}
pongThread = PR_CreateThread(PR_USER_THREAD, PongThreadFunc, NULL,
- PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
if (pongThread == NULL) {
fprintf(stderr, "PR_CreateThread failed\n");
exit(1);
@@ -145,71 +145,71 @@ int main(int argc, char **argv)
}
#if defined(XP_UNIX)
- /*
- * Test PR_Available for pipes
- */
+ /*
+ * Test PR_Available for pipes
+ */
status = PR_CreatePipe(&ping_in, &ping_out);
if (status == PR_FAILURE) {
fprintf(stderr, "PR_CreatePipe failed\n");
exit(1);
}
- nBytes = PR_Write(ping_out, buf, 250);
- if (nBytes == -1) {
- fprintf(stderr, "PR_Write failed: (%d, %d)\n", PR_GetError(),
- PR_GetOSError());
- exit(1);
- }
- nBytes = PR_Available(ping_in);
- if (nBytes < 0) {
- fprintf(stderr, "PR_Available failed: (%d, %d)\n", PR_GetError(),
- PR_GetOSError());
- exit(1);
- } else if (nBytes != 250) {
- fprintf(stderr, "PR_Available: expected 250 bytes but got %d bytes\n",
- nBytes);
- exit(1);
- }
- printf("PR_Available: expected %d, got %d bytes\n",250, nBytes);
- /* read some data */
- nBytes = PR_Read(ping_in, buf, 7);
- if (nBytes == -1) {
- fprintf(stderr, "PR_Read failed\n");
- exit(1);
- }
- /* check available data */
- nBytes = PR_Available(ping_in);
- if (nBytes < 0) {
- fprintf(stderr, "PR_Available failed: (%d, %d)\n", PR_GetError(),
- PR_GetOSError());
- exit(1);
- } else if (nBytes != (250 - 7)) {
- fprintf(stderr, "PR_Available: expected 243 bytes but got %d bytes\n",
- nBytes);
- exit(1);
- }
- printf("PR_Available: expected %d, got %d bytes\n",243, nBytes);
- /* read all data */
- nBytes = PR_Read(ping_in, buf, sizeof(buf));
- if (nBytes == -1) {
- fprintf(stderr, "PR_Read failed\n");
- exit(1);
- } else if (nBytes != 243) {
- fprintf(stderr, "PR_Read failed: expected %d, got %d bytes\n",
- 243, nBytes);
- exit(1);
- }
- /* check available data */
- nBytes = PR_Available(ping_in);
- if (nBytes < 0) {
- fprintf(stderr, "PR_Available failed: (%d, %d)\n", PR_GetError(),
- PR_GetOSError());
- exit(1);
- } else if (nBytes != 0) {
- fprintf(stderr, "PR_Available: expected 0 bytes but got %d bytes\n",
- nBytes);
- exit(1);
- }
- printf("PR_Available: expected %d, got %d bytes\n", 0, nBytes);
+ nBytes = PR_Write(ping_out, buf, 250);
+ if (nBytes == -1) {
+ fprintf(stderr, "PR_Write failed: (%d, %d)\n", PR_GetError(),
+ PR_GetOSError());
+ exit(1);
+ }
+ nBytes = PR_Available(ping_in);
+ if (nBytes < 0) {
+ fprintf(stderr, "PR_Available failed: (%d, %d)\n", PR_GetError(),
+ PR_GetOSError());
+ exit(1);
+ } else if (nBytes != 250) {
+ fprintf(stderr, "PR_Available: expected 250 bytes but got %d bytes\n",
+ nBytes);
+ exit(1);
+ }
+ printf("PR_Available: expected %d, got %d bytes\n",250, nBytes);
+ /* read some data */
+ nBytes = PR_Read(ping_in, buf, 7);
+ if (nBytes == -1) {
+ fprintf(stderr, "PR_Read failed\n");
+ exit(1);
+ }
+ /* check available data */
+ nBytes = PR_Available(ping_in);
+ if (nBytes < 0) {
+ fprintf(stderr, "PR_Available failed: (%d, %d)\n", PR_GetError(),
+ PR_GetOSError());
+ exit(1);
+ } else if (nBytes != (250 - 7)) {
+ fprintf(stderr, "PR_Available: expected 243 bytes but got %d bytes\n",
+ nBytes);
+ exit(1);
+ }
+ printf("PR_Available: expected %d, got %d bytes\n",243, nBytes);
+ /* read all data */
+ nBytes = PR_Read(ping_in, buf, sizeof(buf));
+ if (nBytes == -1) {
+ fprintf(stderr, "PR_Read failed\n");
+ exit(1);
+ } else if (nBytes != 243) {
+ fprintf(stderr, "PR_Read failed: expected %d, got %d bytes\n",
+ 243, nBytes);
+ exit(1);
+ }
+ /* check available data */
+ nBytes = PR_Available(ping_in);
+ if (nBytes < 0) {
+ fprintf(stderr, "PR_Available failed: (%d, %d)\n", PR_GetError(),
+ PR_GetOSError());
+ exit(1);
+ } else if (nBytes != 0) {
+ fprintf(stderr, "PR_Available: expected 0 bytes but got %d bytes\n",
+ nBytes);
+ exit(1);
+ }
+ printf("PR_Available: expected %d, got %d bytes\n", 0, nBytes);
status = PR_Close(ping_in);
if (status == PR_FAILURE) {
diff --git a/pr/tests/poll_er.c b/pr/tests/poll_er.c
index 7c204dc8..b3a751d8 100755..100644
--- a/pr/tests/poll_er.c
+++ b/pr/tests/poll_er.c
@@ -12,12 +12,12 @@
**
** Modification History:
** 19-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.
***********************************************************************/
/***********************************************************************
@@ -64,92 +64,96 @@ int main(int argc, char **argv)
PRIntn npds;
PRInt32 retVal;
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
+ 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_mode = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- /* main test */
+ /* main test */
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
PR_STDIO_INIT();
if (debug_mode) {
- printf("This program tests PR_Poll with sockets.\n");
- printf("error reporting is tested.\n\n");
- }
+ printf("This program tests PR_Poll with sockets.\n");
+ printf("error reporting is tested.\n\n");
+ }
/* Create two listening sockets */
if ((listenSock1 = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr, "Can't create a new TCP socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't create a new TCP socket\n");
+ failed_already=1;
+ goto exit_now;
}
addr.inet.family = AF_INET;
addr.inet.ip = PR_htonl(INADDR_ANY);
addr.inet.port = PR_htons(0);
if (PR_Bind(listenSock1, &addr) == PR_FAILURE) {
- fprintf(stderr, "Can't bind socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't bind socket\n");
+ failed_already=1;
+ goto exit_now;
}
if (PR_GetSockName(listenSock1, &addr) == PR_FAILURE) {
- fprintf(stderr, "PR_GetSockName failed\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "PR_GetSockName failed\n");
+ failed_already=1;
+ goto exit_now;
}
listenPort1 = PR_ntohs(addr.inet.port);
if (PR_Listen(listenSock1, 5) == PR_FAILURE) {
- fprintf(stderr, "Can't listen on a socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't listen on a socket\n");
+ failed_already=1;
+ goto exit_now;
}
if ((listenSock2 = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr, "Can't create a new TCP socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't create a new TCP socket\n");
+ failed_already=1;
+ goto exit_now;
}
addr.inet.family = AF_INET;
addr.inet.ip = PR_htonl(INADDR_ANY);
addr.inet.port = PR_htons(0);
if (PR_Bind(listenSock2, &addr) == PR_FAILURE) {
- fprintf(stderr, "Can't bind socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't bind socket\n");
+ failed_already=1;
+ goto exit_now;
}
if (PR_GetSockName(listenSock2, &addr) == PR_FAILURE) {
- fprintf(stderr, "PR_GetSockName failed\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "PR_GetSockName failed\n");
+ failed_already=1;
+ goto exit_now;
}
listenPort2 = PR_ntohs(addr.inet.port);
if (PR_Listen(listenSock2, 5) == PR_FAILURE) {
- fprintf(stderr, "Can't listen on a socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't listen on a socket\n");
+ failed_already=1;
+ goto exit_now;
}
PR_snprintf(buf, sizeof(buf),
- "The server thread is listening on ports %hu and %hu\n\n",
- listenPort1, listenPort2);
- if (debug_mode) printf("%s", buf);
+ "The server thread is listening on ports %hu and %hu\n\n",
+ listenPort1, listenPort2);
+ if (debug_mode) {
+ printf("%s", buf);
+ }
/* Set up the poll descriptor array */
pds = pds0;
@@ -163,10 +167,12 @@ int main(int argc, char **argv)
/* Testing bad fd */
- if (debug_mode) printf("PR_Poll should detect a bad file descriptor\n");
+ if (debug_mode) {
+ printf("PR_Poll should detect a bad file descriptor\n");
+ }
if ((badFD = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr, "Can't create a TCP socket\n");
- goto exit_now;
+ fprintf(stderr, "Can't create a TCP socket\n");
+ goto exit_now;
}
pds[2].fd = badFD;
@@ -174,27 +180,31 @@ int main(int argc, char **argv)
npds = 3;
if (PR_CreateThread(PR_USER_THREAD, ClientThreadFunc,
- badFD, PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
- PR_UNJOINABLE_THREAD, 0) == NULL) {
+ badFD, PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
+ PR_UNJOINABLE_THREAD, 0) == NULL) {
fprintf(stderr, "cannot create thread\n");
exit(1);
}
retVal = PR_Poll(pds, npds, PR_INTERVAL_NO_TIMEOUT);
if (retVal != 1 || (unsigned short) pds[2].out_flags != PR_POLL_NVAL) {
- fprintf(stderr, "Failed to detect the bad fd: "
- "PR_Poll returns %d, out_flags is 0x%hx\n",
- retVal, pds[2].out_flags);
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Failed to detect the bad fd: "
+ "PR_Poll returns %d, out_flags is 0x%hx\n",
+ retVal, pds[2].out_flags);
+ failed_already=1;
+ goto exit_now;
+ }
+ if (debug_mode) {
+ printf("PR_Poll detected the bad fd. Test passed.\n\n");
}
- if (debug_mode) printf("PR_Poll detected the bad fd. Test passed.\n\n");
PR_Cleanup();
- goto exit_now;
+ goto exit_now;
exit_now:
- if(failed_already)
- return 1;
- else
- return 0;
+ if(failed_already) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
}
diff --git a/pr/tests/poll_nm.c b/pr/tests/poll_nm.c
index 59a24864..f356d141 100644
--- a/pr/tests/poll_nm.c
+++ b/pr/tests/poll_nm.c
@@ -12,12 +12,12 @@
**
** Modification History:
** 19-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.
***********************************************************************/
/***********************************************************************
@@ -62,17 +62,17 @@ clientThreadFunc(void *arg)
PR_snprintf(buf, sizeof(buf), "%hu", port);
for (i = 0; i < NUM_ITERATIONS; i++) {
- sock = PR_NewTCPSocket();
- PR_ASSERT(sock != NULL);
+ sock = PR_NewTCPSocket();
+ PR_ASSERT(sock != NULL);
- sts = PR_Connect(sock, &addr, PR_INTERVAL_NO_TIMEOUT);
- PR_ASSERT(sts == PR_SUCCESS);
+ sts = PR_Connect(sock, &addr, PR_INTERVAL_NO_TIMEOUT);
+ PR_ASSERT(sts == PR_SUCCESS);
- n = PR_Write(sock, buf, sizeof(buf));
- PR_ASSERT(n >= 0);
+ n = PR_Write(sock, buf, sizeof(buf));
+ PR_ASSERT(n >= 0);
- sts = PR_Close(sock);
- PR_ASSERT(sts == PR_SUCCESS);
+ sts = PR_Close(sock);
+ PR_ASSERT(sts == PR_SUCCESS);
}
}
@@ -89,97 +89,101 @@ int main(int argc, char **argv)
PRIntn i, j;
PRSocketOptionData optval;
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
+ 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_mode = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- /* main test */
+ /* main test */
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
PR_STDIO_INIT();
if (debug_mode) {
- printf("This program tests PR_Poll with sockets.\n");
- printf("Normal operation are tested.\n\n");
- }
+ printf("This program tests PR_Poll with sockets.\n");
+ printf("Normal operation are tested.\n\n");
+ }
/* Create two listening sockets */
if ((listenSock1 = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr, "Can't create a new TCP socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't create a new TCP socket\n");
+ failed_already=1;
+ goto exit_now;
}
memset(&addr, 0, sizeof(addr));
addr.inet.family = PR_AF_INET;
addr.inet.ip = PR_htonl(PR_INADDR_ANY);
addr.inet.port = PR_htons(0);
if (PR_Bind(listenSock1, &addr) == PR_FAILURE) {
- fprintf(stderr, "Can't bind socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't bind socket\n");
+ failed_already=1;
+ goto exit_now;
}
if (PR_GetSockName(listenSock1, &addr) == PR_FAILURE) {
- fprintf(stderr, "PR_GetSockName failed\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "PR_GetSockName failed\n");
+ failed_already=1;
+ goto exit_now;
}
listenPort1 = PR_ntohs(addr.inet.port);
optval.option = PR_SockOpt_Nonblocking;
optval.value.non_blocking = PR_TRUE;
PR_SetSocketOption(listenSock1, &optval);
if (PR_Listen(listenSock1, 5) == PR_FAILURE) {
- fprintf(stderr, "Can't listen on a socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't listen on a socket\n");
+ failed_already=1;
+ goto exit_now;
}
if ((listenSock2 = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr, "Can't create a new TCP socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't create a new TCP socket\n");
+ failed_already=1;
+ goto exit_now;
}
addr.inet.family = PR_AF_INET;
addr.inet.ip = PR_htonl(PR_INADDR_ANY);
addr.inet.port = PR_htons(0);
if (PR_Bind(listenSock2, &addr) == PR_FAILURE) {
- fprintf(stderr, "Can't bind socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't bind socket\n");
+ failed_already=1;
+ goto exit_now;
}
if (PR_GetSockName(listenSock2, &addr) == PR_FAILURE) {
- fprintf(stderr, "PR_GetSockName failed\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "PR_GetSockName failed\n");
+ failed_already=1;
+ goto exit_now;
}
listenPort2 = PR_ntohs(addr.inet.port);
PR_SetSocketOption(listenSock2, &optval);
if (PR_Listen(listenSock2, 5) == PR_FAILURE) {
- fprintf(stderr, "Can't listen on a socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't listen on a socket\n");
+ failed_already=1;
+ goto exit_now;
}
PR_snprintf(buf, sizeof(buf),
- "The server thread is listening on ports %hu and %hu\n\n",
- listenPort1, listenPort2);
- if (debug_mode) printf("%s", buf);
+ "The server thread is listening on ports %hu and %hu\n\n",
+ listenPort1, listenPort2);
+ if (debug_mode) {
+ printf("%s", buf);
+ }
/* Set up the poll descriptor array */
pds = pds0;
@@ -196,80 +200,80 @@ int main(int argc, char **argv)
npds = 5;
clientThread = PR_CreateThread(PR_USER_THREAD,
- clientThreadFunc, (void *) listenPort1,
- PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
- PR_UNJOINABLE_THREAD, 0);
+ clientThreadFunc, (void *) listenPort1,
+ PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
+ PR_UNJOINABLE_THREAD, 0);
if (clientThread == NULL) {
- fprintf(stderr, "can't create thread\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "can't create thread\n");
+ failed_already=1;
+ goto exit_now;
}
clientThread = PR_CreateThread(PR_USER_THREAD,
- clientThreadFunc, (void *) listenPort2,
- PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
- PR_UNJOINABLE_THREAD, 0);
+ clientThreadFunc, (void *) listenPort2,
+ PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
+ PR_UNJOINABLE_THREAD, 0);
if (clientThread == NULL) {
- fprintf(stderr, "can't create thread\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "can't create thread\n");
+ failed_already=1;
+ goto exit_now;
}
if (debug_mode) {
- printf("Two client threads are created. Each of them will\n");
- printf("send data to one of the two ports the server is listening on.\n");
- printf("The data they send is the port number. Each of them send\n");
- printf("the data five times, so you should see ten lines below,\n");
- printf("interleaved in an arbitrary order.\n");
- }
+ printf("Two client threads are created. Each of them will\n");
+ printf("send data to one of the two ports the server is listening on.\n");
+ printf("The data they send is the port number. Each of them send\n");
+ printf("the data five times, so you should see ten lines below,\n");
+ printf("interleaved in an arbitrary order.\n");
+ }
/* two clients, three events per iteration: accept, read, close */
i = 0;
while (i < 2 * 3 * NUM_ITERATIONS) {
- PRPollDesc *tmp;
- int nextIndex;
- int nEvents = 0;
-
- retVal = PR_Poll(pds, npds, PR_INTERVAL_NO_TIMEOUT);
- PR_ASSERT(retVal != 0); /* no timeout */
- if (retVal == -1) {
- fprintf(stderr, "PR_Poll failed\n");
- failed_already=1;
- goto exit_now;
- }
-
- nextIndex = 2;
- /* the two listening sockets */
- for (j = 0; j < 2; j++) {
- other_pds[j] = pds[j];
- PR_ASSERT((pds[j].out_flags & PR_POLL_WRITE) == 0
- && (pds[j].out_flags & PR_POLL_EXCEPT) == 0);
- if (pds[j].out_flags & PR_POLL_READ) {
- PRFileDesc *sock;
-
- nEvents++;
- sock = PR_Accept(pds[j].fd, NULL, PR_INTERVAL_NO_TIMEOUT);
- if (sock == NULL) {
- fprintf(stderr, "PR_Accept() failed\n");
- failed_already=1;
- goto exit_now;
- }
- other_pds[nextIndex].fd = sock;
- other_pds[nextIndex].in_flags = PR_POLL_READ;
- nextIndex++;
- } else if (pds[j].out_flags & PR_POLL_ERR) {
- fprintf(stderr, "PR_Poll() indicates that an fd has error\n");
- failed_already=1;
- goto exit_now;
- } else if (pds[j].out_flags & PR_POLL_NVAL) {
- fprintf(stderr, "PR_Poll() indicates that fd %d is invalid\n",
- PR_FileDesc2NativeHandle(pds[j].fd));
- failed_already=1;
- goto exit_now;
- }
- }
-
- for (j = 2; j < npds; j++) {
+ PRPollDesc *tmp;
+ int nextIndex;
+ int nEvents = 0;
+
+ retVal = PR_Poll(pds, npds, PR_INTERVAL_NO_TIMEOUT);
+ PR_ASSERT(retVal != 0); /* no timeout */
+ if (retVal == -1) {
+ fprintf(stderr, "PR_Poll failed\n");
+ failed_already=1;
+ goto exit_now;
+ }
+
+ nextIndex = 2;
+ /* the two listening sockets */
+ for (j = 0; j < 2; j++) {
+ other_pds[j] = pds[j];
+ PR_ASSERT((pds[j].out_flags & PR_POLL_WRITE) == 0
+ && (pds[j].out_flags & PR_POLL_EXCEPT) == 0);
+ if (pds[j].out_flags & PR_POLL_READ) {
+ PRFileDesc *sock;
+
+ nEvents++;
+ sock = PR_Accept(pds[j].fd, NULL, PR_INTERVAL_NO_TIMEOUT);
+ if (sock == NULL) {
+ fprintf(stderr, "PR_Accept() failed\n");
+ failed_already=1;
+ goto exit_now;
+ }
+ other_pds[nextIndex].fd = sock;
+ other_pds[nextIndex].in_flags = PR_POLL_READ;
+ nextIndex++;
+ } else if (pds[j].out_flags & PR_POLL_ERR) {
+ fprintf(stderr, "PR_Poll() indicates that an fd has error\n");
+ failed_already=1;
+ goto exit_now;
+ } else if (pds[j].out_flags & PR_POLL_NVAL) {
+ fprintf(stderr, "PR_Poll() indicates that fd %d is invalid\n",
+ PR_FileDesc2NativeHandle(pds[j].fd));
+ failed_already=1;
+ goto exit_now;
+ }
+ }
+
+ for (j = 2; j < npds; j++) {
if (NULL == pds[j].fd) {
/*
* Keep the unused entries in the poll descriptor array
@@ -280,51 +284,55 @@ int main(int argc, char **argv)
continue;
}
- PR_ASSERT((pds[j].out_flags & PR_POLL_WRITE) == 0
- && (pds[j].out_flags & PR_POLL_EXCEPT) == 0);
- if (pds[j].out_flags & PR_POLL_READ) {
+ PR_ASSERT((pds[j].out_flags & PR_POLL_WRITE) == 0
+ && (pds[j].out_flags & PR_POLL_EXCEPT) == 0);
+ if (pds[j].out_flags & PR_POLL_READ) {
PRInt32 nAvail;
- PRInt32 nRead;
+ PRInt32 nRead;
- nEvents++;
+ nEvents++;
nAvail = PR_Available(pds[j].fd);
- nRead = PR_Read(pds[j].fd, buf, sizeof(buf));
+ nRead = PR_Read(pds[j].fd, buf, sizeof(buf));
PR_ASSERT(nAvail == nRead);
- if (nRead == -1) {
- fprintf(stderr, "PR_Read() failed\n");
- failed_already=1;
- goto exit_now;
+ if (nRead == -1) {
+ fprintf(stderr, "PR_Read() failed\n");
+ failed_already=1;
+ goto exit_now;
} else if (nRead == 0) {
PR_Close(pds[j].fd);
continue;
} else {
/* Just to be safe */
buf[127] = '\0';
- if (debug_mode) printf("The server received \"%s\" from a client\n", buf);
+ if (debug_mode) {
+ printf("The server received \"%s\" from a client\n", buf);
+ }
}
- } else if (pds[j].out_flags & PR_POLL_ERR) {
- fprintf(stderr, "PR_Poll() indicates that an fd has error\n");
- failed_already=1;
- goto exit_now;
- } else if (pds[j].out_flags & PR_POLL_NVAL) {
- fprintf(stderr, "PR_Poll() indicates that an fd is invalid\n");
- failed_already=1;
- goto exit_now;
- }
+ } else if (pds[j].out_flags & PR_POLL_ERR) {
+ fprintf(stderr, "PR_Poll() indicates that an fd has error\n");
+ failed_already=1;
+ goto exit_now;
+ } else if (pds[j].out_flags & PR_POLL_NVAL) {
+ fprintf(stderr, "PR_Poll() indicates that an fd is invalid\n");
+ failed_already=1;
+ goto exit_now;
+ }
other_pds[nextIndex] = pds[j];
nextIndex++;
- }
-
- PR_ASSERT(retVal == nEvents);
- /* swap */
- tmp = pds;
- pds = other_pds;
- other_pds = tmp;
- npds = nextIndex;
- i += nEvents;
+ }
+
+ PR_ASSERT(retVal == nEvents);
+ /* swap */
+ tmp = pds;
+ pds = other_pds;
+ other_pds = tmp;
+ npds = nextIndex;
+ i += nEvents;
}
- if (debug_mode) printf("Tests passed\n");
+ if (debug_mode) {
+ printf("Tests passed\n");
+ }
exit_now:
@@ -337,9 +345,11 @@ exit_now:
PR_Cleanup();
- if(failed_already)
- return 1;
- else
- return 0;
+ if(failed_already) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
}
diff --git a/pr/tests/poll_to.c b/pr/tests/poll_to.c
index b1af515d..91291bcb 100644
--- a/pr/tests/poll_to.c
+++ b/pr/tests/poll_to.c
@@ -12,12 +12,12 @@
**
** Modification History:
** 14-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.
***********************************************************************/
/***********************************************************************
@@ -51,93 +51,113 @@ int main(int argc, char **argv)
PRIntn npds;
PRInt32 retVal;
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
+ 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_mode = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- /* main test */
+ /* main test */
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
PR_STDIO_INIT();
if (debug_mode) {
- printf("This program tests PR_Poll with sockets.\n");
- printf("Timeout is tested.\n\n");
- }
+ printf("This program tests PR_Poll with sockets.\n");
+ printf("Timeout is tested.\n\n");
+ }
/* Create two listening sockets */
if ((listenSock1 = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr, "Can't create a new TCP socket\n");
- if (!debug_mode) failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't create a new TCP socket\n");
+ if (!debug_mode) {
+ failed_already=1;
+ }
+ goto exit_now;
}
memset(&addr, 0, sizeof(addr));
addr.inet.family = PR_AF_INET;
addr.inet.ip = PR_htonl(PR_INADDR_ANY);
addr.inet.port = PR_htons(0);
if (PR_Bind(listenSock1, &addr) == PR_FAILURE) {
- fprintf(stderr, "Can't bind socket\n");
- if (!debug_mode) failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't bind socket\n");
+ if (!debug_mode) {
+ failed_already=1;
+ }
+ goto exit_now;
}
if (PR_GetSockName(listenSock1, &addr) == PR_FAILURE) {
- fprintf(stderr, "PR_GetSockName failed\n");
- if (!debug_mode) failed_already=1;
- goto exit_now;
+ fprintf(stderr, "PR_GetSockName failed\n");
+ if (!debug_mode) {
+ failed_already=1;
+ }
+ goto exit_now;
}
listenPort1 = PR_ntohs(addr.inet.port);
if (PR_Listen(listenSock1, 5) == PR_FAILURE) {
- fprintf(stderr, "Can't listen on a socket\n");
- if (!debug_mode) failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't listen on a socket\n");
+ if (!debug_mode) {
+ failed_already=1;
+ }
+ goto exit_now;
}
if ((listenSock2 = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr, "Can't create a new TCP socket\n");
- if (!debug_mode) failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't create a new TCP socket\n");
+ if (!debug_mode) {
+ failed_already=1;
+ }
+ goto exit_now;
}
addr.inet.family = PR_AF_INET;
addr.inet.ip = PR_htonl(PR_INADDR_ANY);
addr.inet.port = PR_htons(0);
if (PR_Bind(listenSock2, &addr) == PR_FAILURE) {
- fprintf(stderr, "Can't bind socket\n");
- if (!debug_mode) failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't bind socket\n");
+ if (!debug_mode) {
+ failed_already=1;
+ }
+ goto exit_now;
}
if (PR_GetSockName(listenSock2, &addr) == PR_FAILURE) {
- fprintf(stderr, "PR_GetSockName failed\n");
- if (!debug_mode) failed_already=1;
- goto exit_now;
+ fprintf(stderr, "PR_GetSockName failed\n");
+ if (!debug_mode) {
+ failed_already=1;
+ }
+ goto exit_now;
}
listenPort2 = PR_ntohs(addr.inet.port);
if (PR_Listen(listenSock2, 5) == PR_FAILURE) {
- fprintf(stderr, "Can't listen on a socket\n");
- if (!debug_mode) failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't listen on a socket\n");
+ if (!debug_mode) {
+ failed_already=1;
+ }
+ goto exit_now;
}
PR_snprintf(buf, sizeof(buf),
- "The server thread is listening on ports %hu and %hu\n\n",
- listenPort1, listenPort2);
- if (debug_mode) printf("%s", buf);
+ "The server thread is listening on ports %hu and %hu\n\n",
+ listenPort1, listenPort2);
+ if (debug_mode) {
+ printf("%s", buf);
+ }
/* Set up the poll descriptor array */
pds = pds0;
@@ -150,17 +170,23 @@ int main(int argc, char **argv)
npds = 2;
/* Testing timeout */
- if (debug_mode) printf("PR_Poll should time out in 5 seconds\n");
+ if (debug_mode) {
+ printf("PR_Poll should time out in 5 seconds\n");
+ }
retVal = PR_Poll(pds, npds, PR_SecondsToInterval(5));
if (retVal != 0) {
- PR_snprintf(buf, sizeof(buf),
- "PR_Poll should time out and return 0, but it returns %ld\n",
- retVal);
- fprintf(stderr, "%s", buf);
- if (!debug_mode) failed_already=1;
- goto exit_now;
+ PR_snprintf(buf, sizeof(buf),
+ "PR_Poll should time out and return 0, but it returns %ld\n",
+ retVal);
+ fprintf(stderr, "%s", buf);
+ if (!debug_mode) {
+ failed_already=1;
+ }
+ goto exit_now;
+ }
+ if (debug_mode) {
+ printf("PR_Poll timed out. Test passed.\n\n");
}
- if (debug_mode) printf("PR_Poll timed out. Test passed.\n\n");
exit_now:
@@ -173,9 +199,11 @@ exit_now:
PR_Cleanup();
- if(failed_already)
- return 1;
- else
- return 0;
+ if(failed_already) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
}
diff --git a/pr/tests/pollable.c b/pr/tests/pollable.c
index bb87f96e..7d0b51ca 100644
--- a/pr/tests/pollable.c
+++ b/pr/tests/pollable.c
@@ -81,11 +81,11 @@ static void Help(void)
debug_out = PR_STDOUT;
PR_fprintf(
- debug_out, "Usage: pollable [-c n] [-t n] [-d] [-v] [-G] [-C n] [-D n]\n");
+ debug_out, "Usage: pollable [-c n] [-t n] [-d] [-v] [-G] [-C n] [-D n]\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\tglobal threads only (default: FALSE)\n");
@@ -158,12 +158,12 @@ int main(int argc, char **argv)
if (PR_TRUE == debug_mode) {
debug_out = PR_STDOUT;
- PR_fprintf(debug_out, "Test parameters\n");
+ PR_fprintf(debug_out, "Test parameters\n");
PR_fprintf(debug_out, "\tThreads involved: %d\n", numThreads);
PR_fprintf(debug_out, "\tIteration limit: %d\n", numIterations);
PR_fprintf(debug_out, "\tConcurrency: %d\n", concurrency);
PR_fprintf(debug_out, "\tThread type: %s\n",
- (PR_GLOBAL_THREAD == thread_scope) ? "GLOBAL" : "LOCAL");
+ (PR_GLOBAL_THREAD == thread_scope) ? "GLOBAL" : "LOCAL");
}
/*
@@ -181,7 +181,7 @@ int main(int argc, char **argv)
selfData.event = PR_NewPollableEvent();
if (selfData.event == NULL) {
PR_fprintf(PR_STDERR, "cannot create event: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
+ PR_GetError(), PR_GetOSError());
exit(1);
}
selfData.next = &data[0];
@@ -189,7 +189,7 @@ int main(int argc, char **argv)
data[i].event = PR_NewPollableEvent();
if (data[i].event == NULL) {
PR_fprintf(PR_STDERR, "cannot create event: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
+ PR_GetError(), PR_GetOSError());
exit(1);
}
data[i].index = i;
@@ -200,8 +200,8 @@ int main(int argc, char **argv)
}
thread[i] = PR_CreateThread(PR_USER_THREAD,
- ThreadRoutine, &data[i], PR_PRIORITY_NORMAL,
- thread_scope, PR_JOINABLE_THREAD, 0);
+ ThreadRoutine, &data[i], PR_PRIORITY_NORMAL,
+ thread_scope, PR_JOINABLE_THREAD, 0);
if (thread[i] == NULL) {
PR_fprintf(PR_STDERR, "cannot create thread\n");
exit(1);
@@ -232,7 +232,7 @@ int main(int argc, char **argv)
if (verbosity) {
PR_fprintf(debug_out, "main thread awakened\n");
}
- if (PR_WaitForPollableEvent(selfData.event) == PR_FAILURE) {
+ if (PR_WaitForPollableEvent(selfData.event) == PR_FAILURE) {
PR_fprintf(PR_STDERR, "consume event failed\n");
exit(1);
}
@@ -241,9 +241,9 @@ int main(int argc, char **argv)
if (debug_mode) {
average = PR_IntervalToMicroseconds(timeEnd - timeStart)
- / (numIterations * numThreads);
+ / (numIterations * numThreads);
PR_fprintf(debug_out, "Average switch times %d usecs for %d threads\n",
- average, numThreads);
+ average, numThreads);
}
for (i = 0; i < numThreads; i++) {
@@ -254,7 +254,7 @@ int main(int argc, char **argv)
PR_DestroyPollableEvent(data[i].event);
}
PR_DELETE(block);
- PR_DestroyPollableEvent(selfData.event);
+ PR_DestroyPollableEvent(selfData.event);
PR_fprintf(PR_STDOUT, "PASSED\n");
return 0;
diff --git a/pr/tests/prftest.c b/pr/tests/prftest.c
index ac49460a..091c990a 100644
--- a/pr/tests/prftest.c
+++ b/pr/tests/prftest.c
@@ -4,7 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
- * File: prftest.c
+ * File: prftest.c
* Description:
* This is a simple test of the PR_snprintf() function defined
* in prprf.c.
@@ -35,17 +35,17 @@ int main(int argc, char **argv)
PR_snprintf(buf, BUF_SIZE, "%hx %x %lx %llx", i16, n, i32, i64);
strcpy(answer, "ffff ");
for (i = PR_BYTES_PER_INT * 2; i; i--) {
- strcat(answer, "f");
+ strcat(answer, "f");
}
strcat(answer, " ffffffff ffffffffffffffff");
if (!strcmp(buf, answer)) {
- printf("PR_snprintf test 1 passed\n");
+ printf("PR_snprintf test 1 passed\n");
} else {
- printf("PR_snprintf test 1 failed\n");
- printf("Converted string is %s\n", buf);
- printf("Should be %s\n", answer);
- rv = 1;
+ printf("PR_snprintf test 1 failed\n");
+ printf("Converted string is %s\n", buf);
+ printf("Should be %s\n", answer);
+ rv = 1;
}
i16 = -32;
@@ -54,12 +54,12 @@ int main(int argc, char **argv)
LL_I2L(i64, 333);
PR_snprintf(buf, BUF_SIZE, "%d %hd %lld %ld", n, i16, i64, i32);
if (!strcmp(buf, "30 -32 333 64")) {
- printf("PR_snprintf test 2 passed\n");
+ printf("PR_snprintf test 2 passed\n");
} else {
- printf("PR_snprintf test 2 failed\n");
- printf("Converted string is %s\n", buf);
- printf("Should be 30 -32 333 64\n");
- rv = 1;
+ printf("PR_snprintf test 2 failed\n");
+ printf("Converted string is %s\n", buf);
+ printf("Should be 30 -32 333 64\n");
+ rv = 1;
}
return rv;
diff --git a/pr/tests/prftest1.c b/pr/tests/prftest1.c
index 83e7c103..5d6374a4 100644
--- a/pr/tests/prftest1.c
+++ b/pr/tests/prftest1.c
@@ -4,17 +4,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
-** File: prftest1.c
+** File: prftest1.c
** Description:
** This is a simple test of the PR_snprintf() function defined
** in prprf.c.
**
** Modification History:
** 14-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.
***********************************************************************/
/***********************************************************************
** Includes
@@ -34,7 +34,7 @@
/***********************************************************************
** PRIVATE FUNCTION: Test_Result
** DESCRIPTION: Used in conjunction with the regress tool, prints out the
-** status of the test case.
+** status of the test case.
** INPUTS: PASS/FAIL
** OUTPUTS: None
** RETURN: None
@@ -50,10 +50,12 @@
static void Test_Result (int result)
{
- if (result == PASS)
- printf ("PASS\n");
- else
- printf ("FAIL\n");
+ if (result == PASS) {
+ printf ("PASS\n");
+ }
+ else {
+ printf ("FAIL\n");
+ }
}
int main(int argc, char **argv)
@@ -66,29 +68,31 @@ int main(int argc, char **argv)
char answer[BUF_SIZE];
int i;
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
+ 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_mode = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- /* main test */
+ /* main test */
PR_STDIO_INIT();
i16 = -1;
@@ -99,21 +103,26 @@ int main(int argc, char **argv)
PR_snprintf(buf, BUF_SIZE, "%hx %x %lx %llx", i16, n, i32, i64);
strcpy(answer, "ffff ");
for (i = PR_BYTES_PER_INT * 2; i; i--) {
- strcat(answer, "f");
+ strcat(answer, "f");
}
strcat(answer, " ffffffff ffffffffffffffff");
if (!strcmp(buf, answer)) {
- if (debug_mode) printf("PR_snprintf test 1 passed\n");
- else Test_Result (PASS);
+ if (debug_mode) {
+ printf("PR_snprintf test 1 passed\n");
+ }
+ else {
+ Test_Result (PASS);
+ }
} else {
- if (debug_mode) {
- printf("PR_snprintf test 1 failed\n");
- printf("Converted string is %s\n", buf);
- printf("Should be %s\n", answer);
- }
- else
- Test_Result (FAIL);
+ if (debug_mode) {
+ printf("PR_snprintf test 1 failed\n");
+ printf("Converted string is %s\n", buf);
+ printf("Should be %s\n", answer);
+ }
+ else {
+ Test_Result (FAIL);
+ }
}
return 0;
diff --git a/pr/tests/prftest2.c b/pr/tests/prftest2.c
index 4ab7eb32..6376fd2f 100644
--- a/pr/tests/prftest2.c
+++ b/pr/tests/prftest2.c
@@ -4,19 +4,19 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
-** File: prftest2.c
+** File: prftest2.c
** Description:
** This is a simple test of the PR_snprintf() function defined
** in prprf.c.
**
** Modification History:
** 14-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.
***********************************************************************/
/***********************************************************************
** Includes
@@ -43,29 +43,31 @@ int main(int argc, char **argv)
PRInt64 i64;
char buf[BUF_SIZE];
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
+ 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_mode = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- /* main test */
+ /* main test */
PR_STDIO_INIT();
@@ -75,23 +77,27 @@ int main(int argc, char **argv)
LL_I2L(i64, 333);
PR_snprintf(buf, BUF_SIZE, "%d %hd %lld %ld", n, i16, i64, i32);
if (!strcmp(buf, "30 -32 333 64")) {
- if (debug_mode) printf("PR_snprintf test 2 passed\n");
+ if (debug_mode) {
+ printf("PR_snprintf test 2 passed\n");
+ }
} else {
- if (debug_mode) {
- printf("PR_snprintf test 2 failed\n");
- printf("Converted string is %s\n", buf);
- printf("Should be 30 -32 333 64\n");
- }
- else failed_already=1;
+ if (debug_mode) {
+ printf("PR_snprintf test 2 failed\n");
+ printf("Converted string is %s\n", buf);
+ printf("Should be 30 -32 333 64\n");
+ }
+ else {
+ failed_already=1;
+ }
}
- if(failed_already)
- {
+ if(failed_already)
+ {
printf("FAILED\n");
- return 1;
- }
- else
- {
+ return 1;
+ }
+ else
+ {
printf("PASSED\n");
- return 0;
- }
+ return 0;
+ }
}
diff --git a/pr/tests/primblok.c b/pr/tests/primblok.c
index e036572b..1182d3ed 100644
--- a/pr/tests/primblok.c
+++ b/pr/tests/primblok.c
@@ -79,8 +79,8 @@ int main(int argc, char **argv)
/* Must be a global thread */
iothread = PR_CreateThread(
- PR_USER_THREAD, IOThread, NULL, PR_PRIORITY_NORMAL,
- PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, IOThread, NULL, PR_PRIORITY_NORMAL,
+ PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
if (iothread == NULL) {
fprintf(stderr, "cannot create thread\n");
exit(1);
diff --git a/pr/tests/priotest.c b/pr/tests/priotest.c
index 577d5533..1e2249de 100644
--- a/pr/tests/priotest.c
+++ b/pr/tests/priotest.c
@@ -34,8 +34,9 @@ static PRBool debug_mode = PR_FALSE;
static PRUint32 PerSecond(PRIntervalTime timein)
{
PRUint32 loop = 0;
- while (((PRIntervalTime)(PR_IntervalNow()) - timein) < oneSecond)
+ while (((PRIntervalTime)(PR_IntervalNow()) - timein) < oneSecond) {
loop += 1;
+ }
return loop;
} /* PerSecond */
@@ -66,9 +67,9 @@ static void PR_CALLBACK High(void *arg)
static void Help(void)
{
PR_fprintf(
- debug_out, "Usage: priotest [-d] [-c n]\n");
+ debug_out, "Usage: priotest [-d] [-c n]\n");
PR_fprintf(
- debug_out, "-c n\tduration of test in seconds (default: %d)\n", DEFAULT_DURATION);
+ debug_out, "-c n\tduration of test in seconds (default: %d)\n", DEFAULT_DURATION);
PR_fprintf(
debug_out, "-d\tturn on debugging output (default: FALSE)\n");
} /* Help */
@@ -84,7 +85,7 @@ static void RudimentaryTests(void)
PR_SetThreadPriority(PR_GetCurrentThread(), PR_PRIORITY_URGENT);
priority = PR_GetThreadPriority(PR_GetCurrentThread());
failed = ((PR_TRUE == failed) || (PR_PRIORITY_URGENT != priority))
- ? PR_TRUE : PR_FALSE;
+ ? PR_TRUE : PR_FALSE;
if (debug_mode && (PR_PRIORITY_URGENT != priority))
{
PR_fprintf(debug_out, "PR_[S/G]etThreadPriority() failed\n");
@@ -95,7 +96,7 @@ static void RudimentaryTests(void)
PR_GetCurrentThread(), (PRThreadPriority)(PR_PRIORITY_FIRST - 1));
priority = PR_GetThreadPriority(PR_GetCurrentThread());
failed = ((PR_TRUE == failed) || (PR_PRIORITY_FIRST != priority))
- ? PR_TRUE : PR_FALSE;
+ ? PR_TRUE : PR_FALSE;
if (debug_mode && (PR_PRIORITY_FIRST != priority))
{
PR_fprintf(debug_out, "PR_SetThreadPriority(-1) failed\n");
@@ -105,7 +106,7 @@ static void RudimentaryTests(void)
PR_GetCurrentThread(), (PRThreadPriority)(PR_PRIORITY_LAST + 1));
priority = PR_GetThreadPriority(PR_GetCurrentThread());
failed = ((PR_TRUE == failed) || (PR_PRIORITY_LAST != priority))
- ? PR_TRUE : PR_FALSE;
+ ? PR_TRUE : PR_FALSE;
if (debug_mode && (PR_PRIORITY_LAST != priority))
{
PR_fprintf(debug_out, "PR_SetThreadPriority(+1) failed\n");
@@ -128,32 +129,36 @@ int main(int argc, char **argv)
PLOptStatus os;
PRIntn duration = DEFAULT_DURATION;
PRUint32 totalCount, highCount = 0, lowCount = 0;
- PLOptState *opt = PL_CreateOptState(argc, argv, "hdc:");
+ PLOptState *opt = PL_CreateOptState(argc, argv, "hdc:");
debug_out = PR_STDOUT;
oneSecond = PR_SecondsToInterval(1);
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ 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_mode = PR_TRUE;
- break;
- case 'c': /* test duration */
- duration = atoi(opt->value);
- break;
- case 'h': /* help message */
- default:
- Help();
- return 2;
+ case 'd': /* debug mode */
+ debug_mode = PR_TRUE;
+ break;
+ case 'c': /* test duration */
+ duration = atoi(opt->value);
+ break;
+ case 'h': /* help message */
+ default:
+ Help();
+ return 2;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
PR_STDIO_INIT();
- if (duration == 0) duration = DEFAULT_DURATION;
+ if (duration == 0) {
+ duration = DEFAULT_DURATION;
+ }
RudimentaryTests();
@@ -167,9 +172,9 @@ int main(int argc, char **argv)
if (debug_mode)
{
PR_fprintf(debug_out,
- "The high priority thread should get approximately three\n");
+ "The high priority thread should get approximately three\n");
PR_fprintf( debug_out,
- "times what the low priority thread manages. A maximum of \n");
+ "times what the low priority thread manages. A maximum of \n");
PR_fprintf( debug_out, "%d cycles are available.\n\n", totalCount);
}
@@ -178,16 +183,19 @@ int main(int argc, char **argv)
while (duration--)
{
PRIntn loop = 5;
- while (loop--) PR_Sleep(oneSecond);
- if (debug_mode)
+ while (loop--) {
+ PR_Sleep(oneSecond);
+ }
+ if (debug_mode) {
PR_fprintf(debug_out, "high : low :: %d : %d\n", highCount, lowCount);
+ }
}
PR_ProcessExit((failed) ? 1 : 0);
- PR_NOT_REACHED("You can't get here -- but you did!");
- return 1; /* or here */
+ PR_NOT_REACHED("You can't get here -- but you did!");
+ return 1; /* or here */
} /* main */
diff --git a/pr/tests/provider.c b/pr/tests/provider.c
index bb5dd329..1bd15fb6 100644
--- a/pr/tests/provider.c
+++ b/pr/tests/provider.c
@@ -184,7 +184,7 @@ static void _MY_Assert(const char *s, const char *file, PRIntn ln)
static PRBool Aborted(PRStatus rv)
{
return ((PR_FAILURE == rv) && (PR_PENDING_INTERRUPT_ERROR == PR_GetError())) ?
- PR_TRUE : PR_FALSE;
+ PR_TRUE : PR_FALSE;
}
static void TimeOfDayMessage(const char *msg, PRThread* me)
@@ -213,8 +213,9 @@ static void PR_CALLBACK Client(void *arg)
PRIntervalTime timeout = PR_MillisecondsToInterval(DEFAULT_CLIENT_TIMEOUT);
- for (index = 0; index < sizeof(buffer); ++index)
+ for (index = 0; index < sizeof(buffer); ++index) {
buffer[index] = (char)index;
+ }
client->started = PR_IntervalNow();
@@ -231,7 +232,7 @@ static void PR_CALLBACK Client(void *arg)
(void)PR_NetAddrToString(&client->serverAddress, buffer, sizeof(buffer));
TEST_LOG(cltsrv_log_file, TEST_LOG_INFO,
- ("\tClient(0x%p): connecting to server at %s\n", me, buffer));
+ ("\tClient(0x%p): connecting to server at %s\n", me, buffer));
fd = PR_Socket(domain, SOCK_STREAM, protocol);
TEST_ASSERT(NULL != fd);
@@ -253,10 +254,12 @@ static void PR_CALLBACK Client(void *arg)
cltsrv_log_file, TEST_LOG_VERBOSE,
("\tClient(0x%p): sending descriptor for %u bytes\n", me, descbytes));
bytes = PR_Send(
- fd, descriptor, sizeof(*descriptor), SEND_FLAGS, timeout);
+ fd, descriptor, sizeof(*descriptor), SEND_FLAGS, timeout);
if (sizeof(CSDescriptor_t) != bytes)
{
- if (Aborted(PR_FAILURE)) goto aborted;
+ if (Aborted(PR_FAILURE)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -271,15 +274,18 @@ static void PR_CALLBACK Client(void *arg)
while (netbytes < descbytes)
{
filebytes = sizeof(buffer);
- if ((descbytes - netbytes) < filebytes)
+ if ((descbytes - netbytes) < filebytes) {
filebytes = descbytes - netbytes;
+ }
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("\tClient(0x%p): sending %d bytes\n", me, filebytes));
bytes = PR_Send(fd, buffer, filebytes, SEND_FLAGS, timeout);
if (filebytes != bytes)
{
- if (Aborted(PR_FAILURE)) goto aborted;
+ if (Aborted(PR_FAILURE)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -295,8 +301,9 @@ static void PR_CALLBACK Client(void *arg)
while (filebytes < descbytes)
{
netbytes = sizeof(buffer);
- if ((descbytes - filebytes) < netbytes)
+ if ((descbytes - filebytes) < netbytes) {
netbytes = descbytes - filebytes;
+ }
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("\tClient(0x%p): receiving %d bytes\n", me, netbytes));
@@ -314,26 +321,28 @@ static void PR_CALLBACK Client(void *arg)
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
("\tClient(0x%p): receive data timeout\n", me));
- else
+ else
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
("\tClient(0x%p): receive error (%d, %d)\n",
- me, PR_GetError(), PR_GetOSError()));
+ me, PR_GetError(), PR_GetOSError()));
goto retry;
- }
+ }
if (0 == bytes)
{
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
("\t\tClient(0x%p): unexpected end of stream\n",
- PR_GetCurrentThread()));
+ PR_GetCurrentThread()));
break;
}
filebytes += bytes;
}
rv = PR_Shutdown(fd, PR_SHUTDOWN_BOTH);
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
TEST_ASSERT(PR_SUCCESS == rv);
retry:
(void)PR_Close(fd); fd = NULL;
@@ -346,14 +355,18 @@ retry:
client->bytesTransferred += 2 * descbytes;
rv = PR_WaitCondVar(client->stateChange, rand() % clipping);
PR_Unlock(client->ml);
- if (Aborted(rv)) break;
+ if (Aborted(rv)) {
+ break;
+ }
}
aborted:
client->stopped = PR_IntervalNow();
PR_ClearInterrupt();
- if (NULL != fd) rv = PR_Close(fd);
+ if (NULL != fd) {
+ rv = PR_Close(fd);
+ }
PR_Lock(client->ml);
client->state = cs_exit;
@@ -363,7 +376,7 @@ aborted:
TEST_LOG(
cltsrv_log_file, TEST_LOG_ALWAYS,
("\tClient(0x%p): stopped after %u operations and %u bytes\n",
- PR_GetCurrentThread(), client->operations, client->bytesTransferred));
+ PR_GetCurrentThread(), client->operations, client->bytesTransferred));
} /* Client */
@@ -381,11 +394,13 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
cltsrv_log_file, TEST_LOG_VERBOSE,
("\tProcessRequest(0x%p): receiving desciptor\n", me));
bytes = PR_Recv(
- fd, descriptor, sizeof(*descriptor), RECV_FLAGS, timeout);
+ fd, descriptor, sizeof(*descriptor), RECV_FLAGS, timeout);
if (-1 == bytes)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto exit;
+ if (Aborted(rv)) {
+ goto exit;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -408,14 +423,16 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("\t\tProcessRequest(0x%p): read descriptor {%d, %s}\n",
- me, descbytes, descriptor->filename));
+ me, descbytes, descriptor->filename));
file = PR_Open(
- descriptor->filename, (PR_CREATE_FILE | PR_WRONLY), 0666);
+ descriptor->filename, (PR_CREATE_FILE | PR_WRONLY), 0666);
if (NULL == file)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -430,8 +447,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
while (filebytes < descbytes)
{
netbytes = sizeof(buffer);
- if ((descbytes - filebytes) < netbytes)
+ if ((descbytes - filebytes) < netbytes) {
netbytes = descbytes - filebytes;
+ }
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("\tProcessRequest(0x%p): receive %d bytes\n", me, netbytes));
@@ -439,7 +457,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
if (-1 == bytes)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -455,7 +475,7 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
TEST_LOG(
cltsrv_log_file, TEST_LOG_WARNING,
("\t\tProcessRequest(0x%p): unexpected error (%d, %d)\n",
- me, PR_GetError(), PR_GetOSError()));
+ me, PR_GetError(), PR_GetOSError()));
goto aborted;
}
if(0 == bytes)
@@ -477,7 +497,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
if (netbytes != bytes)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -495,7 +517,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
PR_Unlock(server->ml);
rv = PR_Close(file); file = NULL;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
TEST_ASSERT(PR_SUCCESS == rv);
TEST_LOG(
@@ -505,19 +529,21 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
if (NULL == file)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
("\t\tProcessRequest(0x%p): open file timeout\n",
- PR_GetCurrentThread()));
+ PR_GetCurrentThread()));
goto aborted;
}
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
("\t\tProcessRequest(0x%p): other file open error (%u, %u)\n",
- me, PR_GetError(), PR_GetOSError()));
+ me, PR_GetError(), PR_GetOSError()));
goto aborted;
}
TEST_ASSERT(NULL != file);
@@ -526,8 +552,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
while (netbytes < descbytes)
{
filebytes = sizeof(buffer);
- if ((descbytes - netbytes) < filebytes)
+ if ((descbytes - netbytes) < filebytes) {
filebytes = descbytes - netbytes;
+ }
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("\tProcessRequest(0x%p): read %d bytes from file\n", me, filebytes));
@@ -535,7 +562,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
if (filebytes != bytes)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
@@ -544,7 +573,7 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
TEST_LOG(
cltsrv_log_file, TEST_LOG_ERROR,
("\t\tProcessRequest(0x%p): other file error (%d, %d)\n",
- me, PR_GetError(), PR_GetOSError()));
+ me, PR_GetError(), PR_GetOSError()));
goto aborted;
}
TEST_ASSERT(bytes > 0);
@@ -557,7 +586,9 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
if (filebytes != bytes)
{
rv = PR_FAILURE;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
if (PR_IO_TIMEOUT_ERROR == PR_GetError())
{
TEST_LOG(
@@ -567,7 +598,7 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
}
break;
}
- TEST_ASSERT(bytes > 0);
+ TEST_ASSERT(bytes > 0);
}
PR_Lock(server->ml);
@@ -575,15 +606,21 @@ static PRStatus ProcessRequest(PRFileDesc *fd, CSServer_t *server)
PR_Unlock(server->ml);
rv = PR_Shutdown(fd, PR_SHUTDOWN_BOTH);
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
rv = PR_Close(file); file = NULL;
- if (Aborted(rv)) goto aborted;
+ if (Aborted(rv)) {
+ goto aborted;
+ }
TEST_ASSERT(PR_SUCCESS == rv);
aborted:
PR_ClearInterrupt();
- if (NULL != file) PR_Close(file);
+ if (NULL != file) {
+ PR_Close(file);
+ }
drv = PR_Delete(descriptor->filename);
TEST_ASSERT(PR_SUCCESS == drv);
exit:
@@ -640,22 +677,22 @@ static PRStatus JoinThread(PRThread *thread)
PRStatus rv;
switch (thread_provider)
{
- case thread_nspr:
- rv = PR_JoinThread(thread);
- break;
- case thread_pthread:
+ case thread_nspr:
+ rv = PR_JoinThread(thread);
+ break;
+ case thread_pthread:
#if defined(_PR_PTHREADS)
- rv = PR_SUCCESS;
- break;
+ rv = PR_SUCCESS;
+ break;
#endif /* defined(_PR_PTHREADS) */
- case thread_win32:
+ case thread_win32:
#if defined(WIN32)
- rv = PR_SUCCESS;
- break;
+ rv = PR_SUCCESS;
+ break;
#endif
- default:
- rv = PR_FAILURE;
- break;
+ default:
+ rv = PR_FAILURE;
+ break;
}
return rv;
} /* JoinThread */
@@ -667,16 +704,16 @@ static PRStatus NewThread(
switch (thread_provider)
{
- case thread_nspr:
+ case thread_nspr:
{
PRThread *thread = PR_CreateThread(
- PR_USER_THREAD, start, arg,
- PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
- PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, start, arg,
+ PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
+ PR_JOINABLE_THREAD, 0);
rv = (NULL == thread) ? PR_FAILURE : PR_SUCCESS;
}
break;
- case thread_pthread:
+ case thread_pthread:
#if defined(_PR_PTHREADS)
{
int rv;
@@ -707,11 +744,11 @@ static PRStatus NewThread(
#endif /* defined(_PR_PTHREADS) */
break;
- case thread_sproc:
- PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
- rv = PR_FAILURE;
- break;
- case thread_win32:
+ case thread_sproc:
+ PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+ rv = PR_FAILURE;
+ break;
+ case thread_win32:
#if defined(WIN32)
{
void *th;
@@ -722,12 +759,12 @@ static PRStatus NewThread(
start_object->start = start;
start_object->arg = arg;
th = (void*)_beginthreadex(
- NULL, /* LPSECURITY_ATTRIBUTES - pointer to thread security attributes */
- 0U, /* DWORD - initial thread stack size, in bytes */
- windows_start, /* LPTHREAD_START_ROUTINE - pointer to thread function */
- start_object, /* LPVOID - argument for new thread */
- STACK_SIZE_PARAM_IS_A_RESERVATION, /*DWORD dwCreationFlags - creation flags */
- &id /* LPDWORD - pointer to returned thread identifier */ );
+ NULL, /* LPSECURITY_ATTRIBUTES - pointer to thread security attributes */
+ 0U, /* DWORD - initial thread stack size, in bytes */
+ windows_start, /* LPTHREAD_START_ROUTINE - pointer to thread function */
+ start_object, /* LPVOID - argument for new thread */
+ STACK_SIZE_PARAM_IS_A_RESERVATION, /*DWORD dwCreationFlags - creation flags */
+ &id /* LPDWORD - pointer to returned thread identifier */ );
rv = (NULL == th) ? PR_FAILURE : PR_SUCCESS;
}
@@ -736,9 +773,9 @@ static PRStatus NewThread(
rv = PR_FAILURE;
#endif
break;
- default:
- PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
- rv = PR_FAILURE;
+ default:
+ PR_SetError(PR_NOT_IMPLEMENTED_ERROR, 0);
+ rv = PR_FAILURE;
}
return rv;
} /* NewThread */
@@ -750,12 +787,14 @@ static PRStatus CreateWorker(CSServer_t *server, CSPool_t *pool)
worker->server = server;
PR_INIT_CLIST(&worker->element);
rv = NewThread(
- Worker, worker, DEFAULT_SERVER_PRIORITY, PR_UNJOINABLE_THREAD);
- if (PR_FAILURE == rv) PR_DELETE(worker);
+ Worker, worker, DEFAULT_SERVER_PRIORITY, PR_UNJOINABLE_THREAD);
+ if (PR_FAILURE == rv) {
+ PR_DELETE(worker);
+ }
TEST_LOG(cltsrv_log_file, TEST_LOG_STATUS,
- ("\tCreateWorker(0x%p): create new worker (0x%p)\n",
- PR_GetCurrentThread(), worker->thread));
+ ("\tCreateWorker(0x%p): create new worker (0x%p)\n",
+ PR_GetCurrentThread(), worker->thread));
return rv;
} /* CreateWorker */
@@ -786,14 +825,14 @@ static void PR_CALLBACK Worker(void *arg)
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("\t\tWorker(0x%p): waiting for accept slot[%d]\n",
- me, pool->accepting));
+ me, pool->accepting));
rv = PR_WaitCondVar(pool->acceptComplete, PR_INTERVAL_NO_TIMEOUT);
if (Aborted(rv) || (cs_run != server->state))
{
TEST_LOG(
cltsrv_log_file, TEST_LOG_NOTICE,
("\tWorker(0x%p): has been %s\n",
- me, (Aborted(rv) ? "interrupted" : "stopped")));
+ me, (Aborted(rv) ? "interrupted" : "stopped")));
goto exit;
}
}
@@ -831,13 +870,15 @@ static void PR_CALLBACK Worker(void *arg)
*/
PRBool another =
((pool->workers < server->workers.minimum) ||
- ((0 == pool->accepting)
- && (pool->workers < server->workers.maximum))) ?
- PR_TRUE : PR_FALSE;
+ ((0 == pool->accepting)
+ && (pool->workers < server->workers.maximum))) ?
+ PR_TRUE : PR_FALSE;
pool->active += 1;
PR_Unlock(server->ml);
- if (another) (void)CreateWorker(server, pool);
+ if (another) {
+ (void)CreateWorker(server, pool);
+ }
rv = ProcessRequest(fd, server);
if (PR_SUCCESS != rv)
@@ -963,7 +1004,7 @@ static void PR_CALLBACK Server(void *arg)
TEST_LOG(
cltsrv_log_file, TEST_LOG_NOTICE,
("\tServer(0x%p): waiting for %u workers to exit\n",
- me, server->pool.workers));
+ me, server->pool.workers));
(void)PR_WaitCondVar(server->pool.exiting, PR_INTERVAL_NO_TIMEOUT);
}
@@ -974,9 +1015,11 @@ static void PR_CALLBACK Server(void *arg)
TEST_LOG(
cltsrv_log_file, TEST_LOG_ALWAYS,
("\tServer(0x%p): stopped after %u operations and %u bytes\n",
- me, server->operations, server->bytesTransferred));
+ me, server->operations, server->bytesTransferred));
- if (NULL != server->listener) PR_Close(server->listener);
+ if (NULL != server->listener) {
+ PR_Close(server->listener);
+ }
server->stopped = PR_IntervalNow();
} /* Server */
@@ -987,7 +1030,9 @@ static void WaitForCompletion(PRIntn execution)
{
PRIntn dally = (execution > 30) ? 30 : execution;
PR_Sleep(PR_SecondsToInterval(dally));
- if (pthread_stats) PT_FPrintStats(debug_out, "\nPThread Statistics\n");
+ if (pthread_stats) {
+ PT_FPrintStats(debug_out, "\nPThread Statistics\n");
+ }
execution -= dally;
}
} /* WaitForCompletion */
@@ -1025,7 +1070,7 @@ int main(int argc, char **argv)
CSClient_t *client;
PRStatus rv, joinStatus;
CSServer_t *server = NULL;
- char *thread_type;
+ char *thread_type;
PRUintn backlog = DEFAULT_BACKLOG;
PRUintn clients = DEFAULT_CLIENTS;
@@ -1052,9 +1097,9 @@ int main(int argc, char **argv)
PLOptState *opt = PL_CreateOptState(argc, argv, "GX6b:a:c:w:W:e:s:T:vdhp");
#if defined(WIN32)
- thread_provider = thread_win32;
+ thread_provider = thread_win32;
#elif defined(_PR_PTHREADS)
- thread_provider = thread_pthread;
+ thread_provider = thread_pthread;
#else
thread_provider = thread_nspr;
#endif
@@ -1063,70 +1108,95 @@ int main(int argc, char **argv)
while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
- if (PL_OPT_BAD == os) continue;
+ if (PL_OPT_BAD == os) {
+ continue;
+ }
switch (opt->option)
{
- case 'G': /* use global threads */
- thread_scope = PR_GLOBAL_THREAD;
- break;
- case 'X': /* use XTP as transport */
- protocol = 36;
- break;
- case '6': /* Use IPv6 */
- domain = PR_AF_INET6;
- break;
- case 'a': /* the value for accepting */
- accepting = atoi(opt->value);
- break;
- case 'b': /* the value for backlock */
- backlog = atoi(opt->value);
- break;
- case 'T': /* the thread provider */
- if ('n' == *opt->value) thread_provider = thread_nspr;
- else if ('p' == *opt->value) thread_provider = thread_pthread;
- else if ('w' == *opt->value) thread_provider = thread_win32;
- else {Help(); return 2; }
- break;
- case 'c': /* number of client threads */
- clients = atoi(opt->value);
- break;
- case 'w': /* minimum server worker threads */
- workersMin = atoi(opt->value);
- break;
- case 'W': /* maximum server worker threads */
- workersMax = atoi(opt->value);
- break;
- case 'e': /* program execution time in seconds */
- execution = atoi(opt->value);
- break;
- case 's': /* server's address */
- serverName = opt->value;
- break;
- case 'v': /* verbosity */
- verbosity = IncrementVerbosity();
- break;
- case 'd': /* debug mode */
- debug_mode = PR_TRUE;
- break;
- case 'p': /* pthread mode */
- pthread_stats = PR_TRUE;
- break;
- case 'h':
- default:
- Help();
- return 2;
+ case 'G': /* use global threads */
+ thread_scope = PR_GLOBAL_THREAD;
+ break;
+ case 'X': /* use XTP as transport */
+ protocol = 36;
+ break;
+ case '6': /* Use IPv6 */
+ domain = PR_AF_INET6;
+ break;
+ case 'a': /* the value for accepting */
+ accepting = atoi(opt->value);
+ break;
+ case 'b': /* the value for backlock */
+ backlog = atoi(opt->value);
+ break;
+ case 'T': /* the thread provider */
+ if ('n' == *opt->value) {
+ thread_provider = thread_nspr;
+ }
+ else if ('p' == *opt->value) {
+ thread_provider = thread_pthread;
+ }
+ else if ('w' == *opt->value) {
+ thread_provider = thread_win32;
+ }
+ else {
+ Help();
+ return 2;
+ }
+ break;
+ case 'c': /* number of client threads */
+ clients = atoi(opt->value);
+ break;
+ case 'w': /* minimum server worker threads */
+ workersMin = atoi(opt->value);
+ break;
+ case 'W': /* maximum server worker threads */
+ workersMax = atoi(opt->value);
+ break;
+ case 'e': /* program execution time in seconds */
+ execution = atoi(opt->value);
+ break;
+ case 's': /* server's address */
+ serverName = opt->value;
+ break;
+ case 'v': /* verbosity */
+ verbosity = IncrementVerbosity();
+ break;
+ case 'd': /* debug mode */
+ debug_mode = PR_TRUE;
+ break;
+ case 'p': /* pthread mode */
+ pthread_stats = PR_TRUE;
+ break;
+ case 'h':
+ default:
+ Help();
+ return 2;
}
}
PL_DestroyOptState(opt);
- if (0 != PL_strcmp(serverName, DEFAULT_SERVER)) serverIsLocal = PR_FALSE;
- if (0 == execution) execution = DEFAULT_EXECUTION_TIME;
- if (0 == workersMax) workersMax = DEFAULT_WORKERS_MAX;
- if (0 == workersMin) workersMin = DEFAULT_WORKERS_MIN;
- if (0 == accepting) accepting = ALLOWED_IN_ACCEPT;
- if (0 == backlog) backlog = DEFAULT_BACKLOG;
+ if (0 != PL_strcmp(serverName, DEFAULT_SERVER)) {
+ serverIsLocal = PR_FALSE;
+ }
+ if (0 == execution) {
+ execution = DEFAULT_EXECUTION_TIME;
+ }
+ if (0 == workersMax) {
+ workersMax = DEFAULT_WORKERS_MAX;
+ }
+ if (0 == workersMin) {
+ workersMin = DEFAULT_WORKERS_MIN;
+ }
+ if (0 == accepting) {
+ accepting = ALLOWED_IN_ACCEPT;
+ }
+ if (0 == backlog) {
+ backlog = DEFAULT_BACKLOG;
+ }
- if (workersMin > accepting) accepting = workersMin;
+ if (workersMin > accepting) {
+ accepting = workersMin;
+ }
PR_STDIO_INIT();
TimeOfDayMessage("Client/Server started at", PR_GetCurrentThread());
@@ -1161,7 +1231,7 @@ int main(int argc, char **argv)
("main(0x%p): creating server thread\n", PR_GetCurrentThread()));
rv = NewThread(
- Server, server, PR_PRIORITY_HIGH, PR_JOINABLE_THREAD);
+ Server, server, PR_PRIORITY_HIGH, PR_JOINABLE_THREAD);
TEST_ASSERT(PR_SUCCESS == rv);
TEST_LOG(
@@ -1169,14 +1239,15 @@ int main(int argc, char **argv)
("main(0x%p): waiting for server init\n", PR_GetCurrentThread()));
PR_Lock(server->ml);
- while (server->state == cs_init)
+ while (server->state == cs_init) {
PR_WaitCondVar(server->stateChange, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_Unlock(server->ml);
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("main(0x%p): server init complete (port #%d)\n",
- PR_GetCurrentThread(), server->port));
+ PR_GetCurrentThread(), server->port));
}
if (clients != 0)
@@ -1189,7 +1260,7 @@ int main(int argc, char **argv)
TEST_LOG(
cltsrv_log_file, TEST_LOG_VERBOSE,
("main(0x%p): creating %d client threads\n",
- PR_GetCurrentThread(), clients));
+ PR_GetCurrentThread(), clients));
if (!serverIsLocal)
{
@@ -1221,11 +1292,12 @@ int main(int argc, char **argv)
cltsrv_log_file, TEST_LOG_INFO,
("main(0x%p): creating client threads\n", PR_GetCurrentThread()));
rv = NewThread(
- Client, &client[index], PR_PRIORITY_NORMAL, PR_JOINABLE_THREAD);
+ Client, &client[index], PR_PRIORITY_NORMAL, PR_JOINABLE_THREAD);
TEST_ASSERT(PR_SUCCESS == rv);
PR_Lock(client[index].ml);
- while (cs_init == client[index].state)
+ while (cs_init == client[index].state) {
PR_WaitCondVar(client[index].stateChange, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_Unlock(client[index].ml);
}
}
@@ -1234,7 +1306,7 @@ int main(int argc, char **argv)
TEST_LOG(
cltsrv_log_file, TEST_LOG_ALWAYS,
("main(0x%p): waiting for execution interval (%d seconds)\n",
- PR_GetCurrentThread(), execution));
+ PR_GetCurrentThread(), execution));
WaitForCompletion(execution);
@@ -1245,8 +1317,8 @@ int main(int argc, char **argv)
for (index = 0; index < clients; ++index)
{
TEST_LOG(cltsrv_log_file, TEST_LOG_STATUS,
- ("main(0x%p): notifying client(0x%p) to stop\n",
- PR_GetCurrentThread(), client[index].thread));
+ ("main(0x%p): notifying client(0x%p) to stop\n",
+ PR_GetCurrentThread(), client[index].thread));
PR_Lock(client[index].ml);
if (cs_run == client[index].state)
@@ -1260,11 +1332,11 @@ int main(int argc, char **argv)
PR_Unlock(client[index].ml);
TEST_LOG(cltsrv_log_file, TEST_LOG_VERBOSE,
- ("main(0x%p): joining client(0x%p)\n",
- PR_GetCurrentThread(), client[index].thread));
+ ("main(0x%p): joining client(0x%p)\n",
+ PR_GetCurrentThread(), client[index].thread));
- joinStatus = JoinThread(client[index].thread);
- TEST_ASSERT(PR_SUCCESS == joinStatus);
+ joinStatus = JoinThread(client[index].thread);
+ TEST_ASSERT(PR_SUCCESS == joinStatus);
PR_DestroyCondVar(client[index].stateChange);
PR_DestroyLock(client[index].ml);
}
@@ -1277,19 +1349,20 @@ int main(int argc, char **argv)
TEST_LOG(
cltsrv_log_file, TEST_LOG_NOTICE,
("main(0x%p): notifying server(0x%p) to stop\n",
- PR_GetCurrentThread(), server->thread));
+ PR_GetCurrentThread(), server->thread));
PR_Lock(server->ml);
server->state = cs_stop;
PR_Interrupt(server->thread);
- while (cs_exit != server->state)
+ while (cs_exit != server->state) {
PR_WaitCondVar(server->stateChange, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_Unlock(server->ml);
TEST_LOG(
cltsrv_log_file, TEST_LOG_NOTICE,
("main(0x%p): joining server(0x%p)\n",
- PR_GetCurrentThread(), server->thread));
+ PR_GetCurrentThread(), server->thread));
joinStatus = JoinThread(server->thread);
TEST_ASSERT(PR_SUCCESS == joinStatus);
@@ -1304,16 +1377,19 @@ int main(int argc, char **argv)
cltsrv_log_file, TEST_LOG_ALWAYS,
("main(0x%p): test complete\n", PR_GetCurrentThread()));
- if (thread_provider == thread_win32)
- thread_type = "\nWin32 Thread Statistics\n";
- else if (thread_provider == thread_pthread)
- thread_type = "\npthread Statistics\n";
- else if (thread_provider == thread_sproc)
- thread_type = "\nsproc Statistics\n";
+ if (thread_provider == thread_win32) {
+ thread_type = "\nWin32 Thread Statistics\n";
+ }
+ else if (thread_provider == thread_pthread) {
+ thread_type = "\npthread Statistics\n";
+ }
+ else if (thread_provider == thread_sproc) {
+ thread_type = "\nsproc Statistics\n";
+ }
else {
- PR_ASSERT(thread_provider == thread_nspr);
- thread_type = "\nPRThread Statistics\nn";
- }
+ PR_ASSERT(thread_provider == thread_nspr);
+ thread_type = "\nPRThread Statistics\nn";
+ }
PT_FPrintStats(debug_out, thread_type);
diff --git a/pr/tests/prpoll.c b/pr/tests/prpoll.c
index d2c87081..5c87a57d 100644
--- a/pr/tests/prpoll.c
+++ b/pr/tests/prpoll.c
@@ -19,8 +19,8 @@
#include "private/pprio.h"
-#define CLIENT_LOOPS 5
-#define BUF_SIZE 128
+#define CLIENT_LOOPS 5
+#define BUF_SIZE 128
#include <stdio.h>
#include <string.h>
@@ -51,11 +51,11 @@ clientThreadFunc(void *arg)
PR_snprintf(buf, sizeof(buf), "%hu", port);
for (i = 0; i < 5; i++) {
- sock = PR_NewTCPSocket();
+ sock = PR_NewTCPSocket();
PR_Connect(sock, &addr, PR_INTERVAL_NO_TIMEOUT);
- PR_Write(sock, buf, sizeof(buf));
- PR_Close(sock);
+ PR_Write(sock, buf, sizeof(buf));
+ PR_Close(sock);
}
}
@@ -86,100 +86,100 @@ int main(int argc, char **argv)
/* Create two listening sockets */
if ((listenSock1 = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr, "Can't create a new TCP socket\n");
- exit(1);
+ fprintf(stderr, "Can't create a new TCP socket\n");
+ exit(1);
}
addr.inet.family = PR_AF_INET;
addr.inet.ip = PR_htonl(PR_INADDR_ANY);
addr.inet.port = PR_htons(0);
if (PR_Bind(listenSock1, &addr) == PR_FAILURE) {
- fprintf(stderr, "Can't bind socket\n");
- exit(1);
+ fprintf(stderr, "Can't bind socket\n");
+ exit(1);
}
if (PR_GetSockName(listenSock1, &addr) == PR_FAILURE) {
- fprintf(stderr, "PR_GetSockName failed\n");
- exit(1);
+ fprintf(stderr, "PR_GetSockName failed\n");
+ exit(1);
}
listenPort1 = PR_ntohs(addr.inet.port);
if (PR_Listen(listenSock1, 5) == PR_FAILURE) {
- fprintf(stderr, "Can't listen on a socket\n");
- exit(1);
+ fprintf(stderr, "Can't listen on a socket\n");
+ exit(1);
}
if ((listenSock2 = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr, "Can't create a new TCP socket\n");
- exit(1);
+ fprintf(stderr, "Can't create a new TCP socket\n");
+ exit(1);
}
addr.inet.family = PR_AF_INET;
addr.inet.ip = PR_htonl(PR_INADDR_ANY);
addr.inet.port = PR_htons(0);
if (PR_Bind(listenSock2, &addr) == PR_FAILURE) {
- fprintf(stderr, "Can't bind socket\n");
- exit(1);
+ fprintf(stderr, "Can't bind socket\n");
+ exit(1);
}
if (PR_GetSockName(listenSock2, &addr) == PR_FAILURE) {
- fprintf(stderr, "PR_GetSockName failed\n");
- exit(1);
+ fprintf(stderr, "PR_GetSockName failed\n");
+ exit(1);
}
listenPort2 = PR_ntohs(addr.inet.port);
if (PR_Listen(listenSock2, 5) == PR_FAILURE) {
- fprintf(stderr, "Can't listen on a socket\n");
- exit(1);
+ fprintf(stderr, "Can't listen on a socket\n");
+ exit(1);
}
/* Set up the poll descriptor array */
pds = pds0;
other_pds = pds1;
memset(pds, 0, sizeof(pds));
- npds = 0;
+ npds = 0;
pds[npds].fd = listenSock1;
pds[npds].in_flags = PR_POLL_READ;
- npds++;
+ npds++;
pds[npds].fd = listenSock2;
pds[npds].in_flags = PR_POLL_READ;
- npds++;
-
- sd = socket(AF_INET, SOCK_STREAM, 0);
- PR_ASSERT(sd >= 0);
- memset((char *) &saddr, 0, sizeof(saddr));
- saddr.sin_family = AF_INET;
- saddr.sin_addr.s_addr = htonl(INADDR_ANY);
- saddr.sin_port = htons(0);
-
- rv = bind(sd, (struct sockaddr *)&saddr, sizeof(saddr));
- PR_ASSERT(rv == 0);
- saddr_len = sizeof(saddr);
- rv = getsockname(sd, (struct sockaddr *) &saddr, &saddr_len);
- PR_ASSERT(rv == 0);
+ npds++;
+
+ sd = socket(AF_INET, SOCK_STREAM, 0);
+ PR_ASSERT(sd >= 0);
+ memset((char *) &saddr, 0, sizeof(saddr));
+ saddr.sin_family = AF_INET;
+ saddr.sin_addr.s_addr = htonl(INADDR_ANY);
+ saddr.sin_port = htons(0);
+
+ rv = bind(sd, (struct sockaddr *)&saddr, sizeof(saddr));
+ PR_ASSERT(rv == 0);
+ saddr_len = sizeof(saddr);
+ rv = getsockname(sd, (struct sockaddr *) &saddr, &saddr_len);
+ PR_ASSERT(rv == 0);
listenPort3 = ntohs(saddr.sin_port);
- rv = listen(sd, 5);
- PR_ASSERT(rv == 0);
+ rv = listen(sd, 5);
+ PR_ASSERT(rv == 0);
pds[npds].fd = socket_poll_fd = PR_CreateSocketPollFd(sd);
- PR_ASSERT(pds[npds].fd);
+ PR_ASSERT(pds[npds].fd);
pds[npds].in_flags = PR_POLL_READ;
npds++;
PR_snprintf(buf, sizeof(buf),
- "The server thread is listening on ports %hu, %hu and %hu\n\n",
- listenPort1, listenPort2, listenPort3);
+ "The server thread is listening on ports %hu, %hu and %hu\n\n",
+ listenPort1, listenPort2, listenPort3);
printf("%s", buf);
/* Testing timeout */
printf("PR_Poll should time out in 5 seconds\n");
retVal = PR_Poll(pds, npds, PR_SecondsToInterval(5));
if (retVal != 0) {
- PR_snprintf(buf, sizeof(buf),
- "PR_Poll should time out and return 0, but it returns %ld\n",
- retVal);
- fprintf(stderr, "%s", buf);
- exit(1);
+ PR_snprintf(buf, sizeof(buf),
+ "PR_Poll should time out and return 0, but it returns %ld\n",
+ retVal);
+ fprintf(stderr, "%s", buf);
+ exit(1);
}
printf("PR_Poll timed out. Test passed.\n\n");
/* Testing bad fd */
printf("PR_Poll should detect a bad file descriptor\n");
if ((badFD = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr, "Can't create a TCP socket\n");
- exit(1);
+ fprintf(stderr, "Can't create a TCP socket\n");
+ exit(1);
}
pds[npds].fd = badFD;
@@ -189,40 +189,40 @@ int main(int argc, char **argv)
#if 0
retVal = PR_Poll(pds, npds, PR_INTERVAL_NO_TIMEOUT);
if (retVal != 1 || (unsigned short) pds[2].out_flags != PR_POLL_NVAL) {
- fprintf(stderr, "Failed to detect the bad fd: "
- "PR_Poll returns %d, out_flags is 0x%hx\n",
- retVal, pds[npds - 1].out_flags);
- exit(1);
+ fprintf(stderr, "Failed to detect the bad fd: "
+ "PR_Poll returns %d, out_flags is 0x%hx\n",
+ retVal, pds[npds - 1].out_flags);
+ exit(1);
}
printf("PR_Poll detected the bad fd. Test passed.\n\n");
#endif
npds--;
clientThread = PR_CreateThread(PR_USER_THREAD,
- clientThreadFunc, (void *) listenPort1,
- PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
- PR_UNJOINABLE_THREAD, 0);
+ clientThreadFunc, (void *) listenPort1,
+ PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
+ PR_UNJOINABLE_THREAD, 0);
if (clientThread == NULL) {
- fprintf(stderr, "can't create thread\n");
- exit(1);
+ fprintf(stderr, "can't create thread\n");
+ exit(1);
}
clientThread = PR_CreateThread(PR_USER_THREAD,
- clientThreadFunc, (void *) listenPort2,
- PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
- PR_UNJOINABLE_THREAD, 0);
+ clientThreadFunc, (void *) listenPort2,
+ PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
+ PR_UNJOINABLE_THREAD, 0);
if (clientThread == NULL) {
- fprintf(stderr, "can't create thread\n");
- exit(1);
+ fprintf(stderr, "can't create thread\n");
+ exit(1);
}
clientThread = PR_CreateThread(PR_USER_THREAD,
- clientThreadFunc, (void *) listenPort3,
- PR_PRIORITY_NORMAL, PR_GLOBAL_BOUND_THREAD,
- PR_UNJOINABLE_THREAD, 0);
+ clientThreadFunc, (void *) listenPort3,
+ PR_PRIORITY_NORMAL, PR_GLOBAL_BOUND_THREAD,
+ PR_UNJOINABLE_THREAD, 0);
if (clientThread == NULL) {
- fprintf(stderr, "can't create thread\n");
- exit(1);
+ fprintf(stderr, "can't create thread\n");
+ exit(1);
}
@@ -235,110 +235,110 @@ int main(int argc, char **argv)
/* 30 events total */
i = 0;
while (i < 30) {
- PRPollDesc *tmp;
- int nextIndex;
- int nEvents = 0;
-
- retVal = PR_Poll(pds, npds, PR_INTERVAL_NO_TIMEOUT);
- PR_ASSERT(retVal != 0); /* no timeout */
- if (retVal == -1) {
- fprintf(stderr, "PR_Poll failed\n");
- exit(1);
- }
-
- nextIndex = 3;
- /* the three listening sockets */
- for (j = 0; j < 3; j++) {
- other_pds[j] = pds[j];
- PR_ASSERT((pds[j].out_flags & PR_POLL_WRITE) == 0
- && (pds[j].out_flags & PR_POLL_EXCEPT) == 0);
- if (pds[j].out_flags & PR_POLL_READ) {
- PRFileDesc *sock;
-
- nEvents++;
- if (j == 2) {
- PROsfd newsd;
- newsd = accept(PR_FileDesc2NativeHandle(pds[j].fd), NULL, 0);
- if (newsd == -1) {
- fprintf(stderr, "accept() failed\n");
- exit(1);
- }
- other_pds[nextIndex].fd = PR_CreateSocketPollFd(newsd);
- PR_ASSERT(other_pds[nextIndex].fd);
- other_pds[nextIndex].in_flags = PR_POLL_READ;
- } else {
- sock = PR_Accept(pds[j].fd, NULL, PR_INTERVAL_NO_TIMEOUT);
- if (sock == NULL) {
- fprintf(stderr, "PR_Accept() failed\n");
- exit(1);
- }
- other_pds[nextIndex].fd = sock;
- other_pds[nextIndex].in_flags = PR_POLL_READ;
- }
- nextIndex++;
- } else if (pds[j].out_flags & PR_POLL_ERR) {
- fprintf(stderr, "PR_Poll() indicates that an fd has error\n");
- exit(1);
- } else if (pds[j].out_flags & PR_POLL_NVAL) {
- fprintf(stderr, "PR_Poll() indicates that fd %d is invalid\n",
- PR_FileDesc2NativeHandle(pds[j].fd));
- exit(1);
- }
- }
-
- for (j = 3; j < npds; j++) {
- PR_ASSERT((pds[j].out_flags & PR_POLL_WRITE) == 0
- && (pds[j].out_flags & PR_POLL_EXCEPT) == 0);
- if (pds[j].out_flags & PR_POLL_READ) {
- PRInt32 nBytes;
-
- nEvents++;
- /* XXX: This call is a hack and should be fixed */
- if (PR_GetDescType(pds[j].fd) == (PRDescType) 0) {
- nBytes = recv(PR_FileDesc2NativeHandle(pds[j].fd), buf,
- sizeof(buf), 0);
- if (nBytes == -1) {
- fprintf(stderr, "recv() failed\n");
- exit(1);
- }
- printf("Server read %d bytes from native fd %d\n",nBytes,
- PR_FileDesc2NativeHandle(pds[j].fd));
+ PRPollDesc *tmp;
+ int nextIndex;
+ int nEvents = 0;
+
+ retVal = PR_Poll(pds, npds, PR_INTERVAL_NO_TIMEOUT);
+ PR_ASSERT(retVal != 0); /* no timeout */
+ if (retVal == -1) {
+ fprintf(stderr, "PR_Poll failed\n");
+ exit(1);
+ }
+
+ nextIndex = 3;
+ /* the three listening sockets */
+ for (j = 0; j < 3; j++) {
+ other_pds[j] = pds[j];
+ PR_ASSERT((pds[j].out_flags & PR_POLL_WRITE) == 0
+ && (pds[j].out_flags & PR_POLL_EXCEPT) == 0);
+ if (pds[j].out_flags & PR_POLL_READ) {
+ PRFileDesc *sock;
+
+ nEvents++;
+ if (j == 2) {
+ PROsfd newsd;
+ newsd = accept(PR_FileDesc2NativeHandle(pds[j].fd), NULL, 0);
+ if (newsd == -1) {
+ fprintf(stderr, "accept() failed\n");
+ exit(1);
+ }
+ other_pds[nextIndex].fd = PR_CreateSocketPollFd(newsd);
+ PR_ASSERT(other_pds[nextIndex].fd);
+ other_pds[nextIndex].in_flags = PR_POLL_READ;
+ } else {
+ sock = PR_Accept(pds[j].fd, NULL, PR_INTERVAL_NO_TIMEOUT);
+ if (sock == NULL) {
+ fprintf(stderr, "PR_Accept() failed\n");
+ exit(1);
+ }
+ other_pds[nextIndex].fd = sock;
+ other_pds[nextIndex].in_flags = PR_POLL_READ;
+ }
+ nextIndex++;
+ } else if (pds[j].out_flags & PR_POLL_ERR) {
+ fprintf(stderr, "PR_Poll() indicates that an fd has error\n");
+ exit(1);
+ } else if (pds[j].out_flags & PR_POLL_NVAL) {
+ fprintf(stderr, "PR_Poll() indicates that fd %d is invalid\n",
+ PR_FileDesc2NativeHandle(pds[j].fd));
+ exit(1);
+ }
+ }
+
+ for (j = 3; j < npds; j++) {
+ PR_ASSERT((pds[j].out_flags & PR_POLL_WRITE) == 0
+ && (pds[j].out_flags & PR_POLL_EXCEPT) == 0);
+ if (pds[j].out_flags & PR_POLL_READ) {
+ PRInt32 nBytes;
+
+ nEvents++;
+ /* XXX: This call is a hack and should be fixed */
+ if (PR_GetDescType(pds[j].fd) == (PRDescType) 0) {
+ nBytes = recv(PR_FileDesc2NativeHandle(pds[j].fd), buf,
+ sizeof(buf), 0);
+ if (nBytes == -1) {
+ fprintf(stderr, "recv() failed\n");
+ exit(1);
+ }
+ printf("Server read %d bytes from native fd %d\n",nBytes,
+ PR_FileDesc2NativeHandle(pds[j].fd));
#ifdef WIN32
- closesocket((SOCKET)PR_FileDesc2NativeHandle(pds[j].fd));
+ closesocket((SOCKET)PR_FileDesc2NativeHandle(pds[j].fd));
#else
- close(PR_FileDesc2NativeHandle(pds[j].fd));
+ close(PR_FileDesc2NativeHandle(pds[j].fd));
#endif
- PR_DestroySocketPollFd(pds[j].fd);
- } else {
- nBytes = PR_Read(pds[j].fd, buf, sizeof(buf));
- if (nBytes == -1) {
- fprintf(stderr, "PR_Read() failed\n");
- exit(1);
- }
- PR_Close(pds[j].fd);
- }
- /* Just to be safe */
- buf[BUF_SIZE - 1] = '\0';
- printf("The server received \"%s\" from a client\n", buf);
- } else if (pds[j].out_flags & PR_POLL_ERR) {
- fprintf(stderr, "PR_Poll() indicates that an fd has error\n");
- exit(1);
- } else if (pds[j].out_flags & PR_POLL_NVAL) {
- fprintf(stderr, "PR_Poll() indicates that an fd is invalid\n");
- exit(1);
- } else {
- other_pds[nextIndex] = pds[j];
- nextIndex++;
- }
- }
-
- PR_ASSERT(retVal == nEvents);
- /* swap */
- tmp = pds;
- pds = other_pds;
- other_pds = tmp;
- npds = nextIndex;
- i += nEvents;
+ PR_DestroySocketPollFd(pds[j].fd);
+ } else {
+ nBytes = PR_Read(pds[j].fd, buf, sizeof(buf));
+ if (nBytes == -1) {
+ fprintf(stderr, "PR_Read() failed\n");
+ exit(1);
+ }
+ PR_Close(pds[j].fd);
+ }
+ /* Just to be safe */
+ buf[BUF_SIZE - 1] = '\0';
+ printf("The server received \"%s\" from a client\n", buf);
+ } else if (pds[j].out_flags & PR_POLL_ERR) {
+ fprintf(stderr, "PR_Poll() indicates that an fd has error\n");
+ exit(1);
+ } else if (pds[j].out_flags & PR_POLL_NVAL) {
+ fprintf(stderr, "PR_Poll() indicates that an fd is invalid\n");
+ exit(1);
+ } else {
+ other_pds[nextIndex] = pds[j];
+ nextIndex++;
+ }
+ }
+
+ PR_ASSERT(retVal == nEvents);
+ /* swap */
+ tmp = pds;
+ pds = other_pds;
+ other_pds = tmp;
+ npds = nextIndex;
+ i += nEvents;
}
PR_DestroySocketPollFd(socket_poll_fd);
diff --git a/pr/tests/prpollml.c b/pr/tests/prpollml.c
index 82194f5f..118d3674 100644
--- a/pr/tests/prpollml.c
+++ b/pr/tests/prpollml.c
@@ -34,8 +34,8 @@ static void Test(void)
rv = PR_Poll(pd, i, timeout);
if (rv != 0) {
fprintf(stderr,
- "PR_Poll should time out but returns %d (%d, %d)\n",
- (int) rv, (int) PR_GetError(), (int) PR_GetOSError());
+ "PR_Poll should time out but returns %d (%d, %d)\n",
+ (int) rv, (int) PR_GetError(), (int) PR_GetOSError());
exit(1);
}
}
@@ -44,7 +44,7 @@ static void Test(void)
rv = PR_Poll(pd, i, timeout);
if (rv != 0) {
fprintf(stderr, "PR_Poll should time out but returns %d\n",
- (int) rv);
+ (int) rv);
exit(1);
}
}
@@ -70,19 +70,19 @@ int main(int argc, char **argv)
sock = PR_NewTCPSocket();
if (sock == NULL) {
fprintf(stderr, "PR_NewTCPSocket failed (%d, %d)\n",
- (int) PR_GetError(), (int) PR_GetOSError());
+ (int) PR_GetError(), (int) PR_GetOSError());
fprintf(stderr, "Ensure the per process file descriptor limit "
- "is greater than %d.", POLL_DESC_COUNT);
+ "is greater than %d.", POLL_DESC_COUNT);
exit(1);
}
if (PR_Bind(sock, &addr) == PR_FAILURE) {
fprintf(stderr, "PR_Bind failed (%d, %d)\n",
- (int) PR_GetError(), (int) PR_GetOSError());
+ (int) PR_GetError(), (int) PR_GetOSError());
exit(1);
}
if (PR_Listen(sock, 5) == PR_FAILURE) {
fprintf(stderr, "PR_Listen failed (%d, %d)\n",
- (int) PR_GetError(), (int) PR_GetOSError());
+ (int) PR_GetError(), (int) PR_GetOSError());
exit(1);
}
@@ -95,7 +95,7 @@ int main(int argc, char **argv)
/* then run the test on all three kinds of threads */
thread = PR_CreateThread(PR_USER_THREAD, ThreadFunc, NULL,
- PR_PRIORITY_NORMAL, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_PRIORITY_NORMAL, PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
if (NULL == thread) {
fprintf(stderr, "PR_CreateThread failed\n");
exit(1);
@@ -105,7 +105,7 @@ int main(int argc, char **argv)
exit(1);
}
thread = PR_CreateThread(PR_USER_THREAD, ThreadFunc, NULL,
- PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
if (NULL == thread) {
fprintf(stderr, "PR_CreateThread failed\n");
exit(1);
@@ -115,7 +115,7 @@ int main(int argc, char **argv)
exit(1);
}
thread = PR_CreateThread(PR_USER_THREAD, ThreadFunc, NULL,
- PR_PRIORITY_NORMAL, PR_GLOBAL_BOUND_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_PRIORITY_NORMAL, PR_GLOBAL_BOUND_THREAD, PR_JOINABLE_THREAD, 0);
if (NULL == thread) {
fprintf(stderr, "PR_CreateThread failed\n");
exit(1);
diff --git a/pr/tests/prselect.c b/pr/tests/prselect.c
index 9006fe4c..2a81100e 100644
--- a/pr/tests/prselect.c
+++ b/pr/tests/prselect.c
@@ -12,10 +12,10 @@
**
** Modification History:
** 14-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.
***********************************************************************/
/***********************************************************************
@@ -40,7 +40,7 @@
/***********************************************************************
** PRIVATE FUNCTION: Test_Result
** DESCRIPTION: Used in conjunction with the regress tool, prints out the
-** status of the test case.
+** status of the test case.
** INPUTS: PASS/FAIL
** OUTPUTS: None
** RETURN: None
@@ -56,10 +56,12 @@
static Test_Result (int result)
{
- if (result == PASS)
- printf ("PASS\n");
- else
- printf ("FAIL\n");
+ if (result == PASS) {
+ printf ("PASS\n");
+ }
+ else {
+ printf ("FAIL\n");
+ }
}
static void
@@ -77,10 +79,10 @@ clientThreadFunc(void *arg)
PR_snprintf(buf, sizeof(buf), "%hu", port);
for (i = 0; i < 5; i++) {
- sock = PR_NewTCPSocket();
+ sock = PR_NewTCPSocket();
PR_Connect(sock, &addr, PR_INTERVAL_NO_TIMEOUT);
- PR_Write(sock, buf, sizeof(buf));
- PR_Close(sock);
+ PR_Write(sock, buf, sizeof(buf));
+ PR_Close(sock);
}
}
@@ -98,91 +100,109 @@ int main(int argc, char **argv)
PRInt32 retVal;
PRIntn i, j;
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
+ 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_mode = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- /* main test */
+ /* main test */
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
PR_STDIO_INIT();
if (debug_mode) {
- printf("This program tests PR_Select with sockets. Timeout, error\n");
- printf("reporting, and normal operation are tested.\n\n");
- }
+ printf("This program tests PR_Select with sockets. Timeout, error\n");
+ printf("reporting, and normal operation are tested.\n\n");
+ }
/* Create two listening sockets */
if ((listenSock1 = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr, "Can't create a new TCP socket\n");
- if (!debug_mode) Test_Result(FAIL);
- exit(1);
+ fprintf(stderr, "Can't create a new TCP socket\n");
+ if (!debug_mode) {
+ Test_Result(FAIL);
+ }
+ exit(1);
}
addr.inet.family = AF_INET;
addr.inet.ip = PR_htonl(INADDR_ANY);
addr.inet.port = PR_htons(0);
if (PR_Bind(listenSock1, &addr) == PR_FAILURE) {
- fprintf(stderr, "Can't bind socket\n");
- if (!debug_mode) Test_Result(FAIL);
- exit(1);
+ fprintf(stderr, "Can't bind socket\n");
+ if (!debug_mode) {
+ Test_Result(FAIL);
+ }
+ exit(1);
}
if (PR_GetSockName(listenSock1, &addr) == PR_FAILURE) {
- fprintf(stderr, "PR_GetSockName failed\n");
- if (!debug_mode) Test_Result(FAIL);
- exit(1);
+ fprintf(stderr, "PR_GetSockName failed\n");
+ if (!debug_mode) {
+ Test_Result(FAIL);
+ }
+ exit(1);
}
listenPort1 = PR_ntohs(addr.inet.port);
if (PR_Listen(listenSock1, 5) == PR_FAILURE) {
- fprintf(stderr, "Can't listen on a socket\n");
- if (!debug_mode) Test_Result(FAIL);
- exit(1);
+ fprintf(stderr, "Can't listen on a socket\n");
+ if (!debug_mode) {
+ Test_Result(FAIL);
+ }
+ exit(1);
}
if ((listenSock2 = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr, "Can't create a new TCP socket\n");
- if (!debug_mode) Test_Result(FAIL);
- exit(1);
+ fprintf(stderr, "Can't create a new TCP socket\n");
+ if (!debug_mode) {
+ Test_Result(FAIL);
+ }
+ exit(1);
}
addr.inet.family = AF_INET;
addr.inet.ip = PR_htonl(INADDR_ANY);
addr.inet.port = PR_htons(0);
if (PR_Bind(listenSock2, &addr) == PR_FAILURE) {
- fprintf(stderr, "Can't bind socket\n");
- if (!debug_mode) Test_Result(FAIL);
- exit(1);
+ fprintf(stderr, "Can't bind socket\n");
+ if (!debug_mode) {
+ Test_Result(FAIL);
+ }
+ exit(1);
}
if (PR_GetSockName(listenSock2, &addr) == PR_FAILURE) {
- fprintf(stderr, "PR_GetSockName failed\n");
- if (!debug_mode) Test_Result(FAIL);
- exit(1);
+ fprintf(stderr, "PR_GetSockName failed\n");
+ if (!debug_mode) {
+ Test_Result(FAIL);
+ }
+ exit(1);
}
listenPort2 = PR_ntohs(addr.inet.port);
if (PR_Listen(listenSock2, 5) == PR_FAILURE) {
- fprintf(stderr, "Can't listen on a socket\n");
- if (!debug_mode) Test_Result(FAIL);
- exit(1);
+ fprintf(stderr, "Can't listen on a socket\n");
+ if (!debug_mode) {
+ Test_Result(FAIL);
+ }
+ exit(1);
}
PR_snprintf(buf, sizeof(buf),
- "The server thread is listening on ports %hu and %hu\n\n",
- listenPort1, listenPort2);
+ "The server thread is listening on ports %hu and %hu\n\n",
+ listenPort1, listenPort2);
printf("%s", buf);
/* Set up the fd set */
@@ -191,29 +211,37 @@ int main(int argc, char **argv)
PR_FD_SET(listenSock2, &readFdSet);
/* Testing timeout */
- if (debug_mode) printf("PR_Select should time out in 5 seconds\n");
+ if (debug_mode) {
+ printf("PR_Select should time out in 5 seconds\n");
+ }
retVal = PR_Select(0 /* unused */, &readFdSet, NULL, NULL,
- PR_SecondsToInterval(5));
+ PR_SecondsToInterval(5));
if (retVal != 0) {
- PR_snprintf(buf, sizeof(buf),
- "PR_Select should time out and return 0, but it returns %ld\n",
- retVal);
- fprintf(stderr, "%s", buf);
- if (retVal == -1) {
- fprintf(stderr, "Error %d, oserror %d\n", PR_GetError(),
- PR_GetOSError());
- if (!debug_mode) Test_Result(FAIL);
- }
- exit(1);
+ PR_snprintf(buf, sizeof(buf),
+ "PR_Select should time out and return 0, but it returns %ld\n",
+ retVal);
+ fprintf(stderr, "%s", buf);
+ if (retVal == -1) {
+ fprintf(stderr, "Error %d, oserror %d\n", PR_GetError(),
+ PR_GetOSError());
+ if (!debug_mode) {
+ Test_Result(FAIL);
+ }
+ }
+ exit(1);
+ }
+ if (debug_mode) {
+ printf("PR_Select timed out. Test passed.\n\n");
+ }
+ else {
+ Test_Result(PASS);
}
- if (debug_mode) printf("PR_Select timed out. Test passed.\n\n");
- else Test_Result(PASS);
/* Testing bad fd */
printf("PR_Select should detect a bad file descriptor\n");
if ((badFD = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr, "Can't create a TCP socket\n");
- exit(1);
+ fprintf(stderr, "Can't create a TCP socket\n");
+ exit(1);
}
PR_FD_SET(listenSock1, &readFdSet);
@@ -221,35 +249,35 @@ int main(int argc, char **argv)
PR_FD_SET(badFD, &readFdSet);
PR_Close(badFD); /* make the fd bad */
retVal = PR_Select(0 /* unused */, &readFdSet, NULL, NULL,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
if (retVal != -1 || PR_GetError() != PR_BAD_DESCRIPTOR_ERROR) {
- fprintf(stderr, "Failed to detect the bad fd: "
- "PR_Select returns %d\n", retVal);
- if (retVal == -1) {
- fprintf(stderr, "Error %d, oserror %d\n", PR_GetError(),
- PR_GetOSError());
- }
- exit(1);
+ fprintf(stderr, "Failed to detect the bad fd: "
+ "PR_Select returns %d\n", retVal);
+ if (retVal == -1) {
+ fprintf(stderr, "Error %d, oserror %d\n", PR_GetError(),
+ PR_GetOSError());
+ }
+ exit(1);
}
printf("PR_Select detected a bad fd. Test passed.\n\n");
PR_FD_CLR(badFD, &readFdSet);
clientThread = PR_CreateThread(PR_USER_THREAD,
- clientThreadFunc, (void *) listenPort1,
- PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
- PR_UNJOINABLE_THREAD, 0);
+ clientThreadFunc, (void *) listenPort1,
+ PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
+ PR_UNJOINABLE_THREAD, 0);
if (clientThread == NULL) {
- fprintf(stderr, "can't create thread\n");
- exit(1);
+ fprintf(stderr, "can't create thread\n");
+ exit(1);
}
clientThread = PR_CreateThread(PR_USER_THREAD,
- clientThreadFunc, (void *) listenPort2,
- PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
- PR_UNJOINABLE_THREAD, 0);
+ clientThreadFunc, (void *) listenPort2,
+ PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
+ PR_UNJOINABLE_THREAD, 0);
if (clientThread == NULL) {
- fprintf(stderr, "can't create thread\n");
- exit(1);
+ fprintf(stderr, "can't create thread\n");
+ exit(1);
}
printf("Two client threads are created. Each of them will\n");
@@ -270,68 +298,68 @@ int main(int argc, char **argv)
/* 20 events total */
i = 0;
while (i < 20) {
- PRFileDesc **tmp;
- int nextIndex;
- int nEvents = 0;
-
- retVal = PR_Select(0 /* unused */, &readFdSet, NULL, NULL,
- PR_INTERVAL_NO_TIMEOUT);
- PR_ASSERT(retVal != 0); /* no timeout */
- if (retVal == -1) {
- fprintf(stderr, "PR_Select failed (%d, %d)\n", PR_GetError(),
- PR_GetOSError());
- exit(1);
- }
-
- nextIndex = 2;
- /* the two listening sockets */
- for (j = 0; j < 2; j++) {
- other_fds[j] = fds[j];
- if (PR_FD_ISSET(fds[j], &readFdSet)) {
- PRFileDesc *sock;
-
- nEvents++;
- sock = PR_Accept(fds[j], NULL, PR_INTERVAL_NO_TIMEOUT);
- if (sock == NULL) {
- fprintf(stderr, "PR_Accept() failed\n");
- exit(1);
- }
- other_fds[nextIndex] = sock;
- PR_FD_SET(sock, &readFdSet);
- nextIndex++;
- }
- PR_FD_SET(fds[j], &readFdSet);
- }
-
- for (j = 2; j < nfds; j++) {
- if (PR_FD_ISSET(fds[j], &readFdSet)) {
- PRInt32 nBytes;
-
- PR_FD_CLR(fds[j], &readFdSet);
- nEvents++;
- nBytes = PR_Read(fds[j], buf, sizeof(buf));
- if (nBytes == -1) {
- fprintf(stderr, "PR_Read() failed\n");
- exit(1);
- }
- /* Just to be safe */
- buf[127] = '\0';
- PR_Close(fds[j]);
- printf("The server received \"%s\" from a client\n", buf);
- } else {
- PR_FD_SET(fds[j], &readFdSet);
- other_fds[nextIndex] = fds[j];
- nextIndex++;
- }
- }
-
- PR_ASSERT(retVal == nEvents);
- /* swap */
- tmp = fds;
- fds = other_fds;
- other_fds = tmp;
- nfds = nextIndex;
- i += nEvents;
+ PRFileDesc **tmp;
+ int nextIndex;
+ int nEvents = 0;
+
+ retVal = PR_Select(0 /* unused */, &readFdSet, NULL, NULL,
+ PR_INTERVAL_NO_TIMEOUT);
+ PR_ASSERT(retVal != 0); /* no timeout */
+ if (retVal == -1) {
+ fprintf(stderr, "PR_Select failed (%d, %d)\n", PR_GetError(),
+ PR_GetOSError());
+ exit(1);
+ }
+
+ nextIndex = 2;
+ /* the two listening sockets */
+ for (j = 0; j < 2; j++) {
+ other_fds[j] = fds[j];
+ if (PR_FD_ISSET(fds[j], &readFdSet)) {
+ PRFileDesc *sock;
+
+ nEvents++;
+ sock = PR_Accept(fds[j], NULL, PR_INTERVAL_NO_TIMEOUT);
+ if (sock == NULL) {
+ fprintf(stderr, "PR_Accept() failed\n");
+ exit(1);
+ }
+ other_fds[nextIndex] = sock;
+ PR_FD_SET(sock, &readFdSet);
+ nextIndex++;
+ }
+ PR_FD_SET(fds[j], &readFdSet);
+ }
+
+ for (j = 2; j < nfds; j++) {
+ if (PR_FD_ISSET(fds[j], &readFdSet)) {
+ PRInt32 nBytes;
+
+ PR_FD_CLR(fds[j], &readFdSet);
+ nEvents++;
+ nBytes = PR_Read(fds[j], buf, sizeof(buf));
+ if (nBytes == -1) {
+ fprintf(stderr, "PR_Read() failed\n");
+ exit(1);
+ }
+ /* Just to be safe */
+ buf[127] = '\0';
+ PR_Close(fds[j]);
+ printf("The server received \"%s\" from a client\n", buf);
+ } else {
+ PR_FD_SET(fds[j], &readFdSet);
+ other_fds[nextIndex] = fds[j];
+ nextIndex++;
+ }
+ }
+
+ PR_ASSERT(retVal == nEvents);
+ /* swap */
+ tmp = fds;
+ fds = other_fds;
+ other_fds = tmp;
+ nfds = nextIndex;
+ i += nEvents;
}
printf("All tests finished\n");
diff --git a/pr/tests/randseed.c b/pr/tests/randseed.c
index 1b655eab..2ca14c7a 100644
--- a/pr/tests/randseed.c
+++ b/pr/tests/randseed.c
@@ -90,26 +90,28 @@ int main(int argc, char **argv)
PLOptStatus os;
PLOptState *opt = PL_CreateOptState(argc, argv, "hdv");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ 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 */
- debug = 1;
- msgLevel = PR_LOG_ERROR;
- break;
- case 'v': /* verbose mode */
- msgLevel = PR_LOG_DEBUG;
- break;
- case 'h': /* help message */
- Help();
- break;
- default:
- break;
+ case 'd': /* debug */
+ debug = 1;
+ msgLevel = PR_LOG_ERROR;
+ break;
+ case 'v': /* verbose mode */
+ msgLevel = PR_LOG_DEBUG;
+ break;
+ case 'h': /* help message */
+ Help();
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
}
lm = PR_NewLogModule("Test"); /* Initialize logging */
@@ -121,10 +123,14 @@ int main(int argc, char **argv)
failed_already = PR_TRUE;
break;
}
- if (debug) PrintRand( buf, rSize );
+ if (debug) {
+ PrintRand( buf, rSize );
+ }
}
- if (debug) printf("%s\n", (failed_already)? "FAIL" : "PASS");
+ if (debug) {
+ printf("%s\n", (failed_already)? "FAIL" : "PASS");
+ }
return( (failed_already == PR_TRUE )? 1 : 0 );
} /* main() */
/* end template.c */
diff --git a/pr/tests/ranfile.c b/pr/tests/ranfile.c
index a62fc1a5..a6dcc4ac 100644
--- a/pr/tests/ranfile.c
+++ b/pr/tests/ranfile.c
@@ -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.
***********************************************************************/
@@ -57,9 +57,9 @@ typedef struct Hammer_s {
Problem problem;
} Hammer_t;
-#define DEFAULT_LIMIT 10
-#define DEFAULT_THREADS 2
-#define DEFAULT_LOOPS 1
+#define DEFAULT_LIMIT 10
+#define DEFAULT_THREADS 2
+#define DEFAULT_LOOPS 1
static PRInt32 pageSize = 1024;
static const char* baseName = "./";
@@ -132,7 +132,9 @@ static void PR_CALLBACK Thread(void *arg)
(void)sprintf(filename, "%ssg%04ld.dat", baseName, cd->id);
- if (debug_mode) printf("Starting work on %s\n", filename);
+ if (debug_mode) {
+ printf("Starting work on %s\n", filename);
+ }
while (PR_TRUE)
{
@@ -143,51 +145,75 @@ static void PR_CALLBACK Thread(void *arg)
while (minor-- > 0)
{
cd->problem = sg_okay;
- if (cd->action != sg_go) goto finished;
+ if (cd->action != sg_go) {
+ goto finished;
+ }
cd->problem = sg_open;
file = PR_Open(filename, PR_RDWR|PR_CREATE_FILE, 0666);
- if (file == NULL) goto finished;
+ if (file == NULL) {
+ goto finished;
+ }
for (index = 0; index < pages; index++)
{
cd->problem = sg_okay;
- if (cd->action != sg_go) goto close;
+ if (cd->action != sg_go) {
+ goto close;
+ }
cd->problem = sg_seek;
bytes = PR_Seek(file, pageSize * index, PR_SEEK_SET);
- if (bytes != pageSize * index) goto close;
+ if (bytes != pageSize * index) {
+ goto close;
+ }
cd->problem = sg_write;
bytes = PR_Write(file, &zero, sizeof(zero));
- if (bytes <= 0) goto close;
+ if (bytes <= 0) {
+ goto close;
+ }
cd->writes += 1;
}
cd->problem = sg_close;
rv = PR_Close(file);
- if (rv != PR_SUCCESS) goto purge;
+ if (rv != PR_SUCCESS) {
+ goto purge;
+ }
cd->problem = sg_okay;
- if (cd->action != sg_go) goto purge;
+ if (cd->action != sg_go) {
+ goto purge;
+ }
cd->problem = sg_open;
file = PR_Open(filename, PR_RDWR, 0666);
for (index = 0; index < pages; index++)
{
cd->problem = sg_okay;
- if (cd->action != sg_go) goto close;
+ if (cd->action != sg_go) {
+ goto close;
+ }
cd->problem = sg_seek;
bytes = PR_Seek(file, pageSize * index, PR_SEEK_SET);
- if (bytes != pageSize * index) goto close;
+ if (bytes != pageSize * index) {
+ goto close;
+ }
cd->problem = sg_write;
bytes = PR_Write(file, &zero, sizeof(zero));
- if (bytes <= 0) goto close;
+ if (bytes <= 0) {
+ goto close;
+ }
cd->writes += 1;
random = (random + 511) % pages;
}
cd->problem = sg_close;
rv = PR_Close(file);
- if (rv != PR_SUCCESS) goto purge;
+ if (rv != PR_SUCCESS) {
+ goto purge;
+ }
cd->problem = sg_delete;
rv = PR_Delete(filename);
- if (rv != PR_SUCCESS) goto finished;
- }
+ if (rv != PR_SUCCESS) {
+ goto finished;
+ }
+ }
}
close:
@@ -200,7 +226,9 @@ finished:
PR_NotifyCondVar(cd->cv);
PR_Unlock(cd->ml);
- if (debug_mode) printf("Ending work on %s\n", filename);
+ if (debug_mode) {
+ printf("Ending work on %s\n", filename);
+ }
return;
} /* Thread */
@@ -249,41 +277,43 @@ int main(int argc, char **argv)
const char *where[] = {"okay", "open", "close", "delete", "write", "seek"};
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "Gdl:t:i:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+ PLOptStatus os;
+ 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 'G': /* global threads */
- thread_scope = PR_GLOBAL_THREAD;
- 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 */
- loops = atoi(opt->value);
- break;
- default:
- break;
+ case 'G': /* global threads */
+ thread_scope = PR_GLOBAL_THREAD;
+ 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 */
+ loops = atoi(opt->value);
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- /* main test */
+ /* main test */
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
PR_STDIO_INIT();
@@ -293,18 +323,26 @@ int main(int argc, char **argv)
ml = PR_NewLock();
cv = PR_NewCondVar(ml);
- if (loops == 0) loops = DEFAULT_LOOPS;
- if (limit == 0) limit = DEFAULT_LIMIT;
- if (threads == 0) threads = DEFAULT_THREADS;
+ if (loops == 0) {
+ loops = DEFAULT_LOOPS;
+ }
+ if (limit == 0) {
+ limit = DEFAULT_LIMIT;
+ }
+ if (threads == 0) {
+ threads = DEFAULT_THREADS;
+ }
if (debug_mode) printf(
- "%s: Using loops = %d, threads = %d, limit = %d and %s threads\n",
- programName, loops, threads, limit,
- (thread_scope == PR_LOCAL_THREAD) ? "LOCAL" : "GLOBAL");
+ "%s: Using loops = %d, threads = %d, limit = %d and %s threads\n",
+ programName, loops, threads, limit,
+ (thread_scope == PR_LOCAL_THREAD) ? "LOCAL" : "GLOBAL");
for (times = 0; times < loops; ++times)
{
- if (debug_mode) printf("%s: Setting concurrency level to %d\n", programName, times + 1);
+ if (debug_mode) {
+ printf("%s: Setting concurrency level to %d\n", programName, times + 1);
+ }
PR_SetConcurrency(times + 1);
for (active = 0; active < threads; active++)
{
@@ -317,9 +355,9 @@ int main(int argc, char **argv)
hammer[active].limit = (RandomNum() % limit) + 1;
hammer[active].timein = PR_IntervalNow();
hammer[active].thread = PR_CreateThread(
- PR_USER_THREAD, Thread, &hammer[active],
- PR_GetThreadPriority(PR_GetCurrentThread()),
- thread_scope, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, Thread, &hammer[active],
+ PR_GetThreadPriority(PR_GetCurrentThread()),
+ thread_scope, PR_JOINABLE_THREAD, 0);
PR_Lock(ml);
PR_WaitCondVar(cv, interleave); /* start new ones slowly */
@@ -333,8 +371,9 @@ int main(int argc, char **argv)
PR_Lock(ml);
for (poll = 0; poll < threads; poll++)
{
- if (hammer[poll].action == sg_go) /* don't overwrite done */
- hammer[poll].action = sg_stop; /* ask him to stop */
+ if (hammer[poll].action == sg_go) { /* don't overwrite done */
+ hammer[poll].action = sg_stop; /* ask him to stop */
+ }
}
PR_Unlock(ml);
@@ -343,8 +382,9 @@ int main(int argc, char **argv)
for (poll = 0; poll < threads; poll++)
{
PR_Lock(ml);
- while (hammer[poll].action < sg_done)
+ while (hammer[poll].action < sg_done) {
PR_WaitCondVar(cv, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_Unlock(ml);
active -= 1; /* this is another one down */
@@ -353,38 +393,41 @@ int main(int argc, char **argv)
if (hammer[poll].problem == sg_okay)
{
duration = PR_IntervalToMilliseconds(
- PR_IntervalNow() - hammer[poll].timein);
+ PR_IntervalNow() - hammer[poll].timein);
writes = hammer[poll].writes * 1000 / duration;
- if (writes < writesMin)
+ if (writes < writesMin) {
writesMin = writes;
- if (writes > writesMax)
+ }
+ if (writes > writesMax) {
writesMax = writes;
+ }
writesTot += hammer[poll].writes;
durationTot += duration;
}
- else
- if (debug_mode) printf(
+ else if (debug_mode) printf(
"%s: test failed %s after %ld seconds\n",
programName, where[hammer[poll].problem], duration);
- else failed_already=1;
+ else {
+ failed_already=1;
+ }
}
}
}
if (debug_mode) printf(
- "%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);
PR_DestroyCondVar(cv);
PR_DestroyLock(ml);
- if (failed_already)
- {
- printf("FAIL\n");
- return 1;
- }
+ if (failed_already)
+ {
+ printf("FAIL\n");
+ return 1;
+ }
else
{
printf("PASS\n");
- return 0;
+ return 0;
}
} /* main */
diff --git a/pr/tests/rmdir.c b/pr/tests/rmdir.c
index 3e6feda9..c1400d72 100644
--- a/pr/tests/rmdir.c
+++ b/pr/tests/rmdir.c
@@ -24,7 +24,7 @@
#define FILENAME "file80883"
PRBool failed_already = PR_FALSE;
-PRBool debug_mode = PR_FALSE;
+PRBool debug_mode = PR_FALSE;
PRLogModuleInfo *lm;
@@ -33,8 +33,8 @@ PRLogModuleInfo *lm;
*/
static void Help( void ) {
fprintf(stderr, "template usage:\n"
- "\t-d debug mode\n"
- );
+ "\t-d debug mode\n"
+ );
} /* --- end Help() */
int main(int argc, char **argv)
@@ -46,7 +46,9 @@ int main(int argc, char **argv)
/* parse command line options */
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_mode = PR_TRUE;
@@ -66,7 +68,7 @@ int main(int argc, char **argv)
if (fd == 0) {
PRErrorCode err = PR_GetError();
fprintf(stderr, "create file fails: %d: %s\n", err,
- PR_ErrorToString(err, PR_LANGUAGE_I_DEFAULT));
+ PR_ErrorToString(err, PR_LANGUAGE_I_DEFAULT));
failed_already = PR_TRUE;
goto Finished;
}
@@ -81,7 +83,7 @@ int main(int argc, char **argv)
err = PR_GetError();
fprintf(stderr, "remove directory fails with: %d: %s\n", err,
- PR_ErrorToString(err, PR_LANGUAGE_I_DEFAULT));
+ PR_ErrorToString(err, PR_LANGUAGE_I_DEFAULT));
(void) PR_Delete( DIRNAME FILENAME);
(void) PR_RmDir( DIRNAME );
@@ -89,7 +91,9 @@ int main(int argc, char **argv)
return 0;
Finished:
- if ( debug_mode ) printf("%s\n", ( failed_already ) ? "FAILED" : "PASS" );
+ if ( debug_mode ) {
+ printf("%s\n", ( failed_already ) ? "FAILED" : "PASS" );
+ }
return( (failed_already)? 1 : 0 );
} /* --- end main() */
/* --- end template.c */
diff --git a/pr/tests/rwlockrank.c b/pr/tests/rwlockrank.c
index 5872fa17..d77eb968 100644
--- a/pr/tests/rwlockrank.c
+++ b/pr/tests/rwlockrank.c
@@ -64,13 +64,15 @@ int main(int argc, char **argv)
PLOptState *opt = PL_CreateOptState(argc, argv, "d");
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_on = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ _debug_on = 1;
+ break;
+ default:
+ break;
}
}
PL_DestroyOptState(opt);
diff --git a/pr/tests/rwlocktest.c b/pr/tests/rwlocktest.c
index 7b312ad9..396103c3 100644
--- a/pr/tests/rwlocktest.c
+++ b/pr/tests/rwlocktest.c
@@ -7,14 +7,14 @@
*
* RWLock tests
*
- * Several threads are created to access and modify data arrays using
- * PRRWLocks for synchronization. Two data arrays, array_A and array_B, are
- * initialized with random data and a third array, array_C, is initialized
- * with the sum of the first 2 arrays.
+ * Several threads are created to access and modify data arrays using
+ * PRRWLocks for synchronization. Two data arrays, array_A and array_B, are
+ * initialized with random data and a third array, array_C, is initialized
+ * with the sum of the first 2 arrays.
*
- * Each one of the threads acquires a read lock to verify that the sum of
- * the arrays A and B is equal to array C, and acquires a write lock to
- * consistently update arrays A and B so that their is equal to array C.
+ * Each one of the threads acquires a read lock to verify that the sum of
+ * the arrays A and B is equal to array C, and acquires a write lock to
+ * consistently update arrays A and B so that their is equal to array C.
*
*/
@@ -29,181 +29,185 @@ static void update_array(void);
static void check_array(void);
typedef struct thread_args {
- PRRWLock *rwlock;
- PRInt32 loop_cnt;
+ PRRWLock *rwlock;
+ PRInt32 loop_cnt;
} thread_args;
PRFileDesc *output;
PRFileDesc *errhandle;
-#define DEFAULT_THREAD_CNT 4
-#define DEFAULT_LOOP_CNT 100
-#define TEST_ARRAY_SIZE 100
+#define DEFAULT_THREAD_CNT 4
+#define DEFAULT_LOOP_CNT 100
+#define TEST_ARRAY_SIZE 100
int main(int argc, char **argv)
{
PRInt32 cnt;
- PRStatus rc;
- PRInt32 i;
+ PRStatus rc;
+ PRInt32 i;
- PRInt32 thread_cnt = DEFAULT_THREAD_CNT;
- PRInt32 loop_cnt = DEFAULT_LOOP_CNT;
- PRThread **threads;
- thread_args *params;
- PRRWLock *rwlock1;
+ PRInt32 thread_cnt = DEFAULT_THREAD_CNT;
+ PRInt32 loop_cnt = DEFAULT_LOOP_CNT;
+ PRThread **threads;
+ thread_args *params;
+ PRRWLock *rwlock1;
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "dt:c:");
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "dt:c:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ 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_on = 1;
- break;
- case 't': /* thread count */
- thread_cnt = atoi(opt->value);
- break;
- case 'c': /* loop count */
- loop_cnt = atoi(opt->value);
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ _debug_on = 1;
+ break;
+ case 't': /* thread count */
+ thread_cnt = atoi(opt->value);
+ break;
+ case 'c': /* loop count */
+ loop_cnt = atoi(opt->value);
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- PR_SetConcurrency(4);
+ PR_SetConcurrency(4);
output = PR_GetSpecialFD(PR_StandardOutput);
errhandle = PR_GetSpecialFD(PR_StandardError);
- rwlock1 = PR_NewRWLock(0,"Lock 1");
- if (rwlock1 == NULL) {
- PR_fprintf(errhandle, "PR_NewRWLock failed - error %d\n",
- PR_GetError());
- return 1;
- }
-
- threads = (PRThread**) PR_CALLOC(sizeof(PRThread*) * thread_cnt);
- params = (thread_args *) PR_CALLOC(sizeof(thread_args) * thread_cnt);
-
- /*
- * allocate and initialize data arrays
- */
- array_A =(PRInt32 *) PR_MALLOC(sizeof(PRInt32) * TEST_ARRAY_SIZE);
- array_B =(PRInt32 *) PR_MALLOC(sizeof(PRInt32) * TEST_ARRAY_SIZE);
- array_C =(PRInt32 *) PR_MALLOC(sizeof(PRInt32) * TEST_ARRAY_SIZE);
- cnt = 0;
- for (i=0; i < TEST_ARRAY_SIZE;i++) {
- array_A[i] = cnt++;
- array_B[i] = cnt++;
- array_C[i] = array_A[i] + array_B[i];
- }
-
- if (_debug_on)
- PR_fprintf(output,"%s: thread_cnt = %d loop_cnt = %d\n", argv[0],
- thread_cnt, loop_cnt);
- for(cnt = 0; cnt < thread_cnt; cnt++) {
- PRThreadScope scope;
-
- params[cnt].rwlock = rwlock1;
- params[cnt].loop_cnt = loop_cnt;
-
- /*
- * create LOCAL and GLOBAL threads alternately
- */
- if (cnt & 1)
- scope = PR_LOCAL_THREAD;
- else
- scope = PR_GLOBAL_THREAD;
-
- threads[cnt] = PR_CreateThread(PR_USER_THREAD,
- rwtest, &params[cnt],
- PR_PRIORITY_NORMAL,
- scope,
- PR_JOINABLE_THREAD,
- 0);
- if (threads[cnt] == NULL) {
- PR_fprintf(errhandle, "PR_CreateThread failed - error %d\n",
- PR_GetError());
- PR_ProcessExit(2);
- }
- if (_debug_on)
- PR_fprintf(output,"%s: created thread = %p\n", argv[0],
- threads[cnt]);
- }
-
- for(cnt = 0; cnt < thread_cnt; cnt++) {
- rc = PR_JoinThread(threads[cnt]);
- PR_ASSERT(rc == PR_SUCCESS);
-
- }
-
- PR_DELETE(threads);
- PR_DELETE(params);
-
- PR_DELETE(array_A);
- PR_DELETE(array_B);
- PR_DELETE(array_C);
-
- PR_DestroyRWLock(rwlock1);
-
-
- printf("PASS\n");
- return 0;
+ rwlock1 = PR_NewRWLock(0,"Lock 1");
+ if (rwlock1 == NULL) {
+ PR_fprintf(errhandle, "PR_NewRWLock failed - error %d\n",
+ PR_GetError());
+ return 1;
+ }
+
+ threads = (PRThread**) PR_CALLOC(sizeof(PRThread*) * thread_cnt);
+ params = (thread_args *) PR_CALLOC(sizeof(thread_args) * thread_cnt);
+
+ /*
+ * allocate and initialize data arrays
+ */
+ array_A =(PRInt32 *) PR_MALLOC(sizeof(PRInt32) * TEST_ARRAY_SIZE);
+ array_B =(PRInt32 *) PR_MALLOC(sizeof(PRInt32) * TEST_ARRAY_SIZE);
+ array_C =(PRInt32 *) PR_MALLOC(sizeof(PRInt32) * TEST_ARRAY_SIZE);
+ cnt = 0;
+ for (i=0; i < TEST_ARRAY_SIZE; i++) {
+ array_A[i] = cnt++;
+ array_B[i] = cnt++;
+ array_C[i] = array_A[i] + array_B[i];
+ }
+
+ if (_debug_on)
+ PR_fprintf(output,"%s: thread_cnt = %d loop_cnt = %d\n", argv[0],
+ thread_cnt, loop_cnt);
+ for(cnt = 0; cnt < thread_cnt; cnt++) {
+ PRThreadScope scope;
+
+ params[cnt].rwlock = rwlock1;
+ params[cnt].loop_cnt = loop_cnt;
+
+ /*
+ * create LOCAL and GLOBAL threads alternately
+ */
+ if (cnt & 1) {
+ scope = PR_LOCAL_THREAD;
+ }
+ else {
+ scope = PR_GLOBAL_THREAD;
+ }
+
+ threads[cnt] = PR_CreateThread(PR_USER_THREAD,
+ rwtest, &params[cnt],
+ PR_PRIORITY_NORMAL,
+ scope,
+ PR_JOINABLE_THREAD,
+ 0);
+ if (threads[cnt] == NULL) {
+ PR_fprintf(errhandle, "PR_CreateThread failed - error %d\n",
+ PR_GetError());
+ PR_ProcessExit(2);
+ }
+ if (_debug_on)
+ PR_fprintf(output,"%s: created thread = %p\n", argv[0],
+ threads[cnt]);
+ }
+
+ for(cnt = 0; cnt < thread_cnt; cnt++) {
+ rc = PR_JoinThread(threads[cnt]);
+ PR_ASSERT(rc == PR_SUCCESS);
+
+ }
+
+ PR_DELETE(threads);
+ PR_DELETE(params);
+
+ PR_DELETE(array_A);
+ PR_DELETE(array_B);
+ PR_DELETE(array_C);
+
+ PR_DestroyRWLock(rwlock1);
+
+
+ printf("PASS\n");
+ return 0;
}
static void rwtest(void *args)
{
PRInt32 index;
- thread_args *arg = (thread_args *) args;
+ thread_args *arg = (thread_args *) args;
- for (index = 0; index < arg->loop_cnt; index++) {
+ for (index = 0; index < arg->loop_cnt; index++) {
- /*
- * verify sum, update arrays and verify sum again
- */
+ /*
+ * verify sum, update arrays and verify sum again
+ */
- PR_RWLock_Rlock(arg->rwlock);
- check_array();
- PR_RWLock_Unlock(arg->rwlock);
+ PR_RWLock_Rlock(arg->rwlock);
+ check_array();
+ PR_RWLock_Unlock(arg->rwlock);
- PR_RWLock_Wlock(arg->rwlock);
- update_array();
- PR_RWLock_Unlock(arg->rwlock);
+ PR_RWLock_Wlock(arg->rwlock);
+ update_array();
+ PR_RWLock_Unlock(arg->rwlock);
- PR_RWLock_Rlock(arg->rwlock);
- check_array();
- PR_RWLock_Unlock(arg->rwlock);
- }
- if (_debug_on)
- PR_fprintf(output,
- "Thread[0x%x] lock = 0x%x exiting\n",
- PR_GetCurrentThread(), arg->rwlock);
+ PR_RWLock_Rlock(arg->rwlock);
+ check_array();
+ PR_RWLock_Unlock(arg->rwlock);
+ }
+ if (_debug_on)
+ PR_fprintf(output,
+ "Thread[0x%x] lock = 0x%x exiting\n",
+ PR_GetCurrentThread(), arg->rwlock);
}
static void check_array(void)
{
-PRInt32 i;
+ PRInt32 i;
- for (i=0; i < TEST_ARRAY_SIZE;i++)
- if (array_C[i] != (array_A[i] + array_B[i])) {
- PR_fprintf(output, "Error - data check failed\n");
- PR_ProcessExit(1);
- }
+ for (i=0; i < TEST_ARRAY_SIZE; i++)
+ if (array_C[i] != (array_A[i] + array_B[i])) {
+ PR_fprintf(output, "Error - data check failed\n");
+ PR_ProcessExit(1);
+ }
}
static void update_array(void)
{
-PRInt32 i;
+ PRInt32 i;
- for (i=0; i < TEST_ARRAY_SIZE;i++) {
- array_A[i] += i;
- array_B[i] -= i;
- }
+ for (i=0; i < TEST_ARRAY_SIZE; i++) {
+ array_A[i] += i;
+ array_B[i] -= i;
+ }
}
diff --git a/pr/tests/sel_spd.c b/pr/tests/sel_spd.c
index c0210ad2..9eb440b3 100644
--- a/pr/tests/sel_spd.c
+++ b/pr/tests/sel_spd.c
@@ -19,12 +19,12 @@
#define PORT_BASE 19000
typedef struct timer_slot_t {
- unsigned long d_connect;
- unsigned long d_cl_data;
- unsigned long d_sv_data;
- unsigned long d_close;
- unsigned long d_total;
- unsigned long requests;
+ unsigned long d_connect;
+ unsigned long d_cl_data;
+ unsigned long d_sv_data;
+ unsigned long d_close;
+ unsigned long d_total;
+ unsigned long requests;
} timer_slot_t;
static long _iterations = 5;
@@ -44,279 +44,287 @@ void tally_results(int);
/* return the diff in microseconds */
unsigned long _delta(PRIntervalTime *start, PRIntervalTime *stop)
{
- /*
- * Will C do the right thing with unsigned arithemtic?
- */
- return PR_IntervalToMicroseconds(*stop - *start);
+ /*
+ * Will C do the right thing with unsigned arithemtic?
+ */
+ return PR_IntervalToMicroseconds(*stop - *start);
}
int _readn(PRFileDesc *sock, char *buf, int len)
{
- int rem;
- int bytes;
+ int rem;
+ int bytes;
- for (rem=len; rem; rem -= bytes) {
- bytes = PR_Recv(sock, buf+len-rem, rem, 0, PR_INTERVAL_NO_TIMEOUT);
- if (bytes <= 0)
+ for (rem=len; rem; rem -= bytes) {
+ bytes = PR_Recv(sock, buf+len-rem, rem, 0, PR_INTERVAL_NO_TIMEOUT);
+ if (bytes <= 0) {
return -1;
- }
- return len;
+ }
+ }
+ return len;
}
void
_thread_exit(int id)
{
- PR_EnterMonitor(exit_cv);
+ PR_EnterMonitor(exit_cv);
#ifdef DEBUG
- fprintf(stdout, "Thread %d EXIT\n", id);
+ fprintf(stdout, "Thread %d EXIT\n", id);
#endif
- _thread_exit_count--;
- if (_thread_exit_count == 0) {
+ _thread_exit_count--;
+ if (_thread_exit_count == 0) {
#ifdef DEBUG
- fprintf(stdout, "Thread %d EXIT triggered notify\n", id);
+ fprintf(stdout, "Thread %d EXIT triggered notify\n", id);
#endif
- PR_Notify(exit_cv);
- }
- PR_ExitMonitor(exit_cv);
+ PR_Notify(exit_cv);
+ }
+ PR_ExitMonitor(exit_cv);
}
void
_server_thread(void *arg_id)
{
- void _client_thread(void *);
- PRThread *thread;
- int *id = (int *)arg_id;
- PRFileDesc *sock;
- PRSocketOptionData sockopt;
- PRNetAddr sa;
- PRFileDesc * newsock;
- char *data_buffer = NULL;
- int data_buffer_size;
- int index;
- PRIntervalTime start,
- connect_done,
- read_done,
- write_done,
- close_done;
+ void _client_thread(void *);
+ PRThread *thread;
+ int *id = (int *)arg_id;
+ PRFileDesc *sock;
+ PRSocketOptionData sockopt;
+ PRNetAddr sa;
+ PRFileDesc * newsock;
+ char *data_buffer = NULL;
+ int data_buffer_size;
+ int index;
+ PRIntervalTime start,
+ connect_done,
+ read_done,
+ write_done,
+ close_done;
#ifdef DEBUG
- fprintf(stdout, "server thread %d alive\n", *id);
+ fprintf(stdout, "server thread %d alive\n", *id);
#endif
- data_buffer_size = (_client_data>_server_data?_client_data:_server_data);
-
- if ( (data_buffer = (char *)PR_Malloc(data_buffer_size * sizeof(char))) == NULL ) {
- fprintf(stderr, "Error creating buffer in server thread %d\n", *id);
- goto done;
- }
-
-
- if ( (sock = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr, "Error creating socket in server thread %d\n", *id);
- goto done;
- }
-
- sockopt.option = PR_SockOpt_Reuseaddr;
- sockopt.value.reuse_addr = PR_TRUE;
- if ( PR_SetSocketOption(sock, &sockopt) == PR_FAILURE) {
- fprintf(stderr, "Error setting socket option in server thread %d\n", *id);
- goto done;
- }
-
- memset(&sa, 0 , sizeof(sa));
- sa.inet.family = PR_AF_INET;
- sa.inet.port = PR_htons(PORT_BASE + *id);
- sa.inet.ip = PR_htonl(PR_INADDR_ANY);
-
- if ( PR_Bind(sock, &sa) < 0) {
- fprintf(stderr, "Error binding socket in server thread %d errno = %d\n", *id, errno);
- goto done;
- }
-
- if ( PR_Listen(sock, 32) < 0 ) {
- fprintf(stderr, "Error listening to socket in server thread %d\n", *id);
- goto done;
- }
-
- /* Tell the client to start */
- if ( (thread = PR_CreateThread(PR_USER_THREAD,
- _client_thread,
- id,
- PR_PRIORITY_NORMAL,
- scope2,
- PR_UNJOINABLE_THREAD,
- 0)) == NULL)
- fprintf(stderr, "Error creating client thread %d\n", *id);
-
- for (index = 0; index< _iterations; index++) {
+ data_buffer_size = (_client_data>_server_data?_client_data:_server_data);
+
+ if ( (data_buffer = (char *)PR_Malloc(data_buffer_size * sizeof(char))) == NULL ) {
+ fprintf(stderr, "Error creating buffer in server thread %d\n", *id);
+ goto done;
+ }
+
+
+ if ( (sock = PR_NewTCPSocket()) == NULL) {
+ fprintf(stderr, "Error creating socket in server thread %d\n", *id);
+ goto done;
+ }
+
+ sockopt.option = PR_SockOpt_Reuseaddr;
+ sockopt.value.reuse_addr = PR_TRUE;
+ if ( PR_SetSocketOption(sock, &sockopt) == PR_FAILURE) {
+ fprintf(stderr, "Error setting socket option in server thread %d\n", *id);
+ goto done;
+ }
+
+ memset(&sa, 0, sizeof(sa));
+ sa.inet.family = PR_AF_INET;
+ sa.inet.port = PR_htons(PORT_BASE + *id);
+ sa.inet.ip = PR_htonl(PR_INADDR_ANY);
+
+ if ( PR_Bind(sock, &sa) < 0) {
+ fprintf(stderr, "Error binding socket in server thread %d errno = %d\n", *id, errno);
+ goto done;
+ }
+
+ if ( PR_Listen(sock, 32) < 0 ) {
+ fprintf(stderr, "Error listening to socket in server thread %d\n", *id);
+ goto done;
+ }
+
+ /* Tell the client to start */
+ if ( (thread = PR_CreateThread(PR_USER_THREAD,
+ _client_thread,
+ id,
+ PR_PRIORITY_NORMAL,
+ scope2,
+ PR_UNJOINABLE_THREAD,
+ 0)) == NULL) {
+ fprintf(stderr, "Error creating client thread %d\n", *id);
+ }
+
+ for (index = 0; index< _iterations; index++) {
#ifdef DEBUG
- fprintf(stdout, "server thread %d loop %d\n", *id, index);
+ fprintf(stdout, "server thread %d loop %d\n", *id, index);
#endif
- start = PR_IntervalNow();
+ start = PR_IntervalNow();
- if ( (newsock = PR_Accept(sock, &sa,
- PR_INTERVAL_NO_TIMEOUT)) == NULL) {
- fprintf(stderr, "Error accepting connection %d in server thread %d\n",
- index, *id);
- goto done;
- }
+ if ( (newsock = PR_Accept(sock, &sa,
+ PR_INTERVAL_NO_TIMEOUT)) == NULL) {
+ fprintf(stderr, "Error accepting connection %d in server thread %d\n",
+ index, *id);
+ goto done;
+ }
#ifdef DEBUG
- fprintf(stdout, "server thread %d got connection %d\n", *id, newsock);
+ fprintf(stdout, "server thread %d got connection %d\n", *id, newsock);
#endif
- connect_done = PR_IntervalNow();
+ connect_done = PR_IntervalNow();
- if ( _readn(newsock, data_buffer, _client_data) < _client_data) {
- fprintf(stderr, "Error reading client data for iteration %d in server thread %d\n", index, *id );
- goto done;
- }
+ if ( _readn(newsock, data_buffer, _client_data) < _client_data) {
+ fprintf(stderr, "Error reading client data for iteration %d in server thread %d\n", index, *id );
+ goto done;
+ }
#ifdef DEBUG
- fprintf(stdout, "server thread %d read %d bytes\n", *id, _client_data);
+ fprintf(stdout, "server thread %d read %d bytes\n", *id, _client_data);
#endif
- read_done = PR_IntervalNow();
+ read_done = PR_IntervalNow();
- if ( PR_Send(newsock, data_buffer, _server_data, 0,
- PR_INTERVAL_NO_TIMEOUT) < _server_data) {
- fprintf(stderr, "Error sending client data for iteration %d in server thread %d\n", index, *id );
- goto done;
- }
+ if ( PR_Send(newsock, data_buffer, _server_data, 0,
+ PR_INTERVAL_NO_TIMEOUT) < _server_data) {
+ fprintf(stderr, "Error sending client data for iteration %d in server thread %d\n", index, *id );
+ goto done;
+ }
#ifdef DEBUG
- fprintf(stdout, "server thread %d write %d bytes\n", *id, _server_data);
+ fprintf(stdout, "server thread %d write %d bytes\n", *id, _server_data);
#endif
- write_done = PR_IntervalNow();
+ write_done = PR_IntervalNow();
- PR_Close(newsock);
+ PR_Close(newsock);
- close_done = PR_IntervalNow();
+ close_done = PR_IntervalNow();
- timer_data[2*(*id)].d_connect += _delta(&start, &connect_done);
- timer_data[2*(*id)].d_cl_data += _delta(&connect_done, &read_done);
- timer_data[2*(*id)].d_sv_data += _delta(&read_done, &write_done);
- timer_data[2*(*id)].d_close += _delta(&write_done, &close_done);
- timer_data[2*(*id)].d_total += _delta(&start, &close_done);
- timer_data[2*(*id)].requests++;
+ timer_data[2*(*id)].d_connect += _delta(&start, &connect_done);
+ timer_data[2*(*id)].d_cl_data += _delta(&connect_done, &read_done);
+ timer_data[2*(*id)].d_sv_data += _delta(&read_done, &write_done);
+ timer_data[2*(*id)].d_close += _delta(&write_done, &close_done);
+ timer_data[2*(*id)].d_total += _delta(&start, &close_done);
+ timer_data[2*(*id)].requests++;
#ifdef DEBUG
- fprintf(stdout, "server: %d %d %d %d %d\n",
- _delta(&start, &connect_done), _delta(&connect_done, &read_done),
- _delta(&read_done, &write_done), _delta(&write_done, &close_done),
- _delta(&start, &close_done));
+ fprintf(stdout, "server: %d %d %d %d %d\n",
+ _delta(&start, &connect_done), _delta(&connect_done, &read_done),
+ _delta(&read_done, &write_done), _delta(&write_done, &close_done),
+ _delta(&start, &close_done));
#endif
- }
+ }
done:
- if (data_buffer != NULL) PR_Free (data_buffer);
- if (sock) PR_Close(sock);
- _thread_exit(*id);
- return;
+ if (data_buffer != NULL) {
+ PR_Free (data_buffer);
+ }
+ if (sock) {
+ PR_Close(sock);
+ }
+ _thread_exit(*id);
+ return;
}
void
_client_thread(void *arg_id)
{
- int *id = (int *)arg_id;
- int index;
- PRNetAddr sa;
- PRFileDesc *sock_h;
- char *data_buffer = NULL;
- int data_buffer_size;
- int bytes;
- PRIntervalTime start,
- connect_done,
- read_done,
- write_done,
- close_done;
- PRStatus rv;
+ int *id = (int *)arg_id;
+ int index;
+ PRNetAddr sa;
+ PRFileDesc *sock_h;
+ char *data_buffer = NULL;
+ int data_buffer_size;
+ int bytes;
+ PRIntervalTime start,
+ connect_done,
+ read_done,
+ write_done,
+ close_done;
+ PRStatus rv;
#ifdef DEBUG
- fprintf(stdout, "client thread %d alive\n", *id);
+ fprintf(stdout, "client thread %d alive\n", *id);
#endif
- data_buffer_size = (_client_data>_server_data?_client_data:_server_data);
+ data_buffer_size = (_client_data>_server_data?_client_data:_server_data);
- if ( (data_buffer = (char *)PR_Malloc(data_buffer_size * sizeof(char))) == NULL) {
- fprintf(stderr, "Error creating buffer in server thread %d\n", *id);
- goto done;
- }
+ if ( (data_buffer = (char *)PR_Malloc(data_buffer_size * sizeof(char))) == NULL) {
+ fprintf(stderr, "Error creating buffer in server thread %d\n", *id);
+ goto done;
+ }
- memset(&sa, 0 , sizeof(sa));
- rv = PR_InitializeNetAddr(PR_IpAddrLoopback, PORT_BASE + *id, &sa);
- PR_ASSERT(PR_SUCCESS == rv);
+ memset(&sa, 0, sizeof(sa));
+ rv = PR_InitializeNetAddr(PR_IpAddrLoopback, PORT_BASE + *id, &sa);
+ PR_ASSERT(PR_SUCCESS == rv);
- for (index = 0; index< _iterations; index++) {
+ for (index = 0; index< _iterations; index++) {
#ifdef DEBUG
- fprintf(stdout, "client thread %d loop %d\n", *id, index);
+ fprintf(stdout, "client thread %d loop %d\n", *id, index);
#endif
- start = PR_IntervalNow();
- if ( (sock_h = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr, "Error creating socket %d in client thread %d\n",
- index, *id);
- goto done;
- }
+ start = PR_IntervalNow();
+ if ( (sock_h = PR_NewTCPSocket()) == NULL) {
+ fprintf(stderr, "Error creating socket %d in client thread %d\n",
+ index, *id);
+ goto done;
+ }
#ifdef DEBUG
- fprintf(stdout, "client thread %d socket created %d\n", *id, sock_h);
+ fprintf(stdout, "client thread %d socket created %d\n", *id, sock_h);
#endif
- if ( PR_Connect(sock_h, &sa,
- PR_INTERVAL_NO_TIMEOUT) < 0) {
- fprintf(stderr, "Error accepting connection %d in client thread %d\n",
- index, *id);
- goto done;
- }
+ if ( PR_Connect(sock_h, &sa,
+ PR_INTERVAL_NO_TIMEOUT) < 0) {
+ fprintf(stderr, "Error accepting connection %d in client thread %d\n",
+ index, *id);
+ goto done;
+ }
#ifdef DEBUG
- fprintf(stdout, "client thread %d socket connected %d\n", *id, sock_h);
+ fprintf(stdout, "client thread %d socket connected %d\n", *id, sock_h);
#endif
- connect_done = PR_IntervalNow();
- if ( PR_Send(sock_h, data_buffer, _client_data, 0,
- PR_INTERVAL_NO_TIMEOUT) < _client_data) {
- fprintf(stderr, "Error sending client data for iteration %d in client thread %d\n", index, *id );
- goto done;
- }
+ connect_done = PR_IntervalNow();
+ if ( PR_Send(sock_h, data_buffer, _client_data, 0,
+ PR_INTERVAL_NO_TIMEOUT) < _client_data) {
+ fprintf(stderr, "Error sending client data for iteration %d in client thread %d\n", index, *id );
+ goto done;
+ }
#ifdef DEBUG
- fprintf(stdout, "client thread %d socket wrote %d\n", *id, _client_data);
+ fprintf(stdout, "client thread %d socket wrote %d\n", *id, _client_data);
#endif
- write_done = PR_IntervalNow();
- if ( (bytes = _readn(sock_h, data_buffer, _server_data)) < _server_data) {
- fprintf(stderr, "Error reading server data for iteration %d in client thread %d (read %d bytes)\n", index, *id, bytes );
- goto done;
- }
+ write_done = PR_IntervalNow();
+ if ( (bytes = _readn(sock_h, data_buffer, _server_data)) < _server_data) {
+ fprintf(stderr, "Error reading server data for iteration %d in client thread %d (read %d bytes)\n", index, *id, bytes );
+ goto done;
+ }
#ifdef DEBUG
- fprintf(stdout, "client thread %d socket read %d\n", *id, _server_data);
+ fprintf(stdout, "client thread %d socket read %d\n", *id, _server_data);
#endif
- read_done = PR_IntervalNow();
- PR_Close(sock_h);
- close_done = PR_IntervalNow();
-
- timer_data[2*(*id)+1].d_connect += _delta(&start, &connect_done);
- timer_data[2*(*id)+1].d_cl_data += _delta(&connect_done, &write_done);
- timer_data[2*(*id)+1].d_sv_data += _delta(&write_done, &read_done);
- timer_data[2*(*id)+1].d_close += _delta(&read_done, &close_done);
- timer_data[2*(*id)+1].d_total += _delta(&start, &close_done);
- timer_data[2*(*id)+1].requests++;
- }
+ read_done = PR_IntervalNow();
+ PR_Close(sock_h);
+ close_done = PR_IntervalNow();
+
+ timer_data[2*(*id)+1].d_connect += _delta(&start, &connect_done);
+ timer_data[2*(*id)+1].d_cl_data += _delta(&connect_done, &write_done);
+ timer_data[2*(*id)+1].d_sv_data += _delta(&write_done, &read_done);
+ timer_data[2*(*id)+1].d_close += _delta(&read_done, &close_done);
+ timer_data[2*(*id)+1].d_total += _delta(&start, &close_done);
+ timer_data[2*(*id)+1].requests++;
+ }
done:
- if (data_buffer != NULL) PR_Free (data_buffer);
- _thread_exit(*id);
+ if (data_buffer != NULL) {
+ PR_Free (data_buffer);
+ }
+ _thread_exit(*id);
- return;
+ return;
}
static
@@ -324,31 +332,33 @@ void do_work(void)
{
int index;
- _thread_exit_count = _threads * 2;
- for (index=0; index<_threads; index++) {
- PRThread *thread;
- int *id = (int *)PR_Malloc(sizeof(int));
+ _thread_exit_count = _threads * 2;
+ for (index=0; index<_threads; index++) {
+ PRThread *thread;
+ int *id = (int *)PR_Malloc(sizeof(int));
- *id = index;
+ *id = index;
- if ( (thread = PR_CreateThread(PR_USER_THREAD,
+ if ( (thread = PR_CreateThread(PR_USER_THREAD,
_server_thread,
id,
PR_PRIORITY_NORMAL,
scope1,
PR_UNJOINABLE_THREAD,
- 0)) == NULL)
- fprintf(stderr, "Error creating server thread %d\n", index);
- }
+ 0)) == NULL) {
+ fprintf(stderr, "Error creating server thread %d\n", index);
+ }
+ }
- PR_EnterMonitor(exit_cv);
- while (_thread_exit_count > 0)
- PR_Wait(exit_cv, PR_INTERVAL_NO_TIMEOUT);
- PR_ExitMonitor(exit_cv);
+ PR_EnterMonitor(exit_cv);
+ while (_thread_exit_count > 0) {
+ PR_Wait(exit_cv, PR_INTERVAL_NO_TIMEOUT);
+ }
+ PR_ExitMonitor(exit_cv);
- fprintf(stdout, "TEST COMPLETE!\n");
+ fprintf(stdout, "TEST COMPLETE!\n");
- tally_results(verbose);
+ tally_results(verbose);
}
@@ -400,47 +410,49 @@ static void Measure(void (*func)(void), const char *msg)
int main(int argc, char **argv)
{
#if defined(XP_UNIX) || defined(XP_OS2)
- int opt;
- PR_IMPORT_DATA(char *) optarg;
+ int opt;
+ PR_IMPORT_DATA(char *) optarg;
#endif
#if defined(XP_UNIX) || defined(XP_OS2)
- while ( (opt = getopt(argc, argv, "c:s:i:t:v")) != EOF) {
- switch(opt) {
- case 'i':
- _iterations = atoi(optarg);
- break;
- case 't':
- _threads_max = _threads = atoi(optarg);
- break;
- case 'c':
- _client_data = atoi(optarg);
- break;
- case 's':
- _server_data = atoi(optarg);
- break;
- case 'v':
- verbose = 1;
- break;
- default:
- break;
- }
- }
+ while ( (opt = getopt(argc, argv, "c:s:i:t:v")) != EOF) {
+ switch(opt) {
+ case 'i':
+ _iterations = atoi(optarg);
+ break;
+ case 't':
+ _threads_max = _threads = atoi(optarg);
+ break;
+ case 'c':
+ _client_data = atoi(optarg);
+ break;
+ case 's':
+ _server_data = atoi(optarg);
+ break;
+ case 'v':
+ verbose = 1;
+ break;
+ default:
+ break;
+ }
+ }
#endif
- PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
+ PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
PR_STDIO_INIT();
- fprintf(stdout, "Running test for %d iterations with %d simultaneous threads.\n",
- _iterations, _threads);
- fprintf(stdout, "\tWill send %d bytes of client data and %d bytes of server data\n",
- _client_data, _server_data);
+ fprintf(stdout, "Running test for %d iterations with %d simultaneous threads.\n",
+ _iterations, _threads);
+ fprintf(stdout, "\tWill send %d bytes of client data and %d bytes of server data\n",
+ _client_data, _server_data);
- if ( (exit_cv = PR_NewMonitor()) == NULL)
- fprintf(stderr, "Error creating monitor for exit cv\n");
- if ( (timer_data = (timer_slot_t *)PR_Malloc(2*_threads * sizeof(timer_slot_t))) == NULL)
- fprintf(stderr, "error allocating thread time results array\n");
- memset(timer_data, 0 , 2*_threads*sizeof(timer_slot_t));
+ if ( (exit_cv = PR_NewMonitor()) == NULL) {
+ fprintf(stderr, "Error creating monitor for exit cv\n");
+ }
+ if ( (timer_data = (timer_slot_t *)PR_Malloc(2*_threads * sizeof(timer_slot_t))) == NULL) {
+ fprintf(stderr, "error allocating thread time results array\n");
+ }
+ memset(timer_data, 0, 2*_threads*sizeof(timer_slot_t));
Measure(do_workUU, "select loop user/user");
Measure(do_workUK, "select loop user/kernel");
@@ -448,62 +460,62 @@ int main(int argc, char **argv)
Measure(do_workKK, "select loop kernel/kernel");
- return 0;
+ return 0;
}
void
tally_results(int verbose)
{
- int index;
- unsigned long tot_connect = 0;
- unsigned long tot_cl_data = 0;
- unsigned long tot_sv_data = 0;
- unsigned long tot_close = 0;
- unsigned long tot_all = 0;
- unsigned long tot_requests = 0;
-
- fprintf(stdout, "Server results:\n\n");
- for (index=0; index<_threads_max*2; index+=2) {
-
- if (verbose)
- fprintf(stdout, "server thread %u\t%u\t%u\t%u\t%u\t%u\t%u\n",
- index, timer_data[index].requests, timer_data[index].d_connect,
- timer_data[index].d_cl_data, timer_data[index].d_sv_data,
- timer_data[index].d_close, timer_data[index].d_total);
-
- tot_connect += timer_data[index].d_connect / _threads;
- tot_cl_data += timer_data[index].d_cl_data / _threads;
- tot_sv_data += timer_data[index].d_sv_data / _threads;
- tot_close += timer_data[index].d_close / _threads;
- tot_all += timer_data[index].d_total / _threads;
- tot_requests += timer_data[index].requests / _threads;
- }
- fprintf(stdout, "----------\n");
- fprintf(stdout, "server per thread totals %u\t%u\t%u\t%u\t%u\n",
- tot_requests, tot_connect, tot_cl_data, tot_sv_data, tot_close);
- fprintf(stdout, "server per thread elapsed time %u\n", tot_all);
- fprintf(stdout, "----------\n");
-
- tot_connect = tot_cl_data = tot_sv_data = tot_close = tot_all = tot_requests = 0;
- fprintf(stdout, "Client results:\n\n");
- for (index=1; index<_threads_max*2; index+=2) {
-
- if (verbose)
- fprintf(stdout, "client thread %u\t%u\t%u\t%u\t%u\t%u\t%u\n",
- index, timer_data[index].requests, timer_data[index].d_connect,
- timer_data[index].d_cl_data, timer_data[index].d_sv_data,
- timer_data[index].d_close, timer_data[index].d_total);
-
- tot_connect += timer_data[index].d_connect / _threads;
- tot_cl_data += timer_data[index].d_cl_data / _threads;
- tot_sv_data += timer_data[index].d_sv_data / _threads;
- tot_close += timer_data[index].d_close / _threads;
- tot_all += timer_data[index].d_total / _threads;
- tot_requests += timer_data[index].requests / _threads;
- }
- fprintf(stdout, "----------\n");
- fprintf(stdout, "client per thread totals %u\t%u\t%u\t%u\t%u\n",
- tot_requests, tot_connect, tot_cl_data, tot_sv_data, tot_close);
- fprintf(stdout, "client per thread elapsed time %u\n", tot_all);
+ int index;
+ unsigned long tot_connect = 0;
+ unsigned long tot_cl_data = 0;
+ unsigned long tot_sv_data = 0;
+ unsigned long tot_close = 0;
+ unsigned long tot_all = 0;
+ unsigned long tot_requests = 0;
+
+ fprintf(stdout, "Server results:\n\n");
+ for (index=0; index<_threads_max*2; index+=2) {
+
+ if (verbose)
+ fprintf(stdout, "server thread %u\t%u\t%u\t%u\t%u\t%u\t%u\n",
+ index, timer_data[index].requests, timer_data[index].d_connect,
+ timer_data[index].d_cl_data, timer_data[index].d_sv_data,
+ timer_data[index].d_close, timer_data[index].d_total);
+
+ tot_connect += timer_data[index].d_connect / _threads;
+ tot_cl_data += timer_data[index].d_cl_data / _threads;
+ tot_sv_data += timer_data[index].d_sv_data / _threads;
+ tot_close += timer_data[index].d_close / _threads;
+ tot_all += timer_data[index].d_total / _threads;
+ tot_requests += timer_data[index].requests / _threads;
+ }
+ fprintf(stdout, "----------\n");
+ fprintf(stdout, "server per thread totals %u\t%u\t%u\t%u\t%u\n",
+ tot_requests, tot_connect, tot_cl_data, tot_sv_data, tot_close);
+ fprintf(stdout, "server per thread elapsed time %u\n", tot_all);
+ fprintf(stdout, "----------\n");
+
+ tot_connect = tot_cl_data = tot_sv_data = tot_close = tot_all = tot_requests = 0;
+ fprintf(stdout, "Client results:\n\n");
+ for (index=1; index<_threads_max*2; index+=2) {
+
+ if (verbose)
+ fprintf(stdout, "client thread %u\t%u\t%u\t%u\t%u\t%u\t%u\n",
+ index, timer_data[index].requests, timer_data[index].d_connect,
+ timer_data[index].d_cl_data, timer_data[index].d_sv_data,
+ timer_data[index].d_close, timer_data[index].d_total);
+
+ tot_connect += timer_data[index].d_connect / _threads;
+ tot_cl_data += timer_data[index].d_cl_data / _threads;
+ tot_sv_data += timer_data[index].d_sv_data / _threads;
+ tot_close += timer_data[index].d_close / _threads;
+ tot_all += timer_data[index].d_total / _threads;
+ tot_requests += timer_data[index].requests / _threads;
+ }
+ fprintf(stdout, "----------\n");
+ fprintf(stdout, "client per thread totals %u\t%u\t%u\t%u\t%u\n",
+ tot_requests, tot_connect, tot_cl_data, tot_sv_data, tot_close);
+ fprintf(stdout, "client per thread elapsed time %u\n", tot_all);
}
diff --git a/pr/tests/selct_er.c b/pr/tests/selct_er.c
index 70007f1e..0c5c46e0 100755..100644
--- a/pr/tests/selct_er.c
+++ b/pr/tests/selct_er.c
@@ -12,12 +12,12 @@
**
** Modification History:
** 14-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.
***********************************************************************/
/***********************************************************************
@@ -48,92 +48,96 @@ int main(int argc, char **argv)
char buf[128];
PRInt32 retVal;
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
+ 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_mode = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- /* main test */
+ /* main test */
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
PR_STDIO_INIT();
if (debug_mode) {
- printf("This program tests PR_Select with sockets. Error\n");
- printf("reporting operations are tested.\n\n");
- }
+ printf("This program tests PR_Select with sockets. Error\n");
+ printf("reporting operations are tested.\n\n");
+ }
/* Create two listening sockets */
if ((listenSock1 = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr, "Can't create a new TCP socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't create a new TCP socket\n");
+ failed_already=1;
+ goto exit_now;
}
addr.inet.family = AF_INET;
addr.inet.ip = PR_htonl(INADDR_ANY);
addr.inet.port = PR_htons(0);
if (PR_Bind(listenSock1, &addr) == PR_FAILURE) {
- fprintf(stderr, "Can't bind socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't bind socket\n");
+ failed_already=1;
+ goto exit_now;
}
if (PR_GetSockName(listenSock1, &addr) == PR_FAILURE) {
- fprintf(stderr, "PR_GetSockName failed\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "PR_GetSockName failed\n");
+ failed_already=1;
+ goto exit_now;
}
listenPort1 = PR_ntohs(addr.inet.port);
if (PR_Listen(listenSock1, 5) == PR_FAILURE) {
- fprintf(stderr, "Can't listen on a socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't listen on a socket\n");
+ failed_already=1;
+ goto exit_now;
}
if ((listenSock2 = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr, "Can't create a new TCP socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't create a new TCP socket\n");
+ failed_already=1;
+ goto exit_now;
}
addr.inet.family = AF_INET;
addr.inet.ip = PR_htonl(INADDR_ANY);
addr.inet.port = PR_htons(0);
if (PR_Bind(listenSock2, &addr) == PR_FAILURE) {
- fprintf(stderr, "Can't bind socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't bind socket\n");
+ failed_already=1;
+ goto exit_now;
}
if (PR_GetSockName(listenSock2, &addr) == PR_FAILURE) {
- fprintf(stderr, "PR_GetSockName failed\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "PR_GetSockName failed\n");
+ failed_already=1;
+ goto exit_now;
}
listenPort2 = PR_ntohs(addr.inet.port);
if (PR_Listen(listenSock2, 5) == PR_FAILURE) {
- fprintf(stderr, "Can't listen on a socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't listen on a socket\n");
+ failed_already=1;
+ goto exit_now;
}
PR_snprintf(buf, sizeof(buf),
- "The server thread is listening on ports %hu and %hu\n\n",
- listenPort1, listenPort2);
- if (debug_mode) printf("%s", buf);
+ "The server thread is listening on ports %hu and %hu\n\n",
+ listenPort1, listenPort2);
+ if (debug_mode) {
+ printf("%s", buf);
+ }
/* Set up the fd set */
PR_FD_ZERO(&readFdSet);
@@ -142,11 +146,13 @@ int main(int argc, char **argv)
/* Testing bad fd */
- if (debug_mode) printf("PR_Select should detect a bad file descriptor\n");
+ if (debug_mode) {
+ printf("PR_Select should detect a bad file descriptor\n");
+ }
if ((badFD = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr, "Can't create a TCP socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't create a TCP socket\n");
+ failed_already=1;
+ goto exit_now;
}
PR_FD_SET(badFD, &readFdSet);
@@ -164,27 +170,31 @@ int main(int argc, char **argv)
#endif
retVal = PR_Select(0 /* unused */, &readFdSet, NULL, NULL,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
if (retVal != -1 || PR_GetError() != PR_BAD_DESCRIPTOR_ERROR) {
- fprintf(stderr, "Failed to detect the bad fd: "
- "PR_Select returns %d\n", retVal);
- if (retVal == -1) {
- fprintf(stderr, "Error %d, oserror %d\n", PR_GetError(),
- PR_GetOSError());
- failed_already=1;
- }
- goto exit_now;
- }
- if (debug_mode) printf("PR_Select detected a bad fd. Test passed.\n\n");
- PR_FD_CLR(badFD, &readFdSet);
-
- PR_Cleanup();
- goto exit_now;
+ fprintf(stderr, "Failed to detect the bad fd: "
+ "PR_Select returns %d\n", retVal);
+ if (retVal == -1) {
+ fprintf(stderr, "Error %d, oserror %d\n", PR_GetError(),
+ PR_GetOSError());
+ failed_already=1;
+ }
+ goto exit_now;
+ }
+ if (debug_mode) {
+ printf("PR_Select detected a bad fd. Test passed.\n\n");
+ }
+ PR_FD_CLR(badFD, &readFdSet);
+
+ PR_Cleanup();
+ goto exit_now;
exit_now:
- if(failed_already)
- return 1;
- else
- return 0;
+ if(failed_already) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
}
diff --git a/pr/tests/selct_nm.c b/pr/tests/selct_nm.c
index 663f3b8c..a698f0fa 100644
--- a/pr/tests/selct_nm.c
+++ b/pr/tests/selct_nm.c
@@ -12,12 +12,12 @@
**
** Modification History:
** 14-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.
***********************************************************************/
/***********************************************************************
@@ -57,10 +57,10 @@ clientThreadFunc(void *arg)
PR_snprintf(buf, sizeof(buf), "%hu", addr.inet.port);
for (i = 0; i < 5; i++) {
- sock = PR_NewTCPSocket();
+ sock = PR_NewTCPSocket();
PR_Connect(sock, &addr, PR_INTERVAL_NO_TIMEOUT);
- PR_Write(sock, buf, sizeof(buf));
- PR_Close(sock);
+ PR_Write(sock, buf, sizeof(buf));
+ PR_Close(sock);
}
}
@@ -77,120 +77,124 @@ int main(int argc, char **argv)
PRInt32 retVal;
PRIntn i, j;
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
+ 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_mode = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- /* main test */
+ /* main test */
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
PR_STDIO_INIT();
if (debug_mode) {
- printf("This program tests PR_Select with sockets. \n");
- printf(" Normal operation are tested.\n\n");
- }
+ printf("This program tests PR_Select with sockets. \n");
+ printf(" Normal operation are tested.\n\n");
+ }
/* Create two listening sockets */
if ((listenSock1 = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr, "Can't create a new TCP socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't create a new TCP socket\n");
+ failed_already=1;
+ goto exit_now;
}
addr.inet.family = PR_AF_INET;
addr.inet.ip = PR_htonl(PR_INADDR_ANY);
addr.inet.port = PR_htons(0);
if (PR_Bind(listenSock1, &addr) == PR_FAILURE) {
- fprintf(stderr, "Can't bind socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't bind socket\n");
+ failed_already=1;
+ goto exit_now;
}
if (PR_GetSockName(listenSock1, &addr) == PR_FAILURE) {
- fprintf(stderr, "PR_GetSockName failed\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "PR_GetSockName failed\n");
+ failed_already=1;
+ goto exit_now;
}
listenPort1 = PR_ntohs(addr.inet.port);
if (PR_Listen(listenSock1, 5) == PR_FAILURE) {
- fprintf(stderr, "Can't listen on a socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't listen on a socket\n");
+ failed_already=1;
+ goto exit_now;
}
if ((listenSock2 = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr, "Can't create a new TCP socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't create a new TCP socket\n");
+ failed_already=1;
+ goto exit_now;
}
addr.inet.family = PR_AF_INET;
addr.inet.ip = PR_htonl(PR_INADDR_ANY);
addr.inet.port = PR_htons(0);
if (PR_Bind(listenSock2, &addr) == PR_FAILURE) {
- fprintf(stderr, "Can't bind socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't bind socket\n");
+ failed_already=1;
+ goto exit_now;
}
if (PR_GetSockName(listenSock2, &addr) == PR_FAILURE) {
- fprintf(stderr, "PR_GetSockName failed\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "PR_GetSockName failed\n");
+ failed_already=1;
+ goto exit_now;
}
listenPort2 = PR_ntohs(addr.inet.port);
if (PR_Listen(listenSock2, 5) == PR_FAILURE) {
- fprintf(stderr, "Can't listen on a socket\n");
-failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't listen on a socket\n");
+ failed_already=1;
+ goto exit_now;
}
PR_snprintf(buf, sizeof(buf),
- "The server thread is listening on ports %hu and %hu\n\n",
- listenPort1, listenPort2);
- if (debug_mode) printf("%s", buf);
+ "The server thread is listening on ports %hu and %hu\n\n",
+ listenPort1, listenPort2);
+ if (debug_mode) {
+ printf("%s", buf);
+ }
clientThread = PR_CreateThread(PR_USER_THREAD,
- clientThreadFunc, (void *) listenPort1,
- PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
- PR_UNJOINABLE_THREAD, 0);
+ clientThreadFunc, (void *) listenPort1,
+ PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
+ PR_UNJOINABLE_THREAD, 0);
if (clientThread == NULL) {
- fprintf(stderr, "can't create thread\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "can't create thread\n");
+ failed_already=1;
+ goto exit_now;
}
clientThread = PR_CreateThread(PR_USER_THREAD,
- clientThreadFunc, (void *) listenPort2,
- PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
- PR_UNJOINABLE_THREAD, 0);
+ clientThreadFunc, (void *) listenPort2,
+ PR_PRIORITY_NORMAL, PR_LOCAL_THREAD,
+ PR_UNJOINABLE_THREAD, 0);
if (clientThread == NULL) {
- fprintf(stderr, "can't create thread\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "can't create thread\n");
+ failed_already=1;
+ goto exit_now;
}
if (debug_mode) {
- printf("Two client threads are created. Each of them will\n");
- printf("send data to one of the two ports the server is listening on.\n");
- printf("The data they send is the port number. Each of them send\n");
- printf("the data five times, so you should see ten lines below,\n");
- printf("interleaved in an arbitrary order.\n");
- }
+ printf("Two client threads are created. Each of them will\n");
+ printf("send data to one of the two ports the server is listening on.\n");
+ printf("The data they send is the port number. Each of them send\n");
+ printf("the data five times, so you should see ten lines below,\n");
+ printf("interleaved in an arbitrary order.\n");
+ }
/* set up the fd array */
fds = fds0;
other_fds = fds1;
@@ -205,80 +209,86 @@ failed_already=1;
/* 20 events total */
i = 0;
while (i < 20) {
- PRFileDesc **tmp;
- int nextIndex;
- int nEvents = 0;
+ PRFileDesc **tmp;
+ int nextIndex;
+ int nEvents = 0;
- retVal = PR_Select(0 /* unused */, &readFdSet, NULL, NULL,
- PR_INTERVAL_NO_TIMEOUT);
- PR_ASSERT(retVal != 0); /* no timeout */
- if (retVal == -1) {
- fprintf(stderr, "PR_Select failed (%d, %d)\n", PR_GetError(),
- PR_GetOSError());
- failed_already=1;
- goto exit_now;
- }
+ retVal = PR_Select(0 /* unused */, &readFdSet, NULL, NULL,
+ PR_INTERVAL_NO_TIMEOUT);
+ PR_ASSERT(retVal != 0); /* no timeout */
+ if (retVal == -1) {
+ fprintf(stderr, "PR_Select failed (%d, %d)\n", PR_GetError(),
+ PR_GetOSError());
+ failed_already=1;
+ goto exit_now;
+ }
- nextIndex = 2;
- /* the two listening sockets */
- for (j = 0; j < 2; j++) {
- other_fds[j] = fds[j];
- if (PR_FD_ISSET(fds[j], &readFdSet)) {
- PRFileDesc *sock;
+ nextIndex = 2;
+ /* the two listening sockets */
+ for (j = 0; j < 2; j++) {
+ other_fds[j] = fds[j];
+ if (PR_FD_ISSET(fds[j], &readFdSet)) {
+ PRFileDesc *sock;
- nEvents++;
- sock = PR_Accept(fds[j], NULL, PR_INTERVAL_NO_TIMEOUT);
- if (sock == NULL) {
- fprintf(stderr, "PR_Accept() failed\n");
- failed_already=1;
- goto exit_now;
- }
- other_fds[nextIndex] = sock;
- PR_FD_SET(sock, &readFdSet);
- nextIndex++;
- }
- PR_FD_SET(fds[j], &readFdSet);
- }
+ nEvents++;
+ sock = PR_Accept(fds[j], NULL, PR_INTERVAL_NO_TIMEOUT);
+ if (sock == NULL) {
+ fprintf(stderr, "PR_Accept() failed\n");
+ failed_already=1;
+ goto exit_now;
+ }
+ other_fds[nextIndex] = sock;
+ PR_FD_SET(sock, &readFdSet);
+ nextIndex++;
+ }
+ PR_FD_SET(fds[j], &readFdSet);
+ }
- for (j = 2; j < nfds; j++) {
- if (PR_FD_ISSET(fds[j], &readFdSet)) {
- PRInt32 nBytes;
+ for (j = 2; j < nfds; j++) {
+ if (PR_FD_ISSET(fds[j], &readFdSet)) {
+ PRInt32 nBytes;
- PR_FD_CLR(fds[j], &readFdSet);
- nEvents++;
- nBytes = PR_Read(fds[j], buf, sizeof(buf));
- if (nBytes == -1) {
- fprintf(stderr, "PR_Read() failed\n");
- failed_already=1;
- goto exit_now;
- }
- /* Just to be safe */
- buf[127] = '\0';
- PR_Close(fds[j]);
- if (debug_mode) printf("The server received \"%s\" from a client\n", buf);
- } else {
- PR_FD_SET(fds[j], &readFdSet);
- other_fds[nextIndex] = fds[j];
- nextIndex++;
- }
- }
+ PR_FD_CLR(fds[j], &readFdSet);
+ nEvents++;
+ nBytes = PR_Read(fds[j], buf, sizeof(buf));
+ if (nBytes == -1) {
+ fprintf(stderr, "PR_Read() failed\n");
+ failed_already=1;
+ goto exit_now;
+ }
+ /* Just to be safe */
+ buf[127] = '\0';
+ PR_Close(fds[j]);
+ if (debug_mode) {
+ printf("The server received \"%s\" from a client\n", buf);
+ }
+ } else {
+ PR_FD_SET(fds[j], &readFdSet);
+ other_fds[nextIndex] = fds[j];
+ nextIndex++;
+ }
+ }
- PR_ASSERT(retVal == nEvents);
- /* swap */
- tmp = fds;
- fds = other_fds;
- other_fds = tmp;
- nfds = nextIndex;
- i += nEvents;
+ PR_ASSERT(retVal == nEvents);
+ /* swap */
+ tmp = fds;
+ fds = other_fds;
+ other_fds = tmp;
+ nfds = nextIndex;
+ i += nEvents;
}
- if (debug_mode) printf("Test passed\n");
+ if (debug_mode) {
+ printf("Test passed\n");
+ }
PR_Cleanup();
- goto exit_now;
+ goto exit_now;
exit_now:
- if(failed_already)
- return 1;
- else
- return 0;
+ if(failed_already) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
}
diff --git a/pr/tests/selct_to.c b/pr/tests/selct_to.c
index 950579ed..76ac99b2 100644
--- a/pr/tests/selct_to.c
+++ b/pr/tests/selct_to.c
@@ -12,12 +12,12 @@
**
** Modification History:
** 14-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.
***********************************************************************/
/***********************************************************************
@@ -52,92 +52,96 @@ int main(int argc, char **argv)
char buf[128];
PRInt32 retVal;
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
+ 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_mode = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- /* main test */
+ /* main test */
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
PR_STDIO_INIT();
if (debug_mode) {
- printf("This program tests PR_Select with sockets. Timeout \n");
- printf("operations are tested.\n\n");
- }
+ printf("This program tests PR_Select with sockets. Timeout \n");
+ printf("operations are tested.\n\n");
+ }
/* Create two listening sockets */
if ((listenSock1 = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr, "Can't create a new TCP socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't create a new TCP socket\n");
+ failed_already=1;
+ goto exit_now;
}
addr.inet.family = PR_AF_INET;
addr.inet.ip = PR_htonl(PR_INADDR_ANY);
addr.inet.port = PR_htons(0);
if (PR_Bind(listenSock1, &addr) == PR_FAILURE) {
- fprintf(stderr, "Can't bind socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't bind socket\n");
+ failed_already=1;
+ goto exit_now;
}
if (PR_GetSockName(listenSock1, &addr) == PR_FAILURE) {
- fprintf(stderr, "PR_GetSockName failed\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "PR_GetSockName failed\n");
+ failed_already=1;
+ goto exit_now;
}
listenPort1 = PR_ntohs(addr.inet.port);
if (PR_Listen(listenSock1, 5) == PR_FAILURE) {
- fprintf(stderr, "Can't listen on a socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't listen on a socket\n");
+ failed_already=1;
+ goto exit_now;
}
if ((listenSock2 = PR_NewTCPSocket()) == NULL) {
- fprintf(stderr, "Can't create a new TCP socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't create a new TCP socket\n");
+ failed_already=1;
+ goto exit_now;
}
addr.inet.family = PR_AF_INET;
addr.inet.ip = PR_htonl(PR_INADDR_ANY);
addr.inet.port = PR_htons(0);
if (PR_Bind(listenSock2, &addr) == PR_FAILURE) {
- fprintf(stderr, "Can't bind socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't bind socket\n");
+ failed_already=1;
+ goto exit_now;
}
if (PR_GetSockName(listenSock2, &addr) == PR_FAILURE) {
- fprintf(stderr, "PR_GetSockName failed\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "PR_GetSockName failed\n");
+ failed_already=1;
+ goto exit_now;
}
listenPort2 = PR_ntohs(addr.inet.port);
if (PR_Listen(listenSock2, 5) == PR_FAILURE) {
- fprintf(stderr, "Can't listen on a socket\n");
- failed_already=1;
- goto exit_now;
+ fprintf(stderr, "Can't listen on a socket\n");
+ failed_already=1;
+ goto exit_now;
}
PR_snprintf(buf, sizeof(buf),
- "The server thread is listening on ports %hu and %hu\n\n",
- listenPort1, listenPort2);
- if (debug_mode) printf("%s", buf);
+ "The server thread is listening on ports %hu and %hu\n\n",
+ listenPort1, listenPort2);
+ if (debug_mode) {
+ printf("%s", buf);
+ }
/* Set up the fd set */
PR_FD_ZERO(&readFdSet);
@@ -145,28 +149,34 @@ int main(int argc, char **argv)
PR_FD_SET(listenSock2, &readFdSet);
/* Testing timeout */
- if (debug_mode) printf("PR_Select should time out in 5 seconds\n");
+ if (debug_mode) {
+ printf("PR_Select should time out in 5 seconds\n");
+ }
retVal = PR_Select(0 /* unused */, &readFdSet, NULL, NULL,
- PR_SecondsToInterval(5));
+ PR_SecondsToInterval(5));
if (retVal != 0) {
- PR_snprintf(buf, sizeof(buf),
- "PR_Select should time out and return 0, but it returns %ld\n",
- retVal);
- fprintf(stderr, "%s", buf);
- if (retVal == -1) {
- fprintf(stderr, "Error %d, oserror %d\n", PR_GetError(),
- PR_GetOSError());
- failed_already=1;
- }
- goto exit_now;
- }
- if (debug_mode) printf("PR_Select timed out. Test passed.\n\n");
+ PR_snprintf(buf, sizeof(buf),
+ "PR_Select should time out and return 0, but it returns %ld\n",
+ retVal);
+ fprintf(stderr, "%s", buf);
+ if (retVal == -1) {
+ fprintf(stderr, "Error %d, oserror %d\n", PR_GetError(),
+ PR_GetOSError());
+ failed_already=1;
+ }
+ goto exit_now;
+ }
+ if (debug_mode) {
+ printf("PR_Select timed out. Test passed.\n\n");
+ }
PR_Cleanup();
exit_now:
- if(failed_already)
- return 1;
- else
- return 0;
+ if(failed_already) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
}
diff --git a/pr/tests/select2.c b/pr/tests/select2.c
index d20f94ef..da7360b0 100644
--- a/pr/tests/select2.c
+++ b/pr/tests/select2.c
@@ -11,10 +11,10 @@
**
** 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.
***********************************************************************/
/***********************************************************************
@@ -40,7 +40,7 @@ PRInt32 count;
/***********************************************************************
** PRIVATE FUNCTION: Test_Result
** DESCRIPTION: Used in conjunction with the regress tool, prints out the
-** status of the test case.
+** status of the test case.
** INPUTS: PASS/FAIL
** OUTPUTS: None
** RETURN: None
@@ -56,18 +56,18 @@ PRInt32 count;
static void Test_Result (int result)
{
- switch (result)
- {
- case PASS:
- printf ("PASS\n");
- break;
- case FAIL:
- printf ("FAIL\n");
- break;
- default:
- printf ("NOSTATUS\n");
- break;
- }
+ switch (result)
+ {
+ case PASS:
+ printf ("PASS\n");
+ break;
+ case FAIL:
+ printf ("FAIL\n");
+ break;
+ default:
+ printf ("NOSTATUS\n");
+ break;
+ }
}
static void EmptyPRSelect(void)
@@ -75,8 +75,9 @@ static void EmptyPRSelect(void)
PRInt32 index = count;
PRInt32 rv;
- for (; index--;)
+ for (; index--;) {
rv = PR_Select(0, NULL, NULL, NULL, PR_INTERVAL_NO_WAIT);
+ }
}
static void EmptyNativeSelect(void)
@@ -86,8 +87,9 @@ static void EmptyNativeSelect(void)
struct timeval timeout;
timeout.tv_sec = timeout.tv_usec = 0;
- for (; index--;)
+ for (; index--;) {
rv = select(0, NULL, NULL, NULL, &timeout);
+ }
}
static void PRSelectTest(void)
@@ -96,7 +98,9 @@ static void PRSelectTest(void)
PRNetAddr serverAddr;
if ( (listenSocket = PR_NewTCPSocket()) == NULL) {
- if (debug_mode) printf("\tServer error creating listen socket\n");
+ if (debug_mode) {
+ printf("\tServer error creating listen socket\n");
+ }
return;
}
@@ -106,17 +110,23 @@ static void PRSelectTest(void)
serverAddr.inet.ip = PR_htonl(INADDR_ANY);
if ( PR_Bind(listenSocket, &serverAddr) == PR_FAILURE) {
- if (debug_mode) printf("\tServer error binding to server address\n");
+ if (debug_mode) {
+ printf("\tServer error binding to server address\n");
+ }
PR_Close(listenSocket);
return;
}
if ( PR_Listen(listenSocket, 128) == PR_FAILURE) {
- if (debug_mode) printf("\tServer error listening to server socket\n");
+ if (debug_mode) {
+ printf("\tServer error listening to server socket\n");
+ }
PR_Close(listenSocket);
return;
}
- if (debug_mode) printf("Listening on port %d\n", PORT);
+ if (debug_mode) {
+ printf("Listening on port %d\n", PORT);
+ }
{
PRFileDesc *newSock;
@@ -129,40 +139,60 @@ static void PRSelectTest(void)
loops++;
- if (debug_mode) printf("Going into accept\n");
+ if (debug_mode) {
+ printf("Going into accept\n");
+ }
newSock = PR_Accept(listenSocket,
- &rAddr,
- PR_INTERVAL_NO_TIMEOUT);
+ &rAddr,
+ PR_INTERVAL_NO_TIMEOUT);
- if (newSock) {
- if (debug_mode) printf("Got connection!\n");
+ if (newSock) {
+ if (debug_mode) {
+ printf("Got connection!\n");
+ }
} else {
- if (debug_mode) printf("PR_Accept failed: error code %d\n", PR_GetError());
- else Test_Result (FAIL);
+ if (debug_mode) {
+ printf("PR_Accept failed: error code %d\n", PR_GetError());
+ }
+ else {
+ Test_Result (FAIL);
+ }
}
PR_FD_ZERO(&rdset);
PR_FD_SET(newSock, &rdset);
- if (debug_mode) printf("Going into select \n");
+ if (debug_mode) {
+ printf("Going into select \n");
+ }
rv = PR_Select(0, &rdset, 0, 0, PR_INTERVAL_NO_TIMEOUT);
- if (debug_mode) printf("return from select is %d\n", rv);
+ if (debug_mode) {
+ printf("return from select is %d\n", rv);
+ }
if (PR_FD_ISSET(newSock, &rdset)) {
- if (debug_mode) printf("I can't believe it- the socket is ready okay!\n");
+ if (debug_mode) {
+ printf("I can't believe it- the socket is ready okay!\n");
+ }
} else {
- if (debug_mode) printf("Damn; the select test failed...\n");
- else Test_Result (FAIL);
+ if (debug_mode) {
+ printf("Damn; the select test failed...\n");
+ }
+ else {
+ Test_Result (FAIL);
+ }
}
strcpy(buf, "XXXXXXXXXX");
bytesRead = PR_Recv(newSock, buf, 10, 0, PR_INTERVAL_NO_TIMEOUT);
- buf[10] = '\0';
+ buf[10] = '\0';
- if (debug_mode) printf("Recv completed with %d bytes, %s\n", bytesRead, buf);
+ if (debug_mode) {
+ printf("Recv completed with %d bytes, %s\n", bytesRead, buf);
+ }
PR_Close(newSock);
}
@@ -177,7 +207,9 @@ static void NativeSelectTest(void)
PRNetAddr serverAddr;
if ( (listenSocket = PR_NewTCPSocket()) == NULL) {
- if (debug_mode) printf("\tServer error creating listen socket\n");
+ if (debug_mode) {
+ printf("\tServer error creating listen socket\n");
+ }
return;
}
@@ -187,17 +219,23 @@ static void NativeSelectTest(void)
serverAddr.inet.ip = PR_htonl(INADDR_ANY);
if ( PR_Bind(listenSocket, &serverAddr) == PR_FAILURE) {
- if (debug_mode) printf("\tServer error binding to server address\n");
+ if (debug_mode) {
+ printf("\tServer error binding to server address\n");
+ }
PR_Close(listenSocket);
return;
}
if ( PR_Listen(listenSocket, 128) == PR_FAILURE) {
- if (debug_mode) printf("\tServer error listening to server socket\n");
+ if (debug_mode) {
+ printf("\tServer error listening to server socket\n");
+ }
PR_Close(listenSocket);
return;
}
- if (debug_mode) printf("Listening on port %d\n", PORT);
+ if (debug_mode) {
+ printf("Listening on port %d\n", PORT);
+ }
{
PRIntn osfd;
@@ -210,42 +248,61 @@ static void NativeSelectTest(void)
loops++;
- if (debug_mode) printf("Going into accept\n");
+ if (debug_mode) {
+ printf("Going into accept\n");
+ }
newSock = PR_Accept(listenSocket, &rAddr, PR_INTERVAL_NO_TIMEOUT);
- if (newSock) {
- if (debug_mode) printf("Got connection!\n");
+ if (newSock) {
+ if (debug_mode) {
+ printf("Got connection!\n");
+ }
} else {
- if (debug_mode) printf("PR_Accept failed: error code %d\n", PR_GetError());
- else Test_Result (FAIL);
+ if (debug_mode) {
+ printf("PR_Accept failed: error code %d\n", PR_GetError());
+ }
+ else {
+ Test_Result (FAIL);
+ }
}
osfd = PR_FileDesc2NativeHandle(newSock);
FD_ZERO(&rdset);
FD_SET(osfd, &rdset);
- if (debug_mode) printf("Going into select \n");
+ if (debug_mode) {
+ printf("Going into select \n");
+ }
timeout.tv_sec = 2; timeout.tv_usec = 0;
rv = select(osfd + 1, &rdset, NULL, NULL, &timeout);
- if (debug_mode) printf("return from select is %d\n", rv);
+ if (debug_mode) {
+ printf("return from select is %d\n", rv);
+ }
if (FD_ISSET(osfd, &rdset)) {
- if (debug_mode)
+ if (debug_mode) {
printf("I can't believe it- the socket is ready okay!\n");
+ }
} else {
- if (debug_mode) printf("Damn; the select test failed...\n");
- else Test_Result (FAIL);
+ if (debug_mode) {
+ printf("Damn; the select test failed...\n");
+ }
+ else {
+ Test_Result (FAIL);
+ }
}
strcpy(buf, "XXXXXXXXXX");
bytesRead = PR_Recv(newSock, buf, 10, 0, PR_INTERVAL_NO_TIMEOUT);
- buf[10] = '\0';
+ buf[10] = '\0';
- if (debug_mode) printf("Recv completed with %d bytes, %s\n", bytesRead, buf);
+ if (debug_mode) {
+ printf("Recv completed with %d bytes, %s\n", bytesRead, buf);
+ }
PR_Close(newSock);
}
@@ -269,43 +326,47 @@ static void Measure(void (*func)(void), const char *msg)
d = (double)PR_IntervalToMicroseconds(stop - start);
tot = PR_IntervalToMilliseconds(stop-start);
- if (debug_mode) printf("%40s: %6.2f usec avg, %d msec total\n", msg, d / count, tot);
+ if (debug_mode) {
+ printf("%40s: %6.2f usec avg, %d msec total\n", msg, d / count, tot);
+ }
}
int main(int argc, char **argv)
{
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
+ 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_mode = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- /* main test */
+ /* main test */
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
PR_STDIO_INIT();
if (argc > 2) {
- count = atoi(argv[2]);
+ count = atoi(argv[2]);
} else {
- count = DEFAULT_COUNT;
+ count = DEFAULT_COUNT;
}
#if defined(XP_UNIX)
@@ -315,7 +376,9 @@ int main(int argc, char **argv)
Measure(EmptyNativeSelect, "time to call Empty select()");
Measure(PRSelectTest, "time to call 1 element PR_select()");
- if (!debug_mode) Test_Result (NOSTATUS);
+ if (!debug_mode) {
+ Test_Result (NOSTATUS);
+ }
PR_Cleanup();
diff --git a/pr/tests/sem.c b/pr/tests/sem.c
index 7610b740..80db76d2 100644
--- a/pr/tests/sem.c
+++ b/pr/tests/sem.c
@@ -11,12 +11,12 @@
**
** 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.
***********************************************************************/
/***********************************************************************
@@ -36,8 +36,8 @@ PRIntn failed_already=0;
PRIntn debug_mode;
/*
- Since we don't have stdin, stdout everywhere, we will fake
- it with our in-memory buffers called stdin and stdout.
+ Since we don't have stdin, stdout everywhere, we will fake
+ it with our in-memory buffers called stdin and stdout.
*/
#define SBSIZE 1024
@@ -54,156 +54,169 @@ static PRStatus finalResult = PR_SUCCESS;
static size_t dread (PRUintn device, char *buf, size_t bufSize)
{
- PRUintn i;
-
- /* during first read call, initialize the stdinBuf buffer*/
- if (stdinBufIdx == 0) {
- for (i=0; i<SBSIZE; i++)
- stdinBuf[i] = i;
- }
-
- /* now copy data from stdinBuf to the given buffer upto bufSize */
- for (i=0; i<bufSize; i++) {
- if (stdinBufIdx == SBSIZE)
- break;
- buf[i] = stdinBuf[stdinBufIdx++];
- }
-
- return i;
+ PRUintn i;
+
+ /* during first read call, initialize the stdinBuf buffer*/
+ if (stdinBufIdx == 0) {
+ for (i=0; i<SBSIZE; i++) {
+ stdinBuf[i] = i;
+ }
+ }
+
+ /* now copy data from stdinBuf to the given buffer upto bufSize */
+ for (i=0; i<bufSize; i++) {
+ if (stdinBufIdx == SBSIZE) {
+ break;
+ }
+ buf[i] = stdinBuf[stdinBufIdx++];
+ }
+
+ return i;
}
static size_t dwrite (PRUintn device, char *buf, size_t bufSize)
{
- PRUintn i, j;
-
- /* copy data from the given buffer upto bufSize to stdoutBuf */
- for (i=0; i<bufSize; i++) {
- if (stdoutBufIdx == SBSIZE)
- break;
- stdoutBuf[stdoutBufIdx++] = buf[i];
- }
-
- /* during last write call, compare the two buffers */
- if (stdoutBufIdx == SBSIZE)
- for (j=0; j<SBSIZE; j++)
- if (stdinBuf[j] != stdoutBuf[j]) {
- if (debug_mode) printf("data mismatch for index= %d \n", j);
- finalResult = PR_FAILURE;
- }
-
- return i;
+ PRUintn i, j;
+
+ /* copy data from the given buffer upto bufSize to stdoutBuf */
+ for (i=0; i<bufSize; i++) {
+ if (stdoutBufIdx == SBSIZE) {
+ break;
+ }
+ stdoutBuf[stdoutBufIdx++] = buf[i];
+ }
+
+ /* during last write call, compare the two buffers */
+ if (stdoutBufIdx == SBSIZE)
+ for (j=0; j<SBSIZE; j++)
+ if (stdinBuf[j] != stdoutBuf[j]) {
+ if (debug_mode) {
+ printf("data mismatch for index= %d \n", j);
+ }
+ finalResult = PR_FAILURE;
+ }
+
+ return i;
}
/*------------------ Following is the real test program ---------*/
/*
- Program to copy standard input to standard output. The program
- uses two threads. One reads the input and puts the data in a
- double buffer. The other reads the buffer contents and writes
- it to standard output.
+ Program to copy standard input to standard output. The program
+ uses two threads. One reads the input and puts the data in a
+ double buffer. The other reads the buffer contents and writes
+ it to standard output.
*/
-PRSemaphore *emptyBufs; /* number of empty buffers */
-PRSemaphore *fullBufs; /* number of buffers that are full */
+PRSemaphore *emptyBufs; /* number of empty buffers */
+PRSemaphore *fullBufs; /* number of buffers that are full */
-#define BSIZE 100
+#define BSIZE 100
struct {
- char data[BSIZE];
- PRUintn nbytes; /* number of bytes in this buffer */
+ char data[BSIZE];
+ PRUintn nbytes; /* number of bytes in this buffer */
} buf[2];
static void PR_CALLBACK reader(void *arg)
{
- PRUintn i = 0;
- size_t nbytes;
-
- do {
- (void) PR_WaitSem(emptyBufs);
- nbytes = dread(0, buf[i].data, BSIZE);
- buf[i].nbytes = nbytes;
- PR_PostSem(fullBufs);
- i = (i + 1) % 2;
- } while (nbytes > 0);
+ PRUintn i = 0;
+ size_t nbytes;
+
+ do {
+ (void) PR_WaitSem(emptyBufs);
+ nbytes = dread(0, buf[i].data, BSIZE);
+ buf[i].nbytes = nbytes;
+ PR_PostSem(fullBufs);
+ i = (i + 1) % 2;
+ } while (nbytes > 0);
}
static void writer(void)
{
- PRUintn i = 0;
- size_t nbytes;
-
- do {
- (void) PR_WaitSem(fullBufs);
- nbytes = buf[i].nbytes;
- if (nbytes > 0) {
- nbytes = dwrite(1, buf[i].data, nbytes);
- PR_PostSem(emptyBufs);
- i = (i + 1) % 2;
- }
- } while (nbytes > 0);
+ PRUintn i = 0;
+ size_t nbytes;
+
+ do {
+ (void) PR_WaitSem(fullBufs);
+ nbytes = buf[i].nbytes;
+ if (nbytes > 0) {
+ nbytes = dwrite(1, buf[i].data, nbytes);
+ PR_PostSem(emptyBufs);
+ i = (i + 1) % 2;
+ }
+ } while (nbytes > 0);
}
int main(int argc, char **argv)
{
- PRThread *r;
+ PRThread *r;
PR_STDIO_INIT();
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
{
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
+ 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_mode = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
}
- /* main test */
+ /* main test */
- emptyBufs = PR_NewSem(2); /* two empty buffers */
+ emptyBufs = PR_NewSem(2); /* two empty buffers */
- fullBufs = PR_NewSem(0); /* zero full buffers */
+ fullBufs = PR_NewSem(0); /* zero full buffers */
- /* create the reader thread */
+ /* create the reader thread */
- r = PR_CreateThread(PR_USER_THREAD,
- reader, 0,
- PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0);
+ r = PR_CreateThread(PR_USER_THREAD,
+ reader, 0,
+ PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0);
- /* Do the writer operation in this thread */
- writer();
+ /* Do the writer operation in this thread */
+ writer();
- PR_DestroySem(emptyBufs);
- PR_DestroySem(fullBufs);
+ PR_DestroySem(emptyBufs);
+ PR_DestroySem(fullBufs);
- if (finalResult == PR_SUCCESS) {
- if (debug_mode) printf("sem Test Passed.\n");
- }
- else{
- if (debug_mode) printf("sem Test Failed.\n");
- failed_already=1;
- }
+ if (finalResult == PR_SUCCESS) {
+ if (debug_mode) {
+ printf("sem Test Passed.\n");
+ }
+ }
+ else {
+ if (debug_mode) {
+ printf("sem Test Failed.\n");
+ }
+ failed_already=1;
+ }
PR_Cleanup();
- if(failed_already)
- return 1;
- else
- return 0;
+ if(failed_already) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
}
diff --git a/pr/tests/sema.c b/pr/tests/sema.c
index 915fa30f..76198eb0 100644
--- a/pr/tests/sema.c
+++ b/pr/tests/sema.c
@@ -31,7 +31,9 @@ void ThreadFunc(void *arg)
exit(1);
}
if (counter == 2*i+1) {
- if (debug_mode) printf("thread 2: counter = %d\n", counter);
+ if (debug_mode) {
+ printf("thread 2: counter = %d\n", counter);
+ }
} else {
fprintf(stderr, "thread 2: counter should be %d but is %d\n",
2*i+1, counter);
@@ -61,7 +63,9 @@ int main(int argc, char **argv)
PLOptState *opt = PL_CreateOptState(argc, argv, "dc:h");
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_mode = PR_TRUE;
@@ -98,7 +102,7 @@ int main(int argc, char **argv)
exit(1);
}
thred = PR_CreateThread(PR_USER_THREAD, ThreadFunc, NULL,
- PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
if (NULL == thred) {
fprintf(stderr, "PR_CreateThread failed\n");
exit(1);
@@ -113,7 +117,9 @@ int main(int argc, char **argv)
exit(1);
}
if (counter == 2*i) {
- if (debug_mode) printf("thread 1: counter = %d\n", counter);
+ if (debug_mode) {
+ printf("thread 1: counter = %d\n", counter);
+ }
} else {
fprintf(stderr, "thread 1: counter should be %d but is %d\n",
2*i, counter);
diff --git a/pr/tests/semaerr.c b/pr/tests/semaerr.c
index 4da7c1c1..4e6a8ff2 100644
--- a/pr/tests/semaerr.c
+++ b/pr/tests/semaerr.c
@@ -33,7 +33,9 @@ int main(int argc, char **argv)
PRInt32 exit_code;
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_mode = PR_TRUE;
diff --git a/pr/tests/semaerr1.c b/pr/tests/semaerr1.c
index 0d839371..b2e49872 100644
--- a/pr/tests/semaerr1.c
+++ b/pr/tests/semaerr1.c
@@ -28,7 +28,9 @@ int main(int argc, char **argv)
PRSem *sem;
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_mode = PR_TRUE;
diff --git a/pr/tests/semaping.c b/pr/tests/semaping.c
index 60be8dea..2f31bd0b 100644
--- a/pr/tests/semaping.c
+++ b/pr/tests/semaping.c
@@ -42,7 +42,9 @@ int main(int argc, char **argv)
PLOptState *opt = PL_CreateOptState(argc, argv, "dc:h");
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_mode = PR_TRUE;
@@ -122,7 +124,9 @@ int main(int argc, char **argv)
exit(1);
}
if (*counter_addr == 2*i) {
- if (debug_mode) printf("process 1: counter = %d\n", *counter_addr);
+ if (debug_mode) {
+ printf("process 1: counter = %d\n", *counter_addr);
+ }
} else {
fprintf(stderr, "process 1: counter should be %d but is %d\n",
2*i, *counter_addr);
diff --git a/pr/tests/semapong.c b/pr/tests/semapong.c
index 37940dd4..954f90f1 100644
--- a/pr/tests/semapong.c
+++ b/pr/tests/semapong.c
@@ -34,7 +34,9 @@ int main(int argc, char **argv)
PLOptState *opt = PL_CreateOptState(argc, argv, "dc:h");
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_mode = PR_TRUE;
@@ -84,7 +86,9 @@ int main(int argc, char **argv)
exit(1);
}
if (*counter_addr == 2*i+1) {
- if (debug_mode) printf("process 2: counter = %d\n", *counter_addr);
+ if (debug_mode) {
+ printf("process 2: counter = %d\n", *counter_addr);
+ }
} else {
fprintf(stderr, "process 2: counter should be %d but is %d\n",
2*i+1, *counter_addr);
diff --git a/pr/tests/sendzlf.c b/pr/tests/sendzlf.c
index 8b4b5680..a65f6cd6 100644
--- a/pr/tests/sendzlf.c
+++ b/pr/tests/sendzlf.c
@@ -63,7 +63,7 @@ static void ClientThread(void *arg)
exit(1);
}
if (memcmp(buf, HEADER_STR TRAILER_STR TRAILER_STR HEADER_STR HEADER_STR,
- nexpected) != 0) {
+ nexpected) != 0) {
fprintf(stderr, "wrong data is received\n");
exit(1);
}
@@ -84,7 +84,7 @@ static void ServerThread(void *arg)
/* Create a zero-length file */
file = PR_Open(ZERO_LEN_FILE_NAME,
- PR_CREATE_FILE|PR_TRUNCATE|PR_RDWR, 0666);
+ PR_CREATE_FILE|PR_TRUNCATE|PR_RDWR, 0666);
if (NULL == file) {
fprintf(stderr, "PR_Open failed\n");
exit(1);
@@ -105,7 +105,7 @@ static void ServerThread(void *arg)
}
/* Send both header and trailer */
nbytes = PR_SendFile(acceptSock, &sfd, PR_TRANSMITFILE_KEEP_OPEN,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
if (HEADER_LEN+TRAILER_LEN != nbytes) {
fprintf(stderr, "PR_SendFile should return %d but returned %d\n",
HEADER_LEN+TRAILER_LEN, nbytes);
@@ -114,7 +114,7 @@ static void ServerThread(void *arg)
/* Trailer only, no header */
sfd.hlen = 0;
nbytes = PR_SendFile(acceptSock, &sfd, PR_TRANSMITFILE_KEEP_OPEN,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
if (TRAILER_LEN != nbytes) {
fprintf(stderr, "PR_SendFile should return %d but returned %d\n",
TRAILER_LEN, nbytes);
@@ -124,7 +124,7 @@ static void ServerThread(void *arg)
sfd.hlen = HEADER_LEN;
sfd.tlen = 0;
nbytes = PR_SendFile(acceptSock, &sfd, PR_TRANSMITFILE_KEEP_OPEN,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
if (HEADER_LEN != nbytes) {
fprintf(stderr, "PR_SendFile should return %d but returned %d\n",
HEADER_LEN, nbytes);
@@ -132,7 +132,7 @@ static void ServerThread(void *arg)
}
/* Try PR_TransmitFile */
nbytes = PR_TransmitFile(acceptSock, file, header, HEADER_LEN,
- PR_TRANSMITFILE_KEEP_OPEN, PR_INTERVAL_NO_TIMEOUT);
+ PR_TRANSMITFILE_KEEP_OPEN, PR_INTERVAL_NO_TIMEOUT);
if (HEADER_LEN != nbytes) {
fprintf(stderr, "PR_TransmitFile should return %d but returned %d\n",
HEADER_LEN, nbytes);
@@ -184,15 +184,15 @@ int main(int argc, char **argv)
}
clientThread = PR_CreateThread(PR_USER_THREAD,
- ClientThread, (void *) PR_ntohs(PR_NetAddrInetPort(&addr)),
- PR_PRIORITY_NORMAL, scope, PR_JOINABLE_THREAD, 0);
+ ClientThread, (void *) PR_ntohs(PR_NetAddrInetPort(&addr)),
+ PR_PRIORITY_NORMAL, scope, PR_JOINABLE_THREAD, 0);
if (NULL == clientThread) {
fprintf(stderr, "PR_CreateThread failed\n");
exit(1);
}
serverThread = PR_CreateThread(PR_USER_THREAD,
- ServerThread, listenSock,
- PR_PRIORITY_NORMAL, scope, PR_JOINABLE_THREAD, 0);
+ ServerThread, listenSock,
+ PR_PRIORITY_NORMAL, scope, PR_JOINABLE_THREAD, 0);
if (NULL == serverThread) {
fprintf(stderr, "PR_CreateThread failed\n");
exit(1);
diff --git a/pr/tests/server_test.c b/pr/tests/server_test.c
index 3840c828..93ffe4af 100644
--- a/pr/tests/server_test.c
+++ b/pr/tests/server_test.c
@@ -14,10 +14,10 @@
**
** Modification History:
** 19-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.
***********************************************************************/
/***********************************************************************
@@ -68,7 +68,7 @@ PRCondVar *ServerStateCV;
/***********************************************************************
** PRIVATE FUNCTION: Test_Result
** DESCRIPTION: Used in conjunction with the regress tool, prints out the
-** status of the test case.
+** status of the test case.
** INPUTS: PASS/FAIL
** OUTPUTS: None
** RETURN: None
@@ -84,18 +84,18 @@ PRCondVar *ServerStateCV;
static void Test_Result (int result)
{
- switch (result)
- {
- case PASS:
- printf ("PASS\n");
- break;
- case FAIL:
- printf ("FAIL\n");
- failed_already = 1;
- break;
- default:
- break;
- }
+ switch (result)
+ {
+ case PASS:
+ printf ("PASS\n");
+ break;
+ case FAIL:
+ printf ("FAIL\n");
+ failed_already = 1;
+ break;
+ default:
+ break;
+ }
}
static void do_work(void);
@@ -108,7 +108,9 @@ SetServerState(char *waiter, PRInt32 state)
ServerState = state;
PR_NotifyCondVar(ServerStateCV);
- if (debug_mode) DPRINTF("\t%s changed state to %d\n", waiter, state);
+ if (debug_mode) {
+ DPRINTF("\t%s changed state to %d\n", waiter, state);
+ }
PR_Unlock(ServerStateCVLock);
}
@@ -120,14 +122,17 @@ WaitServerState(char *waiter, PRInt32 state)
PR_Lock(ServerStateCVLock);
- if (debug_mode) DPRINTF("\t%s waiting for state %d\n", waiter, state);
+ if (debug_mode) {
+ DPRINTF("\t%s waiting for state %d\n", waiter, state);
+ }
- while(!(ServerState & state))
+ while(!(ServerState & state)) {
PR_WaitCondVar(ServerStateCV, PR_INTERVAL_NO_TIMEOUT);
+ }
rv = ServerState;
if (debug_mode) DPRINTF("\t%s resuming from wait for state %d; state now %d\n",
- waiter, state, ServerState);
+ waiter, state, ServerState);
PR_Unlock(ServerStateCVLock);
return rv;
@@ -149,15 +154,21 @@ WorkerThreadFunc(void *_listenSock)
char *sendBuf;
if (debug_mode) DPRINTF("\tServer buffer is %d bytes; %d data, %d netaddrs\n",
- _client_data+(2*sizeof(PRNetAddr))+32, _client_data, (2*sizeof(PRNetAddr))+32);
+ _client_data+(2*sizeof(PRNetAddr))+32, _client_data, (2*sizeof(PRNetAddr))+32);
dataBuf = (char *)PR_MALLOC(_client_data + 2*sizeof(PRNetAddr) + 32);
if (!dataBuf)
- if (debug_mode) printf("\tServer could not malloc space!?\n");
+ if (debug_mode) {
+ printf("\tServer could not malloc space!?\n");
+ }
sendBuf = (char *)PR_MALLOC(_server_data *sizeof(char));
if (!sendBuf)
- if (debug_mode) printf("\tServer could not malloc space!?\n");
+ if (debug_mode) {
+ printf("\tServer could not malloc space!?\n");
+ }
- if (debug_mode) DPRINTF("\tServer worker thread running\n");
+ if (debug_mode) {
+ DPRINTF("\tServer worker thread running\n");
+ }
while(1) {
PRInt32 bytesToRead = _client_data;
@@ -168,7 +179,9 @@ WorkerThreadFunc(void *_listenSock)
loops++;
- if (debug_mode) DPRINTF("\tServer thread going into accept\n");
+ if (debug_mode) {
+ DPRINTF("\tServer thread going into accept\n");
+ }
bytesRead = PR_AcceptRead(listenSock,
&newSock,
@@ -178,11 +191,15 @@ WorkerThreadFunc(void *_listenSock)
PR_INTERVAL_NO_TIMEOUT);
if (bytesRead < 0) {
- if (debug_mode) printf("\tServer error in accept (%d)\n", bytesRead);
+ if (debug_mode) {
+ printf("\tServer error in accept (%d)\n", bytesRead);
+ }
continue;
}
- if (debug_mode) DPRINTF("\tServer accepted connection (%d bytes)\n", bytesRead);
+ if (debug_mode) {
+ DPRINTF("\tServer accepted connection (%d bytes)\n", bytesRead);
+ }
PR_AtomicIncrement(&workerThreadsBusy);
if (workerThreadsBusy == workerThreads) {
@@ -191,19 +208,23 @@ WorkerThreadFunc(void *_listenSock)
PRThread *WorkerThread;
WorkerThread = PR_CreateThread(
- PR_SYSTEM_THREAD,
- WorkerThreadFunc,
- listenSock,
- PR_PRIORITY_NORMAL,
- ServerScope,
- PR_UNJOINABLE_THREAD,
- THREAD_STACKSIZE);
+ PR_SYSTEM_THREAD,
+ WorkerThreadFunc,
+ listenSock,
+ PR_PRIORITY_NORMAL,
+ ServerScope,
+ PR_UNJOINABLE_THREAD,
+ THREAD_STACKSIZE);
if (!WorkerThread) {
- if (debug_mode) printf("Error creating client thread %d\n", workerThreads);
+ if (debug_mode) {
+ printf("Error creating client thread %d\n", workerThreads);
+ }
} else {
PR_AtomicIncrement(&workerThreads);
- if (debug_mode) DPRINTF("\tServer creates worker (%d)\n", workerThreads);
+ if (debug_mode) {
+ DPRINTF("\tServer creates worker (%d)\n", workerThreads);
+ }
}
}
PR_Unlock(workerThreadsLock);
@@ -217,10 +238,14 @@ WorkerThreadFunc(void *_listenSock)
0,
PR_INTERVAL_NO_TIMEOUT);
if (bytesRead < 0) {
- if (debug_mode) printf("\tServer error receiving data (%d)\n", bytesRead);
+ if (debug_mode) {
+ printf("\tServer error receiving data (%d)\n", bytesRead);
+ }
continue;
}
- if (debug_mode) DPRINTF("\tServer received %d bytes\n", bytesRead);
+ if (debug_mode) {
+ DPRINTF("\tServer received %d bytes\n", bytesRead);
+ }
}
bytesWritten = PR_Send(newSock,
@@ -230,9 +255,11 @@ WorkerThreadFunc(void *_listenSock)
PR_INTERVAL_NO_TIMEOUT);
if (bytesWritten != _server_data) {
if (debug_mode) printf("\tError sending data to client (%d, %d)\n",
- bytesWritten, PR_GetOSError());
+ bytesWritten, PR_GetOSError());
} else {
- if (debug_mode) DPRINTF("\tServer sent %d bytes\n", bytesWritten);
+ if (debug_mode) {
+ DPRINTF("\tServer sent %d bytes\n", bytesWritten);
+ }
}
PR_Close(newSock);
@@ -249,8 +276,12 @@ ServerSetup(void)
PRThread *WorkerThread;
if ((listenSocket = PR_NewTCPSocket()) == NULL) {
- if (debug_mode) printf("\tServer error creating listen socket\n");
- else Test_Result(FAIL);
+ if (debug_mode) {
+ printf("\tServer error creating listen socket\n");
+ }
+ else {
+ Test_Result(FAIL);
+ }
return NULL;
}
@@ -258,8 +289,10 @@ ServerSetup(void)
sockOpt.value.reuse_addr = PR_TRUE;
if (PR_SetSocketOption(listenSocket, &sockOpt) != PR_SUCCESS) {
if (debug_mode) printf("\tServer error setting socket option: OS error %d\n",
- PR_GetOSError());
- else Test_Result(FAIL);
+ PR_GetOSError());
+ else {
+ Test_Result(FAIL);
+ }
PR_Close(listenSocket);
return NULL;
}
@@ -271,15 +304,21 @@ ServerSetup(void)
if (PR_Bind(listenSocket, &serverAddr) != PR_SUCCESS) {
if (debug_mode) printf("\tServer error binding to server address: OS error %d\n",
- PR_GetOSError());
- else Test_Result(FAIL);
+ PR_GetOSError());
+ else {
+ Test_Result(FAIL);
+ }
PR_Close(listenSocket);
return NULL;
}
if (PR_Listen(listenSocket, 128) != PR_SUCCESS) {
- if (debug_mode) printf("\tServer error listening to server socket\n");
- else Test_Result(FAIL);
+ if (debug_mode) {
+ printf("\tServer error listening to server socket\n");
+ }
+ else {
+ Test_Result(FAIL);
+ }
PR_Close(listenSocket);
return NULL;
@@ -292,21 +331,25 @@ ServerSetup(void)
workerThreadsLock = PR_NewLock();
WorkerThread = PR_CreateThread(
- PR_SYSTEM_THREAD,
- WorkerThreadFunc,
- listenSocket,
- PR_PRIORITY_NORMAL,
- ServerScope,
- PR_UNJOINABLE_THREAD,
- THREAD_STACKSIZE);
+ PR_SYSTEM_THREAD,
+ WorkerThreadFunc,
+ listenSocket,
+ PR_PRIORITY_NORMAL,
+ ServerScope,
+ PR_UNJOINABLE_THREAD,
+ THREAD_STACKSIZE);
if (!WorkerThread) {
- if (debug_mode) printf("error creating working thread\n");
+ if (debug_mode) {
+ printf("error creating working thread\n");
+ }
PR_Close(listenSocket);
return NULL;
}
PR_AtomicIncrement(&workerThreads);
- if (debug_mode) DPRINTF("\tServer created primordial worker thread\n");
+ if (debug_mode) {
+ DPRINTF("\tServer created primordial worker thread\n");
+ }
return listenSocket;
}
@@ -324,7 +367,9 @@ ServerThreadFunc(void *unused)
SetServerState(SERVER, SERVER_STATE_DEAD);
} else {
- if (debug_mode) DPRINTF("\tServer up\n");
+ if (debug_mode) {
+ DPRINTF("\tServer up\n");
+ }
/* Tell clients they can start now. */
SetServerState(SERVER, SERVER_STATE_READY);
@@ -355,10 +400,14 @@ ClientThreadFunc(void *unused)
sendBuf = (char *)PR_MALLOC(_client_data * sizeof(char));
if (!sendBuf)
- if (debug_mode) printf("\tClient could not malloc space!?\n");
+ if (debug_mode) {
+ printf("\tClient could not malloc space!?\n");
+ }
recvBuf = (char *)PR_MALLOC(_server_data * sizeof(char));
if (!recvBuf)
- if (debug_mode) printf("\tClient could not malloc space!?\n");
+ if (debug_mode) {
+ printf("\tClient could not malloc space!?\n");
+ }
memset(&serverAddr, 0, sizeof(PRNetAddr));
serverAddr.inet.family = PR_AF_INET;
@@ -368,27 +417,37 @@ ClientThreadFunc(void *unused)
while(numRequests > 0) {
if ( (numRequests % 10) == 0 )
- if (debug_mode) printf(".");
- if (debug_mode) DPRINTF("\tClient starting request %d\n", numRequests);
+ if (debug_mode) {
+ printf(".");
+ }
+ if (debug_mode) {
+ DPRINTF("\tClient starting request %d\n", numRequests);
+ }
clientSocket = PR_NewTCPSocket();
if (!clientSocket) {
if (debug_mode) printf("Client error creating socket: OS error %d\n",
- PR_GetOSError());
+ PR_GetOSError());
continue;
}
- if (debug_mode) DPRINTF("\tClient connecting\n");
+ if (debug_mode) {
+ DPRINTF("\tClient connecting\n");
+ }
rv = PR_Connect(clientSocket,
&serverAddr,
PR_INTERVAL_NO_TIMEOUT);
if (!clientSocket) {
- if (debug_mode) printf("\tClient error connecting\n");
+ if (debug_mode) {
+ printf("\tClient error connecting\n");
+ }
continue;
}
- if (debug_mode) DPRINTF("\tClient connected\n");
+ if (debug_mode) {
+ DPRINTF("\tClient connected\n");
+ }
rv = PR_Send(clientSocket,
sendBuf,
@@ -396,12 +455,16 @@ ClientThreadFunc(void *unused)
0,
PR_INTERVAL_NO_TIMEOUT);
if (rv != _client_data) {
- if (debug_mode) printf("Client error sending data (%d)\n", rv);
+ if (debug_mode) {
+ printf("Client error sending data (%d)\n", rv);
+ }
PR_Close(clientSocket);
continue;
}
- if (debug_mode) DPRINTF("\tClient sent %d bytes\n", rv);
+ if (debug_mode) {
+ DPRINTF("\tClient sent %d bytes\n", rv);
+ }
bytesNeeded = _server_data;
while(bytesNeeded) {
@@ -412,10 +475,12 @@ ClientThreadFunc(void *unused)
PR_INTERVAL_NO_TIMEOUT);
if (rv <= 0) {
if (debug_mode) printf("Client error receiving data (%d) (%d/%d)\n",
- rv, (_server_data - bytesNeeded), _server_data);
+ rv, (_server_data - bytesNeeded), _server_data);
break;
}
- if (debug_mode) DPRINTF("\tClient received %d bytes; need %d more\n", rv, bytesNeeded - rv);
+ if (debug_mode) {
+ DPRINTF("\tClient received %d bytes; need %d more\n", rv, bytesNeeded - rv);
+ }
bytesNeeded -= rv;
}
@@ -447,24 +512,28 @@ RunClients(void)
clientThread = PR_CreateThread(
- PR_USER_THREAD,
- ClientThreadFunc,
- NULL,
- PR_PRIORITY_NORMAL,
- ClientScope,
- PR_UNJOINABLE_THREAD,
- THREAD_STACKSIZE);
+ PR_USER_THREAD,
+ ClientThreadFunc,
+ NULL,
+ PR_PRIORITY_NORMAL,
+ ClientScope,
+ PR_UNJOINABLE_THREAD,
+ THREAD_STACKSIZE);
if (!clientThread) {
- if (debug_mode) printf("\terror creating client thread %d\n", index);
- } else
- if (debug_mode) DPRINTF("\tMain created client %d/%d\n", index+1, _clients);
+ if (debug_mode) {
+ printf("\terror creating client thread %d\n", index);
+ }
+ } else if (debug_mode) {
+ DPRINTF("\tMain created client %d/%d\n", index+1, _clients);
+ }
}
PR_EnterMonitor(clientMonitor);
- while(numClients)
+ while(numClients) {
PR_Wait(clientMonitor, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_ExitMonitor(clientMonitor);
}
@@ -478,15 +547,17 @@ void do_work()
SetServerState(MAIN, SERVER_STATE_STARTUP);
ServerThread = PR_CreateThread(
- PR_USER_THREAD,
- ServerThreadFunc,
- NULL,
- PR_PRIORITY_NORMAL,
- ServerScope,
- PR_JOINABLE_THREAD,
- THREAD_STACKSIZE);
+ PR_USER_THREAD,
+ ServerThreadFunc,
+ NULL,
+ PR_PRIORITY_NORMAL,
+ ServerScope,
+ PR_JOINABLE_THREAD,
+ THREAD_STACKSIZE);
if (!ServerThread) {
- if (debug_mode) printf("error creating main server thread\n");
+ if (debug_mode) {
+ printf("error creating main server thread\n");
+ }
return;
}
@@ -544,60 +615,64 @@ static void Measure(void (*func)(void), const char *msg)
d = (double)PR_IntervalToMicroseconds(stop - start);
- if (debug_mode) printf("\n%40s: %6.2f usec\n", msg, d / _iterations);
+ if (debug_mode) {
+ printf("\n%40s: %6.2f usec\n", msg, d / _iterations);
+ }
}
int main(int argc, char **argv)
{
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "d");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "d");
+ 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_mode = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- /* main test */
+ /* main test */
if (debug_mode) {
- printf("Enter number of iterations: \n");
- scanf("%d", &_iterations);
- printf("Enter number of clients : \n");
- scanf("%d", &_clients);
- printf("Enter size of client data : \n");
- scanf("%d", &_client_data);
- printf("Enter size of server data : \n");
- scanf("%d", &_server_data);
- }
- else
- {
-
- _iterations = 10;
- _clients = 1;
- _client_data = 10;
- _server_data = 10;
- }
+ printf("Enter number of iterations: \n");
+ scanf("%d", &_iterations);
+ printf("Enter number of clients : \n");
+ scanf("%d", &_clients);
+ printf("Enter size of client data : \n");
+ scanf("%d", &_client_data);
+ printf("Enter size of server data : \n");
+ scanf("%d", &_server_data);
+ }
+ else
+ {
+
+ _iterations = 10;
+ _clients = 1;
+ _client_data = 10;
+ _server_data = 10;
+ }
if (debug_mode) {
- printf("\n\n%d iterations with %d client threads.\n",
- _iterations, _clients);
- printf("Sending %d bytes of client data and %d bytes of server data\n",
- _client_data, _server_data);
- }
+ printf("\n\n%d iterations with %d client threads.\n",
+ _iterations, _clients);
+ printf("Sending %d bytes of client data and %d bytes of server data\n",
+ _client_data, _server_data);
+ }
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
PR_STDIO_INIT();
@@ -605,11 +680,11 @@ int main(int argc, char **argv)
ServerStateCV = PR_NewCondVar(ServerStateCVLock);
Measure(do_workUU, "server loop user/user");
- #if 0
+#if 0
Measure(do_workUK, "server loop user/kernel");
Measure(do_workKU, "server loop kernel/user");
Measure(do_workKK, "server loop kernel/kernel");
- #endif
+#endif
PR_Cleanup();
diff --git a/pr/tests/servr_kk.c b/pr/tests/servr_kk.c
index 8fd59b26..06f4fae1 100644
--- a/pr/tests/servr_kk.c
+++ b/pr/tests/servr_kk.c
@@ -14,12 +14,12 @@
**
** Modification History:
** 19-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.
***********************************************************************/
/***********************************************************************
@@ -72,7 +72,9 @@ SetServerState(char *waiter, PRInt32 state)
ServerState = state;
PR_NotifyCondVar(ServerStateCV);
- if (debug_mode) DPRINTF("\t%s changed state to %d\n", waiter, state);
+ if (debug_mode) {
+ DPRINTF("\t%s changed state to %d\n", waiter, state);
+ }
PR_Unlock(ServerStateCVLock);
}
@@ -84,14 +86,17 @@ WaitServerState(char *waiter, PRInt32 state)
PR_Lock(ServerStateCVLock);
- if (debug_mode) DPRINTF("\t%s waiting for state %d\n", waiter, state);
+ if (debug_mode) {
+ DPRINTF("\t%s waiting for state %d\n", waiter, state);
+ }
- while(!(ServerState & state))
+ while(!(ServerState & state)) {
PR_WaitCondVar(ServerStateCV, PR_INTERVAL_NO_TIMEOUT);
+ }
rv = ServerState;
if (debug_mode) DPRINTF("\t%s resuming from wait for state %d; state now %d\n",
- waiter, state, ServerState);
+ waiter, state, ServerState);
PR_Unlock(ServerStateCVLock);
return rv;
@@ -113,15 +118,21 @@ WorkerThreadFunc(void *_listenSock)
char *sendBuf;
if (debug_mode) DPRINTF("\tServer buffer is %d bytes; %d data, %d netaddrs\n",
- _client_data+(2*sizeof(PRNetAddr))+32, _client_data, (2*sizeof(PRNetAddr))+32);
+ _client_data+(2*sizeof(PRNetAddr))+32, _client_data, (2*sizeof(PRNetAddr))+32);
dataBuf = (char *)PR_MALLOC(_client_data + 2*sizeof(PRNetAddr) + 32);
if (!dataBuf)
- if (debug_mode) printf("\tServer could not malloc space!?\n");
+ if (debug_mode) {
+ printf("\tServer could not malloc space!?\n");
+ }
sendBuf = (char *)PR_MALLOC(_server_data *sizeof(char));
if (!sendBuf)
- if (debug_mode) printf("\tServer could not malloc space!?\n");
+ if (debug_mode) {
+ printf("\tServer could not malloc space!?\n");
+ }
- if (debug_mode) DPRINTF("\tServer worker thread running\n");
+ if (debug_mode) {
+ DPRINTF("\tServer worker thread running\n");
+ }
while(1) {
PRInt32 bytesToRead = _client_data;
@@ -132,7 +143,9 @@ WorkerThreadFunc(void *_listenSock)
loops++;
- if (debug_mode) DPRINTF("\tServer thread going into accept\n");
+ if (debug_mode) {
+ DPRINTF("\tServer thread going into accept\n");
+ }
bytesRead = PR_AcceptRead(listenSock,
&newSock,
@@ -142,11 +155,15 @@ WorkerThreadFunc(void *_listenSock)
PR_INTERVAL_NO_TIMEOUT);
if (bytesRead < 0) {
- if (debug_mode) printf("\tServer error in accept (%d)\n", bytesRead);
+ if (debug_mode) {
+ printf("\tServer error in accept (%d)\n", bytesRead);
+ }
continue;
}
- if (debug_mode) DPRINTF("\tServer accepted connection (%d bytes)\n", bytesRead);
+ if (debug_mode) {
+ DPRINTF("\tServer accepted connection (%d bytes)\n", bytesRead);
+ }
PR_AtomicIncrement(&workerThreadsBusy);
if (workerThreadsBusy == workerThreads) {
@@ -155,19 +172,23 @@ WorkerThreadFunc(void *_listenSock)
PRThread *WorkerThread;
WorkerThread = PR_CreateThread(
- PR_SYSTEM_THREAD,
- WorkerThreadFunc,
- listenSock,
- PR_PRIORITY_NORMAL,
- ServerScope,
- PR_UNJOINABLE_THREAD,
- THREAD_STACKSIZE);
+ PR_SYSTEM_THREAD,
+ WorkerThreadFunc,
+ listenSock,
+ PR_PRIORITY_NORMAL,
+ ServerScope,
+ PR_UNJOINABLE_THREAD,
+ THREAD_STACKSIZE);
if (!WorkerThread) {
- if (debug_mode) printf("Error creating client thread %d\n", workerThreads);
+ if (debug_mode) {
+ printf("Error creating client thread %d\n", workerThreads);
+ }
} else {
PR_AtomicIncrement(&workerThreads);
- if (debug_mode) DPRINTF("\tServer creates worker (%d)\n", workerThreads);
+ if (debug_mode) {
+ DPRINTF("\tServer creates worker (%d)\n", workerThreads);
+ }
}
}
PR_Unlock(workerThreadsLock);
@@ -181,10 +202,14 @@ WorkerThreadFunc(void *_listenSock)
0,
PR_INTERVAL_NO_TIMEOUT);
if (bytesRead < 0) {
- if (debug_mode) printf("\tServer error receiving data (%d)\n", bytesRead);
+ if (debug_mode) {
+ printf("\tServer error receiving data (%d)\n", bytesRead);
+ }
continue;
}
- if (debug_mode) DPRINTF("\tServer received %d bytes\n", bytesRead);
+ if (debug_mode) {
+ DPRINTF("\tServer received %d bytes\n", bytesRead);
+ }
}
bytesWritten = PR_Send(newSock,
@@ -194,9 +219,11 @@ WorkerThreadFunc(void *_listenSock)
PR_INTERVAL_NO_TIMEOUT);
if (bytesWritten != _server_data) {
if (debug_mode) printf("\tError sending data to client (%d, %d)\n",
- bytesWritten, PR_GetOSError());
+ bytesWritten, PR_GetOSError());
} else {
- if (debug_mode) DPRINTF("\tServer sent %d bytes\n", bytesWritten);
+ if (debug_mode) {
+ DPRINTF("\tServer sent %d bytes\n", bytesWritten);
+ }
}
PR_Close(newSock);
@@ -213,8 +240,12 @@ ServerSetup(void)
PRThread *WorkerThread;
if ( (listenSocket = PR_NewTCPSocket()) == NULL) {
- if (debug_mode) printf("\tServer error creating listen socket\n");
- else failed_already=1;
+ if (debug_mode) {
+ printf("\tServer error creating listen socket\n");
+ }
+ else {
+ failed_already=1;
+ }
return NULL;
}
@@ -222,8 +253,10 @@ ServerSetup(void)
sockOpt.value.reuse_addr = PR_TRUE;
if ( PR_SetSocketOption(listenSocket, &sockOpt) == PR_FAILURE) {
if (debug_mode) printf("\tServer error setting socket option: OS error %d\n",
- PR_GetOSError());
- else failed_already=1;
+ PR_GetOSError());
+ else {
+ failed_already=1;
+ }
PR_Close(listenSocket);
return NULL;
}
@@ -235,15 +268,21 @@ ServerSetup(void)
if ( PR_Bind(listenSocket, &serverAddr) == PR_FAILURE) {
if (debug_mode) printf("\tServer error binding to server address: OS error %d\n",
- PR_GetOSError());
- else failed_already=1;
+ PR_GetOSError());
+ else {
+ failed_already=1;
+ }
PR_Close(listenSocket);
return NULL;
}
if ( PR_Listen(listenSocket, 128) == PR_FAILURE) {
- if (debug_mode) printf("\tServer error listening to server socket\n");
- else failed_already=1;
+ if (debug_mode) {
+ printf("\tServer error listening to server socket\n");
+ }
+ else {
+ failed_already=1;
+ }
PR_Close(listenSocket);
return NULL;
@@ -256,21 +295,25 @@ ServerSetup(void)
workerThreadsLock = PR_NewLock();
WorkerThread = PR_CreateThread(
- PR_SYSTEM_THREAD,
- WorkerThreadFunc,
- listenSocket,
- PR_PRIORITY_NORMAL,
- ServerScope,
- PR_UNJOINABLE_THREAD,
- THREAD_STACKSIZE);
+ PR_SYSTEM_THREAD,
+ WorkerThreadFunc,
+ listenSocket,
+ PR_PRIORITY_NORMAL,
+ ServerScope,
+ PR_UNJOINABLE_THREAD,
+ THREAD_STACKSIZE);
if (!WorkerThread) {
- if (debug_mode) printf("error creating working thread\n");
+ if (debug_mode) {
+ printf("error creating working thread\n");
+ }
PR_Close(listenSocket);
return NULL;
}
PR_AtomicIncrement(&workerThreads);
- if (debug_mode) DPRINTF("\tServer created primordial worker thread\n");
+ if (debug_mode) {
+ DPRINTF("\tServer created primordial worker thread\n");
+ }
return listenSocket;
}
@@ -288,7 +331,9 @@ ServerThreadFunc(void *unused)
SetServerState(SERVER, SERVER_STATE_DEAD);
} else {
- if (debug_mode) DPRINTF("\tServer up\n");
+ if (debug_mode) {
+ DPRINTF("\tServer up\n");
+ }
/* Tell clients they can start now. */
SetServerState(SERVER, SERVER_STATE_READY);
@@ -319,10 +364,14 @@ ClientThreadFunc(void *unused)
sendBuf = (char *)PR_MALLOC(_client_data * sizeof(char));
if (!sendBuf)
- if (debug_mode) printf("\tClient could not malloc space!?\n");
+ if (debug_mode) {
+ printf("\tClient could not malloc space!?\n");
+ }
recvBuf = (char *)PR_MALLOC(_server_data * sizeof(char));
if (!recvBuf)
- if (debug_mode) printf("\tClient could not malloc space!?\n");
+ if (debug_mode) {
+ printf("\tClient could not malloc space!?\n");
+ }
memset(&serverAddr, 0, sizeof(PRNetAddr));
serverAddr.inet.family = PR_AF_INET;
@@ -332,27 +381,37 @@ ClientThreadFunc(void *unused)
while(numRequests > 0) {
if ( (numRequests % 10) == 0 )
- if (debug_mode) printf(".");
- if (debug_mode) DPRINTF("\tClient starting request %d\n", numRequests);
+ if (debug_mode) {
+ printf(".");
+ }
+ if (debug_mode) {
+ DPRINTF("\tClient starting request %d\n", numRequests);
+ }
clientSocket = PR_NewTCPSocket();
if (!clientSocket) {
if (debug_mode) printf("Client error creating socket: OS error %d\n",
- PR_GetOSError());
+ PR_GetOSError());
continue;
}
- if (debug_mode) DPRINTF("\tClient connecting\n");
+ if (debug_mode) {
+ DPRINTF("\tClient connecting\n");
+ }
rv = PR_Connect(clientSocket,
&serverAddr,
PR_INTERVAL_NO_TIMEOUT);
if (!clientSocket) {
- if (debug_mode) printf("\tClient error connecting\n");
+ if (debug_mode) {
+ printf("\tClient error connecting\n");
+ }
continue;
}
- if (debug_mode) DPRINTF("\tClient connected\n");
+ if (debug_mode) {
+ DPRINTF("\tClient connected\n");
+ }
rv = PR_Send(clientSocket,
sendBuf,
@@ -360,12 +419,16 @@ ClientThreadFunc(void *unused)
0,
PR_INTERVAL_NO_TIMEOUT);
if (rv != _client_data) {
- if (debug_mode) printf("Client error sending data (%d)\n", rv);
+ if (debug_mode) {
+ printf("Client error sending data (%d)\n", rv);
+ }
PR_Close(clientSocket);
continue;
}
- if (debug_mode) DPRINTF("\tClient sent %d bytes\n", rv);
+ if (debug_mode) {
+ DPRINTF("\tClient sent %d bytes\n", rv);
+ }
bytesNeeded = _server_data;
while(bytesNeeded) {
@@ -376,10 +439,12 @@ ClientThreadFunc(void *unused)
PR_INTERVAL_NO_TIMEOUT);
if (rv <= 0) {
if (debug_mode) printf("Client error receiving data (%d) (%d/%d)\n",
- rv, (_server_data - bytesNeeded), _server_data);
+ rv, (_server_data - bytesNeeded), _server_data);
break;
}
- if (debug_mode) DPRINTF("\tClient received %d bytes; need %d more\n", rv, bytesNeeded - rv);
+ if (debug_mode) {
+ DPRINTF("\tClient received %d bytes; need %d more\n", rv, bytesNeeded - rv);
+ }
bytesNeeded -= rv;
}
@@ -411,24 +476,28 @@ RunClients(void)
clientThread = PR_CreateThread(
- PR_USER_THREAD,
- ClientThreadFunc,
- NULL,
- PR_PRIORITY_NORMAL,
- ClientScope,
- PR_UNJOINABLE_THREAD,
- THREAD_STACKSIZE);
+ PR_USER_THREAD,
+ ClientThreadFunc,
+ NULL,
+ PR_PRIORITY_NORMAL,
+ ClientScope,
+ PR_UNJOINABLE_THREAD,
+ THREAD_STACKSIZE);
if (!clientThread) {
- if (debug_mode) printf("\terror creating client thread %d\n", index);
- } else
- if (debug_mode) DPRINTF("\tMain created client %d/%d\n", index+1, _clients);
+ if (debug_mode) {
+ printf("\terror creating client thread %d\n", index);
+ }
+ } else if (debug_mode) {
+ DPRINTF("\tMain created client %d/%d\n", index+1, _clients);
+ }
}
PR_EnterMonitor(clientMonitor);
- while(numClients)
+ while(numClients) {
PR_Wait(clientMonitor, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_ExitMonitor(clientMonitor);
}
@@ -442,15 +511,17 @@ void do_work()
SetServerState(MAIN, SERVER_STATE_STARTUP);
ServerThread = PR_CreateThread(
- PR_USER_THREAD,
- ServerThreadFunc,
- NULL,
- PR_PRIORITY_NORMAL,
- ServerScope,
- PR_JOINABLE_THREAD,
- THREAD_STACKSIZE);
+ PR_USER_THREAD,
+ ServerThreadFunc,
+ NULL,
+ PR_PRIORITY_NORMAL,
+ ServerScope,
+ PR_JOINABLE_THREAD,
+ THREAD_STACKSIZE);
if (!ServerThread) {
- if (debug_mode) printf("error creating main server thread\n");
+ if (debug_mode) {
+ printf("error creating main server thread\n");
+ }
return;
}
@@ -508,59 +579,63 @@ static void Measure(void (*func)(void), const char *msg)
d = (double)PR_IntervalToMicroseconds(stop - start);
- if (debug_mode) printf("\n%40s: %6.2f usec\n", msg, d / _iterations);
+ if (debug_mode) {
+ printf("\n%40s: %6.2f usec\n", msg, d / _iterations);
+ }
}
int main(int argc, char **argv)
{
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
+ 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_mode = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- /* main test */
+ /* main test */
if (debug_mode) {
- printf("Enter number of iterations: \n");
- scanf("%d", &_iterations);
- printf("Enter number of clients : \n");
- scanf("%d", &_clients);
- printf("Enter size of client data : \n");
- scanf("%d", &_client_data);
- printf("Enter size of server data : \n");
- scanf("%d", &_server_data);
- }
- else
- {
- _iterations = 7;
- _clients = 7;
- _client_data = 100;
- _server_data = 100;
- }
+ printf("Enter number of iterations: \n");
+ scanf("%d", &_iterations);
+ printf("Enter number of clients : \n");
+ scanf("%d", &_clients);
+ printf("Enter size of client data : \n");
+ scanf("%d", &_client_data);
+ printf("Enter size of server data : \n");
+ scanf("%d", &_server_data);
+ }
+ else
+ {
+ _iterations = 7;
+ _clients = 7;
+ _client_data = 100;
+ _server_data = 100;
+ }
if (debug_mode) {
- printf("\n\n%d iterations with %d client threads.\n",
- _iterations, _clients);
- printf("Sending %d bytes of client data and %d bytes of server data\n",
- _client_data, _server_data);
- }
+ printf("\n\n%d iterations with %d client threads.\n",
+ _iterations, _clients);
+ printf("Sending %d bytes of client data and %d bytes of server data\n",
+ _client_data, _server_data);
+ }
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
PR_STDIO_INIT();
@@ -572,11 +647,13 @@ int main(int argc, char **argv)
Measure(do_workKK, "server loop kernel/kernel");
- PR_Cleanup();
+ PR_Cleanup();
- if(failed_already)
- return 1;
- else
- return 0;
+ if(failed_already) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
}
diff --git a/pr/tests/servr_ku.c b/pr/tests/servr_ku.c
index 13e8ee15..d0c446f5 100644
--- a/pr/tests/servr_ku.c
+++ b/pr/tests/servr_ku.c
@@ -14,12 +14,12 @@
**
** Modification History:
** 19-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.
***********************************************************************/
/***********************************************************************
@@ -73,7 +73,9 @@ SetServerState(char *waiter, PRInt32 state)
ServerState = state;
PR_NotifyCondVar(ServerStateCV);
- if (debug_mode) DPRINTF("\t%s changed state to %d\n", waiter, state);
+ if (debug_mode) {
+ DPRINTF("\t%s changed state to %d\n", waiter, state);
+ }
PR_Unlock(ServerStateCVLock);
}
@@ -85,14 +87,17 @@ WaitServerState(char *waiter, PRInt32 state)
PR_Lock(ServerStateCVLock);
- if (debug_mode) DPRINTF("\t%s waiting for state %d\n", waiter, state);
+ if (debug_mode) {
+ DPRINTF("\t%s waiting for state %d\n", waiter, state);
+ }
- while(!(ServerState & state))
+ while(!(ServerState & state)) {
PR_WaitCondVar(ServerStateCV, PR_INTERVAL_NO_TIMEOUT);
+ }
rv = ServerState;
if (debug_mode) DPRINTF("\t%s resuming from wait for state %d; state now %d\n",
- waiter, state, ServerState);
+ waiter, state, ServerState);
PR_Unlock(ServerStateCVLock);
return rv;
@@ -114,15 +119,21 @@ WorkerThreadFunc(void *_listenSock)
char *sendBuf;
if (debug_mode) DPRINTF("\tServer buffer is %d bytes; %d data, %d netaddrs\n",
- _client_data+(2*sizeof(PRNetAddr))+32, _client_data, (2*sizeof(PRNetAddr))+32);
+ _client_data+(2*sizeof(PRNetAddr))+32, _client_data, (2*sizeof(PRNetAddr))+32);
dataBuf = (char *)PR_MALLOC(_client_data + 2*sizeof(PRNetAddr) + 32);
if (!dataBuf)
- if (debug_mode) printf("\tServer could not malloc space!?\n");
+ if (debug_mode) {
+ printf("\tServer could not malloc space!?\n");
+ }
sendBuf = (char *)PR_MALLOC(_server_data *sizeof(char));
if (!sendBuf)
- if (debug_mode) printf("\tServer could not malloc space!?\n");
+ if (debug_mode) {
+ printf("\tServer could not malloc space!?\n");
+ }
- if (debug_mode) DPRINTF("\tServer worker thread running\n");
+ if (debug_mode) {
+ DPRINTF("\tServer worker thread running\n");
+ }
while(1) {
PRInt32 bytesToRead = _client_data;
@@ -133,7 +144,9 @@ WorkerThreadFunc(void *_listenSock)
loops++;
- if (debug_mode) DPRINTF("\tServer thread going into accept\n");
+ if (debug_mode) {
+ DPRINTF("\tServer thread going into accept\n");
+ }
bytesRead = PR_AcceptRead(listenSock,
&newSock,
@@ -143,11 +156,15 @@ WorkerThreadFunc(void *_listenSock)
PR_INTERVAL_NO_TIMEOUT);
if (bytesRead < 0) {
- if (debug_mode) printf("\tServer error in accept (%d)\n", bytesRead);
+ if (debug_mode) {
+ printf("\tServer error in accept (%d)\n", bytesRead);
+ }
continue;
}
- if (debug_mode) DPRINTF("\tServer accepted connection (%d bytes)\n", bytesRead);
+ if (debug_mode) {
+ DPRINTF("\tServer accepted connection (%d bytes)\n", bytesRead);
+ }
PR_AtomicIncrement(&workerThreadsBusy);
if (workerThreadsBusy == workerThreads) {
@@ -156,19 +173,23 @@ WorkerThreadFunc(void *_listenSock)
PRThread *WorkerThread;
WorkerThread = PR_CreateThread(
- PR_SYSTEM_THREAD,
- WorkerThreadFunc,
- listenSock,
- PR_PRIORITY_NORMAL,
- ServerScope,
- PR_UNJOINABLE_THREAD,
- THREAD_STACKSIZE);
+ PR_SYSTEM_THREAD,
+ WorkerThreadFunc,
+ listenSock,
+ PR_PRIORITY_NORMAL,
+ ServerScope,
+ PR_UNJOINABLE_THREAD,
+ THREAD_STACKSIZE);
if (!WorkerThread) {
- if (debug_mode) printf("Error creating client thread %d\n", workerThreads);
+ if (debug_mode) {
+ printf("Error creating client thread %d\n", workerThreads);
+ }
} else {
PR_AtomicIncrement(&workerThreads);
- if (debug_mode) DPRINTF("\tServer creates worker (%d)\n", workerThreads);
+ if (debug_mode) {
+ DPRINTF("\tServer creates worker (%d)\n", workerThreads);
+ }
}
}
PR_Unlock(workerThreadsLock);
@@ -182,10 +203,14 @@ WorkerThreadFunc(void *_listenSock)
0,
PR_INTERVAL_NO_TIMEOUT);
if (bytesRead < 0) {
- if (debug_mode) printf("\tServer error receiving data (%d)\n", bytesRead);
+ if (debug_mode) {
+ printf("\tServer error receiving data (%d)\n", bytesRead);
+ }
continue;
}
- if (debug_mode) DPRINTF("\tServer received %d bytes\n", bytesRead);
+ if (debug_mode) {
+ DPRINTF("\tServer received %d bytes\n", bytesRead);
+ }
}
bytesWritten = PR_Send(newSock,
@@ -195,9 +220,11 @@ WorkerThreadFunc(void *_listenSock)
PR_INTERVAL_NO_TIMEOUT);
if (bytesWritten != _server_data) {
if (debug_mode) printf("\tError sending data to client (%d, %d)\n",
- bytesWritten, PR_GetOSError());
+ bytesWritten, PR_GetOSError());
} else {
- if (debug_mode) DPRINTF("\tServer sent %d bytes\n", bytesWritten);
+ if (debug_mode) {
+ DPRINTF("\tServer sent %d bytes\n", bytesWritten);
+ }
}
PR_Close(newSock);
@@ -214,8 +241,12 @@ ServerSetup(void)
PRThread *WorkerThread;
if ( (listenSocket = PR_NewTCPSocket()) == NULL) {
- if (debug_mode) printf("\tServer error creating listen socket\n");
- else failed_already=1;
+ if (debug_mode) {
+ printf("\tServer error creating listen socket\n");
+ }
+ else {
+ failed_already=1;
+ }
return NULL;
}
@@ -223,8 +254,10 @@ ServerSetup(void)
sockOpt.value.reuse_addr = PR_TRUE;
if ( PR_SetSocketOption(listenSocket, &sockOpt) == PR_FAILURE) {
if (debug_mode) printf("\tServer error setting socket option: OS error %d\n",
- PR_GetOSError());
- else failed_already=1;
+ PR_GetOSError());
+ else {
+ failed_already=1;
+ }
PR_Close(listenSocket);
return NULL;
}
@@ -236,15 +269,21 @@ ServerSetup(void)
if ( PR_Bind(listenSocket, &serverAddr) == PR_FAILURE) {
if (debug_mode) printf("\tServer error binding to server address: OS error %d\n",
- PR_GetOSError());
- else failed_already=1;
+ PR_GetOSError());
+ else {
+ failed_already=1;
+ }
PR_Close(listenSocket);
return NULL;
}
if ( PR_Listen(listenSocket, 128) == PR_FAILURE) {
- if (debug_mode) printf("\tServer error listening to server socket\n");
- else failed_already=1;
+ if (debug_mode) {
+ printf("\tServer error listening to server socket\n");
+ }
+ else {
+ failed_already=1;
+ }
PR_Close(listenSocket);
return NULL;
@@ -257,21 +296,25 @@ ServerSetup(void)
workerThreadsLock = PR_NewLock();
WorkerThread = PR_CreateThread(
- PR_SYSTEM_THREAD,
- WorkerThreadFunc,
- listenSocket,
- PR_PRIORITY_NORMAL,
- ServerScope,
- PR_UNJOINABLE_THREAD,
- THREAD_STACKSIZE);
+ PR_SYSTEM_THREAD,
+ WorkerThreadFunc,
+ listenSocket,
+ PR_PRIORITY_NORMAL,
+ ServerScope,
+ PR_UNJOINABLE_THREAD,
+ THREAD_STACKSIZE);
if (!WorkerThread) {
- if (debug_mode) printf("error creating working thread\n");
+ if (debug_mode) {
+ printf("error creating working thread\n");
+ }
PR_Close(listenSocket);
return NULL;
}
PR_AtomicIncrement(&workerThreads);
- if (debug_mode) DPRINTF("\tServer created primordial worker thread\n");
+ if (debug_mode) {
+ DPRINTF("\tServer created primordial worker thread\n");
+ }
return listenSocket;
}
@@ -289,7 +332,9 @@ ServerThreadFunc(void *unused)
SetServerState(SERVER, SERVER_STATE_DEAD);
} else {
- if (debug_mode) DPRINTF("\tServer up\n");
+ if (debug_mode) {
+ DPRINTF("\tServer up\n");
+ }
/* Tell clients they can start now. */
SetServerState(SERVER, SERVER_STATE_READY);
@@ -320,10 +365,14 @@ ClientThreadFunc(void *unused)
sendBuf = (char *)PR_MALLOC(_client_data * sizeof(char));
if (!sendBuf)
- if (debug_mode) printf("\tClient could not malloc space!?\n");
+ if (debug_mode) {
+ printf("\tClient could not malloc space!?\n");
+ }
recvBuf = (char *)PR_MALLOC(_server_data * sizeof(char));
if (!recvBuf)
- if (debug_mode) printf("\tClient could not malloc space!?\n");
+ if (debug_mode) {
+ printf("\tClient could not malloc space!?\n");
+ }
memset(&serverAddr, 0, sizeof(PRNetAddr));
serverAddr.inet.family = PR_AF_INET;
@@ -333,27 +382,37 @@ ClientThreadFunc(void *unused)
while(numRequests > 0) {
if ( (numRequests % 10) == 0 )
- if (debug_mode) printf(".");
- if (debug_mode) DPRINTF("\tClient starting request %d\n", numRequests);
+ if (debug_mode) {
+ printf(".");
+ }
+ if (debug_mode) {
+ DPRINTF("\tClient starting request %d\n", numRequests);
+ }
clientSocket = PR_NewTCPSocket();
if (!clientSocket) {
if (debug_mode) printf("Client error creating socket: OS error %d\n",
- PR_GetOSError());
+ PR_GetOSError());
continue;
}
- if (debug_mode) DPRINTF("\tClient connecting\n");
+ if (debug_mode) {
+ DPRINTF("\tClient connecting\n");
+ }
rv = PR_Connect(clientSocket,
&serverAddr,
PR_INTERVAL_NO_TIMEOUT);
if (!clientSocket) {
- if (debug_mode) printf("\tClient error connecting\n");
+ if (debug_mode) {
+ printf("\tClient error connecting\n");
+ }
continue;
}
- if (debug_mode) DPRINTF("\tClient connected\n");
+ if (debug_mode) {
+ DPRINTF("\tClient connected\n");
+ }
rv = PR_Send(clientSocket,
sendBuf,
@@ -361,12 +420,16 @@ ClientThreadFunc(void *unused)
0,
PR_INTERVAL_NO_TIMEOUT);
if (rv != _client_data) {
- if (debug_mode) printf("Client error sending data (%d)\n", rv);
+ if (debug_mode) {
+ printf("Client error sending data (%d)\n", rv);
+ }
PR_Close(clientSocket);
continue;
}
- if (debug_mode) DPRINTF("\tClient sent %d bytes\n", rv);
+ if (debug_mode) {
+ DPRINTF("\tClient sent %d bytes\n", rv);
+ }
bytesNeeded = _server_data;
while(bytesNeeded) {
@@ -377,10 +440,12 @@ ClientThreadFunc(void *unused)
PR_INTERVAL_NO_TIMEOUT);
if (rv <= 0) {
if (debug_mode) printf("Client error receiving data (%d) (%d/%d)\n",
- rv, (_server_data - bytesNeeded), _server_data);
+ rv, (_server_data - bytesNeeded), _server_data);
break;
}
- if (debug_mode) DPRINTF("\tClient received %d bytes; need %d more\n", rv, bytesNeeded - rv);
+ if (debug_mode) {
+ DPRINTF("\tClient received %d bytes; need %d more\n", rv, bytesNeeded - rv);
+ }
bytesNeeded -= rv;
}
@@ -412,24 +477,28 @@ RunClients(void)
clientThread = PR_CreateThread(
- PR_USER_THREAD,
- ClientThreadFunc,
- NULL,
- PR_PRIORITY_NORMAL,
- ClientScope,
- PR_UNJOINABLE_THREAD,
- THREAD_STACKSIZE);
+ PR_USER_THREAD,
+ ClientThreadFunc,
+ NULL,
+ PR_PRIORITY_NORMAL,
+ ClientScope,
+ PR_UNJOINABLE_THREAD,
+ THREAD_STACKSIZE);
if (!clientThread) {
- if (debug_mode) printf("\terror creating client thread %d\n", index);
- } else
- if (debug_mode) DPRINTF("\tMain created client %d/%d\n", index+1, _clients);
+ if (debug_mode) {
+ printf("\terror creating client thread %d\n", index);
+ }
+ } else if (debug_mode) {
+ DPRINTF("\tMain created client %d/%d\n", index+1, _clients);
+ }
}
PR_EnterMonitor(clientMonitor);
- while(numClients)
+ while(numClients) {
PR_Wait(clientMonitor, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_ExitMonitor(clientMonitor);
}
@@ -443,15 +512,17 @@ void do_work()
SetServerState(MAIN, SERVER_STATE_STARTUP);
ServerThread = PR_CreateThread(
- PR_USER_THREAD,
- ServerThreadFunc,
- NULL,
- PR_PRIORITY_NORMAL,
- ServerScope,
- PR_JOINABLE_THREAD,
- THREAD_STACKSIZE);
+ PR_USER_THREAD,
+ ServerThreadFunc,
+ NULL,
+ PR_PRIORITY_NORMAL,
+ ServerScope,
+ PR_JOINABLE_THREAD,
+ THREAD_STACKSIZE);
if (!ServerThread) {
- if (debug_mode) printf("error creating main server thread\n");
+ if (debug_mode) {
+ printf("error creating main server thread\n");
+ }
return;
}
@@ -490,59 +561,63 @@ static void Measure(void (*func)(void), const char *msg)
d = (double)PR_IntervalToMicroseconds(stop - start);
- if (debug_mode) printf("\n%40s: %6.2f usec\n", msg, d / _iterations);
+ if (debug_mode) {
+ printf("\n%40s: %6.2f usec\n", msg, d / _iterations);
+ }
}
int main(int argc, char **argv)
{
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
+ 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_mode = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- /* main test */
+ /* main test */
if (debug_mode) {
- printf("Enter number of iterations: \n");
- scanf("%d", &_iterations);
- printf("Enter number of clients : \n");
- scanf("%d", &_clients);
- printf("Enter size of client data : \n");
- scanf("%d", &_client_data);
- printf("Enter size of server data : \n");
- scanf("%d", &_server_data);
- }
- else
- {
- _iterations = 7;
- _clients = 7;
- _client_data = 100;
- _server_data = 100;
- }
+ printf("Enter number of iterations: \n");
+ scanf("%d", &_iterations);
+ printf("Enter number of clients : \n");
+ scanf("%d", &_clients);
+ printf("Enter size of client data : \n");
+ scanf("%d", &_client_data);
+ printf("Enter size of server data : \n");
+ scanf("%d", &_server_data);
+ }
+ else
+ {
+ _iterations = 7;
+ _clients = 7;
+ _client_data = 100;
+ _server_data = 100;
+ }
if (debug_mode) {
- printf("\n\n%d iterations with %d client threads.\n",
- _iterations, _clients);
- printf("Sending %d bytes of client data and %d bytes of server data\n",
- _client_data, _server_data);
- }
+ printf("\n\n%d iterations with %d client threads.\n",
+ _iterations, _clients);
+ printf("Sending %d bytes of client data and %d bytes of server data\n",
+ _client_data, _server_data);
+ }
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
PR_STDIO_INIT();
@@ -554,9 +629,11 @@ int main(int argc, char **argv)
Measure(do_workKU, "server loop kernel/user");
PR_Cleanup();
- if(failed_already)
- return 1;
- else
- return 0;
+ if(failed_already) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
}
diff --git a/pr/tests/servr_uk.c b/pr/tests/servr_uk.c
index 79074e83..bd97c8f3 100644
--- a/pr/tests/servr_uk.c
+++ b/pr/tests/servr_uk.c
@@ -14,12 +14,12 @@
**
** Modification History:
** 19-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.
***********************************************************************/
/***********************************************************************
@@ -75,7 +75,9 @@ SetServerState(char *waiter, PRInt32 state)
ServerState = state;
PR_NotifyCondVar(ServerStateCV);
- if (debug_mode) DPRINTF("\t%s changed state to %d\n", waiter, state);
+ if (debug_mode) {
+ DPRINTF("\t%s changed state to %d\n", waiter, state);
+ }
PR_Unlock(ServerStateCVLock);
}
@@ -87,14 +89,17 @@ WaitServerState(char *waiter, PRInt32 state)
PR_Lock(ServerStateCVLock);
- if (debug_mode) DPRINTF("\t%s waiting for state %d\n", waiter, state);
+ if (debug_mode) {
+ DPRINTF("\t%s waiting for state %d\n", waiter, state);
+ }
- while(!(ServerState & state))
+ while(!(ServerState & state)) {
PR_WaitCondVar(ServerStateCV, PR_INTERVAL_NO_TIMEOUT);
+ }
rv = ServerState;
if (debug_mode) DPRINTF("\t%s resuming from wait for state %d; state now %d\n",
- waiter, state, ServerState);
+ waiter, state, ServerState);
PR_Unlock(ServerStateCVLock);
return rv;
@@ -116,15 +121,21 @@ WorkerThreadFunc(void *_listenSock)
char *sendBuf;
if (debug_mode) DPRINTF("\tServer buffer is %d bytes; %d data, %d netaddrs\n",
- _client_data+(2*sizeof(PRNetAddr))+32, _client_data, (2*sizeof(PRNetAddr))+32);
+ _client_data+(2*sizeof(PRNetAddr))+32, _client_data, (2*sizeof(PRNetAddr))+32);
dataBuf = (char *)PR_MALLOC(_client_data + 2*sizeof(PRNetAddr) + 32);
if (!dataBuf)
- if (debug_mode) printf("\tServer could not malloc space!?\n");
+ if (debug_mode) {
+ printf("\tServer could not malloc space!?\n");
+ }
sendBuf = (char *)PR_MALLOC(_server_data *sizeof(char));
if (!sendBuf)
- if (debug_mode) printf("\tServer could not malloc space!?\n");
+ if (debug_mode) {
+ printf("\tServer could not malloc space!?\n");
+ }
- if (debug_mode) DPRINTF("\tServer worker thread running\n");
+ if (debug_mode) {
+ DPRINTF("\tServer worker thread running\n");
+ }
while(1) {
PRInt32 bytesToRead = _client_data;
@@ -135,7 +146,9 @@ WorkerThreadFunc(void *_listenSock)
loops++;
- if (debug_mode) DPRINTF("\tServer thread going into accept\n");
+ if (debug_mode) {
+ DPRINTF("\tServer thread going into accept\n");
+ }
bytesRead = PR_AcceptRead(listenSock,
&newSock,
@@ -145,11 +158,15 @@ WorkerThreadFunc(void *_listenSock)
PR_INTERVAL_NO_TIMEOUT);
if (bytesRead < 0) {
- if (debug_mode) printf("\tServer error in accept (%d)\n", bytesRead);
+ if (debug_mode) {
+ printf("\tServer error in accept (%d)\n", bytesRead);
+ }
continue;
}
- if (debug_mode) DPRINTF("\tServer accepted connection (%d bytes)\n", bytesRead);
+ if (debug_mode) {
+ DPRINTF("\tServer accepted connection (%d bytes)\n", bytesRead);
+ }
PR_AtomicIncrement(&workerThreadsBusy);
if (workerThreadsBusy == workerThreads) {
@@ -158,19 +175,23 @@ WorkerThreadFunc(void *_listenSock)
PRThread *WorkerThread;
WorkerThread = PR_CreateThread(
- PR_SYSTEM_THREAD,
- WorkerThreadFunc,
- listenSock,
- PR_PRIORITY_NORMAL,
- ServerScope,
- PR_UNJOINABLE_THREAD,
- THREAD_STACKSIZE);
+ PR_SYSTEM_THREAD,
+ WorkerThreadFunc,
+ listenSock,
+ PR_PRIORITY_NORMAL,
+ ServerScope,
+ PR_UNJOINABLE_THREAD,
+ THREAD_STACKSIZE);
if (!WorkerThread) {
- if (debug_mode) printf("Error creating client thread %d\n", workerThreads);
+ if (debug_mode) {
+ printf("Error creating client thread %d\n", workerThreads);
+ }
} else {
PR_AtomicIncrement(&workerThreads);
- if (debug_mode) DPRINTF("\tServer creates worker (%d)\n", workerThreads);
+ if (debug_mode) {
+ DPRINTF("\tServer creates worker (%d)\n", workerThreads);
+ }
}
}
PR_Unlock(workerThreadsLock);
@@ -184,10 +205,14 @@ WorkerThreadFunc(void *_listenSock)
0,
PR_INTERVAL_NO_TIMEOUT);
if (bytesRead < 0) {
- if (debug_mode) printf("\tServer error receiving data (%d)\n", bytesRead);
+ if (debug_mode) {
+ printf("\tServer error receiving data (%d)\n", bytesRead);
+ }
continue;
}
- if (debug_mode) DPRINTF("\tServer received %d bytes\n", bytesRead);
+ if (debug_mode) {
+ DPRINTF("\tServer received %d bytes\n", bytesRead);
+ }
}
bytesWritten = PR_Send(newSock,
@@ -197,9 +222,11 @@ WorkerThreadFunc(void *_listenSock)
PR_INTERVAL_NO_TIMEOUT);
if (bytesWritten != _server_data) {
if (debug_mode) printf("\tError sending data to client (%d, %d)\n",
- bytesWritten, PR_GetOSError());
+ bytesWritten, PR_GetOSError());
} else {
- if (debug_mode) DPRINTF("\tServer sent %d bytes\n", bytesWritten);
+ if (debug_mode) {
+ DPRINTF("\tServer sent %d bytes\n", bytesWritten);
+ }
}
PR_Close(newSock);
@@ -216,17 +243,22 @@ ServerSetup(void)
PRThread *WorkerThread;
if ( (listenSocket = PR_NewTCPSocket()) == NULL) {
- if (debug_mode) printf("\tServer error creating listen socket\n");
- else
- return NULL;
+ if (debug_mode) {
+ printf("\tServer error creating listen socket\n");
+ }
+ else {
+ return NULL;
+ }
}
sockOpt.option = PR_SockOpt_Reuseaddr;
sockOpt.value.reuse_addr = PR_TRUE;
if ( PR_SetSocketOption(listenSocket, &sockOpt) == PR_FAILURE) {
if (debug_mode) printf("\tServer error setting socket option: OS error %d\n",
- PR_GetOSError());
- else failed_already=1;
+ PR_GetOSError());
+ else {
+ failed_already=1;
+ }
PR_Close(listenSocket);
return NULL;
}
@@ -238,15 +270,21 @@ ServerSetup(void)
if ( PR_Bind(listenSocket, &serverAddr) == PR_FAILURE) {
if (debug_mode) printf("\tServer error binding to server address: OS error %d\n",
- PR_GetOSError());
- else failed_already=1;
+ PR_GetOSError());
+ else {
+ failed_already=1;
+ }
PR_Close(listenSocket);
return NULL;
}
if ( PR_Listen(listenSocket, 128) == PR_FAILURE) {
- if (debug_mode) printf("\tServer error listening to server socket\n");
- else failed_already=1;
+ if (debug_mode) {
+ printf("\tServer error listening to server socket\n");
+ }
+ else {
+ failed_already=1;
+ }
PR_Close(listenSocket);
return NULL;
@@ -259,21 +297,25 @@ ServerSetup(void)
workerThreadsLock = PR_NewLock();
WorkerThread = PR_CreateThread(
- PR_SYSTEM_THREAD,
- WorkerThreadFunc,
- listenSocket,
- PR_PRIORITY_NORMAL,
- ServerScope,
- PR_UNJOINABLE_THREAD,
- THREAD_STACKSIZE);
+ PR_SYSTEM_THREAD,
+ WorkerThreadFunc,
+ listenSocket,
+ PR_PRIORITY_NORMAL,
+ ServerScope,
+ PR_UNJOINABLE_THREAD,
+ THREAD_STACKSIZE);
if (!WorkerThread) {
- if (debug_mode) printf("error creating working thread\n");
+ if (debug_mode) {
+ printf("error creating working thread\n");
+ }
PR_Close(listenSocket);
return NULL;
}
PR_AtomicIncrement(&workerThreads);
- if (debug_mode) DPRINTF("\tServer created primordial worker thread\n");
+ if (debug_mode) {
+ DPRINTF("\tServer created primordial worker thread\n");
+ }
return listenSocket;
}
@@ -291,7 +333,9 @@ ServerThreadFunc(void *unused)
SetServerState(SERVER, SERVER_STATE_DEAD);
} else {
- if (debug_mode) DPRINTF("\tServer up\n");
+ if (debug_mode) {
+ DPRINTF("\tServer up\n");
+ }
/* Tell clients they can start now. */
SetServerState(SERVER, SERVER_STATE_READY);
@@ -322,10 +366,14 @@ ClientThreadFunc(void *unused)
sendBuf = (char *)PR_MALLOC(_client_data * sizeof(char));
if (!sendBuf)
- if (debug_mode) printf("\tClient could not malloc space!?\n");
+ if (debug_mode) {
+ printf("\tClient could not malloc space!?\n");
+ }
recvBuf = (char *)PR_MALLOC(_server_data * sizeof(char));
if (!recvBuf)
- if (debug_mode) printf("\tClient could not malloc space!?\n");
+ if (debug_mode) {
+ printf("\tClient could not malloc space!?\n");
+ }
memset(&serverAddr, 0, sizeof(PRNetAddr));
serverAddr.inet.family = PR_AF_INET;
@@ -335,27 +383,37 @@ ClientThreadFunc(void *unused)
while(numRequests > 0) {
if ( (numRequests % 10) == 0 )
- if (debug_mode) printf(".");
- if (debug_mode) DPRINTF("\tClient starting request %d\n", numRequests);
+ if (debug_mode) {
+ printf(".");
+ }
+ if (debug_mode) {
+ DPRINTF("\tClient starting request %d\n", numRequests);
+ }
clientSocket = PR_NewTCPSocket();
if (!clientSocket) {
if (debug_mode) printf("Client error creating socket: OS error %d\n",
- PR_GetOSError());
+ PR_GetOSError());
continue;
}
- if (debug_mode) DPRINTF("\tClient connecting\n");
+ if (debug_mode) {
+ DPRINTF("\tClient connecting\n");
+ }
rv = PR_Connect(clientSocket,
&serverAddr,
PR_INTERVAL_NO_TIMEOUT);
if (!clientSocket) {
- if (debug_mode) printf("\tClient error connecting\n");
+ if (debug_mode) {
+ printf("\tClient error connecting\n");
+ }
continue;
}
- if (debug_mode) DPRINTF("\tClient connected\n");
+ if (debug_mode) {
+ DPRINTF("\tClient connected\n");
+ }
rv = PR_Send(clientSocket,
sendBuf,
@@ -363,12 +421,16 @@ ClientThreadFunc(void *unused)
0,
PR_INTERVAL_NO_TIMEOUT);
if (rv != _client_data) {
- if (debug_mode) printf("Client error sending data (%d)\n", rv);
+ if (debug_mode) {
+ printf("Client error sending data (%d)\n", rv);
+ }
PR_Close(clientSocket);
continue;
}
- if (debug_mode) DPRINTF("\tClient sent %d bytes\n", rv);
+ if (debug_mode) {
+ DPRINTF("\tClient sent %d bytes\n", rv);
+ }
bytesNeeded = _server_data;
while(bytesNeeded) {
@@ -379,10 +441,12 @@ ClientThreadFunc(void *unused)
PR_INTERVAL_NO_TIMEOUT);
if (rv <= 0) {
if (debug_mode) printf("Client error receiving data (%d) (%d/%d)\n",
- rv, (_server_data - bytesNeeded), _server_data);
+ rv, (_server_data - bytesNeeded), _server_data);
break;
}
- if (debug_mode) DPRINTF("\tClient received %d bytes; need %d more\n", rv, bytesNeeded - rv);
+ if (debug_mode) {
+ DPRINTF("\tClient received %d bytes; need %d more\n", rv, bytesNeeded - rv);
+ }
bytesNeeded -= rv;
}
@@ -414,24 +478,28 @@ RunClients(void)
clientThread = PR_CreateThread(
- PR_USER_THREAD,
- ClientThreadFunc,
- NULL,
- PR_PRIORITY_NORMAL,
- ClientScope,
- PR_UNJOINABLE_THREAD,
- THREAD_STACKSIZE);
+ PR_USER_THREAD,
+ ClientThreadFunc,
+ NULL,
+ PR_PRIORITY_NORMAL,
+ ClientScope,
+ PR_UNJOINABLE_THREAD,
+ THREAD_STACKSIZE);
if (!clientThread) {
- if (debug_mode) printf("\terror creating client thread %d\n", index);
- } else
- if (debug_mode) DPRINTF("\tMain created client %d/%d\n", index+1, _clients);
+ if (debug_mode) {
+ printf("\terror creating client thread %d\n", index);
+ }
+ } else if (debug_mode) {
+ DPRINTF("\tMain created client %d/%d\n", index+1, _clients);
+ }
}
PR_EnterMonitor(clientMonitor);
- while(numClients)
+ while(numClients) {
PR_Wait(clientMonitor, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_ExitMonitor(clientMonitor);
}
@@ -445,15 +513,17 @@ void do_work()
SetServerState(MAIN, SERVER_STATE_STARTUP);
ServerThread = PR_CreateThread(
- PR_USER_THREAD,
- ServerThreadFunc,
- NULL,
- PR_PRIORITY_NORMAL,
- ServerScope,
- PR_JOINABLE_THREAD,
- THREAD_STACKSIZE);
+ PR_USER_THREAD,
+ ServerThreadFunc,
+ NULL,
+ PR_PRIORITY_NORMAL,
+ ServerScope,
+ PR_JOINABLE_THREAD,
+ THREAD_STACKSIZE);
if (!ServerThread) {
- if (debug_mode) printf("error creating main server thread\n");
+ if (debug_mode) {
+ printf("error creating main server thread\n");
+ }
return;
}
@@ -492,59 +562,63 @@ static void Measure(void (*func)(void), const char *msg)
d = (double)PR_IntervalToMicroseconds(stop - start);
- if (debug_mode) printf("\n%40s: %6.2f usec\n", msg, d / _iterations);
+ if (debug_mode) {
+ printf("\n%40s: %6.2f usec\n", msg, d / _iterations);
+ }
}
int main(int argc, char **argv)
{
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
+ 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_mode = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- /* main test */
+ /* main test */
if (debug_mode) {
- printf("Enter number of iterations: \n");
- scanf("%d", &_iterations);
- printf("Enter number of clients : \n");
- scanf("%d", &_clients);
- printf("Enter size of client data : \n");
- scanf("%d", &_client_data);
- printf("Enter size of server data : \n");
- scanf("%d", &_server_data);
- }
- else
- {
- _iterations = 7;
- _clients = 7;
- _client_data = 100;
- _server_data = 100;
- }
+ printf("Enter number of iterations: \n");
+ scanf("%d", &_iterations);
+ printf("Enter number of clients : \n");
+ scanf("%d", &_clients);
+ printf("Enter size of client data : \n");
+ scanf("%d", &_client_data);
+ printf("Enter size of server data : \n");
+ scanf("%d", &_server_data);
+ }
+ else
+ {
+ _iterations = 7;
+ _clients = 7;
+ _client_data = 100;
+ _server_data = 100;
+ }
if (debug_mode) {
- printf("\n\n%d iterations with %d client threads.\n",
- _iterations, _clients);
- printf("Sending %d bytes of client data and %d bytes of server data\n",
- _client_data, _server_data);
- }
+ printf("\n\n%d iterations with %d client threads.\n",
+ _iterations, _clients);
+ printf("Sending %d bytes of client data and %d bytes of server data\n",
+ _client_data, _server_data);
+ }
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
PR_STDIO_INIT();
@@ -557,8 +631,10 @@ int main(int argc, char **argv)
PR_Cleanup();
- if(failed_already)
- return 1;
- else
- return 0;
+ if(failed_already) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
}
diff --git a/pr/tests/servr_uu.c b/pr/tests/servr_uu.c
index 0b7d5e4d..8e77d8fa 100644
--- a/pr/tests/servr_uu.c
+++ b/pr/tests/servr_uu.c
@@ -14,12 +14,12 @@
**
** Modification History:
** 19-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.
***********************************************************************/
/***********************************************************************
@@ -73,7 +73,9 @@ SetServerState(char *waiter, PRInt32 state)
ServerState = state;
PR_NotifyCondVar(ServerStateCV);
- if (debug_mode) DPRINTF("\t%s changed state to %d\n", waiter, state);
+ if (debug_mode) {
+ DPRINTF("\t%s changed state to %d\n", waiter, state);
+ }
PR_Unlock(ServerStateCVLock);
}
@@ -85,14 +87,17 @@ WaitServerState(char *waiter, PRInt32 state)
PR_Lock(ServerStateCVLock);
- if (debug_mode) DPRINTF("\t%s waiting for state %d\n", waiter, state);
+ if (debug_mode) {
+ DPRINTF("\t%s waiting for state %d\n", waiter, state);
+ }
- while(!(ServerState & state))
+ while(!(ServerState & state)) {
PR_WaitCondVar(ServerStateCV, PR_INTERVAL_NO_TIMEOUT);
+ }
rv = ServerState;
if (debug_mode) DPRINTF("\t%s resuming from wait for state %d; state now %d\n",
- waiter, state, ServerState);
+ waiter, state, ServerState);
PR_Unlock(ServerStateCVLock);
return rv;
@@ -114,15 +119,21 @@ WorkerThreadFunc(void *_listenSock)
char *sendBuf;
if (debug_mode) DPRINTF("\tServer buffer is %d bytes; %d data, %d netaddrs\n",
- _client_data+(2*sizeof(PRNetAddr))+32, _client_data, (2*sizeof(PRNetAddr))+32);
+ _client_data+(2*sizeof(PRNetAddr))+32, _client_data, (2*sizeof(PRNetAddr))+32);
dataBuf = (char *)PR_MALLOC(_client_data + 2*sizeof(PRNetAddr) + 32);
if (!dataBuf)
- if (debug_mode) printf("\tServer could not malloc space!?\n");
+ if (debug_mode) {
+ printf("\tServer could not malloc space!?\n");
+ }
sendBuf = (char *)PR_MALLOC(_server_data *sizeof(char));
if (!sendBuf)
- if (debug_mode) printf("\tServer could not malloc space!?\n");
+ if (debug_mode) {
+ printf("\tServer could not malloc space!?\n");
+ }
- if (debug_mode) DPRINTF("\tServer worker thread running\n");
+ if (debug_mode) {
+ DPRINTF("\tServer worker thread running\n");
+ }
while(1) {
PRInt32 bytesToRead = _client_data;
@@ -133,7 +144,9 @@ WorkerThreadFunc(void *_listenSock)
loops++;
- if (debug_mode) DPRINTF("\tServer thread going into accept\n");
+ if (debug_mode) {
+ DPRINTF("\tServer thread going into accept\n");
+ }
bytesRead = PR_AcceptRead(listenSock,
&newSock,
@@ -143,11 +156,15 @@ WorkerThreadFunc(void *_listenSock)
PR_INTERVAL_NO_TIMEOUT);
if (bytesRead < 0) {
- if (debug_mode) printf("\tServer error in accept (%d)\n", bytesRead);
+ if (debug_mode) {
+ printf("\tServer error in accept (%d)\n", bytesRead);
+ }
continue;
}
- if (debug_mode) DPRINTF("\tServer accepted connection (%d bytes)\n", bytesRead);
+ if (debug_mode) {
+ DPRINTF("\tServer accepted connection (%d bytes)\n", bytesRead);
+ }
PR_AtomicIncrement(&workerThreadsBusy);
if (workerThreadsBusy == workerThreads) {
@@ -157,19 +174,23 @@ WorkerThreadFunc(void *_listenSock)
PRThread *WorkerThread;
WorkerThread = PR_CreateThread(
- PR_SYSTEM_THREAD,
- WorkerThreadFunc,
- listenSock,
- PR_PRIORITY_NORMAL,
- ServerScope,
- PR_UNJOINABLE_THREAD,
- THREAD_STACKSIZE);
+ PR_SYSTEM_THREAD,
+ WorkerThreadFunc,
+ listenSock,
+ PR_PRIORITY_NORMAL,
+ ServerScope,
+ PR_UNJOINABLE_THREAD,
+ THREAD_STACKSIZE);
if (!WorkerThread) {
- if (debug_mode) printf("Error creating client thread %d\n", workerThreads);
+ if (debug_mode) {
+ printf("Error creating client thread %d\n", workerThreads);
+ }
} else {
PR_AtomicIncrement(&workerThreads);
- if (debug_mode) DPRINTF("\tServer creates worker (%d)\n", workerThreads);
+ if (debug_mode) {
+ DPRINTF("\tServer creates worker (%d)\n", workerThreads);
+ }
}
}
PR_Unlock(workerThreadsLock);
@@ -183,10 +204,14 @@ WorkerThreadFunc(void *_listenSock)
0,
PR_INTERVAL_NO_TIMEOUT);
if (bytesRead < 0) {
- if (debug_mode) printf("\tServer error receiving data (%d)\n", bytesRead);
+ if (debug_mode) {
+ printf("\tServer error receiving data (%d)\n", bytesRead);
+ }
continue;
}
- if (debug_mode) DPRINTF("\tServer received %d bytes\n", bytesRead);
+ if (debug_mode) {
+ DPRINTF("\tServer received %d bytes\n", bytesRead);
+ }
}
bytesWritten = PR_Send(newSock,
@@ -196,9 +221,11 @@ WorkerThreadFunc(void *_listenSock)
PR_INTERVAL_NO_TIMEOUT);
if (bytesWritten != _server_data) {
if (debug_mode) printf("\tError sending data to client (%d, %d)\n",
- bytesWritten, PR_GetOSError());
+ bytesWritten, PR_GetOSError());
} else {
- if (debug_mode) DPRINTF("\tServer sent %d bytes\n", bytesWritten);
+ if (debug_mode) {
+ DPRINTF("\tServer sent %d bytes\n", bytesWritten);
+ }
}
PR_Close(newSock);
@@ -215,8 +242,12 @@ ServerSetup(void)
PRThread *WorkerThread;
if ( (listenSocket = PR_NewTCPSocket()) == NULL) {
- if (debug_mode) printf("\tServer error creating listen socket\n");
- else failed_already=1;
+ if (debug_mode) {
+ printf("\tServer error creating listen socket\n");
+ }
+ else {
+ failed_already=1;
+ }
return NULL;
}
@@ -224,8 +255,10 @@ ServerSetup(void)
sockOpt.value.reuse_addr = PR_TRUE;
if ( PR_SetSocketOption(listenSocket, &sockOpt) == PR_FAILURE) {
if (debug_mode) printf("\tServer error setting socket option: OS error %d\n",
- PR_GetOSError());
- else failed_already=1;
+ PR_GetOSError());
+ else {
+ failed_already=1;
+ }
PR_Close(listenSocket);
return NULL;
}
@@ -237,15 +270,21 @@ ServerSetup(void)
if ( PR_Bind(listenSocket, &serverAddr) == PR_FAILURE) {
if (debug_mode) printf("\tServer error binding to server address: OS error %d\n",
- PR_GetOSError());
- else failed_already=1;
+ PR_GetOSError());
+ else {
+ failed_already=1;
+ }
PR_Close(listenSocket);
return NULL;
}
if ( PR_Listen(listenSocket, 128) == PR_FAILURE) {
- if (debug_mode) printf("\tServer error listening to server socket\n");
- else failed_already=1;
+ if (debug_mode) {
+ printf("\tServer error listening to server socket\n");
+ }
+ else {
+ failed_already=1;
+ }
PR_Close(listenSocket);
return NULL;
@@ -258,21 +297,25 @@ ServerSetup(void)
workerThreadsLock = PR_NewLock();
WorkerThread = PR_CreateThread(
- PR_SYSTEM_THREAD,
- WorkerThreadFunc,
- listenSocket,
- PR_PRIORITY_NORMAL,
- ServerScope,
- PR_UNJOINABLE_THREAD,
- THREAD_STACKSIZE);
+ PR_SYSTEM_THREAD,
+ WorkerThreadFunc,
+ listenSocket,
+ PR_PRIORITY_NORMAL,
+ ServerScope,
+ PR_UNJOINABLE_THREAD,
+ THREAD_STACKSIZE);
if (!WorkerThread) {
- if (debug_mode) printf("error creating working thread\n");
+ if (debug_mode) {
+ printf("error creating working thread\n");
+ }
PR_Close(listenSocket);
return NULL;
}
PR_AtomicIncrement(&workerThreads);
- if (debug_mode) DPRINTF("\tServer created primordial worker thread\n");
+ if (debug_mode) {
+ DPRINTF("\tServer created primordial worker thread\n");
+ }
return listenSocket;
}
@@ -290,7 +333,9 @@ ServerThreadFunc(void *unused)
SetServerState(SERVER, SERVER_STATE_DEAD);
} else {
- if (debug_mode) DPRINTF("\tServer up\n");
+ if (debug_mode) {
+ DPRINTF("\tServer up\n");
+ }
/* Tell clients they can start now. */
SetServerState(SERVER, SERVER_STATE_READY);
@@ -321,10 +366,14 @@ ClientThreadFunc(void *unused)
sendBuf = (char *)PR_MALLOC(_client_data * sizeof(char));
if (!sendBuf)
- if (debug_mode) printf("\tClient could not malloc space!?\n");
+ if (debug_mode) {
+ printf("\tClient could not malloc space!?\n");
+ }
recvBuf = (char *)PR_MALLOC(_server_data * sizeof(char));
if (!recvBuf)
- if (debug_mode) printf("\tClient could not malloc space!?\n");
+ if (debug_mode) {
+ printf("\tClient could not malloc space!?\n");
+ }
memset(&serverAddr, 0, sizeof(PRNetAddr));
serverAddr.inet.family = PR_AF_INET;
@@ -334,27 +383,37 @@ ClientThreadFunc(void *unused)
while(numRequests > 0) {
if ( (numRequests % 10) == 0 )
- if (debug_mode) printf(".");
- if (debug_mode) DPRINTF("\tClient starting request %d\n", numRequests);
+ if (debug_mode) {
+ printf(".");
+ }
+ if (debug_mode) {
+ DPRINTF("\tClient starting request %d\n", numRequests);
+ }
clientSocket = PR_NewTCPSocket();
if (!clientSocket) {
if (debug_mode) printf("Client error creating socket: OS error %d\n",
- PR_GetOSError());
+ PR_GetOSError());
continue;
}
- if (debug_mode) DPRINTF("\tClient connecting\n");
+ if (debug_mode) {
+ DPRINTF("\tClient connecting\n");
+ }
rv = PR_Connect(clientSocket,
&serverAddr,
PR_INTERVAL_NO_TIMEOUT);
if (!clientSocket) {
- if (debug_mode) printf("\tClient error connecting\n");
+ if (debug_mode) {
+ printf("\tClient error connecting\n");
+ }
continue;
}
- if (debug_mode) DPRINTF("\tClient connected\n");
+ if (debug_mode) {
+ DPRINTF("\tClient connected\n");
+ }
rv = PR_Send(clientSocket,
sendBuf,
@@ -362,12 +421,16 @@ ClientThreadFunc(void *unused)
0,
PR_INTERVAL_NO_TIMEOUT);
if (rv != _client_data) {
- if (debug_mode) printf("Client error sending data (%d)\n", rv);
+ if (debug_mode) {
+ printf("Client error sending data (%d)\n", rv);
+ }
PR_Close(clientSocket);
continue;
}
- if (debug_mode) DPRINTF("\tClient sent %d bytes\n", rv);
+ if (debug_mode) {
+ DPRINTF("\tClient sent %d bytes\n", rv);
+ }
bytesNeeded = _server_data;
while(bytesNeeded) {
@@ -378,10 +441,12 @@ ClientThreadFunc(void *unused)
PR_INTERVAL_NO_TIMEOUT);
if (rv <= 0) {
if (debug_mode) printf("Client error receiving data (%d) (%d/%d)\n",
- rv, (_server_data - bytesNeeded), _server_data);
+ rv, (_server_data - bytesNeeded), _server_data);
break;
}
- if (debug_mode) DPRINTF("\tClient received %d bytes; need %d more\n", rv, bytesNeeded - rv);
+ if (debug_mode) {
+ DPRINTF("\tClient received %d bytes; need %d more\n", rv, bytesNeeded - rv);
+ }
bytesNeeded -= rv;
}
@@ -413,24 +478,28 @@ RunClients(void)
clientThread = PR_CreateThread(
- PR_USER_THREAD,
- ClientThreadFunc,
- NULL,
- PR_PRIORITY_NORMAL,
- ClientScope,
- PR_UNJOINABLE_THREAD,
- THREAD_STACKSIZE);
+ PR_USER_THREAD,
+ ClientThreadFunc,
+ NULL,
+ PR_PRIORITY_NORMAL,
+ ClientScope,
+ PR_UNJOINABLE_THREAD,
+ THREAD_STACKSIZE);
if (!clientThread) {
- if (debug_mode) printf("\terror creating client thread %d\n", index);
- } else
- if (debug_mode) DPRINTF("\tMain created client %d/%d\n", index+1, _clients);
+ if (debug_mode) {
+ printf("\terror creating client thread %d\n", index);
+ }
+ } else if (debug_mode) {
+ DPRINTF("\tMain created client %d/%d\n", index+1, _clients);
+ }
}
PR_EnterMonitor(clientMonitor);
- while(numClients)
+ while(numClients) {
PR_Wait(clientMonitor, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_ExitMonitor(clientMonitor);
}
@@ -444,15 +513,17 @@ void do_work()
SetServerState(MAIN, SERVER_STATE_STARTUP);
ServerThread = PR_CreateThread(
- PR_USER_THREAD,
- ServerThreadFunc,
- NULL,
- PR_PRIORITY_NORMAL,
- ServerScope,
- PR_JOINABLE_THREAD,
- THREAD_STACKSIZE);
+ PR_USER_THREAD,
+ ServerThreadFunc,
+ NULL,
+ PR_PRIORITY_NORMAL,
+ ServerScope,
+ PR_JOINABLE_THREAD,
+ THREAD_STACKSIZE);
if (!ServerThread) {
- if (debug_mode) printf("error creating main server thread\n");
+ if (debug_mode) {
+ printf("error creating main server thread\n");
+ }
return;
}
@@ -490,59 +561,63 @@ static void Measure(void (*func)(void), const char *msg)
d = (double)PR_IntervalToMicroseconds(stop - start);
- if (debug_mode) printf("\n%40s: %6.2f usec\n", msg, d / _iterations);
+ if (debug_mode) {
+ printf("\n%40s: %6.2f usec\n", msg, d / _iterations);
+ }
}
int main(int argc, char **argv)
{
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
+ 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_mode = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- /* main test */
+ /* main test */
if (debug_mode) {
- printf("Enter number of iterations: \n");
- scanf("%d", &_iterations);
- printf("Enter number of clients : \n");
- scanf("%d", &_clients);
- printf("Enter size of client data : \n");
- scanf("%d", &_client_data);
- printf("Enter size of server data : \n");
- scanf("%d", &_server_data);
- }
- else
- {
- _iterations = 7;
- _clients = 7;
- _client_data = 100;
- _server_data = 100;
- }
+ printf("Enter number of iterations: \n");
+ scanf("%d", &_iterations);
+ printf("Enter number of clients : \n");
+ scanf("%d", &_clients);
+ printf("Enter size of client data : \n");
+ scanf("%d", &_client_data);
+ printf("Enter size of server data : \n");
+ scanf("%d", &_server_data);
+ }
+ else
+ {
+ _iterations = 7;
+ _clients = 7;
+ _client_data = 100;
+ _server_data = 100;
+ }
if (debug_mode) {
- printf("\n\n%d iterations with %d client threads.\n",
- _iterations, _clients);
- printf("Sending %d bytes of client data and %d bytes of server data\n",
- _client_data, _server_data);
- }
+ printf("\n\n%d iterations with %d client threads.\n",
+ _iterations, _clients);
+ printf("Sending %d bytes of client data and %d bytes of server data\n",
+ _client_data, _server_data);
+ }
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
PR_STDIO_INIT();
@@ -555,9 +630,11 @@ int main(int argc, char **argv)
PR_Cleanup();
- if(failed_already)
- return 1;
- else
- return 0;
+ if(failed_already) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
}
diff --git a/pr/tests/short_thread.c b/pr/tests/short_thread.c
index e39c3809..de069e89 100644
--- a/pr/tests/short_thread.c
+++ b/pr/tests/short_thread.c
@@ -19,40 +19,42 @@ static void housecleaning(void *cur_time);
int main (int argc, char **argv)
{
- static PRIntervalTime thread_start_time;
- static PRThread *housekeeping_tid = NULL;
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "d");
-
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
- {
- if (PL_OPT_BAD == os) continue;
- switch (opt->option)
- {
- case 'd': /* debug mode */
- _debug_on = 1;
- break;
- default:
- break;
- }
- }
- PL_DestroyOptState(opt);
-
- if (( housekeeping_tid =
- PR_CreateThread (PR_USER_THREAD, housecleaning, (void*)&thread_start_time,
- PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0))
- == NULL ) {
- fprintf(stderr,
- "simple_test: Error - PR_CreateThread failed: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
- exit( 1 );
- }
- PR_Cleanup();
- return(0);
+ static PRIntervalTime thread_start_time;
+ static PRThread *housekeeping_tid = NULL;
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "d");
+
+ while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ {
+ if (PL_OPT_BAD == os) {
+ continue;
+ }
+ switch (opt->option)
+ {
+ case 'd': /* debug mode */
+ _debug_on = 1;
+ break;
+ default:
+ break;
+ }
+ }
+ PL_DestroyOptState(opt);
+
+ if (( housekeeping_tid =
+ PR_CreateThread (PR_USER_THREAD, housecleaning, (void*)&thread_start_time,
+ PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0))
+ == NULL ) {
+ fprintf(stderr,
+ "simple_test: Error - PR_CreateThread failed: (%ld, %ld)\n",
+ PR_GetError(), PR_GetOSError());
+ exit( 1 );
+ }
+ PR_Cleanup();
+ return(0);
}
static void
housecleaning (void *cur_time)
{
- DPRINTF(("Child Thread exiting\n"));
+ DPRINTF(("Child Thread exiting\n"));
}
diff --git a/pr/tests/sigpipe.c b/pr/tests/sigpipe.c
index f6c27649..02ba9114 100644
--- a/pr/tests/sigpipe.c
+++ b/pr/tests/sigpipe.c
@@ -76,7 +76,7 @@ int main(int argc, char **argv)
PR_SetError(0, 0);
thread = PR_CreateThread(PR_USER_THREAD, Test, NULL, PR_PRIORITY_NORMAL,
- PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
if (thread == NULL) {
fprintf(stderr, "PR_CreateThread failed\n");
exit(1);
diff --git a/pr/tests/sleep.c b/pr/tests/sleep.c
index 43ef34cd..3e00acab 100644
--- a/pr/tests/sleep.c
+++ b/pr/tests/sleep.c
@@ -30,58 +30,66 @@ static void Other(void *unused)
fprintf(stderr, ".");
didit += 1;
}
- if (didit < 5) rv = 1;
+ if (didit < 5) {
+ rv = 1;
+ }
}
int main(int argc, char **argv)
{
PRUint32 elapsed;
PRThread *thread;
- struct timeval timein, timeout;
+ struct timeval timein, timeout;
PRInt32 onePercent = 3000000UL / 100UL;
- fprintf (stderr, "First sleep will sleep 3 seconds.\n");
- fprintf (stderr, " sleep 1 begin\n");
+ fprintf (stderr, "First sleep will sleep 3 seconds.\n");
+ fprintf (stderr, " sleep 1 begin\n");
(void)GTOD(&timein);
- sleep (3);
+ sleep (3);
(void)GTOD(&timeout);
- fprintf (stderr, " sleep 1 end\n");
+ fprintf (stderr, " sleep 1 end\n");
elapsed = 1000000UL * (timeout.tv_sec - timein.tv_sec);
elapsed += (timeout.tv_usec - timein.tv_usec);
fprintf(stderr, "elapsed %u usecs\n", elapsed);
- if (labs(elapsed - 3000000UL) > onePercent) rv = 1;
+ if (labs(elapsed - 3000000UL) > onePercent) {
+ rv = 1;
+ }
- PR_Init (PR_USER_THREAD, PR_PRIORITY_NORMAL, 100);
+ PR_Init (PR_USER_THREAD, PR_PRIORITY_NORMAL, 100);
PR_STDIO_INIT();
- fprintf (stderr, "Second sleep should do the same (does it?).\n");
- fprintf (stderr, " sleep 2 begin\n");
+ fprintf (stderr, "Second sleep should do the same (does it?).\n");
+ fprintf (stderr, " sleep 2 begin\n");
(void)GTOD(&timein);
- sleep (3);
+ sleep (3);
(void)GTOD(&timeout);
- fprintf (stderr, " sleep 2 end\n");
+ fprintf (stderr, " sleep 2 end\n");
elapsed = 1000000UL * (timeout.tv_sec - timein.tv_sec);
elapsed += (timeout.tv_usec - timein.tv_usec);
fprintf(stderr, "elapsed %u usecs\n", elapsed);
- if (labs(elapsed - 3000000UL) > onePercent) rv = 1;
+ if (labs(elapsed - 3000000UL) > onePercent) {
+ rv = 1;
+ }
- fprintf (stderr, "What happens to other threads?\n");
- fprintf (stderr, "You should see dots every quarter second.\n");
- fprintf (stderr, "If you don't, you're probably running on classic NSPR.\n");
+ fprintf (stderr, "What happens to other threads?\n");
+ fprintf (stderr, "You should see dots every quarter second.\n");
+ fprintf (stderr, "If you don't, you're probably running on classic NSPR.\n");
thread = PR_CreateThread(
- PR_USER_THREAD, Other, NULL, PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
- fprintf (stderr, " sleep 2 begin\n");
+ PR_USER_THREAD, Other, NULL, PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
+ fprintf (stderr, " sleep 2 begin\n");
(void)GTOD(&timein);
- sleep (3);
+ sleep (3);
(void)GTOD(&timeout);
- fprintf (stderr, " sleep 2 end\n");
+ fprintf (stderr, " sleep 2 end\n");
PR_Interrupt(thread);
PR_JoinThread(thread);
elapsed = 1000000UL * (timeout.tv_sec - timein.tv_sec);
elapsed += (timeout.tv_usec - timein.tv_usec);
fprintf(stderr, "elapsed %u usecs\n", elapsed);
- if (labs(elapsed - 3000000UL) > onePercent) rv = 1;
+ if (labs(elapsed - 3000000UL) > onePercent) {
+ rv = 1;
+ }
fprintf(stderr, "%s\n", (0 == rv) ? "PASSED" : "FAILED");
return rv;
}
@@ -90,7 +98,7 @@ int main(int argc, char **argv)
PRIntn main()
{
- return 2;
+ return 2;
}
#endif /* defined(XP_UNIX) */
diff --git a/pr/tests/socket.c b/pr/tests/socket.c
index 9a9470c8..a4925350 100644
--- a/pr/tests/socket.c
+++ b/pr/tests/socket.c
@@ -49,27 +49,27 @@ char *TEST_DIR = "/tmp/prsocket_test_dir";
char *SMALL_FILE_NAME = "/tmp/prsocket_test_dir/small_file";
char *LARGE_FILE_NAME = "/tmp/prsocket_test_dir/large_file";
#endif
-#define SMALL_FILE_SIZE (3 * 1024) /* 3 KB */
-#define SMALL_FILE_OFFSET_1 (512)
-#define SMALL_FILE_LEN_1 (1 * 1024) /* 1 KB */
-#define SMALL_FILE_OFFSET_2 (75)
-#define SMALL_FILE_LEN_2 (758)
-#define SMALL_FILE_OFFSET_3 (1024)
-#define SMALL_FILE_LEN_3 (SMALL_FILE_SIZE - SMALL_FILE_OFFSET_3)
-#define SMALL_FILE_HEADER_SIZE (64) /* 64 bytes */
-#define SMALL_FILE_TRAILER_SIZE (128) /* 128 bytes */
-
-#define LARGE_FILE_SIZE (3 * 1024 * 1024) /* 3 MB */
-#define LARGE_FILE_OFFSET_1 (0)
-#define LARGE_FILE_LEN_1 (2 * 1024 * 1024) /* 2 MB */
-#define LARGE_FILE_OFFSET_2 (64)
-#define LARGE_FILE_LEN_2 (1 * 1024 * 1024 + 75)
-#define LARGE_FILE_OFFSET_3 (2 * 1024 * 1024 - 128)
-#define LARGE_FILE_LEN_3 (LARGE_FILE_SIZE - LARGE_FILE_OFFSET_3)
-#define LARGE_FILE_OFFSET_4 PR_GetPageSize()
-#define LARGE_FILE_LEN_4 769
-#define LARGE_FILE_HEADER_SIZE (512)
-#define LARGE_FILE_TRAILER_SIZE (64)
+#define SMALL_FILE_SIZE (3 * 1024) /* 3 KB */
+#define SMALL_FILE_OFFSET_1 (512)
+#define SMALL_FILE_LEN_1 (1 * 1024) /* 1 KB */
+#define SMALL_FILE_OFFSET_2 (75)
+#define SMALL_FILE_LEN_2 (758)
+#define SMALL_FILE_OFFSET_3 (1024)
+#define SMALL_FILE_LEN_3 (SMALL_FILE_SIZE - SMALL_FILE_OFFSET_3)
+#define SMALL_FILE_HEADER_SIZE (64) /* 64 bytes */
+#define SMALL_FILE_TRAILER_SIZE (128) /* 128 bytes */
+
+#define LARGE_FILE_SIZE (3 * 1024 * 1024) /* 3 MB */
+#define LARGE_FILE_OFFSET_1 (0)
+#define LARGE_FILE_LEN_1 (2 * 1024 * 1024) /* 2 MB */
+#define LARGE_FILE_OFFSET_2 (64)
+#define LARGE_FILE_LEN_2 (1 * 1024 * 1024 + 75)
+#define LARGE_FILE_OFFSET_3 (2 * 1024 * 1024 - 128)
+#define LARGE_FILE_LEN_3 (LARGE_FILE_SIZE - LARGE_FILE_OFFSET_3)
+#define LARGE_FILE_OFFSET_4 PR_GetPageSize()
+#define LARGE_FILE_LEN_4 769
+#define LARGE_FILE_HEADER_SIZE (512)
+#define LARGE_FILE_TRAILER_SIZE (64)
#define BUF_DATA_SIZE (2 * 1024)
#define TCP_MESG_SIZE 1024
@@ -78,7 +78,7 @@ char *LARGE_FILE_NAME = "/tmp/prsocket_test_dir/large_file";
* local host will not be lost
*/
#define UDP_DGRAM_SIZE 128
-#define NUM_TCP_CLIENTS 5 /* for a listen queue depth of 5 */
+#define NUM_TCP_CLIENTS 5 /* for a listen queue depth of 5 */
#define NUM_UDP_CLIENTS 10
#define NUM_TRANSMITFILE_CLIENTS 4
@@ -141,7 +141,7 @@ typedef struct Client_Param {
/* the sendfile method in emuSendFileMethods */
static PRInt32 PR_CALLBACK
emu_SendFile(PRFileDesc *sd, PRSendFileData *sfd,
- PRTransmitFileFlags flags, PRIntervalTime timeout)
+ PRTransmitFileFlags flags, PRIntervalTime timeout)
{
return PR_EmulateSendFile(sd, sfd, flags, timeout);
}
@@ -149,7 +149,7 @@ emu_SendFile(PRFileDesc *sd, PRSendFileData *sfd,
/* the transmitfile method in emuSendFileMethods */
static PRInt32 PR_CALLBACK
emu_TransmitFile(PRFileDesc *sd, PRFileDesc *fd, const void *headers,
- PRInt32 hlen, PRTransmitFileFlags flags, PRIntervalTime timeout)
+ PRInt32 hlen, PRTransmitFileFlags flags, PRIntervalTime timeout)
{
PRSendFileData sfd;
@@ -173,33 +173,35 @@ readn(PRFileDesc *sockfd, char *buf, int len)
int rem;
int bytes;
int offset = 0;
- int err;
- PRIntervalTime timeout = PR_INTERVAL_NO_TIMEOUT;
+ int err;
+ PRIntervalTime timeout = PR_INTERVAL_NO_TIMEOUT;
- if (test_cancelio)
- timeout = PR_SecondsToInterval(2);
+ if (test_cancelio) {
+ timeout = PR_SecondsToInterval(2);
+ }
for (rem=len; rem; offset += bytes, rem -= bytes) {
DPRINTF(("thread = 0x%lx: calling PR_Recv, bytes = %d\n",
- PR_GetCurrentThread(), rem));
+ PR_GetCurrentThread(), rem));
retry:
bytes = PR_Recv(sockfd, buf + offset, rem, 0,
- timeout);
+ timeout);
DPRINTF(("thread = 0x%lx: returning from PR_Recv, bytes = %d\n",
- PR_GetCurrentThread(), bytes));
+ PR_GetCurrentThread(), bytes));
if (bytes < 0) {
#ifdef WINNT
- printf("PR_Recv: error = %d oserr = %d\n",(err = PR_GetError()),
- PR_GetOSError());
- if ((test_cancelio) && (err == PR_IO_TIMEOUT_ERROR)) {
- if (PR_NT_CancelIo(sockfd) != PR_SUCCESS)
- printf("PR_NT_CancelIO: error = %d\n",PR_GetError());
- timeout = PR_INTERVAL_NO_TIMEOUT;
- goto retry;
- }
+ printf("PR_Recv: error = %d oserr = %d\n",(err = PR_GetError()),
+ PR_GetOSError());
+ if ((test_cancelio) && (err == PR_IO_TIMEOUT_ERROR)) {
+ if (PR_NT_CancelIo(sockfd) != PR_SUCCESS) {
+ printf("PR_NT_CancelIO: error = %d\n",PR_GetError());
+ }
+ timeout = PR_INTERVAL_NO_TIMEOUT;
+ goto retry;
+ }
#endif
- return -1;
- }
+ return -1;
+ }
}
return len;
}
@@ -217,13 +219,14 @@ writen(PRFileDesc *sockfd, char *buf, int len)
for (rem=len; rem; offset += bytes, rem -= bytes) {
DPRINTF(("thread = 0x%lx: calling PR_Send, bytes = %d\n",
- PR_GetCurrentThread(), rem));
+ PR_GetCurrentThread(), rem));
bytes = PR_Send(sockfd, buf + offset, rem, 0,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
DPRINTF(("thread = 0x%lx: returning from PR_Send, bytes = %d\n",
- PR_GetCurrentThread(), bytes));
- if (bytes <= 0)
+ PR_GetCurrentThread(), bytes));
+ if (bytes <= 0) {
return -1;
+ }
}
return len;
}
@@ -270,7 +273,7 @@ Serve_Client(void *arg)
fprintf(stderr,"prsocket_test: ERROR - PR_Shutdown\n");
}
DPRINTF(("Serve_Client [0x%lx]: inbuf[0] = 0x%lx\n",PR_GetCurrentThread(),
- (*((int *) in_buf->data))));
+ (*((int *) in_buf->data))));
if (writen(sockfd, in_buf->data, bytes) < bytes) {
fprintf(stderr,"prsocket_test: ERROR - Serve_Client:writen\n");
failed_already=1;
@@ -293,59 +296,61 @@ exit:
}
PRThread* create_new_thread(PRThreadType type,
- void (*start)(void *arg),
- void *arg,
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize, PRInt32 index)
+ void (*start)(void *arg),
+ void *arg,
+ PRThreadPriority priority,
+ PRThreadScope scope,
+ PRThreadState state,
+ PRUint32 stackSize, PRInt32 index)
{
-PRInt32 native_thread = 0;
+ PRInt32 native_thread = 0;
- PR_ASSERT(state == PR_UNJOINABLE_THREAD);
+ PR_ASSERT(state == PR_UNJOINABLE_THREAD);
#if defined(_PR_PTHREADS) || defined(WIN32)
- switch(index % 4) {
- case 0:
- scope = (PR_LOCAL_THREAD);
- break;
- case 1:
- scope = (PR_GLOBAL_THREAD);
- break;
- case 2:
- scope = (PR_GLOBAL_BOUND_THREAD);
- break;
- case 3:
- native_thread = 1;
- break;
- default:
- PR_NOT_REACHED("Invalid scope");
- break;
- }
- if (native_thread) {
+ switch(index % 4) {
+ case 0:
+ scope = (PR_LOCAL_THREAD);
+ break;
+ case 1:
+ scope = (PR_GLOBAL_THREAD);
+ break;
+ case 2:
+ scope = (PR_GLOBAL_BOUND_THREAD);
+ break;
+ case 3:
+ native_thread = 1;
+ break;
+ default:
+ PR_NOT_REACHED("Invalid scope");
+ break;
+ }
+ if (native_thread) {
#if defined(_PR_PTHREADS)
- pthread_t tid;
- if (!pthread_create(&tid, NULL, (void * (*)(void *)) start, arg))
- return((PRThread *) tid);
- else
- return (NULL);
+ pthread_t tid;
+ if (!pthread_create(&tid, NULL, (void * (*)(void *)) start, arg)) {
+ return((PRThread *) tid);
+ }
+ else {
+ return (NULL);
+ }
#else
- HANDLE thandle;
- unsigned tid;
-
- thandle = (HANDLE) _beginthreadex(
- NULL,
- stackSize,
- (unsigned (__stdcall *)(void *))start,
- arg,
- STACK_SIZE_PARAM_IS_A_RESERVATION,
- &tid);
- return((PRThread *) thandle);
+ HANDLE thandle;
+ unsigned tid;
+
+ thandle = (HANDLE) _beginthreadex(
+ NULL,
+ stackSize,
+ (unsigned (__stdcall *)(void *))start,
+ arg,
+ STACK_SIZE_PARAM_IS_A_RESERVATION,
+ &tid);
+ return((PRThread *) thandle);
#endif
- } else {
- return(PR_CreateThread(type,start,arg,priority,scope,state,stackSize));
- }
+ } else {
+ return(PR_CreateThread(type,start,arg,priority,scope,state,stackSize));
+ }
#else
- return(PR_CreateThread(type,start,arg,priority,scope,state,stackSize));
+ return(PR_CreateThread(type,start,arg,priority,scope,state,stackSize));
#endif
}
@@ -367,17 +372,17 @@ TCP_Server(void *arg)
/*
* Create a tcp socket
*/
- if ((sockfd = PR_OpenTCPSocket(server_domain)) == NULL) {
+ if ((sockfd = PR_OpenTCPSocket(server_domain)) == NULL) {
fprintf(stderr,"prsocket_test: PR_NewTCPSocket failed\n");
goto exit;
}
- memset(&netaddr, 0 , sizeof(netaddr));
+ memset(&netaddr, 0, sizeof(netaddr));
- if (PR_SetNetAddr(PR_IpAddrAny, server_domain, TCP_SERVER_PORT,
- &netaddr) == PR_FAILURE) {
+ if (PR_SetNetAddr(PR_IpAddrAny, server_domain, TCP_SERVER_PORT,
+ &netaddr) == PR_FAILURE) {
fprintf(stderr,"prsocket_test: PR_SetNetAddr failed\n");
goto exit;
- }
+ }
/*
* try a few times to bind server's address, if addresses are in
* use
@@ -387,8 +392,9 @@ TCP_Server(void *arg)
while (PR_Bind(sockfd, &netaddr) < 0) {
if (PR_GetError() == PR_ADDRESS_IN_USE_ERROR) {
netaddr.inet.port += 2;
- if (i++ < SERVER_MAX_BIND_COUNT)
+ if (i++ < SERVER_MAX_BIND_COUNT) {
continue;
+ }
}
fprintf(stderr,"prsocket_test: ERROR - PR_Bind failed\n");
perror("PR_Bind");
@@ -409,16 +415,16 @@ TCP_Server(void *arg)
}
DPRINTF(("TCP_Server: PR_BIND netaddr.inet.ip = 0x%lx, netaddr.inet.port = %d\n",
- netaddr.inet.ip, netaddr.inet.port));
- if (PR_SetNetAddr(PR_IpAddrLoopback, client_domain,
- PR_ntohs(PR_NetAddrInetPort(&netaddr)),
- &tcp_server_addr) == PR_FAILURE) {
+ netaddr.inet.ip, netaddr.inet.port));
+ if (PR_SetNetAddr(PR_IpAddrLoopback, client_domain,
+ PR_ntohs(PR_NetAddrInetPort(&netaddr)),
+ &tcp_server_addr) == PR_FAILURE) {
fprintf(stderr,"prsocket_test: PR_SetNetAddr failed\n");
goto exit;
- }
- if ((client_domain == PR_AF_INET6) && (server_domain == PR_AF_INET))
- PR_ConvertIPv4AddrToIPv6(PR_htonl(INADDR_LOOPBACK),
- &tcp_server_addr.ipv6.ip);
+ }
+ if ((client_domain == PR_AF_INET6) && (server_domain == PR_AF_INET))
+ PR_ConvertIPv4AddrToIPv6(PR_htonl(INADDR_LOOPBACK),
+ &tcp_server_addr.ipv6.ip);
/*
* Wake up parent thread because server address is bound and made
@@ -430,13 +436,13 @@ TCP_Server(void *arg)
/* test both null and non-null 'addr' argument to PR_Accept */
PRNetAddr *addrp = (i%2 ? &netaddr: NULL);
- DPRINTF(("TCP_Server: Accepting connection\n"));
+ DPRINTF(("TCP_Server: Accepting connection\n"));
if ((newsockfd = PR_Accept(sockfd, addrp,
- PR_INTERVAL_NO_TIMEOUT)) == NULL) {
+ PR_INTERVAL_NO_TIMEOUT)) == NULL) {
fprintf(stderr,"prsocket_test: ERROR - PR_Accept failed\n");
goto exit;
}
- DPRINTF(("TCP_Server: Accepted connection\n"));
+ DPRINTF(("TCP_Server: Accepted connection\n"));
scp = PR_NEW(Serve_Client_Param);
if (scp == NULL) {
fprintf(stderr,"prsocket_test: PR_NEW failed\n");
@@ -450,11 +456,11 @@ TCP_Server(void *arg)
scp->datalen = sp->datalen;
t = create_new_thread(PR_USER_THREAD,
- Serve_Client, (void *)scp,
- PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0, i);
+ Serve_Client, (void *)scp,
+ PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0, i);
if (t == NULL) {
fprintf(stderr,"prsocket_test: PR_CreateThread failed\n");
failed_already=1;
@@ -499,18 +505,18 @@ UDP_Server(void *arg)
/*
* Create a udp socket
*/
- if ((sockfd = PR_OpenUDPSocket(server_domain)) == NULL) {
+ if ((sockfd = PR_OpenUDPSocket(server_domain)) == NULL) {
fprintf(stderr,"prsocket_test: PR_NewUDPSocket failed\n");
failed_already=1;
return;
}
- memset(&netaddr, 0 , sizeof(netaddr));
- if (PR_SetNetAddr(PR_IpAddrAny, server_domain, UDP_SERVER_PORT,
- &netaddr) == PR_FAILURE) {
+ memset(&netaddr, 0, sizeof(netaddr));
+ if (PR_SetNetAddr(PR_IpAddrAny, server_domain, UDP_SERVER_PORT,
+ &netaddr) == PR_FAILURE) {
fprintf(stderr,"prsocket_test: PR_SetNetAddr failed\n");
failed_already=1;
return;
- }
+ }
/*
* try a few times to bind server's address, if addresses are in
* use
@@ -519,8 +525,9 @@ UDP_Server(void *arg)
while (PR_Bind(sockfd, &netaddr) < 0) {
if (PR_GetError() == PR_ADDRESS_IN_USE_ERROR) {
netaddr.inet.port += 2;
- if (i++ < SERVER_MAX_BIND_COUNT)
+ if (i++ < SERVER_MAX_BIND_COUNT) {
continue;
+ }
}
fprintf(stderr,"prsocket_test: ERROR - PR_Bind failed\n");
perror("PR_Bind");
@@ -535,23 +542,23 @@ UDP_Server(void *arg)
}
DPRINTF(("PR_Bind: UDP Server netaddr.inet.ip = 0x%lx, netaddr.inet.port = %d\n",
- netaddr.inet.ip, netaddr.inet.port));
+ netaddr.inet.ip, netaddr.inet.port));
/*
* We can't use the IP address returned by PR_GetSockName in
* netaddr.inet.ip because netaddr.inet.ip is returned
* as 0 (= PR_INADDR_ANY).
*/
- if (PR_SetNetAddr(PR_IpAddrLoopback, client_domain,
- PR_ntohs(PR_NetAddrInetPort(&netaddr)),
- &udp_server_addr) == PR_FAILURE) {
+ if (PR_SetNetAddr(PR_IpAddrLoopback, client_domain,
+ PR_ntohs(PR_NetAddrInetPort(&netaddr)),
+ &udp_server_addr) == PR_FAILURE) {
fprintf(stderr,"prsocket_test: PR_SetNetAddr failed\n");
failed_already=1;
return;
- }
- if ((client_domain == PR_AF_INET6) && (server_domain == PR_AF_INET))
- PR_ConvertIPv4AddrToIPv6(PR_htonl(INADDR_LOOPBACK),
- &udp_server_addr.ipv6.ip);
+ }
+ if ((client_domain == PR_AF_INET6) && (server_domain == PR_AF_INET))
+ PR_ConvertIPv4AddrToIPv6(PR_htonl(INADDR_LOOPBACK),
+ &udp_server_addr.ipv6.ip);
/*
* Wake up parent thread because server address is bound and made
@@ -570,22 +577,22 @@ UDP_Server(void *arg)
* Receive datagrams from clients and send them back, unmodified, to the
* clients
*/
- memset(&netaddr, 0 , sizeof(netaddr));
+ memset(&netaddr, 0, sizeof(netaddr));
for (i = 0; i < (num_udp_clients * num_udp_datagrams_per_client); i++) {
DPRINTF(("UDP_Server: calling PR_RecvFrom client - ip = 0x%lx, port = %d bytes = %d inbuf = 0x%lx, inbuf[0] = 0x%lx\n",
- netaddr.inet.ip, netaddr.inet.port, bytes, in_buf->data,
- in_buf->data[0]));
+ netaddr.inet.ip, netaddr.inet.port, bytes, in_buf->data,
+ in_buf->data[0]));
rv = PR_RecvFrom(sockfd, in_buf->data, bytes, 0, &netaddr,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
DPRINTF(("UDP_Server: PR_RecvFrom client - ip = 0x%lx, port = %d bytes = %d inbuf = 0x%lx, inbuf[0] = 0x%lx\n",
- netaddr.inet.ip, netaddr.inet.port, rv, in_buf->data,
- in_buf->data[0]));
+ netaddr.inet.ip, netaddr.inet.port, rv, in_buf->data,
+ in_buf->data[0]));
if (rv != bytes) {
return;
}
rv = PR_SendTo(sockfd, in_buf->data, bytes, 0, &netaddr,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
if (rv != bytes) {
return;
}
@@ -643,9 +650,9 @@ TCP_Client(void *arg)
failed_already=1;
return;
}
- if (PR_Connect(sockfd, &netaddr,PR_INTERVAL_NO_TIMEOUT) < 0){
- fprintf(stderr, "PR_Connect failed: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
+ if (PR_Connect(sockfd, &netaddr,PR_INTERVAL_NO_TIMEOUT) < 0) {
+ fprintf(stderr, "PR_Connect failed: (%ld, %ld)\n",
+ PR_GetError(), PR_GetOSError());
failed_already=1;
return;
}
@@ -658,8 +665,9 @@ TCP_Client(void *arg)
* write to server
*/
#ifdef WINNT
- if (test_cancelio && (j == 0))
- PR_Sleep(PR_SecondsToInterval(12));
+ if (test_cancelio && (j == 0)) {
+ PR_Sleep(PR_SecondsToInterval(12));
+ }
#endif
if (writen(sockfd, out_buf->data, bytes) < bytes) {
fprintf(stderr,"prsocket_test: ERROR - TCP_Client:writen\n");
@@ -667,7 +675,7 @@ TCP_Client(void *arg)
return;
}
DPRINTF(("TCP Client [0x%lx]: out_buf = 0x%lx out_buf[0] = 0x%lx\n",
- PR_GetCurrentThread(), out_buf, (*((int *) out_buf->data))));
+ PR_GetCurrentThread(), out_buf, (*((int *) out_buf->data))));
if (readn(sockfd, in_buf->data, bytes) < bytes) {
fprintf(stderr,"prsocket_test: ERROR - TCP_Client:readn\n");
failed_already=1;
@@ -748,13 +756,13 @@ UDP_Client(void *arg)
* bind an address for the client, let the system chose the port
* number
*/
- memset(&netaddr, 0 , sizeof(netaddr));
- if (PR_SetNetAddr(PR_IpAddrAny, client_domain, 0,
- &netaddr) == PR_FAILURE) {
+ memset(&netaddr, 0, sizeof(netaddr));
+ if (PR_SetNetAddr(PR_IpAddrAny, client_domain, 0,
+ &netaddr) == PR_FAILURE) {
fprintf(stderr,"prsocket_test: PR_SetNetAddr failed\n");
failed_already=1;
return;
- }
+ }
if (PR_Bind(sockfd, &netaddr) < 0) {
fprintf(stderr,"prsocket_test: ERROR - PR_Bind failed\n");
perror("PR_Bind");
@@ -768,12 +776,12 @@ UDP_Client(void *arg)
}
DPRINTF(("PR_Bind: UDP Client netaddr.inet.ip = 0x%lx, netaddr.inet.port = %d\n",
- netaddr.inet.ip, netaddr.inet.port));
+ netaddr.inet.ip, netaddr.inet.port));
netaddr = cp->server_addr;
if (cp->udp_connect) {
- if (PR_Connect(sockfd, &netaddr,PR_INTERVAL_NO_TIMEOUT) < 0){
+ if (PR_Connect(sockfd, &netaddr,PR_INTERVAL_NO_TIMEOUT) < 0) {
fprintf(stderr,"prsocket_test: PR_Connect failed\n");
failed_already=1;
return;
@@ -785,33 +793,33 @@ UDP_Client(void *arg)
* fill in random data
*/
DPRINTF(("UDP_Client [0x%lx]: out_buf = 0x%lx bytes = 0x%lx\n",
- PR_GetCurrentThread(), out_buf->data, bytes));
+ PR_GetCurrentThread(), out_buf->data, bytes));
memset(out_buf->data, ((PRInt32) (&netaddr)) + i, bytes);
/*
* write to server
*/
if (cp->udp_connect)
rv = PR_Send(sockfd, out_buf->data, bytes, 0,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
else
rv = PR_SendTo(sockfd, out_buf->data, bytes, 0, &netaddr,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
if (rv != bytes) {
return;
}
DPRINTF(("UDP_Client [0x%lx]: out_buf = 0x%lx out_buf[0] = 0x%lx\n",
- PR_GetCurrentThread(), out_buf, (*((int *) out_buf->data))));
+ PR_GetCurrentThread(), out_buf, (*((int *) out_buf->data))));
if (cp->udp_connect)
rv = PR_Recv(sockfd, in_buf->data, bytes, 0,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
else
rv = PR_RecvFrom(sockfd, in_buf->data, bytes, 0, &netaddr,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
if (rv != bytes) {
return;
}
DPRINTF(("UDP_Client [0x%lx]: in_buf = 0x%lx in_buf[0] = 0x%lx\n",
- PR_GetCurrentThread(), in_buf, (*((int *) in_buf->data))));
+ PR_GetCurrentThread(), in_buf, (*((int *) in_buf->data))));
/*
* verify the data read
*/
@@ -892,11 +900,11 @@ TCP_Socket_Client_Server_Test(void)
sparamp->exit_counter = &thread_count;
sparamp->datalen = datalen;
t = PR_CreateThread(PR_USER_THREAD,
- TCP_Server, (void *)sparamp,
- PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0);
+ TCP_Server, (void *)sparamp,
+ PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0);
if (t == NULL) {
fprintf(stderr,"prsocket_test: PR_CreateThread failed\n");
failed_already=1;
@@ -926,11 +934,11 @@ TCP_Socket_Client_Server_Test(void)
cparamp->datalen = datalen;
for (i = 0; i < num_tcp_clients; i++) {
t = create_new_thread(PR_USER_THREAD,
- TCP_Client, (void *) cparamp,
- PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0, i);
+ TCP_Client, (void *) cparamp,
+ PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0, i);
if (t == NULL) {
fprintf(stderr,"prsocket_test: PR_CreateThread failed\n");
failed_already=1;
@@ -947,9 +955,9 @@ TCP_Socket_Client_Server_Test(void)
PR_ExitMonitor(mon2);
printf("%30s","TCP_Socket_Client_Server_Test:");
printf("%2ld Server %2ld Clients %2ld connections_per_client\n",1l,
- num_tcp_clients, num_tcp_connections_per_client);
+ num_tcp_clients, num_tcp_connections_per_client);
printf("%30s %2ld messages_per_connection %4ld bytes_per_message\n",":",
- num_tcp_mesgs_per_connection, tcp_mesg_size);
+ num_tcp_mesgs_per_connection, tcp_mesg_size);
return 0;
}
@@ -1010,11 +1018,11 @@ UDP_Socket_Client_Server_Test(void)
sparamp->datalen = datalen;
DPRINTF(("Creating UDP server"));
t = PR_CreateThread(PR_USER_THREAD,
- UDP_Server, (void *)sparamp,
- PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0);
+ UDP_Server, (void *)sparamp,
+ PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0);
if (t == NULL) {
fprintf(stderr,"prsocket_test: PR_CreateThread failed\n");
failed_already=1;
@@ -1046,17 +1054,19 @@ UDP_Socket_Client_Server_Test(void)
* Cause every other client thread to connect udp sockets
*/
cparamp->udp_connect = udp_connect;
- if (udp_connect)
+ if (udp_connect) {
udp_connect = 0;
- else
+ }
+ else {
udp_connect = 1;
+ }
DPRINTF(("Creating UDP client %d\n", i));
t = PR_CreateThread(PR_USER_THREAD,
- UDP_Client, (void *) cparamp,
- PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0);
+ UDP_Client, (void *) cparamp,
+ PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0);
if (t == NULL) {
fprintf(stderr,"prsocket_test: PR_CreateThread failed\n");
failed_already=1;
@@ -1073,7 +1083,7 @@ UDP_Socket_Client_Server_Test(void)
printf("%30s","UDP_Socket_Client_Server_Test: ");
printf("%2ld Server %2ld Clients\n",1l, num_udp_clients);
printf("%30s %2ld datagrams_per_client %4ld bytes_per_datagram\n",":",
- num_udp_datagrams_per_client, udp_datagram_size);
+ num_udp_datagrams_per_client, udp_datagram_size);
return 0;
}
@@ -1092,17 +1102,17 @@ TransmitFile_Client(void *arg)
union PRNetAddr netaddr;
char *small_buf, *large_buf;
Client_Param *cp = (Client_Param *) arg;
- PRInt32 rlen;
+ PRInt32 rlen;
small_buf = (char*)PR_Malloc(SMALL_FILE_SIZE + SMALL_FILE_HEADER_SIZE +
- SMALL_FILE_TRAILER_SIZE);
+ SMALL_FILE_TRAILER_SIZE);
if (small_buf == NULL) {
fprintf(stderr,"prsocket_test: failed to alloc buffer\n");
failed_already=1;
return;
}
large_buf = (char*)PR_Malloc(LARGE_FILE_SIZE + LARGE_FILE_HEADER_SIZE +
- LARGE_FILE_TRAILER_SIZE);
+ LARGE_FILE_TRAILER_SIZE);
if (large_buf == NULL) {
fprintf(stderr,"prsocket_test: failed to alloc buffer\n");
failed_already=1;
@@ -1118,7 +1128,7 @@ TransmitFile_Client(void *arg)
return;
}
- if (PR_Connect(sockfd, &netaddr,PR_INTERVAL_NO_TIMEOUT) < 0){
+ if (PR_Connect(sockfd, &netaddr,PR_INTERVAL_NO_TIMEOUT) < 0) {
fprintf(stderr,"prsocket_test: PR_Connect failed\n");
failed_already=1;
return;
@@ -1129,22 +1139,22 @@ TransmitFile_Client(void *arg)
if (readn(sockfd, small_buf, SMALL_FILE_SIZE + SMALL_FILE_HEADER_SIZE)
!= (SMALL_FILE_SIZE + SMALL_FILE_HEADER_SIZE)) {
fprintf(stderr,
- "prsocket_test: TransmitFile_Client failed to receive file\n");
+ "prsocket_test: TransmitFile_Client failed to receive file\n");
failed_already=1;
return;
}
#if defined(XP_UNIX)
/* File transmission test can not be done because of large file's size */
- if (memcmp(small_file_header, small_buf, SMALL_FILE_HEADER_SIZE) != 0){
+ if (memcmp(small_file_header, small_buf, SMALL_FILE_HEADER_SIZE) != 0) {
fprintf(stderr,
- "prsocket_test: TransmitFile_Client ERROR - small file header data corruption\n");
+ "prsocket_test: TransmitFile_Client ERROR - small file header data corruption\n");
failed_already=1;
return;
}
if (memcmp(small_file_addr, small_buf + SMALL_FILE_HEADER_SIZE,
- SMALL_FILE_SIZE) != 0) {
+ SMALL_FILE_SIZE) != 0) {
fprintf(stderr,
- "prsocket_test: TransmitFile_Client ERROR - small file data corruption\n");
+ "prsocket_test: TransmitFile_Client ERROR - small file data corruption\n");
failed_already=1;
return;
}
@@ -1154,263 +1164,263 @@ TransmitFile_Client(void *arg)
*/
if (readn(sockfd, large_buf, LARGE_FILE_SIZE) != LARGE_FILE_SIZE) {
fprintf(stderr,
- "prsocket_test: TransmitFile_Client failed to receive file\n");
+ "prsocket_test: TransmitFile_Client failed to receive file\n");
failed_already=1;
return;
}
#if defined(XP_UNIX)
if (memcmp(large_file_addr, large_buf, LARGE_FILE_SIZE) != 0) {
fprintf(stderr,
- "prsocket_test: TransmitFile_Client ERROR - large file data corruption\n");
+ "prsocket_test: TransmitFile_Client ERROR - large file data corruption\n");
failed_already=1;
}
#endif
- /*
- * receive data from PR_SendFile
- */
- /*
- * case 1: small file with header and trailer
- */
+ /*
+ * receive data from PR_SendFile
+ */
+ /*
+ * case 1: small file with header and trailer
+ */
rlen = SMALL_FILE_SIZE + SMALL_FILE_HEADER_SIZE +
- SMALL_FILE_TRAILER_SIZE;
+ SMALL_FILE_TRAILER_SIZE;
if (readn(sockfd, small_buf, rlen) != rlen) {
fprintf(stderr,
- "prsocket_test: SendFile_Client failed to receive file\n");
+ "prsocket_test: SendFile_Client failed to receive file\n");
failed_already=1;
return;
}
#if defined(XP_UNIX)
- if (memcmp(small_file_header, small_buf, SMALL_FILE_HEADER_SIZE) != 0){
+ if (memcmp(small_file_header, small_buf, SMALL_FILE_HEADER_SIZE) != 0) {
fprintf(stderr,
- "SendFile 1. ERROR - small file header corruption\n");
+ "SendFile 1. ERROR - small file header corruption\n");
failed_already=1;
return;
}
if (memcmp(small_file_addr, small_buf + SMALL_FILE_HEADER_SIZE,
- SMALL_FILE_SIZE) != 0) {
+ SMALL_FILE_SIZE) != 0) {
fprintf(stderr,
- "SendFile 1. ERROR - small file data corruption\n");
+ "SendFile 1. ERROR - small file data corruption\n");
failed_already=1;
return;
}
if (memcmp(small_file_trailer,
- small_buf + SMALL_FILE_HEADER_SIZE + SMALL_FILE_SIZE,
- SMALL_FILE_TRAILER_SIZE) != 0) {
+ small_buf + SMALL_FILE_HEADER_SIZE + SMALL_FILE_SIZE,
+ SMALL_FILE_TRAILER_SIZE) != 0) {
fprintf(stderr,
- "SendFile 1. ERROR - small file trailer corruption\n");
+ "SendFile 1. ERROR - small file trailer corruption\n");
failed_already=1;
return;
}
#endif
- /*
- * case 2: partial large file at zero offset, file with header and trailer
- */
+ /*
+ * case 2: partial large file at zero offset, file with header and trailer
+ */
rlen = LARGE_FILE_LEN_1 + LARGE_FILE_HEADER_SIZE +
- LARGE_FILE_TRAILER_SIZE;
+ LARGE_FILE_TRAILER_SIZE;
if (readn(sockfd, large_buf, rlen) != rlen) {
fprintf(stderr,
- "prsocket_test: SendFile_Client failed to receive file\n");
+ "prsocket_test: SendFile_Client failed to receive file\n");
failed_already=1;
return;
}
#if defined(XP_UNIX)
- if (memcmp(large_file_header, large_buf, LARGE_FILE_HEADER_SIZE) != 0){
+ if (memcmp(large_file_header, large_buf, LARGE_FILE_HEADER_SIZE) != 0) {
fprintf(stderr,
- "SendFile 2. ERROR - large file header corruption\n");
+ "SendFile 2. ERROR - large file header corruption\n");
failed_already=1;
return;
}
if (memcmp(large_file_addr, large_buf + LARGE_FILE_HEADER_SIZE,
- LARGE_FILE_LEN_1) != 0) {
+ LARGE_FILE_LEN_1) != 0) {
fprintf(stderr,
- "SendFile 2. ERROR - large file data corruption\n");
+ "SendFile 2. ERROR - large file data corruption\n");
failed_already=1;
return;
}
if (memcmp(large_file_trailer,
- large_buf + LARGE_FILE_HEADER_SIZE + LARGE_FILE_LEN_1,
- LARGE_FILE_TRAILER_SIZE) != 0) {
+ large_buf + LARGE_FILE_HEADER_SIZE + LARGE_FILE_LEN_1,
+ LARGE_FILE_TRAILER_SIZE) != 0) {
fprintf(stderr,
- "SendFile 2. ERROR - large file trailer corruption\n");
+ "SendFile 2. ERROR - large file trailer corruption\n");
failed_already=1;
return;
}
#endif
- /*
- * case 3: partial small file at non-zero offset, with header
- */
+ /*
+ * case 3: partial small file at non-zero offset, with header
+ */
rlen = SMALL_FILE_LEN_1 + SMALL_FILE_HEADER_SIZE;
if (readn(sockfd, small_buf, rlen) != rlen) {
fprintf(stderr,
- "prsocket_test: SendFile_Client failed to receive file\n");
+ "prsocket_test: SendFile_Client failed to receive file\n");
failed_already=1;
return;
}
#if defined(XP_UNIX)
- if (memcmp(small_file_header, small_buf, SMALL_FILE_HEADER_SIZE) != 0){
+ if (memcmp(small_file_header, small_buf, SMALL_FILE_HEADER_SIZE) != 0) {
fprintf(stderr,
- "SendFile 3. ERROR - small file header corruption\n");
+ "SendFile 3. ERROR - small file header corruption\n");
failed_already=1;
return;
}
if (memcmp((char *) small_file_addr + SMALL_FILE_OFFSET_1,
- small_buf + SMALL_FILE_HEADER_SIZE, SMALL_FILE_LEN_1) != 0) {
+ small_buf + SMALL_FILE_HEADER_SIZE, SMALL_FILE_LEN_1) != 0) {
fprintf(stderr,
- "SendFile 3. ERROR - small file data corruption\n");
+ "SendFile 3. ERROR - small file data corruption\n");
failed_already=1;
return;
}
#endif
- /*
- * case 4: partial small file at non-zero offset, with trailer
- */
+ /*
+ * case 4: partial small file at non-zero offset, with trailer
+ */
rlen = SMALL_FILE_LEN_2 + SMALL_FILE_TRAILER_SIZE;
if (readn(sockfd, small_buf, rlen) != rlen) {
fprintf(stderr,
- "prsocket_test: SendFile_Client failed to receive file\n");
+ "prsocket_test: SendFile_Client failed to receive file\n");
failed_already=1;
return;
}
#if defined(XP_UNIX)
if (memcmp((char *) small_file_addr + SMALL_FILE_OFFSET_2, small_buf,
- SMALL_FILE_LEN_2) != 0) {
+ SMALL_FILE_LEN_2) != 0) {
fprintf(stderr,
- "SendFile 4. ERROR - small file data corruption\n");
+ "SendFile 4. ERROR - small file data corruption\n");
failed_already=1;
return;
}
if (memcmp(small_file_trailer, small_buf + SMALL_FILE_LEN_2,
- SMALL_FILE_TRAILER_SIZE) != 0) {
+ SMALL_FILE_TRAILER_SIZE) != 0) {
fprintf(stderr,
- "SendFile 4. ERROR - small file trailer corruption\n");
+ "SendFile 4. ERROR - small file trailer corruption\n");
failed_already=1;
return;
}
#endif
- /*
- * case 5: partial large file at non-zero offset, file with header
- */
+ /*
+ * case 5: partial large file at non-zero offset, file with header
+ */
rlen = LARGE_FILE_LEN_2 + LARGE_FILE_HEADER_SIZE;
if (readn(sockfd, large_buf, rlen) != rlen) {
fprintf(stderr,
- "prsocket_test: SendFile_Client failed to receive file\n");
+ "prsocket_test: SendFile_Client failed to receive file\n");
failed_already=1;
return;
}
#if defined(XP_UNIX)
- if (memcmp(large_file_header, large_buf, LARGE_FILE_HEADER_SIZE) != 0){
+ if (memcmp(large_file_header, large_buf, LARGE_FILE_HEADER_SIZE) != 0) {
fprintf(stderr,
- "SendFile 5. ERROR - large file header corruption\n");
+ "SendFile 5. ERROR - large file header corruption\n");
failed_already=1;
return;
}
if (memcmp((char *)large_file_addr + LARGE_FILE_OFFSET_2,
- large_buf + LARGE_FILE_HEADER_SIZE,
- LARGE_FILE_LEN_2) != 0) {
+ large_buf + LARGE_FILE_HEADER_SIZE,
+ LARGE_FILE_LEN_2) != 0) {
fprintf(stderr,
- "SendFile 5. ERROR - large file data corruption\n");
+ "SendFile 5. ERROR - large file data corruption\n");
failed_already=1;
return;
}
#endif
- /*
- * case 6: partial small file at non-zero offset, with header
- */
+ /*
+ * case 6: partial small file at non-zero offset, with header
+ */
rlen = SMALL_FILE_LEN_3 + SMALL_FILE_HEADER_SIZE;
if (readn(sockfd, small_buf, rlen) != rlen) {
fprintf(stderr,
- "prsocket_test: SendFile_Client failed to receive file\n");
+ "prsocket_test: SendFile_Client failed to receive file\n");
failed_already=1;
return;
}
#if defined(XP_UNIX)
- if (memcmp(small_file_header, small_buf, SMALL_FILE_HEADER_SIZE) != 0){
+ if (memcmp(small_file_header, small_buf, SMALL_FILE_HEADER_SIZE) != 0) {
fprintf(stderr,
- "SendFile 6. ERROR - small file header corruption\n");
+ "SendFile 6. ERROR - small file header corruption\n");
return;
}
if (memcmp((char *) small_file_addr + SMALL_FILE_OFFSET_3,
- small_buf + SMALL_FILE_HEADER_SIZE, SMALL_FILE_LEN_3) != 0) {
+ small_buf + SMALL_FILE_HEADER_SIZE, SMALL_FILE_LEN_3) != 0) {
#if 0
- char *i, *j;
- int k;
-
- i = (char *) small_file_addr + SMALL_FILE_OFFSET_3;
- j = small_buf + SMALL_FILE_HEADER_SIZE;
- k = SMALL_FILE_LEN_3;
- while (k-- > 0) {
- if (*i++ != *j++)
- printf("i = %d j = %d\n",
- (int) (i - ((char *) small_file_addr + SMALL_FILE_OFFSET_3)),
- (int) (j - (small_buf + SMALL_FILE_HEADER_SIZE)));
- }
+ char *i, *j;
+ int k;
+
+ i = (char *) small_file_addr + SMALL_FILE_OFFSET_3;
+ j = small_buf + SMALL_FILE_HEADER_SIZE;
+ k = SMALL_FILE_LEN_3;
+ while (k-- > 0) {
+ if (*i++ != *j++)
+ printf("i = %d j = %d\n",
+ (int) (i - ((char *) small_file_addr + SMALL_FILE_OFFSET_3)),
+ (int) (j - (small_buf + SMALL_FILE_HEADER_SIZE)));
+ }
#endif
fprintf(stderr,
- "SendFile 6. ERROR - small file data corruption\n");
+ "SendFile 6. ERROR - small file data corruption\n");
failed_already=1;
return;
}
#endif
- /*
- * case 7: partial large file at non-zero offset, with header
- */
+ /*
+ * case 7: partial large file at non-zero offset, with header
+ */
rlen = LARGE_FILE_LEN_3 + LARGE_FILE_HEADER_SIZE;
if (readn(sockfd, large_buf, rlen) != rlen) {
fprintf(stderr,
- "prsocket_test: SendFile_Client failed to receive file\n");
+ "prsocket_test: SendFile_Client failed to receive file\n");
failed_already=1;
return;
}
#if defined(XP_UNIX)
- if (memcmp(large_file_header, large_buf, LARGE_FILE_HEADER_SIZE) != 0){
+ if (memcmp(large_file_header, large_buf, LARGE_FILE_HEADER_SIZE) != 0) {
fprintf(stderr,
- "SendFile 7. ERROR - large file header corruption\n");
+ "SendFile 7. ERROR - large file header corruption\n");
failed_already=1;
return;
}
if (memcmp((char *)large_file_addr + LARGE_FILE_OFFSET_3,
- large_buf + LARGE_FILE_HEADER_SIZE,
- LARGE_FILE_LEN_3) != 0) {
+ large_buf + LARGE_FILE_HEADER_SIZE,
+ LARGE_FILE_LEN_3) != 0) {
fprintf(stderr,
- "SendFile 7. ERROR - large file data corruption\n");
+ "SendFile 7. ERROR - large file data corruption\n");
failed_already=1;
return;
}
#endif
- /*
- * case 8: partial large file at non-zero, page-aligned offset, with
- * header and trailer
- */
+ /*
+ * case 8: partial large file at non-zero, page-aligned offset, with
+ * header and trailer
+ */
rlen = LARGE_FILE_LEN_4 + LARGE_FILE_HEADER_SIZE +
- LARGE_FILE_TRAILER_SIZE;
+ LARGE_FILE_TRAILER_SIZE;
if (readn(sockfd, large_buf, rlen) != rlen) {
fprintf(stderr,
- "prsocket_test: SendFile_Client failed to receive file\n");
+ "prsocket_test: SendFile_Client failed to receive file\n");
failed_already=1;
return;
}
#if defined(XP_UNIX)
- if (memcmp(large_file_header, large_buf, LARGE_FILE_HEADER_SIZE) != 0){
+ if (memcmp(large_file_header, large_buf, LARGE_FILE_HEADER_SIZE) != 0) {
fprintf(stderr,
- "SendFile 2. ERROR - large file header corruption\n");
+ "SendFile 2. ERROR - large file header corruption\n");
failed_already=1;
return;
}
if (memcmp((char *)large_file_addr + LARGE_FILE_OFFSET_4,
- large_buf + LARGE_FILE_HEADER_SIZE,
- LARGE_FILE_LEN_4) != 0) {
+ large_buf + LARGE_FILE_HEADER_SIZE,
+ LARGE_FILE_LEN_4) != 0) {
fprintf(stderr,
- "SendFile 2. ERROR - large file data corruption\n");
+ "SendFile 2. ERROR - large file data corruption\n");
failed_already=1;
return;
}
if (memcmp(large_file_trailer,
- large_buf + LARGE_FILE_HEADER_SIZE + LARGE_FILE_LEN_4,
- LARGE_FILE_TRAILER_SIZE) != 0) {
+ large_buf + LARGE_FILE_HEADER_SIZE + LARGE_FILE_LEN_4,
+ LARGE_FILE_TRAILER_SIZE) != 0) {
fprintf(stderr,
- "SendFile 2. ERROR - large file trailer corruption\n");
+ "SendFile 2. ERROR - large file trailer corruption\n");
failed_already=1;
return;
}
@@ -1445,15 +1455,15 @@ Serve_TransmitFile_Client(void *arg)
PRInt32 bytes;
PRFileDesc *local_small_file_fd=NULL;
PRFileDesc *local_large_file_fd=NULL;
- PRSendFileData sfd;
- PRInt32 slen;
+ PRSendFileData sfd;
+ PRInt32 slen;
sockfd = scp->sockfd;
local_small_file_fd = PR_Open(SMALL_FILE_NAME, PR_RDONLY,0);
if (local_small_file_fd == NULL) {
fprintf(stderr,"prsocket_test failed to open file for transmitting %s\n",
- SMALL_FILE_NAME);
+ SMALL_FILE_NAME);
failed_already=1;
goto done;
}
@@ -1461,218 +1471,220 @@ Serve_TransmitFile_Client(void *arg)
if (local_large_file_fd == NULL) {
fprintf(stderr,"prsocket_test failed to open file for transmitting %s\n",
- LARGE_FILE_NAME);
+ LARGE_FILE_NAME);
failed_already=1;
goto done;
}
bytes = PR_TransmitFile(sockfd, local_small_file_fd, small_file_header,
- SMALL_FILE_HEADER_SIZE, PR_TRANSMITFILE_KEEP_OPEN,
- PR_INTERVAL_NO_TIMEOUT);
+ SMALL_FILE_HEADER_SIZE, PR_TRANSMITFILE_KEEP_OPEN,
+ PR_INTERVAL_NO_TIMEOUT);
if (bytes != (SMALL_FILE_SIZE+ SMALL_FILE_HEADER_SIZE)) {
fprintf(stderr,
- "prsocet_test: PR_TransmitFile failed: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
+ "prsocet_test: PR_TransmitFile failed: (%ld, %ld)\n",
+ PR_GetError(), PR_GetOSError());
failed_already=1;
}
bytes = PR_TransmitFile(sockfd, local_large_file_fd, NULL, 0,
- PR_TRANSMITFILE_KEEP_OPEN, PR_INTERVAL_NO_TIMEOUT);
+ PR_TRANSMITFILE_KEEP_OPEN, PR_INTERVAL_NO_TIMEOUT);
if (bytes != LARGE_FILE_SIZE) {
fprintf(stderr,
- "prsocket_test: PR_TransmitFile failed: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
+ "prsocket_test: PR_TransmitFile failed: (%ld, %ld)\n",
+ PR_GetError(), PR_GetOSError());
failed_already=1;
}
- /*
- * PR_SendFile test cases
- */
+ /*
+ * PR_SendFile test cases
+ */
- /*
- * case 1: small file with header and trailer
- */
- sfd.fd = local_small_file_fd;
- sfd.file_offset = 0;
- sfd.file_nbytes = 0;
- sfd.header = small_file_header;
- sfd.hlen = SMALL_FILE_HEADER_SIZE;
- sfd.trailer = small_file_trailer;
- sfd.tlen = SMALL_FILE_TRAILER_SIZE;
+ /*
+ * case 1: small file with header and trailer
+ */
+ sfd.fd = local_small_file_fd;
+ sfd.file_offset = 0;
+ sfd.file_nbytes = 0;
+ sfd.header = small_file_header;
+ sfd.hlen = SMALL_FILE_HEADER_SIZE;
+ sfd.trailer = small_file_trailer;
+ sfd.tlen = SMALL_FILE_TRAILER_SIZE;
bytes = PR_SendFile(sockfd, &sfd, PR_TRANSMITFILE_KEEP_OPEN,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
slen = SMALL_FILE_SIZE+ SMALL_FILE_HEADER_SIZE +
- SMALL_FILE_TRAILER_SIZE;
+ SMALL_FILE_TRAILER_SIZE;
if (bytes != slen) {
fprintf(stderr,
- "socket: Error - 1. PR_SendFile send_size = %d, bytes sent = %d\n",
- slen, bytes);
+ "socket: Error - 1. PR_SendFile send_size = %d, bytes sent = %d\n",
+ slen, bytes);
fprintf(stderr,
- "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
+ "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
+ PR_GetError(), PR_GetOSError());
failed_already=1;
}
- /*
- * case 2: partial large file at zero offset, file with header and trailer
- */
- sfd.fd = local_large_file_fd;
- sfd.file_offset = 0;
- sfd.file_nbytes = LARGE_FILE_LEN_1;
- sfd.header = large_file_header;
- sfd.hlen = LARGE_FILE_HEADER_SIZE;
- sfd.trailer = large_file_trailer;
- sfd.tlen = LARGE_FILE_TRAILER_SIZE;
+ /*
+ * case 2: partial large file at zero offset, file with header and trailer
+ */
+ sfd.fd = local_large_file_fd;
+ sfd.file_offset = 0;
+ sfd.file_nbytes = LARGE_FILE_LEN_1;
+ sfd.header = large_file_header;
+ sfd.hlen = LARGE_FILE_HEADER_SIZE;
+ sfd.trailer = large_file_trailer;
+ sfd.tlen = LARGE_FILE_TRAILER_SIZE;
bytes = PR_SendFile(sockfd, &sfd, PR_TRANSMITFILE_KEEP_OPEN,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
slen = LARGE_FILE_LEN_1 + LARGE_FILE_HEADER_SIZE +
- LARGE_FILE_TRAILER_SIZE;
+ LARGE_FILE_TRAILER_SIZE;
if (bytes != slen) {
fprintf(stderr,
- "socket: Error - 2. PR_SendFile send_size = %d, bytes sent = %d\n",
- slen, bytes);
+ "socket: Error - 2. PR_SendFile send_size = %d, bytes sent = %d\n",
+ slen, bytes);
fprintf(stderr,
- "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
- failed_already=1;
- }
- /*
- * case 3: partial small file at non-zero offset, with header
- */
- sfd.fd = local_small_file_fd;
- sfd.file_offset = SMALL_FILE_OFFSET_1;
- sfd.file_nbytes = SMALL_FILE_LEN_1;
- sfd.header = small_file_header;
- sfd.hlen = SMALL_FILE_HEADER_SIZE;
- sfd.trailer = NULL;
- sfd.tlen = 0;
+ "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
+ PR_GetError(), PR_GetOSError());
+ failed_already=1;
+ }
+ /*
+ * case 3: partial small file at non-zero offset, with header
+ */
+ sfd.fd = local_small_file_fd;
+ sfd.file_offset = SMALL_FILE_OFFSET_1;
+ sfd.file_nbytes = SMALL_FILE_LEN_1;
+ sfd.header = small_file_header;
+ sfd.hlen = SMALL_FILE_HEADER_SIZE;
+ sfd.trailer = NULL;
+ sfd.tlen = 0;
bytes = PR_SendFile(sockfd, &sfd, PR_TRANSMITFILE_KEEP_OPEN,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
slen = SMALL_FILE_LEN_1 + SMALL_FILE_HEADER_SIZE;
if (bytes != slen) {
fprintf(stderr,
- "socket: Error - 3. PR_SendFile send_size = %d, bytes sent = %d\n",
- slen, bytes);
+ "socket: Error - 3. PR_SendFile send_size = %d, bytes sent = %d\n",
+ slen, bytes);
fprintf(stderr,
- "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
- failed_already=1;
- }
- /*
- * case 4: partial small file at non-zero offset, with trailer
- */
- sfd.fd = local_small_file_fd;
- sfd.file_offset = SMALL_FILE_OFFSET_2;
- sfd.file_nbytes = SMALL_FILE_LEN_2;
- sfd.header = NULL;
- sfd.hlen = 0;
- sfd.trailer = small_file_trailer;
- sfd.tlen = SMALL_FILE_TRAILER_SIZE;
+ "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
+ PR_GetError(), PR_GetOSError());
+ failed_already=1;
+ }
+ /*
+ * case 4: partial small file at non-zero offset, with trailer
+ */
+ sfd.fd = local_small_file_fd;
+ sfd.file_offset = SMALL_FILE_OFFSET_2;
+ sfd.file_nbytes = SMALL_FILE_LEN_2;
+ sfd.header = NULL;
+ sfd.hlen = 0;
+ sfd.trailer = small_file_trailer;
+ sfd.tlen = SMALL_FILE_TRAILER_SIZE;
bytes = PR_SendFile(sockfd, &sfd, PR_TRANSMITFILE_KEEP_OPEN,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
slen = SMALL_FILE_LEN_2 + SMALL_FILE_TRAILER_SIZE;
if (bytes != slen) {
fprintf(stderr,
- "socket: Error - 4. PR_SendFile send_size = %d, bytes sent = %d\n",
- slen, bytes);
+ "socket: Error - 4. PR_SendFile send_size = %d, bytes sent = %d\n",
+ slen, bytes);
fprintf(stderr,
- "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
- failed_already=1;
- }
- /*
- * case 5: partial large file at non-zero offset, file with header
- */
- sfd.fd = local_large_file_fd;
- sfd.file_offset = LARGE_FILE_OFFSET_2;
- sfd.file_nbytes = LARGE_FILE_LEN_2;
- sfd.header = large_file_header;
- sfd.hlen = LARGE_FILE_HEADER_SIZE;
- sfd.trailer = NULL;
- sfd.tlen = 0;
+ "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
+ PR_GetError(), PR_GetOSError());
+ failed_already=1;
+ }
+ /*
+ * case 5: partial large file at non-zero offset, file with header
+ */
+ sfd.fd = local_large_file_fd;
+ sfd.file_offset = LARGE_FILE_OFFSET_2;
+ sfd.file_nbytes = LARGE_FILE_LEN_2;
+ sfd.header = large_file_header;
+ sfd.hlen = LARGE_FILE_HEADER_SIZE;
+ sfd.trailer = NULL;
+ sfd.tlen = 0;
bytes = PR_SendFile(sockfd, &sfd, PR_TRANSMITFILE_KEEP_OPEN,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
slen = LARGE_FILE_LEN_2 + LARGE_FILE_HEADER_SIZE;
if (bytes != slen) {
fprintf(stderr,
- "socket: Error - 5. PR_SendFile send_size = %d, bytes sent = %d\n",
- slen, bytes);
+ "socket: Error - 5. PR_SendFile send_size = %d, bytes sent = %d\n",
+ slen, bytes);
fprintf(stderr,
- "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
- failed_already=1;
- }
- /*
- * case 6: partial small file from non-zero offset till end of file, with header
- */
- sfd.fd = local_small_file_fd;
- sfd.file_offset = SMALL_FILE_OFFSET_3;
- sfd.file_nbytes = 0; /* data from offset to end-of-file */
- sfd.header = small_file_header;
- sfd.hlen = SMALL_FILE_HEADER_SIZE;
- sfd.trailer = NULL;
- sfd.tlen = 0;
+ "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
+ PR_GetError(), PR_GetOSError());
+ failed_already=1;
+ }
+ /*
+ * case 6: partial small file from non-zero offset till end of file, with header
+ */
+ sfd.fd = local_small_file_fd;
+ sfd.file_offset = SMALL_FILE_OFFSET_3;
+ sfd.file_nbytes = 0; /* data from offset to end-of-file */
+ sfd.header = small_file_header;
+ sfd.hlen = SMALL_FILE_HEADER_SIZE;
+ sfd.trailer = NULL;
+ sfd.tlen = 0;
bytes = PR_SendFile(sockfd, &sfd, PR_TRANSMITFILE_KEEP_OPEN,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
slen = SMALL_FILE_LEN_3 + SMALL_FILE_HEADER_SIZE;
if (bytes != slen) {
fprintf(stderr,
- "socket: Error - 6. PR_SendFile send_size = %d, bytes sent = %d\n",
- slen, bytes);
+ "socket: Error - 6. PR_SendFile send_size = %d, bytes sent = %d\n",
+ slen, bytes);
fprintf(stderr,
- "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
- failed_already=1;
- }
- /*
- * case 7: partial large file at non-zero offset till end-of-file, with header
- */
- sfd.fd = local_large_file_fd;
- sfd.file_offset = LARGE_FILE_OFFSET_3;
- sfd.file_nbytes = 0; /* data until end-of-file */
- sfd.header = large_file_header;
- sfd.hlen = LARGE_FILE_HEADER_SIZE;
- sfd.trailer = NULL;
- sfd.tlen = 0;
+ "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
+ PR_GetError(), PR_GetOSError());
+ failed_already=1;
+ }
+ /*
+ * case 7: partial large file at non-zero offset till end-of-file, with header
+ */
+ sfd.fd = local_large_file_fd;
+ sfd.file_offset = LARGE_FILE_OFFSET_3;
+ sfd.file_nbytes = 0; /* data until end-of-file */
+ sfd.header = large_file_header;
+ sfd.hlen = LARGE_FILE_HEADER_SIZE;
+ sfd.trailer = NULL;
+ sfd.tlen = 0;
bytes = PR_SendFile(sockfd, &sfd, PR_TRANSMITFILE_KEEP_OPEN,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
slen = LARGE_FILE_LEN_3 + LARGE_FILE_HEADER_SIZE;
if (bytes != slen) {
fprintf(stderr,
- "socket: Error - 7. PR_SendFile send_size = %d, bytes sent = %d\n",
- slen, bytes);
+ "socket: Error - 7. PR_SendFile send_size = %d, bytes sent = %d\n",
+ slen, bytes);
fprintf(stderr,
- "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
- failed_already=1;
- }
- /*
- * case 8: partial large file at non-zero page-aligned offset,
- * with header and trailer
- */
- sfd.fd = local_large_file_fd;
- sfd.file_offset = LARGE_FILE_OFFSET_4;
- sfd.file_nbytes = LARGE_FILE_LEN_4;
- sfd.header = large_file_header;
- sfd.hlen = LARGE_FILE_HEADER_SIZE;
- sfd.trailer = large_file_trailer;
- sfd.tlen = LARGE_FILE_TRAILER_SIZE;
+ "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
+ PR_GetError(), PR_GetOSError());
+ failed_already=1;
+ }
+ /*
+ * case 8: partial large file at non-zero page-aligned offset,
+ * with header and trailer
+ */
+ sfd.fd = local_large_file_fd;
+ sfd.file_offset = LARGE_FILE_OFFSET_4;
+ sfd.file_nbytes = LARGE_FILE_LEN_4;
+ sfd.header = large_file_header;
+ sfd.hlen = LARGE_FILE_HEADER_SIZE;
+ sfd.trailer = large_file_trailer;
+ sfd.tlen = LARGE_FILE_TRAILER_SIZE;
bytes = PR_SendFile(sockfd, &sfd, PR_TRANSMITFILE_CLOSE_SOCKET,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
slen = LARGE_FILE_LEN_4 + LARGE_FILE_HEADER_SIZE +
- LARGE_FILE_TRAILER_SIZE;
+ LARGE_FILE_TRAILER_SIZE;
if (bytes != slen) {
fprintf(stderr,
- "socket: Error - 2. PR_SendFile send_size = %d, bytes sent = %d\n",
- slen, bytes);
+ "socket: Error - 2. PR_SendFile send_size = %d, bytes sent = %d\n",
+ slen, bytes);
fprintf(stderr,
- "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
+ "prsocket_test: PR_SendFile failed: (%ld, %ld)\n",
+ PR_GetError(), PR_GetOSError());
failed_already=1;
}
done:
- if (local_small_file_fd != NULL)
+ if (local_small_file_fd != NULL) {
PR_Close(local_small_file_fd);
- if (local_large_file_fd != NULL)
+ }
+ if (local_large_file_fd != NULL) {
PR_Close(local_large_file_fd);
+ }
}
/*
@@ -1705,7 +1717,7 @@ TransmitFile_Server(void *arg)
failed_already=1;
goto exit;
}
- memset(&netaddr, 0 , sizeof(netaddr));
+ memset(&netaddr, 0, sizeof(netaddr));
netaddr.inet.family = PR_AF_INET;
netaddr.inet.port = PR_htons(TCP_SERVER_PORT);
netaddr.inet.ip = PR_htonl(PR_INADDR_ANY);
@@ -1717,8 +1729,9 @@ TransmitFile_Server(void *arg)
while (PR_Bind(sockfd, &netaddr) < 0) {
if (PR_GetError() == PR_ADDRESS_IN_USE_ERROR) {
netaddr.inet.port += 2;
- if (i++ < SERVER_MAX_BIND_COUNT)
+ if (i++ < SERVER_MAX_BIND_COUNT) {
continue;
+ }
}
fprintf(stderr,"prsocket_test: ERROR - PR_Bind failed\n");
failed_already=1;
@@ -1734,13 +1747,13 @@ TransmitFile_Server(void *arg)
if (PR_GetSockName(sockfd, &netaddr) < 0) {
fprintf(stderr,
- "prsocket_test: ERROR - PR_GetSockName failed\n");
+ "prsocket_test: ERROR - PR_GetSockName failed\n");
failed_already=1;
goto exit;
}
DPRINTF(("TCP_Server: PR_BIND netaddr.inet.ip = 0x%lx, netaddr.inet.port = %d\n",
- netaddr.inet.ip, netaddr.inet.port));
+ netaddr.inet.ip, netaddr.inet.port));
tcp_server_addr.inet.family = netaddr.inet.family;
tcp_server_addr.inet.port = netaddr.inet.port;
tcp_server_addr.inet.ip = netaddr.inet.ip;
@@ -1756,26 +1769,26 @@ TransmitFile_Server(void *arg)
PRNetAddr *addrp = (i%2 ? &netaddr: NULL);
if ((newsockfd = PR_Accept(sockfd, addrp,
- PR_INTERVAL_NO_TIMEOUT)) == NULL) {
+ PR_INTERVAL_NO_TIMEOUT)) == NULL) {
fprintf(stderr,
- "prsocket_test: ERROR - PR_Accept failed\n");
+ "prsocket_test: ERROR - PR_Accept failed\n");
failed_already=1;
goto exit;
}
/* test both regular and emulated PR_SendFile */
if (i%2) {
PRFileDesc *layer = PR_CreateIOLayerStub(
- emuSendFileIdentity, &emuSendFileMethods);
+ emuSendFileIdentity, &emuSendFileMethods);
if (layer == NULL) {
fprintf(stderr,
- "prsocket_test: ERROR - PR_CreateIOLayerStub failed\n");
+ "prsocket_test: ERROR - PR_CreateIOLayerStub failed\n");
failed_already=1;
goto exit;
}
if (PR_PushIOLayer(newsockfd, PR_TOP_IO_LAYER, layer)
- == PR_FAILURE) {
+ == PR_FAILURE) {
fprintf(stderr,
- "prsocket_test: ERROR - PR_PushIOLayer failed\n");
+ "prsocket_test: ERROR - PR_PushIOLayer failed\n");
failed_already=1;
goto exit;
}
@@ -1794,14 +1807,14 @@ TransmitFile_Server(void *arg)
scp->datalen = sp->datalen;
t[i] = PR_CreateThread(PR_USER_THREAD,
- Serve_TransmitFile_Client, (void *)scp,
- PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD,
- PR_JOINABLE_THREAD,
- 0);
+ Serve_TransmitFile_Client, (void *)scp,
+ PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD,
+ PR_JOINABLE_THREAD,
+ 0);
if (t[i] == NULL) {
fprintf(stderr,
- "prsocket_test: PR_CreateThread failed\n");
+ "prsocket_test: PR_CreateThread failed\n");
failed_already=1;
goto exit;
}
@@ -1852,9 +1865,9 @@ Socket_Misc_Test(void)
PRInt32 datalen;
/*
- * We deliberately pick a buffer size that is not a nice multiple
- * of 1024.
- */
+ * We deliberately pick a buffer size that is not a nice multiple
+ * of 1024.
+ */
#define TRANSMITFILE_BUF_SIZE (4 * 1024 - 11)
typedef struct {
@@ -1875,7 +1888,7 @@ Socket_Misc_Test(void)
if (small_file_fd == NULL) {
fprintf(stderr,"prsocket_test failed to create/open file %s\n",
- SMALL_FILE_NAME);
+ SMALL_FILE_NAME);
failed_already=1;
rv = -1;
goto done;
@@ -1896,12 +1909,12 @@ Socket_Misc_Test(void)
count = 0;
do {
len = (SMALL_FILE_SIZE - count) > TRANSMITFILE_BUF_SIZE ?
- TRANSMITFILE_BUF_SIZE : (SMALL_FILE_SIZE - count);
+ TRANSMITFILE_BUF_SIZE : (SMALL_FILE_SIZE - count);
bytes = PR_Write(small_file_fd, buf->data, len);
if (bytes <= 0) {
fprintf(stderr,
- "prsocket_test failed to write to file %s\n",
- SMALL_FILE_NAME);
+ "prsocket_test failed to write to file %s\n",
+ SMALL_FILE_NAME);
failed_already=1;
rv = -1;
goto done;
@@ -1913,10 +1926,10 @@ Socket_Misc_Test(void)
* map the small file; used in checking for data corruption
*/
small_file_addr = mmap(0, SMALL_FILE_SIZE, PROT_READ,
- MAP_SHARED, small_file_fd->secret->md.osfd, 0);
+ MAP_SHARED, small_file_fd->secret->md.osfd, 0);
if (small_file_addr == (void *) -1) {
fprintf(stderr,"prsocket_test failed to mmap file %s\n",
- SMALL_FILE_NAME);
+ SMALL_FILE_NAME);
failed_already=1;
rv = -1;
goto done;
@@ -1933,7 +1946,7 @@ Socket_Misc_Test(void)
goto done;
}
memset(small_file_header, (int) PR_IntervalNow(),
- SMALL_FILE_HEADER_SIZE);
+ SMALL_FILE_HEADER_SIZE);
/*
* trailer for small file
*/
@@ -1945,7 +1958,7 @@ Socket_Misc_Test(void)
goto done;
}
memset(small_file_trailer, (int) PR_IntervalNow(),
- SMALL_FILE_TRAILER_SIZE);
+ SMALL_FILE_TRAILER_SIZE);
/*
* setup large file
*/
@@ -1953,7 +1966,7 @@ Socket_Misc_Test(void)
if (large_file_fd == NULL) {
fprintf(stderr,"prsocket_test failed to create/open file %s\n",
- LARGE_FILE_NAME);
+ LARGE_FILE_NAME);
failed_already=1;
rv = -1;
goto done;
@@ -1967,13 +1980,13 @@ Socket_Misc_Test(void)
count = 0;
do {
len = (LARGE_FILE_SIZE - count) > TRANSMITFILE_BUF_SIZE ?
- TRANSMITFILE_BUF_SIZE : (LARGE_FILE_SIZE - count);
+ TRANSMITFILE_BUF_SIZE : (LARGE_FILE_SIZE - count);
bytes = PR_Write(large_file_fd, buf->data, len);
if (bytes <= 0) {
fprintf(stderr,
- "prsocket_test failed to write to file %s: (%ld, %ld)\n",
- LARGE_FILE_NAME,
- PR_GetError(), PR_GetOSError());
+ "prsocket_test failed to write to file %s: (%ld, %ld)\n",
+ LARGE_FILE_NAME,
+ PR_GetError(), PR_GetOSError());
failed_already=1;
rv = -1;
goto done;
@@ -1985,10 +1998,10 @@ Socket_Misc_Test(void)
* map the large file; used in checking for data corruption
*/
large_file_addr = mmap(0, LARGE_FILE_SIZE, PROT_READ,
- MAP_SHARED, large_file_fd->secret->md.osfd, 0);
+ MAP_SHARED, large_file_fd->secret->md.osfd, 0);
if (large_file_addr == (void *) -1) {
fprintf(stderr,"prsocket_test failed to mmap file %s\n",
- LARGE_FILE_NAME);
+ LARGE_FILE_NAME);
failed_already=1;
rv = -1;
goto done;
@@ -2005,7 +2018,7 @@ Socket_Misc_Test(void)
goto done;
}
memset(large_file_header, (int) PR_IntervalNow(),
- LARGE_FILE_HEADER_SIZE);
+ LARGE_FILE_HEADER_SIZE);
/*
* trailer for large file
*/
@@ -2017,7 +2030,7 @@ Socket_Misc_Test(void)
goto done;
}
memset(large_file_trailer, (int) PR_IntervalNow(),
- LARGE_FILE_TRAILER_SIZE);
+ LARGE_FILE_TRAILER_SIZE);
datalen = tcp_mesg_size;
thread_count = 0;
@@ -2052,11 +2065,11 @@ Socket_Misc_Test(void)
sparamp->exit_counter = &thread_count;
sparamp->datalen = datalen;
t = PR_CreateThread(PR_USER_THREAD,
- TransmitFile_Server, (void *)sparamp,
- PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0);
+ TransmitFile_Server, (void *)sparamp,
+ PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0);
if (t == NULL) {
fprintf(stderr,"prsocket_test: PR_CreateThread failed\n");
failed_already=1;
@@ -2089,11 +2102,11 @@ Socket_Misc_Test(void)
cparamp->datalen = datalen;
for (i = 0; i < num_transmitfile_clients; i++) {
t = create_new_thread(PR_USER_THREAD,
- TransmitFile_Client, (void *) cparamp,
- PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0, i);
+ TransmitFile_Client, (void *) cparamp,
+ PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0, i);
if (t == NULL) {
fprintf(stderr,"prsocket_test: PR_CreateThread failed\n");
rv = -1;
@@ -2121,24 +2134,24 @@ done:
PR_Close(large_file_fd);
if ((PR_Delete(SMALL_FILE_NAME)) == PR_FAILURE) {
fprintf(stderr,"prsocket_test: failed to unlink file %s\n",
- SMALL_FILE_NAME);
+ SMALL_FILE_NAME);
failed_already=1;
}
if ((PR_Delete(LARGE_FILE_NAME)) == PR_FAILURE) {
fprintf(stderr,"prsocket_test: failed to unlink file %s\n",
- LARGE_FILE_NAME);
+ LARGE_FILE_NAME);
failed_already=1;
}
if ((PR_RmDir(TEST_DIR)) == PR_FAILURE) {
fprintf(stderr,"prsocket_test failed to rmdir %s: (%ld, %ld)\n",
- TEST_DIR, PR_GetError(), PR_GetOSError());
+ TEST_DIR, PR_GetError(), PR_GetOSError());
failed_already=1;
}
printf("%-29s%s","Socket_Misc_Test",":");
printf("%2d Server %2d Clients\n",1, num_transmitfile_clients);
printf("%30s Sizes of Transmitted Files - %4d KB, %2d MB \n",":",
- SMALL_FILE_SIZE/1024, LARGE_FILE_SIZE/(1024 * 1024));
+ SMALL_FILE_SIZE/1024, LARGE_FILE_SIZE/(1024 * 1024));
return rv;
@@ -2159,14 +2172,16 @@ int main(int argc, char **argv)
PLOptState *opt = PL_CreateOptState(argc, argv, "d");
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_on = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ _debug_on = 1;
+ break;
+ default:
+ break;
}
}
PL_DestroyOptState(opt);
@@ -2184,45 +2199,49 @@ int main(int argc, char **argv)
/*
* run client-server test with TCP, Ipv4-Ipv4
*/
- printf("TCP Client/Server Test - IPv4/Ipv4\n");
+ printf("TCP Client/Server Test - IPv4/Ipv4\n");
if (TCP_Socket_Client_Server_Test() < 0) {
printf("TCP_Socket_Client_Server_Test failed\n");
goto done;
- } else
+ } else {
printf("TCP_Socket_Client_Server_Test Passed\n");
+ }
/*
* client-server test, Ipv6-Ipv4
*/
- client_domain = PR_AF_INET6;
- printf("TCP Client/Server Test - IPv6/Ipv4\n");
+ client_domain = PR_AF_INET6;
+ printf("TCP Client/Server Test - IPv6/Ipv4\n");
if (TCP_Socket_Client_Server_Test() < 0) {
printf("TCP_Socket_Client_Server_Test failed\n");
goto done;
- } else
+ } else {
printf("TCP_Socket_Client_Server_Test Passed\n");
+ }
/*
* client-server test, Ipv4-Ipv6
*/
- client_domain = PR_AF_INET;
- server_domain = PR_AF_INET6;
- printf("TCP Client/Server Test - IPv4/Ipv6\n");
+ client_domain = PR_AF_INET;
+ server_domain = PR_AF_INET6;
+ printf("TCP Client/Server Test - IPv4/Ipv6\n");
if (TCP_Socket_Client_Server_Test() < 0) {
printf("TCP_Socket_Client_Server_Test failed\n");
goto done;
- } else
+ } else {
printf("TCP_Socket_Client_Server_Test Passed\n");
+ }
/*
* client-server test, Ipv6-Ipv6
*/
- client_domain = PR_AF_INET6;
- server_domain = PR_AF_INET6;
- printf("TCP Client/Server Test - IPv6/Ipv6\n");
+ client_domain = PR_AF_INET6;
+ server_domain = PR_AF_INET6;
+ printf("TCP Client/Server Test - IPv6/Ipv6\n");
if (TCP_Socket_Client_Server_Test() < 0) {
printf("TCP_Socket_Client_Server_Test failed\n");
goto done;
- } else
+ } else {
printf("TCP_Socket_Client_Server_Test Passed\n");
- test_cancelio = 0;
+ }
+ test_cancelio = 0;
/*
* Misc socket tests - including transmitfile, etc.
@@ -2232,16 +2251,17 @@ int main(int argc, char **argv)
* large file's size and the incomplete mmap() implementation. */
#if !defined(WIN16)
/*
-** The 'transmit file' test does not run because
-** transmit file is not implemented in NSPR yet.
-**
-*/
+ ** The 'transmit file' test does not run because
+ ** transmit file is not implemented in NSPR yet.
+ **
+ */
if (Socket_Misc_Test() < 0) {
printf("Socket_Misc_Test failed\n");
failed_already=1;
goto done;
- } else
+ } else {
printf("Socket_Misc_Test passed\n");
+ }
/*
* run client-server test with TCP again to test
@@ -2250,12 +2270,17 @@ int main(int argc, char **argv)
if (TCP_Socket_Client_Server_Test() < 0) {
printf("TCP_Socket_Client_Server_Test failed\n");
goto done;
- } else
+ } else {
printf("TCP_Socket_Client_Server_Test Passed\n");
+ }
#endif
done:
PR_Cleanup();
- if (failed_already) return 1;
- else return 0;
+ if (failed_already) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
}
diff --git a/pr/tests/sockopt.c b/pr/tests/sockopt.c
index 1f85d2a2..540a19b9 100644
--- a/pr/tests/sockopt.c
+++ b/pr/tests/sockopt.c
@@ -20,7 +20,9 @@ static PRBool failed = PR_FALSE;
static void Failed(const char *msg1, const char *msg2)
{
- if (NULL != msg1) PR_fprintf(err, "%s ", msg1);
+ if (NULL != msg1) {
+ PR_fprintf(err, "%s ", msg1);
+ }
PL_FPrintError(err, msg2);
failed = PR_TRUE;
} /* Failed */
@@ -65,8 +67,12 @@ int main(int argc, char **argv)
err = PR_GetSpecialFD(PR_StandardError);
PR_STDIO_INIT();
- if (NULL == udp) Failed("PR_NewUDPSocket()", NULL);
- else if (NULL == tcp) Failed("PR_NewTCPSocket()", NULL);
+ if (NULL == udp) {
+ Failed("PR_NewUDPSocket()", NULL);
+ }
+ else if (NULL == tcp) {
+ Failed("PR_NewTCPSocket()", NULL);
+ }
else
{
PRSockOption option;
@@ -74,9 +80,13 @@ int main(int argc, char **argv)
PRNetAddr addr;
rv = PR_InitializeNetAddr(PR_IpAddrAny, 0, &addr);
- if (PR_FAILURE == rv) Failed("PR_InitializeNetAddr()", NULL);
+ if (PR_FAILURE == rv) {
+ Failed("PR_InitializeNetAddr()", NULL);
+ }
rv = PR_Bind(udp, &addr);
- if (PR_FAILURE == rv) Failed("PR_Bind()", NULL);
+ if (PR_FAILURE == rv) {
+ Failed("PR_Bind()", NULL);
+ }
for(option = PR_SockOpt_Linger; option < PR_SockOpt_Last; Incr(&option))
{
PRSocketOptionData data;
@@ -137,22 +147,25 @@ int main(int argc, char **argv)
default: continue;
}
- /*
- * TCP_MAXSEG can only be read, not set
- */
+ /*
+ * TCP_MAXSEG can only be read, not set
+ */
if (option != PR_SockOpt_MaxSegment) {
#ifdef WIN32
- if (option != PR_SockOpt_McastLoopback)
+ if (option != PR_SockOpt_McastLoopback)
#endif
- {
- rv = PR_SetSocketOption(fd, &data);
- if (PR_FAILURE == rv)
- Failed("PR_SetSocketOption()", tag[option]);
- }
- }
+ {
+ rv = PR_SetSocketOption(fd, &data);
+ if (PR_FAILURE == rv) {
+ Failed("PR_SetSocketOption()", tag[option]);
+ }
+ }
+ }
rv = PR_GetSocketOption(fd, &data);
- if (PR_FAILURE == rv) Failed("PR_GetSocketOption()", tag[option]);
+ if (PR_FAILURE == rv) {
+ Failed("PR_GetSocketOption()", tag[option]);
+ }
}
PR_Close(udp);
PR_Close(tcp);
diff --git a/pr/tests/sprintf.c b/pr/tests/sprintf.c
index 014392c0..51db026d 100644
--- a/pr/tests/sprintf.c
+++ b/pr/tests/sprintf.c
@@ -4,16 +4,16 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
- * File: sprintf.c
+ * File: sprintf.c
* Description:
* This is a test program for the PR_snprintf() functions defined
* in prprf.c. This test program is based on ns/nspr/tests/sprintf.c,
* revision 1.10.
* Modification History:
- * 20-May-1997 AGarcia replaced printf statment to return PASS\n. This is to be used by the
- * regress tool parsing routine.
+ * 20-May-1997 AGarcia replaced printf statment to return PASS\n. This is to be used by the
+ * regress tool parsing routine.
** 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.
*/
#include "prinit.h"
@@ -46,60 +46,66 @@ static void test_i(char *pattern, int i)
/* compare results */
if ((strncmp(s, buf, sizeof(buf)) != 0) ||
- (strncmp(s, sbuf, sizeof(sbuf)) != 0)) {
- fprintf(stderr,
- "pattern='%s' i=%d\nPR_smprintf='%s'\nPR_snprintf='%s'\n sprintf='%s'\n",
- pattern, i, s, buf, sbuf);
- PR_smprintf_free(s);
- exit(-1);
+ (strncmp(s, sbuf, sizeof(sbuf)) != 0)) {
+ fprintf(stderr,
+ "pattern='%s' i=%d\nPR_smprintf='%s'\nPR_snprintf='%s'\n sprintf='%s'\n",
+ pattern, i, s, buf, sbuf);
+ PR_smprintf_free(s);
+ exit(-1);
}
- PR_smprintf_free(s);
+ PR_smprintf_free(s);
}
static void TestI(void)
{
static int nums[] = {
- 0, 1, -1, 10, -10,
- 32767, -32768,
+ 0, 1, -1, 10, -10,
+ 32767, -32768,
};
static char *signs[] = {
- "",
- "0", "-", "+", " ",
- "0-", "0+", "0 ", "-0", "-+", "- ",
- "+0", "+-", "+ ", " 0", " -", " +",
- "0-+", "0- ", "0+-", "0+ ", "0 -", "0 +",
- "-0+", "-0 ", "-+0", "-+ ", "- 0", "- +",
- "+0-", "+0 ", "+-0", "+- ", "+ 0", "+ -",
- " 0-", " 0+", " -0", " -+", " +0", " +-",
- "0-+ ", "0- +", "0+- ", "0+ -", "0 -+", "0 +-",
- "-0+ ", "-0 +", "-+0 ", "-+ 0", "- 0+", "- +0",
- "+0- ", "+0 -", "+-0 ", "+- 0", "+ 0-", "+ -0",
- " 0-+", " 0+-", " -0+", " -+0", " +0-", " +-0",
+ "",
+ "0", "-", "+", " ",
+ "0-", "0+", "0 ", "-0", "-+", "- ",
+ "+0", "+-", "+ ", " 0", " -", " +",
+ "0-+", "0- ", "0+-", "0+ ", "0 -", "0 +",
+ "-0+", "-0 ", "-+0", "-+ ", "- 0", "- +",
+ "+0-", "+0 ", "+-0", "+- ", "+ 0", "+ -",
+ " 0-", " 0+", " -0", " -+", " +0", " +-",
+ "0-+ ", "0- +", "0+- ", "0+ -", "0 -+", "0 +-",
+ "-0+ ", "-0 +", "-+0 ", "-+ 0", "- 0+", "- +0",
+ "+0- ", "+0 -", "+-0 ", "+- 0", "+ 0-", "+ -0",
+ " 0-+", " 0+-", " -0+", " -+0", " +0-", " +-0",
};
static char *precs[] = {
- "", "3", "5", "43",
- "7.3", "7.5", "7.11", "7.43",
+ "", "3", "5", "43",
+ "7.3", "7.5", "7.11", "7.43",
};
static char *formats[] = {
- "d", "o", "x", "u",
- "hd", "ho", "hx", "hu"
+ "d", "o", "x", "u",
+ "hd", "ho", "hx", "hu"
};
int f, s, n, p;
char fmt[20];
for (f = 0; f < PR_ARRAY_SIZE(formats); f++) {
- for (s = 0; s < PR_ARRAY_SIZE(signs); s++) {
- for (p = 0; p < PR_ARRAY_SIZE(precs); p++) {
- fmt[0] = '%';
- fmt[1] = 0;
- if (signs[s]) strcat(fmt, signs[s]);
- if (precs[p]) strcat(fmt, precs[p]);
- if (formats[f]) strcat(fmt, formats[f]);
- for (n = 0; n < PR_ARRAY_SIZE(nums); n++) {
- test_i(fmt, nums[n]);
- }
- }
- }
+ for (s = 0; s < PR_ARRAY_SIZE(signs); s++) {
+ for (p = 0; p < PR_ARRAY_SIZE(precs); p++) {
+ fmt[0] = '%';
+ fmt[1] = 0;
+ if (signs[s]) {
+ strcat(fmt, signs[s]);
+ }
+ if (precs[p]) {
+ strcat(fmt, precs[p]);
+ }
+ if (formats[f]) {
+ strcat(fmt, formats[f]);
+ }
+ for (n = 0; n < PR_ARRAY_SIZE(nums); n++) {
+ test_i(fmt, nums[n]);
+ }
+ }
+ }
}
}
@@ -124,47 +130,47 @@ static void test_l(char *pattern, char *spattern, PRInt32 l)
/* compare results */
if ((strncmp(s, buf, sizeof(buf)) != 0) ||
- (strncmp(s, sbuf, sizeof(sbuf)) != 0)) {
- fprintf(stderr,
- "pattern='%s' l=%ld\nPR_smprintf='%s'\nPR_snprintf='%s'\n sprintf='%s'\n",
- pattern, l, s, buf, sbuf);
- PR_smprintf_free(s);
- exit(-1);
+ (strncmp(s, sbuf, sizeof(sbuf)) != 0)) {
+ fprintf(stderr,
+ "pattern='%s' l=%ld\nPR_smprintf='%s'\nPR_snprintf='%s'\n sprintf='%s'\n",
+ pattern, l, s, buf, sbuf);
+ PR_smprintf_free(s);
+ exit(-1);
}
- PR_smprintf_free(s);
+ PR_smprintf_free(s);
}
static void TestL(void)
{
static PRInt32 nums[] = {
- 0,
- 1,
- -1,
- 10,
- -10,
- 32767,
- -32768,
- PR_INT32(0x7fffffff), /* 2147483647L */
- -1 - PR_INT32(0x7fffffff) /* -2147483648L */
+ 0,
+ 1,
+ -1,
+ 10,
+ -10,
+ 32767,
+ -32768,
+ PR_INT32(0x7fffffff), /* 2147483647L */
+ -1 - PR_INT32(0x7fffffff) /* -2147483648L */
};
static char *signs[] = {
- "",
- "0", "-", "+", " ",
- "0-", "0+", "0 ", "-0", "-+", "- ",
- "+0", "+-", "+ ", " 0", " -", " +",
- "0-+", "0- ", "0+-", "0+ ", "0 -", "0 +",
- "-0+", "-0 ", "-+0", "-+ ", "- 0", "- +",
- "+0-", "+0 ", "+-0", "+- ", "+ 0", "+ -",
- " 0-", " 0+", " -0", " -+", " +0", " +-",
- "0-+ ", "0- +", "0+- ", "0+ -", "0 -+", "0 +-",
- "-0+ ", "-0 +", "-+0 ", "-+ 0", "- 0+", "- +0",
- "+0- ", "+0 -", "+-0 ", "+- 0", "+ 0-", "+ -0",
- " 0-+", " 0+-", " -0+", " -+0", " +0-", " +-0",
+ "",
+ "0", "-", "+", " ",
+ "0-", "0+", "0 ", "-0", "-+", "- ",
+ "+0", "+-", "+ ", " 0", " -", " +",
+ "0-+", "0- ", "0+-", "0+ ", "0 -", "0 +",
+ "-0+", "-0 ", "-+0", "-+ ", "- 0", "- +",
+ "+0-", "+0 ", "+-0", "+- ", "+ 0", "+ -",
+ " 0-", " 0+", " -0", " -+", " +0", " +-",
+ "0-+ ", "0- +", "0+- ", "0+ -", "0 -+", "0 +-",
+ "-0+ ", "-0 +", "-+0 ", "-+ 0", "- 0+", "- +0",
+ "+0- ", "+0 -", "+-0 ", "+- 0", "+ 0-", "+ -0",
+ " 0-+", " 0+-", " -0+", " -+0", " +0-", " +-0",
};
static char *precs[] = {
- "", "3", "5", "43",
- ".3", ".43",
- "7.3", "7.5", "7.11", "7.43",
+ "", "3", "5", "43",
+ ".3", ".43",
+ "7.3", "7.5", "7.11", "7.43",
};
static char *formats[] = { "ld", "lo", "lx", "lu" };
@@ -180,20 +186,28 @@ static void TestL(void)
char fmt[40], sfmt[40];
for (f = 0; f < PR_ARRAY_SIZE(formats); f++) {
- for (s = 0; s < PR_ARRAY_SIZE(signs); s++) {
- for (p = 0; p < PR_ARRAY_SIZE(precs); p++) {
- fmt[0] = '%';
- fmt[1] = 0;
- if (signs[s]) strcat(fmt, signs[s]);
- if (precs[p]) strcat(fmt, precs[p]);
- strcpy(sfmt, fmt);
- if (formats[f]) strcat(fmt, formats[f]);
- if (sformats[f]) strcat(sfmt, sformats[f]);
- for (n = 0; n < PR_ARRAY_SIZE(nums); n++) {
- test_l(fmt, sfmt, nums[n]);
- }
- }
- }
+ for (s = 0; s < PR_ARRAY_SIZE(signs); s++) {
+ for (p = 0; p < PR_ARRAY_SIZE(precs); p++) {
+ fmt[0] = '%';
+ fmt[1] = 0;
+ if (signs[s]) {
+ strcat(fmt, signs[s]);
+ }
+ if (precs[p]) {
+ strcat(fmt, precs[p]);
+ }
+ strcpy(sfmt, fmt);
+ if (formats[f]) {
+ strcat(fmt, formats[f]);
+ }
+ if (sformats[f]) {
+ strcat(sfmt, sformats[f]);
+ }
+ for (n = 0; n < PR_ARRAY_SIZE(nums); n++) {
+ test_l(fmt, sfmt, nums[n]);
+ }
+ }
+ }
}
}
@@ -219,7 +233,7 @@ static void test_ll(char *pattern, char *spattern, PRInt64 l)
/* compare results */
if ((strncmp(s, buf, sizeof(buf)) != 0) ||
- (strncmp(s, sbuf, sizeof(sbuf)) != 0)) {
+ (strncmp(s, sbuf, sizeof(sbuf)) != 0)) {
#if PR_BYTES_PER_LONG == 8
#define FORMAT_SPEC "%ld"
#elif defined(WIN16)
@@ -229,73 +243,73 @@ static void test_ll(char *pattern, char *spattern, PRInt64 l)
#else
#define FORMAT_SPEC "%lld"
#endif
- fprintf(stderr,
- "pattern='%s' ll=" FORMAT_SPEC "\nPR_smprintf='%s'\nPR_snprintf='%s'\n sprintf='%s'\n",
- pattern, l, s, buf, sbuf);
- printf("FAIL\n");
- PR_smprintf_free(s);
- exit(-1);
+ fprintf(stderr,
+ "pattern='%s' ll=" FORMAT_SPEC "\nPR_smprintf='%s'\nPR_snprintf='%s'\n sprintf='%s'\n",
+ pattern, l, s, buf, sbuf);
+ printf("FAIL\n");
+ PR_smprintf_free(s);
+ exit(-1);
}
- PR_smprintf_free(s);
+ PR_smprintf_free(s);
#else
/* compare results */
if ((strncmp(s, buf, sizeof(buf)) != 0)) {
- fprintf(stderr,
- "pattern='%s'\nPR_smprintf='%s'\nPR_snprintf='%s'\n sprintf='%s'\n",
- pattern, s, buf, sbuf);
- printf("FAIL\n");
- PR_smprintf_free(s);
+ fprintf(stderr,
+ "pattern='%s'\nPR_smprintf='%s'\nPR_snprintf='%s'\n sprintf='%s'\n",
+ pattern, s, buf, sbuf);
+ printf("FAIL\n");
+ PR_smprintf_free(s);
exit(-1);
}
- PR_smprintf_free(s);
+ PR_smprintf_free(s);
#endif
}
static void TestLL(void)
{
static PRInt64 nums[] = {
- LL_INIT(0, 0),
- LL_INIT(0, 1),
- LL_INIT(0xffffffff, 0xffffffff), /* -1 */
- LL_INIT(0, 10),
- LL_INIT(0xffffffff, 0xfffffff6), /* -10 */
- LL_INIT(0, 32767),
- LL_INIT(0xffffffff, 0xffff8000), /* -32768 */
- LL_INIT(0, 0x7fffffff), /* 2147483647 */
- LL_INIT(0xffffffff, 0x80000000), /* -2147483648 */
- LL_INIT(0x7fffffff, 0xffffffff), /* 9223372036854775807 */
- LL_INIT(0x80000000, 0), /* -9223372036854775808 */
- PR_INT64(0),
- PR_INT64(1),
- PR_INT64(-1),
- PR_INT64(10),
- PR_INT64(-10),
- PR_INT64(32767),
- PR_INT64(-32768),
- PR_INT64(2147483647),
- PR_INT64(-2147483648),
- PR_INT64(9223372036854775807),
- PR_INT64(-9223372036854775808)
+ LL_INIT(0, 0),
+ LL_INIT(0, 1),
+ LL_INIT(0xffffffff, 0xffffffff), /* -1 */
+ LL_INIT(0, 10),
+ LL_INIT(0xffffffff, 0xfffffff6), /* -10 */
+ LL_INIT(0, 32767),
+ LL_INIT(0xffffffff, 0xffff8000), /* -32768 */
+ LL_INIT(0, 0x7fffffff), /* 2147483647 */
+ LL_INIT(0xffffffff, 0x80000000), /* -2147483648 */
+ LL_INIT(0x7fffffff, 0xffffffff), /* 9223372036854775807 */
+ LL_INIT(0x80000000, 0), /* -9223372036854775808 */
+ PR_INT64(0),
+ PR_INT64(1),
+ PR_INT64(-1),
+ PR_INT64(10),
+ PR_INT64(-10),
+ PR_INT64(32767),
+ PR_INT64(-32768),
+ PR_INT64(2147483647),
+ PR_INT64(-2147483648),
+ PR_INT64(9223372036854775807),
+ PR_INT64(-9223372036854775808)
};
static char *signs[] = {
- "",
- "0", "-", "+", " ",
- "0-", "0+", "0 ", "-0", "-+", "- ",
- "+0", "+-", "+ ", " 0", " -", " +",
- "0-+", "0- ", "0+-", "0+ ", "0 -", "0 +",
- "-0+", "-0 ", "-+0", "-+ ", "- 0", "- +",
- "+0-", "+0 ", "+-0", "+- ", "+ 0", "+ -",
- " 0-", " 0+", " -0", " -+", " +0", " +-",
- "0-+ ", "0- +", "0+- ", "0+ -", "0 -+", "0 +-",
- "-0+ ", "-0 +", "-+0 ", "-+ 0", "- 0+", "- +0",
- "+0- ", "+0 -", "+-0 ", "+- 0", "+ 0-", "+ -0",
- " 0-+", " 0+-", " -0+", " -+0", " +0-", " +-0",
+ "",
+ "0", "-", "+", " ",
+ "0-", "0+", "0 ", "-0", "-+", "- ",
+ "+0", "+-", "+ ", " 0", " -", " +",
+ "0-+", "0- ", "0+-", "0+ ", "0 -", "0 +",
+ "-0+", "-0 ", "-+0", "-+ ", "- 0", "- +",
+ "+0-", "+0 ", "+-0", "+- ", "+ 0", "+ -",
+ " 0-", " 0+", " -0", " -+", " +0", " +-",
+ "0-+ ", "0- +", "0+- ", "0+ -", "0 -+", "0 +-",
+ "-0+ ", "-0 +", "-+0 ", "-+ 0", "- 0+", "- +0",
+ "+0- ", "+0 -", "+-0 ", "+- 0", "+ 0-", "+ -0",
+ " 0-+", " 0+-", " -0+", " -+0", " +0-", " +-0",
};
static char *precs[] = {
- "", "3", "5", "43",
- ".3", ".43",
- "7.3", "7.5", "7.11", "7.43",
+ "", "3", "5", "43",
+ ".3", ".43",
+ "7.3", "7.5", "7.11", "7.43",
};
static char *formats[] = { "lld", "llo", "llx", "llu" };
@@ -314,20 +328,28 @@ static void TestLL(void)
char fmt[40], sfmt[40];
for (f = 0; f < PR_ARRAY_SIZE(formats); f++) {
- for (s = 0; s < PR_ARRAY_SIZE(signs); s++) {
- for (p = 0; p < PR_ARRAY_SIZE(precs); p++) {
- fmt[0] = '%';
- fmt[1] = 0;
- if (signs[s]) strcat(fmt, signs[s]);
- if (precs[p]) strcat(fmt, precs[p]);
- strcpy(sfmt, fmt);
- if (formats[f]) strcat(fmt, formats[f]);
- if (sformats[f]) strcat(sfmt, sformats[f]);
- for (n = 0; n < PR_ARRAY_SIZE(nums); n++) {
- test_ll(fmt, sfmt, nums[n]);
- }
- }
- }
+ for (s = 0; s < PR_ARRAY_SIZE(signs); s++) {
+ for (p = 0; p < PR_ARRAY_SIZE(precs); p++) {
+ fmt[0] = '%';
+ fmt[1] = 0;
+ if (signs[s]) {
+ strcat(fmt, signs[s]);
+ }
+ if (precs[p]) {
+ strcat(fmt, precs[p]);
+ }
+ strcpy(sfmt, fmt);
+ if (formats[f]) {
+ strcat(fmt, formats[f]);
+ }
+ if (sformats[f]) {
+ strcat(sfmt, sformats[f]);
+ }
+ for (n = 0; n < PR_ARRAY_SIZE(nums); n++) {
+ test_ll(fmt, sfmt, nums[n]);
+ }
+ }
+ }
}
}
@@ -356,64 +378,70 @@ static void test_s(char *pattern, char *ss)
sprintf(sbuf, pattern, ss);
for (n = 0; n < 8; n++) {
- PR_ASSERT(before[n] == 0xBB);
- PR_ASSERT(after[n] == 0xAA);
+ PR_ASSERT(before[n] == 0xBB);
+ PR_ASSERT(after[n] == 0xAA);
}
/* compare results */
if ((strncmp(s, buf, sizeof(buf)) != 0) ||
- (strncmp(s, sbuf, sizeof(sbuf)) != 0)) {
- fprintf(stderr,
- "pattern='%s' ss=%.20s\nPR_smprintf='%s'\nPR_snprintf='%s'\n sprintf='%s'\n",
- pattern, ss, s, buf, sbuf);
- printf("FAIL\n");
- PR_smprintf_free(s);
- exit(-1);
+ (strncmp(s, sbuf, sizeof(sbuf)) != 0)) {
+ fprintf(stderr,
+ "pattern='%s' ss=%.20s\nPR_smprintf='%s'\nPR_snprintf='%s'\n sprintf='%s'\n",
+ pattern, ss, s, buf, sbuf);
+ printf("FAIL\n");
+ PR_smprintf_free(s);
+ exit(-1);
}
- PR_smprintf_free(s);
+ PR_smprintf_free(s);
}
static void TestS(void)
{
static char *strs[] = {
- "",
- "a",
- "abc",
- "abcde",
- "abcdefABCDEF",
- "abcdefghijklmnopqrstuvwxyz0123456789!@#$"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$"
- "abcdefghijklmnopqrstuvwxyz0123456789!@#$",
+ "",
+ "a",
+ "abc",
+ "abcde",
+ "abcdefABCDEF",
+ "abcdefghijklmnopqrstuvwxyz0123456789!@#$"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$"
+ "abcdefghijklmnopqrstuvwxyz0123456789!@#$",
};
/* '0' is not relevant to printing strings */
static char *signs[] = {
- "",
- "-", "+", " ",
- "-+", "- ", "+-", "+ ", " -", " +",
- "-+ ", "- +", "+- ", "+ -", " -+", " +-",
+ "",
+ "-", "+", " ",
+ "-+", "- ", "+-", "+ ", " -", " +",
+ "-+ ", "- +", "+- ", "+ -", " -+", " +-",
};
static char *precs[] = {
- "", "3", "5", "43",
- ".3", ".43",
- "7.3", "7.5", "7.11", "7.43",
+ "", "3", "5", "43",
+ ".3", ".43",
+ "7.3", "7.5", "7.11", "7.43",
};
static char *formats[] = { "s" };
int f, s, n, p;
char fmt[40];
for (f = 0; f < PR_ARRAY_SIZE(formats); f++) {
- for (s = 0; s < PR_ARRAY_SIZE(signs); s++) {
- for (p = 0; p < PR_ARRAY_SIZE(precs); p++) {
- fmt[0] = '%';
- fmt[1] = 0;
- if (signs[s]) strcat(fmt+strlen(fmt), signs[s]);
- if (precs[p]) strcat(fmt+strlen(fmt), precs[p]);
- if (formats[f]) strcat(fmt+strlen(fmt), formats[f]);
- for (n = 0; n < PR_ARRAY_SIZE(strs); n++) {
- test_s(fmt, strs[n]);
- }
- }
- }
+ for (s = 0; s < PR_ARRAY_SIZE(signs); s++) {
+ for (p = 0; p < PR_ARRAY_SIZE(precs); p++) {
+ fmt[0] = '%';
+ fmt[1] = 0;
+ if (signs[s]) {
+ strcat(fmt+strlen(fmt), signs[s]);
+ }
+ if (precs[p]) {
+ strcat(fmt+strlen(fmt), precs[p]);
+ }
+ if (formats[f]) {
+ strcat(fmt+strlen(fmt), formats[f]);
+ }
+ for (n = 0; n < PR_ARRAY_SIZE(strs); n++) {
+ test_s(fmt, strs[n]);
+ }
+ }
+ }
}
}
diff --git a/pr/tests/stack.c b/pr/tests/stack.c
index 8da1894e..5526a274 100644
--- a/pr/tests/stack.c
+++ b/pr/tests/stack.c
@@ -8,28 +8,28 @@
*
* Test atomic stack operations
*
- * Two stacks are created and threads add data items (each containing
- * one of the first n integers) to the first stack, remove data items
- * from the first stack and add them to the second stack. The primordial
- * thread compares the sum of the first n integers to the sum of the
- * integers in the data items in the second stack. The test succeeds if
- * they are equal.
+ * Two stacks are created and threads add data items (each containing
+ * one of the first n integers) to the first stack, remove data items
+ * from the first stack and add them to the second stack. The primordial
+ * thread compares the sum of the first n integers to the sum of the
+ * integers in the data items in the second stack. The test succeeds if
+ * they are equal.
*/
#include "nspr.h"
#include "plgetopt.h"
typedef struct _DataRecord {
- PRInt32 data;
- PRStackElem link;
+ PRInt32 data;
+ PRStackElem link;
} DataRecord;
#define RECORD_LINK_PTR(lp) ((DataRecord*) ((char*) (lp) - offsetof(DataRecord,link)))
-#define MAX_THREAD_CNT 100
-#define DEFAULT_THREAD_CNT 4
-#define DEFAULT_DATA_CNT 100
-#define DEFAULT_LOOP_CNT 10000
+#define MAX_THREAD_CNT 100
+#define DEFAULT_THREAD_CNT 4
+#define DEFAULT_DATA_CNT 100
+#define DEFAULT_LOOP_CNT 10000
/*
* sum of the first n numbers using the formula n*(n+1)/2
@@ -37,11 +37,11 @@ typedef struct _DataRecord {
#define SUM_OF_NUMBERS(n) ((n & 1) ? (((n + 1)/2) * n) : ((n/2) * (n+1)))
typedef struct stack_data {
- PRStack *list1;
- PRStack *list2;
- PRInt32 initial_data_value;
- PRInt32 data_cnt;
- PRInt32 loops;
+ PRStack *list1;
+ PRStack *list2;
+ PRInt32 initial_data_value;
+ PRInt32 data_cnt;
+ PRInt32 loops;
} stack_data;
static void stackop(void *arg);
@@ -54,225 +54,229 @@ PRFileDesc *errhandle;
int main(int argc, char **argv)
{
PRInt32 rv, cnt, sum;
- DataRecord *Item;
- PRStack *list1, *list2;
- PRStackElem *node;
- PRStatus rc;
+ DataRecord *Item;
+ PRStack *list1, *list2;
+ PRStackElem *node;
+ PRStatus rc;
- PRInt32 thread_cnt = DEFAULT_THREAD_CNT;
- PRInt32 data_cnt = DEFAULT_DATA_CNT;
- PRInt32 loops = DEFAULT_LOOP_CNT;
- PRThread **threads;
- stack_data *thread_args;
+ PRInt32 thread_cnt = DEFAULT_THREAD_CNT;
+ PRInt32 data_cnt = DEFAULT_DATA_CNT;
+ PRInt32 loops = DEFAULT_LOOP_CNT;
+ PRThread **threads;
+ stack_data *thread_args;
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "dt:c:l:");
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "dt:c:l:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ 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_on = 1;
- break;
- case 't': /* thread count */
- thread_cnt = atoi(opt->value);
- break;
- case 'c': /* data count */
- data_cnt = atoi(opt->value);
- break;
- case 'l': /* loop count */
- loops = atoi(opt->value);
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ _debug_on = 1;
+ break;
+ case 't': /* thread count */
+ thread_cnt = atoi(opt->value);
+ break;
+ case 'c': /* data count */
+ data_cnt = atoi(opt->value);
+ break;
+ case 'l': /* loop count */
+ loops = atoi(opt->value);
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- PR_SetConcurrency(4);
+ PR_SetConcurrency(4);
output = PR_GetSpecialFD(PR_StandardOutput);
errhandle = PR_GetSpecialFD(PR_StandardError);
- list1 = PR_CreateStack("Stack_1");
- if (list1 == NULL) {
- PR_fprintf(errhandle, "PR_CreateStack failed - error %d\n",
- PR_GetError());
- return 1;
- }
-
- list2 = PR_CreateStack("Stack_2");
- if (list2 == NULL) {
- PR_fprintf(errhandle, "PR_CreateStack failed - error %d\n",
- PR_GetError());
- return 1;
- }
-
-
- threads = (PRThread**) PR_CALLOC(sizeof(PRThread*) * thread_cnt);
- thread_args = (stack_data *) PR_CALLOC(sizeof(stack_data) * thread_cnt);
-
- if (_debug_on)
- PR_fprintf(output,"%s: thread_cnt = %d data_cnt = %d\n", argv[0],
- thread_cnt, data_cnt);
- for(cnt = 0; cnt < thread_cnt; cnt++) {
- PRThreadScope scope;
-
- thread_args[cnt].list1 = list1;
- thread_args[cnt].list2 = list2;
- thread_args[cnt].loops = loops;
- thread_args[cnt].data_cnt = data_cnt;
- thread_args[cnt].initial_data_value = 1 + cnt * data_cnt;
-
- if (cnt & 1)
- scope = PR_GLOBAL_THREAD;
- else
- scope = PR_LOCAL_THREAD;
-
-
- threads[cnt] = PR_CreateThread(PR_USER_THREAD,
- stackop, &thread_args[cnt],
- PR_PRIORITY_NORMAL,
- scope,
- PR_JOINABLE_THREAD,
- 0);
- if (threads[cnt] == NULL) {
- PR_fprintf(errhandle, "PR_CreateThread failed - error %d\n",
- PR_GetError());
- PR_ProcessExit(2);
- }
- if (_debug_on)
- PR_fprintf(output,"%s: created thread = 0x%x\n", argv[0],
- threads[cnt]);
- }
-
- for(cnt = 0; cnt < thread_cnt; cnt++) {
- rc = PR_JoinThread(threads[cnt]);
- PR_ASSERT(rc == PR_SUCCESS);
- }
-
- node = PR_StackPop(list1);
- /*
- * list1 should be empty
- */
- if (node != NULL) {
- PR_fprintf(errhandle, "Error - Stack 1 not empty\n");
- PR_ASSERT(node == NULL);
- PR_ProcessExit(4);
- }
-
- cnt = data_cnt * thread_cnt;
- sum = 0;
- while (cnt-- > 0) {
- node = PR_StackPop(list2);
- /*
- * There should be at least 'cnt' number of records
- */
- if (node == NULL) {
- PR_fprintf(errhandle, "Error - PR_StackPop returned NULL\n");
- PR_ProcessExit(3);
- }
- Item = RECORD_LINK_PTR(node);
- sum += Item->data;
- }
- node = PR_StackPop(list2);
- /*
- * there should be exactly 'cnt' number of records
- */
- if (node != NULL) {
- PR_fprintf(errhandle, "Error - Stack 2 not empty\n");
- PR_ASSERT(node == NULL);
- PR_ProcessExit(4);
- }
- PR_DELETE(threads);
- PR_DELETE(thread_args);
-
- PR_DestroyStack(list1);
- PR_DestroyStack(list2);
-
- if (sum == SUM_OF_NUMBERS(data_cnt * thread_cnt)) {
- PR_fprintf(output, "%s successful\n", argv[0]);
- PR_fprintf(output, "\t\tsum = 0x%x, expected = 0x%x\n", sum,
- SUM_OF_NUMBERS(thread_cnt * data_cnt));
- return 0;
- } else {
- PR_fprintf(output, "%s failed: sum = 0x%x, expected = 0x%x\n",
- argv[0], sum,
- SUM_OF_NUMBERS(data_cnt * thread_cnt));
- return 2;
- }
+ list1 = PR_CreateStack("Stack_1");
+ if (list1 == NULL) {
+ PR_fprintf(errhandle, "PR_CreateStack failed - error %d\n",
+ PR_GetError());
+ return 1;
+ }
+
+ list2 = PR_CreateStack("Stack_2");
+ if (list2 == NULL) {
+ PR_fprintf(errhandle, "PR_CreateStack failed - error %d\n",
+ PR_GetError());
+ return 1;
+ }
+
+
+ threads = (PRThread**) PR_CALLOC(sizeof(PRThread*) * thread_cnt);
+ thread_args = (stack_data *) PR_CALLOC(sizeof(stack_data) * thread_cnt);
+
+ if (_debug_on)
+ PR_fprintf(output,"%s: thread_cnt = %d data_cnt = %d\n", argv[0],
+ thread_cnt, data_cnt);
+ for(cnt = 0; cnt < thread_cnt; cnt++) {
+ PRThreadScope scope;
+
+ thread_args[cnt].list1 = list1;
+ thread_args[cnt].list2 = list2;
+ thread_args[cnt].loops = loops;
+ thread_args[cnt].data_cnt = data_cnt;
+ thread_args[cnt].initial_data_value = 1 + cnt * data_cnt;
+
+ if (cnt & 1) {
+ scope = PR_GLOBAL_THREAD;
+ }
+ else {
+ scope = PR_LOCAL_THREAD;
+ }
+
+
+ threads[cnt] = PR_CreateThread(PR_USER_THREAD,
+ stackop, &thread_args[cnt],
+ PR_PRIORITY_NORMAL,
+ scope,
+ PR_JOINABLE_THREAD,
+ 0);
+ if (threads[cnt] == NULL) {
+ PR_fprintf(errhandle, "PR_CreateThread failed - error %d\n",
+ PR_GetError());
+ PR_ProcessExit(2);
+ }
+ if (_debug_on)
+ PR_fprintf(output,"%s: created thread = 0x%x\n", argv[0],
+ threads[cnt]);
+ }
+
+ for(cnt = 0; cnt < thread_cnt; cnt++) {
+ rc = PR_JoinThread(threads[cnt]);
+ PR_ASSERT(rc == PR_SUCCESS);
+ }
+
+ node = PR_StackPop(list1);
+ /*
+ * list1 should be empty
+ */
+ if (node != NULL) {
+ PR_fprintf(errhandle, "Error - Stack 1 not empty\n");
+ PR_ASSERT(node == NULL);
+ PR_ProcessExit(4);
+ }
+
+ cnt = data_cnt * thread_cnt;
+ sum = 0;
+ while (cnt-- > 0) {
+ node = PR_StackPop(list2);
+ /*
+ * There should be at least 'cnt' number of records
+ */
+ if (node == NULL) {
+ PR_fprintf(errhandle, "Error - PR_StackPop returned NULL\n");
+ PR_ProcessExit(3);
+ }
+ Item = RECORD_LINK_PTR(node);
+ sum += Item->data;
+ }
+ node = PR_StackPop(list2);
+ /*
+ * there should be exactly 'cnt' number of records
+ */
+ if (node != NULL) {
+ PR_fprintf(errhandle, "Error - Stack 2 not empty\n");
+ PR_ASSERT(node == NULL);
+ PR_ProcessExit(4);
+ }
+ PR_DELETE(threads);
+ PR_DELETE(thread_args);
+
+ PR_DestroyStack(list1);
+ PR_DestroyStack(list2);
+
+ if (sum == SUM_OF_NUMBERS(data_cnt * thread_cnt)) {
+ PR_fprintf(output, "%s successful\n", argv[0]);
+ PR_fprintf(output, "\t\tsum = 0x%x, expected = 0x%x\n", sum,
+ SUM_OF_NUMBERS(thread_cnt * data_cnt));
+ return 0;
+ } else {
+ PR_fprintf(output, "%s failed: sum = 0x%x, expected = 0x%x\n",
+ argv[0], sum,
+ SUM_OF_NUMBERS(data_cnt * thread_cnt));
+ return 2;
+ }
}
static void stackop(void *thread_arg)
{
PRInt32 val, cnt, index, loops;
- DataRecord *Items, *Item;
- PRStack *list1, *list2;
- PRStackElem *node;
- stack_data *arg = (stack_data *) thread_arg;
-
- val = arg->initial_data_value;
- cnt = arg->data_cnt;
- loops = arg->loops;
- list1 = arg->list1;
- list2 = arg->list2;
-
- /*
- * allocate memory for the data records
- */
- Items = (DataRecord *) PR_CALLOC(sizeof(DataRecord) * cnt);
- PR_ASSERT(Items != NULL);
- index = 0;
-
- if (_debug_on)
- PR_fprintf(output,
- "Thread[0x%x] init_val = %d cnt = %d data1 = 0x%x datan = 0x%x\n",
- PR_GetCurrentThread(), val, cnt, &Items[0], &Items[cnt-1]);
-
-
- /*
- * add the data records to list1
- */
- while (cnt-- > 0) {
- Items[index].data = val++;
- PR_StackPush(list1, &Items[index].link);
- index++;
- }
-
- /*
- * pop data records from list1 and add them back to list1
- * generates contention for the stack accesses
- */
- while (loops-- > 0) {
- cnt = arg->data_cnt;
- while (cnt-- > 0) {
- node = PR_StackPop(list1);
- if (node == NULL) {
- PR_fprintf(errhandle, "Error - PR_StackPop returned NULL\n");
- PR_ASSERT(node != NULL);
- PR_ProcessExit(3);
- }
- PR_StackPush(list1, node);
- }
- }
- /*
- * remove the data records from list1 and add them to list2
- */
- cnt = arg->data_cnt;
- while (cnt-- > 0) {
- node = PR_StackPop(list1);
- if (node == NULL) {
- PR_fprintf(errhandle, "Error - PR_StackPop returned NULL\n");
- PR_ASSERT(node != NULL);
- PR_ProcessExit(3);
- }
- PR_StackPush(list2, node);
- }
- if (_debug_on)
- PR_fprintf(output,
- "Thread[0x%x] init_val = %d cnt = %d exiting\n",
- PR_GetCurrentThread(), val, cnt);
+ DataRecord *Items, *Item;
+ PRStack *list1, *list2;
+ PRStackElem *node;
+ stack_data *arg = (stack_data *) thread_arg;
+
+ val = arg->initial_data_value;
+ cnt = arg->data_cnt;
+ loops = arg->loops;
+ list1 = arg->list1;
+ list2 = arg->list2;
+
+ /*
+ * allocate memory for the data records
+ */
+ Items = (DataRecord *) PR_CALLOC(sizeof(DataRecord) * cnt);
+ PR_ASSERT(Items != NULL);
+ index = 0;
+
+ if (_debug_on)
+ PR_fprintf(output,
+ "Thread[0x%x] init_val = %d cnt = %d data1 = 0x%x datan = 0x%x\n",
+ PR_GetCurrentThread(), val, cnt, &Items[0], &Items[cnt-1]);
+
+
+ /*
+ * add the data records to list1
+ */
+ while (cnt-- > 0) {
+ Items[index].data = val++;
+ PR_StackPush(list1, &Items[index].link);
+ index++;
+ }
+
+ /*
+ * pop data records from list1 and add them back to list1
+ * generates contention for the stack accesses
+ */
+ while (loops-- > 0) {
+ cnt = arg->data_cnt;
+ while (cnt-- > 0) {
+ node = PR_StackPop(list1);
+ if (node == NULL) {
+ PR_fprintf(errhandle, "Error - PR_StackPop returned NULL\n");
+ PR_ASSERT(node != NULL);
+ PR_ProcessExit(3);
+ }
+ PR_StackPush(list1, node);
+ }
+ }
+ /*
+ * remove the data records from list1 and add them to list2
+ */
+ cnt = arg->data_cnt;
+ while (cnt-- > 0) {
+ node = PR_StackPop(list1);
+ if (node == NULL) {
+ PR_fprintf(errhandle, "Error - PR_StackPop returned NULL\n");
+ PR_ASSERT(node != NULL);
+ PR_ProcessExit(3);
+ }
+ PR_StackPush(list2, node);
+ }
+ if (_debug_on)
+ PR_fprintf(output,
+ "Thread[0x%x] init_val = %d cnt = %d exiting\n",
+ PR_GetCurrentThread(), val, cnt);
}
diff --git a/pr/tests/stat.c b/pr/tests/stat.c
index c3c869f2..1f870a0d 100644
--- a/pr/tests/stat.c
+++ b/pr/tests/stat.c
@@ -36,8 +36,8 @@ static void statPRStat(void)
PRFileInfo finfo;
PRInt32 index = count;
- for (;index--;) {
- PR_GetFileInfo(filename, &finfo);
+ for (; index--;) {
+ PR_GetFileInfo(filename, &finfo);
}
}
@@ -46,7 +46,7 @@ static void statStat(void)
struct stat finfo;
PRInt32 index = count;
- for (;index--;) {
+ for (; index--;) {
stat(filename, &finfo);
}
}
@@ -75,9 +75,9 @@ int main(int argc, char **argv)
PR_STDIO_INIT();
if (argc > 1) {
- count = atoi(argv[1]);
+ count = atoi(argv[1]);
} else {
- count = DEFAULT_COUNT;
+ count = DEFAULT_COUNT;
}
Measure(statPRStat, "time to call PR_GetFileInfo()");
diff --git a/pr/tests/stdio.c b/pr/tests/stdio.c
index 8e2b8560..d8a12389 100644
--- a/pr/tests/stdio.c
+++ b/pr/tests/stdio.c
@@ -8,9 +8,9 @@
* Description: testing the "special" fds
* Modification History:
* 20-May-1997 AGarcia - Replace Test succeeded status with PASS. This is used by the
- * regress tool parsing code.
+ * regress tool parsing code.
** 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.
*/
@@ -29,12 +29,12 @@ static PRIntn PR_CALLBACK stdio(PRIntn argc, char **argv)
PRFileDesc *err = PR_GetSpecialFD(PR_StandardError);
rv = PR_Write(
- out, "This to standard out\n",
- strlen("This to standard out\n"));
+ out, "This to standard out\n",
+ strlen("This to standard out\n"));
PR_ASSERT((PRInt32)strlen("This to standard out\n") == rv);
rv = PR_Write(
- err, "This to standard err\n",
- strlen("This to standard err\n"));
+ err, "This to standard err\n",
+ strlen("This to standard err\n"));
PR_ASSERT((PRInt32)strlen("This to standard err\n") == rv);
return 0;
diff --git a/pr/tests/strod.c b/pr/tests/strod.c
index 7a148923..014192fa 100644
--- a/pr/tests/strod.c
+++ b/pr/tests/strod.c
@@ -31,21 +31,23 @@ static PRIntn PR_CALLBACK RealMain(PRIntn argc, char **argv)
while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
- if (PL_OPT_BAD == os) continue;
+ if (PL_OPT_BAD == os) {
+ continue;
+ }
switch (opt->option)
{
- case 'n': /* number to translate */
- number = opt->value;
- break;
- case 'l': /* number of times to run the tests */
- loops = atoi(opt->value);
- break;
- case 'h': /* user wants some guidance */
- Help(); /* so give him an earful */
- return 2; /* but not a lot else */
- break;
- default:
- break;
+ case 'n': /* number to translate */
+ number = opt->value;
+ break;
+ case 'l': /* number of times to run the tests */
+ loops = atoi(opt->value);
+ break;
+ case 'h': /* user wants some guidance */
+ Help(); /* so give him an earful */
+ return 2; /* but not a lot else */
+ break;
+ default:
+ break;
}
}
PL_DestroyOptState(opt);
diff --git a/pr/tests/suspend.c b/pr/tests/suspend.c
index 8afb5a33..1976b9d8 100644
--- a/pr/tests/suspend.c
+++ b/pr/tests/suspend.c
@@ -33,21 +33,21 @@ Level_1_Thread(void *arg)
PRThread *thr;
thr = PR_CreateThreadGCAble(PR_USER_THREAD,
- Level_2_Thread,
- NULL,
- PR_PRIORITY_HIGH,
- scope,
- PR_JOINABLE_THREAD,
- 0);
+ Level_2_Thread,
+ NULL,
+ PR_PRIORITY_HIGH,
+ scope,
+ PR_JOINABLE_THREAD,
+ 0);
if (!thr) {
printf("Could not create thread!\n");
} else {
printf("Level_1_Thread[0x%lx] created %15s thread 0x%lx\n",
- PR_GetCurrentThread(),
- (scope == PR_GLOBAL_THREAD) ?
- "PR_GLOBAL_THREAD" : "PR_LOCAL_THREAD",
- thr);
+ PR_GetCurrentThread(),
+ (scope == PR_GLOBAL_THREAD) ?
+ "PR_GLOBAL_THREAD" : "PR_LOCAL_THREAD",
+ thr);
PR_JoinThread(thr);
}
PR_EnterMonitor(mon);
@@ -69,7 +69,7 @@ static PRStatus PR_CALLBACK print_thread(PRThread *thread, int i, void *arg)
registers = PR_GetGCRegisters(thread, 0, (int *)&words);
if (registers)
printf("Registers R0 = 0x%x R1 = 0x%x R2 = 0x%x R3 = 0x%x\n",
- registers[0],registers[1],registers[2],registers[3]);
+ registers[0],registers[1],registers[2],registers[3]);
printf("Stack Pointer = 0x%lx\n", PR_GetSP(thread));
return PR_SUCCESS;
}
@@ -88,21 +88,21 @@ static void Level_0_Thread(PRThreadScope scope1, PRThreadScope scope2)
alive = count;
for (n=0; n<count; n++) {
thr = PR_CreateThreadGCAble(PR_USER_THREAD,
- Level_1_Thread,
- (void *)scope2,
- PR_PRIORITY_NORMAL,
- scope1,
- PR_UNJOINABLE_THREAD,
- 0);
+ Level_1_Thread,
+ (void *)scope2,
+ PR_PRIORITY_NORMAL,
+ scope1,
+ PR_UNJOINABLE_THREAD,
+ 0);
if (!thr) {
printf("Could not create thread!\n");
alive--;
}
printf("Level_0_Thread[0x%lx] created %15s thread 0x%lx\n",
- PR_GetCurrentThread(),
- (scope1 == PR_GLOBAL_THREAD) ?
- "PR_GLOBAL_THREAD" : "PR_LOCAL_THREAD",
- thr);
+ PR_GetCurrentThread(),
+ (scope1 == PR_GLOBAL_THREAD) ?
+ "PR_GLOBAL_THREAD" : "PR_LOCAL_THREAD",
+ thr);
PR_Sleep(0);
}
@@ -111,7 +111,7 @@ static void Level_0_Thread(PRThreadScope scope1, PRThreadScope scope2)
registers = PR_GetGCRegisters(me, 1, (int *)&words);
if (registers)
printf("My Registers: R0 = 0x%x R1 = 0x%x R2 = 0x%x R3 = 0x%x\n",
- registers[0],registers[1],registers[2],registers[3]);
+ registers[0],registers[1],registers[2],registers[3]);
printf("My Stack Pointer = 0x%lx\n", PR_GetSP(me));
PR_ResumeAll();
diff --git a/pr/tests/switch.c b/pr/tests/switch.c
index b79e30c4..43db7888 100644
--- a/pr/tests/switch.c
+++ b/pr/tests/switch.c
@@ -45,11 +45,11 @@ static void Help(void)
debug_out = PR_STDOUT;
PR_fprintf(
- debug_out, "Usage: >./switch [-c n] [-t n] [-d] [-v] [-G] [-C n]\n");
+ debug_out, "Usage: >./switch [-c n] [-t n] [-d] [-v] [-G] [-C n]\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\tglobal threads only (default: FALSE)\n");
@@ -63,9 +63,12 @@ static void PR_CALLBACK Notified(void *arg)
while (PR_SUCCESS == status)
{
PR_Lock(shared->ml);
- while (shared->twiddle && (PR_SUCCESS == status))
+ while (shared->twiddle && (PR_SUCCESS == status)) {
status = PR_WaitCondVar(shared->cv, PR_INTERVAL_NO_TIMEOUT);
- if (verbosity) PR_fprintf(debug_out, "+");
+ }
+ if (verbosity) {
+ PR_fprintf(debug_out, "+");
+ }
shared->twiddle = PR_TRUE;
shared->next->twiddle = PR_FALSE;
PR_NotifyCondVar(shared->next->cv);
@@ -76,7 +79,7 @@ static void PR_CALLBACK Notified(void *arg)
static Shared home;
PRIntn PR_CALLBACK Switch(PRIntn argc, char **argv)
{
- PLOptStatus os;
+ PLOptStatus os;
PRStatus status;
PRBool help = PR_FALSE;
PRUintn concurrency = 1;
@@ -85,52 +88,56 @@ PRIntn PR_CALLBACK Switch(PRIntn argc, char **argv)
PRThreadScope thread_scope = PR_LOCAL_THREAD;
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 = PR_GLOBAL_THREAD;
- 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 = PR_GLOBAL_THREAD;
+ 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");
+ }
PR_SetConcurrency(concurrency);
@@ -153,70 +160,78 @@ PRIntn PR_CALLBACK Switch(PRIntn argc, char **argv)
link = shared;
shared->thread = PR_CreateThread(
- PR_USER_THREAD, Notified, shared,
- PR_PRIORITY_HIGH, thread_scope,
- PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, Notified, shared,
+ PR_PRIORITY_HIGH, thread_scope,
+ PR_JOINABLE_THREAD, 0);
PR_ASSERT(shared->thread != NULL);
- if (NULL == shared->thread)
+ if (NULL == shared->thread) {
failed = PR_TRUE;
- }
+ }
+ }
for (loop_count = 1; loop_count <= loop_limit; ++loop_count)
{
- timein = PR_IntervalNow();
- for (inner_count = 0; inner_count < INNER_LOOPS; ++inner_count)
- {
- PR_Lock(home.ml);
- home.twiddle = PR_TRUE;
- shared->twiddle = PR_FALSE;
- PR_NotifyCondVar(shared->cv);
- while (home.twiddle)
+ timein = PR_IntervalNow();
+ for (inner_count = 0; inner_count < INNER_LOOPS; ++inner_count)
+ {
+ PR_Lock(home.ml);
+ home.twiddle = PR_TRUE;
+ shared->twiddle = PR_FALSE;
+ PR_NotifyCondVar(shared->cv);
+ while (home.twiddle)
{
- status = PR_WaitCondVar(home.cv, PR_INTERVAL_NO_TIMEOUT);
- if (PR_FAILURE == status)
- failed = PR_TRUE;
+ status = PR_WaitCondVar(home.cv, PR_INTERVAL_NO_TIMEOUT);
+ if (PR_FAILURE == status) {
+ failed = PR_TRUE;
+ }
}
- PR_Unlock(home.ml);
- }
- timeout += (PR_IntervalNow() - timein);
- }
-
- if (debug_mode)
- {
- average = PR_IntervalToMicroseconds(timeout)
- / (INNER_LOOPS * loop_limit * thread_count);
- PR_fprintf(
- debug_out, "Average switch times %d usecs for %d threads\n",
+ PR_Unlock(home.ml);
+ }
+ timeout += (PR_IntervalNow() - timein);
+ }
+
+ if (debug_mode)
+ {
+ average = PR_IntervalToMicroseconds(timeout)
+ / (INNER_LOOPS * loop_limit * thread_count);
+ PR_fprintf(
+ debug_out, "Average switch times %d usecs for %d threads\n",
average, thread_limit);
- }
+ }
link = shared;
for (thread_count = 1; thread_count <= thread_limit; ++thread_count)
{
- if (&home == link) break;
+ if (&home == link) {
+ break;
+ }
status = PR_Interrupt(link->thread);
- 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 = PR_JoinThread(shared->thread);
- 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");
+ }
}
PR_DestroyCondVar(shared->cv);
PR_DELETE(shared);
- if (&home == link) break;
+ if (&home == link) {
+ break;
+ }
shared = link;
}
PR_DestroyCondVar(home.cv);
diff --git a/pr/tests/system.c b/pr/tests/system.c
index 60d318ed..85b5e2e5 100644
--- a/pr/tests/system.c
+++ b/pr/tests/system.c
@@ -35,8 +35,12 @@ int main(int argc, char **argv)
for (cmd = PR_SI_HOSTNAME; cmd <= PR_SI_ARCHITECTURE; Incr(&cmd))
{
rv = PR_GetSystemInfo(cmd, info, SYS_INFO_BUFFER_LENGTH);
- if (PR_SUCCESS == rv) PR_fprintf(output, "%s: %s\n", tag[cmd], info);
- else PL_FPrintError(output, tag[cmd]);
+ if (PR_SUCCESS == rv) {
+ PR_fprintf(output, "%s: %s\n", tag[cmd], info);
+ }
+ else {
+ PL_FPrintError(output, tag[cmd]);
+ }
}
PR_DELETE(info);
diff --git a/pr/tests/testbit.c b/pr/tests/testbit.c
index 0987f5f0..889c637e 100644
--- a/pr/tests/testbit.c
+++ b/pr/tests/testbit.c
@@ -24,74 +24,88 @@ int main(int argc, char **argv)
/*
** Test bitmap things.
*/
- if ( PR_TEST_BIT( myMap, 0 ))
+ if ( PR_TEST_BIT( myMap, 0 )) {
ErrorReport("Test 0.0: Failed\n");
+ }
- if ( PR_TEST_BIT( myMap, 31 ))
+ if ( PR_TEST_BIT( myMap, 31 )) {
ErrorReport("Test 0.1: Failed\n");
+ }
- if ( PR_TEST_BIT( myMap, 128 ))
+ if ( PR_TEST_BIT( myMap, 128 )) {
ErrorReport("Test 0.2: Failed\n");
+ }
- if ( PR_TEST_BIT( myMap, 129 ))
+ if ( PR_TEST_BIT( myMap, 129 )) {
ErrorReport("Test 0.3: Failed\n");
+ }
PR_SET_BIT( myMap, 0 );
- if ( !PR_TEST_BIT( myMap, 0 ))
+ if ( !PR_TEST_BIT( myMap, 0 )) {
ErrorReport("Test 1.0: Failed\n");
+ }
PR_CLEAR_BIT( myMap, 0 );
- if ( PR_TEST_BIT( myMap, 0 ))
+ if ( PR_TEST_BIT( myMap, 0 )) {
ErrorReport("Test 1.0.1: Failed\n");
+ }
PR_SET_BIT( myMap, 31 );
- if ( !PR_TEST_BIT( myMap, 31 ))
+ if ( !PR_TEST_BIT( myMap, 31 )) {
ErrorReport("Test 1.1: Failed\n");
+ }
PR_CLEAR_BIT( myMap, 31 );
- if ( PR_TEST_BIT( myMap, 31 ))
+ if ( PR_TEST_BIT( myMap, 31 )) {
ErrorReport("Test 1.1.1: Failed\n");
+ }
PR_SET_BIT( myMap, 128 );
- if ( !PR_TEST_BIT( myMap, 128 ))
+ if ( !PR_TEST_BIT( myMap, 128 )) {
ErrorReport("Test 1.2: Failed\n");
+ }
PR_CLEAR_BIT( myMap, 128 );
- if ( PR_TEST_BIT( myMap, 128 ))
+ if ( PR_TEST_BIT( myMap, 128 )) {
ErrorReport("Test 1.2.1: Failed\n");
+ }
PR_SET_BIT( myMap, 129 );
- if ( !PR_TEST_BIT( myMap, 129 ))
+ if ( !PR_TEST_BIT( myMap, 129 )) {
ErrorReport("Test 1.3: Failed\n");
+ }
PR_CLEAR_BIT( myMap, 129 );
- if ( PR_TEST_BIT( myMap, 129 ))
+ if ( PR_TEST_BIT( myMap, 129 )) {
ErrorReport("Test 1.3.1: Failed\n");
+ }
/*
** Test Ceiling and Floor functions and macros
*/
- if ((rc = PR_CeilingLog2(32)) != 5 )
+ if ((rc = PR_CeilingLog2(32)) != 5 ) {
ErrorReport("Test 10.0: Failed\n");
+ }
- if ((rc = PR_FloorLog2(32)) != 5 )
+ if ((rc = PR_FloorLog2(32)) != 5 ) {
ErrorReport("Test 10.1: Failed\n");
+ }
/*
** Evaluate results and exit
*/
if (failed)
- {
+ {
printf("FAILED\n");
return(1);
- }
+ }
else
- {
+ {
printf("PASSED\n");
return(0);
- }
+ }
} /* end main() */
/* end testbit.c */
diff --git a/pr/tests/testfile.c b/pr/tests/testfile.c
index 360ef1f7..99cf94dd 100644
--- a/pr/tests/testfile.c
+++ b/pr/tests/testfile.c
@@ -42,24 +42,24 @@ PRInt32 count;
int thread_count;
#ifdef WIN16
-#define BUF_DATA_SIZE 256 * 120
+#define BUF_DATA_SIZE 256 * 120
#else
-#define BUF_DATA_SIZE 256 * 1024
+#define BUF_DATA_SIZE 256 * 1024
#endif
-#define NUM_RDWR_THREADS 10
-#define NUM_DIRTEST_THREADS 4
+#define NUM_RDWR_THREADS 10
+#define NUM_DIRTEST_THREADS 4
#define CHUNK_SIZE 512
typedef struct buffer {
- char data[BUF_DATA_SIZE];
+ char data[BUF_DATA_SIZE];
} buffer;
typedef struct File_Rdwr_Param {
- char *pathname;
- char *buf;
- int offset;
- int len;
+ char *pathname;
+ char *buf;
+ int offset;
+ int len;
} File_Rdwr_Param;
#ifdef XP_PC
@@ -80,800 +80,805 @@ char pathname[256], renamename[256];
#ifdef WINCE
WCHAR wPathname[256];
#endif
-#define TMPDIR_LEN 64
+#define TMPDIR_LEN 64
char testdir[TMPDIR_LEN];
static PRInt32 PR_CALLBACK DirTest(void *argunused);
PRInt32 dirtest_failed = 0;
PRThread* create_new_thread(PRThreadType type,
- void (*start)(void *arg),
- void *arg,
- PRThreadPriority priority,
- PRThreadScope scope,
- PRThreadState state,
- PRUint32 stackSize, PRInt32 index)
+ void (*start)(void *arg),
+ void *arg,
+ PRThreadPriority priority,
+ PRThreadScope scope,
+ PRThreadState state,
+ PRUint32 stackSize, PRInt32 index)
{
-PRInt32 native_thread = 0;
+ PRInt32 native_thread = 0;
- PR_ASSERT(state == PR_UNJOINABLE_THREAD);
+ PR_ASSERT(state == PR_UNJOINABLE_THREAD);
#if defined(_PR_PTHREADS) || defined(WIN32) || defined(XP_OS2)
- switch(index % 4) {
- case 0:
- scope = (PR_LOCAL_THREAD);
- break;
- case 1:
- scope = (PR_GLOBAL_THREAD);
- break;
- case 2:
- scope = (PR_GLOBAL_BOUND_THREAD);
- break;
- case 3:
- native_thread = 1;
- break;
- default:
- PR_NOT_REACHED("Invalid scope");
- break;
- }
- if (native_thread) {
+ switch(index % 4) {
+ case 0:
+ scope = (PR_LOCAL_THREAD);
+ break;
+ case 1:
+ scope = (PR_GLOBAL_THREAD);
+ break;
+ case 2:
+ scope = (PR_GLOBAL_BOUND_THREAD);
+ break;
+ case 3:
+ native_thread = 1;
+ break;
+ default:
+ PR_NOT_REACHED("Invalid scope");
+ break;
+ }
+ if (native_thread) {
#if defined(_PR_PTHREADS)
- pthread_t tid;
- if (!pthread_create(&tid, NULL, start, arg))
- return((PRThread *) tid);
- else
- return (NULL);
+ pthread_t tid;
+ if (!pthread_create(&tid, NULL, start, arg)) {
+ return((PRThread *) tid);
+ }
+ else {
+ return (NULL);
+ }
#elif defined(XP_OS2)
TID tid;
tid = (TID)_beginthread((void(* _Optlink)(void*))start,
NULL, 32768, arg);
if (tid == -1) {
- printf("_beginthread failed. errno %d\n", errno);
- return (NULL);
+ printf("_beginthread failed. errno %d\n", errno);
+ return (NULL);
+ }
+ else {
+ return((PRThread *) tid);
}
- else
- return((PRThread *) tid);
#else
- HANDLE thandle;
- unsigned tid;
-
- thandle = (HANDLE) _beginthreadex(
- NULL,
- stackSize,
- (unsigned (__stdcall *)(void *))start,
- arg,
- STACK_SIZE_PARAM_IS_A_RESERVATION,
- &tid);
- return((PRThread *) thandle);
+ HANDLE thandle;
+ unsigned tid;
+
+ thandle = (HANDLE) _beginthreadex(
+ NULL,
+ stackSize,
+ (unsigned (__stdcall *)(void *))start,
+ arg,
+ STACK_SIZE_PARAM_IS_A_RESERVATION,
+ &tid);
+ return((PRThread *) thandle);
#endif
- } else {
- return(PR_CreateThread(type,start,arg,priority,scope,state,stackSize));
- }
+ } else {
+ return(PR_CreateThread(type,start,arg,priority,scope,state,stackSize));
+ }
#else
- return(PR_CreateThread(type,start,arg,priority,scope,state,stackSize));
+ return(PR_CreateThread(type,start,arg,priority,scope,state,stackSize));
#endif
}
static void PR_CALLBACK File_Write(void *arg)
{
-PRFileDesc *fd_file;
-File_Rdwr_Param *fp = (File_Rdwr_Param *) arg;
-char *name, *buf;
-int offset, len;
-
- setbuf(stdout, NULL);
- name = fp->pathname;
- buf = fp->buf;
- offset = fp->offset;
- len = fp->len;
-
- fd_file = PR_Open(name, PR_RDWR | PR_CREATE_FILE, 0777);
- if (fd_file == NULL) {
- printf("testfile failed to create/open file %s\n",name);
- return;
- }
- if (PR_Seek(fd_file, offset, PR_SEEK_SET) < 0) {
- printf("testfile failed to seek in file %s\n",name);
- return;
- }
- if ((PR_Write(fd_file, buf, len)) < 0) {
- printf("testfile failed to write to file %s\n",name);
- return;
- }
- DPRINTF(("Write out_buf[0] = 0x%x\n",(*((int *) buf))));
- PR_Close(fd_file);
- PR_DELETE(fp);
-
- PR_EnterMonitor(mon);
- --thread_count;
- PR_Notify(mon);
- PR_ExitMonitor(mon);
+ PRFileDesc *fd_file;
+ File_Rdwr_Param *fp = (File_Rdwr_Param *) arg;
+ char *name, *buf;
+ int offset, len;
+
+ setbuf(stdout, NULL);
+ name = fp->pathname;
+ buf = fp->buf;
+ offset = fp->offset;
+ len = fp->len;
+
+ fd_file = PR_Open(name, PR_RDWR | PR_CREATE_FILE, 0777);
+ if (fd_file == NULL) {
+ printf("testfile failed to create/open file %s\n",name);
+ return;
+ }
+ if (PR_Seek(fd_file, offset, PR_SEEK_SET) < 0) {
+ printf("testfile failed to seek in file %s\n",name);
+ return;
+ }
+ if ((PR_Write(fd_file, buf, len)) < 0) {
+ printf("testfile failed to write to file %s\n",name);
+ return;
+ }
+ DPRINTF(("Write out_buf[0] = 0x%x\n",(*((int *) buf))));
+ PR_Close(fd_file);
+ PR_DELETE(fp);
+
+ PR_EnterMonitor(mon);
+ --thread_count;
+ PR_Notify(mon);
+ PR_ExitMonitor(mon);
}
static void PR_CALLBACK File_Read(void *arg)
{
-PRFileDesc *fd_file;
-File_Rdwr_Param *fp = (File_Rdwr_Param *) arg;
-char *name, *buf;
-int offset, len;
-
- setbuf(stdout, NULL);
- name = fp->pathname;
- buf = fp->buf;
- offset = fp->offset;
- len = fp->len;
-
- fd_file = PR_Open(name, PR_RDONLY, 0);
- if (fd_file == NULL) {
- printf("testfile failed to open file %s\n",name);
- return;
- }
- if (PR_Seek(fd_file, offset, PR_SEEK_SET) < 0) {
- printf("testfile failed to seek in file %s\n",name);
- return;
- }
- if ((PR_Read(fd_file, buf, len)) < 0) {
- printf("testfile failed to read to file %s\n",name);
- return;
- }
- DPRINTF(("Read in_buf[0] = 0x%x\n",(*((int *) buf))));
- PR_Close(fd_file);
- PR_DELETE(fp);
-
- PR_EnterMonitor(mon);
- --thread_count;
- PR_Notify(mon);
- PR_ExitMonitor(mon);
+ PRFileDesc *fd_file;
+ File_Rdwr_Param *fp = (File_Rdwr_Param *) arg;
+ char *name, *buf;
+ int offset, len;
+
+ setbuf(stdout, NULL);
+ name = fp->pathname;
+ buf = fp->buf;
+ offset = fp->offset;
+ len = fp->len;
+
+ fd_file = PR_Open(name, PR_RDONLY, 0);
+ if (fd_file == NULL) {
+ printf("testfile failed to open file %s\n",name);
+ return;
+ }
+ if (PR_Seek(fd_file, offset, PR_SEEK_SET) < 0) {
+ printf("testfile failed to seek in file %s\n",name);
+ return;
+ }
+ if ((PR_Read(fd_file, buf, len)) < 0) {
+ printf("testfile failed to read to file %s\n",name);
+ return;
+ }
+ DPRINTF(("Read in_buf[0] = 0x%x\n",(*((int *) buf))));
+ PR_Close(fd_file);
+ PR_DELETE(fp);
+
+ PR_EnterMonitor(mon);
+ --thread_count;
+ PR_Notify(mon);
+ PR_ExitMonitor(mon);
}
static PRInt32 Misc_File_Tests(char *pathname)
{
-PRFileDesc *fd_file;
-int len, rv = 0;
-PRFileInfo file_info, file_info1;
-char tmpname[1024];
-
- setbuf(stdout, NULL);
- /*
- * Test PR_Available, PR_Seek, PR_GetFileInfo, PR_Rename, PR_Access
- */
-
- fd_file = PR_Open(pathname, PR_RDWR | PR_CREATE_FILE, 0777);
-
- if (fd_file == NULL) {
- printf("testfile failed to create/open file %s\n",pathname);
- return -1;
- }
- if (PR_GetOpenFileInfo(fd_file, &file_info) < 0) {
- printf("testfile PR_GetFileInfo failed on file %s\n",pathname);
- rv = -1;
- goto cleanup;
- }
- if (PR_Access(pathname, PR_ACCESS_EXISTS) != 0) {
- printf("testfile PR_Access failed on file %s\n",pathname);
- rv = -1;
- goto cleanup;
- }
- if (PR_Access(pathname, PR_ACCESS_WRITE_OK) != 0) {
- printf("testfile PR_Access failed on file %s\n",pathname);
- rv = -1;
- goto cleanup;
- }
- if (PR_Access(pathname, PR_ACCESS_READ_OK) != 0) {
- printf("testfile PR_Access failed on file %s\n",pathname);
- rv = -1;
- goto cleanup;
- }
-
-
- if (PR_GetFileInfo(pathname, &file_info) < 0) {
- printf("testfile PR_GetFileInfo failed on file %s\n",pathname);
- rv = -1;
- goto cleanup;
- }
- if (file_info.type != PR_FILE_FILE) {
- printf(
- "testfile: Error - PR_GetFileInfo returned incorrect type for file %s\n",
- pathname);
- rv = -1;
- goto cleanup;
- }
- if (file_info.size != 0) {
- printf(
- "testfile PR_GetFileInfo returned incorrect size (%d should be 0) for file %s\n",
- file_info.size, pathname);
- rv = -1;
- goto cleanup;
- }
- file_info1 = file_info;
-
- len = PR_Available(fd_file);
- if (len < 0) {
- printf("testfile PR_Available failed on file %s\n",pathname);
- rv = -1;
- goto cleanup;
- } else if (len != 0) {
- printf(
- "testfile PR_Available failed: expected/returned = %d/%d bytes\n",
- 0, len);
- rv = -1;
- goto cleanup;
- }
- if (PR_GetOpenFileInfo(fd_file, &file_info) < 0) {
- printf("testfile PR_GetFileInfo failed on file %s\n",pathname);
- goto cleanup;
- }
- if (LL_NE(file_info.creationTime , file_info1.creationTime)) {
- printf(
- "testfile PR_GetFileInfo returned incorrect status-change time: %s\n",
- pathname);
- printf("ft = %lld, ft1 = %lld\n",file_info.creationTime,
- file_info1.creationTime);
- rv = -1;
- goto cleanup;
- }
- len = PR_Write(fd_file, out_buf->data, CHUNK_SIZE);
- if (len < 0) {
- printf("testfile failed to write to file %s\n",pathname);
- rv = -1;
- goto cleanup;
- }
- if (PR_GetOpenFileInfo(fd_file, &file_info) < 0) {
- printf("testfile PR_GetFileInfo failed on file %s\n",pathname);
- goto cleanup;
- }
- if (file_info.size != CHUNK_SIZE) {
- printf(
- "testfile PR_GetFileInfo returned incorrect size (%d should be %d) for file %s\n",
- file_info.size, CHUNK_SIZE, pathname);
- rv = -1;
- goto cleanup;
- }
- if (LL_CMP(file_info.modifyTime, < , file_info1.modifyTime)) {
- printf(
- "testfile PR_GetFileInfo returned incorrect modify time: %s\n",
- pathname);
- printf("ft = %lld, ft1 = %lld\n",file_info.modifyTime,
- file_info1.modifyTime);
- rv = -1;
- goto cleanup;
- }
-
- len = PR_Available(fd_file);
- if (len < 0) {
- printf("testfile PR_Available failed on file %s\n",pathname);
- rv = -1;
- goto cleanup;
- } else if (len != 0) {
- printf(
- "testfile PR_Available failed: expected/returned = %d/%d bytes\n",
- 0, len);
- rv = -1;
- goto cleanup;
- }
-
- PR_Seek(fd_file, 0, PR_SEEK_SET);
- len = PR_Available(fd_file);
- if (len < 0) {
- printf("testfile PR_Available failed on file %s\n",pathname);
- rv = -1;
- goto cleanup;
- } else if (len != CHUNK_SIZE) {
- printf(
- "testfile PR_Available failed: expected/returned = %d/%d bytes\n",
- CHUNK_SIZE, len);
- rv = -1;
- goto cleanup;
- }
+ PRFileDesc *fd_file;
+ int len, rv = 0;
+ PRFileInfo file_info, file_info1;
+ char tmpname[1024];
+
+ setbuf(stdout, NULL);
+ /*
+ * Test PR_Available, PR_Seek, PR_GetFileInfo, PR_Rename, PR_Access
+ */
+
+ fd_file = PR_Open(pathname, PR_RDWR | PR_CREATE_FILE, 0777);
+
+ if (fd_file == NULL) {
+ printf("testfile failed to create/open file %s\n",pathname);
+ return -1;
+ }
+ if (PR_GetOpenFileInfo(fd_file, &file_info) < 0) {
+ printf("testfile PR_GetFileInfo failed on file %s\n",pathname);
+ rv = -1;
+ goto cleanup;
+ }
+ if (PR_Access(pathname, PR_ACCESS_EXISTS) != 0) {
+ printf("testfile PR_Access failed on file %s\n",pathname);
+ rv = -1;
+ goto cleanup;
+ }
+ if (PR_Access(pathname, PR_ACCESS_WRITE_OK) != 0) {
+ printf("testfile PR_Access failed on file %s\n",pathname);
+ rv = -1;
+ goto cleanup;
+ }
+ if (PR_Access(pathname, PR_ACCESS_READ_OK) != 0) {
+ printf("testfile PR_Access failed on file %s\n",pathname);
+ rv = -1;
+ goto cleanup;
+ }
+
+
+ if (PR_GetFileInfo(pathname, &file_info) < 0) {
+ printf("testfile PR_GetFileInfo failed on file %s\n",pathname);
+ rv = -1;
+ goto cleanup;
+ }
+ if (file_info.type != PR_FILE_FILE) {
+ printf(
+ "testfile: Error - PR_GetFileInfo returned incorrect type for file %s\n",
+ pathname);
+ rv = -1;
+ goto cleanup;
+ }
+ if (file_info.size != 0) {
+ printf(
+ "testfile PR_GetFileInfo returned incorrect size (%d should be 0) for file %s\n",
+ file_info.size, pathname);
+ rv = -1;
+ goto cleanup;
+ }
+ file_info1 = file_info;
+
+ len = PR_Available(fd_file);
+ if (len < 0) {
+ printf("testfile PR_Available failed on file %s\n",pathname);
+ rv = -1;
+ goto cleanup;
+ } else if (len != 0) {
+ printf(
+ "testfile PR_Available failed: expected/returned = %d/%d bytes\n",
+ 0, len);
+ rv = -1;
+ goto cleanup;
+ }
+ if (PR_GetOpenFileInfo(fd_file, &file_info) < 0) {
+ printf("testfile PR_GetFileInfo failed on file %s\n",pathname);
+ goto cleanup;
+ }
+ if (LL_NE(file_info.creationTime, file_info1.creationTime)) {
+ printf(
+ "testfile PR_GetFileInfo returned incorrect status-change time: %s\n",
+ pathname);
+ printf("ft = %lld, ft1 = %lld\n",file_info.creationTime,
+ file_info1.creationTime);
+ rv = -1;
+ goto cleanup;
+ }
+ len = PR_Write(fd_file, out_buf->data, CHUNK_SIZE);
+ if (len < 0) {
+ printf("testfile failed to write to file %s\n",pathname);
+ rv = -1;
+ goto cleanup;
+ }
+ if (PR_GetOpenFileInfo(fd_file, &file_info) < 0) {
+ printf("testfile PR_GetFileInfo failed on file %s\n",pathname);
+ goto cleanup;
+ }
+ if (file_info.size != CHUNK_SIZE) {
+ printf(
+ "testfile PR_GetFileInfo returned incorrect size (%d should be %d) for file %s\n",
+ file_info.size, CHUNK_SIZE, pathname);
+ rv = -1;
+ goto cleanup;
+ }
+ if (LL_CMP(file_info.modifyTime, <, file_info1.modifyTime)) {
+ printf(
+ "testfile PR_GetFileInfo returned incorrect modify time: %s\n",
+ pathname);
+ printf("ft = %lld, ft1 = %lld\n",file_info.modifyTime,
+ file_info1.modifyTime);
+ rv = -1;
+ goto cleanup;
+ }
+
+ len = PR_Available(fd_file);
+ if (len < 0) {
+ printf("testfile PR_Available failed on file %s\n",pathname);
+ rv = -1;
+ goto cleanup;
+ } else if (len != 0) {
+ printf(
+ "testfile PR_Available failed: expected/returned = %d/%d bytes\n",
+ 0, len);
+ rv = -1;
+ goto cleanup;
+ }
+
+ PR_Seek(fd_file, 0, PR_SEEK_SET);
+ len = PR_Available(fd_file);
+ if (len < 0) {
+ printf("testfile PR_Available failed on file %s\n",pathname);
+ rv = -1;
+ goto cleanup;
+ } else if (len != CHUNK_SIZE) {
+ printf(
+ "testfile PR_Available failed: expected/returned = %d/%d bytes\n",
+ CHUNK_SIZE, len);
+ rv = -1;
+ goto cleanup;
+ }
PR_Close(fd_file);
- strcpy(tmpname,pathname);
- strcat(tmpname,".RENAMED");
- if (PR_FAILURE == PR_Rename(pathname, tmpname)) {
- printf("testfile failed to rename file %s\n",pathname);
- rv = -1;
- goto cleanup;
- }
+ strcpy(tmpname,pathname);
+ strcat(tmpname,".RENAMED");
+ if (PR_FAILURE == PR_Rename(pathname, tmpname)) {
+ printf("testfile failed to rename file %s\n",pathname);
+ rv = -1;
+ goto cleanup;
+ }
- fd_file = PR_Open(pathname, PR_RDWR | PR_CREATE_FILE, 0777);
- len = PR_Write(fd_file, out_buf->data, CHUNK_SIZE);
+ fd_file = PR_Open(pathname, PR_RDWR | PR_CREATE_FILE, 0777);
+ len = PR_Write(fd_file, out_buf->data, CHUNK_SIZE);
PR_Close(fd_file);
- if (PR_SUCCESS == PR_Rename(pathname, tmpname)) {
- printf("testfile renamed to existing file %s\n",pathname);
- }
+ if (PR_SUCCESS == PR_Rename(pathname, tmpname)) {
+ printf("testfile renamed to existing file %s\n",pathname);
+ }
- if ((PR_Delete(tmpname)) < 0) {
- printf("testfile failed to unlink file %s\n",tmpname);
- rv = -1;
- }
+ if ((PR_Delete(tmpname)) < 0) {
+ printf("testfile failed to unlink file %s\n",tmpname);
+ rv = -1;
+ }
cleanup:
- if ((PR_Delete(pathname)) < 0) {
- printf("testfile failed to unlink file %s\n",pathname);
- rv = -1;
- }
- return rv;
+ if ((PR_Delete(pathname)) < 0) {
+ printf("testfile failed to unlink file %s\n",pathname);
+ rv = -1;
+ }
+ return rv;
}
static PRInt32 PR_CALLBACK FileTest(void)
{
-PRDir *fd_dir;
-int i, offset, len, rv = 0;
-PRThread *t;
-PRThreadScope scope = PR_GLOBAL_THREAD;
-File_Rdwr_Param *fparamp;
-
- /*
- * Create Test dir
- */
- if ((PR_MkDir(TEST_DIR, 0777)) < 0) {
- printf("testfile failed to create dir %s\n",TEST_DIR);
- return -1;
- }
- fd_dir = PR_OpenDir(TEST_DIR);
- if (fd_dir == NULL) {
- printf("testfile failed to open dir %s\n",TEST_DIR);
- rv = -1;
- goto cleanup;
- }
+ PRDir *fd_dir;
+ int i, offset, len, rv = 0;
+ PRThread *t;
+ PRThreadScope scope = PR_GLOBAL_THREAD;
+ File_Rdwr_Param *fparamp;
+
+ /*
+ * Create Test dir
+ */
+ if ((PR_MkDir(TEST_DIR, 0777)) < 0) {
+ printf("testfile failed to create dir %s\n",TEST_DIR);
+ return -1;
+ }
+ fd_dir = PR_OpenDir(TEST_DIR);
+ if (fd_dir == NULL) {
+ printf("testfile failed to open dir %s\n",TEST_DIR);
+ rv = -1;
+ goto cleanup;
+ }
PR_CloseDir(fd_dir);
- strcat(pathname, TEST_DIR);
- strcat(pathname, "/");
- strcat(pathname, FILE_NAME);
-
- in_buf = PR_NEW(buffer);
- if (in_buf == NULL) {
- printf(
- "testfile failed to alloc buffer struct\n");
- rv = -1;
- goto cleanup;
- }
- out_buf = PR_NEW(buffer);
- if (out_buf == NULL) {
- printf(
- "testfile failed to alloc buffer struct\n");
- rv = -1;
- goto cleanup;
- }
-
- /*
- * Start a bunch of writer threads
- */
- offset = 0;
- len = CHUNK_SIZE;
- PR_EnterMonitor(mon);
- for (i = 0; i < NUM_RDWR_THREADS; i++) {
- fparamp = PR_NEW(File_Rdwr_Param);
- if (fparamp == NULL) {
- printf(
- "testfile failed to alloc File_Rdwr_Param struct\n");
- rv = -1;
- goto cleanup;
- }
- fparamp->pathname = pathname;
- fparamp->buf = out_buf->data + offset;
- fparamp->offset = offset;
- fparamp->len = len;
- memset(fparamp->buf, i, len);
-
- t = create_new_thread(PR_USER_THREAD,
- File_Write, (void *)fparamp,
- PR_PRIORITY_NORMAL,
- scope,
- PR_UNJOINABLE_THREAD,
- 0, i);
- offset += len;
- }
- thread_count = i;
- /* Wait for writer threads to exit */
- while (thread_count) {
- PR_Wait(mon, PR_INTERVAL_NO_TIMEOUT);
- }
- PR_ExitMonitor(mon);
-
-
- /*
- * Start a bunch of reader threads
- */
- offset = 0;
- len = CHUNK_SIZE;
- PR_EnterMonitor(mon);
- for (i = 0; i < NUM_RDWR_THREADS; i++) {
- fparamp = PR_NEW(File_Rdwr_Param);
- if (fparamp == NULL) {
- printf(
- "testfile failed to alloc File_Rdwr_Param struct\n");
- rv = -1;
- goto cleanup;
- }
- fparamp->pathname = pathname;
- fparamp->buf = in_buf->data + offset;
- fparamp->offset = offset;
- fparamp->len = len;
-
- t = create_new_thread(PR_USER_THREAD,
- File_Read, (void *)fparamp,
- PR_PRIORITY_NORMAL,
- scope,
- PR_UNJOINABLE_THREAD,
- 0, i);
- offset += len;
- if ((offset + len) > BUF_DATA_SIZE)
- break;
- }
- thread_count = i;
-
- /* Wait for reader threads to exit */
- while (thread_count) {
- PR_Wait(mon, PR_INTERVAL_NO_TIMEOUT);
- }
- PR_ExitMonitor(mon);
-
- if (memcmp(in_buf->data, out_buf->data, offset) != 0) {
- printf("File Test failed: file data corrupted\n");
- rv = -1;
- goto cleanup;
- }
-
- if ((PR_Delete(pathname)) < 0) {
- printf("testfile failed to unlink file %s\n",pathname);
- rv = -1;
- goto cleanup;
- }
-
- /*
- * Test PR_Available, PR_Seek, PR_GetFileInfo, PR_Rename, PR_Access
- */
- if (Misc_File_Tests(pathname) < 0) {
- rv = -1;
- }
+ strcat(pathname, TEST_DIR);
+ strcat(pathname, "/");
+ strcat(pathname, FILE_NAME);
+
+ in_buf = PR_NEW(buffer);
+ if (in_buf == NULL) {
+ printf(
+ "testfile failed to alloc buffer struct\n");
+ rv = -1;
+ goto cleanup;
+ }
+ out_buf = PR_NEW(buffer);
+ if (out_buf == NULL) {
+ printf(
+ "testfile failed to alloc buffer struct\n");
+ rv = -1;
+ goto cleanup;
+ }
+
+ /*
+ * Start a bunch of writer threads
+ */
+ offset = 0;
+ len = CHUNK_SIZE;
+ PR_EnterMonitor(mon);
+ for (i = 0; i < NUM_RDWR_THREADS; i++) {
+ fparamp = PR_NEW(File_Rdwr_Param);
+ if (fparamp == NULL) {
+ printf(
+ "testfile failed to alloc File_Rdwr_Param struct\n");
+ rv = -1;
+ goto cleanup;
+ }
+ fparamp->pathname = pathname;
+ fparamp->buf = out_buf->data + offset;
+ fparamp->offset = offset;
+ fparamp->len = len;
+ memset(fparamp->buf, i, len);
+
+ t = create_new_thread(PR_USER_THREAD,
+ File_Write, (void *)fparamp,
+ PR_PRIORITY_NORMAL,
+ scope,
+ PR_UNJOINABLE_THREAD,
+ 0, i);
+ offset += len;
+ }
+ thread_count = i;
+ /* Wait for writer threads to exit */
+ while (thread_count) {
+ PR_Wait(mon, PR_INTERVAL_NO_TIMEOUT);
+ }
+ PR_ExitMonitor(mon);
+
+
+ /*
+ * Start a bunch of reader threads
+ */
+ offset = 0;
+ len = CHUNK_SIZE;
+ PR_EnterMonitor(mon);
+ for (i = 0; i < NUM_RDWR_THREADS; i++) {
+ fparamp = PR_NEW(File_Rdwr_Param);
+ if (fparamp == NULL) {
+ printf(
+ "testfile failed to alloc File_Rdwr_Param struct\n");
+ rv = -1;
+ goto cleanup;
+ }
+ fparamp->pathname = pathname;
+ fparamp->buf = in_buf->data + offset;
+ fparamp->offset = offset;
+ fparamp->len = len;
+
+ t = create_new_thread(PR_USER_THREAD,
+ File_Read, (void *)fparamp,
+ PR_PRIORITY_NORMAL,
+ scope,
+ PR_UNJOINABLE_THREAD,
+ 0, i);
+ offset += len;
+ if ((offset + len) > BUF_DATA_SIZE) {
+ break;
+ }
+ }
+ thread_count = i;
+
+ /* Wait for reader threads to exit */
+ while (thread_count) {
+ PR_Wait(mon, PR_INTERVAL_NO_TIMEOUT);
+ }
+ PR_ExitMonitor(mon);
+
+ if (memcmp(in_buf->data, out_buf->data, offset) != 0) {
+ printf("File Test failed: file data corrupted\n");
+ rv = -1;
+ goto cleanup;
+ }
+
+ if ((PR_Delete(pathname)) < 0) {
+ printf("testfile failed to unlink file %s\n",pathname);
+ rv = -1;
+ goto cleanup;
+ }
+
+ /*
+ * Test PR_Available, PR_Seek, PR_GetFileInfo, PR_Rename, PR_Access
+ */
+ if (Misc_File_Tests(pathname) < 0) {
+ rv = -1;
+ }
cleanup:
- if ((PR_RmDir(TEST_DIR)) < 0) {
- printf("testfile failed to rmdir %s\n", TEST_DIR);
- rv = -1;
- }
- return rv;
+ if ((PR_RmDir(TEST_DIR)) < 0) {
+ printf("testfile failed to rmdir %s\n", TEST_DIR);
+ rv = -1;
+ }
+ return rv;
}
struct dirtest_arg {
- PRMonitor *mon;
- PRInt32 done;
+ PRMonitor *mon;
+ PRInt32 done;
};
static PRInt32 RunDirTest(void)
{
-int i;
-PRThread *t;
-PRMonitor *mon;
-struct dirtest_arg thrarg;
-
- mon = PR_NewMonitor();
- if (!mon) {
- printf("RunDirTest: Error - failed to create monitor\n");
- dirtest_failed = 1;
- return -1;
- }
- thrarg.mon = mon;
-
- for (i = 0; i < NUM_DIRTEST_THREADS; i++) {
-
- thrarg.done= 0;
- t = create_new_thread(PR_USER_THREAD,
- DirTest, &thrarg,
- PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD,
- PR_UNJOINABLE_THREAD,
- 0, i);
- if (!t) {
- printf("RunDirTest: Error - failed to create thread\n");
- dirtest_failed = 1;
- return -1;
- }
- PR_EnterMonitor(mon);
- while (!thrarg.done)
- PR_Wait(mon, PR_INTERVAL_NO_TIMEOUT);
- PR_ExitMonitor(mon);
-
- }
- PR_DestroyMonitor(mon);
- return 0;
+ int i;
+ PRThread *t;
+ PRMonitor *mon;
+ struct dirtest_arg thrarg;
+
+ mon = PR_NewMonitor();
+ if (!mon) {
+ printf("RunDirTest: Error - failed to create monitor\n");
+ dirtest_failed = 1;
+ return -1;
+ }
+ thrarg.mon = mon;
+
+ for (i = 0; i < NUM_DIRTEST_THREADS; i++) {
+
+ thrarg.done= 0;
+ t = create_new_thread(PR_USER_THREAD,
+ DirTest, &thrarg,
+ PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD,
+ PR_UNJOINABLE_THREAD,
+ 0, i);
+ if (!t) {
+ printf("RunDirTest: Error - failed to create thread\n");
+ dirtest_failed = 1;
+ return -1;
+ }
+ PR_EnterMonitor(mon);
+ while (!thrarg.done) {
+ PR_Wait(mon, PR_INTERVAL_NO_TIMEOUT);
+ }
+ PR_ExitMonitor(mon);
+
+ }
+ PR_DestroyMonitor(mon);
+ return 0;
}
static PRInt32 PR_CALLBACK DirTest(void *arg)
{
-struct dirtest_arg *tinfo = (struct dirtest_arg *) arg;
-PRFileDesc *fd_file;
-PRDir *fd_dir;
-int i;
-int path_len;
-PRDirEntry *dirEntry;
-PRFileInfo info;
-PRInt32 num_files = 0;
+ struct dirtest_arg *tinfo = (struct dirtest_arg *) arg;
+ PRFileDesc *fd_file;
+ PRDir *fd_dir;
+ int i;
+ int path_len;
+ PRDirEntry *dirEntry;
+ PRFileInfo info;
+ PRInt32 num_files = 0;
#if defined(XP_PC) && defined(WIN32)
-HANDLE hfile;
+ HANDLE hfile;
#endif
#define FILES_IN_DIR 20
- /*
- * Create Test dir
- */
- DPRINTF(("Creating test dir %s\n",TEST_DIR));
- if ((PR_MkDir(TEST_DIR, 0777)) < 0) {
- printf(
- "testfile failed to create dir %s [%d, %d]\n",
- TEST_DIR, PR_GetError(), PR_GetOSError());
- return -1;
- }
- fd_dir = PR_OpenDir(TEST_DIR);
- if (fd_dir == NULL) {
- printf(
- "testfile failed to open dirctory %s [%d, %d]\n",
- TEST_DIR, PR_GetError(), PR_GetOSError());
- return -1;
- }
-
- strcpy(pathname, TEST_DIR);
- strcat(pathname, "/");
- strcat(pathname, FILE_NAME);
- path_len = strlen(pathname);
-
- for (i = 0; i < FILES_IN_DIR; i++) {
-
- sprintf(pathname + path_len,"%d%s",i,"");
-
- DPRINTF(("Creating test file %s\n",pathname));
-
- fd_file = PR_Open(pathname, PR_RDWR | PR_CREATE_FILE, 0777);
-
- if (fd_file == NULL) {
- printf(
- "testfile failed to create/open file %s [%d, %d]\n",
- pathname, PR_GetError(), PR_GetOSError());
- return -1;
- }
+ /*
+ * Create Test dir
+ */
+ DPRINTF(("Creating test dir %s\n",TEST_DIR));
+ if ((PR_MkDir(TEST_DIR, 0777)) < 0) {
+ printf(
+ "testfile failed to create dir %s [%d, %d]\n",
+ TEST_DIR, PR_GetError(), PR_GetOSError());
+ return -1;
+ }
+ fd_dir = PR_OpenDir(TEST_DIR);
+ if (fd_dir == NULL) {
+ printf(
+ "testfile failed to open dirctory %s [%d, %d]\n",
+ TEST_DIR, PR_GetError(), PR_GetOSError());
+ return -1;
+ }
+
+ strcpy(pathname, TEST_DIR);
+ strcat(pathname, "/");
+ strcat(pathname, FILE_NAME);
+ path_len = strlen(pathname);
+
+ for (i = 0; i < FILES_IN_DIR; i++) {
+
+ sprintf(pathname + path_len,"%d%s",i,"");
+
+ DPRINTF(("Creating test file %s\n",pathname));
+
+ fd_file = PR_Open(pathname, PR_RDWR | PR_CREATE_FILE, 0777);
+
+ if (fd_file == NULL) {
+ printf(
+ "testfile failed to create/open file %s [%d, %d]\n",
+ pathname, PR_GetError(), PR_GetOSError());
+ return -1;
+ }
PR_Close(fd_file);
- }
+ }
#if defined(XP_UNIX) || (defined(XP_PC) && defined(WIN32)) || defined(XP_OS2)
- /*
- * Create a hidden file - a platform-dependent operation
- */
- strcpy(pathname, TEST_DIR);
- strcat(pathname, "/");
- strcat(pathname, HIDDEN_FILE_NAME);
+ /*
+ * Create a hidden file - a platform-dependent operation
+ */
+ strcpy(pathname, TEST_DIR);
+ strcat(pathname, "/");
+ strcat(pathname, HIDDEN_FILE_NAME);
#if defined(XP_UNIX)
- DPRINTF(("Creating hidden test file %s\n",pathname));
- fd_file = PR_Open(pathname, PR_RDWR | PR_CREATE_FILE, 0777);
-
- if (fd_file == NULL) {
- printf(
- "testfile failed to create/open hidden file %s [%d, %d]\n",
- pathname, PR_GetError(), PR_GetOSError());
- return -1;
- }
+ DPRINTF(("Creating hidden test file %s\n",pathname));
+ fd_file = PR_Open(pathname, PR_RDWR | PR_CREATE_FILE, 0777);
+
+ if (fd_file == NULL) {
+ printf(
+ "testfile failed to create/open hidden file %s [%d, %d]\n",
+ pathname, PR_GetError(), PR_GetOSError());
+ return -1;
+ }
PR_Close(fd_file);
#elif defined(WINCE)
- DPRINTF(("Creating hidden test file %s\n",pathname));
+ DPRINTF(("Creating hidden test file %s\n",pathname));
MultiByteToWideChar(CP_ACP, 0, pathname, -1, wPathname, 256);
- hfile = CreateFile(wPathname, GENERIC_READ,
- FILE_SHARE_READ|FILE_SHARE_WRITE,
- NULL,
- CREATE_NEW,
- FILE_ATTRIBUTE_HIDDEN,
- NULL);
- if (hfile == INVALID_HANDLE_VALUE) {
- printf("testfile failed to create/open hidden file %s [0, %d]\n",
- pathname, GetLastError());
- return -1;
- }
- CloseHandle(hfile);
+ hfile = CreateFile(wPathname, GENERIC_READ,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ CREATE_NEW,
+ FILE_ATTRIBUTE_HIDDEN,
+ NULL);
+ if (hfile == INVALID_HANDLE_VALUE) {
+ printf("testfile failed to create/open hidden file %s [0, %d]\n",
+ pathname, GetLastError());
+ return -1;
+ }
+ CloseHandle(hfile);
#elif defined(XP_PC) && defined(WIN32)
- DPRINTF(("Creating hidden test file %s\n",pathname));
- hfile = CreateFile(pathname, GENERIC_READ,
- FILE_SHARE_READ|FILE_SHARE_WRITE,
- NULL,
- CREATE_NEW,
- FILE_ATTRIBUTE_HIDDEN,
- NULL);
- if (hfile == INVALID_HANDLE_VALUE) {
- printf("testfile failed to create/open hidden file %s [0, %d]\n",
- pathname, GetLastError());
- return -1;
- }
- CloseHandle(hfile);
+ DPRINTF(("Creating hidden test file %s\n",pathname));
+ hfile = CreateFile(pathname, GENERIC_READ,
+ FILE_SHARE_READ|FILE_SHARE_WRITE,
+ NULL,
+ CREATE_NEW,
+ FILE_ATTRIBUTE_HIDDEN,
+ NULL);
+ if (hfile == INVALID_HANDLE_VALUE) {
+ printf("testfile failed to create/open hidden file %s [0, %d]\n",
+ pathname, GetLastError());
+ return -1;
+ }
+ CloseHandle(hfile);
#elif defined(OS2)
- DPRINTF(("Creating hidden test file %s\n",pathname));
- fd_file = PR_Open(pathname, PR_RDWR | PR_CREATE_FILE, (int)FILE_HIDDEN);
-
- if (fd_file == NULL) {
- printf("testfile failed to create/open hidden file %s [%d, %d]\n",
- pathname, PR_GetError(), PR_GetOSError());
- return -1;
- }
- PR_Close(fd_file);
-#endif /* XP_UNIX */
-
-#endif /* XP_UNIX || (XP_PC && WIN32) */
-
-
- if (PR_FAILURE == PR_CloseDir(fd_dir))
- {
- printf(
- "testfile failed to close dirctory %s [%d, %d]\n",
- TEST_DIR, PR_GetError(), PR_GetOSError());
- return -1;
- }
- fd_dir = PR_OpenDir(TEST_DIR);
- if (fd_dir == NULL) {
- printf(
- "testfile failed to reopen dirctory %s [%d, %d]\n",
- TEST_DIR, PR_GetError(), PR_GetOSError());
- return -1;
- }
-
- /*
- * List all files, including hidden files
- */
- DPRINTF(("Listing all files in directory %s\n",TEST_DIR));
+ DPRINTF(("Creating hidden test file %s\n",pathname));
+ fd_file = PR_Open(pathname, PR_RDWR | PR_CREATE_FILE, (int)FILE_HIDDEN);
+
+ if (fd_file == NULL) {
+ printf("testfile failed to create/open hidden file %s [%d, %d]\n",
+ pathname, PR_GetError(), PR_GetOSError());
+ return -1;
+ }
+ PR_Close(fd_file);
+#endif /* XP_UNIX */
+
+#endif /* XP_UNIX || (XP_PC && WIN32) */
+
+
+ if (PR_FAILURE == PR_CloseDir(fd_dir))
+ {
+ printf(
+ "testfile failed to close dirctory %s [%d, %d]\n",
+ TEST_DIR, PR_GetError(), PR_GetOSError());
+ return -1;
+ }
+ fd_dir = PR_OpenDir(TEST_DIR);
+ if (fd_dir == NULL) {
+ printf(
+ "testfile failed to reopen dirctory %s [%d, %d]\n",
+ TEST_DIR, PR_GetError(), PR_GetOSError());
+ return -1;
+ }
+
+ /*
+ * List all files, including hidden files
+ */
+ DPRINTF(("Listing all files in directory %s\n",TEST_DIR));
#if defined(XP_UNIX) || (defined(XP_PC) && defined(WIN32)) || defined(XP_OS2)
- num_files = FILES_IN_DIR + 1;
+ num_files = FILES_IN_DIR + 1;
#else
- num_files = FILES_IN_DIR;
+ num_files = FILES_IN_DIR;
#endif
- while ((dirEntry = PR_ReadDir(fd_dir, PR_SKIP_BOTH)) != NULL) {
- num_files--;
- strcpy(pathname, TEST_DIR);
- strcat(pathname, "/");
- strcat(pathname, dirEntry->name);
- DPRINTF(("\t%s\n",dirEntry->name));
-
- if ((PR_GetFileInfo(pathname, &info)) < 0) {
- printf(
- "testfile failed to GetFileInfo file %s [%d, %d]\n",
- pathname, PR_GetError(), PR_GetOSError());
- return -1;
- }
-
- if (info.type != PR_FILE_FILE) {
- printf(
- "testfile incorrect fileinfo for file %s [%d, %d]\n",
- pathname, PR_GetError(), PR_GetOSError());
- return -1;
- }
- }
- if (num_files != 0)
- {
- printf(
- "testfile failed to find all files in directory %s [%d, %d]\n",
- TEST_DIR, PR_GetError(), PR_GetOSError());
- return -1;
- }
+ while ((dirEntry = PR_ReadDir(fd_dir, PR_SKIP_BOTH)) != NULL) {
+ num_files--;
+ strcpy(pathname, TEST_DIR);
+ strcat(pathname, "/");
+ strcat(pathname, dirEntry->name);
+ DPRINTF(("\t%s\n",dirEntry->name));
+
+ if ((PR_GetFileInfo(pathname, &info)) < 0) {
+ printf(
+ "testfile failed to GetFileInfo file %s [%d, %d]\n",
+ pathname, PR_GetError(), PR_GetOSError());
+ return -1;
+ }
+
+ if (info.type != PR_FILE_FILE) {
+ printf(
+ "testfile incorrect fileinfo for file %s [%d, %d]\n",
+ pathname, PR_GetError(), PR_GetOSError());
+ return -1;
+ }
+ }
+ if (num_files != 0)
+ {
+ printf(
+ "testfile failed to find all files in directory %s [%d, %d]\n",
+ TEST_DIR, PR_GetError(), PR_GetOSError());
+ return -1;
+ }
PR_CloseDir(fd_dir);
#if defined(XP_UNIX) || (defined(XP_PC) && defined(WIN32)) || defined(XP_OS2)
- /*
- * List all files, except hidden files
- */
-
- fd_dir = PR_OpenDir(TEST_DIR);
- if (fd_dir == NULL) {
- printf(
- "testfile failed to reopen dirctory %s [%d, %d]\n",
- TEST_DIR, PR_GetError(), PR_GetOSError());
- return -1;
- }
-
- DPRINTF(("Listing non-hidden files in directory %s\n",TEST_DIR));
- while ((dirEntry = PR_ReadDir(fd_dir, PR_SKIP_HIDDEN)) != NULL) {
- DPRINTF(("\t%s\n",dirEntry->name));
- if (!strcmp(HIDDEN_FILE_NAME, dirEntry->name)) {
- printf("testfile found hidden file %s\n", pathname);
- return -1;
- }
-
- }
- /*
- * Delete hidden file
- */
- strcpy(pathname, TEST_DIR);
- strcat(pathname, "/");
- strcat(pathname, HIDDEN_FILE_NAME);
- if (PR_FAILURE == PR_Delete(pathname)) {
- printf(
- "testfile failed to delete hidden file %s [%d, %d]\n",
- pathname, PR_GetError(), PR_GetOSError());
- return -1;
- }
+ /*
+ * List all files, except hidden files
+ */
+
+ fd_dir = PR_OpenDir(TEST_DIR);
+ if (fd_dir == NULL) {
+ printf(
+ "testfile failed to reopen dirctory %s [%d, %d]\n",
+ TEST_DIR, PR_GetError(), PR_GetOSError());
+ return -1;
+ }
+
+ DPRINTF(("Listing non-hidden files in directory %s\n",TEST_DIR));
+ while ((dirEntry = PR_ReadDir(fd_dir, PR_SKIP_HIDDEN)) != NULL) {
+ DPRINTF(("\t%s\n",dirEntry->name));
+ if (!strcmp(HIDDEN_FILE_NAME, dirEntry->name)) {
+ printf("testfile found hidden file %s\n", pathname);
+ return -1;
+ }
+
+ }
+ /*
+ * Delete hidden file
+ */
+ strcpy(pathname, TEST_DIR);
+ strcat(pathname, "/");
+ strcat(pathname, HIDDEN_FILE_NAME);
+ if (PR_FAILURE == PR_Delete(pathname)) {
+ printf(
+ "testfile failed to delete hidden file %s [%d, %d]\n",
+ pathname, PR_GetError(), PR_GetOSError());
+ return -1;
+ }
PR_CloseDir(fd_dir);
-#endif /* XP_UNIX || (XP_PC && WIN32) */
-
- strcpy(renamename, TEST_DIR);
- strcat(renamename, ".RENAMED");
- if (PR_FAILURE == PR_Rename(TEST_DIR, renamename)) {
- printf(
- "testfile failed to rename directory %s [%d, %d]\n",
- TEST_DIR, PR_GetError(), PR_GetOSError());
- return -1;
- }
-
- if (PR_FAILURE == PR_MkDir(TEST_DIR, 0777)) {
- printf(
- "testfile failed to recreate dir %s [%d, %d]\n",
- TEST_DIR, PR_GetError(), PR_GetOSError());
- return -1;
- }
- if (PR_SUCCESS == PR_Rename(renamename, TEST_DIR)) {
- printf(
- "testfile renamed directory to existing name %s\n",
- renamename);
- return -1;
- }
-
- if (PR_FAILURE == PR_RmDir(TEST_DIR)) {
- printf(
- "testfile failed to rmdir %s [%d, %d]\n",
- TEST_DIR, PR_GetError(), PR_GetOSError());
- return -1;
- }
-
- if (PR_FAILURE == PR_Rename(renamename, TEST_DIR)) {
- printf(
- "testfile failed to rename directory %s [%d, %d]\n",
- renamename, PR_GetError(), PR_GetOSError());
- return -1;
- }
- fd_dir = PR_OpenDir(TEST_DIR);
- if (fd_dir == NULL) {
- printf(
- "testfile failed to reopen directory %s [%d, %d]\n",
- TEST_DIR, PR_GetError(), PR_GetOSError());
- return -1;
- }
-
- strcpy(pathname, TEST_DIR);
- strcat(pathname, "/");
- strcat(pathname, FILE_NAME);
- path_len = strlen(pathname);
-
- for (i = 0; i < FILES_IN_DIR; i++) {
-
- sprintf(pathname + path_len,"%d%s",i,"");
-
- if (PR_FAILURE == PR_Delete(pathname)) {
- printf(
- "testfile failed to delete file %s [%d, %d]\n",
- pathname, PR_GetError(), PR_GetOSError());
- return -1;
- }
- }
+#endif /* XP_UNIX || (XP_PC && WIN32) */
+
+ strcpy(renamename, TEST_DIR);
+ strcat(renamename, ".RENAMED");
+ if (PR_FAILURE == PR_Rename(TEST_DIR, renamename)) {
+ printf(
+ "testfile failed to rename directory %s [%d, %d]\n",
+ TEST_DIR, PR_GetError(), PR_GetOSError());
+ return -1;
+ }
+
+ if (PR_FAILURE == PR_MkDir(TEST_DIR, 0777)) {
+ printf(
+ "testfile failed to recreate dir %s [%d, %d]\n",
+ TEST_DIR, PR_GetError(), PR_GetOSError());
+ return -1;
+ }
+ if (PR_SUCCESS == PR_Rename(renamename, TEST_DIR)) {
+ printf(
+ "testfile renamed directory to existing name %s\n",
+ renamename);
+ return -1;
+ }
+
+ if (PR_FAILURE == PR_RmDir(TEST_DIR)) {
+ printf(
+ "testfile failed to rmdir %s [%d, %d]\n",
+ TEST_DIR, PR_GetError(), PR_GetOSError());
+ return -1;
+ }
+
+ if (PR_FAILURE == PR_Rename(renamename, TEST_DIR)) {
+ printf(
+ "testfile failed to rename directory %s [%d, %d]\n",
+ renamename, PR_GetError(), PR_GetOSError());
+ return -1;
+ }
+ fd_dir = PR_OpenDir(TEST_DIR);
+ if (fd_dir == NULL) {
+ printf(
+ "testfile failed to reopen directory %s [%d, %d]\n",
+ TEST_DIR, PR_GetError(), PR_GetOSError());
+ return -1;
+ }
+
+ strcpy(pathname, TEST_DIR);
+ strcat(pathname, "/");
+ strcat(pathname, FILE_NAME);
+ path_len = strlen(pathname);
+
+ for (i = 0; i < FILES_IN_DIR; i++) {
+
+ sprintf(pathname + path_len,"%d%s",i,"");
+
+ if (PR_FAILURE == PR_Delete(pathname)) {
+ printf(
+ "testfile failed to delete file %s [%d, %d]\n",
+ pathname, PR_GetError(), PR_GetOSError());
+ return -1;
+ }
+ }
PR_CloseDir(fd_dir);
- if (PR_FAILURE == PR_RmDir(TEST_DIR)) {
- printf(
- "testfile failed to rmdir %s [%d, %d]\n",
- TEST_DIR, PR_GetError(), PR_GetOSError());
- return -1;
- }
- PR_EnterMonitor(tinfo->mon);
- tinfo->done = 1;
- PR_Notify(tinfo->mon);
- PR_ExitMonitor(tinfo->mon);
-
- return 0;
+ if (PR_FAILURE == PR_RmDir(TEST_DIR)) {
+ printf(
+ "testfile failed to rmdir %s [%d, %d]\n",
+ TEST_DIR, PR_GetError(), PR_GetOSError());
+ return -1;
+ }
+ PR_EnterMonitor(tinfo->mon);
+ tinfo->done = 1;
+ PR_Notify(tinfo->mon);
+ PR_ExitMonitor(tinfo->mon);
+
+ return 0;
}
/************************************************************************/
@@ -884,32 +889,32 @@ HANDLE hfile;
int main(int argc, char **argv)
{
#ifdef WIN32
- PRUint32 len;
+ PRUint32 len;
#endif
#if defined(XP_UNIX) || defined(XP_OS2)
- int opt;
- extern char *optarg;
- extern int optind;
+ int opt;
+ extern char *optarg;
+ extern int optind;
#endif
#if defined(XP_UNIX) || defined(XP_OS2)
- while ((opt = getopt(argc, argv, "d")) != EOF) {
- switch(opt) {
- case 'd':
- _debug_on = 1;
- break;
- default:
- break;
- }
+ while ((opt = getopt(argc, argv, "d")) != EOF) {
+ switch(opt) {
+ case 'd':
+ _debug_on = 1;
+ break;
+ default:
+ break;
}
+ }
#endif
- PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
+ PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
PR_STDIO_INIT();
- mon = PR_NewMonitor();
- if (mon == NULL) {
- printf("testfile: PR_NewMonitor failed\n");
- exit(2);
- }
+ mon = PR_NewMonitor();
+ if (mon == NULL) {
+ printf("testfile: PR_NewMonitor failed\n");
+ exit(2);
+ }
#ifdef WIN32
#ifdef WINCE
@@ -924,31 +929,31 @@ int main(int argc, char **argv)
}
}
#else
- len = GetTempPath(TMPDIR_LEN, testdir);
+ len = GetTempPath(TMPDIR_LEN, testdir);
#endif /* WINCE */
- if ((len > 0) && (len < (TMPDIR_LEN - 6))) {
- /*
- * enough space for prdir
- */
- strcpy((testdir + len),"prdir");
- TEST_DIR = testdir;
- printf("TEST_DIR = %s\n",TEST_DIR);
- }
+ if ((len > 0) && (len < (TMPDIR_LEN - 6))) {
+ /*
+ * enough space for prdir
+ */
+ strcpy((testdir + len),"prdir");
+ TEST_DIR = testdir;
+ printf("TEST_DIR = %s\n",TEST_DIR);
+ }
#endif /* WIN32 */
- if (FileTest() < 0) {
- printf("File Test failed\n");
- exit(2);
- }
- printf("File Test passed\n");
- if ((RunDirTest() < 0) || dirtest_failed) {
- printf("Dir Test failed\n");
- exit(2);
- }
- printf("Dir Test passed\n");
-
- PR_DestroyMonitor(mon);
- PR_Cleanup();
+ if (FileTest() < 0) {
+ printf("File Test failed\n");
+ exit(2);
+ }
+ printf("File Test passed\n");
+ if ((RunDirTest() < 0) || dirtest_failed) {
+ printf("Dir Test failed\n");
+ exit(2);
+ }
+ printf("Dir Test passed\n");
+
+ PR_DestroyMonitor(mon);
+ PR_Cleanup();
return 0;
}
diff --git a/pr/tests/threads.c b/pr/tests/threads.c
index 09b5963a..4a28dc6e 100644
--- a/pr/tests/threads.c
+++ b/pr/tests/threads.c
@@ -42,7 +42,7 @@ DumbThread(void *arg)
if (!thr) {
if (debug_mode) {
printf("Could not create really dumb thread (%d, %d)!\n",
- PR_GetError(), PR_GetOSError());
+ PR_GetError(), PR_GetOSError());
}
passed = PR_FALSE;
} else {
@@ -74,7 +74,7 @@ static void CreateThreads(PRThreadScope scope1, PRThreadScope scope2)
if (!thr) {
if (debug_mode) {
printf("Could not create dumb thread (%d, %d)!\n",
- PR_GetError(), PR_GetOSError());
+ PR_GetError(), PR_GetOSError());
}
passed = PR_FALSE;
alive--;
@@ -90,7 +90,7 @@ static void CreateThreads(PRThreadScope scope1, PRThreadScope scope2)
}
PR_ExitMonitor(mon);
- PR_DestroyMonitor(mon);
+ PR_DestroyMonitor(mon);
}
static void CreateThreadsUU(void)
@@ -139,35 +139,41 @@ int main(int argc, char **argv)
PR_Init(PR_USER_THREAD, PR_PRIORITY_HIGH, 0);
{
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "dc:i:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "dc: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 'd': /* debug mode */
- debug_mode = PR_TRUE;
- break;
- case 'c': /* loop counter */
- count = atoi(opt->value);
- break;
- case 'i': /* loop counter */
- iterations = atoi(opt->value);
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = PR_TRUE;
+ break;
+ case 'c': /* loop counter */
+ count = atoi(opt->value);
+ break;
+ case 'i': /* loop counter */
+ iterations = atoi(opt->value);
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
}
- if (0 == count) count = 50;
- if (0 == iterations) iterations = 10;
+ if (0 == count) {
+ count = 50;
+ }
+ if (0 == iterations) {
+ iterations = 10;
+ }
if (debug_mode)
{
- printf("\
+ printf("\
** Tests lots of thread creations. \n\
** Create %ld native threads %ld times. \n\
** Create %ld user threads %ld times \n", iterations,count,iterations,count);
@@ -180,7 +186,9 @@ int main(int argc, char **argv)
Measure(CreateThreadsKK, "Create native/native threads");
}
- if (debug_mode) printf("\nNow switch to recycling threads \n\n");
+ if (debug_mode) {
+ printf("\nNow switch to recycling threads \n\n");
+ }
PR_SetThreadRecycleMode(1);
for (index=0; index<iterations; index++) {
diff --git a/pr/tests/thrpool_client.c b/pr/tests/thrpool_client.c
index 1ad3527a..2c01a3c5 100644
--- a/pr/tests/thrpool_client.c
+++ b/pr/tests/thrpool_client.c
@@ -43,7 +43,7 @@ static char *program_name = NULL;
#define BUF_DATA_SIZE (2 * 1024)
#define TCP_MESG_SIZE 1024
-#define NUM_TCP_CLIENTS 10 /* for a listen queue depth of 5 */
+#define NUM_TCP_CLIENTS 10 /* for a listen queue depth of 5 */
#define NUM_TCP_CONNECTIONS_PER_CLIENT 10
#define NUM_TCP_MESGS_PER_CONNECTION 10
@@ -79,18 +79,18 @@ readn(PRFileDesc *sockfd, char *buf, int len)
int rem;
int bytes;
int offset = 0;
- PRIntervalTime timeout = PR_INTERVAL_NO_TIMEOUT;
+ PRIntervalTime timeout = PR_INTERVAL_NO_TIMEOUT;
for (rem=len; rem; offset += bytes, rem -= bytes) {
DPRINTF(("thread = 0x%lx: calling PR_Recv, bytes = %d\n",
- PR_GetCurrentThread(), rem));
+ PR_GetCurrentThread(), rem));
bytes = PR_Recv(sockfd, buf + offset, rem, 0,
- timeout);
+ timeout);
DPRINTF(("thread = 0x%lx: returning from PR_Recv, bytes = %d\n",
- PR_GetCurrentThread(), bytes));
+ PR_GetCurrentThread(), bytes));
if (bytes < 0) {
- return -1;
- }
+ return -1;
+ }
}
return len;
}
@@ -108,13 +108,14 @@ writen(PRFileDesc *sockfd, char *buf, int len)
for (rem=len; rem; offset += bytes, rem -= bytes) {
DPRINTF(("thread = 0x%lx: calling PR_Send, bytes = %d\n",
- PR_GetCurrentThread(), rem));
+ PR_GetCurrentThread(), rem));
bytes = PR_Send(sockfd, buf + offset, rem, 0,
- PR_INTERVAL_NO_TIMEOUT);
+ PR_INTERVAL_NO_TIMEOUT);
DPRINTF(("thread = 0x%lx: returning from PR_Send, bytes = %d\n",
- PR_GetCurrentThread(), bytes));
- if (bytes <= 0)
+ PR_GetCurrentThread(), bytes));
+ if (bytes <= 0) {
return -1;
+ }
}
return len;
}
@@ -163,9 +164,9 @@ TCP_Client(void *arg)
}
DPRINTF(("TCP client connecting to server:%d\n", server_port));
- if (PR_Connect(sockfd, &netaddr,PR_INTERVAL_NO_TIMEOUT) < 0){
- fprintf(stderr, "PR_Connect failed: (%ld, %ld)\n",
- PR_GetError(), PR_GetOSError());
+ if (PR_Connect(sockfd, &netaddr,PR_INTERVAL_NO_TIMEOUT) < 0) {
+ fprintf(stderr, "PR_Connect failed: (%ld, %ld)\n",
+ PR_GetError(), PR_GetOSError());
failed_already=1;
return;
}
@@ -182,10 +183,10 @@ TCP_Client(void *arg)
failed_already=1;
return;
}
- /*
+ /*
DPRINTF(("TCP Client [0x%lx]: out_buf = 0x%lx out_buf[0] = 0x%lx\n",
PR_GetCurrentThread(), out_buf, (*((int *) out_buf->data))));
- */
+ */
if (readn(sockfd, in_buf->data, bytes) < bytes) {
fprintf(stderr,"%s: ERROR - TCP_Client:readn\n", program_name);
failed_already=1;
@@ -243,7 +244,7 @@ TCP_Socket_Client_Server_Test(void)
PRMonitor *mon2;
PRInt32 datalen;
PRInt32 connections = 0;
- PRThread *thr;
+ PRThread *thr;
datalen = tcp_mesg_size;
connections = 0;
@@ -271,16 +272,16 @@ TCP_Socket_Client_Server_Test(void)
cparamp->exit_counter = &connections;
cparamp->datalen = datalen;
for (i = 0; i < num_tcp_clients; i++) {
- thr = PR_CreateThread(PR_USER_THREAD, TCP_Client, (void *)cparamp,
- PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0);
+ thr = PR_CreateThread(PR_USER_THREAD, TCP_Client, (void *)cparamp,
+ PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0);
if (NULL == thr) {
fprintf(stderr,"%s: PR_CreateThread failed\n", program_name);
failed_already=1;
return -1;
}
- PR_EnterMonitor(mon2);
+ PR_EnterMonitor(mon2);
connections++;
- PR_ExitMonitor(mon2);
+ PR_ExitMonitor(mon2);
DPRINTF(("Created TCP client = 0x%lx\n", thr));
}
/* Wait for client jobs to exit */
@@ -292,9 +293,9 @@ TCP_Socket_Client_Server_Test(void)
PR_ExitMonitor(mon2);
printf("%30s","TCP_Socket_Client_Server_Test:");
printf("%2ld Server %2ld Clients %2ld connections_per_client\n",1l,
- num_tcp_clients, num_tcp_connections_per_client);
+ num_tcp_clients, num_tcp_connections_per_client);
printf("%30s %2ld messages_per_connection %4ld bytes_per_message\n",":",
- num_tcp_mesgs_per_connection, tcp_mesg_size);
+ num_tcp_mesgs_per_connection, tcp_mesg_size);
PR_DELETE(cparamp);
return 0;
@@ -309,22 +310,24 @@ int main(int argc, char **argv)
*/
PLOptStatus os;
PLOptState *opt;
- program_name = argv[0];
+ program_name = argv[0];
opt = PL_CreateOptState(argc, argv, "dp:");
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_on = 1;
- break;
- case 'p':
- server_port = atoi(opt->value);
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ _debug_on = 1;
+ break;
+ case 'p':
+ server_port = atoi(opt->value);
+ break;
+ default:
+ break;
}
}
PL_DestroyOptState(opt);
@@ -334,11 +337,13 @@ int main(int argc, char **argv)
PR_SetConcurrency(4);
- TCP_Socket_Client_Server_Test();
+ TCP_Socket_Client_Server_Test();
PR_Cleanup();
- if (failed_already)
- return 1;
- else
- return 0;
+ if (failed_already) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
}
diff --git a/pr/tests/thrpool_server.c b/pr/tests/thrpool_server.c
index ce2acb41..ecae117a 100644
--- a/pr/tests/thrpool_server.c
+++ b/pr/tests/thrpool_server.c
@@ -51,13 +51,13 @@ static void serve_client_write(void *arg);
#define BUF_DATA_SIZE (2 * 1024)
#define TCP_MESG_SIZE 1024
-#define NUM_TCP_CLIENTS 10 /* for a listen queue depth of 5 */
+#define NUM_TCP_CLIENTS 10 /* for a listen queue depth of 5 */
#define NUM_TCP_CONNECTIONS_PER_CLIENT 10
#define NUM_TCP_MESGS_PER_CONNECTION 10
-#define TCP_SERVER_PORT 10000
-#define SERVER_MAX_BIND_COUNT 100
+#define TCP_SERVER_PORT 10000
+#define SERVER_MAX_BIND_COUNT 100
#ifdef WINCE
char *getcwd(char *buf, size_t size)
@@ -85,12 +85,12 @@ typedef struct buffer {
typedef struct Server_Param {
PRJobIoDesc iod; /* socket to read from/write to */
- PRInt32 datalen; /* bytes of data transfered in each read/write */
- PRNetAddr netaddr;
- PRMonitor *exit_mon; /* monitor to signal on exit */
- PRInt32 *job_counterp; /* counter to decrement, before exit */
- PRInt32 conn_counter; /* counter to decrement, before exit */
- PRThreadPool *tp;
+ PRInt32 datalen; /* bytes of data transfered in each read/write */
+ PRNetAddr netaddr;
+ PRMonitor *exit_mon; /* monitor to signal on exit */
+ PRInt32 *job_counterp; /* counter to decrement, before exit */
+ PRInt32 conn_counter; /* counter to decrement, before exit */
+ PRThreadPool *tp;
} Server_Param;
typedef struct Serve_Client_Param {
@@ -98,60 +98,60 @@ typedef struct Serve_Client_Param {
PRInt32 datalen; /* bytes of data transfered in each read/write */
PRMonitor *exit_mon; /* monitor to signal on exit */
PRInt32 *job_counterp; /* counter to decrement, before exit */
- PRThreadPool *tp;
+ PRThreadPool *tp;
} Serve_Client_Param;
typedef struct Session {
PRJobIoDesc iod; /* socket to read from/write to */
- buffer *in_buf;
- PRInt32 bytes;
- PRInt32 msg_num;
- PRInt32 bytes_read;
+ buffer *in_buf;
+ PRInt32 bytes;
+ PRInt32 msg_num;
+ PRInt32 bytes_read;
PRMonitor *exit_mon; /* monitor to signal on exit */
PRInt32 *job_counterp; /* counter to decrement, before exit */
- PRThreadPool *tp;
+ PRThreadPool *tp;
} Session;
static void
serve_client_read(void *arg)
{
- Session *sp = (Session *) arg;
+ Session *sp = (Session *) arg;
int rem;
int bytes;
int offset;
- PRFileDesc *sockfd;
- char *buf;
- PRJob *jobp;
+ PRFileDesc *sockfd;
+ char *buf;
+ PRJob *jobp;
- PRIntervalTime timeout = PR_INTERVAL_NO_TIMEOUT;
+ PRIntervalTime timeout = PR_INTERVAL_NO_TIMEOUT;
- sockfd = sp->iod.socket;
- buf = sp->in_buf->data;
+ sockfd = sp->iod.socket;
+ buf = sp->in_buf->data;
PR_ASSERT(sp->msg_num < num_tcp_mesgs_per_connection);
- PR_ASSERT(sp->bytes_read < sp->bytes);
-
- offset = sp->bytes_read;
- rem = sp->bytes - offset;
- bytes = PR_Recv(sockfd, buf + offset, rem, 0, timeout);
- if (bytes < 0) {
- return;
- }
- sp->bytes_read += bytes;
- sp->iod.timeout = PR_SecondsToInterval(60);
- if (sp->bytes_read < sp->bytes) {
- jobp = PR_QueueJob_Read(sp->tp, &sp->iod, serve_client_read, sp,
- PR_FALSE);
- PR_ASSERT(NULL != jobp);
- return;
- }
- PR_ASSERT(sp->bytes_read == sp->bytes);
- DPRINTF(("serve_client: read complete, msg(%d) \n", sp->msg_num));
-
- sp->iod.timeout = PR_SecondsToInterval(60);
- jobp = PR_QueueJob_Write(sp->tp, &sp->iod, serve_client_write, sp,
- PR_FALSE);
- PR_ASSERT(NULL != jobp);
+ PR_ASSERT(sp->bytes_read < sp->bytes);
+
+ offset = sp->bytes_read;
+ rem = sp->bytes - offset;
+ bytes = PR_Recv(sockfd, buf + offset, rem, 0, timeout);
+ if (bytes < 0) {
+ return;
+ }
+ sp->bytes_read += bytes;
+ sp->iod.timeout = PR_SecondsToInterval(60);
+ if (sp->bytes_read < sp->bytes) {
+ jobp = PR_QueueJob_Read(sp->tp, &sp->iod, serve_client_read, sp,
+ PR_FALSE);
+ PR_ASSERT(NULL != jobp);
+ return;
+ }
+ PR_ASSERT(sp->bytes_read == sp->bytes);
+ DPRINTF(("serve_client: read complete, msg(%d) \n", sp->msg_num));
+
+ sp->iod.timeout = PR_SecondsToInterval(60);
+ jobp = PR_QueueJob_Write(sp->tp, &sp->iod, serve_client_write, sp,
+ PR_FALSE);
+ PR_ASSERT(NULL != jobp);
return;
}
@@ -159,35 +159,35 @@ serve_client_read(void *arg)
static void
serve_client_write(void *arg)
{
- Session *sp = (Session *) arg;
+ Session *sp = (Session *) arg;
int bytes;
- PRFileDesc *sockfd;
- char *buf;
- PRJob *jobp;
+ PRFileDesc *sockfd;
+ char *buf;
+ PRJob *jobp;
- sockfd = sp->iod.socket;
- buf = sp->in_buf->data;
+ sockfd = sp->iod.socket;
+ buf = sp->in_buf->data;
PR_ASSERT(sp->msg_num < num_tcp_mesgs_per_connection);
- bytes = PR_Send(sockfd, buf, sp->bytes, 0, PR_INTERVAL_NO_TIMEOUT);
- PR_ASSERT(bytes == sp->bytes);
+ bytes = PR_Send(sockfd, buf, sp->bytes, 0, PR_INTERVAL_NO_TIMEOUT);
+ PR_ASSERT(bytes == sp->bytes);
- if (bytes < 0) {
- return;
- }
- DPRINTF(("serve_client: write complete, msg(%d) \n", sp->msg_num));
+ if (bytes < 0) {
+ return;
+ }
+ DPRINTF(("serve_client: write complete, msg(%d) \n", sp->msg_num));
sp->msg_num++;
if (sp->msg_num < num_tcp_mesgs_per_connection) {
- sp->bytes_read = 0;
- sp->iod.timeout = PR_SecondsToInterval(60);
- jobp = PR_QueueJob_Read(sp->tp, &sp->iod, serve_client_read, sp,
- PR_FALSE);
- PR_ASSERT(NULL != jobp);
- return;
- }
-
- DPRINTF(("serve_client: read/write complete, msg(%d) \n", sp->msg_num));
+ sp->bytes_read = 0;
+ sp->iod.timeout = PR_SecondsToInterval(60);
+ jobp = PR_QueueJob_Read(sp->tp, &sp->iod, serve_client_read, sp,
+ PR_FALSE);
+ PR_ASSERT(NULL != jobp);
+ return;
+ }
+
+ DPRINTF(("serve_client: read/write complete, msg(%d) \n", sp->msg_num));
if (PR_Shutdown(sockfd, PR_SHUTDOWN_BOTH) < 0) {
fprintf(stderr,"%s: ERROR - PR_Shutdown\n", program_name);
}
@@ -215,11 +215,11 @@ Serve_Client(void *arg)
{
Serve_Client_Param *scp = (Serve_Client_Param *) arg;
buffer *in_buf;
- Session *sp;
- PRJob *jobp;
+ Session *sp;
+ PRJob *jobp;
- sp = PR_NEW(Session);
- sp->iod = scp->iod;
+ sp = PR_NEW(Session);
+ sp->iod = scp->iod;
in_buf = PR_NEW(buffer);
if (in_buf == NULL) {
@@ -228,19 +228,19 @@ Serve_Client(void *arg)
return;
}
- sp->in_buf = in_buf;
- sp->bytes = scp->datalen;
- sp->msg_num = 0;
- sp->bytes_read = 0;
- sp->tp = scp->tp;
- sp->exit_mon = scp->exit_mon;
+ sp->in_buf = in_buf;
+ sp->bytes = scp->datalen;
+ sp->msg_num = 0;
+ sp->bytes_read = 0;
+ sp->tp = scp->tp;
+ sp->exit_mon = scp->exit_mon;
sp->job_counterp = scp->job_counterp;
- sp->iod.timeout = PR_SecondsToInterval(60);
- jobp = PR_QueueJob_Read(sp->tp, &sp->iod, serve_client_read, sp,
- PR_FALSE);
- PR_ASSERT(NULL != jobp);
- PR_DELETE(scp);
+ sp->iod.timeout = PR_SecondsToInterval(60);
+ jobp = PR_QueueJob_Read(sp->tp, &sp->iod, serve_client_read, sp,
+ PR_FALSE);
+ PR_ASSERT(NULL != jobp);
+ PR_DELETE(scp);
}
static void
@@ -249,32 +249,32 @@ print_stats(void *arg)
Server_Param *sp = (Server_Param *) arg;
PRThreadPool *tp = sp->tp;
PRInt32 counter;
- PRJob *jobp;
+ PRJob *jobp;
- PR_EnterMonitor(sp->exit_mon);
- counter = (*sp->job_counterp);
- PR_ExitMonitor(sp->exit_mon);
+ PR_EnterMonitor(sp->exit_mon);
+ counter = (*sp->job_counterp);
+ PR_ExitMonitor(sp->exit_mon);
- printf("PRINT_STATS: #client connections = %d\n",counter);
+ printf("PRINT_STATS: #client connections = %d\n",counter);
- jobp = PR_QueueJob_Timer(tp, PR_MillisecondsToInterval(500),
- print_stats, sp, PR_FALSE);
+ jobp = PR_QueueJob_Timer(tp, PR_MillisecondsToInterval(500),
+ print_stats, sp, PR_FALSE);
- PR_ASSERT(NULL != jobp);
+ PR_ASSERT(NULL != jobp);
}
static int job_counter = 0;
/*
* TCP Server
* Server binds an address to a socket, starts a client process and
- * listens for incoming connections.
+ * listens for incoming connections.
* Each client connects to the server and sends a chunk of data
* Starts a Serve_Client job for each incoming connection, to read
* the data from the client and send it back to the client, unmodified.
* Each client checks that data received from server is same as the
* data it sent to the server.
- * Finally, the threadpool is shutdown
+ * Finally, the threadpool is shutdown
*/
static void PR_CALLBACK
TCP_Server(void *arg)
@@ -283,10 +283,10 @@ TCP_Server(void *arg)
Server_Param *sp;
PRFileDesc *sockfd;
PRNetAddr netaddr;
- PRMonitor *sc_mon;
- PRJob *jobp;
- int i;
- PRStatus rval;
+ PRMonitor *sc_mon;
+ PRJob *jobp;
+ int i;
+ PRStatus rval;
/*
* Create a tcp socket
@@ -295,7 +295,7 @@ TCP_Server(void *arg)
fprintf(stderr,"%s: PR_NewTCPSocket failed\n", program_name);
return;
}
- memset(&netaddr, 0 , sizeof(netaddr));
+ memset(&netaddr, 0, sizeof(netaddr));
netaddr.inet.family = PR_AF_INET;
netaddr.inet.port = PR_htons(TCP_SERVER_PORT);
netaddr.inet.ip = PR_htonl(PR_INADDR_ANY);
@@ -303,12 +303,13 @@ TCP_Server(void *arg)
* try a few times to bind server's address, if addresses are in
* use
*/
- i = 0;
+ i = 0;
while (PR_Bind(sockfd, &netaddr) < 0) {
if (PR_GetError() == PR_ADDRESS_IN_USE_ERROR) {
netaddr.inet.port += 2;
- if (i++ < SERVER_MAX_BIND_COUNT)
+ if (i++ < SERVER_MAX_BIND_COUNT) {
continue;
+ }
}
fprintf(stderr,"%s: ERROR - PR_Bind failed\n", program_name);
perror("PR_Bind");
@@ -329,39 +330,39 @@ TCP_Server(void *arg)
}
DPRINTF((
- "TCP_Server: PR_BIND netaddr.inet.ip = 0x%lx, netaddr.inet.port = %d\n",
- netaddr.inet.ip, netaddr.inet.port));
-
- sp = PR_NEW(Server_Param);
- if (sp == NULL) {
- fprintf(stderr,"%s: PR_NEW failed\n", program_name);
- failed_already=1;
- return;
- }
- sp->iod.socket = sockfd;
- sp->iod.timeout = PR_SecondsToInterval(60);
- sp->datalen = tcp_mesg_size;
- sp->exit_mon = sc_mon;
- sp->job_counterp = &job_counter;
- sp->conn_counter = 0;
- sp->tp = tp;
- sp->netaddr = netaddr;
-
- /* create and cancel an io job */
- jobp = PR_QueueJob_Accept(tp, &sp->iod, TCP_Server_Accept, sp,
- PR_FALSE);
- PR_ASSERT(NULL != jobp);
- rval = PR_CancelJob(jobp);
- PR_ASSERT(PR_SUCCESS == rval);
-
- /*
- * create the client process
- */
- {
+ "TCP_Server: PR_BIND netaddr.inet.ip = 0x%lx, netaddr.inet.port = %d\n",
+ netaddr.inet.ip, netaddr.inet.port));
+
+ sp = PR_NEW(Server_Param);
+ if (sp == NULL) {
+ fprintf(stderr,"%s: PR_NEW failed\n", program_name);
+ failed_already=1;
+ return;
+ }
+ sp->iod.socket = sockfd;
+ sp->iod.timeout = PR_SecondsToInterval(60);
+ sp->datalen = tcp_mesg_size;
+ sp->exit_mon = sc_mon;
+ sp->job_counterp = &job_counter;
+ sp->conn_counter = 0;
+ sp->tp = tp;
+ sp->netaddr = netaddr;
+
+ /* create and cancel an io job */
+ jobp = PR_QueueJob_Accept(tp, &sp->iod, TCP_Server_Accept, sp,
+ PR_FALSE);
+ PR_ASSERT(NULL != jobp);
+ rval = PR_CancelJob(jobp);
+ PR_ASSERT(PR_SUCCESS == rval);
+
+ /*
+ * create the client process
+ */
+ {
#define MAX_ARGS 4
- char *argv[MAX_ARGS + 1];
- int index = 0;
- char port[32];
+ char *argv[MAX_ARGS + 1];
+ int index = 0;
+ char port[32];
char path[1024 + sizeof("/thrpool_client")];
getcwd(path, sizeof(path));
@@ -371,7 +372,7 @@ TCP_Server(void *arg)
(void)strcat(path, ".exe");
#endif
argv[index++] = path;
- sprintf(port,"%d",PR_ntohs(netaddr.inet.port));
+ sprintf(port,"%d",PR_ntohs(netaddr.inet.port));
if (_debug_on)
{
argv[index++] = "-d";
@@ -381,18 +382,18 @@ TCP_Server(void *arg)
} else {
argv[index++] = "-p";
argv[index++] = port;
- argv[index++] = NULL;
- }
- PR_ASSERT(MAX_ARGS >= (index - 1));
+ argv[index++] = NULL;
+ }
+ PR_ASSERT(MAX_ARGS >= (index - 1));
DPRINTF(("creating client process %s ...\n", path));
if (PR_FAILURE == PR_CreateProcessDetached(path, argv, NULL, NULL)) {
- fprintf(stderr,
- "thrpool_server: ERROR - PR_CreateProcessDetached failed\n");
- failed_already=1;
- return;
- }
- }
+ fprintf(stderr,
+ "thrpool_server: ERROR - PR_CreateProcessDetached failed\n");
+ failed_already=1;
+ return;
+ }
+ }
sc_mon = PR_NewMonitor();
if (sc_mon == NULL) {
@@ -401,28 +402,28 @@ TCP_Server(void *arg)
return;
}
- sp->iod.socket = sockfd;
- sp->iod.timeout = PR_SecondsToInterval(60);
- sp->datalen = tcp_mesg_size;
- sp->exit_mon = sc_mon;
- sp->job_counterp = &job_counter;
- sp->conn_counter = 0;
- sp->tp = tp;
- sp->netaddr = netaddr;
-
- /* create and cancel a timer job */
- jobp = PR_QueueJob_Timer(tp, PR_MillisecondsToInterval(5000),
- print_stats, sp, PR_FALSE);
- PR_ASSERT(NULL != jobp);
- rval = PR_CancelJob(jobp);
- PR_ASSERT(PR_SUCCESS == rval);
+ sp->iod.socket = sockfd;
+ sp->iod.timeout = PR_SecondsToInterval(60);
+ sp->datalen = tcp_mesg_size;
+ sp->exit_mon = sc_mon;
+ sp->job_counterp = &job_counter;
+ sp->conn_counter = 0;
+ sp->tp = tp;
+ sp->netaddr = netaddr;
+
+ /* create and cancel a timer job */
+ jobp = PR_QueueJob_Timer(tp, PR_MillisecondsToInterval(5000),
+ print_stats, sp, PR_FALSE);
+ PR_ASSERT(NULL != jobp);
+ rval = PR_CancelJob(jobp);
+ PR_ASSERT(PR_SUCCESS == rval);
DPRINTF(("TCP_Server: Accepting connections \n"));
- jobp = PR_QueueJob_Accept(tp, &sp->iod, TCP_Server_Accept, sp,
- PR_FALSE);
- PR_ASSERT(NULL != jobp);
- return;
+ jobp = PR_QueueJob_Accept(tp, &sp->iod, TCP_Server_Accept, sp,
+ PR_FALSE);
+ PR_ASSERT(NULL != jobp);
+ return;
}
static void
@@ -431,97 +432,97 @@ TCP_Server_Accept(void *arg)
Server_Param *sp = (Server_Param *) arg;
PRThreadPool *tp = sp->tp;
Serve_Client_Param *scp;
- PRFileDesc *newsockfd;
- PRJob *jobp;
-
- if ((newsockfd = PR_Accept(sp->iod.socket, &sp->netaddr,
- PR_INTERVAL_NO_TIMEOUT)) == NULL) {
- fprintf(stderr,"%s: ERROR - PR_Accept failed\n", program_name);
- failed_already=1;
- goto exit;
- }
- scp = PR_NEW(Serve_Client_Param);
- if (scp == NULL) {
- fprintf(stderr,"%s: PR_NEW failed\n", program_name);
- failed_already=1;
- goto exit;
- }
-
- /*
- * Start a Serve_Client job for each incoming connection
- */
- scp->iod.socket = newsockfd;
- scp->iod.timeout = PR_SecondsToInterval(60);
- scp->datalen = tcp_mesg_size;
- scp->exit_mon = sp->exit_mon;
- scp->job_counterp = sp->job_counterp;
- scp->tp = sp->tp;
-
- PR_EnterMonitor(sp->exit_mon);
- (*sp->job_counterp)++;
- PR_ExitMonitor(sp->exit_mon);
- jobp = PR_QueueJob(tp, Serve_Client, scp,
- PR_FALSE);
-
- PR_ASSERT(NULL != jobp);
- DPRINTF(("TCP_Server: Created Serve_Client = 0x%lx\n", jobp));
-
- /*
- * single-threaded update; no lock needed
- */
+ PRFileDesc *newsockfd;
+ PRJob *jobp;
+
+ if ((newsockfd = PR_Accept(sp->iod.socket, &sp->netaddr,
+ PR_INTERVAL_NO_TIMEOUT)) == NULL) {
+ fprintf(stderr,"%s: ERROR - PR_Accept failed\n", program_name);
+ failed_already=1;
+ goto exit;
+ }
+ scp = PR_NEW(Serve_Client_Param);
+ if (scp == NULL) {
+ fprintf(stderr,"%s: PR_NEW failed\n", program_name);
+ failed_already=1;
+ goto exit;
+ }
+
+ /*
+ * Start a Serve_Client job for each incoming connection
+ */
+ scp->iod.socket = newsockfd;
+ scp->iod.timeout = PR_SecondsToInterval(60);
+ scp->datalen = tcp_mesg_size;
+ scp->exit_mon = sp->exit_mon;
+ scp->job_counterp = sp->job_counterp;
+ scp->tp = sp->tp;
+
+ PR_EnterMonitor(sp->exit_mon);
+ (*sp->job_counterp)++;
+ PR_ExitMonitor(sp->exit_mon);
+ jobp = PR_QueueJob(tp, Serve_Client, scp,
+ PR_FALSE);
+
+ PR_ASSERT(NULL != jobp);
+ DPRINTF(("TCP_Server: Created Serve_Client = 0x%lx\n", jobp));
+
+ /*
+ * single-threaded update; no lock needed
+ */
sp->conn_counter++;
if (sp->conn_counter <
- (num_tcp_clients * num_tcp_connections_per_client)) {
- jobp = PR_QueueJob_Accept(tp, &sp->iod, TCP_Server_Accept, sp,
- PR_FALSE);
- PR_ASSERT(NULL != jobp);
- return;
- }
- jobp = PR_QueueJob_Timer(tp, PR_MillisecondsToInterval(500),
- print_stats, sp, PR_FALSE);
-
- PR_ASSERT(NULL != jobp);
- DPRINTF(("TCP_Server: Created print_stats timer job = 0x%lx\n", jobp));
+ (num_tcp_clients * num_tcp_connections_per_client)) {
+ jobp = PR_QueueJob_Accept(tp, &sp->iod, TCP_Server_Accept, sp,
+ PR_FALSE);
+ PR_ASSERT(NULL != jobp);
+ return;
+ }
+ jobp = PR_QueueJob_Timer(tp, PR_MillisecondsToInterval(500),
+ print_stats, sp, PR_FALSE);
+
+ PR_ASSERT(NULL != jobp);
+ DPRINTF(("TCP_Server: Created print_stats timer job = 0x%lx\n", jobp));
exit:
- PR_EnterMonitor(sp->exit_mon);
+ PR_EnterMonitor(sp->exit_mon);
/* Wait for server jobs to finish */
while (0 != *sp->job_counterp) {
PR_Wait(sp->exit_mon, PR_INTERVAL_NO_TIMEOUT);
DPRINTF(("TCP_Server: conn_counter = %d\n",
- *sp->job_counterp));
+ *sp->job_counterp));
}
PR_ExitMonitor(sp->exit_mon);
if (sp->iod.socket) {
PR_Close(sp->iod.socket);
}
- PR_DestroyMonitor(sp->exit_mon);
+ PR_DestroyMonitor(sp->exit_mon);
printf("%30s","TCP_Socket_Client_Server_Test:");
printf("%2ld Server %2ld Clients %2ld connections_per_client\n",1l,
- num_tcp_clients, num_tcp_connections_per_client);
+ num_tcp_clients, num_tcp_connections_per_client);
printf("%30s %2ld messages_per_connection %4ld bytes_per_message\n",":",
- num_tcp_mesgs_per_connection, tcp_mesg_size);
+ num_tcp_mesgs_per_connection, tcp_mesg_size);
- DPRINTF(("%s: calling PR_ShutdownThreadPool\n", program_name));
- PR_ShutdownThreadPool(sp->tp);
- PR_DELETE(sp);
+ DPRINTF(("%s: calling PR_ShutdownThreadPool\n", program_name));
+ PR_ShutdownThreadPool(sp->tp);
+ PR_DELETE(sp);
}
/************************************************************************/
-#define DEFAULT_INITIAL_THREADS 4
-#define DEFAULT_MAX_THREADS 100
-#define DEFAULT_STACKSIZE (512 * 1024)
+#define DEFAULT_INITIAL_THREADS 4
+#define DEFAULT_MAX_THREADS 100
+#define DEFAULT_STACKSIZE (512 * 1024)
int main(int argc, char **argv)
{
- PRInt32 initial_threads = DEFAULT_INITIAL_THREADS;
- PRInt32 max_threads = DEFAULT_MAX_THREADS;
- PRInt32 stacksize = DEFAULT_STACKSIZE;
- PRThreadPool *tp = NULL;
- PRStatus rv;
- PRJob *jobp;
+ PRInt32 initial_threads = DEFAULT_INITIAL_THREADS;
+ PRInt32 max_threads = DEFAULT_MAX_THREADS;
+ PRInt32 stacksize = DEFAULT_STACKSIZE;
+ PRThreadPool *tp = NULL;
+ PRStatus rv;
+ PRJob *jobp;
/*
* -d debug mode
@@ -529,18 +530,20 @@ int main(int argc, char **argv)
PLOptStatus os;
PLOptState *opt;
- program_name = argv[0];
+ program_name = argv[0];
opt = PL_CreateOptState(argc, argv, "d");
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_on = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ _debug_on = 1;
+ break;
+ default:
+ break;
}
}
PL_DestroyOptState(opt);
@@ -550,23 +553,27 @@ int main(int argc, char **argv)
PR_SetConcurrency(4);
- tp = PR_CreateThreadPool(initial_threads, max_threads, stacksize);
+ tp = PR_CreateThreadPool(initial_threads, max_threads, stacksize);
if (NULL == tp) {
printf("PR_CreateThreadPool failed\n");
failed_already=1;
goto done;
- }
- jobp = PR_QueueJob(tp, TCP_Server, tp, PR_TRUE);
- rv = PR_JoinJob(jobp);
- PR_ASSERT(PR_SUCCESS == rv);
+ }
+ jobp = PR_QueueJob(tp, TCP_Server, tp, PR_TRUE);
+ rv = PR_JoinJob(jobp);
+ PR_ASSERT(PR_SUCCESS == rv);
- DPRINTF(("%s: calling PR_JoinThreadPool\n", program_name));
- rv = PR_JoinThreadPool(tp);
- PR_ASSERT(PR_SUCCESS == rv);
- DPRINTF(("%s: returning from PR_JoinThreadPool\n", program_name));
+ DPRINTF(("%s: calling PR_JoinThreadPool\n", program_name));
+ rv = PR_JoinThreadPool(tp);
+ PR_ASSERT(PR_SUCCESS == rv);
+ DPRINTF(("%s: returning from PR_JoinThreadPool\n", program_name));
done:
PR_Cleanup();
- if (failed_already) return 1;
- else return 0;
+ if (failed_already) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
}
diff --git a/pr/tests/thruput.c b/pr/tests/thruput.c
index 09ffde7c..a772deaa 100644
--- a/pr/tests/thruput.c
+++ b/pr/tests/thruput.c
@@ -55,9 +55,12 @@ static PRStatus PrintAddress(const PRNetAddr* address)
{
char buffer[ADDR_BUFFER];
PRStatus rv = PR_NetAddrToString(address, buffer, sizeof(buffer));
- if (PR_SUCCESS == rv)
+ if (PR_SUCCESS == rv) {
PR_fprintf(err, "%s:%u\n", buffer, PR_ntohs(address->inet.port));
- else PL_FPrintError(err, "PR_NetAddrToString");
+ }
+ else {
+ PL_FPrintError(err, "PR_NetAddrToString");
+ }
return rv;
} /* PrintAddress */
@@ -93,21 +96,24 @@ static void PR_CALLBACK Clientel(void *arg)
data.option = PR_SockOpt_RecvBufferSize;
data.value.recv_buffer_size = (PRSize)xport_buffer;
rv = PR_SetSocketOption(xport, &data);
- if (PR_FAILURE == rv)
+ if (PR_FAILURE == rv) {
PL_FPrintError(err, "PR_SetSocketOption - ignored");
+ }
data.option = PR_SockOpt_SendBufferSize;
data.value.send_buffer_size = (PRSize)xport_buffer;
rv = PR_SetSocketOption(xport, &data);
- if (PR_FAILURE == rv)
+ if (PR_FAILURE == rv) {
PL_FPrintError(err, "PR_SetSocketOption - ignored");
+ }
}
rv = PR_Connect(xport, server_address, connect_timeout);
if (PR_FAILURE == rv)
{
PL_FPrintError(err, "PR_Connect");
- if (PR_IO_TIMEOUT_ERROR != PR_GetError())
+ if (PR_IO_TIMEOUT_ERROR != PR_GetError()) {
PR_Sleep(connect_timeout);
+ }
PR_Close(xport); /* delete it and start over */
}
} while (PR_FAILURE == rv);
@@ -115,7 +121,7 @@ static void PR_CALLBACK Clientel(void *arg)
do
{
bytes = PR_Recv(
- xport, buffer, buffer_size, 0, PR_INTERVAL_NO_TIMEOUT);
+ xport, buffer, buffer_size, 0, PR_INTERVAL_NO_TIMEOUT);
PR_Lock(shared->ml);
now = PR_IntervalNow();
shared->sampled += bytes;
@@ -147,13 +153,15 @@ static void Client(const char *server_name)
PRIntervalTime dally = PR_SecondsToInterval(60);
PR_fprintf(err, "Translating the name %s\n", server_name);
rv = PR_GetHostByName(server_name, buffer, sizeof(buffer), &host);
- if (PR_FAILURE == rv)
+ if (PR_FAILURE == rv) {
PL_FPrintError(err, "PR_GetHostByName");
+ }
else
{
if (PR_EnumerateHostEnt(
- 0, &host, PORT_NUMBER, &shared->server_address) < 0)
+ 0, &host, PORT_NUMBER, &shared->server_address) < 0) {
PL_FPrintError(err, "PR_EnumerateHostEnt");
+ }
else
{
do
@@ -189,19 +197,21 @@ static void PR_CALLBACK Servette(void *arg)
data.option = PR_SockOpt_RecvBufferSize;
data.value.recv_buffer_size = (PRSize)xport_buffer;
rv = PR_SetSocketOption(client, &data);
- if (PR_FAILURE == rv)
+ if (PR_FAILURE == rv) {
PL_FPrintError(err, "PR_SetSocketOption - ignored");
+ }
data.option = PR_SockOpt_SendBufferSize;
data.value.send_buffer_size = (PRSize)xport_buffer;
rv = PR_SetSocketOption(client, &data);
- if (PR_FAILURE == rv)
+ if (PR_FAILURE == rv) {
PL_FPrintError(err, "PR_SetSocketOption - ignored");
+ }
}
do
{
bytes = PR_Send(
- client, buffer, buffer_size, 0, PR_INTERVAL_NO_TIMEOUT);
+ client, buffer, buffer_size, 0, PR_INTERVAL_NO_TIMEOUT);
PR_Lock(shared->ml);
now = PR_IntervalNow();
@@ -238,11 +248,15 @@ static void Server(void)
}
rv = PR_InitializeNetAddr(PR_IpAddrAny, PORT_NUMBER, &server_address);
- if (PR_FAILURE == rv) PL_FPrintError(err, "PR_InitializeNetAddr");
+ if (PR_FAILURE == rv) {
+ PL_FPrintError(err, "PR_InitializeNetAddr");
+ }
else
{
rv = PR_Bind(xport, &server_address);
- if (PR_FAILURE == rv) PL_FPrintError(err, "PR_Bind");
+ if (PR_FAILURE == rv) {
+ PL_FPrintError(err, "PR_Bind");
+ }
else
{
PRFileDesc *client;
@@ -252,8 +266,10 @@ static void Server(void)
do
{
client = PR_Accept(
- xport, &client_address, PR_INTERVAL_NO_TIMEOUT);
- if (NULL == client) PL_FPrintError(err, "PR_Accept");
+ xport, &client_address, PR_INTERVAL_NO_TIMEOUT);
+ if (NULL == client) {
+ PL_FPrintError(err, "PR_Accept");
+ }
else
{
PR_fprintf(err, "Server accepting from ");
@@ -296,37 +312,39 @@ int main(int argc, char **argv)
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: /* Name of server */
- server_name = opt->value;
- break;
- case 'G': /* Globular threads */
- thread_scope = PR_GLOBAL_THREAD;
- break;
- case 'X': /* Use XTP as the transport */
- protocol = 36;
- break;
- case '6': /* Use IPv6 */
- domain = PR_AF_INET6;
- break;
- case 's': /* initial_streams */
- initial_streams = atoi(opt->value);
- break;
- case 'C': /* concurrency */
- concurrency = atoi(opt->value);
- break;
- case 'b': /* buffer size */
- buffer_size = 1024 * atoi(opt->value);
- break;
- case 'B': /* buffer size */
- xport_buffer = 1024 * atoi(opt->value);
- break;
- case 'h': /* user wants some guidance */
- default:
- Help(); /* so give him an earful */
- return 2; /* but not a lot else */
+ case 0: /* Name of server */
+ server_name = opt->value;
+ break;
+ case 'G': /* Globular threads */
+ thread_scope = PR_GLOBAL_THREAD;
+ break;
+ case 'X': /* Use XTP as the transport */
+ protocol = 36;
+ break;
+ case '6': /* Use IPv6 */
+ domain = PR_AF_INET6;
+ break;
+ case 's': /* initial_streams */
+ initial_streams = atoi(opt->value);
+ break;
+ case 'C': /* concurrency */
+ concurrency = atoi(opt->value);
+ break;
+ case 'b': /* buffer size */
+ buffer_size = 1024 * atoi(opt->value);
+ break;
+ case 'B': /* buffer size */
+ xport_buffer = 1024 * atoi(opt->value);
+ break;
+ case 'h': /* user wants some guidance */
+ default:
+ Help(); /* so give him an earful */
+ return 2; /* but not a lot else */
}
}
PL_DestroyOptState(opt);
@@ -335,12 +353,12 @@ int main(int argc, char **argv)
shared->ml = PR_NewLock();
PR_fprintf(err,
- "This machine is %s\n",
- (NULL == server_name) ? "the SERVER" : "a CLIENT");
+ "This machine is %s\n",
+ (NULL == server_name) ? "the SERVER" : "a CLIENT");
PR_fprintf(err,
- "Transport being used is %s\n",
- (6 == protocol) ? "TCP" : "XTP");
+ "Transport being used is %s\n",
+ (6 == protocol) ? "TCP" : "XTP");
if (PR_GLOBAL_THREAD == thread_scope)
{
@@ -359,18 +377,22 @@ int main(int argc, char **argv)
}
PR_fprintf(err,
- "All threads will be %s\n",
- (PR_GLOBAL_THREAD == thread_scope) ? "GLOBAL" : "LOCAL");
+ "All threads will be %s\n",
+ (PR_GLOBAL_THREAD == thread_scope) ? "GLOBAL" : "LOCAL");
PR_fprintf(err, "Client buffer size will be %u\n", buffer_size);
if (-1 != xport_buffer)
- PR_fprintf(
- err, "Transport send & receive buffer size will be %u\n", xport_buffer);
+ PR_fprintf(
+ err, "Transport send & receive buffer size will be %u\n", xport_buffer);
- if (NULL == server_name) Server();
- else Client(server_name);
+ if (NULL == server_name) {
+ Server();
+ }
+ else {
+ Client(server_name);
+ }
return 0;
} /* main */
diff --git a/pr/tests/time.c b/pr/tests/time.c
index be00231f..cdb3ef73 100644
--- a/pr/tests/time.c
+++ b/pr/tests/time.c
@@ -37,16 +37,16 @@ hrtime_t ihrtime;
void
ftime_init()
{
- itime = time(NULL);
- ihrtime = gethrtime();
+ itime = time(NULL);
+ ihrtime = gethrtime();
}
time_t
ftime()
{
- hrtime_t now = gethrtime();
+ hrtime_t now = gethrtime();
- return itime + ((now - ihrtime) / 1000000000ll);
+ return itime + ((now - ihrtime) / 1000000000ll);
}
static void timeTime(void)
@@ -54,8 +54,9 @@ static void timeTime(void)
PRInt32 index = count;
time_t rv;
- for (;index--;)
+ for (; index--;) {
rv = time(NULL);
+ }
}
static void timeGethrtime(void)
@@ -63,8 +64,9 @@ static void timeGethrtime(void)
PRInt32 index = count;
time_t rv;
- for (;index--;)
+ for (; index--;) {
rv = ftime();
+ }
}
static void timeGettimeofday(void)
@@ -73,8 +75,9 @@ static void timeGettimeofday(void)
time_t rv;
struct timeval tp;
- for (;index--;)
+ for (; index--;) {
rv = gettimeofday(&tp, NULL);
+ }
}
static void timePRTime32(void)
@@ -86,7 +89,7 @@ static void timePRTime32(void)
LL_I2L(q, 1000000);
- for (;index--;) {
+ for (; index--;) {
rv = PR_Now();
LL_DIV(rv, rv, q);
LL_L2I(rv32, rv);
@@ -98,8 +101,9 @@ static void timePRTime64(void)
PRInt32 index = count;
PRTime rv;
- for (;index--;)
+ for (; index--;) {
rv = PR_Now();
+ }
}
/************************************************************************/
@@ -117,40 +121,44 @@ static void Measure(void (*func)(void), const char *msg)
d = (double)PR_IntervalToMicroseconds(stop - start);
tot = PR_IntervalToMilliseconds(stop-start);
- if (debug_mode) printf("%40s: %6.2f usec avg, %d msec total\n", msg, d / count, tot);
+ if (debug_mode) {
+ printf("%40s: %6.2f usec avg, %d msec total\n", msg, d / count, tot);
+ }
}
int main(int argc, char **argv)
{
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "d:");
+ 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_mode = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
PR_STDIO_INIT();
if (argc > 1) {
- count = atoi(argv[1]);
+ count = atoi(argv[1]);
} else {
- count = DEFAULT_COUNT;
+ count = DEFAULT_COUNT;
}
ftime_init();
@@ -161,8 +169,8 @@ int main(int argc, char **argv)
Measure(timePRTime32, "time to get time with PR_Time() (32bit)");
Measure(timePRTime64, "time to get time with PR_Time() (64bit)");
- PR_Cleanup();
- return 0;
+ PR_Cleanup();
+ return 0;
}
diff --git a/pr/tests/timemac.c b/pr/tests/timemac.c
index a12a2aa1..b0f8b17d 100644
--- a/pr/tests/timemac.c
+++ b/pr/tests/timemac.c
@@ -13,10 +13,11 @@
static char *dayOfWeek[] =
- { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???" };
+{ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???" };
static char *month[] =
- { "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 void printExplodedTime(const PRExplodedTime *et) {
PRInt32 totalOffset;
@@ -25,18 +26,18 @@ static void printExplodedTime(const PRExplodedTime *et) {
/* Print day of the week, month, day, hour, minute, and second */
printf( "%s %s %ld %02ld:%02ld:%02ld ",
- dayOfWeek[et->tm_wday], month[et->tm_month], et->tm_mday,
- et->tm_hour, et->tm_min, et->tm_sec);
+ dayOfWeek[et->tm_wday], month[et->tm_month], et->tm_mday,
+ et->tm_hour, et->tm_min, et->tm_sec);
/* Print time zone */
totalOffset = et->tm_params.tp_gmt_offset + et->tm_params.tp_dst_offset;
if (totalOffset == 0) {
- printf("UTC ");
+ printf("UTC ");
} else {
sign = "";
if (totalOffset < 0) {
- totalOffset = -totalOffset;
- sign = "-";
+ totalOffset = -totalOffset;
+ sign = "-";
}
hourOffset = totalOffset / 3600;
minOffset = (totalOffset % 3600) / 60;
@@ -53,57 +54,57 @@ int main(int argc, char** argv)
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
- /*
- *************************************************************
- **
- ** Testing PR_Now(), PR_ExplodeTime, and PR_ImplodeTime
- ** on the current time
- **
- *************************************************************
- */
+ /*
+ *************************************************************
+ **
+ ** Testing PR_Now(), PR_ExplodeTime, and PR_ImplodeTime
+ ** on the current time
+ **
+ *************************************************************
+ */
{
- PRTime t1, t2;
- PRExplodedTime et;
+ PRTime t1, t2;
+ PRExplodedTime et;
- printf("*********************************************\n");
- printf("** **\n");
+ printf("*********************************************\n");
+ printf("** **\n");
printf("** Testing PR_Now(), PR_ExplodeTime, and **\n");
- printf("** PR_ImplodeTime on the current time **\n");
- printf("** **\n");
- printf("*********************************************\n\n");
+ printf("** PR_ImplodeTime on the current time **\n");
+ printf("** **\n");
+ printf("*********************************************\n\n");
t1 = PR_Now();
/* First try converting to UTC */
PR_ExplodeTime(t1, PR_GMTParameters, &et);
if (et.tm_params.tp_gmt_offset || et.tm_params.tp_dst_offset) {
- printf("ERROR: UTC has nonzero gmt or dst offset.\n");
- return 1;
+ printf("ERROR: UTC has nonzero gmt or dst offset.\n");
+ return 1;
}
printf("Current UTC is ");
- printExplodedTime(&et);
- printf("\n");
+ printExplodedTime(&et);
+ printf("\n");
t2 = PR_ImplodeTime(&et);
if (LL_NE(t1, t2)) {
- printf("ERROR: Explode and implode are NOT inverse.\n");
- return 1;
+ printf("ERROR: Explode and implode are NOT inverse.\n");
+ return 1;
}
/* Next, try converting to local (US Pacific) time */
PR_ExplodeTime(t1, PR_LocalTimeParameters, &et);
printf("Current local time is ");
- printExplodedTime(&et);
- printf("\n");
- printf("GMT offset is %ld, DST offset is %ld\n",
- et.tm_params.tp_gmt_offset, et.tm_params.tp_dst_offset);
+ printExplodedTime(&et);
+ printf("\n");
+ printf("GMT offset is %ld, DST offset is %ld\n",
+ et.tm_params.tp_gmt_offset, et.tm_params.tp_dst_offset);
t2 = PR_ImplodeTime(&et);
if (LL_NE(t1, t2)) {
- printf("ERROR: Explode and implode are NOT inverse.\n");
- return 1;
- }
+ printf("ERROR: Explode and implode are NOT inverse.\n");
+ return 1;
+ }
}
printf("Please examine the results\n");
diff --git a/pr/tests/timetest.c b/pr/tests/timetest.c
index 8dec86ef..9f96025d 100644
--- a/pr/tests/timetest.c
+++ b/pr/tests/timetest.c
@@ -25,10 +25,11 @@ int failed_already=0;
PRBool debug_mode = PR_FALSE;
static char *dayOfWeek[] =
- { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???" };
+{ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???" };
static char *month[] =
- { "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 void PrintExplodedTime(const PRExplodedTime *et) {
PRInt32 totalOffset;
@@ -37,46 +38,51 @@ static void PrintExplodedTime(const PRExplodedTime *et) {
/* Print day of the week, month, day, hour, minute, and second */
if (debug_mode) printf("%s %s %ld %02ld:%02ld:%02ld ",
- dayOfWeek[et->tm_wday], month[et->tm_month], et->tm_mday,
- et->tm_hour, et->tm_min, et->tm_sec);
+ dayOfWeek[et->tm_wday], month[et->tm_month], et->tm_mday,
+ et->tm_hour, et->tm_min, et->tm_sec);
/* Print time zone */
totalOffset = et->tm_params.tp_gmt_offset + et->tm_params.tp_dst_offset;
if (totalOffset == 0) {
- if (debug_mode) printf("UTC ");
+ if (debug_mode) {
+ printf("UTC ");
+ }
} else {
sign = "+";
if (totalOffset < 0) {
- totalOffset = -totalOffset;
- sign = "-";
+ totalOffset = -totalOffset;
+ sign = "-";
}
hourOffset = totalOffset / 3600;
minOffset = (totalOffset % 3600) / 60;
- if (debug_mode)
+ if (debug_mode) {
printf("%s%02ld%02ld ", sign, hourOffset, minOffset);
+ }
}
/* Print year */
- if (debug_mode) printf("%hd", et->tm_year);
+ if (debug_mode) {
+ printf("%hd", et->tm_year);
+ }
}
static int ExplodedTimeIsEqual(const PRExplodedTime *et1,
- const PRExplodedTime *et2)
+ const PRExplodedTime *et2)
{
if (et1->tm_usec == et2->tm_usec &&
- et1->tm_sec == et2->tm_sec &&
- et1->tm_min == et2->tm_min &&
- et1->tm_hour == et2->tm_hour &&
- et1->tm_mday == et2->tm_mday &&
- et1->tm_month == et2->tm_month &&
- et1->tm_year == et2->tm_year &&
- et1->tm_wday == et2->tm_wday &&
- et1->tm_yday == et2->tm_yday &&
- et1->tm_params.tp_gmt_offset == et2->tm_params.tp_gmt_offset &&
- et1->tm_params.tp_dst_offset == et2->tm_params.tp_dst_offset) {
+ et1->tm_sec == et2->tm_sec &&
+ et1->tm_min == et2->tm_min &&
+ et1->tm_hour == et2->tm_hour &&
+ et1->tm_mday == et2->tm_mday &&
+ et1->tm_month == et2->tm_month &&
+ et1->tm_year == et2->tm_year &&
+ et1->tm_wday == et2->tm_wday &&
+ et1->tm_yday == et2->tm_yday &&
+ et1->tm_params.tp_gmt_offset == et2->tm_params.tp_gmt_offset &&
+ et1->tm_params.tp_dst_offset == et2->tm_params.tp_dst_offset) {
return 1;
} else {
- return 0;
+ return 0;
}
}
@@ -101,87 +107,95 @@ testParseTimeString(PRTime t)
/* Print day of the week, month, day, hour, minute, and second */
PR_snprintf(timeString, 128, "%s %s %ld %02ld:%02ld:%02ld ",
- dayOfWeek[et.tm_wday], month[et.tm_month], et.tm_mday,
- et.tm_hour, et.tm_min, et.tm_sec);
+ dayOfWeek[et.tm_wday], month[et.tm_month], et.tm_mday,
+ et.tm_hour, et.tm_min, et.tm_sec);
/* Print time zone */
totalOffset = et.tm_params.tp_gmt_offset + et.tm_params.tp_dst_offset;
if (totalOffset == 0) {
- strcat(timeString, "GMT "); /* I wanted to use "UTC" here, but
+ strcat(timeString, "GMT "); /* I wanted to use "UTC" here, but
* PR_ParseTimeString doesn't
* understand "UTC". */
} else {
sign = "+";
if (totalOffset < 0) {
- totalOffset = -totalOffset;
- sign = "-";
+ totalOffset = -totalOffset;
+ sign = "-";
}
hourOffset = totalOffset / 3600;
minOffset = (totalOffset % 3600) / 60;
PR_snprintf(buf, 128, "%s%02ld%02ld ", sign, hourOffset, minOffset);
- strcat(timeString, buf);
+ strcat(timeString, buf);
}
/* Print year */
PR_snprintf(buf, 128, "%hd", et.tm_year);
strcat(timeString, buf);
if (PR_ParseTimeString(timeString, PR_FALSE, &t2) == PR_FAILURE) {
- fprintf(stderr, "PR_ParseTimeString() failed\n");
- exit(1);
+ fprintf(stderr, "PR_ParseTimeString() failed\n");
+ exit(1);
}
if (LL_NE(t, t2)) {
- fprintf(stderr, "PR_ParseTimeString() incorrect\n");
- PR_snprintf(buf, 128, "t is %lld, t2 is %lld, time string is %s\n",
- t, t2, timeString);
- fprintf(stderr, "%s\n", buf);
- exit(1);
+ fprintf(stderr, "PR_ParseTimeString() incorrect\n");
+ PR_snprintf(buf, 128, "t is %lld, t2 is %lld, time string is %s\n",
+ t, t2, timeString);
+ fprintf(stderr, "%s\n", buf);
+ exit(1);
}
}
int main(int argc, char** argv)
{
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
- PLOptStatus os;
- PLOptState *opt;
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+ PLOptStatus os;
+ PLOptState *opt;
PR_STDIO_INIT();
- opt = PL_CreateOptState(argc, argv, "d");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ opt = PL_CreateOptState(argc, argv, "d");
+ 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_mode = PR_TRUE;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = PR_TRUE;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- /* main test */
+ /* main test */
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
/* Testing zero PRTime (the epoch) */
{
- PRTime t;
- PRExplodedTime et;
+ PRTime t;
+ PRExplodedTime et;
- LL_I2L(t, 0);
- if (debug_mode) printf("The NSPR epoch is:\n");
+ LL_I2L(t, 0);
+ if (debug_mode) {
+ printf("The NSPR epoch is:\n");
+ }
PR_ExplodeTime(t, PR_LocalTimeParameters, &et);
- PrintExplodedTime(&et);
- if (debug_mode) printf("\n");
- PR_ExplodeTime(t, PR_GMTParameters, &et);
- PrintExplodedTime(&et);
- if (debug_mode) printf("\n\n");
- testParseTimeString(t);
+ PrintExplodedTime(&et);
+ if (debug_mode) {
+ printf("\n");
+ }
+ PR_ExplodeTime(t, PR_GMTParameters, &et);
+ PrintExplodedTime(&et);
+ if (debug_mode) {
+ printf("\n\n");
+ }
+ testParseTimeString(t);
}
/*
@@ -194,54 +208,74 @@ int main(int argc, char** argv)
*/
{
- PRTime t1, t2;
- PRExplodedTime et;
-
- if (debug_mode) {
- printf("*********************************************\n");
- printf("** **\n");
- printf("** Testing PR_Now(), PR_ExplodeTime, and **\n");
- printf("** PR_ImplodeTime on the current time **\n");
- printf("** **\n");
- printf("*********************************************\n\n");
- }
- t1 = PR_Now();
+ PRTime t1, t2;
+ PRExplodedTime et;
+
+ if (debug_mode) {
+ printf("*********************************************\n");
+ printf("** **\n");
+ printf("** Testing PR_Now(), PR_ExplodeTime, and **\n");
+ printf("** PR_ImplodeTime on the current time **\n");
+ printf("** **\n");
+ printf("*********************************************\n\n");
+ }
+ t1 = PR_Now();
/* First try converting to UTC */
PR_ExplodeTime(t1, PR_GMTParameters, &et);
if (et.tm_params.tp_gmt_offset || et.tm_params.tp_dst_offset) {
- if (debug_mode) printf("ERROR: UTC has nonzero gmt or dst offset.\n");
- else failed_already=1;
- return 1;
+ if (debug_mode) {
+ printf("ERROR: UTC has nonzero gmt or dst offset.\n");
+ }
+ else {
+ failed_already=1;
+ }
+ return 1;
+ }
+ if (debug_mode) {
+ printf("Current UTC is ");
+ }
+ PrintExplodedTime(&et);
+ if (debug_mode) {
+ printf("\n");
}
- if (debug_mode) printf("Current UTC is ");
- PrintExplodedTime(&et);
- if (debug_mode) printf("\n");
t2 = PR_ImplodeTime(&et);
if (LL_NE(t1, t2)) {
- if (debug_mode) printf("ERROR: Explode and implode are NOT inverse.\n");
- else printf("FAIL\n");
- return 1;
+ if (debug_mode) {
+ printf("ERROR: Explode and implode are NOT inverse.\n");
+ }
+ else {
+ printf("FAIL\n");
+ }
+ return 1;
}
/* Next, try converting to local (US Pacific) time */
PR_ExplodeTime(t1, PR_LocalTimeParameters, &et);
- if (debug_mode) printf("Current local time is ");
- PrintExplodedTime(&et);
- if (debug_mode) printf("\n");
- if (debug_mode) printf("GMT offset is %ld, DST offset is %ld\n",
- et.tm_params.tp_gmt_offset, et.tm_params.tp_dst_offset);
+ if (debug_mode) {
+ printf("Current local time is ");
+ }
+ PrintExplodedTime(&et);
+ if (debug_mode) {
+ printf("\n");
+ }
+ if (debug_mode) printf("GMT offset is %ld, DST offset is %ld\n",
+ et.tm_params.tp_gmt_offset, et.tm_params.tp_dst_offset);
t2 = PR_ImplodeTime(&et);
if (LL_NE(t1, t2)) {
- if (debug_mode) printf("ERROR: Explode and implode are NOT inverse.\n");
- return 1;
- }
+ if (debug_mode) {
+ printf("ERROR: Explode and implode are NOT inverse.\n");
+ }
+ return 1;
+ }
- if (debug_mode) printf("Please examine the results\n");
- testParseTimeString(t1);
+ if (debug_mode) {
+ printf("Please examine the results\n");
+ }
+ testParseTimeString(t1);
}
@@ -255,36 +289,44 @@ int main(int argc, char** argv)
/* July 4, 2001 is Wednesday */
{
- PRExplodedTime et;
-
- if (debug_mode) {
- printf("\n");
- printf("**********************************\n");
- printf("** **\n");
- printf("** Testing PR_NormalizeTime() **\n");
- printf("** **\n");
- printf("**********************************\n\n");
- }
+ PRExplodedTime et;
+
+ if (debug_mode) {
+ printf("\n");
+ printf("**********************************\n");
+ printf("** **\n");
+ printf("** Testing PR_NormalizeTime() **\n");
+ printf("** **\n");
+ printf("**********************************\n\n");
+ }
et.tm_year = 2001;
et.tm_month = 7 - 1;
et.tm_mday = 4;
et.tm_hour = 0;
et.tm_min = 0;
et.tm_sec = 0;
- et.tm_usec = 0;
+ et.tm_usec = 0;
et.tm_params = PR_GMTParameters(&et);
- PR_NormalizeTime(&et, PR_GMTParameters);
+ PR_NormalizeTime(&et, PR_GMTParameters);
- if (debug_mode) printf("July 4, 2001 is %s.\n", dayOfWeek[et.tm_wday]);
- if (et.tm_wday == 3) {
- if (debug_mode) printf("PASS\n");
+ if (debug_mode) {
+ printf("July 4, 2001 is %s.\n", dayOfWeek[et.tm_wday]);
+ }
+ if (et.tm_wday == 3) {
+ if (debug_mode) {
+ printf("PASS\n");
+ }
} else {
- if (debug_mode) printf("ERROR: It should be Wednesday\n");
- else failed_already=1;
- return 1;
- }
- testParseTimeString(PR_ImplodeTime(&et));
+ if (debug_mode) {
+ printf("ERROR: It should be Wednesday\n");
+ }
+ else {
+ failed_already=1;
+ }
+ return 1;
+ }
+ testParseTimeString(PR_ImplodeTime(&et));
/* June 12, 1997 23:00 PST == June 13, 1997 00:00 PDT */
et.tm_year = 1997;
@@ -293,25 +335,33 @@ int main(int argc, char** argv)
et.tm_hour = 23;
et.tm_min = 0;
et.tm_sec = 0;
- et.tm_usec = 0;
+ et.tm_usec = 0;
et.tm_params.tp_gmt_offset = -8 * 3600;
- et.tm_params.tp_dst_offset = 0;
+ et.tm_params.tp_dst_offset = 0;
- PR_NormalizeTime(&et, PR_USPacificTimeParameters);
+ PR_NormalizeTime(&et, PR_USPacificTimeParameters);
- if (debug_mode) {
- printf("Thu Jun 12, 1997 23:00:00 PST is ");
- }
- PrintExplodedTime(&et);
- if (debug_mode) printf(".\n");
- if (et.tm_wday == 5) {
- if (debug_mode) printf("PASS\n");
+ if (debug_mode) {
+ printf("Thu Jun 12, 1997 23:00:00 PST is ");
+ }
+ PrintExplodedTime(&et);
+ if (debug_mode) {
+ printf(".\n");
+ }
+ if (et.tm_wday == 5) {
+ if (debug_mode) {
+ printf("PASS\n");
+ }
} else {
- if (debug_mode) printf("ERROR: It should be Friday\n");
- else failed_already=1;
- return 1;
- }
- testParseTimeString(PR_ImplodeTime(&et));
+ if (debug_mode) {
+ printf("ERROR: It should be Friday\n");
+ }
+ else {
+ failed_already=1;
+ }
+ return 1;
+ }
+ testParseTimeString(PR_ImplodeTime(&et));
/* Feb 14, 1997 00:00:00 PDT == Feb 13, 1997 23:00:00 PST */
et.tm_year = 1997;
@@ -320,25 +370,33 @@ int main(int argc, char** argv)
et.tm_hour = 0;
et.tm_min = 0;
et.tm_sec = 0;
- et.tm_usec = 0;
+ et.tm_usec = 0;
et.tm_params.tp_gmt_offset = -8 * 3600;
- et.tm_params.tp_dst_offset = 3600;
+ et.tm_params.tp_dst_offset = 3600;
- PR_NormalizeTime(&et, PR_USPacificTimeParameters);
+ PR_NormalizeTime(&et, PR_USPacificTimeParameters);
- if (debug_mode) {
- printf("Fri Feb 14, 1997 00:00:00 PDT is ");
- }
- PrintExplodedTime(&et);
- if (debug_mode) printf(".\n");
- if (et.tm_wday == 4) {
- if (debug_mode) printf("PASS\n");
+ if (debug_mode) {
+ printf("Fri Feb 14, 1997 00:00:00 PDT is ");
+ }
+ PrintExplodedTime(&et);
+ if (debug_mode) {
+ printf(".\n");
+ }
+ if (et.tm_wday == 4) {
+ if (debug_mode) {
+ printf("PASS\n");
+ }
} else {
- if (debug_mode) printf("ERROR: It should be Thursday\n");
- else failed_already=1;
- return 1;
- }
- testParseTimeString(PR_ImplodeTime(&et));
+ if (debug_mode) {
+ printf("ERROR: It should be Thursday\n");
+ }
+ else {
+ failed_already=1;
+ }
+ return 1;
+ }
+ testParseTimeString(PR_ImplodeTime(&et));
/* What time is Nov. 7, 1996, 18:29:23 PDT? */
et.tm_year = 1996;
@@ -347,15 +405,19 @@ int main(int argc, char** argv)
et.tm_hour = 18;
et.tm_min = 29;
et.tm_sec = 23;
- et.tm_usec = 0;
+ et.tm_usec = 0;
et.tm_params.tp_gmt_offset = -8 * 3600; /* PDT */
- et.tm_params.tp_dst_offset = 3600;
+ et.tm_params.tp_dst_offset = 3600;
- PR_NormalizeTime(&et, PR_LocalTimeParameters);
- if (debug_mode) printf("Nov 7 18:29:23 PDT 1996 is ");
- PrintExplodedTime(&et);
- if (debug_mode) printf(".\n");
- testParseTimeString(PR_ImplodeTime(&et));
+ PR_NormalizeTime(&et, PR_LocalTimeParameters);
+ if (debug_mode) {
+ printf("Nov 7 18:29:23 PDT 1996 is ");
+ }
+ PrintExplodedTime(&et);
+ if (debug_mode) {
+ printf(".\n");
+ }
+ testParseTimeString(PR_ImplodeTime(&et));
/* What time is Oct. 7, 1995, 18:29:23 PST? */
et.tm_year = 1995;
@@ -365,15 +427,21 @@ int main(int argc, char** argv)
et.tm_min = 29;
et.tm_sec = 23;
et.tm_params.tp_gmt_offset = -8 * 3600; /* PST */
- et.tm_params.tp_dst_offset = 0;
+ et.tm_params.tp_dst_offset = 0;
- PR_NormalizeTime(&et, PR_LocalTimeParameters);
- if (debug_mode) printf("Oct 7 18:29:23 PST 1995 is ");
- PrintExplodedTime(&et);
- if (debug_mode) printf(".\n");
- testParseTimeString(PR_ImplodeTime(&et));
+ PR_NormalizeTime(&et, PR_LocalTimeParameters);
+ if (debug_mode) {
+ printf("Oct 7 18:29:23 PST 1995 is ");
+ }
+ PrintExplodedTime(&et);
+ if (debug_mode) {
+ printf(".\n");
+ }
+ testParseTimeString(PR_ImplodeTime(&et));
- if (debug_mode) printf("Please examine the results\n");
+ if (debug_mode) {
+ printf("Please examine the results\n");
+ }
}
/*
@@ -385,74 +453,82 @@ int main(int argc, char** argv)
*/
{
- PRExplodedTime et1, et2;
- PRTime ttt;
- PRTime secs;
-
- if (debug_mode) {
- printf("\n");
- printf("***************************************\n");
- printf("** **\n");
- printf("** Testing range of years **\n");
- printf("** **\n");
- printf("***************************************\n\n");
- }
- /* April 4, 1917 GMT */
- et1.tm_usec = 0;
- et1.tm_sec = 0;
- et1.tm_min = 0;
- et1.tm_hour = 0;
- et1.tm_mday = 4;
- et1.tm_month = 4 - 1;
- et1.tm_year = 1917;
- et1.tm_params = PR_GMTParameters(&et1);
- PR_NormalizeTime(&et1, PR_LocalTimeParameters);
- secs = PR_ImplodeTime(&et1);
- if (LL_GE_ZERO(secs)) {
- if (debug_mode)
- printf("ERROR: April 4, 1917 GMT returns a nonnegative second count\n");
- failed_already = 1;
- return 1;
- }
- PR_ExplodeTime(secs, PR_LocalTimeParameters, &et2);
- if (!ExplodedTimeIsEqual(&et1, &et2)) {
- if (debug_mode)
- printf("ERROR: PR_ImplodeTime and PR_ExplodeTime are not inverse for April 4, 1917 GMT\n");
- failed_already=1;
- return 1;
- }
- ttt = PR_ImplodeTime(&et1);
- testParseTimeString( ttt );
-
- if (debug_mode) printf("Test passed for April 4, 1917\n");
-
- /* July 4, 2050 */
- et1.tm_usec = 0;
- et1.tm_sec = 0;
- et1.tm_min = 0;
- et1.tm_hour = 0;
- et1.tm_mday = 4;
- et1.tm_month = 7 - 1;
- et1.tm_year = 2050;
- et1.tm_params = PR_GMTParameters(&et1);
- PR_NormalizeTime(&et1, PR_LocalTimeParameters);
- secs = PR_ImplodeTime(&et1);
- if (!LL_GE_ZERO(secs)) {
- if (debug_mode)
- printf("ERROR: July 4, 2050 GMT returns a negative second count\n");
- failed_already = 1;
- return 1;
- }
- PR_ExplodeTime(secs, PR_LocalTimeParameters, &et2);
- if (!ExplodedTimeIsEqual(&et1, &et2)) {
- if (debug_mode)
- printf("ERROR: PR_ImplodeTime and PR_ExplodeTime are not inverse for July 4, 2050 GMT\n");
- failed_already=1;
- return 1;
- }
- testParseTimeString(PR_ImplodeTime(&et1));
-
- if (debug_mode) printf("Test passed for July 4, 2050\n");
+ PRExplodedTime et1, et2;
+ PRTime ttt;
+ PRTime secs;
+
+ if (debug_mode) {
+ printf("\n");
+ printf("***************************************\n");
+ printf("** **\n");
+ printf("** Testing range of years **\n");
+ printf("** **\n");
+ printf("***************************************\n\n");
+ }
+ /* April 4, 1917 GMT */
+ et1.tm_usec = 0;
+ et1.tm_sec = 0;
+ et1.tm_min = 0;
+ et1.tm_hour = 0;
+ et1.tm_mday = 4;
+ et1.tm_month = 4 - 1;
+ et1.tm_year = 1917;
+ et1.tm_params = PR_GMTParameters(&et1);
+ PR_NormalizeTime(&et1, PR_LocalTimeParameters);
+ secs = PR_ImplodeTime(&et1);
+ if (LL_GE_ZERO(secs)) {
+ if (debug_mode) {
+ printf("ERROR: April 4, 1917 GMT returns a nonnegative second count\n");
+ }
+ failed_already = 1;
+ return 1;
+ }
+ PR_ExplodeTime(secs, PR_LocalTimeParameters, &et2);
+ if (!ExplodedTimeIsEqual(&et1, &et2)) {
+ if (debug_mode) {
+ printf("ERROR: PR_ImplodeTime and PR_ExplodeTime are not inverse for April 4, 1917 GMT\n");
+ }
+ failed_already=1;
+ return 1;
+ }
+ ttt = PR_ImplodeTime(&et1);
+ testParseTimeString( ttt );
+
+ if (debug_mode) {
+ printf("Test passed for April 4, 1917\n");
+ }
+
+ /* July 4, 2050 */
+ et1.tm_usec = 0;
+ et1.tm_sec = 0;
+ et1.tm_min = 0;
+ et1.tm_hour = 0;
+ et1.tm_mday = 4;
+ et1.tm_month = 7 - 1;
+ et1.tm_year = 2050;
+ et1.tm_params = PR_GMTParameters(&et1);
+ PR_NormalizeTime(&et1, PR_LocalTimeParameters);
+ secs = PR_ImplodeTime(&et1);
+ if (!LL_GE_ZERO(secs)) {
+ if (debug_mode) {
+ printf("ERROR: July 4, 2050 GMT returns a negative second count\n");
+ }
+ failed_already = 1;
+ return 1;
+ }
+ PR_ExplodeTime(secs, PR_LocalTimeParameters, &et2);
+ if (!ExplodedTimeIsEqual(&et1, &et2)) {
+ if (debug_mode) {
+ printf("ERROR: PR_ImplodeTime and PR_ExplodeTime are not inverse for July 4, 2050 GMT\n");
+ }
+ failed_already=1;
+ return 1;
+ }
+ testParseTimeString(PR_ImplodeTime(&et1));
+
+ if (debug_mode) {
+ printf("Test passed for July 4, 2050\n");
+ }
}
@@ -469,271 +545,279 @@ int main(int argc, char** argv)
*/
{
- PRExplodedTime et, et1, et2;
- PRInt64 usecPer10Min;
- int day, hour, min;
- PRTime usecs;
- int dstInEffect = 0;
-
- if (debug_mode) {
- printf("\n");
- printf("*******************************************************\n");
- printf("** **\n");
- printf("** Stress test Pacific Time **\n");
- printf("** Starting from midnight Jan. 1, 2005 PST, **\n");
- printf("** going through four years in 10-minute increment **\n");
- printf("** **\n");
- printf("*******************************************************\n\n");
- }
- LL_I2L(usecPer10Min, 600000000L);
-
- /* 00:00:00 PST Jan. 1, 2005 */
- et.tm_usec = 0;
- et.tm_sec = 0;
- et.tm_min = 0;
- et.tm_hour = 0;
- et.tm_mday = 1;
- et.tm_month = 0;
- et.tm_year = 2005;
- et.tm_params.tp_gmt_offset = -8 * 3600;
- et.tm_params.tp_dst_offset = 0;
- usecs = PR_ImplodeTime(&et);
+ PRExplodedTime et, et1, et2;
+ PRInt64 usecPer10Min;
+ int day, hour, min;
+ PRTime usecs;
+ int dstInEffect = 0;
+
+ if (debug_mode) {
+ printf("\n");
+ printf("*******************************************************\n");
+ printf("** **\n");
+ printf("** Stress test Pacific Time **\n");
+ printf("** Starting from midnight Jan. 1, 2005 PST, **\n");
+ printf("** going through four years in 10-minute increment **\n");
+ printf("** **\n");
+ printf("*******************************************************\n\n");
+ }
+ LL_I2L(usecPer10Min, 600000000L);
+
+ /* 00:00:00 PST Jan. 1, 2005 */
+ et.tm_usec = 0;
+ et.tm_sec = 0;
+ et.tm_min = 0;
+ et.tm_hour = 0;
+ et.tm_mday = 1;
+ et.tm_month = 0;
+ et.tm_year = 2005;
+ et.tm_params.tp_gmt_offset = -8 * 3600;
+ et.tm_params.tp_dst_offset = 0;
+ usecs = PR_ImplodeTime(&et);
for (day = 0; day < 4 * 365 + 1; day++) {
- for (hour = 0; hour < 24; hour++) {
- for (min = 0; min < 60; min += 10) {
- LL_ADD(usecs, usecs, usecPer10Min);
- PR_ExplodeTime(usecs, PR_USPacificTimeParameters, &et1);
-
- et2 = et;
- et2.tm_usec += 600000000L;
- PR_NormalizeTime(&et2, PR_USPacificTimeParameters);
-
- if (!ExplodedTimeIsEqual(&et1, &et2)) {
- printf("ERROR: componentwise comparison failed\n");
- PrintExplodedTime(&et1);
- printf("\n");
- PrintExplodedTime(&et2);
- printf("\n");
- failed_already=1;
- return 1;
- }
-
- if (LL_NE(usecs, PR_ImplodeTime(&et1))) {
- printf("ERROR: PR_ExplodeTime and PR_ImplodeTime are not inverse\n");
- PrintExplodedTime(&et1);
- printf("\n");
- failed_already=1;
- return 1;
- }
- testParseTimeString(usecs);
-
- if (!dstInEffect && et1.tm_params.tp_dst_offset) {
- dstInEffect = 1;
- if (debug_mode) {
- printf("DST changeover from ");
- PrintExplodedTime(&et);
- printf(" to ");
- PrintExplodedTime(&et1);
- printf(".\n");
- }
+ for (hour = 0; hour < 24; hour++) {
+ for (min = 0; min < 60; min += 10) {
+ LL_ADD(usecs, usecs, usecPer10Min);
+ PR_ExplodeTime(usecs, PR_USPacificTimeParameters, &et1);
+
+ et2 = et;
+ et2.tm_usec += 600000000L;
+ PR_NormalizeTime(&et2, PR_USPacificTimeParameters);
+
+ if (!ExplodedTimeIsEqual(&et1, &et2)) {
+ printf("ERROR: componentwise comparison failed\n");
+ PrintExplodedTime(&et1);
+ printf("\n");
+ PrintExplodedTime(&et2);
+ printf("\n");
+ failed_already=1;
+ return 1;
+ }
+
+ if (LL_NE(usecs, PR_ImplodeTime(&et1))) {
+ printf("ERROR: PR_ExplodeTime and PR_ImplodeTime are not inverse\n");
+ PrintExplodedTime(&et1);
+ printf("\n");
+ failed_already=1;
+ return 1;
+ }
+ testParseTimeString(usecs);
+
+ if (!dstInEffect && et1.tm_params.tp_dst_offset) {
+ dstInEffect = 1;
+ if (debug_mode) {
+ printf("DST changeover from ");
+ PrintExplodedTime(&et);
+ printf(" to ");
+ PrintExplodedTime(&et1);
+ printf(".\n");
+ }
} else if (dstInEffect && !et1.tm_params.tp_dst_offset) {
- dstInEffect = 0;
- if (debug_mode) {
- printf("DST changeover from ");
- PrintExplodedTime(&et);
- printf(" to ");
- PrintExplodedTime(&et1);
- printf(".\n");
- }
+ dstInEffect = 0;
+ if (debug_mode) {
+ printf("DST changeover from ");
+ PrintExplodedTime(&et);
+ printf(" to ");
+ PrintExplodedTime(&et1);
+ printf(".\n");
+ }
}
- et = et1;
- }
- }
+ et = et1;
+ }
+ }
+ }
+ if (debug_mode) {
+ printf("Test passed\n");
}
- if (debug_mode) printf("Test passed\n");
}
/* Same stress test, but with PR_LocalTimeParameters */
{
- PRExplodedTime et, et1, et2;
- PRInt64 usecPer10Min;
- int day, hour, min;
- PRTime usecs;
- int dstInEffect = 0;
-
- if (debug_mode) {
- printf("\n");
- printf("*******************************************************\n");
- printf("** **\n");
- printf("** Stress test Local Time **\n");
- printf("** Starting from midnight Jan. 1, 2005 PST, **\n");
- printf("** going through four years in 10-minute increment **\n");
- printf("** **\n");
- printf("*******************************************************\n\n");
- }
-
- LL_I2L(usecPer10Min, 600000000L);
-
- /* 00:00:00 PST Jan. 1, 2005 */
- et.tm_usec = 0;
- et.tm_sec = 0;
- et.tm_min = 0;
- et.tm_hour = 0;
- et.tm_mday = 1;
- et.tm_month = 0;
- et.tm_year = 2005;
- et.tm_params.tp_gmt_offset = -8 * 3600;
- et.tm_params.tp_dst_offset = 0;
- usecs = PR_ImplodeTime(&et);
+ PRExplodedTime et, et1, et2;
+ PRInt64 usecPer10Min;
+ int day, hour, min;
+ PRTime usecs;
+ int dstInEffect = 0;
+
+ if (debug_mode) {
+ printf("\n");
+ printf("*******************************************************\n");
+ printf("** **\n");
+ printf("** Stress test Local Time **\n");
+ printf("** Starting from midnight Jan. 1, 2005 PST, **\n");
+ printf("** going through four years in 10-minute increment **\n");
+ printf("** **\n");
+ printf("*******************************************************\n\n");
+ }
+
+ LL_I2L(usecPer10Min, 600000000L);
+
+ /* 00:00:00 PST Jan. 1, 2005 */
+ et.tm_usec = 0;
+ et.tm_sec = 0;
+ et.tm_min = 0;
+ et.tm_hour = 0;
+ et.tm_mday = 1;
+ et.tm_month = 0;
+ et.tm_year = 2005;
+ et.tm_params.tp_gmt_offset = -8 * 3600;
+ et.tm_params.tp_dst_offset = 0;
+ usecs = PR_ImplodeTime(&et);
for (day = 0; day < 4 * 365 + 1; day++) {
- for (hour = 0; hour < 24; hour++) {
- for (min = 0; min < 60; min += 10) {
- LL_ADD(usecs, usecs, usecPer10Min);
- PR_ExplodeTime(usecs, PR_LocalTimeParameters, &et1);
-
- et2 = et;
- et2.tm_usec += 600000000L;
- PR_NormalizeTime(&et2, PR_LocalTimeParameters);
-
- if (!ExplodedTimeIsEqual(&et1, &et2)) {
- printf("ERROR: componentwise comparison failed\n");
- PrintExplodedTime(&et1);
- printf("\n");
- PrintExplodedTime(&et2);
- printf("\n");
- return 1;
- }
-
- if (LL_NE(usecs, PR_ImplodeTime(&et1))) {
+ for (hour = 0; hour < 24; hour++) {
+ for (min = 0; min < 60; min += 10) {
+ LL_ADD(usecs, usecs, usecPer10Min);
+ PR_ExplodeTime(usecs, PR_LocalTimeParameters, &et1);
+
+ et2 = et;
+ et2.tm_usec += 600000000L;
+ PR_NormalizeTime(&et2, PR_LocalTimeParameters);
+
+ if (!ExplodedTimeIsEqual(&et1, &et2)) {
+ printf("ERROR: componentwise comparison failed\n");
+ PrintExplodedTime(&et1);
+ printf("\n");
+ PrintExplodedTime(&et2);
+ printf("\n");
+ return 1;
+ }
+
+ if (LL_NE(usecs, PR_ImplodeTime(&et1))) {
printf("ERROR: PR_ExplodeTime and PR_ImplodeTime are not inverse\n");
- PrintExplodedTime(&et1);
- printf("\n");
- failed_already=1;
- return 1;
- }
- testParseTimeString(usecs);
-
- if (!dstInEffect && et1.tm_params.tp_dst_offset) {
- dstInEffect = 1;
- if (debug_mode) {
- printf("DST changeover from ");
- PrintExplodedTime(&et);
- printf(" to ");
- PrintExplodedTime(&et1);
- printf(".\n");
- }
+ PrintExplodedTime(&et1);
+ printf("\n");
+ failed_already=1;
+ return 1;
+ }
+ testParseTimeString(usecs);
+
+ if (!dstInEffect && et1.tm_params.tp_dst_offset) {
+ dstInEffect = 1;
+ if (debug_mode) {
+ printf("DST changeover from ");
+ PrintExplodedTime(&et);
+ printf(" to ");
+ PrintExplodedTime(&et1);
+ printf(".\n");
+ }
} else if (dstInEffect && !et1.tm_params.tp_dst_offset) {
- dstInEffect = 0;
- if (debug_mode) {
- printf("DST changeover from ");
- PrintExplodedTime(&et);
- printf(" to ");
- PrintExplodedTime(&et1);
- printf(".\n");
- }
+ dstInEffect = 0;
+ if (debug_mode) {
+ printf("DST changeover from ");
+ PrintExplodedTime(&et);
+ printf(" to ");
+ PrintExplodedTime(&et1);
+ printf(".\n");
+ }
}
- et = et1;
- }
- }
+ et = et1;
+ }
+ }
+ }
+ if (debug_mode) {
+ printf("Test passed\n");
}
- if (debug_mode) printf("Test passed\n");
}
/* Same stress test, but with PR_LocalTimeParameters and going backward */
{
- PRExplodedTime et, et1, et2;
- PRInt64 usecPer10Min;
- int day, hour, min;
- PRTime usecs;
- int dstInEffect = 0;
-
- if (debug_mode) {
- printf("\n");
- printf("*******************************************************\n");
- printf("** **\n");
- printf("** Stress test Local Time **\n");
- printf("** Starting from midnight Jan. 1, 2009 PST, **\n");
- printf("** going back four years in 10-minute increment **\n");
- printf("** **\n");
- printf("*******************************************************\n\n");
- }
-
- LL_I2L(usecPer10Min, 600000000L);
-
- /* 00:00:00 PST Jan. 1, 2009 */
- et.tm_usec = 0;
- et.tm_sec = 0;
- et.tm_min = 0;
- et.tm_hour = 0;
- et.tm_mday = 1;
- et.tm_month = 0;
- et.tm_year = 2009;
- et.tm_params.tp_gmt_offset = -8 * 3600;
- et.tm_params.tp_dst_offset = 0;
- usecs = PR_ImplodeTime(&et);
+ PRExplodedTime et, et1, et2;
+ PRInt64 usecPer10Min;
+ int day, hour, min;
+ PRTime usecs;
+ int dstInEffect = 0;
+
+ if (debug_mode) {
+ printf("\n");
+ printf("*******************************************************\n");
+ printf("** **\n");
+ printf("** Stress test Local Time **\n");
+ printf("** Starting from midnight Jan. 1, 2009 PST, **\n");
+ printf("** going back four years in 10-minute increment **\n");
+ printf("** **\n");
+ printf("*******************************************************\n\n");
+ }
+
+ LL_I2L(usecPer10Min, 600000000L);
+
+ /* 00:00:00 PST Jan. 1, 2009 */
+ et.tm_usec = 0;
+ et.tm_sec = 0;
+ et.tm_min = 0;
+ et.tm_hour = 0;
+ et.tm_mday = 1;
+ et.tm_month = 0;
+ et.tm_year = 2009;
+ et.tm_params.tp_gmt_offset = -8 * 3600;
+ et.tm_params.tp_dst_offset = 0;
+ usecs = PR_ImplodeTime(&et);
for (day = 0; day < 4 * 365 + 1; day++) {
- for (hour = 0; hour < 24; hour++) {
- for (min = 0; min < 60; min += 10) {
- LL_SUB(usecs, usecs, usecPer10Min);
- PR_ExplodeTime(usecs, PR_LocalTimeParameters, &et1);
-
- et2 = et;
- et2.tm_usec -= 600000000L;
- PR_NormalizeTime(&et2, PR_LocalTimeParameters);
-
- if (!ExplodedTimeIsEqual(&et1, &et2)) {
- printf("ERROR: componentwise comparison failed\n");
- PrintExplodedTime(&et1);
- printf("\n");
- PrintExplodedTime(&et2);
- printf("\n");
- return 1;
- }
-
- if (LL_NE(usecs, PR_ImplodeTime(&et1))) {
- printf("ERROR: PR_ExplodeTime and PR_ImplodeTime are not inverse\n");
- PrintExplodedTime(&et1);
- printf("\n");
- failed_already=1;
- return 1;
- }
- testParseTimeString(usecs);
-
- if (!dstInEffect && et1.tm_params.tp_dst_offset) {
- dstInEffect = 1;
- if (debug_mode) {
- printf("DST changeover from ");
- PrintExplodedTime(&et);
- printf(" to ");
- PrintExplodedTime(&et1);
- printf(".\n");
- }
+ for (hour = 0; hour < 24; hour++) {
+ for (min = 0; min < 60; min += 10) {
+ LL_SUB(usecs, usecs, usecPer10Min);
+ PR_ExplodeTime(usecs, PR_LocalTimeParameters, &et1);
+
+ et2 = et;
+ et2.tm_usec -= 600000000L;
+ PR_NormalizeTime(&et2, PR_LocalTimeParameters);
+
+ if (!ExplodedTimeIsEqual(&et1, &et2)) {
+ printf("ERROR: componentwise comparison failed\n");
+ PrintExplodedTime(&et1);
+ printf("\n");
+ PrintExplodedTime(&et2);
+ printf("\n");
+ return 1;
+ }
+
+ if (LL_NE(usecs, PR_ImplodeTime(&et1))) {
+ printf("ERROR: PR_ExplodeTime and PR_ImplodeTime are not inverse\n");
+ PrintExplodedTime(&et1);
+ printf("\n");
+ failed_already=1;
+ return 1;
+ }
+ testParseTimeString(usecs);
+
+ if (!dstInEffect && et1.tm_params.tp_dst_offset) {
+ dstInEffect = 1;
+ if (debug_mode) {
+ printf("DST changeover from ");
+ PrintExplodedTime(&et);
+ printf(" to ");
+ PrintExplodedTime(&et1);
+ printf(".\n");
+ }
} else if (dstInEffect && !et1.tm_params.tp_dst_offset) {
- dstInEffect = 0;
- if (debug_mode) {
- printf("DST changeover from ");
- PrintExplodedTime(&et);
- printf(" to ");
- PrintExplodedTime(&et1);
- printf(".\n");
- }
+ dstInEffect = 0;
+ if (debug_mode) {
+ printf("DST changeover from ");
+ PrintExplodedTime(&et);
+ printf(" to ");
+ PrintExplodedTime(&et1);
+ printf(".\n");
+ }
}
- et = et1;
- }
- }
+ et = et1;
+ }
+ }
}
}
- if (failed_already) return 1;
- else return 0;
+ if (failed_already) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
}
diff --git a/pr/tests/tmoacc.c b/pr/tests/tmoacc.c
index 9bd3a4e0..a4d14daa 100644
--- a/pr/tests/tmoacc.c
+++ b/pr/tests/tmoacc.c
@@ -54,45 +54,54 @@ static void Accept(void *arg)
PRInt32 recv_length = 0, flags = 0;
PRFileDesc *clientSock;
PRIntn toread, byte, bytes, loop = 0;
- struct Descriptor { PRInt32 length; PRUint32 checksum; } descriptor;
+ struct Descriptor {
+ PRInt32 length;
+ PRUint32 checksum;
+ } descriptor;
do
{
PRUint32 checksum = 0;
- if (NULL != shared->debug)
+ if (NULL != shared->debug) {
PR_fprintf(shared->debug, "[%d]accepting ... ", loop++);
+ }
clientSock = PR_Accept(
- shared->listenSock, &clientAddr, Timeout(shared));
+ shared->listenSock, &clientAddr, Timeout(shared));
if (clientSock != NULL)
{
- if (NULL != shared->debug)
+ if (NULL != shared->debug) {
PR_fprintf(shared->debug, "reading length ... ");
+ }
bytes = PR_Recv(
- clientSock, &descriptor, sizeof(descriptor),
- flags, Timeout(shared));
+ clientSock, &descriptor, sizeof(descriptor),
+ flags, Timeout(shared));
if (sizeof(descriptor) == bytes)
{
/* and, before doing something stupid ... */
descriptor.length = PR_ntohl(descriptor.length);
descriptor.checksum = PR_ntohl(descriptor.checksum);
- if (NULL != shared->debug)
+ if (NULL != shared->debug) {
PR_fprintf(shared->debug, "%d bytes ... ", descriptor.length);
+ }
toread = descriptor.length;
if (recv_length < descriptor.length)
{
- if (NULL != buffer) PR_DELETE(buffer);
+ if (NULL != buffer) {
+ PR_DELETE(buffer);
+ }
buffer = (char*)PR_MALLOC(descriptor.length);
recv_length = descriptor.length;
}
for (toread = descriptor.length; toread > 0; toread -= bytes)
{
bytes = PR_Recv(
- clientSock, &buffer[descriptor.length - toread],
- toread, flags, Timeout(shared));
+ clientSock, &buffer[descriptor.length - toread],
+ toread, flags, Timeout(shared));
if (-1 == bytes)
{
- if (NULL != shared->debug)
+ if (NULL != shared->debug) {
PR_fprintf(shared->debug, "read data failed...");
+ }
bytes = 0;
}
}
@@ -102,8 +111,9 @@ static void Accept(void *arg)
PR_fprintf(shared->debug, "read desciptor failed...");
descriptor.length = -1;
}
- if (NULL != shared->debug)
+ if (NULL != shared->debug) {
PR_fprintf(shared->debug, "closing");
+ }
rv = PR_Shutdown(clientSock, PR_SHUTDOWN_BOTH);
if ((PR_FAILURE == rv) && (NULL != shared->debug))
{
@@ -112,17 +122,19 @@ static void Accept(void *arg)
}
rv = PR_Close(clientSock);
if (PR_FAILURE == rv) if (NULL != shared->debug)
- {
- PR_fprintf(shared->debug, " failed");
- shared->passed = PR_FALSE;
- }
+ {
+ PR_fprintf(shared->debug, " failed");
+ shared->passed = PR_FALSE;
+ }
if (descriptor.length > 0)
{
for (byte = 0; byte < descriptor.length; ++byte)
{
PRUint32 overflow = checksum & 0x80000000;
checksum = (checksum << 1);
- if (0x00000000 != overflow) checksum += 1;
+ if (0x00000000 != overflow) {
+ checksum += 1;
+ }
checksum += buffer[byte];
}
if ((descriptor.checksum != checksum) && (NULL != shared->debug))
@@ -138,19 +150,24 @@ static void Accept(void *arg)
PR_NotifyCondVar(shared->cv);
PR_Unlock(shared->ml);
}
- if (NULL != shared->debug)
+ if (NULL != shared->debug) {
PR_fprintf(shared->debug, "\n");
+ }
}
else
{
if (PR_PENDING_INTERRUPT_ERROR != PR_GetError())
{
- if (NULL != shared->debug) PL_PrintError("Accept");
+ if (NULL != shared->debug) {
+ PL_PrintError("Accept");
+ }
shared->passed = PR_FALSE;
}
}
} while (running == shared->status);
- if (NULL != buffer) PR_DELETE(buffer);
+ if (NULL != buffer) {
+ PR_DELETE(buffer);
+ }
} /* Accept */
PRIntn Tmoacc(PRIntn argc, char **argv)
@@ -158,9 +175,9 @@ PRIntn Tmoacc(PRIntn argc, char **argv)
PRStatus rv;
PRIntn exitStatus;
PRIntn index;
- Shared *shared;
- PLOptStatus os;
- PRThread **thread;
+ Shared *shared;
+ PLOptStatus os;
+ PRThread **thread;
PRNetAddr listenAddr;
PRSocketOptionData sockOpt;
PRIntn timeout = DEFAULT_TIMEOUT;
@@ -168,7 +185,7 @@ PRIntn Tmoacc(PRIntn argc, char **argv)
PRIntn backlog = DEFAULT_BACKLOG;
PRThreadScope thread_scope = PR_LOCAL_THREAD;
- PLOptState *opt = PL_CreateOptState(argc, argv, "dGb:t:T:R");
+ PLOptState *opt = PL_CreateOptState(argc, argv, "dGb:t:T:R");
shared = PR_NEWZAP(Shared);
@@ -179,37 +196,45 @@ PRIntn Tmoacc(PRIntn argc, char **argv)
shared->ml = PR_NewLock();
shared->cv = PR_NewCondVar(shared->ml);
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ 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 */
- shared->debug = PR_GetSpecialFD(PR_StandardError);
- break;
- case 'G': /* use global threads */
- thread_scope = PR_GLOBAL_THREAD;
- break;
- case 'b': /* size of listen backlog */
- backlog = atoi(opt->value);
- break;
- case 't': /* number of threads doing accept */
- threads = atoi(opt->value);
- break;
- case 'T': /* timeout used for network operations */
- timeout = atoi(opt->value);
- break;
- case 'R': /* randomize the timeout values */
- shared->random = PR_TRUE;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ shared->debug = PR_GetSpecialFD(PR_StandardError);
+ break;
+ case 'G': /* use global threads */
+ thread_scope = PR_GLOBAL_THREAD;
+ break;
+ case 'b': /* size of listen backlog */
+ backlog = atoi(opt->value);
+ break;
+ case 't': /* number of threads doing accept */
+ threads = atoi(opt->value);
+ break;
+ case 'T': /* timeout used for network operations */
+ timeout = atoi(opt->value);
+ break;
+ case 'R': /* randomize the timeout values */
+ shared->random = PR_TRUE;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
- if (0 == threads) threads = DEFAULT_THREADS;
- if (0 == backlog) backlog = DEFAULT_BACKLOG;
- if (0 == timeout) timeout = DEFAULT_TIMEOUT;
+ PL_DestroyOptState(opt);
+ if (0 == threads) {
+ threads = DEFAULT_THREADS;
+ }
+ if (0 == backlog) {
+ backlog = DEFAULT_BACKLOG;
+ }
+ if (0 == timeout) {
+ timeout = DEFAULT_TIMEOUT;
+ }
PR_STDIO_INIT();
memset(&listenAddr, 0, sizeof(listenAddr));
@@ -236,15 +261,16 @@ PRIntn Tmoacc(PRIntn argc, char **argv)
for (index = 0; index < threads; ++index)
{
thread[index] = PR_CreateThread(
- PR_USER_THREAD, Accept, shared,
- PR_PRIORITY_NORMAL, thread_scope,
- PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, Accept, shared,
+ PR_PRIORITY_NORMAL, thread_scope,
+ PR_JOINABLE_THREAD, 0);
PR_ASSERT(NULL != thread[index]);
}
PR_Lock(shared->ml);
- while (shared->status == running)
+ while (shared->status == running) {
PR_WaitCondVar(shared->cv, PR_INTERVAL_NO_TIMEOUT);
+ }
PR_Unlock(shared->ml);
for (index = 0; index < threads; ++index)
{
@@ -257,13 +283,17 @@ PRIntn Tmoacc(PRIntn argc, char **argv)
}
else
{
- if (shared->debug) PL_PrintError("Listen");
+ if (shared->debug) {
+ PL_PrintError("Listen");
+ }
shared->passed = PR_FALSE;
}
}
else
{
- if (shared->debug) PL_PrintError("Bind");
+ if (shared->debug) {
+ PL_PrintError("Bind");
+ }
shared->passed = PR_FALSE;
}
@@ -271,7 +301,9 @@ PRIntn Tmoacc(PRIntn argc, char **argv)
}
else
{
- if (shared->debug) PL_PrintError("Create");
+ if (shared->debug) {
+ PL_PrintError("Create");
+ }
shared->passed = PR_FALSE;
}
@@ -290,7 +322,7 @@ PRIntn Tmoacc(PRIntn argc, char **argv)
int main(int argc, char **argv)
{
return (PR_VersionCheck(PR_VERSION)) ?
- PR_Initialize(Tmoacc, argc, argv, 4) : -1;
+ PR_Initialize(Tmoacc, argc, argv, 4) : -1;
} /* main */
/* tmoacc */
diff --git a/pr/tests/tmocon.c b/pr/tests/tmocon.c
index c1e2f675..9d214bc5 100644
--- a/pr/tests/tmocon.c
+++ b/pr/tests/tmocon.c
@@ -11,10 +11,10 @@
**
** Modification History:
** 19-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.
***********************************************************************/
/***********************************************************************
@@ -87,7 +87,9 @@ static PRIntervalTime Timeout(const Shared *shared)
static void CauseTimeout(const Shared *shared)
{
- if (shared->intermittant) PR_Sleep(Timeout(shared));
+ if (shared->intermittant) {
+ PR_Sleep(Timeout(shared));
+ }
} /* CauseTimeout */
static PRStatus MakeReceiver(Shared *shared)
@@ -110,24 +112,30 @@ static PRStatus MakeReceiver(Shared *shared)
argv[1] = "-d";
argv[2] = NULL;
}
- else argv[1] = NULL;
- if (shared->debug > 1)
+ else {
+ argv[1] = NULL;
+ }
+ if (shared->debug > 1) {
PR_fprintf(debug_out, " creating accept process %s ...", path);
+ }
fflush(stdout);
rv = PR_CreateProcessDetached(path, argv, NULL, NULL);
if (PR_SUCCESS == rv)
{
- if (shared->debug > 1)
+ if (shared->debug > 1) {
PR_fprintf(debug_out, " wait 5 seconds");
- if (shared->debug > 1)
+ }
+ if (shared->debug > 1) {
PR_fprintf(debug_out, " before connecting to accept process ...");
+ }
fflush(stdout);
PR_Sleep(PR_SecondsToInterval(5));
return rv;
}
shared->failed = PR_TRUE;
- if (shared->debug > 0)
+ if (shared->debug > 0) {
PL_FPrintError(debug_out, "PR_CreateProcessDetached failed");
+ }
}
return rv;
} /* MakeReceiver */
@@ -139,28 +147,35 @@ static void Connect(void *arg)
PRFileDesc *clientSock;
Shared *shared = (Shared*)arg;
PRInt32 loop, bytes, flags = 0;
- struct Descriptor { PRInt32 length; PRUint32 checksum; } descriptor;
+ struct Descriptor {
+ PRInt32 length;
+ PRUint32 checksum;
+ } descriptor;
debug_out = (0 == shared->debug) ? NULL : PR_GetSpecialFD(PR_StandardError);
buffer = (char*)PR_MALLOC(shared->message_length);
- for (bytes = 0; bytes < shared->message_length; ++bytes)
+ for (bytes = 0; bytes < shared->message_length; ++bytes) {
buffer[bytes] = (char)bytes;
+ }
descriptor.checksum = 0;
for (bytes = 0; bytes < shared->message_length; ++bytes)
{
PRUint32 overflow = descriptor.checksum & 0x80000000;
descriptor.checksum = (descriptor.checksum << 1);
- if (0x00000000 != overflow) descriptor.checksum += 1;
+ if (0x00000000 != overflow) {
+ descriptor.checksum += 1;
+ }
descriptor.checksum += buffer[bytes];
}
descriptor.checksum = PR_htonl(descriptor.checksum);
for (loop = 0; loop < shared->messages; ++loop)
{
- if (shared->debug > 1)
+ if (shared->debug > 1) {
PR_fprintf(debug_out, "[%d]socket ... ", loop);
+ }
clientSock = PR_NewTCPSocket();
if (clientSock)
{
@@ -179,58 +194,72 @@ static void Connect(void *arg)
PR_fprintf(debug_out, "connecting to %s ... ", buf);
}
rv = PR_Connect(
- clientSock, &shared->serverAddress, Timeout(shared));
+ clientSock, &shared->serverAddress, Timeout(shared));
if (PR_SUCCESS == rv)
{
PRInt32 descriptor_length = (loop < (shared->messages - 1)) ?
- shared->message_length : 0;
+ shared->message_length : 0;
descriptor.length = PR_htonl(descriptor_length);
if (shared->debug > 1)
PR_fprintf(
debug_out, "sending %d bytes ... ", descriptor_length);
CauseTimeout(shared); /* might cause server to timeout */
bytes = PR_Send(
- clientSock, &descriptor, sizeof(descriptor),
- flags, Timeout(shared));
+ clientSock, &descriptor, sizeof(descriptor),
+ flags, Timeout(shared));
if (bytes != sizeof(descriptor))
{
shared->failed = PR_TRUE;
- if (shared->debug > 0)
+ if (shared->debug > 0) {
PL_FPrintError(debug_out, "PR_Send failed");
+ }
}
if (0 != descriptor_length)
{
CauseTimeout(shared);
bytes = PR_Send(
- clientSock, buffer, descriptor_length,
- flags, Timeout(shared));
+ clientSock, buffer, descriptor_length,
+ flags, Timeout(shared));
if (bytes != descriptor_length)
{
shared->failed = PR_TRUE;
- if (shared->debug > 0)
+ if (shared->debug > 0) {
PL_FPrintError(debug_out, "PR_Send failed");
+ }
}
}
- if (shared->debug > 1) PR_fprintf(debug_out, "closing ... ");
+ if (shared->debug > 1) {
+ PR_fprintf(debug_out, "closing ... ");
+ }
rv = PR_Shutdown(clientSock, PR_SHUTDOWN_BOTH);
rv = PR_Close(clientSock);
if (shared->debug > 1)
{
- if (PR_SUCCESS == rv) PR_fprintf(debug_out, "\n");
- else PL_FPrintError(debug_out, "shutdown failed");
+ if (PR_SUCCESS == rv) {
+ PR_fprintf(debug_out, "\n");
+ }
+ else {
+ PL_FPrintError(debug_out, "shutdown failed");
+ }
}
}
else
{
- if (shared->debug > 1) PL_FPrintError(debug_out, "connect failed");
+ if (shared->debug > 1) {
+ PL_FPrintError(debug_out, "connect failed");
+ }
PR_Close(clientSock);
if ((loop == 0) && (PR_GetError() == PR_CONNECT_REFUSED_ERROR))
{
- if (MakeReceiver(shared) == PR_FAILURE) break;
+ if (MakeReceiver(shared) == PR_FAILURE) {
+ break;
+ }
}
else
{
- if (shared->debug > 1) PR_fprintf(debug_out, " exiting\n");
+ if (shared->debug > 1) {
+ PR_fprintf(debug_out, " exiting\n");
+ }
break;
}
}
@@ -238,7 +267,9 @@ static void Connect(void *arg)
else
{
shared->failed = PR_TRUE;
- if (shared->debug > 0) PL_FPrintError(debug_out, "create socket");
+ if (shared->debug > 0) {
+ PL_FPrintError(debug_out, "create socket");
+ }
break;
}
}
@@ -288,25 +319,31 @@ int Tmocon(int argc, char **argv)
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':
- if (0 == shared->debug) shared->debug = 1;
- break;
- case 'v':
- if (0 == shared->debug) shared->debug = 2;
- break;
- case 'i':
- shared->intermittant = PR_TRUE;
- break;
- case 'R':
- shared->random = PR_TRUE;
- break;
- case 'G':
- thread_scope = PR_GLOBAL_THREAD;
- break;
- case 'h': /* the value for backlock */
+ case 'd':
+ if (0 == shared->debug) {
+ shared->debug = 1;
+ }
+ break;
+ case 'v':
+ if (0 == shared->debug) {
+ shared->debug = 2;
+ }
+ break;
+ case 'i':
+ shared->intermittant = PR_TRUE;
+ break;
+ case 'R':
+ shared->random = PR_TRUE;
+ break;
+ case 'G':
+ thread_scope = PR_GLOBAL_THREAD;
+ break;
+ case 'h': /* the value for backlock */
{
PRIntn es = 0;
PRHostEnt host;
@@ -314,35 +351,43 @@ int Tmocon(int argc, char **argv)
(void)PR_GetHostByName(
opt->value, buffer, sizeof(buffer), &host);
es = PR_EnumerateHostEnt(
- es, &host, BASE_PORT, &shared->serverAddress);
+ es, &host, BASE_PORT, &shared->serverAddress);
PR_ASSERT(es > 0);
}
break;
- case 'm': /* number of messages to send */
- shared->messages = atoi(opt->value);
- break;
- case 't': /* number of threads sending */
- threads = atoi(opt->value);
- break;
- case 'D': /* dally time between transmissions */
- dally = atoi(opt->value);
- break;
- case 'T': /* timeout on I/O operations */
- timeout = atoi(opt->value);
- break;
- case 's': /* total size of each message */
- shared->message_length = atoi(opt->value);
- break;
- default:
- break;
+ case 'm': /* number of messages to send */
+ shared->messages = atoi(opt->value);
+ break;
+ case 't': /* number of threads sending */
+ threads = atoi(opt->value);
+ break;
+ case 'D': /* dally time between transmissions */
+ dally = atoi(opt->value);
+ break;
+ case 'T': /* timeout on I/O operations */
+ timeout = atoi(opt->value);
+ break;
+ case 's': /* total size of each message */
+ shared->message_length = atoi(opt->value);
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- if (0 == timeout) timeout = DEFAULT_TIMEOUT;
- if (0 == threads) threads = DEFAULT_THREADS;
- if (0 == shared->messages) shared->messages = DEFAULT_MESSAGES;
- if (0 == shared->message_length) shared->message_length = DEFAULT_MESSAGESIZE;
+ if (0 == timeout) {
+ timeout = DEFAULT_TIMEOUT;
+ }
+ if (0 == threads) {
+ threads = DEFAULT_THREADS;
+ }
+ if (0 == shared->messages) {
+ shared->messages = DEFAULT_MESSAGES;
+ }
+ if (0 == shared->message_length) {
+ shared->message_length = DEFAULT_MESSAGESIZE;
+ }
shared->dally = PR_SecondsToInterval(dally);
shared->timeout = PR_SecondsToInterval(timeout);
@@ -351,11 +396,12 @@ int Tmocon(int argc, char **argv)
for (index = 0; index < threads; ++index)
thread[index] = PR_CreateThread(
- PR_USER_THREAD, Connect, shared,
- PR_PRIORITY_NORMAL, thread_scope,
- PR_JOINABLE_THREAD, 0);
- for (index = 0; index < threads; ++index)
+ PR_USER_THREAD, Connect, shared,
+ PR_PRIORITY_NORMAL, thread_scope,
+ PR_JOINABLE_THREAD, 0);
+ for (index = 0; index < threads; ++index) {
rv = PR_JoinThread(thread[index]);
+ }
PR_DELETE(thread);
@@ -370,7 +416,7 @@ int Tmocon(int argc, char **argv)
int main(int argc, char **argv)
{
return (PR_VersionCheck(PR_VERSION)) ?
- PR_Initialize(Tmocon, argc, argv, 4) : -1;
+ PR_Initialize(Tmocon, argc, argv, 4) : -1;
} /* main */
/* tmocon.c */
diff --git a/pr/tests/tpd.c b/pr/tests/tpd.c
index e1486fab..cac8c59a 100644
--- a/pr/tests/tpd.c
+++ b/pr/tests/tpd.c
@@ -46,8 +46,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) \
@@ -57,8 +58,12 @@ static void MyAssert(const char *expr, const char *file, PRIntn line)
static void PR_CALLBACK Destructor(void *data)
{
MY_ASSERT(NULL != data);
- if (should) did = PR_TRUE;
- else failed = PR_TRUE;
+ if (should) {
+ did = PR_TRUE;
+ }
+ else {
+ failed = PR_TRUE;
+ }
/*
* We don't actually free the storage since it's actually allocated
* on the stack. Normally, this would not be the case and this is
@@ -74,7 +79,8 @@ static void PR_CALLBACK Thread(void *null)
PRUintn keys;
char *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)
@@ -167,7 +173,8 @@ static PRIntn PR_CALLBACK Tpd(PRIntn argc, char **argv)
PRThread *thread;
char *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"
+ };
fout = PR_STDOUT;
@@ -195,8 +202,9 @@ static PRIntn PR_CALLBACK Tpd(PRIntn argc, char **argv)
}
PrintProgress(__LINE__);
- for (keys = 4; keys < 8; ++keys)
- key[keys] = 4096; /* set to invalid value */
+ for (keys = 4; keys < 8; ++keys) {
+ key[keys] = 4096; /* set to invalid value */
+ }
did = should = PR_FALSE;
for (keys = 4; keys < 8; ++keys)
{
@@ -255,8 +263,8 @@ static PRIntn PR_CALLBACK Tpd(PRIntn argc, char **argv)
}
thread = PR_CreateThread(
- PR_USER_THREAD, Thread, NULL, PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, Thread, NULL, PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
(void)PR_JoinThread(thread);
@@ -276,21 +284,23 @@ static PRIntn PR_CALLBACK Tpd(PRIntn argc, char **argv)
int main(int argc, char **argv)
{
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "dl:r:");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "dl:r:");
+ 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);
+ PL_DestroyOptState(opt);
PR_STDIO_INIT();
return PR_Initialize(Tpd, argc, argv, 0);
} /* main */
diff --git a/pr/tests/udpsrv.c b/pr/tests/udpsrv.c
index d8aa208f..39a919c6 100644
--- a/pr/tests/udpsrv.c
+++ b/pr/tests/udpsrv.c
@@ -98,7 +98,7 @@ void ListNetAddr( char *msg, PRNetAddr *na )
char mbuf[256];
sprintf( mbuf, "ListNetAddr: %s family: %d, port: %d, ip: %8.8X\n",
- msg, na->inet.family, PR_ntohs( na->inet.port), PR_ntohl(na->inet.ip) );
+ msg, na->inet.family, PR_ntohs( na->inet.port), PR_ntohl(na->inet.ip) );
#if 0
DPRINTF( mbuf );
#endif
@@ -138,7 +138,7 @@ static void PR_CALLBACK UDP_Server( void *arg )
passed = PR_FALSE;
if (debug_mode)
PR_fprintf(output,
- "udpsrv: UDP_Server(): PR_NewUDPSocket() returned NULL\n" );
+ "udpsrv: UDP_Server(): PR_NewUDPSocket() returned NULL\n" );
return;
}
@@ -167,13 +167,14 @@ static void PR_CALLBACK UDP_Server( void *arg )
passed = PR_FALSE;
if (debug_mode) PR_fprintf(output, "udpsrv: UDP_Server(): \
PR_Bind(): failed: %ld with error: %ld\n",
- rv, PR_GetError() );
+ rv, PR_GetError() );
PR_Close( svrSock );
return;
}
}
- else
+ else {
bound = PR_TRUE;
+ }
}
ListNetAddr( "UDP_Server: after bind", &netaddr );
@@ -187,8 +188,8 @@ static void PR_CALLBACK UDP_Server( void *arg )
passed = PR_FALSE;
if (debug_mode)
PR_fprintf(output,
- "udpsrv: UDP_Server(): PR_RecvFrom(): failed with error: %ld\n",
- PR_GetError() );
+ "udpsrv: UDP_Server(): PR_RecvFrom(): failed with error: %ld\n",
+ PR_GetError() );
PR_Close( svrSock );
return;
}
@@ -210,8 +211,8 @@ static void PR_CALLBACK UDP_Server( void *arg )
passed = PR_FALSE;
if (debug_mode)
PR_fprintf(output,
- "udpsrv: UDP_Server(): PR_SendTo(): failed with error: %ld\n",
- PR_GetError() );
+ "udpsrv: UDP_Server(): PR_SendTo(): failed with error: %ld\n",
+ PR_GetError() );
PR_Close( svrSock );
return;
}
@@ -226,7 +227,7 @@ static void PR_CALLBACK UDP_Server( void *arg )
passed = PR_FALSE;
if (debug_mode)
PR_fprintf(output,
- "udpsrv: UDP_Server(): PR_Close(): failed to close socket\n" );
+ "udpsrv: UDP_Server(): PR_Close(): failed to close socket\n" );
return;
}
@@ -275,7 +276,7 @@ static void PR_CALLBACK UDP_Client( void *arg )
passed = PR_FALSE;
if (debug_mode)
PR_fprintf(output,
- "udpsrv: UDP_Client(): PR_NewUDPSocket() returned NULL\n" );
+ "udpsrv: UDP_Client(): PR_NewUDPSocket() returned NULL\n" );
return;
}
@@ -286,8 +287,9 @@ static void PR_CALLBACK UDP_Client( void *arg )
netaddr.inet.port = PR_htons( UDP_CLIENT_PORT );
/* --- Initialize the write buffer --- */
- for ( i = 0; i < UDP_BUF_SIZE ; i++ )
+ for ( i = 0; i < UDP_BUF_SIZE ; i++ ) {
cltBuf[i] = i;
+ }
/* --- Bind the socket --- */
while ( !bound )
@@ -300,7 +302,7 @@ static void PR_CALLBACK UDP_Client( void *arg )
{
if (debug_mode)
PR_fprintf(output,
- "udpsrv: UDP_Client(): PR_Bind(): reports: PR_ADDRESS_IN_USE_ERROR\n");
+ "udpsrv: UDP_Client(): PR_Bind(): reports: PR_ADDRESS_IN_USE_ERROR\n");
PR_Sleep( PR_MillisecondsToInterval( 2000 ));
continue;
}
@@ -309,14 +311,15 @@ static void PR_CALLBACK UDP_Client( void *arg )
passed = PR_FALSE;
if (debug_mode)
PR_fprintf(output,
- "udpsrv: UDP_Client(): PR_Bind(): failed: %ld with error: %ld\n",
- rv, PR_GetError() );
+ "udpsrv: UDP_Client(): PR_Bind(): failed: %ld with error: %ld\n",
+ rv, PR_GetError() );
PR_Close( cltSock );
return;
}
}
- else
+ else {
bound = PR_TRUE;
+ }
}
ListNetAddr( "UDP_Client after Bind", &netaddr );
@@ -340,15 +343,17 @@ static void PR_CALLBACK UDP_Client( void *arg )
}
/* --- SendTo the socket --- */
- if ( writeThisMany > UDP_DGRAM_SIZE )
+ if ( writeThisMany > UDP_DGRAM_SIZE ) {
numBytes = UDP_DGRAM_SIZE;
- else
+ }
+ else {
numBytes = writeThisMany;
+ }
writeThisMany -= numBytes;
{
char mbuf[256];
sprintf( mbuf, "udpsrv: UDP_Client(): write_this_many: %d, numbytes: %d\n",
- writeThisMany, numBytes );
+ writeThisMany, numBytes );
DPRINTF( mbuf );
}
@@ -359,8 +364,8 @@ static void PR_CALLBACK UDP_Client( void *arg )
passed = PR_FALSE;
if (debug_mode)
PR_fprintf(output,
- "udpsrv: UDP_Client(): PR_SendTo(): failed with error: %ld\n",
- PR_GetError() );
+ "udpsrv: UDP_Client(): PR_SendTo(): failed with error: %ld\n",
+ PR_GetError() );
PR_Close( cltSock );
return;
}
@@ -374,8 +379,8 @@ static void PR_CALLBACK UDP_Client( void *arg )
{
passed = PR_FALSE;
if (debug_mode) PR_fprintf(output,
- "udpsrv: UDP_Client(): PR_RecvFrom(): failed with error: %ld\n",
- PR_GetError() );
+ "udpsrv: UDP_Client(): PR_RecvFrom(): failed with error: %ld\n",
+ PR_GetError() );
PR_Close( cltSock );
return;
}
@@ -388,16 +393,19 @@ static void PR_CALLBACK UDP_Client( void *arg )
if ( cltBufin[i] != i )
{
/* --- special case, end of input --- */
- if ( endOfInput && i == 0 && cltBufin[0] == 'E' )
+ if ( endOfInput && i == 0 && cltBufin[0] == 'E' ) {
continue;
+ }
passed = PR_FALSE;
if (debug_mode) PR_fprintf(output,
- "udpsrv: UDP_Client(): return data mismatch\n" );
+ "udpsrv: UDP_Client(): return data mismatch\n" );
PR_Close( cltSock );
return;
}
}
- if (debug_mode) PR_fprintf(output, ".");
+ if (debug_mode) {
+ PR_fprintf(output, ".");
+ }
}
/* --- Close the socket --- */
@@ -407,7 +415,7 @@ static void PR_CALLBACK UDP_Client( void *arg )
{
passed = PR_FALSE;
if (debug_mode) PR_fprintf(output,
- "udpsrv: UDP_Client(): PR_Close(): failed to close socket\n" );
+ "udpsrv: UDP_Client(): PR_Close(): failed to close socket\n" );
return;
}
DPRINTF("udpsrv: UDP_Client(): ending\n" );
@@ -434,30 +442,32 @@ static void PR_CALLBACK UDP_Client( void *arg )
int main(int argc, char **argv)
{
PRThread *srv, *clt;
-/* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d -v
- */
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "dv");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d -v
+ */
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "dv");
+ 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_mode = 1;
- break;
- case 'v': /* verbose mode */
- _debug_on = 1;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = 1;
+ break;
+ case 'v': /* verbose mode */
+ _debug_on = 1;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
PR_STDIO_INIT();
@@ -470,15 +480,17 @@ int main(int argc, char **argv)
*/
DPRINTF( "udpsrv: Creating Server Thread\n" );
srv = PR_CreateThread( PR_USER_THREAD,
- UDP_Server,
- (void *) 0,
- PR_PRIORITY_LOW,
- PR_LOCAL_THREAD,
- PR_JOINABLE_THREAD,
- 0 );
+ UDP_Server,
+ (void *) 0,
+ PR_PRIORITY_LOW,
+ PR_LOCAL_THREAD,
+ PR_JOINABLE_THREAD,
+ 0 );
if ( srv == NULL )
{
- if (debug_mode) PR_fprintf(output, "udpsrv: Cannot create server thread\n" );
+ if (debug_mode) {
+ PR_fprintf(output, "udpsrv: Cannot create server thread\n" );
+ }
passed = PR_FALSE;
}
@@ -493,15 +505,17 @@ int main(int argc, char **argv)
*/
DPRINTF( "udpsrv: Creating Client Thread\n" );
clt = PR_CreateThread( PR_USER_THREAD,
- UDP_Client,
- (void *) 0,
- PR_PRIORITY_LOW,
- PR_LOCAL_THREAD,
- PR_JOINABLE_THREAD,
- 0 );
+ UDP_Client,
+ (void *) 0,
+ PR_PRIORITY_LOW,
+ PR_LOCAL_THREAD,
+ PR_JOINABLE_THREAD,
+ 0 );
if ( clt == NULL )
{
- if (debug_mode) PR_fprintf(output, "udpsrv: Cannot create server thread\n" );
+ if (debug_mode) {
+ PR_fprintf(output, "udpsrv: Cannot create server thread\n" );
+ }
passed = PR_FALSE;
}
@@ -517,14 +531,16 @@ int main(int argc, char **argv)
*/
if (debug_mode) PR_fprintf(output, "\n\nudpsrv: main(): cltBytesRead(%ld), \
srvBytesRead(%ld), expected(%ld)\n",
- cltBytesRead, srvBytesRead, UDP_AMOUNT_TO_WRITE );
+ cltBytesRead, srvBytesRead, UDP_AMOUNT_TO_WRITE );
if ( cltBytesRead != srvBytesRead || cltBytesRead != UDP_AMOUNT_TO_WRITE )
{
passed = PR_FALSE;
}
PR_Cleanup();
- if ( passed )
+ if ( passed ) {
return 0;
- else
- return 1;
+ }
+ else {
+ return 1;
+ }
} /* --- end main() --- */
diff --git a/pr/tests/version.c b/pr/tests/version.c
index a1d4d962..49e8a05d 100644
--- a/pr/tests/version.c
+++ b/pr/tests/version.c
@@ -21,26 +21,28 @@ int main(int argc, char **argv)
PRLibrary *runtime = NULL;
const char *library_name = NULL;
const PRVersionDescription *version_info;
- char buffer[100];
- PRExplodedTime exploded;
+ char buffer[100];
+ PRExplodedTime exploded;
PLOptState *opt = PL_CreateOptState(argc, argv, "d");
PRFileDesc *err = PR_GetSpecialFD(PR_StandardError);
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: /* fully qualified library name */
- library_name = opt->value;
- break;
- case 'd': /* verbodity */
- verbosity += 1;
- break;
- default:
- PR_fprintf(err, "Usage: version [-d] {fully qualified library name}\n");
- return 2; /* but not a lot else */
+ case 0: /* fully qualified library name */
+ library_name = opt->value;
+ break;
+ case 'd': /* verbodity */
+ verbosity += 1;
+ break;
+ default:
+ PR_fprintf(err, "Usage: version [-d] {fully qualified library name}\n");
+ return 2; /* but not a lot else */
}
}
PL_DestroyOptState(opt);
@@ -49,42 +51,43 @@ int main(int argc, char **argv)
{
runtime = PR_LoadLibrary(library_name);
if (NULL == runtime) {
- PL_FPrintError(err, "PR_LoadLibrary");
- return 3;
- } else {
+ PL_FPrintError(err, "PR_LoadLibrary");
+ return 3;
+ } else {
versionEntryPointType versionPoint = (versionEntryPointType)
- PR_FindSymbol(runtime, "libVersionPoint");
+ PR_FindSymbol(runtime, "libVersionPoint");
if (NULL == versionPoint) {
- PL_FPrintError(err, "PR_FindSymbol");
- return 4;
- }
- version_info = versionPoint();
- }
- } else
- version_info = libVersionPoint(); /* NSPR's version info */
+ PL_FPrintError(err, "PR_FindSymbol");
+ return 4;
+ }
+ version_info = versionPoint();
+ }
+ } else {
+ version_info = libVersionPoint(); /* NSPR's version info */
+ }
- (void)PR_fprintf(err, "Runtime library version information\n");
- PR_ExplodeTime(
- version_info->buildTime, PR_GMTParameters, &exploded);
- (void)PR_FormatTime(
- buffer, sizeof(buffer), "%d %b %Y %H:%M:%S", &exploded);
- (void)PR_fprintf(err, " Build time: %s GMT\n", buffer);
- (void)PR_fprintf(
- err, " Build time: %s\n", version_info->buildTimeString);
- (void)PR_fprintf(
- err, " %s V%u.%u.%u (%s%s%s)\n",
- version_info->description,
- version_info->vMajor,
- version_info->vMinor,
- version_info->vPatch,
- (version_info->beta ? " beta " : ""),
- (version_info->debug ? " debug " : ""),
- (version_info->special ? " special" : ""));
- (void)PR_fprintf(err, " filename: %s\n", version_info->filename);
- (void)PR_fprintf(err, " security: %s\n", version_info->security);
- (void)PR_fprintf(err, " copyright: %s\n", version_info->copyright);
- (void)PR_fprintf(err, " comment: %s\n", version_info->comment);
- rv = 0;
+ (void)PR_fprintf(err, "Runtime library version information\n");
+ PR_ExplodeTime(
+ version_info->buildTime, PR_GMTParameters, &exploded);
+ (void)PR_FormatTime(
+ buffer, sizeof(buffer), "%d %b %Y %H:%M:%S", &exploded);
+ (void)PR_fprintf(err, " Build time: %s GMT\n", buffer);
+ (void)PR_fprintf(
+ err, " Build time: %s\n", version_info->buildTimeString);
+ (void)PR_fprintf(
+ err, " %s V%u.%u.%u (%s%s%s)\n",
+ version_info->description,
+ version_info->vMajor,
+ version_info->vMinor,
+ version_info->vPatch,
+ (version_info->beta ? " beta " : ""),
+ (version_info->debug ? " debug " : ""),
+ (version_info->special ? " special" : ""));
+ (void)PR_fprintf(err, " filename: %s\n", version_info->filename);
+ (void)PR_fprintf(err, " security: %s\n", version_info->security);
+ (void)PR_fprintf(err, " copyright: %s\n", version_info->copyright);
+ (void)PR_fprintf(err, " comment: %s\n", version_info->comment);
+ rv = 0;
return rv;
}
diff --git a/pr/tests/writev.c b/pr/tests/writev.c
index df76ff6d..7b761648 100644
--- a/pr/tests/writev.c
+++ b/pr/tests/writev.c
@@ -31,7 +31,10 @@ int PR_CALLBACK Writev(int argc, char **argv)
PRIntervalTime tmo_min = 0x7fffffff, tmo_max = 0, tmo_elapsed = 0;
PRInt32 tmo_counted = 0, iov_index, loop, bytes, number_fragments;
PRInt32 message_length = 100, fragment_length = 100, messages = 100;
- struct Descriptor { PRInt32 length; PRUint32 checksum; } descriptor;
+ struct Descriptor {
+ PRInt32 length;
+ PRUint32 checksum;
+ } descriptor;
/*
* USAGE
@@ -41,19 +44,21 @@ int PR_CALLBACK Writev(int argc, char **argv)
* -f size of each message fragment (default = 100)
*/
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "dh:m:s:f:");
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "dh:m:s:f:");
PR_STDIO_INIT();
rv = PR_InitializeNetAddr(PR_IpAddrLoopback, BASE_PORT, &serverAddr);
PR_ASSERT(PR_SUCCESS == rv);
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
{
- if (PL_OPT_BAD == os) continue;
+ if (PL_OPT_BAD == os) {
+ continue;
+ }
switch (opt->option)
{
- case 'h': /* the remote host */
+ case 'h': /* the remote host */
{
PRIntn es = 0;
PRHostEnt host;
@@ -63,23 +68,23 @@ int PR_CALLBACK Writev(int argc, char **argv)
PR_ASSERT(es > 0);
}
break;
- case 'd': /* debug mode */
- debug = PR_GetSpecialFD(PR_StandardError);
- break;
- case 'm': /* number of messages to send */
- messages = atoi(opt->value);
- break;
- case 's': /* total size of each message */
- message_length = atoi(opt->value);
- break;
- case 'f': /* size of each message fragment */
- fragment_length = atoi(opt->value);
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug = PR_GetSpecialFD(PR_StandardError);
+ break;
+ case 'm': /* number of messages to send */
+ messages = atoi(opt->value);
+ break;
+ case 's': /* total size of each message */
+ message_length = atoi(opt->value);
+ break;
+ case 'f': /* size of each message fragment */
+ fragment_length = atoi(opt->value);
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
buffer = (char*)malloc(message_length);
@@ -88,9 +93,9 @@ int PR_CALLBACK Writev(int argc, char **argv)
{
fragment_length = message_length / (IOV_MAX - 2);
number_fragments = (message_length + fragment_length - 1) /
- fragment_length + 1;
+ fragment_length + 1;
if (NULL != debug) PR_fprintf(debug,
- "Too many fragments - reset fragment length to %ld\n", fragment_length);
+ "Too many fragments - reset fragment length to %ld\n", fragment_length);
}
iov = (PRIOVec*)malloc(number_fragments * sizeof(PRIOVec));
@@ -102,60 +107,72 @@ int PR_CALLBACK Writev(int argc, char **argv)
iov[iov_index].iov_len = fragment_length;
}
- for (bytes = 0; bytes < message_length; ++bytes)
+ for (bytes = 0; bytes < message_length; ++bytes) {
buffer[bytes] = (char)bytes;
+ }
timeout = PR_SecondsToInterval(1);
for (loop = 0; loop < messages; ++loop)
{
- if (NULL != debug)
+ if (NULL != debug) {
PR_fprintf(debug, "[%d]socket ... ", loop);
+ }
clientSock = PR_NewTCPSocket();
if (clientSock)
{
timein = PR_IntervalNow();
- if (NULL != debug)
+ if (NULL != debug) {
PR_fprintf(debug, "connecting ... ");
+ }
rv = PR_Connect(clientSock, &serverAddr, timeout);
if (PR_SUCCESS == rv)
{
descriptor.checksum = 0;
descriptor.length = (loop < (messages - 1)) ? message_length : 0;
- if (0 == descriptor.length) number_fragments = 1;
+ if (0 == descriptor.length) {
+ number_fragments = 1;
+ }
else
for (iov_index = 0; iov_index < descriptor.length; ++iov_index)
{
PRUint32 overflow = descriptor.checksum & 0x80000000;
descriptor.checksum = (descriptor.checksum << 1);
- if (0x00000000 != overflow) descriptor.checksum += 1;
+ if (0x00000000 != overflow) {
+ descriptor.checksum += 1;
+ }
descriptor.checksum += buffer[iov_index];
}
if (NULL != debug) PR_fprintf(
- debug, "sending %d bytes ... ", descriptor.length);
+ debug, "sending %d bytes ... ", descriptor.length);
/* then, at the last moment ... */
descriptor.length = PR_ntohl(descriptor.length);
descriptor.checksum = PR_ntohl(descriptor.checksum);
bytes = PR_Writev(clientSock, iov, number_fragments, timeout);
- if (NULL != debug)
+ if (NULL != debug) {
PR_fprintf(debug, "closing ... ");
+ }
rv = PR_Shutdown(clientSock, PR_SHUTDOWN_BOTH);
rv = PR_Close(clientSock);
if (NULL != debug) PR_fprintf(
- debug, "%s\n", ((PR_SUCCESS == rv) ? "good" : "bad"));
+ debug, "%s\n", ((PR_SUCCESS == rv) ? "good" : "bad"));
elapsed = PR_IntervalNow() - timein;
- if (elapsed < tmo_min) tmo_min = elapsed;
- else if (elapsed > tmo_max) tmo_max = elapsed;
+ if (elapsed < tmo_min) {
+ tmo_min = elapsed;
+ }
+ else if (elapsed > tmo_max) {
+ tmo_max = elapsed;
+ }
tmo_elapsed += elapsed;
tmo_counted += 1;
}
else
{
if (NULL != debug) PR_fprintf(
- debug, "failed - retrying (%d, %d)\n",
- PR_GetError(), PR_GetOSError());
+ debug, "failed - retrying (%d, %d)\n",
+ PR_GetError(), PR_GetOSError());
PR_Close(clientSock);
}
}
@@ -169,12 +186,12 @@ int PR_CALLBACK Writev(int argc, char **argv)
if (0 == tmo_counted) {
PR_fprintf(debug, "No connection made\n");
} else {
- PR_fprintf(
- debug, "\nTimings: %d [%d] %d (microseconds)\n",
- PR_IntervalToMicroseconds(tmo_min),
- PR_IntervalToMicroseconds(tmo_elapsed / tmo_counted),
- PR_IntervalToMicroseconds(tmo_max));
- }
+ PR_fprintf(
+ debug, "\nTimings: %d [%d] %d (microseconds)\n",
+ PR_IntervalToMicroseconds(tmo_min),
+ PR_IntervalToMicroseconds(tmo_elapsed / tmo_counted),
+ PR_IntervalToMicroseconds(tmo_max));
+ }
}
PR_DELETE(buffer);
@@ -189,7 +206,7 @@ int PR_CALLBACK Writev(int argc, char **argv)
int main(int argc, char **argv)
{
return (PR_VersionCheck(PR_VERSION)) ?
- PR_Initialize(Writev, argc, argv, 4) : -1;
+ PR_Initialize(Writev, argc, argv, 4) : -1;
} /* main */
/* writev.c */
diff --git a/pr/tests/xnotify.c b/pr/tests/xnotify.c
index 00d35210..7e6f0e29 100644
--- a/pr/tests/xnotify.c
+++ b/pr/tests/xnotify.c
@@ -43,8 +43,12 @@ static void LogNow(const char *msg, PRStatus rv)
PRIntervalTime now = PR_IntervalNow();
PR_Lock(ml);
PR_fprintf(err, "%6ld: %s", (now - base), msg);
- if (PR_FAILURE == rv) PL_FPrintError(err, " ");
- else PR_fprintf(err, "\n");
+ if (PR_FAILURE == rv) {
+ PL_FPrintError(err, " ");
+ }
+ else {
+ PR_fprintf(err, "\n");
+ }
PR_Unlock(ml);
} /* LogNow */
@@ -66,12 +70,20 @@ static void PR_CALLBACK T2CMon(void *arg)
PR_CEnterMonitor(&shared->o1);
LogNow("T2 waiting 5 seconds on o1", PR_SUCCESS);
rv = PR_CWait(&shared->o1, PR_SecondsToInterval(5));
- if (PR_SUCCESS == rv) LogNow("T2 resuming on o1", rv);
- else LogNow("T2 wait failed on o1", rv);
+ if (PR_SUCCESS == rv) {
+ LogNow("T2 resuming on o1", rv);
+ }
+ else {
+ LogNow("T2 wait failed on o1", rv);
+ }
rv = PR_CNotify(&shared->o1);
- if (PR_SUCCESS == rv) LogNow("T2 notified o1", rv);
- else LogNow("T2 notify on o1 failed", rv);
+ if (PR_SUCCESS == rv) {
+ LogNow("T2 notified o1", rv);
+ }
+ else {
+ LogNow("T2 notify on o1 failed", rv);
+ }
PR_CExitMonitor(&shared->o1);
} /* T2CMon */
@@ -84,8 +96,12 @@ static void PR_CALLBACK T3CMon(void *arg)
PR_CEnterMonitor(&shared->o2);
LogNow("T3 waiting 5 seconds on o2", PR_SUCCESS);
rv = PR_CWait(&shared->o2, PR_SecondsToInterval(5));
- if (PR_SUCCESS == rv) LogNow("T3 resuming on o2", rv);
- else LogNow("T3 wait failed on o2", rv);
+ if (PR_SUCCESS == rv) {
+ LogNow("T3 resuming on o2", rv);
+ }
+ else {
+ LogNow("T3 wait failed on o2", rv);
+ }
rv = PR_CNotify(&shared->o2);
LogNow("T3 notify on o2", rv);
PR_CExitMonitor(&shared->o2);
@@ -108,25 +124,33 @@ static void T1CMon(void)
PR_CEnterMonitor(&sharedCM.o1);
LogNow("T1 waiting 3 seconds on o1", PR_SUCCESS);
rv = PR_CWait(&sharedCM.o1, PR_SecondsToInterval(3));
- if (PR_SUCCESS == rv) LogNow("T1 resuming on o1", rv);
- else LogNow("T1 wait on o1 failed", rv);
+ if (PR_SUCCESS == rv) {
+ LogNow("T1 resuming on o1", rv);
+ }
+ else {
+ LogNow("T1 wait on o1 failed", rv);
+ }
PR_CExitMonitor(&sharedCM.o1);
LogNow("T1 creating T2", PR_SUCCESS);
t2 = PR_CreateThread(
- PR_USER_THREAD, T2CMon, &sharedCM, PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, T2CMon, &sharedCM, PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
LogNow("T1 creating T3", PR_SUCCESS);
t3 = PR_CreateThread(
- PR_USER_THREAD, T3CMon, &sharedCM, PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, T3CMon, &sharedCM, PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
PR_CEnterMonitor(&sharedCM.o2);
LogNow("T1 waiting forever on o2", PR_SUCCESS);
rv = PR_CWait(&sharedCM.o2, PR_INTERVAL_NO_TIMEOUT);
- if (PR_SUCCESS == rv) LogNow("T1 resuming on o2", rv);
- else LogNow("T1 wait on o2 failed", rv);
+ if (PR_SUCCESS == rv) {
+ LogNow("T1 resuming on o2", rv);
+ }
+ else {
+ LogNow("T1 wait on o2 failed", rv);
+ }
PR_CExitMonitor(&sharedCM.o2);
(void)PR_JoinThread(t2);
@@ -142,12 +166,20 @@ static void PR_CALLBACK T2Mon(void *arg)
PR_EnterMonitor(shared->o1);
LogNow("T2 waiting 5 seconds on o1", PR_SUCCESS);
rv = PR_Wait(shared->o1, PR_SecondsToInterval(5));
- if (PR_SUCCESS == rv) LogNow("T2 resuming on o1", rv);
- else LogNow("T2 wait failed on o1", rv);
+ if (PR_SUCCESS == rv) {
+ LogNow("T2 resuming on o1", rv);
+ }
+ else {
+ LogNow("T2 wait failed on o1", rv);
+ }
rv = PR_Notify(shared->o1);
- if (PR_SUCCESS == rv) LogNow("T2 notified o1", rv);
- else LogNow("T2 notify on o1 failed", rv);
+ if (PR_SUCCESS == rv) {
+ LogNow("T2 notified o1", rv);
+ }
+ else {
+ LogNow("T2 notify on o1 failed", rv);
+ }
PR_ExitMonitor(shared->o1);
} /* T2Mon */
@@ -160,8 +192,12 @@ static void PR_CALLBACK T3Mon(void *arg)
PR_EnterMonitor(shared->o2);
LogNow("T3 waiting 5 seconds on o2", PR_SUCCESS);
rv = PR_Wait(shared->o2, PR_SecondsToInterval(5));
- if (PR_SUCCESS == rv) LogNow("T3 resuming on o2", rv);
- else LogNow("T3 wait failed on o2", rv);
+ if (PR_SUCCESS == rv) {
+ LogNow("T3 resuming on o2", rv);
+ }
+ else {
+ LogNow("T3 wait failed on o2", rv);
+ }
rv = PR_Notify(shared->o2);
LogNow("T3 notify on o2", rv);
PR_ExitMonitor(shared->o2);
@@ -186,25 +222,33 @@ static void T1Mon(void)
PR_EnterMonitor(sharedM.o1);
LogNow("T1 waiting 3 seconds on o1", PR_SUCCESS);
rv = PR_Wait(sharedM.o1, PR_SecondsToInterval(3));
- if (PR_SUCCESS == rv) LogNow("T1 resuming on o1", rv);
- else LogNow("T1 wait on o1 failed", rv);
+ if (PR_SUCCESS == rv) {
+ LogNow("T1 resuming on o1", rv);
+ }
+ else {
+ LogNow("T1 wait on o1 failed", rv);
+ }
PR_ExitMonitor(sharedM.o1);
LogNow("T1 creating T2", PR_SUCCESS);
t2 = PR_CreateThread(
- PR_USER_THREAD, T2Mon, &sharedM, PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, T2Mon, &sharedM, PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
LogNow("T1 creating T3", PR_SUCCESS);
t3 = PR_CreateThread(
- PR_USER_THREAD, T3Mon, &sharedM, PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, T3Mon, &sharedM, PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
PR_EnterMonitor(sharedM.o2);
LogNow("T1 waiting forever on o2", PR_SUCCESS);
rv = PR_Wait(sharedM.o2, PR_INTERVAL_NO_TIMEOUT);
- if (PR_SUCCESS == rv) LogNow("T1 resuming on o2", rv);
- else LogNow("T1 wait on o2 failed", rv);
+ if (PR_SUCCESS == rv) {
+ LogNow("T1 resuming on o2", rv);
+ }
+ else {
+ LogNow("T1 wait on o2 failed", rv);
+ }
PR_ExitMonitor(sharedM.o2);
(void)PR_JoinThread(t2);
@@ -223,12 +267,20 @@ static void PR_CALLBACK T2Lock(void *arg)
PR_Lock(shared->o1);
LogNow("T2 waiting 5 seconds on o1", PR_SUCCESS);
rv = PR_WaitCondVar(shared->cv1, PR_SecondsToInterval(5));
- if (PR_SUCCESS == rv) LogNow("T2 resuming on o1", rv);
- else LogNow("T2 wait failed on o1", rv);
+ if (PR_SUCCESS == rv) {
+ LogNow("T2 resuming on o1", rv);
+ }
+ else {
+ LogNow("T2 wait failed on o1", rv);
+ }
rv = PR_NotifyCondVar(shared->cv1);
- if (PR_SUCCESS == rv) LogNow("T2 notified o1", rv);
- else LogNow("T2 notify on o1 failed", rv);
+ if (PR_SUCCESS == rv) {
+ LogNow("T2 notified o1", rv);
+ }
+ else {
+ LogNow("T2 notify on o1 failed", rv);
+ }
PR_Unlock(shared->o1);
} /* T2Lock */
@@ -241,8 +293,12 @@ static void PR_CALLBACK T3Lock(void *arg)
PR_Lock(shared->o2);
LogNow("T3 waiting 5 seconds on o2", PR_SUCCESS);
rv = PR_WaitCondVar(shared->cv2, PR_SecondsToInterval(5));
- if (PR_SUCCESS == rv) LogNow("T3 resuming on o2", rv);
- else LogNow("T3 wait failed on o2", rv);
+ if (PR_SUCCESS == rv) {
+ LogNow("T3 resuming on o2", rv);
+ }
+ else {
+ LogNow("T3 wait failed on o2", rv);
+ }
rv = PR_NotifyCondVar(shared->cv2);
LogNow("T3 notify on o2", rv);
PR_Unlock(shared->o2);
@@ -272,25 +328,33 @@ static void T1Lock(void)
PR_Lock(sharedL.o1);
LogNow("T1 waiting 3 seconds on o1", PR_SUCCESS);
rv = PR_WaitCondVar(sharedL.cv1, PR_SecondsToInterval(3));
- if (PR_SUCCESS == rv) LogNow("T1 resuming on o1", rv);
- else LogNow("T1 wait on o1 failed", rv);
+ if (PR_SUCCESS == rv) {
+ LogNow("T1 resuming on o1", rv);
+ }
+ else {
+ LogNow("T1 wait on o1 failed", rv);
+ }
PR_Unlock(sharedL.o1);
LogNow("T1 creating T2", PR_SUCCESS);
t2 = PR_CreateThread(
- PR_USER_THREAD, T2Lock, &sharedL, PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, T2Lock, &sharedL, PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
LogNow("T1 creating T3", PR_SUCCESS);
t3 = PR_CreateThread(
- PR_USER_THREAD, T3Lock, &sharedL, PR_PRIORITY_NORMAL,
- PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
+ PR_USER_THREAD, T3Lock, &sharedL, PR_PRIORITY_NORMAL,
+ PR_LOCAL_THREAD, PR_JOINABLE_THREAD, 0);
PR_Lock(sharedL.o2);
LogNow("T1 waiting forever on o2", PR_SUCCESS);
rv = PR_WaitCondVar(sharedL.cv2, PR_INTERVAL_NO_TIMEOUT);
- if (PR_SUCCESS == rv) LogNow("T1 resuming on o2", rv);
- else LogNow("T1 wait on o2 failed", rv);
+ if (PR_SUCCESS == rv) {
+ LogNow("T1 resuming on o2", rv);
+ }
+ else {
+ LogNow("T1 wait on o2 failed", rv);
+ }
PR_Unlock(sharedL.o2);
(void)PR_JoinThread(t2);
@@ -304,40 +368,48 @@ static void T1Lock(void)
static PRIntn PR_CALLBACK RealMain( PRIntn argc, char **argv )
{
- PLOptStatus os;
- PLOptState *opt = PL_CreateOptState(argc, argv, "dhlmc");
- PRBool locks = PR_FALSE, monitors = PR_FALSE, cmonitors = PR_FALSE;
+ PLOptStatus os;
+ PLOptState *opt = PL_CreateOptState(argc, argv, "dhlmc");
+ PRBool locks = PR_FALSE, monitors = PR_FALSE, cmonitors = PR_FALSE;
err = PR_GetSpecialFD(PR_StandardError);
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ 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 (noop) */
- break;
- case 'l': /* locks */
- locks = PR_TRUE;
- break;
- case 'm': /* monitors */
- monitors = PR_TRUE;
- break;
- case 'c': /* cached monitors */
- cmonitors = PR_TRUE;
- break;
- case 'h': /* needs guidance */
- default:
- Help();
- return 2;
+ case 'd': /* debug mode (noop) */
+ break;
+ case 'l': /* locks */
+ locks = PR_TRUE;
+ break;
+ case 'm': /* monitors */
+ monitors = PR_TRUE;
+ break;
+ case 'c': /* cached monitors */
+ cmonitors = PR_TRUE;
+ break;
+ case 'h': /* needs guidance */
+ default:
+ Help();
+ return 2;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
ml = PR_NewLock();
- if (locks) T1Lock();
- if (monitors) T1Mon();
- if (cmonitors) T1CMon();
+ if (locks) {
+ T1Lock();
+ }
+ if (monitors) {
+ T1Mon();
+ }
+ if (cmonitors) {
+ T1CMon();
+ }
PR_DestroyLock(ml);
diff --git a/pr/tests/y2k.c b/pr/tests/y2k.c
index 80934142..31b35e7e 100644
--- a/pr/tests/y2k.c
+++ b/pr/tests/y2k.c
@@ -30,10 +30,11 @@ int failed_already=0;
PRBool debug_mode = PR_FALSE;
static char *dayOfWeek[] =
- { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???" };
+{ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???" };
static char *month[] =
- { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
- "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???" };
+{ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"
+};
PRLogModuleInfo *lm;
@@ -44,8 +45,8 @@ static void PrintExplodedTime(const PRExplodedTime *et) {
/* Print day of the week, month, day, hour, minute, and second */
printf("%s %s %2ld %02ld:%02ld:%02ld ",
- dayOfWeek[et->tm_wday], month[et->tm_month], et->tm_mday,
- et->tm_hour, et->tm_min, et->tm_sec);
+ dayOfWeek[et->tm_wday], month[et->tm_month], et->tm_mday,
+ et->tm_hour, et->tm_min, et->tm_sec);
/* Print year */
printf("%hd ", et->tm_year);
@@ -53,49 +54,49 @@ static void PrintExplodedTime(const PRExplodedTime *et) {
/* Print time zone */
totalOffset = et->tm_params.tp_gmt_offset + et->tm_params.tp_dst_offset;
if (totalOffset == 0) {
- printf("UTC ");
+ printf("UTC ");
} else {
sign = "+";
if (totalOffset < 0) {
- totalOffset = -totalOffset;
- sign = "-";
+ totalOffset = -totalOffset;
+ sign = "-";
}
hourOffset = totalOffset / 3600;
minOffset = (totalOffset % 3600) / 60;
printf("%s%02ld%02ld ", sign, hourOffset, minOffset);
}
#ifdef PRINT_DETAILS
- printf("{%d, %d, %d, %d, %d, %d, %d, %d, %d, { %d, %d}}\n",et->tm_usec,
- et->tm_sec,
- et->tm_min,
- et->tm_hour,
- et->tm_mday,
- et->tm_month,
- et->tm_year,
- et->tm_wday,
- et->tm_yday,
- et->tm_params.tp_gmt_offset,
- et->tm_params.tp_dst_offset);
+ printf("{%d, %d, %d, %d, %d, %d, %d, %d, %d, { %d, %d}}\n",et->tm_usec,
+ et->tm_sec,
+ et->tm_min,
+ et->tm_hour,
+ et->tm_mday,
+ et->tm_month,
+ et->tm_year,
+ et->tm_wday,
+ et->tm_yday,
+ et->tm_params.tp_gmt_offset,
+ et->tm_params.tp_dst_offset);
#endif
}
static int ExplodedTimeIsEqual(const PRExplodedTime *et1,
- const PRExplodedTime *et2)
+ const PRExplodedTime *et2)
{
if (et1->tm_usec == et2->tm_usec &&
- et1->tm_sec == et2->tm_sec &&
- et1->tm_min == et2->tm_min &&
- et1->tm_hour == et2->tm_hour &&
- et1->tm_mday == et2->tm_mday &&
- et1->tm_month == et2->tm_month &&
- et1->tm_year == et2->tm_year &&
- et1->tm_wday == et2->tm_wday &&
- et1->tm_yday == et2->tm_yday &&
- et1->tm_params.tp_gmt_offset == et2->tm_params.tp_gmt_offset &&
- et1->tm_params.tp_dst_offset == et2->tm_params.tp_dst_offset) {
+ et1->tm_sec == et2->tm_sec &&
+ et1->tm_min == et2->tm_min &&
+ et1->tm_hour == et2->tm_hour &&
+ et1->tm_mday == et2->tm_mday &&
+ et1->tm_month == et2->tm_month &&
+ et1->tm_year == et2->tm_year &&
+ et1->tm_wday == et2->tm_wday &&
+ et1->tm_yday == et2->tm_yday &&
+ et1->tm_params.tp_gmt_offset == et2->tm_params.tp_gmt_offset &&
+ et1->tm_params.tp_dst_offset == et2->tm_params.tp_dst_offset) {
return 1;
} else {
- return 0;
+ return 0;
}
}
@@ -164,12 +165,12 @@ static PRExplodedTime gmt[] = {
};
static PRExplodedTime uspt[] = {
-{ 0, 0, 0, 2, 31, 11, 1999, 5, 364, {-28800, 0}}, /* 1999/12/31 2:00:00 PST */
-{ 0, 0, 0, 2, 1, 0, 2000, 6, 0, {-28800, 0}}, /* 2000/01/01 2:00:00 PST */
-{ 0, 0, 0, 2, 29, 1, 2000, 2, 59, {-28800, 0}}, /* 2000/02/29 2:00:00 PST */
-{ 0, 0, 0, 2, 1, 2, 2001, 4, 59, {-28800, 0}}, /* 2001/3/1 2:00:00 PST */
-{ 0, 0, 0, 2, 1, 2, 2005, 2, 59, {-28800, 0}}, /* 2005/3/1 2:00:00 PST */
-{ 0, 0, 0, 3, 9, 8, 1999, 4, 251, {-28800, 3600}}, /* 1999/9/9 3:00:00 PDT */
+ { 0, 0, 0, 2, 31, 11, 1999, 5, 364, {-28800, 0}}, /* 1999/12/31 2:00:00 PST */
+ { 0, 0, 0, 2, 1, 0, 2000, 6, 0, {-28800, 0}}, /* 2000/01/01 2:00:00 PST */
+ { 0, 0, 0, 2, 29, 1, 2000, 2, 59, {-28800, 0}}, /* 2000/02/29 2:00:00 PST */
+ { 0, 0, 0, 2, 1, 2, 2001, 4, 59, {-28800, 0}}, /* 2001/3/1 2:00:00 PST */
+ { 0, 0, 0, 2, 1, 2, 2005, 2, 59, {-28800, 0}}, /* 2005/3/1 2:00:00 PST */
+ { 0, 0, 0, 3, 9, 8, 1999, 4, 251, {-28800, 3600}}, /* 1999/9/9 3:00:00 PDT */
/* Sun's dates follow */
{ 0, 0, 0, 2, 31, 11, 1998, 4, 364, {-28800, 0}}, /* 12/31/1998 00:00:00 GMT */
{ 0, 0, 0, 3, 10, 8, 1999, 5, 252, {-28800, 3600}}, /* 9/10/1999 00:00:00 GMT */
@@ -186,12 +187,12 @@ static PRExplodedTime uspt[] = {
* Zone is provided as an example.
*/
static PRExplodedTime localt[] = {
-{ 0, 0, 0, 2, 31, 11, 1999, 5, 364, {-28800, 0}}, /* 1999/12/31 2:00:00 PST */
-{ 0, 0, 0, 2, 1, 0, 2000, 6, 0, {-28800, 0}}, /* 2000/01/01 2:00:00 PST */
-{ 0, 0, 0, 2, 29, 1, 2000, 2, 59, {-28800, 0}}, /* 2000/02/29 2:00:00 PST */
-{ 0, 0, 0, 2, 1, 2, 2001, 4, 59, {-28800, 0}}, /* 2001/3/1 2:00:00 PST */
-{ 0, 0, 0, 2, 1, 2, 2005, 2, 59, {-28800, 0}}, /* 2005/3/1 2:00:00 PST */
-{ 0, 0, 0, 3, 9, 8, 1999, 4, 251, {-28800, 3600}}, /* 1999/9/9 3:00:00 PDT */
+ { 0, 0, 0, 2, 31, 11, 1999, 5, 364, {-28800, 0}}, /* 1999/12/31 2:00:00 PST */
+ { 0, 0, 0, 2, 1, 0, 2000, 6, 0, {-28800, 0}}, /* 2000/01/01 2:00:00 PST */
+ { 0, 0, 0, 2, 29, 1, 2000, 2, 59, {-28800, 0}}, /* 2000/02/29 2:00:00 PST */
+ { 0, 0, 0, 2, 1, 2, 2001, 4, 59, {-28800, 0}}, /* 2001/3/1 2:00:00 PST */
+ { 0, 0, 0, 2, 1, 2, 2005, 2, 59, {-28800, 0}}, /* 2005/3/1 2:00:00 PST */
+ { 0, 0, 0, 3, 9, 8, 1999, 4, 251, {-28800, 3600}}, /* 1999/9/9 3:00:00 PDT */
/* Sun's dates follow */
{ 0, 0, 0, 2, 31, 11, 1998, 4, 364, {-28800, 0}}, /* 12/31/1998 00:00:00 GMT */
{ 0, 0, 0, 3, 10, 8, 1999, 5, 252, {-28800, 3600}}, /* 9/10/1999 00:00:00 GMT */
@@ -202,12 +203,12 @@ static PRExplodedTime localt[] = {
#ifdef US_EASTERN_TIME
static PRExplodedTime localt[] = {
-{ 0, 0, 0, 5, 31, 11, 1999, 5, 364, {-18000, 0}}, /* 1999/12/31 2:00:00 EST */
-{ 0, 0, 0, 5, 1, 0, 2000, 6, 0, {-18000, 0}}, /* 2000/01/01 2:00:00 EST */
-{ 0, 0, 0, 5, 29, 1, 2000, 2, 59, {-18000, 0}}, /* 2000/02/29 2:00:00 EST */
-{ 0, 0, 0, 5, 1, 2, 2001, 4, 59, {-18000, 0}}, /* 2001/3/1 2:00:00 EST */
-{ 0, 0, 0, 5, 1, 2, 2005, 2, 59, {-18000, 0}}, /* 2005/3/1 2:00:00 EST */
-{ 0, 0, 0, 6, 9, 8, 1999, 4, 251, {-18000, 3600}}, /* 1999/9/9 3:00:00 EDT */
+ { 0, 0, 0, 5, 31, 11, 1999, 5, 364, {-18000, 0}}, /* 1999/12/31 2:00:00 EST */
+ { 0, 0, 0, 5, 1, 0, 2000, 6, 0, {-18000, 0}}, /* 2000/01/01 2:00:00 EST */
+ { 0, 0, 0, 5, 29, 1, 2000, 2, 59, {-18000, 0}}, /* 2000/02/29 2:00:00 EST */
+ { 0, 0, 0, 5, 1, 2, 2001, 4, 59, {-18000, 0}}, /* 2001/3/1 2:00:00 EST */
+ { 0, 0, 0, 5, 1, 2, 2005, 2, 59, {-18000, 0}}, /* 2005/3/1 2:00:00 EST */
+ { 0, 0, 0, 6, 9, 8, 1999, 4, 251, {-18000, 3600}}, /* 1999/9/9 3:00:00 EDT */
/* Sun's dates follow */
{ 0, 0, 0, 5, 31, 11, 1998, 4, 364, {-18000 0}}, /* 12/31/1998 00:00:00 GMT */
{ 0, 0, 0, 6, 10, 8, 1999, 5, 252, {-18000 3600}}, /* 9/10/1999 00:00:00 GMT */
@@ -228,7 +229,9 @@ static PRStatus TestExplodeImplodeTime(void)
for (idx = 0; idx < array_size; idx++) {
PR_snprintf(buf, sizeof(buf), "%lld", prt[idx]);
- if (debug_mode) printf("Time stamp %s\n", buf);
+ if (debug_mode) {
+ printf("Time stamp %s\n", buf);
+ }
PR_ExplodeTime(prt[idx], PR_GMTParameters, &et_tmp);
if (!ExplodedTimeIsEqual(&et_tmp, &gmt[idx])) {
fprintf(stderr, "GMT not equal\n");
@@ -314,7 +317,9 @@ static PRStatus TestExplodeImplodeTime(void)
}
printf("Please verify the results\n\n");
- if (debug_mode) printf("Test 1 passed\n");
+ if (debug_mode) {
+ printf("Test 1 passed\n");
+ }
return PR_SUCCESS;
}
/* End of Test 1: TestExplodeImplodeTime */
@@ -327,165 +332,166 @@ static PRStatus TestExplodeImplodeTime(void)
* time increment for addition to PRExplodeTime
*/
typedef struct time_increment {
- PRInt32 ti_usec;
- PRInt32 ti_sec;
- PRInt32 ti_min;
- PRInt32 ti_hour;
+ PRInt32 ti_usec;
+ PRInt32 ti_sec;
+ PRInt32 ti_min;
+ PRInt32 ti_hour;
} time_increment_t;
/*
* Data for testing PR_Normalize
- * Add the increment to base_time, normalize it to GMT and US Pacific
- * Time zone.
+ * Add the increment to base_time, normalize it to GMT and US Pacific
+ * Time zone.
*/
typedef struct normalize_test_data {
- PRExplodedTime base_time;
- time_increment_t increment;
- PRExplodedTime expected_gmt_time;
- PRExplodedTime expected_uspt_time;
+ PRExplodedTime base_time;
+ time_increment_t increment;
+ PRExplodedTime expected_gmt_time;
+ PRExplodedTime expected_uspt_time;
} normalize_test_data_t;
/*
- * Test data - the base time values cover dates of interest including y2k - 1,
- * y2k + 1, y2k leap year, y2k leap date + 1year,
- * y2k leap date + 4 years
+ * Test data - the base time values cover dates of interest including y2k - 1,
+ * y2k + 1, y2k leap year, y2k leap date + 1year,
+ * y2k leap date + 4 years
*/
normalize_test_data_t normalize_test_array[] = {
- /*usec sec min hour mday mo year wday yday {gmtoff, dstoff }*/
-
- /* Fri 12/31/1999 19:32:48 PST */
- {{0, 48, 32, 19, 31, 11, 1999, 5, 364, { -28800, 0}},
- {0, 0, 30, 20},
- {0, 48, 2, 0, 2, 0, 2000, 0, 1, { 0, 0}}, /*Sun Jan 2 00:02:48 UTC 2000*/
- {0, 48, 2, 16, 1, 0, 2000, 6, 0, { -28800, 0}},/* Sat Jan 1 16:02:48
- PST 2000*/
- },
- /* Fri 99-12-31 23:59:02 GMT */
- {{0, 2, 59, 23, 31, 11, 1999, 5, 364, { 0, 0}},
- {0, 0, 45, 0},
- {0, 2, 44, 0, 1, 0, 2000, 6, 0, { 0, 0}},/* Sat Jan 1 00:44:02 UTC 2000*/
- {0, 2, 44, 16, 31, 11, 1999, 5, 364, { -28800, 0}}/*Fri Dec 31 16:44:02
- PST 1999*/
- },
- /* 99-12-25 12:00:00 GMT */
- {{0, 0, 0, 12, 25, 11, 1999, 6, 358, { 0, 0}},
- {0, 0, 0, 364 * 24},
- {0, 0, 0, 12, 23, 11, 2000, 6, 357, { 0, 0}},/*Sat Dec 23 12:00:00
- 2000 UTC*/
- {0, 0, 0, 4, 23, 11, 2000, 6, 357, { -28800, 0}}/*Sat Dec 23 04:00:00
- 2000 -0800*/
- },
- /* 00-01-1 00:00:00 PST */
- {{0, 0, 0, 0, 1, 0, 2000, 6, 0, { -28800, 0}},
- {0, 0, 0, 48},
- {0, 0, 0, 8, 3, 0, 2000, 1, 2, { 0, 0}},/*Mon Jan 3 08:00:00 2000 UTC*/
- {0, 0, 0, 0, 3, 0, 2000, 1, 2, { -28800, 0}}/*Mon Jan 3 00:00:00 2000
- -0800*/
- },
- /* 00-01-10 12:00:00 PST */
- {{0, 0, 0, 12, 10, 0, 2000, 1, 9, { -28800, 0}},
- {0, 0, 0, 364 * 5 * 24},
- {0, 0, 0, 20, 3, 0, 2005, 1, 2, { 0, 0}},/*Mon Jan 3 20:00:00 2005 UTC */
- {0, 0, 0, 12, 3, 0, 2005, 1, 2, { -28800, 0}}/*Mon Jan 3 12:00:00
- 2005 -0800*/
- },
- /* 00-02-28 15:39 GMT */
- {{0, 0, 39, 15, 28, 1, 2000, 1, 58, { 0, 0}},
- {0, 0, 0, 24},
- {0, 0, 39, 15, 29, 1, 2000, 2, 59, { 0, 0}}, /*Tue Feb 29 15:39:00 2000
- UTC*/
- {0, 0, 39, 7, 29, 1, 2000, 2, 59, { -28800, 0}}/*Tue Feb 29 07:39:00
- 2000 -0800*/
- },
- /* 01-03-01 12:00 PST */
- {{0, 0, 0, 12, 3, 0, 2001, 3, 2, { -28800, 0}},/*Wed Jan 3 12:00:00
- -0800 2001*/
- {0, 30, 30,45},
- {0, 30, 30, 17, 5, 0, 2001, 5, 4, { 0, 0}}, /*Fri Jan 5 17:30:30 2001
- UTC*/
- {0, 30, 30, 9, 5, 0, 2001, 5, 4, { -28800, 0}} /*Fri Jan 5 09:30:30
- 2001 -0800*/
- },
- /* 2004-04-26 12:00 GMT */
- {{0, 0, 0, 20, 3, 0, 2001, 3, 2, { 0, 0}},
- {0, 0, 30,0},
- {0, 0, 30, 20, 3, 0, 2001, 3, 2, { 0, 0}},/*Wed Jan 3 20:30:00 2001 UTC*/
- {0, 0, 30, 12, 3, 0, 2001, 3, 2, { -28800, 0}}/*Wed Jan 3 12:30:00
- 2001 -0800*/
- },
- /* 99-09-09 00:00 GMT */
- {{0, 0, 0, 0, 9, 8, 1999, 4, 251, { 0, 0}},
- {0, 0, 0, 12},
- {0, 0, 0, 12, 9, 8, 1999, 4, 251, { 0, 0}},/*Thu Sep 9 12:00:00 1999 UTC*/
- {0, 0, 0, 5, 9, 8, 1999, 4, 251, { -28800, 3600}}/*Thu Sep 9 05:00:00
- 1999 -0700*/
- }
+ /*usec sec min hour mday mo year wday yday {gmtoff, dstoff }*/
+
+ /* Fri 12/31/1999 19:32:48 PST */
+ { {0, 48, 32, 19, 31, 11, 1999, 5, 364, { -28800, 0}},
+ {0, 0, 30, 20},
+ {0, 48, 2, 0, 2, 0, 2000, 0, 1, { 0, 0}}, /*Sun Jan 2 00:02:48 UTC 2000*/
+ {0, 48, 2, 16, 1, 0, 2000, 6, 0, { -28800, 0}},/* Sat Jan 1 16:02:48
+ PST 2000*/
+ },
+ /* Fri 99-12-31 23:59:02 GMT */
+ { {0, 2, 59, 23, 31, 11, 1999, 5, 364, { 0, 0}},
+ {0, 0, 45, 0},
+ {0, 2, 44, 0, 1, 0, 2000, 6, 0, { 0, 0}},/* Sat Jan 1 00:44:02 UTC 2000*/
+ {0, 2, 44, 16, 31, 11, 1999, 5, 364, { -28800, 0}}/*Fri Dec 31 16:44:02
+ PST 1999*/
+ },
+ /* 99-12-25 12:00:00 GMT */
+ { {0, 0, 0, 12, 25, 11, 1999, 6, 358, { 0, 0}},
+ {0, 0, 0, 364 * 24},
+ {0, 0, 0, 12, 23, 11, 2000, 6, 357, { 0, 0}},/*Sat Dec 23 12:00:00
+ 2000 UTC*/
+ {0, 0, 0, 4, 23, 11, 2000, 6, 357, { -28800, 0}}/*Sat Dec 23 04:00:00
+ 2000 -0800*/
+ },
+ /* 00-01-1 00:00:00 PST */
+ { {0, 0, 0, 0, 1, 0, 2000, 6, 0, { -28800, 0}},
+ {0, 0, 0, 48},
+ {0, 0, 0, 8, 3, 0, 2000, 1, 2, { 0, 0}},/*Mon Jan 3 08:00:00 2000 UTC*/
+ {0, 0, 0, 0, 3, 0, 2000, 1, 2, { -28800, 0}}/*Mon Jan 3 00:00:00 2000
+ -0800*/
+ },
+ /* 00-01-10 12:00:00 PST */
+ { {0, 0, 0, 12, 10, 0, 2000, 1, 9, { -28800, 0}},
+ {0, 0, 0, 364 * 5 * 24},
+ {0, 0, 0, 20, 3, 0, 2005, 1, 2, { 0, 0}},/*Mon Jan 3 20:00:00 2005 UTC */
+ {0, 0, 0, 12, 3, 0, 2005, 1, 2, { -28800, 0}}/*Mon Jan 3 12:00:00
+ 2005 -0800*/
+ },
+ /* 00-02-28 15:39 GMT */
+ { {0, 0, 39, 15, 28, 1, 2000, 1, 58, { 0, 0}},
+ {0, 0, 0, 24},
+ {0, 0, 39, 15, 29, 1, 2000, 2, 59, { 0, 0}}, /*Tue Feb 29 15:39:00 2000
+ UTC*/
+ {0, 0, 39, 7, 29, 1, 2000, 2, 59, { -28800, 0}}/*Tue Feb 29 07:39:00
+ 2000 -0800*/
+ },
+ /* 01-03-01 12:00 PST */
+ { {0, 0, 0, 12, 3, 0, 2001, 3, 2, { -28800, 0}},/*Wed Jan 3 12:00:00
+ -0800 2001*/
+ {0, 30, 30,45},
+ {0, 30, 30, 17, 5, 0, 2001, 5, 4, { 0, 0}}, /*Fri Jan 5 17:30:30 2001
+ UTC*/
+ {0, 30, 30, 9, 5, 0, 2001, 5, 4, { -28800, 0}} /*Fri Jan 5 09:30:30
+ 2001 -0800*/
+ },
+ /* 2004-04-26 12:00 GMT */
+ { {0, 0, 0, 20, 3, 0, 2001, 3, 2, { 0, 0}},
+ {0, 0, 30,0},
+ {0, 0, 30, 20, 3, 0, 2001, 3, 2, { 0, 0}},/*Wed Jan 3 20:30:00 2001 UTC*/
+ {0, 0, 30, 12, 3, 0, 2001, 3, 2, { -28800, 0}}/*Wed Jan 3 12:30:00
+ 2001 -0800*/
+ },
+ /* 99-09-09 00:00 GMT */
+ { {0, 0, 0, 0, 9, 8, 1999, 4, 251, { 0, 0}},
+ {0, 0, 0, 12},
+ {0, 0, 0, 12, 9, 8, 1999, 4, 251, { 0, 0}},/*Thu Sep 9 12:00:00 1999 UTC*/
+ {0, 0, 0, 5, 9, 8, 1999, 4, 251, { -28800, 3600}}/*Thu Sep 9 05:00:00
+ 1999 -0700*/
+ }
};
void add_time_increment(PRExplodedTime *et1, time_increment_t *it)
{
- et1->tm_usec += it->ti_usec;
- et1->tm_sec += it->ti_sec;
- et1->tm_min += it->ti_min;
- et1->tm_hour += it->ti_hour;
+ et1->tm_usec += it->ti_usec;
+ et1->tm_sec += it->ti_sec;
+ et1->tm_min += it->ti_min;
+ et1->tm_hour += it->ti_hour;
}
/*
** TestNormalizeTime() -- Test PR_NormalizeTime()
-** For each data item, add the time increment to the base_time and then
-** normalize it for GMT and local time zones. This test assumes that
-** the local time zone is the Pacific Time Zone. The normalized values
-** should match the expected values in the data item.
+** For each data item, add the time increment to the base_time and then
+** normalize it for GMT and local time zones. This test assumes that
+** the local time zone is the Pacific Time Zone. The normalized values
+** should match the expected values in the data item.
**
*/
PRStatus TestNormalizeTime(void)
{
-int idx, count;
-normalize_test_data_t *itemp;
-time_increment_t *itp;
-
- count = sizeof(normalize_test_array)/sizeof(normalize_test_array[0]);
- for (idx = 0; idx < count; idx++) {
- itemp = &normalize_test_array[idx];
- if (debug_mode) {
- printf("%2d. %15s",idx +1,"Base time: ");
- PrintExplodedTime(&itemp->base_time);
- printf("\n");
- }
- itp = &itemp->increment;
- if (debug_mode) {
- printf("%20s %2d hrs %2d min %3d sec\n","Add",itp->ti_hour,
- itp->ti_min, itp->ti_sec);
- }
- add_time_increment(&itemp->base_time, &itemp->increment);
- PR_NormalizeTime(&itemp->base_time, PR_LocalTimeParameters);
- if (debug_mode) {
- printf("%19s","PST time: ");
- PrintExplodedTime(&itemp->base_time);
- printf("\n");
- }
- if (!ExplodedTimeIsEqual(&itemp->base_time,
- &itemp->expected_uspt_time)) {
- printf("PR_NormalizeTime failed\n");
- if (debug_mode)
- PrintExplodedTime(&itemp->expected_uspt_time);
- return PR_FAILURE;
- }
- PR_NormalizeTime(&itemp->base_time, PR_GMTParameters);
- if (debug_mode) {
- printf("%19s","GMT time: ");
- PrintExplodedTime(&itemp->base_time);
- printf("\n");
- }
-
- if (!ExplodedTimeIsEqual(&itemp->base_time,
- &itemp->expected_gmt_time)) {
- printf("PR_NormalizeTime failed\n");
- return PR_FAILURE;
- }
- }
- return PR_SUCCESS;
+ int idx, count;
+ normalize_test_data_t *itemp;
+ time_increment_t *itp;
+
+ count = sizeof(normalize_test_array)/sizeof(normalize_test_array[0]);
+ for (idx = 0; idx < count; idx++) {
+ itemp = &normalize_test_array[idx];
+ if (debug_mode) {
+ printf("%2d. %15s",idx +1,"Base time: ");
+ PrintExplodedTime(&itemp->base_time);
+ printf("\n");
+ }
+ itp = &itemp->increment;
+ if (debug_mode) {
+ printf("%20s %2d hrs %2d min %3d sec\n","Add",itp->ti_hour,
+ itp->ti_min, itp->ti_sec);
+ }
+ add_time_increment(&itemp->base_time, &itemp->increment);
+ PR_NormalizeTime(&itemp->base_time, PR_LocalTimeParameters);
+ if (debug_mode) {
+ printf("%19s","PST time: ");
+ PrintExplodedTime(&itemp->base_time);
+ printf("\n");
+ }
+ if (!ExplodedTimeIsEqual(&itemp->base_time,
+ &itemp->expected_uspt_time)) {
+ printf("PR_NormalizeTime failed\n");
+ if (debug_mode) {
+ PrintExplodedTime(&itemp->expected_uspt_time);
+ }
+ return PR_FAILURE;
+ }
+ PR_NormalizeTime(&itemp->base_time, PR_GMTParameters);
+ if (debug_mode) {
+ printf("%19s","GMT time: ");
+ PrintExplodedTime(&itemp->base_time);
+ printf("\n");
+ }
+
+ if (!ExplodedTimeIsEqual(&itemp->base_time,
+ &itemp->expected_gmt_time)) {
+ printf("PR_NormalizeTime failed\n");
+ return PR_FAILURE;
+ }
+ }
+ return PR_SUCCESS;
}
@@ -696,7 +702,7 @@ static PRStatus TestParseTime( void )
}
else
{
- PR_ExplodeTime( ct, PR_LocalTimeParameters , &cet );
+ PR_ExplodeTime( ct, PR_LocalTimeParameters, &cet );
if ( !ExplodedTimeIsEqual( &cet, &ptp->et ))
{
@@ -724,32 +730,34 @@ static PRStatus TestParseTime( void )
int main(int argc, char** argv)
{
- /* The command line argument: -d is used to determine if the test is being run
- in debug mode. The regress tool requires only one line output:PASS or FAIL.
- All of the printfs associated with this test has been handled with a if (debug_mode)
- test.
- Usage: test_name -d
- */
- PLOptStatus os;
- PLOptState *opt;
+ /* The command line argument: -d is used to determine if the test is being run
+ in debug mode. The regress tool requires only one line output:PASS or FAIL.
+ All of the printfs associated with this test has been handled with a if (debug_mode)
+ test.
+ Usage: test_name -d
+ */
+ PLOptStatus os;
+ PLOptState *opt;
PR_STDIO_INIT();
- opt = PL_CreateOptState(argc, argv, "d");
- while (PL_OPT_EOL != (os = PL_GetNextOpt(opt)))
+ opt = PL_CreateOptState(argc, argv, "d");
+ 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_mode = PR_TRUE;
- break;
- default:
- break;
+ case 'd': /* debug mode */
+ debug_mode = PR_TRUE;
+ break;
+ default:
+ break;
}
}
- PL_DestroyOptState(opt);
+ PL_DestroyOptState(opt);
- /* main test */
+ /* main test */
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
lm = PR_NewLogModule("test");
@@ -757,30 +765,35 @@ int main(int argc, char** argv)
if ( PR_FAILURE == TestExplodeImplodeTime())
{
PR_LOG( lm, PR_LOG_ERROR,
- ("TestExplodeImplodeTime() failed"));
+ ("TestExplodeImplodeTime() failed"));
+ }
+ else {
+ printf("Test 1: Calendar Time Test passed\n");
}
- else
- printf("Test 1: Calendar Time Test passed\n");
if ( PR_FAILURE == TestNormalizeTime())
{
PR_LOG( lm, PR_LOG_ERROR,
- ("TestNormalizeTime() failed"));
+ ("TestNormalizeTime() failed"));
+ }
+ else {
+ printf("Test 2: Normalize Time Test passed\n");
}
- else
- printf("Test 2: Normalize Time Test passed\n");
if ( PR_FAILURE == TestParseTime())
{
PR_LOG( lm, PR_LOG_ERROR,
- ("TestParseTime() failed"));
+ ("TestParseTime() failed"));
+ }
+ else {
+ printf("Test 3: Parse Time Test passed\n");
}
- else
- printf("Test 3: Parse Time Test passed\n");
- if (failed_already)
- return 1;
- else
- return 0;
+ if (failed_already) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
} /* end main() y2k.c */
diff --git a/pr/tests/y2ktmo.c b/pr/tests/y2ktmo.c
index e7ceb436..b28467e4 100644
--- a/pr/tests/y2ktmo.c
+++ b/pr/tests/y2ktmo.c
@@ -95,7 +95,7 @@ static void SleepThread(void *arg)
#if defined(XP_UNIX)
gettimeofday(&end_time_tv, NULL);
elapsed_msecs = 1000*(end_time_tv.tv_sec - start_time_tv.tv_sec)
- + (end_time_tv.tv_usec - start_time_tv.tv_usec)/1000;
+ + (end_time_tv.tv_usec - start_time_tv.tv_usec)/1000;
#endif
#if defined(WIN32)
#if defined(WINCE)
@@ -103,12 +103,12 @@ static void SleepThread(void *arg)
#else
_ftime(&end_time_tb);
elapsed_msecs = 1000*(end_time_tb.time - start_time_tb.time)
- + (end_time_tb.millitm - start_time_tb.millitm);
+ + (end_time_tb.millitm - start_time_tb.millitm);
#endif
#endif
#if defined(XP_UNIX) || defined(WIN32)
if (elapsed_msecs + tolerance_msecs < timeout_msecs
- || elapsed_msecs > timeout_msecs + tolerance_msecs) {
+ || elapsed_msecs > timeout_msecs + tolerance_msecs) {
fprintf(stderr, "timeout wrong\n");
exit(1);
}
@@ -167,7 +167,7 @@ static void AcceptThread(void *arg)
#if defined(XP_UNIX)
gettimeofday(&end_time_tv, NULL);
elapsed_msecs = 1000*(end_time_tv.tv_sec - start_time_tv.tv_sec)
- + (end_time_tv.tv_usec - start_time_tv.tv_usec)/1000;
+ + (end_time_tv.tv_usec - start_time_tv.tv_usec)/1000;
#endif
#if defined(WIN32)
#if defined(WINCE)
@@ -175,12 +175,12 @@ static void AcceptThread(void *arg)
#else
_ftime(&end_time_tb);
elapsed_msecs = 1000*(end_time_tb.time - start_time_tb.time)
- + (end_time_tb.millitm - start_time_tb.millitm);
+ + (end_time_tb.millitm - start_time_tb.millitm);
#endif
#endif
#if defined(XP_UNIX) || defined(WIN32)
if (elapsed_msecs + tolerance_msecs < timeout_msecs
- || elapsed_msecs > timeout_msecs + tolerance_msecs) {
+ || elapsed_msecs > timeout_msecs + tolerance_msecs) {
fprintf(stderr, "timeout wrong\n");
exit(1);
}
@@ -246,7 +246,7 @@ static void PollThread(void *arg)
#if defined(XP_UNIX)
gettimeofday(&end_time_tv, NULL);
elapsed_msecs = 1000*(end_time_tv.tv_sec - start_time_tv.tv_sec)
- + (end_time_tv.tv_usec - start_time_tv.tv_usec)/1000;
+ + (end_time_tv.tv_usec - start_time_tv.tv_usec)/1000;
#endif
#if defined(WIN32)
#if defined(WINCE)
@@ -254,12 +254,12 @@ static void PollThread(void *arg)
#else
_ftime(&end_time_tb);
elapsed_msecs = 1000*(end_time_tb.time - start_time_tb.time)
- + (end_time_tb.millitm - start_time_tb.millitm);
+ + (end_time_tb.millitm - start_time_tb.millitm);
#endif
#endif
#if defined(XP_UNIX) || defined(WIN32)
if (elapsed_msecs + tolerance_msecs < timeout_msecs
- || elapsed_msecs > timeout_msecs + tolerance_msecs) {
+ || elapsed_msecs > timeout_msecs + tolerance_msecs) {
fprintf(stderr, "timeout wrong\n");
exit(1);
}
@@ -312,7 +312,7 @@ static void WaitCondVarThread(void *arg)
#if defined(XP_UNIX)
gettimeofday(&end_time_tv, NULL);
elapsed_msecs = 1000*(end_time_tv.tv_sec - start_time_tv.tv_sec)
- + (end_time_tv.tv_usec - start_time_tv.tv_usec)/1000;
+ + (end_time_tv.tv_usec - start_time_tv.tv_usec)/1000;
#endif
#if defined(WIN32)
#if defined(WINCE)
@@ -320,12 +320,12 @@ static void WaitCondVarThread(void *arg)
#else
_ftime(&end_time_tb);
elapsed_msecs = 1000*(end_time_tb.time - start_time_tb.time)
- + (end_time_tb.millitm - start_time_tb.millitm);
+ + (end_time_tb.millitm - start_time_tb.millitm);
#endif
#endif
#if defined(XP_UNIX) || defined(WIN32)
if (elapsed_msecs + tolerance_msecs < timeout_msecs
- || elapsed_msecs > timeout_msecs + tolerance_msecs) {
+ || elapsed_msecs > timeout_msecs + tolerance_msecs) {
fprintf(stderr, "timeout wrong\n");
exit(1);
}
@@ -370,7 +370,7 @@ static void WaitMonitorThread(void *arg)
#if defined(XP_UNIX)
gettimeofday(&end_time_tv, NULL);
elapsed_msecs = 1000*(end_time_tv.tv_sec - start_time_tv.tv_sec)
- + (end_time_tv.tv_usec - start_time_tv.tv_usec)/1000;
+ + (end_time_tv.tv_usec - start_time_tv.tv_usec)/1000;
#endif
#if defined(WIN32)
#if defined(WINCE)
@@ -378,12 +378,12 @@ static void WaitMonitorThread(void *arg)
#else
_ftime(&end_time_tb);
elapsed_msecs = 1000*(end_time_tb.time - start_time_tb.time)
- + (end_time_tb.millitm - start_time_tb.millitm);
+ + (end_time_tb.millitm - start_time_tb.millitm);
#endif
#endif
#if defined(XP_UNIX) || defined(WIN32)
if (elapsed_msecs + tolerance_msecs < timeout_msecs
- || elapsed_msecs > timeout_msecs + tolerance_msecs) {
+ || elapsed_msecs > timeout_msecs + tolerance_msecs) {
fprintf(stderr, "timeout wrong\n");
exit(1);
}
@@ -422,7 +422,7 @@ static void WaitCMonitorThread(void *arg)
#if defined(XP_UNIX)
gettimeofday(&end_time_tv, NULL);
elapsed_msecs = 1000*(end_time_tv.tv_sec - start_time_tv.tv_sec)
- + (end_time_tv.tv_usec - start_time_tv.tv_usec)/1000;
+ + (end_time_tv.tv_usec - start_time_tv.tv_usec)/1000;
#endif
#if defined(WIN32)
#if defined(WINCE)
@@ -430,12 +430,12 @@ static void WaitCMonitorThread(void *arg)
#else
_ftime(&end_time_tb);
elapsed_msecs = 1000*(end_time_tb.time - start_time_tb.time)
- + (end_time_tb.millitm - start_time_tb.millitm);
+ + (end_time_tb.millitm - start_time_tb.millitm);
#endif
#endif
#if defined(XP_UNIX) || defined(WIN32)
if (elapsed_msecs + tolerance_msecs < timeout_msecs
- || elapsed_msecs > timeout_msecs + tolerance_msecs) {
+ || elapsed_msecs > timeout_msecs + tolerance_msecs) {
fprintf(stderr, "timeout wrong\n");
exit(1);
}
@@ -450,10 +450,12 @@ typedef void (*NSPRThreadFunc)(void*);
static NSPRThreadFunc threadFuncs[] = {
SleepThread, AcceptThread, PollThread,
- WaitCondVarThread, WaitMonitorThread, WaitCMonitorThread};
+ WaitCondVarThread, WaitMonitorThread, WaitCMonitorThread
+};
static PRThreadScope threadScopes[] = {
- PR_LOCAL_THREAD, PR_GLOBAL_THREAD, PR_GLOBAL_BOUND_THREAD};
+ PR_LOCAL_THREAD, PR_GLOBAL_THREAD, PR_GLOBAL_BOUND_THREAD
+};
static void Help(void)
{
@@ -478,7 +480,9 @@ int main(int argc, char **argv)
PLOptState *opt = PL_CreateOptState(argc, argv, "dl:t:h");
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_mode = PR_TRUE;
@@ -516,7 +520,7 @@ int main(int argc, char **argv)
tolerance = PR_MillisecondsToInterval(tolerance_msecs);
threads = PR_Malloc(
- num_thread_scopes * num_thread_funcs * sizeof(PRThread*));
+ num_thread_scopes * num_thread_funcs * sizeof(PRThread*));
if (threads == NULL) {
fprintf(stderr, "PR_Malloc failed\n");
exit(1);
@@ -528,8 +532,8 @@ int main(int argc, char **argv)
for (i = 0; i < num_thread_scopes; i++) {
for (j = 0; j < num_thread_funcs; j++) {
threads[idx] = PR_CreateThread(PR_USER_THREAD, threadFuncs[j],
- (void*)PR_SecondsToInterval(secs), PR_PRIORITY_NORMAL,
- threadScopes[i], PR_JOINABLE_THREAD, 0);
+ (void*)PR_SecondsToInterval(secs), PR_PRIORITY_NORMAL,
+ threadScopes[i], PR_JOINABLE_THREAD, 0);
if (threads[idx] == NULL) {
fprintf(stderr, "PR_CreateThread failed\n");
exit(1);
diff --git a/pr/tests/yield.c b/pr/tests/yield.c
index 1e4b6b89..eb55926b 100644
--- a/pr/tests/yield.c
+++ b/pr/tests/yield.c
@@ -43,14 +43,15 @@ int main(int argc, char **argv)
for (index=0; index<THREADS; index++) {
a[index] = PR_CreateThread(PR_USER_THREAD,
- threadmain,
- (void *)index,
- PR_PRIORITY_NORMAL,
- index%2?PR_LOCAL_THREAD:PR_GLOBAL_THREAD,
- PR_JOINABLE_THREAD,
- 0);
+ threadmain,
+ (void *)index,
+ PR_PRIORITY_NORMAL,
+ index%2?PR_LOCAL_THREAD:PR_GLOBAL_THREAD,
+ PR_JOINABLE_THREAD,
+ 0);
}
- for(index=0; index<THREADS; index++)
+ for(index=0; index<THREADS; index++) {
PR_JoinThread(a[index]);
+ }
printf("main dying\n");
}
diff --git a/pr/tests/zerolen.c b/pr/tests/zerolen.c
index 730be79d..15fb6ccb 100644
--- a/pr/tests/zerolen.c
+++ b/pr/tests/zerolen.c
@@ -124,8 +124,8 @@ int main()
* First test PR_Writev.
*/
clientThread = PR_CreateThread(PR_USER_THREAD,
- ClientThread, (void *) PR_ntohs(PR_NetAddrInetPort(&addr)),
- PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
+ ClientThread, (void *) PR_ntohs(PR_NetAddrInetPort(&addr)),
+ PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
if (NULL == clientThread) {
fprintf(stderr, "PR_CreateThread failed\n");
exit(1);
@@ -165,8 +165,8 @@ int main()
* Then test PR_Write.
*/
clientThread = PR_CreateThread(PR_USER_THREAD,
- ClientThread, (void *) PR_ntohs(PR_NetAddrInetPort(&addr)),
- PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
+ ClientThread, (void *) PR_ntohs(PR_NetAddrInetPort(&addr)),
+ PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
if (NULL == clientThread) {
fprintf(stderr, "PR_CreateThread failed\n");
exit(1);
@@ -204,8 +204,8 @@ int main()
* Finally test PR_Send.
*/
clientThread = PR_CreateThread(PR_USER_THREAD,
- ClientThread, (void *) PR_ntohs(PR_NetAddrInetPort(&addr)),
- PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
+ ClientThread, (void *) PR_ntohs(PR_NetAddrInetPort(&addr)),
+ PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
if (NULL == clientThread) {
fprintf(stderr, "PR_CreateThread failed\n");
exit(1);
diff --git a/tools/httpget.c b/tools/httpget.c
index ec8776f3..ed363651 100644
--- a/tools/httpget.c
+++ b/tools/httpget.c
@@ -70,22 +70,22 @@ PRInt32 ReadLine(PRFileDesc *fd, char *buf, PRUint32 bufSize)
loop:
PR_ASSERT(inputBuf <= inputHead && inputHead <= inputTail
- && inputTail <= inputBufEnd);
+ && inputTail <= inputBufEnd);
while (lineFound == PR_FALSE && inputHead != inputTail
- && dst < bufEnd - 1) {
- if (*inputHead == '\r') {
- crPtr = dst;
- } else if (*inputHead == '\n') {
- lineFound = PR_TRUE;
- if (crPtr == dst - 1) {
- dst--;
- }
- }
- *(dst++) = *(inputHead++);
+ && dst < bufEnd - 1) {
+ if (*inputHead == '\r') {
+ crPtr = dst;
+ } else if (*inputHead == '\n') {
+ lineFound = PR_TRUE;
+ if (crPtr == dst - 1) {
+ dst--;
+ }
+ }
+ *(dst++) = *(inputHead++);
}
if (lineFound == PR_TRUE || dst == bufEnd - 1 || endOfStream == PR_TRUE) {
- *dst = '\0';
- return dst - buf;
+ *dst = '\0';
+ return dst - buf;
}
/*
@@ -95,12 +95,12 @@ loop:
nRead = PR_Read(fd, inputBuf, sizeof(inputBuf));
if (nRead == -1) {
- *dst = '\0';
- return -1;
+ *dst = '\0';
+ return -1;
} else if (nRead == 0) {
- endOfStream = PR_TRUE;
- *dst = '\0';
- return dst - buf;
+ endOfStream = PR_TRUE;
+ *dst = '\0';
+ return dst - buf;
}
inputHead = inputBuf;
inputTail = inputBuf + nRead;
@@ -112,14 +112,14 @@ PRInt32 DrainInputBuffer(char *buf, PRUint32 bufSize)
PRInt32 nBytes = inputTail - inputHead;
if (nBytes == 0) {
- if (endOfStream) {
- return -1;
- } else {
- return 0;
- }
+ if (endOfStream) {
+ return -1;
+ } else {
+ return 0;
+ }
}
if ((PRInt32) bufSize < nBytes) {
- nBytes = bufSize;
+ nBytes = bufSize;
}
memcpy(buf, inputHead, nBytes);
inputHead += nBytes;
@@ -132,24 +132,24 @@ PRStatus FetchFile(PRFileDesc *in, PRFileDesc *out)
PRInt32 nBytes;
while ((nBytes = DrainInputBuffer(buf, sizeof(buf))) > 0) {
- if (PR_Write(out, buf, nBytes) != nBytes) {
+ if (PR_Write(out, buf, nBytes) != nBytes) {
fprintf(stderr, "httpget: cannot write to file\n");
- return PR_FAILURE;
- }
+ return PR_FAILURE;
+ }
}
if (nBytes < 0) {
- /* Input buffer is empty and end of stream */
- return PR_SUCCESS;
+ /* Input buffer is empty and end of stream */
+ return PR_SUCCESS;
}
while ((nBytes = PR_Read(in, buf, sizeof(buf))) > 0) {
- if (PR_Write(out, buf, nBytes) != nBytes) {
- fprintf(stderr, "httpget: cannot write to file\n");
- return PR_FAILURE;
+ if (PR_Write(out, buf, nBytes) != nBytes) {
+ fprintf(stderr, "httpget: cannot write to file\n");
+ return PR_FAILURE;
}
}
if (nBytes < 0) {
- fprintf(stderr, "httpget: cannot read from socket\n");
- return PR_FAILURE;
+ fprintf(stderr, "httpget: cannot read from socket\n");
+ return PR_FAILURE;
}
return PR_SUCCESS;
}
@@ -170,31 +170,31 @@ PRStatus FastFetchFile(PRFileDesc *in, PRFileDesc *out, PRUint32 size)
PR_ASSERT(outfMap);
addr = PR_MemMap(outfMap, LL_ZERO, size);
if (addr == NULL) {
- fprintf(stderr, "cannot memory-map file: (%d, %d)\n", PR_GetError(),
- PR_GetOSError());
+ fprintf(stderr, "cannot memory-map file: (%d, %d)\n", PR_GetError(),
+ PR_GetOSError());
- PR_CloseFileMap(outfMap);
- return PR_FAILURE;
+ PR_CloseFileMap(outfMap);
+ return PR_FAILURE;
}
start = (char *) addr;
rem = size;
while ((nBytes = DrainInputBuffer(start, rem)) > 0) {
- start += nBytes;
- rem -= nBytes;
+ start += nBytes;
+ rem -= nBytes;
}
if (nBytes < 0) {
- /* Input buffer is empty and end of stream */
- return PR_SUCCESS;
+ /* Input buffer is empty and end of stream */
+ return PR_SUCCESS;
}
bytesToRead = (rem < FCOPY_BUFFER_SIZE) ? rem : FCOPY_BUFFER_SIZE;
while (rem > 0 && (nBytes = PR_Read(in, start, bytesToRead)) > 0) {
- start += nBytes;
- rem -= nBytes;
+ start += nBytes;
+ rem -= nBytes;
bytesToRead = (rem < FCOPY_BUFFER_SIZE) ? rem : FCOPY_BUFFER_SIZE;
}
if (nBytes < 0) {
- fprintf(stderr, "httpget: cannot read from socket\n");
- return PR_FAILURE;
+ fprintf(stderr, "httpget: cannot read from socket\n");
+ return PR_FAILURE;
}
rv = PR_MemUnmap(addr, size);
PR_ASSERT(rv == PR_SUCCESS);
@@ -204,7 +204,7 @@ PRStatus FastFetchFile(PRFileDesc *in, PRFileDesc *out, PRUint32 size)
}
PRStatus ParseURL(char *url, char *host, PRUint32 hostSize,
- char *port, PRUint32 portSize, char *path, PRUint32 pathSize)
+ char *port, PRUint32 portSize, char *path, PRUint32 pathSize)
{
char *start, *end;
char *dst;
@@ -213,60 +213,60 @@ PRStatus ParseURL(char *url, char *host, PRUint32 hostSize,
char *pathEnd;
if (strncmp(url, "http", 4)) {
- fprintf(stderr, "httpget: the protocol must be http\n");
- return PR_FAILURE;
+ fprintf(stderr, "httpget: the protocol must be http\n");
+ return PR_FAILURE;
}
if (strncmp(url + 4, "://", 3) || url[7] == '\0') {
- fprintf(stderr, "httpget: malformed URL: %s\n", url);
- return PR_FAILURE;
+ fprintf(stderr, "httpget: malformed URL: %s\n", url);
+ return PR_FAILURE;
}
start = end = url + 7;
dst = host;
hostEnd = host + hostSize;
while (*end && *end != ':' && *end != '/') {
- if (dst == hostEnd - 1) {
- fprintf(stderr, "httpget: host name too long\n");
- return PR_FAILURE;
- }
- *(dst++) = *(end++);
+ if (dst == hostEnd - 1) {
+ fprintf(stderr, "httpget: host name too long\n");
+ return PR_FAILURE;
+ }
+ *(dst++) = *(end++);
}
*dst = '\0';
if (*end == '\0') {
- PR_snprintf(port, portSize, "%d", 80);
- PR_snprintf(path, pathSize, "%s", "/");
- return PR_SUCCESS;
+ PR_snprintf(port, portSize, "%d", 80);
+ PR_snprintf(path, pathSize, "%s", "/");
+ return PR_SUCCESS;
}
if (*end == ':') {
- end++;
- dst = port;
- portEnd = port + portSize;
- while (*end && *end != '/') {
- if (dst == portEnd - 1) {
- fprintf(stderr, "httpget: port number too long\n");
- return PR_FAILURE;
- }
- *(dst++) = *(end++);
+ end++;
+ dst = port;
+ portEnd = port + portSize;
+ while (*end && *end != '/') {
+ if (dst == portEnd - 1) {
+ fprintf(stderr, "httpget: port number too long\n");
+ return PR_FAILURE;
+ }
+ *(dst++) = *(end++);
}
- *dst = '\0';
- if (*end == '\0') {
- PR_snprintf(path, pathSize, "%s", "/");
- return PR_SUCCESS;
+ *dst = '\0';
+ if (*end == '\0') {
+ PR_snprintf(path, pathSize, "%s", "/");
+ return PR_SUCCESS;
}
} else {
- PR_snprintf(port, portSize, "%d", 80);
+ PR_snprintf(port, portSize, "%d", 80);
}
dst = path;
pathEnd = path + pathSize;
while (*end) {
- if (dst == pathEnd - 1) {
- fprintf(stderr, "httpget: file pathname too long\n");
- return PR_FAILURE;
- }
- *(dst++) = *(end++);
+ if (dst == pathEnd - 1) {
+ fprintf(stderr, "httpget: file pathname too long\n");
+ return PR_FAILURE;
+ }
+ *(dst++) = *(end++);
}
*dst = '\0';
return PR_SUCCESS;
@@ -274,8 +274,8 @@ PRStatus ParseURL(char *url, char *host, PRUint32 hostSize,
void PrintUsage(void) {
fprintf(stderr, "usage: httpget url\n"
- " httpget -o outputfile url\n"
- " httpget url -o outputfile\n");
+ " httpget -o outputfile url\n"
+ " httpget url -o outputfile\n");
}
int main(int argc, char **argv)
@@ -296,44 +296,44 @@ int main(int argc, char **argv)
PRUint32 fileSize;
if (argc != 2 && argc != 4) {
- PrintUsage();
- exit(1);
+ PrintUsage();
+ exit(1);
}
if (argc == 2) {
- /*
- * case 1: httpget url
- */
- url = argv[1];
+ /*
+ * case 1: httpget url
+ */
+ url = argv[1];
} else {
- if (strcmp(argv[1], "-o") == 0) {
- /*
- * case 2: httpget -o outputfile url
- */
- fileName = argv[2];
- url = argv[3];
+ if (strcmp(argv[1], "-o") == 0) {
+ /*
+ * case 2: httpget -o outputfile url
+ */
+ fileName = argv[2];
+ url = argv[3];
} else {
- /*
- * case 3: httpget url -o outputfile
- */
- url = argv[1];
- if (strcmp(argv[2], "-o") != 0) {
- PrintUsage();
- exit(1);
+ /*
+ * case 3: httpget url -o outputfile
+ */
+ url = argv[1];
+ if (strcmp(argv[2], "-o") != 0) {
+ PrintUsage();
+ exit(1);
}
- fileName = argv[3];
- }
+ fileName = argv[3];
+ }
}
if (ParseURL(url, host, sizeof(host), port, sizeof(port),
- path, sizeof(path)) == PR_FAILURE) {
- exit(1);
+ path, sizeof(path)) == PR_FAILURE) {
+ exit(1);
}
if (PR_GetHostByName(host, buf, sizeof(buf), &hostentry)
- == PR_FAILURE) {
+ == PR_FAILURE) {
fprintf(stderr, "httpget: unknown host name: %s\n", host);
- exit(1);
+ exit(1);
}
addr.inet.family = PR_AF_INET;
@@ -342,92 +342,96 @@ int main(int argc, char **argv)
socket = PR_NewTCPSocket();
if (socket == NULL) {
- fprintf(stderr, "httpget: cannot create new tcp socket\n");
- exit(1);
+ fprintf(stderr, "httpget: cannot create new tcp socket\n");
+ exit(1);
}
if (PR_Connect(socket, &addr, PR_INTERVAL_NO_TIMEOUT) == PR_FAILURE) {
- fprintf(stderr, "httpget: cannot connect to http server\n");
- exitStatus = 1;
- goto done;
+ fprintf(stderr, "httpget: cannot connect to http server\n");
+ exitStatus = 1;
+ goto done;
}
if (fileName == NULL) {
- file = PR_STDOUT;
+ file = PR_STDOUT;
} else {
file = PR_Open(fileName, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE,
- 00777);
+ 00777);
if (file == NULL) {
- fprintf(stderr, "httpget: cannot open file %s: (%d, %d)\n",
- fileName, PR_GetError(), PR_GetOSError());
- exitStatus = 1;
- goto done;
- }
+ fprintf(stderr, "httpget: cannot open file %s: (%d, %d)\n",
+ fileName, PR_GetError(), PR_GetOSError());
+ exitStatus = 1;
+ goto done;
+ }
}
cmdSize = PR_snprintf(buf, sizeof(buf), "GET %s HTTP/1.0\r\n\r\n", path);
PR_ASSERT(cmdSize == (PRIntn) strlen("GET HTTP/1.0\r\n\r\n")
- + (PRIntn) strlen(path));
+ + (PRIntn) strlen(path));
if (PR_Write(socket, buf, cmdSize) != cmdSize) {
- fprintf(stderr, "httpget: cannot write to http server\n");
- exitStatus = 1;
- goto done;
+ fprintf(stderr, "httpget: cannot write to http server\n");
+ exitStatus = 1;
+ goto done;
}
if (ReadLine(socket, line, sizeof(line)) <= 0) {
- fprintf(stderr, "httpget: cannot read line from http server\n");
- exitStatus = 1;
- goto done;
+ fprintf(stderr, "httpget: cannot read line from http server\n");
+ exitStatus = 1;
+ goto done;
}
/* HTTP response: 200 == OK */
if (strstr(line, "200") == NULL) {
- fprintf(stderr, "httpget: %s\n", line);
- exitStatus = 1;
- goto done;
+ fprintf(stderr, "httpget: %s\n", line);
+ exitStatus = 1;
+ goto done;
}
while (ReadLine(socket, line, sizeof(line)) > 0) {
- if (line[0] == '\n') {
- endOfHeader = PR_TRUE;
- break;
- }
- if (strncmp(line, "Content-Length", 14) == 0
- || strncmp(line, "Content-length", 14) == 0) {
- char *p = line + 14;
-
- while (*p == ' ' || *p == '\t') {
- p++;
- }
- if (*p != ':') {
- continue;
+ if (line[0] == '\n') {
+ endOfHeader = PR_TRUE;
+ break;
+ }
+ if (strncmp(line, "Content-Length", 14) == 0
+ || strncmp(line, "Content-length", 14) == 0) {
+ char *p = line + 14;
+
+ while (*p == ' ' || *p == '\t') {
+ p++;
+ }
+ if (*p != ':') {
+ continue;
}
- p++;
- while (*p == ' ' || *p == '\t') {
- p++;
- }
- fileSize = 0;
- while ('0' <= *p && *p <= '9') {
- fileSize = 10 * fileSize + (*p - '0');
- p++;
+ p++;
+ while (*p == ' ' || *p == '\t') {
+ p++;
}
- }
+ fileSize = 0;
+ while ('0' <= *p && *p <= '9') {
+ fileSize = 10 * fileSize + (*p - '0');
+ p++;
+ }
+ }
}
if (endOfHeader == PR_FALSE) {
- fprintf(stderr, "httpget: cannot read line from http server\n");
- exitStatus = 1;
- goto done;
+ fprintf(stderr, "httpget: cannot read line from http server\n");
+ exitStatus = 1;
+ goto done;
}
if (fileName == NULL || fileSize == 0) {
FetchFile(socket, file);
} else {
- FastFetchFile(socket, file, fileSize);
+ FastFetchFile(socket, file, fileSize);
}
done:
- if (socket) PR_Close(socket);
- if (file) PR_Close(file);
+ if (socket) {
+ PR_Close(socket);
+ }
+ if (file) {
+ PR_Close(file);
+ }
PR_Cleanup();
return exitStatus;
}
diff --git a/tools/tail.c b/tools/tail.c
index 32c93ddf..d9b87a0e 100644
--- a/tools/tail.c
+++ b/tools/tail.c
@@ -29,16 +29,16 @@ static void Help(void)
PRIntn main(PRIntn argc, char **argv)
{
- PRIntn rv = 0;
+ PRIntn rv = 0;
PLOptStatus os;
- PRStatus status;
- PRFileDesc *file;
- PRFileInfo fileInfo;
- PRIntervalTime dally;
- char buffer[BUFFER_SIZE];
- PRBool follow = PR_FALSE;
- const char *filename = NULL;
- PRUint32 position = 0, seek = 0, time = 0;
+ PRStatus status;
+ PRFileDesc *file;
+ PRFileInfo fileInfo;
+ PRIntervalTime dally;
+ char buffer[BUFFER_SIZE];
+ PRBool follow = PR_FALSE;
+ const char *filename = NULL;
+ PRUint32 position = 0, seek = 0, time = 0;
PLOptState *opt = PL_CreateOptState(argc, argv, "hfn:");
out = PR_GetSpecialFD(PR_StandardOutput);
@@ -46,89 +46,99 @@ PRIntn main(PRIntn argc, char **argv)
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: /* it's the filename */
- filename = opt->value;
- break;
- case 'n': /* bytes before end of file */
- seek = atoi(opt->value);
- break;
- case 't': /* dally time */
- time = atoi(opt->value);
- break;
- case 'f': /* follow the end of file */
- follow = PR_TRUE;
- break;
- case 'h': /* user wants some guidance */
- Help(); /* so give him an earful */
- return 2; /* but not a lot else */
- break;
- default:
- break;
+ case 0: /* it's the filename */
+ filename = opt->value;
+ break;
+ case 'n': /* bytes before end of file */
+ seek = atoi(opt->value);
+ break;
+ case 't': /* dally time */
+ time = atoi(opt->value);
+ break;
+ case 'f': /* follow the end of file */
+ follow = PR_TRUE;
+ break;
+ case 'h': /* user wants some guidance */
+ Help(); /* so give him an earful */
+ return 2; /* but not a lot else */
+ break;
+ default:
+ break;
}
}
PL_DestroyOptState(opt);
- if (0 == time) time = 1000;
- dally = PR_MillisecondsToInterval(time);
+ if (0 == time) {
+ time = 1000;
+ }
+ dally = PR_MillisecondsToInterval(time);
if (NULL == filename)
{
(void)PR_fprintf(out, "Input file not specified\n");
rv = 1; goto done;
}
- file = PR_Open(filename, PR_RDONLY, 0);
- if (NULL == file)
- {
- PL_FPrintError(err, "File cannot be opened for reading");
- return 1;
- }
-
- status = PR_GetOpenFileInfo(file, &fileInfo);
- if (PR_FAILURE == status)
- {
- PL_FPrintError(err, "Cannot acquire status of file");
- rv = 1; goto done;
- }
- if (seek > 0)
- {
- if (seek > fileInfo.size) seek = 0;
- position = PR_Seek(file, (fileInfo.size - seek), PR_SEEK_SET);
- if (-1 == (PRInt32)position)
- PL_FPrintError(err, "Cannot seek to starting position");
- }
-
- do
- {
- while (position < fileInfo.size)
- {
- PRInt32 read, bytes = fileInfo.size - position;
- if (bytes > sizeof(buffer)) bytes = sizeof(buffer);
- read = PR_Read(file, buffer, bytes);
- if (read != bytes)
- PL_FPrintError(err, "Cannot read to eof");
- position += read;
- PR_Write(out, buffer, read);
- }
-
- if (follow)
- {
- PR_Sleep(dally);
- status = PR_GetOpenFileInfo(file, &fileInfo);
- if (PR_FAILURE == status)
- {
- PL_FPrintError(err, "Cannot acquire status of file");
- rv = 1; goto done;
- }
- }
- } while (follow);
+ file = PR_Open(filename, PR_RDONLY, 0);
+ if (NULL == file)
+ {
+ PL_FPrintError(err, "File cannot be opened for reading");
+ return 1;
+ }
+
+ status = PR_GetOpenFileInfo(file, &fileInfo);
+ if (PR_FAILURE == status)
+ {
+ PL_FPrintError(err, "Cannot acquire status of file");
+ rv = 1; goto done;
+ }
+ if (seek > 0)
+ {
+ if (seek > fileInfo.size) {
+ seek = 0;
+ }
+ position = PR_Seek(file, (fileInfo.size - seek), PR_SEEK_SET);
+ if (-1 == (PRInt32)position) {
+ PL_FPrintError(err, "Cannot seek to starting position");
+ }
+ }
+
+ do
+ {
+ while (position < fileInfo.size)
+ {
+ PRInt32 read, bytes = fileInfo.size - position;
+ if (bytes > sizeof(buffer)) {
+ bytes = sizeof(buffer);
+ }
+ read = PR_Read(file, buffer, bytes);
+ if (read != bytes) {
+ PL_FPrintError(err, "Cannot read to eof");
+ }
+ position += read;
+ PR_Write(out, buffer, read);
+ }
+
+ if (follow)
+ {
+ PR_Sleep(dally);
+ status = PR_GetOpenFileInfo(file, &fileInfo);
+ if (PR_FAILURE == status)
+ {
+ PL_FPrintError(err, "Cannot acquire status of file");
+ rv = 1; goto done;
+ }
+ }
+ } while (follow);
done:
- PR_Close(file);
+ PR_Close(file);
- return rv;
+ return rv;
} /* main */
/* tail.c */