Subject: Re `sys_errlist definition'
To: None <firstname.lastname@example.org>
From: Alan Peakall <email@example.com>
Date: 07/02/1996 16:12:03
Curt Sampson (firstname.lastname@example.org) writes:
> Now that sys_errlist is defined in errno.h, and defined correctly,
> a lot of non-ANSI programs break slightly when compiled because
> they also define it as just extern char * (without the const).
> What's the easiest and simplist way to determine, in the general
> case, whether one is running on a system that already has this
> defined? I'm currently using a #ifdef __NetBSD__ around the code,
> but I'd rather send back more general patches to the authors if I
> can, since I'm fairly certain this change needs to be made for
> FreeBSD and the like as well.
As one of the original guilty parties in this area (I originated the
gripe that lead to this declaration being relocated from `stdio.h'
to `errno.h'), my feeling is that if application maintainers are
to integrate patches to address this issue then all reference to
`sys_errlist' should be removed and replaced with
extern char *strerror();
extern char *strerror(int);
depending on whether the coding policy of the application is ANSI
or K&R. If compilation is attempted on an ANSI platform then this
declaration will be consistent with the one in `string.h'. If
compilation is on a non-ANSI platform then there should not be
a native declaration to provide a clash. `strerror()' may need to be
defined from some non ANSI platforms but as it is supplied with NetBSD
the need for a `__NetBSD__' controlled porting exception does not
arise. I believe that the GNU autoconf system standardises on a
macro called `HAVE_STRERROR'. The application maintainers can
still bundle a `strerror.c' with the application, implementing it
in terms of `sys_errlist' but such a file will only need porting
exceptions (if at all) for systems that do not define a `strerror()'
themselves which should be a progressively diminishing minority.
Note that the ANSI-C standard (220.127.116.11) specifies `strerror()' as returning
`char *' NOT `const char *'. The constraint that the caller may
not modify the storage to which a pointer is returned is specified
in the text of the standard NOT in the interface to the function.
I really do not want to flog a dead horse but this reinforces my position
of the last time this one came round ...
If `sys_errlist' is declared (not defined) correctly in `errno.h'
(ie with `const') then it is impossible to use it correctly (ie without
somewhere casting away void) to implement an ANSI-C standard conforming
strerror(). Or did ANSI-C define strerror() incorrectly ? :-)
Alan Peakall, applications engineer Parsys Ltd
Email: email@example.com London W7 2QE, United Kingdom
Tel: +44 181 5798683 Fax: +44 181 5798365