2004-08-25 14:20:07 +08:00
|
|
|
//===-- Path.cpp - Implement OS Path Concept --------------------*- C++ -*-===//
|
2005-04-22 06:55:34 +08:00
|
|
|
//
|
2004-08-25 14:20:07 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:36:04 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-22 06:55:34 +08:00
|
|
|
//
|
2004-08-25 14:20:07 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This header file implements the operating system Path concept.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2004-08-29 13:24:01 +08:00
|
|
|
|
2010-11-30 02:16:10 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
2004-12-14 02:41:28 +08:00
|
|
|
#include "llvm/Config/config.h"
|
2011-04-04 06:53:19 +08:00
|
|
|
#include "llvm/Support/Endian.h"
|
2012-12-04 00:50:05 +08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
2013-06-12 04:00:56 +08:00
|
|
|
#include "llvm/Support/PathV1.h"
|
2004-11-15 06:37:42 +08:00
|
|
|
#include <cassert>
|
2008-01-10 03:42:09 +08:00
|
|
|
#include <cstring>
|
2006-07-08 02:11:32 +08:00
|
|
|
#include <ostream>
|
|
|
|
using namespace llvm;
|
2004-08-29 13:24:01 +08:00
|
|
|
using namespace sys;
|
2011-04-04 06:53:19 +08:00
|
|
|
namespace {
|
|
|
|
using support::ulittle32_t;
|
|
|
|
}
|
2004-08-25 14:20:07 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//=== WARNING: Implementation here must contain only TRULY operating system
|
2005-04-22 06:55:34 +08:00
|
|
|
//=== independent code.
|
2004-08-25 14:20:07 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-05-22 05:20:07 +08:00
|
|
|
bool Path::operator==(const Path &that) const {
|
|
|
|
return path == that.path;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Path::operator<(const Path& that) const {
|
|
|
|
return path < that.path;
|
|
|
|
}
|
|
|
|
|
2004-12-13 11:00:39 +08:00
|
|
|
bool
|
|
|
|
Path::isArchive() const {
|
2011-12-14 07:17:12 +08:00
|
|
|
fs::file_magic type;
|
2011-01-16 04:39:36 +08:00
|
|
|
if (fs::identify_magic(str(), type))
|
|
|
|
return false;
|
2011-12-14 07:17:12 +08:00
|
|
|
return type == fs::file_magic::archive;
|
2004-12-13 11:00:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Path::isDynamicLibrary() const {
|
2011-12-14 07:17:12 +08:00
|
|
|
fs::file_magic type;
|
2011-01-16 04:39:36 +08:00
|
|
|
if (fs::identify_magic(str(), type))
|
|
|
|
return false;
|
|
|
|
switch (type) {
|
|
|
|
default: return false;
|
2011-12-14 07:17:12 +08:00
|
|
|
case fs::file_magic::macho_fixed_virtual_memory_shared_lib:
|
|
|
|
case fs::file_magic::macho_dynamically_linked_shared_lib:
|
|
|
|
case fs::file_magic::macho_dynamically_linked_shared_lib_stub:
|
|
|
|
case fs::file_magic::elf_shared_object:
|
|
|
|
case fs::file_magic::pecoff_executable: return true;
|
2011-01-16 04:39:36 +08:00
|
|
|
}
|
2004-12-13 11:00:39 +08:00
|
|
|
}
|
|
|
|
|
2010-09-16 06:45:45 +08:00
|
|
|
bool
|
|
|
|
Path::isObjectFile() const {
|
2011-12-14 07:17:12 +08:00
|
|
|
fs::file_magic type;
|
|
|
|
if (fs::identify_magic(str(), type) || type == fs::file_magic::unknown)
|
2011-01-16 04:39:36 +08:00
|
|
|
return false;
|
|
|
|
return true;
|
2010-09-16 06:45:45 +08:00
|
|
|
}
|
|
|
|
|
2010-12-01 10:46:41 +08:00
|
|
|
void
|
2010-11-03 06:18:37 +08:00
|
|
|
Path::appendSuffix(StringRef suffix) {
|
|
|
|
if (!suffix.empty()) {
|
|
|
|
path.append(".");
|
|
|
|
path.append(suffix);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-25 14:20:07 +08:00
|
|
|
// Include the truly platform-specific parts of this class.
|
2004-12-24 14:29:17 +08:00
|
|
|
#if defined(LLVM_ON_UNIX)
|
2005-01-10 07:29:00 +08:00
|
|
|
#include "Unix/Path.inc"
|
2004-12-24 14:29:17 +08:00
|
|
|
#endif
|
|
|
|
#if defined(LLVM_ON_WIN32)
|
2010-11-30 02:16:10 +08:00
|
|
|
#include "Windows/Path.inc"
|
2004-12-24 14:29:17 +08:00
|
|
|
#endif
|