Printing of off_t and size_t values

Martin Husemann <[email protected]>
Newsgroups gmane.os.netbsd.devel.general
Message-ID <[email protected]>
A short discussion after a recent commit on source-changes brought this topic
up again and I tried to find all affected files (there are 235) - and then
noticed share/misc/style is among them. It suggests:

        /*
         * To printf 64 bit quantities, use %ll and cast to (long long).
         */
        printf("The size of %s is %lld\n", p, (long long)sb->st_size);

Nowadays we can do better. I suggest to change this into:

        /*
         * To printf size_t quantities, use %zd:
         */
        printf("The size of %s is %zd\n", p, sb->st_size);
        
        /*
         * To printf off_t (or other 64 bit) quantities, use PRId64
         * from <inttypes.h>:
         */
        printf("Read error at offset %" PRId64 "\n", o);

Is that OK?
One option is to leave out the first part and use PRId64 (and friends) always.

I volunteer to change all occurances in-tree to whatever we agree upon (skiping
gnu/dist).

Martin
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.