[Pcsclite-git-commit] [PCSC] 03/03: SCardDisconnect(): refactoring code

Ludovic Rousseau rousseau at moszumanska.debian.org
Sat May 13 19:44:29 UTC 2017


This is an automated email from the git hooks/post-receive script.

rousseau pushed a commit to branch master
in repository PCSC.

commit fd1e32d0b524325a88e7e5b25a8cc2bd897ae668
Author: Ludovic Rousseau <ludovic.rousseau at free.fr>
Date:   Sat May 13 21:38:40 2017 +0200

    SCardDisconnect(): refactoring code
    
    Handle the error cases for SCARD_UNPOWER_CARD and SCARD_RESET_CARD in
    the same code block. This avoids code duplication.
---
 src/winscard.c | 38 ++++++++++++++------------------------
 1 file changed, 14 insertions(+), 24 deletions(-)

diff --git a/src/winscard.c b/src/winscard.c
index 47a0e33..e958b44 100644
--- a/src/winscard.c
+++ b/src/winscard.c
@@ -904,28 +904,12 @@ LONG SCardDisconnect(SCARDHANDLE hCard, DWORD dwDisposition)
 		/* the protocol is unset after a power on */
 		rContext->readerState->cardProtocol = SCARD_PROTOCOL_UNDEFINED;
 
-		if (SCARD_UNPOWER_CARD == dwDisposition)
+		if (rv == SCARD_S_SUCCESS)
 		{
-			if (rv == SCARD_S_SUCCESS)
+			if (SCARD_UNPOWER_CARD == dwDisposition)
 				rContext->readerState->readerState = SCARD_PRESENT;
 			else
 			{
-				Log3(PCSC_LOG_ERROR, "Error powering down card: %ld 0x%04lX",
-					rv, rv);
-				if (rv == SCARD_W_REMOVED_CARD)
-					rContext->readerState->readerState = SCARD_ABSENT;
-				else
-					rContext->readerState->readerState =
-						SCARD_PRESENT | SCARD_SWALLOWED;
-			}
-		}
-		else
-		{
-			/*
-			 * Set up the status bit masks on readerState
-			 */
-			if (rv == SCARD_S_SUCCESS)
-			{
 				rContext->readerState->cardAtrLength = dwAtrLen;
 				rContext->readerState->readerState =
 					SCARD_PRESENT | SCARD_POWERED | SCARD_NEGOTIABLE;
@@ -935,17 +919,23 @@ LONG SCardDisconnect(SCARDHANDLE hCard, DWORD dwDisposition)
 					rContext->readerState->cardAtr,
 					rContext->readerState->cardAtrLength);
 			}
+		}
+		else
+		{
+			if (SCARD_UNPOWER_CARD == dwDisposition)
+				Log3(PCSC_LOG_ERROR, "Error powering down card: %ld 0x%04lX",
+					rv, rv);
 			else
 			{
 				rContext->readerState->cardAtrLength = 0;
 				Log1(PCSC_LOG_ERROR, "Error resetting card.");
-
-				if (rv == SCARD_W_REMOVED_CARD)
-					rContext->readerState->readerState = SCARD_ABSENT;
-				else
-					rContext->readerState->readerState =
-						SCARD_PRESENT | SCARD_SWALLOWED;
 			}
+
+			if (rv == SCARD_W_REMOVED_CARD)
+				rContext->readerState->readerState = SCARD_ABSENT;
+			else
+				rContext->readerState->readerState =
+					SCARD_PRESENT | SCARD_SWALLOWED;
 		}
 	}
 	else if (dwDisposition == SCARD_EJECT_CARD)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pcsclite/PCSC.git



More information about the Pcsclite-cvs-commit mailing list