From 25263fd9e7a8a913395cb93d7c104cd48c2b4a00 Mon Sep 17 00:00:00 2001 From: Lasse Collin Date: Sun, 29 Mar 2015 22:13:48 +0300 Subject: [PATCH] Fix the detection of installed RAM on QNX. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The earlier version compiled but didn't actually work since sysconf(_SC_PHYS_PAGES) always fails (or so I was told). Thanks to Ole André Vadla Ravnås for the patch and testing. --- m4/tuklib_physmem.m4 | 6 +++--- src/common/tuklib_physmem.c | 14 +++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/m4/tuklib_physmem.m4 b/m4/tuklib_physmem.m4 index ea02208f..8a57ca29 100644 --- a/m4/tuklib_physmem.m4 +++ b/m4/tuklib_physmem.m4 @@ -10,8 +10,8 @@ # # Supported methods: # -# - Windows (including Cygwin), OS/2, DJGPP (DOS), and OpenVMS have -# operating-system specific functions. +# - Windows (including Cygwin), OS/2, DJGPP (DOS), OpenVMS, AROS, +# and QNX have operating-system specific functions. # # - AIX has _system_configuration.physmem. # @@ -54,7 +54,7 @@ AC_CACHE_CHECK([how to detect the amount of physical memory], AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ #if defined(_WIN32) || defined(__CYGWIN__) || defined(__OS2__) \ || defined(__DJGPP__) || defined(__VMS) \ - || defined(AMIGA) || defined(__AROS__) + || defined(AMIGA) || defined(__AROS__) || defined(__QNX__) int main(void) { return 0; } #else compile error diff --git a/src/common/tuklib_physmem.c b/src/common/tuklib_physmem.c index 3cc7d12a..cd2437d8 100644 --- a/src/common/tuklib_physmem.c +++ b/src/common/tuklib_physmem.c @@ -37,7 +37,10 @@ # define __USE_INLINE__ # include -// AIX +#elif defined(__QNX__) +# include +# include + #elif defined(TUKLIB_PHYSMEM_AIX) # include @@ -126,6 +129,15 @@ tuklib_physmem(void) #elif defined(AMIGA) || defined(__AROS__) ret = AvailMem(MEMF_TOTAL); +#elif defined(__QNX__) + const struct asinfo_entry *entries = SYSPAGE_ENTRY(asinfo); + size_t count = SYSPAGE_ENTRY_SIZE(asinfo) / sizeof(struct asinfo_entry); + const char *strings = SYSPAGE_ENTRY(strings)->data; + + for (size_t i = 0; i < count; ++i) + if (strcmp(strings + entries[i].name, "ram") == 0) + ret += entries[i].end - entries[i].start + 1; + #elif defined(TUKLIB_PHYSMEM_AIX) ret = _system_configuration.physmem;