Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
2/*
3 * ctype function definitions for NOLIBC
4 * Copyright (C) 2017-2021 Willy Tarreau <w@1wt.eu>
5 */
6
7/* make sure to include all global symbols */
8#include "nolibc.h"
9
10#ifndef _NOLIBC_CTYPE_H
11#define _NOLIBC_CTYPE_H
12
13#include "std.h"
14
15/*
16 * As much as possible, please keep functions alphabetically sorted.
17 */
18
19static __attribute__((unused))
20int isascii(int c)
21{
22 /* 0x00..0x7f */
23 return (unsigned int)c <= 0x7f;
24}
25
26static __attribute__((unused))
27int isblank(int c)
28{
29 return c == '\t' || c == ' ';
30}
31
32static __attribute__((unused))
33int iscntrl(int c)
34{
35 /* 0x00..0x1f, 0x7f */
36 return (unsigned int)c < 0x20 || c == 0x7f;
37}
38
39static __attribute__((unused))
40int isdigit(int c)
41{
42 return (unsigned int)(c - '0') < 10;
43}
44
45static __attribute__((unused))
46int isgraph(int c)
47{
48 /* 0x21..0x7e */
49 return (unsigned int)(c - 0x21) < 0x5e;
50}
51
52static __attribute__((unused))
53int islower(int c)
54{
55 return (unsigned int)(c - 'a') < 26;
56}
57
58static __attribute__((unused))
59int isprint(int c)
60{
61 /* 0x20..0x7e */
62 return (unsigned int)(c - 0x20) < 0x5f;
63}
64
65static __attribute__((unused))
66int isspace(int c)
67{
68 /* \t is 0x9, \n is 0xA, \v is 0xB, \f is 0xC, \r is 0xD */
69 return ((unsigned int)c == ' ') || (unsigned int)(c - 0x09) < 5;
70}
71
72static __attribute__((unused))
73int isupper(int c)
74{
75 return (unsigned int)(c - 'A') < 26;
76}
77
78static __attribute__((unused))
79int isxdigit(int c)
80{
81 return isdigit(c) || (unsigned int)(c - 'A') < 6 || (unsigned int)(c - 'a') < 6;
82}
83
84static __attribute__((unused))
85int isalpha(int c)
86{
87 return islower(c) || isupper(c);
88}
89
90static __attribute__((unused))
91int isalnum(int c)
92{
93 return isalpha(c) || isdigit(c);
94}
95
96static __attribute__((unused))
97int ispunct(int c)
98{
99 return isgraph(c) && !isalnum(c);
100}
101
102#endif /* _NOLIBC_CTYPE_H */