X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=sbr%2Fm_getfld2.c;h=a2b8ae9a4049fa50f7df81311fff78a28a40b54e;hb=d0d56900365f8088ac1fcfea53183ba2f34c705f;hp=de38435c01267e1a328721834f5d98d3c2a81321;hpb=bebbba12196b01deca4e33631937fdfdf605b75c;p=mmh diff --git a/sbr/m_getfld2.c b/sbr/m_getfld2.c index de38435..a2b8ae9 100644 --- a/sbr/m_getfld2.c +++ b/sbr/m_getfld2.c @@ -10,6 +10,7 @@ #include #include #include +#include enum threestate { @@ -23,7 +24,7 @@ enum threestate { */ static enum threestate is_falted(FILE *); static size_t copyname(char *, char *); -static int is_separator(char *); +static bool is_separator(char *); /* @@ -48,29 +49,29 @@ m_getfld2(enum state s, struct field *f, FILE *msg) ssize_t nchars; enum threestate falted; - nchars = getline(&tmpline, &len, msg); - if (nchars < 1) { - if (feof(msg)) { - return FILEEOF2; - } else { - return IOERR2; + switch (s) { + case FLD2: + nchars = getline(&tmpline, &len, msg); + if (nchars < 1) { + if (feof(msg)) { + return FILEEOF2; + } else { + return IOERR2; + } } - } - *f->name = '\0'; - f->namelen = 0; + *f->name = '\0'; + f->namelen = 0; - if (nchars >= NAMESZ) { - if (f->value) { - free(f->value); + if (nchars >= NAMESZ) { + if (f->value) { + free(f->value); + } + f->value = tmpline; + f->valuelen = nchars; + return LENERR2; } - f->value = tmpline; - f->valuelen = nchars; - return LENERR2; - } - switch (s) { - case FLD2: if (*(tmpline + nchars - 1) != '\n') { if (f->value) { free(f->value); @@ -151,6 +152,26 @@ m_getfld2(enum state s, struct field *f, FILE *msg) return FLD2; case BODY2: + nchars = getline(&tmpline, &len, msg); + if (nchars < 1) { + if (feof(msg)) { + return FILEEOF2; + } else { + return IOERR2; + } + } + + *f->name = '\0'; + f->namelen = 0; + + if (nchars >= NAMESZ) { + if (f->value) { + free(f->value); + } + f->value = tmpline; + f->valuelen = nchars; + return LENERR2; + } if (f->value) { free(f->value); } @@ -217,7 +238,7 @@ copyname(char *dst, char *src) return strlen(dst); } -static int +static bool is_separator(char *line) { /* @@ -227,8 +248,8 @@ is_separator(char *line) while (*line == '-') { line++; } - if (strcmp("\n", line)==0) { - return 1; + if (strcmp("\n", line) == 0 || strcmp("\r\n", line) == 0 ) { + return true; } - return 0; + return false; }