asprintf.c File Reference

#include <stdint.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
int vasprintf (char **strp, const char *fmt, va_list args)
 Write a formatted string to newly allocated memory.
int asprintf (char **strp, const char *fmt,...)
 Write a formatted string to newly allocated memory.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER   ) 

int vasprintf ( char **  strp,
const char *  fmt,
va_list  args 
)

Write a formatted string to newly allocated memory.

Parameters:
strp Pointer to hold allocated string
fmt Format string
args Arguments corresponding to the format string
Return values:
len Length of formatted string

Definition at line 17 of file asprintf.c.

References ENOMEM, malloc(), NULL, va_copy, va_end, and vsnprintf().

Referenced by asprintf().

00017                                                              {
00018         size_t len;
00019         va_list args_tmp;
00020 
00021         /* Calculate length needed for string */
00022         va_copy ( args_tmp, args );
00023         len = ( vsnprintf ( NULL, 0, fmt, args_tmp ) + 1 );
00024         va_end ( args_tmp );
00025 
00026         /* Allocate and fill string */
00027         *strp = malloc ( len );
00028         if ( ! *strp )
00029                 return -ENOMEM;
00030         return vsnprintf ( *strp, len, fmt, args );
00031 }

int asprintf ( char **  strp,
const char *  fmt,
  ... 
)

Write a formatted string to newly allocated memory.

Parameters:
strp Pointer to hold allocated string
fmt Format string
... Arguments corresponding to the format string
Return values:
len Length of formatted string

Definition at line 41 of file asprintf.c.

References va_end, va_start, and vasprintf().

Referenced by dns_qualify_name(), expand_command(), and resolve_path().

00041                                                    {
00042         va_list args;
00043         int len;
00044 
00045         va_start ( args, fmt );
00046         len = vasprintf ( strp, fmt, args );
00047         va_end ( args );
00048         return len;
00049 }


Generated on Tue Apr 6 20:01:14 2010 for gPXE by  doxygen 1.5.7.1