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