diff options
author | Guy Harris <guy@alum.mit.edu> | 2018-12-10 23:16:45 -0800 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2018-12-10 23:16:45 -0800 |
commit | 7df90fa2a2b317d66750a8e595b695e6604672ac (patch) | |
tree | 954fd39df10502a6d16d608d1857bddf0bd0190e | |
parent | 877753b5c84dfb2236a9646713bb8072f03b3c0b (diff) | |
download | tcpdump-7df90fa2a2b317d66750a8e595b695e6604672ac.tar.gz |
Add, and use, macros to do locale-independent case mapping.
This means we get the same behavior in Turkish locales (where, if we
aren't in the C locale, we might get lower-case "i" mapped to upper-case
"I with dot" and upper-case "I" mapped to lower-case "i without dot),
and may also suppress some shortening warnings from MSVC.
-rw-r--r-- | netdissect.h | 24 | ||||
-rw-r--r-- | print-zephyr.c | 2 | ||||
-rw-r--r-- | util-print.c | 2 |
3 files changed, 23 insertions, 5 deletions
diff --git a/netdissect.h b/netdissect.h index 0bacbfc7..36adf852 100644 --- a/netdissect.h +++ b/netdissect.h @@ -350,15 +350,33 @@ extern void txtproto_print(netdissect_options *, const u_char *, u_int, /* * Locale-independent macros for testing character properties and - * stripping the 8th bit from characters. Assumed to be handed - * a value between 0 and 255, i.e. don't hand them a char, as - * those might be in the range -128 to 127. + * stripping the 8th bit from characters. + * + * Byte values outside the ASCII range are considered unprintable, so + * both ND_ISPRINT() and ND_ISGRAPH() return "false" for them. + * + * Assumed to be handed a value between 0 and 255, i.e. don't hand them + * a char, as those might be in the range -128 to 127. */ #define ND_ISASCII(c) (!((c) & 0x80)) /* value is an ASCII code point */ #define ND_ISPRINT(c) ((c) >= 0x20 && (c) <= 0x7E) #define ND_ISGRAPH(c) ((c) > 0x20 && (c) <= 0x7E) #define ND_TOASCII(c) ((c) & 0x7F) +/* + * Locale-independent macros for coverting to upper or lower case. + * + * Byte values outside the ASCII range are not converted. Byte values + * *in* the ASCII range are converted to byte values in the ASCII range; + * in particular, 'i' is upper-cased to 'I" and 'I' is lower-cased to 'i', + * even in Turkish locales. + * + * Assumed to be handed a value between 0 and 255, i.e. don't hand + * them a char, as those might be in the range -128 to 127. + */ +#define ND_TOLOWER(c) (((c) >= 'A' && (c) <= 'Z') ? (c) - 'A' + 'a' : (c)) +#define ND_TOUPPER(c) (((c) >= 'a' && (c) <= 'z') ? (c) - 'a' + 'z' : (c)) + #if (defined(__i386__) || defined(_M_IX86) || defined(__X86__) || defined(__x86_64__) || defined(_M_X64)) || \ (defined(__arm__) || defined(_M_ARM) || defined(__aarch64__)) || \ (defined(__m68k__) && (!defined(__mc68000__) && !defined(__mc68010__))) || \ diff --git a/print-zephyr.c b/print-zephyr.c index bce7394b..d2fbf4d0 100644 --- a/print-zephyr.c +++ b/print-zephyr.c @@ -134,7 +134,7 @@ str_to_lower(const char *string) zb_string = z_buf; while (*zb_string) { - *zb_string = tolower((unsigned char)(*zb_string)); + *zb_string = ND_TOLOWER((unsigned char)(*zb_string)); zb_string++; } diff --git a/util-print.c b/util-print.c index 5a8c8fe5..aa6cf87f 100644 --- a/util-print.c +++ b/util-print.c @@ -892,7 +892,7 @@ txtproto_print(netdissect_options *ndo, const u_char *pptr, u_int len, /* Capitalize the protocol name */ for (pnp = protoname; *pnp != '\0'; pnp++) - ND_PRINT("%c", toupper((u_char)*pnp)); + ND_PRINT("%c", ND_TOUPPER((u_char)*pnp)); if (print_this) { /* |