xref: /csrg-svn/usr.bin/pascal/libpc/RESET.c (revision 62096)
140865Sbostic /*-
2*62096Sbostic  * Copyright (c) 1979, 1993
3*62096Sbostic  *	The Regents of the University of California.  All rights reserved.
440865Sbostic  *
540865Sbostic  * %sccs.include.redist.c%
640865Sbostic  */
71695Smckusick 
840865Sbostic #ifndef lint
9*62096Sbostic static char sccsid[] = "@(#)RESET.c	8.1 (Berkeley) 06/06/93";
1040865Sbostic #endif /* not lint */
111695Smckusick 
121695Smckusick #include "h00vars.h"
131695Smckusick 
RESET(filep,name,maxnamlen,datasize)141695Smckusick RESET(filep, name, maxnamlen, datasize)
151695Smckusick 
161695Smckusick 	register struct iorec	*filep;
171695Smckusick 	char			*name;
183026Smckusic 	long			maxnamlen;
193026Smckusic 	long			datasize;
201695Smckusick {
211695Smckusick 	if (name == NULL && filep == INPUT && filep->fname[0] == '\0') {
2226243Slepreau 		if (fseek(filep->fbuf, (long)0, 0) == -1) {
233869Smckusic 			PERROR("Could not reset ", filep->pfname);
241695Smckusick 			return;
251695Smckusick 		}
267495Smckusick 		filep->funit &= ~EOFF;
277495Smckusick 		filep->funit |= (SYNC | EOLN);
281695Smckusick 		return;
291695Smckusick 	}
301695Smckusick 	filep = GETNAME(filep, name, maxnamlen, datasize);
311695Smckusick 	filep->fbuf = fopen(filep->fname, "r");
321695Smckusick 	if (filep->fbuf == NULL) {
335717Smckusic 		/*
345717Smckusic 		 * This allows unnamed temp files to be opened even if
355717Smckusic 		 * they have not been rewritten yet. We decided to remove
365717Smckusic 		 * this feature since the standard requires that files be
375717Smckusic 		 * defined before being reset.
385717Smckusic 		 *
391695Smckusick 		if (filep->funit & TEMP) {
401695Smckusick 			filep->funit |= (EOFF | SYNC | FREAD);
411695Smckusick 			return;
421695Smckusick 		}
435717Smckusic 		 */
443869Smckusic 		PERROR("Could not open ", filep->pfname);
451695Smckusick 		return;
461695Smckusick 	}
471695Smckusick 	filep->funit |= (SYNC | FREAD);
485024Smckusic 	if (filep->funit & FTEXT)
495024Smckusic 		filep->funit |= EOLN;
501695Smckusick 	if (filep->fblk > PREDEF) {
511695Smckusick 		setbuf(filep->fbuf, &filep->buf[0]);
521695Smckusick 	}
531695Smckusick }
54