/***************************************************************************1* _ _ ____ _2* Project ___| | | | _ \| |3* / __| | | | |_) | |4* | (__| |_| | _ <| |___5* \___|\___/|_| \_\_____|6*7* Copyright (C) Daniel Stenberg, <[email protected]>, et al.8*9* This software is licensed as described in the file COPYING, which10* you should have received as part of this distribution. The terms11* are also available at https://curl.se/docs/copyright.html.12*13* You may opt to use, copy, modify, merge, publish, distribute and/or sell14* copies of the Software, and permit persons to whom the Software is15* furnished to do so, under the terms of the COPYING file.16*17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY18* KIND, either express or implied.19*20* SPDX-License-Identifier: curl21*22***************************************************************************/23#include "curl_setup.h"2425#if !defined(CURL_DISABLE_COOKIES) || !defined(CURL_DISABLE_ALTSVC) || \26!defined(CURL_DISABLE_HSTS) || !defined(CURL_DISABLE_NETRC)2728#include "curl_get_line.h"2930#define appendnl(b) curlx_dyn_addn(buf, "\n", 1)3132/*33* Curl_get_line() returns only complete whole lines that end with newline.34* When 'eof' is set TRUE, the last line has been read.35*/36CURLcode Curl_get_line(struct dynbuf *buf, FILE *input, bool *eof)37{38CURLcode result;39char buffer[128];40curlx_dyn_reset(buf);41while(1) {42size_t rlen;43char *b = fgets(buffer, sizeof(buffer), input);4445*eof = feof(input);4647rlen = b ? strlen(b) : 0;48if(rlen) {49result = curlx_dyn_addn(buf, b, rlen);50if(result)51/* too long line or out of memory */52return result;53}54/* now check the full line */55rlen = curlx_dyn_len(buf);56b = curlx_dyn_ptr(buf);57if(rlen && (b[rlen - 1] == '\n'))58/* LF at end of the line */59return CURLE_OK; /* all good */60if(*eof)61/* append a newline */62return appendnl(buf);63/* otherwise get next line to append */64}65/* UNREACHABLE */66}6768#endif /* if not disabled */697071