Formatting, tweaking indentation
… my Emacs previously used tabs+spaces for Scheme, which is genuinely horrific. >o<
This commit is contained in:
parent
1b5e9d5b1f
commit
adaa561e59
78
xattr.scm
78
xattr.scm
|
@ -23,16 +23,16 @@
|
||||||
srfi-1 srfi-12)
|
srfi-1 srfi-12)
|
||||||
|
|
||||||
|
|
||||||
(foreign-declare "#include \"xattr_ext.c\"")
|
(foreign-declare "#include \"xattr_ext.c\"")
|
||||||
|
|
||||||
|
|
||||||
;; The direct foreign binding for `get_xattr`
|
;; The direct foreign binding for `get_xattr`
|
||||||
(define get-xattr-foreign
|
(define get-xattr-foreign
|
||||||
(foreign-lambda c-string* "get_xattr" c-string c-string (c-pointer int)))
|
(foreign-lambda c-string* "get_xattr" c-string c-string (c-pointer int)))
|
||||||
|
|
||||||
|
|
||||||
;; Wrapper around get-xattr-foreign, which throws exceptions and such.
|
;; Wrapper around get-xattr-foreign, which throws exceptions and such.
|
||||||
(define (get-xattr path attr)
|
(define (get-xattr path attr)
|
||||||
(let-location ([error-code int])
|
(let-location ([error-code int])
|
||||||
(let ([attr-value (get-xattr-foreign path attr (location error-code))]
|
(let ([attr-value (get-xattr-foreign path attr (location error-code))]
|
||||||
[exception (or (getxattr-exception error-code)
|
[exception (or (getxattr-exception error-code)
|
||||||
|
@ -42,13 +42,13 @@
|
||||||
attr-value))))
|
attr-value))))
|
||||||
|
|
||||||
|
|
||||||
;; The direct foreign binding for `list_xattr`
|
;; The direct foreign binding for `list_xattr`
|
||||||
(define list-xattrs-foreign
|
(define list-xattrs-foreign
|
||||||
(foreign-lambda (c-pointer char) "list_xattr" c-string (c-pointer ssize_t) (c-pointer int)))
|
(foreign-lambda (c-pointer char) "list_xattr" c-string (c-pointer ssize_t) (c-pointer int)))
|
||||||
|
|
||||||
|
|
||||||
;; Wrapper around list-xattrs-foreign, which throws exceptions and such.
|
;; Wrapper around list-xattrs-foreign, which throws exceptions and such.
|
||||||
(define (list-xattrs path)
|
(define (list-xattrs path)
|
||||||
(let-location ([error-code int]
|
(let-location ([error-code int]
|
||||||
[length ssize_t])
|
[length ssize_t])
|
||||||
(let ([list-pointer (list-xattrs-foreign path (location length) (location error-code))]
|
(let ([list-pointer (list-xattrs-foreign path (location length) (location error-code))]
|
||||||
|
@ -60,13 +60,13 @@
|
||||||
(pointer->delimited-string-list list-pointer length 0)))))
|
(pointer->delimited-string-list list-pointer length 0)))))
|
||||||
|
|
||||||
|
|
||||||
;; The direct foreign binding for `set_xattr`
|
;; The direct foreign binding for `set_xattr`
|
||||||
(define set-xattr-foreign
|
(define set-xattr-foreign
|
||||||
(foreign-lambda int "set_xattr" c-string c-string c-string (c-pointer int)))
|
(foreign-lambda int "set_xattr" c-string c-string c-string (c-pointer int)))
|
||||||
|
|
||||||
|
|
||||||
;; Wrapper around set-xattr-foreign, throwing exceptions and all that jazz
|
;; Wrapper around set-xattr-foreign, throwing exceptions and all that jazz
|
||||||
(define (set-xattr path attr value)
|
(define (set-xattr path attr value)
|
||||||
(let-location ([error-code int])
|
(let-location ([error-code int])
|
||||||
(let ([return-code (set-xattr-foreign path attr value (location error-code))]
|
(let ([return-code (set-xattr-foreign path attr value (location error-code))]
|
||||||
[exception (or (setxattr-exception error-code)
|
[exception (or (setxattr-exception error-code)
|
||||||
|
@ -77,13 +77,13 @@
|
||||||
value))))
|
value))))
|
||||||
|
|
||||||
|
|
||||||
;; The direct foreign binding for `remove_xattr`
|
;; The direct foreign binding for `remove_xattr`
|
||||||
(define remove-xattr-foreign
|
(define remove-xattr-foreign
|
||||||
(foreign-lambda int "remove_xattr" c-string c-string))
|
(foreign-lambda int "remove_xattr" c-string c-string))
|
||||||
|
|
||||||
|
|
||||||
;; Wrapper around remove-xattr-foreign, blah blah
|
;; Wrapper around remove-xattr-foreign, blah blah
|
||||||
(define (remove-xattr path attr)
|
(define (remove-xattr path attr)
|
||||||
(let* ([value (get-xattr path attr)]
|
(let* ([value (get-xattr path attr)]
|
||||||
[error-code (remove-xattr-foreign path attr)]
|
[error-code (remove-xattr-foreign path attr)]
|
||||||
[exception (or (getxattr-exception error-code)
|
[exception (or (getxattr-exception error-code)
|
||||||
|
@ -93,14 +93,14 @@
|
||||||
value)))
|
value)))
|
||||||
|
|
||||||
|
|
||||||
;; 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?
|
;; Unfortunately, it looks like chicken's macros work a good bit differently from CLs?
|
||||||
;; orr I'm losing my mind
|
;; 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
|
||||||
(define (getxattr-exception error-code)
|
(define (getxattr-exception error-code)
|
||||||
(cond
|
(cond
|
||||||
[(eq? error-code (foreign-value "E2BIG" int))
|
[(eq? error-code (foreign-value "E2BIG" int))
|
||||||
(build-exception 'e2big "The attribute value was too big.")]
|
(build-exception 'e2big "The attribute value was too big.")]
|
||||||
|
@ -112,8 +112,8 @@
|
||||||
#f]))
|
#f]))
|
||||||
|
|
||||||
|
|
||||||
;; Return the exception associated with a setxattr(2) error-code, if it exists.
|
;; Return the exception associated with a setxattr(2) error-code, if it exists.
|
||||||
(define (setxattr-exception error-code)
|
(define (setxattr-exception error-code)
|
||||||
(cond
|
(cond
|
||||||
[(eq? error-code (foreign-value "EDQUOT" int))
|
[(eq? error-code (foreign-value "EDQUOT" int))
|
||||||
(build-exception 'edquot "Setting this attribute would violate disk quota.")]
|
(build-exception 'edquot "Setting this attribute would violate disk quota.")]
|
||||||
|
@ -127,8 +127,8 @@
|
||||||
#f]))
|
#f]))
|
||||||
|
|
||||||
|
|
||||||
;; Return the exception associated with an error-code as per stat(2), if applicable
|
;; Return the exception associated with an error-code as per stat(2), if applicable
|
||||||
(define (stat-exception error-code)
|
(define (stat-exception error-code)
|
||||||
(cond
|
(cond
|
||||||
[(eq? error-code (foreign-value "EACCES" int))
|
[(eq? error-code (foreign-value "EACCES" int))
|
||||||
(build-exception 'file "Search permission denied for a parent directory.")]
|
(build-exception 'file "Search permission denied for a parent directory.")]
|
||||||
|
@ -154,15 +154,15 @@
|
||||||
#f]))
|
#f]))
|
||||||
|
|
||||||
|
|
||||||
;; Creates a generic exception with given symbol and message
|
;; Creates a generic exception with given symbol and message
|
||||||
(define (build-exception symbol message)
|
(define (build-exception symbol message)
|
||||||
(signal (make-property-condition 'exn 'location symbol 'message message)))
|
(signal (make-property-condition 'exn 'location symbol 'message message)))
|
||||||
|
|
||||||
|
|
||||||
;; Some C functions offer up a string-list that isn't a two-dimensional array, but a
|
;; Some C functions offer up a string-list that isn't a two-dimensional array, but a
|
||||||
;; one-dimensional array with given length and strings separated by a given delimeter.
|
;; one-dimensional array with given length and strings separated by a given delimeter.
|
||||||
;; This takes that sort of pointer and gives you a nice list of strings.
|
;; This takes that sort of pointer and gives you a nice list of strings.
|
||||||
(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)])
|
[byte-list (drop-right (pointer->integers pointer length) 1)])
|
||||||
|
@ -171,8 +171,8 @@
|
||||||
(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
|
||||||
(define (pointer->integers pointer length)
|
(define (pointer->integers pointer length)
|
||||||
(let ([byte (pointer-s8-ref pointer)])
|
(let ([byte (pointer-s8-ref pointer)])
|
||||||
(if (eq? length 0)
|
(if (eq? length 0)
|
||||||
byte
|
byte
|
||||||
|
@ -180,8 +180,8 @@
|
||||||
(pointer->integers (pointer+ pointer 1) (- length 1))))))
|
(pointer->integers (pointer+ pointer 1) (- length 1))))))
|
||||||
|
|
||||||
|
|
||||||
;; Split a list into sublists, with items passing `test` being the delimiters
|
;; Split a list into sublists, with items passing `test` being the delimiters
|
||||||
(define (split-list test list)
|
(define (split-list test list)
|
||||||
(let ([before (take-while (compose not test) list)]
|
(let ([before (take-while (compose not test) list)]
|
||||||
[after (drop-while (compose not test) list)])
|
[after (drop-while (compose not test) list)])
|
||||||
(cond
|
(cond
|
||||||
|
@ -190,6 +190,4 @@
|
||||||
[(null-list? before)
|
[(null-list? before)
|
||||||
(split-list test (cdr after))]
|
(split-list test (cdr after))]
|
||||||
[#t
|
[#t
|
||||||
(append `(,before) (split-list test (cdr after)))])))
|
(append `(,before) (split-list test (cdr after)))]))))
|
||||||
|
|
||||||
)
|
|
||||||
|
|
Ŝarĝante…
Reference in New Issue