"Fossies" - the Fresh Open Source Software Archive

Member "msmtp-1.8.5/src/stream.c" (13 Dec 2018, 1688 Bytes) of package /linux/privat/msmtp-1.8.5.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "stream.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.8.1_vs_1.8.2.

    1 /*
    2  * stream.c
    3  *
    4  * This file is part of msmtp, an SMTP client, and of mpop, a POP3 client.
    5  *
    6  * Copyright (C) 2005, 2007
    7  * Martin Lambers <marlam@marlam.de>
    8  *
    9  *   This program is free software; you can redistribute it and/or modify
   10  *   it under the terms of the GNU General Public License as published by
   11  *   the Free Software Foundation; either version 3 of the License, or
   12  *   (at your option) any later version.
   13  *
   14  *   This program is distributed in the hope that it will be useful,
   15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
   16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17  *   GNU General Public License for more details.
   18  *
   19  *   You should have received a copy of the GNU General Public License
   20  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
   21  */
   22 
   23 
   24 #ifdef HAVE_CONFIG_H
   25 # include "config.h"
   26 #endif
   27 
   28 #include <stdio.h>
   29 
   30 #include "gettext.h"
   31 #define _(string) gettext(string)
   32 
   33 #include "xalloc.h"
   34 #include "stream.h"
   35 
   36 
   37 /*
   38  * stream_gets()
   39  *
   40  * see stream.h
   41  */
   42 
   43 int stream_gets(FILE *f, char *str, size_t size, size_t *len, char **errstr)
   44 {
   45     char c;
   46     size_t i;
   47 
   48     i = 0;
   49     while (i + 1 < size)
   50     {
   51         if (fread(&c, sizeof(char), 1, f) == 1)
   52         {
   53             str[i++] = c;
   54             if (c == '\n')
   55             {
   56                 break;
   57             }
   58         }
   59         else
   60         {
   61             if (ferror(f))
   62             {
   63                 *errstr = xasprintf(_("input error"));
   64                 return STREAM_EIO;
   65             }
   66             else /* EOF */
   67             {
   68                 break;
   69             }
   70         }
   71     }
   72     str[i] = '\0';
   73     *len = i;
   74     return STREAM_EOK;
   75 }