--- parser3/src/main/pa_common.C 2016/07/29 20:24:16 1.291 +++ parser3/src/main/pa_common.C 2016/09/21 14:12:23 1.293 @@ -50,7 +50,7 @@ #define pa_mkdir(path, mode) mkdir(path, mode) #endif -volatile const char * IDENT_PA_COMMON_C="$Id: pa_common.C,v 1.291 2016/07/29 20:24:16 moko Exp $" IDENT_PA_COMMON_H IDENT_PA_HASH_H IDENT_PA_ARRAY_H IDENT_PA_STACK_H; +volatile const char * IDENT_PA_COMMON_C="$Id: pa_common.C,v 1.293 2016/09/21 14:12:23 moko Exp $" IDENT_PA_COMMON_H IDENT_PA_HASH_H IDENT_PA_ARRAY_H IDENT_PA_STACK_H; // some maybe-undefined constants @@ -75,6 +75,11 @@ volatile const char * IDENT_PA_COMMON_C= #define FILE_STATUS_NAME "status" +// defines for vs2015 linking with old libs +#if _MSC_VER >= 1900 +int (WINAPIV * __vsnprintf)(char *, size_t, const char*, va_list) = _vsnprintf; +#endif + // globals const String file_status_name(FILE_STATUS_NAME); @@ -895,56 +900,6 @@ const char* hex_string(unsigned char* by return bytes_hex; } -/// must be last in this file -#undef vsnprintf -int __vsnprintf(char* b, size_t s, const char* f, va_list l) { - if(!s) - return 0; - - int r; - // note: on win32 & maybe somewhere else - // vsnprintf do not writes terminating 0 in 'buffer full' case, reducing - // http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010 - --s; - - // clients do not check for negative 's', feature: ignore such prints - if((ssize_t)s<0) - return 0; - -#ifdef _MSC_VER - // win32: if the number of bytes to write exceeds buffer, then count bytes are written and -1 is returned - r=_vsnprintf(b, s, f, l); - if(r<0) - r=s; -#else - r=vsnprintf(b, s, f, l); - /* - solaris: man vsnprintf - - The snprintf() function returns the number of characters - formatted, that is, the number of characters that would have - been written to the buffer if it were large enough. If the - value of n is 0 on a call to snprintf(), an unspecified - value less than 1 is returned. - */ - - if(r<0) - r=0; - else if((size_t)r>s) - r=s; -#endif - b[r]=0; - return r; -} - -int __snprintf(char* b, size_t s, const char* f, ...) { - va_list l; - va_start(l, f); - int r=__vsnprintf(b, s, f, l); - va_end(l); - return r; -} - /* mime64 functions are from libgmime[http://spruce.sourceforge.net/gmime/] lib */ /* * Authors: Michael Zucchi @@ -1423,3 +1378,53 @@ const char *pa_idna_decode(const char *i return result; } +/// must be last in this file +#undef vsnprintf +int pa_vsnprintf(char* b, size_t s, const char* f, va_list l) { + if(!s) + return 0; + + int r; + // note: on win32 & maybe somewhere else + // vsnprintf do not writes terminating 0 in 'buffer full' case, reducing + // http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010 + --s; + + // clients do not check for negative 's', feature: ignore such prints + if((ssize_t)s<0) + return 0; + +#ifdef _MSC_VER + // win32: if the number of bytes to write exceeds buffer, then count bytes are written and -1 is returned + r=_vsnprintf(b, s, f, l); + if(r<0) + r=s; +#else + r=vsnprintf(b, s, f, l); + /* + solaris: man vsnprintf + + The snprintf() function returns the number of characters + formatted, that is, the number of characters that would have + been written to the buffer if it were large enough. If the + value of n is 0 on a call to snprintf(), an unspecified + value less than 1 is returned. + */ + + if(r<0) + r=0; + else if((size_t)r>s) + r=s; +#endif + b[r]=0; + return r; +} + +int pa_snprintf(char* b, size_t s, const char* f, ...) { + va_list l; + va_start(l, f); + int r=pa_vsnprintf(b, s, f, l); + va_end(l); + return r; +} +