Improve handling of file read results.
This commit is contained in:
@ -513,17 +513,18 @@ 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);
|
||||||
|
|
||||||
/* Terminate immediately on error. */
|
/* If no more bytes, error or file empty, terminate. */
|
||||||
|
if (bytes_read == 0) {
|
||||||
|
/* Report any error. */
|
||||||
if (ferror(file)) {
|
if (ferror(file)) {
|
||||||
fprintf(stderr, "Could not read input file.\n");
|
fprintf(stderr, "Could not read input file.\n");
|
||||||
stop_main_loop();
|
stop_main_loop();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (ftell(file) < 1) {
|
||||||
/* Finish TX if no more data can be read. */
|
stop_main_loop();
|
||||||
if ((bytes_read == 0) && (ftell(file) < 1)) {
|
return -1;
|
||||||
tx_complete = true;
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -561,9 +562,17 @@ int tx_callback(hackrf_transfer* transfer)
|
|||||||
|
|
||||||
/* If no more bytes, error or file empty, use what we have. */
|
/* If no more bytes, error or file empty, use what we have. */
|
||||||
if (extra_bytes_read == 0) {
|
if (extra_bytes_read == 0) {
|
||||||
|
/* Report any error. */
|
||||||
|
if (ferror(file)) {
|
||||||
|
fprintf(stderr, "Could not read input file.\n");
|
||||||
tx_complete = true;
|
tx_complete = true;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if (ftell(file) < 1) {
|
||||||
|
tx_complete = true;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bytes_read += extra_bytes_read;
|
bytes_read += extra_bytes_read;
|
||||||
transfer->valid_length += extra_bytes_read;
|
transfer->valid_length += extra_bytes_read;
|
||||||
|
Reference in New Issue
Block a user