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