utils: Add 'ar-file?'.
* guix/build/utils.scm (%ar-magic-bytes): New variable. (ar-file?): New procedure.
This commit is contained in:
parent
50b87bd54b
commit
91ee959b03
|
@ -37,6 +37,7 @@
|
||||||
executable-file?
|
executable-file?
|
||||||
call-with-ascii-input-file
|
call-with-ascii-input-file
|
||||||
elf-file?
|
elf-file?
|
||||||
|
ar-file?
|
||||||
with-directory-excursion
|
with-directory-excursion
|
||||||
mkdir-p
|
mkdir-p
|
||||||
copy-recursively
|
copy-recursively
|
||||||
|
@ -118,6 +119,21 @@ return values of applying PROC to the port."
|
||||||
(equal? (get-header)
|
(equal? (get-header)
|
||||||
#vu8(#x7f #x45 #x4c #x46))) ;"\177ELF"
|
#vu8(#x7f #x45 #x4c #x46))) ;"\177ELF"
|
||||||
|
|
||||||
|
(define %ar-magic-bytes
|
||||||
|
;; Magic bytes of archives created by 'ar'. See <ar.h>.
|
||||||
|
(u8-list->bytevector (map char->integer (string->list "!<arch>\n"))))
|
||||||
|
|
||||||
|
(define (ar-file? file)
|
||||||
|
"Return true if FILE starts with the magic bytes of archives as created by
|
||||||
|
'ar'."
|
||||||
|
(define (get-header)
|
||||||
|
(call-with-input-file file
|
||||||
|
(lambda (port)
|
||||||
|
(get-bytevector-n port 8))
|
||||||
|
#:binary #t #:guess-encoding #f))
|
||||||
|
|
||||||
|
(equal? (get-header) %ar-magic-bytes))
|
||||||
|
|
||||||
(define-syntax-rule (with-directory-excursion dir body ...)
|
(define-syntax-rule (with-directory-excursion dir body ...)
|
||||||
"Run BODY with DIR as the process's current directory."
|
"Run BODY with DIR as the process's current directory."
|
||||||
(let ((init (getcwd)))
|
(let ((init (getcwd)))
|
||||||
|
|
Loading…
Reference in New Issue