diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/libbb.h | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/include/libbb.h b/include/libbb.h index d95be5c51..77c9e2888 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -1606,10 +1606,11 @@ extern const char bb_default_login_shell[]; | |||
1606 | 1606 | ||
1607 | /* We save ~500 bytes on isdigit alone. | 1607 | /* We save ~500 bytes on isdigit alone. |
1608 | * BTW, x86 likes (unsigned char) cast more than (unsigned). */ | 1608 | * BTW, x86 likes (unsigned char) cast more than (unsigned). */ |
1609 | #define isdigit(a) ((unsigned char)((a) - '0') <= 9) | 1609 | |
1610 | /* These work the same for ASCII and Unicode, | ||
1611 | * assuming no one asks "is this a *Unicode* letter?" using isalpha(letter) */ | ||
1610 | #define isascii(a) ((unsigned char)(a) <= 0x7f) | 1612 | #define isascii(a) ((unsigned char)(a) <= 0x7f) |
1611 | #define isgraph(a) ((unsigned char)(a) > ' ') | 1613 | #define isdigit(a) ((unsigned char)((a) - '0') <= 9) |
1612 | #define isprint(a) ((unsigned char)(a) >= ' ') | ||
1613 | #define isupper(a) ((unsigned char)((a) - 'A') <= ('Z' - 'A')) | 1614 | #define isupper(a) ((unsigned char)((a) - 'A') <= ('Z' - 'A')) |
1614 | #define islower(a) ((unsigned char)((a) - 'a') <= ('z' - 'a')) | 1615 | #define islower(a) ((unsigned char)((a) - 'a') <= ('z' - 'a')) |
1615 | #define isalpha(a) ((unsigned char)(((a)|0x20) - 'a') <= ('z' - 'a')) | 1616 | #define isalpha(a) ((unsigned char)(((a)|0x20) - 'a') <= ('z' - 'a')) |
@@ -1619,9 +1620,9 @@ extern const char bb_default_login_shell[]; | |||
1619 | * "\t\n\v\f\r" happen to have ASCII codes 9,10,11,12,13. | 1620 | * "\t\n\v\f\r" happen to have ASCII codes 9,10,11,12,13. |
1620 | */ | 1621 | */ |
1621 | #define isspace(a) ({ unsigned char bb__isspace = (a) - 9; bb__isspace == (' ' - 9) || bb__isspace <= (13 - 9); }) | 1622 | #define isspace(a) ({ unsigned char bb__isspace = (a) - 9; bb__isspace == (' ' - 9) || bb__isspace <= (13 - 9); }) |
1622 | 1623 | // Unsafe wrt NUL: #define ispunct(a) (strchr("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", (a)) != NULL) | |
1623 | // Bigger code: | 1624 | #define ispunct(a) (strchrnul("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", (a))[0]) |
1624 | //#define isalnum(a) ({ unsigned char bb__isalnum = (a) - '0'; bb__isalnum <= 9 || ((bb__isalnum - ('A' - '0')) & 0xdf) <= 25; }) | 1625 | // Bigger code: #define isalnum(a) ({ unsigned char bb__isalnum = (a) - '0'; bb__isalnum <= 9 || ((bb__isalnum - ('A' - '0')) & 0xdf) <= 25; }) |
1625 | #define isalnum(a) bb_ascii_isalnum(a) | 1626 | #define isalnum(a) bb_ascii_isalnum(a) |
1626 | static ALWAYS_INLINE int bb_ascii_isalnum(unsigned char a) | 1627 | static ALWAYS_INLINE int bb_ascii_isalnum(unsigned char a) |
1627 | { | 1628 | { |
@@ -1640,11 +1641,6 @@ static ALWAYS_INLINE int bb_ascii_isxdigit(unsigned char a) | |||
1640 | b = (a|0x20) - 'a'; | 1641 | b = (a|0x20) - 'a'; |
1641 | return b <= 'f' - 'a'; | 1642 | return b <= 'f' - 'a'; |
1642 | } | 1643 | } |
1643 | |||
1644 | // Unsafe wrt NUL! | ||
1645 | //#define ispunct(a) (strchr("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", (a)) != NULL) | ||
1646 | #define ispunct(a) (strchrnul("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", (a))[0]) | ||
1647 | |||
1648 | #define toupper(a) bb_ascii_toupper(a) | 1644 | #define toupper(a) bb_ascii_toupper(a) |
1649 | static ALWAYS_INLINE unsigned char bb_ascii_toupper(unsigned char a) | 1645 | static ALWAYS_INLINE unsigned char bb_ascii_toupper(unsigned char a) |
1650 | { | 1646 | { |
@@ -1662,6 +1658,14 @@ static ALWAYS_INLINE unsigned char bb_ascii_tolower(unsigned char a) | |||
1662 | return a; | 1658 | return a; |
1663 | } | 1659 | } |
1664 | 1660 | ||
1661 | /* In ASCII and Unicode, these are likely to be very different. | ||
1662 | * Let's prevent ambiguous usage from the start */ | ||
1663 | #define isgraph(a) isgraph_is_ambiguous_dont_use(a) | ||
1664 | #define isprint(a) isprint_is_ambiguous_dont_use(a) | ||
1665 | /* NB: must not treat EOF as isgraph or isprint */ | ||
1666 | #define isgraph_asciionly(a) ((unsigned)((a) - 0x21) <= 0x7e - 0x21) | ||
1667 | #define isprint_asciionly(a) ((unsigned)((a) - 0x20) <= 0x7e - 0x20) | ||
1668 | |||
1665 | 1669 | ||
1666 | POP_SAVED_FUNCTION_VISIBILITY | 1670 | POP_SAVED_FUNCTION_VISIBILITY |
1667 | 1671 | ||