X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Ftype-props.h;h=8c83ea6fc37d6c77e41555f7c79c409b542fbcc7;hb=28c5588e8e1a8d091c5d2275232c35f2968a97fa;hp=efaf4a5de48c649d7872663ce6809c04aa832111;hpb=a14bc59fb8f27db193d74662dc9c5cb8237177ef;p=sliver-openvswitch.git diff --git a/lib/type-props.h b/lib/type-props.h index efaf4a5de..8c83ea6fc 100644 --- a/lib/type-props.h +++ b/lib/type-props.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008 Nicira Networks. + * Copyright (c) 2008, 2011 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ #include #define TYPE_IS_INTEGER(TYPE) ((TYPE) 1.5 == (TYPE) 1) -#define TYPE_IS_SIGNED(TYPE) ((TYPE) 0 > (TYPE) -1) +#define TYPE_IS_SIGNED(TYPE) ((TYPE) 1 > (TYPE) -1) #define TYPE_VALUE_BITS(TYPE) (sizeof(TYPE) * CHAR_BIT - TYPE_IS_SIGNED(TYPE)) #define TYPE_MINIMUM(TYPE) (TYPE_IS_SIGNED(TYPE) \ ? ~(TYPE)0 << TYPE_VALUE_BITS(TYPE) \ @@ -29,4 +29,11 @@ ? ~(~(TYPE)0 << TYPE_VALUE_BITS(TYPE)) \ : (TYPE)-1) +/* Number of decimal digits required to format an integer of the given TYPE. + * Includes space for a sign, if TYPE is signed, but not for a null + * terminator. + * + * The value is an overestimate. */ +#define INT_STRLEN(TYPE) (TYPE_IS_SIGNED(TYPE) + TYPE_VALUE_BITS(TYPE) / 3 + 1) + #endif /* type-props.h */