]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Initialize locale on bsdcpio, and change test_option_t accordingly
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Fri, 15 Apr 2011 14:37:42 +0000 (10:37 -0400)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Fri, 15 Apr 2011 14:37:42 +0000 (10:37 -0400)
because it compared date format in "C" locale to the output of bsdcpio -t option.

SVN-Revision: 3237

cpio/cpio.c
cpio/test/test_option_t.c

index 46d6927741ddea4951dffb9b8e982b09e3a911d9..6a09412c4705e593d759feee70b6f841688e9241 100644 (file)
@@ -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 <grp.h>
 #endif
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
 #ifdef HAVE_PWD_H
 #include <pwd.h>
 #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;
index 4427bb3a6cd76f3cf0e494cf195ea5e62863a626..2d6636bec19f2175c52a49d4b2b66147324fdf84 100644 (file)
 #include "test.h"
 __FBSDID("$FreeBSD$");
 
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#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. */