123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 |
- {
- This file is part of the Free Pascal run time library.
- Copyright (c) 1999-2021 by the Free Pascal development team.
- Sysutils unit for The WebAssembly System Interface (WASI).
- 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.
- **********************************************************************}
- {$inline on}
- unit sysutils;
- interface
- {$MODE objfpc}
- {$MODESWITCH out}
- { force ansistrings }
- {$H+}
- {$modeswitch typehelpers}
- {$modeswitch advancedrecords}
- uses
- wasiapi;
- {$DEFINE HAS_SLEEP}
- {$DEFINE HAS_GETTICKCOUNT64}
- { used OS file system APIs use ansistring }
- {$define SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
- { OS has an ansistring/single byte environment variable API }
- {$define SYSUTILS_HAS_ANSISTR_ENVVAR_IMPL}
- { Include platform independent interface part }
- {$i sysutilh.inc}
- implementation
- uses
- sysconst;
- {$DEFINE FPC_FEXPAND_UNC} (* UNC paths are supported *)
- {$DEFINE FPC_FEXPAND_DRIVES} (* Full paths begin with drive specification *)
- {$DEFINE HAS_LOCALTIMEZONEOFFSET}
- {$DEFINE executeprocuni} (* Only 1 byte version of ExecuteProcess is provided by the OS *)
- { Include platform independent implementation part }
- {$i sysutils.inc}
- function GetTickCount64: QWord;
- var
- NanoSecsPast: __wasi_timestamp_t;
- begin
- if __wasi_clock_time_get(__WASI_CLOCKID_MONOTONIC,1000000,@NanoSecsPast)=__WASI_ERRNO_SUCCESS then
- Result:=NanoSecsPast div 1000000
- else
- Result:=0;
- end;
- {****************************************************************************
- File Functions
- ****************************************************************************}
- Function FileOpen (Const FileName : RawByteString; Mode : Integer) : THandle;
- Begin
- end;
- Function FileCreate (Const FileName : RawByteString) : THandle;
- begin
- end;
- Function FileCreate (Const FileName : RawByteString; ShareMode:integer; Rights : integer) : THandle;
- begin
- end;
- Function FileCreate (Const FileName : RawByteString; Rights:integer) : THandle;
- begin
- end;
- Function FileRead (Handle : THandle; Out Buffer; Count : longint) : Longint;
- begin
- end;
- Function FileWrite (Handle : THandle; const Buffer; Count : Longint) : Longint;
- begin
- end;
- Function FileSeek (Handle : THandle; FOffset, Origin : Longint) : Longint;
- begin
- end;
- Function FileSeek (Handle : THandle; FOffset: Int64; Origin: {Integer}Longint) : Int64;
- begin
- end;
- Procedure FileClose (Handle : THandle);
- begin
- end;
- Function FileTruncate (Handle: THandle; Size: Int64) : boolean;
- begin
- end;
- Function FileAge (Const FileName : RawByteString): Int64;
- begin
- end;
- function FileGetSymLinkTarget(const FileName: RawByteString; out SymLinkRec: TRawbyteSymLinkRec): Boolean;
- begin
- Result := False;
- end;
- function FileExists (const FileName: RawByteString; FollowLink : Boolean): boolean;
- begin
- end;
- Function DirectoryExists (Const Directory : RawByteString; FollowLink : Boolean) : Boolean;
- begin
- end;
- Function InternalFindFirst (Const Path : RawByteString; Attr : Longint; out Rslt : TAbstractSearchRec; var Name: RawByteString) : Longint;
- begin
- { not yet implemented }
- Result := -1;
- end;
- Function InternalFindNext (var Rslt : TAbstractSearchRec; var Name : RawByteString) : Longint;
- begin
- { not yet implemented }
- Result := -1;
- end;
- Procedure InternalFindClose(var Handle: THandle);
- begin
- end;
- Function FileGetDate (Handle : THandle) : Int64;
- begin
- end;
- Function FileSetDate (Handle : THandle; Age : Int64) : Longint;
- begin
- end;
- Function FileGetAttr (Const FileName : RawByteString) : Longint;
- begin
- end;
- Function FileSetAttr (Const Filename : RawByteString; Attr: longint) : Longint;
- begin
- end;
- Function DeleteFile (Const FileName : RawByteString) : Boolean;
- begin
- end;
- Function RenameFile (Const OldName, NewName : RawByteString) : Boolean;
- begin
- end;
- {****************************************************************************
- Disk Functions
- ****************************************************************************}
- function diskfree(drive : byte) : int64;
- begin
- end;
- function disksize(drive : byte) : int64;
- begin
- end;
- {****************************************************************************
- Time Functions
- ****************************************************************************}
- {$I tzenv.inc}
- Procedure GetLocalTime(var SystemTime: TSystemTime);
- begin
- end ;
- {****************************************************************************
- Misc Functions
- ****************************************************************************}
- procedure sysBeep;
- begin
- end;
- {****************************************************************************
- Locale Functions
- ****************************************************************************}
- procedure InitAnsi;
- begin
- end;
- Procedure InitInternational;
- begin
- InitInternationalGeneric;
- InitAnsi;
- end;
- function SysErrorMessage(ErrorCode: Integer): String;
- begin
- Result:=Format(SUnknownErrorCode,[ErrorCode]);
- end;
- {****************************************************************************
- Os utils
- ****************************************************************************}
- Function GetEnvironmentVariable(Const EnvVar : String) : String;
- var
- hp : ppchar;
- hs : string;
- eqpos : longint;
- begin
- result:='';
- hp:=envp;
- if hp<>nil then
- while assigned(hp^) do
- begin
- hs:=strpas(hp^);
- eqpos:=pos('=',hs);
- if copy(hs,1,eqpos-1)=envvar then
- begin
- result:=copy(hs,eqpos+1,length(hs)-eqpos);
- break;
- end;
- inc(hp);
- end;
- end;
- Function GetEnvironmentVariableCount : Integer;
- var
- p: ppchar;
- begin
- result:=0;
- p:=envp; {defined in system}
- if p<>nil then
- while p^<>nil do
- begin
- inc(result);
- inc(p);
- end;
- end;
- Function GetEnvironmentString(Index : Integer) : {$ifdef FPC_RTL_UNICODE}UnicodeString{$else}AnsiString{$endif};
- Var
- i : longint;
- p : ppchar;
- begin
- if (Index <= 0) or (envp=nil) then
- result:=''
- else
- begin
- p:=envp; {defined in system}
- i:=1;
- while (i<Index) and (p^<>nil) do
- begin
- inc(i);
- inc(p);
- end;
- if p^=nil then
- result:=''
- else
- result:=strpas(p^)
- end;
- end;
- function ExecuteProcess(Const Path: RawByteString; Const ComLine: RawByteString;Flags:TExecuteFlags=[]):integer;
- begin
- end;
- function ExecuteProcess (const Path: RawByteString;
- const ComLine: array of RawByteString;Flags:TExecuteFlags=[]): integer;
- begin
- end;
- {*************************************************************************
- Sleep
- *************************************************************************}
- procedure Sleep (MilliSeconds: Cardinal);
- var
- subscription: __wasi_subscription_t;
- event: __wasi_event_t;
- nevents: __wasi_size_t;
- begin
- FillChar(subscription,SizeOf(subscription),0);
- subscription.u.tag:=__WASI_EVENTTYPE_CLOCK;
- subscription.u.u.clock.id:=__WASI_CLOCKID_MONOTONIC;
- subscription.u.u.clock.timeout:=MilliSeconds*1000000;
- subscription.u.u.clock.precision:=1000000;
- subscription.u.u.clock.flags:=0; { timeout value is relative }
- __wasi_poll_oneoff(@subscription,@event,1,@nevents);
- end;
- {****************************************************************************
- Initialization code
- ****************************************************************************}
- Initialization
- InitExceptions; { Initialize exceptions. OS independent }
- InitInternational; { Initialize internationalization settings }
- OnBeep:=@SysBeep;
- InitTZ;
- Finalization
- FreeTerminateProcs;
- DoneExceptions;
- end.
|