aboutsummaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2017-03-18 20:30:06 +0000
committerFreeArtMan <dos21h@gmail.com>2017-03-18 20:30:06 +0000
commit0ae9dc3dfe4b1bd24a0d0385480d9ad7d07d0976 (patch)
treef51cbf81033fd9f87373c27c0c81d6b6c59396e9 /util.c
parent39c0045fbb2f511484d5effb69c987906d0b52d8 (diff)
downloadagni-0ae9dc3dfe4b1bd24a0d0385480d9ad7d07d0976.tar.gz
agni-0ae9dc3dfe4b1bd24a0d0385480d9ad7d07d0976.zip
Basic response from 2 command, works for privatemessages
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;
}