+Wed Jun 20 12:00:54 2001 Owen Taylor <otaylor@redhat.com>
+
+ Changes for 64-bit cleanliness, loosely based on patch
+ from Mark Murnane.
+
+ * gconvert.c (g_convert/g_convert_with_fallback): Remove
+ workarounds for since-fixed GNU libc bugs. Minor
+ doc fix.
+
+ * gconvert.[ch]: Change gint to gsize/gssize as
+ appropriate.
+
+ * gconvert.c (g_locale/filename_to/from_utf8): Fix incorrect
+ computation of bytes_read / bytes_written.
+
+ * gfileutils.[ch] (g_file_get_contents): Make length
+ out parameter 'gsize *len'.
+
+ * ghook.c (g_hook_compare_ids): Don't compare a
+ and b as 'a - b'.
+
+ * gmacros.h (GSIZE_TO_POINTER): Add GPOINTER_TO_SIZE,
+ GSIZE_TO_POINTER.
+
+ * gmain.c (g_timeout_prepare): Rewrite to avoid
+ overflows. (Fixes bug when system clock skews
+ backwards more than 24 days.)
+
+ * gmarkup.[ch]: Make lengths passed to callbacks
+ gsize, length for g_markup_parse-context_parse(),
+ g_markup_escape_text() gssize.
+
+ * gmessages.[ch] (g_printf_string_upper_bound): Change
+ return value to gsize.
+
+ * gmessages.c (printf_string_upper_bound): Remove
+ a ridiculous use of 'inline' on a 300 line function.
+
+ * gstring.[ch]: Represent size of string as a gsize,
+ not gint. Make parameters to functions take gsize,
+ or gssize where -1 is allowed.
+
+ * gstring.c (g_string_erase): Make
+ g_string_erase (string, pos, -1) a synonym for
+ g_string_truncate for consistency with other G*
+ APIs.
+
+ * gstrfuncs.[ch]: Make all functions taking a string
+ length, take a gsize, or gssize if -1 is allowed.
+ (g_strstr_len, g_strrstr_len). Also fix some boundary
+ conditions in g_str[r]str[_len].
+
+ * gutf8.c tests/unicode-encoding.c: Make parameters that
+ are byte lengths gsize, gssize as appropriate. Make
+ character offsets, other counts, glong.
+
+ * gasyncqueue.c gcompletion.c
+ timeloop.c timeloop-basic.c gutils.c gspawn.c.
+ Small 64 bit cleanliness fixups.
+
+ * glist.c (g_list_sort2, g_list_sort_real): Fix functions
+ that should have been static.
+
+ * gdate.c (g_date_fill_parse_tokens): Fix extra
+ declaration that was shadowing another.
+
+ * tests/module-test.c: Include string.h
+
+Mon Jun 18 15:43:29 2001 Owen Taylor <otaylor@redhat.com>
+
+ * gutf8.c (g_get_charset): Make argument
+ G_CONST_RETURN char **.
+
2001-06-22 Andrew Lanoix <alanoix@umich.edu>
*giowin32.c: Debug and partial rewrite of async socket code
+Wed Jun 20 12:00:54 2001 Owen Taylor <otaylor@redhat.com>
+
+ Changes for 64-bit cleanliness, loosely based on patch
+ from Mark Murnane.
+
+ * gconvert.c (g_convert/g_convert_with_fallback): Remove
+ workarounds for since-fixed GNU libc bugs. Minor
+ doc fix.
+
+ * gconvert.[ch]: Change gint to gsize/gssize as
+ appropriate.
+
+ * gconvert.c (g_locale/filename_to/from_utf8): Fix incorrect
+ computation of bytes_read / bytes_written.
+
+ * gfileutils.[ch] (g_file_get_contents): Make length
+ out parameter 'gsize *len'.
+
+ * ghook.c (g_hook_compare_ids): Don't compare a
+ and b as 'a - b'.
+
+ * gmacros.h (GSIZE_TO_POINTER): Add GPOINTER_TO_SIZE,
+ GSIZE_TO_POINTER.
+
+ * gmain.c (g_timeout_prepare): Rewrite to avoid
+ overflows. (Fixes bug when system clock skews
+ backwards more than 24 days.)
+
+ * gmarkup.[ch]: Make lengths passed to callbacks
+ gsize, length for g_markup_parse-context_parse(),
+ g_markup_escape_text() gssize.
+
+ * gmessages.[ch] (g_printf_string_upper_bound): Change
+ return value to gsize.
+
+ * gmessages.c (printf_string_upper_bound): Remove
+ a ridiculous use of 'inline' on a 300 line function.
+
+ * gstring.[ch]: Represent size of string as a gsize,
+ not gint. Make parameters to functions take gsize,
+ or gssize where -1 is allowed.
+
+ * gstring.c (g_string_erase): Make
+ g_string_erase (string, pos, -1) a synonym for
+ g_string_truncate for consistency with other G*
+ APIs.
+
+ * gstrfuncs.[ch]: Make all functions taking a string
+ length, take a gsize, or gssize if -1 is allowed.
+ (g_strstr_len, g_strrstr_len). Also fix some boundary
+ conditions in g_str[r]str[_len].
+
+ * gutf8.c tests/unicode-encoding.c: Make parameters that
+ are byte lengths gsize, gssize as appropriate. Make
+ character offsets, other counts, glong.
+
+ * gasyncqueue.c gcompletion.c
+ timeloop.c timeloop-basic.c gutils.c gspawn.c.
+ Small 64 bit cleanliness fixups.
+
+ * glist.c (g_list_sort2, g_list_sort_real): Fix functions
+ that should have been static.
+
+ * gdate.c (g_date_fill_parse_tokens): Fix extra
+ declaration that was shadowing another.
+
+ * tests/module-test.c: Include string.h
+
+Mon Jun 18 15:43:29 2001 Owen Taylor <otaylor@redhat.com>
+
+ * gutf8.c (g_get_charset): Make argument
+ G_CONST_RETURN char **.
+
2001-06-22 Andrew Lanoix <alanoix@umich.edu>
*giowin32.c: Debug and partial rewrite of async socket code
+Wed Jun 20 12:00:54 2001 Owen Taylor <otaylor@redhat.com>
+
+ Changes for 64-bit cleanliness, loosely based on patch
+ from Mark Murnane.
+
+ * gconvert.c (g_convert/g_convert_with_fallback): Remove
+ workarounds for since-fixed GNU libc bugs. Minor
+ doc fix.
+
+ * gconvert.[ch]: Change gint to gsize/gssize as
+ appropriate.
+
+ * gconvert.c (g_locale/filename_to/from_utf8): Fix incorrect
+ computation of bytes_read / bytes_written.
+
+ * gfileutils.[ch] (g_file_get_contents): Make length
+ out parameter 'gsize *len'.
+
+ * ghook.c (g_hook_compare_ids): Don't compare a
+ and b as 'a - b'.
+
+ * gmacros.h (GSIZE_TO_POINTER): Add GPOINTER_TO_SIZE,
+ GSIZE_TO_POINTER.
+
+ * gmain.c (g_timeout_prepare): Rewrite to avoid
+ overflows. (Fixes bug when system clock skews
+ backwards more than 24 days.)
+
+ * gmarkup.[ch]: Make lengths passed to callbacks
+ gsize, length for g_markup_parse-context_parse(),
+ g_markup_escape_text() gssize.
+
+ * gmessages.[ch] (g_printf_string_upper_bound): Change
+ return value to gsize.
+
+ * gmessages.c (printf_string_upper_bound): Remove
+ a ridiculous use of 'inline' on a 300 line function.
+
+ * gstring.[ch]: Represent size of string as a gsize,
+ not gint. Make parameters to functions take gsize,
+ or gssize where -1 is allowed.
+
+ * gstring.c (g_string_erase): Make
+ g_string_erase (string, pos, -1) a synonym for
+ g_string_truncate for consistency with other G*
+ APIs.
+
+ * gstrfuncs.[ch]: Make all functions taking a string
+ length, take a gsize, or gssize if -1 is allowed.
+ (g_strstr_len, g_strrstr_len). Also fix some boundary
+ conditions in g_str[r]str[_len].
+
+ * gutf8.c tests/unicode-encoding.c: Make parameters that
+ are byte lengths gsize, gssize as appropriate. Make
+ character offsets, other counts, glong.
+
+ * gasyncqueue.c gcompletion.c
+ timeloop.c timeloop-basic.c gutils.c gspawn.c.
+ Small 64 bit cleanliness fixups.
+
+ * glist.c (g_list_sort2, g_list_sort_real): Fix functions
+ that should have been static.
+
+ * gdate.c (g_date_fill_parse_tokens): Fix extra
+ declaration that was shadowing another.
+
+ * tests/module-test.c: Include string.h
+
+Mon Jun 18 15:43:29 2001 Owen Taylor <otaylor@redhat.com>
+
+ * gutf8.c (g_get_charset): Make argument
+ G_CONST_RETURN char **.
+
2001-06-22 Andrew Lanoix <alanoix@umich.edu>
*giowin32.c: Debug and partial rewrite of async socket code
+Wed Jun 20 12:00:54 2001 Owen Taylor <otaylor@redhat.com>
+
+ Changes for 64-bit cleanliness, loosely based on patch
+ from Mark Murnane.
+
+ * gconvert.c (g_convert/g_convert_with_fallback): Remove
+ workarounds for since-fixed GNU libc bugs. Minor
+ doc fix.
+
+ * gconvert.[ch]: Change gint to gsize/gssize as
+ appropriate.
+
+ * gconvert.c (g_locale/filename_to/from_utf8): Fix incorrect
+ computation of bytes_read / bytes_written.
+
+ * gfileutils.[ch] (g_file_get_contents): Make length
+ out parameter 'gsize *len'.
+
+ * ghook.c (g_hook_compare_ids): Don't compare a
+ and b as 'a - b'.
+
+ * gmacros.h (GSIZE_TO_POINTER): Add GPOINTER_TO_SIZE,
+ GSIZE_TO_POINTER.
+
+ * gmain.c (g_timeout_prepare): Rewrite to avoid
+ overflows. (Fixes bug when system clock skews
+ backwards more than 24 days.)
+
+ * gmarkup.[ch]: Make lengths passed to callbacks
+ gsize, length for g_markup_parse-context_parse(),
+ g_markup_escape_text() gssize.
+
+ * gmessages.[ch] (g_printf_string_upper_bound): Change
+ return value to gsize.
+
+ * gmessages.c (printf_string_upper_bound): Remove
+ a ridiculous use of 'inline' on a 300 line function.
+
+ * gstring.[ch]: Represent size of string as a gsize,
+ not gint. Make parameters to functions take gsize,
+ or gssize where -1 is allowed.
+
+ * gstring.c (g_string_erase): Make
+ g_string_erase (string, pos, -1) a synonym for
+ g_string_truncate for consistency with other G*
+ APIs.
+
+ * gstrfuncs.[ch]: Make all functions taking a string
+ length, take a gsize, or gssize if -1 is allowed.
+ (g_strstr_len, g_strrstr_len). Also fix some boundary
+ conditions in g_str[r]str[_len].
+
+ * gutf8.c tests/unicode-encoding.c: Make parameters that
+ are byte lengths gsize, gssize as appropriate. Make
+ character offsets, other counts, glong.
+
+ * gasyncqueue.c gcompletion.c
+ timeloop.c timeloop-basic.c gutils.c gspawn.c.
+ Small 64 bit cleanliness fixups.
+
+ * glist.c (g_list_sort2, g_list_sort_real): Fix functions
+ that should have been static.
+
+ * gdate.c (g_date_fill_parse_tokens): Fix extra
+ declaration that was shadowing another.
+
+ * tests/module-test.c: Include string.h
+
+Mon Jun 18 15:43:29 2001 Owen Taylor <otaylor@redhat.com>
+
+ * gutf8.c (g_get_charset): Make argument
+ G_CONST_RETURN char **.
+
2001-06-22 Andrew Lanoix <alanoix@umich.edu>
*giowin32.c: Debug and partial rewrite of async socket code
+Wed Jun 20 12:00:54 2001 Owen Taylor <otaylor@redhat.com>
+
+ Changes for 64-bit cleanliness, loosely based on patch
+ from Mark Murnane.
+
+ * gconvert.c (g_convert/g_convert_with_fallback): Remove
+ workarounds for since-fixed GNU libc bugs. Minor
+ doc fix.
+
+ * gconvert.[ch]: Change gint to gsize/gssize as
+ appropriate.
+
+ * gconvert.c (g_locale/filename_to/from_utf8): Fix incorrect
+ computation of bytes_read / bytes_written.
+
+ * gfileutils.[ch] (g_file_get_contents): Make length
+ out parameter 'gsize *len'.
+
+ * ghook.c (g_hook_compare_ids): Don't compare a
+ and b as 'a - b'.
+
+ * gmacros.h (GSIZE_TO_POINTER): Add GPOINTER_TO_SIZE,
+ GSIZE_TO_POINTER.
+
+ * gmain.c (g_timeout_prepare): Rewrite to avoid
+ overflows. (Fixes bug when system clock skews
+ backwards more than 24 days.)
+
+ * gmarkup.[ch]: Make lengths passed to callbacks
+ gsize, length for g_markup_parse-context_parse(),
+ g_markup_escape_text() gssize.
+
+ * gmessages.[ch] (g_printf_string_upper_bound): Change
+ return value to gsize.
+
+ * gmessages.c (printf_string_upper_bound): Remove
+ a ridiculous use of 'inline' on a 300 line function.
+
+ * gstring.[ch]: Represent size of string as a gsize,
+ not gint. Make parameters to functions take gsize,
+ or gssize where -1 is allowed.
+
+ * gstring.c (g_string_erase): Make
+ g_string_erase (string, pos, -1) a synonym for
+ g_string_truncate for consistency with other G*
+ APIs.
+
+ * gstrfuncs.[ch]: Make all functions taking a string
+ length, take a gsize, or gssize if -1 is allowed.
+ (g_strstr_len, g_strrstr_len). Also fix some boundary
+ conditions in g_str[r]str[_len].
+
+ * gutf8.c tests/unicode-encoding.c: Make parameters that
+ are byte lengths gsize, gssize as appropriate. Make
+ character offsets, other counts, glong.
+
+ * gasyncqueue.c gcompletion.c
+ timeloop.c timeloop-basic.c gutils.c gspawn.c.
+ Small 64 bit cleanliness fixups.
+
+ * glist.c (g_list_sort2, g_list_sort_real): Fix functions
+ that should have been static.
+
+ * gdate.c (g_date_fill_parse_tokens): Fix extra
+ declaration that was shadowing another.
+
+ * tests/module-test.c: Include string.h
+
+Mon Jun 18 15:43:29 2001 Owen Taylor <otaylor@redhat.com>
+
+ * gutf8.c (g_get_charset): Make argument
+ G_CONST_RETURN char **.
+
2001-06-22 Andrew Lanoix <alanoix@umich.edu>
*giowin32.c: Debug and partial rewrite of async socket code
+Wed Jun 20 12:00:54 2001 Owen Taylor <otaylor@redhat.com>
+
+ Changes for 64-bit cleanliness, loosely based on patch
+ from Mark Murnane.
+
+ * gconvert.c (g_convert/g_convert_with_fallback): Remove
+ workarounds for since-fixed GNU libc bugs. Minor
+ doc fix.
+
+ * gconvert.[ch]: Change gint to gsize/gssize as
+ appropriate.
+
+ * gconvert.c (g_locale/filename_to/from_utf8): Fix incorrect
+ computation of bytes_read / bytes_written.
+
+ * gfileutils.[ch] (g_file_get_contents): Make length
+ out parameter 'gsize *len'.
+
+ * ghook.c (g_hook_compare_ids): Don't compare a
+ and b as 'a - b'.
+
+ * gmacros.h (GSIZE_TO_POINTER): Add GPOINTER_TO_SIZE,
+ GSIZE_TO_POINTER.
+
+ * gmain.c (g_timeout_prepare): Rewrite to avoid
+ overflows. (Fixes bug when system clock skews
+ backwards more than 24 days.)
+
+ * gmarkup.[ch]: Make lengths passed to callbacks
+ gsize, length for g_markup_parse-context_parse(),
+ g_markup_escape_text() gssize.
+
+ * gmessages.[ch] (g_printf_string_upper_bound): Change
+ return value to gsize.
+
+ * gmessages.c (printf_string_upper_bound): Remove
+ a ridiculous use of 'inline' on a 300 line function.
+
+ * gstring.[ch]: Represent size of string as a gsize,
+ not gint. Make parameters to functions take gsize,
+ or gssize where -1 is allowed.
+
+ * gstring.c (g_string_erase): Make
+ g_string_erase (string, pos, -1) a synonym for
+ g_string_truncate for consistency with other G*
+ APIs.
+
+ * gstrfuncs.[ch]: Make all functions taking a string
+ length, take a gsize, or gssize if -1 is allowed.
+ (g_strstr_len, g_strrstr_len). Also fix some boundary
+ conditions in g_str[r]str[_len].
+
+ * gutf8.c tests/unicode-encoding.c: Make parameters that
+ are byte lengths gsize, gssize as appropriate. Make
+ character offsets, other counts, glong.
+
+ * gasyncqueue.c gcompletion.c
+ timeloop.c timeloop-basic.c gutils.c gspawn.c.
+ Small 64 bit cleanliness fixups.
+
+ * glist.c (g_list_sort2, g_list_sort_real): Fix functions
+ that should have been static.
+
+ * gdate.c (g_date_fill_parse_tokens): Fix extra
+ declaration that was shadowing another.
+
+ * tests/module-test.c: Include string.h
+
+Mon Jun 18 15:43:29 2001 Owen Taylor <otaylor@redhat.com>
+
+ * gutf8.c (g_get_charset): Make argument
+ G_CONST_RETURN char **.
+
2001-06-22 Andrew Lanoix <alanoix@umich.edu>
*giowin32.c: Debug and partial rewrite of async socket code
+Wed Jun 20 12:00:54 2001 Owen Taylor <otaylor@redhat.com>
+
+ Changes for 64-bit cleanliness, loosely based on patch
+ from Mark Murnane.
+
+ * gconvert.c (g_convert/g_convert_with_fallback): Remove
+ workarounds for since-fixed GNU libc bugs. Minor
+ doc fix.
+
+ * gconvert.[ch]: Change gint to gsize/gssize as
+ appropriate.
+
+ * gconvert.c (g_locale/filename_to/from_utf8): Fix incorrect
+ computation of bytes_read / bytes_written.
+
+ * gfileutils.[ch] (g_file_get_contents): Make length
+ out parameter 'gsize *len'.
+
+ * ghook.c (g_hook_compare_ids): Don't compare a
+ and b as 'a - b'.
+
+ * gmacros.h (GSIZE_TO_POINTER): Add GPOINTER_TO_SIZE,
+ GSIZE_TO_POINTER.
+
+ * gmain.c (g_timeout_prepare): Rewrite to avoid
+ overflows. (Fixes bug when system clock skews
+ backwards more than 24 days.)
+
+ * gmarkup.[ch]: Make lengths passed to callbacks
+ gsize, length for g_markup_parse-context_parse(),
+ g_markup_escape_text() gssize.
+
+ * gmessages.[ch] (g_printf_string_upper_bound): Change
+ return value to gsize.
+
+ * gmessages.c (printf_string_upper_bound): Remove
+ a ridiculous use of 'inline' on a 300 line function.
+
+ * gstring.[ch]: Represent size of string as a gsize,
+ not gint. Make parameters to functions take gsize,
+ or gssize where -1 is allowed.
+
+ * gstring.c (g_string_erase): Make
+ g_string_erase (string, pos, -1) a synonym for
+ g_string_truncate for consistency with other G*
+ APIs.
+
+ * gstrfuncs.[ch]: Make all functions taking a string
+ length, take a gsize, or gssize if -1 is allowed.
+ (g_strstr_len, g_strrstr_len). Also fix some boundary
+ conditions in g_str[r]str[_len].
+
+ * gutf8.c tests/unicode-encoding.c: Make parameters that
+ are byte lengths gsize, gssize as appropriate. Make
+ character offsets, other counts, glong.
+
+ * gasyncqueue.c gcompletion.c
+ timeloop.c timeloop-basic.c gutils.c gspawn.c.
+ Small 64 bit cleanliness fixups.
+
+ * glist.c (g_list_sort2, g_list_sort_real): Fix functions
+ that should have been static.
+
+ * gdate.c (g_date_fill_parse_tokens): Fix extra
+ declaration that was shadowing another.
+
+ * tests/module-test.c: Include string.h
+
+Mon Jun 18 15:43:29 2001 Owen Taylor <otaylor@redhat.com>
+
+ * gutf8.c (g_get_charset): Make argument
+ G_CONST_RETURN char **.
+
2001-06-22 Andrew Lanoix <alanoix@umich.edu>
*giowin32.c: Debug and partial rewrite of async socket code
+Wed Jun 20 12:00:54 2001 Owen Taylor <otaylor@redhat.com>
+
+ Changes for 64-bit cleanliness, loosely based on patch
+ from Mark Murnane.
+
+ * gconvert.c (g_convert/g_convert_with_fallback): Remove
+ workarounds for since-fixed GNU libc bugs. Minor
+ doc fix.
+
+ * gconvert.[ch]: Change gint to gsize/gssize as
+ appropriate.
+
+ * gconvert.c (g_locale/filename_to/from_utf8): Fix incorrect
+ computation of bytes_read / bytes_written.
+
+ * gfileutils.[ch] (g_file_get_contents): Make length
+ out parameter 'gsize *len'.
+
+ * ghook.c (g_hook_compare_ids): Don't compare a
+ and b as 'a - b'.
+
+ * gmacros.h (GSIZE_TO_POINTER): Add GPOINTER_TO_SIZE,
+ GSIZE_TO_POINTER.
+
+ * gmain.c (g_timeout_prepare): Rewrite to avoid
+ overflows. (Fixes bug when system clock skews
+ backwards more than 24 days.)
+
+ * gmarkup.[ch]: Make lengths passed to callbacks
+ gsize, length for g_markup_parse-context_parse(),
+ g_markup_escape_text() gssize.
+
+ * gmessages.[ch] (g_printf_string_upper_bound): Change
+ return value to gsize.
+
+ * gmessages.c (printf_string_upper_bound): Remove
+ a ridiculous use of 'inline' on a 300 line function.
+
+ * gstring.[ch]: Represent size of string as a gsize,
+ not gint. Make parameters to functions take gsize,
+ or gssize where -1 is allowed.
+
+ * gstring.c (g_string_erase): Make
+ g_string_erase (string, pos, -1) a synonym for
+ g_string_truncate for consistency with other G*
+ APIs.
+
+ * gstrfuncs.[ch]: Make all functions taking a string
+ length, take a gsize, or gssize if -1 is allowed.
+ (g_strstr_len, g_strrstr_len). Also fix some boundary
+ conditions in g_str[r]str[_len].
+
+ * gutf8.c tests/unicode-encoding.c: Make parameters that
+ are byte lengths gsize, gssize as appropriate. Make
+ character offsets, other counts, glong.
+
+ * gasyncqueue.c gcompletion.c
+ timeloop.c timeloop-basic.c gutils.c gspawn.c.
+ Small 64 bit cleanliness fixups.
+
+ * glist.c (g_list_sort2, g_list_sort_real): Fix functions
+ that should have been static.
+
+ * gdate.c (g_date_fill_parse_tokens): Fix extra
+ declaration that was shadowing another.
+
+ * tests/module-test.c: Include string.h
+
+Mon Jun 18 15:43:29 2001 Owen Taylor <otaylor@redhat.com>
+
+ * gutf8.c (g_get_charset): Make argument
+ G_CONST_RETURN char **.
+
2001-06-22 Andrew Lanoix <alanoix@umich.edu>
*giowin32.c: Debug and partial rewrite of async socket code
Portable way to copy <type>va_list</type> variables.
</para>
-<!-- # Unused Parameters # -->
@ap1: the <type>va_list</type> variable to place a copy of @ap2 in.
@ap2: a <type>va_list</type>.
@string: a #GString.
@pos: the position of the characters to remove.
-@len: the number of characters to remove.
+@len: the number of characters to remove, or -1 to remove all
+ following characters.
@Returns: the #GString.
</para>
-@charset:
@Returns:
+<!-- # Unused Parameters # -->
+@charset:
<!-- ##### FUNCTION g_unichar_validate ##### -->
gpointer data)
{
GRealPtrArray* array = (GRealPtrArray*) farray;
- int i;
+ guint i;
g_return_val_if_fail (array, FALSE);
gpointer data)
{
GRealPtrArray* array = (GRealPtrArray*) farray;
- int i;
+ guint i;
g_return_val_if_fail (array, FALSE);
gint
g_async_queue_length (GAsyncQueue* queue)
{
- glong retval;
+ gint retval;
g_return_val_if_fail (queue, 0);
g_return_val_if_fail (queue->ref_count > 0, 0);
gchar** new_prefix)
{
register GList* list;
- register gint len;
- register gint i;
- register gint plen;
+ register gsize len;
+ register gsize i;
+ register gsize plen;
gchar* postfix;
gchar* s;
gchar* prefix,
gchar** new_prefix)
{
- gint plen, len;
- gint done = 0;
+ gsize plen, len;
+ gboolean done = FALSE;
GList* list;
g_return_val_if_fail (cmp != NULL, NULL);
else
list = list->next;
}
- done = 1;
+ done = TRUE;
}
}
#define __G_COMPLETION_H__
#include <glist.h>
-#include <stddef.h> /* For size_t */
G_BEGIN_DECLS
typedef gint (*GCompletionStrncmpFunc) (const gchar *s1,
const gchar *s2,
- size_t n);
+ gsize n);
struct _GCompletion
{
size_t
g_iconv (GIConv converter,
gchar **inbuf,
- size_t *inbytes_left,
+ gsize *inbytes_left,
gchar **outbuf,
- size_t *outbytes_left)
+ gsize *outbytes_left)
{
iconv_t cd = (iconv_t)converter;
**/
gchar*
g_convert (const gchar *str,
- gint len,
+ gssize len,
const gchar *to_codeset,
const gchar *from_codeset,
- gint *bytes_read,
- gint *bytes_written,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error)
{
gchar *dest;
gchar *outp;
const gchar *p;
- size_t inbytes_remaining;
- size_t outbytes_remaining;
- size_t err;
+ gsize inbytes_remaining;
+ gsize outbytes_remaining;
+ gsize err;
GIConv cd;
- size_t outbuf_size;
+ gsize outbuf_size;
gboolean have_error = FALSE;
g_return_val_if_fail (str != NULL, NULL);
p = str;
inbytes_remaining = len;
-
- /* Due to a GLIBC bug, round outbuf_size up to a multiple of 4 */
- /* + 1 for nul in case len == 1 */
- outbuf_size = ((len + 3) & ~3) + 1;
+ outbuf_size = len + 1; /* + 1 for nul in case len == 1 */
outbytes_remaining = outbuf_size - 1; /* -1 for nul */
outp = dest = g_malloc (outbuf_size);
{
size_t used = outp - dest;
- /* glibc's iconv can return E2BIG even if there is space
- * remaining if an internal buffer is exhausted. The
- * folllowing is a heuristic to catch this. The 16 is
- * pretty arbitrary.
- */
- if (used + 16 > outbuf_size)
- {
- outbuf_size = (outbuf_size - 1) * 2 + 1;
- dest = g_realloc (dest, outbuf_size);
+ outbuf_size *= 2;
+ dest = g_realloc (dest, outbuf_size);
- outp = dest + used;
- outbytes_remaining = outbuf_size - used - 1; /* -1 for nul */
- }
+ outp = dest + used;
+ outbytes_remaining = outbuf_size - used - 1; /* -1 for nul */
goto again;
}
* input string that were successfully converted, or %NULL.
* Even if the conversion was succesful, this may be
* less than len if there were partial characters
- * at the end of the input. If the error
- * G_CONVERT_ERROR_ILLEGAL_SEQUENCE occurs, the value
- * stored will the byte fofset after the last valid
- * input sequence.
+ * at the end of the input.
* @bytes_written: the stored in the output buffer (not including the
* terminating nul.
* @error: location to store the error occuring, or %NULL to ignore
**/
gchar*
g_convert_with_fallback (const gchar *str,
- gint len,
+ gssize len,
const gchar *to_codeset,
const gchar *from_codeset,
gchar *fallback,
- gint *bytes_read,
- gint *bytes_written,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error)
{
gchar *utf8;
gchar *outp;
const gchar *insert_str = NULL;
const gchar *p;
- int inbytes_remaining;
+ gsize inbytes_remaining;
const gchar *save_p = NULL;
- size_t save_inbytes = 0;
- size_t outbytes_remaining;
- size_t err;
+ gsize save_inbytes = 0;
+ gsize outbytes_remaining;
+ gsize err;
GIConv cd;
- size_t outbuf_size;
+ gsize outbuf_size;
gboolean have_error = FALSE;
gboolean done = FALSE;
* for the original string while we are converting the fallback
*/
p = utf8;
- /* Due to a GLIBC bug, round outbuf_size up to a multiple of 4 */
- /* + 1 for nul in case len == 1 */
- outbuf_size = ((len + 3) & ~3) + 1;
+
+ outbuf_size = len + 1; /* + 1 for nul in case len == 1 */
outbytes_remaining = outbuf_size - 1; /* -1 for nul */
outp = dest = g_malloc (outbuf_size);
{
size_t used = outp - dest;
- /* glibc's iconv can return E2BIG even if there is space
- * remaining if an internal buffer is exhausted. The
- * folllowing is a heuristic to catch this. The 16 is
- * pretty arbitrary.
- */
- if (used + 16 > outbuf_size)
- {
- outbuf_size = (outbuf_size - 1) * 2 + 1;
- dest = g_realloc (dest, outbuf_size);
-
- outp = dest + used;
- outbytes_remaining = outbuf_size - used - 1; /* -1 for nul */
- }
+ outbuf_size *= 2;
+ dest = g_realloc (dest, outbuf_size);
+
+ outp = dest + used;
+ outbytes_remaining = outbuf_size - used - 1; /* -1 for nul */
break;
}
*
*/
+static gchar *
+strdup_len (const gchar *string,
+ gssize len,
+ gsize *bytes_written,
+ gsize *bytes_read)
+
+{
+ gsize real_len;
+
+ if (len < 0)
+ real_len = strlen (string);
+ else
+ {
+ real_len = 0;
+
+ while (real_len < len && string[real_len])
+ real_len++;
+ }
+
+ if (bytes_read)
+ *bytes_read = real_len;
+ if (bytes_written)
+ *bytes_written = real_len;
+
+ return g_strndup (string, real_len);
+}
+
/**
* g_locale_to_utf8:
* @opsysstring: a string in the encoding of the current locale
**/
gchar *
g_locale_to_utf8 (const gchar *opsysstring,
- gint len,
- gint *bytes_read,
- gint *bytes_written,
+ gssize len,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error)
{
#ifdef G_PLATFORM_WIN32
#else /* !G_PLATFORM_WIN32 */
- char *charset, *str;
+ const char *charset;
if (g_get_charset (&charset))
- return g_strdup (opsysstring);
+ return strdup_len (opsysstring, len, bytes_read, bytes_written);
+ else
+ return g_convert (opsysstring, len,
+ "UTF-8", charset, bytes_read, bytes_written, error);
- str = g_convert (opsysstring, len,
- "UTF-8", charset, bytes_read, bytes_written, error);
-
- return str;
#endif /* !G_PLATFORM_WIN32 */
}
**/
gchar *
g_locale_from_utf8 (const gchar *utf8string,
- gint len,
- gint *bytes_read,
- gint *bytes_written,
+ gssize len,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error)
{
#ifdef G_PLATFORM_WIN32
return result;
#else /* !G_PLATFORM_WIN32 */
-
- gchar *charset, *str;
+
+ const gchar *charset;
if (g_get_charset (&charset))
- return g_strdup (utf8string);
-
- str = g_convert (utf8string, strlen (utf8string),
- charset, "UTF-8", bytes_read, bytes_written, error);
+ return strdup_len (utf8string, len, bytes_read, bytes_written);
+ else
+ return g_convert (utf8string, len,
+ charset, "UTF-8", bytes_read, bytes_written, error);
- return str;
-
#endif /* !G_PLATFORM_WIN32 */
}
**/
gchar*
g_filename_to_utf8 (const gchar *opsysstring,
- gint len,
- gint *bytes_read,
- gint *bytes_written,
+ gssize len,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error)
{
#ifdef G_PLATFORM_WIN32
return g_locale_to_utf8 (opsysstring, len,
bytes_read, bytes_written,
error);
-
- if (bytes_read || bytes_written)
- {
- gint len = strlen (opsysstring);
-
- if (bytes_read)
- *bytes_read = len;
- if (bytes_written)
- *bytes_written = len;
- }
-
- if (len < 0)
- return g_strdup (opsysstring);
else
- return g_strndup (opsysstring, len);
+ return strdup_len (opsysstring, len, bytes_read, bytes_written);
#endif /* !G_PLATFORM_WIN32 */
}
**/
gchar*
g_filename_from_utf8 (const gchar *utf8string,
- gint len,
- gint *bytes_read,
- gint *bytes_written,
+ gssize len,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error)
{
#ifdef G_PLATFORM_WIN32
return g_locale_from_utf8 (utf8string, len,
bytes_read, bytes_written,
error);
-
- if (bytes_read || bytes_written)
- {
- gint len = strlen (utf8string);
-
- if (bytes_read)
- *bytes_read = len;
- if (bytes_written)
- *bytes_written = len;
- }
-
- if (len < 0)
- return g_strdup (utf8string);
else
- return g_strndup (utf8string, len);
+ return strdup_len (utf8string, len, bytes_read, bytes_written);
#endif /* !G_PLATFORM_WIN32 */
}
} GConvertError;
#define G_CONVERT_ERROR g_convert_error_quark()
-GQuark g_convert_error_quark();
+GQuark g_convert_error_quark (void);
/* Thin wrappers around iconv
*/
const gchar *from_codeset);
size_t g_iconv (GIConv converter,
gchar **inbuf,
- size_t *inbytes_left,
+ gsize *inbytes_left,
gchar **outbuf,
- size_t *outbytes_left);
+ gsize *outbytes_left);
gint g_iconv_close (GIConv converter);
gchar* g_convert (const gchar *str,
- gint len,
+ gssize len,
const gchar *to_codeset,
const gchar *from_codeset,
- gint *bytes_read,
- gint *bytes_written,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error);
gchar* g_convert_with_fallback (const gchar *str,
- gint len,
+ gssize len,
const gchar *to_codeset,
const gchar *from_codeset,
gchar *fallback,
- gint *bytes_read,
- gint *bytes_written,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error);
/* Convert between libc's idea of strings and UTF-8.
*/
gchar* g_locale_to_utf8 (const gchar *opsysstring,
- gint len,
- gint *bytes_read,
- gint *bytes_written,
+ gssize len,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error);
gchar* g_locale_from_utf8 (const gchar *utf8string,
- gint len,
- gint *bytes_read,
- gint *bytes_written,
+ gssize len,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error);
/* Convert between the operating system (or C runtime)
* representation of file names and UTF-8.
*/
gchar* g_filename_to_utf8 (const gchar *opsysstring,
- gint len,
- gint *bytes_read,
- gint *bytes_written,
+ gssize len,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error);
gchar* g_filename_from_utf8 (const gchar *utf8string,
- gint len,
- gint *bytes_read,
- gint *bytes_written,
+ gssize len,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error);
G_END_DECLS
if (pt->num_ints < 3)
{
gchar lcstr[128];
- int i = 1;
strncpy (lcstr, str, 127);
g_strdown (lcstr);
get_contents_stdio (const gchar *filename,
FILE *f,
gchar **contents,
- guint *length,
+ gsize *length,
GError **error)
{
gchar buf[2048];
struct stat *stat_buf,
gint fd,
gchar **contents,
- guint *length,
+ gsize *length,
GError **error)
{
gchar *buf;
bytes_read = 0;
while (bytes_read < size)
{
- gint rc;
+ gssize rc;
rc = read (fd, buf + bytes_read, size - bytes_read);
static gboolean
get_contents_posix (const gchar *filename,
gchar **contents,
- guint *length,
+ gsize *length,
GError **error)
{
struct stat stat_buf;
static gboolean
get_contents_win32 (const gchar *filename,
gchar **contents,
- guint *length,
+ gsize *length,
GError **error)
{
FILE *f;
gboolean
g_file_get_contents (const gchar *filename,
gchar **contents,
- guint *length,
+ gsize *length,
GError **error)
{
g_return_val_if_fail (filename != NULL, FALSE);
GFileTest test);
gboolean g_file_get_contents (const gchar *filename,
gchar **contents,
- guint *length,
+ gsize *length,
GError **error);
g_hook_compare_ids (GHook *new_hook,
GHook *sibling)
{
- return ((glong) new_hook->hook_id) - ((glong) sibling->hook_id);
+ if (new_hook->hook_id < sibling->hook_id)
+ return -1;
+ else if (new_hook->hook_id > sibling->hook_id)
+ return 1;
+
+ return 0;
}
gpointer data)
{
GRealPtrArray* array = (GRealPtrArray*) farray;
- int i;
+ guint i;
g_return_val_if_fail (array, FALSE);
gpointer data)
{
GRealPtrArray* array = (GRealPtrArray*) farray;
- int i;
+ guint i;
g_return_val_if_fail (array, FALSE);
gint
g_async_queue_length (GAsyncQueue* queue)
{
- glong retval;
+ gint retval;
g_return_val_if_fail (queue, 0);
g_return_val_if_fail (queue->ref_count > 0, 0);
gchar** new_prefix)
{
register GList* list;
- register gint len;
- register gint i;
- register gint plen;
+ register gsize len;
+ register gsize i;
+ register gsize plen;
gchar* postfix;
gchar* s;
gchar* prefix,
gchar** new_prefix)
{
- gint plen, len;
- gint done = 0;
+ gsize plen, len;
+ gboolean done = FALSE;
GList* list;
g_return_val_if_fail (cmp != NULL, NULL);
else
list = list->next;
}
- done = 1;
+ done = TRUE;
}
}
#define __G_COMPLETION_H__
#include <glist.h>
-#include <stddef.h> /* For size_t */
G_BEGIN_DECLS
typedef gint (*GCompletionStrncmpFunc) (const gchar *s1,
const gchar *s2,
- size_t n);
+ gsize n);
struct _GCompletion
{
size_t
g_iconv (GIConv converter,
gchar **inbuf,
- size_t *inbytes_left,
+ gsize *inbytes_left,
gchar **outbuf,
- size_t *outbytes_left)
+ gsize *outbytes_left)
{
iconv_t cd = (iconv_t)converter;
**/
gchar*
g_convert (const gchar *str,
- gint len,
+ gssize len,
const gchar *to_codeset,
const gchar *from_codeset,
- gint *bytes_read,
- gint *bytes_written,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error)
{
gchar *dest;
gchar *outp;
const gchar *p;
- size_t inbytes_remaining;
- size_t outbytes_remaining;
- size_t err;
+ gsize inbytes_remaining;
+ gsize outbytes_remaining;
+ gsize err;
GIConv cd;
- size_t outbuf_size;
+ gsize outbuf_size;
gboolean have_error = FALSE;
g_return_val_if_fail (str != NULL, NULL);
p = str;
inbytes_remaining = len;
-
- /* Due to a GLIBC bug, round outbuf_size up to a multiple of 4 */
- /* + 1 for nul in case len == 1 */
- outbuf_size = ((len + 3) & ~3) + 1;
+ outbuf_size = len + 1; /* + 1 for nul in case len == 1 */
outbytes_remaining = outbuf_size - 1; /* -1 for nul */
outp = dest = g_malloc (outbuf_size);
{
size_t used = outp - dest;
- /* glibc's iconv can return E2BIG even if there is space
- * remaining if an internal buffer is exhausted. The
- * folllowing is a heuristic to catch this. The 16 is
- * pretty arbitrary.
- */
- if (used + 16 > outbuf_size)
- {
- outbuf_size = (outbuf_size - 1) * 2 + 1;
- dest = g_realloc (dest, outbuf_size);
+ outbuf_size *= 2;
+ dest = g_realloc (dest, outbuf_size);
- outp = dest + used;
- outbytes_remaining = outbuf_size - used - 1; /* -1 for nul */
- }
+ outp = dest + used;
+ outbytes_remaining = outbuf_size - used - 1; /* -1 for nul */
goto again;
}
* input string that were successfully converted, or %NULL.
* Even if the conversion was succesful, this may be
* less than len if there were partial characters
- * at the end of the input. If the error
- * G_CONVERT_ERROR_ILLEGAL_SEQUENCE occurs, the value
- * stored will the byte fofset after the last valid
- * input sequence.
+ * at the end of the input.
* @bytes_written: the stored in the output buffer (not including the
* terminating nul.
* @error: location to store the error occuring, or %NULL to ignore
**/
gchar*
g_convert_with_fallback (const gchar *str,
- gint len,
+ gssize len,
const gchar *to_codeset,
const gchar *from_codeset,
gchar *fallback,
- gint *bytes_read,
- gint *bytes_written,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error)
{
gchar *utf8;
gchar *outp;
const gchar *insert_str = NULL;
const gchar *p;
- int inbytes_remaining;
+ gsize inbytes_remaining;
const gchar *save_p = NULL;
- size_t save_inbytes = 0;
- size_t outbytes_remaining;
- size_t err;
+ gsize save_inbytes = 0;
+ gsize outbytes_remaining;
+ gsize err;
GIConv cd;
- size_t outbuf_size;
+ gsize outbuf_size;
gboolean have_error = FALSE;
gboolean done = FALSE;
* for the original string while we are converting the fallback
*/
p = utf8;
- /* Due to a GLIBC bug, round outbuf_size up to a multiple of 4 */
- /* + 1 for nul in case len == 1 */
- outbuf_size = ((len + 3) & ~3) + 1;
+
+ outbuf_size = len + 1; /* + 1 for nul in case len == 1 */
outbytes_remaining = outbuf_size - 1; /* -1 for nul */
outp = dest = g_malloc (outbuf_size);
{
size_t used = outp - dest;
- /* glibc's iconv can return E2BIG even if there is space
- * remaining if an internal buffer is exhausted. The
- * folllowing is a heuristic to catch this. The 16 is
- * pretty arbitrary.
- */
- if (used + 16 > outbuf_size)
- {
- outbuf_size = (outbuf_size - 1) * 2 + 1;
- dest = g_realloc (dest, outbuf_size);
-
- outp = dest + used;
- outbytes_remaining = outbuf_size - used - 1; /* -1 for nul */
- }
+ outbuf_size *= 2;
+ dest = g_realloc (dest, outbuf_size);
+
+ outp = dest + used;
+ outbytes_remaining = outbuf_size - used - 1; /* -1 for nul */
break;
}
*
*/
+static gchar *
+strdup_len (const gchar *string,
+ gssize len,
+ gsize *bytes_written,
+ gsize *bytes_read)
+
+{
+ gsize real_len;
+
+ if (len < 0)
+ real_len = strlen (string);
+ else
+ {
+ real_len = 0;
+
+ while (real_len < len && string[real_len])
+ real_len++;
+ }
+
+ if (bytes_read)
+ *bytes_read = real_len;
+ if (bytes_written)
+ *bytes_written = real_len;
+
+ return g_strndup (string, real_len);
+}
+
/**
* g_locale_to_utf8:
* @opsysstring: a string in the encoding of the current locale
**/
gchar *
g_locale_to_utf8 (const gchar *opsysstring,
- gint len,
- gint *bytes_read,
- gint *bytes_written,
+ gssize len,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error)
{
#ifdef G_PLATFORM_WIN32
#else /* !G_PLATFORM_WIN32 */
- char *charset, *str;
+ const char *charset;
if (g_get_charset (&charset))
- return g_strdup (opsysstring);
+ return strdup_len (opsysstring, len, bytes_read, bytes_written);
+ else
+ return g_convert (opsysstring, len,
+ "UTF-8", charset, bytes_read, bytes_written, error);
- str = g_convert (opsysstring, len,
- "UTF-8", charset, bytes_read, bytes_written, error);
-
- return str;
#endif /* !G_PLATFORM_WIN32 */
}
**/
gchar *
g_locale_from_utf8 (const gchar *utf8string,
- gint len,
- gint *bytes_read,
- gint *bytes_written,
+ gssize len,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error)
{
#ifdef G_PLATFORM_WIN32
return result;
#else /* !G_PLATFORM_WIN32 */
-
- gchar *charset, *str;
+
+ const gchar *charset;
if (g_get_charset (&charset))
- return g_strdup (utf8string);
-
- str = g_convert (utf8string, strlen (utf8string),
- charset, "UTF-8", bytes_read, bytes_written, error);
+ return strdup_len (utf8string, len, bytes_read, bytes_written);
+ else
+ return g_convert (utf8string, len,
+ charset, "UTF-8", bytes_read, bytes_written, error);
- return str;
-
#endif /* !G_PLATFORM_WIN32 */
}
**/
gchar*
g_filename_to_utf8 (const gchar *opsysstring,
- gint len,
- gint *bytes_read,
- gint *bytes_written,
+ gssize len,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error)
{
#ifdef G_PLATFORM_WIN32
return g_locale_to_utf8 (opsysstring, len,
bytes_read, bytes_written,
error);
-
- if (bytes_read || bytes_written)
- {
- gint len = strlen (opsysstring);
-
- if (bytes_read)
- *bytes_read = len;
- if (bytes_written)
- *bytes_written = len;
- }
-
- if (len < 0)
- return g_strdup (opsysstring);
else
- return g_strndup (opsysstring, len);
+ return strdup_len (opsysstring, len, bytes_read, bytes_written);
#endif /* !G_PLATFORM_WIN32 */
}
**/
gchar*
g_filename_from_utf8 (const gchar *utf8string,
- gint len,
- gint *bytes_read,
- gint *bytes_written,
+ gssize len,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error)
{
#ifdef G_PLATFORM_WIN32
return g_locale_from_utf8 (utf8string, len,
bytes_read, bytes_written,
error);
-
- if (bytes_read || bytes_written)
- {
- gint len = strlen (utf8string);
-
- if (bytes_read)
- *bytes_read = len;
- if (bytes_written)
- *bytes_written = len;
- }
-
- if (len < 0)
- return g_strdup (utf8string);
else
- return g_strndup (utf8string, len);
+ return strdup_len (utf8string, len, bytes_read, bytes_written);
#endif /* !G_PLATFORM_WIN32 */
}
} GConvertError;
#define G_CONVERT_ERROR g_convert_error_quark()
-GQuark g_convert_error_quark();
+GQuark g_convert_error_quark (void);
/* Thin wrappers around iconv
*/
const gchar *from_codeset);
size_t g_iconv (GIConv converter,
gchar **inbuf,
- size_t *inbytes_left,
+ gsize *inbytes_left,
gchar **outbuf,
- size_t *outbytes_left);
+ gsize *outbytes_left);
gint g_iconv_close (GIConv converter);
gchar* g_convert (const gchar *str,
- gint len,
+ gssize len,
const gchar *to_codeset,
const gchar *from_codeset,
- gint *bytes_read,
- gint *bytes_written,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error);
gchar* g_convert_with_fallback (const gchar *str,
- gint len,
+ gssize len,
const gchar *to_codeset,
const gchar *from_codeset,
gchar *fallback,
- gint *bytes_read,
- gint *bytes_written,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error);
/* Convert between libc's idea of strings and UTF-8.
*/
gchar* g_locale_to_utf8 (const gchar *opsysstring,
- gint len,
- gint *bytes_read,
- gint *bytes_written,
+ gssize len,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error);
gchar* g_locale_from_utf8 (const gchar *utf8string,
- gint len,
- gint *bytes_read,
- gint *bytes_written,
+ gssize len,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error);
/* Convert between the operating system (or C runtime)
* representation of file names and UTF-8.
*/
gchar* g_filename_to_utf8 (const gchar *opsysstring,
- gint len,
- gint *bytes_read,
- gint *bytes_written,
+ gssize len,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error);
gchar* g_filename_from_utf8 (const gchar *utf8string,
- gint len,
- gint *bytes_read,
- gint *bytes_written,
+ gssize len,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error);
G_END_DECLS
if (pt->num_ints < 3)
{
gchar lcstr[128];
- int i = 1;
strncpy (lcstr, str, 127);
g_strdown (lcstr);
get_contents_stdio (const gchar *filename,
FILE *f,
gchar **contents,
- guint *length,
+ gsize *length,
GError **error)
{
gchar buf[2048];
struct stat *stat_buf,
gint fd,
gchar **contents,
- guint *length,
+ gsize *length,
GError **error)
{
gchar *buf;
bytes_read = 0;
while (bytes_read < size)
{
- gint rc;
+ gssize rc;
rc = read (fd, buf + bytes_read, size - bytes_read);
static gboolean
get_contents_posix (const gchar *filename,
gchar **contents,
- guint *length,
+ gsize *length,
GError **error)
{
struct stat stat_buf;
static gboolean
get_contents_win32 (const gchar *filename,
gchar **contents,
- guint *length,
+ gsize *length,
GError **error)
{
FILE *f;
gboolean
g_file_get_contents (const gchar *filename,
gchar **contents,
- guint *length,
+ gsize *length,
GError **error)
{
g_return_val_if_fail (filename != NULL, FALSE);
GFileTest test);
gboolean g_file_get_contents (const gchar *filename,
gchar **contents,
- guint *length,
+ gsize *length,
GError **error);
g_hook_compare_ids (GHook *new_hook,
GHook *sibling)
{
- return ((glong) new_hook->hook_id) - ((glong) sibling->hook_id);
+ if (new_hook->hook_id < sibling->hook_id)
+ return -1;
+ else if (new_hook->hook_id > sibling->hook_id)
+ return 1;
+
+ return 0;
}
return list.next;
}
-GList*
+static GList*
g_list_sort_real (GList *list,
GFunc compare_func,
gboolean use_data,
return g_list_sort_real (list, (GFunc) compare_func, TRUE, user_data);
}
-GList*
+static GList*
g_list_sort2 (GList *list,
GCompareFunc compare_func)
{
*/
#define G_N_ELEMENTS(arr) (sizeof (arr) / sizeof ((arr)[0]))
+/* Macros by analogy to GINT_TO_POINTER, GPOINTER_TO_INT
+ */
+#define GPOINTER_TO_SIZE(p) ((gsize) (p))
+#define GSIZE_TO_POINTER(s) ((gpointer) (gsize) (s))
+
/* Provide convenience macros for handling structure
* fields through their offsets.
*/
GMemChunk *poll_chunk;
guint n_poll_records;
GPollFD *cached_poll_array;
- gint cached_poll_array_size;
+ guint cached_poll_array_size;
#ifdef G_THREADS_ENABLED
#ifndef G_OS_WIN32
static void
g_main_dispatch (GMainContext *context)
{
- gint i;
+ guint i;
for (i = 0; i < context->pending_dispatches->len; i++)
{
g_timeout_prepare (GSource *source,
gint *timeout)
{
+ glong sec;
glong msec;
GTimeVal current_time;
GTimeoutSource *timeout_source = (GTimeoutSource *)source;
g_source_get_current_time (source, ¤t_time);
-
- msec = ((timeout_source->expiration.tv_sec - current_time.tv_sec) * 1000 +
- (timeout_source->expiration.tv_usec - current_time.tv_usec) / 1000);
- if (msec < 0)
+ sec = timeout_source->expiration.tv_sec - current_time.tv_sec;
+ msec = (timeout_source->expiration.tv_usec - current_time.tv_usec) / 1000;
+
+ /* We do the following in a rather convoluted fashion to deal with
+ * the fact that we don't have an integral type big enough to hold
+ * the difference of two timevals in millseconds.
+ */
+ if (sec < 0 || (sec == 0 && msec < 0))
msec = 0;
- else if (msec > timeout_source->interval)
+ else
{
- /* The system time has been set backwards, so we
- * reset the expiration time to now + timeout_source->interval;
- * this at least avoids hanging for long periods of time.
- */
- g_timeout_set_expiration (timeout_source, ¤t_time);
- msec = timeout_source->interval;
+ glong interval_sec = timeout_source->interval / 1000;
+ glong interval_msec = timeout_source->interval % 1000;
+
+ if (msec < 0)
+ {
+ msec += 1000;
+ sec -= 1;
+ }
+
+ if (sec > interval_sec ||
+ (sec == interval_sec && msec > interval_msec))
+ {
+ /* The system time has been set backwards, so we
+ * reset the expiration time to now + timeout_source->interval;
+ * this at least avoids hanging for long periods of time.
+ */
+ g_timeout_set_expiration (timeout_source, ¤t_time);
+ msec = timeout_source->interval;
+ }
+ else
+ {
+ msec += sec * 1000;
+ }
}
-
- *timeout = msec;
+
+ *timeout = (gint)msec;
return msec == 0;
}
gint alloc_attrs;
const gchar *current_text;
- gint current_text_len;
+ gssize current_text_len;
const gchar *current_text_end;
GString *leftover_char_portion;
(l >= 0x10000 && l <= 0x10FFFF))
{
gchar buf[7];
- g_string_append (str,
- char_str (l, buf));
+ g_string_append (str, char_str (l, buf));
}
else
{
gboolean
g_markup_parse_context_parse (GMarkupParseContext *context,
const gchar *text,
- gint text_len,
+ gssize text_len,
GError **error)
{
const gchar *first_invalid;
static void
append_escaped_text (GString *str,
const gchar *text,
- gint length)
+ gssize length)
{
const gchar *p;
const gchar *end;
**/
gchar*
g_markup_escape_text (const gchar *text,
- gint length)
+ gssize length)
{
GString *str;
/* text is not nul-terminated */
void (*text) (GMarkupParseContext *context,
const gchar *text,
- gint text_len,
+ gsize text_len,
gpointer user_data,
GError **error);
/* text is not nul-terminated. */
void (*passthrough) (GMarkupParseContext *context,
const gchar *passthrough_text,
- gint text_len,
+ gsize text_len,
gpointer user_data,
GError **error);
void g_markup_parse_context_free (GMarkupParseContext *context);
gboolean g_markup_parse_context_parse (GMarkupParseContext *context,
const gchar *text,
- gint text_len,
+ gssize text_len,
GError **error);
gboolean g_markup_parse_context_end_parse (GMarkupParseContext *context,
/* useful when saving */
gchar* g_markup_escape_text (const gchar *text,
- gint length);
+ gssize length);
G_END_DECLS
/* --- prototypes --- */
-static inline guint printf_string_upper_bound (const gchar *format,
- gboolean may_warn,
- va_list args);
+static guint printf_string_upper_bound (const gchar *format,
+ gboolean may_warn,
+ va_list args);
/* --- variables --- */
#endif
static void
-write_unsigned (GFileDescriptor fd,
- gulong num,
- guint radix)
+write_unsigned (GFileDescriptor fd,
+ gulong num,
+ guint radix)
{
char buffer[64];
gulong tmp;
gboolean mod_half, mod_long, mod_extra_long;
} PrintfArgSpec;
-static inline guint
+static gsize
printf_string_upper_bound (const gchar *format,
gboolean may_warn,
va_list args)
{
static const gboolean honour_longs = SIZEOF_LONG > 4 || SIZEOF_VOID_P > 4;
- guint len = 1;
+ gsize len = 1;
if (!format)
return len;
{
PrintfArgSpec spec = { 0, };
gboolean seen_l = FALSE, conv_done = FALSE;
- guint conv_len = 0;
+ gsize conv_len = 0;
const gchar *spec_start = format;
do
return len;
}
-guint
+gsize
g_printf_string_upper_bound (const gchar *format,
va_list args)
{
/* calculate a string size, guarranteed to fit format + args.
*/
-guint g_printf_string_upper_bound (const gchar* format,
+gsize g_printf_string_upper_bound (const gchar* format,
va_list args);
/* Log level shift offset for user defined
gint fd,
GError **error)
{
- gint bytes;
- gchar buf[4096];
+ gssize bytes;
+ gchar buf[4096];
again:
static gboolean
read_ints (int fd,
gint* buf,
- gint n_ints_in_buf,
- gint *n_ints_read,
+ gint n_ints_in_buf,
+ gint *n_ints_read,
GError **error)
{
- gint bytes = 0;
+ gsize bytes = 0;
while (TRUE)
{
- gint chunk;
+ gssize chunk;
if (bytes >= sizeof(gint)*2)
break; /* give up, who knows what happened, should not be
again:
chunk = read (fd,
((gchar*)buf) + bytes,
- sizeof(gint)*n_ints_in_buf - bytes);
+ sizeof(gint) * n_ints_in_buf - bytes);
if (chunk < 0 && errno == EINTR)
goto again;
}
else if (chunk == 0)
break; /* EOF */
- else
- {
- g_assert (chunk > 0);
-
- bytes += chunk;
- }
+ else /* chunk > 0 */
+ bytes += chunk;
}
- *n_ints_read = bytes/4;
+ *n_ints_read = (gint)(bytes / sizeof(gint));
return TRUE;
}
/* Parent */
gint buf[2];
- gint n_ints = 0;
+ gint n_ints = 0;
/* Close the uncared-about ends of the pipes */
close_and_invalidate (&child_err_report_pipe[1]);
gchar*
g_strndup (const gchar *str,
- guint n)
+ gsize n)
{
gchar *new_str;
}
gchar*
-g_strnfill (guint length,
+g_strnfill (gsize length,
gchar fill_char)
{
register gchar *str, *s, *end;
gchar*
g_strconcat (const gchar *string1, ...)
{
- guint l;
+ gsize l;
va_list args;
gchar *s;
gchar *concat;
gint
g_strncasecmp (const gchar *s1,
const gchar *s2,
- guint n)
+ gsize n)
{
#ifdef HAVE_STRNCASECMP
return strncasecmp (s1, s2, n);
s = strstr (string, delimiter);
if (s)
{
- guint delimiter_len = strlen (delimiter);
+ gsize delimiter_len = strlen (delimiter);
do
{
- guint len;
+ gsize len;
gchar *new_string;
len = s - string;
if (*str_array)
{
- guint i, len;
- guint separator_len;
+ gint i;
+ gsize len;
+ gsize separator_len;
separator_len = strlen (separator);
/* First part, getting length */
{
gchar *string, *s;
va_list args;
- guint len;
- guint separator_len;
+ gsize len;
+ gsize separator_len;
gchar *ptr;
if (separator == NULL)
**/
gchar *
g_strstr_len (const gchar *haystack,
- gint haystack_len,
+ gssize haystack_len,
const gchar *needle)
{
- int i;
-
g_return_val_if_fail (haystack != NULL, NULL);
g_return_val_if_fail (needle != NULL, NULL);
return strstr (haystack, needle);
else
{
- const char *p = haystack;
- int needle_len = strlen (needle);
- const char *end = haystack + haystack_len - needle_len;
-
+ const gchar *p = haystack;
+ gsize needle_len = strlen (needle);
+ const gchar *end;
+ gsize i;
+
if (needle_len == 0)
- return (char *)haystack;
+ return (gchar *)haystack;
+ if (haystack_len < needle_len)
+ return NULL;
+
+ end = haystack + haystack_len - needle_len;
+
while (*p && p <= end)
{
for (i = 0; i < needle_len; i++)
if (p[i] != needle[i])
goto next;
- return (char *)p;
+ return (gchar *)p;
next:
p++;
}
+
+ return NULL;
}
-
- return NULL;
}
/**
g_strrstr (const gchar *haystack,
const gchar *needle)
{
- int i;
- int needle_len = strlen (needle);
- int haystack_len = strlen (haystack);
- const char *p = haystack + haystack_len - needle_len;
+ gsize i;
+ gsize needle_len;
+ gsize haystack_len;
+ const gchar *p;
g_return_val_if_fail (haystack != NULL, NULL);
g_return_val_if_fail (needle != NULL, NULL);
-
+
+ needle_len = strlen (needle);
+ haystack_len = strlen (haystack);
+
if (needle_len == 0)
- return (char *)p;
+ return (gchar *)haystack;
+
+ if (haystack_len < needle_len)
+ return NULL;
+ p = haystack + haystack_len - needle_len;
+
while (p >= haystack)
{
for (i = 0; i < needle_len; i++)
if (p[i] != needle[i])
goto next;
- return (char *)p;
+ return (gchar *)p;
next:
p--;
gint haystack_len,
const gchar *needle)
{
- int i;
-
g_return_val_if_fail (haystack != NULL, NULL);
g_return_val_if_fail (needle != NULL, NULL);
return g_strrstr (haystack, needle);
else
{
- int needle_len = strlen (needle);
- const char *haystack_max = haystack + haystack_len;
- const char *p = haystack;
+ gsize needle_len = strlen (needle);
+ const gchar *haystack_max = haystack + haystack_len;
+ const gchar *p = haystack;
+ gsize i;
while (p < haystack_max && *p)
p++;
+ if (p < haystack + needle_len)
+ return NULL;
+
p -= needle_len;
while (p >= haystack)
if (p[i] != needle[i])
goto next;
- return (char *)p;
+ return (gchar *)p;
next:
p--;
}
- }
- return NULL;
+ return NULL;
+ }
}
gchar **endptr);
G_CONST_RETURN gchar* g_strerror (gint errnum) G_GNUC_CONST;
G_CONST_RETURN gchar* g_strsignal (gint signum) G_GNUC_CONST;
-gint g_strcasecmp (const gchar *s1,
+gint g_strcasecmp (const gchar *s1,
const gchar *s2);
-gint g_strncasecmp (const gchar *s1,
+gint g_strncasecmp (const gchar *s1,
const gchar *s2,
- guint n);
+ gsize n);
gchar* g_strdown (gchar *string);
gchar* g_strup (gchar *string);
gchar* g_strreverse (gchar *string);
const gchar *src,
gsize dest_size);
gchar * g_strstr_len (const gchar *haystack,
- gint haystack_len,
+ gssize haystack_len,
const gchar *needle);
gchar * g_strrstr (const gchar *haystack,
const gchar *needle);
gchar * g_strrstr_len (const gchar *haystack,
- gint haystack_len,
+ gssize haystack_len,
const gchar *needle);
/* removes leading spaces */
gchar* g_strdup_vprintf (const gchar *format,
va_list args);
gchar* g_strndup (const gchar *str,
- guint n);
-gchar* g_strnfill (guint length,
+ gsize n);
+gchar* g_strnfill (gsize length,
gchar fill_char);
gchar* g_strconcat (const gchar *string1,
...); /* NULL terminated */
{
GHashTable *const_table;
GSList *storage_list;
- gint storage_next;
- gint this_size;
- gint default_size;
+ gsize storage_next;
+ gsize this_size;
+ gsize default_size;
};
struct _GRealString
{
gchar *str;
- gint len;
- gint alloc;
+ gsize len;
+ gsize alloc;
};
G_LOCK_DEFINE_STATIC (string_mem_chunk);
return h;
}
+#define MY_MAXSIZE ((gsize)-1)
+
+static inline gsize
+nearest_power (gsize base, gsize num)
+{
+ if (num > MY_MAXSIZE / 2)
+ {
+ return MY_MAXSIZE;
+ }
+ else
+ {
+ gsize n = base;
+
+ while (n < num)
+ n <<= 1;
+
+ return n;
+ }
+}
/* String Chunks.
*/
GStringChunk*
-g_string_chunk_new (gint default_size)
+g_string_chunk_new (gsize default_size)
{
GRealStringChunk *new_chunk = g_new (GRealStringChunk, 1);
- gint size = 1;
+ gsize size = 1;
- while (size < default_size)
- size <<= 1;
+ size = nearest_power (1, default_size);
new_chunk->const_table = NULL;
new_chunk->storage_list = NULL;
const gchar *string)
{
GRealStringChunk *chunk = (GRealStringChunk*) fchunk;
- gint len = strlen (string);
+ gsize len = strlen (string);
char* pos;
g_return_val_if_fail (chunk != NULL, NULL);
if ((chunk->storage_next + len + 1) > chunk->this_size)
{
- gint new_size = chunk->default_size;
-
- while (new_size < len+1)
- new_size <<= 1;
+ gsize new_size = nearest_power (chunk->default_size, len + 1);
chunk->storage_list = g_slist_prepend (chunk->storage_list,
g_new (char, new_size));
/* Strings.
*/
-static inline gint
-nearest_power (gint num)
-{
- gint n = 1;
-
- while (n < num)
- n <<= 1;
-
- return n;
-}
-
static void
-g_string_maybe_expand (GRealString* string, gint len)
+g_string_maybe_expand (GRealString* string,
+ gsize len)
{
if (string->len + len >= string->alloc)
{
- string->alloc = nearest_power (string->len + len + 1);
+ string->alloc = nearest_power (1, string->len + len + 1);
string->str = g_realloc (string->str, string->alloc);
}
}
GString*
-g_string_sized_new (guint dfl_size)
+g_string_sized_new (gsize dfl_size)
{
GRealString *string;
GString*
g_string_new_len (const gchar *init,
- gint len)
+ gssize len)
{
GString *string;
gchar *p, *q;
GRealString *string1 = (GRealString *) v;
GRealString *string2 = (GRealString *) v2;
- gint i = string1->len;
+ gsize i = string1->len;
if (i != string2->len)
return FALSE;
g_string_hash (const GString *str)
{
const gchar *p = str->str;
- gint n = str->len;
+ gsize n = str->len;
guint h = 0;
while (n--)
GString*
g_string_truncate (GString *fstring,
- guint len)
+ gsize len)
{
GRealString *string = (GRealString *) fstring;
GString*
g_string_insert_len (GString *fstring,
- gint pos,
+ gssize pos,
const gchar *val,
- gint len)
+ gssize len)
{
GRealString *string = (GRealString *) fstring;
g_return_val_if_fail (string != NULL, NULL);
g_return_val_if_fail (val != NULL, fstring);
- g_return_val_if_fail (pos <= string->len, fstring);
if (len < 0)
len = strlen (val);
if (pos < 0)
pos = string->len;
+ else
+ g_return_val_if_fail (pos <= string->len, fstring);
g_string_maybe_expand (string, len);
GString*
g_string_append_len (GString *string,
const gchar *val,
- gint len)
+ gssize len)
{
g_return_val_if_fail (string != NULL, NULL);
g_return_val_if_fail (val != NULL, string);
GString*
g_string_prepend_len (GString *string,
const gchar *val,
- gint len)
+ gssize len)
{
g_return_val_if_fail (string != NULL, NULL);
g_return_val_if_fail (val != NULL, string);
GString*
g_string_insert (GString *fstring,
- gint pos,
+ gssize pos,
const gchar *val)
{
g_return_val_if_fail (fstring != NULL, NULL);
g_return_val_if_fail (val != NULL, fstring);
- g_return_val_if_fail (pos <= fstring->len, fstring);
+ if (pos >= 0)
+ g_return_val_if_fail (pos <= fstring->len, fstring);
return g_string_insert_len (fstring, pos, val, -1);
}
GString*
g_string_insert_c (GString *fstring,
- gint pos,
+ gssize pos,
gchar c)
{
GRealString *string = (GRealString *) fstring;
g_return_val_if_fail (string != NULL, NULL);
- g_return_val_if_fail (pos <= string->len, fstring);
g_string_maybe_expand (string, 1);
if (pos < 0)
pos = string->len;
+ else
+ g_return_val_if_fail (pos <= string->len, fstring);
/* If not just an append, move the old stuff */
if (pos < string->len)
GString*
g_string_erase (GString *fstring,
- gint pos,
- gint len)
+ gsize pos,
+ gsize len)
{
GRealString *string = (GRealString*)fstring;
g_return_val_if_fail (string != NULL, NULL);
- g_return_val_if_fail (len >= 0, fstring);
g_return_val_if_fail (pos >= 0, fstring);
g_return_val_if_fail (pos <= string->len, fstring);
- g_return_val_if_fail (pos + len <= string->len, fstring);
- if (pos + len < string->len)
- g_memmove (string->str + pos, string->str + pos + len, string->len - (pos + len));
+ if (len < 0)
+ len = string->len - pos;
+ else
+ {
+ g_return_val_if_fail (pos + len <= string->len, fstring);
+
+ if (pos + len < string->len)
+ g_memmove (string->str + pos, string->str + pos + len, string->len - (pos + len));
+ }
string->len -= len;
{
GRealString *string = (GRealString *) fstring;
guchar *s;
- gint n = string->len;
+ glong n = string->len;
g_return_val_if_fail (string != NULL, NULL);
{
GRealString *string = (GRealString *) fstring;
guchar *s;
- gint n = string->len;
+ glong n = string->len;
g_return_val_if_fail (string != NULL, NULL);
struct _GString
{
- gchar *str;
- gint len;
+ gchar *str;
+ gssize len;
};
/* String Chunks
*/
-GStringChunk* g_string_chunk_new (gint size);
+GStringChunk* g_string_chunk_new (gsize size);
void g_string_chunk_free (GStringChunk *chunk);
gchar* g_string_chunk_insert (GStringChunk *chunk,
const gchar *string);
*/
GString* g_string_new (const gchar *init);
GString* g_string_new_len (const gchar *init,
- gint len);
-GString* g_string_sized_new (guint dfl_size);
+ gssize len);
+GString* g_string_sized_new (gsize dfl_size);
gchar* g_string_free (GString *string,
gboolean free_segment);
gboolean g_string_equal (const GString *v,
GString* g_string_assign (GString *string,
const gchar *rval);
GString* g_string_truncate (GString *string,
- guint len);
+ gsize len);
GString* g_string_insert_len (GString *string,
- gint pos,
+ gssize pos,
const gchar *val,
- gint len);
+ gssize len);
GString* g_string_append (GString *string,
const gchar *val);
GString* g_string_append_len (GString *string,
const gchar *val,
- gint len);
+ gssize len);
GString* g_string_append_c (GString *string,
gchar c);
GString* g_string_prepend (GString *string,
gchar c);
GString* g_string_prepend_len (GString *string,
const gchar *val,
- gint len);
+ gssize len);
GString* g_string_insert (GString *string,
- gint pos,
+ gssize pos,
const gchar *val);
GString* g_string_insert_c (GString *string,
- gint pos,
+ gssize pos,
gchar c);
GString* g_string_erase (GString *string,
- gint pos,
- gint len);
+ gsize pos,
+ gsize len);
GString* g_string_down (GString *string);
GString* g_string_up (GString *string);
void g_string_printf (GString *string,
* in case the locale's charset will be changed later using setlocale()
* or in some other way.
*/
-gboolean g_get_charset (char **charset);
+gboolean g_get_charset (G_CONST_RETURN char **charset);
/* These are all analogs of the <ctype.h> functions.
*/
gunichar g_utf8_get_char (const gchar *p);
gchar* g_utf8_offset_to_pointer (const gchar *str,
- gint offset);
-gint g_utf8_pointer_to_offset (const gchar *str,
+ glong offset);
+glong g_utf8_pointer_to_offset (const gchar *str,
const gchar *pos);
gchar* g_utf8_prev_char (const gchar *p);
gchar* g_utf8_find_next_char (const gchar *p,
gchar* g_utf8_find_prev_char (const gchar *str,
const gchar *p);
-gint g_utf8_strlen (const gchar *p,
- gint max);
+glong g_utf8_strlen (const gchar *p,
+ gssize max);
/* Copies n characters from src to dest */
gchar* g_utf8_strncpy (gchar *dest,
/* Find the UTF-8 character corresponding to ch, in string p. These
functions are equivalants to strchr and strrchr */
gchar* g_utf8_strchr (const gchar *p,
- gint len,
+ gssize len,
gunichar c);
gchar* g_utf8_strrchr (const gchar *p,
- gint len,
+ gssize len,
gunichar c);
gunichar2 *g_utf8_to_utf16 (const gchar *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error);
gunichar * g_utf8_to_ucs4 (const gchar *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error);
gunichar * g_utf8_to_ucs4_fast (const gchar *str,
- gint len,
- gint *items_written);
+ glong len,
+ glong *items_written);
gunichar * g_utf16_to_ucs4 (const gunichar2 *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error);
gchar* g_utf16_to_utf8 (const gunichar2 *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error);
gunichar2 *g_ucs4_to_utf16 (const gunichar *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error);
gchar* g_ucs4_to_utf8 (const gunichar *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error);
/* Convert a single character into UTF-8. outbuf must have at
* result.
*/
gint g_unichar_to_utf8 (gunichar c,
- char *outbuf);
+ gchar *outbuf);
/* Validate a UTF8 string, return TRUE if valid, put pointer to
* first invalid char in **end
*/
gboolean g_utf8_validate (const gchar *str,
- gint max_len,
+ gssize max_len,
const gchar **end);
/* Validate a Unicode character */
*
* Return value: the length of the string in characters
**/
-gint
+glong
g_utf8_strlen (const gchar *p,
- gint max)
+ gssize max)
{
- int len = 0;
+ glong len = 0;
const gchar *start = p;
if (max < 0)
**/
gchar *
g_utf8_offset_to_pointer (const gchar *str,
- gint offset)
+ glong offset)
{
const gchar *s = str;
while (offset--)
*
* Return value: the resulting character offset
**/
-gint
+glong
g_utf8_pointer_to_offset (const gchar *str,
const gchar *pos)
{
const gchar *s = str;
- gint offset = 0;
+ glong offset = 0;
while (s < pos)
{
* Return value: %TRUE if the returned charset is UTF-8
**/
gboolean
-g_get_charset (char **charset)
+g_get_charset (G_CONST_RETURN char **charset)
{
if (utf8_locale_cache != -1)
{
* Return value: number of bytes written
**/
int
-g_unichar_to_utf8 (gunichar c, gchar *outbuf)
+g_unichar_to_utf8 (gunichar c,
+ gchar *outbuf)
{
- size_t len = 0;
+ guint len = 0;
int first;
int i;
**/
gchar *
g_utf8_strchr (const char *p,
- gint p_len,
+ gssize p_len,
gunichar c)
{
gchar ch[10];
**/
gchar *
g_utf8_strrchr (const char *p,
- gint p_len,
+ gssize p_len,
gunichar c)
{
gchar ch[10];
* and return (gunichar)-2 on incomplete trailing character
*/
static inline gunichar
-g_utf8_get_char_extended (const gchar *p, int max_len)
+g_utf8_get_char_extended (const gchar *p, gsize max_len)
{
- gint i, len;
+ guint i, len;
gunichar wc = (guchar) *p;
if (wc < 0x80)
return (gunichar)-1;
}
- if (len == -1)
- return (gunichar)-1;
if (max_len >= 0 && len > max_len)
{
for (i = 1; i < max_len; i++)
**/
gunichar *
g_utf8_to_ucs4_fast (const gchar *str,
- gint len,
- gint *items_written)
+ glong len,
+ glong *items_written)
{
gint j, charlen;
gunichar *result;
**/
gunichar *
g_utf8_to_ucs4 (const gchar *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error)
{
gunichar *result = NULL;
**/
gchar *
g_ucs4_to_utf8 (const gunichar *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error)
{
gint result_length;
**/
gchar *
g_utf16_to_utf8 (const gunichar2 *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error)
{
/* This function and g_utf16_to_ucs4 are almost exactly identical - The lines that differ
**/
gunichar *
g_utf16_to_ucs4 (const gunichar2 *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error)
{
const gunichar2 *in;
**/
gunichar2 *
g_utf8_to_utf16 (const gchar *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error)
{
gunichar2 *result = NULL;
**/
gunichar2 *
g_ucs4_to_utf16 (const gunichar *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error)
{
gunichar2 *result = NULL;
**/
gboolean
g_utf8_validate (const gchar *str,
- gint max_len,
+ gssize max_len,
const gchar **end)
{
gchar*
g_path_get_basename (const gchar *file_name)
{
- register gint base;
- register gint last_nonslash;
- guint len;
+ register gssize base;
+ register gssize last_nonslash;
+ gsize len;
gchar *retval;
g_return_val_if_fail (file_name != NULL, NULL);
-
+
if (file_name[0] == '\0')
/* empty string */
return g_strdup (".");
-
+
last_nonslash = strlen (file_name) - 1;
while (last_nonslash >= 0 && file_name [last_nonslash] == G_DIR_SEPARATOR)
g_path_get_dirname (const gchar *file_name)
{
register gchar *base;
- register guint len;
+ register gsize len;
g_return_val_if_fail (file_name != NULL, NULL);
#ifdef P_tmpdir
if (!g_tmp_dir)
{
- int k;
+ gsize k;
g_tmp_dir = g_strdup (P_tmpdir);
k = strlen (g_tmp_dir);
- if (g_tmp_dir[k-1] == G_DIR_SEPARATOR)
- g_tmp_dir[k-1] = '\0';
+ if (k > 1 && g_tmp_dir[k - 1] == G_DIR_SEPARATOR)
+ g_tmp_dir[k - 1] = '\0';
}
#endif
struct passwd pwd;
# ifdef _SC_GETPW_R_SIZE_MAX
/* This reurns the maximum length */
- guint bufsize = sysconf (_SC_GETPW_R_SIZE_MAX);
+ glong bufsize = sysconf (_SC_GETPW_R_SIZE_MAX);
# else /* _SC_GETPW_R_SIZE_MAX */
- guint bufsize = 64;
+ glong bufsize = 64;
# endif /* _SC_GETPW_R_SIZE_MAX */
gint error;
return list.next;
}
-GList*
+static GList*
g_list_sort_real (GList *list,
GFunc compare_func,
gboolean use_data,
return g_list_sort_real (list, (GFunc) compare_func, TRUE, user_data);
}
-GList*
+static GList*
g_list_sort2 (GList *list,
GCompareFunc compare_func)
{
*/
#define G_N_ELEMENTS(arr) (sizeof (arr) / sizeof ((arr)[0]))
+/* Macros by analogy to GINT_TO_POINTER, GPOINTER_TO_INT
+ */
+#define GPOINTER_TO_SIZE(p) ((gsize) (p))
+#define GSIZE_TO_POINTER(s) ((gpointer) (gsize) (s))
+
/* Provide convenience macros for handling structure
* fields through their offsets.
*/
GMemChunk *poll_chunk;
guint n_poll_records;
GPollFD *cached_poll_array;
- gint cached_poll_array_size;
+ guint cached_poll_array_size;
#ifdef G_THREADS_ENABLED
#ifndef G_OS_WIN32
static void
g_main_dispatch (GMainContext *context)
{
- gint i;
+ guint i;
for (i = 0; i < context->pending_dispatches->len; i++)
{
g_timeout_prepare (GSource *source,
gint *timeout)
{
+ glong sec;
glong msec;
GTimeVal current_time;
GTimeoutSource *timeout_source = (GTimeoutSource *)source;
g_source_get_current_time (source, ¤t_time);
-
- msec = ((timeout_source->expiration.tv_sec - current_time.tv_sec) * 1000 +
- (timeout_source->expiration.tv_usec - current_time.tv_usec) / 1000);
- if (msec < 0)
+ sec = timeout_source->expiration.tv_sec - current_time.tv_sec;
+ msec = (timeout_source->expiration.tv_usec - current_time.tv_usec) / 1000;
+
+ /* We do the following in a rather convoluted fashion to deal with
+ * the fact that we don't have an integral type big enough to hold
+ * the difference of two timevals in millseconds.
+ */
+ if (sec < 0 || (sec == 0 && msec < 0))
msec = 0;
- else if (msec > timeout_source->interval)
+ else
{
- /* The system time has been set backwards, so we
- * reset the expiration time to now + timeout_source->interval;
- * this at least avoids hanging for long periods of time.
- */
- g_timeout_set_expiration (timeout_source, ¤t_time);
- msec = timeout_source->interval;
+ glong interval_sec = timeout_source->interval / 1000;
+ glong interval_msec = timeout_source->interval % 1000;
+
+ if (msec < 0)
+ {
+ msec += 1000;
+ sec -= 1;
+ }
+
+ if (sec > interval_sec ||
+ (sec == interval_sec && msec > interval_msec))
+ {
+ /* The system time has been set backwards, so we
+ * reset the expiration time to now + timeout_source->interval;
+ * this at least avoids hanging for long periods of time.
+ */
+ g_timeout_set_expiration (timeout_source, ¤t_time);
+ msec = timeout_source->interval;
+ }
+ else
+ {
+ msec += sec * 1000;
+ }
}
-
- *timeout = msec;
+
+ *timeout = (gint)msec;
return msec == 0;
}
gint alloc_attrs;
const gchar *current_text;
- gint current_text_len;
+ gssize current_text_len;
const gchar *current_text_end;
GString *leftover_char_portion;
(l >= 0x10000 && l <= 0x10FFFF))
{
gchar buf[7];
- g_string_append (str,
- char_str (l, buf));
+ g_string_append (str, char_str (l, buf));
}
else
{
gboolean
g_markup_parse_context_parse (GMarkupParseContext *context,
const gchar *text,
- gint text_len,
+ gssize text_len,
GError **error)
{
const gchar *first_invalid;
static void
append_escaped_text (GString *str,
const gchar *text,
- gint length)
+ gssize length)
{
const gchar *p;
const gchar *end;
**/
gchar*
g_markup_escape_text (const gchar *text,
- gint length)
+ gssize length)
{
GString *str;
/* text is not nul-terminated */
void (*text) (GMarkupParseContext *context,
const gchar *text,
- gint text_len,
+ gsize text_len,
gpointer user_data,
GError **error);
/* text is not nul-terminated. */
void (*passthrough) (GMarkupParseContext *context,
const gchar *passthrough_text,
- gint text_len,
+ gsize text_len,
gpointer user_data,
GError **error);
void g_markup_parse_context_free (GMarkupParseContext *context);
gboolean g_markup_parse_context_parse (GMarkupParseContext *context,
const gchar *text,
- gint text_len,
+ gssize text_len,
GError **error);
gboolean g_markup_parse_context_end_parse (GMarkupParseContext *context,
/* useful when saving */
gchar* g_markup_escape_text (const gchar *text,
- gint length);
+ gssize length);
G_END_DECLS
/* --- prototypes --- */
-static inline guint printf_string_upper_bound (const gchar *format,
- gboolean may_warn,
- va_list args);
+static guint printf_string_upper_bound (const gchar *format,
+ gboolean may_warn,
+ va_list args);
/* --- variables --- */
#endif
static void
-write_unsigned (GFileDescriptor fd,
- gulong num,
- guint radix)
+write_unsigned (GFileDescriptor fd,
+ gulong num,
+ guint radix)
{
char buffer[64];
gulong tmp;
gboolean mod_half, mod_long, mod_extra_long;
} PrintfArgSpec;
-static inline guint
+static gsize
printf_string_upper_bound (const gchar *format,
gboolean may_warn,
va_list args)
{
static const gboolean honour_longs = SIZEOF_LONG > 4 || SIZEOF_VOID_P > 4;
- guint len = 1;
+ gsize len = 1;
if (!format)
return len;
{
PrintfArgSpec spec = { 0, };
gboolean seen_l = FALSE, conv_done = FALSE;
- guint conv_len = 0;
+ gsize conv_len = 0;
const gchar *spec_start = format;
do
return len;
}
-guint
+gsize
g_printf_string_upper_bound (const gchar *format,
va_list args)
{
/* calculate a string size, guarranteed to fit format + args.
*/
-guint g_printf_string_upper_bound (const gchar* format,
+gsize g_printf_string_upper_bound (const gchar* format,
va_list args);
/* Log level shift offset for user defined
+2001-05-21 Mark Murnane <Mark.Murnane@ireland.sun.com>
+
+ * gmodule.c (g_str_check_suffix): Modified type of string_len
+ and suffix_len to be gsize. Properly accommodates return from
+ strlen().
+
2001-05-29 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* gmodule.c (g_module_set_error_unduped): Do not g_strdup, as
str_check_suffix (const gchar* string,
const gchar* suffix)
{
- guint string_len = strlen (string);
- guint suffix_len = strlen (suffix);
+ gsize string_len = strlen (string);
+ gsize suffix_len = strlen (suffix);
return string_len >= suffix_len &&
strcmp (string + string_len - suffix_len, suffix) == 0;
gint fd,
GError **error)
{
- gint bytes;
- gchar buf[4096];
+ gssize bytes;
+ gchar buf[4096];
again:
static gboolean
read_ints (int fd,
gint* buf,
- gint n_ints_in_buf,
- gint *n_ints_read,
+ gint n_ints_in_buf,
+ gint *n_ints_read,
GError **error)
{
- gint bytes = 0;
+ gsize bytes = 0;
while (TRUE)
{
- gint chunk;
+ gssize chunk;
if (bytes >= sizeof(gint)*2)
break; /* give up, who knows what happened, should not be
again:
chunk = read (fd,
((gchar*)buf) + bytes,
- sizeof(gint)*n_ints_in_buf - bytes);
+ sizeof(gint) * n_ints_in_buf - bytes);
if (chunk < 0 && errno == EINTR)
goto again;
}
else if (chunk == 0)
break; /* EOF */
- else
- {
- g_assert (chunk > 0);
-
- bytes += chunk;
- }
+ else /* chunk > 0 */
+ bytes += chunk;
}
- *n_ints_read = bytes/4;
+ *n_ints_read = (gint)(bytes / sizeof(gint));
return TRUE;
}
/* Parent */
gint buf[2];
- gint n_ints = 0;
+ gint n_ints = 0;
/* Close the uncared-about ends of the pipes */
close_and_invalidate (&child_err_report_pipe[1]);
gchar*
g_strndup (const gchar *str,
- guint n)
+ gsize n)
{
gchar *new_str;
}
gchar*
-g_strnfill (guint length,
+g_strnfill (gsize length,
gchar fill_char)
{
register gchar *str, *s, *end;
gchar*
g_strconcat (const gchar *string1, ...)
{
- guint l;
+ gsize l;
va_list args;
gchar *s;
gchar *concat;
gint
g_strncasecmp (const gchar *s1,
const gchar *s2,
- guint n)
+ gsize n)
{
#ifdef HAVE_STRNCASECMP
return strncasecmp (s1, s2, n);
s = strstr (string, delimiter);
if (s)
{
- guint delimiter_len = strlen (delimiter);
+ gsize delimiter_len = strlen (delimiter);
do
{
- guint len;
+ gsize len;
gchar *new_string;
len = s - string;
if (*str_array)
{
- guint i, len;
- guint separator_len;
+ gint i;
+ gsize len;
+ gsize separator_len;
separator_len = strlen (separator);
/* First part, getting length */
{
gchar *string, *s;
va_list args;
- guint len;
- guint separator_len;
+ gsize len;
+ gsize separator_len;
gchar *ptr;
if (separator == NULL)
**/
gchar *
g_strstr_len (const gchar *haystack,
- gint haystack_len,
+ gssize haystack_len,
const gchar *needle)
{
- int i;
-
g_return_val_if_fail (haystack != NULL, NULL);
g_return_val_if_fail (needle != NULL, NULL);
return strstr (haystack, needle);
else
{
- const char *p = haystack;
- int needle_len = strlen (needle);
- const char *end = haystack + haystack_len - needle_len;
-
+ const gchar *p = haystack;
+ gsize needle_len = strlen (needle);
+ const gchar *end;
+ gsize i;
+
if (needle_len == 0)
- return (char *)haystack;
+ return (gchar *)haystack;
+ if (haystack_len < needle_len)
+ return NULL;
+
+ end = haystack + haystack_len - needle_len;
+
while (*p && p <= end)
{
for (i = 0; i < needle_len; i++)
if (p[i] != needle[i])
goto next;
- return (char *)p;
+ return (gchar *)p;
next:
p++;
}
+
+ return NULL;
}
-
- return NULL;
}
/**
g_strrstr (const gchar *haystack,
const gchar *needle)
{
- int i;
- int needle_len = strlen (needle);
- int haystack_len = strlen (haystack);
- const char *p = haystack + haystack_len - needle_len;
+ gsize i;
+ gsize needle_len;
+ gsize haystack_len;
+ const gchar *p;
g_return_val_if_fail (haystack != NULL, NULL);
g_return_val_if_fail (needle != NULL, NULL);
-
+
+ needle_len = strlen (needle);
+ haystack_len = strlen (haystack);
+
if (needle_len == 0)
- return (char *)p;
+ return (gchar *)haystack;
+
+ if (haystack_len < needle_len)
+ return NULL;
+ p = haystack + haystack_len - needle_len;
+
while (p >= haystack)
{
for (i = 0; i < needle_len; i++)
if (p[i] != needle[i])
goto next;
- return (char *)p;
+ return (gchar *)p;
next:
p--;
gint haystack_len,
const gchar *needle)
{
- int i;
-
g_return_val_if_fail (haystack != NULL, NULL);
g_return_val_if_fail (needle != NULL, NULL);
return g_strrstr (haystack, needle);
else
{
- int needle_len = strlen (needle);
- const char *haystack_max = haystack + haystack_len;
- const char *p = haystack;
+ gsize needle_len = strlen (needle);
+ const gchar *haystack_max = haystack + haystack_len;
+ const gchar *p = haystack;
+ gsize i;
while (p < haystack_max && *p)
p++;
+ if (p < haystack + needle_len)
+ return NULL;
+
p -= needle_len;
while (p >= haystack)
if (p[i] != needle[i])
goto next;
- return (char *)p;
+ return (gchar *)p;
next:
p--;
}
- }
- return NULL;
+ return NULL;
+ }
}
gchar **endptr);
G_CONST_RETURN gchar* g_strerror (gint errnum) G_GNUC_CONST;
G_CONST_RETURN gchar* g_strsignal (gint signum) G_GNUC_CONST;
-gint g_strcasecmp (const gchar *s1,
+gint g_strcasecmp (const gchar *s1,
const gchar *s2);
-gint g_strncasecmp (const gchar *s1,
+gint g_strncasecmp (const gchar *s1,
const gchar *s2,
- guint n);
+ gsize n);
gchar* g_strdown (gchar *string);
gchar* g_strup (gchar *string);
gchar* g_strreverse (gchar *string);
const gchar *src,
gsize dest_size);
gchar * g_strstr_len (const gchar *haystack,
- gint haystack_len,
+ gssize haystack_len,
const gchar *needle);
gchar * g_strrstr (const gchar *haystack,
const gchar *needle);
gchar * g_strrstr_len (const gchar *haystack,
- gint haystack_len,
+ gssize haystack_len,
const gchar *needle);
/* removes leading spaces */
gchar* g_strdup_vprintf (const gchar *format,
va_list args);
gchar* g_strndup (const gchar *str,
- guint n);
-gchar* g_strnfill (guint length,
+ gsize n);
+gchar* g_strnfill (gsize length,
gchar fill_char);
gchar* g_strconcat (const gchar *string1,
...); /* NULL terminated */
{
GHashTable *const_table;
GSList *storage_list;
- gint storage_next;
- gint this_size;
- gint default_size;
+ gsize storage_next;
+ gsize this_size;
+ gsize default_size;
};
struct _GRealString
{
gchar *str;
- gint len;
- gint alloc;
+ gsize len;
+ gsize alloc;
};
G_LOCK_DEFINE_STATIC (string_mem_chunk);
return h;
}
+#define MY_MAXSIZE ((gsize)-1)
+
+static inline gsize
+nearest_power (gsize base, gsize num)
+{
+ if (num > MY_MAXSIZE / 2)
+ {
+ return MY_MAXSIZE;
+ }
+ else
+ {
+ gsize n = base;
+
+ while (n < num)
+ n <<= 1;
+
+ return n;
+ }
+}
/* String Chunks.
*/
GStringChunk*
-g_string_chunk_new (gint default_size)
+g_string_chunk_new (gsize default_size)
{
GRealStringChunk *new_chunk = g_new (GRealStringChunk, 1);
- gint size = 1;
+ gsize size = 1;
- while (size < default_size)
- size <<= 1;
+ size = nearest_power (1, default_size);
new_chunk->const_table = NULL;
new_chunk->storage_list = NULL;
const gchar *string)
{
GRealStringChunk *chunk = (GRealStringChunk*) fchunk;
- gint len = strlen (string);
+ gsize len = strlen (string);
char* pos;
g_return_val_if_fail (chunk != NULL, NULL);
if ((chunk->storage_next + len + 1) > chunk->this_size)
{
- gint new_size = chunk->default_size;
-
- while (new_size < len+1)
- new_size <<= 1;
+ gsize new_size = nearest_power (chunk->default_size, len + 1);
chunk->storage_list = g_slist_prepend (chunk->storage_list,
g_new (char, new_size));
/* Strings.
*/
-static inline gint
-nearest_power (gint num)
-{
- gint n = 1;
-
- while (n < num)
- n <<= 1;
-
- return n;
-}
-
static void
-g_string_maybe_expand (GRealString* string, gint len)
+g_string_maybe_expand (GRealString* string,
+ gsize len)
{
if (string->len + len >= string->alloc)
{
- string->alloc = nearest_power (string->len + len + 1);
+ string->alloc = nearest_power (1, string->len + len + 1);
string->str = g_realloc (string->str, string->alloc);
}
}
GString*
-g_string_sized_new (guint dfl_size)
+g_string_sized_new (gsize dfl_size)
{
GRealString *string;
GString*
g_string_new_len (const gchar *init,
- gint len)
+ gssize len)
{
GString *string;
gchar *p, *q;
GRealString *string1 = (GRealString *) v;
GRealString *string2 = (GRealString *) v2;
- gint i = string1->len;
+ gsize i = string1->len;
if (i != string2->len)
return FALSE;
g_string_hash (const GString *str)
{
const gchar *p = str->str;
- gint n = str->len;
+ gsize n = str->len;
guint h = 0;
while (n--)
GString*
g_string_truncate (GString *fstring,
- guint len)
+ gsize len)
{
GRealString *string = (GRealString *) fstring;
GString*
g_string_insert_len (GString *fstring,
- gint pos,
+ gssize pos,
const gchar *val,
- gint len)
+ gssize len)
{
GRealString *string = (GRealString *) fstring;
g_return_val_if_fail (string != NULL, NULL);
g_return_val_if_fail (val != NULL, fstring);
- g_return_val_if_fail (pos <= string->len, fstring);
if (len < 0)
len = strlen (val);
if (pos < 0)
pos = string->len;
+ else
+ g_return_val_if_fail (pos <= string->len, fstring);
g_string_maybe_expand (string, len);
GString*
g_string_append_len (GString *string,
const gchar *val,
- gint len)
+ gssize len)
{
g_return_val_if_fail (string != NULL, NULL);
g_return_val_if_fail (val != NULL, string);
GString*
g_string_prepend_len (GString *string,
const gchar *val,
- gint len)
+ gssize len)
{
g_return_val_if_fail (string != NULL, NULL);
g_return_val_if_fail (val != NULL, string);
GString*
g_string_insert (GString *fstring,
- gint pos,
+ gssize pos,
const gchar *val)
{
g_return_val_if_fail (fstring != NULL, NULL);
g_return_val_if_fail (val != NULL, fstring);
- g_return_val_if_fail (pos <= fstring->len, fstring);
+ if (pos >= 0)
+ g_return_val_if_fail (pos <= fstring->len, fstring);
return g_string_insert_len (fstring, pos, val, -1);
}
GString*
g_string_insert_c (GString *fstring,
- gint pos,
+ gssize pos,
gchar c)
{
GRealString *string = (GRealString *) fstring;
g_return_val_if_fail (string != NULL, NULL);
- g_return_val_if_fail (pos <= string->len, fstring);
g_string_maybe_expand (string, 1);
if (pos < 0)
pos = string->len;
+ else
+ g_return_val_if_fail (pos <= string->len, fstring);
/* If not just an append, move the old stuff */
if (pos < string->len)
GString*
g_string_erase (GString *fstring,
- gint pos,
- gint len)
+ gsize pos,
+ gsize len)
{
GRealString *string = (GRealString*)fstring;
g_return_val_if_fail (string != NULL, NULL);
- g_return_val_if_fail (len >= 0, fstring);
g_return_val_if_fail (pos >= 0, fstring);
g_return_val_if_fail (pos <= string->len, fstring);
- g_return_val_if_fail (pos + len <= string->len, fstring);
- if (pos + len < string->len)
- g_memmove (string->str + pos, string->str + pos + len, string->len - (pos + len));
+ if (len < 0)
+ len = string->len - pos;
+ else
+ {
+ g_return_val_if_fail (pos + len <= string->len, fstring);
+
+ if (pos + len < string->len)
+ g_memmove (string->str + pos, string->str + pos + len, string->len - (pos + len));
+ }
string->len -= len;
{
GRealString *string = (GRealString *) fstring;
guchar *s;
- gint n = string->len;
+ glong n = string->len;
g_return_val_if_fail (string != NULL, NULL);
{
GRealString *string = (GRealString *) fstring;
guchar *s;
- gint n = string->len;
+ glong n = string->len;
g_return_val_if_fail (string != NULL, NULL);
struct _GString
{
- gchar *str;
- gint len;
+ gchar *str;
+ gssize len;
};
/* String Chunks
*/
-GStringChunk* g_string_chunk_new (gint size);
+GStringChunk* g_string_chunk_new (gsize size);
void g_string_chunk_free (GStringChunk *chunk);
gchar* g_string_chunk_insert (GStringChunk *chunk,
const gchar *string);
*/
GString* g_string_new (const gchar *init);
GString* g_string_new_len (const gchar *init,
- gint len);
-GString* g_string_sized_new (guint dfl_size);
+ gssize len);
+GString* g_string_sized_new (gsize dfl_size);
gchar* g_string_free (GString *string,
gboolean free_segment);
gboolean g_string_equal (const GString *v,
GString* g_string_assign (GString *string,
const gchar *rval);
GString* g_string_truncate (GString *string,
- guint len);
+ gsize len);
GString* g_string_insert_len (GString *string,
- gint pos,
+ gssize pos,
const gchar *val,
- gint len);
+ gssize len);
GString* g_string_append (GString *string,
const gchar *val);
GString* g_string_append_len (GString *string,
const gchar *val,
- gint len);
+ gssize len);
GString* g_string_append_c (GString *string,
gchar c);
GString* g_string_prepend (GString *string,
gchar c);
GString* g_string_prepend_len (GString *string,
const gchar *val,
- gint len);
+ gssize len);
GString* g_string_insert (GString *string,
- gint pos,
+ gssize pos,
const gchar *val);
GString* g_string_insert_c (GString *string,
- gint pos,
+ gssize pos,
gchar c);
GString* g_string_erase (GString *string,
- gint pos,
- gint len);
+ gsize pos,
+ gsize len);
GString* g_string_down (GString *string);
GString* g_string_up (GString *string);
void g_string_printf (GString *string,
* in case the locale's charset will be changed later using setlocale()
* or in some other way.
*/
-gboolean g_get_charset (char **charset);
+gboolean g_get_charset (G_CONST_RETURN char **charset);
/* These are all analogs of the <ctype.h> functions.
*/
gunichar g_utf8_get_char (const gchar *p);
gchar* g_utf8_offset_to_pointer (const gchar *str,
- gint offset);
-gint g_utf8_pointer_to_offset (const gchar *str,
+ glong offset);
+glong g_utf8_pointer_to_offset (const gchar *str,
const gchar *pos);
gchar* g_utf8_prev_char (const gchar *p);
gchar* g_utf8_find_next_char (const gchar *p,
gchar* g_utf8_find_prev_char (const gchar *str,
const gchar *p);
-gint g_utf8_strlen (const gchar *p,
- gint max);
+glong g_utf8_strlen (const gchar *p,
+ gssize max);
/* Copies n characters from src to dest */
gchar* g_utf8_strncpy (gchar *dest,
/* Find the UTF-8 character corresponding to ch, in string p. These
functions are equivalants to strchr and strrchr */
gchar* g_utf8_strchr (const gchar *p,
- gint len,
+ gssize len,
gunichar c);
gchar* g_utf8_strrchr (const gchar *p,
- gint len,
+ gssize len,
gunichar c);
gunichar2 *g_utf8_to_utf16 (const gchar *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error);
gunichar * g_utf8_to_ucs4 (const gchar *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error);
gunichar * g_utf8_to_ucs4_fast (const gchar *str,
- gint len,
- gint *items_written);
+ glong len,
+ glong *items_written);
gunichar * g_utf16_to_ucs4 (const gunichar2 *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error);
gchar* g_utf16_to_utf8 (const gunichar2 *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error);
gunichar2 *g_ucs4_to_utf16 (const gunichar *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error);
gchar* g_ucs4_to_utf8 (const gunichar *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error);
/* Convert a single character into UTF-8. outbuf must have at
* result.
*/
gint g_unichar_to_utf8 (gunichar c,
- char *outbuf);
+ gchar *outbuf);
/* Validate a UTF8 string, return TRUE if valid, put pointer to
* first invalid char in **end
*/
gboolean g_utf8_validate (const gchar *str,
- gint max_len,
+ gssize max_len,
const gchar **end);
/* Validate a Unicode character */
*
* Return value: the length of the string in characters
**/
-gint
+glong
g_utf8_strlen (const gchar *p,
- gint max)
+ gssize max)
{
- int len = 0;
+ glong len = 0;
const gchar *start = p;
if (max < 0)
**/
gchar *
g_utf8_offset_to_pointer (const gchar *str,
- gint offset)
+ glong offset)
{
const gchar *s = str;
while (offset--)
*
* Return value: the resulting character offset
**/
-gint
+glong
g_utf8_pointer_to_offset (const gchar *str,
const gchar *pos)
{
const gchar *s = str;
- gint offset = 0;
+ glong offset = 0;
while (s < pos)
{
* Return value: %TRUE if the returned charset is UTF-8
**/
gboolean
-g_get_charset (char **charset)
+g_get_charset (G_CONST_RETURN char **charset)
{
if (utf8_locale_cache != -1)
{
* Return value: number of bytes written
**/
int
-g_unichar_to_utf8 (gunichar c, gchar *outbuf)
+g_unichar_to_utf8 (gunichar c,
+ gchar *outbuf)
{
- size_t len = 0;
+ guint len = 0;
int first;
int i;
**/
gchar *
g_utf8_strchr (const char *p,
- gint p_len,
+ gssize p_len,
gunichar c)
{
gchar ch[10];
**/
gchar *
g_utf8_strrchr (const char *p,
- gint p_len,
+ gssize p_len,
gunichar c)
{
gchar ch[10];
* and return (gunichar)-2 on incomplete trailing character
*/
static inline gunichar
-g_utf8_get_char_extended (const gchar *p, int max_len)
+g_utf8_get_char_extended (const gchar *p, gsize max_len)
{
- gint i, len;
+ guint i, len;
gunichar wc = (guchar) *p;
if (wc < 0x80)
return (gunichar)-1;
}
- if (len == -1)
- return (gunichar)-1;
if (max_len >= 0 && len > max_len)
{
for (i = 1; i < max_len; i++)
**/
gunichar *
g_utf8_to_ucs4_fast (const gchar *str,
- gint len,
- gint *items_written)
+ glong len,
+ glong *items_written)
{
gint j, charlen;
gunichar *result;
**/
gunichar *
g_utf8_to_ucs4 (const gchar *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error)
{
gunichar *result = NULL;
**/
gchar *
g_ucs4_to_utf8 (const gunichar *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error)
{
gint result_length;
**/
gchar *
g_utf16_to_utf8 (const gunichar2 *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error)
{
/* This function and g_utf16_to_ucs4 are almost exactly identical - The lines that differ
**/
gunichar *
g_utf16_to_ucs4 (const gunichar2 *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error)
{
const gunichar2 *in;
**/
gunichar2 *
g_utf8_to_utf16 (const gchar *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error)
{
gunichar2 *result = NULL;
**/
gunichar2 *
g_ucs4_to_utf16 (const gunichar *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error)
{
gunichar2 *result = NULL;
**/
gboolean
g_utf8_validate (const gchar *str,
- gint max_len,
+ gssize max_len,
const gchar **end)
{
gchar*
g_path_get_basename (const gchar *file_name)
{
- register gint base;
- register gint last_nonslash;
- guint len;
+ register gssize base;
+ register gssize last_nonslash;
+ gsize len;
gchar *retval;
g_return_val_if_fail (file_name != NULL, NULL);
-
+
if (file_name[0] == '\0')
/* empty string */
return g_strdup (".");
-
+
last_nonslash = strlen (file_name) - 1;
while (last_nonslash >= 0 && file_name [last_nonslash] == G_DIR_SEPARATOR)
g_path_get_dirname (const gchar *file_name)
{
register gchar *base;
- register guint len;
+ register gsize len;
g_return_val_if_fail (file_name != NULL, NULL);
#ifdef P_tmpdir
if (!g_tmp_dir)
{
- int k;
+ gsize k;
g_tmp_dir = g_strdup (P_tmpdir);
k = strlen (g_tmp_dir);
- if (g_tmp_dir[k-1] == G_DIR_SEPARATOR)
- g_tmp_dir[k-1] = '\0';
+ if (k > 1 && g_tmp_dir[k - 1] == G_DIR_SEPARATOR)
+ g_tmp_dir[k - 1] = '\0';
}
#endif
struct passwd pwd;
# ifdef _SC_GETPW_R_SIZE_MAX
/* This reurns the maximum length */
- guint bufsize = sysconf (_SC_GETPW_R_SIZE_MAX);
+ glong bufsize = sysconf (_SC_GETPW_R_SIZE_MAX);
# else /* _SC_GETPW_R_SIZE_MAX */
- guint bufsize = 64;
+ glong bufsize = 64;
# endif /* _SC_GETPW_R_SIZE_MAX */
gint error;
static void
text_handler (GMarkupParseContext *context,
const gchar *text,
- gint text_len,
+ gsize text_len,
gpointer user_data,
GError **error)
{
static void
passthrough_handler (GMarkupParseContext *context,
const gchar *passthrough_text,
- gint text_len,
+ gsize text_len,
gpointer user_data,
GError **error)
{
*/
#include <gmodule.h>
+#include <string.h>
gchar* global_state;
int
read_all (int fd, char *buf, int len)
{
- int bytes_read = 0;
- int count;
+ size_t bytes_read = 0;
+ ssize_t count;
while (bytes_read < len)
{
int
write_all (int fd, char *buf, int len)
{
- int bytes_written = 0;
- int count;
+ size_t bytes_written = 0;
+ ssize_t count;
while (bytes_written < len)
{
static int n_iters = 10000;
static GMainLoop *loop;
-void
+static void
io_pipe (GIOChannel **channels)
{
int fds[2];
channels[1] = g_io_channel_unix_new (fds[1]);
}
-gboolean
+static gboolean
read_all (GIOChannel *channel, char *buf, int len)
{
- int bytes_read = 0;
- int count;
+ gsize bytes_read = 0;
+ gsize count;
GIOError err;
while (bytes_read < len)
return TRUE;
}
-gboolean
+static gboolean
write_all (GIOChannel *channel, char *buf, int len)
{
- int bytes_written = 0;
- int count;
+ gsize bytes_written = 0;
+ gsize count;
GIOError err;
while (bytes_written < len)
return TRUE;
}
-void
+static void
run_child (GIOChannel *in_channel, GIOChannel *out_channel)
{
int i;
exit (0);
}
-gboolean
+static gboolean
input_callback (GIOChannel *source,
GIOCondition condition,
gpointer data)
}
}
-void
+static void
create_child ()
{
int pid;
static gint exit_status = 0;
-void
+static void
croak (char *format, ...)
{
va_list va;
exit (1);
}
-void
+static void
fail (char *format, ...)
{
va_list va;
const gchar *end;
gboolean is_valid = g_utf8_validate (utf8, -1, &end);
GError *error = NULL;
- gint items_read, items_written;
+ glong items_read, items_written;
switch (status)
{
gunichar2 *utf16_from_utf8;
gunichar2 *utf16_from_ucs4;
gunichar *ucs4_result;
- gint bytes_written;
+ gsize bytes_written;
gint n_chars;
gchar *utf8_result;
int
read_all (int fd, char *buf, int len)
{
- int bytes_read = 0;
- int count;
+ size_t bytes_read = 0;
+ ssize_t count;
while (bytes_read < len)
{
int
write_all (int fd, char *buf, int len)
{
- int bytes_written = 0;
- int count;
+ size_t bytes_written = 0;
+ ssize_t count;
while (bytes_written < len)
{
static int n_iters = 10000;
static GMainLoop *loop;
-void
+static void
io_pipe (GIOChannel **channels)
{
int fds[2];
channels[1] = g_io_channel_unix_new (fds[1]);
}
-gboolean
+static gboolean
read_all (GIOChannel *channel, char *buf, int len)
{
- int bytes_read = 0;
- int count;
+ gsize bytes_read = 0;
+ gsize count;
GIOError err;
while (bytes_read < len)
return TRUE;
}
-gboolean
+static gboolean
write_all (GIOChannel *channel, char *buf, int len)
{
- int bytes_written = 0;
- int count;
+ gsize bytes_written = 0;
+ gsize count;
GIOError err;
while (bytes_written < len)
return TRUE;
}
-void
+static void
run_child (GIOChannel *in_channel, GIOChannel *out_channel)
{
int i;
exit (0);
}
-gboolean
+static gboolean
input_callback (GIOChannel *source,
GIOCondition condition,
gpointer data)
}
}
-void
+static void
create_child ()
{
int pid;