mirror of
https://github.com/postgres/postgres.git
synced 2025-07-05 07:21:24 +03:00
Deal with C++ incompatibility of sys_nerr declaration by taking it out
of c.h altogether, and putting it into the only places that use it (elog.c and exc.c), instead. Modify these routines to check for a NULL or empty-string return from strerror, too, since some platforms define strerror to return empty string for unknown errors (what a useless definition that is ...). Clean up some cruft in ExcPrint while at it.
This commit is contained in:
@ -8,11 +8,10 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.77 2001/01/19 22:08:47 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.78 2001/01/21 00:59:26 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#include <time.h>
|
||||
@ -44,6 +43,10 @@
|
||||
|
||||
extern int errno;
|
||||
|
||||
#ifdef HAVE_SYS_NERR
|
||||
extern int sys_nerr;
|
||||
#endif
|
||||
|
||||
extern CommandDest whereToSendOutput;
|
||||
|
||||
#ifdef ENABLE_SYSLOG
|
||||
@ -120,10 +123,8 @@ elog(int lev, const char *fmt, ...)
|
||||
char *msg_buf = msg_fixedbuf;
|
||||
/* this buffer is only used for strange values of lev: */
|
||||
char prefix_buf[32];
|
||||
#ifdef HAVE_SYS_NERR
|
||||
/* this buffer is only used if errno has a bogus value: */
|
||||
char errorstr_buf[32];
|
||||
#endif
|
||||
const char *errorstr;
|
||||
const char *prefix;
|
||||
const char *cp;
|
||||
@ -137,19 +138,24 @@ elog(int lev, const char *fmt, ...)
|
||||
if (lev <= DEBUG && Debugfile < 0)
|
||||
return; /* ignore debug msgs if noplace to send */
|
||||
|
||||
/* Save error str before calling any function that might change errno */
|
||||
if (errno >= 0
|
||||
#ifdef HAVE_SYS_NERR
|
||||
/* save errno string for %m */
|
||||
if (errno < sys_nerr && errno >= 0)
|
||||
&& errno <= sys_nerr
|
||||
#endif
|
||||
)
|
||||
errorstr = strerror(errno);
|
||||
else
|
||||
errorstr = NULL;
|
||||
/*
|
||||
* Some strerror()s return an empty string for out-of-range errno.
|
||||
* This is ANSI C spec compliant, but not exactly useful.
|
||||
*/
|
||||
if (errorstr == NULL || *errorstr == '\0')
|
||||
{
|
||||
sprintf(errorstr_buf, "error %d", errno);
|
||||
errorstr = errorstr_buf;
|
||||
}
|
||||
#else
|
||||
/* assume strerror() will cope gracefully with bogus errno values */
|
||||
errorstr = strerror(errno);
|
||||
#endif
|
||||
|
||||
if (lev == ERROR || lev == FATAL)
|
||||
{
|
||||
|
Reference in New Issue
Block a user