#ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include /* chmod(2) */ #include #include #include #include #include /* strdup(3) */ #include /* basename(3) */ #include /* tolower(3) */ #include #include #include #include #include #include #include #include #include #include #include #include #define HTML_ERRMSG_SIZE 4096 void html_error( const char *fmt, ... ) { va_list arg_ptr; char buf[HTML_ERRMSG_SIZE]; char msg[HTML_ERRMSG_SIZE]; char *format = "%s: %s\n"; va_start( arg_ptr, fmt ); vsnprintf( msg, HTML_ERRMSG_SIZE, (const void *)fmt, arg_ptr ); va_end( arg_ptr ); /* Reset variable arguments. */ snprintf( buf, HTML_ERRMSG_SIZE, format, "http", msg ); (void)write( STDERR_FILENO, buf, strlen( buf ) ); exit( 1 ); } html_errfunc html_fatal = html_error; void html_raw( const char *data, size_t size ) { if( write( STDOUT_FILENO, data, size ) != size ) html_fatal( "write error on html output" ); } void html( const char *txt ) { html_raw( txt, strlen(txt) ); } void htmlf( const char *format, ... ) { va_list args; struct strbuf buf = STRBUF_INIT; va_start( args, format ); strbuf_vaddf( &buf, format, args ); va_end( args ); html( buf.buf ); strbuf_release( &buf ); }