*** swank-sbcl.lisp.~1.273.~	2010-08-14 20:29:25.000000000 +0400
--- swank-sbcl.lisp	2010-08-19 20:26:59.000000000 +0400
***************
*** 161,166 ****
--- 161,172 ----
      (sb-bsd-sockets:socket (sb-bsd-sockets:socket-file-descriptor socket))
      (file-stream (sb-sys:fd-stream-fd socket))))
  
+ (defimplementation command-line-args ()
+   sb-ext:*posix-argv*)
+ 
+ (defimplementation dup (fd)
+   (sb-posix:dup fd))
+ 
  (defvar *wait-for-input-called*)
  
  (defimplementation wait-for-input (streams &optional timeout)
***************
*** 1559,1561 ****
--- 1565,1600 ----
               (assert (= pid rpid))
               (assert (and (sb-posix:wifexited status)
                            (zerop (sb-posix:wexitstatus status)))))))))
+ 
+ #+unix
+ (progn
+   (sb-alien:define-alien-routine ("execve" sys-execve) sb-alien:int 
+     (program sb-alien:c-string)
+     (argv (* sb-alien:c-string))
+     (envp (* sb-alien:c-string)))
+   (defun execve (program args environment)
+     "Replace current executable with another one."
+     (let ((a-args (sb-alien:make-alien sb-alien:c-string
+                                        (1+ (length args))))
+           (a-environment (sb-alien:make-alien sb-alien:c-string
+                                               (1+ (length environment)))))
+       (loop for index from 0 by 1
+             and item in args
+             do (setf (sb-alien:deref a-args index) item))
+ 
+       (loop for index from 0 by 1
+             and item in environment
+             do (setf (sb-alien:deref a-environment index) item))
+       (sys-execve program a-args a-environment)))
+   (defimplementation exec-image (image-file args)
+     (execve (first sb-ext:*posix-argv*)
+             `(,(first sb-ext:*posix-argv*)
+                "--core" ,image-file
+                ,@args)
+             (sb-ext:posix-environ))))
+ 
+ (defimplementation make-fd-stream (fd external-format)
+   (sb-sys:make-fd-stream fd :input t :output t
+                          :element-type 'character
+                          :buffering :none
+                          :external-format external-format))
