summaryrefslogtreecommitdiffstats
path: root/util.h
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2022-01-18 11:27:54 -0500
committerTavian Barnes <tavianator@tavianator.com>2022-01-18 12:27:29 -0500
commit03563b1407e436b2863509ebf09d412e79cbd1dd (patch)
treed2e5b735c8be3078b7b76c31c9168330a7f2557b /util.h
parentabbb00766a8d10f63bbafb60bb13eb4672d7f44a (diff)
downloadbfs-03563b1407e436b2863509ebf09d412e79cbd1dd.tar.xz
util: New close() wrappers to check for EBADF and preserve errno
Diffstat (limited to 'util.h')
-rw-r--r--util.h20
1 files changed, 19 insertions, 1 deletions
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 <tavianator@tavianator.com> *
+ * Copyright (C) 2016-2022 Tavian Barnes <tavianator@tavianator.com> *
* *
* 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