source: trunk/abcl/contrib/posix-syscalls/getenv.lisp

Last change on this file was 15700, checked in by Mark Evenson, 12 months ago

Create POSIX-SYSCALLS contrib to set environment variables

Based on code provided by Alan Ruttenberg in
<https://github.com/alanruttenberg/lsw2/blob/owlapiv4/util/setenv.lisp>.

See
<https://mailman.common-lisp.net/pipermail/armedbear-devel/2023-April/004308.html>
ff.

See <file:contrib/posix-syscalls/posix-syscalls.org>.

File size: 988 bytes
Line 
1(in-package :system/posix-syscalls)
2
3(defun c-library-reference ()
4  (#"getInstance" 'com.sun.jna.NativeLibrary "c"))
5
6(defun getenv (variable)
7  (let ((found (#"invokePointer"
8                (#"getFunction" (c-library-reference) "getenv")
9                (java:jnew-array-from-list "java.lang.Object" (list variable)))))
10    (when found
11      (#"getString" found 0))))
12
13(defun putenv (variable value)
14  (let ((variable=value
15          (java:jnew-array-from-list "java.lang.Object"
16                                     (list
17                                      (format nil "~a=~a"
18                                              variable  value)))))
19          (#"invokeInt"
20           (#"getFunction" (c-library-reference) "putenv")
21           variable=value)))
22
23(defun unsetenv (variable)
24  (when
25      (= 0
26         (#"invokeInt"
27          (#"getFunction" (c-library-reference) "unsetenv")
28          (java:jnew-array-from-list "java.lang.Object" (list variable))))
29    t))
30     
31 
32
33
Note: See TracBrowser for help on using the repository browser.