[sanitizer] Improve FreeBSD ASLR detection
[llvm-project.git] / lldb / tools / debugserver / source / MacOSX / CFBundle.cpp
blob6971c1f4c328f51fa70d9580597dc2f47ba4456e
1 //===-- CFBundle.cpp --------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Created by Greg Clayton on 1/16/08.
11 //===----------------------------------------------------------------------===//
13 #include "CFBundle.h"
14 #include "CFString.h"
16 // CFBundle constructor
17 CFBundle::CFBundle(const char *path)
18 : CFReleaser<CFBundleRef>(), m_bundle_url() {
19 if (path && path[0])
20 SetPath(path);
23 // CFBundle copy constructor
24 CFBundle::CFBundle(const CFBundle &rhs)
25 : CFReleaser<CFBundleRef>(rhs), m_bundle_url(rhs.m_bundle_url) {}
27 // CFBundle copy constructor
28 CFBundle &CFBundle::operator=(const CFBundle &rhs) {
29 if (this != &rhs)
30 *this = rhs;
31 return *this;
34 // Destructor
35 CFBundle::~CFBundle() {}
37 // Set the path for a bundle by supplying a
38 bool CFBundle::SetPath(const char *path) {
39 CFAllocatorRef alloc = kCFAllocatorDefault;
40 // Release our old bundle and ULR
41 reset(); // This class is a CFReleaser<CFBundleRef>
42 m_bundle_url.reset();
43 // Make a CFStringRef from the supplied path
44 CFString cf_path;
45 cf_path.SetFileSystemRepresentation(path);
46 if (cf_path.get()) {
47 // Make our Bundle URL
48 m_bundle_url.reset(::CFURLCreateWithFileSystemPath(
49 alloc, cf_path.get(), kCFURLPOSIXPathStyle, true));
50 if (m_bundle_url.get()) {
51 reset(::CFBundleCreate(alloc, m_bundle_url.get()));
54 return get() != NULL;
57 CFStringRef CFBundle::GetIdentifier() const {
58 CFBundleRef bundle = get();
59 if (bundle != NULL)
60 return ::CFBundleGetIdentifier(bundle);
61 return NULL;
64 CFURLRef CFBundle::CopyExecutableURL() const {
65 CFBundleRef bundle = get();
66 if (bundle != NULL)
67 return CFBundleCopyExecutableURL(bundle);
68 return NULL;