199: POSIX errno manipulation

by Harold Ancell

Status

This SRFI is currently in withdrawn status. Here is an explanation of each status that a SRFI can hold. To provide input on this SRFI, please send email to srfi-199@nospamsrfi.schemers.org. To subscribe to the list, follow these instructions. You can access previous messages via the mailing list archive.

author's summary of reasons for withdrawal: As thoroughly discussed on the mailing list, a simple Scheme level API like the one proposed is unsatisfactory because a Scheme implementation can run arbitrary code that might set errno between any of 1) manually setting it, 2) a POSIX call possibly setting it, and 3) retrieving its value. This, along with EINTR loops (see the Worse is Better essay) need to be done at a low level, and no one has been able to come up with a suitable standard and universal high level API for any of this.

Abstract

The majority of POSIX system and library calls require accessing errno to discern the specific cause of an error, and some require setting it to 0 before being called. This SRFI specifies procedures to both retrieve its value, and to set it.

Rationale

The POSIX lvalue errno is implemented as "a macro or an identifier declared with external linkage". It does not fit into the paradigm of many autogenerating FFIs such as Chibi Scheme's, and for the latter must be hand coded. Its value is required when using SRFI 198 POSIX system call exceptions, which does not provide a procedure to get its value. This SRFI will allow many implementers of POSIX interfaces to focus on their particular system or library calls of interest without also providing these errno procedures or importing them from another more general library.

Specification

(errno)    →    exact integer       (procedure)

Returns the current value of errno.

 
(errno) ⇒ 2
(set-errno! errno)    →    undefined       (procedure)

Sets the current value of errno, where the argument errno is an exact integer.

 
(errno) ⇒ 2
(set-errno! 0)
(errno) ⇒ 0

Implementation

To be supplied for Chibi Scheme from its SRFI 170 sample implementation.

Acknowledgements

Thanks to Olin Shivers and John Cowan for SRFI 170, and to the latter for SRFI 198.

Copyright

Copyright © Harold Ancell (2020).

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Editor: Arthur A. Gleckler