This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Enhance localedef to accept file argument for --list-archive.


Community,

The utility `localedef' has an option called `--list-archive'
which allows you to list all of the locales that are currently
loaded in a locale archive (useful if you're debugging locale
archive creation).

When you run `localedef --help' it says:
~~~
...
Usage: localedef [OPTION...] NAME
  or:  localedef [OPTION...] [--add-to-archive|--delete-from-archive] FILE...
  or:  localedef [OPTION...] --list-archive [FILE]
...
~~~

Notice that it shows `--list-archive' as accepting an optional
FILE argument. It makes logical sense for you to leave
FILE off and list the locales in the default locale archive,
or add a FILE and list the locales in an archive you're building.

Unfortunately the current implementation ignores FILE entirely,
and always lists from the default locale archive.

This patch implements the support for listing locales from an
alternate locale archive as the usage suggests. If FILE is
not specified the default locale is loaded, otherwise the specified
file is loaded as if it were a locale archive. It's only an error
if the user specified locale archive doesn't exist (the current
code treats a missing default locale archive as if it was empty).

Tested on x86-64.

Comments?

If nobody objects I'll check this in next Monday, it seems like
entirely obvious and missing functionality.

2013-10-03  Carlos O'Donell  <carlos@redhat.com>

	* locale/locarchive.h (struct locarhandle): Add fname.
	* locale/programs/localedef.c (main): Pass argv[remaining]
	if an optional argument was specified to --list-archive
	otherwise NULL.
	* locale/programs/localedef.h: Pass fname as first argument
	for show_archive_content.
	* locale/programs/locarchive.c (show_archive_content): Pass fname 
	via ah.fname to open_archive.
	(open_archive): Use ah->fname as the locale archive otherwise
	open the default locale archive. It's an error for a user specified
	locale archive not to exist.

diff --git a/locale/locarchive.h b/locale/locarchive.h
index f2d8477..04e5229 100644
--- a/locale/locarchive.h
+++ b/locale/locarchive.h
@@ -80,6 +80,8 @@ struct locrecent
 
 struct locarhandle
 {
+  /* Full path to the locale archive file.  */
+  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..7e577bb 100644
--- a/locale/programs/locarchive.c
+++ b/locale/programs/locarchive.c
@@ -562,11 +562,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 +582,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)
 		{
@@ -1612,7 +1623,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 +1633,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;
---

Cheers,
Carlos.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]