Create wrapper functions for iconv() so that we can transparently use the

Sun Nov 12 18:34:32 2000  Owen Taylor  <otaylor@redhat.com>

	* gconvert.[ch]: Create wrapper functions for iconv()
	so that we can transparently use the native iconv,
	libiconv, or (in the future) a mini-iconv included
	with glib.

	* glib-config-2.0.in glib-2.0.pc.in: Include @ICONV_LIBS@

	* INSTALL: Added note about libiconv.

	* configure.in: Add checks for libiconv from pango. If
	EILSEQ is not defined in errno.h add define for it into
	glibconfig.h so g_iconv can use it. (Note, recompiling
	from a system without EILSEQ to a system with EILSEQ
	will break binary compatibility)
This commit is contained in:
Owen Taylor 2000-11-12 23:44:28 +00:00 committed by Owen Taylor
parent 8bda01029f
commit 292152dae2
19 changed files with 366 additions and 35 deletions

View File

@ -1,3 +1,20 @@
Sun Nov 12 18:34:32 2000 Owen Taylor <otaylor@redhat.com>
* gconvert.[ch]: Create wrapper functions for iconv()
so that we can transparently use the native iconv,
libiconv, or (in the future) a mini-iconv included
with glib.
* glib-config-2.0.in glib-2.0.pc.in: Include @ICONV_LIBS@
* INSTALL: Added note about libiconv.
* configure.in: Add checks for libiconv from pango. If
EILSEQ is not defined in errno.h add define for it into
glibconfig.h so g_iconv can use it. (Note, recompiling
from a system without EILSEQ to a system with EILSEQ
will break binary compatibility)
2000-11-12 Robert Brady <robert@suse.co.uk>
* gstrfuncs.c, gstrfuncs.h: Remove g_filename_{to,from}_utf8

View File

@ -1,3 +1,20 @@
Sun Nov 12 18:34:32 2000 Owen Taylor <otaylor@redhat.com>
* gconvert.[ch]: Create wrapper functions for iconv()
so that we can transparently use the native iconv,
libiconv, or (in the future) a mini-iconv included
with glib.
* glib-config-2.0.in glib-2.0.pc.in: Include @ICONV_LIBS@
* INSTALL: Added note about libiconv.
* configure.in: Add checks for libiconv from pango. If
EILSEQ is not defined in errno.h add define for it into
glibconfig.h so g_iconv can use it. (Note, recompiling
from a system without EILSEQ to a system with EILSEQ
will break binary compatibility)
2000-11-12 Robert Brady <robert@suse.co.uk>
* gstrfuncs.c, gstrfuncs.h: Remove g_filename_{to,from}_utf8

View File

@ -1,3 +1,20 @@
Sun Nov 12 18:34:32 2000 Owen Taylor <otaylor@redhat.com>
* gconvert.[ch]: Create wrapper functions for iconv()
so that we can transparently use the native iconv,
libiconv, or (in the future) a mini-iconv included
with glib.
* glib-config-2.0.in glib-2.0.pc.in: Include @ICONV_LIBS@
* INSTALL: Added note about libiconv.
* configure.in: Add checks for libiconv from pango. If
EILSEQ is not defined in errno.h add define for it into
glibconfig.h so g_iconv can use it. (Note, recompiling
from a system without EILSEQ to a system with EILSEQ
will break binary compatibility)
2000-11-12 Robert Brady <robert@suse.co.uk>
* gstrfuncs.c, gstrfuncs.h: Remove g_filename_{to,from}_utf8

View File

@ -1,3 +1,20 @@
Sun Nov 12 18:34:32 2000 Owen Taylor <otaylor@redhat.com>
* gconvert.[ch]: Create wrapper functions for iconv()
so that we can transparently use the native iconv,
libiconv, or (in the future) a mini-iconv included
with glib.
* glib-config-2.0.in glib-2.0.pc.in: Include @ICONV_LIBS@
* INSTALL: Added note about libiconv.
* configure.in: Add checks for libiconv from pango. If
EILSEQ is not defined in errno.h add define for it into
glibconfig.h so g_iconv can use it. (Note, recompiling
from a system without EILSEQ to a system with EILSEQ
will break binary compatibility)
2000-11-12 Robert Brady <robert@suse.co.uk>
* gstrfuncs.c, gstrfuncs.h: Remove g_filename_{to,from}_utf8

