Browse Source

add buffer_fromarray, buffer_frombuf

master
Felix von Leitner 8 years ago
parent
commit
ba62b9d96f
  1. 6
      buffer.h
  2. 9
      buffer/buffer_fromarray.c
  3. 18
      buffer/buffer_frombuf.c
  4. 14
      buffer/buffer_fromsa.c

6
buffer.h

@ -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 */
#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
}
#endif

9
buffer/buffer_fromarray.c

@ -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);
}

18
buffer/buffer_frombuf.c

@ -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;
}

14
buffer/buffer_fromsa.c

@ -1,18 +1,6 @@
#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_fromsa(buffer* b,stralloc* sa) {
b->x=sa->s;
b->p=0;
b->n=sa->len;
b->a=sa->a;
b->fd=0;
b->op=dummyreadwrite;
buffer_frombuf(b,sa->s,sa->len);
}
Loading…
Cancel
Save