summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToomas Soome <tsoome@me.com>2016-11-08 14:47:08 +0200
committerDan McDonald <danmcd@omniti.com>2016-12-05 10:17:36 -0500
commit3185d26a1274d3eff47dcd1c4dd9ca606e6fdc34 (patch)
treedf15b6358d69d6e2baae187498dc90bf4f868002
parent4f5c6fa51ee27ee27271feb50bdaf94cedc40af2 (diff)
downloadillumos-joyent-3185d26a1274d3eff47dcd1c4dd9ca606e6fdc34.tar.gz
7551 ficl: Implement uuid-to-string and uuid-from-string.
Reviewed by: Robert Mustacchi <rm@joyent.com> Reviewed by: Adam Števko <adam.stevko@gmail.com> Reviewed by: Richard Lowe <richlowe@richlowe.net> Approved by: Dan McDonald <danmcd@omniti.com>
-rw-r--r--usr/src/common/ficl/loader.c83
-rw-r--r--usr/src/lib/libficl/Makefile.com2
2 files changed, 84 insertions, 1 deletions
diff --git a/usr/src/common/ficl/loader.c b/usr/src/common/ficl/loader.c
index 4000e5aabc..054beba91a 100644
--- a/usr/src/common/ficl/loader.c
+++ b/usr/src/common/ficl/loader.c
@@ -48,6 +48,11 @@
#endif
#include "bootstrap.h"
#endif
+#ifdef STAND
+#include <uuid.h>
+#else
+#include <uuid/uuid.h>
+#endif
#include <string.h>
#include "ficl.h"
@@ -71,6 +76,8 @@ extern uint32_t biospci_locator(uint8_t, uint8_t, uint8_t);
* pnpdevices ( -- addr )
* pnphandlers ( -- addr )
* ccall ( [[...[p10] p9] ... p1] n addr -- result )
+ * uuid-from-string ( addr n -- addr' )
+ * uuid-to-string ( addr' -- addr n | -1 )
* .# ( value -- )
*/
@@ -324,6 +331,78 @@ ficlCcall(ficlVm *pVM)
ficlStackPushInteger(ficlVmGetDataStack(pVM), result);
}
+void
+ficlUuidFromString(ficlVm *pVM)
+{
+ char *uuid;
+ char *uuid_ptr;
+ int uuid_size;
+ uuid_t *u;
+#ifdef STAND
+ uint32_t status;
+#else
+ int status;
+#endif
+
+ FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 2, 0);
+
+ uuid_size = ficlStackPopInteger(ficlVmGetDataStack(pVM));
+ uuid_ptr = ficlStackPopPointer(ficlVmGetDataStack(pVM));
+
+ uuid = ficlMalloc(uuid_size + 1);
+ if (!uuid)
+ ficlVmThrowError(pVM, "Error: out of memory");
+ (void) memcpy(uuid, uuid_ptr, uuid_size);
+ uuid[uuid_size] = '\0';
+
+ u = ficlMalloc(sizeof (*u));
+#ifdef STAND
+ uuid_from_string(uuid, u, &status);
+ ficlFree(uuid);
+ if (status != uuid_s_ok) {
+ ficlFree(u);
+ u = NULL;
+ }
+#else
+ status = uuid_parse(uuid, *u);
+ ficlFree(uuid);
+ if (status != 0) {
+ ficlFree(u);
+ u = NULL;
+ }
+#endif
+ ficlStackPushPointer(ficlVmGetDataStack(pVM), u);
+}
+
+void
+ficlUuidToString(ficlVm *pVM)
+{
+ char *uuid;
+ uuid_t *u;
+#ifdef STAND
+ uint32_t status;
+#endif
+
+ FICL_STACK_CHECK(ficlVmGetDataStack(pVM), 1, 0);
+
+ u = ficlStackPopPointer(ficlVmGetDataStack(pVM));
+#ifdef STAND
+ uuid_to_string(u, &uuid, &status);
+ if (status == uuid_s_ok) {
+ ficlStackPushPointer(ficlVmGetDataStack(pVM), uuid);
+ ficlStackPushInteger(ficlVmGetDataStack(pVM), strlen(uuid));
+ } else
+#else
+ uuid = ficlMalloc(UUID_PRINTABLE_STRING_LENGTH);
+ if (uuid != NULL) {
+ uuid_unparse(*u, uuid);
+ ficlStackPushPointer(ficlVmGetDataStack(pVM), uuid);
+ ficlStackPushInteger(ficlVmGetDataStack(pVM), strlen(uuid));
+ } else
+#endif
+ ficlStackPushInteger(ficlVmGetDataStack(pVM), -1);
+}
+
/*
* f i c l E x e c F D
* reads in text from file fd and passes it to ficlExec()
@@ -1038,6 +1117,10 @@ ficlSystemCompilePlatform(ficlSystem *pSys)
ficlDictionarySetPrimitive(dp, "findfile", ficlFindfile,
FICL_WORD_DEFAULT);
ficlDictionarySetPrimitive(dp, "ccall", ficlCcall, FICL_WORD_DEFAULT);
+ ficlDictionarySetPrimitive(dp, "uuid-from-string", ficlUuidFromString,
+ FICL_WORD_DEFAULT);
+ ficlDictionarySetPrimitive(dp, "uuid-to-string", ficlUuidToString,
+ FICL_WORD_DEFAULT);
#ifdef STAND
#ifdef __i386__
ficlDictionarySetPrimitive(dp, "outb", ficlOutb, FICL_WORD_DEFAULT);
diff --git a/usr/src/lib/libficl/Makefile.com b/usr/src/lib/libficl/Makefile.com
index a2c37d27c2..505e0d27f4 100644
--- a/usr/src/lib/libficl/Makefile.com
+++ b/usr/src/lib/libficl/Makefile.com
@@ -31,7 +31,7 @@ FICLDIR= $(SRC)/common/ficl
C99MODE= $(C99_ENABLE)
CPPFLAGS += -I.. -I$(FICLDIR) -D_LARGEFILE64_SOURCE=1
-LDLIBS += -lc -lm -lumem
+LDLIBS += -luuid -lc -lm -lumem
HEADERS= $(FICLDIR)/ficl.h $(FICLDIR)/ficltokens.h ../ficllocal.h \
$(FICLDIR)/ficlplatform/unix.h