Subject: Re: magic symlinks: uid keyword translation
To: None <tech-kern@NetBSD.org>
From: Christian Biere <email@example.com>
Date: 10/30/2006 16:59:54
Stephen Borrill wrote:
> >>+ char uidtmp;
> >>+ (void)snprintf(uidtmp, sizeof(uidtmp) - 1, "%u",
> >>+ kauth_cred_getuid(p->p_cred));
> It's numeric UID not user name, so 16 will be fine.
Well, as long as you don't introduce 64-bit UIDs. 16 is more than you
need for a 32-bit value. I for one completely agree that magic numbers
are bad in almost every context for several obvious reasons. Look even
the IPv6 RFCs introduce definitions for certain buffer length albeit
every knows that an IPv6 address has 16 bytes but in most cases like
the above most people wouldn't be able to tell how much bytes you
need and they shouldn't have to.
I wonder though what's the point of the "- 1"? That's the snprintf()
I know from C99, isn't it? I admit I prefer TYPE_to_string() to
functions. Too bad, you can only return structs but not plain strings
in C. For small fixed size strings like the above case a struct
wrapper might be acceptable nonetheless.