Use strdup(3) instead of reimplementing it inline.

This commit is contained in:
Dima Dorfman 2001-06-24 18:21:52 +00:00
parent f053d7777b
commit 8d3c1246b8
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=78711

View File

@ -475,25 +475,19 @@ extract_ugid(const char *str, struct mtpt_info *mip)
{
char *ug; /* Writable 'str'. */
char *user, *group; /* Result of extracton. */
size_t strl; /* Length of 'str' incl. NULL. */
struct passwd *pw;
struct group *gr;
char *p;
uid_t *uid;
gid_t *gid;
size_t rv;
uid = &mip->mi_uid;
gid = &mip->mi_gid;
mip->mi_have_uid = mip->mi_have_gid = false;
/* Extract the user and group from 'str'. Format above. */
strl = strlen(str) + 1;
ug = malloc(strl);
ug = strdup(str);
assert(ug != NULL);
rv = strlcpy(ug, str, strl);
if (rv >= strl)
errx(1, "-w word too long (%ld >= %ld)", (long)rv, (long)strl);
group = ug;
user = strsep(&group, ":");
if (user == NULL || group == NULL || *user == '\0' || *group == '\0')