summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeah Rowe <leah@libreboot.org>2023-06-05 01:05:38 +0100
committerLeah Rowe <leah@libreboot.org>2023-06-05 01:05:38 +0100
commit264a31b95dd5e2c7790368b2b53e44d067a27c01 (patch)
treed90747dc21b0c7ef50e0453dfeddb50d903e5019
parent118bb19ff84b013954b3032e93c7fb0fc926b15e (diff)
util/spkmodem-recv: always disable line buffering
thus, there's no need to handle flushing of stdout whatsoever, and the code can be greatly simplified ascii bits are still reset, when no input on stdin is given Signed-off-by: Leah Rowe <leah@libreboot.org>
-rw-r--r--util/spkmodem_recv/spkmodem-recv.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/util/spkmodem_recv/spkmodem-recv.c b/util/spkmodem_recv/spkmodem-recv.c
index d43c27d9..2485943a 100644
--- a/util/spkmodem_recv/spkmodem-recv.c
+++ b/util/spkmodem_recv/spkmodem-recv.c
@@ -23,7 +23,7 @@
#define ERR() (errno = errno ? errno : ECANCELED)
signed short frame[2 * SAMPLES_PER_FRAME], pulse[2 * SAMPLES_PER_FRAME];
-int flush, freq_data, freq_separator, sample_count, ascii_bit = 7;
+int freq_data, freq_separator, sample_count, ascii_bit = 7;
char ascii = 0;
void handle_audio(void);
@@ -40,11 +40,7 @@ main(int argc, char *argv[])
if (pledge("stdio", NULL) == -1)
err(ERR(), "pledge");
#endif
- while ((c = getopt(argc, argv, "u")) != -1) {
- if (c != 'u')
- err(errno = EINVAL, NULL);
- setvbuf(stdout, NULL, _IONBF, 0);
- }
+ setvbuf(stdout, NULL, _IONBF, 0);
while (!feof(stdin))
handle_audio();
if (errno)
@@ -55,21 +51,19 @@ main(int argc, char *argv[])
void
handle_audio(void)
{
- if ((flush = (sample_count > (3 * SAMPLES_PER_FRAME)))) {
+ if (sample_count > (3 * SAMPLES_PER_FRAME)) {
ascii_bit = 7;
ascii = sample_count = 0;
- if (fflush(stdout) == EOF)
- err(ERR(), NULL);
}
if ((freq_separator <= FREQ_SEP_MIN) || (freq_separator >= FREQ_SEP_MAX)
|| (freq_data <= FREQ_DATA_MIN) || (freq_data >= FREQ_DATA_MAX)) {
fetch_sample();
return;
}
+
if (!set_ascii_bit())
print_char();
-
- sample_count = flush = 0;
+ sample_count = 0;
for (int sample = 0; sample < SAMPLES_PER_FRAME; sample++)
fetch_sample();
}