a function to read size from string with K,M,G.
authorGengbin Zheng <gzheng@illinois.edu>
Sat, 4 Feb 2012 19:32:06 +0000 (13:32 -0600)
committerGengbin Zheng <gzheng@illinois.edu>
Sat, 4 Feb 2012 19:32:06 +0000 (13:32 -0600)
src/conv-core/convcore.c
src/conv-core/converse.h

index d72a0107bf5aa0c45707c741d824dbb2d3cc1b4b..17a5ff76979f329a8f0d80cbc933dca76595bfaf 100644 (file)
@@ -3762,4 +3762,25 @@ int CmiMyRank_()
   return CmiMyRank();
 }
 
+int CmiReadSize(char *str)
+{
+    int val;
+    if (strpbrk(str,"G")) {
+        sscanf(str, "%lldG", &val);
+        val *= 1024ll*1024*1024;
+    }
+    else if (strpbrk(str,"M")) {
+        sscanf(str, "%lldM", &val);
+        val *= 1024*1024;
+    }
+    else if (strpbrk(str,"K")) {
+        sscanf(str, "%lldK", &val);
+        val *= 1024;
+    }
+    else {
+        sscanf(str, "%lld", &val);
+    }
+    return val;
+}
+
 /*@}*/
index c03ebf6a06cbacf254bb47d491a6798c7ad7cfed..b7b8ee875dc223387d322d58b8a9b4449f913979 100644 (file)
@@ -1925,4 +1925,6 @@ EXTERN void CmiResetNotifyCommThdMsg(CmiNotifyCommThdMsg *msg, CmiCommThdFnPtr f
 EXTERN void CmiNotifyCommThd(CmiNotifyCommThdMsg *msg);
 #endif
 
+int CmiReadSize(char *str);
+
 #endif /* CONVERSE_H */