Files
nixpkgs/pkgs/by-name/sm/smatch/fix_include_path.patch
2026-01-22 20:50:45 +00:00

47 lines
1.1 KiB
Diff

--- a/pre-process.c
+++ b/pre-process.c
@@ -2410,22 +2410,27 @@ static void do_preprocess(struct token **list)
void init_include_path(void)
{
- char path[256];
- char os[32];
- int error;
- struct utsname name;
-
- error = uname(&name);
- if (error)
- return;
-
- if (strcmp(name.sysname, "Linux") != 0)
- return;
- strcpy(os, "linux-gnu");
-
- snprintf(path, sizeof(path), "/usr/include/%s-%s/",
- name.machine, os);
- add_pre_buffer("#add_system \"%s/\"\n", path);
+ add_pre_buffer("#add_system \"%s/\"\n", "@clang@");
+ add_pre_buffer("#add_system \"%s/\"\n", "@libc@");
+
+ bool collect = false;
+ char *nix_cflags = getenv("NIX_CFLAGS_COMPILE");
+ if (nix_cflags == NULL)
+ return;
+
+ for (
+ char *token = strtok(nix_cflags, " ");
+ token != NULL;
+ token = strtok(NULL, " ")
+ ) {
+ if (collect && *token == '/') {
+ add_pre_buffer("#add_system \"%s/\"\n", token);
+ collect = false;
+ continue;
+ }
+ if (!strcmp(token, "-isystem"))
+ collect = true;
+ }
}
struct token * preprocess(struct token *token)