pcsc-lite 1.5.5
|
00001 /* 00002 * MUSCLE SmartCard Development ( http://www.linuxnet.com ) 00003 * 00004 * Copyright (C) 1999 00005 * David Corcoran <corcoran@linuxnet.com> 00006 * Copyright (C) 2004 00007 * Ludovic Rousseau <ludovic.rousseau@free.fr> 00008 * 00009 * $Id: dyn_unix.c 3247 2009-01-02 13:22:46Z rousseau $ 00010 */ 00011 00017 #include "config.h" 00018 #include <stdio.h> 00019 #include <string.h> 00020 #if defined(HAVE_DLFCN_H) && !defined(HAVE_DL_H) && !defined(__APPLE__) 00021 #include <dlfcn.h> 00022 #include <stdlib.h> 00023 00024 #include "misc.h" 00025 #include "pcsclite.h" 00026 #include "debug.h" 00027 #include "dyn_generic.h" 00028 00029 INTERNAL int DYN_LoadLibrary(void **pvLHandle, char *pcLibrary) 00030 { 00031 *pvLHandle = NULL; 00032 *pvLHandle = dlopen(pcLibrary, RTLD_LAZY); 00033 00034 if (*pvLHandle == NULL) 00035 { 00036 Log3(PCSC_LOG_CRITICAL, "%s: %s", pcLibrary, dlerror()); 00037 return SCARD_F_UNKNOWN_ERROR; 00038 } 00039 00040 return SCARD_S_SUCCESS; 00041 } 00042 00043 INTERNAL int DYN_CloseLibrary(void **pvLHandle) 00044 { 00045 int ret; 00046 00047 ret = dlclose(*pvLHandle); 00048 *pvLHandle = NULL; 00049 00050 if (ret) 00051 { 00052 Log2(PCSC_LOG_CRITICAL, "%s", dlerror()); 00053 return SCARD_F_UNKNOWN_ERROR; 00054 } 00055 00056 return SCARD_S_SUCCESS; 00057 } 00058 00059 INTERNAL int DYN_GetAddress(void *pvLHandle, void **pvFHandle, const char *pcFunction) 00060 { 00061 char pcFunctionName[256]; 00062 int rv; 00063 00064 /* Some platforms might need a leading underscore for the symbol */ 00065 (void)snprintf(pcFunctionName, sizeof(pcFunctionName), "_%s", pcFunction); 00066 00067 *pvFHandle = NULL; 00068 *pvFHandle = dlsym(pvLHandle, pcFunctionName); 00069 00070 /* Failed? Try again without the leading underscore */ 00071 if (*pvFHandle == NULL) 00072 *pvFHandle = dlsym(pvLHandle, pcFunction); 00073 00074 if (*pvFHandle == NULL) 00075 { 00076 Log3(PCSC_LOG_CRITICAL, "%s: %s", pcFunction, dlerror()); 00077 rv = SCARD_F_UNKNOWN_ERROR; 00078 } else 00079 rv = SCARD_S_SUCCESS; 00080 00081 return rv; 00082 } 00083 00084 #endif /* HAVE_DLFCN_H && !HAVE_DL_H && !__APPLE__ */