2000-02-18 03:38:33 +08:00
|
|
|
/* sysconf.cc
|
|
|
|
|
2003-01-10 20:32:49 +08:00
|
|
|
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2000-08-03 00:28:18 +08:00
|
|
|
#include "winsup.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <limits.h>
|
2000-10-25 02:44:56 +08:00
|
|
|
#include <ntdef.h>
|
2001-07-27 03:22:24 +08:00
|
|
|
#include "security.h"
|
2000-08-22 13:10:20 +08:00
|
|
|
#include "fhandler.h"
|
2001-10-01 12:10:07 +08:00
|
|
|
#include "path.h"
|
2000-08-12 13:35:42 +08:00
|
|
|
#include "dtable.h"
|
2000-08-22 11:58:47 +08:00
|
|
|
#include "cygerrno.h"
|
2001-10-16 07:39:33 +08:00
|
|
|
#include "cygheap.h"
|
2000-10-25 02:44:56 +08:00
|
|
|
#include "ntdll.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/* sysconf: POSIX 4.8.1.1 */
|
|
|
|
/* Allows a portable app to determine quantities of resources or
|
|
|
|
presence of an option at execution time. */
|
|
|
|
long int
|
|
|
|
sysconf (int in)
|
|
|
|
{
|
|
|
|
switch (in)
|
|
|
|
{
|
|
|
|
case _SC_ARG_MAX:
|
|
|
|
/* FIXME: what's the right value? _POSIX_ARG_MAX is only 4K */
|
|
|
|
return 1048576;
|
|
|
|
case _SC_OPEN_MAX:
|
2001-08-16 22:29:21 +08:00
|
|
|
return getdtablesize ();
|
2000-02-18 03:38:33 +08:00
|
|
|
case _SC_PAGESIZE:
|
2001-01-15 18:58:19 +08:00
|
|
|
return getpagesize ();
|
2000-02-18 03:38:33 +08:00
|
|
|
case _SC_CLK_TCK:
|
|
|
|
return CLOCKS_PER_SEC;
|
|
|
|
case _SC_JOB_CONTROL:
|
|
|
|
return _POSIX_JOB_CONTROL;
|
|
|
|
case _SC_CHILD_MAX:
|
|
|
|
return CHILD_MAX;
|
|
|
|
case _SC_NGROUPS_MAX:
|
|
|
|
return NGROUPS_MAX;
|
|
|
|
case _SC_SAVED_IDS:
|
|
|
|
return _POSIX_SAVED_IDS;
|
2003-01-02 02:12:49 +08:00
|
|
|
case _SC_LOGIN_NAME_MAX:
|
|
|
|
case _SC_GETPW_R_SIZE_MAX:
|
|
|
|
case _SC_GETGR_R_SIZE_MAX:
|
|
|
|
return 16*1024;
|
2000-02-18 03:38:33 +08:00
|
|
|
case _SC_VERSION:
|
|
|
|
return _POSIX_VERSION;
|
|
|
|
#if 0 /* FIXME -- unimplemented */
|
|
|
|
case _SC_TZNAME_MAX:
|
|
|
|
return _POSIX_TZNAME_MAX;
|
|
|
|
case _SC_STREAM_MAX:
|
|
|
|
return _POSIX_STREAM_MAX;
|
|
|
|
#endif
|
2000-10-25 02:44:56 +08:00
|
|
|
case _SC_NPROCESSORS_CONF:
|
|
|
|
case _SC_NPROCESSORS_ONLN:
|
* Makefile.in: Build wincap.o.
* wincap.cc: New file.
* wincap.h: Ditto.
* autoload.cc: Add dynamic load statement for `CreateHardLinkA'.
* dcrt0.cc (os_being_run): Eliminated.
(osname): Ditto.
(iswinnt): Ditto.
(set_os_type): Ditto.
(dll_crt0_1): Call wincap.init() instead of set_os_type().
(_dll_crt0): Ditto.
* environ.cc (set_chunksize): New function.
(parse_thing): `forkchunk' setting now invokes function `set_chunksize'.
* fork.cc (chunksize): Eliminated. Moved to be member of wincap.
* host_dependent.h: Removed.
* syscalls.cc (_link): Try using `CreateHardLinkA' first, if available.
* cygheap.cc, dcrt0.cc, delqueue.cc, dir.cc,
environ.cc, fhandler.cc, fhandler.h, fhandler_console.cc,
fhandler_mem.cc, fork.cc, mmap.cc, net.cc, pinfo.cc, pinfo.h,
security.cc, syscalls.cc, sysconf.cc, syslog.cc, thread.cc,
times.cc, tty.cc, uinfo.cc, uname.cc, winsup.h: Use new wincap
capability check throughout.
* winsup.h: Include wincap.h. Eliminate extern declarations of
`os_being_run' and `iswinnt'. Eliminate `os_type" definition.
* include/cygwin/version.h: Bump version to 1.3.4.
2001-09-13 01:46:37 +08:00
|
|
|
if (!wincap.supports_smp ())
|
2000-10-25 02:44:56 +08:00
|
|
|
return 1;
|
|
|
|
/*FALLTHRU*/
|
|
|
|
case _SC_PHYS_PAGES:
|
|
|
|
case _SC_AVPHYS_PAGES:
|
2002-03-12 16:57:22 +08:00
|
|
|
if (wincap.supports_smp ())
|
* Makefile.in: Build wincap.o.
* wincap.cc: New file.
* wincap.h: Ditto.
* autoload.cc: Add dynamic load statement for `CreateHardLinkA'.
* dcrt0.cc (os_being_run): Eliminated.
(osname): Ditto.
(iswinnt): Ditto.
(set_os_type): Ditto.
(dll_crt0_1): Call wincap.init() instead of set_os_type().
(_dll_crt0): Ditto.
* environ.cc (set_chunksize): New function.
(parse_thing): `forkchunk' setting now invokes function `set_chunksize'.
* fork.cc (chunksize): Eliminated. Moved to be member of wincap.
* host_dependent.h: Removed.
* syscalls.cc (_link): Try using `CreateHardLinkA' first, if available.
* cygheap.cc, dcrt0.cc, delqueue.cc, dir.cc,
environ.cc, fhandler.cc, fhandler.h, fhandler_console.cc,
fhandler_mem.cc, fork.cc, mmap.cc, net.cc, pinfo.cc, pinfo.h,
security.cc, syscalls.cc, sysconf.cc, syslog.cc, thread.cc,
times.cc, tty.cc, uinfo.cc, uname.cc, winsup.h: Use new wincap
capability check throughout.
* winsup.h: Include wincap.h. Eliminate extern declarations of
`os_being_run' and `iswinnt'. Eliminate `os_type" definition.
* include/cygwin/version.h: Bump version to 1.3.4.
2001-09-13 01:46:37 +08:00
|
|
|
{
|
|
|
|
NTSTATUS ret;
|
|
|
|
SYSTEM_BASIC_INFORMATION sbi;
|
|
|
|
if ((ret = NtQuerySystemInformation (SystemBasicInformation,
|
|
|
|
(PVOID) &sbi,
|
|
|
|
sizeof sbi, NULL))
|
|
|
|
!= STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
__seterrno_from_win_error (RtlNtStatusToDosError (ret));
|
2002-09-22 11:38:57 +08:00
|
|
|
debug_printf ("NtQuerySystemInformation: ret = %d, "
|
|
|
|
"Dos(ret) = %d",
|
|
|
|
ret, RtlNtStatusToDosError (ret));
|
* Makefile.in: Build wincap.o.
* wincap.cc: New file.
* wincap.h: Ditto.
* autoload.cc: Add dynamic load statement for `CreateHardLinkA'.
* dcrt0.cc (os_being_run): Eliminated.
(osname): Ditto.
(iswinnt): Ditto.
(set_os_type): Ditto.
(dll_crt0_1): Call wincap.init() instead of set_os_type().
(_dll_crt0): Ditto.
* environ.cc (set_chunksize): New function.
(parse_thing): `forkchunk' setting now invokes function `set_chunksize'.
* fork.cc (chunksize): Eliminated. Moved to be member of wincap.
* host_dependent.h: Removed.
* syscalls.cc (_link): Try using `CreateHardLinkA' first, if available.
* cygheap.cc, dcrt0.cc, delqueue.cc, dir.cc,
environ.cc, fhandler.cc, fhandler.h, fhandler_console.cc,
fhandler_mem.cc, fork.cc, mmap.cc, net.cc, pinfo.cc, pinfo.h,
security.cc, syscalls.cc, sysconf.cc, syslog.cc, thread.cc,
times.cc, tty.cc, uinfo.cc, uname.cc, winsup.h: Use new wincap
capability check throughout.
* winsup.h: Include wincap.h. Eliminate extern declarations of
`os_being_run' and `iswinnt'. Eliminate `os_type" definition.
* include/cygwin/version.h: Bump version to 1.3.4.
2001-09-13 01:46:37 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
switch (in)
|
|
|
|
{
|
|
|
|
case _SC_NPROCESSORS_CONF:
|
|
|
|
return sbi.NumberProcessors;
|
|
|
|
case _SC_NPROCESSORS_ONLN:
|
|
|
|
return sbi.ActiveProcessors;
|
|
|
|
case _SC_PHYS_PAGES:
|
|
|
|
return sbi.NumberOfPhysicalPages;
|
|
|
|
case _SC_AVPHYS_PAGES:
|
|
|
|
return sbi.HighestPhysicalPage - sbi.LowestPhysicalPage + 1;
|
|
|
|
}
|
|
|
|
}
|
2001-11-05 14:09:15 +08:00
|
|
|
break;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Invalid input or unimplemented sysconf name */
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|