From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.perfora.net (mout.perfora.net [74.208.4.196]) by sourceware.org (Postfix) with ESMTPS id 019BC385ED4D for ; Fri, 16 Oct 2020 19:06:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 019BC385ED4D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=Damon-Family.org Authentication-Results: sourceware.org; spf=none smtp.mailfrom=Richard@Damon-Family.org Received: from [192.168.77.189] ([108.20.19.251]) by mrelay.perfora.net (mreueus002 [74.208.5.2]) with ESMTPA (Nemesis) id 0MSLPR-1krrHU17xD-00TTmF for ; Fri, 16 Oct 2020 21:06:43 +0200 Subject: Re: When/how is global "errno" variable from reent.c to be used? To: newlib@sourceware.org References: From: Richard Damon Message-ID: <766f7b8d-6e68-9c33-a3bc-c7bbd868d0f3@Damon-Family.org> Date: Fri, 16 Oct 2020 15:06:42 -0400 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:78.0) Gecko/20100101 Thunderbird/78.3.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Content-Language: en-US X-Provags-ID: V03:K1:bNVqzSS+fj9Pp1KHXTCahG995xA+CKF3Yj7Xxhx/wzBOYRYmcks KGdMbu5Ebyv/6Xm7qsk7rm3QERE6TYF1hkAYxaj2ZWZi0PsAbly4U5vmIpYt8NPHAgeEdW+ 7xruKP0ihmbS3Uynb0s66Igbn9Lidwl3lZDhzmMdEBzDoQV7qTvGi8qTFNxnYZXfOU5VkH1 8UalqWdpiuC90LoyastQg== X-UI-Out-Filterresults: notjunk:1;V03:K0:4JtiQQWdYhU=:YINng6YwZmViMgAy4kdORT YDGc36zxakwySPCqEWO0VSAsChXfHFDVtjZugycg5a76XEE7ZWiyHEwrvXM0cqacsDSwnjzNj z11151QdIb0/yIgcazgSqLFGEsiRizpwmFEoi1CWa0/B1kCPHlXcWJoy0I2j/oGdRF5S8lg2Q VlK7UJM5pbXp52UC3gArHHpaQHUmW1I882+7Aa+nOKnuqRp41dTK9IfQmza1euI+A/04IOnRK 7jpvkBRkeKvXg6AzA6oitF6nWhrBQXrVHfwjAeFMzUpYV6y/gtxzTceIctRqFSmQJrtIyGvVJ qkJ7Zz0khJzhU3nROFq3Uj3IoQsHm0LwpY/CW/zGPPt2G8Bzdxx/LQKbr6G9GzIN3EAivawv9 n2IrptcOQ3E2JLsdcwi56euycvtntzT7RChAdLGTPNqADICh2LYRPIE2/ldyhGGB7osqLBr6I weIzsK0QBQ== X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Oct 2020 19:06:45 -0000 On 10/16/20 2:10 PM, Grant Edwards via Newlib wrote: > On 2020-10-16, Richard Damon 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