From 3185d26a1274d3eff47dcd1c4dd9ca606e6fdc34 Mon Sep 17 00:00:00 2001 From: Toomas Soome Date: Tue, 8 Nov 2016 14:47:08 +0200 Subject: 7551 ficl: Implement uuid-to-string and uuid-from-string. Reviewed by: Robert Mustacchi Reviewed by: Adam Števko Reviewed by: Richard Lowe Approved by: Dan McDonald MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- usr/src/common/ficl/loader.c | 83 ++++++++++++++++++++++++++++++++++++++++ usr/src/lib/libficl/Makefile.com | 2 +- 2 files changed, 84 insertions(+), 1 deletion(-) 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 +#else +#include +#endif #include #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 -- cgit v1.2.3