mirror of
https://github.com/EttusResearch/uhd.git
synced 2026-10-25 17:36:10 +00:00
Host: Examples: Add error check for open failures
If open output file failed (e.g. missing permission) this was not tracked and the C rx example crashed when try to write to the empty file descriptor. This checks the result of fopen and prints the str error of the failure for graceful exit.
This commit is contained in:
parent
12de60b20b
commit
192b3b24f0
@ -9,6 +9,7 @@
|
||||
|
||||
#include "getopt.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -35,6 +36,16 @@ void print_help(void)
|
||||
" -h (print this help message)\n");
|
||||
};
|
||||
|
||||
int open_file(const char* filename, FILE** fp)
|
||||
{
|
||||
*fp = fopen(filename, "wb");
|
||||
if (!*fp) {
|
||||
fprintf(stderr, "Cannot open %s: %s\n", filename, strerror(errno));
|
||||
return UHD_ERROR_OS;
|
||||
}
|
||||
return UHD_ERROR_NONE;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int option = 0;
|
||||
@ -176,7 +187,8 @@ int main(int argc, char* argv[])
|
||||
free_buffer, uhd_rx_streamer_issue_stream_cmd(rx_streamer, &stream_cmd))
|
||||
|
||||
// Set up file output
|
||||
fp = fopen(filename, "wb");
|
||||
EXECUTE_OR_GOTO(
|
||||
free_buffer, open_file(filename, &fp));
|
||||
|
||||
// Actual streaming
|
||||
while (num_acc_samps < n_samples) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user