[syslinux:master] libutil: copy suffix_number() from com32/lib/syslinux/load_linux.c
syslinux-bot for Gene Cumm
gene.cumm at gmail.com
Wed Mar 2 15:12:46 PST 2011
Commit-ID: d3c03fe651a932f058aca7596311ada76b80ba81
Gitweb: http://syslinux.zytor.com/commit/d3c03fe651a932f058aca7596311ada76b80ba81
Author: Gene Cumm <gene.cumm at gmail.com>
AuthorDate: Mon, 7 Feb 2011 20:13:48 -0500
Committer: Gene Cumm <gene.cumm at gmail.com>
CommitDate: Mon, 7 Feb 2011 20:13:48 -0500
libutil: copy suffix_number() from com32/lib/syslinux/load_linux.c
---
com32/libutil/Makefile | 3 +-
.../reboot.h => libutil/include/suffix_number.h} | 14 +++---
.../syslinux/memscan.h => libutil/suffix_number.c} | 48 +++++++++++++++++---
3 files changed, 50 insertions(+), 15 deletions(-)
diff --git a/com32/libutil/Makefile b/com32/libutil/Makefile
index 02789ca..d9466aa 100644
--- a/com32/libutil/Makefile
+++ b/com32/libutil/Makefile
@@ -33,7 +33,8 @@ topdir = ../..
include ../MCONFIG
LIBOBJS = ansiline.o ansiraw.o get_key.o sha1hash.o unbase64.o \
- md5.o crypt-md5.o sha256crypt.o sha512crypt.o base64.o
+ md5.o crypt-md5.o sha256crypt.o sha512crypt.o base64.o \
+ suffix_number.o
LNXLIBOBJS = $(patsubst %.o,%.lo,$(LIBOBJS))
all: libutil_com.a libutil_lnx.a
diff --git a/com32/include/syslinux/reboot.h b/com32/libutil/include/suffix_number.h
similarity index 83%
copy from com32/include/syslinux/reboot.h
copy to com32/libutil/include/suffix_number.h
index e589982..e2349b4 100644
--- a/com32/include/syslinux/reboot.h
+++ b/com32/libutil/include/suffix_number.h
@@ -26,16 +26,16 @@
* ----------------------------------------------------------------------- */
/*
- * syslinux/reboot.h
+ * suffix_number.h
*
- * Reboot the system
+ * Definitions used to convert a string of a number with potential SI suffix
+ * to int-type.
*/
-#ifndef _SYSLINUX_REBOOT_H
-#define _SYSLINUX_REBOOT_H
+#ifndef LIBUTIL_SUFFIX_NUMBER_H
+#define LIBUTIL_SUFFIX_NUMBER_H
-#include <klibc/compiler.h>
+unsigned long long suffix_number(const char *);
-__noreturn syslinux_reboot(int warm);
+#endif /* LIBUTIL_SUFFIX_NUMBER_H */
-#endif /* _SYSLINUX_REBOOT_H */
diff --git a/com32/include/syslinux/memscan.h b/com32/libutil/suffix_number.c
similarity index 68%
copy from com32/include/syslinux/memscan.h
copy to com32/libutil/suffix_number.c
index db79543..df073a0 100644
--- a/com32/include/syslinux/memscan.h
+++ b/com32/libutil/suffix_number.c
@@ -26,13 +26,47 @@
*
* ----------------------------------------------------------------------- */
-#ifndef _SYSLINUX_MEMSCAN_H
-#define _SYSLINUX_MEMSCAN_H
+/*
+ * suffix_number.c
+ *
+ * Convert a string of a number with potential SI suffix to int-type
+ */
+
+#include <stdlib.h>
+#include <suffix_number.h>
-#include <stdbool.h>
-#include <syslinux/movebits.h> /* addr_t */
+/* Get a value with a potential suffix (k/m/g/t/p/e) */
+unsigned long long suffix_number(const char *str)
+{
+ char *ep;
+ unsigned long long v;
+ int shift;
-typedef int (*scan_memory_callback_t) (void *, addr_t, addr_t, bool);
-int syslinux_scan_memory(scan_memory_callback_t callback, void *data);
+ v = strtoull(str, &ep, 0);
+ switch (*ep | 0x20) {
+ case 'k':
+ shift = 10;
+ break;
+ case 'm':
+ shift = 20;
+ break;
+ case 'g':
+ shift = 30;
+ break;
+ case 't':
+ shift = 40;
+ break;
+ case 'p':
+ shift = 50;
+ break;
+ case 'e':
+ shift = 60;
+ break;
+ default:
+ shift = 0;
+ break;
+ }
+ v <<= shift;
-#endif /* _SYSLINUX_MEMSCAN_H */
+ return v;
+}
More information about the Syslinux-commits
mailing list