- Added sanity check for sc_establish_context.
If no readers are found, fail and return SC_ERROR_NO_READERS_FOUND. git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@403 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
parent
e589a94aac
commit
88530c8dba
|
@ -319,6 +319,10 @@ int sc_establish_context(struct sc_context **ctx_out, const char *app_name)
|
|||
del_drvs(&opts, 0);
|
||||
del_drvs(&opts, 1);
|
||||
|
||||
if (ctx->reader_count == 0) {
|
||||
sc_release_context(ctx);
|
||||
return SC_ERROR_NO_READERS_FOUND;
|
||||
}
|
||||
*ctx_out = ctx;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ int sc_test_init(int *argc, char *argv[])
|
|||
|
||||
printf("Using libopensc version %s.\n", sc_version);
|
||||
i = sc_establish_context(&ctx, "tests");
|
||||
if (i < 0) {
|
||||
printf("sc_establish_context() failed (%d)\n", i);
|
||||
if (i != SC_SUCCESS) {
|
||||
printf("Failed to establish context: %s\n", sc_strerror(i));
|
||||
return i;
|
||||
}
|
||||
i = sc_detect_card_presence(ctx->reader[0], 0);
|
||||
|
@ -49,8 +49,8 @@ int sc_test_init(int *argc, char *argv[])
|
|||
printf("Connecting... ");
|
||||
fflush(stdout);
|
||||
i = sc_connect_card(ctx->reader[c], 0, &card);
|
||||
if (i != 0) {
|
||||
printf("Connecting to card failed\n");
|
||||
if (i != SC_SUCCESS) {
|
||||
printf("Connecting to card failed: %s\n", sc_strerror(i));
|
||||
return i;
|
||||
}
|
||||
printf("connected.\nATR = ");
|
||||
|
|
Loading…
Reference in New Issue