OSDN Git Service

* cygerrno.h: New file. Use this throughout whenever errno manipulation is
[pf3gnuchains/pf3gnuchains3x.git] / winsup / cygwin / sysconf.cc
1 /* sysconf.cc
2
3    Copyright 1996, 1997, 1998 Cygnus Solutions.
4
5 This file is part of Cygwin.
6
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
9 details. */
10
11 #include "winsup.h"
12 #include <unistd.h>
13 #include <errno.h>
14 #include <time.h>
15 #include <limits.h>
16 #include "dtable.h"
17 #include "cygerrno.h"
18
19 /* sysconf: POSIX 4.8.1.1 */
20 /* Allows a portable app to determine quantities of resources or
21    presence of an option at execution time. */
22 long int
23 sysconf (int in)
24 {
25   switch (in)
26     {
27       case _SC_ARG_MAX:
28         /* FIXME: what's the right value?  _POSIX_ARG_MAX is only 4K */
29         return 1048576;
30       case _SC_OPEN_MAX:
31         /* FIXME: this returns the current limit which can increase
32            if and when dtable::find_unused_handle is called.  Perhaps
33            we should return NOFILE or OPEN_MAX instead? */
34         return fdtab.size;
35       case _SC_PAGESIZE:
36         {
37           SYSTEM_INFO b;
38           GetSystemInfo (&b);
39           return b.dwPageSize;
40         }
41       case _SC_CLK_TCK:
42         return CLOCKS_PER_SEC;
43       case _SC_JOB_CONTROL:
44         return _POSIX_JOB_CONTROL;
45       case _SC_CHILD_MAX:
46         return CHILD_MAX;
47       case _SC_NGROUPS_MAX:
48         return NGROUPS_MAX;
49       case _SC_SAVED_IDS:
50         return _POSIX_SAVED_IDS;
51       case _SC_VERSION:
52         return _POSIX_VERSION;
53 #if 0   /* FIXME -- unimplemented */
54       case _SC_TZNAME_MAX:
55         return _POSIX_TZNAME_MAX;
56       case _SC_STREAM_MAX:
57         return _POSIX_STREAM_MAX;
58 #endif
59     }
60
61   /* Invalid input or unimplemented sysconf name */
62   set_errno (EINVAL);
63   return -1;
64 }