mirror of
https://github.com/gryf/wmaker.git
synced 2026-02-02 14:15:46 +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:
@@ -33,6 +33,7 @@ changes since wmaker 0.61.1:
|
||||
1. if old is NULL, return wmalloc(new_size).
|
||||
2. if new_size is 0, call wfree(old), and return NULL.
|
||||
3. if both old is a valid pointer and new_size>0, call realloc.
|
||||
- added wstrerror(int errnum) to return the string associated with errnum.
|
||||
|
||||
changes since wmaker 0.61.0:
|
||||
............................
|
||||
|
||||
@@ -142,6 +142,9 @@ typedef void (waborthandler)(int);
|
||||
waborthandler *wsetabort(waborthandler*);
|
||||
|
||||
|
||||
/* don't free the returned string */
|
||||
char *wstrerror(int errnum);
|
||||
|
||||
void wfatal(const char *msg, ...);
|
||||
void wwarning(const char *msg, ...);
|
||||
void wsyserror(const char *msg, ...);
|
||||
@@ -156,6 +159,7 @@ char *wexpandpath(char *path);
|
||||
|
||||
/* don't free the returned string */
|
||||
char *wgethomedir();
|
||||
|
||||
void *wmalloc(size_t size);
|
||||
void *wrealloc(void *ptr, size_t newsize);
|
||||
void wfree(void *ptr);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user