pcsc-lite  1.8.8
dyn_unix.c
Go to the documentation of this file.
1 /*
2  * MUSCLE SmartCard Development ( http://www.linuxnet.com )
3  *
4  * Copyright (C) 1999-2002
5  * David Corcoran <corcoran@linuxnet.com>
6  * Copyright (C) 2002-2010
7  * Ludovic Rousseau <ludovic.rousseau@free.fr>
8  *
9  * $Id: dyn_unix.c 5047 2010-06-29 14:39:24Z rousseau $
10  */
11 
17 #include "config.h"
18 #include <stdio.h>
19 #include <string.h>
20 #if defined(HAVE_DLFCN_H) && !defined(HAVE_DL_H) && !defined(__APPLE__)
21 #include <dlfcn.h>
22 #include <stdlib.h>
23 
24 #include "misc.h"
25 #include "pcsclite.h"
26 #include "debuglog.h"
27 #include "dyn_generic.h"
28 
29 INTERNAL int DYN_LoadLibrary(void **pvLHandle, char *pcLibrary)
30 {
31  *pvLHandle = NULL;
32 #ifndef PCSCLITE_STATIC_DRIVER
33  *pvLHandle = dlopen(pcLibrary, RTLD_LAZY);
34 
35  if (*pvLHandle == NULL)
36  {
37  Log3(PCSC_LOG_CRITICAL, "%s: %s", pcLibrary, dlerror());
38  return SCARD_F_UNKNOWN_ERROR;
39  }
40 #endif
41 
42  return SCARD_S_SUCCESS;
43 }
44 
45 INTERNAL int DYN_CloseLibrary(void **pvLHandle)
46 {
47 #ifndef PCSCLITE_STATIC_DRIVER
48  int ret;
49 
50  ret = dlclose(*pvLHandle);
51  *pvLHandle = NULL;
52 
53  if (ret)
54  {
55  Log2(PCSC_LOG_CRITICAL, "%s", dlerror());
56  return SCARD_F_UNKNOWN_ERROR;
57  }
58 #endif
59 
60  return SCARD_S_SUCCESS;
61 }
62 
63 INTERNAL int DYN_GetAddress(void *pvLHandle, void **pvFHandle, const char *pcFunction)
64 {
65  char pcFunctionName[256];
66  int rv = SCARD_S_SUCCESS;
67 
68  /* Some platforms might need a leading underscore for the symbol */
69  (void)snprintf(pcFunctionName, sizeof(pcFunctionName), "_%s", pcFunction);
70 
71  *pvFHandle = NULL;
72 #ifndef PCSCLITE_STATIC_DRIVER
73  *pvFHandle = dlsym(pvLHandle, pcFunctionName);
74 
75  /* Failed? Try again without the leading underscore */
76  if (*pvFHandle == NULL)
77  *pvFHandle = dlsym(pvLHandle, pcFunction);
78 
79  if (*pvFHandle == NULL)
80  {
81  Log3(PCSC_LOG_CRITICAL, "%s: %s", pcFunction, dlerror());
83  }
84 #endif
85 
86  return rv;
87 }
88 
89 #endif /* HAVE_DLFCN_H && !HAVE_DL_H && !__APPLE__ */
This abstracts dynamic library loading functions.
#define SCARD_F_UNKNOWN_ERROR
An internal error has been detected, but the source is unknown.
Definition: pcsclite.h:100
This keeps a list of defines for pcsc-lite.
#define SCARD_S_SUCCESS
error codes from http://msdn.microsoft.com/en-us/library/aa924526.aspx
Definition: pcsclite.h:80
This handles debugging.