Resolve a path: if relative, join with directory. */
| 58 | |
| 59 | /* Resolve a path: if relative, join with directory. */ |
| 60 | static char *resolve_path(const char *path, const char *directory) { |
| 61 | if (!path) { |
| 62 | return NULL; |
| 63 | } |
| 64 | |
| 65 | /* Absolute path */ |
| 66 | if (path[0] == '/') { |
| 67 | return strdup(path); |
| 68 | } |
| 69 | |
| 70 | /* Relative — join with directory */ |
| 71 | if (directory && directory[0]) { |
| 72 | char buf[CBM_SZ_4K]; |
| 73 | snprintf(buf, sizeof(buf), "%s/%s", directory, path); |
| 74 | return strdup(buf); |
| 75 | } |
| 76 | |
| 77 | return strdup(path); |
| 78 | } |
| 79 | |
| 80 | /* Try to consume a -I or -isystem include path flag. Returns true if consumed. */ |
| 81 | static bool try_include_flag(cbm_compile_flags_t *f, const char **args, int argc, int *i, |