1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
6 ;;;; Purpose: UFFI Example file to get environment variable
7 ;;;; Programmer: Kevin M. Rosenberg
8 ;;;; Date Started: Feb 2002
10 ;;;; $Id: getenv.cl,v 1.9 2002/04/02 23:27:05 kevin Exp $
12 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
14 ;;;; UFFI users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;; *************************************************************************
22 (uffi:def-function ("getenv" c-getenv)
26 (defun my-getenv (key)
27 "Returns an environment variable, or NIL if it does not exist"
28 (check-type key string)
29 (uffi:with-cstring (key-native key)
30 (uffi:convert-from-cstring (c-getenv key-native))))
34 (flet ((print-results (str)
35 (format t "~&(getenv ~S) => ~S" str (my-getenv str))))
36 (print-results "USER")
37 (print-results "_FOO_")))
42 (util.test:test (my-getenv "_FOO_") nil :fail-info "Error retrieving non-existent getenv")
43 (util.test:test (and (stringp (my-getenv "USER"))
44 (< 0 (length (my-getenv "USER"))))
45 t :fail-info "Error retrieving getenv")