From 75b2e35c4b81a1a2b549f9a614c752211310aa07 Mon Sep 17 00:00:00 2001 From: Nicolas Martyanoff Date: Tue, 21 Feb 2023 16:46:30 +0100 Subject: [PATCH] store errno in SIMPLE-FILE-ERROR conditions CCL signals SIMPLE-FILE-ERROR conditions for all file-related errors, but they do not contain any information to programmatically distinguish what the error actually is. The most basic use case is the ability to detect that opening a file failed because it does not exist. Without this patch, it is impossible to make the difference between a file-not-found error and for example an IO error. --- level-1/l1-error-signal.lisp | 5 +++-- level-1/l1-error-system.lisp | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/level-1/l1-error-signal.lisp b/level-1/l1-error-signal.lisp index 18b2cd78d..8b0705aa7 100644 --- a/level-1/l1-error-signal.lisp +++ b/level-1/l1-error-signal.lisp @@ -45,7 +45,7 @@ (format-string (if errargs (format nil "~a : ~a" error-string "~s") error-string))) - (%err-disp-common nil err-type format-string errargs frame-ptr))) + (%err-disp-common errno err-type format-string errargs frame-ptr))) (defun %err-disp-internal (err-num errargs frame-ptr) @@ -87,7 +87,8 @@ (simple-file-error (make-condition condition-name :pathname (car errargs) :error-type format-string - :format-arguments (cdr errargs))) + :format-arguments (cdr errargs) + :errno err-num)) (undefined-function (make-condition condition-name :name (car errargs))) (call-special-operator-or-macro diff --git a/level-1/l1-error-system.lisp b/level-1/l1-error-system.lisp index e1aad9cc1..796188a09 100644 --- a/level-1/l1-error-system.lisp +++ b/level-1/l1-error-system.lisp @@ -580,7 +580,11 @@ (file-error-pathname c))))) (define-condition simple-file-error (simple-condition file-error) - () + ((errno + :type (or integer null) + :initarg :errno + :initform nil + :reader simple-file-error-errno)) (:report (lambda (c s) (apply #'format s (slot-value c 'error-type) (file-error-pathname c)