GRASS GIS 8 Programmer's Manual  8.4.0dev(2024)-9f2952cf23
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 18 of file asprintf.c.

Function Documentation

◆ G_asprintf()

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

Definition at line 69 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 100 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 41 of file asprintf.c.

References count, G_malloc, and G_realloc.

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