[plt-scheme] environment variables (i.e. getenv)

From: Andrew Gwozdziewycz (apgwoz at gmail.com)
Date: Fri Mar 23 13:57:14 EDT 2007

Well, that's definitely more help than required, but thank you!

Andrew

On Mar 23, 2007, at 1:51 PM, Daniel Yoo wrote:

>
>
> On Fri, 23 Mar 2007, Andrew Gwozdziewycz wrote:
>
>> In scheme48 there is a function that returns an association list  
>> of all the environment variables, environment->alist.
>>
>> Is there something similar in MzLib? I've only come up with  
>> references to getenv in my searching, but that only returns one  
>> variable or #f. Any help appreciated.
>
>
> Hi Andrew,
>
> This might not be completely right yet, but here's something that  
> should help, using the Foreign Function Interface (FFI):
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> (module environ-vars mzscheme
>   (require (lib "foreign.ss"))
>   (unsafe!)
>   (provide get-environ)
>
>   (define lib (ffi-lib #f))
>
>   ;; get-environ: -> (listof byte-string)
>   ;; Returns a list of byte strings.  Each byte string will be
>   ;; in the form "key=value".
>   (define (get-environ)
>     (let ([byte-ptr (get-ffi-obj "environ" lib _pointer)])
>       (let loop ([results '()]
>                  [i 0])
>         (let ([next-elt (ptr-ref byte-ptr _bytes/eof i)])
>           (cond
>             [(eof-object? next-elt) (reverse! results)]
>             [else
>              (loop (cons next-elt results) (add1 i))]))))))
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
>
>
> This module should provide access to the environ byte strings, so  
> that you can later figure out all the environment names:
>
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
> ;;;;
>> (map (lambda (b) (car (regexp-match #rx"^[^=]+" b))) (get-environ))
> (#"SSH_AGENT_PID"
>  #"SHELL"
>  #"GTK_RC_FILES"
>  #"OLDPWD"
>  #"USER"
>  #"GNOME_KEYRING_SOCKET"
>  #"SSH_AUTH_SOCK"
>  #"SESSION_MANAGER"
>  #"USERNAME"
>  #"DESKTOP_SESSION"
>  #"PATH"
>  #"GDM_XSERVER_LOCATION"
>  #"PWD"
>  #"JAVA_HOME"
>  #"LANG"
>  #"GDMSESSION"
>  #"HOME"
>  #"SHLVL"
>  #"LANGUAGE"
>  #"GNOME_DESKTOP_SESSION_ID"
>  #"LOGNAME"
>  #"DBUS_SESSION_BUS_ADDRESS"
>  #"DISPLAY"
>  #"XAUTHORITY")
> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
> ;;;;
>
>
> Best of wishes!

--
Andrew Gwozdziewycz
apgwoz at gmail.com
http://and.rovir.us  |  http://www.photub.com



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20070323/a0b5dfbc/attachment.html>

Posted on the users mailing list.