Module: kamailio
Branch: master
Commit: a086b23458f1019e9f3ac5d66ae6f19074ff543e
URL: 
https://github.com/kamailio/kamailio/commit/a086b23458f1019e9f3ac5d66ae6f19074ff543e

Author: Daniel-Constantin Mierla <mico...@gmail.com>
Committer: Daniel-Constantin Mierla <mico...@gmail.com>
Date: 2025-02-04T19:35:52+01:00

core: ut.h - function split time in two signed integers

- the lower 4 bytes are returned, the upper 4 bytes can be stored in the
  second parameter

---

Modified: src/core/ut.h

---

Diff:  
https://github.com/kamailio/kamailio/commit/a086b23458f1019e9f3ac5d66ae6f19074ff543e.diff
Patch: 
https://github.com/kamailio/kamailio/commit/a086b23458f1019e9f3ac5d66ae6f19074ff543e.patch

---

diff --git a/src/core/ut.h b/src/core/ut.h
index 29faca83fc2..f1829f73ca0 100644
--- a/src/core/ut.h
+++ b/src/core/ut.h
@@ -1155,6 +1155,12 @@ static inline int strno2int(str *val, unsigned int *mask)
        }
 }
 
+/**
+ * split time value in two (upper and lower 4-bytes) unsigned int values
+ * - time value representation on 8 bytes: UUUULLLL
+ * - lower 4 bytes are returned (LLLL)
+ * - upper 4 bytes can be stored in second paramter (UUUU)
+ */
 static inline unsigned int ksr_time_uint(time_t *tv, unsigned int *tu)
 {
        unsigned int tl; /* lower 4 bytes */
@@ -1176,6 +1182,33 @@ static inline unsigned int ksr_time_uint(time_t *tv, 
unsigned int *tu)
        return tl;
 }
 
+/**
+ * split time value in two (upper and lower 4-bytes) signed int values
+ * - time value representation on 8 bytes: UUUULLLL
+ * - lower 4 bytes are returned (LLLL)
+ * - upper 4 bytes can be stored in second paramter (UUUU)
+ */
+static inline int ksr_time_sint(time_t *tv, int *tu)
+{
+       int tl; /* lower 4 bytes */
+       long long v64;
+       time_t t;
+
+       if(tv != NULL) {
+               t = *tv;
+       } else {
+               t = time(NULL);
+       }
+       v64 = (long long)t;
+       tl = (int)(v64 & 0xFFFFFFFFLL);
+       if(tu != NULL) {
+               /* upper 4 bytes */
+               *tu = (int)((v64 >> 32) & 0xFFFFFFFFLL);
+       }
+
+       return tl;
+}
+
 /* converts a username into uid:gid,
  * returns -1 on error & 0 on success */
 int user2uid(int *uid, int *gid, char *user);

_______________________________________________
Kamailio - Development Mailing List -- sr-dev@lists.kamailio.org
To unsubscribe send an email to sr-dev-le...@lists.kamailio.org
Important: keep the mailing list in the recipients, do not reply only to the 
sender!

Reply via email to