View File

@ -1,3 +1,20 @@
Sun Nov 12 18:34:32 2000 Owen Taylor <otaylor@redhat.com>
* gconvert.[ch]: Create wrapper functions for iconv()
so that we can transparently use the native iconv,
libiconv, or (in the future) a mini-iconv included
with glib.
* glib-config-2.0.in glib-2.0.pc.in: Include @ICONV_LIBS@
* INSTALL: Added note about libiconv.
* configure.in: Add checks for libiconv from pango. If
EILSEQ is not defined in errno.h add define for it into
glibconfig.h so g_iconv can use it. (Note, recompiling
from a system without EILSEQ to a system with EILSEQ
will break binary compatibility)
2000-11-12 Robert Brady <robert@suse.co.uk>
* gstrfuncs.c, gstrfuncs.h: Remove g_filename_{to,from}_utf8

View File

@ -1,3 +1,20 @@
Sun Nov 12 18:34:32 2000 Owen Taylor <otaylor@redhat.com>
* gconvert.[ch]: Create wrapper functions for iconv()
so that we can transparently use the native iconv,
libiconv, or (in the future) a mini-iconv included
with glib.
* glib-config-2.0.in glib-2.0.pc.in: Include @ICONV_LIBS@
* INSTALL: Added note about libiconv.
* configure.in: Add checks for libiconv from pango. If
EILSEQ is not defined in errno.h add define for it into
glibconfig.h so g_iconv can use it. (Note, recompiling
from a system without EILSEQ to a system with EILSEQ
will break binary compatibility)
2000-11-12 Robert Brady <robert@suse.co.uk>
* gstrfuncs.c, gstrfuncs.h: Remove g_filename_{to,from}_utf8

View File

@ -1,3 +1,20 @@
Sun Nov 12 18:34:32 2000 Owen Taylor <otaylor@redhat.com>
* gconvert.[ch]: Create wrapper functions for iconv()
so that we can transparently use the native iconv,
libiconv, or (in the future) a mini-iconv included
with glib.
* glib-config-2.0.in glib-2.0.pc.in: Include @ICONV_LIBS@
* INSTALL: Added note about libiconv.
* configure.in: Add checks for libiconv from pango. If
EILSEQ is not defined in errno.h add define for it into
glibconfig.h so g_iconv can use it. (Note, recompiling
from a system without EILSEQ to a system with EILSEQ
will break binary compatibility)
2000-11-12 Robert Brady <robert@suse.co.uk>
* gstrfuncs.c, gstrfuncs.h: Remove g_filename_{to,from}_utf8

View File

@ -1,3 +1,20 @@
Sun Nov 12 18:34:32 2000 Owen Taylor <otaylor@redhat.com>
* gconvert.[ch]: Create wrapper functions for iconv()
so that we can transparently use the native iconv,
libiconv, or (in the future) a mini-iconv included
with glib.
* glib-config-2.0.in glib-2.0.pc.in: Include @ICONV_LIBS@
* INSTALL: Added note about libiconv.
* configure.in: Add checks for libiconv from pango. If
EILSEQ is not defined in errno.h add define for it into
glibconfig.h so g_iconv can use it. (Note, recompiling
from a system without EILSEQ to a system with EILSEQ
will break binary compatibility)
2000-11-12 Robert Brady <robert@suse.co.uk>
* gstrfuncs.c, gstrfuncs.h: Remove g_filename_{to,from}_utf8

20
INSTALL
View File

