Back to index

openldap  2.4.31
Functions
stdio.c File Reference
#include "portable.h"
#include <stdio.h>
#include <ac/stdarg.h>
#include <ac/string.h>
#include <ac/ctype.h>
#include <lutil.h>
#include <ac/signal.h>

Go to the source code of this file.

Functions

int ber_pvt_vsnprintf (char *str, size_t n, const char *fmt, va_list ap)
int ber_pvt_snprintf (char *str, size_t n, const char *fmt,...)

Function Documentation

int ber_pvt_snprintf ( char *  str,
size_t  n,
const char *  fmt,
  ... 
)

Definition at line 77 of file stdio.c.

{
       va_list ap;
       int res;

       va_start( ap, fmt );
       res = vsnprintf( str, n, fmt, ap );
       va_end( ap );
       return res;
}
int ber_pvt_vsnprintf ( char *  str,
size_t  n,
const char *  fmt,
va_list  ap 
)

Definition at line 47 of file stdio.c.

{
       int fds[2], res;
       FILE *f;
       RETSIGTYPE (*sig)();

       if (pipe( fds )) return -1;

       f = fdopen( fds[1], "w" );
       if ( !f ) {
              close( fds[1] );
              close( fds[0] );
              return -1;
       }
       setvbuf( f, str, _IOFBF, n );
       sig = signal( SIGPIPE, SIG_IGN );
       close( fds[0] );

       res = vfprintf( f, fmt, ap );

       fclose( f );
       signal( SIGPIPE, sig );
       if ( res > 0 && res < n ) {
              res = vsprintf( str, fmt, ap );
       }
       return res;
}