Subject: Re: `sys_errlist' in `stdio.h'
To: None <email@example.com, current-users@NetBSD.ORG>
From: Henry G. Juengst, ISKP, Bonn <firstname.lastname@example.org>
Date: 01/17/1996 12:19:30
> >>Moving the declaration to <errno.h> would address the original problem,
> >>as ``old'' code should no more know about that header than about `const'.
> >Pardon? What old code doesn't know about errno.h? I believe that
> >file has been in use since V7 latest.
> You are quite correct, I regret that I was suffering the mental aberration
> of confusing the absence of a declaration for `errno' in `errno.h' with the
> absence of `errno.h' itself !
email@example.com - it's not an UK internet address...
> > The interface (the header file and its declarations) is the only tool
> > which is available for the compiler to check the correct usage of a
> > specific implementation by the programmer of an application.
> So far the only (non-obsolete) application cited for `sys_errlist' has been
> the implementation of `strerror()' - I see this as an aspect of the
> implementation internals of the library.
The implementation of sys_errlist is src/lib/libc/gen/errlist.c. Strerror()
and some applications (any user program) are using it. In fact some other
NetBSD sources also use it. Internal or not is irrelevant. It should be
just _correct_. It is not correct if you remove the 'const's.
If you have an old designed compiler you can use 'cc -Dconst='. But,
this is not what we want in the year 1996.
> > It might be possible to use a private declaration, but this is not a
> > real solution. You should never use a private declaration of a system
> > (OS) identifier, because its implementation could be different for
> > each system (look at lseek, offset is sometimes int or long).
> Can anyone cite an implementation of `sys_errlist' that is not
> functionally `const char *const '. The constancy of the
> character strings and pointers has always been implicit even when
> the compiler could not understand a declarative statement of the fact.
> Further, since `sys_errlist' has now been obsoleted by `strerror()',
> no one should be reimplementing it.
It is not just the implementation of 'sys_errlist', but _any_ global
identifier should be declared correctly (another example: errno;-). Your
compiler can not see the functionality without the declaration in the
header file. Now, with the NetBSD declarations (here especially of
sys_errlist) we have a chance to see any invalid access via any pointer
and propagated pointer referencing sys_errlist during the compilation phase.
> On SunOS4.1.3 and (presumably) all its BSD ancestors `sys_errlist' is
> not declared in any header file and so, undesirable as it may be, it
> must always have been declared in `*.c' source files where it was
> referenced. Such declarations would have been unlikely to have used
> `const', as there was then no compiler support and as `perror(3)' does
> not specify it. By exporting a stricter declaration from a commonly
> used header file (`stdio.h' or `errno.h') NetBSD is demanding a porting
SunOS4.1.3 is irrelevant. It will be assimilated. Oops, the wrong film. :-)
Don't put the missing declarations into the '.c' files, but into a
header file which should be specific for a specific OS. Include it
via '#ifdef xxxos' (please, not via '#ifndef goodos' - I have seen
that too often;-).
> I know no good reason for new _application_ code to use `sys_errlist',
> so it seems to me that the question is a pragmatic one of whether having
> a more strictly typed declaration of `sys_errlist' really finds bugs
> in old application code being ported to NetBSD to compensate for
> the nuisance of the near certainty of requiring a porting exception
> for code whose historic insecure usage (``a private declaration of
> a system (OS) identifier'') was correct. NetBSD seems to have
> gone almost all the way towards becoming independent of `sys_errlist'
> for its own utilities, which seems an argument for giving way to
> the requirements of external source.
Old code gives you your money, new code is what you are dreaming of.
And again, 'sys_errlist' without 'const's is not correct. Believe me
or not, you will find many bugs in old programs with better declarations.
> Is `sys_errlist' is publicly declared for any reason but backward
> compatibility ?
> If the answer to the previous question is `NO', then should it not
> BE compatible ?
No, yes (my opinion).