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.
31 extern char *_WINGS_progname
;
35 /*********************************************************************
36 * Returns the system error message associated with error code 'errnum'
37 *********************************************************************/
38 char *wstrerror(int errnum
)
40 #if defined(HAVE_STRERROR)
41 return strerror(errnum
);
42 #elif !defined(HAVE_STRERROR) && defined(BSD)
43 extern int errno
, sys_nerr
;
45 extern char *sys_errlist
[];
47 static char buf
[] = "Unknown error 12345678901234567890";
50 return sys_errlist
[errnum
];
52 snprintf(buf
, sizeof(buf
), _("Unknown error %d"), errnum
);
54 #else /* no strerror() and no sys_errlist[] */
55 static char buf
[] = "Error 12345678901234567890";
57 snprintf(buf
, sizeof(buf
), _("Error %d"), errnum
);
62 void __wmessage(int type
, void *extra
, const char *msg
, ...)
68 /* message format: <wings_progname>: <qualifier>: <message>[: <extra info>]"\n" */
69 snprintf(buf
, sizeof(buf
), "%s: ", _WINGS_progname
? _WINGS_progname
: "WINGs");
72 case WMESSAGE_TYPE_WARNING
:
73 snprintf(buf
+ strlen(buf
), sizeof(buf
) - strlen(buf
),
75 vsnprintf(buf
+ strlen(buf
), sizeof(buf
) - strlen(buf
),
78 case WMESSAGE_TYPE_FATAL
:
79 snprintf(buf
+ strlen(buf
), sizeof(buf
) - strlen(buf
),
81 vsnprintf(buf
+ strlen(buf
), sizeof(buf
) - strlen(buf
),
84 case WMESSAGE_TYPE_WSYSERROR
:
85 case WMESSAGE_TYPE_WSYSERRORWITHCODE
:
86 snprintf(buf
+ strlen(buf
), sizeof(buf
) - strlen(buf
),
88 vsnprintf(buf
+ strlen(buf
), sizeof(buf
) - strlen(buf
),
90 snprintf(buf
+ strlen(buf
), sizeof(buf
) - strlen(buf
),
91 ": %s", type
== WMESSAGE_TYPE_WSYSERROR
?
92 wstrerror(errno
) : wstrerror(*(int *)extra
));
94 case WMESSAGE_TYPE_MESSAGE
:
97 snprintf(buf
+ strlen(buf
), sizeof(buf
) - strlen(buf
), ": ");
98 vsnprintf(buf
+ strlen(buf
), sizeof(buf
) - strlen(buf
), msg
, args
);
102 strncat(buf
+ strlen(buf
), "\n", sizeof(buf
) - strlen(buf
) - 1);