1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien.accessors alien.c-types alien.data alien.strings
4 alien.syntax environment io.encodings.utf8 kernel libc system unix.ffi
5 unix.utilities vocabs ;
8 HOOK: environ os ( -- void* )
10 M: unix environ ( -- void* ) &: environ ;
12 M: unix os-env ( key -- value ) getenv ;
14 M: unix set-os-env ( value key -- )
16 swap 1 setenv io-error
21 M: unix unset-os-env ( key -- ) unsetenv io-error ;
23 M: unix (os-envs) ( -- seq )
24 environ void* deref native-string-encoding alien>strings ;
26 : set-void* ( value alien -- ) 0 set-alien-cell ;
28 M: unix set-os-envs-pointer ( malloc -- ) environ set-void* ;
30 M: unix (set-os-envs) ( seq -- )
31 utf8 strings>alien malloc-byte-array set-os-envs-pointer ;
33 os macosx? [ "environment.unix.macosx" require ] when