|
@@ -70,26 +70,32 @@ End;
|
|
|
// !! In the libc versions, the alt code is already integrated in the libc code.
|
|
|
// !! Also significantly boosted buffersize. This will make failure of the
|
|
|
// !! dos legacy api's better visibile due to cut-off path, instead of "empty"
|
|
|
-procedure getdir(drivenr : byte;var dir : shortstring);
|
|
|
+
|
|
|
+
|
|
|
+procedure do_getdir(drivenr : byte;var dir : rawbytestring);
|
|
|
var
|
|
|
buf : array[0..2047] of char;
|
|
|
+{$ifndef FPC_USE_LIBC}
|
|
|
cwdinfo : stat;
|
|
|
rootinfo : stat;
|
|
|
- thedir,dummy : string[255];
|
|
|
+ thedir,dummy : rawbytestring;
|
|
|
dirstream : pdir;
|
|
|
d : pdirent;
|
|
|
- name : string[255];
|
|
|
thisdir : stat;
|
|
|
- tmp : string[255];
|
|
|
-
|
|
|
+ tmp : rawbytestring;
|
|
|
+{$endif FPC_USE_LIBC}
|
|
|
begin
|
|
|
dir:='';
|
|
|
if Fpgetcwd(@buf[0],sizeof(buf))<>nil then
|
|
|
- dir:=strpas(buf)
|
|
|
+ begin
|
|
|
+ dir:=buf;
|
|
|
+ { the returned result by the OS is in the DefaultFileSystemCodePage ->
|
|
|
+ no conversion }
|
|
|
+ setcodepage(dir,DefaultFileSystemCodePage,false);
|
|
|
+ end
|
|
|
{$ifndef FPC_USE_LIBC}
|
|
|
else
|
|
|
begin
|
|
|
- thedir:='';
|
|
|
dummy:='';
|
|
|
|
|
|
{ get root directory information }
|
|
@@ -108,12 +114,12 @@ begin
|
|
|
if dirstream=nil then
|
|
|
exit;
|
|
|
repeat
|
|
|
- name:='';
|
|
|
+ thedir:='';
|
|
|
d:=Fpreaddir(dirstream);
|
|
|
{ no more entries to read ... }
|
|
|
if not assigned(d) then
|
|
|
break;
|
|
|
- tmp:=dummy+'../'+strpas(d^.d_name) + #0;
|
|
|
+ tmp:=dummy+'../'+d^.d_name + #0;
|
|
|
if (Fpstat(@tmp[1],thisdir)=0) then
|
|
|
begin
|
|
|
{ found the entry for this directory name }
|
|
@@ -123,20 +129,32 @@ begin
|
|
|
{ then do not set the name. }
|
|
|
if (not ((d^.d_name[0]='.') and ((d^.d_name[1]=#0) or
|
|
|
((d^.d_name[1]='.') and (d^.d_name[2]=#0))))) then
|
|
|
- name:='/'+strpas(d^.d_name);
|
|
|
+ { d^.d_name is an array[0..x] of char -> will be assigned the
|
|
|
+ ansi code page on conversion to ansistring -> also typecast
|
|
|
+ '/' to ansistring rather than rawbytestring so code pages match
|
|
|
+ (will be unconditionally set to DefaultFileSystemCodePage at
|
|
|
+ the end without conversion) }
|
|
|
+ thedir:=ansistring('/')+d^.d_name;
|
|
|
end;
|
|
|
end;
|
|
|
- until (name<>'');
|
|
|
+ until (thedir<>'');
|
|
|
if Fpclosedir(dirstream)<0 then
|
|
|
Exit;
|
|
|
- thedir:=name+thedir;
|
|
|
dummy:=dummy+'../';
|
|
|
if ((cwdinfo.st_dev=rootinfo.st_dev) and (cwdinfo.st_ino=rootinfo.st_ino)) then
|
|
|
begin
|
|
|
if thedir='' then
|
|
|
dir:='/'
|
|
|
else
|
|
|
- dir:=thedir;
|
|
|
+ begin
|
|
|
+ dir:=thedir;
|
|
|
+ { try to ensure that "dir" has a refcount of 1, so that setcodepage
|
|
|
+ doesn't have to create a deep copy }
|
|
|
+ thedir:='';
|
|
|
+ end;
|
|
|
+ { the returned result by the OS is in the DefaultFileSystemCodePage ->
|
|
|
+ no conversion }
|
|
|
+ setcodepage(dir,DefaultFileSystemCodePage,false);
|
|
|
exit;
|
|
|
end;
|
|
|
until false;
|