#include "glib.h"
#include "config.h"
-#ifdef G_OS_WIN32
+#ifdef G_PLATFORM_WIN32
+#define STRICT
#include <windows.h>
+#undef STRICT
#endif
#include "glibintl.h"
#error libiconv not in use but included iconv.h is from libiconv
#endif
+/**
+ * g_iconv_open:
+ * @to_codeset: destination codeset
+ * @from_codeset: source codeset
+ *
+ * Same as the standard UNIX routine iconv_open(), but
+ * may be implemented via libiconv on UNIX flavors that lack
+ * a native implementation.
+ *
+ * GLib provides g_convert() and g_locale_to_utf8() which are likely
+ * more convenient than the raw iconv wrappers.
+ *
+ * Return value: a "conversion descriptor"
+ **/
GIConv
g_iconv_open (const gchar *to_codeset,
const gchar *from_codeset)
return (GIConv)cd;
}
+/**
+ * g_iconv:
+ * @converter: conversion descriptor from g_iconv_open()
+ * @inbuf: bytes to convert
+ * @inbytes_left: inout parameter, bytes remaining to convert in @inbuf
+ * @outbuf: converted output bytes
+ * @outbytes_left: inout parameter, bytes available to fill in @outbuf
+ *
+ * Same as the standard UNIX routine iconv(), but
+ * may be implemented via libiconv on UNIX flavors that lack
+ * a native implementation.
+ *
+ * GLib provides g_convert() and g_locale_to_utf8() which are likely
+ * more convenient than the raw iconv wrappers.
+ *
+ * Return value: count of non-reversible conversions, or -1 on error
+ **/
size_t
g_iconv (GIConv converter,
gchar **inbuf,
return iconv (cd, inbuf, inbytes_left, outbuf, outbytes_left);
}
+/**
+ * g_iconv_close:
+ * @converter: a conversion descriptor from g_iconv_open()
+ *
+ * Same as the standard UNIX routine iconv_close(), but
+ * may be implemented via libiconv on UNIX flavors that lack
+ * a native implementation. Should be called to clean up
+ * the conversion descriptor from iconv_open() when
+ * you are done converting things.
+ *
+ * GLib provides g_convert() and g_locale_to_utf8() which are likely
+ * more convenient than the raw iconv wrappers.
+ *
+ * Return value: -1 on error, 0 on success
+ **/
gint
g_iconv_close (GIConv converter)
{
{
if ((p - str) != len)
{
- g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_PARTIAL_INPUT,
- _("Partial character sequence at end of input"));
- have_error = TRUE;
+ if (!have_error)
+ {
+ g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_PARTIAL_INPUT,
+ _("Partial character sequence at end of input"));
+ have_error = TRUE;
+ }
}
}
else
g_error_free (local_error);
+ local_error = NULL;
+
/* No go; to proceed, we need a converter from "UTF-8" to
* to_codeset, and the string as UTF-8.
*/
gint *bytes_written,
GError **error)
{
-#ifdef G_OS_WIN32
+#ifdef G_PLATFORM_WIN32
gint i, clen, total_len, wclen, first;
wchar_t *wcs, wc;
return result;
-#else
+#else /* !G_PLATFORM_WIN32 */
char *charset, *str;
"UTF-8", charset, bytes_read, bytes_written, error);
return str;
-#endif
+#endif /* !G_PLATFORM_WIN32 */
}
/**
gint *bytes_written,
GError **error)
{
-#ifdef G_OS_WIN32
+#ifdef G_PLATFORM_WIN32
gint i, mask, clen, mblen;
wchar_t *wcs, *wcp;
return result;
-#else
+#else /* !G_PLATFORM_WIN32 */
gchar *charset, *str;
return str;
-#endif
+#endif /* !G_PLATFORM_WIN32 */
}
/**
gint *bytes_written,
GError **error)
{
-#ifdef G_OS_WIN32
+#ifdef G_PLATFORM_WIN32
return g_locale_to_utf8 (opsysstring, len,
bytes_read, bytes_written,
error);
-#else
+#else /* !G_PLATFORM_WIN32 */
if (getenv ("G_BROKEN_FILENAMES"))
return g_locale_to_utf8 (opsysstring, len,
bytes_read, bytes_written,
return g_strdup (opsysstring);
else
return g_strndup (opsysstring, len);
-#endif
+#endif /* !G_PLATFORM_WIN32 */
}
/**
gint *bytes_written,
GError **error)
{
-#ifdef G_OS_WIN32
+#ifdef G_PLATFORM_WIN32
return g_locale_from_utf8 (utf8string, len,
bytes_read, bytes_written,
error);
-#else
+#else /* !G_PLATFORM_WIN32 */
if (getenv ("G_BROKEN_FILENAMES"))
return g_locale_from_utf8 (utf8string, len,
bytes_read, bytes_written,
return g_strdup (utf8string);
else
return g_strndup (utf8string, len);
-#endif
+#endif /* !G_PLATFORM_WIN32 */
}
-
-