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"
20 //===----------------------------------------------------------------------===//
21 //=== WARNING: Implementation here must contain only TRULY operating system
22 //=== independent code.
23 //===----------------------------------------------------------------------===//
26 sys::IdentifyFileType(const char*magic, unsigned length) {
27 assert(magic && "Invalid magic number string");
28 assert(length >=4 && "Invalid magic number length");
31 if (magic[1] == 'l' && magic[2] == 'v') {
33 return CompressedBytecodeFileType;
34 else if (magic[3] == 'm')
35 return BytecodeFileType;
41 if (memcmp(magic,"!<arch>\n",8) == 0)
42 return ArchiveFileType;
49 return UnknownFileType;
53 Path::isArchive() const {
55 return hasMagicNumber("!<arch>\012");
60 Path::isDynamicLibrary() const {
62 return hasMagicNumber("\177ELF");
67 Path::FindLibrary(std::string& name) {
68 std::vector<sys::Path> LibPaths;
69 GetSystemLibraryPaths(LibPaths);
70 for (unsigned i = 0; i < LibPaths.size(); ++i) {
71 sys::Path FullPath(LibPaths[i]);
72 FullPath.appendFile("lib" + name + LTDL_SHLIB_EXT);
73 if (FullPath.isDynamicLibrary())
75 FullPath.elideSuffix();
76 FullPath.appendSuffix("a");
77 if (FullPath.isArchive())
85 // Include the truly platform-specific parts of this class.
86 #include "platform/Path.cpp"
88 // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab