Add setlocale() call (fix #1740)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Nicolas Williams · committed by Nico Williams · parent ac3b70d · Browse files · 3 files·+31 added−5 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+31 added−5 removed
- tests:+23 added−5 removed
- other:+8 added−0 removed
Provenance
- Commit
11c528d- Tree
3eb4d21- Author
Nicolas Williams <nico@cryptonector.com>- Committer
Nico Williams <nico@cryptonector.com>- Parent
ac3b70d
3 files changed+31 added−5 removed
modified:src/main.c+7 added
1 #include <assert.h>2 #include <ctype.h>3 #include <errno.h>4 #include <libgen.h>5+#ifdef HAVE_SETLOCALE6+#include <locale.h>7+#endif8 #include <stdlib.h>9 #include <stdio.h>10 #include <string.h>11 #include <unistd.h>309 unmodified lines321 int options = 0;322 jv ARGS = jv_array(); /* positional arguments */323 jv program_arguments = jv_object(); /* named arguments */324 325+#ifdef HAVE_SETLOCALE326+ (void) setlocale(LC_ALL, "");327+#endif328+329 #ifdef WIN32330 jv_tsd_dtoa_ctx_init();331 fflush(stdout);332 fflush(stderr);465 unmodified linesmodified:tests/shtest+23 added-5 removed
1 #!/bin/sh -x2 3 . "${0%/*}/setup" "$@"4 5+msys=false6+mingw=false7+case "$(uname -s)" in8+MSYS*) msys=true;;9+MINGW*) mingw=true;;10+esac11+12 JQ_NO_B=$JQ13 JQ="$JQ -b"14 15 PATH=$JQBASEDIR:$PATH $JQBASEDIR/tests/jq-f-test.sh > /dev/null486 unmodified lines502 cmp $d/color $d/expect503 cmp $d/warning $d/expect_warning504 505 # Check $NO_COLOR499-case "$(uname -s)" in500-MSYS*) test_no_color=false;;501-MINGW*) test_no_color=false;;502-*) test_no_color=true;;503-esac506+test_no_color=true507+$msys && test_no_color=false508+$mingw && test_no_color=false509 if $test_no_color && command -v script >/dev/null 2>&1; then510 unset NO_COLOR511 if script -qc echo /dev/null >/dev/null 2>&1; then512 faketty() { script -qec "$*" /dev/null; }52 unmodified lines565 echo "jq -f $JQTESTDIR/yes-main-program.jq failed"566 exit 1567 fi568 569+if ( ! $msys && ! $mingw ) && locale -a > /dev/null; then570+ locale=$(locale -a | egrep -v '^(C|LANG|POSIX|en)' | egrep -i 'utf8|utf-8' | head -1)571+ if [ -z "$locale" ]; then572+ echo "WARNING: Not testing localization"573+ else574+ date=$(LC_ALL="$locale" date +"%a %d %b %Y at %H:%M:%S")575+ if ! LC_ALL="$locale" ./jq -nRe --arg date "$date" '$date|strptime("%a %d %b %Y at %H:%M:%S")? // false'; then576+ echo "jq does not honor LC_ALL environment variable"577+ exit 1;578+ fi579+ fi580+fi581+582 exit 0modified:configure.ac+1 added
147 unmodified lines148 AC_CHECK_MEMBER([struct tm.tm_gmtoff], [AC_DEFINE([HAVE_TM_TM_GMT_OFF],1,[Define to 1 if the system has the tm_gmt_off field in struct tm])],149 [], [[#include <time.h>]])150 AC_CHECK_MEMBER([struct tm.__tm_gmtoff], [AC_DEFINE([HAVE_TM___TM_GMT_OFF],1,[Define to 1 if the system has the __tm_gmt_off field in struct tm])],151 [], [[#include <time.h>]])152+AC_FIND_FUNC([setlocale], [c], [#include <locale.h>], [0,0])153 154 dnl Figure out if we have the pthread functions we actually need155 AC_FIND_FUNC_NO_LIBS([pthread_key_create], [], [#include <pthread.h>], [NULL, NULL])156 AC_FIND_FUNC_NO_LIBS([pthread_once], [], [#include <pthread.h>], [NULL, NULL])142 unmodified lines