commit 9fa079475e8e3113e34d3e0739abf53d8bc348a3
parent af0bafaaf168f6e332dbd3f509d5122662798262
Author: Christoph Lohmann <20h@r-36.net>
Date: Fri, 22 Jun 2018 17:14:42 +0200
The West-NULL-Fever is spreading in geomyidae. :O
Diffstat:
arg.h | | | 2 | +- |
handlr.c | | | 38 | +++++++++++++++++++------------------- |
ind.c | | | 30 | +++++++++++++++--------------- |
ind.h | | | 1 | - |
main.c | | | 50 | +++++++++++++++++++++++++------------------------- |
5 files changed, 60 insertions(+), 61 deletions(-)
diff --git a/arg.h b/arg.h
@@ -30,7 +30,7 @@ extern char *argv0;
USED(argv);\
USED(argc);
-#define EARGF(x) ((argv[1] == nil)? ((x), abort(), (char *)0) :\
+#define EARGF(x) ((argv[1] == NULL)? ((x), abort(), (char *)0) :\
(argc--, argv++, argv[0]))
#endif
diff --git a/handlr.c b/handlr.c
@@ -39,7 +39,7 @@ handledir(int sock, char *path, char *port, char *base, char *args,
par = xstrdup(pa);
b = strrchr(par + strlen(base), '/');
- if (b != nil) {
+ if (b != NULL) {
*b = '\0';
dprintf(sock, "1..\t%s\t%s\t%s\r\n",
par + strlen(base), ohost, port);
@@ -88,11 +88,11 @@ handlegph(int sock, char *file, char *port, char *base, char *args,
USED(sear);
act = scanfile(file);
- if (act != nil) {
+ if (act != NULL) {
for (i = 0; i < act->num && ret >= 0; i++) {
ret = printelem(sock, act->n[i], ohost, port);
freeelem(act->n[i]);
- act->n[i] = nil;
+ act->n[i] = NULL;
}
dprintf(sock, ".\r\n");
@@ -131,20 +131,20 @@ handlecgi(int sock, char *file, char *port, char *base, char *args,
path = xstrdup(file);
p = strrchr(path, '/');
- if (p != nil)
+ if (p != NULL)
p[1] = '\0';
else {
free(path);
- path = nil;
+ path = NULL;
}
p = strrchr(file, '/');
- if (p == nil)
+ if (p == NULL)
p = file;
- if (sear == nil)
+ if (sear == NULL)
sear = "";
- if (args == nil)
+ if (args == NULL)
args = "";
dup2(sock, 0);
@@ -152,7 +152,7 @@ handlecgi(int sock, char *file, char *port, char *base, char *args,
dup2(sock, 2);
switch (fork()) {
case 0:
- if (path != nil) {
+ if (path != NULL) {
if (chdir(path) < 0)
break;
}
@@ -160,7 +160,7 @@ handlecgi(int sock, char *file, char *port, char *base, char *args,
setcgienviron(p, file, port, base, args, sear, ohost, chost);
if (execl(file, p, sear, args, ohost, port,
- (char *)nil) == -1) {
+ (char *)NULL) == -1) {
perror("execl");
_exit(1);
}
@@ -179,7 +179,7 @@ handledcgi(int sock, char *file, char *port, char *base, char *args,
char *sear, char *ohost, char *chost)
{
FILE *fp;
- char *p, *path, *ln = nil;
+ char *p, *path, *ln = NULL;
size_t linesiz = 0;
ssize_t n;
int outpipe[2], ret = 0;
@@ -192,20 +192,20 @@ handledcgi(int sock, char *file, char *port, char *base, char *args,
path = xstrdup(file);
p = strrchr(path, '/');
- if (p != nil)
+ if (p != NULL)
p[1] = '\0';
else {
free(path);
- path = nil;
+ path = NULL;
}
p = strrchr(file, '/');
- if (p == nil)
+ if (p == NULL)
p = file;
- if (sear == nil)
+ if (sear == NULL)
sear = "";
- if (args == nil)
+ if (args == NULL)
args = "";
dup2(sock, 0);
@@ -214,7 +214,7 @@ handledcgi(int sock, char *file, char *port, char *base, char *args,
case 0:
dup2(outpipe[1], 1);
close(outpipe[0]);
- if (path != nil) {
+ if (path != NULL) {
if (chdir(path) < 0)
break;
}
@@ -222,7 +222,7 @@ handledcgi(int sock, char *file, char *port, char *base, char *args,
setcgienviron(p, file, port, base, args, sear, ohost, chost);
if (execl(file, p, sear, args, ohost, port,
- (char *)nil) == -1) {
+ (char *)NULL) == -1) {
perror("execl");
_exit(1);
}
@@ -243,7 +243,7 @@ handledcgi(int sock, char *file, char *port, char *base, char *args,
ln[--n] = '\0';
el = getadv(ln);
- if (el == nil)
+ if (el == NULL)
continue;
ret = printelem(sock, el, ohost, port);
diff --git a/ind.c b/ind.c
@@ -56,7 +56,7 @@ filetype type[] = {
{"c", "0", handlebin},
{"sh", "0", handlebin},
{"patch", "0", handlebin},
- {nil, nil, nil},
+ {NULL, NULL, NULL},
};
int
@@ -240,11 +240,11 @@ gettype(char *filename)
int i;
end = strrchr(filename, '.');
- if (end == nil)
+ if (end == NULL)
return &type[0];
end++;
- for (i = 0; type[i].end != nil; i++)
+ for (i = 0; type[i].end != NULL; i++)
if (!strcasecmp(end, type[i].end))
return &type[i];
@@ -254,10 +254,10 @@ gettype(char *filename)
void
freeelem(Elems *e)
{
- if (e != nil) {
- if (e->e != nil) {
+ if (e != NULL) {
+ if (e->e != NULL) {
for (;e->num > 0; e->num--)
- if (e->e[e->num - 1] != nil)
+ if (e->e[e->num - 1] != NULL)
free(e->e[e->num - 1]);
free(e->e);
}
@@ -269,8 +269,8 @@ freeelem(Elems *e)
void
freeindex(Indexs *i)
{
- if (i != nil) {
- if (i->n != nil) {
+ if (i != NULL) {
+ if (i->n != NULL) {
for (;i->num > 0; i->num--)
freeelem(i->n[i->num - 1]);
free(i->n);
@@ -321,7 +321,7 @@ getadv(char *str)
o = xstrdup(str);
b = o + 1;
bo = b;
- while ((e = strchr(bo, '|')) != nil) {
+ while ((e = strchr(bo, '|')) != NULL) {
if (e != bo && e[-1] == '\\') {
memmove(&e[-1], e, strlen(e));
bo = e;
@@ -335,12 +335,12 @@ getadv(char *str)
}
e = strchr(b, ']');
- if (e != nil) {
+ if (e != NULL) {
*e = '\0';
addelem(ret, b);
}
free(o);
- if (ret->e != nil && ret->num == 5)
+ if (ret->e != NULL && ret->num == 5)
return ret;
/* Invalid entry: Give back the whole line. */
@@ -381,7 +381,7 @@ scanfile(char *fname)
Elems *el;
if (!(fp = fopen(fname, "r")))
- return nil;
+ return NULL;
ret = xcalloc(1, sizeof(Indexs));
@@ -389,7 +389,7 @@ scanfile(char *fname)
if (ln[n - 1] == '\n')
ln[--n] = '\0';
el = getadv(ln);
- if(el == nil)
+ if(el == NULL)
continue;
addindexs(ret, el);
@@ -399,9 +399,9 @@ scanfile(char *fname)
free(ln);
fclose(fp);
- if (ret->n == nil) {
+ if (ret->n == NULL) {
free(ret);
- return nil;
+ return NULL;
}
return ret;
diff --git a/ind.h b/ind.h
@@ -7,7 +7,6 @@
#define IND_H
#include <stdio.h>
-#define nil NULL
extern int glfd;
diff --git a/main.c b/main.c
@@ -41,7 +41,7 @@ int glfd = -1;
int loglvl = 15;
int listfd = -1;
int revlookup = 1;
-char *logfile = nil;
+char *logfile = NULL;
char *argv0;
char *stdbase = "/var/gopher";
@@ -72,11 +72,11 @@ char *selinval ="3Happy helping ☃ here: "
int
dropprivileges(struct group *gr, struct passwd *pw)
{
- if (gr != nil)
+ if (gr != NULL)
if (setgroups(1, &gr->gr_gid) != 0 || setgid(gr->gr_gid) != 0)
return -1;
- if (pw != nil) {
- if (gr == nil) {
+ if (pw != NULL) {
+ if (gr == NULL) {
if (setgroups(1, &pw->pw_gid) != 0 ||
setgid(pw->pw_gid) != 0)
return -1;
@@ -123,7 +123,7 @@ handlerequest(int sock, char *base, char *ohost, char *port, char *clienth,
memset(&dir, 0, sizeof(dir));
memset(recvb, 0, sizeof(recvb));
memset(recvc, 0, sizeof(recvc));
- args = nil;
+ args = NULL;
len = recv(sock, recvb, sizeof(recvb)-1, 0);
if (len <= 0) {
@@ -139,7 +139,7 @@ handlerequest(int sock, char *base, char *ohost, char *port, char *clienth,
if (c)
c[0] = '\0';
sear = strchr(recvb, '\t');
- if (sear != nil) {
+ if (sear != NULL) {
*sear++ = '\0';
/*
@@ -173,7 +173,7 @@ handlerequest(int sock, char *base, char *ohost, char *port, char *clienth,
}
args = strchr(recvb, '?');
- if (args != nil)
+ if (args != NULL)
*args++ = '\0';
if (recvb[0] == '\0') {
@@ -219,7 +219,7 @@ handlerequest(int sock, char *base, char *ohost, char *port, char *clienth,
logentry(clienth, clientp, recvc, "serving");
c = strrchr(path, '/');
- if (c == nil)
+ if (c == NULL)
c = path;
type = gettype(c);
if (nocgi && (type->f == handledcgi || type->f == handlecgi)) {
@@ -262,7 +262,7 @@ sighandler(int sig)
case SIGABRT:
case SIGTERM:
case SIGKILL:
- if (logfile != nil && glfd != -1) {
+ if (logfile != NULL && glfd != -1) {
close(glfd);
glfd = -1;
}
@@ -303,11 +303,11 @@ getlistenfd(struct addrinfo *hints, char *bindip, char *port)
if (getaddrinfo(bindip, port, hints, &ai))
return -1;
- if (ai == nil)
+ if (ai == NULL)
return -1;
on = 1;
- for (rp = ai; rp != nil; rp = rp->ai_next) {
+ for (rp = ai; rp != NULL; rp = rp->ai_next) {
listfd = socket(rp->ai_family, rp->ai_socktype,
rp->ai_protocol);
if (listfd < 0)
@@ -335,7 +335,7 @@ getlistenfd(struct addrinfo *hints, char *bindip, char *port)
logentry(addstr, port, "-", "could not bind");
}
}
- if (rp == nil)
+ if (rp == NULL)
return -1;
freeaddrinfo(ai);
@@ -367,12 +367,12 @@ main(int argc, char *argv[])
base = stdbase;
port = stdport;
dofork = 1;
- user = nil;
- group = nil;
- us = nil;
- gr = nil;
- bindip = nil;
- ohost = nil;
+ user = NULL;
+ group = NULL;
+ us = NULL;
+ gr = NULL;
+ bindip = NULL;
+ ohost = NULL;
sport = port;
v4 = 1;
v6 = 1;
@@ -432,7 +432,7 @@ main(int argc, char *argv[])
if (argc != 0)
usage();
- if (ohost == nil) {
+ if (ohost == NULL) {
ohost = xcalloc(1, 513);
if (gethostname(ohost, 512) < 0) {
perror("gethostname");
@@ -443,15 +443,15 @@ main(int argc, char *argv[])
ohost = xstrdup(ohost);
}
- if (group != nil) {
- if ((gr = getgrnam(group)) == nil) {
+ if (group != NULL) {
+ if ((gr = getgrnam(group)) == NULL) {
perror("no such group");
return 1;
}
}
- if (user != nil) {
- if ((us = getpwnam(user)) == nil) {
+ if (user != NULL) {
+ if ((us = getpwnam(user)) == NULL) {
perror("no such user");
return 1;
}
@@ -469,7 +469,7 @@ main(int argc, char *argv[])
}
}
- if (logfile != nil) {
+ if (logfile != NULL) {
glfd = open(logfile, O_APPEND | O_WRONLY | O_CREAT, 0644);
if (glfd < 0) {
perror("log");
@@ -595,7 +595,7 @@ main(int argc, char *argv[])
shutdown(listfd, SHUT_RDWR);
close(listfd);
- if (logfile != nil && glfd != -1) {
+ if (logfile != NULL && glfd != -1) {
close(glfd);
glfd = -1;
}