]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - locale/programs/locarchive.c
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / locale / programs / locarchive.c
index e2a30b5682aa7ab638bb6ecaa530f34c933deeca..88e9ce1a126864027c4c657011c796bfa2101096 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002-2013 Free Software Foundation, Inc.
+/* Copyright (C) 2002-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
 
@@ -13,7 +13,7 @@
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, see <http://www.gnu.org/licenses/>.  */
+   along with this program; if not, see <https://www.gnu.org/licenses/>.  */
 
 #ifdef HAVE_CONFIG_H
 # include <config.h>
@@ -40,8 +40,8 @@
 #include <sys/shm.h>
 #include <sys/stat.h>
 
-#include <libc-internal.h>
 #include <libc-mmap.h>
+#include <libc-pointer-arith.h>
 #include "../../crypt/md5.h"
 #include "../localeinfo.h"
 #include "../locarchive.h"
@@ -57,7 +57,7 @@
 
 extern const char *output_prefix;
 
-#define ARCHIVE_NAME LOCALEDIR "/locale-archive"
+#define ARCHIVE_NAME COMPLOCALEDIR "/locale-archive"
 
 static const char *locnames[] =
   {
@@ -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;
@@ -319,8 +320,8 @@ compare_from_file (struct locarhandle *ah, void *p1, uint32_t offset2,
 {
   void *p2 = xmalloc (size);
   if (pread (ah->fd, p2, size, offset2) != size)
-    WITH_CUR_LOCALE (error (4, errno,
-                           _("cannot read data from locale archive")));
+    record_error (4, errno,
+                 _("cannot read data from locale archive"));
 
   int res = memcmp (p1, p2, size);
   free (p2);
@@ -562,11 +563,17 @@ 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 default_fname[prefix_len + sizeof (ARCHIVE_NAME)];
+  const char *archivefname = ah->fname;
 
-  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)
+    {
+      archivefname = default_fname;
+      if (output_prefix)
+        memcpy (default_fname, output_prefix, prefix_len);
+      strcpy (default_fname + prefix_len, ARCHIVE_NAME);
+    }
 
   while (1)
     {
@@ -574,8 +581,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 && archivefname == default_fname)
            {
              if (readonly)
                {
@@ -1117,11 +1127,8 @@ add_locale (struct locarhandle *ah,
    of the files if necessary.  Add all the names, possibly overwriting
    old files.  */
 int
-add_locale_to_archive (ah, name, data, replace)
-     struct locarhandle *ah;
-     const char *name;
-     locale_data_t data;
-     bool replace;
+add_locale_to_archive (struct locarhandle *ah, const char *name,
+                      locale_data_t data, bool replace)
 {
   char *normalized_name = NULL;
   uint32_t locrec_offset;
@@ -1319,16 +1326,14 @@ add_locale_to_archive (ah, name, data, replace)
 
 
 int
-add_locales_to_archive (nlist, list, replace)
-     size_t nlist;
-     char *list[];
-     bool replace;
+add_locales_to_archive (size_t nlist, char *list[], bool replace)
 {
   struct locarhandle ah;
   int result = 0;
 
   /* Open the archive.  This call never returns if we cannot
      successfully open the archive.  */
+  ah.fname = NULL;
   open_archive (&ah, false);
 
   while (nlist-- > 0)
@@ -1380,17 +1385,13 @@ add_locales_to_archive (nlist, list, replace)
                     a directory we have to look at a file with the
                     prefix "SYS_".  Otherwise we have found what we
                     are looking for.  */
-#ifdef _DIRENT_HAVE_D_TYPE
                  d_type = d->d_type;
 
                  if (d_type != DT_REG)
-#endif
                    {
                      char fullname[fnamelen + 2 * strlen (d->d_name) + 7];
 
-#ifdef _DIRENT_HAVE_D_TYPE
                      if (d_type == DT_UNKNOWN)
-#endif
                        {
                          strcpy (stpcpy (stpcpy (fullname, fname), "/"),
                                  d->d_name);
@@ -1518,9 +1519,7 @@ add_locales_to_archive (nlist, list, replace)
 
 
 int
-delete_locales_from_archive (nlist, list)
-     size_t nlist;
-     char *list[];
+delete_locales_from_archive (size_t nlist, char *list[])
 {
   struct locarhandle ah;
   struct locarhead *head;
@@ -1528,6 +1527,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;
@@ -1617,7 +1617,7 @@ dataentcmp (const void *a, const void *b)
 
 
 void
-show_archive_content (int verbose)
+show_archive_content (const char *fname, int verbose)
 {
   struct locarhandle ah;
   struct locarhead *head;
@@ -1627,6 +1627,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;