dos.pp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Michael Van Canneyt and Peter Vreman,
  5. members 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. Unit Dos;
  13. Interface
  14. Const
  15. {Max FileName Length for files}
  16. FileNameLen=255;
  17. {Bitmasks for CPU Flags}
  18. fcarry = $0001;
  19. fparity = $0004;
  20. fauxiliary = $0010;
  21. fzero = $0040;
  22. fsign = $0080;
  23. foverflow = $0800;
  24. {Bitmasks for file attribute}
  25. readonly = $01;
  26. hidden = $02;
  27. sysfile = $04;
  28. volumeid = $08;
  29. directory = $10;
  30. archive = $20;
  31. anyfile = $3F;
  32. {File Status}
  33. fmclosed = $D7B0;
  34. fminput = $D7B1;
  35. fmoutput = $D7B2;
  36. fminout = $D7B3;
  37. Type
  38. ComStr = String[FileNameLen];
  39. PathStr = String[FileNameLen];
  40. DirStr = String[FileNameLen];
  41. NameStr = String[FileNameLen];
  42. ExtStr = String[FileNameLen];
  43. SearchRec = packed Record
  44. {Fill : array[1..21] of byte; Fill replaced with below}
  45. SearchNum : LongInt; {to track which search this is}
  46. SearchPos : LongInt; {directory position}
  47. DirPtr : LongInt; {directory pointer for reading directory}
  48. SearchType : Byte; {0=normal, 1=open will close, 2=only 1 file}
  49. SearchAttr : Byte; {attribute we are searching for}
  50. Fill : Array[1..07] of Byte; {future use}
  51. {End of fill}
  52. Attr : Byte; {attribute of found file}
  53. Time : LongInt; {last modify date of found file}
  54. Size : LongInt; {file size of found file}
  55. Reserved : Word; {future use}
  56. Name : String[FileNameLen]; {name of found file}
  57. SearchSpec : String[FileNameLen]; {search pattern}
  58. NamePos : Word; {end of path, start of name position}
  59. End;
  60. {
  61. filerec.inc contains the definition of the filerec.
  62. textrec.inc contains the definition of the textrec.
  63. It is in a separate file to make it available in other units without
  64. having to use the DOS unit for it.
  65. }
  66. {$i filerec.inc}
  67. {$i textrec.inc}
  68. Registers = packed record
  69. case i : integer of
  70. 0 : (ax,f1,bx,f2,cx,f3,dx,f4,bp,f5,si,f51,di,f6,ds,f7,es,f8,flags,fs,gs : word);
  71. 1 : (al,ah,f9,f10,bl,bh,f11,f12,cl,ch,f13,f14,dl,dh : byte);
  72. 2 : (eax, ebx, ecx, edx, ebp, esi, edi : longint);
  73. End;
  74. DateTime = packed record
  75. Year,
  76. Month,
  77. Day,
  78. Hour,
  79. Min,
  80. Sec : word;
  81. End;
  82. Var
  83. DosError : integer;
  84. {Utils}
  85. function weekday(y,m,d : longint) : longint;
  86. Procedure UnixDateToDt(SecsPast: LongInt; Var Dt: DateTime);
  87. Function DTToUnixDate(DT: DateTime): LongInt;
  88. {Info/Date/Time}
  89. Function DosVersion: Word;
  90. Procedure GetDate(var year, month, mday, wday: word);
  91. Procedure GetTime(var hour, minute, second, sec100: word);
  92. procedure SetDate(year,month,day: word);
  93. Procedure SetTime(hour,minute,second,sec100: word);
  94. Procedure UnpackTime(p: longint; var t: datetime);
  95. Procedure PackTime(var t: datetime; var p: longint);
  96. {Exec}
  97. Procedure Exec(const path: pathstr; const comline: comstr);
  98. Function DosExitCode: word;
  99. {Disk}
  100. Procedure AddDisk(const path:string);
  101. {$ifdef Int64}
  102. Function DiskFree(drive: byte) : int64;
  103. Function DiskSize(drive: byte) : int64;
  104. {$else}
  105. Function DiskFree(drive: byte) : longint;
  106. Function DiskSize(drive: byte) : longint;
  107. {$endif}
  108. Procedure FindFirst(const path: pathstr; attr: word; var f: searchRec);
  109. Procedure FindNext(var f: searchRec);
  110. Procedure FindClose(Var f: SearchRec);
  111. {File}
  112. Procedure GetFAttr(var f; var attr: word);
  113. Procedure GetFTime(var f; var time: longint);
  114. Function FSearch(path: pathstr; dirlist: string): pathstr;
  115. Function FExpand(const path: pathstr): pathstr;
  116. Procedure FSplit(path: pathstr; var dir: dirstr; var name: namestr; var ext: extstr);
  117. {Environment}
  118. Function EnvCount: longint;
  119. Function EnvStr(index: integer): string;
  120. Function GetEnv (envvar: string): string;
  121. {Do Nothing Functions, no Linux version}
  122. Procedure Intr(intno: byte; var regs: registers);
  123. Procedure MSDos(var regs: registers);
  124. Procedure SwapVectors;
  125. Procedure GetIntVec(intno: byte; var vector: pointer);
  126. Procedure SetIntVec(intno: byte; vector: pointer);
  127. Procedure Keep(exitcode: word);
  128. Procedure SetFAttr(var f; attr: word);
  129. Procedure SetFTime(var f; time: longint);
  130. Procedure GetCBreak(var breakvalue: boolean);
  131. Procedure SetCBreak(breakvalue: boolean);
  132. Procedure GetVerify(var verify: boolean);
  133. Procedure SetVerify(verify: boolean);
  134. Implementation
  135. Uses
  136. Strings,linux;
  137. {******************************************************************************
  138. --- Link C Lib if set ---
  139. ******************************************************************************}
  140. type
  141. RtlInfoType = Record
  142. FMode,
  143. FInode,
  144. FUid,
  145. FGid,
  146. FSize,
  147. FMTime : LongInt;
  148. End;
  149. {******************************************************************************
  150. --- Info / Date / Time ---
  151. ******************************************************************************}
  152. Const
  153. {Date Calculation}
  154. C1970 = 2440588;
  155. D0 = 1461;
  156. D1 = 146097;
  157. D2 = 1721119;
  158. type
  159. GTRec = packed Record
  160. Year,
  161. Month,
  162. MDay,
  163. WDay,
  164. Hour,
  165. Minute,
  166. Second : Word;
  167. End;
  168. Function DosVersion:Word;
  169. Var
  170. Buffer : Array[0..255] of Char;
  171. Tmp2,
  172. TmpStr : String[40];
  173. TmpPos,
  174. SubRel,
  175. Rel : LongInt;
  176. info : utsname;
  177. Begin
  178. UName(info);
  179. Move(info.release,buffer[0],40);
  180. TmpStr:=StrPas(Buffer);
  181. SubRel:=0;
  182. TmpPos:=Pos('.',TmpStr);
  183. if TmpPos>0 then
  184. begin
  185. Tmp2:=Copy(TmpStr,TmpPos+1,40);
  186. Delete(TmpStr,TmpPos,40);
  187. end;
  188. TmpPos:=Pos('.',Tmp2);
  189. if TmpPos>0 then
  190. Delete(Tmp2,TmpPos,40);
  191. Val(TmpStr,Rel);
  192. Val(Tmp2,SubRel);
  193. DosVersion:=Rel+(SubRel shl 8);
  194. End;
  195. function WeekDay (y,m,d:longint):longint;
  196. {
  197. Calculates th day of the week. returns -1 on error
  198. }
  199. var
  200. u,v : longint;
  201. begin
  202. if (m<1) or (m>12) or (y<1600) or (y>4000) or
  203. (d<1) or (d>30+((m+ord(m>7)) and 1)-ord(m=2)) or
  204. ((m*d=58) and (((y mod 4>0) or (y mod 100=0)) and (y mod 400>0))) then
  205. WeekDay:=-1
  206. else
  207. begin
  208. u:=m;
  209. v:=y;
  210. if m<3 then
  211. begin
  212. inc(u,12);
  213. dec(v);
  214. end;
  215. WeekDay:=(d+2*u+((3*(u+1)) div 5)+v+(v div 4)-(v div 100)+(v div 400)+1) mod 7;
  216. end;
  217. end;
  218. Procedure GetDate(Var Year, Month, MDay, WDay: Word);
  219. Begin
  220. Linux.GetDate(Year,Month,MDay);
  221. Wday:=weekday(Year,Month,MDay);
  222. end;
  223. Procedure SetDate(Year, Month, Day: Word);
  224. Begin
  225. {!!}
  226. End;
  227. Procedure GetTime(Var Hour, Minute, Second, Sec100: Word);
  228. Begin
  229. Linux.GetTime(Hour,Minute,Second,Sec100);
  230. end;
  231. Procedure SetTime(Hour, Minute, Second, Sec100: Word);
  232. Begin
  233. {!!}
  234. End;
  235. Procedure packtime(var t : datetime;var p : longint);
  236. Begin
  237. p:=(t.sec shr 1)+(t.min shl 5)+(t.hour shl 11)+(t.day shl 16)+(t.month shl 21)+((t.year-1980) shl 25);
  238. End;
  239. Procedure unpacktime(p : longint;var t : datetime);
  240. Begin
  241. t.sec:=(p and 31) shl 1;
  242. t.min:=(p shr 5) and 63;
  243. t.hour:=(p shr 11) and 31;
  244. t.day:=(p shr 16) and 31;
  245. t.month:=(p shr 21) and 15;
  246. t.year:=(p shr 25)+1980;
  247. End;
  248. Procedure UnixDateToDt(SecsPast: LongInt; Var Dt: DateTime);
  249. Begin
  250. EpochToLocal(SecsPast,dt.Year,dt.Month,dt.Day,dt.Hour,dt.Min,dt.Sec);
  251. End;
  252. Function DTToUnixDate(DT: DateTime): LongInt;
  253. Begin
  254. DTToUnixDate:=LocalToEpoch(dt.Year,dt.Month,dt.Day,dt.Hour,dt.Min,dt.Sec);
  255. End;
  256. {******************************************************************************
  257. --- Exec ---
  258. ******************************************************************************}
  259. var
  260. LastDosExitCode: word;
  261. Procedure Exec (Const Path: PathStr; Const ComLine: ComStr);
  262. var
  263. pid : longint;
  264. status : integer;
  265. Begin
  266. pid:=Fork;
  267. if pid=0 then
  268. begin
  269. {The child does the actual exec, and then exits}
  270. Execl (Path+' '+ComLine);
  271. {If the execve fails, we return an exitvalue of 127, to let it be known}
  272. halt (127)
  273. end
  274. else
  275. if pid=-1 then {Fork failed}
  276. begin
  277. DosError:=8;
  278. exit
  279. end;
  280. {We're in the parent, let's wait.}
  281. Waitpid (pid,@status,0);
  282. if status=127 then {The child couldn't execve !!}
  283. DosError:=8 {We set this error, erroneously, since we cannot get to the real error}
  284. else
  285. begin
  286. LastDosExitCode:=status shr 8;
  287. DosError:=0
  288. end;
  289. End;
  290. Function DosExitCode: Word;
  291. Begin
  292. DosExitCode:=LastDosExitCode;
  293. End;
  294. {******************************************************************************
  295. --- Disk ---
  296. ******************************************************************************}
  297. {
  298. The Diskfree and Disksize functions need a file on the specified drive, since this
  299. is required for the statfs system call.
  300. These filenames are set in drivestr[0..26], and have been preset to :
  301. 0 - '.' (default drive - hence current dir is ok.)
  302. 1 - '/fd0/.' (floppy drive 1 - should be adapted to local system )
  303. 2 - '/fd1/.' (floppy drive 2 - should be adapted to local system )
  304. 3 - '/' (C: equivalent of dos is the root partition)
  305. 4..26 (can be set by you're own applications)
  306. ! Use AddDisk() to Add new drives !
  307. They both return -1 when a failure occurs.
  308. }
  309. Const
  310. FixDriveStr : array[0..3] of pchar=(
  311. '.',
  312. '/fd0/.',
  313. '/fd1/.',
  314. '/.'
  315. );
  316. var
  317. Drives : byte;
  318. DriveStr : array[4..26] of pchar;
  319. Procedure AddDisk(const path:string);
  320. begin
  321. if not (DriveStr[Drives]=nil) then
  322. FreeMem(DriveStr[Drives],StrLen(DriveStr[Drives])+1);
  323. GetMem(DriveStr[Drives],length(Path)+1);
  324. StrPCopy(DriveStr[Drives],path);
  325. inc(Drives);
  326. if Drives>26 then
  327. Drives:=4;
  328. end;
  329. {$ifdef INT64}
  330. Function DiskFree(Drive: Byte): int64;
  331. var
  332. fs : statfs;
  333. Begin
  334. if ((Drive<4) and (not (fixdrivestr[Drive]=nil)) and fsstat(StrPas(fixdrivestr[drive]),fs)) or
  335. ((not (drivestr[Drive]=nil)) and fsstat(StrPas(drivestr[drive]),fs)) then
  336. Diskfree:=int64(fs.bavail)*int64(fs.bsize)
  337. else
  338. Diskfree:=-1;
  339. End;
  340. Function DiskSize(Drive: Byte): int64;
  341. var
  342. fs : statfs;
  343. Begin
  344. if ((Drive<4) and (not (fixdrivestr[Drive]=nil)) and fsstat(StrPas(fixdrivestr[drive]),fs)) or
  345. ((not (drivestr[Drive]=nil)) and fsstat(StrPas(drivestr[drive]),fs)) then
  346. DiskSize:=int64(fs.blocks)*int64(fs.bsize)
  347. else
  348. DiskSize:=-1;
  349. End;
  350. {$else}
  351. Function DiskFree(Drive: Byte): Longint;
  352. var
  353. fs : statfs;
  354. Begin
  355. if ((Drive<4) and (not (fixdrivestr[Drive]=nil)) and fsstat(StrPas(fixdrivestr[drive]),fs)) or
  356. ((not (drivestr[Drive]=nil)) and fsstat(StrPas(drivestr[drive]),fs)) then
  357. Diskfree:=fs.bavail*fs.bsize
  358. else
  359. Diskfree:=-1;
  360. End;
  361. Function DiskSize(Drive: Byte): Longint;
  362. var
  363. fs : statfs;
  364. Begin
  365. if ((Drive<4) and (not (fixdrivestr[Drive]=nil)) and fsstat(StrPas(fixdrivestr[drive]),fs)) or
  366. ((not (drivestr[Drive]=nil)) and fsstat(StrPas(drivestr[drive]),fs)) then
  367. DiskSize:=fs.blocks*fs.bsize
  368. else
  369. DiskSize:=-1;
  370. End;
  371. {$endif INT64}
  372. {******************************************************************************
  373. --- Findfirst FindNext ---
  374. ******************************************************************************}
  375. Const
  376. RtlFindSize = 15;
  377. Type
  378. RtlFindRecType = Record
  379. SearchNum,
  380. DirPtr,
  381. LastUsed : LongInt;
  382. End;
  383. Var
  384. RtlFindRecs : Array[1..RtlFindSize] of RtlFindRecType;
  385. CurrSearchNum : LongInt;
  386. Procedure FindClose(Var f: SearchRec);
  387. {
  388. Closes dirptr if it is open
  389. }
  390. Var
  391. i : longint;
  392. Begin
  393. if f.SearchType=0 then
  394. begin
  395. i:=1;
  396. repeat
  397. if (RtlFindRecs[i].SearchNum=f.SearchNum) then
  398. break;
  399. inc(i);
  400. until (i>RtlFindSize);
  401. If i<=RtlFindSize Then
  402. Begin
  403. RtlFindRecs[i].SearchNum:=0;
  404. if f.dirptr>0 then
  405. closedir(pdir(f.dirptr));
  406. End;
  407. end;
  408. f.dirptr:=0;
  409. End;
  410. Function FindGetFileInfo(const s:string;var f:SearchRec):boolean;
  411. var
  412. DT : DateTime;
  413. Info : RtlInfoType;
  414. st : stat;
  415. begin
  416. FindGetFileInfo:=false;
  417. if not Fstat(s,st) then
  418. exit;
  419. info.FSize:=st.Size;
  420. info.FMTime:=st.mtime;
  421. if (st.mode and STAT_IFMT)=STAT_IFDIR then
  422. info.fmode:=$10
  423. else
  424. info.fmode:=$20;
  425. if (st.mode and STAT_IWUSR)=0 then
  426. info.fmode:=info.fmode or 1;
  427. If ((Info.FMode and Not(f.searchattr))=0) Then
  428. Begin
  429. f.Name:=Copy(s,f.NamePos+1,255);
  430. f.Attr:=Info.FMode;
  431. f.Size:=Info.FSize;
  432. UnixDateToDT(Info.FMTime, DT);
  433. PackTime(DT,f.Time);
  434. FindGetFileInfo:=true;
  435. End;
  436. end;
  437. Function FindLastUsed: Longint;
  438. {
  439. Find unused or least recently used dirpointer slot in findrecs array
  440. }
  441. Var
  442. BestMatch,i : Longint;
  443. Found : Boolean;
  444. Begin
  445. BestMatch:=1;
  446. i:=1;
  447. Found:=False;
  448. While (i <= RtlFindSize) And (Not Found) Do
  449. Begin
  450. If (RtlFindRecs[i].SearchNum = 0) Then
  451. Begin
  452. BestMatch := i;
  453. Found := True;
  454. End
  455. Else
  456. Begin
  457. If RtlFindRecs[i].LastUsed > RtlFindRecs[BestMatch].LastUsed Then
  458. BestMatch := i;
  459. End;
  460. Inc(i);
  461. End;
  462. FindLastUsed := BestMatch;
  463. End;
  464. Procedure FindNext(Var f: SearchRec);
  465. {
  466. re-opens dir if not already in array and calls FindWorkProc
  467. }
  468. Var
  469. DirName : Array[0..256] of Char;
  470. i,
  471. ArrayPos : Longint;
  472. FName,
  473. SName : string;
  474. Found,
  475. Finished : boolean;
  476. p : PDirEnt;
  477. Begin
  478. If f.SearchType=0 Then
  479. Begin
  480. ArrayPos:=0;
  481. For i:=1 to RtlFindSize Do
  482. Begin
  483. If RtlFindRecs[i].SearchNum = f.SearchNum Then
  484. ArrayPos:=i;
  485. Inc(RtlFindRecs[i].LastUsed);
  486. End;
  487. If ArrayPos=0 Then
  488. Begin
  489. If f.NamePos = 0 Then
  490. Begin
  491. DirName[0] := '.';
  492. DirName[1] := '/';
  493. DirName[2] := #0;
  494. End
  495. Else
  496. Begin
  497. Move(f.SearchSpec[1], DirName[0], f.NamePos);
  498. DirName[f.NamePos] := #0;
  499. End;
  500. f.DirPtr := longint(opendir(@(DirName)));
  501. If f.DirPtr > 0 Then
  502. begin
  503. ArrayPos:=FindLastUsed;
  504. If RtlFindRecs[ArrayPos].SearchNum > 0 Then
  505. CloseDir(pdir(rtlfindrecs[arraypos].dirptr));
  506. RtlFindRecs[ArrayPos].SearchNum := f.SearchNum;
  507. RtlFindRecs[ArrayPos].DirPtr := f.DirPtr;
  508. if f.searchpos>0 then
  509. seekdir(pdir(f.dirptr), f.searchpos);
  510. end;
  511. End;
  512. if ArrayPos>0 then
  513. RtlFindRecs[ArrayPos].LastUsed:=0;
  514. end;
  515. {Main loop}
  516. SName:=Copy(f.SearchSpec,f.NamePos+1,255);
  517. Found:=False;
  518. Finished:=(f.dirptr=0);
  519. While Not Finished Do
  520. Begin
  521. p:=readdir(pdir(f.dirptr));
  522. if p=nil then
  523. FName:=''
  524. else
  525. FName:=Strpas(@p^.name);
  526. If FName='' Then
  527. Finished:=True
  528. Else
  529. Begin
  530. If FNMatch(SName,FName) Then
  531. Begin
  532. Found:=FindGetFileInfo(Copy(f.SearchSpec,1,f.NamePos)+FName,f);
  533. if Found then
  534. Finished:=true;
  535. End;
  536. End;
  537. End;
  538. {Shutdown}
  539. If Found Then
  540. Begin
  541. f.searchpos:=telldir(pdir(f.dirptr));
  542. DosError:=0;
  543. End
  544. Else
  545. Begin
  546. FindClose(f);
  547. DosError:=18;
  548. End;
  549. End;
  550. Procedure FindFirst(Const Path: PathStr; Attr: Word; Var f: SearchRec);
  551. {
  552. opens dir and calls FindWorkProc
  553. }
  554. Begin
  555. if Path='' then
  556. begin
  557. DosError:=3;
  558. exit;
  559. end;
  560. {Create Info}
  561. f.SearchSpec := Path;
  562. f.SearchAttr := Attr;
  563. f.SearchPos:=0;
  564. f.NamePos := Length(f.SearchSpec);
  565. while (f.NamePos>0) and (f.SearchSpec[f.NamePos]<>'/') do
  566. dec(f.NamePos);
  567. {Wildcards?}
  568. if (Pos('?',Path)=0) and (Pos('*',Path)=0) then
  569. begin
  570. if FindGetFileInfo(Path,f) then
  571. DosError:=0
  572. else
  573. begin
  574. if ErrNo=Sys_ENOENT then
  575. DosError:=3
  576. else
  577. DosError:=18;
  578. end;
  579. f.DirPtr:=0;
  580. f.SearchType:=1;
  581. f.searchnum:=-1;
  582. end
  583. else
  584. {Find Entry}
  585. begin
  586. Inc(CurrSearchNum);
  587. f.SearchNum:=CurrSearchNum;
  588. f.SearchType:=0;
  589. FindNext(f);
  590. end;
  591. End;
  592. {******************************************************************************
  593. --- File ---
  594. ******************************************************************************}
  595. Procedure FSplit(Path: PathStr; Var Dir: DirStr; Var Name: NameStr;Var Ext: ExtStr);
  596. Begin
  597. Linux.FSplit(Path,Dir,Name,Ext);
  598. End;
  599. Function FExpand(Const Path: PathStr): PathStr;
  600. Begin
  601. FExpand:=Linux.FExpand(Path);
  602. End;
  603. Function FSearch(path : pathstr;dirlist : string) : pathstr;
  604. Begin
  605. FSearch:=Linux.FSearch(path,dirlist);
  606. End;
  607. Procedure GetFAttr(var f; var attr : word);
  608. Var
  609. info : stat;
  610. LinAttr : longint;
  611. Begin
  612. DosError:=0;
  613. if not FStat(strpas(@textrec(f).name),info) then
  614. begin
  615. Attr:=0;
  616. DosError:=3;
  617. exit;
  618. end
  619. else
  620. LinAttr:=Info.Mode;
  621. if S_ISDIR(LinAttr) then
  622. Attr:=$10
  623. else
  624. Attr:=$20;
  625. if not Access(strpas(@textrec(f).name),W_OK) then
  626. Attr:=Attr or $1;
  627. if (not S_ISDIR(LinAttr)) and (filerec(f).name[0]='.') then
  628. Attr:=Attr or $2;
  629. end;
  630. Procedure getftime (var f; var time : longint);
  631. Var
  632. Info: stat;
  633. DT: DateTime;
  634. Begin
  635. doserror:=0;
  636. if not fstat(filerec(f).handle,info) then
  637. begin
  638. Time:=0;
  639. doserror:=3;
  640. exit
  641. end
  642. else
  643. UnixDateToDT(Info.mTime,DT);
  644. PackTime(DT,Time);
  645. End;
  646. {******************************************************************************
  647. --- Environment ---
  648. ******************************************************************************}
  649. Function EnvCount: Longint;
  650. var
  651. envcnt : longint;
  652. p : ppchar;
  653. Begin
  654. envcnt:=0;
  655. p:=envp; {defined in syslinux}
  656. while (p^<>nil) do
  657. begin
  658. inc(envcnt);
  659. inc(p);
  660. end;
  661. EnvCount := envcnt
  662. End;
  663. Function EnvStr(Index: Integer): String;
  664. Var
  665. i : longint;
  666. p : ppchar;
  667. Begin
  668. p:=envp; {defined in syslinux}
  669. i:=1;
  670. while (i<Index) and (p^<>nil) do
  671. begin
  672. inc(i);
  673. inc(p);
  674. end;
  675. if p=nil then
  676. envstr:=''
  677. else
  678. envstr:=strpas(p^)
  679. End;
  680. Function GetEnv(EnvVar: String): String;
  681. var
  682. p : pchar;
  683. Begin
  684. p:=Linux.GetEnv(EnvVar);
  685. if p=nil then
  686. GetEnv:=''
  687. else
  688. GetEnv:=StrPas(p);
  689. End;
  690. {******************************************************************************
  691. --- Do Nothing Procedures/Functions ---
  692. ******************************************************************************}
  693. Procedure Intr (intno: byte; var regs: registers);
  694. Begin
  695. {! No Linux equivalent !}
  696. End;
  697. Procedure msdos(var regs : registers);
  698. Begin
  699. {! No Linux equivalent !}
  700. End;
  701. Procedure getintvec(intno : byte;var vector : pointer);
  702. Begin
  703. {! No Linux equivalent !}
  704. End;
  705. Procedure setintvec(intno : byte;vector : pointer);
  706. Begin
  707. {! No Linux equivalent !}
  708. End;
  709. Procedure SwapVectors;
  710. Begin
  711. {! No Linux equivalent !}
  712. End;
  713. Procedure keep(exitcode : word);
  714. Begin
  715. {! No Linux equivalent !}
  716. End;
  717. Procedure setftime(var f; time : longint);
  718. Begin
  719. {! No Linux equivalent !}
  720. End;
  721. Procedure setfattr (var f;attr : word);
  722. Begin
  723. {! No Linux equivalent !}
  724. End;
  725. Procedure GetCBreak(Var BreakValue: Boolean);
  726. Begin
  727. {! No Linux equivalent !}
  728. breakvalue:=true
  729. End;
  730. Procedure SetCBreak(BreakValue: Boolean);
  731. Begin
  732. {! No Linux equivalent !}
  733. End;
  734. Procedure GetVerify(Var Verify: Boolean);
  735. Begin
  736. {! No Linux equivalent !}
  737. Verify:=true;
  738. End;
  739. Procedure SetVerify(Verify: Boolean);
  740. Begin
  741. {! No Linux equivalent !}
  742. End;
  743. {******************************************************************************
  744. --- Initialization ---
  745. ******************************************************************************}
  746. End.
  747. {
  748. $Log$
  749. Revision 1.17 2000-02-09 16:59:31 peter
  750. * truncated log
  751. Revision 1.16 2000/02/02 15:07:05 peter
  752. * gettime supports now also sec100
  753. * removed crtlib code as it was broken (still available in old releases)
  754. * int64 disksize/diskfree
  755. Revision 1.15 2000/01/07 16:41:40 daniel
  756. * copyright 2000
  757. Revision 1.14 2000/01/07 16:32:26 daniel
  758. * copyright 2000 added
  759. Revision 1.13 1999/09/08 16:14:41 peter
  760. * pointer fixes
  761. Revision 1.12 1999/07/28 23:18:35 peter
  762. * closedir fixes, which now disposes the pdir itself
  763. Revision 1.11 1999/07/24 11:18:11 peter
  764. * fixed getfattr which didn't reset doserror
  765. }