http://developer.gnome.org/glib/2.28/glib-String-Utility-Functions.html
g_try_new()
#define g_try_new(struct_type, n_structs)
Attempts to allocate n_structs
elements of type struct_type
, and returns NULL
on failure. Contrast with g_new()
, which aborts the program on failure. The returned pointer is cast to a pointer to the given type. If n_structs
is 0 it returns NULL
.
| the type of the elements to allocate |
| the number of elements to allocate |
Returns : | a pointer to the allocated memory, cast to a pointer to struct_type |
g_strdup ()
gchar * g_strdup (const gchar *str
);
Duplicates a string. If str
is NULL
it returns NULL
. The returned string should be freed with g_free()
when no longer needed.
| the string to duplicate |
Returns : | a newly-allocated copy of str |
g_file_get_contents ()
gboolean g_file_get_contents (const gchar *filename
,
gchar **contents
,
gsize *length
,
GError **error
);
Reads an entire file into allocated memory, with good error checking.
If the call was successful, it returns TRUE
and sets contents
to the file contents and length
to the length of the file contents in bytes. The string stored in contents
will be nul-terminated, so for text files you can pass NULL
for the length
argument. If the call was not successful, it returns FALSE
and setserror
. The error domain is G_FILE_ERROR. Possible error codes are those in the GFileError enumeration. In the error case, contents
is set to NULL
andlength
is set to zero.
| name of a file to read contents from, in the GLib file name encoding. [type filename] |
| location to store an allocated string, use g_free() to free the returned string. [out][array length=length][element-type guint8] |
| location to store length in bytes of the contents, or NULL . [allow-none] |
| return location for a GError, or NULL |
Returns : | TRUE on success, FALSE if an error occurred |