kolibrios-fun/programs/develop/fp/rtl/sysfile.inc
bw f23fc38433 FreePascal RTL
git-svn-id: svn://kolibrios.org@616 a494cfbc-eb01-0410-851d-a64ba20cac60
2007-08-29 09:16:31 +00:00

146 lines
3.4 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{cp866}
function DecodeErrNo(ErrNo: DWord): Word;
{0 = ãᯥ譮
1 = ­¥ ®¯à¥¤¥«¥­  ¡ §  ¨/¨«¨ à §¤¥« ¦ñá⪮£® ¤¨áª  (¯®¤äã­ªæ¨ï¬¨ 7, 8 ä㭪樨 21)
2 = äã­ªæ¨ï ­¥ ¯®¤¤¥à¦¨¢ ¥âáï ¤«ï ¤ ­­®© ä ©«®¢®© á¨á⥬ë
3 = ­¥¨§¢¥áâ­ ï ä ©«®¢ ï á¨á⥬ 
4 = § à¥§¥à¢¨à®¢ ­®, ­¨ª®£¤  ­¥ ¢®§¢à é ¥âáï ¢ ⥪ã饩 ॠ«¨§ æ¨¨
5 = ä ©« ­¥ ­ ©¤¥­
6 = ä ©« § ª®­ç¨«áï
7 = 㪠§ â¥«ì ¢­¥ ¯ ¬ï⨠¯à¨«®¦¥­¨ï
8 = ¤¨áª § ¯®«­¥­
9 = â ¡«¨æ  FAT à §àã襭 
10 = ¤®áâ㯠§ ¯à¥éñ­
11 = ®è¨¡ª  ãáâனá⢠}
begin
case ErrNo of
0: Result := 0;
1: Result := 152;
2: Result := 153;
3: Result := 151;
4: Result := 1;
5: Result := 2;
6: Result := 0;
8: Result := 101;
else
Result := 153; { Unknown command (­¥¨§¢¥áâ­ ï ª®¬ ­¤ ) }
end;
end;
function do_isdevice(handle:thandle): Boolean;
begin
InOutRes := 211;
Result := False;
end;
procedure do_close(handle: THandle);
begin
FreeMem(PKosFile(handle));
InOutRes := 0;
end;
procedure do_erase(p : pchar);
begin
InOutRes := 211;
end;
procedure do_rename(p1,p2 : pchar);
begin
InOutRes := 211;
end;
function do_write(handle: THandle; addr: Pointer; len: Longint): Longint;
begin
PKosFile(handle)^.Size := len;
PKosFile(handle)^.Data := addr;
InOutRes := DecodeErrNo(kos_writefile(PKosFile(handle), Result));
Inc(PKosFile(handle)^.Position, Result);
end;
function do_read(handle: THandle; addr: Pointer; len: Longint): Longint;
begin
PKosFile(handle)^.Size := len;
PKosFile(handle)^.Data := addr;
InOutRes := DecodeErrNo(kos_readfile(PKosFile(handle), Result));
Inc(PKosFile(handle)^.Position, Result);
end;
function do_filepos(handle: THandle): Int64;
begin
Result := PKosFile(handle)^.Position;
end;
procedure do_seek(handle: THandle; pos: Int64);
begin
PKosFile(handle)^.Position := pos;
end;
function do_seekend(handle: THandle): Int64;
begin
InOutRes := 211;
Result := 0;
end;
function do_filesize(handle: THandle): Int64;
var
BDFE: TKosBDFE;
begin
PKosFile(handle)^.Data := @BDFE;
InOutRes := DecodeErrNo(kos_fileinfo(PKosFile(handle)));
Result := BDFE.Size;
end;
procedure do_truncate(handle: THandle; pos: Int64);
begin
InOutRes := 211;
end;
procedure do_open(var f; p: PChar; flags: Longint);
var
KosFile: PKosFile;
FilePath: PChar;
FilePathLen: Longint;
RecSize: Longint;
CurrDir: array[0..2048] of Char;
CurrDirLen: Longint;
begin
case flags and 3 of
0: FileRec(f).Mode := fmInput;
1: FileRec(f).Mode := fmOutput;
2: FileRec(f).Mode := fmInOut;
end;
{”®à¬¨à®¢ ­¨¥ ¨¬¥­¨  ¡á®«îâ­®£® ¯ãâ¨}
FilePathLen := Length(p);
if p^ <> DirectorySeparator then
begin
{XXX: à §¬¥à ¡ãä¥à  CurrDir ¬®¦¥â ®ª § âìáï ­¥¤®áâ â®ç­ë¬}
CurrDirLen := kos_getdir(@CurrDir, SizeOf(CurrDir) - FilePathLen - 1) - 1;
FilePath := @CurrDir;
if FilePath[CurrDirLen - 1] <> DirectorySeparator then
begin
FilePath[CurrDirLen] := DirectorySeparator;
Inc(CurrDirLen);
end;
Move(p^, FilePath[CurrDirLen], FilePathLen + 1);
Inc(FilePathLen, CurrDirLen);
end else
FilePath := p;
{‘®§¤ ­¨¥ áâàãªâãàë TKosFile}
RecSize := SizeOf(TKosFile) + FilePathLen;
KosFile := GetMem(RecSize);
FillChar(KosFile^, RecSize, 0);
Move(FilePath^, KosFile^.Name, FilePathLen);
FileRec(f).Handle := DWord(KosFile);
if flags and $1000 <> 0 then
begin
{ ᮧ¤ âì ä ©« }
InOutRes := DecodeErrNo(kos_rewritefile(KosFile, RecSize));
end else
InOutRes := 0;
end;