Skip to content

Commit ce4fabe

Browse files
committed
add errno
1 parent dd14792 commit ce4fabe

File tree

1 file changed

+14
-2
lines changed
  • components/libc/compilers/common

1 file changed

+14
-2
lines changed

components/libc/compilers/common/time.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* 2021-02-10 Meco Man add ctime_r() and re-implement ctime()
1414
* 2021-02-11 Meco Man fix bug #3183 - align days[] and months[] to 4 bytes
1515
* add difftime()
16+
* 2021-02-12 Meco Man add errno
1617
*/
1718

1819
#include <sys/time.h>
@@ -208,6 +209,11 @@ RT_WEAK time_t time(time_t *t)
208209
*t = time_now;
209210
}
210211

212+
if(time_now == (time_t)-1)
213+
{
214+
errno = ENOSYS;
215+
}
216+
211217
return time_now;
212218
}
213219

@@ -230,11 +236,13 @@ int stime(const time_t *t)
230236
}
231237
else
232238
{
239+
errno = ENOSYS;
233240
return -1;
234241
}
235242
return 0;
236243

237244
#else
245+
errno = ENOSYS;
238246
return -1;
239247
#endif /* RT_USING_RTC */
240248
}
@@ -316,14 +324,17 @@ time_t timegm(struct tm * const t)
316324
/* TODO: timezone */
317325
int gettimeofday(struct timeval *tv, struct timezone *tz)
318326
{
319-
if (tv != RT_NULL)
327+
time_t t = time(RT_NULL);
328+
329+
if (tv != RT_NULL && t != (time_t)-1)
320330
{
321-
tv->tv_sec = time(RT_NULL);
331+
tv->tv_sec = t;
322332
tv->tv_usec = 0;
323333
return 0;
324334
}
325335
else
326336
{
337+
errno = ENOSYS;
327338
return -1;
328339
}
329340
}
@@ -337,6 +348,7 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz)
337348
}
338349
else
339350
{
351+
errno = ENOSYS;
340352
return -1;
341353
}
342354
}

0 commit comments

Comments
 (0)