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
|
{
This file is part of the Free Pascal run time library.
Copyright (c) 1999-2014 by Florian Klaempfl
and other members of the Free Pascal development team.
FPC Pascal system unit for OS/2.
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.
**********************************************************************}
{*****************************************************************************
Directory Handling
*****************************************************************************}
Procedure do_MkDir(s: rawbytestring);
var
Rc : word;
begin
DoDirSeparators(s);
Rc := DosCreateDir(pchar(s),nil);
if Rc <> 0 then
begin
InOutRes := Rc;
Errno2Inoutres;
OSErrorWatch (RC);
end;
end;
Procedure do_RmDir(s: rawbytestring);
var
Rc : word;
begin
if s = '.' then
begin
InOutRes := 16;
exit;
end;
DoDirSeparators(s);
Rc := DosDeleteDir(pchar(s));
if Rc <> 0 then
begin
InOutRes := Rc;
Errno2Inoutres;
OSErrorWatch (RC);
end;
end;
{$ASMMODE INTEL}
Procedure do_ChDir(s: rawbytestring);
var RC: cardinal;
Len: Longint;
begin
Len := Length (S);
if (Len >= 2) and (S[2] = ':') then
begin
RC := DosSetDefaultDisk ((Ord (S [1]) and not ($20)) - $40);
if RC <> 0 then
begin
InOutRes := RC;
OSErrorWatch (RC);
end
else
if Len > 2 then
begin
DoDirSeparators (s);
if (S [Len] = DirectorySeparator) and (Len <> 3) then
S [Len] := #0;
RC := DosSetCurrentDir (pchar (s));
if RC <> 0 then
begin
InOutRes := RC;
Errno2InOutRes;
OSErrorWatch (RC);
end;
end;
end else begin
DoDirSeparators (s);
if (Len > 1) and (S [Len] = DirectorySeparator) then
S [Len] := #0;
RC := DosSetCurrentDir (pchar (s));
if RC <> 0 then
begin
InOutRes:= RC;
Errno2InOutRes;
OSErrorWatch (RC);
end;
end;
end;
{$ASMMODE ATT}
procedure do_GetDir (DriveNr: byte; var Dir: RawByteString);
{Written by Michael Van Canneyt.}
var sof: Pchar;
i:byte;
l,l2:cardinal;
RC: cardinal;
begin
setlength(Dir,255);
Dir [4] := #0;
{ Used in case the specified drive isn't available }
sof:=pchar(@dir[4]);
{ dir[1..3] will contain '[drivenr]:\', but is not }
{ supplied by DOS, so we let dos string start at }
{ dir[4] }
{ Get dir from drivenr : 0=default, 1=A etc... }
{ TODO: if max path length is > 255, increase the setlength parameter above and
the 255 below }
l:=255-3;
RC := DosQueryCurrentDir(DriveNr, sof^, l);
if RC <> 0 then
begin
InOutRes := longint (RC);
Errno2Inoutres;
OSErrorWatch (RC);
end;
{$WARNING Result code should be translated in some cases!}
{ Now Dir should be filled with directory in ASCIIZ, }
{ starting from dir[4] }
dir[2]:=':';
dir[3]:='\';
i:=4;
{Conversion to Pascal string }
while (dir[i]<>#0) do
begin
{ convert path name to DOS }
if dir[i] in AllowDirectorySeparators then
dir[i]:=DirectorySeparator;
inc(i);
end;
setlength(dir,i-1);
{ upcase the string (FPC function) }
if drivenr<>0 then { Drive was supplied. We know it }
dir[1]:=chr(64+drivenr)
else
begin
{ We need to get the current drive from DOS function 19H }
{ because the drive was the default, which can be unknown }
DosQueryCurrentDisk(l, l2);
dir[1]:=chr(64+l);
end;
SetCodePage(dir,DefaultFileSystemCodePage,false);
if not (FileNameCasePreserving) then dir:=upcase(dir);
end;
|