diff options
Diffstat (limited to 'UEngines.pas')
| -rw-r--r-- | UEngines.pas | 352 |
1 files changed, 165 insertions, 187 deletions
diff --git a/UEngines.pas b/UEngines.pas index e490cca..6cb8d7a 100644 --- a/UEngines.pas +++ b/UEngines.pas @@ -21,7 +21,7 @@ unit UEngines; interface -uses glib2, gdk2, Classes, Libc, UGlibC_compat; +uses glib2, gdk2, Classes, ULibc; const ERRException = -1; @@ -49,7 +49,7 @@ type UpDir: boolean; Mode, UID, GID: Cardinal; IsDir, IsLnk, IsBlk, IsChr, IsFIFO, IsSock, Selected, IsDotFile: boolean; - ModifyTime: TTimeT; + ModifyTime: time_t; Icon: Pointer; ItemColor: PGdkColor; end; @@ -64,7 +64,7 @@ type Size: Int64; Mode, UID, GID: Cardinal; IsDir, IsLnk, ForceMove, IsOnRO, IsExecutable: boolean; - ModifyTime: TTimeT; + ModifyTime: time_t; Level: word; atime, mtime: Int64; end; @@ -189,7 +189,7 @@ procedure FreeDataItem(DataItem: PDataItem); overload; implementation -uses SysUtils, UCoreUtils, UConfig; +uses SysUtils, UCoreUtils; (********************************************************************************************************************************) constructor TPanelEngine.Create; @@ -244,23 +244,23 @@ end; function TLocalTreeEngine.GetListing(var List: TList; const AddDotFiles: boolean; APath: string): integer; var Item : PDataItem; - Handle : PDirectoryStream; + Handle : PDIR; DirEnt : PDirent64; Buf : PChar; // StatBuf : TStatBuf64; - StatBuf : PGlibc_stat64; + StatBuf : Pstat64; i: integer; LnkBuf : array[0..1000] of char; begin Result := 0; try APath := IncludeTrailingPathDelimiter(APath); - if Libc.__chdir(PChar(APath)) <> 0 then begin + if libc_chdir(PChar(APath)) <> 0 then begin Result := errno; DebugMsg(['*** TLocalTreeEngine.GetListing(APath=', APath, '): chdir error: ', strerror(Result)]); Exit; end; - Handle := Libc.opendir(PChar(APath)); + Handle := opendir(PChar(APath)); if not Assigned(Handle) then begin DebugMsg(['*** TLocalTreeEngine.GetListing(APath=', APath, '): opendir() handle == NULL: ', strerror(errno)]); Result := ERRNoAccess; @@ -279,9 +279,9 @@ begin begin Item := nil; // DebugMsg(['x5']); - Item := Libc.malloc(SizeOf(TDataItem)); + Item := malloc(SizeOf(TDataItem)); // DebugMsg(['x6']); - Libc.memset(Item, 0, SizeOf(TDataItem)); + memset(Item, 0, SizeOf(TDataItem)); // DebugMsg(['x7']); with Item^ do begin // DebugMsg(['x8']); @@ -293,10 +293,10 @@ begin FDisplayName := StrToUTF8(Buf); // FDisplayName := strdup(Buf); // DebugMsg(['x']); - StatBuf := Libc.malloc(sizeof(TGlibc_stat64)); - Libc.memset(StatBuf, 0, sizeof(TGlibc_stat64)); + StatBuf := malloc(sizeof(Tstat64)); + memset(StatBuf, 0, sizeof(Tstat64)); // DebugMsg(['(II) TLocalTreeEngine.GetListing(APath=', APath, '): lstat(Buf = ', Buf, ')']); - if glibc_lstat64(Buf, StatBuf) <> 0 then begin + if lstat64(Buf, StatBuf) <> 0 then begin DebugMsg(['*** TLocalTreeEngine.GetListing(APath=', APath, '): Error reading file via lstat64: ', strerror(errno)]); Continue; end; @@ -308,11 +308,7 @@ begin IsChr := __S_ISTYPE(StatBuf^.st_mode, __S_IFCHR); IsFIFO := __S_ISTYPE(StatBuf^.st_mode, __S_IFIFO); IsSock := __S_ISTYPE(StatBuf^.st_mode, __S_IFSOCK); -{$IFDEF KYLIX} - ModifyTime := StatBuf^.st_mtime; -{$ELSE} ModifyTime := StatBuf^.st_mtim.tv_sec; -{$ENDIF} if StatBuf^.st_uid = 4294967295 then UID := getuid else UID := StatBuf^.st_uid; if StatBuf^.st_gid = 4294967295 then GID := getgid @@ -320,26 +316,26 @@ begin UpDir := False; Selected := False; // DebugMsg(['(II) TLocalTreeEngine.GetListing(APath=', APath, '): freeing StatBuf...']); - Libc.free(StatBuf); + libc_free(StatBuf); // DebugMsg([' done.']); if IsLnk then begin // DebugMsg(['aaaax']); i := readlink(PChar(APath + String(Buf)), LnkBuf, SizeOf(LnkBuf)); if i > 0 then begin LnkBuf[i] := #0; - LnkPointTo := Libc.malloc(i + 1); - Libc.memset(LnkPointTo, 0, i + 1); - LnkPointTo := Libc.strncpy(LnkPointTo, @LnkBuf[0], i); + LnkPointTo := malloc(i + 1); + memset(LnkPointTo, 0, i + 1); + LnkPointTo := strncpy(LnkPointTo, @LnkBuf[0], i); end; - StatBuf := Libc.malloc(sizeof(TGlibc_stat64)); - Libc.memset(StatBuf, 0, sizeof(TGlibc_stat64)); - if glibc_stat64(Buf, StatBuf) = 0 then begin + StatBuf := malloc(sizeof(Tstat64)); + memset(StatBuf, 0, sizeof(Tstat64)); + if stat64(Buf, StatBuf) = 0 then begin IsDir := __S_ISTYPE(StatBuf^.st_mode, __S_IFDIR); Mode := StatBuf^.st_mode; end; // DebugMsg(['(II) TLocalTreeEngine.GetListing(APath=', APath, '): freeing StatBuf...']); - Libc.free(StatBuf); + libc_free(StatBuf); // DebugMsg([' done.']); end; // DebugMsg(['xdffffffff']); @@ -369,11 +365,11 @@ end; function TLocalTreeEngine.ChangeDir(const NewPath: string; const ShowProgress: boolean = True): integer; var APath: string; - Handle : PDirectoryStream; + Handle : PDIR; begin try APath := IncludeTrailingPathDelimiter(NewPath); - if __chdir(PChar(APath)) <> 0 then begin + if libc_chdir(PChar(APath)) <> 0 then begin Result := errno; Exit; end; @@ -403,21 +399,21 @@ end; (********************************************************************************************************************************) function TLocalTreeEngine.ExplicitChDir(const NewPath: string): integer; begin - Result := __chdir(PChar(NewPath)); + Result := libc_chdir(PChar(NewPath)); if Result <> 0 then Result := errno; end; (********************************************************************************************************************************) function TLocalTreeEngine.GetFileSystemSize(const APath: string): Int64; -var Stat: PGlibc_statfs64; +var Stat: Pstatfs64; begin Result := 0; try - Stat := Libc.malloc(sizeof(TGlibc_statfs64)); - Libc.memset(Stat, 0, sizeof(TGlibc_statfs64)); - if glibc_statfs64(PChar(APath), Stat) <> 0 then Exit; + Stat := malloc(sizeof(Tstatfs64)); + memset(Stat, 0, sizeof(Tstatfs64)); + if statfs64(PChar(APath), Stat) <> 0 then Exit; Result := Stat^.f_bsize * Stat^.f_blocks; - Libc.free(Stat); + libc_free(Stat); except on E: Exception do DebugMsg(['*** TLocalTreeEngine.GetFileSystemSize(APath=', APath, ') -Exception: ', E.Message]); end; @@ -430,15 +426,15 @@ end; (********************************************************************************************************************************) function TLocalTreeEngine.GetFileSystemFree(const APath: string): Int64; -var Stat: PGlibc_statfs64; +var Stat: Pstatfs64; begin Result := 0; try - Stat := Libc.malloc(sizeof(TGlibc_statfs64)); - Libc.memset(Stat, 0, sizeof(TGlibc_statfs64)); - if glibc_statfs64(PChar(APath), Stat) <> 0 then Exit; + Stat := malloc(sizeof(Tstatfs64)); + memset(Stat, 0, sizeof(Tstatfs64)); + if statfs64(PChar(APath), Stat) <> 0 then Exit; Result := Stat^.f_bsize * Stat^.f_bavail; - Libc.free(Stat); + libc_free(Stat); except on E: Exception do DebugMsg(['*** TLocalTreeEngine.GetFileSystemFree(APath=', APath, ') -Exception: ', E.Message]); end; @@ -452,9 +448,9 @@ end; (********************************************************************************************************************************) function TLocalTreeEngine.MakeDir(const NewDir: string): integer; begin - DebugMsg(['(II) TLocalTreeEngine.MakeDir: begin']); +// DebugMsg(['(II) TLocalTreeEngine.MakeDir: begin']); Result := __mkdir(PChar(NewDir), OctalToAttr(ConfDefaultDirCreationMask)); - DebugMsg(['(II) TLocalTreeEngine.MakeDir: Result = ', Result]); +// DebugMsg(['(II) TLocalTreeEngine.MakeDir: Result = ', Result]); if Result <> 0 then Result := errno; (* if Result <> 0 then try @@ -464,7 +460,7 @@ begin DebugMsg(['(II) TLocalTreeEngine.MakeDir: Exception']); end; *) - DebugMsg(['(II) TLocalTreeEngine.MakeDir: end']); +// DebugMsg(['(II) TLocalTreeEngine.MakeDir: end']); end; (********************************************************************************************************************************) @@ -472,15 +468,15 @@ end; function TLocalTreeEngine.GetDirSize(APath: string): Int64; function InternalGetDirSize(APath: string): Int64; - var Handle : PDirectoryStream; + var Handle : PDIR; DirEnt : PDirent64; - StatBuf : PGlibc_stat64; + StatBuf : Pstat64; begin Result := 0; try if BreakProcessingType = 1 then Exit; APath := IncludeTrailingPathDelimiter(APath); - if __chdir(PChar(APath)) <> 0 then begin + if libc_chdir(PChar(APath)) <> 0 then begin Result := 0; Exit; end; @@ -494,14 +490,14 @@ function TLocalTreeEngine.GetDirSize(APath: string): Int64; if Assigned(DirEnt) and Assigned(PChar(@DirEnt^.d_name[0])) and (PChar(@DirEnt^.d_name[0]) <> '.') and (PChar(@DirEnt^.d_name[0]) <> '..') and (DirEnt^.d_name[0] <> #0) then begin - StatBuf := Libc.malloc(sizeof(TGlibc_stat64)); - Libc.memset(StatBuf, 0, sizeof(TGlibc_stat64)); - if glibc_lstat64(PChar(@DirEnt^.d_name[0]), StatBuf) <> 0 then Continue; + StatBuf := malloc(sizeof(Tstat64)); + memset(StatBuf, 0, sizeof(Tstat64)); + if lstat64(PChar(@DirEnt^.d_name[0]), StatBuf) <> 0 then Continue; if __S_ISTYPE(StatBuf^.st_mode, __S_IFDIR) then begin Inc(Result, InternalGetDirSize(APath + String(PChar(@DirEnt^.d_name[0])))); - __chdir(PChar(APath)); + libc_chdir(PChar(APath)); end else Inc(Result, StatBuf^.st_size); - Libc.free(StatBuf); + libc_free(StatBuf); end; until DirEnt = nil; closedir(Handle); @@ -526,15 +522,15 @@ end; function TLocalTreeEngine.Remove(APath: string): integer; begin APath := ExcludeTrailingPathDelimiter(APath); - Result := Libc.remove(PChar(APath)); + Result := libc_remove(PChar(APath)); if Result <> 0 then Result := errno; end; (********************************************************************************************************************************) procedure TLocalTreeEngine.FillDirFiles(APath: string; List: TList; ALevel: word); -var Handle : PDirectoryStream; +var Handle : PDIR; DirEnt : PDirent64; - StatBuf_global : PGlibc_stat64; + StatBuf_global : Pstat64; Item: PDataItemSL; i: integer; LnkBuf : array[0..1000] of char; @@ -542,18 +538,18 @@ var Handle : PDirectoryStream; procedure AddEntry(FPath: string; AddCurrDirStage, AStage1: boolean); - var StatBuf_local : PGlibc_stat64; + var StatBuf_local : Pstat64; begin // DebugMsg(['TLocalTreeEngine.FillDirFiles: addding "', FPath, '"']); FPath := ExcludeTrailingPathDelimiter(FPath); - StatBuf_local := Libc.malloc(sizeof(TGlibc_stat64)); - Libc.memset(StatBuf_local, 0, sizeof(TGlibc_stat64)); - if glibc_lstat64(PChar(FPath), StatBuf_local) <> 0 then begin + StatBuf_local := malloc(sizeof(Tstat64)); + memset(StatBuf_local, 0, sizeof(Tstat64)); + if lstat64(PChar(FPath), StatBuf_local) <> 0 then begin DebugMsg(['*** TLocalTreeEngine.FillDirFiles: Error reading file stat AddEntry("', FPath, '"): ', strerror(errno)]); Exit; end; - Item := Libc.malloc(SizeOf(TDataItemSL)); - Libc.memset(Item, 0, SizeOf(TDataItemSL)); + Item := malloc(SizeOf(TDataItemSL)); + memset(Item, 0, SizeOf(TDataItemSL)); with Item^ do begin FName := nil; FDisplayName := nil; @@ -573,32 +569,23 @@ var Handle : PDirectoryStream; else UID := StatBuf_local^.st_uid; if StatBuf_local^.st_gid = 4294967295 then GID := getgid else GID := StatBuf_local^.st_gid; -{$IFDEF KYLIX} - atime := StatBuf_local^.st_atime; - mtime := StatBuf_local^.st_mtime; -{$ELSE} atime := StatBuf_local^.st_atim.tv_sec; mtime := StatBuf_local^.st_mtim.tv_sec; -{$ENDIF} if IsLnk and AddCurrDirStage then DebugMsg(['*** Assertion failed AddEntry: Item^.IsLnk = True']); if IsLnk and (not AddCurrDirStage) then begin i := readlink(PChar(APath + String(PChar(@DirEnt^.d_name[0]))), LnkBuf, SizeOf(LnkBuf)); if i > 0 then begin LnkBuf[i] := #0; - LnkPointTo := Libc.malloc(i + 1); - Libc.memset(LnkPointTo, 0, i + 1); - LnkPointTo := Libc.strncpy(LnkPointTo, @LnkBuf[0], i); + LnkPointTo := malloc(i + 1); + memset(LnkPointTo, 0, i + 1); + LnkPointTo := strncpy(LnkPointTo, @LnkBuf[0], i); // StrLCopy(LnkPointTo, @LnkBuf[0], i); end; end; -{$IFDEF KYLIX} - ModifyTime := StatBuf_local^.st_mtime; -{$ELSE} ModifyTime := StatBuf_local^.st_mtim.tv_sec; -{$ENDIF} // DebugMsg([FormatDateTime('c', ModifyTime)]); Level := ALevel + Ord(not AddCurrDirStage); - Libc.free(StatBuf_local); + libc_free(StatBuf_local); end; if AddCurrDirStage then List.Add(Item) else FilesList.Add(Item); @@ -610,7 +597,7 @@ begin AddEntry(APath, True, True); FilesList := TList.Create; APath := IncludeTrailingPathDelimiter(APath); - if __chdir(PChar(APath)) <> 0 then begin + if libc_chdir(PChar(APath)) <> 0 then begin DebugMsg(['*** TLocalTreeEngine.FillDirFiles: chdir to "', APath, '" failed: ', strerror(errno)]); Exit; end; @@ -619,17 +606,17 @@ begin repeat DirEnt := readdir64(Handle); if Assigned(DirEnt) and Assigned(PChar(@DirEnt^.d_name[0])) and (PChar(@DirEnt^.d_name[0]) <> '.') and (PChar(@DirEnt^.d_name[0]) <> '..') then begin - StatBuf_global := Libc.malloc(sizeof(TGlibc_stat64)); - Libc.memset(StatBuf_global, 0, sizeof(TGlibc_stat64)); - if glibc_lstat64(PChar(@DirEnt^.d_name[0]), StatBuf_global) <> 0 then begin + StatBuf_global := malloc(sizeof(Tstat64)); + memset(StatBuf_global, 0, sizeof(Tstat64)); + if lstat64(PChar(@DirEnt^.d_name[0]), StatBuf_global) <> 0 then begin DebugMsg(['*** TLocalTreeEngine.FillDirFiles: Error lstat-ing ("', PChar(@DirEnt^.d_name[0]), '"): ', strerror(errno)]); Continue; end; if __S_ISTYPE(StatBuf_global^.st_mode, __S_IFDIR) then begin FillDirFiles(APath + String(PChar(@DirEnt^.d_name[0])), List, ALevel + 1); - __chdir(PChar(APath)); + libc_chdir(PChar(APath)); end else AddEntry(APath + String(PChar(@DirEnt^.d_name[0])), False, True); - Libc.free(StatBuf_global); + libc_free(StatBuf_global); end; until DirEnt = nil; CloseDir(Handle); @@ -645,21 +632,21 @@ end; (********************************************************************************************************************************) function TLocalTreeEngine.GetFileInfoSL(APath: string): PDataItemSL; -var StatBuf : PGlibc_stat64; +var StatBuf : Pstat64; i : integer; LnkBuf : array[0..1000] of char; begin Result := nil; try - StatBuf := Libc.malloc(sizeof(TGlibc_stat64)); - Libc.memset(StatBuf, 0, sizeof(TGlibc_stat64)); - if glibc_lstat64(PChar(APath), StatBuf) <> 0 then begin + StatBuf := malloc(sizeof(Tstat64)); + memset(StatBuf, 0, sizeof(Tstat64)); + if lstat64(PChar(APath), StatBuf) <> 0 then begin DebugMsg(['*** Error reading file stat GetFileInfoSL(lstat): ', strerror(errno)]); Exit; end; // DebugMsg(['x1']); - Result := Libc.malloc(SizeOf(TDataItemSL)); - Libc.memset(Result, 0, SizeOf(TDataItemSL)); + Result := malloc(SizeOf(TDataItemSL)); + memset(Result, 0, SizeOf(TDataItemSL)); // DebugMsg(['x1']); with Result^ do begin FName := nil; @@ -681,25 +668,16 @@ begin // DebugMsg(['x2']); ForceMove := False; // DebugMsg(['x2']); -{$IFDEF KYLIX} - ModifyTime := StatBuf^.st_mtime; -{$ELSE} ModifyTime := StatBuf^.st_mtim.tv_sec; -{$ENDIF} // DebugMsg(['x2']); if StatBuf^.st_uid = 4294967295 then UID := getuid else UID := StatBuf^.st_uid; if StatBuf^.st_gid = 4294967295 then GID := getgid else GID := StatBuf^.st_gid; -{$IFDEF KYLIX} - atime := StatBuf^.st_atime; - mtime := StatBuf^.st_mtime; -{$ELSE} atime := StatBuf^.st_atim.tv_sec; mtime := StatBuf^.st_mtim.tv_sec; -{$ENDIF} // DebugMsg(['x1']); - Libc.free(StatBuf); + libc_free(StatBuf); // DebugMsg(['x1']); Level := 1; // DebugMsg(['x1']); @@ -707,18 +685,18 @@ begin i := readlink(PChar(APath), LnkBuf, SizeOf(LnkBuf)); if i > 0 then begin LnkBuf[i] := #0; - LnkPointTo := Libc.malloc(i + 1); - Libc.memset(LnkPointTo, 0, i + 1); + LnkPointTo := malloc(i + 1); + memset(LnkPointTo, 0, i + 1); // StrLCopy(LnkPointTo, @LnkBuf[0], i); - LnkPointTo := Libc.strncpy(LnkPointTo, @LnkBuf[0], i); + LnkPointTo := strncpy(LnkPointTo, @LnkBuf[0], i); end; - StatBuf := Libc.malloc(sizeof(TGlibc_stat64)); - Libc.memset(StatBuf, 0, sizeof(TGlibc_stat64)); - if glibc_stat64(PChar(APath), StatBuf) = 0 then begin + StatBuf := malloc(sizeof(Tstat64)); + memset(StatBuf, 0, sizeof(Tstat64)); + if stat64(PChar(APath), StatBuf) = 0 then begin IsDir := __S_ISTYPE(StatBuf^.st_mode, __S_IFDIR); Mode := StatBuf^.st_mode; end; - Libc.free(StatBuf); + libc_free(StatBuf); end; end; // DebugMsg(['x1']); @@ -739,9 +717,9 @@ begin end; function TLocalTreeEngine.CopyFile(Sender: Pointer; SourceFile, DestFile: string; ProgressFunc: TEngineProgressFunc; ErrorFunc: TEngineErrorFunc; Append: boolean): boolean; -var fsrc, fdest: PIOFile; +var fsrc, fdest: PFILE; BytesDone, BytesRead: Int64; - offset: off_t; +// offset: __off_t; // Used due to sendfile bug while copying from NTFS and some 2.6.x kernels @@ -753,16 +731,16 @@ var fsrc, fdest: PIOFile; try Result := False; Res := True; - DebugMsg(['*** Using old copy function due to bug in sendfile']); +// DebugMsg(['*** Using old copy function due to bug in sendfile']); // WriteLn('x1'); - Buffer := Libc.malloc(FBlockSize); + Buffer := malloc(FBlockSize); // WriteLn('x2'); if Buffer = nil then begin ErrorFunc(Sender, 1, errno, SourceFile); // Memory allocation failed -// Libc.free(Buffer); +// libc_free(Buffer); Exit; end; - Libc.memset(Buffer, 0, FBlockSize); + memset(Buffer, 0, FBlockSize); // WriteLn('x3'); while feof(fsrc) = 0 do begin @@ -791,23 +769,23 @@ var fsrc, fdest: PIOFile; // WriteLn('x7'); end; // WriteLn('x8'); - Libc.free(Buffer); + libc_free(Buffer); // WriteLn('x9'); Result := Res; except on E: Exception do DebugMsg(['*** Exception raised in TLocalTreeEngine.CopyFile.OldCopyRoutine(Sender=', DWord(Sender), ', SourceFile=', SourceFile, ', DestFile=', DestFile, '): (', E.ClassName, '): ', E.Message]); end; end; - +(* function NewCopyRoutine: boolean; var Res: boolean; - StatBuf: PGlibc_stat64; + StatBuf: Pstat64; begin try Res := True; repeat DebugMsg(['Copy(sendfile): offset = ', offset, ', BytesDone = ', BytesDone, ', ftell(fsrc) = ', ftell(fsrc)]); - BytesRead := Libc.sendfile(glibc_fileno(fdest), glibc_fileno(fsrc), offset, FBlockSize); + BytesRead := sendfile(fileno(fdest), fileno(fsrc), offset, FBlockSize); if BytesRead = -1 then begin if errno = EINVAL then begin Result := OldCopyRoutine; @@ -822,21 +800,21 @@ var fsrc, fdest: PIOFile; end; until BytesRead < FBlockSize; - StatBuf := Libc.malloc(sizeof(TGlibc_stat64)); - Libc.memset(StatBuf, 0, sizeof(TGlibc_stat64)); - if glibc_lstat64(PChar(SourceFile), StatBuf) <> 0 then begin + StatBuf := malloc(sizeof(Tstat64)); + memset(StatBuf, 0, sizeof(Tstat64)); + if lstat64(PChar(SourceFile), StatBuf) <> 0 then begin DebugMsg(['*** TLocalTreeEngine.CopyFile.NewCopyRoutine(Sender=', DWord(Sender), ', SourceFile=', SourceFile, ', DestFile=', DestFile, '): Error reading file via lstat64: ', strerror(errno)]); Res := ErrorFunc(Sender, 6, errno, SourceFile); end else if (BytesDone < StatBuf^.st_size) and Res then Res := ErrorFunc(Sender, 6, errno, SourceFile); - Libc.free(StatBuf); + libc_free(StatBuf); Result := Res; except on E: Exception do DebugMsg(['*** Exception raised in TLocalTreeEngine.CopyFile.NewCopyRoutine(Sender=', DWord(Sender), ', SourceFile=', SourceFile, ', DestFile=', DestFile, '): (', E.ClassName, '): ', E.Message]); end; end; - +*) begin Result := False; try @@ -854,9 +832,9 @@ begin end; BytesDone := 0; - offset := 0; +// offset := 0; - Result := NewCopyRoutine; + Result := OldCopyRoutine; if fclose(fdest) <> 0 then begin fclose(fsrc); @@ -870,52 +848,52 @@ begin except on E: Exception do DebugMsg(['*** Exception raised in TLocalTreeEngine.CopyFile(Sender=', DWord(Sender), ', SourceFile=', SourceFile, ', DestFile=', DestFile, '): (', E.ClassName, '): ', E.Message]); end; - DebugMsg(['(II) TLocalTreeEngine.CopyFile: finished']); +// DebugMsg(['(II) TLocalTreeEngine.CopyFile: finished']); end; (********************************************************************************************************************************) function TLocalTreeEngine.FileExists(const FileName: string; const Use_lstat: boolean = False): Boolean; -var st: PGlibc_stat64; +var st: Pstat64; begin - st := Libc.malloc(sizeof(TGlibc_stat64)); - Libc.memset(st, 0, sizeof(TGlibc_stat64)); - if Use_lstat then Result := glibc_lstat64(PChar(FileName), st) = 0 - else Result := glibc_stat64(PChar(FileName), st) = 0; - Libc.free(st); + st := malloc(sizeof(Tstat64)); + memset(st, 0, sizeof(Tstat64)); + if Use_lstat then Result := lstat64(PChar(FileName), st) = 0 + else Result := stat64(PChar(FileName), st) = 0; + libc_free(st); end; (********************************************************************************************************************************) function TLocalTreeEngine.DirectoryExists(const FileName: string; const Use_lstat: boolean = False): Boolean; -var st: PGlibc_stat64; +var st: Pstat64; begin - st := Libc.malloc(sizeof(TGlibc_stat64)); - Libc.memset(st, 0, sizeof(TGlibc_stat64)); - if Use_lstat then Result := glibc_lstat64(PChar(FileName), st) = 0 else - if glibc_stat64(PChar(FileName), st) = 0 + st := malloc(sizeof(Tstat64)); + memset(st, 0, sizeof(Tstat64)); + if Use_lstat then Result := lstat64(PChar(FileName), st) = 0 else + if stat64(PChar(FileName), st) = 0 then Result := S_ISDIR(st^.st_mode) else Result := False; - Libc.free(st); + libc_free(st); end; (********************************************************************************************************************************) function TLocalTreeEngine.MakeSymLink(const NewFileName, PointTo: string): integer; begin // DebugMsg(['TLocalTreeEngine.MakeSymLink(NewFileName = "', NewFileName, '", PointTo = "', PointTo, '"']); - Result := Libc.symlink(PChar(PointTo), PChar(NewFileName)); + Result := symlink(PChar(PointTo), PChar(NewFileName)); if Result <> 0 then Result := errno; end; (********************************************************************************************************************************) function TLocalTreeEngine.Chmod(const FileName: string; const Mode: integer): integer; begin - Result := Libc.chmod(PChar(FileName), Mode); + Result := libc_chmod(PChar(FileName), Mode); if Result <> 0 then Result := errno; end; (********************************************************************************************************************************) function TLocalTreeEngine.Chown(const FileName: string; const UID, GID: integer): integer; begin - Result := Libc.chown(PChar(FileName), UID, GID); + Result := libc_chown(PChar(FileName), UID, GID); if Result <> 0 then Result := errno; end; @@ -927,48 +905,48 @@ end; (********************************************************************************************************************************) function TLocalTreeEngine.IsOnSameFS(const Path1, Path2: string): boolean; -var FStat1, FStat2: PGlibc_stat64; +var FStat1, FStat2: Pstat64; begin // DebugMsg(['** TLocalTreeEngine.IsOnSameFS("', Path1, '", "', Path2, '")']); Result := False; // Default fallback result (forces copy + delete) - FStat1 := Libc.malloc(sizeof(TGlibc_stat64)); - FStat2 := Libc.malloc(sizeof(TGlibc_stat64)); - Libc.memset(FStat1, 0, sizeof(TGlibc_stat64)); - Libc.memset(FStat2, 0, sizeof(TGlibc_stat64)); - if glibc_lstat64(PChar(Path1), FStat1) <> 0 then begin - DebugMsg(['** TLocalTreeEngine.IsOnSameFS: Libc.stat(', Path1, ') error: ', strerror(errno)]); + FStat1 := malloc(sizeof(Tstat64)); + FStat2 := malloc(sizeof(Tstat64)); + memset(FStat1, 0, sizeof(Tstat64)); + memset(FStat2, 0, sizeof(Tstat64)); + if lstat64(PChar(Path1), FStat1) <> 0 then begin + DebugMsg(['** TLocalTreeEngine.IsOnSameFS: stat(', Path1, ') error: ', strerror(errno)]); Exit; end; - if glibc_lstat64(PChar(Path2), FStat2) <> 0 then begin - DebugMsg(['** TLocalTreeEngine.IsOnSameFS: Libc.stat(', Path2, ') error: ', strerror(errno)]); + if lstat64(PChar(Path2), FStat2) <> 0 then begin + DebugMsg(['** TLocalTreeEngine.IsOnSameFS: stat(', Path2, ') error: ', strerror(errno)]); Exit; end; Result := FStat1^.st_dev = FStat2^.st_dev; - Libc.free(FStat1); - Libc.free(FStat2); + libc_free(FStat1); + libc_free(FStat2); // DebugMsg(['** TLocalTreeEngine.IsOnSameFS("', Path1, '", "', Path2, '") Result = ', Result]); end; (********************************************************************************************************************************) function TLocalTreeEngine.RenameFile(SourceFile, DestFile: string): integer; begin - Result := Libc.__rename(PChar(SourceFile), PChar(DestFile)); + Result := libc_rename(PChar(SourceFile), PChar(DestFile)); if Result <> 0 then Result := errno; end; (********************************************************************************************************************************) function TLocalTreeEngine.ChangeTimes(APath: string; mtime, atime: Int64): integer; -var timebuf: PGlibc_utimbuf; +var timebuf: Putimbuf; begin Result := errno; try - timebuf := Libc.malloc(sizeof(TGlibc_utimbuf)); - Libc.memset(timebuf, 0, sizeof(TGlibc_utimbuf)); + timebuf := malloc(sizeof(Tutimbuf)); + memset(timebuf, 0, sizeof(Tutimbuf)); timebuf^.actime := atime; timebuf^.modtime := mtime; - Result := glibc_utime(PChar(APath), timebuf); + Result := utime(PChar(APath), timebuf); if Result <> 0 then Result := errno; - Libc.free(timebuf); + libc_free(timebuf); except on E: Exception do DebugMsg(['*** Exception raised in TLocalTreeEngine.ChangeTimes(APath=', APath, '): (', E.ClassName, '): ', E.Message]); end; @@ -976,9 +954,9 @@ end; (********************************************************************************************************************************) procedure TLocalTreeEngine.GetFileSystemInfo(const APath: string; var FSSize, FSFree: Int64; var FSName: string); -var Stat: PGlibc_statfs64; - fd: PIOFile; - mntent: PMountEntry; +var Stat: Pstatfs64; + fd: PFILE; + mntent: Pmntent; mntdev: PChar; FoundLength: integer; Buffer: array[0..31] of char; @@ -987,9 +965,9 @@ begin FSFree := 0; FSName := ''; try - Stat := Libc.malloc(sizeof(TGlibc_statfs64)); - Libc.memset(Stat, 0, sizeof(TGlibc_statfs64)); - if glibc_statfs64(PChar(APath), Stat) <> 0 then Exit; + Stat := malloc(sizeof(Tstatfs64)); + memset(Stat, 0, sizeof(Tstatfs64)); + if statfs64(PChar(APath), Stat) <> 0 then Exit; FSSize := Stat^.f_bsize * Stat^.f_blocks; FSFree := Stat^.f_bsize * Stat^.f_bavail; fd := setmntent(_PATH_MOUNTED, 'r'); @@ -1017,7 +995,7 @@ begin fclose(fd); end; end; - Libc.free(Stat); + libc_free(Stat); except on E: Exception do DebugMsg(['*** Exception raised in TLocalTreeEngine.GetFileSystemInfo(APath=', APath, '): (', E.ClassName, '): ', E.Message]); end; @@ -1034,7 +1012,7 @@ begin omAppend: m := 'a'; else m := 'r'; end; - Result := Libc.fopen64(PChar(APath), m); + Result := fopen64(PChar(APath), m); if Result = nil then Error := errno; end; @@ -1042,7 +1020,7 @@ end; function TLocalTreeEngine.ReadFile(const FileDescriptor: TEngineFileDes; Buffer: Pointer; ABlockSize: integer; var Error: integer): integer; begin Error := 0; - Result := Libc.fread(Buffer, 1, ABlockSize, FileDescriptor); + Result := fread(Buffer, 1, ABlockSize, FileDescriptor); if (Result = 0) and (feof(FileDescriptor) = 0) then Error := errno; end; @@ -1050,16 +1028,16 @@ end; function TLocalTreeEngine.WriteFile(const FileDescriptor: TEngineFileDes; Buffer: Pointer; BytesCount: integer; var Error: integer): integer; begin Error := 0; -{ Result := Libc.__write(fileno(FileDescriptor), Buffer^, BytesCount); +{ Result := __write(fileno(FileDescriptor), Buffer^, BytesCount); if Result < BytesCount then Error := errno; } - Result := Libc.fwrite(Buffer, 1, BytesCount, FileDescriptor); + Result := fwrite(Buffer, 1, BytesCount, FileDescriptor); if Result < BytesCount then Error := ferror(FileDescriptor); end; (********************************************************************************************************************************) function TLocalTreeEngine.CloseFile(const FileDescriptor: TEngineFileDes): integer; begin - Result := Libc.fclose(FileDescriptor); + Result := fclose(FileDescriptor); if Result <> 0 then Result := errno; end; @@ -1067,21 +1045,21 @@ end; function TLocalTreeEngine.FileSeek(const FileDescriptor: TEngineFileDes; const AbsoluteOffset: Int64; var Error: integer): Int64; begin Error := 0; - Result := Libc.fseeko64(FileDescriptor, AbsoluteOffset, SEEK_SET); + Result := fseeko64(FileDescriptor, AbsoluteOffset, SEEK_SET); if Result = -1 then Error := errno; end; (********************************************************************************************************************************) function TLocalTreeEngine.IsOnROMedium(const FileName: string): boolean; -var Stat: PGlibc_statfs64; +var Stat: Pstatfs64; begin Result := False; try - Stat := Libc.malloc(sizeof(TGlibc_statfs64)); - Libc.memset(Stat, 0, sizeof(TGlibc_statfs64)); - if glibc_statfs64(PChar(FileName), Stat) <> 0 then Exit; + Stat := malloc(sizeof(Tstatfs64)); + memset(Stat, 0, sizeof(Tstatfs64)); + if statfs64(PChar(FileName), Stat) <> 0 then Exit; Result := (Stat^.f_type = $9660); { ISOFS_SUPER_MAGIC } - Libc.free(Stat); + libc_free(Stat); except on E: Exception do DebugMsg(['*** TLocalTreeEngine.IsOnROMedium(FileName=', FileName, ') -Exception: ', E.Message]); end; @@ -1090,7 +1068,7 @@ end; (********************************************************************************************************************************) function TLocalTreeEngine.FileCanRun(const FileName: string): boolean; begin - Result := Libc.access(PChar(FileName), R_OK or X_OK) = 0; + Result := access(PChar(FileName), R_OK or X_OK) = 0; end; (********************************************************************************************************************************) @@ -1107,19 +1085,19 @@ end; (********************************************************************************************************************************) function TLocalTreeEngine.TwoSameFiles(const Path1, Path2: string): boolean; -var st1, st2: PGlibc_stat64; +var st1, st2: Pstat64; begin Result := False; - st1 := Libc.malloc(sizeof(TGlibc_stat64)); - st2 := Libc.malloc(sizeof(TGlibc_stat64)); - Libc.memset(st1, 0, sizeof(TGlibc_stat64)); - Libc.memset(st2, 0, sizeof(TGlibc_stat64)); - if glibc_lstat64(PChar(Path1), st1) <> 0 then Exit; - if glibc_lstat64(PChar(Path2), st2) <> 0 then Exit; + st1 := malloc(sizeof(Tstat64)); + st2 := malloc(sizeof(Tstat64)); + memset(st1, 0, sizeof(Tstat64)); + memset(st2, 0, sizeof(Tstat64)); + if lstat64(PChar(Path1), st1) <> 0 then Exit; + if lstat64(PChar(Path2), st2) <> 0 then Exit; // DebugMsg(['*** TLocalTreeEngine.TwoSameFiles: ', st1^.st_ino, ' ', st2^.st_ino]); Result := st1^.st_ino = st2^.st_ino; - Libc.free(st1); - Libc.free(st2); + libc_free(st1); + libc_free(st2); end; @@ -1130,12 +1108,12 @@ begin try if Assigned(DataItem) then begin with DataItem^ do begin - if FName <> nil then Libc.free(FName); - if FDisplayName <> nil then Libc.free(FDisplayName); + if FName <> nil then libc_free(FName); + if FDisplayName <> nil then libc_free(FDisplayName); // if Assigned(ADestination) then Dispose(ADestination); - if LnkPointTo <> nil then Libc.free(LnkPointTo); + if LnkPointTo <> nil then libc_free(LnkPointTo); end; - Libc.free(DataItem); + libc_free(DataItem); end; except end; @@ -1147,13 +1125,13 @@ begin try if Assigned(DataItem) then begin with DataItem^ do begin - if FName <> nil then Libc.free(FName); - if FDisplayName <> nil then Libc.free(FDisplayName); - if LnkPointTo <> nil then Libc.free(LnkPointTo); + if FName <> nil then libc_free(FName); + if FDisplayName <> nil then libc_free(FDisplayName); + if LnkPointTo <> nil then libc_free(LnkPointTo); for i := 0 to Length(ColumnData) - 1 do - if ColumnData[i] <> nil then Libc.free(ColumnData[i]); + if ColumnData[i] <> nil then libc_free(ColumnData[i]); end; - Libc.free(DataItem); + libc_free(DataItem); end; except end; |
