summaryrefslogtreecommitdiff
path: root/modules/uuid
diff options
context:
space:
mode:
Diffstat (limited to 'modules/uuid')
-rw-r--r--modules/uuid/module.mk3
-rw-r--r--modules/uuid/uuid.c30
2 files changed, 21 insertions, 12 deletions
diff --git a/modules/uuid/module.mk b/modules/uuid/module.mk
index 64a3909..d82836b 100644
--- a/modules/uuid/module.mk
+++ b/modules/uuid/module.mk
@@ -6,8 +6,5 @@
MOD := uuid
$(MOD)_SRCS += uuid.c
-ifneq ($(OS),darwin)
-$(MOD)_LFLAGS += -luuid
-endif
include mk/mod.mk
diff --git a/modules/uuid/uuid.c b/modules/uuid/uuid.c
index 6426a6e..b213128 100644
--- a/modules/uuid/uuid.c
+++ b/modules/uuid/uuid.c
@@ -5,15 +5,27 @@
*/
#include <stdlib.h>
#include <string.h>
-#include <uuid/uuid.h>
+#include <stdio.h>
#include <re.h>
#include <baresip.h>
+enum { UUID_LEN = 36 };
+
+
+static int generate_random_uuid(FILE *f)
+{
+ if (re_fprintf(f, "%08x-%04x-%04x-%04x-%08x%04x",
+ rand_u32(), rand_u16(), rand_u16(), rand_u16(),
+ rand_u32(), rand_u16()) != UUID_LEN)
+ return ENOMEM;
+
+ return 0;
+}
+
+
static int uuid_init(const char *file)
{
- char uuid[37];
- uuid_t uu;
FILE *f = NULL;
int err = 0;
@@ -30,13 +42,13 @@ static int uuid_init(const char *file)
goto out;
}
- uuid_generate(uu);
-
- uuid_unparse(uu, uuid);
-
- re_fprintf(f, "%s", uuid);
+ err = generate_random_uuid(f);
+ if (err) {
+ warning("uuid: generate random UUID failed (%m)\n", err);
+ goto out;
+ }
- info("uuid: generated new UUID (%s)\n", uuid);
+ info("uuid: generated new UUID in %s\n", file);
out:
if (f)