sysutils.pp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2021 by the Free Pascal development team.
  4. Sysutils unit for The WebAssembly System Interface (WASI).
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {$inline on}
  12. unit sysutils;
  13. interface
  14. {$MODE objfpc}
  15. {$MODESWITCH out}
  16. { force ansistrings }
  17. {$H+}
  18. {$modeswitch typehelpers}
  19. {$modeswitch advancedrecords}
  20. uses
  21. wasiapi;
  22. {$DEFINE HAS_SLEEP}
  23. {$DEFINE HAS_GETTICKCOUNT64}
  24. { used OS file system APIs use ansistring }
  25. {$define SYSUTILS_HAS_ANSISTR_FILEUTIL_IMPL}
  26. { OS has an ansistring/single byte environment variable API }
  27. {$define SYSUTILS_HAS_ANSISTR_ENVVAR_IMPL}
  28. { Include platform independent interface part }
  29. {$i sysutilh.inc}
  30. implementation
  31. uses
  32. sysconst;
  33. {$DEFINE FPC_FEXPAND_UNC} (* UNC paths are supported *)
  34. {$DEFINE FPC_FEXPAND_DRIVES} (* Full paths begin with drive specification *)
  35. {$DEFINE HAS_LOCALTIMEZONEOFFSET}
  36. {$DEFINE executeprocuni} (* Only 1 byte version of ExecuteProcess is provided by the OS *)
  37. { Include platform independent implementation part }
  38. {$i sysutils.inc}
  39. function GetTickCount64: QWord;
  40. var
  41. NanoSecsPast: __wasi_timestamp_t;
  42. begin
  43. if __wasi_clock_time_get(__WASI_CLOCKID_MONOTONIC,1000000,@NanoSecsPast)=__WASI_ERRNO_SUCCESS then
  44. Result:=NanoSecsPast div 1000000
  45. else
  46. Result:=0;
  47. end;
  48. {****************************************************************************
  49. File Functions
  50. ****************************************************************************}
  51. Function FileOpen (Const FileName : RawByteString; Mode : Integer) : THandle;
  52. Begin
  53. end;
  54. Function FileCreate (Const FileName : RawByteString) : THandle;
  55. begin
  56. end;
  57. Function FileCreate (Const FileName : RawByteString; ShareMode:integer; Rights : integer) : THandle;
  58. begin
  59. end;
  60. Function FileCreate (Const FileName : RawByteString; Rights:integer) : THandle;
  61. begin
  62. end;
  63. Function FileRead (Handle : THandle; Out Buffer; Count : longint) : Longint;
  64. begin
  65. end;
  66. Function FileWrite (Handle : THandle; const Buffer; Count : Longint) : Longint;
  67. begin
  68. end;
  69. Function FileSeek (Handle : THandle; FOffset, Origin : Longint) : Longint;
  70. begin
  71. end;
  72. Function FileSeek (Handle : THandle; FOffset: Int64; Origin: {Integer}Longint) : Int64;
  73. begin
  74. end;
  75. Procedure FileClose (Handle : THandle);
  76. begin
  77. end;
  78. Function FileTruncate (Handle: THandle; Size: Int64) : boolean;
  79. begin
  80. end;
  81. Function FileAge (Const FileName : RawByteString): Int64;
  82. begin
  83. end;
  84. function FileGetSymLinkTarget(const FileName: RawByteString; out SymLinkRec: TRawbyteSymLinkRec): Boolean;
  85. begin
  86. Result := False;
  87. end;
  88. function FileExists (const FileName: RawByteString; FollowLink : Boolean): boolean;
  89. begin
  90. end;
  91. Function DirectoryExists (Const Directory : RawByteString; FollowLink : Boolean) : Boolean;
  92. begin
  93. end;
  94. Function InternalFindFirst (Const Path : RawByteString; Attr : Longint; out Rslt : TAbstractSearchRec; var Name: RawByteString) : Longint;
  95. begin
  96. { not yet implemented }
  97. Result := -1;
  98. end;
  99. Function InternalFindNext (var Rslt : TAbstractSearchRec; var Name : RawByteString) : Longint;
  100. begin
  101. { not yet implemented }
  102. Result := -1;
  103. end;
  104. Procedure InternalFindClose(var Handle: THandle);
  105. begin
  106. end;
  107. Function FileGetDate (Handle : THandle) : Int64;
  108. begin
  109. end;
  110. Function FileSetDate (Handle : THandle; Age : Int64) : Longint;
  111. begin
  112. end;
  113. Function FileGetAttr (Const FileName : RawByteString) : Longint;
  114. begin
  115. end;
  116. Function FileSetAttr (Const Filename : RawByteString; Attr: longint) : Longint;
  117. begin
  118. end;
  119. Function DeleteFile (Const FileName : RawByteString) : Boolean;
  120. begin
  121. end;
  122. Function RenameFile (Const OldName, NewName : RawByteString) : Boolean;
  123. begin
  124. end;
  125. {****************************************************************************
  126. Disk Functions
  127. ****************************************************************************}
  128. function diskfree(drive : byte) : int64;
  129. begin
  130. end;
  131. function disksize(drive : byte) : int64;
  132. begin
  133. end;
  134. {****************************************************************************
  135. Time Functions
  136. ****************************************************************************}
  137. {$I tzenv.inc}
  138. Procedure GetLocalTime(var SystemTime: TSystemTime);
  139. begin
  140. end ;
  141. {****************************************************************************
  142. Misc Functions
  143. ****************************************************************************}
  144. procedure sysBeep;
  145. begin
  146. end;
  147. {****************************************************************************
  148. Locale Functions
  149. ****************************************************************************}
  150. procedure InitAnsi;
  151. begin
  152. end;
  153. Procedure InitInternational;
  154. begin
  155. InitInternationalGeneric;
  156. InitAnsi;
  157. end;
  158. function SysErrorMessage(ErrorCode: Integer): String;
  159. begin
  160. Result:=Format(SUnknownErrorCode,[ErrorCode]);
  161. end;
  162. {****************************************************************************
  163. Os utils
  164. ****************************************************************************}
  165. Function GetEnvironmentVariable(Const EnvVar : String) : String;
  166. var
  167. hp : ppchar;
  168. hs : string;
  169. eqpos : longint;
  170. begin
  171. result:='';
  172. hp:=envp;
  173. if hp<>nil then
  174. while assigned(hp^) do
  175. begin
  176. hs:=strpas(hp^);
  177. eqpos:=pos('=',hs);
  178. if copy(hs,1,eqpos-1)=envvar then
  179. begin
  180. result:=copy(hs,eqpos+1,length(hs)-eqpos);
  181. break;
  182. end;
  183. inc(hp);
  184. end;
  185. end;
  186. Function GetEnvironmentVariableCount : Integer;
  187. var
  188. p: ppchar;
  189. begin
  190. result:=0;
  191. p:=envp; {defined in system}
  192. if p<>nil then
  193. while p^<>nil do
  194. begin
  195. inc(result);
  196. inc(p);
  197. end;
  198. end;
  199. Function GetEnvironmentString(Index : Integer) : {$ifdef FPC_RTL_UNICODE}UnicodeString{$else}AnsiString{$endif};
  200. Var
  201. i : longint;
  202. p : ppchar;
  203. begin
  204. if (Index <= 0) or (envp=nil) then
  205. result:=''
  206. else
  207. begin
  208. p:=envp; {defined in system}
  209. i:=1;
  210. while (i<Index) and (p^<>nil) do
  211. begin
  212. inc(i);
  213. inc(p);
  214. end;
  215. if p^=nil then
  216. result:=''
  217. else
  218. result:=strpas(p^)
  219. end;
  220. end;
  221. function ExecuteProcess(Const Path: RawByteString; Const ComLine: RawByteString;Flags:TExecuteFlags=[]):integer;
  222. begin
  223. end;
  224. function ExecuteProcess (const Path: RawByteString;
  225. const ComLine: array of RawByteString;Flags:TExecuteFlags=[]): integer;
  226. begin
  227. end;
  228. {*************************************************************************
  229. Sleep
  230. *************************************************************************}
  231. procedure Sleep (MilliSeconds: Cardinal);
  232. var
  233. subscription: __wasi_subscription_t;
  234. event: __wasi_event_t;
  235. nevents: __wasi_size_t;
  236. begin
  237. FillChar(subscription,SizeOf(subscription),0);
  238. subscription.u.tag:=__WASI_EVENTTYPE_CLOCK;
  239. subscription.u.u.clock.id:=__WASI_CLOCKID_MONOTONIC;
  240. subscription.u.u.clock.timeout:=MilliSeconds*1000000;
  241. subscription.u.u.clock.precision:=1000000;
  242. subscription.u.u.clock.flags:=0; { timeout value is relative }
  243. __wasi_poll_oneoff(@subscription,@event,1,@nevents);
  244. end;
  245. {****************************************************************************
  246. Initialization code
  247. ****************************************************************************}
  248. Initialization
  249. InitExceptions; { Initialize exceptions. OS independent }
  250. InitInternational; { Initialize internationalization settings }
  251. OnBeep:=@SysBeep;
  252. InitTZ;
  253. Finalization
  254. FreeTerminateProcs;
  255. DoneExceptions;
  256. end.