From: Bruno Haible Date: Sun, 20 Jun 2021 01:43:50 +0000 (+0200) Subject: intl: Assume strdup exists. X-Git-Tag: v0.21.1~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a7df39a15b806b8a085879f61f28fcc998321b49;p=thirdparty%2Fgettext.git intl: Assume strdup exists. * gettext-runtime/intl/bindtextdom.c (set_binding_values): Assume HAVE_STRDUP to be 1. * gettext-runtime/intl/finddomain.c (_nl_find_domain): Likewise. * gettext-runtime/intl/textdomain.c (TEXTDOMAIN): Likewise. * gettext-runtime/m4/intl.m4 (gt_INTL_SUBDIR_CORE): Don't test for strdup. --- diff --git a/gettext-runtime/intl/bindtextdom.c b/gettext-runtime/intl/bindtextdom.c index 57cf1f486..7eaf47072 100644 --- a/gettext-runtime/intl/bindtextdom.c +++ b/gettext-runtime/intl/bindtextdom.c @@ -133,16 +133,7 @@ set_binding_values (const char *domainname, if (strcmp (dirname, _nl_default_dirname) == 0) result = (char *) _nl_default_dirname; else - { -#if defined _LIBC || defined HAVE_STRDUP - result = strdup (dirname); -#else - size_t len = strlen (dirname) + 1; - result = (char *) malloc (len); - if (__builtin_expect (result != NULL, 1)) - memcpy (result, dirname, len); -#endif - } + result = strdup (dirname); if (__builtin_expect (result != NULL, 1)) { @@ -212,15 +203,7 @@ set_binding_values (const char *domainname, char *result = binding->codeset; if (result == NULL || strcmp (codeset, result) != 0) { -#if defined _LIBC || defined HAVE_STRDUP result = strdup (codeset); -#else - size_t len = strlen (codeset) + 1; - result = (char *) malloc (len); - if (__builtin_expect (result != NULL, 1)) - memcpy (result, codeset, len); -#endif - if (__builtin_expect (result != NULL, 1)) { free (binding->codeset); @@ -281,18 +264,9 @@ set_binding_values (const char *domainname, dirname = _nl_default_dirname; else { - char *result; -#if defined _LIBC || defined HAVE_STRDUP - result = strdup (dirname); + char *result = strdup (dirname); if (__builtin_expect (result == NULL, 0)) goto failed_dirname; -#else - size_t len = strlen (dirname) + 1; - result = (char *) malloc (len); - if (__builtin_expect (result == NULL, 0)) - goto failed_dirname; - memcpy (result, dirname, len); -#endif dirname = result; } } @@ -335,19 +309,9 @@ set_binding_values (const char *domainname, if (codeset != NULL) { - char *result; - -#if defined _LIBC || defined HAVE_STRDUP - result = strdup (codeset); + char *result = strdup (codeset); if (__builtin_expect (result == NULL, 0)) goto failed_codeset; -#else - size_t len = strlen (codeset) + 1; - result = (char *) malloc (len); - if (__builtin_expect (result == NULL, 0)) - goto failed_codeset; - memcpy (result, codeset, len); -#endif codeset = result; } *codesetp = codeset; diff --git a/gettext-runtime/intl/finddomain.c b/gettext-runtime/intl/finddomain.c index 830558d59..e4cab2246 100644 --- a/gettext-runtime/intl/finddomain.c +++ b/gettext-runtime/intl/finddomain.c @@ -136,18 +136,9 @@ _nl_find_domain (const char *dirname, alias_value = _nl_expand_alias (locale); if (alias_value != NULL) { -#if defined _LIBC || defined HAVE_STRDUP locale = strdup (alias_value); if (locale == NULL) return NULL; -#else - size_t len = strlen (alias_value) + 1; - locale = (char *) malloc (len); - if (locale == NULL) - return NULL; - - memcpy (locale, alias_value, len); -#endif } /* Now we determine the single parts of the locale name. First diff --git a/gettext-runtime/intl/textdomain.c b/gettext-runtime/intl/textdomain.c index fb2209dc0..e17cff10b 100644 --- a/gettext-runtime/intl/textdomain.c +++ b/gettext-runtime/intl/textdomain.c @@ -87,18 +87,10 @@ TEXTDOMAIN (const char *domainname) new_domain = old_domain; else { - /* If the following malloc fails `_nl_current_default_domain' + /* If the following strdup fails '_nl_current_default_domain' will be NULL. This value will be returned and so signals we - are out of core. */ -#if defined _LIBC || defined HAVE_STRDUP + are out of memory. */ new_domain = strdup (domainname); -#else - size_t len = strlen (domainname) + 1; - new_domain = (char *) malloc (len); - if (new_domain != NULL) - memcpy (new_domain, domainname, len); -#endif - if (new_domain != NULL) _nl_current_default_domain = new_domain; } diff --git a/gettext-runtime/m4/intl.m4 b/gettext-runtime/m4/intl.m4 index cd5a7287b..dfe68638b 100644 --- a/gettext-runtime/m4/intl.m4 +++ b/gettext-runtime/m4/intl.m4 @@ -1,4 +1,4 @@ -# intl.m4 serial 49 (gettext-0.21.1) +# intl.m4 serial 50 (gettext-0.21.1) dnl Copyright (C) 1995-2014, 2016-2021 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -242,7 +242,7 @@ AC_DEFUN([gt_INTL_SUBDIR_CORE], AC_CHECK_HEADERS([inttypes.h unistd.h sys/param.h]) AC_CHECK_FUNCS([getcwd getegid geteuid getgid getuid mempcpy munmap \ - stpcpy strcasecmp strdup strtoul tsearch __fsetlocking]) + stpcpy strcasecmp strtoul tsearch __fsetlocking]) dnl Use the *_unlocked functions only if they are declared. dnl (because some of them were defined without being declared in Solaris