diff options
author | Andreas Schwab <schwab@redhat.com> | 2010-08-12 09:05:50 -0700 |
---|---|---|
committer | Andreas Schwab <schwab@redhat.com> | 2010-12-01 15:35:16 +0100 |
commit | 00b4cc7aefcebb3d36532c5f3ea245737b67c561 (patch) | |
tree | 77d4d97413937515365511fb257c2a4e8559babe | |
parent | 63ed86a37f94af5599d93813cc22be7be23f016a (diff) | |
download | glibc-00b4cc7aefcebb3d36532c5f3ea245737b67c561.tar.gz glibc-00b4cc7aefcebb3d36532c5f3ea245737b67c561.tar.xz glibc-00b4cc7aefcebb3d36532c5f3ea245737b67c561.zip |
Properly quote output of locale
(cherry picked from commit 026373745eab50a683536d950cb7e17dc98c4259)
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | locale/programs/locale.c | 37 |
2 files changed, 36 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog index 2d07ad1b4f..82116e2fff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2010-08-12 Andreas Schwab <schwab@redhat.com> + + [BZ #11904] + * locale/programs/locale.c (print_assignment): New function. + (show_locale_vars): Use it. + 2010-10-26 Ulrich Drepper <drepper@gmail.com> * elf/rtld.c (dl_main): Move assertion after the point where rtld map diff --git a/locale/programs/locale.c b/locale/programs/locale.c index a3602cf118..2005dec00b 100644 --- a/locale/programs/locale.c +++ b/locale/programs/locale.c @@ -762,6 +762,29 @@ write_charmaps (void) twalk (all_data, print_names); } +/* Print a properly quoted assignment of NAME with VAL, using double + quotes iff DQUOTE is true. */ +static void +print_assignment (const char *name, const char *val, bool dquote) +{ + printf ("%s=", name); + if (dquote) + putchar ('"'); + while (*val != '\0') + { + size_t segment + = strcspn (val, dquote ? "$`\"\\" : "~|&;<>()$`\\\"' \t\n"); + printf ("%.*s", (int) segment, val); + val += segment; + if (*val == '\0') + break; + putchar ('\\'); + putchar (*val++); + } + if (dquote) + putchar ('"'); + putchar ('\n'); +} /* We have to show the contents of the environments determining the locale. */ @@ -769,7 +792,7 @@ static void show_locale_vars (void) { size_t cat_no; - const char *lcall = getenv ("LC_ALL"); + const char *lcall = getenv ("LC_ALL") ? : ""; const char *lang = getenv ("LANG") ? : ""; auto void get_source (const char *name); @@ -778,15 +801,15 @@ show_locale_vars (void) { char *val = getenv (name); - if ((lcall ?: "")[0] != '\0' || val == NULL) - printf ("%s=\"%s\"\n", name, - (lcall ?: "")[0] ? lcall : (lang ?: "")[0] ? lang : "POSIX"); + if (lcall[0] != '\0' || val == NULL) + print_assignment (name, lcall[0] ? lcall : lang[0] ? lang : "POSIX", + true); else - printf ("%s=%s\n", name, val); + print_assignment (name, val, false); } /* LANG has to be the first value. */ - printf ("LANG=%s\n", lang); + print_assignment ("LANG", lang, false); /* Now all categories in an unspecified order. */ for (cat_no = 0; cat_no < NCATEGORIES; ++cat_no) @@ -794,7 +817,7 @@ show_locale_vars (void) get_source (category[cat_no].name); /* The last is the LC_ALL value. */ - printf ("LC_ALL=%s\n", lcall ? : ""); + print_assignment ("LC_ALL", lcall, false); } |