Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape spaces in depfile with backslashes. #1

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions dtc/include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ static inline void NORETURN PRINTF(1, 2) die(const char *str, ...)
exit(1);
}

/**
* Writes path to fp, escaping spaces with a backslash.
*/
void fprint_path_escaped(FILE *fp, const char *path);

static inline void *xmalloc(size_t len)
{
void *new = malloc(len);
Expand Down
4 changes: 3 additions & 1 deletion dtc/src/dtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,9 @@ int main(int argc, char *argv[])
if (!depfile)
die("Couldn't open dependency file %s: %s\n", depname,
strerror(errno));
fprintf(depfile, "%s:", outname);

fprint_path_escaped(depfile, outname);
fputc(':', depfile);
}

if (inform == NULL)
Expand Down
6 changes: 4 additions & 2 deletions dtc/src/srcpos.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,10 @@ FILE *srcfile_relative_open(const char *fname, char **fullnamep)
strerror(errno));
}

if (depfile)
fprintf(depfile, " %s", fullname);
if (depfile) {
fputc(' ', depfile);
fprint_path_escaped(depfile, fullname);
}

if (fullnamep)
*fullnamep = fullname;
Expand Down
16 changes: 16 additions & 0 deletions dtc/src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@
#include "util.h"
#include "version_gen.h"

void fprint_path_escaped(FILE *fp, const char *path)
{
const char *p = path;

while (*p) {
if (*p == ' ') {
fputc('\\', fp);
fputc(' ', fp);
} else {
fputc(*p, fp);
}

p++;
}
}

char *xstrdup(const char *s)
{
int len = strlen(s) + 1;
Expand Down