2019-03-31 03:11:57 +08:00
|
|
|
/***************************************************************************
|
|
|
|
* _ _ ____ _
|
|
|
|
* Project ___| | | | _ \| |
|
|
|
|
* / __| | | | |_) | |
|
|
|
|
* | (__| |_| | _ <| |___
|
|
|
|
* \___|\___/|_| \_\_____|
|
|
|
|
*
|
2023-01-02 20:51:48 +08:00
|
|
|
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
2019-03-31 03:11:57 +08:00
|
|
|
*
|
|
|
|
* This software is licensed as described in the file COPYING, which
|
|
|
|
* you should have received as part of this distribution. The terms
|
2020-11-04 21:02:01 +08:00
|
|
|
* are also available at https://curl.se/docs/copyright.html.
|
2019-03-31 03:11:57 +08:00
|
|
|
*
|
|
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: curl
|
2022-05-17 17:16:50 +08:00
|
|
|
*
|
2019-03-31 03:11:57 +08:00
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "curl_setup.h"
|
|
|
|
|
2020-11-03 06:17:01 +08:00
|
|
|
#if !defined(CURL_DISABLE_COOKIES) || !defined(CURL_DISABLE_ALTSVC) || \
|
2022-10-04 20:37:24 +08:00
|
|
|
!defined(CURL_DISABLE_HSTS) || !defined(CURL_DISABLE_NETRC)
|
2020-08-14 21:43:41 +08:00
|
|
|
|
2019-03-31 03:11:57 +08:00
|
|
|
#include "curl_get_line.h"
|
|
|
|
#include "curl_memory.h"
|
|
|
|
/* The last #include file should be: */
|
|
|
|
#include "memdebug.h"
|
|
|
|
|
|
|
|
/*
|
2024-02-06 17:15:52 +08:00
|
|
|
* Curl_get_line() makes sure to only return complete whole lines that end
|
|
|
|
* newlines.
|
2019-03-31 03:11:57 +08:00
|
|
|
*/
|
2024-02-06 17:15:52 +08:00
|
|
|
int Curl_get_line(struct dynbuf *buf, FILE *input)
|
2019-03-31 03:11:57 +08:00
|
|
|
{
|
2024-02-06 17:15:52 +08:00
|
|
|
CURLcode result;
|
|
|
|
char buffer[128];
|
|
|
|
Curl_dyn_reset(buf);
|
2019-03-31 03:11:57 +08:00
|
|
|
while(1) {
|
2024-02-06 17:15:52 +08:00
|
|
|
char *b = fgets(buffer, sizeof(buffer), input);
|
2022-11-23 21:56:39 +08:00
|
|
|
|
2019-03-31 03:11:57 +08:00
|
|
|
if(b) {
|
|
|
|
size_t rlen = strlen(b);
|
2022-11-23 21:56:39 +08:00
|
|
|
|
|
|
|
if(!rlen)
|
|
|
|
break;
|
|
|
|
|
2024-02-06 17:15:52 +08:00
|
|
|
result = Curl_dyn_addn(buf, b, rlen);
|
|
|
|
if(result)
|
|
|
|
/* too long line or out of memory */
|
|
|
|
return 0; /* error */
|
2022-11-23 21:56:39 +08:00
|
|
|
|
2024-02-06 17:15:52 +08:00
|
|
|
else if(b[rlen-1] == '\n')
|
|
|
|
/* end of the line */
|
|
|
|
return 1; /* all good */
|
|
|
|
|
|
|
|
else if(feof(input)) {
|
|
|
|
/* append a newline */
|
|
|
|
result = Curl_dyn_addn(buf, "\n", 1);
|
|
|
|
if(result)
|
|
|
|
/* too long line or out of memory */
|
|
|
|
return 0; /* error */
|
|
|
|
return 1; /* all good */
|
2022-11-23 21:56:39 +08:00
|
|
|
}
|
2019-03-31 03:11:57 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2024-02-06 17:15:52 +08:00
|
|
|
return 0;
|
2019-03-31 03:11:57 +08:00
|
|
|
}
|
2020-08-14 21:43:41 +08:00
|
|
|
|
|
|
|
#endif /* if not disabled */
|