1236099Sdes/*-
2236099Sdes * Copyright (c) 2012 Dag-Erling Sm��rgrav
3236099Sdes * All rights reserved.
4236099Sdes *
5236099Sdes * Redistribution and use in source and binary forms, with or without
6236099Sdes * modification, are permitted provided that the following conditions
7236099Sdes * are met:
8236099Sdes * 1. Redistributions of source code must retain the above copyright
9255376Sdes *    notice, this list of conditions and the following disclaimer.
10236099Sdes * 2. Redistributions in binary form must reproduce the above copyright
11236099Sdes *    notice, this list of conditions and the following disclaimer in the
12236099Sdes *    documentation and/or other materials provided with the distribution.
13236099Sdes * 3. The name of the author may not be used to endorse or promote
14236099Sdes *    products derived from this software without specific prior written
15236099Sdes *    permission.
16236099Sdes *
17236099Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18236099Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19236099Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20236099Sdes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21236099Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22236099Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23236099Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24236099Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25236099Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26236099Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27236099Sdes * SUCH DAMAGE.
28236099Sdes *
29271624Sdes * $Id: openpam_ctype.h 763 2014-02-26 16:29:16Z des $
30236099Sdes */
31236099Sdes
32236099Sdes#ifndef OPENPAM_CTYPE_H_INCLUDED
33236099Sdes#define OPENPAM_CTYPE_H_INCLUDED
34236099Sdes
35236099Sdes/*
36255376Sdes * Evaluates to non-zero if the argument is a digit.
37255376Sdes */
38255376Sdes#define is_digit(ch)				\
39255376Sdes	(ch >= '0' && ch <= '9')
40255376Sdes
41255376Sdes/*
42262530Sdes * Evaluates to non-zero if the argument is a hex digit.
43262530Sdes */
44262530Sdes#define is_xdigit(ch)				\
45262530Sdes	((ch >= '0' && ch <= '9') ||		\
46262530Sdes	 (ch >= 'a' && ch <= 'f') ||		\
47262530Sdes	 (ch >= 'A' && ch <= 'F'))
48262530Sdes
49262530Sdes/*
50255376Sdes * Evaluates to non-zero if the argument is an uppercase letter.
51255376Sdes */
52255376Sdes#define is_upper(ch)				\
53262530Sdes	(ch >= 'A' && ch <= 'Z')
54255376Sdes
55255376Sdes/*
56255376Sdes * Evaluates to non-zero if the argument is a lowercase letter.
57255376Sdes */
58255376Sdes#define is_lower(ch)				\
59255376Sdes	(ch >= 'a' && ch <= 'z')
60255376Sdes
61255376Sdes/*
62255376Sdes * Evaluates to non-zero if the argument is a letter.
63255376Sdes */
64255376Sdes#define is_letter(ch)				\
65255376Sdes	(is_upper(ch) || is_lower(ch))
66255376Sdes
67255376Sdes/*
68236099Sdes * Evaluates to non-zero if the argument is a linear whitespace character.
69236099Sdes * For the purposes of this macro, the definition of linear whitespace is
70236099Sdes * extended to include the form feed and carraige return characters.
71236099Sdes */
72236099Sdes#define is_lws(ch)				\
73236099Sdes	(ch == ' ' || ch == '\t' || ch == '\f' || ch == '\r')
74236099Sdes
75236099Sdes/*
76236099Sdes * Evaluates to non-zero if the argument is a whitespace character.
77236099Sdes */
78236099Sdes#define is_ws(ch)				\
79236099Sdes	(is_lws(ch) || ch == '\n')
80236099Sdes
81236099Sdes/*
82236099Sdes * Evaluates to non-zero if the argument is a printable ASCII character.
83236099Sdes * Assumes that the execution character set is a superset of ASCII.
84236099Sdes */
85236099Sdes#define is_p(ch) \
86236099Sdes	(ch >= '!' && ch <= '~')
87236099Sdes
88236099Sdes/*
89236099Sdes * Returns non-zero if the argument belongs to the POSIX Portable Filename
90236099Sdes * Character Set.  Assumes that the execution character set is a superset
91236099Sdes * of ASCII.
92236099Sdes */
93236099Sdes#define is_pfcs(ch)				\
94255376Sdes	(is_digit(ch) || is_letter(ch)  ||	\
95236099Sdes	 ch == '.' || ch == '_' || ch == '-')
96236099Sdes
97236099Sdes#endif
98