summaryrefslogtreecommitdiffstats
path: root/libsmartcols/src/line.c
diff options
context:
space:
mode:
authorKarel Zak2017-05-05 12:12:43 +0200
committerKarel Zak2017-05-05 12:12:43 +0200
commiteebf2dd89ba905c52ec00ed321a9c246e00598f8 (patch)
tree506d8e70bc21e0560100d6618156022b40747da0 /libsmartcols/src/line.c
parentcolumn: add note that circular dependencies are ignored (diff)
downloadkernel-qcow2-util-linux-eebf2dd89ba905c52ec00ed321a9c246e00598f8.tar.gz
kernel-qcow2-util-linux-eebf2dd89ba905c52ec00ed321a9c246e00598f8.tar.xz
kernel-qcow2-util-linux-eebf2dd89ba905c52ec00ed321a9c246e00598f8.zip
libsmartcols: add scols_line_is_ancestor()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libsmartcols/src/line.c')
-rw-r--r--libsmartcols/src/line.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/libsmartcols/src/line.c b/libsmartcols/src/line.c
index 1c3141a16..134bf2d8e 100644
--- a/libsmartcols/src/line.c
+++ b/libsmartcols/src/line.c
@@ -307,6 +307,25 @@ int scols_line_next_child(struct libscols_line *ln,
return rc;
}
+
+/**
+ * scols_line_is_ancestor:
+ * @ln: line
+ * @parent: potential parent
+ *
+ * The function is designed to detect circular dependencies between @ln and
+ * @parent. It checks if @ln is not any (grand) parent in the @parent's tree.
+ */
+int scols_line_is_ancestor(struct libscols_line *ln, struct libscols_line *parent)
+{
+ while (parent) {
+ if (parent == ln)
+ return 1;
+ parent = scols_line_get_parent(parent);
+ };
+ return 0;
+}
+
/**
* scols_line_set_color:
* @ln: a pointer to a struct libscols_line instance