[Pcsclite-cvs-commit] CVS libmusclecard/src
CVS User rousseau
ludovic.rousseau@free.fr
Thu, 21 Apr 2005 09:28:17 +0000
Update of /cvsroot/pcsclite/libmusclecard/src
In directory haydn:/tmp/cvs-serv7563
Added Files:
dyn_hpux.c dyn_macosx.c dyn_unix.c dyn_win32.c
Log Message:
files copied from pcsc-lite since they are now separate packages
--- /cvsroot/pcsclite/libmusclecard/src/dyn_hpux.c 2005/04/21 09:28:17 NONE
+++ /cvsroot/pcsclite/libmusclecard/src/dyn_hpux.c 2005/04/21 09:28:17 1.1
/*
* This abstracts dynamic library loading functions and timing.
*
* MUSCLE SmartCard Development ( http://www.linuxnet.com )
*
* Copyright (C) 2001
* David Corcoran <corcoran@linuxnet.com>
* Copyright (C) 2004
* Ludovic Rousseau <ludovic.rousseau@free.fr>
*
* $Id: dyn_hpux.c,v 1.1 2005/04/21 09:28:17 rousseau Exp $
*/
#include "config.h"
#include <string.h>
#ifdef HAVE_DL_H
#include <dl.h>
#include <errno.h>
#include "pcsclite.h"
#include "debuglog.h"
#include "dyn_generic.h"
int DYN_LoadLibrary(void **pvLHandle, char *pcLibrary)
{
shl_t myHandle;
*pvLHandle = 0;
myHandle =
shl_load(pcLibrary, BIND_IMMEDIATE | BIND_VERBOSE | BIND_NOSTART,
0L);
if (myHandle == 0)
{
Log3(PCSC_LOG_ERROR, "%s: %s", pcLibrary, strerror(errno));
return SCARD_F_UNKNOWN_ERROR;
}
*pvLHandle = (void *) myHandle;
return SCARD_S_SUCCESS;
}
int DYN_CloseLibrary(void **pvLHandle)
{
int rv;
rv = shl_unload((shl_t) * pvLHandle);
*pvLHandle = 0;
if (rv == -1)
{
Log2(PCSC_LOG_ERROR, "%s", strerror(errno));
return SCARD_F_UNKNOWN_ERROR;
}
return SCARD_S_SUCCESS;
}
int DYN_GetAddress(void *pvLHandle, void **pvFHandle, char *pcFunction)
{
int rv;
*pvFHandle = 0;
rv = shl_findsym((shl_t *) & pvLHandle, pcFunction, TYPE_PROCEDURE,
pvFHandle);
if (rv == -1)
{
Log3(PCSC_LOG_ERROR, "%s: %s", pcFunction, strerror(errno));
rv = SCARD_F_UNKNOWN_ERROR;
}
else
rv = SCARD_S_SUCCESS;
return rv;
}
#endif /* HAVE_DL_H */
--- /cvsroot/pcsclite/libmusclecard/src/dyn_macosx.c 2005/04/21 09:28:17 NONE
+++ /cvsroot/pcsclite/libmusclecard/src/dyn_macosx.c 2005/04/21 09:28:17 1.1
/*
* This abstracts dynamic library loading functions and timing.
*
* MUSCLE SmartCard Development ( http://www.linuxnet.com )
*
* Copyright (C) 2000
* David Corcoran <corcoran@linuxnet.com>
*
* $Id: dyn_macosx.c,v 1.1 2005/04/21 09:28:17 rousseau Exp $
*/
#include "config.h"
#include "pcsclite.h"
#include "debuglog.h"
#include "dyn_generic.h"
#ifdef __APPLE__
#include <CoreFoundation/CFBundle.h>
#include <CoreFoundation/CFString.h>
#include <CoreFoundation/CFURL.h>
/*
* / Load a module (if needed)
*/
int DYN_LoadLibrary(void **pvLHandle, char *pcLibrary)
{
CFStringRef bundlePath;
CFURLRef bundleURL;
CFBundleRef bundle;
*pvLHandle = 0;
/*
* @@@ kCFStringEncodingMacRoman might be wrong on non US systems.
*/
bundlePath = CFStringCreateWithCString(NULL, pcLibrary,
kCFStringEncodingMacRoman);
if (bundlePath == NULL)
return SCARD_E_NO_MEMORY;
bundleURL = CFURLCreateWithFileSystemPath(NULL, bundlePath,
kCFURLPOSIXPathStyle, TRUE);
CFRelease(bundlePath);
if (bundleURL == NULL)
return SCARD_E_NO_MEMORY;
bundle = CFBundleCreate(NULL, bundleURL);
CFRelease(bundleURL);
if (bundle == NULL)
return SCARD_F_UNKNOWN_ERROR;
if (!CFBundleLoadExecutable(bundle))
{
CFRelease(bundle);
return SCARD_F_UNKNOWN_ERROR;
}
*pvLHandle = (void *) bundle;
return SCARD_S_SUCCESS;
}
int DYN_CloseLibrary(void **pvLHandle)
{
CFBundleRef bundle = (CFBundleRef) * pvLHandle;
if (CFBundleIsExecutableLoaded(bundle) == TRUE)
{
CFBundleUnloadExecutable(bundle);
CFRelease(bundle);
}
else
Log1(PCSC_LOG_ERROR, "Cannot unload library.");
*pvLHandle = 0;
return SCARD_S_SUCCESS;
}
int DYN_GetAddress(void *pvLHandle, void **pvFHandle, char *pcFunction)
{
CFBundleRef bundle = (CFBundleRef) pvLHandle;
CFStringRef cfName = CFStringCreateWithCString(NULL, pcFunction,
kCFStringEncodingMacRoman);
if (cfName == NULL)
return SCARD_E_NO_MEMORY;
*pvFHandle = CFBundleGetFunctionPointerForName(bundle, cfName);
CFRelease(cfName);
if (*pvFHandle == NULL)
return SCARD_F_UNKNOWN_ERROR;
return SCARD_S_SUCCESS;
}
#endif /* __APPLE__ */
--- /cvsroot/pcsclite/libmusclecard/src/dyn_unix.c 2005/04/21 09:28:17 NONE
+++ /cvsroot/pcsclite/libmusclecard/src/dyn_unix.c 2005/04/21 09:28:17 1.1
/*
* This abstracts dynamic library loading functions and timing.
*
* MUSCLE SmartCard Development ( http://www.linuxnet.com )
*
* Copyright (C) 1999
* David Corcoran <corcoran@linuxnet.com>
* Copyright (C) 2004
* Ludovic Rousseau <ludovic.rousseau@free.fr>
*
* $Id: dyn_unix.c,v 1.1 2005/04/21 09:28:17 rousseau Exp $
*/
#include "config.h"
#include <stdio.h>
#include <string.h>
#if defined(HAVE_DLFCN_H) && !defined(HAVE_DL_H) && !defined(__APPLE__)
#include <dlfcn.h>
#include <stdlib.h>
#include "pcsclite.h"
#include "debuglog.h"
#include "dyn_generic.h"
#include "misc.h"
INTERNAL int DYN_LoadLibrary(void **pvLHandle, char *pcLibrary)
{
*pvLHandle = NULL;
*pvLHandle = dlopen(pcLibrary, RTLD_LAZY);
if (*pvLHandle == NULL)
{
Log3(PCSC_LOG_CRITICAL, "%s: %s", pcLibrary, dlerror());
return SCARD_F_UNKNOWN_ERROR;
}
return SCARD_S_SUCCESS;
}
INTERNAL int DYN_CloseLibrary(void **pvLHandle)
{
int ret;
ret = dlclose(*pvLHandle);
*pvLHandle = NULL;
if (ret)
{
Log2(PCSC_LOG_CRITICAL, "%s", dlerror());
return SCARD_F_UNKNOWN_ERROR;
}
return SCARD_S_SUCCESS;
}
INTERNAL int DYN_GetAddress(void *pvLHandle, void **pvFHandle, char *pcFunction)
{
char pcFunctionName[256];
int rv;
/* Some platforms might need a leading underscore for the symbol */
snprintf(pcFunctionName, sizeof(pcFunctionName), "_%s", pcFunction);
*pvFHandle = NULL;
*pvFHandle = dlsym(pvLHandle, pcFunctionName);
/* Failed? Try again without the leading underscore */
if (*pvFHandle == NULL)
*pvFHandle = dlsym(pvLHandle, pcFunction);
if (*pvFHandle == NULL)
{
Log3(PCSC_LOG_CRITICAL, "%s: %s", pcFunction, dlerror());
rv = SCARD_F_UNKNOWN_ERROR;
} else
rv = SCARD_S_SUCCESS;
return rv;
}
#endif /* HAVE_DLFCN_H && !HAVE_DL_H && !__APPLE__ */
--- /cvsroot/pcsclite/libmusclecard/src/dyn_win32.c 2005/04/21 09:28:17 NONE
+++ /cvsroot/pcsclite/libmusclecard/src/dyn_win32.c 2005/04/21 09:28:17 1.1
/*
* This abstracts dynamic library loading functions and timing.
*
* MUSCLE SmartCard Development ( http://www.linuxnet.com )
*
* Copyright (C) 1999
* David Corcoran <corcoran@linuxnet.com>
*
* $Id: dyn_win32.c,v 1.1 2005/04/21 09:28:17 rousseau Exp $
*/
#include "config.h"
#ifdef WIN32
#include <string.h>
#include "windows.h"
#include <winscard.h>
#include "dyn_generic.h"
#include "debuglog.h"
int DYN_LoadLibrary(void **pvLHandle, char *pcLibrary)
{
*pvLHandle = NULL;
*pvLHandle = LoadLibrary(pcLibrary);
if (*pvLHandle == NULL)
{
#if 0
Log2(PCSC_LOG_ERROR, "DYN_LoadLibrary: dlerror() reports %s", dlerror());
#endif
return SCARD_F_UNKNOWN_ERROR;
}
return SCARD_S_SUCCESS;
}
int DYN_CloseLibrary(void **pvLHandle)
{
int ret;
ret = FreeLibrary(*pvLHandle);
*pvLHandle = NULL;
/* If the function fails, the return value is zero. To get extended error
* information, call GetLastError. */
if (ret == 0)
{
#if 0
Log2(PCSC_LOG_ERROR, "DYN_CloseLibrary: dlerror() reports %s", dlerror());
#endif
return SCARD_F_UNKNOWN_ERROR;
}
return SCARD_S_SUCCESS;
}
int DYN_GetAddress(void *pvLHandle, void **pvFHandle, char *pcFunction)
{
int rv;
char *pcFunctionName;
/*
* Zero out everything
*/
rv = 0;
pcFunctionName = NULL;
pcFunctionName = pcFunction;
*pvFHandle = NULL;
*pvFHandle = GetProcAddress(pvLHandle, pcFunctionName);
if (*pvFHandle == NULL)
{
#if 0
Log2(PCSC_LOG_ERROR, "DYN_GetAddress: dlerror() reports %s", dlerror());
#endif
rv = SCARD_F_UNKNOWN_ERROR;
}
else
rv = SCARD_S_SUCCESS;
return rv;
}
#endif /* WIN32 */