diff --git a/resources/testproject/lib/clib.c3l/manifest.json b/resources/testproject/lib/clib.c3l/manifest.json index 3d5cca505..c5c4d498d 100644 --- a/resources/testproject/lib/clib.c3l/manifest.json +++ b/resources/testproject/lib/clib.c3l/manifest.json @@ -8,6 +8,8 @@ "linux-x64" : { "cflags": "-fPIE" }, - "windows-x64" : { } + "windows-x64" : { + "c-include-dirs": ["C:\\"] + } } } diff --git a/src/compiler/linker.c b/src/compiler/linker.c index 59bc93308..e4785b456 100644 --- a/src/compiler/linker.c +++ b/src/compiler/linker.c @@ -704,7 +704,7 @@ static char *assemble_linker_command(const char **args, bool extra_quote) if (arg == quote_arg) { scratch_buffer_append_char('"'); - scratch_buffer_append(args[++i]); + scratch_buffer_append_in_quote(args[++i]); scratch_buffer_append_char('"'); continue; } @@ -717,8 +717,8 @@ static char *assemble_linker_command(const char **args, bool extra_quote) if (arg == quote_concat_arg) { scratch_buffer_append_char('"'); - scratch_buffer_append(args[++i]); - scratch_buffer_append(args[++i]); + scratch_buffer_append_in_quote(args[++i]); + scratch_buffer_append_in_quote(args[++i]); scratch_buffer_append_char('"'); continue; } @@ -726,7 +726,7 @@ static char *assemble_linker_command(const char **args, bool extra_quote) { scratch_buffer_append(args[++i]); scratch_buffer_append_char('"'); - scratch_buffer_append(args[++i]); + scratch_buffer_append_in_quote(args[++i]); scratch_buffer_append_char('"'); continue; } diff --git a/src/utils/lib.h b/src/utils/lib.h index 8552d286a..e58e0965e 100644 --- a/src/utils/lib.h +++ b/src/utils/lib.h @@ -156,6 +156,7 @@ void scratch_buffer_clear(void); void scratch_buffer_append(const char *string); void scratch_buffer_append_len(const char *string, size_t len); void scratch_buffer_append_char(char c); +void scratch_buffer_append_in_quote(const char *string); void scratch_buffer_append_char_repeat(char c, size_t count); void scratch_buffer_append_signed_int(int64_t i); void scratch_buffer_append_double(double d); diff --git a/src/utils/stringutils.c b/src/utils/stringutils.c index 0e9717679..28817b04d 100644 --- a/src/utils/stringutils.c +++ b/src/utils/stringutils.c @@ -384,6 +384,25 @@ void scratch_buffer_printf(const char *format, ...) scratch_buffer.len += len_needed; } +void scratch_buffer_append_in_quote(const char *string) +{ + size_t len = strlen(string); + for (size_t i = 0; i < len; ) + { + char c = string[i++]; + switch (c) + { + case '"': + scratch_buffer_append("\\\""); + continue; + case '\\': + scratch_buffer_append("\\\\"); + continue; + } + scratch_buffer_append_char(c); + } +} + void scratch_buffer_append_char(char c) { if (scratch_buffer.len + 1 > MAX_STRING_BUFFER - 1)