call :element %1 lib "curl_ctype.c" %3
call :element %1 lib "curl_multibyte.c" %3
call :element %1 lib "version_win32.c" %3
+ call :element %1 lib "dynbuf.c" %3
) else if "!var!" == "CURL_SRC_X_H_FILES" (
call :element %1 lib "config-win32.h" %3
call :element %1 lib "curl_setup.h" %3
call :element %1 lib "curl_ctype.h" %3
call :element %1 lib "curl_multibyte.h" %3
call :element %1 lib "version_win32.h" %3
+ call :element %1 lib "dynbuf.h" %3
) else if "!var!" == "CURL_LIB_C_FILES" (
for /f "delims=" %%c in ('dir /b ..\lib\*.c') do call :element %1 lib "%%c" %3
) else if "!var!" == "CURL_LIB_H_FILES" (
#include "tool_homedir.h"
#include "tool_msgs.h"
#include "tool_parsecfg.h"
+#include "dynbuf.h"
#include "memdebug.h" /* keep this as LAST include */
#define ISSEP(x,dash) (!dash && (((x) == '=') || ((x) == ':')))
static const char *unslashquote(const char *line, char *param);
-static char *my_get_line(FILE *fp);
+
+#define MAX_CONFIG_LINE_LENGTH (100*1024)
+static bool my_get_line(FILE *fp, struct curlx_dynbuf *, bool *error);
#ifdef WIN32
static FILE *execpath(const char *filename)
if(file) {
char *line;
- char *aline;
char *option;
char *param;
int lineno = 0;
bool dashed_option;
+ struct curlx_dynbuf buf;
+ bool fileerror;
+ curlx_dyn_init(&buf, MAX_CONFIG_LINE_LENGTH);
- while(NULL != (aline = my_get_line(file))) {
+ while(my_get_line(file, &buf, &fileerror)) {
int res;
bool alloced_param = FALSE;
lineno++;
- line = aline;
+ line = curlx_dyn_ptr(&buf);
+ if(!line) {
+ rc = 1; /* out of memory */
+ break;
+ }
/* line with # in the first non-blank column is a comment! */
while(*line && ISSPACE(*line))
case '\n':
case '*':
case '\0':
- Curl_safefree(aline);
+ curlx_dyn_reset(&buf);
continue;
}
param = malloc(strlen(line) + 1); /* parameter */
if(!param) {
/* out of memory */
- Curl_safefree(aline);
rc = 1;
break;
}
if(alloced_param)
Curl_safefree(param);
- Curl_safefree(aline);
+ curlx_dyn_reset(&buf);
}
+ curlx_dyn_free(&buf);
if(file != stdin)
fclose(file);
+ if(fileerror)
+ rc = 1;
}
else
rc = 1; /* couldn't open the file */
/*
* Reads a line from the given file, ensuring is NUL terminated.
- * The pointer must be freed by the caller.
- * NULL is returned on an out of memory condition.
*/
-static char *my_get_line(FILE *fp)
+static bool my_get_line(FILE *fp, struct curlx_dynbuf *db,
+ bool *error)
{
char buf[4096];
- char *nl = NULL;
- char *line = NULL;
-
+ *error = FALSE;
do {
- if(NULL == fgets(buf, sizeof(buf), fp))
- break;
- if(!line) {
- line = strdup(buf);
- if(!line)
- return NULL;
+ /* fgets() returns s on success, and NULL on error or when end of file
+ occurs while no characters have been read. */
+ if(!fgets(buf, sizeof(buf), fp))
+ /* only if there's data in the line, return TRUE */
+ return curlx_dyn_len(db) ? TRUE : FALSE;
+ if(curlx_dyn_add(db, buf)) {
+ *error = TRUE; /* error */
+ return FALSE; /* stop reading */
}
- else {
- char *ptr;
- size_t linelen = strlen(line);
- ptr = realloc(line, linelen + strlen(buf) + 1);
- if(!ptr) {
- Curl_safefree(line);
- return NULL;
- }
- line = ptr;
- strcpy(&line[linelen], buf);
- }
- nl = strchr(line, '\n');
- } while(!nl);
+ } while(!strchr(buf, '\n'));
- if(nl)
- *nl = '\0';
-
- return line;
+ return TRUE; /* continue */
}
$(CURL_DIROBJ)\warnless.obj \\r
$(CURL_DIROBJ)\curl_ctype.obj \\r
$(CURL_DIROBJ)\curl_multibyte.obj \\r
- $(CURL_DIROBJ)\version_win32.obj\r
+ $(CURL_DIROBJ)\version_win32.obj \\r
+ $(CURL_DIROBJ)\dynbuf.obj\r
\r
$(PROGRAM_NAME): $(CURL_DIROBJ) $(CURL_FROM_LIBCURL) $(EXE_OBJS)\r
$(CURL_LINK) $(CURL_LFLAGS) $(CURL_LIBCURL_LIBNAME) $(WIN_LIBS) $(CURL_FROM_LIBCURL) $(EXE_OBJS)\r
$(CURL_CC) $(CURL_CFLAGS) /Fo"$@" ../lib/curl_multibyte.c\r
$(CURL_DIROBJ)\version_win32.obj: ../lib/version_win32.c\r
$(CURL_CC) $(CURL_CFLAGS) /Fo"$@" ../lib/version_win32.c\r
+$(CURL_DIROBJ)\dynbuf.obj: ../lib/dynbuf.c\r
+ $(CURL_CC) $(CURL_CFLAGS) /Fo"$@" ../lib/dynbuf.c\r
$(CURL_DIROBJ)\curl.res: $(CURL_SRC_DIR)\curl.rc\r
rc $(CURL_RC_FLAGS)\r
\r