Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
RT-Thread
rt-thread
提交
c4154104
R
rt-thread
项目概览
RT-Thread
/
rt-thread
大约 1 年 前同步成功
通知
774
Star
8911
Fork
4735
代码
文件
提交
分支
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,发现更多精彩内容 >>
未验证
提交
c4154104
编写于
5月 06, 2021
作者:
B
Bernard Xiong
提交者:
GitHub
5月 06, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4654 from mysterywolf/timezone
[libc][time]优化gettimeofday/settimeofday; 规范set_timeval/get_timeval函数返回值
上级
ed900427
8fee8d2c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
56 addition
and
42 deletion
+56
-42
components/libc/compilers/common/sys/mman.h
components/libc/compilers/common/sys/mman.h
+1
-1
components/libc/compilers/common/sys/time.h
components/libc/compilers/common/sys/time.h
+12
-0
components/libc/compilers/common/time.c
components/libc/compilers/common/time.c
+43
-41
未找到文件。
components/libc/compilers/common/sys/mman.h
浏览文件 @
c4154104
...
...
@@ -16,7 +16,7 @@ extern "C" {
#endif
#include <sys/types.h>
#define MAP_FAILED ((void *) -1)
#define MAP_SHARED 0x01
...
...
components/libc/compilers/common/sys/time.h
浏览文件 @
c4154104
...
...
@@ -18,6 +18,18 @@
extern
"C"
{
#endif
#define DST_NONE 0
/* not on dst */
#define DST_USA 1
/* USA style dst */
#define DST_AUST 2
/* Australian style dst */
#define DST_WET 3
/* Western European dst */
#define DST_MET 4
/* Middle European dst */
#define DST_EET 5
/* Eastern European dst */
#define DST_CAN 6
/* Canada */
#define DST_GB 7
/* Great Britain and Eire */
#define DST_RUM 8
/* Rumania */
#define DST_TUR 9
/* Turkey */
#define DST_AUSTALT 10
/* Australian style with shift in 1986 */
#ifndef _TIMEVAL_DEFINED
#define _TIMEVAL_DEFINED
/*
...
...
components/libc/compilers/common/time.c
浏览文件 @
c4154104
...
...
@@ -17,9 +17,10 @@
* 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>
#include
"sys/time.h"
#include <rtthread.h>
#ifdef RT_USING_DEVICE
...
...
@@ -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,48 @@ time_t timegm(struct tm * const t)
}
RTM_EXPORT
(
timegm
);
/* TODO: timezone */
int
gettimeofday
(
struct
timeval
*
tv
,
struct
timezone
*
tz
)
{
if
(
tv
!=
RT_NULL
&&
get_timeval
(
tv
)
>
0
)
/* The use of the timezone structure is obsolete;
* the tz argument should normally be specified as NULL.
* The tz_dsttime field has never been used under Linux.
* Thus, the following is purely of historic interest.
*/
if
(
tz
!=
RT_NULL
)
{
tz
->
tz_dsttime
=
DST_NONE
;
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: timezone */
int
settimeofday
(
const
struct
timeval
*
tv
,
const
struct
timezone
*
tz
)
{
if
(
tv
!=
RT_NULL
)
/* The use of the timezone structure is obsolete;
* the tz argument should normally be specified as NULL.
* The tz_dsttime field has never been used under Linux.
* Thus, the following is purely of historic interest.
*/
if
(
tv
!=
RT_NULL
&&
tv
->
tv_sec
>=
0
&&
tv
->
tv_usec
>=
0
&&
set_timeval
((
struct
timeval
*
)
tv
)
==
RT_EOK
)
{
if
(
tv
->
tv_sec
>=
0
&&
tv
->
tv_usec
>=
0
)
{
if
(
set_timeval
((
struct
timeval
*
)
tv
)
>
0
)
{
return
0
;
}
else
{
errno
=
EFAULT
;
return
-
1
;
}
}
else
{
errno
=
EINVAL
;
return
-
1
;
}
return
0
;
}
else
{
errno
=
EFAULT
;
rt_set_errno
(
EINVAL
)
;
return
-
1
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录