diff options
author | hwspeedy <ns@bigbear.dk> | 2024-05-04 10:50:33 +0200 |
---|---|---|
committer | hwspeedy <ns@bigbear.dk> | 2024-05-04 10:50:33 +0200 |
commit | 7a55301afc255119bc0b5bcd0ec411f8151d4802 (patch) | |
tree | 621d93ef1ac2216e3f813624d657849beb40de2c /modules | |
parent | 47b8c66bb26c1a60aba8aa31774c2e6bdfb7140c (diff) |
FIX Improve UX - Groups sorted by group name
Diffstat (limited to 'modules')
-rw-r--r-- | modules/computer/groups.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/modules/computer/groups.c b/modules/computer/groups.c index 9371e211..e39a8abc 100644 --- a/modules/computer/groups.c +++ b/modules/computer/groups.c @@ -21,12 +21,13 @@ #include "hardinfo.h" #include "computer.h" -gchar *groups = NULL; +gint comparGroups (gpointer a, gpointer b) {return strcmp( (char*)a, (char*)b );} -void -scan_groups_do(void) +gchar *groups = NULL; +void scan_groups_do(void) { struct group *group_; + GList *list=NULL, *a; setgrent(); group_ = getgrent(); @@ -37,9 +38,22 @@ scan_groups_do(void) groups = g_strdup(""); while (group_) { - groups = h_strdup_cprintf("%s=%d\n", groups, group_->gr_name, group_->gr_gid); + list=g_list_prepend(list,g_strdup_printf("%s=%d\n", group_->gr_name, group_->gr_gid)); group_ = getgrent(); } endgrent(); + + //sort + list=g_list_sort(list,(GCompareFunc)comparGroups); + + while (list) { + groups = h_strdup_cprintf("%s", groups, (char *)list->data); + + //next and free + a=list; + list=list->next; + free(a->data); + g_list_free_1(a); + } } |