Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/lib/util/dprintf.c

    r414 r988  
    3434#include "includes.h"
    3535#include "system/locale.h"
    36 #include "param/param.h"
    3736
    38 static smb_iconv_t display_cd = (smb_iconv_t)-1;
    39 
    40 void d_set_iconv(smb_iconv_t cd)
     37static int d_vfprintf(FILE *f, const char *format, va_list ap)
    4138{
    42         if (display_cd != (smb_iconv_t)-1)
    43                 talloc_free(display_cd);
    44 
    45         display_cd = cd;
    46 }
    47 
    48 _PUBLIC_ int d_vfprintf(FILE *f, const char *format, va_list ap)
    49 {
    50         char *p, *p2;
    51         int ret, clen;
    52         va_list ap2;
    53 
    54         /* If there's nothing to convert, take a shortcut */
    55         if (display_cd == (smb_iconv_t)-1) {
    56                 return vfprintf(f, format, ap);
    57         }
    58 
    59         /* do any message translations */
    60         va_copy(ap2, ap);
    61         ret = vasprintf(&p, format, ap2);
    62         va_end(ap2);
    63 
    64         if (ret <= 0) return ret;
    65 
    66         clen = iconv_talloc(NULL, display_cd, p, ret, (void **)&p2);
    67         if (clen == -1) {
    68                 /* the string can't be converted - do the best we can,
    69                    filling in non-printing chars with '?' */
    70                 int i;
    71                 for (i=0;i<ret;i++) {
    72                         if (isprint(p[i]) || isspace(p[i])) {
    73                                 fwrite(p+i, 1, 1, f);
    74                         } else {
    75                                 fwrite("?", 1, 1, f);
    76                         }
    77                 }
    78                 SAFE_FREE(p);
    79                 return ret;
    80         }
    81 
    82         /* good, its converted OK */
    83         SAFE_FREE(p);
    84         ret = fwrite(p2, 1, clen, f);
    85         talloc_free(p2);
    86 
    87         return ret;
     39        return vfprintf(f, format, ap);
    8840}
    8941
     
    10153}
    10254
    103 _PUBLIC_ int d_printf(const char *format, ...)
     55static FILE *outfile;
     56
     57_PUBLIC_  int d_printf(const char *format, ...)
    10458{
    10559        int ret;
    106         va_list ap;
    107 
    108         va_start(ap, format);
    109         ret = d_vfprintf(stdout, format, ap);
    110         va_end(ap);
    111 
    112         return ret;
     60       va_list ap;
     61       
     62       if (!outfile) outfile = stdout;
     63       
     64       va_start(ap, format);
     65       ret = d_vfprintf(outfile, format, ap);
     66       va_end(ap);
     67       
     68       return ret;
    11369}
    11470
     71/* interactive programs need a way of tell d_*() to write to stderr instead
     72   of stdout */
     73void display_set_stderr(void)
     74{
     75        outfile = stderr;
     76}
Note: See TracChangeset for help on using the changeset viewer.