diff options
author | June McEnroe <june@causal.agency> | 2019-10-24 18:09:13 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2019-10-24 18:09:13 -0400 |
commit | bc30300f5087458a8de57e79430abb61174b8832 (patch) | |
tree | ee4a5b9b580373ebe2518df782d7398e1aee298a /ring.c | |
parent | Unset non-blocking on clients (diff) | |
download | pounce-bc30300f5087458a8de57e79430abb61174b8832.tar.gz pounce-bc30300f5087458a8de57e79430abb61174b8832.zip |
Register readers by client usernames
Diffstat (limited to '')
-rw-r--r-- | ring.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/ring.c b/ring.c index 40fb7df..ff83cea 100644 --- a/ring.c +++ b/ring.c @@ -38,3 +38,28 @@ void ringWrite(const char *line) { ring.lines[i] = strdup(line); if (!ring.lines[i]) err(EX_OSERR, "strdup"); } + +static struct { + char **names; + size_t *reads; + size_t cap, len; +} reader; + +size_t ringReader(const char *name) { + for (size_t i = 0; i < reader.len; ++i) { + if (!strcmp(reader.names[i], name)) return i; + } + + if (reader.len == reader.cap) { + reader.cap = (reader.cap ? reader.cap * 2 : 8); + reader.names = realloc(reader.names, sizeof(*reader.names) * reader.cap); + if (!reader.names) err(EX_OSERR, "realloc"); + reader.reads = realloc(reader.reads, sizeof(*reader.reads) * reader.cap); + if (!reader.reads) err(EX_OSERR, "realloc"); + } + + reader.names[reader.len] = strdup(name); + if (!reader.names[reader.len]) err(EX_OSERR, "strdup"); + reader.reads[reader.len] = 0; + return reader.len++; +} |