blob: e17f6aa3b9a3bbf2b0dda665c04721b4dc7a5cdf [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001From 865651d2496a90f7ae8e7cc19a2e54b6f17a8ad5 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 | 37 ++++++++++++++++++++++++++----------
18 1 file changed, 27 insertions(+), 10 deletions(-)
19
20diff --git a/locale/programs/locarchive.c b/locale/programs/locarchive.c
21index ca332a345f..91f62da662 100644
22--- a/locale/programs/locarchive.c
23+++ b/locale/programs/locarchive.c
24@@ -340,12 +340,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@@ -551,6 +563,8 @@ enlarge_archive (struct locarhandle *ah, const struct locarhead *head)
55
56 /* Add the information for the new one. */
57 *ah = new_ah;
58+ free(archivefname);
59+ free(fname);
60 }
61
62
63@@ -569,10 +583,13 @@ open_archive (struct locarhandle *ah, bool readonly)
64 /* If ah has a non-NULL fname open that otherwise open the default. */
65 if (archivefname == NULL)
66 {
67- archivefname = default_fname;
68- if (output_prefix)
69- memcpy (default_fname, output_prefix, prefix_len);
70- strcpy (default_fname + prefix_len, ARCHIVE_NAME);
71+ archivefname = getenv("LOCALEARCHIVE");
72+ if (archivefname == NULL) {
73+ archivefname = default_fname;
74+ if (output_prefix)
75+ memcpy (default_fname, output_prefix, prefix_len);
76+ strcpy (default_fname + prefix_len, ARCHIVE_NAME);
77+ }
78 }
79
80 while (1)
81@@ -585,7 +602,7 @@ open_archive (struct locarhandle *ah, bool readonly)
82 the default locale archive we ignore the failure and
83 list an empty archive, otherwise we print an error
84 and exit. */
85- if (errno == ENOENT && archivefname == default_fname)
86+ if (errno == ENOENT)
87 {
88 if (readonly)
89 {