mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-05-11 21:22:41 +02:00
93 lines
2.4 KiB
PHP
93 lines
2.4 KiB
PHP
{%MainUnit lazfileutils.pas}
|
|
|
|
function FilenameIsAbsolute(const TheFilename: string):boolean;
|
|
begin
|
|
Result:=FilenameIsUnixAbsolute(TheFilename);
|
|
end;
|
|
|
|
function FileOpenUTF8(Const FileName : string; Mode : Integer) : THandle;
|
|
begin
|
|
Result := SysUtils.FileOpen(UTF8ToSys(FileName), Mode);
|
|
end;
|
|
|
|
function FileCreateUTF8(Const FileName : string) : THandle;
|
|
begin
|
|
Result := SysUtils.FileCreate(UTF8ToSys(FileName));
|
|
end;
|
|
|
|
function FileCreateUTF8(Const FileName : string; Rights: Cardinal) : THandle;
|
|
begin
|
|
Result := SysUtils.FileCreate(UTF8ToSys(FileName), Rights);
|
|
end;
|
|
|
|
Function FileCreateUtf8(Const FileName : String; ShareMode : Integer; Rights : Cardinal) : THandle;
|
|
begin
|
|
Result := SysUtils.FileCreate(UTF8ToSys(FileName), ShareMode, Rights);
|
|
end;
|
|
|
|
function FileGetAttrUTF8(const FileName: String): Longint;
|
|
begin
|
|
Result:=SysUtils.FileGetAttr(UTF8ToSys(Filename));
|
|
end;
|
|
|
|
function FileSetAttrUTF8(const Filename: String; Attr: longint): Longint;
|
|
begin
|
|
Result:=SysUtils.FileSetAttr(UTF8ToSys(Filename),Attr);
|
|
InvalidateFileStateCache(Filename);
|
|
end;
|
|
|
|
function FileExistsUTF8(const Filename: string): boolean;
|
|
begin
|
|
Result:=SysUtils.FileExists(UTF8ToSys(Filename));
|
|
end;
|
|
|
|
function ExpandFileNameUtf8(const FileName: string; {const} BaseDir: String = ''): String;
|
|
var
|
|
IsAbs: Boolean;
|
|
CurDir, HomeDir, Fn: String;
|
|
begin
|
|
Fn := FileName;
|
|
DoDirSeparators(Fn);
|
|
IsAbs := FileNameIsUnixAbsolute(Fn);
|
|
if (not IsAbs) then
|
|
begin
|
|
CurDir := GetCurrentDirUtf8;
|
|
if ((Length(Fn) > 1) and (Fn[1] = '~') and (Fn[2] = '/')) or (Fn = '~') then
|
|
begin
|
|
{$Hint use GetEnvironmentVariableUTF8}
|
|
HomeDir := SysToUtf8(GetEnvironmentVariable('HOME'));
|
|
if not FileNameIsUnixAbsolute(HomeDir) then
|
|
HomeDir := ExpandFileNameUtf8(HomeDir,'');
|
|
Fn := HomeDir + Copy(Fn,2,length(Fn));
|
|
IsAbs := True;
|
|
end;
|
|
end;
|
|
if IsAbs then
|
|
begin
|
|
Result := ResolveDots(Fn);
|
|
end
|
|
else
|
|
begin
|
|
if (BaseDir = '') then
|
|
Fn := IncludeTrailingPathDelimiter(CurDir) + Fn
|
|
else
|
|
Fn := IncludeTrailingPathDelimiter(BaseDir) + Fn;
|
|
Fn := ResolveDots(Fn);
|
|
//if BaseDir is not absolute then this needs to be expanded as well
|
|
if not FileNameIsUnixAbsolute(Fn) then
|
|
Fn := ExpandFileNameUtf8(Fn, '');
|
|
Result := Fn;
|
|
end;
|
|
end;
|
|
|
|
function GetCurrentDirUTF8: String;
|
|
begin
|
|
Result:=SysToUTF8(SysUtils.GetCurrentDir);
|
|
end;
|
|
|
|
|
|
procedure InitLazFileUtils;
|
|
begin
|
|
//dummy
|
|
end;
|