diff options
| author | Leah Rowe <leah@libreboot.org> | 2026-03-11 23:30:22 +0000 |
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2026-03-11 23:30:22 +0000 |
| commit | bf9c4a67f8d81fefea7ef0e808351fdcde339ba4 (patch) | |
| tree | 888413c56bf23ae31216c9aedc9728b700e7f862 | |
| parent | 9195ff97b7f1b61ad06852c482a6570c322444bc (diff) | |
util/spkmodem-recv: handle fread errors
also handle EOF condition and exit cleanly.
don't use dirty feof.
Signed-off-by: Leah Rowe <leah@libreboot.org>
| -rw-r--r-- | util/spkmodem_recv/spkmodem-recv.c | 14 |
1 files changed, 10 insertions, 4 deletions
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++]; |
