chiark / gitweb /
xfoo => mfoo, rename
[inn-innduct.git] / lib / sendarticle.c
1 /*  $Id: sendarticle.c 4076 2000-10-05 00:36:52Z rra $
2 **
3 */
4
5 #include "config.h"
6 #include "clibrary.h"
7 #include "libinn.h"
8 #include "nntp.h"
9
10
11 /*
12 **  Send a string of one or more lines down a stdio FILE using RFC977
13 **  conventions.  Return -1 on error.
14 */
15 int NNTPsendarticle(char *p, FILE *F, bool Terminate)
16 {
17     char *next;
18
19     for (; p && *p; next[-1] = '\n', p = next) {
20         /* Get pointer to next line.  Truncate long lines. */
21         if ((next = strchr(p, '\n')) != NULL)
22             *next++ = '\0';
23
24         /* Write line. */
25         if (*p == '.' && putc('.', F) == EOF)
26             return -1;
27         if (fprintf(F, "%s\r\n", p) == EOF)
28             return -1;
29
30         /* Done? */
31         if (next == NULL)
32             break;
33     }
34
35     if (Terminate && fprintf(F, ".\r\n") == EOF)
36         return -1;
37
38     return fflush(F) == EOF || ferror(F) ? -1 : 0;
39 }