return rc;
}
+
+/**
+ * scols_filter_has_holder:
+ * @fltr: filter instance
+ * @name: wanted holder
+ *
+ * Returns: 0 or 1
+ *
+ * Since: 2.42
+ */
+int scols_filter_has_holder(struct libscols_filter *fltr, const char *name)
+{
+ struct libscols_iter itr;
+ const char *n = NULL;
+
+ if (!fltr || !name)
+ return 0;
+
+ scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
+
+ while (scols_filter_next_holder(fltr, &itr, &n, 0) == 0) {
+ if (strcmp(n, name) == 0)
+ return 1;
+ }
+
+ return 0;
+}
extern int scols_filter_next_holder(struct libscols_filter *fltr,
struct libscols_iter *itr, const char **name, int type);
+extern int scols_filter_has_holder(struct libscols_filter *fltr, const char *name);
+
extern int scols_filter_assign_column(struct libscols_filter *fltr,
struct libscols_iter *itr,
const char *name, struct libscols_column *col);
return -1;
}
-static int is_column_in_filter(int id, struct libscols_filter *filter)
+static inline const char *column_id_to_name(int id)
{
- int r = 0;
- const char *name = NULL;
- struct libscols_iter *itr = scols_new_iter(SCOLS_ITER_FORWARD);
-
- if (!itr)
- err(EXIT_FAILURE, _("failed to allocate iterator"));
-
- while (scols_filter_next_holder(filter, itr, &name, 0) == 0) {
- if (strcmp(infos[id].name, name) == 0) {
- r = 1;
- break;
- }
- }
+ assert(id >= 0);
+ assert(id < (int) ARRAY_SIZE(infos));
- scols_free_iter(itr);
- return r;
+ return infos[ id ].name;
}
static int has_column(int id)
return &infos[ get_column_id(num) ];
}
+
#ifdef USE_NS_GET_API
/* Get the inode number for the parent namespace of the namespace `fd' specifies.
* If `pfd' is non-null, the file descriptor opening the parent namespace.*/
#ifdef HAVE_LINUX_NET_NAMESPACE_H
if (has_column(COL_NETNSID)
- || (ls.filter && is_column_in_filter(COL_NETNSID, ls.filter)))
+ || (ls.filter && scols_filter_has_holder(ls.filter,
+ column_id_to_name(COL_NETNSID))))
netlink_fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
#endif
ls.tab = mnt_new_table_from_file(_PATH_PROC_MOUNTINFO);