1
/* Load needed message catalogs.
2
Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2, or (at your option)
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software Foundation,
16
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23
#include <sys/types.h>
26
#if defined STDC_HEADERS || defined _LIBC
30
#if defined HAVE_UNISTD_H || defined _LIBC
34
#define DISALLOW_MMAP 1 /* ADR */
35
#if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \
36
|| (defined _LIBC && defined _POSIX_MAPPED_FILES)
37
# include <sys/mman.h>
47
/* @@ end of prolog @@ */
50
/* Rename the non ISO C functions. This is required by the standard
51
because some ISO C functions will require linking with this object
52
file and the name space must not be polluted. */
54
# define close __close
57
# define munmap __munmap
60
/* We need a sign, whether a new catalog was loaded, which can be associated
61
with all translations. This is important if the translations are
62
cached by one of GCC's features. */
63
int _nl_msg_cat_cntr = 0;
66
/* Load the message catalogs specified by FILENAME. If it is no valid
67
message catalog do nothing. */
70
_nl_load_domain (domain_file)
71
struct loaded_l10nfile *domain_file;
76
struct mo_file_header *data = (struct mo_file_header *) -1;
78
struct loaded_domain *domain;
80
domain_file->decided = 1;
81
domain_file->data = NULL;
83
/* If the record does not represent a valid locale the FILENAME
84
might be NULL. This can happen when according to the given
85
specification the locale file name is different for XPG and CEN
87
if (domain_file->filename == NULL)
90
/* Try to open the addressed file. */
91
fd = open (domain_file->filename, O_RDONLY);
95
/* We must know about the size of the file. */
96
if (fstat (fd, &st) != 0
97
|| (size = (size_t) st.st_size) != st.st_size
98
|| size < sizeof (struct mo_file_header))
100
/* Something went wrong. */
106
/* Now we are ready to load the file. If mmap() is available we try
107
this first. If not available or it failed we try to load it. */
108
data = (struct mo_file_header *) mmap (NULL, size, PROT_READ,
111
if (data != (struct mo_file_header *) -1)
113
/* mmap() call was successful. */
119
/* If the data is not yet available (i.e. mmap'ed) we try to load
121
if (data == (struct mo_file_header *) -1)
126
data = (struct mo_file_header *) malloc (size);
131
read_ptr = (char *) data;
134
long int nb = (long int) read (fd, read_ptr, to_read);
149
/* Using the magic number we can test whether it really is a message
151
if (data->magic != _MAGIC && data->magic != _MAGIC_SWAPPED)
153
/* The magic number is wrong: not a message catalog file. */
156
munmap ((caddr_t) data, size);
164
= (struct loaded_domain *) malloc (sizeof (struct loaded_domain));
165
if (domain_file->data == NULL)
168
domain = (struct loaded_domain *) domain_file->data;
169
domain->data = (char *) data;
170
domain->use_mmap = use_mmap;
171
domain->mmap_size = size;
172
domain->must_swap = data->magic != _MAGIC;
174
/* Fill in the information about the available tables. */
175
switch (W (domain->must_swap, data->revision))
178
domain->nstrings = W (domain->must_swap, data->nstrings);
179
domain->orig_tab = (struct string_desc *)
180
((char *) data + W (domain->must_swap, data->orig_tab_offset));
181
domain->trans_tab = (struct string_desc *)
182
((char *) data + W (domain->must_swap, data->trans_tab_offset));
183
domain->hash_size = W (domain->must_swap, data->hash_tab_size);
184
domain->hash_tab = (nls_uint32 *)
185
((char *) data + W (domain->must_swap, data->hash_tab_offset));
188
/* This is an invalid revision. */
191
munmap ((caddr_t) data, size);
196
domain_file->data = NULL;
200
/* Show that one domain is changed. This might make some cached
201
translations invalid. */
209
_nl_unload_domain (domain)
210
struct loaded_domain *domain;
212
#ifdef _POSIX_MAPPED_FILES
213
if (domain->use_mmap)
214
munmap ((caddr_t) domain->data, domain->mmap_size);
216
#endif /* _POSIX_MAPPED_FILES */
217
free ((void *) domain->data);