2 Copyright (C) 2011 Tim Mayberry
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #ifdef PLATFORM_WINDOWS
24 #include <sys/resource.h>
27 #include "pbd/resource.h"
32 get_resource_limit (ResourceType resource, ResourceLimit& limit)
34 if (resource == OpenFiles)
36 #ifdef PLATFORM_WINDOWS
37 limit.current_limit = _getmaxstdio();
38 limit.max_limit = 2048;
42 if (getrlimit (RLIMIT_NOFILE, &rl) == 0) {
43 limit.current_limit = rl.rlim_cur;
44 limit.max_limit = rl.rlim_max;
54 set_resource_limit (ResourceType resource, const ResourceLimit& limit)
56 if (resource == OpenFiles)
58 #ifdef PLATFORM_WINDOWS
59 // no soft and hard limits on windows
60 rlimit_t new_max = _setmaxstdio(limit.current_limit);
62 if (new_max == limit.current_limit) return true;
65 rl.rlim_cur = limit.current_limit;
66 rl.rlim_max = limit.max_limit;
67 if (setrlimit (RLIMIT_NOFILE, &rl) == 0) {