dos.pas 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  1. {****************************************************************************
  2. Free Pascal Runtime-Library
  3. DOS unit for OS/2
  4. Copyright (c) 1997,1999-2000 by Daniel Mantione,
  5. member 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. {$ASMMODE ATT}
  14. {***************************************************************************}
  15. interface
  16. {***************************************************************************}
  17. {$PACKRECORDS 1}
  18. uses Strings, DosCalls;
  19. Type
  20. {Search record which is used by findfirst and findnext:}
  21. SearchRec = record
  22. case boolean of
  23. false: (Handle: THandle; {Used in os_OS2 mode}
  24. FStat: PFileFindBuf3;
  25. Fill: array [1..21 - SizeOf (THandle) - SizeOf (pointer)]
  26. of byte;
  27. Attr: byte;
  28. Time: longint;
  29. Size: longint;
  30. Name: string); {Filenames can be long in OS/2!}
  31. true: (Fill2: array [1..21] of byte;
  32. Attr2: byte;
  33. Time2: longint;
  34. Size2: longint;
  35. Name2: string); {Filenames can be long in OS/2!}
  36. end;
  37. {Flags for the exec procedure:
  38. }
  39. threadvar
  40. (* For compatibility with VP/2, used for runflags in Exec procedure. *)
  41. ExecFlags: cardinal;
  42. (* Note that the TP/BP compatible method for retrieval of exit codes *)
  43. (* is limited to only one (the last) execution! Including the following *)
  44. (* two variables in the interface part allows querying the status of *)
  45. (* of asynchronously started programs using DosWaitChild with dtNoWait *)
  46. (* parameter, i.e. without waiting for the final program result (as *)
  47. (* opposed to calling DosExitCode which would wait for the exit code). *)
  48. LastExecRes: TResultCodes;
  49. LastExecFlags: cardinal;
  50. {$i dosh.inc}
  51. {OS/2 specific functions}
  52. function GetEnvPChar (EnvVar: string): PChar;
  53. function DosErrorModuleName: string;
  54. (* In case of an error in Dos.Exec returns the name of the module *)
  55. (* causing the problem - e.g. name of a missing or corrupted DLL. *)
  56. (* It may also contain a queue name in case of a failed attempt *)
  57. (* to create queue for reading results of started sessions. *)
  58. implementation
  59. {$DEFINE HAS_GETMSCOUNT}
  60. {$DEFINE HAS_DOSEXITCODE}
  61. {$DEFINE FPC_FEXPAND_UNC} (* UNC paths are supported *)
  62. {$DEFINE FPC_FEXPAND_DRIVES} (* Full paths begin with drive specification *)
  63. {$DEFINE FPC_FEXPAND_GETENV_PCHAR}
  64. {$I dos.inc}
  65. threadvar
  66. LastDosErrorModuleName: string;
  67. const FindResvdMask = $00003737; {Allowed bits in attribute
  68. specification for DosFindFirst call.}
  69. function GetMsCount: int64;
  70. var
  71. L: cardinal;
  72. begin
  73. DosQuerySysInfo (svMsCount, svMsCount, L, 4);
  74. GetMsCount := L;
  75. end;
  76. function fsearch(path:pathstr;dirlist:string):pathstr;
  77. Var
  78. A: array [0..255] of char;
  79. D, P: AnsiString;
  80. begin
  81. P:=Path;
  82. D:=DirList;
  83. DosError := DosSearchPath (dsIgnoreNetErrs, PChar(D), PChar(P), @A, 255);
  84. if DosError <> 0 then
  85. OSErrorWatch (DosError);
  86. fsearch := StrPas (@A);
  87. end;
  88. procedure getftime(var f;var time:longint);
  89. var
  90. FStat: TFileStatus3;
  91. begin
  92. DosError := DosQueryFileInfo (FileRec (F).Handle, ilStandard, @FStat,
  93. SizeOf (FStat));
  94. if DosError=0 then
  95. begin
  96. Time := FStat.TimeLastWrite + longint (FStat.DateLastWrite) shl 16;
  97. if Time = 0 then
  98. Time := FStat.TimeCreation + longint (FStat.DateCreation) shl 16;
  99. end
  100. else
  101. begin
  102. Time:=0;
  103. OSErrorWatch (DosError);
  104. end;
  105. end;
  106. procedure SetFTime (var F; Time: longint);
  107. var FStat: TFileStatus3;
  108. RC: cardinal;
  109. begin
  110. RC := DosQueryFileInfo (FileRec (F).Handle, ilStandard, @FStat,
  111. SizeOf (FStat));
  112. if RC = 0 then
  113. begin
  114. FStat.DateLastAccess := Hi (Time);
  115. FStat.DateLastWrite := Hi (Time);
  116. FStat.TimeLastAccess := Lo (Time);
  117. FStat.TimeLastWrite := Lo (Time);
  118. RC := DosSetFileInfo (FileRec (F).Handle, ilStandard, @FStat,
  119. SizeOf (FStat));
  120. if RC <> 0 then
  121. OSErrorWatch (RC);
  122. end
  123. else
  124. OSErrorWatch (RC);
  125. DosError := integer (RC);
  126. end;
  127. function DosExitCode: word;
  128. var
  129. Res: TResultCodes;
  130. PPID: cardinal;
  131. RC: cardinal;
  132. begin
  133. if (LastExecFlags = deAsyncResult) or (LastExecFlags = deAsyncResultDb) then
  134. begin
  135. RC := DosWaitChild (DCWA_PROCESS, dtWait, Res, PPID, LastExecRes.PID);
  136. if RC = 0 then
  137. (* If we succeeded, the process is finished - possible future querying
  138. of DosExitCode shall return the result immediately as with synchronous
  139. execution. *)
  140. begin
  141. LastExecFlags := deSync;
  142. LastExecRes := Res;
  143. end
  144. else
  145. begin
  146. LastExecRes.ExitCode := RC shl 16;
  147. OSErrorWatch (RC);
  148. end;
  149. end;
  150. if LastExecRes.ExitCode > high (word) then
  151. DosExitCode := high (word)
  152. else
  153. DosExitCode := LastExecRes.ExitCode and $FFFF;
  154. end;
  155. procedure Exec (const Path: PathStr; const ComLine: ComStr);
  156. {Execute a program.}
  157. var
  158. Args0, Args: PByteArray;
  159. ArgSize: word;
  160. ObjName: string;
  161. Res: TResultCodes;
  162. RC, RC2: cardinal;
  163. ExecAppType: cardinal;
  164. HQ: THandle;
  165. SPID, STID, QName: string;
  166. SID, PID: cardinal;
  167. SD: TStartData;
  168. RD: TRequestData;
  169. PCI: PChildInfo;
  170. CISize: cardinal;
  171. Prio: byte;
  172. DSS: boolean;
  173. SR: SearchRec;
  174. MaxArgsSize: PtrUInt; (* Amount of memory reserved for arguments in bytes. *)
  175. MaxArgsSizeInc: word;
  176. PathZ: array [0..255] of char;
  177. begin
  178. { LastDosExitCode := Exec (Path, ExecRunFlags (ExecFlags), efDefault, ComLine);}
  179. ObjName := '';
  180. (* FExpand should be used only for the DosStartSession part
  181. and only if the executable is in the current directory. *)
  182. FindFirst (Path, AnyFile, SR);
  183. if DosError = 0 then
  184. QName := FExpand (Path)
  185. else
  186. QName := Path;
  187. FindClose (SR);
  188. MaxArgsSize := Length (ComLine) + Length (QName) + 256; (* More than enough *)
  189. if MaxArgsSize > high (word) then
  190. begin
  191. DosError := 8; (* Not quite, but "not enough memory" is close enough *)
  192. Exit;
  193. end;
  194. if ComLine = '' then
  195. begin
  196. Args0 := nil;
  197. Args := nil;
  198. StrPCopy (PathZ, Path);
  199. RC := DosQueryAppType (@PathZ [0], ExecAppType);
  200. end
  201. else
  202. begin
  203. GetMem (Args0, MaxArgsSize);
  204. Args := Args0;
  205. (* Work around a bug in OS/2 - argument to DosExecPgm *)
  206. (* should not cross a 64K boundary. *)
  207. while ((PtrUInt (Args) + MaxArgsSize) and $FFFF) < MaxArgsSize do
  208. begin
  209. MaxArgsSizeInc := MaxArgsSize -
  210. ((PtrUInt (Args) + MaxArgsSize) and $FFFF);
  211. Inc (MaxArgsSize, MaxArgsSizeInc);
  212. if MaxArgsSize > high (word) then
  213. begin
  214. DosError := 8; (* Not quite, but "not enough memory" is close enough *)
  215. Exit;
  216. end;
  217. ReallocMem (Args0, MaxArgsSize);
  218. Inc (pointer (Args), MaxArgsSizeInc);
  219. end;
  220. ArgSize := 0;
  221. Move (QName [1], Args^ [ArgSize], Length (QName));
  222. Inc (ArgSize, Length (QName));
  223. Args^ [ArgSize] := 0;
  224. Inc (ArgSize);
  225. {Now do the real arguments.}
  226. Move (ComLine [1], Args^ [ArgSize], Length (ComLine));
  227. Inc (ArgSize, Length (ComLine));
  228. Args^ [ArgSize] := 0;
  229. Inc (ArgSize);
  230. Args^ [ArgSize] := 0;
  231. RC := DosQueryAppType (PChar (Args), ExecAppType);
  232. end;
  233. if RC <> 0 then
  234. OSErrorWatch (RC)
  235. else
  236. if (ApplicationType and 3 = ExecAppType and 3) then
  237. (* DosExecPgm should work... *)
  238. begin
  239. DSS := false;
  240. Res.ExitCode := $FFFFFFFF;
  241. RC := DosExecPgm (ObjName, cardinal (ExecFlags), Args, nil, Res, Path);
  242. if RC = 0 then
  243. begin
  244. LastExecFlags := ExecFlags;
  245. LastExecRes := Res;
  246. LastDosErrorModuleName := '';
  247. end
  248. else
  249. begin
  250. if (RC = 190) or (RC = 191) then
  251. DSS := true;
  252. OSErrorWatch (RC);
  253. end;
  254. end
  255. else
  256. DSS := true;
  257. if DSS then
  258. begin
  259. Str (GetProcessID, SPID);
  260. Str (ThreadID, STID);
  261. QName := '\QUEUES\FPC_Dos_Exec_p' + SPID + 't' + STID + '.QUE'#0;
  262. FillChar (SD, SizeOf (SD), 0);
  263. SD.Length := SizeOf (SD);
  264. RC := 0;
  265. case ExecFlags of
  266. deSync:
  267. begin
  268. SD.Related := ssf_Related_Child;
  269. LastExecFlags := ExecFlags;
  270. SD.TermQ := @QName [1];
  271. RC := DosCreateQueue (HQ, quFIFO or quConvert_Address, @QName [1]);
  272. if RC <> 0 then
  273. OSErrorWatch (RC);
  274. end;
  275. deAsync,
  276. deAsyncResult:
  277. begin
  278. (* Current implementation of DosExitCode does not support retrieval *)
  279. (* of result codes for other session types started asynchronously. *)
  280. LastExecFlags := deAsync;
  281. SD.Related := ssf_Related_Independent;
  282. end;
  283. deBackground:
  284. begin
  285. (* Current implementation of DosExitCode does not support retrieval *)
  286. (* of result codes for other session types started asynchronously. *)
  287. LastExecFlags := ExecFlags;
  288. SD.Related := ssf_Related_Independent;
  289. SD.FgBg := ssf_FgBg_Back;
  290. end;
  291. deAsyncResultDB:
  292. begin
  293. (* Current implementation of DosExitCode does not support retrieval *)
  294. (* of result codes for other session types started asynchronously. *)
  295. LastExecFlags := ExecFlags;
  296. SD.Related := ssf_Related_Child;
  297. SD.TraceOpt := ssf_TraceOpt_Trace;
  298. end;
  299. end;
  300. if RC <> 0 then
  301. ObjName := Copy (QName, 1, Pred (Length (QName)))
  302. else
  303. begin
  304. if Args = nil then
  305. (* No parameters passed, Args not allocated for DosExecPgm, so allocate now. *)
  306. begin
  307. GetMem (Args0, MaxArgsSize);
  308. Args := Args0;
  309. Move (QName [1], Args^ [0], Length (QName));
  310. Args^ [Length (QName)] := 0;
  311. end
  312. else
  313. SD.PgmInputs := PChar (@Args^ [Length (QName) + 1]);
  314. SD.PgmName := PChar (Args);
  315. SD.InheritOpt := ssf_InhertOpt_Parent;
  316. SD.ObjectBuffer := @ObjName [1];
  317. SD.ObjectBuffLen := SizeOf (ObjName) - 1;
  318. RC := DosStartSession (SD, SID, PID);
  319. if RC <> 0 then
  320. OSErrorWatch (RC);
  321. if (RC = 0) or (RC = 457) then
  322. begin
  323. LastExecRes.PID := PID;
  324. if ExecFlags = deSync then
  325. begin
  326. RC := DosReadQueue (HQ, RD, CISize, PCI, 0, 0, Prio, 0);
  327. if RC <> 0 then
  328. OSErrorWatch (RC);
  329. if (RC = 0) and (PCI^.SessionID = SID) then
  330. begin
  331. LastExecRes.ExitCode := PCI^.Return;
  332. RC2 := DosCloseQueue (HQ);
  333. if RC2 <> 0 then
  334. OSErrorWatch (RC2);
  335. RC2 := DosFreeMem (PCI);
  336. if RC2 <> 0 then
  337. OSErrorWatch (RC2);
  338. end
  339. else
  340. begin
  341. RC2 := DosCloseQueue (HQ);
  342. if RC2 <> 0 then
  343. OSErrorWatch (RC2);
  344. end;
  345. end;
  346. end
  347. else if ExecFlags = deSync then
  348. begin
  349. RC2 := DosCloseQueue (HQ);
  350. if RC2 <> 0 then
  351. OSErrorWatch (RC2);
  352. end;
  353. end;
  354. end;
  355. if RC <> 0 then
  356. begin
  357. LastDosErrorModuleName := ObjName;
  358. LastExecFlags := deSync;
  359. LastExecRes.ExitCode := 0; (* Needed for TP/BP compatibility *)
  360. LastExecRes.TerminateReason := $FFFFFFFF;
  361. end;
  362. DosError := RC;
  363. if Args0 <> nil then
  364. FreeMem (Args0, MaxArgsSize);
  365. end;
  366. function DosErrorModuleName: string;
  367. begin
  368. DosErrorModuleName := LastDosErrorModuleName;
  369. end;
  370. function dosversion:word;
  371. {Returns OS/2 version}
  372. var
  373. Minor, Major: Cardinal;
  374. begin
  375. DosQuerySysInfo(svMajorVersion, svMajorVersion, Major, 4);
  376. DosQuerySysInfo(svMinorVersion, svMinorVersion, Minor, 4);
  377. DosVersion:=Major or Minor shl 8;
  378. end;
  379. procedure GetDate (var Year, Month, MDay, WDay: word);
  380. Var
  381. dt: TDateTime;
  382. begin
  383. DosGetDateTime(dt);
  384. Year:=dt.year;
  385. Month:=dt.month;
  386. MDay:=dt.Day;
  387. WDay:=dt.Weekday;
  388. end;
  389. procedure SetDate (Year, Month, Day: word);
  390. var
  391. DT: TDateTime;
  392. RC: cardinal;
  393. begin
  394. DosGetDateTime (DT);
  395. DT.Year := Year;
  396. DT.Month := byte (Month);
  397. DT.Day := byte (Day);
  398. RC := DosSetDateTime (DT);
  399. if RC <> 0 then
  400. OSErrorWatch (RC);
  401. end;
  402. procedure GetTime (var Hour, Minute, Second, Sec100: word);
  403. var
  404. dt: TDateTime;
  405. begin
  406. DosGetDateTime(dt);
  407. Hour:=dt.Hour;
  408. Minute:=dt.Minute;
  409. Second:=dt.Second;
  410. Sec100:=dt.Hundredths;
  411. end;
  412. procedure SetTime (Hour, Minute, Second, Sec100: word);
  413. var
  414. DT: TDateTime;
  415. RC: cardinal;
  416. begin
  417. DosGetDateTime (DT);
  418. DT.Hour := byte (Hour);
  419. DT.Minute := byte (Minute);
  420. DT.Second := byte (Second);
  421. DT.Sec100 := byte (Sec100);
  422. RC := DosSetDateTime (DT);
  423. if RC <> 0 then
  424. OSErrorWatch (RC);
  425. end;
  426. function DiskFree (Drive: byte): int64;
  427. var FI: TFSinfo;
  428. RC: cardinal;
  429. begin
  430. {In OS/2, we use the filesystem information.}
  431. RC := DosQueryFSInfo (Drive, 1, FI, SizeOf (FI));
  432. if RC = 0 then
  433. DiskFree := int64 (FI.Free_Clusters) *
  434. int64 (FI.Sectors_Per_Cluster) * int64 (FI.Bytes_Per_Sector)
  435. else
  436. begin
  437. DiskFree := -1;
  438. OSErrorWatch (RC);
  439. end;
  440. end;
  441. function DiskSize (Drive: byte): int64;
  442. var FI: TFSinfo;
  443. RC: cardinal;
  444. begin
  445. RC := DosQueryFSinfo (Drive, 1, FI, SizeOf (FI));
  446. if RC = 0 then
  447. DiskSize := int64 (FI.Total_Clusters) *
  448. int64 (FI.Sectors_Per_Cluster) * int64 (FI.Bytes_Per_Sector)
  449. else
  450. begin
  451. DiskSize := -1;
  452. OSErrorWatch (RC);
  453. end;
  454. end;
  455. procedure DosSearchRec2SearchRec (var F: SearchRec);
  456. type
  457. TRec = record
  458. T, D: word;
  459. end;
  460. begin
  461. with F do
  462. begin
  463. Name := FStat^.Name;
  464. Size := FStat^.FileSize;
  465. Attr := byte(FStat^.AttrFile and $FF);
  466. TRec (Time).T := FStat^.TimeLastWrite;
  467. TRec (Time).D := FStat^.DateLastWrite;
  468. end;
  469. end;
  470. procedure FindFirst (const Path: PathStr; Attr: word; var F: SearchRec);
  471. var Count: cardinal;
  472. begin
  473. {No error.}
  474. DosError := 0;
  475. New (F.FStat);
  476. F.Handle := THandle ($FFFFFFFF);
  477. Count := 1;
  478. DosError := integer (DosFindFirst (Path, F.Handle,
  479. Attr and FindResvdMask, F.FStat, SizeOf (F.FStat^),
  480. Count, ilStandard));
  481. if DosError <> 0 then
  482. OSErrorWatch (DosError)
  483. else if Count = 0 then
  484. DosError := 18;
  485. DosSearchRec2SearchRec (F);
  486. end;
  487. procedure FindNext (var F: SearchRec);
  488. var
  489. Count: cardinal;
  490. begin
  491. {No error}
  492. DosError := 0;
  493. Count := 1;
  494. DosError := integer (DosFindNext (F.Handle, F.FStat, SizeOf (F.FStat^),
  495. Count));
  496. if DosError <> 0 then
  497. OSErrorWatch (DosError)
  498. else if Count = 0 then
  499. DosError := 18;
  500. DosSearchRec2SearchRec (F);
  501. end;
  502. procedure FindClose (var F: SearchRec);
  503. begin
  504. if F.Handle <> THandle ($FFFFFFFF) then
  505. begin
  506. DosError := integer (DosFindClose (F.Handle));
  507. if DosError <> 0 then
  508. OSErrorWatch (DosError);
  509. end;
  510. Dispose (F.FStat);
  511. end;
  512. function envcount:longint;
  513. begin
  514. envcount:=envc;
  515. end;
  516. function envstr (index : longint) : string;
  517. var hp:Pchar;
  518. begin
  519. if (index<=0) or (index>envcount) then
  520. begin
  521. envstr:='';
  522. exit;
  523. end;
  524. hp:=EnvP[index-1];
  525. envstr:=strpas(hp);
  526. end;
  527. function GetEnvPChar (EnvVar: string): PChar;
  528. (* The assembler version is more than three times as fast as Pascal. *)
  529. var
  530. P: PChar;
  531. begin
  532. EnvVar := UpCase (EnvVar);
  533. {$ASMMODE INTEL}
  534. asm
  535. cld
  536. mov edi, Environment
  537. lea esi, EnvVar
  538. xor eax, eax
  539. lodsb
  540. @NewVar:
  541. cmp byte ptr [edi], 0
  542. jz @Stop
  543. push eax { eax contains length of searched variable name }
  544. push esi { esi points to the beginning of the variable name }
  545. mov ecx, -1 { our character ('=' - see below) _must_ be found }
  546. mov edx, edi { pointer to beginning of variable name saved in edx }
  547. mov al, '=' { searching until '=' (end of variable name) }
  548. repne
  549. scasb { scan until '=' not found }
  550. neg ecx { what was the name length? }
  551. dec ecx { corrected }
  552. dec ecx { exclude the '=' character }
  553. pop esi { restore pointer to beginning of variable name }
  554. pop eax { restore length of searched variable name }
  555. push eax { and save both of them again for later use }
  556. push esi
  557. cmp ecx, eax { compare length of searched variable name with name }
  558. jnz @NotEqual { ... of currently found variable, jump if different }
  559. xchg edx, edi { pointer to current variable name restored in edi }
  560. repe
  561. cmpsb { compare till the end of variable name }
  562. xchg edx, edi { pointer to beginning of variable contents in edi }
  563. jz @Equal { finish if they're equal }
  564. @NotEqual:
  565. xor eax, eax { look for 00h }
  566. mov ecx, -1 { it _must_ be found }
  567. repne
  568. scasb { scan until found }
  569. pop esi { restore pointer to beginning of variable name }
  570. pop eax { restore length of searched variable name }
  571. jmp @NewVar { ... or continue with new variable otherwise }
  572. @Stop:
  573. xor eax, eax
  574. mov P, eax { Not found - return nil }
  575. jmp @End
  576. @Equal:
  577. pop esi { restore the stack position }
  578. pop eax
  579. mov P, edi { place pointer to variable contents in P }
  580. @End:
  581. end ['eax','ecx','edx','esi','edi'];
  582. GetEnvPChar := P;
  583. end;
  584. {$ASMMODE ATT}
  585. Function GetEnv(envvar: string): string;
  586. (* The assembler version is more than three times as fast as Pascal. *)
  587. begin
  588. GetEnv := StrPas (GetEnvPChar (EnvVar));
  589. end;
  590. procedure GetFAttr (var F; var Attr: word);
  591. var
  592. PathInfo: TFileStatus3;
  593. RC: cardinal;
  594. {$ifndef FPC_ANSI_TEXTFILEREC}
  595. R: rawbytestring;
  596. {$endif not FPC_ANSI_TEXTFILEREC}
  597. P: pchar;
  598. begin
  599. Attr := 0;
  600. {$ifdef FPC_ANSI_TEXTFILEREC}
  601. P := @FileRec (F).Name;
  602. {$else FPC_ANSI_TEXTFILEREC}
  603. R := ToSingleByteFileSystemEncodedFileName (FileRec (F).Name);
  604. P := PChar (R);
  605. {$endif FPC_ANSI_TEXTFILEREC}
  606. RC := DosQueryPathInfo (P, ilStandard, @PathInfo, SizeOf (PathInfo));
  607. DosError := integer (RC);
  608. if RC = 0 then
  609. Attr := PathInfo.AttrFile
  610. else
  611. OSErrorWatch (RC);
  612. end;
  613. procedure SetFAttr (var F; Attr: word);
  614. var
  615. PathInfo: TFileStatus3;
  616. RC: cardinal;
  617. {$ifndef FPC_ANSI_TEXTFILEREC}
  618. R: rawbytestring;
  619. {$endif not FPC_ANSI_TEXTFILEREC}
  620. P: pchar;
  621. begin
  622. {$ifdef FPC_ANSI_TEXTFILEREC}
  623. P := @FileRec (F).Name;
  624. {$else FPC_ANSI_TEXTFILEREC}
  625. R := ToSingleByteFileSystemEncodedFileName (FileRec (F).Name);
  626. P := PChar (R);
  627. {$endif FPC_ANSI_TEXTFILEREC}
  628. RC := DosQueryPathInfo (P, ilStandard, @PathInfo, SizeOf (PathInfo));
  629. if RC = 0 then
  630. begin
  631. PathInfo.AttrFile := Attr;
  632. RC := DosSetPathInfo (P, ilStandard, @PathInfo, SizeOf (PathInfo),
  633. doWriteThru);
  634. if RC <> 0 then
  635. OSErrorWatch (RC);
  636. end
  637. else
  638. OSErrorWatch (RC);
  639. DosError := integer (RC);
  640. end;
  641. {function GetShortName(var p : String) : boolean;
  642. begin
  643. GetShortName:=true;}
  644. {$WARNING EA .shortname support (see FAT32 driver) should be probably added here!}
  645. {end;
  646. function GetLongName(var p : String) : boolean;
  647. begin
  648. GetLongName:=true;}
  649. {$WARNING EA .longname support should be probably added here!}
  650. {end;}
  651. begin
  652. FillChar (LastExecRes, SizeOf (LastExecRes), 0);
  653. LastDosErrorModuleName := '';
  654. ExecFlags := 0;
  655. LastExecFlags := deSync;
  656. end.