dos.pas 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741
  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. begin
  177. { LastDosExitCode := Exec (Path, ExecRunFlags (ExecFlags), efDefault, ComLine);}
  178. ObjName := '';
  179. (* FExpand should be used only for the DosStartSession part
  180. and only if the executable is in the current directory. *)
  181. FindFirst (Path, AnyFile, SR);
  182. if DosError = 0 then
  183. QName := FExpand (Path)
  184. else
  185. QName := Path;
  186. FindClose (SR);
  187. MaxArgsSize := Length (ComLine) + Length (QName) + 256; (* More than enough *)
  188. if MaxArgsSize > high (word) then
  189. begin
  190. DosError := 8; (* Not quite, but "not enough memory" is close enough *)
  191. Exit;
  192. end;
  193. if ComLine = '' then
  194. begin
  195. Args0 := nil;
  196. Args := nil;
  197. end
  198. else
  199. begin
  200. GetMem (Args0, MaxArgsSize);
  201. Args := Args0;
  202. (* Work around a bug in OS/2 - argument to DosExecPgm *)
  203. (* should not cross a 64K boundary. *)
  204. while ((PtrUInt (Args) + MaxArgsSize) and $FFFF) < MaxArgsSize do
  205. begin
  206. MaxArgsSizeInc := MaxArgsSize -
  207. ((PtrUInt (Args) + MaxArgsSize) and $FFFF);
  208. Inc (MaxArgsSize, MaxArgsSizeInc);
  209. if MaxArgsSize > high (word) then
  210. begin
  211. DosError := 8; (* Not quite, but "not enough memory" is close enough *)
  212. Exit;
  213. end;
  214. ReallocMem (Args0, MaxArgsSize);
  215. Inc (pointer (Args), MaxArgsSizeInc);
  216. end;
  217. ArgSize := 0;
  218. Move (QName [1], Args^ [ArgSize], Length (QName));
  219. Inc (ArgSize, Length (QName));
  220. Args^ [ArgSize] := 0;
  221. Inc (ArgSize);
  222. {Now do the real arguments.}
  223. Move (ComLine [1], Args^ [ArgSize], Length (ComLine));
  224. Inc (ArgSize, Length (ComLine));
  225. Args^ [ArgSize] := 0;
  226. Inc (ArgSize);
  227. Args^ [ArgSize] := 0;
  228. end;
  229. RC := DosQueryAppType (PChar (Args), ExecAppType);
  230. if RC <> 0 then
  231. OSErrorWatch (RC)
  232. else
  233. if (ApplicationType and 3 = ExecAppType and 3) then
  234. (* DosExecPgm should work... *)
  235. begin
  236. DSS := false;
  237. Res.ExitCode := $FFFFFFFF;
  238. RC := DosExecPgm (ObjName, cardinal (ExecFlags), Args, nil, Res, Path);
  239. if RC = 0 then
  240. begin
  241. LastExecFlags := ExecFlags;
  242. LastExecRes := Res;
  243. LastDosErrorModuleName := '';
  244. end
  245. else
  246. begin
  247. if (RC = 190) or (RC = 191) then
  248. DSS := true;
  249. OSErrorWatch (RC);
  250. end;
  251. end
  252. else
  253. DSS := true;
  254. if DSS then
  255. begin
  256. Str (GetProcessID, SPID);
  257. Str (ThreadID, STID);
  258. QName := '\QUEUES\FPC_Dos_Exec_p' + SPID + 't' + STID + '.QUE'#0;
  259. FillChar (SD, SizeOf (SD), 0);
  260. SD.Length := SizeOf (SD);
  261. RC := 0;
  262. case ExecFlags of
  263. deSync:
  264. begin
  265. SD.Related := ssf_Related_Child;
  266. LastExecFlags := ExecFlags;
  267. SD.TermQ := @QName [1];
  268. RC := DosCreateQueue (HQ, quFIFO or quConvert_Address, @QName [1]);
  269. if RC <> 0 then
  270. OSErrorWatch (RC);
  271. end;
  272. deAsync,
  273. deAsyncResult:
  274. begin
  275. (* Current implementation of DosExitCode does not support retrieval *)
  276. (* of result codes for other session types started asynchronously. *)
  277. LastExecFlags := deAsync;
  278. SD.Related := ssf_Related_Independent;
  279. end;
  280. deBackground:
  281. begin
  282. (* Current implementation of DosExitCode does not support retrieval *)
  283. (* of result codes for other session types started asynchronously. *)
  284. LastExecFlags := ExecFlags;
  285. SD.Related := ssf_Related_Independent;
  286. SD.FgBg := ssf_FgBg_Back;
  287. end;
  288. deAsyncResultDB:
  289. begin
  290. (* Current implementation of DosExitCode does not support retrieval *)
  291. (* of result codes for other session types started asynchronously. *)
  292. LastExecFlags := ExecFlags;
  293. SD.Related := ssf_Related_Child;
  294. SD.TraceOpt := ssf_TraceOpt_Trace;
  295. end;
  296. end;
  297. if RC <> 0 then
  298. ObjName := Copy (QName, 1, Pred (Length (QName)))
  299. else
  300. begin
  301. if Args = nil then
  302. (* No parameters passed, Args not allocated for DosExecPgm, so allocate now. *)
  303. begin
  304. GetMem (Args0, MaxArgsSize);
  305. Args := Args0;
  306. Move (QName [1], Args^ [0], Length (QName));
  307. Args^ [Length (QName)] := 0;
  308. end
  309. else
  310. SD.PgmInputs := PChar (@Args^ [Length (QName) + 1]);
  311. SD.PgmName := PChar (Args);
  312. SD.InheritOpt := ssf_InhertOpt_Parent;
  313. SD.ObjectBuffer := @ObjName [1];
  314. SD.ObjectBuffLen := SizeOf (ObjName) - 1;
  315. RC := DosStartSession (SD, SID, PID);
  316. if RC <> 0 then
  317. OSErrorWatch (RC);
  318. if (RC = 0) or (RC = 457) then
  319. begin
  320. LastExecRes.PID := PID;
  321. if ExecFlags = deSync then
  322. begin
  323. RC := DosReadQueue (HQ, RD, CISize, PCI, 0, 0, Prio, 0);
  324. if RC <> 0 then
  325. OSErrorWatch (RC);
  326. if (RC = 0) and (PCI^.SessionID = SID) then
  327. begin
  328. LastExecRes.ExitCode := PCI^.Return;
  329. RC2 := DosCloseQueue (HQ);
  330. if RC2 <> 0 then
  331. OSErrorWatch (RC2);
  332. RC2 := DosFreeMem (PCI);
  333. if RC2 <> 0 then
  334. OSErrorWatch (RC2);
  335. end
  336. else
  337. begin
  338. RC2 := DosCloseQueue (HQ);
  339. if RC2 <> 0 then
  340. OSErrorWatch (RC2);
  341. end;
  342. end;
  343. end
  344. else if ExecFlags = deSync then
  345. begin
  346. RC2 := DosCloseQueue (HQ);
  347. if RC2 <> 0 then
  348. OSErrorWatch (RC2);
  349. end;
  350. end;
  351. end;
  352. if RC <> 0 then
  353. begin
  354. LastDosErrorModuleName := ObjName;
  355. LastExecFlags := deSync;
  356. LastExecRes.ExitCode := 0; (* Needed for TP/BP compatibility *)
  357. LastExecRes.TerminateReason := $FFFFFFFF;
  358. end;
  359. DosError := RC;
  360. if Args0 <> nil then
  361. FreeMem (Args0, MaxArgsSize);
  362. end;
  363. function DosErrorModuleName: string;
  364. begin
  365. DosErrorModuleName := LastDosErrorModuleName;
  366. end;
  367. function dosversion:word;
  368. {Returns OS/2 version}
  369. var
  370. Minor, Major: Cardinal;
  371. begin
  372. DosQuerySysInfo(svMajorVersion, svMajorVersion, Major, 4);
  373. DosQuerySysInfo(svMinorVersion, svMinorVersion, Minor, 4);
  374. DosVersion:=Major or Minor shl 8;
  375. end;
  376. procedure GetDate (var Year, Month, MDay, WDay: word);
  377. Var
  378. dt: TDateTime;
  379. begin
  380. DosGetDateTime(dt);
  381. Year:=dt.year;
  382. Month:=dt.month;
  383. MDay:=dt.Day;
  384. WDay:=dt.Weekday;
  385. end;
  386. procedure SetDate (Year, Month, Day: word);
  387. var
  388. DT: TDateTime;
  389. RC: cardinal;
  390. begin
  391. DosGetDateTime (DT);
  392. DT.Year := Year;
  393. DT.Month := byte (Month);
  394. DT.Day := byte (Day);
  395. RC := DosSetDateTime (DT);
  396. if RC <> 0 then
  397. OSErrorWatch (RC);
  398. end;
  399. procedure GetTime (var Hour, Minute, Second, Sec100: word);
  400. var
  401. dt: TDateTime;
  402. begin
  403. DosGetDateTime(dt);
  404. Hour:=dt.Hour;
  405. Minute:=dt.Minute;
  406. Second:=dt.Second;
  407. Sec100:=dt.Hundredths;
  408. end;
  409. procedure SetTime (Hour, Minute, Second, Sec100: word);
  410. var
  411. DT: TDateTime;
  412. RC: cardinal;
  413. begin
  414. DosGetDateTime (DT);
  415. DT.Hour := byte (Hour);
  416. DT.Minute := byte (Minute);
  417. DT.Second := byte (Second);
  418. DT.Sec100 := byte (Sec100);
  419. RC := DosSetDateTime (DT);
  420. if RC <> 0 then
  421. OSErrorWatch (RC);
  422. end;
  423. function DiskFree (Drive: byte): int64;
  424. var FI: TFSinfo;
  425. RC: cardinal;
  426. begin
  427. {In OS/2, we use the filesystem information.}
  428. RC := DosQueryFSInfo (Drive, 1, FI, SizeOf (FI));
  429. if RC = 0 then
  430. DiskFree := int64 (FI.Free_Clusters) *
  431. int64 (FI.Sectors_Per_Cluster) * int64 (FI.Bytes_Per_Sector)
  432. else
  433. begin
  434. DiskFree := -1;
  435. OSErrorWatch (RC);
  436. end;
  437. end;
  438. function DiskSize (Drive: byte): int64;
  439. var FI: TFSinfo;
  440. RC: cardinal;
  441. begin
  442. RC := DosQueryFSinfo (Drive, 1, FI, SizeOf (FI));
  443. if RC = 0 then
  444. DiskSize := int64 (FI.Total_Clusters) *
  445. int64 (FI.Sectors_Per_Cluster) * int64 (FI.Bytes_Per_Sector)
  446. else
  447. begin
  448. DiskSize := -1;
  449. OSErrorWatch (RC);
  450. end;
  451. end;
  452. procedure DosSearchRec2SearchRec (var F: SearchRec);
  453. type
  454. TRec = record
  455. T, D: word;
  456. end;
  457. begin
  458. with F do
  459. begin
  460. Name := FStat^.Name;
  461. Size := FStat^.FileSize;
  462. Attr := byte(FStat^.AttrFile and $FF);
  463. TRec (Time).T := FStat^.TimeLastWrite;
  464. TRec (Time).D := FStat^.DateLastWrite;
  465. end;
  466. end;
  467. procedure FindFirst (const Path: PathStr; Attr: word; var F: SearchRec);
  468. var Count: cardinal;
  469. begin
  470. {No error.}
  471. DosError := 0;
  472. New (F.FStat);
  473. F.Handle := THandle ($FFFFFFFF);
  474. Count := 1;
  475. DosError := integer (DosFindFirst (Path, F.Handle,
  476. Attr and FindResvdMask, F.FStat, SizeOf (F.FStat^),
  477. Count, ilStandard));
  478. if DosError <> 0 then
  479. OSErrorWatch (DosError)
  480. else if Count = 0 then
  481. DosError := 18;
  482. DosSearchRec2SearchRec (F);
  483. end;
  484. procedure FindNext (var F: SearchRec);
  485. var
  486. Count: cardinal;
  487. begin
  488. {No error}
  489. DosError := 0;
  490. Count := 1;
  491. DosError := integer (DosFindNext (F.Handle, F.FStat, SizeOf (F.FStat^),
  492. Count));
  493. if DosError <> 0 then
  494. OSErrorWatch (DosError)
  495. else if Count = 0 then
  496. DosError := 18;
  497. DosSearchRec2SearchRec (F);
  498. end;
  499. procedure FindClose (var F: SearchRec);
  500. begin
  501. if F.Handle <> THandle ($FFFFFFFF) then
  502. begin
  503. DosError := integer (DosFindClose (F.Handle));
  504. if DosError <> 0 then
  505. OSErrorWatch (DosError);
  506. end;
  507. Dispose (F.FStat);
  508. end;
  509. function envcount:longint;
  510. begin
  511. envcount:=envc;
  512. end;
  513. function envstr (index : longint) : string;
  514. var hp:Pchar;
  515. begin
  516. if (index<=0) or (index>envcount) then
  517. begin
  518. envstr:='';
  519. exit;
  520. end;
  521. hp:=EnvP[index-1];
  522. envstr:=strpas(hp);
  523. end;
  524. function GetEnvPChar (EnvVar: string): PChar;
  525. (* The assembler version is more than three times as fast as Pascal. *)
  526. var
  527. P: PChar;
  528. begin
  529. EnvVar := UpCase (EnvVar);
  530. {$ASMMODE INTEL}
  531. asm
  532. cld
  533. mov edi, Environment
  534. lea esi, EnvVar
  535. xor eax, eax
  536. lodsb
  537. @NewVar:
  538. cmp byte ptr [edi], 0
  539. jz @Stop
  540. push eax { eax contains length of searched variable name }
  541. push esi { esi points to the beginning of the variable name }
  542. mov ecx, -1 { our character ('=' - see below) _must_ be found }
  543. mov edx, edi { pointer to beginning of variable name saved in edx }
  544. mov al, '=' { searching until '=' (end of variable name) }
  545. repne
  546. scasb { scan until '=' not found }
  547. neg ecx { what was the name length? }
  548. dec ecx { corrected }
  549. dec ecx { exclude the '=' character }
  550. pop esi { restore pointer to beginning of variable name }
  551. pop eax { restore length of searched variable name }
  552. push eax { and save both of them again for later use }
  553. push esi
  554. cmp ecx, eax { compare length of searched variable name with name }
  555. jnz @NotEqual { ... of currently found variable, jump if different }
  556. xchg edx, edi { pointer to current variable name restored in edi }
  557. repe
  558. cmpsb { compare till the end of variable name }
  559. xchg edx, edi { pointer to beginning of variable contents in edi }
  560. jz @Equal { finish if they're equal }
  561. @NotEqual:
  562. xor eax, eax { look for 00h }
  563. mov ecx, -1 { it _must_ be found }
  564. repne
  565. scasb { scan until found }
  566. pop esi { restore pointer to beginning of variable name }
  567. pop eax { restore length of searched variable name }
  568. jmp @NewVar { ... or continue with new variable otherwise }
  569. @Stop:
  570. xor eax, eax
  571. mov P, eax { Not found - return nil }
  572. jmp @End
  573. @Equal:
  574. pop esi { restore the stack position }
  575. pop eax
  576. mov P, edi { place pointer to variable contents in P }
  577. @End:
  578. end ['eax','ecx','edx','esi','edi'];
  579. GetEnvPChar := P;
  580. end;
  581. {$ASMMODE ATT}
  582. Function GetEnv(envvar: string): string;
  583. (* The assembler version is more than three times as fast as Pascal. *)
  584. begin
  585. GetEnv := StrPas (GetEnvPChar (EnvVar));
  586. end;
  587. procedure GetFAttr (var F; var Attr: word);
  588. var
  589. PathInfo: TFileStatus3;
  590. RC: cardinal;
  591. {$ifndef FPC_ANSI_TEXTFILEREC}
  592. R: rawbytestring;
  593. {$endif not FPC_ANSI_TEXTFILEREC}
  594. P: pchar;
  595. begin
  596. Attr := 0;
  597. {$ifdef FPC_ANSI_TEXTFILEREC}
  598. P := @FileRec (F).Name;
  599. {$else FPC_ANSI_TEXTFILEREC}
  600. R := ToSingleByteFileSystemEncodedFileName (FileRec (F).Name);
  601. P := PChar (R);
  602. {$endif FPC_ANSI_TEXTFILEREC}
  603. RC := DosQueryPathInfo (P, ilStandard, @PathInfo, SizeOf (PathInfo));
  604. DosError := integer (RC);
  605. if RC = 0 then
  606. Attr := PathInfo.AttrFile
  607. else
  608. OSErrorWatch (RC);
  609. end;
  610. procedure SetFAttr (var F; Attr: word);
  611. var
  612. PathInfo: TFileStatus3;
  613. RC: cardinal;
  614. {$ifndef FPC_ANSI_TEXTFILEREC}
  615. R: rawbytestring;
  616. {$endif not FPC_ANSI_TEXTFILEREC}
  617. P: pchar;
  618. begin
  619. {$ifdef FPC_ANSI_TEXTFILEREC}
  620. P := @FileRec (F).Name;
  621. {$else FPC_ANSI_TEXTFILEREC}
  622. R := ToSingleByteFileSystemEncodedFileName (FileRec (F).Name);
  623. P := PChar (R);
  624. {$endif FPC_ANSI_TEXTFILEREC}
  625. RC := DosQueryPathInfo (P, ilStandard, @PathInfo, SizeOf (PathInfo));
  626. if RC = 0 then
  627. begin
  628. PathInfo.AttrFile := Attr;
  629. RC := DosSetPathInfo (P, ilStandard, @PathInfo, SizeOf (PathInfo),
  630. doWriteThru);
  631. if RC <> 0 then
  632. OSErrorWatch (RC);
  633. end
  634. else
  635. OSErrorWatch (RC);
  636. DosError := integer (RC);
  637. end;
  638. {function GetShortName(var p : String) : boolean;
  639. begin
  640. GetShortName:=true;}
  641. {$WARNING EA .shortname support (see FAT32 driver) should be probably added here!}
  642. {end;
  643. function GetLongName(var p : String) : boolean;
  644. begin
  645. GetLongName:=true;}
  646. {$WARNING EA .longname support should be probably added here!}
  647. {end;}
  648. begin
  649. FillChar (LastExecRes, SizeOf (LastExecRes), 0);
  650. LastDosErrorModuleName := '';
  651. ExecFlags := 0;
  652. LastExecFlags := deSync;
  653. end.