summaryrefslogtreecommitdiff
path: root/components/libc/compilers/common
diff options
context:
space:
mode:
authorzhkag <[email protected]>2023-06-07 11:46:18 +0800
committerMan, Jianting (Meco) <[email protected]>2023-06-07 08:52:28 -0400
commit22972409d4efd9ea2d8248024a88307615a0ca6c (patch)
treea42bbddab6634f57eda8be215f40b1f151dd0f32 /components/libc/compilers/common
parent0a7b08d00accabd9b6921aa93c55119ec9248312 (diff)
[simulator] 修复 linux simulator 编译运行失败
Diffstat (limited to 'components/libc/compilers/common')
-rw-r--r--components/libc/compilers/common/SConscript2
-rw-r--r--components/libc/compilers/common/ctime.c2
-rw-r--r--components/libc/compilers/common/include/sys/time.h27
3 files changed, 31 insertions, 0 deletions
diff --git a/components/libc/compilers/common/SConscript b/components/libc/compilers/common/SConscript
index fda7c6bf61..bb1abae5d5 100644
--- a/components/libc/compilers/common/SConscript
+++ b/components/libc/compilers/common/SConscript
@@ -11,6 +11,8 @@ if rtconfig.PLATFORM in ['armcc', 'armclang']:
CPPDEFINES += ['__CLK_TCK=RT_TICK_PER_SECOND']
elif rtconfig.PLATFORM in ['iccarm']:
CPPDEFINES += ['CLOCKS_PER_SEC=RT_TICK_PER_SECOND'] # forcly revert to 1 by IAR
+elif rtconfig.PLATFORM in ['gcc'] and rtconfig.CPU in ['posix']:
+ CPPDEFINES += ['_GNU_SOURCE'] # linux x86 platform gcc use!
src += Glob('*.c')
diff --git a/components/libc/compilers/common/ctime.c b/components/libc/compilers/common/ctime.c
index d5aff8618b..dff9ac188e 100644
--- a/components/libc/compilers/common/ctime.c
+++ b/components/libc/compilers/common/ctime.c
@@ -66,6 +66,7 @@ static const short __spm[13] =
rt_align(4) 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 ";
+#ifndef __isleap
static int __isleap(int year)
{
/* every fourth year is a leap year except for century years that are
@@ -73,6 +74,7 @@ static int __isleap(int year)
/* return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); */
return (!(year % 4) && ((year % 100) || !(year % 400)));
}
+#endif
static void num2str(char *c, int i)
{
diff --git a/components/libc/compilers/common/include/sys/time.h b/components/libc/compilers/common/include/sys/time.h
index 87be959715..7cf4c8c0d8 100644
--- a/components/libc/compilers/common/include/sys/time.h
+++ b/components/libc/compilers/common/include/sys/time.h
@@ -48,6 +48,33 @@ struct timezone
int tz_dsttime; /* type of dst correction */
};
+#if defined(_GNU_SOURCE) && (defined(__x86_64__) || defined(__i386__))
+/* linux x86 platform gcc use! */
+#define _TIMEVAL_DEFINED
+/* Values for the first argument to `getitimer' and `setitimer'. */
+enum __itimer_which
+{
+ /* Timers run in real time. */
+ ITIMER_REAL = 0,
+#define ITIMER_REAL ITIMER_REAL
+ /* Timers run only when the process is executing. */
+ ITIMER_VIRTUAL = 1,
+#define ITIMER_VIRTUAL ITIMER_VIRTUAL
+ /* Timers run when the process is executing and when
+ the system is executing on behalf of the process. */
+ ITIMER_PROF = 2
+#define ITIMER_PROF ITIMER_PROF
+};
+
+struct itimerval
+{
+ /* Value to put into `it_value' when the timer expires. */
+ struct timeval it_interval;
+ /* Time to the next timer expiration. */
+ struct timeval it_value;
+};
+#endif /* defined(_GNU_SOURCE) && (defined(__x86_64__) || defined(__i386__)) */
+
#ifndef _TIMEVAL_DEFINED
#define _TIMEVAL_DEFINED
struct timeval