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

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

View file

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

View file

@ -151,12 +151,16 @@ main(int argc, 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 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

@ -73,10 +73,14 @@ main(int argc, const char *argv[])
nfc_context *context;
nfc_init(&context);
if (context == NULL) {
ERR("Unable to init libnfc (malloc)");
exit(EXIT_FAILURE);
}
pnd = nfc_open(context, NULL);
if (pnd == NULL) {
printf("Unable to open NFC device.\n");
ERR("Unable to open NFC device.");
nfc_exit(context);
exit(EXIT_FAILURE);
}

View file

@ -72,6 +72,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);
}
#define MAX_DEVICE_COUNT 2
nfc_connstring connstrings[MAX_DEVICE_COUNT];
size_t szDeviceFound = nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT);

View file

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

View file

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

View file

@ -128,12 +128,16 @@ main(int argc, 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) {
printf("Unable to open NFC device\n");
ERR("Unable to open NFC device");
nfc_exit(context);
exit(EXIT_FAILURE);
}

View file

@ -179,12 +179,16 @@ main(int argc, 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 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

@ -105,6 +105,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);
}
pnd = nfc_open(context, NULL);

View file

@ -110,6 +110,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
size_t szFound = nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT);
@ -123,7 +127,7 @@ main(int argc, char *argv[])
// Try to open the NFC emulator device
pndTag = nfc_open(context, connstrings[0]);
if (pndTag == NULL) {
printf("Error opening NFC emulator device\n");
ERR("Error opening NFC emulator device");
nfc_exit(context);
exit(EXIT_FAILURE);
}

View file

@ -69,6 +69,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

@ -77,6 +77,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
const char *acLibnfcVersion = nfc_version();

View file

@ -85,6 +85,10 @@ int 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 reader
pnd = nfc_open(context, NULL);