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.lisp,v 1.4 2003/08/13 18:53:42 kevin Exp $
12 ;;;; This file, part of UFFI, is Copyright (c) 2002-2003 by Kevin M. Rosenberg
14 ;;;; *************************************************************************
16 (in-package #:uffi-tests)
19 (uffi:def-function ("getenv" c-getenv)
23 (uffi:def-function ("setenv" c-setenv)
29 (uffi:def-function ("unsetenv" c-unsetenv)
33 (defun my-getenv (key)
34 "Returns an environment variable, or NIL if it does not exist"
35 (check-type key string)
36 (uffi:with-cstring (key-native key)
37 (uffi:convert-from-cstring (c-getenv key-native))))
39 (defun my-setenv (key name &optional (overwrite t))
40 "Returns an environment variable, or NIL if it does not exist"
41 (check-type key string)
42 (check-type name string)
43 (setq overwrite (if overwrite 1 0))
44 (uffi:with-cstrings ((key-native key)
46 (c-setenv key-native name-native (if overwrite 1 0))))
48 (defun my-unsetenv (key)
49 "Returns an environment variable, or NIL if it does not exist"
50 (check-type key string)
51 (uffi:with-cstrings ((key-native key))
52 (c-unsetenv key-native)))
54 (deftest getenv.1 (progn
55 (my-unsetenv "__UFFI_FOO1__")
56 (my-getenv "__UFFI_FOO1__"))
58 (deftest getenv.2 (progn
59 (my-setenv "__UFFI_FOO1__" "UFFI-TEST")
60 (my-getenv "__UFFI_FOO1__"))