dos.pp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952
  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. {$IFNDEF BSD}
  179. UName(info);
  180. Move(info.release,buffer[0],40);
  181. TmpStr:=StrPas(Buffer);
  182. {$ELSE}
  183. TmpStr:='FreeBSD doesn''t support UName';
  184. {$ENDIF}
  185. SubRel:=0;
  186. TmpPos:=Pos('.',TmpStr);
  187. if TmpPos>0 then
  188. begin
  189. Tmp2:=Copy(TmpStr,TmpPos+1,40);
  190. Delete(TmpStr,TmpPos,40);
  191. end;
  192. TmpPos:=Pos('.',Tmp2);
  193. if TmpPos>0 then
  194. Delete(Tmp2,TmpPos,40);
  195. Val(TmpStr,Rel);
  196. Val(Tmp2,SubRel);
  197. DosVersion:=Rel+(SubRel shl 8);
  198. End;
  199. function WeekDay (y,m,d:longint):longint;
  200. {
  201. Calculates th day of the week. returns -1 on error
  202. }
  203. var
  204. u,v : longint;
  205. begin
  206. if (m<1) or (m>12) or (y<1600) or (y>4000) or
  207. (d<1) or (d>30+((m+ord(m>7)) and 1)-ord(m=2)) or
  208. ((m*d=58) and (((y mod 4>0) or (y mod 100=0)) and (y mod 400>0))) then
  209. WeekDay:=-1
  210. else
  211. begin
  212. u:=m;
  213. v:=y;
  214. if m<3 then
  215. begin
  216. inc(u,12);
  217. dec(v);
  218. end;
  219. WeekDay:=(d+2*u+((3*(u+1)) div 5)+v+(v div 4)-(v div 100)+(v div 400)+1) mod 7;
  220. end;
  221. end;
  222. Procedure GetDate(Var Year, Month, MDay, WDay: Word);
  223. Begin
  224. Linux.GetDate(Year,Month,MDay);
  225. Wday:=weekday(Year,Month,MDay);
  226. end;
  227. Procedure SetDate(Year, Month, Day: Word);
  228. Begin
  229. {!!}
  230. End;
  231. Procedure GetTime(Var Hour, Minute, Second, Sec100: Word);
  232. Begin
  233. Linux.GetTime(Hour,Minute,Second,Sec100);
  234. end;
  235. Procedure SetTime(Hour, Minute, Second, Sec100: Word);
  236. Begin
  237. {!!}
  238. End;
  239. Procedure packtime(var t : datetime;var p : longint);
  240. Begin
  241. 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);
  242. End;
  243. Procedure unpacktime(p : longint;var t : datetime);
  244. Begin
  245. t.sec:=(p and 31) shl 1;
  246. t.min:=(p shr 5) and 63;
  247. t.hour:=(p shr 11) and 31;
  248. t.day:=(p shr 16) and 31;
  249. t.month:=(p shr 21) and 15;
  250. t.year:=(p shr 25)+1980;
  251. End;
  252. Procedure UnixDateToDt(SecsPast: LongInt; Var Dt: DateTime);
  253. Begin
  254. EpochToLocal(SecsPast,dt.Year,dt.Month,dt.Day,dt.Hour,dt.Min,dt.Sec);
  255. End;
  256. Function DTToUnixDate(DT: DateTime): LongInt;
  257. Begin
  258. DTToUnixDate:=LocalToEpoch(dt.Year,dt.Month,dt.Day,dt.Hour,dt.Min,dt.Sec);
  259. End;
  260. {******************************************************************************
  261. --- Exec ---
  262. ******************************************************************************}
  263. var
  264. LastDosExitCode: word;
  265. Procedure Exec (Const Path: PathStr; Const ComLine: ComStr);
  266. var
  267. pid : longint;
  268. status : longint;
  269. Begin
  270. LastDosExitCode:=0;
  271. pid:=Fork;
  272. if pid=0 then
  273. begin
  274. {The child does the actual exec, and then exits}
  275. Execl (Path+' '+ComLine);
  276. {If the execve fails, we return an exitvalue of 127, to let it be known}
  277. halt (127)
  278. end
  279. else
  280. if pid=-1 then {Fork failed}
  281. begin
  282. DosError:=8;
  283. exit
  284. end;
  285. {We're in the parent, let's wait.}
  286. Waitpid (pid,@status,0);
  287. if status=127 then {The child couldn't execve !!}
  288. DosError:=8 {We set this error, erroneously, since we cannot get to the real error}
  289. else
  290. begin
  291. LastDosExitCode:=status shr 8;
  292. DosError:=0
  293. end;
  294. End;
  295. Function DosExitCode: Word;
  296. Begin
  297. DosExitCode:=LastDosExitCode;
  298. End;
  299. {******************************************************************************
  300. --- Disk ---
  301. ******************************************************************************}
  302. {
  303. The Diskfree and Disksize functions need a file on the specified drive, since this
  304. is required for the statfs system call.
  305. These filenames are set in drivestr[0..26], and have been preset to :
  306. 0 - '.' (default drive - hence current dir is ok.)
  307. 1 - '/fd0/.' (floppy drive 1 - should be adapted to local system )
  308. 2 - '/fd1/.' (floppy drive 2 - should be adapted to local system )
  309. 3 - '/' (C: equivalent of dos is the root partition)
  310. 4..26 (can be set by you're own applications)
  311. ! Use AddDisk() to Add new drives !
  312. They both return -1 when a failure occurs.
  313. }
  314. Const
  315. FixDriveStr : array[0..3] of pchar=(
  316. '.',
  317. '/fd0/.',
  318. '/fd1/.',
  319. '/.'
  320. );
  321. var
  322. Drives : byte;
  323. DriveStr : array[4..26] of pchar;
  324. Procedure AddDisk(const path:string);
  325. begin
  326. if not (DriveStr[Drives]=nil) then
  327. FreeMem(DriveStr[Drives],StrLen(DriveStr[Drives])+1);
  328. GetMem(DriveStr[Drives],length(Path)+1);
  329. StrPCopy(DriveStr[Drives],path);
  330. inc(Drives);
  331. if Drives>26 then
  332. Drives:=4;
  333. end;
  334. {$ifdef INT64}
  335. Function DiskFree(Drive: Byte): int64;
  336. var
  337. fs : statfs;
  338. Begin
  339. if ((Drive<4) and (not (fixdrivestr[Drive]=nil)) and fsstat(StrPas(fixdrivestr[drive]),fs)) or
  340. ((not (drivestr[Drive]=nil)) and fsstat(StrPas(drivestr[drive]),fs)) then
  341. Diskfree:=int64(fs.bavail)*int64(fs.bsize)
  342. else
  343. Diskfree:=-1;
  344. End;
  345. Function DiskSize(Drive: Byte): int64;
  346. var
  347. fs : statfs;
  348. Begin
  349. if ((Drive<4) and (not (fixdrivestr[Drive]=nil)) and fsstat(StrPas(fixdrivestr[drive]),fs)) or
  350. ((not (drivestr[Drive]=nil)) and fsstat(StrPas(drivestr[drive]),fs)) then
  351. DiskSize:=int64(fs.blocks)*int64(fs.bsize)
  352. else
  353. DiskSize:=-1;
  354. End;
  355. {$else}
  356. Function DiskFree(Drive: Byte): Longint;
  357. var
  358. fs : statfs;
  359. Begin
  360. if ((Drive<4) and (not (fixdrivestr[Drive]=nil)) and fsstat(StrPas(fixdrivestr[drive]),fs)) or
  361. ((not (drivestr[Drive]=nil)) and fsstat(StrPas(drivestr[drive]),fs)) then
  362. Diskfree:=fs.bavail*fs.bsize
  363. else
  364. Diskfree:=-1;
  365. End;
  366. Function DiskSize(Drive: Byte): Longint;
  367. var
  368. fs : statfs;
  369. Begin
  370. if ((Drive<4) and (not (fixdrivestr[Drive]=nil)) and fsstat(StrPas(fixdrivestr[drive]),fs)) or
  371. ((not (drivestr[Drive]=nil)) and fsstat(StrPas(drivestr[drive]),fs)) then
  372. DiskSize:=fs.blocks*fs.bsize
  373. else
  374. DiskSize:=-1;
  375. End;
  376. {$endif INT64}
  377. {******************************************************************************
  378. --- Findfirst FindNext ---
  379. ******************************************************************************}
  380. Const
  381. RtlFindSize = 15;
  382. Type
  383. RtlFindRecType = Record
  384. SearchNum,
  385. DirPtr,
  386. LastUsed : LongInt;
  387. End;
  388. Var
  389. RtlFindRecs : Array[1..RtlFindSize] of RtlFindRecType;
  390. CurrSearchNum : LongInt;
  391. Procedure FindClose(Var f: SearchRec);
  392. {
  393. Closes dirptr if it is open
  394. }
  395. Var
  396. i : longint;
  397. Begin
  398. if f.SearchType=0 then
  399. begin
  400. i:=1;
  401. repeat
  402. if (RtlFindRecs[i].SearchNum=f.SearchNum) then
  403. break;
  404. inc(i);
  405. until (i>RtlFindSize);
  406. If i<=RtlFindSize Then
  407. Begin
  408. RtlFindRecs[i].SearchNum:=0;
  409. if f.dirptr>0 then
  410. closedir(pdir(f.dirptr));
  411. End;
  412. end;
  413. f.dirptr:=0;
  414. End;
  415. Function FindGetFileInfo(const s:string;var f:SearchRec):boolean;
  416. var
  417. DT : DateTime;
  418. Info : RtlInfoType;
  419. st : stat;
  420. begin
  421. FindGetFileInfo:=false;
  422. if not Fstat(s,st) then
  423. exit;
  424. info.FSize:=st.Size;
  425. info.FMTime:=st.mtime;
  426. if (st.mode and STAT_IFMT)=STAT_IFDIR then
  427. info.fmode:=$10
  428. else
  429. info.fmode:=$20;
  430. if (st.mode and STAT_IWUSR)=0 then
  431. info.fmode:=info.fmode or 1;
  432. If ((Info.FMode and Not(f.searchattr))=0) Then
  433. Begin
  434. f.Name:=Copy(s,f.NamePos+1,255);
  435. f.Attr:=Info.FMode;
  436. f.Size:=Info.FSize;
  437. UnixDateToDT(Info.FMTime, DT);
  438. PackTime(DT,f.Time);
  439. FindGetFileInfo:=true;
  440. End;
  441. end;
  442. Function FindLastUsed: Longint;
  443. {
  444. Find unused or least recently used dirpointer slot in findrecs array
  445. }
  446. Var
  447. BestMatch,i : Longint;
  448. Found : Boolean;
  449. Begin
  450. BestMatch:=1;
  451. i:=1;
  452. Found:=False;
  453. While (i <= RtlFindSize) And (Not Found) Do
  454. Begin
  455. If (RtlFindRecs[i].SearchNum = 0) Then
  456. Begin
  457. BestMatch := i;
  458. Found := True;
  459. End
  460. Else
  461. Begin
  462. If RtlFindRecs[i].LastUsed > RtlFindRecs[BestMatch].LastUsed Then
  463. BestMatch := i;
  464. End;
  465. Inc(i);
  466. End;
  467. FindLastUsed := BestMatch;
  468. End;
  469. Procedure FindNext(Var f: SearchRec);
  470. {
  471. re-opens dir if not already in array and calls FindWorkProc
  472. }
  473. Var
  474. DirName : Array[0..256] of Char;
  475. i,
  476. ArrayPos : Longint;
  477. FName,
  478. SName : string;
  479. Found,
  480. Finished : boolean;
  481. p : PDirEnt;
  482. Begin
  483. If f.SearchType=0 Then
  484. Begin
  485. ArrayPos:=0;
  486. For i:=1 to RtlFindSize Do
  487. Begin
  488. If RtlFindRecs[i].SearchNum = f.SearchNum Then
  489. ArrayPos:=i;
  490. Inc(RtlFindRecs[i].LastUsed);
  491. End;
  492. If ArrayPos=0 Then
  493. Begin
  494. If f.NamePos = 0 Then
  495. Begin
  496. DirName[0] := '.';
  497. DirName[1] := '/';
  498. DirName[2] := #0;
  499. End
  500. Else
  501. Begin
  502. Move(f.SearchSpec[1], DirName[0], f.NamePos);
  503. DirName[f.NamePos] := #0;
  504. End;
  505. f.DirPtr := longint(opendir(@(DirName)));
  506. If f.DirPtr > 0 Then
  507. begin
  508. ArrayPos:=FindLastUsed;
  509. If RtlFindRecs[ArrayPos].SearchNum > 0 Then
  510. CloseDir(pdir(rtlfindrecs[arraypos].dirptr));
  511. RtlFindRecs[ArrayPos].SearchNum := f.SearchNum;
  512. RtlFindRecs[ArrayPos].DirPtr := f.DirPtr;
  513. if f.searchpos>0 then
  514. seekdir(pdir(f.dirptr), f.searchpos);
  515. end;
  516. End;
  517. if ArrayPos>0 then
  518. RtlFindRecs[ArrayPos].LastUsed:=0;
  519. end;
  520. {Main loop}
  521. SName:=Copy(f.SearchSpec,f.NamePos+1,255);
  522. Found:=False;
  523. Finished:=(f.dirptr=0);
  524. While Not Finished Do
  525. Begin
  526. p:=readdir(pdir(f.dirptr));
  527. if p=nil then
  528. FName:=''
  529. else
  530. FName:=Strpas(@p^.name);
  531. If FName='' Then
  532. Finished:=True
  533. Else
  534. Begin
  535. If FNMatch(SName,FName) Then
  536. Begin
  537. Found:=FindGetFileInfo(Copy(f.SearchSpec,1,f.NamePos)+FName,f);
  538. if Found then
  539. Finished:=true;
  540. End;
  541. End;
  542. End;
  543. {Shutdown}
  544. If Found Then
  545. Begin
  546. f.searchpos:=telldir(pdir(f.dirptr));
  547. DosError:=0;
  548. End
  549. Else
  550. Begin
  551. FindClose(f);
  552. DosError:=18;
  553. End;
  554. End;
  555. Procedure FindFirst(Const Path: PathStr; Attr: Word; Var f: SearchRec);
  556. {
  557. opens dir and calls FindWorkProc
  558. }
  559. Begin
  560. if Path='' then
  561. begin
  562. DosError:=3;
  563. exit;
  564. end;
  565. {Create Info}
  566. f.SearchSpec := Path;
  567. f.SearchAttr := Attr;
  568. f.SearchPos:=0;
  569. f.NamePos := Length(f.SearchSpec);
  570. while (f.NamePos>0) and (f.SearchSpec[f.NamePos]<>'/') do
  571. dec(f.NamePos);
  572. {Wildcards?}
  573. if (Pos('?',Path)=0) and (Pos('*',Path)=0) then
  574. begin
  575. if FindGetFileInfo(Path,f) then
  576. DosError:=0
  577. else
  578. begin
  579. if ErrNo=Sys_ENOENT then
  580. DosError:=3
  581. else
  582. DosError:=18;
  583. end;
  584. f.DirPtr:=0;
  585. f.SearchType:=1;
  586. f.searchnum:=-1;
  587. end
  588. else
  589. {Find Entry}
  590. begin
  591. Inc(CurrSearchNum);
  592. f.SearchNum:=CurrSearchNum;
  593. f.SearchType:=0;
  594. FindNext(f);
  595. end;
  596. End;
  597. {******************************************************************************
  598. --- File ---
  599. ******************************************************************************}
  600. Procedure FSplit(Path: PathStr; Var Dir: DirStr; Var Name: NameStr;Var Ext: ExtStr);
  601. Begin
  602. Linux.FSplit(Path,Dir,Name,Ext);
  603. End;
  604. Function FExpand(Const Path: PathStr): PathStr;
  605. Begin
  606. FExpand:=Linux.FExpand(Path);
  607. End;
  608. Function FSearch(path : pathstr;dirlist : string) : pathstr;
  609. Var
  610. info:stat;
  611. Begin
  612. if (length(Path)>0) and (path[1]='/') and FStat(path,info) then
  613. FSearch:=path
  614. else
  615. FSearch:=Linux.FSearch(path,dirlist);
  616. End;
  617. Procedure GetFAttr(var f; var attr : word);
  618. Var
  619. info : stat;
  620. LinAttr : longint;
  621. Begin
  622. DosError:=0;
  623. if not FStat(strpas(@textrec(f).name),info) then
  624. begin
  625. Attr:=0;
  626. DosError:=3;
  627. exit;
  628. end
  629. else
  630. LinAttr:=Info.Mode;
  631. if S_ISDIR(LinAttr) then
  632. Attr:=$10
  633. else
  634. Attr:=$20;
  635. if not Access(strpas(@textrec(f).name),W_OK) then
  636. Attr:=Attr or $1;
  637. if (not S_ISDIR(LinAttr)) and (filerec(f).name[0]='.') then
  638. Attr:=Attr or $2;
  639. end;
  640. Procedure getftime (var f; var time : longint);
  641. Var
  642. Info: stat;
  643. DT: DateTime;
  644. Begin
  645. doserror:=0;
  646. if not fstat(filerec(f).handle,info) then
  647. begin
  648. Time:=0;
  649. doserror:=3;
  650. exit
  651. end
  652. else
  653. UnixDateToDT(Info.mTime,DT);
  654. PackTime(DT,Time);
  655. End;
  656. {******************************************************************************
  657. --- Environment ---
  658. ******************************************************************************}
  659. Function EnvCount: Longint;
  660. var
  661. envcnt : longint;
  662. p : ppchar;
  663. Begin
  664. envcnt:=0;
  665. p:=envp; {defined in syslinux}
  666. while (p^<>nil) do
  667. begin
  668. inc(envcnt);
  669. inc(p);
  670. end;
  671. EnvCount := envcnt
  672. End;
  673. Function EnvStr(Index: Integer): String;
  674. Var
  675. i : longint;
  676. p : ppchar;
  677. Begin
  678. p:=envp; {defined in syslinux}
  679. i:=1;
  680. while (i<Index) and (p^<>nil) do
  681. begin
  682. inc(i);
  683. inc(p);
  684. end;
  685. if p=nil then
  686. envstr:=''
  687. else
  688. envstr:=strpas(p^)
  689. End;
  690. Function GetEnv(EnvVar: String): String;
  691. var
  692. p : pchar;
  693. Begin
  694. p:=Linux.GetEnv(EnvVar);
  695. if p=nil then
  696. GetEnv:=''
  697. else
  698. GetEnv:=StrPas(p);
  699. End;
  700. {******************************************************************************
  701. --- Do Nothing Procedures/Functions ---
  702. ******************************************************************************}
  703. Procedure Intr (intno: byte; var regs: registers);
  704. Begin
  705. {! No Linux equivalent !}
  706. End;
  707. Procedure msdos(var regs : registers);
  708. Begin
  709. {! No Linux equivalent !}
  710. End;
  711. Procedure getintvec(intno : byte;var vector : pointer);
  712. Begin
  713. {! No Linux equivalent !}
  714. End;
  715. Procedure setintvec(intno : byte;vector : pointer);
  716. Begin
  717. {! No Linux equivalent !}
  718. End;
  719. Procedure SwapVectors;
  720. Begin
  721. {! No Linux equivalent !}
  722. End;
  723. Procedure keep(exitcode : word);
  724. Begin
  725. {! No Linux equivalent !}
  726. End;
  727. Procedure setftime(var f; time : longint);
  728. Begin
  729. {! No Linux equivalent !}
  730. End;
  731. Procedure setfattr (var f;attr : word);
  732. Begin
  733. {! No Linux equivalent !}
  734. End;
  735. Procedure GetCBreak(Var BreakValue: Boolean);
  736. Begin
  737. {! No Linux equivalent !}
  738. breakvalue:=true
  739. End;
  740. Procedure SetCBreak(BreakValue: Boolean);
  741. Begin
  742. {! No Linux equivalent !}
  743. End;
  744. Procedure GetVerify(Var Verify: Boolean);
  745. Begin
  746. {! No Linux equivalent !}
  747. Verify:=true;
  748. End;
  749. Procedure SetVerify(Verify: Boolean);
  750. Begin
  751. {! No Linux equivalent !}
  752. End;
  753. {******************************************************************************
  754. --- Initialization ---
  755. ******************************************************************************}
  756. End.
  757. {
  758. $Log$
  759. Revision 1.21 2000-04-18 08:03:40 michael
  760. Corrected fix for bug 902
  761. Revision 1.20 2000/04/17 20:43:27 pierre
  762. fix bug 902 for win32 and linux
  763. Revision 1.19 2000/03/19 18:48:19 peter
  764. * dosexitcode finally works correct
  765. Revision 1.18 2000/03/16 15:23:02 marco
  766. * Added one BSD conditional (uname not supported)
  767. Revision 1.17 2000/02/09 16:59:31 peter
  768. * truncated log
  769. Revision 1.16 2000/02/02 15:07:05 peter
  770. * gettime supports now also sec100
  771. * removed crtlib code as it was broken (still available in old releases)
  772. * int64 disksize/diskfree
  773. Revision 1.15 2000/01/07 16:41:40 daniel
  774. * copyright 2000
  775. Revision 1.14 2000/01/07 16:32:26 daniel
  776. * copyright 2000 added
  777. Revision 1.13 1999/09/08 16:14:41 peter
  778. * pointer fixes
  779. Revision 1.12 1999/07/28 23:18:35 peter
  780. * closedir fixes, which now disposes the pdir itself
  781. Revision 1.11 1999/07/24 11:18:11 peter
  782. * fixed getfattr which didn't reset doserror
  783. }