kolibrios/contrib/media/updf_newlib/fitz/stm_buffer.c
maxcodehack dd0cf276d2 Upload uPDF port to newlib
git-svn-id: svn://kolibrios.org@8402 a494cfbc-eb01-0410-851d-a64ba20cac60
2020-12-14 10:37:08 +00:00

50 lines
658 B
C
Executable File

#include "fitz.h"
fz_buffer *
fz_new_buffer(int size)
{
fz_buffer *b;
size = size > 1 ? size : 16;
b = fz_malloc(sizeof(fz_buffer));
b->refs = 1;
b->data = fz_malloc(size);
b->cap = size;
b->len = 0;
return b;
}
fz_buffer *
fz_keep_buffer(fz_buffer *buf)
{
buf->refs ++;
return buf;
}
void
fz_drop_buffer(fz_buffer *buf)
{
if (--buf->refs == 0)
{
fz_free(buf->data);
fz_free(buf);
}
}
void
fz_resize_buffer(fz_buffer *buf, int size)
{
buf->data = fz_realloc(buf->data, size, 1);
buf->cap = size;
if (buf->len > buf->cap)
buf->len = buf->cap;
}
void
fz_grow_buffer(fz_buffer *buf)
{
fz_resize_buffer(buf, (buf->cap * 3) / 2);
}