- /* eat tabs and spaces from the beginning of the continuation line */
- while ((ch = fgetc (f)) == ' ' || ch == '\t');
- ungetc (ch, f);
- *++buf = ' '; /* string is still terminated because we removed
- at least one whitespace char above */
- }
+ /* end of file or end of headers */
+ if (!fgets(p + pos, *n - pos, f) || (ISSPACE(*p) && pos == 0)) {
+ *p = '\0';
+ return 0;
+ }
+
+ pos += m_strlen(p + pos);
+ if (p[pos - 1] == '\n') {
+ int c;
+
+ /* remove trailing spaces. safe: p[0] is not a space */
+ do {
+ p[--pos] = '\0';
+ } while (ISSPACE(p[pos]));
+
+ /* check to see if the next line is a continuation line */
+ c = fgetc(f);
+ if (c != ' ' && c != '\t') {
+ /* next line is a separate header field or EOH */
+ ungetc(c, f);
+ return pos;
+ }
+
+ /* eat tabs and spaces from the beginning of the continuation line */
+ do {
+ c = fgetc(f);
+ } while (c == ' ' || c == '\t');
+ ungetc(c, f);
+
+ /* string is still terminated because we removed at least one
+ whitespace char above */
+ p[pos++] = ' ';
+ }