xref: /csrg-svn/usr.bin/pascal/libpc/RESET.c (revision 26243)
11695Smckusick /* Copyright (c) 1979 Regents of the University of California */
21695Smckusick 
3*26243Slepreau static char sccsid[] = "@(#)RESET.c 1.8 02/19/86";
41695Smckusick 
51695Smckusick #include "h00vars.h"
61695Smckusick 
71695Smckusick RESET(filep, name, maxnamlen, datasize)
81695Smckusick 
91695Smckusick 	register struct iorec	*filep;
101695Smckusick 	char			*name;
113026Smckusic 	long			maxnamlen;
123026Smckusic 	long			datasize;
131695Smckusick {
141695Smckusick 	if (name == NULL && filep == INPUT && filep->fname[0] == '\0') {
15*26243Slepreau 		if (fseek(filep->fbuf, (long)0, 0) == -1) {
163869Smckusic 			PERROR("Could not reset ", filep->pfname);
171695Smckusick 			return;
181695Smckusick 		}
197495Smckusick 		filep->funit &= ~EOFF;
207495Smckusick 		filep->funit |= (SYNC | EOLN);
211695Smckusick 		return;
221695Smckusick 	}
231695Smckusick 	filep = GETNAME(filep, name, maxnamlen, datasize);
241695Smckusick 	filep->fbuf = fopen(filep->fname, "r");
251695Smckusick 	if (filep->fbuf == NULL) {
265717Smckusic 		/*
275717Smckusic 		 * This allows unnamed temp files to be opened even if
285717Smckusic 		 * they have not been rewritten yet. We decided to remove
295717Smckusic 		 * this feature since the standard requires that files be
305717Smckusic 		 * defined before being reset.
315717Smckusic 		 *
321695Smckusick 		if (filep->funit & TEMP) {
331695Smckusick 			filep->funit |= (EOFF | SYNC | FREAD);
341695Smckusick 			return;
351695Smckusick 		}
365717Smckusic 		 */
373869Smckusic 		PERROR("Could not open ", filep->pfname);
381695Smckusick 		return;
391695Smckusick 	}
401695Smckusick 	filep->funit |= (SYNC | FREAD);
415024Smckusic 	if (filep->funit & FTEXT)
425024Smckusic 		filep->funit |= EOLN;
431695Smckusick 	if (filep->fblk > PREDEF) {
441695Smckusick 		setbuf(filep->fbuf, &filep->buf[0]);
451695Smckusick 	}
461695Smckusick }
47