2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
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 $ */
29 * Copyright (c) 1988 by Sun Microsystems, Inc.
36 * Watch the limit on UNIX file descriptors used by the FCB module.
40 #define _POSIX_SYSCONF
44 #define _POSIX_SYSCONF
47 #include "isam_impl.h"
49 #include <sys/resource.h>
52 #endif /* _POSIX_SYSCONF */
54 static int _limit = MAXFCB_UNIXFD; /* Imposed limit */
55 static int _in_use = 0; /* Current number of
56 * open file descriptors
62 * Register that n additional UNIX file descriptors were open.
64 * Return the new number of open file descriptors.
71 assert(_in_use <= _limit);
79 * Register that n open file descriptors were closed.
81 * Return the new number of open file descriptors.
96 * Return number of fd that are still available.
102 return (_limit - _in_use);
107 * _watchfd_max_set(n)
109 * Set the maximum number of UNIX fds that may be comsumed by ISAM files.
113 _watchfd_max_set(int n)
115 int oldlimit = _limit;
117 #ifdef _POSIX_SYSCONF
118 if (n < 3 || n > sysconf(_SC_OPEN_MAX)) {
122 if (getrlimit(RLIMIT_NOFILE, &rl) == 0)
123 dtab_size = rl.rlim_cur;
125 if (n < 3 || n > dtab_size) {
127 _setiserrno2(EBADARG, '9', '0');
138 * Get the maximum number of UNIX fds that may be comsumed by ISAM files.
142 _watchfd_max_get(void)