dos.pp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1993,97 by the Free Pascal development team.
  5. Dos unit for BP7 compatible RTL
  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. {$I os.inc}
  14. interface
  15. { Include Win32 Consts,Types }
  16. {$I win32.inc}
  17. Const
  18. Max_Path = 255;
  19. {Bitmasks for CPU Flags}
  20. fcarry = $0001;
  21. fparity = $0004;
  22. fauxiliary = $0010;
  23. fzero = $0040;
  24. fsign = $0080;
  25. foverflow = $0800;
  26. {Bitmasks for file attribute}
  27. readonly = $01;
  28. hidden = $02;
  29. sysfile = $04;
  30. volumeid = $08;
  31. directory = $10;
  32. archive = $20;
  33. anyfile = $3F;
  34. {File Status}
  35. fmclosed = $D7B0;
  36. fminput = $D7B1;
  37. fmoutput = $D7B2;
  38. fminout = $D7B3;
  39. Type
  40. { Needed for Win95 LFN Support }
  41. ComStr = String[255];
  42. PathStr = String[255];
  43. DirStr = String[255];
  44. NameStr = String[255];
  45. ExtStr = String[255];
  46. {
  47. filerec.inc contains the definition of the filerec.
  48. textrec.inc contains the definition of the textrec.
  49. It is in a separate file to make it available in other units without
  50. having to use the DOS unit for it.
  51. }
  52. {$i filerec.inc}
  53. {$i textrec.inc}
  54. DateTime = packed record
  55. Year,
  56. Month,
  57. Day,
  58. Hour,
  59. Min,
  60. Sec : word;
  61. End;
  62. PWin32FindData = ^TWin32FindData;
  63. TWin32FindData = packed record
  64. dwFileAttributes: Cardinal;
  65. ftCreationTime: TFileTime;
  66. ftLastAccessTime: TFileTime;
  67. ftLastWriteTime: TFileTime;
  68. nFileSizeHigh: Cardinal;
  69. nFileSizeLow: Cardinal;
  70. dwReserved0: Cardinal;
  71. dwReserved1: Cardinal;
  72. cFileName: array[0..MAX_PATH - 1] of Char;
  73. cAlternateFileName: array[0..13] of Char;
  74. end;
  75. Searchrec = Packed Record
  76. FindHandle : THandle;
  77. W32FindData : TWin32FindData;
  78. time : longint;
  79. size : longint;
  80. attr : longint;
  81. name : string;
  82. end;
  83. registers = packed record
  84. case i : integer of
  85. 0 : (ax,f1,bx,f2,cx,f3,dx,f4,bp,f5,si,f51,di,f6,ds,f7,es,f8,flags,fs,gs : word);
  86. 1 : (al,ah,f9,f10,bl,bh,f11,f12,cl,ch,f13,f14,dl,dh : byte);
  87. 2 : (eax, ebx, ecx, edx, ebp, esi, edi : longint);
  88. end;
  89. Var
  90. DosError : integer;
  91. {Interrupt}
  92. Procedure Intr(intno: byte; var regs: registers);
  93. Procedure MSDos(var regs: registers);
  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. Function DiskFree(drive: byte) : longint;
  107. Function DiskSize(drive: byte) : longint;
  108. Procedure FindFirst(const path: pathstr; attr: word; var f: searchRec);
  109. Procedure FindNext(var f: searchRec);
  110. Procedure FindClose(Var f: SearchRec);
  111. {File}
  112. Procedure GetFAttr(var f; var attr: word);
  113. Procedure GetFTime(var f; var time: longint);
  114. Function FSearch(path: pathstr; dirlist: string): pathstr;
  115. Function FExpand(const path: pathstr): pathstr;
  116. Procedure FSplit(path: pathstr; var dir: dirstr; var name: namestr; var ext: extstr);
  117. {Environment}
  118. Function EnvCount: longint;
  119. Function EnvStr(index: integer): string;
  120. Function GetEnv(envvar: string): string;
  121. {Misc}
  122. Procedure SetFAttr(var f; attr: word);
  123. Procedure SetFTime(var f; time: longint);
  124. Procedure GetCBreak(var breakvalue: boolean);
  125. Procedure SetCBreak(breakvalue: boolean);
  126. Procedure GetVerify(var verify: boolean);
  127. Procedure SetVerify(verify: boolean);
  128. {Do Nothing Functions}
  129. Procedure SwapVectors;
  130. Procedure GetIntVec(intno: byte; var vector: pointer);
  131. Procedure SetIntVec(intno: byte; vector: pointer);
  132. Procedure Keep(exitcode: word);
  133. implementation
  134. uses strings;
  135. {******************************************************************************
  136. --- Conversion ---
  137. ******************************************************************************}
  138. function GetLastError : DWORD;
  139. external 'kernel32' name 'GetLastError';
  140. function FileTimeToDosDateTime(const ft :TFileTime;var data,time : word) : boolean;
  141. external 'kernel32' name 'FileTimeToDosDateTime';
  142. function DosDateTimeToFileTime(date,time : word;var ft :TFileTime) : boolean;
  143. external 'kernel32' name 'DosDateTimeToFileTime';
  144. function FileTimeToLocalFileTime(const ft : TFileTime;var lft : TFileTime) : boolean;
  145. external 'kernel32' name 'FileTimeToLocalFileTime';
  146. function LocalFileTimeToFileTime(const lft : TFileTime;var ft : TFileTime) : boolean;
  147. external 'kernel32' name 'LocalFileTimeToFileTime';
  148. type
  149. Longrec=packed record
  150. lo,hi : word;
  151. end;
  152. function Last2DosError(d:dword):integer;
  153. begin
  154. Last2DosError:=d;
  155. end;
  156. Function DosToWinAttr (Const Attr : Longint) : longint;
  157. begin
  158. DosToWinAttr:=Attr;
  159. end;
  160. Function WinToDosAttr (Const Attr : Longint) : longint;
  161. begin
  162. WinToDosAttr:=Attr;
  163. end;
  164. Function DosToWinTime (DTime:longint;Var Wtime : TFileTime):boolean;
  165. var
  166. lft : TFileTime;
  167. begin
  168. DosToWinTime:=DosDateTimeToFileTime(longrec(dtime).hi,longrec(dtime).lo,lft) and
  169. LocalFileTimeToFileTime(lft,Wtime);
  170. end;
  171. Function WinToDosTime (Const Wtime : TFileTime;var DTime:longint):boolean;
  172. var
  173. lft : TFileTime;
  174. begin
  175. WinToDosTime:=FileTimeToLocalFileTime(WTime,lft) and
  176. FileTimeToDosDateTime(lft,longrec(dtime).hi,longrec(dtime).lo);
  177. end;
  178. {******************************************************************************
  179. --- Dos Interrupt ---
  180. ******************************************************************************}
  181. procedure intr(intno : byte;var regs : registers);
  182. begin
  183. { !!!!!!!! }
  184. end;
  185. procedure msdos(var regs : registers);
  186. begin
  187. { !!!!!!!! }
  188. end;
  189. {******************************************************************************
  190. --- Info / Date / Time ---
  191. ******************************************************************************}
  192. function GetVersion : longint;
  193. external 'kernel32' name 'GetVersion';
  194. procedure GetLocalTime(var t : TSystemTime);
  195. external 'kernel32' name 'GetLocalTime';
  196. function SetLocalTime(const t : TSystemTime) : boolean;
  197. external 'kernel32' name 'SetLocalTime';
  198. function dosversion : word;
  199. begin
  200. dosversion:=GetVersion;
  201. end;
  202. procedure getdate(var year,month,mday,wday : word);
  203. var
  204. t : TSystemTime;
  205. begin
  206. GetLocalTime(t);
  207. year:=t.wYear;
  208. month:=t.wMonth;
  209. mday:=t.wDay;
  210. wday:=t.wDayOfWeek;
  211. end;
  212. procedure setdate(year,month,day : word);
  213. var
  214. t : TSystemTime;
  215. begin
  216. { we need the time set privilege }
  217. { so this function crash currently }
  218. {!!!!!}
  219. GetLocalTime(t);
  220. t.wYear:=year;
  221. t.wMonth:=month;
  222. t.wDay:=day;
  223. { only a quite good solution, we can loose some ms }
  224. SetLocalTime(t);
  225. end;
  226. procedure gettime(var hour,minute,second,sec100 : word);
  227. var
  228. t : TSystemTime;
  229. begin
  230. GetLocalTime(t);
  231. hour:=t.wHour;
  232. minute:=t.wMinute;
  233. second:=t.wSecond;
  234. sec100:=t.wMilliSeconds div 10;
  235. end;
  236. procedure settime(hour,minute,second,sec100 : word);
  237. var
  238. t : TSystemTime;
  239. begin
  240. { we need the time set privilege }
  241. { so this function crash currently }
  242. {!!!!!}
  243. GetLocalTime(t);
  244. t.wHour:=hour;
  245. t.wMinute:=minute;
  246. t.wSecond:=second;
  247. t.wMilliSeconds:=sec100*10;
  248. SetLocalTime(t);
  249. end;
  250. Procedure packtime(var t : datetime;var p : longint);
  251. Begin
  252. 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);
  253. End;
  254. Procedure unpacktime(p : longint;var t : datetime);
  255. Begin
  256. with t do
  257. begin
  258. sec:=(p and 31) shl 1;
  259. min:=(p shr 5) and 63;
  260. hour:=(p shr 11) and 31;
  261. day:=(p shr 16) and 31;
  262. month:=(p shr 21) and 15;
  263. year:=(p shr 25)+1980;
  264. end;
  265. End;
  266. {******************************************************************************
  267. --- Exec ---
  268. ******************************************************************************}
  269. function CreateProcess(lpApplicationName: PChar; lpCommandLine: PChar;
  270. lpProcessAttributes, lpThreadAttributes: PSecurityAttributes;
  271. bInheritHandles: BOOL; dwCreationFlags: DWORD; lpEnvironment: Pointer;
  272. lpCurrentDirectory: PChar; const lpStartupInfo: TStartupInfo;
  273. var lpProcessInformation: TProcessInformation): boolean;
  274. external 'kernel32' name 'CreateProcessA';
  275. function getExitCodeProcess(h:THandle;var code:longint):boolean;
  276. external 'kernel32' name 'GetExitCodeProcess';
  277. function WaitForSingleObject(hHandle: THandle; dwMilliseconds: DWORD): DWORD;
  278. external 'kernel32' name 'WaitForSingleObject';
  279. function CloseHandle(h : THandle) : longint;
  280. external 'kernel32' name 'CloseHandle';
  281. var
  282. lastdosexitcode : word;
  283. procedure exec(const path : pathstr;const comline : comstr);
  284. var
  285. SI: TStartupInfo;
  286. PI: TProcessInformation;
  287. Proc : THandle;
  288. l : Longint;
  289. AppPath,
  290. AppParam : array[0..255] of char;
  291. begin
  292. FillChar(SI, SizeOf(SI), 0);
  293. SI.cb:=SizeOf(SI);
  294. SI.wShowWindow:=1;
  295. Move(Path[1],AppPath,length(Path));
  296. AppPath[Length(Path)]:=#0;
  297. AppParam[0]:='-';
  298. AppParam[1]:=' ';
  299. Move(ComLine[1],AppParam[2],length(Comline));
  300. AppParam[Length(ComLine)+2]:=#0;
  301. if not CreateProcess(PChar(@AppPath), PChar(@AppParam), Nil, Nil, False,$20, Nil, Nil, SI, PI) then
  302. begin
  303. DosError:=Last2DosError(GetLastError);
  304. exit;
  305. end;
  306. Proc:=PI.hProcess;
  307. CloseHandle(PI.hThread);
  308. if WaitForSingleObject(Proc, Infinite) <> $ffffffff then
  309. GetExitCodeProcess(Proc,l)
  310. else
  311. l:=-1;
  312. CloseHandle(Proc);
  313. LastDosExitCode:=l;
  314. end;
  315. function dosexitcode : word;
  316. begin
  317. dosexitcode:=lastdosexitcode;
  318. end;
  319. procedure getcbreak(var breakvalue : boolean);
  320. begin
  321. { !! No Win32 Function !! }
  322. end;
  323. procedure setcbreak(breakvalue : boolean);
  324. begin
  325. { !! No Win32 Function !! }
  326. end;
  327. procedure getverify(var verify : boolean);
  328. begin
  329. { !! No Win32 Function !! }
  330. end;
  331. procedure setverify(verify : boolean);
  332. begin
  333. { !! No Win32 Function !! }
  334. end;
  335. {******************************************************************************
  336. --- Disk ---
  337. ******************************************************************************}
  338. function GetDiskFreeSpace(drive:pchar;var sector_cluster,bytes_sector,
  339. freeclusters,totalclusters:longint):boolean;
  340. external 'kernel32' name 'GetDiskFreeSpaceA';
  341. function diskfree(drive : byte) : longint;
  342. var
  343. disk : array[1..4] of char;
  344. secs,bytes,
  345. free,total : longint;
  346. begin
  347. if drive=0 then
  348. begin
  349. disk[1]:='\';
  350. disk[2]:=#0;
  351. end
  352. else
  353. begin
  354. disk[1]:=chr(drive+64);
  355. disk[2]:=':';
  356. disk[3]:='\';
  357. disk[4]:=#0;
  358. end;
  359. if GetDiskFreeSpace(@disk,secs,bytes,free,total) then
  360. diskfree:=free*secs*bytes
  361. else
  362. diskfree:=-1;
  363. end;
  364. function disksize(drive : byte) : longint;
  365. var
  366. disk : array[1..4] of char;
  367. secs,bytes,
  368. free,total : longint;
  369. begin
  370. if drive=0 then
  371. begin
  372. disk[1]:='\';
  373. disk[2]:=#0;
  374. end
  375. else
  376. begin
  377. disk[1]:=chr(drive+64);
  378. disk[2]:=':';
  379. disk[3]:='\';
  380. disk[4]:=#0;
  381. end;
  382. if GetDiskFreeSpace(@disk,secs,bytes,free,total) then
  383. disksize:=total*secs*bytes
  384. else
  385. disksize:=-1;
  386. end;
  387. {******************************************************************************
  388. --- Findfirst FindNext ---
  389. ******************************************************************************}
  390. { Needed kernel calls }
  391. function FindFirstFile (lpFileName: PChar; var lpFindFileData: TWIN32FindData): THandle;
  392. external 'kernel32' name 'FindFirstFileA';
  393. function FindNextFile (hFindFile: THandle; var lpFindFileData: TWIN32FindData): Boolean;
  394. external 'kernel32' name 'FindNextFileA';
  395. function FindCloseFile (hFindFile: THandle): Boolean;
  396. external 'kernel32' name 'FindClose';
  397. Procedure StringToPchar (Var S : String);
  398. Var L : Longint;
  399. begin
  400. L:=ord(S[0]);
  401. Move (S[1],S[0],L);
  402. S[L]:=#0;
  403. end;
  404. procedure FindMatch(var f:searchrec);
  405. Var
  406. TheAttr : Longint;
  407. begin
  408. TheAttr:=DosToWinAttr(F.Attr);
  409. { Find file with correct attribute }
  410. While (F.W32FindData.dwFileAttributes and TheAttr)=0 do
  411. begin
  412. if not FindNextFile (F.FindHandle,F.W32FindData) then
  413. begin
  414. DosError:=Last2DosError(GetLastError);
  415. exit;
  416. end;
  417. end;
  418. { Convert some attributes back }
  419. f.size:=F.W32FindData.NFileSizeLow;
  420. f.attr:=WinToDosAttr(F.W32FindData.dwFileAttributes);
  421. WinToDosTime(F.W32FindData.ftLastWriteTime,f.Time);
  422. f.Name:=StrPas(@F.W32FindData.cFileName);
  423. end;
  424. procedure findfirst(const path : pathstr;attr : word;var f : searchRec);
  425. begin
  426. { no error }
  427. doserror:=0;
  428. F.Name:=Path;
  429. F.Attr:=attr;
  430. StringToPchar(f.name);
  431. { FindFirstFile is a Win32 Call. }
  432. F.FindHandle:=FindFirstFile (pchar(@f.Name),F.W32FindData);
  433. If longint(F.FindHandle)=Invalid_Handle_value then
  434. begin
  435. DosError:=Last2DosError(GetLastError);
  436. exit;
  437. end;
  438. { Find file with correct attribute }
  439. FindMatch(f);
  440. end;
  441. procedure findnext(var f : searchRec);
  442. begin
  443. { no error }
  444. doserror:=0;
  445. if not FindNextFile (F.FindHandle,F.W32FindData) then
  446. begin
  447. DosError:=Last2DosError(GetLastError);
  448. exit;
  449. end;
  450. { Find file with correct attribute }
  451. FindMatch(f);
  452. end;
  453. procedure swapvectors;
  454. begin
  455. end;
  456. Procedure FindClose(Var f: SearchRec);
  457. begin
  458. If longint(F.FindHandle)<>Invalid_Handle_value then
  459. FindCloseFile(F.FindHandle);
  460. end;
  461. {******************************************************************************
  462. --- File ---
  463. ******************************************************************************}
  464. function GetFileTime(h : longint;creation,lastaccess,lastwrite : PFileTime) : boolean;
  465. external 'kernel32' name 'GetFileTime';
  466. function SetFileTime(h : longint;creation,lastaccess,lastwrite : PFileTime) : boolean;
  467. external 'kernel32' name 'SetFileTime';
  468. function SetFileAttributes(lpFileName : pchar;dwFileAttributes : longint) : boolean;
  469. external 'kernel32' name 'SetFileAttributesA';
  470. function GetFileAttributes(lpFileName : pchar) : longint;
  471. external 'kernel32' name 'GetFileAttributesA';
  472. procedure fsplit(path : pathstr;var dir : dirstr;var name : namestr;var ext : extstr);
  473. var
  474. p1,i : longint;
  475. begin
  476. { allow slash as backslash }
  477. for i:=1 to length(path) do
  478. if path[i]='/' then path[i]:='\';
  479. { get drive name }
  480. p1:=pos(':',path);
  481. if p1>0 then
  482. begin
  483. dir:=path[1]+':';
  484. delete(path,1,p1);
  485. end
  486. else
  487. dir:='';
  488. { split the path and the name, there are no more path informtions }
  489. { if path contains no backslashes }
  490. while true do
  491. begin
  492. p1:=pos('\',path);
  493. if p1=0 then
  494. break;
  495. dir:=dir+copy(path,1,p1);
  496. delete(path,1,p1);
  497. end;
  498. { try to find out a extension }
  499. p1:=pos('.',path);
  500. if p1>0 then
  501. begin
  502. ext:=copy(path,p1,4);
  503. delete(path,p1,length(path)-p1+1);
  504. end
  505. else
  506. ext:='';
  507. name:=path;
  508. end;
  509. function fexpand(const path : pathstr) : pathstr;
  510. var
  511. s,pa : string[79];
  512. i,j : longint;
  513. begin
  514. getdir(0,s);
  515. pa:=upcase(path);
  516. { allow slash as backslash }
  517. for i:=1 to length(pa) do
  518. if pa[i]='/' then
  519. pa[i]:='\';
  520. if (length(pa)>1) and (pa[1] in ['A'..'Z']) and (pa[2]=':') then
  521. begin
  522. { we must get the right directory }
  523. getdir(ord(pa[1])-ord('A')+1,s);
  524. if (ord(pa[0])>2) and (pa[3]<>'\') then
  525. if pa[1]=s[1] then
  526. pa:=s+'\'+copy (pa,3,length(pa))
  527. else
  528. pa:=pa[1]+':\'+copy (pa,3,length(pa))
  529. end
  530. else
  531. if pa[1]='\' then
  532. pa:=s[1]+':'+pa
  533. else if s[0]=#3 then
  534. pa:=s+pa
  535. else
  536. pa:=s+'\'+pa;
  537. {First remove all references to '\.\'}
  538. while pos ('\.\',pa)<>0 do
  539. delete (pa,pos('\.\',pa),2);
  540. {Now remove also all references to '\..\' + of course previous dirs..}
  541. repeat
  542. i:=pos('\..\',pa);
  543. if i<>0 then
  544. begin
  545. j:=i-1;
  546. while (j>1) and (pa[j]<>'\') do
  547. dec (j);
  548. delete (pa,j,i-j+3);
  549. end;
  550. until i=0;
  551. {Remove End . and \}
  552. if (length(pa)>0) and (pa[length(pa)]='.') then
  553. dec(byte(pa[0]));
  554. if (length(pa)>0) and (pa[length(pa)]='\') then
  555. dec(byte(pa[0]));
  556. fexpand:=pa;
  557. end;
  558. Function FSearch(path: pathstr; dirlist: string): pathstr;
  559. var
  560. i,p1 : longint;
  561. s : searchrec;
  562. newdir : pathstr;
  563. begin
  564. { No wildcards allowed in these things }
  565. if (pos('?',path)<>0) or (pos('*',path)<>0) then
  566. fsearch:=''
  567. else
  568. begin
  569. { allow slash as backslash }
  570. for i:=1 to length(dirlist) do
  571. if dirlist[i]='/' then dirlist[i]:='\';
  572. repeat
  573. p1:=pos(';',dirlist);
  574. if p1=0 then
  575. begin
  576. newdir:=copy(dirlist,1,p1-1);
  577. delete(dirlist,1,p1);
  578. end
  579. else
  580. begin
  581. newdir:=dirlist;
  582. dirlist:='';
  583. end;
  584. if (newdir<>'') and (not (newdir[length(newdir)] in ['\',':'])) then
  585. newdir:=newdir+'\';
  586. findfirst(newdir+path,anyfile,s);
  587. if doserror=0 then
  588. newdir:=newdir+path
  589. else
  590. newdir:='';
  591. until (dirlist='') or (newdir<>'');
  592. fsearch:=newdir;
  593. end;
  594. end;
  595. procedure getftime(var f;var time : longint);
  596. var
  597. ft : TFileTime;
  598. begin
  599. if GetFileTime(filerec(f).Handle,nil,nil,@ft) and
  600. WinToDosTime(ft,time) then
  601. exit
  602. else
  603. time:=0;
  604. end;
  605. procedure setftime(var f;time : longint);
  606. var
  607. ft : TFileTime;
  608. begin
  609. if DosToWinTime(time,ft) then
  610. SetFileTime(filerec(f).Handle,nil,nil,@ft);
  611. end;
  612. procedure getfattr(var f;var attr : word);
  613. var
  614. l : longint;
  615. begin
  616. l:=GetFileAttributes(filerec(f).name);
  617. if l=$ffffffff then
  618. doserror:=getlasterror;
  619. attr:=l;
  620. end;
  621. procedure setfattr(var f;attr : word);
  622. begin
  623. doserror:=0;
  624. if not(SetFileAttributes(filerec(f).name,attr)) then
  625. doserror:=getlasterror;
  626. end;
  627. {******************************************************************************
  628. --- Environment ---
  629. ******************************************************************************}
  630. {
  631. The environment is a block of zero terminated strings
  632. terminated by a #0
  633. }
  634. function GetEnvironmentStrings : pchar;
  635. external 'kernel32' name 'GetEnvironmentStringsA';
  636. function FreeEnvironmentStrings(p : pchar) : boolean;
  637. external 'kernel32' name 'FreeEnvironmentStringsA';
  638. function envcount : longint;
  639. var
  640. hp,p : pchar;
  641. count : longint;
  642. begin
  643. p:=GetEnvironmentStrings;
  644. hp:=p;
  645. count:=0;
  646. while hp^<>#0 do
  647. begin
  648. { next string entry}
  649. hp:=hp+strlen(hp)+1;
  650. inc(count);
  651. end;
  652. FreeEnvironmentStrings(p);
  653. envcount:=count;
  654. end;
  655. Function EnvStr(index: integer): string;
  656. var
  657. hp,p : pchar;
  658. count,i : longint;
  659. begin
  660. { envcount takes some time in win32 }
  661. count:=envcount;
  662. { range checking }
  663. if (index<=0) or (index>count) then
  664. begin
  665. envstr:='';
  666. exit;
  667. end;
  668. p:=GetEnvironmentStrings;
  669. hp:=p;
  670. { retrive the string with the given index }
  671. for i:=2 to index do
  672. hp:=hp+strlen(hp)+1;
  673. envstr:=strpas(hp);
  674. FreeEnvironmentStrings(p);
  675. end;
  676. Function GetEnv(envvar: string): string;
  677. var
  678. s : string;
  679. i : longint;
  680. hp,p : pchar;
  681. begin
  682. getenv:='';
  683. p:=GetEnvironmentStrings;
  684. hp:=p;
  685. while hp^<>#0 do
  686. begin
  687. s:=strpas(hp);
  688. i:=pos('=',s);
  689. if copy(s,1,i-1)=envvar then
  690. begin
  691. getenv:=copy(s,i+1,length(s)-i);
  692. break;
  693. end;
  694. { next string entry}
  695. hp:=hp+strlen(hp)+1;
  696. end;
  697. FreeEnvironmentStrings(p);
  698. end;
  699. {******************************************************************************
  700. --- Not Supported ---
  701. ******************************************************************************}
  702. Procedure keep(exitcode : word);
  703. Begin
  704. End;
  705. Procedure getintvec(intno : byte;var vector : pointer);
  706. Begin
  707. End;
  708. Procedure setintvec(intno : byte;vector : pointer);
  709. Begin
  710. End;
  711. end.
  712. {
  713. $Log$
  714. Revision 1.7 1998-06-10 10:39:13 peter
  715. * working w32 rtl
  716. Revision 1.6 1998/06/08 23:07:45 peter
  717. * dos interface is now 100% compatible
  718. * fixed call PASCALMAIN which must be direct asm
  719. Revision 1.5 1998/05/06 12:36:50 michael
  720. + Removed log from before restored version.
  721. Revision 1.4 1998/04/27 14:01:38 florian
  722. * was uncompilable
  723. Revision 1.3 1998/04/26 22:37:02 florian
  724. + getftime, unpacktime, packtime
  725. Revision 1.2 1998/04/26 21:49:09 florian
  726. + first compiling and working version
  727. }