From 0d30632de6864a7cfaaa3a1de78ff7ef8f77539a Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 7 Feb 2021 22:09:22 +0800 Subject: [PATCH 01/17] fix #3976 --- components/libc/compilers/common/time.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index e2dae1feaf..ad167a85c7 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -213,22 +213,12 @@ RT_WEAK clock_t clock(void) /* TODO: timezone */ int gettimeofday(struct timeval *tp, struct timezone *tz) { - time_t time = 0; -#ifdef RT_USING_DEVICE - rt_device_t device; - device = rt_device_find("rtc"); - RT_ASSERT(device != RT_NULL); - rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time); + time_t time = time(NULL); if (tp != RT_NULL) { tp->tv_sec = time; tp->tv_usec = 0; } -#else - tv->tv_sec = 0; - tv->tv_usec = 0; -#endif - return time; } From d92f8a53da900f4c03dd8c5c0b8163a03a72a9df Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 7 Feb 2021 22:25:30 +0800 Subject: [PATCH 02/17] update --- components/libc/compilers/common/time.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index ad167a85c7..d7f239bea1 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -213,13 +213,13 @@ RT_WEAK clock_t clock(void) /* TODO: timezone */ int gettimeofday(struct timeval *tp, struct timezone *tz) { - time_t time = time(NULL); + time_t t = time(RT_NULL); if (tp != RT_NULL) { - tp->tv_sec = time; + tp->tv_sec = t; tp->tv_usec = 0; } - return time; + return 0; } time_t timegm(struct tm * const t) From 4c6962436ae8a89252c397dffac4b865f5cb663f Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 7 Feb 2021 22:33:37 +0800 Subject: [PATCH 03/17] update --- components/libc/compilers/common/time.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index d7f239bea1..bdbb27bce4 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -213,10 +213,9 @@ RT_WEAK clock_t clock(void) /* TODO: timezone */ int gettimeofday(struct timeval *tp, struct timezone *tz) { - time_t t = time(RT_NULL); if (tp != RT_NULL) { - tp->tv_sec = t; + tp->tv_sec = time(RT_NULL); tp->tv_usec = 0; } return 0; From 6c7dd305329602611aba93772357aa5a394a3a6e Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 8 Feb 2021 00:56:31 +0800 Subject: [PATCH 04/17] add function settimeofday & stime --- components/libc/compilers/common/sys/time.h | 4 +- components/libc/compilers/common/time.c | 71 +++++++++++++++------ 2 files changed, 55 insertions(+), 20 deletions(-) diff --git a/components/libc/compilers/common/sys/time.h b/components/libc/compilers/common/sys/time.h index e99fd7d54f..599b8b5262 100644 --- a/components/libc/compilers/common/sys/time.h +++ b/components/libc/compilers/common/sys/time.h @@ -48,8 +48,10 @@ struct timezone { int tz_dsttime; /* type of dst correction */ }; -int gettimeofday(struct timeval *tp, struct timezone *tz); +int stime(const time_t *t); time_t timegm(struct tm * const t); +int gettimeofday(struct timeval *tv, struct timezone *tz); +int settimeofday(const struct timeval *tv, const struct timezone *tz); #ifdef __cplusplus } diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index bdbb27bce4..155a04f92f 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -8,6 +8,8 @@ * 2019-08-21 zhangjun copy from minilibc * 2020-09-07 Meco Man combine gcc armcc iccarm * 2021-02-05 Meco Man add timegm() + * 2021-02-07 Meco Man fixed gettimeofday() time() + * 2021-02-08 Meco Man add settimeofday() stime() */ #include @@ -175,24 +177,15 @@ time_t time(time_t *t) #endif { time_t time_now = 0; - #ifdef RT_USING_RTC - static rt_device_t device = RT_NULL; - - /* optimization: find rtc device only first. */ - if (device == RT_NULL) - { - device = rt_device_find("rtc"); - } + rt_device_t device; /* read timestamp from RTC device. */ - if (device != RT_NULL) + device = rt_device_find("rtc"); + if (rt_device_open(device, 0) == RT_EOK) { - if (rt_device_open(device, 0) == RT_EOK) - { - rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time_now); - rt_device_close(device); - } + rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time_now); + rt_device_close(device); } #endif /* RT_USING_RTC */ @@ -210,15 +203,27 @@ RT_WEAK clock_t clock(void) return rt_tick_get(); } -/* TODO: timezone */ -int gettimeofday(struct timeval *tp, struct timezone *tz) +int stime(const time_t *t) { - if (tp != RT_NULL) +#ifdef RT_USING_RTC + rt_device_t device; + + /* read timestamp from RTC device. */ + device = rt_device_find("rtc"); + if (rt_device_open(device, 0) == RT_EOK) { - tp->tv_sec = time(RT_NULL); - tp->tv_usec = 0; + rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, (void*)t); + rt_device_close(device); + } + else + { + return -1; } return 0; + +#else + return -1; +#endif /* RT_USING_RTC */ } time_t timegm(struct tm * const t) @@ -294,3 +299,31 @@ time_t timegm(struct tm * const t) i = 60; return ((day + t->tm_hour) * i + t->tm_min) * i + t->tm_sec; } + +/* TODO: timezone */ +int gettimeofday(struct timeval *tv, struct timezone *tz) +{ + if (tv != RT_NULL) + { + tv->tv_sec = time(RT_NULL); + tv->tv_usec = 0; + return 0; + } + else + { + return -1; + } +} + +/* TODO: timezone */ +int settimeofday(const struct timeval *tv, const struct timezone *tz) +{ + if (tv != RT_NULL) + { + return stime(&tv->tv_sec); + } + else + { + return -1; + } +} From d0c2631b1215af38eb07b24cd25a751640e9c07c Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 8 Feb 2021 10:33:12 +0800 Subject: [PATCH 05/17] revert time() --- components/libc/compilers/common/time.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 155a04f92f..a67c0497af 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -8,7 +8,7 @@ * 2019-08-21 zhangjun copy from minilibc * 2020-09-07 Meco Man combine gcc armcc iccarm * 2021-02-05 Meco Man add timegm() - * 2021-02-07 Meco Man fixed gettimeofday() time() + * 2021-02-07 Meco Man fixed gettimeofday() * 2021-02-08 Meco Man add settimeofday() stime() */ @@ -177,15 +177,24 @@ time_t time(time_t *t) #endif { time_t time_now = 0; + #ifdef RT_USING_RTC - rt_device_t device; + static rt_device_t device = RT_NULL; + + /* optimization: find rtc device only first. */ + if (device == RT_NULL) + { + device = rt_device_find("rtc"); + } /* read timestamp from RTC device. */ - device = rt_device_find("rtc"); - if (rt_device_open(device, 0) == RT_EOK) + if (device != RT_NULL) { - rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time_now); - rt_device_close(device); + if (rt_device_open(device, 0) == RT_EOK) + { + rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time_now); + rt_device_close(device); + } } #endif /* RT_USING_RTC */ From 9b428e519fc91204f4be5e91f1436ba6fd63119b Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 8 Feb 2021 10:42:50 +0800 Subject: [PATCH 06/17] avoid warning --- components/libc/compilers/common/time.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index a67c0497af..bd251d99bf 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -329,7 +329,7 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz) { if (tv != RT_NULL) { - return stime(&tv->tv_sec); + return stime((const time_t *)&tv->tv_sec); } else { From 3e9c77efd5aac880e2f5d5db895d50c227dda663 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 8 Feb 2021 10:55:08 +0800 Subject: [PATCH 07/17] =?UTF-8?q?=E4=BC=98=E5=8C=96IAR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/time.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index bd251d99bf..bc77aee510 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -18,9 +18,6 @@ #include #endif - -#if !defined (__IAR_SYSTEMS_ICC__) - /* seconds per day */ #define SPD 24*60*60 @@ -155,8 +152,6 @@ char* ctime(const time_t *timep) return asctime(localtime(timep)); } -#endif /* __IAR_SYSTEMS_ICC__ */ - /** * Returns the current time. * From 2645aec2e3b5b805d697b2ec546faeb5157e8d81 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 8 Feb 2021 11:30:49 +0800 Subject: [PATCH 08/17] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E7=94=A8=E7=9A=84=E9=A2=84=E7=BC=96=E8=AF=91=EF=BC=8C=E5=9C=A8?= =?UTF-8?q?=E6=96=B0=E7=89=88=E7=9A=84IAR=E4=B8=AD=E6=AD=A4=E5=B7=B2?= =?UTF-8?q?=E7=BB=8F=E4=B8=8D=E9=9C=80=E8=A6=81=E4=BA=86=20=E5=AF=B9time?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=A2=9E=E5=8A=A0RT=5FWEAK?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/time.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index bc77aee510..7e4a98f923 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -160,16 +160,7 @@ char* ctime(const time_t *timep) * @return time_t return timestamp current. * */ -#if defined (__IAR_SYSTEMS_ICC__) && (__VER__) >= 6020000 /* for IAR 6.2 later Compiler */ -#pragma module_name = "?time" -#if _DLIB_TIME_USES_64 -time_t __time64(time_t *t) -#else -time_t __time32(time_t *t) -#endif -#else /* Keil & GCC */ -time_t time(time_t *t) -#endif +RT_WEAK time_t time(time_t *t) { time_t time_now = 0; From 39ff4b5a97accf4a0c2134b8b7b395482fc785fb Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 8 Feb 2021 11:37:24 +0800 Subject: [PATCH 09/17] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=B6=E5=8C=BA?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E5=85=AC=E5=BC=8F=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/common/time.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 7e4a98f923..2cea9b75ce 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -101,10 +101,10 @@ struct tm* gmtime(const time_t* t) struct tm* localtime_r(const time_t* t, struct tm* r) { time_t local_tz; - int timezone; + int utc; - timezone = 0 * 3600 * 8; /* GTM: UTC+0 */ - local_tz = *t + timezone; + utc = 3600 * 0; /* GTM: UTC+0 */ + local_tz = *t + utc; return gmtime_r(&local_tz, r); } From 66e2a9424b6d4a46be1bb697fa5acbec46a287a8 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 10 Feb 2021 21:01:16 +0800 Subject: [PATCH 10/17] update --- components/libc/compilers/common/time.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 2cea9b75ce..dc33e0b9e5 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -101,10 +101,10 @@ struct tm* gmtime(const time_t* t) struct tm* localtime_r(const time_t* t, struct tm* r) { time_t local_tz; - int utc; + int utc_plus; - utc = 3600 * 0; /* GTM: UTC+0 */ - local_tz = *t + utc; + utc_plus = 3600 * 0; /* GTM: UTC+0 */ + local_tz = *t + utc_plus; return gmtime_r(&local_tz, r); } From 072dbe57c6da6bafb90128720462dd16e92741cd Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 11 Feb 2021 02:31:53 +0800 Subject: [PATCH 11/17] format & add clear tm_isdst --- components/libc/compilers/common/time.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index dc33e0b9e5..081e27de74 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -88,6 +88,8 @@ struct tm *gmtime_r(const time_t *timep, struct tm *r) ; r->tm_mon = i; r->tm_mday += work - __spm[i]; + + r->tm_isdst = 0; return r; } @@ -103,8 +105,8 @@ struct tm* localtime_r(const time_t* t, struct tm* r) time_t local_tz; int utc_plus; - utc_plus = 3600 * 0; /* GTM: UTC+0 */ - local_tz = *t + utc_plus; + utc_plus = 0; /* GTM: UTC+0 */ + local_tz = *t + utc_plus * 3600; return gmtime_r(&local_tz, r); } From 5e5ceabfdce8638c5ec8b78d4a53aa2ed0046b82 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 11 Feb 2021 02:32:47 +0800 Subject: [PATCH 12/17] add ctime_r() and re-implement ctime() --- components/libc/compilers/common/time.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 081e27de74..ff76fae453 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -10,6 +10,7 @@ * 2021-02-05 Meco Man add timegm() * 2021-02-07 Meco Man fixed gettimeofday() * 2021-02-08 Meco Man add settimeofday() stime() + * 2021-02-10 Meco Man add ctime_r() and re-implement ctime() */ #include @@ -149,9 +150,15 @@ char* asctime(const struct tm *timeptr) return asctime_r(timeptr, buf); } -char* ctime(const time_t *timep) +char *ctime_r (const time_t * tim_p, char * result) { - return asctime(localtime(timep)); + struct tm tm; + return asctime_r (localtime_r (tim_p, &tm), result); +} + +char* ctime(const time_t *tim_p) +{ + return asctime (localtime (tim_p)); } /** From 51cb109cf8386088368469769d14b1d039551dd1 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 11 Feb 2021 02:33:45 +0800 Subject: [PATCH 13/17] fix bug #3183 - align days[] and months[] to 4 bytes --- components/libc/compilers/common/time.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index ff76fae453..68cd7f0837 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -11,6 +11,7 @@ * 2021-02-07 Meco Man fixed gettimeofday() * 2021-02-08 Meco Man add settimeofday() stime() * 2021-02-10 Meco Man add ctime_r() and re-implement ctime() + * 2021-02-11 Meco Man fix bug #3183 - align days[] and months[] to 4 bytes */ #include @@ -39,8 +40,9 @@ const short __spm[13] = (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30), (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31), }; -static const char days[] = "Sun Mon Tue Wed Thu Fri Sat "; -static const char months[] = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec "; + +ALIGN(4) static const char days[] = "Sun Mon Tue Wed Thu Fri Sat "; +ALIGN(4) static const char months[] = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec "; static int __isleap(int year) { From d67d4d3fd0ae292677cee9cf9a4d2bb5b5eefb1a Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 11 Feb 2021 02:34:38 +0800 Subject: [PATCH 14/17] add difftime() --- components/libc/compilers/common/time.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 68cd7f0837..366bc28bd1 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -12,6 +12,7 @@ * 2021-02-08 Meco Man add settimeofday() stime() * 2021-02-10 Meco Man add ctime_r() and re-implement ctime() * 2021-02-11 Meco Man fix bug #3183 - align days[] and months[] to 4 bytes + * add difftime() */ #include @@ -163,6 +164,11 @@ char* ctime(const time_t *tim_p) return asctime (localtime (tim_p)); } +double difftime (time_t tim1, time_t tim2) +{ + return (double)(tim1 - tim2); +} + /** * Returns the current time. * From e3fee1ca77104bbc6d8e5e964b5f44fca7456c49 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 11 Feb 2021 02:46:23 +0800 Subject: [PATCH 15/17] 2 spaces -> 4 spaces --- components/libc/compilers/common/time.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 366bc28bd1..e1c9340e69 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -155,8 +155,8 @@ char* asctime(const struct tm *timeptr) char *ctime_r (const time_t * tim_p, char * result) { - struct tm tm; - return asctime_r (localtime_r (tim_p, &tm), result); + struct tm tm; + return asctime_r (localtime_r (tim_p, &tm), result); } char* ctime(const time_t *tim_p) From dd147925e52aa205a09d631984c545f9c99c52c2 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 11 Feb 2021 13:41:24 +0800 Subject: [PATCH 16/17] fix time() return value --- components/libc/compilers/common/time.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index e1c9340e69..fecae28f9f 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -174,23 +174,24 @@ double difftime (time_t tim1, time_t tim2) * * @param time_t * t the timestamp pointer, if not used, keep NULL. * - * @return time_t return timestamp current. + * @return The value ((time_t)-1) is returned if the calendar time is not available. + * If timer is not a NULL pointer, the return value is also stored in timer. * */ RT_WEAK time_t time(time_t *t) { - time_t time_now = 0; + time_t time_now = ((time_t)-1); /* default is not available */ #ifdef RT_USING_RTC static rt_device_t device = RT_NULL; - /* optimization: find rtc device only first. */ + /* optimization: find rtc device only first */ if (device == RT_NULL) { device = rt_device_find("rtc"); } - /* read timestamp from RTC device. */ + /* read timestamp from RTC device */ if (device != RT_NULL) { if (rt_device_open(device, 0) == RT_EOK) From ce4fabe158a9b0367712a4afe904b5d6d7da9f78 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 11 Feb 2021 20:48:30 +0800 Subject: [PATCH 17/17] add errno --- components/libc/compilers/common/time.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index fecae28f9f..a980f742fb 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -13,6 +13,7 @@ * 2021-02-10 Meco Man add ctime_r() and re-implement ctime() * 2021-02-11 Meco Man fix bug #3183 - align days[] and months[] to 4 bytes * add difftime() + * 2021-02-12 Meco Man add errno */ #include @@ -208,6 +209,11 @@ RT_WEAK time_t time(time_t *t) *t = time_now; } + if(time_now == (time_t)-1) + { + errno = ENOSYS; + } + return time_now; } @@ -230,11 +236,13 @@ int stime(const time_t *t) } else { + errno = ENOSYS; return -1; } return 0; #else + errno = ENOSYS; return -1; #endif /* RT_USING_RTC */ } @@ -316,14 +324,17 @@ time_t timegm(struct tm * const t) /* TODO: timezone */ int gettimeofday(struct timeval *tv, struct timezone *tz) { - if (tv != RT_NULL) + time_t t = time(RT_NULL); + + if (tv != RT_NULL && t != (time_t)-1) { - tv->tv_sec = time(RT_NULL); + tv->tv_sec = t; tv->tv_usec = 0; return 0; } else { + errno = ENOSYS; return -1; } } @@ -337,6 +348,7 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz) } else { + errno = ENOSYS; return -1; } }