buffer.c revision f8d63d12dd6fe15de6a1339722c61b030d1e5bad
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * Copyright (C) 1998, 1999 Internet Software Consortium.
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * Permission to use, copy, modify, and distribute this software for any
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * purpose with or without fee is hereby granted, provided that the above
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * copyright notice and this permission notice appear in all copies.
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
1ccbfca64ae86ace521053773001cb995352f96fBob Halleyisc_buffer_init(isc_buffer_t *b, void *base, unsigned int length,
1ccbfca64ae86ace521053773001cb995352f96fBob Halley unsigned int type)
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * Make 'b' refer to the 'length'-byte region starting at base.
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * Make 'b' an invalid buffer.
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * The type of 'b'.
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley return (b->type);
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleyisc_buffer_region(isc_buffer_t *b, isc_region_t *r) {
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * Make 'r' refer to the region of 'b'.
1ccbfca64ae86ace521053773001cb995352f96fBob Halleyisc_buffer_used(isc_buffer_t *b, isc_region_t *r) {
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * Make 'r' refer to the used region of 'b'.
1ccbfca64ae86ace521053773001cb995352f96fBob Halleyisc_buffer_available(isc_buffer_t *b, isc_region_t *r) {
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * Make 'r' refer to the available region of 'b'.
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * Increase the 'used' region of 'b' by 'n' bytes.
1ccbfca64ae86ace521053773001cb995352f96fBob Halleyisc_buffer_subtract(isc_buffer_t *b, unsigned int n) {
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * Decrease the 'used' region of 'b' by 'n' bytes.
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * Make the used region empty.
a99979c686ae04efd55ba8f0aacf32493b4aa7faBob Halleyisc_buffer_consumed(isc_buffer_t *b, isc_region_t *r) {
a99979c686ae04efd55ba8f0aacf32493b4aa7faBob Halley * Make 'r' refer to the consumed region of 'b'.
48481c9b6e19501457bcbc2995555412f352b99fBob Halleyisc_buffer_remaining(isc_buffer_t *b, isc_region_t *r) {
b03b67a6f1ea2966367e7beb2ef276ed6a1d3f92Bob Halley * Make 'r' refer to the remaining region of 'b'.
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleyisc_buffer_active(isc_buffer_t *b, isc_region_t *r) {
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * Make 'r' refer to the active region of 'b'.
1ccbfca64ae86ace521053773001cb995352f96fBob Halleyisc_buffer_setactive(isc_buffer_t *b, unsigned int n) {
1ccbfca64ae86ace521053773001cb995352f96fBob Halley unsigned int active;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * Sets the end of the active region 'n' bytes after current.
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley * Make the consumed region empty.
b8862d5130b88e7b1a257997d7909f769716d51cBob Halleyisc_buffer_forward(isc_buffer_t *b, unsigned int n) {
b8862d5130b88e7b1a257997d7909f769716d51cBob Halley * Increase the 'consumed' region of 'b' by 'n' bytes.
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleyisc_buffer_back(isc_buffer_t *b, unsigned int n) {
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * Decrease the 'consumed' region of 'b' by 'n' bytes.
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley unsigned int length;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * Compact the used region by moving the remaining region so it occurs
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * at the start of the buffer. The used region is shrunk by the size
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * of the consumed region, and the consumed region is then made empty.
ced5499494f8afba75c056eb2f3933de24a5f360Bob Halley unsigned char *cp;
e7e2e948e37a0eeb93b0d4f2390f38ed2d9dcd82Bob Halley * Read an unsigned 8-bit integer from 'b' and return it.
1ccbfca64ae86ace521053773001cb995352f96fBob Halleyisc_buffer_putuint8(isc_buffer_t *b, isc_uint8_t val)
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley unsigned char *cp;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley unsigned char *cp;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley * Read an unsigned 16-bit integer in network byte order from 'b',
1ccbfca64ae86ace521053773001cb995352f96fBob Halley * convert it to host byte order, and return it.
097c31fdea44383b7ce95345a66489040ad5e333Bob Halleyisc_buffer_putuint16(isc_buffer_t *b, isc_uint16_t val)
097c31fdea44383b7ce95345a66489040ad5e333Bob Halley unsigned char *cp;
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley unsigned char *cp;
6bb7b678f50a61dccad0bb3db4c26f73b59d8c16Bob Halley * Read an unsigned 32-bit integer in network byte order from 'b',
8c65ae482a50bed3184026301c6f99f32a683dbfBob Halley * convert it to host byte order, and return it.
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleyisc_buffer_putuint32(isc_buffer_t *b, isc_uint32_t val)
63e6086ef99eca768a4cd69871038181251905bbBob Halley unsigned char *cp;
63e6086ef99eca768a4cd69871038181251905bbBob Halley cp[0] = (unsigned char)((val & 0xff000000) >> 24);
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halley cp[1] = (unsigned char)((val & 0x00ff0000) >> 16);
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halley cp[2] = (unsigned char)((val & 0x0000ff00) >> 8);
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halleyisc_buffer_putmem(isc_buffer_t *b, unsigned char *base, unsigned int length)
efe6d8f0665b466052910e8efd4b031dc048f196Bob Halley unsigned char *cp;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleyisc_buffer_putstr(isc_buffer_t *b, const char *source) {
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley unsigned int l;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley unsigned char *cp;
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halleyisc_buffer_copyregion(isc_buffer_t *b, isc_region_t *r) {
62837b832f6a9999976d607eb0a9125bbbbb138bBob Halley unsigned char *base;
1ccbfca64ae86ace521053773001cb995352f96fBob Halley unsigned int available;
return (ISC_R_NOSPACE);
return (ISC_R_SUCCESS);
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
unsigned int real_length;