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:
parent
232930c3d5
commit
bece73faaf
21 changed files with 433 additions and 298 deletions
|
|
@ -66,9 +66,7 @@ intr_hdlr(int sig)
|
|||
{
|
||||
(void) sig;
|
||||
printf("\nQuitting...\n");
|
||||
if (pnd != NULL) {
|
||||
nfc_close(pnd);
|
||||
}
|
||||
nfc_close(pnd);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
|
@ -184,15 +182,16 @@ main(int argc, char *argv[])
|
|||
|
||||
nfc_init(&context);
|
||||
|
||||
// Try to open the NFC reader
|
||||
pnd = nfc_open(context, NULL);
|
||||
|
||||
// Display libnfc version
|
||||
acLibnfcVersion = nfc_version();
|
||||
printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
|
||||
|
||||
// Try to open the NFC reader
|
||||
pnd = nfc_open(context, NULL);
|
||||
|
||||
if (pnd == NULL) {
|
||||
ERR("Unable to open NFC device");
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
|
@ -267,6 +266,8 @@ main(int argc, char *argv[])
|
|||
printf("NFC device (configured as target) is now emulating the tag, please touch it with a second NFC device (initiator)\n");
|
||||
if (!nfc_target_emulate_tag(pnd, &nt)) {
|
||||
nfc_perror(pnd, "nfc_target_emulate_tag");
|
||||
nfc_close(pnd);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue