Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 1 | From 2ec233ce078b74030de9195096058cd502fdc395 Mon Sep 17 00:00:00 2001 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Fri, 3 Aug 2018 09:42:06 -0700 |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 4 | Subject: [PATCH] localedef --add-to-archive uses a hard-coded locale path |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 5 | |
| 6 | it doesn't exist in normal use, and there's no way to pass an |
| 7 | alternative filename. |
| 8 | |
| 9 | Add a fallback of $LOCALEARCHIVE from the environment, and allow |
| 10 | creation of new locale archives that are not the system archive. |
| 11 | |
| 12 | Upstream-Status: Inappropriate (OE-specific) |
| 13 | |
| 14 | Signed-off-by: Ross Burton <ross.burton@intel.com> |
| 15 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 16 | --- |
| 17 | locale/programs/locarchive.c | 35 +++++++++++++++++++++++++---------- |
| 18 | 1 file changed, 25 insertions(+), 10 deletions(-) |
| 19 | |
| 20 | diff --git a/locale/programs/locarchive.c b/locale/programs/locarchive.c |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 21 | index 6bb189ae37..0711c5c44e 100644 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 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 | @@ -569,10 +581,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 | @@ -585,7 +600,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 | { |