summaryrefslogtreecommitdiff
path: root/lib/replace
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2021-01-04 13:12:30 +0100
committerJeremy Allison <jra@samba.org>2021-01-08 20:31:33 +0000
commitc8d9ce3f7c8c486ab21e320a0adcb71311dcb453 (patch)
tree8012f95115a6d82013b337bca6a404692fdaa4f7 /lib/replace
parentdad4410c86c2a2988cdc301693d6be3ee9cf6253 (diff)
downloadsamba-c8d9ce3f7c8c486ab21e320a0adcb71311dcb453.tar.gz
lib: Add "hex_byte()" to replace.h
This is required in quite a few places, and replace.h has things like ZERO_STRUCT already, so this is not completely outplaced. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'lib/replace')
-rw-r--r--lib/replace/replace.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/replace/replace.h b/lib/replace/replace.h
index f7f6b653869..e08bf7c2e58 100644
--- a/lib/replace/replace.h
+++ b/lib/replace/replace.h
@@ -977,6 +977,22 @@ bool nss_wrapper_hosts_enabled(void);
bool socket_wrapper_enabled(void);
bool uid_wrapper_enabled(void);
+static inline bool _hexcharval(char c, uint8_t *val)
+{
+ if ((c >= '0') && (c <= '9')) { *val = c - '0'; return true; }
+ if ((c >= 'a') && (c <= 'f')) { *val = c - 'a' + 10; return true; }
+ if ((c >= 'A') && (c <= 'F')) { *val = c - 'A' + 10; return true; }
+ return false;
+}
+
+static inline bool hex_byte(const char *in, uint8_t *out)
+{
+ uint8_t hi=0, lo=0;
+ bool ok = _hexcharval(in[0], &hi) && _hexcharval(in[1], &lo);
+ *out = (hi<<4)+lo;
+ return ok;
+}
+
/* Needed for Solaris atomic_add_XX functions. */
#if defined(HAVE_SYS_ATOMIC_H)
#include <sys/atomic.h>