diff mbox series

[15/15] cleanup: move hexval() to utils.c

Message ID 20200705130220.26230-16-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show
Series tidy-up options / reorganize lib.c | expand

Commit Message

Luc Van Oostenryck July 5, 2020, 1:02 p.m. UTC
Now lib.c contains almost nothing else than library entrypoints.

Move a small utility, hexval(), to utils.c to complete this cleanup.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 lib.c   | 17 -----------------
 lib.h   |  2 --
 utils.c | 17 +++++++++++++++++
 utils.h |  4 ++++
 4 files changed, 21 insertions(+), 19 deletions(-)
diff mbox series

Patch

diff --git a/lib.c b/lib.c
index f512be2e1a43..57c89a16448e 100644
--- a/lib.c
+++ b/lib.c
@@ -50,23 +50,6 @@ 
 #include "bits.h"
 
 
-unsigned int hexval(unsigned int c)
-{
-	int retval = 256;
-	switch (c) {
-	case '0'...'9':
-		retval = c - '0';
-		break;
-	case 'a'...'f':
-		retval = c - 'a' + 10;
-		break;
-	case 'A'...'F':
-		retval = c - 'A' + 10;
-		break;
-	}
-	return retval;
-}
-
 static void do_warn(const char *type, struct position pos, const char * fmt, va_list args)
 {
 	static char buffer[512];
diff --git a/lib.h b/lib.h
index 81253a3e7ee5..46483f2bed5c 100644
--- a/lib.h
+++ b/lib.h
@@ -45,8 +45,6 @@ 
 #endif
 
 
-extern unsigned int hexval(unsigned int c);
-
 struct position {
 	unsigned int type:6,
 		     stream:14,
diff --git a/utils.c b/utils.c
index 094df3f9bf1c..72fff00ff91b 100644
--- a/utils.c
+++ b/utils.c
@@ -8,6 +8,23 @@ 
 #include <stdio.h>
 
 
+unsigned int hexval(unsigned int c)
+{
+	int retval = 256;
+	switch (c) {
+	case '0'...'9':
+		retval = c - '0';
+		break;
+	case 'a'...'f':
+		retval = c - 'a' + 10;
+		break;
+	case 'A'...'F':
+		retval = c - 'A' + 10;
+		break;
+	}
+	return retval;
+}
+
 void *xmemdup(const void *src, size_t len)
 {
 	return memcpy(__alloc_bytes(len), src, len);
diff --git a/utils.h b/utils.h
index 7bd14f467799..079fb02a3e94 100644
--- a/utils.h
+++ b/utils.h
@@ -8,6 +8,10 @@ 
 #include <stddef.h>
 #include <stdarg.h>
 
+///
+// return the value coresponding to an hexadecimal digit
+unsigned int hexval(unsigned int c);
+
 ///
 // duplicate a memory buffer in a newly allocated buffer.
 // @src: a pointer to the memory buffer to be duplicated