diff options
| author | Meco Man <[email protected]> | 2021-02-11 13:41:24 +0800 |
|---|---|---|
| committer | Meco Man <[email protected]> | 2021-02-11 13:41:24 +0800 |
| commit | dd147925e52aa205a09d631984c545f9c99c52c2 (patch) | |
| tree | fef0be16487599d9432209cd54f4d9514f851ea0 /components/libc | |
| parent | e3fee1ca77104bbc6d8e5e964b5f44fca7456c49 (diff) | |
fix time() return value
Diffstat (limited to 'components/libc')
| -rw-r--r-- | components/libc/compilers/common/time.c | 9 |
1 files 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) |
