+2001-12-16 Havoc Pennington <hp@pobox.com>
+
+ * glib/gfileutils.c (get_contents_regfile): use g_try_malloc and
+ return error on not-enough-memory
+ (get_contents_stdio): ditto
+
2001-12-17 Matthias Clasen <matthiasc@poet.de>
* glib/gspawn.c, glib/gspawn-win32.c: Use <envar>, not <envvar>.
+2001-12-16 Havoc Pennington <hp@pobox.com>
+
+ * glib/gfileutils.c (get_contents_regfile): use g_try_malloc and
+ return error on not-enough-memory
+ (get_contents_stdio): ditto
+
2001-12-17 Matthias Clasen <matthiasc@poet.de>
* glib/gspawn.c, glib/gspawn-win32.c: Use <envar>, not <envvar>.
+2001-12-16 Havoc Pennington <hp@pobox.com>
+
+ * glib/gfileutils.c (get_contents_regfile): use g_try_malloc and
+ return error on not-enough-memory
+ (get_contents_stdio): ditto
+
2001-12-17 Matthias Clasen <matthiasc@poet.de>
* glib/gspawn.c, glib/gspawn-win32.c: Use <envar>, not <envvar>.
+2001-12-16 Havoc Pennington <hp@pobox.com>
+
+ * glib/gfileutils.c (get_contents_regfile): use g_try_malloc and
+ return error on not-enough-memory
+ (get_contents_stdio): ditto
+
2001-12-17 Matthias Clasen <matthiasc@poet.de>
* glib/gspawn.c, glib/gspawn-win32.c: Use <envar>, not <envvar>.
+2001-12-16 Havoc Pennington <hp@pobox.com>
+
+ * glib/gfileutils.c (get_contents_regfile): use g_try_malloc and
+ return error on not-enough-memory
+ (get_contents_stdio): ditto
+
2001-12-17 Matthias Clasen <matthiasc@poet.de>
* glib/gspawn.c, glib/gspawn-win32.c: Use <envar>, not <envvar>.
+2001-12-16 Havoc Pennington <hp@pobox.com>
+
+ * glib/gfileutils.c (get_contents_regfile): use g_try_malloc and
+ return error on not-enough-memory
+ (get_contents_stdio): ditto
+
2001-12-17 Matthias Clasen <matthiasc@poet.de>
* glib/gspawn.c, glib/gspawn-win32.c: Use <envar>, not <envvar>.
+2001-12-16 Havoc Pennington <hp@pobox.com>
+
+ * glib/gfileutils.c (get_contents_regfile): use g_try_malloc and
+ return error on not-enough-memory
+ (get_contents_stdio): ditto
+
2001-12-17 Matthias Clasen <matthiasc@poet.de>
* glib/gspawn.c, glib/gspawn-win32.c: Use <envar>, not <envvar>.
+2001-12-16 Havoc Pennington <hp@pobox.com>
+
+ * glib/gfileutils.c (get_contents_regfile): use g_try_malloc and
+ return error on not-enough-memory
+ (get_contents_stdio): ditto
+
2001-12-17 Matthias Clasen <matthiasc@poet.de>
* glib/gspawn.c, glib/gspawn-win32.c: Use <envar>, not <envvar>.
@parent_instance:
+<!-- ##### ENUM GTypeFundamentals ##### -->
+<para>
+The predefined identifiers of the reserved fundamental types.
+</para>
+
+@G_TYPE_INVALID: Usually a return value indicating an error.
+@G_TYPE_NONE: A synonym for the "void" type in C.
+@G_TYPE_INTERFACE: Root type of all interface types.
+@G_TYPE_CHAR: Identifier for the built-in type "gchar".
+@G_TYPE_UCHAR: Identifier for the built-in type "guchar".
+@G_TYPE_BOOLEAN: Identifier for the built-in type "gboolean".
+@G_TYPE_INT: Identifier for the built-in type "gint".
+@G_TYPE_UINT: Identifier for the built-in type "guint".
+@G_TYPE_LONG: Identifier for the built-in type "glong".
+@G_TYPE_ULONG: Identifier for the built-in type "gulong".
+@G_TYPE_INT64:
+@G_TYPE_UINT64:
+@G_TYPE_ENUM: Identifier for the "#GEnum" type.
+@G_TYPE_FLAGS: Identifier for the "#GFlags" type.
+@G_TYPE_FLOAT: Identifier for the built-in type "gfloat".
+@G_TYPE_DOUBLE: Identifier for the built-in type "gdouble".
+@G_TYPE_STRING: Identifier for a pointer to a null-terminated string "gchar*".
+@G_TYPE_POINTER: Identifier for anonymous pointers "void*".
+@G_TYPE_BOXED: Identifier for the "#GBoxed" type.
+@G_TYPE_PARAM: Identifier for the "#GParam" type.
+@G_TYPE_OBJECT: Identifier for the "#GObject" type.
+@G_TYPE_RESERVED_BSE_FIRST: First fundamental type ID reserved for BSE.
+@G_TYPE_RESERVED_BSE_LAST: Last fundamental type ID reserved for BSE.
+@G_TYPE_RESERVED_LAST_FUNDAMENTAL:
+@G_TYPE_CONSTANT_TYPES:
+@G_TYPE_CLOSURE:
+@G_TYPE_VALUE:
+@G_TYPE_VALUE_ARRAY:
+@G_TYPE_GSTRING:
+@G_TYPE_PARAM_CHAR:
+@G_TYPE_PARAM_UCHAR:
+@G_TYPE_PARAM_BOOLEAN:
+@G_TYPE_PARAM_INT:
+@G_TYPE_PARAM_UINT:
+@G_TYPE_PARAM_LONG:
+@G_TYPE_PARAM_ULONG:
+@G_TYPE_PARAM_INT64:
+@G_TYPE_PARAM_UINT64:
+@G_TYPE_PARAM_UNICHAR:
+@G_TYPE_PARAM_ENUM:
+@G_TYPE_PARAM_FLAGS:
+@G_TYPE_PARAM_FLOAT:
+@G_TYPE_PARAM_DOUBLE:
+@G_TYPE_PARAM_STRING:
+@G_TYPE_PARAM_PARAM:
+@G_TYPE_PARAM_BOXED:
+@G_TYPE_PARAM_POINTER:
+@G_TYPE_PARAM_VALUE_ARRAY:
+@G_TYPE_PARAM_CLOSURE:
+@G_TYPE_PARAM_OBJECT:
+
<!-- ##### MACRO G_IS_PARAM_SPEC_CLOSURE ##### -->
<para>
@type: A #GType value.
-<!-- ##### ENUM GTypeFundamentals ##### -->
-<para>
-The predefined identifiers of the reserved fundamental types.
-</para>
-
-@G_TYPE_INVALID: Usually a return value indicating an error.
-@G_TYPE_NONE: A synonym for the "void" type in C.
-@G_TYPE_INTERFACE: Root type of all interface types.
-@G_TYPE_CHAR: Identifier for the built-in type "gchar".
-@G_TYPE_UCHAR: Identifier for the built-in type "guchar".
-@G_TYPE_BOOLEAN: Identifier for the built-in type "gboolean".
-@G_TYPE_INT: Identifier for the built-in type "gint".
-@G_TYPE_UINT: Identifier for the built-in type "guint".
-@G_TYPE_LONG: Identifier for the built-in type "glong".
-@G_TYPE_ULONG: Identifier for the built-in type "gulong".
-@G_TYPE_INT64:
-@G_TYPE_UINT64:
-@G_TYPE_ENUM: Identifier for the "#GEnum" type.
-@G_TYPE_FLAGS: Identifier for the "#GFlags" type.
-@G_TYPE_FLOAT: Identifier for the built-in type "gfloat".
-@G_TYPE_DOUBLE: Identifier for the built-in type "gdouble".
-@G_TYPE_STRING: Identifier for a pointer to a null-terminated string "gchar*".
-@G_TYPE_POINTER: Identifier for anonymous pointers "void*".
-@G_TYPE_BOXED: Identifier for the "#GBoxed" type.
-@G_TYPE_PARAM: Identifier for the "#GParam" type.
-@G_TYPE_OBJECT: Identifier for the "#GObject" type.
-@G_TYPE_RESERVED_BSE_FIRST: First fundamental type ID reserved for BSE.
-@G_TYPE_RESERVED_BSE_LAST: Last fundamental type ID reserved for BSE.
-@G_TYPE_RESERVED_LAST_FUNDAMENTAL:
-@G_TYPE_CONSTANT_TYPES:
-@G_TYPE_CLOSURE:
-@G_TYPE_VALUE:
-@G_TYPE_VALUE_ARRAY:
-@G_TYPE_GSTRING:
-@G_TYPE_PARAM_CHAR:
-@G_TYPE_PARAM_UCHAR:
-@G_TYPE_PARAM_BOOLEAN:
-@G_TYPE_PARAM_INT:
-@G_TYPE_PARAM_UINT:
-@G_TYPE_PARAM_LONG:
-@G_TYPE_PARAM_ULONG:
-@G_TYPE_PARAM_INT64:
-@G_TYPE_PARAM_UINT64:
-@G_TYPE_PARAM_UNICHAR:
-@G_TYPE_PARAM_ENUM:
-@G_TYPE_PARAM_FLAGS:
-@G_TYPE_PARAM_FLOAT:
-@G_TYPE_PARAM_DOUBLE:
-@G_TYPE_PARAM_STRING:
-@G_TYPE_PARAM_PARAM:
-@G_TYPE_PARAM_BOXED:
-@G_TYPE_PARAM_POINTER:
-@G_TYPE_PARAM_VALUE_ARRAY:
-@G_TYPE_PARAM_CLOSURE:
-@G_TYPE_PARAM_OBJECT:
-
<!-- ##### STRUCT GTypeInterface ##### -->
<para>
An opaque structure used as the base of all interface types.
{
gchar buf[2048];
size_t bytes;
- GString *str;
-
+ char *str;
+ size_t total_bytes;
+ size_t total_allocated;
+
g_assert (f != NULL);
+
+#define STARTING_ALLOC 64
- str = g_string_new ("");
+ total_bytes = 0;
+ total_allocated = STARTING_ALLOC;
+ str = g_malloc (STARTING_ALLOC);
while (!feof (f))
{
bytes = fread (buf, 1, 2048, f);
+
+ while ((total_bytes + bytes + 1) > total_allocated)
+ {
+ total_allocated *= 2;
+ str = g_try_realloc (str, total_allocated);
+
+ if (str == NULL)
+ {
+ g_set_error (error,
+ G_FILE_ERROR,
+ G_FILE_ERROR_NOMEM,
+ _("Could not allocate %lu bytes to read file \"%s\""),
+ (gulong) total_allocated, filename);
+ goto error;
+ }
+ }
if (ferror (f))
{
_("Error reading file '%s': %s"),
filename, strerror (errno));
- g_string_free (str, TRUE);
- fclose (f);
-
- return FALSE;
+ goto error;
}
- g_string_append_len (str, buf, bytes);
+ memcpy (str + total_bytes, buf, bytes);
+ total_bytes += bytes;
}
fclose (f);
+ str[total_bytes] = '\0';
+
if (length)
- *length = str->len;
+ *length = total_bytes;
+
+ *contents = str;
- *contents = g_string_free (str, FALSE);
+ return TRUE;
+
+ error:
- return TRUE;
+ g_free (str);
+ fclose (f);
+
+ return FALSE;
}
#ifndef G_OS_WIN32
gchar *buf;
size_t bytes_read;
size_t size;
-
+ size_t alloc_size;
+
size = stat_buf->st_size;
- buf = g_new (gchar, size + 1);
-
+ alloc_size = size + 1;
+ buf = g_try_malloc (alloc_size);
+
+ if (buf == NULL)
+ {
+ g_set_error (error,
+ G_FILE_ERROR,
+ G_FILE_ERROR_NOMEM,
+ _("Could not allocate %lu bytes to read file \"%s\""),
+ (gulong) alloc_size, filename);
+
+ return FALSE;
+ }
+
bytes_read = 0;
while (bytes_read < size)
{