aboutsummaryrefslogtreecommitdiff
path: root/bp.c
diff options
context:
space:
mode:
Diffstat (limited to 'bp.c')
-rw-r--r--bp.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/bp.c b/bp.c
index 236aab0..c67669f 100644
--- a/bp.c
+++ b/bp.c
@@ -98,6 +98,16 @@ static inline void fprint_filename(FILE *out, const char *filename)
else fprintf(out, "%s:\n", filename);
}
+static void *portable_memrchr(const void *s, int c, size_t n)
+{
+ const unsigned char *p = (const unsigned char *)s + n;
+ while (n--) {
+ if (*--p == (unsigned char)c)
+ return (void *)p;
+ }
+ return NULL;
+}
+
//
// If there was a parse error while building a pattern, print an error message and exit.
//
@@ -109,7 +119,7 @@ static inline bp_pat_t *assert_pat(const char *start, const char *end, maybe_pat
*err_end = maybe_pat.value.error.end,
*err_msg = maybe_pat.value.error.msg;
- const char *nl = memrchr(start, '\n', (size_t)(err_start - start));
+ const char *nl = portable_memrchr(start, '\n', (size_t)(err_start - start));
const char *sol = nl ? nl+1 : start;
nl = memchr(err_start, '\n', (size_t)(end - err_start));
const char *eol = nl ? nl : end;
@@ -547,7 +557,7 @@ int main(int argc, char *argv[])
bp_pat_t *pattern = NULL;
// Load builtins:
- file_t *builtins_file = load_file(&loaded_files, "/etc/"BP_NAME"/builtins.bp");
+ file_t *builtins_file = load_file(&loaded_files, SYSCONFDIR"/"BP_NAME"/builtins.bp");
if (builtins_file) defs = load_grammar(defs, builtins_file);
file_t *local_file = load_filef(&loaded_files, "%s/.config/"BP_NAME"/builtins.bp", getenv("HOME"));
if (local_file) defs = load_grammar(defs, local_file);
@@ -595,7 +605,7 @@ int main(int argc, char *argv[])
if (f == NULL)
f = load_filef(&loaded_files, "%s/.config/"BP_NAME"/%s.bp", getenv("HOME"), flag);
if (f == NULL)
- f = load_filef(&loaded_files, "/etc/"BP_NAME"/%s.bp", flag);
+ f = load_filef(&loaded_files, SYSCONFDIR"/"BP_NAME"/%s.bp", flag);
if (f == NULL)
errx(EXIT_FAILURE, "Couldn't find grammar: %s", flag);
defs = load_grammar(defs, f); // Keep in memory for debug output