openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/glib-2.0/1_2.60.3-r0/glib-2.60.3/gio/gfile.c
gboolean g_file_load_contents(GFile* file, GCancellable* cancellable,
                              char** contents, gsize* length, char** etag_out,
                              GError** error)
{
    GFileInputStream* in;
    GByteArray* content;
    gsize pos;
    gssize res;
    GFileInfo* info;

    g_return_val_if_fail(G_IS_FILE(file), FALSE);
    g_return_val_if_fail(contents != NULL, FALSE);

    in = g_file_read(file, cancellable, error);
    if (in == NULL)
        return FALSE;

    content = g_byte_array_new();
    pos = 0;

    g_byte_array_set_size(content, pos + GET_CONTENT_BLOCK_SIZE + 1);
    while ((res = g_input_stream_read(G_INPUT_STREAM(in), content->data + pos,
                                      GET_CONTENT_BLOCK_SIZE, cancellable,
                                      error)) > 0)
    {
        pos += res;
        g_byte_array_set_size(content, pos + GET_CONTENT_BLOCK_SIZE + 1);
    }

    if (etag_out)
    {
        *etag_out = NULL;

        info = g_file_input_stream_query_info(in, G_FILE_ATTRIBUTE_ETAG_VALUE,
                                              cancellable, NULL);
        if (info)
        {
            *etag_out = g_strdup(g_file_info_get_etag(info));
            g_object_unref(info);
        }
    }

    /* Ignore errors on close */
    g_input_stream_close(G_INPUT_STREAM(in), cancellable, NULL);
    g_object_unref(in);

    if (res < 0)
    {
        /* error is set already */
        g_byte_array_free(content, TRUE);
        return FALSE;
    }

    if (length)
        *length = pos;

    /* Zero terminate (we got an extra byte allocated for this */
    content->data[pos] = 0;

    *contents = (char*)g_byte_array_free(content, FALSE);

    return TRUE;
}
/**
 * g_file_load_contents:
 * @file: input #GFile
 * @cancellable: optional #GCancellable object, %NULL to ignore
 * @contents: (out) (transfer full) (element-type guint8) (array length=length):
 * a location to place the contents of the file
 * @length: (out) (optional): a location to place the length of the contents of
 * the file, or %NULL if the length is not needed
 * @etag_out: (out) (optional): a location to place the current entity tag for
 * the file, or %NULL if the entity tag is not needed
 * @error: a #GError, or %NULL
 *
 * Loads the content of the file into memory. The data is always
 * zero-terminated, but this is not included in the resultant @length.
 * The returned @content should be freed with g_free() when no longer
 * needed.
 *
 * If @cancellable is not %NULL, then the operation can be cancelled by
 * triggering the cancellable object from another thread. If the operation
 * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.
 *
 * Returns: %TRUE if the @file's contents were successfully loaded.
 *     %FALSE if there were errors.
 */


Loads the content of the file into memory. The data is always
zero-terminated, but this is not included in the resultant @length.
The returned @content should be freed with g_free() when no longer
needed.

If @cancellable is not %NULL, then the operation can be cancelled by
triggering the cancellable object from another thread. If the operation
was cancelled, the error %G_IO_ERROR_CANCELLED will be returned.

