logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git
commit: 51b51a7d99fb19b31719d4ab7f19e34bf514211f
parent 1218b73c00641407836ed951fda142f8783d2022
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue, 10 Sep 2024 09:46:52 +0200

cmd/cut: close stdin/stdout before returning successfully

Inspired by https://blog.sunfishcode.online/errors-from-close/

Diffstat:

Mcmd/cut.c12++++++++++++
1 file changed, 12 insertions(+), 0 deletions(-)

diff --git a/cmd/cut.c b/cmd/cut.c @@ -466,5 +466,17 @@ main(int argc, char *argv[]) if(ret != 0) return 1; } + if(fclose(stdin) != 0) + { + fprintf(stderr, "cut: Error closing <stdin>: %s\n", strerror(errno)); + return 1; + } + + if(fclose(stdout) != 0) + { + fprintf(stderr, "cut: Error closing <stdout>: %s\n", strerror(errno)); + return 1; + } + return 0; }