When/how is global "errno" variable from reent.c to be used?

Richard Damon Richard@Damon-Family.org
Fri Oct 16 19:06:42 GMT 2020


On 10/16/20 2:10 PM, Grant Edwards via Newlib wrote:
> On 2020-10-16, Richard Damon <Richard@Damon-Family.org> wrote:
>
>> Software the explicitly declares errno as
>> extern int errno;
>> is broken, and violates the C standard, and creates explicitly stated
>> Undefined Behavior.
> So the LWIP source is just plain wrong.
>
> What is the global 'int errno' exported by reent.c for?
>
> --
> Grant
>
>
First, newlib considers itself as part of 'the implementation', as its
purpose is to provide the 'standard library' for an implementation, thus
it can do what it wants here (as long as the net result meets the
specifications).

I would have to dig into the actual implementation details to tell for
sure, but first check if when the statement int errno; is compiled, is
errno currently a macro, and after replacing that macro with its
definition what the statement actually defines, it might be creating the
pointer that is used to access the effective errno.

It could also be creating a global variable just to limit the breakage
that programs that do it wrong incur (though, I might prefer getting the
link error errno not defined rather than code that ends up checking the
wrong errno).

-- 
Richard Damon



More information about the Newlib mailing list