diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 14:30:35 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 14:30:35 +0000 |
commit | 378c18e5f024ac5a8aef4cb40d7c9aa9633d144c (patch) | |
tree | 44dfb6ca500d32cabd450649b322a42e70a30683 /misc-utils/lsfd-counter.c | |
parent | Initial commit. (diff) | |
download | util-linux-378c18e5f024ac5a8aef4cb40d7c9aa9633d144c.tar.xz util-linux-378c18e5f024ac5a8aef4cb40d7c9aa9633d144c.zip |
Adding upstream version 2.38.1.upstream/2.38.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'misc-utils/lsfd-counter.c')
-rw-r--r-- | misc-utils/lsfd-counter.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/misc-utils/lsfd-counter.c b/misc-utils/lsfd-counter.c new file mode 100644 index 0000000..55f0fde --- /dev/null +++ b/misc-utils/lsfd-counter.c @@ -0,0 +1,56 @@ +/* + * lsfd-counter.c - counter implementation used in --summary option + * + * Copyright (C) 2021 Red Hat, Inc. + * Copyright (C) 2021 Masatake YAMATO <yamato@redhat.com> + * + * This file may be redistributed under the terms of the + * GNU Lesser General Public License. + */ + +#include "lsfd-counter.h" + +#include "xalloc.h" + +struct lsfd_counter { + char *name; + size_t value; + struct lsfd_filter *filter; +}; + +struct lsfd_counter *lsfd_counter_new(const char *const name, struct lsfd_filter *filter) +{ + struct lsfd_counter *counter = xmalloc(sizeof(struct lsfd_counter)); + + counter->name = xstrdup(name); + counter->value = 0; + counter->filter = filter; + + return counter; +} + +void lsfd_counter_free(struct lsfd_counter *counter) +{ + lsfd_filter_free(counter->filter); + free(counter->name); + free(counter); +} + +bool lsfd_counter_accumulate(struct lsfd_counter *counter, struct libscols_line *ln) +{ + if (lsfd_filter_apply(counter->filter, ln)) { + counter->value++; + return true; + } + return false; +} + +const char *lsfd_counter_name(struct lsfd_counter *counter) +{ + return counter->name; +} + +size_t lsfd_counter_value(struct lsfd_counter *counter) +{ + return counter->value; +} |