home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / gnu / gawk213s.lzh / GAWK213S / TEXTRD.C < prev    next >
C/C++ Source or Header  |  1993-07-29  |  652b  |  31 lines

  1. /*
  2.  * From gnulib Atari ST sources - with a fix for a bug causing
  3.  * a premature EOF when only characters read are CR's.
  4.  * Written by Eric R. Smith and placed in the public domain.
  5.  * Fix - Michal Jaegermann, June 1991.
  6.  */
  7. #include <stdio.h>
  8. #include <unistd.h>
  9. int
  10. _text_read(fd, buf, nbytes)
  11.     int fd;
  12.     char *buf;
  13.     int nbytes;
  14. {
  15.     char *to, *from;
  16.     int  r;
  17.     do {
  18.         r = read(fd, buf, nbytes);
  19.         if (r <= 0)        /* if EOF or read error - return */
  20.             return r;
  21.         to = from = buf;
  22.         do {
  23.             if (*from == '\r')
  24.                 from++;
  25.             else
  26.                 *to++ = *from++;
  27.         } while (--r);
  28.     } while (buf == to);    /* only '\r's? - try to read next nbytes */
  29.     return (to - buf);
  30. }
  31.