aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-07-01 23:52:18 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-07-06 02:07:14 +0200
commit61f53e257de47e29fe3d6eec6d233552e8116cb4 (patch)
treebc13bf2dea0fa11cb25f969dedbe60bbb66f93e8
parent8e929d4e369f687552db8d127b2d39947eb93983 (diff)
downloadsparse-61f53e257de47e29fe3d6eec6d233552e8116cb4.tar.gz
cleanup: move hexval() to utils.c
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>
-rw-r--r--lib.c17
-rw-r--r--lib.h2
-rw-r--r--utils.c17
-rw-r--r--utils.h4
4 files changed, 21 insertions, 19 deletions
diff --git a/lib.c b/lib.c
index f512be2e..57c89a16 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 b906d503..682e54f5 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 094df3f9..72fff00f 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 7bd14f46..079fb02a 100644
--- a/utils.h
+++ b/utils.h
@@ -9,6 +9,10 @@
#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
// @len: the size of the memory buffer to be duplicated