Module: xenomai-3
Branch: master
Commit: 0da6b0d20fcdd0f06b83333b3be0280a40b20bb7
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=0da6b0d20fcdd0f06b83333b3be0280a40b20bb7

Author: Philippe Gerum <r...@xenomai.org>
Date:   Thu Aug 13 17:07:37 2015 +0200

boilerplate/ancillaries: add routine to parse mem size

---

 include/boilerplate/ancillaries.h |    4 +++-
 lib/boilerplate/ancillaries.c     |   31 +++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/include/boilerplate/ancillaries.h 
b/include/boilerplate/ancillaries.h
index 1ba320b..6b87f0c 100644
--- a/include/boilerplate/ancillaries.h
+++ b/include/boilerplate/ancillaries.h
@@ -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
diff --git a/lib/boilerplate/ancillaries.c b/lib/boilerplate/ancillaries.c
index 6c8be35..848adc7 100644
--- a/lib/boilerplate/ancillaries.c
+++ b/lib/boilerplate/ancillaries.c
@@ -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,


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to