(void) fprintf(to, "%s:*:%d:%s\n", group, gid, name);
(void) fprintf(to, "%s:*:%u:%s\n", group, gid, name);
creategid(char *group, int gid, char *name){	struct stat	st;	FILE		*from;	FILE		*to;	char		buf[LINE_MAX];	char		f[MaxFileNameLen];	int		fd;	int		cc;	if (getgrnam(group) != NULL) {		warnx("group `%s' already exists", group);		return 0;	}	if ((from = fopen(_PATH_GROUP, "r")) == NULL) {		warn("can't create gid for %s: can't open %s", group,		    _PATH_GROUP);		return 0;	}	if (flock(fileno(from), LOCK_EX | LOCK_NB) < 0) {		warn("can't lock `%s'", _PATH_GROUP);	}	(void) fstat(fileno(from), &st);	(void) snprintf(f, sizeof(f), "%s.XXXXXXXX", _PATH_GROUP);	if ((fd = mkstemp(f)) < 0) {		(void) fclose(from);		warn("can't create gid: mkstemp failed");		return 0;	}	if ((to = fdopen(fd, "w")) == NULL) {		(void) fclose(from);		(void) close(fd);		(void) unlink(f);		warn("can't create gid: fdopen `%s' failed", f);		return 0;	}	while ((cc = fread(buf, sizeof(char), sizeof(buf), from)) > 0) {		if (fwrite(buf, cc, 1, to) <= 0) {			(void) fclose(from);			(void) fclose(to);			(void) unlink(f);			warn("can't create gid: short write to `%s'", f);			return 0;		}	}	(void) fprintf(to, "%s:*:%d:%s\n", group, gid, name);	(void) fclose(from);	(void) fclose(to);	if (rename(f, _PATH_GROUP) < 0) {		warn("can't create gid: can't rename `%s' to `%s'", f,		    _PATH_GROUP);		return 0;	}	(void) chmod(_PATH_GROUP, st.st_mode & 07777);	return 1;}