[Pcsclite-cvs-commit] PCSC/src Makefile.am,1.25,1.26 dyn_unix.c,1.3,1.4 dyn_win32.c,1.2,1.3 pcscdaemon.c,1.28,1.29 sys_generic.h,1.4,1.5 sys_unix.c,1.4,1.5 thread_generic.h,1.5,1.6 thread_unix.c,1.4,1.5 thread_win32.c,1.2,1.3 dyn_bsd.c,1.3,NONE sys_hpux.c,1.4,NONE sys_solaris.c,1.4,NONE thread_macosx.c,1.3,NONE
aet-guest@quantz.debian.org
aet-guest@quantz.debian.org
Sun, 07 Sep 2003 19:20:24 +0200
Update of /cvsroot/pcsclite/PCSC/src
In directory quantz:/tmp/cvs-serv29591/src
Modified Files:
Makefile.am dyn_unix.c dyn_win32.c pcscdaemon.c sys_generic.h
sys_unix.c thread_generic.h thread_unix.c thread_win32.c
Removed Files:
dyn_bsd.c sys_hpux.c sys_solaris.c thread_macosx.c
Log Message:
- Removed most of the duplicated code, replaced
with the usage of config.h's defines for
portability issues:
- Merged dyn_{bsd,unix}.c, left as dyn_unix.c
- Merged thread_{macosx,unix}.c, left as thread_unix.c
- Merged sys_{hpux,solaris,unix}.c, left as sys_unix.c
- Removed MSC_ thread API from generic / win32,
they're not used.
Starting from now, the source tree might be broken for a
few hours or even days. Sorry about that.
Index: Makefile.am
===================================================================
RCS file: /cvsroot/pcsclite/PCSC/src/Makefile.am,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- Makefile.am 4 Sep 2003 20:51:10 -0000 1.25
+++ Makefile.am 7 Sep 2003 17:20:22 -0000 1.26
@@ -38,7 +38,7 @@
PCSC_INCLUDE_LIBS = -lfl
PCSCD_INCLUDE_LIBS = -lfl -pthread
PCSC_THREAD_SOURCE = thread_unix.c thread_generic.h
-PCSC_DYNLOAD_SOURCE = dyn_bsd.c dyn_generic.h
+PCSC_DYNLOAD_SOURCE = dyn_unix.c dyn_generic.h
PCSC_SYSTEM_SOURCE = sys_unix.c sys_generic.h
PCSC_CLIENT_SRC = winscard_clnt.c
if PCSC_USE_LIBUSB
@@ -52,7 +52,7 @@
PCSC_MYLDFLAGS = -framework CoreFoundation
PCSC_INCLUDE_LIBS = -ll -lIOKit
PCSCD_INCLUDE_LIBS = -ll -lIOKit
-PCSC_THREAD_SOURCE = thread_macosx.c thread_generic.h
+PCSC_THREAD_SOURCE = thread_unix.c thread_generic.h
PCSC_DYNLOAD_SOURCE = dyn_macosx.c dyn_generic.h
PCSC_HOTPLUG_SOURCE = hotplug_macosx.c hotplug.h powermgt_macosx.c \
powermgt_generic.h
@@ -78,7 +78,7 @@
PCSC_THREAD_SOURCE = thread_unix.c thread_generic.h
PCSC_DYNLOAD_SOURCE = dyn_unix.c dyn_generic.h
PCSC_HOTPLUG_SOURCE = hotplug_generic.c hotplug.h
-PCSC_SYSTEM_SOURCE = sys_solaris.c sys_generic.h
+PCSC_SYSTEM_SOURCE = sys_unix.c sys_generic.h
endif
if PCSC_ARCH_HPUX
@@ -88,7 +88,7 @@
PCSC_THREAD_SOURCE = thread_unix.c thread_generic.h
PCSC_DYNLOAD_SOURCE = dyn_hpux.c dyn_generic.h
PCSC_HOTPLUG_SOURCE = hotplug_generic.c hotplug.h
-PCSC_SYSTEM_SOURCE = sys_hpux.c sys_generic.h
+PCSC_SYSTEM_SOURCE = sys_unix.c sys_generic.h
PCSC_CLIENT_SRC = winscard_clnt.c
endif
Index: dyn_unix.c
===================================================================
RCS file: /cvsroot/pcsclite/PCSC/src/dyn_unix.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- dyn_unix.c 4 Apr 2002 23:47:24 -0000 1.3
+++ dyn_unix.c 7 Sep 2003 17:20:22 -0000 1.4
@@ -5,8 +5,7 @@
Package: pcsc lite
Author : David Corcoran
Date : 8/12/99
- License: Copyright (C) 1999 David Corcoran
- <corcoran@linuxnet.com>
+ License: Copyright (C) 1999 David Corcoran <corcoran@linuxnet.com>
Purpose: This abstracts dynamic library loading functions and timing.
$Id$
@@ -15,6 +14,7 @@
#include <string.h>
#include <dlfcn.h>
+#include <stdlib.h>
#include "config.h"
#include "wintypes.h"
@@ -24,7 +24,7 @@
int DYN_LoadLibrary(void **pvLHandle, char *pcLibrary)
{
- *pvLHandle = 0;
+ *pvLHandle = NULL;
*pvLHandle = dlopen(pcLibrary, RTLD_LAZY);
if (*pvLHandle == NULL)
@@ -41,7 +41,7 @@
int ret;
ret = dlclose(*pvLHandle);
- *pvLHandle = 0;
+ *pvLHandle = NULL;
if (ret)
{
@@ -54,28 +54,38 @@
int DYN_GetAddress(void *pvLHandle, void **pvFHandle, char *pcFunction)
{
- int rv;
+ int rv, iSize;
char *pcFunctionName;
/*
* Zero out everything
*/
rv = 0;
- pcFunctionName = 0;
+ pcFunctionName = NULL;
+ iSize = 0;
- pcFunctionName = pcFunction;
+ iSize = strlen(pcFunction) + 2; /* 1-NULL, 2-_ */
+ pcFunctionName = (char *) malloc(iSize * sizeof(char));
+ pcFunctionName[0] = '_';
+ strcpy(&pcFunctionName[1], pcFunction);
- *pvFHandle = 0;
+ *pvFHandle = NULL;
*pvFHandle = dlsym(pvLHandle, pcFunctionName);
+ /*
+ * also try without a leading '_' (needed for FreeBSD)
+ */
+ if (*pvFHandle == NULL)
+ *pvFHandle = dlsym(pvLHandle, pcFunction);
+
if (*pvFHandle == NULL)
{
DebugLogB("DYN_GetAddress: dlerror() reports %s", dlerror());
rv = SCARD_F_UNKNOWN_ERROR;
- }
- else
+ } else
rv = SCARD_S_SUCCESS;
+ free(pcFunctionName);
+
return rv;
}
-
Index: dyn_win32.c
===================================================================
RCS file: /cvsroot/pcsclite/PCSC/src/dyn_win32.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- dyn_win32.c 7 May 2002 02:02:55 -0000 1.2
+++ dyn_win32.c 7 Sep 2003 17:20:22 -0000 1.3
@@ -14,7 +14,6 @@
********************************************************************/
#include <string.h>
-//#include <dlfcn.h>
#include "../win32/win32_config.h"
#include "windows.h"
Index: pcscdaemon.c
===================================================================
RCS file: /cvsroot/pcsclite/PCSC/src/pcscdaemon.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- pcscdaemon.c 19 Aug 2003 09:27:43 -0000 1.28
+++ pcscdaemon.c 7 Sep 2003 17:20:22 -0000 1.29
@@ -358,32 +358,8 @@
if (setToForeground == 0)
{
-#ifndef HAVE_DAEMON
- switch (SYS_Fork())
- {
- case -1:
- return (-1);
- case 0:
- break;
- default:
- return (0);
- }
-
- if (SYS_CloseFile(0))
- DebugLogB("main: SYS_CloseFile(0) failed: %s", strerror(errno));
-
- if (SYS_CloseFile(1))
- DebugLogB("main: SYS_CloseFile(1) failed: %s", strerror(errno));
-
- if (SYS_CloseFile(2))
- DebugLogB("main: SYS_CloseFile(2) failed: %s", strerror(errno));
-
- if (SYS_Chdir("/"))
- DebugLogB("main: SYS_Chdir() failed: %s", strerror(errno));
-#else
if (SYS_Daemon(0, 0))
DebugLogB("main: SYS_Daemon() failed: %s", strerror(errno));
-#endif
}
/*
Index: sys_generic.h
===================================================================
RCS file: /cvsroot/pcsclite/PCSC/src/sys_generic.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- sys_generic.h 22 Apr 2002 18:42:44 -0000 1.4
+++ sys_generic.h 7 Sep 2003 17:20:22 -0000 1.5
@@ -77,9 +77,7 @@
int SYS_Fork();
-#ifdef HAVE_DAEMON
int SYS_Daemon(int, int);
-#endif
int SYS_Wait(int, int);
Index: sys_unix.c
===================================================================
RCS file: /cvsroot/pcsclite/PCSC/src/sys_unix.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- sys_unix.c 22 Apr 2002 18:42:44 -0000 1.4
+++ sys_unix.c 7 Sep 2003 17:20:22 -0000 1.5
@@ -33,7 +33,7 @@
int SYS_Initialize()
{
/*
- * Nothing special for OS X and Linux
+ * Nothing special
*/
return 0;
}
@@ -50,13 +50,29 @@
int SYS_Sleep(int iTimeVal)
{
+#ifdef HAVE_NANOSLEEP
+ struct timespec mrqtp;
+ mrqtp.tv_sec = iTimeVal;
+ mrqtp.tv_nsec = 0;
+
+ return nanosleep(&mrqtp, NULL);
+#else
return sleep(iTimeVal);
+#endif
}
int SYS_USleep(int iTimeVal)
{
+#ifdef HAVE_NANOSLEEP
+ struct timespec mrqtp;
+ mrqtp.tv_sec = 0;
+ mrqtp.tv_nsec = iTimeVal * 1000;
+
+ return nanosleep(&mrqtp, NULL);
+#else
usleep(iTimeVal);
return iTimeVal;
+#endif
}
int SYS_OpenFile(char *pcFile, int flags, int mode)
@@ -116,17 +132,50 @@
int SYS_LockFile(int iHandle)
{
+#ifdef HAVE_FLOCK
return flock(iHandle, LOCK_EX | LOCK_NB);
+#else
+ struct flock lock_s;
+
+ lock_s.l_type = F_WRLCK;
+ lock_s.l_whence = 0;
+ lock_s.l_start = 0L;
+ lock_s.l_len = 0L;
+
+ return fcntl(iHandle, F_SETLK, &lock_s);
+#endif
}
int SYS_LockAndBlock(int iHandle)
{
+#ifdef HAVE_FLOCK
return flock(iHandle, LOCK_EX);
+#else
+ struct flock lock_s;
+
+ lock_s.l_type = F_RDLCK;
+ lock_s.l_whence = 0;
+ lock_s.l_start = 0L;
+ lock_s.l_len = 0L;
+
+ return fcntl(iHandle, F_SETLKW, &lock_s);
+#endif
}
int SYS_UnlockFile(int iHandle)
{
+#ifdef HAVE_FLOCK
return flock(iHandle, LOCK_UN);
+#else
+ struct flock lock_s;
+
+ lock_s.l_type = F_UNLCK;
+ lock_s.l_whence = 0;
+ lock_s.l_start = 0L;
+ lock_s.l_len = 0L;
+
+ return fcntl(iHandle, F_SETLK, &lock_s);
+#endif
}
int SYS_SeekFile(int iHandle, int iSeekLength)
@@ -182,7 +231,12 @@
int SYS_MMapSynchronize(void *begin, int length)
{
- return msync(begin, length, MS_SYNC | MS_INVALIDATE);
+ int flags = 0;
+
+#ifdef MS_INVALIDATE
+ flags |= MS_INVALIDATE;
+#endif
+ return msync(begin, length, MS_SYNC | flags);
}
int SYS_Fork()
@@ -190,12 +244,37 @@
return fork();
}
-#ifdef HAVE_DAEMON
int SYS_Daemon(int nochdir, int noclose)
{
+#ifdef HAVE_DAEMON
return daemon(nochdir, noclose);
-}
+#else
+ switch (SYS_Fork())
+ {
+ case -1:
+ return (-1);
+ case 0:
+ break;
+ default:
+ return (0);
+ }
+
+ if (!noclose) {
+ if (SYS_CloseFile(0))
+ DebugLogB("main: SYS_CloseFile(0) failed: %s", strerror(errno));
+
+ if (SYS_CloseFile(1))
+ DebugLogB("main: SYS_CloseFile(1) failed: %s", strerror(errno));
+
+ if (SYS_CloseFile(2))
+ DebugLogB("main: SYS_CloseFile(2) failed: %s", strerror(errno));
+ }
+ if (!nochdir) {
+ if (SYS_Chdir("/"))
+ DebugLogB("main: SYS_Chdir() failed: %s", strerror(errno));
+ }
#endif
+}
int SYS_Wait(int iPid, int iWait)
{
@@ -261,4 +340,3 @@
{
return unlink(pcFile);
}
-
Index: thread_generic.h
===================================================================
RCS file: /cvsroot/pcsclite/PCSC/src/thread_generic.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- thread_generic.h 5 Jun 2003 00:47:21 -0000 1.5
+++ thread_generic.h 7 Sep 2003 17:20:22 -0000 1.6
@@ -49,12 +49,6 @@
int SYS_ThreadJoin(PCSCLITE_THREAD_T *, LPVOID*);
int SYS_ThreadExit(LPVOID);
-
- PCSC_API int MSC_MutexInit(PCSCLITE_MUTEX_T);
- PCSC_API int MSC_MutexDestroy(PCSCLITE_MUTEX_T);
- PCSC_API int MSC_MutexLock(PCSCLITE_MUTEX_T);
- PCSC_API int MSC_MutexUnLock(PCSCLITE_MUTEX_T);
-
#ifdef __cplusplus
}
#endif
Index: thread_unix.c
===================================================================
RCS file: /cvsroot/pcsclite/PCSC/src/thread_unix.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- thread_unix.c 5 Jun 2002 18:11:32 -0000 1.4
+++ thread_unix.c 7 Sep 2003 17:20:22 -0000 1.5
@@ -116,17 +116,6 @@
int SYS_ThreadExit(LPVOID pvRetVal)
{
- int retval;
-
pthread_exit(pvRetVal);
-
- retval = *(int *)pvRetVal;
-
- if (retval == 0)
- {
- return 1;
- } else
- {
- return 0;
- }
+ return 1;
}
Index: thread_win32.c
===================================================================
RCS file: /cvsroot/pcsclite/PCSC/src/thread_win32.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- thread_win32.c 5 Jun 2003 00:47:21 -0000 1.2
+++ thread_win32.c 7 Sep 2003 17:20:22 -0000 1.3
@@ -153,19 +153,3 @@
return 0;
}
-
-int MSC_MutexInit(PCSCLITE_MUTEX_T theMutex) {
- return SYS_MutexInit(theMutex);
-}
-
-int MSC_MutexDestroy(PCSCLITE_MUTEX_T theMutex) {
- return SYS_MutexDestroy(theMutex);
-}
-
-int MSC_MutexLock(PCSCLITE_MUTEX_T theMutex) {
- return SYS_MutexLock(theMutex);
-}
-
-int MSC_MutexUnLock(PCSCLITE_MUTEX_T theMutex) {
- return SYS_MutexUnLock(theMutex);
-}
\ No newline at end of file
--- dyn_bsd.c DELETED ---
--- sys_hpux.c DELETED ---
--- sys_solaris.c DELETED ---
--- thread_macosx.c DELETED ---