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 = -DFNORD='"eris/$(VERSION)"' -Wall -Werror
CFLAGS = -Wall -Werror
all: eris
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
sh ./test.sh
clean:
rm -f *.[oa] eris
rm -f *.[oa] version.h eris

26
eris.c
View File

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