syslinux.pp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879
  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. dirtest : stat;
  294. Begin
  295. { close first if opened }
  296. if ((flags and $10000)=0) then
  297. begin
  298. case FileRec(f).mode of
  299. fminput,fmoutput,fminout : Do_Close(FileRec(f).Handle);
  300. fmclosed : ;
  301. else
  302. begin
  303. inoutres:=102; {not assigned}
  304. exit;
  305. end;
  306. end;
  307. end;
  308. { reset file Handle }
  309. FileRec(f).Handle:=UnusedHandle;
  310. { We do the conversion of filemodes here, concentrated on 1 place }
  311. case (flags and 3) of
  312. 0 : begin
  313. oflags :=Open_RDONLY;
  314. FileRec(f).mode:=fminput;
  315. end;
  316. 1 : begin
  317. oflags :=Open_WRONLY;
  318. FileRec(f).mode:=fmoutput;
  319. end;
  320. 2 : begin
  321. oflags :=Open_RDWR;
  322. FileRec(f).mode:=fminout;
  323. end;
  324. end;
  325. if (flags and $1000)=$1000 then
  326. oflags:=oflags or (Open_CREAT or Open_TRUNC)
  327. else
  328. if (flags and $100)=$100 then
  329. oflags:=oflags or (Open_APPEND);
  330. { empty name is special }
  331. if p[0]=#0 then
  332. begin
  333. case FileRec(f).mode of
  334. fminput :
  335. FileRec(f).Handle:=StdInputHandle;
  336. fminout, { this is set by rewrite }
  337. fmoutput :
  338. FileRec(f).Handle:=StdOutputHandle;
  339. fmappend :
  340. begin
  341. FileRec(f).Handle:=StdOutputHandle;
  342. FileRec(f).mode:=fmoutput; {fool fmappend}
  343. end;
  344. end;
  345. exit;
  346. end;
  347. { real open call }
  348. FileRec(f).Handle:=sys_open(p,oflags,438);
  349. if (ErrNo=Sys_EROFS) and ((OFlags and Open_RDWR)<>0) then
  350. begin
  351. Oflags:=Oflags and not(Open_RDWR);
  352. FileRec(f).Handle:=sys_open(p,oflags,438);
  353. end;
  354. { Check if it's a directory, then we should return io error 2 }
  355. if ErrNo=0 then
  356. begin
  357. if (Sys_fstat(filerec(f).handle,dirtest)<>0) then
  358. inoutres:=2
  359. else
  360. if (dirtest.mode and STAT_IFMT)<>STAT_IFREG then
  361. inoutres:=2;
  362. end;
  363. Errno2Inoutres;
  364. End;
  365. Function Do_IsDevice(Handle:Longint):boolean;
  366. {
  367. Interface to Unix ioctl call.
  368. Performs various operations on the filedescriptor Handle.
  369. Ndx describes the operation to perform.
  370. Data points to data needed for the Ndx function. The structure of this
  371. data is function-dependent.
  372. }
  373. var
  374. {$ifndef BSD}
  375. sr: SysCallRegs;
  376. {$endif}
  377. Data : array[0..255] of byte; {Large enough for termios info}
  378. begin
  379. {$ifdef BSD}
  380. Do_IsDevice:=(do_SysCall(syscall_nr_ioctl,handle,$5401,longint(@data))=0);
  381. {$else}
  382. sr.reg2:=Handle;
  383. sr.reg3:=$5401; {=TCGETS}
  384. sr.reg4:=Longint(@Data);
  385. Do_IsDevice:=(SysCall(Syscall_nr_ioctl,sr)=0);
  386. {$endif}
  387. end;
  388. {*****************************************************************************
  389. UnTyped File Handling
  390. *****************************************************************************}
  391. {$i file.inc}
  392. {*****************************************************************************
  393. Typed File Handling
  394. *****************************************************************************}
  395. {$i typefile.inc}
  396. {*****************************************************************************
  397. Text File Handling
  398. *****************************************************************************}
  399. {$DEFINE SHORT_LINEBREAK}
  400. {$DEFINE EXTENDED_EOF}
  401. {$i text.inc}
  402. {*****************************************************************************
  403. Directory Handling
  404. *****************************************************************************}
  405. Procedure MkDir(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_mkdir(@buffer, 511);
  413. Errno2Inoutres;
  414. End;
  415. Procedure RmDir(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_rmdir(@buffer);
  423. Errno2Inoutres;
  424. End;
  425. Procedure ChDir(Const s: String);[IOCheck];
  426. Var
  427. Buffer: Array[0..255] of Char;
  428. Begin
  429. If InOutRes <> 0 then exit;
  430. Move(s[1], Buffer, Length(s));
  431. Buffer[Length(s)] := #0;
  432. sys_chdir(@buffer);
  433. Errno2Inoutres;
  434. End;
  435. procedure getdir(drivenr : byte;var dir : shortstring);
  436. var
  437. thisdir : stat;
  438. rootino,
  439. thisino,
  440. dotdotino : longint;
  441. rootdev,
  442. thisdev,
  443. dotdotdev : {$ifdef bsd}longint{$else}word{$endif};
  444. thedir,dummy : string[255];
  445. dirstream : pdir;
  446. d : pdirent;
  447. mountpoint,validdir : boolean;
  448. predot : string[255];
  449. begin
  450. drivenr:=0;
  451. dir:='';
  452. thedir:='/'#0;
  453. if sys_stat(@thedir[1],thisdir)<0 then
  454. exit;
  455. rootino:=thisdir.ino;
  456. rootdev:=thisdir.dev;
  457. thedir:='.'#0;
  458. if sys_stat(@thedir[1],thisdir)<0 then
  459. exit;
  460. thisino:=thisdir.ino;
  461. thisdev:=thisdir.dev;
  462. { Now we can uniquely identify the current and root dir }
  463. thedir:='';
  464. predot:='';
  465. while not ((thisino=rootino) and (thisdev=rootdev)) do
  466. begin
  467. { Are we on a mount point ? }
  468. dummy:=predot+'..'#0;
  469. if sys_stat(@dummy[1],thisdir)<0 then
  470. exit;
  471. dotdotino:=thisdir.ino;
  472. dotdotdev:=thisdir.dev;
  473. mountpoint:=(thisdev<>dotdotdev);
  474. { Now, Try to find the name of this dir in the previous one }
  475. dirstream:=opendir (@dummy[1]);
  476. if dirstream=nil then
  477. exit;
  478. repeat
  479. d:=sys_readdir (dirstream);
  480. validdir:=false;
  481. if (d<>nil) and
  482. (not ((d^.name[0]='.') and ((d^.name[1]=#0) or ((d^.name[1]='.')
  483. and (d^.name[2]=#0))))) and
  484. (mountpoint or (d^.ino=thisino)) then
  485. begin
  486. dummy:=predot+'../'+strpas(@(d^.name[0]))+#0;
  487. validdir:=not (sys_stat (@(dummy[1]),thisdir)<0);
  488. end
  489. else
  490. validdir:=false;
  491. until (d=nil) or
  492. ((validdir) and (thisdir.dev=thisdev) and (thisdir.ino=thisino) );
  493. if (closedir(dirstream)<0) or (d=nil) then
  494. exit;
  495. { At this point, d.name contains the name of the current dir}
  496. thedir:='/'+strpas(@(d^.name[0]))+thedir;
  497. thisdev:=dotdotdev;
  498. thisino:=dotdotino;
  499. predot:=predot+'../';
  500. end;
  501. { Now rootino=thisino and rootdev=thisdev so we've reached / }
  502. dir:=thedir
  503. end;
  504. {*****************************************************************************
  505. SystemUnit Initialization
  506. *****************************************************************************}
  507. {$ifdef I386}
  508. { this should be defined in i386 directory !! PM }
  509. const
  510. fpucw : word = $1332;
  511. FPU_Invalid = 1;
  512. FPU_Denormal = 2;
  513. FPU_DivisionByZero = 4;
  514. FPU_Overflow = 8;
  515. FPU_Underflow = $10;
  516. FPU_StackUnderflow = $20;
  517. FPU_StackOverflow = $40;
  518. {$endif I386}
  519. Procedure ResetFPU;
  520. begin
  521. {$ifdef I386}
  522. {$ifndef CORRECTFLDCW}
  523. {$asmmode direct}
  524. {$endif}
  525. asm
  526. fninit
  527. fldcw fpucw
  528. end;
  529. {$ifndef CORRECTFLDCW}
  530. {$asmmode att}
  531. {$endif}
  532. {$endif I386}
  533. end;
  534. {$ifndef BSD}
  535. {$ifndef newSignal}
  536. Procedure SignalToRunError(Sig:longint);
  537. begin
  538. case sig of
  539. 8 : begin
  540. { this is not allways necessary but I don't know yet
  541. how to tell if it is or not PM }
  542. ResetFPU;
  543. HandleError(200);
  544. end;
  545. 11 : HandleError(216);
  546. end;
  547. end;
  548. Procedure InstallSignals;
  549. var
  550. sr : syscallregs;
  551. begin
  552. sr.reg3:=longint(@SignalToRunError);
  553. { sigsegv }
  554. sr.reg2:=11;
  555. syscall(syscall_nr_signal,sr);
  556. { sigfpe }
  557. sr.reg2:=8;
  558. syscall(syscall_nr_signal,sr);
  559. end;
  560. {$else newSignal}
  561. {$i i386/signal.inc}
  562. procedure SignalToRunerror(Sig: longint; SigContext: SigContextRec); cdecl;
  563. var
  564. res,fpustate : word;
  565. begin
  566. res:=0;
  567. case sig of
  568. 8 : begin
  569. { this is not allways necessary but I don't know yet
  570. how to tell if it is or not PM }
  571. {$ifdef I386}
  572. fpustate:=0;
  573. res:=200;
  574. if assigned(SigContext.fpstate) then
  575. fpuState:=SigContext.fpstate^.sw;
  576. {$ifdef SYSTEMDEBUG}
  577. Writeln(stderr,'FpuState = ',Hexstr(FpuState,4));
  578. {$endif SYSTEMDEBUG}
  579. if (FpuState and $7f) <> 0 then
  580. begin
  581. { first check te more precise options }
  582. if (FpuState and FPU_DivisionByZero)<>0 then
  583. res:=200
  584. else if (FpuState and FPU_Overflow)<>0 then
  585. res:=205
  586. else if (FpuState and FPU_Underflow)<>0 then
  587. res:=206
  588. else if (FpuState and FPU_Denormal)<>0 then
  589. res:=216
  590. else if (FpuState and (FPU_StackOverflow or FPU_StackUnderflow))<>0 then
  591. res:=207
  592. else if (FpuState and FPU_Invalid)<>0 then
  593. res:=216
  594. else
  595. res:=207; {'Coprocessor Error'}
  596. end;
  597. {$endif I386}
  598. ResetFPU;
  599. end;
  600. 11 : res:=216;
  601. end;
  602. { give runtime error at the position where the signal was raised }
  603. if res<>0 then
  604. begin
  605. {$ifdef I386}
  606. HandleErrorAddrFrame(res,SigContext.eip,SigContext.ebp);
  607. {$else}
  608. HandleError(res);
  609. {$endif}
  610. end;
  611. end;
  612. Procedure InstallSignals;
  613. const
  614. act: SigActionRec = (handler:(Sa:@SignalToRunError);sa_mask:0;sa_flags:0;
  615. Sa_restorer: NIL);
  616. oldact: PSigActionRec = Nil;
  617. begin
  618. ResetFPU;
  619. SigAction(8,@act,oldact);
  620. SigAction(11,@act,oldact);
  621. end;
  622. {$endif newSignal}
  623. {$endif bsd}
  624. procedure SetupCmdLine;
  625. var
  626. bufsize,
  627. len,j,
  628. size,i : longint;
  629. found : boolean;
  630. buf : array[0..1026] of char;
  631. procedure AddBuf;
  632. begin
  633. reallocmem(cmdline,size+bufsize);
  634. move(buf,cmdline[size],bufsize);
  635. inc(size,bufsize);
  636. bufsize:=0;
  637. end;
  638. begin
  639. size:=0;
  640. bufsize:=0;
  641. i:=0;
  642. while (i<argc) do
  643. begin
  644. len:=strlen(argv[i]);
  645. if len>sizeof(buf)-2 then
  646. len:=sizeof(buf)-2;
  647. found:=false;
  648. for j:=1 to len do
  649. if argv[i][j]=' ' then
  650. begin
  651. found:=true;
  652. break;
  653. end;
  654. if bufsize+len>=sizeof(buf)-2 then
  655. AddBuf;
  656. if found then
  657. begin
  658. buf[bufsize]:='"';
  659. inc(bufsize);
  660. end;
  661. move(argv[i]^,buf[bufsize],len);
  662. inc(bufsize,len);
  663. if found then
  664. begin
  665. buf[bufsize]:='"';
  666. inc(bufsize);
  667. end;
  668. if i<argc then
  669. buf[bufsize]:=' '
  670. else
  671. buf[bufsize]:=#0;
  672. inc(bufsize);
  673. inc(i);
  674. end;
  675. AddBuf;
  676. end;
  677. Begin
  678. { Set up signals handlers }
  679. {$ifndef bsd}
  680. InstallSignals;
  681. {$endif}
  682. { Setup heap }
  683. InitHeap;
  684. InitExceptions;
  685. { Arguments }
  686. SetupCmdLine;
  687. { Setup stdin, stdout and stderr }
  688. OpenStdIO(Input,fmInput,StdInputHandle);
  689. OpenStdIO(Output,fmOutput,StdOutputHandle);
  690. OpenStdIO(StdOut,fmOutput,StdOutputHandle);
  691. OpenStdIO(StdErr,fmOutput,StdErrorHandle);
  692. { Reset IO Error }
  693. InOutRes:=0;
  694. End.
  695. {
  696. $Log$
  697. Revision 1.49 2000-07-08 18:02:39 peter
  698. * do_open checks for directory, if directory then ioerror 2
  699. Revision 1.48 2000/06/30 22:14:03 peter
  700. * removed obsolete crtlib code
  701. * support EINTR for read/write to restart the syscall
  702. Revision 1.47 2000/05/11 17:55:13 peter
  703. * changed order of fpustate checking to first check the more
  704. specific states
  705. Revision 1.46 2000/05/08 14:27:36 peter
  706. * released newsignal
  707. * newsignal gives now better backtraces using the sigcontext eip/ebp
  708. fields
  709. Revision 1.45 2000/04/16 16:07:58 marco
  710. * BSD fixes
  711. Revision 1.44 2000/04/14 13:04:53 marco
  712. * Merged bsd/syslinux.pp and 1.43 linux/syslinux.pp to this file with ifdefs
  713. Revision 1.43 2000/04/07 14:56:36 peter
  714. * switch to direct asm if not correctfldcw defined
  715. Revision 1.42 2000/03/31 23:26:32 pierre
  716. * FPU needs reset for all SIGFPE even from integer division by zero
  717. Revision 1.41 2000/03/31 23:21:19 pierre
  718. * multiple exception handling works
  719. (for linux only if syslinux is compiled with -dnewsignal)
  720. Revision 1.40 2000/03/31 13:24:28 jonas
  721. * signal handling using sigaction when compiled with -dnewsignal
  722. (allows multiple signals to be received in one run)
  723. Revision 1.39 2000/03/25 12:28:37 peter
  724. * patch for getdir from Pierre
  725. Revision 1.38 2000/03/23 15:24:18 peter
  726. * remove handle check for do_close
  727. Revision 1.37 2000/02/09 16:59:32 peter
  728. * truncated log
  729. Revision 1.36 2000/02/09 12:17:51 peter
  730. * moved halt to system.inc
  731. * syslinux doesn't use direct asm anymore
  732. Revision 1.35 2000/02/08 11:47:09 peter
  733. * paramstr(0) support
  734. Revision 1.34 2000/01/20 23:38:02 peter
  735. * support fm_inout as stdoutput for assign(f,'');rewrite(f,1); becuase
  736. rewrite opens always with filemode 2
  737. Revision 1.33 2000/01/16 22:25:38 peter
  738. * check handle for file closing
  739. Revision 1.32 2000/01/07 16:41:41 daniel
  740. * copyright 2000
  741. Revision 1.31 2000/01/07 16:32:28 daniel
  742. * copyright 2000 added
  743. Revision 1.30 1999/12/01 22:57:31 peter
  744. * cmdline support
  745. Revision 1.29 1999/11/06 14:39:12 peter
  746. * truncated log
  747. Revision 1.28 1999/10/28 09:50:06 peter
  748. * use mmap instead of brk
  749. Revision 1.27 1999/09/10 15:40:35 peter
  750. * fixed do_open flags to be > $100, becuase filemode can be upto 255
  751. Revision 1.26 1999/09/08 16:14:43 peter
  752. * pointer fixes
  753. Revision 1.25 1999/07/28 23:18:36 peter
  754. * closedir fixes, which now disposes the pdir itself
  755. }