summaryrefslogtreecommitdiff
path: root/csvncgi/html.c
diff options
context:
space:
mode:
authorkx <kx@radix.pro>2023-03-24 03:55:33 +0300
committerkx <kx@radix.pro>2023-03-24 03:55:33 +0300
commitbfc1508d26c89c9a36d2d9a827fe2c4ed128884d (patch)
tree8d41298a7072a3e289e4912f77ece75cbea1bd54 /csvncgi/html.c
parentc836ae3775cf72f17e0b7e3792d156fdb389bee3 (diff)
downloadcsvn-ui-bfc1508d26c89c9a36d2d9a827fe2c4ed128884d.tar.xz
Version 0.1.4
Diffstat (limited to 'csvncgi/html.c')
-rw-r--r--csvncgi/html.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/csvncgi/html.c b/csvncgi/html.c
new file mode 100644
index 0000000..df50a61
--- /dev/null
+++ b/csvncgi/html.c
@@ -0,0 +1,81 @@
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/sysinfo.h>
+#include <sys/types.h>
+#include <stdint.h>
+#include <dirent.h>
+#include <sys/stat.h> /* chmod(2) */
+#include <sys/file.h>
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <string.h> /* strdup(3) */
+#include <libgen.h> /* basename(3) */
+#include <ctype.h> /* tolower(3) */
+#include <errno.h>
+#include <time.h>
+#include <sys/time.h>
+#include <pwd.h>
+#include <grp.h>
+#include <stdarg.h>
+#include <unistd.h>
+
+#include <defs.h>
+#include <fatal.h>
+#include <http.h>
+#include <html.h>
+#include <strbuf.h>
+
+
+#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 );
+}