summaryrefslogtreecommitdiffstats
path: root/lib/groupmem.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/groupmem.c')
-rw-r--r--lib/groupmem.c40
1 files changed, 6 insertions, 34 deletions
diff --git a/lib/groupmem.c b/lib/groupmem.c
index c858b72..69d4435 100644
--- a/lib/groupmem.c
+++ b/lib/groupmem.c
@@ -12,6 +12,8 @@
#ident "$Id$"
+#include "alloc.h"
+#include "memzero.h"
#include "prototypes.h"
#include "defines.h"
#include "groupio.h"
@@ -21,12 +23,11 @@
struct group *gr;
int i;
- gr = (struct group *) malloc (sizeof *gr);
+ gr = CALLOC(1, struct group);
if (NULL == gr) {
return NULL;
}
/* The libc might define other fields. They won't be copied. */
- memset (gr, 0, sizeof *gr);
gr->gr_gid = grent->gr_gid;
/*@-mustfreeonly@*/
gr->gr_name = strdup (grent->gr_name);
@@ -46,7 +47,7 @@
for (i = 0; grent->gr_mem[i]; i++);
/*@-mustfreeonly@*/
- gr->gr_mem = (char **) malloc ((i + 1) * sizeof (char *));
+ gr->gr_mem = MALLOC(i + 1, char *);
/*@=mustfreeonly@*/
if (NULL == gr->gr_mem) {
gr_free(gr);
@@ -76,7 +77,8 @@ void gr_free_members (struct group *grent)
}
}
-void gr_free (/*@out@*/ /*@only@*/struct group *grent)
+void
+gr_free(/*@only@*/struct group *grent)
{
free (grent->gr_name);
if (NULL != grent->gr_passwd) {
@@ -86,33 +88,3 @@ void gr_free (/*@out@*/ /*@only@*/struct group *grent)
gr_free_members(grent);
free (grent);
}
-
-bool gr_append_member(struct group *grp, char *member)
-{
- int i;
-
- if (NULL == grp->gr_mem || grp->gr_mem[0] == NULL) {
- grp->gr_mem = (char **)malloc(2 * sizeof(char *));
- if (!grp->gr_mem) {
- return false;
- }
- grp->gr_mem[0] = strdup(member);
- if (!grp->gr_mem[0]) {
- return false;
- }
- grp->gr_mem[1] = NULL;
- return true;
- }
-
- for (i = 0; grp->gr_mem[i]; i++) ;
- grp->gr_mem = realloc(grp->gr_mem, (i + 2) * sizeof(char *));
- if (NULL == grp->gr_mem) {
- return false;
- }
- grp->gr_mem[i] = strdup(member);
- if (NULL == grp->gr_mem[i]) {
- return false;
- }
- grp->gr_mem[i + 1] = NULL;
- return true;
-}