From 050e318ea9c71d3ac15d15967b800ba5fdd99ab6 Mon Sep 17 00:00:00 2001 From: terror Date: Wed, 12 Jun 2024 18:56:38 +1200 Subject: [PATCH] Do not use timespec_tonanos --- tool/net/lfuncs.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tool/net/lfuncs.c b/tool/net/lfuncs.c index ac43fd10e..a76cf8b18 100644 --- a/tool/net/lfuncs.c +++ b/tool/net/lfuncs.c @@ -860,15 +860,15 @@ int LuaUuidV4(lua_State *L) { int LuaUuidV7(lua_State *L) { char uuid_str[37] = {0}; - struct timespec now = timespec_real(); - uint64_t time_now = timespec_tonanos(now); + struct timespec ts = timespec_real(); + uint64_t time_now = ts.tv_sec * 1000000000 + ts.tv_nsec; uint64_t random_data = _rand64(); - snprintf(uuid_str, sizeof(uuid_str), "%08x-%04x-%04x-%04x-%012llx", - (uint32_t)(time_now >> 32), //8 - (uint16_t)(time_now >> 16), //4 - (uint16_t)((0x7 << 12) | (time_now >> 4 & 0x0fff)), //4 - (uint16_t)((0b10 << 14 | ((time_now & 0x000f) << 10)) | (random_data & 0x03FF)), //4 - (uint64_t)(random_data >> 4 & 0xFFFFFFFFFFFF) //12 + snprintf(uuid_str, 37, "%08x-%04x-%04x-%04x-%012llx", + (uint32_t)(time_now >> 32), + (uint16_t)(time_now >> 16), + (uint16_t)((0x7 << 12) | (time_now >> 4 & 0x0fff)), + (uint16_t)((0b10 << 14 | ((time_now & 0x000f) << 10)) | (random_data & 0x03FF)), + (uint64_t)(random_data >> 4 & 0xFFFFFFFFFFFF) ); lua_pushfstring(L, uuid_str); return 1;