Skip to content

Commit

Permalink
Apparently there are two different function signatures for the iconv …
Browse files Browse the repository at this point in the history
…function. Account for that.
  • Loading branch information
paulbaumgart committed Feb 5, 2011
1 parent d8f9431 commit 5cf686b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
18 changes: 9 additions & 9 deletions configure
@@ -1,12 +1,12 @@
echo "#include <JavaScriptCore/JavaScript.h>" > .check_JavaScript_h.h if echo "#include <JavaScriptCore/JavaScript.h>" | cpp &> /dev/null; then
if gcc -E .check_JavaScript_h.h -framework JavaScriptCore &>/dev/null; then echo "#define HAVE_JAVASCRIPT_H" > include/config.h
echo '#define HAVE_JAVASCRIPT_H 1' > include/config.h
echo 'Detected <JavaScriptCore/JavaScript.h>'
else else
echo '#ifdef HAVE_JAVASCRIPT_H' > include/config.h echo "#undef HAVE_JAVASCRIPT_H" > include/config.h
echo '#undef HAVE_JAVASCRIPT_H' >> include/config.h
echo '#endif' >> include/config.h
echo 'No <JavaScriptCore/JavaScript.h> detected. Using <JavaScriptCore/JavaScriptCore.h> instead.'
fi fi
rm -f .check_JavaScript_h.h


if echo "#include <iconv.h>" | cpp | egrep -C2 "size_t[\w]+iconv" |\
tr -d "\n" | egrep "const[\w]+char" &> /dev/null; then
echo "#define ICONV_REQUIRES_CONST_POINTER" > include/config.h
else
echo "#undef ICONV_REQUIRES_CONST_POINTER" > include/config.h
fi
9 changes: 8 additions & 1 deletion src/binary-engine.cc
Expand Up @@ -185,13 +185,20 @@ int transcode(char *src, size_t srcLength, char **dstOut, size_t *dstLengthOut,
} }


char *src_buf = src, *dst_buf = dst; char *src_buf = src, *dst_buf = dst;

#ifdef ICONV_REQUIRES_CONST_POINTER
const char **src_buf_ptr = &src_buf;
#else
char **src_buf_ptr = &src_buf;
#endif

size_t src_bytes_left = (size_t)srcLength, dst_bytes_left = (size_t)dst_length, converted=0; size_t src_bytes_left = (size_t)srcLength, dst_bytes_left = (size_t)dst_length, converted=0;


while (dst_bytes_left > 0) while (dst_bytes_left > 0)
{ {
if (src_bytes_left == 0) if (src_bytes_left == 0)
break; break;
if ((converted = iconv(cd, &src_buf, &src_bytes_left, &dst_buf, &dst_bytes_left)) == (size_t)-1) if ((converted = iconv(cd, src_buf_ptr, &src_bytes_left, &dst_buf, &dst_bytes_left)) == (size_t)-1)
{ {
if (errno != EINVAL) if (errno != EINVAL)
{ {
Expand Down

0 comments on commit 5cf686b

Please sign in to comment.