version 1.16, 2002/06/26 08:54:18 |
version 1.16.4.2, 2003/09/16 21:30:49 |
|
|
void |
void |
buffer_init(Buffer *buffer) |
buffer_init(Buffer *buffer) |
{ |
{ |
buffer->alloc = 4096; |
const u_int len = 4096; |
buffer->buf = xmalloc(buffer->alloc); |
|
|
buffer->alloc = 0; |
|
buffer->buf = xmalloc(len); |
|
buffer->alloc = len; |
buffer->offset = 0; |
buffer->offset = 0; |
buffer->end = 0; |
buffer->end = 0; |
} |
} |
|
|
void |
void |
buffer_free(Buffer *buffer) |
buffer_free(Buffer *buffer) |
{ |
{ |
memset(buffer->buf, 0, buffer->alloc); |
if (buffer->alloc > 0) { |
xfree(buffer->buf); |
memset(buffer->buf, 0, buffer->alloc); |
|
xfree(buffer->buf); |
|
} |
} |
} |
|
|
/* |
/* |
|
|
void * |
void * |
buffer_append_space(Buffer *buffer, u_int len) |
buffer_append_space(Buffer *buffer, u_int len) |
{ |
{ |
|
u_int newlen; |
void *p; |
void *p; |
|
|
if (len > 0x100000) |
if (len > 0x100000) |
|
|
goto restart; |
goto restart; |
} |
} |
/* Increase the size of the buffer and retry. */ |
/* Increase the size of the buffer and retry. */ |
buffer->alloc += len + 32768; |
|
if (buffer->alloc > 0xa00000) |
newlen = buffer->alloc + len + 32768; |
|
if (newlen > 0xa00000) |
fatal("buffer_append_space: alloc %u not supported", |
fatal("buffer_append_space: alloc %u not supported", |
buffer->alloc); |
newlen); |
buffer->buf = xrealloc(buffer->buf, buffer->alloc); |
buffer->buf = xrealloc(buffer->buf, newlen); |
|
buffer->alloc = newlen; |
goto restart; |
goto restart; |
/* NOTREACHED */ |
/* NOTREACHED */ |
} |
} |