GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
asprintf.c File Reference

GIS Library - GRASS implementation of asprintf(). More...

#include <grass/config.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <assert.h>
#include <grass/gis.h>
Include dependency graph for asprintf.c:

Go to the source code of this file.

Macros

#define _GNU_SOURCE   /* enable asprintf */
 

Functions

int G_vasprintf (char **out, const char *fmt, va_list ap)
 Safe replacement for asprintf(). More...
 
int G_asprintf (char **out, const char *fmt,...)
 

Detailed Description

GIS Library - GRASS implementation of asprintf().

Eric G. Miller - Thu, 2 May 2002 17:51:54 -0700

I've got a sort of cheat for asprintf. We can't use vsnprintf for the same reason we can't use snprintf ;-) Comments welcome.

We cheat by printing to a tempfile via vfprintf() and then reading it back in. Probably not the most efficient way.

WARNING: Temporarily, the G_asprintf macro cannot be used. See explanation in gisdefs.h.

(C) 2001-2008 by the GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Author
Eric Miller - egm2 at jps net
Date
2002-2008

Definition in file asprintf.c.

Macro Definition Documentation

#define _GNU_SOURCE   /* enable asprintf */

Definition at line 28 of file asprintf.c.

Function Documentation

int G_vasprintf ( char **  out,
const char *  fmt,
va_list  ap 
)

Safe replacement for asprintf().

Allocate a string large enough to hold the new output, including the terminating NULL, and returns a pointer to the first parameter. The pointer should be passed to G_free() to release the allocated storage when it is no longer needed.

Parameters
[out]out
[in]fmt
Returns
number of bytes written

Definition at line 66 of file asprintf.c.

References count, fclose(), file_name, G_free(), and NULL.

Referenced by G_asprintf().