summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorNikola Pajkovsky <npajkovs@redhat.com>2010-06-04 11:23:56 +0200
committerNikola Pajkovsky <npajkovs@redhat.com>2010-06-04 11:25:13 +0200
commitd5f79e3b0bd7cccab80411b0fc0731b08c30064e (patch)
tree7aff4e6de0b941d196ae5fa63d32013fb7b3c9bc /lib
parent1459f9ec6a7fd62780dae9230c4a5d625a8a7a9a (diff)
downloadabrt-d5f79e3b0bd7cccab80411b0fc0731b08c30064e.tar.gz
abrt-d5f79e3b0bd7cccab80411b0fc0731b08c30064e.tar.xz
abrt-d5f79e3b0bd7cccab80411b0fc0731b08c30064e.zip
new fuctions and realloc replaced by xrealloc
new functions are prefixcmp and suffixcmp Signed-off-by: Nikola Pajkovsky <npajkovs@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/Utils/strbuf.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/lib/Utils/strbuf.c b/lib/Utils/strbuf.c
index 02062336..2cefefe3 100644
--- a/lib/Utils/strbuf.c
+++ b/lib/Utils/strbuf.c
@@ -25,6 +25,25 @@
#include <stdarg.h>
#include "xfuncs.h"
+
+int prefixcmp(const char *str, const char *prefix)
+{
+ for (; ; str++, prefix++)
+ if (!*prefix)
+ return 0;
+ else if (*str != *prefix)
+ return (unsigned char)*prefix - (unsigned char)*str;
+}
+
+int suffixcmp(const char *str, const char *suffix)
+{
+ int len_minus_suflen = strlen(str) - strlen(suffix);
+ if (len_minus_suflen < 0)
+ return len_minus_suflen;
+ else
+ return strcmp(str + len_minus_suflen, suffix);
+}
+
struct strbuf *strbuf_new()
{
struct strbuf *buf = xmalloc(sizeof(struct strbuf));
@@ -66,12 +85,7 @@ static void strbuf_grow(struct strbuf *strbuf, int num)
while (strbuf->len + num + 1 > strbuf->alloc)
strbuf->alloc *= 2; /* huge grow = infinite loop */
- strbuf->buf = realloc(strbuf->buf, strbuf->alloc);
- if (!strbuf->buf)
- {
- puts("Error while allocating memory for string buffer.");
- exit(5);
- }
+ strbuf->buf = xrealloc(strbuf->buf, strbuf->alloc);
}
}