mirror of
https://github.com/curl/curl.git
synced 2026-08-24 20:23:40 +03:00
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:
parent
990a23bb97
commit
769ccb4d42
7 changed files with 112 additions and 110 deletions
31
lib/netrc.c
31
lib/netrc.c
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue