mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 19:49:22 +02:00
+ linux support for fileio contributed by Holger Schurig
This commit is contained in:
parent
f530871848
commit
16f5751207
@ -75,7 +75,9 @@ UNIT FileIO;
|
|||||||
|
|
||||||
{$X+} { Extended syntax is ok }
|
{$X+} { Extended syntax is ok }
|
||||||
{$R-} { Disable range checking }
|
{$R-} { Disable range checking }
|
||||||
|
{$IFNDEF OS_LINUX}
|
||||||
{$S-} { Disable Stack Checking }
|
{$S-} { Disable Stack Checking }
|
||||||
|
{$ENDIF}
|
||||||
{$I-} { Disable IO Checking }
|
{$I-} { Disable IO Checking }
|
||||||
{$Q-} { Disable Overflow Checking }
|
{$Q-} { Disable Overflow Checking }
|
||||||
{$V-} { Turn off strict VAR strings }
|
{$V-} { Turn off strict VAR strings }
|
||||||
@ -225,6 +227,10 @@ FUNCTION FileWrite (Handle: THandle; Var Buf; Count: Sw_Word; Var Actual: Sw_Wor
|
|||||||
|
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
|
{$IFDEF OS_LINUX} { LINUX COMPILER }
|
||||||
|
USES unix;
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
{***************************************************************************}
|
{***************************************************************************}
|
||||||
{ INTERFACE ROUTINES }
|
{ INTERFACE ROUTINES }
|
||||||
{***************************************************************************}
|
{***************************************************************************}
|
||||||
@ -279,8 +285,7 @@ END;
|
|||||||
{$IFDEF OS_LINUX} { LINUX CODE }
|
{$IFDEF OS_LINUX} { LINUX CODE }
|
||||||
BEGIN
|
BEGIN
|
||||||
fdClose(Handle); { Close the file }
|
fdClose(Handle); { Close the file }
|
||||||
If (LinuxError <= 0) Then FileClosed := True { Close succesful }
|
FileClose := LinuxError <= 0
|
||||||
Else FileClosed := False; { Close failed }
|
|
||||||
END;
|
END;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
@ -375,6 +380,15 @@ BEGIN
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
END;
|
END;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
{$IFDEF OS_LINUX}
|
||||||
|
BEGIN
|
||||||
|
if mode = fa_Create then mode := Open_Creat or Open_RdWr else
|
||||||
|
if mode = fa_OpenRead then mode := Open_RdOnly else
|
||||||
|
if mode = fa_OpenWrite then mode := Open_WrOnly else
|
||||||
|
if mode = fa_Open then mode := Open_RdWr;
|
||||||
|
FileOpen := fdOpen(FileName, mode);
|
||||||
|
END;
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
{---------------------------------------------------------------------------}
|
{---------------------------------------------------------------------------}
|
||||||
{ SetFileSize -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 26Feb97 LdB }
|
{ SetFileSize -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 26Feb97 LdB }
|
||||||
@ -446,6 +460,18 @@ BEGIN
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
END;
|
END;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
{$IFDEF OS_LINUX}
|
||||||
|
VAR
|
||||||
|
Actual : LongInt;
|
||||||
|
BEGIN
|
||||||
|
Actual := fdSeek(Handle, FileSize, 0); { Position file }
|
||||||
|
If (Actual = FileSize) Then Begin { No position error }
|
||||||
|
if (fdTruncate(Handle, FileSize)) { Truncate the file }
|
||||||
|
Then SetFileSize := 0 { No truncate error }
|
||||||
|
else SetFileSize := 103; { File truncate error }
|
||||||
|
End Else SetFileSize := 103; { File truncate error }
|
||||||
|
END;
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
{---------------------------------------------------------------------------}
|
{---------------------------------------------------------------------------}
|
||||||
{ SetFilePos -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 25Feb97 LdB }
|
{ SetFilePos -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 25Feb97 LdB }
|
||||||
@ -514,6 +540,13 @@ BEGIN
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
END;
|
END;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
{$IFDEF OS_LINUX}
|
||||||
|
BEGIN
|
||||||
|
Actual := fdSeek(Handle, Pos, MoveType);
|
||||||
|
If (Actual <> -1) Then SetFilePos := 0 Else { No position error }
|
||||||
|
SetFilePos := 107; { File position error }
|
||||||
|
END;
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
{---------------------------------------------------------------------------}
|
{---------------------------------------------------------------------------}
|
||||||
{ FileRead -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct98 LdB }
|
{ FileRead -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct98 LdB }
|
||||||
@ -551,7 +584,6 @@ FUNCTION FileRead (Handle: THandle; Var Buf; Count: Sw_Word; Var Actual: Sw_Word
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
{$IFDEF OS_WINDOWS} { WIN/NT CODE }
|
{$IFDEF OS_WINDOWS} { WIN/NT CODE }
|
||||||
|
|
||||||
BEGIN
|
BEGIN
|
||||||
{$IFDEF BIT_16} { 16 BIT WINDOWS CODE }
|
{$IFDEF BIT_16} { 16 BIT WINDOWS CODE }
|
||||||
Actual := _lread(Handle, Pointer(@Buf), Count); { Read from file }
|
Actual := _lread(Handle, Pointer(@Buf), Count); { Read from file }
|
||||||
@ -572,6 +604,13 @@ BEGIN
|
|||||||
FileRead := 104; { File read error }
|
FileRead := 104; { File read error }
|
||||||
END;
|
END;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
{$IFDEF OS_LINUX}
|
||||||
|
BEGIN
|
||||||
|
Actual := fdRead(Handle, Buf, Count);
|
||||||
|
if (Actual = Count) Then FileRead := 0 { No read error }
|
||||||
|
Else FileRead := 104; { File read error }
|
||||||
|
END;
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
{---------------------------------------------------------------------------}
|
{---------------------------------------------------------------------------}
|
||||||
{ FileWrite -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct98 LdB }
|
{ FileWrite -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct98 LdB }
|
||||||
@ -629,11 +668,21 @@ BEGIN
|
|||||||
FileWrite := 105; { File write error }
|
FileWrite := 105; { File write error }
|
||||||
END;
|
END;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
{$IFDEF OS_LINUX}
|
||||||
|
BEGIN
|
||||||
|
Actual := fdWrite(Handle, Buf, Count);
|
||||||
|
If (Actual = Count) Then FileWrite := 0 Else { No write error }
|
||||||
|
FileWrite := 105; { File write error }
|
||||||
|
END;
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
END.
|
END.
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.3 2001-04-10 21:29:55 pierre
|
Revision 1.4 2001-05-03 15:55:44 pierre
|
||||||
|
+ linux support for fileio contributed by Holger Schurig
|
||||||
|
|
||||||
|
Revision 1.3 2001/04/10 21:29:55 pierre
|
||||||
* import of Leon de Boer's files
|
* import of Leon de Boer's files
|
||||||
|
|
||||||
Revision 1.2 2000/08/24 12:00:21 marco
|
Revision 1.2 2000/08/24 12:00:21 marco
|
||||||
|
29
fv/test/tfileio.pas
Normal file
29
fv/test/tfileio.pas
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
USES
|
||||||
|
Common,FileIO;
|
||||||
|
|
||||||
|
VAR
|
||||||
|
Handle : THandle;
|
||||||
|
buf : ARRAY[0..255] OF CHAR;
|
||||||
|
n : Longint;
|
||||||
|
BEGIN
|
||||||
|
Handle := FileOpen(AsciiZ('test'), fa_Create);
|
||||||
|
writeln('FileOpen: ',Handle);
|
||||||
|
|
||||||
|
buf := 'Test'#0;
|
||||||
|
writeln('FileWrite: ', FileWrite(handle, Buf, 5, n));
|
||||||
|
writeln('Bytes written: ', n);
|
||||||
|
|
||||||
|
Writeln('SetFileSize: ', SetFileSize(handle, 4));
|
||||||
|
|
||||||
|
Writeln('SetFilePos: ', SetFilePos(handle, 2, 0, n));
|
||||||
|
Writeln('Actual: ', n);
|
||||||
|
|
||||||
|
Writeln('FileRead: ', FileRead(Handle, buf, 2, n) );
|
||||||
|
Writeln('Actual: ', n);
|
||||||
|
|
||||||
|
Writeln('Buf[0]=', Buf[0], ' Buf[1]=', Buf[1]);
|
||||||
|
|
||||||
|
Writeln('FileClose: ', FileClose(Handle));
|
||||||
|
END.
|
||||||
|
|
||||||
|
|
@ -75,7 +75,9 @@ UNIT FileIO;
|
|||||||
|
|
||||||
{$X+} { Extended syntax is ok }
|
{$X+} { Extended syntax is ok }
|
||||||
{$R-} { Disable range checking }
|
{$R-} { Disable range checking }
|
||||||
|
{$IFNDEF OS_LINUX}
|
||||||
{$S-} { Disable Stack Checking }
|
{$S-} { Disable Stack Checking }
|
||||||
|
{$ENDIF}
|
||||||
{$I-} { Disable IO Checking }
|
{$I-} { Disable IO Checking }
|
||||||
{$Q-} { Disable Overflow Checking }
|
{$Q-} { Disable Overflow Checking }
|
||||||
{$V-} { Turn off strict VAR strings }
|
{$V-} { Turn off strict VAR strings }
|
||||||
@ -225,6 +227,10 @@ FUNCTION FileWrite (Handle: THandle; Var Buf; Count: Sw_Word; Var Actual: Sw_Wor
|
|||||||
|
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
|
{$IFDEF OS_LINUX} { LINUX COMPILER }
|
||||||
|
USES unix;
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
{***************************************************************************}
|
{***************************************************************************}
|
||||||
{ INTERFACE ROUTINES }
|
{ INTERFACE ROUTINES }
|
||||||
{***************************************************************************}
|
{***************************************************************************}
|
||||||
@ -279,8 +285,7 @@ END;
|
|||||||
{$IFDEF OS_LINUX} { LINUX CODE }
|
{$IFDEF OS_LINUX} { LINUX CODE }
|
||||||
BEGIN
|
BEGIN
|
||||||
fdClose(Handle); { Close the file }
|
fdClose(Handle); { Close the file }
|
||||||
If (LinuxError <= 0) Then FileClosed := True { Close succesful }
|
FileClose := LinuxError <= 0
|
||||||
Else FileClosed := False; { Close failed }
|
|
||||||
END;
|
END;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
@ -375,6 +380,15 @@ BEGIN
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
END;
|
END;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
{$IFDEF OS_LINUX}
|
||||||
|
BEGIN
|
||||||
|
if mode = fa_Create then mode := Open_Creat or Open_RdWr else
|
||||||
|
if mode = fa_OpenRead then mode := Open_RdOnly else
|
||||||
|
if mode = fa_OpenWrite then mode := Open_WrOnly else
|
||||||
|
if mode = fa_Open then mode := Open_RdWr;
|
||||||
|
FileOpen := fdOpen(FileName, mode);
|
||||||
|
END;
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
{---------------------------------------------------------------------------}
|
{---------------------------------------------------------------------------}
|
||||||
{ SetFileSize -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 26Feb97 LdB }
|
{ SetFileSize -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 26Feb97 LdB }
|
||||||
@ -446,6 +460,18 @@ BEGIN
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
END;
|
END;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
{$IFDEF OS_LINUX}
|
||||||
|
VAR
|
||||||
|
Actual : LongInt;
|
||||||
|
BEGIN
|
||||||
|
Actual := fdSeek(Handle, FileSize, 0); { Position file }
|
||||||
|
If (Actual = FileSize) Then Begin { No position error }
|
||||||
|
if (fdTruncate(Handle, FileSize)) { Truncate the file }
|
||||||
|
Then SetFileSize := 0 { No truncate error }
|
||||||
|
else SetFileSize := 103; { File truncate error }
|
||||||
|
End Else SetFileSize := 103; { File truncate error }
|
||||||
|
END;
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
{---------------------------------------------------------------------------}
|
{---------------------------------------------------------------------------}
|
||||||
{ SetFilePos -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 25Feb97 LdB }
|
{ SetFilePos -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 25Feb97 LdB }
|
||||||
@ -514,6 +540,13 @@ BEGIN
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
END;
|
END;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
{$IFDEF OS_LINUX}
|
||||||
|
BEGIN
|
||||||
|
Actual := fdSeek(Handle, Pos, MoveType);
|
||||||
|
If (Actual <> -1) Then SetFilePos := 0 Else { No position error }
|
||||||
|
SetFilePos := 107; { File position error }
|
||||||
|
END;
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
{---------------------------------------------------------------------------}
|
{---------------------------------------------------------------------------}
|
||||||
{ FileRead -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct98 LdB }
|
{ FileRead -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct98 LdB }
|
||||||
@ -551,7 +584,6 @@ FUNCTION FileRead (Handle: THandle; Var Buf; Count: Sw_Word; Var Actual: Sw_Word
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
{$IFDEF OS_WINDOWS} { WIN/NT CODE }
|
{$IFDEF OS_WINDOWS} { WIN/NT CODE }
|
||||||
|
|
||||||
BEGIN
|
BEGIN
|
||||||
{$IFDEF BIT_16} { 16 BIT WINDOWS CODE }
|
{$IFDEF BIT_16} { 16 BIT WINDOWS CODE }
|
||||||
Actual := _lread(Handle, Pointer(@Buf), Count); { Read from file }
|
Actual := _lread(Handle, Pointer(@Buf), Count); { Read from file }
|
||||||
@ -572,6 +604,13 @@ BEGIN
|
|||||||
FileRead := 104; { File read error }
|
FileRead := 104; { File read error }
|
||||||
END;
|
END;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
{$IFDEF OS_LINUX}
|
||||||
|
BEGIN
|
||||||
|
Actual := fdRead(Handle, Buf, Count);
|
||||||
|
if (Actual = Count) Then FileRead := 0 { No read error }
|
||||||
|
Else FileRead := 104; { File read error }
|
||||||
|
END;
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
{---------------------------------------------------------------------------}
|
{---------------------------------------------------------------------------}
|
||||||
{ FileWrite -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct98 LdB }
|
{ FileWrite -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 22Oct98 LdB }
|
||||||
@ -629,11 +668,21 @@ BEGIN
|
|||||||
FileWrite := 105; { File write error }
|
FileWrite := 105; { File write error }
|
||||||
END;
|
END;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
{$IFDEF OS_LINUX}
|
||||||
|
BEGIN
|
||||||
|
Actual := fdWrite(Handle, Buf, Count);
|
||||||
|
If (Actual = Count) Then FileWrite := 0 Else { No write error }
|
||||||
|
FileWrite := 105; { File write error }
|
||||||
|
END;
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
END.
|
END.
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
Revision 1.3 2001-04-10 21:29:55 pierre
|
Revision 1.4 2001-05-03 15:55:44 pierre
|
||||||
|
+ linux support for fileio contributed by Holger Schurig
|
||||||
|
|
||||||
|
Revision 1.3 2001/04/10 21:29:55 pierre
|
||||||
* import of Leon de Boer's files
|
* import of Leon de Boer's files
|
||||||
|
|
||||||
Revision 1.2 2000/08/24 12:00:21 marco
|
Revision 1.2 2000/08/24 12:00:21 marco
|
||||||
|
29
fvision/test/tfileio.pas
Normal file
29
fvision/test/tfileio.pas
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
USES
|
||||||
|
Common,FileIO;
|
||||||
|
|
||||||
|
VAR
|
||||||
|
Handle : THandle;
|
||||||
|
buf : ARRAY[0..255] OF CHAR;
|
||||||
|
n : Longint;
|
||||||
|
BEGIN
|
||||||
|
Handle := FileOpen(AsciiZ('test'), fa_Create);
|
||||||
|
writeln('FileOpen: ',Handle);
|
||||||
|
|
||||||
|
buf := 'Test'#0;
|
||||||
|
writeln('FileWrite: ', FileWrite(handle, Buf, 5, n));
|
||||||
|
writeln('Bytes written: ', n);
|
||||||
|
|
||||||
|
Writeln('SetFileSize: ', SetFileSize(handle, 4));
|
||||||
|
|
||||||
|
Writeln('SetFilePos: ', SetFilePos(handle, 2, 0, n));
|
||||||
|
Writeln('Actual: ', n);
|
||||||
|
|
||||||
|
Writeln('FileRead: ', FileRead(Handle, buf, 2, n) );
|
||||||
|
Writeln('Actual: ', n);
|
||||||
|
|
||||||
|
Writeln('Buf[0]=', Buf[0], ' Buf[1]=', Buf[1]);
|
||||||
|
|
||||||
|
Writeln('FileClose: ', FileClose(Handle));
|
||||||
|
END.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user