2015-09-12 12:33:25 +02:00
|
|
|
#include <platform.h>
|
2015-09-12 12:24:10 +02:00
|
|
|
#include "prefix.h"
|
|
|
|
|
2016-11-23 18:56:40 +01:00
|
|
|
#include <util/log.h>
|
|
|
|
|
2015-09-12 12:49:12 +02:00
|
|
|
#include <assert.h>
|
2015-09-12 12:24:10 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
char **race_prefixes = NULL;
|
2015-09-12 12:49:12 +02:00
|
|
|
static size_t size = 4;
|
|
|
|
static unsigned int next = 0;
|
2015-09-12 12:24:10 +02:00
|
|
|
|
2016-11-23 18:56:40 +01:00
|
|
|
int add_raceprefix(const char *prefix)
|
2015-09-12 12:24:10 +02:00
|
|
|
{
|
2015-09-12 12:49:12 +02:00
|
|
|
assert(prefix);
|
|
|
|
if (race_prefixes == NULL) {
|
|
|
|
next = 0;
|
|
|
|
size = 4;
|
2015-09-12 12:24:10 +02:00
|
|
|
race_prefixes = malloc(size * sizeof(char *));
|
2015-09-12 12:49:12 +02:00
|
|
|
}
|
2015-09-12 12:24:10 +02:00
|
|
|
if (next + 1 == size) {
|
2016-11-23 18:56:40 +01:00
|
|
|
char **tmp;
|
|
|
|
tmp = realloc(race_prefixes, 2 * size * sizeof(char *));
|
|
|
|
if (!tmp) {
|
|
|
|
log_fatal("allocation failure");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
race_prefixes = tmp;
|
2015-09-12 12:24:10 +02:00
|
|
|
size *= 2;
|
|
|
|
}
|
2017-01-10 16:31:05 +01:00
|
|
|
race_prefixes[next++] = strdup(prefix);
|
2015-09-12 12:24:10 +02:00
|
|
|
race_prefixes[next] = NULL;
|
2016-11-23 18:56:40 +01:00
|
|
|
return 0;
|
2015-09-12 12:24:10 +02:00
|
|
|
}
|
2015-09-12 12:29:42 +02:00
|
|
|
|
|
|
|
void free_prefixes(void) {
|
|
|
|
int i;
|
|
|
|
if (race_prefixes) {
|
|
|
|
for (i = 0; race_prefixes[i]; ++i) {
|
|
|
|
free(race_prefixes[i]);
|
|
|
|
}
|
|
|
|
free(race_prefixes);
|
|
|
|
race_prefixes = 0;
|
|
|
|
}
|
|
|
|
}
|