svn commit: r252074 - head/sys/fs/nfsclient

Bruce Evans brde at optusnet.com.au
Sun Jun 23 00:44:40 UTC 2013


On Sat, 22 Jun 2013, Garrett Cooper wrote:

> On Jun 22, 2013, at 11:22 AM, Steven Hartland wrote:
>
>> I thought the use of PRIu64  was frowned on?
>
> 	It is in FreeBSD, unlike Linux (for better or for worse). It should be cast with either intmax_t or uintmax_t and use %jd or %ju.

Do you mean that this mistake is not even possible in Linux (the kernel)?
Linux-2.6.10 has no references to PRI* or SCN*.  It doesn't even have
stdint.h.  The PRI* and SCN* bugs are in inttypes.h.  In C99, <inttypes.h>
is a historical wrapper for <stdint.h> that adds these bugs and prototypes
for strtoimax() and friends.  In the kernel, these files really shouldn't
be used.

Even in FreeBSD, it takes extra work to get these bugs.  <sys/stdint.h>
is standard pollution in <sys/systm.h>, but inttypes.h has to be
included directly about 30 files in /sys include it under any name.
Almost half of these are userland applications so they have the excuse
that <inttypes.h> is a Standard header.

Some of the includes, not counted in the 30, are in comments.  1 of
the 30 is is an include of the nonstandard header <sys/inttypes.h>.  This
file doesn't exist in FreeBSD.  Including it only defeats simple greps.
It doesn't break the build since the include is in code ifdefed for
NetBSD and OpenBSD.  sys/inttypes.h existed in FreeBSD until 2001.  It
was removed then as part of implementing the C99 headers <stdint.h>
and <inttypes.h>.  I think <inttypes.h> was the old name, and exists
now mainly to hold historical mistakes, while <stdint.h> is a C99
invention to clean up some of the mistakes, but unfortunately it wasn't
possible to clean them all.  Before 2001, FreeBSD used only the
older name inttypes.h, but only had the important parts of <stdint.h>
in it, and of course didn't have PRI* or SCN*.  The <sys> part of
<stdint.h> was created essentially by renaming sys/inttypes.h to
sys/stdint.h in 2001.

This means that there is no supported kernel include file containing the
PRI* and SCN* mistakes.  But all arches have a <machine/_inttypes.h> for
exporting these mistakes to userland.  15 of the 30 files are chummy
with this implemntation detail and include <machine/_inttypes.h> directly,
presumably so that they can have more style bugs by using PRI*.  All 15
of these files are relatively new.  <machine/_inttypes.h> was not referenced
in the kernel for several years after it was created.

Bruce


More information about the svn-src-all mailing list