5 Star 31 Fork 6

方瑾/async

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
util.c 1.03 KB
一键复制 编辑 原始数据 按行查看 历史
方瑾 提交于 2019-04-14 19:27 . update
#include "util.h"
char * createUUID() {
const char * c = "89ab";
char * buf = (char *)malloc(37);
char * p = buf;
for (int n = 0; n < 16; ++n) {
int b = rand() % 255;
switch (n) {
case 6: sprintf(p, "4%x", b % 15); break;
case 8: sprintf(p, "%c%x", c[rand() % strlen(c)], b % 15); break;
default: sprintf(p, "%02x", b); break;
}
p += 2;
switch (n) {
case 3:
case 5:
case 7:
case 9:
*p++ = '-'; break;
}
}
*p = 0;
return buf;
}
int getNumberLength(int number) {
if (number < 0) return 0;
if (number == 0) return 1;
int length = 0;
while (number != 0) {
number /= 10;
length++;
}
return length;
}
int gettimeofday(struct timeval *tp, void *tzp)
{
time_t clock;
struct tm tm;
SYSTEMTIME wtm;
GetLocalTime(&wtm);
tm.tm_year = wtm.wYear - 1900;
tm.tm_mon = wtm.wMonth - 1;
tm.tm_mday = wtm.wDay;
tm.tm_hour = wtm.wHour;
tm.tm_min = wtm.wMinute;
tm.tm_sec = wtm.wSecond;
tm.tm_isdst = -1;
clock = mktime(&tm);
tp->tv_sec = clock;
tp->tv_usec = wtm.wMilliseconds * 1000;
return (0);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lyxfj/async.git
git@gitee.com:lyxfj/async.git
lyxfj
async
async
master

搜索帮助