httpd: remove redundant NULL assignment and save one strrchr. -8 bytes

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2011-12-18 03:22:36 +01:00
parent ee0f444f11
commit f85bd1a7a7

View File

@ -1284,7 +1284,7 @@ static void send_cgi_and_exit(
{ {
struct fd_pair fromCgi; /* CGI -> httpd pipe */ struct fd_pair fromCgi; /* CGI -> httpd pipe */
struct fd_pair toCgi; /* httpd -> CGI pipe */ struct fd_pair toCgi; /* httpd -> CGI pipe */
char *script; char *script, *last_slash;
int pid; int pid;
/* Make a copy. NB: caller guarantees: /* Make a copy. NB: caller guarantees:
@ -1298,15 +1298,18 @@ static void send_cgi_and_exit(
*/ */
/* Check for [dirs/]script.cgi/PATH_INFO */ /* Check for [dirs/]script.cgi/PATH_INFO */
script = (char*)url; last_slash = script = (char*)url;
while ((script = strchr(script + 1, '/')) != NULL) { while ((script = strchr(script + 1, '/')) != NULL) {
int dir;
*script = '\0'; *script = '\0';
if (!is_directory(url + 1, 1, NULL)) { dir = is_directory(url + 1, /*followlinks:*/ 1, NULL);
/* not directory, found script.cgi/PATH_INFO */
*script = '/'; *script = '/';
if (!dir) {
/* not directory, found script.cgi/PATH_INFO */
break; break;
} }
*script = '/'; /* is directory, find next '/' */ /* is directory, find next '/' */
last_slash = script;
} }
setenv1("PATH_INFO", script); /* set to /PATH_INFO or "" */ setenv1("PATH_INFO", script); /* set to /PATH_INFO or "" */
setenv1("REQUEST_METHOD", request); setenv1("REQUEST_METHOD", request);
@ -1387,7 +1390,7 @@ static void send_cgi_and_exit(
log_and_exit(); log_and_exit();
} }
if (!pid) { if (pid == 0) {
/* Child process */ /* Child process */
char *argv[3]; char *argv[3];
@ -1403,7 +1406,7 @@ static void send_cgi_and_exit(
/* dup2(1, 2); */ /* dup2(1, 2); */
/* Chdiring to script's dir */ /* Chdiring to script's dir */
script = strrchr(url, '/'); script = last_slash;
if (script != url) { /* paranoia */ if (script != url) { /* paranoia */
*script = '\0'; *script = '\0';
if (chdir(url + 1) != 0) { if (chdir(url + 1) != 0) {
@ -1992,7 +1995,7 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr)
/* NB: urlcopy ptr is never changed after this */ /* NB: urlcopy ptr is never changed after this */
/* Extract url args if present */ /* Extract url args if present */
g_query = NULL; /* g_query = NULL; - already is */
tptr = strchr(urlcopy, '?'); tptr = strchr(urlcopy, '?');
if (tptr) { if (tptr) {
*tptr++ = '\0'; *tptr++ = '\0';