pcsc-lite 2.3.0
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-2024
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#ifndef __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 void * DYN_LoadLibrary(const char *pcLibrary)
52{
53 void *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());
60 }
61#endif
62
63 return pvLHandle;
64}
65
66INTERNAL LONG DYN_CloseLibrary(void *pvLHandle)
67{
68#ifndef PCSCLITE_STATIC_DRIVER
69 int ret;
70
71 ret = dlclose(pvLHandle);
72
73 if (ret)
74 {
75 Log2(PCSC_LOG_CRITICAL, "%s", dlerror());
77 }
78#endif
79
80 return SCARD_S_SUCCESS;
81}
82
83INTERNAL LONG DYN_GetAddress(void *pvLHandle, void **pvFHandle,
84 const char *pcFunction, bool mayfail)
85{
86 char pcFunctionName[256];
87 LONG rv = SCARD_S_SUCCESS;
88
89 /* Some platforms might need a leading underscore for the symbol */
90 (void)snprintf(pcFunctionName, sizeof(pcFunctionName), "_%s", pcFunction);
91
92 *pvFHandle = NULL;
93#ifndef PCSCLITE_STATIC_DRIVER
94 *pvFHandle = dlsym(pvLHandle, pcFunctionName);
95
96 /* Failed? Try again without the leading underscore */
97 if (*pvFHandle == NULL)
98 *pvFHandle = dlsym(pvLHandle, pcFunction);
99
100 if (*pvFHandle == NULL)
101 {
102#ifdef NO_LOG
103 (void)mayfail;
104#endif
105 Log3(mayfail ? PCSC_LOG_INFO : PCSC_LOG_CRITICAL, "%s: %s",
106 pcFunction, dlerror());
108 }
109#endif
110
111 return rv;
112}
113
114#endif /* !__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.