Jens-S. Voeckler wrote:
>
> On Sat, 24 Jul 1999, Henrik Nordstrom wrote:
>
> ]> supported by the 64 bit environment any longer. On the other hand,
> ]> strerror() is guaranteed to return a NULL pointer for illegal error
> ]> numbers. I don't know if that is always true on all platforms (doubt it,
> ]> though), or even if it is prescribed by POSIX.
> ]
> ]I don't have access to the POSIX standard document, but the Open Group
> ]"The Single UNIX ® Specification, Version 2" does not guarantee that
> ]strerror returns NULL for unknown errors:
> ]
> ] On error errno may be set, but no return value is
> ] reserved to indicate an error.
>
> So, what is "no return value"? An undefined value? A null pointer? The
> guarantee I was talking about was just an empiric study of Solaris 7/64.
> Anyway, would the Squid gurus have me continue poking into the Squid/64?
> Not that I have much time left for it ;-)
undefined, Up to the implementation.
So I guess the reasonably portable sstrerror() with error detection
without depending on undocumented sys_XXX variables boils down to
const char *
xstrerror(void)
{
static char xstrerror_buf[BUFSIZ];
char *errstr
int err = errno;
errno = 0;
errstr = strerror(err);
if (!errstr || errno) {
errstr = "Unknown"
}
errno = err;
snprintf(xstrerror_buf, BUFSIZ, "(%d) %s", errno, errstr);
return xstrerror_buf;
}
This practice of watching errno is documented in "The Single UNIX ®
Specification, Version 2", but at the same time strerror is not
guaranteed (MAY be set) to update errno on errors...
/Henrik
Received on Tue Jul 29 2003 - 13:15:59 MDT
This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:12:16 MST