1834645 Members
2857 Online
110069 Solutions
New Discussion

Re: vsnprintf

 
Robert O'Brien
Occasional Contributor

vsnprintf

hi
one of our programmers has started using vsnprintf which is available on HP-UX 11.00 We have to support products on HP-UX 10.20 as well, but the function doesn't seem to be publicly available in libc patches on 10.20.
Any advice?
thanks
-robert-
ask a question and look stupid for 5 minutes. Don't and remain stupid for life.
1 REPLY 1
Kenneth Platz
Esteemed Contributor

Re: vsnprintf

Robert,

Investigation of the libc.1 file shows that vsnprintf() is indeed in the library, even if it is not included in the correct header files. The following 3 lines at the beginning of your file should fix the problem:

#include
#include
extern int vsnprintf( char *, int, const char *, va_list );

I used the following piece of example code to illustrate the usage:

#include
#include

extern int vsnprintf( char *s, size_t maxsize, const char *format, va_list ap );

int call_it( char *s, size_t maxsize, const char *format, ... ) {
va_list ap;
int i;

va_start( ap, format );
i = vsnprintf( s, maxsize, format, ap );
va_end( ap );
}

int main( ) {
char buf[BUFSIZ];

call_it( buf, BUFSIZ-1, "This is a test %d %c %s\n", 123, 'a', "test" );
puts( buf );
}


I think, therefore I am... I think!