use dprintf and reorder so a fflush is not needed, saves some lines - gopherproxy-c - Gopher HTTP proxy in C (CGI)
(HTM) git clone git://git.codemadness.org/gopherproxy-c
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit a3dbec3aff240cf18792ac54e40d7ea04dae4d07
(DIR) parent 09feebbc6b6947493acdadf0afca1a61da517c40
(HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date: Sun, 12 Aug 2018 19:27:16 +0200
use dprintf and reorder so a fflush is not needed, saves some lines
+ minor cleanup
Diffstat:
M README | 2 +-
M gopherproxy.c | 13 +++++--------
2 files changed, 6 insertions(+), 9 deletions(-)
---
(DIR) diff --git a/README b/README
@@ -3,7 +3,7 @@ gopherproxy
Build dependencies:
- C compiler.
-- libc
+- libc + some BSD extensions (dprintf).
- POSIX system.
- make (optional).
(DIR) diff --git a/gopherproxy.c b/gopherproxy.c
@@ -502,19 +502,16 @@ main(void)
headerset = 1;
switch (_type) {
case '0':
- printf("Content-Type: text/plain; charset=utf-8\r\n\r\n");
- fflush(stdout);
+ dprintf(1, "Content-Type: text/plain; charset=utf-8\r\n\r\n");
servefile(u.host, u.port, path);
return 0;
case '1':
case '7':
break; /* handled below */
case '9':
- printf("Content-Type: application/octet-stream\r\n");
if ((p = strrchr(path, '/')))
- printf("Content-Disposition: attachment; filename=\"%s\"\r\n", p + 1);
- printf("\r\n");
- fflush(stdout);
+ dprintf(1, "Content-Disposition: attachment; filename=\"%s\"\r\n", p + 1);
+ dprintf(1, "Content-Type: application/octet-stream\r\n\r\n");
servefile(u.host, u.port, path);
return 0;
default:
@@ -524,10 +521,10 @@ main(void)
}
}
- fputs("Content-Type: text/html; charset=utf-8\r\n\r\n", stdout);
headerset = 1;
-
fputs(
+ "Content-Type: text/html; charset=utf-8\r\n"
+ "\r\n"
"<!DOCTYPE html>\n"
"<html dir=\"ltr\">\n"
"<head>\n"