[PATCH 02/12] Change most internal uses of __gettimeofday to __clock_gettime.

Paul Eggert eggert@cs.ucla.edu
Tue Aug 20 18:53:00 GMT 2019


Zack Weinberg wrote:
> +      long int end = (now.tv_sec * 1000 + usectmo +
> +                      (now.tv_nsec + 500000) / 1000000);

The usual GNU style is to put that trailing "+" at the start of the next line 
instead, here and elsewhere.


> --- a/support/support_test_main.c
> +++ b/support/support_test_main.c
> @@ -88,16 +88,16 @@ static pid_t test_pid;
>  static void (*cleanup_function) (void);
>  
>  static void
> -print_timestamp (const char *what, struct timeval tv)
> +print_timestamp (const char *what, struct timespec tv)
>  {
>    struct tm tm;
>    if (gmtime_r (&tv.tv_sec, &tm) == NULL)
>      printf ("%s: %lld.%06d\n",
> -            what, (long long int) tv.tv_sec, (int) tv.tv_usec);
> +            what, (long long int) tv.tv_sec, (int) tv.tv_nsec / 1000);
>    else
>      printf ("%s: %04d-%02d-%02dT%02d:%02d:%02d.%06d\n",
>              what, 1900 + tm.tm_year, tm.tm_mon + 1, tm.tm_mday,
> -            tm.tm_hour, tm.tm_min, tm.tm_sec, (int) tv.tv_usec);
> +            tm.tm_hour, tm.tm_min, tm.tm_sec, (int) tv.tv_nsec / 1000);
>  }

Since the goal of this test code is to print the timestamp, the code should 
simply use %09d in the format and not divide by 1000.



More information about the Libc-alpha mailing list