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