|
|
@ -13,6 +13,13 @@
|
|
|
|
extern "C" {
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* dietlibc defines these in sys/cdefs.h, which is included from stddef.h */
|
|
|
|
|
|
|
|
#ifndef __writememsz__
|
|
|
|
|
|
|
|
#define __writememsz__(a,b)
|
|
|
|
|
|
|
|
#define __readmemsz__(a,b)
|
|
|
|
|
|
|
|
#define __readmem__(a)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct buffer {
|
|
|
|
typedef struct buffer {
|
|
|
|
char *x; /* actual buffer space */
|
|
|
|
char *x; /* actual buffer space */
|
|
|
|
size_t p; /* current position */
|
|
|
|
size_t p; /* current position */
|
|
|
@ -30,7 +37,9 @@ typedef struct buffer {
|
|
|
|
#define BUFFER_INSIZE 8192
|
|
|
|
#define BUFFER_INSIZE 8192
|
|
|
|
#define BUFFER_OUTSIZE 8192
|
|
|
|
#define BUFFER_OUTSIZE 8192
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__writememsz__(4,5)
|
|
|
|
void buffer_init(buffer* b,ssize_t (*op)(),int fd,char* y,size_t ylen);
|
|
|
|
void buffer_init(buffer* b,ssize_t (*op)(),int fd,char* y,size_t ylen);
|
|
|
|
|
|
|
|
__writememsz__(4,5)
|
|
|
|
void buffer_init_free(buffer* b,ssize_t (*op)(),int fd,char* y,size_t ylen);
|
|
|
|
void buffer_init_free(buffer* b,ssize_t (*op)(),int fd,char* y,size_t ylen);
|
|
|
|
void buffer_free(void* buf);
|
|
|
|
void buffer_free(void* buf);
|
|
|
|
void buffer_munmap(void* buf);
|
|
|
|
void buffer_munmap(void* buf);
|
|
|
@ -38,11 +47,17 @@ int buffer_mmapread(buffer* b,const char* filename);
|
|
|
|
void buffer_close(buffer* b);
|
|
|
|
void buffer_close(buffer* b);
|
|
|
|
|
|
|
|
|
|
|
|
int buffer_flush(buffer* b);
|
|
|
|
int buffer_flush(buffer* b);
|
|
|
|
|
|
|
|
__readmemsz__(2,3)
|
|
|
|
int buffer_put(buffer* b,const char* x,size_t len);
|
|
|
|
int buffer_put(buffer* b,const char* x,size_t len);
|
|
|
|
|
|
|
|
__readmemsz__(2,3)
|
|
|
|
int buffer_putalign(buffer* b,const char* x,size_t len);
|
|
|
|
int buffer_putalign(buffer* b,const char* x,size_t len);
|
|
|
|
|
|
|
|
__readmemsz__(2,3)
|
|
|
|
int buffer_putflush(buffer* b,const char* x,size_t len);
|
|
|
|
int buffer_putflush(buffer* b,const char* x,size_t len);
|
|
|
|
|
|
|
|
__readmem__(2)
|
|
|
|
int buffer_puts(buffer* b,const char* x);
|
|
|
|
int buffer_puts(buffer* b,const char* x);
|
|
|
|
|
|
|
|
__readmem__(2)
|
|
|
|
int buffer_putsalign(buffer* b,const char* x);
|
|
|
|
int buffer_putsalign(buffer* b,const char* x);
|
|
|
|
|
|
|
|
__readmem__(2)
|
|
|
|
int buffer_putsflush(buffer* b,const char* x);
|
|
|
|
int buffer_putsflush(buffer* b,const char* x);
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__LIBOWFAT_INTERNAL)
|
|
|
|
#if defined(__GNUC__) && !defined(__LIBOWFAT_INTERNAL)
|
|
|
@ -67,16 +82,21 @@ int buffer_putnlflush(buffer* b); /* put \n and flush */
|
|
|
|
: buffer_put((s),&(c),1) \
|
|
|
|
: buffer_put((s),&(c),1) \
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__writememsz__(2,3)
|
|
|
|
ssize_t buffer_get(buffer* b,char* x,size_t len);
|
|
|
|
ssize_t buffer_get(buffer* b,char* x,size_t len);
|
|
|
|
ssize_t buffer_feed(buffer* b);
|
|
|
|
ssize_t buffer_feed(buffer* b);
|
|
|
|
ssize_t buffer_getc(buffer* b,char* x);
|
|
|
|
ssize_t buffer_getc(buffer* b,char* x);
|
|
|
|
|
|
|
|
__writememsz__(2,3)
|
|
|
|
ssize_t buffer_getn(buffer* b,char* x,size_t len);
|
|
|
|
ssize_t buffer_getn(buffer* b,char* x,size_t len);
|
|
|
|
|
|
|
|
|
|
|
|
/* read bytes until the destination buffer is full (len bytes), end of
|
|
|
|
/* read bytes until the destination buffer is full (len bytes), end of
|
|
|
|
* file is reached or the read char is in charset (setlen bytes). An
|
|
|
|
* file is reached or the read char is in charset (setlen bytes). An
|
|
|
|
* empty line when looking for \n will write '\n' to x and return 0. If
|
|
|
|
* empty line when looking for \n will write '\n' to x and return 0. If
|
|
|
|
* EOF is reached, \0 is written to the buffer */
|
|
|
|
* EOF is reached, \0 is written to the buffer */
|
|
|
|
|
|
|
|
__writememsz__(2,3)
|
|
|
|
|
|
|
|
__readmemsz__(4,5)
|
|
|
|
ssize_t buffer_get_token(buffer* b,char* x,size_t len,const char* charset,size_t setlen);
|
|
|
|
ssize_t buffer_get_token(buffer* b,char* x,size_t len,const char* charset,size_t setlen);
|
|
|
|
|
|
|
|
__writememsz__(2,3)
|
|
|
|
ssize_t buffer_getline(buffer* b,char* x,size_t len);
|
|
|
|
ssize_t buffer_getline(buffer* b,char* x,size_t len);
|
|
|
|
|
|
|
|
|
|
|
|
/* this predicate is given the string as currently read from the buffer
|
|
|
|
/* this predicate is given the string as currently read from the buffer
|
|
|
@ -84,6 +104,7 @@ ssize_t buffer_getline(buffer* b,char* x,size_t len);
|
|
|
|
typedef int (*string_predicate)(const char* x,size_t len);
|
|
|
|
typedef int (*string_predicate)(const char* x,size_t len);
|
|
|
|
|
|
|
|
|
|
|
|
/* like buffer_get_token but the token ends when your predicate says so */
|
|
|
|
/* like buffer_get_token but the token ends when your predicate says so */
|
|
|
|
|
|
|
|
__writememsz__(2,3)
|
|
|
|
ssize_t buffer_get_token_pred(buffer* b,char* x,size_t len,string_predicate p);
|
|
|
|
ssize_t buffer_get_token_pred(buffer* b,char* x,size_t len,string_predicate p);
|
|
|
|
|
|
|
|
|
|
|
|
char *buffer_peek(buffer* b);
|
|
|
|
char *buffer_peek(buffer* b);
|
|
|
@ -133,11 +154,13 @@ int buffer_putsaflush(buffer* b,const stralloc* sa);
|
|
|
|
* data is available. */
|
|
|
|
* data is available. */
|
|
|
|
|
|
|
|
|
|
|
|
/* read token from buffer to stralloc */
|
|
|
|
/* read token from buffer to stralloc */
|
|
|
|
|
|
|
|
__readmemsz__(3,4)
|
|
|
|
int buffer_get_token_sa(buffer* b,stralloc* sa,const char* charset,size_t setlen);
|
|
|
|
int buffer_get_token_sa(buffer* b,stralloc* sa,const char* charset,size_t setlen);
|
|
|
|
/* read line from buffer to stralloc */
|
|
|
|
/* read line from buffer to stralloc */
|
|
|
|
int buffer_getline_sa(buffer* b,stralloc* sa);
|
|
|
|
int buffer_getline_sa(buffer* b,stralloc* sa);
|
|
|
|
|
|
|
|
|
|
|
|
/* same as buffer_get_token_sa but empty sa first */
|
|
|
|
/* same as buffer_get_token_sa but empty sa first */
|
|
|
|
|
|
|
|
__readmemsz__(3,4)
|
|
|
|
int buffer_get_new_token_sa(buffer* b,stralloc* sa,const char* charset,size_t setlen);
|
|
|
|
int buffer_get_new_token_sa(buffer* b,stralloc* sa,const char* charset,size_t setlen);
|
|
|
|
/* same as buffer_getline_sa but empty sa first */
|
|
|
|
/* same as buffer_getline_sa but empty sa first */
|
|
|
|
int buffer_getnewline_sa(buffer* b,stralloc* sa);
|
|
|
|
int buffer_getnewline_sa(buffer* b,stralloc* sa);
|
|
|
@ -155,6 +178,7 @@ void buffer_fromsa(buffer* b,const 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__readmemsz__(2,3)
|
|
|
|
void buffer_frombuf(buffer* b,const char* x,size_t l); /* buffer reads from static buffer */
|
|
|
|
void buffer_frombuf(buffer* b,const char* x,size_t l); /* buffer reads from static buffer */
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef ARRAY_H
|
|
|
|
#ifdef ARRAY_H
|
|
|
|