From f6d554da10d73af6856da03013a8915d5e187561 Mon Sep 17 00:00:00 2001 From: leitner Date: Sun, 25 Nov 2001 22:37:38 +0000 Subject: [PATCH] Fixed input buffers, thanks to David Lichteblau. --- CHANGES | 1 + buffer.h | 14 +++++++------- buffer/buffer_init.c | 3 ++- buffer/buffer_put.c | 4 ++-- buffer/buffer_putalign.c | 2 +- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/CHANGES b/CHANGES index 18bb8e9..1f3a8ad 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,6 @@ 0.9: fmt_str did not check for out==NULL! Thanks, Uwe Ohse. + Updated to buffer to fix read buffers. Thanks, David Lichteblau. 0.8: BSD compatibility. diff --git a/buffer.h b/buffer.h index cb7c4e7..bf00102 100644 --- a/buffer.h +++ b/buffer.h @@ -10,8 +10,8 @@ typedef struct buffer { int (*op)(); } buffer; -#define BUFFER_INIT(op,fd,buf,len) { (buf), 0, (len), 0, (fd), (op) } -#define BUFFER_INIT_READ(op,fd,buf,len) { (buf), 0, 0, (len), (fd), (op) } +#define BUFFER_INIT(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_OUTSIZE 8192 @@ -28,7 +28,7 @@ extern int buffer_putsflush(buffer* b,const char* x); extern int buffer_putspace(buffer* b); #define buffer_PUTC(s,c) \ - ( ((s)->n != (s)->p) \ + ( ((s)->a != (s)->p) \ ? ( (s)->x[(s)->p++] = (c), 0 ) \ : 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 void buffer_seek(buffer* b,unsigned int len); -#define buffer_PEEK(s) ( (s)->x + (s)->n ) -#define buffer_SEEK(s,len) ( ( (s)->p -= (len) ) , ( (s)->n += (len) ) ) +#define buffer_PEEK(s) ( (s)->x + (s)->p ) +#define buffer_SEEK(s,len) ( (s)->p += (len) ) #define buffer_GETC(s,c) \ - ( ((s)->p > 0) \ - ? ( *(c) = (s)->x[(s)->n], buffer_SEEK((s),1), 1 ) \ + ( ((s)->p < (s>->n) \ + ? ( *(c) = *buffer_PEEK(s), buffer_SEEK((s),1), 1 ) \ : buffer_get((s),(c),1) \ ) diff --git a/buffer/buffer_init.c b/buffer/buffer_init.c index 6989936..e6adb05 100644 --- a/buffer/buffer_init.c +++ b/buffer/buffer_init.c @@ -4,6 +4,7 @@ void buffer_init(buffer* b,int (*op)(),int fd,char* y,unsigned int ylen) { b->op=op; b->fd=fd; b->x=y; - b->n=ylen; + b->a=ylen; b->p=0; + b->n=0; } diff --git a/buffer/buffer_put.c b/buffer/buffer_put.c index ad16aab..d53b6cc 100644 --- a/buffer/buffer_put.c +++ b/buffer/buffer_put.c @@ -4,9 +4,9 @@ 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) { - 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 (len>b->n) { + if (len>b->a) { if (buffer_stubborn(b->op,b->fd,buf,len)<0) return -1; return 0; } diff --git a/buffer/buffer_putalign.c b/buffer/buffer_putalign.c index 8b901bc..0ff1cd4 100644 --- a/buffer/buffer_putalign.c +++ b/buffer/buffer_putalign.c @@ -3,7 +3,7 @@ int buffer_putalign(buffer* b,const char* buf,unsigned int len) { int tmp; - while (len>(tmp=b->n-b->p)) { + while (len>(tmp=b->a-b->p)) { byte_copy(b->x+b->p, tmp, buf); b->p+=tmp; buf+=tmp;