Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 2 Jun 2001 20:33:08 -0400 (EDT)
From:      Garrett Wollman <wollman@khavrinen.lcs.mit.edu>
To:        Yoshihiro.Koya@math.yokohama-cu.ac.jp
Cc:        stable@freebsd.org
Subject:   Re: time_t definition is worng
Message-ID:  <200106030033.UAA57864@khavrinen.lcs.mit.edu>
In-Reply-To: <20010603012933K.koya@pluto.math.yokohama-cu.ac.jp>
References:  <20010602085237.A73968@dragon.nuxi.com> <20010603010518C.koya@pluto.math.yokohama-cu.ac.jp> <20010602091643.C73968@dragon.nuxi.com>

next in thread | previous in thread | raw e-mail | index | archive | help
In article <20010603012933K.koya@pluto.math.yokohama-cu.ac.jp> you write:

>The pw->pw_chage and pw->pw_passwd are of time_t. But, in the above, 
>%ld is used for them.

This is a general problem; there is no portable way to print a time_t
that does not include the following steps:

1) Determine whether time_t is integral, floating-point, or (new in
C99) complex.

2) If time_t is integral, determine whether it is signed or unsigned.

3) If the compilation environment is not C99, and time_t is integral,
cast to (appropriately signed) long and print with %ld or %lu as
appropriate.  If the compilation environment is (close enough to) C99,
case to (appropriately signed) intmax_t and print with %jd or %ju as
appropriate.  If time_t is floating-point, cast to long double and
print with %Lf.  If time_t is complex, you have a lot more serious
problems to deal with.

There is a simple way around this, for POSIX systems only: use
strftime() with the %s format.

-GAWollman

-- 
Garrett A. Wollman   | O Siem / We are all family / O Siem / We're all the same
wollman@lcs.mit.edu  | O Siem / The fires of freedom 
Opinions not those of| Dance in the burning flame
MIT, LCS, CRS, or NSA|                     - Susan Aglukark and Chad Irschick

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-stable" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200106030033.UAA57864>