lib/libutil/gr_util.c
char *
gr_make(const struct group *gr)
{
	char *line;
	size_t line_size;
	int ndx;

	/* Calculate the length of the group line. */
	line_size = snprintf(NULL, 0, group_line_format, gr->gr_name,
	    gr->gr_passwd, (uintmax_t)gr->gr_gid) + 1;
	if (gr->gr_mem != NULL) {
		for (ndx = 0; gr->gr_mem[ndx] != NULL; ndx++)
			line_size += strlen(gr->gr_mem[ndx]) + 1;
		if (ndx > 0)
			line_size--;
	}

	/* Create the group line and fill it. */
	if ((line = malloc(line_size)) == NULL)
		return (NULL);
	snprintf(line, line_size, group_line_format, gr->gr_name, gr->gr_passwd,
	    (uintmax_t)gr->gr_gid);
	if (gr->gr_mem != NULL)
		for (ndx = 0; gr->gr_mem[ndx] != NULL; ndx++) {
			strcat(line, gr->gr_mem[ndx]);
			if (gr->gr_mem[ndx + 1] != NULL)
				strcat(line, ",");
		}

	return (line);
}
/*
 * Make a group line out of a struct group.
 */
Make a group line out of a struct group.
Make a group line out of a struct group .
char *
gr_make(const struct group *gr)
{
	char *line;
	size_t line_size;
	int ndx;
	line_size = snprintf(NULL, 0, group_line_format, gr->gr_name,
	    gr->gr_passwd, (uintmax_t)gr->gr_gid) + 1;
	if (gr->gr_mem != NULL) {
		for (ndx = 0; gr->gr_mem[ndx] != NULL; ndx++)
			line_size += strlen(gr->gr_mem[ndx]) + 1;
		if (ndx > 0)
			line_size--;
	}
	if ((line = malloc(line_size)) == NULL)
		return (NULL);
	snprintf(line, line_size, group_line_format, gr->gr_name, gr->gr_passwd,
	    (uintmax_t)gr->gr_gid);
	if (gr->gr_mem != NULL)
		for (ndx = 0; gr->gr_mem[ndx] != NULL; ndx++) {
			strcat(line, gr->gr_mem[ndx]);
			if (gr->gr_mem[ndx + 1] != NULL)
				strcat(line, ",");
		}
	return (line);
}
char * gr_make ( const struct group * gr ) { char * line ; size_t line_size ; int ndx ; line_size = snprintf ( NULL , 0 , group_line_format , gr -> gr_name , gr -> gr_passwd , ( uintmax_t ) gr -> gr_gid ) + 1 ; if ( gr -> gr_mem != NULL ) { for ( ndx = 0 ; gr -> gr_mem [ ndx ] != NULL ; ndx ++ ) line_size += strlen ( gr -> gr_mem [ ndx ] ) + 1 ; if ( ndx > 0 ) line_size -- ; } if ( ( line = malloc ( line_size ) ) == NULL ) return ( NULL ) ; snprintf ( line , line_size , group_line_format , gr -> gr_name , gr -> gr_passwd , ( uintmax_t ) gr -> gr_gid ) ; if ( gr -> gr_mem != NULL ) for ( ndx = 0 ; gr -> gr_mem [ ndx ] != NULL ; ndx ++ ) { strcat ( line , gr -> gr_mem [ ndx ] ) ; if ( gr -> gr_mem [ ndx + 1 ] != NULL ) strcat ( line , " " ) ; } return ( line ) ; }
Make a group line out of a struct group.
Make a group line out of a struct group .
/* Calculate the length of the group line. */ /* Create the group line and fill it. */