00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "IArchString.h"
00020
00021 #if HAVE_VSNPRINTF
00022
00023 #if !defined(ARCH_VSNPRINTF)
00024 # define ARCH_VSNPRINTF vsnprintf
00025 #endif
00026
00027 int
00028 IArchString::vsnprintf(char* str, int size, const char* fmt, va_list ap)
00029 {
00030 int n = ::ARCH_VSNPRINTF(str, size, fmt, ap);
00031 if (n > size) {
00032 n = -1;
00033 }
00034 return n;
00035 }
00036
00037 #elif SYSAPI_UNIX // !HAVE_VSNPRINTF
00038
00039 #include <stdio.h>
00040
00041 int
00042 IArchString::vsnprintf(char* str, int size, const char* fmt, va_list ap)
00043 {
00044 static FILE* bitbucket = fopen("/dev/null", "w");
00045 if (bitbucket == NULL) {
00046
00047 if (size > 0) {
00048 str[0] = '\0';
00049 }
00050 return 0;
00051 }
00052 else {
00053
00054 int n = vfprintf(bitbucket, fmt, ap);
00055 if (n + 1 <= size) {
00056
00057 vsprintf(str, fmt, ap);
00058 }
00059 return n;
00060 }
00061 }
00062
00063 #else // !HAVE_VSNPRINTF && !SYSAPI_UNIX
00064
00065 #error vsnprintf not implemented
00066
00067 #endif // !HAVE_VSNPRINTF