File: buffer_tosa.c

package info (click to toggle)
libowfat 0.28-6
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 4,068 kB
  • sloc: ansic: 12,863; makefile: 16
file content (27 lines) | stat: -rw-r--r-- 511 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include "stralloc.h"
#include "buffer.h"

static ssize_t strallocwrite(int fd,char* buf,size_t len,void* myself) {
  buffer* b=myself;
  stralloc* sa=b->cookie;
  sa->len+=len;
  if (stralloc_readyplus(sa,1024)==0) return 0;
  b->x=sa->s+sa->len;
  b->p=0;
  b->a=1024;
  (void)fd;
  (void)buf;
  return len;
}

int buffer_tosa(buffer* b,stralloc* sa) {
  if (stralloc_ready(sa,1024)==0) return -1;
  b->x=sa->s;
  b->p=0;
  b->n=0;
  b->a=1024;
  b->fd=0;
  b->op=strallocwrite;
  b->cookie=sa;
  return 0;
}