diff options
| author | Bruce Hill <bruce@stainless.com> | 2025-08-22 13:06:08 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@stainless.com> | 2025-08-22 13:06:08 -0400 |
| commit | 2d81f92fbadb0d60243cbcad7c4a5236815fdbbc (patch) | |
| tree | 99284bfcc320c102941a4d885b195d182899821f /bp.c | |
| parent | 20c11b29b3a63c221cac942a17bf9abcf8b9bafe (diff) | |
Mac platform fixes
Diffstat (limited to 'bp.c')
| -rw-r--r-- | bp.c | 16 |
1 files changed, 13 insertions, 3 deletions
@@ -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 |
