summaryrefslogtreecommitdiff
path: root/guix/build/utils.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2014-11-22 21:44:59 +0100
committerLudovic Courtès <ludo@gnu.org>2014-11-22 21:52:12 +0100
commit91ee959b03e9e45727761823a4fcc1046e0aa450 (patch)
treeb37db50a259a85a7f7650a5e153088a25a2e6b53 /guix/build/utils.scm
parent50b87bd54b7fd5fe5cb3482d7801d5e74d0c2fb3 (diff)
downloadguix-patches-91ee959b03e9e45727761823a4fcc1046e0aa450.tar
guix-patches-91ee959b03e9e45727761823a4fcc1046e0aa450.tar.gz
utils: Add 'ar-file?'.
* guix/build/utils.scm (%ar-magic-bytes): New variable. (ar-file?): New procedure.
Diffstat (limited to 'guix/build/utils.scm')
-rw-r--r--guix/build/utils.scm16
1 files changed, 16 insertions, 0 deletions
diff --git a/guix/build/utils.scm b/guix/build/utils.scm
index fcf6dfc12c..0ea22ec657 100644
--- a/guix/build/utils.scm
+++ b/guix/build/utils.scm
@@ -37,6 +37,7 @@
executable-file?
call-with-ascii-input-file
elf-file?
+ ar-file?
with-directory-excursion
mkdir-p
copy-recursively
@@ -118,6 +119,21 @@ return values of applying PROC to the port."
(equal? (get-header)
#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 ...)
"Run BODY with DIR as the process's current directory."
(let ((init (getcwd)))