From: Andre Noll Date: Wed, 14 May 2008 12:09:41 +0000 (+0200) Subject: NetBSD Compile fixes. X-Git-Tag: v0.1.0~2 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=952745a3f7cc03b9581454d1c32f735b8ad16f93;p=dss.git NetBSD Compile fixes. Add a missing include and the dss_isdigit macro. --- diff --git a/signal.c b/signal.c index 7594953..2685d0b 100644 --- a/signal.c +++ b/signal.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "gcc-compat.h" diff --git a/snap.c b/snap.c index 268e99b..c47e688 100644 --- a/snap.c +++ b/snap.c @@ -19,6 +19,21 @@ #include "time.h" #include "fd.h" +/** + * Wrapper for isdigit. + * 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 dss_isdigit(c) isdigit((int)(unsigned char)(c)) + + /** * Return the desired number of snapshots of an interval. */ @@ -47,7 +62,7 @@ static int is_snapshot(const char *dirname, int64_t now, int unit_interval, if (!dash || !dash[1] || dash == dirname) return 0; for (i = 0; dirname[i] != '-'; i++) - if (!isdigit(dirname[i])) + if (!dss_isdigit(dirname[i])) return 0; tmp = dss_strdup(dirname); tmp[i] = '\0'; @@ -77,7 +92,7 @@ static int is_snapshot(const char *dirname, int64_t now, int unit_interval, if (!dot || !dot[1] || dot == tmp) return 0; for (i = 0; tmp[i] != '.'; i++) - if (!isdigit(tmp[i])) + if (!dss_isdigit(tmp[i])) return 0; tmp = dss_strdup(dash + 1); tmp[i] = '\0';