pcsc-lite  1.8.14
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  * $Id$
33  */
34 
40 #include "config.h"
41 
42 #include "misc.h"
43 #include "pcsclite.h"
44 #include "debuglog.h"
45 #include "dyn_generic.h"
46 
47 #ifdef __APPLE__
48 #include <CoreFoundation/CFBundle.h>
49 #include <CoreFoundation/CFString.h>
50 #include <CoreFoundation/CFURL.h>
51 
52 /*
53  * / Load a module (if needed)
54  */
55 int DYN_LoadLibrary(void **pvLHandle, char *pcLibrary)
56 {
57 
58  CFStringRef bundlePath;
59  CFURLRef bundleURL;
60  CFBundleRef bundle;
61 
62  *pvLHandle = 0;
63 
64  /*
65  * @@@ kCFStringEncodingMacRoman might be wrong on non US systems.
66  */
67 
68  bundlePath = CFStringCreateWithCString(NULL, pcLibrary,
69  kCFStringEncodingMacRoman);
70  if (bundlePath == NULL)
71  return SCARD_E_NO_MEMORY;
72 
73  bundleURL = CFURLCreateWithFileSystemPath(NULL, bundlePath,
74  kCFURLPOSIXPathStyle, TRUE);
75  CFRelease(bundlePath);
76  if (bundleURL == NULL)
77  return SCARD_E_NO_MEMORY;
78 
79  bundle = CFBundleCreate(NULL, bundleURL);
80  CFRelease(bundleURL);
81  if (bundle == NULL)
82  {
83  Log1(PCSC_LOG_ERROR, "CFBundleCreate");
84  return SCARD_F_UNKNOWN_ERROR;
85  }
86 
87  if (!CFBundleLoadExecutable(bundle))
88  {
89  Log1(PCSC_LOG_ERROR, "CFBundleLoadExecutable");
90  CFRelease(bundle);
91  return SCARD_F_UNKNOWN_ERROR;
92  }
93 
94  *pvLHandle = (void *) bundle;
95 
96  return SCARD_S_SUCCESS;
97 }
98 
99 int DYN_CloseLibrary(void **pvLHandle)
100 {
101 
102  CFBundleRef bundle = (CFBundleRef) * pvLHandle;
103 
104  if (CFBundleIsExecutableLoaded(bundle) == TRUE)
105  {
106  CFBundleUnloadExecutable(bundle);
107  CFRelease(bundle);
108  }
109  else
110  Log1(PCSC_LOG_ERROR, "Cannot unload library.");
111 
112  *pvLHandle = 0;
113  return SCARD_S_SUCCESS;
114 }
115 
116 int DYN_GetAddress(void *pvLHandle, void **pvFHandle, const char *pcFunction,
117  int mayfail)
118 {
119 
120  CFBundleRef bundle = (CFBundleRef) pvLHandle;
121  CFStringRef cfName = CFStringCreateWithCString(NULL, pcFunction,
122  kCFStringEncodingMacRoman);
123  if (cfName == NULL)
124  return SCARD_E_NO_MEMORY;
125 
126  *pvFHandle = CFBundleGetFunctionPointerForName(bundle, cfName);
127  CFRelease(cfName);
128  if (*pvFHandle == NULL)
129  return SCARD_F_UNKNOWN_ERROR;
130 
131  return SCARD_S_SUCCESS;
132 }
133 
134 #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:123
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:109
#define SCARD_S_SUCCESS
error codes from http://msdn.microsoft.com/en-us/library/aa924526.aspx
Definition: pcsclite.h:103
This handles debugging.