pcsc-lite  1.8.20
dyn_macosx.c
Go to the documentation of this file.
1 /*
2  * MUSCLE SmartCard Development ( http://pcsclite.alioth.debian.org/pcsclite.html )
3  *
4  * Copyright (C) 2000
5  * David Corcoran <corcoran@musclecard.com>
6  * Copyright (C) 2002-2010
7  * Ludovic Rousseau <ludovic.rousseau@free.fr>
8  *
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions
11 are met:
12 
13 1. Redistributions of source code must retain the above copyright
14  notice, this list of conditions and the following disclaimer.
15 2. 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.
18 3. 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 
21 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 THIS 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  */
53 int DYN_LoadLibrary(void **pvLHandle, char *pcLibrary)
54 {
55 
56  CFStringRef bundlePath;
57  CFURLRef bundleURL;
58  CFBundleRef bundle;
59 
60  *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 SCARD_E_NO_MEMORY;
70 
71  bundleURL = CFURLCreateWithFileSystemPath(NULL, bundlePath,
72  kCFURLPOSIXPathStyle, TRUE);
73  CFRelease(bundlePath);
74  if (bundleURL == NULL)
75  return SCARD_E_NO_MEMORY;
76 
77  bundle = CFBundleCreate(NULL, bundleURL);
78  CFRelease(bundleURL);
79  if (bundle == NULL)
80  {
81  Log1(PCSC_LOG_ERROR, "CFBundleCreate");
82  return SCARD_F_UNKNOWN_ERROR;
83  }
84 
85  if (!CFBundleLoadExecutable(bundle))
86  {
87  Log1(PCSC_LOG_ERROR, "CFBundleLoadExecutable");
88  CFRelease(bundle);
89  return SCARD_F_UNKNOWN_ERROR;
90  }
91 
92  *pvLHandle = (void *) bundle;
93 
94  return SCARD_S_SUCCESS;
95 }
96 
97 int 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  *pvLHandle = 0;
111  return SCARD_S_SUCCESS;
112 }
113 
114 int DYN_GetAddress(void *pvLHandle, void **pvFHandle, const char *pcFunction,
115  int mayfail)
116 {
117  (void)mayfail;
118 
119  CFBundleRef bundle = (CFBundleRef) pvLHandle;
120  CFStringRef cfName = CFStringCreateWithCString(NULL, pcFunction,
121  kCFStringEncodingMacRoman);
122  if (cfName == NULL)
123  return SCARD_E_NO_MEMORY;
124 
125  *pvFHandle = CFBundleGetFunctionPointerForName(bundle, cfName);
126  CFRelease(cfName);
127  if (*pvFHandle == NULL)
128  return SCARD_F_UNKNOWN_ERROR;
129 
130  return SCARD_S_SUCCESS;
131 }
132 
133 #endif /* __APPLE__ */
This abstracts dynamic library loading functions.
#define SCARD_S_SUCCESS
No error was encountered.
Definition: pcsclite.h:107
#define SCARD_F_UNKNOWN_ERROR
An internal error has been detected, but the source is unknown.
Definition: pcsclite.h:147
#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.
This handles debugging.