changeset 480:967763846b84

val: add a function to return a val type name Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Thu, 12 Apr 2018 09:45:07 -0400
parents 72e41d6090f6
children a99742fc9157
files include/jeffpc/val.h jeffpc.mapfile-vers val_dump.c
diffstat 3 files changed, 18 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/include/jeffpc/val.h	Thu Apr 12 09:44:55 2018 -0400
+++ b/include/jeffpc/val.h	Thu Apr 12 09:45:07 2018 -0400
@@ -233,6 +233,7 @@
  * Dumping functions
  */
 
+extern const char *__val_typename(int type, bool human);
 extern void val_dump_file(FILE *out, struct val *v, int indent);
 
 static inline void val_dump(struct val *v, int indent)
@@ -241,6 +242,20 @@
 }
 
 /*
+ * NOTE: The typename functions below may return a thread-local buffer when
+ * given an unknown type.
+ */
+static inline const char *val_typename(int type)
+{
+	return __val_typename(type, true);
+}
+
+static inline const char *val_rawtypename(int type)
+{
+	return __val_typename(type, false);
+}
+
+/*
  * Misc functions
  */
 
--- a/jeffpc.mapfile-vers	Thu Apr 12 09:44:55 2018 -0400
+++ b/jeffpc.mapfile-vers	Thu Apr 12 09:45:07 2018 -0400
@@ -234,6 +234,7 @@
 		xuuid_unparse;
 
 		# val
+		__val_typename;
 		val_dump_file;
 		val_free;
 		val_alloc_array;
--- a/val_dump.c	Thu Apr 12 09:44:55 2018 -0400
+++ b/val_dump.c	Thu Apr 12 09:45:07 2018 -0400
@@ -27,7 +27,7 @@
 
 #define INDENT_STEP	5
 
-static inline const char *typename(int type)
+const char *__val_typename(int type, bool human)
 {
 	static __thread char badname[10];
 
@@ -64,7 +64,7 @@
 		return;
 	}
 
-	fprintf(out, "type=%s", typename(val->type));
+	fprintf(out, "type=%s", val_typename(val->type));
 
 	switch (val->type) {
 		case VT_NULL: