[GRASS-dev] G_message () family of functions

Ivan Shmakov ivan at theory.asu.ru
Sat Jan 26 13:12:21 EST 2008


>>>>> Markus Neteler <neteler at osgeo.org> writes:

 > Ivan, before your libgis patch gets lost: should it be applied?

	I believe it should.

 > According to Glynn it looked reasonable AFAIK.

 > Please send it to me (maybe offlist) for inclusion.

	Surely.

	BTW, since you apparently are using Google mail, you can try to
	use `Download' on the ``Show original'' link for a message to
	get it unaltered.

[...]

 >>> +    char buffer[2000];  /* G_asprintf does not work */
 >>> +
 >>> +    vsprintf (buffer, template, ap);

 >> It would be nice to use vsnprintf(), but we would need to check that
 >> it's available (it's not in C89).

	It would be even better to check for vasprintf () and use it if
	it's available.  Like:

static int
vfprint_error (int type, const char *template, va_list ap)
{
    int result;
#ifdef HAVE_VASPRINTF
    char *buffer;

    vasprintf (&buffer, template, ap);
    if (buffer == 0) {
        /* . */
        return -1;
    }
    result = print_error (buffer, type);
    free (buffer);
#else
    char buffer[2000];  /* G_asprintf does not work */
#ifdef HAVE_VSNPRINTF
    vnsprintf (buffer, sizeof (buffer), template, ap);
#else
    vsprintf (buffer, template, ap);
#endif
    result = print_error (buffer, type);
#endif

    /* . */
    return result
}

	However, I see no reason for why gnulib/lib/vasnprintf.c cannot
	be used for a portable implementation of vasprintf ().  Reusing
	it would also obviate the need in lib/gis/asprintf.c.  And,
	well, doesn't eliminating extra code ease maintenance?



More information about the grass-dev mailing list