]> sourceware.org Git - newlib-cygwin.git/blame - winsup/cygwin/sysconf.cc
* environ.cc (environ_init): Avoid a compiler warning.
[newlib-cygwin.git] / winsup / cygwin / sysconf.cc
CommitLineData
1fd5e000
CF
1/* sysconf.cc
2
ce006ffa 3 Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
1fd5e000
CF
4
5This file is part of Cygwin.
6
7This software is a copyrighted work licensed under the terms of the
8Cygwin license. Please consult the file "CYGWIN_LICENSE" for
9details. */
10
4c8d72de 11#include "winsup.h"
1fd5e000
CF
12#include <unistd.h>
13#include <errno.h>
14#include <time.h>
15#include <limits.h>
8c8d0db4 16#include <ntdef.h>
6b91b8d5 17#include "security.h"
bccd5e0d 18#include "fhandler.h"
47063f00 19#include "path.h"
e2ebe117 20#include "dtable.h"
9e2baf8d 21#include "cygerrno.h"
df63bd49 22#include "cygheap.h"
8c8d0db4 23#include "ntdll.h"
1fd5e000
CF
24
25/* sysconf: POSIX 4.8.1.1 */
26/* Allows a portable app to determine quantities of resources or
27 presence of an option at execution time. */
28long int
29sysconf (int in)
30{
31 switch (in)
32 {
33 case _SC_ARG_MAX:
34 /* FIXME: what's the right value? _POSIX_ARG_MAX is only 4K */
35 return 1048576;
36 case _SC_OPEN_MAX:
1457739a 37 return getdtablesize ();
1fd5e000 38 case _SC_PAGESIZE:
4cf2c0e0 39 return getpagesize ();
1fd5e000
CF
40 case _SC_CLK_TCK:
41 return CLOCKS_PER_SEC;
42 case _SC_JOB_CONTROL:
43 return _POSIX_JOB_CONTROL;
44 case _SC_CHILD_MAX:
45 return CHILD_MAX;
46 case _SC_NGROUPS_MAX:
47 return NGROUPS_MAX;
48 case _SC_SAVED_IDS:
49 return _POSIX_SAVED_IDS;
50 case _SC_VERSION:
51 return _POSIX_VERSION;
52#if 0 /* FIXME -- unimplemented */
53 case _SC_TZNAME_MAX:
54 return _POSIX_TZNAME_MAX;
55 case _SC_STREAM_MAX:
56 return _POSIX_STREAM_MAX;
57#endif
8c8d0db4
CV
58 case _SC_NPROCESSORS_CONF:
59 case _SC_NPROCESSORS_ONLN:
ba946828 60 if (!wincap.supports_smp ())
8c8d0db4
CV
61 return 1;
62 /*FALLTHRU*/
63 case _SC_PHYS_PAGES:
64 case _SC_AVPHYS_PAGES:
cb4589f4 65 if (wincap.supports_smp ())
ba946828
CV
66 {
67 NTSTATUS ret;
68 SYSTEM_BASIC_INFORMATION sbi;
69 if ((ret = NtQuerySystemInformation (SystemBasicInformation,
70 (PVOID) &sbi,
71 sizeof sbi, NULL))
72 != STATUS_SUCCESS)
73 {
74 __seterrno_from_win_error (RtlNtStatusToDosError (ret));
c90e1cf1
CF
75 debug_printf ("NtQuerySystemInformation: ret = %d, "
76 "Dos(ret) = %d",
77 ret, RtlNtStatusToDosError (ret));
ba946828
CV
78 return -1;
79 }
80 switch (in)
81 {
82 case _SC_NPROCESSORS_CONF:
83 return sbi.NumberProcessors;
84 case _SC_NPROCESSORS_ONLN:
85 return sbi.ActiveProcessors;
86 case _SC_PHYS_PAGES:
87 return sbi.NumberOfPhysicalPages;
88 case _SC_AVPHYS_PAGES:
89 return sbi.HighestPhysicalPage - sbi.LowestPhysicalPage + 1;
90 }
91 }
9c510edc 92 break;
1fd5e000
CF
93 }
94
95 /* Invalid input or unimplemented sysconf name */
96 set_errno (EINVAL);
97 return -1;
98}
This page took 0.133712 seconds and 5 git commands to generate.