dos.pp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909
  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. Function DiskFree(drive: byte) : int64;
  102. Function DiskSize(drive: byte) : int64;
  103. Procedure FindFirst(const path: pathstr; attr: word; var f: searchRec);
  104. Procedure FindNext(var f: searchRec);
  105. Procedure FindClose(Var f: SearchRec);
  106. {File}
  107. Procedure GetFAttr(var f; var attr: word);
  108. Procedure GetFTime(var f; var time: longint);
  109. Function FSearch(path: pathstr; dirlist: string): pathstr;
  110. Function FExpand(const path: pathstr): pathstr;
  111. Procedure FSplit(path: pathstr; var dir: dirstr; var name: namestr; var ext: extstr);
  112. {Environment}
  113. Function EnvCount: longint;
  114. Function EnvStr(index: integer): string;
  115. Function GetEnv (envvar: string): string;
  116. {Do Nothing Functions, no Linux version}
  117. Procedure Intr(intno: byte; var regs: registers);
  118. Procedure MSDos(var regs: registers);
  119. Procedure SwapVectors;
  120. Procedure GetIntVec(intno: byte; var vector: pointer);
  121. Procedure SetIntVec(intno: byte; vector: pointer);
  122. Procedure Keep(exitcode: word);
  123. Procedure SetFAttr(var f; attr: word);
  124. Procedure SetFTime(var f; time: longint);
  125. Procedure GetCBreak(var breakvalue: boolean);
  126. Procedure SetCBreak(breakvalue: boolean);
  127. Procedure GetVerify(var verify: boolean);
  128. Procedure SetVerify(verify: boolean);
  129. Implementation
  130. Uses
  131. Strings,Unix;
  132. {******************************************************************************
  133. --- Link C Lib if set ---
  134. ******************************************************************************}
  135. type
  136. RtlInfoType = Record
  137. FMode,
  138. FInode,
  139. FUid,
  140. FGid,
  141. FSize,
  142. FMTime : LongInt;
  143. End;
  144. {******************************************************************************
  145. --- Info / Date / Time ---
  146. ******************************************************************************}
  147. Const
  148. {Date Calculation}
  149. C1970 = 2440588;
  150. D0 = 1461;
  151. D1 = 146097;
  152. D2 = 1721119;
  153. type
  154. GTRec = packed Record
  155. Year,
  156. Month,
  157. MDay,
  158. WDay,
  159. Hour,
  160. Minute,
  161. Second : Word;
  162. End;
  163. Function DosVersion:Word;
  164. Var
  165. Buffer : Array[0..255] of Char;
  166. Tmp2,
  167. TmpStr : String[40];
  168. TmpPos,
  169. SubRel,
  170. Rel : LongInt;
  171. info : utsname;
  172. Begin
  173. {$IFNDEF BSD}
  174. UName(info);
  175. Move(info.release,buffer[0],40);
  176. TmpStr:=StrPas(Buffer);
  177. {$ELSE}
  178. TmpStr:='FreeBSD doesn''t support UName';
  179. {$ENDIF}
  180. SubRel:=0;
  181. TmpPos:=Pos('.',TmpStr);
  182. if TmpPos>0 then
  183. begin
  184. Tmp2:=Copy(TmpStr,TmpPos+1,40);
  185. Delete(TmpStr,TmpPos,40);
  186. end;
  187. TmpPos:=Pos('.',Tmp2);
  188. if TmpPos>0 then
  189. Delete(Tmp2,TmpPos,40);
  190. Val(TmpStr,Rel);
  191. Val(Tmp2,SubRel);
  192. DosVersion:=Rel+(SubRel shl 8);
  193. End;
  194. function WeekDay (y,m,d:longint):longint;
  195. {
  196. Calculates th day of the week. returns -1 on error
  197. }
  198. var
  199. u,v : longint;
  200. begin
  201. if (m<1) or (m>12) or (y<1600) or (y>4000) or
  202. (d<1) or (d>30+((m+ord(m>7)) and 1)-ord(m=2)) or
  203. ((m*d=58) and (((y mod 4>0) or (y mod 100=0)) and (y mod 400>0))) then
  204. WeekDay:=-1
  205. else
  206. begin
  207. u:=m;
  208. v:=y;
  209. if m<3 then
  210. begin
  211. inc(u,12);
  212. dec(v);
  213. end;
  214. WeekDay:=(d+2*u+((3*(u+1)) div 5)+v+(v div 4)-(v div 100)+(v div 400)+1) mod 7;
  215. end;
  216. end;
  217. Procedure GetDate(Var Year, Month, MDay, WDay: Word);
  218. Begin
  219. Unix.GetDate(Year,Month,MDay);
  220. Wday:=weekday(Year,Month,MDay);
  221. end;
  222. Procedure SetDate(Year, Month, Day: Word);
  223. Begin
  224. Unix.SetDate ( Year, Month, Day );
  225. End;
  226. Procedure GetTime(Var Hour, Minute, Second, Sec100: Word);
  227. Begin
  228. Unix.GetTime(Hour,Minute,Second,Sec100);
  229. end;
  230. Procedure SetTime(Hour, Minute, Second, Sec100: Word);
  231. Begin
  232. Unix.SetTime ( Hour, Minute, Second );
  233. End;
  234. Procedure packtime(var t : datetime;var p : longint);
  235. Begin
  236. 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);
  237. End;
  238. Procedure unpacktime(p : longint;var t : datetime);
  239. Begin
  240. t.sec:=(p and 31) shl 1;
  241. t.min:=(p shr 5) and 63;
  242. t.hour:=(p shr 11) and 31;
  243. t.day:=(p shr 16) and 31;
  244. t.month:=(p shr 21) and 15;
  245. t.year:=(p shr 25)+1980;
  246. End;
  247. Procedure UnixDateToDt(SecsPast: LongInt; Var Dt: DateTime);
  248. Begin
  249. EpochToLocal(SecsPast,dt.Year,dt.Month,dt.Day,dt.Hour,dt.Min,dt.Sec);
  250. End;
  251. Function DTToUnixDate(DT: DateTime): LongInt;
  252. Begin
  253. DTToUnixDate:=LocalToEpoch(dt.Year,dt.Month,dt.Day,dt.Hour,dt.Min,dt.Sec);
  254. End;
  255. {******************************************************************************
  256. --- Exec ---
  257. ******************************************************************************}
  258. var
  259. LastDosExitCode: word;
  260. Procedure Exec (Const Path: PathStr; Const ComLine: ComStr);
  261. var
  262. pid : longint;
  263. // The Error-Checking in the previous Version failed, since halt($7F) gives an WaitPid-status of $7F00
  264. Begin
  265. LastDosExitCode:=0;
  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. ExitProcess(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. LastDosExitCode:=WaitProcess(pid); // WaitPid and result-convert
  282. if (LastDosExitCode>=0) and (LastDosExitCode<>127) then
  283. DosError:=0
  284. else
  285. DosError:=8; // perhaps one time give an better error
  286. End;
  287. Function DosExitCode: Word;
  288. Begin
  289. DosExitCode:=LastDosExitCode;
  290. End;
  291. {******************************************************************************
  292. --- Disk ---
  293. ******************************************************************************}
  294. {
  295. The Diskfree and Disksize functions need a file on the specified drive, since this
  296. is required for the statfs system call.
  297. These filenames are set in drivestr[0..26], and have been preset to :
  298. 0 - '.' (default drive - hence current dir is ok.)
  299. 1 - '/fd0/.' (floppy drive 1 - should be adapted to local system )
  300. 2 - '/fd1/.' (floppy drive 2 - should be adapted to local system )
  301. 3 - '/' (C: equivalent of dos is the root partition)
  302. 4..26 (can be set by you're own applications)
  303. ! Use AddDisk() to Add new drives !
  304. They both return -1 when a failure occurs.
  305. }
  306. Const
  307. FixDriveStr : array[0..3] of pchar=(
  308. '.',
  309. '/fd0/.',
  310. '/fd1/.',
  311. '/.'
  312. );
  313. const
  314. Drives : byte = 4;
  315. var
  316. DriveStr : array[4..26] of pchar;
  317. Procedure AddDisk(const path:string);
  318. begin
  319. if not (DriveStr[Drives]=nil) then
  320. FreeMem(DriveStr[Drives],StrLen(DriveStr[Drives])+1);
  321. GetMem(DriveStr[Drives],length(Path)+1);
  322. StrPCopy(DriveStr[Drives],path);
  323. inc(Drives);
  324. if Drives>26 then
  325. Drives:=4;
  326. end;
  327. Function DiskFree(Drive: Byte): int64;
  328. var
  329. fs : tstatfs;
  330. Begin
  331. if ((Drive<4) and (not (fixdrivestr[Drive]=nil)) and StatFS(StrPas(fixdrivestr[drive]),fs)) or
  332. ((not (drivestr[Drive]=nil)) and StatFS(StrPas(drivestr[drive]),fs)) then
  333. Diskfree:=int64(fs.bavail)*int64(fs.bsize)
  334. else
  335. Diskfree:=-1;
  336. End;
  337. Function DiskSize(Drive: Byte): int64;
  338. var
  339. fs : tstatfs;
  340. Begin
  341. if ((Drive<4) and (not (fixdrivestr[Drive]=nil)) and StatFS(StrPas(fixdrivestr[drive]),fs)) or
  342. ((not (drivestr[Drive]=nil)) and StatFS(StrPas(drivestr[drive]),fs)) then
  343. DiskSize:=int64(fs.blocks)*int64(fs.bsize)
  344. else
  345. DiskSize:=-1;
  346. End;
  347. {******************************************************************************
  348. --- Findfirst FindNext ---
  349. ******************************************************************************}
  350. Const
  351. RtlFindSize = 15;
  352. Type
  353. RtlFindRecType = Record
  354. SearchNum,
  355. DirPtr,
  356. LastUsed : LongInt;
  357. End;
  358. Var
  359. RtlFindRecs : Array[1..RtlFindSize] of RtlFindRecType;
  360. CurrSearchNum : LongInt;
  361. Procedure FindClose(Var f: SearchRec);
  362. {
  363. Closes dirptr if it is open
  364. }
  365. Var
  366. i : longint;
  367. Begin
  368. if f.SearchType=0 then
  369. begin
  370. i:=1;
  371. repeat
  372. if (RtlFindRecs[i].SearchNum=f.SearchNum) then
  373. break;
  374. inc(i);
  375. until (i>RtlFindSize);
  376. If i<=RtlFindSize Then
  377. Begin
  378. RtlFindRecs[i].SearchNum:=0;
  379. if f.dirptr>0 then
  380. closedir(pdir(f.dirptr));
  381. End;
  382. end;
  383. f.dirptr:=0;
  384. End;
  385. Function FindGetFileInfo(const s:string;var f:SearchRec):boolean;
  386. var
  387. DT : DateTime;
  388. Info : RtlInfoType;
  389. st : stat;
  390. begin
  391. FindGetFileInfo:=false;
  392. if not Fstat(s,st) then
  393. exit;
  394. info.FSize:=st.Size;
  395. info.FMTime:=st.mtime;
  396. if (st.mode and STAT_IFMT)=STAT_IFDIR then
  397. info.fmode:=$10
  398. else
  399. info.fmode:=$20;
  400. if (st.mode and STAT_IWUSR)=0 then
  401. info.fmode:=info.fmode or 1;
  402. If ((Info.FMode and Not(f.searchattr))=0) Then
  403. Begin
  404. f.Name:=Copy(s,f.NamePos+1,255);
  405. f.Attr:=Info.FMode;
  406. f.Size:=Info.FSize;
  407. UnixDateToDT(Info.FMTime, DT);
  408. PackTime(DT,f.Time);
  409. FindGetFileInfo:=true;
  410. End;
  411. end;
  412. Function FindLastUsed: Longint;
  413. {
  414. Find unused or least recently used dirpointer slot in findrecs array
  415. }
  416. Var
  417. BestMatch,i : Longint;
  418. Found : Boolean;
  419. Begin
  420. BestMatch:=1;
  421. i:=1;
  422. Found:=False;
  423. While (i <= RtlFindSize) And (Not Found) Do
  424. Begin
  425. If (RtlFindRecs[i].SearchNum = 0) Then
  426. Begin
  427. BestMatch := i;
  428. Found := True;
  429. End
  430. Else
  431. Begin
  432. If RtlFindRecs[i].LastUsed > RtlFindRecs[BestMatch].LastUsed Then
  433. BestMatch := i;
  434. End;
  435. Inc(i);
  436. End;
  437. FindLastUsed := BestMatch;
  438. End;
  439. Procedure FindNext(Var f: SearchRec);
  440. {
  441. re-opens dir if not already in array and calls FindWorkProc
  442. }
  443. Var
  444. DirName : Array[0..256] of Char;
  445. i,
  446. ArrayPos : Longint;
  447. FName,
  448. SName : string;
  449. Found,
  450. Finished : boolean;
  451. p : PDirEnt;
  452. Begin
  453. If f.SearchType=0 Then
  454. Begin
  455. ArrayPos:=0;
  456. For i:=1 to RtlFindSize Do
  457. Begin
  458. If RtlFindRecs[i].SearchNum = f.SearchNum Then
  459. ArrayPos:=i;
  460. Inc(RtlFindRecs[i].LastUsed);
  461. End;
  462. If ArrayPos=0 Then
  463. Begin
  464. If f.NamePos = 0 Then
  465. Begin
  466. DirName[0] := '.';
  467. DirName[1] := '/';
  468. DirName[2] := #0;
  469. End
  470. Else
  471. Begin
  472. Move(f.SearchSpec[1], DirName[0], f.NamePos);
  473. DirName[f.NamePos] := #0;
  474. End;
  475. f.DirPtr := longint(opendir(@(DirName)));
  476. If f.DirPtr > 0 Then
  477. begin
  478. ArrayPos:=FindLastUsed;
  479. If RtlFindRecs[ArrayPos].SearchNum > 0 Then
  480. CloseDir(pdir(rtlfindrecs[arraypos].dirptr));
  481. RtlFindRecs[ArrayPos].SearchNum := f.SearchNum;
  482. RtlFindRecs[ArrayPos].DirPtr := f.DirPtr;
  483. if f.searchpos>0 then
  484. seekdir(pdir(f.dirptr), f.searchpos);
  485. end;
  486. End;
  487. if ArrayPos>0 then
  488. RtlFindRecs[ArrayPos].LastUsed:=0;
  489. end;
  490. {Main loop}
  491. SName:=Copy(f.SearchSpec,f.NamePos+1,255);
  492. Found:=False;
  493. Finished:=(f.dirptr=0);
  494. While Not Finished Do
  495. Begin
  496. p:=readdir(pdir(f.dirptr));
  497. if p=nil then
  498. FName:=''
  499. else
  500. FName:=Strpas(@p^.name);
  501. If FName='' Then
  502. Finished:=True
  503. Else
  504. Begin
  505. If FNMatch(SName,FName) Then
  506. Begin
  507. Found:=FindGetFileInfo(Copy(f.SearchSpec,1,f.NamePos)+FName,f);
  508. if Found then
  509. Finished:=true;
  510. End;
  511. End;
  512. End;
  513. {Shutdown}
  514. If Found Then
  515. Begin
  516. f.searchpos:=telldir(pdir(f.dirptr));
  517. DosError:=0;
  518. End
  519. Else
  520. Begin
  521. FindClose(f);
  522. DosError:=18;
  523. End;
  524. End;
  525. Procedure FindFirst(Const Path: PathStr; Attr: Word; Var f: SearchRec);
  526. {
  527. opens dir and calls FindWorkProc
  528. }
  529. Begin
  530. if Path='' then
  531. begin
  532. DosError:=3;
  533. exit;
  534. end;
  535. {Create Info}
  536. f.SearchSpec := Path;
  537. f.SearchAttr := Attr;
  538. f.SearchPos:=0;
  539. f.NamePos := Length(f.SearchSpec);
  540. while (f.NamePos>0) and (f.SearchSpec[f.NamePos]<>'/') do
  541. dec(f.NamePos);
  542. {Wildcards?}
  543. if (Pos('?',Path)=0) and (Pos('*',Path)=0) then
  544. begin
  545. if FindGetFileInfo(Path,f) then
  546. DosError:=0
  547. else
  548. begin
  549. if ErrNo=Sys_ENOENT then
  550. DosError:=3
  551. else
  552. DosError:=18;
  553. end;
  554. f.DirPtr:=0;
  555. f.SearchType:=1;
  556. f.searchnum:=-1;
  557. end
  558. else
  559. {Find Entry}
  560. begin
  561. Inc(CurrSearchNum);
  562. f.SearchNum:=CurrSearchNum;
  563. f.SearchType:=0;
  564. FindNext(f);
  565. end;
  566. End;
  567. {******************************************************************************
  568. --- File ---
  569. ******************************************************************************}
  570. Procedure FSplit(Path: PathStr; Var Dir: DirStr; Var Name: NameStr;Var Ext: ExtStr);
  571. Begin
  572. Unix.FSplit(Path,Dir,Name,Ext);
  573. End;
  574. Function FExpand(Const Path: PathStr): PathStr;
  575. Begin
  576. FExpand:=Unix.FExpand(Path);
  577. End;
  578. Function FSearch(path : pathstr;dirlist : string) : pathstr;
  579. Var
  580. info:stat;
  581. Begin
  582. if (length(Path)>0) and (path[1]='/') and FStat(path,info) then
  583. FSearch:=path
  584. else
  585. FSearch:=Unix.FSearch(path,dirlist);
  586. End;
  587. Procedure GetFAttr(var f; var attr : word);
  588. Var
  589. info : stat;
  590. LinAttr : longint;
  591. Begin
  592. DosError:=0;
  593. if not FStat(strpas(@textrec(f).name),info) then
  594. begin
  595. Attr:=0;
  596. DosError:=3;
  597. exit;
  598. end
  599. else
  600. LinAttr:=Info.Mode;
  601. if S_ISDIR(LinAttr) then
  602. Attr:=$10
  603. else
  604. Attr:=$20;
  605. if not Access(strpas(@textrec(f).name),W_OK) then
  606. Attr:=Attr or $1;
  607. if (not S_ISDIR(LinAttr)) and (filerec(f).name[0]='.') then
  608. Attr:=Attr or $2;
  609. end;
  610. Procedure getftime (var f; var time : longint);
  611. Var
  612. Info: stat;
  613. DT: DateTime;
  614. Begin
  615. doserror:=0;
  616. if not fstat(filerec(f).handle,info) then
  617. begin
  618. Time:=0;
  619. doserror:=3;
  620. exit
  621. end
  622. else
  623. UnixDateToDT(Info.mTime,DT);
  624. PackTime(DT,Time);
  625. End;
  626. {******************************************************************************
  627. --- Environment ---
  628. ******************************************************************************}
  629. Function EnvCount: Longint;
  630. var
  631. envcnt : longint;
  632. p : ppchar;
  633. Begin
  634. envcnt:=0;
  635. p:=envp; {defined in syslinux}
  636. while (p^<>nil) do
  637. begin
  638. inc(envcnt);
  639. inc(p);
  640. end;
  641. EnvCount := envcnt
  642. End;
  643. Function EnvStr(Index: Integer): String;
  644. Var
  645. i : longint;
  646. p : ppchar;
  647. Begin
  648. p:=envp; {defined in syslinux}
  649. i:=1;
  650. while (i<Index) and (p^<>nil) do
  651. begin
  652. inc(i);
  653. inc(p);
  654. end;
  655. if p=nil then
  656. envstr:=''
  657. else
  658. envstr:=strpas(p^)
  659. End;
  660. Function GetEnv(EnvVar: String): String;
  661. var
  662. p : pchar;
  663. Begin
  664. p:=Unix.GetEnv(EnvVar);
  665. if p=nil then
  666. GetEnv:=''
  667. else
  668. GetEnv:=StrPas(p);
  669. End;
  670. {******************************************************************************
  671. --- Do Nothing Procedures/Functions ---
  672. ******************************************************************************}
  673. Procedure Intr (intno: byte; var regs: registers);
  674. Begin
  675. {! No Linux equivalent !}
  676. End;
  677. Procedure msdos(var regs : registers);
  678. Begin
  679. {! No Linux equivalent !}
  680. End;
  681. Procedure getintvec(intno : byte;var vector : pointer);
  682. Begin
  683. {! No Linux equivalent !}
  684. End;
  685. Procedure setintvec(intno : byte;vector : pointer);
  686. Begin
  687. {! No Linux equivalent !}
  688. End;
  689. Procedure SwapVectors;
  690. Begin
  691. {! No Linux equivalent !}
  692. End;
  693. Procedure keep(exitcode : word);
  694. Begin
  695. {! No Linux equivalent !}
  696. End;
  697. Procedure setftime(var f; time : longint);
  698. Begin
  699. {! No Linux equivalent !}
  700. End;
  701. Procedure setfattr (var f;attr : word);
  702. Begin
  703. {! No Linux equivalent !}
  704. End;
  705. Procedure GetCBreak(Var BreakValue: Boolean);
  706. Begin
  707. {! No Linux equivalent !}
  708. breakvalue:=true
  709. End;
  710. Procedure SetCBreak(BreakValue: Boolean);
  711. Begin
  712. {! No Linux equivalent !}
  713. End;
  714. Procedure GetVerify(Var Verify: Boolean);
  715. Begin
  716. {! No Linux equivalent !}
  717. Verify:=true;
  718. End;
  719. Procedure SetVerify(Verify: Boolean);
  720. Begin
  721. {! No Linux equivalent !}
  722. End;
  723. {******************************************************************************
  724. --- Initialization ---
  725. ******************************************************************************}
  726. End.
  727. {
  728. $Log$
  729. Revision 1.8 2001-07-12 12:42:39 marco
  730. * Fixes to the FreeBSD compability of the datetime patches
  731. Revision 1.7 2001/07/12 07:20:05 michael
  732. + Added setdate/time/datetime functions
  733. Revision 1.6 2001/06/03 20:19:09 peter
  734. * FSStat to StatFS
  735. * StatFS structure to TStatFS
  736. Revision 1.5 2001/06/02 00:31:30 peter
  737. * merge unix updates from the 1.0 branch, mostly related to the
  738. solaris target
  739. Revision 1.4 2001/05/06 14:23:21 peter
  740. * fixed adddisk
  741. Revision 1.3 2001/01/21 20:21:40 marco
  742. * Rename fest II. Rtl OK
  743. Revision 1.2 2000/09/18 13:14:50 marco
  744. * Global Linux +bsd to (rtl/freebsd rtl/unix rtl/linux structure)
  745. Revision 1.3 2000/07/14 10:33:10 michael
  746. + Conditionals fixed
  747. Revision 1.2 2000/07/13 11:33:48 michael
  748. + removed logs
  749. }