summaryrefslogtreecommitdiff
path: root/rtl/os2/dos.pas
blob: c89898c743089d44f7a75d0d79c41964ce98f094 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
{****************************************************************************


                         Free Pascal Runtime-Library
                              DOS unit for OS/2
                   Copyright (c) 1997,1999-2000 by Daniel Mantione,
                   member of the Free Pascal development team

    See the file COPYING.FPC, included in this distribution,
    for details about the copyright.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 ****************************************************************************}

unit dos;

{$ASMMODE ATT}

{***************************************************************************}

interface

{***************************************************************************}

{$PACKRECORDS 1}

uses    Strings, DosCalls;

Type
   {Search record which is used by findfirst and findnext:}
   SearchRec = record
            case boolean of
             false: (Handle: THandle;     {Used in os_OS2 mode}
                     FStat: PFileFindBuf3;
                     Fill: array [1..21 - SizeOf (THandle) - SizeOf (pointer)]
                                                                       of byte;
                     Attr: byte;
                     Time: longint;
                     Size: longint;
                     Name: string);      {Filenames can be long in OS/2!}
             true:  (Fill2: array [1..21] of byte;
                     Attr2: byte;
                     Time2: longint;
                     Size2: longint;
                     Name2: string);       {Filenames can be long in OS/2!}
        end;

        {Flags for the exec procedure:
        }

threadvar
(* For compatibility with VP/2, used for runflags in Exec procedure. *)
    ExecFlags: cardinal;
(* Note that the TP/BP compatible method for retrieval of exit codes    *)
(* is limited to only one (the last) execution! Including the following *)
(* two variables in the interface part allows querying the status of    *)
(* of asynchronously started programs using DosWaitChild with dtNoWait  *)
(* parameter, i.e. without waiting for the final program result (as     *)
(* opposed to calling DosExitCode which would wait for the exit code).  *)
    LastExecRes: TResultCodes;
    LastExecFlags: cardinal;

{$i dosh.inc}

{OS/2 specific functions}

function GetEnvPChar (EnvVar: string): PChar;

function DosErrorModuleName: string;
(* In case of an error in Dos.Exec returns the name of the module *)
(* causing the problem - e.g. name of a missing or corrupted DLL. *)
(* It may also contain a queue name in case of a failed attempt *)
(* to create queue for reading results of started sessions.     *)



implementation

{$DEFINE HAS_GETMSCOUNT}
{$DEFINE HAS_DOSEXITCODE}

{$DEFINE FPC_FEXPAND_UNC} (* UNC paths are supported *)
{$DEFINE FPC_FEXPAND_DRIVES} (* Full paths begin with drive specification *)
{$DEFINE FPC_FEXPAND_GETENV_PCHAR}

{$I dos.inc}

threadvar
  LastDosErrorModuleName: string;


const   FindResvdMask = $00003737; {Allowed bits in attribute
                                    specification for DosFindFirst call.}


function GetMsCount: int64;
var
  L: cardinal;
begin
  DosQuerySysInfo (svMsCount, svMsCount, L, 4);
  GetMsCount := L;
end;


function FSearch (Path: PathStr; DirList: string): PathStr;
var
  i,p1   : longint;
  s      : searchrec;
  newdir : pathstr;
