ctype.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*-
  2. * SPDX-License-Identifier: BSD-3-Clause
  3. *
  4. * Copyright (c) 1989, 1993
  5. * The Regents of the University of California. All rights reserved.
  6. * (c) UNIX System Laboratories, Inc.
  7. * All or some portions of this file are derived from material licensed
  8. * to the University of California by American Telephone and Telegraph
  9. * Co. or Unix System Laboratories, Inc. and are reproduced herein with
  10. * the permission of UNIX System Laboratories, Inc.
  11. *
  12. * This code is derived from software contributed to Berkeley by
  13. * Paul Borman at Krystal Technologies.
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions
  17. * are met:
  18. * 1. Redistributions of source code must retain the above copyright
  19. * notice, this list of conditions and the following disclaimer.
  20. * 2. Redistributions in binary form must reproduce the above copyright
  21. * notice, this list of conditions and the following disclaimer in the
  22. * documentation and/or other materials provided with the distribution.
  23. * 3. Neither the name of the University nor the names of its contributors
  24. * may be used to endorse or promote products derived from this software
  25. * without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  28. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  29. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  30. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  31. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  33. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  34. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  35. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  36. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  37. * SUCH DAMAGE.
  38. */
  39. #ifndef _CTYPE_H_
  40. #define _CTYPE_H_
  41. #include <sys/cdefs.h>
  42. #include <sys/_types.h>
  43. #include <_ctype.h>
  44. __BEGIN_DECLS
  45. int isalnum(int);
  46. int isalpha(int);
  47. int iscntrl(int);
  48. int isdigit(int);
  49. int isgraph(int);
  50. int islower(int);
  51. int isprint(int);
  52. int ispunct(int);
  53. int isspace(int);
  54. int isupper(int);
  55. int isxdigit(int);
  56. int tolower(int);
  57. int toupper(int);
  58. #if __XSI_VISIBLE
  59. int isascii(int);
  60. int toascii(int);
  61. #endif
  62. #if __ISO_C_VISIBLE >= 1999
  63. int isblank(int);
  64. #endif
  65. #if __BSD_VISIBLE
  66. int digittoint(int);
  67. int ishexnumber(int);
  68. int isideogram(int);
  69. int isnumber(int);
  70. int isphonogram(int);
  71. int isrune(int);
  72. int isspecial(int);
  73. #endif
  74. #if __POSIX_VISIBLE >= 200809 || defined(_XLOCALE_H_)
  75. #include <xlocale/_ctype.h>
  76. #endif
  77. __END_DECLS
  78. #ifndef __cplusplus
  79. #define isalnum(c) __sbistype((c), _CTYPE_A|_CTYPE_D|_CTYPE_N)
  80. #define isalpha(c) __sbistype((c), _CTYPE_A)
  81. #define iscntrl(c) __sbistype((c), _CTYPE_C)
  82. #define isdigit(c) __sbistype((c), _CTYPE_D)
  83. #define isgraph(c) __sbistype((c), _CTYPE_G)
  84. #define islower(c) __sbistype((c), _CTYPE_L)
  85. #define isprint(c) __sbistype((c), _CTYPE_R)
  86. #define ispunct(c) __sbistype((c), _CTYPE_P)
  87. #define isspace(c) __sbistype((c), _CTYPE_S)
  88. #define isupper(c) __sbistype((c), _CTYPE_U)
  89. #define isxdigit(c) __sbistype((c), _CTYPE_X)
  90. #define tolower(c) __sbtolower(c)
  91. #define toupper(c) __sbtoupper(c)
  92. #endif /* !__cplusplus */
  93. #if __XSI_VISIBLE
  94. /*
  95. * POSIX.1-2001 specifies _tolower() and _toupper() to be macros equivalent to
  96. * tolower() and toupper() respectively, minus extra checking to ensure that
  97. * the argument is a lower or uppercase letter respectively. We've chosen to
  98. * implement these macros with the same error checking as tolower() and
  99. * toupper() since this doesn't violate the specification itself, only its
  100. * intent. We purposely leave _tolower() and _toupper() undocumented to
  101. * discourage their use.
  102. *
  103. * XXX isascii() and toascii() should similarly be undocumented.
  104. */
  105. #define _tolower(c) __sbtolower(c)
  106. #define _toupper(c) __sbtoupper(c)
  107. #define isascii(c) (((c) & ~0x7F) == 0)
  108. #define toascii(c) ((c) & 0x7F)
  109. #endif
  110. #if __ISO_C_VISIBLE >= 1999 && !defined(__cplusplus)
  111. #define isblank(c) __sbistype((c), _CTYPE_B)
  112. #endif
  113. #if __BSD_VISIBLE
  114. #define digittoint(c) __sbmaskrune((c), 0xFF)
  115. #define ishexnumber(c) __sbistype((c), _CTYPE_X)
  116. #define isideogram(c) __sbistype((c), _CTYPE_I)
  117. #define isnumber(c) __sbistype((c), _CTYPE_D|_CTYPE_N)
  118. #define isphonogram(c) __sbistype((c), _CTYPE_Q)
  119. #define isrune(c) __sbistype((c), 0xFFFFFF00L)
  120. #define isspecial(c) __sbistype((c), _CTYPE_T)
  121. #endif
  122. #endif /* !_CTYPE_H_ */