X-Git-Url: http://git.tuebingen.mpg.de/?p=dss.git;a=blobdiff_plain;f=snap.c;h=1fab237a58462d47aaaebddb27b297526ff9fb4b;hp=1bc97b595a7bb99ecb1bfdf2a050168814c5ef3c;hb=d184cc0fa0368ca089b1ae6f2162ccfc224bf28c;hpb=222b3355ee441ab4a310ef2830181ffd4300223b diff --git a/snap.c b/snap.c index 1bc97b5..1fab237 100644 --- a/snap.c +++ b/snap.c @@ -1,3 +1,8 @@ +/* + * Copyright (C) 2008 Andre Noll + * + * Licensed under the GPL v2. For licencing details see COPYING. + */ #include #include #include @@ -6,6 +11,7 @@ #include #include #include +#include #include "gcc-compat.h" #include "error.h" @@ -14,6 +20,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. */ @@ -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 (!isdigit(dirname[i])) + if (!dss_isdigit(dirname[i])) 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 (!isdigit(tmp[i])) + if (!dss_isdigit(tmp[i])) return 0; tmp = dss_strdup(dash + 1); tmp[i] = '\0'; @@ -80,7 +101,7 @@ static int is_snapshot(const char *dirname, int64_t now, int unit_interval, free(tmp); if (ret < 0) return 0; - if (num > now) + if (num > now || num < s->creation_time) return 0; s->completion_time = num; s->flags = SS_COMPLETE; @@ -167,17 +188,15 @@ void free_snapshot_list(struct snapshot_list *sl) __malloc char *incomplete_name(int64_t start) { - return make_message("%lli-incomplete", (long long)start); + return make_message("%" PRId64 "-incomplete", start); } __malloc char *being_deleted_name(struct snapshot *s) { if (s->flags & SS_COMPLETE) - return make_message("%lli-%lli.being_deleted", - (long long)s->creation_time, - (long long)s->completion_time); - return make_message("%lli-incomplete.being_deleted", - (long long)s->creation_time); + return make_message("%" PRId64 "-%" PRId64 ".being_deleted", + s->creation_time, s->completion_time); + return make_message("%" PRId64 "-incomplete.being_deleted", s->creation_time); } int complete_name(int64_t start, int64_t end, char **result) @@ -195,7 +214,7 @@ int complete_name(int64_t start, int64_t end, char **result) return -E_STRFTIME; if (!strftime(end_str, sizeof(end_str), "%a_%b_%d_%Y_%H_%M_%S", &end_tm)) return -E_STRFTIME; - *result = make_message("%lli-%lli.%s-%s", (long long) start, (long long) end, + *result = make_message("%" PRId64 "-%" PRId64 ".%s-%s", start, end, start_str, end_str); return 1; }