summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'util.c')
-rw-r--r--util.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/util.c b/util.c
index 20ad6d8..b0d8efe 100644
--- a/util.c
+++ b/util.c
@@ -1,5 +1,23 @@
#include "util.h"
+/*
+return unique ID, with atomic counter should work in all cases
+*/
+_Atomic static int _glbl_id=1;
+int uniq_id()
+{
+ int ret=-1,id;
+
+ //what possible could go wrong?
+ // sry emilsp this is not important for now
+ id = atomic_load(&_glbl_id);
+ ret = id;
+ id += 1;
+ atomic_store(&_glbl_id, id);
+ return ret;
+
+}
+
char *alloc_new_str_s(char *str, size_t size)
{
char *ret = NULL;
@@ -15,14 +33,14 @@ char *alloc_new_str_s(char *str, size_t size)
return NULL;
}
- ret = malloc(size+1);
+ ret = malloc(size+1); //extra for 1 zero at then end
if (ret == NULL)
{
return NULL;
}
memcpy(ret, str, size);
- ret[size] = 0;
+ ret[size] = 0; //add zero at the end
return ret;
}