]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Properly quote output of locale
authorAndreas Schwab <schwab@redhat.com>
Thu, 12 Aug 2010 16:05:50 +0000 (09:05 -0700)
committerUlrich Drepper <drepper@redhat.com>
Thu, 12 Aug 2010 16:05:50 +0000 (09:05 -0700)
ChangeLog
NEWS
locale/programs/locale.c

index 250eaf92b4c3daf4e536bc022ed8a71a68fe2ec1..85bda58b6d6d48e5bdbf1ed0fdf8bb502e479d45 100644 (file)
--- 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-08-11  Ulrich Drepper  <drepper@redhat.com>
 
        * sysdeps/unix/sysv/linux/bits/statfs.h (struct statfs): Add f_flags
diff --git a/NEWS b/NEWS
index d9cc5e41140d1d7829f5767f67f28de7ffcf416c..eba00f4e52d0367baf06f9bf8d4d553189380856 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
-GNU C Library NEWS -- history of user-visible changes.  2010-8-11
+GNU C Library NEWS -- history of user-visible changes.  2010-8-12
 Copyright (C) 1992-2009, 2010 Free Software Foundation, Inc.
 See the end for copying conditions.
 
@@ -9,7 +9,7 @@ Version 2.13
 
 * The following bugs are resolved with this release:
 
-  11640, 11701, 11840, 11856, 11883, 11903
+  11640, 11701, 11840, 11856, 11883, 11903, 11904
 
 * New Linux interfaces: prlimit, prlimit64, fanotify_init, fanotify_mark
 
index a3602cf11834a6cf3f6d3a6afb9caa149c193dd2..2005dec00b26dd81c0dd618ea66117afe8473d74 100644 (file)
@@ -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);
 }