diff options
author | Mike Frysinger <vapier@gentoo.org> | 2009-01-09 00:12:48 +0100 |
---|---|---|
committer | Christoph Brill <egore911@egore911.de> | 2009-01-09 00:12:48 +0100 |
commit | 9bc605ad36fa2881ca5e352f6a6132ba191dcef1 (patch) | |
tree | 50f387735c57df3690ce4aeb77fbfaa824d89f24 | |
parent | e4efd52bc81c24d8c9d772576a65ac228b5890d3 (diff) |
[PATCH] 60_all_jpeg-maxmem-sysconf.patch
touchups to make this work nicely with BSD systems
http://bugs.gentoo.org/166057
Make a reasonable guess about memory limits using sysconf().
includes 5% slop factor as suggested in documentation.
-rw-r--r-- | jmemansi.c | 30 |
1 files changed, 29 insertions, 1 deletions
@@ -12,6 +12,15 @@ * is shoved onto the user. */ +#include <unistd.h> + +#ifdef __FreeBSD__ +# include <sys/types.h> +# include <sys/sysctl.h> +# include <sys/vmmeter.h> +# include <vm/vm_param.h> +#endif + #define JPEG_INTERNALS #include "jinclude.h" #include "jpeglib.h" @@ -157,7 +166,26 @@ jpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info, GLOBAL(long) jpeg_mem_init (j_common_ptr cinfo) { - return DEFAULT_MAX_MEM; /* default for max_memory_to_use */ +#ifdef _SC_AVPHYS_PAGES + long phys_size; + + if ((phys_size = sysconf(_SC_AVPHYS_PAGES)) == -1) + return DEFAULT_MAX_MEM; /* default for max_memory_to_use */ + if ((phys_size *= sysconf(_SC_PAGESIZE)) < 0) + return DEFAULT_MAX_MEM; + return (long) (phys_size * 0.95); +#elif defined(HAVE_SYSCTL) && defined(HW_PHYSMEM) + /* This works on *bsd and darwin. */ + unsigned int physmem; + size_t len = sizeof physmem; + static int mib[2] = { CTL_HW, HW_PHYSMEM }; + + if (sysctl (mib, ARRAY_SIZE (mib), &physmem, &len, NULL, 0) == 0 + && len == sizeof (physmem)) + return (long) (physmem * 0.95); +#endif + + return DEFAULT_MAX_MEM; } GLOBAL(void) |