From 03563b1407e436b2863509ebf09d412e79cbd1dd Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 18 Jan 2022 11:27:54 -0500 Subject: util: New close() wrappers to check for EBADF and preserve errno --- main.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 7ceb0a2..ade5358 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,6 @@ /**************************************************************************** * bfs * - * Copyright (C) 2015-2021 Tavian Barnes * + * Copyright (C) 2015-2022 Tavian Barnes * * * * Permission to use, copy, modify, and/or distribute this software for any * * purpose with or without fee is hereby granted. * @@ -54,6 +54,7 @@ #include "ctx.h" #include "eval.h" #include "parse.h" +#include "util.h" #include #include #include @@ -79,9 +80,7 @@ static int redirect(int fd, const char *path, int flags) { } int ret = dup2(newfd, fd); - int err = errno; - close(newfd); - errno = err; + close_quietly(newfd); return ret; } -- cgit v1.2.3