1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE a_modes.inc}
21 uses SysUtils
, CTypes
;
23 function SetEnvVar(const VarName
: AnsiString; const VarVal
: AnsiString): Boolean;
24 function GetUserName
: String;
36 function setenv(const VarStr
: PChar; const VarVal
: PChar; Repl
: cint
): cint
;
38 if (SetEnvironmentVariable(VarStr
, VarVal
)) then
46 function setenv(const VarStr
: PChar; const VarVal
: PChar; Repl
: cint
): cint
;
47 cdecl; external clib name
'setenv';
50 function SetEnvVar(const VarName
: AnsiString; const VarVal
: AnsiString): Boolean;
52 Result
:= (setenv(PChar(VarName
), PChar(VarVal
), 1) = 0);
55 (* Get system username already in cp1251 *)
56 function GetUserName
: AnsiString;
59 {$IF DEFINED(WINDOWS)}
60 Result
:= utf2win(UTF8String(SysUtils
.GetEnvironmentVariable(WideString('USERNAME'))));
61 {$ELSEIF DEFINED(UNIX)}
62 Result
:= utf2win(SysUtils
.GetEnvironmentVariable('USER'));
66 (* invalidate username with non-cp1251 symbols *)
68 while i
<= High(Result
) do
70 if Result
[i
] = '?' then