]> git.tue.mpg.de Git - adu.git/commitdiff
Make --limit work also for the user summary.
authorAndre Noll <maan@systemlinux.org>
Sun, 9 Nov 2008 15:21:54 +0000 (16:21 +0100)
committerAndre Noll <maan@systemlinux.org>
Sun, 9 Nov 2008 15:21:54 +0000 (16:21 +0100)
select.c

index fd25da48b48d264a896abd74099fe56375c5d8e6..7537f4cae3b638bccf6c51c23282ccb68b9b693c 100644 (file)
--- 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)