1From f4b1d6429298c0f8a2aa29ff559eb2093ea0188f Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Fri, 3 Aug 2018 09:42:06 -0700
4Subject: [PATCH] localedef --add-to-archive uses a hard-coded locale path
5
6it doesn't exist in normal use, and there's no way to pass an
7alternative filename.
8
9Add a fallback of $LOCALEARCHIVE from the environment, and allow
10creation of new locale archives that are not the system archive.
11
12Upstream-Status: Inappropriate (OE-specific)
13
14Signed-off-by: Ross Burton <ross.burton@intel.com>
15Signed-off-by: Khem Raj <raj.khem@gmail.com>
16---
17 locale/programs/locarchive.c | 35 +++++++++++++++++++++++++----------
18 1 file changed, 25 insertions(+), 10 deletions(-)
19
20diff --git a/locale/programs/locarchive.c b/locale/programs/locarchive.c
21index 8d79a1b6d1..6dc7ecd4e7 100644
22--- a/locale/programs/locarchive.c
23+++ b/locale/programs/locarchive.c
24@@ -339,12 +339,24 @@ enlarge_archive (struct locarhandle *ah, const struct locarhead *head)
25   struct namehashent *oldnamehashtab;
26   struct locarhandle new_ah;
27   size_t prefix_len = output_prefix ? strlen (output_prefix) : 0;
28-  char archivefname[prefix_len + sizeof (ARCHIVE_NAME)];
29-  char fname[prefix_len + sizeof (ARCHIVE_NAME) + sizeof (".XXXXXX") - 1];
30+  char *archivefname;
31+  char *fname;
32+  char *envarchive = getenv("LOCALEARCHIVE");
33
34-  if (output_prefix)
35-    memcpy (archivefname, output_prefix, prefix_len);
36-  strcpy (archivefname + prefix_len, ARCHIVE_NAME);
37+  if (envarchive != NULL)
38+    {
39+      archivefname = xmalloc(strlen(envarchive) + 1);
40+      fname = xmalloc(strlen(envarchive) + sizeof (".XXXXXX"));
41+      strcpy (archivefname, envarchive);
42+    }
43+  else
44+    {
45+      archivefname = xmalloc(prefix_len + sizeof (ARCHIVE_NAME));
46+      fname = xmalloc(prefix_len + sizeof (ARCHIVE_NAME) + sizeof (".XXXXXX") - 1);
47+      if (output_prefix)
48+        memcpy (archivefname, output_prefix, prefix_len);
49+      strcpy (archivefname + prefix_len, ARCHIVE_NAME);
50+    }
51   strcpy (stpcpy (fname, archivefname), ".XXXXXX");
52
53   /* Not all of the old file has to be mapped.  Change this now this
54@@ -568,10 +580,13 @@ open_archive (struct locarhandle *ah, bool readonly)
55   /* If ah has a non-NULL fname open that otherwise open the default.  */
56   if (archivefname == NULL)
57     {
58-      archivefname = default_fname;
59-      if (output_prefix)
60-        memcpy (default_fname, output_prefix, prefix_len);
61-      strcpy (default_fname + prefix_len, ARCHIVE_NAME);
62+      archivefname = getenv("LOCALEARCHIVE");
63+      if (archivefname == NULL) {
64+              archivefname = default_fname;
65+              if (output_prefix)
66+                memcpy (default_fname, output_prefix, prefix_len);
67+              strcpy (default_fname + prefix_len, ARCHIVE_NAME);
68+      }
69     }
70
71   while (1)
72@@ -584,7 +599,7 @@ open_archive (struct locarhandle *ah, bool readonly)
73 	     the default locale archive we ignore the failure and
74 	     list an empty archive, otherwise we print an error
75 	     and exit.  */
76-	  if (errno == ENOENT && archivefname == default_fname)
77+	  if (errno == ENOENT)
78 	    {
79 	      if (readonly)
80 		{
81