/** * scols_line_add_child: * @ln: a pointer to a struct libscols_line instance * @child: a pointer to a struct libscols_line instance * * Sets @child as a child of @ln. * * Returns: 0, a negative value in case of an error. */ int scols_line_add_child(struct libscols_line *ln, struct libscols_line *child) { if (!ln || !child) return -EINVAL; DBG(LINE, ul_debugobj(ln, "add child %p", child)); scols_ref_line(child); scols_ref_line(ln); /* unref old<->parent */ if (child->parent) scols_line_remove_child(child->parent, child); /* new reference from parent to child */ list_add_tail(&child->ln_children, &ln->ln_branch); /* new reference from child to parent */ child->parent = ln; return 0; }
/** * scols_line_add_child: * @ln: a pointer to a struct libscols_line instance * @child: a pointer to a struct libscols_line instance * * Sets @child as a child of @ln. * * Returns: 0, a negative value in case of an error. */ int scols_line_add_child(struct libscols_line *ln, struct libscols_line *child) { assert(ln); assert(child); if (!ln || !child) return -EINVAL; /* unref old<->parent */ if (child->parent) scols_line_remove_child(child->parent, child); /* new reference from parent to child */ list_add_tail(&child->ln_children, &ln->ln_branch); scols_ref_line(child); /* new reference from child to parent */ child->parent = ln; scols_ref_line(ln); return 0; }