Updating to version 0.20.2
[wmaker-crm.git] / WINGs / error.c
bloba6e7abad7e8acfb3852e29d12fad27f7638bf024
1 /*
2 * Window Maker miscelaneous function library
3 *
4 * Copyright (c) 1997 Alfredo K. Kojima
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "../src/config.h"
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <stdarg.h>
27 #include <string.h>
28 #include <errno.h>
31 extern char *_WINGS_progname;
33 #define MAXLINE 1024
36 /**************************************************************************
37 * Prints a fatal error message with variable arguments and terminates
39 * msg - message to print with optional formatting
40 * ... - arguments to use on formatting
41 **************************************************************************/
42 void
43 wfatal(const char *msg, ...)
45 va_list args;
46 char buf[MAXLINE];
48 va_start(args, msg);
50 vsprintf(buf, msg, args);
51 strcat(buf,"\n");
52 fflush(stdout);
53 fputs(_WINGS_progname, stderr);
54 fputs(" fatal error: ",stderr);
55 fputs(buf, stderr);
56 fflush(stdout);
57 fflush(stderr);
59 va_end(args);
63 /*********************************************************************
64 * Prints a warning message with variable arguments
66 * msg - message to print with optional formatting
67 * ... - arguments to use on formatting
68 *********************************************************************/
69 void
70 wwarning(const char *msg, ...)
72 va_list args;
73 char buf[MAXLINE];
75 va_start(args, msg);
77 vsprintf(buf, msg, args);
78 strcat(buf,"\n");
79 fflush(stdout);
80 fputs(_WINGS_progname, stderr);
81 fputs(" warning: ",stderr);
82 fputs(buf, stderr);
83 fflush(stdout);
84 fflush(stderr);
86 va_end(args);
90 /*********************************************************************
91 * Prints a system error message with variable arguments
93 * msg - message to print with optional formatting
94 * ... - arguments to use on formatting
95 *********************************************************************/
96 void
97 wsyserror(const char *msg, ...)
99 va_list args;
100 char buf[MAXLINE];
101 #ifdef HAVE_STRERROR
102 int error=errno;
103 #endif
104 va_start(args, msg);
105 vsprintf(buf, msg, args);
106 fflush(stdout);
107 fputs(_WINGS_progname, stderr);
108 fputs(" error: ", stderr);
109 strcat(buf, ": ");
110 #ifdef HAVE_STRERROR
111 strcat(buf, strerror(error));
112 strcat(buf,"\n");
113 fputs(buf, stderr);
114 fflush(stderr);
115 fflush(stdout);
116 #else
117 perror(buf);
118 #endif
119 va_end(args);