mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-14 04:57:46 +02:00
Formatting cleanup
This commit is contained in:
401
gio/gresource.c
401
gio/gresource.c
@@ -134,7 +134,7 @@ G_DEFINE_BOXED_TYPE (GResource, g_resource, g_resource_ref, g_resource_unref)
|
|||||||
*
|
*
|
||||||
* Gets the #GResource Error Quark.
|
* Gets the #GResource Error Quark.
|
||||||
*
|
*
|
||||||
* Return value: a #GQuark.
|
* Return value: a #GQuark
|
||||||
*
|
*
|
||||||
* Since: 2.32
|
* Since: 2.32
|
||||||
*/
|
*/
|
||||||
@@ -146,12 +146,12 @@ g_resource_error_quark (void)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* g_resource_ref:
|
* g_resource_ref:
|
||||||
* @resource: A #GResource.
|
* @resource: A #GResource
|
||||||
*
|
*
|
||||||
* Atomically increments the reference count of @array by one. This
|
* Atomically increments the reference count of @array by one. This
|
||||||
* function is MT-safe and may be called from any thread.
|
* function is MT-safe and may be called from any thread.
|
||||||
*
|
*
|
||||||
* Returns: The passed in #GResource.
|
* Returns: The passed in #GResource
|
||||||
*
|
*
|
||||||
* Since: 2.32
|
* Since: 2.32
|
||||||
**/
|
**/
|
||||||
@@ -164,7 +164,7 @@ g_resource_ref (GResource *resource)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* g_resource_unref:
|
* g_resource_unref:
|
||||||
* @resource: A #GResource.
|
* @resource: A #GResource
|
||||||
*
|
*
|
||||||
* Atomically decrements the reference count of @resource by one. If the
|
* Atomically decrements the reference count of @resource by one. If the
|
||||||
* reference count drops to 0, all memory allocated by the array is
|
* reference count drops to 0, all memory allocated by the array is
|
||||||
@@ -203,8 +203,8 @@ g_resource_new_from_table (GvdbTable *table)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* g_resource_new_from_data:
|
* g_resource_new_from_data:
|
||||||
* @data: A #GBytes.
|
* @data: A #GBytes
|
||||||
* @error: return location for a #GError, or %NULL.
|
* @error: return location for a #GError, or %NULL
|
||||||
*
|
*
|
||||||
* Creates a GResource from a reference to the binary resource bundle.
|
* Creates a GResource from a reference to the binary resource bundle.
|
||||||
* This will keep a reference to @data while the resource lives, so
|
* This will keep a reference to @data while the resource lives, so
|
||||||
@@ -213,23 +213,23 @@ g_resource_new_from_table (GvdbTable *table)
|
|||||||
* If you want to use this resource in the global resource namespace you need
|
* If you want to use this resource in the global resource namespace you need
|
||||||
* to register it with g_resources_register().
|
* to register it with g_resources_register().
|
||||||
*
|
*
|
||||||
* Return value: (transfer full): a new #GResource, or %NULL on error.
|
* Return value: (transfer full): a new #GResource, or %NULL on error
|
||||||
*
|
*
|
||||||
* Since: 2.32
|
* Since: 2.32
|
||||||
**/
|
**/
|
||||||
GResource *
|
GResource *
|
||||||
g_resource_new_from_data (GBytes *data,
|
g_resource_new_from_data (GBytes *data,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GvdbTable *table;
|
GvdbTable *table;
|
||||||
|
|
||||||
table = gvdb_table_new_from_data (g_bytes_get_data (data, NULL),
|
table = gvdb_table_new_from_data (g_bytes_get_data (data, NULL),
|
||||||
g_bytes_get_size (data),
|
g_bytes_get_size (data),
|
||||||
TRUE,
|
TRUE,
|
||||||
g_bytes_ref (data),
|
g_bytes_ref (data),
|
||||||
(GvdbRefFunc)g_bytes_ref,
|
(GvdbRefFunc)g_bytes_ref,
|
||||||
(GDestroyNotify)g_bytes_unref,
|
(GDestroyNotify)g_bytes_unref,
|
||||||
error);
|
error);
|
||||||
|
|
||||||
if (table == NULL)
|
if (table == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -239,8 +239,8 @@ g_resource_new_from_data (GBytes *data,
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* g_resource_load:
|
* g_resource_load:
|
||||||
* @filename: (type filename): the path of a filename to load, in the GLib filename encoding.
|
* @filename: (type filename): the path of a filename to load, in the GLib filename encoding
|
||||||
* @error: return location for a #GError, or %NULL.
|
* @error: return location for a #GError, or %NULL
|
||||||
*
|
*
|
||||||
* Loads a binary resource bundle and creates a #GResource representation of it, allowing
|
* Loads a binary resource bundle and creates a #GResource representation of it, allowing
|
||||||
* you to query it for data.
|
* you to query it for data.
|
||||||
@@ -248,13 +248,13 @@ g_resource_new_from_data (GBytes *data,
|
|||||||
* If you want to use this resource in the global resource namespace you need
|
* If you want to use this resource in the global resource namespace you need
|
||||||
* to register it with g_resources_register().
|
* to register it with g_resources_register().
|
||||||
*
|
*
|
||||||
* Return value: (transfer full): a new #GResource, or %NULL on error.
|
* Return value: (transfer full): a new #GResource, or %NULL on error
|
||||||
*
|
*
|
||||||
* Since: 2.32
|
* Since: 2.32
|
||||||
**/
|
**/
|
||||||
GResource *
|
GResource *
|
||||||
g_resource_load (const gchar *filename,
|
g_resource_load (const gchar *filename,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GvdbTable *table;
|
GvdbTable *table;
|
||||||
|
|
||||||
@@ -265,14 +265,15 @@ g_resource_load (const gchar *filename,
|
|||||||
return g_resource_new_from_table (table);
|
return g_resource_new_from_table (table);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean do_lookup (GResource *resource,
|
static
|
||||||
const char *path,
|
gboolean do_lookup (GResource *resource,
|
||||||
GResourceLookupFlags lookup_flags,
|
const gchar *path,
|
||||||
gsize *size,
|
GResourceLookupFlags lookup_flags,
|
||||||
guint32 *flags,
|
gsize *size,
|
||||||
const void **data,
|
guint32 *flags,
|
||||||
gsize *data_size,
|
const void **data,
|
||||||
GError **error)
|
gsize *data_size,
|
||||||
|
GError **error)
|
||||||
{
|
{
|
||||||
char *free_path = NULL;
|
char *free_path = NULL;
|
||||||
gsize path_len;
|
gsize path_len;
|
||||||
@@ -291,8 +292,8 @@ static gboolean do_lookup (GResource *resource,
|
|||||||
if (value == NULL)
|
if (value == NULL)
|
||||||
{
|
{
|
||||||
g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
|
g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
|
||||||
_("The resource at '%s' does not exist"),
|
_("The resource at '%s' does not exist"),
|
||||||
path);
|
path);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -300,9 +301,9 @@ static gboolean do_lookup (GResource *resource,
|
|||||||
GVariant *array;
|
GVariant *array;
|
||||||
|
|
||||||
g_variant_get (value, "(uu@ay)",
|
g_variant_get (value, "(uu@ay)",
|
||||||
&_size,
|
&_size,
|
||||||
&_flags,
|
&_flags,
|
||||||
&array);
|
&array);
|
||||||
|
|
||||||
if (size)
|
if (size)
|
||||||
*size = _size;
|
*size = _size;
|
||||||
@@ -330,10 +331,10 @@ static gboolean do_lookup (GResource *resource,
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* g_resource_open_stream:
|
* g_resource_open_stream:
|
||||||
* @resource: A #GResource.
|
* @resource: A #GResource
|
||||||
* @path: A pathname inside the resource.
|
* @path: A pathname inside the resource
|
||||||
* @lookup_flags: A #GResourceLookupFlags.
|
* @lookup_flags: A #GResourceLookupFlags
|
||||||
* @error: return location for a #GError, or %NULL.
|
* @error: return location for a #GError, or %NULL
|
||||||
*
|
*
|
||||||
* Looks for a file at the specified @path in the resource and
|
* Looks for a file at the specified @path in the resource and
|
||||||
* returns a #GInputStream that lets you read the data.
|
* returns a #GInputStream that lets you read the data.
|
||||||
@@ -341,15 +342,15 @@ static gboolean do_lookup (GResource *resource,
|
|||||||
* @lookup_flags controls the behaviour of the lookup.
|
* @lookup_flags controls the behaviour of the lookup.
|
||||||
*
|
*
|
||||||
* Returns: (transfer full): #GInputStream or %NULL on error.
|
* Returns: (transfer full): #GInputStream or %NULL on error.
|
||||||
* Free the returned object with g_object_unref().
|
* Free the returned object with g_object_unref()
|
||||||
*
|
*
|
||||||
* Since: 2.32
|
* Since: 2.32
|
||||||
**/
|
**/
|
||||||
GInputStream *
|
GInputStream *
|
||||||
g_resource_open_stream (GResource *resource,
|
g_resource_open_stream (GResource *resource,
|
||||||
const char *path,
|
const gchar *path,
|
||||||
GResourceLookupFlags lookup_flags,
|
GResourceLookupFlags lookup_flags,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
const void *data;
|
const void *data;
|
||||||
gsize data_size;
|
gsize data_size;
|
||||||
@@ -361,13 +362,13 @@ g_resource_open_stream (GResource *resource,
|
|||||||
|
|
||||||
stream = g_memory_input_stream_new_from_data (data, data_size, NULL);
|
stream = g_memory_input_stream_new_from_data (data, data_size, NULL);
|
||||||
g_object_set_data_full (G_OBJECT (stream), "g-resource",
|
g_object_set_data_full (G_OBJECT (stream), "g-resource",
|
||||||
g_resource_ref (resource),
|
g_resource_ref (resource),
|
||||||
(GDestroyNotify)g_resource_unref);
|
(GDestroyNotify)g_resource_unref);
|
||||||
|
|
||||||
if (flags & G_RESOURCE_FLAGS_COMPRESSED)
|
if (flags & G_RESOURCE_FLAGS_COMPRESSED)
|
||||||
{
|
{
|
||||||
GZlibDecompressor *decompressor =
|
GZlibDecompressor *decompressor =
|
||||||
g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_ZLIB);
|
g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_ZLIB);
|
||||||
|
|
||||||
stream2 = g_converter_input_stream_new (stream, G_CONVERTER (decompressor));
|
stream2 = g_converter_input_stream_new (stream, G_CONVERTER (decompressor));
|
||||||
g_object_unref (decompressor);
|
g_object_unref (decompressor);
|
||||||
@@ -380,10 +381,10 @@ g_resource_open_stream (GResource *resource,
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* g_resource_lookup_data:
|
* g_resource_lookup_data:
|
||||||
* @resource: A #GResource.
|
* @resource: A #GResource
|
||||||
* @path: A pathname inside the resource.
|
* @path: A pathname inside the resource
|
||||||
* @lookup_flags: A #GResourceLookupFlags.
|
* @lookup_flags: A #GResourceLookupFlags
|
||||||
* @error: return location for a #GError, or %NULL.
|
* @error: return location for a #GError, or %NULL
|
||||||
*
|
*
|
||||||
* Looks for a file at the specified @path in the resource and
|
* Looks for a file at the specified @path in the resource and
|
||||||
* returns a #GBytes that lets you directly access the data in
|
* returns a #GBytes that lets you directly access the data in
|
||||||
@@ -401,15 +402,15 @@ g_resource_open_stream (GResource *resource,
|
|||||||
* @lookup_flags controls the behaviour of the lookup.
|
* @lookup_flags controls the behaviour of the lookup.
|
||||||
*
|
*
|
||||||
* Returns: (transfer full): #GBytes or %NULL on error.
|
* Returns: (transfer full): #GBytes or %NULL on error.
|
||||||
* Free the returned object with g_bytes_unref().
|
* Free the returned object with g_bytes_unref()
|
||||||
*
|
*
|
||||||
* Since: 2.32
|
* Since: 2.32
|
||||||
**/
|
**/
|
||||||
GBytes *
|
GBytes *
|
||||||
g_resource_lookup_data (GResource *resource,
|
g_resource_lookup_data (GResource *resource,
|
||||||
const char *path,
|
const gchar *path,
|
||||||
GResourceLookupFlags lookup_flags,
|
GResourceLookupFlags lookup_flags,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
const void *data;
|
const void *data;
|
||||||
guint32 flags;
|
guint32 flags;
|
||||||
@@ -429,7 +430,7 @@ g_resource_lookup_data (GResource *resource,
|
|||||||
|
|
||||||
|
|
||||||
GZlibDecompressor *decompressor =
|
GZlibDecompressor *decompressor =
|
||||||
g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_ZLIB);
|
g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_ZLIB);
|
||||||
|
|
||||||
uncompressed = g_malloc (size + 1);
|
uncompressed = g_malloc (size + 1);
|
||||||
|
|
||||||
@@ -439,30 +440,30 @@ g_resource_lookup_data (GResource *resource,
|
|||||||
d_size = size;
|
d_size = size;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
res = g_converter_convert (G_CONVERTER (decompressor),
|
res = g_converter_convert (G_CONVERTER (decompressor),
|
||||||
s, s_size,
|
s, s_size,
|
||||||
d, d_size,
|
d, d_size,
|
||||||
G_CONVERTER_INPUT_AT_END,
|
G_CONVERTER_INPUT_AT_END,
|
||||||
&bytes_read,
|
&bytes_read,
|
||||||
&bytes_written,
|
&bytes_written,
|
||||||
NULL);
|
NULL);
|
||||||
if (res == G_CONVERTER_ERROR)
|
if (res == G_CONVERTER_ERROR)
|
||||||
{
|
{
|
||||||
g_free (uncompressed);
|
g_free (uncompressed);
|
||||||
g_object_unref (decompressor);
|
g_object_unref (decompressor);
|
||||||
|
|
||||||
g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_INTERNAL,
|
g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_INTERNAL,
|
||||||
_("The resource at '%s' failed to decompress"),
|
_("The resource at '%s' failed to decompress"),
|
||||||
path);
|
path);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
s += bytes_read;
|
s += bytes_read;
|
||||||
s_size -= bytes_read;
|
s_size -= bytes_read;
|
||||||
d += bytes_written;
|
d += bytes_written;
|
||||||
d_size -= bytes_written;
|
d_size -= bytes_written;
|
||||||
}
|
}
|
||||||
while (res != G_CONVERTER_FINISHED);
|
while (res != G_CONVERTER_FINISHED);
|
||||||
|
|
||||||
uncompressed[size] = 0; /* Zero terminate */
|
uncompressed[size] = 0; /* Zero terminate */
|
||||||
@@ -477,41 +478,41 @@ g_resource_lookup_data (GResource *resource,
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* g_resource_get_info:
|
* g_resource_get_info:
|
||||||
* @resource: A #GResource.
|
* @resource: A #GResource
|
||||||
* @path: A pathname inside the resource.
|
* @path: A pathname inside the resource
|
||||||
* @lookup_flags: A #GResourceLookupFlags.
|
* @lookup_flags: A #GResourceLookupFlags
|
||||||
* @size: (out) (allow-none): a location to place the length of the contents of the file,
|
* @size: (out) (allow-none): a location to place the length of the contents of the file,
|
||||||
* or %NULL if the length is not needed
|
* or %NULL if the length is not needed
|
||||||
* @flags: (out) (allow-none): a location to place the flags about the file,
|
* @flags: (out) (allow-none): a location to place the flags about the file,
|
||||||
* or %NULL if the length is not needed
|
* or %NULL if the length is not needed
|
||||||
* @error: return location for a #GError, or %NULL.
|
* @error: return location for a #GError, or %NULL
|
||||||
*
|
*
|
||||||
* Looks for a file at the specified @path in the resource and
|
* Looks for a file at the specified @path in the resource and
|
||||||
* if found returns information about it.
|
* if found returns information about it.
|
||||||
*
|
*
|
||||||
* @lookup_flags controls the behaviour of the lookup.
|
* @lookup_flags controls the behaviour of the lookup.
|
||||||
*
|
*
|
||||||
* Returns: %TRUE if the file was found. %FALSE if there were errors.
|
* Returns: %TRUE if the file was found. %FALSE if there were errors
|
||||||
*
|
*
|
||||||
* Since: 2.32
|
* Since: 2.32
|
||||||
**/
|
**/
|
||||||
gboolean
|
gboolean
|
||||||
g_resource_get_info (GResource *resource,
|
g_resource_get_info (GResource *resource,
|
||||||
const char *path,
|
const gchar *path,
|
||||||
GResourceLookupFlags lookup_flags,
|
GResourceLookupFlags lookup_flags,
|
||||||
gsize *size,
|
gsize *size,
|
||||||
guint32 *flags,
|
guint32 *flags,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
return do_lookup (resource, path, lookup_flags, size, flags, NULL, NULL, error);
|
return do_lookup (resource, path, lookup_flags, size, flags, NULL, NULL, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* g_resource_enumerate_children:
|
* g_resource_enumerate_children:
|
||||||
* @resource: A #GResource.
|
* @resource: A #GResource
|
||||||
* @path: A pathname inside the resource.
|
* @path: A pathname inside the resource
|
||||||
* @lookup_flags: A #GResourceLookupFlags.
|
* @lookup_flags: A #GResourceLookupFlags
|
||||||
* @error: return location for a #GError, or %NULL.
|
* @error: return location for a #GError, or %NULL
|
||||||
*
|
*
|
||||||
* Returns all the names of children at the specified @path in the resource.
|
* Returns all the names of children at the specified @path in the resource.
|
||||||
* The return result is a %NULL terminated list of strings which should
|
* The return result is a %NULL terminated list of strings which should
|
||||||
@@ -523,11 +524,11 @@ g_resource_get_info (GResource *resource,
|
|||||||
*
|
*
|
||||||
* Since: 2.32
|
* Since: 2.32
|
||||||
**/
|
**/
|
||||||
char **
|
gchar **
|
||||||
g_resource_enumerate_children (GResource *resource,
|
g_resource_enumerate_children (GResource *resource,
|
||||||
const char *path,
|
const gchar *path,
|
||||||
GResourceLookupFlags lookup_flags,
|
GResourceLookupFlags lookup_flags,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gchar **children;
|
gchar **children;
|
||||||
gsize path_len;
|
gsize path_len;
|
||||||
@@ -536,8 +537,8 @@ g_resource_enumerate_children (GResource *resource,
|
|||||||
if (*path == 0)
|
if (*path == 0)
|
||||||
{
|
{
|
||||||
g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
|
g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
|
||||||
_("The resource at '%s' does not exist"),
|
_("The resource at '%s' does not exist"),
|
||||||
path);
|
path);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -553,8 +554,8 @@ g_resource_enumerate_children (GResource *resource,
|
|||||||
if (children == NULL)
|
if (children == NULL)
|
||||||
{
|
{
|
||||||
g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
|
g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
|
||||||
_("The resource at '%s' does not exist"),
|
_("The resource at '%s' does not exist"),
|
||||||
path);
|
path);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -571,8 +572,7 @@ static GStaticResource *lazy_register_resources;
|
|||||||
static void
|
static void
|
||||||
g_resources_register_unlocked (GResource *resource)
|
g_resources_register_unlocked (GResource *resource)
|
||||||
{
|
{
|
||||||
registered_resources = g_list_prepend (registered_resources,
|
registered_resources = g_list_prepend (registered_resources, g_resource_ref (resource));
|
||||||
g_resource_ref (resource));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -584,15 +584,14 @@ g_resources_unregister_unlocked (GResource *resource)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
registered_resources = g_list_remove (registered_resources,
|
registered_resources = g_list_remove (registered_resources, resource);
|
||||||
resource);
|
|
||||||
g_resource_unref (resource);
|
g_resource_unref (resource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* g_resources_register:
|
* g_resources_register:
|
||||||
* @resource: A #GResource.
|
* @resource: A #GResource
|
||||||
*
|
*
|
||||||
* Registers the resource with the process-global set of resources.
|
* Registers the resource with the process-global set of resources.
|
||||||
* Once a resource is registered the files in it can be accessed
|
* Once a resource is registered the files in it can be accessed
|
||||||
@@ -610,7 +609,7 @@ g_resources_register (GResource *resource)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* g_resources_unregister:
|
* g_resources_unregister:
|
||||||
* @resource: A #GResource.
|
* @resource: A #GResource
|
||||||
*
|
*
|
||||||
* Unregisters the resource from the process-global set of resources.
|
* Unregisters the resource from the process-global set of resources.
|
||||||
*
|
*
|
||||||
@@ -626,9 +625,9 @@ g_resources_unregister (GResource *resource)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* g_resources_open_stream:
|
* g_resources_open_stream:
|
||||||
* @path: A pathname inside the resource.
|
* @path: A pathname inside the resource
|
||||||
* @lookup_flags: A #GResourceLookupFlags.
|
* @lookup_flags: A #GResourceLookupFlags
|
||||||
* @error: return location for a #GError, or %NULL.
|
* @error: return location for a #GError, or %NULL
|
||||||
*
|
*
|
||||||
* Looks for a file at the specified @path in the set of
|
* Looks for a file at the specified @path in the set of
|
||||||
* globally registred resources and returns a #GInputStream
|
* globally registred resources and returns a #GInputStream
|
||||||
@@ -637,14 +636,14 @@ g_resources_unregister (GResource *resource)
|
|||||||
* @lookup_flags controls the behaviour of the lookup.
|
* @lookup_flags controls the behaviour of the lookup.
|
||||||
*
|
*
|
||||||
* Returns: (transfer full): #GInputStream or %NULL on error.
|
* Returns: (transfer full): #GInputStream or %NULL on error.
|
||||||
* Free the returned object with g_object_unref().
|
* Free the returned object with g_object_unref()
|
||||||
*
|
*
|
||||||
* Since: 2.32
|
* Since: 2.32
|
||||||
**/
|
**/
|
||||||
GInputStream *
|
GInputStream *
|
||||||
g_resources_open_stream (const char *path,
|
g_resources_open_stream (const gchar *path,
|
||||||
GResourceLookupFlags lookup_flags,
|
GResourceLookupFlags lookup_flags,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GInputStream *res = NULL;
|
GInputStream *res = NULL;
|
||||||
GList *l;
|
GList *l;
|
||||||
@@ -661,23 +660,23 @@ g_resources_open_stream (const char *path,
|
|||||||
|
|
||||||
stream = g_resource_open_stream (r, path, lookup_flags, &my_error);
|
stream = g_resource_open_stream (r, path, lookup_flags, &my_error);
|
||||||
if (stream == NULL &&
|
if (stream == NULL &&
|
||||||
g_error_matches (my_error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND))
|
g_error_matches (my_error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND))
|
||||||
{
|
{
|
||||||
g_clear_error (&my_error);
|
g_clear_error (&my_error);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (stream == NULL)
|
if (stream == NULL)
|
||||||
g_propagate_error (error, my_error);
|
g_propagate_error (error, my_error);
|
||||||
res = stream;
|
res = stream;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (l == NULL)
|
if (l == NULL)
|
||||||
g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
|
g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
|
||||||
_("The resource at '%s' does not exist"),
|
_("The resource at '%s' does not exist"),
|
||||||
path);
|
path);
|
||||||
|
|
||||||
g_rw_lock_reader_unlock (&resources_lock);
|
g_rw_lock_reader_unlock (&resources_lock);
|
||||||
|
|
||||||
@@ -686,9 +685,9 @@ g_resources_open_stream (const char *path,
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* g_resources_lookup_data:
|
* g_resources_lookup_data:
|
||||||
* @path: A pathname inside the resource.
|
* @path: A pathname inside the resource
|
||||||
* @lookup_flags: A #GResourceLookupFlags.
|
* @lookup_flags: A #GResourceLookupFlags
|
||||||
* @error: return location for a #GError, or %NULL.
|
* @error: return location for a #GError, or %NULL
|
||||||
*
|
*
|
||||||
* Looks for a file at the specified @path in the set of
|
* Looks for a file at the specified @path in the set of
|
||||||
* globally registred resources and returns a #GBytes that
|
* globally registred resources and returns a #GBytes that
|
||||||
@@ -706,14 +705,14 @@ g_resources_open_stream (const char *path,
|
|||||||
* @lookup_flags controls the behaviour of the lookup.
|
* @lookup_flags controls the behaviour of the lookup.
|
||||||
*
|
*
|
||||||
* Returns: (transfer full): #GBytes or %NULL on error.
|
* Returns: (transfer full): #GBytes or %NULL on error.
|
||||||
* Free the returned object with g_bytes_unref().
|
* Free the returned object with g_bytes_unref()
|
||||||
*
|
*
|
||||||
* Since: 2.32
|
* Since: 2.32
|
||||||
**/
|
**/
|
||||||
GBytes *
|
GBytes *
|
||||||
g_resources_lookup_data (const char *path,
|
g_resources_lookup_data (const gchar *path,
|
||||||
GResourceLookupFlags lookup_flags,
|
GResourceLookupFlags lookup_flags,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GBytes *res = NULL;
|
GBytes *res = NULL;
|
||||||
GList *l;
|
GList *l;
|
||||||
@@ -730,23 +729,23 @@ g_resources_lookup_data (const char *path,
|
|||||||
|
|
||||||
data = g_resource_lookup_data (r, path, lookup_flags, &my_error);
|
data = g_resource_lookup_data (r, path, lookup_flags, &my_error);
|
||||||
if (data == NULL &&
|
if (data == NULL &&
|
||||||
g_error_matches (my_error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND))
|
g_error_matches (my_error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND))
|
||||||
{
|
{
|
||||||
g_clear_error (&my_error);
|
g_clear_error (&my_error);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (data == NULL)
|
if (data == NULL)
|
||||||
g_propagate_error (error, my_error);
|
g_propagate_error (error, my_error);
|
||||||
res = data;
|
res = data;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (l == NULL)
|
if (l == NULL)
|
||||||
g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
|
g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
|
||||||
_("The resource at '%s' does not exist"),
|
_("The resource at '%s' does not exist"),
|
||||||
path);
|
path);
|
||||||
|
|
||||||
g_rw_lock_reader_unlock (&resources_lock);
|
g_rw_lock_reader_unlock (&resources_lock);
|
||||||
|
|
||||||
@@ -755,9 +754,9 @@ g_resources_lookup_data (const char *path,
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* g_resources_enumerate_children:
|
* g_resources_enumerate_children:
|
||||||
* @path: A pathname inside the resource.
|
* @path: A pathname inside the resource
|
||||||
* @lookup_flags: A #GResourceLookupFlags.
|
* @lookup_flags: A #GResourceLookupFlags
|
||||||
* @error: return location for a #GError, or %NULL.
|
* @error: return location for a #GError, or %NULL
|
||||||
*
|
*
|
||||||
* Returns all the names of children at the specified @path in the set of
|
* Returns all the names of children at the specified @path in the set of
|
||||||
* globally registred resources.
|
* globally registred resources.
|
||||||
@@ -770,10 +769,10 @@ g_resources_lookup_data (const char *path,
|
|||||||
*
|
*
|
||||||
* Since: 2.32
|
* Since: 2.32
|
||||||
**/
|
**/
|
||||||
char **
|
gchar **
|
||||||
g_resources_enumerate_children (const char *path,
|
g_resources_enumerate_children (const gchar *path,
|
||||||
GResourceLookupFlags lookup_flags,
|
GResourceLookupFlags lookup_flags,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
GHashTable *hash = NULL;
|
GHashTable *hash = NULL;
|
||||||
GList *l;
|
GList *l;
|
||||||
@@ -791,14 +790,14 @@ g_resources_enumerate_children (const char *path,
|
|||||||
children = g_resource_enumerate_children (r, path, 0, NULL);
|
children = g_resource_enumerate_children (r, path, 0, NULL);
|
||||||
|
|
||||||
if (children != NULL)
|
if (children != NULL)
|
||||||
{
|
{
|
||||||
if (hash == NULL)
|
if (hash == NULL)
|
||||||
hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
||||||
|
|
||||||
for (i = 0; children[i] != NULL; i++)
|
for (i = 0; children[i] != NULL; i++)
|
||||||
g_hash_table_insert (hash, children[i], children[i]);
|
g_hash_table_insert (hash, children[i], children[i]);
|
||||||
g_free (children);
|
g_free (children);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_rw_lock_reader_unlock (&resources_lock);
|
g_rw_lock_reader_unlock (&resources_lock);
|
||||||
@@ -806,8 +805,8 @@ g_resources_enumerate_children (const char *path,
|
|||||||
if (hash == NULL)
|
if (hash == NULL)
|
||||||
{
|
{
|
||||||
g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
|
g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
|
||||||
_("The resource at '%s' does not exist"),
|
_("The resource at '%s' does not exist"),
|
||||||
path);
|
path);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -821,7 +820,7 @@ g_resources_enumerate_children (const char *path,
|
|||||||
|
|
||||||
g_hash_table_iter_init (&iter, hash);
|
g_hash_table_iter_init (&iter, hash);
|
||||||
while (g_hash_table_iter_next (&iter, (gpointer *)&key, NULL))
|
while (g_hash_table_iter_next (&iter, (gpointer *)&key, NULL))
|
||||||
children[i++] = g_strdup (key);
|
children[i++] = g_strdup (key);
|
||||||
children[i++] = NULL;
|
children[i++] = NULL;
|
||||||
|
|
||||||
g_hash_table_destroy (hash);
|
g_hash_table_destroy (hash);
|
||||||
@@ -832,29 +831,29 @@ g_resources_enumerate_children (const char *path,
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* g_resources_get_info:
|
* g_resources_get_info:
|
||||||
* @path: A pathname inside the resource.
|
* @path: A pathname inside the resource
|
||||||
* @lookup_flags: A #GResourceLookupFlags.
|
* @lookup_flags: A #GResourceLookupFlags
|
||||||
* @size: (out) (allow-none): a location to place the length of the contents of the file,
|
* @size: (out) (allow-none): a location to place the length of the contents of the file,
|
||||||
* or %NULL if the length is not needed
|
* or %NULL if the length is not needed
|
||||||
* @flags: (out) (allow-none): a location to place the flags about the file,
|
* @flags: (out) (allow-none): a location to place the flags about the file,
|
||||||
* or %NULL if the length is not needed
|
* or %NULL if the length is not needed
|
||||||
* @error: return location for a #GError, or %NULL.
|
* @error: return location for a #GError, or %NULL
|
||||||
*
|
*
|
||||||
* Looks for a file at the specified @path in the set of
|
* Looks for a file at the specified @path in the set of
|
||||||
* globally registred resources and if found returns information about it.
|
* globally registred resources and if found returns information about it.
|
||||||
*
|
*
|
||||||
* @lookup_flags controls the behaviour of the lookup.
|
* @lookup_flags controls the behaviour of the lookup.
|
||||||
*
|
*
|
||||||
* Returns: %TRUE if the file was found. %FALSE if there were errors.
|
* Returns: %TRUE if the file was found. %FALSE if there were errors
|
||||||
*
|
*
|
||||||
* Since: 2.32
|
* Since: 2.32
|
||||||
**/
|
**/
|
||||||
gboolean
|
gboolean
|
||||||
g_resources_get_info (const char *path,
|
g_resources_get_info (const gchar *path,
|
||||||
GResourceLookupFlags lookup_flags,
|
GResourceLookupFlags lookup_flags,
|
||||||
gsize *size,
|
gsize *size,
|
||||||
guint32 *flags,
|
guint32 *flags,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean res = FALSE;
|
gboolean res = FALSE;
|
||||||
GList *l;
|
GList *l;
|
||||||
@@ -871,23 +870,23 @@ g_resources_get_info (const char *path,
|
|||||||
|
|
||||||
r_res = g_resource_get_info (r, path, lookup_flags, size, flags, &my_error);
|
r_res = g_resource_get_info (r, path, lookup_flags, size, flags, &my_error);
|
||||||
if (!r_res &&
|
if (!r_res &&
|
||||||
g_error_matches (my_error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND))
|
g_error_matches (my_error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND))
|
||||||
{
|
{
|
||||||
g_clear_error (&my_error);
|
g_clear_error (&my_error);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!r_res)
|
if (!r_res)
|
||||||
g_propagate_error (error, my_error);
|
g_propagate_error (error, my_error);
|
||||||
res = r_res;
|
res = r_res;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (l == NULL)
|
if (l == NULL)
|
||||||
g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
|
g_set_error (error, G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND,
|
||||||
_("The resource at '%s' does not exist"),
|
_("The resource at '%s' does not exist"),
|
||||||
path);
|
path);
|
||||||
|
|
||||||
g_rw_lock_reader_unlock (&resources_lock);
|
g_rw_lock_reader_unlock (&resources_lock);
|
||||||
|
|
||||||
@@ -915,7 +914,7 @@ g_resources_get_info (const char *path,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
register_lazy_static_resources_unlocked ()
|
register_lazy_static_resources_unlocked (void)
|
||||||
{
|
{
|
||||||
GStaticResource *list;
|
GStaticResource *list;
|
||||||
|
|
||||||
@@ -928,10 +927,10 @@ register_lazy_static_resources_unlocked ()
|
|||||||
GBytes *bytes = g_bytes_new_static (list->data, list->data_len);
|
GBytes *bytes = g_bytes_new_static (list->data, list->data_len);
|
||||||
GResource *resource = g_resource_new_from_data (bytes, NULL);
|
GResource *resource = g_resource_new_from_data (bytes, NULL);
|
||||||
if (resource)
|
if (resource)
|
||||||
{
|
{
|
||||||
g_resources_register_unlocked (resource);
|
g_resources_register_unlocked (resource);
|
||||||
g_atomic_pointer_set (&list->resource, resource);
|
g_atomic_pointer_set (&list->resource, resource);
|
||||||
}
|
}
|
||||||
g_bytes_unref (bytes);
|
g_bytes_unref (bytes);
|
||||||
|
|
||||||
list = list->next;
|
list = list->next;
|
||||||
@@ -939,7 +938,7 @@ register_lazy_static_resources_unlocked ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
register_lazy_static_resources ()
|
register_lazy_static_resources (void)
|
||||||
{
|
{
|
||||||
if (g_atomic_pointer_get (&lazy_register_resources) == NULL)
|
if (g_atomic_pointer_get (&lazy_register_resources) == NULL)
|
||||||
return;
|
return;
|
||||||
@@ -951,14 +950,14 @@ register_lazy_static_resources ()
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* g_static_resource_init:
|
* g_static_resource_init:
|
||||||
* @static_resource: pointer to a static #GStaticResource.
|
* @static_resource: pointer to a static #GStaticResource
|
||||||
*
|
*
|
||||||
* Initializes a GResource from static data using a
|
* Initializes a GResource from static data using a
|
||||||
* GStaticResource.
|
* GStaticResource.
|
||||||
*
|
*
|
||||||
* This is normally used by code generated by
|
* This is normally used by code generated by
|
||||||
* <link linkend="glib-compile-resources">glib-compile-resources</link> and is
|
* <link linkend="glib-compile-resources">glib-compile-resources</link>
|
||||||
* not typically used by other code.
|
* and is not typically used by other code.
|
||||||
*
|
*
|
||||||
* Since: 2.32
|
* Since: 2.32
|
||||||
**/
|
**/
|
||||||
@@ -977,13 +976,13 @@ g_static_resource_init (GStaticResource *static_resource)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* g_static_resource_fini:
|
* g_static_resource_fini:
|
||||||
* @static_resource: pointer to a static #GStaticResource.
|
* @static_resource: pointer to a static #GStaticResource
|
||||||
*
|
*
|
||||||
* Finalized a GResource initialized by g_static_resource_init ().
|
* Finalized a GResource initialized by g_static_resource_init().
|
||||||
*
|
*
|
||||||
* This is normally used by code generated by
|
* This is normally used by code generated by
|
||||||
* <link linkend="glib-compile-resources">glib-compile-resources</link> and is
|
* <link linkend="glib-compile-resources">glib-compile-resources</link>
|
||||||
* not typically used by other code.
|
* and is not typically used by other code.
|
||||||
*
|
*
|
||||||
* Since: 2.32
|
* Since: 2.32
|
||||||
**/
|
**/
|
||||||
@@ -1009,20 +1008,20 @@ g_static_resource_fini (GStaticResource *static_resource)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* g_static_resource_get_resource:
|
* g_static_resource_get_resource:
|
||||||
* @static_resource: pointer to a static #GStaticResource.
|
* @static_resource: pointer to a static #GStaticResource
|
||||||
*
|
*
|
||||||
* Gets the GResource that was registred by a call to g_static_resource_init ().
|
* Gets the GResource that was registred by a call to g_static_resource_init().
|
||||||
*
|
*
|
||||||
* This is normally used by code generated by
|
* This is normally used by code generated by
|
||||||
* <link linkend="glib-compile-resources">glib-compile-resources</link> and is
|
* <link linkend="glib-compile-resources">glib-compile-resources</link>
|
||||||
* not typically used by other code.
|
* and is not typically used by other code.
|
||||||
*
|
*
|
||||||
* Return value: (transfer none): a #GResource.
|
* Return value: (transfer none): a #GResource
|
||||||
*
|
*
|
||||||
* Since: 2.32
|
* Since: 2.32
|
||||||
**/
|
**/
|
||||||
GResource *
|
GResource *
|
||||||
g_static_resource_get_resource (GStaticResource *static_resource)
|
g_static_resource_get_resource (GStaticResource *static_resource)
|
||||||
{
|
{
|
||||||
register_lazy_static_resources ();
|
register_lazy_static_resources ();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user