dir.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) Sergey P. Derevyago, 2008.
00003  *
00004  * Permission to copy, use, modify, sell and distribute this software is granted
00005  * provided this copyright notice appears in all copies.
00006  * This software is provided "as is" without express or implied warranty, and
00007  * with no claim as to its suitability for any purpose.
00008  *
00009  */
00010 
00015 #include <ders/dir.hpp>
00016 #include <ders/file.hpp>
00017 #include <ders/path.hpp>
00018 
00019 namespace ders {  // ::ders
00020 
00021 using namespace std;
00022 
00023 error make_dirs(mem_pool& mp, const ch_rng& dname)
00024 {
00025  vector<path_elmt> vpe;
00026  parse_path(mp, dname, vpe);
00027 
00028  int i=0, end=vpe.size();
00029  for ( ; ; i++) {
00030      if (i>=end) return einval;
00031      if (vpe[i].tp==path_elmt::name) break;
00032  }
00033 
00034  error err;
00035  do {
00036     err=make_dir(mp, make_path(mp, &vpe[0], &vpe[0]+i+1));
00037     if (err!=ezero && err!=eexist) return err;
00038  } while (++i<end);
00039 
00040  return err;
00041 }
00042 
00043 void ex_make_dir(mem_pool& mp, const ch_rng& dname)
00044 {
00045  error err=make_dir(mp, dname);
00046  if (err!=ezero) {
00047     throw newFileErrorException(mp, _FLINE_, "Can't make directory", err,
00048       dname);
00049  }
00050 }
00051 
00052 void ex_make_dirs(mem_pool& mp, const ch_rng& dname)
00053 {
00054  error err=make_dirs(mp, dname);
00055  if (err!=ezero) {
00056     throw newFileErrorException(mp, _FLINE_, "Can't make directories", err,
00057       dname);
00058  }
00059 }
00060 
00061 }  // namespace ::ders
00062 

Generated on Tue Dec 8 11:35:32 2009 for derslib by  doxygen 1.5.5