surf-adblock

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

commit 75a5ce0455bace5c6b20ef07ceb202bd0af02269
parent bce9b1e6b8d516ab21f9e23839ae96f82a9cd723
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sat, 16 Jul 2016 12:11:51 +0200

use non-hardcoded adblock list

Diffstat:
surf-adblock.c | 17+++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/surf-adblock.c b/surf-adblock.c @@ -788,16 +788,25 @@ webkit_web_extension_initialize(WebKitWebExtension *e) { struct filterrule *r; FILE *fp; - const char *filename = "/home/hiltjo/adblock_rules"; + char filepath[PATH_MAX], *home; + int n; + + home = getenv("HOME"); + n = snprintf(filepath, sizeof(filepath), "%s%s.surf/adblockrules", + home ? home : "", home ? "/" : ""); + if (n < 0 || (size_t)n >= sizeof(filepath)) { + fprintf(stderr, "fatal: path too long, truncated\n"); + return; + } - if (!(fp = fopen(filename, "r"))) { + if (!(fp = fopen(filepath, "r"))) { fprintf(stderr, "fatal: cannot read rules file: %s: %s\n", - filename, strerror(errno)); + filepath, strerror(errno)); return; } if (!(rules = loadrules(fp))) { fprintf(stderr, "fatal: cannot read adblock rules from file: %s: %s\n", - filename, strerror(errno)); + filepath, strerror(errno)); return; } fclose(fp);