aboutsummaryrefslogtreecommitdiff
path: root/win32/mingw.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2021-02-18 15:27:44 +0000
committerRon Yorston <rmy@pobox.com>2021-02-18 15:47:47 +0000
commit2b8770720868c750ad8609df4041337eb2c6cf71 (patch)
tree85aff1e2b748d0e75ee5dbe82bc574bb2a5a9c1b /win32/mingw.c
parent2d20b9d88c4fc91637babaafa4a60dd7943e03a7 (diff)
downloadbusybox-w32-2b8770720868c750ad8609df4041337eb2c6cf71.tar.gz
busybox-w32-2b8770720868c750ad8609df4041337eb2c6cf71.tar.bz2
busybox-w32-2b8770720868c750ad8609df4041337eb2c6cf71.zip
free: implement sysinfo(2) and enable free(1)
This is an experimental implementation of sysinfo(2)/free(1). It uses the WIN32 API GlobalMemoryStatusEx() to obtain information about memory. It seems that the 'total pagefile' value includes total RAM as well as pagefile and 'available pagefile' includes available RAM. So the RAM values are deducted. I've no idea what corresponds to Linux buffers and cache.
Diffstat (limited to '')
-rw-r--r--win32/mingw.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/win32/mingw.c b/win32/mingw.c
index 75635fdf1..48d2eefa7 100644
--- a/win32/mingw.c
+++ b/win32/mingw.c
@@ -1368,6 +1368,30 @@ int mingw_unlink(const char *pathname)
1368 return ret; 1368 return ret;
1369} 1369}
1370 1370
1371int sysinfo(struct sysinfo *info)
1372{
1373 DECLARE_PROC_ADDR(BOOL, GlobalMemoryStatusEx, LPMEMORYSTATUSEX);
1374 MEMORYSTATUSEX mem;
1375
1376 memset((void *)info, 0, sizeof(struct sysinfo));
1377
1378 if (!INIT_PROC_ADDR(kernel32.dll, GlobalMemoryStatusEx)) {
1379 return -1;
1380 }
1381
1382 mem.dwLength = sizeof(MEMORYSTATUSEX);
1383 if (!GlobalMemoryStatusEx(&mem))
1384 return -1;
1385
1386 info->mem_unit = 1;
1387 info->totalram = mem.ullTotalPhys;
1388 info->freeram = mem.ullAvailPhys;
1389 info->totalswap = mem.ullTotalPageFile - mem.ullTotalPhys;
1390 info->freeswap = mem.ullAvailPageFile - mem.ullAvailPhys;
1391
1392 return 0;
1393}
1394
1371#undef strftime 1395#undef strftime
1372size_t mingw_strftime(char *buf, size_t max, const char *format, const struct tm *tm) 1396size_t mingw_strftime(char *buf, size_t max, const char *format, const struct tm *tm)
1373{ 1397{