uuid-generator.c 704 B

1234567891011121314151617181920212223242526272829
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <uuid.h>
  4. #include <unistd.h>
  5. int main() {
  6. /* restrict ourselves to standard IO */
  7. pledge("stdio", NULL);
  8. /* allocate space to store a generated UUID, a string representation
  9. * and status/error information. */
  10. void *myuuid;
  11. char *myuuidstr;
  12. uint32_t uuidstatus;
  13. myuuid = malloc(sizeof(uuid_t));
  14. /* create a UUID (Version 4), convert it to a string representation,
  15. * and print it out to the screen. */
  16. uuid_create(myuuid, &uuidstatus);
  17. uuid_to_string(myuuid, &myuuidstr, &uuidstatus);
  18. printf("%s\n", myuuidstr);
  19. /* free malloc()'ed memory. */
  20. free(myuuid);
  21. free(myuuidstr);
  22. return 0;
  23. }