]> jfr.im git - irc/quakenet/newserv.git/blame - lib/stringbuf.c
Someone figured out how to print the ip, nterfacer now shows bad IP connections.
[irc/quakenet/newserv.git] / lib / stringbuf.c
CommitLineData
ba8a65c4
CP
1#include "stringbuf.h"
2
8b7b4553
CP
3void sbinit(StringBuf *buf, char *c, int capacity) {
4 buf->buf = c;
5 buf->capacity = capacity;
6 buf->len = 0;
7}
8
ba8a65c4
CP
9int sbaddchar(StringBuf *buf, char c) {
10 if(buf->len >= buf->capacity - 1)
11 return 0;
12
13 buf->buf[buf->len++] = c;
14
15 return 1;
16}
17
18int sbaddstr(StringBuf *buf, char *c) {
19 int remaining = buf->capacity - buf->len - 1;
20 char *p;
21
22 for(p=c;*p;p++) {
23 if(remaining <= 0)
24 return 0;
25
26 remaining--;
27
28 buf->buf[buf->len++] = *p;
29 }
30
31 return 1;
32}
33
0be0b2d0
CP
34int sbterminate(StringBuf *buf) {
35 if(buf->capacity - buf->len > 0) {
36 buf->buf[buf->len] = '\0';
37 return 1;
38 }
39 return 0;
40}