use pcsc-lite's debuglog.h or syslog

...or no log at all for debugging
This commit is contained in:
Frank Morgner
2015-05-17 14:18:02 +02:00
parent a6e6beb2a9
commit 570bcf996a
9 changed files with 177 additions and 377 deletions

View File

@@ -16,11 +16,16 @@
* You should have received a copy of the GNU General Public License along with
* virtualsmartcard. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "ifd-vpcd.h"
#include "vpcd.h"
#include <debuglog.h>
#include <errno.h>
#include <wintypes.h>
#include <errno.h>
#include <ifdhandler.h>
#include <stdio.h>
#include <stdlib.h>
@@ -33,6 +38,71 @@
PCSCLITE_MAX_READERS_CONTEXTS-6 : 1)
const unsigned char vicc_max_slots = VICC_MAX_SLOTS;
#ifdef HAVE_DEBUGLOG_H
#include <debuglog.h>
#else
enum {
PCSC_LOG_DEBUG = 0,
PCSC_LOG_INFO,
PCSC_LOG_ERROR,
PCSC_LOG_CRITICAL
};
#ifdef HAVE_SYSLOG_H
#include <stdarg.h>
#include <syslog.h>
void log_msg(const int priority, const char *fmt, ...)
{
char debug_buffer[160]; /* up to 2 lines of 80 characters */
va_list argptr;
int syslog_level;
switch(priority) {
case PCSC_LOG_CRITICAL:
syslog_level = LOG_CRIT;
break;
case PCSC_LOG_ERROR:
syslog_level = LOG_ERR;
break;
case PCSC_LOG_INFO:
syslog_level = LOG_INFO;
break;
default:
syslog_level = LOG_DEBUG;
}
va_start(argptr, fmt);
(void)vsnprintf(debug_buffer, sizeof debug_buffer, fmt, argptr);
va_end(argptr);
syslog(syslog_level, "%s", debug_buffer);
}
#define Log0(priority) log_msg(priority, "%s:%d:%s()", __FILE__, __LINE__, __FUNCTION__)
#define Log1(priority, fmt) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__)
#define Log2(priority, fmt, data) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data)
#define Log3(priority, fmt, data1, data2) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2)
#define Log4(priority, fmt, data1, data2, data3) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2, data3)
#define Log5(priority, fmt, data1, data2, data3, data4) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2, data3, data4)
#define Log9(priority, fmt, data1, data2, data3, data4, data5, data6, data7, data8) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2, data3, data4, data5, data6, data7, data8)
#else
#define Log0(priority) do { } while(0)
#define Log1(priority, fmt) do { } while(0)
#define Log2(priority, fmt, data) do { } while(0)
#define Log3(priority, fmt, data1, data2) do { } while(0)
#define Log4(priority, fmt, data1, data2, data3) do { } while(0)
#define Log5(priority, fmt, data1, data2, data3, data4) do { } while(0)
#define Log9(priority, fmt, data1, data2, data3, data4, data5, data6, data7, data8) do { } while(0)
#endif
#endif
static struct vicc_ctx *ctx[VICC_MAX_SLOTS];
const char *hostname = NULL;
static const char openport[] = "/dev/null";

View File

@@ -4,10 +4,10 @@ lib_LTLIBRARIES = libpcsclite.la
libpcsclite_la_CPPFLAGS = $(PCSC_CFLAGS) -I$(srcdir)/../ifd-vpcd -I$(srcdir)/../vpcd
libpcsclite_la_LDFLAGS = -no-undefined -version-info 1:0:0
libpcsclite_la_SOURCES = winscard.c debug.c strlcpy.c error.c
libpcsclite_la_SOURCES = winscard.c error.c
libpcsclite_la_LIBADD = $(top_builddir)/src/ifd-vpcd/libifdvpcd.la
noinst_HEADERS = strlcpycat.h misc.h
noinst_HEADERS = misc.h
nobase_include_HEADERS = \
PCSC/pcsclite.h \

View File

