list-xattrs: Don’t throw exception on empty x-attr

This commit is contained in:
Jaidyn Ann 2024-05-13 22:10:39 -05:00
parent adaa561e59
commit 9e1947b0f7

View File

@ -19,8 +19,8 @@
(get-xattr set-xattr remove-xattr list-xattrs) (get-xattr set-xattr remove-xattr list-xattrs)
(import scheme (import scheme
(chicken base) (chicken foreign) (chicken memory) (chicken base) (chicken condition) (chicken foreign) (chicken memory)
srfi-1 srfi-12) srfi-1)
(foreign-declare "#include \"xattr_ext.c\"") (foreign-declare "#include \"xattr_ext.c\"")
@ -95,8 +95,6 @@
;; TODO: These exception functions should be constructed with a macro and a simple ;; 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.")) ;; 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 ;; 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) (define (pointer->delimited-string-list pointer length delimiter)
(let* ([is-zero (lambda (num) (eq? num 0))] (let* ([is-zero (lambda (num) (eq? num 0))]
[map-to-char (lambda (a) (map integer->char a))] [map-to-char (lambda (a) (map integer->char a))]
[byte-list (drop-right (pointer->integers pointer length) 1)]) [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 list->string
(map map-to-char (map map-to-char
(split-list is-zero byte-list))))) (split-list is-zero byte-list)))
'())))
;; Takes a pointer and returns a list of bytes of a given length ;; Takes a pointer and returns a list of bytes of a given length