*** empty log message ***
[coreutils.git] / lib / physmem.c
blobd0e252f1ecf9556663233a007ba1b68243600434
1 /* Calculate the size of physical memory.
2 Copyright 2000 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
18 /* Written by Paul Eggert. */
20 #if HAVE_CONFIG_H
21 # include <config.h>
22 #endif
24 #include "physmem.h"
26 #if HAVE_UNISTD_H
27 # include <unistd.h>
28 #endif
30 /* Return the total amount of physical memory. */
31 double
32 physmem_total (void)
34 #if defined _SC_PHYS_PAGES && defined _SC_PAGESIZE
35 double pages = sysconf (_SC_PHYS_PAGES);
36 double pagesize = sysconf (_SC_PAGESIZE);
37 if (0 <= pages && 0 <= pagesize)
38 return pages * pagesize;
39 #endif
41 /* Guess 64 MB. It's probably an older host, so guess small. */
42 return 64 * 1024 * 1024;
45 /* Return the amount of physical memory available. */
46 double
47 physmem_available (void)
49 #if defined _SC_AVPHYS_PAGES && defined _SC_PAGESIZE
50 double pages = sysconf (_SC_AVPHYS_PAGES);
51 double pagesize = sysconf (_SC_PAGESIZE);
52 if (0 <= pages && 0 <= pagesize)
53 return pages * pagesize;
54 #endif
56 /* Guess 25% of physical memory. */
57 return physmem_total () / 4;