---
name: "buffer_init"
section: "3"
platform: "linux"
package: "libowfat-dev"
version: "0.32-5"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/buffer_init"
---

# buffer\_init(3)

initialize buffer structure

## NAME

buffer\_init - initialize buffer structure

## SYNTAX

**#include \<libowfat/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 \<libowfat/buffer.h\>\
   \#include \<libowfat/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_flush/3.md), [buffer(3)](/buffer/3.md)
