]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - locale/loadlocale.c
Replace = with += in CFLAGS-xxx.c/CPPFLAGS-xxx.c
[thirdparty/glibc.git] / locale / loadlocale.c
index 6ef25b023477228b1009e9a45334e9b65d8c1ebd..2dba86d7738201d80646b756750412864f618209 100644 (file)
@@ -1,5 +1,5 @@
 /* Functions to read locale data files.
-   Copyright (C) 1996-2004, 2005, 2006, 2010 Free Software Foundation, Inc.
+   Copyright (C) 1996-2017 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
 
@@ -14,9 +14,8 @@
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
 
 #include <assert.h>
 #include <errno.h>
@@ -45,8 +44,12 @@ static const size_t _nl_category_num_items[] =
 
 #define NO_PAREN(arg, rest...) arg, ##rest
 
+/* The size of the array must be specified explicitly because some of
+   the 'items' may be subarrays, which will cause the compiler to deduce
+   an incorrect size from the initializer.  */
 #define DEFINE_CATEGORY(category, category_name, items, a) \
-static const enum value_type _nl_value_type_##category[] = { NO_PAREN items };
+static const enum value_type _nl_value_type_##category     \
+  [_NL_ITEM_INDEX (_NL_NUM_##category)] = { NO_PAREN items };
 #define DEFINE_ELEMENT(element, element_name, optstd, type, rest...) \
   [_NL_ITEM_INDEX (element)] = type,
 #include "categories.def"
@@ -62,7 +65,6 @@ static const enum value_type *const _nl_value_types[] =
 
 
 struct __locale_data *
-internal_function
 _nl_intern_locale_data (int category, const void *data, size_t datasize)
 {
   const struct
@@ -108,7 +110,7 @@ _nl_intern_locale_data (int category, const void *data, size_t datasize)
   for (cnt = 0; cnt < newdata->nstrings; ++cnt)
     {
       size_t idx = filedata->strindex[cnt];
-      if (__builtin_expect (idx > (size_t) newdata->filesize, 0))
+      if (__glibc_unlikely (idx > (size_t) newdata->filesize))
        {
        puntdata:
          free (newdata);
@@ -122,9 +124,10 @@ _nl_intern_locale_data (int category, const void *data, size_t datasize)
       switch (category)
        {
 #define CATTEST(cat) \
-       case LC_##cat:                                                        \
-         assert (cnt < (sizeof (_nl_value_type_LC_##cat)                     \
-                        / sizeof (_nl_value_type_LC_##cat[0])));             \
+       case LC_##cat:                                          \
+         if (cnt >= (sizeof (_nl_value_type_LC_##cat)          \
+                     / sizeof (_nl_value_type_LC_##cat[0])))   \
+           goto puntdata;                                      \
          break
          CATTEST (NUMERIC);
          CATTEST (TIME);
@@ -149,10 +152,10 @@ _nl_intern_locale_data (int category, const void *data, size_t datasize)
        newdata->values[cnt].string = newdata->filedata + idx;
       else
        {
-         if (idx % __alignof__ (u_int32_t) != 0)
+         if (!LOCFILE_ALIGNED_P (idx))
            goto puntdata;
          newdata->values[cnt].word =
-           *((const u_int32_t *) (newdata->filedata + idx));
+           *((const uint32_t *) (newdata->filedata + idx));
        }
     }
 
@@ -160,7 +163,6 @@ _nl_intern_locale_data (int category, const void *data, size_t datasize)
 }
 
 void
-internal_function
 _nl_load_locale (struct loaded_l10nfile *file, int category)
 {
   int fd;
@@ -173,7 +175,7 @@ _nl_load_locale (struct loaded_l10nfile *file, int category)
   file->decided = 1;
   file->data = NULL;
 
-  fd = open_not_cancel_2 (file->filename, O_RDONLY);
+  fd = __open_nocancel (file->filename, O_RDONLY | O_CLOEXEC);
   if (__builtin_expect (fd, 0) < 0)
     /* Cannot open the file.  */
     return;
@@ -181,17 +183,17 @@ _nl_load_locale (struct loaded_l10nfile *file, int category)
   if (__builtin_expect (__fxstat64 (_STAT_VER, fd, &st), 0) < 0)
     {
     puntfd:
-      close_not_cancel_no_status (fd);
+      __close_nocancel_nostatus (fd);
       return;
     }
-  if (__builtin_expect (S_ISDIR (st.st_mode), 0))
+  if (__glibc_unlikely (S_ISDIR (st.st_mode)))
     {
       /* LOCALE/LC_foo is a directory; open LOCALE/LC_foo/SYS_LC_foo
           instead.  */
       char *newp;
       size_t filenamelen;
 
-      close_not_cancel_no_status (fd);
+      __close_nocancel_nostatus (fd);
 
       filenamelen = strlen (file->filename);
       newp = (char *) alloca (filenamelen
@@ -201,7 +203,7 @@ _nl_load_locale (struct loaded_l10nfile *file, int category)
                 _nl_category_names.str + _nl_category_name_idxs[category],
                 _nl_category_name_sizes[category] + 1);
 
-      fd = open_not_cancel_2 (newp, O_RDONLY);
+      fd = __open_nocancel (newp, O_RDONLY | O_CLOEXEC);
       if (__builtin_expect (fd, 0) < 0)
        return;
 
@@ -222,8 +224,9 @@ _nl_load_locale (struct loaded_l10nfile *file, int category)
 # endif
   filedata = __mmap ((caddr_t) 0, st.st_size,
                     PROT_READ, MAP_FILE|MAP_COPY, fd, 0);
-  if (__builtin_expect (filedata == MAP_FAILED, 0))
+  if (__glibc_unlikely (filedata == MAP_FAILED))
     {
+      filedata = NULL;
       if (__builtin_expect (errno, ENOSYS) == ENOSYS)
        {
 #endif /* _POSIX_MAPPED_FILES */
@@ -237,7 +240,7 @@ _nl_load_locale (struct loaded_l10nfile *file, int category)
              char *p = (char *) filedata;
              while (to_read > 0)
                {
-                 nread = read_not_cancel (fd, p, to_read);
+                 nread = __read_nocancel (fd, p, to_read);
                  if (__builtin_expect (nread, 1) <= 0)
                    {
                      free (filedata);
@@ -256,14 +259,14 @@ _nl_load_locale (struct loaded_l10nfile *file, int category)
 #endif /* _POSIX_MAPPED_FILES */
 
   /* We have mapped the data, so we no longer need the descriptor.  */
-  close_not_cancel_no_status (fd);
+  __close_nocancel_nostatus (fd);
 
-  if (__builtin_expect (filedata == NULL, 0))
+  if (__glibc_unlikely (filedata == NULL))
     /* We failed to map or read the data.  */
     return;
 
   newdata = _nl_intern_locale_data (category, filedata, st.st_size);
-  if (__builtin_expect (newdata == NULL, 0))
+  if (__glibc_unlikely (newdata == NULL))
     /* Bad data.  */
     {
 #ifdef _POSIX_MAPPED_FILES
@@ -281,7 +284,6 @@ _nl_load_locale (struct loaded_l10nfile *file, int category)
 }
 
 void
-internal_function
 _nl_unload_locale (struct __locale_data *locale)
 {
   if (locale->private.cleanup)