curl_get_line: enhance the API

To make sure callers can properly differentiate between errors and know
cleanly when EOF happens. Updated all users and unit test 3200.

Triggered by a remark by ZeroPath

Closes #19140
This commit is contained in:
Daniel Stenberg 2025-10-19 13:09:42 +02:00
parent 990a23bb97
commit 769ccb4d42
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
7 changed files with 112 additions and 110 deletions

View file

@ -81,22 +81,27 @@ static NETRCcode file2memory(const char *filename, struct dynbuf *filebuf)
curlx_dyn_init(&linebuf, MAX_NETRC_LINE);
if(file) {
CURLcode result = CURLE_OK;
bool eof;
ret = NETRC_OK;
while(Curl_get_line(&linebuf, file)) {
CURLcode result;
const char *line = curlx_dyn_ptr(&linebuf);
/* skip comments on load */
curlx_str_passblanks(&line);
if(*line == '#')
continue;
result = curlx_dyn_add(filebuf, line);
if(result) {
ret = curl2netrc(result);
goto done;
do {
const char *line;
result = Curl_get_line(&linebuf, file, &eof);
if(!result) {
line = curlx_dyn_ptr(&linebuf);
/* skip comments on load */
curlx_str_passblanks(&line);
if(*line == '#')
continue;
result = curlx_dyn_add(filebuf, line);
}
}
if(result) {
curlx_dyn_free(filebuf);
ret = curl2netrc(result);
break;
}
} while(!eof);
}
done:
curlx_dyn_free(&linebuf);
if(file)
curlx_fclose(file);