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
|
|
@ -51,7 +51,7 @@ int
|
|||
main(int argc, const char *argv[])
|
||||
{
|
||||
size_t i;
|
||||
nfc_device *pnd;
|
||||
nfc_device *pnd = NULL;
|
||||
const char *acLibnfcVersion;
|
||||
bool result;
|
||||
int res = 0;
|
||||
|
|
@ -63,7 +63,8 @@ main(int argc, const char *argv[])
|
|||
const uint8_t pncmd_diagnose_ram_test[] = { Diagnose, 0x02 };
|
||||
|
||||
if (argc > 1) {
|
||||
errx(1, "usage: %s", argv[0]);
|
||||
printf("Usage: %s", argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
nfc_context *context;
|
||||
|
|
@ -85,7 +86,8 @@ main(int argc, const char *argv[])
|
|||
|
||||
if (pnd == NULL) {
|
||||
ERR("%s", "Unable to open NFC device.");
|
||||
return EXIT_FAILURE;
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("NFC device [%s] opened.\n", nfc_device_get_name(pnd));
|
||||
|
|
@ -119,4 +121,7 @@ main(int argc, const char *argv[])
|
|||
nfc_perror(pnd, "pn53x_transceive: cannot diagnose RAM");
|
||||
}
|
||||
}
|
||||
nfc_close(pnd);
|
||||
nfc_exit(context);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue