11679Smckusick /* Copyright (c) 1979 Regents of the University of California */ 21679Smckusick 3*15128Smckusick static char sccsid[] = "@(#)READ4.c 1.7 10/01/83"; 41679Smckusick 51679Smckusick #include "h00vars.h" 66498Smckusick #include <errno.h> 76498Smckusick extern int errno; 81679Smckusick 93019Smckusic long 101679Smckusick READ4(curfile) 111679Smckusick 121679Smckusick register struct iorec *curfile; 131679Smckusick { 143019Smckusic long data; 153019Smckusic int retval; 161679Smckusick 171679Smckusick if (curfile->funit & FWRITE) { 183869Smckusic ERROR("%s: Attempt to read, but open for writing\n", 193869Smckusic curfile->pfname); 201679Smckusick return; 211679Smckusick } 221679Smckusick UNSYNC(curfile); 236498Smckusick errno = 0; 242223Smckusic retval = fscanf(curfile->fbuf, "%ld", &data); 252223Smckusic if (retval == EOF) { 263869Smckusic ERROR("%s: Tried to read past end of file\n", curfile->pfname); 272223Smckusic return; 282223Smckusic } 292223Smckusic if (retval == 0) { 303869Smckusic ERROR("%s: Bad data found on integer read\n", curfile->pfname); 311679Smckusick return; 321679Smckusick } 336498Smckusick if (errno == ERANGE) { 346498Smckusick ERROR("%s: Overflow on integer read\n", curfile->pfname); 356498Smckusick return; 366498Smckusick } 376498Smckusick if (errno != 0) { 38*15128Smckusick PERROR("Error encountered on integer read ", curfile->pfname); 396498Smckusick return; 406498Smckusick } 412309Smckusic curfile->funit &= ~EOLN; 421679Smckusick curfile->funit |= SYNC; 431679Smckusick return data; 441679Smckusick } 45