GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
asprintf.c File Reference

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

#include <stdio.h>
#include <stdarg.h>
#include <string.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,...)
 
int G_rasprintf (char **out, size_t *size, const char *fmt,...)
 Reallocating version of asprintf(). More...
 

Detailed Description

GIS Library - GRASS implementation of asprintf().

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

Rewritten by Glynn Clements, Sat, 6 Feb 2010 Assumes that vsnprintf() is available

(C) 2002-2014 by the GRASS Development Team (C) 2010 by Glynn Clements

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

Definition in file asprintf.c.

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE   /* enable asprintf */

Definition at line 19 of file asprintf.c.

Function Documentation

◆ G_asprintf()

int G_asprintf ( char **  out,
const char *  fmt,
  ... 
)

Definition at line 70 of file asprintf.c.

References count, and G_vasprintf().

◆ G_rasprintf()

int G_rasprintf ( char **  out,
size_t *  size,
const char *  fmt,
  ... 
)

Reallocating version of asprintf().

Reallocate a string large enough to hold the output, including the terminating NULL, and return the number of characters printed. Contrary to G_asprintf(), any existing buffer pointed to by out of size osize is used to hold the output and enlarged if necessary. This is useful when G_rasprintf is called many times in a loop.

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

Definition at line 101 of file asprintf.c.

References count, and G_realloc.

◆ G_vasprintf()

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 return the number of characters printed. The pointer out is set to the output string and should be passed to G_free() to release the allocated storage when it is no longer needed.

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

Definition at line 42 of file asprintf.c.

References count, G_malloc, and G_realloc.

Referenced by G_asprintf(), Rast_append_format_history(), and Rast_format_history().