add buffer_fromarray, buffer_frombuf

master
leitner 11 years ago
parent 875c0dc491
commit 24d8e81116

@ -143,6 +143,12 @@ void buffer_fromsa(buffer* b,stralloc* sa); /* read from sa */
int buffer_tosa(buffer*b,stralloc* sa); /* write to sa, auto-growing it */ int buffer_tosa(buffer*b,stralloc* sa); /* write to sa, auto-growing it */
#endif #endif
void buffer_frombuf(buffer* b,const char* x,size_t l); /* buffer reads from static buffer */
#ifdef ARRAY_H
void buffer_fromarray(buffer* b,array* a); /* buffer reads from array */
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

@ -0,0 +1,9 @@
#include "array.h"
#include "buffer.h"
void buffer_fromarray(buffer* b,array* a) {
if (array_failed(a))
buffer_frombuf(b,NULL,0);
else
buffer_frombuf(b,array_start(a),a->initialized);
}

@ -0,0 +1,18 @@
#include "stralloc.h"
#include "buffer.h"
static ssize_t dummyreadwrite(int fd,char* buf,size_t len) {
(void)fd;
(void)buf;
(void)len;
return 0;
}
void buffer_frombuf(buffer* b,const char* x,size_t l) {
b->x=x;
b->p=0;
b->n=l;
b->a=l;
b->fd=0;
b->op=dummyreadwrite;
}

@ -1,18 +1,6 @@
#include "stralloc.h" #include "stralloc.h"
#include "buffer.h" #include "buffer.h"
static ssize_t dummyreadwrite(int fd,char* buf,size_t len) {
(void)fd;
(void)buf;
(void)len;
return 0;
}
void buffer_fromsa(buffer* b,stralloc* sa) { void buffer_fromsa(buffer* b,stralloc* sa) {
b->x=sa->s; buffer_frombuf(b,sa->s,sa->len);
b->p=0;
b->n=sa->len;
b->a=sa->a;
b->fd=0;
b->op=dummyreadwrite;
} }

Loading…
Cancel
Save