aboutsummaryrefslogtreecommitdiff
path: root/newlib/libc/time
diff options
context:
space:
mode:
authorJeff Johnston <jjohnstn@redhat.com>2016-05-02 16:11:26 -0400
committerJeff Johnston <jjohnstn@redhat.com>2016-05-02 16:11:26 -0400
commitf310e8d951acfdbcacc56501e39c2e26caf152ae (patch)
tree01f55c476a0efbcebbc191a769ab7648308c92c9 /newlib/libc/time
parent58dd08ee5072c7f6246baf7d35dbf37806e78ba1 (diff)
downloadnewlib-f310e8d951acfdbcacc56501e39c2e26caf152ae.zip
newlib-f310e8d951acfdbcacc56501e39c2e26caf152ae.tar.gz
newlib-f310e8d951acfdbcacc56501e39c2e26caf152ae.tar.bz2
Always assign return value to passed pointer in time function.
If the passed t pointer is not a null pointer, always assign the return value to the object it points to, regardless of whether the return value is an error. This is what the GNU C Library does, and this is also the expected behavior according to the latest draft of the C programming language standard (C11 ISO/IEC 9899:201x WG14 N1570, dated 2011-04-12): Signed-off-by: Benoît Thébaudeau <benoit@wsystem.com>
Diffstat (limited to 'newlib/libc/time')
-rw-r--r--newlib/libc/time/time.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/newlib/libc/time/time.c b/newlib/libc/time/time.c
index 2506388..9de71d4 100644
--- a/newlib/libc/time/time.c
+++ b/newlib/libc/time/time.c
@@ -43,11 +43,10 @@ _DEFUN (time, (t),
{
struct timeval now;
- if (_gettimeofday_r (_REENT, &now, NULL) >= 0)
- {
- if (t)
- *t = now.tv_sec;
- return now.tv_sec;
- }
- return -1;
+ if (_gettimeofday_r (_REENT, &now, NULL) < 0)
+ now.tv_sec = (time_t) -1;
+
+ if (t)
+ *t = now.tv_sec;
+ return now.tv_sec;
}