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() {
29 if (result.setDirectory(LLVM_ETCDIR))
31 return GetLLVMDefaultConfigDir();
35 sys::IdentifyFileType(const char*magic, unsigned length) {
36 assert(magic && "Invalid magic number string");
37 assert(length >=4 && "Invalid magic number length");
40 if (magic[1] == 'l' && magic[2] == 'v') {
42 return CompressedBytecodeFileType;
43 else if (magic[3] == 'm')
44 return BytecodeFileType;
50 if (memcmp(magic,"!<arch>\n",8) == 0)
51 return ArchiveFileType;
58 return UnknownFileType;
62 Path::isArchive() const {
64 return hasMagicNumber("!<arch>\012");
69 Path::isDynamicLibrary() const {
71 return hasMagicNumber("\177ELF");
76 Path::FindLibrary(std::string& name) {
77 std::vector<sys::Path> LibPaths;
78 GetSystemLibraryPaths(LibPaths);
79 for (unsigned i = 0; i < LibPaths.size(); ++i) {
80 sys::Path FullPath(LibPaths[i]);
81 FullPath.appendFile("lib" + name + LTDL_SHLIB_EXT);
82 if (FullPath.isDynamicLibrary())
84 FullPath.elideSuffix();
85 FullPath.appendSuffix("a");
86 if (FullPath.isArchive())
93 Path::GetDLLSuffix() {
94 return LTDL_SHLIB_EXT;
99 // Include the truly platform-specific parts of this class.
100 #include "platform/Path.cpp"
102 // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab