Blame SOURCES/glibc-rh625893.patch

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