Mercurial > hg > octave-jordi > gnulib-hg
annotate lib/physmem.c @ 18029:e4a13d95b503
mgetgroups: port to strict OS X
* doc/glibc-functions/getgrouplist.texi (getgrouplist):
Document the getgrouplist problem.
* lib/mgetgroups.c (getgrouplist_gids) [HAVE_GETGROUPLIST]:
New macro.
(mgetgroups): Use it.
* m4/mgetgroups.m4 (gl_MGETGROUPS):
Check for OS X signature for getgrouplist.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Sun, 28 Jun 2015 23:43:35 -0700 |
parents | ab58d4870664 |
children |
rev | line source |
---|---|
3064 | 1 /* Calculate the size of physical memory. |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
2 |
17848 | 3 Copyright (C) 2000-2001, 2003, 2005-2006, 2009-2015 Free Software |
12559
c2cbabec01dd
update nearly all FSF copyright year lists to include 2010
Jim Meyering <meyering@redhat.com>
parents:
12518
diff
changeset
|
4 Foundation, Inc. |
3064 | 5 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7302
diff
changeset
|
6 This program is free software: you can redistribute it and/or modify |
3064 | 7 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7302
diff
changeset
|
8 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7302
diff
changeset
|
9 (at your option) any later version. |
3064 | 10 |
11 This program is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7302
diff
changeset
|
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
3064 | 18 |
19 /* Written by Paul Eggert. */ | |
20 | |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
21 #include <config.h> |
3064 | 22 |
23 #include "physmem.h" | |
24 | |
6275 | 25 #include <unistd.h> |
3064 | 26 |
3607
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
27 #if HAVE_SYS_PSTAT_H |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
28 # include <sys/pstat.h> |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
29 #endif |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
30 |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
31 #if HAVE_SYS_SYSMP_H |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
32 # include <sys/sysmp.h> |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
33 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
34 |
17659
10089b66b66e
physmem: use sysinfo if _SC_PHYS_PAGES unavailable
Natanael Copa <ncopa@alpinelinux.org>
parents:
17587
diff
changeset
|
35 #if HAVE_SYS_SYSINFO_H |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
36 # include <sys/sysinfo.h> |
17659
10089b66b66e
physmem: use sysinfo if _SC_PHYS_PAGES unavailable
Natanael Copa <ncopa@alpinelinux.org>
parents:
17587
diff
changeset
|
37 #endif |
10089b66b66e
physmem: use sysinfo if _SC_PHYS_PAGES unavailable
Natanael Copa <ncopa@alpinelinux.org>
parents:
17587
diff
changeset
|
38 |
10089b66b66e
physmem: use sysinfo if _SC_PHYS_PAGES unavailable
Natanael Copa <ncopa@alpinelinux.org>
parents:
17587
diff
changeset
|
39 #if HAVE_MACHINE_HAL_SYSINFO_H |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
40 # include <machine/hal_sysinfo.h> |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
41 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
42 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
43 #if HAVE_SYS_TABLE_H |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
44 # include <sys/table.h> |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
45 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
46 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
47 #include <sys/types.h> |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
48 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
49 #if HAVE_SYS_PARAM_H |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
50 # include <sys/param.h> |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
51 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
52 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
53 #if HAVE_SYS_SYSCTL_H |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
54 # include <sys/sysctl.h> |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
55 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
56 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
57 #if HAVE_SYS_SYSTEMCFG_H |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
58 # include <sys/systemcfg.h> |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
59 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
60 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
61 #ifdef _WIN32 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
62 # define WIN32_LEAN_AND_MEAN |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
63 # include <windows.h> |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
64 /* MEMORYSTATUSEX is missing from older windows headers, so define |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
65 a local replacement. */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
66 typedef struct |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
67 { |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
68 DWORD dwLength; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
69 DWORD dwMemoryLoad; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
70 DWORDLONG ullTotalPhys; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
71 DWORDLONG ullAvailPhys; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
72 DWORDLONG ullTotalPageFile; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
73 DWORDLONG ullAvailPageFile; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
74 DWORDLONG ullTotalVirtual; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
75 DWORDLONG ullAvailVirtual; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
76 DWORDLONG ullAvailExtendedVirtual; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
77 } lMEMORYSTATUSEX; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
78 typedef WINBOOL (WINAPI *PFN_MS_EX) (lMEMORYSTATUSEX*); |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
79 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
80 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
81 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
82 |
3064 | 83 /* Return the total amount of physical memory. */ |
84 double | |
4669
c7ad68a45173
(physmem_total, physmem_available, main): Define with prototypes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4551
diff
changeset
|
85 physmem_total (void) |
3064 | 86 { |
87 #if defined _SC_PHYS_PAGES && defined _SC_PAGESIZE | |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
88 { /* This works on linux-gnu, solaris2 and cygwin. */ |
3607
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
89 double pages = sysconf (_SC_PHYS_PAGES); |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
90 double pagesize = sysconf (_SC_PAGESIZE); |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
91 if (0 <= pages && 0 <= pagesize) |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
92 return pages * pagesize; |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
93 } |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
94 #endif |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
95 |
17659
10089b66b66e
physmem: use sysinfo if _SC_PHYS_PAGES unavailable
Natanael Copa <ncopa@alpinelinux.org>
parents:
17587
diff
changeset
|
96 #if HAVE_SYSINFO && HAVE_STRUCT_SYSINFO_MEM_UNIT |
10089b66b66e
physmem: use sysinfo if _SC_PHYS_PAGES unavailable
Natanael Copa <ncopa@alpinelinux.org>
parents:
17587
diff
changeset
|
97 { /* This works on linux. */ |
10089b66b66e
physmem: use sysinfo if _SC_PHYS_PAGES unavailable
Natanael Copa <ncopa@alpinelinux.org>
parents:
17587
diff
changeset
|
98 struct sysinfo si; |
10089b66b66e
physmem: use sysinfo if _SC_PHYS_PAGES unavailable
Natanael Copa <ncopa@alpinelinux.org>
parents:
17587
diff
changeset
|
99 if (sysinfo(&si) == 0) |
10089b66b66e
physmem: use sysinfo if _SC_PHYS_PAGES unavailable
Natanael Copa <ncopa@alpinelinux.org>
parents:
17587
diff
changeset
|
100 return (double) si.totalram * si.mem_unit; |
10089b66b66e
physmem: use sysinfo if _SC_PHYS_PAGES unavailable
Natanael Copa <ncopa@alpinelinux.org>
parents:
17587
diff
changeset
|
101 } |
10089b66b66e
physmem: use sysinfo if _SC_PHYS_PAGES unavailable
Natanael Copa <ncopa@alpinelinux.org>
parents:
17587
diff
changeset
|
102 #endif |
10089b66b66e
physmem: use sysinfo if _SC_PHYS_PAGES unavailable
Natanael Copa <ncopa@alpinelinux.org>
parents:
17587
diff
changeset
|
103 |
3607
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
104 #if HAVE_PSTAT_GETSTATIC |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
105 { /* This works on hpux11. */ |
3607
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
106 struct pst_static pss; |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
107 if (0 <= pstat_getstatic (&pss, sizeof pss, 1, 0)) |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
108 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
109 double pages = pss.physical_memory; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
110 double pagesize = pss.page_size; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
111 if (0 <= pages && 0 <= pagesize) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
112 return pages * pagesize; |
3607
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
113 } |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
114 } |
3064 | 115 #endif |
116 | |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
117 #if HAVE_SYSMP && defined MP_SAGET && defined MPSA_RMINFO && defined _SC_PAGESIZE |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
118 { /* This works on irix6. */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
119 struct rminfo realmem; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
120 if (sysmp (MP_SAGET, MPSA_RMINFO, &realmem, sizeof realmem) == 0) |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
121 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
122 double pagesize = sysconf (_SC_PAGESIZE); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
123 double pages = realmem.physmem; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
124 if (0 <= pages && 0 <= pagesize) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
125 return pages * pagesize; |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
126 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
127 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
128 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
129 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
130 #if HAVE_GETSYSINFO && defined GSI_PHYSMEM |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
131 { /* This works on Tru64 UNIX V4/5. */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
132 int physmem; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
133 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
134 if (getsysinfo (GSI_PHYSMEM, (caddr_t) &physmem, sizeof (physmem), |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
135 NULL, NULL, NULL) == 1) |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
136 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
137 double kbytes = physmem; |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
138 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
139 if (0 <= kbytes) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
140 return kbytes * 1024.0; |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
141 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
142 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
143 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
144 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
145 #if HAVE_SYSCTL && defined HW_PHYSMEM |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
146 { /* This works on *bsd and darwin. */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
147 unsigned int physmem; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
148 size_t len = sizeof physmem; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
149 static int mib[2] = { CTL_HW, HW_PHYSMEM }; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
150 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
151 if (sysctl (mib, ARRAY_SIZE (mib), &physmem, &len, NULL, 0) == 0 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
152 && len == sizeof (physmem)) |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
153 return (double) physmem; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
154 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
155 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
156 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
157 #if HAVE__SYSTEM_CONFIGURATION |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
158 /* This works on AIX. */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
159 return _system_configuration.physmem; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
160 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
161 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
162 #if defined _WIN32 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
163 { /* this works on windows */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
164 PFN_MS_EX pfnex; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
165 HMODULE h = GetModuleHandle ("kernel32.dll"); |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
166 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
167 if (!h) |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
168 return 0.0; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
169 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
170 /* Use GlobalMemoryStatusEx if available. */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
171 if ((pfnex = (PFN_MS_EX) GetProcAddress (h, "GlobalMemoryStatusEx"))) |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
172 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
173 lMEMORYSTATUSEX lms_ex; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
174 lms_ex.dwLength = sizeof lms_ex; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
175 if (!pfnex (&lms_ex)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
176 return 0.0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
177 return (double) lms_ex.ullTotalPhys; |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
178 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
179 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
180 /* Fall back to GlobalMemoryStatus which is always available. |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
181 but returns wrong results for physical memory > 4GB. */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
182 else |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
183 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
184 MEMORYSTATUS ms; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
185 GlobalMemoryStatus (&ms); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
186 return (double) ms.dwTotalPhys; |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
187 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
188 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
189 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
190 |
3064 | 191 /* Guess 64 MB. It's probably an older host, so guess small. */ |
192 return 64 * 1024 * 1024; | |
193 } | |
194 | |
195 /* Return the amount of physical memory available. */ | |
196 double | |
4669
c7ad68a45173
(physmem_total, physmem_available, main): Define with prototypes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4551
diff
changeset
|
197 physmem_available (void) |
3064 | 198 { |
199 #if defined _SC_AVPHYS_PAGES && defined _SC_PAGESIZE | |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
200 { /* This works on linux-gnu, solaris2 and cygwin. */ |
3607
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
201 double pages = sysconf (_SC_AVPHYS_PAGES); |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
202 double pagesize = sysconf (_SC_PAGESIZE); |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
203 if (0 <= pages && 0 <= pagesize) |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
204 return pages * pagesize; |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
205 } |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
206 #endif |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
207 |
17659
10089b66b66e
physmem: use sysinfo if _SC_PHYS_PAGES unavailable
Natanael Copa <ncopa@alpinelinux.org>
parents:
17587
diff
changeset
|
208 #if HAVE_SYSINFO && HAVE_STRUCT_SYSINFO_MEM_UNIT |
10089b66b66e
physmem: use sysinfo if _SC_PHYS_PAGES unavailable
Natanael Copa <ncopa@alpinelinux.org>
parents:
17587
diff
changeset
|
209 { /* This works on linux. */ |
10089b66b66e
physmem: use sysinfo if _SC_PHYS_PAGES unavailable
Natanael Copa <ncopa@alpinelinux.org>
parents:
17587
diff
changeset
|
210 struct sysinfo si; |
10089b66b66e
physmem: use sysinfo if _SC_PHYS_PAGES unavailable
Natanael Copa <ncopa@alpinelinux.org>
parents:
17587
diff
changeset
|
211 if (sysinfo(&si) == 0) |
10089b66b66e
physmem: use sysinfo if _SC_PHYS_PAGES unavailable
Natanael Copa <ncopa@alpinelinux.org>
parents:
17587
diff
changeset
|
212 return ((double) si.freeram + si.bufferram) * si.mem_unit; |
10089b66b66e
physmem: use sysinfo if _SC_PHYS_PAGES unavailable
Natanael Copa <ncopa@alpinelinux.org>
parents:
17587
diff
changeset
|
213 } |
10089b66b66e
physmem: use sysinfo if _SC_PHYS_PAGES unavailable
Natanael Copa <ncopa@alpinelinux.org>
parents:
17587
diff
changeset
|
214 #endif |
10089b66b66e
physmem: use sysinfo if _SC_PHYS_PAGES unavailable
Natanael Copa <ncopa@alpinelinux.org>
parents:
17587
diff
changeset
|
215 |
3607
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
216 #if HAVE_PSTAT_GETSTATIC && HAVE_PSTAT_GETDYNAMIC |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
217 { /* This works on hpux11. */ |
3607
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
218 struct pst_static pss; |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
219 struct pst_dynamic psd; |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
220 if (0 <= pstat_getstatic (&pss, sizeof pss, 1, 0) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
221 && 0 <= pstat_getdynamic (&psd, sizeof psd, 1, 0)) |
3607
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
222 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
223 double pages = psd.psd_free; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
224 double pagesize = pss.page_size; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
225 if (0 <= pages && 0 <= pagesize) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
226 return pages * pagesize; |
3607
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
227 } |
0eb39272f531
[HAVE_SYS_PSTAT_H]: Include <sys/pstat.h>.
Jim Meyering <jim@meyering.net>
parents:
3064
diff
changeset
|
228 } |
3064 | 229 #endif |
230 | |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
231 #if HAVE_SYSMP && defined MP_SAGET && defined MPSA_RMINFO && defined _SC_PAGESIZE |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
232 { /* This works on irix6. */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
233 struct rminfo realmem; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
234 if (sysmp (MP_SAGET, MPSA_RMINFO, &realmem, sizeof realmem) == 0) |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
235 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
236 double pagesize = sysconf (_SC_PAGESIZE); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
237 double pages = realmem.availrmem; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
238 if (0 <= pages && 0 <= pagesize) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
239 return pages * pagesize; |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
240 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
241 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
242 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
243 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
244 #if HAVE_TABLE && defined TBL_VMSTATS |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
245 { /* This works on Tru64 UNIX V4/5. */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
246 struct tbl_vmstats vmstats; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
247 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
248 if (table (TBL_VMSTATS, 0, &vmstats, 1, sizeof (vmstats)) == 1) |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
249 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
250 double pages = vmstats.free_count; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
251 double pagesize = vmstats.pagesize; |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
252 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
253 if (0 <= pages && 0 <= pagesize) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
254 return pages * pagesize; |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
255 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
256 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
257 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
258 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
259 #if HAVE_SYSCTL && defined HW_USERMEM |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
260 { /* This works on *bsd and darwin. */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
261 unsigned int usermem; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
262 size_t len = sizeof usermem; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
263 static int mib[2] = { CTL_HW, HW_USERMEM }; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
264 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
265 if (sysctl (mib, ARRAY_SIZE (mib), &usermem, &len, NULL, 0) == 0 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
266 && len == sizeof (usermem)) |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
267 return (double) usermem; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
268 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
269 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
270 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
271 #if defined _WIN32 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
272 { /* this works on windows */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
273 PFN_MS_EX pfnex; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
274 HMODULE h = GetModuleHandle ("kernel32.dll"); |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
275 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
276 if (!h) |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
277 return 0.0; |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
278 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
279 /* Use GlobalMemoryStatusEx if available. */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
280 if ((pfnex = (PFN_MS_EX) GetProcAddress (h, "GlobalMemoryStatusEx"))) |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
281 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
282 lMEMORYSTATUSEX lms_ex; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
283 lms_ex.dwLength = sizeof lms_ex; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
284 if (!pfnex (&lms_ex)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
285 return 0.0; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
286 return (double) lms_ex.ullAvailPhys; |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
287 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
288 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
289 /* Fall back to GlobalMemoryStatus which is always available. |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
290 but returns wrong results for physical memory > 4GB */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
291 else |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
292 { |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
293 MEMORYSTATUS ms; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
294 GlobalMemoryStatus (&ms); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9309
diff
changeset
|
295 return (double) ms.dwAvailPhys; |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
296 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
297 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
298 #endif |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
299 |
3064 | 300 /* Guess 25% of physical memory. */ |
301 return physmem_total () / 4; | |
302 } | |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
303 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
304 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
305 #if DEBUG |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
306 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
307 # include <stdio.h> |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
308 # include <stdlib.h> |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
309 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
310 int |
4669
c7ad68a45173
(physmem_total, physmem_available, main): Define with prototypes.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4551
diff
changeset
|
311 main (void) |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
312 { |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
313 printf ("%12.f %12.f\n", physmem_total (), physmem_available ()); |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
314 exit (0); |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
315 } |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
316 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
317 #endif /* DEBUG */ |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
318 |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
319 /* |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
320 Local Variables: |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6275
diff
changeset
|
321 compile-command: "gcc -DDEBUG -g -O -Wall -W physmem.c" |
4551
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
322 End: |
e98bdaad6174
Merge in portability changes from gcc/libiberty
Paul Eggert <eggert@cs.ucla.edu>
parents:
3607
diff
changeset
|
323 */ |