X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/803f254122dc757db104a4c36cf98b726be004be..3c54bbb247ffc8fa094d754099c0b009e79d484d:/test/fakehttp.c diff --git a/test/fakehttp.c b/test/fakehttp.c index f773a73d..328af80d 100644 --- a/test/fakehttp.c +++ b/test/fakehttp.c @@ -1,5 +1,4 @@ -/* - * fakehttp - A fake HTTP server used by the nmh test suite +/* fakehttp - A fake HTTP server used by the nmh test suite * * This code is Copyright (c) 2014, by the authors of nmh. See the * COPYRIGHT file in the root directory of the nmh distribution for @@ -15,12 +14,24 @@ #include #include -#define LINESIZE 1024 #define PIDFN "/tmp/fakehttp.pid" int serve(const char *, const char *); void putcrlf(int, char *); +static void +strip_cr(char *buf, ssize_t *len) +{ + ssize_t src, dst; + for (src = dst = 0; src < *len; src++) { + buf[dst] = buf[src]; + if (buf[src] != '\r') { + dst++; + } + } + *len -= src - dst; +} + static void save_req(int conn, FILE *req) { @@ -55,7 +66,7 @@ save_req(int conn, FILE *req) } if (r < 0) { e = errno; - fputs("\n", req); /* req body usually has no newline */ + putc('\n', req); /* req body usually has no newline */ fclose(req); if (e != EAGAIN && e != EWOULDBLOCK) { fprintf(stderr, "Unable to read socket: %s\n", strerror(e)); @@ -66,7 +77,7 @@ save_req(int conn, FILE *req) * all done. */ return; } - /* make tests simpler by eliding carriage-returns? */ + strip_cr(buf, &r); fwrite(buf, 1, r, req); } }