syswin32.pp 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Florian Klaempfl and Pavel Ozerski
  5. member of the Free Pascal development team.
  6. FPC Pascal system unit for the Win32 API.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. unit syswin32;
  14. interface
  15. {$ifdef SYSTEMDEBUG}
  16. {$define SYSTEMEXCEPTIONDEBUG}
  17. {$endif SYSTEMDEBUG}
  18. {$ifdef i386}
  19. {$define Set_i386_Exception_handler}
  20. {$endif i386}
  21. { include system-independent routine headers }
  22. {$I systemh.inc}
  23. { include heap support headers }
  24. {$I heaph.inc}
  25. const
  26. { Default filehandles }
  27. UnusedHandle : longint = -1;
  28. StdInputHandle : longint = 0;
  29. StdOutputHandle : longint = 0;
  30. StdErrorHandle : longint = 0;
  31. FileNameCaseSensitive : boolean = true;
  32. type
  33. TStartupInfo=packed record
  34. cb : longint;
  35. lpReserved : Pointer;
  36. lpDesktop : Pointer;
  37. lpTitle : Pointer;
  38. dwX : longint;
  39. dwY : longint;
  40. dwXSize : longint;
  41. dwYSize : longint;
  42. dwXCountChars : longint;
  43. dwYCountChars : longint;
  44. dwFillAttribute : longint;
  45. dwFlags : longint;
  46. wShowWindow : Word;
  47. cbReserved2 : Word;
  48. lpReserved2 : Pointer;
  49. hStdInput : longint;
  50. hStdOutput : longint;
  51. hStdError : longint;
  52. end;
  53. var
  54. { C compatible arguments }
  55. argc : longint;
  56. argv : ppchar;
  57. { Win32 Info }
  58. startupinfo : tstartupinfo;
  59. hprevinst,
  60. HInstance,
  61. MainInstance,
  62. cmdshow : longint;
  63. DLLreason,DLLparam:longint;
  64. Win32StackTop : Dword;
  65. { Thread count for DLL }
  66. const
  67. Thread_count : longint = 0;
  68. type
  69. TDLL_Process_Entry_Hook = function (dllparam : longint) : longbool;
  70. TDLL_Entry_Hook = procedure (dllparam : longint);
  71. const
  72. Dll_Process_Attach_Hook : TDLL_Process_Entry_Hook = nil;
  73. Dll_Process_Detach_Hook : TDLL_Entry_Hook = nil;
  74. Dll_Thread_Attach_Hook : TDLL_Entry_Hook = nil;
  75. Dll_Thread_Detach_Hook : TDLL_Entry_Hook = nil;
  76. implementation
  77. { include system independent routines }
  78. {$I system.inc}
  79. { some declarations for Win32 API calls }
  80. {$I win32.inc}
  81. CONST
  82. { These constants are used for conversion of error codes }
  83. { from win32 i/o errors to tp i/o errors }
  84. { errors 1 to 18 are the same as in Turbo Pascal }
  85. { DO NOT MODIFY UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING! }
  86. { The media is write protected. }
  87. ERROR_WRITE_PROTECT = 19;
  88. { The system cannot find the device specified. }
  89. ERROR_BAD_UNIT = 20;
  90. { The device is not ready. }
  91. ERROR_NOT_READY = 21;
  92. { The device does not recognize the command. }
  93. ERROR_BAD_COMMAND = 22;
  94. { Data error (cyclic redundancy check) }
  95. ERROR_CRC = 23;
  96. { The program issued a command but the }
  97. { command length is incorrect. }
  98. ERROR_BAD_LENGTH = 24;
  99. { The drive cannot locate a specific }
  100. { area or track on the disk. }
  101. ERROR_SEEK = 25;
  102. { The specified disk or diskette cannot be accessed. }
  103. ERROR_NOT_DOS_DISK = 26;
  104. { The drive cannot find the sector requested. }
  105. ERROR_SECTOR_NOT_FOUND = 27;
  106. { The printer is out of paper. }
  107. ERROR_OUT_OF_PAPER = 28;
  108. { The system cannot write to the specified device. }
  109. ERROR_WRITE_FAULT = 29;
  110. { The system cannot read from the specified device. }
  111. ERROR_READ_FAULT = 30;
  112. { A device attached to the system is not functioning.}
  113. ERROR_GEN_FAILURE = 31;
  114. { The process cannot access the file because }
  115. { it is being used by another process. }
  116. ERROR_SHARING_VIOLATION = 32;
  117. var
  118. errno : longint;
  119. {$ASMMODE ATT}
  120. { misc. functions }
  121. function GetLastError : DWORD;
  122. external 'kernel32' name 'GetLastError';
  123. { time and date functions }
  124. function GetTickCount : longint;
  125. external 'kernel32' name 'GetTickCount';
  126. { process functions }
  127. procedure ExitProcess(uExitCode : UINT);
  128. external 'kernel32' name 'ExitProcess';
  129. Procedure Errno2InOutRes;
  130. Begin
  131. { DO NOT MODIFY UNLESS YOU KNOW EXACTLY WHAT YOU ARE DOING }
  132. if (errno >= ERROR_WRITE_PROTECT) and (errno <= ERROR_GEN_FAILURE) THEN
  133. BEGIN
  134. { This is the offset to the Win32 to add to directly map }
  135. { to the DOS/TP compatible error codes when in this range }
  136. InOutRes := word(errno)+131;
  137. END
  138. else
  139. { This case is special }
  140. if errno=ERROR_SHARING_VIOLATION THEN
  141. BEGIN
  142. InOutRes :=5;
  143. END
  144. else
  145. { other error codes can directly be mapped }
  146. InOutRes := Word(errno);
  147. errno:=0;
  148. end;
  149. {$ifdef dummy}
  150. procedure int_stackcheck(stack_size:longint);[public,alias: 'STACKCHECK'];
  151. {
  152. called when trying to get local stack if the compiler directive $S
  153. is set this function must preserve esi !!!! because esi is set by
  154. the calling proc for methods it must preserve all registers !!
  155. With a 2048 byte safe area used to write to StdIo without crossing
  156. the stack boundary
  157. }
  158. begin
  159. asm
  160. pushl %eax
  161. pushl %ebx
  162. movl stack_size,%ebx
  163. addl $2048,%ebx
  164. movl %esp,%eax
  165. subl %ebx,%eax
  166. movl stacklimit,%ebx
  167. cmpl %eax,%ebx
  168. jae .L__short_on_stack
  169. popl %ebx
  170. popl %eax
  171. leave
  172. ret $4
  173. .L__short_on_stack:
  174. { can be usefull for error recovery !! }
  175. popl %ebx
  176. popl %eax
  177. end['EAX','EBX'];
  178. HandleError(202);
  179. end;
  180. {$endif dummy}
  181. function paramcount : longint;
  182. begin
  183. paramcount := argc - 1;
  184. end;
  185. { module functions }
  186. function GetModuleFileName(l1:longint;p:pointer;l2:longint):longint;
  187. external 'kernel32' name 'GetModuleFileNameA';
  188. function GetModuleHandle(p : pointer) : longint;
  189. external 'kernel32' name 'GetModuleHandleA';
  190. function GetCommandFile:pchar;forward;
  191. function paramstr(l : longint) : string;
  192. begin
  193. if (l>=0) and (l<argc) then
  194. paramstr:=strpas(argv[l])
  195. else
  196. paramstr:='';
  197. end;
  198. procedure randomize;
  199. begin
  200. randseed:=GetTickCount;
  201. end;
  202. {*****************************************************************************
  203. Heap Management
  204. *****************************************************************************}
  205. { memory functions }
  206. function GetProcessHeap : DWord;
  207. external 'kernel32' name 'GetProcessHeap';
  208. function HeapAlloc(hHeap : DWord; dwFlags : DWord; dwBytes : DWord) : Longint;
  209. external 'kernel32' name 'HeapAlloc';
  210. {$IFDEF SYSTEMDEBUG}
  211. function HeapSize(hHeap : DWord; dwFlags : DWord; ptr : Pointer) : DWord;
  212. external 'kernel32' name 'HeapSize';
  213. {$ENDIF}
  214. var
  215. heap : longint;external name 'HEAP';
  216. intern_heapsize : longint;external name 'HEAPSIZE';
  217. function getheapstart:pointer;assembler;
  218. asm
  219. leal HEAP,%eax
  220. end ['EAX'];
  221. function getheapsize:longint;assembler;
  222. asm
  223. movl intern_HEAPSIZE,%eax
  224. end ['EAX'];
  225. function Sbrk(size : longint):longint;
  226. var
  227. l : longint;
  228. begin
  229. l := HeapAlloc(GetProcessHeap(), 0, size);
  230. if (l = 0) then
  231. l := -1;
  232. {$ifdef DUMPGROW}
  233. Writeln('new heap part at $',hexstr(l,8), ' size = ',HeapSize(GetProcessHeap()));
  234. {$endif}
  235. sbrk:=l;
  236. end;
  237. { include standard heap management }
  238. {$I heap.inc}
  239. {*****************************************************************************
  240. Low Level File Routines
  241. *****************************************************************************}
  242. function WriteFile(fh:longint;buf:pointer;len:longint;var loaded:longint;
  243. overlap:pointer):longint;
  244. external 'kernel32' name 'WriteFile';
  245. function ReadFile(fh:longint;buf:pointer;len:longint;var loaded:longint;
  246. overlap:pointer):longint;
  247. external 'kernel32' name 'ReadFile';
  248. function CloseHandle(h : longint) : longint;
  249. external 'kernel32' name 'CloseHandle';
  250. function DeleteFile(p : pchar) : longint;
  251. external 'kernel32' name 'DeleteFileA';
  252. function MoveFile(old,_new : pchar) : longint;
  253. external 'kernel32' name 'MoveFileA';
  254. function SetFilePointer(l1,l2 : longint;l3 : pointer;l4 : longint) : longint;
  255. external 'kernel32' name 'SetFilePointer';
  256. function GetFileSize(h:longint;p:pointer) : longint;
  257. external 'kernel32' name 'GetFileSize';
  258. function CreateFile(name : pointer;access,sharing : longint;
  259. security : pointer;how,attr,template : longint) : longint;
  260. external 'kernel32' name 'CreateFileA';
  261. function SetEndOfFile(h : longint) : longbool;
  262. external 'kernel32' name 'SetEndOfFile';
  263. function GetFileType(Handle:DWORD):DWord;
  264. external 'kernel32' name 'GetFileType';
  265. procedure AllowSlash(p:pchar);
  266. var
  267. i : longint;
  268. begin
  269. { allow slash as backslash }
  270. for i:=0 to strlen(p) do
  271. if p[i]='/' then p[i]:='\';
  272. end;
  273. function do_isdevice(handle:longint):boolean;
  274. begin
  275. do_isdevice:=(getfiletype(handle)=2);
  276. end;
  277. procedure do_close(h : longint);
  278. begin
  279. if do_isdevice(h) then
  280. exit;
  281. CloseHandle(h);
  282. end;
  283. procedure do_erase(p : pchar);
  284. begin
  285. AllowSlash(p);
  286. if DeleteFile(p)=0 then
  287. Begin
  288. errno:=GetLastError;
  289. Errno2InoutRes;
  290. end;
  291. end;
  292. procedure do_rename(p1,p2 : pchar);
  293. begin
  294. AllowSlash(p1);
  295. AllowSlash(p2);
  296. if MoveFile(p1,p2)=0 then
  297. Begin
  298. errno:=GetLastError;
  299. Errno2InoutRes;
  300. end;
  301. end;
  302. function do_write(h,addr,len : longint) : longint;
  303. var
  304. size:longint;
  305. begin
  306. if writefile(h,pointer(addr),len,size,nil)=0 then
  307. Begin
  308. errno:=GetLastError;
  309. Errno2InoutRes;
  310. end;
  311. do_write:=size;
  312. end;
  313. function do_read(h,addr,len : longint) : longint;
  314. var
  315. _result:longint;
  316. begin
  317. if readfile(h,pointer(addr),len,_result,nil)=0 then
  318. Begin
  319. errno:=GetLastError;
  320. Errno2InoutRes;
  321. end;
  322. do_read:=_result;
  323. end;
  324. function do_filepos(handle : longint) : longint;
  325. var
  326. l:longint;
  327. begin
  328. l:=SetFilePointer(handle,0,nil,FILE_CURRENT);
  329. if l=-1 then
  330. begin
  331. l:=0;
  332. errno:=GetLastError;
  333. Errno2InoutRes;
  334. end;
  335. do_filepos:=l;
  336. end;
  337. procedure do_seek(handle,pos : longint);
  338. begin
  339. if SetFilePointer(handle,pos,nil,FILE_BEGIN)=-1 then
  340. Begin
  341. errno:=GetLastError;
  342. Errno2InoutRes;
  343. end;
  344. end;
  345. function do_seekend(handle:longint):longint;
  346. begin
  347. do_seekend:=SetFilePointer(handle,0,nil,FILE_END);
  348. if do_seekend=-1 then
  349. begin
  350. errno:=GetLastError;
  351. Errno2InoutRes;
  352. end;
  353. end;
  354. function do_filesize(handle : longint) : longint;
  355. var
  356. aktfilepos : longint;
  357. begin
  358. aktfilepos:=do_filepos(handle);
  359. do_filesize:=do_seekend(handle);
  360. do_seek(handle,aktfilepos);
  361. end;
  362. procedure do_truncate (handle,pos:longint);
  363. begin
  364. do_seek(handle,pos);
  365. if not(SetEndOfFile(handle)) then
  366. begin
  367. errno:=GetLastError;
  368. Errno2InoutRes;
  369. end;
  370. end;
  371. procedure do_open(var f;p : pchar;flags:longint);
  372. {
  373. filerec and textrec have both handle and mode as the first items so
  374. they could use the same routine for opening/creating.
  375. when (flags and $100) the file will be append
  376. when (flags and $1000) the file will be truncate/rewritten
  377. when (flags and $10000) there is no check for close (needed for textfiles)
  378. }
  379. Const
  380. file_Share_Read = $00000001;
  381. file_Share_Write = $00000002;
  382. Var
  383. shflags,
  384. oflags,cd : longint;
  385. begin
  386. AllowSlash(p);
  387. { close first if opened }
  388. if ((flags and $10000)=0) then
  389. begin
  390. case filerec(f).mode of
  391. fminput,fmoutput,fminout : Do_Close(filerec(f).handle);
  392. fmclosed : ;
  393. else
  394. begin
  395. {not assigned}
  396. inoutres:=102;
  397. exit;
  398. end;
  399. end;
  400. end;
  401. { reset file handle }
  402. filerec(f).handle:=UnusedHandle;
  403. { convert filesharing }
  404. shflags:=0;
  405. if ((filemode and fmshareExclusive) = fmshareExclusive) then
  406. { no sharing }
  407. else
  408. if (filemode = fmShareCompat) or ((filemode and fmshareDenyWrite) = fmshareDenyWrite) then
  409. shflags := file_Share_Read
  410. else
  411. if ((filemode and fmshareDenyRead) = fmshareDenyRead) then
  412. shflags := file_Share_Write
  413. else
  414. if ((filemode and fmshareDenyNone) = fmshareDenyNone) then
  415. shflags := file_Share_Read + file_Share_Write;
  416. { convert filemode to filerec modes }
  417. case (flags and 3) of
  418. 0 : begin
  419. filerec(f).mode:=fminput;
  420. oflags:=GENERIC_READ;
  421. end;
  422. 1 : begin
  423. filerec(f).mode:=fmoutput;
  424. oflags:=GENERIC_WRITE;
  425. end;
  426. 2 : begin
  427. filerec(f).mode:=fminout;
  428. oflags:=GENERIC_WRITE or GENERIC_READ;
  429. end;
  430. end;
  431. { standard is opening and existing file }
  432. cd:=OPEN_EXISTING;
  433. { create it ? }
  434. if (flags and $1000)<>0 then
  435. cd:=CREATE_ALWAYS
  436. { or append ? }
  437. else
  438. if (flags and $100)<>0 then
  439. cd:=OPEN_ALWAYS;
  440. { empty name is special }
  441. if p[0]=#0 then
  442. begin
  443. case FileRec(f).mode of
  444. fminput :
  445. FileRec(f).Handle:=StdInputHandle;
  446. fminout, { this is set by rewrite }
  447. fmoutput :
  448. FileRec(f).Handle:=StdOutputHandle;
  449. fmappend :
  450. begin
  451. FileRec(f).Handle:=StdOutputHandle;
  452. FileRec(f).mode:=fmoutput; {fool fmappend}
  453. end;
  454. end;
  455. exit;
  456. end;
  457. filerec(f).handle:=CreateFile(p,oflags,shflags,nil,cd,FILE_ATTRIBUTE_NORMAL,0);
  458. { append mode }
  459. if (flags and $100)<>0 then
  460. begin
  461. do_seekend(filerec(f).handle);
  462. filerec(f).mode:=fmoutput; {fool fmappend}
  463. end;
  464. { get errors }
  465. { handle -1 is returned sometimes !! (PM) }
  466. if (filerec(f).handle=0) or (filerec(f).handle=-1) then
  467. begin
  468. errno:=GetLastError;
  469. Errno2InoutRes;
  470. end;
  471. end;
  472. {*****************************************************************************
  473. UnTyped File Handling
  474. *****************************************************************************}
  475. {$i file.inc}
  476. {*****************************************************************************
  477. Typed File Handling
  478. *****************************************************************************}
  479. {$i typefile.inc}
  480. {*****************************************************************************
  481. Text File Handling
  482. *****************************************************************************}
  483. {$DEFINE EOF_CTRLZ}
  484. {$i text.inc}
  485. {*****************************************************************************
  486. Directory Handling
  487. *****************************************************************************}
  488. function CreateDirectory(name : pointer;sec : pointer) : longint;
  489. external 'kernel32' name 'CreateDirectoryA';
  490. function RemoveDirectory(name:pointer):longint;
  491. external 'kernel32' name 'RemoveDirectoryA';
  492. function SetCurrentDirectory(name : pointer) : longint;
  493. external 'kernel32' name 'SetCurrentDirectoryA';
  494. function GetCurrentDirectory(bufsize : longint;name : pchar) : longint;
  495. external 'kernel32' name 'GetCurrentDirectoryA';
  496. type
  497. TDirFnType=function(name:pointer):word;
  498. procedure dirfn(afunc : TDirFnType;const s:string);
  499. var
  500. buffer : array[0..255] of char;
  501. begin
  502. move(s[1],buffer,length(s));
  503. buffer[length(s)]:=#0;
  504. AllowSlash(pchar(@buffer));
  505. if aFunc(@buffer)=0 then
  506. begin
  507. errno:=GetLastError;
  508. Errno2InoutRes;
  509. end;
  510. end;
  511. function CreateDirectoryTrunc(name:pointer):word;
  512. begin
  513. CreateDirectoryTrunc:=CreateDirectory(name,nil);
  514. end;
  515. procedure mkdir(const s:string);[IOCHECK];
  516. begin
  517. If InOutRes <> 0 then exit;
  518. dirfn(TDirFnType(@CreateDirectoryTrunc),s);
  519. end;
  520. procedure rmdir(const s:string);[IOCHECK];
  521. begin
  522. If InOutRes <> 0 then exit;
  523. dirfn(TDirFnType(@RemoveDirectory),s);
  524. end;
  525. procedure chdir(const s:string);[IOCHECK];
  526. begin
  527. If InOutRes <> 0 then exit;
  528. dirfn(TDirFnType(@SetCurrentDirectory),s);
  529. end;
  530. procedure getdir(drivenr:byte;var dir:shortstring);
  531. const
  532. Drive:array[0..3]of char=(#0,':',#0,#0);
  533. var
  534. defaultdrive:boolean;
  535. DirBuf,SaveBuf:array[0..259] of Char;
  536. begin
  537. defaultdrive:=drivenr=0;
  538. if not defaultdrive then
  539. begin
  540. byte(Drive[0]):=Drivenr+64;
  541. GetCurrentDirectory(SizeOf(SaveBuf),SaveBuf);
  542. SetCurrentDirectory(@Drive);
  543. end;
  544. GetCurrentDirectory(SizeOf(DirBuf),DirBuf);
  545. if not defaultdrive then
  546. SetCurrentDirectory(@SaveBuf);
  547. dir:=strpas(DirBuf);
  548. if not FileNameCaseSensitive then
  549. dir:=upcase(dir);
  550. end;
  551. {*****************************************************************************
  552. SystemUnit Initialization
  553. *****************************************************************************}
  554. { Startup }
  555. procedure GetStartupInfo(p : pointer);
  556. external 'kernel32' name 'GetStartupInfoA';
  557. function GetStdHandle(nStdHandle:DWORD):THANDLE;
  558. external 'kernel32' name 'GetStdHandle';
  559. { command line/enviroment functions }
  560. function GetCommandLine : pchar;
  561. external 'kernel32' name 'GetCommandLineA';
  562. var
  563. ModuleName : array[0..255] of char;
  564. function GetCommandFile:pchar;
  565. begin
  566. GetModuleFileName(0,@ModuleName,255);
  567. GetCommandFile:=@ModuleName;
  568. end;
  569. procedure setup_arguments;
  570. var
  571. arglen,
  572. count : longint;
  573. argstart,
  574. pc : pchar;
  575. quote : set of char;
  576. argsbuf : array[0..127] of pchar;
  577. begin
  578. { create commandline, it starts with the executed filename which is argv[0] }
  579. { Win32 passes the command NOT via the args, but via getmodulefilename}
  580. count:=0;
  581. pc:=getcommandfile;
  582. Arglen:=0;
  583. repeat
  584. Inc(Arglen);
  585. until (pc[Arglen]=#0);
  586. getmem(argsbuf[count],arglen+1);
  587. move(pc^,argsbuf[count]^,arglen);
  588. { Now skip the first one }
  589. pc:=GetCommandLine;
  590. repeat
  591. { skip leading spaces }
  592. while pc^ in [' ',#9,#13] do
  593. inc(pc);
  594. case pc^ of
  595. #0 : break;
  596. '"' : begin
  597. quote:=['"'];
  598. inc(pc);
  599. end;
  600. '''' : begin
  601. quote:=[''''];
  602. inc(pc);
  603. end;
  604. else
  605. quote:=[' ',#9,#13];
  606. end;
  607. { scan until the end of the argument }
  608. argstart:=pc;
  609. while (pc^<>#0) and not(pc^ in quote) do
  610. inc(pc);
  611. { Don't copy the first one, it is already there.}
  612. If Count<>0 then
  613. begin
  614. { reserve some memory }
  615. arglen:=pc-argstart;
  616. getmem(argsbuf[count],arglen+1);
  617. move(argstart^,argsbuf[count]^,arglen);
  618. argsbuf[count][arglen]:=#0;
  619. end;
  620. { skip quote }
  621. if pc^ in quote then
  622. inc(pc);
  623. inc(count);
  624. until false;
  625. { create argc }
  626. argc:=count;
  627. { create an nil entry }
  628. argsbuf[count]:=nil;
  629. inc(count);
  630. { create the argv }
  631. getmem(argv,count shl 2);
  632. move(argsbuf,argv^,count shl 2);
  633. { Setup cmdline variable }
  634. cmdline:=GetCommandLine;
  635. end;
  636. {*****************************************************************************
  637. System Dependent Exit code
  638. *****************************************************************************}
  639. procedure install_exception_handlers;forward;
  640. procedure remove_exception_handlers;forward;
  641. procedure PascalMain;external name 'PASCALMAIN';
  642. procedure fpc_do_exit;external name 'FPC_DO_EXIT';
  643. Procedure ExitDLL(Exitcode : longint); forward;
  644. Procedure system_exit;
  645. begin
  646. { don't call ExitProcess inside
  647. the DLL exit code !!
  648. This crashes Win95 at least PM }
  649. if IsLibrary then
  650. ExitDLL(ExitCode);
  651. if not IsConsole then
  652. begin
  653. Close(stderr);
  654. Close(stdout);
  655. { what about Input and Output ?? PM }
  656. end;
  657. remove_exception_handlers;
  658. ExitProcess(ExitCode);
  659. end;
  660. {$ifdef dummy}
  661. Function SetUpStack : longint;
  662. { This routine does the following : }
  663. { returns the value of the initial SP - __stklen }
  664. begin
  665. asm
  666. pushl %ebx
  667. pushl %eax
  668. movl __stklen,%ebx
  669. movl %esp,%eax
  670. subl %ebx,%eax
  671. movl %eax,__RESULT
  672. popl %eax
  673. popl %ebx
  674. end;
  675. end;
  676. {$endif}
  677. var
  678. { value of the stack segment
  679. to check if the call stack can be written on exceptions }
  680. _SS : longint;
  681. const
  682. fpucw : word = $1332;
  683. procedure Exe_entry;[public, alias : '_FPC_EXE_Entry'];
  684. begin
  685. IsLibrary:=false;
  686. { install the handlers for exe only ?
  687. or should we install them for DLL also ? (PM) }
  688. install_exception_handlers;
  689. { This strange construction is needed to solve the _SS problem
  690. with a smartlinked syswin32 (PFV) }
  691. asm
  692. pushl %ebp
  693. xorl %ebp,%ebp
  694. movl %esp,%eax
  695. movl %eax,Win32StackTop
  696. movw %ss,%bp
  697. movl %ebp,_SS
  698. fninit
  699. fldcw fpucw
  700. xorl %ebp,%ebp
  701. call PASCALMAIN
  702. popl %ebp
  703. end;
  704. { if we pass here there was no error ! }
  705. system_exit;
  706. end;
  707. Const
  708. { DllEntryPoint }
  709. DLL_PROCESS_ATTACH = 1;
  710. DLL_THREAD_ATTACH = 2;
  711. DLL_PROCESS_DETACH = 0;
  712. DLL_THREAD_DETACH = 3;
  713. Var
  714. DLLBuf : Jmp_buf;
  715. Const
  716. DLLExitOK : boolean = true;
  717. function Dll_entry : longbool;[public, alias : '_FPC_DLL_Entry'];
  718. var
  719. res : longbool;
  720. begin
  721. IsLibrary:=true;
  722. Dll_entry:=false;
  723. case DLLreason of
  724. DLL_PROCESS_ATTACH :
  725. begin
  726. If SetJmp(DLLBuf) = 0 then
  727. begin
  728. if assigned(Dll_Process_Attach_Hook) then
  729. begin
  730. res:=Dll_Process_Attach_Hook(DllParam);
  731. if not res then
  732. exit(false);
  733. end;
  734. PASCALMAIN;
  735. Dll_entry:=true;
  736. end
  737. else
  738. Dll_entry:=DLLExitOK;
  739. end;
  740. DLL_THREAD_ATTACH :
  741. begin
  742. inc(Thread_count);
  743. if assigned(Dll_Thread_Attach_Hook) then
  744. Dll_Thread_Attach_Hook(DllParam);
  745. Dll_entry:=true; { return value is ignored }
  746. end;
  747. DLL_THREAD_DETACH :
  748. begin
  749. dec(Thread_count);
  750. if assigned(Dll_Thread_Detach_Hook) then
  751. Dll_Thread_Detach_Hook(DllParam);
  752. Dll_entry:=true; { return value is ignored }
  753. end;
  754. DLL_PROCESS_DETACH :
  755. begin
  756. Dll_entry:=true; { return value is ignored }
  757. If SetJmp(DLLBuf) = 0 then
  758. begin
  759. FPC_DO_EXIT;
  760. end;
  761. if assigned(Dll_Process_Detach_Hook) then
  762. Dll_Process_Detach_Hook(DllParam);
  763. end;
  764. end;
  765. end;
  766. Procedure ExitDLL(Exitcode : longint);
  767. begin
  768. DLLExitOK:=ExitCode=0;
  769. LongJmp(DLLBuf,1);
  770. end;
  771. {$ifdef Set_i386_Exception_handler}
  772. const
  773. EXCEPTION_MAXIMUM_PARAMETERS = 15;
  774. EXCEPTION_ACCESS_VIOLATION = $c0000005;
  775. EXCEPTION_BREAKPOINT = $80000003;
  776. EXCEPTION_DATATYPE_MISALIGNMENT = $80000002;
  777. EXCEPTION_SINGLE_STEP = $80000004;
  778. EXCEPTION_ARRAY_BOUNDS_EXCEEDED = $c000008c;
  779. EXCEPTION_FLT_DENORMAL_OPERAND = $c000008d;
  780. EXCEPTION_FLT_DIVIDE_BY_ZERO = $c000008e;
  781. EXCEPTION_FLT_INEXACT_RESULT = $c000008f;
  782. EXCEPTION_FLT_INVALID_OPERATION = $c0000090;
  783. EXCEPTION_FLT_OVERFLOW = $c0000091;
  784. EXCEPTION_FLT_STACK_CHECK = $c0000092;
  785. EXCEPTION_FLT_UNDERFLOW = $c0000093;
  786. EXCEPTION_INT_DIVIDE_BY_ZERO = $c0000094;
  787. EXCEPTION_INT_OVERFLOW = $c0000095;
  788. EXCEPTION_INVALID_HANDLE = $c0000008;
  789. EXCEPTION_PRIV_INSTRUCTION = $c0000096;
  790. EXCEPTION_NONCONTINUABLE_EXCEPTION = $c0000025;
  791. EXCEPTION_NONCONTINUABLE = $1;
  792. EXCEPTION_STACK_OVERFLOW = $c00000fd;
  793. EXCEPTION_INVALID_DISPOSITION = $c0000026;
  794. EXCEPTION_ILLEGAL_INSTRUCTION = $C000001D;
  795. EXCEPTION_IN_PAGE_ERROR = $C0000006;
  796. EXCEPTION_EXECUTE_HANDLER = 1;
  797. EXCEPTION_CONTINUE_EXECUTION = -(1);
  798. EXCEPTION_CONTINUE_SEARCH = 0;
  799. type
  800. FLOATING_SAVE_AREA = record
  801. ControlWord : DWORD;
  802. StatusWord : DWORD;
  803. TagWord : DWORD;
  804. ErrorOffset : DWORD;
  805. ErrorSelector : DWORD;
  806. DataOffset : DWORD;
  807. DataSelector : DWORD;
  808. RegisterArea : array[0..79] of BYTE;
  809. Cr0NpxState : DWORD;
  810. end;
  811. _FLOATING_SAVE_AREA = FLOATING_SAVE_AREA;
  812. TFLOATINGSAVEAREA = FLOATING_SAVE_AREA;
  813. PFLOATINGSAVEAREA = ^FLOATING_SAVE_AREA;
  814. CONTEXT = record
  815. ContextFlags : DWORD;
  816. Dr0 : DWORD;
  817. Dr1 : DWORD;
  818. Dr2 : DWORD;
  819. Dr3 : DWORD;
  820. Dr6 : DWORD;
  821. Dr7 : DWORD;
  822. FloatSave : FLOATING_SAVE_AREA;
  823. SegGs : DWORD;
  824. SegFs : DWORD;
  825. SegEs : DWORD;
  826. SegDs : DWORD;
  827. Edi : DWORD;
  828. Esi : DWORD;
  829. Ebx : DWORD;
  830. Edx : DWORD;
  831. Ecx : DWORD;
  832. Eax : DWORD;
  833. Ebp : DWORD;
  834. Eip : DWORD;
  835. SegCs : DWORD;
  836. EFlags : DWORD;
  837. Esp : DWORD;
  838. SegSs : DWORD;
  839. end;
  840. LPCONTEXT = ^CONTEXT;
  841. _CONTEXT = CONTEXT;
  842. TCONTEXT = CONTEXT;
  843. PCONTEXT = ^CONTEXT;
  844. type pexception_record = ^exception_record;
  845. EXCEPTION_RECORD = record
  846. ExceptionCode : longint;
  847. ExceptionFlags : longint;
  848. ExceptionRecord : pexception_record;
  849. ExceptionAddress : pointer;
  850. NumberParameters : longint;
  851. ExceptionInformation : array[0..EXCEPTION_MAXIMUM_PARAMETERS-1] of pointer;
  852. end;
  853. PEXCEPTION_POINTERS = ^EXCEPTION_POINTERS;
  854. EXCEPTION_POINTERS = record
  855. ExceptionRecord : PEXCEPTION_RECORD ;
  856. ContextRecord : PCONTEXT ;
  857. end;
  858. { type of functions that should be used for exception handling }
  859. LPTOP_LEVEL_EXCEPTION_FILTER = function(excep :PEXCEPTION_POINTERS) : longint;
  860. function SetUnhandledExceptionFilter(lpTopLevelExceptionFilter : LPTOP_LEVEL_EXCEPTION_FILTER)
  861. : LPTOP_LEVEL_EXCEPTION_FILTER;
  862. external 'kernel32' name 'SetUnhandledExceptionFilter';
  863. const
  864. MAX_Level = 16;
  865. except_level : byte = 0;
  866. var
  867. except_eip : array[0..Max_level-1] of longint;
  868. except_error : array[0..Max_level-1] of byte;
  869. reset_fpu : array[0..max_level-1] of boolean;
  870. {$ifdef SYSTEMEXCEPTIONDEBUG}
  871. procedure DebugHandleErrorAddrFrame(error, addr, frame : longint);
  872. begin
  873. if IsConsole then
  874. begin
  875. write(stderr,'call to HandleErrorAddrFrame(error=',error);
  876. write(stderr,',addr=',hexstr(addr,8));
  877. writeln(stderr,',frame=',hexstr(frame,8),')');
  878. end;
  879. HandleErrorAddrFrame(error,addr,frame);
  880. end;
  881. {$endif SYSTEMEXCEPTIONDEBUG}
  882. procedure JumpToHandleErrorFrame;
  883. var
  884. eip,ebp,error : longint;
  885. begin
  886. asm
  887. movl (%ebp),%eax
  888. movl %eax,ebp
  889. end;
  890. if except_level>0 then
  891. dec(except_level);
  892. eip:=except_eip[except_level];
  893. error:=except_error[except_level];
  894. {$ifdef SYSTEMEXCEPTIONDEBUG}
  895. if IsConsole then
  896. begin
  897. writeln(stderr,'In JumpToHandleErrorFrame error=',error);
  898. end;
  899. {$endif SYSTEMEXCEPTIONDEBUG}
  900. if reset_fpu[except_level] then
  901. asm
  902. fninit
  903. fldcw fpucw
  904. end;
  905. { build a fake stack }
  906. asm
  907. movl ebp,%eax
  908. pushl %eax
  909. movl eip,%eax
  910. pushl %eax
  911. movl error,%eax
  912. pushl %eax
  913. movl eip,%eax
  914. pushl %eax
  915. movl ebp,%ebp // Change frame pointer
  916. {$ifdef SYSTEMEXCEPTIONDEBUG}
  917. jmpl DebugHandleErrorAddrFrame
  918. {$else not SYSTEMEXCEPTIONDEBUG}
  919. jmpl HandleErrorAddrFrame
  920. {$endif SYSTEMEXCEPTIONDEBUG}
  921. end;
  922. end;
  923. function syswin32_i386_exception_handler(excep :PEXCEPTION_POINTERS) : longint;
  924. var frame,res : longint;
  925. function SysHandleErrorFrame(error,frame : longint;must_reset_fpu : boolean) : longint;
  926. begin
  927. if frame=0 then
  928. SysHandleErrorFrame:=Exception_Continue_Search
  929. else
  930. begin
  931. if except_level >= Max_level then
  932. exit;
  933. except_eip[except_level]:=excep^.ContextRecord^.Eip;
  934. except_error[except_level]:=error;
  935. reset_fpu[except_level]:=must_reset_fpu;
  936. inc(except_level);
  937. excep^.ContextRecord^.Eip:=longint(@JumpToHandleErrorFrame);
  938. excep^.ExceptionRecord^.ExceptionCode:=0;
  939. SysHandleErrorFrame:=Exception_Continue_Execution;
  940. {$ifdef SYSTEMEXCEPTIONDEBUG}
  941. if IsConsole then
  942. begin
  943. writeln(stderr,'Exception Continue Exception set at ',
  944. hexstr(except_eip[except_level],8));
  945. writeln(stderr,'Eip changed to ',
  946. hexstr(longint(@JumpToHandleErrorFrame),8), ' error=',error);
  947. end;
  948. {$endif SYSTEMEXCEPTIONDEBUG}
  949. end;
  950. end;
  951. begin
  952. if excep^.ContextRecord^.SegSs=_SS then
  953. frame:=excep^.ContextRecord^.Ebp
  954. else
  955. frame:=0;
  956. { default : unhandled !}
  957. res:=Exception_Continue_Search;
  958. {$ifdef SYSTEMEXCEPTIONDEBUG}
  959. if IsConsole then
  960. writeln(stderr,'Exception ',
  961. hexstr(excep^.ExceptionRecord^.ExceptionCode,8));
  962. {$endif SYSTEMEXCEPTIONDEBUG}
  963. case excep^.ExceptionRecord^.ExceptionCode of
  964. EXCEPTION_ACCESS_VIOLATION :
  965. res:=SysHandleErrorFrame(216,frame,false);
  966. { EXCEPTION_BREAKPOINT = $80000003;
  967. EXCEPTION_DATATYPE_MISALIGNMENT = $80000002;
  968. EXCEPTION_SINGLE_STEP = $80000004; }
  969. EXCEPTION_ARRAY_BOUNDS_EXCEEDED :
  970. res:=SysHandleErrorFrame(201,frame,false);
  971. EXCEPTION_FLT_DENORMAL_OPERAND :
  972. begin
  973. res:=SysHandleErrorFrame(216,frame,true);
  974. end;
  975. EXCEPTION_FLT_DIVIDE_BY_ZERO :
  976. begin
  977. res:=SysHandleErrorFrame(200,frame,true);
  978. {excep^.ContextRecord^.FloatSave.StatusWord:=excep^.ContextRecord^.FloatSave.StatusWord and $ffffff00;}
  979. end;
  980. {EXCEPTION_FLT_INEXACT_RESULT = $c000008f; }
  981. EXCEPTION_FLT_INVALID_OPERATION :
  982. begin
  983. res:=SysHandleErrorFrame(207,frame,true);
  984. end;
  985. EXCEPTION_FLT_OVERFLOW :
  986. begin
  987. res:=SysHandleErrorFrame(205,frame,true);
  988. end;
  989. EXCEPTION_FLT_STACK_CHECK :
  990. begin
  991. res:=SysHandleErrorFrame(207,frame,true);
  992. end;
  993. EXCEPTION_FLT_UNDERFLOW :
  994. begin
  995. res:=SysHandleErrorFrame(206,frame,true); { should be accepted as zero !! }
  996. end;
  997. EXCEPTION_INT_DIVIDE_BY_ZERO :
  998. res:=SysHandleErrorFrame(200,frame,false);
  999. EXCEPTION_INT_OVERFLOW :
  1000. res:=SysHandleErrorFrame(215,frame,false);
  1001. {EXCEPTION_INVALID_HANDLE = $c0000008;
  1002. EXCEPTION_PRIV_INSTRUCTION = $c0000096;
  1003. EXCEPTION_NONCONTINUABLE_EXCEPTION = $c0000025;
  1004. EXCEPTION_NONCONTINUABLE = $1;}
  1005. EXCEPTION_STACK_OVERFLOW :
  1006. res:=SysHandleErrorFrame(202,frame,false);
  1007. {EXCEPTION_INVALID_DISPOSITION = $c0000026;}
  1008. EXCEPTION_ILLEGAL_INSTRUCTION,
  1009. EXCEPTION_PRIV_INSTRUCTION,
  1010. EXCEPTION_IN_PAGE_ERROR,
  1011. EXCEPTION_SINGLE_STEP : res:=SysHandleErrorFrame(217,frame,false);
  1012. end;
  1013. syswin32_i386_exception_handler:=res;
  1014. end;
  1015. procedure install_exception_handlers;
  1016. {$ifdef SYSTEMEXCEPTIONDEBUG}
  1017. var
  1018. oldexceptaddr,newexceptaddr : longint;
  1019. {$endif SYSTEMEXCEPTIONDEBUG}
  1020. begin
  1021. {$ifdef SYSTEMEXCEPTIONDEBUG}
  1022. asm
  1023. movl $0,%eax
  1024. movl %fs:(%eax),%eax
  1025. movl %eax,oldexceptaddr
  1026. end;
  1027. {$endif SYSTEMEXCEPTIONDEBUG}
  1028. SetUnhandledExceptionFilter(@syswin32_i386_exception_handler);
  1029. {$ifdef SYSTEMEXCEPTIONDEBUG}
  1030. asm
  1031. movl $0,%eax
  1032. movl %fs:(%eax),%eax
  1033. movl %eax,newexceptaddr
  1034. end;
  1035. if IsConsole then
  1036. writeln(stderr,'Old exception ',hexstr(oldexceptaddr,8),
  1037. ' new exception ',hexstr(newexceptaddr,8));
  1038. {$endif SYSTEMEXCEPTIONDEBUG}
  1039. end;
  1040. procedure remove_exception_handlers;
  1041. begin
  1042. SetUnhandledExceptionFilter(nil);
  1043. end;
  1044. {$else not i386 (Processor specific !!)}
  1045. procedure install_exception_handlers;
  1046. begin
  1047. end;
  1048. procedure remove_exception_handlers;
  1049. begin
  1050. end;
  1051. {$endif Set_i386_Exception_handler}
  1052. {****************************************************************************
  1053. Error Message writing using messageboxes
  1054. ****************************************************************************}
  1055. function MessageBox(w1:longint;l1,l2:pointer;w2:longint):longint;
  1056. external 'user32' name 'MessageBoxA';
  1057. const
  1058. ErrorBufferLength = 1024;
  1059. var
  1060. ErrorBuf : array[0..ErrorBufferLength] of char;
  1061. ErrorLen : longint;
  1062. Function ErrorWrite(Var F: TextRec): Integer;
  1063. {
  1064. An error message should always end with #13#10#13#10
  1065. }
  1066. var
  1067. p : pchar;
  1068. i : longint;
  1069. Begin
  1070. if F.BufPos>0 then
  1071. begin
  1072. if F.BufPos+ErrorLen>ErrorBufferLength then
  1073. i:=ErrorBufferLength-ErrorLen
  1074. else
  1075. i:=F.BufPos;
  1076. Move(F.BufPtr^,ErrorBuf[ErrorLen],i);
  1077. inc(ErrorLen,i);
  1078. ErrorBuf[ErrorLen]:=#0;
  1079. end;
  1080. if ErrorLen>3 then
  1081. begin
  1082. p:=@ErrorBuf[ErrorLen];
  1083. for i:=1 to 4 do
  1084. begin
  1085. dec(p);
  1086. if not(p^ in [#10,#13]) then
  1087. break;
  1088. end;
  1089. end;
  1090. if ErrorLen=ErrorBufferLength then
  1091. i:=4;
  1092. if (i=4) then
  1093. begin
  1094. MessageBox(0,@ErrorBuf,pchar('Error'),0);
  1095. ErrorLen:=0;
  1096. end;
  1097. F.BufPos:=0;
  1098. ErrorWrite:=0;
  1099. End;
  1100. Function ErrorClose(Var F: TextRec): Integer;
  1101. begin
  1102. if ErrorLen>0 then
  1103. begin
  1104. MessageBox(0,@ErrorBuf,pchar('Error'),0);
  1105. ErrorLen:=0;
  1106. end;
  1107. ErrorLen:=0;
  1108. ErrorClose:=0;
  1109. end;
  1110. Function ErrorOpen(Var F: TextRec): Integer;
  1111. Begin
  1112. TextRec(F).InOutFunc:=@ErrorWrite;
  1113. TextRec(F).FlushFunc:=@ErrorWrite;
  1114. TextRec(F).CloseFunc:=@ErrorClose;
  1115. ErrorOpen:=0;
  1116. End;
  1117. procedure AssignError(Var T: Text);
  1118. begin
  1119. Assign(T,'');
  1120. TextRec(T).OpenFunc:=@ErrorOpen;
  1121. Rewrite(T);
  1122. end;
  1123. const
  1124. Exe_entry_code : pointer = @Exe_entry;
  1125. Dll_entry_code : pointer = @Dll_entry;
  1126. begin
  1127. { get some helpful informations }
  1128. GetStartupInfo(@startupinfo);
  1129. { some misc Win32 stuff }
  1130. hprevinst:=0;
  1131. if not IsLibrary then
  1132. HInstance:=getmodulehandle(GetCommandFile);
  1133. MainInstance:=HInstance;
  1134. { No idea how to know this issue !! }
  1135. IsMultithreaded:=false;
  1136. cmdshow:=startupinfo.wshowwindow;
  1137. { to test stack depth }
  1138. loweststack:=maxlongint;
  1139. { real test stack depth }
  1140. { stacklimit := setupstack; }
  1141. { Setup heap }
  1142. InitHeap;
  1143. InitExceptions;
  1144. { Setup stdin, stdout and stderr, for GUI apps redirect stderr,stdout to be
  1145. displayed in and messagebox }
  1146. StdInputHandle:=longint(GetStdHandle(STD_INPUT_HANDLE));
  1147. StdOutputHandle:=longint(GetStdHandle(STD_OUTPUT_HANDLE));
  1148. StdErrorHandle:=longint(GetStdHandle(STD_ERROR_HANDLE));
  1149. if not IsConsole then
  1150. begin
  1151. AssignError(stderr);
  1152. AssignError(stdout);
  1153. Assign(Output,'');
  1154. Assign(Input,'');
  1155. end
  1156. else
  1157. begin
  1158. OpenStdIO(Input,fmInput,StdInputHandle);
  1159. OpenStdIO(Output,fmOutput,StdOutputHandle);
  1160. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  1161. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  1162. end;
  1163. { Arguments }
  1164. setup_arguments;
  1165. { Reset IO Error }
  1166. InOutRes:=0;
  1167. { Reset internal error variable }
  1168. errno:=0;
  1169. end.
  1170. {
  1171. $Log$
  1172. Revision 1.3 2000-09-04 19:36:59 peter
  1173. * new heapalloc calls, patch from Thomas Schatzl
  1174. Revision 1.2 2000/07/13 11:33:58 michael
  1175. + removed logs
  1176. }