From c9a02bf590248c0bd8e1343198d3f9c13ce118c1 Mon Sep 17 00:00:00 2001 From: Tomas Bzatek Date: Sat, 14 Jun 2008 18:34:02 +0200 Subject: Port to new ULibc unit, drop dependency to compiler Libc library (preparation for PPC port) --- vfs/UVFSCore.pas | 90 +++++++++++++++++++++++++++----------------------------- 1 file changed, 44 insertions(+), 46 deletions(-) (limited to 'vfs') diff --git a/vfs/UVFSCore.pas b/vfs/UVFSCore.pas index ded912a..5ca80d5 100644 --- a/vfs/UVFSCore.pas +++ b/vfs/UVFSCore.pas @@ -25,7 +25,7 @@ unit UVFSCore; interface -uses GTKForms, Libc, {$IFDEF KYLIX}UGlibC_compat,{$ENDIF} Classes, uVFSprototypes, UEngines, UCoreUtils; +uses GTKForms, ULibc, Classes, uVFSprototypes, UEngines, UCoreUtils; type @@ -295,11 +295,11 @@ begin ArchiveMode := False; BreakProcessingKind := 0; if @FSourcePlugin.FVFSAllocNeeded <> nil then begin - FGlobs := Libc.malloc(FSourcePlugin.FVFSAllocNeeded); - Libc.memset(FGlobs, 0, FSourcePlugin.FVFSAllocNeeded); + FGlobs := malloc(FSourcePlugin.FVFSAllocNeeded); + memset(FGlobs, 0, FSourcePlugin.FVFSAllocNeeded); end else begin - FGlobs := Libc.malloc(SizeOf(FGlobs)); - Libc.memset(FGlobs, 0, SizeOf(FGlobs)); + FGlobs := malloc(SizeOf(FGlobs)); + memset(FGlobs, 0, SizeOf(FGlobs)); end; {$IFNDEF KYLIX} @@ -342,7 +342,7 @@ destructor TVFSEngine.Destroy; begin try if @FSourcePlugin.FVFSDestroy <> nil then FSourcePlugin.FVFSDestroy(FGlobs); - libc.free(FGlobs); + libc_free(FGlobs); except on E: Exception do DebugMsg(['*** TVFSEngine.Destroy() -Exception: ', E.Message]); end; @@ -357,8 +357,8 @@ begin Result := 0; try if @FSourcePlugin.FVFSListFirst = nil then Exit; - P := Libc.malloc(SizeOf(TVFSItem)); - Libc.memset(P, 0, SizeOf(TVFSItem)); + P := malloc(SizeOf(TVFSItem)); + memset(P, 0, SizeOf(TVFSItem)); // DebugMsg(['Item = ', Int64(P)]); // DebugMsg(['FVFSListFirst']); Res := FSourcePlugin.FVFSListFirst(FGlobs, PChar(APath), P); @@ -366,7 +366,7 @@ begin FSourcePlugin.FVFSListClose(FGlobs); if Res = cVFS_Not_More_Files then Result := 0 else Result := Res; - Libc.free(P); + libc_free(P); Exit; end; @@ -374,8 +374,8 @@ begin // DebugMsg(['begin--']); if AddDotFiles or (not ((Length(P^.sFileName) > 1) and (P^.sFileName[0] = '.') and (P^.sFileName[1] <> '.'))) then begin // DebugMsg(['Checkpoint 1']); - Item := Libc.malloc(SizeOf(TDataItem)); - Libc.memset(Item, 0, SizeOf(TDataItem)); + Item := malloc(SizeOf(TDataItem)); + memset(Item, 0, SizeOf(TDataItem)); // DebugMsg(['Checkpoint 2']); for i := 0 to Length(Item^.ColumnData) - 1 do Item^.ColumnData[i] := nil; // DebugMsg(['Checkpoint 3']); @@ -418,10 +418,10 @@ begin DebugMsg(['^^VFS (EE): GetListing: Item-Exception: ', E.Message]); end; end; // of if AddDotFiles - Libc.free(P); // Not needed - just zero-erase the memory + libc_free(P); // Not needed - just zero-erase the memory // DebugMsg(['Checkpoint 13']); - P := Libc.malloc(SizeOf(TVFSItem)); - Libc.memset(P, 0, SizeOf(TVFSItem)); + P := malloc(SizeOf(TVFSItem)); + memset(P, 0, SizeOf(TVFSItem)); // DebugMsg(['Item = ', Int64(P)]); // DebugMsg(['Checkpoint 14']); // DebugMsg(['FVFSListNext --begin']); @@ -431,7 +431,7 @@ begin until (Res <> cVFS_OK) or (BreakProcessingKind = 2); if BreakProcessingKind <> 0 then DebugMsg(['^^VFS (WW): GetListing: stopped by BreakProcessing']); - Libc.free(P); + libc_free(P); FSourcePlugin.FVFSListClose(FGlobs); if Res <> cVFS_Not_More_Files then Result := Res; except @@ -449,7 +449,7 @@ end; function TVFSEngine.ExplicitChDir(const NewPath: string): integer; begin - Result := __chdir(PChar(NewPath)); + Result := libc_chdir(PChar(NewPath)); if Result <> 0 then Result := errno; end; @@ -546,11 +546,11 @@ begin if @FSourcePlugin.FVFSFileExists <> nil then begin Result := FSourcePlugin.FVFSFileExists(FGlobs, PChar(FileName), Use_lstat); if Result and (@FSourcePlugin.FVFSFileInfo <> nil) then begin - P := Libc.malloc(SizeOf(TVFSItem)); - Libc.memset(P, 0, SizeOf(TVFSItem)); + P := malloc(SizeOf(TVFSItem)); + memset(P, 0, SizeOf(TVFSItem)); Res := FSourcePlugin.FVFSFileInfo(FGlobs, PChar(FileName), P); if (Res <> cVFS_OK) or (P = nil) or (TVFSItemType(P^.ItemType) <> vDirectory) then Result := False; - Libc.free(P); + libc_free(P); end; end else Result := False; end; @@ -562,8 +562,8 @@ var P: PVFSItem; begin Result := nil; if @FSourcePlugin.FVFSFileInfo = nil then Exit; - P := Libc.malloc(SizeOf(TVFSItem)); - Libc.memset(P, 0, SizeOf(TVFSItem)); + P := malloc(SizeOf(TVFSItem)); + memset(P, 0, SizeOf(TVFSItem)); Res := FSourcePlugin.FVFSFileInfo(FGlobs, PChar(APath), P); if Res <> cVFS_OK then begin @@ -572,8 +572,8 @@ begin end; try - 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 := strdup(P^.sFileName); FDisplayName := StrToUTF8(P^.sFileName); @@ -594,7 +594,7 @@ begin UID := P^.iUID; GID := P^.iGID; Size := P^.iSize; - Libc.free(P); + libc_free(P); end; Result := Item; except @@ -630,11 +630,11 @@ var Item: PDataItemSL; procedure AddEntry(FPath: string; AddCurrDirStage, AStage1: boolean); begin - Item := Libc.malloc(SizeOf(TDataItemSL)); - Libc.memset(Item, 0, SizeOf(TDataItemSL)); + Item := malloc(SizeOf(TDataItemSL)); + memset(Item, 0, SizeOf(TDataItemSL)); with Item^ do begin -// AName := Libc.malloc(Length(FPath) + 1); -// Libc.memset(AName, 0, Length(FPath) + 1); +// AName := malloc(Length(FPath) + 1); +// memset(AName, 0, Length(FPath) + 1); FName := strdup(PChar(FPath)); FDisplayName := StrToUTF8(PChar(FPath)); if P^.sLinkTo <> nil then LnkPointTo := strdup(P^.sLinkTo) @@ -654,9 +654,7 @@ var Item: PDataItemSL; UID := P^.iUID; GID := P^.iGID; Size := P^.iSize; - {$WARNINGS OFF} Level := ALevel + Ord(not AddCurrDirStage); - {$WARNINGS ON} end; if AddCurrDirStage then List.Add(Item) else FilesList.Add(Item); @@ -668,12 +666,12 @@ begin LocalList := TStringList.Create; try try - P := Libc.malloc(SizeOf(TVFSItem)); - Libc.memset(P, 0, SizeOf(TVFSItem)); + P := malloc(SizeOf(TVFSItem)); + memset(P, 0, SizeOf(TVFSItem)); Res := FSourcePlugin.FVFSFileInfo(FGlobs, PChar(APath), P); if Res <> cVFS_OK then DebugMsg(['*** FillDirFiles - VFSFileInfo(', APath, ') failed. Code = ', Res]); AddEntry(APath, True, True); - Libc.free(P); + libc_free(P); APath := IncludeTrailingPathDelimiter(APath); if @FSourcePlugin.FVFSChangeDir <> nil then Res := FSourcePlugin.FVFSChangeDir(FGlobs, PChar(APath)) @@ -681,12 +679,12 @@ begin if Res <> 0 then Exit; if @FSourcePlugin.FVFSListFirst = nil then Exit; - P := Libc.malloc(SizeOf(TVFSItem)); - Libc.memset(P, 0, SizeOf(TVFSItem)); + P := malloc(SizeOf(TVFSItem)); + memset(P, 0, SizeOf(TVFSItem)); Res := FSourcePlugin.FVFSListFirst(FGlobs, PChar(APath), P); if Res <> cVFS_OK then begin FSourcePlugin.FVFSListClose(FGlobs); - Libc.free(P); + libc_free(P); Exit; end; @@ -694,13 +692,13 @@ begin if TVFSItemType(P^.ItemType) = vDirectory then LocalList.Add(APath + String(P^.sFileName)) else AddEntry(APath + String(P^.sFileName), False, True); - Libc.free(P); - P := Libc.malloc(SizeOf(TVFSItem)); - Libc.memset(P, 0, SizeOf(TVFSItem)); + libc_free(P); + P := malloc(SizeOf(TVFSItem)); + memset(P, 0, SizeOf(TVFSItem)); Res := FSourcePlugin.FVFSListNext(FGlobs, PChar(GetPath), P); until (Res <> cVFS_OK); - Libc.free(P); + libc_free(P); FSourcePlugin.FVFSListClose(FGlobs); {$WARNINGS OFF} @@ -716,12 +714,12 @@ begin on E: Exception do DebugMsg(['*** TVFSEngine.FillDirFiles(APath=', APath, ', Level=', ALevel, ') -Exception: ', E.Message]); end; finally - P := Libc.malloc(SizeOf(TVFSItem)); - Libc.memset(P, 0, SizeOf(TVFSItem)); + P := malloc(SizeOf(TVFSItem)); + memset(P, 0, SizeOf(TVFSItem)); Res := FSourcePlugin.FVFSFileInfo(FGlobs, PChar(APath), P); if Res <> cVFS_OK then DebugMsg(['*** FillDirFiles - VFSFileInfo(', APath, ') failed. Code = ', Res]); AddEntry(APath, True, False); - Libc.free(P); + libc_free(P); LocalList.Free; FilesList.Free; @@ -959,7 +957,7 @@ end; procedure QueryModules(APath: string); -var Handle: PDirectoryStream; +var Handle: PDIR; DirEnt: PDirent64; s: string; PluginItem: TVFSPlugin; @@ -979,7 +977,7 @@ begin if APath[1] <> '/' then begin s := ExtractFilePath(BinaryPath); DebugMsg(['----> Changing dir to ', s]); - i := __chdir(PChar(s)); + i := libc_chdir(PChar(s)); if i <> 0 then DebugMsg(['Something went wrong during chdir: ', string(strerror(errno))]); s := get_current_dir_name; DebugMsg([' [II] Changed dir to ', s]); @@ -988,7 +986,7 @@ begin // Change to the required directory s := APath; DebugMsg(['----> Changing dir to ', s]); - i := __chdir(PChar(s)); + i := libc_chdir(PChar(s)); if i <> 0 then begin DebugMsg(['Something went wrong during chdir: ', string(strerror(errno))]); Exit; -- cgit v1.2.3