iPXE
Functions
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_OR_UBDL)
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_OR_UBDL  )
int vasprintf ( char **  strp,
const char *  fmt,
va_list  args 
)

Write a formatted string to newly allocated memory.

Parameters:
strpPointer to hold allocated string
fmtFormat string
argsArguments corresponding to the format string
Return values:
lenLength of formatted string

Definition at line 17 of file asprintf.c.

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

Referenced by asprintf(), and xfer_vprintf().

                                                             {
        size_t len;
        va_list args_tmp;

        /* Calculate length needed for string */
        va_copy ( args_tmp, args );
        len = ( vsnprintf ( NULL, 0, fmt, args_tmp ) + 1 );
        va_end ( args_tmp );

        /* Allocate and fill string */
        *strp = malloc ( len );
        if ( ! *strp )
                return -ENOMEM;
        return vsnprintf ( *strp, len, fmt, args );
}
int asprintf ( char **  strp,
const char *  fmt,
  ... 
)

Write a formatted string to newly allocated memory.

Parameters:
strpPointer to hold allocated string
fmtFormat string
...Arguments corresponding to the format string
Return values:
lenLength of formatted string

Definition at line 41 of file asprintf.c.

References len, va_end, va_start, and vasprintf().

Referenced by efi_local_check_volume_name(), expand_settings(), iscsi_fetch_settings(), peerdist_discovery_request(), resolve_path(), tftp_uri(), and xenstore_dump().

                                                   {
        va_list args;
        int len;

        va_start ( args, fmt );
        len = vasprintf ( strp, fmt, args );
        va_end ( args );
        return len;
}