* utilunix.c (init_groups): Use glib memory allocation functions.

This commit is contained in:
Andrew V. Samoilov 2005-02-01 12:04:05 +00:00
parent a7a42c3d8b
commit 172cead7fb
2 changed files with 27 additions and 24 deletions

View File

@ -1,3 +1,7 @@
2005-02-01 Andrew V. Samoilov <sav@bcs.zp.ua>
* utilunix.c (init_groups): Use glib memory allocation functions.
2005-01-31 Roland Illig <roland.illig@gmx.de>
* view.c: Eliminated two global variables and put them into the

View File

@ -94,33 +94,32 @@ void init_groups (void)
#ifdef HAVE_GETGROUPLIST
{
gid_t *groups = NULL;
int ng = 1;
//struct group *grp;
gid_t *newgroups = NULL;
groups = (gid_t *) malloc(ng * sizeof(gid_t));
gid_t *groups = g_new (gid_t, 1);
int ng = 1;
gid_t *newgroups = NULL;
if (getgrouplist(pwd->pw_name, pwd->pw_gid, groups, &ng) == -1) {
newgroups = (gid_t *) malloc(ng * sizeof(gid_t));
if (newgroups != NULL) {
free (groups);
groups = newgroups;
getgrouplist (pwd->pw_name, pwd->pw_gid, groups, &ng);
} else
ng = 1;
}
if (getgrouplist (pwd->pw_name, pwd->pw_gid, groups, &ng) == -1) {
newgroups = g_new (gid_t, ng);
if (newgroups != NULL) {
g_free (groups);
groups = newgroups;
getgrouplist (pwd->pw_name, pwd->pw_gid, groups, &ng);
} else
ng = 1;
}
for (i = 0; i < ng; i++) {
grp = getgrgid(groups[i]);
if (grp != NULL && !g_tree_lookup (current_user_gid, GUINT_TO_POINTER ((int) grp->gr_gid))) {
g_tree_insert (current_user_gid,
GUINT_TO_POINTER ((int) grp->gr_gid),
g_strdup (grp->gr_name));
}
}
for (i = 0; i < ng; i++) {
grp = getgrgid (groups[i]);
if (grp != NULL
&& !g_tree_lookup (current_user_gid,
GUINT_TO_POINTER ((int) grp->gr_gid))) {
g_tree_insert (current_user_gid,
GUINT_TO_POINTER ((int) grp->gr_gid),
g_strdup (grp->gr_name));
}
}
free(groups);
g_free (groups);
}
#else
setgrent ();