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 --- dir.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'dir.c') diff --git a/dir.c b/dir.c index 90c2e3e..024e767 100644 --- a/dir.c +++ b/dir.c @@ -138,12 +138,10 @@ struct bfs_dir *bfs_opendir(int at_fd, const char *at_path) { #else dir->dir = fdopendir(fd); if (!dir->dir) { - int error = errno; if (at_path) { - close(fd); + close_quietly(fd); } free(dir); - errno = error; return NULL; } @@ -280,7 +278,7 @@ int bfs_readdir(struct bfs_dir *dir, struct bfs_dirent *de) { int bfs_closedir(struct bfs_dir *dir) { #if __linux__ - int ret = close(dir->fd); + int ret = xclose(dir->fd); #else int ret = closedir(dir->dir); #endif -- cgit v1.2.3