/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Host/macosx/cfcpp/CFCBundle.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- CFCBundle.cpp -----------------------------------------------------===// |
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 | | #include "CFCBundle.h" |
10 | | #include "CFCString.h" |
11 | | |
12 | | // CFCBundle constructor |
13 | 2 | CFCBundle::CFCBundle(const char *path) : CFCReleaser<CFBundleRef>() { |
14 | 2 | if (path && path[0]) |
15 | 2 | SetPath(path); |
16 | 2 | } |
17 | | |
18 | | CFCBundle::CFCBundle(CFURLRef url) |
19 | 0 | : CFCReleaser<CFBundleRef>(url ? CFBundleCreate(NULL, url) : NULL) {} |
20 | | |
21 | | // Destructor |
22 | 2 | CFCBundle::~CFCBundle() = default; |
23 | | |
24 | | // Set the path for a bundle by supplying a |
25 | 2 | bool CFCBundle::SetPath(const char *path) { |
26 | 2 | CFAllocatorRef alloc = kCFAllocatorDefault; |
27 | | // Release our old bundle and URL |
28 | 2 | reset(); |
29 | | |
30 | | // Make a CFStringRef from the supplied path |
31 | 2 | CFCString cf_path; |
32 | 2 | cf_path.SetFileSystemRepresentation(path); |
33 | 2 | if (cf_path.get()) { |
34 | | // Make our Bundle URL |
35 | 2 | CFCReleaser<CFURLRef> bundle_url(::CFURLCreateWithFileSystemPath( |
36 | 2 | alloc, cf_path.get(), kCFURLPOSIXPathStyle, true)); |
37 | 2 | if (bundle_url.get()) |
38 | 2 | reset(::CFBundleCreate(alloc, bundle_url.get())); |
39 | 2 | } |
40 | 2 | return get() != NULL; |
41 | 2 | } |
42 | | |
43 | 0 | bool CFCBundle::GetPath(char *dst, size_t dst_len) { |
44 | 0 | CFBundleRef bundle = get(); |
45 | 0 | if (bundle) { |
46 | 0 | CFCReleaser<CFURLRef> bundle_url(CFBundleCopyBundleURL(bundle)); |
47 | 0 | if (bundle_url.get()) { |
48 | 0 | Boolean resolveAgainstBase = 0; |
49 | 0 | return ::CFURLGetFileSystemRepresentation(bundle_url.get(), |
50 | 0 | resolveAgainstBase, |
51 | 0 | (UInt8 *)dst, dst_len) != 0; |
52 | 0 | } |
53 | 0 | } |
54 | 0 | return false; |
55 | 0 | } |
56 | | |
57 | 0 | CFStringRef CFCBundle::GetIdentifier() const { |
58 | 0 | CFBundleRef bundle = get(); |
59 | 0 | if (bundle != NULL) |
60 | 0 | return ::CFBundleGetIdentifier(bundle); |
61 | 0 | return NULL; |
62 | 0 | } |
63 | | |
64 | 0 | CFTypeRef CFCBundle::GetValueForInfoDictionaryKey(CFStringRef key) const { |
65 | 0 | CFBundleRef bundle = get(); |
66 | 0 | if (bundle != NULL) |
67 | 0 | return ::CFBundleGetValueForInfoDictionaryKey(bundle, key); |
68 | 0 | return NULL; |
69 | 0 | } |
70 | | |
71 | 2 | CFURLRef CFCBundle::CopyExecutableURL() const { |
72 | 2 | CFBundleRef bundle = get(); |
73 | 2 | if (bundle != NULL) |
74 | 2 | return CFBundleCopyExecutableURL(bundle); |
75 | 0 | return NULL; |
76 | 2 | } |