1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Mozilla Public License Version
6
* 1.1 (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/MPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is the Netscape Portable Runtime (NSPR).
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998-2000
20
* the Initial Developer. All Rights Reserved.
24
* Alternatively, the contents of this file may be used under the terms of
25
* either the GNU General Public License Version 2 or later (the "GPL"), or
26
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
* in which case the provisions of the GPL or the LGPL are applicable instead
28
* of those above. If you wish to allow use of your version of this file only
29
* under the terms of either the GPL or the LGPL, and not to allow others to
30
* use your version of this file under the terms of the MPL, indicate your
31
* decision by deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL or the LGPL. If you do not delete
33
* the provisions above, a recipient may use your version of this file under
34
* the terms of any one of the MPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
39
* NCR 3.0 - cloned from UnixWare by ruslan
45
void _MD_EarlyInit(void)
49
PRWord *_MD_HomeGCRegisters(PRThread *t, int isCurrent, int *np)
52
(void) setjmp(CONTEXT(t));
54
*np = sizeof(CONTEXT(t)) / sizeof(PRWord);
55
return (PRWord *) CONTEXT(t);
58
#ifdef ALARMS_BREAK_TCP /* I don't think they do */
60
PRInt32 _MD_connect(PRInt32 osfd, const PRNetAddr *addr, PRInt32 addrlen,
61
PRIntervalTime timeout)
65
_MD_BLOCK_CLOCK_INTERRUPTS();
66
rv = _connect(osfd,addr,addrlen);
67
_MD_UNBLOCK_CLOCK_INTERRUPTS();
70
PRInt32 _MD_accept(PRInt32 osfd, PRNetAddr *addr, PRInt32 addrlen,
71
PRIntervalTime timeout)
75
_MD_BLOCK_CLOCK_INTERRUPTS();
76
rv = _accept(osfd,addr,addrlen);
77
_MD_UNBLOCK_CLOCK_INTERRUPTS();
83
* These are also implemented in pratom.c using NSPR locks. Any reason
84
* this might be better or worse? If you like this better, define
85
* _PR_HAVE_ATOMIC_OPS in include/md/unixware.h
87
#ifdef _PR_HAVE_ATOMIC_OPS
88
/* Atomic operations */
90
static FILE *_uw_semf;
95
/* Sigh. Sure wish SYSV semaphores weren't such a pain to use */
96
if ((_uw_semf = tmpfile()) == NULL)
103
_MD_ATOMIC_INCREMENT(PRInt32 *val)
107
unflockfile(_uw_semf);
111
_MD_ATOMIC_ADD(PRInt32 *ptr, PRInt32 val)
115
unflockfile(_uw_semf);
120
_MD_ATOMIC_DECREMENT(PRInt32 *val)
124
unflockfile(_uw_semf);
128
_MD_ATOMIC_SET(PRInt32 *val, PRInt32 newval)
132
unflockfile(_uw_semf);
137
_MD_SET_PRIORITY(_MDThread *thread, PRUintn newPri)
143
_MD_InitializeThread(PRThread *thread)
149
_MD_WAIT(PRThread *thread, PRIntervalTime ticks)
151
PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
152
_PR_MD_SWITCH_CONTEXT(thread);
157
_MD_WAKEUP_WAITER(PRThread *thread)
160
PR_ASSERT(!(thread->flags & _PR_GLOBAL_SCOPE));
165
/* These functions should not be called for Unixware */
169
PR_NOT_REACHED("_MD_YIELD should not be called for Unixware.");
175
void (*start) (void *),
181
PR_NOT_REACHED("_MD_CREATE_THREAD should not be called for Unixware.");
186
This is temp. replacement for localtime_r. Normally PR_ExplodeTime should
187
be used as to my understanding
191
** $$$$$ THEN WHY ARE WE DOING THIS? - AOF $$$$$
194
#define NEED_LOCALTIME_R
195
#define NEED_GMTIME_R
196
#define NEED_ASCTIME_R
197
#define NEED_STRTOK_R
200
#if defined (NEED_LOCALTIME_R) || defined (NEED_CTIME_R) || defined (NEED_ASCTIME_R) || defined (NEED_GMTIME_R) || defined (NEED_STRTOK_R)
204
#if defined (NEED_LOCALTIME_R)
206
static PRLock *localtime_r_monitor = NULL;
208
struct tm *localtime_r (const time_t *clock, struct tm *result)
211
int needLock = PR_Initialized(); /* We need to use a lock to protect
212
* against NSPR threads only when the
213
* NSPR thread system is activated. */
216
if (localtime_r_monitor == NULL) {
218
localtime_r_monitor = PR_NewLock();
220
PR_Lock(localtime_r_monitor);
224
* On Windows, localtime() returns a NULL pointer if 'clock'
225
* represents a time before midnight January 1, 1970. In
226
* that case, we also return a NULL pointer and the struct tm
227
* object pointed to by 'result' is not modified.
230
tmPtr = localtime(clock);
237
if (needLock) PR_Unlock(localtime_r_monitor);
244
#if defined (NEED_GMTIME_R)
246
static PRLock *gmtime_r_monitor = NULL;
248
struct tm *gmtime_r (const time_t *clock, struct tm *result)
251
int needLock = PR_Initialized(); /* We need to use a lock to protect
252
* against NSPR threads only when the
253
* NSPR thread system is activated. */
256
if (gmtime_r_monitor == NULL) {
257
gmtime_r_monitor = PR_NewLock();
259
PR_Lock(gmtime_r_monitor);
262
tmPtr = gmtime(clock);
269
if (needLock) PR_Unlock(gmtime_r_monitor);
276
#if defined (NEED_CTIME_R)
278
static PRLock *ctime_r_monitor = NULL;
280
char *ctime_r (const time_t *clock, char *buf, int buflen)
283
int needLock = PR_Initialized(); /* We need to use a lock to protect
284
* against NSPR threads only when the
285
* NSPR thread system is activated. */
289
if (ctime_r_monitor == NULL) {
290
ctime_r_monitor = PR_NewLock();
292
PR_Lock(ctime_r_monitor);
295
cbuf = ctime (clock);
297
strncpy (buf, cbuf, buflen - 1);
301
if (needLock) PR_Unlock(ctime_r_monitor);
308
#if defined (NEED_ASCTIME_R)
310
static PRLock *asctime_r_monitor = NULL;
313
char *asctime_r (const struct tm *tm, char *buf, int buflen)
316
int needLock = PR_Initialized(); /* We need to use a lock to protect
317
* against NSPR threads only when the
318
* NSPR thread system is activated. */
321
if (asctime_r_monitor == NULL) {
322
asctime_r_monitor = PR_NewLock();
324
PR_Lock(asctime_r_monitor);
329
strncpy (buf, cbuf, buflen - 1);
333
if (needLock) PR_Unlock(asctime_r_monitor);
340
#if defined (NEED_STRTOK_R)
343
strtok_r (s, delim, last)
345
register const char *delim;
346
register char **last;
348
register char *spanp;
353
if (s == NULL && (s = *last) == NULL)
357
* Skip (span) leading delimiters (s += strspn(s, delim), sort of).
362
for (spanp = (char *)delim; (sc = *spanp++) != 0;) {
367
if (c == 0) { /* no non-delimiter characters */
374
* Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
375
* Note that delim must have one NUL; we stop if we see that, too.
379
spanp = (char *)delim;
381
if ((sc = *spanp++) == c) {