1 /*
2 Copyright (c) 1989 The Regents of the University of California.
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8 1. Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 3. Neither the name of the University nor the names of its contributors
14 may be used to endorse or promote products derived from this software
15 without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 SUCH DAMAGE.
28  */
29 /*
30 FUNCTION
31 	<<isprint>>, <<isgraph>>, <<isprint_l>>, <<isgraph_l>>---printable character predicates
32 
33 INDEX
34 	isprint
35 
36 INDEX
37 	isgraph
38 
39 INDEX
40 	isprint_l
41 
42 INDEX
43 	isgraph_l
44 
45 SYNOPSIS
46 	#include <ctype.h>
47 	int isprint(int <[c]>);
48 	int isgraph(int <[c]>);
49 
50 	#include <ctype.h>
51 	int isprint_l(int <[c]>, locale_t <[locale]>);
52 	int isgraph_l(int <[c]>, locale_t <[locale]>);
53 
54 DESCRIPTION
55 <<isprint>> is a macro which classifies singlebyte charset values by table
56 lookup.  It is a predicate returning non-zero for printable characters,
57 and 0 for other character arguments.  It is defined only if <[c]> is
58 representable as an unsigned char or if <[c]> is EOF.
59 
60 <<isgraph>> behaves identically to <<isprint>>, except that space characters
61 are excluded.
62 
63 <<isprint_l>>, <<isgraph_l>> are like <<isprint>>, <<isgraph>> but perform
64 the check based on the locale specified by the locale object locale.  If
65 <[locale]> is LC_GLOBAL_LOCALE or not a valid locale object, the behaviour
66 is undefined.
67 
68 You can use a compiled subroutine instead of the macro definition by
69 undefining either macro using `<<#undef isprint>>' or `<<#undef isgraph>>',
70 or `<<#undef isprint_l>>' or `<<#undef isgraph_l>>'.
71 
72 RETURNS
73 <<isprint>>, <<isprint_l>> return non-zero if <[c]> is a printing character.
74 <<isgraph>>, <<isgraph_l>> return non-zero if <[c]> is a printing character
75 except spaces.
76 
77 PORTABILITY
78 <<isprint>> and <<isgraph>> are ANSI C.
79 
80 No supporting OS subroutines are required.
81 */
82 
83 #include <ctype.h>
84 
85 #undef isprint
86 int
isprint(int c)87 isprint (int c)
88 {
89 #if _PICOLIBC_CTYPE_SMALL
90     return ' ' <= c && c <= '~';
91 #else
92     return __CTYPE_PTR[c+1] & (_P|_U|_L|_N|_B);
93 #endif
94 }
95