xstrlcpy.
* include/am_utils.h: use new HAVE_C99_VARARGS_MACROS or
HAVE_GCC_VARARGS_MACROS to pass file name and line number to
xsnprintf/xvsnprintf.
* libamu/strutil.c (xsnprintf, xvsnprintf): if debugging is on,
then also print the source file name and line number that called
xsnprintf/xvsnprintf with a buffer that wasn't large enough (most
likely an am-utils bug).
* Makefile.am (EXTRA_DIST_M4): distribute new
check_varargs_macros.m4 file.
* configure.in: execute new AMU_VARARGS_MACROS test.
* m4/macros/check_varargs_macros.m4: new test to check what style
of variable-length argument macros, if any, does the
compiler/pre-processor supports.
2005-10-06 Erez Zadok <ezk@cs.sunysb.edu>
+ * libamu/wire.c (print_wires): convert argument-less xsnprintf to
+ xstrlcpy.
+
+ * include/am_utils.h: use new HAVE_C99_VARARGS_MACROS or
+ HAVE_GCC_VARARGS_MACROS to pass file name and line number to
+ xsnprintf/xvsnprintf.
+
+ * libamu/strutil.c (xsnprintf, xvsnprintf): if debugging is on,
+ then also print the source file name and line number that called
+ xsnprintf/xvsnprintf with a buffer that wasn't large enough (most
+ likely an am-utils bug).
+
+ * Makefile.am (EXTRA_DIST_M4): distribute new
+ check_varargs_macros.m4 file.
+
+ * configure.in: execute new AMU_VARARGS_MACROS test.
+
+ * m4/macros/check_varargs_macros.m4: new test to check what style
+ of variable-length argument macros, if any, does the
+ compiler/pre-processor supports.
+
* conf/autofs/autofs_solaris_v2_v3.c (autofs_lookup_2_req)
conf/autofs/autofs_solaris_v1.c (autofs_mount_1_req), amd/opts.c,
amd/nfs_subr.c (nfsproc_lookup_2_svc), amd/nfs_start.c
m4/macros/check_umount_style.m4 \
m4/macros/check_unmount_args.m4 \
m4/macros/check_unmount_call.m4 \
+ m4/macros/check_varargs_macros.m4 \
m4/macros/expand_cpp_hex.m4 \
m4/macros/expand_cpp_int.m4 \
m4/macros/expand_cpp_string.m4 \
dnl
dnl AC_CONFIG_AUX_DIR(m4)
AC_PREREQ(2.52)
-AC_REVISION($Revision: 1.118 $)
+AC_REVISION($Revision: 1.119 $)
AC_COPYRIGHT([Copyright (c) 1997-2005 Erez Zadok])
dnl find out system type
AC_MSG_NOTICE(*** SYSTEM TYPES ***)
dnl Generic Compiler Characteristics
AC_MSG_NOTICE(*** GENERIC COMPILER CHARACTERISTICS ***)
AMU_C_VOID_P
+AMU_VARARGS_MACROS
dnl ======================================================================
dnl *********
extern void setup_sighandler(int signum, void (*handler)(int));
extern time_t clocktime(nfstime *nt);
+#if defined(DEBUG) && (defined(HAVE_C99_VARARGS_MACROS) || defined(HAVE_GCC_VARARGS_MACROS))
+# ifdef HAVE_C99_VARARGS_MACROS
+#define xsnprintf(str,size,fmt,...) _xsnprintf(__FILE__,__LINE__,(str),(size),(fmt),__VA_ARGS__)
+# endif /* HAVE_C99_VARARGS_MACROS */
+# ifdef HAVE_GCC_VARARGS_MACROS
+#define xsnprintf(str,size,fmt,args...) _xsnprintf(__FILE__,__LINE__,(str),(size),(fmt),args)
+# endif /* HAVE_GCC_VARARGS_MACROS */
+extern int _xsnprintf(const char *filename, int lineno, char *str, size_t size, const char *format, ...);
+#define xvsnprintf(str,size,fmt,ap) _xvsnprintf(__FILE__,__LINE__,(str),(size),(fmt),(ap))
+extern int _xvsnprintf(const char *filename, int lineno, char *str, size_t size, const char *format, va_list ap);
+#else /* not DEBUG or no C99/GCC-style vararg cpp macros supported */
extern int xsnprintf(char *str, size_t size, const char *format, ...);
extern int xvsnprintf(char *str, size_t size, const char *format, va_list ap);
+#endif /* not DEBUG or no C99/GCC-style vararg cpp macros supported */
#ifdef DEBUG
-extern void _xstrlcat(char *dst, const char *src, size_t len, const char *filename, int lineno);
-# define xstrlcat(d,s,l) _xstrlcat((d),(s),(l),__FILE__,__LINE__)
-extern void _xstrlcpy(char *dst, const char *src, size_t len, const char *filename, int lineno);
-# define xstrlcpy(d,s,l) _xstrlcpy((d),(s),(l),__FILE__,__LINE__)
+extern void _xstrlcat(const char *filename, int lineno, char *dst, const char *src, size_t len);
+# define xstrlcat(d,s,l) _xstrlcat(__FILE__,__LINE__,(d),(s),(l))
+extern void _xstrlcpy(const char *filename, int lineno, char *dst, const char *src, size_t len);
+# define xstrlcpy(d,s,l) _xstrlcpy(__FILE__,__LINE__,(d),(s),(l))
#else /* not DEBUG */
extern void xstrlcat(char *dst, const char *src, size_t len);
extern void xstrlcpy(char *dst, const char *src, size_t len);
*/
void
#ifdef DEBUG
-_xstrlcpy(char *dst, const char *src, size_t len, const char *filename, int lineno)
+_xstrlcpy(const char *filename, int lineno, char *dst, const char *src, size_t len)
#else /* not DEBUG */
xstrlcpy(char *dst, const char *src, size_t len)
#endif /* not DEBUG */
*/
void
#ifdef DEBUG
-_xstrlcat(char *dst, const char *src, size_t len, const char *filename, int lineno)
+_xstrlcat(const char *filename, int lineno, char *dst, const char *src, size_t len)
#else /* not DEBUG */
xstrlcat(char *dst, const char *src, size_t len)
#endif /* not DEBUG */
/* our version of snprintf */
int
+#if defined(DEBUG) && (defined(HAVE_C99_VARARGS_MACROS) || defined(HAVE_GCC_VARARGS_MACROS))
+_xsnprintf(const char *filename, int lineno, char *str, size_t size, const char *format, ...)
+#else /* not DEBUG or no C99/GCC-style vararg cpp macros supported */
xsnprintf(char *str, size_t size, const char *format, ...)
+#endif /* not DEBUG or no C99/GCC-style vararg cpp macros supported */
{
va_list ap;
int ret = 0;
va_start(ap, format);
+#if defined(DEBUG) && (defined(HAVE_C99_VARARGS_MACROS) || defined(HAVE_GCC_VARARGS_MACROS))
+ ret = _xvsnprintf(filename, lineno, str, size, format, ap);
+#else /* not DEBUG or no C99/GCC-style vararg cpp macros supported */
ret = xvsnprintf(str, size, format, ap);
+#endif /* not DEBUG or no C99/GCC-style vararg cpp macros supported */
va_end(ap);
return ret;
/* our version of vsnprintf */
int
+#if defined(DEBUG) && (defined(HAVE_C99_VARARGS_MACROS) || defined(HAVE_GCC_VARARGS_MACROS))
+_xvsnprintf(const char *filename, int lineno, char *str, size_t size, const char *format, va_list ap)
+#else /* not DEBUG or no C99/GCC-style vararg cpp macros supported */
xvsnprintf(char *str, size_t size, const char *format, va_list ap)
+#endif /* not DEBUG or no C99/GCC-style vararg cpp macros supported */
{
int ret = 0;
if (ret < 0 || ret >= size) { /* error or truncation occured */
static int maxtrunc; /* hack to avoid inifinite loop */
if (++maxtrunc > 10)
- plog(XLOG_ERROR, "BUG: string %p truncated (ret=%d, format=\"%s\")",
+#if defined(DEBUG) && (defined(HAVE_C99_VARARGS_MACROS) || defined(HAVE_GCC_VARARGS_MACROS))
+ plog(XLOG_ERROR, "xvsnprintf(%s:%d): string %p truncated (ret=%d, format=\"%s\")",
+ filename, lineno, str, ret, format);
+#else /* not DEBUG or no C99/GCC-style vararg cpp macros supported */
+ plog(XLOG_ERROR, "xvsnprintf: string %p truncated (ret=%d, format=\"%s\")",
str, ret, format);
+#endif /* not DEBUG or no C99/GCC-style vararg cpp macros supported */
}
return ret;
return NULL;
if (!localnets) {
- xsnprintf(buf, buf_size, "No networks.\n");
+ xstrlcpy(buf, "No networks\n", buf_size);
return buf;
}
/* check if there's more than one network */
--- /dev/null
+dnl ######################################################################
+dnl check if CPP can handle variable-length argument macros
+AC_DEFUN([AMU_VARARGS_MACROS],
+[
+AC_CACHE_CHECK(if pre-processor can handle variable-length macros,
+ac_cv_varargs_macros,
+[
+# try C99 style
+AC_PREPROC_IFELSE(
+[
+#define foo(format, ...) bar(format, __VA_ARGS__)
+], ac_cv_varargs_macros=c99,
+# else try gcc style
+AC_PREPROC_IFELSE(
+[
+#define foo(format, args...) bar(format, args)
+], ac_cv_varargs_macros=gcc, ac_cv_varargs_macros=none))
+])
+if test "$ac_cv_varargs_macros" = c99
+then
+ AC_DEFINE(HAVE_C99_VARARGS_MACROS, 1,
+ [System supports C99-style variable-length argument macros])
+else
+ if test "$ac_cv_varargs_macros" = gcc
+ then
+ AC_DEFINE(HAVE_GCC_VARARGS_MACROS, 1,
+ [System supports GCC-style variable-length argument macros])
+ fi
+fi
+])
+dnl ======================================================================