dos.pp 20 KB

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