[fpc-pascal] Improve THandleStream.Size for VFS on Linux
Alexey Tor.
aaa5500 at ya.ru
Tue Oct 8 00:02:42 CEST 2019
Ubuntu 18.x x64. FPC 3.3 trunk.
I get handle of '/proc/version' using func below (e.g. handle=22).
Now I want to get file size of that file. and read all contents into
THandleStream. But problem is: THandleSteam.Size gets 0.
I guess THandleStream can override GetSize to get size smarter. Maybe
someone knows how?
It will be very good, to access /proc/... by streams.
const
{$IF DEFINED(LINUX)}
FD_CLOEXEC = 1;
O_CLOEXEC = &02000000;
{$ELSEIF DEFINED(FREEBSD)}
O_CLOEXEC = &04000000;
{$ELSEIF DEFINED(NETBSD)}
O_CLOEXEC = $00400000;
{$ELSE}
O_CLOEXEC = 0;
{$ENDIF}
function _CustomFileHandle(const FileName: string; Mode: LongWord): THandle;
const
AccessModes: array[0..2] of cInt = (
O_RdOnly,
O_WrOnly,
O_RdWr);
OpenFlags: array[0..3] of cInt = (
0,
O_SYNC,
O_DIRECT,
O_SYNC or O_DIRECT);
begin
repeat
Result:= fpOpen(UTF8ToSys(FileName), AccessModes[Mode and 3] or
OpenFlags[(Mode shr 16) and 3] or O_CLOEXEC);
until (Result <> -1) or (fpgeterrno <> ESysEINTR);
end;
--
Regards,
Alexey
More information about the fpc-pascal
mailing list