s4: Remove autogenerated attributes from minschema and fullschema output
[Samba/bb.git] / lib / util / dprintf.c
blob3e6d0e8bca99dfe5bf9705818b2f2f96f7444c73
1 /*
2 Unix SMB/CIFS implementation.
3 display print functions
4 Copyright (C) Andrew Tridgell 2001
5 Copyright (C) Jelmer Vernooij 2007
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 this module provides functions for printing internal strings in the
24 "display charset".
26 This charset may be quite different from the chosen unix charset.
28 Eventually these functions will need to take care of column count constraints
30 The d_ prefix on print functions in Samba refers to the display character set
31 conversion
34 #include "includes.h"
35 #include "system/locale.h"
36 #include "param/param.h"
38 static smb_iconv_t display_cd = (smb_iconv_t)-1;
40 void d_set_iconv(smb_iconv_t cd)
42 display_cd = cd;
45 _PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap)
47 char *p, *p2;
48 int ret, clen;
49 va_list ap2;
51 /* If there's nothing to convert, take a shortcut */
52 if (display_cd == (smb_iconv_t)-1) {
53 return vfprintf(f, format, ap);
56 /* do any message translations */
57 va_copy(ap2, ap);
58 ret = vasprintf(&p, format, ap2);
59 va_end(ap2);
61 if (ret <= 0) return ret;
63 clen = iconv_talloc(NULL, display_cd, p, ret, (void **)&p2);
64 if (clen == -1) {
65 /* the string can't be converted - do the best we can,
66 filling in non-printing chars with '?' */
67 int i;
68 for (i=0;i<ret;i++) {
69 if (isprint(p[i]) || isspace(p[i])) {
70 fwrite(p+i, 1, 1, f);
71 } else {
72 fwrite("?", 1, 1, f);
75 SAFE_FREE(p);
76 return ret;
79 /* good, its converted OK */
80 SAFE_FREE(p);
81 ret = fwrite(p2, 1, clen, f);
82 talloc_free(p2);
84 return ret;
88 _PUBLIC_ int d_fprintf(FILE *f, const char *format, ...)
90 int ret;
91 va_list ap;
93 va_start(ap, format);
94 ret = d_vfprintf(f, format, ap);
95 va_end(ap);
97 return ret;
100 _PUBLIC_ int d_printf(const char *format, ...)
102 int ret;
103 va_list ap;
105 va_start(ap, format);
106 ret = d_vfprintf(stdout, format, ap);
107 va_end(ap);
109 return ret;