Hello Alon,

I do not understand your patch. In which cases SCardListReaders() is
returning ERROR_INVALID_HANDLE?
This error code is not a PC/SC error code. I checked with pcsc-lite
and SCardListReaders(-1, ...) correctly returns SCARD_E_INVALID_HANDLE

I guess it is the same on Windows.

Are you using a "very" old version of pcsc-lite?

Bye

On Wed, Jul 2, 2008 at 11:55 AM,  <[EMAIL PROTECTED]> wrote:
> Revision: 3535
> Author:   alonbl
> Date:     2008-07-02 11:55:32 +0200 (Wed, 02 Jul 2008)
>
> Log Message:
> -----------
> Make PC/SC work on Windows again
>
> Modified Paths:
> --------------
>    trunk/src/libopensc/reader-pcsc.c
> Modified: trunk/src/libopensc/reader-pcsc.c
> ===================================================================
> --- trunk/src/libopensc/reader-pcsc.c   2008-06-11 10:14:43 UTC (rev 3534)
> +++ trunk/src/libopensc/reader-pcsc.c   2008-07-02 09:55:32 UTC (rev 3535)
> @@ -825,26 +825,25 @@
>        ret = SC_SUCCESS;
>
>  out:
> -       if (ret != SC_SUCCESS) {
> -               if (gpriv->pcsc_ctx != 0)
> -                       gpriv->SCardReleaseContext(gpriv->pcsc_ctx);
> +       if (gpriv != NULL) {
>                if (gpriv->dlhandle != NULL)
>                        lt_dlclose(gpriv->dlhandle);
> -               if (gpriv != NULL)
> -                       free(gpriv);
> +               free(gpriv);
>        }
>
> -       return 0;
> +       return ret;
>  }
>
>  static int pcsc_finish(sc_context_t *ctx, void *prv_data)
>  {
> -       struct pcsc_global_private_data *priv = (struct 
> pcsc_global_private_data *) prv_data;
> +       struct pcsc_global_private_data *gpriv = (struct 
> pcsc_global_private_data *) prv_data;
>
> -       if (priv) {
> -               priv->SCardReleaseContext(priv->pcsc_ctx);
> -               lt_dlclose(priv->dlhandle);
> -               free(priv);
> +       if (gpriv) {
> +               if (gpriv->pcsc_ctx != -1)
> +                       gpriv->SCardReleaseContext(gpriv->pcsc_ctx);
> +               if (gpriv->dlhandle != NULL)
> +                       lt_dlclose(gpriv->dlhandle);
> +               free(gpriv);
>        }
>
>        return 0;
> @@ -859,14 +858,24 @@
>        const char *mszGroups = NULL;
>        int ret = SC_ERROR_INTERNAL;
>
> -       if (!prv_data) {
> +       if (!gpriv) {
>                ret = SC_ERROR_NO_READERS_FOUND;
>                goto out;
>        }
>
>        do {
> -               rv = gpriv->SCardListReaders(gpriv->pcsc_ctx, NULL, NULL,
> -                                     (LPDWORD) &reader_buf_size);
> +               if (gpriv->pcsc_ctx == -1) {
> +                       /*
> +                        * Cannot call SCardListReaders with -1
> +                        * context as in Windows ERROR_INVALID_HANDLE
> +                        * is returned instead of SCARD_E_INVALID_HANDLE
> +                        */
> +                       rv = SCARD_E_INVALID_HANDLE;
> +               }
> +               else {
> +                       rv = gpriv->SCardListReaders(gpriv->pcsc_ctx, NULL, 
> NULL,
> +                                             (LPDWORD) &reader_buf_size);
> +               }
>                if (rv != SCARD_S_SUCCESS) {
>                        if (rv != SCARD_E_INVALID_HANDLE) {
>                                ret = pcsc_ret_to_error(rv);


-- 
 Dr. Ludovic Rousseau
_______________________________________________
opensc-devel mailing list
opensc-devel@lists.opensc-project.org
http://www.opensc-project.org/mailman/listinfo/opensc-devel

Reply via email to