Show
Ignore:
Timestamp:
07/02/08 11:55:32 (5 months ago)
Author:
alonbl
Message:

Make PC/SC work on Windows again

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/libopensc/reader-pcsc.c

    r3520 r3535  
    826826 
    827827out: 
    828         if (ret != SC_SUCCESS) { 
    829                 if (gpriv->pcsc_ctx != 0) 
     828        if (gpriv != NULL) { 
     829                if (gpriv->dlhandle != NULL) 
     830                        lt_dlclose(gpriv->dlhandle); 
     831                free(gpriv); 
     832        } 
     833 
     834        return ret; 
     835} 
     836 
     837static int pcsc_finish(sc_context_t *ctx, void *prv_data) 
     838{ 
     839        struct pcsc_global_private_data *gpriv = (struct pcsc_global_private_data *) prv_data; 
     840 
     841        if (gpriv) { 
     842                if (gpriv->pcsc_ctx != -1) 
    830843                        gpriv->SCardReleaseContext(gpriv->pcsc_ctx); 
    831844                if (gpriv->dlhandle != NULL) 
    832845                        lt_dlclose(gpriv->dlhandle); 
    833                 if (gpriv != NULL) 
    834                         free(gpriv); 
    835         } 
    836  
    837         return 0; 
    838 } 
    839  
    840 static int pcsc_finish(sc_context_t *ctx, void *prv_data) 
    841 { 
    842         struct pcsc_global_private_data *priv = (struct pcsc_global_private_data *) prv_data; 
    843  
    844         if (priv) { 
    845                 priv->SCardReleaseContext(priv->pcsc_ctx); 
    846                 lt_dlclose(priv->dlhandle); 
    847                 free(priv); 
     846                free(gpriv); 
    848847        } 
    849848 
     
    860859        int ret = SC_ERROR_INTERNAL; 
    861860 
    862         if (!prv_data) { 
     861        if (!gpriv) { 
    863862                ret = SC_ERROR_NO_READERS_FOUND; 
    864863                goto out; 
     
    866865 
    867866        do { 
    868                 rv = gpriv->SCardListReaders(gpriv->pcsc_ctx, NULL, NULL, 
    869                                       (LPDWORD) &reader_buf_size); 
     867                if (gpriv->pcsc_ctx == -1) { 
     868                        /* 
     869                         * Cannot call SCardListReaders with -1 
     870                         * context as in Windows ERROR_INVALID_HANDLE 
     871                         * is returned instead of SCARD_E_INVALID_HANDLE 
     872                         */ 
     873                        rv = SCARD_E_INVALID_HANDLE; 
     874                } 
     875                else { 
     876                        rv = gpriv->SCardListReaders(gpriv->pcsc_ctx, NULL, NULL, 
     877                                              (LPDWORD) &reader_buf_size); 
     878                } 
    870879                if (rv != SCARD_S_SUCCESS) { 
    871880                        if (rv != SCARD_E_INVALID_HANDLE) {