NAME section for manpage
[dss.git] / snap.c
diff --git a/snap.c b/snap.c
index 1bc97b595a7bb99ecb1bfdf2a050168814c5ef3c..a5749a93293782cd1411c92d60829cb51c926688 100644 (file)
--- a/snap.c
+++ b/snap.c
@@ -1,3 +1,8 @@
+/*
+ * Copyright (C) 2008 Andre Noll <maan@systemlinux.org>
+ *
+ * Licensed under the GPL v2. For licencing details see COPYING.
+ */
 #include <stdlib.h>
 #include <assert.h>
 #include <inttypes.h>
 #include <stdlib.h>
 #include <assert.h>
 #include <inttypes.h>
@@ -6,6 +11,7 @@
 #include <stdio.h>
 #include <errno.h>
 #include <time.h>
 #include <stdio.h>
 #include <errno.h>
 #include <time.h>
+#include <sys/time.h>
 
 #include "gcc-compat.h"
 #include "error.h"
 
 #include "gcc-compat.h"
 #include "error.h"
 #include "time.h"
 #include "fd.h"
 
 #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.
  */
 /**
  * Return the desired number of snapshots of an interval.
  */
@@ -42,7 +63,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 (!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';
                        return 0;
        tmp = dss_strdup(dirname);
        tmp[i] = '\0';
@@ -72,7 +93,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 (!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';
                        return 0;
        tmp = dss_strdup(dash + 1);
        tmp[i] = '\0';