1
0
mirror of https://github.com/gryf/wmaker.git synced 2026-02-08 17:35:55 +01:00

Added char* wsterrror(int errnum) to return the string associated with errnum

This works even on platforms that don't provide strerror().
This commit is contained in:
dan
1999-12-11 00:39:57 +00:00
parent 4b69ea222e
commit bb75616aad
3 changed files with 36 additions and 27 deletions

View File

@@ -27,31 +27,40 @@
#include <string.h>
#include <errno.h>
#if !defined(HAVE_STRERROR) && defined(BSD)
#define HAVE_STRERROR
char *
strerror(int errnum)
{
extern int errno, sys_nerr;
#ifndef __DECC
extern char *sys_errlist[];
#endif
static char buf[] = "Unknown error 12345678901234567890";
if (errno < sys_nerr)
return sys_errlist[errnum];
sprintf (buf, "Unknown error %d", errnum);
return buf;
}
#endif
extern char *_WINGS_progname;
#define MAXLINE 1024
/*********************************************************************
* Returns the system error message associated with error code 'errnum'
*********************************************************************/
char*
wstrerror(int errnum)
{
#if defined(HAVE_STRERROR)
return strerror(errnum);
#elif !defined(HAVE_STRERROR) && defined(BSD)
extern int errno, sys_nerr;
# ifndef __DECC
extern char *sys_errlist[];
# endif
static char buf[] = "Unknown error number 12345678901234567890";
if (errno < sys_nerr)
return sys_errlist[errnum];
sprintf (buf, "Unknown error number %d", errnum);
return buf;
#else /* no strerror() and no sys_errlist[] */
static char buf[] = "Error number 12345678901234567890";
sprintf(buf, "Error number %d", errnum);
return buf;
#endif
}
/**************************************************************************
* Prints a fatal error message with variable arguments and terminates
*
@@ -117,24 +126,19 @@ wsyserror(const char *msg, ...)
{
va_list args;
char buf[MAXLINE];
#ifdef HAVE_STRERROR
int error=errno;
#endif
va_start(args, msg);
vsprintf(buf, msg, args);
fflush(stdout);
fputs(_WINGS_progname, stderr);
fputs(" error: ", stderr);
strcat(buf, ": ");
#ifdef HAVE_STRERROR
strcat(buf, strerror(error));
strcat(buf, wstrerror(error));
strcat(buf,"\n");
fputs(buf, stderr);
fflush(stderr);
fflush(stdout);
#else
perror(buf);
#endif
va_end(args);
}