1 
2 static char rcsid[] = "@(#)$Id: mail_gets.c,v 1.2 1995/09/29 17:41:15 wfp5p Exp $";
3 
4 /*******************************************************************************
5  *  The Elm Mail System  -  $Revision: 1.2 $   $State: Exp $
6  *
7  *                      Copyright (c) 1988-1995 USENET Community Trust
8  *******************************************************************************
9  * Bug reports, patches, comments, suggestions should be sent to:
10  *
11  *      Bill Pemberton, Elm Coordinator
12  *      flash@virginia.edu
13  *
14  *******************************************************************************
15  * $Log: mail_gets.c,v $
16  * Revision 1.2  1995/09/29  17:41:15  wfp5p
17  * Alpha 8 (Chip's big changes)
18  *
19  * Revision 1.1.1.1  1995/04/19  20:38:32  wfp5p
20  * Initial import of elm 2.4 PL0 as base for elm 2.5.
21  *
22  ******************************************************************************/
23 
24 /** get a line from the mail file, but be tolerant of nulls
25 
26   The length of the line is returned
27 
28 **/
29 
30 #include "elm_defs.h"
31 
32 int
mail_gets(buffer,size,mailfile)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 
43 	while (!feof(mailfile) && !ferror(mailfile) && line_bytes < size) {
44 	  ch = getc(mailfile); /* Macro, faster than  fgetc() ! */
45 
46 	  if (ch == EOF)
47 	  {
48 	    if (line_bytes > 0 && *c != '\n')
49 	    {
50 	        ++line_bytes;
51 	    	*c++ = '\n';
52 	    }
53 	    break;
54 	  }
55 
56 	  *c++ = ch;
57 	  ++line_bytes;
58 
59 	  if (ch == '\n')
60 	    break;
61 	}
62 	*c = 0;	/* Actually this should NOT be needed.. */
63 	return line_bytes;
64 }
65