1 //===-- CFCBundle.cpp -----------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
10 #include "CFCString.h"
12 // CFCBundle constructor
13 CFCBundle::CFCBundle(const char *path
) : CFCReleaser
<CFBundleRef
>() {
18 CFCBundle::CFCBundle(CFURLRef url
)
19 : CFCReleaser
<CFBundleRef
>(url
? CFBundleCreate(NULL
, url
) : NULL
) {}
22 CFCBundle::~CFCBundle() = default;
24 // Set the path for a bundle by supplying a
25 bool CFCBundle::SetPath(const char *path
) {
26 CFAllocatorRef alloc
= kCFAllocatorDefault
;
27 // Release our old bundle and URL
30 // Make a CFStringRef from the supplied path
32 cf_path
.SetFileSystemRepresentation(path
);
34 // Make our Bundle URL
35 CFCReleaser
<CFURLRef
> bundle_url(::CFURLCreateWithFileSystemPath(
36 alloc
, cf_path
.get(), kCFURLPOSIXPathStyle
, true));
38 reset(::CFBundleCreate(alloc
, bundle_url
.get()));
43 bool CFCBundle::GetPath(char *dst
, size_t dst_len
) {
44 CFBundleRef bundle
= get();
46 CFCReleaser
<CFURLRef
> bundle_url(CFBundleCopyBundleURL(bundle
));
47 if (bundle_url
.get()) {
48 Boolean resolveAgainstBase
= 0;
49 return ::CFURLGetFileSystemRepresentation(bundle_url
.get(),
51 (UInt8
*)dst
, dst_len
) != 0;
57 CFStringRef
CFCBundle::GetIdentifier() const {
58 CFBundleRef bundle
= get();
60 return ::CFBundleGetIdentifier(bundle
);
64 CFTypeRef
CFCBundle::GetValueForInfoDictionaryKey(CFStringRef key
) const {
65 CFBundleRef bundle
= get();
67 return ::CFBundleGetValueForInfoDictionaryKey(bundle
, key
);
71 CFURLRef
CFCBundle::CopyExecutableURL() const {
72 CFBundleRef bundle
= get();
74 return CFBundleCopyExecutableURL(bundle
);