Commit 0da6b0d2 authored by Philippe Gerum's avatar Philippe Gerum

boilerplate/ancillaries: add routine to parse mem size

parent 65f16f4a
......@@ -111,7 +111,9 @@ int get_static_cpu_count(void);
pid_t get_thread_pid(void);
char *lookup_command(const char *cmd);
size_t get_mem_size(const char *arg);
#ifdef __cplusplus
}
#endif
......
......@@ -23,8 +23,10 @@
#include <stdarg.h>
#include <pthread.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
#include <malloc.h>
#include "boilerplate/atomic.h"
#include "boilerplate/lock.h"
......@@ -319,6 +321,35 @@ char *lookup_command(const char *cmd)
return NULL;
}
size_t get_mem_size(const char *arg)
{
size_t size;
char *p;
size = strtol(arg, &p, 0);
if (size == LONG_MIN || size == LONG_MAX)
return 0;
if (*p == '\0')
return size;
switch (tolower(*p)) {
case 'k':
size *= 1024;
break;
case 'm':
size *= (1024 * 1024);
break;
case 'g':
size *= (1024 * 1024 * 1024);
break;
default:
size = 0;
}
return size;
}
const char *config_strings[] = {
#include "config-dump.h"
NULL,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment