-/* Copyright (C) 1996-2013 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2019 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper, <drepper@gnu.org>.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
- <http://www.gnu.org/licenses/>. */
+ <https://www.gnu.org/licenses/>. */
#include <byteswap.h>
#include <endian.h>
size_t tab_size;
const char *lastp;
int result = -1;
+ char *buf = NULL;
if (strchr (cat_name, '/') != NULL || nlspath == NULL)
- fd = open_not_cancel_2 (cat_name, O_RDONLY);
+ fd = __open_nocancel (cat_name, O_RDONLY);
else
{
const char *run_nlspath = nlspath;
#define ENOUGH(n) \
- if (__builtin_expect (bufact + (n) >= bufmax, 0)) \
+ if (__glibc_unlikely (bufact + (n) >= bufmax)) \
{ \
char *old_buf = buf; \
- bufmax += 256 + (n); \
- buf = (char *) alloca (bufmax); \
- memcpy (buf, old_buf, bufact); \
+ bufmax += (bufmax < 256 + (n)) ? 256 + (n) : bufmax; \
+ buf = realloc (buf, bufmax); \
+ if (__glibc_unlikely (buf == NULL)) \
+ { \
+ free (old_buf); \
+ return -1; \
+ } \
}
/* The RUN_NLSPATH variable contains a colon separated list of
descriptions where we expect to find catalogs. We have to
recognize certain % substitutions and stop when we found the
first existing file. */
- char *buf;
size_t bufact;
- size_t bufmax;
+ size_t bufmax = 0;
size_t len;
- buf = NULL;
- bufmax = 0;
-
fd = -1;
while (*run_nlspath != '\0')
{
if (bufact != 0)
{
- fd = open_not_cancel_2 (buf, O_RDONLY);
+ fd = __open_nocancel (buf, O_RDONLY);
if (fd >= 0)
break;
}
/* Avoid dealing with directories and block devices */
if (__builtin_expect (fd, 0) < 0)
- return -1;
+ {
+ free (buf);
+ return -1;
+ }
if (__builtin_expect (__fxstat64 (_STAT_VER, fd, &st), 0) < 0)
goto close_unlock_return;
/* Save read, handle partial reads. */
do
{
- size_t now = read_not_cancel (fd, (((char *) catalog->file_ptr)
+ size_t now = __read_nocancel (fd, (((char *) catalog->file_ptr)
+ (st.st_size - todo)), todo);
if (now == 0 || now == (size_t) -1)
{
/* Determine whether the file is a catalog file and if yes whether
it is written using the correct byte order. Else we have to swap
the values. */
- if (__builtin_expect (catalog->file_ptr->magic == CATGETS_MAGIC, 1))
+ if (__glibc_likely (catalog->file_ptr->magic == CATGETS_MAGIC))
swapping = 0;
else if (catalog->file_ptr->magic == SWAPU32 (CATGETS_MAGIC))
swapping = 1;
/* Release the lock again. */
close_unlock_return:
- close_not_cancel_no_status (fd);
+ __close_nocancel_nostatus (fd);
+ free (buf);
return result;
}