Browse Source

Fixed input buffers, thanks to David Lichteblau.

master
Felix von Leitner 19 years ago
parent
commit
3d345f814d
5 changed files with 13 additions and 11 deletions
  1. +1
    -0
      CHANGES
  2. +7
    -7
      buffer.h
  3. +2
    -1
      buffer/buffer_init.c
  4. +2
    -2
      buffer/buffer_put.c
  5. +1
    -1
      buffer/buffer_putalign.c

+ 1
- 0
CHANGES View File

@ -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.


+ 7
- 7
buffer.h View File

@ -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) \
)


+ 2
- 1
buffer/buffer_init.c View File

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

+ 2
- 2
buffer/buffer_put.c View File

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


+ 1
- 1
buffer/buffer_putalign.c View File

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


Loading…
Cancel
Save