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.10 2004/12/17 21:09:04 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, ...)
87 vfprintf(stderr, fmt, ap);
89 fprintf(stderr, "\n");
95 * Produce a Fatal error message. If jobs are running, waits for them
106 Fatal(const char *fmt, ...)
114 vfprintf(stderr, fmt, ap);
116 fprintf(stderr, "\n");
121 exit(2); /* Not 1 so -q can distinguish error */
126 * Major exception once jobs are being created. Kills all jobs, prints
127 * a message and exits.
133 * All children are killed indiscriminately and the program Lib_Exits
137 Punt(const char *fmt, ...)
142 fprintf(stderr, "make: ");
143 vfprintf(stderr, fmt, ap);
145 fprintf(stderr, "\n");
153 * Exit without giving a message.
168 exit(2); /* Not 1, so -q can distinguish error */
173 * Called when aborting due to errors in child shell to signal
174 * abnormal exit, with the number of errors encountered in Make_Make.
186 Fatal("%d error%s", errors, errors == 1 ? "" : "s");
191 * malloc, but die on error.
198 if ((p = malloc(len)) == NULL)
205 * strdup, but die on error.
208 estrdup(const char *str)
212 if ((p = strdup(str)) == NULL)
219 * realloc, but die on error.
222 erealloc(void *ptr, size_t size)
225 if ((ptr = realloc(ptr, size)) == NULL)
232 * die when out of memory.
242 * Remove a file carefully, avoiding directories.
245 eunlink(const char *file)
249 if (lstat(file, &st) == -1)
252 if (S_ISDIR(st.st_mode)) {
256 return (unlink(file));
261 * Print the address of a node, used as an interative function.
264 PrintAddr(void *a, void *b __unused)