xref: /illumos-gate/usr/src/common/util/strtolctype.h (revision bcf23f43)
12ef9abdcSjv /*
22ef9abdcSjv  * CDDL HEADER START
32ef9abdcSjv  *
42ef9abdcSjv  * The contents of this file are subject to the terms of the
52ef9abdcSjv  * Common Development and Distribution License (the "License").
62ef9abdcSjv  * You may not use this file except in compliance with the License.
72ef9abdcSjv  *
82ef9abdcSjv  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
92ef9abdcSjv  * or http://www.opensolaris.org/os/licensing.
102ef9abdcSjv  * See the License for the specific language governing permissions
112ef9abdcSjv  * and limitations under the License.
122ef9abdcSjv  *
132ef9abdcSjv  * When distributing Covered Code, include this CDDL HEADER in each
142ef9abdcSjv  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
152ef9abdcSjv  * If applicable, add the following below this CDDL HEADER, with the
162ef9abdcSjv  * fields enclosed by brackets "[]" replaced with your own identifying
172ef9abdcSjv  * information: Portions Copyright [yyyy] [name of copyright owner]
182ef9abdcSjv  *
192ef9abdcSjv  * CDDL HEADER END
202ef9abdcSjv  */
212ef9abdcSjv 
222ef9abdcSjv /*
23*bcf23f43SGary Mills  * Copyright 2016 Gary Mills
242ef9abdcSjv  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
252ef9abdcSjv  * Use is subject to license terms.
262ef9abdcSjv  */
272ef9abdcSjv 
282ef9abdcSjv /*	Copyright (c) 1988 AT&T	*/
292ef9abdcSjv /*	  All Rights Reserved  	*/
302ef9abdcSjv 
31*bcf23f43SGary Mills #ifndef	_COMMON_UTIL_STRTOLCTYPE_H
32*bcf23f43SGary Mills #define	_COMMON_UTIL_STRTOLCTYPE_H
332ef9abdcSjv 
342ef9abdcSjv #ifdef	__cplusplus
352ef9abdcSjv extern "C" {
362ef9abdcSjv #endif
372ef9abdcSjv 
382ef9abdcSjv /*
39*bcf23f43SGary Mills  * This is a private header file containing a collection of macros that
40*bcf23f43SGary Mills  * the strtou?ll? functions in common/util use to test characters.  Which
41*bcf23f43SGary Mills  * macros are defined depends on which of _KERNEL or _BOOT are defined.
42*bcf23f43SGary Mills  * New code should use the kernel version of ctype.h: <sys/ctype.h>.
43f497f9feSJoshua M. Clulow  *
44f497f9feSJoshua M. Clulow  * NOTE: These macros are used within several DTrace probe context functions.
45f497f9feSJoshua M. Clulow  * They must not be altered to make function calls or perform actions not
46f497f9feSJoshua M. Clulow  * safe in probe context.
472ef9abdcSjv  */
482ef9abdcSjv 
49*bcf23f43SGary Mills /*
50*bcf23f43SGary Mills  * Cases that define these macros:
51*bcf23f43SGary Mills  *   _KERNEL && !_BOOT: Used by kernel functions
52*bcf23f43SGary Mills  *   !_KERNEL && _BOOT: Used by dboot_startkern.c for x86 boot
53*bcf23f43SGary Mills  * Cases that omit these macros:
54*bcf23f43SGary Mills  *   _KERNEL && _BOOT: Used by common/util/strtol.c for SPARC boot library
55*bcf23f43SGary Mills  *   !_KERNEL && !_BOOT: Used by strtou?ll? functions in libc
56*bcf23f43SGary Mills  */
57*bcf23f43SGary Mills #if	defined(_KERNEL) ^ defined(_BOOT)
582ef9abdcSjv 
592ef9abdcSjv #define	isalnum(ch)	(isalpha(ch) || isdigit(ch))
602ef9abdcSjv #define	isalpha(ch)	(isupper(ch) || islower(ch))
612ef9abdcSjv #define	isdigit(ch)	((ch) >= '0' && (ch) <= '9')
622ef9abdcSjv #define	islower(ch)	((ch) >= 'a' && (ch) <= 'z')
632ef9abdcSjv #define	isspace(ch)	(((ch) == ' ') || ((ch) == '\r') || ((ch) == '\n') || \
642ef9abdcSjv 			((ch) == '\t') || ((ch) == '\f'))
652ef9abdcSjv #define	isupper(ch)	((ch) >= 'A' && (ch) <= 'Z')
662ef9abdcSjv #define	isxdigit(ch)	(isdigit(ch) || ((ch) >= 'a' && (ch) <= 'f') || \
672ef9abdcSjv 			((ch) >= 'A' && (ch) <= 'F'))
682ef9abdcSjv 
69*bcf23f43SGary Mills #endif	/* _KERNEL ^ _BOOT */
70*bcf23f43SGary Mills 
71*bcf23f43SGary Mills /*
72*bcf23f43SGary Mills  * The following macros are defined unconditionally.
73*bcf23f43SGary Mills  */
742ef9abdcSjv 
752ef9abdcSjv #define	DIGIT(x)	\
762ef9abdcSjv 	(isdigit(x) ? (x) - '0' : islower(x) ? (x) + 10 - 'a' : (x) + 10 - 'A')
772ef9abdcSjv 
782ef9abdcSjv #define	MBASE	('z' - 'a' + 1 + 10)
792ef9abdcSjv 
802ef9abdcSjv /*
812ef9abdcSjv  * The following macro is a version of isalnum() that limits alphabetic
822ef9abdcSjv  * characters to the ranges a-z and A-Z; locale dependent characters will not
832ef9abdcSjv  * return 1.  The members of a-z and A-Z are assumed to be in ascending order
842ef9abdcSjv  * and contiguous.
852ef9abdcSjv  */
862ef9abdcSjv #define	lisalnum(x)	\
872ef9abdcSjv 	(isdigit(x) || ((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z'))
882ef9abdcSjv 
892ef9abdcSjv #ifdef	__cplusplus
902ef9abdcSjv }
912ef9abdcSjv #endif
922ef9abdcSjv 
93*bcf23f43SGary Mills #endif	/* _COMMON_UTIL_STRTOLCTYPE_H */
94