Remove wcsdup fallback

2a0e0d6721 removed the last use of it,
and in most cases we'd probably prefer to use a wcstring instead
This commit is contained in:
Fabian Boehm 2022-08-27 11:36:15 +02:00
parent 4dfcd4cb4e
commit 5e0f5eff37
4 changed files with 2 additions and 39 deletions

View File

@ -133,18 +133,12 @@ SET(CMAKE_C_FLAGS "${OLD_CMAKE_C_FLAGS}")
check_cxx_symbol_exists(eventfd sys/eventfd.h HAVE_EVENTFD) check_cxx_symbol_exists(eventfd sys/eventfd.h HAVE_EVENTFD)
check_cxx_symbol_exists(pipe2 unistd.h HAVE_PIPE2) check_cxx_symbol_exists(pipe2 unistd.h HAVE_PIPE2)
check_cxx_symbol_exists(wcscasecmp wchar.h HAVE_WCSCASECMP) check_cxx_symbol_exists(wcscasecmp wchar.h HAVE_WCSCASECMP)
check_cxx_symbol_exists(wcsdup wchar.h HAVE_WCSDUP)
check_cxx_symbol_exists(wcsncasecmp wchar.h HAVE_WCSNCASECMP) check_cxx_symbol_exists(wcsncasecmp wchar.h HAVE_WCSNCASECMP)
# These are for compatibility with Solaris 10, which places the following # These are for compatibility with Solaris 10, which places the following
# in the std namespace. # in the std namespace.
if(NOT HAVE_WCSNCASECMP) if(NOT HAVE_WCSNCASECMP)
check_cxx_symbol_exists(std::wcscasecmp wchar.h HAVE_STD__WCSCASECMP) check_cxx_symbol_exists(std::wcscasecmp wchar.h HAVE_STD__WCSCASECMP)
endif()
if(NOT HAVE_WCSDUP)
check_cxx_symbol_exists(std::wcsdup wchar.h HAVE_STD__WCSDUP)
endif()
if(NOT HAVE_WCSNCASECMP)
check_cxx_symbol_exists(std::wcsncasecmp wchar.h HAVE_STD__WCSNCASECMP) check_cxx_symbol_exists(std::wcsncasecmp wchar.h HAVE_STD__WCSNCASECMP)
endif() endif()

View File

@ -61,9 +61,6 @@
/* Define to 1 if you have the `std::wcscasecmp' function. */ /* Define to 1 if you have the `std::wcscasecmp' function. */
#cmakedefine HAVE_STD__WCSCASECMP 1 #cmakedefine HAVE_STD__WCSCASECMP 1
/* Define to 1 if you have the `std::wcsdup' function. */
#cmakedefine HAVE_STD__WCSDUP 1
/* Define to 1 if you have the `std::wcsncasecmp' function. */ /* Define to 1 if you have the `std::wcsncasecmp' function. */
#cmakedefine HAVE_STD__WCSNCASECMP 1 #cmakedefine HAVE_STD__WCSNCASECMP 1
@ -94,9 +91,6 @@
/* Define to 1 if you have the `wcscasecmp' function. */ /* Define to 1 if you have the `wcscasecmp' function. */
#cmakedefine HAVE_WCSCASECMP 1 #cmakedefine HAVE_WCSCASECMP 1
/* Define to 1 if you have the `wcsdup' function. */
#cmakedefine HAVE_WCSDUP 1
/* Define to 1 if you have the `wcsncasecmp' function. */ /* Define to 1 if you have the `wcsncasecmp' function. */
#cmakedefine HAVE_WCSNCASECMP 1 #cmakedefine HAVE_WCSNCASECMP 1

View File

@ -58,21 +58,10 @@ int fish_mkstemp_cloexec(char *name_template) {
return result_fd; return result_fd;
} }
/// Fallback implementations of wcsdup and wcscasecmp. On systems where these are not needed (e.g. /// Fallback implementations of wcsncasecmp and wcscasecmp. On systems where these are not needed (e.g.
/// building on Linux) these should end up just being stripped, as they are static functions that /// building on Linux) these should end up just being stripped, as they are static functions that
/// are not referenced in this file. /// are not referenced in this file.
// cppcheck-suppress unusedFunction // cppcheck-suppress unusedFunction
[[gnu::unused]] static wchar_t *wcsdup_fallback(const wchar_t *in) {
size_t len = std::wcslen(in);
auto out = static_cast<wchar_t *>(malloc(sizeof(wchar_t) * (len + 1)));
if (out == nullptr) {
return nullptr;
}
std::memcpy(out, in, sizeof(wchar_t) * (len + 1));
return out;
}
[[gnu::unused]] static int wcscasecmp_fallback(const wchar_t *a, const wchar_t *b) { [[gnu::unused]] static int wcscasecmp_fallback(const wchar_t *a, const wchar_t *b) {
if (*a == 0) { if (*a == 0) {
return *b == 0 ? 0 : -1; return *b == 0 ? 0 : -1;
@ -99,12 +88,6 @@ int fish_mkstemp_cloexec(char *name_template) {
return wcsncasecmp_fallback(a + 1, b + 1, count - 1); return wcsncasecmp_fallback(a + 1, b + 1, count - 1);
} }
#ifndef HAVE_WCSDUP
#ifndef HAVE_STD__WCSDUP
wchar_t *wcsdup(const wchar_t *in) { return wcsdup_fallback(in); }
#endif
#endif
#ifndef HAVE_WCSCASECMP #ifndef HAVE_WCSCASECMP
#ifndef HAVE_STD__WCSCASECMP #ifndef HAVE_STD__WCSCASECMP
int wcscasecmp(const wchar_t *a, const wchar_t *b) { return wcscasecmp_fallback(a, b); } int wcscasecmp(const wchar_t *a, const wchar_t *b) { return wcscasecmp_fallback(a, b); }

View File

@ -5,7 +5,7 @@
#include <stdint.h> #include <stdint.h>
// The following include must be kept despite what IWYU says. That's because of the interaction // The following include must be kept despite what IWYU says. That's because of the interaction
// between the weak linking of `wcsdup` and `wcscasecmp` via `#define`s below and the declarations // between the weak linking of `wcscasecmp` via `#define`s below and the declarations
// in <wchar.h>. At least on OS X if we don't do this we get compilation errors do to the macro // in <wchar.h>. At least on OS X if we don't do this we get compilation errors do to the macro
// substitution if wchar.h is included after this header. // substitution if wchar.h is included after this header.
#include <cwchar> // IWYU pragma: keep #include <cwchar> // IWYU pragma: keep
@ -75,14 +75,6 @@ char *tparm_solaris_kludge(char *str, long p1 = 0, long p2 = 0, long p3 = 0, lon
/// These functions are missing from Solaris 10, and only accessible from /// These functions are missing from Solaris 10, and only accessible from
/// Solaris 11 in the std:: namespace. /// Solaris 11 in the std:: namespace.
#ifndef HAVE_WCSDUP
#ifdef HAVE_STD__WCSDUP
using std::wcsdup;
#else
wchar_t *wcsdup(const wchar_t *in);
#endif // HAVE_STD__WCSDUP
#endif // HAVE_WCSDUP
#ifndef HAVE_WCSCASECMP #ifndef HAVE_WCSCASECMP
#ifdef HAVE_STD__WCSCASECMP #ifdef HAVE_STD__WCSCASECMP
using std::wcscasecmp; using std::wcscasecmp;