This update includes the 0.20.3pre3 code
[wmaker-crm.git] / WINGs / error.c
bloba873b3d0c0f43aefbfd2c2f31224e628b86ec0e2
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>
30 #if !defined(HAVE_STRERROR) && defined(BSD)
31 #define HAVE_STRERROR
32 char *
33 strerror(int errnum)
35 extern int errno, sys_nerr;
36 #ifndef __DECC
37 extern char *sys_errlist[];
38 #endif
39 static char buf[] = "Unknown error 12345678901234567890";
41 if (errno < sys_nerr)
42 return sys_errlist[errnum];
44 sprintf (buf, "Unknown error %d", errnum);
45 return buf;
47 #endif
50 extern char *_WINGS_progname;
52 #define MAXLINE 1024
55 /**************************************************************************
56 * Prints a fatal error message with variable arguments and terminates
58 * msg - message to print with optional formatting
59 * ... - arguments to use on formatting
60 **************************************************************************/
61 void
62 wfatal(const char *msg, ...)
64 va_list args;
65 char buf[MAXLINE];
67 va_start(args, msg);
69 vsprintf(buf, msg, args);
70 strcat(buf,"\n");
71 fflush(stdout);
72 fputs(_WINGS_progname, stderr);
73 fputs(" fatal error: ",stderr);
74 fputs(buf, stderr);
75 fflush(stdout);
76 fflush(stderr);
78 va_end(args);
82 /*********************************************************************
83 * Prints a warning message with variable arguments
85 * msg - message to print with optional formatting
86 * ... - arguments to use on formatting
87 *********************************************************************/
88 void
89 wwarning(const char *msg, ...)
91 va_list args;
92 char buf[MAXLINE];
94 va_start(args, msg);
96 vsprintf(buf, msg, args);
97 strcat(buf,"\n");
98 fflush(stdout);
99 fputs(_WINGS_progname, stderr);
100 fputs(" warning: ",stderr);
101 fputs(buf, stderr);
102 fflush(stdout);
103 fflush(stderr);
105 va_end(args);
109 /*********************************************************************
110 * Prints a system error message with variable arguments
112 * msg - message to print with optional formatting
113 * ... - arguments to use on formatting
114 *********************************************************************/
115 void
116 wsyserror(const char *msg, ...)
118 va_list args;
119 char buf[MAXLINE];
120 #ifdef HAVE_STRERROR
121 int error=errno;
122 #endif
123 va_start(args, msg);
124 vsprintf(buf, msg, args);
125 fflush(stdout);
126 fputs(_WINGS_progname, stderr);
127 fputs(" error: ", stderr);
128 strcat(buf, ": ");
129 #ifdef HAVE_STRERROR
130 strcat(buf, strerror(error));
131 strcat(buf,"\n");
132 fputs(buf, stderr);
133 fflush(stderr);
134 fflush(stdout);
135 #else
136 perror(buf);
137 #endif
138 va_end(args);