[PATCH 3/4] Introduce virFileReadAllQuiet

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

 



Just like virFileReadAll, but returns -errno instead
of reporting errors. Useful for ignoring some errors.
---
 src/libvirt_private.syms |  1 +
 src/util/virfile.c       | 15 +++++++++++++++
 src/util/virfile.h       |  2 ++
 3 files changed, 18 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 1e1dd84..ed56103 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1288,6 +1288,7 @@ virFileOpenAs;
 virFileOpenTty;
 virFilePrintf;
 virFileReadAll;
+virFileReadAllQuiet;
 virFileReadHeaderFD;
 virFileReadLimFD;
 virFileRelLinkPointsTo;
diff --git a/src/util/virfile.c b/src/util/virfile.c
index 9e17504..463064c 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -1301,6 +1301,21 @@ virFileReadAll(const char *path, int maxlen, char **buf)
     return len;
 }
 
+int
+virFileReadAllQuiet(const char *path, int maxlen, char **buf)
+{
+    int fd = open(path, O_RDONLY);
+    if (fd < 0)
+        return -errno;
+
+    int len = virFileReadLimFD(fd, maxlen, buf);
+    VIR_FORCE_CLOSE(fd);
+    if (len < 0)
+        return -errno;
+
+    return len;
+}
+
 /* Truncate @path and write @str to it.  If @mode is 0, ensure that
    @path exists; otherwise, use @mode if @path must be created.
    Return 0 for success, nonzero for failure.
diff --git a/src/util/virfile.h b/src/util/virfile.h
index 5fee407..36d3fe7 100644
--- a/src/util/virfile.h
+++ b/src/util/virfile.h
@@ -129,6 +129,8 @@ int virFileReadLimFD(int fd, int maxlen, char **buf)
     ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(3);
 int virFileReadAll(const char *path, int maxlen, char **buf)
     ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
+int virFileReadAllQuiet(const char *path, int maxlen, char **buf)
+    ATTRIBUTE_RETURN_CHECK ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
 
 int virFileWriteStr(const char *path, const char *str, mode_t mode)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
-- 
1.8.5.5

--
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]