]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: Introduce virFileReadLink
authorMichal Privoznik <mprivozn@redhat.com>
Wed, 18 Jan 2017 17:35:31 +0000 (18:35 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 7 Feb 2017 09:40:53 +0000 (10:40 +0100)
We will need to traverse the symlinks one step at the time.
Therefore we need to see where a symlink is pointing to.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/libvirt_private.syms
src/util/virfile.c
src/util/virfile.h

index 8e994c7f062bd76c569a5d225ec1f6b030d4d1cb..d556c7d5225229312fb4f4c1caacf2a043a57f30 100644 (file)
@@ -1616,6 +1616,7 @@ virFileReadAllQuiet;
 virFileReadBufQuiet;
 virFileReadHeaderFD;
 virFileReadLimFD;
+virFileReadLink;
 virFileRelLinkPointsTo;
 virFileRemove;
 virFileRemoveLastComponent;
index bf8099e3427626f195f0e4d3619970468a411537..49ea1d1f00d75658e0ceaf345dc578d5bcb0309f 100644 (file)
@@ -76,6 +76,7 @@
 #include "virutil.h"
 
 #include "c-ctype.h"
+#include "areadlink.h"
 
 #define VIR_FROM_THIS VIR_FROM_NONE
 
@@ -1614,6 +1615,17 @@ virFileIsLink(const char *linkpath)
     return S_ISLNK(st.st_mode) != 0;
 }
 
+/*
+ * Read where symlink is pointing to.
+ *
+ * Returns 0 on success (@linkpath is a successfully read link),
+ *        -1 with errno set upon error.
+ */
+int
+virFileReadLink(const char *linkpath, char **resultpath)
+{
+    return (*resultpath = areadlink(linkpath)) ? 0 : -1;
+}
 
 /*
  * Finds a requested executable file in the PATH env. e.g.:
index 0343acd5b8460bac73c837f5f9724b4fb52ebc08..232c1d66e115ce01bf95bbb7e7f5ede6e532e520 100644 (file)
@@ -166,6 +166,9 @@ int virFileResolveAllLinks(const char *linkpath,
 int virFileIsLink(const char *linkpath)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
 
+int virFileReadLink(const char *linkpath, char **resultpath)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
+
 char *virFindFileInPath(const char *file);
 
 char *virFileFindResource(const char *filename,