sysunix.inc 20 KB

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