From e76878bf849caa0916ab39bddb033f9f08dc4242 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Mon, 24 Aug 2009 17:52:31 +0200 Subject: [PATCH 1/1] Add wrapper for isspace() which is needed for NetBSD. --- adu.h | 15 +++++++++++++++ interactive.c | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/adu.h b/adu.h index 42b9471..83c3c66 100644 --- a/adu.h +++ b/adu.h @@ -85,6 +85,21 @@ #endif /** \endcond */ +/** + * Wrapper for isspace. + * NetBSD needs this. + */ +/* + * The values should be cast to an unsigned char first, then to int. + * Why? Because the isdigit (as do all other is/to functions/macros) + * expect a number from 0 upto and including 255 as their (int) argument. + * Because char is signed on most systems, casting it to int immediately + * gives the functions an argument between -128 and 127 (inclusive), + * which they will use as an array index, and which will thus fail + * horribly for characters which have their most significant bit set. + */ +#define adu_isspace(c) isspace((int)(unsigned char)(c)) + /** * Write a log message to a dynamically allocated string. * diff --git a/interactive.c b/interactive.c index 1c75622..88a1bd5 100644 --- a/interactive.c +++ b/interactive.c @@ -145,7 +145,7 @@ static int exec_interactive_command(char *line) return 1; len = strlen(line); - while (len && isspace(line[len - 1])) { + while (len && adu_isspace(line[len - 1])) { line[len - 1] = '\0'; len--; } -- 2.39.2