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 --- util.h | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'util.h') diff --git a/util.h b/util.h index ccac549..37c03fa 100644 --- a/util.h +++ b/util.h @@ -1,6 +1,6 @@ /**************************************************************************** * bfs * - * Copyright (C) 2016-2021 Tavian Barnes * + * Copyright (C) 2016-2022 Tavian Barnes * * * * Permission to use, copy, modify, and/or distribute this software for any * * purpose with or without fee is hereby granted. * @@ -298,4 +298,22 @@ char *xgetdelim(FILE *file, char delim); */ FILE *xfopen(const char *path, int flags); +/** + * close() wrapper that asserts the file descriptor is valid. + * + * @param fd + * The file descriptor to close. + * @return + * 0 on success, or -1 on error. + */ +int xclose(int fd); + +/** + * close() variant that preserves errno. + * + * @param fd + * The file descriptor to close. + */ +void close_quietly(int fd); + #endif // BFS_UTIL_H -- cgit v1.2.3