@ -8,6 +8,26 @@ Simple install procedure
[ Become root if necessary ]
% make install # install GLIB
Requirements
============
In order to implement conversions between character sets,
GLib requires an implementation of the standard iconv() routine.
Most modern systems will have a suitable implementation, however
many older systems lack an iconv() implementation. On such systems,
you must install the libiconv library. This can be found at:
http://clisp.cons.org/~haible/packages-libiconv.html
If your system has an iconv implementation but you want to use
libiconv instead, you can pass the --with-libiconv option to
configure. This forces libiconv to be used.
Note that if you have libiconv installed in your default include
search path (for instance, in /usr/local/), but don't enable
it, you will get an error while compiling GTK+ because the
iconv.h that libiconv installs hides the system iconv.
The Nitty-Gritty
================

View File

@ -153,6 +153,8 @@ stamp-gc-h: config.status
CONFIG_FILES= CONFIG_HEADERS= CONFIG_OTHER=glibconfig.h ./config.status
echo timestamp > stamp-gc-h
libglib_1_3_la_LIBADD = @ICONV_LIBS@
libglib_1_3_la_LDFLAGS = \
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
-export-dynamic

View File

@ -42,3 +42,5 @@
If you're adding to this file, keep in mind:
The entries are in sort -df order: alphabetical, case insensitive,
ignoring punctuation (such as underscores). */
#undef USE_LIBICONV

View File

@ -1099,6 +1099,50 @@ GLIB_SYSDEFS(
glibconfig-sysdefs.h,
=)
dnl ***********************
dnl *** Tests for iconv ***
dnl ***********************
AC_ARG_WITH(libiconv, [ --with-libiconv Use the libiconv library ],,with_libiconv=maybe)
found_iconv=no
if test "x$with_libiconv" != "xyes" ; then
#
# Check in the C library
#
AC_CHECK_FUNC(iconv_open, with_libiconv=no; found_iconv=yes)
fi
if test "x$with_libiconv" != "xno" ; then
#
# Check for libiconv
#
AC_CHECK_LIB(iconv, libiconv_open, with_libiconv=yes; found_iconv=yes)
fi
if test "x$found_iconv" = "xno" ; then
AC_MSG_ERROR([*** No iconv() implementation found in C library or libiconv])
fi
if test "x$with_libiconv" = "xyes" ; then
ICONV_LIBS="-liconv"
AC_DEFINE(USE_LIBICONV)
fi
AC_SUBST(ICONV_LIBS)
dnl If the system doesn't define EILSEQ, we should define EILSEQ ourselves
dnl since we need it for g_iconv()
AC_MSG_CHECKING([for EILSEQ])
AC_TRY_COMPILE([
#include <errno.h>
],
[
int error = EILSEQ;
], have_eilseq=yes, have_eilseq=no);
AC_MSG_RESULT($have_eilseq)
dnl **************************
dnl *** Checks for gtk-doc ***
dnl **************************
@ -1298,6 +1342,20 @@ $glib_inline
#endif /* !__cplusplus */
_______EOF
echo >>$outfile
if test x$g_have_eilseq = xno; then
cat >>$outfile <<_______EOF
#ifndef EILSEQ
/* On some systems, like SunOS and NetBSD, EILSEQ is not defined.
* The correspondence between this and the corresponding definition
* in libiconv is essential.
*/
# define EILSEQ ENOENT
#endif
_______EOF
fi
echo >>$outfile
if test x$g_mutex_has_default = xyes; then
cat >>$outfile <<_______EOF
@ -1576,6 +1634,8 @@ x$ac_cv_c_bigendian)
;;
esac
g_have_eilseq=$have_eilseq
case x$have_threads in
xnone) g_enable_threads_def="#undef";;
*) g_enable_threads_def="#define";;

View File

