[tyndur-devel] [PATCH] libc: ctype.h-Funktionen sollten keine Makros sein
Kevin Wolf ·
! libc: Parameter mehrfach auswerten in isspace() usw. ist doof Signed-off-by: Kevin Wolf <kevin at tyndur.org> --- src/include/ctype.h | 153 ++++++++++++++++++++++++++++++++------------------- 1 files changed, 96 insertions(+), 57 deletions(-) diff --git a/src/include/ctype.h b/src/include/ctype.h index d43dcab..51cb2f4 100644 --- a/src/include/ctype.h +++ b/src/include/ctype.h @@ -1,57 +1,96 @@ -/* - * Copyright (c) 2006-2007 The tyndur Project. All rights reserved. - * - * This code is derived from software contributed to the tyndur Project - * by Burkhard Weseloh. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _CTYPE_H_ -#define _CTYPE_H_ - -#define isprint(c) ((c) >= (char) 0x20) -#define iscntrl(c) ((c) < (char) 0x20) - -#define isspace(c) ((c) == ' ' || (c) == '\n' || (c) == '\t' || (c) == '\r') -#define isblank(c) ((c) == ' ' || (c) == '\t') -#define isdigit(c) ((c) >= '0' && (c) <= '9') -#define isalpha(c) (((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z')) -#define isalnum(c) (isdigit(c) || isalpha(c)) -#define isxdigit(c) (isdigit(c) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F')) -#define isupper(c) ((c) >= 'A' && (c) <= 'Z') -#define islower(c) ((c) >= 'a' && (c) <= 'z') -#define ispunct(c) (isprint(c) && (!isspace(c)) && (!isalpha(c))) -#define isgraph(c) (isprint(c) && !isspace(c)) - - -static inline int tolower(int c) -{ - return isupper(c) ? c + ('a' - 'A') : c; -} - -static inline int toupper(int c) -{ - return islower(c) ? c - ('a' - 'A') : c; -} - -#endif /* ndef CTYPE_H */ +/* + * Copyright (c) 2006-2007 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Burkhard Weseloh. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _CTYPE_H_ +#define _CTYPE_H_ + +#define isprint(c) ((c) >= (char) 0x20) +#define iscntrl(c) ((c) < (char) 0x20) + +static inline int isspace(int c) +{ + return (c == ' ' || c== '\n' || c == '\t' || c == '\r'); +} + +static inline int isblank(int c) +{ + return (c == ' ' ||c == '\t'); +} + +static inline int isdigit(int c) +{ + return (c >= '0' && c <= '9'); +} + +static inline int isalpha(int c) +{ + return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); +} + +static inline int isalnum(int c) +{ + return (isdigit(c) || isalpha(c)); +} + +static inline int isxdigit(int c) +{ + return (isdigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')); +} + +static inline int isupper(int c) +{ + return (c >= 'A' && c <= 'Z'); +} + +static inline int islower(int c) +{ + return (c >= 'a' && c <= 'z'); +} + +static inline int ispunct(int c) +{ + return (isprint(c) && !isspace(c) && !isalpha(c)); +} + +static inline int isgraph(int c) +{ + return (isprint(c) && !isspace(c)); +} + + +static inline int tolower(int c) +{ + return isupper(c) ? c + ('a' - 'A') : c; +} + +static inline int toupper(int c) +{ + return islower(c) ? c - ('a' - 'A') : c; +} + +#endif /* ndef CTYPE_H */ -- 1.6.0.2
Antworten
- [tyndur-devel] [PATCH] libc: ctype.h-Funktionen sollten keine Makros sein · Antoine Kaufmann