Re: [AD] al_make_recursive_directory

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Fri, 2010-10-22 at 09:32 +1100, Peter Wang wrote:
> 
> Any reason not to just extend al_make_directory?
> 

Hm, thinking about it, that's the most useful behavior as it's very
unlikely you want the function to fail if the parent doesn't exist. The
attached patch changes is accordingly.

-- 
Elias Pschernig <elias.pschernig@xxxxxxxxxx>
diff --git a/src/fshook.c b/src/fshook.c
index 8100dd1..d889a76 100644
--- a/src/fshook.c
+++ b/src/fshook.c
@@ -190,10 +190,24 @@ bool al_change_directory(const char *path)
 bool al_make_directory(const char *path)
 {
    const ALLEGRO_FS_INTERFACE *vt = al_get_fs_interface();
+   ALLEGRO_PATH *path1, *path2;
+   int i, n;
+   bool success;
+
    ASSERT(path);
    ASSERT(vt->fs_make_directory);
 
-   return vt->fs_make_directory(path);
+   path1 = al_create_path(path);
+   path2 = al_create_path(NULL);
+   n = al_get_path_num_components(path1);
+   for (i = 0; i < n; i++) {
+      al_path_append_component(path2, al_path_get_component(path1, i));
+      success = vt->fs_make_directory(al_path_cstr(path2);
+      if (!success) break;
+   }
+   al_destroy_path(path1);
+   al_destroy_path(path2);
+   return success;
 }
 
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/