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; }
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; }
/* Opens the log handle * Returns 1 if successful or -1 on error */ int log_handle_open( log_handle_t *log_handle, const libcstring_system_character_t *filename, libcerror_error_t **error ) { static char *function = "log_handle_open"; 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( filename != NULL ) { #if defined( LIBCSTRING_HAVE_WIDE_SYSTEM_CHARACTER ) log_handle->log_stream = file_stream_open_wide( filename, _LIBCSTRING_SYSTEM_STRING( FILE_STREAM_OPEN_APPEND ) ); #else log_handle->log_stream = file_stream_open( filename, FILE_STREAM_OPEN_APPEND ); #endif if( log_handle->log_stream == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_OPEN_FAILED, "%s: unable to open file.", function ); return( -1 ); } } return( 1 ); }
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; }
/* Opens the notification stream using a filename * The stream is opened in append mode * Returns 1 if successful or -1 on error */ int libsystem_notify_stream_open( const char *filename, liberror_error_t **error ) { static char *function = "libsystem_notify_stream_open"; if( filename == NULL ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_ARGUMENTS, LIBERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid filename.", function ); return( -1 ); } if( ( libsystem_notify_stream_opened_in_library != 0 ) && ( libsystem_notify_stream_close( error ) != 0 ) ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_IO, LIBERROR_IO_ERROR_OPEN_FAILED, "%s: unable to close notify stream.", function ); return( -1 ); } libsystem_notify_stream = file_stream_open( filename, FILE_STREAM_OPEN_APPEND ); if( libsystem_notify_stream == NULL ) { switch( errno ) { case EACCES: liberror_error_set( error, LIBERROR_ERROR_DOMAIN_IO, LIBERROR_IO_ERROR_ACCESS_DENIED, "%s: access denied to file: %s.", function, filename ); break; case ENOENT: liberror_error_set( error, LIBERROR_ERROR_DOMAIN_IO, LIBERROR_IO_ERROR_INVALID_RESOURCE, "%s: no such file: %s.", function, filename ); break; default: liberror_error_set( error, LIBERROR_ERROR_DOMAIN_IO, LIBERROR_IO_ERROR_OPEN_FAILED, "%s: unable to open file: %s.", function, filename ); break; } return( -1 ); } libsystem_notify_stream_opened_in_library = 1; return( 1 ); }