This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] time: Always set the passed variable if any


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
> 
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]