pcsc-lite 1.9.9
dyn_unix.c
Go to the documentation of this file.
1/*
2 * MUSCLE SmartCard Development ( https://pcsclite.apdu.fr/ )
3 *
4 * Copyright (C) 1999-2002
5 * David Corcoran <corcoran@musclecard.com>
6 * Copyright (C) 2002-2010
7 * Ludovic Rousseau <ludovic.rousseau@free.fr>
8 *
9Redistribution and use in source and binary forms, with or without
10modification, are permitted provided that the following conditions
11are met:
12
131. Redistributions of source code must retain the above copyright
14 notice, this list of conditions and the following disclaimer.
152. Redistributions in binary form must reproduce the above copyright
16 notice, this list of conditions and the following disclaimer in the
17 documentation and/or other materials provided with the distribution.
183. The name of the author may not be used to endorse or promote products
19 derived from this software without specific prior written permission.
20
21THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
38#include "config.h"
39#include <stdio.h>
40#include <string.h>
41#if defined(HAVE_DLFCN_H) && !defined(HAVE_DL_H) && !defined(__APPLE__)
42#include <dlfcn.h>
43#include <stdlib.h>
44#include <stdbool.h>
45
46#include "misc.h"
47#include "pcsclite.h"
48#include "debuglog.h"
49#include "dyn_generic.h"
50
51INTERNAL LONG DYN_LoadLibrary(void **pvLHandle, char *pcLibrary)
52{
53 *pvLHandle = NULL;
54#ifndef PCSCLITE_STATIC_DRIVER
55 *pvLHandle = dlopen(pcLibrary, RTLD_LAZY);
56
57 if (*pvLHandle == NULL)
58 {
59 Log3(PCSC_LOG_CRITICAL, "%s: %s", pcLibrary, dlerror());
61 }
62#endif
63
64 return SCARD_S_SUCCESS;
65}
66
67INTERNAL LONG DYN_CloseLibrary(void **pvLHandle)
68{
69#ifndef PCSCLITE_STATIC_DRIVER
70 int ret;
71
72 ret = dlclose(*pvLHandle);
73 *pvLHandle = NULL;
74
75 if (ret)
76 {
77 Log2(PCSC_LOG_CRITICAL, "%s", dlerror());
79 }
80#endif
81
82 return SCARD_S_SUCCESS;
83}
84
85INTERNAL LONG DYN_GetAddress(void *pvLHandle, void **pvFHandle,
86 const char *pcFunction, bool mayfail)
87{
88 char pcFunctionName[256];
89 LONG rv = SCARD_S_SUCCESS;
90
91 /* Some platforms might need a leading underscore for the symbol */
92 (void)snprintf(pcFunctionName, sizeof(pcFunctionName), "_%s", pcFunction);
93
94 *pvFHandle = NULL;
95#ifndef PCSCLITE_STATIC_DRIVER
96 *pvFHandle = dlsym(pvLHandle, pcFunctionName);
97
98 /* Failed? Try again without the leading underscore */
99 if (*pvFHandle == NULL)
100 *pvFHandle = dlsym(pvLHandle, pcFunction);
101
102 if (*pvFHandle == NULL)
103 {
104#ifdef NO_LOG
105 (void)mayfail;
106#endif
107 Log3(mayfail ? PCSC_LOG_INFO : PCSC_LOG_CRITICAL, "%s: %s",
108 pcFunction, dlerror());
110 }
111#endif
112
113 return rv;
114}
115
116#endif /* HAVE_DLFCN_H && !HAVE_DL_H && !__APPLE__ */
This handles debugging.
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:147
#define SCARD_S_SUCCESS
No error was encountered.
Definition pcsclite.h:107
This keeps a list of defines for pcsc-lite.