%TRUE if the @file's contents were successfully loaded.
%FALSE if there were errors.
Loads the content of the file into memory . The data is always zero - terminated but this is not included in the resultant @length . The returned @content should be freed with g_free () when no longer needed . If @cancellable is not %NULL then the operation can be cancelled by triggering the cancellable object from another thread . If the operation was cancelled the error %G_IO_ERROR_CANCELLED will be returned . %TRUE if the @file ' s contents were successfully loaded . %FALSE if there were errors .
gboolean g_file_load_contents(GFile* file, GCancellable* cancellable,
                              char** contents, gsize* length, char** etag_out,
                              GError** error)
{
    GFileInputStream* in;
    GByteArray* content;
    gsize pos;
    gssize res;
    GFileInfo* info;
    g_return_val_if_fail(G_IS_FILE(file), FALSE);
    g_return_val_if_fail(contents != NULL, FALSE);
    in = g_file_read(file, cancellable, error);
    if (in == NULL)
        return FALSE;
    content = g_byte_array_new();
    pos = 0;
    g_byte_array_set_size(content, pos + GET_CONTENT_BLOCK_SIZE + 1);
    while ((res = g_input_stream_read(G_INPUT_STREAM(in), content->data + pos,
                                      GET_CONTENT_BLOCK_SIZE, cancellable,
                                      error)) > 0)
    {
        pos += res;
        g_byte_array_set_size(content, pos + GET_CONTENT_BLOCK_SIZE + 1);
    }
    if (etag_out)
    {
        *etag_out = NULL;
        info = g_file_input_stream_query_info(in, G_FILE_ATTRIBUTE_ETAG_VALUE,
                                              cancellable, NULL);
        if (info)
        {
            *etag_out = g_strdup(g_file_info_get_etag(info));
            g_object_unref(info);
        }
    }
    g_input_stream_close(G_INPUT_STREAM(in), cancellable, NULL);
    g_object_unref(in);
    if (res < 0)
    {
        g_byte_array_free(content, TRUE);
        return FALSE;
    }
    if (length)
        *length = pos;
    content->data[pos] = 0;
    *contents = (char*)g_byte_array_free(content, FALSE);
    return TRUE;
}
gboolean g_file_load_contents ( GFile * file , GCancellable * cancellable , char * * contents , gsize * length , char * * etag_out , GError * * error ) { GFileInputStream * in ; GByteArray * content ; gsize pos ; gssize res ; GFileInfo * info ; g_return_val_if_fail ( G_IS_FILE ( file ) , FALSE ) ; g_return_val_if_fail ( contents != NULL , FALSE ) ; in = g_file_read ( file , cancellable , error ) ; if ( in == NULL ) return FALSE ; content = g_byte_array_new ( ) ; pos = 0 ; g_byte_array_set_size ( content , pos + GET_CONTENT_BLOCK_SIZE + 1 ) ; while ( ( res = g_input_stream_read ( G_INPUT_STREAM ( in ) , content -> data + pos , GET_CONTENT_BLOCK_SIZE , cancellable , error ) ) > 0 ) { pos += res ; g_byte_array_set_size ( content , pos + GET_CONTENT_BLOCK_SIZE + 1 ) ; } if ( etag_out ) { * etag_out = NULL ; info = g_file_input_stream_query_info ( in , G_FILE_ATTRIBUTE_ETAG_VALUE , cancellable , NULL ) ; if ( info ) { * etag_out = g_strdup ( g_file_info_get_etag ( info ) ) ; g_object_unref ( info ) ; } } g_input_stream_close ( G_INPUT_STREAM ( in ) , cancellable , NULL ) ; g_object_unref ( in ) ; if ( res < 0 ) { g_byte_array_free ( content , TRUE ) ; return FALSE ; } if ( length ) * length = pos ; content -> data [ pos ] = 0 ; * contents = ( char * ) g_byte_array_free ( content , FALSE ) ; return TRUE ; }
g_file_load_contents:
 @file: input #GFile
 @cancellable: optional #GCancellable object, %NULL to ignore
 @contents: (out) (transfer full) (element-type guint8) (array length=length):
 a location to place the contents of the file
 @length: (out) (optional): a location to place the length of the contents of
 the file, or %NULL if the length is not needed
 @etag_out: (out) (optional): a location to place the current entity tag for
 the file, or %NULL if the entity tag is not needed
 @error: a #GError, or %NULL
g_file_load_contents : @file : input #GFile @cancellable : optional #GCancellable object %NULL to ignore @contents : ( out ) ( transfer full ) ( element - type guint8 ) ( array length = length ) : a location to place the contents of the file @length : ( out ) ( optional ) : a location to place the length of the contents of the file or %NULL if the length is not needed @etag_out : ( out ) ( optional ) : a location to place the current entity tag for the file or %NULL if the entity tag is not needed @error : a #GError or %NULL
/* Ignore errors on close */ /* error is set already */ /* Zero terminate (we got an extra byte allocated for this */