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 system environment
5 alien.c-types sequences windows.errors io.streams.memory
9 << "TCHAR" require-c-arrays >>
11 M: winnt os-env ( key -- value )
12 MAX_UNICODE_PATH "TCHAR" <c-array>
13 [ dup length GetEnvironmentVariable ] keep over 0 = [
16 nip utf16n alien>string
19 M: winnt set-os-env ( value key -- )
20 swap SetEnvironmentVariable win32-error=0/f ;
22 M: winnt unset-os-env ( key -- )
23 f SetEnvironmentVariable 0 = [
24 GetLastError ERROR_ENVVAR_NOT_FOUND =
25 [ win32-error ] unless
28 M: winnt (os-envs) ( -- seq )
29 GetEnvironmentStrings [
32 [ "\0" read-until drop dup empty? not ] [ ] produce nip
34 ] [ FreeEnvironmentStrings win32-error=0/f ] bi ;