r1555: *** empty log message ***
[uffi.git] / examples / getenv.cl
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          getenv.cl
6 ;;;; Purpose:       UFFI Example file to get environment variable
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Feb 2002
9 ;;;;
10 ;;;; $Id: getenv.cl,v 1.7 2002/03/14 21:03:12 kevin Exp $
11 ;;;;
12 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
13 ;;;;
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 ;;;; *************************************************************************
18
19 (in-package :cl-user)
20
21
22 (uffi:def-function ("getenv" c-getenv) 
23     ((name :cstring))
24   :returning :cstring)
25
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))))
31     
32 #+test-uffi
33 (progn
34   (flet ((print-results (str)
35            (format t "~&(getenv ~S) => ~S" str (my-getenv str))))
36     (print-results "USER")
37     (print-results "_FOO_")))
38