Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* struct timeval problem
@ 1999-01-15 21:00 Munagala V. S. Ramanath
  1999-01-15 21:13 ` Greg Lindahl
  0 siblings, 1 reply; 3+ messages in thread
From: Munagala V. S. Ramanath @ 1999-01-15 21:00 UTC (permalink / raw)
  To: axp-list

Hi,

Just noticed a discrepancy in RH 5.2 in the way 'struct timeval' is
defined in /usr/include/timebits.H:

struct timeval 
  {
    int tv_sec;                 /* Seconds.  */
    int tv_usec;                /* Microseconds.  */
  };

This seems incorrect since the man page for gettimeofday says:
--------------------
gettimeofday  and settimeofday can set the time as well as
a timezone.  tv is a  timeval  struct,  as  specified   in
/usr/include/sys/time.h:

struct timeval {
    long tv_sec;        /* seconds */
    long tv_usec;  /* microseconds */
};
--------------------

However, on RH 5.2 x86, the members are 'time_t' rather than 'int'.

This means that code that previously did this:
    gettimeofday( &p, &q ) ;
    s = ctime( &p.tv_sec ) ;

now needs to do this:

    time_t tmp ;
    gettimeofday( &p, &q ) ;
    tmp = p.tv_sec ;
    s = ctime( &tmp ) ;

Does anyone know if this is intentional or a bug ?  Thanks.

Ram


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: struct timeval problem
  1999-01-15 21:00 struct timeval problem Munagala V. S. Ramanath
@ 1999-01-15 21:13 ` Greg Lindahl
  1999-01-16  3:43   ` Richard Henderson
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Lindahl @ 1999-01-15 21:13 UTC (permalink / raw)
  To: axp-list

> Just noticed a discrepancy in RH 5.2 in the way 'struct timeval' is
> defined in /usr/include/timebits.H:

All non-Linux OSes seem to have a long for those fields. Linux has
been confused about it for a while, and I am unhappy to see that the
confusion is continuing. Doesn't anybody own a copy of the standard?

> This means that code that previously did this:
>     gettimeofday( &p, &q ) ;
>     s = ctime( &p.tv_sec ) ;
> 
> now needs to do this:
> 
>     time_t tmp ;
>     gettimeofday( &p, &q ) ;
>     tmp = p.tv_sec ;
>     s = ctime( &tmp ) ;

That is already required since I don't think that tv_sec is supposed
to be a time_t... a bug in the standard. But we have to follow the
bugs, too.

-- greg


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: struct timeval problem
  1999-01-15 21:13 ` Greg Lindahl
@ 1999-01-16  3:43   ` Richard Henderson
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Henderson @ 1999-01-16  3:43 UTC (permalink / raw)
  To: axp-list

On Fri, Jan 15, 1999 at 04:13:34PM -0500, Greg Lindahl wrote:
> > Just noticed a discrepancy in RH 5.2 in the way 'struct timeval' is
> > defined in /usr/include/timebits.H:

Yes, you've caught a real standards conformance bug.  This was fixed
early in the glibc 2.1 development cycle; glibc 2.1 is going through
test releases prior to final right now.

Binary compatibility (against libc at least) is handled with ELF
symbol versioning on the related functions.

> That is already required since I don't think that tv_sec is supposed
> to be a time_t... a bug in the standard. But we have to follow the
> bugs, too.

tv_sec is required to be a time_t.  I don't recall off-hand what
POSIX sez for tv_usec -- probably `long'.  I was thinking one of
Single Unix or UNIX98 defined a useconds_t or some such.


r~


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1999-01-16  4:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1999-01-15 21:00 struct timeval problem Munagala V. S. Ramanath
1999-01-15 21:13 ` Greg Lindahl
1999-01-16  3:43   ` Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox