summaryrefslogtreecommitdiff
path: root/CC/include_scan.c
diff options
context:
space:
mode:
authorOliver Reiche <oliver.reiche@huawei.com>2025-05-07 12:10:55 +0200
committerOliver Reiche <oliver.reiche@huawei.com>2025-05-07 16:39:59 +0200
commitb909c514866f1f0713edd831d183e4fa1e5c91f5 (patch)
tree3654f3655cb10a002c499106bfb01ee62afe9e62 /CC/include_scan.c
parenteff965fdd8f03668f99d9c90ea9a3f81dabc3b66 (diff)
downloadrules-cc-b909c514866f1f0713edd831d183e4fa1e5c91f5.tar.gz
Do not assume out_dirs exist
Diffstat (limited to 'CC/include_scan.c')
-rw-r--r--CC/include_scan.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/CC/include_scan.c b/CC/include_scan.c
index ea013ad..8652fc0 100644
--- a/CC/include_scan.c
+++ b/CC/include_scan.c
@@ -94,11 +94,13 @@ int main(int argc, const char *argv[]) {
int retval = 0;
char *path = NULL;
char *prefix;
+ char *outdir;
size_t prefix_len = 0;
+ size_t outdir_len = 0;
struct IncludeList incl;
if (argc < 3) {
- fprintf(stderr, "usage: %s PREFIX FILE ARGV...\n", argv[0]);
+ fprintf(stderr, "usage: %s OUT_DIR ARGV...\n", argv[0]);
fprintf(stderr, "Missing arguments\n");
exit(EXIT_FAILURE);
}
@@ -130,9 +132,20 @@ int main(int argc, const char *argv[]) {
strcat(prefix + prefix_len, "/");
prefix_len += 1;
parse_paths(&incl, fd[0], "include/", prefix);
- free(prefix);
close(fd[0]);
+ /* create output directory "<prefix>/include" */
+ outdir_len = prefix_len + 8 /* strlen("include/") */;
+ outdir = (char *)calloc(outdir_len + 1, sizeof(char));
+ strcat(outdir, prefix);
+ strcat(outdir + prefix_len, "include/");
+ if (helper_mkdir_p(outdir, 0755) != 0) {
+ fprintf(stderr, "Failed to create output directory\n");
+ return 1;
+ }
+ free(prefix);
+ free(outdir);
+
/* wait for child to finish */
while (1) {
if (waitpid(pid, &status, 0) == -1) {