mirror of
https://github.com/postgres/postgres.git
synced 2025-04-29 13:56:47 +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:
parent
37fd198456
commit
023a48b811
@ -8,11 +8,10 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* 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 "postgres.h"
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
@ -44,6 +43,10 @@
|
|||||||
|
|
||||||
extern int errno;
|
extern int errno;
|
||||||
|
|
||||||
|
#ifdef HAVE_SYS_NERR
|
||||||
|
extern int sys_nerr;
|
||||||
|
#endif
|
||||||
|
|
||||||
extern CommandDest whereToSendOutput;
|
extern CommandDest whereToSendOutput;
|
||||||
|
|
||||||
#ifdef ENABLE_SYSLOG
|
#ifdef ENABLE_SYSLOG
|
||||||
@ -120,10 +123,8 @@ elog(int lev, const char *fmt, ...)
|
|||||||
char *msg_buf = msg_fixedbuf;
|
char *msg_buf = msg_fixedbuf;
|
||||||
/* this buffer is only used for strange values of lev: */
|
/* this buffer is only used for strange values of lev: */
|
||||||
char prefix_buf[32];
|
char prefix_buf[32];
|
||||||
#ifdef HAVE_SYS_NERR
|
|
||||||
/* this buffer is only used if errno has a bogus value: */
|
/* this buffer is only used if errno has a bogus value: */
|
||||||
char errorstr_buf[32];
|
char errorstr_buf[32];
|
||||||
#endif
|
|
||||||
const char *errorstr;
|
const char *errorstr;
|
||||||
const char *prefix;
|
const char *prefix;
|
||||||
const char *cp;
|
const char *cp;
|
||||||
@ -137,19 +138,24 @@ elog(int lev, const char *fmt, ...)
|
|||||||
if (lev <= DEBUG && Debugfile < 0)
|
if (lev <= DEBUG && Debugfile < 0)
|
||||||
return; /* ignore debug msgs if noplace to send */
|
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
|
#ifdef HAVE_SYS_NERR
|
||||||
/* save errno string for %m */
|
&& errno <= sys_nerr
|
||||||
if (errno < sys_nerr && errno >= 0)
|
#endif
|
||||||
|
)
|
||||||
errorstr = strerror(errno);
|
errorstr = strerror(errno);
|
||||||
else
|
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);
|
sprintf(errorstr_buf, "error %d", errno);
|
||||||
errorstr = errorstr_buf;
|
errorstr = errorstr_buf;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
/* assume strerror() will cope gracefully with bogus errno values */
|
|
||||||
errorstr = strerror(errno);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (lev == ERROR || lev == FATAL)
|
if (lev == ERROR || lev == FATAL)
|
||||||
{
|
{
|
||||||
|
@ -8,11 +8,12 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/error/Attic/exc.c,v 1.33 2001/01/09 18:40:14 petere Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/error/Attic/exc.c,v 1.34 2001/01/21 00:59:26 tgl Exp $
|
||||||
*
|
*
|
||||||
* NOTE
|
* NOTE
|
||||||
* XXX this code needs improvement--check for state violations and
|
* XXX this code needs improvement--check for state violations and
|
||||||
* XXX reset after handling an exception.
|
* XXX reset after handling an exception.
|
||||||
|
* XXX Probably should be merged with elog.c.
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -23,6 +24,13 @@
|
|||||||
#include "storage/ipc.h"
|
#include "storage/ipc.h"
|
||||||
#include "utils/exc.h"
|
#include "utils/exc.h"
|
||||||
|
|
||||||
|
extern int errno;
|
||||||
|
|
||||||
|
#ifdef HAVE_SYS_NERR
|
||||||
|
extern int sys_nerr;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static void ExcUnCaught(Exception *excP, ExcDetail detail, ExcData data,
|
static void ExcUnCaught(Exception *excP, ExcDetail detail, ExcData data,
|
||||||
ExcMessage message);
|
ExcMessage message);
|
||||||
static void ExcPrint(Exception *excP, ExcDetail detail, ExcData data,
|
static void ExcPrint(Exception *excP, ExcDetail detail, ExcData data,
|
||||||
@ -40,8 +48,6 @@ ExcFrame *ExcCurFrameP = NULL;
|
|||||||
|
|
||||||
static ExcProc *ExcUnCaughtP = NULL;
|
static ExcProc *ExcUnCaughtP = NULL;
|
||||||
|
|
||||||
extern char *ProgramName;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Exported Functions
|
* Exported Functions
|
||||||
*/
|
*/
|
||||||
@ -94,49 +100,49 @@ EnableExceptionHandling(bool on)
|
|||||||
ExceptionHandlingEnabled = on;
|
ExceptionHandlingEnabled = on;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern int errno;
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ExcPrint(Exception *excP,
|
ExcPrint(Exception *excP,
|
||||||
ExcDetail detail,
|
ExcDetail detail,
|
||||||
ExcData data,
|
ExcData data,
|
||||||
ExcMessage message)
|
ExcMessage message)
|
||||||
{
|
{
|
||||||
|
/* this buffer is only used if errno has a bogus value: */
|
||||||
|
char errorstr_buf[32];
|
||||||
|
const char *errorstr;
|
||||||
|
|
||||||
#ifdef lint
|
#ifdef lint
|
||||||
data = data;
|
data = data;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fflush(stdout); /* In case stderr is buffered */
|
/* Save error str before calling any function that might change errno */
|
||||||
|
if (errno >= 0
|
||||||
#if 0
|
#ifdef HAVE_SYS_NERR
|
||||||
if (ProgramName != NULL && *ProgramName != '\0')
|
&& errno <= sys_nerr
|
||||||
fprintf(stderr, "%s: ", ProgramName);
|
|
||||||
#endif
|
#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;
|
||||||
|
}
|
||||||
|
|
||||||
|
fflush(stdout); /* In case stderr is buffered */
|
||||||
|
|
||||||
if (message != NULL)
|
if (message != NULL)
|
||||||
fprintf(stderr, "%s", message);
|
fprintf(stderr, "%s", message);
|
||||||
else if (excP->message != NULL)
|
else if (excP->message != NULL)
|
||||||
fprintf(stderr, "%s", excP->message);
|
fprintf(stderr, "%s", excP->message);
|
||||||
else
|
else
|
||||||
#ifdef lint
|
fprintf(stderr, "UNNAMED EXCEPTION %p", excP);
|
||||||
fprintf(stderr, "UNNAMED EXCEPTION 0x%lx", excP);
|
|
||||||
#else
|
|
||||||
fprintf(stderr, "UNNAMED EXCEPTION 0x%lx", (long) excP);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
fprintf(stderr, " (%ld)", detail);
|
fprintf(stderr, " (%ld) [%s]\n", detail, errorstr);
|
||||||
|
|
||||||
#ifdef HAVE_SYS_NERR
|
|
||||||
if (errno > 0 && errno < sys_nerr)
|
|
||||||
#else
|
|
||||||
if (errno > 0)
|
|
||||||
#endif
|
|
||||||
fprintf(stderr, " [%s]", strerror(errno));
|
|
||||||
else if (errno != 0)
|
|
||||||
fprintf(stderr, " [Error %d]", errno);
|
|
||||||
|
|
||||||
fprintf(stderr, "\n");
|
|
||||||
|
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: c.h,v 1.87 2001/01/09 18:40:15 petere Exp $
|
* $Id: c.h,v 1.88 2001/01/21 00:59:24 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -993,10 +993,6 @@ extern int vsnprintf(char *str, size_t count, const char *fmt, va_list args);
|
|||||||
#include <regex/utils.h>
|
#include <regex/utils.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_SYS_NERR
|
|
||||||
extern int sys_nerr;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* ----------------
|
/* ----------------
|
||||||
* end of c.h
|
* end of c.h
|
||||||
* ----------------
|
* ----------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user