server/src/prefix.c

47 lines
998 B
C
Raw Normal View History

2015-09-12 12:33:25 +02:00
#include <platform.h>
#include "prefix.h"
#include <util/log.h>
#include <util/strings.h>
#include <assert.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
char **race_prefixes = NULL;
static size_t size = 4;
static unsigned int next = 0;
int add_raceprefix(const char *prefix)
{
assert(prefix);
if (race_prefixes == NULL) {
next = 0;
size = 4;
race_prefixes = malloc(size * sizeof(char *));
2018-12-15 20:01:51 +01:00
if (!race_prefixes) abort();
}
if (next + 1 == size) {
char **tmp;
tmp = realloc(race_prefixes, 2 * size * sizeof(char *));
2018-12-15 20:01:51 +01:00
if (!tmp) abort();
race_prefixes = tmp;
size *= 2;
}
race_prefixes[next++] = str_strdup(prefix);
race_prefixes[next] = NULL;
return 0;
}
void free_prefixes(void) {
if (race_prefixes) {
2018-02-11 15:57:31 +01:00
int i;
for (i = 0; race_prefixes[i]; ++i) {
free(race_prefixes[i]);
}
free(race_prefixes);
race_prefixes = 0;
}
}