1 //===-- Path.cpp - Implement OS Path Concept --------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Reid Spencer and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This header file implements the operating system Path concept.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/System/Path.h"
15 #include "llvm/Config/config.h"
21 //===----------------------------------------------------------------------===//
22 //=== WARNING: Implementation here must contain only TRULY operating system
23 //=== independent code.
24 //===----------------------------------------------------------------------===//
26 std::ostream& llvm::operator<<(std::ostream &strm, const sys::Path &aPath) {
27 strm << aPath.toString();
32 Path::GetLLVMConfigDir() {
35 if (result.set(LLVM_ETCDIR))
38 return GetLLVMDefaultConfigDir();
42 sys::IdentifyFileType(const char*magic, unsigned length) {
43 assert(magic && "Invalid magic number string");
44 assert(length >=4 && "Invalid magic number length");
47 if (magic[1] == 'l' && magic[2] == 'v') {
49 return CompressedBytecodeFileType;
50 else if (magic[3] == 'm')
51 return BytecodeFileType;
57 if (memcmp(magic,"!<arch>\n",8) == 0)
58 return ArchiveFileType;
65 return UnknownFileType;
69 Path::isArchive() const {
71 return hasMagicNumber("!<arch>\012");
76 Path::isDynamicLibrary() const {
78 return hasMagicNumber("\177ELF");
83 Path::FindLibrary(std::string& name) {
84 std::vector<sys::Path> LibPaths;
85 GetSystemLibraryPaths(LibPaths);
86 for (unsigned i = 0; i < LibPaths.size(); ++i) {
87 sys::Path FullPath(LibPaths[i]);
88 FullPath.appendComponent("lib" + name + LTDL_SHLIB_EXT);
89 if (FullPath.isDynamicLibrary())
91 FullPath.eraseSuffix();
92 FullPath.appendSuffix("a");
93 if (FullPath.isArchive())
99 std::string Path::GetDLLSuffix() {
100 return LTDL_SHLIB_EXT;
103 // Include the truly platform-specific parts of this class.
104 #if defined(LLVM_ON_UNIX)
105 #include "Unix/Path.inc"
107 #if defined(LLVM_ON_WIN32)
108 #include "Win32/Path.inc"
111 DEFINING_FILE_FOR(SystemPath)