[PATCH] time: Always set the passed variable if any
Jeff Johnston
jjohnstn@redhat.com
Mon May 2 20:13:00 GMT 2016
Patch applied.
-- Jeff J.
----- Original Message -----
> 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):
>
> Synopsis
> #include <time.h>
> time_t time(time_t *timer);
>
> Description
> The time function determines the current calendar time. The encoding
> of the value is unspecified.
>
> Returns
> The time function returns the implementation’s best approximation to
> the current calendar time. 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 assigned to the object it points to.
>
> Signed-off-by: Benoît Thébaudeau <benoit@wsystem.com>
> ---
> newlib/libc/time/time.c | 13 ++++++-------
> 1 file 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;
> }
> --
> 2.5.0
>
>
More information about the Newlib
mailing list