mirror of
https://github.com/nfc-tools/libnfc.git
synced 2026-04-20 13:36:19 +00:00
Error conditions in utils & examples: fix leaks, unify style (see details)
* in main(): ** errx()/err()/return -> exit() ** return values -> EXIT_SUCCESS & EXIT_FAILURE * out of main: ** err()/errx()/exit() -> return ** change retval from size_t to int to allow returning errors ** don't use EXIT_SUCCESS / EXIT_FAILURE as retvals * add nfc_close() & nfc_exit() to exit() on errors * add missing fclose() on errors * add missing test if (pnd == NULL) * unify style if (pnd == / != NULL) * remove goto's * few related fixes * remove if(pnd!=NULL) test on nfc_close() calls
This commit is contained in:
@@ -183,30 +183,39 @@ main(int argc, char *argv[])
|
||||
// Try to open the NFC reader
|
||||
pnd = nfc_open(context, NULL);
|
||||
|
||||
if (!pnd) {
|
||||
if (pnd == NULL) {
|
||||
printf("Error opening NFC reader\n");
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Initialise NFC device as "initiator"
|
||||
if (nfc_initiator_init(pnd) < 0) {
|
||||
nfc_perror(pnd, "nfc_initiator_init");
|
||||
nfc_close(pnd);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Configure the CRC
|
||||
if (nfc_device_set_property_bool(pnd, NP_HANDLE_CRC, false) < 0) {
|
||||
nfc_perror(pnd, "nfc_device_set_property_bool");
|
||||
nfc_close(pnd);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// Use raw send/receive methods
|
||||
if (nfc_device_set_property_bool(pnd, NP_EASY_FRAMING, false) < 0) {
|
||||
nfc_perror(pnd, "nfc_device_set_property_bool");
|
||||
nfc_close(pnd);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// Disable 14443-4 autoswitching
|
||||
if (nfc_device_set_property_bool(pnd, NP_AUTO_ISO14443_4, false) < 0) {
|
||||
nfc_perror(pnd, "nfc_device_set_property_bool");
|
||||
nfc_close(pnd);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -217,7 +226,7 @@ main(int argc, char *argv[])
|
||||
printf("Error: No tag available\n");
|
||||
nfc_close(pnd);
|
||||
nfc_exit(context);
|
||||
return 1;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
memcpy(abtAtqa, abtRx, 2);
|
||||
|
||||
@@ -353,8 +362,7 @@ main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
nfc_close(pnd);
|
||||
nfc_exit(context);
|
||||
return EXIT_SUCCESS;
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user