mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
common/utils: cleanups: Add CLEANUP_CLOSE function.
This is present in the daemon, but the function could be used throughout the code.
This commit is contained in:
@@ -84,6 +84,15 @@ guestfs_int_cleanup_unlink_free (char **ptr)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
guestfs_int_cleanup_close (void *ptr)
|
||||
{
|
||||
const int fd = * (int *) ptr;
|
||||
|
||||
if (fd >= 0)
|
||||
close (fd);
|
||||
}
|
||||
|
||||
void
|
||||
guestfs_int_cleanup_fclose (void *ptr)
|
||||
{
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
__attribute__((cleanup(guestfs_int_cleanup_gl_recursive_lock_unlock)))
|
||||
#define CLEANUP_UNLINK_FREE \
|
||||
__attribute__((cleanup(guestfs_int_cleanup_unlink_free)))
|
||||
#define CLEANUP_CLOSE \
|
||||
__attribute__((cleanup(guestfs_int_cleanup_close)))
|
||||
#define CLEANUP_FCLOSE \
|
||||
__attribute__((cleanup(guestfs_int_cleanup_fclose)))
|
||||
#define CLEANUP_PCLOSE \
|
||||
@@ -53,6 +55,7 @@
|
||||
#define CLEANUP_HASH_FREE
|
||||
/* XXX no safe equivalent to CLEANUP_GL_RECURSIVE_LOCK_UNLOCK */
|
||||
#define CLEANUP_UNLINK_FREE
|
||||
#define CLEANUP_CLOSE
|
||||
#define CLEANUP_FCLOSE
|
||||
#define CLEANUP_PCLOSE
|
||||
#define CLEANUP_FREE_STRING_LIST
|
||||
@@ -72,6 +75,7 @@ extern void guestfs_int_cleanup_free (void *ptr);
|
||||
extern void guestfs_int_cleanup_hash_free (void *ptr);
|
||||
extern void guestfs_int_cleanup_gl_recursive_lock_unlock (void *ptr);
|
||||
extern void guestfs_int_cleanup_unlink_free (char **ptr);
|
||||
extern void guestfs_int_cleanup_close (void *ptr);
|
||||
extern void guestfs_int_cleanup_fclose (void *ptr);
|
||||
extern void guestfs_int_cleanup_pclose (void *ptr);
|
||||
extern void guestfs_int_cleanup_free_string_list (char ***ptr);
|
||||
|
||||
Reference in New Issue
Block a user