logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git
commit: b2e3ac9522cdd49c6a617c689505b431d3198039
parent 8ef0891b4ff2718e24ced9eca947af45180ac794
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sun, 23 Jan 2022 12:21:02 +0100

bin/lolcat: Always reset colors at the end

Reported by anotherposter@shitposter.club

Diffstat:

Mbin/lolcat.c26+++++++++++++++++---------
1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/bin/lolcat.c b/bin/lolcat.c @@ -58,43 +58,51 @@ concat(FILE *stream) int main(int argc, char *argv[]) { + int ret = 0; + if(argc <= 1) { - return concat(stdin); + ret = concat(stdin); + goto end; } for(int argi = 1; argi < argc; argi++) { if(strncmp(argv[argi], "-", 2) == 0) { - if(concat(stdin) != 0) + ret = concat(stdin); + if(ret != 0) { - return 1; + goto end; } } else { FILE *file = fopen(argv[argi], "r"); + if(!file) { printf("\nError opening ā€˜%sā€™: %s\n", argv[argi], strerror(errno)); + goto end; } else { - if(concat(file) != 0) + ret = concat(file); + if(ret != 0) { - return 1; + goto end; } - if(fclose(file) != 0) + ret = fclose(file); + if(ret != 0) { - return 1; + goto end; } } } } +end: printf(""); - - return 0; + return ret; }