Applies to both branches -- Uwe Bonnes b...@elektron.ikp.physik.tu-darmstadt.de
Institut fuer Kernphysik Schlossgartenstrasse 9 64289 Darmstadt --------- Tel. 06151 162516 -------- Fax. 06151 164321 ---------- >From fa4ea32b14347043eb3cf20cf5a74dad0019ed9d Mon Sep 17 00:00:00 2001 From: Uwe Bonnes <b...@elektron.ikp.physik.tu-darmstadt.de> Date: Tue, 1 Feb 2011 11:28:29 +0100 Subject: Error handling in stream_test --- examples/stream_test.c | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-) diff --git a/examples/stream_test.c b/examples/stream_test.c index 21b1a11..840f595 100644 --- a/examples/stream_test.c +++ b/examples/stream_test.c @@ -147,6 +147,7 @@ int main(int argc, char **argv) char *serial = NULL; int option_index; static struct option long_options[] = {{NULL},}; + int retval = 1; while ((c = getopt_long(argc, argv, "s:S:n", long_options, &option_index)) !=- 1) switch (c) @@ -187,7 +188,8 @@ int main(int argc, char **argv) if (ftdi_set_interface(ftdi, INTERFACE_A) < 0) { fprintf(stderr, "ftdi_set_interface failed\n"); - return EXIT_FAILURE; + retval = 1; + goto cleanup; } if (ftdi_usb_open_desc(ftdi, 0x0403, 0x6010, descstring, serial) < 0) @@ -198,14 +200,16 @@ int main(int argc, char **argv) if (descstring) fprintf(stderr,"with Serial: %s", serial); fprintf(stderr,"\n"); - return EXIT_FAILURE; + retval = 1; + goto cleanup; } /* A timeout value of 1 results in may skipped blocks */ if (ftdi_set_latency_timer(ftdi, 2)) { fprintf(stderr,"Can't set latency, Error %s\n",ftdi_get_error_string(ftdi)); - return EXIT_FAILURE; + retval = 1; + goto cleanup_close; } /* if(ftdi_usb_purge_rx_buffer(ftdi) < 0) @@ -239,7 +243,10 @@ int main(int argc, char **argv) fprintf(stderr,"Can't set synchronous fifo mode, Error %s\n",ftdi_get_error_string(ftdi)); return EXIT_FAILURE; } + retval = 0; +cleanup_close: ftdi_usb_close(ftdi); +cleanup: ftdi_free(ftdi); signal(SIGINT, SIG_DFL); if (check && outfile) -- 1.7.1 -- libftdi - see http://www.intra2net.com/en/developer/libftdi for details. To unsubscribe send a mail to libftdi+unsubscr...@developer.intra2net.com