[Bug time/19890] New: strptime() and strftime() symmetry and support of %x and %X
carlos at redhat dot com
sourceware-bugzilla@sourceware.org
Wed Mar 30 19:44:00 GMT 2016
https://sourceware.org/bugzilla/show_bug.cgi?id=19890
Bug ID: 19890
Summary: strptime() and strftime() symmetry and support of %x
and %X
Product: glibc
Version: 2.24
Status: NEW
Severity: normal
Priority: P2
Component: time
Assignee: unassigned at sourceware dot org
Reporter: carlos at redhat dot com
Target Milestone: ---
This bug is in many ways related bug 4772 which was fixed by Ondrej.
Here we have "%x %X" format being used, and it fails to be re-read by strptime
for three locales.
Test program is this:
cat >> tst-uselocale2.c <<EOF
#define _XOPEN_SOURCE 700
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <langinfo.h>
#include <time.h>
#include <string.h>
#define BUF_SIZE 256
#define TEST_LOCALE argv[1]
int main(int argc, char **argv)
{
int ret;
struct tm *loctm, nt;
time_t now;
char str[BUF_SIZE];
const char *format = "%x %X", *retval;
locale_t myloc;
memset (str, '0', BUF_SIZE);
printf ("TEST: %s\n", TEST_LOCALE);
if (setlocale(LC_TIME, TEST_LOCALE) == NULL)
{
printf("FAIL: Error setting locale %s\n", TEST_LOCALE);
return EXIT_FAILURE;
}
now = time(NULL);
loctm = localtime(&now);
myloc = newlocale (LC_TIME_MASK, TEST_LOCALE, (locale_t) 0);
ret = strftime_l(str, BUF_SIZE, format, loctm, myloc);
if (ret == 0)
{
printf("FAIL: Error creating time string for %s locale\n", TEST_LOCALE);
return EXIT_FAILURE;
}
retval = strptime(str, format, &nt);
if (retval == NULL)
{
printf("FAIL: Error converting time string to struct in %s locale\n",
TEST_LOCALE);
return EXIT_FAILURE;
}
printf ("PASS: Converted strftime_l output back via strptime\n");
return 0;
}
EOF
cat >> build-chroot.sh <<EOF
#!/bin/bash
BUILD=/home/carlos/build/glibc
rm -rf chroot
mkdir chroot
pushd chroot
mkdir lib64
cp $BUILD/libc.so lib64/libc.so.6
cp $BUILD/elf/ld.so lib64/ld-linux-x86-64.so.2
mkdir -p usr/lib64/locale
ln -s lib64 usr/lib
cp /home/carlos/install-glibc-locales/usr/lib64/locale/locale-archive
usr/lib64/locale/
popd
EOF
cat >> build.sh <<EOF
#!/bin/bash
gcc -Wall -pedantic -g3 -O0 -o tst-uselocale2 tst-uselocale2.c
cp tst-uselocale2 ./chroot
EOF
cat >> run.sh <<EOF
#!/bin/bash
for i in `localedef --prefix ./chroot/ --list-archive`
do
sudo chroot ./chroot ./tst-uselocale2 "$i"
done
EOF
./build-chroot.sh
./build.sh
./run.sh | grep FAIL
With upstream master we get:
FAIL: Error converting time string to struct in gd_GB locale
FAIL: Error converting time string to struct in gd_GB.iso885915 locale
FAIL: Error converting time string to struct in gd_GB.utf8 locale
FAIL: Error converting time string to struct in lzh_TW locale
FAIL: Error converting time string to struct in lzh_TW.utf8 locale
FAIL: Error converting time string to struct in my_MM locale
FAIL: Error converting time string to struct in my_MM.utf8 locale
FAIL: Error setting locale no_NO.ISO-8859-1
Which means we have 3 broken locales that can't use strptime to process the
output of strftime in a symmetric fashion.
It should be possible to use the same format specifier for strftime and
strptime for symmetry and easy-of-use of the API.
--
You are receiving this mail because:
You are on the CC list for the bug.
More information about the Glibc-bugs
mailing list