From ab7109065ced6feac485e3a5621c0f9c52f7aeec Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Tue, 2 May 2023 00:37:30 -0400 Subject: tac, ls fixes --- src/util/shared.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/util/shared.c') diff --git a/src/util/shared.c b/src/util/shared.c index e207c6d..3e6fca3 100644 --- a/src/util/shared.c +++ b/src/util/shared.c @@ -20,6 +20,11 @@ void error(const char* format, ...) { FILE* get_file_s(const char* path, const char* type) { struct stat s; + if (streql("-", path) && type[0] == 'r') { + clearerr(stdin); + fflush(stdin); + return stdin; + } if (lstat(path, &s) < 0) { if (type[0] != 'r') goto read; fprintf(stderr, "error: failed to read %s: %s\n", path, strerror(errno)); @@ -40,10 +45,6 @@ read: } FILE* get_file(const char* path, const char* type) { - if (streql("-", path) && type[0] == 'r') { - clearerr(stdin); - return stdin; - } FILE* file = get_file_s(path, type); if (file == NULL) exit(EXIT_FAILURE); return file; -- cgit v1.2.3-freya