Add proper per-file copyright notices/licenses and top-level license.
[bluesky.git] / TBBT / trace_play / rpc / rpc_dtablesize.c
1 #ifndef lint
2 static char sfs_clnt_id[] = "@(#)rpc_dtablesize.c     2.1     97/10/23";
3 #endif
4 /* @(#)rpc_dtablesize.c 2.1 88/07/29 4.0 RPCSRC */
5 /*
6  *   Copyright (c) 1992-1997,2001 by Standard Performance Evaluation Corporation
7  *      All rights reserved.
8  *              Standard Performance Evaluation Corporation (SPEC)
9  *              6585 Merchant Place, Suite 100
10  *              Warrenton, VA 20187
11  *
12  *      This product contains benchmarks acquired from several sources who
13  *      understand and agree with SPEC's goal of creating fair and objective
14  *      benchmarks to measure computer performance.
15  *
16  *      This copyright notice is placed here only to protect SPEC in the
17  *      event the source is misused in any manner that is contrary to the
18  *      spirit, the goals and the intent of SPEC.
19  *
20  *      The source code is provided to the user or company under the license
21  *      agreement for the SPEC Benchmark Suite for this product.
22  */
23 /*
24  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
25  * unrestricted use provided that this legend is included on all tape
26  * media and as a part of the software program in whole or part.  Users
27  * may copy or modify Sun RPC without charge, but are not authorized
28  * to license or distribute it to anyone else except as part of a product or
29  * program developed by the user.
30  * 
31  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
32  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
33  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
34  * 
35  * Sun RPC is provided with no support and without any obligation on the
36  * part of Sun Microsystems, Inc. to assist in its use, correction,
37  * modification or enhancement.
38  * 
39  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
40  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
41  * OR ANY PART THEREOF.
42  * 
43  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
44  * or profits or other special, indirect and consequential damages, even if
45  * Sun has been advised of the possibility of such damages.
46  * 
47  * Sun Microsystems, Inc.
48  * 2550 Garcia Avenue
49  * Mountain View, California  94043
50  */
51 #if !defined(lint) && defined(SCCSIDS)
52 static char sccsid[] = "@(#)rpc_dtablesize.c 1.2 87/08/11 Copyr 1987 Sun Micro";
53 #endif
54
55
56 /*
57  * Cache the result of getdtablesize(), so we don't have to do an
58  * expensive system call every time.
59  */
60
61 #if !(defined(USE_GETDTABLESIZE) || defined(USE_GETRLIMIT) || defined(USE_NOFILE))
62 #define USE_GETDTABLESIZE
63 #endif
64
65 #ifdef USE_GETDTABLESIZE
66 #include <unistd.h>
67
68 int
69 _rpc_dtablesize(void)
70 {
71         static int size = 0;
72         
73         if (size == 0) {
74                 size = getdtablesize();
75 #ifdef FD_SETSIZE
76                 /*
77                  * FreeBSD select() produces a segmentation violation if
78                  * the argument is larger than FD_SETSIZE.
79                  */
80                 if (size > FD_SETSIZE) {
81                         size = FD_SETSIZE;
82                 }
83 #endif /* def FD_SETSIZE */
84         }
85         return (size);
86 }
87 #endif
88
89 #ifdef USE_GETRLIMIT
90 #include <sys/resource.h>
91
92 int
93 _rpc_dtablesize(void)
94 {
95         static int size = 0;
96         struct rlimit rlimit;
97
98         if (size == 0) {
99                 (void)getrlimit(RLIMIT_NOFILE, &rlimit);
100                 size = (int) rlimit.rlim_cur;
101         }
102         return (size);
103 }
104 #endif
105
106 #ifdef USE_NOFILE
107 #include <sys/param.h>
108
109 int
110 _rpc_dtablesize(void)
111 {
112         return (NOFILE);
113 }
114 #endif