@@ -1,112 +0,0 @@
/*
* MUSCLE SmartCard Development ( http://www.linuxnet.com )
*
* Copyright (C) 1999-2004
* David Corcoran <corcoran@linuxnet.com>
* Copyright (C) 1999-2011
* Ludovic Rousseau <ludovic.rousseau@free.fr>
*
* $Id: debuglog.h 5854 2011-07-09 11:10:32Z rousseau $
*/
/**
* @file
* @brief This handles debugging.
*
* @note log message is sent to syslog or stderr depending on --foreground
* command line argument
*
* @code
* Log1(priority, "text");
* log "text" with priority level priority
* Log2(priority, "text: %d", 1234);
* log "text: 1234"
* the format string can be anything printf() can understand
* Log3(priority, "text: %d %d", 1234, 5678);
* log "text: 1234 5678"
* the format string can be anything printf() can understand
* LogXxd(priority, msg, buffer, size);
* log "msg" + a hex dump of size bytes of buffer[]
* @endcode
*/
#ifndef __debuglog_h__
#define __debuglog_h__
#ifndef PCSC_API
#define PCSC_API
#endif
enum {
DEBUGLOG_NO_DEBUG = 0,
DEBUGLOG_SYSLOG_DEBUG,
DEBUGLOG_STDOUT_DEBUG,
DEBUGLOG_STDOUT_COLOR_DEBUG
};
#define DEBUG_CATEGORY_NOTHING 0
#define DEBUG_CATEGORY_APDU 1
#define DEBUG_CATEGORY_SW 2
enum {
PCSC_LOG_DEBUG = 0,
PCSC_LOG_INFO,
PCSC_LOG_ERROR,
PCSC_LOG_CRITICAL
};
/* You can't do #ifndef __FUNCTION__ */
#if !defined(__GNUC__) && !defined(__IBMC__)
#define __FUNCTION__ ""
#endif
#ifndef __GNUC__
#define __attribute__(x) /*nothing*/
#endif
#ifdef NO_LOG
#define Log0(priority) do { } while(0)
#define Log1(priority, fmt) do { } while(0)
#define Log2(priority, fmt, data) do { } while(0)
#define Log3(priority, fmt, data1, data2) do { } while(0)
#define Log4(priority, fmt, data1, data2, data3) do { } while(0)
#define Log5(priority, fmt, data1, data2, data3, data4) do { } while(0)
#define Log9(priority, fmt, data1, data2, data3, data4, data5, data6, data7, data8) do { } while(0)
#define LogXxd(priority, msg, buffer, size) do { } while(0)
#define DebugLogA(a)
#define DebugLogB(a, b)
#define DebugLogC(a, b,c)
#else
#define Log0(priority) log_msg(priority, "%s:%d:%s()", __FILE__, __LINE__, __FUNCTION__)
#define Log1(priority, fmt) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__)
#define Log2(priority, fmt, data) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data)
#define Log3(priority, fmt, data1, data2) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2)
#define Log4(priority, fmt, data1, data2, data3) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2, data3)
#define Log5(priority, fmt, data1, data2, data3, data4) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2, data3, data4)
#define Log9(priority, fmt, data1, data2, data3, data4, data5, data6, data7, data8) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2, data3, data4, data5, data6, data7, data8)
#define LogXxd(priority, msg, buffer, size) log_xxd(priority, msg, buffer, size)
#define DebugLogA(a) Log1(PCSC_LOG_INFO, a)
#define DebugLogB(a, b) Log2(PCSC_LOG_INFO, a, b)
#define DebugLogC(a, b,c) Log3(PCSC_LOG_INFO, a, b, c)
#endif /* NO_LOG */
PCSC_API void log_msg(const int priority, const char *fmt, ...)
__attribute__((format(printf, 2, 3)));
PCSC_API void log_xxd(const int priority, const char *msg,
const unsigned char *buffer, const int size);
void DebugLogSuppress(const int);
void DebugLogSetLogType(const int);
int DebugLogSetCategory(const int);
void DebugLogCategory(const int, const unsigned char *, const int);
PCSC_API void DebugLogSetLevel(const int level);
#endif /* __debuglog_h__ */

View File

