[Pcsclite-cvs-commit] CVS PCSC/src

CVS User rousseau ludovic.rousseau@free.fr
Tue, 14 Sep 2004 01:33:18 -0600


Update of /cvsroot/pcsclite/PCSC/src
In directory haydn:/tmp/cvs-serv15020

Modified Files:
	winscard_clnt.c 
Log Message:
SCardListReaders(): simplify the code


--- /cvsroot/pcsclite/PCSC/src/winscard_clnt.c	2004/09/14 07:16:24	1.45
+++ /cvsroot/pcsclite/PCSC/src/winscard_clnt.c	2004/09/14 07:33:18	1.46
@@ -9,7 +9,7 @@
  *  Damien Sauveron <damien.sauveron@labri.fr>
  *  Ludovic Rousseau <ludovic.rousseau@free.fr>
  *
- * $Id: winscard_clnt.c,v 1.45 2004/09/14 07:16:24 rousseau Exp $
+ * $Id: winscard_clnt.c,v 1.46 2004/09/14 07:33:18 rousseau Exp $
  */
 
 #include "config.h"
@@ -1810,14 +1810,14 @@
 LONG SCardListReaders(SCARDCONTEXT hContext, LPCTSTR mszGroups,
 	LPTSTR mszReaders, LPDWORD pcchReaders)
 {
-	DWORD dwReadersLen = 0;
-	int i, lastChrPtr = 0;
+	DWORD dwReadersLen;
+	int i, lastChrPtr;
 	DWORD dwContextIndex;
 
 	/*
 	 * Check for NULL parameters
 	 */
-	if (pcchReaders == 0)
+	if (pcchReaders == NULL)
 		return SCARD_E_INVALID_PARAMETER;
 
 	if (SCardCheckDaemonAvailability() != SCARD_S_SUCCESS)
@@ -1832,46 +1832,42 @@
 
 	SYS_MutexLock(psContextMap[dwContextIndex].mMutex);	
 
+	dwReadersLen = 0;
 	for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
-	{
 		if ((readerStates[i])->readerID != 0)
-		{
-			dwReadersLen += (strlen((readerStates[i])->readerName) + 1);
-		}
-	}
+			dwReadersLen += strlen((readerStates[i])->readerName) + 1;
 
+	/* for the last NULL byte */
 	dwReadersLen += 1;
 
-	if (mszReaders == 0)
+	if ((mszReaders == NULL)	/* text array not allocated */
+		|| (*pcchReaders == 0))	/* size == 0 */
 	{
 		*pcchReaders = dwReadersLen;
 		SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);	
 		return SCARD_S_SUCCESS;
-	} else if (*pcchReaders == 0)
-	{
-		*pcchReaders = dwReadersLen;
-		SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);	
-		return SCARD_S_SUCCESS;
-	} else if (*pcchReaders < dwReadersLen)
+	}
+	
+	if (*pcchReaders < dwReadersLen)
 	{
 		*pcchReaders = dwReadersLen;
 		SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);	
 		return SCARD_E_INSUFFICIENT_BUFFER;
-	} else
+	}
+
+	lastChrPtr = 0;
+	for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
 	{
-		for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
+		if ((readerStates[i])->readerID != 0)
 		{
-			if ((readerStates[i])->readerID != 0)
-			{
-				/*
-				 * Build the multi-string
-				 */
-				strcpy(&mszReaders[lastChrPtr], (readerStates[i])->readerName);
-				lastChrPtr += strlen((readerStates[i])->readerName)+1;
-			}
+			/*
+			 * Build the multi-string
+			 */
+			strcpy(&mszReaders[lastChrPtr], (readerStates[i])->readerName);
+			lastChrPtr += strlen((readerStates[i])->readerName)+1;
 		}
-		mszReaders[lastChrPtr] = '\0';	/* Add the last null */
 	}
+	mszReaders[lastChrPtr] = '\0';	/* Add the last null */
 
 	*pcchReaders = dwReadersLen;