1 ! Copyright (C) 2008 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien.strings fry io.encodings.utf16n kernel
4 splitting windows windows.kernel32 windows.types system
5 environment alien.data sequences windows.errors
6 io.streams.memory io.encodings io specialized-arrays ;
7 SPECIALIZED-ARRAY: TCHAR
10 M: winnt os-env ( key -- value )
11 MAX_UNICODE_PATH TCHAR <c-array>
12 [ dup length GetEnvironmentVariable ] keep over 0 = [
15 nip utf16n alien>string
18 M: winnt set-os-env ( value key -- )
19 swap SetEnvironmentVariable win32-error=0/f ;
21 M: winnt unset-os-env ( key -- )
22 f SetEnvironmentVariable 0 = [
23 GetLastError ERROR_ENVVAR_NOT_FOUND =
24 [ win32-error ] unless
27 M: winnt (os-envs) ( -- seq )
28 GetEnvironmentStrings [
31 [ "\0" read-until drop dup empty? not ] [ ] produce nip
33 ] [ FreeEnvironmentStrings win32-error=0/f ] bi ;