Thread: Request for portability test of strerror().

Request for portability test of strerror().

From
Pete Forman
Date:
I'm preparing a patch for backend/utils/error to make the printing of
error messages more robust.  It would be very helpful if people on
different systems would compile and run the following test program to
check the behaviour of strerror().

The PostgreSQL code is called only in exceptional circumstances, so
regular testing of my changes is not possible.

According to the standards UNIX95 (aka XPG4v2) and later, strerror()
should set errno to EINVAL if its argument is out of range.  Most
compliant systems seem to return a default string with a number
printed in it and so never set errno.

sys_nerr was last in XPG2 but has now been dropped.  I'm hoping to
remove it from the PostgreSQL code.


My results so far follow.  I've listed them by OS though there is also
a dependency on libc.

AIX 4.3:     errno = 0 after strerror(-1) returned "Error -1 occurred."
Cygwin B20:  errno = 0 after strerror(-1) returned "error -1"
IRIX 6.5:    errno = 0 after strerror(-1) returned NULL
Redhat 6.2:  errno = 0 after strerror(-1) returned "Unknown error 4294967295"
Solaris 2.6: errno = 0 after strerror(-1) returned NULL
Solaris 7:   errno = 0 after strerror(-1) returned NULL


What I'd like to know is whether any version of strerror() returns a
non-NULL pointer that does not contain a print of the number.
--
Pete Forman                 -./\.- Disclaimer: This post is originated
Western Geophysical           -./\.-  by myself and does not represent
pete.forman@westgeo.com         -./\.-  the opinion of Baker Hughes or
http://www.crosswinds.net/~petef  -./\.-  its divisions.

Attachment

Re: Request for portability test of strerror().

From
Jason Tishler
Date:
Pete,

On Fri, Oct 20, 2000 at 12:33:06PM +0100, Pete Forman wrote:
> I'm preparing a patch for backend/utils/error to make the printing of
> error messages more robust.  It would be very helpful if people on
> different systems would compile and run the following test program to
> check the behaviour of strerror().

On Cygwin 1.1.4, I get the following:

    $ uname -a
    CYGWIN_NT-4.0 KOSH 1.1.4(0.26/3/2) 2000-08-03 20:53 i686 unknown
    $ strerror
    errno = 0 after strerror(-1) returned "error -1"

Jason

--
Jason Tishler
Director, Software Engineering       Phone: +1 (732) 264-8770 x235
Dot Hill Systems Corporation         Fax:   +1 (732) 264-8798
82 Bethany Road, Suite 7             Email: Jason.Tishler@dothill.com
Hazlet, NJ 07730 USA                 WWW:   http://www.dothill.com

Re: Request for portability test of strerror().

From
Bruce Momjian
Date:
Pete, can you handle coversion of fprintf(stderr) to elog at the same
time?  It would be nice, but it can only be done in places where elog is
safe.


Content-Description: message body text

> I'm preparing a patch for backend/utils/error to make the printing of
> error messages more robust.  It would be very helpful if people on
> different systems would compile and run the following test program to
> check the behaviour of strerror().
>
> The PostgreSQL code is called only in exceptional circumstances, so
> regular testing of my changes is not possible.
>
> According to the standards UNIX95 (aka XPG4v2) and later, strerror()
> should set errno to EINVAL if its argument is out of range.  Most
> compliant systems seem to return a default string with a number
> printed in it and so never set errno.
>
> sys_nerr was last in XPG2 but has now been dropped.  I'm hoping to
> remove it from the PostgreSQL code.
>
Content-Description: Test behaviour of strerror()

[ Attachment, skipping... ]
Content-Description: message body and .signature

>
> My results so far follow.  I've listed them by OS though there is also
> a dependency on libc.
>
> AIX 4.3:     errno = 0 after strerror(-1) returned "Error -1 occurred."
> Cygwin B20:  errno = 0 after strerror(-1) returned "error -1"
> IRIX 6.5:    errno = 0 after strerror(-1) returned NULL
> Redhat 6.2:  errno = 0 after strerror(-1) returned "Unknown error 4294967295"
> Solaris 2.6: errno = 0 after strerror(-1) returned NULL
> Solaris 7:   errno = 0 after strerror(-1) returned NULL
>
>
> What I'd like to know is whether any version of strerror() returns a
> non-NULL pointer that does not contain a print of the number.
> --
> Pete Forman                 -./\.- Disclaimer: This post is originated
> Western Geophysical           -./\.-  by myself and does not represent
> pete.forman@westgeo.com         -./\.-  the opinion of Baker Hughes or
> http://www.crosswinds.net/~petef  -./\.-  its divisions.


--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Re: Request for portability test of strerror().

From
Pete Forman
Date:
Pete Forman writes:
 > What I'd like to know is whether any version of strerror() returns
 > a non-NULL pointer that does not contain a print of the number.

Bernd Tegg writes:
> QNX 4.25: errno = 0 after strerror(-1) returned "Unknown error"
> (egcs-2.91.66 using watcom 10.6 QNX specific libs)

I'll modify the question then.  Does any version of strerror() return
a non-NULL pointer to a garbage string?


The proposed modifications to the PostgreSQL code would be to remove
references to sys_nerr and print both the error number and its text,
if available.  Testing against sys_nerr is probably redundant anyway
as most calls to the routines will be with a valid errno.  If anyone
feels strongly about keeping sys_nerr it should be tested for by
configure and not with the OS-specific ifdefs in the code.
--
Pete Forman                    -./\.- <mailto:pete.forman@westgeo.com>
Western Geophysical              -./\.-          <tel:+44-1234-224798>
Manton Lane, Bedford, MK41 7PA, UK -./\.-        <fax:+44-1234-224804>
    -./\.-  <http://www.bedford.waii.com/wsdev/petef/PeteF_links.html>