From 32c34ab174f1dd93985831926241ed3f20f4d0c7 Mon Sep 17 00:00:00 2001 From: jaseg Date: Sun, 22 Jul 2018 18:38:00 +0200 Subject: Remove fmemopen altogether since it just doesn't work. Closes #9. --- lolcat.c | 60 ++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 22 deletions(-) (limited to 'lolcat.c') diff --git a/lolcat.c b/lolcat.c index 687f259..ad1893b 100644 --- a/lolcat.c +++ b/lolcat.c @@ -13,6 +13,8 @@ * 0. You just DO WHAT THE FUCK YOU WANT TO. */ +#define _XOPEN_SOURCE + #include #include #include @@ -25,13 +27,6 @@ #include #include -#ifdef __APPLE__ -#include "fmemopen.h" -#else // __APPLE__ -#define _GNU_SOURCE //for fmemopen -#endif // __APPLE__ - - static char helpstr[] = "\n" "Usage: lolcat [-h horizontal_speed] [-v vertical_speed] [--] [FILES...]\n" "\n" @@ -79,7 +74,8 @@ void version(){ } int main(int argc, char **argv){ - int c, cc=-1, i, l=0; + int cc=-1, i, l=0; + wint_t c; int colors=1; double freq_h = 0.23, freq_v = 0.1; @@ -128,20 +124,38 @@ int main(int argc, char **argv){ i=0; for(char **filename=inputs; filename 0){ + while((c = this_file_read_wchar(f)) != WEOF) { if(colors){ find_escape_sequences(c, &escape_state); @@ -165,11 +179,13 @@ int main(int argc, char **argv){ printf("\n\033[0m"); cc = -1; - fclose(f); + if (f) { + fclose(f); - if(c != WEOF && c != 0){ - fprintf(stderr, "Error reading input file \"%s\": %s\n", *filename, strerror(errno)); - return 2; + if(ferror(f)){ + fprintf(stderr, "Error reading input file \"%s\": %s\n", *filename, strerror(errno)); + return 2; + } } } } -- cgit