tt/mini_isam: remove all ancient sccsid blocks
[oweals/cde.git] / cde / lib / tt / mini_isam / isfcbwatchfd.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*%%  (c) Copyright 1993, 1994 Hewlett-Packard Company                   */
24 /*%%  (c) Copyright 1993, 1994 International Business Machines Corp.     */
25 /*%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                    */
26 /*%%  (c) Copyright 1993, 1994 Novell, Inc.                              */
27 /*%%  $XConsortium: isfcbwatchfd.c /main/3 1995/10/23 11:38:51 rswiston $                                                        */
28 /*
29  * Copyright (c) 1988 by Sun Microsystems, Inc.
30  */
31
32 /*
33  * isfcbwatchfd.c
34  *
35  * Description:
36  *      Watch the limit on UNIX file descriptors used by the FCB module.
37  */
38
39 #if defined(_AIX)
40 #define _POSIX_SYSCONF
41 #endif 
42
43 #if defined(_AIX)
44 #define _POSIX_SYSCONF
45 #endif 
46
47 #include "isam_impl.h"
48 #include <sys/time.h>
49 #include <sys/resource.h>
50 #ifdef _POSIX_SYSCONF
51 #include <unistd.h>
52 #endif /* _POSIX_SYSCONF */
53
54 static int _limit = MAXFCB_UNIXFD;           /* Imposed limit */
55 static int _in_use = 0;                      /* Current number of 
56                                               * open file descriptors
57                                               */
58
59 /*
60  * _watchfd_incr(n)
61  *
62  * Register that n additional UNIX file descriptors were open.
63  *
64  * Return the new number of open file descriptors.
65  */
66
67 int
68 _watchfd_incr(int n)
69 {
70     _in_use += n;
71     assert(_in_use <= _limit);
72     return (_in_use);
73 }
74
75
76 /*
77  * _watch_decr(n)
78  *
79  * Register that n open file descriptors were closed.
80  *
81  * Return the new number of open file descriptors.
82  */
83
84 int
85 _watchfd_decr(int n)
86 {
87     _in_use -= n;
88     assert(_in_use >= 0);
89     return (_in_use);
90 }
91
92
93 /*
94  * _watch_check()
95  *
96  * Return number of fd that are still available.
97  */
98
99 int
100 _watchfd_check(void)
101 {
102     return (_limit - _in_use);
103 }
104
105
106 /*
107  * _watchfd_max_set(n)
108  *
109  * Set the maximum number of UNIX fds that may be comsumed by ISAM files.
110  */
111
112 int
113 _watchfd_max_set(int n)
114 {
115     int         oldlimit = _limit;
116
117 #ifdef _POSIX_SYSCONF
118     if (n < 3 || n > sysconf(_SC_OPEN_MAX)) {
119 #else
120     int dtab_size = 0;
121     struct rlimit rl;
122     if (getrlimit(RLIMIT_NOFILE, &rl) == 0)
123       dtab_size = rl.rlim_cur;
124
125     if (n < 3 || n > dtab_size) {
126 #endif
127         _setiserrno2(EBADARG, '9', '0');
128         return (ISERROR);
129     }
130
131     _limit = n;
132     return (oldlimit);
133 }
134
135 /*
136  * _watchfd_max_get()
137  *
138  * Get the maximum number of UNIX fds that may be comsumed by ISAM files.
139  */
140
141 int
142 _watchfd_max_get(void)
143 {
144     return (_limit);
145 }