clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name main.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D NO_X11 -D XP_PC -D HW_THREADS -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -std=gnu89 -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -stack-protector 2 -fgnuc-version=4.2.1 -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c /home/maarten/src/libreoffice/core/soltools/mkdepend/main.c
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | #if defined(FREEBSD) || defined(MACOSX) |
32 | #include <sys/types.h> |
33 | #include <sys/stat.h> |
34 | #endif |
35 | |
36 | #ifdef _WIN32 |
37 | #include <io.h> |
38 | #endif |
39 | |
40 | #ifdef _MSC_VER /* Define ssize_t */ |
41 | |
42 | #if !defined(_W64) |
43 | #if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) |
44 | #define _W64 __w64 |
45 | #else |
46 | #define _W64 |
47 | #endif |
48 | #endif |
49 | |
50 | #ifdef _WIN64 |
51 | typedef __int64 ssize_t; |
52 | #else |
53 | typedef _W64 int ssize_t; |
54 | #endif |
55 | |
56 | #endif |
57 | |
58 | #include "def.h" |
59 | #include <assert.h> |
60 | #include <string.h> |
61 | #ifdef hpux |
62 | #define sigvec sigvector |
63 | #endif /* hpux */ |
64 | |
65 | #ifdef X_POSIX_C_SOURCE |
66 | #define _POSIX_C_SOURCE X_POSIX_C_SOURCE |
67 | #include <signal.h> |
68 | #undef _POSIX_C_SOURCE |
69 | #else |
70 | #if defined(X_NOT_POSIX) || defined(_POSIX_SOURCE) |
71 | #include <signal.h> |
72 | #else |
73 | #define _POSIX_SOURCE |
74 | #include <signal.h> |
75 | #undef _POSIX_SOURCE |
76 | #endif |
77 | #endif |
78 | |
79 | #include <stdarg.h> |
80 | |
81 | #ifdef MINIX |
82 | #define USE_CHMOD 1 |
83 | #endif |
84 | |
85 | #ifdef DEBUG |
86 | int _debugmask; |
87 | #endif |
88 | |
89 | static char *ProgramName; |
90 | |
91 | #define OBJSUFFIX ".obj" |
92 | #define INCLUDEDIR "." |
93 | |
94 | char *directives[] = { |
95 | "if", |
96 | "ifdef", |
97 | "ifndef", |
98 | "else", |
99 | "endif", |
100 | "define", |
101 | "undef", |
102 | "include", |
103 | "line", |
104 | "pragma", |
105 | "error", |
106 | "ident", |
107 | "sccs", |
108 | "elif", |
109 | "eject", |
110 | NULL |
111 | }; |
112 | |
113 | #define MAKEDEPEND |
114 | #include "imakemdep.h" /* from config sources */ |
115 | #undef MAKEDEPEND |
116 | |
117 | |
118 | |
119 | static void redirect(char * makefile); |
120 | |
121 | struct inclist inclist[ MAXFILES ]; |
122 | struct inclist *inclistp = inclist; |
123 | |
124 | static struct symhash *maininclist = NULL; |
125 | |
126 | static char *filelist[ MAXFILES ]; |
127 | char *includedirs[ MAXDIRS + 1 ]; |
128 | char *objprefix = ""; |
129 | char *objsuffix = OBJSUFFIX; |
130 | static char *startat = "# DO NOT DELETE"; |
131 | boolean printed = FALSE; |
132 | boolean verbose = FALSE; |
133 | boolean show_where_not = FALSE; |
134 | boolean warn_multiple = FALSE; |
135 | |
136 | static |
137 | #ifdef SIGNALRETURNSINT |
138 | int |
139 | #else |
140 | void |
141 | #endif |
142 | catch (int sig) |
143 | { |
144 | fflush (stdout); |
145 | fatalerr ("got signal %d\n", sig); |
146 | } |
147 | |
148 | #if (defined(i386) && defined(SYSV)) || defined(_WIN32) |
149 | #define USGISH |
150 | #endif |
151 | |
152 | #ifndef USGISH |
153 | #ifndef _POSIX_SOURCE |
154 | #define sigaction sigvec |
155 | #define sa_handler sv_handler |
156 | #define sa_mask sv_mask |
157 | #define sa_flags sv_flags |
158 | #endif |
159 | static struct sigaction sig_act; |
160 | #endif /* USGISH */ |
161 | |
162 | static boolean native_win_slashes = FALSE; |
163 | |
164 | int main(int argc, char **argv) |
165 | { |
166 | char **fp = filelist; |
167 | char **incp = includedirs; |
168 | char *p; |
169 | struct inclist *ip; |
170 | char *makefile = NULL; |
171 | struct filepointer *filecontent; |
172 | struct pair *psymp = predefs; |
173 | char *endmarker = NULL; |
174 | char *defincdir = NULL; |
175 | struct IncludesCollection* incCollection; |
176 | |
177 | ProgramName = argv[0]; |
178 | |
179 | while (psymp->p_name) |
| 1 | Loop condition is false. Execution continues on line 184 | |
|
180 | { |
181 | hash_define(psymp->p_name, psymp->p_value, &maininclist); |
182 | psymp++; |
183 | } |
184 | if (argc == 2 && argv[1][0] == '@') { |
| 2 | | Assuming 'argc' is not equal to 2 | |
|
185 | struct stat ast; |
186 | int afd; |
187 | char *args; |
188 | char **nargv; |
189 | int nargc; |
190 | char quotechar = '\0'; |
191 | |
192 | nargc = 1; |
193 | if ((afd = open(argv[1]+1, O_RDONLY)) < 0) |
194 | fatalerr("cannot open \"%s\"\n", argv[1]+1); |
195 | (void)fstat(afd, &ast); |
196 | args = (char *)malloc(ast.st_size + 1); |
197 | if ((ast.st_size = read(afd, args, (size_t) ast.st_size)) < 0) |
198 | fatalerr("failed to read %s\n", argv[1]+1); |
199 | args[ast.st_size] = '\0'; |
200 | close(afd); |
201 | for (p = args; *p; p++) { |
202 | if (quotechar) { |
203 | if (quotechar == '\\' |
204 | || (*p == quotechar && p[-1] != '\\')) |
205 | quotechar = '\0'; |
206 | continue; |
207 | } |
208 | switch (*p) { |
209 | case '\\': |
210 | case '"': |
211 | case '\'': |
212 | quotechar = *p; |
213 | break; |
214 | case ' ': |
215 | case '\n': |
216 | *p = '\0'; |
217 | if (p > args && p[-1]) |
218 | nargc++; |
219 | break; |
220 | } |
221 | } |
222 | if (p[-1]) |
223 | nargc++; |
224 | nargv = (char **)malloc(nargc * sizeof(char *)); |
225 | nargv[0] = argv[0]; |
226 | argc = 1; |
227 | for (p = args; argc < nargc; p += strlen(p) + 1) |
228 | if (*p) nargv[argc++] = p; |
229 | argv = nargv; |
230 | } |
231 | for(argc--, argv++; argc; argc--, argv++) { |
| 3 | | Loop condition is true. Entering loop body | |
|
| 11 | | Loop condition is false. Execution continues on line 349 | |
|
232 | |
233 | if (endmarker && strcmp (endmarker, *argv) == 0) { |
234 | endmarker = NULL; |
235 | continue; |
236 | } |
237 | if (**argv != '-') { |
| 4 | | Assuming the condition is false | |
|
| |
238 | |
239 | if (endmarker && **argv == '+') |
240 | continue; |
241 | *fp++ = argv[0]; |
242 | continue; |
243 | } |
244 | switch(argv[0][1]) { |
| 6 | | Control jumps to 'case 112:' at line 296 | |
|
245 | case '-': |
246 | endmarker = &argv[0][2]; |
247 | if (endmarker[0] == '\0') endmarker = "--"; |
248 | break; |
249 | case 'D': |
250 | if (argv[0][2] == '\0') { |
251 | argv++; |
252 | argc--; |
253 | } |
254 | for (p=argv[0] + 2; *p ; p++) |
255 | if (*p == '=') { |
256 | *p = ' '; |
257 | break; |
258 | } |
259 | define(argv[0] + 2, &maininclist); |
260 | break; |
261 | case 'I': |
262 | if (incp >= includedirs + MAXDIRS) |
263 | fatalerr("Too many -I flags.\n"); |
264 | *incp++ = argv[0]+2; |
265 | if (**(incp-1) == '\0') { |
266 | *(incp-1) = *(++argv); |
267 | argc--; |
268 | } |
269 | break; |
270 | case 'Y': |
271 | defincdir = argv[0]+2; |
272 | break; |
273 | |
274 | case 'a': |
275 | break; |
276 | case 'w': |
277 | if (endmarker) break; |
278 | if (argv[0][2] == '\0') { |
279 | argv++; |
280 | argc--; |
281 | } |
282 | break; |
283 | case 'n': |
284 | |
285 | native_win_slashes = TRUE; |
286 | break; |
287 | case 'o': |
288 | if (endmarker) break; |
289 | if (argv[0][2] == '\0') { |
290 | argv++; |
291 | argc--; |
292 | objsuffix = argv[0]; |
293 | } else |
294 | objsuffix = argv[0]+2; |
295 | break; |
296 | case 'p': |
297 | if (endmarker) break; |
| |
298 | if (argv[0][2] == '\0') { |
| 8 | | Assuming the condition is false | |
|
| |
299 | argv++; |
300 | argc--; |
301 | objprefix = argv[0]; |
302 | } else |
303 | objprefix = argv[0]+2; |
304 | break; |
| 10 | | Execution continues on line 231 | |
|
305 | case 'v': |
306 | if (endmarker) break; |
307 | verbose = TRUE; |
308 | #ifdef DEBUG |
309 | if (argv[0][2]) |
310 | _debugmask = atoi(argv[0]+2); |
311 | #endif |
312 | break; |
313 | case 's': |
314 | if (endmarker) break; |
315 | startat = argv[0]+2; |
316 | if (*startat == '\0') { |
317 | startat = *(++argv); |
318 | argc--; |
319 | } |
320 | if (*startat != '#') |
321 | fatalerr("-s flag's value should start %s\n", |
322 | "with '#'."); |
323 | break; |
324 | case 'f': |
325 | if (endmarker) break; |
326 | makefile = argv[0]+2; |
327 | if (*makefile == '\0') { |
328 | makefile = *(++argv); |
329 | argc--; |
330 | } |
331 | break; |
332 | |
333 | case 'm': |
334 | warn_multiple = TRUE; |
335 | break; |
336 | |
337 | |
338 | |
339 | |
340 | case 'O': |
341 | case 'g': |
342 | break; |
343 | default: |
344 | if (endmarker) break; |
345 | warning("ignoring option %s\n", argv[0]); |
346 | } |
347 | } |
348 | |
349 | convert_slashes(objprefix); |
350 | objprefix = append_slash(objprefix); |
351 | |
352 | if (!defincdir) { |
| |
353 | #ifdef PREINCDIR |
354 | if (incp >= includedirs + MAXDIRS) |
355 | fatalerr("Too many -I flags.\n"); |
356 | *incp++ = PREINCDIR; |
357 | #endif |
358 | if (incp >= includedirs + MAXDIRS) |
| |
359 | fatalerr("Too many -I flags.\n"); |
360 | *incp++ = INCLUDEDIR; |
361 | #ifdef POSTINCDIR |
362 | if (incp >= includedirs + MAXDIRS) |
363 | fatalerr("Too many -I flags.\n"); |
364 | *incp++ = POSTINCDIR; |
365 | #endif |
366 | } else if (*defincdir) { |
367 | if (incp >= includedirs + MAXDIRS) |
368 | fatalerr("Too many -I flags.\n"); |
369 | *incp++ = defincdir; |
370 | } |
371 | |
372 | redirect(makefile); |
373 | |
374 | |
375 | |
376 | |
377 | #ifdef USGISH |
378 | |
379 | #ifdef SIGHUP |
380 | signal (SIGHUP, catch); |
381 | #endif |
382 | signal (SIGINT, catch); |
383 | #ifdef SIGQUIT |
384 | signal (SIGQUIT, catch); |
385 | #endif |
386 | signal (SIGILL, catch); |
387 | #ifdef SIGBUS |
388 | signal (SIGBUS, catch); |
389 | #endif |
390 | signal (SIGSEGV, catch); |
391 | #ifdef SIGSYS |
392 | signal (SIGSYS, catch); |
393 | #endif |
394 | signal (SIGFPE, catch); |
395 | #else |
396 | sig_act.sa_handler = catch; |
397 | #ifdef _POSIX_SOURCE |
398 | sigemptyset(&sig_act.sa_mask); |
399 | sigaddset(&sig_act.sa_mask, SIGINT); |
400 | sigaddset(&sig_act.sa_mask, SIGQUIT); |
401 | #ifdef SIGBUS |
402 | sigaddset(&sig_act.sa_mask, SIGBUS); |
403 | #endif |
404 | sigaddset(&sig_act.sa_mask, SIGILL); |
405 | sigaddset(&sig_act.sa_mask, SIGSEGV); |
406 | sigaddset(&sig_act.sa_mask, SIGHUP); |
407 | sigaddset(&sig_act.sa_mask, SIGPIPE); |
408 | #ifdef SIGSYS |
409 | sigaddset(&sig_act.sa_mask, SIGSYS); |
410 | #endif |
411 | #else |
412 | sig_act.sa_mask = ((1<<(SIGINT -1)) |
413 | |(1<<(SIGQUIT-1)) |
414 | #ifdef SIGBUS |
415 | |(1<<(SIGBUS-1)) |
416 | #endif |
417 | |(1<<(SIGILL-1)) |
418 | |(1<<(SIGSEGV-1)) |
419 | |(1<<(SIGHUP-1)) |
420 | |(1<<(SIGPIPE-1)) |
421 | #ifdef SIGSYS |
422 | |(1<<(SIGSYS-1)) |
423 | #endif |
424 | ); |
425 | #endif /* _POSIX_SOURCE */ |
426 | sig_act.sa_flags = 0; |
427 | sigaction(SIGHUP, &sig_act, (struct sigaction *)0); |
428 | sigaction(SIGINT, &sig_act, (struct sigaction *)0); |
429 | sigaction(SIGQUIT, &sig_act, (struct sigaction *)0); |
430 | sigaction(SIGILL, &sig_act, (struct sigaction *)0); |
431 | #ifdef SIGBUS |
432 | sigaction(SIGBUS, &sig_act, (struct sigaction *)0); |
433 | #endif |
434 | sigaction(SIGSEGV, &sig_act, (struct sigaction *)0); |
435 | #ifdef SIGSYS |
436 | sigaction(SIGSYS, &sig_act, (struct sigaction *)0); |
437 | #endif |
438 | #endif /* USGISH */ |
439 | |
440 | |
441 | |
442 | |
443 | incCollection = create_IncludesCollection(); |
444 | |
445 | for(fp=filelist; *fp; fp++) { |
| 14 | | Loop condition is true. Entering loop body | |
|
446 | struct symhash *includes; |
447 | filecontent = getfile(*fp); |
| |
448 | ip = newinclude(*fp, (char *)NULL); |
449 | |
450 | includes = hash_copy( maininclist ); |
451 | find_includes(filecontent, ip, ip, 0, FALSE, incCollection, includes); |
452 | hash_free( includes ); |
453 | |
454 | freefile(filecontent); |
455 | recursive_pr_include(ip, ip->i_file, base_name(*fp)); |
456 | if (printed) |
457 | fwrite("\n\n", 2, 1, stdout); |
458 | recursive_pr_dummy(ip, ip->i_file); |
459 | inc_clean(); |
460 | } |
461 | if (printed) |
462 | printf("\n"); |
463 | |
464 | delete_IncludesCollection(incCollection); |
465 | |
466 | exit(0); |
467 | } |
468 | |
469 | struct filepointer *getfile(char *file) |
470 | { |
471 | int fd; |
472 | struct filepointer *content; |
473 | struct stat st; |
474 | off_t size_backup; |
475 | ssize_t bytes_read; |
476 | unsigned malloc_size; |
477 | |
478 | content = (struct filepointer *)malloc(sizeof(struct filepointer)); |
479 | if ((fd = open(file, O_RDONLY)) < 0) { |
| 16 | | Assuming the condition is false | |
|
| |
480 | warning("makedepend: Cannot open file \"%s\"\n", file); |
481 | content->f_p = content->f_base = content->f_end = (char *)malloc(1); |
482 | *content->f_p = '\0'; |
483 | return content; |
484 | } |
485 | (void)fstat(fd, &st); |
486 | |
487 | size_backup = st.st_size; |
488 | malloc_size = size_backup; |
489 | |
490 | |
491 | |
492 | if ( (off_t)malloc_size != size_backup ) |
| |
493 | { |
494 | close( fd ); |
495 | warning("makedepend: File \"%s\" is too large.\n", file); |
496 | content->f_p = content->f_base = content->f_end = (char *)malloc(1); |
497 | *content->f_p = '\0'; |
498 | return content; |
499 | } |
500 | |
501 | content->f_base = (char *)malloc(malloc_size+1); |
| 19 | | Value assigned to field 'f_base' | |
|
502 | if (content->f_base == NULL) |
| 20 | | Assuming field 'f_base' is equal to NULL | |
|
| |
503 | fatalerr("makedepend: Cannot allocate memory to process file \"%s\"\n", file); |
504 | if ((bytes_read = read(fd, content->f_base, malloc_size)) < 0) |
| 22 | | Assuming the condition is false | |
|
| |
505 | if ( st.st_mode & S_IFREG ) |
506 | fatalerr("makedepend: Failed to read file \"%s\"\n", file); |
507 | |
508 | close(fd); |
509 | content->f_p = content->f_base; |
510 | content->f_end = content->f_base + bytes_read; |
| 24 | | Null pointer value stored to field 'f_end' | |
|
511 | *content->f_end = '\0'; |
| 25 | | Dereference of null pointer (loaded from field 'f_end') |
|
512 | content->f_line = 0; |
513 | return content; |
514 | } |
515 | |
516 | void freefile(struct filepointer *fp) |
517 | { |
518 | free(fp->f_base); |
519 | free(fp); |
520 | } |
521 | |
522 | char *copy(char const *str) |
523 | { |
524 | char *p = (char *)malloc(strlen(str) + 1); |
525 | assert(p); |
526 | strcpy(p, str); |
527 | return p; |
528 | } |
529 | |
530 | int match(char const *str, char **list) |
531 | { |
532 | int i; |
533 | |
534 | for (i=0; *list; i++, list++) |
535 | if (strcmp(str, *list) == 0) |
536 | return i; |
537 | return -1; |
538 | } |
539 | |
540 | |
541 | |
542 | |
543 | |
544 | char *get_line(struct filepointer *filep) |
545 | { |
546 | char *p, |
547 | *eof, |
548 | *bol; |
549 | int lineno; |
550 | |
551 | p = filep->f_p; |
552 | eof = filep->f_end; |
553 | if (p >= eof) |
554 | return (char *)NULL; |
555 | lineno = filep->f_line; |
556 | |
557 | for(bol = p--; ++p < eof; ) { |
558 | if (*p == '/' && *(p+1) == '*') { |
559 | *p++ = ' '; |
560 | *p++ = ' '; |
561 | while (*p) { |
562 | if (*p == '*' && *(p+1) == '/') { |
563 | *p++ = ' '; |
564 | *p = ' '; |
565 | break; |
566 | } |
567 | else if (*p == '\n') |
568 | lineno++; |
569 | *p++ = ' '; |
570 | } |
571 | continue; |
572 | } |
573 | else if (*p == '/' && *(p+1) == '/') { |
574 | *p++ = ' '; |
575 | *p++ = ' '; |
576 | while (*p && *p != '\n') |
577 | *p++ = ' '; |
578 | if ( *p == '\n' ) |
579 | p--; |
580 | lineno++; |
581 | continue; |
582 | } |
583 | else if (*p == '\\') { |
584 | if (*(p+1) == '\n') { |
585 | *p = ' '; |
586 | *(p+1) = ' '; |
587 | lineno++; |
588 | } |
589 | } |
590 | else if (*p == '\n') { |
591 | lineno++; |
592 | if (*bol == '#') { |
593 | char *cp; |
594 | |
595 | *p++ = '\0'; |
596 | |
597 | for (cp = bol+1; |
598 | *cp && (*cp == ' ' || *cp == '\t'); cp++); |
599 | if (*cp) goto done; |
600 | } |
601 | bol = p+1; |
602 | } |
603 | } |
604 | if (*bol != '#') |
605 | bol = NULL; |
606 | done: |
607 | filep->f_p = p; |
608 | filep->f_line = lineno; |
609 | return bol; |
610 | } |
611 | |
612 | |
613 | |
614 | |
615 | |
616 | char *base_name(char *file) |
617 | { |
618 | char *p; |
619 | |
620 | file = copy(file); |
621 | for(p=file+strlen(file); p>file && *p != '.'; p--) ; |
622 | |
623 | if (*p == '.') |
624 | *p = '\0'; |
625 | |
626 | while (p > file) { |
627 | if ( *p == '/' || *p == '\\') { |
628 | file = p + 1; |
629 | break; |
630 | } |
631 | p--; |
632 | } |
633 | return file; |
634 | } |
635 | |
636 | #if defined(USG) && !defined(CRAY) && !defined(SVR4) |
637 | int rename (char *from, char *to) |
638 | { |
639 | (void) unlink (to); |
640 | if (link (from, to) == 0) { |
641 | unlink (from); |
642 | return 0; |
643 | } else { |
644 | return -1; |
645 | } |
646 | } |
647 | #endif /* USGISH */ |
648 | |
649 | void redirect(char *makefile) |
650 | { |
651 | FILE *fdout; |
652 | fdout = makefile ? freopen(makefile, "wb", stdout) : NULL; |
653 | if (fdout == NULL) |
654 | fatalerr("cannot open \"%s\"\n", makefile ? makefile : "<NULL>"); |
655 | } |
656 | |
657 | #if defined __GNUC__ |
658 | __attribute__ ((format (printf, 1, 2))) |
659 | #endif |
660 | void fatalerr(char *msg, ...) |
661 | { |
662 | va_list args; |
663 | fprintf(stderr, "%s: error: ", ProgramName); |
664 | va_start(args, msg); |
665 | vfprintf(stderr, msg, args); |
666 | va_end(args); |
667 | exit (1); |
668 | } |
669 | |
670 | #if defined __GNUC__ |
671 | __attribute__ ((format (printf, 1, 2))) |
672 | #endif |
673 | void warning(char const *msg, ...) |
674 | { |
675 | #ifdef DEBUG_MKDEPEND |
676 | va_list args; |
677 | fprintf(stderr, "%s: warning: ", ProgramName); |
678 | va_start(args, msg); |
679 | vfprintf(stderr, msg, args); |
680 | va_end(args); |
681 | #else |
682 | (void)msg; |
683 | #endif /* DEBUG_MKDEPEND */ |
684 | } |
685 | |
686 | #if defined __GNUC__ |
687 | __attribute__ ((format (printf, 1, 2))) |
688 | #endif |
689 | void warning1(char const *msg, ...) |
690 | { |
691 | #ifdef DEBUG_MKDEPEND |
692 | va_list args; |
693 | va_start(args, msg); |
694 | vfprintf(stderr, msg, args); |
695 | va_end(args); |
696 | #else |
697 | (void)msg; |
698 | #endif /* DEBUG_MKDEPEND */ |
699 | } |
700 | |
701 | void convert_slashes(char *path) |
702 | { |
703 | #if defined (_WIN32) |
704 | |
705 | |
706 | |
707 | char *ptr; |
708 | if (native_win_slashes) { |
709 | for (ptr = (char*)path; *ptr; ++ptr) |
710 | if (*ptr == '/') |
711 | *ptr = '\\'; |
712 | } else { |
713 | for (ptr = (char*)path; *ptr; ++ptr) |
714 | if (*ptr == '\\') |
715 | *ptr = '/'; |
716 | } |
717 | #else |
718 | (void)path; |
719 | #endif |
720 | } |
721 | |
722 | char* append_slash(char *path) |
723 | { |
724 | char *new_string; |
725 | const char cLastChar = path[strlen(path) - 1]; |
726 | if (cLastChar == '/' || cLastChar == '\\') { |
727 | new_string = path; |
728 | } else { |
729 | new_string = (char*)malloc(sizeof(char) * (strlen(path) + 2)); |
730 | assert(new_string); |
731 | strcpy(new_string, path); |
732 | if (native_win_slashes) |
733 | strcat(new_string, "\\"); |
734 | else |
735 | strcat(new_string, "/"); |
736 | } |
737 | return new_string; |
738 | } |
739 | |
740 | |