From 9e1947b0f728c1d2e2db1d6de862a9c2231d1481 Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Mon, 13 May 2024 22:10:39 -0500 Subject: [PATCH] =?UTF-8?q?list-xattrs:=20Don=E2=80=99t=20throw=20exceptio?= =?UTF-8?q?n=20on=20empty=20x-attr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xattr.scm | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/xattr.scm b/xattr.scm index bd3a143..778627a 100644 --- a/xattr.scm +++ b/xattr.scm @@ -19,8 +19,8 @@ (get-xattr set-xattr remove-xattr list-xattrs) (import scheme - (chicken base) (chicken foreign) (chicken memory) - srfi-1 srfi-12) + (chicken base) (chicken condition) (chicken foreign) (chicken memory) + srfi-1) (foreign-declare "#include \"xattr_ext.c\"") @@ -95,8 +95,6 @@ ;; TODO: These exception functions should be constructed with a macro and a simple ;; list, like `((c-constant symbol error-message) ("E2BIG" 'e2big "The attribute value was too big.")) - ;; Unfortunately, it looks like chicken's macros work a good bit differently from CLs? - ;; orr I'm losing my mind ;; Return the exception associated with an error-code as per getxattr(2), if it exists @@ -165,10 +163,15 @@ (define (pointer->delimited-string-list pointer length delimiter) (let* ([is-zero (lambda (num) (eq? num 0))] [map-to-char (lambda (a) (map integer->char a))] - [byte-list (drop-right (pointer->integers pointer length) 1)]) - (map list->string - (map map-to-char - (split-list is-zero byte-list))))) + [pointer-ints (pointer->integers pointer length)] + [byte-list (when (list? pointer-ints) + (drop-right pointer-ints 1))]) + (if (and (list? byte-list) + (not (null-list? byte-list))) + (map list->string + (map map-to-char + (split-list is-zero byte-list))) + '()))) ;; Takes a pointer and returns a list of bytes of a given length