pcsc-lite 2.3.0
dyn_macosx.c
Go to the documentation of this file.
1/*
2 * MUSCLE SmartCard Development ( https://pcsclite.apdu.fr/ )
3 *
4 * Copyright (C) 2000
5 * David Corcoran <corcoran@musclecard.com>
6 * Copyright (C) 2002-2024
7 * Ludovic Rousseau <ludovic.rousseau@free.fr>
8 *
9Redistribution and use in source and binary forms, with or without
10modification, are permitted provided that the following conditions
11are met:
12
131. Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
152. Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in the
17 documentation and/or other materials provided with the distribution.
183. The name of the author may not be used to endorse or promote products
19 derived from this software without specific prior written permission.
20
21THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
38#include "config.h"
39
40#include "misc.h"
41#include "pcsclite.h"
42#include "debuglog.h"
43#include "dyn_generic.h"
44
45#ifdef __APPLE__
46#include <CoreFoundation/CFBundle.h>
47#include <CoreFoundation/CFString.h>
48#include <CoreFoundation/CFURL.h>
49
50/*
51 * / Load a module (if needed)
52 */
53void * DYN_LoadLibrary(const char *pcLibrary)
54{
55
56 CFStringRef bundlePath;
57 CFURLRef bundleURL;
58 CFBundleRef bundle;
59
60 void *pvLHandle = 0;
61
62 /*
63 * @@@ kCFStringEncodingMacRoman might be wrong on non US systems.
64 */
65
66 bundlePath = CFStringCreateWithCString(NULL, pcLibrary,
67 kCFStringEncodingMacRoman);
68 if (bundlePath == NULL)
69 return NULL;
70
71 bundleURL = CFURLCreateWithFileSystemPath(NULL, bundlePath,
72 kCFURLPOSIXPathStyle, TRUE);
73 CFRelease(bundlePath);
74 if (bundleURL == NULL)
75 return NULL;
76
77 bundle = CFBundleCreate(NULL, bundleURL);
78 CFRelease(bundleURL);
79 if (bundle == NULL)
80 {
81 Log1(PCSC_LOG_ERROR, "CFBundleCreate");
82 return NULL;
83 }
84
85 if (!CFBundleLoadExecutable(bundle))
86 {
87 Log1(PCSC_LOG_ERROR, "CFBundleLoadExecutable");
88 CFRelease(bundle);
89 return NULL;
90 }
91
92 pvLHandle = (void *) bundle;
93
94 return pvLHandle;
95}
96
97int DYN_CloseLibrary(void *pvLHandle)
98{
99
100 CFBundleRef bundle = (CFBundleRef) pvLHandle;
101
102 if (CFBundleIsExecutableLoaded(bundle) == TRUE)
103 {
104 CFBundleUnloadExecutable(bundle);
105 CFRelease(bundle);
106 }
107 else
108 Log1(PCSC_LOG_ERROR, "Cannot unload library.");
109
110 return SCARD_S_SUCCESS;
111}
112
113int DYN_GetAddress(void *pvLHandle, void **pvFHandle, const char *pcFunction,
114 bool mayfail)
115{
116 (void)mayfail;
117
118 CFBundleRef bundle = (CFBundleRef) pvLHandle;
119 CFStringRef cfName = CFStringCreateWithCString(NULL, pcFunction,
120 kCFStringEncodingMacRoman);
121 if (cfName == NULL)
122 return SCARD_E_NO_MEMORY;
123
124 *pvFHandle = CFBundleGetFunctionPointerForName(bundle, cfName);
125 CFRelease(cfName);
126 if (*pvFHandle == NULL)
128
129 return SCARD_S_SUCCESS;
130}
131
132#endif /* __APPLE__ */
This handles debugging.
This abstracts dynamic library loading functions.
#define SCARD_F_UNKNOWN_ERROR
An internal error has been detected, but the source is unknown.
Definition pcsclite.h:147
#define SCARD_S_SUCCESS
No error was encountered.
Definition pcsclite.h:107
#define SCARD_E_NO_MEMORY
Not enough memory available to complete this command.
Definition pcsclite.h:119
This keeps a list of defines for pcsc-lite.