Quit needing CFLAGS

This commit is contained in:
Neale Pickett 2012-10-30 19:10:55 -06:00
parent f0cd1af781
commit b9d6c8ce98
3 changed files with 29 additions and 11 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.o
version.h

View File

@ -1,13 +1,15 @@
VERSION := $(shell head -n 1 CHANGES | tr -d :) CFLAGS = -Wall -Werror
CFLAGS = -DFNORD='"eris/$(VERSION)"' -Wall -Werror
all: eris all: eris
eris: eris.o strings.o mime.o timerfc.o eris: eris.o strings.o mime.o timerfc.o
eris.o: version.h
version.h: CHANGES
awk -F : 'NR==1 {printf("const char *FNORD = \"eris/%s\";\n", $$1);}' $< > $@
test: eris test: eris
sh ./test.sh sh ./test.sh
clean: clean:
rm -f *.[oa] eris rm -f *.[oa] version.h eris

28
eris.c
View File

@ -25,6 +25,7 @@
#include "strings.h" #include "strings.h"
#include "mime.h" #include "mime.h"
#include "timerfc.h" #include "timerfc.h"
#include "version.h"
#ifdef __linux__ #ifdef __linux__
# include <sys/sendfile.h> # include <sys/sendfile.h>
@ -143,7 +144,7 @@ void
header(unsigned int code, const char *httpcomment) header(unsigned int code, const char *httpcomment)
{ {
printf("HTTP/1.%d %u %s\r\n", http_version, code, httpcomment); printf("HTTP/1.%d %u %s\r\n", http_version, code, httpcomment);
printf("Server: " FNORD "\r\n"); printf("Server: %s\r\n", FNORD);
printf("Connection: %s\r\n", keepalive?"keep-alive":"close"); printf("Connection: %s\r\n", keepalive?"keep-alive":"close");
} }
@ -265,7 +266,7 @@ parse_options(int argc, char *argv[])
redirect = 1; redirect = 1;
break; break;
case 'v': case 'v':
printf(FNORD "\n"); printf("%s\n", FNORD);
exit(0); exit(0);
case 'h': case 'h':
default: default:
@ -319,14 +320,15 @@ cgi_child(const char *relpath)
env("CONTENT_TYPE", content_type); env("CONTENT_TYPE", content_type);
} }
/* Change to CGI's directory */ /* Try to change to CGI's directory */
{ {
char *delim = strrchr(relpath, '/'); char *delim = strrchr(relpath, '/');
if (delim) { if (delim) {
*delim = '\0'; *delim = '\0';
chdir(relpath); if (0 == chdir(relpath)) {
relpath = delim + 1; relpath = delim + 1;
}
} }
} }
@ -439,13 +441,23 @@ cgi_parent(int cin, int cout, int passthru)
size_t len; size_t len;
char buf[BUFFER_SIZE]; char buf[BUFFER_SIZE];
size_t nmemb = min(BUFFER_SIZE, content_length); size_t nmemb = min(BUFFER_SIZE, content_length);
char *p = buf;
len = fread(buf, 1, nmemb, stdin); len = fread(buf, 1, nmemb, stdin);
if (len < 1) { if (len < 1) {
break; break;
} }
content_length -= len; content_length -= len;
write(cout, buf, len);
while (len > 0) {
size_t wlen = write(cout, p, len);
if (wlen == -1) {
break;
}
len -= wlen;
p += wlen;
}
} else { } else {
close(cout); close(cout);
} }
@ -989,7 +1001,9 @@ main(int argc, char *argv[], const char *const *envp)
if (! keepalive) { if (! keepalive) {
break; break;
} }
fchdir(cwd); if (-1 == fchdir(cwd)) {
break;
}
} }
return 0; return 0;