begin
{ check if the file specified exists }
  findfirst(path,anyfile and not(directory),s);
  if doserror=0 then
   begin
     findclose(s);
     fsearch:=path;
     exit;
   end;
{ No wildcards allowed in these things }
  if (pos('?',path)<>0) or (pos('*',path)<>0) then
    fsearch:=''
  else
    begin
       { allow slash as backslash }
       DoDirSeparators(dirlist);
       repeat
         p1:=pos(';',dirlist);
         if p1<>0 then
          begin
            newdir:=copy(dirlist,1,p1-1);
            delete(dirlist,1,p1);
          end
         else
          begin
            newdir:=dirlist;
            dirlist:='';
          end;
         if (newdir<>'') and (not (newdir[length(newdir)] in ['\',':'])) then
          newdir:=newdir+'\';
         findfirst(newdir+path,anyfile and not(directory),s);
         if doserror=0 then
          newdir:=newdir+path
         else
          newdir:='';
       until (dirlist='') or (newdir<>'');
       fsearch:=newdir;
    end;
  findclose(s);
end;


procedure getftime(var f;var time:longint);
var
  FStat: TFileStatus3;
begin
  DosError := DosQueryFileInfo (FileRec (F).Handle, ilStandard, @FStat,
                                                               SizeOf (FStat));
  if DosError=0 then
   begin
    Time := FStat.TimeLastWrite + longint (FStat.DateLastWrite) shl 16;
    if Time = 0 then
      Time := FStat.TimeCreation + longint (FStat.DateCreation) shl 16;
   end
  else
   begin
    Time:=0;
    OSErrorWatch (DosError);
    if DosError = 87 then
     DosError := 6; (* Align to TP/BP behaviour *)
   end;
end;


procedure SetFTime (var F; Time: longint);
var FStat: TFileStatus3;
    RC: cardinal;
begin
  RC := DosQueryFileInfo (FileRec (F).Handle, ilStandard, @FStat,
                                                               SizeOf (FStat));
  if RC = 0 then
   begin
    FStat.DateLastAccess := Hi (Time);
    FStat.DateLastWrite := Hi (Time);
    FStat.TimeLastAccess := Lo (Time);
    FStat.TimeLastWrite := Lo (Time);
    RC := DosSetFileInfo (FileRec (F).Handle, ilStandard, @FStat,
                                                               SizeOf (FStat));
    if RC <> 0 then
     OSErrorWatch (RC);
   end
  else
   begin
    OSErrorWatch (RC);
    if RC = 87 then
     RC := 6;
   end;
  DosError := integer (RC);
end;


function DosExitCode: word;
var
  Res: TResultCodes;
  PPID: cardinal;
  RC: cardinal;
begin
  if (LastExecFlags = deAsyncResult) or (LastExecFlags = deAsyncResultDb) then
   begin
    RC := DosWaitChild (DCWA_PROCESS, dtWait, Res, PPID, LastExecRes.PID);
    if RC = 0 then
(* If we succeeded, the process is finished - possible future querying
   of DosExitCode shall return the result immediately as with synchronous
   execution. *)
     begin
      LastExecFlags := deSync;
      LastExecRes := Res;
     end
    else
     begin
      LastExecRes.ExitCode := RC shl 16;
      OSErrorWatch (RC);
     end;
   end;
  if LastExecRes.ExitCode > high (word) then
    DosExitCode := high (word)
  else
    DosExitCode := LastExecRes.ExitCode and $FFFF;
end;


procedure Exec (const Path: PathStr; const ComLine: ComStr);
{Execute a program.}
var
  Args0, Args: PByteArray;
  ArgSize: word;
  ObjName: string;
  Res: TResultCodes;
  RC, RC2: cardinal;
  ExecAppType: cardinal;
  HQ: THandle;
  SPID, STID, QName: string;
  SID, PID: cardinal;
  SD: TStartData;
  RD: TRequestData;
  PCI: PChildInfo;
  CISize: cardinal;
  Prio: byte;
  DSS: boolean;
  SR: SearchRec;
  MaxArgsSize: PtrUInt; (* Amount of memory reserved for arguments in bytes. *)
  MaxArgsSizeInc: word;
  PathZ: array [0..255] of char;

begin
{  LastDosExitCode := Exec (Path, ExecRunFlags (ExecFlags), efDefault, ComLine);}
  ObjName := '';
(* FExpand should be used only for the DosStartSession part
   and only if the executable is in the current directory.  *)
  FindFirst (Path, AnyFile, SR);
  if DosError = 0 then
   QName := FExpand (Path)
  else
   QName := Path;
  FindClose (SR);
  MaxArgsSize := Length (ComLine) + Length (QName) + 256; (* More than enough *)
  if MaxArgsSize > high (word) then
   begin
    DosError := 8; (* Not quite, but "not enough memory" is close enough *)
    Exit;
   end;
  if ComLine = '' then
   begin
    Args0 := nil;
    Args := nil;
    StrPCopy (PathZ, Path);
    RC := DosQueryAppType (@PathZ [0], ExecAppType);
   end
  else
   begin
    GetMem (Args0, MaxArgsSize);
    Args := Args0;
(* Work around a bug in OS/2 - argument to DosExecPgm *)
(* should not cross a 64K boundary. *)
    while ((PtrUInt (Args) + MaxArgsSize) and $FFFF) < MaxArgsSize do
     begin
      MaxArgsSizeInc := MaxArgsSize -
                                    ((PtrUInt (Args) + MaxArgsSize) and $FFFF);
      Inc (MaxArgsSize, MaxArgsSizeInc);
      if MaxArgsSize > high (word) then
       begin
        DosError := 8; (* Not quite, but "not enough memory" is close enough *)
        Exit;
       end;
      ReallocMem (Args0, MaxArgsSize);
      Inc (pointer (Args), MaxArgsSizeInc);
     end;
    ArgSize := 0;
    Move (QName [1], Args^ [ArgSize], Length (QName));
    Inc (ArgSize, Length (QName));
    Args^ [ArgSize] := 0;
    Inc (ArgSize);
    {Now do the real arguments.}
    Move (ComLine [1], Args^ [ArgSize], Length (ComLine));
    Inc (ArgSize, Length (ComLine));
    Args^ [ArgSize] := 0;
    Inc (ArgSize);
    Args^ [ArgSize] := 0;
    RC := DosQueryAppType (PChar (Args), ExecAppType);
   end;

  if RC <> 0 then
   OSErrorWatch (RC)
  else
   if (ApplicationType and 3 = ExecAppType and 3) then
(* DosExecPgm should work... *)
    begin
     DSS := false;
     Res.ExitCode := $FFFFFFFF;
     RC := DosExecPgm (ObjName, cardinal (ExecFlags), Args, nil, Res, Path);
     if RC = 0 then
      begin
       LastExecFlags := ExecFlags;
       LastExecRes := Res;
       LastDosErrorModuleName := '';
      end
     else
      begin
       if (RC = 190) or (RC = 191) then
        DSS := true;
       OSErrorWatch (RC);
      end;
   end
  else
   DSS := true;
  if DSS then
   begin
    Str (GetProcessID, SPID);
    Str (ThreadID, STID);
    QName := '\QUEUES\FPC_Dos_Exec_p' + SPID + 't' + STID + '.QUE'#0;
    FillChar (SD, SizeOf (SD), 0);
    SD.Length := SizeOf (SD);
    RC := 0;
    case ExecFlags of
     deSync:
      begin
       SD.Related := ssf_Related_Child;
       LastExecFlags := ExecFlags;
       SD.TermQ := @QName [1];
       RC := DosCreateQueue (HQ, quFIFO or quConvert_Address, @QName [1]);
       if RC <> 0 then
        OSErrorWatch (RC);
      end;
     deAsync,
     deAsyncResult:
      begin
(* Current implementation of DosExitCode does not support retrieval *)
(* of result codes for other session types started asynchronously.  *)
       LastExecFlags := deAsync;
       SD.Related := ssf_Related_Independent;
      end;
     deBackground:
      begin
(* Current implementation of DosExitCode does not support retrieval *)
(* of result codes for other session types started asynchronously.  *)
       LastExecFlags := ExecFlags;
       SD.Related := ssf_Related_Independent;
       SD.FgBg := ssf_FgBg_Back;
      end;
     deAsyncResultDB:
      begin
(* Current implementation of DosExitCode does not support retrieval *)
(* of result codes for other session types started asynchronously.  *)
       LastExecFlags := ExecFlags;
       SD.Related := ssf_Related_Child;
       SD.TraceOpt := ssf_TraceOpt_Trace;
      end;
    end;
    if RC <> 0 then
     ObjName := Copy (QName, 1, Pred (Length (QName)))
    else
     begin
      if Args = nil then
(* No parameters passed, Args not allocated for DosExecPgm, so allocate now. *)
       begin
        GetMem (Args0, MaxArgsSize);
        Args := Args0;
        Move (QName [1], Args^ [0], Length (QName));
        Args^ [Length (QName)] := 0;
       end
      else
       SD.PgmInputs := PChar (@Args^ [Length (QName) + 1]);
      SD.PgmName := PChar (Args);
      SD.InheritOpt := ssf_InhertOpt_Parent;
      SD.ObjectBuffer := @ObjName [1];
      SD.ObjectBuffLen := SizeOf (ObjName) - 1;
      RC := DosStartSession (SD, SID, PID);
      if RC <> 0 then
       OSErrorWatch (RC);
      if (RC = 0) or (RC = 457) then
       begin
        LastExecRes.PID := PID;
        if ExecFlags = deSync then
         begin
          RC := DosReadQueue (HQ, RD, CISize, PCI, 0, 0, Prio, 0);
          if RC <> 0 then
           OSErrorWatch (RC);
          if (RC = 0) and (PCI^.SessionID = SID) then
           begin
            LastExecRes.ExitCode := PCI^.Return;
            RC2 := DosCloseQueue (HQ);
            if RC2 <> 0 then
             OSErrorWatch (RC2);
            RC2 := DosFreeMem (PCI);
            if RC2 <> 0 then
             OSErrorWatch (RC2);
           end
          else
           begin
            RC2 := DosCloseQueue (HQ);
            if RC2 <> 0 then
             OSErrorWatch (RC2);
           end;
         end;
       end
      else if ExecFlags = deSync then
       begin
        RC2 := DosCloseQueue (HQ);
        if RC2 <> 0 then
         OSErrorWatch (RC2);
       end;
     end;
   end;
  if RC <> 0 then
   begin
    LastDosErrorModuleName := ObjName;
    LastExecFlags := deSync;
    LastExecRes.ExitCode := 0; (* Needed for TP/BP compatibility *)
    LastExecRes.TerminateReason := $FFFFFFFF;
   end;
  DosError := RC;
  if Args0 <> nil then
   FreeMem (Args0, MaxArgsSize);
end;


function DosErrorModuleName: string;
begin
  DosErrorModuleName := LastDosErrorModuleName;
end;


function dosversion:word;
{Returns OS/2 version}
var
  Minor, Major: Cardinal;
begin
  DosQuerySysInfo(svMajorVersion, svMajorVersion, Major, 4);
  DosQuerySysInfo(svMinorVersion, svMinorVersion, Minor, 4);
  DosVersion:=Major or Minor shl 8;
end;


procedure GetDate (var Year, Month, MDay, WDay: word);
Var
  dt: TDateTime;
begin
  DosGetDateTime(dt);
  Year:=dt.year;
  Month:=dt.month;
  MDay:=dt.Day;
  WDay:=dt.Weekday;
end;


procedure SetDate (Year, Month, Day: word);
var
  DT: TDateTime;
  RC: cardinal;
begin
  DosGetDateTime (DT);
  DT.Year := Year;
  DT.Month := byte (Month);
  DT.Day := byte (Day);
  RC := DosSetDateTime (DT);
  if RC <> 0 then
   OSErrorWatch (RC);
end;


procedure GetTime (var Hour, Minute, Second, Sec100: word);
var
  dt: TDateTime;
begin
  DosGetDateTime(dt);
  Hour:=dt.Hour;
  Minute:=dt.Minute;
  Second:=dt.Second;
  Sec100:=dt.Hundredths;
end;


procedure SetTime (Hour, Minute, Second, Sec100: word);
var
  DT: TDateTime;
  RC: cardinal;
begin
  DosGetDateTime (DT);
  DT.Hour := byte (Hour);
  DT.Minute := byte (Minute);
  DT.Second := byte (Second);
  DT.Sec100 := byte (Sec100);
  RC := DosSetDateTime (DT);
  if RC <> 0 then
   OSErrorWatch (RC);
end;

function DiskFree (Drive: byte): int64;
var FI: TFSinfo;
    RC: cardinal;
begin
  {In OS/2, we use the filesystem information.}
  RC := DosQueryFSInfo (Drive, 1, FI, SizeOf (FI));
  if RC = 0 then
      DiskFree := int64 (FI.Free_Clusters) *
         int64 (FI.Sectors_Per_Cluster) * int64 (FI.Bytes_Per_Sector)
  else
   begin
    DiskFree := -1;
    OSErrorWatch (RC);
   end;
end;


function DiskSize (Drive: byte): int64;
var FI: TFSinfo;
    RC: cardinal;
begin
  RC := DosQueryFSinfo (Drive, 1, FI, SizeOf (FI));
  if RC = 0 then
      DiskSize := int64 (FI.Total_Clusters) *
         int64 (FI.Sectors_Per_Cluster) * int64 (FI.Bytes_Per_Sector)
  else
   begin
    DiskSize := -1;
    OSErrorWatch (RC);
   end;
end;


procedure DosSearchRec2SearchRec (var F: SearchRec);
type
  TRec = record
    T, D: word;
  end;
begin
 with F do
    begin
        Name := FStat^.Name;
        Size := FStat^.FileSize;
        Attr := byte(FStat^.AttrFile and $FF);
        TRec (Time).T := FStat^.TimeLastWrite;
        TRec (Time).D := FStat^.DateLastWrite;
    end;
end;


procedure FindFirst (const Path: PathStr; Attr: word; var F: SearchRec);


var Count: cardinal;

begin
  {No error.}
  DosError := 0;
  New (F.FStat);
  F.Handle := THandle ($FFFFFFFF);
  Count := 1;
  DosError := integer (DosFindFirst (Path, F.Handle,
                     Attr and FindResvdMask, F.FStat, SizeOf (F.FStat^),
                                                           Count, ilStandard));
  if DosError <> 0 then
   OSErrorWatch (DosError)
  else if Count = 0 then
   DosError := 18;
  DosSearchRec2SearchRec (F);
end;


procedure FindNext (var F: SearchRec);
var
  Count: cardinal;
begin
    {No error}
    DosError := 0;
    Count := 1;
    DosError := integer (DosFindNext (F.Handle, F.FStat, SizeOf (F.FStat^),
                                                                       Count));
    if DosError <> 0 then
     OSErrorWatch (DosError)
    else if Count = 0 then
     DosError := 18;
    DosSearchRec2SearchRec (F);
end;


procedure FindClose (var F: SearchRec);
begin
  if F.Handle <> THandle ($FFFFFFFF) then
   begin
    DosError := integer (DosFindClose (F.Handle));
    if DosError <> 0 then
     OSErrorWatch (DosError);
   end;
  Dispose (F.FStat);
end;


function envcount:longint;
begin
  envcount:=envc;
end;


function envstr (index : longint) : string;

var hp:Pchar;

begin
    if (index<=0) or (index>envcount) then
        begin
            envstr:='';
            exit;
        end;
    hp:=EnvP[index-1];
    envstr:=strpas(hp);
end;


function GetEnvPChar (EnvVar: string): PChar;
(* The assembler version is more than three times as fast as Pascal. *)
var
 P: PChar;
begin
 EnvVar := UpCase (EnvVar);
{$ASMMODE INTEL}
 asm
  cld
  mov edi, Environment
  lea esi, EnvVar
  xor eax, eax
  lodsb
@NewVar:
  cmp byte ptr [edi], 0
  jz @Stop
  push eax        { eax contains length of searched variable name }
  push esi        { esi points to the beginning of the variable name }
  mov ecx, -1     { our character ('=' - see below) _must_ be found }
  mov edx, edi    { pointer to beginning of variable name saved in edx }
  mov al, '='     { searching until '=' (end of variable name) }
  repne
  scasb           { scan until '=' not found }
  neg ecx         { what was the name length? }
  dec ecx         { corrected }
  dec ecx         { exclude the '=' character }
  pop esi         { restore pointer to beginning of variable name }
  pop eax         { restore length of searched variable name }
  push eax        { and save both of them again for later use }
  push esi
  cmp ecx, eax    { compare length of searched variable name with name }
  jnz @NotEqual   { ... of currently found variable, jump if different }
  xchg edx, edi   { pointer to current variable name restored in edi }
  repe
  cmpsb           { compare till the end of variable name }
  xchg edx, edi   { pointer to beginning of variable contents in edi }
  jz @Equal       { finish if they're equal }
@NotEqual:
  xor eax, eax    { look for 00h }
  mov ecx, -1     { it _must_ be found }
  repne
  scasb           { scan until found }
  pop esi         { restore pointer to beginning of variable name }
  pop eax         { restore length of searched variable name }
  jmp @NewVar     { ... or continue with new variable otherwise }
@Stop:
  xor eax, eax
  mov P, eax      { Not found - return nil }
  jmp @End
@Equal:
  pop esi         { restore the stack position }
  pop eax
  mov P, edi      { place pointer to variable contents in P }
@End:
 end ['eax','ecx','edx','esi','edi'];
 GetEnvPChar := P;
end;
{$ASMMODE ATT}


Function GetEnv(envvar: string): string;
(* The assembler version is more than three times as fast as Pascal. *)
begin
 GetEnv := StrPas (GetEnvPChar (EnvVar));
end;


procedure GetFAttr (var F; var Attr: word);
var
  PathInfo: TFileStatus3;
  RC: cardinal;
{$ifndef FPC_ANSI_TEXTFILEREC}
  R: rawbytestring;
{$endif not FPC_ANSI_TEXTFILEREC}
  P: pchar;
begin
  Attr := 0;
{$ifdef FPC_ANSI_TEXTFILEREC}
  P := @FileRec (F).Name;
{$else FPC_ANSI_TEXTFILEREC}
  R := ToSingleByteFileSystemEncodedFileName (FileRec (F).Name);
  P := PChar (R);
{$endif FPC_ANSI_TEXTFILEREC}
  RC := DosQueryPathInfo (P, ilStandard, @PathInfo, SizeOf (PathInfo));
  DosError := integer (RC);
  if RC = 0 then
    Attr := PathInfo.AttrFile
  else
   begin
    OSErrorWatch (RC);
    if FileRec (F).Name [0] = #0 then
     DosError := 3; (* Align the returned error value to TP/BP *)
   end;
end;


procedure SetFAttr (var F; Attr: word);
var
  PathInfo: TFileStatus3;
  RC: cardinal;
{$ifndef FPC_ANSI_TEXTFILEREC}
  R: rawbytestring;
{$endif not FPC_ANSI_TEXTFILEREC}
  P: pchar;
begin
{$ifdef FPC_ANSI_TEXTFILEREC}
  P := @FileRec (F).Name;
{$else FPC_ANSI_TEXTFILEREC}
  R := ToSingleByteFileSystemEncodedFileName (FileRec (F).Name);
  P := PChar (R);
{$endif FPC_ANSI_TEXTFILEREC}
  RC := DosQueryPathInfo (P, ilStandard, @PathInfo, SizeOf (PathInfo));
  if RC = 0 then
   begin
    PathInfo.AttrFile := Attr;
    RC := DosSetPathInfo (P, ilStandard, @PathInfo, SizeOf (PathInfo), 0);
    if RC <> 0 then
     begin
      OSErrorWatch (RC);
      if Attr and VolumeID = VolumeID then
       RC := 5; (* Align the returned error value to TP/BP *)
     end;
   end
  else
   begin
    OSErrorWatch (RC);
    if FileRec (F).Name [0] = #0 then
     RC := 3; (* Align the returned error value to TP/BP *)
   end;
  DosError := integer (RC);
end;


{function  GetShortName(var p : String) : boolean;
begin
  GetShortName:=true;}
{$WARNING EA .shortname support (see FAT32 driver) should be probably added here!}
{end;

function  GetLongName(var p : String) : boolean;
begin
  GetLongName:=true;}
{$WARNING EA .longname support should be probably added here!}
{end;}



begin
 FillChar (LastExecRes, SizeOf (LastExecRes), 0);
 LastDosErrorModuleName := '';
 ExecFlags := 0;
 LastExecFlags := deSync;
end.