chiark / gitweb /
[PATCH] sync up with the 0.84 version of klibc
[elogind.git] / klibc / klibc / include / ctype.h
1 /*
2  * ctype.h
3  *
4  * This assumes ISO 8859-1, being a reasonable superset of ASCII.
5  */
6
7 #ifndef _CTYPE_H
8 #define _CTYPE_H
9
10 #ifndef __CTYPE_NO_INLINE
11 # define __ctype_inline extern __inline__
12 #else
13 # define __ctype_inline
14 #endif
15
16 /*
17  * This relies on the following definitions:
18  *
19  * cntrl = !print
20  * alpha = upper|lower
21  * graph = punct|alpha|digit
22  * blank = '\t' || ' ' (per POSIX requirement)
23  */
24 enum {
25   __ctype_upper  = (1 << 0),
26   __ctype_lower  = (1 << 1),
27   __ctype_digit  = (1 << 2),
28   __ctype_xdigit = (1 << 3),
29   __ctype_space  = (1 << 4),
30   __ctype_print  = (1 << 5),
31   __ctype_punct  = (1 << 6)
32 };
33
34 extern const unsigned char __ctypes[];
35
36 __ctype_inline int isalnum(int __c)
37 {
38   return __ctypes[__c+1] &
39     (__ctype_upper|__ctype_lower|__ctype_digit);
40 }
41
42 __ctype_inline int isalpha(int __c)
43 {
44   return __ctypes[__c+1] &
45     (__ctype_upper|__ctype_lower);
46 }
47
48 __ctype_inline int isascii(int __c)
49 {
50   return !(__c & ~0x7f);
51 }
52
53 __ctype_inline int isblank(int __c)
54 {
55   return (__c == '\t') || (__c == ' ');
56 }
57
58 __ctype_inline int iscntrl(int __c)
59 {
60   return (__c >= 0) && !(__ctypes[__c+1] & __ctype_print);
61 }
62
63 __ctype_inline int isdigit(int __c)
64 {
65   return __ctypes[__c+1] & __ctype_digit;
66 }
67
68 __ctype_inline int isgraph(int __c)
69 {
70   return __ctypes[__c+1] &
71     (__ctype_upper|__ctype_lower|__ctype_digit|__ctype_punct);
72 }
73
74 __ctype_inline int islower(int __c)
75 {
76   return __ctypes[__c+1] & __ctype_lower;
77 }
78
79 __ctype_inline int isprint(int __c)
80 {
81   return __ctypes[__c+1] & __ctype_print;
82 }
83
84 __ctype_inline int ispunct(int __c)
85 {
86   return __ctypes[__c+1] & __ctype_punct;
87 }
88
89 __ctype_inline int isspace(int __c)
90 {
91   return __ctypes[__c+1] & __ctype_space;
92 }
93
94 __ctype_inline int isupper(int __c)
95 {
96   return __ctypes[__c+1] & __ctype_upper;
97 }
98
99 __ctype_inline int isxdigit(int __c)
100 {
101   return __ctypes[__c+1] & __ctype_xdigit;
102 }
103
104 /* Note: this is decimal, not hex, to avoid accidental promotion to unsigned */
105 #define _toupper(__c) ((__c) & ~32)
106 #define _tolower(__c) ((__c) | 32)
107
108 __ctype_inline int toupper(int __c)
109 {
110   return islower(__c) ? _toupper(__c) : __c;
111 }
112
113 __ctype_inline int tolower(int __c)
114 {
115   return isupper(__c) ? _tolower(__c) : __c;
116 }
117
118 #endif /* _CTYPE_H */