From 9c2bf0197b2ffe84a4424d72ce4fc48282b78c67 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Wed, 1 Jul 2009 13:16:29 +0200 Subject: [PATCH] Introduced own automacro LIBBURNIA_CHECK_ICONV to handle iconv() peculiarities --- acinclude.m4 | 41 +++++++++++++++++++++++++++++++++++++++++ configure.ac | 8 +++++--- libisofs/util.c | 11 ++++++++++- 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index 02577cb..2ab289e 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -24,3 +24,44 @@ AC_DEFUN([TARGET_SHIZZLE], AC_MSG_RESULT([$ARCH]) ]) + + +dnl LIBBURNIA_CHECK_ICONV is by Thomas Schmitt, libburnia project +dnl It is based on gestures from: +dnl iconv.m4 serial AM7 (gettext-0.18) +dnl Copyright (C) 2000-2002, 2007-2009 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. +dnl From Bruno Haible. +dnl +AC_DEFUN([LIBBURNIA_CHECK_ICONV], +[ + dnl Check whether it is allowed to link with -liconv + AC_MSG_CHECKING([for separate -liconv ]) + libburnia_liconv="no" + libburnia_save_LIBS="$LIBS" + LIBS="$LIBS -liconv" + AC_TRY_LINK([#include +#include ], + [iconv_t cd = iconv_open("",""); + iconv(cd,NULL,NULL,NULL,NULL); + iconv_close(cd);], + [libburnia_liconv="yes"], + [LIBS="$libburnia_save_LIBS"] + ) + AC_MSG_RESULT([$libburnia_liconv]) + + dnl Check for iconv(..., const char **inbuf, ...) + AC_MSG_CHECKING([for const qualifier with iconv() ]) + AC_TRY_COMPILE([ +#include +#include +size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft); +], [], [libburnia_iconv_const=""], [libburnia_iconv_const="const"] + ) + AC_DEFINE_UNQUOTED([ICONV_CONST], [$libburnia_iconv_const]) + test -z "$libburnia_iconv_const" && libburnia_iconv_const="no" + AC_MSG_RESULT([$libburnia_iconv_const]) +]) + diff --git a/configure.ac b/configure.ac index 213b1dd..a694b5f 100644 --- a/configure.ac +++ b/configure.ac @@ -91,9 +91,11 @@ dnl test ticket 151 ### LIBICONV= ### ifdef(AM_ICONV, AM_ICONV, AC_CHECK_LIB(iconv, iconv, , )) ### LIBS="$LIBS $LIBICONV" -AC_CHECK_LIB(iconv, iconv, , ) -dnl GNU iconv has no function iconv() but libiconv() and a macro iconv() -AC_CHECK_LIB(iconv, libiconv, , ) +## AC_CHECK_LIB(iconv, iconv, , ) +## dnl GNU iconv has no function iconv() but libiconv() and a macro iconv() +## AC_CHECK_LIB(iconv, libiconv, , ) +LIBBURNIA_CHECK_ICONV + AC_PROG_LIBTOOL AC_SUBST(LIBTOOL_DEPS) diff --git a/libisofs/util.c b/libisofs/util.c index ce2e97d..8381b71 100644 --- a/libisofs/util.c +++ b/libisofs/util.c @@ -75,6 +75,15 @@ size_t iso_iconv(struct iso_iconv_handle *handle, char **outbuf, size_t *outbytesleft, int flag) { size_t ret; +/* The build system might indicate iconv(,const char **inbuf,) by + defining ICONV_CONST const +*/ +#ifndef ICONV_CONST +#define ICONV_CONST +#endif + ICONV_CONST char **local_inbuf; + + local_inbuf = (ICONV_CONST char **) inbuf; if (!(handle->status & 1)) { if (iso_iconv_debug) @@ -101,7 +110,7 @@ null_buf:; return (size_t) -1; return (size_t) 0; } - ret = iconv(handle->descr, inbuf, inbytesleft, outbuf, outbytesleft); + ret = iconv(handle->descr, local_inbuf, inbytesleft, outbuf, outbytesleft); if (ret == (size_t) -1) { if (iso_iconv_debug) fprintf(stderr, "libisofs_DEBUG: iconv() failed: errno= %d %s\n",