From bf9c4a67f8d81fefea7ef0e808351fdcde339ba4 Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Wed, 11 Mar 2026 23:30:22 +0000 Subject: util/spkmodem-recv: handle fread errors also handle EOF condition and exit cleanly. don't use dirty feof. Signed-off-by: Leah Rowe --- util/spkmodem_recv/spkmodem-recv.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'util') diff --git a/util/spkmodem_recv/spkmodem-recv.c b/util/spkmodem_recv/spkmodem-recv.c index 749e93ca..92a16457 100644 --- a/util/spkmodem_recv/spkmodem-recv.c +++ b/util/spkmodem_recv/spkmodem-recv.c @@ -80,7 +80,7 @@ main(int argc, char *argv[]) setvbuf(stdout, NULL, _IONBF, 0); - while (!feof(stdin)) + while (1) handle_audio(); return EXIT_SUCCESS; @@ -112,16 +112,22 @@ handle_audio(void) static void decode_pulse(void) { + size_t n; + int next_ringpos = (ringpos + SAMPLES_PER_FRAME) % MAX_SAMPLES; freq_data -= pulse[ringpos]; freq_data += pulse[next_ringpos]; freq_separator -= pulse[next_ringpos]; - fread(frame + ringpos, 1, sizeof(frame[0]), stdin); + n = fread(frame + ringpos, 1, sizeof(frame[0]), stdin); - if (ferror(stdin) != 0) - err(errno, "Could not read from frame."); + if (n != sizeof(frame[0])) { + if (feof(stdin)) + exit(EXIT_SUCCESS); + if (ferror(stdin)) + err(errno, "Could not read from frame."); + } pulse[ringpos] = (abs(frame[ringpos]) > THRESHOLD) ? 1 : 0; freq_separator += pulse[ringpos++]; -- cgit v1.2.1