2ef9abdc6ea9bad985430325b12b90938a8cd18fjv/*
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv * CDDL HEADER START
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv *
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv * The contents of this file are subject to the terms of the
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv * Common Development and Distribution License (the "License").
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv * You may not use this file except in compliance with the License.
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv *
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv * or http://www.opensolaris.org/os/licensing.
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv * See the License for the specific language governing permissions
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv * and limitations under the License.
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv *
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv * When distributing Covered Code, include this CDDL HEADER in each
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv * If applicable, add the following below this CDDL HEADER, with the
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv * fields enclosed by brackets "[]" replaced with your own identifying
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv * information: Portions Copyright [yyyy] [name of copyright owner]
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv *
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv * CDDL HEADER END
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv */
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv/*
bcf23f43dc1b73080eeded927585ee86feab40a7Gary Mills * Copyright 2016 Gary Mills
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv * Use is subject to license terms.
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv */
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv/* Copyright (c) 1988 AT&T */
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv/* All Rights Reserved */
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv
bcf23f43dc1b73080eeded927585ee86feab40a7Gary Mills#ifndef _COMMON_UTIL_STRTOLCTYPE_H
bcf23f43dc1b73080eeded927585ee86feab40a7Gary Mills#define _COMMON_UTIL_STRTOLCTYPE_H
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv#ifdef __cplusplus
2ef9abdc6ea9bad985430325b12b90938a8cd18fjvextern "C" {
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv#endif
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv/*
bcf23f43dc1b73080eeded927585ee86feab40a7Gary Mills * This is a private header file containing a collection of macros that
bcf23f43dc1b73080eeded927585ee86feab40a7Gary Mills * the strtou?ll? functions in common/util use to test characters. Which
bcf23f43dc1b73080eeded927585ee86feab40a7Gary Mills * macros are defined depends on which of _KERNEL or _BOOT are defined.
bcf23f43dc1b73080eeded927585ee86feab40a7Gary Mills * New code should use the kernel version of ctype.h: <sys/ctype.h>.
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow *
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow * NOTE: These macros are used within several DTrace probe context functions.
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow * They must not be altered to make function calls or perform actions not
f497f9fe231e0e400f339c84a7d80c4aae2ac4d5Joshua M. Clulow * safe in probe context.
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv */
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv
bcf23f43dc1b73080eeded927585ee86feab40a7Gary Mills/*
bcf23f43dc1b73080eeded927585ee86feab40a7Gary Mills * Cases that define these macros:
bcf23f43dc1b73080eeded927585ee86feab40a7Gary Mills * _KERNEL && !_BOOT: Used by kernel functions
bcf23f43dc1b73080eeded927585ee86feab40a7Gary Mills * !_KERNEL && _BOOT: Used by dboot_startkern.c for x86 boot
bcf23f43dc1b73080eeded927585ee86feab40a7Gary Mills * Cases that omit these macros:
bcf23f43dc1b73080eeded927585ee86feab40a7Gary Mills * _KERNEL && _BOOT: Used by common/util/strtol.c for SPARC boot library
bcf23f43dc1b73080eeded927585ee86feab40a7Gary Mills * !_KERNEL && !_BOOT: Used by strtou?ll? functions in libc
bcf23f43dc1b73080eeded927585ee86feab40a7Gary Mills */
bcf23f43dc1b73080eeded927585ee86feab40a7Gary Mills#if defined(_KERNEL) ^ defined(_BOOT)
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv#define isalnum(ch) (isalpha(ch) || isdigit(ch))
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv#define isalpha(ch) (isupper(ch) || islower(ch))
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv#define isdigit(ch) ((ch) >= '0' && (ch) <= '9')
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv#define islower(ch) ((ch) >= 'a' && (ch) <= 'z')
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv#define isspace(ch) (((ch) == ' ') || ((ch) == '\r') || ((ch) == '\n') || \
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv ((ch) == '\t') || ((ch) == '\f'))
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv#define isupper(ch) ((ch) >= 'A' && (ch) <= 'Z')
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv#define isxdigit(ch) (isdigit(ch) || ((ch) >= 'a' && (ch) <= 'f') || \
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv ((ch) >= 'A' && (ch) <= 'F'))
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv
bcf23f43dc1b73080eeded927585ee86feab40a7Gary Mills#endif /* _KERNEL ^ _BOOT */
bcf23f43dc1b73080eeded927585ee86feab40a7Gary Mills
bcf23f43dc1b73080eeded927585ee86feab40a7Gary Mills/*
bcf23f43dc1b73080eeded927585ee86feab40a7Gary Mills * The following macros are defined unconditionally.
bcf23f43dc1b73080eeded927585ee86feab40a7Gary Mills */
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv#define DIGIT(x) \
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv (isdigit(x) ? (x) - '0' : islower(x) ? (x) + 10 - 'a' : (x) + 10 - 'A')
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv#define MBASE ('z' - 'a' + 1 + 10)
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv/*
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv * The following macro is a version of isalnum() that limits alphabetic
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv * characters to the ranges a-z and A-Z; locale dependent characters will not
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv * return 1. The members of a-z and A-Z are assumed to be in ascending order
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv * and contiguous.
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv */
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv#define lisalnum(x) \
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv (isdigit(x) || ((x) >= 'a' && (x) <= 'z') || ((x) >= 'A' && (x) <= 'Z'))
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv#ifdef __cplusplus
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv}
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv#endif
2ef9abdc6ea9bad985430325b12b90938a8cd18fjv
bcf23f43dc1b73080eeded927585ee86feab40a7Gary Mills#endif /* _COMMON_UTIL_STRTOLCTYPE_H */