-/* 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.
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>
#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"
extern const char *output_prefix;
-#define ARCHIVE_NAME LOCALEDIR "/locale-archive"
+#define ARCHIVE_NAME COMPLOCALEDIR "/locale-archive"
static const char *locnames[] =
{
_("cannot change mode of new locale archive"));
}
+ ah->fname = NULL;
ah->fd = fd;
ah->mmap_base = mmap_base;
ah->mmap_len = mmap_len;
{
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);
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)
{
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)
{
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;
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)
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);
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;
/* Open the archive. This call never returns if we cannot
successfully open the archive. */
+ ah.fname = NULL;
open_archive (&ah, false);
head = ah.addr;
void
-show_archive_content (int verbose)
+show_archive_content (const char *fname, int verbose)
{
struct locarhandle ah;
struct locarhead *head;
/* Open the archive. This call never returns if we cannot
successfully open the archive. */
+ ah.fname = fname;
open_archive (&ah, true);
head = ah.addr;