本文整理汇总了C++中buf_init函数的典型用法代码示例。如果您正苦于以下问题:C++ buf_init函数的具体用法?C++ buf_init怎么用?C++ buf_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了buf_init函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: decode_vrrp
int
decode_vrrp(u_char *buf, int len, u_char *obuf, int olen)
{
struct buf *b, inbuf, outbuf;
struct vrrp_header *vrrp;
buf_init(&inbuf, buf, len);
buf_init(&outbuf, obuf, olen);
vrrp = (struct vrrp_header *)buf_ptr(&inbuf);
if (buf_len(&inbuf) < sizeof(*vrrp))
return (0);
/* We only care about VRRP_AUTH_SIMPLE */
if (ntohs(vrrp->vr_auth) != VRRP_AUTH_SIMPLE)
return (0);
/* XXX - probably want to verify checksum */
/* Forward to Authentication Data */
buf_skip(&inbuf, sizeof(*vrrp) + 8 + (vrrp->vr_naddr * 4));
if ((b = buf_tok(&inbuf, NULL, VRRP_AUTH_DATA_LEN)) == NULL)
return (0);
buf_put(&outbuf, buf_ptr(b), buf_len(b));
buf_put(&outbuf, "\n", 1);
buf_end(&outbuf);
return (buf_len(&outbuf));
}
示例2: output_init
/*---------------------------------------------------------------------------*/
void output_init(unsigned outputbuf_size, struct thread_ctx_s *ctx) {
LOG_DEBUG("[%p] init output media renderer", ctx);
ctx->outputbuf = &ctx->__o_buf;
buf_init(ctx->outputbuf, outputbuf_size);
if (!ctx->outputbuf->buf) {
LOG_ERROR("[%p]: unable to malloc output buffer", ctx);
exit(0);
}
if (strcasecmp(ctx->config.encode, "thru")) {
ctx->encodebuf = &ctx->__e_buf;
buf_init(ctx->encodebuf, outputbuf_size);
if (!ctx->encodebuf->buf) {
LOG_ERROR("[%p]: unable to malloc output buffer", ctx);
exit(0);
}
}
ctx->output.track_started = false;
ctx->output.track_start = NULL;
ctx->output_running = THREAD_KILLED;
ctx->output.http = -1;
ctx->output.icy.artist = ctx->output.icy.title = ctx->output.icy.artwork = NULL;
ctx->render.index = -1;
}
示例3: decode_imap
int
decode_imap(u_char *buf, int len, u_char *obuf, int olen)
{
struct buf *line, inbuf, outbuf;
int i;
buf_init(&inbuf, buf, len);
buf_init(&outbuf, obuf, olen);
while ((i = buf_index(&inbuf, "\r\n", 2)) != -1) {
line = buf_tok(&inbuf, NULL, i);
buf_skip(&inbuf, 2);
if ((i = buf_index(line, " ", 1)) != -1) {
buf_skip(line, i + 1);
if (buf_cmp(line, "LOGIN ", 6) == 0) {
buf_putf(&outbuf, "%.*s\n",
buf_len(line), buf_ptr(line));
}
}
}
buf_end(&outbuf);
return (buf_len(&outbuf));
}
示例4: test_crypto
void
test_crypto (const struct crypto_options *co, struct frame* frame)
{
int i, j;
struct gc_arena gc = gc_new ();
struct buffer src = alloc_buf_gc (TUN_MTU_SIZE (frame), &gc);
struct buffer work = alloc_buf_gc (BUF_SIZE (frame), &gc);
struct buffer encrypt_workspace = alloc_buf_gc (BUF_SIZE (frame), &gc);
struct buffer decrypt_workspace = alloc_buf_gc (BUF_SIZE (frame), &gc);
struct buffer buf = clear_buf();
/* init work */
ASSERT (buf_init (&work, FRAME_HEADROOM (frame)));
msg (M_INFO, "Entering " PACKAGE_NAME " crypto self-test mode.");
for (i = 1; i <= TUN_MTU_SIZE (frame); ++i)
{
update_time ();
msg (M_INFO, "TESTING ENCRYPT/DECRYPT of packet length=%d", i);
/*
* Load src with random data.
*/
ASSERT (buf_init (&src, 0));
ASSERT (i <= src.capacity);
src.len = i;
ASSERT (rand_bytes (BPTR (&src), BLEN (&src)));
/* copy source to input buf */
buf = work;
memcpy (buf_write_alloc (&buf, BLEN (&src)), BPTR (&src), BLEN (&src));
/* encrypt */
openvpn_encrypt (&buf, encrypt_workspace, co, frame);
/* decrypt */
openvpn_decrypt (&buf, decrypt_workspace, co, frame);
/* compare */
if (buf.len != src.len)
msg (M_FATAL, "SELF TEST FAILED, src.len=%d buf.len=%d", src.len, buf.len);
for (j = 0; j < i; ++j)
{
const uint8_t in = *(BPTR (&src) + j);
const uint8_t out = *(BPTR (&buf) + j);
if (in != out)
msg (M_FATAL, "SELF TEST FAILED, pos=%d in=%d out=%d", j, in, out);
}
}
msg (M_INFO, PACKAGE_NAME " crypto self-test mode SUCCEEDED.");
gc_free (&gc);
}
示例5: network_init
void network_init(struct network *net)
{
memset(net, 0, sizeof(struct network));
net->portno = DEFAULT_PORT;
net->conf = prog_config.net_global_conf;
buf_init(&net->sock);
buf_init(&net->cmdfd);
net->joinedfd = -1;
net->motdfd = -1;
net->rawfd = -1;
net->realnamefd = -1;
net->nicknamefd = -1;
}
示例6: status_flush
void
status_flush(struct status_output *so)
{
if (so && so->fd >= 0 && (so->flags & STATUS_OUTPUT_WRITE))
{
#if defined(HAVE_FTRUNCATE)
{
const off_t off = lseek(so->fd, (off_t)0, SEEK_CUR);
if (ftruncate(so->fd, off) != 0)
{
msg(M_WARN, "Failed to truncate status file: %s", strerror(errno));
}
}
#elif defined(HAVE_CHSIZE)
{
const long off = (long) lseek(so->fd, (off_t)0, SEEK_CUR);
chsize(so->fd, off);
}
#else /* if defined(HAVE_FTRUNCATE) */
#warning both ftruncate and chsize functions appear to be missing from this OS
#endif
/* clear read buffer */
if (buf_defined(&so->read_buf))
{
ASSERT(buf_init(&so->read_buf, 0));
}
}
}
示例7: kmain
void kmain(u32 init_stack) {
init_esp_start = init_stack;
init_video();
puts_color_str("Booting Panda OS ...\n", 0x0B);
cli();
time_init();
gdt_init();
idt_init();
kb_init();
mm_init();
buf_init();
file_init();
inode_init();
ide_init();
task_init();
timer_init();
sysc_init();
spawn(init_user);
sti();
init = 0;
while(1) {
if(!init) {
printk("kernel running ...\n");
init = 1;
}
sti();
sched();
}
}
示例8: PyString_FromString
static PyObject *quote_literal_body(unsigned char *src, Py_ssize_t src_len)
{
struct Buf buf;
unsigned char *esc, *dst, *src_end = src + src_len;
unsigned int start_ofs = 1;
if (src == NULL)
return PyString_FromString("null");
esc = dst = buf_init(&buf, src_len * 2 + 2 + 1);
if (!dst)
return NULL;
*dst++ = ' ';
*dst++ = '\'';
while (src < src_end) {
if (*src == '\\') {
*dst++ = '\\';
start_ofs = 0;
} else if (*src == '\'') {
*dst++ = '\'';
}
*dst++ = *src++;
}
*dst++ = '\'';
if (start_ofs == 0)
*esc = 'E';
return buf_pystr(&buf, start_ofs, dst);
}
示例9: mass_init
static void mass_init(int argc, char **argv)
{
option_init(argc, argv);
if (!option_output_file)
option_output_file = "a.out";
if (!option_input_file)
{
errmsg("mass: error: no input file specified\n");
exit(0);
}
FILE *tmp_in = fopen(option_input_file, "r");
if (!tmp_in)
{
errmsg("mass: error: %s: %s\n", option_input_file, strerror(errno));
exit(0);
}
yyset_in(tmp_in);
symbol_table_init();
buf_init();
return;
}
示例10: main
int
main()
{
buf_pool_t *sp ;
sp = buf_init(PROD_NUM,sizeof(test_ar_t));
int res ;
pthread_t tid[THREAD_NUM] ; //store to child pthread
pthread_t master_tid ;
fprintPt(pthread_self());
res = pthread_create(&master_tid,NULL,master_thread_function,sp);
if (res != 0)
{
fprintf(stderr,"pthread was create error \n");
exit(EXIT_FAILURE);
}
for(int i = 0 ;i < THREAD_NUM ;i++) //the child thread
{
res = pthread_create(&tid[i],NULL,thread_function,sp);
if (res != 0)
{
fprintf(stderr,"pthread was create error \n");
exit(EXIT_FAILURE);
}
}
printf("master thread : %lu \n ", pthread_self());
sleep(20);
release(sp);
return 0;
}
示例11: PROCESS_THREAD
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(telnetd_process, ev, data)
{
PROCESS_BEGIN();
tcp_listen(HTONS(23));
buf_init(&buf);
shell_init();
#if TELNETD_CONF_GUI
telnetd_gui_init();
#endif /* TELNETD_CONF_GUI */
while(1) {
PROCESS_WAIT_EVENT();
if(ev == tcpip_event) {
telnetd_appcall(data);
} else if(ev == PROCESS_EVENT_EXIT) {
telnetd_quit();
} else {
#if TELNETD_CONF_GUI
telnetd_gui_eventhandler(ev, data);
#endif /* TELNETD_CONF_GUI */
}
}
PROCESS_END();
}
示例12: FsMountVol
/* FsMountVol : mount the file system volume */
INT32 FsMountVol(struct super_block *sb)
{
INT32 err, drv;
sm_P(&z_sem);
for (drv = 0; drv < MAX_DRIVE; drv++) {
if (!fs_struct[drv].mounted) break;
}
if (drv >= MAX_DRIVE) {
err = FFS_ERROR;
goto ret_unlock;
}
sm_P(&(fs_struct[drv].v_sem));
err = buf_init(sb);
if (!err) {
err = ffsMountVol(sb, drv);
}
sm_V(&(fs_struct[drv].v_sem));
if (!err) {
fs_struct[drv].mounted = TRUE;
fs_struct[drv].sb = sb;
} else {
buf_shutdown(sb);
}
ret_unlock:
sm_V(&z_sem);
return(err);
} /* end of FsMountVol */
示例13: buf_assign
bool
buf_assign (struct buffer *dest, const struct buffer *src)
{
if (!buf_init (dest, src->offset))
return false;
return buf_write (dest, BPTR (src), BLEN (src));
}
示例14: ld_ataraid_make_cbuf
static struct cbuf *
ld_ataraid_make_cbuf(struct ld_ataraid_softc *sc, struct buf *bp,
u_int comp, daddr_t bn, void *addr, long bcount)
{
struct cbuf *cbp;
cbp = CBUF_GET();
if (cbp == NULL)
return (NULL);
buf_init(&cbp->cb_buf);
cbp->cb_buf.b_flags = bp->b_flags;
cbp->cb_buf.b_oflags = bp->b_oflags;
cbp->cb_buf.b_cflags = bp->b_cflags;
cbp->cb_buf.b_iodone = sc->sc_iodone;
cbp->cb_buf.b_proc = bp->b_proc;
cbp->cb_buf.b_vp = sc->sc_vnodes[comp];
cbp->cb_buf.b_objlock = &sc->sc_vnodes[comp]->v_interlock;
cbp->cb_buf.b_blkno = bn + sc->sc_aai->aai_offset;
cbp->cb_buf.b_data = addr;
cbp->cb_buf.b_bcount = bcount;
/* Context for iodone */
cbp->cb_obp = bp;
cbp->cb_sc = sc;
cbp->cb_comp = comp;
cbp->cb_other = NULL;
cbp->cb_flags = 0;
return (cbp);
}
示例15: buf_reset
/* Reset to search beginning of buffer, looking for tag */
static void buf_reset(int source, int tag) {
assert( source != MPI_ANY_SOURCE );
if ( recv_buf == NULL )
buf_init();
recv_buf[source].curs = 0;
recv_buf[source].tag = tag;
}