From: Michihiro NAKAJIMA Date: Fri, 15 Apr 2011 14:37:42 +0000 (-0400) Subject: Initialize locale on bsdcpio, and change test_option_t accordingly X-Git-Tag: v3.0.0a~449 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=817c5c0d6ab0bb4c594daeb53c491d659ea03578;p=thirdparty%2Flibarchive.git Initialize locale on bsdcpio, and change test_option_t accordingly because it compared date format in "C" locale to the output of bsdcpio -t option. SVN-Revision: 3237 --- diff --git a/cpio/cpio.c b/cpio/cpio.c index 46d692774..6a09412c4 100644 --- a/cpio/cpio.c +++ b/cpio/cpio.c @@ -50,6 +50,9 @@ __FBSDID("$FreeBSD: src/usr.bin/cpio/cpio.c,v 1.15 2008/12/06 07:30:40 kientzle #ifdef HAVE_GRP_H #include #endif +#ifdef HAVE_LOCALE_H +#include +#endif #ifdef HAVE_PWD_H #include #endif @@ -147,6 +150,10 @@ main(int argc, char *argv[]) else lafe_progname = *argv; } +#if HAVE_SETLOCALE + if (setlocale(LC_ALL, "") == NULL) + lafe_warnc(0, "Failed to set default locale"); +#endif cpio->uid_override = -1; cpio->gid_override = -1; diff --git a/cpio/test/test_option_t.c b/cpio/test/test_option_t.c index 4427bb3a6..2d6636bec 100644 --- a/cpio/test/test_option_t.c +++ b/cpio/test/test_option_t.c @@ -25,11 +25,16 @@ #include "test.h" __FBSDID("$FreeBSD$"); +#ifdef HAVE_LOCALE_H +#include +#endif DEFINE_TEST(test_option_t) { char *p; int r; + time_t mtime; + char date[32]; /* List reference archive, make sure the TOC is correct. */ extract_reference_file("test_option_t.cpio"); @@ -75,17 +80,19 @@ DEFINE_TEST(test_option_t) /* Since -n uses numeric UID/GID, this part should be the * same on every system. */ assertEqualMem(p, "-rw-r--r-- 1 1000 1000 0 ",42); - /* Date varies depending on local timezone. */ - if (memcmp(p + 42, "Dec 31 1969", 12) == 0) { - /* East of Greenwich we get Dec 31, 1969. */ - } else { - /* West of Greenwich get Jan 1, 1970 */ - assertEqualMem(p + 42, "Jan ", 4); - /* Some systems format "Jan 01", some "Jan 1" */ - assert(p[46] == ' ' || p[46] == '0'); - assertEqualMem(p + 47, "1 1970 ", 8); - } - assertEqualMem(p + 54, " file", 5); + + /* Date varies depending on local timezone and locale. */ + mtime = 1; +#ifdef HAVE_LOCALE_H + setlocale(LC_ALL, ""); +#endif +#if defined(_WIN32) && !defined(__CYGWIN__) + strftime(date, sizeof(date), "%b %d %Y ", localtime(&mtime)); +#else + strftime(date, sizeof(date), "%b %e %Y ", localtime(&mtime)); +#endif + assertEqualMem(p + 42, date, strlen(date)); + assertEqualMem(p + 42 + strlen(date)-1, " file", 5); free(p); /* But "-n" without "-t" is an error. */