Add macros to determine the length of an integer type in string form.

Adapted from answer #6 in:
https://stackoverflow.com/questions/10536207/ansi-c-maximum-number-of-characters-printing-a-decimal-int
This commit is contained in:
Todd C. Miller
2023-09-19 15:15:02 -06:00
parent 221a10340c
commit d53bbb54b2
12 changed files with 16 additions and 12 deletions

View File

@@ -136,6 +136,10 @@
#define sudo_isset(_a, _i) ((_a)[(_i) / NBBY] & (1<<((_i) % NBBY)))
#define sudo_isclr(_a, _i) (((_a)[(_i) / NBBY] & (1<<((_i) % NBBY))) == 0)
/* Macros to determine the length of a type in string form. */
#define STRLEN_MAX_UNSIGNED(t) (((sizeof(t) * 8 * 1233) >> 12) + 1)
#define STRLEN_MAX_SIGNED(t) (STRLEN_MAX_UNSIGNED(t) + ((sizeof(t) == 8) ? 0 : 1))
/* sudo_parseln() flags */
#define PARSELN_COMM_BOL 0x01 /* comments only at beginning of line */
#define PARSELN_CONT_IGN 0x02 /* ignore line continuation char */