Subject: [clisp-list] execl, et al.

From: Pascal Bourguignon <[email-masked]>
Date: Tue Dec 10 02:09:02 2002

Hello,

Those who  have tried to use  the package LINUX may  have noticed that
execl,  execle,  and  other  functions  taking a  variable  number  of
arguments  are  missing,  because  the  FFI package  does  not  handle
variable number  of arguments.   Well, I did  not want to  dive deeply
into FFI,  so here is  a little macro  defining on the fly  the needed
execl# foreign functions.

One defect of  this macro is that it polutes  the current package with
execl# symbols, but  since the LINUX package is  locked... (Is there a
mean  to  unlock a  package?)   Perhaps  it  should define  a  package
"LINUX-DYN-FUN".  

(defmacro execl (path &rest argv)
  (let* ((argc (1- (length argv)))
         (exec (intern (format nil "EXECL~D" argc))))
    (if (fboundp exec)
        `(,exec ,path ,@argv nil)
      `(progn
         (ffi:def-call-out
          ,exec
          (:language :stdc)
          (:arguments
           (path ffi:c-string)
           ,@(do ((i 0 (1+ i))
                  (arguments nil (cons (list (intern (format nil "ARGV~D" i))
                                             'ffi:c-string) arguments)) )
                 ((< argc i) (nreverse arguments)))
           (null ffi:c-string))
          (:return-type ffi:int)
          (:name "execl"))
         (,exec ,path ,@argv nil)))))

-- 
__Pascal_Bourguignon__                   http://www.informatimago.com/
----------------------------------------------------------------------
There is a fault in reality. do not adjust your minds. -- Salman Rushdie