+ initial WASI implementation of DOS.GetFTime. Not working yet, due to a

compiler bug, related to the import of fd_filestat_get from the wasiapi unit.

git-svn-id: trunk@49536 -
This commit is contained in:
nickysn 2021-06-23 20:04:03 +00:00
parent ba1dcfc6a4
commit 953893267b
3 changed files with 50 additions and 16 deletions

View File

@ -2664,7 +2664,7 @@ wasiapi$(PPUEXT) : wasiapi.pp wasiinc/wasitypes.inc wasiinc/wasiprocs.inc $(SYST
$(COMPILER) $< -Fiwasiinc $(COMPILER) $< -Fiwasiinc
ctypes$(PPUEXT) : $(INC)/ctypes.pp $(SYSTEMUNIT)$(PPUEXT) ctypes$(PPUEXT) : $(INC)/ctypes.pp $(SYSTEMUNIT)$(PPUEXT)
$(COMPILER) $< $(COMPILER) $<
dos$(PPUEXT) : dos.pp $(INC)/filerec.inc $(INC)/textrec.inc system$(PPUEXT) dos$(PPUEXT) : dos.pp $(INC)/filerec.inc $(INC)/textrec.inc wasiapi$(PPUEXT) system$(PPUEXT)
$(COMPILER) $< $(COMPILER) $<
sysutils$(PPUEXT) : sysutils.pp $(wildcard $(OBJPASDIR)/sysutils/*.inc) \ sysutils$(PPUEXT) : sysutils.pp $(wildcard $(OBJPASDIR)/sysutils/*.inc) \
objpas$(PPUEXT) wasiapi$(PPUEXT) sysconst$(PPUEXT) system$(PPUEXT) objpas$(PPUEXT) wasiapi$(PPUEXT) sysconst$(PPUEXT) system$(PPUEXT)

View File

@ -96,7 +96,7 @@ ctypes$(PPUEXT) : $(INC)/ctypes.pp $(SYSTEMUNIT)$(PPUEXT)
# #
# TP7 Compatible RTL Units # TP7 Compatible RTL Units
# #
dos$(PPUEXT) : dos.pp $(INC)/filerec.inc $(INC)/textrec.inc system$(PPUEXT) dos$(PPUEXT) : dos.pp $(INC)/filerec.inc $(INC)/textrec.inc wasiapi$(PPUEXT) system$(PPUEXT)
$(COMPILER) $< $(COMPILER) $<
# #

View File

@ -46,7 +46,7 @@ Type
{Extra Utils} {Extra Utils}
//function weekday(y,m,d : longint) : longint; platform; //function weekday(y,m,d : longint) : longint; platform;
//Procedure UnixDateToDt(SecsPast: LongInt; Var Dt: DateTime); platform; Procedure WasiDateToDt(NanoSecsPast: UInt64; Var Dt: DateTime); platform;
//Function DTToUnixDate(DT: DateTime): LongInt; platform; //Function DTToUnixDate(DT: DateTime): LongInt; platform;
{Disk} {Disk}
@ -54,11 +54,8 @@ Type
Implementation Implementation
//Uses Uses
// UnixUtil, WasiAPI;
// Strings,
// Unix,
// {$ifdef FPC_USE_LIBC}initc{$ELSE}Syscall{$ENDIF};
{$DEFINE HAS_GETMSCOUNT} {$DEFINE HAS_GETMSCOUNT}
@ -140,8 +137,45 @@ begin
end; end;
Procedure UnixDateToDt(SecsPast: LongInt; Var Dt: DateTime); Procedure WasiDateToDt(NanoSecsPast: UInt64; Var Dt: DateTime);
const
days_in_month: array [boolean, 1..12] of Byte =
((31,28,31,30,31,30,31,31,30,31,30,31),
(31,29,31,30,31,30,31,31,30,31,30,31));
var
leap: Boolean;
days_in_year: LongInt;
Begin Begin
{ todo: convert UTC to local time, as soon as we can get the local timezone
from WASI: https://github.com/WebAssembly/WASI/issues/239 }
NanoSecsPast:=NanoSecsPast div 1000000000;
Dt.Sec:=NanoSecsPast mod 60;
NanoSecsPast:=NanoSecsPast div 60;
Dt.Min:=NanoSecsPast mod 60;
NanoSecsPast:=NanoSecsPast div 60;
Dt.Hour:=NanoSecsPast mod 24;
NanoSecsPast:=NanoSecsPast div 24;
Dt.Year:=1970;
leap:=false;
days_in_year:=365;
while NanoSecsPast>=days_in_year do
begin
Dec(NanoSecsPast,days_in_year);
Inc(Dt.Year);
leap:=((Dt.Year mod 4)=0) and (((Dt.Year mod 100)<>0) or ((Dt.Year mod 400)=0));
if leap then
days_in_year:=365
else
days_in_year:=366;
end;
Dt.Month:=1;
Inc(NanoSecsPast);
while NanoSecsPast>days_in_month[leap,Dt.Month] do
begin
Dec(NanoSecsPast,days_in_month[leap,Dt.Month]);
Inc(Dt.Month);
end;
Dt.Day:=Word(NanoSecsPast);
End; End;
@ -623,20 +657,20 @@ Begin
end; end;
Procedure getftime (var f; var time : longint); Procedure getftime (var f; var time : longint);
{Var Var
Info: baseunix.stat; Info: __wasi_filestat_t;
DT: DateTime;} DT: DateTime;
Begin Begin
{ doserror:=0; doserror:=0;
if fpfstat(filerec(f).handle,info)<0 then if __wasi_fd_filestat_get(filerec(f).handle,@Info)<>__WASI_ERRNO_SUCCESS then
begin begin
Time:=0; Time:=0;
doserror:=6; doserror:=6;
exit exit
end end
else else
UnixDateToDT(Info.st_mTime,DT); WasiDateToDt(Info.mtim,DT);
PackTime(DT,Time);} PackTime(DT,Time);
End; End;
Procedure setftime(var f; time : longint); Procedure setftime(var f; time : longint);