--- parser3/src/main/pa_common.C 2001/11/14 11:26:17 1.88 +++ parser3/src/main/pa_common.C 2001/11/23 11:53:03 1.91.4.1 @@ -4,7 +4,7 @@ Copyright(c) 2001 ArtLebedev Group(http://www.artlebedev.com) Author: Alexander Petrosyan (http://paf.design.ru) - $Id: pa_common.C,v 1.88 2001/11/14 11:26:17 paf Exp $ + $Id: pa_common.C,v 1.91.4.1 2001/11/23 11:53:03 paf Exp $ */ #include "pa_common.h" @@ -26,55 +26,6 @@ # define O_TRUNC 0 #endif -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 - --s; -#if _MSC_VER - /* - win32: - mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN\2001APR\1033\vccore.chm::/html/_crt__vsnprintf.2c_._vsnwprintf.htm - - 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 - int 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(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; -} - - static char *strnchr(char *buf, size_t size, char c) { for(; size-->0; buf++) { if(*buf==c) @@ -201,7 +152,7 @@ void file_write(Pool& pool, if((f=open(fname, O_CREAT|O_RDWR |(as_text?_O_TEXT:_O_BINARY) - |(do_append?O_APPEND:O_TRUNC), 0666))>=0) { + |(do_append?O_APPEND:O_TRUNC), 0664))>=0) { /*if(exclusive) flock(f, LOCK_EX);*/ @@ -518,3 +469,54 @@ void remove_crlf(char *start, char *end) case '\r': *p=' '; break; } } + + +/// 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 + --s; +#if _MSC_VER + /* + win32: + mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN\2001APR\1033\vccore.chm::/html/_crt__vsnprintf.2c_._vsnwprintf.htm + + 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(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; +}