Having trouble reading from STDIN using fread(). The environment variable CONTENT_LENGTH is used to tell the program the length of the input in bytes. I can use atoi(getenv("CONTENT_LENGTH")) just fine. Where I'm having trouble is with fread()...
Obviously this won't run on the command line. But for some reason it won't work on the server, either. I can only guess, but I think it's always a segmentation fault because the script ends "prematurely" according to the error log:
printf("%s\n<br />",s); //Shows you CONTENT_LENGTH works
printf("%d\n<br />",i); //Shows you it was converted to int
fread(tmp,i,1,stdin); //read from stdin something of i bytes to tmp
[Thu Sep 15 07:18:26 2011] [error] [client 127.0.0.1] Premature end of script headers: a.out, referer: http://localhost/home.html
What's actually happening?