X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=examples%2Fecho.c;h=6e71b1fa76b69e333344268e6cfc75864409e945;hb=e4bb1ae06af550799a635c3e0188bc2567d79816;hp=d2b3092efe9c474618e9becd4caaf30f4a962585;hpb=2fd179abeca574b3ef6e903065c9712a35343861;p=catagits%2Ffcgi2.git diff --git a/examples/echo.c b/examples/echo.c index d2b3092..6e71b1f 100644 --- a/examples/echo.c +++ b/examples/echo.c @@ -1,4 +1,4 @@ -/* +/* * echo.c -- * * Produce a page containing all FastCGI inputs @@ -10,66 +10,78 @@ * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * */ - #ifndef lint -static const char rcsid[] = "$Id: echo.c,v 1.2 1999/01/30 22:27:31 roberts Exp $"; +static const char rcsid[] = "$Id: echo.c,v 1.5 1999/07/28 00:29:37 roberts Exp $"; #endif /* not lint */ -#if defined HAVE_UNISTD_H || __linux__ -#include -#endif +#include "fcgi_config.h" -#include "fcgi_stdio.h" #include +#ifdef HAVE_UNISTD_H +#include +#endif + #ifdef _WIN32 #include #else extern char **environ; #endif +#include "fcgi_stdio.h" + + static void PrintEnv(char *label, char **envp) { printf("%s:
\n
\n", label);
-    for(; *envp != NULL; envp++) {
+    for ( ; *envp != NULL; envp++) {
         printf("%s\n", *envp);
     }
     printf("

\n"); } -void main () +int main () { char **initialEnv = environ; int count = 0; - while(FCGI_Accept() >= 0) { + + while (FCGI_Accept() >= 0) { char *contentLength = getenv("CONTENT_LENGTH"); int len; + printf("Content-type: text/html\r\n" - "\r\n" - "FastCGI echo" - "

FastCGI echo

\n" - "Request number %d, Process ID: %d

\n", ++count, getpid()); - if(contentLength != NULL) { + "\r\n" + "FastCGI echo" + "

FastCGI echo

\n" + "Request number %d, Process ID: %d

\n", ++count, getpid()); + + if (contentLength != NULL) { len = strtol(contentLength, NULL, 10); - } else { + } + else { len = 0; } - if(len <= 0) { + + if (len <= 0) { printf("No data from standard input.

\n"); - } else { + } + else { int i, ch; + printf("Standard input:
\n

\n");
-            for(i = 0; i < len; i++) {
-                if((ch = getchar()) < 0) {
-                    printf("Error: Not enough bytes received "
-                           "on standard input

\n"); + for (i = 0; i < len; i++) { + if ((ch = getchar()) < 0) { + printf("Error: Not enough bytes received on standard input

\n"); break; } putchar(ch); } printf("\n

\n"); } + PrintEnv("Request environment", environ); PrintEnv("Initial environment", initialEnv); } /* while */ + + return 0; }