+++ /dev/null
-/* Load needed message catalogs.\r
- Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.\r
-\r
- This program is free software; you can redistribute it and/or modify\r
- it under the terms of the GNU General Public License as published by\r
- the Free Software Foundation; either version 2, or (at your option)\r
- any later version.\r
-\r
- This program is distributed in the hope that it will be useful,\r
- but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- GNU General Public License for more details.\r
-\r
- You should have received a copy of the GNU General Public License\r
- along with this program; if not, write to the Free Software Foundation,\r
- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA. */\r
-\r
-#include "intlconfig.h"\r
-\r
-#include <fcntl.h>\r
-#include <sys/types.h>\r
-#include <sys/stat.h>\r
-\r
-#if defined STDC_HEADERS || defined _LIBC\r
-# include <stdlib.h>\r
-#endif\r
-\r
-#if defined HAVE_UNISTD_H || defined _LIBC\r
-# include <unistd.h>\r
-#endif\r
-\r
-#if (defined HAVE_MMAP && defined HAVE_MUNMAP) || defined _LIBC\r
-# include <sys/mman.h>\r
-#endif\r
-\r
-#ifdef _WIN32\r
-#include <io.h>\r
-#ifdef _MSC_VER\r
-#pragma warning (disable:4018)\r
-#endif\r
-#endif\r
-\r
-#include "gettext.h"\r
-#include "gettextP.h"\r
-\r
-/* @@ end of prolog @@ */\r
-\r
-#ifdef _LIBC\r
-/* Rename the non ISO C functions. This is required by the standard\r
- because some ISO C functions will require linking with this object\r
- file and the name space must not be polluted. */\r
-# define open __open\r
-# define close __close\r
-# define read __read\r
-# define mmap __mmap\r
-# define munmap __munmap\r
-#endif\r
-\r
-/* We need a sign, whether a new catalog was loaded, which can be associated\r
- with all translations. This is important if the translations are\r
- cached by one of GCC's features. */\r
-int _nl_msg_cat_cntr = 0;\r
-\r
-\r
-/* Load the message catalogs specified by FILENAME. If it is no valid\r
- message catalog do nothing. */\r
-void\r
-internal_function\r
-_nl_load_domain (domain_file)\r
- struct loaded_l10nfile *domain_file;\r
-{\r
- int fd;\r
- size_t size;\r
- struct stat st;\r
- struct mo_file_header *data = (struct mo_file_header *) -1;\r
-#if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \\r
- || defined _LIBC\r
- int use_mmap = 0;\r
-#endif\r
- struct loaded_domain *domain;\r
-\r
- domain_file->decided = 1;\r
- domain_file->data = NULL;\r
-\r
- /* If the record does not represent a valid locale the FILENAME\r
- might be NULL. This can happen when according to the given\r
- specification the locale file name is different for XPG and CEN\r
- syntax. */\r
- if (domain_file->filename == NULL)\r
- return;\r
-\r
- /* Try to open the addressed file. */\r
- fd = open (domain_file->filename, O_RDONLY | O_BINARY); /*FRANCO - binary*/\r
- if (fd == -1)\r
- return;\r
-\r
- /* We must know about the size of the file. */\r
- if (fstat (fd, &st) != 0\r
- || (size = (size_t) st.st_size) != st.st_size\r
- || size < sizeof (struct mo_file_header))\r
- {\r
- /* Something went wrong. */\r
- close (fd);\r
- return;\r
- }\r
-\r
-#if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \\r
- || defined _LIBC\r
- /* Now we are ready to load the file. If mmap() is available we try\r
- this first. If not available or it failed we try to load it. */\r
- data = (struct mo_file_header *) mmap (NULL, size, PROT_READ,\r
- MAP_PRIVATE, fd, 0);\r
-\r
- if (data != (struct mo_file_header *) -1)\r
- {\r
- /* mmap() call was successful. */\r
- close (fd);\r
- use_mmap = 1;\r
- }\r
-#endif\r
-\r
- /* If the data is not yet available (i.e. mmap'ed) we try to load\r
- it manually. */\r
- if (data == (struct mo_file_header *) -1)\r
- {\r
- size_t to_read;\r
- char *read_ptr;\r
-\r
- data = (struct mo_file_header *) malloc (size);\r
- if (data == NULL)\r
- return;\r
-\r
- to_read = size;\r
- read_ptr = (char *) data;\r
- do\r
- {\r
- long int nb = (long int) read (fd, read_ptr, to_read);\r
- if (nb == -1)\r
- {\r
- close (fd);\r
- return;\r
- }\r
-\r
- read_ptr += nb;\r
- to_read -= nb;\r
- }\r
- while (to_read > 0);\r
-\r
- close (fd);\r
- }\r
-\r
- /* Using the magic number we can test whether it really is a message\r
- catalog file. */\r
- if (data->magic != _MAGIC && data->magic != _MAGIC_SWAPPED)\r
- {\r
- /* The magic number is wrong: not a message catalog file. */\r
-#if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \\r
- || defined _LIBC\r
- if (use_mmap)\r
- munmap ((caddr_t) data, size);\r
- else\r
-#endif\r
- free (data);\r
- return;\r
- }\r
-\r
- domain_file->data\r
- = (struct loaded_domain *) malloc (sizeof (struct loaded_domain));\r
- if (domain_file->data == NULL)\r
- return;\r
-\r
- domain = (struct loaded_domain *) domain_file->data;\r
- domain->data = (char *) data;\r
-#if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \\r
- || defined _LIBC\r
- domain->use_mmap = use_mmap;\r
-#endif\r
- domain->mmap_size = size;\r
- domain->must_swap = data->magic != _MAGIC;\r
-\r
- /* Fill in the information about the available tables. */\r
- switch (W (domain->must_swap, data->revision))\r
- {\r
- case 0:\r
- domain->nstrings = W (domain->must_swap, data->nstrings);\r
- domain->orig_tab = (struct string_desc *)\r
- ((char *) data + W (domain->must_swap, data->orig_tab_offset));\r
- domain->trans_tab = (struct string_desc *)\r
- ((char *) data + W (domain->must_swap, data->trans_tab_offset));\r
- domain->hash_size = W (domain->must_swap, data->hash_tab_size);\r
- domain->hash_tab = (nls_uint32 *)\r
- ((char *) data + W (domain->must_swap, data->hash_tab_offset));\r
- break;\r
- default:\r
- /* This is an illegal revision. */\r
-#if (defined HAVE_MMAP && defined HAVE_MUNMAP && !defined DISALLOW_MMAP) \\r
- || defined _LIBC\r
- if (use_mmap)\r
- munmap ((caddr_t) data, size);\r
- else\r
-#endif\r
- free (data);\r
- free (domain);\r
- domain_file->data = NULL;\r
- return;\r
- }\r
-\r
- /* Show that one domain is changed. This might make some cached\r
- translations invalid. */\r
- ++_nl_msg_cat_cntr;\r
-}\r
-\r
-\r
-#ifdef _LIBC\r
-void\r
-internal_function\r
-_nl_unload_domain (domain)\r
- struct loaded_domain *domain;\r
-{\r
- if (domain->use_mmap)\r
- munmap ((caddr_t) domain->data, domain->mmap_size);\r
- else\r
- free ((void *) domain->data);\r
-\r
- free (domain);\r
-}\r
-#endif\r