diff options
Diffstat (limited to 'lib/util')
-rw-r--r-- | lib/util/dprintf.c | 44 | ||||
-rw-r--r-- | lib/util/util.h | 3 | ||||
-rwxr-xr-x | lib/util/wscript_build | 4 |
3 files changed, 25 insertions, 26 deletions
diff --git a/lib/util/dprintf.c b/lib/util/dprintf.c index c7c701bcfa..c79989b517 100644 --- a/lib/util/dprintf.c +++ b/lib/util/dprintf.c @@ -33,22 +33,15 @@ #include "includes.h" #include "system/locale.h" -#include "param/param.h" static smb_iconv_t display_cd = (smb_iconv_t)-1; -void d_set_iconv(smb_iconv_t cd) -{ - if (display_cd != (smb_iconv_t)-1) - talloc_free(display_cd); - - display_cd = cd; -} - static int d_vfprintf(FILE *f, const char *format, va_list ap) { char *p, *p2; - int ret, clen; + int ret; + size_t clen; + bool cret; va_list ap2; /* If there's nothing to convert, take a shortcut */ @@ -56,15 +49,14 @@ static int d_vfprintf(FILE *f, const char *format, va_list ap) return vfprintf(f, format, ap); } - /* do any message translations */ va_copy(ap2, ap); ret = vasprintf(&p, format, ap2); va_end(ap2); if (ret <= 0) return ret; - clen = iconv_talloc(NULL, display_cd, p, ret, (void **)&p2); - if (clen == -1) { + cret = convert_string_talloc(NULL, CH_UTF8, CH_DISPLAY, p, ret, (void **)&p2, &clen); + if (!cret) { /* the string can't be converted - do the best we can, filling in non-printing chars with '?' */ int i; @@ -100,15 +92,25 @@ _PUBLIC_ int d_fprintf(FILE *f, const char *format, ...) return ret; } -_PUBLIC_ int d_printf(const char *format, ...) +static FILE *outfile; + +_PUBLIC_ int d_printf(const char *format, ...) { int ret; - va_list ap; - - va_start(ap, format); - ret = d_vfprintf(stdout, format, ap); - va_end(ap); - - return ret; + va_list ap; + + if (!outfile) outfile = stdout; + + va_start(ap, format); + ret = d_vfprintf(outfile, format, ap); + va_end(ap); + + return ret; } +/* interactive programs need a way of tell d_*() to write to stderr instead + of stdout */ +void display_set_stderr(void) +{ + outfile = stderr; +} diff --git a/lib/util/util.h b/lib/util/util.h index f4861a6fcf..c715440186 100644 --- a/lib/util/util.h +++ b/lib/util/util.h @@ -211,13 +211,10 @@ _PUBLIC_ char** generate_unique_strs(TALLOC_CTX *mem_ctx, size_t len, uint32_t num); /* The following definitions come from lib/util/dprintf.c */ -#if _SAMBA_BUILD_ == 4 -_PUBLIC_ void d_set_iconv(smb_iconv_t); _PUBLIC_ int d_fprintf(FILE *f, const char *format, ...) PRINTF_ATTRIBUTE(2,3); _PUBLIC_ int d_printf(const char *format, ...) PRINTF_ATTRIBUTE(1,2); _PUBLIC_ void display_set_stderr(void); -#endif /* The following definitions come from lib/util/util_str.c */ diff --git a/lib/util/wscript_build b/lib/util/wscript_build index a094fa3b54..8046a8ba07 100755 --- a/lib/util/wscript_build +++ b/lib/util/wscript_build @@ -6,11 +6,11 @@ common_util_sources = '''talloc_stack.c smb_threads.c xfile.c data_blob.c signal.c system.c params.c util.c util_id.c util_net.c util_strlist.c util_paths.c idtree.c debug.c fault.c base64.c util_str.c util_str_common.c substitute.c ms_fnmatch.c - server_id.c''' + server_id.c dprintf.c''' common_util_headers = 'debug.h' common_util_public_deps = 'talloc pthread LIBCRYPTO CHARSET' -s4_util_sources = '''dprintf.c parmlist.c''' +s4_util_sources = '''parmlist.c''' s4_util_deps = 'DYNCONFIG' s4_util_public_deps = 'talloc execinfo uid_wrapper' s4_util_public_headers = 'attr.h byteorder.h data_blob.h memory.h safe_string.h time.h talloc_stack.h xfile.h dlinklist.h util.h string_wrappers.h' |