mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-07 04:30:18 +02:00
(Conventions): Use `system-error-errno' instead of explicit code
This commit is contained in:
parent
019ac1c987
commit
daabbf15d7
1 changed files with 5 additions and 11 deletions
|
@ -68,15 +68,12 @@ the documentation.
|
||||||
|
|
||||||
For ways to deal with exceptions, @ref{Exceptions}.
|
For ways to deal with exceptions, @ref{Exceptions}.
|
||||||
|
|
||||||
Errors which the C-library would report by returning a NULL
|
Errors which the C-library would report by returning a NULL pointer or
|
||||||
pointer or through some other means are reported by raising a
|
through some other means are reported by raising a @code{system-error}
|
||||||
@code{system-error} exception.
|
exception. The value of the Unix @code{errno} variable is available
|
||||||
The value of the Unix @code{errno} variable is available
|
|
||||||
in the data passed by the exception.
|
in the data passed by the exception.
|
||||||
|
|
||||||
Here's an ad-hoc@footnote{This may be changed in the future; be prepared
|
It can be extracted with the function @code{system-error-errno}:
|
||||||
to rewrite this sort of code.} way to extract the @code{errno} value
|
|
||||||
from an exception:
|
|
||||||
|
|
||||||
@example
|
@example
|
||||||
(catch
|
(catch
|
||||||
|
@ -84,7 +81,7 @@ from an exception:
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(mkdir "/this-ought-to-fail-if-I'm-not-root"))
|
(mkdir "/this-ought-to-fail-if-I'm-not-root"))
|
||||||
(lambda stuff
|
(lambda stuff
|
||||||
(let ((errno (car (list-ref stuff 4))))
|
(let ((errno (system-error-errno 4)))
|
||||||
(cond
|
(cond
|
||||||
((= errno EACCES)
|
((= errno EACCES)
|
||||||
(display "You're not allowed to do that."))
|
(display "You're not allowed to do that."))
|
||||||
|
@ -95,9 +92,6 @@ from an exception:
|
||||||
(newline))))
|
(newline))))
|
||||||
@end example
|
@end example
|
||||||
|
|
||||||
The important thing to note is that the @code{errno} value can be
|
|
||||||
extracted with @code{(car (list-ref stuff 4))}.
|
|
||||||
|
|
||||||
@node Ports and File Descriptors
|
@node Ports and File Descriptors
|
||||||
@section Ports and File Descriptors
|
@section Ports and File Descriptors
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue