home *** CD-ROM | disk | FTP | other *** search
/ ftp.uv.es / 2014.11.ftp.uv.es.tar / ftp.uv.es / pub / unix / elm-2.4-pl20.tar.Z / elm-2.4-pl20.tar / lib / mail_gets.c < prev    next >
C/C++ Source or Header  |  1992-10-03  |  1KB  |  57 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: mail_gets.c,v 5.1 1992/10/03 22:41:36 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 5.1 $   $State: Exp $
  6.  *
  7.  *             Copyright (c) 1992 USENET Community Trust
  8.  *******************************************************************************
  9.  * Bug reports, patches, comments, suggestions should be sent to:
  10.  *
  11.  *    Syd Weinstein, Elm Coordinator
  12.  *    elm@DSI.COM            dsinc!elm
  13.  *
  14.  *******************************************************************************
  15.  * $Log: mail_gets.c,v $
  16.  * Revision 5.1  1992/10/03  22:41:36  syd
  17.  * Initial checkin as of 2.4 Release at PL0
  18.  *
  19.  *
  20.  ******************************************************************************/
  21.  
  22. /** get a line from the mail file, but be tolerant of nulls
  23.  
  24.   The length of the line is returned
  25.  
  26. **/
  27.  
  28. #include <stdio.h>
  29. #include <ctype.h>
  30.  
  31.  
  32. int
  33. mail_gets(buffer, size, mailfile)
  34. char *buffer;
  35. int size;
  36. FILE *mailfile;
  37. {
  38.     register int line_bytes = 0, ch;
  39.     register char *c = buffer;
  40.  
  41.     size--; /* allow room for zero terminator on end, just in case */
  42.     while (!feof(mailfile) && !ferror(mailfile) && line_bytes < size) {
  43.       ch = getc(mailfile); /* Macro, faster than  fgetc() ! */
  44.  
  45.       if (ch == EOF)
  46.         break;
  47.  
  48.       *c++ = ch;
  49.       ++line_bytes;
  50.  
  51.       if (ch == '\n')
  52.         break;
  53.     }
  54.     *c = 0;    /* Actually this should NOT be needed.. */
  55.     return line_bytes;
  56. }
  57.