summaryrefslogtreecommitdiffstats
path: root/Source/cmSystemTools.cxx
blob: 4efb05d3a8ff39495dc302f0bdccacb4594771db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "cmSystemTools.h"
#include <direct.h>
#include "errno.h"
#include <windows.h>

bool cmSystemTools::MakeDirectory(const char* path)
{
  std::string dir = path;
  // replace all of the \ with /
  size_t pos = 0;
  while((pos = dir.find('\\', pos)) != std::string::npos)
    {
    dir[pos] = '/';
    pos++;
    }
  pos =  dir.find(':');
  if(pos == std::string::npos)
    {
    pos = 0;
    }
  while((pos = dir.find('/', pos)) != std::string::npos)
    {
    std::string topdir = dir.substr(0, pos);
    _mkdir(topdir.c_str());
    pos++;
    }
  if(_mkdir(path) != 0)
    {
    // if it is some other error besides directory exists
    // then return false
    if(errno != EEXIST)
      {
      return false;
      }
    }
  return true;
}

void cmSystemTools::ReplaceString(std::string& source,
                                   const char* replace,
                                   const char* with)
{
  std::string line = source;
  size_t start = line.find(replace);
  while(start != std::string::npos)
    {
    source = line.substr(0, start);
    source += with;
    source += line.substr(start + strlen(replace));
    start = line.find(replace, start + strlen(replace) );
    }
}