1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
3
* The contents of this file are subject to the Mozilla Public
4
* License Version 1.1 (the "License"); you may not use this file
5
* except in compliance with the License. You may obtain a copy of
6
* the License at http://www.mozilla.org/MPL/
8
* Software distributed under the License is distributed on an "AS
9
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10
* implied. See the License for the specific language governing
11
* rights and limitations under the License.
13
* The Original Code is the Netscape Portable Runtime (NSPR).
15
* The Initial Developer of the Original Code is Netscape
16
* Communications Corporation. Portions created by Netscape are
17
* Copyright (C) 1998-2000 Netscape Communications Corporation. All
22
* Alternatively, the contents of this file may be used under the
23
* terms of the GNU General Public License Version 2 or later (the
24
* "GPL"), in which case the provisions of the GPL are applicable
25
* instead of those above. If you wish to allow use of your
26
* version of this file only under the terms of the GPL and not to
27
* allow others to use your version of this file under the MPL,
28
* indicate your decision by deleting the provisions above and
29
* replace them with the notice and other provisions required by
30
* the GPL. If you do not delete the provisions above, a recipient
31
* may use your version of this file under either the MPL or the
40
#include <kernel/OS.h>
46
/* define the required constant if it is not already defined in the headers */
47
#ifndef QSV_NUMPROCESSORS
48
#define QSV_NUMPROCESSORS 26
52
/* BSD-derived systems use sysctl() to get the number of processors */
53
#if defined(BSDI) || defined(FREEBSD) || defined(NETBSD) \
54
|| defined(OPENBSD) || defined(DARWIN)
55
#define _PR_HAVE_SYSCTL
56
#include <sys/param.h>
57
#include <sys/sysctl.h>
61
#include <sys/mpctl.h>
66
#include <sys/utsname.h>
69
PR_IMPLEMENT(char) PR_GetDirectorySeparator(void)
71
return PR_DIRECTORY_SEPARATOR;
72
} /* PR_GetDirectorySeparator */
75
** OBSOLETE -- the function name is misspelled.
77
PR_IMPLEMENT(char) PR_GetDirectorySepartor(void)
80
static PRBool warn = PR_TRUE;
82
warn = _PR_Obsolete("PR_GetDirectorySepartor()",
83
"PR_GetDirectorySeparator()");
86
return PR_GetDirectorySeparator();
87
} /* PR_GetDirectorySepartor */
89
PR_IMPLEMENT(char) PR_GetPathSeparator(void)
91
return PR_PATH_SEPARATOR;
92
} /* PR_GetPathSeparator */
94
PR_IMPLEMENT(PRStatus) PR_GetSystemInfo(PRSysInfo cmd, char *buf, PRUint32 buflen)
98
if (!_pr_initialized) _PR_ImplicitInitialization();
103
if (PR_FAILURE == _PR_MD_GETHOSTNAME(buf, (PRUintn)buflen))
106
* On some platforms a system does not have a hostname and
107
* its IP address is returned instead. The following code
108
* should be skipped on those platforms.
110
#ifndef _PR_GET_HOST_ADDR_AS_NAME
111
/* Return the unqualified hostname */
112
while (buf[len] && (len < buflen)) {
113
if (buf[len] == '.') {
123
/* Return the operating system name */
124
#if defined(XP_UNIX) || defined(WIN32)
125
if (PR_FAILURE == _PR_MD_GETSYSINFO(cmd, buf, (PRUintn)buflen))
128
(void)PR_snprintf(buf, buflen, _PR_SI_SYSNAME);
133
/* Return the version of the operating system */
134
#if defined(XP_UNIX) || defined(WIN32)
135
if (PR_FAILURE == _PR_MD_GETSYSINFO(cmd, buf, (PRUintn)buflen))
140
ULONG os2ver[2] = {0};
141
DosQuerySysInfo(QSV_VERSION_MINOR, QSV_VERSION_REVISION,
142
&os2ver, sizeof(os2ver));
143
/* Formatting for normal usage (2.11, 3.0, 4.0, 4.5); officially,
144
Warp 4 is version 2.40.00, WSeB 2.45.00 */
146
(void)PR_snprintf(buf, buflen, "%s%lu",
148
else if (os2ver[0] < 45)
149
(void)PR_snprintf(buf, buflen, "%lu%s%lu",
150
os2ver[0]/10, ".", os2ver[1]);
152
(void)PR_snprintf(buf, buflen, "%.1f",
158
case PR_SI_ARCHITECTURE:
159
/* Return the architecture of the machine (ie. x86, mips, alpha, ...)*/
160
(void)PR_snprintf(buf, buflen, _PR_SI_ARCHITECTURE);
163
PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0);
170
** PR_GetNumberOfProcessors()
172
** Implementation notes:
173
** Every platform does it a bit different.
174
** numCpus is the returned value.
175
** for each platform's "if defined" section
176
** declare your local variable
177
** do your thing, assign to numCpus
178
** order of the if defined()s may be important,
179
** especially for unix variants. Do platform
180
** specific implementations before XP_UNIX.
183
PR_IMPLEMENT(PRInt32) PR_GetNumberOfProcessors( void )
189
GetSystemInfo( &info );
190
numCpus = info.dwNumberOfProcessors;
191
#elif defined(XP_MAC)
192
/* Hard-code the number of processors to 1 on the Mac
193
** MacOS/9 will always be 1. The MPProcessors() call is for
194
** MacOS/X, when issued. Leave it commented out for now. */
195
/* numCpus = MPProcessors(); */
200
get_system_info(&sysInfo);
201
numCpus = sysInfo.cpu_count;
203
DosQuerySysInfo( QSV_NUMPROCESSORS, QSV_NUMPROCESSORS, &numCpus, sizeof(numCpus));
204
#elif defined(_PR_HAVE_SYSCTL)
207
size_t len = sizeof(numCpus);
211
rc = sysctl( mib, 2, &numCpus, &len, NULL, 0 );
213
numCpus = -1; /* set to -1 for return value on error */
214
_PR_MD_MAP_DEFAULT_ERROR( _MD_ERRNO() );
217
numCpus = mpctl( MPC_GETNUMSPUS, 0, 0 );
219
numCpus = -1; /* set to -1 for return value on error */
220
_PR_MD_MAP_DEFAULT_ERROR( _MD_ERRNO() );
223
numCpus = sysconf( _SC_NPROC_ONLN );
224
#elif defined(XP_UNIX)
225
numCpus = sysconf( _SC_NPROCESSORS_ONLN );
227
#error "An implementation is required"
230
} /* end PR_GetNumberOfProcessors() */