[pacman-dev] [PATCH 2/2] More consistent printing of off_t and time_t

Xavier shiningxc at gmail.com
Mon Nov 16 05:30:31 EST 2009


On Mon, Nov 16, 2009 at 2:57 AM, Dan McGee <dpmcgee at gmail.com> wrote:
> On Sat, Nov 14, 2009 at 1:30 PM, Xavier Chantry <shiningxc at gmail.com> wrote:
>> %ld for type_t
> What is type_t?
>

lol, I remember I had a bug when I typed (hmm) that.
It was meant to be time_t

>> %"PRId64" for off_t
> Can you explain why this works for off_t?
>
> It looks like we have three "rogue" types here to be concerned with-
> time_t, size_t, and off_t. I'm not sure that removing all of the casts
> was the right decision, but hopefully I can be learned if you point me
> in the right direction.
>

I am not sure either.

I looked again at various references :
- man 3 printf
- man types.h
- man inttypes.h

What about the following :
time_t : %ld
size_t : %zu
ssize_t : %zd
off_t : %jd or %"PRIdMAX" and cast to intmax_t

For other long unsigned types (is there any?) : %ju or %"PRIuMAX" and
cast to uintmax_t

I checked netbsd, freebsd and osx man pages : they all document the z
and j length modifier
http://www.freebsd.org/cgi/man.cgi?query=printf&sektion=3&apropos=0&manpath=FreeBSD+7.2-RELEASE
http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man3/printf.3.html#//apple_ref/doc/man/3/printf
http://netbsd.gw.com/cgi-bin/man-cgi?printf+3+NetBSD-current

For cygwin, the man page I found inside this tarball does not document it :
http://cygwin.elite-systems.org/release/cygwin-doc/cygwin-doc-1.4-4.tar.bz2
But we are already using j and z in the current code and it did not
cause any problems.

So my final proposal :
time_t : %ld
size_t : %zu
ssize_t : %zd
off_t : %jd and cast to intmax_t
other long unsigned types : %ju and cast to uintmax_t


More information about the pacman-dev mailing list