1 //===- RealPath.cpp -------------------------------------------------------===//
2 //
3 //                     The MCLinker Project
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 #include "mcld/Support/RealPath.h"
10 #include "mcld/Support/FileSystem.h"
11 
12 namespace mcld {
13 namespace sys {
14 namespace fs {
15 
16 //==========================
17 // RealPath
RealPath()18 RealPath::RealPath() : Path() {
19 }
20 
RealPath(const RealPath::ValueType * s)21 RealPath::RealPath(const RealPath::ValueType* s) : Path(s) {
22   initialize();
23 }
24 
RealPath(const RealPath::StringType & s)25 RealPath::RealPath(const RealPath::StringType& s) : Path(s) {
26   initialize();
27 }
28 
RealPath(const Path & pPath)29 RealPath::RealPath(const Path& pPath) : Path(pPath) {
30   initialize();
31 }
32 
~RealPath()33 RealPath::~RealPath() {
34 }
35 
assign(const Path & pPath)36 RealPath& RealPath::assign(const Path& pPath) {
37   Path::m_PathName.assign(pPath.native());
38   return (*this);
39 }
40 
initialize()41 void RealPath::initialize() {
42   if (isFromRoot()) {
43     detail::canonicalize(m_PathName);
44   } else if (isFromPWD()) {
45     Path path_name;
46     detail::get_pwd(path_name);
47     path_name.native() += preferred_separator;
48     path_name.native() += m_PathName;
49     detail::canonicalize(path_name.native());
50     m_PathName = path_name.native();
51   }
52 }
53 
54 }  // namespace fs
55 }  // namespace sys
56 }  // namespace mcld
57