]>
Commit | Line | Data |
---|---|---|
6df73332 JB |
1 | # Make a reasonable guess about memory limits using sysconf(). |
2 | # includes 5% slop factor as suggested in documentation. | |
3 | ||
4 | --- jpeg-6b/jmemansi.c | |
5 | +++ jpeg-6b/jmemansi.c | |
6 | @@ -12,6 +12,15 @@ | |
7 | * is shoved onto the user. | |
8 | */ | |
9 | ||
10 | +#include <unistd.h> | |
11 | + | |
12 | +#ifdef __FreeBSD__ | |
13 | +# include <sys/types.h> | |
14 | +# include <sys/sysctl.h> | |
15 | +# include <sys/vmmeter.h> | |
16 | +# include <vm/vm_param.h> | |
17 | +#endif | |
18 | + | |
19 | #define JPEG_INTERNALS | |
20 | #include "jinclude.h" | |
21 | #include "jpeglib.h" | |
22 | @@ -157,7 +166,26 @@ | |
23 | GLOBAL(long) | |
24 | jpeg_mem_init (j_common_ptr cinfo) | |
25 | { | |
26 | - return DEFAULT_MAX_MEM; /* default for max_memory_to_use */ | |
27 | +#ifdef _SC_AVPHYS_PAGES | |
28 | + long phys_size; | |
29 | + | |
30 | + if ((phys_size = sysconf(_SC_AVPHYS_PAGES)) == -1) | |
31 | + return DEFAULT_MAX_MEM; /* default for max_memory_to_use */ | |
32 | + if ((phys_size *= sysconf(_SC_PAGESIZE)) < 0) | |
33 | + return DEFAULT_MAX_MEM; | |
34 | + return (long) (phys_size * 0.95); | |
35 | +#elif defined(HAVE_SYSCTL) && defined(HW_PHYSMEM) | |
36 | + /* This works on *bsd and darwin. */ | |
37 | + unsigned int physmem; | |
38 | + size_t len = sizeof physmem; | |
39 | + static int mib[2] = { CTL_HW, HW_PHYSMEM }; | |
40 | + | |
41 | + if (sysctl (mib, ARRAY_SIZE (mib), &physmem, &len, NULL, 0) == 0 | |
42 | + && len == sizeof (physmem)) | |
43 | + return (long) (physmem * 0.95); | |
44 | +#endif | |
45 | + | |
46 | + return DEFAULT_MAX_MEM; | |
47 | } | |
48 | ||
49 | GLOBAL(void) |