[PATCH 09/18] Introduce virDirOpenQuiet

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



A helper function that does not report any errors.
---
 src/libvirt_private.syms |  1 +
 src/util/virfile.c       | 25 ++++++++++++++++++++++---
 src/util/virfile.h       |  2 ++
 3 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 2bb1d95..8ebe6f3 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1497,6 +1497,7 @@ virDirClose;
 virDirCreate;
 virDirOpen;
 virDirOpenIfExists;
+virDirOpenQuiet;
 virDirRead;
 virFileAbsPath;
 virFileAccessibleAs;
diff --git a/src/util/virfile.c b/src/util/virfile.c
index efdb98b..f6c43d4 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -2727,10 +2727,13 @@ virFileRemove(const char *path,
 #endif /* WIN32 */
 
 static int
-virDirOpenInternal(DIR **dirp, const char *name, bool ignoreENOENT)
+virDirOpenInternal(DIR **dirp, const char *name, bool ignoreENOENT, bool quiet)
 {
     *dirp = opendir(name);
     if (!*dirp) {
+        if (quiet)
+            return -1;
+
         if (ignoreENOENT && errno == ENOENT)
             return 0;
         virReportSystemError(errno, _("cannot open directory '%s'"), name);
@@ -2750,7 +2753,7 @@ virDirOpenInternal(DIR **dirp, const char *name, bool ignoreENOENT)
 int
 virDirOpen(DIR **dirp, const char *name)
 {
-    return virDirOpenInternal(dirp, name, false);
+    return virDirOpenInternal(dirp, name, false, false);
 }
 
 /**
@@ -2765,7 +2768,23 @@ virDirOpen(DIR **dirp, const char *name)
 int
 virDirOpenIfExists(DIR **dirp, const char *name)
 {
-    return virDirOpenInternal(dirp, name, true);
+    return virDirOpenInternal(dirp, name, true, false);
+}
+
+/**
+ * virDirOpenQuiet
+ * @dirp: directory stream
+ * @name: path of the directory
+ *
+ * Returns 1 on success.
+ *        -1 on failure.
+ *
+ * Does not report any errors and errno is preserved.
+ */
+int
+virDirOpenQuiet(DIR **dirp, const char *name)
+{
+    return virDirOpenInternal(dirp, name, false, true);
 }
 
 /**
diff --git a/src/util/virfile.h b/src/util/virfile.h
index 42c65f2..b4ae6ea 100644
--- a/src/util/virfile.h
+++ b/src/util/virfile.h
@@ -234,6 +234,8 @@ int virDirOpen(DIR **dirp, const char *dirname)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
 int virDirOpenIfExists(DIR **dirp, const char *dirname)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
+int virDirOpenQuiet(DIR **dirp, const char *dirname)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
 int virDirRead(DIR *dirp, struct dirent **ent, const char *dirname)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
 void virDirClose(DIR **dirp)
-- 
2.7.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]