#include "gconvert.h"
-#include "gprintfint.h"
+#include "gcharsetprivate.h"
#include "gslist.h"
#include "gstrfuncs.h"
#include "gtestutils.h"
#include "gthread.h"
-#include "gthreadprivate.h"
#include "gunicode.h"
+#include "gfileutils.h"
#ifdef NEED_ICONV_CACHE
#include "glist.h"
#if defined(USE_LIBICONV_GNU) && !defined (_LIBICONV_H)
#error GNU libiconv in use but included iconv.h not from libiconv
#endif
-#if !defined(USE_LIBICONV_GNU) && defined (_LIBICONV_H)
+#if !defined(USE_LIBICONV_GNU) && defined (_LIBICONV_H) \
+ && !defined (__APPLE_CC__) && !defined (__LP_64__)
#error GNU libiconv not in use but included iconv.h is from libiconv
#endif
/**
* SECTION:conversions
* @title: Character Set Conversion
- * @short_description: Convert strings between different character sets
+ * @short_description: convert strings between different character sets
*
* The g_convert() family of function wraps the functionality of iconv(). In
* addition to pure character set conversions, GLib has functions to deal
*/
#define NUL_TERMINATOR_LENGTH 4
-GQuark
-g_convert_error_quark (void)
-{
- return g_quark_from_static_string ("g_convert_error");
-}
+G_DEFINE_QUARK (g_convert_error, g_convert_error)
static gboolean
try_conversion (const char *to_codeset,
* input sequence.
* @bytes_written: the number of bytes stored in the output buffer (not
* including the terminating nul).
- * @error: location to store the error occuring, or %NULL to ignore
+ * @error: location to store the error occurring, or %NULL to ignore
* errors. Any of the errors in #GConvertError may occur.
*
* Converts a string from one character set to another.
}
break;
case EILSEQ:
- if (error)
- g_set_error_literal (error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
- _("Invalid byte sequence in conversion input"));
+ g_set_error_literal (error, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
+ _("Invalid byte sequence in conversion input"));
have_error = TRUE;
break;
default:
- if (error)
- {
- int errsv = errno;
-
- g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_FAILED,
- _("Error during conversion: %s"),
- g_strerror (errsv));
- }
+ {
+ int errsv = errno;
+
+ g_set_error (error, G_CONVERT_ERROR, G_CONVERT_ERROR_FAILED,
+ _("Error during conversion: %s"),
+ g_strerror (errsv));
+ }
have_error = TRUE;
break;
}
{
if (!have_error)
{
- if (error)
- g_set_error_literal (error, G_CONVERT_ERROR, G_CONVERT_ERROR_PARTIAL_INPUT,
- _("Partial character sequence at end of input"));
+ g_set_error_literal (error, G_CONVERT_ERROR, G_CONVERT_ERROR_PARTIAL_INPUT,
+ _("Partial character sequence at end of input"));
have_error = TRUE;
}
}
* input sequence.
* @bytes_written: (out): the number of bytes stored in the output buffer (not
* including the terminating nul).
- * @error: location to store the error occuring, or %NULL to ignore
+ * @error: location to store the error occurring, or %NULL to ignore
* errors. Any of the errors in #GConvertError may occur.
*
* Converts a string from one character set to another.
* at the end of the input.
* @bytes_written: the number of bytes stored in the output buffer (not
* including the terminating nul).
- * @error: location to store the error occuring, or %NULL to ignore
+ * @error: location to store the error occurring, or %NULL to ignore
* errors. Any of the errors in #GConvertError may occur.
*
* Converts a string from one character set to another, possibly
* input sequence.
* @bytes_written: the number of bytes stored in the output buffer (not
* including the terminating nul).
- * @error: location to store the error occuring, or %NULL to ignore
+ * @error: location to store the error occurring, or %NULL to ignore
* errors. Any of the errors in #GConvertError may occur.
*
* Converts a string which is in the encoding used for strings by
* input sequence.
* @bytes_written: the number of bytes stored in the output buffer (not
* including the terminating nul).
- * @error: location to store the error occuring, or %NULL to ignore
+ * @error: location to store the error occurring, or %NULL to ignore
* errors. Any of the errors in #GConvertError may occur.
*
* Converts a string from UTF-8 to the encoding used for strings by
gboolean
g_get_filename_charsets (const gchar ***filename_charsets)
{
- static GStaticPrivate cache_private = G_STATIC_PRIVATE_INIT;
- GFilenameCharsetCache *cache = g_static_private_get (&cache_private);
+ static GPrivate cache_private = G_PRIVATE_INIT (filename_charset_cache_free);
+ GFilenameCharsetCache *cache = g_private_get (&cache_private);
const gchar *charset;
if (!cache)
{
cache = g_new0 (GFilenameCharsetCache, 1);
- g_static_private_set (&cache_private, cache, filename_charset_cache_free);
+ g_private_set (&cache_private, cache);
}
g_get_charset (&charset);
return is_utf8;
}
-/* This is called from g_thread_init(). It's used to
- * initialize some static data in a threadsafe way.
- */
-void
-_g_convert_thread_init (void)
-{
- const gchar **dummy;
- (void) g_get_filename_charsets (&dummy);
-}
-
/**
* g_filename_to_utf8:
* @opsysstring: a string in the encoding for filenames
* input sequence.
* @bytes_written: the number of bytes stored in the output buffer (not
* including the terminating nul).
- * @error: location to store the error occuring, or %NULL to ignore
+ * @error: location to store the error occurring, or %NULL to ignore
* errors. Any of the errors in #GConvertError may occur.
*
* Converts a string which is in the encoding used by GLib for
{
const gchar *charset;
+ g_return_val_if_fail (opsysstring != NULL, NULL);
+
if (get_filename_charset (&charset))
return strdup_len (opsysstring, len, bytes_read, bytes_written, error);
else
{
const gchar *charset;
+ g_return_val_if_fail (opsysstring != NULL, NULL);
+
if (g_get_charset (&charset))
return strdup_len (opsysstring, len, bytes_read, bytes_written, error);
else
* input sequence.
* @bytes_written: the number of bytes stored in the output buffer (not
* including the terminating nul).
- * @error: location to store the error occuring, or %NULL to ignore
+ * @error: location to store the error occurring, or %NULL to ignore
* errors. Any of the errors in #GConvertError may occur.
*
* Converts a string from UTF-8 to the encoding GLib uses for
/**
* g_filename_from_uri:
* @uri: a uri describing a filename (escaped, encoded in ASCII).
- * @hostname: Location to store hostname for the URI, or %NULL.
+ * @hostname: (out) (allow-none): Location to store hostname for the URI, or %NULL.
* If there is no hostname in the URI, %NULL will be
* stored in this location.
- * @error: location to store the error occuring, or %NULL to ignore
+ * @error: location to store the error occurring, or %NULL to ignore
* errors. Any of the errors in #GConvertError may occur.
*
* Converts an escaped ASCII-encoded URI to a local filename in the
* encoding used for filenames.
*
- * Return value: a newly-allocated string holding the resulting
- * filename, or %NULL on an error.
+ * Return value: (type filename): a newly-allocated string holding
+ * the resulting filename, or %NULL on an error.
**/
gchar *
g_filename_from_uri (const gchar *uri,
* which is the on-disk file name bytes on Unix, and UTF-8 on
* Windows
* @hostname: (allow-none): A UTF-8 encoded hostname, or %NULL for none.
- * @error: location to store the error occuring, or %NULL to ignore
+ * @error: location to store the error occurring, or %NULL to ignore
* errors. Any of the errors in #GConvertError may occur.
*
* Converts an absolute filename to an escaped ASCII-encoded URI, with the path
* mime type defined in RFC 2483 into individual URIs,
* discarding any comments. The URIs are not validated.
*
- * Returns: a newly allocated %NULL-terminated list of
- * strings holding the individual URIs. The array should
- * be freed with g_strfreev().
+ * Returns: (transfer full): a newly allocated %NULL-terminated list
+ * of strings holding the individual URIs. The array should be freed
+ * with g_strfreev().
*
* Since: 2.6
*/