FreeBSD/usr.sbin/edquota/edquota.c
/*
 * Merge changes of grace times in an ASCII file into a quotause list.
 */
Merge changes of grace times in an ASCII file into a quotause list.
Merge changes of grace times in an ASCII file into a quotause list .
int
readtimes(struct quotause *quplist, char *inname)
{
	struct quotause *qup;
	FILE *fd;
	int cnt;
	char *cp;
	uintmax_t itime, btime, iseconds, bseconds;
	char *fsp, bunits[10], iunits[10], line1[BUFSIZ];
	fd = fopen(inname, "r");
	if (fd == NULL) {
		warnx("can't re-read temp file!!");
		return (0);
	}
	(void) fgets(line1, sizeof (line1), fd);
	(void) fgets(line1, sizeof (line1), fd);
	while (fgets(line1, sizeof (line1), fd) != NULL) {
		if ((fsp = strtok(line1, " \t:")) == NULL) {
			warnx("%s: bad format", line1);
			return (0);
		}
		if ((cp = strtok((char *)0, "\n")) == NULL) {
			warnx("%s: %s: bad format", fsp, &fsp[strlen(fsp) + 1]);
			return (0);
		}
		cnt = sscanf(cp,
		    " block grace period: %ju %s file grace period: %ju %s",
		    &btime, bunits, &itime, iunits);
		if (cnt != 4) {
			warnx("%s:%s: bad format", fsp, cp);
			return (0);
		}
		if (cvtatos(btime, bunits, &bseconds) == 0)
			return (0);
		if (cvtatos(itime, iunits, &iseconds) == 0)
			return (0);
		for (qup = quplist; qup; qup = qup->next) {
			if (strcmp(fsp, qup->fsname))
				continue;
			qup->dqblk.dqb_btime = bseconds;
			qup->dqblk.dqb_itime = iseconds;
			qup->flags |= FOUND;
			break;
		}
	}
	fclose(fd);
	for (qup = quplist; qup; qup = qup->next) {
		if (qup->flags & FOUND) {
			qup->flags &= ~FOUND;
			continue;
		}
		qup->dqblk.dqb_btime = 0;
		qup->dqblk.dqb_itime = 0;
	}
	return (1);
}
int readtimes ( struct quotause * quplist , char * inname ) { struct quotause * qup ; FILE * fd ; int cnt ; char * cp ; uintmax_t itime , btime , iseconds , bseconds ; char * fsp , bunits [ 10 ] , iunits [ 10 ] , line1 [ BUFSIZ ] ; fd = fopen ( inname , " " ) ; if ( fd == NULL ) { warnx ( " " ) ; return ( 0 ) ; } ( void ) fgets ( line1 , sizeof ( line1 ) , fd ) ; ( void ) fgets ( line1 , sizeof ( line1 ) , fd ) ; while ( fgets ( line1 , sizeof ( line1 ) , fd ) != NULL ) { if ( ( fsp = strtok ( line1 , " \t " ) ) == NULL ) { warnx ( " " , line1 ) ; return ( 0 ) ; } if ( ( cp = strtok ( ( char * ) 0 , " \n " ) ) == NULL ) { warnx ( " " , fsp , & fsp [ strlen ( fsp ) + 1 ] ) ; return ( 0 ) ; } cnt = sscanf ( cp , " " , & btime , bunits , & itime , iunits ) ; if ( cnt != 4 ) { warnx ( " " , fsp , cp ) ; return ( 0 ) ; } if ( cvtatos ( btime , bunits , & bseconds ) == 0 ) return ( 0 ) ; if ( cvtatos ( itime , iunits , & iseconds ) == 0 ) return ( 0 ) ; for ( qup = quplist ; qup ; qup = qup -> next ) { if ( strcmp ( fsp , qup -> fsname ) ) continue ; qup -> dqblk . dqb_btime = bseconds ; qup -> dqblk . dqb_itime = iseconds ; qup -> flags |= FOUND ; break ; } } fclose ( fd ) ; for ( qup = quplist ; qup ; qup = qup -> next ) { if ( qup -> flags & FOUND ) { qup -> flags &= ~ FOUND ; continue ; } qup -> dqblk . dqb_btime = 0 ; qup -> dqblk . dqb_itime = 0 ; } return ( 1 ) ; }
Merge changes of grace times in an ASCII file into a quotause list.
Merge changes of grace times in an ASCII file into a quotause list .
/*
	 * Discard two title lines, then read lines to process.
	 */ /*
	 * reset default grace periods for any filesystems
	 * that have not been found.
	 */