]> diplodocus.org Git - nmh/blobdiff - test/fakehttp.c
pidstatus.c: Move interface to own file.
[nmh] / test / fakehttp.c
index f773a73..328af80 100644 (file)
@@ -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
 #include <string.h>
 #include <unistd.h>
 
-#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);
     }
 }