gnokii-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Good bits from Marcin's patch3


From: Pawel Kot
Subject: Re: Good bits from Marcin's patch3
Date: Wed, 03 Apr 2002 17:18:51 +0200

Hi,

>>> address@hidden 3 April 2002 16:15:21 >>>
> On Wed, Apr 03, 2002 at 02:02:55PM +0100, Ian Campbell wrote:
> > http://www.gnu.org/software/ac-archive/C_Support/ac_func_snprintf.html 
> It's not enough. It just checks wheter snprintf(NULL, 0, ...) can be
> accepted. C99 implementations will return the required buffer size - 1
> (not counting the terminating \0 character).
> 
> We should implement another test, similar to the following (just an idea,
> I'll finish it this night):
>     char buf[5] = {0, 0, 0, 0, 0};
>     snprintf(buf, 4, "ABCD");
>     exit( strlen(buf) != 3 );

OK. Now I can see that there are two issies adressed in Bozo's version and 
gcc's one.
Here's the proposition of the ISO C99 compability checking (it tests both: 
retval and
copying no more then n-1 characters):
AC_DEFUN([AC_FUNC_SNPRINTF],
        [AC_CACHE_CHECK(for ISO C99 compliant snprintf, ac_cv_func_snprintf,
        [AC_TRY_RUN([#include <stdio.h>
int main()
{
        char buf[] = {0, 0, 0, 0};
        snprintf(buf, 3, "ABC");
        exit (!(buf[2] == 0) && !(snprintf(NULL, 0, "%d", 100)));
}]
        ac_cv_func_snprintf=yes,
        ac_cv_func_snprintf=no,
        ac_cv_func_snprintf=no)])
        if test $ac_cv_func_snprintf = yes; then
                AC_DEFINE(HAVE_SNPRINTF)
        fi
])

I have tested the C function only, The m4 makro is likely to work. Well, I 
can't really test
it as all snprintf's here are C99 compatible :-)
Bozo: it's not good to use strlen here...

pkot
PS. Is the buf declaration valid or is it gccism?




reply via email to

[Prev in Thread] Current Thread [Next in Thread]