xref: /original-bsd/usr.bin/pascal/libpc/RESET.c (revision 1f3a482a)
1 /* Copyright (c) 1979 Regents of the University of California */
2 
3 static char sccsid[] = "@(#)RESET.c 1.4 06/10/81";
4 
5 #include "h00vars.h"
6 
7 RESET(filep, name, maxnamlen, datasize)
8 
9 	register struct iorec	*filep;
10 	char			*name;
11 	long			maxnamlen;
12 	long			datasize;
13 {
14 	if (name == NULL && filep == INPUT && filep->fname[0] == '\0') {
15 		if (fseek(filep->fbuf, (long)0, 0)) {
16 			PERROR("Could not reset ", filep->pfname);
17 			return;
18 		}
19 		filep->funit &= ~(EOFF | EOLN);
20 		filep->funit |= SYNC;
21 		return;
22 	}
23 	filep = GETNAME(filep, name, maxnamlen, datasize);
24 	filep->fbuf = fopen(filep->fname, "r");
25 	if (filep->fbuf == NULL) {
26 		if (filep->funit & TEMP) {
27 			filep->funit |= (EOFF | SYNC | FREAD);
28 			return;
29 		}
30 		PERROR("Could not open ", filep->pfname);
31 		return;
32 	}
33 	filep->funit |= (SYNC | FREAD);
34 	if (filep->fblk > PREDEF) {
35 		setbuf(filep->fbuf, &filep->buf[0]);
36 	}
37 }
38