libc/winsup/cygwin/sysconf.cc

129 lines
3.0 KiB
C++
Raw Normal View History

2000-02-17 20:38:33 +01:00
/* sysconf.cc
Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
2000-02-17 20:38:33 +01: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. */
#include "winsup.h"
2000-02-17 20:38:33 +01:00
#include <unistd.h>
#include <time.h>
#include <limits.h>
#include <ntdef.h>
#include "security.h"
#include "fhandler.h"
Add "path.h" include throughout, where needed. Use new path_conv methods and operators to simplify testing for directory and attributes, throughout. * path.h (path_conv::exists): New method. (path_conv::has_attribute): Ditto. (path_conv::isdir): Ditto. (path_conv::DWORD &): New operator. (path_conv::int &): Ditto. * dir.cc (rmdir): Eliminate a goto. * dtable.cc (dtable::build_fhandler): Accept opt and suffix info for path_conv.check. Return fh == NULL on path_conv error. Pass unit to set_name as appropriate. (dtable::reset_unix_path_name): New method. * dtable.h (dtable): Declare new method. Reflect arg changes to build_fhandler. * fhandler.cc (fhandler_disk_dummy_name): Eliminate. (fhandler_base::set_name): Expect paths to be NULL. Build unix_path_name from win32_path_name when it is a device. (fhandler_base::reset_unix_path_name): New method. (fhandler_base::raw_read): Report EISDIR when ERROR_INVALID_FUNCTION or ERROR_INVALID_PARAMETER and reading a directory. (fhandler_disk_file::fstat): Don't call stat_dev since we should now never be calling fhandler_disk_file methods with devices. (fhandler_base::fhandler_base): Clear {unix,win32}_path_name. (fhandler_base::~fhandler_base): Always free {unix,win32}_path_name. (fhandler_disk_file::fhandler_disk_file): Remove set_no_free_names kludge. (fhandler_disk_file::open): Ditto. * fhandler.h (fhandler_base::no_free_names): Eliminate. (fhandler_base::set_no_free_names): Ditto. * fhandler_tty.cc (fhandler_tty_slave::fhandler_tty_slave): Don't set unix_path_name here. * path.cc (fchdir): Lock fd table throughout. Use new dtable::reset_unix_path_name method to reset path. * syscalls.cc (stat_worker): Reorganize to always call fstat method. Pass path_conv method to fhandler_*::open. (chroot): Elminate a goto.
2001-10-01 06:10:07 +02:00
#include "path.h"
#include "dtable.h"
#include "cygerrno.h"
#include "cygheap.h"
#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:
{
long max = getdtablesize ();
if (max < OPEN_MAX)
max = OPEN_MAX;
return max;
}
case _SC_PAGESIZE:
return getpagesize ();
2000-02-17 20:38:33 +01: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;
case _SC_LOGIN_NAME_MAX:
case _SC_GETPW_R_SIZE_MAX:
case _SC_GETGR_R_SIZE_MAX:
return 16*1024;
2000-02-17 20:38:33 +01: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
case _SC_NPROCESSORS_CONF:
case _SC_NPROCESSORS_ONLN:
if (!wincap.supports_smp ())
return 1;
/*FALLTHRU*/
case _SC_PHYS_PAGES:
2002-03-12 09:57:22 +01:00
if (wincap.supports_smp ())
{
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:
{
int i = 0;
do
if (sbi.ActiveProcessors & 1)
i++;
while (sbi.ActiveProcessors >>= 1);
return i;
}
case _SC_PHYS_PAGES:
return sbi.NumberOfPhysicalPages;
}
}
2001-11-05 07:09:15 +01:00
break;
case _SC_AVPHYS_PAGES:
if (wincap.supports_smp ())
{
NTSTATUS ret;
SYSTEM_PERFORMANCE_INFORMATION spi;
if ((ret = NtQuerySystemInformation (SystemPerformanceInformation,
(PVOID) &spi,
sizeof spi, NULL))
!= STATUS_SUCCESS)
{
__seterrno_from_win_error (RtlNtStatusToDosError (ret));
debug_printf ("NtQuerySystemInformation: ret = %d, "
"Dos(ret) = %d",
ret, RtlNtStatusToDosError (ret));
return -1;
}
return spi.AvailablePages;
}
2000-02-17 20:38:33 +01:00
}
/* Invalid input or unimplemented sysconf name */
set_errno (EINVAL);
return -1;
}