mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-19 23:19:24 +02:00
Added file calls. Implemented for linux only
This commit is contained in:
parent
af1ccc6f61
commit
844f30a84c
237
rtl/dos/go32v1/filutil.inc
Normal file
237
rtl/dos/go32v1/filutil.inc
Normal file
@ -0,0 +1,237 @@
|
||||
{
|
||||
$Id$
|
||||
This file is part of the Free Pascal run time library.
|
||||
Copyright (c) 1998 by the Free Pascal development team
|
||||
|
||||
File utility calls
|
||||
|
||||
See the file COPYING.FPC, included in this distribution,
|
||||
for details about the copyright.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
**********************************************************************}
|
||||
|
||||
|
||||
Function FileOpen (Const FileName : string; Mode : Integer) : Longint;
|
||||
|
||||
Var LinuxFlags : longint;
|
||||
|
||||
BEGIN
|
||||
LinuxFlags:=0;
|
||||
Case (Mode and 3) of
|
||||
0 : LinuxFlags:=LinuxFlags or Open_RdOnly;
|
||||
1 : LinuxFlags:=LinuxFlags or Open_WrOnly;
|
||||
2 : LinuxFlags:=LinuxFlags or Open_RdWr;
|
||||
end;
|
||||
FileOpen:=fdOpen (FileName,LinuxFlags);
|
||||
//!! We need to set locking based on Mode !!
|
||||
end;
|
||||
|
||||
|
||||
Function FileCreate (Const FileName : String) : Longint;
|
||||
|
||||
begin
|
||||
FileCreate:=FileOpen (FileName,Open_RdWr or Open_Creat);
|
||||
end;
|
||||
|
||||
|
||||
Function FileRead (Handle : Longint; Var Buffer; Count : longint) : Longint;
|
||||
|
||||
begin
|
||||
FileRead:=fdRead (Handle,Buffer,Count);
|
||||
end;
|
||||
|
||||
|
||||
Function FileWrite (Handle : Longint; Var Buffer; Count : Longint) : Longint;
|
||||
|
||||
begin
|
||||
FileWrite:=fdWrite (Handle,Buffer,Count);
|
||||
end;
|
||||
|
||||
|
||||
Function FileSeek (Handle,Offset,Origin : Longint) : Longint;
|
||||
|
||||
begin
|
||||
FileSeek:=fdSeek (Handle,Offset,Origin);
|
||||
end;
|
||||
|
||||
|
||||
Procedure FileClose (Handle : Longint);
|
||||
|
||||
begin
|
||||
fdclose(Handle);
|
||||
end;
|
||||
|
||||
|
||||
Function FileAge (Const FileName : String): Longint;
|
||||
|
||||
Var Info : Stat;
|
||||
|
||||
begin
|
||||
If not fstat (FileName,Info) then
|
||||
exit(-1)
|
||||
else
|
||||
Exit (Info.mtime);
|
||||
end;
|
||||
|
||||
|
||||
Function FileExists (Const FileName : String) : Boolean;
|
||||
|
||||
Var Info : Stat;
|
||||
|
||||
begin
|
||||
FileExists:=fstat(filename,Info);
|
||||
end;
|
||||
|
||||
Function LinuxToWinAttr (FN : Char; Const Info : Stat) : Longint;
|
||||
|
||||
begin
|
||||
Result:=0;
|
||||
If FN='.' then
|
||||
Result:=Result or faHidden;
|
||||
If (Info.Mode and STAT_IFDIR)=STAT_IFDIR then
|
||||
Result:=Result or faDirectory;
|
||||
If (Info.Mode and STAT_IWUSR)=0 Then
|
||||
Result:=Result or faReadOnly;
|
||||
end;
|
||||
|
||||
{
|
||||
GlobToSearch takes a glob entry, stats the file.
|
||||
The glob entry is removed.
|
||||
If FileAttributes match, the entry is reused
|
||||
}
|
||||
|
||||
Function GlobToTSearchRec (Info : TSearchRec) : Boolean;
|
||||
|
||||
Var SInfo : Stat;
|
||||
p : Pglob;
|
||||
TAttr : Longint;
|
||||
|
||||
begin
|
||||
P:=pglob(Info.FindHandle);
|
||||
Result:=Fstat(p^.name,SInfo);
|
||||
Info.FindHandle:=Longint(P^.Next);
|
||||
P^.Next:=Nil;
|
||||
GlobFree(P);
|
||||
If Result then
|
||||
begin
|
||||
Info.Attr:=LinuxToWinAttr(p^.name[0],SInfo);
|
||||
Result:=(Info.ExcludeAttr and TAttr)<>0 ;
|
||||
If Result Then
|
||||
With Info do
|
||||
begin
|
||||
Attr:=Info.Attr;
|
||||
Name:=strpas(p^.name);
|
||||
Time:=Sinfo.mtime;
|
||||
Size:=Sinfo.Size;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
Function DoFind(Var Rslt : TSearchRec) : Longint;
|
||||
|
||||
begin
|
||||
If Rslt.FindHandle<>0 then
|
||||
While (Rslt.FindHandle<>0) and GlobToTSearchRec(Rslt) do;
|
||||
If Rslt.FindHandle=0 Then
|
||||
Result:=-1
|
||||
else
|
||||
Result:=0;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
Function FindFirst (Const Path : String; Attr : Longint; Var Rslt : TSearchRec) : Longint;
|
||||
|
||||
begin
|
||||
Rslt.ExcludeAttr:=Attr; //!! Not correct !!
|
||||
Rslt.FindHandle:=Longint(Glob(Path));
|
||||
Result:=DoFind (Rslt);
|
||||
end;
|
||||
|
||||
|
||||
Function FindNext (Var Rslt : TSearchRec) : Longint;
|
||||
|
||||
begin
|
||||
Result:=DoFind (Rslt);
|
||||
end;
|
||||
|
||||
|
||||
Procedure FindClose (Var F : TSearchrec);
|
||||
|
||||
begin
|
||||
GlobFree (PGlob(F.FindHandle));
|
||||
end;
|
||||
|
||||
|
||||
Function FileGetDate (Handle : Longint) : Longint;
|
||||
|
||||
Var Info : Stat;
|
||||
|
||||
begin
|
||||
If Not(FStat(Handle,Info)) then
|
||||
Result:=-1
|
||||
else
|
||||
Result:=Info.Mtime;
|
||||
end;
|
||||
|
||||
|
||||
Function FileSetDate (Handle,Age : Longint) : Longint;
|
||||
|
||||
begin
|
||||
// Impossible under Linux from FileHandle !!
|
||||
FileSetDate:=-1;
|
||||
end;
|
||||
|
||||
|
||||
Function FileGetAttr (Const FileName : String) : Longint;
|
||||
|
||||
Var Info : Stat;
|
||||
|
||||
begin
|
||||
If Not FStat (FileName,Info) then
|
||||
Result:=-1
|
||||
Else
|
||||
Result:=LinuxToWinAttr(FileName[1],Info);
|
||||
end;
|
||||
|
||||
|
||||
Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
|
||||
|
||||
begin
|
||||
//!! Still Needs doing
|
||||
end;
|
||||
|
||||
|
||||
Function DeleteFile (Const FileName : String) : Boolean;
|
||||
|
||||
begin
|
||||
Result:=UnLink (FileName);
|
||||
end;
|
||||
|
||||
|
||||
Function RenameFile (Const OldName, NewName : String) : Boolean;
|
||||
|
||||
Var P1,P2 : String;
|
||||
|
||||
begin
|
||||
RenameFile:=Linux.Rename(OldNAme,NewName);
|
||||
end;
|
||||
|
||||
|
||||
Function FileSearch (Const Name, DirList : String) : String;
|
||||
|
||||
begin
|
||||
FileSearch:=Linux.FSearch(Name,Dirlist);
|
||||
end;
|
||||
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.1 1998-10-11 12:21:01 michael
|
||||
Added file calls. Implemented for linux only
|
||||
|
||||
}
|
237
rtl/dos/go32v2/filutil.inc
Normal file
237
rtl/dos/go32v2/filutil.inc
Normal file
@ -0,0 +1,237 @@
|
||||
{
|
||||
$Id$
|
||||
This file is part of the Free Pascal run time library.
|
||||
Copyright (c) 1998 by the Free Pascal development team
|
||||
|
||||
File utility calls
|
||||
|
||||
See the file COPYING.FPC, included in this distribution,
|
||||
for details about the copyright.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
**********************************************************************}
|
||||
|
||||
|
||||
Function FileOpen (Const FileName : string; Mode : Integer) : Longint;
|
||||
|
||||
Var LinuxFlags : longint;
|
||||
|
||||
BEGIN
|
||||
LinuxFlags:=0;
|
||||
Case (Mode and 3) of
|
||||
0 : LinuxFlags:=LinuxFlags or Open_RdOnly;
|
||||
1 : LinuxFlags:=LinuxFlags or Open_WrOnly;
|
||||
2 : LinuxFlags:=LinuxFlags or Open_RdWr;
|
||||
end;
|
||||
FileOpen:=fdOpen (FileName,LinuxFlags);
|
||||
//!! We need to set locking based on Mode !!
|
||||
end;
|
||||
|
||||
|
||||
Function FileCreate (Const FileName : String) : Longint;
|
||||
|
||||
begin
|
||||
FileCreate:=FileOpen (FileName,Open_RdWr or Open_Creat);
|
||||
end;
|
||||
|
||||
|
||||
Function FileRead (Handle : Longint; Var Buffer; Count : longint) : Longint;
|
||||
|
||||
begin
|
||||
FileRead:=fdRead (Handle,Buffer,Count);
|
||||
end;
|
||||
|
||||
|
||||
Function FileWrite (Handle : Longint; Var Buffer; Count : Longint) : Longint;
|
||||
|
||||
begin
|
||||
FileWrite:=fdWrite (Handle,Buffer,Count);
|
||||
end;
|
||||
|
||||
|
||||
Function FileSeek (Handle,Offset,Origin : Longint) : Longint;
|
||||
|
||||
begin
|
||||
FileSeek:=fdSeek (Handle,Offset,Origin);
|
||||
end;
|
||||
|
||||
|
||||
Procedure FileClose (Handle : Longint);
|
||||
|
||||
begin
|
||||
fdclose(Handle);
|
||||
end;
|
||||
|
||||
|
||||
Function FileAge (Const FileName : String): Longint;
|
||||
|
||||
Var Info : Stat;
|
||||
|
||||
begin
|
||||
If not fstat (FileName,Info) then
|
||||
exit(-1)
|
||||
else
|
||||
Exit (Info.mtime);
|
||||
end;
|
||||
|
||||
|
||||
Function FileExists (Const FileName : String) : Boolean;
|
||||
|
||||
Var Info : Stat;
|
||||
|
||||
begin
|
||||
FileExists:=fstat(filename,Info);
|
||||
end;
|
||||
|
||||
Function LinuxToWinAttr (FN : Char; Const Info : Stat) : Longint;
|
||||
|
||||
begin
|
||||
Result:=0;
|
||||
If FN='.' then
|
||||
Result:=Result or faHidden;
|
||||
If (Info.Mode and STAT_IFDIR)=STAT_IFDIR then
|
||||
Result:=Result or faDirectory;
|
||||
If (Info.Mode and STAT_IWUSR)=0 Then
|
||||
Result:=Result or faReadOnly;
|
||||
end;
|
||||
|
||||
{
|
||||
GlobToSearch takes a glob entry, stats the file.
|
||||
The glob entry is removed.
|
||||
If FileAttributes match, the entry is reused
|
||||
}
|
||||
|
||||
Function GlobToTSearchRec (Info : TSearchRec) : Boolean;
|
||||
|
||||
Var SInfo : Stat;
|
||||
p : Pglob;
|
||||
TAttr : Longint;
|
||||
|
||||
begin
|
||||
P:=pglob(Info.FindHandle);
|
||||
Result:=Fstat(p^.name,SInfo);
|
||||
Info.FindHandle:=Longint(P^.Next);
|
||||
P^.Next:=Nil;
|
||||
GlobFree(P);
|
||||
If Result then
|
||||
begin
|
||||
Info.Attr:=LinuxToWinAttr(p^.name[0],SInfo);
|
||||
Result:=(Info.ExcludeAttr and TAttr)<>0 ;
|
||||
If Result Then
|
||||
With Info do
|
||||
begin
|
||||
Attr:=Info.Attr;
|
||||
Name:=strpas(p^.name);
|
||||
Time:=Sinfo.mtime;
|
||||
Size:=Sinfo.Size;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
Function DoFind(Var Rslt : TSearchRec) : Longint;
|
||||
|
||||
begin
|
||||
If Rslt.FindHandle<>0 then
|
||||
While (Rslt.FindHandle<>0) and GlobToTSearchRec(Rslt) do;
|
||||
If Rslt.FindHandle=0 Then
|
||||
Result:=-1
|
||||
else
|
||||
Result:=0;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
Function FindFirst (Const Path : String; Attr : Longint; Var Rslt : TSearchRec) : Longint;
|
||||
|
||||
begin
|
||||
Rslt.ExcludeAttr:=Attr; //!! Not correct !!
|
||||
Rslt.FindHandle:=Longint(Glob(Path));
|
||||
Result:=DoFind (Rslt);
|
||||
end;
|
||||
|
||||
|
||||
Function FindNext (Var Rslt : TSearchRec) : Longint;
|
||||
|
||||
begin
|
||||
Result:=DoFind (Rslt);
|
||||
end;
|
||||
|
||||
|
||||
Procedure FindClose (Var F : TSearchrec);
|
||||
|
||||
begin
|
||||
GlobFree (PGlob(F.FindHandle));
|
||||
end;
|
||||
|
||||
|
||||
Function FileGetDate (Handle : Longint) : Longint;
|
||||
|
||||
Var Info : Stat;
|
||||
|
||||
begin
|
||||
If Not(FStat(Handle,Info)) then
|
||||
Result:=-1
|
||||
else
|
||||
Result:=Info.Mtime;
|
||||
end;
|
||||
|
||||
|
||||
Function FileSetDate (Handle,Age : Longint) : Longint;
|
||||
|
||||
begin
|
||||
// Impossible under Linux from FileHandle !!
|
||||
FileSetDate:=-1;
|
||||
end;
|
||||
|
||||
|
||||
Function FileGetAttr (Const FileName : String) : Longint;
|
||||
|
||||
Var Info : Stat;
|
||||
|
||||
begin
|
||||
If Not FStat (FileName,Info) then
|
||||
Result:=-1
|
||||
Else
|
||||
Result:=LinuxToWinAttr(FileName[1],Info);
|
||||
end;
|
||||
|
||||
|
||||
Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
|
||||
|
||||
begin
|
||||
//!! Still Needs doing
|
||||
end;
|
||||
|
||||
|
||||
Function DeleteFile (Const FileName : String) : Boolean;
|
||||
|
||||
begin
|
||||
Result:=UnLink (FileName);
|
||||
end;
|
||||
|
||||
|
||||
Function RenameFile (Const OldName, NewName : String) : Boolean;
|
||||
|
||||
Var P1,P2 : String;
|
||||
|
||||
begin
|
||||
RenameFile:=Linux.Rename(OldNAme,NewName);
|
||||
end;
|
||||
|
||||
|
||||
Function FileSearch (Const Name, DirList : String) : String;
|
||||
|
||||
begin
|
||||
FileSearch:=Linux.FSearch(Name,Dirlist);
|
||||
end;
|
||||
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.1 1998-10-11 12:21:01 michael
|
||||
Added file calls. Implemented for linux only
|
||||
|
||||
}
|
237
rtl/linux/filutil.inc
Normal file
237
rtl/linux/filutil.inc
Normal file
@ -0,0 +1,237 @@
|
||||
{
|
||||
$Id$
|
||||
This file is part of the Free Pascal run time library.
|
||||
Copyright (c) 1998 by the Free Pascal development team
|
||||
|
||||
File utility calls
|
||||
|
||||
See the file COPYING.FPC, included in this distribution,
|
||||
for details about the copyright.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
**********************************************************************}
|
||||
|
||||
|
||||
Function FileOpen (Const FileName : string; Mode : Integer) : Longint;
|
||||
|
||||
Var LinuxFlags : longint;
|
||||
|
||||
BEGIN
|
||||
LinuxFlags:=0;
|
||||
Case (Mode and 3) of
|
||||
0 : LinuxFlags:=LinuxFlags or Open_RdOnly;
|
||||
1 : LinuxFlags:=LinuxFlags or Open_WrOnly;
|
||||
2 : LinuxFlags:=LinuxFlags or Open_RdWr;
|
||||
end;
|
||||
FileOpen:=fdOpen (FileName,LinuxFlags);
|
||||
//!! We need to set locking based on Mode !!
|
||||
end;
|
||||
|
||||
|
||||
Function FileCreate (Const FileName : String) : Longint;
|
||||
|
||||
begin
|
||||
FileCreate:=FileOpen (FileName,Open_RdWr or Open_Creat);
|
||||
end;
|
||||
|
||||
|
||||
Function FileRead (Handle : Longint; Var Buffer; Count : longint) : Longint;
|
||||
|
||||
begin
|
||||
FileRead:=fdRead (Handle,Buffer,Count);
|
||||
end;
|
||||
|
||||
|
||||
Function FileWrite (Handle : Longint; Var Buffer; Count : Longint) : Longint;
|
||||
|
||||
begin
|
||||
FileWrite:=fdWrite (Handle,Buffer,Count);
|
||||
end;
|
||||
|
||||
|
||||
Function FileSeek (Handle,Offset,Origin : Longint) : Longint;
|
||||
|
||||
begin
|
||||
FileSeek:=fdSeek (Handle,Offset,Origin);
|
||||
end;
|
||||
|
||||
|
||||
Procedure FileClose (Handle : Longint);
|
||||
|
||||
begin
|
||||
fdclose(Handle);
|
||||
end;
|
||||
|
||||
|
||||
Function FileAge (Const FileName : String): Longint;
|
||||
|
||||
Var Info : Stat;
|
||||
|
||||
begin
|
||||
If not fstat (FileName,Info) then
|
||||
exit(-1)
|
||||
else
|
||||
Exit (Info.mtime);
|
||||
end;
|
||||
|
||||
|
||||
Function FileExists (Const FileName : String) : Boolean;
|
||||
|
||||
Var Info : Stat;
|
||||
|
||||
begin
|
||||
FileExists:=fstat(filename,Info);
|
||||
end;
|
||||
|
||||
Function LinuxToWinAttr (FN : Char; Const Info : Stat) : Longint;
|
||||
|
||||
begin
|
||||
Result:=0;
|
||||
If FN='.' then
|
||||
Result:=Result or faHidden;
|
||||
If (Info.Mode and STAT_IFDIR)=STAT_IFDIR then
|
||||
Result:=Result or faDirectory;
|
||||
If (Info.Mode and STAT_IWUSR)=0 Then
|
||||
Result:=Result or faReadOnly;
|
||||
end;
|
||||
|
||||
{
|
||||
GlobToSearch takes a glob entry, stats the file.
|
||||
The glob entry is removed.
|
||||
If FileAttributes match, the entry is reused
|
||||
}
|
||||
|
||||
Function GlobToTSearchRec (Info : TSearchRec) : Boolean;
|
||||
|
||||
Var SInfo : Stat;
|
||||
p : Pglob;
|
||||
TAttr : Longint;
|
||||
|
||||
begin
|
||||
P:=pglob(Info.FindHandle);
|
||||
Result:=Fstat(p^.name,SInfo);
|
||||
Info.FindHandle:=Longint(P^.Next);
|
||||
P^.Next:=Nil;
|
||||
GlobFree(P);
|
||||
If Result then
|
||||
begin
|
||||
Info.Attr:=LinuxToWinAttr(p^.name[0],SInfo);
|
||||
Result:=(Info.ExcludeAttr and TAttr)<>0 ;
|
||||
If Result Then
|
||||
With Info do
|
||||
begin
|
||||
Attr:=Info.Attr;
|
||||
Name:=strpas(p^.name);
|
||||
Time:=Sinfo.mtime;
|
||||
Size:=Sinfo.Size;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
Function DoFind(Var Rslt : TSearchRec) : Longint;
|
||||
|
||||
begin
|
||||
If Rslt.FindHandle<>0 then
|
||||
While (Rslt.FindHandle<>0) and GlobToTSearchRec(Rslt) do;
|
||||
If Rslt.FindHandle=0 Then
|
||||
Result:=-1
|
||||
else
|
||||
Result:=0;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
Function FindFirst (Const Path : String; Attr : Longint; Var Rslt : TSearchRec) : Longint;
|
||||
|
||||
begin
|
||||
Rslt.ExcludeAttr:=Attr; //!! Not correct !!
|
||||
Rslt.FindHandle:=Longint(Glob(Path));
|
||||
Result:=DoFind (Rslt);
|
||||
end;
|
||||
|
||||
|
||||
Function FindNext (Var Rslt : TSearchRec) : Longint;
|
||||
|
||||
begin
|
||||
Result:=DoFind (Rslt);
|
||||
end;
|
||||
|
||||
|
||||
Procedure FindClose (Var F : TSearchrec);
|
||||
|
||||
begin
|
||||
GlobFree (PGlob(F.FindHandle));
|
||||
end;
|
||||
|
||||
|
||||
Function FileGetDate (Handle : Longint) : Longint;
|
||||
|
||||
Var Info : Stat;
|
||||
|
||||
begin
|
||||
If Not(FStat(Handle,Info)) then
|
||||
Result:=-1
|
||||
else
|
||||
Result:=Info.Mtime;
|
||||
end;
|
||||
|
||||
|
||||
Function FileSetDate (Handle,Age : Longint) : Longint;
|
||||
|
||||
begin
|
||||
// Impossible under Linux from FileHandle !!
|
||||
FileSetDate:=-1;
|
||||
end;
|
||||
|
||||
|
||||
Function FileGetAttr (Const FileName : String) : Longint;
|
||||
|
||||
Var Info : Stat;
|
||||
|
||||
begin
|
||||
If Not FStat (FileName,Info) then
|
||||
Result:=-1
|
||||
Else
|
||||
Result:=LinuxToWinAttr(FileName[1],Info);
|
||||
end;
|
||||
|
||||
|
||||
Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
|
||||
|
||||
begin
|
||||
//!! Still Needs doing
|
||||
end;
|
||||
|
||||
|
||||
Function DeleteFile (Const FileName : String) : Boolean;
|
||||
|
||||
begin
|
||||
Result:=UnLink (FileName);
|
||||
end;
|
||||
|
||||
|
||||
Function RenameFile (Const OldName, NewName : String) : Boolean;
|
||||
|
||||
Var P1,P2 : String;
|
||||
|
||||
begin
|
||||
RenameFile:=Linux.Rename(OldNAme,NewName);
|
||||
end;
|
||||
|
||||
|
||||
Function FileSearch (Const Name, DirList : String) : String;
|
||||
|
||||
begin
|
||||
FileSearch:=Linux.FSearch(Name,Dirlist);
|
||||
end;
|
||||
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.1 1998-10-11 12:21:01 michael
|
||||
Added file calls. Implemented for linux only
|
||||
|
||||
}
|
66
rtl/objpas/filutilh.inc
Normal file
66
rtl/objpas/filutilh.inc
Normal file
@ -0,0 +1,66 @@
|
||||
{
|
||||
$Id$
|
||||
This file is part of the Free Pascal run time library.
|
||||
Copyright (c) 1998 by the Free Pascal development team
|
||||
|
||||
File utility calls
|
||||
|
||||
See the file COPYING.FPC, included in this distribution,
|
||||
for details about the copyright.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
**********************************************************************}
|
||||
|
||||
{$ifndef win32}
|
||||
Type
|
||||
THandle = Longint; // Needed for TSearchRec
|
||||
{$endif}
|
||||
|
||||
Type
|
||||
TSearchRec = Record
|
||||
Time,Size, Attr : Longint;
|
||||
Name : TFileName;
|
||||
ExcludeAttr : Longint;
|
||||
FindHandle : THandle;
|
||||
{$ifdef Win32}
|
||||
FindData : TWin32FindData;
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
Const
|
||||
faReadOnly = $00000001;
|
||||
faHidden = $00000002;
|
||||
faSysFile = $00000004;
|
||||
faVolumeId = $00000008;
|
||||
faDirectory = $00000010;
|
||||
faArchive = $00000020;
|
||||
faAnyFile = $0000003f;
|
||||
|
||||
Function FileOpen (Const FileName : string; Mode : Integer) : Longint;
|
||||
Function FileCreate (Const FileName : String) : Longint;
|
||||
Function FileRead (Handle : Longint; Var Buffer; Count : longint) : Longint;
|
||||
Function FileWrite (Handle : Longint; Var Buffer; Count : Longint) : Longint;
|
||||
Function FileSeek (Handle,Offset,Origin : Longint) : Longint;
|
||||
Procedure FileClose (Handle : Longint);
|
||||
Function FileAge (Const FileName : String): Longint;
|
||||
Function FileExists (Const FileName : String) : Boolean;
|
||||
Function FindFirst (Const Path : String; Attr : Longint; Var Rslt : TSearchRec) : Longint;
|
||||
Function FindNext (Var Rslt : TSearchRec) : Longint;
|
||||
Procedure FindClose (Var F : TSearchrec);
|
||||
Function FileGetDate (Handle : Longint) : Longint;
|
||||
Function FileSetDate (Handle,Age : Longint) : Longint;
|
||||
Function FileGetAttr (Const FileName : String) : Longint;
|
||||
Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
|
||||
Function DeleteFile (Const FileName : String) : Boolean;
|
||||
Function RenameFile (Const OldName, NewName : String) : Boolean;
|
||||
Function FileSearch (Const Name, DirList : String) : String;
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.1 1998-10-11 12:21:01 michael
|
||||
Added file calls. Implemented for linux only
|
||||
|
||||
}
|
237
rtl/os2/filutil.inc
Normal file
237
rtl/os2/filutil.inc
Normal file
@ -0,0 +1,237 @@
|
||||
{
|
||||
$Id$
|
||||
This file is part of the Free Pascal run time library.
|
||||
Copyright (c) 1998 by the Free Pascal development team
|
||||
|
||||
File utility calls
|
||||
|
||||
See the file COPYING.FPC, included in this distribution,
|
||||
for details about the copyright.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
**********************************************************************}
|
||||
|
||||
|
||||
Function FileOpen (Const FileName : string; Mode : Integer) : Longint;
|
||||
|
||||
Var LinuxFlags : longint;
|
||||
|
||||
BEGIN
|
||||
LinuxFlags:=0;
|
||||
Case (Mode and 3) of
|
||||
0 : LinuxFlags:=LinuxFlags or Open_RdOnly;
|
||||
1 : LinuxFlags:=LinuxFlags or Open_WrOnly;
|
||||
2 : LinuxFlags:=LinuxFlags or Open_RdWr;
|
||||
end;
|
||||
FileOpen:=fdOpen (FileName,LinuxFlags);
|
||||
//!! We need to set locking based on Mode !!
|
||||
end;
|
||||
|
||||
|
||||
Function FileCreate (Const FileName : String) : Longint;
|
||||
|
||||
begin
|
||||
FileCreate:=FileOpen (FileName,Open_RdWr or Open_Creat);
|
||||
end;
|
||||
|
||||
|
||||
Function FileRead (Handle : Longint; Var Buffer; Count : longint) : Longint;
|
||||
|
||||
begin
|
||||
FileRead:=fdRead (Handle,Buffer,Count);
|
||||
end;
|
||||
|
||||
|
||||
Function FileWrite (Handle : Longint; Var Buffer; Count : Longint) : Longint;
|
||||
|
||||
begin
|
||||
FileWrite:=fdWrite (Handle,Buffer,Count);
|
||||
end;
|
||||
|
||||
|
||||
Function FileSeek (Handle,Offset,Origin : Longint) : Longint;
|
||||
|
||||
begin
|
||||
FileSeek:=fdSeek (Handle,Offset,Origin);
|
||||
end;
|
||||
|
||||
|
||||
Procedure FileClose (Handle : Longint);
|
||||
|
||||
begin
|
||||
fdclose(Handle);
|
||||
end;
|
||||
|
||||
|
||||
Function FileAge (Const FileName : String): Longint;
|
||||
|
||||
Var Info : Stat;
|
||||
|
||||
begin
|
||||
If not fstat (FileName,Info) then
|
||||
exit(-1)
|
||||
else
|
||||
Exit (Info.mtime);
|
||||
end;
|
||||
|
||||
|
||||
Function FileExists (Const FileName : String) : Boolean;
|
||||
|
||||
Var Info : Stat;
|
||||
|
||||
begin
|
||||
FileExists:=fstat(filename,Info);
|
||||
end;
|
||||
|
||||
Function LinuxToWinAttr (FN : Char; Const Info : Stat) : Longint;
|
||||
|
||||
begin
|
||||
Result:=0;
|
||||
If FN='.' then
|
||||
Result:=Result or faHidden;
|
||||
If (Info.Mode and STAT_IFDIR)=STAT_IFDIR then
|
||||
Result:=Result or faDirectory;
|
||||
If (Info.Mode and STAT_IWUSR)=0 Then
|
||||
Result:=Result or faReadOnly;
|
||||
end;
|
||||
|
||||
{
|
||||
GlobToSearch takes a glob entry, stats the file.
|
||||
The glob entry is removed.
|
||||
If FileAttributes match, the entry is reused
|
||||
}
|
||||
|
||||
Function GlobToTSearchRec (Info : TSearchRec) : Boolean;
|
||||
|
||||
Var SInfo : Stat;
|
||||
p : Pglob;
|
||||
TAttr : Longint;
|
||||
|
||||
begin
|
||||
P:=pglob(Info.FindHandle);
|
||||
Result:=Fstat(p^.name,SInfo);
|
||||
Info.FindHandle:=Longint(P^.Next);
|
||||
P^.Next:=Nil;
|
||||
GlobFree(P);
|
||||
If Result then
|
||||
begin
|
||||
Info.Attr:=LinuxToWinAttr(p^.name[0],SInfo);
|
||||
Result:=(Info.ExcludeAttr and TAttr)<>0 ;
|
||||
If Result Then
|
||||
With Info do
|
||||
begin
|
||||
Attr:=Info.Attr;
|
||||
Name:=strpas(p^.name);
|
||||
Time:=Sinfo.mtime;
|
||||
Size:=Sinfo.Size;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
Function DoFind(Var Rslt : TSearchRec) : Longint;
|
||||
|
||||
begin
|
||||
If Rslt.FindHandle<>0 then
|
||||
While (Rslt.FindHandle<>0) and GlobToTSearchRec(Rslt) do;
|
||||
If Rslt.FindHandle=0 Then
|
||||
Result:=-1
|
||||
else
|
||||
Result:=0;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
Function FindFirst (Const Path : String; Attr : Longint; Var Rslt : TSearchRec) : Longint;
|
||||
|
||||
begin
|
||||
Rslt.ExcludeAttr:=Attr; //!! Not correct !!
|
||||
Rslt.FindHandle:=Longint(Glob(Path));
|
||||
Result:=DoFind (Rslt);
|
||||
end;
|
||||
|
||||
|
||||
Function FindNext (Var Rslt : TSearchRec) : Longint;
|
||||
|
||||
begin
|
||||
Result:=DoFind (Rslt);
|
||||
end;
|
||||
|
||||
|
||||
Procedure FindClose (Var F : TSearchrec);
|
||||
|
||||
begin
|
||||
GlobFree (PGlob(F.FindHandle));
|
||||
end;
|
||||
|
||||
|
||||
Function FileGetDate (Handle : Longint) : Longint;
|
||||
|
||||
Var Info : Stat;
|
||||
|
||||
begin
|
||||
If Not(FStat(Handle,Info)) then
|
||||
Result:=-1
|
||||
else
|
||||
Result:=Info.Mtime;
|
||||
end;
|
||||
|
||||
|
||||
Function FileSetDate (Handle,Age : Longint) : Longint;
|
||||
|
||||
begin
|
||||
// Impossible under Linux from FileHandle !!
|
||||
FileSetDate:=-1;
|
||||
end;
|
||||
|
||||
|
||||
Function FileGetAttr (Const FileName : String) : Longint;
|
||||
|
||||
Var Info : Stat;
|
||||
|
||||
begin
|
||||
If Not FStat (FileName,Info) then
|
||||
Result:=-1
|
||||
Else
|
||||
Result:=LinuxToWinAttr(FileName[1],Info);
|
||||
end;
|
||||
|
||||
|
||||
Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
|
||||
|
||||
begin
|
||||
//!! Still Needs doing
|
||||
end;
|
||||
|
||||
|
||||
Function DeleteFile (Const FileName : String) : Boolean;
|
||||
|
||||
begin
|
||||
Result:=UnLink (FileName);
|
||||
end;
|
||||
|
||||
|
||||
Function RenameFile (Const OldName, NewName : String) : Boolean;
|
||||
|
||||
Var P1,P2 : String;
|
||||
|
||||
begin
|
||||
RenameFile:=Linux.Rename(OldNAme,NewName);
|
||||
end;
|
||||
|
||||
|
||||
Function FileSearch (Const Name, DirList : String) : String;
|
||||
|
||||
begin
|
||||
FileSearch:=Linux.FSearch(Name,Dirlist);
|
||||
end;
|
||||
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.1 1998-10-11 12:21:01 michael
|
||||
Added file calls. Implemented for linux only
|
||||
|
||||
}
|
149
rtl/win32/filutil.inc
Normal file
149
rtl/win32/filutil.inc
Normal file
@ -0,0 +1,149 @@
|
||||
{
|
||||
$Id$
|
||||
This file is part of the Free Pascal run time library.
|
||||
Copyright (c) 1998 by the Free Pascal development team
|
||||
|
||||
File utility calls
|
||||
|
||||
See the file COPYING.FPC, included in this distribution,
|
||||
for details about the copyright.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
**********************************************************************}
|
||||
|
||||
|
||||
Function FileOpen (Const FileName : string; Mode : Integer) : Longint;
|
||||
|
||||
Begin
|
||||
//!! Needs implementing
|
||||
end;
|
||||
|
||||
|
||||
Function FileCreate (Const FileName : String) : Longint;
|
||||
|
||||
begin
|
||||
//!! Needs implementing
|
||||
end;
|
||||
|
||||
|
||||
Function FileRead (Handle : Longint; Var Buffer; Count : longint) : Longint;
|
||||
|
||||
begin
|
||||
//!! Needs implementing
|
||||
end;
|
||||
|
||||
|
||||
Function FileWrite (Handle : Longint; Var Buffer; Count : Longint) : Longint;
|
||||
|
||||
begin
|
||||
//!! Needs implementing
|
||||
end;
|
||||
|
||||
|
||||
Function FileSeek (Handle,Offset,Origin : Longint) : Longint;
|
||||
|
||||
begin
|
||||
//!! Needs implementing
|
||||
end;
|
||||
|
||||
|
||||
Procedure FileClose (Handle : Longint);
|
||||
|
||||
begin
|
||||
//!! Needs implementing
|
||||
end;
|
||||
|
||||
|
||||
Function FileAge (Const FileName : String): Longint;
|
||||
|
||||
begin
|
||||
//!! Needs implementing
|
||||
end;
|
||||
|
||||
|
||||
Function FileExists (Const FileName : String) : Boolean;
|
||||
|
||||
begin
|
||||
//!! Needs implementing
|
||||
end;
|
||||
|
||||
|
||||
Function FindFirst (Const Path : String; Attr : Longint; Var Rslt : TSearchRec) : Longint;
|
||||
|
||||
begin
|
||||
//!! Needs implementing
|
||||
end;
|
||||
|
||||
|
||||
Function FindNext (Var Rslt : TSearchRec) : Longint;
|
||||
|
||||
begin
|
||||
//!! Needs implementing
|
||||
end;
|
||||
|
||||
|
||||
Procedure FindClose (Var F : TSearchrec);
|
||||
|
||||
begin
|
||||
//!! Needs implementing
|
||||
end;
|
||||
|
||||
|
||||
Function FileGetDate (Handle : Longint) : Longint;
|
||||
|
||||
begin
|
||||
//!! Needs implementing
|
||||
end;
|
||||
|
||||
|
||||
Function FileSetDate (Handle,Age : Longint) : Longint;
|
||||
|
||||
begin
|
||||
//!! Needs implementing
|
||||
end;
|
||||
|
||||
|
||||
Function FileGetAttr (Const FileName : String) : Longint;
|
||||
|
||||
begin
|
||||
//!! Needs implementing
|
||||
end;
|
||||
|
||||
|
||||
Function FileSetAttr (Const Filename : String; Attr: longint) : Longint;
|
||||
|
||||
begin
|
||||
//!! Needs implementing
|
||||
end;
|
||||
|
||||
|
||||
Function DeleteFile (Const FileName : String) : Boolean;
|
||||
|
||||
begin
|
||||
//!! Needs implementing
|
||||
end;
|
||||
|
||||
|
||||
Function RenameFile (Const OldName, NewName : String) : Boolean;
|
||||
|
||||
begin
|
||||
//!! Needs implementing
|
||||
end;
|
||||
|
||||
|
||||
Function FileSearch (Const Name, DirList : String) : String;
|
||||
|
||||
begin
|
||||
//!! Needs implementing
|
||||
end;
|
||||
|
||||
|
||||
{
|
||||
$Log$
|
||||
Revision 1.1 1998-10-11 12:21:01 michael
|
||||
Added file calls. Implemented for linux only
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user