"Fossies" - the Fresh Open Source Software Archive

Member "libgcgi.a-0.9.5/examples/getinput.c" (22 Jun 2002, 1263 Bytes) of package /linux/www/old/gcgi-0.9.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #include <stdlib.h>
    2 #include <stdio.h>
    3 #include <sys/types.h>
    4 #include <errno.h>
    5 
    6 int main (int argc, char *argv[], char *envp[]) 
    7 {
    8     FILE  *output;
    9     int    clen;
   10     size_t read, write;
   11     off_t  offset;
   12     char  *querystring, *e;
   13 
   14     if ((e = getenv("CONTENT_LENGTH")) == NULL) {
   15       fprintf(stderr, "Unable to get content length.");
   16       return -1;
   17     }
   18 
   19     clen = strtol(e, NULL, 10);
   20     /* Content Length was out of range */
   21     if (errno == ERANGE) {
   22       fprintf(stderr, "Unable to convert Content-Length to integer.\n");
   23         return -1;
   24     }
   25 
   26     read           = 0;
   27     offset         = 0;
   28     querystring    = (char *) malloc(clen+1);
   29     memset(querystring, 0, clen + 1);
   30 
   31     /* Read in the query from STDIN */
   32     do {
   33         read = fread(querystring + offset, sizeof(char), clen - offset, stdin);
   34         if (ferror(stdin)) 
   35             return -1;
   36         else if (read <= 0)
   37             continue;
   38         offset += read;
   39     } while (offset < clen && read > 0);
   40 
   41     if ((output = fopen("./output", "w")) == NULL)
   42       fprintf(stderr, "Unable to open output!");
   43 
   44     write = fwrite(querystring, sizeof(char), clen, output);
   45     fclose(output);
   46 
   47     fprintf(stdout, "Content-Type: text/plain\r\n\r\nDone.\n");
   48 
   49     return 0;
   50 }