@@ -1,132 +0,0 @@
/*
* MUSCLE SmartCard Development ( http://www.linuxnet.com )
*
* Copyright (C) 1999-2002
* David Corcoran <corcoran@linuxnet.com>
* Copyright (C) 2002-2011
* Ludovic Rousseau <ludovic.rousseau@free.fr>
*
* $Id: debug.c 6551 2013-03-06 13:44:17Z rousseau $
*/
/**
* @file
* @brief This handles debugging for libpcsclite.
*/
#include "config.h"
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include "debuglog.h"
#include "strlcpycat.h"
#define DEBUG_BUF_SIZE 2048
#ifdef NO_LOG
void log_msg(const int priority, const char *fmt, ...)
{
(void)priority;
(void)fmt;
}
#else
/** default level is quiet to avoid polluting fd 2 (possibly NOT stderr) */
static char LogLevel = 20;
static signed char LogDoColor = 0; /**< no color by default */
static void log_init(void)
{
char *e;
#ifdef LIBPCSCLITE
e = getenv("PCSCLITE_DEBUG");
#else
e = getenv("MUSCLECARD_DEBUG");
#endif
if (e)
LogLevel = atoi(e);
/* log to stderr and stderr is a tty? */
if (isatty(fileno(stderr)))
{
char *term;
term = getenv("TERM");
if (term)
{
const char *terms[] = { "linux", "xterm", "xterm-color", "Eterm", "rxvt", "rxvt-unicode" };
unsigned int i;
/* for each known color terminal */
for (i = 0; i < sizeof(terms) / sizeof(terms[0]); i++)
{
/* we found a supported term? */
if (0 == strcmp(terms[i], term))
{
LogDoColor = 1;
break;
}
}
}
}
} /* log_init */
void log_msg(const int priority, const char *fmt, ...)
{
char DebugBuffer[DEBUG_BUF_SIZE];
va_list argptr;
static int is_initialized = 0;
if (!is_initialized)
{
log_init();
is_initialized = 1;
}
if (priority < LogLevel) /* log priority lower than threshold? */
return;
va_start(argptr, fmt);
(void)vsnprintf(DebugBuffer, DEBUG_BUF_SIZE, fmt, argptr);
va_end(argptr);
{
if (LogDoColor)
{
const char *color_pfx = "", *color_sfx = "\33[0m";
switch (priority)
{
case PCSC_LOG_CRITICAL:
color_pfx = "\33[01;31m"; /* bright + Red */
break;
case PCSC_LOG_ERROR:
color_pfx = "\33[35m"; /* Magenta */
break;
case PCSC_LOG_INFO:
color_pfx = "\33[34m"; /* Blue */
break;
case PCSC_LOG_DEBUG:
color_pfx = ""; /* normal (black) */
color_sfx = "";
break;
}
fprintf(stderr, "%s%s%s\n", color_pfx, DebugBuffer, color_sfx);
}
else
fprintf(stderr, "%s\n", DebugBuffer);
}
} /* log_msg */
#endif

View File

