MCPcopy Create free account
hub / github.com/F-Stack/f-stack / grmemlen

Function grmemlen

tools/libutil/gr_util.c:563–594  ·  view source on GitHub ↗

* Calculate length of a struct group + given name */

Source from the content-addressed store, hash-verified

561 * Calculate length of a struct group + given name
562 */
563static size_t
564grmemlen(const struct group *gr, const char *name, int *num_mem)
565{
566 size_t len;
567 int i;
568
569 if (gr == NULL)
570 return (0);
571 /* Calculate size of the group. */
572 len = sizeof(*gr);
573 if (gr->gr_name != NULL)
574 len += strlen(gr->gr_name) + 1;
575 if (gr->gr_passwd != NULL)
576 len += strlen(gr->gr_passwd) + 1;
577 i = 0;
578 if (gr->gr_mem != NULL) {
579 for (; gr->gr_mem[i] != NULL; i++) {
580 len += strlen(gr->gr_mem[i]) + 1;
581 len += sizeof(*gr->gr_mem);
582 }
583 }
584 if (name != NULL) {
585 i++;
586 len += strlen(name) + 1;
587 len += sizeof(*gr->gr_mem);
588 }
589 /* Allow for NULL pointer */
590 if (i != 0)
591 len += sizeof(*gr->gr_mem);
592 *num_mem = i;
593 return(len);
594}
595
596/*
597 * Scan a line and place it into a group structure.

Callers 1

gr_addFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected