buffer_init - Man Page

initialize buffer structure

Syntax

#include <buffer.h>

void buffer_init(buffer &b,
               ssize_t (*op)(int,char*,size_t),
               int fd, char* y, size_t ylen);

Description

buffer_init prepares b to store a string in y[0], y[1], ..., y[ylen-1].  Initially the string is empty.

buffer_init also prepares b to use the read/write operation specified by op and fd.

You can use

 buffer b = BUFFER_INIT(op,fd,y,ylen);

to initialize b statically if op, fd, y, and ylen are compile-time constants.

You can call buffer_init again at any time. Note that this discards the currently buffered string.

Example

 #include <buffer.h>
 #include <open.h>

 char buf[4096];
 int fd=open_read("/etc/services");
 buffer input;

 if (fd>=0) {
   char x;
   buffer_init(&input,read,fd,buf,sizeof buf);
   while (buffer_get(&input,&x,1)==1) {
     buffer_put(buffer_1,&x,1);
     if (x=='\n') break;
   }
   buffer_flush(buffer_1);
 }

See Also

buffer_flush(3), buffer(3)

Referenced By

buffer(3), buffer_close(3), buffer_feed(3), buffer_flush(3), buffer_fromarray(3), buffer_frombuf(3), buffer_fromsa(3), buffer_get(3), buffer_getc(3), buffer_getline(3), buffer_getn(3), buffer_get_token(3), buffer_get_token_pred(3), buffer_init_free(3), buffer_peek(3), buffer_seek(3), buffer_tosa(3).