aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-07-10 15:37:16 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-07-10 15:37:16 -0700
commit176a3913aa0dc2b0a03c16ffea9a22069266f4ab (patch)
tree85d8e17f3685ce399095d6cca6c89ef45108e6c6
parent6f0b00f9831d96dce6ea940ab93696c61bb6f01e (diff)
Lets us configure and build on FreeBSD
-rw-r--r--configure.ac3
-rw-r--r--env_universal_common.cpp31
2 files changed, 31 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac
index 908fed38..99eb86c3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -104,8 +104,9 @@ fi
# This mostly helps OS X users, since fink usually installs out of
# tree and doesn't update CFLAGS.
#
+# It also helps FreeBSD which puts libiconv in /usr/local/lib
-for i in /usr/pkg /sw /opt /opt/local; do
+for i in /usr/pkg /sw /opt /opt/local /usr/local; do
AC_MSG_CHECKING([for $i/include include directory])
if test -d $i/include; then
diff --git a/env_universal_common.cpp b/env_universal_common.cpp
index d80a4d0d..80ab4a0f 100644
--- a/env_universal_common.cpp
+++ b/env_universal_common.cpp
@@ -167,6 +167,26 @@ static const char *iconv_wide_names_2[]=
}
;
+template<class T>
+class sloppy {};
+
+static size_t hack_iconv(iconv_t cd, const char * const* inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
+{
+ /* FreeBSD has this prototype: size_t iconv (iconv_t, const char **...)
+ OS X and Linux this one: size_t iconv (iconv_t, char **...)
+ AFAIK there's no single type that can be passed as both char ** and const char **.
+ Therefore, we let C++ figure it out, by providing a struct with an implicit conversion to both char** and const char **.
+ */
+ struct sloppy_char
+ {
+ const char * const * t;
+ operator char** () const { return (char **)t; }
+ operator const char** () const { return (const char**)t; }
+ } slop_inbuf = {inbuf};
+
+ return iconv( cd, slop_inbuf, inbytesleft, outbuf, outbytesleft );
+}
+
/**
Convert utf-8 string to wide string
*/
@@ -246,7 +266,12 @@ static wchar_t *utf2wcs( const char *in )
return 0;
}
- nconv = iconv( cd, (char **)&in, &in_len, &nout, &out_len );
+ /* FreeBSD has this prototype: size_t iconv (iconv_t, const char **...)
+ OS X and Linux this one: size_t iconv (iconv_t, char **...)
+ AFAIK there's no single type that can be passed as both char ** and const char **.
+ So we cast the function pointer instead (!)
+ */
+ nconv = hack_iconv( cd, &in, &in_len, &nout, &out_len );
if (nconv == (size_t) -1)
{
@@ -280,6 +305,8 @@ static wchar_t *utf2wcs( const char *in )
return out;
}
+
+
/**
Convert wide string to utf-8
*/
@@ -357,7 +384,7 @@ static char *wcs2utf( const wchar_t *in )
return 0;
}
- nconv = iconv( cd, &char_in, &in_len, &nout, &out_len );
+ nconv = hack_iconv( cd, &char_in, &in_len, &nout, &out_len );
if (nconv == (size_t) -1)