FreeBSD/contrib/ntp/ntpd/ntp_filegen.c
/*
 * this function sets up gen->fp to point to the correct
 * generation of the file for the time specified by 'now'
 *
 * 'now' usually is interpreted as second part of a l_fp as is in the cal...
 * library routines
 */
this function sets up gen->fp to point to the correct
generation of the file for the time specified by 'now'

'now' usually is interpreted as second part of a l_fp as is in the cal
library routines
this function sets up gen - > fp to point to the correct generation of the file for the time specified by ' now ' ' now ' usually is interpreted as second part of a l_fp as is in the cal library routines
void
filegen_setup(
	FILEGEN *	gen,
	u_int32		now
	)
{
	int	current;
	time_t	pivot;
	if (!(gen->flag & FGEN_FLAG_ENABLED)) {
		if (NULL != gen->fp) {
			fclose(gen->fp);
			gen->fp = NULL;
		}
		return;
	}
	switch (gen->type) {
	default:
	case FILEGEN_NONE:
		current = TRUE;
		break;
	case FILEGEN_PID:
		current = ((int)gen->id_lo == getpid());
		break;
	case FILEGEN_AGE:
		current = (gen->id_lo <= current_time) &&
			  (gen->id_hi > current_time);
		break;
	case FILEGEN_DAY:
	case FILEGEN_WEEK:
	case FILEGEN_MONTH:
	case FILEGEN_YEAR:
		current = (gen->id_lo <= now) &&
			  (gen->id_hi > now);
		break;
	}
	if (NULL == gen->fp || !current) {
		DPRINTF(1, ("filegen  %0x %u\n", gen->type, now));
		pivot = time(NULL);
		filegen_open(gen, now, &pivot);
	}
}
void filegen_setup ( FILEGEN * gen , u_int32 now ) { int current ; time_t pivot ; if ( ! ( gen -> flag & FGEN_FLAG_ENABLED ) ) { if ( NULL != gen -> fp ) { fclose ( gen -> fp ) ; gen -> fp = NULL ; } return ; } switch ( gen -> type ) { default : case FILEGEN_NONE : current = TRUE ; break ; case FILEGEN_PID : current = ( ( int ) gen -> id_lo == getpid ( ) ) ; break ; case FILEGEN_AGE : current = ( gen -> id_lo <= current_time ) && ( gen -> id_hi > current_time ) ; break ; case FILEGEN_DAY : case FILEGEN_WEEK : case FILEGEN_MONTH : case FILEGEN_YEAR : current = ( gen -> id_lo <= now ) && ( gen -> id_hi > now ) ; break ; } if ( NULL == gen -> fp || ! current ) { DPRINTF ( 1 , ( " \n " , gen -> type , now ) ) ; pivot = time ( NULL ) ; filegen_open ( gen , now , & pivot ) ; } }
this function sets up gen->fp to point to the correct
 generation of the file for the time specified by 'now'
this function sets up gen - > fp to point to the correct generation of the file for the time specified by ' now '
/*
	 * try to open file if not yet open
	 * reopen new file generation file on change of generation id
	 */