dos.pp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 2001 by members of the Free Pascal
  5. development team
  6. DOS unit template based on POSIX
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. Unit Dos;
  14. Interface
  15. {$goto on}
  16. Const
  17. FileNameLen = 255;
  18. Type
  19. SearchRec = packed Record
  20. {Fill : array[1..21] of byte; Fill replaced with below}
  21. DirPtr : pointer; {directory pointer for reading directory}
  22. SearchAttr : Byte; {attribute we are searching for}
  23. Fill : Array[1..16] of Byte; {future use}
  24. {End of fill}
  25. Attr : Byte; {attribute of found file}
  26. Time : LongInt; {last modify date of found file}
  27. Size : LongInt; {file size of found file}
  28. Reserved : Word; {future use}
  29. Name : String[FileNameLen]; {name of found file}
  30. SearchSpec : String[FileNameLen]; {search pattern}
  31. SearchDir : String[FileNameLen]; { path we are searching in }
  32. End;
  33. {$DEFINE HAS_FILENAMELEN}
  34. {$I dosh.inc}
  35. Procedure AddDisk(const path:string);
  36. Implementation
  37. Uses
  38. strings,posix;
  39. (* Potentially needed FPC_FEXPAND_* defines should be defined here. *)
  40. {$I dos.inc}
  41. { Used by AddDisk(), DiskFree() and DiskSize() }
  42. const
  43. Drives : byte = 4;
  44. MAX_DRIVES = 26;
  45. var
  46. DriveStr : array[4..MAX_DRIVES] of pchar;
  47. Function StringToPPChar(Var S:STring; var count : longint):ppchar;
  48. {
  49. Create a PPChar to structure of pchars which are the arguments specified
  50. in the string S. Especially usefull for creating an ArgV for Exec-calls
  51. }
  52. var
  53. nr : longint;
  54. Buf : ^char;
  55. p : ppchar;
  56. begin
  57. s:=s+#0;
  58. buf:=@s[1];
  59. nr:=0;
  60. while(buf^<>#0) do
  61. begin
  62. while (buf^ in [' ',#8,#10]) do
  63. inc(buf);
  64. inc(nr);
  65. while not (buf^ in [' ',#0,#8,#10]) do
  66. inc(buf);
  67. end;
  68. getmem(p,nr*4);
  69. StringToPPChar:=p;
  70. if p=nil then
  71. begin
  72. Errno:=sys_enomem;
  73. count := 0;
  74. exit;
  75. end;
  76. buf:=@s[1];
  77. while (buf^<>#0) do
  78. begin
  79. while (buf^ in [' ',#8,#10]) do
  80. begin
  81. buf^:=#0;
  82. inc(buf);
  83. end;
  84. p^:=buf;
  85. inc(p);
  86. p^:=nil;
  87. while not (buf^ in [' ',#0,#8,#10]) do
  88. inc(buf);
  89. end;
  90. count := nr;
  91. end;
  92. {$i dos_beos.inc} { include OS specific stuff }
  93. {******************************************************************************
  94. --- Info / Date / Time ---
  95. ******************************************************************************}
  96. var
  97. TZSeconds : longint; { offset to add/ subtract from Epoch to get local time }
  98. tzdaylight : boolean;
  99. tzname : array[boolean] of pchar;
  100. type
  101. GTRec = packed Record
  102. Year,
  103. Month,
  104. MDay,
  105. WDay,
  106. Hour,
  107. Minute,
  108. Second : Word;
  109. End;
  110. Const
  111. {Date Calculation}
  112. C1970 = 2440588;
  113. D0 = 1461;
  114. D1 = 146097;
  115. D2 = 1721119;
  116. function WeekDay (y,m,d:longint):longint;
  117. {
  118. Calculates th day of the week. returns -1 on error
  119. }
  120. var
  121. u,v : longint;
  122. begin
  123. if (m<1) or (m>12) or (y<1600) or (y>4000) or
  124. (d<1) or (d>30+((m+ord(m>7)) and 1)-ord(m=2)) or
  125. ((m*d=58) and (((y mod 4>0) or (y mod 100=0)) and (y mod 400>0))) then
  126. WeekDay:=-1
  127. else
  128. begin
  129. u:=m;
  130. v:=y;
  131. if m<3 then
  132. begin
  133. inc(u,12);
  134. dec(v);
  135. end;
  136. WeekDay:=(d+2*u+((3*(u+1)) div 5)+v+(v div 4)-(v div 100)+(v div 400)+1) mod 7;
  137. end;
  138. end;
  139. Procedure JulianToGregorian(JulianDN:LongInt;Var Year,Month,Day:Word);
  140. Var
  141. YYear,XYear,Temp,TempMonth : LongInt;
  142. Begin
  143. Temp:=((JulianDN-D2) shl 2)-1;
  144. JulianDN:=Temp Div D1;
  145. XYear:=(Temp Mod D1) or 3;
  146. YYear:=(XYear Div D0);
  147. Temp:=((((XYear mod D0)+4) shr 2)*5)-3;
  148. Day:=((Temp Mod 153)+5) Div 5;
  149. TempMonth:=Temp Div 153;
  150. If TempMonth>=10 Then
  151. Begin
  152. inc(YYear);
  153. dec(TempMonth,12);
  154. End;
  155. inc(TempMonth,3);
  156. Month := TempMonth;
  157. Year:=YYear+(JulianDN*100);
  158. end;
  159. Procedure EpochToLocal(epoch:time_t;var year,month,day,hour,minute,second:Word);
  160. {
  161. Transforms Epoch time into local time (hour, minute,seconds)
  162. }
  163. Var
  164. DateNum: time_t;
  165. Begin
  166. Epoch:=Epoch+TZSeconds;
  167. Datenum:=(Epoch Div 86400) + c1970;
  168. JulianToGregorian(DateNum,Year,Month,day);
  169. Epoch:=Abs(Epoch Mod 86400);
  170. Hour:=Epoch Div 3600;
  171. Epoch:=Epoch Mod 3600;
  172. Minute:=Epoch Div 60;
  173. Second:=Epoch Mod 60;
  174. End;
  175. Procedure GetDate(Var Year, Month, MDay, WDay: Word);
  176. var
  177. hour,minute,second : word;
  178. timeval : time_t;
  179. Begin
  180. timeval := sys_time(timeval);
  181. { convert the GMT time to local time }
  182. EpochToLocal(timeval,year,month,mday,hour,minute,second);
  183. Wday:=weekday(Year,Month,MDay);
  184. end;
  185. Procedure SetDate(Year, Month, Day: Word);
  186. Begin
  187. {!!}
  188. End;
  189. Procedure GetTime(Var Hour, Minute, Second, Sec100: Word);
  190. var
  191. timeval : time_t;
  192. year,month,day: word;
  193. Begin
  194. timeval := sys_time(timeval);
  195. EpochToLocal(timeval,year,month,day,hour,minute,second);
  196. Sec100 := 0;
  197. end;
  198. Procedure SetTime(Hour, Minute, Second, Sec100: Word);
  199. Begin
  200. {!!}
  201. End;
  202. Procedure UnixDateToDt(SecsPast: LongInt; Var Dt: DateTime);
  203. Begin
  204. EpochToLocal(SecsPast,dt.Year,dt.Month,dt.Day,dt.Hour,dt.Min,dt.Sec);
  205. End;
  206. {$ifndef DOS_HAS_EXEC}
  207. {******************************************************************************
  208. --- Exec ---
  209. ******************************************************************************}
  210. Function InternalWaitProcess(Pid:pid_t):Longint; { like WaitPid(PID,@result,0) Handling of Signal interrupts (errno=EINTR), returning the Exitcode of Process (>=0) or -Status if terminated}
  211. var r,s : cint;
  212. begin
  213. repeat
  214. s:=$7F00;
  215. r:=sys_WaitPid(Pid,s,0);
  216. until (r<>-1) or (Errno<>Sys_EINTR);
  217. { When r = -1 or r = 0, no status is available, so there was an error. }
  218. if (r=-1) or (r=0) then
  219. InternalWaitProcess:=-1 { return -1 to indicate an error }
  220. else
  221. begin
  222. { process terminated normally }
  223. if wifexited(s)<>0 then
  224. begin
  225. { get status code }
  226. InternalWaitProcess := wexitstatus(s);
  227. exit;
  228. end;
  229. { process terminated due to a signal }
  230. if wifsignaled(s)<>0 then
  231. begin
  232. { get signal number }
  233. InternalWaitProcess := wstopsig(s);
  234. exit;
  235. end;
  236. InternalWaitProcess:=-1;
  237. end;
  238. end;
  239. Procedure Exec (Const Path: PathStr; Const ComLine: ComStr);
  240. var
  241. pid : pid_t;
  242. tmp : string;
  243. p : ppchar;
  244. count: longint;
  245. // The Error-Checking in the previous Version failed, since halt($7F) gives an WaitPid-status of $7F00
  246. F: File;
  247. Begin
  248. {$IFOPT I+}
  249. {$DEFINE IOCHECK}
  250. {$ENDIF}
  251. {$I-}
  252. { verify if the file to execute exists }
  253. Assign(F,Path);
  254. Reset(F,1);
  255. if IOResult <> 0 then
  256. { file not found }
  257. begin
  258. DosError := 2;
  259. exit;
  260. end
  261. else
  262. Close(F);
  263. {$IFDEF IOCHECK}
  264. {$I+}
  265. {$UNDEF IOCHECK}
  266. {$ENDIF}
  267. LastDosExitCode:=0;
  268. { Fork the process }
  269. pid:=sys_Fork;
  270. if pid=0 then
  271. begin
  272. {The child does the actual execution, and then exits}
  273. tmp := Path+' '+ComLine;
  274. p:=StringToPPChar(tmp,count);
  275. if (p<>nil) and (p^<>nil) then
  276. begin
  277. sys_Execve(p^,p,Envp);
  278. end;
  279. {If the execve fails, we return an exitvalue of 127, to let it be known}
  280. sys_exit(127);
  281. end
  282. else
  283. if pid=-1 then {Fork failed - parent only}
  284. begin
  285. DosError:=8;
  286. exit
  287. end;
  288. {We're in the parent, let's wait.}
  289. LastDosExitCode:=InternalWaitProcess(pid); // WaitPid and result-convert
  290. if (LastDosExitCode>=0) and (LastDosExitCode<>127) then DosError:=0 else
  291. DosError:=8; // perhaps one time give an better error
  292. End;
  293. {$ENDIF}
  294. {******************************************************************************
  295. --- Disk ---
  296. ******************************************************************************}
  297. Procedure AddDisk(const path:string);
  298. begin
  299. if not (DriveStr[Drives]=nil) then
  300. FreeMem(DriveStr[Drives],StrLen(DriveStr[Drives])+1);
  301. GetMem(DriveStr[Drives],length(Path)+1);
  302. StrPCopy(DriveStr[Drives],path);
  303. inc(Drives);
  304. if Drives>26 then
  305. Drives:=4;
  306. end;
  307. {******************************************************************************
  308. --- Findfirst FindNext ---
  309. ******************************************************************************}
  310. Function FNMatch(const Pattern,Name:string):Boolean;
  311. Var
  312. LenPat,LenName : longint;
  313. Function DoFNMatch(i,j:longint):Boolean;
  314. Var
  315. Found : boolean;
  316. Begin
  317. Found:=true;
  318. While Found and (i<=LenPat) Do
  319. Begin
  320. Case Pattern[i] of
  321. '?' : Found:=(j<=LenName);
  322. '*' : Begin
  323. {find the next character in pattern, different of ? and *}
  324. while Found and (i<LenPat) do
  325. begin
  326. inc(i);
  327. case Pattern[i] of
  328. '*' : ;
  329. '?' : begin
  330. inc(j);
  331. Found:=(j<=LenName);
  332. end;
  333. else
  334. Found:=false;
  335. end;
  336. end;
  337. {Now, find in name the character which i points to, if the * or ?
  338. wasn't the last character in the pattern, else, use up all the
  339. chars in name}
  340. Found:=true;
  341. if (i<=LenPat) then
  342. begin
  343. repeat
  344. {find a letter (not only first !) which maches pattern[i]}
  345. while (j<=LenName) and (name[j]<>pattern[i]) do
  346. inc (j);
  347. if (j<LenName) then
  348. begin
  349. if DoFnMatch(i+1,j+1) then
  350. begin
  351. i:=LenPat;
  352. j:=LenName;{we can stop}
  353. Found:=true;
  354. end
  355. else
  356. inc(j);{We didn't find one, need to look further}
  357. end;
  358. until (j>=LenName);
  359. end
  360. else
  361. j:=LenName;{we can stop}
  362. end;
  363. else {not a wildcard character in pattern}
  364. Found:=(j<=LenName) and (pattern[i]=name[j]);
  365. end;
  366. inc(i);
  367. inc(j);
  368. end;
  369. DoFnMatch:=Found and (j>LenName);
  370. end;
  371. Begin {start FNMatch}
  372. LenPat:=Length(Pattern);
  373. LenName:=Length(Name);
  374. FNMatch:=DoFNMatch(1,1);
  375. End;
  376. Procedure FindClose(Var f: SearchRec);
  377. {
  378. Closes dirptr if it is open
  379. }
  380. Begin
  381. { could already have been closed }
  382. if assigned(f.dirptr) then
  383. sys_closedir(pdir(f.dirptr));
  384. f.dirptr := nil;
  385. End;
  386. { Returns a filled in searchRec structure }
  387. { and TRUE if the specified file in s is }
  388. { found. }
  389. Function FindGetFileInfo(s:string;var f:SearchRec):boolean;
  390. var
  391. DT : DateTime;
  392. st : stat;
  393. Fmode : byte;
  394. res: string; { overlaid variable }
  395. Dir : DirsTr;
  396. Name : NameStr;
  397. Ext: ExtStr;
  398. begin
  399. FindGetFileInfo:=false;
  400. res := s + #0;
  401. if sys_stat(@res[1],st)<>0 then
  402. exit;
  403. if S_ISDIR(st.st_mode) then
  404. fmode:=directory
  405. else
  406. fmode:=0;
  407. if (st.st_mode and S_IWUSR)=0 then
  408. fmode:=fmode or readonly;
  409. FSplit(s,Dir,Name,Ext);
  410. if Name[1]='.' then
  411. fmode:=fmode or hidden;
  412. If ((FMode and Not(f.searchattr))=0) Then
  413. Begin
  414. if Ext <> '' then
  415. res := Name + Ext
  416. else
  417. res := Name;
  418. f.Name:=res;
  419. f.Attr:=FMode;
  420. f.Size:=longint(st.st_size);
  421. UnixDateToDT(st.st_mtime, DT);
  422. PackTime(DT,f.Time);
  423. FindGetFileInfo:=true;
  424. End;
  425. end;
  426. Procedure FindNext(Var f: SearchRec);
  427. {
  428. re-opens dir if not already in array and calls FindWorkProc
  429. }
  430. Var
  431. FName,
  432. SName : string;
  433. Found,
  434. Finished : boolean;
  435. p : PDirEnt;
  436. Begin
  437. {Main loop}
  438. SName:=f.SearchSpec;
  439. Found:=False;
  440. Finished:=(f.dirptr=nil);
  441. While Not Finished Do
  442. Begin
  443. p:=sys_readdir(pdir(f.dirptr));
  444. if p=nil then
  445. begin
  446. FName:=''
  447. end
  448. else
  449. FName:=Strpas(@p^.d_name);
  450. If FName='' Then
  451. Finished:=True
  452. Else
  453. Begin
  454. If FNMatch(SName,FName) Then
  455. Begin
  456. Found:=FindGetFileInfo(f.SearchDir+FName,f);
  457. if Found then
  458. begin
  459. Finished:=true;
  460. end;
  461. End;
  462. End;
  463. End;
  464. {Shutdown}
  465. If Found Then
  466. Begin
  467. DosError:=0;
  468. End
  469. Else
  470. Begin
  471. FindClose(f);
  472. { FindClose() might be called thereafter also... }
  473. f.dirptr := nil;
  474. DosError:=18;
  475. End;
  476. End;
  477. Procedure FindFirst(Const Path: PathStr; Attr: Word; Var f: SearchRec);
  478. {
  479. opens dir
  480. }
  481. var
  482. res: string;
  483. Dir : DirsTr;
  484. Name : NameStr;
  485. Ext: ExtStr;
  486. Begin
  487. { initialize f.dirptr because it is used }
  488. { to see if we need to close the dir stream }
  489. f.dirptr := nil;
  490. if Path='' then
  491. begin
  492. DosError:=3;
  493. exit;
  494. end;
  495. {We always also search for readonly and archive, regardless of Attr:}
  496. f.SearchAttr := Attr or archive or readonly;
  497. {Wildcards?}
  498. if (Pos('?',Path)=0) and (Pos('*',Path)=0) then
  499. begin
  500. if FindGetFileInfo(Path,f) then
  501. DosError:=0
  502. else
  503. begin
  504. if ErrNo=Sys_ENOENT then
  505. DosError:=3
  506. else
  507. DosError:=18;
  508. end;
  509. f.DirPtr:=nil;
  510. end
  511. else
  512. {Find Entry}
  513. begin
  514. FSplit(Path,Dir,Name,Ext);
  515. if Ext <> '' then
  516. res := Name + Ext
  517. else
  518. res := Name;
  519. f.SearchSpec := res;
  520. { if dir is an empty string }
  521. { then this indicates that }
  522. { use the current working }
  523. { directory. }
  524. if dir = '' then
  525. dir := './';
  526. f.SearchDir := Dir;
  527. { add terminating null character }
  528. Dir := Dir + #0;
  529. f.dirptr := sys_opendir(@Dir[1]);
  530. if not assigned(f.dirptr) then
  531. begin
  532. DosError := 8;
  533. exit;
  534. end;
  535. FindNext(f);
  536. end;
  537. End;
  538. {******************************************************************************
  539. --- File ---
  540. ******************************************************************************}
  541. Function FSearch(const path:pathstr;dirlist:string):pathstr;
  542. {
  543. Searches for a file 'path' in the list of direcories in 'dirlist'.
  544. returns an empty string if not found. Wildcards are NOT allowed.
  545. If dirlist is empty, it is set to '.'
  546. }
  547. Var
  548. NewDir : PathStr;
  549. p1 : Longint;
  550. Info : Stat;
  551. buffer : array[0..FileNameLen+1] of char;
  552. Begin
  553. Move(path[1], Buffer, Length(path));
  554. Buffer[Length(path)]:=#0;
  555. if (length(Path)>0) and (path[1]='/') and (sys_stat(pchar(@Buffer),info)=0) then
  556. begin
  557. FSearch:=path;
  558. exit;
  559. end;
  560. {Replace ':' with ';'}
  561. for p1:=1to length(dirlist) do
  562. if dirlist[p1]=':' then
  563. dirlist[p1]:=';';
  564. {Check for WildCards}
  565. If (Pos('?',Path) <> 0) or (Pos('*',Path) <> 0) Then
  566. FSearch:='' {No wildcards allowed in these things.}
  567. Else
  568. Begin
  569. Dirlist:='.;'+dirlist;{Make sure current dir is first to be searched.}
  570. Repeat
  571. p1:=Pos(';',DirList);
  572. If p1=0 Then
  573. p1:=255;
  574. NewDir:=Copy(DirList,1,P1 - 1);
  575. if NewDir[Length(NewDir)]<>'/' then
  576. NewDir:=NewDir+'/';
  577. NewDir:=NewDir+Path;
  578. Delete(DirList,1,p1);
  579. Move(NewDir[1], Buffer, Length(NewDir));
  580. Buffer[Length(NewDir)]:=#0;
  581. if sys_stat(pchar(@Buffer),Info)=0 then
  582. Begin
  583. If Pos('./',NewDir)=1 Then
  584. Delete(NewDir,1,2);
  585. {DOS strips off an initial .\}
  586. End
  587. Else
  588. NewDir:='';
  589. Until (DirList='') or (Length(NewDir) > 0);
  590. FSearch:=NewDir;
  591. End;
  592. End;
  593. Procedure GetFAttr(var f; var attr : word);
  594. Var
  595. info : stat;
  596. LinAttr : mode_t;
  597. Begin
  598. DosError:=0;
  599. if sys_stat(@textrec(f).name,info)<>0 then
  600. begin
  601. Attr:=0;
  602. DosError:=3;
  603. exit;
  604. end
  605. else
  606. LinAttr:=Info.st_Mode;
  607. if S_ISDIR(LinAttr) then
  608. Attr:=directory
  609. else
  610. Attr:=0;
  611. if sys_Access(@textrec(f).name,W_OK)<>0 then
  612. Attr:=Attr or readonly;
  613. if (filerec(f).name[0]='.') then
  614. Attr:=Attr or hidden;
  615. end;
  616. Procedure getftime (var f; var time : longint);
  617. Var
  618. Info: stat;
  619. DT: DateTime;
  620. Begin
  621. doserror:=0;
  622. if sys_fstat(filerec(f).handle,info)<>0 then
  623. begin
  624. Time:=0;
  625. doserror:=3;
  626. exit
  627. end
  628. else
  629. UnixDateToDT(Info.st_mtime,DT);
  630. PackTime(DT,Time);
  631. End;
  632. {******************************************************************************
  633. --- Environment ---
  634. ******************************************************************************}
  635. Function EnvCount: Longint;
  636. var
  637. envcnt : longint;
  638. p : ppchar;
  639. Begin
  640. envcnt:=0;
  641. p:=envp; {defined in syslinux}
  642. while (p^<>nil) do
  643. begin
  644. inc(envcnt);
  645. inc(p);
  646. end;
  647. EnvCount := envcnt
  648. End;
  649. Function EnvStr (Index: longint): String;
  650. Var
  651. i : longint;
  652. p : ppchar;
  653. Begin
  654. p:=envp; {defined in syslinux}
  655. i:=1;
  656. envstr:='';
  657. if (index < 1) or (index > EnvCount) then
  658. exit;
  659. while (i<Index) and (p^<>nil) do
  660. begin
  661. inc(i);
  662. inc(p);
  663. end;
  664. if p<>nil then
  665. envstr:=strpas(p^)
  666. End;
  667. Function GetEnv(EnvVar:string):string;
  668. {
  669. Searches the environment for a string with name p and
  670. returns a pchar to it's value.
  671. A pchar is used to accomodate for strings of length > 255
  672. }
  673. var
  674. ep : ppchar;
  675. found : boolean;
  676. p1 : pchar;
  677. Begin
  678. EnvVar:=EnvVar+'='; {Else HOST will also find HOSTNAME, etc}
  679. ep:=envp;
  680. found:=false;
  681. if ep<>nil then
  682. begin
  683. while (not found) and (ep^<>nil) do
  684. begin
  685. if strlcomp(@EnvVar[1],(ep^),length(EnvVar))=0 then
  686. found:=true
  687. else
  688. inc(ep);
  689. end;
  690. end;
  691. if found then
  692. p1:=ep^+length(EnvVar)
  693. else
  694. p1:=nil;
  695. if p1 = nil then
  696. GetEnv := ''
  697. else
  698. GetEnv := StrPas(p1);
  699. end;
  700. Procedure setftime(var f; time : longint);
  701. Begin
  702. {! No POSIX equivalent !}
  703. End;
  704. Procedure setfattr (var f;attr : word);
  705. Begin
  706. {! No POSIX equivalent !}
  707. End;
  708. { Include timezone routines }
  709. {$i timezone.inc}
  710. {******************************************************************************
  711. --- Initialization ---
  712. ******************************************************************************}
  713. Initialization
  714. InitLocalTime;
  715. finalization
  716. DoneLocalTime;
  717. end.
  718. {
  719. $Log$
  720. Revision 1.12 2004-12-05 21:04:56 hajny
  721. * compilation fix for dosh.inc changes
  722. Revision 1.11 2004/12/05 20:35:03 hajny
  723. * compilation fix for dosh.inc changes
  724. Revision 1.10 2004/12/05 16:44:43 hajny
  725. * GetMsCount added, platform independent routines moved to single include file
  726. Revision 1.9 2004/02/17 17:37:26 daniel
  727. * Enable threadvars again
  728. Revision 1.8 2004/02/16 22:16:57 hajny
  729. * LastDosExitCode changed back from threadvar temporarily
  730. Revision 1.7 2004/02/15 21:26:37 hajny
  731. * overloaded ExecuteProcess added, EnvStr param changed to longint
  732. Revision 1.6 2004/02/09 12:03:16 michael
  733. + Switched to single interface in dosh.inc
  734. Revision 1.5 2003/12/03 20:53:22 olle
  735. * files are not pretended to have attr ARCHIVE anymore
  736. * files with attr READONLY and ARCHIVE are always returned by FindFirst etc
  737. * made code more conformant with unix/dos.pp
  738. Revision 1.4 2003/01/08 22:32:28 marco
  739. * Small fixes and quick merge with 1.0.x. At least the compiler builds now,
  740. but it could crash hard, since there are lots of unimplemented funcs.
  741. Revision 1.1.2.14 2001/12/09 03:31:35 carl
  742. * Exec() fixed (was full of bugs) : No DosError=2 report fixed, status code error fixed.
  743. + MAX_DRIVES constant added
  744. Revision 1.1.2.13 2001/12/03 03:12:28 carl
  745. * update for new posix prototype (caused problem with other OS)
  746. readdir / closedir
  747. Revision 1.1.2.12 2001/09/28 01:11:14 carl
  748. * bugfix of pchar move in FSearch() (would give wrong results)
  749. Revision 1.1.2.11 2001/08/21 10:48:46 carl
  750. + add goto on
  751. Revision 1.1.2.10 2001/08/15 01:04:38 carl
  752. * instead include posix unit
  753. * corrected bug in DateNum type (should be time_t)
  754. Revision 1.1.2.9 2001/08/13 09:37:17 carl
  755. * changed prototype of sys_readdir
  756. Revision 1.1.2.8 2001/08/12 15:12:30 carl
  757. + added timezone information
  758. * bugfix of overflow in conversion of epoch to local
  759. * bugfix of index verification in getenv
  760. Revision 1.1.2.7 2001/08/08 01:58:18 carl
  761. * bugfix of problem with FindFirst() / FindNext()
  762. Revision 1.1.2.5 2001/08/04 05:24:21 carl
  763. + implemented FindFirst / FindNext (untested)
  764. + Exec()
  765. + split
  766. + Timezone support reinstated
  767. Revision 1.1.2.4 2001/07/08 04:46:01 carl
  768. * waitpid is now portable
  769. + fnmatch()
  770. Revision 1.1.2.3 2001/07/07 15:42:29 carl
  771. * compiler error corrections
  772. Revision 1.1.2.2 2001/07/07 03:49:53 carl
  773. + more POSIX compliance stuff
  774. Revision 1.1.2.1 2001/07/06 11:21:49 carl
  775. + add files for POSIX
  776. }