Commit 5b84acbc authored by Pavel Khlebovich's avatar Pavel Khlebovich

Consume \n in mg_fgets when reading from membuf.

parent c12838e2
...@@ -2418,10 +2418,13 @@ static char *mg_fgets(char *buf, size_t size, struct file *filep, char **p) { ...@@ -2418,10 +2418,13 @@ static char *mg_fgets(char *buf, size_t size, struct file *filep, char **p) {
if (filep->membuf != NULL && *p != NULL) { if (filep->membuf != NULL && *p != NULL) {
eof = (char *) memchr(*p, '\n', &filep->membuf[filep->size] - *p); eof = (char *) memchr(*p, '\n', &filep->membuf[filep->size] - *p);
len = (size_t) (eof - *p) > size - 1 ? size - 1 : (size_t) (eof - *p); if (eof != NULL) {
memcpy(buf, *p, len); eof += 1; // Include \n
buf[len] = '\0'; len = (size_t) (eof - *p) > size - 1 ? size - 1 : (size_t) (eof - *p);
*p = eof; memcpy(buf, *p, len);
buf[len] = '\0';
*p = eof;
}
return eof; return eof;
} else if (filep->fp != NULL) { } else if (filep->fp != NULL) {
return fgets(buf, size, filep->fp); return fgets(buf, size, filep->fp);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment