mirror of /home/gitosis/repositories/libowfat.git
parent
4243bd22ec
commit
97161ed0df
10 changed files with 56 additions and 13 deletions
@ -1,10 +1,10 @@ |
||||
#include "buffer.h" |
||||
|
||||
extern int buffer_stubborn(ssize_t (*op)(),int fd,const char* buf, size_t len); |
||||
extern int buffer_stubborn(ssize_t (*op)(),int fd,const char* buf, size_t len,void* cookie); |
||||
|
||||
extern int buffer_flush(buffer* b) { |
||||
register int p; |
||||
if (!(p=b->p)) return 0; /* buffer already empty */ |
||||
b->p=0; |
||||
return buffer_stubborn(b->op,b->fd,b->x,p); |
||||
return buffer_stubborn(b->op,b->fd,b->x,p,b); |
||||
} |
||||
|
@ -0,0 +1,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; |
||||
} |
Loading…
Reference in new issue