Index: contrib/libxo/libxo/libxo.c =================================================================== --- contrib/libxo/libxo/libxo.c +++ contrib/libxo/libxo/libxo.c @@ -78,6 +78,7 @@ unsigned short xo_style; /* XO_STYLE_* value */ unsigned short xo_indent; /* Indent level (if pretty) */ unsigned short xo_indent_by; /* Indent amount (tab stop) */ + xo_flush_func_t xo_flush; /* Write callback */ xo_write_func_t xo_write; /* Write callback */ xo_close_func_t xo_close; /* Close callback */ xo_formatter_t xo_formatter; /* Custom formating function */ @@ -220,6 +221,17 @@ xo_anchor_clear (xo_handle_t *xop); /* + * Callback to flush a FILE pointer + */ +static int +xo_flush_file (void *opaque) +{ + FILE *fp = (FILE *) opaque; + + return (fflush(fp)); +} + +/* * Callback to write data to a FILE pointer */ static int @@ -300,6 +312,7 @@ { xop->xo_opaque = stdout; xop->xo_write = xo_write_to_file; + xop->xo_flush = xo_flush_file; /* * We need to initialize the locale, which isn't really pretty. @@ -1213,7 +1226,7 @@ break; } - xo_flush_h(xop); + (void)xo_flush_h(xop); } void @@ -1299,6 +1312,7 @@ if (xop) { xop->xo_opaque = fp; + xop->xo_flush = xo_flush_file; xop->xo_write = xo_write_to_file; xop->xo_close = xo_close_file; } @@ -3165,7 +3179,8 @@ for (cp = fmt; *cp; ) { if (*cp == '\n') { xo_line_close(xop); - xo_flush_h(xop); + if (xo_flush_h(xop)) + return -1; cp += 1; continue; @@ -4031,13 +4046,14 @@ void xo_set_writer (xo_handle_t *xop, void *opaque, xo_write_func_t write_func, - xo_close_func_t close_func) + xo_close_func_t close_func, xo_flush_func_t flush_func) { xop = xo_default(xop); xop->xo_opaque = opaque; xop->xo_write = write_func; xop->xo_close = close_func; + xop->xo_flush = flush_func; } void @@ -4047,7 +4063,7 @@ xo_free = free_func; } -void +int xo_flush_h (xo_handle_t *xop) { static char div_close[] = ""; @@ -4067,15 +4083,20 @@ } xo_write(xop); + if (xop->xo_flush == NULL) + return 0; + + return (xop->xo_flush(xop->xo_opaque)); + } -void +int xo_flush (void) { - xo_flush_h(NULL); + return xo_flush_h(NULL); } -void +int xo_finish_h (xo_handle_t *xop) { const char *cp = ""; @@ -4093,13 +4114,13 @@ break; } - xo_flush_h(xop); + return xo_flush_h(xop); } -void +int xo_finish (void) { - xo_finish_h(NULL); + return xo_finish_h(NULL); } /* Index: contrib/libxo/libxo/xo.h =================================================================== --- contrib/libxo/libxo/xo.h +++ contrib/libxo/libxo/xo.h @@ -69,6 +69,7 @@ typedef struct xo_handle_s xo_handle_t; /* Handle for XO output */ typedef int (*xo_write_func_t)(void *, const char *); +typedef int (*xo_flush_func_t)(void *); typedef void (*xo_close_func_t)(void *); typedef void *(*xo_realloc_func_t)(void *, size_t); typedef void (*xo_free_func_t)(void *); @@ -93,7 +94,7 @@ void xo_set_writer (xo_handle_t *xop, void *opaque, xo_write_func_t write_func, - xo_close_func_t close_func); + xo_close_func_t close_func, xo_flush_func_t flush_func); void xo_set_allocator (xo_realloc_func_t realloc_func, xo_free_func_t free_func); @@ -227,16 +228,16 @@ void xo_error (const char *fmt, ...); -void +int xo_flush_h (xo_handle_t *xop); -void +int xo_flush (void); -void +int xo_finish_h (xo_handle_t *xop); -void +int xo_finish (void); void