aboutsummaryrefslogtreecommitdiffhomepage
path: root/fallback.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-07-20 14:33:08 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-07-20 14:33:29 -0700
commit966bbd476ff209dea8b1ca8670b50dd48854317d (patch)
tree43648e60fab31d60c7105e03137ae4b0bc8a02d0 /fallback.cpp
parentcf9bfe9e66fd58d3421deb3946bc8464971cee0a (diff)
Use weak linking of wcsdup and wcscasecmp on OS X
Diffstat (limited to 'fallback.cpp')
-rw-r--r--fallback.cpp69
1 files changed, 50 insertions, 19 deletions
diff --git a/fallback.cpp b/fallback.cpp
index abfe5cee..50954ab0 100644
--- a/fallback.cpp
+++ b/fallback.cpp
@@ -803,8 +803,9 @@ wchar_t *wcstok(wchar_t *wcs, const wchar_t *delim, wchar_t **save_ptr)
#endif
-#ifndef HAVE_WCSDUP
-wchar_t *wcsdup( const wchar_t *in )
+/* Fallback implementations of wcsdup 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 are not referenced in this file.
+*/
+static wchar_t *wcsdup_fallback(const wchar_t *in)
{
size_t len=wcslen(in);
wchar_t *out = (wchar_t *)malloc( sizeof( wchar_t)*(len+1));
@@ -815,23 +816,9 @@ wchar_t *wcsdup( const wchar_t *in )
memcpy( out, in, sizeof( wchar_t)*(len+1));
return out;
-
}
-#endif
-#ifndef HAVE_WCSLEN
-size_t wcslen(const wchar_t *in)
-{
- const wchar_t *end=in;
- while( *end )
- end++;
- return end-in;
-}
-#endif
-
-
-#ifndef HAVE_WCSCASECMP
-int wcscasecmp( const wchar_t *a, const wchar_t *b )
+int wcscasecmp_fallback( const wchar_t *a, const wchar_t *b )
{
if( *a == 0 )
{
@@ -845,11 +832,55 @@ int wcscasecmp( const wchar_t *a, const wchar_t *b )
if( diff != 0 )
return diff;
else
- return wcscasecmp( a+1,b+1);
+ return wcscasecmp_fallback( a+1,b+1);
}
-#endif
+#if __APPLE__ && __DARWIN_C_LEVEL >= 200809L
+/* Note parens avoid the macro expansion */
+wchar_t *wcsdup_use_weak(const wchar_t *a)
+{
+ if (wcsdup != NULL)
+ return (wcsdup)(a);
+ return wcsdup_fallback(a);
+}
+
+int wcscasecmp_use_weak(const wchar_t *a, const wchar_t *b)
+{
+ if (wcscasecmp != NULL)
+ return (wcscasecmp)(a, b);
+ return wcscasecmp_fallback(a, b);
+}
+
+#else //__APPLE__
+
+ #ifndef HAVE_WCSDUP
+wchar_t *wcsdup( const wchar_t *in )
+{
+ return wcsdup_fallback(in);
+
+}
+ #endif
+
+
+ #ifndef HAVE_WCSCASECMP
+int wcscasecmp( const wchar_t *a, const wchar_t *b )
+{
+ return wcscasecmp_fallback(a, b);
+}
+ #endif
+#endif //__APPLE__
+
+#ifndef HAVE_WCSLEN
+size_t wcslen(const wchar_t *in)
+{
+ const wchar_t *end=in;
+ while( *end )
+ end++;
+ return end-in;
+}
+#endif
+
#ifndef HAVE_WCSNCASECMP
int wcsncasecmp( const wchar_t *a, const wchar_t *b, int count )
{