int close(Process *p, FileDescriptor fd) { FileHandle *handle = p->fd_table[fd]; p->fd_table[fd] = NULL; return_fd(p, fd); delete_handle(handle); return 0; }
int mql_commit_transaction(char *name) { mqi_handle_t h; MDB_CHECKARG(name, -1); if ((h = delete_handle(name)) == MQI_HANDLE_INVALID) return -1; if (mqi_commit_transaction(h) < 0) return -1; return 0; }
static void on_feed_done_cb(void *data, struct sol_message_digest *md, struct sol_blob *input) { struct update_get_hash_handle *handle = data; char buf[CHUNK_SIZE], *blob_backend = NULL; struct sol_blob *blob = NULL; size_t size; bool last; int r; size = fread(buf, 1, sizeof(buf), handle->file); if (ferror(handle->file)) { SOL_WRN("Could not read file for feed hash algorithm"); goto err; } last = feof(handle->file); /* TODO Maybe this is a bug on sol_message_digest? Keeps calling on_feed_done * after send last chunk */ if (!size && last && input) { SOL_WRN("Nothing more to feed hash algorithm, ignoring on_feed_done request"); return; } blob_backend = malloc(size); SOL_NULL_CHECK_GOTO(blob_backend, err); blob = sol_blob_new(&SOL_BLOB_TYPE_DEFAULT, NULL, blob_backend, size); SOL_NULL_CHECK_GOTO(blob, err); memcpy(blob_backend, buf, size); r = sol_message_digest_feed(md, blob, last); SOL_INT_CHECK_GOTO(r, < 0, err); sol_blob_unref(blob); return; err: SOL_WRN("Could not feed data to check update file hash"); free(blob_backend); sol_blob_unref(blob); sol_message_digest_del(md); handle->cb((void *)handle->user_data, -EINVAL, NULL); delete_handle(handle); }
static void on_digest_ready_cb(void *data, struct sol_message_digest *md, struct sol_blob *output) { struct update_get_hash_handle *handle = data; struct sol_buffer buffer = SOL_BUFFER_INIT_EMPTY; struct sol_str_slice slice = sol_str_slice_from_blob(output); int r = 0; r = sol_buffer_append_as_base16(&buffer, slice, false); SOL_INT_CHECK_GOTO(r, < 0, end); end: handle->cb((void *)handle->user_data, r, (char *)buffer.data); sol_message_digest_del(md); sol_buffer_fini(&buffer); delete_handle(handle); }