From dfc517b05395d925a4d7b1ce9633a849f9468e70 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 23 Feb 2006 15:52:24 +0000 Subject: r13658: More moving around of files: - Collect the generic utility functions into a lib/util/ (a la GLib is for the GNOME folks) - Remove even more files from include/ (This used to be commit ba62880f5b05c2a505dc7f54676b231197a7e707) --- source4/lib/util/dprintf.c | 107 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 source4/lib/util/dprintf.c (limited to 'source4/lib/util/dprintf.c') diff --git a/source4/lib/util/dprintf.c b/source4/lib/util/dprintf.c new file mode 100644 index 0000000000..64227148fd --- /dev/null +++ b/source4/lib/util/dprintf.c @@ -0,0 +1,107 @@ +/* + Unix SMB/CIFS implementation. + display print functions + Copyright (C) Andrew Tridgell 2001 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + + +/* + this module provides functions for printing internal strings in the "display charset" + This charset may be quite different from the chosen unix charset + + Eventually these functions will need to take care of column count constraints + + The d_ prefix on print functions in Samba refers to the display character set + conversion +*/ + +#include "includes.h" + +int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0) +{ + char *p, *p2; + int ret, maxlen, clen; + va_list ap2; + + /* do any message translations */ + VA_COPY(ap2, ap); + + ret = vasprintf(&p, format, ap2); + + if (ret <= 0) return ret; + + /* now we have the string in unix format, convert it to the display + charset, but beware of it growing */ + maxlen = ret*2; +again: + p2 = malloc(maxlen); + if (!p2) { + SAFE_FREE(p); + return -1; + } + clen = convert_string(CH_UNIX, CH_DISPLAY, p, ret, p2, maxlen); + + if (clen >= maxlen) { + /* it didn't fit - try a larger buffer */ + maxlen *= 2; + SAFE_FREE(p2); + goto again; + } + + /* good, its converted OK */ + SAFE_FREE(p); + ret = fwrite(p2, 1, clen, f); + SAFE_FREE(p2); + + return ret; +} + + +int d_fprintf(FILE *f, const char *format, ...) _PRINTF_ATTRIBUTE(2,3) +{ + int ret; + va_list ap; + + va_start(ap, format); + ret = d_vfprintf(f, format, ap); + va_end(ap); + + return ret; +} + +static FILE *outfile; + +int d_printf(const char *format, ...) _PRINTF_ATTRIBUTE(1,2) +{ + int 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; +} -- cgit From 967bff7d88f478b49bba9e04244fd9239c0cf3c8 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 7 Mar 2006 16:37:35 +0000 Subject: r13959: make more functions public metze (This used to be commit a5b95a7741085a9adb04b8b63066d1b3d0f024ae) --- source4/lib/util/dprintf.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/lib/util/dprintf.c') diff --git a/source4/lib/util/dprintf.c b/source4/lib/util/dprintf.c index 64227148fd..916db3af93 100644 --- a/source4/lib/util/dprintf.c +++ b/source4/lib/util/dprintf.c @@ -31,7 +31,7 @@ #include "includes.h" -int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0) +_PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0) { char *p, *p2; int ret, maxlen, clen; @@ -71,7 +71,7 @@ again: } -int d_fprintf(FILE *f, const char *format, ...) _PRINTF_ATTRIBUTE(2,3) +_PUBLIC_ int d_fprintf(FILE *f, const char *format, ...) _PRINTF_ATTRIBUTE(2,3) { int ret; va_list ap; @@ -85,7 +85,7 @@ int d_fprintf(FILE *f, const char *format, ...) _PRINTF_ATTRIBUTE(2,3) static FILE *outfile; -int d_printf(const char *format, ...) _PRINTF_ATTRIBUTE(1,2) +_PUBLIC_ int d_printf(const char *format, ...) _PRINTF_ATTRIBUTE(1,2) { int ret; va_list ap; @@ -101,7 +101,7 @@ int d_printf(const char *format, ...) _PRINTF_ATTRIBUTE(1,2) /* interactive programs need a way of tell d_*() to write to stderr instead of stdout */ -void display_set_stderr(void) +_PUBLIC_ void display_set_stderr(void) { outfile = stderr; } -- cgit From 4a61e4901ebc751fea57880424f9045e3bdf238e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Apr 2006 16:05:21 +0000 Subject: r14999: Remove more unused autoconf code Simplify va_copy() replacement code a bit (This used to be commit a5c87360a7f14a90b831ea372277f4f89ee4c5f1) --- source4/lib/util/dprintf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util/dprintf.c') diff --git a/source4/lib/util/dprintf.c b/source4/lib/util/dprintf.c index 916db3af93..62dc2a227a 100644 --- a/source4/lib/util/dprintf.c +++ b/source4/lib/util/dprintf.c @@ -38,7 +38,7 @@ _PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBU va_list ap2; /* do any message translations */ - VA_COPY(ap2, ap); + va_copy(ap2, ap); ret = vasprintf(&p, format, ap2); -- cgit From 8538af1107a6e894d4941708b77e79fac587e35d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 6 Feb 2007 05:26:25 +0000 Subject: r21174: many thanks to Paul Wayper for pointing out that C99 requires a matching va_end() for each va_copy(). This doesn't matter for most architectures, but there could be some obscure ones where it does matter. some of this should be ported to Samba3 (This used to be commit 21eb316473486cb6b73bb3ff9c5f3a44ecd57e4a) --- source4/lib/util/dprintf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util/dprintf.c') diff --git a/source4/lib/util/dprintf.c b/source4/lib/util/dprintf.c index 62dc2a227a..79b90ec3e1 100644 --- a/source4/lib/util/dprintf.c +++ b/source4/lib/util/dprintf.c @@ -39,8 +39,8 @@ _PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBU /* do any message translations */ va_copy(ap2, ap); - ret = vasprintf(&p, format, ap2); + va_end(ap2); if (ret <= 0) return ret; -- cgit From 793db3bc5073083e223d084437c6e751d422416d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 7 Mar 2007 10:00:14 +0000 Subject: r21740: this fixes the real cause of the large log files we had. The problem was we were not checking the result of a convert_string() call, and it was giving -1. We then passed -1 to fwrite() on stdout, which on aix and macosx wrote all of available memory to stdout :) To fix this, replace non-printing chars with ? in d_printf if the string cannot be converted (This used to be commit d20102d363f4b9214e29296ad8ec45c8d95614b5) --- source4/lib/util/dprintf.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'source4/lib/util/dprintf.c') diff --git a/source4/lib/util/dprintf.c b/source4/lib/util/dprintf.c index 79b90ec3e1..209fb8da36 100644 --- a/source4/lib/util/dprintf.c +++ b/source4/lib/util/dprintf.c @@ -30,6 +30,7 @@ */ #include "includes.h" +#include "system/locale.h" _PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0) { @@ -54,6 +55,22 @@ again: return -1; } clen = convert_string(CH_UNIX, CH_DISPLAY, p, ret, p2, maxlen); + if (clen == -1) { + /* the string can't be converted - do the best we can, + filling in non-printing chars with '?' */ + int i; + for (i=0;i= maxlen) { /* it didn't fit - try a larger buffer */ -- cgit From 0479a2f1cbae51fcd8dbdc3c148c808421fb4d25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:07:03 +0000 Subject: r23792: convert Samba4 to GPLv3 There are still a few tidyups of old FSF addresses to come (in both s3 and s4). More commits soon. (This used to be commit fcf38a38ac691abd0fa51b89dc951a08e89fdafa) --- source4/lib/util/dprintf.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/util/dprintf.c') diff --git a/source4/lib/util/dprintf.c b/source4/lib/util/dprintf.c index 209fb8da36..a7770f364d 100644 --- a/source4/lib/util/dprintf.c +++ b/source4/lib/util/dprintf.c @@ -5,7 +5,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ -- cgit From dccf3f99e45137b6cd18c1de1c79808ad67130d1 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Sep 2007 13:27:14 +0000 Subject: r25027: Fix more warnings. (This used to be commit 5085c53fcfade614e83d21fc2c1a5bc43bb2a729) --- source4/lib/util/dprintf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util/dprintf.c') diff --git a/source4/lib/util/dprintf.c b/source4/lib/util/dprintf.c index a7770f364d..91665e7bdd 100644 --- a/source4/lib/util/dprintf.c +++ b/source4/lib/util/dprintf.c @@ -48,7 +48,7 @@ _PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBU charset, but beware of it growing */ maxlen = ret*2; again: - p2 = malloc(maxlen); + p2 = (char *)malloc(maxlen); if (!p2) { SAFE_FREE(p); return -1; -- cgit From ef13073676be9ec073f9cec3dd9fbce90e1d1228 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 14 Oct 2007 13:00:12 +0200 Subject: r25627: Remove unused global. (This used to be commit b0b4668333b53991b04cae8905836c766e50aa10) --- source4/lib/util/dprintf.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'source4/lib/util/dprintf.c') diff --git a/source4/lib/util/dprintf.c b/source4/lib/util/dprintf.c index 91665e7bdd..be716241e3 100644 --- a/source4/lib/util/dprintf.c +++ b/source4/lib/util/dprintf.c @@ -19,8 +19,10 @@ /* - this module provides functions for printing internal strings in the "display charset" - This charset may be quite different from the chosen unix charset + this module provides functions for printing internal strings in the + "display charset". + + This charset may be quite different from the chosen unix charset. Eventually these functions will need to take care of column count constraints @@ -99,25 +101,14 @@ _PUBLIC_ int d_fprintf(FILE *f, const char *format, ...) _PRINTF_ATTRIBUTE(2,3) return ret; } -static FILE *outfile; - _PUBLIC_ int d_printf(const char *format, ...) _PRINTF_ATTRIBUTE(1,2) { int ret; va_list ap; - if (!outfile) outfile = stdout; - va_start(ap, format); - ret = d_vfprintf(outfile, format, ap); + ret = d_vfprintf(stdout, format, ap); va_end(ap); return ret; } - -/* interactive programs need a way of tell d_*() to write to stderr instead - of stdout */ -_PUBLIC_ void display_set_stderr(void) -{ - outfile = stderr; -} -- cgit From 39ee38d9c1aabf4db065b433d067d0da053d7d61 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 6 Dec 2007 17:52:23 +0100 Subject: r26316: Use contexts for conversion functions. (This used to be commit f6420d933b5b011d428974f3a2a57edf19e6f482) --- source4/lib/util/dprintf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/util/dprintf.c') diff --git a/source4/lib/util/dprintf.c b/source4/lib/util/dprintf.c index be716241e3..5b3fe4b1ea 100644 --- a/source4/lib/util/dprintf.c +++ b/source4/lib/util/dprintf.c @@ -55,7 +55,7 @@ again: SAFE_FREE(p); return -1; } - clen = convert_string(CH_UNIX, CH_DISPLAY, p, ret, p2, maxlen); + clen = convert_string(global_smb_iconv_convenience, CH_UNIX, CH_DISPLAY, p, ret, p2, maxlen); if (clen == -1) { /* the string can't be converted - do the best we can, filling in non-printing chars with '?' */ -- cgit From d891c0c74a03d797aed1c5ac0329fd9d1d78da63 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 13 Dec 2007 22:46:09 +0100 Subject: r26429: Avoid use of global_smb_iconv_convenience. (This used to be commit d37136b7abfbba75ef2e5ab855eb3382b9648b8c) --- source4/lib/util/dprintf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/lib/util/dprintf.c') diff --git a/source4/lib/util/dprintf.c b/source4/lib/util/dprintf.c index 5b3fe4b1ea..ae2b7bb4d5 100644 --- a/source4/lib/util/dprintf.c +++ b/source4/lib/util/dprintf.c @@ -32,6 +32,7 @@ #include "includes.h" #include "system/locale.h" +#include "param/param.h" _PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0) { @@ -55,7 +56,7 @@ again: SAFE_FREE(p); return -1; } - clen = convert_string(global_smb_iconv_convenience, CH_UNIX, CH_DISPLAY, p, ret, p2, maxlen); + clen = convert_string(lp_iconv_convenience(global_loadparm), CH_UNIX, CH_DISPLAY, p, ret, p2, maxlen); if (clen == -1) { /* the string can't be converted - do the best we can, filling in non-printing chars with '?' */ -- cgit From 2bf0cdd01cf399bf28125f9e2a0d419f4e94996c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 13 Dec 2007 22:46:33 +0100 Subject: r26434: Remove display charset from iconv convenience context. (This used to be commit a76625994abf9906d54ae11f9c171f89063cf508) --- source4/lib/util/dprintf.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) (limited to 'source4/lib/util/dprintf.c') diff --git a/source4/lib/util/dprintf.c b/source4/lib/util/dprintf.c index ae2b7bb4d5..308d81b105 100644 --- a/source4/lib/util/dprintf.c +++ b/source4/lib/util/dprintf.c @@ -2,6 +2,7 @@ Unix SMB/CIFS implementation. display print functions Copyright (C) Andrew Tridgell 2001 + Copyright (C) Jelmer Vernooij 2007 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -34,12 +35,24 @@ #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) +{ + display_cd = cd; +} + _PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0) { char *p, *p2; - int ret, maxlen, clen; + int ret, clen; va_list ap2; + /* If there's nothing to convert, take a shortcut */ + if (display_cd == (smb_iconv_t)-1) { + return vfprintf(f, format, ap); + } + /* do any message translations */ va_copy(ap2, ap); ret = vasprintf(&p, format, ap2); @@ -47,16 +60,7 @@ _PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBU if (ret <= 0) return ret; - /* now we have the string in unix format, convert it to the display - charset, but beware of it growing */ - maxlen = ret*2; -again: - p2 = (char *)malloc(maxlen); - if (!p2) { - SAFE_FREE(p); - return -1; - } - clen = convert_string(lp_iconv_convenience(global_loadparm), CH_UNIX, CH_DISPLAY, p, ret, p2, maxlen); + clen = convert_string_talloc_descriptor(NULL, display_cd, p, ret, (void **)&p2); if (clen == -1) { /* the string can't be converted - do the best we can, filling in non-printing chars with '?' */ @@ -69,22 +73,13 @@ again: } } SAFE_FREE(p); - SAFE_FREE(p2); return ret; } - - if (clen >= maxlen) { - /* it didn't fit - try a larger buffer */ - maxlen *= 2; - SAFE_FREE(p2); - goto again; - } - /* good, its converted OK */ SAFE_FREE(p); ret = fwrite(p2, 1, clen, f); - SAFE_FREE(p2); + talloc_free(p2); return ret; } @@ -113,3 +108,4 @@ _PUBLIC_ int d_printf(const char *format, ...) _PRINTF_ATTRIBUTE(1,2) return ret; } + -- cgit From afe3e8172ddaa5e4aa811faceecda4f943d6e2ef Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 2 Apr 2008 04:53:27 +0200 Subject: Install public header files again and include required prototypes. (This used to be commit 47ffbbf67435904754469544390b67d34c958343) --- source4/lib/util/dprintf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/util/dprintf.c') diff --git a/source4/lib/util/dprintf.c b/source4/lib/util/dprintf.c index 308d81b105..e4f02758eb 100644 --- a/source4/lib/util/dprintf.c +++ b/source4/lib/util/dprintf.c @@ -42,7 +42,7 @@ void d_set_iconv(smb_iconv_t cd) display_cd = cd; } -_PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBUTE(2,0) +_PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) { char *p, *p2; int ret, clen; @@ -85,7 +85,7 @@ _PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap) _PRINTF_ATTRIBU } -_PUBLIC_ int d_fprintf(FILE *f, const char *format, ...) _PRINTF_ATTRIBUTE(2,3) +_PUBLIC_ int d_fprintf(FILE *f, const char *format, ...) { int ret; va_list ap; @@ -97,7 +97,7 @@ _PUBLIC_ int d_fprintf(FILE *f, const char *format, ...) _PRINTF_ATTRIBUTE(2,3) return ret; } -_PUBLIC_ int d_printf(const char *format, ...) _PRINTF_ATTRIBUTE(1,2) +_PUBLIC_ int d_printf(const char *format, ...) { int ret; va_list ap; -- cgit