buffer.c revision c0435c854a0e7246373b9752d163095cc4fbe985
/*
Copyright (c) 2002 Timo Sirainen
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* @UNSAFE: whole file */
#include "lib.h"
#include "buffer.h"
struct buffer {
const unsigned char *r_buffer;
unsigned char *w_buffer;
/* buffer_set_start_pos() modifies start_pos, but internally we deal
only with absolute positions. buffer_check_read|write modifies
given position to absolute one.
start_pos <= used <= alloc <= max_alloc.
start_pos <= limit <= max_alloc */
unsigned int alloced:1;
unsigned int readonly:1;
unsigned int hard:1;
};
{
return;
else
}
{
return FALSE;
return TRUE;
}
{
return FALSE;
/* check that we don't overflow size_t */
return FALSE;
else {
if (max_size == 0 || !accept_partial)
return FALSE;
}
/* make sure we're within our limits */
}
return FALSE;
}
/* see if we need to grow the buffer */
}
return TRUE;
}
{
return buf;
}
{
return buf;
}
{
return buf;
}
{
return buf;
}
{
return buf;
}
{
}
{
void *data;
return data;
}
{
return 0;
return data_size;
}
{
}
{
return 0;
if (data_size == 1)
return data_size;
}
{
/* move_size == number of bytes we have to move forward to make space */
return 0;
/* size == number of bytes we want to modify after pos */
else
return 0;
/* size == number of bytes we actually inserted. data_size usually. */
return size;
}
{
return 0;
return 0;
/* delete from between */
} else {
/* delete the rest of the buffer */
end_size = 0;
}
return size;
}
{
return 0;
return 0;
} else {
}
return copy_size;
}
{
}
{
return NULL;
}
{
}
{
}
{
}
{
}
{
}
{
return old;
}
{
}
{
else
}
{
}
{
}
#ifdef BUFFER_TEST
/* gcc buffer.c -o testbuffer liblib.a -Wall -DHAVE_CONFIG_H -DBUFFER_TEST -g */
int main(void)
{
lib_init();
return 0;
}
#endif