#include <stddef.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "alloc/malloc.h"
}
/*@observer@*//*@null@*/struct sgrp *
-sgetsgent(const char *string)
+sgetsgent(const char *s)
{
static char *sgrbuf = NULL;
- static size_t sgrbuflen = 0;
char *fields[FIELDS];
char *cp;
int i;
- size_t len = strlen (string) + 1;
- if (len > sgrbuflen) {
- char *buf = REALLOC(sgrbuf, len, char);
- if (NULL == buf)
- return NULL;
-
- sgrbuf = buf;
- sgrbuflen = len;
- }
+ free(sgrbuf);
+ sgrbuf = strdup(s);
+ if (sgrbuf == NULL)
+ return NULL;
- strcpy (sgrbuf, string);
stpsep(sgrbuf, "\n");
/*
#ident "$Id$"
-#include <stdio.h>
-#include <sys/types.h>
#include <grp.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
+#include <sys/types.h>
#include "alloc/malloc.h"
#include "alloc/reallocf.h"
}
-struct group *sgetgrent (const char *buf)
+struct group *
+sgetgrent(const char *s)
{
static char *grpbuf = NULL;
- static size_t size = 0;
static char *grpfields[NFIELDS];
static struct group grent;
int i;
char *cp;
- if (strlen (buf) + 1 > size) {
- /* no need to use realloc() here - just free it and
- allocate a larger block */
- free (grpbuf);
- size = strlen (buf) + 1000; /* at least: strlen(buf) + 1 */
- grpbuf = MALLOC(size, char);
- if (grpbuf == NULL) {
- size = 0;
- return NULL;
- }
- }
- strcpy (grpbuf, buf);
+ free(grpbuf);
+ grpbuf = strdup(s);
+ if (grpbuf == NULL)
+ return NULL;
+
stpsep(grpbuf, "\n");
for (cp = grpbuf, i = 0; (i < NFIELDS) && (NULL != cp); i++)