From cca956b199841d754e8a78391d2e2c7efce4a3ee Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Mon, 2 Jun 2008 16:12:46 +0100 Subject: [PATCH] Work around buggy FreeBSD strptime() Organization: Straylight/Edgeware From: Richard Kettlewell --- lib/dateparse.c | 6 +++--- libtests/t-dateparse.c | 5 +++++ libtests/test.c | 1 + libtests/test.h | 7 ++++++- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/dateparse.c b/lib/dateparse.c index 2a25292..f390d0c 100644 --- a/lib/dateparse.c +++ b/lib/dateparse.c @@ -38,6 +38,9 @@ static const char *const datemsk[] = { /* ISO format */ "%Y-%m-%d %H:%M:%S", + /* Generic time, same day */ + "%H:%M:%S", + "%H:%M", /* "%Y-%m-%d %H:%M:%S %Z" - no, not sensibly supported anywhere */ /* Locale-specific date + time */ "%c", @@ -45,9 +48,6 @@ static const char *const datemsk[] = { /* Locale-specific time, same day */ "%X", "%EX", - /* Generic time, same day */ - "%H:%M", - "%H:%M:%S", NULL, }; diff --git a/libtests/t-dateparse.c b/libtests/t-dateparse.c index a0d8e31..3b1e819 100644 --- a/libtests/t-dateparse.c +++ b/libtests/t-dateparse.c @@ -48,6 +48,10 @@ static void test_dateparse(void) { check_date(now, "%H:%M:%S", localtime); /* This one needs a bodge: */ check_date(now - now % 60, "%H:%M", localtime); +#if __FreeBSD__ + fprintf(stderr, "strptime() is broken on FreeBSD - skipping further tests\n"); + ++skipped; +#else /* Reject invalid formats */ check_fatal(dateparse("12")); check_fatal(dateparse("12:34:56:23")); @@ -55,6 +59,7 @@ static void test_dateparse(void) { check_fatal(dateparse("25:34")); check_fatal(dateparse("23:61")); check_fatal(dateparse("23:23:62")); +#endif } TEST(dateparse); diff --git a/libtests/test.c b/libtests/test.c index d37d70f..4fcb008 100644 --- a/libtests/test.c +++ b/libtests/test.c @@ -26,6 +26,7 @@ long long tests, errors; int fail_first; int verbose; +int skipped; void count_error(void) { ++errors; diff --git a/libtests/test.h b/libtests/test.h index a4f478e..48c8956 100644 --- a/libtests/test.h +++ b/libtests/test.h @@ -68,6 +68,7 @@ extern long long tests, errors; extern int fail_first; extern int verbose; +extern int skipped; /** @brief Checks that @p expr is nonzero */ #define insist(expr) do { \ @@ -153,7 +154,11 @@ void test_exitfn(int) attribute((noreturn)); if(errors || verbose) \ fprintf(stderr, "test_"#name": %lld errors out of %lld tests\n", \ errors, tests); \ - return !!errors; \ + if(errors) \ + return 1; \ + if(skipped) \ + return 77; \ + return 0; \ } \ \ struct swallow_semicolon -- [mdw]