Revised method for re-reading the executable as data.
[rrq/newlisp/packnl.git] / incore.lsp
index 7203047c0be43aefb1b97d0fc694df61b2878ccf..658972a367292a3334169cc30d98507e80a189f8 100644 (file)
 ;; This is a hashmap of loaded files
 (new Tree 'archives)
 
-;; A copy of the executable
-(define core:core (read-file "/proc/self/exe"))
+;; A copy of the executable (file descriptor 3)
+(define core:core
+  (letn ((FD 3) (SZ (seek FD)) (BUFFER (dup "" SZ)))
+    (seek FD 0) (read FD BUFFER SZ) BUFFER))
+(map delete '(FD SZ BUFFER GNU GNU))
 
 (context 'archive)
-
 (setf main nil)
-
-(constant 'AR "/usr/bin/ar" 'TAR "/bin/tar" 'FILE "/usr/bin/file")
+(constant
+ 'AR "/usr/bin/ar"
+ 'TAR (exists file? '("/bin/tar" "/usr/bin/tar"))
+ 'FILE "/usr/bin/file" )
 
 (define (tar-able PATH)
   (when (file? FILE)