Convert the little caches in util_sock.c to use
[bbaumbach/samba-autobuild/.git] / source / lib / dprintf.c
index 11c9f23e9d724d5826676407e18ccbe1d83affa4..18b261623e693d30c7f22b983bf24d348a131d1c 100644 (file)
@@ -1,12 +1,11 @@
 /* 
-   Unix SMB/Netbios implementation.
-   Version 3.0
+   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
+   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,
@@ -15,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 <http://www.gnu.org/licenses/>.
 */
 
 
 
 #include "includes.h"
 
-int d_vfprintf(FILE *f, const char *format, va_list ap)
+ int d_vfprintf(FILE *f, const char *format, va_list ap)
 {
        char *p, *p2;
        int ret, maxlen, clen;
        const char *msgstr;
+       va_list ap2;
 
        /* do any message translations */
        msgstr = lang_msg(format);
        if (!msgstr) return -1;
 
-       ret = vasprintf(&p, msgstr, ap);
+       VA_COPY(ap2, ap);
+
+       ret = vasprintf(&p, msgstr, ap2);
 
        lang_msg_free(msgstr);
 
@@ -52,12 +53,12 @@ int d_vfprintf(FILE *f, const char *format, va_list ap)
           charset, but beware of it growing */
        maxlen = ret*2;
 again:
-       p2 = malloc(maxlen);
+       p2 = (char *)SMB_MALLOC(maxlen);
        if (!p2) {
                SAFE_FREE(p);
                return -1;
        }
-       clen = convert_string(CH_UNIX, CH_DISPLAY, p, ret, p2, maxlen);
+       clen = convert_string(CH_UNIX, CH_DISPLAY, p, ret, p2, maxlen, True);
 
        if (clen >= maxlen) {
                /* it didn't fit - try a larger buffer */