From 4eb74a3c93221f0873c8d2ef2e9c2ec0485b08b5 Mon Sep 17 00:00:00 2001 From: ehofman Date: Sat, 17 Dec 2005 15:06:56 +0000 Subject: [PATCH] Add a function to create aa new directory --- simgear/misc/sg_path.cxx | 20 ++++++++++++++++++++ simgear/misc/sg_path.hxx | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/simgear/misc/sg_path.cxx b/simgear/misc/sg_path.cxx index 54f7138d..dd0b7068 100644 --- a/simgear/misc/sg_path.cxx +++ b/simgear/misc/sg_path.cxx @@ -26,7 +26,10 @@ #include #include +#include #include +#include +#include #include "sg_path.hxx" @@ -183,6 +186,23 @@ bool SGPath::exists() const { } +void SGPath::create_dir( mode_t mode ) { + string_list dirlist = sgPathSplit(dir()); + SGPath dir = dirlist[0]; + int i; + for(i=1; dir.exists() && i < dirlist.size(); i++) { + dir.add(dirlist[i]); + } + for(;i < dirlist.size(); i++) { + string subdir = dirlist[i]; + if ( mkdir( subdir.c_str(), mode) ) { + SG_LOG( SG_IO, SG_ALERT, "Error creating directory: " + dir.str() ); + break; + } + dir.add(subdir); + } +} + string_list sgPathSplit( const string &search_path ) { string tmp = search_path; string_list result; diff --git a/simgear/misc/sg_path.hxx b/simgear/misc/sg_path.hxx index 26302493..2921ac27 100644 --- a/simgear/misc/sg_path.hxx +++ b/simgear/misc/sg_path.hxx @@ -29,6 +29,7 @@ #ifndef _SG_PATH_HXX #define _SG_PATH_HXX +#include #include #include STL_STRING @@ -132,6 +133,11 @@ public: */ bool exists() const; + /** + * Create the designated directory. + */ + void create_dir(mode_t mode); + private: void fix(); -- 2.39.5