174462Salfred/* $NetBSD: rpc_dtablesize.c,v 1.14 1998/11/15 17:32:43 christos Exp $ */ 274462Salfred 3261057Smav/*- 4261057Smav * Copyright (c) 2009, Sun Microsystems, Inc. 5261057Smav * All rights reserved. 68870Srgrimes * 7261057Smav * Redistribution and use in source and binary forms, with or without 8261057Smav * modification, are permitted provided that the following conditions are met: 9261057Smav * - Redistributions of source code must retain the above copyright notice, 10261057Smav * this list of conditions and the following disclaimer. 11261057Smav * - Redistributions in binary form must reproduce the above copyright notice, 12261057Smav * this list of conditions and the following disclaimer in the documentation 13261057Smav * and/or other materials provided with the distribution. 14261057Smav * - Neither the name of Sun Microsystems, Inc. nor the names of its 15261057Smav * contributors may be used to endorse or promote products derived 16261057Smav * from this software without specific prior written permission. 17261057Smav * 18261057Smav * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19261057Smav * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20261057Smav * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21261057Smav * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 22261057Smav * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23261057Smav * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24261057Smav * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25261057Smav * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26261057Smav * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27261057Smav * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28261057Smav * POSSIBILITY OF SUCH DAMAGE. 291901Swollman */ 301901Swollman 311901Swollman#if defined(LIBC_SCCS) && !defined(lint) 32136581Sobrienstatic char *sccsid2 = "@(#)rpc_dtablesize.c 1.2 87/08/11 Copyr 1987 Sun Micro"; 3392990Sobrienstatic char *sccsid = "@(#)rpc_dtablesize.c 2.1 88/07/29 4.0 RPCSRC"; 341901Swollman#endif 3592990Sobrien#include <sys/cdefs.h> 3692990Sobrien__FBSDID("$FreeBSD$"); 371901Swollman 3874462Salfred#include "namespace.h" 3916283Sjraynard#include <unistd.h> 4074462Salfred#include "un-namespace.h" 417616Swpaul 4292905Sobrienint _rpc_dtablesize(void); /* XXX */ 4374462Salfred 441901Swollman/* 451901Swollman * Cache the result of getdtablesize(), so we don't have to do an 461901Swollman * expensive system call every time. 471901Swollman */ 4821103Speter/* 4921103Speter * XXX In FreeBSD 2.x, you can have the maximum number of open file 5021103Speter * descriptors be greater than FD_SETSIZE (which us 256 by default). 5121103Speter * 5221103Speter * Since old programs tend to use this call to determine the first arg 5371579Sdeischen * for _select(), having this return > FD_SETSIZE is a Bad Idea(TM)! 5421103Speter */ 5521085Speterint 5621103Speter_rpc_dtablesize(void) 571901Swollman{ 581901Swollman static int size; 598870Srgrimes 6021103Speter if (size == 0) { 611901Swollman size = getdtablesize(); 6221103Speter if (size > FD_SETSIZE) 6321103Speter size = FD_SETSIZE; 6421103Speter } 651901Swollman return (size); 661901Swollman} 67