Remove dependencies on HAVE_VSNPRINTF, use replacement in liblutil/stdio.c

if needed. Same check for snprintf.
This commit is contained in:
Howard Chu 2002-09-06 20:54:22 +00:00
parent b623e4495b
commit 4d8a2e2815
6 changed files with 16 additions and 38 deletions

View file

@ -2420,7 +2420,7 @@ AC_FUNC_VPRINTF
if test $ac_cv_func_vprintf = yes ; then if test $ac_cv_func_vprintf = yes ; then
dnl check for vsnprintf dnl check for vsnprintf
AC_CHECK_FUNCS(vsnprintf vsprintf) AC_CHECK_FUNCS(snprintf vsnprintf)
fi fi
AC_CHECK_FUNCS( \ AC_CHECK_FUNCS( \
@ -2485,6 +2485,16 @@ AC_REPLACE_FUNCS(getopt)
if test "$ac_cv_func_getopt" != yes; then if test "$ac_cv_func_getopt" != yes; then
LIBSRCS="$LIBSRCS getopt.c" LIBSRCS="$LIBSRCS getopt.c"
fi fi
if test "$ac_cv_func_snprintf" != yes -o "$ac_cv_func_vsnprintf" != yes; then
LIBSRCS="$LIBSRCS stdio.c"
LIBOBJS="$LIBOBJS stdio.o"
if test "$ac_cv_func_snprintf" != yes; then
AC_DEFINE(snprintf, lutil_snprintf, [define to snprintf routine])
fi
if test "$ac_cv_func_vsnprintf" != yes; then
AC_DEFINE(vsnprintf, lutil_vsnprintf, [define to snprintf routine])
fi
fi
dnl ---------------------------------------------------------------- dnl ----------------------------------------------------------------
# Check Configuration # Check Configuration

View file

@ -87,15 +87,8 @@ int ber_pvt_log_output(
{ {
int level; int level;
ber_get_option( NULL, LBER_OPT_BER_DEBUG, &level ); ber_get_option( NULL, LBER_OPT_BER_DEBUG, &level );
#ifdef HAVE_VSNPRINTF
buf[sizeof(buf) - 1] = '\0'; buf[sizeof(buf) - 1] = '\0';
vsnprintf( buf, sizeof(buf)-1, fmt, vl ); vsnprintf( buf, sizeof(buf)-1, fmt, vl );
#elif HAVE_VSPRINTF
vsprintf( buf, fmt, vl ); /* hope it's not too long */
#else
/* use doprnt() */
#error "vsprintf() required.";
#endif
if ( ber_log_check( LDAP_DEBUG_BER, level ) ) if ( ber_log_check( LDAP_DEBUG_BER, level ) )
(*ber_pvt_log_print)( buf ); (*ber_pvt_log_print)( buf );
} }
@ -117,15 +110,8 @@ int ber_pvt_log_printf( int errlvl, int loglvl, const char *fmt, ... )
va_start( ap, fmt ); va_start( ap, fmt );
#ifdef HAVE_VSNPRINTF
buf[sizeof(buf) - 1] = '\0'; buf[sizeof(buf) - 1] = '\0';
vsnprintf( buf, sizeof(buf)-1, fmt, ap ); vsnprintf( buf, sizeof(buf)-1, fmt, ap );
#elif HAVE_VSPRINTF
vsprintf( buf, fmt, ap ); /* hope it's not too long */
#else
/* use doprnt() */
#error "vsprintf() required."
#endif
va_end(ap); va_end(ap);

View file

@ -311,11 +311,7 @@ void (lutil_debug)( int debug, int level, const char *fmt, ... )
#endif #endif
va_start( vl, fmt ); va_start( vl, fmt );
#ifdef HAVE_VSNPRINTF
vsnprintf( buffer, sizeof(buffer), fmt, vl ); vsnprintf( buffer, sizeof(buffer), fmt, vl );
#else
vsprintf( buffer, fmt, vl );
#endif
buffer[sizeof(buffer)-1] = '\0'; buffer[sizeof(buffer)-1] = '\0';
if( log_file != NULL ) { if( log_file != NULL ) {

View file

@ -43,15 +43,8 @@ int ldap_log_printf( LDAP *ld, int loglvl, const char *fmt, ... )
va_start( ap, fmt ); va_start( ap, fmt );
#ifdef HAVE_VSNPRINTF
buf[sizeof(buf) - 1] = '\0'; buf[sizeof(buf) - 1] = '\0';
vsnprintf( buf, sizeof(buf)-1, fmt, ap ); vsnprintf( buf, sizeof(buf)-1, fmt, ap );
#elif HAVE_VSPRINTF
vsprintf( buf, fmt, ap ); /* hope it's not too long */
#else
/* use doprnt() */
chokeme = "choke me! I don't have a doprnt manual handy!";
#endif
va_end(ap); va_end(ap);

View file

@ -42,15 +42,8 @@ void setproctitle( const char *fmt, ... )
va_start(ap, fmt); va_start(ap, fmt);
#ifdef HAVE_VSNPRINTF
buf[sizeof(buf) - 1] = '\0'; buf[sizeof(buf) - 1] = '\0';
vsnprintf( buf, sizeof(buf)-1, fmt, ap ); vsnprintf( buf, sizeof(buf)-1, fmt, ap );
#elif HAVE_VPRINTF
vsprintf( buf, fmt, ap ); /* hope it's not too long */
#else
/* use doprnt() */
chokeme = "choke me! I don't have a doprnt() manual handy";
#endif
va_end(ap); va_end(ap);

View file

@ -12,7 +12,7 @@
#include <lutil.h> #include <lutil.h>
#ifndef HAVE_VSNPRINTF #if !defined(HAVE_VSNPRINTF) && !defined(HAVE_EBCDIC)
/* Write at most n characters to the buffer in str, return the /* Write at most n characters to the buffer in str, return the
* number of chars written or -1 if the buffer would have been * number of chars written or -1 if the buffer would have been
* overflowed. * overflowed.
@ -30,13 +30,12 @@
* broken pipe, and the write will be terminated. * broken pipe, and the write will be terminated.
* -- hyc, 2002-07-19 * -- hyc, 2002-07-19
*/ */
#ifndef HAVE_EBCDIC
/* This emulation uses vfprintf; on OS/390 we're also emulating /* This emulation uses vfprintf; on OS/390 we're also emulating
* that function so it's more efficient just to have a separate * that function so it's more efficient just to have a separate
* version of vsnprintf there. * version of vsnprintf there.
*/ */
#include <ac/signal.h> #include <ac/signal.h>
int vsnprintf( char *str, size_t n, const char *fmt, va_list ap ) int lutil_vsnprintf( char *str, size_t n, const char *fmt, va_list ap )
{ {
int fds[2], res; int fds[2], res;
FILE *f; FILE *f;
@ -62,7 +61,8 @@ int vsnprintf( char *str, size_t n, const char *fmt, va_list ap )
} }
#endif #endif
int snprintf( char *str, size_t n, const char *fmt, ... ) #ifndef HAVE_SNPRINTF
int lutil_snprintf( char *str, size_t n, const char *fmt, ... )
{ {
va_list ap; va_list ap;
int res; int res;
@ -116,7 +116,7 @@ int lutil_fputs( const char *str, FILE *fp )
* may need to be extended to recognize other qualifiers but so * may need to be extended to recognize other qualifiers but so
* far this seems to be enough. * far this seems to be enough.
*/ */
int vsnprintf( char *str, size_t n, const char *fmt, va_list ap ) int lutil_vsnprintf( char *str, size_t n, const char *fmt, va_list ap )
{ {
char *ptr, *pct, *s2, *f2, *end; char *ptr, *pct, *s2, *f2, *end;
char fm2[64]; char fm2[64];