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