spkmodem-recv: remove buggy errno usage

Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
Leah Rowe
2026-04-22 03:32:46 +01:00
parent 3b7ac395f4
commit 46574146f5
+8 -9
View File
@@ -23,7 +23,6 @@
#define FREQ_DATA_MAX 60 #define FREQ_DATA_MAX 60
#define THRESHOLD 500 #define THRESHOLD 500
#define ERR() (errno = errno ? errno : ECANCELED)
#define reset_char() ascii = 0, ascii_bit = 7 #define reset_char() ascii = 0, ascii_bit = 7
signed short frame[MAX_SAMPLES], pulse[MAX_SAMPLES]; signed short frame[MAX_SAMPLES], pulse[MAX_SAMPLES];
@@ -42,17 +41,17 @@ main(int argc, char *argv[])
int c; int c;
#ifdef __OpenBSD__ #ifdef __OpenBSD__
if (pledge("stdio", NULL) == -1) if (pledge("stdio", NULL) == -1)
err(ERR(), "pledge"); err(EXIT_FAILURE, "pledge");
#endif #endif
while ((c = getopt(argc, argv, "d")) != -1) while ((c = getopt(argc, argv, "d")) != -1)
if (!(debug = (c == 'd'))) if (!(debug = (c == 'd'))) {
err(errno = EINVAL, NULL); errno = EINVAL;
err(EXIT_FAILURE, "%c: Invalid option", c);
}
setvbuf(stdout, NULL, _IONBF, 0); setvbuf(stdout, NULL, _IONBF, 0);
while (!feof(stdin)) while (!feof(stdin))
handle_audio(); handle_audio();
if (errno && debug) return EXIT_SUCCESS;
err(errno, "Unhandled error, errno %d", errno);
return errno;
} }
void void
@@ -83,7 +82,7 @@ decode_pulse(void)
fread(frame + ringpos, 1, sizeof(frame[0]), stdin); fread(frame + ringpos, 1, sizeof(frame[0]), stdin);
if (ferror(stdin) != 0) if (ferror(stdin) != 0)
err(ERR(), "Could not read from frame."); err(EXIT_FAILURE, "Could not read from frame.");
if ((pulse[ringpos] = (abs(frame[ringpos]) > THRESHOLD) ? 1 : 0)) if ((pulse[ringpos] = (abs(frame[ringpos]) > THRESHOLD) ? 1 : 0))
++freq_separator; ++freq_separator;
@@ -118,7 +117,7 @@ print_stats(void)
{ {
long stdin_pos; long stdin_pos;
if ((stdin_pos = ftell(stdin)) == -1) if ((stdin_pos = ftell(stdin)) == -1)
err(ERR(), NULL); err(EXIT_FAILURE, NULL);
printf ("%d %d %d @%ld\n", freq_data, freq_separator, printf ("%d %d %d @%ld\n", freq_data, freq_separator,
FREQ_DATA_THRESHOLD, stdin_pos - sizeof(frame)); FREQ_DATA_THRESHOLD, stdin_pos - sizeof(frame));
} }