thematdev
140738e4e8
In order to use hiredis it is needed to move from ANSI C to C99 or gnu89. For now redis auth code is untested it's just first compiling prototype
55 lines
981 B
C
55 lines
981 B
C
#include <stdlib.h>
|
|
#include "string_buffer.h"
|
|
|
|
/* TODO: better solution instead of abort */
|
|
void
|
|
sb_add_char(StringBuffer *buffer, char c)
|
|
{
|
|
if (buffer->size == buffer->capacity) {
|
|
buffer->capacity = 2 * buffer->capacity + 1;
|
|
if (!(buffer->buf = realloc(buffer->buf, buffer->capacity))) {
|
|
abort();
|
|
}
|
|
}
|
|
buffer->buf[buffer->size++] = c;
|
|
}
|
|
|
|
void
|
|
sb_add_string(StringBuffer *buffer, const char *str)
|
|
{
|
|
char c;
|
|
while ((c = *(str++))) {
|
|
sb_add_char(buffer, c);
|
|
}
|
|
}
|
|
|
|
size_t
|
|
sb_length(const StringBuffer *buffer)
|
|
{
|
|
return buffer->size;
|
|
}
|
|
|
|
void
|
|
sb_to_c_str(const StringBuffer *buffer, char *str)
|
|
{
|
|
size_t i;
|
|
for (i = 0; i < buffer->size; ++i) {
|
|
str[i] = buffer->buf[i];
|
|
}
|
|
str[buffer->size] = '\0';
|
|
}
|
|
|
|
void
|
|
sb_init_empty(StringBuffer *buffer)
|
|
{
|
|
buffer->buf = NULL;
|
|
buffer->size = 0;
|
|
buffer->capacity = 0;
|
|
}
|
|
|
|
void
|
|
sb_free(StringBuffer *buffer)
|
|
{
|
|
if (buffer) free(buffer->buf);
|
|
}
|