Skip to content

Commit 6d7ba2b

Browse files
authored
Merge pull request #5077 from mysterywolf/time
[libc][time] 修复数据类型报警
2 parents 163c059 + 71f4826 commit 6d7ba2b

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

components/libc/compilers/common/sys/time.h

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
#define __SYS_TIME_H__
1313

1414
#include <rtconfig.h>
15-
#include <rtdef.h>
15+
#include <sys/types.h>
16+
#include <stdint.h>
1617
#include <time.h>
1718

1819
#ifdef __cplusplus
@@ -32,22 +33,19 @@ extern "C" {
3233
#define DST_TUR 9 /* Turkey */
3334
#define DST_AUSTALT 10 /* Australian style with shift in 1986 */
3435

35-
struct timezone {
36-
int tz_minuteswest; /* minutes west of Greenwich */
37-
int tz_dsttime; /* type of dst correction */
36+
struct timezone
37+
{
38+
int tz_minuteswest; /* minutes west of Greenwich */
39+
int tz_dsttime; /* type of dst correction */
3840
};
3941

40-
void rt_tz_set(rt_int8_t tz);
41-
rt_int8_t rt_tz_get(void);
42-
rt_int8_t rt_tz_is_dst(void);
43-
4442
/*
4543
* Structure returned by gettimeofday(2) system call,
4644
* and used in other calls.
4745
*/
4846
#ifndef _TIMEVAL_DEFINED
4947
#define _TIMEVAL_DEFINED
50-
#if !(defined(_WIN32))
48+
#if !defined(_WIN32)
5149
struct timeval
5250
{
5351
time_t tv_sec; /* seconds */
@@ -56,6 +54,16 @@ struct timeval
5654
#endif
5755
#endif /* _TIMEVAL_DEFINED */
5856

57+
#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) && \
58+
!(defined(__ICCARM__) && (__VER__ >= 8010001)) && \
59+
!defined(_WIN32)
60+
struct timespec
61+
{
62+
time_t tv_sec; /* seconds */
63+
long tv_nsec; /* and nanoseconds */
64+
};
65+
#endif
66+
5967
int stime(const time_t *t);
6068
time_t timegm(struct tm * const t);
6169
int gettimeofday(struct timeval *tv, struct timezone *tz);
@@ -65,15 +73,6 @@ struct tm *gmtime_r(const time_t *timep, struct tm *r);
6573
#endif
6674

6775
#ifdef RT_USING_POSIX
68-
#include <sys/types.h>
69-
70-
#if !(defined(__GNUC__) && !defined(__ARMCC_VERSION)/*GCC*/) && !(defined(__ICCARM__) && (__VER__ >= 8010001)) && !defined(_WIN32)
71-
struct timespec {
72-
time_t tv_sec; /* seconds */
73-
long tv_nsec; /* and nanoseconds */
74-
};
75-
#endif
76-
7776
/* POSIX clock and timer */
7877
#define MILLISECOND_PER_SECOND 1000UL
7978
#define MICROSECOND_PER_SECOND 1000000UL
@@ -106,6 +105,10 @@ int clock_settime (clockid_t clockid, const struct timespec *tp);
106105
int rt_timespec_to_tick(const struct timespec *time);
107106
#endif /* RT_USING_POSIX */
108107

108+
void tz_set(int8_t tz);
109+
int8_t tz_get(void);
110+
int8_t tz_is_dst(void);
111+
109112
#ifdef __cplusplus
110113
}
111114
#endif

components/libc/compilers/common/time.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ struct tm *gmtime_r(const time_t *timep, struct tm *r)
199199
r->tm_mon = i;
200200
r->tm_mday += work - __spm[i];
201201

202-
r->tm_isdst = rt_tz_is_dst();
202+
r->tm_isdst = tz_is_dst();
203203
return r;
204204
}
205205
RTM_EXPORT(gmtime_r);
@@ -215,7 +215,7 @@ struct tm* localtime_r(const time_t* t, struct tm* r)
215215
{
216216
time_t local_tz;
217217

218-
local_tz = *t + rt_tz_get() * 3600;
218+
local_tz = *t + tz_get() * 3600;
219219
return gmtime_r(&local_tz, r);
220220
}
221221
RTM_EXPORT(localtime_r);
@@ -232,7 +232,7 @@ time_t mktime(struct tm * const t)
232232
time_t timestamp;
233233

234234
timestamp = timegm(t);
235-
timestamp = timestamp - 3600 * rt_tz_get();
235+
timestamp = timestamp - 3600 * tz_get();
236236
return timestamp;
237237
}
238238
RTM_EXPORT(mktime);
@@ -423,7 +423,7 @@ int gettimeofday(struct timeval *tv, struct timezone *tz)
423423
if(tz != RT_NULL)
424424
{
425425
tz->tz_dsttime = DST_NONE;
426-
tz->tz_minuteswest = -(rt_tz_get() * 60);
426+
tz->tz_minuteswest = -(tz_get() * 60);
427427
}
428428

429429
if (tv != RT_NULL && get_timeval(tv) == RT_EOK)
@@ -446,7 +446,6 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz)
446446
* Thus, the following is purely of historic interest.
447447
*/
448448
if (tv != RT_NULL
449-
&& tv->tv_sec >= 0
450449
&& tv->tv_usec >= 0
451450
&& set_timeval((struct timeval *)tv) == RT_EOK)
452451
{
@@ -676,22 +675,22 @@ RTM_EXPORT(rt_timespec_to_tick);
676675
#define RT_LIBC_DEFAULT_TIMEZONE 8
677676
#endif
678677

679-
static volatile rt_int8_t rt_current_timezone = RT_LIBC_DEFAULT_TIMEZONE;
678+
static volatile int8_t _current_timezone = RT_LIBC_DEFAULT_TIMEZONE;
680679

681-
void rt_tz_set(rt_int8_t tz)
680+
void tz_set(int8_t tz)
682681
{
683682
register rt_base_t level;
684683
level = rt_hw_interrupt_disable();
685-
rt_current_timezone = tz;
684+
_current_timezone = tz;
686685
rt_hw_interrupt_enable(level);
687686
}
688687

689-
rt_int8_t rt_tz_get(void)
688+
int8_t tz_get(void)
690689
{
691-
return rt_current_timezone;
690+
return _current_timezone;
692691
}
693692

694-
rt_int8_t rt_tz_is_dst(void)
693+
int8_t tz_is_dst(void)
695694
{
696695
return 0;
697696
}

0 commit comments

Comments
 (0)