From c5a8fc5f5153f1d2859ddc4f4030c178d77eb726 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 9 Nov 2008 16:21:54 +0100 Subject: [PATCH] Make --limit work also for the user summary. --- select.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/select.c b/select.c index fd25da4..7537f4c 100644 --- a/select.c +++ b/select.c @@ -117,6 +117,10 @@ struct user_summary_info { int osl_errno; }; +struct user_summary_line_info { + struct format_info *fi; + uint32_t count; +}; static FILE *output_file; @@ -348,7 +352,7 @@ static int compute_user_summary(struct user_info *ui, __a_unused void *data) static int print_user_summary_line(struct user_info *ui, void *data) { - struct format_info *fi = data; + struct user_summary_line_info *usli = data; union atom_value values[] = { [usa_pw_name] = {.string_value = ui->pw_name? ui->pw_name : "?"}, @@ -358,11 +362,15 @@ static int print_user_summary_line(struct user_info *ui, void *data) [usa_size] = {.num_value = (long long unsigned)ui->bytes} }; char *buf; - int ret; + int ret = -E_LOOP_COMPLETE; - buf = format_items(fi, values); + if (!usli->count) + return ret; + + buf = format_items(usli->fi, values); ret = output("%s", buf); free(buf); + usli->count--; return ret; } @@ -402,6 +410,10 @@ static int print_user_summary(struct format_info *fi) { int ret; int (*comp)(struct user_info *a, struct user_info *b); + struct user_summary_line_info usli = { + .fi = fi, + .count = select_conf.limit_arg + }; if (!select_conf.no_headers_given) { ret = output("User summary\n"); @@ -429,7 +441,10 @@ static int print_user_summary(struct format_info *fi) break; } sort_hash_table(comp); - return for_each_admissible_user(print_user_summary_line, fi); + ret = for_each_admissible_user(print_user_summary_line, &usli); + if (ret == -E_LOOP_COMPLETE) + ret = 1; + return ret; } static int user_list_loop_function(struct osl_row *row, void *data) -- 2.39.5