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:
Philippe Teuwen 2013-03-05 19:44:59 +01:00
parent 232930c3d5
commit bece73faaf
21 changed files with 433 additions and 298 deletions

View file

@ -79,7 +79,7 @@ int main(int argc, const char *argv[])
if (argc >= 2) {
if ((input = fopen(argv[1], "r")) == NULL) {
ERR("%s", "Cannot open file.");
return EXIT_FAILURE;
exit(EXIT_FAILURE);
}
}
@ -94,7 +94,8 @@ int main(int argc, const char *argv[])
if (input != NULL) {
fclose(input);
}
return EXIT_FAILURE;
nfc_exit(context);
exit(EXIT_FAILURE);
}
printf("NFC reader: %s opened\n", nfc_device_get_name(pnd));
@ -103,6 +104,8 @@ int main(int argc, const char *argv[])
if (input != NULL) {
fclose(input);
}
nfc_close(pnd);
nfc_exit(context);
exit(EXIT_FAILURE);
}
@ -205,5 +208,5 @@ int main(int argc, const char *argv[])
}
nfc_close(pnd);
nfc_exit(context);
return EXIT_SUCCESS;
exit(EXIT_SUCCESS);
}