xref: /netbsd-src/lib/libc/gen/ctype.3 (revision 7c3f385475147b6e1c4753f2bee961630e2dfc40)
1.\"	$NetBSD: ctype.3,v 1.18 2008/04/17 16:24:40 apb Exp $
2.\"
3.\" Copyright (c) 1991 Regents of the University of California.
4.\" All rights reserved.
5.\"
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\"     @(#)ctype.3	6.5 (Berkeley) 4/19/91
32.\"
33.Dd April 17, 2008
34.Dt CTYPE 3
35.Os
36.Sh NAME
37.Nm isalpha ,
38.Nm isupper ,
39.Nm islower ,
40.Nm isdigit ,
41.Nm isxdigit ,
42.Nm isalnum ,
43.Nm isspace ,
44.Nm ispunct ,
45.Nm isprint ,
46.Nm isgraph ,
47.Nm iscntrl ,
48.Nm isblank ,
49.Nm toupper ,
50.Nm tolower ,
51.Nd character classification and mapping functions
52.Sh LIBRARY
53.Lb libc
54.Sh SYNOPSIS
55.In ctype.h
56.Fa int c
57.br
58.Fn isalpha c
59.Fn isupper c
60.Fn islower c
61.Fn isdigit c
62.Fn isxdigit c
63.Fn isalnum c
64.Fn isspace c
65.Fn ispunct c
66.Fn isprint c
67.Fn isgraph c
68.Fn iscntrl c
69.Fn isblank c
70.Fn toupper c
71.Fn tolower c
72.Sh DESCRIPTION
73The above functions perform character tests and conversions on the integer
74.Ar c .
75.Pp
76See the specific manual pages for information about the
77test or conversion performed by each function.
78.Sh EXAMPLES
79To print an upper-case version of a string on stdout, use the following
80code:
81.Bd -literal
82const char *s = ...;
83while (*s != '\\0') {
84    putchar(toupper((int)(unsigned char)*s));
85    s++;
86}
87.Ed
88.Sh SEE ALSO
89.Xr isalnum 3 ,
90.Xr isalpha 3 ,
91.Xr isblank 3 ,
92.Xr iscntrl 3 ,
93.Xr isdigit 3 ,
94.Xr isgraph 3 ,
95.Xr islower 3 ,
96.Xr isprint 3 ,
97.Xr ispunct 3 ,
98.Xr isspace 3 ,
99.Xr isupper 3 ,
100.Xr isxdigit 3 ,
101.Xr tolower 3 ,
102.Xr toupper 3 ,
103.Xr ascii 7
104.Sh STANDARDS
105These functions, with the exception of
106.Fn isblank ,
107conform to
108.St -ansiC .
109.Sh CAVEATS
110The first argument of these functions is of type
111.Vt int ,
112but only a very restricted subset of values are actually valid.
113The argument must either be the value of the macro
114.Dv EOF
115(which has a negative value),
116or must be a non-negative value within the range representable as
117.Vt unsigned char .
118Passing invalid values leads to undefined behavior.
119.Pp
120Values of type
121.Vt int
122that were returned by
123.Xr getc 3 ,
124.Xr fgetc 3 ,
125and similar functions or macros
126are already in the correct range, and may be safely passed to these
127.Nm ctype
128functions without any casts.
129.Pp
130Values of type
131.Vt char
132or
133.Vt signed char
134must first be cast to
135.Vt unsigned char ,
136to ensure that the values are within the correct range.
137The result should then be cast to
138.Vt int
139to avoid warnings from some compilers.
140Casting a negative-valued
141.Vt char
142or
143.Vt signed char
144directly to
145.Vt int
146will produce a negative-valued
147.Vt int ,
148which will be outside the range of allowed values
149(unless it happens to be equal to
150.Dv EOF ,
151but even that would not give the desired result).
152