diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2001-01-21 00:59:26 +0000 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2001-01-21 00:59:26 +0000 |
| commit | 023a48b811d8e0a288e2bf999bb4f3e028f5d0c9 (patch) | |
| tree | a283db4d46bbd64cdaf91426b87bc4f816e5e9d0 /src/backend/utils/error/elog.c | |
| parent | 37fd19845679f7648e09c61bbaf7199ca713f79b (diff) | |
| download | postgresql-023a48b811d8e0a288e2bf999bb4f3e028f5d0c9.tar.gz | |
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.
Diffstat (limited to 'src/backend/utils/error/elog.c')
| -rw-r--r-- | src/backend/utils/error/elog.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 2bb6cd976c..6a842bd469 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -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) { |
