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
|
|
@ -76,7 +76,7 @@ main(int argc, const char *argv[])
|
|||
for (int arg = 1; arg < argc; arg++) {
|
||||
if (0 == strcmp(argv[arg], "-h")) {
|
||||
print_usage(argv);
|
||||
return EXIT_SUCCESS;
|
||||
exit(EXIT_SUCCESS);
|
||||
} else if (0 == strcmp(argv[arg], "-v")) {
|
||||
verbose = true;
|
||||
} else if (0 == strcmp(argv[arg], "-i")) {
|
||||
|
|
@ -85,7 +85,7 @@ main(int argc, const char *argv[])
|
|||
} else {
|
||||
ERR("%s is not supported option.", argv[arg]);
|
||||
print_usage(argv);
|
||||
return EXIT_FAILURE;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -98,10 +98,10 @@ main(int argc, const char *argv[])
|
|||
nfc_connstring connstrings[MAX_DEVICE_COUNT];
|
||||
size_t szDeviceFound = nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT);
|
||||
|
||||
int res = EXIT_FAILURE;
|
||||
if (szDeviceFound == 0) {
|
||||
printf("No NFC device found.\n");
|
||||
goto bye;
|
||||
nfc_exit(context);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("%d NFC device(s) found:\n", (int)szDeviceFound);
|
||||
|
|
@ -121,9 +121,6 @@ main(int argc, const char *argv[])
|
|||
printf("nfc_open failed for %s\n", connstrings[i]);
|
||||
}
|
||||
}
|
||||
res = EXIT_SUCCESS;
|
||||
|
||||
bye:
|
||||
nfc_exit(context);
|
||||
return res;
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue