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