Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00036 #ifndef _MI_FMT_H_
00037 #define _MI_FMT_H_
00038
00039 #include <stdarg.h>
00040 #include <errno.h>
00041
00043 #define DEFAULT_MI_FMT_BUF_SIZE 2048
00044
00045 extern char *mi_fmt_buf;
00046 extern int mi_fmt_buf_len;
00047
00048 int mi_fmt_init( unsigned int size );
00049
00050 static inline char* mi_print_fmt(char *fmt, va_list ap, int *len)
00051 {
00052 int n;
00053
00054 if (mi_fmt_buf==NULL) {
00055 if (mi_fmt_init(DEFAULT_MI_FMT_BUF_SIZE)!=0) {
00056 LM_ERR("failed to init\n");
00057 return 0;
00058 }
00059 }
00060
00061 n = vsnprintf( mi_fmt_buf, mi_fmt_buf_len, fmt, ap);
00062 if (n<0 || n>=mi_fmt_buf_len) {
00063 LM_ERR("formatting failed with n=%d, %s\n",n,strerror(errno));
00064 return 0;
00065 }
00066
00067 *len = n;
00068 return mi_fmt_buf;
00069 }
00070
00071 #endif