home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / sharew / packer / zlib / zfgets.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-17  |  736 b   |  46 lines

  1. #include "zdef.h"
  2.  
  3. /*------------------------------*/
  4. /*    zfgets            */
  5. /*------------------------------*/
  6. #ifndef __STDC__
  7. char *zfgets (line, len, zfp)
  8. char   *line;
  9. int     len;
  10. ZFILE  *zfp;
  11. #else
  12. char *zfgets (char *line, int len, ZFILE *zfp)
  13. #endif
  14. {
  15.  
  16. /*
  17.  *    I *hope* this is what fgets does - I only added it
  18.  *    here when I came across a program that needed it; I'm
  19.  *    including the '\n' in the string.
  20.  */
  21.  
  22.     int     c,
  23.             pos = 0;
  24.  
  25.     for (;;)
  26.     {
  27.         c = zfgetc (zfp);
  28.         if (c == EOF)
  29.             return ((char *) NULL);
  30.  
  31.         c &= 255;
  32.         line[pos] = (char) c;
  33.         if (pos + 1 == len)    /* Too long! */
  34.             break;
  35.         pos++;
  36.         if (c == '\n')
  37.             break;
  38.     }
  39.     line[pos] = '\0';
  40.  
  41.     return ((char *) line);
  42. }
  43.  
  44.  
  45.  
  46.