summaryrefslogtreecommitdiff
path: root/lib/Support/RealPath.cpp
blob: b62f4439013c5cdff7ffa27dae4db04cd48cba1d (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
53
54
55
56
57
58
59
//===- RealPath.cpp -------------------------------------------------------===//
//
//                     The MCLinker Project
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "mcld/Support/RealPath.h"
#include "mcld/Support/FileSystem.h"

using namespace mcld::sys::fs;

//==========================
// RealPath
RealPath::RealPath()
  : Path() {
}

RealPath::RealPath(const RealPath::ValueType* s )
  : Path(s) {
  initialize();
}

RealPath::RealPath(const RealPath::StringType &s )
  : Path(s) {
  initialize();
}

RealPath::RealPath(const Path& pPath)
 : Path(pPath) {
  initialize();
}

RealPath::~RealPath()
{
}

RealPath& RealPath::assign(const Path& pPath)
{
  Path::m_PathName.assign(pPath.native());
  return (*this);
}

void RealPath::initialize()
{
  if (isFromRoot()) {
    detail::canonicalize(m_PathName);
  }
  else if (isFromPWD()) {
    Path path_name;
    detail::get_pwd(path_name);
    path_name.native() += preferred_separator;
    path_name.native() += m_PathName;
    detail::canonicalize(path_name.native());
    m_PathName = path_name.native();
  }
}