nfc_init() return rather than exit on malloc error, examples fixed accordingly

This commit is contained in:
Philippe Teuwen 2013-03-05 22:24:59 +01:00
parent ae6062e5ba
commit 73b5c9d0af
22 changed files with 92 additions and 9 deletions

View file

@ -380,6 +380,10 @@ main(int argc, char *argv[])
nfc_context *context;
nfc_init(&context);
if (context == NULL) {
ERR("Unable to init libnfc (malloc)\n");
exit(EXIT_FAILURE);
}
// Try to open the NFC reader
pnd = nfc_open(context, NULL);

View file

@ -71,6 +71,10 @@ main(int argc, const char *argv[])
nfc_context *context;
nfc_init(&context);
if (context == NULL) {
ERR("Unable to init libnfc (malloc)");
exit(EXIT_FAILURE);
}
// Display libnfc version
acLibnfcVersion = nfc_version();

View file

@ -503,11 +503,15 @@ main(int argc, const char *argv[])
// printf("Successfully opened required files\n");
nfc_init(&context);
if (context == NULL) {
ERR("Unable to init libnfc (malloc)");
exit(EXIT_FAILURE);
}
// Try to open the NFC reader
pnd = nfc_open(context, NULL);
if (pnd == NULL) {
printf("Error opening NFC reader\n");
ERR("Error opening NFC reader");
nfc_exit(context);
exit(EXIT_FAILURE);
}

View file

@ -206,11 +206,15 @@ main(int argc, const char *argv[])
nfc_context *context;
nfc_init(&context);
if (context == NULL) {
ERR("Unable to init libnfc (malloc)");
exit(EXIT_FAILURE);
}
// Try to open the NFC device
pnd = nfc_open(context, NULL);
if (pnd == NULL) {
ERR("Error opening NFC device\n");
ERR("Error opening NFC device");
nfc_exit(context);
exit(EXIT_FAILURE);
}

View file

@ -198,6 +198,10 @@ main(int argc, char *argv[])
nfc_context *context;
nfc_init(&context);
if (context == NULL) {
ERR("Unable to init libnfc (malloc)\n");
exit(EXIT_FAILURE);
}
pnd = nfc_open(context, NULL);

View file

@ -197,6 +197,10 @@ main(int argc, char *argv[])
nfc_context *context;
nfc_init(&context);
if (context == NULL) {
ERR("Unable to init libnfc (malloc)");
exit(EXIT_FAILURE);
}
nfc_connstring connstrings[MAX_DEVICE_COUNT];
// List available devices

View file

@ -90,6 +90,10 @@ main(int argc, const char *argv[])
}
nfc_init(&context);
if (context == NULL) {
ERR("Unable to init libnfc (malloc)\n");
exit(EXIT_FAILURE);
}
// Display libnfc version
acLibnfcVersion = nfc_version();