Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wwsmg1
rt-thread
提交
f4015029
R
rt-thread
项目概览
wwsmg1
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f4015029
编写于
5月 01, 2021
作者:
mysterywolf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
gettimeofday()函数支持时区;规范set_timeval/get_timeval函数返回值
上级
6d575153
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
32 addition
and
25 deletion
+32
-25
components/libc/compilers/common/time.c
components/libc/compilers/common/time.c
+32
-25
未找到文件。
components/libc/compilers/common/time.c
浏览文件 @
f4015029
...
...
@@ -17,6 +17,7 @@
* which found by Rob <rdent@iinet.net.au>
* 2021-02-12 Meco Man move all of the functions located in <clock_time.c> to this file
* 2021-03-15 Meco Man fixed a bug of leaking memory in asctime()
* 2021-05-01 Meco Man support fixed timezone
*/
#include <sys/time.h>
...
...
@@ -73,18 +74,18 @@ static void num2str(char *c, int i)
}
/**
* Get time from RTC device (without timezone)
* Get time from RTC device (without timezone
, UTC+0
)
* @param tv: struct timeval
* @return
-1 failure; 1 success
* @return
the operation status, RT_EOK on successful
*/
static
in
t
get_timeval
(
struct
timeval
*
tv
)
static
rt_err_
t
get_timeval
(
struct
timeval
*
tv
)
{
#ifdef RT_USING_RTC
static
rt_device_t
device
=
RT_NULL
;
rt_err_t
rst
=
-
RT_ERROR
;
if
(
tv
==
RT_NULL
)
return
-
1
;
return
-
RT_EINVAL
;
/* default is 0 */
tv
->
tv_sec
=
0
;
...
...
@@ -110,22 +111,22 @@ static int get_timeval(struct timeval *tv)
{
/* LOG_W will cause a recursive printing if ulog timestamp function is enabled */
rt_kprintf
(
"Cannot find a RTC device to provide time!
\r\n
"
);
return
-
1
;
return
-
RT_ENOSYS
;
}
return
(
rst
<
0
)
?
-
1
:
1
;
return
rst
;
#else
/* LOG_W will cause a recursive printing if ulog timestamp function is enabled */
rt_kprintf
(
"Cannot find a RTC device to provide time!
\r\n
"
);
return
-
1
;
return
-
RT_ENOSYS
;
#endif
/* RT_USING_RTC */
}
/**
* Set time to RTC device (without timezone)
* @param tv: struct timeval
* @return
-1 failure; 1 success
* @return
the operation status, RT_EOK on successful
*/
static
int
set_timeval
(
struct
timeval
*
tv
)
{
...
...
@@ -134,7 +135,7 @@ static int set_timeval(struct timeval *tv)
rt_err_t
rst
=
-
RT_ERROR
;
if
(
tv
==
RT_NULL
)
return
-
1
;
return
-
RT_EINVAL
;
/* optimization: find rtc device only first */
if
(
device
==
RT_NULL
)
...
...
@@ -155,14 +156,14 @@ static int set_timeval(struct timeval *tv)
else
{
LOG_W
(
"Cannot find a RTC device to provide time!"
);
return
-
1
;
return
-
RT_ENOSYS
;
}
return
(
rst
<
0
)
?
-
1
:
1
;
return
rst
;
#else
LOG_W
(
"Cannot find a RTC device to provide time!"
);
return
-
1
;
return
-
RT_ENOSYS
;
#endif
/* RT_USING_RTC */
}
...
...
@@ -294,7 +295,7 @@ RT_WEAK time_t time(time_t *t)
{
struct
timeval
now
;
if
(
get_timeval
(
&
now
)
>
0
)
if
(
get_timeval
(
&
now
)
==
RT_EOK
)
{
if
(
t
)
{
...
...
@@ -304,7 +305,7 @@ RT_WEAK time_t time(time_t *t)
}
else
{
errno
=
EFAULT
;
rt_set_errno
(
EFAULT
)
;
return
((
time_t
)
-
1
);
}
}
...
...
@@ -322,18 +323,18 @@ int stime(const time_t *t)
if
(
!
t
)
{
errno
=
EFAULT
;
rt_set_errno
(
EFAULT
)
;
return
-
1
;
}
tv
.
tv_sec
=
*
t
;
if
(
set_timeval
(
&
tv
)
>
0
)
if
(
set_timeval
(
&
tv
)
==
RT_EOK
)
{
return
0
;
}
else
{
errno
=
EFAULT
;
rt_set_errno
(
EFAULT
)
;
return
-
1
;
}
}
...
...
@@ -414,47 +415,53 @@ time_t timegm(struct tm * const t)
}
RTM_EXPORT
(
timegm
);
/* TODO:
timezon
e */
/* TODO:
Daylight Saving Tim
e */
int
gettimeofday
(
struct
timeval
*
tv
,
struct
timezone
*
tz
)
{
if
(
tv
!=
RT_NULL
&&
get_timeval
(
tv
)
>
0
)
if
(
tz
!=
RT_NULL
)
{
tz
->
tz_dsttime
=
0
;
tz
->
tz_minuteswest
=
-
(
RT_LIBC_FIXED_TIMEZONE
*
60
);
}
if
(
tv
!=
RT_NULL
&&
get_timeval
(
tv
)
==
RT_EOK
)
{
return
0
;
}
else
{
errno
=
EFAULT
;
rt_set_errno
(
EFAULT
)
;
return
-
1
;
}
}
RTM_EXPORT
(
gettimeofday
);
/* TODO:
timezon
e */
/* TODO:
Daylight Saving Tim
e */
int
settimeofday
(
const
struct
timeval
*
tv
,
const
struct
timezone
*
tz
)
{
if
(
tv
!=
RT_NULL
)
{
if
(
tv
->
tv_sec
>=
0
&&
tv
->
tv_usec
>=
0
)
{
if
(
set_timeval
((
struct
timeval
*
)
tv
)
>
0
)
if
(
set_timeval
((
struct
timeval
*
)
tv
)
==
RT_EOK
)
{
return
0
;
}
else
{
errno
=
EFAULT
;
rt_set_errno
(
EFAULT
)
;
return
-
1
;
}
}
else
{
errno
=
EINVAL
;
rt_set_errno
(
EINVAL
)
;
return
-
1
;
}
}
else
{
errno
=
EFAULT
;
rt_set_errno
(
EFAULT
)
;
return
-
1
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录