snprintf2.c

Go to the documentation of this file.
00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1996, 1997, 1998, 1999
00005  *      Sleepycat Software.  All rights reserved.
00006  */
00007 
00008 #ifdef HAVE_CONFIG_H
00009 #include "config.h"
00010 #endif /* HAVE_CONFIG_H */
00011 
00012 #ifndef HAVE_SNPRINTF
00013 
00014 #ifndef NO_SYSTEM_INCLUDES
00015 #include <sys/types.h>
00016 
00017 #include <stdio.h>
00018 #ifdef __STDC__
00019 #include <stdarg.h>
00020 #else
00021 #include <varargs.h>
00022 #endif
00023 #endif
00024 
00025 /*
00026  * snprintf --
00027  *      Bounded version of sprintf.
00028  *
00029  * PUBLIC: #ifndef HAVE_SNPRINTF
00030  * PUBLIC: #ifdef __STDC__
00031  * PUBLIC: int snprintf __P((char *, size_t, const char *, ...));
00032  * PUBLIC: #else
00033  * PUBLIC: int snprintf();
00034  * PUBLIC: #endif
00035  * PUBLIC: #endif
00036  */
00037 int
00038 #ifdef __STDC__
00039 snprintf(char *str, size_t n, const char *fmt, ...)
00040 #else
00041 snprintf(str, n, fmt, va_alist)
00042         char *str;
00043         size_t n;
00044         const char *fmt;
00045         va_dcl
00046 #endif
00047 {
00048         va_list ap;
00049         int rval;
00050 
00051         n = 0;
00052 #ifdef __STDC__
00053         va_start(ap, fmt);
00054 #else
00055         va_start(ap);
00056 #endif
00057 #ifdef SPRINTF_RET_CHARPNT
00058         (void)vsprintf(str, fmt, ap);
00059         va_end(ap);
00060         return (strlen(str));
00061 #else
00062         rval = vsprintf(str, fmt, ap);
00063         va_end(ap);
00064         return (rval);
00065 #endif
00066 }
00067 #endif /* HAVE_SNPRINTF */
00068 

Generated on Sun Jun 8 10:56:34 2008 for GNUmifluz by  doxygen 1.5.5