sysunix.inc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Michael Van Canneyt,
  5. member of the Free Pascal development team.
  6. This is the core of the system unit *nix systems (now FreeBSD
  7. and Unix).
  8. See the file COPYING.FPC, included in this distribution,
  9. for details about the copyright.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. **********************************************************************}
  14. { These things are set in the makefile, }
  15. { But you can override them here.}
  16. { If you use an aout system, set the conditional AOUT}
  17. { $Define AOUT}
  18. {$I system.inc}
  19. { used in syscall to report errors.}
  20. var
  21. Errno : longint;
  22. { Include constant and type definitions }
  23. {$i errno.inc } { Error numbers }
  24. {$i sysnr.inc } { System call numbers }
  25. {$i sysconst.inc } { Miscellaneous constants }
  26. {$i systypes.inc } { Types needed for system calls }
  27. { Read actual system call definitions. }
  28. {$i signal.inc}
  29. {$i syscalls.inc }
  30. {*****************************************************************************
  31. Misc. System Dependent Functions
  32. *****************************************************************************}
  33. {$ifdef I386}
  34. { this should be defined in i386 directory !! PM }
  35. const
  36. fpucw : word = $1332;
  37. FPU_Invalid = 1;
  38. FPU_Denormal = 2;
  39. FPU_DivisionByZero = 4;
  40. FPU_Overflow = 8;
  41. FPU_Underflow = $10;
  42. FPU_StackUnderflow = $20;
  43. FPU_StackOverflow = $40;
  44. {$endif I386}
  45. Procedure ResetFPU;
  46. begin
  47. {$ifdef I386}
  48. asm
  49. fninit
  50. fldcw fpucw
  51. end;
  52. {$endif I386}
  53. end;
  54. procedure prthaltproc;external name '_haltproc';
  55. Procedure System_exit;
  56. Begin
  57. prthaltproc;
  58. End;
  59. Function ParamCount: Longint;
  60. Begin
  61. Paramcount:=argc-1;
  62. End;
  63. Function ParamStr(l: Longint): String;
  64. var
  65. link,
  66. hs : string;
  67. i : longint;
  68. begin
  69. if l=0 then
  70. begin
  71. str(sys_getpid,hs);
  72. {$ifdef FreeBSD}
  73. hs:='/proc/'+hs+'/file'#0;
  74. {$else}
  75. hs:='/proc/'+hs+'/exe'#0;
  76. {$endif}
  77. i:=Sys_readlink(@hs[1],@link[1],high(link));
  78. { it must also be an absolute filename, linux 2.0 points to a memory
  79. location so this will skip that }
  80. if (i>0) and (link[1]='/') then
  81. begin
  82. link[0]:=chr(i);
  83. paramstr:=link;
  84. end
  85. else
  86. paramstr:=strpas(argv[0]);
  87. end
  88. else
  89. if (l>0) and (l<argc) then
  90. paramstr:=strpas(argv[l])
  91. else
  92. paramstr:='';
  93. end;
  94. Procedure Randomize;
  95. Begin
  96. randseed:=sys_time;
  97. End;
  98. {*****************************************************************************
  99. Heap Management
  100. *****************************************************************************}
  101. var
  102. _HEAP : pointer;external name 'HEAP';
  103. _HEAPSIZE : longint;external name 'HEAPSIZE';
  104. function getheapstart:pointer;assembler;
  105. {$undef fpc_getheapstart_ok}
  106. {$ifdef i386}
  107. {$define fpc_getheapstart_ok}
  108. asm
  109. leal _HEAP,%eax
  110. end ['EAX'];
  111. {$endif i386}
  112. {$ifdef m68k}
  113. {$define fpc_getheapstart_ok}
  114. asm
  115. lea.l _HEAP,a0
  116. move.l a0,d0
  117. end['A0','D0'];
  118. {$endif m68k}
  119. {$ifndef fpc_getheapstart_ok}
  120. {$error Getheapstart code is not implemented }
  121. {$endif not fpc_getheapstart_ok}
  122. function getheapsize:longint;assembler;
  123. {$undef fpc_getheapsize_ok}
  124. {$ifdef i386}
  125. {$define fpc_getheapsize_ok}
  126. asm
  127. movl _HEAPSIZE,%eax
  128. end ['EAX'];
  129. {$endif i386}
  130. {$ifdef m68k}
  131. {$define fpc_getheapsize_ok}
  132. asm
  133. move.l _HEAPSIZE,d0
  134. end ['D0'];
  135. {$endif m68k}
  136. {$ifndef fpc_getheapsize_ok}
  137. {$error Getheapsize code is not implemented }
  138. {$endif not fpc_getheapsize_ok}
  139. Function sbrk(size : longint) : Longint;
  140. begin
  141. sbrk:=Sys_mmap(0,Size,3,MAP_PRIVATE+MAP_ANONYMOUS,-1,0);
  142. if sbrk<>-1 then
  143. errno:=0;
  144. {! It must be -1, not 0 as before, see heap.inc. Should be in sysmmap?}
  145. end;
  146. { include standard heap management }
  147. {$I heap.inc}
  148. {*****************************************************************************
  149. Low Level File Routines
  150. *****************************************************************************}
  151. {
  152. The lowlevel file functions should take care of setting the InOutRes to the
  153. correct value if an error has occured, else leave it untouched
  154. }
  155. Procedure Errno2Inoutres;
  156. {
  157. Convert ErrNo error to the correct Inoutres value
  158. }
  159. begin
  160. if ErrNo=0 then { Else it will go through all the cases }
  161. exit;
  162. If errno<0 then Errno:=-errno;
  163. case ErrNo of
  164. Sys_ENFILE,
  165. Sys_EMFILE : Inoutres:=4;
  166. Sys_ENOENT : Inoutres:=2;
  167. Sys_EBADF : Inoutres:=6;
  168. Sys_ENOMEM,
  169. Sys_EFAULT : Inoutres:=217;
  170. Sys_EINVAL : Inoutres:=218;
  171. Sys_EPIPE,
  172. Sys_EINTR,
  173. Sys_EIO,
  174. Sys_EAGAIN,
  175. Sys_ENOSPC : Inoutres:=101;
  176. Sys_ENAMETOOLONG,
  177. Sys_ELOOP,
  178. Sys_ENOTDIR : Inoutres:=3;
  179. Sys_EROFS,
  180. Sys_EEXIST,
  181. Sys_EISDIR,
  182. Sys_ENOTEMPTY,
  183. Sys_EACCES : Inoutres:=5;
  184. Sys_ETXTBSY : Inoutres:=162;
  185. else
  186. InOutRes := Integer(Errno);
  187. end;
  188. end;
  189. Procedure Do_Close(Handle:Longint);
  190. Begin
  191. sys_close(Handle);
  192. {Errno2Inoutres;}
  193. End;
  194. Procedure Do_Erase(p:pchar);
  195. {$ifdef BSD}
  196. var FileInfo : Stat;
  197. {$endif}
  198. Begin
  199. {$ifdef BSD} {or POSIX}
  200. { verify if the filename is actually a directory }
  201. { if so return error and do nothing, as defined }
  202. { by POSIX }
  203. if sys_stat(p,fileinfo)<0 then
  204. begin
  205. Errno2Inoutres;
  206. exit;
  207. end;
  208. {$ifdef BSD}
  209. if (fileinfo.mode and STAT_IFMT)=STAT_IFDIR then
  210. {$else}
  211. if s_ISDIR(fileinfo.st_mode) then
  212. {$endif}
  213. begin
  214. InOutRes := 2;
  215. exit;
  216. end;
  217. {$endif}
  218. sys_unlink(p);
  219. Errno2Inoutres;
  220. {$ifdef Linux}
  221. { tp compatible result }
  222. if (Errno=Sys_EISDIR) then
  223. InOutRes:=2;
  224. {$endif}
  225. End;
  226. Procedure Do_Rename(p1,p2:pchar);
  227. Begin
  228. sys_rename(p1,p2);
  229. Errno2Inoutres;
  230. End;
  231. Function Do_Write(Handle,Addr,Len:Longint):longint;
  232. Begin
  233. repeat
  234. Do_Write:=sys_write(Handle,pchar(addr),len);
  235. until ErrNo<>Sys_EINTR;
  236. Errno2Inoutres;
  237. if Do_Write<0 then
  238. Do_Write:=0;
  239. End;
  240. Function Do_Read(Handle,Addr,Len:Longint):Longint;
  241. Begin
  242. repeat
  243. Do_Read:=sys_read(Handle,pchar(addr),len);
  244. until ErrNo<>Sys_EINTR;
  245. Errno2Inoutres;
  246. if Do_Read<0 then
  247. Do_Read:=0;
  248. End;
  249. Function Do_FilePos(Handle: Longint): Longint;
  250. Begin
  251. Do_FilePos:=sys_lseek(Handle, 0, Seek_Cur);
  252. Errno2Inoutres;
  253. End;
  254. Procedure Do_Seek(Handle,Pos:Longint);
  255. Begin
  256. sys_lseek(Handle, pos, Seek_set);
  257. errno2inoutres;
  258. End;
  259. Function Do_SeekEnd(Handle:Longint): Longint;
  260. begin
  261. Do_SeekEnd:=sys_lseek(Handle,0,Seek_End);
  262. errno2inoutres;
  263. end;
  264. Function Do_FileSize(Handle:Longint): Longint;
  265. var
  266. Info : Stat;
  267. Begin
  268. if sys_fstat(handle,info)=0 then
  269. Do_FileSize:=Info.Size
  270. else
  271. Do_FileSize:=0;
  272. Errno2Inoutres;
  273. End;
  274. Procedure Do_Truncate(Handle,fPos:longint);
  275. begin
  276. sys_ftruncate(handle,fpos);
  277. Errno2Inoutres;
  278. end;
  279. Procedure Do_Open(var f;p:pchar;flags:longint);
  280. {
  281. FileRec and textrec have both Handle and mode as the first items so
  282. they could use the same routine for opening/creating.
  283. when (flags and $100) the file will be append
  284. when (flags and $1000) the file will be truncate/rewritten
  285. when (flags and $10000) there is no check for close (needed for textfiles)
  286. }
  287. var
  288. oflags : longint;
  289. Begin
  290. { close first if opened }
  291. if ((flags and $10000)=0) then
  292. begin
  293. case FileRec(f).mode of
  294. fminput,fmoutput,fminout : Do_Close(FileRec(f).Handle);
  295. fmclosed : ;
  296. else
  297. begin
  298. inoutres:=102; {not assigned}
  299. exit;
  300. end;
  301. end;
  302. end;
  303. { reset file Handle }
  304. FileRec(f).Handle:=UnusedHandle;
  305. { We do the conversion of filemodes here, concentrated on 1 place }
  306. case (flags and 3) of
  307. 0 : begin
  308. oflags :=Open_RDONLY;
  309. FileRec(f).mode:=fminput;
  310. end;
  311. 1 : begin
  312. oflags :=Open_WRONLY;
  313. FileRec(f).mode:=fmoutput;
  314. end;
  315. 2 : begin
  316. oflags :=Open_RDWR;
  317. FileRec(f).mode:=fminout;
  318. end;
  319. end;
  320. if (flags and $1000)=$1000 then
  321. oflags:=oflags or (Open_CREAT or Open_TRUNC)
  322. else
  323. if (flags and $100)=$100 then
  324. oflags:=oflags or (Open_APPEND);
  325. { empty name is special }
  326. if p[0]=#0 then
  327. begin
  328. case FileRec(f).mode of
  329. fminput :
  330. FileRec(f).Handle:=StdInputHandle;
  331. fminout, { this is set by rewrite }
  332. fmoutput :
  333. FileRec(f).Handle:=StdOutputHandle;
  334. fmappend :
  335. begin
  336. FileRec(f).Handle:=StdOutputHandle;
  337. FileRec(f).mode:=fmoutput; {fool fmappend}
  338. end;
  339. end;
  340. exit;
  341. end;
  342. { real open call }
  343. FileRec(f).Handle:=sys_open(p,oflags,438);
  344. if (ErrNo=Sys_EROFS) and ((OFlags and Open_RDWR)<>0) then
  345. begin
  346. Oflags:=Oflags and not(Open_RDWR);
  347. FileRec(f).Handle:=sys_open(p,oflags,438);
  348. end;
  349. Errno2Inoutres;
  350. End;
  351. Function Do_IsDevice(Handle:Longint):boolean;
  352. {
  353. Interface to Unix ioctl call.
  354. Performs various operations on the filedescriptor Handle.
  355. Ndx describes the operation to perform.
  356. Data points to data needed for the Ndx function. The structure of this
  357. data is function-dependent.
  358. }
  359. var
  360. Data : array[0..255] of byte; {Large enough for termios info}
  361. begin
  362. Do_IsDevice:=(sys_ioctl(handle,IOCTL_TCGETS,@data)<>-1);
  363. end;
  364. {*****************************************************************************
  365. UnTyped File Handling
  366. *****************************************************************************}
  367. {$i file.inc}
  368. {*****************************************************************************
  369. Typed File Handling
  370. *****************************************************************************}
  371. {$i typefile.inc}
  372. {*****************************************************************************
  373. Text File Handling
  374. *****************************************************************************}
  375. {$DEFINE SHORT_LINEBREAK}
  376. {$DEFINE EXTENDED_EOF}
  377. {$i text.inc}
  378. {*****************************************************************************
  379. Directory Handling
  380. *****************************************************************************}
  381. Procedure MkDir(Const s: String);[IOCheck];
  382. Var
  383. Buffer: Array[0..255] of Char;
  384. Begin
  385. If (s='') or (InOutRes <> 0) then
  386. exit;
  387. Move(s[1], Buffer, Length(s));
  388. Buffer[Length(s)] := #0;
  389. sys_mkdir(@buffer, 511);
  390. Errno2Inoutres;
  391. End;
  392. Procedure RmDir(Const s: String);[IOCheck];
  393. Var
  394. Buffer: Array[0..255] of Char;
  395. Begin
  396. if (s ='.') then
  397. InOutRes := 16;
  398. If (s='') or (InOutRes <> 0) then
  399. exit;
  400. Move(s[1], Buffer, Length(s));
  401. Buffer[Length(s)] := #0;
  402. sys_rmdir(@buffer);
  403. {$ifdef BSD}
  404. if (Errno=Sys_EINVAL) Then
  405. InOutRes:=5
  406. Else
  407. {$endif}
  408. Errno2Inoutres;
  409. End;
  410. Procedure ChDir(Const s: String);[IOCheck];
  411. Var
  412. Buffer: Array[0..255] of Char;
  413. Begin
  414. If (s='') or (InOutRes <> 0) then
  415. exit;
  416. Move(s[1], Buffer, Length(s));
  417. Buffer[Length(s)] := #0;
  418. sys_chdir(@buffer);
  419. Errno2Inoutres;
  420. { file not exists is path not found under tp7 }
  421. if InOutRes=2 then
  422. InOutRes:=3;
  423. End;
  424. procedure GetDir (DriveNr: byte; var Dir: ShortString);
  425. var
  426. thisdir : stat;
  427. rootino,
  428. thisino,
  429. dotdotino : longint;
  430. rootdev,
  431. thisdev,
  432. dotdotdev : dev_t;
  433. thedir,dummy : string[255];
  434. dirstream : pdir;
  435. d : pdirent;
  436. mountpoint,validdir : boolean;
  437. predot : string[255];
  438. begin
  439. drivenr:=0;
  440. dir:='';
  441. thedir:='/'#0;
  442. if sys_stat(@thedir[1],thisdir)<0 then
  443. exit;
  444. rootino:=thisdir.ino;
  445. rootdev:=thisdir.dev;
  446. thedir:='.'#0;
  447. if sys_stat(@thedir[1],thisdir)<0 then
  448. exit;
  449. thisino:=thisdir.ino;
  450. thisdev:=thisdir.dev;
  451. { Now we can uniquely identify the current and root dir }
  452. thedir:='';
  453. predot:='';
  454. while not ((thisino=rootino) and (thisdev=rootdev)) do
  455. begin
  456. { Are we on a mount point ? }
  457. dummy:=predot+'..'#0;
  458. if sys_stat(@dummy[1],thisdir)<0 then
  459. exit;
  460. dotdotino:=thisdir.ino;
  461. dotdotdev:=thisdir.dev;
  462. mountpoint:=(thisdev<>dotdotdev);
  463. { Now, Try to find the name of this dir in the previous one }
  464. dirstream:=opendir (@dummy[1]);
  465. if dirstream=nil then
  466. exit;
  467. repeat
  468. d:=sys_readdir (dirstream);
  469. validdir:=false;
  470. if (d<>nil) and
  471. (not ((d^.name[0]='.') and ((d^.name[1]=#0) or ((d^.name[1]='.')
  472. and (d^.name[2]=#0))))) and
  473. (mountpoint or (d^.ino=thisino)) then
  474. begin
  475. dummy:=predot+'../'+strpas(@(d^.name[0]))+#0;
  476. validdir:=not (sys_stat (@(dummy[1]),thisdir)<0);
  477. end
  478. else
  479. validdir:=false;
  480. until (d=nil) or
  481. ((validdir) and (thisdir.dev=thisdev) and (thisdir.ino=thisino) );
  482. { At this point, d.name contains the name of the current dir}
  483. if (d<>nil) then
  484. thedir:='/'+strpas(@(d^.name[0]))+thedir;
  485. { closedir also makes d invalid }
  486. if (closedir(dirstream)<0) or (d=nil) then
  487. exit;
  488. thisdev:=dotdotdev;
  489. thisino:=dotdotino;
  490. predot:=predot+'../';
  491. end;
  492. { Now rootino=thisino and rootdev=thisdev so we've reached / }
  493. dir:=thedir
  494. end;
  495. {$ifdef Unix}
  496. {*****************************************************************************
  497. Thread Handling
  498. *****************************************************************************}
  499. { include threading stuff, this is os independend part }
  500. {$I thread.inc}
  501. {$endif Unix}
  502. {*****************************************************************************
  503. SystemUnit Initialization
  504. *****************************************************************************}
  505. {$ifdef BSD}
  506. procedure SignalToRunerror(Sig: longint; SigContext: SigContextRec;someptr:pointer); cdecl;
  507. {$else}
  508. {$ifdef Solaris}
  509. procedure SignalToRunerror(Sig: longint; SigContext: SigContextRec;someptr:pointer); cdecl;
  510. {$else}
  511. procedure SignalToRunerror(Sig: longint; SigContext: SigContextRec); cdecl;
  512. {$endif}
  513. {$ENDIF}
  514. var
  515. res,fpustate : word;
  516. begin
  517. res:=0;
  518. case sig of
  519. SIGFPE :
  520. begin
  521. { this is not allways necessary but I don't know yet
  522. how to tell if it is or not PM }
  523. {$ifdef I386}
  524. fpustate:=0;
  525. res:=200;
  526. {$ifndef FreeBSD}
  527. if assigned(SigContext.fpstate) then
  528. fpuState:=SigContext.fpstate^.sw;
  529. {$else}
  530. fpustate:=SigContext.en_sw;
  531. {$ifdef SYSTEM_DEBUG}
  532. writeln('xx:',sigcontext.en_tw,' ',sigcontext.en_cw);
  533. {$endif SYSTEM_DEBUG}
  534. {$endif}
  535. {$ifdef SYSTEM_DEBUG}
  536. Writeln(stderr,'FpuState = ',FpuState);
  537. {$endif SYSTEM_DEBUG}
  538. if (FpuState and $7f) <> 0 then
  539. begin
  540. { first check te more precise options }
  541. if (FpuState and FPU_DivisionByZero)<>0 then
  542. res:=200
  543. else if (FpuState and FPU_Overflow)<>0 then
  544. res:=205
  545. else if (FpuState and FPU_Underflow)<>0 then
  546. res:=206
  547. else if (FpuState and FPU_Denormal)<>0 then
  548. res:=216
  549. else if (FpuState and (FPU_StackOverflow or FPU_StackUnderflow))<>0 then
  550. res:=207
  551. else if (FpuState and FPU_Invalid)<>0 then
  552. res:=216
  553. else
  554. res:=207; {'Coprocessor Error'}
  555. end;
  556. {$endif I386}
  557. ResetFPU;
  558. end;
  559. SIGILL,
  560. SIGBUS,
  561. SIGSEGV :
  562. res:=216;
  563. end;
  564. { give runtime error at the position where the signal was raised }
  565. if res<>0 then
  566. begin
  567. {$ifdef I386}
  568. {$ifdef FreeBSD}
  569. HandleErrorAddrFrame(res,SigContext.sc_eip,SigContext.sc_ebp);
  570. {$else}
  571. HandleErrorAddrFrame(res,SigContext.eip,SigContext.ebp);
  572. {$endif}
  573. {$else}
  574. HandleError(res);
  575. {$endif}
  576. end;
  577. end;
  578. Procedure InstallSignals;
  579. const
  580. {$Ifndef BSD}
  581. {$ifdef solaris}
  582. act: SigActionRec =(sa_flags:SA_SIGINFO;Handler:(sa:@signaltorunerror;sa_mask:0);
  583. {$else}
  584. act: SigActionRec = (handler:(Sa:@SignalToRunError);sa_mask:0;sa_flags:0;
  585. Sa_restorer: NIL);
  586. {$endif}
  587. {$ELSE}
  588. act: SigActionRec = (handler:(Sa:@SignalToRunError);sa_flags:SA_SIGINFO;
  589. sa_mask:0);
  590. {$endif}
  591. oldact: PSigActionRec = Nil; {Probably not necessary anymore, now
  592. VAR is removed}
  593. begin
  594. ResetFPU;
  595. SigAction(SIGFPE,@act,oldact);
  596. {$ifndef Solaris}
  597. SigAction(SIGSEGV,@act,oldact);
  598. SigAction(SIGBUS,@act,oldact);
  599. SigAction(SIGILL,@act,oldact);
  600. {$endif}
  601. end;
  602. procedure SetupCmdLine;
  603. var
  604. bufsize,
  605. len,j,
  606. size,i : longint;
  607. found : boolean;
  608. buf : array[0..1026] of char;
  609. procedure AddBuf;
  610. begin
  611. reallocmem(cmdline,size+bufsize);
  612. move(buf,cmdline[size],bufsize);
  613. inc(size,bufsize);
  614. bufsize:=0;
  615. end;
  616. begin
  617. size:=0;
  618. bufsize:=0;
  619. i:=0;
  620. while (i<argc) do
  621. begin
  622. len:=strlen(argv[i]);
  623. if len>sizeof(buf)-2 then
  624. len:=sizeof(buf)-2;
  625. found:=false;
  626. for j:=1 to len do
  627. if argv[i][j]=' ' then
  628. begin
  629. found:=true;
  630. break;
  631. end;
  632. if bufsize+len>=sizeof(buf)-2 then
  633. AddBuf;
  634. if found then
  635. begin
  636. buf[bufsize]:='"';
  637. inc(bufsize);
  638. end;
  639. move(argv[i]^,buf[bufsize],len);
  640. inc(bufsize,len);
  641. if found then
  642. begin
  643. buf[bufsize]:='"';
  644. inc(bufsize);
  645. end;
  646. if i<argc then
  647. buf[bufsize]:=' '
  648. else
  649. buf[bufsize]:=#0;
  650. inc(bufsize);
  651. inc(i);
  652. end;
  653. AddBuf;
  654. end;
  655. Begin
  656. IsConsole := TRUE;
  657. IsLibrary := FALSE;
  658. StackBottom := Sptr - StackLength;
  659. { Set up signals handlers }
  660. InstallSignals;
  661. { Setup heap }
  662. InitHeap;
  663. InitExceptions;
  664. { Arguments }
  665. SetupCmdLine;
  666. { Setup stdin, stdout and stderr }
  667. OpenStdIO(Input,fmInput,StdInputHandle);
  668. OpenStdIO(Output,fmOutput,StdOutputHandle);
  669. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  670. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  671. { Reset IO Error }
  672. InOutRes:=0;
  673. End.
  674. {
  675. $Log$
  676. Revision 1.22 2002-05-31 13:37:24 marco
  677. * more Renamefest
  678. Revision 1.21 2002/04/21 15:55:00 carl
  679. + initialize some global variables
  680. Revision 1.20 2002/04/12 17:43:28 carl
  681. + generic stack checking
  682. Revision 1.19 2002/03/11 19:10:33 peter
  683. * Regenerated with updated fpcmake
  684. Revision 1.18 2001/10/14 13:33:21 peter
  685. * start of thread support for linux
  686. Revision 1.17 2001/09/30 21:10:20 peter
  687. * erase(directory) returns now 2 to be tp compatible
  688. Revision 1.16 2001/08/05 12:24:20 peter
  689. * m68k merges
  690. Revision 1.15 2001/07/16 19:51:36 marco
  691. * A small note, copied from the Solaris patch. Do_close needs errnotoiores?
  692. Revision 1.14 2001/07/15 11:57:16 peter
  693. * merged m68k updates
  694. Revision 1.13 2001/07/13 22:05:09 peter
  695. * cygwin updates
  696. Revision 1.12 2001/06/02 19:24:49 peter
  697. * chdir rte 2 mapped to 3
  698. Revision 1.11 2001/06/02 00:31:31 peter
  699. * merge unix updates from the 1.0 branch, mostly related to the
  700. solaris target
  701. Revision 1.10 2001/04/23 20:33:31 peter
  702. * also install sig handlers for sigill,sigbus
  703. Revision 1.9 2001/04/13 22:39:05 peter
  704. * removed warning
  705. Revision 1.8 2001/04/12 17:53:43 peter
  706. * fixed usage of already release memory in getdir
  707. Revision 1.7 2001/03/21 21:08:20 hajny
  708. * GetDir fixed
  709. Revision 1.6 2001/03/16 20:09:58 hajny
  710. * universal FExpand
  711. Revision 1.5 2001/02/20 21:31:12 peter
  712. * chdir,mkdir,rmdir with empty string fixed
  713. Revision 1.4 2000/12/17 14:00:57 peter
  714. * removed debug writelns
  715. Revision 1.3 2000/10/09 16:35:51 marco
  716. * Fixed the first (of many) ioctls that make building the IDE hard.
  717. Revision 1.2 2000/09/18 13:14:51 marco
  718. * Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
  719. Revision 1.6 2000/09/11 13:48:08 marco
  720. * FreeBSD support and removal of old sighandler
  721. Revision 1.5 2000/08/13 08:43:45 peter
  722. * don't check for directory in do_open (merged)
  723. Revision 1.4 2000/08/05 18:33:51 peter
  724. * paramstr(0) fix for linux 2.0 kernels (merged)
  725. Revision 1.3 2000/07/14 10:33:10 michael
  726. + Conditionals fixed
  727. Revision 1.2 2000/07/13 11:33:49 michael
  728. + removed logs
  729. }