Fix handling of EOF and error conditions after fread.
This commit is contained in:

committed by
Michael Ossmann

parent
eae7049284
commit
c089bb0b88
@ -513,8 +513,15 @@ int tx_callback(hackrf_transfer* transfer)
|
|||||||
/* Read samples from file. */
|
/* Read samples from file. */
|
||||||
bytes_read = fread(transfer->buffer, 1, bytes_to_read, file);
|
bytes_read = fread(transfer->buffer, 1, bytes_to_read, file);
|
||||||
|
|
||||||
/* If no more bytes, error or file empty, treat as end. */
|
/* Terminate immediately on error. */
|
||||||
if (bytes_read == 0) {
|
if (ferror(file)) {
|
||||||
|
fprintf(stderr, "Could not read input file.\n");
|
||||||
|
stop_main_loop();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Finish TX if no more data can be read. */
|
||||||
|
if ((bytes_read == 0) && (ftell(file) < 1)) {
|
||||||
tx_complete = true;
|
tx_complete = true;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user