r10811: fix warning for sbcl. remove setf getenv
[uffi.git] / src / os.lisp
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10; Package: UFFI -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          os.lisp
6 ;;;; Purpose:       Operating system interface for UFFI
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Sep 2002 
9 ;;;;
10 ;;;; $Id$
11 ;;;;
12 ;;;; This file, part of UFFI, is Copyright (c) 2002-2005 by Kevin M. Rosenberg.
13 ;;;;
14 ;;;; *************************************************************************
15
16 (in-package #:uffi)
17
18
19 (defun getenv (var)
20   "Return the value of the environment variable."
21   #+allegro (sys::getenv (string var))
22   #+clisp (sys::getenv (string var))
23   #+cmu (cdr (assoc (string var) ext:*environment-list* :test #'equalp
24                     :key #'string))
25   #+gcl (si:getenv (string var))
26   #+lispworks (lw:environment-variable (string var))
27   #+lucid (lcl:environment-variable (string var))
28   #+mcl (ccl::getenv var)
29   #+sbcl (sb-ext:posix-getenv var)
30   #-(or allegro clisp cmu gcl lispworks lucid mcl sbcl)
31   (error 'not-implemented :proc (list 'getenv var)))
32
33
34 ;; modified from function ASDF -- Copyright Dan Barlow and Contributors
35
36 (defun run-shell-command (control-string  &rest args &key output)
37   "Interpolate ARGS into CONTROL-STRING as if by FORMAT, and
38 synchronously execute the result using a Bourne-compatible shell, with
39 output to *trace-output*.  Returns the shell's exit code."
40   (unless output
41     (setq output *trace-output*))
42
43   (let ((command (apply #'format nil control-string args)))
44     #+sbcl
45     (sb-impl::process-exit-code
46      (sb-ext:run-program  
47       "/bin/sh"
48       (list "-c" command)
49       :input nil :output output))
50     
51     #+(or cmu scl)
52     (ext:process-exit-code
53      (ext:run-program  
54       "/bin/sh"
55       (list "-c" command)
56       :input nil :output output))
57
58     #+allegro
59     (excl:run-shell-command command :input nil :output output)
60     
61     #+lispworks
62     (system:call-system-showing-output
63      command
64      :shell-type "/bin/sh"
65      :output-stream output)
66     
67     #+clisp                             ;XXX not exactly *trace-output*, I know
68     (ext:run-shell-command  command :output :terminal :wait t)
69
70     #+openmcl
71     (nth-value 1
72                (ccl:external-process-status
73                 (ccl:run-program "/bin/sh" (list "-c" command)
74                                  :input nil :output output
75                                  :wait t)))
76
77     #-(or openmcl clisp lispworks allegro scl cmu sbcl)
78     (error "RUN-SHELL-PROGRAM not implemented for this Lisp")
79     ))