2000-02-17 20:38:33 +01:00
|
|
|
/* sysconf.cc
|
|
|
|
|
|
|
|
Copyright 1996, 1997, 1998 Cygnus Solutions.
|
|
|
|
|
|
|
|
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-02 18:28:18 +02:00
|
|
|
#include "winsup.h"
|
2000-02-17 20:38:33 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <limits.h>
|
2000-10-24 20:44:56 +02:00
|
|
|
#include <ntdef.h>
|
2000-08-22 07:10:20 +02:00
|
|
|
#include "fhandler.h"
|
2000-08-12 07:35:42 +02:00
|
|
|
#include "dtable.h"
|
2000-08-22 05:58:47 +02:00
|
|
|
#include "cygerrno.h"
|
2000-10-24 20:44:56 +02:00
|
|
|
#include "ntdll.h"
|
2000-02-17 20:38:33 +01: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:
|
|
|
|
/* FIXME: this returns the current limit which can increase
|
2000-08-12 06:48:44 +02:00
|
|
|
if and when dtable::find_unused_handle is called. Perhaps
|
2000-02-17 20:38:33 +01:00
|
|
|
we should return NOFILE or OPEN_MAX instead? */
|
2000-08-12 06:48:44 +02:00
|
|
|
return fdtab.size;
|
2000-02-17 20:38:33 +01:00
|
|
|
case _SC_PAGESIZE:
|
|
|
|
{
|
|
|
|
SYSTEM_INFO b;
|
|
|
|
GetSystemInfo (&b);
|
|
|
|
return b.dwPageSize;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
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-24 20:44:56 +02:00
|
|
|
case _SC_NPROCESSORS_CONF:
|
|
|
|
case _SC_NPROCESSORS_ONLN:
|
|
|
|
if (os_being_run != winNT)
|
|
|
|
return 1;
|
|
|
|
/*FALLTHRU*/
|
|
|
|
case _SC_PHYS_PAGES:
|
|
|
|
case _SC_AVPHYS_PAGES:
|
|
|
|
{
|
|
|
|
NTSTATUS ret;
|
|
|
|
SYSTEM_BASIC_INFORMATION sbi;
|
|
|
|
if ((ret = NtQuerySystemInformation (SystemBasicInformation,
|
|
|
|
(PVOID) &sbi,
|
|
|
|
sizeof sbi, NULL))
|
|
|
|
!= STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
__seterrno_from_win_error (RtlNtStatusToDosError (ret));
|
|
|
|
debug_printf("NtQuerySystemInformation: ret = %d, "
|
|
|
|
"Dos(ret) = %d",
|
|
|
|
ret, RtlNtStatusToDosError (ret));
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2000-02-17 20:38:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Invalid input or unimplemented sysconf name */
|
|
|
|
set_errno (EINVAL);
|
|
|
|
return -1;
|
|
|
|
}
|