Nothing wrong with big format strings on printf() function. Try this:
Code:
#include <fcgi_stdio.h>
#include <stdlib.h>
#include <string.h>
int main ( void )
{
int len = 0;
while ( FCGI_Accept() >= 0 )
{
FILE *fp;
// Change mode to append. Testing errno...
errno = 0;
fp = fopen ( "/wwwdata/example.txt", "a+" );
if ( errno )
printf ( "Content-type: text/html\r\n\r\n<html><body><h1>Error</h1><br/>%s</body>\r\n",
strerror ( errno ) );
// Output actual content only if file could be opened.
if ( fp )
{
char *content_type = getenv ( "CONTENT_TYPE" );
char *contentLength = getenv ( "CONTENT_LENGTH" );
if ( contentLength )
len = atoi ( contentLength );
else
len = 0;
// Added \r\n at the end of the string.
printf ( "Content-type: text/html\r\n"
"\r\n"
"<!DOCTYPE html>"
"<html><head><meta content='text/html;charset=utf-8' http-equiv='Content-Type'><meta charset='utf-8' http-equiv='encoding'>"
"<script type='text/javascript'>"
"function f(){var x = new XMLHttpRequest();x.open('POST', '/i/a.out', true);x.timeout = 300000;"
"var f = new FormData();"
"f.append('f', window.document.getElementById('f').files[0]);"
"x.send(f);"
"}</script></head><body>"
"<b>%d</b><input type='file' id='f' name='f' accept='image/png'><p onClick='f();'>PRESS!</p></body></html>\r\n",
len );
// Why to write each char individually if content_type is a string?
if ( len > 0 && content_type )
fprintf ( fp, "%s\n", content_type );
fclose ( fp );
}
FCGI_Finish();
}
}