Main Page   Data Structures   File List   Data Fields   Globals   Related Pages  

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 2265 2006-12-03 13:17: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         return SCARD_F_UNKNOWN_ERROR;
00058 
00059     if (!CFBundleLoadExecutable(bundle))
00060     {
00061         CFRelease(bundle);
00062         return SCARD_F_UNKNOWN_ERROR;
00063     }
00064 
00065     *pvLHandle = (void *) bundle;
00066 
00067     return SCARD_S_SUCCESS;
00068 }
00069 
00070 int DYN_CloseLibrary(void **pvLHandle)
00071 {
00072 
00073     CFBundleRef bundle = (CFBundleRef) * pvLHandle;
00074 
00075     if (CFBundleIsExecutableLoaded(bundle) == TRUE)
00076     {
00077         CFBundleUnloadExecutable(bundle);
00078         CFRelease(bundle);
00079     }
00080     else
00081         Log1(PCSC_LOG_ERROR, "Cannot unload library.");
00082 
00083     *pvLHandle = 0;
00084     return SCARD_S_SUCCESS;
00085 }
00086 
00087 int DYN_GetAddress(void *pvLHandle, void **pvFHandle, const char *pcFunction)
00088 {
00089 
00090     CFBundleRef bundle = (CFBundleRef) pvLHandle;
00091     CFStringRef cfName = CFStringCreateWithCString(NULL, pcFunction,
00092         kCFStringEncodingMacRoman);
00093     if (cfName == NULL)
00094         return SCARD_E_NO_MEMORY;
00095 
00096     *pvFHandle = CFBundleGetFunctionPointerForName(bundle, cfName);
00097     CFRelease(cfName);
00098     if (*pvFHandle == NULL)
00099         return SCARD_F_UNKNOWN_ERROR;
00100 
00101     return SCARD_S_SUCCESS;
00102 }
00103 
00104 #endif  /* __APPLE__ */

Generated on Mon Nov 24 20:31:19 2008 for pcsc-lite by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002