home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 387b.lha / dice_v2.02 / lib / stdio / fgetc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-30  |  730 b   |  47 lines

  1.  
  2. /*
  3.  *  FGETC.C
  4.  *
  5.  *  (c)Copyright 1990, Matthew Dillon, All Rights Reserved
  6.  *
  7.  *  no error checking for speed...
  8.  */
  9.  
  10. #include <stdio.h>
  11.  
  12. int
  13. fgetc(fi)
  14. FILE *fi;
  15. {
  16.     int error;
  17.     unsigned char c;
  18.  
  19.     if (fi && (fi->sd_Flags & __SIF_READ)) {
  20.     if (fi->sd_UC >= 0) {
  21.         c = fi->sd_UC;
  22.         fi->sd_UC = -1;
  23.         return(c);
  24.     }
  25.     if (fi->sd_RLeft <= 0) {
  26.         if (error = _filbuf(fi))
  27.         return(error);
  28.         if (fi->sd_RLeft == 0) {    /*  unbuffered! */
  29.         error = read(fi->sd_Fd, &c, 1);
  30.         if (error <= 0) {
  31.             if (error == 0)
  32.             fi->sd_Flags |= __SIF_EOF;
  33.             else
  34.             fi->sd_Error = EOF;
  35.             return(EOF);
  36.         }
  37.         ++fi->sd_Offset;
  38.         return(c);
  39.         }
  40.     }
  41.     --fi->sd_RLeft;
  42.     return(*fi->sd_RPtr++);
  43.     }
  44.     return(EOF);
  45. }
  46.  
  47.