Pārlūkot izejas kodu

small utility to generate and print a UUID to the screen

George C. Privon 6 mēneši atpakaļ
revīzija
3416e95b84
1 mainītis faili ar 29 papildinājumiem un 0 dzēšanām
  1. 29 0
      uuid-generator.c

+ 29 - 0
uuid-generator.c

@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <uuid.h>
+#include <unistd.h>
+
+int main() {
+
+    /* restrict ourselves to standard IO */
+    pledge("stdio", NULL);
+
+	/* allocate space to store a generated UUID, a string representation
+     * and status/error information. */
+	void *myuuid;
+	char *myuuidstr;
+	uint32_t uuidstatus;
+	myuuid = malloc(sizeof(uuid_t));
+
+    /* create a UUID (Version 4), convert it to a string representation,
+     * and print it out to the screen. */
+	uuid_create(myuuid, &uuidstatus);
+	uuid_to_string(myuuid, &myuuidstr, &uuidstatus);
+	printf("%s\n", myuuidstr);
+
+    /* free malloc()'ed memory. */
+	free(myuuid);
+	free(myuuidstr);
+
+return 0;
+}