mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-14 07:19:40 +02:00
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>
This commit is contained in:
@@ -80,7 +80,7 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
setvbuf(stdout, NULL, _IONBF, 0);
|
setvbuf(stdout, NULL, _IONBF, 0);
|
||||||
|
|
||||||
while (!feof(stdin))
|
while (1)
|
||||||
handle_audio();
|
handle_audio();
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
@@ -112,16 +112,22 @@ handle_audio(void)
|
|||||||
static void
|
static void
|
||||||
decode_pulse(void)
|
decode_pulse(void)
|
||||||
{
|
{
|
||||||
|
size_t n;
|
||||||
|
|
||||||
int next_ringpos = (ringpos + SAMPLES_PER_FRAME) % MAX_SAMPLES;
|
int next_ringpos = (ringpos + SAMPLES_PER_FRAME) % MAX_SAMPLES;
|
||||||
|
|
||||||
freq_data -= pulse[ringpos];
|
freq_data -= pulse[ringpos];
|
||||||
freq_data += pulse[next_ringpos];
|
freq_data += pulse[next_ringpos];
|
||||||
freq_separator -= 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)
|
if (n != sizeof(frame[0])) {
|
||||||
err(errno, "Could not read from frame.");
|
if (feof(stdin))
|
||||||
|
exit(EXIT_SUCCESS);
|
||||||
|
if (ferror(stdin))
|
||||||
|
err(errno, "Could not read from frame.");
|
||||||
|
}
|
||||||
|
|
||||||
pulse[ringpos] = (abs(frame[ringpos]) > THRESHOLD) ? 1 : 0;
|
pulse[ringpos] = (abs(frame[ringpos]) > THRESHOLD) ? 1 : 0;
|
||||||
freq_separator += pulse[ringpos++];
|
freq_separator += pulse[ringpos++];
|
||||||
|
|||||||
Reference in New Issue
Block a user