mirror of
https://github.com/moparisthebest/imapfilter
synced 2024-08-13 16:53:51 -04:00
4fe1a3d649
Move the source code to the src dir, the man pages to the doc dir, and the example configuration files to the samples dir, and update all relevant files to reflect the changes.
61 lines
737 B
C
61 lines
737 B
C
#include <stdio.h>
|
|
|
|
#include "imapfilter.h"
|
|
#include "buffer.h"
|
|
|
|
|
|
/*
|
|
* Initialize buffer.
|
|
*/
|
|
void
|
|
buffer_init(buffer *buf, size_t n)
|
|
{
|
|
|
|
buf->data = (char *)xmalloc((n + 1) * sizeof(char));
|
|
*buf->data = '\0';
|
|
buf->len = 0;
|
|
buf->size = n;
|
|
}
|
|
|
|
|
|
/*
|
|
* Free allocated memory of buffer.
|
|
*/
|
|
void
|
|
buffer_free(buffer *buf)
|
|
{
|
|
|
|
if (!buf->data)
|
|
return;
|
|
|
|
xfree(buf->data);
|
|
buf->data = NULL;
|
|
}
|
|
|
|
|
|
/*
|
|
* Reset buffer.
|
|
*/
|
|
void
|
|
buffer_reset(buffer *buf)
|
|
{
|
|
|
|
*buf->data = '\0';
|
|
buf->len = 0;
|
|
}
|
|
|
|
|
|
/*
|
|
* Check if the buffer has enough space to store data and reallocate memory if
|
|
* needed.
|
|
*/
|
|
void
|
|
buffer_check(buffer *buf, size_t n)
|
|
{
|
|
|
|
while (n > buf->size) {
|
|
buf->size *= 2;
|
|
buf->data = (char *)xrealloc(buf->data, buf->size + 1);
|
|
}
|
|
}
|