Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e04ef027
T
TDengine
项目概览
taosdata
/
TDengine
接近 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
e04ef027
编写于
3月 11, 2022
作者:
wafwerar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-13768]<fix>: redefine time api.
上级
0595d9f1
变更
30
隐藏空白更改
内联
并排
Showing
30 changed file
with
804 addition
and
442 deletion
+804
-442
include/os/osDef.h
include/os/osDef.h
+0
-2
include/os/osTime.h
include/os/osTime.h
+12
-0
source/common/src/tname.c
source/common/src/tname.c
+1
-1
source/common/src/ttime.c
source/common/src/ttime.c
+12
-12
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+1
-1
source/libs/executor/test/executorTests.cpp
source/libs/executor/test/executorTests.cpp
+3
-3
source/libs/executor/test/lhashTests.cpp
source/libs/executor/test/lhashTests.cpp
+1
-1
source/libs/qworker/test/qworkerTests.cpp
source/libs/qworker/test/qworkerTests.cpp
+7
-7
source/libs/scalar/test/filter/filterTests.cpp
source/libs/scalar/test/filter/filterTests.cpp
+1
-1
source/libs/scalar/test/scalar/scalarTests.cpp
source/libs/scalar/test/scalar/scalarTests.cpp
+1
-1
source/libs/scheduler/test/schedulerTests.cpp
source/libs/scheduler/test/schedulerTests.cpp
+2
-2
source/libs/sync/src/syncEnv.c
source/libs/sync/src/syncEnv.c
+1
-1
source/libs/sync/src/syncIO.c
source/libs/sync/src/syncIO.c
+1
-1
source/libs/transport/test/pushClient.c
source/libs/transport/test/pushClient.c
+2
-2
source/libs/transport/test/rclient.c
source/libs/transport/test/rclient.c
+2
-2
source/libs/transport/test/rsclient.c
source/libs/transport/test/rsclient.c
+2
-2
source/libs/transport/test/syncClient.c
source/libs/transport/test/syncClient.c
+2
-2
source/os/src/osRand.c
source/os/src/osRand.c
+2
-2
source/os/src/osStrptime.c
source/os/src/osStrptime.c
+365
-363
source/os/src/osTime.c
source/os/src/osTime.c
+371
-21
source/os/src/osTimezone.c
source/os/src/osTimezone.c
+4
-4
source/util/src/tdes.c
source/util/src/tdes.c
+1
-1
source/util/src/tlog.c
source/util/src/tlog.c
+1
-1
source/util/src/tskiplist.c
source/util/src/tskiplist.c
+1
-1
source/util/test/codingTests.cpp
source/util/test/codingTests.cpp
+2
-2
source/util/test/pageBufferTest.cpp
source/util/test/pageBufferTest.cpp
+1
-1
source/util/test/skiplistTest.cpp
source/util/test/skiplistTest.cpp
+2
-2
tests/script/api/batchprepare.c
tests/script/api/batchprepare.c
+1
-1
tests/script/api/stmtBatchTest.c
tests/script/api/stmtBatchTest.c
+1
-1
tests/test/c/tmqDemo.c
tests/test/c/tmqDemo.c
+1
-1
未找到文件。
include/os/osDef.h
浏览文件 @
e04ef027
...
...
@@ -65,8 +65,6 @@ extern "C" {
#define in_addr_t unsigned long
#define socklen_t int
struct
tm
*
localtime_r
(
const
time_t
*
timep
,
struct
tm
*
result
);
char
*
strptime
(
const
char
*
buf
,
const
char
*
fmt
,
struct
tm
*
tm
);
char
*
strsep
(
char
**
stringp
,
const
char
*
delim
);
char
*
getpass
(
const
char
*
prefix
);
char
*
strndup
(
const
char
*
s
,
size_t
n
);
...
...
include/os/osTime.h
浏览文件 @
e04ef027
...
...
@@ -20,6 +20,15 @@
extern
"C"
{
#endif
// If the error is in a third-party library, place this header file under the third-party library header file.
#ifndef ALLOW_FORBID_FUNC
#define strptime STRPTIME_FUNC_TAOS_FORBID
#define gettimeofday GETTIMEOFDAY_FUNC_TAOS_FORBID
#define localtime_s LOCALTIMES_FUNC_TAOS_FORBID
#define localtime_r LOCALTIMER_FUNC_TAOS_FORBID
#define time TIME_FUNC_TAOS_FORBID
#endif
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#ifdef _TD_GO_DLL_
#define MILLISECOND_PER_SECOND (1000LL)
...
...
@@ -61,6 +70,9 @@ static FORCE_INLINE int64_t taosGetTimestampNs() {
return
(
int64_t
)
systemTime
.
tv_sec
*
1000000000L
+
(
int64_t
)
systemTime
.
tv_nsec
;
}
char
*
taosStrpTime
(
const
char
*
buf
,
const
char
*
fmt
,
struct
tm
*
tm
);
struct
tm
*
taosLocalTime
(
const
time_t
*
timep
,
struct
tm
*
result
);
#ifdef __cplusplus
}
#endif
...
...
source/common/src/tname.c
浏览文件 @
e04ef027
...
...
@@ -61,7 +61,7 @@ int64_t taosGetIntervalStartTimestamp(int64_t startTime, int64_t slidingTime, in
}
struct tm tm;
time_t t = (time_t)start;
localtime_r
(&t, &tm);
taosLocalTime
(&t, &tm);
tm.tm_sec = 0;
tm.tm_min = 0;
tm.tm_hour = 0;
...
...
source/common/src/ttime.c
浏览文件 @
e04ef027
...
...
@@ -69,7 +69,7 @@ static int64_t m_deltaUtc = 0;
void
deltaToUtcInitOnce
()
{
struct
tm
tm
=
{
0
};
(
void
)
strpt
ime
(
"1970-01-01 00:00:00"
,
(
const
char
*
)(
"%Y-%m-%d %H:%M:%S"
),
&
tm
);
(
void
)
taosStrpT
ime
(
"1970-01-01 00:00:00"
,
(
const
char
*
)(
"%Y-%m-%d %H:%M:%S"
),
&
tm
);
m_deltaUtc
=
(
int64_t
)
mktime
(
&
tm
);
// printf("====delta:%lld\n\n", seconds);
}
...
...
@@ -236,9 +236,9 @@ int32_t parseTimeWithTz(const char* timestr, int64_t* time, int32_t timePrec, ch
char
*
str
;
if
(
delim
==
'T'
)
{
str
=
strpt
ime
(
timestr
,
"%Y-%m-%dT%H:%M:%S"
,
&
tm
);
str
=
taosStrpT
ime
(
timestr
,
"%Y-%m-%dT%H:%M:%S"
,
&
tm
);
}
else
if
(
delim
==
0
)
{
str
=
strpt
ime
(
timestr
,
"%Y-%m-%d %H:%M:%S"
,
&
tm
);
str
=
taosStrpT
ime
(
timestr
,
"%Y-%m-%d %H:%M:%S"
,
&
tm
);
}
else
{
str
=
NULL
;
}
...
...
@@ -303,7 +303,7 @@ int32_t parseLocaltime(char* timestr, int64_t* time, int32_t timePrec) {
*
time
=
0
;
struct
tm
tm
=
{
0
};
char
*
str
=
strpt
ime
(
timestr
,
"%Y-%m-%d %H:%M:%S"
,
&
tm
);
char
*
str
=
taosStrpT
ime
(
timestr
,
"%Y-%m-%d %H:%M:%S"
,
&
tm
);
if
(
str
==
NULL
)
{
return
-
1
;
}
...
...
@@ -338,7 +338,7 @@ int32_t parseLocaltimeDst(char* timestr, int64_t* time, int32_t timePrec) {
struct
tm
tm
=
{
0
};
tm
.
tm_isdst
=
-
1
;
char
*
str
=
strpt
ime
(
timestr
,
"%Y-%m-%d %H:%M:%S"
,
&
tm
);
char
*
str
=
taosStrpT
ime
(
timestr
,
"%Y-%m-%d %H:%M:%S"
,
&
tm
);
if
(
str
==
NULL
)
{
return
-
1
;
}
...
...
@@ -466,7 +466,7 @@ int64_t taosTimeAdd(int64_t t, int64_t duration, char unit, int32_t precision) {
struct
tm
tm
;
time_t
tt
=
(
time_t
)(
t
/
TSDB_TICK_PER_SECOND
(
precision
));
localtime_r
(
&
tt
,
&
tm
);
taosLocalTime
(
&
tt
,
&
tm
);
int32_t
mon
=
tm
.
tm_year
*
12
+
tm
.
tm_mon
+
(
int32_t
)
duration
;
tm
.
tm_year
=
mon
/
12
;
tm
.
tm_mon
=
mon
%
12
;
...
...
@@ -489,11 +489,11 @@ int32_t taosTimeCountInterval(int64_t skey, int64_t ekey, int64_t interval, char
struct
tm
tm
;
time_t
t
=
(
time_t
)
skey
;
localtime_r
(
&
t
,
&
tm
);
taosLocalTime
(
&
t
,
&
tm
);
int32_t
smon
=
tm
.
tm_year
*
12
+
tm
.
tm_mon
;
t
=
(
time_t
)
ekey
;
localtime_r
(
&
t
,
&
tm
);
taosLocalTime
(
&
t
,
&
tm
);
int32_t
emon
=
tm
.
tm_year
*
12
+
tm
.
tm_mon
;
if
(
unit
==
'y'
)
{
...
...
@@ -514,7 +514,7 @@ int64_t taosTimeTruncate(int64_t t, const SInterval* pInterval, int32_t precisio
start
/=
(
int64_t
)(
TSDB_TICK_PER_SECOND
(
precision
));
struct
tm
tm
;
time_t
tt
=
(
time_t
)
start
;
localtime_r
(
&
tt
,
&
tm
);
taosLocalTime
(
&
tt
,
&
tm
);
tm
.
tm_sec
=
0
;
tm
.
tm_min
=
0
;
tm
.
tm_hour
=
0
;
...
...
@@ -597,13 +597,13 @@ const char* fmtts(int64_t ts) {
if
(
ts
>
-
62135625943
&&
ts
<
32503651200
)
{
time_t
t
=
(
time_t
)
ts
;
localtime_r
(
&
t
,
&
tm
);
taosLocalTime
(
&
t
,
&
tm
);
pos
+=
strftime
(
buf
+
pos
,
sizeof
(
buf
),
"s=%Y-%m-%d %H:%M:%S"
,
&
tm
);
}
if
(
ts
>
-
62135625943000
&&
ts
<
32503651200000
)
{
time_t
t
=
(
time_t
)(
ts
/
1000
);
localtime_r
(
&
t
,
&
tm
);
taosLocalTime
(
&
t
,
&
tm
);
if
(
pos
>
0
)
{
buf
[
pos
++
]
=
' '
;
buf
[
pos
++
]
=
'|'
;
...
...
@@ -615,7 +615,7 @@ const char* fmtts(int64_t ts) {
{
time_t
t
=
(
time_t
)(
ts
/
1000000
);
localtime_r
(
&
t
,
&
tm
);
taosLocalTime
(
&
t
,
&
tm
);
if
(
pos
>
0
)
{
buf
[
pos
++
]
=
' '
;
buf
[
pos
++
]
=
'|'
;
...
...
source/libs/executor/src/executorimpl.c
浏览文件 @
e04ef027
...
...
@@ -163,7 +163,7 @@ static void getNextTimeWindow(SInterval* pInterval, int32_t precision, int32_t o
struct
tm
tm
;
time_t
t
=
(
time_t
)
key
;
localtime_r
(
&
t
,
&
tm
);
taosLocalTime
(
&
t
,
&
tm
);
int
mon
=
(
int
)(
tm
.
tm_year
*
12
+
tm
.
tm_mon
+
interval
*
factor
);
tm
.
tm_year
=
mon
/
12
;
...
...
source/libs/executor/test/executorTests.cpp
浏览文件 @
e04ef027
...
...
@@ -1019,7 +1019,7 @@ TEST(testCase, external_sort_Test) {
return;
#endif
taosSeedRand(t
ime(NULL
));
taosSeedRand(t
aosGetTimestampSec(
));
SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder));
SOrder o = {0};
...
...
@@ -1080,7 +1080,7 @@ TEST(testCase, external_sort_Test) {
}
TEST(testCase, sorted_merge_Test) {
taosSeedRand(t
ime(NULL
));
taosSeedRand(t
aosGetTimestampSec(
));
SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder));
SOrder o = {0};
...
...
@@ -1152,7 +1152,7 @@ TEST(testCase, sorted_merge_Test) {
}
TEST(testCase, time_interval_Operator_Test) {
taosSeedRand(t
ime(NULL
));
taosSeedRand(t
aosGetTimestampSec(
));
SArray* pOrderVal = taosArrayInit(4, sizeof(SOrder));
SOrder o = {0};
...
...
source/libs/executor/test/lhashTests.cpp
浏览文件 @
e04ef027
...
...
@@ -25,7 +25,7 @@
#pragma GCC diagnostic ignored "-Wsign-compare"
TEST
(
testCase
,
linear_hash_Tests
)
{
taosSeedRand
(
t
ime
(
NULL
));
taosSeedRand
(
t
aosGetTimestampSec
(
));
_hash_fn_t
fn
=
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_INT
);
#if 0
...
...
source/libs/qworker/test/qworkerTests.cpp
浏览文件 @
e04ef027
...
...
@@ -963,7 +963,7 @@ TEST(seqTest, randCase) {
stubSetRpcSendResponse();
stubSetCreateExecTask();
taosSeedRand(t
ime(NULL
));
taosSeedRand(t
aosGetTimestampSec(
));
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, mockPointer, qwtPutReqToQueue);
ASSERT_EQ(code, 0);
...
...
@@ -1025,7 +1025,7 @@ TEST(seqTest, multithreadRand) {
stubSetStringToPlan();
stubSetRpcSendResponse();
taosSeedRand(t
ime(NULL
));
taosSeedRand(t
aosGetTimestampSec(
));
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, mockPointer, qwtPutReqToQueue);
ASSERT_EQ(code, 0);
...
...
@@ -1076,7 +1076,7 @@ TEST(rcTest, shortExecshortDelay) {
stubSetPutDataBlock
();
stubSetGetDataBlock
();
taosSeedRand
(
t
ime
(
NULL
));
taosSeedRand
(
t
aosGetTimestampSec
(
));
qwtTestStop
=
false
;
qwtTestQuitThreadNum
=
0
;
...
...
@@ -1157,7 +1157,7 @@ TEST(rcTest, longExecshortDelay) {
stubSetPutDataBlock
();
stubSetGetDataBlock
();
taosSeedRand
(
t
ime
(
NULL
));
taosSeedRand
(
t
aosGetTimestampSec
(
));
qwtTestStop
=
false
;
qwtTestQuitThreadNum
=
0
;
...
...
@@ -1240,7 +1240,7 @@ TEST(rcTest, shortExeclongDelay) {
stubSetPutDataBlock
();
stubSetGetDataBlock
();
taosSeedRand
(
t
ime
(
NULL
));
taosSeedRand
(
t
aosGetTimestampSec
(
));
qwtTestStop
=
false
;
qwtTestQuitThreadNum
=
0
;
...
...
@@ -1324,7 +1324,7 @@ TEST(rcTest, dropTest) {
stubSetPutDataBlock();
stubSetGetDataBlock();
taosSeedRand(t
ime(NULL
));
taosSeedRand(t
aosGetTimestampSec(
));
code = qWorkerInit(NODE_TYPE_VNODE, 1, NULL, &mgmt, mockPointer, qwtPutReqToQueue);
ASSERT_EQ(code, 0);
...
...
@@ -1358,7 +1358,7 @@ TEST(rcTest, dropTest) {
int
main
(
int
argc
,
char
**
argv
)
{
taosSeedRand
(
t
ime
(
NULL
));
taosSeedRand
(
t
aosGetTimestampSec
(
));
testing
::
InitGoogleTest
(
&
argc
,
argv
);
return
RUN_ALL_TESTS
();
}
...
...
source/libs/scalar/test/filter/filterTests.cpp
浏览文件 @
e04ef027
...
...
@@ -1286,7 +1286,7 @@ TEST(scalarModelogicTest, diff_columns_or_and_or) {
int
main
(
int
argc
,
char
**
argv
)
{
taosSeedRand
(
t
ime
(
NULL
));
taosSeedRand
(
t
aosGetTimestampSec
(
));
testing
::
InitGoogleTest
(
&
argc
,
argv
);
return
RUN_ALL_TESTS
();
}
...
...
source/libs/scalar/test/scalar/scalarTests.cpp
浏览文件 @
e04ef027
...
...
@@ -1435,7 +1435,7 @@ TEST(columnTest, greater_and_lower) {
int
main
(
int
argc
,
char
**
argv
)
{
taosSeedRand
(
t
ime
(
NULL
));
taosSeedRand
(
t
aosGetTimestampSec
(
));
testing
::
InitGoogleTest
(
&
argc
,
argv
);
return
RUN_ALL_TESTS
();
}
...
...
source/libs/scheduler/test/schedulerTests.cpp
浏览文件 @
e04ef027
...
...
@@ -724,7 +724,7 @@ TEST(queryTest, flowCtrlCase) {
schtInitLogFile
();
taosSeedRand
(
t
ime
(
NULL
));
taosSeedRand
(
t
aosGetTimestampSec
(
));
SArray
*
qnodeList
=
taosArrayInit
(
1
,
sizeof
(
SEp
));
...
...
@@ -873,7 +873,7 @@ TEST(multiThread, forceFree) {
}
int
main
(
int
argc
,
char
**
argv
)
{
taosSeedRand
(
t
ime
(
NULL
));
taosSeedRand
(
t
aosGetTimestampSec
(
));
testing
::
InitGoogleTest
(
&
argc
,
argv
);
return
RUN_ALL_TESTS
();
}
...
...
source/libs/sync/src/syncEnv.c
浏览文件 @
e04ef027
...
...
@@ -28,7 +28,7 @@ static void doSyncEnvStopTimer(SSyncEnv *pSyncEnv, tmr_h *pTimer);
int32_t
syncEnvStart
()
{
int32_t
ret
;
taosSeedRand
(
t
ime
(
NULL
));
taosSeedRand
(
t
aosGetTimestampSec
(
));
gSyncEnv
=
(
SSyncEnv
*
)
malloc
(
sizeof
(
SSyncEnv
));
assert
(
gSyncEnv
!=
NULL
);
ret
=
doSyncEnvStart
(
gSyncEnv
);
...
...
source/libs/sync/src/syncIO.c
浏览文件 @
e04ef027
...
...
@@ -44,7 +44,7 @@ int32_t syncIOStart(char *host, uint16_t port) {
gSyncIO
=
syncIOCreate
(
host
,
port
);
assert
(
gSyncIO
!=
NULL
);
taosSeedRand
(
t
ime
(
NULL
));
taosSeedRand
(
t
aosGetTimestampSec
(
));
int32_t
ret
=
syncIOStartInternal
(
gSyncIO
);
assert
(
ret
==
0
);
...
...
source/libs/transport/test/pushClient.c
浏览文件 @
e04ef027
...
...
@@ -203,7 +203,7 @@ int main(int argc, char *argv[]) {
tInfo
(
"client is initialized"
);
tInfo
(
"threads:%d msgSize:%d requests:%d"
,
appThreads
,
msgSize
,
numOfReqs
);
gettimeofday
(
&
systemTime
,
NULL
);
taosGetTimeOfDay
(
&
systemTime
);
startTime
=
systemTime
.
tv_sec
*
1000000
+
systemTime
.
tv_usec
;
SInfo
*
pInfo
=
(
SInfo
*
)
calloc
(
1
,
sizeof
(
SInfo
)
*
appThreads
);
...
...
@@ -226,7 +226,7 @@ int main(int argc, char *argv[]) {
taosUsleep
(
1
);
}
while
(
tcount
<
appThreads
);
gettimeofday
(
&
systemTime
,
NULL
);
taosGetTimeOfDay
(
&
systemTime
);
endTime
=
systemTime
.
tv_sec
*
1000000
+
systemTime
.
tv_usec
;
float
usedTime
=
(
endTime
-
startTime
)
/
1000
.
0
f
;
// mseconds
...
...
source/libs/transport/test/rclient.c
浏览文件 @
e04ef027
...
...
@@ -181,7 +181,7 @@ int main(int argc, char *argv[]) {
tInfo
(
"client is initialized"
);
tInfo
(
"threads:%d msgSize:%d requests:%d"
,
appThreads
,
msgSize
,
numOfReqs
);
gettimeofday
(
&
systemTime
,
NULL
);
taosGetTimeOfDay
(
&
systemTime
);
startTime
=
systemTime
.
tv_sec
*
1000000
+
systemTime
.
tv_usec
;
SInfo
*
pInfo
=
(
SInfo
*
)
calloc
(
1
,
sizeof
(
SInfo
)
*
appThreads
);
...
...
@@ -204,7 +204,7 @@ int main(int argc, char *argv[]) {
taosUsleep
(
1
);
}
while
(
tcount
<
appThreads
);
gettimeofday
(
&
systemTime
,
NULL
);
taosGetTimeOfDay
(
&
systemTime
);
endTime
=
systemTime
.
tv_sec
*
1000000
+
systemTime
.
tv_usec
;
float
usedTime
=
(
endTime
-
startTime
)
/
1000
.
0
f
;
// mseconds
...
...
source/libs/transport/test/rsclient.c
浏览文件 @
e04ef027
...
...
@@ -158,7 +158,7 @@ int main(int argc, char *argv[]) {
tInfo
(
"client is initialized"
);
gettimeofday
(
&
systemTime
,
NULL
);
taosGetTimeOfDay
(
&
systemTime
);
startTime
=
systemTime
.
tv_sec
*
1000000
+
systemTime
.
tv_usec
;
SInfo
*
pInfo
=
(
SInfo
*
)
calloc
(
1
,
sizeof
(
SInfo
)
*
appThreads
);
...
...
@@ -181,7 +181,7 @@ int main(int argc, char *argv[]) {
taosUsleep
(
1
);
}
while
(
tcount
<
appThreads
);
gettimeofday
(
&
systemTime
,
NULL
);
taosGetTimeOfDay
(
&
systemTime
);
endTime
=
systemTime
.
tv_sec
*
1000000
+
systemTime
.
tv_usec
;
float
usedTime
=
(
endTime
-
startTime
)
/
1000
.
0
;
// mseconds
...
...
source/libs/transport/test/syncClient.c
浏览文件 @
e04ef027
...
...
@@ -181,7 +181,7 @@ int main(int argc, char *argv[]) {
tInfo
(
"client is initialized"
);
tInfo
(
"threads:%d msgSize:%d requests:%d"
,
appThreads
,
msgSize
,
numOfReqs
);
gettimeofday
(
&
systemTime
,
NULL
);
taosGetTimeOfDay
(
&
systemTime
);
startTime
=
systemTime
.
tv_sec
*
1000000
+
systemTime
.
tv_usec
;
SInfo
*
pInfo
=
(
SInfo
*
)
calloc
(
1
,
sizeof
(
SInfo
)
*
appThreads
);
...
...
@@ -204,7 +204,7 @@ int main(int argc, char *argv[]) {
taosUsleep
(
1
);
}
while
(
tcount
<
appThreads
);
gettimeofday
(
&
systemTime
,
NULL
);
taosGetTimeOfDay
(
&
systemTime
);
endTime
=
systemTime
.
tv_sec
*
1000000
+
systemTime
.
tv_usec
;
float
usedTime
=
(
endTime
-
startTime
)
/
1000
.
0
f
;
// mseconds
...
...
source/os/src/osRand.c
浏览文件 @
e04ef027
...
...
@@ -33,11 +33,11 @@ uint32_t taosSafeRand(void) {
pFile
=
taosOpenFile
(
"/dev/urandom"
,
TD_FILE_READ
);
if
(
pFile
==
NULL
)
{
seed
=
(
int
)
t
ime
(
0
);
seed
=
(
int
)
t
aosGetTimestampSec
(
);
}
else
{
int
len
=
taosReadFile
(
pFile
,
&
seed
,
sizeof
(
seed
));
if
(
len
<
0
)
{
seed
=
(
int
)
t
ime
(
0
);
seed
=
(
int
)
t
aosGetTimestampSec
(
);
}
taosCloseFile
(
&
pFile
);
}
...
...
source/os/src/osStrptime.c
浏览文件 @
e04ef027
...
...
@@ -38,366 +38,368 @@
//
//#include "lukemftp.h"
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <winsock2.h>
//#define TM_YEAR_BASE 1970 //origin
#define TM_YEAR_BASE 1900 //slguan
/*
* We do not implement alternate representations. However, we always
* check whether a given modifier is allowed for a certain conversion.
*/
#define ALT_E 0x01
#define ALT_O 0x02
#define LEGAL_ALT(x) { if (alt_format & ~(x)) return (0); }
static
int
conv_num
(
const
char
**
,
int
*
,
int
,
int
);
static
const
char
*
day
[
7
]
=
{
"Sunday"
,
"Monday"
,
"Tuesday"
,
"Wednesday"
,
"Thursday"
,
"Friday"
,
"Saturday"
};
static
const
char
*
abday
[
7
]
=
{
"Sun"
,
"Mon"
,
"Tue"
,
"Wed"
,
"Thu"
,
"Fri"
,
"Sat"
};
static
const
char
*
mon
[
12
]
=
{
"January"
,
"February"
,
"March"
,
"April"
,
"May"
,
"June"
,
"July"
,
"August"
,
"September"
,
"October"
,
"November"
,
"December"
};
static
const
char
*
abmon
[
12
]
=
{
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"Jun"
,
"Jul"
,
"Aug"
,
"Sep"
,
"Oct"
,
"Nov"
,
"Dec"
};
static
const
char
*
am_pm
[
2
]
=
{
"AM"
,
"PM"
};
char
*
strptime
(
const
char
*
buf
,
const
char
*
fmt
,
struct
tm
*
tm
)
{
char
c
;
const
char
*
bp
;
size_t
len
=
0
;
int
alt_format
,
i
,
split_year
=
0
;
bp
=
buf
;
while
((
c
=
*
fmt
)
!=
'\0'
)
{
/* Clear `alternate' modifier prior to new conversion. */
alt_format
=
0
;
/* Eat up white-space. */
if
(
isspace
(
c
))
{
while
(
isspace
(
*
bp
))
bp
++
;
fmt
++
;
continue
;
}
if
((
c
=
*
fmt
++
)
!=
'%'
)
goto
literal
;
again:
switch
(
c
=
*
fmt
++
)
{
case
'%'
:
/* "%%" is converted to "%". */
literal
:
if
(
c
!=
*
bp
++
)
return
(
0
);
break
;
/*
* "Alternative" modifiers. Just set the appropriate flag
* and start over again.
*/
case
'E'
:
/* "%E?" alternative conversion modifier. */
LEGAL_ALT
(
0
);
alt_format
|=
ALT_E
;
goto
again
;
case
'O'
:
/* "%O?" alternative conversion modifier. */
LEGAL_ALT
(
0
);
alt_format
|=
ALT_O
;
goto
again
;
/*
* "Complex" conversion rules, implemented through recursion.
*/
case
'c'
:
/* Date and time, using the locale's format. */
LEGAL_ALT
(
ALT_E
);
if
(
!
(
bp
=
strptime
(
bp
,
"%x %X"
,
tm
)))
return
(
0
);
break
;
case
'D'
:
/* The date as "%m/%d/%y". */
LEGAL_ALT
(
0
);
if
(
!
(
bp
=
strptime
(
bp
,
"%m/%d/%y"
,
tm
)))
return
(
0
);
break
;
case
'R'
:
/* The time as "%H:%M". */
LEGAL_ALT
(
0
);
if
(
!
(
bp
=
strptime
(
bp
,
"%H:%M"
,
tm
)))
return
(
0
);
break
;
case
'r'
:
/* The time in 12-hour clock representation. */
LEGAL_ALT
(
0
);
if
(
!
(
bp
=
strptime
(
bp
,
"%I:%M:%S %p"
,
tm
)))
return
(
0
);
break
;
case
'T'
:
/* The time as "%H:%M:%S". */
LEGAL_ALT
(
0
);
if
(
!
(
bp
=
strptime
(
bp
,
"%H:%M:%S"
,
tm
)))
return
(
0
);
break
;
case
'X'
:
/* The time, using the locale's format. */
LEGAL_ALT
(
ALT_E
);
if
(
!
(
bp
=
strptime
(
bp
,
"%H:%M:%S"
,
tm
)))
return
(
0
);
break
;
case
'x'
:
/* The date, using the locale's format. */
LEGAL_ALT
(
ALT_E
);
if
(
!
(
bp
=
strptime
(
bp
,
"%m/%d/%y"
,
tm
)))
return
(
0
);
break
;
/*
* "Elementary" conversion rules.
*/
case
'A'
:
/* The day of week, using the locale's form. */
case
'a'
:
LEGAL_ALT
(
0
);
for
(
i
=
0
;
i
<
7
;
i
++
)
{
/* Full name. */
len
=
strlen
(
day
[
i
]);
if
(
strncmp
(
day
[
i
],
bp
,
len
)
==
0
)
break
;
/* Abbreviated name. */
len
=
strlen
(
abday
[
i
]);
if
(
strncmp
(
abday
[
i
],
bp
,
len
)
==
0
)
break
;
}
/* Nothing matched. */
if
(
i
==
7
)
return
(
0
);
tm
->
tm_wday
=
i
;
bp
+=
len
;
break
;
case
'B'
:
/* The month, using the locale's form. */
case
'b'
:
case
'h'
:
LEGAL_ALT
(
0
);
for
(
i
=
0
;
i
<
12
;
i
++
)
{
/* Full name. */
len
=
strlen
(
mon
[
i
]);
if
(
strncmp
(
mon
[
i
],
bp
,
len
)
==
0
)
break
;
/* Abbreviated name. */
len
=
strlen
(
abmon
[
i
]);
if
(
strncmp
(
abmon
[
i
],
bp
,
len
)
==
0
)
break
;
}
/* Nothing matched. */
if
(
i
==
12
)
return
(
0
);
tm
->
tm_mon
=
i
;
bp
+=
len
;
break
;
case
'C'
:
/* The century number. */
LEGAL_ALT
(
ALT_E
);
if
(
!
(
conv_num
(
&
bp
,
&
i
,
0
,
99
)))
return
(
0
);
if
(
split_year
)
{
tm
->
tm_year
=
(
tm
->
tm_year
%
100
)
+
(
i
*
100
);
}
else
{
tm
->
tm_year
=
i
*
100
;
split_year
=
1
;
}
break
;
case
'd'
:
/* The day of month. */
case
'e'
:
LEGAL_ALT
(
ALT_O
);
if
(
!
(
conv_num
(
&
bp
,
&
tm
->
tm_mday
,
1
,
31
)))
return
(
0
);
break
;
case
'k'
:
/* The hour (24-hour clock representation). */
LEGAL_ALT
(
0
);
/* FALLTHROUGH */
case
'H'
:
LEGAL_ALT
(
ALT_O
);
if
(
!
(
conv_num
(
&
bp
,
&
tm
->
tm_hour
,
0
,
23
)))
return
(
0
);
break
;
case
'l'
:
/* The hour (12-hour clock representation). */
LEGAL_ALT
(
0
);
/* FALLTHROUGH */
case
'I'
:
LEGAL_ALT
(
ALT_O
);
if
(
!
(
conv_num
(
&
bp
,
&
tm
->
tm_hour
,
1
,
12
)))
return
(
0
);
if
(
tm
->
tm_hour
==
12
)
tm
->
tm_hour
=
0
;
break
;
case
'j'
:
/* The day of year. */
LEGAL_ALT
(
0
);
if
(
!
(
conv_num
(
&
bp
,
&
i
,
1
,
366
)))
return
(
0
);
tm
->
tm_yday
=
i
-
1
;
break
;
case
'M'
:
/* The minute. */
LEGAL_ALT
(
ALT_O
);
if
(
!
(
conv_num
(
&
bp
,
&
tm
->
tm_min
,
0
,
59
)))
return
(
0
);
break
;
case
'm'
:
/* The month. */
LEGAL_ALT
(
ALT_O
);
if
(
!
(
conv_num
(
&
bp
,
&
i
,
1
,
12
)))
return
(
0
);
tm
->
tm_mon
=
i
-
1
;
break
;
case
'p'
:
/* The locale's equivalent of AM/PM. */
LEGAL_ALT
(
0
);
/* AM? */
if
(
strcmp
(
am_pm
[
0
],
bp
)
==
0
)
{
if
(
tm
->
tm_hour
>
11
)
return
(
0
);
bp
+=
strlen
(
am_pm
[
0
]);
break
;
}
/* PM? */
else
if
(
strcmp
(
am_pm
[
1
],
bp
)
==
0
)
{
if
(
tm
->
tm_hour
>
11
)
return
(
0
);
tm
->
tm_hour
+=
12
;
bp
+=
strlen
(
am_pm
[
1
]);
break
;
}
/* Nothing matched. */
return
(
0
);
case
'S'
:
/* The seconds. */
LEGAL_ALT
(
ALT_O
);
if
(
!
(
conv_num
(
&
bp
,
&
tm
->
tm_sec
,
0
,
61
)))
return
(
0
);
break
;
case
'U'
:
/* The week of year, beginning on sunday. */
case
'W'
:
/* The week of year, beginning on monday. */
LEGAL_ALT
(
ALT_O
);
/*
* XXX This is bogus, as we can not assume any valid
* information present in the tm structure at this
* point to calculate a real value, so just check the
* range for now.
*/
if
(
!
(
conv_num
(
&
bp
,
&
i
,
0
,
53
)))
return
(
0
);
break
;
case
'w'
:
/* The day of week, beginning on sunday. */
LEGAL_ALT
(
ALT_O
);
if
(
!
(
conv_num
(
&
bp
,
&
tm
->
tm_wday
,
0
,
6
)))
return
(
0
);
break
;
case
'Y'
:
/* The year. */
LEGAL_ALT
(
ALT_E
);
if
(
!
(
conv_num
(
&
bp
,
&
i
,
0
,
9999
)))
return
(
0
);
tm
->
tm_year
=
i
-
TM_YEAR_BASE
;
break
;
case
'y'
:
/* The year within 100 years of the epoch. */
LEGAL_ALT
(
ALT_E
|
ALT_O
);
if
(
!
(
conv_num
(
&
bp
,
&
i
,
0
,
99
)))
return
(
0
);
if
(
split_year
)
{
tm
->
tm_year
=
((
tm
->
tm_year
/
100
)
*
100
)
+
i
;
break
;
}
split_year
=
1
;
if
(
i
<=
68
)
tm
->
tm_year
=
i
+
2000
-
TM_YEAR_BASE
;
else
tm
->
tm_year
=
i
+
1900
-
TM_YEAR_BASE
;
break
;
/*
* Miscellaneous conversions.
*/
case
'n'
:
/* Any kind of white-space. */
case
't'
:
LEGAL_ALT
(
0
);
while
(
isspace
(
*
bp
))
bp
++
;
break
;
default:
/* Unknown/unsupported conversion. */
return
(
0
);
}
}
/* LINTED functional specification */
return
((
char
*
)
bp
);
}
static
int
conv_num
(
const
char
**
buf
,
int
*
dest
,
int
llim
,
int
ulim
)
{
int
result
=
0
;
/* The limit also determines the number of valid digits. */
int
rulim
=
ulim
;
if
(
**
buf
<
'0'
||
**
buf
>
'9'
)
return
(
0
);
do
{
result
*=
10
;
result
+=
*
(
*
buf
)
++
-
'0'
;
rulim
/=
10
;
}
while
((
result
*
10
<=
ulim
)
&&
rulim
&&
**
buf
>=
'0'
&&
**
buf
<=
'9'
);
if
(
result
<
llim
||
result
>
ulim
)
return
(
0
);
*
dest
=
result
;
return
(
1
);
}
#endif
\ No newline at end of file
// #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
// #include <time.h>
// #include <stdlib.h>
// #include <string.h>
// #include <winsock2.h>
// //#define TM_YEAR_BASE 1970 //origin
// #define TM_YEAR_BASE 1900 //slguan
// /*
// * We do not implement alternate representations. However, we always
// * check whether a given modifier is allowed for a certain conversion.
// */
// #define ALT_E 0x01
// #define ALT_O 0x02
// #define LEGAL_ALT(x) { if (alt_format & ~(x)) return (0); }
// static int conv_num(const char **buf, int *dest, int llim, int ulim)
// {
// int result = 0;
// /* The limit also determines the number of valid digits. */
// int rulim = ulim;
// if (**buf < '0' || **buf > '9')
// return (0);
// do {
// result *= 10;
// result += *(*buf)++ - '0';
// rulim /= 10;
// } while ((result * 10 <= ulim) && rulim && **buf >= '0' && **buf <= '9');
// if (result < llim || result > ulim)
// return (0);
// *dest = result;
// return (1);
// }
// static const char *day[7] = {
// "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
// "Friday", "Saturday"
// };
// static const char *abday[7] = {
// "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
// };
// static const char *mon[12] = {
// "January", "February", "March", "April", "May", "June", "July",
// "August", "September", "October", "November", "December"
// };
// static const char *abmon[12] = {
// "Jan", "Feb", "Mar", "Apr", "May", "Jun",
// "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
// };
// static const char *am_pm[2] = {
// "AM", "PM"
// };
// #endif
// char *taosStrpTime(const char *buf, const char *fmt, struct tm *tm) {
// #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
// char c;
// const char *bp;
// size_t len = 0;
// int alt_format, i, split_year = 0;
// bp = buf;
// while ((c = *fmt) != '\0') {
// /* Clear `alternate' modifier prior to new conversion. */
// alt_format = 0;
// /* Eat up white-space. */
// if (isspace(c)) {
// while (isspace(*bp))
// bp++;
// fmt++;
// continue;
// }
// if ((c = *fmt++) != '%')
// goto literal;
// again: switch (c = *fmt++) {
// case '%': /* "%%" is converted to "%". */
// literal :
// if (c != *bp++)
// return (0);
// break;
// /*
// * "Alternative" modifiers. Just set the appropriate flag
// * and start over again.
// */
// case 'E': /* "%E?" alternative conversion modifier. */
// LEGAL_ALT(0);
// alt_format |= ALT_E;
// goto again;
// case 'O': /* "%O?" alternative conversion modifier. */
// LEGAL_ALT(0);
// alt_format |= ALT_O;
// goto again;
// /*
// * "Complex" conversion rules, implemented through recursion.
// */
// case 'c': /* Date and time, using the locale's format. */
// LEGAL_ALT(ALT_E);
// if (!(bp = taosStrpTime(bp, "%x %X", tm)))
// return (0);
// break;
// case 'D': /* The date as "%m/%d/%y". */
// LEGAL_ALT(0);
// if (!(bp = taosStrpTime(bp, "%m/%d/%y", tm)))
// return (0);
// break;
// case 'R': /* The time as "%H:%M". */
// LEGAL_ALT(0);
// if (!(bp = taosStrpTime(bp, "%H:%M", tm)))
// return (0);
// break;
// case 'r': /* The time in 12-hour clock representation. */
// LEGAL_ALT(0);
// if (!(bp = taosStrpTime(bp, "%I:%M:%S %p", tm)))
// return (0);
// break;
// case 'T': /* The time as "%H:%M:%S". */
// LEGAL_ALT(0);
// if (!(bp = taosStrpTime(bp, "%H:%M:%S", tm)))
// return (0);
// break;
// case 'X': /* The time, using the locale's format. */
// LEGAL_ALT(ALT_E);
// if (!(bp = taosStrpTime(bp, "%H:%M:%S", tm)))
// return (0);
// break;
// case 'x': /* The date, using the locale's format. */
// LEGAL_ALT(ALT_E);
// if (!(bp = taosStrpTime(bp, "%m/%d/%y", tm)))
// return (0);
// break;
// /*
// * "Elementary" conversion rules.
// */
// case 'A': /* The day of week, using the locale's form. */
// case 'a':
// LEGAL_ALT(0);
// for (i = 0; i < 7; i++) {
// /* Full name. */
// len = strlen(day[i]);
// if (strncmp(day[i], bp, len) == 0)
// break;
// /* Abbreviated name. */
// len = strlen(abday[i]);
// if (strncmp(abday[i], bp, len) == 0)
// break;
// }
// /* Nothing matched. */
// if (i == 7)
// return (0);
// tm->tm_wday = i;
// bp += len;
// break;
// case 'B': /* The month, using the locale's form. */
// case 'b':
// case 'h':
// LEGAL_ALT(0);
// for (i = 0; i < 12; i++) {
// /* Full name. */
// len = strlen(mon[i]);
// if (strncmp(mon[i], bp, len) == 0)
// break;
// /* Abbreviated name. */
// len = strlen(abmon[i]);
// if (strncmp(abmon[i], bp, len) == 0)
// break;
// }
// /* Nothing matched. */
// if (i == 12)
// return (0);
// tm->tm_mon = i;
// bp += len;
// break;
// case 'C': /* The century number. */
// LEGAL_ALT(ALT_E);
// if (!(conv_num(&bp, &i, 0, 99)))
// return (0);
// if (split_year) {
// tm->tm_year = (tm->tm_year % 100) + (i * 100);
// }
// else {
// tm->tm_year = i * 100;
// split_year = 1;
// }
// break;
// case 'd': /* The day of month. */
// case 'e':
// LEGAL_ALT(ALT_O);
// if (!(conv_num(&bp, &tm->tm_mday, 1, 31)))
// return (0);
// break;
// case 'k': /* The hour (24-hour clock representation). */
// LEGAL_ALT(0);
// /* FALLTHROUGH */
// case 'H':
// LEGAL_ALT(ALT_O);
// if (!(conv_num(&bp, &tm->tm_hour, 0, 23)))
// return (0);
// break;
// case 'l': /* The hour (12-hour clock representation). */
// LEGAL_ALT(0);
// /* FALLTHROUGH */
// case 'I':
// LEGAL_ALT(ALT_O);
// if (!(conv_num(&bp, &tm->tm_hour, 1, 12)))
// return (0);
// if (tm->tm_hour == 12)
// tm->tm_hour = 0;
// break;
// case 'j': /* The day of year. */
// LEGAL_ALT(0);
// if (!(conv_num(&bp, &i, 1, 366)))
// return (0);
// tm->tm_yday = i - 1;
// break;
// case 'M': /* The minute. */
// LEGAL_ALT(ALT_O);
// if (!(conv_num(&bp, &tm->tm_min, 0, 59)))
// return (0);
// break;
// case 'm': /* The month. */
// LEGAL_ALT(ALT_O);
// if (!(conv_num(&bp, &i, 1, 12)))
// return (0);
// tm->tm_mon = i - 1;
// break;
// case 'p': /* The locale's equivalent of AM/PM. */
// LEGAL_ALT(0);
// /* AM? */
// if (strcmp(am_pm[0], bp) == 0) {
// if (tm->tm_hour > 11)
// return (0);
// bp += strlen(am_pm[0]);
// break;
// }
// /* PM? */
// else if (strcmp(am_pm[1], bp) == 0) {
// if (tm->tm_hour > 11)
// return (0);
// tm->tm_hour += 12;
// bp += strlen(am_pm[1]);
// break;
// }
// /* Nothing matched. */
// return (0);
// case 'S': /* The seconds. */
// LEGAL_ALT(ALT_O);
// if (!(conv_num(&bp, &tm->tm_sec, 0, 61)))
// return (0);
// break;
// case 'U': /* The week of year, beginning on sunday. */
// case 'W': /* The week of year, beginning on monday. */
// LEGAL_ALT(ALT_O);
// /*
// * XXX This is bogus, as we can not assume any valid
// * information present in the tm structure at this
// * point to calculate a real value, so just check the
// * range for now.
// */
// if (!(conv_num(&bp, &i, 0, 53)))
// return (0);
// break;
// case 'w': /* The day of week, beginning on sunday. */
// LEGAL_ALT(ALT_O);
// if (!(conv_num(&bp, &tm->tm_wday, 0, 6)))
// return (0);
// break;
// case 'Y': /* The year. */
// LEGAL_ALT(ALT_E);
// if (!(conv_num(&bp, &i, 0, 9999)))
// return (0);
// tm->tm_year = i - TM_YEAR_BASE;
// break;
// case 'y': /* The year within 100 years of the epoch. */
// LEGAL_ALT(ALT_E | ALT_O);
// if (!(conv_num(&bp, &i, 0, 99)))
// return (0);
// if (split_year) {
// tm->tm_year = ((tm->tm_year / 100) * 100) + i;
// break;
// }
// split_year = 1;
// if (i <= 68)
// tm->tm_year = i + 2000 - TM_YEAR_BASE;
// else
// tm->tm_year = i + 1900 - TM_YEAR_BASE;
// break;
// /*
// * Miscellaneous conversions.
// */
// case 'n': /* Any kind of white-space. */
// case 't':
// LEGAL_ALT(0);
// while (isspace(*bp))
// bp++;
// break;
// default: /* Unknown/unsupported conversion. */
// return (0);
// }
// }
// /* LINTED functional specification */
// return ((char *)bp);
// #elif defined(_TD_DARWIN_64)
// return strptime(buf, fmt, tm);
// #else
// return strptime(buf, fmt, tm);
// #endif
// }
source/os/src/osTime.c
浏览文件 @
e04ef027
...
...
@@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define ALLOW_FORBID_FUNC
#define _BSD_SOURCE
#ifdef DARWIN
...
...
@@ -26,16 +27,373 @@
#include "os.h"
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
/*
* windows implementation
*/
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <winsock2.h>
//#define TM_YEAR_BASE 1970 //origin
#define TM_YEAR_BASE 1900 //slguan
/*
* We do not implement alternate representations. However, we always
* check whether a given modifier is allowed for a certain conversion.
*/
#define ALT_E 0x01
#define ALT_O 0x02
#define LEGAL_ALT(x) { if (alt_format & ~(x)) return (0); }
static
int
conv_num
(
const
char
**
buf
,
int
*
dest
,
int
llim
,
int
ulim
)
{
int
result
=
0
;
/* The limit also determines the number of valid digits. */
int
rulim
=
ulim
;
if
(
**
buf
<
'0'
||
**
buf
>
'9'
)
return
(
0
);
do
{
result
*=
10
;
result
+=
*
(
*
buf
)
++
-
'0'
;
rulim
/=
10
;
}
while
((
result
*
10
<=
ulim
)
&&
rulim
&&
**
buf
>=
'0'
&&
**
buf
<=
'9'
);
if
(
result
<
llim
||
result
>
ulim
)
return
(
0
);
*
dest
=
result
;
return
(
1
);
}
static
const
char
*
day
[
7
]
=
{
"Sunday"
,
"Monday"
,
"Tuesday"
,
"Wednesday"
,
"Thursday"
,
"Friday"
,
"Saturday"
};
static
const
char
*
abday
[
7
]
=
{
"Sun"
,
"Mon"
,
"Tue"
,
"Wed"
,
"Thu"
,
"Fri"
,
"Sat"
};
static
const
char
*
mon
[
12
]
=
{
"January"
,
"February"
,
"March"
,
"April"
,
"May"
,
"June"
,
"July"
,
"August"
,
"September"
,
"October"
,
"November"
,
"December"
};
static
const
char
*
abmon
[
12
]
=
{
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"Jun"
,
"Jul"
,
"Aug"
,
"Sep"
,
"Oct"
,
"Nov"
,
"Dec"
};
static
const
char
*
am_pm
[
2
]
=
{
"AM"
,
"PM"
};
#else
#include <sys/time.h>
#endif
char
*
taosStrpTime
(
const
char
*
buf
,
const
char
*
fmt
,
struct
tm
*
tm
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
char
c
;
const
char
*
bp
;
size_t
len
=
0
;
int
alt_format
,
i
,
split_year
=
0
;
bp
=
buf
;
while
((
c
=
*
fmt
)
!=
'\0'
)
{
/* Clear `alternate' modifier prior to new conversion. */
alt_format
=
0
;
/* Eat up white-space. */
if
(
isspace
(
c
))
{
while
(
isspace
(
*
bp
))
bp
++
;
fmt
++
;
continue
;
}
if
((
c
=
*
fmt
++
)
!=
'%'
)
goto
literal
;
again:
switch
(
c
=
*
fmt
++
)
{
case
'%'
:
/* "%%" is converted to "%". */
literal
:
if
(
c
!=
*
bp
++
)
return
(
0
);
break
;
/*
* "Alternative" modifiers. Just set the appropriate flag
* and start over again.
*/
case
'E'
:
/* "%E?" alternative conversion modifier. */
LEGAL_ALT
(
0
);
alt_format
|=
ALT_E
;
goto
again
;
case
'O'
:
/* "%O?" alternative conversion modifier. */
LEGAL_ALT
(
0
);
alt_format
|=
ALT_O
;
goto
again
;
/*
* "Complex" conversion rules, implemented through recursion.
*/
case
'c'
:
/* Date and time, using the locale's format. */
LEGAL_ALT
(
ALT_E
);
if
(
!
(
bp
=
taosStrpTime
(
bp
,
"%x %X"
,
tm
)))
return
(
0
);
break
;
case
'D'
:
/* The date as "%m/%d/%y". */
LEGAL_ALT
(
0
);
if
(
!
(
bp
=
taosStrpTime
(
bp
,
"%m/%d/%y"
,
tm
)))
return
(
0
);
break
;
case
'R'
:
/* The time as "%H:%M". */
LEGAL_ALT
(
0
);
if
(
!
(
bp
=
taosStrpTime
(
bp
,
"%H:%M"
,
tm
)))
return
(
0
);
break
;
case
'r'
:
/* The time in 12-hour clock representation. */
LEGAL_ALT
(
0
);
if
(
!
(
bp
=
taosStrpTime
(
bp
,
"%I:%M:%S %p"
,
tm
)))
return
(
0
);
break
;
case
'T'
:
/* The time as "%H:%M:%S". */
LEGAL_ALT
(
0
);
if
(
!
(
bp
=
taosStrpTime
(
bp
,
"%H:%M:%S"
,
tm
)))
return
(
0
);
break
;
case
'X'
:
/* The time, using the locale's format. */
LEGAL_ALT
(
ALT_E
);
if
(
!
(
bp
=
taosStrpTime
(
bp
,
"%H:%M:%S"
,
tm
)))
return
(
0
);
break
;
case
'x'
:
/* The date, using the locale's format. */
LEGAL_ALT
(
ALT_E
);
if
(
!
(
bp
=
taosStrpTime
(
bp
,
"%m/%d/%y"
,
tm
)))
return
(
0
);
break
;
/*
* "Elementary" conversion rules.
*/
case
'A'
:
/* The day of week, using the locale's form. */
case
'a'
:
LEGAL_ALT
(
0
);
for
(
i
=
0
;
i
<
7
;
i
++
)
{
/* Full name. */
len
=
strlen
(
day
[
i
]);
if
(
strncmp
(
day
[
i
],
bp
,
len
)
==
0
)
break
;
/* Abbreviated name. */
len
=
strlen
(
abday
[
i
]);
if
(
strncmp
(
abday
[
i
],
bp
,
len
)
==
0
)
break
;
}
/* Nothing matched. */
if
(
i
==
7
)
return
(
0
);
tm
->
tm_wday
=
i
;
bp
+=
len
;
break
;
case
'B'
:
/* The month, using the locale's form. */
case
'b'
:
case
'h'
:
LEGAL_ALT
(
0
);
for
(
i
=
0
;
i
<
12
;
i
++
)
{
/* Full name. */
len
=
strlen
(
mon
[
i
]);
if
(
strncmp
(
mon
[
i
],
bp
,
len
)
==
0
)
break
;
/* Abbreviated name. */
len
=
strlen
(
abmon
[
i
]);
if
(
strncmp
(
abmon
[
i
],
bp
,
len
)
==
0
)
break
;
}
/* Nothing matched. */
if
(
i
==
12
)
return
(
0
);
tm
->
tm_mon
=
i
;
bp
+=
len
;
break
;
case
'C'
:
/* The century number. */
LEGAL_ALT
(
ALT_E
);
if
(
!
(
conv_num
(
&
bp
,
&
i
,
0
,
99
)))
return
(
0
);
if
(
split_year
)
{
tm
->
tm_year
=
(
tm
->
tm_year
%
100
)
+
(
i
*
100
);
}
else
{
tm
->
tm_year
=
i
*
100
;
split_year
=
1
;
}
break
;
case
'd'
:
/* The day of month. */
case
'e'
:
LEGAL_ALT
(
ALT_O
);
if
(
!
(
conv_num
(
&
bp
,
&
tm
->
tm_mday
,
1
,
31
)))
return
(
0
);
break
;
int
taosGetTimeOfDay
(
struct
timeval
*
tv
,
struct
timezone
*
tz
)
{
case
'k'
:
/* The hour (24-hour clock representation). */
LEGAL_ALT
(
0
);
/* FALLTHROUGH */
case
'H'
:
LEGAL_ALT
(
ALT_O
);
if
(
!
(
conv_num
(
&
bp
,
&
tm
->
tm_hour
,
0
,
23
)))
return
(
0
);
break
;
case
'l'
:
/* The hour (12-hour clock representation). */
LEGAL_ALT
(
0
);
/* FALLTHROUGH */
case
'I'
:
LEGAL_ALT
(
ALT_O
);
if
(
!
(
conv_num
(
&
bp
,
&
tm
->
tm_hour
,
1
,
12
)))
return
(
0
);
if
(
tm
->
tm_hour
==
12
)
tm
->
tm_hour
=
0
;
break
;
case
'j'
:
/* The day of year. */
LEGAL_ALT
(
0
);
if
(
!
(
conv_num
(
&
bp
,
&
i
,
1
,
366
)))
return
(
0
);
tm
->
tm_yday
=
i
-
1
;
break
;
case
'M'
:
/* The minute. */
LEGAL_ALT
(
ALT_O
);
if
(
!
(
conv_num
(
&
bp
,
&
tm
->
tm_min
,
0
,
59
)))
return
(
0
);
break
;
case
'm'
:
/* The month. */
LEGAL_ALT
(
ALT_O
);
if
(
!
(
conv_num
(
&
bp
,
&
i
,
1
,
12
)))
return
(
0
);
tm
->
tm_mon
=
i
-
1
;
break
;
case
'p'
:
/* The locale's equivalent of AM/PM. */
LEGAL_ALT
(
0
);
/* AM? */
if
(
strcmp
(
am_pm
[
0
],
bp
)
==
0
)
{
if
(
tm
->
tm_hour
>
11
)
return
(
0
);
bp
+=
strlen
(
am_pm
[
0
]);
break
;
}
/* PM? */
else
if
(
strcmp
(
am_pm
[
1
],
bp
)
==
0
)
{
if
(
tm
->
tm_hour
>
11
)
return
(
0
);
tm
->
tm_hour
+=
12
;
bp
+=
strlen
(
am_pm
[
1
]);
break
;
}
/* Nothing matched. */
return
(
0
);
case
'S'
:
/* The seconds. */
LEGAL_ALT
(
ALT_O
);
if
(
!
(
conv_num
(
&
bp
,
&
tm
->
tm_sec
,
0
,
61
)))
return
(
0
);
break
;
case
'U'
:
/* The week of year, beginning on sunday. */
case
'W'
:
/* The week of year, beginning on monday. */
LEGAL_ALT
(
ALT_O
);
/*
* XXX This is bogus, as we can not assume any valid
* information present in the tm structure at this
* point to calculate a real value, so just check the
* range for now.
*/
if
(
!
(
conv_num
(
&
bp
,
&
i
,
0
,
53
)))
return
(
0
);
break
;
case
'w'
:
/* The day of week, beginning on sunday. */
LEGAL_ALT
(
ALT_O
);
if
(
!
(
conv_num
(
&
bp
,
&
tm
->
tm_wday
,
0
,
6
)))
return
(
0
);
break
;
case
'Y'
:
/* The year. */
LEGAL_ALT
(
ALT_E
);
if
(
!
(
conv_num
(
&
bp
,
&
i
,
0
,
9999
)))
return
(
0
);
tm
->
tm_year
=
i
-
TM_YEAR_BASE
;
break
;
case
'y'
:
/* The year within 100 years of the epoch. */
LEGAL_ALT
(
ALT_E
|
ALT_O
);
if
(
!
(
conv_num
(
&
bp
,
&
i
,
0
,
99
)))
return
(
0
);
if
(
split_year
)
{
tm
->
tm_year
=
((
tm
->
tm_year
/
100
)
*
100
)
+
i
;
break
;
}
split_year
=
1
;
if
(
i
<=
68
)
tm
->
tm_year
=
i
+
2000
-
TM_YEAR_BASE
;
else
tm
->
tm_year
=
i
+
1900
-
TM_YEAR_BASE
;
break
;
/*
* Miscellaneous conversions.
*/
case
'n'
:
/* Any kind of white-space. */
case
't'
:
LEGAL_ALT
(
0
);
while
(
isspace
(
*
bp
))
bp
++
;
break
;
default:
/* Unknown/unsupported conversion. */
return
(
0
);
}
}
/* LINTED functional specification */
return
((
char
*
)
bp
);
#else
return
strptime
(
buf
,
fmt
,
tm
);
#endif
}
FORCE_INLINE
int32_t
taosGetTimeOfDay
(
struct
timeval
*
tv
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
time_t
t
;
t
=
t
ime
(
NULL
);
t
=
t
aosGetTimestampSec
(
);
SYSTEMTIME
st
;
GetLocalTime
(
&
st
);
...
...
@@ -43,26 +401,18 @@ int taosGetTimeOfDay(struct timeval *tv, struct timezone *tz) {
tv
->
tv_usec
=
st
.
wMilliseconds
*
1000
;
return
0
;
#else
return
gettimeofday
(
tv
,
NULL
);
#endif
}
struct
tm
*
localtime_r
(
const
time_t
*
timep
,
struct
tm
*
result
)
{
struct
tm
*
taosLocalTime
(
const
time_t
*
timep
,
struct
tm
*
result
)
{
#if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32)
localtime_s
(
result
,
timep
);
return
result
;
}
#else
/*
* linux and darwin implementation
*/
#include <sys/time.h>
// #include "monotonic.h"
FORCE_INLINE
int32_t
taosGetTimeOfDay
(
struct
timeval
*
tv
)
{
return
gettimeofday
(
tv
,
NULL
);
localtime_r
(
timep
,
result
);
#endif
return
result
;
}
int32_t
taosGetTimestampSec
()
{
return
(
int32_t
)
time
(
NULL
);
}
#endif
source/os/src/osTimezone.c
浏览文件 @
e04ef027
...
...
@@ -128,9 +128,9 @@ void taosGetSystemTimezone(char *outTimezone) {
* Enforce set the correct daylight saving time(DST) flag according
* to current time
*/
time_t
tx1
=
t
ime
(
NULL
);
time_t
tx1
=
t
aosGetTimestampSec
(
);
struct
tm
tm1
;
localtime_r
(
&
tx1
,
&
tm1
);
taosLocalTime
(
&
tx1
,
&
tm1
);
/*
* format example:
...
...
@@ -147,9 +147,9 @@ void taosGetSystemTimezone(char *outTimezone) {
* Enforce set the correct daylight saving time(DST) flag according
* to current time
*/
time_t
tx1
=
t
ime
(
NULL
);
time_t
tx1
=
t
aosGetTimestampSec
(
);
struct
tm
tm1
;
localtime_r
(
&
tx1
,
&
tm1
);
taosLocalTime
(
&
tx1
,
&
tm1
);
/* load time zone string from /etc/timezone */
// FILE *f = fopen("/etc/timezone", "r");
...
...
source/util/src/tdes.c
浏览文件 @
e04ef027
...
...
@@ -31,7 +31,7 @@ void process_message(uint8_t* message_piece, uint8_t* processed_piece, key_set*
#if 0
int64_t taosDesGenKey() {
uint32_t iseed = (uint32_t)t
ime(NULL
);
uint32_t iseed = (uint32_t)t
aosGetTimestampSec(
);
taosSeedRand(iseed);
uint8_t key[8] = {0};
...
...
source/util/src/tlog.c
浏览文件 @
e04ef027
...
...
@@ -401,7 +401,7 @@ static inline int32_t taosBuildLogHead(char *buffer, const char *flags) {
taosGetTimeOfDay
(
&
timeSecs
);
time_t
curTime
=
timeSecs
.
tv_sec
;
ptm
=
localtime_r
(
&
curTime
,
&
Tm
);
ptm
=
taosLocalTime
(
&
curTime
,
&
Tm
);
return
sprintf
(
buffer
,
"%02d/%02d %02d:%02d:%02d.%06d %08"
PRId64
" %s"
,
ptm
->
tm_mon
+
1
,
ptm
->
tm_mday
,
ptm
->
tm_hour
,
ptm
->
tm_min
,
ptm
->
tm_sec
,
(
int32_t
)
timeSecs
.
tv_usec
,
taosGetSelfPthreadId
(),
flags
);
...
...
source/util/src/tskiplist.c
浏览文件 @
e04ef027
...
...
@@ -82,7 +82,7 @@ SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, _
}
}
taosSeedRand
((
uint32_t
)
t
ime
(
NULL
));
taosSeedRand
((
uint32_t
)
t
aosGetTimestampSec
(
));
#if SKIP_LIST_RECORD_PERFORMANCE
pSkipList
->
state
.
nTotalMemSize
+=
sizeof
(
SSkipList
);
...
...
source/util/test/codingTests.cpp
浏览文件 @
e04ef027
...
...
@@ -150,7 +150,7 @@ static bool test_variant_int64(int64_t value) {
}
TEST
(
codingTest
,
fixed_encode_decode
)
{
taosSeedRand
(
t
ime
(
0
));
taosSeedRand
(
t
aosGetTimestampSec
(
));
// uint16_t
for
(
uint16_t
value
=
0
;
value
<=
UINT16_MAX
;
value
++
)
{
...
...
@@ -204,7 +204,7 @@ TEST(codingTest, fixed_encode_decode) {
}
TEST
(
codingTest
,
variant_encode_decode
)
{
taosSeedRand
(
t
ime
(
0
));
taosSeedRand
(
t
aosGetTimestampSec
(
));
// uint16_t
for
(
uint16_t
value
=
0
;
value
<=
UINT16_MAX
;
value
++
)
{
...
...
source/util/test/pageBufferTest.cpp
浏览文件 @
e04ef027
...
...
@@ -161,7 +161,7 @@ void recyclePageTest() {
TEST
(
testCase
,
resultBufferTest
)
{
taosSeedRand
(
t
ime
(
NULL
));
taosSeedRand
(
t
aosGetTimestampSec
(
));
simpleTest
();
writeDownTest
();
recyclePageTest
();
...
...
source/util/test/skiplistTest.cpp
浏览文件 @
e04ef027
...
...
@@ -74,7 +74,7 @@ void randKeyTest() {
false, getkey);
int32_t size = 200000;
taosSeedRand(t
ime(NULL
));
taosSeedRand(t
aosGetTimestampSec(
));
printf("generated %d keys is: \n", size);
...
...
@@ -337,7 +337,7 @@ void duplicatedKeyTest() {
TEST(testCase, skiplist_test) {
assert(sizeof(SSkipListKey) == 8);
taosSeedRand(t
ime(NULL
));
taosSeedRand(t
aosGetTimestampSec(
));
stringKeySkiplistTest();
doubleSkipListTest();
...
...
tests/script/api/batchprepare.c
浏览文件 @
e04ef027
...
...
@@ -18,7 +18,7 @@ void taosMsleep(int mseconds);
unsigned
long
long
getCurrentTime
(){
struct
timeval
tv
;
if
(
gettimeofday
(
&
tv
,
NULL
)
!=
0
)
{
if
(
taosGetTimeOfDay
(
&
tv
)
!=
0
)
{
perror
(
"Failed to get current time in ms"
);
exit
(
EXIT_FAILURE
);
}
...
...
tests/script/api/stmtBatchTest.c
浏览文件 @
e04ef027
...
...
@@ -42,7 +42,7 @@ int g_runTimes = 5;
unsigned
long
long
getCurrentTime
(){
struct
timeval
tv
;
if
(
gettimeofday
(
&
tv
,
NULL
)
!=
0
)
{
if
(
taosGetTimeOfDay
(
&
tv
)
!=
0
)
{
perror
(
"Failed to get current time in ms"
);
exit
(
EXIT_FAILURE
);
}
...
...
tests/test/c/tmqDemo.c
浏览文件 @
e04ef027
...
...
@@ -609,7 +609,7 @@ void printParaIntoFile() {
};
g_fp
=
pFile
;
time_t
tTime
=
t
ime
(
NULL
);
time_t
tTime
=
t
aosGetTimestampSec
(
);
struct
tm
tm
=
*
localtime
(
&
tTime
);
taosFprintfFile
(
pFile
,
"###################################################################
\n
"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录