@@ -1,8 +1,8 @@
/*
* MUSCLE SmartCard Development ( http://www.linuxnet.com )
* MUSCLE SmartCard Development ( http://pcsclite.alioth.debian.org/pcsclite.html )
*
* Copyright (C) 1999-2002
* David Corcoran <corcoran@linuxnet.com>
* David Corcoran <corcoran@musclecard.com>
* Copyright (C) 2006-2009
* Ludovic Rousseau <ludovic.rousseau@free.fr>
*
@@ -10,7 +10,30 @@
* - BSD-like, see the COPYING file
* - GNU Lesser General Licence 2.1 or (at your option) any later version.
*
* $Id: error.c 5964 2011-09-24 09:22:24Z rousseau $
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id$
*/
/**
@@ -24,7 +47,7 @@
#include "config.h"
#include "misc.h"
#include "pcsclite.h"
#include "strlcpycat.h"
#include "string.h"
#ifdef NO_LOG
PCSC_API char* pcsc_stringify_error(const LONG pcscError)
@@ -57,99 +80,100 @@ PCSC_API char* pcsc_stringify_error(const LONG pcscError)
PCSC_API char* pcsc_stringify_error(const LONG pcscError)
{
static char strError[75];
const char *msg = NULL;
switch (pcscError)
{
case SCARD_S_SUCCESS:
(void)strlcpy(strError, "Command successful.", sizeof(strError));
msg = "Command successful.";
break;
case SCARD_F_INTERNAL_ERROR:
(void)strlcpy(strError, "Internal error.", sizeof(strError));
msg = "Internal error.";
break;
case SCARD_E_CANCELLED:
(void)strlcpy(strError, "Command cancelled.", sizeof(strError));
msg = "Command cancelled.";
break;
case SCARD_E_INVALID_HANDLE:
(void)strlcpy(strError, "Invalid handle.", sizeof(strError));
msg = "Invalid handle.";
break;
case SCARD_E_INVALID_PARAMETER:
(void)strlcpy(strError, "Invalid parameter given.", sizeof(strError));
msg = "Invalid parameter given.";
break;
case SCARD_E_INVALID_TARGET:
(void)strlcpy(strError, "Invalid target given.", sizeof(strError));
msg = "Invalid target given.";
break;
case SCARD_E_NO_MEMORY:
(void)strlcpy(strError, "Not enough memory.", sizeof(strError));
msg = "Not enough memory.";
break;
case SCARD_F_WAITED_TOO_LONG:
(void)strlcpy(strError, "Waited too long.", sizeof(strError));
msg = "Waited too long.";
break;
case SCARD_E_INSUFFICIENT_BUFFER:
(void)strlcpy(strError, "Insufficient buffer.", sizeof(strError));
msg = "Insufficient buffer.";
break;
case SCARD_E_UNKNOWN_READER:
(void)strlcpy(strError, "Unknown reader specified.", sizeof(strError));
msg = "Unknown reader specified.";
break;
case SCARD_E_TIMEOUT:
(void)strlcpy(strError, "Command timeout.", sizeof(strError));
msg = "Command timeout.";
break;
case SCARD_E_SHARING_VIOLATION:
(void)strlcpy(strError, "Sharing violation.", sizeof(strError));
msg = "Sharing violation.";
break;
case SCARD_E_NO_SMARTCARD:
(void)strlcpy(strError, "No smart card inserted.", sizeof(strError));
msg = "No smart card inserted.";
break;
case SCARD_E_UNKNOWN_CARD:
(void)strlcpy(strError, "Unknown card.", sizeof(strError));
msg = "Unknown card.";
break;
case SCARD_E_CANT_DISPOSE:
(void)strlcpy(strError, "Cannot dispose handle.", sizeof(strError));
msg = "Cannot dispose handle.";
break;
case SCARD_E_PROTO_MISMATCH:
(void)strlcpy(strError, "Card protocol mismatch.", sizeof(strError));
msg = "Card protocol mismatch.";
break;
case SCARD_E_NOT_READY:
(void)strlcpy(strError, "Subsystem not ready.", sizeof(strError));
msg = "Subsystem not ready.";
break;
case SCARD_E_INVALID_VALUE:
(void)strlcpy(strError, "Invalid value given.", sizeof(strError));
msg = "Invalid value given.";
break;
case SCARD_E_SYSTEM_CANCELLED:
(void)strlcpy(strError, "System cancelled.", sizeof(strError));
msg = "System cancelled.";
break;
case SCARD_F_COMM_ERROR:
(void)strlcpy(strError, "RPC transport error.", sizeof(strError));
msg = "RPC transport error.";
break;
case SCARD_F_UNKNOWN_ERROR:
(void)strlcpy(strError, "Unknown error.", sizeof(strError));
msg = "Unknown error.";
break;
case SCARD_E_INVALID_ATR:
(void)strlcpy(strError, "Invalid ATR.", sizeof(strError));
msg = "Invalid ATR.";
break;
case SCARD_E_NOT_TRANSACTED:
(void)strlcpy(strError, "Transaction failed.", sizeof(strError));
msg = "Transaction failed.";
break;
case SCARD_E_READER_UNAVAILABLE:
(void)strlcpy(strError, "Reader is unavailable.", sizeof(strError));
msg = "Reader is unavailable.";
break;
/* case SCARD_P_SHUTDOWN: */
case SCARD_E_PCI_TOO_SMALL:
(void)strlcpy(strError, "PCI struct too small.", sizeof(strError));
msg = "PCI struct too small.";
break;
case SCARD_E_READER_UNSUPPORTED:
(void)strlcpy(strError, "Reader is unsupported.", sizeof(strError));
msg = "Reader is unsupported.";
break;
case SCARD_E_DUPLICATE_READER:
(void)strlcpy(strError, "Reader already exists.", sizeof(strError));
msg = "Reader already exists.";
break;
case SCARD_E_CARD_UNSUPPORTED:
(void)strlcpy(strError, "Card is unsupported.", sizeof(strError));
msg = "Card is unsupported.";
break;
case SCARD_E_NO_SERVICE:
(void)strlcpy(strError, "Service not available.", sizeof(strError));
msg = "Service not available.";
break;
case SCARD_E_SERVICE_STOPPED:
(void)strlcpy(strError, "Service was stopped.", sizeof(strError));
msg = "Service was stopped.";
break;
/* case SCARD_E_UNEXPECTED: */
/* case SCARD_E_ICC_CREATEORDER: */
@@ -165,25 +189,25 @@ PCSC_API char* pcsc_stringify_error(const LONG pcscError)
/* case SCARD_E_NO_SUCH_CERTIFICATE: */
/* case SCARD_E_CERTIFICATE_UNAVAILABLE: */
case SCARD_E_NO_READERS_AVAILABLE:
(void)strlcpy(strError, "Cannot find a smart card reader.", sizeof(strError));
msg = "Cannot find a smart card reader.";
break;
/* case SCARD_E_COMM_DATA_LOST: */
/* case SCARD_E_NO_KEY_CONTAINER: */
/* case SCARD_E_SERVER_TOO_BUSY: */
case SCARD_W_UNSUPPORTED_CARD:
(void)strlcpy(strError, "Card is not supported.", sizeof(strError));
msg = "Card is not supported.";
break;
case SCARD_W_UNRESPONSIVE_CARD:
(void)strlcpy(strError, "Card is unresponsive.", sizeof(strError));
msg = "Card is unresponsive.";
break;
case SCARD_W_UNPOWERED_CARD:
(void)strlcpy(strError, "Card is unpowered.", sizeof(strError));
msg = "Card is unpowered.";
break;
case SCARD_W_RESET_CARD:
(void)strlcpy(strError, "Card was reset.", sizeof(strError));
msg = "Card was reset.";
break;
case SCARD_W_REMOVED_CARD:
(void)strlcpy(strError, "Card was removed.", sizeof(strError));
msg = "Card was removed.";
break;
/* case SCARD_W_SECURITY_VIOLATION: */
/* case SCARD_W_WRONG_CHV: */
@@ -193,13 +217,19 @@ PCSC_API char* pcsc_stringify_error(const LONG pcscError)
/* case SCARD_W_CARD_NOT_AUTHENTICATED: */
case SCARD_E_UNSUPPORTED_FEATURE:
(void)strlcpy(strError, "Feature not supported.", sizeof(strError));
msg = "Feature not supported.";
break;
default:
(void)snprintf(strError, sizeof(strError)-1, "Unknown error: 0x%08lX",
pcscError);
};
if (msg)
(void)strncpy(strError, msg, sizeof(strError));
else
(void)snprintf(strError, sizeof(strError)-1, "Unknown error: 0x%08lX",
pcscError);
/* add a null byte */
strError[sizeof(strError)-1] = '\0';

