dyn_macosx.c

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

Generated on Mon Aug 17 01:00:08 2009 for pcsc-lite by  doxygen 1.5.9