xref: /original-bsd/usr.bin/pascal/libpc/READ4.c (revision 8bb7073f)
1 /* Copyright (c) 1979 Regents of the University of California */
2 
3 static char sccsid[] = "@(#)READ4.c 1.7 10/01/83";
4 
5 #include "h00vars.h"
6 #include <errno.h>
7 extern int errno;
8 
9 long
10 READ4(curfile)
11 
12 	register struct iorec	*curfile;
13 {
14 	long			data;
15 	int			retval;
16 
17 	if (curfile->funit & FWRITE) {
18 		ERROR("%s: Attempt to read, but open for writing\n",
19 			curfile->pfname);
20 		return;
21 	}
22 	UNSYNC(curfile);
23 	errno = 0;
24 	retval = fscanf(curfile->fbuf, "%ld", &data);
25 	if (retval == EOF) {
26 		ERROR("%s: Tried to read past end of file\n", curfile->pfname);
27 		return;
28 	}
29 	if (retval == 0) {
30 		ERROR("%s: Bad data found on integer read\n", curfile->pfname);
31 		return;
32 	}
33 	if (errno == ERANGE) {
34 		ERROR("%s: Overflow on integer read\n", curfile->pfname);
35 		return;
36 	}
37 	if (errno != 0) {
38 		PERROR("Error encountered on integer read ", curfile->pfname);
39 		return;
40 	}
41 	curfile->funit &= ~EOLN;
42 	curfile->funit |= SYNC;
43 	return data;
44 }
45