pcsc-lite  1.8.11
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 Changes to this license can be made only by the copyright author with
22 explicit written consent.
23 
24 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  *
35  * $Id: dyn_macosx.c 6851 2014-02-14 15:43:32Z rousseau $
36  */
37 
43 #include "config.h"
44 
45 #include "misc.h"
46 #include "pcsclite.h"
47 #include "debuglog.h"
48 #include "dyn_generic.h"
49 
50 #ifdef __APPLE__
51 #include <CoreFoundation/CFBundle.h>
52 #include <CoreFoundation/CFString.h>
53 #include <CoreFoundation/CFURL.h>
54 
55 /*
56  * / Load a module (if needed)
57  */
58 int DYN_LoadLibrary(void **pvLHandle, char *pcLibrary)
59 {
60 
61  CFStringRef bundlePath;
62  CFURLRef bundleURL;
63  CFBundleRef bundle;
64 
65  *pvLHandle = 0;
66 
67  /*
68  * @@@ kCFStringEncodingMacRoman might be wrong on non US systems.
69  */
70 
71  bundlePath = CFStringCreateWithCString(NULL, pcLibrary,
72  kCFStringEncodingMacRoman);
73  if (bundlePath == NULL)
74  return SCARD_E_NO_MEMORY;
75 
76  bundleURL = CFURLCreateWithFileSystemPath(NULL, bundlePath,
77  kCFURLPOSIXPathStyle, TRUE);
78  CFRelease(bundlePath);
79  if (bundleURL == NULL)
80  return SCARD_E_NO_MEMORY;
81 
82  bundle = CFBundleCreate(NULL, bundleURL);
83  CFRelease(bundleURL);
84  if (bundle == NULL)
85  {
86  Log1(PCSC_LOG_ERROR, "CFBundleCreate");
87  return SCARD_F_UNKNOWN_ERROR;
88  }
89 
90  if (!CFBundleLoadExecutable(bundle))
91  {
92  Log1(PCSC_LOG_ERROR, "CFBundleLoadExecutable");
93  CFRelease(bundle);
94  return SCARD_F_UNKNOWN_ERROR;
95  }
96 
97  *pvLHandle = (void *) bundle;
98 
99  return SCARD_S_SUCCESS;
100 }
101 
102 int DYN_CloseLibrary(void **pvLHandle)
103 {
104 
105  CFBundleRef bundle = (CFBundleRef) * pvLHandle;
106 
107  if (CFBundleIsExecutableLoaded(bundle) == TRUE)
108  {
109  CFBundleUnloadExecutable(bundle);
110  CFRelease(bundle);
111  }
112  else
113  Log1(PCSC_LOG_ERROR, "Cannot unload library.");
114 
115  *pvLHandle = 0;
116  return SCARD_S_SUCCESS;
117 }
118 
119 int DYN_GetAddress(void *pvLHandle, void **pvFHandle, const char *pcFunction,
120  int mayfail)
121 {
122 
123  CFBundleRef bundle = (CFBundleRef) pvLHandle;
124  CFStringRef cfName = CFStringCreateWithCString(NULL, pcFunction,
125  kCFStringEncodingMacRoman);
126  if (cfName == NULL)
127  return SCARD_E_NO_MEMORY;
128 
129  *pvFHandle = CFBundleGetFunctionPointerForName(bundle, cfName);
130  CFRelease(cfName);
131  if (*pvFHandle == NULL)
132  return SCARD_F_UNKNOWN_ERROR;
133 
134  return SCARD_S_SUCCESS;
135 }
136 
137 #endif /* __APPLE__ */
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:126
This keeps a list of defines for pcsc-lite.
#define SCARD_E_NO_MEMORY
Not enough memory available to complete this command.
Definition: pcsclite.h:112
#define SCARD_S_SUCCESS
error codes from http://msdn.microsoft.com/en-us/library/aa924526.aspx
Definition: pcsclite.h:106
This handles debugging.