[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
check for C99-compliant snprintf
From: |
Ben Pfaff |
Subject: |
check for C99-compliant snprintf |
Date: |
Thu, 15 Feb 2007 21:04:20 -0800 |
User-agent: |
Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) |
Pre-C99 versions of snprintf often had an interface different
from the C99 interface: they would return -1 when the buffer was
too small, and the "size" argument was not necessarily
interpreted the same way. However, the current Gnulib snprintf
module doesn't check whether snprintf is C99-compliant, it just
checks for its presence. This is a problem with, e.g. Windows,
which has such a noncompliant snprintf.
The following patch attempts to remedy the situation. It works
fine for me with mingw32/Wine. I suspect that the patch to
vasnprintf.c is not the right way to go about things, but I don't
know what the preferred method is.
vsnprintf probably wants something similar.
Comments?
Index: lib/vasnprintf.c
===================================================================
RCS file: /sources/gnulib/gnulib/lib/vasnprintf.c,v
retrieving revision 1.22
diff -u -p -r1.22 vasnprintf.c
--- lib/vasnprintf.c 30 Jan 2007 01:07:22 -0000 1.22
+++ lib/vasnprintf.c 16 Feb 2007 05:01:05 -0000
@@ -27,6 +27,9 @@
# include <alloca.h>
#endif
+/* If we're replacing snprintf with rpl_snprintf, avoid a loop. */
+#undef snprintf
+
/* Specification. */
#if WIDE_CHAR_VERSION
# include "vasnwprintf.h"
Index: m4/snprintf.m4
===================================================================
RCS file: /sources/gnulib/gnulib/m4/snprintf.m4,v
retrieving revision 1.3
diff -u -p -r1.3 snprintf.m4
--- m4/snprintf.m4 23 Jan 2005 08:06:57 -0000 1.3
+++ m4/snprintf.m4 16 Feb 2007 05:01:06 -0000
@@ -1,12 +1,27 @@
-# snprintf.m4 serial 2
-dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+# snprintf.m4 serial 3
+dnl Copyright (C) 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FUNC_SNPRINTF],
[
- AC_REPLACE_FUNCS(snprintf)
+ AC_CACHE_CHECK([for C99-compliant snprintf],
+ [gl_cv_func_snprintf],
+ [AC_RUN_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <stdio.h>]],
+ [[char s[2];
+return !(snprintf (s, 2, "foo") == 3 && s[0] == 'f' && s[1] == '\0');]])],
+ [gl_cv_func_snprintf=yes],
+ [gl_cv_func_snprintf=no],
+ [gl_cv_func_snprintf=no])])
+
+ if test $gl_cv_func_snprintf = no; then
+ AC_LIBOBJ(snprintf)
+ AC_DEFINE(snprintf, rpl_snprintf,
+ [Define to rpl_snprintf if the replacement function should be used.])
+ fi
AC_CHECK_DECLS_ONCE(snprintf)
gl_PREREQ_SNPRINTF
])
--
"In the PARTIES partition there is a small section called the BEER.
Prior to turning control over to the PARTIES partition,
the BIOS must measure the BEER area into PCR[5]."
--TCPA PC Specific Implementation Specification
- check for C99-compliant snprintf,
Ben Pfaff <=
- Re: check for C99-compliant snprintf, Paul Eggert, 2007/02/16
- Re: check for C99-compliant snprintf, Ben Pfaff, 2007/02/16
- Re: check for C99-compliant snprintf, Paul Eggert, 2007/02/16
- Re: check for C99-compliant snprintf, Ben Pfaff, 2007/02/16
- Re: check for C99-compliant snprintf, Albert Chin, 2007/02/19
- Re: check for C99-compliant snprintf, Ben Pfaff, 2007/02/19
- Re: check for C99-compliant snprintf, Albert Chin, 2007/02/19
- Re: check for C99-compliant snprintf, Ben Pfaff, 2007/02/19
- Re: check for C99-compliant snprintf, Albert Chin, 2007/02/19
- Re: check for C99-compliant snprintf, Bruno Haible, 2007/02/19