Subject: Re: magic symlinks: uid keyword translation
To: None <tech-kern@NetBSD.org>
From: Christian Biere <christianbiere@gmx.de>
List: tech-kern
Date: 10/30/2006 17:31:35
Alan Barrett wrote:
> 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)
I don't think the user has to worry about signed or unsigned himself:
#define __MAX_STRLEN_FOR_INT_TYPE(t) \
((t) -1 < 0 ? __MAX_DIGITS_FOR_SIGNED_TYPE(t) : __MAX_DIGITS_FOR_UNSIGNED_TYPE(t))
Of course, this doesn't allow
int x;
char buf[__MAX_STRLEN_FOR_INT_TYPE(x)];
but you can always use the explicit variant in such cases.
--
Christian