lib/dprintf.c

説明を見る。
00001 /* 
00002    Unix SMB/CIFS implementation.
00003    display print functions
00004    Copyright (C) Andrew Tridgell 2001
00005    
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015    
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software
00018    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019 */
00020 
00021 
00022 /*
00023   this module provides functions for printing internal strings in the "display charset"
00024   This charset may be quite different from the chosen unix charset
00025 
00026   Eventually these functions will need to take care of column count constraints
00027 
00028   The d_ prefix on print functions in Samba refers to the display character set
00029   conversion
00030 */
00031 
00032 #include "includes.h"
00033 
00034  int d_vfprintf(FILE *f, const char *format, va_list ap)
00035 {
00036         char *p, *p2;
00037         int ret, maxlen, clen;
00038         const char *msgstr;
00039         va_list ap2;
00040 
00041         /* do any message translations */
00042         msgstr = lang_msg(format);
00043         if (!msgstr) return -1;
00044 
00045         VA_COPY(ap2, ap);
00046 
00047         ret = vasprintf(&p, msgstr, ap2);
00048 
00049         lang_msg_free(msgstr);
00050 
00051         if (ret <= 0) return ret;
00052 
00053         /* now we have the string in unix format, convert it to the display
00054            charset, but beware of it growing */
00055         maxlen = ret*2;
00056 again:
00057         p2 = (char *)SMB_MALLOC(maxlen);
00058         if (!p2) {
00059                 SAFE_FREE(p);
00060                 return -1;
00061         }
00062         clen = convert_string(CH_UNIX, CH_DISPLAY, p, ret, p2, maxlen, True);
00063 
00064         if (clen >= maxlen) {
00065                 /* it didn't fit - try a larger buffer */
00066                 maxlen *= 2;
00067                 SAFE_FREE(p2);
00068                 goto again;
00069         }
00070 
00071         /* good, its converted OK */
00072         SAFE_FREE(p);
00073         ret = fwrite(p2, 1, clen, f);
00074         SAFE_FREE(p2);
00075 
00076         return ret;
00077 }
00078 
00079 
00080  int d_fprintf(FILE *f, const char *format, ...)
00081 {
00082         int ret;
00083         va_list ap;
00084 
00085         va_start(ap, format);
00086         ret = d_vfprintf(f, format, ap);
00087         va_end(ap);
00088 
00089         return ret;
00090 }
00091 
00092 static FILE *outfile;
00093 
00094  int d_printf(const char *format, ...)
00095 {
00096         int ret;
00097         va_list ap;
00098 
00099         if (!outfile) outfile = stdout;
00100         
00101         va_start(ap, format);
00102         ret = d_vfprintf(outfile, format, ap);
00103         va_end(ap);
00104 
00105         return ret;
00106 }
00107 
00108 /* interactive programs need a way of tell d_*() to write to stderr instead
00109    of stdout */
00110 void display_set_stderr(void)
00111 {
00112         outfile = stderr;
00113 }

Sambaに対してSat Aug 29 21:22:58 2009に生成されました。  doxygen 1.4.7