2 * Window Maker miscelaneous function library
4 * Copyright (c) 1997-2003 Alfredo K. Kojima
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.
29 extern char *_WINGS_progname
;
33 /*********************************************************************
34 * Returns the system error message associated with error code 'errnum'
35 *********************************************************************/
36 char *wstrerror(int errnum
)
38 #if defined(HAVE_STRERROR)
39 return strerror(errnum
);
40 #elif !defined(HAVE_STRERROR) && defined(BSD)
41 extern int errno
, sys_nerr
;
43 extern char *sys_errlist
[];
45 static char buf
[] = "Unknown error 12345678901234567890";
48 return sys_errlist
[errnum
];
50 snprintf(buf
, sizeof(buf
), _("Unknown error %d"), errnum
);
52 #else /* no strerror() and no sys_errlist[] */
53 static char buf
[] = "Error 12345678901234567890";
55 snprintf(buf
, sizeof(buf
), _("Error %d"), errnum
);
60 /*********************************************************************
61 * Prints a message with variable arguments
63 * msg - message to print with optional formatting
64 * ... - arguments to use on formatting
65 *********************************************************************/
66 void wmessage(const char *msg
, ...)
73 vsnprintf(buf
, MAXLINE
- 3, msg
, args
);
76 fputs(_WINGS_progname
? _WINGS_progname
: "WINGs", stderr
);
85 /*********************************************************************
86 * Prints a warning message with variable arguments
88 * msg - message to print with optional formatting
89 * ... - arguments to use on formatting
90 *********************************************************************/
91 void wwarning(const char *msg
, ...)
98 vsnprintf(buf
, MAXLINE
- 3, msg
, args
);
101 fputs(_WINGS_progname
? _WINGS_progname
: "WINGs", stderr
);
102 fputs(_(" warning: "), stderr
);
110 /**************************************************************************
111 * Prints a fatal error message with variable arguments and terminates
113 * msg - message to print with optional formatting
114 * ... - arguments to use on formatting
115 **************************************************************************/
116 void wfatal(const char *msg
, ...)
123 vsnprintf(buf
, MAXLINE
- 3, msg
, args
);
126 fputs(_WINGS_progname
? _WINGS_progname
: "WINGs", stderr
);
127 fputs(_(" fatal error: "), stderr
);
135 /*********************************************************************
136 * Prints a system error message with variable arguments
138 * msg - message to print with optional formatting
139 * ... - arguments to use on formatting
140 *********************************************************************/
141 void wsyserror(const char *msg
, ...)
148 vsnprintf(buf
, MAXLINE
- 3, msg
, args
);
150 fputs(_WINGS_progname
? _WINGS_progname
: "WINGs", stderr
);
151 fputs(_(" error: "), stderr
);
154 fputs(wstrerror(error
), stderr
);
161 /*********************************************************************
162 * Prints a system error message with variable arguments, being given
165 * error - the error code foe which to print the message
166 * msg - message to print with optional formatting
167 * ... - arguments to use on formatting
168 *********************************************************************/
169 void wsyserrorwithcode(int error
, const char *msg
, ...)
175 vsnprintf(buf
, MAXLINE
- 3, msg
, args
);
177 fputs(_WINGS_progname
? _WINGS_progname
: "WINGs", stderr
);
178 fputs(_(" error: "), stderr
);
181 fputs(wstrerror(error
), stderr
);