diff options
author | Karel Zak | 2017-05-05 12:12:43 +0200 |
---|---|---|
committer | Karel Zak | 2017-05-05 12:12:43 +0200 |
commit | eebf2dd89ba905c52ec00ed321a9c246e00598f8 (patch) | |
tree | 506d8e70bc21e0560100d6618156022b40747da0 /libsmartcols/src/line.c | |
parent | column: add note that circular dependencies are ignored (diff) | |
download | kernel-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.c | 19 |
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 |