diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2022-01-18 11:27:54 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2022-01-18 12:27:29 -0500 |
commit | 03563b1407e436b2863509ebf09d412e79cbd1dd (patch) | |
tree | d2e5b735c8be3078b7b76c31c9168330a7f2557b /util.h | |
parent | abbb00766a8d10f63bbafb60bb13eb4672d7f44a (diff) | |
download | bfs-03563b1407e436b2863509ebf09d412e79cbd1dd.tar.xz |
util: New close() wrappers to check for EBADF and preserve errno
Diffstat (limited to 'util.h')
-rw-r--r-- | util.h | 20 |
1 files changed, 19 insertions, 1 deletions
@@ -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 |