1buffer_init(3) Library Functions Manual buffer_init(3)
2
3
4
6 buffer_init - initialize buffer structure
7
9 #include <buffer.h>
10
11 void buffer_init(buffer &b,
12 ssize_t (*op)(int,char*,size_t),
13 int fd, char* y, size_t ylen);
14
16 buffer_init prepares b to store a string in y[0], y[1], ..., y[ylen-1].
17 Initially the string is empty.
18
19 buffer_init also prepares b to use the read/write operation specified
20 by op and fd.
21
22 You can use
23
24 buffer b = BUFFER_INIT(op,fd,y,ylen);
25
26 to initialize b statically if op, fd, y, and ylen are compile-time con‐
27 stants.
28
29 You can call buffer_init again at any time. Note that this discards the
30 currently buffered string.
31
33 #include <buffer.h>
34 #include <open.h>
35
36 char buf[4096];
37 int fd=open_read("/etc/services");
38 buffer input;
39
40 if (fd>=0) {
41 char x;
42 buffer_init(&input,read,fd,buf,sizeof buf);
43 while (buffer_get(&input,&x,1)==1) {
44 buffer_put(buffer_1,&x,1);
45 if (x=='\n') break;
46 }
47 buffer_flush(buffer_1);
48 }
49
50
52 buffer_flush(3), buffer(3)
53
54
55
56 buffer_init(3)