View File

@@ -1,12 +1,35 @@
/*
* This handles GCC attributes
*
* MUSCLE SmartCard Development ( http://www.linuxnet.com )
* MUSCLE SmartCard Development ( http://pcsclite.alioth.debian.org/pcsclite.html )
*
* Copyright (C) 2005-2010
* Ludovic Rousseau <ludovic.rousseau@free.fr>
*
* $Id: misc.h 5434 2010-12-08 14:13:21Z rousseau $
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id$
*/
#ifndef __misc_h__
@@ -55,4 +78,8 @@
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef COUNT_OF
#define COUNT_OF(arr) (sizeof(arr)/sizeof(arr[0]))
#endif
#endif /* __misc_h__ */

View File

@@ -1,60 +0,0 @@
/* $OpenBSD: strlcpy.c,v 1.10 2005/08/08 08:05:37 espie Exp $ */
/*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef HAVE_STRLCPY
#include <sys/types.h>
#include <string.h>
#include "strlcpycat.h"
/*
* Copy src to string dst of size siz. At most siz-1 characters
* will be copied. Always NUL terminates (unless siz == 0).
* Returns strlen(src); if retval >= siz, truncation occurred.
*/
size_t
strlcpy(char *dst, const char *src, size_t siz)
{
char *d = dst;
const char *s = src;
size_t n = siz;
/* Copy as many bytes as will fit */
if (n != 0 && --n != 0) {
do {
if ((*d++ = *s++) == 0)
break;
} while (--n != 0);
}
/* Not enough room in dst, add NUL and traverse rest of src */
if (n == 0) {
if (siz != 0)
*d = '\0'; /* NUL-terminate dst */
while (*s++)
;
}
return(s - src - 1); /* count does not include NUL */
}
#endif

View File

@@ -1,24 +0,0 @@
/*
* MUSCLE SmartCard Development ( http://www.linuxnet.com )
*
* Copyright (C) 2004-2010
* Ludovic Rousseau <ludovic.rousseau@free.fr>
*
* $Id: strlcpycat.h 4974 2010-06-01 09:43:47Z rousseau $
*/
/**
* @file
* @brief prototypes of strlcpy()/strlcat() imported from OpenBSD
*/
#ifdef HAVE_STRLCPY
#include <string.h>
#else
size_t strlcpy(char *dst, const char *src, size_t siz);
#endif
#ifndef HAVE_STRLCAT
size_t strlcat(char *dst, const char *src, size_t siz);
#endif