Add BIND 9.2.4rc7.
[dragonfly.git] / contrib / bind-9.2.4rc7 / lib / isc / unix / os.c
blobbc9ac24a515bf21a0f4d9424652f1718a0ca7d65
1 /*
2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2000, 2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: os.c,v 1.11.2.2 2004/05/18 01:38:39 marka Exp $ */
20 #include <config.h>
22 #include <isc/os.h>
25 #ifdef HAVE_SYSCONF
27 #include <unistd.h>
29 static inline long
30 sysconf_ncpus(void) {
31 #if defined(_SC_NPROCESSORS_ONLN)
32 return sysconf((_SC_NPROCESSORS_ONLN));
33 #elif defined(_SC_NPROC_ONLN)
34 return sysconf((_SC_NPROC_ONLN));
35 #else
36 return (0);
37 #endif
39 #endif /* HAVE_SYSCONF */
42 #ifdef __hpux
44 #include <sys/pstat.h>
46 static inline int
47 hpux_ncpus(void) {
48 struct pst_dynamic psd;
49 if (pstat_getdynamic(&psd, sizeof(psd), 1, 0) != -1)
50 return (psd.psd_proc_cnt);
51 else
52 return (0);
55 #endif /* __hpux */
57 #if defined(HAVE_SYS_SYSCTL_H) && defined(HAVE_SYSCTLBYNAME)
58 #include <sys/types.h> /* for FreeBSD */
59 #include <sys/param.h> /* for NetBSD */
60 #include <sys/sysctl.h>
62 static int
63 sysctl_ncpus(void) {
64 int ncpu, result;
65 size_t len;
67 len = sizeof ncpu;
68 result = sysctlbyname("hw.ncpu", &ncpu, &len , 0, 0);
69 if (result != -1)
70 return (ncpu);
71 return (0);
73 #endif
75 unsigned int
76 isc_os_ncpus(void) {
77 long ncpus = 0;
79 #ifdef __hpux
80 ncpus = hpux_ncpus();
81 #elif defined(HAVE_SYSCONF)
82 ncpus = sysconf_ncpus();
83 #endif
84 #if defined(HAVE_SYS_SYSCTL_H) && defined(HAVE_SYSCTLBYNAME)
85 if (ncpus <= 0)
86 ncpus = sysctl_ncpus();
87 #endif
88 if (ncpus <= 0)
89 ncpus = 1;
91 return ((unsigned int)ncpus);