4 * Copyright (C) 2004, 2007, 2008 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 2000, 2001 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: resource.c,v 1.10 2008/07/11 23:47:09 tbox Exp */
26 #include <isc/platform.h>
27 #include <isc/resource.h>
28 #include <isc/result.h>
31 #include "errno2result.h"
34 * Windows limits the maximum number of open files to 2048
37 #define WIN32_MAX_OPEN_FILES 2048
40 isc_resource_setlimit(isc_resource_t resource
, isc_resourcevalue_t value
) {
41 isc_resourcevalue_t rlim_value
;
44 if (resource
!= isc_resource_openfiles
)
45 return (ISC_R_NOTIMPLEMENTED
);
48 if (value
== ISC_RESOURCE_UNLIMITED
)
49 rlim_value
= WIN32_MAX_OPEN_FILES
;
51 rlim_value
= min(value
, WIN32_MAX_OPEN_FILES
);
53 wresult
= _setmaxstdio((int) rlim_value
);
56 return (ISC_R_SUCCESS
);
58 return (isc__errno2result(errno
));
62 isc_resource_getlimit(isc_resource_t resource
, isc_resourcevalue_t
*value
) {
64 if (resource
!= isc_resource_openfiles
)
65 return (ISC_R_NOTIMPLEMENTED
);
67 *value
= WIN32_MAX_OPEN_FILES
;
68 return (ISC_R_SUCCESS
);
72 isc_resource_getcurlimit(isc_resource_t resource
, isc_resourcevalue_t
*value
) {
73 return (isc_resource_getlimit(resource
, value
));