mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-04 10:16:17 +01:00
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:
parent
8bda01029f
commit
292152dae2
17
ChangeLog
17
ChangeLog
@ -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>
|
2000-11-12 Robert Brady <robert@suse.co.uk>
|
||||||
|
|
||||||
* gstrfuncs.c, gstrfuncs.h: Remove g_filename_{to,from}_utf8
|
* gstrfuncs.c, gstrfuncs.h: Remove g_filename_{to,from}_utf8
|
||||||
|
@ -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>
|
2000-11-12 Robert Brady <robert@suse.co.uk>
|
||||||
|
|
||||||
* gstrfuncs.c, gstrfuncs.h: Remove g_filename_{to,from}_utf8
|
* gstrfuncs.c, gstrfuncs.h: Remove g_filename_{to,from}_utf8
|
||||||
|
@ -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>
|
2000-11-12 Robert Brady <robert@suse.co.uk>
|
||||||
|
|
||||||
* gstrfuncs.c, gstrfuncs.h: Remove g_filename_{to,from}_utf8
|
* gstrfuncs.c, gstrfuncs.h: Remove g_filename_{to,from}_utf8
|
||||||
|
@ -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>
|
2000-11-12 Robert Brady <robert@suse.co.uk>
|
||||||
|
|
||||||
* gstrfuncs.c, gstrfuncs.h: Remove g_filename_{to,from}_utf8
|
* gstrfuncs.c, gstrfuncs.h: Remove g_filename_{to,from}_utf8
|
||||||
|
@ -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>
|
2000-11-12 Robert Brady <robert@suse.co.uk>
|
||||||
|
|
||||||
* gstrfuncs.c, gstrfuncs.h: Remove g_filename_{to,from}_utf8
|
* gstrfuncs.c, gstrfuncs.h: Remove g_filename_{to,from}_utf8
|
||||||
|
@ -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>
|
2000-11-12 Robert Brady <robert@suse.co.uk>
|
||||||
|
|
||||||
* gstrfuncs.c, gstrfuncs.h: Remove g_filename_{to,from}_utf8
|
* gstrfuncs.c, gstrfuncs.h: Remove g_filename_{to,from}_utf8
|
||||||
|
@ -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>
|
2000-11-12 Robert Brady <robert@suse.co.uk>
|
||||||
|
|
||||||
* gstrfuncs.c, gstrfuncs.h: Remove g_filename_{to,from}_utf8
|
* gstrfuncs.c, gstrfuncs.h: Remove g_filename_{to,from}_utf8
|
||||||
|
@ -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>
|
2000-11-12 Robert Brady <robert@suse.co.uk>
|
||||||
|
|
||||||
* gstrfuncs.c, gstrfuncs.h: Remove g_filename_{to,from}_utf8
|
* gstrfuncs.c, gstrfuncs.h: Remove g_filename_{to,from}_utf8
|
||||||
|
20
INSTALL
20
INSTALL
@ -8,6 +8,26 @@ Simple install procedure
|
|||||||
[ Become root if necessary ]
|
[ Become root if necessary ]
|
||||||
% make install # install GLIB
|
% 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
|
The Nitty-Gritty
|
||||||
================
|
================
|
||||||
|
|
||||||
|
@ -153,6 +153,8 @@ stamp-gc-h: config.status
|
|||||||
CONFIG_FILES= CONFIG_HEADERS= CONFIG_OTHER=glibconfig.h ./config.status
|
CONFIG_FILES= CONFIG_HEADERS= CONFIG_OTHER=glibconfig.h ./config.status
|
||||||
echo timestamp > stamp-gc-h
|
echo timestamp > stamp-gc-h
|
||||||
|
|
||||||
|
libglib_1_3_la_LIBADD = @ICONV_LIBS@
|
||||||
|
|
||||||
libglib_1_3_la_LDFLAGS = \
|
libglib_1_3_la_LDFLAGS = \
|
||||||
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
|
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
|
||||||
-export-dynamic
|
-export-dynamic
|
||||||
|
@ -42,3 +42,5 @@
|
|||||||
If you're adding to this file, keep in mind:
|
If you're adding to this file, keep in mind:
|
||||||
The entries are in sort -df order: alphabetical, case insensitive,
|
The entries are in sort -df order: alphabetical, case insensitive,
|
||||||
ignoring punctuation (such as underscores). */
|
ignoring punctuation (such as underscores). */
|
||||||
|
|
||||||
|
#undef USE_LIBICONV
|
||||||
|
60
configure.in
60
configure.in
@ -1099,6 +1099,50 @@ GLIB_SYSDEFS(
|
|||||||
glibconfig-sysdefs.h,
|
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 **************************
|
||||||
dnl *** Checks for gtk-doc ***
|
dnl *** Checks for gtk-doc ***
|
||||||
dnl **************************
|
dnl **************************
|
||||||
@ -1298,6 +1342,20 @@ $glib_inline
|
|||||||
#endif /* !__cplusplus */
|
#endif /* !__cplusplus */
|
||||||
_______EOF
|
_______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
|
echo >>$outfile
|
||||||
if test x$g_mutex_has_default = xyes; then
|
if test x$g_mutex_has_default = xyes; then
|
||||||
cat >>$outfile <<_______EOF
|
cat >>$outfile <<_______EOF
|
||||||
@ -1576,6 +1634,8 @@ x$ac_cv_c_bigendian)
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
g_have_eilseq=$have_eilseq
|
||||||
|
|
||||||
case x$have_threads in
|
case x$have_threads in
|
||||||
xnone) g_enable_threads_def="#undef";;
|
xnone) g_enable_threads_def="#undef";;
|
||||||
*) g_enable_threads_def="#define";;
|
*) g_enable_threads_def="#define";;
|
||||||
|
61
gconvert.c
61
gconvert.c
@ -30,6 +30,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "glib.h"
|
#include "glib.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#define _(s) (s)
|
#define _(s) (s)
|
||||||
|
|
||||||
@ -39,22 +40,59 @@ g_convert_error_quark()
|
|||||||
static GQuark quark;
|
static GQuark quark;
|
||||||
if (!quark)
|
if (!quark)
|
||||||
quark = g_quark_from_static_string ("g_convert_error");
|
quark = g_quark_from_static_string ("g_convert_error");
|
||||||
|
|
||||||
return quark;
|
return quark;
|
||||||
}
|
}
|
||||||
|
|
||||||
static iconv_t
|
#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,
|
open_converter (const gchar *to_codeset,
|
||||||
const gchar *from_codeset,
|
const gchar *from_codeset,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
iconv_t cd = iconv_open (to_codeset, from_codeset);
|
GIConv cd = g_iconv_open (to_codeset, from_codeset);
|
||||||
|
|
||||||
if (cd == (iconv_t) -1)
|
if (cd == (iconv_t) -1)
|
||||||
{
|
{
|
||||||
/* Something went wrong. */
|
/* Something went wrong. */
|
||||||
if (errno == EINVAL)
|
if (errno == EINVAL)
|
||||||
g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_NO_CONVERSION,
|
g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_NO_CONVERSION,
|
||||||
_("Conversion from character set `%s' to `%s' is not supported"),
|
_("Conversion from character set `%s' to `%s' is not suppo\rted"),
|
||||||
from_codeset, to_codeset);
|
from_codeset, to_codeset);
|
||||||
else
|
else
|
||||||
g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_FAILED,
|
g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_FAILED,
|
||||||
@ -106,7 +144,7 @@ g_convert (const gchar *str,
|
|||||||
size_t inbytes_remaining;
|
size_t inbytes_remaining;
|
||||||
size_t outbytes_remaining;
|
size_t outbytes_remaining;
|
||||||
size_t err;
|
size_t err;
|
||||||
iconv_t cd;
|
GIConv cd;
|
||||||
size_t outbuf_size;
|
size_t outbuf_size;
|
||||||
gboolean have_error = FALSE;
|
gboolean have_error = FALSE;
|
||||||
|
|
||||||
@ -116,7 +154,7 @@ g_convert (const gchar *str,
|
|||||||
|
|
||||||
cd = open_converter (to_codeset, from_codeset, error);
|
cd = open_converter (to_codeset, from_codeset, error);
|
||||||
|
|
||||||
if (cd == (iconv_t) -1)
|
if (cd == (GIConv) -1)
|
||||||
{
|
{
|
||||||
if (bytes_read)
|
if (bytes_read)
|
||||||
*bytes_read = 0;
|
*bytes_read = 0;
|
||||||
@ -138,7 +176,7 @@ g_convert (const gchar *str,
|
|||||||
|
|
||||||
again:
|
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)
|
if (err == (size_t) -1)
|
||||||
{
|
{
|
||||||
@ -174,7 +212,7 @@ g_convert (const gchar *str,
|
|||||||
|
|
||||||
*outp = '\0';
|
*outp = '\0';
|
||||||
|
|
||||||
iconv_close (cd);
|
g_iconv_close (cd);
|
||||||
|
|
||||||
if (bytes_read)
|
if (bytes_read)
|
||||||
*bytes_read = p - str;
|
*bytes_read = p - str;
|
||||||
@ -256,7 +294,7 @@ g_convert_with_fallback (const gchar *str,
|
|||||||
size_t save_inbytes = 0;
|
size_t save_inbytes = 0;
|
||||||
size_t outbytes_remaining;
|
size_t outbytes_remaining;
|
||||||
size_t err;
|
size_t err;
|
||||||
iconv_t cd;
|
GIConv cd;
|
||||||
size_t outbuf_size;
|
size_t outbuf_size;
|
||||||
gboolean have_error = FALSE;
|
gboolean have_error = FALSE;
|
||||||
gboolean done = FALSE;
|
gboolean done = FALSE;
|
||||||
@ -290,7 +328,7 @@ g_convert_with_fallback (const gchar *str,
|
|||||||
* to_codeset, and the string as UTF-8.
|
* to_codeset, and the string as UTF-8.
|
||||||
*/
|
*/
|
||||||
cd = open_converter (to_codeset, "UTF-8", error);
|
cd = open_converter (to_codeset, "UTF-8", error);
|
||||||
if (cd == (iconv_t) -1)
|
if (cd == (GIConv) -1)
|
||||||
{
|
{
|
||||||
if (bytes_read)
|
if (bytes_read)
|
||||||
*bytes_read = 0;
|
*bytes_read = 0;
|
||||||
@ -322,7 +360,7 @@ g_convert_with_fallback (const gchar *str,
|
|||||||
while (!done && !have_error)
|
while (!done && !have_error)
|
||||||
{
|
{
|
||||||
size_t inbytes_tmp = inbytes_remaining;
|
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;
|
inbytes_remaining = inbytes_tmp;
|
||||||
|
|
||||||
if (err == (size_t) -1)
|
if (err == (size_t) -1)
|
||||||
@ -399,7 +437,7 @@ g_convert_with_fallback (const gchar *str,
|
|||||||
*/
|
*/
|
||||||
*outp = '\0';
|
*outp = '\0';
|
||||||
|
|
||||||
iconv_close (cd);
|
g_iconv_close (cd);
|
||||||
|
|
||||||
if (bytes_written)
|
if (bytes_written)
|
||||||
*bytes_written = outp - str; /* Doesn't include '\0' */
|
*bytes_written = outp - str; /* Doesn't include '\0' */
|
||||||
@ -678,3 +716,4 @@ g_filename_from_utf8 (const gchar *string, GError **error)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
15
gconvert.h
15
gconvert.h
@ -27,6 +27,7 @@
|
|||||||
#ifndef __G_CONVERT_H__
|
#ifndef __G_CONVERT_H__
|
||||||
#define __G_CONVERT_H__
|
#define __G_CONVERT_H__
|
||||||
|
|
||||||
|
#include <stddef.h> /* For size_t */
|
||||||
#include <gerror.h>
|
#include <gerror.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
@ -42,6 +43,20 @@ typedef enum
|
|||||||
#define G_CONVERT_ERROR g_convert_error_quark()
|
#define G_CONVERT_ERROR g_convert_error_quark()
|
||||||
GQuark 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,
|
gchar* g_convert (const gchar *str,
|
||||||
gint len,
|
gint len,
|
||||||
const gchar *to_codeset,
|
const gchar *to_codeset,
|
||||||
|
@ -6,5 +6,5 @@ includedir=@includedir@
|
|||||||
Name: GLib
|
Name: GLib
|
||||||
Description: C Utility Library
|
Description: C Utility Library
|
||||||
Version: @VERSION@
|
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
|
Cflags: -I${includedir}/glib-2.0 -I${libdir}/glib-2.0/include
|
||||||
|
@ -100,6 +100,7 @@ if test "$echo_libs" = "yes"; then
|
|||||||
libsa=""
|
libsa=""
|
||||||
if test "$lib_glib" = "yes"; then
|
if test "$lib_glib" = "yes"; then
|
||||||
libsp="$libsp -lglib-1.3"
|
libsp="$libsp -lglib-1.3"
|
||||||
|
libsa="$libsa @ICONV_LIBS@"
|
||||||
fi
|
fi
|
||||||
if test "$lib_gobject" = "yes"; then
|
if test "$lib_gobject" = "yes"; then
|
||||||
libsp="-lgobject-1.3 $libsp"
|
libsp="-lgobject-1.3 $libsp"
|
||||||
|
@ -153,6 +153,8 @@ stamp-gc-h: config.status
|
|||||||
CONFIG_FILES= CONFIG_HEADERS= CONFIG_OTHER=glibconfig.h ./config.status
|
CONFIG_FILES= CONFIG_HEADERS= CONFIG_OTHER=glibconfig.h ./config.status
|
||||||
echo timestamp > stamp-gc-h
|
echo timestamp > stamp-gc-h
|
||||||
|
|
||||||
|
libglib_1_3_la_LIBADD = @ICONV_LIBS@
|
||||||
|
|
||||||
libglib_1_3_la_LDFLAGS = \
|
libglib_1_3_la_LDFLAGS = \
|
||||||
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
|
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
|
||||||
-export-dynamic
|
-export-dynamic
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "glib.h"
|
#include "glib.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#define _(s) (s)
|
#define _(s) (s)
|
||||||
|
|
||||||
@ -39,22 +40,59 @@ g_convert_error_quark()
|
|||||||
static GQuark quark;
|
static GQuark quark;
|
||||||
if (!quark)
|
if (!quark)
|
||||||
quark = g_quark_from_static_string ("g_convert_error");
|
quark = g_quark_from_static_string ("g_convert_error");
|
||||||
|
|
||||||
return quark;
|
return quark;
|
||||||
}
|
}
|
||||||
|
|
||||||
static iconv_t
|
#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,
|
open_converter (const gchar *to_codeset,
|
||||||
const gchar *from_codeset,
|
const gchar *from_codeset,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
iconv_t cd = iconv_open (to_codeset, from_codeset);
|
GIConv cd = g_iconv_open (to_codeset, from_codeset);
|
||||||
|
|
||||||
if (cd == (iconv_t) -1)
|
if (cd == (iconv_t) -1)
|
||||||
{
|
{
|
||||||
/* Something went wrong. */
|
/* Something went wrong. */
|
||||||
if (errno == EINVAL)
|
if (errno == EINVAL)
|
||||||
g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_NO_CONVERSION,
|
g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_NO_CONVERSION,
|
||||||
_("Conversion from character set `%s' to `%s' is not supported"),
|
_("Conversion from character set `%s' to `%s' is not suppo\rted"),
|
||||||
from_codeset, to_codeset);
|
from_codeset, to_codeset);
|
||||||
else
|
else
|
||||||
g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_FAILED,
|
g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_FAILED,
|
||||||
@ -106,7 +144,7 @@ g_convert (const gchar *str,
|
|||||||
size_t inbytes_remaining;
|
size_t inbytes_remaining;
|
||||||
size_t outbytes_remaining;
|
size_t outbytes_remaining;
|
||||||
size_t err;
|
size_t err;
|
||||||
iconv_t cd;
|
GIConv cd;
|
||||||
size_t outbuf_size;
|
size_t outbuf_size;
|
||||||
gboolean have_error = FALSE;
|
gboolean have_error = FALSE;
|
||||||
|
|
||||||
@ -116,7 +154,7 @@ g_convert (const gchar *str,
|
|||||||
|
|
||||||
cd = open_converter (to_codeset, from_codeset, error);
|
cd = open_converter (to_codeset, from_codeset, error);
|
||||||
|
|
||||||
if (cd == (iconv_t) -1)
|
if (cd == (GIConv) -1)
|
||||||
{
|
{
|
||||||
if (bytes_read)
|
if (bytes_read)
|
||||||
*bytes_read = 0;
|
*bytes_read = 0;
|
||||||
@ -138,7 +176,7 @@ g_convert (const gchar *str,
|
|||||||
|
|
||||||
again:
|
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)
|
if (err == (size_t) -1)
|
||||||
{
|
{
|
||||||
@ -174,7 +212,7 @@ g_convert (const gchar *str,
|
|||||||
|
|
||||||
*outp = '\0';
|
*outp = '\0';
|
||||||
|
|
||||||
iconv_close (cd);
|
g_iconv_close (cd);
|
||||||
|
|
||||||
if (bytes_read)
|
if (bytes_read)
|
||||||
*bytes_read = p - str;
|
*bytes_read = p - str;
|
||||||
@ -256,7 +294,7 @@ g_convert_with_fallback (const gchar *str,
|
|||||||
size_t save_inbytes = 0;
|
size_t save_inbytes = 0;
|
||||||
size_t outbytes_remaining;
|
size_t outbytes_remaining;
|
||||||
size_t err;
|
size_t err;
|
||||||
iconv_t cd;
|
GIConv cd;
|
||||||
size_t outbuf_size;
|
size_t outbuf_size;
|
||||||
gboolean have_error = FALSE;
|
gboolean have_error = FALSE;
|
||||||
gboolean done = FALSE;
|
gboolean done = FALSE;
|
||||||
@ -290,7 +328,7 @@ g_convert_with_fallback (const gchar *str,
|
|||||||
* to_codeset, and the string as UTF-8.
|
* to_codeset, and the string as UTF-8.
|
||||||
*/
|
*/
|
||||||
cd = open_converter (to_codeset, "UTF-8", error);
|
cd = open_converter (to_codeset, "UTF-8", error);
|
||||||
if (cd == (iconv_t) -1)
|
if (cd == (GIConv) -1)
|
||||||
{
|
{
|
||||||
if (bytes_read)
|
if (bytes_read)
|
||||||
*bytes_read = 0;
|
*bytes_read = 0;
|
||||||
@ -322,7 +360,7 @@ g_convert_with_fallback (const gchar *str,
|
|||||||
while (!done && !have_error)
|
while (!done && !have_error)
|
||||||
{
|
{
|
||||||
size_t inbytes_tmp = inbytes_remaining;
|
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;
|
inbytes_remaining = inbytes_tmp;
|
||||||
|
|
||||||
if (err == (size_t) -1)
|
if (err == (size_t) -1)
|
||||||
@ -399,7 +437,7 @@ g_convert_with_fallback (const gchar *str,
|
|||||||
*/
|
*/
|
||||||
*outp = '\0';
|
*outp = '\0';
|
||||||
|
|
||||||
iconv_close (cd);
|
g_iconv_close (cd);
|
||||||
|
|
||||||
if (bytes_written)
|
if (bytes_written)
|
||||||
*bytes_written = outp - str; /* Doesn't include '\0' */
|
*bytes_written = outp - str; /* Doesn't include '\0' */
|
||||||
@ -678,3 +716,4 @@ g_filename_from_utf8 (const gchar *string, GError **error)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#ifndef __G_CONVERT_H__
|
#ifndef __G_CONVERT_H__
|
||||||
#define __G_CONVERT_H__
|
#define __G_CONVERT_H__
|
||||||
|
|
||||||
|
#include <stddef.h> /* For size_t */
|
||||||
#include <gerror.h>
|
#include <gerror.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
@ -42,6 +43,20 @@ typedef enum
|
|||||||
#define G_CONVERT_ERROR g_convert_error_quark()
|
#define G_CONVERT_ERROR g_convert_error_quark()
|
||||||
GQuark 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,
|
gchar* g_convert (const gchar *str,
|
||||||
gint len,
|
gint len,
|
||||||
const gchar *to_codeset,
|
const gchar *to_codeset,
|
||||||
|
Loading…
Reference in New Issue
Block a user