dos.pp 21 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. {$ifdef cpui386}
  69. Registers = packed record
  70. case i : integer of
  71. 0 : (ax,f1,bx,f2,cx,f3,dx,f4,bp,f5,si,f51,di,f6,ds,f7,es,f8,flags,fs,gs : word);
  72. 1 : (al,ah,f9,f10,bl,bh,f11,f12,cl,ch,f13,f14,dl,dh : byte);
  73. 2 : (eax, ebx, ecx, edx, ebp, esi, edi : longint);
  74. End;
  75. {$endif cpui386}
  76. DateTime = packed record
  77. Year,
  78. Month,
  79. Day,
  80. Hour,
  81. Min,
  82. Sec : word;
  83. End;
  84. Var
  85. DosError : integer;
  86. {Utils}
  87. function weekday(y,m,d : longint) : longint;
  88. Procedure UnixDateToDt(SecsPast: LongInt; Var Dt: DateTime);
  89. Function DTToUnixDate(DT: DateTime): LongInt;
  90. {Info/Date/Time}
  91. Function DosVersion: Word;
  92. Procedure GetDate(var year, month, mday, wday: word);
  93. Procedure GetTime(var hour, minute, second, sec100: word);
  94. procedure SetDate(year,month,day: word);
  95. Procedure SetTime(hour,minute,second,sec100: word);
  96. Procedure UnpackTime(p: longint; var t: datetime);
  97. Procedure PackTime(var t: datetime; var p: longint);
  98. {Exec}
  99. Procedure Exec(const path: pathstr; const comline: comstr);
  100. Function DosExitCode: word;
  101. {Disk}
  102. Procedure AddDisk(const path:string);
  103. Function DiskFree(drive: byte) : int64;
  104. Function DiskSize(drive: byte) : int64;
  105. Procedure FindFirst(const path: pathstr; attr: word; var f: searchRec);
  106. Procedure FindNext(var f: searchRec);
  107. Procedure FindClose(Var f: SearchRec);
  108. {File}
  109. Procedure GetFAttr(var f; var attr: word);
  110. Procedure GetFTime(var f; var time: longint);
  111. Function FSearch(path: pathstr; dirlist: string): pathstr;
  112. Function FExpand(const path: pathstr): pathstr;
  113. Procedure FSplit(path: pathstr; var dir: dirstr; var name: namestr; var ext: extstr);
  114. {Environment}
  115. Function EnvCount: longint;
  116. Function EnvStr(index: integer): string;
  117. Function GetEnv (envvar: string): string;
  118. {Do Nothing Functions, no Linux version}
  119. {$ifdef cpui386}
  120. Procedure Intr(intno: byte; var regs: registers);
  121. Procedure MSDos(var regs: registers);
  122. {$endif cpui386}
  123. Procedure SwapVectors;
  124. Procedure GetIntVec(intno: byte; var vector: pointer);
  125. Procedure SetIntVec(intno: byte; vector: pointer);
  126. Procedure Keep(exitcode: Word);
  127. Procedure SetFAttr(var f; attr: word);
  128. Procedure SetFTime(var f; time: longint);
  129. Procedure GetCBreak(var breakvalue: boolean);
  130. Procedure SetCBreak(breakvalue: boolean);
  131. Procedure GetVerify(var verify: boolean);
  132. Procedure SetVerify(verify: boolean);
  133. Implementation
  134. Uses
  135. Strings,UnixUtil,Unix,BaseUnix;
  136. {******************************************************************************
  137. --- Link C Lib if set ---
  138. ******************************************************************************}
  139. type
  140. RtlInfoType = Record
  141. FMode,
  142. FInode,
  143. FUid,
  144. FGid,
  145. FSize,
  146. FMTime : LongInt;
  147. End;
  148. {******************************************************************************
  149. --- Info / Date / Time ---
  150. ******************************************************************************}
  151. Const
  152. {Date Calculation}
  153. C1970 = 2440588;
  154. D0 = 1461;
  155. D1 = 146097;
  156. D2 = 1721119;
  157. type
  158. GTRec = packed Record
  159. Year,
  160. Month,
  161. MDay,
  162. WDay,
  163. Hour,
  164. Minute,
  165. Second : Word;
  166. End;
  167. Function DosVersion:Word;
  168. Var
  169. Buffer : Array[0..255] of Char;
  170. Tmp2,
  171. TmpStr : String[40];
  172. TmpPos,
  173. SubRel,
  174. Rel : LongInt;
  175. info : utsname;
  176. Begin
  177. FPUName(info);
  178. Move(info.release,buffer[0],40);
  179. TmpStr:=StrPas(Buffer);
  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:=fpFork;
  267. if pid=0 then
  268. begin
  269. {The child does the actual exec, and then exits}
  270. if ComLine='' then
  271. Execl(Path)
  272. else
  273. Execl(Path+' '+ComLine);
  274. {If the execve fails, we return an exitvalue of 127, to let it be known}
  275. fpExit(127);
  276. end
  277. else
  278. if pid=-1 then {Fork failed}
  279. begin
  280. DosError:=8;
  281. exit
  282. end;
  283. {We're in the parent, let's wait.}
  284. LastDosExitCode:=WaitProcess(pid); // WaitPid and result-convert
  285. if (LastDosExitCode>=0) and (LastDosExitCode<>127) then
  286. DosError:=0
  287. else
  288. DosError:=8; // perhaps one time give an better error
  289. End;
  290. Function DosExitCode: Word;
  291. Begin
  292. DosExitCode:=LastDosExitCode;
  293. End;
  294. {******************************************************************************
  295. --- Disk ---
  296. ******************************************************************************}
  297. {
  298. The Diskfree and Disksize functions need a file on the specified drive, since this
  299. is required for the statfs system call.
  300. These filenames are set in drivestr[0..26], and have been preset to :
  301. 0 - '.' (default drive - hence current dir is ok.)
  302. 1 - '/fd0/.' (floppy drive 1 - should be adapted to local system )
  303. 2 - '/fd1/.' (floppy drive 2 - should be adapted to local system )
  304. 3 - '/' (C: equivalent of dos is the root partition)
  305. 4..26 (can be set by you're own applications)
  306. ! Use AddDisk() to Add new drives !
  307. They both return -1 when a failure occurs.
  308. }
  309. Const
  310. FixDriveStr : array[0..3] of pchar=(
  311. '.',
  312. '/fd0/.',
  313. '/fd1/.',
  314. '/.'
  315. );
  316. const
  317. Drives : byte = 4;
  318. var
  319. DriveStr : array[4..26] of pchar;
  320. Procedure AddDisk(const path:string);
  321. begin
  322. if not (DriveStr[Drives]=nil) then
  323. FreeMem(DriveStr[Drives],StrLen(DriveStr[Drives])+1);
  324. GetMem(DriveStr[Drives],length(Path)+1);
  325. StrPCopy(DriveStr[Drives],path);
  326. inc(Drives);
  327. if Drives>26 then
  328. Drives:=4;
  329. end;
  330. Function DiskFree(Drive: Byte): int64;
  331. var
  332. fs : tstatfs;
  333. Begin
  334. if ((Drive<4) and (not (fixdrivestr[Drive]=nil)) and (StatFS(StrPas(fixdrivestr[drive]),fs)<>-1)) or
  335. ((not (drivestr[Drive]=nil)) and (StatFS(StrPas(drivestr[drive]),fs)<>-1)) then
  336. Diskfree:=int64(fs.bavail)*int64(fs.bsize)
  337. else
  338. Diskfree:=-1;
  339. End;
  340. Function DiskSize(Drive: Byte): int64;
  341. var
  342. fs : tstatfs;
  343. Begin
  344. if ((Drive<4) and (not (fixdrivestr[Drive]=nil)) and (StatFS(StrPas(fixdrivestr[drive]),fs)<>-1)) or
  345. ((not (drivestr[Drive]=nil)) and (StatFS(StrPas(drivestr[drive]),fs)<>-1)) then
  346. DiskSize:=int64(fs.blocks)*int64(fs.bsize)
  347. else
  348. DiskSize:=-1;
  349. End;
  350. {******************************************************************************
  351. --- Findfirst FindNext ---
  352. ******************************************************************************}
  353. Const
  354. RtlFindSize = 15;
  355. Type
  356. RtlFindRecType = Record
  357. SearchNum,
  358. DirPtr,
  359. LastUsed : LongInt;
  360. End;
  361. Var
  362. RtlFindRecs : Array[1..RtlFindSize] of RtlFindRecType;
  363. CurrSearchNum : LongInt;
  364. Procedure FindClose(Var f: SearchRec);
  365. {
  366. Closes dirptr if it is open
  367. }
  368. Var
  369. i : longint;
  370. Begin
  371. if f.SearchType=0 then
  372. begin
  373. i:=1;
  374. repeat
  375. if (RtlFindRecs[i].SearchNum=f.SearchNum) then
  376. break;
  377. inc(i);
  378. until (i>RtlFindSize);
  379. If i<=RtlFindSize Then
  380. Begin
  381. RtlFindRecs[i].SearchNum:=0;
  382. if f.dirptr<>0 then
  383. fpclosedir(pdir(f.dirptr)^);
  384. End;
  385. end;
  386. f.dirptr:=0;
  387. End;
  388. Function FindGetFileInfo(const s:string;var f:SearchRec):boolean;
  389. var
  390. DT : DateTime;
  391. Info : RtlInfoType;
  392. st : baseunix.stat;
  393. begin
  394. FindGetFileInfo:=false;
  395. if not fpstat(s,st)>=0 then
  396. exit;
  397. info.FSize:=st.st_Size;
  398. info.FMTime:=st.st_mtime;
  399. if (st.st_mode and STAT_IFMT)=STAT_IFDIR then
  400. info.fmode:=$10
  401. else
  402. info.fmode:=$0;
  403. if (st.st_mode and STAT_IWUSR)=0 then
  404. info.fmode:=info.fmode or 1;
  405. if s[f.NamePos+1]='.' then
  406. info.fmode:=info.fmode or $2;
  407. If ((Info.FMode and Not(f.searchattr))=0) Then
  408. Begin
  409. f.Name:=Copy(s,f.NamePos+1,255);
  410. f.Attr:=Info.FMode;
  411. f.Size:=Info.FSize;
  412. UnixDateToDT(Info.FMTime, DT);
  413. PackTime(DT,f.Time);
  414. FindGetFileInfo:=true;
  415. End;
  416. end;
  417. Function FindLastUsed: Longint;
  418. {
  419. Find unused or least recently used dirpointer slot in findrecs array
  420. }
  421. Var
  422. BestMatch,i : Longint;
  423. Found : Boolean;
  424. Begin
  425. BestMatch:=1;
  426. i:=1;
  427. Found:=False;
  428. While (i <= RtlFindSize) And (Not Found) Do
  429. Begin
  430. If (RtlFindRecs[i].SearchNum = 0) Then
  431. Begin
  432. BestMatch := i;
  433. Found := True;
  434. End
  435. Else
  436. Begin
  437. If RtlFindRecs[i].LastUsed > RtlFindRecs[BestMatch].LastUsed Then
  438. BestMatch := i;
  439. End;
  440. Inc(i);
  441. End;
  442. FindLastUsed := BestMatch;
  443. End;
  444. Procedure FindNext(Var f: SearchRec);
  445. {
  446. re-opens dir if not already in array and calls FindWorkProc
  447. }
  448. Var
  449. DirName : Array[0..256] of Char;
  450. i,
  451. ArrayPos : Longint;
  452. FName,
  453. SName : string;
  454. Found,
  455. Finished : boolean;
  456. p : PDirEnt;
  457. Begin
  458. If f.SearchType=0 Then
  459. Begin
  460. ArrayPos:=0;
  461. For i:=1 to RtlFindSize Do
  462. Begin
  463. If RtlFindRecs[i].SearchNum = f.SearchNum Then
  464. ArrayPos:=i;
  465. Inc(RtlFindRecs[i].LastUsed);
  466. End;
  467. If ArrayPos=0 Then
  468. Begin
  469. If f.NamePos = 0 Then
  470. Begin
  471. DirName[0] := '.';
  472. DirName[1] := '/';
  473. DirName[2] := #0;
  474. End
  475. Else
  476. Begin
  477. Move(f.SearchSpec[1], DirName[0], f.NamePos);
  478. DirName[f.NamePos] := #0;
  479. End;
  480. f.DirPtr := longint(fpopendir(@(DirName)));
  481. If f.DirPtr <> 0 Then
  482. begin
  483. ArrayPos:=FindLastUsed;
  484. If RtlFindRecs[ArrayPos].SearchNum > 0 Then
  485. FpCloseDir((pdir(rtlfindrecs[arraypos].dirptr)^));
  486. RtlFindRecs[ArrayPos].SearchNum := f.SearchNum;
  487. RtlFindRecs[ArrayPos].DirPtr := f.DirPtr;
  488. if f.searchpos>0 then
  489. seekdir(pdir(f.dirptr), f.searchpos);
  490. end;
  491. End;
  492. if ArrayPos>0 then
  493. RtlFindRecs[ArrayPos].LastUsed:=0;
  494. end;
  495. {Main loop}
  496. SName:=Copy(f.SearchSpec,f.NamePos+1,255);
  497. Found:=False;
  498. Finished:=(f.dirptr=0);
  499. While Not Finished Do
  500. Begin
  501. p:=fpreaddir(pdir(f.dirptr)^);
  502. if p=nil then
  503. FName:=''
  504. else
  505. FName:=Strpas(@p^.d_name);
  506. If FName='' Then
  507. Finished:=True
  508. Else
  509. Begin
  510. If FNMatch(SName,FName) Then
  511. Begin
  512. Found:=FindGetFileInfo(Copy(f.SearchSpec,1,f.NamePos)+FName,f);
  513. if Found then
  514. Finished:=true;
  515. End;
  516. End;
  517. End;
  518. {Shutdown}
  519. If Found Then
  520. Begin
  521. f.searchpos:=telldir(pdir(f.dirptr));
  522. DosError:=0;
  523. End
  524. Else
  525. Begin
  526. FindClose(f);
  527. DosError:=18;
  528. End;
  529. End;
  530. Procedure FindFirst(Const Path: PathStr; Attr: Word; Var f: SearchRec);
  531. {
  532. opens dir and calls FindWorkProc
  533. }
  534. Begin
  535. if Path='' then
  536. begin
  537. DosError:=3;
  538. exit;
  539. end;
  540. {Create Info}
  541. f.SearchSpec := Path;
  542. {We always also search for readonly and archive, regardless of Attr:}
  543. f.SearchAttr := Attr or archive or readonly;
  544. f.SearchPos := 0;
  545. f.NamePos := Length(f.SearchSpec);
  546. while (f.NamePos>0) and (f.SearchSpec[f.NamePos]<>'/') do
  547. dec(f.NamePos);
  548. {Wildcards?}
  549. if (Pos('?',Path)=0) and (Pos('*',Path)=0) then
  550. begin
  551. if FindGetFileInfo(Path,f) then
  552. DosError:=0
  553. else
  554. begin
  555. { According to tdos2 test it should return 18
  556. if ErrNo=Sys_ENOENT then
  557. DosError:=3
  558. else }
  559. DosError:=18;
  560. end;
  561. f.DirPtr:=0;
  562. f.SearchType:=1;
  563. f.searchnum:=-1;
  564. end
  565. else
  566. {Find Entry}
  567. begin
  568. Inc(CurrSearchNum);
  569. f.SearchNum:=CurrSearchNum;
  570. f.SearchType:=0;
  571. FindNext(f);
  572. end;
  573. End;
  574. {******************************************************************************
  575. --- File ---
  576. ******************************************************************************}
  577. Procedure FSplit(Path: PathStr; Var Dir: DirStr; Var Name: NameStr;Var Ext: ExtStr);
  578. Begin
  579. UnixUtil.FSplit(Path,Dir,Name,Ext);
  580. End;
  581. Function FExpand(Const Path: PathStr): PathStr;
  582. Begin
  583. FExpand:=Unix.FExpand(Path);
  584. End;
  585. Function FSearch(path : pathstr;dirlist : string) : pathstr;
  586. Var
  587. info : BaseUnix.stat;
  588. Begin
  589. if (length(Path)>0) and (path[1]='/') and (fpStat(path,info)>=0) then
  590. FSearch:=path
  591. else
  592. FSearch:=Unix.FSearch(path,dirlist);
  593. End;
  594. Procedure GetFAttr(var f; var attr : word);
  595. Var
  596. info : baseunix.stat;
  597. LinAttr : longint;
  598. Begin
  599. DosError:=0;
  600. if FPStat(strpas(@textrec(f).name),info)<0 then
  601. begin
  602. Attr:=0;
  603. DosError:=3;
  604. exit;
  605. end
  606. else
  607. LinAttr:=Info.st_Mode;
  608. if fpS_ISDIR(LinAttr) then
  609. Attr:=$10
  610. else
  611. Attr:=$0;
  612. if fpAccess(strpas(@textrec(f).name),W_OK)<0 then
  613. Attr:=Attr or $1;
  614. if filerec(f).name[0]='.' then
  615. Attr:=Attr or $2;
  616. end;
  617. Procedure getftime (var f; var time : longint);
  618. Var
  619. Info: baseunix.stat;
  620. DT: DateTime;
  621. Begin
  622. doserror:=0;
  623. if fpfstat(filerec(f).handle,info)<0 then
  624. begin
  625. Time:=0;
  626. doserror:=6;
  627. exit
  628. end
  629. else
  630. UnixDateToDT(Info.st_mTime,DT);
  631. PackTime(DT,Time);
  632. End;
  633. Procedure setftime(var f; time : longint);
  634. Var
  635. utim: utimbuf;
  636. DT: DateTime;
  637. path: pathstr;
  638. index: Integer;
  639. Begin
  640. doserror:=0;
  641. with utim do
  642. begin
  643. actime:=getepochtime;
  644. UnPackTime(Time,DT);
  645. modtime:=DTToUnixDate(DT);
  646. end;
  647. path := strpas(@filerec(f).name);
  648. if fputime(path,@utim)<0 then
  649. begin
  650. Time:=0;
  651. doserror:=3;
  652. end;
  653. End;
  654. {******************************************************************************
  655. --- Environment ---
  656. ******************************************************************************}
  657. Function EnvCount: Longint;
  658. var
  659. envcnt : longint;
  660. p : ppchar;
  661. Begin
  662. envcnt:=0;
  663. p:=envp; {defined in syslinux}
  664. while (p^<>nil) do
  665. begin
  666. inc(envcnt);
  667. inc(p);
  668. end;
  669. EnvCount := envcnt
  670. End;
  671. Function EnvStr(Index: Integer): String;
  672. Var
  673. i : longint;
  674. p : ppchar;
  675. Begin
  676. p:=envp; {defined in syslinux}
  677. i:=1;
  678. while (i<Index) and (p^<>nil) do
  679. begin
  680. inc(i);
  681. inc(p);
  682. end;
  683. if p=nil then
  684. envstr:=''
  685. else
  686. envstr:=strpas(p^)
  687. End;
  688. Function GetEnv(EnvVar: String): String;
  689. var
  690. p : pchar;
  691. Begin
  692. p:=BaseUnix.fpGetEnv(EnvVar);
  693. if p=nil then
  694. GetEnv:=''
  695. else
  696. GetEnv:=StrPas(p);
  697. End;
  698. {******************************************************************************
  699. --- Do Nothing Procedures/Functions ---
  700. ******************************************************************************}
  701. {$ifdef cpui386}
  702. Procedure Intr (intno: byte; var regs: registers);
  703. Begin
  704. {! No Linux equivalent !}
  705. End;
  706. Procedure msdos(var regs : registers);
  707. Begin
  708. {! No Linux equivalent !}
  709. End;
  710. {$endif cpui386}
  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 setfattr (var f;attr : word);
  728. Begin
  729. {! No Linux equivalent !}
  730. { Fail for setting VolumeId }
  731. if (attr and VolumeID)<>0 then
  732. doserror:=5;
  733. End;
  734. Procedure GetCBreak(Var BreakValue: Boolean);
  735. Begin
  736. {! No Linux equivalent !}
  737. breakvalue:=true
  738. End;
  739. Procedure SetCBreak(BreakValue: Boolean);
  740. Begin
  741. {! No Linux equivalent !}
  742. End;
  743. Procedure GetVerify(Var Verify: Boolean);
  744. Begin
  745. {! No Linux equivalent !}
  746. Verify:=true;
  747. End;
  748. Procedure SetVerify(Verify: Boolean);
  749. Begin
  750. {! No Linux equivalent !}
  751. End;
  752. {******************************************************************************
  753. --- Initialization ---
  754. ******************************************************************************}
  755. End.
  756. {
  757. $Log$
  758. Revision 1.22 2003-12-29 21:15:04 jonas
  759. * fixed setftime (sorry Marco :)
  760. Revision 1.21 2003/12/03 20:17:03 olle
  761. * files are not pretended to have attr ARCHIVED anymore
  762. + FindFirst etc now also filters on attr HIDDEN
  763. * files with attr READONLY and ARCHIVE are always returned by FindFirst etc
  764. Revision 1.19 2003/10/17 22:13:30 olle
  765. * changed i386 to cpui386
  766. Revision 1.18 2003/09/27 12:51:33 peter
  767. * fpISxxx macros renamed to C compliant fpS_ISxxx
  768. Revision 1.17 2003/09/17 17:30:46 marco
  769. * Introduction of unixutil
  770. Revision 1.16 2003/09/14 20:15:01 marco
  771. * Unix reform stage two. Remove all calls from Unix that exist in Baseunix.
  772. Revision 1.15 2003/05/16 20:56:06 florian
  773. no message
  774. Revision 1.14 2003/05/14 13:51:03 florian
  775. * ifdef'd code which i386 specific
  776. Revision 1.13 2002/12/08 16:05:34 peter
  777. * small error code fixes so tdos2 passes
  778. Revision 1.12 2002/09/07 16:01:27 peter
  779. * old logs removed and tabs fixed
  780. }