At the end I have tried this simple test case, which is 'out context'
(so it could be not meaningful), but it seems to return wrong values:
-----------------------------------------------
$ cat test_printf.c
#include <stdio.h>
#include <sys/resource.h>
int main()
{
struct rlimit rlimit;
unsigned long five_percent;
unsigned long data_size;
getrlimit (RLIMIT_AS, &rlimit);
if (RLIM_INFINITY == rlimit.rlim_max)
return 1;
/* This is a nonsensical case, but it happens -- rms. */
if (rlimit.rlim_cur > rlimit.rlim_max)
return 2;
five_percent = rlimit.rlim_max / 20;
data_size = rlimit.rlim_cur;
printf("have getrlimit %lu, %lu %lu %lu\n",
data_size,five_percent,rlimit.rlim_cur,rlimit.rlim_max);
if (data_size > five_percent * 19)
printf("past 95 percent of memory limit\n");
return 0;
}
$ gcc -o test_printf test_printf.c
$ ./test_printf
have getrlimit 2147483648, 107374182 2147483648 2147483648
past 95 percent of memory limit
-----------------------------------------------