本文整理汇总了C++中buffer_create函数的典型用法代码示例。如果您正苦于以下问题:C++ buffer_create函数的具体用法?C++ buffer_create怎么用?C++ buffer_create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了buffer_create函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: sprite_create
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;
}
开发者ID:ifzz,项目名称:merriment,代码行数:28,代码来源:sprite.c
示例2: callocz
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;
}
开发者ID:unclehowell,项目名称:WaveOS_App--netdata,代码行数:7,代码来源:web_server.c
示例3: io_create
/* 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);
}
开发者ID:mbeck-,项目名称:fdm,代码行数:31,代码来源:io.c
示例4: argos_net_client_create
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;
}
开发者ID:ianrose14,项目名称:argos,代码行数:58,代码来源:net.c
示例5: safe_malloc
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;
}
开发者ID:iagox86,项目名称:dnscat2,代码行数:12,代码来源:driver_command.c
示例6: main
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;
}
开发者ID:tiagogehring,项目名称:molch,代码行数:51,代码来源:crashtest-store.c
示例7: process_message_playerrequest
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);
}
}
开发者ID:jongtao,项目名称:benetnasch2,代码行数:34,代码来源:nethandlers.cpp
示例8: framer_initialize
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;
}
开发者ID:vogonsoft,项目名称:jabsocket,代码行数:32,代码来源:framer.c
示例9: win_create_chat
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;
}
开发者ID:AlexTalker,项目名称:profanity,代码行数:26,代码来源:window.c
示例10: buffer_create
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;
}
开发者ID:nfillmore,项目名称:cctools,代码行数:25,代码来源:chirp_ticket.c
示例11: op_delete
/*
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;
}
开发者ID:dgkang,项目名称:skynet_v0.1_with_notes,代码行数:41,代码来源:lua-mongo.c
示例12: buffer_create
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);
}
开发者ID:5up3rc,项目名称:hash_extender,代码行数:25,代码来源:formats.c
示例13: main
/**
* 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();
}
开发者ID:dyu,项目名称:librinoo,代码行数:31,代码来源:buffer_tolong.c
示例14: malloc
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;
}
开发者ID:qianlihu8906,项目名称:gwdata-server,代码行数:28,代码来源:seriport.c
示例15: assert
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;
}
开发者ID:bitpick,项目名称:coreboot,代码行数:30,代码来源:partitioned_file.c
示例16: prt_tree
/* 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);
}
开发者ID:transceptor-technology,项目名称:cleri,代码行数:36,代码来源:tree.c
示例17: load_settings
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;
}
开发者ID:TyRoXx,项目名称:webserver,代码行数:26,代码来源:main.c
示例18: print_udb_rr
/** 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);
}
开发者ID:LTD-Beget,项目名称:nsd,代码行数:34,代码来源:udb-inspect.c
示例19: ipv6_pseudo_header_create
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;
}
开发者ID:jordanauge,项目名称:libparistraceroute,代码行数:32,代码来源:ipv6_pseudo_header.c
示例20: query_create
/**
* 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;
}
开发者ID:jschlyter,项目名称:opendnssec-workflow-test,代码行数:39,代码来源:query.c
注:本文中的buffer_create函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论