sysutils.pp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  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. Function UniversalToEpoch(year,month,day,hour,minute,second:Word):int64;
  38. const
  39. days_in_month: array [boolean, 1..12] of Byte =
  40. ((31,28,31,30,31,30,31,31,30,31,30,31),
  41. (31,29,31,30,31,30,31,31,30,31,30,31));
  42. days_before_month: array [boolean, 1..12] of Byte =
  43. ((0,
  44. 0+31,
  45. 0+31+28,
  46. 0+31+28+31,
  47. 0+31+28+31+30,
  48. 0+31+28+31+30+31,
  49. 0+31+28+31+30+31+30,
  50. 0+31+28+31+30+31+30+31,
  51. 0+31+28+31+30+31+30+31+31,
  52. 0+31+28+31+30+31+30+31+31+30,
  53. 0+31+28+31+30+31+30+31+31+30+31,
  54. 0+31+28+31+30+31+30+31+31+30+31+30),
  55. (0,
  56. 0+31,
  57. 0+31+29,
  58. 0+31+29+31,
  59. 0+31+29+31+30,
  60. 0+31+29+31+30+31,
  61. 0+31+29+31+30+31+30,
  62. 0+31+29+31+30+31+30+31,
  63. 0+31+29+31+30+31+30+31+31,
  64. 0+31+29+31+30+31+30+31+31+30,
  65. 0+31+29+31+30+31+30+31+31+30+31,
  66. 0+31+29+31+30+31+30+31+31+30+31+30));
  67. var
  68. leap: Boolean;
  69. days_in_year: LongInt;
  70. y,m: LongInt;
  71. begin
  72. if (year<1970) or (month<1) or (month>12) or (day<1) or (day>31) or
  73. (hour>=24) or (minute>=60) or (second>=60) then
  74. begin
  75. result:=-1;
  76. exit;
  77. end;
  78. leap:=((year mod 4)=0) and (((year mod 100)<>0) or ((year mod 400)=0));
  79. if day>days_in_month[leap,month] then
  80. begin
  81. result:=-1;
  82. exit;
  83. end;
  84. result:=0;
  85. for y:=1970 to year-1 do
  86. if ((y mod 4)=0) and (((y mod 100)<>0) or ((y mod 400)=0)) then
  87. Inc(result,366)
  88. else
  89. Inc(result,365);
  90. Inc(result,days_before_month[leap,month]);
  91. Inc(result,day-1);
  92. result:=(((result*24+hour)*60+minute)*60)+second;
  93. end;
  94. Function LocalToEpoch(year,month,day,hour,minute,second:Word):int64;
  95. begin
  96. { todo: convert UTC to local time, as soon as we can get the local timezone
  97. from WASI: https://github.com/WebAssembly/WASI/issues/239 }
  98. result:=UniversalToEpoch(year,month,day,hour,minute,second);
  99. end;
  100. Procedure EpochToUniversal(epoch:int64;var year,month,day,hour,minute,second:Word);
  101. const
  102. days_in_month: array [boolean, 1..12] of Byte =
  103. ((31,28,31,30,31,30,31,31,30,31,30,31),
  104. (31,29,31,30,31,30,31,31,30,31,30,31));
  105. var
  106. leap: Boolean;
  107. days_in_year: LongInt;
  108. begin
  109. if epoch<0 then
  110. begin
  111. year:=0;
  112. month:=0;
  113. day:=0;
  114. hour:=0;
  115. minute:=0;
  116. second:=0;
  117. exit;
  118. end;
  119. second:=epoch mod 60;
  120. epoch:=epoch div 60;
  121. minute:=epoch mod 60;
  122. epoch:=epoch div 60;
  123. hour:=epoch mod 24;
  124. epoch:=epoch div 24;
  125. year:=1970;
  126. leap:=false;
  127. days_in_year:=365;
  128. while epoch>=days_in_year do
  129. begin
  130. Dec(epoch,days_in_year);
  131. Inc(year);
  132. leap:=((year mod 4)=0) and (((year mod 100)<>0) or ((year mod 400)=0));
  133. if leap then
  134. days_in_year:=366
  135. else
  136. days_in_year:=365;
  137. end;
  138. month:=1;
  139. Inc(epoch);
  140. while epoch>days_in_month[leap,month] do
  141. begin
  142. Dec(epoch,days_in_month[leap,month]);
  143. Inc(month);
  144. end;
  145. day:=Word(epoch);
  146. end;
  147. Procedure EpochToLocal(epoch:int64;var year,month,day,hour,minute,second:Word);
  148. begin
  149. { todo: convert UTC to local time, as soon as we can get the local timezone
  150. from WASI: https://github.com/WebAssembly/WASI/issues/239 }
  151. EpochToUniversal(epoch,year,month,day,hour,minute,second);
  152. end;
  153. { Include platform independent implementation part }
  154. {$i sysutils.inc}
  155. function GetTickCount64: QWord;
  156. var
  157. NanoSecsPast: __wasi_timestamp_t;
  158. begin
  159. if __wasi_clock_time_get(__WASI_CLOCKID_MONOTONIC,1000000,@NanoSecsPast)=__WASI_ERRNO_SUCCESS then
  160. Result:=NanoSecsPast div 1000000
  161. else
  162. Result:=0;
  163. end;
  164. {****************************************************************************
  165. File Functions
  166. ****************************************************************************}
  167. Function FileOpen (Const FileName : RawByteString; Mode : Integer) : THandle;
  168. Var
  169. fs_rights_base: __wasi_rights_t = 0;
  170. ourfd: __wasi_fd_t;
  171. res: __wasi_errno_t;
  172. pr: RawByteString;
  173. fd: __wasi_fd_t;
  174. Begin
  175. case (Mode and (fmOpenRead or fmOpenWrite or fmOpenReadWrite)) of
  176. fmOpenRead:
  177. fs_rights_base :=__WASI_RIGHTS_FD_READ or
  178. __WASI_RIGHTS_FD_FILESTAT_GET or
  179. __WASI_RIGHTS_FD_SEEK or
  180. __WASI_RIGHTS_FD_TELL or
  181. __WASI_RIGHTS_FD_FDSTAT_SET_FLAGS or
  182. __WASI_RIGHTS_FD_ADVISE or
  183. __WASI_RIGHTS_POLL_FD_READWRITE;
  184. fmOpenWrite:
  185. fs_rights_base :=__WASI_RIGHTS_FD_WRITE or
  186. __WASI_RIGHTS_FD_FILESTAT_GET or
  187. __WASI_RIGHTS_FD_SEEK or
  188. __WASI_RIGHTS_FD_TELL or
  189. __WASI_RIGHTS_FD_FDSTAT_SET_FLAGS or
  190. __WASI_RIGHTS_FD_ADVISE or
  191. __WASI_RIGHTS_POLL_FD_READWRITE or
  192. __WASI_RIGHTS_FD_FILESTAT_SET_SIZE or
  193. __WASI_RIGHTS_FD_FILESTAT_SET_TIMES or
  194. __WASI_RIGHTS_FD_ALLOCATE or
  195. __WASI_RIGHTS_FD_DATASYNC or
  196. __WASI_RIGHTS_FD_SYNC;
  197. fmOpenReadWrite:
  198. fs_rights_base :=__WASI_RIGHTS_FD_READ or
  199. __WASI_RIGHTS_FD_WRITE or
  200. __WASI_RIGHTS_FD_FILESTAT_GET or
  201. __WASI_RIGHTS_FD_SEEK or
  202. __WASI_RIGHTS_FD_TELL or
  203. __WASI_RIGHTS_FD_FDSTAT_SET_FLAGS or
  204. __WASI_RIGHTS_FD_ADVISE or
  205. __WASI_RIGHTS_POLL_FD_READWRITE or
  206. __WASI_RIGHTS_FD_FILESTAT_SET_SIZE or
  207. __WASI_RIGHTS_FD_FILESTAT_SET_TIMES or
  208. __WASI_RIGHTS_FD_ALLOCATE or
  209. __WASI_RIGHTS_FD_DATASYNC or
  210. __WASI_RIGHTS_FD_SYNC;
  211. end;
  212. if not ConvertToFdRelativePath(FileName,fd,pr) then
  213. begin
  214. result:=-1;
  215. exit;
  216. end;
  217. repeat
  218. res:=__wasi_path_open(fd,
  219. 0,
  220. PChar(pr),
  221. length(pr),
  222. 0,
  223. fs_rights_base,
  224. fs_rights_base,
  225. 0,
  226. @ourfd);
  227. until (res=__WASI_ERRNO_SUCCESS) or (res<>__WASI_ERRNO_INTR);
  228. If res=__WASI_ERRNO_SUCCESS Then
  229. Result:=ourfd
  230. else
  231. Result:=-1;
  232. end;
  233. Function FileCreate (Const FileName : RawByteString) : THandle;
  234. Const
  235. fs_rights_base: __wasi_rights_t =
  236. __WASI_RIGHTS_FD_READ or
  237. __WASI_RIGHTS_FD_WRITE or
  238. __WASI_RIGHTS_FD_FILESTAT_GET or
  239. __WASI_RIGHTS_FD_SEEK or
  240. __WASI_RIGHTS_FD_TELL or
  241. __WASI_RIGHTS_FD_FDSTAT_SET_FLAGS or
  242. __WASI_RIGHTS_FD_ADVISE or
  243. __WASI_RIGHTS_POLL_FD_READWRITE or
  244. __WASI_RIGHTS_FD_FILESTAT_SET_SIZE or
  245. __WASI_RIGHTS_FD_FILESTAT_SET_TIMES or
  246. __WASI_RIGHTS_FD_ALLOCATE or
  247. __WASI_RIGHTS_FD_DATASYNC or
  248. __WASI_RIGHTS_FD_SYNC;
  249. Var
  250. ourfd: __wasi_fd_t;
  251. res: __wasi_errno_t;
  252. pr: RawByteString;
  253. fd: __wasi_fd_t;
  254. Begin
  255. if not ConvertToFdRelativePath(FileName,fd,pr) then
  256. begin
  257. result:=-1;
  258. exit;
  259. end;
  260. repeat
  261. res:=__wasi_path_open(fd,
  262. 0,
  263. PChar(pr),
  264. length(pr),
  265. __WASI_OFLAGS_CREAT or __WASI_OFLAGS_TRUNC,
  266. fs_rights_base,
  267. fs_rights_base,
  268. 0,
  269. @ourfd);
  270. until (res=__WASI_ERRNO_SUCCESS) or (res<>__WASI_ERRNO_INTR);
  271. If res=__WASI_ERRNO_SUCCESS Then
  272. Result:=ourfd
  273. else
  274. Result:=-1;
  275. end;
  276. Function FileCreate (Const FileName : RawByteString; ShareMode:integer; Rights : integer) : THandle;
  277. begin
  278. FileCreate:=FileCreate(FileName);
  279. end;
  280. Function FileCreate (Const FileName : RawByteString; Rights:integer) : THandle;
  281. begin
  282. FileCreate:=FileCreate(FileName);
  283. end;
  284. Function FileRead (Handle : THandle; Out Buffer; Count : longint) : Longint;
  285. var
  286. our_iov: __wasi_iovec_t;
  287. our_nread: __wasi_size_t;
  288. res: __wasi_errno_t;
  289. begin
  290. repeat
  291. our_iov.buf:=@Buffer;
  292. our_iov.buf_len:=Count;
  293. res:=__wasi_fd_read(Handle,@our_iov,1,@our_nread);
  294. until (res=__WASI_ERRNO_SUCCESS) or ((res<>__WASI_ERRNO_INTR) and (res<>__WASI_ERRNO_AGAIN));
  295. if res=__WASI_ERRNO_SUCCESS then
  296. Result:=our_nread
  297. else
  298. Result:=-1;
  299. end;
  300. Function FileWrite (Handle : THandle; const Buffer; Count : Longint) : Longint;
  301. var
  302. our_iov: __wasi_ciovec_t;
  303. our_nwritten: longint;
  304. res: __wasi_errno_t;
  305. begin
  306. repeat
  307. our_iov.buf:=@Buffer;
  308. our_iov.buf_len:=Count;
  309. res:=__wasi_fd_write(Handle,@our_iov,1,@our_nwritten);
  310. until (res=__WASI_ERRNO_SUCCESS) or ((res<>__WASI_ERRNO_INTR) and (res<>__WASI_ERRNO_AGAIN));
  311. if res=__WASI_ERRNO_SUCCESS then
  312. Result:=our_nwritten
  313. else
  314. Result:=-1;
  315. end;
  316. Function FileSeek (Handle : THandle; FOffset, Origin : Longint) : Longint;
  317. begin
  318. result:=longint(FileSeek(Handle,int64(FOffset),Origin));
  319. end;
  320. Function FileSeek (Handle : THandle; FOffset: Int64; Origin: Longint) : Int64;
  321. var
  322. res: __wasi_errno_t;
  323. newoffset: __wasi_filesize_t;
  324. whence: __wasi_whence_t;
  325. begin
  326. case Origin of
  327. fsFromBeginning:
  328. whence:=__WASI_WHENCE_SET;
  329. fsFromCurrent:
  330. whence:=__WASI_WHENCE_CUR;
  331. fsFromEnd:
  332. whence:=__WASI_WHENCE_END;
  333. else
  334. begin
  335. Result:=-1;
  336. exit;
  337. end;
  338. end;
  339. res:=__wasi_fd_seek(Handle,FOffset,whence,@newoffset);
  340. if res=__WASI_ERRNO_SUCCESS then
  341. Result:=newoffset
  342. else
  343. Result:=-1;
  344. end;
  345. Procedure FileClose (Handle : THandle);
  346. var
  347. res: __wasi_errno_t;
  348. begin
  349. repeat
  350. res:=__wasi_fd_close(Handle);
  351. until (res=__WASI_ERRNO_SUCCESS) or (res<>__WASI_ERRNO_INTR);
  352. end;
  353. Function FileTruncate (Handle: THandle; Size: Int64) : boolean;
  354. var
  355. res: __wasi_errno_t;
  356. begin
  357. Result:=__wasi_fd_filestat_set_size(handle,Size)=__WASI_ERRNO_SUCCESS;
  358. end;
  359. Function FileAge (Const FileName : RawByteString): Int64;
  360. var
  361. res: __wasi_errno_t;
  362. pr: RawByteString;
  363. fd: __wasi_fd_t;
  364. Info: __wasi_filestat_t;
  365. begin
  366. if not ConvertToFdRelativePath(FileName,fd,pr) then
  367. begin
  368. result:=-1;
  369. exit;
  370. end;
  371. res:=__wasi_path_filestat_get(fd,0,PChar(pr),length(pr),@Info);
  372. if res=__WASI_ERRNO_SUCCESS then
  373. result:=Info.mtim div 1000000000
  374. else
  375. result:=-1;
  376. end;
  377. function FileGetSymLinkTarget(const FileName: RawByteString; out SymLinkRec: TRawbyteSymLinkRec): Boolean;
  378. begin
  379. Result := False;
  380. end;
  381. function FileExists (const FileName: RawByteString; FollowLink : Boolean): boolean;
  382. begin
  383. end;
  384. Function DirectoryExists (Const Directory : RawByteString; FollowLink : Boolean) : Boolean;
  385. begin
  386. end;
  387. Function InternalFindFirst (Const Path : RawByteString; Attr : Longint; out Rslt : TAbstractSearchRec; var Name: RawByteString) : Longint;
  388. begin
  389. { not yet implemented }
  390. Result := -1;
  391. end;
  392. Function InternalFindNext (var Rslt : TAbstractSearchRec; var Name : RawByteString) : Longint;
  393. begin
  394. { not yet implemented }
  395. Result := -1;
  396. end;
  397. Procedure InternalFindClose(var Handle: THandle);
  398. begin
  399. end;
  400. Function FileGetDate (Handle : THandle) : Int64;
  401. var
  402. res: __wasi_errno_t;
  403. Info: __wasi_filestat_t;
  404. begin
  405. res:=__wasi_fd_filestat_get(Handle,@Info);
  406. if res=__WASI_ERRNO_SUCCESS then
  407. result:=Info.mtim div 1000000000
  408. else
  409. result:=-1;
  410. end;
  411. Function FileSetDate (Handle : THandle; Age : Int64) : Longint;
  412. begin
  413. if __wasi_fd_filestat_set_times(Handle,Age*1000000000,Age*1000000000,
  414. __WASI_FSTFLAGS_MTIM or __WASI_FSTFLAGS_ATIM)=__WASI_ERRNO_SUCCESS then
  415. result:=0
  416. else
  417. result:=-1;
  418. end;
  419. Function FileGetAttr (Const FileName : RawByteString) : Longint;
  420. begin
  421. end;
  422. Function FileSetAttr (Const Filename : RawByteString; Attr: longint) : Longint;
  423. begin
  424. end;
  425. Function DeleteFile (Const FileName : RawByteString) : Boolean;
  426. var
  427. fd: __wasi_fd_t;
  428. pr: RawByteString;
  429. res: __wasi_errno_t;
  430. begin
  431. if not ConvertToFdRelativePath(FileName,fd,pr) then
  432. begin
  433. result:=false;
  434. exit;
  435. end;
  436. result:=__wasi_path_unlink_file(fd,PChar(pr),Length(pr))=__WASI_ERRNO_SUCCESS;
  437. end;
  438. Function RenameFile (Const OldName, NewName : RawByteString) : Boolean;
  439. var
  440. fd1,fd2: __wasi_fd_t;
  441. pr1,pr2: RawByteString;
  442. res: __wasi_errno_t;
  443. begin
  444. result:=false;
  445. if not ConvertToFdRelativePath(OldName,fd1,pr1) then
  446. exit;
  447. if not ConvertToFdRelativePath(NewName,fd2,pr2) then
  448. exit;
  449. result:=__wasi_path_rename(fd1,PChar(pr1),Length(pr1),fd2,PChar(pr2),Length(pr2))=__WASI_ERRNO_SUCCESS;
  450. end;
  451. {****************************************************************************
  452. Disk Functions
  453. ****************************************************************************}
  454. function diskfree(drive : byte) : int64;
  455. begin
  456. end;
  457. function disksize(drive : byte) : int64;
  458. begin
  459. end;
  460. {****************************************************************************
  461. Time Functions
  462. ****************************************************************************}
  463. {$I tzenv.inc}
  464. Procedure GetLocalTime(var SystemTime: TSystemTime);
  465. begin
  466. end ;
  467. {****************************************************************************
  468. Misc Functions
  469. ****************************************************************************}
  470. procedure sysBeep;
  471. begin
  472. end;
  473. {****************************************************************************
  474. Locale Functions
  475. ****************************************************************************}
  476. procedure InitAnsi;
  477. begin
  478. end;
  479. Procedure InitInternational;
  480. begin
  481. InitInternationalGeneric;
  482. InitAnsi;
  483. end;
  484. function SysErrorMessage(ErrorCode: Integer): String;
  485. begin
  486. Result:=Format(SUnknownErrorCode,[ErrorCode]);
  487. end;
  488. {****************************************************************************
  489. Os utils
  490. ****************************************************************************}
  491. Function GetEnvironmentVariable(Const EnvVar : String) : String;
  492. var
  493. hp : ppchar;
  494. hs : string;
  495. eqpos : longint;
  496. begin
  497. result:='';
  498. hp:=envp;
  499. if hp<>nil then
  500. while assigned(hp^) do
  501. begin
  502. hs:=strpas(hp^);
  503. eqpos:=pos('=',hs);
  504. if copy(hs,1,eqpos-1)=envvar then
  505. begin
  506. result:=copy(hs,eqpos+1,length(hs)-eqpos);
  507. break;
  508. end;
  509. inc(hp);
  510. end;
  511. end;
  512. Function GetEnvironmentVariableCount : Integer;
  513. var
  514. p: ppchar;
  515. begin
  516. result:=0;
  517. p:=envp; {defined in system}
  518. if p<>nil then
  519. while p^<>nil do
  520. begin
  521. inc(result);
  522. inc(p);
  523. end;
  524. end;
  525. Function GetEnvironmentString(Index : Integer) : {$ifdef FPC_RTL_UNICODE}UnicodeString{$else}AnsiString{$endif};
  526. Var
  527. i : longint;
  528. p : ppchar;
  529. begin
  530. if (Index <= 0) or (envp=nil) then
  531. result:=''
  532. else
  533. begin
  534. p:=envp; {defined in system}
  535. i:=1;
  536. while (i<Index) and (p^<>nil) do
  537. begin
  538. inc(i);
  539. inc(p);
  540. end;
  541. if p^=nil then
  542. result:=''
  543. else
  544. result:=strpas(p^)
  545. end;
  546. end;
  547. function ExecuteProcess(Const Path: RawByteString; Const ComLine: RawByteString;Flags:TExecuteFlags=[]):integer;
  548. begin
  549. end;
  550. function ExecuteProcess (const Path: RawByteString;
  551. const ComLine: array of RawByteString;Flags:TExecuteFlags=[]): integer;
  552. begin
  553. end;
  554. {*************************************************************************
  555. Sleep
  556. *************************************************************************}
  557. procedure Sleep (MilliSeconds: Cardinal);
  558. var
  559. subscription: __wasi_subscription_t;
  560. event: __wasi_event_t;
  561. nevents: __wasi_size_t;
  562. begin
  563. FillChar(subscription,SizeOf(subscription),0);
  564. subscription.u.tag:=__WASI_EVENTTYPE_CLOCK;
  565. subscription.u.u.clock.id:=__WASI_CLOCKID_MONOTONIC;
  566. subscription.u.u.clock.timeout:=MilliSeconds*1000000;
  567. subscription.u.u.clock.precision:=1000000;
  568. subscription.u.u.clock.flags:=0; { timeout value is relative }
  569. __wasi_poll_oneoff(@subscription,@event,1,@nevents);
  570. end;
  571. {****************************************************************************
  572. Initialization code
  573. ****************************************************************************}
  574. Initialization
  575. InitExceptions; { Initialize exceptions. OS independent }
  576. InitInternational; { Initialize internationalization settings }
  577. OnBeep:=@SysBeep;
  578. InitTZ;
  579. Finalization
  580. FreeTerminateProcs;
  581. DoneExceptions;
  582. end.