2 * Copyright (c) 2002 Juli Mallett. All rights reserved.
3 * Copyright (c) 1988, 1989, 1990, 1993
4 * The Regents of the University of California. All rights reserved.
5 * Copyright (c) 1989 by Berkeley Softworks
8 * This code is derived from software contributed to Berkeley by
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
27 * $FreeBSD: src/usr.bin/make/util.c,v 1.5.2.2 2001/02/13 03:13:58 will Exp $
28 * $DragonFly: src/usr.bin/make/util.c,v 1.9 2004/12/10 19:22:24 okumoto Exp $
31 #include <sys/types.h>
46 #include "pathnames.h"
50 * Print a debugging message given its format.
56 * The message is printed.
60 Debug(const char *fmt, ...)
65 vfprintf(stderr, fmt, ap);
72 * Print an error message given its format.
78 * The message is printed.
82 Error(const char *fmt, ...)
86 vfprintf(stderr, fmt, ap);
88 fprintf(stderr, "\n");
94 * Produce a Fatal error message. If jobs are running, waits for them
105 Fatal(const char *fmt, ...)
112 vfprintf(stderr, fmt, ap);
114 fprintf(stderr, "\n");
119 exit(2); /* Not 1 so -q can distinguish error */
124 * Major exception once jobs are being created. Kills all jobs, prints
125 * a message and exits.
131 * All children are killed indiscriminately and the program Lib_Exits
135 Punt(const char *fmt, ...)
140 fprintf(stderr, "make: ");
141 vfprintf(stderr, fmt, ap);
143 fprintf(stderr, "\n");
151 * Exit without giving a message.
166 exit(2); /* Not 1, so -q can distinguish error */
171 * Called when aborting due to errors in child shell to signal
172 * abnormal exit, with the number of errors encountered in Make_Make.
184 Fatal("%d error%s", errors, errors == 1 ? "" : "s");
189 * malloc, but die on error.
196 if ((p = malloc(len)) == NULL)
203 * strdup, but die on error.
206 estrdup(const char *str)
210 if ((p = strdup(str)) == NULL)
217 * realloc, but die on error.
220 erealloc(void *ptr, size_t size)
223 if ((ptr = realloc(ptr, size)) == NULL)
230 * die when out of memory.
240 * Remove a file carefully, avoiding directories.
243 eunlink(const char *file)
247 if (lstat(file, &st) == -1)
250 if (S_ISDIR(st.st_mode)) {
254 return (unlink(file));
259 * Print the address of a node, used as an interative function.
262 PrintAddr(void *a, void *b __unused)