diff options
-rw-r--r-- | libvirt-utils.c | 19 | ||||
-rw-r--r-- | libvirt-utils.h | 7 |
2 files changed, 26 insertions, 0 deletions
diff --git a/libvirt-utils.c b/libvirt-utils.c index 873552c..6866bf1 100644 --- a/libvirt-utils.c +++ b/libvirt-utils.c @@ -115,3 +115,22 @@ void virFree(void *ptrptr) *(void**)ptrptr = NULL; errno = save_errno; } + + +int virFileClose(int *fdptr) +{ + int saved_errno = 0; + int rc = 0; + + saved_errno = errno; + + if (*fdptr < 0) + return 0; + + rc = close(*fdptr); + *fdptr = -1; + + errno = saved_errno; + + return rc; +} diff --git a/libvirt-utils.h b/libvirt-utils.h index 93a2541..1b26413 100644 --- a/libvirt-utils.h +++ b/libvirt-utils.h @@ -183,4 +183,11 @@ void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1); # define VIR_FREE(ptr) virFree((void *) &(ptr)) # endif +/* Don't call this directly - use the macro below */ +int virFileClose(int *fdptr) + ATTRIBUTE_RETURN_CHECK; + +# define VIR_FORCE_CLOSE(FD) \ + ignore_value(virFileClose(&(FD))) + #endif /* __LIBVIRT_UTILS_H__ */ |