[hackers] [quark] Reordering function-prototypes and functions and size_t-correctness || FRIGN
commit d5af6424f1da8ca5a022752a7d16dc2482030215
Author: FRIGN <dev_AT_frign.de>
Date: Mon Aug 11 13:29:29 2014 +0200
Reordering function-prototypes and functions and size_t-correctness
diff --git a/quark.c b/quark.c
index 0c53439..0631248 100644
--- a/quark.c
+++ b/quark.c
_AT_@ -62,24 +62,24 @@ static const char *resentry[] = {
[MODIFIED] = "Last-Modified: %s
"
};
-static ssize_t writetext(const char *buf);
-static ssize_t writedata(const char *buf, size_t buflen);
+static char *tstamp(void);
+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 logmsg(const char *errstr, ...);
static void logerrmsg(const char *errstr, ...);
static void die(const char *errstr, ...);
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 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 request(void);
static void serve(int fd);
static void sighandler(int sig);
-static char *tstamp(void);
#include "config.h"
_AT_@ -94,7 +94,16 @@ static char reqmod[256];
static int fd;
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) {
ssize_t r, offset;
_AT_@ -107,7 +116,7 @@ writedata(const char *buf, size_t buf_len) {
return 0;
}
-ssize_t
+int
writetext(const char *buf) {
return writedata(buf, strlen(buf));
}
_AT_@ -115,7 +124,7 @@ writetext(const char *buf) {
void
atomiclog(int fd, const char *errstr, va_list ap) {
static char buf[512];
- int n;
+ size_t n;
/* assemble the message in buf and write it in one pass
to avoid interleaved concurrent writes on a shared fd. */
_AT_@ -182,9 +191,8 @@ responsefiledata(int fd, off_t size) {
void
responsefile(void) {
const char *mimetype = "application/octet-stream";
- char *p;
- char mod[30];
- int i, ffd, r;
+ char mod[30], *p;
+ int r, ffd;
struct stat st;
time_t t;
_AT_@ -207,9 +215,9 @@ responsefile(void) {
/* determine mime-type */
if ((p = strrchr(reqbuf, '.'))) {
p++;
- for (i = 0; i < LENGTH(servermimes); i++)
- if (!strcmp(servermimes[i].extension, p)) {
- mimetype = servermimes[i].mimetype;
+ for (r = 0; r < LENGTH(servermimes); r++)
+ if (!strcmp(servermimes[r].extension, p)) {
+ mimetype = servermimes[r].mimetype;
break;
}
}
_AT_@ -256,7 +264,7 @@ responsedirdata(DIR *d) {
void
responsedir(void) {
- ssize_t len = strlen(reqbuf);
+ size_t len = strlen(reqbuf);
DIR *d;
if ((reqbuf[len - 1] != '/') && (len + 1 < MAXBUFLEN)) {
_AT_@ -291,7 +299,7 @@ responsedir(void) {
void
responsecgi(void) {
FILE *cgi;
- int r;
+ size_t r;
if (req.type == GET)
setenv("REQUEST_METHOD", "GET", 1);
_AT_@ -376,7 +384,7 @@ getreqentry(char *name, char *target, size_t targetlen, char *breakchars) {
int
request(void) {
char *p, *res;
- int r;
+ ssize_t r;
size_t offset = 0;
/* read request into reqbuf (MAXBUFLEN byte of reqbuf is emergency 0 terminator */
_AT_@ -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
main(int argc, char *argv[]) {
struct addrinfo hints, *ai;
Received on Mon Aug 11 2014 - 13:28:04 CEST
This archive was generated by hypermail 2.3.0
: Mon Aug 11 2014 - 13:36:08 CEST