diff options
Diffstat (limited to 'scripts/basic/fixdep.c')
-rw-r--r-- | scripts/basic/fixdep.c | 67 |
1 files changed, 62 insertions, 5 deletions
diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c index 071c3b407..47a0cee07 100644 --- a/scripts/basic/fixdep.c +++ b/scripts/basic/fixdep.c | |||
@@ -104,7 +104,9 @@ | |||
104 | 104 | ||
105 | #include <sys/types.h> | 105 | #include <sys/types.h> |
106 | #include <sys/stat.h> | 106 | #include <sys/stat.h> |
107 | #ifndef __MINGW32__ | ||
107 | #include <sys/mman.h> | 108 | #include <sys/mman.h> |
109 | #endif | ||
108 | #include <errno.h> | 110 | #include <errno.h> |
109 | #include <unistd.h> | 111 | #include <unistd.h> |
110 | #include <fcntl.h> | 112 | #include <fcntl.h> |
@@ -113,7 +115,9 @@ | |||
113 | #include <stdio.h> | 115 | #include <stdio.h> |
114 | #include <limits.h> | 116 | #include <limits.h> |
115 | #include <ctype.h> | 117 | #include <ctype.h> |
118 | #ifndef __MINGW32__ | ||
116 | #include <arpa/inet.h> | 119 | #include <arpa/inet.h> |
120 | #endif | ||
117 | //bbox disabled: #include <alloca.h> | 121 | //bbox disabled: #include <alloca.h> |
118 | 122 | ||
119 | /* bbox: not needed | 123 | /* bbox: not needed |
@@ -123,6 +127,57 @@ | |||
123 | #define INT_FIG_ ntohl(0x4649475f) | 127 | #define INT_FIG_ ntohl(0x4649475f) |
124 | */ | 128 | */ |
125 | 129 | ||
130 | #ifndef O_BINARY | ||
131 | #define O_BINARY 0 | ||
132 | #endif | ||
133 | |||
134 | #ifdef __MINGW32__ | ||
135 | #define UNUSED __attribute__ ((__unused__)) | ||
136 | |||
137 | /* Workaround specifically for fixdep */ | ||
138 | #define PROT_READ 0 | ||
139 | #define MAP_PRIVATE 0 | ||
140 | void *mmap(void *start UNUSED, size_t size, int prot UNUSED, | ||
141 | int flags UNUSED, int fd, off_t offset UNUSED) | ||
142 | { | ||
143 | void *p; | ||
144 | void *curP; | ||
145 | ssize_t readB; | ||
146 | |||
147 | p = malloc(size); | ||
148 | if (!p) | ||
149 | return (void*)((long)-1); | ||
150 | |||
151 | curP = p; | ||
152 | |||
153 | while (size > 0) | ||
154 | { | ||
155 | readB = read(fd, curP, size); | ||
156 | |||
157 | if (readB == 0) | ||
158 | { | ||
159 | /* EOF reached */ | ||
160 | break; | ||
161 | } | ||
162 | else if (readB < 0) | ||
163 | { | ||
164 | perror("fixdep: read config"); | ||
165 | free(p); | ||
166 | return (void*)((long)-1); | ||
167 | } | ||
168 | |||
169 | size -= readB; | ||
170 | curP += readB; | ||
171 | } | ||
172 | |||
173 | return p; | ||
174 | } | ||
175 | void munmap(void *p, size_t size UNUSED) | ||
176 | { | ||
177 | free(p); | ||
178 | } | ||
179 | #endif | ||
180 | |||
126 | char *target; | 181 | char *target; |
127 | char *depfile; | 182 | char *depfile; |
128 | char *cmdline; | 183 | char *cmdline; |
@@ -287,7 +342,7 @@ void do_config_file(char *filename) | |||
287 | int fd; | 342 | int fd; |
288 | void *map; | 343 | void *map; |
289 | 344 | ||
290 | fd = open(filename, O_RDONLY); | 345 | fd = open(filename, O_RDONLY | O_BINARY); |
291 | if (fd < 0) { | 346 | if (fd < 0) { |
292 | fprintf(stderr, "fixdep: "); | 347 | fprintf(stderr, "fixdep: "); |
293 | perror(filename); | 348 | perror(filename); |
@@ -302,7 +357,7 @@ void do_config_file(char *filename) | |||
302 | return; | 357 | return; |
303 | } | 358 | } |
304 | map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); | 359 | map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); |
305 | if ((long) map == -1) { | 360 | if ((intptr_t) map == -1) { |
306 | perror("fixdep: mmap"); | 361 | perror("fixdep: mmap"); |
307 | close(fd); | 362 | close(fd); |
308 | return; | 363 | return; |
@@ -338,8 +393,9 @@ void parse_dep_file(void *map, size_t len) | |||
338 | m++; | 393 | m++; |
339 | p = m; | 394 | p = m; |
340 | while (p < end && *p != ' ') p++; | 395 | while (p < end && *p != ' ') p++; |
396 | if (p == m) break; | ||
341 | if (p == end) { | 397 | if (p == end) { |
342 | do p--; while (!isalnum((unsigned char)*p)); | 398 | do p--; while (p != m && !isalnum((unsigned char)*p)); |
343 | p++; | 399 | p++; |
344 | } | 400 | } |
345 | if (p < m) { | 401 | if (p < m) { |
@@ -354,6 +410,7 @@ void parse_dep_file(void *map, size_t len) | |||
354 | printf(" %s \\\n", s); | 410 | printf(" %s \\\n", s); |
355 | do_config_file(s); | 411 | do_config_file(s); |
356 | } | 412 | } |
413 | if (p == end) break; | ||
357 | m = p + 1; | 414 | m = p + 1; |
358 | } | 415 | } |
359 | printf("\n%s: $(deps_%s)\n\n", target, target); | 416 | printf("\n%s: $(deps_%s)\n\n", target, target); |
@@ -366,7 +423,7 @@ void print_deps(void) | |||
366 | int fd; | 423 | int fd; |
367 | void *map; | 424 | void *map; |
368 | 425 | ||
369 | fd = open(depfile, O_RDONLY); | 426 | fd = open(depfile, O_RDONLY | O_BINARY); |
370 | if (fd < 0) { | 427 | if (fd < 0) { |
371 | fprintf(stderr, "fixdep: "); | 428 | fprintf(stderr, "fixdep: "); |
372 | perror(depfile); | 429 | perror(depfile); |
@@ -382,7 +439,7 @@ void print_deps(void) | |||
382 | return; | 439 | return; |
383 | } | 440 | } |
384 | map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); | 441 | map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); |
385 | if ((long) map == -1) { | 442 | if ((intptr_t) map == -1) { |
386 | perror("fixdep: mmap"); | 443 | perror("fixdep: mmap"); |
387 | close(fd); | 444 | close(fd); |
388 | return; | 445 | return; |