syslinux.pp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  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. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. { These things are set in the makefile, }
  13. { But you can override them here.}
  14. { If you use an aout system, set the conditional AOUT}
  15. { $Define AOUT}
  16. Unit SysLinux;
  17. Interface
  18. {$ifdef m68k}
  19. { used for single computations }
  20. const
  21. BIAS4 = $7f-1;
  22. {$endif}
  23. {$define newsignal}
  24. {$I systemh.inc}
  25. {$I heaph.inc}
  26. const
  27. UnusedHandle = -1;
  28. StdInputHandle = 0;
  29. StdOutputHandle = 1;
  30. StdErrorHandle = 2;
  31. var
  32. argc : longint;
  33. argv : ppchar;
  34. envp : ppchar;
  35. Implementation
  36. {$I system.inc}
  37. { used in syscall to report errors.}
  38. var
  39. Errno : longint;
  40. { Include constant and type definitions }
  41. {$i errno.inc } { Error numbers }
  42. {$i sysnr.inc } { System call numbers }
  43. {$i sysconst.inc } { Miscellaneous constants }
  44. {$i systypes.inc } { Types needed for system calls }
  45. { Read actual system call definitions. }
  46. {$i syscalls.inc }
  47. {*****************************************************************************
  48. Misc. System Dependent Functions
  49. *****************************************************************************}
  50. procedure prthaltproc;external name '_haltproc';
  51. procedure System_exit;
  52. begin
  53. {$ifdef i386}
  54. asm
  55. jmp prthaltproc
  56. end;
  57. {$else}
  58. asm
  59. jmp prthaltproc
  60. end;
  61. {$endif}
  62. End;
  63. Function ParamCount: Longint;
  64. Begin
  65. Paramcount:=argc-1
  66. End;
  67. Function ParamStr(l: Longint): String;
  68. var
  69. link,
  70. hs : string;
  71. i : longint;
  72. begin
  73. if l=0 then
  74. begin
  75. str(sys_getpid,hs);
  76. hs:='/proc/'+hs+'/exe'#0;
  77. i:=Sys_readlink(@hs[1],@link[1],high(link));
  78. if i>0 then
  79. begin
  80. link[0]:=chr(i);
  81. paramstr:=link;
  82. end
  83. else
  84. paramstr:=strpas(argv[0]);
  85. end
  86. else
  87. if (l>0) and (l<argc) then
  88. paramstr:=strpas(argv[l])
  89. else
  90. paramstr:='';
  91. end;
  92. Procedure Randomize;
  93. Begin
  94. randseed:=sys_time;
  95. End;
  96. {*****************************************************************************
  97. Heap Management
  98. *****************************************************************************}
  99. var
  100. _HEAP : longint;external name 'HEAP';
  101. _HEAPSIZE : longint;external name 'HEAPSIZE';
  102. function getheapstart:pointer;assembler;
  103. {$ifdef i386}
  104. asm
  105. leal _HEAP,%eax
  106. end ['EAX'];
  107. {$else}
  108. asm
  109. lea.l _HEAP,a0
  110. move.l a0,d0
  111. end;
  112. {$endif}
  113. function getheapsize:longint;assembler;
  114. {$ifdef i386}
  115. asm
  116. movl _HEAPSIZE,%eax
  117. end ['EAX'];
  118. {$else}
  119. asm
  120. move.l _HEAPSIZE,d0
  121. end ['D0'];
  122. {$endif}
  123. {$ifdef bsd}
  124. Function sbrk(size : longint) : Longint;
  125. CONST MAP_PRIVATE =2;
  126. MAP_ANONYMOUS =$1000; {$20 under linux}
  127. begin
  128. Sbrk:=do_syscall(syscall_nr_mmap,0,size,3,MAP_PRIVATE+MAP_ANONYMOUS,-1,0,0);
  129. if ErrNo<>0 then
  130. Sbrk:=0;
  131. end;
  132. {$else}
  133. Function sbrk(size : longint) : Longint;
  134. type
  135. tmmapargs=packed record
  136. address : longint;
  137. size : longint;
  138. prot : longint;
  139. flags : longint;
  140. fd : longint;
  141. offset : longint;
  142. end;
  143. var
  144. t : syscallregs;
  145. mmapargs : tmmapargs;
  146. begin
  147. mmapargs.address:=0;
  148. mmapargs.size:=Size;
  149. mmapargs.prot:=3;
  150. mmapargs.flags:=$22;
  151. mmapargs.fd:=-1;
  152. mmapargs.offset:=0;
  153. t.reg2:=longint(@mmapargs);
  154. Sbrk:=syscall(syscall_nr_mmap,t);
  155. if ErrNo<>0 then
  156. Sbrk:=0;
  157. end;
  158. {$endif}
  159. { include standard heap management }
  160. {$I heap.inc}
  161. {*****************************************************************************
  162. Low Level File Routines
  163. *****************************************************************************}
  164. {
  165. The lowlevel file functions should take care of setting the InOutRes to the
  166. correct value if an error has occured, else leave it untouched
  167. }
  168. Procedure Errno2Inoutres;
  169. {
  170. Convert ErrNo error to the correct Inoutres value
  171. }
  172. begin
  173. if ErrNo=0 then { Else it will go through all the cases }
  174. exit;
  175. case ErrNo of
  176. Sys_ENFILE,
  177. Sys_EMFILE : Inoutres:=4;
  178. Sys_ENOENT : Inoutres:=2;
  179. Sys_EBADF : Inoutres:=6;
  180. Sys_ENOMEM,
  181. Sys_EFAULT : Inoutres:=217;
  182. Sys_EINVAL : Inoutres:=218;
  183. Sys_EPIPE,
  184. Sys_EINTR,
  185. Sys_EIO,
  186. Sys_EAGAIN,
  187. Sys_ENOSPC : Inoutres:=101;
  188. Sys_ENAMETOOLONG,
  189. Sys_ELOOP,
  190. Sys_ENOTDIR : Inoutres:=3;
  191. Sys_EROFS,
  192. Sys_EEXIST,
  193. Sys_EACCES : Inoutres:=5;
  194. Sys_ETXTBSY : Inoutres:=162;
  195. end;
  196. end;
  197. Procedure Do_Close(Handle:Longint);
  198. Begin
  199. sys_close(Handle);
  200. End;
  201. Procedure Do_Erase(p:pchar);
  202. Begin
  203. sys_unlink(p);
  204. Errno2Inoutres;
  205. End;
  206. Procedure Do_Rename(p1,p2:pchar);
  207. Begin
  208. sys_rename(p1,p2);
  209. Errno2Inoutres;
  210. End;
  211. Function Do_Write(Handle,Addr,Len:Longint):longint;
  212. Begin
  213. repeat
  214. Do_Write:=sys_write(Handle,pchar(addr),len);
  215. until ErrNo<>Sys_EINTR;
  216. Errno2Inoutres;
  217. if Do_Write<0 then
  218. Do_Write:=0;
  219. End;
  220. Function Do_Read(Handle,Addr,Len:Longint):Longint;
  221. Begin
  222. repeat
  223. Do_Read:=sys_read(Handle,pchar(addr),len);
  224. until ErrNo<>Sys_EINTR;
  225. Errno2Inoutres;
  226. if Do_Read<0 then
  227. Do_Read:=0;
  228. End;
  229. Function Do_FilePos(Handle: Longint): Longint;
  230. Begin
  231. Do_FilePos:=sys_lseek(Handle, 0, Seek_Cur);
  232. Errno2Inoutres;
  233. End;
  234. Procedure Do_Seek(Handle,Pos:Longint);
  235. Begin
  236. sys_lseek(Handle, pos, Seek_set);
  237. End;
  238. Function Do_SeekEnd(Handle:Longint): Longint;
  239. begin
  240. Do_SeekEnd:=sys_lseek(Handle,0,Seek_End);
  241. end;
  242. {$ifdef BSD}
  243. Function Do_FileSize(Handle:Longint): Longint;
  244. var
  245. Info : Stat;
  246. Begin
  247. if do_SysCall(syscall_nr_fstat,handle,longint(@info))=0 then
  248. Do_FileSize:=Info.Size
  249. else
  250. Do_FileSize:=0;
  251. Errno2Inoutres;
  252. End;
  253. {$ELSE}
  254. Function Do_FileSize(Handle:Longint): Longint;
  255. var
  256. regs : Syscallregs;
  257. Info : Stat;
  258. Begin
  259. regs.reg2:=Handle;
  260. regs.reg3:=longint(@Info);
  261. if SysCall(SysCall_nr_fstat,regs)=0 then
  262. Do_FileSize:=Info.Size
  263. else
  264. Do_FileSize:=0;
  265. Errno2Inoutres;
  266. End;
  267. {$endif}
  268. Procedure Do_Truncate(Handle,Pos:longint);
  269. {$ifndef bsd}
  270. var
  271. sr : syscallregs;
  272. {$endif}
  273. begin
  274. {$ifdef bsd}
  275. do_syscall(syscall_nr_ftruncate,handle,pos,0);
  276. {$else}
  277. sr.reg2:=Handle;
  278. sr.reg3:=Pos;
  279. syscall(syscall_nr_ftruncate,sr);
  280. {$endif}
  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. {$ifndef BSD}
  365. sr: SysCallRegs;
  366. {$endif}
  367. Data : array[0..255] of byte; {Large enough for termios info}
  368. begin
  369. {$ifdef BSD}
  370. Do_IsDevice:=(do_SysCall(syscall_nr_ioctl,handle,$5401,longint(@data))=0);
  371. {$else}
  372. sr.reg2:=Handle;
  373. sr.reg3:=$5401; {=TCGETS}
  374. sr.reg4:=Longint(@Data);
  375. Do_IsDevice:=(SysCall(Syscall_nr_ioctl,sr)=0);
  376. {$endif}
  377. end;
  378. {*****************************************************************************
  379. UnTyped File Handling
  380. *****************************************************************************}
  381. {$i file.inc}
  382. {*****************************************************************************
  383. Typed File Handling
  384. *****************************************************************************}
  385. {$i typefile.inc}
  386. {*****************************************************************************
  387. Text File Handling
  388. *****************************************************************************}
  389. {$DEFINE SHORT_LINEBREAK}
  390. {$DEFINE EXTENDED_EOF}
  391. {$i text.inc}
  392. {*****************************************************************************
  393. Directory Handling
  394. *****************************************************************************}
  395. Procedure MkDir(Const s: String);[IOCheck];
  396. Var
  397. Buffer: Array[0..255] of Char;
  398. Begin
  399. If InOutRes <> 0 then exit;
  400. Move(s[1], Buffer, Length(s));
  401. Buffer[Length(s)] := #0;
  402. sys_mkdir(@buffer, 511);
  403. Errno2Inoutres;
  404. End;
  405. Procedure RmDir(Const s: String);[IOCheck];
  406. Var
  407. Buffer: Array[0..255] of Char;
  408. Begin
  409. If InOutRes <> 0 then exit;
  410. Move(s[1], Buffer, Length(s));
  411. Buffer[Length(s)] := #0;
  412. sys_rmdir(@buffer);
  413. Errno2Inoutres;
  414. End;
  415. Procedure ChDir(Const s: String);[IOCheck];
  416. Var
  417. Buffer: Array[0..255] of Char;
  418. Begin
  419. If InOutRes <> 0 then exit;
  420. Move(s[1], Buffer, Length(s));
  421. Buffer[Length(s)] := #0;
  422. sys_chdir(@buffer);
  423. Errno2Inoutres;
  424. End;
  425. procedure getdir(drivenr : byte;var dir : shortstring);
  426. var
  427. thisdir : stat;
  428. rootino,
  429. thisino,
  430. dotdotino : longint;
  431. rootdev,
  432. thisdev,
  433. dotdotdev : {$ifdef bsd}longint{$else}word{$endif};
  434. thedir,dummy : string[255];
  435. dirstream : pdir;
  436. d : pdirent;
  437. mountpoint,validdir : boolean;
  438. predot : string[255];
  439. begin
  440. drivenr:=0;
  441. dir:='';
  442. thedir:='/'#0;
  443. if sys_stat(@thedir[1],thisdir)<0 then
  444. exit;
  445. rootino:=thisdir.ino;
  446. rootdev:=thisdir.dev;
  447. thedir:='.'#0;
  448. if sys_stat(@thedir[1],thisdir)<0 then
  449. exit;
  450. thisino:=thisdir.ino;
  451. thisdev:=thisdir.dev;
  452. { Now we can uniquely identify the current and root dir }
  453. thedir:='';
  454. predot:='';
  455. while not ((thisino=rootino) and (thisdev=rootdev)) do
  456. begin
  457. { Are we on a mount point ? }
  458. dummy:=predot+'..'#0;
  459. if sys_stat(@dummy[1],thisdir)<0 then
  460. exit;
  461. dotdotino:=thisdir.ino;
  462. dotdotdev:=thisdir.dev;
  463. mountpoint:=(thisdev<>dotdotdev);
  464. { Now, Try to find the name of this dir in the previous one }
  465. dirstream:=opendir (@dummy[1]);
  466. if dirstream=nil then
  467. exit;
  468. repeat
  469. d:=sys_readdir (dirstream);
  470. validdir:=false;
  471. if (d<>nil) and
  472. (not ((d^.name[0]='.') and ((d^.name[1]=#0) or ((d^.name[1]='.')
  473. and (d^.name[2]=#0))))) and
  474. (mountpoint or (d^.ino=thisino)) then
  475. begin
  476. dummy:=predot+'../'+strpas(@(d^.name[0]))+#0;
  477. validdir:=not (sys_stat (@(dummy[1]),thisdir)<0);
  478. end
  479. else
  480. validdir:=false;
  481. until (d=nil) or
  482. ((validdir) and (thisdir.dev=thisdev) and (thisdir.ino=thisino) );
  483. if (closedir(dirstream)<0) or (d=nil) then
  484. exit;
  485. { At this point, d.name contains the name of the current dir}
  486. thedir:='/'+strpas(@(d^.name[0]))+thedir;
  487. thisdev:=dotdotdev;
  488. thisino:=dotdotino;
  489. predot:=predot+'../';
  490. end;
  491. { Now rootino=thisino and rootdev=thisdev so we've reached / }
  492. dir:=thedir
  493. end;
  494. {*****************************************************************************
  495. SystemUnit Initialization
  496. *****************************************************************************}
  497. {$ifdef I386}
  498. { this should be defined in i386 directory !! PM }
  499. const
  500. fpucw : word = $1332;
  501. FPU_Invalid = 1;
  502. FPU_Denormal = 2;
  503. FPU_DivisionByZero = 4;
  504. FPU_Overflow = 8;
  505. FPU_Underflow = $10;
  506. FPU_StackUnderflow = $20;
  507. FPU_StackOverflow = $40;
  508. {$endif I386}
  509. Procedure ResetFPU;
  510. begin
  511. {$ifdef I386}
  512. {$ifndef CORRECTFLDCW}
  513. {$asmmode direct}
  514. {$endif}
  515. asm
  516. fninit
  517. fldcw fpucw
  518. end;
  519. {$ifndef CORRECTFLDCW}
  520. {$asmmode att}
  521. {$endif}
  522. {$endif I386}
  523. end;
  524. {$ifndef BSD}
  525. {$ifndef newSignal}
  526. Procedure SignalToRunError(Sig:longint);
  527. begin
  528. case sig of
  529. 8 : begin
  530. { this is not allways necessary but I don't know yet
  531. how to tell if it is or not PM }
  532. ResetFPU;
  533. HandleError(200);
  534. end;
  535. 11 : HandleError(216);
  536. end;
  537. end;
  538. Procedure InstallSignals;
  539. var
  540. sr : syscallregs;
  541. begin
  542. sr.reg3:=longint(@SignalToRunError);
  543. { sigsegv }
  544. sr.reg2:=11;
  545. syscall(syscall_nr_signal,sr);
  546. { sigfpe }
  547. sr.reg2:=8;
  548. syscall(syscall_nr_signal,sr);
  549. end;
  550. {$else newSignal}
  551. {$i i386/signal.inc}
  552. procedure SignalToRunerror(Sig: longint; SigContext: SigContextRec); cdecl;
  553. var
  554. res,fpustate : word;
  555. begin
  556. res:=0;
  557. case sig of
  558. 8 : begin
  559. { this is not allways necessary but I don't know yet
  560. how to tell if it is or not PM }
  561. {$ifdef I386}
  562. fpustate:=0;
  563. res:=200;
  564. if assigned(SigContext.fpstate) then
  565. fpuState:=SigContext.fpstate^.sw;
  566. {$ifdef SYSTEMDEBUG}
  567. Writeln(stderr,'FpuState = ',Hexstr(FpuState,4));
  568. {$endif SYSTEMDEBUG}
  569. if (FpuState and $7f) <> 0 then
  570. begin
  571. { first check te more precise options }
  572. if (FpuState and FPU_DivisionByZero)<>0 then
  573. res:=200
  574. else if (FpuState and FPU_Overflow)<>0 then
  575. res:=205
  576. else if (FpuState and FPU_Underflow)<>0 then
  577. res:=206
  578. else if (FpuState and FPU_Denormal)<>0 then
  579. res:=216
  580. else if (FpuState and (FPU_StackOverflow or FPU_StackUnderflow))<>0 then
  581. res:=207
  582. else if (FpuState and FPU_Invalid)<>0 then
  583. res:=216
  584. else
  585. res:=207; {'Coprocessor Error'}
  586. end;
  587. {$endif I386}
  588. ResetFPU;
  589. end;
  590. 11 : res:=216;
  591. end;
  592. { give runtime error at the position where the signal was raised }
  593. if res<>0 then
  594. begin
  595. {$ifdef I386}
  596. HandleErrorAddrFrame(res,SigContext.eip,SigContext.ebp);
  597. {$else}
  598. HandleError(res);
  599. {$endif}
  600. end;
  601. end;
  602. Procedure InstallSignals;
  603. const
  604. act: SigActionRec = (handler:(Sa:@SignalToRunError);sa_mask:0;sa_flags:0;
  605. Sa_restorer: NIL);
  606. oldact: PSigActionRec = Nil;
  607. begin
  608. ResetFPU;
  609. SigAction(8,@act,oldact);
  610. SigAction(11,@act,oldact);
  611. end;
  612. {$endif newSignal}
  613. {$endif bsd}
  614. procedure SetupCmdLine;
  615. var
  616. bufsize,
  617. len,j,
  618. size,i : longint;
  619. found : boolean;
  620. buf : array[0..1026] of char;
  621. procedure AddBuf;
  622. begin
  623. reallocmem(cmdline,size+bufsize);
  624. move(buf,cmdline[size],bufsize);
  625. inc(size,bufsize);
  626. bufsize:=0;
  627. end;
  628. begin
  629. size:=0;
  630. bufsize:=0;
  631. i:=0;
  632. while (i<argc) do
  633. begin
  634. len:=strlen(argv[i]);
  635. if len>sizeof(buf)-2 then
  636. len:=sizeof(buf)-2;
  637. found:=false;
  638. for j:=1 to len do
  639. if argv[i][j]=' ' then
  640. begin
  641. found:=true;
  642. break;
  643. end;
  644. if bufsize+len>=sizeof(buf)-2 then
  645. AddBuf;
  646. if found then
  647. begin
  648. buf[bufsize]:='"';
  649. inc(bufsize);
  650. end;
  651. move(argv[i]^,buf[bufsize],len);
  652. inc(bufsize,len);
  653. if found then
  654. begin
  655. buf[bufsize]:='"';
  656. inc(bufsize);
  657. end;
  658. if i<argc then
  659. buf[bufsize]:=' '
  660. else
  661. buf[bufsize]:=#0;
  662. inc(bufsize);
  663. inc(i);
  664. end;
  665. AddBuf;
  666. end;
  667. Begin
  668. { Set up signals handlers }
  669. {$ifndef bsd}
  670. InstallSignals;
  671. {$endif}
  672. { Setup heap }
  673. InitHeap;
  674. InitExceptions;
  675. { Arguments }
  676. SetupCmdLine;
  677. { Setup stdin, stdout and stderr }
  678. OpenStdIO(Input,fmInput,StdInputHandle);
  679. OpenStdIO(Output,fmOutput,StdOutputHandle);
  680. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  681. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  682. { Reset IO Error }
  683. InOutRes:=0;
  684. End.
  685. {
  686. $Log$
  687. Revision 1.48 2000-06-30 22:14:03 peter
  688. * removed obsolete crtlib code
  689. * support EINTR for read/write to restart the syscall
  690. Revision 1.47 2000/05/11 17:55:13 peter
  691. * changed order of fpustate checking to first check the more
  692. specific states
  693. Revision 1.46 2000/05/08 14:27:36 peter
  694. * released newsignal
  695. * newsignal gives now better backtraces using the sigcontext eip/ebp
  696. fields
  697. Revision 1.45 2000/04/16 16:07:58 marco
  698. * BSD fixes
  699. Revision 1.44 2000/04/14 13:04:53 marco
  700. * Merged bsd/syslinux.pp and 1.43 linux/syslinux.pp to this file with ifdefs
  701. Revision 1.43 2000/04/07 14:56:36 peter
  702. * switch to direct asm if not correctfldcw defined
  703. Revision 1.42 2000/03/31 23:26:32 pierre
  704. * FPU needs reset for all SIGFPE even from integer division by zero
  705. Revision 1.41 2000/03/31 23:21:19 pierre
  706. * multiple exception handling works
  707. (for linux only if syslinux is compiled with -dnewsignal)
  708. Revision 1.40 2000/03/31 13:24:28 jonas
  709. * signal handling using sigaction when compiled with -dnewsignal
  710. (allows multiple signals to be received in one run)
  711. Revision 1.39 2000/03/25 12:28:37 peter
  712. * patch for getdir from Pierre
  713. Revision 1.38 2000/03/23 15:24:18 peter
  714. * remove handle check for do_close
  715. Revision 1.37 2000/02/09 16:59:32 peter
  716. * truncated log
  717. Revision 1.36 2000/02/09 12:17:51 peter
  718. * moved halt to system.inc
  719. * syslinux doesn't use direct asm anymore
  720. Revision 1.35 2000/02/08 11:47:09 peter
  721. * paramstr(0) support
  722. Revision 1.34 2000/01/20 23:38:02 peter
  723. * support fm_inout as stdoutput for assign(f,'');rewrite(f,1); becuase
  724. rewrite opens always with filemode 2
  725. Revision 1.33 2000/01/16 22:25:38 peter
  726. * check handle for file closing
  727. Revision 1.32 2000/01/07 16:41:41 daniel
  728. * copyright 2000
  729. Revision 1.31 2000/01/07 16:32:28 daniel
  730. * copyright 2000 added
  731. Revision 1.30 1999/12/01 22:57:31 peter
  732. * cmdline support
  733. Revision 1.29 1999/11/06 14:39:12 peter
  734. * truncated log
  735. Revision 1.28 1999/10/28 09:50:06 peter
  736. * use mmap instead of brk
  737. Revision 1.27 1999/09/10 15:40:35 peter
  738. * fixed do_open flags to be > $100, becuase filemode can be upto 255
  739. Revision 1.26 1999/09/08 16:14:43 peter
  740. * pointer fixes
  741. Revision 1.25 1999/07/28 23:18:36 peter
  742. * closedir fixes, which now disposes the pdir itself
  743. }