Blame SOURCES/glibc-rh625893.patch

b9ba6d
2010-08-12  Andreas Schwab  <schwab@redhat.com>
b9ba6d
b9ba6d
	[BZ #11904]
b9ba6d
	* locale/programs/locale.c (print_assignment): New function.
b9ba6d
	(show_locale_vars): Use it.
b9ba6d
b9ba6d
Index: glibc-2.12-2-gc4ccff1/locale/programs/locale.c
b9ba6d
===================================================================
b9ba6d
--- glibc-2.12-2-gc4ccff1.orig/locale/programs/locale.c
b9ba6d
+++ glibc-2.12-2-gc4ccff1/locale/programs/locale.c
b9ba6d
@@ -762,6 +762,29 @@ write_charmaps (void)
b9ba6d
   twalk (all_data, print_names);
b9ba6d
 }
b9ba6d
 
b9ba6d
+/* Print a properly quoted assignment of NAME with VAL, using double
b9ba6d
+   quotes iff DQUOTE is true.  */
b9ba6d
+static void
b9ba6d
+print_assignment (const char *name, const char *val, bool dquote)
b9ba6d
+{
b9ba6d
+  printf ("%s=", name);
b9ba6d
+  if (dquote)
b9ba6d
+    putchar ('"');
b9ba6d
+  while (*val != '\0')
b9ba6d
+    {
b9ba6d
+      size_t segment
b9ba6d
+	= strcspn (val, dquote ? "$`\"\\" : "~|&;<>()$`\\\"' \t\n");
b9ba6d
+      printf ("%.*s", (int) segment, val);
b9ba6d
+      val += segment;
b9ba6d
+      if (*val == '\0')
b9ba6d
+	break;
b9ba6d
+      putchar ('\\');
b9ba6d
+      putchar (*val++);
b9ba6d
+    }
b9ba6d
+  if (dquote)
b9ba6d
+    putchar ('"');
b9ba6d
+  putchar ('\n');
b9ba6d
+}
b9ba6d
 
b9ba6d
 /* We have to show the contents of the environments determining the
b9ba6d
    locale.  */
b9ba6d
@@ -769,7 +792,7 @@ static void
b9ba6d
 show_locale_vars (void)
b9ba6d
 {
b9ba6d
   size_t cat_no;
b9ba6d
-  const char *lcall = getenv ("LC_ALL");
b9ba6d
+  const char *lcall = getenv ("LC_ALL") ? : "";
b9ba6d
   const char *lang = getenv ("LANG") ? : "";
b9ba6d
 
b9ba6d
   auto void get_source (const char *name);
b9ba6d
@@ -778,15 +801,15 @@ show_locale_vars (void)
b9ba6d
     {
b9ba6d
       char *val = getenv (name);
b9ba6d
 
b9ba6d
-      if ((lcall ?: "")[0] != '\0' || val == NULL)
b9ba6d
-	printf ("%s=\"%s\"\n", name,
b9ba6d
-		(lcall ?: "")[0] ? lcall : (lang ?: "")[0] ? lang : "POSIX");
b9ba6d
+      if (lcall[0] != '\0' || val == NULL)
b9ba6d
+	print_assignment (name, lcall[0] ? lcall : lang[0] ? lang : "POSIX",
b9ba6d
+			  true);
b9ba6d
       else
b9ba6d
-	printf ("%s=%s\n", name, val);
b9ba6d
+	print_assignment (name, val, false);
b9ba6d
     }
b9ba6d
 
b9ba6d
   /* LANG has to be the first value.  */
b9ba6d
-  printf ("LANG=%s\n", lang);
b9ba6d
+  print_assignment ("LANG", lang, false);
b9ba6d
 
b9ba6d
   /* Now all categories in an unspecified order.  */
b9ba6d
   for (cat_no = 0; cat_no < NCATEGORIES; ++cat_no)
b9ba6d
@@ -794,7 +817,7 @@ show_locale_vars (void)
b9ba6d
       get_source (category[cat_no].name);
b9ba6d
 
b9ba6d
   /* The last is the LC_ALL value.  */
b9ba6d
-  printf ("LC_ALL=%s\n", lcall ? : "");
b9ba6d
+  print_assignment ("LC_ALL", lcall, false);
b9ba6d
 }
b9ba6d
 
b9ba6d