LALStd.c

Go to the documentation of this file.
00001 /*
00002 *  Copyright (C) 2007 Bernd Machenschalk, Jolien Creighton
00003 *
00004 *  This program is free software; you can redistribute it and/or modify
00005 *  it under the terms of the GNU General Public License as published by
00006 *  the Free Software Foundation; either version 2 of the License, or
00007 *  (at your option) any later version.
00008 *
00009 *  This program is distributed in the hope that it will be useful,
00010 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 *  GNU General Public License for more details.
00013 *
00014 *  You should have received a copy of the GNU General Public License
00015 *  along with with program; see the file COPYING. If not, write to the
00016 *  Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00017 *  MA  02111-1307  USA
00018 */
00019 
00020 #if 0 /* autodoc block */
00021 <lalVerbatim file="LALStdCV">
00022 $Id: LALStd.c,v 1.4 2007/06/08 14:41:53 bema Exp $
00023 </lalVerbatim>
00024 
00025 <lalLaTeX>
00026 \subsection{Module \texttt{LALStd.c}}
00027 
00028 LAL replacement routines for standard C functions.  At present, this
00029 just includes replacements for \texttt{snprintf}.
00030 
00031 \subsection*{Prototypes}
00032 \begin{verbatim}
00033 int LALSnprintf( char *str, size_t size, const char *fmt, ... );
00034 int LALVsnprintf( char *str, size_t size, const char *fmt, va_list ap );
00035 \end{verbatim}
00036 \idx{LALSnprintf()}
00037 \idx{LALVsnprintf()}
00038 
00039 \subsection*{Description}
00040 
00041 The routines \verb+LALSnprintf()+ and \verb+LALVsnprintf()+ are
00042 wrappers for \verb+snprintf()+ and \verb+vsnprintf()+, if these functions
00043 are available, otherwise they are simply sprintf() or vsprintf().
00044 It is strongly recommended that \verb+LALSnprintf()+ and \verb+LALVsnprintf()+
00045 be used rather than \verb+sprintf()+ and \verb+vsprintf()+ as the latter are
00046 prone to buffer-overflow problems.
00047 
00048 \vfill{\footnotesize\input{LALStdCV}}
00049 
00050 </lalLaTeX>
00051 #endif /* autodoc block */
00052 
00053 /* DO *NOT* INCLUDE STDIO... STDLIB has size_t */
00054 #include <config.h>
00055 #include <stdlib.h>
00056 #include <stdarg.h>
00057 
00058 #include <lal/LALRCSID.h>
00059 NRCSID (LALSTDC,"$Id: LALStd.c,v 1.4 2007/06/08 14:41:53 bema Exp $");
00060 
00061 #ifdef HAVE_VSNPRINTF
00062 int vsnprintf( char *str, size_t size, const char *fmt, va_list ap );
00063 #else /* dangerous: just use vsprintf!!! */
00064 int vsprintf( char *str, const char *fmt, va_list ap );
00065 #define vsnprintf( s, n, f, a ) vsprintf( s, f, a );
00066 #endif
00067 
00068 int LALSnprintf( char *str, size_t size, const char *fmt, ... );
00069 int LALVsnprintf( char *str, size_t size, const char *fmt, va_list ap );
00070 int LALSnprintf( char *str, size_t size, const char *fmt, ... )
00071 {
00072   int n;
00073   va_list ap;
00074   va_start( ap, fmt );
00075   n = vsnprintf( str, size, fmt, ap );
00076   va_end( ap );
00077   return n;
00078 }
00079 int LALVsnprintf( char *str, size_t size, const char *fmt, va_list ap )
00080 {
00081   return vsnprintf( str, size, fmt, ap );
00082 }
00083 
00084 /*
00085  * This needs to be in some source code somewhere,
00086  * so may as well put it here.
00087  */
00088 #if defined(NDEBUG) || defined(LAL_NDEBUG)
00089 const int lalNoDebug = 1;
00090 #else
00091 const int lalNoDebug = 0;
00092 #endif

Generated on Sun Sep 7 03:06:57 2008 for LAL by  doxygen 1.5.2