syscalls: Extract 'bytes->string'.
* guix/build/syscalls.scm (bytes->string): New procedure. (bytevector->string-list): Use it.
This commit is contained in:
parent
0691c9c05d
commit
57f068bec5
|
@ -900,6 +900,15 @@ bytevector BV at INDEX."
|
||||||
;; The most terrible interface, live from Scheme.
|
;; The most terrible interface, live from Scheme.
|
||||||
(syscall->procedure int "ioctl" (list int unsigned-long '*)))
|
(syscall->procedure int "ioctl" (list int unsigned-long '*)))
|
||||||
|
|
||||||
|
(define (bytes->string bytes)
|
||||||
|
"Read BYTES, a list of bytes, and return the null-terminated string decoded
|
||||||
|
from there, or #f if that would be an empty string."
|
||||||
|
(match (take-while (negate zero?) bytes)
|
||||||
|
(()
|
||||||
|
#f)
|
||||||
|
(non-zero
|
||||||
|
(list->string (map integer->char non-zero)))))
|
||||||
|
|
||||||
(define (bytevector->string-list bv stride len)
|
(define (bytevector->string-list bv stride len)
|
||||||
"Return the null-terminated strings found in BV every STRIDE bytes. Read at
|
"Return the null-terminated strings found in BV every STRIDE bytes. Read at
|
||||||
most LEN bytes from BV."
|
most LEN bytes from BV."
|
||||||
|
@ -911,9 +920,7 @@ most LEN bytes from BV."
|
||||||
(reverse result))
|
(reverse result))
|
||||||
(_
|
(_
|
||||||
(loop (drop bytes stride)
|
(loop (drop bytes stride)
|
||||||
(cons (list->string (map integer->char
|
(cons (bytes->string bytes) result))))))
|
||||||
(take-while (negate zero?) bytes)))
|
|
||||||
result))))))
|
|
||||||
|
|
||||||
(define* (network-interface-names #:optional sock)
|
(define* (network-interface-names #:optional sock)
|
||||||
"Return the names of existing network interfaces. This is typically limited
|
"Return the names of existing network interfaces. This is typically limited
|
||||||
|
|
Loading…
Reference in New Issue