>From 5dae49b4fc7fd82583d6be033907f693e9832f83 Mon Sep 17 00:00:00 2001 From: Aron Barath Date: Wed, 8 Aug 2018 09:39:42 +0200 Subject: [PATCH] fdleak.c: avoid compiler error on platforms lacking getrlimit * lib/fdleak.c (get_max_fd): Move definition of the fd_limit variable into the HAVE_GETRLIMIT block giving it a better scope: platforms lacking getrlimit probably also lack struct rlimit, too. Copyright-paperwork-exempt: Yes --- lib/fdleak.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/fdleak.c b/lib/fdleak.c index 38ff8360..818c0fbe 100644 --- a/lib/fdleak.c +++ b/lib/fdleak.c @@ -109,7 +109,6 @@ get_proc_max_fd (void) static int get_max_fd (void) { - struct rlimit fd_limit; long open_max; open_max = get_proc_max_fd (); @@ -122,13 +121,16 @@ get_max_fd (void) /* We assume if RLIMIT_NOFILE is defined, all the related macros are, too. */ #if defined HAVE_GETRLIMIT && defined RLIMIT_NOFILE - if (0 == getrlimit (RLIMIT_NOFILE, &fd_limit)) - { - if (fd_limit.rlim_cur == RLIM_INFINITY) - return open_max; - else - return (int) fd_limit.rlim_cur; - } + { + struct rlimit fd_limit; + if (0 == getrlimit (RLIMIT_NOFILE, &fd_limit)) + { + if (fd_limit.rlim_cur == RLIM_INFINITY) + return open_max; + else + return (int) fd_limit.rlim_cur; + } + } #endif /* cannot determine the limit's value */ return open_max; -- 2.18.0