5 kx
5 kx #ifdef HAVE_CONFIG_H
5 kx #include <config.h>
5 kx #endif
5 kx
5 kx #include <stdlib.h>
5 kx #include <stdio.h>
5 kx #include <sys/sysinfo.h>
5 kx #include <sys/types.h>
5 kx #include <stdint.h>
5 kx #include <dirent.h>
5 kx #include <sys/stat.h> /* chmod(2) */
5 kx #include <sys/file.h>
5 kx #include <sys/mman.h>
5 kx #include <fcntl.h>
5 kx #include <limits.h>
5 kx #include <string.h> /* strdup(3) */
5 kx #include <libgen.h> /* basename(3) */
5 kx #include <ctype.h> /* tolower(3) */
5 kx #include <errno.h>
5 kx #include <time.h>
5 kx #include <sys/time.h>
5 kx #include <pwd.h>
5 kx #include <grp.h>
5 kx #include <stdarg.h>
5 kx #include <unistd.h>
5 kx
5 kx #include <defs.h>
5 kx #include <fatal.h>
5 kx #include <http.h>
5 kx #include <html.h>
5 kx #include <strbuf.h>
5 kx
5 kx
5 kx #define HTML_ERRMSG_SIZE 4096
5 kx
5 kx void html_error( const char *fmt, ... )
5 kx {
5 kx va_list arg_ptr;
5 kx char buf[HTML_ERRMSG_SIZE];
5 kx char msg[HTML_ERRMSG_SIZE];
5 kx char *format = "%s: %s\n";
5 kx
5 kx va_start( arg_ptr, fmt );
5 kx
5 kx vsnprintf( msg, HTML_ERRMSG_SIZE, (const void *)fmt, arg_ptr );
5 kx
5 kx va_end( arg_ptr ); /* Reset variable arguments. */
5 kx
5 kx snprintf( buf, HTML_ERRMSG_SIZE, format, "http", msg );
5 kx
5 kx (void)write( STDERR_FILENO, buf, strlen( buf ) );
5 kx
5 kx exit( 1 );
5 kx }
5 kx
5 kx html_errfunc html_fatal = html_error;
5 kx
5 kx
5 kx void html_raw( const char *data, size_t size )
5 kx {
5 kx if( write( STDOUT_FILENO, data, size ) != size )
5 kx html_fatal( "write error on html output" );
5 kx }
5 kx
5 kx void html( const char *txt )
5 kx {
5 kx html_raw( txt, strlen(txt) );
5 kx }
5 kx
5 kx void htmlf( const char *format, ... )
5 kx {
5 kx va_list args;
5 kx struct strbuf buf = STRBUF_INIT;
5 kx
5 kx va_start( args, format );
5 kx strbuf_vaddf( &buf, format, args );
5 kx va_end( args );
5 kx html( buf.buf );
5 kx strbuf_release( &buf );
5 kx }