Reordering function-prototypes and functions and size_t-correctness

This commit is contained in:
FRIGN 2014-08-11 13:29:29 +02:00
parent b00fc1454f
commit d5af6424f1

57
quark.c
View file

@ -62,24 +62,24 @@ static const char *resentry[] = {
[MODIFIED] = "Last-Modified: %s\r\n" [MODIFIED] = "Last-Modified: %s\r\n"
}; };
static ssize_t writetext(const char *buf); static char *tstamp(void);
static ssize_t writedata(const char *buf, size_t buflen); static int writedata(const char *buf, size_t buflen);
static int writetext(const char *buf);
static void atomiclog(int fd, const char *errstr, va_list ap); static void atomiclog(int fd, const char *errstr, va_list ap);
static void logmsg(const char *errstr, ...); static void logmsg(const char *errstr, ...);
static void logerrmsg(const char *errstr, ...); static void logerrmsg(const char *errstr, ...);
static void die(const char *errstr, ...); static void die(const char *errstr, ...);
static int putresentry(int type, ...); static int putresentry(int type, ...);
static void response(void);
static void responsecgi(void);
static void responsedir(void);
static void responsedirdata(DIR *d);
static void responsefile(void);
static void responsefiledata(int fd, off_t size); static void responsefiledata(int fd, off_t size);
static void responsefile(void);
static void responsedirdata(DIR *d);
static void responsedir(void);
static void responsecgi(void);
static void response(void);
static int getreqentry(char *name, char *target, size_t targetlen, char *breakchars); static int getreqentry(char *name, char *target, size_t targetlen, char *breakchars);
static int request(void); static int request(void);
static void serve(int fd); static void serve(int fd);
static void sighandler(int sig); static void sighandler(int sig);
static char *tstamp(void);
#include "config.h" #include "config.h"
@ -94,7 +94,16 @@ static char reqmod[256];
static int fd; static int fd;
static Request req; static Request req;
ssize_t char *
tstamp(void) {
static char res[30];
time_t t = time(NULL);
strftime(res, sizeof res, "%a, %d %b %Y %H:%M:%S GMT", gmtime(&t));
return res;
}
int
writedata(const char *buf, size_t buf_len) { writedata(const char *buf, size_t buf_len) {
ssize_t r, offset; ssize_t r, offset;
@ -107,7 +116,7 @@ writedata(const char *buf, size_t buf_len) {
return 0; return 0;
} }
ssize_t int
writetext(const char *buf) { writetext(const char *buf) {
return writedata(buf, strlen(buf)); return writedata(buf, strlen(buf));
} }
@ -115,7 +124,7 @@ writetext(const char *buf) {
void void
atomiclog(int fd, const char *errstr, va_list ap) { atomiclog(int fd, const char *errstr, va_list ap) {
static char buf[512]; static char buf[512];
int n; size_t n;
/* assemble the message in buf and write it in one pass /* assemble the message in buf and write it in one pass
to avoid interleaved concurrent writes on a shared fd. */ to avoid interleaved concurrent writes on a shared fd. */
@ -182,9 +191,8 @@ responsefiledata(int fd, off_t size) {
void void
responsefile(void) { responsefile(void) {
const char *mimetype = "application/octet-stream"; const char *mimetype = "application/octet-stream";
char *p; char mod[30], *p;
char mod[30]; int r, ffd;
int i, ffd, r;
struct stat st; struct stat st;
time_t t; time_t t;
@ -207,9 +215,9 @@ responsefile(void) {
/* determine mime-type */ /* determine mime-type */
if ((p = strrchr(reqbuf, '.'))) { if ((p = strrchr(reqbuf, '.'))) {
p++; p++;
for (i = 0; i < LENGTH(servermimes); i++) for (r = 0; r < LENGTH(servermimes); r++)
if (!strcmp(servermimes[i].extension, p)) { if (!strcmp(servermimes[r].extension, p)) {
mimetype = servermimes[i].mimetype; mimetype = servermimes[r].mimetype;
break; break;
} }
} }
@ -256,7 +264,7 @@ responsedirdata(DIR *d) {
void void
responsedir(void) { responsedir(void) {
ssize_t len = strlen(reqbuf); size_t len = strlen(reqbuf);
DIR *d; DIR *d;
if ((reqbuf[len - 1] != '/') && (len + 1 < MAXBUFLEN)) { if ((reqbuf[len - 1] != '/') && (len + 1 < MAXBUFLEN)) {
@ -291,7 +299,7 @@ responsedir(void) {
void void
responsecgi(void) { responsecgi(void) {
FILE *cgi; FILE *cgi;
int r; size_t r;
if (req.type == GET) if (req.type == GET)
setenv("REQUEST_METHOD", "GET", 1); setenv("REQUEST_METHOD", "GET", 1);
@ -376,7 +384,7 @@ getreqentry(char *name, char *target, size_t targetlen, char *breakchars) {
int int
request(void) { request(void) {
char *p, *res; char *p, *res;
int r; ssize_t r;
size_t offset = 0; size_t offset = 0;
/* read request into reqbuf (MAXBUFLEN byte of reqbuf is emergency 0 terminator */ /* read request into reqbuf (MAXBUFLEN byte of reqbuf is emergency 0 terminator */
@ -472,15 +480,6 @@ sighandler(int sig) {
} }
} }
char *
tstamp(void) {
static char res[30];
time_t t = time(NULL);
strftime(res, sizeof res, "%a, %d %b %Y %H:%M:%S GMT", gmtime(&t));
return res;
}
int int
main(int argc, char *argv[]) { main(int argc, char *argv[]) {
struct addrinfo hints, *ai; struct addrinfo hints, *ai;