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 //===----------------------------------------------------------------------===//
27 Path::GetLLVMConfigDir() {
30 if (result.setDirectory(LLVM_ETCDIR))
33 return GetLLVMDefaultConfigDir();
37 sys::IdentifyFileType(const char*magic, unsigned length) {
38 assert(magic && "Invalid magic number string");
39 assert(length >=4 && "Invalid magic number length");
42 if (magic[1] == 'l' && magic[2] == 'v') {
44 return CompressedBytecodeFileType;
45 else if (magic[3] == 'm')
46 return BytecodeFileType;
52 if (memcmp(magic,"!<arch>\n",8) == 0)
53 return ArchiveFileType;
60 return UnknownFileType;
64 Path::isArchive() const {
66 return hasMagicNumber("!<arch>\012");
71 Path::isDynamicLibrary() const {
73 return hasMagicNumber("\177ELF");
78 Path::FindLibrary(std::string& name) {
79 std::vector<sys::Path> LibPaths;
80 GetSystemLibraryPaths(LibPaths);
81 for (unsigned i = 0; i < LibPaths.size(); ++i) {
82 sys::Path FullPath(LibPaths[i]);
83 FullPath.appendFile("lib" + name + LTDL_SHLIB_EXT);
84 if (FullPath.isDynamicLibrary())
86 FullPath.elideSuffix();
87 FullPath.appendSuffix("a");
88 if (FullPath.isArchive())
95 Path::GetDLLSuffix() {
96 return LTDL_SHLIB_EXT;
101 // Include the truly platform-specific parts of this class.
103 #if defined(LLVM_ON_UNIX)
104 #include "Unix/Path.inc"
106 #if defined(LLVM_ON_WIN32)
107 #include "Win32/Path.inc"
110 // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab