提交 f52095d2 编写于 作者: mysterywolf's avatar mysterywolf 提交者: mysterywolf

[libc][time] cleanup code

上级 c985f318
...@@ -26,21 +26,18 @@ ...@@ -26,21 +26,18 @@
#include "sys/time.h" #include "sys/time.h"
#include <rthw.h> #include <rthw.h>
#include <rtthread.h> #include <rtdevice.h>
#include <drivers/rtc.h>
#include <sys/errno.h> #include <sys/errno.h>
#include <unistd.h> #include <unistd.h>
#include "drivers/rtc.h"
#ifdef RT_USING_SMART #ifdef RT_USING_SMART
#include "lwp.h" #include <lwp.h>
#endif #endif
#ifdef RT_USING_POSIX_DELAY #ifdef RT_USING_POSIX_DELAY
#include <delay.h> #include <delay.h>
#endif #endif
#if defined( RT_USING_RTC ) || defined( RT_USING_CPUTIME)
#include <rtdevice.h>
#endif
#ifdef RT_USING_KTIME #ifdef RT_USING_KTIME
#include "ktime.h" #include <ktime.h>
#endif #endif
#define DBG_TAG "time" #define DBG_TAG "time"
...@@ -49,9 +46,6 @@ ...@@ -49,9 +46,6 @@
#define _WARNING_NO_RTC "Cannot find a RTC device!" #define _WARNING_NO_RTC "Cannot find a RTC device!"
/* seconds per day */
#define SPD 24*60*60
/* days per month -- nonleap! */ /* days per month -- nonleap! */
static const short __spm[13] = static const short __spm[13] =
{ {
...@@ -70,8 +64,8 @@ static const short __spm[13] = ...@@ -70,8 +64,8 @@ static const short __spm[13] =
(31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31), (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31),
}; };
rt_align(4) static const char *days = "Sun Mon Tue Wed Thu Fri Sat "; rt_align(RT_ALIGN_SIZE) static const char *days = "Sun Mon Tue Wed Thu Fri Sat ";
rt_align(4) static const char *months = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec "; rt_align(RT_ALIGN_SIZE) static const char *months = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ";
#ifndef __isleap #ifndef __isleap
static int __isleap(int year) static int __isleap(int year)
...@@ -134,12 +128,12 @@ struct tm *gmtime_r(const time_t *timep, struct tm *r) ...@@ -134,12 +128,12 @@ struct tm *gmtime_r(const time_t *timep, struct tm *r)
rt_memset(r, RT_NULL, sizeof(struct tm)); rt_memset(r, RT_NULL, sizeof(struct tm));
work = *timep % (SPD); work = *timep % (24*60*60);
r->tm_sec = work % 60; r->tm_sec = work % 60;
work /= 60; work /= 60;
r->tm_min = work % 60; r->tm_min = work % 60;
r->tm_hour = work / 60; r->tm_hour = work / 60;
work = (int)(*timep / (SPD)); work = (int)(*timep / (24*60*60));
r->tm_wday = (4 + work) % 7; r->tm_wday = (4 + work) % 7;
for (i = 1970;; ++i) for (i = 1970;; ++i)
{ {
...@@ -257,7 +251,7 @@ char* asctime_r(const struct tm *t, char *buf) ...@@ -257,7 +251,7 @@ char* asctime_r(const struct tm *t, char *buf)
} }
RTM_EXPORT(asctime_r); RTM_EXPORT(asctime_r);
char* asctime(const struct tm *timeptr) char *asctime(const struct tm *timeptr)
{ {
static char buf[26]; static char buf[26];
return asctime_r(timeptr, buf); return asctime_r(timeptr, buf);
...@@ -271,7 +265,7 @@ char *ctime_r(const time_t * tim_p, char * result) ...@@ -271,7 +265,7 @@ char *ctime_r(const time_t * tim_p, char * result)
} }
RTM_EXPORT(ctime_r); RTM_EXPORT(ctime_r);
char* ctime(const time_t *tim_p) char *ctime(const time_t *tim_p)
{ {
return asctime(localtime(tim_p)); return asctime(localtime(tim_p));
} }
...@@ -303,7 +297,7 @@ rt_weak time_t time(time_t *t) ...@@ -303,7 +297,7 @@ rt_weak time_t time(time_t *t)
if (_control_rtc(RT_DEVICE_CTRL_RTC_GET_TIME, &_t) != RT_EOK) if (_control_rtc(RT_DEVICE_CTRL_RTC_GET_TIME, &_t) != RT_EOK)
{ {
rt_set_errno(EFAULT); rt_set_errno(EFAULT);
return -1; return (time_t)-1;
} }
if (t) if (t)
...@@ -809,7 +803,7 @@ static void rtthread_timer_wrapper(void *timerobj) ...@@ -809,7 +803,7 @@ static void rtthread_timer_wrapper(void *timerobj)
{ {
(timer->sigev_notify_function)(timer->val); (timer->sigev_notify_function)(timer->val);
} }
#endif #endif /* RT_USING_SMART */
} }
#define TIMER_ID_MAX 50 #define TIMER_ID_MAX 50
...@@ -890,8 +884,7 @@ int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid) ...@@ -890,8 +884,7 @@ int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid)
} }
timer->work = work; timer->work = work;
#endif /* RT_USING_SMART */
#endif
timer->sigev_notify_function = evp->sigev_notify_function; timer->sigev_notify_function = evp->sigev_notify_function;
timer->val = evp->sigev_value; timer->val = evp->sigev_value;
timer->interval.tv_sec = 0; timer->interval.tv_sec = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册