xref: /original-bsd/usr.bin/pascal/libpc/READ4.c (revision b8338845)
1 /* Copyright (c) 1979 Regents of the University of California */
2 
3 static char sccsid[] = "@(#)READ4.c 1.9 01/09/89";
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 	}
21 	UNSYNC(curfile);
22 	errno = 0;
23 	retval = fscanf(curfile->fbuf, "%ld", &data);
24 	if (retval == EOF) {
25 		ERROR("%s: Tried to read past end of file\n", curfile->pfname);
26 	}
27 	if (retval == 0) {
28 		ERROR("%s: Bad data found on integer read\n", curfile->pfname);
29 	}
30 	if (errno == ERANGE) {
31 		ERROR("%s: Overflow on integer read\n", curfile->pfname);
32 	}
33 	if (errno != 0) {
34 		PERROR("Error encountered on integer read ", curfile->pfname);
35 	}
36 	return data;
37 }
38