1 | /* $Id: err.c 2113 2008-12-25 13:21:58Z bird $ */
|
---|
2 | /** @file
|
---|
3 | * Override err.h so we get the program name right.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (c) 2005-2008 knut st. osmundsen <[email protected]>
|
---|
8 | *
|
---|
9 | * This file is part of kBuild.
|
---|
10 | *
|
---|
11 | * kBuild is free software; you can redistribute it and/or modify
|
---|
12 | * it under the terms of the GNU General Public License as published by
|
---|
13 | * the Free Software Foundation; either version 3 of the License, or
|
---|
14 | * (at your option) any later version.
|
---|
15 | *
|
---|
16 | * kBuild is distributed in the hope that it will be useful,
|
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | * GNU General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with kBuild. If not, see <http://www.gnu.org/licenses/>
|
---|
23 | *
|
---|
24 | */
|
---|
25 |
|
---|
26 | /*******************************************************************************
|
---|
27 | * Header Files *
|
---|
28 | *******************************************************************************/
|
---|
29 | #include "config.h"
|
---|
30 | #include <stdio.h>
|
---|
31 | #include <stdarg.h>
|
---|
32 | #include <string.h>
|
---|
33 | #include <errno.h>
|
---|
34 | #include "err.h"
|
---|
35 |
|
---|
36 |
|
---|
37 | /** The current program name. */
|
---|
38 | const char *g_progname = "kmk";
|
---|
39 |
|
---|
40 |
|
---|
41 | int err(int eval, const char *fmt, ...)
|
---|
42 | {
|
---|
43 | va_list args;
|
---|
44 | int error = errno;
|
---|
45 | fprintf(stderr, "%s: ", g_progname);
|
---|
46 | va_start(args, fmt);
|
---|
47 | vfprintf(stderr, fmt, args);
|
---|
48 | va_end(args);
|
---|
49 | fprintf(stderr, ": %s\n", strerror(error));
|
---|
50 |
|
---|
51 | return eval;
|
---|
52 | }
|
---|
53 |
|
---|
54 |
|
---|
55 | int errx(int eval, const char *fmt, ...)
|
---|
56 | {
|
---|
57 | va_list args;
|
---|
58 | fprintf(stderr, "%s: ", g_progname);
|
---|
59 | va_start(args, fmt);
|
---|
60 | vfprintf(stderr, fmt, args);
|
---|
61 | va_end(args);
|
---|
62 | fprintf(stderr, "\n");
|
---|
63 |
|
---|
64 | return eval;
|
---|
65 | }
|
---|
66 |
|
---|
67 | void warn(const char *fmt, ...)
|
---|
68 | {
|
---|
69 | int error = errno;
|
---|
70 | va_list args;
|
---|
71 | fprintf(stderr, "%s: ", g_progname);
|
---|
72 | va_start(args, fmt);
|
---|
73 | vfprintf(stderr, fmt, args);
|
---|
74 | va_end(args);
|
---|
75 | fprintf(stderr, ": %s\n", strerror(error));
|
---|
76 | }
|
---|
77 |
|
---|
78 | void warnx(const char *fmt, ...)
|
---|
79 | {
|
---|
80 | va_list args;
|
---|
81 | fprintf(stderr, "%s: ", g_progname);
|
---|
82 | va_start(args, fmt);
|
---|
83 | vfprintf(stderr, fmt, args);
|
---|
84 | va_end(args);
|
---|
85 | fprintf(stderr, "\n");
|
---|
86 | }
|
---|
87 |
|
---|