pcsc-lite 1.7.2
|
00001 /* 00002 * MUSCLE SmartCard Development ( http://www.linuxnet.com ) 00003 * 00004 * Copyright (C) 2000 00005 * David Corcoran <corcoran@linuxnet.com> 00006 * Copyright (C) 2002-2010 00007 * Ludovic Rousseau <ludovic.rousseau@free.fr> 00008 * 00009 * $Id: dyn_macosx.c 5047 2010-06-29 14:39:24Z rousseau $ 00010 */ 00011 00017 #include "config.h" 00018 00019 #include "misc.h" 00020 #include "pcsclite.h" 00021 #include "debuglog.h" 00022 #include "dyn_generic.h" 00023 00024 #ifdef __APPLE__ 00025 #include <CoreFoundation/CFBundle.h> 00026 #include <CoreFoundation/CFString.h> 00027 #include <CoreFoundation/CFURL.h> 00028 00029 /* 00030 * / Load a module (if needed) 00031 */ 00032 int DYN_LoadLibrary(void **pvLHandle, char *pcLibrary) 00033 { 00034 00035 CFStringRef bundlePath; 00036 CFURLRef bundleURL; 00037 CFBundleRef bundle; 00038 00039 *pvLHandle = 0; 00040 00041 /* 00042 * @@@ kCFStringEncodingMacRoman might be wrong on non US systems. 00043 */ 00044 00045 bundlePath = CFStringCreateWithCString(NULL, pcLibrary, 00046 kCFStringEncodingMacRoman); 00047 if (bundlePath == NULL) 00048 return SCARD_E_NO_MEMORY; 00049 00050 bundleURL = CFURLCreateWithFileSystemPath(NULL, bundlePath, 00051 kCFURLPOSIXPathStyle, TRUE); 00052 CFRelease(bundlePath); 00053 if (bundleURL == NULL) 00054 return SCARD_E_NO_MEMORY; 00055 00056 bundle = CFBundleCreate(NULL, bundleURL); 00057 CFRelease(bundleURL); 00058 if (bundle == NULL) 00059 { 00060 Log1(PCSC_LOG_ERROR, "CFBundleCreate"); 00061 return SCARD_F_UNKNOWN_ERROR; 00062 } 00063 00064 if (!CFBundleLoadExecutable(bundle)) 00065 { 00066 Log1(PCSC_LOG_ERROR, "CFBundleLoadExecutable"); 00067 CFRelease(bundle); 00068 return SCARD_F_UNKNOWN_ERROR; 00069 } 00070 00071 *pvLHandle = (void *) bundle; 00072 00073 return SCARD_S_SUCCESS; 00074 } 00075 00076 int DYN_CloseLibrary(void **pvLHandle) 00077 { 00078 00079 CFBundleRef bundle = (CFBundleRef) * pvLHandle; 00080 00081 if (CFBundleIsExecutableLoaded(bundle) == TRUE) 00082 { 00083 CFBundleUnloadExecutable(bundle); 00084 CFRelease(bundle); 00085 } 00086 else 00087 Log1(PCSC_LOG_ERROR, "Cannot unload library."); 00088 00089 *pvLHandle = 0; 00090 return SCARD_S_SUCCESS; 00091 } 00092 00093 int DYN_GetAddress(void *pvLHandle, void **pvFHandle, const char *pcFunction) 00094 { 00095 00096 CFBundleRef bundle = (CFBundleRef) pvLHandle; 00097 CFStringRef cfName = CFStringCreateWithCString(NULL, pcFunction, 00098 kCFStringEncodingMacRoman); 00099 if (cfName == NULL) 00100 return SCARD_E_NO_MEMORY; 00101 00102 *pvFHandle = CFBundleGetFunctionPointerForName(bundle, cfName); 00103 CFRelease(cfName); 00104 if (*pvFHandle == NULL) 00105 return SCARD_F_UNKNOWN_ERROR; 00106 00107 return SCARD_S_SUCCESS; 00108 } 00109 00110 #endif /* __APPLE__ */