dos.pp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944
  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 =
  44. {$ifndef ARM}
  45. packed
  46. {$endif ARM}
  47. Record
  48. {Fill : array[1..21] of byte; Fill replaced with below}
  49. SearchNum : LongInt; {to track which search this is}
  50. SearchPos : LongInt; {directory position}
  51. DirPtr : LongInt; {directory pointer for reading directory}
  52. SearchType : Byte; {0=normal, 1=open will close, 2=only 1 file}
  53. SearchAttr : Byte; {attribute we are searching for}
  54. Fill : Array[1..07] of Byte; {future use}
  55. {End of fill}
  56. Attr : Byte; {attribute of found file}
  57. Time : LongInt; {last modify date of found file}
  58. Size : LongInt; {file size of found file}
  59. Reserved : Word; {future use}
  60. Name : String[FileNameLen]; {name of found file}
  61. SearchSpec : String[FileNameLen]; {search pattern}
  62. NamePos : Word; {end of path, start of name position}
  63. End;
  64. {
  65. filerec.inc contains the definition of the filerec.
  66. textrec.inc contains the definition of the textrec.
  67. It is in a separate file to make it available in other units without
  68. having to use the DOS unit for it.
  69. }
  70. {$i filerec.inc}
  71. {$i textrec.inc}
  72. {$ifdef cpui386}
  73. Registers = packed record
  74. case i : integer of
  75. 0 : (ax,f1,bx,f2,cx,f3,dx,f4,bp,f5,si,f51,di,f6,ds,f7,es,f8,flags,fs,gs : word);
  76. 1 : (al,ah,f9,f10,bl,bh,f11,f12,cl,ch,f13,f14,dl,dh : byte);
  77. 2 : (eax, ebx, ecx, edx, ebp, esi, edi : longint);
  78. End;
  79. {$endif cpui386}
  80. DateTime = packed record
  81. Year,
  82. Month,
  83. Day,
  84. Hour,
  85. Min,
  86. Sec : word;
  87. End;
  88. Var
  89. DosError : integer;
  90. {Utils}
  91. function weekday(y,m,d : longint) : longint;
  92. Procedure UnixDateToDt(SecsPast: LongInt; Var Dt: DateTime);
  93. Function DTToUnixDate(DT: DateTime): LongInt;
  94. {Info/Date/Time}
  95. Function DosVersion: Word;
  96. Procedure GetDate(var year, month, mday, wday: word);
  97. Procedure GetTime(var hour, minute, second, sec100: word);
  98. procedure SetDate(year,month,day: word);
  99. Procedure SetTime(hour,minute,second,sec100: word);
  100. Procedure UnpackTime(p: longint; var t: datetime);
  101. Procedure PackTime(var t: datetime; var p: longint);
  102. {Exec}
  103. Procedure Exec(const path: pathstr; const comline: comstr);
  104. Function DosExitCode: word;
  105. {Disk}
  106. Procedure AddDisk(const path:string);
  107. Function DiskFree(drive: byte) : int64;
  108. Function DiskSize(drive: byte) : int64;
  109. Procedure FindFirst(const path: pathstr; attr: word; var f: searchRec);
  110. Procedure FindNext(var f: searchRec);
  111. Procedure FindClose(Var f: SearchRec);
  112. {File}
  113. Procedure GetFAttr(var f; var attr: word);
  114. Procedure GetFTime(var f; var time: longint);
  115. Function FSearch(path: pathstr; dirlist: string): pathstr;
  116. Function FExpand(const path: pathstr): pathstr;
  117. Procedure FSplit(path: pathstr; var dir: dirstr; var name: namestr; var ext: extstr);
  118. {Environment}
  119. Function EnvCount: longint;
  120. Function EnvStr(index: integer): string;
  121. Function GetEnv (envvar: string): string;
  122. {Do Nothing Functions, no Linux version}
  123. {$ifdef cpui386}
  124. Procedure Intr(intno: byte; var regs: registers);
  125. Procedure MSDos(var regs: registers);
  126. {$endif cpui386}
  127. Procedure SwapVectors;
  128. Procedure GetIntVec(intno: byte; var vector: pointer);
  129. Procedure SetIntVec(intno: byte; vector: pointer);
  130. Procedure Keep(exitcode: Word);
  131. Procedure SetFAttr(var f; attr: word);
  132. Procedure SetFTime(var f; time: longint);
  133. Procedure GetCBreak(var breakvalue: boolean);
  134. Procedure SetCBreak(breakvalue: boolean);
  135. Procedure GetVerify(var verify: boolean);
  136. Procedure SetVerify(verify: boolean);
  137. Implementation
  138. Uses
  139. Strings,UnixUtil,Unix,BaseUnix;
  140. {******************************************************************************
  141. --- Link C Lib if set ---
  142. ******************************************************************************}
  143. type
  144. RtlInfoType = Record
  145. FMode,
  146. FInode,
  147. FUid,
  148. FGid,
  149. FSize,
  150. FMTime : LongInt;
  151. End;
  152. {******************************************************************************
  153. --- Info / Date / Time ---
  154. ******************************************************************************}
  155. Const
  156. {Date Calculation}
  157. C1970 = 2440588;
  158. D0 = 1461;
  159. D1 = 146097;
  160. D2 = 1721119;
  161. type
  162. GTRec = packed Record
  163. Year,
  164. Month,
  165. MDay,
  166. WDay,
  167. Hour,
  168. Minute,
  169. Second : Word;
  170. End;
  171. Function DosVersion:Word;
  172. Var
  173. Buffer : Array[0..255] of Char;
  174. Tmp2,
  175. TmpStr : String[40];
  176. TmpPos,
  177. SubRel,
  178. Rel : LongInt;
  179. info : utsname;
  180. Begin
  181. FPUName(info);
  182. Move(info.release,buffer[0],40);
  183. TmpStr:=StrPas(Buffer);
  184. SubRel:=0;
  185. TmpPos:=Pos('.',TmpStr);
  186. if TmpPos>0 then
  187. begin
  188. Tmp2:=Copy(TmpStr,TmpPos+1,40);
  189. Delete(TmpStr,TmpPos,40);
  190. end;
  191. TmpPos:=Pos('.',Tmp2);
  192. if TmpPos>0 then
  193. Delete(Tmp2,TmpPos,40);
  194. Val(TmpStr,Rel);
  195. Val(Tmp2,SubRel);
  196. DosVersion:=Rel+(SubRel shl 8);
  197. End;
  198. function WeekDay (y,m,d:longint):longint;
  199. {
  200. Calculates th day of the week. returns -1 on error
  201. }
  202. var
  203. u,v : longint;
  204. begin
  205. if (m<1) or (m>12) or (y<1600) or (y>4000) or
  206. (d<1) or (d>30+((m+ord(m>7)) and 1)-ord(m=2)) or
  207. ((m*d=58) and (((y mod 4>0) or (y mod 100=0)) and (y mod 400>0))) then
  208. WeekDay:=-1
  209. else
  210. begin
  211. u:=m;
  212. v:=y;
  213. if m<3 then
  214. begin
  215. inc(u,12);
  216. dec(v);
  217. end;
  218. WeekDay:=(d+2*u+((3*(u+1)) div 5)+v+(v div 4)-(v div 100)+(v div 400)+1) mod 7;
  219. end;
  220. end;
  221. Procedure GetDate(Var Year, Month, MDay, WDay: Word);
  222. Begin
  223. Unix.GetDate(Year,Month,MDay);
  224. Wday:=weekday(Year,Month,MDay);
  225. end;
  226. Procedure SetDate(Year, Month, Day: Word);
  227. Begin
  228. Unix.SetDate ( Year, Month, Day );
  229. End;
  230. Procedure GetTime(Var Hour, Minute, Second, Sec100: Word);
  231. Begin
  232. Unix.GetTime(Hour,Minute,Second,Sec100);
  233. end;
  234. Procedure SetTime(Hour, Minute, Second, Sec100: Word);
  235. Begin
  236. Unix.SetTime ( Hour, Minute, Second );
  237. End;
  238. Procedure packtime(var t : datetime;var p : longint);
  239. Begin
  240. 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);
  241. End;
  242. Procedure unpacktime(p : longint;var t : datetime);
  243. Begin
  244. t.sec:=(p and 31) shl 1;
  245. t.min:=(p shr 5) and 63;
  246. t.hour:=(p shr 11) and 31;
  247. t.day:=(p shr 16) and 31;
  248. t.month:=(p shr 21) and 15;
  249. t.year:=(p shr 25)+1980;
  250. End;
  251. Procedure UnixDateToDt(SecsPast: LongInt; Var Dt: DateTime);
  252. Begin
  253. EpochToLocal(SecsPast,dt.Year,dt.Month,dt.Day,dt.Hour,dt.Min,dt.Sec);
  254. End;
  255. Function DTToUnixDate(DT: DateTime): LongInt;
  256. Begin
  257. DTToUnixDate:=LocalToEpoch(dt.Year,dt.Month,dt.Day,dt.Hour,dt.Min,dt.Sec);
  258. End;
  259. {******************************************************************************
  260. --- Exec ---
  261. ******************************************************************************}
  262. var
  263. LastDosExitCode: word;
  264. Procedure Exec (Const Path: PathStr; Const ComLine: ComStr);
  265. var
  266. pid : longint;
  267. // The Error-Checking in the previous Version failed, since halt($7F) gives an WaitPid-status of $7F00
  268. Begin
  269. LastDosExitCode:=0;
  270. pid:=fpFork;
  271. if pid=0 then
  272. begin
  273. {The child does the actual exec, and then exits}
  274. if ComLine='' then
  275. Execl(Path)
  276. else
  277. Execl(Path+' '+ComLine);
  278. {If the execve fails, we return an exitvalue of 127, to let it be known}
  279. fpExit(127);
  280. end
  281. else
  282. if pid=-1 then {Fork failed}
  283. begin
  284. DosError:=8;
  285. exit
  286. end;
  287. {We're in the parent, let's wait.}
  288. LastDosExitCode:=WaitProcess(pid); // WaitPid and result-convert
  289. if (LastDosExitCode>=0) and (LastDosExitCode<>127) then
  290. DosError:=0
  291. else
  292. DosError:=8; // perhaps one time give an better error
  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. const
  321. Drives : byte = 4;
  322. var
  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. Function DiskFree(Drive: Byte): int64;
  335. var
  336. fs : tstatfs;
  337. Begin
  338. if ((Drive<4) and (not (fixdrivestr[Drive]=nil)) and (StatFS(StrPas(fixdrivestr[drive]),fs)<>-1)) or
  339. ((not (drivestr[Drive]=nil)) and (StatFS(StrPas(drivestr[drive]),fs)<>-1)) 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 : tstatfs;
  347. Begin
  348. if ((Drive<4) and (not (fixdrivestr[Drive]=nil)) and (StatFS(StrPas(fixdrivestr[drive]),fs)<>-1)) or
  349. ((not (drivestr[Drive]=nil)) and (StatFS(StrPas(drivestr[drive]),fs)<>-1)) then
  350. DiskSize:=int64(fs.blocks)*int64(fs.bsize)
  351. else
  352. DiskSize:=-1;
  353. End;
  354. {******************************************************************************
  355. --- Findfirst FindNext ---
  356. ******************************************************************************}
  357. Const
  358. RtlFindSize = 15;
  359. Type
  360. RtlFindRecType = Record
  361. SearchNum,
  362. DirPtr,
  363. LastUsed : LongInt;
  364. End;
  365. Var
  366. RtlFindRecs : Array[1..RtlFindSize] of RtlFindRecType;
  367. CurrSearchNum : LongInt;
  368. Procedure FindClose(Var f: SearchRec);
  369. {
  370. Closes dirptr if it is open
  371. }
  372. Var
  373. i : longint;
  374. Begin
  375. if f.SearchType=0 then
  376. begin
  377. i:=1;
  378. repeat
  379. if (RtlFindRecs[i].SearchNum=f.SearchNum) then
  380. break;
  381. inc(i);
  382. until (i>RtlFindSize);
  383. If i<=RtlFindSize Then
  384. Begin
  385. RtlFindRecs[i].SearchNum:=0;
  386. if f.dirptr<>0 then
  387. fpclosedir(pdir(f.dirptr)^);
  388. End;
  389. end;
  390. f.dirptr:=0;
  391. End;
  392. Function FindGetFileInfo(const s:string;var f:SearchRec):boolean;
  393. var
  394. DT : DateTime;
  395. Info : RtlInfoType;
  396. st : baseunix.stat;
  397. begin
  398. FindGetFileInfo:=false;
  399. if not fpstat(s,st)>=0 then
  400. exit;
  401. info.FSize:=st.st_Size;
  402. info.FMTime:=st.st_mtime;
  403. if (st.st_mode and STAT_IFMT)=STAT_IFDIR then
  404. info.fmode:=$10
  405. else
  406. info.fmode:=$0;
  407. if (st.st_mode and STAT_IWUSR)=0 then
  408. info.fmode:=info.fmode or 1;
  409. if s[f.NamePos+1]='.' then
  410. info.fmode:=info.fmode or $2;
  411. If ((Info.FMode and Not(f.searchattr))=0) Then
  412. Begin
  413. f.Name:=Copy(s,f.NamePos+1,255);
  414. f.Attr:=Info.FMode;
  415. f.Size:=Info.FSize;
  416. UnixDateToDT(Info.FMTime, DT);
  417. PackTime(DT,f.Time);
  418. FindGetFileInfo:=true;
  419. End;
  420. end;
  421. Function FindLastUsed: Longint;
  422. {
  423. Find unused or least recently used dirpointer slot in findrecs array
  424. }
  425. Var
  426. BestMatch,i : Longint;
  427. Found : Boolean;
  428. Begin
  429. BestMatch:=1;
  430. i:=1;
  431. Found:=False;
  432. While (i <= RtlFindSize) And (Not Found) Do
  433. Begin
  434. If (RtlFindRecs[i].SearchNum = 0) Then
  435. Begin
  436. BestMatch := i;
  437. Found := True;
  438. End
  439. Else
  440. Begin
  441. If RtlFindRecs[i].LastUsed > RtlFindRecs[BestMatch].LastUsed Then
  442. BestMatch := i;
  443. End;
  444. Inc(i);
  445. End;
  446. FindLastUsed := BestMatch;
  447. End;
  448. Procedure FindNext(Var f: SearchRec);
  449. {
  450. re-opens dir if not already in array and calls FindWorkProc
  451. }
  452. Var
  453. DirName : Array[0..256] of Char;
  454. i,
  455. ArrayPos : Longint;
  456. FName,
  457. SName : string;
  458. Found,
  459. Finished : boolean;
  460. p : PDirEnt;
  461. Begin
  462. If f.SearchType=0 Then
  463. Begin
  464. ArrayPos:=0;
  465. For i:=1 to RtlFindSize Do
  466. Begin
  467. If RtlFindRecs[i].SearchNum = f.SearchNum Then
  468. ArrayPos:=i;
  469. Inc(RtlFindRecs[i].LastUsed);
  470. End;
  471. If ArrayPos=0 Then
  472. Begin
  473. If f.NamePos = 0 Then
  474. Begin
  475. DirName[0] := '.';
  476. DirName[1] := '/';
  477. DirName[2] := #0;
  478. End
  479. Else
  480. Begin
  481. Move(f.SearchSpec[1], DirName[0], f.NamePos);
  482. DirName[f.NamePos] := #0;
  483. End;
  484. f.DirPtr := longint(fpopendir(@(DirName)));
  485. If f.DirPtr <> 0 Then
  486. begin
  487. ArrayPos:=FindLastUsed;
  488. If RtlFindRecs[ArrayPos].SearchNum > 0 Then
  489. FpCloseDir((pdir(rtlfindrecs[arraypos].dirptr)^));
  490. RtlFindRecs[ArrayPos].SearchNum := f.SearchNum;
  491. RtlFindRecs[ArrayPos].DirPtr := f.DirPtr;
  492. if f.searchpos>0 then
  493. seekdir(pdir(f.dirptr), f.searchpos);
  494. end;
  495. End;
  496. if ArrayPos>0 then
  497. RtlFindRecs[ArrayPos].LastUsed:=0;
  498. end;
  499. {Main loop}
  500. SName:=Copy(f.SearchSpec,f.NamePos+1,255);
  501. Found:=False;
  502. Finished:=(f.dirptr=0);
  503. While Not Finished Do
  504. Begin
  505. p:=fpreaddir(pdir(f.dirptr)^);
  506. if p=nil then
  507. FName:=''
  508. else
  509. FName:=Strpas(@p^.d_name);
  510. If FName='' Then
  511. Finished:=True
  512. Else
  513. Begin
  514. If FNMatch(SName,FName) Then
  515. Begin
  516. Found:=FindGetFileInfo(Copy(f.SearchSpec,1,f.NamePos)+FName,f);
  517. if Found then
  518. Finished:=true;
  519. End;
  520. End;
  521. End;
  522. {Shutdown}
  523. If Found Then
  524. Begin
  525. f.searchpos:=telldir(pdir(f.dirptr));
  526. DosError:=0;
  527. End
  528. Else
  529. Begin
  530. FindClose(f);
  531. DosError:=18;
  532. End;
  533. End;
  534. Procedure FindFirst(Const Path: PathStr; Attr: Word; Var f: SearchRec);
  535. {
  536. opens dir and calls FindWorkProc
  537. }
  538. Begin
  539. if Path='' then
  540. begin
  541. DosError:=3;
  542. exit;
  543. end;
  544. {Create Info}
  545. f.SearchSpec := Path;
  546. {We always also search for readonly and archive, regardless of Attr:}
  547. f.SearchAttr := Attr or archive or readonly;
  548. f.SearchPos := 0;
  549. f.NamePos := Length(f.SearchSpec);
  550. while (f.NamePos>0) and (f.SearchSpec[f.NamePos]<>'/') do
  551. dec(f.NamePos);
  552. {Wildcards?}
  553. if (Pos('?',Path)=0) and (Pos('*',Path)=0) then
  554. begin
  555. if FindGetFileInfo(Path,f) then
  556. DosError:=0
  557. else
  558. begin
  559. { According to tdos2 test it should return 18
  560. if ErrNo=Sys_ENOENT then
  561. DosError:=3
  562. else }
  563. DosError:=18;
  564. end;
  565. f.DirPtr:=0;
  566. f.SearchType:=1;
  567. f.searchnum:=-1;
  568. end
  569. else
  570. {Find Entry}
  571. begin
  572. Inc(CurrSearchNum);
  573. f.SearchNum:=CurrSearchNum;
  574. f.SearchType:=0;
  575. FindNext(f);
  576. end;
  577. End;
  578. {******************************************************************************
  579. --- File ---
  580. ******************************************************************************}
  581. Procedure FSplit(Path: PathStr; Var Dir: DirStr; Var Name: NameStr;Var Ext: ExtStr);
  582. Begin
  583. UnixUtil.FSplit(Path,Dir,Name,Ext);
  584. End;
  585. Function FExpand(Const Path: PathStr): PathStr;
  586. Begin
  587. FExpand:=Unix.FExpand(Path);
  588. End;
  589. Function FSearch(path : pathstr;dirlist : string) : pathstr;
  590. Var
  591. info : BaseUnix.stat;
  592. Begin
  593. if (length(Path)>0) and (path[1]='/') and (fpStat(path,info)>=0) then
  594. FSearch:=path
  595. else
  596. FSearch:=Unix.FSearch(path,dirlist);
  597. End;
  598. Procedure GetFAttr(var f; var attr : word);
  599. Var
  600. info : baseunix.stat;
  601. LinAttr : longint;
  602. Begin
  603. DosError:=0;
  604. if FPStat(strpas(@textrec(f).name),info)<0 then
  605. begin
  606. Attr:=0;
  607. DosError:=3;
  608. exit;
  609. end
  610. else
  611. LinAttr:=Info.st_Mode;
  612. if fpS_ISDIR(LinAttr) then
  613. Attr:=$10
  614. else
  615. Attr:=$0;
  616. if fpAccess(strpas(@textrec(f).name),W_OK)<0 then
  617. Attr:=Attr or $1;
  618. if filerec(f).name[0]='.' then
  619. Attr:=Attr or $2;
  620. end;
  621. Procedure getftime (var f; var time : longint);
  622. Var
  623. Info: baseunix.stat;
  624. DT: DateTime;
  625. Begin
  626. doserror:=0;
  627. if fpfstat(filerec(f).handle,info)<0 then
  628. begin
  629. Time:=0;
  630. doserror:=6;
  631. exit
  632. end
  633. else
  634. UnixDateToDT(Info.st_mTime,DT);
  635. PackTime(DT,Time);
  636. End;
  637. Procedure setftime(var f; time : longint);
  638. Var
  639. utim: utimbuf;
  640. DT: DateTime;
  641. path: pathstr;
  642. index: Integer;
  643. Begin
  644. doserror:=0;
  645. with utim do
  646. begin
  647. actime:=getepochtime;
  648. UnPackTime(Time,DT);
  649. modtime:=DTToUnixDate(DT);
  650. end;
  651. path := strpas(@filerec(f).name);
  652. if fputime(path,@utim)<0 then
  653. begin
  654. Time:=0;
  655. doserror:=3;
  656. end;
  657. End;
  658. {******************************************************************************
  659. --- Environment ---
  660. ******************************************************************************}
  661. Function EnvCount: Longint;
  662. var
  663. envcnt : longint;
  664. p : ppchar;
  665. Begin
  666. envcnt:=0;
  667. p:=envp; {defined in syslinux}
  668. while (p^<>nil) do
  669. begin
  670. inc(envcnt);
  671. inc(p);
  672. end;
  673. EnvCount := envcnt
  674. End;
  675. Function EnvStr(Index: Integer): String;
  676. Var
  677. i : longint;
  678. p : ppchar;
  679. Begin
  680. p:=envp; {defined in syslinux}
  681. i:=1;
  682. while (i<Index) and (p^<>nil) do
  683. begin
  684. inc(i);
  685. inc(p);
  686. end;
  687. if p=nil then
  688. envstr:=''
  689. else
  690. envstr:=strpas(p^)
  691. End;
  692. Function GetEnv(EnvVar: String): String;
  693. var
  694. p : pchar;
  695. Begin
  696. p:=BaseUnix.fpGetEnv(EnvVar);
  697. if p=nil then
  698. GetEnv:=''
  699. else
  700. GetEnv:=StrPas(p);
  701. End;
  702. {******************************************************************************
  703. --- Do Nothing Procedures/Functions ---
  704. ******************************************************************************}
  705. {$ifdef cpui386}
  706. Procedure Intr (intno: byte; var regs: registers);
  707. Begin
  708. {! No Linux equivalent !}
  709. End;
  710. Procedure msdos(var regs : registers);
  711. Begin
  712. {! No Linux equivalent !}
  713. End;
  714. {$endif cpui386}
  715. Procedure getintvec(intno : byte;var vector : pointer);
  716. Begin
  717. {! No Linux equivalent !}
  718. End;
  719. Procedure setintvec(intno : byte;vector : pointer);
  720. Begin
  721. {! No Linux equivalent !}
  722. End;
  723. Procedure SwapVectors;
  724. Begin
  725. {! No Linux equivalent !}
  726. End;
  727. Procedure keep(exitcode : word);
  728. Begin
  729. {! No Linux equivalent !}
  730. End;
  731. Procedure setfattr (var f;attr : word);
  732. Begin
  733. {! No Linux equivalent !}
  734. { Fail for setting VolumeId }
  735. if (attr and VolumeID)<>0 then
  736. doserror:=5;
  737. End;
  738. Procedure GetCBreak(Var BreakValue: Boolean);
  739. Begin
  740. {! No Linux equivalent !}
  741. breakvalue:=true
  742. End;
  743. Procedure SetCBreak(BreakValue: Boolean);
  744. Begin
  745. {! No Linux equivalent !}
  746. End;
  747. Procedure GetVerify(Var Verify: Boolean);
  748. Begin
  749. {! No Linux equivalent !}
  750. Verify:=true;
  751. End;
  752. Procedure SetVerify(Verify: Boolean);
  753. Begin
  754. {! No Linux equivalent !}
  755. End;
  756. {******************************************************************************
  757. --- Initialization ---
  758. ******************************************************************************}
  759. End.
  760. {
  761. $Log$
  762. Revision 1.23 2004-01-31 16:15:14 florian
  763. * packing of searchrec for arm fixed
  764. Revision 1.22 2003/12/29 21:15:04 jonas
  765. * fixed setftime (sorry Marco :)
  766. Revision 1.21 2003/12/03 20:17:03 olle
  767. * files are not pretended to have attr ARCHIVED anymore
  768. + FindFirst etc now also filters on attr HIDDEN
  769. * files with attr READONLY and ARCHIVE are always returned by FindFirst etc
  770. Revision 1.19 2003/10/17 22:13:30 olle
  771. * changed i386 to cpui386
  772. Revision 1.18 2003/09/27 12:51:33 peter
  773. * fpISxxx macros renamed to C compliant fpS_ISxxx
  774. Revision 1.17 2003/09/17 17:30:46 marco
  775. * Introduction of unixutil
  776. Revision 1.16 2003/09/14 20:15:01 marco
  777. * Unix reform stage two. Remove all calls from Unix that exist in Baseunix.
  778. Revision 1.15 2003/05/16 20:56:06 florian
  779. no message
  780. Revision 1.14 2003/05/14 13:51:03 florian
  781. * ifdef'd code which i386 specific
  782. Revision 1.13 2002/12/08 16:05:34 peter
  783. * small error code fixes so tdos2 passes
  784. Revision 1.12 2002/09/07 16:01:27 peter
  785. * old logs removed and tabs fixed
  786. }