Updated the copyright year.
[userinfo.git] / src / err.c
blob699b80d020f45163e6e6559f489b55efc0fc9ad2
1 /*
2 Copyright (C) 2001-2011 Ben Kibbey <bjk@luxsci.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02110-1301 USA
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <stdarg.h>
21 #include <limits.h>
23 #define err(eval, fmt, ...) print_string(eval, 1, fmt, ## __VA_ARGS__)
24 #define errx(eval, fmt, ...) print_string(eval, 0, fmt, ## __VA_ARGS__)
25 #define warn(fmt, ...) print_string(-1, 0, fmt, ## __VA_ARGS__)
26 #define warnx(fmt, ...) print_string(-1, 1, fmt, ## __VA_ARGS__)
28 void print_string(int eval, int prog, const char *fmt, ...)
30 va_list ap;
31 char line[LINE_MAX];
33 #ifndef HAVE___PROGNAME
34 char *__progname = "ui";
35 #else
36 extern char *__progname;
37 #endif
39 va_start(ap, fmt);
40 vsnprintf(line, sizeof(line), fmt, ap);
41 va_end(ap);
43 fprintf(stderr, "%s%s%s\n", (prog) ? __progname : "", (prog) ? ": " : "",
44 line);
46 if (eval > -1)
47 exit(eval);