Sprite* sprite_create(const char* texture_path) { Sprite* sprite = malloc(sizeof(*sprite)); if(sprite == NULL) { perror("Sprite creation"); return NULL; } strcpy(sprite->path, texture_path); sprite->texture = texture_load(sprite->path); sprite->width = texture_get_param(sprite->texture, GL_TEXTURE_WIDTH); sprite->height = texture_get_param(sprite->texture, GL_TEXTURE_HEIGHT); sprite->transform = m4_identity(); vec3 vertices[num_vertices]; vec3 scale = {sprite->width, sprite->height, 1}; int i; for(i = 0; i < num_vertices; ++i) { v3_scale(&vertices[i], &quad_vertices[i], &scale); } sprite->attributes[0].buffer = buffer_create(&vertices, sizeof(vertices)); sprite->attributes[0].size = 3; sprite->attributes[1].buffer = buffer_create(&quad_uv, sizeof(quad_uv)); sprite->attributes[1].size = 2; return sprite; }
static struct web_client *web_client_alloc(void) { struct web_client *w = callocz(1, sizeof(struct web_client)); w->response.data = buffer_create(NETDATA_WEB_RESPONSE_INITIAL_SIZE); w->response.header = buffer_create(NETDATA_WEB_RESPONSE_HEADER_SIZE); w->response.header_output = buffer_create(NETDATA_WEB_RESPONSE_HEADER_SIZE); return w; }
/* Create a struct io for the specified socket and SSL descriptors. */ struct io * io_create(int fd, SSL *ssl, const char *eol) { struct io *io; int mode; io = xcalloc(1, sizeof *io); io->fd = fd; io->ssl = ssl; io->dup_fd = -1; /* Set non-blocking. */ if ((mode = fcntl(fd, F_GETFL)) == -1) fatal("fcntl failed"); if (fcntl(fd, F_SETFL, mode|O_NONBLOCK) == -1) fatal("fcntl failed"); io->flags = 0; io->error = NULL; io->rd = buffer_create(IO_BLOCKSIZE); io->wr = buffer_create(IO_BLOCKSIZE); io->lbuf = NULL; io->llen = 0; io->eol = eol; return (io); }
struct argos_net_conn * argos_net_client_create(struct sockaddr_in *remote_addr, int dlt, const struct sockaddr_in *client_ip, size_t inbufsz, size_t outbufsz, size_t pktbufsz) { if (dlt < 0) { errno = EINVAL; return NULL; } /* inbufsz has to at least be big enough to hold a handshake message */ if (inbufsz < sizeof(struct argos_net_handshake_msg)) { errno = ENOSPC; return NULL; } struct argos_net_conn *conn = malloc(sizeof(struct argos_net_conn)); if (conn == NULL) return NULL; bzero(conn, sizeof(struct argos_net_conn)); conn->dlt = dlt; conn->state = ARGOS_NET_CONN_IDLE; memcpy(&conn->remote_addr, remote_addr, sizeof(struct sockaddr_in)); conn->init_backoff = ARGOS_NET_DEF_INIT_BACKOFF; conn->max_backoff = ARGOS_NET_DEF_MAX_BACKOFF; conn->cur_backoff = conn->init_backoff; conn->inbuf = buffer_create(inbufsz); if (conn->inbuf == NULL) goto fail; conn->outbuf = buffer_create(outbufsz); if (conn->outbuf == NULL) goto fail; conn->pktbuf = buffer_create(pktbufsz); if (conn->pktbuf == NULL) goto fail; /* outbuf and pktbuf should be empty! */ assert(buffer_len(conn->outbuf) == 0); assert(buffer_len(conn->pktbuf) == 0); conn->handshake.msgtype = htons(ARGOS_NET_HANDSHAKE_MSGTYPE); conn->handshake.msglen = htonl(sizeof(struct argos_net_handshake_msg)); conn->handshake.magicnum = htonl(ARGOS_NET_MAGICNUM); conn->handshake.major_version = htons(ARGOS_MAJOR_VERSION); conn->handshake.minor_version = htons(ARGOS_MINOR_VERSION); conn->handshake.dlt = htonl(conn->dlt); if (client_ip != NULL) conn->handshake.ip = client_ip->sin_addr.s_addr; /* start trying to connect */ attempt_connect(conn); return conn; fail: if (conn->inbuf != NULL) buffer_destroy(conn->inbuf); if (conn->outbuf != NULL) buffer_destroy(conn->outbuf); if (conn->pktbuf != NULL) buffer_destroy(conn->pktbuf); free(conn); return NULL; }
driver_command_t *driver_command_create(select_group_t *group) { driver_command_t *driver = (driver_command_t*) safe_malloc(sizeof(driver_command_t)); driver->stream = buffer_create(BO_BIG_ENDIAN); driver->group = group; driver->is_shutdown = FALSE; driver->outgoing_data = buffer_create(BO_LITTLE_ENDIAN); driver->tunnels = ll_create(NULL); return driver; }
int main(void) { sodium_init(); //create a user_store user_store *store = user_store_create(); //check the content buffer_t *list = user_store_list(store); if (list->content_length != 0) { fprintf(stderr, "ERROR: List of users is not empty.\n"); user_store_destroy(store); buffer_destroy_from_heap(list); return EXIT_FAILURE; } buffer_destroy_from_heap(list); int status; //create three users with prekeys and identity keys //first alice //alice identity key buffer_t *alice_private_identity = buffer_create(crypto_box_SECRETKEYBYTES, crypto_box_SECRETKEYBYTES); buffer_t *alice_public_identity = buffer_create(crypto_box_PUBLICKEYBYTES, crypto_box_PUBLICKEYBYTES); status = generate_and_print_keypair( alice_public_identity->content, alice_private_identity->content, "Alice", "identity"); if (status != 0) { fprintf(stderr, "ERROR: Failed to generate Alice's identity keypair.\n"); buffer_clear(alice_private_identity); return status; } //alice prekeys buffer_t *alice_private_prekeys = buffer_create(PREKEY_AMOUNT * crypto_box_SECRETKEYBYTES, PREKEY_AMOUNT * crypto_box_SECRETKEYBYTES); buffer_t *alice_public_prekeys = buffer_create(PREKEY_AMOUNT * crypto_box_PUBLICKEYBYTES, PREKEY_AMOUNT * crypto_box_PUBLICKEYBYTES); status = generate_prekeys(alice_private_prekeys, alice_public_prekeys); if (status != 0) { fprintf(stderr, "ERROR: Failed to generate Alice's prekeys.\n"); buffer_clear(alice_private_identity); buffer_clear(alice_private_prekeys); return status; } //make illegal access to the user store printf("User store length: %zi\n", store->length); //The program should crash here! user_store_destroy(store); return EXIT_SUCCESS; }
void process_message_playerrequest(Net::Connection * connection, double buffer) { if(Sys::PlayerList::FromConnection(connection) == NULL) { auto namelen = read_ubyte(buffer); auto name = read_string(buffer, namelen); auto player = new Sys::Player(Ent::New(), name); unsigned playerslot = Sys::PlayerList::AddPlayer(connection, player); auto serverplayer = Sys::PlayerList::Slots[playerslot]; player->spawn(Maps::width/2, Maps::height/2); auto response = buffer_create(); write_ubyte(response, namelen); write_string(response, name); write_ushort(response, Maps::width/2); write_ushort(response, Maps::height/2); // tell other players about the new player for ( unsigned i = 0; i+1/*last slot is joining player*/ < Sys::PlayerList::Slots.size(); ++i ) { auto current = Sys::PlayerList::Slots[i]->connection; std::cout << "Sending player " << playerslot << " to " << i << " (" << current->as_string() << ")\n"; Net::send(current, 0, SERVERMESSAGE::ADDPLAYER, response); } buffer_clear(response); // tell the new player about everyone, including theirself build_message_serveplayer(serverplayer, response); Net::send(connection, 0, SERVERMESSAGE::SERVEPLAYER, response); buffer_destroy(response); } }
static int framer_initialize(framer_t *framer) { framer_cleanup(framer); framer->parser = XML_ParserCreateNS(NULL, /* ':' */ '\xFF'); if (framer->parser == NULL) goto Error; XML_SetElementHandler( framer->parser, framer_start, framer_end); XML_SetUserData( framer->parser, framer); framer->level = 0; framer->error = 0; framer->index = 0; framer->buffer_index = 0; framer->head = framer->tail = NULL; framer->buffer = buffer_create(0); if (framer->buffer == NULL) goto Error; return 1; Error: if (framer->parser != NULL) XML_ParserFree(framer->parser); return 0; }
static int handle_global(cJSON *json, bool *globals_found) { struct nl_buffer *buffer; int error; if (!json) return 0; buffer = buffer_create(SEC_GLOBAL); if (!buffer) return -ENOMEM; for (json = json->child; json; json = json->next) { error = handle_global_field(json, buffer, globals_found); if (error) goto end; } error = nlbuffer_flush(buffer); /* Fall through. */ end: nlbuffer_destroy(buffer); return error; }
ProfWin* win_create_chat(const char * const barejid) { ProfWin *new_win = malloc(sizeof(ProfWin)); int cols = getmaxx(stdscr); new_win->type = WIN_CHAT; new_win->win = newpad(PAD_SIZE, (cols)); wbkgd(new_win->win, theme_attrs(THEME_TEXT)); new_win->from = strdup(barejid); new_win->buffer = buffer_create(); new_win->y_pos = 0; new_win->paged = 0; new_win->unread = 0; new_win->wins.chat.resource = NULL; new_win->wins.chat.is_otr = FALSE; new_win->wins.chat.is_trusted = FALSE; new_win->wins.chat.history_shown = FALSE; scrollok(new_win->win, TRUE); return new_win; }
static int handle_addr4_pool(cJSON *json, enum parse_section section) { struct nl_buffer *buffer; struct ipv4_prefix prefix; int error; if (!json) return 0; buffer = buffer_create(section); if (!buffer) return -ENOMEM; for (json = json->child; json; json = json->next) { error = str_to_prefix4(json->valuestring, &prefix); if (error) goto end; error = buffer_write(buffer, &prefix, sizeof(prefix), section); if (error) goto end; } error = nlbuffer_flush(buffer); /* Fall through. */ end: nlbuffer_destroy(buffer); return error; }
char *chirp_ticket_tostring(struct chirp_ticket *ct) { size_t n; const char *s; char *result; buffer_t *B; B = buffer_create(); buffer_printf(B, "subject \"%s\"\n", ct->subject); buffer_printf(B, "ticket \"%s\"\n", ct->ticket); buffer_printf(B, "expiration \"%lu\"\n", (unsigned long) ct->expiration); for(n = 0; n < ct->nrights; n++) { buffer_printf(B, "rights \"%s\" \"%s\"\n", ct->rights[n].directory, ct->rights[n].acl); } s = buffer_tostring(B, &n); result = xxmalloc(n + 1); memset(result, 0, n + 1); memcpy(result, s, n); buffer_delete(B); return result; }
/* 1 string collection 2 integer single remove 3 document selector return string package */ static int op_delete(lua_State *L) { document selector = lua_touserdata(L,3); if (selector == NULL) { luaL_error(L, "Invalid param"); } size_t sz = 0; const char * name = luaL_checklstring(L,1,&sz); luaL_Buffer b; luaL_buffinit(L,&b); struct buffer buf; buffer_create(&buf); int len = reserve_length(&buf); write_int32(&buf, 0); write_int32(&buf, 0); write_int32(&buf, OP_DELETE); write_int32(&buf, 0); write_string(&buf, name, sz); write_int32(&buf, lua_tointeger(L,2)); int32_t selector_len = get_length(selector); int total = buf.size + selector_len; write_length(&buf, total, len); luaL_addlstring(&b, (const char *)buf.ptr, buf.size); buffer_destroy(&buf); luaL_addlstring(&b, (const char *)selector, selector_len); luaL_pushresult(&b); return 1; }
static uint8_t *decode_hex(uint8_t *data, uint64_t data_length, uint64_t *out_length) { buffer_t *b = buffer_create(BO_HOST); uint64_t i = 0; /* If we wind up with an odd number of characters, the final character is * ignored. */ while(i + 1 < data_length) { /* Skip over and ignore non-hex digits. */ if(!isxdigit(data[i]) || !isxdigit(data[i+1])) { i++; continue; } /* Add the new character to the string as a uint8_t. */ buffer_add_int8(b, hex_to_int(&data[i])); /* We consumed three digits here. */ i += 2; } return buffer_create_string_and_destroy(b, out_length); }
/** * Main function for this unit test * * * @return 0 if test passed */ int main() { t_buffer *buffer; t_buffer buffer2; buffer = buffer_create(NULL); XTEST(buffer != NULL); XTEST(buffer_add(buffer, "123456789", 9) == 9); check_buf(buffer, 123456789); buffer_erase(buffer, buffer_size(buffer)); XTEST(buffer_add(buffer, "1", 1) == 1); check_buf(buffer, 1); buffer_erase(buffer, buffer_size(buffer)); XTEST(buffer_add(buffer, "-12345678", 9) == 9); check_buf(buffer, -12345678); buffer_erase(buffer, buffer_size(buffer)); buffer_destroy(buffer); strtobuffer(&buffer2, "987654321"); check_buf(&buffer2, 987654321); strtobuffer(&buffer2, "0"); check_buf(&buffer2, 0); strtobuffer(&buffer2, "-987654321"); check_buf(&buffer2, -987654321); XPASS(); }
static uint8_t *encode_html(uint8_t *data, uint64_t data_length, uint64_t *out_length) { int i; buffer_t *b = buffer_create(BO_HOST); char tmp[16]; for(i = 0; i < data_length; i++) { if(isalnum(data[i])) { /* If the character is alphanumeric, add it as-is. */ buffer_add_int8(b, data[i]); } else if(data[i] == ' ') { /* If the character is a space, add a '+'. */ buffer_add_int8(b, '+'); } else { /* Otherwise, encode it as a % followed by a hex code. */ sprintf(tmp, "%%%02x", data[i]); buffer_add_string(b, tmp); } } return buffer_create_string_and_destroy(b, out_length); }
static uint8_t *decode_html(uint8_t *data, uint64_t data_length, uint64_t *out_length) { buffer_t *b = buffer_create(BO_HOST); uint64_t i = 0; while(i < data_length) { /* If the character is a '%' and we aren't at the end of the string, decode * the hex character and add it to the string. * * The typecasts to 'int' here are to fix warnings from cygwin. */ if(data[i] == '%' && (i + 2) < data_length && isxdigit((int)data[i + 1]) && isxdigit((int)data[i + 2])) { /* Add the new character to the string as a uint8_t. */ buffer_add_int8(b, hex_to_int(&data[i] + 1)); /* We consumed three digits here. */ i += 3; } else if(data[i] == '+') { /* In html encoding, a '+' is a space. */ buffer_add_int8(b, ' '); i++; } else { /* If it's not %NN or +, it's just a raw number.k */ buffer_add_int8(b, data[i]); i++; } } return buffer_create_string_and_destroy(b, out_length); }
struct gwseriport *gwseriport_create(const char *ttypath,int uart_speed) { struct gwseriport *s = malloc(sizeof(*s)); if(s == NULL) return NULL; memset(s,0,sizeof(*s)); int fd = open_seriport(ttypath,uart_speed); if(fd < 0){ free(s); return NULL; } s->recvbuf = buffer_create(1024); s->fd = fd; s->ttypath = strdup(ttypath); if(aeCreateFileEvent(server.el,fd,AE_READABLE,seriportHandler,s) == AE_ERR){ close(fd); buffer_release(s->recvbuf); free(s); return NULL; } listAddNodeTail(server.seriports,s); return s; }
partitioned_file_t *partitioned_file_create_flat(const char *filename, size_t image_size) { assert(filename); struct partitioned_file *file = calloc(1, sizeof(*file)); if (!file) { ERROR("Failed to allocate partitioned file structure\n"); return NULL; } file->stream = fopen(filename, "wb"); if (!file->stream) { perror(filename); free(file); return NULL; } if (buffer_create(&file->buffer, image_size, filename)) { partitioned_file_close(file); return NULL; } if (!fill_ones_through(file)) { partitioned_file_close(file); return NULL; } return file; }
/* Prints the parse tree in JSON format. Note that the cl_obj is NULL for the root node and the first can be found in its children. */ void prt_tree(cleri_grammar_t * grammar, const char * str) { cleri_parse_t * pr = cleri_parse(grammar, str); if (pr == NULL) abort(); printf("Test string '%s': %s\n", str, pr->is_valid ? "true" : "false"); cleri_node_t * tree = pr->tree; /* Creates a dynamic buffer that will store the string to be parsed. If error occurs, NULL is returned and redirected to goto. */ buffer_t * buf = buffer_create(); if (buf == NULL) goto prt_tree; /* Check if the tree node (root node) has children and if true get_children() will be called. */ if (cleri_node_has_children(tree)) { cleri_children_t * child = tree->children; int rc = get_children(child, pr->str, buf); /* Prints the end result collected in buf->buf in JSON format including space, tabs and newlines */ if (!rc) { prt_JSON(buf->buf); } } buffer_destroy(buf); prt_tree: cleri_parse_free(pr); }
static bool load_settings( settings_t *settings, char const *file_name, log_t *log ) { buffer_t settings_content; buffer_create(&settings_content); if (!load_buffer_from_file_name(&settings_content, file_name)) { log_write(log, "Could not load settings file '%s'", file_name); buffer_destroy(&settings_content); return false; } if (!settings_create(settings, settings_content.data, settings_content.data + settings_content.size)) { buffer_destroy(&settings_content); return false; } buffer_destroy(&settings_content); return true; }
/** print one line with udb RR */ static void print_udb_rr(uint8_t* name, udb_ptr* urr) { buffer_type buffer; region_type* region = region_create(xalloc, free); region_type* tmpregion = region_create(xalloc, free); buffer_type* tmpbuffer = buffer_create(region, MAX_RDLENGTH); rr_type rr; ssize_t c; domain_table_type* owners; owners = domain_table_create(region); rr.owner = domain_table_insert(owners, dname_make(region, name, 0)); /* to RR */ rr.type = RR(urr)->type; rr.klass = RR(urr)->klass; rr.ttl = RR(urr)->ttl; buffer_create_from(&buffer, RR(urr)->wire, RR(urr)->len); c = rdata_wireformat_to_rdata_atoms(region, owners, RR(urr)->type, RR(urr)->len, &buffer, &rr.rdatas); if(c == -1) { printf("cannot parse wireformat\n"); region_destroy(region); return; } rr.rdata_count = c; print_rr(stdout, NULL, &rr, tmpregion, tmpbuffer); region_destroy(region); region_destroy(tmpregion); }
buffer_t * ipv6_pseudo_header_create(const uint8_t * ipv6_segment) { buffer_t * psh; const struct ip6_hdr * iph = (const struct ip6_hdr *) ipv6_segment; ipv6_pseudo_header_t * data; if (!(psh = buffer_create())) { goto ERR_BUFFER_CREATE; } if (!(buffer_resize(psh, sizeof(ipv6_pseudo_header_t)))) { goto ERR_BUFFER_RESIZE; } data = (ipv6_pseudo_header_t *) buffer_get_data(psh); memcpy((uint8_t *) data + offsetof(ipv6_pseudo_header_t, ip_src), &iph->ip6_src, sizeof(ipv6_t)); memcpy((uint8_t *) data + offsetof(ipv6_pseudo_header_t, ip_dst), &iph->ip6_dst, sizeof(ipv6_t)); // IPv6 stores a uint16 but our pseudo header uses an uint32 ... // So to take care of endianness we cannot directly copy the value. data->size = htonl(ntohs(iph->ip6_ctlun.ip6_un1.ip6_un1_plen)); data->zeros = 0; data->zero = 0; data->protocol = iph->ip6_ctlun.ip6_un1.ip6_un1_nxt; return psh; ERR_BUFFER_RESIZE: buffer_free(psh); ERR_BUFFER_CREATE: return NULL; }
/** * Create query. * */ query_type* query_create(void) { allocator_type* allocator = NULL; query_type* q = NULL; allocator = allocator_create(malloc, free); if (!allocator) { return NULL; } q = (query_type*) allocator_alloc(allocator, sizeof(query_type)); if (!q) { allocator_cleanup(allocator); return NULL; } q->allocator = allocator; q->buffer = NULL; q->tsig_rr = NULL; q->buffer = buffer_create(allocator, PACKET_BUFFER_SIZE); if (!q->buffer) { query_cleanup(q); return NULL; } q->tsig_rr = tsig_rr_create(allocator); if (!q->tsig_rr) { query_cleanup(q); return NULL; } q->edns_rr = edns_rr_create(allocator); if (!q->edns_rr) { query_cleanup(q); return NULL; } query_reset(q, UDP_MAX_MESSAGE_LEN, 0); return q; }
/* 1 string cursor_id return string package */ static int op_kill(lua_State *L) { size_t cursor_len = 0; const char * cursor_id = luaL_tolstring(L, 1, &cursor_len); if (cursor_len != 8) { return luaL_error(L, "Invalid cursor id"); } struct buffer buf; buffer_create(&buf); int len = reserve_length(&buf); write_int32(&buf, 0); write_int32(&buf, 0); write_int32(&buf, OP_KILL_CURSORS); write_int32(&buf, 0); write_int32(&buf, 1); write_bytes(&buf, cursor_id, 8); write_length(&buf, buf.size, len); lua_pushlstring(L, (const char *)buf.ptr, buf.size); buffer_destroy(&buf); return 1; }
static void compile_regexes(FileEntry *fileEntry) { BUFFER *bufRegex; int result; while (fileEntry->szParameter) { bufRegex = buffer_create(); buffer_append(bufRegex, "^[ \t]*"); buffer_append(bufRegex, fileEntry->szParameter); buffer_append(bufRegex, "[ \t]*=[ \t]*("); buffer_append(bufRegex, fileEntry->szRegex); buffer_append(bufRegex, ")[ \t]*"); fileEntry->pRegexCompiled = malloc(sizeof(regex_t)); if (!fileEntry->pRegexCompiled) { exit(EXIT_FAILURE); } result = regcomp( fileEntry->pRegexCompiled, buffer_data(bufRegex), REG_EXTENDED ); if (result) { exit(EXIT_FAILURE); } buffer_destroy(bufRegex); fileEntry++; } }
/* 1 integer id 2 string collection 3 integer number 4 cursor_id (8 bytes string/ 64bit) return string package */ static int op_get_more(lua_State *L) { int id = luaL_checkinteger(L, 1); size_t sz = 0; const char * name = luaL_checklstring(L,2,&sz); int number = luaL_checkinteger(L, 3); size_t cursor_len = 0; const char * cursor_id = luaL_tolstring(L, 4, &cursor_len); if (cursor_len != 8) { return luaL_error(L, "Invalid cursor id"); } struct buffer buf; buffer_create(&buf); int len = reserve_length(&buf); write_int32(&buf, id); write_int32(&buf, 0); write_int32(&buf, OP_GET_MORE); write_int32(&buf, 0); write_string(&buf, name, sz); write_int32(&buf, number); write_bytes(&buf, cursor_id, 8); write_length(&buf, buf.size, len); lua_pushlstring(L, (const char *)buf.ptr, buf.size); buffer_destroy(&buf); return 1; }
/* Add a job. */ struct job * job_add(struct jobs *jobs, int flags, struct client *c, const char *cmd, void (*callbackfn)(struct job *), void (*freefn)(void *), void *data) { struct job *job; job = xmalloc(sizeof *job); job->cmd = xstrdup(cmd); job->pid = -1; job->status = 0; job->client = c; job->fd = -1; job->out = buffer_create(BUFSIZ); job->callbackfn = callbackfn; job->freefn = freefn; job->data = data; job->flags = flags|JOB_DONE; if (jobs != NULL) RB_INSERT(jobs, jobs, job); SLIST_INSERT_HEAD(&all_jobs, job, lentry); return (job); }
static USocket * create_usock(int fd, struct sockaddr_in *addr, void *cred_p, int clen) { USocket *usock; if (connect(fd, (Sockaddr *)addr, sizeof(*addr)) < 0) return NULL; usock = (USocket *)malloc(sizeof(USocket)); if (!usock) return NULL; usock->fd = fd; usock->status = 0; usock->clen = clen; usock->tsize = 0; memcpy(usock->credv, cred_p, clen); pthread_mutex_init(&usock->rlock, NULL); pthread_mutex_init(&usock->wlock, NULL); pthread_cond_init(&usock->rcond, NULL); pthread_cond_init(&usock->wcond, NULL); usock->r_pack_count = 0; usock->w_pack_count = 1; usock->rbuf = buffer_create(MAX_UBUF); sem_init(&usock->sem, 0, 0); pthread_create(&usock->pid, NULL, usock_read_handler, usock); return usock; }
static int handle_pool6(cJSON *pool6_json) { struct nl_buffer *buffer; struct ipv6_prefix prefix; int error; if (!pool6_json) return 0; buffer = buffer_create(SEC_POOL6); if (!buffer) return -ENOMEM; error = str_to_prefix6(pool6_json->valuestring, &prefix); if (error) goto end; error = buffer_write(buffer, &prefix, sizeof(prefix), SEC_POOL6); if (error) goto end; error = nlbuffer_flush(buffer); /* Fall through. */ end: nlbuffer_destroy(buffer); return error; }