(libretro-common) Start creating STRING_REP_ULONG

This commit is contained in:
twinaphex 2016-06-23 07:37:02 +02:00
parent f177d22007
commit dee7533d65
3 changed files with 18 additions and 20 deletions

View File

@ -1919,7 +1919,7 @@ static uint64_t frontend_linux_get_mem_total(void)
char line[256];
uint64_t total = 0;
while (fgets(line, sizeof(line), data)) {
if (sscanf(line, "MemTotal: %lu kB", &total) == 1) {
if (sscanf(line, "MemTotal: " STRING_REP_ULONG " kB", &total) == 1) {
fclose(data);
total *= 1024;
return total;
@ -1942,14 +1942,15 @@ static uint64_t frontend_linux_get_mem_used(void)
uint64_t cached = 0;
char line[256];
while (fgets(line, sizeof(line), data)) {
if (sscanf(line, "MemTotal: %lu kB", &total) == 1)
while (fgets(line, sizeof(line), data))
{
if (sscanf(line, "MemTotal: " STRING_REP_ULONG " kB", &total) == 1)
total *= 1024;
if (sscanf(line, "MemFree: %lu kB", &freemem) == 1)
if (sscanf(line, "MemFree: " STRING_REP_ULONG " kB", &freemem) == 1)
freemem *= 1024;
if (sscanf(line, "Buffers: %lu kB", &buffers) == 1)
if (sscanf(line, "Buffers: " STRING_REP_ULONG " kB", &buffers) == 1)
buffers *= 1024;
if (sscanf(line, "Cached: %lu kB", &cached) == 1)
if (sscanf(line, "Cached: " STRING_REP_ULONG " kB", &cached) == 1)
cached *= 1024;
}

View File

@ -75,6 +75,14 @@ typedef int ssize_t;
#include <sys/types.h>
#endif
#ifdef _WIN32
#define STRING_REP_ULONG "%Iu"
#elif defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L
#define STRING_REP_ULONG "%zu"
#else
#define STRING_REP_ULONG "%lu"
#endif
/*
I would like to see retro_inline.h moved in here; possibly boolean too.

View File

@ -85,28 +85,17 @@ static int task_database_iterate_start(database_info_handle_t *db,
{
char msg[128] = {0};
#ifdef _WIN32
snprintf(msg, sizeof(msg),
"%Iu/%Iu: %s %s...\n",
STRING_REP_ULONG "/" STRING_REP_ULONG ": %s %s...\n",
#if defined(_WIN32) || defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L
db->list_ptr,
db->list->size,
msg_hash_to_str(MSG_SCANNING),
name);
#elif defined(__STDC_VERSION__) && __STDC_VERSION__>=199901L
snprintf(msg, sizeof(msg),
"%zu/%zu: %s %s...\n",
db->list_ptr,
db->list->size,
msg_hash_to_str(MSG_SCANNING),
name);
#else
snprintf(msg, sizeof(msg),
"%lu/%lu: %s %s...\n",
(unsigned long)db->list_ptr,
(unsigned long)db->list->size,
#endif
msg_hash_to_str(MSG_SCANNING),
name);
#endif
if (!string_is_empty(msg))
runloop_msg_queue_push(msg, 1, 180, true);