@ -30,6 +30,7 @@
#endif
#include "glib.h"
#include "config.h"
#define _(s) (s)
@ -39,27 +40,64 @@ g_convert_error_quark()
static GQuark quark;
if (!quark)
quark = g_quark_from_static_string ("g_convert_error");
return quark;
}
static iconv_t
open_converter (const gchar *to_codeset,
const gchar *from_codeset,
GError **error)
#if defined(USE_LIBICONV) && !defined (_LIBICONV_H)
#error libiconv in use but included iconv.h not from libiconv
#endif
#if !defined(USE_LIBICONV) && defined (_LIBICONV_H)
#error libiconv not in use but included iconv.h is from libiconv
#endif
GIConv
g_iconv_open (const gchar *to_codeset,
const gchar *from_codeset)
{
iconv_t cd = iconv_open (to_codeset, from_codeset);
return (GIConv)cd;
}
size_t
g_iconv (GIConv converter,
gchar **inbuf,
size_t *inbytes_left,
gchar **outbuf,
size_t *outbytes_left)
{
iconv_t cd = (iconv_t)converter;
return iconv (cd, inbuf, inbytes_left, outbuf, outbytes_left);
}
gint
g_iconv_close (GIConv converter)
{
iconv_t cd = (iconv_t)converter;
return iconv_close (cd);
}
GIConv
open_converter (const gchar *to_codeset,
const gchar *from_codeset,
GError **error)
{
GIConv cd = g_iconv_open (to_codeset, from_codeset);
if (cd == (iconv_t) -1)
{
/* Something went wrong. */
if (errno == EINVAL)
g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_NO_CONVERSION,
_("Conversion from character set `%s' to `%s' is not supported"),
from_codeset, to_codeset);
g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_NO_CONVERSION,
_("Conversion from character set `%s' to `%s' is not suppo\rted"),
from_codeset, to_codeset);
else
g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_FAILED,
_("Could not open converter from `%s' to `%s': %s"),
from_codeset, to_codeset, strerror (errno));
_("Could not open converter from `%s' to `%s': %s"),
from_codeset, to_codeset, strerror (errno));
}
return cd;
@ -106,7 +144,7 @@ g_convert (const gchar *str,
size_t inbytes_remaining;
size_t outbytes_remaining;
size_t err;
iconv_t cd;
GIConv cd;
size_t outbuf_size;
gboolean have_error = FALSE;
@ -116,7 +154,7 @@ g_convert (const gchar *str,
cd = open_converter (to_codeset, from_codeset, error);
if (cd == (iconv_t) -1)
if (cd == (GIConv) -1)
{
if (bytes_read)
*bytes_read = 0;
@ -138,7 +176,7 @@ g_convert (const gchar *str,
again:
err = iconv (cd, &p, &inbytes_remaining, &outp, &outbytes_remaining);
err = g_iconv (cd, (char **)&p, &inbytes_remaining, &outp, &outbytes_remaining);
if (err == (size_t) -1)
{
@ -174,7 +212,7 @@ g_convert (const gchar *str,
*outp = '\0';
iconv_close (cd);
g_iconv_close (cd);
if (bytes_read)
*bytes_read = p - str;
@ -256,7 +294,7 @@ g_convert_with_fallback (const gchar *str,
size_t save_inbytes = 0;
size_t outbytes_remaining;
size_t err;
iconv_t cd;
GIConv cd;
size_t outbuf_size;
gboolean have_error = FALSE;
gboolean done = FALSE;
@ -290,7 +328,7 @@ g_convert_with_fallback (const gchar *str,
* to_codeset, and the string as UTF-8.
*/
cd = open_converter (to_codeset, "UTF-8", error);
if (cd == (iconv_t) -1)
if (cd == (GIConv) -1)
{
if (bytes_read)
*bytes_read = 0;
@ -322,7 +360,7 @@ g_convert_with_fallback (const gchar *str,
while (!done && !have_error)
{
size_t inbytes_tmp = inbytes_remaining;
err = iconv (cd, &p, &inbytes_tmp, &outp, &outbytes_remaining);
err = g_iconv (cd, (char **)&p, &inbytes_tmp, &outp, &outbytes_remaining);
inbytes_remaining = inbytes_tmp;
if (err == (size_t) -1)
@ -399,7 +437,7 @@ g_convert_with_fallback (const gchar *str,
*/
*outp = '\0';
iconv_close (cd);
g_iconv_close (cd);
if (bytes_written)
*bytes_written = outp - str; /* Doesn't include '\0' */
@ -678,3 +716,4 @@ g_filename_from_utf8 (const gchar *string, GError **error)
#endif
}

View File

@ -27,6 +27,7 @@
#ifndef __G_CONVERT_H__
#define __G_CONVERT_H__
#include <stddef.h> /* For size_t */
#include <gerror.h>
G_BEGIN_DECLS
@ -42,6 +43,20 @@ typedef enum
#define G_CONVERT_ERROR g_convert_error_quark()
GQuark g_convert_error_quark();
/* Thin wrappers around iconv
*/
typedef struct _GIConv *GIConv;
GIConv g_iconv_open (const gchar *to_codeset,
const gchar *from_codeset);
size_t g_iconv (GIConv converter,
gchar **inbuf,
size_t *inbytes_left,
gchar **outbuf,
size_t *outbytes_left);
gint g_iconv_close (GIConv converter);
gchar* g_convert (const gchar *str,
gint len,
const gchar *to_codeset,

View File

@ -6,5 +6,5 @@ includedir=@includedir@
Name: GLib
Description: C Utility Library
Version: @VERSION@
Libs: -L${libdir} -lglib-1.3
Libs: -L${libdir} -lglib-1.3 @ICONV_LIBS@
Cflags: -I${includedir}/glib-2.0 -I${libdir}/glib-2.0/include

View File

@ -100,6 +100,7 @@ if test "$echo_libs" = "yes"; then
libsa=""
if test "$lib_glib" = "yes"; then
libsp="$libsp -lglib-1.3"
libsa="$libsa @ICONV_LIBS@"
fi
if test "$lib_gobject" = "yes"; then
libsp="-lgobject-1.3 $libsp"

View File

@ -153,6 +153,8 @@ stamp-gc-h: config.status
CONFIG_FILES= CONFIG_HEADERS= CONFIG_OTHER=glibconfig.h ./config.status
echo timestamp > stamp-gc-h
libglib_1_3_la_LIBADD = @ICONV_LIBS@
libglib_1_3_la_LDFLAGS = \
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
-export-dynamic

View File

@ -30,6 +30,7 @@
#endif
#include "glib.h"
#include "config.h"
#define _(s) (s)
@ -39,27 +40,64 @@ g_convert_error_quark()
static GQuark quark;
if (!quark)
quark = g_quark_from_static_string ("g_convert_error");
return quark;
}
static iconv_t
open_converter (const gchar *to_codeset,
const gchar *from_codeset,
GError **error)
#if defined(USE_LIBICONV) && !defined (_LIBICONV_H)
#error libiconv in use but included iconv.h not from libiconv
#endif
#if !defined(USE_LIBICONV) && defined (_LIBICONV_H)
#error libiconv not in use but included iconv.h is from libiconv
#endif
GIConv
g_iconv_open (const gchar *to_codeset,
const gchar *from_codeset)
{
iconv_t cd = iconv_open (to_codeset, from_codeset);
return (GIConv)cd;
}
size_t
g_iconv (GIConv converter,
gchar **inbuf,
size_t *inbytes_left,
gchar **outbuf,
size_t *outbytes_left)
{
iconv_t cd = (iconv_t)converter;
return iconv (cd, inbuf, inbytes_left, outbuf, outbytes_left);
}
gint
g_iconv_close (GIConv converter)
{
iconv_t cd = (iconv_t)converter;
return iconv_close (cd);
}
GIConv
open_converter (const gchar *to_codeset,
const gchar *from_codeset,
GError **error)
{
GIConv cd = g_iconv_open (to_codeset, from_codeset);
if (cd == (iconv_t) -1)
{
/* Something went wrong. */
if (errno == EINVAL)
g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_NO_CONVERSION,
_("Conversion from character set `%s' to `%s' is not supported"),
from_codeset, to_codeset);
g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_NO_CONVERSION,
_("Conversion from character set `%s' to `%s' is not suppo\rted"),
from_codeset, to_codeset);
else
g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_FAILED,
_("Could not open converter from `%s' to `%s': %s"),
from_codeset, to_codeset, strerror (errno));
_("Could not open converter from `%s' to `%s': %s"),
from_codeset, to_codeset, strerror (errno));
}
return cd;
@ -106,7 +144,7 @@ g_convert (const gchar *str,
size_t inbytes_remaining;
size_t outbytes_remaining;
size_t err;
iconv_t cd;
GIConv cd;
size_t outbuf_size;
gboolean have_error = FALSE;
@ -116,7 +154,7 @@ g_convert (const gchar *str,
cd = open_converter (to_codeset, from_codeset, error);
if (cd == (iconv_t) -1)
if (cd == (GIConv) -1)
{
if (bytes_read)
*bytes_read = 0;
@ -138,7 +176,7 @@ g_convert (const gchar *str,
again:
err = iconv (cd, &p, &inbytes_remaining, &outp, &outbytes_remaining);
err = g_iconv (cd, (char **)&p, &inbytes_remaining, &outp, &outbytes_remaining);
if (err == (size_t) -1)
{
@ -174,7 +212,7 @@ g_convert (const gchar *str,
*outp = '\0';
iconv_close (cd);
g_iconv_close (cd);
if (bytes_read)
*bytes_read = p - str;
@ -256,7 +294,7 @@ g_convert_with_fallback (const gchar *str,
size_t save_inbytes = 0;
size_t outbytes_remaining;
size_t err;
iconv_t cd;
GIConv cd;
size_t outbuf_size;
gboolean have_error = FALSE;
gboolean done = FALSE;
@ -290,7 +328,7 @@ g_convert_with_fallback (const gchar *str,
* to_codeset, and the string as UTF-8.
*/
cd = open_converter (to_codeset, "UTF-8", error);
if (cd == (iconv_t) -1)
if (cd == (GIConv) -1)
{
if (bytes_read)
*bytes_read = 0;
@ -322,7 +360,7 @@ g_convert_with_fallback (const gchar *str,
while (!done && !have_error)
{
size_t inbytes_tmp = inbytes_remaining;
err = iconv (cd, &p, &inbytes_tmp, &outp, &outbytes_remaining);
err = g_iconv (cd, (char **)&p, &inbytes_tmp, &outp, &outbytes_remaining);
inbytes_remaining = inbytes_tmp;
if (err == (size_t) -1)
@ -399,7 +437,7 @@ g_convert_with_fallback (const gchar *str,
*/
*outp = '\0';
iconv_close (cd);
g_iconv_close (cd);
if (bytes_written)
*bytes_written = outp - str; /* Doesn't include '\0' */
@ -678,3 +716,4 @@ g_filename_from_utf8 (const gchar *string, GError **error)
#endif
}

View File

@ -27,6 +27,7 @@
#ifndef __G_CONVERT_H__
#define __G_CONVERT_H__
#include <stddef.h> /* For size_t */
#include <gerror.h>
G_BEGIN_DECLS
@ -42,6 +43,20 @@ typedef enum
#define G_CONVERT_ERROR g_convert_error_quark()
GQuark g_convert_error_quark();
/* Thin wrappers around iconv
*/
typedef struct _GIConv *GIConv;
GIConv g_iconv_open (const gchar *to_codeset,
const gchar *from_codeset);
size_t g_iconv (GIConv converter,
gchar **inbuf,
size_t *inbytes_left,
gchar **outbuf,
size_t *outbytes_left);
gint g_iconv_close (GIConv converter);
gchar* g_convert (const gchar *str,
gint len,
const gchar *to_codeset,