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