Beispiel #1
0
/* Closes the log handle
 * Returns the 0 if succesful or -1 on error
 */
int log_handle_close(
    log_handle_t *log_handle,
    libcerror_error_t **error )
{
    static char *function = "log_handle_close";

    if( log_handle == NULL )
    {
        libcerror_error_set(
            error,
            LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
            LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
            "%s: invalid log handle.",
            function );

        return( -1 );
    }
    if( log_handle->log_stream != NULL )
    {
        if( file_stream_close(
                    log_handle->log_stream ) != 0 )
        {
            libcerror_error_set(
                error,
                LIBCERROR_ERROR_DOMAIN_IO,
                LIBCERROR_IO_ERROR_CLOSE_FAILED,
                "%s: unable to close log stream.",
                function );

            return( -1 );
        }
        log_handle->log_stream = NULL;
    }
    return( 0 );
}
Beispiel #2
0
static int do_generate_lib_c(cpe_dr_generate_ctx_t ctx) {
    struct write_stream_file stream;
    int i;
    int rv;

    rv = 0;

    for(i = 0; i < o_lib_c->count; ++i) {
        FILE * fp;

        if (o_lib_c_arg->count == 0) {
            CPE_ERROR(ctx->m_em, "not arg name setted!");
            return -1;
        }

        fp = file_stream_open(o_lib_c->filename[i], "w", ctx->m_em);
        if (fp == NULL) {
            rv = -1;
            continue;
        }

        write_stream_file_init(&stream, fp, ctx->m_em);

        cpe_dr_generate_lib_c((write_stream_t)&stream, o_lib_c_arg->sval[0], ctx);

        file_stream_close(fp, ctx->m_em);
    }

    return rv;
}
Beispiel #3
0
static int do_generate_h(cpe_dr_generate_ctx_t ctx) {
    struct dr_metalib_source_it source_it;
    dr_metalib_source_t source;
    struct mem_buffer buffer;
    struct write_stream_file stream;
    int i;
    FILE * fp;
    int rv;

    mem_buffer_init(&buffer, 0);

    rv = 0;
    for(i = 0; i < o_h->count; ++i) {
        dr_metalib_builder_sources(&source_it, ctx->m_builder);
        while((source = dr_metalib_source_next(&source_it))) {
            const char * file_name;

            if (dr_metalib_source_from(source) != dr_metalib_source_from_user) continue;

            file_name = dr_metalib_source_file(source);
            if (file_name == NULL) continue;

            mem_buffer_clear_data(&buffer);
            mem_buffer_strcat(&buffer, o_h->filename[i]);
            mem_buffer_strcat(&buffer, "/");
            file_name_append_base(&buffer, file_name);
            mem_buffer_strcat(&buffer, ".h");

            fp = file_stream_open((char *)mem_buffer_make_continuous(&buffer, 0), "w", ctx->m_em);
            if (fp == NULL) {
                rv = -1;
                continue;
            }

            write_stream_file_init(&stream, fp, ctx->m_em);
            cpe_dr_generate_h((write_stream_t)&stream, source, ctx);
            file_stream_close(fp, ctx->m_em);
        }
    }

    mem_buffer_clear(&buffer);

    return rv;
}
/* Closes the notification stream if opened using a filename
 * Returns 0 if successful or -1 on error
 */
int libsystem_notify_stream_close(
    liberror_error_t **error )
{
    static char *function = "libsystem_notify_stream_close";

    if( libsystem_notify_stream_opened_in_library != 0 )
    {
        if( file_stream_close(
                    libsystem_notify_stream ) != 0 )
        {
            liberror_error_set(
                error,
                LIBERROR_ERROR_DOMAIN_IO,
                LIBERROR_IO_ERROR_OPEN_FAILED,
                "%s: unable to close stream.",
                function );

            return( -1 );
        }
        libsystem_notify_stream                   = NULL;
        libsystem_notify_stream_opened_in_library = 0;
    }
    return( 0 );
}
Beispiel #5
0
static int do_generate_lib_bin(cpe_dr_generate_ctx_t ctx) {
    int i;
    int rv;

    rv = 0;

    for(i = 0; i < o_lib_bin->count; ++i) {
        FILE * fp;

        fp = file_stream_open(o_lib_bin->filename[i], "w", ctx->m_em);
        if (fp == NULL) {
            rv = -1;
            continue;
        }

        if (file_stream_write_from_buf(fp, ctx->m_metalib, dr_lib_size(ctx->m_metalib), ctx->m_em) <= 0) {
            rv = -1;
        }

        file_stream_close(fp, ctx->m_em);
    }

    return rv;
}