summaryrefslogtreecommitdiff
path: root/components/libc/compilers
diff options
context:
space:
mode:
authorMeco Man <[email protected]>2021-05-01 16:21:52 +0800
committerMeco Man <[email protected]>2021-05-01 16:22:27 +0800
commit47de5265250f76ed1f48f7d1c51beda690a4bd74 (patch)
treeacc14101ded2219def81bc7b946a6c10edca9273 /components/libc/compilers
parent6fa385b98743c78b61a72fa5d4ff8ea7be4a31fd (diff)
精简settimeofday代码;
在Linux中settimeofday以及gettimeofday函数的时区功能已经被废弃,因此增加注释予以提示。 gettimeofday实现了tz_minuteswest功能,tz_dsttime功能未实现,按废弃处理; settimeofday时区功能废弃。
Diffstat (limited to 'components/libc/compilers')
-rw-r--r--components/libc/compilers/common/time.c41
1 files changed, 18 insertions, 23 deletions
diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c
index 388dc52ac3..50fbe0d5cc 100644
--- a/components/libc/compilers/common/time.c
+++ b/components/libc/compilers/common/time.c
@@ -124,11 +124,11 @@ static rt_err_t get_timeval(struct timeval *tv)
}
/**
- * Set time to RTC device (without timezone, UTC+0)
+ * Set time to RTC device (without timezone)
* @param tv: struct timeval
* @return the operation status, RT_EOK on successful
*/
-static rt_err_t set_timeval(struct timeval *tv)
+static int set_timeval(const struct timeval *tv)
{
#ifdef RT_USING_RTC
static rt_device_t device = RT_NULL;
@@ -415,9 +415,13 @@ time_t timegm(struct tm * const t)
}
RTM_EXPORT(timegm);
-/* TODO: Daylight Saving Time */
int gettimeofday(struct timeval *tv, struct timezone *tz)
{
+ /* 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 = 0;
@@ -436,32 +440,23 @@ int gettimeofday(struct timeval *tv, struct timezone *tz)
}
RTM_EXPORT(gettimeofday);
-/* TODO: Daylight Saving Time */
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(tv) == RT_EOK)
{
- if(tv->tv_sec >= 0 && tv->tv_usec >= 0)
- {
- if(set_timeval((struct timeval *)tv) == RT_EOK)
- {
- return 0;
- }
- else
- {
- rt_set_errno(EFAULT);
- return -1;
- }
- }
- else
- {
- rt_set_errno(EINVAL);
- return -1;
- }
+ return 0;
}
else
{
- rt_set_errno(EFAULT);
+ rt_set_errno(EINVAL);
return -1;
}
}