From 002757225a3e3e0ac2e3ffe479beb50eb8cef6ad Mon Sep 17 00:00:00 2001 From: David Adam Date: Mon, 6 Mar 2017 21:23:24 +0800 Subject: [PATCH] fallback: check for existence of std:: namespace functions Before defining fallback functions of wcsdup(), wcscasecmp() and wcsncasecmp(), use the std:: namespace functions instead if they exist. 0019c12af37 fixed the build on Solaris 10, but broke it on Solaris 11. --- src/common.h | 12 ------------ src/fallback.cpp | 10 +++++++++- src/fallback.h | 24 ++++++++++++++++++++---- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/common.h b/src/common.h index 17b8c7159..a464d6735 100644 --- a/src/common.h +++ b/src/common.h @@ -858,18 +858,6 @@ static const wchar_t *enum_to_str(T enum_val, const enum_map map[]) { return NULL; }; -#if !defined(HAVE_WCSDUP) && defined(HAVE_STD__WCSDUP) -using std::wcsdup; -#endif - -#if !defined(HAVE_WCSCASECMP) && defined(HAVE_STD__WCSCASECMP) -using std::wcscasecmp; -#endif - -#if !defined(HAVE_WCSNCASECMP) && defined(HAVE_STD__WCSNCASECMP) -using std::wcsncasecmp; -#endif - void redirect_tty_output(); // Minimum allowed terminal size and default size if the detected size is not reasonable. diff --git a/src/fallback.cpp b/src/fallback.cpp index 0d58db0be..c20563b01 100644 --- a/src/fallback.cpp +++ b/src/fallback.cpp @@ -171,14 +171,20 @@ int wcsncasecmp(const wchar_t *a, const wchar_t *b, size_t n) { #endif // __DARWIN_C_LEVEL >= 200809L #else // __APPLE__ -/// These functions are missing from Solaris 10 #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_STD__WCSCASECMP int wcscasecmp(const wchar_t *a, const wchar_t *b) { return wcscasecmp_fallback(a, b); } #endif +#endif + #ifndef HAVE_WCSNCASECMP +#ifndef HAVE_STD__WCSNCASECMP int wcsncasecmp(const wchar_t *a, const wchar_t *b, size_t n) { return wcsncasecmp_fallback(a, b, n); } @@ -196,6 +202,8 @@ wchar_t *wcsndup(const wchar_t *in, size_t c) { } #endif +#endif // __APPLE__ + #ifndef HAVE_WCSLCPY /*$OpenBSD: strlcpy.c,v 1.8 2003/06/17 21:56:24 millert Exp $*/ diff --git a/src/fallback.h b/src/fallback.h index e8ddfec03..1814b5e22 100644 --- a/src/fallback.h +++ b/src/fallback.h @@ -89,16 +89,32 @@ wchar_t *wcsndup(const wchar_t *in, size_t c); #endif #else //__APPLE__ -/// These functions are missing from Solaris 10 +/// These functions are missing from Solaris 10, and only accessible from +/// 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 +#endif // HAVE_STD__WCSDUP +#endif // HAVE_WCSDUP + #ifndef HAVE_WCSCASECMP +#ifdef HAVE_STD__WCSCASECMP +using std::wcscasecmp; +#else int wcscasecmp(const wchar_t *a, const wchar_t *b); -#endif +#endif // HAVE_STD__WCSCASECMP +#endif // HAVE_WCSCASECMP + #ifndef HAVE_WCSNCASECMP +#ifdef HAVE_STD__WCSNCASECMP +using std::wcsncasecmp; +#else int wcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n); -#endif +#endif // HAVE_STD__WCSNCASECMP +#endif // HAVE_WCSNCASECMP + #ifndef HAVE_DIRFD #ifndef __XOPEN_OR_POSIX #define dirfd(d) (d->dd_fd)