pcsc-lite  1.8.8
dyn_macosx.c
Go to the documentation of this file.
1 /*
2  * MUSCLE SmartCard Development ( http://www.linuxnet.com )
3  *
4  * Copyright (C) 2000
5  * David Corcoran <corcoran@linuxnet.com>
6  * Copyright (C) 2002-2010
7  * Ludovic Rousseau <ludovic.rousseau@free.fr>
8  *
9  * $Id: dyn_macosx.c 5047 2010-06-29 14:39:24Z rousseau $
10  */
11 
17 #include "config.h"
18 
19 #include "misc.h"
20 #include "pcsclite.h"
21 #include "debuglog.h"
22 #include "dyn_generic.h"
23 
24 #ifdef __APPLE__
25 #include <CoreFoundation/CFBundle.h>
26 #include <CoreFoundation/CFString.h>
27 #include <CoreFoundation/CFURL.h>
28 
29 /*
30  * / Load a module (if needed)
31  */
32 int DYN_LoadLibrary(void **pvLHandle, char *pcLibrary)
33 {
34 
35  CFStringRef bundlePath;
36  CFURLRef bundleURL;
37  CFBundleRef bundle;
38 
39  *pvLHandle = 0;
40 
41  /*
42  * @@@ kCFStringEncodingMacRoman might be wrong on non US systems.
43  */
44 
45  bundlePath = CFStringCreateWithCString(NULL, pcLibrary,
46  kCFStringEncodingMacRoman);
47  if (bundlePath == NULL)
48  return SCARD_E_NO_MEMORY;
49 
50  bundleURL = CFURLCreateWithFileSystemPath(NULL, bundlePath,
51  kCFURLPOSIXPathStyle, TRUE);
52  CFRelease(bundlePath);
53  if (bundleURL == NULL)
54  return SCARD_E_NO_MEMORY;
55 
56  bundle = CFBundleCreate(NULL, bundleURL);
57  CFRelease(bundleURL);
58  if (bundle == NULL)
59  {
60  Log1(PCSC_LOG_ERROR, "CFBundleCreate");
61  return SCARD_F_UNKNOWN_ERROR;
62  }
63 
64  if (!CFBundleLoadExecutable(bundle))
65  {
66  Log1(PCSC_LOG_ERROR, "CFBundleLoadExecutable");
67  CFRelease(bundle);
68  return SCARD_F_UNKNOWN_ERROR;
69  }
70 
71  *pvLHandle = (void *) bundle;
72 
73  return SCARD_S_SUCCESS;
74 }
75 
76 int DYN_CloseLibrary(void **pvLHandle)
77 {
78 
79  CFBundleRef bundle = (CFBundleRef) * pvLHandle;
80 
81  if (CFBundleIsExecutableLoaded(bundle) == TRUE)
82  {
83  CFBundleUnloadExecutable(bundle);
84  CFRelease(bundle);
85  }
86  else
87  Log1(PCSC_LOG_ERROR, "Cannot unload library.");
88 
89  *pvLHandle = 0;
90  return SCARD_S_SUCCESS;
91 }
92 
93 int DYN_GetAddress(void *pvLHandle, void **pvFHandle, const char *pcFunction)
94 {
95 
96  CFBundleRef bundle = (CFBundleRef) pvLHandle;
97  CFStringRef cfName = CFStringCreateWithCString(NULL, pcFunction,
98  kCFStringEncodingMacRoman);
99  if (cfName == NULL)
100  return SCARD_E_NO_MEMORY;
101 
102  *pvFHandle = CFBundleGetFunctionPointerForName(bundle, cfName);
103  CFRelease(cfName);
104  if (*pvFHandle == NULL)
105  return SCARD_F_UNKNOWN_ERROR;
106 
107  return SCARD_S_SUCCESS;
108 }
109 
110 #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:100
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:86
#define SCARD_S_SUCCESS
error codes from http://msdn.microsoft.com/en-us/library/aa924526.aspx
Definition: pcsclite.h:80
This handles debugging.