glibc/glibc-localedef-arg.patch

141 lines
4.7 KiB
Diff
Raw Normal View History

#
# Posted upstream:
# https://sourceware.org/ml/libc-alpha/2013-10/msg00103.html
#
diff --git a/locale/locarchive.h b/locale/locarchive.h
index f2d8477..fec3b1a 100644
--- a/locale/locarchive.h
+++ b/locale/locarchive.h
@@ -80,6 +80,8 @@ struct locrecent
struct locarhandle
{
+ /* Full path to the locale archive file. */
+ const char *fname;
int fd;
void *addr;
size_t mmaped;
diff --git a/locale/programs/localedef.c b/locale/programs/localedef.c
index 8b9866a..d664232 100644
--- a/locale/programs/localedef.c
+++ b/locale/programs/localedef.c
@@ -209,7 +209,7 @@ main (int argc, char *argv[])
/* Handle a few special cases. */
if (list_archive)
- show_archive_content (verbose);
+ show_archive_content (remaining > 1 ? argv[remaining] : NULL, verbose);
if (add_to_archive)
return add_locales_to_archive (argc - remaining, &argv[remaining],
replace_archive);
diff --git a/locale/programs/localedef.h b/locale/programs/localedef.h
index e010c72..0cfc416 100644
--- a/locale/programs/localedef.h
+++ b/locale/programs/localedef.h
@@ -170,7 +170,8 @@ extern int add_locales_to_archive (size_t nlist, char *list[], bool replace);
/* Removed named locales from archive. */
extern int delete_locales_from_archive (size_t nlist, char *list[]);
-/* List content of locale archive. */
-extern void show_archive_content (int verbose) __attribute__ ((noreturn));
+/* List content of locale archive. If FNAME is non-null use that as
+ the locale archive to list, otherwise the default. */
+extern void show_archive_content (char *fname, int verbose) __attribute__ ((noreturn));
#endif /* localedef.h */
diff --git a/locale/programs/locarchive.c b/locale/programs/locarchive.c
index 13dba0f..b88f1b1 100644
--- a/locale/programs/locarchive.c
+++ b/locale/programs/locarchive.c
@@ -223,6 +223,7 @@ create_archive (const char *archivefname, struct locarhandle *ah)
_("cannot change mode of new locale archive"));
}
+ ah->fname = NULL;
ah->fd = fd;
ah->mmap_base = mmap_base;
ah->mmap_len = mmap_len;
@@ -562,11 +563,19 @@ open_archive (struct locarhandle *ah, bool readonly)
struct locarhead head;
int retry = 0;
size_t prefix_len = output_prefix ? strlen (output_prefix) : 0;
- char archivefname[prefix_len + sizeof (ARCHIVE_NAME)];
+ char fname[prefix_len + sizeof (ARCHIVE_NAME)];
+ char *archivefname = ah->fname;
+ bool defaultfname = false;
- if (output_prefix)
- memcpy (archivefname, output_prefix, prefix_len);
- strcpy (archivefname + prefix_len, ARCHIVE_NAME);
+ /* If ah has a non-NULL fname open that otherwise open the default. */
+ if (archivefname == NULL)
+ {
+ defaultfname = true;
+ archivefname = fname;
+ if (output_prefix)
+ memcpy (archivefname, output_prefix, prefix_len);
+ strcpy (archivefname + prefix_len, ARCHIVE_NAME);
+ }
while (1)
{
@@ -574,8 +583,11 @@ open_archive (struct locarhandle *ah, bool readonly)
fd = open64 (archivefname, readonly ? O_RDONLY : O_RDWR);
if (fd == -1)
{
- /* Maybe the file does not yet exist. */
- if (errno == ENOENT)
+ /* Maybe the file does not yet exist? If we are opening
+ the default locale archive we ignore the failure and
+ list an empty archive, otherwise we print an error
+ and exit. */
+ if (errno == ENOENT && defaultfname)
{
if (readonly)
{
@@ -1324,6 +1336,7 @@ add_locales_to_archive (nlist, list, replace)
/* Open the archive. This call never returns if we cannot
successfully open the archive. */
+ ah.fname = NULL;
open_archive (&ah, false);
while (nlist-- > 0)
@@ -1523,6 +1536,7 @@ delete_locales_from_archive (nlist, list)
/* Open the archive. This call never returns if we cannot
successfully open the archive. */
+ ah.fname = NULL;
open_archive (&ah, false);
head = ah.addr;
@@ -1612,7 +1626,7 @@ dataentcmp (const void *a, const void *b)
void
-show_archive_content (int verbose)
+show_archive_content (char *fname, int verbose)
{
struct locarhandle ah;
struct locarhead *head;
@@ -1622,6 +1636,7 @@ show_archive_content (int verbose)
/* Open the archive. This call never returns if we cannot
successfully open the archive. */
+ ah.fname = fname;
open_archive (&ah, true);
head = ah.addr;
diff --git a/locale/programs/locfile.c b/locale/programs/locfile.c
index 4969391..6410cbd 100644
--- a/locale/programs/locfile.c
+++ b/locale/programs/locfile.c
@@ -343,6 +343,7 @@ write_all_categories (struct localedef_t *definitions,
/* Open the archive. This call never returns if we cannot
successfully open the archive. */
+ ah.fname = NULL;
open_archive (&ah, false);
if (add_locale_to_archive (&ah, locname, to_archive, true) != 0)