fmt.h

Go to the documentation of this file.
00001 /*
00002  * $Id: fmt.h 4518 2008-07-28 15:39:28Z henningw $
00003  *
00004  * Copyright (C) 2006 Voice Sistem SRL
00005  *
00006  * This file is part of Kamailio, a free SIP server.
00007  *
00008  * Kamailio is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * Kamailio is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00021  *
00022  *
00023  * History:
00024  * ---------
00025  *  2006-09-08  first version (bogdan)
00026  */
00027 
00028 /*!
00029  * \file 
00030  * \brief MI :: Format handling
00031  * \ingroup mi
00032  */
00033 
00034 
00035 
00036 #ifndef _MI_FMT_H_
00037 #define _MI_FMT_H_
00038 
00039 #include <stdarg.h>
00040 #include <errno.h>
00041 
00042 /*! \brief size of the buffer used for printing the FMT */
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

Generated on Wed May 23 06:00:45 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6