X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=include%2Fsafe-ctype.h;h=b6d585cded5ec71689f3469d822548e152134f9f;hb=refs%2Fheads%2Fsandbox%2Fvbarinov%2Fupstream233;hp=977653c75a2fb40ba43433c3075b7830ad77d573;hpb=39cd2525463aab63af6a9b111a01fb2b37e1733a;p=external%2Fbinutils.git diff --git a/include/safe-ctype.h b/include/safe-ctype.h index 977653c..b6d585c 100644 --- a/include/safe-ctype.h +++ b/include/safe-ctype.h @@ -1,6 +1,6 @@ /* replacement macros. - Copyright (C) 2000 Free Software Foundation, Inc. + Copyright (C) 2000-2019 Free Software Foundation, Inc. Contributed by Zack Weinberg . This file is part of the libiberty library. @@ -16,8 +16,8 @@ Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with libiberty; see the file COPYING.LIB. If -not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. */ +not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, +Boston, MA 02110-1301, USA. */ /* This is a compatible replacement of the standard C library's with the following properties: @@ -35,9 +35,22 @@ Boston, MA 02111-1307, USA. */ #ifndef SAFE_CTYPE_H #define SAFE_CTYPE_H -#ifdef isalpha - #error "safe-ctype.h and ctype.h may not be used simultaneously" +/* Determine host character set. */ +#define HOST_CHARSET_UNKNOWN 0 +#define HOST_CHARSET_ASCII 1 +#define HOST_CHARSET_EBCDIC 2 + +#if '\n' == 0x0A && ' ' == 0x20 && '0' == 0x30 \ + && 'A' == 0x41 && 'a' == 0x61 && '!' == 0x21 +# define HOST_CHARSET HOST_CHARSET_ASCII #else +# if '\n' == 0x15 && ' ' == 0x40 && '0' == 0xF0 \ + && 'A' == 0xC1 && 'a' == 0x81 && '!' == 0x5A +# define HOST_CHARSET HOST_CHARSET_EBCDIC +# else +# define HOST_CHARSET HOST_CHARSET_UNKNOWN +# endif +#endif /* Categories. */ @@ -63,18 +76,15 @@ enum { _sch_isalnum = _sch_isalpha|_sch_isdigit, /* A-Za-z0-9 */ _sch_isidnum = _sch_isidst|_sch_isdigit, /* A-Za-z0-9_ */ _sch_isgraph = _sch_isalnum|_sch_ispunct, /* isprint and not space */ - _sch_iscppsp = _sch_isvsp|_sch_isnvsp /* isspace + \0 */ + _sch_iscppsp = _sch_isvsp|_sch_isnvsp, /* isspace + \0 */ + _sch_isbasic = _sch_isprint|_sch_iscppsp /* basic charset of ISO C + (plus ` and @) */ }; -/* This code fundamentally assumes that a byte is 8 bits. Test this - at compile time. */ - -extern int a_byte_isnt_eight_bits[(unsigned char)256 == 0 ? 1 : -1]; - /* Character classification. */ extern const unsigned short _sch_istable[256]; -#define _sch_test(c, bit) (_sch_istable[(int)(unsigned char)(c)] & (bit)) +#define _sch_test(c, bit) (_sch_istable[(c) & 0xff] & (unsigned short)(bit)) #define ISALPHA(c) _sch_test(c, _sch_isalpha) #define ISALNUM(c) _sch_test(c, _sch_isalnum) @@ -91,6 +101,7 @@ extern const unsigned short _sch_istable[256]; #define ISIDNUM(c) _sch_test(c, _sch_isidnum) #define ISIDST(c) _sch_test(c, _sch_isidst) +#define IS_ISOBASIC(c) _sch_test(c, _sch_isbasic) #define IS_VSPACE(c) _sch_test(c, _sch_isvsp) #define IS_NVSPACE(c) _sch_test(c, _sch_isnvsp) #define IS_SPACE_OR_NUL(c) _sch_test(c, _sch_iscppsp) @@ -98,8 +109,42 @@ extern const unsigned short _sch_istable[256]; /* Character transformation. */ extern const unsigned char _sch_toupper[256]; extern const unsigned char _sch_tolower[256]; -#define TOUPPER(c) _sch_toupper[(int)(unsigned char)(c)] -#define TOLOWER(c) _sch_tolower[(int)(unsigned char)(c)] +#define TOUPPER(c) _sch_toupper[(c) & 0xff] +#define TOLOWER(c) _sch_tolower[(c) & 0xff] + +/* Prevent the users of safe-ctype.h from accidently using the routines + from ctype.h. Initially, the approach was to produce an error when + detecting that ctype.h has been included. But this was causing + trouble as ctype.h might get indirectly included as a result of + including another system header (for instance gnulib's stdint.h). + So we include ctype.h here and then immediately redefine its macros. */ + +#include +#undef isalpha +#define isalpha(c) do_not_use_isalpha_with_safe_ctype +#undef isalnum +#define isalnum(c) do_not_use_isalnum_with_safe_ctype +#undef iscntrl +#define iscntrl(c) do_not_use_iscntrl_with_safe_ctype +#undef isdigit +#define isdigit(c) do_not_use_isdigit_with_safe_ctype +#undef isgraph +#define isgraph(c) do_not_use_isgraph_with_safe_ctype +#undef islower +#define islower(c) do_not_use_islower_with_safe_ctype +#undef isprint +#define isprint(c) do_not_use_isprint_with_safe_ctype +#undef ispunct +#define ispunct(c) do_not_use_ispunct_with_safe_ctype +#undef isspace +#define isspace(c) do_not_use_isspace_with_safe_ctype +#undef isupper +#define isupper(c) do_not_use_isupper_with_safe_ctype +#undef isxdigit +#define isxdigit(c) do_not_use_isxdigit_with_safe_ctype +#undef toupper +#define toupper(c) do_not_use_toupper_with_safe_ctype +#undef tolower +#define tolower(c) do_not_use_tolower_with_safe_ctype -#endif /* no ctype.h */ #endif /* SAFE_CTYPE_H */