lib/libutil/gr_util.c
int
gr_tmp(int mfd)
{
	char buf[8192];
	ssize_t nr;
	const char *p;
	int tfd;

	if (*group_file == '\0')
		return (-1);
	if ((p = strrchr(group_file, '/')))
		++p;
	else
		p = group_file;
	if (snprintf(tempname, sizeof(tempname), "%.*sgroup.XXXXXX",
		(int)(p - group_file), group_file) >= (int)sizeof(tempname)) {
		errno = ENAMETOOLONG;
		return (-1);
	}
	if ((tfd = mkstemp(tempname)) == -1)
		return (-1);
	if (mfd != -1) {
		while ((nr = read(mfd, buf, sizeof(buf))) > 0)
			if (write(tfd, buf, (size_t)nr) != nr)
				break;
		if (nr != 0) {
			unlink(tempname);
			*tempname = '\0';
			close(tfd);
			return (-1);
		}
	}
	return (tfd);
}
/*
 * Create and open a presmuably safe temp file for editing group data
 */
Create and open a presmuably safe temp file for editing group data
Create and open a presmuably safe temp file for editing group data
int
gr_tmp(int mfd)
{
	char buf[8192];
	ssize_t nr;
	const char *p;
	int tfd;
	if (*group_file == '\0')
		return (-1);
	if ((p = strrchr(group_file, '/')))
		++p;
	else
		p = group_file;
	if (snprintf(tempname, sizeof(tempname), "%.*sgroup.XXXXXX",
		(int)(p - group_file), group_file) >= (int)sizeof(tempname)) {
		errno = ENAMETOOLONG;
		return (-1);
	}
	if ((tfd = mkstemp(tempname)) == -1)
		return (-1);
	if (mfd != -1) {
		while ((nr = read(mfd, buf, sizeof(buf))) > 0)
			if (write(tfd, buf, (size_t)nr) != nr)
				break;
		if (nr != 0) {
			unlink(tempname);
			*tempname = '\0';
			close(tfd);
			return (-1);
		}
	}
	return (tfd);
}
int gr_tmp ( int mfd ) { char buf [ 8192 ] ; ssize_t nr ; const char * p ; int tfd ; if ( * group_file == ' \0 ' ) return ( -1 ) ; if ( ( p = strrchr ( group_file , ' ' ) ) ) ++ p ; else p = group_file ; if ( snprintf ( tempname , sizeof ( tempname ) , " " , ( int ) ( p - group_file ) , group_file ) >= ( int ) sizeof ( tempname ) ) { errno = ENAMETOOLONG ; return ( -1 ) ; } if ( ( tfd = mkstemp ( tempname ) ) == -1 ) return ( -1 ) ; if ( mfd != -1 ) { while ( ( nr = read ( mfd , buf , sizeof ( buf ) ) ) > 0 ) if ( write ( tfd , buf , ( size_t ) nr ) != nr ) break ; if ( nr != 0 ) { unlink ( tempname ) ; * tempname = ' \0 ' ; close ( tfd ) ; return ( -1 ) ; } } return ( tfd ) ; }
Create and open a presmuably safe temp file for editing group data
Create and open a presmuably safe temp file for editing group data