Commit 468ee337 by Pascal Obry Committed by Arnaud Charlet

adaint.h, adaint.c (__gnat_rmdir): New routine.

2009-04-16  Pascal Obry  <obry@adacore.com>

	* adaint.h, adaint.c (__gnat_rmdir): New routine.
	Simple wrapper routines used to convert to proper encoding on
	Windows.

	* s-crtl.ads: Use __gnat_rmdir instead of direct call to the C library.

	* g-dirope.adb (Remove_Dir): Fix a bug, the root directory was removed
	twice.

From-SVN: r146176
parent bca17d51
2009-04-16 Pascal Obry <obry@adacore.com> 2009-04-16 Pascal Obry <obry@adacore.com>
* adaint.h, adaint.c (__gnat_rmdir): New routine.
Simple wrapper routines used to convert to proper encoding on
Windows.
* s-crtl.ads: Use __gnat_rmdir instead of direct call to the C library.
* g-dirope.adb (Remove_Dir): Fix a bug, the root directory was removed
twice.
2009-04-16 Pascal Obry <obry@adacore.com>
* s-crtl.ads, s-os_lib.adb: Minor code clean-up. * s-crtl.ads, s-os_lib.adb: Minor code clean-up.
2009-04-16 Thomas Quinot <quinot@adacore.com> 2009-04-16 Thomas Quinot <quinot@adacore.com>
...@@ -70,7 +70,7 @@ package body Ada.Directories is ...@@ -70,7 +70,7 @@ package body Ada.Directories is
type Search_Data is record type Search_Data is record
Is_Valid : Boolean := False; Is_Valid : Boolean := False;
Name : Ada.Strings.Unbounded.Unbounded_String; Name : Unbounded_String;
Pattern : Regexp; Pattern : Regexp;
Filter : Filter_Type; Filter : Filter_Type;
Dir : Dir_Type_Value := No_Dir; Dir : Dir_Type_Value := No_Dir;
...@@ -481,9 +481,7 @@ package body Ada.Directories is ...@@ -481,9 +481,7 @@ package body Ada.Directories is
C_Dir_Name : constant String := Directory & ASCII.NUL; C_Dir_Name : constant String := Directory & ASCII.NUL;
begin begin
rmdir (C_Dir_Name); if rmdir (C_Dir_Name) /= 0 then
if System.OS_Lib.Is_Directory (Directory) then
raise Use_Error with raise Use_Error with
"deletion of directory """ & Directory & """ failed"; "deletion of directory """ & Directory & """ failed";
end if; end if;
...@@ -565,9 +563,7 @@ package body Ada.Directories is ...@@ -565,9 +563,7 @@ package body Ada.Directories is
C_Dir_Name : constant String := Directory & ASCII.NUL; C_Dir_Name : constant String := Directory & ASCII.NUL;
begin begin
rmdir (C_Dir_Name); if rmdir (C_Dir_Name) /= 0 then
if System.OS_Lib.Is_Directory (Directory) then
raise Use_Error with raise Use_Error with
"directory tree rooted at """ & "directory tree rooted at """ &
Directory & """ could not be deleted"; Directory & """ could not be deleted";
......
...@@ -725,6 +725,23 @@ __gnat_chdir (char *path) ...@@ -725,6 +725,23 @@ __gnat_chdir (char *path)
#endif #endif
} }
/* Removing a directory. */
int
__gnat_rmdir (char *path)
{
#if defined (__MINGW32__) && ! defined (__vxworks) && ! defined (CROSS_COMPILE)
{
TCHAR wpath[GNAT_MAX_PATH_LEN];
S2WSU (wpath, path, GNAT_MAX_PATH_LEN);
return _trmdir (wpath);
}
#else
return rmdir (path);
#endif
}
FILE * FILE *
__gnat_fopen (char *path, char *mode, int encoding ATTRIBUTE_UNUSED) __gnat_fopen (char *path, char *mode, int encoding ATTRIBUTE_UNUSED)
{ {
......
...@@ -73,6 +73,7 @@ extern int __gnat_stat (char *, ...@@ -73,6 +73,7 @@ extern int __gnat_stat (char *,
extern int __gnat_unlink (char *); extern int __gnat_unlink (char *);
extern int __gnat_rename (char *, char *); extern int __gnat_rename (char *, char *);
extern int __gnat_chdir (char *); extern int __gnat_chdir (char *);
extern int __gnat_rmdir (char *);
extern FILE *__gnat_fopen (char *, char *, int); extern FILE *__gnat_fopen (char *, char *, int);
extern FILE *__gnat_freopen (char *, char *, FILE *, extern FILE *__gnat_freopen (char *, char *, FILE *,
......
...@@ -739,9 +739,7 @@ package body GNAT.Directory_Operations is ...@@ -739,9 +739,7 @@ package body GNAT.Directory_Operations is
-- Remove the directory only if it is empty -- Remove the directory only if it is empty
if not Recursive then if not Recursive then
rmdir (C_Dir_Name); if rmdir (C_Dir_Name) /= 0 then
if GNAT.OS_Lib.Is_Directory (Dir_Name) then
raise Directory_Error; raise Directory_Error;
end if; end if;
...@@ -764,7 +762,6 @@ package body GNAT.Directory_Operations is ...@@ -764,7 +762,6 @@ package body GNAT.Directory_Operations is
Str (1 .. Last) /= ".." Str (1 .. Last) /= ".."
then then
Remove_Dir (Str (1 .. Last), True); Remove_Dir (Str (1 .. Last), True);
Remove_Dir (Str (1 .. Last));
end if; end if;
else else
......
...@@ -164,8 +164,8 @@ package System.CRTL is ...@@ -164,8 +164,8 @@ package System.CRTL is
procedure rewind (stream : FILEs); procedure rewind (stream : FILEs);
pragma Import (C, rewind, "rewind"); pragma Import (C, rewind, "rewind");
procedure rmdir (dir_name : String); function rmdir (dir_name : String) return int;
pragma Import (C, rmdir, "rmdir"); pragma Import (C, rmdir, "__gnat_rmdir");
function chdir (dir_name : String) return int; function chdir (dir_name : String) return int;
pragma Import (C, chdir, "__gnat_chdir"); pragma Import (C, chdir, "__gnat_chdir");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment