]> git.ipfire.org Git - thirdparty/libvirt.git/commit
util: change virDirClose to take a DIR* instead of DIR**.
authorLaine Stump <laine@redhat.com>
Tue, 13 Oct 2020 13:58:57 +0000 (09:58 -0400)
committerLaine Stump <laine@redhat.com>
Tue, 3 Nov 2020 03:01:36 +0000 (22:01 -0500)
commit24d8968cd0a718af4badbbc858b1b449fea7205a
treee741a0ae2c0d17c98aa8537f2ef3965d6fe20546
parent7f42bdf5c021dc79b1062fca13d2d5ac4b735259
util: change virDirClose to take a DIR* instead of DIR**.

In order to make a usable g_autoptr(DIR), we need to have a close
function that is a NOP when the pointer is NULL, but takes a simple
DIR*. But virDirClose() (candidate to be the g_autoptr cleanup
function) currently takes a DIR**, not DIR*. It does this so that it
can clear the pointer, thus making it safe to call virDirClose on the
same DIR multiple times.

In the past the clearing of the DIR* was essential in a few places,
but those few places have now been changed, so we can modify
virDirClose() to take a DIR*, and remove the side effect of clearing
the DIR*. This will make it directly usable as the g_autoptr cleanup,
and will mean that this:

   {
   DIR *dirp = NULL;
   blah blah ...
   VIR_DIR_CLOSE(dirp)
   }

is functionally identical to

   {
   g_autoptr(DIR) dirp = NULL;
   blah blah ...
   }

which will make conversion to using g_autoptr mechanical and simple to review.

(Note that virDirClose() will still check for NULL before attempting
to close, so that it can always be safely called, as long as the DIR*
was initialized to NULL (another prerequisite of becoming a g_autoptr
cleanup function)

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
src/util/virfile.c
src/util/virfile.h