int xml_writer_close(xml_writer_t *writer) { int rv = 0; if (writer->file && ferror(writer->file)) rv = -1; if (writer->file && !writer->noclose) { fclose(writer->file); writer->file = NULL; } if (writer->hash) { ni_hashctx_free(writer->hash); writer->hash = NULL; } return rv; }
/* * Create a new hash context */ ni_hashctx_t * __ni_hashctx_new(int algo) { ni_hashctx_t *ctx; gcry_error_t err; ctx = calloc(1, sizeof(*ctx)); err = gcry_md_open(&ctx->handle, algo, 0); if (err) { ni_error("%s: gcry_md_open failed", __func__); ni_hashctx_free(ctx); return NULL; } ctx->md_length = gcry_md_get_algo_dlen(algo); return ctx; }