surf-adblock

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 94705d18c8191bd931b284dfc50c4c6f100ea65a
parent 943b025897dd39e4b64755e6bafa890d35ea8ae1
Author: Quentin Rameau <quinq@fifth.space>
Date:   Sat, 16 Jul 2016 18:41:41 +0200

introduce eprintf() to replace various error points

Diffstat:
surf-adblock.c | 54++++++++++++++++++++++++++++--------------------------
1 file changed, 28 insertions(+), 26 deletions(-)

diff --git a/surf-adblock.c b/surf-adblock.c @@ -111,16 +111,28 @@ static String globalcss; static struct filterrule *rules; static void +eprintf(const char *fmt, ...) +{ + va_list ap; + + fprintf(stderr, "surf-adblock: "); + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + + exit(1); +} + +static void string_buffer_realloc(String *s, size_t newlen) { size_t alloclen; for (alloclen = 64; alloclen <= newlen; alloclen *= 2) ; - if (!(s->data = realloc(s->data, alloclen))) { - fprintf(stderr, "realloc: %s\n", strerror(errno)); - exit(1); - } + if (!(s->data = realloc(s->data, alloclen))) + eprintf("realloc: %s\n", strerror(errno)); s->bufsiz = alloclen; } @@ -143,10 +155,8 @@ ecalloc(size_t nmemb, size_t size) { void *p; - if (!(p = calloc(nmemb, size))) { - fprintf(stderr, "calloc: %s\n", strerror(errno)); - exit(1); - } + if (!(p = calloc(nmemb, size))) + eprintf("calloc: %s\n", strerror(errno)); return p; } @@ -156,10 +166,8 @@ estrdup(const char *s) { char *p; - if (!(p = strdup(s))) { - fprintf(stderr, "strdup: %s\n", strerror(errno)); - exit(1); - } + if (!(p = strdup(s))) + eprintf("strdup: %s\n", strerror(errno)); return p; } @@ -798,21 +806,15 @@ webkit_web_extension_initialize(WebKitWebExtension *ext) n = snprintf(filepath, sizeof(filepath), "%s%s.surf/adblockrules", e, e[0] && e[strlen(e) - 1] != '/' ? "/" : ""); } - if (n < 0 || (size_t)n >= sizeof(filepath)) { - fprintf(stderr, "fatal: path too long, truncated\n"); - return; - } + if (n < 0 || (size_t)n >= sizeof(filepath)) + eprintf("fatal: rules file path too long"); - if (!(fp = fopen(filepath, "r"))) { - fprintf(stderr, "fatal: cannot read rules from file: %s: %s\n", - filepath, strerror(errno)); - return; - } - if (!(rules = loadrules(fp))) { - fprintf(stderr, "fatal: cannot read adblock rules from file: %s: %s\n", - filepath, strerror(errno)); - return; - } + if (!(fp = fopen(filepath, "r"))) + eprintf("fatal: cannot open rules file %s: %s\n", + filepath, strerror(errno)); + if (!(rules = loadrules(fp))) + eprintf("fatal: cannot read rules file %s: %s\n", + filepath, strerror(errno)); fclose(fp); /* general CSS rules: all sites */