// mkdir.cxx #include "dataset_util/mkdir.h" #include #include #include "dataset_util/FileStatus.h" using std::string; //********************************************************************** // Create directory. int mkdir(string dir) { mode_t mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH; return mkdir(dir.c_str(), mode); } //********************************************************************** // Create directory and parents. int mkfulldir(string dir) { // Find the position of the last / or series of /'s. string::size_type ipos = dir.rfind('/'); if ( ipos != string::npos ) while ( ipos>0 && dir[ipos-1]=='/' ) --ipos; // If there a directory above this one and it does not exist, try to // create it. // Exit with error if it is not there and cannot be created. if ( ipos!=string::npos && ipos>0 ) { string superdir = dir.substr(0, ipos); FileStatus sstat(superdir); if ( ! sstat.exists() ) { mkfulldir(superdir); sstat.update(); } if ( ! sstat.exists() ) return 101; if ( ! sstat.is_directory() ) return 102; if ( ! sstat.is_writeable() ) return 103; } // Create the requested directory. return mkdir(dir); } //**********************************************************************