summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@elego.de>2011-05-29 01:24:09 +0200
committerCarlos Martín Nieto <cmn@elego.de>2011-05-31 17:33:23 +0200
commitf2abee47d8908cd74f1ca2e46f30c8b9f6a07754 (patch)
tree75c103a77e6346ddf4b3dbc3393ae959b7c3a5fd /src
parenta5f43b95364e76436df25349f5f7b07e532e8e23 (diff)
downloadlibgit2-f2abee47d8908cd74f1ca2e46f30c8b9f6a07754.tar.gz
cfg_readline: really ignore empty lines
Simplify cfg_readline and at the same time fix it so that it does really ignore empty lines. This fixes point 2-1 of Issue #210 Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Diffstat (limited to 'src')
-rw-r--r--src/config_file.c39
1 files changed, 8 insertions, 31 deletions
diff --git a/src/config_file.c b/src/config_file.c
index 216c07417..e468a0b88 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -483,15 +483,6 @@ static int cfg_peek(diskfile_backend *cfg, int flags)
return ret;
}
-static const char *LINEBREAK_UNIX = "\\\n";
-static const char *LINEBREAK_WIN32 = "\\\r\n";
-
-static int is_linebreak(const char *pos)
-{
- return memcmp(pos - 1, LINEBREAK_UNIX, sizeof(LINEBREAK_UNIX)) == 0 ||
- memcmp(pos - 2, LINEBREAK_WIN32, sizeof(LINEBREAK_WIN32)) == 0;
-}
-
/*
* Read and consume a line, returning it in newly-allocated memory.
*/
@@ -502,38 +493,24 @@ static char *cfg_readline(diskfile_backend *cfg)
int line_len;
line_src = cfg->reader.read_ptr;
+
+ /* Skip empty empty lines */
+ while (isspace(*line_src))
+ ++line_src;
+
line_end = strchr(line_src, '\n');
/* no newline at EOF */
if (line_end == NULL)
line_end = strchr(line_src, 0);
- else
- while (is_linebreak(line_end))
- line_end = strchr(line_end + 1, '\n');
+ line_len = line_end - line_src;
- while (line_src < line_end && isspace(*line_src))
- line_src++;
-
- line = (char *)git__malloc((size_t)(line_end - line_src) + 1);
+ line = git__malloc(line_len + 1);
if (line == NULL)
return NULL;
- line_len = 0;
- while (line_src < line_end) {
-
- if (memcmp(line_src, LINEBREAK_UNIX, sizeof(LINEBREAK_UNIX)) == 0) {
- line_src += sizeof(LINEBREAK_UNIX);
- continue;
- }
-
- if (memcmp(line_src, LINEBREAK_WIN32, sizeof(LINEBREAK_WIN32)) == 0) {
- line_src += sizeof(LINEBREAK_WIN32);
- continue;
- }
-
- line[line_len++] = *line_src++;
- }
+ memcpy(line, line_src, line_len);
line[line_len] = '\0';