dos.pas 19 KB

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