Fixed input buffers, thanks to David Lichteblau.

master
leitner 23 years ago
parent b40bae5bf4
commit f6d554da10

@ -1,5 +1,6 @@
0.9: 0.9:
fmt_str did not check for out==NULL! Thanks, Uwe Ohse. fmt_str did not check for out==NULL! Thanks, Uwe Ohse.
Updated to buffer to fix read buffers. Thanks, David Lichteblau.
0.8: 0.8:
BSD compatibility. BSD compatibility.

@ -10,8 +10,8 @@ typedef struct buffer {
int (*op)(); int (*op)();
} buffer; } buffer;
#define BUFFER_INIT(op,fd,buf,len) { (buf), 0, (len), 0, (fd), (op) } #define BUFFER_INIT(op,fd,buf,len) { (buf), 0, 0, (len), (fd), (op) }
#define BUFFER_INIT_READ(op,fd,buf,len) { (buf), 0, 0, (len), (fd), (op) } #define BUFFER_INIT_READ(op,fd,buf,len) BUFFER_INIT(op,fd,buf,len) /*obsolete*/
#define BUFFER_INSIZE 8192 #define BUFFER_INSIZE 8192
#define BUFFER_OUTSIZE 8192 #define BUFFER_OUTSIZE 8192
@ -28,7 +28,7 @@ extern int buffer_putsflush(buffer* b,const char* x);
extern int buffer_putspace(buffer* b); extern int buffer_putspace(buffer* b);
#define buffer_PUTC(s,c) \ #define buffer_PUTC(s,c) \
( ((s)->n != (s)->p) \ ( ((s)->a != (s)->p) \
? ( (s)->x[(s)->p++] = (c), 0 ) \ ? ( (s)->x[(s)->p++] = (c), 0 ) \
: buffer_put((s),&(c),1) \ : buffer_put((s),&(c),1) \
) )
@ -44,12 +44,12 @@ extern int buffer_get_token(buffer* b,char* x,unsigned int len,const char* chars
extern char *buffer_peek(buffer* b); extern char *buffer_peek(buffer* b);
extern void buffer_seek(buffer* b,unsigned int len); extern void buffer_seek(buffer* b,unsigned int len);
#define buffer_PEEK(s) ( (s)->x + (s)->n ) #define buffer_PEEK(s) ( (s)->x + (s)->p )
#define buffer_SEEK(s,len) ( ( (s)->p -= (len) ) , ( (s)->n += (len) ) ) #define buffer_SEEK(s,len) ( (s)->p += (len) )
#define buffer_GETC(s,c) \ #define buffer_GETC(s,c) \
( ((s)->p > 0) \ ( ((s)->p < (s>->n) \
? ( *(c) = (s)->x[(s)->n], buffer_SEEK((s),1), 1 ) \ ? ( *(c) = *buffer_PEEK(s), buffer_SEEK((s),1), 1 ) \
: buffer_get((s),(c),1) \ : buffer_get((s),(c),1) \
) )

@ -4,6 +4,7 @@ void buffer_init(buffer* b,int (*op)(),int fd,char* y,unsigned int ylen) {
b->op=op; b->op=op;
b->fd=fd; b->fd=fd;
b->x=y; b->x=y;
b->n=ylen; b->a=ylen;
b->p=0; b->p=0;
b->n=0;
} }

@ -4,9 +4,9 @@
extern int buffer_stubborn(int (*op)(),int fd,const char* buf, unsigned int len); extern int buffer_stubborn(int (*op)(),int fd,const char* buf, unsigned int len);
int buffer_put(buffer* b,const char* buf,unsigned int len) { int buffer_put(buffer* b,const char* buf,unsigned int len) {
if (len>b->n-b->p) { /* doesn't fit */ if (len>b->a-b->p) { /* doesn't fit */
if (buffer_flush(b)==-1) return -1; if (buffer_flush(b)==-1) return -1;
if (len>b->n) { if (len>b->a) {
if (buffer_stubborn(b->op,b->fd,buf,len)<0) return -1; if (buffer_stubborn(b->op,b->fd,buf,len)<0) return -1;
return 0; return 0;
} }

@ -3,7 +3,7 @@
int buffer_putalign(buffer* b,const char* buf,unsigned int len) { int buffer_putalign(buffer* b,const char* buf,unsigned int len) {
int tmp; int tmp;
while (len>(tmp=b->n-b->p)) { while (len>(tmp=b->a-b->p)) {
byte_copy(b->x+b->p, tmp, buf); byte_copy(b->x+b->p, tmp, buf);
b->p+=tmp; b->p+=tmp;
buf+=tmp; buf+=tmp;

Loading…
Cancel
Save