Subject: Re: magic symlinks: uid keyword translation
To: None <tech-kern@netbsd.org>
From: Christos Zoulas <christos@astron.com>
List: tech-kern
Date: 10/30/2006 16:50:23
In article <20061030161013.GN10449@apb-laptoy.apb.alt.za>,
Alan Barrett  <apb@cequrux.com> wrote:
>On Mon, 30 Oct 2006, Stephen Borrill wrote:
>> It's numeric UID not user name, so 16 will be fine.
>
>11 would be enough for unsigned 32-bit uid_t.  16 is not enough for
>64-bit uid_t, so the choice of 16 seems rather arbitrary to me.
>
>Perhaps we should define something like
>
>    #define __MAX_DIGITS_FOR_UNSIGNED_TYPE(t) \
>	((sizeof(t) * CHAR_BIT + 2) / 3)
>    #define __MAX_DIGITS_FOR_SIGNED_TYPE(t) \
>	((sizeof(t) * CHAR_BIT + 2) / 3 + 1)
>
>and then people could do
>
>    char buf[__MAX_DIGITS_FOR_UNSIGNED_TYPE(uid_t) + 1];

The name is a little too long, but very nice. We should write the second in
terms of the first:

#define __MAX_DIGITS_FOR_SIGNED_TYPE(t) \
    (__MAX_DIGITS_FOR_UNSIGNED_TYPE(t) + 1)

christos