MCPcopy Index your code
hub / github.com/F-Stack/f-stack / __gr_scan

Function __gr_scan

tools/libutil/gr_util.c:599–640  ·  view source on GitHub ↗

* Scan a line and place it into a group structure. */

Source from the content-addressed store, hash-verified

597 * Scan a line and place it into a group structure.
598 */
599static bool
600__gr_scan(char *line, struct group *gr)
601{
602 char *loc;
603 int ndx;
604
605 /* Assign non-member information to structure. */
606 gr->gr_name = line;
607 if ((loc = strchr(line, ':')) == NULL)
608 return (false);
609 *loc = '\0';
610 gr->gr_passwd = loc + 1;
611 if (*gr->gr_passwd == ':')
612 *gr->gr_passwd = '\0';
613 else {
614 if ((loc = strchr(loc + 1, ':')) == NULL)
615 return (false);
616 *loc = '\0';
617 }
618 if (sscanf(loc + 1, "%u", &gr->gr_gid) != 1)
619 return (false);
620
621 /* Assign member information to structure. */
622 if ((loc = strchr(loc + 1, ':')) == NULL)
623 return (false);
624 line = loc + 1;
625 gr->gr_mem = NULL;
626 ndx = 0;
627 do {
628 gr->gr_mem = reallocf(gr->gr_mem, sizeof(*gr->gr_mem) *
629 (ndx + 1));
630 if (gr->gr_mem == NULL)
631 return (false);
632
633 /* Skip locations without members (i.e., empty string). */
634 do {
635 gr->gr_mem[ndx] = strsep(&line, ",");
636 } while (gr->gr_mem[ndx] != NULL && *gr->gr_mem[ndx] == '\0');
637 } while (gr->gr_mem[ndx++] != NULL);
638
639 return (true);
640}
641
642/*
643 * Create a struct group from a line.

Callers 1

gr_scanFunction · 0.85

Calls 4

strchrFunction · 0.85
sscanfFunction · 0.85
strsepFunction · 0.85
reallocfFunction · 0.50

Tested by

no test coverage detected